blob: 660680bf9e41d20022393f3ba0c0bbcd48dae924 [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; }
chaviwa76b2712017-09-20 12:02:26 -0700532 virtual status_t captureLayers(const sp<IBinder>& /*parentHandle*/,
533 const sp<IGraphicBufferProducer>& /*producer*/,
534 ISurfaceComposer::Rotation /*rotation*/) override {
535 return NO_ERROR;
536 }
Brian Anderson3da8d272016-07-28 16:20:47 -0700537 status_t clearAnimationFrameStats() override { return NO_ERROR; }
538 status_t getAnimationFrameStats(FrameStats* /*outStats*/) const override {
539 return NO_ERROR;
540 }
541 status_t getHdrCapabilities(const sp<IBinder>& /*display*/,
542 HdrCapabilities* /*outCapabilities*/) const override {
543 return NO_ERROR;
544 }
545 status_t enableVSyncInjections(bool /*enable*/) override {
546 return NO_ERROR;
547 }
548 status_t injectVSync(nsecs_t /*when*/) override { return NO_ERROR; }
Kalle Raitaa099a242017-01-11 11:17:29 -0800549 status_t getLayerDebugInfo(std::vector<LayerDebugInfo>* /*layers*/) const override {
550 return NO_ERROR;
551 }
Brian Anderson3da8d272016-07-28 16:20:47 -0700552
553protected:
554 IBinder* onAsBinder() override { return nullptr; }
555
556private:
557 bool mSupportsPresent{true};
Brian Anderson3da8d272016-07-28 16:20:47 -0700558};
559
560class FakeProducerFrameEventHistory : public ProducerFrameEventHistory {
561public:
562 FakeProducerFrameEventHistory(FenceToFenceTimeMap* fenceMap)
563 : mFenceMap(fenceMap) {}
564
565 ~FakeProducerFrameEventHistory() {}
566
567 void updateAcquireFence(uint64_t frameNumber,
568 std::shared_ptr<FenceTime>&& acquire) override {
569 // Verify the acquire fence being added isn't the one from the consumer.
570 EXPECT_NE(mConsumerAcquireFence, acquire);
571 // Override the fence, so we can verify this was called by the
572 // producer after the frame is queued.
573 ProducerFrameEventHistory::updateAcquireFence(frameNumber,
574 std::shared_ptr<FenceTime>(mAcquireFenceOverride));
575 }
576
577 void setAcquireFenceOverride(
578 const std::shared_ptr<FenceTime>& acquireFenceOverride,
579 const std::shared_ptr<FenceTime>& consumerAcquireFence) {
580 mAcquireFenceOverride = acquireFenceOverride;
581 mConsumerAcquireFence = consumerAcquireFence;
582 }
583
584protected:
585 std::shared_ptr<FenceTime> createFenceTime(const sp<Fence>& fence)
586 const override {
587 return mFenceMap->createFenceTimeForTest(fence);
588 }
589
590 FenceToFenceTimeMap* mFenceMap{nullptr};
591
592 std::shared_ptr<FenceTime> mAcquireFenceOverride{FenceTime::NO_FENCE};
593 std::shared_ptr<FenceTime> mConsumerAcquireFence{FenceTime::NO_FENCE};
594};
595
596
597class TestSurface : public Surface {
598public:
599 TestSurface(const sp<IGraphicBufferProducer>& bufferProducer,
600 FenceToFenceTimeMap* fenceMap)
601 : Surface(bufferProducer),
602 mFakeSurfaceComposer(new FakeSurfaceComposer) {
603 mFakeFrameEventHistory = new FakeProducerFrameEventHistory(fenceMap);
604 mFrameEventHistory.reset(mFakeFrameEventHistory);
605 }
606
607 ~TestSurface() override {}
608
609 sp<ISurfaceComposer> composerService() const override {
610 return mFakeSurfaceComposer;
611 }
612
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800613 nsecs_t now() const override {
614 return mNow;
615 }
616
617 void setNow(nsecs_t now) {
618 mNow = now;
619 }
620
Brian Anderson3da8d272016-07-28 16:20:47 -0700621public:
622 sp<FakeSurfaceComposer> mFakeSurfaceComposer;
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800623 nsecs_t mNow = 0;
Brian Anderson3da8d272016-07-28 16:20:47 -0700624
625 // mFrameEventHistory owns the instance of FakeProducerFrameEventHistory,
626 // but this raw pointer gives access to test functionality.
627 FakeProducerFrameEventHistory* mFakeFrameEventHistory;
628};
629
630
Brian Andersond0010582017-03-07 13:20:31 -0800631class GetFrameTimestampsTest : public ::testing::Test {
Brian Anderson3da8d272016-07-28 16:20:47 -0700632protected:
633 struct FenceAndFenceTime {
634 explicit FenceAndFenceTime(FenceToFenceTimeMap& fenceMap)
635 : mFence(new Fence),
636 mFenceTime(fenceMap.createFenceTimeForTest(mFence)) {}
637 sp<Fence> mFence { nullptr };
638 std::shared_ptr<FenceTime> mFenceTime { nullptr };
639 };
640
641 struct RefreshEvents {
642 RefreshEvents(FenceToFenceTimeMap& fenceMap, nsecs_t refreshStart)
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800643 : mFenceMap(fenceMap),
644 kCompositorTiming(
645 {refreshStart, refreshStart + 1, refreshStart + 2 }),
646 kStartTime(refreshStart + 3),
647 kGpuCompositionDoneTime(refreshStart + 4),
648 kPresentTime(refreshStart + 5) {}
Brian Anderson3da8d272016-07-28 16:20:47 -0700649
650 void signalPostCompositeFences() {
651 mFenceMap.signalAllForTest(
652 mGpuCompositionDone.mFence, kGpuCompositionDoneTime);
653 mFenceMap.signalAllForTest(mPresent.mFence, kPresentTime);
654 }
655
656 FenceToFenceTimeMap& mFenceMap;
657
658 FenceAndFenceTime mGpuCompositionDone { mFenceMap };
659 FenceAndFenceTime mPresent { mFenceMap };
660
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800661 const CompositorTiming kCompositorTiming;
662
Brian Anderson3da8d272016-07-28 16:20:47 -0700663 const nsecs_t kStartTime;
664 const nsecs_t kGpuCompositionDoneTime;
665 const nsecs_t kPresentTime;
666 };
667
668 struct FrameEvents {
669 FrameEvents(FenceToFenceTimeMap& fenceMap, nsecs_t frameStartTime)
670 : mFenceMap(fenceMap),
671 kPostedTime(frameStartTime + 100),
672 kRequestedPresentTime(frameStartTime + 200),
673 kProducerAcquireTime(frameStartTime + 300),
674 kConsumerAcquireTime(frameStartTime + 301),
675 kLatchTime(frameStartTime + 500),
Brian Andersonf6386862016-10-31 16:34:13 -0700676 kDequeueReadyTime(frameStartTime + 600),
Brian Anderson4e606e32017-03-16 15:34:57 -0700677 kReleaseTime(frameStartTime + 700),
Brian Anderson3da8d272016-07-28 16:20:47 -0700678 mRefreshes {
679 { mFenceMap, frameStartTime + 410 },
680 { mFenceMap, frameStartTime + 420 },
681 { mFenceMap, frameStartTime + 430 } } {}
682
683 void signalQueueFences() {
684 mFenceMap.signalAllForTest(
685 mAcquireConsumer.mFence, kConsumerAcquireTime);
686 mFenceMap.signalAllForTest(
687 mAcquireProducer.mFence, kProducerAcquireTime);
688 }
689
690 void signalRefreshFences() {
691 for (auto& re : mRefreshes) {
692 re.signalPostCompositeFences();
693 }
694 }
695
696 void signalReleaseFences() {
Brian Anderson3da8d272016-07-28 16:20:47 -0700697 mFenceMap.signalAllForTest(mRelease.mFence, kReleaseTime);
698 }
699
700 FenceToFenceTimeMap& mFenceMap;
701
702 FenceAndFenceTime mAcquireConsumer { mFenceMap };
703 FenceAndFenceTime mAcquireProducer { mFenceMap };
Brian Anderson3da8d272016-07-28 16:20:47 -0700704 FenceAndFenceTime mRelease { mFenceMap };
705
706 const nsecs_t kPostedTime;
707 const nsecs_t kRequestedPresentTime;
708 const nsecs_t kProducerAcquireTime;
709 const nsecs_t kConsumerAcquireTime;
710 const nsecs_t kLatchTime;
Brian Andersonf6386862016-10-31 16:34:13 -0700711 const nsecs_t kDequeueReadyTime;
Brian Anderson3da8d272016-07-28 16:20:47 -0700712 const nsecs_t kReleaseTime;
713
714 RefreshEvents mRefreshes[3];
715 };
716
Brian Andersond0010582017-03-07 13:20:31 -0800717 GetFrameTimestampsTest() {}
Brian Anderson3da8d272016-07-28 16:20:47 -0700718
719 virtual void SetUp() {
Brian Anderson3da8d272016-07-28 16:20:47 -0700720 BufferQueue::createBufferQueue(&mProducer, &mConsumer);
721 mFakeConsumer = new FakeConsumer;
722 mCfeh = &mFakeConsumer->mFrameEventHistory;
723 mConsumer->consumerConnect(mFakeConsumer, false);
724 mConsumer->setConsumerName(String8("TestConsumer"));
725 mSurface = new TestSurface(mProducer, &mFenceMap);
726 mWindow = mSurface;
727
728 ASSERT_EQ(NO_ERROR, native_window_api_connect(mWindow.get(),
729 NATIVE_WINDOW_API_CPU));
730 native_window_set_buffer_count(mWindow.get(), 4);
731 }
732
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800733 void disableFrameTimestamps() {
734 mFakeConsumer->mGetFrameTimestampsEnabled = false;
735 native_window_enable_frame_timestamps(mWindow.get(), 0);
736 mFrameTimestampsEnabled = false;
737 }
738
Brian Anderson3da8d272016-07-28 16:20:47 -0700739 void enableFrameTimestamps() {
740 mFakeConsumer->mGetFrameTimestampsEnabled = true;
741 native_window_enable_frame_timestamps(mWindow.get(), 1);
742 mFrameTimestampsEnabled = true;
743 }
744
Brian Anderson1049d1d2016-12-16 17:25:57 -0800745 int getAllFrameTimestamps(uint64_t frameId) {
746 return native_window_get_frame_timestamps(mWindow.get(), frameId,
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700747 &outRequestedPresentTime, &outAcquireTime, &outLatchTime,
748 &outFirstRefreshStartTime, &outLastRefreshStartTime,
749 &outGpuCompositionDoneTime, &outDisplayPresentTime,
Brian Anderson4e606e32017-03-16 15:34:57 -0700750 &outDequeueReadyTime, &outReleaseTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700751 }
752
Brian Anderson3da8d272016-07-28 16:20:47 -0700753 void resetTimestamps() {
754 outRequestedPresentTime = -1;
755 outAcquireTime = -1;
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700756 outLatchTime = -1;
757 outFirstRefreshStartTime = -1;
758 outLastRefreshStartTime = -1;
Brian Anderson3da8d272016-07-28 16:20:47 -0700759 outGpuCompositionDoneTime = -1;
760 outDisplayPresentTime = -1;
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700761 outDequeueReadyTime = -1;
Brian Anderson3da8d272016-07-28 16:20:47 -0700762 outReleaseTime = -1;
763 }
764
Brian Anderson1049d1d2016-12-16 17:25:57 -0800765 uint64_t getNextFrameId() {
766 uint64_t frameId = -1;
767 int status = native_window_get_next_frame_id(mWindow.get(), &frameId);
768 EXPECT_EQ(status, NO_ERROR);
769 return frameId;
770 }
771
Brian Anderson3da8d272016-07-28 16:20:47 -0700772 void dequeueAndQueue(uint64_t frameIndex) {
773 int fence = -1;
774 ANativeWindowBuffer* buffer = nullptr;
775 ASSERT_EQ(NO_ERROR,
776 mWindow->dequeueBuffer(mWindow.get(), &buffer, &fence));
777
778 int oldAddFrameTimestampsCount =
779 mFakeConsumer->mAddFrameTimestampsCount;
780
781 FrameEvents* frame = &mFrames[frameIndex];
782 uint64_t frameNumber = frameIndex + 1;
783
784 NewFrameEventsEntry fe;
785 fe.frameNumber = frameNumber;
786 fe.postedTime = frame->kPostedTime;
787 fe.requestedPresentTime = frame->kRequestedPresentTime;
788 fe.acquireFence = frame->mAcquireConsumer.mFenceTime;
789 mFakeConsumer->mNewFrameEntryOverride = fe;
790
791 mSurface->mFakeFrameEventHistory->setAcquireFenceOverride(
792 frame->mAcquireProducer.mFenceTime,
793 frame->mAcquireConsumer.mFenceTime);
794
795 ASSERT_EQ(NO_ERROR, mWindow->queueBuffer(mWindow.get(), buffer, fence));
796
797 EXPECT_EQ(frameNumber, mFakeConsumer->mLastAddedFrameNumber);
798
799 EXPECT_EQ(
800 oldAddFrameTimestampsCount + (mFrameTimestampsEnabled ? 1 : 0),
801 mFakeConsumer->mAddFrameTimestampsCount);
802 }
803
804 void addFrameEvents(
805 bool gpuComposited, uint64_t iOldFrame, int64_t iNewFrame) {
806 FrameEvents* oldFrame =
807 (iOldFrame == NO_FRAME_INDEX) ? nullptr : &mFrames[iOldFrame];
808 FrameEvents* newFrame = &mFrames[iNewFrame];
809
810 uint64_t nOldFrame = iOldFrame + 1;
811 uint64_t nNewFrame = iNewFrame + 1;
812
Brian Anderson4e606e32017-03-16 15:34:57 -0700813 // Latch, Composite, and Release the frames in a plausible order.
814 // Note: The timestamps won't necessarily match the order, but
Brian Anderson3da8d272016-07-28 16:20:47 -0700815 // that's okay for the purposes of this test.
816 std::shared_ptr<FenceTime> gpuDoneFenceTime = FenceTime::NO_FENCE;
817
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700818 // Composite the previous frame one more time, which helps verify
819 // LastRefresh is updated properly.
820 if (oldFrame != nullptr) {
821 mCfeh->addPreComposition(nOldFrame,
822 oldFrame->mRefreshes[2].kStartTime);
823 gpuDoneFenceTime = gpuComposited ?
824 oldFrame->mRefreshes[2].mGpuCompositionDone.mFenceTime :
825 FenceTime::NO_FENCE;
826 mCfeh->addPostComposition(nOldFrame, gpuDoneFenceTime,
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800827 oldFrame->mRefreshes[2].mPresent.mFenceTime,
828 oldFrame->mRefreshes[2].kCompositorTiming);
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700829 }
830
831 // Latch the new frame.
Brian Anderson3da8d272016-07-28 16:20:47 -0700832 mCfeh->addLatch(nNewFrame, newFrame->kLatchTime);
833
834 mCfeh->addPreComposition(nNewFrame, newFrame->mRefreshes[0].kStartTime);
835 gpuDoneFenceTime = gpuComposited ?
836 newFrame->mRefreshes[0].mGpuCompositionDone.mFenceTime :
837 FenceTime::NO_FENCE;
838 // HWC2 releases the previous buffer after a new latch just before
839 // calling postComposition.
840 if (oldFrame != nullptr) {
Brian Andersonf6386862016-10-31 16:34:13 -0700841 mCfeh->addRelease(nOldFrame, oldFrame->kDequeueReadyTime,
Brian Anderson3da8d272016-07-28 16:20:47 -0700842 std::shared_ptr<FenceTime>(oldFrame->mRelease.mFenceTime));
843 }
844 mCfeh->addPostComposition(nNewFrame, gpuDoneFenceTime,
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800845 newFrame->mRefreshes[0].mPresent.mFenceTime,
846 newFrame->mRefreshes[0].kCompositorTiming);
Brian Anderson3da8d272016-07-28 16:20:47 -0700847
Brian Anderson3da8d272016-07-28 16:20:47 -0700848 mCfeh->addPreComposition(nNewFrame, newFrame->mRefreshes[1].kStartTime);
849 gpuDoneFenceTime = gpuComposited ?
850 newFrame->mRefreshes[1].mGpuCompositionDone.mFenceTime :
851 FenceTime::NO_FENCE;
852 mCfeh->addPostComposition(nNewFrame, gpuDoneFenceTime,
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800853 newFrame->mRefreshes[1].mPresent.mFenceTime,
854 newFrame->mRefreshes[1].kCompositorTiming);
Brian Anderson3da8d272016-07-28 16:20:47 -0700855 }
856
Brian Anderson3da8d272016-07-28 16:20:47 -0700857 sp<IGraphicBufferProducer> mProducer;
858 sp<IGraphicBufferConsumer> mConsumer;
859 sp<FakeConsumer> mFakeConsumer;
860 ConsumerFrameEventHistory* mCfeh;
861 sp<TestSurface> mSurface;
862 sp<ANativeWindow> mWindow;
863
864 FenceToFenceTimeMap mFenceMap;
865
866 bool mFrameTimestampsEnabled = false;
867
868 int64_t outRequestedPresentTime = -1;
869 int64_t outAcquireTime = -1;
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700870 int64_t outLatchTime = -1;
871 int64_t outFirstRefreshStartTime = -1;
872 int64_t outLastRefreshStartTime = -1;
Brian Anderson3da8d272016-07-28 16:20:47 -0700873 int64_t outGpuCompositionDoneTime = -1;
874 int64_t outDisplayPresentTime = -1;
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700875 int64_t outDequeueReadyTime = -1;
Brian Anderson3da8d272016-07-28 16:20:47 -0700876 int64_t outReleaseTime = -1;
877
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800878 FrameEvents mFrames[3] {
879 { mFenceMap, 1000 }, { mFenceMap, 2000 }, { mFenceMap, 3000 } };
Brian Anderson3da8d272016-07-28 16:20:47 -0700880};
881
882
883// This test verifies that the frame timestamps are not retrieved when not
884// explicitly enabled via native_window_enable_frame_timestamps.
885// We want to check this to make sure there's no overhead for users
886// that don't need the timestamp information.
887TEST_F(GetFrameTimestampsTest, DefaultDisabled) {
888 int fence;
889 ANativeWindowBuffer* buffer;
890
891 EXPECT_EQ(0, mFakeConsumer->mAddFrameTimestampsCount);
892 EXPECT_EQ(0, mFakeConsumer->mGetFrameTimestampsCount);
893
Brian Anderson1049d1d2016-12-16 17:25:57 -0800894 const uint64_t fId = getNextFrameId();
895
Brian Anderson3da8d272016-07-28 16:20:47 -0700896 // Verify the producer doesn't get frame timestamps piggybacked on dequeue.
897 ASSERT_EQ(NO_ERROR, mWindow->dequeueBuffer(mWindow.get(), &buffer, &fence));
898 EXPECT_EQ(0, mFakeConsumer->mAddFrameTimestampsCount);
899 EXPECT_EQ(0, mFakeConsumer->mGetFrameTimestampsCount);
900
901 // Verify the producer doesn't get frame timestamps piggybacked on queue.
902 // It is okay that frame timestamps are added in the consumer since it is
903 // still needed for SurfaceFlinger dumps.
904 ASSERT_EQ(NO_ERROR, mWindow->queueBuffer(mWindow.get(), buffer, fence));
905 EXPECT_EQ(1, mFakeConsumer->mAddFrameTimestampsCount);
906 EXPECT_EQ(0, mFakeConsumer->mGetFrameTimestampsCount);
907
908 // Verify attempts to get frame timestamps fail.
Brian Anderson1049d1d2016-12-16 17:25:57 -0800909 int result = getAllFrameTimestamps(fId);
Brian Anderson3da8d272016-07-28 16:20:47 -0700910 EXPECT_EQ(INVALID_OPERATION, result);
911 EXPECT_EQ(0, mFakeConsumer->mGetFrameTimestampsCount);
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800912
913 // Verify compositor timing query fails.
914 nsecs_t compositeDeadline = 0;
915 nsecs_t compositeInterval = 0;
916 nsecs_t compositeToPresentLatency = 0;
917 result = native_window_get_compositor_timing(mWindow.get(),
918 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
919 EXPECT_EQ(INVALID_OPERATION, result);
Brian Anderson3da8d272016-07-28 16:20:47 -0700920}
921
922// This test verifies that the frame timestamps are retrieved if explicitly
923// enabled via native_window_enable_frame_timestamps.
924TEST_F(GetFrameTimestampsTest, EnabledSimple) {
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800925 CompositorTiming initialCompositorTiming {
926 1000000000, // 1s deadline
927 16666667, // 16ms interval
928 50000000, // 50ms present latency
929 };
930 mCfeh->initializeCompositorTiming(initialCompositorTiming);
931
Brian Anderson3da8d272016-07-28 16:20:47 -0700932 enableFrameTimestamps();
933
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800934 // Verify the compositor timing query gets the initial compositor values
935 // after timststamps are enabled; even before the first frame is queued
936 // or dequeued.
937 nsecs_t compositeDeadline = 0;
938 nsecs_t compositeInterval = 0;
939 nsecs_t compositeToPresentLatency = 0;
940 mSurface->setNow(initialCompositorTiming.deadline - 1);
941 int result = native_window_get_compositor_timing(mWindow.get(),
942 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
943 EXPECT_EQ(NO_ERROR, result);
944 EXPECT_EQ(initialCompositorTiming.deadline, compositeDeadline);
945 EXPECT_EQ(initialCompositorTiming.interval, compositeInterval);
946 EXPECT_EQ(initialCompositorTiming.presentLatency,
947 compositeToPresentLatency);
948
Brian Anderson3da8d272016-07-28 16:20:47 -0700949 int fence;
950 ANativeWindowBuffer* buffer;
951
952 EXPECT_EQ(0, mFakeConsumer->mAddFrameTimestampsCount);
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800953 EXPECT_EQ(1, mFakeConsumer->mGetFrameTimestampsCount);
Brian Anderson3da8d272016-07-28 16:20:47 -0700954
Brian Anderson1049d1d2016-12-16 17:25:57 -0800955 const uint64_t fId1 = getNextFrameId();
956
Brian Anderson3da8d272016-07-28 16:20:47 -0700957 // Verify getFrameTimestamps is piggybacked on dequeue.
958 ASSERT_EQ(NO_ERROR, mWindow->dequeueBuffer(mWindow.get(), &buffer, &fence));
959 EXPECT_EQ(0, mFakeConsumer->mAddFrameTimestampsCount);
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800960 EXPECT_EQ(2, mFakeConsumer->mGetFrameTimestampsCount);
Brian Anderson3da8d272016-07-28 16:20:47 -0700961
962 NewFrameEventsEntry f1;
963 f1.frameNumber = 1;
964 f1.postedTime = mFrames[0].kPostedTime;
965 f1.requestedPresentTime = mFrames[0].kRequestedPresentTime;
966 f1.acquireFence = mFrames[0].mAcquireConsumer.mFenceTime;
967 mSurface->mFakeFrameEventHistory->setAcquireFenceOverride(
968 mFrames[0].mAcquireProducer.mFenceTime,
969 mFrames[0].mAcquireConsumer.mFenceTime);
970 mFakeConsumer->mNewFrameEntryOverride = f1;
971 mFrames[0].signalQueueFences();
972
973 // Verify getFrameTimestamps is piggybacked on queue.
974 ASSERT_EQ(NO_ERROR, mWindow->queueBuffer(mWindow.get(), buffer, fence));
975 EXPECT_EQ(1, mFakeConsumer->mAddFrameTimestampsCount);
976 EXPECT_EQ(1u, mFakeConsumer->mLastAddedFrameNumber);
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800977 EXPECT_EQ(3, mFakeConsumer->mGetFrameTimestampsCount);
Brian Anderson3da8d272016-07-28 16:20:47 -0700978
979 // Verify queries for timestamps that the producer doesn't know about
980 // triggers a call to see if the consumer has any new timestamps.
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800981 result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -0700982 EXPECT_EQ(NO_ERROR, result);
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800983 EXPECT_EQ(4, mFakeConsumer->mGetFrameTimestampsCount);
Brian Anderson3da8d272016-07-28 16:20:47 -0700984}
985
Brian Anderson6b376712017-04-04 10:51:39 -0700986TEST_F(GetFrameTimestampsTest, QueryPresentSupported) {
987 bool displayPresentSupported = true;
988 mSurface->mFakeSurfaceComposer->setSupportsPresent(displayPresentSupported);
989
990 // Verify supported bits are forwarded.
991 int supportsPresent = -1;
992 mWindow.get()->query(mWindow.get(),
993 NATIVE_WINDOW_FRAME_TIMESTAMPS_SUPPORTS_PRESENT, &supportsPresent);
994 EXPECT_EQ(displayPresentSupported, supportsPresent);
995}
996
997TEST_F(GetFrameTimestampsTest, QueryPresentNotSupported) {
998 bool displayPresentSupported = false;
999 mSurface->mFakeSurfaceComposer->setSupportsPresent(displayPresentSupported);
1000
1001 // Verify supported bits are forwarded.
1002 int supportsPresent = -1;
1003 mWindow.get()->query(mWindow.get(),
1004 NATIVE_WINDOW_FRAME_TIMESTAMPS_SUPPORTS_PRESENT, &supportsPresent);
1005 EXPECT_EQ(displayPresentSupported, supportsPresent);
1006}
1007
Brian Anderson0a61b0c2016-12-07 14:55:56 -08001008TEST_F(GetFrameTimestampsTest, SnapToNextTickBasic) {
1009 nsecs_t phase = 4000;
1010 nsecs_t interval = 1000;
1011
1012 // Timestamp in previous interval.
1013 nsecs_t timestamp = 3500;
1014 EXPECT_EQ(4000, ProducerFrameEventHistory::snapToNextTick(
1015 timestamp, phase, interval));
1016
1017 // Timestamp in next interval.
1018 timestamp = 4500;
1019 EXPECT_EQ(5000, ProducerFrameEventHistory::snapToNextTick(
1020 timestamp, phase, interval));
1021
1022 // Timestamp multiple intervals before.
1023 timestamp = 2500;
1024 EXPECT_EQ(3000, ProducerFrameEventHistory::snapToNextTick(
1025 timestamp, phase, interval));
1026
1027 // Timestamp multiple intervals after.
1028 timestamp = 6500;
1029 EXPECT_EQ(7000, ProducerFrameEventHistory::snapToNextTick(
1030 timestamp, phase, interval));
1031
1032 // Timestamp on previous interval.
1033 timestamp = 3000;
1034 EXPECT_EQ(3000, ProducerFrameEventHistory::snapToNextTick(
1035 timestamp, phase, interval));
1036
1037 // Timestamp on next interval.
1038 timestamp = 5000;
1039 EXPECT_EQ(5000, ProducerFrameEventHistory::snapToNextTick(
1040 timestamp, phase, interval));
1041
1042 // Timestamp equal to phase.
1043 timestamp = 4000;
1044 EXPECT_EQ(4000, ProducerFrameEventHistory::snapToNextTick(
1045 timestamp, phase, interval));
1046}
1047
1048// int(big_timestamp / interval) < 0, which can cause a crash or invalid result
1049// if the number of intervals elapsed is internally stored in an int.
1050TEST_F(GetFrameTimestampsTest, SnapToNextTickOverflow) {
1051 nsecs_t phase = 0;
1052 nsecs_t interval = 4000;
1053 nsecs_t big_timestamp = 8635916564000;
1054 int32_t intervals = big_timestamp / interval;
1055
1056 EXPECT_LT(intervals, 0);
1057 EXPECT_EQ(8635916564000, ProducerFrameEventHistory::snapToNextTick(
1058 big_timestamp, phase, interval));
1059 EXPECT_EQ(8635916564000, ProducerFrameEventHistory::snapToNextTick(
1060 big_timestamp, big_timestamp, interval));
1061}
1062
1063// This verifies the compositor timing is updated by refresh events
1064// and piggy backed on a queue, dequeue, and enabling of timestamps..
1065TEST_F(GetFrameTimestampsTest, CompositorTimingUpdatesBasic) {
1066 CompositorTiming initialCompositorTiming {
1067 1000000000, // 1s deadline
1068 16666667, // 16ms interval
1069 50000000, // 50ms present latency
1070 };
1071 mCfeh->initializeCompositorTiming(initialCompositorTiming);
1072
1073 enableFrameTimestamps();
1074
1075 // We get the initial values before any frames are submitted.
1076 nsecs_t compositeDeadline = 0;
1077 nsecs_t compositeInterval = 0;
1078 nsecs_t compositeToPresentLatency = 0;
1079 mSurface->setNow(initialCompositorTiming.deadline - 1);
1080 int result = native_window_get_compositor_timing(mWindow.get(),
1081 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1082 EXPECT_EQ(NO_ERROR, result);
1083 EXPECT_EQ(initialCompositorTiming.deadline, compositeDeadline);
1084 EXPECT_EQ(initialCompositorTiming.interval, compositeInterval);
1085 EXPECT_EQ(initialCompositorTiming.presentLatency,
1086 compositeToPresentLatency);
1087
Brian Anderson0a61b0c2016-12-07 14:55:56 -08001088 dequeueAndQueue(0);
1089 addFrameEvents(true, NO_FRAME_INDEX, 0);
1090
1091 // Still get the initial values because the frame events for frame 0
1092 // didn't get a chance to piggyback on a queue or dequeue yet.
1093 result = native_window_get_compositor_timing(mWindow.get(),
1094 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1095 EXPECT_EQ(NO_ERROR, result);
1096 EXPECT_EQ(initialCompositorTiming.deadline, compositeDeadline);
1097 EXPECT_EQ(initialCompositorTiming.interval, compositeInterval);
1098 EXPECT_EQ(initialCompositorTiming.presentLatency,
1099 compositeToPresentLatency);
1100
Brian Anderson0a61b0c2016-12-07 14:55:56 -08001101 dequeueAndQueue(1);
1102 addFrameEvents(true, 0, 1);
1103
1104 // Now expect the composite values associated with frame 1.
1105 mSurface->setNow(mFrames[0].mRefreshes[1].kCompositorTiming.deadline);
1106 result = native_window_get_compositor_timing(mWindow.get(),
1107 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1108 EXPECT_EQ(NO_ERROR, result);
1109 EXPECT_EQ(mFrames[0].mRefreshes[1].kCompositorTiming.deadline,
1110 compositeDeadline);
1111 EXPECT_EQ(mFrames[0].mRefreshes[1].kCompositorTiming.interval,
1112 compositeInterval);
1113 EXPECT_EQ(mFrames[0].mRefreshes[1].kCompositorTiming.presentLatency,
1114 compositeToPresentLatency);
1115
1116 dequeueAndQueue(2);
1117 addFrameEvents(true, 1, 2);
1118
1119 // Now expect the composite values associated with frame 2.
1120 mSurface->setNow(mFrames[1].mRefreshes[1].kCompositorTiming.deadline);
1121 result = native_window_get_compositor_timing(mWindow.get(),
1122 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1123 EXPECT_EQ(NO_ERROR, result);
1124 EXPECT_EQ(mFrames[1].mRefreshes[1].kCompositorTiming.deadline,
1125 compositeDeadline);
1126 EXPECT_EQ(mFrames[1].mRefreshes[1].kCompositorTiming.interval,
1127 compositeInterval);
1128 EXPECT_EQ(mFrames[1].mRefreshes[1].kCompositorTiming.presentLatency,
1129 compositeToPresentLatency);
1130
1131 // Re-enabling frame timestamps should get the latest values.
1132 disableFrameTimestamps();
1133 enableFrameTimestamps();
1134
1135 // Now expect the composite values associated with frame 3.
1136 mSurface->setNow(mFrames[2].mRefreshes[1].kCompositorTiming.deadline);
1137 result = native_window_get_compositor_timing(mWindow.get(),
1138 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1139 EXPECT_EQ(NO_ERROR, result);
1140 EXPECT_EQ(mFrames[2].mRefreshes[1].kCompositorTiming.deadline,
1141 compositeDeadline);
1142 EXPECT_EQ(mFrames[2].mRefreshes[1].kCompositorTiming.interval,
1143 compositeInterval);
1144 EXPECT_EQ(mFrames[2].mRefreshes[1].kCompositorTiming.presentLatency,
1145 compositeToPresentLatency);
1146}
1147
1148// This verifies the compositor deadline properly snaps to the the next
1149// deadline based on the current time.
1150TEST_F(GetFrameTimestampsTest, CompositorTimingDeadlineSnaps) {
1151 CompositorTiming initialCompositorTiming {
1152 1000000000, // 1s deadline
1153 16666667, // 16ms interval
1154 50000000, // 50ms present latency
1155 };
1156 mCfeh->initializeCompositorTiming(initialCompositorTiming);
1157
1158 enableFrameTimestamps();
1159
1160 nsecs_t compositeDeadline = 0;
1161 nsecs_t compositeInterval = 0;
1162 nsecs_t compositeToPresentLatency = 0;
1163
1164 // A "now" just before the deadline snaps to the deadline.
1165 mSurface->setNow(initialCompositorTiming.deadline - 1);
1166 int result = native_window_get_compositor_timing(mWindow.get(),
1167 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1168 EXPECT_EQ(NO_ERROR, result);
1169 EXPECT_EQ(initialCompositorTiming.deadline, compositeDeadline);
1170 nsecs_t expectedDeadline = initialCompositorTiming.deadline;
1171 EXPECT_EQ(expectedDeadline, compositeDeadline);
1172
Brian Anderson0a61b0c2016-12-07 14:55:56 -08001173 dequeueAndQueue(0);
1174 addFrameEvents(true, NO_FRAME_INDEX, 0);
1175
1176 // A "now" just after the deadline snaps properly.
1177 mSurface->setNow(initialCompositorTiming.deadline + 1);
1178 result = native_window_get_compositor_timing(mWindow.get(),
1179 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1180 EXPECT_EQ(NO_ERROR, result);
1181 expectedDeadline =
1182 initialCompositorTiming.deadline +initialCompositorTiming.interval;
1183 EXPECT_EQ(expectedDeadline, compositeDeadline);
1184
Brian Anderson0a61b0c2016-12-07 14:55:56 -08001185 dequeueAndQueue(1);
1186 addFrameEvents(true, 0, 1);
1187
1188 // A "now" just after the next interval snaps properly.
1189 mSurface->setNow(
1190 mFrames[0].mRefreshes[1].kCompositorTiming.deadline +
1191 mFrames[0].mRefreshes[1].kCompositorTiming.interval + 1);
1192 result = native_window_get_compositor_timing(mWindow.get(),
1193 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1194 EXPECT_EQ(NO_ERROR, result);
1195 expectedDeadline =
1196 mFrames[0].mRefreshes[1].kCompositorTiming.deadline +
1197 mFrames[0].mRefreshes[1].kCompositorTiming.interval * 2;
1198 EXPECT_EQ(expectedDeadline, compositeDeadline);
1199
1200 dequeueAndQueue(2);
1201 addFrameEvents(true, 1, 2);
1202
1203 // A "now" over 1 interval before the deadline snaps properly.
1204 mSurface->setNow(
1205 mFrames[1].mRefreshes[1].kCompositorTiming.deadline -
1206 mFrames[1].mRefreshes[1].kCompositorTiming.interval - 1);
1207 result = native_window_get_compositor_timing(mWindow.get(),
1208 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1209 EXPECT_EQ(NO_ERROR, result);
1210 expectedDeadline =
1211 mFrames[1].mRefreshes[1].kCompositorTiming.deadline -
1212 mFrames[1].mRefreshes[1].kCompositorTiming.interval;
1213 EXPECT_EQ(expectedDeadline, compositeDeadline);
1214
1215 // Re-enabling frame timestamps should get the latest values.
1216 disableFrameTimestamps();
1217 enableFrameTimestamps();
1218
1219 // A "now" over 2 intervals before the deadline snaps properly.
1220 mSurface->setNow(
1221 mFrames[2].mRefreshes[1].kCompositorTiming.deadline -
1222 mFrames[2].mRefreshes[1].kCompositorTiming.interval * 2 - 1);
1223 result = native_window_get_compositor_timing(mWindow.get(),
1224 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1225 EXPECT_EQ(NO_ERROR, result);
1226 expectedDeadline =
1227 mFrames[2].mRefreshes[1].kCompositorTiming.deadline -
1228 mFrames[2].mRefreshes[1].kCompositorTiming.interval * 2;
1229 EXPECT_EQ(expectedDeadline, compositeDeadline);
1230}
1231
Brian Anderson1049d1d2016-12-16 17:25:57 -08001232// This verifies the timestamps recorded in the consumer's
1233// FrameTimestampsHistory are properly retrieved by the producer for the
1234// correct frames.
Brian Anderson3da8d272016-07-28 16:20:47 -07001235TEST_F(GetFrameTimestampsTest, TimestampsAssociatedWithCorrectFrame) {
1236 enableFrameTimestamps();
1237
Brian Anderson1049d1d2016-12-16 17:25:57 -08001238 const uint64_t fId1 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001239 dequeueAndQueue(0);
1240 mFrames[0].signalQueueFences();
1241
Brian Anderson1049d1d2016-12-16 17:25:57 -08001242 const uint64_t fId2 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001243 dequeueAndQueue(1);
1244 mFrames[1].signalQueueFences();
1245
1246 addFrameEvents(true, NO_FRAME_INDEX, 0);
1247 mFrames[0].signalRefreshFences();
1248 addFrameEvents(true, 0, 1);
1249 mFrames[0].signalReleaseFences();
1250 mFrames[1].signalRefreshFences();
1251
1252 // Verify timestamps are correct for frame 1.
Brian Anderson3da8d272016-07-28 16:20:47 -07001253 resetTimestamps();
Brian Anderson1049d1d2016-12-16 17:25:57 -08001254 int result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001255 EXPECT_EQ(NO_ERROR, result);
1256 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1257 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001258 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1259 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1260 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001261 EXPECT_EQ(mFrames[0].mRefreshes[0].kGpuCompositionDoneTime,
1262 outGpuCompositionDoneTime);
1263 EXPECT_EQ(mFrames[0].mRefreshes[0].kPresentTime, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001264 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001265 EXPECT_EQ(mFrames[0].kReleaseTime, outReleaseTime);
1266
1267 // Verify timestamps are correct for frame 2.
Brian Anderson3da8d272016-07-28 16:20:47 -07001268 resetTimestamps();
Brian Anderson1049d1d2016-12-16 17:25:57 -08001269 result = getAllFrameTimestamps(fId2);
Brian Anderson3da8d272016-07-28 16:20:47 -07001270 EXPECT_EQ(NO_ERROR, result);
1271 EXPECT_EQ(mFrames[1].kRequestedPresentTime, outRequestedPresentTime);
1272 EXPECT_EQ(mFrames[1].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001273 EXPECT_EQ(mFrames[1].kLatchTime, outLatchTime);
1274 EXPECT_EQ(mFrames[1].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1275 EXPECT_EQ(mFrames[1].mRefreshes[1].kStartTime, outLastRefreshStartTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001276 EXPECT_EQ(mFrames[1].mRefreshes[0].kGpuCompositionDoneTime,
1277 outGpuCompositionDoneTime);
1278 EXPECT_EQ(mFrames[1].mRefreshes[0].kPresentTime, outDisplayPresentTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001279 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDequeueReadyTime);
1280 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001281}
1282
1283// This test verifies the acquire fence recorded by the consumer is not sent
1284// back to the producer and the producer saves its own fence.
1285TEST_F(GetFrameTimestampsTest, QueueTimestampsNoSync) {
1286 enableFrameTimestamps();
Brian Anderson3da8d272016-07-28 16:20:47 -07001287
Brian Anderson3da8d272016-07-28 16:20:47 -07001288 // Dequeue and queue frame 1.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001289 const uint64_t fId1 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001290 dequeueAndQueue(0);
1291
1292 // Verify queue-related timestamps for f1 are available immediately in the
1293 // producer without asking the consumer again, even before signaling the
1294 // acquire fence.
1295 resetTimestamps();
1296 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001297 int result = native_window_get_frame_timestamps(mWindow.get(), fId1,
Brian Anderson3da8d272016-07-28 16:20:47 -07001298 &outRequestedPresentTime, &outAcquireTime, nullptr, nullptr,
Brian Anderson4e606e32017-03-16 15:34:57 -07001299 nullptr, nullptr, nullptr, nullptr, nullptr);
Brian Anderson3da8d272016-07-28 16:20:47 -07001300 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1301 EXPECT_EQ(NO_ERROR, result);
1302 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001303 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outAcquireTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001304
1305 // Signal acquire fences. Verify a sync call still isn't necessary.
1306 mFrames[0].signalQueueFences();
1307
1308 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001309 result = native_window_get_frame_timestamps(mWindow.get(), fId1,
Brian Anderson3da8d272016-07-28 16:20:47 -07001310 &outRequestedPresentTime, &outAcquireTime, nullptr, nullptr,
Brian Anderson4e606e32017-03-16 15:34:57 -07001311 nullptr, nullptr, nullptr, nullptr, nullptr);
Brian Anderson3da8d272016-07-28 16:20:47 -07001312 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1313 EXPECT_EQ(NO_ERROR, result);
1314 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1315 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
1316
1317 // Dequeue and queue frame 2.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001318 const uint64_t fId2 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001319 dequeueAndQueue(1);
1320
1321 // Verify queue-related timestamps for f2 are available immediately in the
1322 // producer without asking the consumer again, even before signaling the
1323 // acquire fence.
1324 resetTimestamps();
1325 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001326 result = native_window_get_frame_timestamps(mWindow.get(), fId2,
Brian Anderson3da8d272016-07-28 16:20:47 -07001327 &outRequestedPresentTime, &outAcquireTime, nullptr, nullptr,
Brian Anderson4e606e32017-03-16 15:34:57 -07001328 nullptr, nullptr, nullptr, nullptr, nullptr);
Brian Anderson3da8d272016-07-28 16:20:47 -07001329 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1330 EXPECT_EQ(NO_ERROR, result);
1331 EXPECT_EQ(mFrames[1].kRequestedPresentTime, outRequestedPresentTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001332 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outAcquireTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001333
1334 // Signal acquire fences. Verify a sync call still isn't necessary.
1335 mFrames[1].signalQueueFences();
1336
1337 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001338 result = native_window_get_frame_timestamps(mWindow.get(), fId2,
Brian Anderson3da8d272016-07-28 16:20:47 -07001339 &outRequestedPresentTime, &outAcquireTime, nullptr, nullptr,
Brian Anderson4e606e32017-03-16 15:34:57 -07001340 nullptr, nullptr, nullptr, nullptr, nullptr);
Brian Anderson3da8d272016-07-28 16:20:47 -07001341 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1342 EXPECT_EQ(NO_ERROR, result);
1343 EXPECT_EQ(mFrames[1].kRequestedPresentTime, outRequestedPresentTime);
1344 EXPECT_EQ(mFrames[1].kProducerAcquireTime, outAcquireTime);
1345}
1346
1347TEST_F(GetFrameTimestampsTest, ZeroRequestedTimestampsNoSync) {
1348 enableFrameTimestamps();
Brian Anderson3da8d272016-07-28 16:20:47 -07001349
1350 // Dequeue and queue frame 1.
1351 dequeueAndQueue(0);
1352 mFrames[0].signalQueueFences();
1353
1354 // Dequeue and queue frame 2.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001355 const uint64_t fId2 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001356 dequeueAndQueue(1);
1357 mFrames[1].signalQueueFences();
1358
1359 addFrameEvents(true, NO_FRAME_INDEX, 0);
1360 mFrames[0].signalRefreshFences();
1361 addFrameEvents(true, 0, 1);
1362 mFrames[0].signalReleaseFences();
1363 mFrames[1].signalRefreshFences();
1364
1365 // Verify a request for no timestamps doesn't result in a sync call.
Brian Anderson3da8d272016-07-28 16:20:47 -07001366 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001367 int result = native_window_get_frame_timestamps(mWindow.get(), fId2,
Brian Anderson6b376712017-04-04 10:51:39 -07001368 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
1369 nullptr, nullptr);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001370 EXPECT_EQ(NO_ERROR, result);
Brian Anderson3da8d272016-07-28 16:20:47 -07001371 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1372}
1373
1374// This test verifies that fences can signal and update timestamps producer
1375// side without an additional sync call to the consumer.
1376TEST_F(GetFrameTimestampsTest, FencesInProducerNoSync) {
1377 enableFrameTimestamps();
Brian Anderson3da8d272016-07-28 16:20:47 -07001378
1379 // Dequeue and queue frame 1.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001380 const uint64_t fId1 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001381 dequeueAndQueue(0);
1382 mFrames[0].signalQueueFences();
1383
1384 // Dequeue and queue frame 2.
1385 dequeueAndQueue(1);
1386 mFrames[1].signalQueueFences();
1387
1388 addFrameEvents(true, NO_FRAME_INDEX, 0);
1389 addFrameEvents(true, 0, 1);
1390
1391 // Verify available timestamps are correct for frame 1, before any
1392 // fence has been signaled.
1393 // Note: A sync call is necessary here since the events triggered by
1394 // addFrameEvents didn't get to piggyback on the earlier queues/dequeues.
Brian Anderson3da8d272016-07-28 16:20:47 -07001395 resetTimestamps();
1396 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001397 int result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001398 EXPECT_EQ(oldCount + 1, mFakeConsumer->mGetFrameTimestampsCount);
1399 EXPECT_EQ(NO_ERROR, result);
1400 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1401 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001402 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1403 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1404 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001405 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outGpuCompositionDoneTime);
1406 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001407 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001408 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001409
1410 // Verify available timestamps are correct for frame 1 again, before any
1411 // fence has been signaled.
1412 // This time a sync call should not be necessary.
Brian Anderson3da8d272016-07-28 16:20:47 -07001413 resetTimestamps();
1414 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001415 result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001416 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1417 EXPECT_EQ(NO_ERROR, result);
1418 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1419 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001420 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1421 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1422 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001423 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outGpuCompositionDoneTime);
1424 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001425 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001426 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001427
1428 // Signal the fences for frame 1.
1429 mFrames[0].signalRefreshFences();
1430 mFrames[0].signalReleaseFences();
1431
1432 // Verify all timestamps are available without a sync call.
Brian Anderson3da8d272016-07-28 16:20:47 -07001433 resetTimestamps();
1434 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001435 result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001436 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1437 EXPECT_EQ(NO_ERROR, result);
1438 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1439 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001440 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1441 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1442 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001443 EXPECT_EQ(mFrames[0].mRefreshes[0].kGpuCompositionDoneTime,
1444 outGpuCompositionDoneTime);
1445 EXPECT_EQ(mFrames[0].mRefreshes[0].kPresentTime, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001446 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001447 EXPECT_EQ(mFrames[0].kReleaseTime, outReleaseTime);
1448}
1449
1450// This test verifies that if the frame wasn't GPU composited but has a refresh
1451// event a sync call isn't made to get the GPU composite done time since it will
1452// never exist.
1453TEST_F(GetFrameTimestampsTest, NoGpuNoSync) {
1454 enableFrameTimestamps();
Brian Anderson3da8d272016-07-28 16:20:47 -07001455
Brian Anderson3da8d272016-07-28 16:20:47 -07001456 // Dequeue and queue frame 1.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001457 const uint64_t fId1 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001458 dequeueAndQueue(0);
1459 mFrames[0].signalQueueFences();
1460
1461 // Dequeue and queue frame 2.
1462 dequeueAndQueue(1);
1463 mFrames[1].signalQueueFences();
1464
1465 addFrameEvents(false, NO_FRAME_INDEX, 0);
1466 addFrameEvents(false, 0, 1);
1467
1468 // Verify available timestamps are correct for frame 1, before any
1469 // fence has been signaled.
1470 // Note: A sync call is necessary here since the events triggered by
1471 // addFrameEvents didn't get to piggyback on the earlier queues/dequeues.
1472 resetTimestamps();
1473 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001474 int result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001475 EXPECT_EQ(oldCount + 1, mFakeConsumer->mGetFrameTimestampsCount);
1476 EXPECT_EQ(NO_ERROR, result);
1477 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1478 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001479 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1480 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1481 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001482 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_INVALID, outGpuCompositionDoneTime);
1483 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001484 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001485 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001486
1487 // Signal the fences for frame 1.
1488 mFrames[0].signalRefreshFences();
1489 mFrames[0].signalReleaseFences();
1490
1491 // Verify all timestamps, except GPU composition, are available without a
1492 // sync call.
1493 resetTimestamps();
1494 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001495 result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001496 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1497 EXPECT_EQ(NO_ERROR, result);
1498 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1499 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001500 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1501 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1502 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001503 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_INVALID, outGpuCompositionDoneTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001504 EXPECT_EQ(mFrames[0].mRefreshes[0].kPresentTime, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001505 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001506 EXPECT_EQ(mFrames[0].kReleaseTime, outReleaseTime);
1507}
1508
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001509// This test verifies that if the certain timestamps can't possibly exist for
1510// the most recent frame, then a sync call is not done.
Brian Anderson6b376712017-04-04 10:51:39 -07001511TEST_F(GetFrameTimestampsTest, NoReleaseNoSync) {
Brian Anderson3da8d272016-07-28 16:20:47 -07001512 enableFrameTimestamps();
Brian Anderson3da8d272016-07-28 16:20:47 -07001513
1514 // Dequeue and queue frame 1.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001515 const uint64_t fId1 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001516 dequeueAndQueue(0);
1517 mFrames[0].signalQueueFences();
1518
1519 // Dequeue and queue frame 2.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001520 const uint64_t fId2 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001521 dequeueAndQueue(1);
1522 mFrames[1].signalQueueFences();
1523
1524 addFrameEvents(false, NO_FRAME_INDEX, 0);
1525 addFrameEvents(false, 0, 1);
1526
1527 // Verify available timestamps are correct for frame 1, before any
1528 // fence has been signaled.
1529 // Note: A sync call is necessary here since the events triggered by
1530 // addFrameEvents didn't get to piggyback on the earlier queues/dequeues.
Brian Anderson3da8d272016-07-28 16:20:47 -07001531 resetTimestamps();
1532 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001533 int result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001534 EXPECT_EQ(oldCount + 1, mFakeConsumer->mGetFrameTimestampsCount);
1535 EXPECT_EQ(NO_ERROR, result);
1536 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1537 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001538 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1539 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1540 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001541 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_INVALID, outGpuCompositionDoneTime);
1542 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001543 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001544 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001545
1546 mFrames[0].signalRefreshFences();
1547 mFrames[0].signalReleaseFences();
1548 mFrames[1].signalRefreshFences();
1549
Brian Anderson1049d1d2016-12-16 17:25:57 -08001550 // Verify querying for all timestmaps of f2 does not do a sync call. Even
Brian Anderson4e606e32017-03-16 15:34:57 -07001551 // though the lastRefresh, dequeueReady, and release times aren't
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001552 // available, a sync call should not occur because it's not possible for f2
1553 // to encounter the final value for those events until another frame is
1554 // queued.
Brian Anderson3da8d272016-07-28 16:20:47 -07001555 resetTimestamps();
1556 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001557 result = getAllFrameTimestamps(fId2);
Brian Anderson3da8d272016-07-28 16:20:47 -07001558 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1559 EXPECT_EQ(NO_ERROR, result);
1560 EXPECT_EQ(mFrames[1].kRequestedPresentTime, outRequestedPresentTime);
1561 EXPECT_EQ(mFrames[1].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001562 EXPECT_EQ(mFrames[1].kLatchTime, outLatchTime);
1563 EXPECT_EQ(mFrames[1].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1564 EXPECT_EQ(mFrames[1].mRefreshes[1].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001565 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_INVALID, outGpuCompositionDoneTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001566 EXPECT_EQ(mFrames[1].mRefreshes[0].kPresentTime, outDisplayPresentTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001567 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDequeueReadyTime);
1568 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001569}
1570
Brian Anderson6b376712017-04-04 10:51:39 -07001571// This test verifies there are no sync calls for present times
1572// when they aren't supported and that an error is returned.
1573
1574TEST_F(GetFrameTimestampsTest, PresentUnsupportedNoSync) {
1575 enableFrameTimestamps();
1576 mSurface->mFakeSurfaceComposer->setSupportsPresent(false);
1577
1578 // Dequeue and queue frame 1.
1579 const uint64_t fId1 = getNextFrameId();
1580 dequeueAndQueue(0);
1581
1582 // Verify a query for the Present times do not trigger a sync call if they
1583 // are not supported.
1584 resetTimestamps();
1585 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
1586 int result = native_window_get_frame_timestamps(mWindow.get(), fId1,
1587 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
1588 &outDisplayPresentTime, nullptr, nullptr);
1589 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1590 EXPECT_EQ(BAD_VALUE, result);
1591 EXPECT_EQ(-1, outDisplayPresentTime);
1592}
1593
Dan Stoza932f0082017-05-31 13:50:16 -07001594} // namespace android