blob: 45e95a593bd32854ed321900286454cb88fa7f61 [file] [log] [blame]
Jamie Gennis134f0422011-03-08 12:18:54 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Dan Stozac6f30bd2015-06-08 09:32:50 -070017#include "DummyConsumer.h"
18
Jamie Gennis134f0422011-03-08 12:18:54 -080019#include <gtest/gtest.h>
Jamie Gennis7a4d0df2011-03-09 17:05:02 -080020
Courtney Goeltzenleuchter6a570b62017-03-13 14:30:00 -060021#include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h>
Brian Anderson3da8d272016-07-28 16:20:47 -070022#include <binder/ProcessState.h>
Courtney Goeltzenleuchter6a570b62017-03-13 14:30:00 -060023#include <configstore/Utils.h>
Courtney Goeltzenleuchter1eb1b272017-02-02 16:51:06 -070024#include <cutils/properties.h>
25#include <gui/BufferItemConsumer.h>
Brian Anderson3da8d272016-07-28 16:20:47 -070026#include <gui/IDisplayEventConnection.h>
Yin-Chia Yeh1f2af5c2017-05-11 16:54:04 -070027#include <gui/IProducerListener.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080028#include <gui/ISurfaceComposer.h>
29#include <gui/Surface.h>
30#include <gui/SurfaceComposerClient.h>
Brian Anderson3da8d272016-07-28 16:20:47 -070031#include <private/gui/ComposerService.h>
Dan Stozac1879002014-05-22 15:59:05 -070032#include <ui/Rect.h>
Jamie Gennis134f0422011-03-08 12:18:54 -080033#include <utils/String8.h>
34
Brian Anderson3da8d272016-07-28 16:20:47 -070035#include <limits>
Kalle Raita643f0942016-12-07 09:20:14 -080036#include <thread>
37
Jamie Gennis134f0422011-03-08 12:18:54 -080038namespace android {
39
Kalle Raita643f0942016-12-07 09:20:14 -080040using namespace std::chrono_literals;
Courtney Goeltzenleuchter6a570b62017-03-13 14:30:00 -060041// retrieve wide-color and hdr settings from configstore
42using namespace android::hardware::configstore;
43using namespace android::hardware::configstore::V1_0;
44
45static bool hasWideColorDisplay =
46 getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasWideColorDisplay>(false);
Kalle Raita643f0942016-12-07 09:20:14 -080047
Brian Anderson3da8d272016-07-28 16:20:47 -070048class FakeSurfaceComposer;
49class FakeProducerFrameEventHistory;
50
51static constexpr uint64_t NO_FRAME_INDEX = std::numeric_limits<uint64_t>::max();
52
Jamie Gennis134f0422011-03-08 12:18:54 -080053class SurfaceTest : public ::testing::Test {
54protected:
Mathias Agopian7c1a4872013-03-20 15:56:04 -070055
56 SurfaceTest() {
57 ProcessState::self()->startThreadPool();
58 }
59
Jamie Gennis134f0422011-03-08 12:18:54 -080060 virtual void SetUp() {
Jamie Gennis7a4d0df2011-03-09 17:05:02 -080061 mComposerClient = new SurfaceComposerClient;
Jamie Gennis134f0422011-03-08 12:18:54 -080062 ASSERT_EQ(NO_ERROR, mComposerClient->initCheck());
63
Brian Andersond0010582017-03-07 13:20:31 -080064 // TODO(brianderson): The following sometimes fails and is a source of
65 // test flakiness.
Jamie Gennisfc850122011-04-25 16:40:05 -070066 mSurfaceControl = mComposerClient->createSurface(
Jeff Brown9d4e3d22012-08-24 20:00:51 -070067 String8("Test Surface"), 32, 32, PIXEL_FORMAT_RGBA_8888, 0);
Jamie Gennis134f0422011-03-08 12:18:54 -080068
69 ASSERT_TRUE(mSurfaceControl != NULL);
70 ASSERT_TRUE(mSurfaceControl->isValid());
71
Mathias Agopian698c0872011-06-28 19:09:31 -070072 SurfaceComposerClient::openGlobalTransaction();
Mathias Agopian9303eee2011-07-01 15:27:27 -070073 ASSERT_EQ(NO_ERROR, mSurfaceControl->setLayer(0x7fffffff));
Jamie Gennis134f0422011-03-08 12:18:54 -080074 ASSERT_EQ(NO_ERROR, mSurfaceControl->show());
Mathias Agopian698c0872011-06-28 19:09:31 -070075 SurfaceComposerClient::closeGlobalTransaction();
Jamie Gennis134f0422011-03-08 12:18:54 -080076
77 mSurface = mSurfaceControl->getSurface();
78 ASSERT_TRUE(mSurface != NULL);
79 }
80
81 virtual void TearDown() {
82 mComposerClient->dispose();
83 }
84
85 sp<Surface> mSurface;
86 sp<SurfaceComposerClient> mComposerClient;
87 sp<SurfaceControl> mSurfaceControl;
88};
89
90TEST_F(SurfaceTest, QueuesToWindowComposerIsTrueWhenVisible) {
91 sp<ANativeWindow> anw(mSurface);
92 int result = -123;
93 int err = anw->query(anw.get(), NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER,
94 &result);
95 EXPECT_EQ(NO_ERROR, err);
96 EXPECT_EQ(1, result);
97}
98
99TEST_F(SurfaceTest, QueuesToWindowComposerIsTrueWhenPurgatorized) {
100 mSurfaceControl.clear();
Kalle Raita643f0942016-12-07 09:20:14 -0800101 // Wait for the async clean-up to complete.
102 std::this_thread::sleep_for(50ms);
Jamie Gennis134f0422011-03-08 12:18:54 -0800103
104 sp<ANativeWindow> anw(mSurface);
105 int result = -123;
106 int err = anw->query(anw.get(), NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER,
107 &result);
108 EXPECT_EQ(NO_ERROR, err);
109 EXPECT_EQ(1, result);
110}
111
Jamie Gennis7a4d0df2011-03-09 17:05:02 -0800112// This test probably doesn't belong here.
Jamie Gennisc901ca02011-10-11 16:02:31 -0700113TEST_F(SurfaceTest, ScreenshotsOfProtectedBuffersSucceed) {
Jamie Gennis7a4d0df2011-03-09 17:05:02 -0800114 sp<ANativeWindow> anw(mSurface);
115
116 // Verify the screenshot works with no protected buffers.
Dan Stoza5603a2f2014-04-07 13:41:37 -0700117 sp<IGraphicBufferProducer> producer;
118 sp<IGraphicBufferConsumer> consumer;
119 BufferQueue::createBufferQueue(&producer, &consumer);
120 sp<CpuConsumer> cpuConsumer = new CpuConsumer(consumer, 1);
Jamie Gennis7a4d0df2011-03-09 17:05:02 -0800121 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
Brian Anderson3da8d272016-07-28 16:20:47 -0700122 sp<IBinder> display(sf->getBuiltInDisplay(
123 ISurfaceComposer::eDisplayIdMain));
Dan Stozac1879002014-05-22 15:59:05 -0700124 ASSERT_EQ(NO_ERROR, sf->captureScreen(display, producer, Rect(),
Dan Stoza8d759962014-02-19 18:35:30 -0800125 64, 64, 0, 0x7fffffff, false));
Jamie Gennis7a4d0df2011-03-09 17:05:02 -0800126
Pablo Ceballos583b1b32015-09-03 18:23:52 -0700127 ASSERT_EQ(NO_ERROR, native_window_api_connect(anw.get(),
128 NATIVE_WINDOW_API_CPU));
Jamie Gennis7a4d0df2011-03-09 17:05:02 -0800129 // Set the PROTECTED usage bit and verify that the screenshot fails. Note
130 // that we need to dequeue a buffer in order for it to actually get
131 // allocated in SurfaceFlinger.
132 ASSERT_EQ(NO_ERROR, native_window_set_usage(anw.get(),
133 GRALLOC_USAGE_PROTECTED));
134 ASSERT_EQ(NO_ERROR, native_window_set_buffer_count(anw.get(), 3));
Iliyan Malchev697526b2011-05-01 11:33:26 -0700135 ANativeWindowBuffer* buf = 0;
Mathias Agopian9303eee2011-07-01 15:27:27 -0700136
Jamie Gennisd8e812c2012-06-13 16:32:25 -0700137 status_t err = native_window_dequeue_buffer_and_wait(anw.get(), &buf);
Mathias Agopian9303eee2011-07-01 15:27:27 -0700138 if (err) {
139 // we could fail if GRALLOC_USAGE_PROTECTED is not supported.
140 // that's okay as long as this is the reason for the failure.
141 // try again without the GRALLOC_USAGE_PROTECTED bit.
142 ASSERT_EQ(NO_ERROR, native_window_set_usage(anw.get(), 0));
Jamie Gennisd8e812c2012-06-13 16:32:25 -0700143 ASSERT_EQ(NO_ERROR, native_window_dequeue_buffer_and_wait(anw.get(),
144 &buf));
Mathias Agopian9303eee2011-07-01 15:27:27 -0700145 return;
146 }
Jamie Gennisd8e812c2012-06-13 16:32:25 -0700147 ASSERT_EQ(NO_ERROR, anw->cancelBuffer(anw.get(), buf, -1));
Mathias Agopian9303eee2011-07-01 15:27:27 -0700148
Jamie Gennis7a4d0df2011-03-09 17:05:02 -0800149 for (int i = 0; i < 4; i++) {
150 // Loop to make sure SurfaceFlinger has retired a protected buffer.
Jamie Gennisd8e812c2012-06-13 16:32:25 -0700151 ASSERT_EQ(NO_ERROR, native_window_dequeue_buffer_and_wait(anw.get(),
152 &buf));
153 ASSERT_EQ(NO_ERROR, anw->queueBuffer(anw.get(), buf, -1));
Jamie Gennis7a4d0df2011-03-09 17:05:02 -0800154 }
Dan Stozac1879002014-05-22 15:59:05 -0700155 ASSERT_EQ(NO_ERROR, sf->captureScreen(display, producer, Rect(),
Dan Stoza8d759962014-02-19 18:35:30 -0800156 64, 64, 0, 0x7fffffff, false));
Jamie Gennis7a4d0df2011-03-09 17:05:02 -0800157}
158
Jamie Gennis391bbe22011-03-14 15:00:06 -0700159TEST_F(SurfaceTest, ConcreteTypeIsSurface) {
160 sp<ANativeWindow> anw(mSurface);
161 int result = -123;
162 int err = anw->query(anw.get(), NATIVE_WINDOW_CONCRETE_TYPE, &result);
163 EXPECT_EQ(NO_ERROR, err);
164 EXPECT_EQ(NATIVE_WINDOW_SURFACE, result);
165}
166
Craig Donner6ebc46a2016-10-21 15:23:44 -0700167TEST_F(SurfaceTest, LayerCountIsOne) {
168 sp<ANativeWindow> anw(mSurface);
169 int result = -123;
170 int err = anw->query(anw.get(), NATIVE_WINDOW_LAYER_COUNT, &result);
171 EXPECT_EQ(NO_ERROR, err);
172 EXPECT_EQ(1, result);
173}
174
Eino-Ville Talvalaf7c60872013-07-30 14:05:02 -0700175TEST_F(SurfaceTest, QueryConsumerUsage) {
176 const int TEST_USAGE_FLAGS =
177 GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_HW_RENDER;
Dan Stoza5603a2f2014-04-07 13:41:37 -0700178 sp<IGraphicBufferProducer> producer;
179 sp<IGraphicBufferConsumer> consumer;
180 BufferQueue::createBufferQueue(&producer, &consumer);
181 sp<BufferItemConsumer> c = new BufferItemConsumer(consumer,
Eino-Ville Talvalaf7c60872013-07-30 14:05:02 -0700182 TEST_USAGE_FLAGS);
Dan Stoza5603a2f2014-04-07 13:41:37 -0700183 sp<Surface> s = new Surface(producer);
Eino-Ville Talvalaf7c60872013-07-30 14:05:02 -0700184
185 sp<ANativeWindow> anw(s);
186
187 int flags = -1;
188 int err = anw->query(anw.get(), NATIVE_WINDOW_CONSUMER_USAGE_BITS, &flags);
189
190 ASSERT_EQ(NO_ERROR, err);
191 ASSERT_EQ(TEST_USAGE_FLAGS, flags);
192}
193
Eino-Ville Talvala5b75a512015-02-19 16:10:43 -0800194TEST_F(SurfaceTest, QueryDefaultBuffersDataSpace) {
195 const android_dataspace TEST_DATASPACE = HAL_DATASPACE_SRGB;
196 sp<IGraphicBufferProducer> producer;
197 sp<IGraphicBufferConsumer> consumer;
198 BufferQueue::createBufferQueue(&producer, &consumer);
199 sp<CpuConsumer> cpuConsumer = new CpuConsumer(consumer, 1);
200
201 cpuConsumer->setDefaultBufferDataSpace(TEST_DATASPACE);
202
203 sp<Surface> s = new Surface(producer);
204
205 sp<ANativeWindow> anw(s);
206
207 android_dataspace dataSpace;
208
209 int err = anw->query(anw.get(), NATIVE_WINDOW_DEFAULT_DATASPACE,
210 reinterpret_cast<int*>(&dataSpace));
211
212 ASSERT_EQ(NO_ERROR, err);
213 ASSERT_EQ(TEST_DATASPACE, dataSpace);
214}
215
Dan Stoza812ed062015-06-02 15:45:22 -0700216TEST_F(SurfaceTest, SettingGenerationNumber) {
217 sp<IGraphicBufferProducer> producer;
218 sp<IGraphicBufferConsumer> consumer;
219 BufferQueue::createBufferQueue(&producer, &consumer);
220 sp<CpuConsumer> cpuConsumer = new CpuConsumer(consumer, 1);
221 sp<Surface> surface = new Surface(producer);
222 sp<ANativeWindow> window(surface);
223
224 // Allocate a buffer with a generation number of 0
225 ANativeWindowBuffer* buffer;
226 int fenceFd;
Pablo Ceballos583b1b32015-09-03 18:23:52 -0700227 ASSERT_EQ(NO_ERROR, native_window_api_connect(window.get(),
228 NATIVE_WINDOW_API_CPU));
Dan Stoza812ed062015-06-02 15:45:22 -0700229 ASSERT_EQ(NO_ERROR, window->dequeueBuffer(window.get(), &buffer, &fenceFd));
230 ASSERT_EQ(NO_ERROR, window->cancelBuffer(window.get(), buffer, fenceFd));
231
232 // Detach the buffer and check its generation number
233 sp<GraphicBuffer> graphicBuffer;
234 sp<Fence> fence;
235 ASSERT_EQ(NO_ERROR, surface->detachNextBuffer(&graphicBuffer, &fence));
236 ASSERT_EQ(0U, graphicBuffer->getGenerationNumber());
237
238 ASSERT_EQ(NO_ERROR, surface->setGenerationNumber(1));
239 buffer = static_cast<ANativeWindowBuffer*>(graphicBuffer.get());
240
241 // This should change the generation number of the GraphicBuffer
242 ASSERT_EQ(NO_ERROR, surface->attachBuffer(buffer));
243
244 // Check that the new generation number sticks with the buffer
245 ASSERT_EQ(NO_ERROR, window->cancelBuffer(window.get(), buffer, -1));
246 ASSERT_EQ(NO_ERROR, window->dequeueBuffer(window.get(), &buffer, &fenceFd));
247 graphicBuffer = static_cast<GraphicBuffer*>(buffer);
248 ASSERT_EQ(1U, graphicBuffer->getGenerationNumber());
249}
250
Dan Stozac6f30bd2015-06-08 09:32:50 -0700251TEST_F(SurfaceTest, GetConsumerName) {
252 sp<IGraphicBufferProducer> producer;
253 sp<IGraphicBufferConsumer> consumer;
254 BufferQueue::createBufferQueue(&producer, &consumer);
255
256 sp<DummyConsumer> dummyConsumer(new DummyConsumer);
257 consumer->consumerConnect(dummyConsumer, false);
258 consumer->setConsumerName(String8("TestConsumer"));
259
260 sp<Surface> surface = new Surface(producer);
261 sp<ANativeWindow> window(surface);
262 native_window_api_connect(window.get(), NATIVE_WINDOW_API_CPU);
263
264 EXPECT_STREQ("TestConsumer", surface->getConsumerName().string());
265}
266
Courtney Goeltzenleuchter1eb1b272017-02-02 16:51:06 -0700267TEST_F(SurfaceTest, GetWideColorSupport) {
268 sp<IGraphicBufferProducer> producer;
269 sp<IGraphicBufferConsumer> consumer;
270 BufferQueue::createBufferQueue(&producer, &consumer);
271
272 sp<DummyConsumer> dummyConsumer(new DummyConsumer);
273 consumer->consumerConnect(dummyConsumer, false);
274 consumer->setConsumerName(String8("TestConsumer"));
275
276 sp<Surface> surface = new Surface(producer);
277 sp<ANativeWindow> window(surface);
278 native_window_api_connect(window.get(), NATIVE_WINDOW_API_CPU);
279
280 bool supported;
281 surface->getWideColorSupport(&supported);
282
Courtney Goeltzenleuchter6a570b62017-03-13 14:30:00 -0600283 // NOTE: This test assumes that device that supports
284 // wide-color (as indicated by BoardConfig) must also
285 // have a wide-color primary display.
286 // That assumption allows this test to cover devices
287 // that advertised a wide-color color mode without
288 // actually supporting wide-color to pass this test
289 // as well as the case of a device that does support
290 // wide-color (via BoardConfig) and has a wide-color
291 // primary display.
292 // NOT covered at this time is a device that supports
293 // wide color in the BoardConfig but does not support
294 // a wide-color color mode on the primary display.
295 ASSERT_EQ(hasWideColorDisplay, supported);
Courtney Goeltzenleuchter1eb1b272017-02-02 16:51:06 -0700296}
297
Pablo Ceballos789a0c82016-02-05 13:39:27 -0800298TEST_F(SurfaceTest, DynamicSetBufferCount) {
299 sp<IGraphicBufferProducer> producer;
300 sp<IGraphicBufferConsumer> consumer;
301 BufferQueue::createBufferQueue(&producer, &consumer);
302
303 sp<DummyConsumer> dummyConsumer(new DummyConsumer);
304 consumer->consumerConnect(dummyConsumer, false);
305 consumer->setConsumerName(String8("TestConsumer"));
306
307 sp<Surface> surface = new Surface(producer);
308 sp<ANativeWindow> window(surface);
309
310 ASSERT_EQ(NO_ERROR, native_window_api_connect(window.get(),
311 NATIVE_WINDOW_API_CPU));
312 native_window_set_buffer_count(window.get(), 4);
313
314 int fence;
315 ANativeWindowBuffer* buffer;
316 ASSERT_EQ(NO_ERROR, window->dequeueBuffer(window.get(), &buffer, &fence));
317 native_window_set_buffer_count(window.get(), 3);
318 ASSERT_EQ(NO_ERROR, window->queueBuffer(window.get(), buffer, fence));
319 native_window_set_buffer_count(window.get(), 2);
320 ASSERT_EQ(NO_ERROR, window->dequeueBuffer(window.get(), &buffer, &fence));
321 ASSERT_EQ(NO_ERROR, window->queueBuffer(window.get(), buffer, fence));
322}
323
Yin-Chia Yeh1f2af5c2017-05-11 16:54:04 -0700324TEST_F(SurfaceTest, GetAndFlushRemovedBuffers) {
325 sp<IGraphicBufferProducer> producer;
326 sp<IGraphicBufferConsumer> consumer;
327 BufferQueue::createBufferQueue(&producer, &consumer);
328
329 sp<DummyConsumer> dummyConsumer(new DummyConsumer);
330 consumer->consumerConnect(dummyConsumer, false);
331 consumer->setConsumerName(String8("TestConsumer"));
332
333 sp<Surface> surface = new Surface(producer);
334 sp<ANativeWindow> window(surface);
335 sp<DummyProducerListener> listener = new DummyProducerListener();
336 ASSERT_EQ(OK, surface->connect(
337 NATIVE_WINDOW_API_CPU,
338 /*listener*/listener,
339 /*reportBufferRemoval*/true));
340 const int BUFFER_COUNT = 4;
341 ASSERT_EQ(NO_ERROR, native_window_set_buffer_count(window.get(), BUFFER_COUNT));
342
343 sp<GraphicBuffer> detachedBuffer;
344 sp<Fence> outFence;
345 int fences[BUFFER_COUNT];
346 ANativeWindowBuffer* buffers[BUFFER_COUNT];
347 // Allocate buffers because detachNextBuffer requires allocated buffers
348 for (int i = 0; i < BUFFER_COUNT; i++) {
349 ASSERT_EQ(NO_ERROR, window->dequeueBuffer(window.get(), &buffers[i], &fences[i]));
350 }
351 for (int i = 0; i < BUFFER_COUNT; i++) {
352 ASSERT_EQ(NO_ERROR, window->cancelBuffer(window.get(), buffers[i], fences[i]));
353 }
354
355 // Test detached buffer is correctly reported
356 ASSERT_EQ(NO_ERROR, surface->detachNextBuffer(&detachedBuffer, &outFence));
357 std::vector<sp<GraphicBuffer>> removedBuffers;
358 ASSERT_EQ(OK, surface->getAndFlushRemovedBuffers(&removedBuffers));
359 ASSERT_EQ(1u, removedBuffers.size());
360 ASSERT_EQ(detachedBuffer->handle, removedBuffers.at(0)->handle);
361 // Test the list is flushed one getAndFlushRemovedBuffers returns
362 ASSERT_EQ(OK, surface->getAndFlushRemovedBuffers(&removedBuffers));
363 ASSERT_EQ(0u, removedBuffers.size());
364
365
366 // Test removed buffer list is cleanup after next dequeueBuffer call
367 ASSERT_EQ(NO_ERROR, surface->detachNextBuffer(&detachedBuffer, &outFence));
368 ASSERT_EQ(NO_ERROR, window->dequeueBuffer(window.get(), &buffers[0], &fences[0]));
369 ASSERT_EQ(OK, surface->getAndFlushRemovedBuffers(&removedBuffers));
370 ASSERT_EQ(0u, removedBuffers.size());
371 ASSERT_EQ(NO_ERROR, window->cancelBuffer(window.get(), buffers[0], fences[0]));
372
373 // Test removed buffer list is cleanup after next detachNextBuffer call
374 ASSERT_EQ(NO_ERROR, surface->detachNextBuffer(&detachedBuffer, &outFence));
375 ASSERT_EQ(NO_ERROR, surface->detachNextBuffer(&detachedBuffer, &outFence));
376 ASSERT_EQ(OK, surface->getAndFlushRemovedBuffers(&removedBuffers));
377 ASSERT_EQ(1u, removedBuffers.size());
378 ASSERT_EQ(detachedBuffer->handle, removedBuffers.at(0)->handle);
379
380 // Re-allocate buffers since all buffers are detached up to now
381 for (int i = 0; i < BUFFER_COUNT; i++) {
382 ASSERT_EQ(NO_ERROR, window->dequeueBuffer(window.get(), &buffers[i], &fences[i]));
383 }
384 for (int i = 0; i < BUFFER_COUNT; i++) {
385 ASSERT_EQ(NO_ERROR, window->cancelBuffer(window.get(), buffers[i], fences[i]));
386 }
387
388 ASSERT_EQ(NO_ERROR, surface->detachNextBuffer(&detachedBuffer, &outFence));
389 ASSERT_EQ(NO_ERROR, surface->attachBuffer(detachedBuffer.get()));
390 ASSERT_EQ(OK, surface->getAndFlushRemovedBuffers(&removedBuffers));
391 // Depends on which slot GraphicBufferProducer impl pick, the attach call might
392 // get 0 or 1 buffer removed.
393 ASSERT_LE(removedBuffers.size(), 1u);
394}
Brian Anderson3da8d272016-07-28 16:20:47 -0700395
Dan Stoza932f0082017-05-31 13:50:16 -0700396TEST_F(SurfaceTest, TestGetLastDequeueStartTime) {
397 sp<ANativeWindow> anw(mSurface);
398 ASSERT_EQ(NO_ERROR, native_window_api_connect(anw.get(), NATIVE_WINDOW_API_CPU));
399
400 ANativeWindowBuffer* buffer = nullptr;
401 int32_t fenceFd = -1;
402
403 nsecs_t before = systemTime(CLOCK_MONOTONIC);
404 anw->dequeueBuffer(anw.get(), &buffer, &fenceFd);
405 nsecs_t after = systemTime(CLOCK_MONOTONIC);
406
407 nsecs_t lastDequeueTime = mSurface->getLastDequeueStartTime();
408 ASSERT_LE(before, lastDequeueTime);
409 ASSERT_GE(after, lastDequeueTime);
410}
411
Brian Anderson3da8d272016-07-28 16:20:47 -0700412class FakeConsumer : public BnConsumerListener {
413public:
414 void onFrameAvailable(const BufferItem& /*item*/) override {}
415 void onBuffersReleased() override {}
416 void onSidebandStreamChanged() override {}
417
418 void addAndGetFrameTimestamps(
419 const NewFrameEventsEntry* newTimestamps,
420 FrameEventHistoryDelta* outDelta) override {
421 if (newTimestamps) {
422 if (mGetFrameTimestampsEnabled) {
423 EXPECT_GT(mNewFrameEntryOverride.frameNumber, 0u) <<
424 "Test should set mNewFrameEntryOverride before queuing "
425 "a frame.";
426 EXPECT_EQ(newTimestamps->frameNumber,
427 mNewFrameEntryOverride.frameNumber) <<
428 "Test attempting to add NewFrameEntryOverride with "
429 "incorrect frame number.";
430 mFrameEventHistory.addQueue(mNewFrameEntryOverride);
431 mNewFrameEntryOverride.frameNumber = 0;
432 }
433 mAddFrameTimestampsCount++;
434 mLastAddedFrameNumber = newTimestamps->frameNumber;
435 }
436 if (outDelta) {
437 mFrameEventHistory.getAndResetDelta(outDelta);
438 mGetFrameTimestampsCount++;
439 }
440 mAddAndGetFrameTimestampsCallCount++;
441 }
442
443 bool mGetFrameTimestampsEnabled = false;
444
445 ConsumerFrameEventHistory mFrameEventHistory;
446 int mAddAndGetFrameTimestampsCallCount = 0;
447 int mAddFrameTimestampsCount = 0;
448 int mGetFrameTimestampsCount = 0;
449 uint64_t mLastAddedFrameNumber = NO_FRAME_INDEX;
450
451 NewFrameEventsEntry mNewFrameEntryOverride = { 0, 0, 0, nullptr };
452};
453
454
455class FakeSurfaceComposer : public ISurfaceComposer{
456public:
457 ~FakeSurfaceComposer() override {}
458
Brian Anderson6b376712017-04-04 10:51:39 -0700459 void setSupportsPresent(bool supportsPresent) {
460 mSupportsPresent = supportsPresent;
461 }
462
Brian Anderson3da8d272016-07-28 16:20:47 -0700463 sp<ISurfaceComposerClient> createConnection() override { return nullptr; }
Robert Carr1db73f62016-12-21 12:58:51 -0800464 sp<ISurfaceComposerClient> createScopedConnection(
465 const sp<IGraphicBufferProducer>& /* parent */) override {
466 return nullptr;
467 }
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700468 sp<IDisplayEventConnection> createDisplayEventConnection(ISurfaceComposer::VsyncSource)
469 override {
Brian Anderson3da8d272016-07-28 16:20:47 -0700470 return nullptr;
471 }
472 sp<IBinder> createDisplay(const String8& /*displayName*/,
473 bool /*secure*/) override { return nullptr; }
474 void destroyDisplay(const sp<IBinder>& /*display */) override {}
475 sp<IBinder> getBuiltInDisplay(int32_t /*id*/) override { return nullptr; }
476 void setTransactionState(const Vector<ComposerState>& /*state*/,
477 const Vector<DisplayState>& /*displays*/, uint32_t /*flags*/)
478 override {}
479 void bootFinished() override {}
480 bool authenticateSurfaceTexture(
481 const sp<IGraphicBufferProducer>& /*surface*/) const override {
482 return false;
483 }
Brian Anderson6b376712017-04-04 10:51:39 -0700484
485 status_t getSupportedFrameTimestamps(std::vector<FrameEvent>* outSupported)
486 const override {
487 *outSupported = {
488 FrameEvent::REQUESTED_PRESENT,
489 FrameEvent::ACQUIRE,
490 FrameEvent::LATCH,
491 FrameEvent::FIRST_REFRESH_START,
492 FrameEvent::LAST_REFRESH_START,
493 FrameEvent::GPU_COMPOSITION_DONE,
494 FrameEvent::DEQUEUE_READY,
495 FrameEvent::RELEASE
496 };
497 if (mSupportsPresent) {
498 outSupported->push_back(
499 FrameEvent::DISPLAY_PRESENT);
500 }
501 return NO_ERROR;
502 }
503
Brian Anderson3da8d272016-07-28 16:20:47 -0700504 void setPowerMode(const sp<IBinder>& /*display*/, int /*mode*/) override {}
505 status_t getDisplayConfigs(const sp<IBinder>& /*display*/,
506 Vector<DisplayInfo>* /*configs*/) override { return NO_ERROR; }
507 status_t getDisplayStats(const sp<IBinder>& /*display*/,
508 DisplayStatInfo* /*stats*/) override { return NO_ERROR; }
509 int getActiveConfig(const sp<IBinder>& /*display*/) override { return 0; }
510 status_t setActiveConfig(const sp<IBinder>& /*display*/, int /*id*/)
511 override {
512 return NO_ERROR;
513 }
514 status_t getDisplayColorModes(const sp<IBinder>& /*display*/,
515 Vector<android_color_mode_t>* /*outColorModes*/) override {
516 return NO_ERROR;
517 }
518 android_color_mode_t getActiveColorMode(const sp<IBinder>& /*display*/)
519 override {
520 return HAL_COLOR_MODE_NATIVE;
521 }
522 status_t setActiveColorMode(const sp<IBinder>& /*display*/,
523 android_color_mode_t /*colorMode*/) override { return NO_ERROR; }
524 status_t captureScreen(const sp<IBinder>& /*display*/,
525 const sp<IGraphicBufferProducer>& /*producer*/,
526 Rect /*sourceCrop*/, uint32_t /*reqWidth*/, uint32_t /*reqHeight*/,
Robert Carrae060832016-11-28 10:51:00 -0800527 int32_t /*minLayerZ*/, int32_t /*maxLayerZ*/,
Brian Anderson3da8d272016-07-28 16:20:47 -0700528 bool /*useIdentityTransform*/,
529 Rotation /*rotation*/) override { return NO_ERROR; }
530 status_t clearAnimationFrameStats() override { return NO_ERROR; }
531 status_t getAnimationFrameStats(FrameStats* /*outStats*/) const override {
532 return NO_ERROR;
533 }
534 status_t getHdrCapabilities(const sp<IBinder>& /*display*/,
535 HdrCapabilities* /*outCapabilities*/) const override {
536 return NO_ERROR;
537 }
538 status_t enableVSyncInjections(bool /*enable*/) override {
539 return NO_ERROR;
540 }
541 status_t injectVSync(nsecs_t /*when*/) override { return NO_ERROR; }
Kalle Raitaa099a242017-01-11 11:17:29 -0800542 status_t getLayerDebugInfo(std::vector<LayerDebugInfo>* /*layers*/) const override {
543 return NO_ERROR;
544 }
Brian Anderson3da8d272016-07-28 16:20:47 -0700545
546protected:
547 IBinder* onAsBinder() override { return nullptr; }
548
549private:
550 bool mSupportsPresent{true};
Brian Anderson3da8d272016-07-28 16:20:47 -0700551};
552
553class FakeProducerFrameEventHistory : public ProducerFrameEventHistory {
554public:
555 FakeProducerFrameEventHistory(FenceToFenceTimeMap* fenceMap)
556 : mFenceMap(fenceMap) {}
557
558 ~FakeProducerFrameEventHistory() {}
559
560 void updateAcquireFence(uint64_t frameNumber,
561 std::shared_ptr<FenceTime>&& acquire) override {
562 // Verify the acquire fence being added isn't the one from the consumer.
563 EXPECT_NE(mConsumerAcquireFence, acquire);
564 // Override the fence, so we can verify this was called by the
565 // producer after the frame is queued.
566 ProducerFrameEventHistory::updateAcquireFence(frameNumber,
567 std::shared_ptr<FenceTime>(mAcquireFenceOverride));
568 }
569
570 void setAcquireFenceOverride(
571 const std::shared_ptr<FenceTime>& acquireFenceOverride,
572 const std::shared_ptr<FenceTime>& consumerAcquireFence) {
573 mAcquireFenceOverride = acquireFenceOverride;
574 mConsumerAcquireFence = consumerAcquireFence;
575 }
576
577protected:
578 std::shared_ptr<FenceTime> createFenceTime(const sp<Fence>& fence)
579 const override {
580 return mFenceMap->createFenceTimeForTest(fence);
581 }
582
583 FenceToFenceTimeMap* mFenceMap{nullptr};
584
585 std::shared_ptr<FenceTime> mAcquireFenceOverride{FenceTime::NO_FENCE};
586 std::shared_ptr<FenceTime> mConsumerAcquireFence{FenceTime::NO_FENCE};
587};
588
589
590class TestSurface : public Surface {
591public:
592 TestSurface(const sp<IGraphicBufferProducer>& bufferProducer,
593 FenceToFenceTimeMap* fenceMap)
594 : Surface(bufferProducer),
595 mFakeSurfaceComposer(new FakeSurfaceComposer) {
596 mFakeFrameEventHistory = new FakeProducerFrameEventHistory(fenceMap);
597 mFrameEventHistory.reset(mFakeFrameEventHistory);
598 }
599
600 ~TestSurface() override {}
601
602 sp<ISurfaceComposer> composerService() const override {
603 return mFakeSurfaceComposer;
604 }
605
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800606 nsecs_t now() const override {
607 return mNow;
608 }
609
610 void setNow(nsecs_t now) {
611 mNow = now;
612 }
613
Brian Anderson3da8d272016-07-28 16:20:47 -0700614public:
615 sp<FakeSurfaceComposer> mFakeSurfaceComposer;
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800616 nsecs_t mNow = 0;
Brian Anderson3da8d272016-07-28 16:20:47 -0700617
618 // mFrameEventHistory owns the instance of FakeProducerFrameEventHistory,
619 // but this raw pointer gives access to test functionality.
620 FakeProducerFrameEventHistory* mFakeFrameEventHistory;
621};
622
623
Brian Andersond0010582017-03-07 13:20:31 -0800624class GetFrameTimestampsTest : public ::testing::Test {
Brian Anderson3da8d272016-07-28 16:20:47 -0700625protected:
626 struct FenceAndFenceTime {
627 explicit FenceAndFenceTime(FenceToFenceTimeMap& fenceMap)
628 : mFence(new Fence),
629 mFenceTime(fenceMap.createFenceTimeForTest(mFence)) {}
630 sp<Fence> mFence { nullptr };
631 std::shared_ptr<FenceTime> mFenceTime { nullptr };
632 };
633
634 struct RefreshEvents {
635 RefreshEvents(FenceToFenceTimeMap& fenceMap, nsecs_t refreshStart)
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800636 : mFenceMap(fenceMap),
637 kCompositorTiming(
638 {refreshStart, refreshStart + 1, refreshStart + 2 }),
639 kStartTime(refreshStart + 3),
640 kGpuCompositionDoneTime(refreshStart + 4),
641 kPresentTime(refreshStart + 5) {}
Brian Anderson3da8d272016-07-28 16:20:47 -0700642
643 void signalPostCompositeFences() {
644 mFenceMap.signalAllForTest(
645 mGpuCompositionDone.mFence, kGpuCompositionDoneTime);
646 mFenceMap.signalAllForTest(mPresent.mFence, kPresentTime);
647 }
648
649 FenceToFenceTimeMap& mFenceMap;
650
651 FenceAndFenceTime mGpuCompositionDone { mFenceMap };
652 FenceAndFenceTime mPresent { mFenceMap };
653
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800654 const CompositorTiming kCompositorTiming;
655
Brian Anderson3da8d272016-07-28 16:20:47 -0700656 const nsecs_t kStartTime;
657 const nsecs_t kGpuCompositionDoneTime;
658 const nsecs_t kPresentTime;
659 };
660
661 struct FrameEvents {
662 FrameEvents(FenceToFenceTimeMap& fenceMap, nsecs_t frameStartTime)
663 : mFenceMap(fenceMap),
664 kPostedTime(frameStartTime + 100),
665 kRequestedPresentTime(frameStartTime + 200),
666 kProducerAcquireTime(frameStartTime + 300),
667 kConsumerAcquireTime(frameStartTime + 301),
668 kLatchTime(frameStartTime + 500),
Brian Andersonf6386862016-10-31 16:34:13 -0700669 kDequeueReadyTime(frameStartTime + 600),
Brian Anderson4e606e32017-03-16 15:34:57 -0700670 kReleaseTime(frameStartTime + 700),
Brian Anderson3da8d272016-07-28 16:20:47 -0700671 mRefreshes {
672 { mFenceMap, frameStartTime + 410 },
673 { mFenceMap, frameStartTime + 420 },
674 { mFenceMap, frameStartTime + 430 } } {}
675
676 void signalQueueFences() {
677 mFenceMap.signalAllForTest(
678 mAcquireConsumer.mFence, kConsumerAcquireTime);
679 mFenceMap.signalAllForTest(
680 mAcquireProducer.mFence, kProducerAcquireTime);
681 }
682
683 void signalRefreshFences() {
684 for (auto& re : mRefreshes) {
685 re.signalPostCompositeFences();
686 }
687 }
688
689 void signalReleaseFences() {
Brian Anderson3da8d272016-07-28 16:20:47 -0700690 mFenceMap.signalAllForTest(mRelease.mFence, kReleaseTime);
691 }
692
693 FenceToFenceTimeMap& mFenceMap;
694
695 FenceAndFenceTime mAcquireConsumer { mFenceMap };
696 FenceAndFenceTime mAcquireProducer { mFenceMap };
Brian Anderson3da8d272016-07-28 16:20:47 -0700697 FenceAndFenceTime mRelease { mFenceMap };
698
699 const nsecs_t kPostedTime;
700 const nsecs_t kRequestedPresentTime;
701 const nsecs_t kProducerAcquireTime;
702 const nsecs_t kConsumerAcquireTime;
703 const nsecs_t kLatchTime;
Brian Andersonf6386862016-10-31 16:34:13 -0700704 const nsecs_t kDequeueReadyTime;
Brian Anderson3da8d272016-07-28 16:20:47 -0700705 const nsecs_t kReleaseTime;
706
707 RefreshEvents mRefreshes[3];
708 };
709
Brian Andersond0010582017-03-07 13:20:31 -0800710 GetFrameTimestampsTest() {}
Brian Anderson3da8d272016-07-28 16:20:47 -0700711
712 virtual void SetUp() {
Brian Anderson3da8d272016-07-28 16:20:47 -0700713 BufferQueue::createBufferQueue(&mProducer, &mConsumer);
714 mFakeConsumer = new FakeConsumer;
715 mCfeh = &mFakeConsumer->mFrameEventHistory;
716 mConsumer->consumerConnect(mFakeConsumer, false);
717 mConsumer->setConsumerName(String8("TestConsumer"));
718 mSurface = new TestSurface(mProducer, &mFenceMap);
719 mWindow = mSurface;
720
721 ASSERT_EQ(NO_ERROR, native_window_api_connect(mWindow.get(),
722 NATIVE_WINDOW_API_CPU));
723 native_window_set_buffer_count(mWindow.get(), 4);
724 }
725
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800726 void disableFrameTimestamps() {
727 mFakeConsumer->mGetFrameTimestampsEnabled = false;
728 native_window_enable_frame_timestamps(mWindow.get(), 0);
729 mFrameTimestampsEnabled = false;
730 }
731
Brian Anderson3da8d272016-07-28 16:20:47 -0700732 void enableFrameTimestamps() {
733 mFakeConsumer->mGetFrameTimestampsEnabled = true;
734 native_window_enable_frame_timestamps(mWindow.get(), 1);
735 mFrameTimestampsEnabled = true;
736 }
737
Brian Anderson1049d1d2016-12-16 17:25:57 -0800738 int getAllFrameTimestamps(uint64_t frameId) {
739 return native_window_get_frame_timestamps(mWindow.get(), frameId,
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700740 &outRequestedPresentTime, &outAcquireTime, &outLatchTime,
741 &outFirstRefreshStartTime, &outLastRefreshStartTime,
742 &outGpuCompositionDoneTime, &outDisplayPresentTime,
Brian Anderson4e606e32017-03-16 15:34:57 -0700743 &outDequeueReadyTime, &outReleaseTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700744 }
745
Brian Anderson3da8d272016-07-28 16:20:47 -0700746 void resetTimestamps() {
747 outRequestedPresentTime = -1;
748 outAcquireTime = -1;
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700749 outLatchTime = -1;
750 outFirstRefreshStartTime = -1;
751 outLastRefreshStartTime = -1;
Brian Anderson3da8d272016-07-28 16:20:47 -0700752 outGpuCompositionDoneTime = -1;
753 outDisplayPresentTime = -1;
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700754 outDequeueReadyTime = -1;
Brian Anderson3da8d272016-07-28 16:20:47 -0700755 outReleaseTime = -1;
756 }
757
Brian Anderson1049d1d2016-12-16 17:25:57 -0800758 uint64_t getNextFrameId() {
759 uint64_t frameId = -1;
760 int status = native_window_get_next_frame_id(mWindow.get(), &frameId);
761 EXPECT_EQ(status, NO_ERROR);
762 return frameId;
763 }
764
Brian Anderson3da8d272016-07-28 16:20:47 -0700765 void dequeueAndQueue(uint64_t frameIndex) {
766 int fence = -1;
767 ANativeWindowBuffer* buffer = nullptr;
768 ASSERT_EQ(NO_ERROR,
769 mWindow->dequeueBuffer(mWindow.get(), &buffer, &fence));
770
771 int oldAddFrameTimestampsCount =
772 mFakeConsumer->mAddFrameTimestampsCount;
773
774 FrameEvents* frame = &mFrames[frameIndex];
775 uint64_t frameNumber = frameIndex + 1;
776
777 NewFrameEventsEntry fe;
778 fe.frameNumber = frameNumber;
779 fe.postedTime = frame->kPostedTime;
780 fe.requestedPresentTime = frame->kRequestedPresentTime;
781 fe.acquireFence = frame->mAcquireConsumer.mFenceTime;
782 mFakeConsumer->mNewFrameEntryOverride = fe;
783
784 mSurface->mFakeFrameEventHistory->setAcquireFenceOverride(
785 frame->mAcquireProducer.mFenceTime,
786 frame->mAcquireConsumer.mFenceTime);
787
788 ASSERT_EQ(NO_ERROR, mWindow->queueBuffer(mWindow.get(), buffer, fence));
789
790 EXPECT_EQ(frameNumber, mFakeConsumer->mLastAddedFrameNumber);
791
792 EXPECT_EQ(
793 oldAddFrameTimestampsCount + (mFrameTimestampsEnabled ? 1 : 0),
794 mFakeConsumer->mAddFrameTimestampsCount);
795 }
796
797 void addFrameEvents(
798 bool gpuComposited, uint64_t iOldFrame, int64_t iNewFrame) {
799 FrameEvents* oldFrame =
800 (iOldFrame == NO_FRAME_INDEX) ? nullptr : &mFrames[iOldFrame];
801 FrameEvents* newFrame = &mFrames[iNewFrame];
802
803 uint64_t nOldFrame = iOldFrame + 1;
804 uint64_t nNewFrame = iNewFrame + 1;
805
Brian Anderson4e606e32017-03-16 15:34:57 -0700806 // Latch, Composite, and Release the frames in a plausible order.
807 // Note: The timestamps won't necessarily match the order, but
Brian Anderson3da8d272016-07-28 16:20:47 -0700808 // that's okay for the purposes of this test.
809 std::shared_ptr<FenceTime> gpuDoneFenceTime = FenceTime::NO_FENCE;
810
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700811 // Composite the previous frame one more time, which helps verify
812 // LastRefresh is updated properly.
813 if (oldFrame != nullptr) {
814 mCfeh->addPreComposition(nOldFrame,
815 oldFrame->mRefreshes[2].kStartTime);
816 gpuDoneFenceTime = gpuComposited ?
817 oldFrame->mRefreshes[2].mGpuCompositionDone.mFenceTime :
818 FenceTime::NO_FENCE;
819 mCfeh->addPostComposition(nOldFrame, gpuDoneFenceTime,
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800820 oldFrame->mRefreshes[2].mPresent.mFenceTime,
821 oldFrame->mRefreshes[2].kCompositorTiming);
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700822 }
823
824 // Latch the new frame.
Brian Anderson3da8d272016-07-28 16:20:47 -0700825 mCfeh->addLatch(nNewFrame, newFrame->kLatchTime);
826
827 mCfeh->addPreComposition(nNewFrame, newFrame->mRefreshes[0].kStartTime);
828 gpuDoneFenceTime = gpuComposited ?
829 newFrame->mRefreshes[0].mGpuCompositionDone.mFenceTime :
830 FenceTime::NO_FENCE;
831 // HWC2 releases the previous buffer after a new latch just before
832 // calling postComposition.
833 if (oldFrame != nullptr) {
Brian Andersonf6386862016-10-31 16:34:13 -0700834 mCfeh->addRelease(nOldFrame, oldFrame->kDequeueReadyTime,
Brian Anderson3da8d272016-07-28 16:20:47 -0700835 std::shared_ptr<FenceTime>(oldFrame->mRelease.mFenceTime));
836 }
837 mCfeh->addPostComposition(nNewFrame, gpuDoneFenceTime,
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800838 newFrame->mRefreshes[0].mPresent.mFenceTime,
839 newFrame->mRefreshes[0].kCompositorTiming);
Brian Anderson3da8d272016-07-28 16:20:47 -0700840
Brian Anderson3da8d272016-07-28 16:20:47 -0700841 mCfeh->addPreComposition(nNewFrame, newFrame->mRefreshes[1].kStartTime);
842 gpuDoneFenceTime = gpuComposited ?
843 newFrame->mRefreshes[1].mGpuCompositionDone.mFenceTime :
844 FenceTime::NO_FENCE;
845 mCfeh->addPostComposition(nNewFrame, gpuDoneFenceTime,
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800846 newFrame->mRefreshes[1].mPresent.mFenceTime,
847 newFrame->mRefreshes[1].kCompositorTiming);
Brian Anderson3da8d272016-07-28 16:20:47 -0700848 }
849
Brian Anderson3da8d272016-07-28 16:20:47 -0700850 sp<IGraphicBufferProducer> mProducer;
851 sp<IGraphicBufferConsumer> mConsumer;
852 sp<FakeConsumer> mFakeConsumer;
853 ConsumerFrameEventHistory* mCfeh;
854 sp<TestSurface> mSurface;
855 sp<ANativeWindow> mWindow;
856
857 FenceToFenceTimeMap mFenceMap;
858
859 bool mFrameTimestampsEnabled = false;
860
861 int64_t outRequestedPresentTime = -1;
862 int64_t outAcquireTime = -1;
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700863 int64_t outLatchTime = -1;
864 int64_t outFirstRefreshStartTime = -1;
865 int64_t outLastRefreshStartTime = -1;
Brian Anderson3da8d272016-07-28 16:20:47 -0700866 int64_t outGpuCompositionDoneTime = -1;
867 int64_t outDisplayPresentTime = -1;
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700868 int64_t outDequeueReadyTime = -1;
Brian Anderson3da8d272016-07-28 16:20:47 -0700869 int64_t outReleaseTime = -1;
870
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800871 FrameEvents mFrames[3] {
872 { mFenceMap, 1000 }, { mFenceMap, 2000 }, { mFenceMap, 3000 } };
Brian Anderson3da8d272016-07-28 16:20:47 -0700873};
874
875
876// This test verifies that the frame timestamps are not retrieved when not
877// explicitly enabled via native_window_enable_frame_timestamps.
878// We want to check this to make sure there's no overhead for users
879// that don't need the timestamp information.
880TEST_F(GetFrameTimestampsTest, DefaultDisabled) {
881 int fence;
882 ANativeWindowBuffer* buffer;
883
884 EXPECT_EQ(0, mFakeConsumer->mAddFrameTimestampsCount);
885 EXPECT_EQ(0, mFakeConsumer->mGetFrameTimestampsCount);
886
Brian Anderson1049d1d2016-12-16 17:25:57 -0800887 const uint64_t fId = getNextFrameId();
888
Brian Anderson3da8d272016-07-28 16:20:47 -0700889 // Verify the producer doesn't get frame timestamps piggybacked on dequeue.
890 ASSERT_EQ(NO_ERROR, mWindow->dequeueBuffer(mWindow.get(), &buffer, &fence));
891 EXPECT_EQ(0, mFakeConsumer->mAddFrameTimestampsCount);
892 EXPECT_EQ(0, mFakeConsumer->mGetFrameTimestampsCount);
893
894 // Verify the producer doesn't get frame timestamps piggybacked on queue.
895 // It is okay that frame timestamps are added in the consumer since it is
896 // still needed for SurfaceFlinger dumps.
897 ASSERT_EQ(NO_ERROR, mWindow->queueBuffer(mWindow.get(), buffer, fence));
898 EXPECT_EQ(1, mFakeConsumer->mAddFrameTimestampsCount);
899 EXPECT_EQ(0, mFakeConsumer->mGetFrameTimestampsCount);
900
901 // Verify attempts to get frame timestamps fail.
Brian Anderson1049d1d2016-12-16 17:25:57 -0800902 int result = getAllFrameTimestamps(fId);
Brian Anderson3da8d272016-07-28 16:20:47 -0700903 EXPECT_EQ(INVALID_OPERATION, result);
904 EXPECT_EQ(0, mFakeConsumer->mGetFrameTimestampsCount);
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800905
906 // Verify compositor timing query fails.
907 nsecs_t compositeDeadline = 0;
908 nsecs_t compositeInterval = 0;
909 nsecs_t compositeToPresentLatency = 0;
910 result = native_window_get_compositor_timing(mWindow.get(),
911 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
912 EXPECT_EQ(INVALID_OPERATION, result);
Brian Anderson3da8d272016-07-28 16:20:47 -0700913}
914
915// This test verifies that the frame timestamps are retrieved if explicitly
916// enabled via native_window_enable_frame_timestamps.
917TEST_F(GetFrameTimestampsTest, EnabledSimple) {
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800918 CompositorTiming initialCompositorTiming {
919 1000000000, // 1s deadline
920 16666667, // 16ms interval
921 50000000, // 50ms present latency
922 };
923 mCfeh->initializeCompositorTiming(initialCompositorTiming);
924
Brian Anderson3da8d272016-07-28 16:20:47 -0700925 enableFrameTimestamps();
926
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800927 // Verify the compositor timing query gets the initial compositor values
928 // after timststamps are enabled; even before the first frame is queued
929 // or dequeued.
930 nsecs_t compositeDeadline = 0;
931 nsecs_t compositeInterval = 0;
932 nsecs_t compositeToPresentLatency = 0;
933 mSurface->setNow(initialCompositorTiming.deadline - 1);
934 int result = native_window_get_compositor_timing(mWindow.get(),
935 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
936 EXPECT_EQ(NO_ERROR, result);
937 EXPECT_EQ(initialCompositorTiming.deadline, compositeDeadline);
938 EXPECT_EQ(initialCompositorTiming.interval, compositeInterval);
939 EXPECT_EQ(initialCompositorTiming.presentLatency,
940 compositeToPresentLatency);
941
Brian Anderson3da8d272016-07-28 16:20:47 -0700942 int fence;
943 ANativeWindowBuffer* buffer;
944
945 EXPECT_EQ(0, mFakeConsumer->mAddFrameTimestampsCount);
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800946 EXPECT_EQ(1, mFakeConsumer->mGetFrameTimestampsCount);
Brian Anderson3da8d272016-07-28 16:20:47 -0700947
Brian Anderson1049d1d2016-12-16 17:25:57 -0800948 const uint64_t fId1 = getNextFrameId();
949
Brian Anderson3da8d272016-07-28 16:20:47 -0700950 // Verify getFrameTimestamps is piggybacked on dequeue.
951 ASSERT_EQ(NO_ERROR, mWindow->dequeueBuffer(mWindow.get(), &buffer, &fence));
952 EXPECT_EQ(0, mFakeConsumer->mAddFrameTimestampsCount);
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800953 EXPECT_EQ(2, mFakeConsumer->mGetFrameTimestampsCount);
Brian Anderson3da8d272016-07-28 16:20:47 -0700954
955 NewFrameEventsEntry f1;
956 f1.frameNumber = 1;
957 f1.postedTime = mFrames[0].kPostedTime;
958 f1.requestedPresentTime = mFrames[0].kRequestedPresentTime;
959 f1.acquireFence = mFrames[0].mAcquireConsumer.mFenceTime;
960 mSurface->mFakeFrameEventHistory->setAcquireFenceOverride(
961 mFrames[0].mAcquireProducer.mFenceTime,
962 mFrames[0].mAcquireConsumer.mFenceTime);
963 mFakeConsumer->mNewFrameEntryOverride = f1;
964 mFrames[0].signalQueueFences();
965
966 // Verify getFrameTimestamps is piggybacked on queue.
967 ASSERT_EQ(NO_ERROR, mWindow->queueBuffer(mWindow.get(), buffer, fence));
968 EXPECT_EQ(1, mFakeConsumer->mAddFrameTimestampsCount);
969 EXPECT_EQ(1u, mFakeConsumer->mLastAddedFrameNumber);
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800970 EXPECT_EQ(3, mFakeConsumer->mGetFrameTimestampsCount);
Brian Anderson3da8d272016-07-28 16:20:47 -0700971
972 // Verify queries for timestamps that the producer doesn't know about
973 // triggers a call to see if the consumer has any new timestamps.
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800974 result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -0700975 EXPECT_EQ(NO_ERROR, result);
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800976 EXPECT_EQ(4, mFakeConsumer->mGetFrameTimestampsCount);
Brian Anderson3da8d272016-07-28 16:20:47 -0700977}
978
Brian Anderson6b376712017-04-04 10:51:39 -0700979TEST_F(GetFrameTimestampsTest, QueryPresentSupported) {
980 bool displayPresentSupported = true;
981 mSurface->mFakeSurfaceComposer->setSupportsPresent(displayPresentSupported);
982
983 // Verify supported bits are forwarded.
984 int supportsPresent = -1;
985 mWindow.get()->query(mWindow.get(),
986 NATIVE_WINDOW_FRAME_TIMESTAMPS_SUPPORTS_PRESENT, &supportsPresent);
987 EXPECT_EQ(displayPresentSupported, supportsPresent);
988}
989
990TEST_F(GetFrameTimestampsTest, QueryPresentNotSupported) {
991 bool displayPresentSupported = false;
992 mSurface->mFakeSurfaceComposer->setSupportsPresent(displayPresentSupported);
993
994 // Verify supported bits are forwarded.
995 int supportsPresent = -1;
996 mWindow.get()->query(mWindow.get(),
997 NATIVE_WINDOW_FRAME_TIMESTAMPS_SUPPORTS_PRESENT, &supportsPresent);
998 EXPECT_EQ(displayPresentSupported, supportsPresent);
999}
1000
Brian Anderson0a61b0c2016-12-07 14:55:56 -08001001TEST_F(GetFrameTimestampsTest, SnapToNextTickBasic) {
1002 nsecs_t phase = 4000;
1003 nsecs_t interval = 1000;
1004
1005 // Timestamp in previous interval.
1006 nsecs_t timestamp = 3500;
1007 EXPECT_EQ(4000, ProducerFrameEventHistory::snapToNextTick(
1008 timestamp, phase, interval));
1009
1010 // Timestamp in next interval.
1011 timestamp = 4500;
1012 EXPECT_EQ(5000, ProducerFrameEventHistory::snapToNextTick(
1013 timestamp, phase, interval));
1014
1015 // Timestamp multiple intervals before.
1016 timestamp = 2500;
1017 EXPECT_EQ(3000, ProducerFrameEventHistory::snapToNextTick(
1018 timestamp, phase, interval));
1019
1020 // Timestamp multiple intervals after.
1021 timestamp = 6500;
1022 EXPECT_EQ(7000, ProducerFrameEventHistory::snapToNextTick(
1023 timestamp, phase, interval));
1024
1025 // Timestamp on previous interval.
1026 timestamp = 3000;
1027 EXPECT_EQ(3000, ProducerFrameEventHistory::snapToNextTick(
1028 timestamp, phase, interval));
1029
1030 // Timestamp on next interval.
1031 timestamp = 5000;
1032 EXPECT_EQ(5000, ProducerFrameEventHistory::snapToNextTick(
1033 timestamp, phase, interval));
1034
1035 // Timestamp equal to phase.
1036 timestamp = 4000;
1037 EXPECT_EQ(4000, ProducerFrameEventHistory::snapToNextTick(
1038 timestamp, phase, interval));
1039}
1040
1041// int(big_timestamp / interval) < 0, which can cause a crash or invalid result
1042// if the number of intervals elapsed is internally stored in an int.
1043TEST_F(GetFrameTimestampsTest, SnapToNextTickOverflow) {
1044 nsecs_t phase = 0;
1045 nsecs_t interval = 4000;
1046 nsecs_t big_timestamp = 8635916564000;
1047 int32_t intervals = big_timestamp / interval;
1048
1049 EXPECT_LT(intervals, 0);
1050 EXPECT_EQ(8635916564000, ProducerFrameEventHistory::snapToNextTick(
1051 big_timestamp, phase, interval));
1052 EXPECT_EQ(8635916564000, ProducerFrameEventHistory::snapToNextTick(
1053 big_timestamp, big_timestamp, interval));
1054}
1055
1056// This verifies the compositor timing is updated by refresh events
1057// and piggy backed on a queue, dequeue, and enabling of timestamps..
1058TEST_F(GetFrameTimestampsTest, CompositorTimingUpdatesBasic) {
1059 CompositorTiming initialCompositorTiming {
1060 1000000000, // 1s deadline
1061 16666667, // 16ms interval
1062 50000000, // 50ms present latency
1063 };
1064 mCfeh->initializeCompositorTiming(initialCompositorTiming);
1065
1066 enableFrameTimestamps();
1067
1068 // We get the initial values before any frames are submitted.
1069 nsecs_t compositeDeadline = 0;
1070 nsecs_t compositeInterval = 0;
1071 nsecs_t compositeToPresentLatency = 0;
1072 mSurface->setNow(initialCompositorTiming.deadline - 1);
1073 int result = native_window_get_compositor_timing(mWindow.get(),
1074 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1075 EXPECT_EQ(NO_ERROR, result);
1076 EXPECT_EQ(initialCompositorTiming.deadline, compositeDeadline);
1077 EXPECT_EQ(initialCompositorTiming.interval, compositeInterval);
1078 EXPECT_EQ(initialCompositorTiming.presentLatency,
1079 compositeToPresentLatency);
1080
1081 const uint64_t fId1 = getNextFrameId();
1082 dequeueAndQueue(0);
1083 addFrameEvents(true, NO_FRAME_INDEX, 0);
1084
1085 // Still get the initial values because the frame events for frame 0
1086 // didn't get a chance to piggyback on a queue or dequeue yet.
1087 result = native_window_get_compositor_timing(mWindow.get(),
1088 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1089 EXPECT_EQ(NO_ERROR, result);
1090 EXPECT_EQ(initialCompositorTiming.deadline, compositeDeadline);
1091 EXPECT_EQ(initialCompositorTiming.interval, compositeInterval);
1092 EXPECT_EQ(initialCompositorTiming.presentLatency,
1093 compositeToPresentLatency);
1094
1095 const uint64_t fId2 = getNextFrameId();
1096 dequeueAndQueue(1);
1097 addFrameEvents(true, 0, 1);
1098
1099 // Now expect the composite values associated with frame 1.
1100 mSurface->setNow(mFrames[0].mRefreshes[1].kCompositorTiming.deadline);
1101 result = native_window_get_compositor_timing(mWindow.get(),
1102 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1103 EXPECT_EQ(NO_ERROR, result);
1104 EXPECT_EQ(mFrames[0].mRefreshes[1].kCompositorTiming.deadline,
1105 compositeDeadline);
1106 EXPECT_EQ(mFrames[0].mRefreshes[1].kCompositorTiming.interval,
1107 compositeInterval);
1108 EXPECT_EQ(mFrames[0].mRefreshes[1].kCompositorTiming.presentLatency,
1109 compositeToPresentLatency);
1110
1111 dequeueAndQueue(2);
1112 addFrameEvents(true, 1, 2);
1113
1114 // Now expect the composite values associated with frame 2.
1115 mSurface->setNow(mFrames[1].mRefreshes[1].kCompositorTiming.deadline);
1116 result = native_window_get_compositor_timing(mWindow.get(),
1117 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1118 EXPECT_EQ(NO_ERROR, result);
1119 EXPECT_EQ(mFrames[1].mRefreshes[1].kCompositorTiming.deadline,
1120 compositeDeadline);
1121 EXPECT_EQ(mFrames[1].mRefreshes[1].kCompositorTiming.interval,
1122 compositeInterval);
1123 EXPECT_EQ(mFrames[1].mRefreshes[1].kCompositorTiming.presentLatency,
1124 compositeToPresentLatency);
1125
1126 // Re-enabling frame timestamps should get the latest values.
1127 disableFrameTimestamps();
1128 enableFrameTimestamps();
1129
1130 // Now expect the composite values associated with frame 3.
1131 mSurface->setNow(mFrames[2].mRefreshes[1].kCompositorTiming.deadline);
1132 result = native_window_get_compositor_timing(mWindow.get(),
1133 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1134 EXPECT_EQ(NO_ERROR, result);
1135 EXPECT_EQ(mFrames[2].mRefreshes[1].kCompositorTiming.deadline,
1136 compositeDeadline);
1137 EXPECT_EQ(mFrames[2].mRefreshes[1].kCompositorTiming.interval,
1138 compositeInterval);
1139 EXPECT_EQ(mFrames[2].mRefreshes[1].kCompositorTiming.presentLatency,
1140 compositeToPresentLatency);
1141}
1142
1143// This verifies the compositor deadline properly snaps to the the next
1144// deadline based on the current time.
1145TEST_F(GetFrameTimestampsTest, CompositorTimingDeadlineSnaps) {
1146 CompositorTiming initialCompositorTiming {
1147 1000000000, // 1s deadline
1148 16666667, // 16ms interval
1149 50000000, // 50ms present latency
1150 };
1151 mCfeh->initializeCompositorTiming(initialCompositorTiming);
1152
1153 enableFrameTimestamps();
1154
1155 nsecs_t compositeDeadline = 0;
1156 nsecs_t compositeInterval = 0;
1157 nsecs_t compositeToPresentLatency = 0;
1158
1159 // A "now" just before the deadline snaps to the deadline.
1160 mSurface->setNow(initialCompositorTiming.deadline - 1);
1161 int result = native_window_get_compositor_timing(mWindow.get(),
1162 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1163 EXPECT_EQ(NO_ERROR, result);
1164 EXPECT_EQ(initialCompositorTiming.deadline, compositeDeadline);
1165 nsecs_t expectedDeadline = initialCompositorTiming.deadline;
1166 EXPECT_EQ(expectedDeadline, compositeDeadline);
1167
1168 const uint64_t fId1 = getNextFrameId();
1169 dequeueAndQueue(0);
1170 addFrameEvents(true, NO_FRAME_INDEX, 0);
1171
1172 // A "now" just after the deadline snaps properly.
1173 mSurface->setNow(initialCompositorTiming.deadline + 1);
1174 result = native_window_get_compositor_timing(mWindow.get(),
1175 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1176 EXPECT_EQ(NO_ERROR, result);
1177 expectedDeadline =
1178 initialCompositorTiming.deadline +initialCompositorTiming.interval;
1179 EXPECT_EQ(expectedDeadline, compositeDeadline);
1180
1181 const uint64_t fId2 = getNextFrameId();
1182 dequeueAndQueue(1);
1183 addFrameEvents(true, 0, 1);
1184
1185 // A "now" just after the next interval snaps properly.
1186 mSurface->setNow(
1187 mFrames[0].mRefreshes[1].kCompositorTiming.deadline +
1188 mFrames[0].mRefreshes[1].kCompositorTiming.interval + 1);
1189 result = native_window_get_compositor_timing(mWindow.get(),
1190 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1191 EXPECT_EQ(NO_ERROR, result);
1192 expectedDeadline =
1193 mFrames[0].mRefreshes[1].kCompositorTiming.deadline +
1194 mFrames[0].mRefreshes[1].kCompositorTiming.interval * 2;
1195 EXPECT_EQ(expectedDeadline, compositeDeadline);
1196
1197 dequeueAndQueue(2);
1198 addFrameEvents(true, 1, 2);
1199
1200 // A "now" over 1 interval before the deadline snaps properly.
1201 mSurface->setNow(
1202 mFrames[1].mRefreshes[1].kCompositorTiming.deadline -
1203 mFrames[1].mRefreshes[1].kCompositorTiming.interval - 1);
1204 result = native_window_get_compositor_timing(mWindow.get(),
1205 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1206 EXPECT_EQ(NO_ERROR, result);
1207 expectedDeadline =
1208 mFrames[1].mRefreshes[1].kCompositorTiming.deadline -
1209 mFrames[1].mRefreshes[1].kCompositorTiming.interval;
1210 EXPECT_EQ(expectedDeadline, compositeDeadline);
1211
1212 // Re-enabling frame timestamps should get the latest values.
1213 disableFrameTimestamps();
1214 enableFrameTimestamps();
1215
1216 // A "now" over 2 intervals before the deadline snaps properly.
1217 mSurface->setNow(
1218 mFrames[2].mRefreshes[1].kCompositorTiming.deadline -
1219 mFrames[2].mRefreshes[1].kCompositorTiming.interval * 2 - 1);
1220 result = native_window_get_compositor_timing(mWindow.get(),
1221 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1222 EXPECT_EQ(NO_ERROR, result);
1223 expectedDeadline =
1224 mFrames[2].mRefreshes[1].kCompositorTiming.deadline -
1225 mFrames[2].mRefreshes[1].kCompositorTiming.interval * 2;
1226 EXPECT_EQ(expectedDeadline, compositeDeadline);
1227}
1228
Brian Anderson1049d1d2016-12-16 17:25:57 -08001229// This verifies the timestamps recorded in the consumer's
1230// FrameTimestampsHistory are properly retrieved by the producer for the
1231// correct frames.
Brian Anderson3da8d272016-07-28 16:20:47 -07001232TEST_F(GetFrameTimestampsTest, TimestampsAssociatedWithCorrectFrame) {
1233 enableFrameTimestamps();
1234
Brian Anderson1049d1d2016-12-16 17:25:57 -08001235 const uint64_t fId1 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001236 dequeueAndQueue(0);
1237 mFrames[0].signalQueueFences();
1238
Brian Anderson1049d1d2016-12-16 17:25:57 -08001239 const uint64_t fId2 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001240 dequeueAndQueue(1);
1241 mFrames[1].signalQueueFences();
1242
1243 addFrameEvents(true, NO_FRAME_INDEX, 0);
1244 mFrames[0].signalRefreshFences();
1245 addFrameEvents(true, 0, 1);
1246 mFrames[0].signalReleaseFences();
1247 mFrames[1].signalRefreshFences();
1248
1249 // Verify timestamps are correct for frame 1.
Brian Anderson3da8d272016-07-28 16:20:47 -07001250 resetTimestamps();
Brian Anderson1049d1d2016-12-16 17:25:57 -08001251 int result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001252 EXPECT_EQ(NO_ERROR, result);
1253 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1254 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001255 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1256 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1257 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001258 EXPECT_EQ(mFrames[0].mRefreshes[0].kGpuCompositionDoneTime,
1259 outGpuCompositionDoneTime);
1260 EXPECT_EQ(mFrames[0].mRefreshes[0].kPresentTime, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001261 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001262 EXPECT_EQ(mFrames[0].kReleaseTime, outReleaseTime);
1263
1264 // Verify timestamps are correct for frame 2.
Brian Anderson3da8d272016-07-28 16:20:47 -07001265 resetTimestamps();
Brian Anderson1049d1d2016-12-16 17:25:57 -08001266 result = getAllFrameTimestamps(fId2);
Brian Anderson3da8d272016-07-28 16:20:47 -07001267 EXPECT_EQ(NO_ERROR, result);
1268 EXPECT_EQ(mFrames[1].kRequestedPresentTime, outRequestedPresentTime);
1269 EXPECT_EQ(mFrames[1].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001270 EXPECT_EQ(mFrames[1].kLatchTime, outLatchTime);
1271 EXPECT_EQ(mFrames[1].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1272 EXPECT_EQ(mFrames[1].mRefreshes[1].kStartTime, outLastRefreshStartTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001273 EXPECT_EQ(mFrames[1].mRefreshes[0].kGpuCompositionDoneTime,
1274 outGpuCompositionDoneTime);
1275 EXPECT_EQ(mFrames[1].mRefreshes[0].kPresentTime, outDisplayPresentTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001276 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDequeueReadyTime);
1277 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001278}
1279
1280// This test verifies the acquire fence recorded by the consumer is not sent
1281// back to the producer and the producer saves its own fence.
1282TEST_F(GetFrameTimestampsTest, QueueTimestampsNoSync) {
1283 enableFrameTimestamps();
Brian Anderson3da8d272016-07-28 16:20:47 -07001284
Brian Anderson3da8d272016-07-28 16:20:47 -07001285 // Dequeue and queue frame 1.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001286 const uint64_t fId1 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001287 dequeueAndQueue(0);
1288
1289 // Verify queue-related timestamps for f1 are available immediately in the
1290 // producer without asking the consumer again, even before signaling the
1291 // acquire fence.
1292 resetTimestamps();
1293 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001294 int result = native_window_get_frame_timestamps(mWindow.get(), fId1,
Brian Anderson3da8d272016-07-28 16:20:47 -07001295 &outRequestedPresentTime, &outAcquireTime, nullptr, nullptr,
Brian Anderson4e606e32017-03-16 15:34:57 -07001296 nullptr, nullptr, nullptr, nullptr, nullptr);
Brian Anderson3da8d272016-07-28 16:20:47 -07001297 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1298 EXPECT_EQ(NO_ERROR, result);
1299 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001300 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outAcquireTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001301
1302 // Signal acquire fences. Verify a sync call still isn't necessary.
1303 mFrames[0].signalQueueFences();
1304
1305 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001306 result = native_window_get_frame_timestamps(mWindow.get(), fId1,
Brian Anderson3da8d272016-07-28 16:20:47 -07001307 &outRequestedPresentTime, &outAcquireTime, nullptr, nullptr,
Brian Anderson4e606e32017-03-16 15:34:57 -07001308 nullptr, nullptr, nullptr, nullptr, nullptr);
Brian Anderson3da8d272016-07-28 16:20:47 -07001309 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1310 EXPECT_EQ(NO_ERROR, result);
1311 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1312 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
1313
1314 // Dequeue and queue frame 2.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001315 const uint64_t fId2 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001316 dequeueAndQueue(1);
1317
1318 // Verify queue-related timestamps for f2 are available immediately in the
1319 // producer without asking the consumer again, even before signaling the
1320 // acquire fence.
1321 resetTimestamps();
1322 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001323 result = native_window_get_frame_timestamps(mWindow.get(), fId2,
Brian Anderson3da8d272016-07-28 16:20:47 -07001324 &outRequestedPresentTime, &outAcquireTime, nullptr, nullptr,
Brian Anderson4e606e32017-03-16 15:34:57 -07001325 nullptr, nullptr, nullptr, nullptr, nullptr);
Brian Anderson3da8d272016-07-28 16:20:47 -07001326 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1327 EXPECT_EQ(NO_ERROR, result);
1328 EXPECT_EQ(mFrames[1].kRequestedPresentTime, outRequestedPresentTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001329 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outAcquireTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001330
1331 // Signal acquire fences. Verify a sync call still isn't necessary.
1332 mFrames[1].signalQueueFences();
1333
1334 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001335 result = native_window_get_frame_timestamps(mWindow.get(), fId2,
Brian Anderson3da8d272016-07-28 16:20:47 -07001336 &outRequestedPresentTime, &outAcquireTime, nullptr, nullptr,
Brian Anderson4e606e32017-03-16 15:34:57 -07001337 nullptr, nullptr, nullptr, nullptr, nullptr);
Brian Anderson3da8d272016-07-28 16:20:47 -07001338 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1339 EXPECT_EQ(NO_ERROR, result);
1340 EXPECT_EQ(mFrames[1].kRequestedPresentTime, outRequestedPresentTime);
1341 EXPECT_EQ(mFrames[1].kProducerAcquireTime, outAcquireTime);
1342}
1343
1344TEST_F(GetFrameTimestampsTest, ZeroRequestedTimestampsNoSync) {
1345 enableFrameTimestamps();
Brian Anderson3da8d272016-07-28 16:20:47 -07001346
1347 // Dequeue and queue frame 1.
1348 dequeueAndQueue(0);
1349 mFrames[0].signalQueueFences();
1350
1351 // Dequeue and queue frame 2.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001352 const uint64_t fId2 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001353 dequeueAndQueue(1);
1354 mFrames[1].signalQueueFences();
1355
1356 addFrameEvents(true, NO_FRAME_INDEX, 0);
1357 mFrames[0].signalRefreshFences();
1358 addFrameEvents(true, 0, 1);
1359 mFrames[0].signalReleaseFences();
1360 mFrames[1].signalRefreshFences();
1361
1362 // Verify a request for no timestamps doesn't result in a sync call.
Brian Anderson3da8d272016-07-28 16:20:47 -07001363 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001364 int result = native_window_get_frame_timestamps(mWindow.get(), fId2,
Brian Anderson6b376712017-04-04 10:51:39 -07001365 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
1366 nullptr, nullptr);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001367 EXPECT_EQ(NO_ERROR, result);
Brian Anderson3da8d272016-07-28 16:20:47 -07001368 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1369}
1370
1371// This test verifies that fences can signal and update timestamps producer
1372// side without an additional sync call to the consumer.
1373TEST_F(GetFrameTimestampsTest, FencesInProducerNoSync) {
1374 enableFrameTimestamps();
Brian Anderson3da8d272016-07-28 16:20:47 -07001375
1376 // Dequeue and queue frame 1.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001377 const uint64_t fId1 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001378 dequeueAndQueue(0);
1379 mFrames[0].signalQueueFences();
1380
1381 // Dequeue and queue frame 2.
1382 dequeueAndQueue(1);
1383 mFrames[1].signalQueueFences();
1384
1385 addFrameEvents(true, NO_FRAME_INDEX, 0);
1386 addFrameEvents(true, 0, 1);
1387
1388 // Verify available timestamps are correct for frame 1, before any
1389 // fence has been signaled.
1390 // Note: A sync call is necessary here since the events triggered by
1391 // addFrameEvents didn't get to piggyback on the earlier queues/dequeues.
Brian Anderson3da8d272016-07-28 16:20:47 -07001392 resetTimestamps();
1393 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001394 int result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001395 EXPECT_EQ(oldCount + 1, mFakeConsumer->mGetFrameTimestampsCount);
1396 EXPECT_EQ(NO_ERROR, result);
1397 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1398 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001399 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1400 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1401 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001402 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outGpuCompositionDoneTime);
1403 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001404 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001405 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001406
1407 // Verify available timestamps are correct for frame 1 again, before any
1408 // fence has been signaled.
1409 // This time a sync call should not be necessary.
Brian Anderson3da8d272016-07-28 16:20:47 -07001410 resetTimestamps();
1411 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001412 result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001413 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1414 EXPECT_EQ(NO_ERROR, result);
1415 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1416 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001417 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1418 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1419 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001420 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outGpuCompositionDoneTime);
1421 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001422 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001423 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001424
1425 // Signal the fences for frame 1.
1426 mFrames[0].signalRefreshFences();
1427 mFrames[0].signalReleaseFences();
1428
1429 // Verify all timestamps are available without a sync call.
Brian Anderson3da8d272016-07-28 16:20:47 -07001430 resetTimestamps();
1431 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001432 result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001433 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1434 EXPECT_EQ(NO_ERROR, result);
1435 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1436 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001437 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1438 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1439 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001440 EXPECT_EQ(mFrames[0].mRefreshes[0].kGpuCompositionDoneTime,
1441 outGpuCompositionDoneTime);
1442 EXPECT_EQ(mFrames[0].mRefreshes[0].kPresentTime, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001443 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001444 EXPECT_EQ(mFrames[0].kReleaseTime, outReleaseTime);
1445}
1446
1447// This test verifies that if the frame wasn't GPU composited but has a refresh
1448// event a sync call isn't made to get the GPU composite done time since it will
1449// never exist.
1450TEST_F(GetFrameTimestampsTest, NoGpuNoSync) {
1451 enableFrameTimestamps();
Brian Anderson3da8d272016-07-28 16:20:47 -07001452
Brian Anderson3da8d272016-07-28 16:20:47 -07001453 // Dequeue and queue frame 1.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001454 const uint64_t fId1 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001455 dequeueAndQueue(0);
1456 mFrames[0].signalQueueFences();
1457
1458 // Dequeue and queue frame 2.
1459 dequeueAndQueue(1);
1460 mFrames[1].signalQueueFences();
1461
1462 addFrameEvents(false, NO_FRAME_INDEX, 0);
1463 addFrameEvents(false, 0, 1);
1464
1465 // Verify available timestamps are correct for frame 1, before any
1466 // fence has been signaled.
1467 // Note: A sync call is necessary here since the events triggered by
1468 // addFrameEvents didn't get to piggyback on the earlier queues/dequeues.
1469 resetTimestamps();
1470 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001471 int result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001472 EXPECT_EQ(oldCount + 1, mFakeConsumer->mGetFrameTimestampsCount);
1473 EXPECT_EQ(NO_ERROR, result);
1474 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1475 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001476 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1477 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1478 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001479 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_INVALID, outGpuCompositionDoneTime);
1480 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001481 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001482 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001483
1484 // Signal the fences for frame 1.
1485 mFrames[0].signalRefreshFences();
1486 mFrames[0].signalReleaseFences();
1487
1488 // Verify all timestamps, except GPU composition, are available without a
1489 // sync call.
1490 resetTimestamps();
1491 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001492 result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001493 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1494 EXPECT_EQ(NO_ERROR, result);
1495 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1496 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001497 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1498 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1499 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001500 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_INVALID, outGpuCompositionDoneTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001501 EXPECT_EQ(mFrames[0].mRefreshes[0].kPresentTime, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001502 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001503 EXPECT_EQ(mFrames[0].kReleaseTime, outReleaseTime);
1504}
1505
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001506// This test verifies that if the certain timestamps can't possibly exist for
1507// the most recent frame, then a sync call is not done.
Brian Anderson6b376712017-04-04 10:51:39 -07001508TEST_F(GetFrameTimestampsTest, NoReleaseNoSync) {
Brian Anderson3da8d272016-07-28 16:20:47 -07001509 enableFrameTimestamps();
Brian Anderson3da8d272016-07-28 16:20:47 -07001510
1511 // Dequeue and queue frame 1.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001512 const uint64_t fId1 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001513 dequeueAndQueue(0);
1514 mFrames[0].signalQueueFences();
1515
1516 // Dequeue and queue frame 2.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001517 const uint64_t fId2 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001518 dequeueAndQueue(1);
1519 mFrames[1].signalQueueFences();
1520
1521 addFrameEvents(false, NO_FRAME_INDEX, 0);
1522 addFrameEvents(false, 0, 1);
1523
1524 // Verify available timestamps are correct for frame 1, before any
1525 // fence has been signaled.
1526 // Note: A sync call is necessary here since the events triggered by
1527 // addFrameEvents didn't get to piggyback on the earlier queues/dequeues.
Brian Anderson3da8d272016-07-28 16:20:47 -07001528 resetTimestamps();
1529 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001530 int result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001531 EXPECT_EQ(oldCount + 1, mFakeConsumer->mGetFrameTimestampsCount);
1532 EXPECT_EQ(NO_ERROR, result);
1533 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1534 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001535 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1536 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1537 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001538 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_INVALID, outGpuCompositionDoneTime);
1539 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001540 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001541 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001542
1543 mFrames[0].signalRefreshFences();
1544 mFrames[0].signalReleaseFences();
1545 mFrames[1].signalRefreshFences();
1546
Brian Anderson1049d1d2016-12-16 17:25:57 -08001547 // Verify querying for all timestmaps of f2 does not do a sync call. Even
Brian Anderson4e606e32017-03-16 15:34:57 -07001548 // though the lastRefresh, dequeueReady, and release times aren't
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001549 // available, a sync call should not occur because it's not possible for f2
1550 // to encounter the final value for those events until another frame is
1551 // queued.
Brian Anderson3da8d272016-07-28 16:20:47 -07001552 resetTimestamps();
1553 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001554 result = getAllFrameTimestamps(fId2);
Brian Anderson3da8d272016-07-28 16:20:47 -07001555 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1556 EXPECT_EQ(NO_ERROR, result);
1557 EXPECT_EQ(mFrames[1].kRequestedPresentTime, outRequestedPresentTime);
1558 EXPECT_EQ(mFrames[1].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001559 EXPECT_EQ(mFrames[1].kLatchTime, outLatchTime);
1560 EXPECT_EQ(mFrames[1].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1561 EXPECT_EQ(mFrames[1].mRefreshes[1].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001562 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_INVALID, outGpuCompositionDoneTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001563 EXPECT_EQ(mFrames[1].mRefreshes[0].kPresentTime, outDisplayPresentTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001564 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDequeueReadyTime);
1565 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001566}
1567
Brian Anderson6b376712017-04-04 10:51:39 -07001568// This test verifies there are no sync calls for present times
1569// when they aren't supported and that an error is returned.
1570
1571TEST_F(GetFrameTimestampsTest, PresentUnsupportedNoSync) {
1572 enableFrameTimestamps();
1573 mSurface->mFakeSurfaceComposer->setSupportsPresent(false);
1574
1575 // Dequeue and queue frame 1.
1576 const uint64_t fId1 = getNextFrameId();
1577 dequeueAndQueue(0);
1578
1579 // Verify a query for the Present times do not trigger a sync call if they
1580 // are not supported.
1581 resetTimestamps();
1582 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
1583 int result = native_window_get_frame_timestamps(mWindow.get(), fId1,
1584 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
1585 &outDisplayPresentTime, nullptr, nullptr);
1586 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1587 EXPECT_EQ(BAD_VALUE, result);
1588 EXPECT_EQ(-1, outDisplayPresentTime);
1589}
1590
Dan Stoza932f0082017-05-31 13:50:16 -07001591} // namespace android