blob: e572e51b2c5e982339d620104fb3f8ab104d4f6c [file] [log] [blame]
Jamie Gennis134f0422011-03-08 12:18:54 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Dan Stozac6f30bd2015-06-08 09:32:50 -070017#include "DummyConsumer.h"
18
Jamie Gennis134f0422011-03-08 12:18:54 -080019#include <gtest/gtest.h>
Jamie Gennis7a4d0df2011-03-09 17:05:02 -080020
Courtney Goeltzenleuchter6a570b62017-03-13 14:30:00 -060021#include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h>
Brian Anderson3da8d272016-07-28 16:20:47 -070022#include <binder/ProcessState.h>
Courtney Goeltzenleuchter6a570b62017-03-13 14:30:00 -060023#include <configstore/Utils.h>
Courtney Goeltzenleuchter1eb1b272017-02-02 16:51:06 -070024#include <cutils/properties.h>
25#include <gui/BufferItemConsumer.h>
Brian Anderson3da8d272016-07-28 16:20:47 -070026#include <gui/IDisplayEventConnection.h>
Yin-Chia Yeh1f2af5c2017-05-11 16:54:04 -070027#include <gui/IProducerListener.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080028#include <gui/ISurfaceComposer.h>
29#include <gui/Surface.h>
30#include <gui/SurfaceComposerClient.h>
Brian Anderson3da8d272016-07-28 16:20:47 -070031#include <private/gui/ComposerService.h>
Dan Stozac1879002014-05-22 15:59:05 -070032#include <ui/Rect.h>
Jamie Gennis134f0422011-03-08 12:18:54 -080033#include <utils/String8.h>
34
Brian Anderson3da8d272016-07-28 16:20:47 -070035#include <limits>
Kalle Raita643f0942016-12-07 09:20:14 -080036#include <thread>
37
Jamie Gennis134f0422011-03-08 12:18:54 -080038namespace android {
39
Kalle Raita643f0942016-12-07 09:20:14 -080040using namespace std::chrono_literals;
Courtney Goeltzenleuchter6a570b62017-03-13 14:30:00 -060041// retrieve wide-color and hdr settings from configstore
42using namespace android::hardware::configstore;
43using namespace android::hardware::configstore::V1_0;
44
45static bool hasWideColorDisplay =
46 getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasWideColorDisplay>(false);
Kalle Raita643f0942016-12-07 09:20:14 -080047
Brian Anderson3da8d272016-07-28 16:20:47 -070048class FakeSurfaceComposer;
49class FakeProducerFrameEventHistory;
50
51static constexpr uint64_t NO_FRAME_INDEX = std::numeric_limits<uint64_t>::max();
52
Jamie Gennis134f0422011-03-08 12:18:54 -080053class SurfaceTest : public ::testing::Test {
54protected:
Mathias Agopian7c1a4872013-03-20 15:56:04 -070055
56 SurfaceTest() {
57 ProcessState::self()->startThreadPool();
58 }
59
Jamie Gennis134f0422011-03-08 12:18:54 -080060 virtual void SetUp() {
Jamie Gennis7a4d0df2011-03-09 17:05:02 -080061 mComposerClient = new SurfaceComposerClient;
Jamie Gennis134f0422011-03-08 12:18:54 -080062 ASSERT_EQ(NO_ERROR, mComposerClient->initCheck());
63
Brian Andersond0010582017-03-07 13:20:31 -080064 // TODO(brianderson): The following sometimes fails and is a source of
65 // test flakiness.
Jamie Gennisfc850122011-04-25 16:40:05 -070066 mSurfaceControl = mComposerClient->createSurface(
Jeff Brown9d4e3d22012-08-24 20:00:51 -070067 String8("Test Surface"), 32, 32, PIXEL_FORMAT_RGBA_8888, 0);
Jamie Gennis134f0422011-03-08 12:18:54 -080068
69 ASSERT_TRUE(mSurfaceControl != NULL);
70 ASSERT_TRUE(mSurfaceControl->isValid());
71
Mathias Agopian698c0872011-06-28 19:09:31 -070072 SurfaceComposerClient::openGlobalTransaction();
Mathias Agopian9303eee2011-07-01 15:27:27 -070073 ASSERT_EQ(NO_ERROR, mSurfaceControl->setLayer(0x7fffffff));
Jamie Gennis134f0422011-03-08 12:18:54 -080074 ASSERT_EQ(NO_ERROR, mSurfaceControl->show());
Mathias Agopian698c0872011-06-28 19:09:31 -070075 SurfaceComposerClient::closeGlobalTransaction();
Jamie Gennis134f0422011-03-08 12:18:54 -080076
77 mSurface = mSurfaceControl->getSurface();
78 ASSERT_TRUE(mSurface != NULL);
79 }
80
81 virtual void TearDown() {
82 mComposerClient->dispose();
83 }
84
85 sp<Surface> mSurface;
86 sp<SurfaceComposerClient> mComposerClient;
87 sp<SurfaceControl> mSurfaceControl;
88};
89
90TEST_F(SurfaceTest, QueuesToWindowComposerIsTrueWhenVisible) {
91 sp<ANativeWindow> anw(mSurface);
92 int result = -123;
93 int err = anw->query(anw.get(), NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER,
94 &result);
95 EXPECT_EQ(NO_ERROR, err);
96 EXPECT_EQ(1, result);
97}
98
99TEST_F(SurfaceTest, QueuesToWindowComposerIsTrueWhenPurgatorized) {
100 mSurfaceControl.clear();
Kalle Raita643f0942016-12-07 09:20:14 -0800101 // Wait for the async clean-up to complete.
102 std::this_thread::sleep_for(50ms);
Jamie Gennis134f0422011-03-08 12:18:54 -0800103
104 sp<ANativeWindow> anw(mSurface);
105 int result = -123;
106 int err = anw->query(anw.get(), NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER,
107 &result);
108 EXPECT_EQ(NO_ERROR, err);
109 EXPECT_EQ(1, result);
110}
111
Jamie Gennis7a4d0df2011-03-09 17:05:02 -0800112// This test probably doesn't belong here.
Jamie Gennisc901ca02011-10-11 16:02:31 -0700113TEST_F(SurfaceTest, ScreenshotsOfProtectedBuffersSucceed) {
Jamie Gennis7a4d0df2011-03-09 17:05:02 -0800114 sp<ANativeWindow> anw(mSurface);
115
116 // Verify the screenshot works with no protected buffers.
Dan Stoza5603a2f2014-04-07 13:41:37 -0700117 sp<IGraphicBufferProducer> producer;
118 sp<IGraphicBufferConsumer> consumer;
119 BufferQueue::createBufferQueue(&producer, &consumer);
120 sp<CpuConsumer> cpuConsumer = new CpuConsumer(consumer, 1);
Jamie Gennis7a4d0df2011-03-09 17:05:02 -0800121 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
Brian Anderson3da8d272016-07-28 16:20:47 -0700122 sp<IBinder> display(sf->getBuiltInDisplay(
123 ISurfaceComposer::eDisplayIdMain));
Dan Stozac1879002014-05-22 15:59:05 -0700124 ASSERT_EQ(NO_ERROR, sf->captureScreen(display, producer, Rect(),
Dan Stoza8d759962014-02-19 18:35:30 -0800125 64, 64, 0, 0x7fffffff, false));
Jamie Gennis7a4d0df2011-03-09 17:05:02 -0800126
Pablo Ceballos583b1b32015-09-03 18:23:52 -0700127 ASSERT_EQ(NO_ERROR, native_window_api_connect(anw.get(),
128 NATIVE_WINDOW_API_CPU));
Jamie Gennis7a4d0df2011-03-09 17:05:02 -0800129 // Set the PROTECTED usage bit and verify that the screenshot fails. Note
130 // that we need to dequeue a buffer in order for it to actually get
131 // allocated in SurfaceFlinger.
132 ASSERT_EQ(NO_ERROR, native_window_set_usage(anw.get(),
133 GRALLOC_USAGE_PROTECTED));
134 ASSERT_EQ(NO_ERROR, native_window_set_buffer_count(anw.get(), 3));
Iliyan Malchev697526b2011-05-01 11:33:26 -0700135 ANativeWindowBuffer* buf = 0;
Mathias Agopian9303eee2011-07-01 15:27:27 -0700136
Jamie Gennisd8e812c2012-06-13 16:32:25 -0700137 status_t err = native_window_dequeue_buffer_and_wait(anw.get(), &buf);
Mathias Agopian9303eee2011-07-01 15:27:27 -0700138 if (err) {
139 // we could fail if GRALLOC_USAGE_PROTECTED is not supported.
140 // that's okay as long as this is the reason for the failure.
141 // try again without the GRALLOC_USAGE_PROTECTED bit.
142 ASSERT_EQ(NO_ERROR, native_window_set_usage(anw.get(), 0));
Jamie Gennisd8e812c2012-06-13 16:32:25 -0700143 ASSERT_EQ(NO_ERROR, native_window_dequeue_buffer_and_wait(anw.get(),
144 &buf));
Mathias Agopian9303eee2011-07-01 15:27:27 -0700145 return;
146 }
Jamie Gennisd8e812c2012-06-13 16:32:25 -0700147 ASSERT_EQ(NO_ERROR, anw->cancelBuffer(anw.get(), buf, -1));
Mathias Agopian9303eee2011-07-01 15:27:27 -0700148
Jamie Gennis7a4d0df2011-03-09 17:05:02 -0800149 for (int i = 0; i < 4; i++) {
150 // Loop to make sure SurfaceFlinger has retired a protected buffer.
Jamie Gennisd8e812c2012-06-13 16:32:25 -0700151 ASSERT_EQ(NO_ERROR, native_window_dequeue_buffer_and_wait(anw.get(),
152 &buf));
153 ASSERT_EQ(NO_ERROR, anw->queueBuffer(anw.get(), buf, -1));
Jamie Gennis7a4d0df2011-03-09 17:05:02 -0800154 }
Dan Stozac1879002014-05-22 15:59:05 -0700155 ASSERT_EQ(NO_ERROR, sf->captureScreen(display, producer, Rect(),
Dan Stoza8d759962014-02-19 18:35:30 -0800156 64, 64, 0, 0x7fffffff, false));
Jamie Gennis7a4d0df2011-03-09 17:05:02 -0800157}
158
Jamie Gennis391bbe22011-03-14 15:00:06 -0700159TEST_F(SurfaceTest, ConcreteTypeIsSurface) {
160 sp<ANativeWindow> anw(mSurface);
161 int result = -123;
162 int err = anw->query(anw.get(), NATIVE_WINDOW_CONCRETE_TYPE, &result);
163 EXPECT_EQ(NO_ERROR, err);
164 EXPECT_EQ(NATIVE_WINDOW_SURFACE, result);
165}
166
Craig Donner6ebc46a2016-10-21 15:23:44 -0700167TEST_F(SurfaceTest, LayerCountIsOne) {
168 sp<ANativeWindow> anw(mSurface);
169 int result = -123;
170 int err = anw->query(anw.get(), NATIVE_WINDOW_LAYER_COUNT, &result);
171 EXPECT_EQ(NO_ERROR, err);
172 EXPECT_EQ(1, result);
173}
174
Eino-Ville Talvalaf7c60872013-07-30 14:05:02 -0700175TEST_F(SurfaceTest, QueryConsumerUsage) {
176 const int TEST_USAGE_FLAGS =
177 GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_HW_RENDER;
Dan Stoza5603a2f2014-04-07 13:41:37 -0700178 sp<IGraphicBufferProducer> producer;
179 sp<IGraphicBufferConsumer> consumer;
180 BufferQueue::createBufferQueue(&producer, &consumer);
181 sp<BufferItemConsumer> c = new BufferItemConsumer(consumer,
Eino-Ville Talvalaf7c60872013-07-30 14:05:02 -0700182 TEST_USAGE_FLAGS);
Dan Stoza5603a2f2014-04-07 13:41:37 -0700183 sp<Surface> s = new Surface(producer);
Eino-Ville Talvalaf7c60872013-07-30 14:05:02 -0700184
185 sp<ANativeWindow> anw(s);
186
187 int flags = -1;
188 int err = anw->query(anw.get(), NATIVE_WINDOW_CONSUMER_USAGE_BITS, &flags);
189
190 ASSERT_EQ(NO_ERROR, err);
191 ASSERT_EQ(TEST_USAGE_FLAGS, flags);
192}
193
Eino-Ville Talvala5b75a512015-02-19 16:10:43 -0800194TEST_F(SurfaceTest, QueryDefaultBuffersDataSpace) {
195 const android_dataspace TEST_DATASPACE = HAL_DATASPACE_SRGB;
196 sp<IGraphicBufferProducer> producer;
197 sp<IGraphicBufferConsumer> consumer;
198 BufferQueue::createBufferQueue(&producer, &consumer);
199 sp<CpuConsumer> cpuConsumer = new CpuConsumer(consumer, 1);
200
201 cpuConsumer->setDefaultBufferDataSpace(TEST_DATASPACE);
202
203 sp<Surface> s = new Surface(producer);
204
205 sp<ANativeWindow> anw(s);
206
207 android_dataspace dataSpace;
208
209 int err = anw->query(anw.get(), NATIVE_WINDOW_DEFAULT_DATASPACE,
210 reinterpret_cast<int*>(&dataSpace));
211
212 ASSERT_EQ(NO_ERROR, err);
213 ASSERT_EQ(TEST_DATASPACE, dataSpace);
214}
215
Dan Stoza812ed062015-06-02 15:45:22 -0700216TEST_F(SurfaceTest, SettingGenerationNumber) {
217 sp<IGraphicBufferProducer> producer;
218 sp<IGraphicBufferConsumer> consumer;
219 BufferQueue::createBufferQueue(&producer, &consumer);
220 sp<CpuConsumer> cpuConsumer = new CpuConsumer(consumer, 1);
221 sp<Surface> surface = new Surface(producer);
222 sp<ANativeWindow> window(surface);
223
224 // Allocate a buffer with a generation number of 0
225 ANativeWindowBuffer* buffer;
226 int fenceFd;
Pablo Ceballos583b1b32015-09-03 18:23:52 -0700227 ASSERT_EQ(NO_ERROR, native_window_api_connect(window.get(),
228 NATIVE_WINDOW_API_CPU));
Dan Stoza812ed062015-06-02 15:45:22 -0700229 ASSERT_EQ(NO_ERROR, window->dequeueBuffer(window.get(), &buffer, &fenceFd));
230 ASSERT_EQ(NO_ERROR, window->cancelBuffer(window.get(), buffer, fenceFd));
231
232 // Detach the buffer and check its generation number
233 sp<GraphicBuffer> graphicBuffer;
234 sp<Fence> fence;
235 ASSERT_EQ(NO_ERROR, surface->detachNextBuffer(&graphicBuffer, &fence));
236 ASSERT_EQ(0U, graphicBuffer->getGenerationNumber());
237
238 ASSERT_EQ(NO_ERROR, surface->setGenerationNumber(1));
239 buffer = static_cast<ANativeWindowBuffer*>(graphicBuffer.get());
240
241 // This should change the generation number of the GraphicBuffer
242 ASSERT_EQ(NO_ERROR, surface->attachBuffer(buffer));
243
244 // Check that the new generation number sticks with the buffer
245 ASSERT_EQ(NO_ERROR, window->cancelBuffer(window.get(), buffer, -1));
246 ASSERT_EQ(NO_ERROR, window->dequeueBuffer(window.get(), &buffer, &fenceFd));
247 graphicBuffer = static_cast<GraphicBuffer*>(buffer);
248 ASSERT_EQ(1U, graphicBuffer->getGenerationNumber());
249}
250
Dan Stozac6f30bd2015-06-08 09:32:50 -0700251TEST_F(SurfaceTest, GetConsumerName) {
252 sp<IGraphicBufferProducer> producer;
253 sp<IGraphicBufferConsumer> consumer;
254 BufferQueue::createBufferQueue(&producer, &consumer);
255
256 sp<DummyConsumer> dummyConsumer(new DummyConsumer);
257 consumer->consumerConnect(dummyConsumer, false);
258 consumer->setConsumerName(String8("TestConsumer"));
259
260 sp<Surface> surface = new Surface(producer);
261 sp<ANativeWindow> window(surface);
262 native_window_api_connect(window.get(), NATIVE_WINDOW_API_CPU);
263
264 EXPECT_STREQ("TestConsumer", surface->getConsumerName().string());
265}
266
Courtney Goeltzenleuchter1eb1b272017-02-02 16:51:06 -0700267TEST_F(SurfaceTest, GetWideColorSupport) {
268 sp<IGraphicBufferProducer> producer;
269 sp<IGraphicBufferConsumer> consumer;
270 BufferQueue::createBufferQueue(&producer, &consumer);
271
272 sp<DummyConsumer> dummyConsumer(new DummyConsumer);
273 consumer->consumerConnect(dummyConsumer, false);
274 consumer->setConsumerName(String8("TestConsumer"));
275
276 sp<Surface> surface = new Surface(producer);
277 sp<ANativeWindow> window(surface);
278 native_window_api_connect(window.get(), NATIVE_WINDOW_API_CPU);
279
280 bool supported;
281 surface->getWideColorSupport(&supported);
282
Courtney Goeltzenleuchter6a570b62017-03-13 14:30:00 -0600283 // NOTE: This test assumes that device that supports
284 // wide-color (as indicated by BoardConfig) must also
285 // have a wide-color primary display.
286 // That assumption allows this test to cover devices
287 // that advertised a wide-color color mode without
288 // actually supporting wide-color to pass this test
289 // as well as the case of a device that does support
290 // wide-color (via BoardConfig) and has a wide-color
291 // primary display.
292 // NOT covered at this time is a device that supports
293 // wide color in the BoardConfig but does not support
294 // a wide-color color mode on the primary display.
295 ASSERT_EQ(hasWideColorDisplay, supported);
Courtney Goeltzenleuchter1eb1b272017-02-02 16:51:06 -0700296}
297
Pablo Ceballos789a0c82016-02-05 13:39:27 -0800298TEST_F(SurfaceTest, DynamicSetBufferCount) {
299 sp<IGraphicBufferProducer> producer;
300 sp<IGraphicBufferConsumer> consumer;
301 BufferQueue::createBufferQueue(&producer, &consumer);
302
303 sp<DummyConsumer> dummyConsumer(new DummyConsumer);
304 consumer->consumerConnect(dummyConsumer, false);
305 consumer->setConsumerName(String8("TestConsumer"));
306
307 sp<Surface> surface = new Surface(producer);
308 sp<ANativeWindow> window(surface);
309
310 ASSERT_EQ(NO_ERROR, native_window_api_connect(window.get(),
311 NATIVE_WINDOW_API_CPU));
312 native_window_set_buffer_count(window.get(), 4);
313
314 int fence;
315 ANativeWindowBuffer* buffer;
316 ASSERT_EQ(NO_ERROR, window->dequeueBuffer(window.get(), &buffer, &fence));
317 native_window_set_buffer_count(window.get(), 3);
318 ASSERT_EQ(NO_ERROR, window->queueBuffer(window.get(), buffer, fence));
319 native_window_set_buffer_count(window.get(), 2);
320 ASSERT_EQ(NO_ERROR, window->dequeueBuffer(window.get(), &buffer, &fence));
321 ASSERT_EQ(NO_ERROR, window->queueBuffer(window.get(), buffer, fence));
322}
323
Yin-Chia Yeh1f2af5c2017-05-11 16:54:04 -0700324TEST_F(SurfaceTest, GetAndFlushRemovedBuffers) {
325 sp<IGraphicBufferProducer> producer;
326 sp<IGraphicBufferConsumer> consumer;
327 BufferQueue::createBufferQueue(&producer, &consumer);
328
329 sp<DummyConsumer> dummyConsumer(new DummyConsumer);
330 consumer->consumerConnect(dummyConsumer, false);
331 consumer->setConsumerName(String8("TestConsumer"));
332
333 sp<Surface> surface = new Surface(producer);
334 sp<ANativeWindow> window(surface);
335 sp<DummyProducerListener> listener = new DummyProducerListener();
336 ASSERT_EQ(OK, surface->connect(
337 NATIVE_WINDOW_API_CPU,
338 /*listener*/listener,
339 /*reportBufferRemoval*/true));
340 const int BUFFER_COUNT = 4;
341 ASSERT_EQ(NO_ERROR, native_window_set_buffer_count(window.get(), BUFFER_COUNT));
342
343 sp<GraphicBuffer> detachedBuffer;
344 sp<Fence> outFence;
345 int fences[BUFFER_COUNT];
346 ANativeWindowBuffer* buffers[BUFFER_COUNT];
347 // Allocate buffers because detachNextBuffer requires allocated buffers
348 for (int i = 0; i < BUFFER_COUNT; i++) {
349 ASSERT_EQ(NO_ERROR, window->dequeueBuffer(window.get(), &buffers[i], &fences[i]));
350 }
351 for (int i = 0; i < BUFFER_COUNT; i++) {
352 ASSERT_EQ(NO_ERROR, window->cancelBuffer(window.get(), buffers[i], fences[i]));
353 }
354
355 // Test detached buffer is correctly reported
356 ASSERT_EQ(NO_ERROR, surface->detachNextBuffer(&detachedBuffer, &outFence));
357 std::vector<sp<GraphicBuffer>> removedBuffers;
358 ASSERT_EQ(OK, surface->getAndFlushRemovedBuffers(&removedBuffers));
359 ASSERT_EQ(1u, removedBuffers.size());
360 ASSERT_EQ(detachedBuffer->handle, removedBuffers.at(0)->handle);
361 // Test the list is flushed one getAndFlushRemovedBuffers returns
362 ASSERT_EQ(OK, surface->getAndFlushRemovedBuffers(&removedBuffers));
363 ASSERT_EQ(0u, removedBuffers.size());
364
365
366 // Test removed buffer list is cleanup after next dequeueBuffer call
367 ASSERT_EQ(NO_ERROR, surface->detachNextBuffer(&detachedBuffer, &outFence));
368 ASSERT_EQ(NO_ERROR, window->dequeueBuffer(window.get(), &buffers[0], &fences[0]));
369 ASSERT_EQ(OK, surface->getAndFlushRemovedBuffers(&removedBuffers));
370 ASSERT_EQ(0u, removedBuffers.size());
371 ASSERT_EQ(NO_ERROR, window->cancelBuffer(window.get(), buffers[0], fences[0]));
372
373 // Test removed buffer list is cleanup after next detachNextBuffer call
374 ASSERT_EQ(NO_ERROR, surface->detachNextBuffer(&detachedBuffer, &outFence));
375 ASSERT_EQ(NO_ERROR, surface->detachNextBuffer(&detachedBuffer, &outFence));
376 ASSERT_EQ(OK, surface->getAndFlushRemovedBuffers(&removedBuffers));
377 ASSERT_EQ(1u, removedBuffers.size());
378 ASSERT_EQ(detachedBuffer->handle, removedBuffers.at(0)->handle);
379
380 // Re-allocate buffers since all buffers are detached up to now
381 for (int i = 0; i < BUFFER_COUNT; i++) {
382 ASSERT_EQ(NO_ERROR, window->dequeueBuffer(window.get(), &buffers[i], &fences[i]));
383 }
384 for (int i = 0; i < BUFFER_COUNT; i++) {
385 ASSERT_EQ(NO_ERROR, window->cancelBuffer(window.get(), buffers[i], fences[i]));
386 }
387
388 ASSERT_EQ(NO_ERROR, surface->detachNextBuffer(&detachedBuffer, &outFence));
389 ASSERT_EQ(NO_ERROR, surface->attachBuffer(detachedBuffer.get()));
390 ASSERT_EQ(OK, surface->getAndFlushRemovedBuffers(&removedBuffers));
391 // Depends on which slot GraphicBufferProducer impl pick, the attach call might
392 // get 0 or 1 buffer removed.
393 ASSERT_LE(removedBuffers.size(), 1u);
394}
Brian Anderson3da8d272016-07-28 16:20:47 -0700395
Dan Stoza932f0082017-05-31 13:50:16 -0700396TEST_F(SurfaceTest, TestGetLastDequeueStartTime) {
397 sp<ANativeWindow> anw(mSurface);
398 ASSERT_EQ(NO_ERROR, native_window_api_connect(anw.get(), NATIVE_WINDOW_API_CPU));
399
400 ANativeWindowBuffer* buffer = nullptr;
401 int32_t fenceFd = -1;
402
403 nsecs_t before = systemTime(CLOCK_MONOTONIC);
404 anw->dequeueBuffer(anw.get(), &buffer, &fenceFd);
405 nsecs_t after = systemTime(CLOCK_MONOTONIC);
406
407 nsecs_t lastDequeueTime = mSurface->getLastDequeueStartTime();
408 ASSERT_LE(before, lastDequeueTime);
409 ASSERT_GE(after, lastDequeueTime);
410}
411
Brian Anderson3da8d272016-07-28 16:20:47 -0700412class FakeConsumer : public BnConsumerListener {
413public:
414 void onFrameAvailable(const BufferItem& /*item*/) override {}
415 void onBuffersReleased() override {}
416 void onSidebandStreamChanged() override {}
417
418 void addAndGetFrameTimestamps(
419 const NewFrameEventsEntry* newTimestamps,
420 FrameEventHistoryDelta* outDelta) override {
421 if (newTimestamps) {
422 if (mGetFrameTimestampsEnabled) {
423 EXPECT_GT(mNewFrameEntryOverride.frameNumber, 0u) <<
424 "Test should set mNewFrameEntryOverride before queuing "
425 "a frame.";
426 EXPECT_EQ(newTimestamps->frameNumber,
427 mNewFrameEntryOverride.frameNumber) <<
428 "Test attempting to add NewFrameEntryOverride with "
429 "incorrect frame number.";
430 mFrameEventHistory.addQueue(mNewFrameEntryOverride);
431 mNewFrameEntryOverride.frameNumber = 0;
432 }
433 mAddFrameTimestampsCount++;
434 mLastAddedFrameNumber = newTimestamps->frameNumber;
435 }
436 if (outDelta) {
437 mFrameEventHistory.getAndResetDelta(outDelta);
438 mGetFrameTimestampsCount++;
439 }
440 mAddAndGetFrameTimestampsCallCount++;
441 }
442
443 bool mGetFrameTimestampsEnabled = false;
444
445 ConsumerFrameEventHistory mFrameEventHistory;
446 int mAddAndGetFrameTimestampsCallCount = 0;
447 int mAddFrameTimestampsCount = 0;
448 int mGetFrameTimestampsCount = 0;
449 uint64_t mLastAddedFrameNumber = NO_FRAME_INDEX;
450
451 NewFrameEventsEntry mNewFrameEntryOverride = { 0, 0, 0, nullptr };
452};
453
454
455class FakeSurfaceComposer : public ISurfaceComposer{
456public:
457 ~FakeSurfaceComposer() override {}
458
Brian Anderson6b376712017-04-04 10:51:39 -0700459 void setSupportsPresent(bool supportsPresent) {
460 mSupportsPresent = supportsPresent;
461 }
462
Brian Anderson3da8d272016-07-28 16:20:47 -0700463 sp<ISurfaceComposerClient> createConnection() override { return nullptr; }
Robert Carr1db73f62016-12-21 12:58:51 -0800464 sp<ISurfaceComposerClient> createScopedConnection(
465 const sp<IGraphicBufferProducer>& /* parent */) override {
466 return nullptr;
467 }
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700468 sp<IDisplayEventConnection> createDisplayEventConnection(ISurfaceComposer::VsyncSource)
469 override {
Brian Anderson3da8d272016-07-28 16:20:47 -0700470 return nullptr;
471 }
472 sp<IBinder> createDisplay(const String8& /*displayName*/,
473 bool /*secure*/) override { return nullptr; }
474 void destroyDisplay(const sp<IBinder>& /*display */) override {}
475 sp<IBinder> getBuiltInDisplay(int32_t /*id*/) override { return nullptr; }
476 void setTransactionState(const Vector<ComposerState>& /*state*/,
477 const Vector<DisplayState>& /*displays*/, uint32_t /*flags*/)
478 override {}
479 void bootFinished() override {}
480 bool authenticateSurfaceTexture(
481 const sp<IGraphicBufferProducer>& /*surface*/) const override {
482 return false;
483 }
Brian Anderson6b376712017-04-04 10:51:39 -0700484
485 status_t getSupportedFrameTimestamps(std::vector<FrameEvent>* outSupported)
486 const override {
487 *outSupported = {
488 FrameEvent::REQUESTED_PRESENT,
489 FrameEvent::ACQUIRE,
490 FrameEvent::LATCH,
491 FrameEvent::FIRST_REFRESH_START,
492 FrameEvent::LAST_REFRESH_START,
493 FrameEvent::GPU_COMPOSITION_DONE,
494 FrameEvent::DEQUEUE_READY,
495 FrameEvent::RELEASE
496 };
497 if (mSupportsPresent) {
498 outSupported->push_back(
499 FrameEvent::DISPLAY_PRESENT);
500 }
501 return NO_ERROR;
502 }
503
Brian Anderson3da8d272016-07-28 16:20:47 -0700504 void setPowerMode(const sp<IBinder>& /*display*/, int /*mode*/) override {}
505 status_t getDisplayConfigs(const sp<IBinder>& /*display*/,
506 Vector<DisplayInfo>* /*configs*/) override { return NO_ERROR; }
507 status_t getDisplayStats(const sp<IBinder>& /*display*/,
508 DisplayStatInfo* /*stats*/) override { return NO_ERROR; }
509 int getActiveConfig(const sp<IBinder>& /*display*/) override { return 0; }
510 status_t setActiveConfig(const sp<IBinder>& /*display*/, int /*id*/)
511 override {
512 return NO_ERROR;
513 }
514 status_t getDisplayColorModes(const sp<IBinder>& /*display*/,
515 Vector<android_color_mode_t>* /*outColorModes*/) override {
516 return NO_ERROR;
517 }
518 android_color_mode_t getActiveColorMode(const sp<IBinder>& /*display*/)
519 override {
520 return HAL_COLOR_MODE_NATIVE;
521 }
522 status_t setActiveColorMode(const sp<IBinder>& /*display*/,
523 android_color_mode_t /*colorMode*/) override { return NO_ERROR; }
524 status_t captureScreen(const sp<IBinder>& /*display*/,
525 const sp<IGraphicBufferProducer>& /*producer*/,
526 Rect /*sourceCrop*/, uint32_t /*reqWidth*/, uint32_t /*reqHeight*/,
Robert Carrae060832016-11-28 10:51:00 -0800527 int32_t /*minLayerZ*/, int32_t /*maxLayerZ*/,
Brian Anderson3da8d272016-07-28 16:20:47 -0700528 bool /*useIdentityTransform*/,
529 Rotation /*rotation*/) override { return NO_ERROR; }
530 status_t clearAnimationFrameStats() override { return NO_ERROR; }
531 status_t getAnimationFrameStats(FrameStats* /*outStats*/) const override {
532 return NO_ERROR;
533 }
534 status_t getHdrCapabilities(const sp<IBinder>& /*display*/,
535 HdrCapabilities* /*outCapabilities*/) const override {
536 return NO_ERROR;
537 }
538 status_t enableVSyncInjections(bool /*enable*/) override {
539 return NO_ERROR;
540 }
541 status_t injectVSync(nsecs_t /*when*/) override { return NO_ERROR; }
542
543protected:
544 IBinder* onAsBinder() override { return nullptr; }
545
546private:
547 bool mSupportsPresent{true};
Brian Anderson3da8d272016-07-28 16:20:47 -0700548};
549
550class FakeProducerFrameEventHistory : public ProducerFrameEventHistory {
551public:
552 FakeProducerFrameEventHistory(FenceToFenceTimeMap* fenceMap)
553 : mFenceMap(fenceMap) {}
554
555 ~FakeProducerFrameEventHistory() {}
556
557 void updateAcquireFence(uint64_t frameNumber,
558 std::shared_ptr<FenceTime>&& acquire) override {
559 // Verify the acquire fence being added isn't the one from the consumer.
560 EXPECT_NE(mConsumerAcquireFence, acquire);
561 // Override the fence, so we can verify this was called by the
562 // producer after the frame is queued.
563 ProducerFrameEventHistory::updateAcquireFence(frameNumber,
564 std::shared_ptr<FenceTime>(mAcquireFenceOverride));
565 }
566
567 void setAcquireFenceOverride(
568 const std::shared_ptr<FenceTime>& acquireFenceOverride,
569 const std::shared_ptr<FenceTime>& consumerAcquireFence) {
570 mAcquireFenceOverride = acquireFenceOverride;
571 mConsumerAcquireFence = consumerAcquireFence;
572 }
573
574protected:
575 std::shared_ptr<FenceTime> createFenceTime(const sp<Fence>& fence)
576 const override {
577 return mFenceMap->createFenceTimeForTest(fence);
578 }
579
580 FenceToFenceTimeMap* mFenceMap{nullptr};
581
582 std::shared_ptr<FenceTime> mAcquireFenceOverride{FenceTime::NO_FENCE};
583 std::shared_ptr<FenceTime> mConsumerAcquireFence{FenceTime::NO_FENCE};
584};
585
586
587class TestSurface : public Surface {
588public:
589 TestSurface(const sp<IGraphicBufferProducer>& bufferProducer,
590 FenceToFenceTimeMap* fenceMap)
591 : Surface(bufferProducer),
592 mFakeSurfaceComposer(new FakeSurfaceComposer) {
593 mFakeFrameEventHistory = new FakeProducerFrameEventHistory(fenceMap);
594 mFrameEventHistory.reset(mFakeFrameEventHistory);
595 }
596
597 ~TestSurface() override {}
598
599 sp<ISurfaceComposer> composerService() const override {
600 return mFakeSurfaceComposer;
601 }
602
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800603 nsecs_t now() const override {
604 return mNow;
605 }
606
607 void setNow(nsecs_t now) {
608 mNow = now;
609 }
610
Brian Anderson3da8d272016-07-28 16:20:47 -0700611public:
612 sp<FakeSurfaceComposer> mFakeSurfaceComposer;
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800613 nsecs_t mNow = 0;
Brian Anderson3da8d272016-07-28 16:20:47 -0700614
615 // mFrameEventHistory owns the instance of FakeProducerFrameEventHistory,
616 // but this raw pointer gives access to test functionality.
617 FakeProducerFrameEventHistory* mFakeFrameEventHistory;
618};
619
620
Brian Andersond0010582017-03-07 13:20:31 -0800621class GetFrameTimestampsTest : public ::testing::Test {
Brian Anderson3da8d272016-07-28 16:20:47 -0700622protected:
623 struct FenceAndFenceTime {
624 explicit FenceAndFenceTime(FenceToFenceTimeMap& fenceMap)
625 : mFence(new Fence),
626 mFenceTime(fenceMap.createFenceTimeForTest(mFence)) {}
627 sp<Fence> mFence { nullptr };
628 std::shared_ptr<FenceTime> mFenceTime { nullptr };
629 };
630
631 struct RefreshEvents {
632 RefreshEvents(FenceToFenceTimeMap& fenceMap, nsecs_t refreshStart)
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800633 : mFenceMap(fenceMap),
634 kCompositorTiming(
635 {refreshStart, refreshStart + 1, refreshStart + 2 }),
636 kStartTime(refreshStart + 3),
637 kGpuCompositionDoneTime(refreshStart + 4),
638 kPresentTime(refreshStart + 5) {}
Brian Anderson3da8d272016-07-28 16:20:47 -0700639
640 void signalPostCompositeFences() {
641 mFenceMap.signalAllForTest(
642 mGpuCompositionDone.mFence, kGpuCompositionDoneTime);
643 mFenceMap.signalAllForTest(mPresent.mFence, kPresentTime);
644 }
645
646 FenceToFenceTimeMap& mFenceMap;
647
648 FenceAndFenceTime mGpuCompositionDone { mFenceMap };
649 FenceAndFenceTime mPresent { mFenceMap };
650
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800651 const CompositorTiming kCompositorTiming;
652
Brian Anderson3da8d272016-07-28 16:20:47 -0700653 const nsecs_t kStartTime;
654 const nsecs_t kGpuCompositionDoneTime;
655 const nsecs_t kPresentTime;
656 };
657
658 struct FrameEvents {
659 FrameEvents(FenceToFenceTimeMap& fenceMap, nsecs_t frameStartTime)
660 : mFenceMap(fenceMap),
661 kPostedTime(frameStartTime + 100),
662 kRequestedPresentTime(frameStartTime + 200),
663 kProducerAcquireTime(frameStartTime + 300),
664 kConsumerAcquireTime(frameStartTime + 301),
665 kLatchTime(frameStartTime + 500),
Brian Andersonf6386862016-10-31 16:34:13 -0700666 kDequeueReadyTime(frameStartTime + 600),
Brian Anderson4e606e32017-03-16 15:34:57 -0700667 kReleaseTime(frameStartTime + 700),
Brian Anderson3da8d272016-07-28 16:20:47 -0700668 mRefreshes {
669 { mFenceMap, frameStartTime + 410 },
670 { mFenceMap, frameStartTime + 420 },
671 { mFenceMap, frameStartTime + 430 } } {}
672
673 void signalQueueFences() {
674 mFenceMap.signalAllForTest(
675 mAcquireConsumer.mFence, kConsumerAcquireTime);
676 mFenceMap.signalAllForTest(
677 mAcquireProducer.mFence, kProducerAcquireTime);
678 }
679
680 void signalRefreshFences() {
681 for (auto& re : mRefreshes) {
682 re.signalPostCompositeFences();
683 }
684 }
685
686 void signalReleaseFences() {
Brian Anderson3da8d272016-07-28 16:20:47 -0700687 mFenceMap.signalAllForTest(mRelease.mFence, kReleaseTime);
688 }
689
690 FenceToFenceTimeMap& mFenceMap;
691
692 FenceAndFenceTime mAcquireConsumer { mFenceMap };
693 FenceAndFenceTime mAcquireProducer { mFenceMap };
Brian Anderson3da8d272016-07-28 16:20:47 -0700694 FenceAndFenceTime mRelease { mFenceMap };
695
696 const nsecs_t kPostedTime;
697 const nsecs_t kRequestedPresentTime;
698 const nsecs_t kProducerAcquireTime;
699 const nsecs_t kConsumerAcquireTime;
700 const nsecs_t kLatchTime;
Brian Andersonf6386862016-10-31 16:34:13 -0700701 const nsecs_t kDequeueReadyTime;
Brian Anderson3da8d272016-07-28 16:20:47 -0700702 const nsecs_t kReleaseTime;
703
704 RefreshEvents mRefreshes[3];
705 };
706
Brian Andersond0010582017-03-07 13:20:31 -0800707 GetFrameTimestampsTest() {}
Brian Anderson3da8d272016-07-28 16:20:47 -0700708
709 virtual void SetUp() {
Brian Anderson3da8d272016-07-28 16:20:47 -0700710 BufferQueue::createBufferQueue(&mProducer, &mConsumer);
711 mFakeConsumer = new FakeConsumer;
712 mCfeh = &mFakeConsumer->mFrameEventHistory;
713 mConsumer->consumerConnect(mFakeConsumer, false);
714 mConsumer->setConsumerName(String8("TestConsumer"));
715 mSurface = new TestSurface(mProducer, &mFenceMap);
716 mWindow = mSurface;
717
718 ASSERT_EQ(NO_ERROR, native_window_api_connect(mWindow.get(),
719 NATIVE_WINDOW_API_CPU));
720 native_window_set_buffer_count(mWindow.get(), 4);
721 }
722
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800723 void disableFrameTimestamps() {
724 mFakeConsumer->mGetFrameTimestampsEnabled = false;
725 native_window_enable_frame_timestamps(mWindow.get(), 0);
726 mFrameTimestampsEnabled = false;
727 }
728
Brian Anderson3da8d272016-07-28 16:20:47 -0700729 void enableFrameTimestamps() {
730 mFakeConsumer->mGetFrameTimestampsEnabled = true;
731 native_window_enable_frame_timestamps(mWindow.get(), 1);
732 mFrameTimestampsEnabled = true;
733 }
734
Brian Anderson1049d1d2016-12-16 17:25:57 -0800735 int getAllFrameTimestamps(uint64_t frameId) {
736 return native_window_get_frame_timestamps(mWindow.get(), frameId,
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700737 &outRequestedPresentTime, &outAcquireTime, &outLatchTime,
738 &outFirstRefreshStartTime, &outLastRefreshStartTime,
739 &outGpuCompositionDoneTime, &outDisplayPresentTime,
Brian Anderson4e606e32017-03-16 15:34:57 -0700740 &outDequeueReadyTime, &outReleaseTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700741 }
742
Brian Anderson3da8d272016-07-28 16:20:47 -0700743 void resetTimestamps() {
744 outRequestedPresentTime = -1;
745 outAcquireTime = -1;
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700746 outLatchTime = -1;
747 outFirstRefreshStartTime = -1;
748 outLastRefreshStartTime = -1;
Brian Anderson3da8d272016-07-28 16:20:47 -0700749 outGpuCompositionDoneTime = -1;
750 outDisplayPresentTime = -1;
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700751 outDequeueReadyTime = -1;
Brian Anderson3da8d272016-07-28 16:20:47 -0700752 outReleaseTime = -1;
753 }
754
Brian Anderson1049d1d2016-12-16 17:25:57 -0800755 uint64_t getNextFrameId() {
756 uint64_t frameId = -1;
757 int status = native_window_get_next_frame_id(mWindow.get(), &frameId);
758 EXPECT_EQ(status, NO_ERROR);
759 return frameId;
760 }
761
Brian Anderson3da8d272016-07-28 16:20:47 -0700762 void dequeueAndQueue(uint64_t frameIndex) {
763 int fence = -1;
764 ANativeWindowBuffer* buffer = nullptr;
765 ASSERT_EQ(NO_ERROR,
766 mWindow->dequeueBuffer(mWindow.get(), &buffer, &fence));
767
768 int oldAddFrameTimestampsCount =
769 mFakeConsumer->mAddFrameTimestampsCount;
770
771 FrameEvents* frame = &mFrames[frameIndex];
772 uint64_t frameNumber = frameIndex + 1;
773
774 NewFrameEventsEntry fe;
775 fe.frameNumber = frameNumber;
776 fe.postedTime = frame->kPostedTime;
777 fe.requestedPresentTime = frame->kRequestedPresentTime;
778 fe.acquireFence = frame->mAcquireConsumer.mFenceTime;
779 mFakeConsumer->mNewFrameEntryOverride = fe;
780
781 mSurface->mFakeFrameEventHistory->setAcquireFenceOverride(
782 frame->mAcquireProducer.mFenceTime,
783 frame->mAcquireConsumer.mFenceTime);
784
785 ASSERT_EQ(NO_ERROR, mWindow->queueBuffer(mWindow.get(), buffer, fence));
786
787 EXPECT_EQ(frameNumber, mFakeConsumer->mLastAddedFrameNumber);
788
789 EXPECT_EQ(
790 oldAddFrameTimestampsCount + (mFrameTimestampsEnabled ? 1 : 0),
791 mFakeConsumer->mAddFrameTimestampsCount);
792 }
793
794 void addFrameEvents(
795 bool gpuComposited, uint64_t iOldFrame, int64_t iNewFrame) {
796 FrameEvents* oldFrame =
797 (iOldFrame == NO_FRAME_INDEX) ? nullptr : &mFrames[iOldFrame];
798 FrameEvents* newFrame = &mFrames[iNewFrame];
799
800 uint64_t nOldFrame = iOldFrame + 1;
801 uint64_t nNewFrame = iNewFrame + 1;
802
Brian Anderson4e606e32017-03-16 15:34:57 -0700803 // Latch, Composite, and Release the frames in a plausible order.
804 // Note: The timestamps won't necessarily match the order, but
Brian Anderson3da8d272016-07-28 16:20:47 -0700805 // that's okay for the purposes of this test.
806 std::shared_ptr<FenceTime> gpuDoneFenceTime = FenceTime::NO_FENCE;
807
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700808 // Composite the previous frame one more time, which helps verify
809 // LastRefresh is updated properly.
810 if (oldFrame != nullptr) {
811 mCfeh->addPreComposition(nOldFrame,
812 oldFrame->mRefreshes[2].kStartTime);
813 gpuDoneFenceTime = gpuComposited ?
814 oldFrame->mRefreshes[2].mGpuCompositionDone.mFenceTime :
815 FenceTime::NO_FENCE;
816 mCfeh->addPostComposition(nOldFrame, gpuDoneFenceTime,
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800817 oldFrame->mRefreshes[2].mPresent.mFenceTime,
818 oldFrame->mRefreshes[2].kCompositorTiming);
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700819 }
820
821 // Latch the new frame.
Brian Anderson3da8d272016-07-28 16:20:47 -0700822 mCfeh->addLatch(nNewFrame, newFrame->kLatchTime);
823
824 mCfeh->addPreComposition(nNewFrame, newFrame->mRefreshes[0].kStartTime);
825 gpuDoneFenceTime = gpuComposited ?
826 newFrame->mRefreshes[0].mGpuCompositionDone.mFenceTime :
827 FenceTime::NO_FENCE;
828 // HWC2 releases the previous buffer after a new latch just before
829 // calling postComposition.
830 if (oldFrame != nullptr) {
Brian Andersonf6386862016-10-31 16:34:13 -0700831 mCfeh->addRelease(nOldFrame, oldFrame->kDequeueReadyTime,
Brian Anderson3da8d272016-07-28 16:20:47 -0700832 std::shared_ptr<FenceTime>(oldFrame->mRelease.mFenceTime));
833 }
834 mCfeh->addPostComposition(nNewFrame, gpuDoneFenceTime,
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800835 newFrame->mRefreshes[0].mPresent.mFenceTime,
836 newFrame->mRefreshes[0].kCompositorTiming);
Brian Anderson3da8d272016-07-28 16:20:47 -0700837
Brian Anderson3da8d272016-07-28 16:20:47 -0700838 mCfeh->addPreComposition(nNewFrame, newFrame->mRefreshes[1].kStartTime);
839 gpuDoneFenceTime = gpuComposited ?
840 newFrame->mRefreshes[1].mGpuCompositionDone.mFenceTime :
841 FenceTime::NO_FENCE;
842 mCfeh->addPostComposition(nNewFrame, gpuDoneFenceTime,
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800843 newFrame->mRefreshes[1].mPresent.mFenceTime,
844 newFrame->mRefreshes[1].kCompositorTiming);
Brian Anderson3da8d272016-07-28 16:20:47 -0700845 }
846
Brian Anderson3da8d272016-07-28 16:20:47 -0700847 sp<IGraphicBufferProducer> mProducer;
848 sp<IGraphicBufferConsumer> mConsumer;
849 sp<FakeConsumer> mFakeConsumer;
850 ConsumerFrameEventHistory* mCfeh;
851 sp<TestSurface> mSurface;
852 sp<ANativeWindow> mWindow;
853
854 FenceToFenceTimeMap mFenceMap;
855
856 bool mFrameTimestampsEnabled = false;
857
858 int64_t outRequestedPresentTime = -1;
859 int64_t outAcquireTime = -1;
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700860 int64_t outLatchTime = -1;
861 int64_t outFirstRefreshStartTime = -1;
862 int64_t outLastRefreshStartTime = -1;
Brian Anderson3da8d272016-07-28 16:20:47 -0700863 int64_t outGpuCompositionDoneTime = -1;
864 int64_t outDisplayPresentTime = -1;
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700865 int64_t outDequeueReadyTime = -1;
Brian Anderson3da8d272016-07-28 16:20:47 -0700866 int64_t outReleaseTime = -1;
867
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800868 FrameEvents mFrames[3] {
869 { mFenceMap, 1000 }, { mFenceMap, 2000 }, { mFenceMap, 3000 } };
Brian Anderson3da8d272016-07-28 16:20:47 -0700870};
871
872
873// This test verifies that the frame timestamps are not retrieved when not
874// explicitly enabled via native_window_enable_frame_timestamps.
875// We want to check this to make sure there's no overhead for users
876// that don't need the timestamp information.
877TEST_F(GetFrameTimestampsTest, DefaultDisabled) {
878 int fence;
879 ANativeWindowBuffer* buffer;
880
881 EXPECT_EQ(0, mFakeConsumer->mAddFrameTimestampsCount);
882 EXPECT_EQ(0, mFakeConsumer->mGetFrameTimestampsCount);
883
Brian Anderson1049d1d2016-12-16 17:25:57 -0800884 const uint64_t fId = getNextFrameId();
885
Brian Anderson3da8d272016-07-28 16:20:47 -0700886 // Verify the producer doesn't get frame timestamps piggybacked on dequeue.
887 ASSERT_EQ(NO_ERROR, mWindow->dequeueBuffer(mWindow.get(), &buffer, &fence));
888 EXPECT_EQ(0, mFakeConsumer->mAddFrameTimestampsCount);
889 EXPECT_EQ(0, mFakeConsumer->mGetFrameTimestampsCount);
890
891 // Verify the producer doesn't get frame timestamps piggybacked on queue.
892 // It is okay that frame timestamps are added in the consumer since it is
893 // still needed for SurfaceFlinger dumps.
894 ASSERT_EQ(NO_ERROR, mWindow->queueBuffer(mWindow.get(), buffer, fence));
895 EXPECT_EQ(1, mFakeConsumer->mAddFrameTimestampsCount);
896 EXPECT_EQ(0, mFakeConsumer->mGetFrameTimestampsCount);
897
898 // Verify attempts to get frame timestamps fail.
Brian Anderson1049d1d2016-12-16 17:25:57 -0800899 int result = getAllFrameTimestamps(fId);
Brian Anderson3da8d272016-07-28 16:20:47 -0700900 EXPECT_EQ(INVALID_OPERATION, result);
901 EXPECT_EQ(0, mFakeConsumer->mGetFrameTimestampsCount);
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800902
903 // Verify compositor timing query fails.
904 nsecs_t compositeDeadline = 0;
905 nsecs_t compositeInterval = 0;
906 nsecs_t compositeToPresentLatency = 0;
907 result = native_window_get_compositor_timing(mWindow.get(),
908 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
909 EXPECT_EQ(INVALID_OPERATION, result);
Brian Anderson3da8d272016-07-28 16:20:47 -0700910}
911
912// This test verifies that the frame timestamps are retrieved if explicitly
913// enabled via native_window_enable_frame_timestamps.
914TEST_F(GetFrameTimestampsTest, EnabledSimple) {
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800915 CompositorTiming initialCompositorTiming {
916 1000000000, // 1s deadline
917 16666667, // 16ms interval
918 50000000, // 50ms present latency
919 };
920 mCfeh->initializeCompositorTiming(initialCompositorTiming);
921
Brian Anderson3da8d272016-07-28 16:20:47 -0700922 enableFrameTimestamps();
923
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800924 // Verify the compositor timing query gets the initial compositor values
925 // after timststamps are enabled; even before the first frame is queued
926 // or dequeued.
927 nsecs_t compositeDeadline = 0;
928 nsecs_t compositeInterval = 0;
929 nsecs_t compositeToPresentLatency = 0;
930 mSurface->setNow(initialCompositorTiming.deadline - 1);
931 int result = native_window_get_compositor_timing(mWindow.get(),
932 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
933 EXPECT_EQ(NO_ERROR, result);
934 EXPECT_EQ(initialCompositorTiming.deadline, compositeDeadline);
935 EXPECT_EQ(initialCompositorTiming.interval, compositeInterval);
936 EXPECT_EQ(initialCompositorTiming.presentLatency,
937 compositeToPresentLatency);
938
Brian Anderson3da8d272016-07-28 16:20:47 -0700939 int fence;
940 ANativeWindowBuffer* buffer;
941
942 EXPECT_EQ(0, mFakeConsumer->mAddFrameTimestampsCount);
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800943 EXPECT_EQ(1, mFakeConsumer->mGetFrameTimestampsCount);
Brian Anderson3da8d272016-07-28 16:20:47 -0700944
Brian Anderson1049d1d2016-12-16 17:25:57 -0800945 const uint64_t fId1 = getNextFrameId();
946
Brian Anderson3da8d272016-07-28 16:20:47 -0700947 // Verify getFrameTimestamps is piggybacked on dequeue.
948 ASSERT_EQ(NO_ERROR, mWindow->dequeueBuffer(mWindow.get(), &buffer, &fence));
949 EXPECT_EQ(0, mFakeConsumer->mAddFrameTimestampsCount);
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800950 EXPECT_EQ(2, mFakeConsumer->mGetFrameTimestampsCount);
Brian Anderson3da8d272016-07-28 16:20:47 -0700951
952 NewFrameEventsEntry f1;
953 f1.frameNumber = 1;
954 f1.postedTime = mFrames[0].kPostedTime;
955 f1.requestedPresentTime = mFrames[0].kRequestedPresentTime;
956 f1.acquireFence = mFrames[0].mAcquireConsumer.mFenceTime;
957 mSurface->mFakeFrameEventHistory->setAcquireFenceOverride(
958 mFrames[0].mAcquireProducer.mFenceTime,
959 mFrames[0].mAcquireConsumer.mFenceTime);
960 mFakeConsumer->mNewFrameEntryOverride = f1;
961 mFrames[0].signalQueueFences();
962
963 // Verify getFrameTimestamps is piggybacked on queue.
964 ASSERT_EQ(NO_ERROR, mWindow->queueBuffer(mWindow.get(), buffer, fence));
965 EXPECT_EQ(1, mFakeConsumer->mAddFrameTimestampsCount);
966 EXPECT_EQ(1u, mFakeConsumer->mLastAddedFrameNumber);
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800967 EXPECT_EQ(3, mFakeConsumer->mGetFrameTimestampsCount);
Brian Anderson3da8d272016-07-28 16:20:47 -0700968
969 // Verify queries for timestamps that the producer doesn't know about
970 // triggers a call to see if the consumer has any new timestamps.
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800971 result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -0700972 EXPECT_EQ(NO_ERROR, result);
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800973 EXPECT_EQ(4, mFakeConsumer->mGetFrameTimestampsCount);
Brian Anderson3da8d272016-07-28 16:20:47 -0700974}
975
Brian Anderson6b376712017-04-04 10:51:39 -0700976TEST_F(GetFrameTimestampsTest, QueryPresentSupported) {
977 bool displayPresentSupported = true;
978 mSurface->mFakeSurfaceComposer->setSupportsPresent(displayPresentSupported);
979
980 // Verify supported bits are forwarded.
981 int supportsPresent = -1;
982 mWindow.get()->query(mWindow.get(),
983 NATIVE_WINDOW_FRAME_TIMESTAMPS_SUPPORTS_PRESENT, &supportsPresent);
984 EXPECT_EQ(displayPresentSupported, supportsPresent);
985}
986
987TEST_F(GetFrameTimestampsTest, QueryPresentNotSupported) {
988 bool displayPresentSupported = false;
989 mSurface->mFakeSurfaceComposer->setSupportsPresent(displayPresentSupported);
990
991 // Verify supported bits are forwarded.
992 int supportsPresent = -1;
993 mWindow.get()->query(mWindow.get(),
994 NATIVE_WINDOW_FRAME_TIMESTAMPS_SUPPORTS_PRESENT, &supportsPresent);
995 EXPECT_EQ(displayPresentSupported, supportsPresent);
996}
997
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800998TEST_F(GetFrameTimestampsTest, SnapToNextTickBasic) {
999 nsecs_t phase = 4000;
1000 nsecs_t interval = 1000;
1001
1002 // Timestamp in previous interval.
1003 nsecs_t timestamp = 3500;
1004 EXPECT_EQ(4000, ProducerFrameEventHistory::snapToNextTick(
1005 timestamp, phase, interval));
1006
1007 // Timestamp in next interval.
1008 timestamp = 4500;
1009 EXPECT_EQ(5000, ProducerFrameEventHistory::snapToNextTick(
1010 timestamp, phase, interval));
1011
1012 // Timestamp multiple intervals before.
1013 timestamp = 2500;
1014 EXPECT_EQ(3000, ProducerFrameEventHistory::snapToNextTick(
1015 timestamp, phase, interval));
1016
1017 // Timestamp multiple intervals after.
1018 timestamp = 6500;
1019 EXPECT_EQ(7000, ProducerFrameEventHistory::snapToNextTick(
1020 timestamp, phase, interval));
1021
1022 // Timestamp on previous interval.
1023 timestamp = 3000;
1024 EXPECT_EQ(3000, ProducerFrameEventHistory::snapToNextTick(
1025 timestamp, phase, interval));
1026
1027 // Timestamp on next interval.
1028 timestamp = 5000;
1029 EXPECT_EQ(5000, ProducerFrameEventHistory::snapToNextTick(
1030 timestamp, phase, interval));
1031
1032 // Timestamp equal to phase.
1033 timestamp = 4000;
1034 EXPECT_EQ(4000, ProducerFrameEventHistory::snapToNextTick(
1035 timestamp, phase, interval));
1036}
1037
1038// int(big_timestamp / interval) < 0, which can cause a crash or invalid result
1039// if the number of intervals elapsed is internally stored in an int.
1040TEST_F(GetFrameTimestampsTest, SnapToNextTickOverflow) {
1041 nsecs_t phase = 0;
1042 nsecs_t interval = 4000;
1043 nsecs_t big_timestamp = 8635916564000;
1044 int32_t intervals = big_timestamp / interval;
1045
1046 EXPECT_LT(intervals, 0);
1047 EXPECT_EQ(8635916564000, ProducerFrameEventHistory::snapToNextTick(
1048 big_timestamp, phase, interval));
1049 EXPECT_EQ(8635916564000, ProducerFrameEventHistory::snapToNextTick(
1050 big_timestamp, big_timestamp, interval));
1051}
1052
1053// This verifies the compositor timing is updated by refresh events
1054// and piggy backed on a queue, dequeue, and enabling of timestamps..
1055TEST_F(GetFrameTimestampsTest, CompositorTimingUpdatesBasic) {
1056 CompositorTiming initialCompositorTiming {
1057 1000000000, // 1s deadline
1058 16666667, // 16ms interval
1059 50000000, // 50ms present latency
1060 };
1061 mCfeh->initializeCompositorTiming(initialCompositorTiming);
1062
1063 enableFrameTimestamps();
1064
1065 // We get the initial values before any frames are submitted.
1066 nsecs_t compositeDeadline = 0;
1067 nsecs_t compositeInterval = 0;
1068 nsecs_t compositeToPresentLatency = 0;
1069 mSurface->setNow(initialCompositorTiming.deadline - 1);
1070 int result = native_window_get_compositor_timing(mWindow.get(),
1071 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1072 EXPECT_EQ(NO_ERROR, result);
1073 EXPECT_EQ(initialCompositorTiming.deadline, compositeDeadline);
1074 EXPECT_EQ(initialCompositorTiming.interval, compositeInterval);
1075 EXPECT_EQ(initialCompositorTiming.presentLatency,
1076 compositeToPresentLatency);
1077
Brian Anderson0a61b0c2016-12-07 14:55:56 -08001078 dequeueAndQueue(0);
1079 addFrameEvents(true, NO_FRAME_INDEX, 0);
1080
1081 // Still get the initial values because the frame events for frame 0
1082 // didn't get a chance to piggyback on a queue or dequeue yet.
1083 result = native_window_get_compositor_timing(mWindow.get(),
1084 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1085 EXPECT_EQ(NO_ERROR, result);
1086 EXPECT_EQ(initialCompositorTiming.deadline, compositeDeadline);
1087 EXPECT_EQ(initialCompositorTiming.interval, compositeInterval);
1088 EXPECT_EQ(initialCompositorTiming.presentLatency,
1089 compositeToPresentLatency);
1090
Brian Anderson0a61b0c2016-12-07 14:55:56 -08001091 dequeueAndQueue(1);
1092 addFrameEvents(true, 0, 1);
1093
1094 // Now expect the composite values associated with frame 1.
1095 mSurface->setNow(mFrames[0].mRefreshes[1].kCompositorTiming.deadline);
1096 result = native_window_get_compositor_timing(mWindow.get(),
1097 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1098 EXPECT_EQ(NO_ERROR, result);
1099 EXPECT_EQ(mFrames[0].mRefreshes[1].kCompositorTiming.deadline,
1100 compositeDeadline);
1101 EXPECT_EQ(mFrames[0].mRefreshes[1].kCompositorTiming.interval,
1102 compositeInterval);
1103 EXPECT_EQ(mFrames[0].mRefreshes[1].kCompositorTiming.presentLatency,
1104 compositeToPresentLatency);
1105
1106 dequeueAndQueue(2);
1107 addFrameEvents(true, 1, 2);
1108
1109 // Now expect the composite values associated with frame 2.
1110 mSurface->setNow(mFrames[1].mRefreshes[1].kCompositorTiming.deadline);
1111 result = native_window_get_compositor_timing(mWindow.get(),
1112 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1113 EXPECT_EQ(NO_ERROR, result);
1114 EXPECT_EQ(mFrames[1].mRefreshes[1].kCompositorTiming.deadline,
1115 compositeDeadline);
1116 EXPECT_EQ(mFrames[1].mRefreshes[1].kCompositorTiming.interval,
1117 compositeInterval);
1118 EXPECT_EQ(mFrames[1].mRefreshes[1].kCompositorTiming.presentLatency,
1119 compositeToPresentLatency);
1120
1121 // Re-enabling frame timestamps should get the latest values.
1122 disableFrameTimestamps();
1123 enableFrameTimestamps();
1124
1125 // Now expect the composite values associated with frame 3.
1126 mSurface->setNow(mFrames[2].mRefreshes[1].kCompositorTiming.deadline);
1127 result = native_window_get_compositor_timing(mWindow.get(),
1128 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1129 EXPECT_EQ(NO_ERROR, result);
1130 EXPECT_EQ(mFrames[2].mRefreshes[1].kCompositorTiming.deadline,
1131 compositeDeadline);
1132 EXPECT_EQ(mFrames[2].mRefreshes[1].kCompositorTiming.interval,
1133 compositeInterval);
1134 EXPECT_EQ(mFrames[2].mRefreshes[1].kCompositorTiming.presentLatency,
1135 compositeToPresentLatency);
1136}
1137
1138// This verifies the compositor deadline properly snaps to the the next
1139// deadline based on the current time.
1140TEST_F(GetFrameTimestampsTest, CompositorTimingDeadlineSnaps) {
1141 CompositorTiming initialCompositorTiming {
1142 1000000000, // 1s deadline
1143 16666667, // 16ms interval
1144 50000000, // 50ms present latency
1145 };
1146 mCfeh->initializeCompositorTiming(initialCompositorTiming);
1147
1148 enableFrameTimestamps();
1149
1150 nsecs_t compositeDeadline = 0;
1151 nsecs_t compositeInterval = 0;
1152 nsecs_t compositeToPresentLatency = 0;
1153
1154 // A "now" just before the deadline snaps to the deadline.
1155 mSurface->setNow(initialCompositorTiming.deadline - 1);
1156 int result = native_window_get_compositor_timing(mWindow.get(),
1157 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1158 EXPECT_EQ(NO_ERROR, result);
1159 EXPECT_EQ(initialCompositorTiming.deadline, compositeDeadline);
1160 nsecs_t expectedDeadline = initialCompositorTiming.deadline;
1161 EXPECT_EQ(expectedDeadline, compositeDeadline);
1162
Brian Anderson0a61b0c2016-12-07 14:55:56 -08001163 dequeueAndQueue(0);
1164 addFrameEvents(true, NO_FRAME_INDEX, 0);
1165
1166 // A "now" just after the deadline snaps properly.
1167 mSurface->setNow(initialCompositorTiming.deadline + 1);
1168 result = native_window_get_compositor_timing(mWindow.get(),
1169 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1170 EXPECT_EQ(NO_ERROR, result);
1171 expectedDeadline =
1172 initialCompositorTiming.deadline +initialCompositorTiming.interval;
1173 EXPECT_EQ(expectedDeadline, compositeDeadline);
1174
Brian Anderson0a61b0c2016-12-07 14:55:56 -08001175 dequeueAndQueue(1);
1176 addFrameEvents(true, 0, 1);
1177
1178 // A "now" just after the next interval snaps properly.
1179 mSurface->setNow(
1180 mFrames[0].mRefreshes[1].kCompositorTiming.deadline +
1181 mFrames[0].mRefreshes[1].kCompositorTiming.interval + 1);
1182 result = native_window_get_compositor_timing(mWindow.get(),
1183 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1184 EXPECT_EQ(NO_ERROR, result);
1185 expectedDeadline =
1186 mFrames[0].mRefreshes[1].kCompositorTiming.deadline +
1187 mFrames[0].mRefreshes[1].kCompositorTiming.interval * 2;
1188 EXPECT_EQ(expectedDeadline, compositeDeadline);
1189
1190 dequeueAndQueue(2);
1191 addFrameEvents(true, 1, 2);
1192
1193 // A "now" over 1 interval before the deadline snaps properly.
1194 mSurface->setNow(
1195 mFrames[1].mRefreshes[1].kCompositorTiming.deadline -
1196 mFrames[1].mRefreshes[1].kCompositorTiming.interval - 1);
1197 result = native_window_get_compositor_timing(mWindow.get(),
1198 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1199 EXPECT_EQ(NO_ERROR, result);
1200 expectedDeadline =
1201 mFrames[1].mRefreshes[1].kCompositorTiming.deadline -
1202 mFrames[1].mRefreshes[1].kCompositorTiming.interval;
1203 EXPECT_EQ(expectedDeadline, compositeDeadline);
1204
1205 // Re-enabling frame timestamps should get the latest values.
1206 disableFrameTimestamps();
1207 enableFrameTimestamps();
1208
1209 // A "now" over 2 intervals before the deadline snaps properly.
1210 mSurface->setNow(
1211 mFrames[2].mRefreshes[1].kCompositorTiming.deadline -
1212 mFrames[2].mRefreshes[1].kCompositorTiming.interval * 2 - 1);
1213 result = native_window_get_compositor_timing(mWindow.get(),
1214 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1215 EXPECT_EQ(NO_ERROR, result);
1216 expectedDeadline =
1217 mFrames[2].mRefreshes[1].kCompositorTiming.deadline -
1218 mFrames[2].mRefreshes[1].kCompositorTiming.interval * 2;
1219 EXPECT_EQ(expectedDeadline, compositeDeadline);
1220}
1221
Brian Anderson1049d1d2016-12-16 17:25:57 -08001222// This verifies the timestamps recorded in the consumer's
1223// FrameTimestampsHistory are properly retrieved by the producer for the
1224// correct frames.
Brian Anderson3da8d272016-07-28 16:20:47 -07001225TEST_F(GetFrameTimestampsTest, TimestampsAssociatedWithCorrectFrame) {
1226 enableFrameTimestamps();
1227
Brian Anderson1049d1d2016-12-16 17:25:57 -08001228 const uint64_t fId1 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001229 dequeueAndQueue(0);
1230 mFrames[0].signalQueueFences();
1231
Brian Anderson1049d1d2016-12-16 17:25:57 -08001232 const uint64_t fId2 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001233 dequeueAndQueue(1);
1234 mFrames[1].signalQueueFences();
1235
1236 addFrameEvents(true, NO_FRAME_INDEX, 0);
1237 mFrames[0].signalRefreshFences();
1238 addFrameEvents(true, 0, 1);
1239 mFrames[0].signalReleaseFences();
1240 mFrames[1].signalRefreshFences();
1241
1242 // Verify timestamps are correct for frame 1.
Brian Anderson3da8d272016-07-28 16:20:47 -07001243 resetTimestamps();
Brian Anderson1049d1d2016-12-16 17:25:57 -08001244 int result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001245 EXPECT_EQ(NO_ERROR, result);
1246 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1247 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001248 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1249 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1250 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001251 EXPECT_EQ(mFrames[0].mRefreshes[0].kGpuCompositionDoneTime,
1252 outGpuCompositionDoneTime);
1253 EXPECT_EQ(mFrames[0].mRefreshes[0].kPresentTime, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001254 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001255 EXPECT_EQ(mFrames[0].kReleaseTime, outReleaseTime);
1256
1257 // Verify timestamps are correct for frame 2.
Brian Anderson3da8d272016-07-28 16:20:47 -07001258 resetTimestamps();
Brian Anderson1049d1d2016-12-16 17:25:57 -08001259 result = getAllFrameTimestamps(fId2);
Brian Anderson3da8d272016-07-28 16:20:47 -07001260 EXPECT_EQ(NO_ERROR, result);
1261 EXPECT_EQ(mFrames[1].kRequestedPresentTime, outRequestedPresentTime);
1262 EXPECT_EQ(mFrames[1].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001263 EXPECT_EQ(mFrames[1].kLatchTime, outLatchTime);
1264 EXPECT_EQ(mFrames[1].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1265 EXPECT_EQ(mFrames[1].mRefreshes[1].kStartTime, outLastRefreshStartTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001266 EXPECT_EQ(mFrames[1].mRefreshes[0].kGpuCompositionDoneTime,
1267 outGpuCompositionDoneTime);
1268 EXPECT_EQ(mFrames[1].mRefreshes[0].kPresentTime, outDisplayPresentTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001269 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDequeueReadyTime);
1270 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001271}
1272
1273// This test verifies the acquire fence recorded by the consumer is not sent
1274// back to the producer and the producer saves its own fence.
1275TEST_F(GetFrameTimestampsTest, QueueTimestampsNoSync) {
1276 enableFrameTimestamps();
Brian Anderson3da8d272016-07-28 16:20:47 -07001277
Brian Anderson3da8d272016-07-28 16:20:47 -07001278 // Dequeue and queue frame 1.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001279 const uint64_t fId1 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001280 dequeueAndQueue(0);
1281
1282 // Verify queue-related timestamps for f1 are available immediately in the
1283 // producer without asking the consumer again, even before signaling the
1284 // acquire fence.
1285 resetTimestamps();
1286 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001287 int result = native_window_get_frame_timestamps(mWindow.get(), fId1,
Brian Anderson3da8d272016-07-28 16:20:47 -07001288 &outRequestedPresentTime, &outAcquireTime, nullptr, nullptr,
Brian Anderson4e606e32017-03-16 15:34:57 -07001289 nullptr, nullptr, nullptr, nullptr, nullptr);
Brian Anderson3da8d272016-07-28 16:20:47 -07001290 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1291 EXPECT_EQ(NO_ERROR, result);
1292 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001293 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outAcquireTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001294
1295 // Signal acquire fences. Verify a sync call still isn't necessary.
1296 mFrames[0].signalQueueFences();
1297
1298 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001299 result = native_window_get_frame_timestamps(mWindow.get(), fId1,
Brian Anderson3da8d272016-07-28 16:20:47 -07001300 &outRequestedPresentTime, &outAcquireTime, nullptr, nullptr,
Brian Anderson4e606e32017-03-16 15:34:57 -07001301 nullptr, nullptr, nullptr, nullptr, nullptr);
Brian Anderson3da8d272016-07-28 16:20:47 -07001302 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1303 EXPECT_EQ(NO_ERROR, result);
1304 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1305 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
1306
1307 // Dequeue and queue frame 2.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001308 const uint64_t fId2 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001309 dequeueAndQueue(1);
1310
1311 // Verify queue-related timestamps for f2 are available immediately in the
1312 // producer without asking the consumer again, even before signaling the
1313 // acquire fence.
1314 resetTimestamps();
1315 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001316 result = native_window_get_frame_timestamps(mWindow.get(), fId2,
Brian Anderson3da8d272016-07-28 16:20:47 -07001317 &outRequestedPresentTime, &outAcquireTime, nullptr, nullptr,
Brian Anderson4e606e32017-03-16 15:34:57 -07001318 nullptr, nullptr, nullptr, nullptr, nullptr);
Brian Anderson3da8d272016-07-28 16:20:47 -07001319 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1320 EXPECT_EQ(NO_ERROR, result);
1321 EXPECT_EQ(mFrames[1].kRequestedPresentTime, outRequestedPresentTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001322 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outAcquireTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001323
1324 // Signal acquire fences. Verify a sync call still isn't necessary.
1325 mFrames[1].signalQueueFences();
1326
1327 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001328 result = native_window_get_frame_timestamps(mWindow.get(), fId2,
Brian Anderson3da8d272016-07-28 16:20:47 -07001329 &outRequestedPresentTime, &outAcquireTime, nullptr, nullptr,
Brian Anderson4e606e32017-03-16 15:34:57 -07001330 nullptr, nullptr, nullptr, nullptr, nullptr);
Brian Anderson3da8d272016-07-28 16:20:47 -07001331 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1332 EXPECT_EQ(NO_ERROR, result);
1333 EXPECT_EQ(mFrames[1].kRequestedPresentTime, outRequestedPresentTime);
1334 EXPECT_EQ(mFrames[1].kProducerAcquireTime, outAcquireTime);
1335}
1336
1337TEST_F(GetFrameTimestampsTest, ZeroRequestedTimestampsNoSync) {
1338 enableFrameTimestamps();
Brian Anderson3da8d272016-07-28 16:20:47 -07001339
1340 // Dequeue and queue frame 1.
1341 dequeueAndQueue(0);
1342 mFrames[0].signalQueueFences();
1343
1344 // Dequeue and queue frame 2.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001345 const uint64_t fId2 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001346 dequeueAndQueue(1);
1347 mFrames[1].signalQueueFences();
1348
1349 addFrameEvents(true, NO_FRAME_INDEX, 0);
1350 mFrames[0].signalRefreshFences();
1351 addFrameEvents(true, 0, 1);
1352 mFrames[0].signalReleaseFences();
1353 mFrames[1].signalRefreshFences();
1354
1355 // Verify a request for no timestamps doesn't result in a sync call.
Brian Anderson3da8d272016-07-28 16:20:47 -07001356 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001357 int result = native_window_get_frame_timestamps(mWindow.get(), fId2,
Brian Anderson6b376712017-04-04 10:51:39 -07001358 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
1359 nullptr, nullptr);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001360 EXPECT_EQ(NO_ERROR, result);
Brian Anderson3da8d272016-07-28 16:20:47 -07001361 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1362}
1363
1364// This test verifies that fences can signal and update timestamps producer
1365// side without an additional sync call to the consumer.
1366TEST_F(GetFrameTimestampsTest, FencesInProducerNoSync) {
1367 enableFrameTimestamps();
Brian Anderson3da8d272016-07-28 16:20:47 -07001368
1369 // Dequeue and queue frame 1.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001370 const uint64_t fId1 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001371 dequeueAndQueue(0);
1372 mFrames[0].signalQueueFences();
1373
1374 // Dequeue and queue frame 2.
1375 dequeueAndQueue(1);
1376 mFrames[1].signalQueueFences();
1377
1378 addFrameEvents(true, NO_FRAME_INDEX, 0);
1379 addFrameEvents(true, 0, 1);
1380
1381 // Verify available timestamps are correct for frame 1, before any
1382 // fence has been signaled.
1383 // Note: A sync call is necessary here since the events triggered by
1384 // addFrameEvents didn't get to piggyback on the earlier queues/dequeues.
Brian Anderson3da8d272016-07-28 16:20:47 -07001385 resetTimestamps();
1386 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001387 int result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001388 EXPECT_EQ(oldCount + 1, mFakeConsumer->mGetFrameTimestampsCount);
1389 EXPECT_EQ(NO_ERROR, result);
1390 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1391 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001392 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1393 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1394 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001395 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outGpuCompositionDoneTime);
1396 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001397 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001398 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001399
1400 // Verify available timestamps are correct for frame 1 again, before any
1401 // fence has been signaled.
1402 // This time a sync call should not be necessary.
Brian Anderson3da8d272016-07-28 16:20:47 -07001403 resetTimestamps();
1404 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001405 result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001406 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1407 EXPECT_EQ(NO_ERROR, result);
1408 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1409 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001410 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1411 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1412 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001413 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outGpuCompositionDoneTime);
1414 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001415 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001416 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001417
1418 // Signal the fences for frame 1.
1419 mFrames[0].signalRefreshFences();
1420 mFrames[0].signalReleaseFences();
1421
1422 // Verify all timestamps are available without a sync call.
Brian Anderson3da8d272016-07-28 16:20:47 -07001423 resetTimestamps();
1424 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001425 result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001426 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1427 EXPECT_EQ(NO_ERROR, result);
1428 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1429 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001430 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1431 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1432 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001433 EXPECT_EQ(mFrames[0].mRefreshes[0].kGpuCompositionDoneTime,
1434 outGpuCompositionDoneTime);
1435 EXPECT_EQ(mFrames[0].mRefreshes[0].kPresentTime, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001436 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001437 EXPECT_EQ(mFrames[0].kReleaseTime, outReleaseTime);
1438}
1439
1440// This test verifies that if the frame wasn't GPU composited but has a refresh
1441// event a sync call isn't made to get the GPU composite done time since it will
1442// never exist.
1443TEST_F(GetFrameTimestampsTest, NoGpuNoSync) {
1444 enableFrameTimestamps();
Brian Anderson3da8d272016-07-28 16:20:47 -07001445
Brian Anderson3da8d272016-07-28 16:20:47 -07001446 // Dequeue and queue frame 1.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001447 const uint64_t fId1 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001448 dequeueAndQueue(0);
1449 mFrames[0].signalQueueFences();
1450
1451 // Dequeue and queue frame 2.
1452 dequeueAndQueue(1);
1453 mFrames[1].signalQueueFences();
1454
1455 addFrameEvents(false, NO_FRAME_INDEX, 0);
1456 addFrameEvents(false, 0, 1);
1457
1458 // Verify available timestamps are correct for frame 1, before any
1459 // fence has been signaled.
1460 // Note: A sync call is necessary here since the events triggered by
1461 // addFrameEvents didn't get to piggyback on the earlier queues/dequeues.
1462 resetTimestamps();
1463 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001464 int result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001465 EXPECT_EQ(oldCount + 1, mFakeConsumer->mGetFrameTimestampsCount);
1466 EXPECT_EQ(NO_ERROR, result);
1467 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1468 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001469 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1470 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1471 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001472 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_INVALID, outGpuCompositionDoneTime);
1473 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001474 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001475 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001476
1477 // Signal the fences for frame 1.
1478 mFrames[0].signalRefreshFences();
1479 mFrames[0].signalReleaseFences();
1480
1481 // Verify all timestamps, except GPU composition, are available without a
1482 // sync call.
1483 resetTimestamps();
1484 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001485 result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001486 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1487 EXPECT_EQ(NO_ERROR, result);
1488 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1489 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001490 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1491 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1492 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001493 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_INVALID, outGpuCompositionDoneTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001494 EXPECT_EQ(mFrames[0].mRefreshes[0].kPresentTime, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001495 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001496 EXPECT_EQ(mFrames[0].kReleaseTime, outReleaseTime);
1497}
1498
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001499// This test verifies that if the certain timestamps can't possibly exist for
1500// the most recent frame, then a sync call is not done.
Brian Anderson6b376712017-04-04 10:51:39 -07001501TEST_F(GetFrameTimestampsTest, NoReleaseNoSync) {
Brian Anderson3da8d272016-07-28 16:20:47 -07001502 enableFrameTimestamps();
Brian Anderson3da8d272016-07-28 16:20:47 -07001503
1504 // Dequeue and queue frame 1.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001505 const uint64_t fId1 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001506 dequeueAndQueue(0);
1507 mFrames[0].signalQueueFences();
1508
1509 // Dequeue and queue frame 2.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001510 const uint64_t fId2 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001511 dequeueAndQueue(1);
1512 mFrames[1].signalQueueFences();
1513
1514 addFrameEvents(false, NO_FRAME_INDEX, 0);
1515 addFrameEvents(false, 0, 1);
1516
1517 // Verify available timestamps are correct for frame 1, before any
1518 // fence has been signaled.
1519 // Note: A sync call is necessary here since the events triggered by
1520 // addFrameEvents didn't get to piggyback on the earlier queues/dequeues.
Brian Anderson3da8d272016-07-28 16:20:47 -07001521 resetTimestamps();
1522 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001523 int result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001524 EXPECT_EQ(oldCount + 1, mFakeConsumer->mGetFrameTimestampsCount);
1525 EXPECT_EQ(NO_ERROR, result);
1526 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1527 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001528 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1529 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1530 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001531 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_INVALID, outGpuCompositionDoneTime);
1532 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001533 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001534 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001535
1536 mFrames[0].signalRefreshFences();
1537 mFrames[0].signalReleaseFences();
1538 mFrames[1].signalRefreshFences();
1539
Brian Anderson1049d1d2016-12-16 17:25:57 -08001540 // Verify querying for all timestmaps of f2 does not do a sync call. Even
Brian Anderson4e606e32017-03-16 15:34:57 -07001541 // though the lastRefresh, dequeueReady, and release times aren't
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001542 // available, a sync call should not occur because it's not possible for f2
1543 // to encounter the final value for those events until another frame is
1544 // queued.
Brian Anderson3da8d272016-07-28 16:20:47 -07001545 resetTimestamps();
1546 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001547 result = getAllFrameTimestamps(fId2);
Brian Anderson3da8d272016-07-28 16:20:47 -07001548 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1549 EXPECT_EQ(NO_ERROR, result);
1550 EXPECT_EQ(mFrames[1].kRequestedPresentTime, outRequestedPresentTime);
1551 EXPECT_EQ(mFrames[1].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001552 EXPECT_EQ(mFrames[1].kLatchTime, outLatchTime);
1553 EXPECT_EQ(mFrames[1].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1554 EXPECT_EQ(mFrames[1].mRefreshes[1].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001555 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_INVALID, outGpuCompositionDoneTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001556 EXPECT_EQ(mFrames[1].mRefreshes[0].kPresentTime, outDisplayPresentTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001557 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDequeueReadyTime);
1558 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001559}
1560
Brian Anderson6b376712017-04-04 10:51:39 -07001561// This test verifies there are no sync calls for present times
1562// when they aren't supported and that an error is returned.
1563
1564TEST_F(GetFrameTimestampsTest, PresentUnsupportedNoSync) {
1565 enableFrameTimestamps();
1566 mSurface->mFakeSurfaceComposer->setSupportsPresent(false);
1567
1568 // Dequeue and queue frame 1.
1569 const uint64_t fId1 = getNextFrameId();
1570 dequeueAndQueue(0);
1571
1572 // Verify a query for the Present times do not trigger a sync call if they
1573 // are not supported.
1574 resetTimestamps();
1575 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
1576 int result = native_window_get_frame_timestamps(mWindow.get(), fId1,
1577 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
1578 &outDisplayPresentTime, nullptr, nullptr);
1579 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1580 EXPECT_EQ(BAD_VALUE, result);
1581 EXPECT_EQ(-1, outDisplayPresentTime);
1582}
1583
Dan Stoza932f0082017-05-31 13:50:16 -07001584} // namespace android