blob: 81820def1cdd45b6fc4318886961793f355cbd58 [file] [log] [blame]
Jamie Gennis134f0422011-03-08 12:18:54 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Dan Stozac6f30bd2015-06-08 09:32:50 -070017#include "DummyConsumer.h"
18
Jamie Gennis134f0422011-03-08 12:18:54 -080019#include <gtest/gtest.h>
Jamie Gennis7a4d0df2011-03-09 17:05:02 -080020
Courtney Goeltzenleuchter6a570b62017-03-13 14:30:00 -060021#include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h>
Brian Anderson3da8d272016-07-28 16:20:47 -070022#include <binder/ProcessState.h>
Courtney Goeltzenleuchter6a570b62017-03-13 14:30:00 -060023#include <configstore/Utils.h>
Courtney Goeltzenleuchter1eb1b272017-02-02 16:51:06 -070024#include <cutils/properties.h>
25#include <gui/BufferItemConsumer.h>
Brian Anderson3da8d272016-07-28 16:20:47 -070026#include <gui/IDisplayEventConnection.h>
Yin-Chia Yeh1f2af5c2017-05-11 16:54:04 -070027#include <gui/IProducerListener.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080028#include <gui/ISurfaceComposer.h>
29#include <gui/Surface.h>
30#include <gui/SurfaceComposerClient.h>
Brian Anderson3da8d272016-07-28 16:20:47 -070031#include <private/gui/ComposerService.h>
Dan Stozac1879002014-05-22 15:59:05 -070032#include <ui/Rect.h>
Jamie Gennis134f0422011-03-08 12:18:54 -080033#include <utils/String8.h>
34
Brian Anderson3da8d272016-07-28 16:20:47 -070035#include <limits>
Kalle Raita643f0942016-12-07 09:20:14 -080036#include <thread>
37
Jamie Gennis134f0422011-03-08 12:18:54 -080038namespace android {
39
Kalle Raita643f0942016-12-07 09:20:14 -080040using namespace std::chrono_literals;
Courtney Goeltzenleuchter6a570b62017-03-13 14:30:00 -060041// retrieve wide-color and hdr settings from configstore
42using namespace android::hardware::configstore;
43using namespace android::hardware::configstore::V1_0;
44
45static bool hasWideColorDisplay =
46 getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasWideColorDisplay>(false);
Kalle Raita643f0942016-12-07 09:20:14 -080047
Brian Anderson3da8d272016-07-28 16:20:47 -070048class FakeSurfaceComposer;
49class FakeProducerFrameEventHistory;
50
51static constexpr uint64_t NO_FRAME_INDEX = std::numeric_limits<uint64_t>::max();
52
Jamie Gennis134f0422011-03-08 12:18:54 -080053class SurfaceTest : public ::testing::Test {
54protected:
Mathias Agopian7c1a4872013-03-20 15:56:04 -070055
56 SurfaceTest() {
57 ProcessState::self()->startThreadPool();
58 }
59
Jamie Gennis134f0422011-03-08 12:18:54 -080060 virtual void SetUp() {
Jamie Gennis7a4d0df2011-03-09 17:05:02 -080061 mComposerClient = new SurfaceComposerClient;
Jamie Gennis134f0422011-03-08 12:18:54 -080062 ASSERT_EQ(NO_ERROR, mComposerClient->initCheck());
63
Brian Andersond0010582017-03-07 13:20:31 -080064 // TODO(brianderson): The following sometimes fails and is a source of
65 // test flakiness.
Jamie Gennisfc850122011-04-25 16:40:05 -070066 mSurfaceControl = mComposerClient->createSurface(
Jeff Brown9d4e3d22012-08-24 20:00:51 -070067 String8("Test Surface"), 32, 32, PIXEL_FORMAT_RGBA_8888, 0);
Jamie Gennis134f0422011-03-08 12:18:54 -080068
69 ASSERT_TRUE(mSurfaceControl != NULL);
70 ASSERT_TRUE(mSurfaceControl->isValid());
71
Mathias Agopian698c0872011-06-28 19:09:31 -070072 SurfaceComposerClient::openGlobalTransaction();
Mathias Agopian9303eee2011-07-01 15:27:27 -070073 ASSERT_EQ(NO_ERROR, mSurfaceControl->setLayer(0x7fffffff));
Jamie Gennis134f0422011-03-08 12:18:54 -080074 ASSERT_EQ(NO_ERROR, mSurfaceControl->show());
Mathias Agopian698c0872011-06-28 19:09:31 -070075 SurfaceComposerClient::closeGlobalTransaction();
Jamie Gennis134f0422011-03-08 12:18:54 -080076
77 mSurface = mSurfaceControl->getSurface();
78 ASSERT_TRUE(mSurface != NULL);
79 }
80
81 virtual void TearDown() {
82 mComposerClient->dispose();
83 }
84
85 sp<Surface> mSurface;
86 sp<SurfaceComposerClient> mComposerClient;
87 sp<SurfaceControl> mSurfaceControl;
88};
89
90TEST_F(SurfaceTest, QueuesToWindowComposerIsTrueWhenVisible) {
91 sp<ANativeWindow> anw(mSurface);
92 int result = -123;
93 int err = anw->query(anw.get(), NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER,
94 &result);
95 EXPECT_EQ(NO_ERROR, err);
96 EXPECT_EQ(1, result);
97}
98
99TEST_F(SurfaceTest, QueuesToWindowComposerIsTrueWhenPurgatorized) {
100 mSurfaceControl.clear();
Kalle Raita643f0942016-12-07 09:20:14 -0800101 // Wait for the async clean-up to complete.
102 std::this_thread::sleep_for(50ms);
Jamie Gennis134f0422011-03-08 12:18:54 -0800103
104 sp<ANativeWindow> anw(mSurface);
105 int result = -123;
106 int err = anw->query(anw.get(), NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER,
107 &result);
108 EXPECT_EQ(NO_ERROR, err);
109 EXPECT_EQ(1, result);
110}
111
Jamie Gennis7a4d0df2011-03-09 17:05:02 -0800112// This test probably doesn't belong here.
Jamie Gennisc901ca02011-10-11 16:02:31 -0700113TEST_F(SurfaceTest, ScreenshotsOfProtectedBuffersSucceed) {
Jamie Gennis7a4d0df2011-03-09 17:05:02 -0800114 sp<ANativeWindow> anw(mSurface);
115
116 // Verify the screenshot works with no protected buffers.
Dan Stoza5603a2f2014-04-07 13:41:37 -0700117 sp<IGraphicBufferProducer> producer;
118 sp<IGraphicBufferConsumer> consumer;
119 BufferQueue::createBufferQueue(&producer, &consumer);
120 sp<CpuConsumer> cpuConsumer = new CpuConsumer(consumer, 1);
Jamie Gennis7a4d0df2011-03-09 17:05:02 -0800121 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
Brian Anderson3da8d272016-07-28 16:20:47 -0700122 sp<IBinder> display(sf->getBuiltInDisplay(
123 ISurfaceComposer::eDisplayIdMain));
Dan Stozac1879002014-05-22 15:59:05 -0700124 ASSERT_EQ(NO_ERROR, sf->captureScreen(display, producer, Rect(),
Dan Stoza8d759962014-02-19 18:35:30 -0800125 64, 64, 0, 0x7fffffff, false));
Jamie Gennis7a4d0df2011-03-09 17:05:02 -0800126
Pablo Ceballos583b1b32015-09-03 18:23:52 -0700127 ASSERT_EQ(NO_ERROR, native_window_api_connect(anw.get(),
128 NATIVE_WINDOW_API_CPU));
Jamie Gennis7a4d0df2011-03-09 17:05:02 -0800129 // Set the PROTECTED usage bit and verify that the screenshot fails. Note
130 // that we need to dequeue a buffer in order for it to actually get
131 // allocated in SurfaceFlinger.
132 ASSERT_EQ(NO_ERROR, native_window_set_usage(anw.get(),
133 GRALLOC_USAGE_PROTECTED));
134 ASSERT_EQ(NO_ERROR, native_window_set_buffer_count(anw.get(), 3));
Iliyan Malchev697526b2011-05-01 11:33:26 -0700135 ANativeWindowBuffer* buf = 0;
Mathias Agopian9303eee2011-07-01 15:27:27 -0700136
Jamie Gennisd8e812c2012-06-13 16:32:25 -0700137 status_t err = native_window_dequeue_buffer_and_wait(anw.get(), &buf);
Mathias Agopian9303eee2011-07-01 15:27:27 -0700138 if (err) {
139 // we could fail if GRALLOC_USAGE_PROTECTED is not supported.
140 // that's okay as long as this is the reason for the failure.
141 // try again without the GRALLOC_USAGE_PROTECTED bit.
142 ASSERT_EQ(NO_ERROR, native_window_set_usage(anw.get(), 0));
Jamie Gennisd8e812c2012-06-13 16:32:25 -0700143 ASSERT_EQ(NO_ERROR, native_window_dequeue_buffer_and_wait(anw.get(),
144 &buf));
Mathias Agopian9303eee2011-07-01 15:27:27 -0700145 return;
146 }
Jamie Gennisd8e812c2012-06-13 16:32:25 -0700147 ASSERT_EQ(NO_ERROR, anw->cancelBuffer(anw.get(), buf, -1));
Mathias Agopian9303eee2011-07-01 15:27:27 -0700148
Jamie Gennis7a4d0df2011-03-09 17:05:02 -0800149 for (int i = 0; i < 4; i++) {
150 // Loop to make sure SurfaceFlinger has retired a protected buffer.
Jamie Gennisd8e812c2012-06-13 16:32:25 -0700151 ASSERT_EQ(NO_ERROR, native_window_dequeue_buffer_and_wait(anw.get(),
152 &buf));
153 ASSERT_EQ(NO_ERROR, anw->queueBuffer(anw.get(), buf, -1));
Jamie Gennis7a4d0df2011-03-09 17:05:02 -0800154 }
Dan Stozac1879002014-05-22 15:59:05 -0700155 ASSERT_EQ(NO_ERROR, sf->captureScreen(display, producer, Rect(),
Dan Stoza8d759962014-02-19 18:35:30 -0800156 64, 64, 0, 0x7fffffff, false));
Jamie Gennis7a4d0df2011-03-09 17:05:02 -0800157}
158
Jamie Gennis391bbe22011-03-14 15:00:06 -0700159TEST_F(SurfaceTest, ConcreteTypeIsSurface) {
160 sp<ANativeWindow> anw(mSurface);
161 int result = -123;
162 int err = anw->query(anw.get(), NATIVE_WINDOW_CONCRETE_TYPE, &result);
163 EXPECT_EQ(NO_ERROR, err);
164 EXPECT_EQ(NATIVE_WINDOW_SURFACE, result);
165}
166
Craig Donner6ebc46a2016-10-21 15:23:44 -0700167TEST_F(SurfaceTest, LayerCountIsOne) {
168 sp<ANativeWindow> anw(mSurface);
169 int result = -123;
170 int err = anw->query(anw.get(), NATIVE_WINDOW_LAYER_COUNT, &result);
171 EXPECT_EQ(NO_ERROR, err);
172 EXPECT_EQ(1, result);
173}
174
Eino-Ville Talvalaf7c60872013-07-30 14:05:02 -0700175TEST_F(SurfaceTest, QueryConsumerUsage) {
176 const int TEST_USAGE_FLAGS =
177 GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_HW_RENDER;
Dan Stoza5603a2f2014-04-07 13:41:37 -0700178 sp<IGraphicBufferProducer> producer;
179 sp<IGraphicBufferConsumer> consumer;
180 BufferQueue::createBufferQueue(&producer, &consumer);
181 sp<BufferItemConsumer> c = new BufferItemConsumer(consumer,
Eino-Ville Talvalaf7c60872013-07-30 14:05:02 -0700182 TEST_USAGE_FLAGS);
Dan Stoza5603a2f2014-04-07 13:41:37 -0700183 sp<Surface> s = new Surface(producer);
Eino-Ville Talvalaf7c60872013-07-30 14:05:02 -0700184
185 sp<ANativeWindow> anw(s);
186
187 int flags = -1;
188 int err = anw->query(anw.get(), NATIVE_WINDOW_CONSUMER_USAGE_BITS, &flags);
189
190 ASSERT_EQ(NO_ERROR, err);
191 ASSERT_EQ(TEST_USAGE_FLAGS, flags);
192}
193
Eino-Ville Talvala5b75a512015-02-19 16:10:43 -0800194TEST_F(SurfaceTest, QueryDefaultBuffersDataSpace) {
195 const android_dataspace TEST_DATASPACE = HAL_DATASPACE_SRGB;
196 sp<IGraphicBufferProducer> producer;
197 sp<IGraphicBufferConsumer> consumer;
198 BufferQueue::createBufferQueue(&producer, &consumer);
199 sp<CpuConsumer> cpuConsumer = new CpuConsumer(consumer, 1);
200
201 cpuConsumer->setDefaultBufferDataSpace(TEST_DATASPACE);
202
203 sp<Surface> s = new Surface(producer);
204
205 sp<ANativeWindow> anw(s);
206
207 android_dataspace dataSpace;
208
209 int err = anw->query(anw.get(), NATIVE_WINDOW_DEFAULT_DATASPACE,
210 reinterpret_cast<int*>(&dataSpace));
211
212 ASSERT_EQ(NO_ERROR, err);
213 ASSERT_EQ(TEST_DATASPACE, dataSpace);
214}
215
Dan Stoza812ed062015-06-02 15:45:22 -0700216TEST_F(SurfaceTest, SettingGenerationNumber) {
217 sp<IGraphicBufferProducer> producer;
218 sp<IGraphicBufferConsumer> consumer;
219 BufferQueue::createBufferQueue(&producer, &consumer);
220 sp<CpuConsumer> cpuConsumer = new CpuConsumer(consumer, 1);
221 sp<Surface> surface = new Surface(producer);
222 sp<ANativeWindow> window(surface);
223
224 // Allocate a buffer with a generation number of 0
225 ANativeWindowBuffer* buffer;
226 int fenceFd;
Pablo Ceballos583b1b32015-09-03 18:23:52 -0700227 ASSERT_EQ(NO_ERROR, native_window_api_connect(window.get(),
228 NATIVE_WINDOW_API_CPU));
Dan Stoza812ed062015-06-02 15:45:22 -0700229 ASSERT_EQ(NO_ERROR, window->dequeueBuffer(window.get(), &buffer, &fenceFd));
230 ASSERT_EQ(NO_ERROR, window->cancelBuffer(window.get(), buffer, fenceFd));
231
232 // Detach the buffer and check its generation number
233 sp<GraphicBuffer> graphicBuffer;
234 sp<Fence> fence;
235 ASSERT_EQ(NO_ERROR, surface->detachNextBuffer(&graphicBuffer, &fence));
236 ASSERT_EQ(0U, graphicBuffer->getGenerationNumber());
237
238 ASSERT_EQ(NO_ERROR, surface->setGenerationNumber(1));
239 buffer = static_cast<ANativeWindowBuffer*>(graphicBuffer.get());
240
241 // This should change the generation number of the GraphicBuffer
242 ASSERT_EQ(NO_ERROR, surface->attachBuffer(buffer));
243
244 // Check that the new generation number sticks with the buffer
245 ASSERT_EQ(NO_ERROR, window->cancelBuffer(window.get(), buffer, -1));
246 ASSERT_EQ(NO_ERROR, window->dequeueBuffer(window.get(), &buffer, &fenceFd));
247 graphicBuffer = static_cast<GraphicBuffer*>(buffer);
248 ASSERT_EQ(1U, graphicBuffer->getGenerationNumber());
249}
250
Dan Stozac6f30bd2015-06-08 09:32:50 -0700251TEST_F(SurfaceTest, GetConsumerName) {
252 sp<IGraphicBufferProducer> producer;
253 sp<IGraphicBufferConsumer> consumer;
254 BufferQueue::createBufferQueue(&producer, &consumer);
255
256 sp<DummyConsumer> dummyConsumer(new DummyConsumer);
257 consumer->consumerConnect(dummyConsumer, false);
258 consumer->setConsumerName(String8("TestConsumer"));
259
260 sp<Surface> surface = new Surface(producer);
261 sp<ANativeWindow> window(surface);
262 native_window_api_connect(window.get(), NATIVE_WINDOW_API_CPU);
263
264 EXPECT_STREQ("TestConsumer", surface->getConsumerName().string());
265}
266
Courtney Goeltzenleuchter1eb1b272017-02-02 16:51:06 -0700267TEST_F(SurfaceTest, GetWideColorSupport) {
268 sp<IGraphicBufferProducer> producer;
269 sp<IGraphicBufferConsumer> consumer;
270 BufferQueue::createBufferQueue(&producer, &consumer);
271
272 sp<DummyConsumer> dummyConsumer(new DummyConsumer);
273 consumer->consumerConnect(dummyConsumer, false);
274 consumer->setConsumerName(String8("TestConsumer"));
275
276 sp<Surface> surface = new Surface(producer);
277 sp<ANativeWindow> window(surface);
278 native_window_api_connect(window.get(), NATIVE_WINDOW_API_CPU);
279
280 bool supported;
281 surface->getWideColorSupport(&supported);
282
Courtney Goeltzenleuchter6a570b62017-03-13 14:30:00 -0600283 // NOTE: This test assumes that device that supports
284 // wide-color (as indicated by BoardConfig) must also
285 // have a wide-color primary display.
286 // That assumption allows this test to cover devices
287 // that advertised a wide-color color mode without
288 // actually supporting wide-color to pass this test
289 // as well as the case of a device that does support
290 // wide-color (via BoardConfig) and has a wide-color
291 // primary display.
292 // NOT covered at this time is a device that supports
293 // wide color in the BoardConfig but does not support
294 // a wide-color color mode on the primary display.
295 ASSERT_EQ(hasWideColorDisplay, supported);
Courtney Goeltzenleuchter1eb1b272017-02-02 16:51:06 -0700296}
297
Pablo Ceballos789a0c82016-02-05 13:39:27 -0800298TEST_F(SurfaceTest, DynamicSetBufferCount) {
299 sp<IGraphicBufferProducer> producer;
300 sp<IGraphicBufferConsumer> consumer;
301 BufferQueue::createBufferQueue(&producer, &consumer);
302
303 sp<DummyConsumer> dummyConsumer(new DummyConsumer);
304 consumer->consumerConnect(dummyConsumer, false);
305 consumer->setConsumerName(String8("TestConsumer"));
306
307 sp<Surface> surface = new Surface(producer);
308 sp<ANativeWindow> window(surface);
309
310 ASSERT_EQ(NO_ERROR, native_window_api_connect(window.get(),
311 NATIVE_WINDOW_API_CPU));
312 native_window_set_buffer_count(window.get(), 4);
313
314 int fence;
315 ANativeWindowBuffer* buffer;
316 ASSERT_EQ(NO_ERROR, window->dequeueBuffer(window.get(), &buffer, &fence));
317 native_window_set_buffer_count(window.get(), 3);
318 ASSERT_EQ(NO_ERROR, window->queueBuffer(window.get(), buffer, fence));
319 native_window_set_buffer_count(window.get(), 2);
320 ASSERT_EQ(NO_ERROR, window->dequeueBuffer(window.get(), &buffer, &fence));
321 ASSERT_EQ(NO_ERROR, window->queueBuffer(window.get(), buffer, fence));
322}
323
Yin-Chia Yeh1f2af5c2017-05-11 16:54:04 -0700324TEST_F(SurfaceTest, GetAndFlushRemovedBuffers) {
325 sp<IGraphicBufferProducer> producer;
326 sp<IGraphicBufferConsumer> consumer;
327 BufferQueue::createBufferQueue(&producer, &consumer);
328
329 sp<DummyConsumer> dummyConsumer(new DummyConsumer);
330 consumer->consumerConnect(dummyConsumer, false);
331 consumer->setConsumerName(String8("TestConsumer"));
332
333 sp<Surface> surface = new Surface(producer);
334 sp<ANativeWindow> window(surface);
335 sp<DummyProducerListener> listener = new DummyProducerListener();
336 ASSERT_EQ(OK, surface->connect(
337 NATIVE_WINDOW_API_CPU,
338 /*listener*/listener,
339 /*reportBufferRemoval*/true));
340 const int BUFFER_COUNT = 4;
341 ASSERT_EQ(NO_ERROR, native_window_set_buffer_count(window.get(), BUFFER_COUNT));
342
343 sp<GraphicBuffer> detachedBuffer;
344 sp<Fence> outFence;
345 int fences[BUFFER_COUNT];
346 ANativeWindowBuffer* buffers[BUFFER_COUNT];
347 // Allocate buffers because detachNextBuffer requires allocated buffers
348 for (int i = 0; i < BUFFER_COUNT; i++) {
349 ASSERT_EQ(NO_ERROR, window->dequeueBuffer(window.get(), &buffers[i], &fences[i]));
350 }
351 for (int i = 0; i < BUFFER_COUNT; i++) {
352 ASSERT_EQ(NO_ERROR, window->cancelBuffer(window.get(), buffers[i], fences[i]));
353 }
354
355 // Test detached buffer is correctly reported
356 ASSERT_EQ(NO_ERROR, surface->detachNextBuffer(&detachedBuffer, &outFence));
357 std::vector<sp<GraphicBuffer>> removedBuffers;
358 ASSERT_EQ(OK, surface->getAndFlushRemovedBuffers(&removedBuffers));
359 ASSERT_EQ(1u, removedBuffers.size());
360 ASSERT_EQ(detachedBuffer->handle, removedBuffers.at(0)->handle);
361 // Test the list is flushed one getAndFlushRemovedBuffers returns
362 ASSERT_EQ(OK, surface->getAndFlushRemovedBuffers(&removedBuffers));
363 ASSERT_EQ(0u, removedBuffers.size());
364
365
366 // Test removed buffer list is cleanup after next dequeueBuffer call
367 ASSERT_EQ(NO_ERROR, surface->detachNextBuffer(&detachedBuffer, &outFence));
368 ASSERT_EQ(NO_ERROR, window->dequeueBuffer(window.get(), &buffers[0], &fences[0]));
369 ASSERT_EQ(OK, surface->getAndFlushRemovedBuffers(&removedBuffers));
370 ASSERT_EQ(0u, removedBuffers.size());
371 ASSERT_EQ(NO_ERROR, window->cancelBuffer(window.get(), buffers[0], fences[0]));
372
373 // Test removed buffer list is cleanup after next detachNextBuffer call
374 ASSERT_EQ(NO_ERROR, surface->detachNextBuffer(&detachedBuffer, &outFence));
375 ASSERT_EQ(NO_ERROR, surface->detachNextBuffer(&detachedBuffer, &outFence));
376 ASSERT_EQ(OK, surface->getAndFlushRemovedBuffers(&removedBuffers));
377 ASSERT_EQ(1u, removedBuffers.size());
378 ASSERT_EQ(detachedBuffer->handle, removedBuffers.at(0)->handle);
379
380 // Re-allocate buffers since all buffers are detached up to now
381 for (int i = 0; i < BUFFER_COUNT; i++) {
382 ASSERT_EQ(NO_ERROR, window->dequeueBuffer(window.get(), &buffers[i], &fences[i]));
383 }
384 for (int i = 0; i < BUFFER_COUNT; i++) {
385 ASSERT_EQ(NO_ERROR, window->cancelBuffer(window.get(), buffers[i], fences[i]));
386 }
387
388 ASSERT_EQ(NO_ERROR, surface->detachNextBuffer(&detachedBuffer, &outFence));
389 ASSERT_EQ(NO_ERROR, surface->attachBuffer(detachedBuffer.get()));
390 ASSERT_EQ(OK, surface->getAndFlushRemovedBuffers(&removedBuffers));
391 // Depends on which slot GraphicBufferProducer impl pick, the attach call might
392 // get 0 or 1 buffer removed.
393 ASSERT_LE(removedBuffers.size(), 1u);
394}
Brian Anderson3da8d272016-07-28 16:20:47 -0700395
Dan Stoza932f0082017-05-31 13:50:16 -0700396TEST_F(SurfaceTest, TestGetLastDequeueStartTime) {
397 sp<ANativeWindow> anw(mSurface);
398 ASSERT_EQ(NO_ERROR, native_window_api_connect(anw.get(), NATIVE_WINDOW_API_CPU));
399
400 ANativeWindowBuffer* buffer = nullptr;
401 int32_t fenceFd = -1;
402
403 nsecs_t before = systemTime(CLOCK_MONOTONIC);
404 anw->dequeueBuffer(anw.get(), &buffer, &fenceFd);
405 nsecs_t after = systemTime(CLOCK_MONOTONIC);
406
407 nsecs_t lastDequeueTime = mSurface->getLastDequeueStartTime();
408 ASSERT_LE(before, lastDequeueTime);
409 ASSERT_GE(after, lastDequeueTime);
410}
411
Brian Anderson3da8d272016-07-28 16:20:47 -0700412class FakeConsumer : public BnConsumerListener {
413public:
414 void onFrameAvailable(const BufferItem& /*item*/) override {}
415 void onBuffersReleased() override {}
416 void onSidebandStreamChanged() override {}
417
418 void addAndGetFrameTimestamps(
419 const NewFrameEventsEntry* newTimestamps,
420 FrameEventHistoryDelta* outDelta) override {
421 if (newTimestamps) {
422 if (mGetFrameTimestampsEnabled) {
423 EXPECT_GT(mNewFrameEntryOverride.frameNumber, 0u) <<
424 "Test should set mNewFrameEntryOverride before queuing "
425 "a frame.";
426 EXPECT_EQ(newTimestamps->frameNumber,
427 mNewFrameEntryOverride.frameNumber) <<
428 "Test attempting to add NewFrameEntryOverride with "
429 "incorrect frame number.";
430 mFrameEventHistory.addQueue(mNewFrameEntryOverride);
431 mNewFrameEntryOverride.frameNumber = 0;
432 }
433 mAddFrameTimestampsCount++;
434 mLastAddedFrameNumber = newTimestamps->frameNumber;
435 }
436 if (outDelta) {
437 mFrameEventHistory.getAndResetDelta(outDelta);
438 mGetFrameTimestampsCount++;
439 }
440 mAddAndGetFrameTimestampsCallCount++;
441 }
442
443 bool mGetFrameTimestampsEnabled = false;
444
445 ConsumerFrameEventHistory mFrameEventHistory;
446 int mAddAndGetFrameTimestampsCallCount = 0;
447 int mAddFrameTimestampsCount = 0;
448 int mGetFrameTimestampsCount = 0;
449 uint64_t mLastAddedFrameNumber = NO_FRAME_INDEX;
450
451 NewFrameEventsEntry mNewFrameEntryOverride = { 0, 0, 0, nullptr };
452};
453
454
455class FakeSurfaceComposer : public ISurfaceComposer{
456public:
457 ~FakeSurfaceComposer() override {}
458
Brian Anderson6b376712017-04-04 10:51:39 -0700459 void setSupportsPresent(bool supportsPresent) {
460 mSupportsPresent = supportsPresent;
461 }
462
Brian Anderson3da8d272016-07-28 16:20:47 -0700463 sp<ISurfaceComposerClient> createConnection() override { return nullptr; }
Robert Carr1db73f62016-12-21 12:58:51 -0800464 sp<ISurfaceComposerClient> createScopedConnection(
465 const sp<IGraphicBufferProducer>& /* parent */) override {
466 return nullptr;
467 }
Brian Anderson3da8d272016-07-28 16:20:47 -0700468 sp<IDisplayEventConnection> createDisplayEventConnection() override {
469 return nullptr;
470 }
471 sp<IBinder> createDisplay(const String8& /*displayName*/,
472 bool /*secure*/) override { return nullptr; }
473 void destroyDisplay(const sp<IBinder>& /*display */) override {}
474 sp<IBinder> getBuiltInDisplay(int32_t /*id*/) override { return nullptr; }
475 void setTransactionState(const Vector<ComposerState>& /*state*/,
476 const Vector<DisplayState>& /*displays*/, uint32_t /*flags*/)
477 override {}
478 void bootFinished() override {}
479 bool authenticateSurfaceTexture(
480 const sp<IGraphicBufferProducer>& /*surface*/) const override {
481 return false;
482 }
Brian Anderson6b376712017-04-04 10:51:39 -0700483
484 status_t getSupportedFrameTimestamps(std::vector<FrameEvent>* outSupported)
485 const override {
486 *outSupported = {
487 FrameEvent::REQUESTED_PRESENT,
488 FrameEvent::ACQUIRE,
489 FrameEvent::LATCH,
490 FrameEvent::FIRST_REFRESH_START,
491 FrameEvent::LAST_REFRESH_START,
492 FrameEvent::GPU_COMPOSITION_DONE,
493 FrameEvent::DEQUEUE_READY,
494 FrameEvent::RELEASE
495 };
496 if (mSupportsPresent) {
497 outSupported->push_back(
498 FrameEvent::DISPLAY_PRESENT);
499 }
500 return NO_ERROR;
501 }
502
Brian Anderson3da8d272016-07-28 16:20:47 -0700503 void setPowerMode(const sp<IBinder>& /*display*/, int /*mode*/) override {}
504 status_t getDisplayConfigs(const sp<IBinder>& /*display*/,
505 Vector<DisplayInfo>* /*configs*/) override { return NO_ERROR; }
506 status_t getDisplayStats(const sp<IBinder>& /*display*/,
507 DisplayStatInfo* /*stats*/) override { return NO_ERROR; }
508 int getActiveConfig(const sp<IBinder>& /*display*/) override { return 0; }
509 status_t setActiveConfig(const sp<IBinder>& /*display*/, int /*id*/)
510 override {
511 return NO_ERROR;
512 }
513 status_t getDisplayColorModes(const sp<IBinder>& /*display*/,
514 Vector<android_color_mode_t>* /*outColorModes*/) override {
515 return NO_ERROR;
516 }
517 android_color_mode_t getActiveColorMode(const sp<IBinder>& /*display*/)
518 override {
519 return HAL_COLOR_MODE_NATIVE;
520 }
521 status_t setActiveColorMode(const sp<IBinder>& /*display*/,
522 android_color_mode_t /*colorMode*/) override { return NO_ERROR; }
523 status_t captureScreen(const sp<IBinder>& /*display*/,
524 const sp<IGraphicBufferProducer>& /*producer*/,
525 Rect /*sourceCrop*/, uint32_t /*reqWidth*/, uint32_t /*reqHeight*/,
Robert Carrae060832016-11-28 10:51:00 -0800526 int32_t /*minLayerZ*/, int32_t /*maxLayerZ*/,
Brian Anderson3da8d272016-07-28 16:20:47 -0700527 bool /*useIdentityTransform*/,
528 Rotation /*rotation*/) override { return NO_ERROR; }
529 status_t clearAnimationFrameStats() override { return NO_ERROR; }
530 status_t getAnimationFrameStats(FrameStats* /*outStats*/) const override {
531 return NO_ERROR;
532 }
533 status_t getHdrCapabilities(const sp<IBinder>& /*display*/,
534 HdrCapabilities* /*outCapabilities*/) const override {
535 return NO_ERROR;
536 }
537 status_t enableVSyncInjections(bool /*enable*/) override {
538 return NO_ERROR;
539 }
540 status_t injectVSync(nsecs_t /*when*/) override { return NO_ERROR; }
541
542protected:
543 IBinder* onAsBinder() override { return nullptr; }
544
545private:
546 bool mSupportsPresent{true};
Brian Anderson3da8d272016-07-28 16:20:47 -0700547};
548
549class FakeProducerFrameEventHistory : public ProducerFrameEventHistory {
550public:
551 FakeProducerFrameEventHistory(FenceToFenceTimeMap* fenceMap)
552 : mFenceMap(fenceMap) {}
553
554 ~FakeProducerFrameEventHistory() {}
555
556 void updateAcquireFence(uint64_t frameNumber,
557 std::shared_ptr<FenceTime>&& acquire) override {
558 // Verify the acquire fence being added isn't the one from the consumer.
559 EXPECT_NE(mConsumerAcquireFence, acquire);
560 // Override the fence, so we can verify this was called by the
561 // producer after the frame is queued.
562 ProducerFrameEventHistory::updateAcquireFence(frameNumber,
563 std::shared_ptr<FenceTime>(mAcquireFenceOverride));
564 }
565
566 void setAcquireFenceOverride(
567 const std::shared_ptr<FenceTime>& acquireFenceOverride,
568 const std::shared_ptr<FenceTime>& consumerAcquireFence) {
569 mAcquireFenceOverride = acquireFenceOverride;
570 mConsumerAcquireFence = consumerAcquireFence;
571 }
572
573protected:
574 std::shared_ptr<FenceTime> createFenceTime(const sp<Fence>& fence)
575 const override {
576 return mFenceMap->createFenceTimeForTest(fence);
577 }
578
579 FenceToFenceTimeMap* mFenceMap{nullptr};
580
581 std::shared_ptr<FenceTime> mAcquireFenceOverride{FenceTime::NO_FENCE};
582 std::shared_ptr<FenceTime> mConsumerAcquireFence{FenceTime::NO_FENCE};
583};
584
585
586class TestSurface : public Surface {
587public:
588 TestSurface(const sp<IGraphicBufferProducer>& bufferProducer,
589 FenceToFenceTimeMap* fenceMap)
590 : Surface(bufferProducer),
591 mFakeSurfaceComposer(new FakeSurfaceComposer) {
592 mFakeFrameEventHistory = new FakeProducerFrameEventHistory(fenceMap);
593 mFrameEventHistory.reset(mFakeFrameEventHistory);
594 }
595
596 ~TestSurface() override {}
597
598 sp<ISurfaceComposer> composerService() const override {
599 return mFakeSurfaceComposer;
600 }
601
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800602 nsecs_t now() const override {
603 return mNow;
604 }
605
606 void setNow(nsecs_t now) {
607 mNow = now;
608 }
609
Brian Anderson3da8d272016-07-28 16:20:47 -0700610public:
611 sp<FakeSurfaceComposer> mFakeSurfaceComposer;
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800612 nsecs_t mNow = 0;
Brian Anderson3da8d272016-07-28 16:20:47 -0700613
614 // mFrameEventHistory owns the instance of FakeProducerFrameEventHistory,
615 // but this raw pointer gives access to test functionality.
616 FakeProducerFrameEventHistory* mFakeFrameEventHistory;
617};
618
619
Brian Andersond0010582017-03-07 13:20:31 -0800620class GetFrameTimestampsTest : public ::testing::Test {
Brian Anderson3da8d272016-07-28 16:20:47 -0700621protected:
622 struct FenceAndFenceTime {
623 explicit FenceAndFenceTime(FenceToFenceTimeMap& fenceMap)
624 : mFence(new Fence),
625 mFenceTime(fenceMap.createFenceTimeForTest(mFence)) {}
626 sp<Fence> mFence { nullptr };
627 std::shared_ptr<FenceTime> mFenceTime { nullptr };
628 };
629
630 struct RefreshEvents {
631 RefreshEvents(FenceToFenceTimeMap& fenceMap, nsecs_t refreshStart)
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800632 : mFenceMap(fenceMap),
633 kCompositorTiming(
634 {refreshStart, refreshStart + 1, refreshStart + 2 }),
635 kStartTime(refreshStart + 3),
636 kGpuCompositionDoneTime(refreshStart + 4),
637 kPresentTime(refreshStart + 5) {}
Brian Anderson3da8d272016-07-28 16:20:47 -0700638
639 void signalPostCompositeFences() {
640 mFenceMap.signalAllForTest(
641 mGpuCompositionDone.mFence, kGpuCompositionDoneTime);
642 mFenceMap.signalAllForTest(mPresent.mFence, kPresentTime);
643 }
644
645 FenceToFenceTimeMap& mFenceMap;
646
647 FenceAndFenceTime mGpuCompositionDone { mFenceMap };
648 FenceAndFenceTime mPresent { mFenceMap };
649
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800650 const CompositorTiming kCompositorTiming;
651
Brian Anderson3da8d272016-07-28 16:20:47 -0700652 const nsecs_t kStartTime;
653 const nsecs_t kGpuCompositionDoneTime;
654 const nsecs_t kPresentTime;
655 };
656
657 struct FrameEvents {
658 FrameEvents(FenceToFenceTimeMap& fenceMap, nsecs_t frameStartTime)
659 : mFenceMap(fenceMap),
660 kPostedTime(frameStartTime + 100),
661 kRequestedPresentTime(frameStartTime + 200),
662 kProducerAcquireTime(frameStartTime + 300),
663 kConsumerAcquireTime(frameStartTime + 301),
664 kLatchTime(frameStartTime + 500),
Brian Andersonf6386862016-10-31 16:34:13 -0700665 kDequeueReadyTime(frameStartTime + 600),
Brian Anderson4e606e32017-03-16 15:34:57 -0700666 kReleaseTime(frameStartTime + 700),
Brian Anderson3da8d272016-07-28 16:20:47 -0700667 mRefreshes {
668 { mFenceMap, frameStartTime + 410 },
669 { mFenceMap, frameStartTime + 420 },
670 { mFenceMap, frameStartTime + 430 } } {}
671
672 void signalQueueFences() {
673 mFenceMap.signalAllForTest(
674 mAcquireConsumer.mFence, kConsumerAcquireTime);
675 mFenceMap.signalAllForTest(
676 mAcquireProducer.mFence, kProducerAcquireTime);
677 }
678
679 void signalRefreshFences() {
680 for (auto& re : mRefreshes) {
681 re.signalPostCompositeFences();
682 }
683 }
684
685 void signalReleaseFences() {
Brian Anderson3da8d272016-07-28 16:20:47 -0700686 mFenceMap.signalAllForTest(mRelease.mFence, kReleaseTime);
687 }
688
689 FenceToFenceTimeMap& mFenceMap;
690
691 FenceAndFenceTime mAcquireConsumer { mFenceMap };
692 FenceAndFenceTime mAcquireProducer { mFenceMap };
Brian Anderson3da8d272016-07-28 16:20:47 -0700693 FenceAndFenceTime mRelease { mFenceMap };
694
695 const nsecs_t kPostedTime;
696 const nsecs_t kRequestedPresentTime;
697 const nsecs_t kProducerAcquireTime;
698 const nsecs_t kConsumerAcquireTime;
699 const nsecs_t kLatchTime;
Brian Andersonf6386862016-10-31 16:34:13 -0700700 const nsecs_t kDequeueReadyTime;
Brian Anderson3da8d272016-07-28 16:20:47 -0700701 const nsecs_t kReleaseTime;
702
703 RefreshEvents mRefreshes[3];
704 };
705
Brian Andersond0010582017-03-07 13:20:31 -0800706 GetFrameTimestampsTest() {}
Brian Anderson3da8d272016-07-28 16:20:47 -0700707
708 virtual void SetUp() {
Brian Anderson3da8d272016-07-28 16:20:47 -0700709 BufferQueue::createBufferQueue(&mProducer, &mConsumer);
710 mFakeConsumer = new FakeConsumer;
711 mCfeh = &mFakeConsumer->mFrameEventHistory;
712 mConsumer->consumerConnect(mFakeConsumer, false);
713 mConsumer->setConsumerName(String8("TestConsumer"));
714 mSurface = new TestSurface(mProducer, &mFenceMap);
715 mWindow = mSurface;
716
717 ASSERT_EQ(NO_ERROR, native_window_api_connect(mWindow.get(),
718 NATIVE_WINDOW_API_CPU));
719 native_window_set_buffer_count(mWindow.get(), 4);
720 }
721
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800722 void disableFrameTimestamps() {
723 mFakeConsumer->mGetFrameTimestampsEnabled = false;
724 native_window_enable_frame_timestamps(mWindow.get(), 0);
725 mFrameTimestampsEnabled = false;
726 }
727
Brian Anderson3da8d272016-07-28 16:20:47 -0700728 void enableFrameTimestamps() {
729 mFakeConsumer->mGetFrameTimestampsEnabled = true;
730 native_window_enable_frame_timestamps(mWindow.get(), 1);
731 mFrameTimestampsEnabled = true;
732 }
733
Brian Anderson1049d1d2016-12-16 17:25:57 -0800734 int getAllFrameTimestamps(uint64_t frameId) {
735 return native_window_get_frame_timestamps(mWindow.get(), frameId,
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700736 &outRequestedPresentTime, &outAcquireTime, &outLatchTime,
737 &outFirstRefreshStartTime, &outLastRefreshStartTime,
738 &outGpuCompositionDoneTime, &outDisplayPresentTime,
Brian Anderson4e606e32017-03-16 15:34:57 -0700739 &outDequeueReadyTime, &outReleaseTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700740 }
741
Brian Anderson3da8d272016-07-28 16:20:47 -0700742 void resetTimestamps() {
743 outRequestedPresentTime = -1;
744 outAcquireTime = -1;
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700745 outLatchTime = -1;
746 outFirstRefreshStartTime = -1;
747 outLastRefreshStartTime = -1;
Brian Anderson3da8d272016-07-28 16:20:47 -0700748 outGpuCompositionDoneTime = -1;
749 outDisplayPresentTime = -1;
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700750 outDequeueReadyTime = -1;
Brian Anderson3da8d272016-07-28 16:20:47 -0700751 outReleaseTime = -1;
752 }
753
Brian Anderson1049d1d2016-12-16 17:25:57 -0800754 uint64_t getNextFrameId() {
755 uint64_t frameId = -1;
756 int status = native_window_get_next_frame_id(mWindow.get(), &frameId);
757 EXPECT_EQ(status, NO_ERROR);
758 return frameId;
759 }
760
Brian Anderson3da8d272016-07-28 16:20:47 -0700761 void dequeueAndQueue(uint64_t frameIndex) {
762 int fence = -1;
763 ANativeWindowBuffer* buffer = nullptr;
764 ASSERT_EQ(NO_ERROR,
765 mWindow->dequeueBuffer(mWindow.get(), &buffer, &fence));
766
767 int oldAddFrameTimestampsCount =
768 mFakeConsumer->mAddFrameTimestampsCount;
769
770 FrameEvents* frame = &mFrames[frameIndex];
771 uint64_t frameNumber = frameIndex + 1;
772
773 NewFrameEventsEntry fe;
774 fe.frameNumber = frameNumber;
775 fe.postedTime = frame->kPostedTime;
776 fe.requestedPresentTime = frame->kRequestedPresentTime;
777 fe.acquireFence = frame->mAcquireConsumer.mFenceTime;
778 mFakeConsumer->mNewFrameEntryOverride = fe;
779
780 mSurface->mFakeFrameEventHistory->setAcquireFenceOverride(
781 frame->mAcquireProducer.mFenceTime,
782 frame->mAcquireConsumer.mFenceTime);
783
784 ASSERT_EQ(NO_ERROR, mWindow->queueBuffer(mWindow.get(), buffer, fence));
785
786 EXPECT_EQ(frameNumber, mFakeConsumer->mLastAddedFrameNumber);
787
788 EXPECT_EQ(
789 oldAddFrameTimestampsCount + (mFrameTimestampsEnabled ? 1 : 0),
790 mFakeConsumer->mAddFrameTimestampsCount);
791 }
792
793 void addFrameEvents(
794 bool gpuComposited, uint64_t iOldFrame, int64_t iNewFrame) {
795 FrameEvents* oldFrame =
796 (iOldFrame == NO_FRAME_INDEX) ? nullptr : &mFrames[iOldFrame];
797 FrameEvents* newFrame = &mFrames[iNewFrame];
798
799 uint64_t nOldFrame = iOldFrame + 1;
800 uint64_t nNewFrame = iNewFrame + 1;
801
Brian Anderson4e606e32017-03-16 15:34:57 -0700802 // Latch, Composite, and Release the frames in a plausible order.
803 // Note: The timestamps won't necessarily match the order, but
Brian Anderson3da8d272016-07-28 16:20:47 -0700804 // that's okay for the purposes of this test.
805 std::shared_ptr<FenceTime> gpuDoneFenceTime = FenceTime::NO_FENCE;
806
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700807 // Composite the previous frame one more time, which helps verify
808 // LastRefresh is updated properly.
809 if (oldFrame != nullptr) {
810 mCfeh->addPreComposition(nOldFrame,
811 oldFrame->mRefreshes[2].kStartTime);
812 gpuDoneFenceTime = gpuComposited ?
813 oldFrame->mRefreshes[2].mGpuCompositionDone.mFenceTime :
814 FenceTime::NO_FENCE;
815 mCfeh->addPostComposition(nOldFrame, gpuDoneFenceTime,
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800816 oldFrame->mRefreshes[2].mPresent.mFenceTime,
817 oldFrame->mRefreshes[2].kCompositorTiming);
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700818 }
819
820 // Latch the new frame.
Brian Anderson3da8d272016-07-28 16:20:47 -0700821 mCfeh->addLatch(nNewFrame, newFrame->kLatchTime);
822
823 mCfeh->addPreComposition(nNewFrame, newFrame->mRefreshes[0].kStartTime);
824 gpuDoneFenceTime = gpuComposited ?
825 newFrame->mRefreshes[0].mGpuCompositionDone.mFenceTime :
826 FenceTime::NO_FENCE;
827 // HWC2 releases the previous buffer after a new latch just before
828 // calling postComposition.
829 if (oldFrame != nullptr) {
Brian Andersonf6386862016-10-31 16:34:13 -0700830 mCfeh->addRelease(nOldFrame, oldFrame->kDequeueReadyTime,
Brian Anderson3da8d272016-07-28 16:20:47 -0700831 std::shared_ptr<FenceTime>(oldFrame->mRelease.mFenceTime));
832 }
833 mCfeh->addPostComposition(nNewFrame, gpuDoneFenceTime,
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800834 newFrame->mRefreshes[0].mPresent.mFenceTime,
835 newFrame->mRefreshes[0].kCompositorTiming);
Brian Anderson3da8d272016-07-28 16:20:47 -0700836
Brian Anderson3da8d272016-07-28 16:20:47 -0700837 mCfeh->addPreComposition(nNewFrame, newFrame->mRefreshes[1].kStartTime);
838 gpuDoneFenceTime = gpuComposited ?
839 newFrame->mRefreshes[1].mGpuCompositionDone.mFenceTime :
840 FenceTime::NO_FENCE;
841 mCfeh->addPostComposition(nNewFrame, gpuDoneFenceTime,
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800842 newFrame->mRefreshes[1].mPresent.mFenceTime,
843 newFrame->mRefreshes[1].kCompositorTiming);
Brian Anderson3da8d272016-07-28 16:20:47 -0700844 }
845
Brian Anderson3da8d272016-07-28 16:20:47 -0700846 sp<IGraphicBufferProducer> mProducer;
847 sp<IGraphicBufferConsumer> mConsumer;
848 sp<FakeConsumer> mFakeConsumer;
849 ConsumerFrameEventHistory* mCfeh;
850 sp<TestSurface> mSurface;
851 sp<ANativeWindow> mWindow;
852
853 FenceToFenceTimeMap mFenceMap;
854
855 bool mFrameTimestampsEnabled = false;
856
857 int64_t outRequestedPresentTime = -1;
858 int64_t outAcquireTime = -1;
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700859 int64_t outLatchTime = -1;
860 int64_t outFirstRefreshStartTime = -1;
861 int64_t outLastRefreshStartTime = -1;
Brian Anderson3da8d272016-07-28 16:20:47 -0700862 int64_t outGpuCompositionDoneTime = -1;
863 int64_t outDisplayPresentTime = -1;
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700864 int64_t outDequeueReadyTime = -1;
Brian Anderson3da8d272016-07-28 16:20:47 -0700865 int64_t outReleaseTime = -1;
866
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800867 FrameEvents mFrames[3] {
868 { mFenceMap, 1000 }, { mFenceMap, 2000 }, { mFenceMap, 3000 } };
Brian Anderson3da8d272016-07-28 16:20:47 -0700869};
870
871
872// This test verifies that the frame timestamps are not retrieved when not
873// explicitly enabled via native_window_enable_frame_timestamps.
874// We want to check this to make sure there's no overhead for users
875// that don't need the timestamp information.
876TEST_F(GetFrameTimestampsTest, DefaultDisabled) {
877 int fence;
878 ANativeWindowBuffer* buffer;
879
880 EXPECT_EQ(0, mFakeConsumer->mAddFrameTimestampsCount);
881 EXPECT_EQ(0, mFakeConsumer->mGetFrameTimestampsCount);
882
Brian Anderson1049d1d2016-12-16 17:25:57 -0800883 const uint64_t fId = getNextFrameId();
884
Brian Anderson3da8d272016-07-28 16:20:47 -0700885 // Verify the producer doesn't get frame timestamps piggybacked on dequeue.
886 ASSERT_EQ(NO_ERROR, mWindow->dequeueBuffer(mWindow.get(), &buffer, &fence));
887 EXPECT_EQ(0, mFakeConsumer->mAddFrameTimestampsCount);
888 EXPECT_EQ(0, mFakeConsumer->mGetFrameTimestampsCount);
889
890 // Verify the producer doesn't get frame timestamps piggybacked on queue.
891 // It is okay that frame timestamps are added in the consumer since it is
892 // still needed for SurfaceFlinger dumps.
893 ASSERT_EQ(NO_ERROR, mWindow->queueBuffer(mWindow.get(), buffer, fence));
894 EXPECT_EQ(1, mFakeConsumer->mAddFrameTimestampsCount);
895 EXPECT_EQ(0, mFakeConsumer->mGetFrameTimestampsCount);
896
897 // Verify attempts to get frame timestamps fail.
Brian Anderson1049d1d2016-12-16 17:25:57 -0800898 int result = getAllFrameTimestamps(fId);
Brian Anderson3da8d272016-07-28 16:20:47 -0700899 EXPECT_EQ(INVALID_OPERATION, result);
900 EXPECT_EQ(0, mFakeConsumer->mGetFrameTimestampsCount);
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800901
902 // Verify compositor timing query fails.
903 nsecs_t compositeDeadline = 0;
904 nsecs_t compositeInterval = 0;
905 nsecs_t compositeToPresentLatency = 0;
906 result = native_window_get_compositor_timing(mWindow.get(),
907 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
908 EXPECT_EQ(INVALID_OPERATION, result);
Brian Anderson3da8d272016-07-28 16:20:47 -0700909}
910
911// This test verifies that the frame timestamps are retrieved if explicitly
912// enabled via native_window_enable_frame_timestamps.
913TEST_F(GetFrameTimestampsTest, EnabledSimple) {
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800914 CompositorTiming initialCompositorTiming {
915 1000000000, // 1s deadline
916 16666667, // 16ms interval
917 50000000, // 50ms present latency
918 };
919 mCfeh->initializeCompositorTiming(initialCompositorTiming);
920
Brian Anderson3da8d272016-07-28 16:20:47 -0700921 enableFrameTimestamps();
922
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800923 // Verify the compositor timing query gets the initial compositor values
924 // after timststamps are enabled; even before the first frame is queued
925 // or dequeued.
926 nsecs_t compositeDeadline = 0;
927 nsecs_t compositeInterval = 0;
928 nsecs_t compositeToPresentLatency = 0;
929 mSurface->setNow(initialCompositorTiming.deadline - 1);
930 int result = native_window_get_compositor_timing(mWindow.get(),
931 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
932 EXPECT_EQ(NO_ERROR, result);
933 EXPECT_EQ(initialCompositorTiming.deadline, compositeDeadline);
934 EXPECT_EQ(initialCompositorTiming.interval, compositeInterval);
935 EXPECT_EQ(initialCompositorTiming.presentLatency,
936 compositeToPresentLatency);
937
Brian Anderson3da8d272016-07-28 16:20:47 -0700938 int fence;
939 ANativeWindowBuffer* buffer;
940
941 EXPECT_EQ(0, mFakeConsumer->mAddFrameTimestampsCount);
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800942 EXPECT_EQ(1, mFakeConsumer->mGetFrameTimestampsCount);
Brian Anderson3da8d272016-07-28 16:20:47 -0700943
Brian Anderson1049d1d2016-12-16 17:25:57 -0800944 const uint64_t fId1 = getNextFrameId();
945
Brian Anderson3da8d272016-07-28 16:20:47 -0700946 // Verify getFrameTimestamps is piggybacked on dequeue.
947 ASSERT_EQ(NO_ERROR, mWindow->dequeueBuffer(mWindow.get(), &buffer, &fence));
948 EXPECT_EQ(0, mFakeConsumer->mAddFrameTimestampsCount);
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800949 EXPECT_EQ(2, mFakeConsumer->mGetFrameTimestampsCount);
Brian Anderson3da8d272016-07-28 16:20:47 -0700950
951 NewFrameEventsEntry f1;
952 f1.frameNumber = 1;
953 f1.postedTime = mFrames[0].kPostedTime;
954 f1.requestedPresentTime = mFrames[0].kRequestedPresentTime;
955 f1.acquireFence = mFrames[0].mAcquireConsumer.mFenceTime;
956 mSurface->mFakeFrameEventHistory->setAcquireFenceOverride(
957 mFrames[0].mAcquireProducer.mFenceTime,
958 mFrames[0].mAcquireConsumer.mFenceTime);
959 mFakeConsumer->mNewFrameEntryOverride = f1;
960 mFrames[0].signalQueueFences();
961
962 // Verify getFrameTimestamps is piggybacked on queue.
963 ASSERT_EQ(NO_ERROR, mWindow->queueBuffer(mWindow.get(), buffer, fence));
964 EXPECT_EQ(1, mFakeConsumer->mAddFrameTimestampsCount);
965 EXPECT_EQ(1u, mFakeConsumer->mLastAddedFrameNumber);
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800966 EXPECT_EQ(3, mFakeConsumer->mGetFrameTimestampsCount);
Brian Anderson3da8d272016-07-28 16:20:47 -0700967
968 // Verify queries for timestamps that the producer doesn't know about
969 // triggers a call to see if the consumer has any new timestamps.
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800970 result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -0700971 EXPECT_EQ(NO_ERROR, result);
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800972 EXPECT_EQ(4, mFakeConsumer->mGetFrameTimestampsCount);
Brian Anderson3da8d272016-07-28 16:20:47 -0700973}
974
Brian Anderson6b376712017-04-04 10:51:39 -0700975TEST_F(GetFrameTimestampsTest, QueryPresentSupported) {
976 bool displayPresentSupported = true;
977 mSurface->mFakeSurfaceComposer->setSupportsPresent(displayPresentSupported);
978
979 // Verify supported bits are forwarded.
980 int supportsPresent = -1;
981 mWindow.get()->query(mWindow.get(),
982 NATIVE_WINDOW_FRAME_TIMESTAMPS_SUPPORTS_PRESENT, &supportsPresent);
983 EXPECT_EQ(displayPresentSupported, supportsPresent);
984}
985
986TEST_F(GetFrameTimestampsTest, QueryPresentNotSupported) {
987 bool displayPresentSupported = false;
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
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800997TEST_F(GetFrameTimestampsTest, SnapToNextTickBasic) {
998 nsecs_t phase = 4000;
999 nsecs_t interval = 1000;
1000
1001 // Timestamp in previous interval.
1002 nsecs_t timestamp = 3500;
1003 EXPECT_EQ(4000, ProducerFrameEventHistory::snapToNextTick(
1004 timestamp, phase, interval));
1005
1006 // Timestamp in next interval.
1007 timestamp = 4500;
1008 EXPECT_EQ(5000, ProducerFrameEventHistory::snapToNextTick(
1009 timestamp, phase, interval));
1010
1011 // Timestamp multiple intervals before.
1012 timestamp = 2500;
1013 EXPECT_EQ(3000, ProducerFrameEventHistory::snapToNextTick(
1014 timestamp, phase, interval));
1015
1016 // Timestamp multiple intervals after.
1017 timestamp = 6500;
1018 EXPECT_EQ(7000, ProducerFrameEventHistory::snapToNextTick(
1019 timestamp, phase, interval));
1020
1021 // Timestamp on previous interval.
1022 timestamp = 3000;
1023 EXPECT_EQ(3000, ProducerFrameEventHistory::snapToNextTick(
1024 timestamp, phase, interval));
1025
1026 // Timestamp on next interval.
1027 timestamp = 5000;
1028 EXPECT_EQ(5000, ProducerFrameEventHistory::snapToNextTick(
1029 timestamp, phase, interval));
1030
1031 // Timestamp equal to phase.
1032 timestamp = 4000;
1033 EXPECT_EQ(4000, ProducerFrameEventHistory::snapToNextTick(
1034 timestamp, phase, interval));
1035}
1036
1037// int(big_timestamp / interval) < 0, which can cause a crash or invalid result
1038// if the number of intervals elapsed is internally stored in an int.
1039TEST_F(GetFrameTimestampsTest, SnapToNextTickOverflow) {
1040 nsecs_t phase = 0;
1041 nsecs_t interval = 4000;
1042 nsecs_t big_timestamp = 8635916564000;
1043 int32_t intervals = big_timestamp / interval;
1044
1045 EXPECT_LT(intervals, 0);
1046 EXPECT_EQ(8635916564000, ProducerFrameEventHistory::snapToNextTick(
1047 big_timestamp, phase, interval));
1048 EXPECT_EQ(8635916564000, ProducerFrameEventHistory::snapToNextTick(
1049 big_timestamp, big_timestamp, interval));
1050}
1051
1052// This verifies the compositor timing is updated by refresh events
1053// and piggy backed on a queue, dequeue, and enabling of timestamps..
1054TEST_F(GetFrameTimestampsTest, CompositorTimingUpdatesBasic) {
1055 CompositorTiming initialCompositorTiming {
1056 1000000000, // 1s deadline
1057 16666667, // 16ms interval
1058 50000000, // 50ms present latency
1059 };
1060 mCfeh->initializeCompositorTiming(initialCompositorTiming);
1061
1062 enableFrameTimestamps();
1063
1064 // We get the initial values before any frames are submitted.
1065 nsecs_t compositeDeadline = 0;
1066 nsecs_t compositeInterval = 0;
1067 nsecs_t compositeToPresentLatency = 0;
1068 mSurface->setNow(initialCompositorTiming.deadline - 1);
1069 int result = native_window_get_compositor_timing(mWindow.get(),
1070 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1071 EXPECT_EQ(NO_ERROR, result);
1072 EXPECT_EQ(initialCompositorTiming.deadline, compositeDeadline);
1073 EXPECT_EQ(initialCompositorTiming.interval, compositeInterval);
1074 EXPECT_EQ(initialCompositorTiming.presentLatency,
1075 compositeToPresentLatency);
1076
1077 const uint64_t fId1 = getNextFrameId();
1078 dequeueAndQueue(0);
1079 addFrameEvents(true, NO_FRAME_INDEX, 0);
1080
1081 // Still get the initial values because the frame events for frame 0
1082 // didn't get a chance to piggyback on a queue or dequeue yet.
1083 result = native_window_get_compositor_timing(mWindow.get(),
1084 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1085 EXPECT_EQ(NO_ERROR, result);
1086 EXPECT_EQ(initialCompositorTiming.deadline, compositeDeadline);
1087 EXPECT_EQ(initialCompositorTiming.interval, compositeInterval);
1088 EXPECT_EQ(initialCompositorTiming.presentLatency,
1089 compositeToPresentLatency);
1090
1091 const uint64_t fId2 = getNextFrameId();
1092 dequeueAndQueue(1);
1093 addFrameEvents(true, 0, 1);
1094
1095 // Now expect the composite values associated with frame 1.
1096 mSurface->setNow(mFrames[0].mRefreshes[1].kCompositorTiming.deadline);
1097 result = native_window_get_compositor_timing(mWindow.get(),
1098 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1099 EXPECT_EQ(NO_ERROR, result);
1100 EXPECT_EQ(mFrames[0].mRefreshes[1].kCompositorTiming.deadline,
1101 compositeDeadline);
1102 EXPECT_EQ(mFrames[0].mRefreshes[1].kCompositorTiming.interval,
1103 compositeInterval);
1104 EXPECT_EQ(mFrames[0].mRefreshes[1].kCompositorTiming.presentLatency,
1105 compositeToPresentLatency);
1106
1107 dequeueAndQueue(2);
1108 addFrameEvents(true, 1, 2);
1109
1110 // Now expect the composite values associated with frame 2.
1111 mSurface->setNow(mFrames[1].mRefreshes[1].kCompositorTiming.deadline);
1112 result = native_window_get_compositor_timing(mWindow.get(),
1113 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1114 EXPECT_EQ(NO_ERROR, result);
1115 EXPECT_EQ(mFrames[1].mRefreshes[1].kCompositorTiming.deadline,
1116 compositeDeadline);
1117 EXPECT_EQ(mFrames[1].mRefreshes[1].kCompositorTiming.interval,
1118 compositeInterval);
1119 EXPECT_EQ(mFrames[1].mRefreshes[1].kCompositorTiming.presentLatency,
1120 compositeToPresentLatency);
1121
1122 // Re-enabling frame timestamps should get the latest values.
1123 disableFrameTimestamps();
1124 enableFrameTimestamps();
1125
1126 // Now expect the composite values associated with frame 3.
1127 mSurface->setNow(mFrames[2].mRefreshes[1].kCompositorTiming.deadline);
1128 result = native_window_get_compositor_timing(mWindow.get(),
1129 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1130 EXPECT_EQ(NO_ERROR, result);
1131 EXPECT_EQ(mFrames[2].mRefreshes[1].kCompositorTiming.deadline,
1132 compositeDeadline);
1133 EXPECT_EQ(mFrames[2].mRefreshes[1].kCompositorTiming.interval,
1134 compositeInterval);
1135 EXPECT_EQ(mFrames[2].mRefreshes[1].kCompositorTiming.presentLatency,
1136 compositeToPresentLatency);
1137}
1138
1139// This verifies the compositor deadline properly snaps to the the next
1140// deadline based on the current time.
1141TEST_F(GetFrameTimestampsTest, CompositorTimingDeadlineSnaps) {
1142 CompositorTiming initialCompositorTiming {
1143 1000000000, // 1s deadline
1144 16666667, // 16ms interval
1145 50000000, // 50ms present latency
1146 };
1147 mCfeh->initializeCompositorTiming(initialCompositorTiming);
1148
1149 enableFrameTimestamps();
1150
1151 nsecs_t compositeDeadline = 0;
1152 nsecs_t compositeInterval = 0;
1153 nsecs_t compositeToPresentLatency = 0;
1154
1155 // A "now" just before the deadline snaps to the deadline.
1156 mSurface->setNow(initialCompositorTiming.deadline - 1);
1157 int result = native_window_get_compositor_timing(mWindow.get(),
1158 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1159 EXPECT_EQ(NO_ERROR, result);
1160 EXPECT_EQ(initialCompositorTiming.deadline, compositeDeadline);
1161 nsecs_t expectedDeadline = initialCompositorTiming.deadline;
1162 EXPECT_EQ(expectedDeadline, compositeDeadline);
1163
1164 const uint64_t fId1 = getNextFrameId();
1165 dequeueAndQueue(0);
1166 addFrameEvents(true, NO_FRAME_INDEX, 0);
1167
1168 // A "now" just after the deadline snaps properly.
1169 mSurface->setNow(initialCompositorTiming.deadline + 1);
1170 result = native_window_get_compositor_timing(mWindow.get(),
1171 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1172 EXPECT_EQ(NO_ERROR, result);
1173 expectedDeadline =
1174 initialCompositorTiming.deadline +initialCompositorTiming.interval;
1175 EXPECT_EQ(expectedDeadline, compositeDeadline);
1176
1177 const uint64_t fId2 = getNextFrameId();
1178 dequeueAndQueue(1);
1179 addFrameEvents(true, 0, 1);
1180
1181 // A "now" just after the next interval snaps properly.
1182 mSurface->setNow(
1183 mFrames[0].mRefreshes[1].kCompositorTiming.deadline +
1184 mFrames[0].mRefreshes[1].kCompositorTiming.interval + 1);
1185 result = native_window_get_compositor_timing(mWindow.get(),
1186 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1187 EXPECT_EQ(NO_ERROR, result);
1188 expectedDeadline =
1189 mFrames[0].mRefreshes[1].kCompositorTiming.deadline +
1190 mFrames[0].mRefreshes[1].kCompositorTiming.interval * 2;
1191 EXPECT_EQ(expectedDeadline, compositeDeadline);
1192
1193 dequeueAndQueue(2);
1194 addFrameEvents(true, 1, 2);
1195
1196 // A "now" over 1 interval before the deadline snaps properly.
1197 mSurface->setNow(
1198 mFrames[1].mRefreshes[1].kCompositorTiming.deadline -
1199 mFrames[1].mRefreshes[1].kCompositorTiming.interval - 1);
1200 result = native_window_get_compositor_timing(mWindow.get(),
1201 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1202 EXPECT_EQ(NO_ERROR, result);
1203 expectedDeadline =
1204 mFrames[1].mRefreshes[1].kCompositorTiming.deadline -
1205 mFrames[1].mRefreshes[1].kCompositorTiming.interval;
1206 EXPECT_EQ(expectedDeadline, compositeDeadline);
1207
1208 // Re-enabling frame timestamps should get the latest values.
1209 disableFrameTimestamps();
1210 enableFrameTimestamps();
1211
1212 // A "now" over 2 intervals before the deadline snaps properly.
1213 mSurface->setNow(
1214 mFrames[2].mRefreshes[1].kCompositorTiming.deadline -
1215 mFrames[2].mRefreshes[1].kCompositorTiming.interval * 2 - 1);
1216 result = native_window_get_compositor_timing(mWindow.get(),
1217 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1218 EXPECT_EQ(NO_ERROR, result);
1219 expectedDeadline =
1220 mFrames[2].mRefreshes[1].kCompositorTiming.deadline -
1221 mFrames[2].mRefreshes[1].kCompositorTiming.interval * 2;
1222 EXPECT_EQ(expectedDeadline, compositeDeadline);
1223}
1224
Brian Anderson1049d1d2016-12-16 17:25:57 -08001225// This verifies the timestamps recorded in the consumer's
1226// FrameTimestampsHistory are properly retrieved by the producer for the
1227// correct frames.
Brian Anderson3da8d272016-07-28 16:20:47 -07001228TEST_F(GetFrameTimestampsTest, TimestampsAssociatedWithCorrectFrame) {
1229 enableFrameTimestamps();
1230
Brian Anderson1049d1d2016-12-16 17:25:57 -08001231 const uint64_t fId1 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001232 dequeueAndQueue(0);
1233 mFrames[0].signalQueueFences();
1234
Brian Anderson1049d1d2016-12-16 17:25:57 -08001235 const uint64_t fId2 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001236 dequeueAndQueue(1);
1237 mFrames[1].signalQueueFences();
1238
1239 addFrameEvents(true, NO_FRAME_INDEX, 0);
1240 mFrames[0].signalRefreshFences();
1241 addFrameEvents(true, 0, 1);
1242 mFrames[0].signalReleaseFences();
1243 mFrames[1].signalRefreshFences();
1244
1245 // Verify timestamps are correct for frame 1.
Brian Anderson3da8d272016-07-28 16:20:47 -07001246 resetTimestamps();
Brian Anderson1049d1d2016-12-16 17:25:57 -08001247 int result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001248 EXPECT_EQ(NO_ERROR, result);
1249 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1250 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001251 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1252 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1253 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001254 EXPECT_EQ(mFrames[0].mRefreshes[0].kGpuCompositionDoneTime,
1255 outGpuCompositionDoneTime);
1256 EXPECT_EQ(mFrames[0].mRefreshes[0].kPresentTime, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001257 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001258 EXPECT_EQ(mFrames[0].kReleaseTime, outReleaseTime);
1259
1260 // Verify timestamps are correct for frame 2.
Brian Anderson3da8d272016-07-28 16:20:47 -07001261 resetTimestamps();
Brian Anderson1049d1d2016-12-16 17:25:57 -08001262 result = getAllFrameTimestamps(fId2);
Brian Anderson3da8d272016-07-28 16:20:47 -07001263 EXPECT_EQ(NO_ERROR, result);
1264 EXPECT_EQ(mFrames[1].kRequestedPresentTime, outRequestedPresentTime);
1265 EXPECT_EQ(mFrames[1].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001266 EXPECT_EQ(mFrames[1].kLatchTime, outLatchTime);
1267 EXPECT_EQ(mFrames[1].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1268 EXPECT_EQ(mFrames[1].mRefreshes[1].kStartTime, outLastRefreshStartTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001269 EXPECT_EQ(mFrames[1].mRefreshes[0].kGpuCompositionDoneTime,
1270 outGpuCompositionDoneTime);
1271 EXPECT_EQ(mFrames[1].mRefreshes[0].kPresentTime, outDisplayPresentTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001272 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDequeueReadyTime);
1273 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001274}
1275
1276// This test verifies the acquire fence recorded by the consumer is not sent
1277// back to the producer and the producer saves its own fence.
1278TEST_F(GetFrameTimestampsTest, QueueTimestampsNoSync) {
1279 enableFrameTimestamps();
Brian Anderson3da8d272016-07-28 16:20:47 -07001280
Brian Anderson3da8d272016-07-28 16:20:47 -07001281 // Dequeue and queue frame 1.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001282 const uint64_t fId1 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001283 dequeueAndQueue(0);
1284
1285 // Verify queue-related timestamps for f1 are available immediately in the
1286 // producer without asking the consumer again, even before signaling the
1287 // acquire fence.
1288 resetTimestamps();
1289 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001290 int result = native_window_get_frame_timestamps(mWindow.get(), fId1,
Brian Anderson3da8d272016-07-28 16:20:47 -07001291 &outRequestedPresentTime, &outAcquireTime, nullptr, nullptr,
Brian Anderson4e606e32017-03-16 15:34:57 -07001292 nullptr, nullptr, nullptr, nullptr, nullptr);
Brian Anderson3da8d272016-07-28 16:20:47 -07001293 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1294 EXPECT_EQ(NO_ERROR, result);
1295 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001296 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outAcquireTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001297
1298 // Signal acquire fences. Verify a sync call still isn't necessary.
1299 mFrames[0].signalQueueFences();
1300
1301 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001302 result = native_window_get_frame_timestamps(mWindow.get(), fId1,
Brian Anderson3da8d272016-07-28 16:20:47 -07001303 &outRequestedPresentTime, &outAcquireTime, nullptr, nullptr,
Brian Anderson4e606e32017-03-16 15:34:57 -07001304 nullptr, nullptr, nullptr, nullptr, nullptr);
Brian Anderson3da8d272016-07-28 16:20:47 -07001305 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1306 EXPECT_EQ(NO_ERROR, result);
1307 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1308 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
1309
1310 // Dequeue and queue frame 2.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001311 const uint64_t fId2 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001312 dequeueAndQueue(1);
1313
1314 // Verify queue-related timestamps for f2 are available immediately in the
1315 // producer without asking the consumer again, even before signaling the
1316 // acquire fence.
1317 resetTimestamps();
1318 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001319 result = native_window_get_frame_timestamps(mWindow.get(), fId2,
Brian Anderson3da8d272016-07-28 16:20:47 -07001320 &outRequestedPresentTime, &outAcquireTime, nullptr, nullptr,
Brian Anderson4e606e32017-03-16 15:34:57 -07001321 nullptr, nullptr, nullptr, nullptr, nullptr);
Brian Anderson3da8d272016-07-28 16:20:47 -07001322 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1323 EXPECT_EQ(NO_ERROR, result);
1324 EXPECT_EQ(mFrames[1].kRequestedPresentTime, outRequestedPresentTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001325 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outAcquireTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001326
1327 // Signal acquire fences. Verify a sync call still isn't necessary.
1328 mFrames[1].signalQueueFences();
1329
1330 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001331 result = native_window_get_frame_timestamps(mWindow.get(), fId2,
Brian Anderson3da8d272016-07-28 16:20:47 -07001332 &outRequestedPresentTime, &outAcquireTime, nullptr, nullptr,
Brian Anderson4e606e32017-03-16 15:34:57 -07001333 nullptr, nullptr, nullptr, nullptr, nullptr);
Brian Anderson3da8d272016-07-28 16:20:47 -07001334 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1335 EXPECT_EQ(NO_ERROR, result);
1336 EXPECT_EQ(mFrames[1].kRequestedPresentTime, outRequestedPresentTime);
1337 EXPECT_EQ(mFrames[1].kProducerAcquireTime, outAcquireTime);
1338}
1339
1340TEST_F(GetFrameTimestampsTest, ZeroRequestedTimestampsNoSync) {
1341 enableFrameTimestamps();
Brian Anderson3da8d272016-07-28 16:20:47 -07001342
1343 // Dequeue and queue frame 1.
1344 dequeueAndQueue(0);
1345 mFrames[0].signalQueueFences();
1346
1347 // Dequeue and queue frame 2.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001348 const uint64_t fId2 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001349 dequeueAndQueue(1);
1350 mFrames[1].signalQueueFences();
1351
1352 addFrameEvents(true, NO_FRAME_INDEX, 0);
1353 mFrames[0].signalRefreshFences();
1354 addFrameEvents(true, 0, 1);
1355 mFrames[0].signalReleaseFences();
1356 mFrames[1].signalRefreshFences();
1357
1358 // Verify a request for no timestamps doesn't result in a sync call.
Brian Anderson3da8d272016-07-28 16:20:47 -07001359 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001360 int result = native_window_get_frame_timestamps(mWindow.get(), fId2,
Brian Anderson6b376712017-04-04 10:51:39 -07001361 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
1362 nullptr, nullptr);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001363 EXPECT_EQ(NO_ERROR, result);
Brian Anderson3da8d272016-07-28 16:20:47 -07001364 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1365}
1366
1367// This test verifies that fences can signal and update timestamps producer
1368// side without an additional sync call to the consumer.
1369TEST_F(GetFrameTimestampsTest, FencesInProducerNoSync) {
1370 enableFrameTimestamps();
Brian Anderson3da8d272016-07-28 16:20:47 -07001371
1372 // Dequeue and queue frame 1.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001373 const uint64_t fId1 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001374 dequeueAndQueue(0);
1375 mFrames[0].signalQueueFences();
1376
1377 // Dequeue and queue frame 2.
1378 dequeueAndQueue(1);
1379 mFrames[1].signalQueueFences();
1380
1381 addFrameEvents(true, NO_FRAME_INDEX, 0);
1382 addFrameEvents(true, 0, 1);
1383
1384 // Verify available timestamps are correct for frame 1, before any
1385 // fence has been signaled.
1386 // Note: A sync call is necessary here since the events triggered by
1387 // addFrameEvents didn't get to piggyback on the earlier queues/dequeues.
Brian Anderson3da8d272016-07-28 16:20:47 -07001388 resetTimestamps();
1389 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001390 int result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001391 EXPECT_EQ(oldCount + 1, mFakeConsumer->mGetFrameTimestampsCount);
1392 EXPECT_EQ(NO_ERROR, result);
1393 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1394 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001395 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1396 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1397 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001398 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outGpuCompositionDoneTime);
1399 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001400 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001401 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001402
1403 // Verify available timestamps are correct for frame 1 again, before any
1404 // fence has been signaled.
1405 // This time a sync call should not be necessary.
Brian Anderson3da8d272016-07-28 16:20:47 -07001406 resetTimestamps();
1407 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001408 result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001409 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1410 EXPECT_EQ(NO_ERROR, result);
1411 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1412 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001413 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1414 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1415 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001416 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outGpuCompositionDoneTime);
1417 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001418 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001419 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001420
1421 // Signal the fences for frame 1.
1422 mFrames[0].signalRefreshFences();
1423 mFrames[0].signalReleaseFences();
1424
1425 // Verify all timestamps are available without a sync call.
Brian Anderson3da8d272016-07-28 16:20:47 -07001426 resetTimestamps();
1427 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001428 result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001429 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1430 EXPECT_EQ(NO_ERROR, result);
1431 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1432 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001433 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1434 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1435 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001436 EXPECT_EQ(mFrames[0].mRefreshes[0].kGpuCompositionDoneTime,
1437 outGpuCompositionDoneTime);
1438 EXPECT_EQ(mFrames[0].mRefreshes[0].kPresentTime, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001439 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001440 EXPECT_EQ(mFrames[0].kReleaseTime, outReleaseTime);
1441}
1442
1443// This test verifies that if the frame wasn't GPU composited but has a refresh
1444// event a sync call isn't made to get the GPU composite done time since it will
1445// never exist.
1446TEST_F(GetFrameTimestampsTest, NoGpuNoSync) {
1447 enableFrameTimestamps();
Brian Anderson3da8d272016-07-28 16:20:47 -07001448
Brian Anderson3da8d272016-07-28 16:20:47 -07001449 // Dequeue and queue frame 1.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001450 const uint64_t fId1 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001451 dequeueAndQueue(0);
1452 mFrames[0].signalQueueFences();
1453
1454 // Dequeue and queue frame 2.
1455 dequeueAndQueue(1);
1456 mFrames[1].signalQueueFences();
1457
1458 addFrameEvents(false, NO_FRAME_INDEX, 0);
1459 addFrameEvents(false, 0, 1);
1460
1461 // Verify available timestamps are correct for frame 1, before any
1462 // fence has been signaled.
1463 // Note: A sync call is necessary here since the events triggered by
1464 // addFrameEvents didn't get to piggyback on the earlier queues/dequeues.
1465 resetTimestamps();
1466 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001467 int result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001468 EXPECT_EQ(oldCount + 1, mFakeConsumer->mGetFrameTimestampsCount);
1469 EXPECT_EQ(NO_ERROR, result);
1470 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1471 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001472 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1473 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1474 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001475 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_INVALID, outGpuCompositionDoneTime);
1476 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001477 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001478 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001479
1480 // Signal the fences for frame 1.
1481 mFrames[0].signalRefreshFences();
1482 mFrames[0].signalReleaseFences();
1483
1484 // Verify all timestamps, except GPU composition, are available without a
1485 // sync call.
1486 resetTimestamps();
1487 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001488 result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001489 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1490 EXPECT_EQ(NO_ERROR, result);
1491 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1492 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001493 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1494 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1495 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001496 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_INVALID, outGpuCompositionDoneTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001497 EXPECT_EQ(mFrames[0].mRefreshes[0].kPresentTime, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001498 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001499 EXPECT_EQ(mFrames[0].kReleaseTime, outReleaseTime);
1500}
1501
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001502// This test verifies that if the certain timestamps can't possibly exist for
1503// the most recent frame, then a sync call is not done.
Brian Anderson6b376712017-04-04 10:51:39 -07001504TEST_F(GetFrameTimestampsTest, NoReleaseNoSync) {
Brian Anderson3da8d272016-07-28 16:20:47 -07001505 enableFrameTimestamps();
Brian Anderson3da8d272016-07-28 16:20:47 -07001506
1507 // Dequeue and queue frame 1.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001508 const uint64_t fId1 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001509 dequeueAndQueue(0);
1510 mFrames[0].signalQueueFences();
1511
1512 // Dequeue and queue frame 2.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001513 const uint64_t fId2 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001514 dequeueAndQueue(1);
1515 mFrames[1].signalQueueFences();
1516
1517 addFrameEvents(false, NO_FRAME_INDEX, 0);
1518 addFrameEvents(false, 0, 1);
1519
1520 // Verify available timestamps are correct for frame 1, before any
1521 // fence has been signaled.
1522 // Note: A sync call is necessary here since the events triggered by
1523 // addFrameEvents didn't get to piggyback on the earlier queues/dequeues.
Brian Anderson3da8d272016-07-28 16:20:47 -07001524 resetTimestamps();
1525 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001526 int result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001527 EXPECT_EQ(oldCount + 1, mFakeConsumer->mGetFrameTimestampsCount);
1528 EXPECT_EQ(NO_ERROR, result);
1529 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1530 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001531 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1532 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1533 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001534 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_INVALID, outGpuCompositionDoneTime);
1535 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001536 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001537 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001538
1539 mFrames[0].signalRefreshFences();
1540 mFrames[0].signalReleaseFences();
1541 mFrames[1].signalRefreshFences();
1542
Brian Anderson1049d1d2016-12-16 17:25:57 -08001543 // Verify querying for all timestmaps of f2 does not do a sync call. Even
Brian Anderson4e606e32017-03-16 15:34:57 -07001544 // though the lastRefresh, dequeueReady, and release times aren't
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001545 // available, a sync call should not occur because it's not possible for f2
1546 // to encounter the final value for those events until another frame is
1547 // queued.
Brian Anderson3da8d272016-07-28 16:20:47 -07001548 resetTimestamps();
1549 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001550 result = getAllFrameTimestamps(fId2);
Brian Anderson3da8d272016-07-28 16:20:47 -07001551 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1552 EXPECT_EQ(NO_ERROR, result);
1553 EXPECT_EQ(mFrames[1].kRequestedPresentTime, outRequestedPresentTime);
1554 EXPECT_EQ(mFrames[1].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001555 EXPECT_EQ(mFrames[1].kLatchTime, outLatchTime);
1556 EXPECT_EQ(mFrames[1].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1557 EXPECT_EQ(mFrames[1].mRefreshes[1].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001558 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_INVALID, outGpuCompositionDoneTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001559 EXPECT_EQ(mFrames[1].mRefreshes[0].kPresentTime, outDisplayPresentTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001560 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDequeueReadyTime);
1561 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001562}
1563
Brian Anderson6b376712017-04-04 10:51:39 -07001564// This test verifies there are no sync calls for present times
1565// when they aren't supported and that an error is returned.
1566
1567TEST_F(GetFrameTimestampsTest, PresentUnsupportedNoSync) {
1568 enableFrameTimestamps();
1569 mSurface->mFakeSurfaceComposer->setSupportsPresent(false);
1570
1571 // Dequeue and queue frame 1.
1572 const uint64_t fId1 = getNextFrameId();
1573 dequeueAndQueue(0);
1574
1575 // Verify a query for the Present times do not trigger a sync call if they
1576 // are not supported.
1577 resetTimestamps();
1578 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
1579 int result = native_window_get_frame_timestamps(mWindow.get(), fId1,
1580 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
1581 &outDisplayPresentTime, nullptr, nullptr);
1582 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1583 EXPECT_EQ(BAD_VALUE, result);
1584 EXPECT_EQ(-1, outDisplayPresentTime);
1585}
1586
Dan Stoza932f0082017-05-31 13:50:16 -07001587} // namespace android