blob: bfcd75f26c6452e23e9e194d22c5442db5ba9121 [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
Robert Carr4cdc58f2017-08-23 14:22:20 -070045using Transaction = SurfaceComposerClient::Transaction;
46
Courtney Goeltzenleuchter6a570b62017-03-13 14:30:00 -060047static bool hasWideColorDisplay =
48 getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasWideColorDisplay>(false);
Kalle Raita643f0942016-12-07 09:20:14 -080049
Brian Anderson3da8d272016-07-28 16:20:47 -070050class FakeSurfaceComposer;
51class FakeProducerFrameEventHistory;
52
53static constexpr uint64_t NO_FRAME_INDEX = std::numeric_limits<uint64_t>::max();
54
Jamie Gennis134f0422011-03-08 12:18:54 -080055class SurfaceTest : public ::testing::Test {
56protected:
Mathias Agopian7c1a4872013-03-20 15:56:04 -070057
58 SurfaceTest() {
59 ProcessState::self()->startThreadPool();
60 }
61
Jamie Gennis134f0422011-03-08 12:18:54 -080062 virtual void SetUp() {
Jamie Gennis7a4d0df2011-03-09 17:05:02 -080063 mComposerClient = new SurfaceComposerClient;
Jamie Gennis134f0422011-03-08 12:18:54 -080064 ASSERT_EQ(NO_ERROR, mComposerClient->initCheck());
65
Brian Andersond0010582017-03-07 13:20:31 -080066 // TODO(brianderson): The following sometimes fails and is a source of
67 // test flakiness.
Jamie Gennisfc850122011-04-25 16:40:05 -070068 mSurfaceControl = mComposerClient->createSurface(
Jeff Brown9d4e3d22012-08-24 20:00:51 -070069 String8("Test Surface"), 32, 32, PIXEL_FORMAT_RGBA_8888, 0);
Jamie Gennis134f0422011-03-08 12:18:54 -080070
71 ASSERT_TRUE(mSurfaceControl != NULL);
72 ASSERT_TRUE(mSurfaceControl->isValid());
73
Robert Carr4cdc58f2017-08-23 14:22:20 -070074 Transaction t;
75 ASSERT_EQ(NO_ERROR, t.setLayer(mSurfaceControl, 0x7fffffff)
76 .show(mSurfaceControl)
77 .apply());
Jamie Gennis134f0422011-03-08 12:18:54 -080078
79 mSurface = mSurfaceControl->getSurface();
80 ASSERT_TRUE(mSurface != NULL);
81 }
82
83 virtual void TearDown() {
84 mComposerClient->dispose();
85 }
86
87 sp<Surface> mSurface;
88 sp<SurfaceComposerClient> mComposerClient;
89 sp<SurfaceControl> mSurfaceControl;
90};
91
92TEST_F(SurfaceTest, QueuesToWindowComposerIsTrueWhenVisible) {
93 sp<ANativeWindow> anw(mSurface);
94 int result = -123;
95 int err = anw->query(anw.get(), NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER,
96 &result);
97 EXPECT_EQ(NO_ERROR, err);
98 EXPECT_EQ(1, result);
99}
100
101TEST_F(SurfaceTest, QueuesToWindowComposerIsTrueWhenPurgatorized) {
102 mSurfaceControl.clear();
Kalle Raita643f0942016-12-07 09:20:14 -0800103 // Wait for the async clean-up to complete.
104 std::this_thread::sleep_for(50ms);
Jamie Gennis134f0422011-03-08 12:18:54 -0800105
106 sp<ANativeWindow> anw(mSurface);
107 int result = -123;
108 int err = anw->query(anw.get(), NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER,
109 &result);
110 EXPECT_EQ(NO_ERROR, err);
111 EXPECT_EQ(1, result);
112}
113
Jamie Gennis7a4d0df2011-03-09 17:05:02 -0800114// This test probably doesn't belong here.
Jamie Gennisc901ca02011-10-11 16:02:31 -0700115TEST_F(SurfaceTest, ScreenshotsOfProtectedBuffersSucceed) {
Jamie Gennis7a4d0df2011-03-09 17:05:02 -0800116 sp<ANativeWindow> anw(mSurface);
117
118 // Verify the screenshot works with no protected buffers.
Dan Stoza5603a2f2014-04-07 13:41:37 -0700119 sp<IGraphicBufferProducer> producer;
120 sp<IGraphicBufferConsumer> consumer;
121 BufferQueue::createBufferQueue(&producer, &consumer);
122 sp<CpuConsumer> cpuConsumer = new CpuConsumer(consumer, 1);
Jamie Gennis7a4d0df2011-03-09 17:05:02 -0800123 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
Brian Anderson3da8d272016-07-28 16:20:47 -0700124 sp<IBinder> display(sf->getBuiltInDisplay(
125 ISurfaceComposer::eDisplayIdMain));
Dan Stozac1879002014-05-22 15:59:05 -0700126 ASSERT_EQ(NO_ERROR, sf->captureScreen(display, producer, Rect(),
Dan Stoza8d759962014-02-19 18:35:30 -0800127 64, 64, 0, 0x7fffffff, false));
Jamie Gennis7a4d0df2011-03-09 17:05:02 -0800128
Pablo Ceballos583b1b32015-09-03 18:23:52 -0700129 ASSERT_EQ(NO_ERROR, native_window_api_connect(anw.get(),
130 NATIVE_WINDOW_API_CPU));
Jamie Gennis7a4d0df2011-03-09 17:05:02 -0800131 // Set the PROTECTED usage bit and verify that the screenshot fails. Note
132 // that we need to dequeue a buffer in order for it to actually get
133 // allocated in SurfaceFlinger.
134 ASSERT_EQ(NO_ERROR, native_window_set_usage(anw.get(),
135 GRALLOC_USAGE_PROTECTED));
136 ASSERT_EQ(NO_ERROR, native_window_set_buffer_count(anw.get(), 3));
Iliyan Malchev697526b2011-05-01 11:33:26 -0700137 ANativeWindowBuffer* buf = 0;
Mathias Agopian9303eee2011-07-01 15:27:27 -0700138
Jamie Gennisd8e812c2012-06-13 16:32:25 -0700139 status_t err = native_window_dequeue_buffer_and_wait(anw.get(), &buf);
Mathias Agopian9303eee2011-07-01 15:27:27 -0700140 if (err) {
141 // we could fail if GRALLOC_USAGE_PROTECTED is not supported.
142 // that's okay as long as this is the reason for the failure.
143 // try again without the GRALLOC_USAGE_PROTECTED bit.
144 ASSERT_EQ(NO_ERROR, native_window_set_usage(anw.get(), 0));
Jamie Gennisd8e812c2012-06-13 16:32:25 -0700145 ASSERT_EQ(NO_ERROR, native_window_dequeue_buffer_and_wait(anw.get(),
146 &buf));
Mathias Agopian9303eee2011-07-01 15:27:27 -0700147 return;
148 }
Jamie Gennisd8e812c2012-06-13 16:32:25 -0700149 ASSERT_EQ(NO_ERROR, anw->cancelBuffer(anw.get(), buf, -1));
Mathias Agopian9303eee2011-07-01 15:27:27 -0700150
Jamie Gennis7a4d0df2011-03-09 17:05:02 -0800151 for (int i = 0; i < 4; i++) {
152 // Loop to make sure SurfaceFlinger has retired a protected buffer.
Jamie Gennisd8e812c2012-06-13 16:32:25 -0700153 ASSERT_EQ(NO_ERROR, native_window_dequeue_buffer_and_wait(anw.get(),
154 &buf));
155 ASSERT_EQ(NO_ERROR, anw->queueBuffer(anw.get(), buf, -1));
Jamie Gennis7a4d0df2011-03-09 17:05:02 -0800156 }
Dan Stozac1879002014-05-22 15:59:05 -0700157 ASSERT_EQ(NO_ERROR, sf->captureScreen(display, producer, Rect(),
Dan Stoza8d759962014-02-19 18:35:30 -0800158 64, 64, 0, 0x7fffffff, false));
Jamie Gennis7a4d0df2011-03-09 17:05:02 -0800159}
160
Jamie Gennis391bbe22011-03-14 15:00:06 -0700161TEST_F(SurfaceTest, ConcreteTypeIsSurface) {
162 sp<ANativeWindow> anw(mSurface);
163 int result = -123;
164 int err = anw->query(anw.get(), NATIVE_WINDOW_CONCRETE_TYPE, &result);
165 EXPECT_EQ(NO_ERROR, err);
166 EXPECT_EQ(NATIVE_WINDOW_SURFACE, result);
167}
168
Craig Donner6ebc46a2016-10-21 15:23:44 -0700169TEST_F(SurfaceTest, LayerCountIsOne) {
170 sp<ANativeWindow> anw(mSurface);
171 int result = -123;
172 int err = anw->query(anw.get(), NATIVE_WINDOW_LAYER_COUNT, &result);
173 EXPECT_EQ(NO_ERROR, err);
174 EXPECT_EQ(1, result);
175}
176
Eino-Ville Talvalaf7c60872013-07-30 14:05:02 -0700177TEST_F(SurfaceTest, QueryConsumerUsage) {
178 const int TEST_USAGE_FLAGS =
179 GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_HW_RENDER;
Dan Stoza5603a2f2014-04-07 13:41:37 -0700180 sp<IGraphicBufferProducer> producer;
181 sp<IGraphicBufferConsumer> consumer;
182 BufferQueue::createBufferQueue(&producer, &consumer);
183 sp<BufferItemConsumer> c = new BufferItemConsumer(consumer,
Eino-Ville Talvalaf7c60872013-07-30 14:05:02 -0700184 TEST_USAGE_FLAGS);
Dan Stoza5603a2f2014-04-07 13:41:37 -0700185 sp<Surface> s = new Surface(producer);
Eino-Ville Talvalaf7c60872013-07-30 14:05:02 -0700186
187 sp<ANativeWindow> anw(s);
188
189 int flags = -1;
190 int err = anw->query(anw.get(), NATIVE_WINDOW_CONSUMER_USAGE_BITS, &flags);
191
192 ASSERT_EQ(NO_ERROR, err);
193 ASSERT_EQ(TEST_USAGE_FLAGS, flags);
194}
195
Eino-Ville Talvala5b75a512015-02-19 16:10:43 -0800196TEST_F(SurfaceTest, QueryDefaultBuffersDataSpace) {
197 const android_dataspace TEST_DATASPACE = HAL_DATASPACE_SRGB;
198 sp<IGraphicBufferProducer> producer;
199 sp<IGraphicBufferConsumer> consumer;
200 BufferQueue::createBufferQueue(&producer, &consumer);
201 sp<CpuConsumer> cpuConsumer = new CpuConsumer(consumer, 1);
202
203 cpuConsumer->setDefaultBufferDataSpace(TEST_DATASPACE);
204
205 sp<Surface> s = new Surface(producer);
206
207 sp<ANativeWindow> anw(s);
208
209 android_dataspace dataSpace;
210
211 int err = anw->query(anw.get(), NATIVE_WINDOW_DEFAULT_DATASPACE,
212 reinterpret_cast<int*>(&dataSpace));
213
214 ASSERT_EQ(NO_ERROR, err);
215 ASSERT_EQ(TEST_DATASPACE, dataSpace);
216}
217
Dan Stoza812ed062015-06-02 15:45:22 -0700218TEST_F(SurfaceTest, SettingGenerationNumber) {
219 sp<IGraphicBufferProducer> producer;
220 sp<IGraphicBufferConsumer> consumer;
221 BufferQueue::createBufferQueue(&producer, &consumer);
222 sp<CpuConsumer> cpuConsumer = new CpuConsumer(consumer, 1);
223 sp<Surface> surface = new Surface(producer);
224 sp<ANativeWindow> window(surface);
225
226 // Allocate a buffer with a generation number of 0
227 ANativeWindowBuffer* buffer;
228 int fenceFd;
Pablo Ceballos583b1b32015-09-03 18:23:52 -0700229 ASSERT_EQ(NO_ERROR, native_window_api_connect(window.get(),
230 NATIVE_WINDOW_API_CPU));
Dan Stoza812ed062015-06-02 15:45:22 -0700231 ASSERT_EQ(NO_ERROR, window->dequeueBuffer(window.get(), &buffer, &fenceFd));
232 ASSERT_EQ(NO_ERROR, window->cancelBuffer(window.get(), buffer, fenceFd));
233
234 // Detach the buffer and check its generation number
235 sp<GraphicBuffer> graphicBuffer;
236 sp<Fence> fence;
237 ASSERT_EQ(NO_ERROR, surface->detachNextBuffer(&graphicBuffer, &fence));
238 ASSERT_EQ(0U, graphicBuffer->getGenerationNumber());
239
240 ASSERT_EQ(NO_ERROR, surface->setGenerationNumber(1));
241 buffer = static_cast<ANativeWindowBuffer*>(graphicBuffer.get());
242
243 // This should change the generation number of the GraphicBuffer
244 ASSERT_EQ(NO_ERROR, surface->attachBuffer(buffer));
245
246 // Check that the new generation number sticks with the buffer
247 ASSERT_EQ(NO_ERROR, window->cancelBuffer(window.get(), buffer, -1));
248 ASSERT_EQ(NO_ERROR, window->dequeueBuffer(window.get(), &buffer, &fenceFd));
249 graphicBuffer = static_cast<GraphicBuffer*>(buffer);
250 ASSERT_EQ(1U, graphicBuffer->getGenerationNumber());
251}
252
Dan Stozac6f30bd2015-06-08 09:32:50 -0700253TEST_F(SurfaceTest, GetConsumerName) {
254 sp<IGraphicBufferProducer> producer;
255 sp<IGraphicBufferConsumer> consumer;
256 BufferQueue::createBufferQueue(&producer, &consumer);
257
258 sp<DummyConsumer> dummyConsumer(new DummyConsumer);
259 consumer->consumerConnect(dummyConsumer, false);
260 consumer->setConsumerName(String8("TestConsumer"));
261
262 sp<Surface> surface = new Surface(producer);
263 sp<ANativeWindow> window(surface);
264 native_window_api_connect(window.get(), NATIVE_WINDOW_API_CPU);
265
266 EXPECT_STREQ("TestConsumer", surface->getConsumerName().string());
267}
268
Courtney Goeltzenleuchter1eb1b272017-02-02 16:51:06 -0700269TEST_F(SurfaceTest, GetWideColorSupport) {
270 sp<IGraphicBufferProducer> producer;
271 sp<IGraphicBufferConsumer> consumer;
272 BufferQueue::createBufferQueue(&producer, &consumer);
273
274 sp<DummyConsumer> dummyConsumer(new DummyConsumer);
275 consumer->consumerConnect(dummyConsumer, false);
276 consumer->setConsumerName(String8("TestConsumer"));
277
278 sp<Surface> surface = new Surface(producer);
279 sp<ANativeWindow> window(surface);
280 native_window_api_connect(window.get(), NATIVE_WINDOW_API_CPU);
281
282 bool supported;
283 surface->getWideColorSupport(&supported);
284
Courtney Goeltzenleuchter6a570b62017-03-13 14:30:00 -0600285 // NOTE: This test assumes that device that supports
286 // wide-color (as indicated by BoardConfig) must also
287 // have a wide-color primary display.
288 // That assumption allows this test to cover devices
289 // that advertised a wide-color color mode without
290 // actually supporting wide-color to pass this test
291 // as well as the case of a device that does support
292 // wide-color (via BoardConfig) and has a wide-color
293 // primary display.
294 // NOT covered at this time is a device that supports
295 // wide color in the BoardConfig but does not support
296 // a wide-color color mode on the primary display.
297 ASSERT_EQ(hasWideColorDisplay, supported);
Courtney Goeltzenleuchter1eb1b272017-02-02 16:51:06 -0700298}
299
Pablo Ceballos789a0c82016-02-05 13:39:27 -0800300TEST_F(SurfaceTest, DynamicSetBufferCount) {
301 sp<IGraphicBufferProducer> producer;
302 sp<IGraphicBufferConsumer> consumer;
303 BufferQueue::createBufferQueue(&producer, &consumer);
304
305 sp<DummyConsumer> dummyConsumer(new DummyConsumer);
306 consumer->consumerConnect(dummyConsumer, false);
307 consumer->setConsumerName(String8("TestConsumer"));
308
309 sp<Surface> surface = new Surface(producer);
310 sp<ANativeWindow> window(surface);
311
312 ASSERT_EQ(NO_ERROR, native_window_api_connect(window.get(),
313 NATIVE_WINDOW_API_CPU));
314 native_window_set_buffer_count(window.get(), 4);
315
316 int fence;
317 ANativeWindowBuffer* buffer;
318 ASSERT_EQ(NO_ERROR, window->dequeueBuffer(window.get(), &buffer, &fence));
319 native_window_set_buffer_count(window.get(), 3);
320 ASSERT_EQ(NO_ERROR, window->queueBuffer(window.get(), buffer, fence));
321 native_window_set_buffer_count(window.get(), 2);
322 ASSERT_EQ(NO_ERROR, window->dequeueBuffer(window.get(), &buffer, &fence));
323 ASSERT_EQ(NO_ERROR, window->queueBuffer(window.get(), buffer, fence));
324}
325
Yin-Chia Yeh1f2af5c2017-05-11 16:54:04 -0700326TEST_F(SurfaceTest, GetAndFlushRemovedBuffers) {
327 sp<IGraphicBufferProducer> producer;
328 sp<IGraphicBufferConsumer> consumer;
329 BufferQueue::createBufferQueue(&producer, &consumer);
330
331 sp<DummyConsumer> dummyConsumer(new DummyConsumer);
332 consumer->consumerConnect(dummyConsumer, false);
333 consumer->setConsumerName(String8("TestConsumer"));
334
335 sp<Surface> surface = new Surface(producer);
336 sp<ANativeWindow> window(surface);
337 sp<DummyProducerListener> listener = new DummyProducerListener();
338 ASSERT_EQ(OK, surface->connect(
339 NATIVE_WINDOW_API_CPU,
340 /*listener*/listener,
341 /*reportBufferRemoval*/true));
342 const int BUFFER_COUNT = 4;
343 ASSERT_EQ(NO_ERROR, native_window_set_buffer_count(window.get(), BUFFER_COUNT));
344
345 sp<GraphicBuffer> detachedBuffer;
346 sp<Fence> outFence;
347 int fences[BUFFER_COUNT];
348 ANativeWindowBuffer* buffers[BUFFER_COUNT];
349 // Allocate buffers because detachNextBuffer requires allocated buffers
350 for (int i = 0; i < BUFFER_COUNT; i++) {
351 ASSERT_EQ(NO_ERROR, window->dequeueBuffer(window.get(), &buffers[i], &fences[i]));
352 }
353 for (int i = 0; i < BUFFER_COUNT; i++) {
354 ASSERT_EQ(NO_ERROR, window->cancelBuffer(window.get(), buffers[i], fences[i]));
355 }
356
357 // Test detached buffer is correctly reported
358 ASSERT_EQ(NO_ERROR, surface->detachNextBuffer(&detachedBuffer, &outFence));
359 std::vector<sp<GraphicBuffer>> removedBuffers;
360 ASSERT_EQ(OK, surface->getAndFlushRemovedBuffers(&removedBuffers));
361 ASSERT_EQ(1u, removedBuffers.size());
362 ASSERT_EQ(detachedBuffer->handle, removedBuffers.at(0)->handle);
363 // Test the list is flushed one getAndFlushRemovedBuffers returns
364 ASSERT_EQ(OK, surface->getAndFlushRemovedBuffers(&removedBuffers));
365 ASSERT_EQ(0u, removedBuffers.size());
366
367
368 // Test removed buffer list is cleanup after next dequeueBuffer call
369 ASSERT_EQ(NO_ERROR, surface->detachNextBuffer(&detachedBuffer, &outFence));
370 ASSERT_EQ(NO_ERROR, window->dequeueBuffer(window.get(), &buffers[0], &fences[0]));
371 ASSERT_EQ(OK, surface->getAndFlushRemovedBuffers(&removedBuffers));
372 ASSERT_EQ(0u, removedBuffers.size());
373 ASSERT_EQ(NO_ERROR, window->cancelBuffer(window.get(), buffers[0], fences[0]));
374
375 // Test removed buffer list is cleanup after next detachNextBuffer call
376 ASSERT_EQ(NO_ERROR, surface->detachNextBuffer(&detachedBuffer, &outFence));
377 ASSERT_EQ(NO_ERROR, surface->detachNextBuffer(&detachedBuffer, &outFence));
378 ASSERT_EQ(OK, surface->getAndFlushRemovedBuffers(&removedBuffers));
379 ASSERT_EQ(1u, removedBuffers.size());
380 ASSERT_EQ(detachedBuffer->handle, removedBuffers.at(0)->handle);
381
382 // Re-allocate buffers since all buffers are detached up to now
383 for (int i = 0; i < BUFFER_COUNT; i++) {
384 ASSERT_EQ(NO_ERROR, window->dequeueBuffer(window.get(), &buffers[i], &fences[i]));
385 }
386 for (int i = 0; i < BUFFER_COUNT; i++) {
387 ASSERT_EQ(NO_ERROR, window->cancelBuffer(window.get(), buffers[i], fences[i]));
388 }
389
390 ASSERT_EQ(NO_ERROR, surface->detachNextBuffer(&detachedBuffer, &outFence));
391 ASSERT_EQ(NO_ERROR, surface->attachBuffer(detachedBuffer.get()));
392 ASSERT_EQ(OK, surface->getAndFlushRemovedBuffers(&removedBuffers));
393 // Depends on which slot GraphicBufferProducer impl pick, the attach call might
394 // get 0 or 1 buffer removed.
395 ASSERT_LE(removedBuffers.size(), 1u);
396}
Brian Anderson3da8d272016-07-28 16:20:47 -0700397
Dan Stoza932f0082017-05-31 13:50:16 -0700398TEST_F(SurfaceTest, TestGetLastDequeueStartTime) {
399 sp<ANativeWindow> anw(mSurface);
400 ASSERT_EQ(NO_ERROR, native_window_api_connect(anw.get(), NATIVE_WINDOW_API_CPU));
401
402 ANativeWindowBuffer* buffer = nullptr;
403 int32_t fenceFd = -1;
404
405 nsecs_t before = systemTime(CLOCK_MONOTONIC);
406 anw->dequeueBuffer(anw.get(), &buffer, &fenceFd);
407 nsecs_t after = systemTime(CLOCK_MONOTONIC);
408
409 nsecs_t lastDequeueTime = mSurface->getLastDequeueStartTime();
410 ASSERT_LE(before, lastDequeueTime);
411 ASSERT_GE(after, lastDequeueTime);
412}
413
Brian Anderson3da8d272016-07-28 16:20:47 -0700414class FakeConsumer : public BnConsumerListener {
415public:
416 void onFrameAvailable(const BufferItem& /*item*/) override {}
417 void onBuffersReleased() override {}
418 void onSidebandStreamChanged() override {}
419
420 void addAndGetFrameTimestamps(
421 const NewFrameEventsEntry* newTimestamps,
422 FrameEventHistoryDelta* outDelta) override {
423 if (newTimestamps) {
424 if (mGetFrameTimestampsEnabled) {
425 EXPECT_GT(mNewFrameEntryOverride.frameNumber, 0u) <<
426 "Test should set mNewFrameEntryOverride before queuing "
427 "a frame.";
428 EXPECT_EQ(newTimestamps->frameNumber,
429 mNewFrameEntryOverride.frameNumber) <<
430 "Test attempting to add NewFrameEntryOverride with "
431 "incorrect frame number.";
432 mFrameEventHistory.addQueue(mNewFrameEntryOverride);
433 mNewFrameEntryOverride.frameNumber = 0;
434 }
435 mAddFrameTimestampsCount++;
436 mLastAddedFrameNumber = newTimestamps->frameNumber;
437 }
438 if (outDelta) {
439 mFrameEventHistory.getAndResetDelta(outDelta);
440 mGetFrameTimestampsCount++;
441 }
442 mAddAndGetFrameTimestampsCallCount++;
443 }
444
445 bool mGetFrameTimestampsEnabled = false;
446
447 ConsumerFrameEventHistory mFrameEventHistory;
448 int mAddAndGetFrameTimestampsCallCount = 0;
449 int mAddFrameTimestampsCount = 0;
450 int mGetFrameTimestampsCount = 0;
451 uint64_t mLastAddedFrameNumber = NO_FRAME_INDEX;
452
453 NewFrameEventsEntry mNewFrameEntryOverride = { 0, 0, 0, nullptr };
454};
455
456
457class FakeSurfaceComposer : public ISurfaceComposer{
458public:
459 ~FakeSurfaceComposer() override {}
460
Brian Anderson6b376712017-04-04 10:51:39 -0700461 void setSupportsPresent(bool supportsPresent) {
462 mSupportsPresent = supportsPresent;
463 }
464
Brian Anderson3da8d272016-07-28 16:20:47 -0700465 sp<ISurfaceComposerClient> createConnection() override { return nullptr; }
Robert Carr1db73f62016-12-21 12:58:51 -0800466 sp<ISurfaceComposerClient> createScopedConnection(
467 const sp<IGraphicBufferProducer>& /* parent */) override {
468 return nullptr;
469 }
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700470 sp<IDisplayEventConnection> createDisplayEventConnection(ISurfaceComposer::VsyncSource)
471 override {
Brian Anderson3da8d272016-07-28 16:20:47 -0700472 return nullptr;
473 }
474 sp<IBinder> createDisplay(const String8& /*displayName*/,
475 bool /*secure*/) override { return nullptr; }
476 void destroyDisplay(const sp<IBinder>& /*display */) override {}
477 sp<IBinder> getBuiltInDisplay(int32_t /*id*/) override { return nullptr; }
478 void setTransactionState(const Vector<ComposerState>& /*state*/,
479 const Vector<DisplayState>& /*displays*/, uint32_t /*flags*/)
480 override {}
481 void bootFinished() override {}
482 bool authenticateSurfaceTexture(
483 const sp<IGraphicBufferProducer>& /*surface*/) const override {
484 return false;
485 }
Brian Anderson6b376712017-04-04 10:51:39 -0700486
487 status_t getSupportedFrameTimestamps(std::vector<FrameEvent>* outSupported)
488 const override {
489 *outSupported = {
490 FrameEvent::REQUESTED_PRESENT,
491 FrameEvent::ACQUIRE,
492 FrameEvent::LATCH,
493 FrameEvent::FIRST_REFRESH_START,
494 FrameEvent::LAST_REFRESH_START,
495 FrameEvent::GPU_COMPOSITION_DONE,
496 FrameEvent::DEQUEUE_READY,
497 FrameEvent::RELEASE
498 };
499 if (mSupportsPresent) {
500 outSupported->push_back(
501 FrameEvent::DISPLAY_PRESENT);
502 }
503 return NO_ERROR;
504 }
505
Brian Anderson3da8d272016-07-28 16:20:47 -0700506 void setPowerMode(const sp<IBinder>& /*display*/, int /*mode*/) override {}
507 status_t getDisplayConfigs(const sp<IBinder>& /*display*/,
508 Vector<DisplayInfo>* /*configs*/) override { return NO_ERROR; }
509 status_t getDisplayStats(const sp<IBinder>& /*display*/,
510 DisplayStatInfo* /*stats*/) override { return NO_ERROR; }
511 int getActiveConfig(const sp<IBinder>& /*display*/) override { return 0; }
512 status_t setActiveConfig(const sp<IBinder>& /*display*/, int /*id*/)
513 override {
514 return NO_ERROR;
515 }
516 status_t getDisplayColorModes(const sp<IBinder>& /*display*/,
517 Vector<android_color_mode_t>* /*outColorModes*/) override {
518 return NO_ERROR;
519 }
520 android_color_mode_t getActiveColorMode(const sp<IBinder>& /*display*/)
521 override {
522 return HAL_COLOR_MODE_NATIVE;
523 }
524 status_t setActiveColorMode(const sp<IBinder>& /*display*/,
525 android_color_mode_t /*colorMode*/) override { return NO_ERROR; }
526 status_t captureScreen(const sp<IBinder>& /*display*/,
527 const sp<IGraphicBufferProducer>& /*producer*/,
528 Rect /*sourceCrop*/, uint32_t /*reqWidth*/, uint32_t /*reqHeight*/,
Robert Carrae060832016-11-28 10:51:00 -0800529 int32_t /*minLayerZ*/, int32_t /*maxLayerZ*/,
Brian Anderson3da8d272016-07-28 16:20:47 -0700530 bool /*useIdentityTransform*/,
531 Rotation /*rotation*/) override { return NO_ERROR; }
532 status_t clearAnimationFrameStats() override { return NO_ERROR; }
533 status_t getAnimationFrameStats(FrameStats* /*outStats*/) const override {
534 return NO_ERROR;
535 }
536 status_t getHdrCapabilities(const sp<IBinder>& /*display*/,
537 HdrCapabilities* /*outCapabilities*/) const override {
538 return NO_ERROR;
539 }
540 status_t enableVSyncInjections(bool /*enable*/) override {
541 return NO_ERROR;
542 }
543 status_t injectVSync(nsecs_t /*when*/) override { return NO_ERROR; }
Kalle Raitaa099a242017-01-11 11:17:29 -0800544 status_t getLayerDebugInfo(std::vector<LayerDebugInfo>* /*layers*/) const override {
545 return NO_ERROR;
546 }
Brian Anderson3da8d272016-07-28 16:20:47 -0700547
548protected:
549 IBinder* onAsBinder() override { return nullptr; }
550
551private:
552 bool mSupportsPresent{true};
Brian Anderson3da8d272016-07-28 16:20:47 -0700553};
554
555class FakeProducerFrameEventHistory : public ProducerFrameEventHistory {
556public:
557 FakeProducerFrameEventHistory(FenceToFenceTimeMap* fenceMap)
558 : mFenceMap(fenceMap) {}
559
560 ~FakeProducerFrameEventHistory() {}
561
562 void updateAcquireFence(uint64_t frameNumber,
563 std::shared_ptr<FenceTime>&& acquire) override {
564 // Verify the acquire fence being added isn't the one from the consumer.
565 EXPECT_NE(mConsumerAcquireFence, acquire);
566 // Override the fence, so we can verify this was called by the
567 // producer after the frame is queued.
568 ProducerFrameEventHistory::updateAcquireFence(frameNumber,
569 std::shared_ptr<FenceTime>(mAcquireFenceOverride));
570 }
571
572 void setAcquireFenceOverride(
573 const std::shared_ptr<FenceTime>& acquireFenceOverride,
574 const std::shared_ptr<FenceTime>& consumerAcquireFence) {
575 mAcquireFenceOverride = acquireFenceOverride;
576 mConsumerAcquireFence = consumerAcquireFence;
577 }
578
579protected:
580 std::shared_ptr<FenceTime> createFenceTime(const sp<Fence>& fence)
581 const override {
582 return mFenceMap->createFenceTimeForTest(fence);
583 }
584
585 FenceToFenceTimeMap* mFenceMap{nullptr};
586
587 std::shared_ptr<FenceTime> mAcquireFenceOverride{FenceTime::NO_FENCE};
588 std::shared_ptr<FenceTime> mConsumerAcquireFence{FenceTime::NO_FENCE};
589};
590
591
592class TestSurface : public Surface {
593public:
594 TestSurface(const sp<IGraphicBufferProducer>& bufferProducer,
595 FenceToFenceTimeMap* fenceMap)
596 : Surface(bufferProducer),
597 mFakeSurfaceComposer(new FakeSurfaceComposer) {
598 mFakeFrameEventHistory = new FakeProducerFrameEventHistory(fenceMap);
599 mFrameEventHistory.reset(mFakeFrameEventHistory);
600 }
601
602 ~TestSurface() override {}
603
604 sp<ISurfaceComposer> composerService() const override {
605 return mFakeSurfaceComposer;
606 }
607
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800608 nsecs_t now() const override {
609 return mNow;
610 }
611
612 void setNow(nsecs_t now) {
613 mNow = now;
614 }
615
Brian Anderson3da8d272016-07-28 16:20:47 -0700616public:
617 sp<FakeSurfaceComposer> mFakeSurfaceComposer;
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800618 nsecs_t mNow = 0;
Brian Anderson3da8d272016-07-28 16:20:47 -0700619
620 // mFrameEventHistory owns the instance of FakeProducerFrameEventHistory,
621 // but this raw pointer gives access to test functionality.
622 FakeProducerFrameEventHistory* mFakeFrameEventHistory;
623};
624
625
Brian Andersond0010582017-03-07 13:20:31 -0800626class GetFrameTimestampsTest : public ::testing::Test {
Brian Anderson3da8d272016-07-28 16:20:47 -0700627protected:
628 struct FenceAndFenceTime {
629 explicit FenceAndFenceTime(FenceToFenceTimeMap& fenceMap)
630 : mFence(new Fence),
631 mFenceTime(fenceMap.createFenceTimeForTest(mFence)) {}
632 sp<Fence> mFence { nullptr };
633 std::shared_ptr<FenceTime> mFenceTime { nullptr };
634 };
635
636 struct RefreshEvents {
637 RefreshEvents(FenceToFenceTimeMap& fenceMap, nsecs_t refreshStart)
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800638 : mFenceMap(fenceMap),
639 kCompositorTiming(
640 {refreshStart, refreshStart + 1, refreshStart + 2 }),
641 kStartTime(refreshStart + 3),
642 kGpuCompositionDoneTime(refreshStart + 4),
643 kPresentTime(refreshStart + 5) {}
Brian Anderson3da8d272016-07-28 16:20:47 -0700644
645 void signalPostCompositeFences() {
646 mFenceMap.signalAllForTest(
647 mGpuCompositionDone.mFence, kGpuCompositionDoneTime);
648 mFenceMap.signalAllForTest(mPresent.mFence, kPresentTime);
649 }
650
651 FenceToFenceTimeMap& mFenceMap;
652
653 FenceAndFenceTime mGpuCompositionDone { mFenceMap };
654 FenceAndFenceTime mPresent { mFenceMap };
655
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800656 const CompositorTiming kCompositorTiming;
657
Brian Anderson3da8d272016-07-28 16:20:47 -0700658 const nsecs_t kStartTime;
659 const nsecs_t kGpuCompositionDoneTime;
660 const nsecs_t kPresentTime;
661 };
662
663 struct FrameEvents {
664 FrameEvents(FenceToFenceTimeMap& fenceMap, nsecs_t frameStartTime)
665 : mFenceMap(fenceMap),
666 kPostedTime(frameStartTime + 100),
667 kRequestedPresentTime(frameStartTime + 200),
668 kProducerAcquireTime(frameStartTime + 300),
669 kConsumerAcquireTime(frameStartTime + 301),
670 kLatchTime(frameStartTime + 500),
Brian Andersonf6386862016-10-31 16:34:13 -0700671 kDequeueReadyTime(frameStartTime + 600),
Brian Anderson4e606e32017-03-16 15:34:57 -0700672 kReleaseTime(frameStartTime + 700),
Brian Anderson3da8d272016-07-28 16:20:47 -0700673 mRefreshes {
674 { mFenceMap, frameStartTime + 410 },
675 { mFenceMap, frameStartTime + 420 },
676 { mFenceMap, frameStartTime + 430 } } {}
677
678 void signalQueueFences() {
679 mFenceMap.signalAllForTest(
680 mAcquireConsumer.mFence, kConsumerAcquireTime);
681 mFenceMap.signalAllForTest(
682 mAcquireProducer.mFence, kProducerAcquireTime);
683 }
684
685 void signalRefreshFences() {
686 for (auto& re : mRefreshes) {
687 re.signalPostCompositeFences();
688 }
689 }
690
691 void signalReleaseFences() {
Brian Anderson3da8d272016-07-28 16:20:47 -0700692 mFenceMap.signalAllForTest(mRelease.mFence, kReleaseTime);
693 }
694
695 FenceToFenceTimeMap& mFenceMap;
696
697 FenceAndFenceTime mAcquireConsumer { mFenceMap };
698 FenceAndFenceTime mAcquireProducer { mFenceMap };
Brian Anderson3da8d272016-07-28 16:20:47 -0700699 FenceAndFenceTime mRelease { mFenceMap };
700
701 const nsecs_t kPostedTime;
702 const nsecs_t kRequestedPresentTime;
703 const nsecs_t kProducerAcquireTime;
704 const nsecs_t kConsumerAcquireTime;
705 const nsecs_t kLatchTime;
Brian Andersonf6386862016-10-31 16:34:13 -0700706 const nsecs_t kDequeueReadyTime;
Brian Anderson3da8d272016-07-28 16:20:47 -0700707 const nsecs_t kReleaseTime;
708
709 RefreshEvents mRefreshes[3];
710 };
711
Brian Andersond0010582017-03-07 13:20:31 -0800712 GetFrameTimestampsTest() {}
Brian Anderson3da8d272016-07-28 16:20:47 -0700713
714 virtual void SetUp() {
Brian Anderson3da8d272016-07-28 16:20:47 -0700715 BufferQueue::createBufferQueue(&mProducer, &mConsumer);
716 mFakeConsumer = new FakeConsumer;
717 mCfeh = &mFakeConsumer->mFrameEventHistory;
718 mConsumer->consumerConnect(mFakeConsumer, false);
719 mConsumer->setConsumerName(String8("TestConsumer"));
720 mSurface = new TestSurface(mProducer, &mFenceMap);
721 mWindow = mSurface;
722
723 ASSERT_EQ(NO_ERROR, native_window_api_connect(mWindow.get(),
724 NATIVE_WINDOW_API_CPU));
725 native_window_set_buffer_count(mWindow.get(), 4);
726 }
727
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800728 void disableFrameTimestamps() {
729 mFakeConsumer->mGetFrameTimestampsEnabled = false;
730 native_window_enable_frame_timestamps(mWindow.get(), 0);
731 mFrameTimestampsEnabled = false;
732 }
733
Brian Anderson3da8d272016-07-28 16:20:47 -0700734 void enableFrameTimestamps() {
735 mFakeConsumer->mGetFrameTimestampsEnabled = true;
736 native_window_enable_frame_timestamps(mWindow.get(), 1);
737 mFrameTimestampsEnabled = true;
738 }
739
Brian Anderson1049d1d2016-12-16 17:25:57 -0800740 int getAllFrameTimestamps(uint64_t frameId) {
741 return native_window_get_frame_timestamps(mWindow.get(), frameId,
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700742 &outRequestedPresentTime, &outAcquireTime, &outLatchTime,
743 &outFirstRefreshStartTime, &outLastRefreshStartTime,
744 &outGpuCompositionDoneTime, &outDisplayPresentTime,
Brian Anderson4e606e32017-03-16 15:34:57 -0700745 &outDequeueReadyTime, &outReleaseTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700746 }
747
Brian Anderson3da8d272016-07-28 16:20:47 -0700748 void resetTimestamps() {
749 outRequestedPresentTime = -1;
750 outAcquireTime = -1;
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700751 outLatchTime = -1;
752 outFirstRefreshStartTime = -1;
753 outLastRefreshStartTime = -1;
Brian Anderson3da8d272016-07-28 16:20:47 -0700754 outGpuCompositionDoneTime = -1;
755 outDisplayPresentTime = -1;
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700756 outDequeueReadyTime = -1;
Brian Anderson3da8d272016-07-28 16:20:47 -0700757 outReleaseTime = -1;
758 }
759
Brian Anderson1049d1d2016-12-16 17:25:57 -0800760 uint64_t getNextFrameId() {
761 uint64_t frameId = -1;
762 int status = native_window_get_next_frame_id(mWindow.get(), &frameId);
763 EXPECT_EQ(status, NO_ERROR);
764 return frameId;
765 }
766
Brian Anderson3da8d272016-07-28 16:20:47 -0700767 void dequeueAndQueue(uint64_t frameIndex) {
768 int fence = -1;
769 ANativeWindowBuffer* buffer = nullptr;
770 ASSERT_EQ(NO_ERROR,
771 mWindow->dequeueBuffer(mWindow.get(), &buffer, &fence));
772
773 int oldAddFrameTimestampsCount =
774 mFakeConsumer->mAddFrameTimestampsCount;
775
776 FrameEvents* frame = &mFrames[frameIndex];
777 uint64_t frameNumber = frameIndex + 1;
778
779 NewFrameEventsEntry fe;
780 fe.frameNumber = frameNumber;
781 fe.postedTime = frame->kPostedTime;
782 fe.requestedPresentTime = frame->kRequestedPresentTime;
783 fe.acquireFence = frame->mAcquireConsumer.mFenceTime;
784 mFakeConsumer->mNewFrameEntryOverride = fe;
785
786 mSurface->mFakeFrameEventHistory->setAcquireFenceOverride(
787 frame->mAcquireProducer.mFenceTime,
788 frame->mAcquireConsumer.mFenceTime);
789
790 ASSERT_EQ(NO_ERROR, mWindow->queueBuffer(mWindow.get(), buffer, fence));
791
792 EXPECT_EQ(frameNumber, mFakeConsumer->mLastAddedFrameNumber);
793
794 EXPECT_EQ(
795 oldAddFrameTimestampsCount + (mFrameTimestampsEnabled ? 1 : 0),
796 mFakeConsumer->mAddFrameTimestampsCount);
797 }
798
799 void addFrameEvents(
800 bool gpuComposited, uint64_t iOldFrame, int64_t iNewFrame) {
801 FrameEvents* oldFrame =
802 (iOldFrame == NO_FRAME_INDEX) ? nullptr : &mFrames[iOldFrame];
803 FrameEvents* newFrame = &mFrames[iNewFrame];
804
805 uint64_t nOldFrame = iOldFrame + 1;
806 uint64_t nNewFrame = iNewFrame + 1;
807
Brian Anderson4e606e32017-03-16 15:34:57 -0700808 // Latch, Composite, and Release the frames in a plausible order.
809 // Note: The timestamps won't necessarily match the order, but
Brian Anderson3da8d272016-07-28 16:20:47 -0700810 // that's okay for the purposes of this test.
811 std::shared_ptr<FenceTime> gpuDoneFenceTime = FenceTime::NO_FENCE;
812
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700813 // Composite the previous frame one more time, which helps verify
814 // LastRefresh is updated properly.
815 if (oldFrame != nullptr) {
816 mCfeh->addPreComposition(nOldFrame,
817 oldFrame->mRefreshes[2].kStartTime);
818 gpuDoneFenceTime = gpuComposited ?
819 oldFrame->mRefreshes[2].mGpuCompositionDone.mFenceTime :
820 FenceTime::NO_FENCE;
821 mCfeh->addPostComposition(nOldFrame, gpuDoneFenceTime,
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800822 oldFrame->mRefreshes[2].mPresent.mFenceTime,
823 oldFrame->mRefreshes[2].kCompositorTiming);
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700824 }
825
826 // Latch the new frame.
Brian Anderson3da8d272016-07-28 16:20:47 -0700827 mCfeh->addLatch(nNewFrame, newFrame->kLatchTime);
828
829 mCfeh->addPreComposition(nNewFrame, newFrame->mRefreshes[0].kStartTime);
830 gpuDoneFenceTime = gpuComposited ?
831 newFrame->mRefreshes[0].mGpuCompositionDone.mFenceTime :
832 FenceTime::NO_FENCE;
833 // HWC2 releases the previous buffer after a new latch just before
834 // calling postComposition.
835 if (oldFrame != nullptr) {
Brian Andersonf6386862016-10-31 16:34:13 -0700836 mCfeh->addRelease(nOldFrame, oldFrame->kDequeueReadyTime,
Brian Anderson3da8d272016-07-28 16:20:47 -0700837 std::shared_ptr<FenceTime>(oldFrame->mRelease.mFenceTime));
838 }
839 mCfeh->addPostComposition(nNewFrame, gpuDoneFenceTime,
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800840 newFrame->mRefreshes[0].mPresent.mFenceTime,
841 newFrame->mRefreshes[0].kCompositorTiming);
Brian Anderson3da8d272016-07-28 16:20:47 -0700842
Brian Anderson3da8d272016-07-28 16:20:47 -0700843 mCfeh->addPreComposition(nNewFrame, newFrame->mRefreshes[1].kStartTime);
844 gpuDoneFenceTime = gpuComposited ?
845 newFrame->mRefreshes[1].mGpuCompositionDone.mFenceTime :
846 FenceTime::NO_FENCE;
847 mCfeh->addPostComposition(nNewFrame, gpuDoneFenceTime,
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800848 newFrame->mRefreshes[1].mPresent.mFenceTime,
849 newFrame->mRefreshes[1].kCompositorTiming);
Brian Anderson3da8d272016-07-28 16:20:47 -0700850 }
851
Brian Anderson3da8d272016-07-28 16:20:47 -0700852 sp<IGraphicBufferProducer> mProducer;
853 sp<IGraphicBufferConsumer> mConsumer;
854 sp<FakeConsumer> mFakeConsumer;
855 ConsumerFrameEventHistory* mCfeh;
856 sp<TestSurface> mSurface;
857 sp<ANativeWindow> mWindow;
858
859 FenceToFenceTimeMap mFenceMap;
860
861 bool mFrameTimestampsEnabled = false;
862
863 int64_t outRequestedPresentTime = -1;
864 int64_t outAcquireTime = -1;
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700865 int64_t outLatchTime = -1;
866 int64_t outFirstRefreshStartTime = -1;
867 int64_t outLastRefreshStartTime = -1;
Brian Anderson3da8d272016-07-28 16:20:47 -0700868 int64_t outGpuCompositionDoneTime = -1;
869 int64_t outDisplayPresentTime = -1;
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700870 int64_t outDequeueReadyTime = -1;
Brian Anderson3da8d272016-07-28 16:20:47 -0700871 int64_t outReleaseTime = -1;
872
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800873 FrameEvents mFrames[3] {
874 { mFenceMap, 1000 }, { mFenceMap, 2000 }, { mFenceMap, 3000 } };
Brian Anderson3da8d272016-07-28 16:20:47 -0700875};
876
877
878// This test verifies that the frame timestamps are not retrieved when not
879// explicitly enabled via native_window_enable_frame_timestamps.
880// We want to check this to make sure there's no overhead for users
881// that don't need the timestamp information.
882TEST_F(GetFrameTimestampsTest, DefaultDisabled) {
883 int fence;
884 ANativeWindowBuffer* buffer;
885
886 EXPECT_EQ(0, mFakeConsumer->mAddFrameTimestampsCount);
887 EXPECT_EQ(0, mFakeConsumer->mGetFrameTimestampsCount);
888
Brian Anderson1049d1d2016-12-16 17:25:57 -0800889 const uint64_t fId = getNextFrameId();
890
Brian Anderson3da8d272016-07-28 16:20:47 -0700891 // Verify the producer doesn't get frame timestamps piggybacked on dequeue.
892 ASSERT_EQ(NO_ERROR, mWindow->dequeueBuffer(mWindow.get(), &buffer, &fence));
893 EXPECT_EQ(0, mFakeConsumer->mAddFrameTimestampsCount);
894 EXPECT_EQ(0, mFakeConsumer->mGetFrameTimestampsCount);
895
896 // Verify the producer doesn't get frame timestamps piggybacked on queue.
897 // It is okay that frame timestamps are added in the consumer since it is
898 // still needed for SurfaceFlinger dumps.
899 ASSERT_EQ(NO_ERROR, mWindow->queueBuffer(mWindow.get(), buffer, fence));
900 EXPECT_EQ(1, mFakeConsumer->mAddFrameTimestampsCount);
901 EXPECT_EQ(0, mFakeConsumer->mGetFrameTimestampsCount);
902
903 // Verify attempts to get frame timestamps fail.
Brian Anderson1049d1d2016-12-16 17:25:57 -0800904 int result = getAllFrameTimestamps(fId);
Brian Anderson3da8d272016-07-28 16:20:47 -0700905 EXPECT_EQ(INVALID_OPERATION, result);
906 EXPECT_EQ(0, mFakeConsumer->mGetFrameTimestampsCount);
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800907
908 // Verify compositor timing query fails.
909 nsecs_t compositeDeadline = 0;
910 nsecs_t compositeInterval = 0;
911 nsecs_t compositeToPresentLatency = 0;
912 result = native_window_get_compositor_timing(mWindow.get(),
913 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
914 EXPECT_EQ(INVALID_OPERATION, result);
Brian Anderson3da8d272016-07-28 16:20:47 -0700915}
916
917// This test verifies that the frame timestamps are retrieved if explicitly
918// enabled via native_window_enable_frame_timestamps.
919TEST_F(GetFrameTimestampsTest, EnabledSimple) {
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800920 CompositorTiming initialCompositorTiming {
921 1000000000, // 1s deadline
922 16666667, // 16ms interval
923 50000000, // 50ms present latency
924 };
925 mCfeh->initializeCompositorTiming(initialCompositorTiming);
926
Brian Anderson3da8d272016-07-28 16:20:47 -0700927 enableFrameTimestamps();
928
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800929 // Verify the compositor timing query gets the initial compositor values
930 // after timststamps are enabled; even before the first frame is queued
931 // or dequeued.
932 nsecs_t compositeDeadline = 0;
933 nsecs_t compositeInterval = 0;
934 nsecs_t compositeToPresentLatency = 0;
935 mSurface->setNow(initialCompositorTiming.deadline - 1);
936 int result = native_window_get_compositor_timing(mWindow.get(),
937 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
938 EXPECT_EQ(NO_ERROR, result);
939 EXPECT_EQ(initialCompositorTiming.deadline, compositeDeadline);
940 EXPECT_EQ(initialCompositorTiming.interval, compositeInterval);
941 EXPECT_EQ(initialCompositorTiming.presentLatency,
942 compositeToPresentLatency);
943
Brian Anderson3da8d272016-07-28 16:20:47 -0700944 int fence;
945 ANativeWindowBuffer* buffer;
946
947 EXPECT_EQ(0, mFakeConsumer->mAddFrameTimestampsCount);
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800948 EXPECT_EQ(1, mFakeConsumer->mGetFrameTimestampsCount);
Brian Anderson3da8d272016-07-28 16:20:47 -0700949
Brian Anderson1049d1d2016-12-16 17:25:57 -0800950 const uint64_t fId1 = getNextFrameId();
951
Brian Anderson3da8d272016-07-28 16:20:47 -0700952 // Verify getFrameTimestamps is piggybacked on dequeue.
953 ASSERT_EQ(NO_ERROR, mWindow->dequeueBuffer(mWindow.get(), &buffer, &fence));
954 EXPECT_EQ(0, mFakeConsumer->mAddFrameTimestampsCount);
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800955 EXPECT_EQ(2, mFakeConsumer->mGetFrameTimestampsCount);
Brian Anderson3da8d272016-07-28 16:20:47 -0700956
957 NewFrameEventsEntry f1;
958 f1.frameNumber = 1;
959 f1.postedTime = mFrames[0].kPostedTime;
960 f1.requestedPresentTime = mFrames[0].kRequestedPresentTime;
961 f1.acquireFence = mFrames[0].mAcquireConsumer.mFenceTime;
962 mSurface->mFakeFrameEventHistory->setAcquireFenceOverride(
963 mFrames[0].mAcquireProducer.mFenceTime,
964 mFrames[0].mAcquireConsumer.mFenceTime);
965 mFakeConsumer->mNewFrameEntryOverride = f1;
966 mFrames[0].signalQueueFences();
967
968 // Verify getFrameTimestamps is piggybacked on queue.
969 ASSERT_EQ(NO_ERROR, mWindow->queueBuffer(mWindow.get(), buffer, fence));
970 EXPECT_EQ(1, mFakeConsumer->mAddFrameTimestampsCount);
971 EXPECT_EQ(1u, mFakeConsumer->mLastAddedFrameNumber);
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800972 EXPECT_EQ(3, mFakeConsumer->mGetFrameTimestampsCount);
Brian Anderson3da8d272016-07-28 16:20:47 -0700973
974 // Verify queries for timestamps that the producer doesn't know about
975 // triggers a call to see if the consumer has any new timestamps.
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800976 result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -0700977 EXPECT_EQ(NO_ERROR, result);
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800978 EXPECT_EQ(4, mFakeConsumer->mGetFrameTimestampsCount);
Brian Anderson3da8d272016-07-28 16:20:47 -0700979}
980
Brian Anderson6b376712017-04-04 10:51:39 -0700981TEST_F(GetFrameTimestampsTest, QueryPresentSupported) {
982 bool displayPresentSupported = true;
983 mSurface->mFakeSurfaceComposer->setSupportsPresent(displayPresentSupported);
984
985 // Verify supported bits are forwarded.
986 int supportsPresent = -1;
987 mWindow.get()->query(mWindow.get(),
988 NATIVE_WINDOW_FRAME_TIMESTAMPS_SUPPORTS_PRESENT, &supportsPresent);
989 EXPECT_EQ(displayPresentSupported, supportsPresent);
990}
991
992TEST_F(GetFrameTimestampsTest, QueryPresentNotSupported) {
993 bool displayPresentSupported = false;
994 mSurface->mFakeSurfaceComposer->setSupportsPresent(displayPresentSupported);
995
996 // Verify supported bits are forwarded.
997 int supportsPresent = -1;
998 mWindow.get()->query(mWindow.get(),
999 NATIVE_WINDOW_FRAME_TIMESTAMPS_SUPPORTS_PRESENT, &supportsPresent);
1000 EXPECT_EQ(displayPresentSupported, supportsPresent);
1001}
1002
Brian Anderson0a61b0c2016-12-07 14:55:56 -08001003TEST_F(GetFrameTimestampsTest, SnapToNextTickBasic) {
1004 nsecs_t phase = 4000;
1005 nsecs_t interval = 1000;
1006
1007 // Timestamp in previous interval.
1008 nsecs_t timestamp = 3500;
1009 EXPECT_EQ(4000, ProducerFrameEventHistory::snapToNextTick(
1010 timestamp, phase, interval));
1011
1012 // Timestamp in next interval.
1013 timestamp = 4500;
1014 EXPECT_EQ(5000, ProducerFrameEventHistory::snapToNextTick(
1015 timestamp, phase, interval));
1016
1017 // Timestamp multiple intervals before.
1018 timestamp = 2500;
1019 EXPECT_EQ(3000, ProducerFrameEventHistory::snapToNextTick(
1020 timestamp, phase, interval));
1021
1022 // Timestamp multiple intervals after.
1023 timestamp = 6500;
1024 EXPECT_EQ(7000, ProducerFrameEventHistory::snapToNextTick(
1025 timestamp, phase, interval));
1026
1027 // Timestamp on previous interval.
1028 timestamp = 3000;
1029 EXPECT_EQ(3000, ProducerFrameEventHistory::snapToNextTick(
1030 timestamp, phase, interval));
1031
1032 // Timestamp on next interval.
1033 timestamp = 5000;
1034 EXPECT_EQ(5000, ProducerFrameEventHistory::snapToNextTick(
1035 timestamp, phase, interval));
1036
1037 // Timestamp equal to phase.
1038 timestamp = 4000;
1039 EXPECT_EQ(4000, ProducerFrameEventHistory::snapToNextTick(
1040 timestamp, phase, interval));
1041}
1042
1043// int(big_timestamp / interval) < 0, which can cause a crash or invalid result
1044// if the number of intervals elapsed is internally stored in an int.
1045TEST_F(GetFrameTimestampsTest, SnapToNextTickOverflow) {
1046 nsecs_t phase = 0;
1047 nsecs_t interval = 4000;
1048 nsecs_t big_timestamp = 8635916564000;
1049 int32_t intervals = big_timestamp / interval;
1050
1051 EXPECT_LT(intervals, 0);
1052 EXPECT_EQ(8635916564000, ProducerFrameEventHistory::snapToNextTick(
1053 big_timestamp, phase, interval));
1054 EXPECT_EQ(8635916564000, ProducerFrameEventHistory::snapToNextTick(
1055 big_timestamp, big_timestamp, interval));
1056}
1057
1058// This verifies the compositor timing is updated by refresh events
1059// and piggy backed on a queue, dequeue, and enabling of timestamps..
1060TEST_F(GetFrameTimestampsTest, CompositorTimingUpdatesBasic) {
1061 CompositorTiming initialCompositorTiming {
1062 1000000000, // 1s deadline
1063 16666667, // 16ms interval
1064 50000000, // 50ms present latency
1065 };
1066 mCfeh->initializeCompositorTiming(initialCompositorTiming);
1067
1068 enableFrameTimestamps();
1069
1070 // We get the initial values before any frames are submitted.
1071 nsecs_t compositeDeadline = 0;
1072 nsecs_t compositeInterval = 0;
1073 nsecs_t compositeToPresentLatency = 0;
1074 mSurface->setNow(initialCompositorTiming.deadline - 1);
1075 int result = native_window_get_compositor_timing(mWindow.get(),
1076 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1077 EXPECT_EQ(NO_ERROR, result);
1078 EXPECT_EQ(initialCompositorTiming.deadline, compositeDeadline);
1079 EXPECT_EQ(initialCompositorTiming.interval, compositeInterval);
1080 EXPECT_EQ(initialCompositorTiming.presentLatency,
1081 compositeToPresentLatency);
1082
1083 const uint64_t fId1 = getNextFrameId();
1084 dequeueAndQueue(0);
1085 addFrameEvents(true, NO_FRAME_INDEX, 0);
1086
1087 // Still get the initial values because the frame events for frame 0
1088 // didn't get a chance to piggyback on a queue or dequeue yet.
1089 result = native_window_get_compositor_timing(mWindow.get(),
1090 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1091 EXPECT_EQ(NO_ERROR, result);
1092 EXPECT_EQ(initialCompositorTiming.deadline, compositeDeadline);
1093 EXPECT_EQ(initialCompositorTiming.interval, compositeInterval);
1094 EXPECT_EQ(initialCompositorTiming.presentLatency,
1095 compositeToPresentLatency);
1096
1097 const uint64_t fId2 = getNextFrameId();
1098 dequeueAndQueue(1);
1099 addFrameEvents(true, 0, 1);
1100
1101 // Now expect the composite values associated with frame 1.
1102 mSurface->setNow(mFrames[0].mRefreshes[1].kCompositorTiming.deadline);
1103 result = native_window_get_compositor_timing(mWindow.get(),
1104 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1105 EXPECT_EQ(NO_ERROR, result);
1106 EXPECT_EQ(mFrames[0].mRefreshes[1].kCompositorTiming.deadline,
1107 compositeDeadline);
1108 EXPECT_EQ(mFrames[0].mRefreshes[1].kCompositorTiming.interval,
1109 compositeInterval);
1110 EXPECT_EQ(mFrames[0].mRefreshes[1].kCompositorTiming.presentLatency,
1111 compositeToPresentLatency);
1112
1113 dequeueAndQueue(2);
1114 addFrameEvents(true, 1, 2);
1115
1116 // Now expect the composite values associated with frame 2.
1117 mSurface->setNow(mFrames[1].mRefreshes[1].kCompositorTiming.deadline);
1118 result = native_window_get_compositor_timing(mWindow.get(),
1119 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1120 EXPECT_EQ(NO_ERROR, result);
1121 EXPECT_EQ(mFrames[1].mRefreshes[1].kCompositorTiming.deadline,
1122 compositeDeadline);
1123 EXPECT_EQ(mFrames[1].mRefreshes[1].kCompositorTiming.interval,
1124 compositeInterval);
1125 EXPECT_EQ(mFrames[1].mRefreshes[1].kCompositorTiming.presentLatency,
1126 compositeToPresentLatency);
1127
1128 // Re-enabling frame timestamps should get the latest values.
1129 disableFrameTimestamps();
1130 enableFrameTimestamps();
1131
1132 // Now expect the composite values associated with frame 3.
1133 mSurface->setNow(mFrames[2].mRefreshes[1].kCompositorTiming.deadline);
1134 result = native_window_get_compositor_timing(mWindow.get(),
1135 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1136 EXPECT_EQ(NO_ERROR, result);
1137 EXPECT_EQ(mFrames[2].mRefreshes[1].kCompositorTiming.deadline,
1138 compositeDeadline);
1139 EXPECT_EQ(mFrames[2].mRefreshes[1].kCompositorTiming.interval,
1140 compositeInterval);
1141 EXPECT_EQ(mFrames[2].mRefreshes[1].kCompositorTiming.presentLatency,
1142 compositeToPresentLatency);
1143}
1144
1145// This verifies the compositor deadline properly snaps to the the next
1146// deadline based on the current time.
1147TEST_F(GetFrameTimestampsTest, CompositorTimingDeadlineSnaps) {
1148 CompositorTiming initialCompositorTiming {
1149 1000000000, // 1s deadline
1150 16666667, // 16ms interval
1151 50000000, // 50ms present latency
1152 };
1153 mCfeh->initializeCompositorTiming(initialCompositorTiming);
1154
1155 enableFrameTimestamps();
1156
1157 nsecs_t compositeDeadline = 0;
1158 nsecs_t compositeInterval = 0;
1159 nsecs_t compositeToPresentLatency = 0;
1160
1161 // A "now" just before the deadline snaps to the deadline.
1162 mSurface->setNow(initialCompositorTiming.deadline - 1);
1163 int result = native_window_get_compositor_timing(mWindow.get(),
1164 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1165 EXPECT_EQ(NO_ERROR, result);
1166 EXPECT_EQ(initialCompositorTiming.deadline, compositeDeadline);
1167 nsecs_t expectedDeadline = initialCompositorTiming.deadline;
1168 EXPECT_EQ(expectedDeadline, compositeDeadline);
1169
1170 const uint64_t fId1 = getNextFrameId();
1171 dequeueAndQueue(0);
1172 addFrameEvents(true, NO_FRAME_INDEX, 0);
1173
1174 // A "now" just after the deadline snaps properly.
1175 mSurface->setNow(initialCompositorTiming.deadline + 1);
1176 result = native_window_get_compositor_timing(mWindow.get(),
1177 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1178 EXPECT_EQ(NO_ERROR, result);
1179 expectedDeadline =
1180 initialCompositorTiming.deadline +initialCompositorTiming.interval;
1181 EXPECT_EQ(expectedDeadline, compositeDeadline);
1182
1183 const uint64_t fId2 = getNextFrameId();
1184 dequeueAndQueue(1);
1185 addFrameEvents(true, 0, 1);
1186
1187 // A "now" just after the next interval snaps properly.
1188 mSurface->setNow(
1189 mFrames[0].mRefreshes[1].kCompositorTiming.deadline +
1190 mFrames[0].mRefreshes[1].kCompositorTiming.interval + 1);
1191 result = native_window_get_compositor_timing(mWindow.get(),
1192 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1193 EXPECT_EQ(NO_ERROR, result);
1194 expectedDeadline =
1195 mFrames[0].mRefreshes[1].kCompositorTiming.deadline +
1196 mFrames[0].mRefreshes[1].kCompositorTiming.interval * 2;
1197 EXPECT_EQ(expectedDeadline, compositeDeadline);
1198
1199 dequeueAndQueue(2);
1200 addFrameEvents(true, 1, 2);
1201
1202 // A "now" over 1 interval before the deadline snaps properly.
1203 mSurface->setNow(
1204 mFrames[1].mRefreshes[1].kCompositorTiming.deadline -
1205 mFrames[1].mRefreshes[1].kCompositorTiming.interval - 1);
1206 result = native_window_get_compositor_timing(mWindow.get(),
1207 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1208 EXPECT_EQ(NO_ERROR, result);
1209 expectedDeadline =
1210 mFrames[1].mRefreshes[1].kCompositorTiming.deadline -
1211 mFrames[1].mRefreshes[1].kCompositorTiming.interval;
1212 EXPECT_EQ(expectedDeadline, compositeDeadline);
1213
1214 // Re-enabling frame timestamps should get the latest values.
1215 disableFrameTimestamps();
1216 enableFrameTimestamps();
1217
1218 // A "now" over 2 intervals before the deadline snaps properly.
1219 mSurface->setNow(
1220 mFrames[2].mRefreshes[1].kCompositorTiming.deadline -
1221 mFrames[2].mRefreshes[1].kCompositorTiming.interval * 2 - 1);
1222 result = native_window_get_compositor_timing(mWindow.get(),
1223 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1224 EXPECT_EQ(NO_ERROR, result);
1225 expectedDeadline =
1226 mFrames[2].mRefreshes[1].kCompositorTiming.deadline -
1227 mFrames[2].mRefreshes[1].kCompositorTiming.interval * 2;
1228 EXPECT_EQ(expectedDeadline, compositeDeadline);
1229}
1230
Brian Anderson1049d1d2016-12-16 17:25:57 -08001231// This verifies the timestamps recorded in the consumer's
1232// FrameTimestampsHistory are properly retrieved by the producer for the
1233// correct frames.
Brian Anderson3da8d272016-07-28 16:20:47 -07001234TEST_F(GetFrameTimestampsTest, TimestampsAssociatedWithCorrectFrame) {
1235 enableFrameTimestamps();
1236
Brian Anderson1049d1d2016-12-16 17:25:57 -08001237 const uint64_t fId1 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001238 dequeueAndQueue(0);
1239 mFrames[0].signalQueueFences();
1240
Brian Anderson1049d1d2016-12-16 17:25:57 -08001241 const uint64_t fId2 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001242 dequeueAndQueue(1);
1243 mFrames[1].signalQueueFences();
1244
1245 addFrameEvents(true, NO_FRAME_INDEX, 0);
1246 mFrames[0].signalRefreshFences();
1247 addFrameEvents(true, 0, 1);
1248 mFrames[0].signalReleaseFences();
1249 mFrames[1].signalRefreshFences();
1250
1251 // Verify timestamps are correct for frame 1.
Brian Anderson3da8d272016-07-28 16:20:47 -07001252 resetTimestamps();
Brian Anderson1049d1d2016-12-16 17:25:57 -08001253 int result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001254 EXPECT_EQ(NO_ERROR, result);
1255 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1256 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001257 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1258 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1259 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001260 EXPECT_EQ(mFrames[0].mRefreshes[0].kGpuCompositionDoneTime,
1261 outGpuCompositionDoneTime);
1262 EXPECT_EQ(mFrames[0].mRefreshes[0].kPresentTime, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001263 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001264 EXPECT_EQ(mFrames[0].kReleaseTime, outReleaseTime);
1265
1266 // Verify timestamps are correct for frame 2.
Brian Anderson3da8d272016-07-28 16:20:47 -07001267 resetTimestamps();
Brian Anderson1049d1d2016-12-16 17:25:57 -08001268 result = getAllFrameTimestamps(fId2);
Brian Anderson3da8d272016-07-28 16:20:47 -07001269 EXPECT_EQ(NO_ERROR, result);
1270 EXPECT_EQ(mFrames[1].kRequestedPresentTime, outRequestedPresentTime);
1271 EXPECT_EQ(mFrames[1].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001272 EXPECT_EQ(mFrames[1].kLatchTime, outLatchTime);
1273 EXPECT_EQ(mFrames[1].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1274 EXPECT_EQ(mFrames[1].mRefreshes[1].kStartTime, outLastRefreshStartTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001275 EXPECT_EQ(mFrames[1].mRefreshes[0].kGpuCompositionDoneTime,
1276 outGpuCompositionDoneTime);
1277 EXPECT_EQ(mFrames[1].mRefreshes[0].kPresentTime, outDisplayPresentTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001278 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDequeueReadyTime);
1279 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001280}
1281
1282// This test verifies the acquire fence recorded by the consumer is not sent
1283// back to the producer and the producer saves its own fence.
1284TEST_F(GetFrameTimestampsTest, QueueTimestampsNoSync) {
1285 enableFrameTimestamps();
Brian Anderson3da8d272016-07-28 16:20:47 -07001286
Brian Anderson3da8d272016-07-28 16:20:47 -07001287 // Dequeue and queue frame 1.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001288 const uint64_t fId1 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001289 dequeueAndQueue(0);
1290
1291 // Verify queue-related timestamps for f1 are available immediately in the
1292 // producer without asking the consumer again, even before signaling the
1293 // acquire fence.
1294 resetTimestamps();
1295 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001296 int result = native_window_get_frame_timestamps(mWindow.get(), fId1,
Brian Anderson3da8d272016-07-28 16:20:47 -07001297 &outRequestedPresentTime, &outAcquireTime, nullptr, nullptr,
Brian Anderson4e606e32017-03-16 15:34:57 -07001298 nullptr, nullptr, nullptr, nullptr, nullptr);
Brian Anderson3da8d272016-07-28 16:20:47 -07001299 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1300 EXPECT_EQ(NO_ERROR, result);
1301 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001302 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outAcquireTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001303
1304 // Signal acquire fences. Verify a sync call still isn't necessary.
1305 mFrames[0].signalQueueFences();
1306
1307 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001308 result = native_window_get_frame_timestamps(mWindow.get(), fId1,
Brian Anderson3da8d272016-07-28 16:20:47 -07001309 &outRequestedPresentTime, &outAcquireTime, nullptr, nullptr,
Brian Anderson4e606e32017-03-16 15:34:57 -07001310 nullptr, nullptr, nullptr, nullptr, nullptr);
Brian Anderson3da8d272016-07-28 16:20:47 -07001311 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1312 EXPECT_EQ(NO_ERROR, result);
1313 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1314 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
1315
1316 // Dequeue and queue frame 2.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001317 const uint64_t fId2 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001318 dequeueAndQueue(1);
1319
1320 // Verify queue-related timestamps for f2 are available immediately in the
1321 // producer without asking the consumer again, even before signaling the
1322 // acquire fence.
1323 resetTimestamps();
1324 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001325 result = native_window_get_frame_timestamps(mWindow.get(), fId2,
Brian Anderson3da8d272016-07-28 16:20:47 -07001326 &outRequestedPresentTime, &outAcquireTime, nullptr, nullptr,
Brian Anderson4e606e32017-03-16 15:34:57 -07001327 nullptr, nullptr, nullptr, nullptr, nullptr);
Brian Anderson3da8d272016-07-28 16:20:47 -07001328 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1329 EXPECT_EQ(NO_ERROR, result);
1330 EXPECT_EQ(mFrames[1].kRequestedPresentTime, outRequestedPresentTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001331 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outAcquireTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001332
1333 // Signal acquire fences. Verify a sync call still isn't necessary.
1334 mFrames[1].signalQueueFences();
1335
1336 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001337 result = native_window_get_frame_timestamps(mWindow.get(), fId2,
Brian Anderson3da8d272016-07-28 16:20:47 -07001338 &outRequestedPresentTime, &outAcquireTime, nullptr, nullptr,
Brian Anderson4e606e32017-03-16 15:34:57 -07001339 nullptr, nullptr, nullptr, nullptr, nullptr);
Brian Anderson3da8d272016-07-28 16:20:47 -07001340 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1341 EXPECT_EQ(NO_ERROR, result);
1342 EXPECT_EQ(mFrames[1].kRequestedPresentTime, outRequestedPresentTime);
1343 EXPECT_EQ(mFrames[1].kProducerAcquireTime, outAcquireTime);
1344}
1345
1346TEST_F(GetFrameTimestampsTest, ZeroRequestedTimestampsNoSync) {
1347 enableFrameTimestamps();
Brian Anderson3da8d272016-07-28 16:20:47 -07001348
1349 // Dequeue and queue frame 1.
1350 dequeueAndQueue(0);
1351 mFrames[0].signalQueueFences();
1352
1353 // Dequeue and queue frame 2.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001354 const uint64_t fId2 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001355 dequeueAndQueue(1);
1356 mFrames[1].signalQueueFences();
1357
1358 addFrameEvents(true, NO_FRAME_INDEX, 0);
1359 mFrames[0].signalRefreshFences();
1360 addFrameEvents(true, 0, 1);
1361 mFrames[0].signalReleaseFences();
1362 mFrames[1].signalRefreshFences();
1363
1364 // Verify a request for no timestamps doesn't result in a sync call.
Brian Anderson3da8d272016-07-28 16:20:47 -07001365 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001366 int result = native_window_get_frame_timestamps(mWindow.get(), fId2,
Brian Anderson6b376712017-04-04 10:51:39 -07001367 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
1368 nullptr, nullptr);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001369 EXPECT_EQ(NO_ERROR, result);
Brian Anderson3da8d272016-07-28 16:20:47 -07001370 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1371}
1372
1373// This test verifies that fences can signal and update timestamps producer
1374// side without an additional sync call to the consumer.
1375TEST_F(GetFrameTimestampsTest, FencesInProducerNoSync) {
1376 enableFrameTimestamps();
Brian Anderson3da8d272016-07-28 16:20:47 -07001377
1378 // Dequeue and queue frame 1.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001379 const uint64_t fId1 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001380 dequeueAndQueue(0);
1381 mFrames[0].signalQueueFences();
1382
1383 // Dequeue and queue frame 2.
1384 dequeueAndQueue(1);
1385 mFrames[1].signalQueueFences();
1386
1387 addFrameEvents(true, NO_FRAME_INDEX, 0);
1388 addFrameEvents(true, 0, 1);
1389
1390 // Verify available timestamps are correct for frame 1, before any
1391 // fence has been signaled.
1392 // Note: A sync call is necessary here since the events triggered by
1393 // addFrameEvents didn't get to piggyback on the earlier queues/dequeues.
Brian Anderson3da8d272016-07-28 16:20:47 -07001394 resetTimestamps();
1395 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001396 int result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001397 EXPECT_EQ(oldCount + 1, mFakeConsumer->mGetFrameTimestampsCount);
1398 EXPECT_EQ(NO_ERROR, result);
1399 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1400 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001401 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1402 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1403 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001404 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outGpuCompositionDoneTime);
1405 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001406 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001407 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001408
1409 // Verify available timestamps are correct for frame 1 again, before any
1410 // fence has been signaled.
1411 // This time a sync call should not be necessary.
Brian Anderson3da8d272016-07-28 16:20:47 -07001412 resetTimestamps();
1413 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001414 result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001415 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1416 EXPECT_EQ(NO_ERROR, result);
1417 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1418 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001419 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1420 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1421 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001422 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outGpuCompositionDoneTime);
1423 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001424 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001425 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001426
1427 // Signal the fences for frame 1.
1428 mFrames[0].signalRefreshFences();
1429 mFrames[0].signalReleaseFences();
1430
1431 // Verify all timestamps are available without a sync call.
Brian Anderson3da8d272016-07-28 16:20:47 -07001432 resetTimestamps();
1433 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001434 result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001435 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1436 EXPECT_EQ(NO_ERROR, result);
1437 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1438 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001439 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1440 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1441 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001442 EXPECT_EQ(mFrames[0].mRefreshes[0].kGpuCompositionDoneTime,
1443 outGpuCompositionDoneTime);
1444 EXPECT_EQ(mFrames[0].mRefreshes[0].kPresentTime, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001445 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001446 EXPECT_EQ(mFrames[0].kReleaseTime, outReleaseTime);
1447}
1448
1449// This test verifies that if the frame wasn't GPU composited but has a refresh
1450// event a sync call isn't made to get the GPU composite done time since it will
1451// never exist.
1452TEST_F(GetFrameTimestampsTest, NoGpuNoSync) {
1453 enableFrameTimestamps();
Brian Anderson3da8d272016-07-28 16:20:47 -07001454
Brian Anderson3da8d272016-07-28 16:20:47 -07001455 // Dequeue and queue frame 1.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001456 const uint64_t fId1 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001457 dequeueAndQueue(0);
1458 mFrames[0].signalQueueFences();
1459
1460 // Dequeue and queue frame 2.
1461 dequeueAndQueue(1);
1462 mFrames[1].signalQueueFences();
1463
1464 addFrameEvents(false, NO_FRAME_INDEX, 0);
1465 addFrameEvents(false, 0, 1);
1466
1467 // Verify available timestamps are correct for frame 1, before any
1468 // fence has been signaled.
1469 // Note: A sync call is necessary here since the events triggered by
1470 // addFrameEvents didn't get to piggyback on the earlier queues/dequeues.
1471 resetTimestamps();
1472 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001473 int result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001474 EXPECT_EQ(oldCount + 1, mFakeConsumer->mGetFrameTimestampsCount);
1475 EXPECT_EQ(NO_ERROR, result);
1476 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1477 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001478 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1479 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1480 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001481 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_INVALID, outGpuCompositionDoneTime);
1482 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001483 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001484 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001485
1486 // Signal the fences for frame 1.
1487 mFrames[0].signalRefreshFences();
1488 mFrames[0].signalReleaseFences();
1489
1490 // Verify all timestamps, except GPU composition, are available without a
1491 // sync call.
1492 resetTimestamps();
1493 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001494 result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001495 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1496 EXPECT_EQ(NO_ERROR, result);
1497 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1498 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001499 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1500 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1501 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001502 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_INVALID, outGpuCompositionDoneTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001503 EXPECT_EQ(mFrames[0].mRefreshes[0].kPresentTime, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001504 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001505 EXPECT_EQ(mFrames[0].kReleaseTime, outReleaseTime);
1506}
1507
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001508// This test verifies that if the certain timestamps can't possibly exist for
1509// the most recent frame, then a sync call is not done.
Brian Anderson6b376712017-04-04 10:51:39 -07001510TEST_F(GetFrameTimestampsTest, NoReleaseNoSync) {
Brian Anderson3da8d272016-07-28 16:20:47 -07001511 enableFrameTimestamps();
Brian Anderson3da8d272016-07-28 16:20:47 -07001512
1513 // Dequeue and queue frame 1.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001514 const uint64_t fId1 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001515 dequeueAndQueue(0);
1516 mFrames[0].signalQueueFences();
1517
1518 // Dequeue and queue frame 2.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001519 const uint64_t fId2 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001520 dequeueAndQueue(1);
1521 mFrames[1].signalQueueFences();
1522
1523 addFrameEvents(false, NO_FRAME_INDEX, 0);
1524 addFrameEvents(false, 0, 1);
1525
1526 // Verify available timestamps are correct for frame 1, before any
1527 // fence has been signaled.
1528 // Note: A sync call is necessary here since the events triggered by
1529 // addFrameEvents didn't get to piggyback on the earlier queues/dequeues.
Brian Anderson3da8d272016-07-28 16:20:47 -07001530 resetTimestamps();
1531 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001532 int result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001533 EXPECT_EQ(oldCount + 1, mFakeConsumer->mGetFrameTimestampsCount);
1534 EXPECT_EQ(NO_ERROR, result);
1535 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1536 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001537 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1538 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1539 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001540 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_INVALID, outGpuCompositionDoneTime);
1541 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001542 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001543 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001544
1545 mFrames[0].signalRefreshFences();
1546 mFrames[0].signalReleaseFences();
1547 mFrames[1].signalRefreshFences();
1548
Brian Anderson1049d1d2016-12-16 17:25:57 -08001549 // Verify querying for all timestmaps of f2 does not do a sync call. Even
Brian Anderson4e606e32017-03-16 15:34:57 -07001550 // though the lastRefresh, dequeueReady, and release times aren't
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001551 // available, a sync call should not occur because it's not possible for f2
1552 // to encounter the final value for those events until another frame is
1553 // queued.
Brian Anderson3da8d272016-07-28 16:20:47 -07001554 resetTimestamps();
1555 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001556 result = getAllFrameTimestamps(fId2);
Brian Anderson3da8d272016-07-28 16:20:47 -07001557 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1558 EXPECT_EQ(NO_ERROR, result);
1559 EXPECT_EQ(mFrames[1].kRequestedPresentTime, outRequestedPresentTime);
1560 EXPECT_EQ(mFrames[1].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001561 EXPECT_EQ(mFrames[1].kLatchTime, outLatchTime);
1562 EXPECT_EQ(mFrames[1].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1563 EXPECT_EQ(mFrames[1].mRefreshes[1].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001564 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_INVALID, outGpuCompositionDoneTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001565 EXPECT_EQ(mFrames[1].mRefreshes[0].kPresentTime, outDisplayPresentTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001566 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDequeueReadyTime);
1567 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001568}
1569
Brian Anderson6b376712017-04-04 10:51:39 -07001570// This test verifies there are no sync calls for present times
1571// when they aren't supported and that an error is returned.
1572
1573TEST_F(GetFrameTimestampsTest, PresentUnsupportedNoSync) {
1574 enableFrameTimestamps();
1575 mSurface->mFakeSurfaceComposer->setSupportsPresent(false);
1576
1577 // Dequeue and queue frame 1.
1578 const uint64_t fId1 = getNextFrameId();
1579 dequeueAndQueue(0);
1580
1581 // Verify a query for the Present times do not trigger a sync call if they
1582 // are not supported.
1583 resetTimestamps();
1584 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
1585 int result = native_window_get_frame_timestamps(mWindow.get(), fId1,
1586 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
1587 &outDisplayPresentTime, nullptr, nullptr);
1588 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1589 EXPECT_EQ(BAD_VALUE, result);
1590 EXPECT_EQ(-1, outDisplayPresentTime);
1591}
1592
Dan Stoza932f0082017-05-31 13:50:16 -07001593} // namespace android