blob: 572760e77d87dd4b5bca2f76278e441176a2de12 [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
Brian Anderson0a61b0c2016-12-07 14:55:56 -08001083 dequeueAndQueue(0);
1084 addFrameEvents(true, NO_FRAME_INDEX, 0);
1085
1086 // Still get the initial values because the frame events for frame 0
1087 // didn't get a chance to piggyback on a queue or dequeue yet.
1088 result = native_window_get_compositor_timing(mWindow.get(),
1089 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1090 EXPECT_EQ(NO_ERROR, result);
1091 EXPECT_EQ(initialCompositorTiming.deadline, compositeDeadline);
1092 EXPECT_EQ(initialCompositorTiming.interval, compositeInterval);
1093 EXPECT_EQ(initialCompositorTiming.presentLatency,
1094 compositeToPresentLatency);
1095
Brian Anderson0a61b0c2016-12-07 14:55:56 -08001096 dequeueAndQueue(1);
1097 addFrameEvents(true, 0, 1);
1098
1099 // Now expect the composite values associated with frame 1.
1100 mSurface->setNow(mFrames[0].mRefreshes[1].kCompositorTiming.deadline);
1101 result = native_window_get_compositor_timing(mWindow.get(),
1102 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1103 EXPECT_EQ(NO_ERROR, result);
1104 EXPECT_EQ(mFrames[0].mRefreshes[1].kCompositorTiming.deadline,
1105 compositeDeadline);
1106 EXPECT_EQ(mFrames[0].mRefreshes[1].kCompositorTiming.interval,
1107 compositeInterval);
1108 EXPECT_EQ(mFrames[0].mRefreshes[1].kCompositorTiming.presentLatency,
1109 compositeToPresentLatency);
1110
1111 dequeueAndQueue(2);
1112 addFrameEvents(true, 1, 2);
1113
1114 // Now expect the composite values associated with frame 2.
1115 mSurface->setNow(mFrames[1].mRefreshes[1].kCompositorTiming.deadline);
1116 result = native_window_get_compositor_timing(mWindow.get(),
1117 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1118 EXPECT_EQ(NO_ERROR, result);
1119 EXPECT_EQ(mFrames[1].mRefreshes[1].kCompositorTiming.deadline,
1120 compositeDeadline);
1121 EXPECT_EQ(mFrames[1].mRefreshes[1].kCompositorTiming.interval,
1122 compositeInterval);
1123 EXPECT_EQ(mFrames[1].mRefreshes[1].kCompositorTiming.presentLatency,
1124 compositeToPresentLatency);
1125
1126 // Re-enabling frame timestamps should get the latest values.
1127 disableFrameTimestamps();
1128 enableFrameTimestamps();
1129
1130 // Now expect the composite values associated with frame 3.
1131 mSurface->setNow(mFrames[2].mRefreshes[1].kCompositorTiming.deadline);
1132 result = native_window_get_compositor_timing(mWindow.get(),
1133 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1134 EXPECT_EQ(NO_ERROR, result);
1135 EXPECT_EQ(mFrames[2].mRefreshes[1].kCompositorTiming.deadline,
1136 compositeDeadline);
1137 EXPECT_EQ(mFrames[2].mRefreshes[1].kCompositorTiming.interval,
1138 compositeInterval);
1139 EXPECT_EQ(mFrames[2].mRefreshes[1].kCompositorTiming.presentLatency,
1140 compositeToPresentLatency);
1141}
1142
1143// This verifies the compositor deadline properly snaps to the the next
1144// deadline based on the current time.
1145TEST_F(GetFrameTimestampsTest, CompositorTimingDeadlineSnaps) {
1146 CompositorTiming initialCompositorTiming {
1147 1000000000, // 1s deadline
1148 16666667, // 16ms interval
1149 50000000, // 50ms present latency
1150 };
1151 mCfeh->initializeCompositorTiming(initialCompositorTiming);
1152
1153 enableFrameTimestamps();
1154
1155 nsecs_t compositeDeadline = 0;
1156 nsecs_t compositeInterval = 0;
1157 nsecs_t compositeToPresentLatency = 0;
1158
1159 // A "now" just before the deadline snaps to the deadline.
1160 mSurface->setNow(initialCompositorTiming.deadline - 1);
1161 int result = native_window_get_compositor_timing(mWindow.get(),
1162 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1163 EXPECT_EQ(NO_ERROR, result);
1164 EXPECT_EQ(initialCompositorTiming.deadline, compositeDeadline);
1165 nsecs_t expectedDeadline = initialCompositorTiming.deadline;
1166 EXPECT_EQ(expectedDeadline, compositeDeadline);
1167
Brian Anderson0a61b0c2016-12-07 14:55:56 -08001168 dequeueAndQueue(0);
1169 addFrameEvents(true, NO_FRAME_INDEX, 0);
1170
1171 // A "now" just after the deadline snaps properly.
1172 mSurface->setNow(initialCompositorTiming.deadline + 1);
1173 result = native_window_get_compositor_timing(mWindow.get(),
1174 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1175 EXPECT_EQ(NO_ERROR, result);
1176 expectedDeadline =
1177 initialCompositorTiming.deadline +initialCompositorTiming.interval;
1178 EXPECT_EQ(expectedDeadline, compositeDeadline);
1179
Brian Anderson0a61b0c2016-12-07 14:55:56 -08001180 dequeueAndQueue(1);
1181 addFrameEvents(true, 0, 1);
1182
1183 // A "now" just after the next interval snaps properly.
1184 mSurface->setNow(
1185 mFrames[0].mRefreshes[1].kCompositorTiming.deadline +
1186 mFrames[0].mRefreshes[1].kCompositorTiming.interval + 1);
1187 result = native_window_get_compositor_timing(mWindow.get(),
1188 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1189 EXPECT_EQ(NO_ERROR, result);
1190 expectedDeadline =
1191 mFrames[0].mRefreshes[1].kCompositorTiming.deadline +
1192 mFrames[0].mRefreshes[1].kCompositorTiming.interval * 2;
1193 EXPECT_EQ(expectedDeadline, compositeDeadline);
1194
1195 dequeueAndQueue(2);
1196 addFrameEvents(true, 1, 2);
1197
1198 // A "now" over 1 interval before the deadline snaps properly.
1199 mSurface->setNow(
1200 mFrames[1].mRefreshes[1].kCompositorTiming.deadline -
1201 mFrames[1].mRefreshes[1].kCompositorTiming.interval - 1);
1202 result = native_window_get_compositor_timing(mWindow.get(),
1203 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1204 EXPECT_EQ(NO_ERROR, result);
1205 expectedDeadline =
1206 mFrames[1].mRefreshes[1].kCompositorTiming.deadline -
1207 mFrames[1].mRefreshes[1].kCompositorTiming.interval;
1208 EXPECT_EQ(expectedDeadline, compositeDeadline);
1209
1210 // Re-enabling frame timestamps should get the latest values.
1211 disableFrameTimestamps();
1212 enableFrameTimestamps();
1213
1214 // A "now" over 2 intervals before the deadline snaps properly.
1215 mSurface->setNow(
1216 mFrames[2].mRefreshes[1].kCompositorTiming.deadline -
1217 mFrames[2].mRefreshes[1].kCompositorTiming.interval * 2 - 1);
1218 result = native_window_get_compositor_timing(mWindow.get(),
1219 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1220 EXPECT_EQ(NO_ERROR, result);
1221 expectedDeadline =
1222 mFrames[2].mRefreshes[1].kCompositorTiming.deadline -
1223 mFrames[2].mRefreshes[1].kCompositorTiming.interval * 2;
1224 EXPECT_EQ(expectedDeadline, compositeDeadline);
1225}
1226
Brian Anderson1049d1d2016-12-16 17:25:57 -08001227// This verifies the timestamps recorded in the consumer's
1228// FrameTimestampsHistory are properly retrieved by the producer for the
1229// correct frames.
Brian Anderson3da8d272016-07-28 16:20:47 -07001230TEST_F(GetFrameTimestampsTest, TimestampsAssociatedWithCorrectFrame) {
1231 enableFrameTimestamps();
1232
Brian Anderson1049d1d2016-12-16 17:25:57 -08001233 const uint64_t fId1 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001234 dequeueAndQueue(0);
1235 mFrames[0].signalQueueFences();
1236
Brian Anderson1049d1d2016-12-16 17:25:57 -08001237 const uint64_t fId2 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001238 dequeueAndQueue(1);
1239 mFrames[1].signalQueueFences();
1240
1241 addFrameEvents(true, NO_FRAME_INDEX, 0);
1242 mFrames[0].signalRefreshFences();
1243 addFrameEvents(true, 0, 1);
1244 mFrames[0].signalReleaseFences();
1245 mFrames[1].signalRefreshFences();
1246
1247 // Verify timestamps are correct for frame 1.
Brian Anderson3da8d272016-07-28 16:20:47 -07001248 resetTimestamps();
Brian Anderson1049d1d2016-12-16 17:25:57 -08001249 int result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001250 EXPECT_EQ(NO_ERROR, result);
1251 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1252 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001253 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1254 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1255 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001256 EXPECT_EQ(mFrames[0].mRefreshes[0].kGpuCompositionDoneTime,
1257 outGpuCompositionDoneTime);
1258 EXPECT_EQ(mFrames[0].mRefreshes[0].kPresentTime, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001259 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001260 EXPECT_EQ(mFrames[0].kReleaseTime, outReleaseTime);
1261
1262 // Verify timestamps are correct for frame 2.
Brian Anderson3da8d272016-07-28 16:20:47 -07001263 resetTimestamps();
Brian Anderson1049d1d2016-12-16 17:25:57 -08001264 result = getAllFrameTimestamps(fId2);
Brian Anderson3da8d272016-07-28 16:20:47 -07001265 EXPECT_EQ(NO_ERROR, result);
1266 EXPECT_EQ(mFrames[1].kRequestedPresentTime, outRequestedPresentTime);
1267 EXPECT_EQ(mFrames[1].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001268 EXPECT_EQ(mFrames[1].kLatchTime, outLatchTime);
1269 EXPECT_EQ(mFrames[1].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1270 EXPECT_EQ(mFrames[1].mRefreshes[1].kStartTime, outLastRefreshStartTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001271 EXPECT_EQ(mFrames[1].mRefreshes[0].kGpuCompositionDoneTime,
1272 outGpuCompositionDoneTime);
1273 EXPECT_EQ(mFrames[1].mRefreshes[0].kPresentTime, outDisplayPresentTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001274 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDequeueReadyTime);
1275 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001276}
1277
1278// This test verifies the acquire fence recorded by the consumer is not sent
1279// back to the producer and the producer saves its own fence.
1280TEST_F(GetFrameTimestampsTest, QueueTimestampsNoSync) {
1281 enableFrameTimestamps();
Brian Anderson3da8d272016-07-28 16:20:47 -07001282
Brian Anderson3da8d272016-07-28 16:20:47 -07001283 // Dequeue and queue frame 1.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001284 const uint64_t fId1 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001285 dequeueAndQueue(0);
1286
1287 // Verify queue-related timestamps for f1 are available immediately in the
1288 // producer without asking the consumer again, even before signaling the
1289 // acquire fence.
1290 resetTimestamps();
1291 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001292 int result = native_window_get_frame_timestamps(mWindow.get(), fId1,
Brian Anderson3da8d272016-07-28 16:20:47 -07001293 &outRequestedPresentTime, &outAcquireTime, nullptr, nullptr,
Brian Anderson4e606e32017-03-16 15:34:57 -07001294 nullptr, nullptr, nullptr, nullptr, nullptr);
Brian Anderson3da8d272016-07-28 16:20:47 -07001295 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1296 EXPECT_EQ(NO_ERROR, result);
1297 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001298 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outAcquireTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001299
1300 // Signal acquire fences. Verify a sync call still isn't necessary.
1301 mFrames[0].signalQueueFences();
1302
1303 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001304 result = native_window_get_frame_timestamps(mWindow.get(), fId1,
Brian Anderson3da8d272016-07-28 16:20:47 -07001305 &outRequestedPresentTime, &outAcquireTime, nullptr, nullptr,
Brian Anderson4e606e32017-03-16 15:34:57 -07001306 nullptr, nullptr, nullptr, nullptr, nullptr);
Brian Anderson3da8d272016-07-28 16:20:47 -07001307 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1308 EXPECT_EQ(NO_ERROR, result);
1309 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1310 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
1311
1312 // Dequeue and queue frame 2.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001313 const uint64_t fId2 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001314 dequeueAndQueue(1);
1315
1316 // Verify queue-related timestamps for f2 are available immediately in the
1317 // producer without asking the consumer again, even before signaling the
1318 // acquire fence.
1319 resetTimestamps();
1320 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001321 result = native_window_get_frame_timestamps(mWindow.get(), fId2,
Brian Anderson3da8d272016-07-28 16:20:47 -07001322 &outRequestedPresentTime, &outAcquireTime, nullptr, nullptr,
Brian Anderson4e606e32017-03-16 15:34:57 -07001323 nullptr, nullptr, nullptr, nullptr, nullptr);
Brian Anderson3da8d272016-07-28 16:20:47 -07001324 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1325 EXPECT_EQ(NO_ERROR, result);
1326 EXPECT_EQ(mFrames[1].kRequestedPresentTime, outRequestedPresentTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001327 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outAcquireTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001328
1329 // Signal acquire fences. Verify a sync call still isn't necessary.
1330 mFrames[1].signalQueueFences();
1331
1332 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001333 result = native_window_get_frame_timestamps(mWindow.get(), fId2,
Brian Anderson3da8d272016-07-28 16:20:47 -07001334 &outRequestedPresentTime, &outAcquireTime, nullptr, nullptr,
Brian Anderson4e606e32017-03-16 15:34:57 -07001335 nullptr, nullptr, nullptr, nullptr, nullptr);
Brian Anderson3da8d272016-07-28 16:20:47 -07001336 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1337 EXPECT_EQ(NO_ERROR, result);
1338 EXPECT_EQ(mFrames[1].kRequestedPresentTime, outRequestedPresentTime);
1339 EXPECT_EQ(mFrames[1].kProducerAcquireTime, outAcquireTime);
1340}
1341
1342TEST_F(GetFrameTimestampsTest, ZeroRequestedTimestampsNoSync) {
1343 enableFrameTimestamps();
Brian Anderson3da8d272016-07-28 16:20:47 -07001344
1345 // Dequeue and queue frame 1.
1346 dequeueAndQueue(0);
1347 mFrames[0].signalQueueFences();
1348
1349 // Dequeue and queue frame 2.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001350 const uint64_t fId2 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001351 dequeueAndQueue(1);
1352 mFrames[1].signalQueueFences();
1353
1354 addFrameEvents(true, NO_FRAME_INDEX, 0);
1355 mFrames[0].signalRefreshFences();
1356 addFrameEvents(true, 0, 1);
1357 mFrames[0].signalReleaseFences();
1358 mFrames[1].signalRefreshFences();
1359
1360 // Verify a request for no timestamps doesn't result in a sync call.
Brian Anderson3da8d272016-07-28 16:20:47 -07001361 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001362 int result = native_window_get_frame_timestamps(mWindow.get(), fId2,
Brian Anderson6b376712017-04-04 10:51:39 -07001363 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
1364 nullptr, nullptr);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001365 EXPECT_EQ(NO_ERROR, result);
Brian Anderson3da8d272016-07-28 16:20:47 -07001366 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1367}
1368
1369// This test verifies that fences can signal and update timestamps producer
1370// side without an additional sync call to the consumer.
1371TEST_F(GetFrameTimestampsTest, FencesInProducerNoSync) {
1372 enableFrameTimestamps();
Brian Anderson3da8d272016-07-28 16:20:47 -07001373
1374 // Dequeue and queue frame 1.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001375 const uint64_t fId1 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001376 dequeueAndQueue(0);
1377 mFrames[0].signalQueueFences();
1378
1379 // Dequeue and queue frame 2.
1380 dequeueAndQueue(1);
1381 mFrames[1].signalQueueFences();
1382
1383 addFrameEvents(true, NO_FRAME_INDEX, 0);
1384 addFrameEvents(true, 0, 1);
1385
1386 // Verify available timestamps are correct for frame 1, before any
1387 // fence has been signaled.
1388 // Note: A sync call is necessary here since the events triggered by
1389 // addFrameEvents didn't get to piggyback on the earlier queues/dequeues.
Brian Anderson3da8d272016-07-28 16:20:47 -07001390 resetTimestamps();
1391 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001392 int result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001393 EXPECT_EQ(oldCount + 1, mFakeConsumer->mGetFrameTimestampsCount);
1394 EXPECT_EQ(NO_ERROR, result);
1395 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1396 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001397 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1398 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1399 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001400 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outGpuCompositionDoneTime);
1401 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001402 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001403 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001404
1405 // Verify available timestamps are correct for frame 1 again, before any
1406 // fence has been signaled.
1407 // This time a sync call should not be necessary.
Brian Anderson3da8d272016-07-28 16:20:47 -07001408 resetTimestamps();
1409 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001410 result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001411 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1412 EXPECT_EQ(NO_ERROR, result);
1413 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1414 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001415 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1416 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1417 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001418 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outGpuCompositionDoneTime);
1419 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001420 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001421 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001422
1423 // Signal the fences for frame 1.
1424 mFrames[0].signalRefreshFences();
1425 mFrames[0].signalReleaseFences();
1426
1427 // Verify all timestamps are available without a sync call.
Brian Anderson3da8d272016-07-28 16:20:47 -07001428 resetTimestamps();
1429 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001430 result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001431 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1432 EXPECT_EQ(NO_ERROR, result);
1433 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1434 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001435 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1436 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1437 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001438 EXPECT_EQ(mFrames[0].mRefreshes[0].kGpuCompositionDoneTime,
1439 outGpuCompositionDoneTime);
1440 EXPECT_EQ(mFrames[0].mRefreshes[0].kPresentTime, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001441 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001442 EXPECT_EQ(mFrames[0].kReleaseTime, outReleaseTime);
1443}
1444
1445// This test verifies that if the frame wasn't GPU composited but has a refresh
1446// event a sync call isn't made to get the GPU composite done time since it will
1447// never exist.
1448TEST_F(GetFrameTimestampsTest, NoGpuNoSync) {
1449 enableFrameTimestamps();
Brian Anderson3da8d272016-07-28 16:20:47 -07001450
Brian Anderson3da8d272016-07-28 16:20:47 -07001451 // Dequeue and queue frame 1.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001452 const uint64_t fId1 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001453 dequeueAndQueue(0);
1454 mFrames[0].signalQueueFences();
1455
1456 // Dequeue and queue frame 2.
1457 dequeueAndQueue(1);
1458 mFrames[1].signalQueueFences();
1459
1460 addFrameEvents(false, NO_FRAME_INDEX, 0);
1461 addFrameEvents(false, 0, 1);
1462
1463 // Verify available timestamps are correct for frame 1, before any
1464 // fence has been signaled.
1465 // Note: A sync call is necessary here since the events triggered by
1466 // addFrameEvents didn't get to piggyback on the earlier queues/dequeues.
1467 resetTimestamps();
1468 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001469 int result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001470 EXPECT_EQ(oldCount + 1, mFakeConsumer->mGetFrameTimestampsCount);
1471 EXPECT_EQ(NO_ERROR, result);
1472 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1473 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001474 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1475 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1476 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001477 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_INVALID, outGpuCompositionDoneTime);
1478 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001479 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001480 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001481
1482 // Signal the fences for frame 1.
1483 mFrames[0].signalRefreshFences();
1484 mFrames[0].signalReleaseFences();
1485
1486 // Verify all timestamps, except GPU composition, are available without a
1487 // sync call.
1488 resetTimestamps();
1489 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001490 result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001491 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1492 EXPECT_EQ(NO_ERROR, result);
1493 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1494 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001495 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1496 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1497 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001498 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_INVALID, outGpuCompositionDoneTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001499 EXPECT_EQ(mFrames[0].mRefreshes[0].kPresentTime, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001500 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001501 EXPECT_EQ(mFrames[0].kReleaseTime, outReleaseTime);
1502}
1503
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001504// This test verifies that if the certain timestamps can't possibly exist for
1505// the most recent frame, then a sync call is not done.
Brian Anderson6b376712017-04-04 10:51:39 -07001506TEST_F(GetFrameTimestampsTest, NoReleaseNoSync) {
Brian Anderson3da8d272016-07-28 16:20:47 -07001507 enableFrameTimestamps();
Brian Anderson3da8d272016-07-28 16:20:47 -07001508
1509 // Dequeue and queue frame 1.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001510 const uint64_t fId1 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001511 dequeueAndQueue(0);
1512 mFrames[0].signalQueueFences();
1513
1514 // Dequeue and queue frame 2.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001515 const uint64_t fId2 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001516 dequeueAndQueue(1);
1517 mFrames[1].signalQueueFences();
1518
1519 addFrameEvents(false, NO_FRAME_INDEX, 0);
1520 addFrameEvents(false, 0, 1);
1521
1522 // Verify available timestamps are correct for frame 1, before any
1523 // fence has been signaled.
1524 // Note: A sync call is necessary here since the events triggered by
1525 // addFrameEvents didn't get to piggyback on the earlier queues/dequeues.
Brian Anderson3da8d272016-07-28 16:20:47 -07001526 resetTimestamps();
1527 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001528 int result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001529 EXPECT_EQ(oldCount + 1, mFakeConsumer->mGetFrameTimestampsCount);
1530 EXPECT_EQ(NO_ERROR, result);
1531 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1532 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001533 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1534 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1535 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001536 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_INVALID, outGpuCompositionDoneTime);
1537 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001538 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001539 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001540
1541 mFrames[0].signalRefreshFences();
1542 mFrames[0].signalReleaseFences();
1543 mFrames[1].signalRefreshFences();
1544
Brian Anderson1049d1d2016-12-16 17:25:57 -08001545 // Verify querying for all timestmaps of f2 does not do a sync call. Even
Brian Anderson4e606e32017-03-16 15:34:57 -07001546 // though the lastRefresh, dequeueReady, and release times aren't
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001547 // available, a sync call should not occur because it's not possible for f2
1548 // to encounter the final value for those events until another frame is
1549 // queued.
Brian Anderson3da8d272016-07-28 16:20:47 -07001550 resetTimestamps();
1551 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001552 result = getAllFrameTimestamps(fId2);
Brian Anderson3da8d272016-07-28 16:20:47 -07001553 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1554 EXPECT_EQ(NO_ERROR, result);
1555 EXPECT_EQ(mFrames[1].kRequestedPresentTime, outRequestedPresentTime);
1556 EXPECT_EQ(mFrames[1].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001557 EXPECT_EQ(mFrames[1].kLatchTime, outLatchTime);
1558 EXPECT_EQ(mFrames[1].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1559 EXPECT_EQ(mFrames[1].mRefreshes[1].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001560 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_INVALID, outGpuCompositionDoneTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001561 EXPECT_EQ(mFrames[1].mRefreshes[0].kPresentTime, outDisplayPresentTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001562 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDequeueReadyTime);
1563 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001564}
1565
Brian Anderson6b376712017-04-04 10:51:39 -07001566// This test verifies there are no sync calls for present times
1567// when they aren't supported and that an error is returned.
1568
1569TEST_F(GetFrameTimestampsTest, PresentUnsupportedNoSync) {
1570 enableFrameTimestamps();
1571 mSurface->mFakeSurfaceComposer->setSupportsPresent(false);
1572
1573 // Dequeue and queue frame 1.
1574 const uint64_t fId1 = getNextFrameId();
1575 dequeueAndQueue(0);
1576
1577 // Verify a query for the Present times do not trigger a sync call if they
1578 // are not supported.
1579 resetTimestamps();
1580 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
1581 int result = native_window_get_frame_timestamps(mWindow.get(), fId1,
1582 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
1583 &outDisplayPresentTime, nullptr, nullptr);
1584 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1585 EXPECT_EQ(BAD_VALUE, result);
1586 EXPECT_EQ(-1, outDisplayPresentTime);
1587}
1588
Dan Stoza932f0082017-05-31 13:50:16 -07001589} // namespace android