blob: fcaa23a4e5df0266aaedd730e783560425429e63 [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
396class FakeConsumer : public BnConsumerListener {
397public:
398 void onFrameAvailable(const BufferItem& /*item*/) override {}
399 void onBuffersReleased() override {}
400 void onSidebandStreamChanged() override {}
401
402 void addAndGetFrameTimestamps(
403 const NewFrameEventsEntry* newTimestamps,
404 FrameEventHistoryDelta* outDelta) override {
405 if (newTimestamps) {
406 if (mGetFrameTimestampsEnabled) {
407 EXPECT_GT(mNewFrameEntryOverride.frameNumber, 0u) <<
408 "Test should set mNewFrameEntryOverride before queuing "
409 "a frame.";
410 EXPECT_EQ(newTimestamps->frameNumber,
411 mNewFrameEntryOverride.frameNumber) <<
412 "Test attempting to add NewFrameEntryOverride with "
413 "incorrect frame number.";
414 mFrameEventHistory.addQueue(mNewFrameEntryOverride);
415 mNewFrameEntryOverride.frameNumber = 0;
416 }
417 mAddFrameTimestampsCount++;
418 mLastAddedFrameNumber = newTimestamps->frameNumber;
419 }
420 if (outDelta) {
421 mFrameEventHistory.getAndResetDelta(outDelta);
422 mGetFrameTimestampsCount++;
423 }
424 mAddAndGetFrameTimestampsCallCount++;
425 }
426
427 bool mGetFrameTimestampsEnabled = false;
428
429 ConsumerFrameEventHistory mFrameEventHistory;
430 int mAddAndGetFrameTimestampsCallCount = 0;
431 int mAddFrameTimestampsCount = 0;
432 int mGetFrameTimestampsCount = 0;
433 uint64_t mLastAddedFrameNumber = NO_FRAME_INDEX;
434
435 NewFrameEventsEntry mNewFrameEntryOverride = { 0, 0, 0, nullptr };
436};
437
438
439class FakeSurfaceComposer : public ISurfaceComposer{
440public:
441 ~FakeSurfaceComposer() override {}
442
Brian Anderson6b376712017-04-04 10:51:39 -0700443 void setSupportsPresent(bool supportsPresent) {
444 mSupportsPresent = supportsPresent;
445 }
446
Brian Anderson3da8d272016-07-28 16:20:47 -0700447 sp<ISurfaceComposerClient> createConnection() override { return nullptr; }
Robert Carr1db73f62016-12-21 12:58:51 -0800448 sp<ISurfaceComposerClient> createScopedConnection(
449 const sp<IGraphicBufferProducer>& /* parent */) override {
450 return nullptr;
451 }
Brian Anderson3da8d272016-07-28 16:20:47 -0700452 sp<IDisplayEventConnection> createDisplayEventConnection() override {
453 return nullptr;
454 }
455 sp<IBinder> createDisplay(const String8& /*displayName*/,
456 bool /*secure*/) override { return nullptr; }
457 void destroyDisplay(const sp<IBinder>& /*display */) override {}
458 sp<IBinder> getBuiltInDisplay(int32_t /*id*/) override { return nullptr; }
459 void setTransactionState(const Vector<ComposerState>& /*state*/,
460 const Vector<DisplayState>& /*displays*/, uint32_t /*flags*/)
461 override {}
462 void bootFinished() override {}
463 bool authenticateSurfaceTexture(
464 const sp<IGraphicBufferProducer>& /*surface*/) const override {
465 return false;
466 }
Brian Anderson6b376712017-04-04 10:51:39 -0700467
468 status_t getSupportedFrameTimestamps(std::vector<FrameEvent>* outSupported)
469 const override {
470 *outSupported = {
471 FrameEvent::REQUESTED_PRESENT,
472 FrameEvent::ACQUIRE,
473 FrameEvent::LATCH,
474 FrameEvent::FIRST_REFRESH_START,
475 FrameEvent::LAST_REFRESH_START,
476 FrameEvent::GPU_COMPOSITION_DONE,
477 FrameEvent::DEQUEUE_READY,
478 FrameEvent::RELEASE
479 };
480 if (mSupportsPresent) {
481 outSupported->push_back(
482 FrameEvent::DISPLAY_PRESENT);
483 }
484 return NO_ERROR;
485 }
486
Brian Anderson3da8d272016-07-28 16:20:47 -0700487 void setPowerMode(const sp<IBinder>& /*display*/, int /*mode*/) override {}
488 status_t getDisplayConfigs(const sp<IBinder>& /*display*/,
489 Vector<DisplayInfo>* /*configs*/) override { return NO_ERROR; }
490 status_t getDisplayStats(const sp<IBinder>& /*display*/,
491 DisplayStatInfo* /*stats*/) override { return NO_ERROR; }
492 int getActiveConfig(const sp<IBinder>& /*display*/) override { return 0; }
493 status_t setActiveConfig(const sp<IBinder>& /*display*/, int /*id*/)
494 override {
495 return NO_ERROR;
496 }
497 status_t getDisplayColorModes(const sp<IBinder>& /*display*/,
498 Vector<android_color_mode_t>* /*outColorModes*/) override {
499 return NO_ERROR;
500 }
501 android_color_mode_t getActiveColorMode(const sp<IBinder>& /*display*/)
502 override {
503 return HAL_COLOR_MODE_NATIVE;
504 }
505 status_t setActiveColorMode(const sp<IBinder>& /*display*/,
506 android_color_mode_t /*colorMode*/) override { return NO_ERROR; }
507 status_t captureScreen(const sp<IBinder>& /*display*/,
508 const sp<IGraphicBufferProducer>& /*producer*/,
509 Rect /*sourceCrop*/, uint32_t /*reqWidth*/, uint32_t /*reqHeight*/,
Robert Carrae060832016-11-28 10:51:00 -0800510 int32_t /*minLayerZ*/, int32_t /*maxLayerZ*/,
Brian Anderson3da8d272016-07-28 16:20:47 -0700511 bool /*useIdentityTransform*/,
512 Rotation /*rotation*/) override { return NO_ERROR; }
513 status_t clearAnimationFrameStats() override { return NO_ERROR; }
514 status_t getAnimationFrameStats(FrameStats* /*outStats*/) const override {
515 return NO_ERROR;
516 }
517 status_t getHdrCapabilities(const sp<IBinder>& /*display*/,
518 HdrCapabilities* /*outCapabilities*/) const override {
519 return NO_ERROR;
520 }
521 status_t enableVSyncInjections(bool /*enable*/) override {
522 return NO_ERROR;
523 }
524 status_t injectVSync(nsecs_t /*when*/) override { return NO_ERROR; }
525
526protected:
527 IBinder* onAsBinder() override { return nullptr; }
528
529private:
530 bool mSupportsPresent{true};
Brian Anderson3da8d272016-07-28 16:20:47 -0700531};
532
533class FakeProducerFrameEventHistory : public ProducerFrameEventHistory {
534public:
535 FakeProducerFrameEventHistory(FenceToFenceTimeMap* fenceMap)
536 : mFenceMap(fenceMap) {}
537
538 ~FakeProducerFrameEventHistory() {}
539
540 void updateAcquireFence(uint64_t frameNumber,
541 std::shared_ptr<FenceTime>&& acquire) override {
542 // Verify the acquire fence being added isn't the one from the consumer.
543 EXPECT_NE(mConsumerAcquireFence, acquire);
544 // Override the fence, so we can verify this was called by the
545 // producer after the frame is queued.
546 ProducerFrameEventHistory::updateAcquireFence(frameNumber,
547 std::shared_ptr<FenceTime>(mAcquireFenceOverride));
548 }
549
550 void setAcquireFenceOverride(
551 const std::shared_ptr<FenceTime>& acquireFenceOverride,
552 const std::shared_ptr<FenceTime>& consumerAcquireFence) {
553 mAcquireFenceOverride = acquireFenceOverride;
554 mConsumerAcquireFence = consumerAcquireFence;
555 }
556
557protected:
558 std::shared_ptr<FenceTime> createFenceTime(const sp<Fence>& fence)
559 const override {
560 return mFenceMap->createFenceTimeForTest(fence);
561 }
562
563 FenceToFenceTimeMap* mFenceMap{nullptr};
564
565 std::shared_ptr<FenceTime> mAcquireFenceOverride{FenceTime::NO_FENCE};
566 std::shared_ptr<FenceTime> mConsumerAcquireFence{FenceTime::NO_FENCE};
567};
568
569
570class TestSurface : public Surface {
571public:
572 TestSurface(const sp<IGraphicBufferProducer>& bufferProducer,
573 FenceToFenceTimeMap* fenceMap)
574 : Surface(bufferProducer),
575 mFakeSurfaceComposer(new FakeSurfaceComposer) {
576 mFakeFrameEventHistory = new FakeProducerFrameEventHistory(fenceMap);
577 mFrameEventHistory.reset(mFakeFrameEventHistory);
578 }
579
580 ~TestSurface() override {}
581
582 sp<ISurfaceComposer> composerService() const override {
583 return mFakeSurfaceComposer;
584 }
585
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800586 nsecs_t now() const override {
587 return mNow;
588 }
589
590 void setNow(nsecs_t now) {
591 mNow = now;
592 }
593
Brian Anderson3da8d272016-07-28 16:20:47 -0700594public:
595 sp<FakeSurfaceComposer> mFakeSurfaceComposer;
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800596 nsecs_t mNow = 0;
Brian Anderson3da8d272016-07-28 16:20:47 -0700597
598 // mFrameEventHistory owns the instance of FakeProducerFrameEventHistory,
599 // but this raw pointer gives access to test functionality.
600 FakeProducerFrameEventHistory* mFakeFrameEventHistory;
601};
602
603
Brian Andersond0010582017-03-07 13:20:31 -0800604class GetFrameTimestampsTest : public ::testing::Test {
Brian Anderson3da8d272016-07-28 16:20:47 -0700605protected:
606 struct FenceAndFenceTime {
607 explicit FenceAndFenceTime(FenceToFenceTimeMap& fenceMap)
608 : mFence(new Fence),
609 mFenceTime(fenceMap.createFenceTimeForTest(mFence)) {}
610 sp<Fence> mFence { nullptr };
611 std::shared_ptr<FenceTime> mFenceTime { nullptr };
612 };
613
614 struct RefreshEvents {
615 RefreshEvents(FenceToFenceTimeMap& fenceMap, nsecs_t refreshStart)
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800616 : mFenceMap(fenceMap),
617 kCompositorTiming(
618 {refreshStart, refreshStart + 1, refreshStart + 2 }),
619 kStartTime(refreshStart + 3),
620 kGpuCompositionDoneTime(refreshStart + 4),
621 kPresentTime(refreshStart + 5) {}
Brian Anderson3da8d272016-07-28 16:20:47 -0700622
623 void signalPostCompositeFences() {
624 mFenceMap.signalAllForTest(
625 mGpuCompositionDone.mFence, kGpuCompositionDoneTime);
626 mFenceMap.signalAllForTest(mPresent.mFence, kPresentTime);
627 }
628
629 FenceToFenceTimeMap& mFenceMap;
630
631 FenceAndFenceTime mGpuCompositionDone { mFenceMap };
632 FenceAndFenceTime mPresent { mFenceMap };
633
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800634 const CompositorTiming kCompositorTiming;
635
Brian Anderson3da8d272016-07-28 16:20:47 -0700636 const nsecs_t kStartTime;
637 const nsecs_t kGpuCompositionDoneTime;
638 const nsecs_t kPresentTime;
639 };
640
641 struct FrameEvents {
642 FrameEvents(FenceToFenceTimeMap& fenceMap, nsecs_t frameStartTime)
643 : mFenceMap(fenceMap),
644 kPostedTime(frameStartTime + 100),
645 kRequestedPresentTime(frameStartTime + 200),
646 kProducerAcquireTime(frameStartTime + 300),
647 kConsumerAcquireTime(frameStartTime + 301),
648 kLatchTime(frameStartTime + 500),
Brian Andersonf6386862016-10-31 16:34:13 -0700649 kDequeueReadyTime(frameStartTime + 600),
Brian Anderson4e606e32017-03-16 15:34:57 -0700650 kReleaseTime(frameStartTime + 700),
Brian Anderson3da8d272016-07-28 16:20:47 -0700651 mRefreshes {
652 { mFenceMap, frameStartTime + 410 },
653 { mFenceMap, frameStartTime + 420 },
654 { mFenceMap, frameStartTime + 430 } } {}
655
656 void signalQueueFences() {
657 mFenceMap.signalAllForTest(
658 mAcquireConsumer.mFence, kConsumerAcquireTime);
659 mFenceMap.signalAllForTest(
660 mAcquireProducer.mFence, kProducerAcquireTime);
661 }
662
663 void signalRefreshFences() {
664 for (auto& re : mRefreshes) {
665 re.signalPostCompositeFences();
666 }
667 }
668
669 void signalReleaseFences() {
Brian Anderson3da8d272016-07-28 16:20:47 -0700670 mFenceMap.signalAllForTest(mRelease.mFence, kReleaseTime);
671 }
672
673 FenceToFenceTimeMap& mFenceMap;
674
675 FenceAndFenceTime mAcquireConsumer { mFenceMap };
676 FenceAndFenceTime mAcquireProducer { mFenceMap };
Brian Anderson3da8d272016-07-28 16:20:47 -0700677 FenceAndFenceTime mRelease { mFenceMap };
678
679 const nsecs_t kPostedTime;
680 const nsecs_t kRequestedPresentTime;
681 const nsecs_t kProducerAcquireTime;
682 const nsecs_t kConsumerAcquireTime;
683 const nsecs_t kLatchTime;
Brian Andersonf6386862016-10-31 16:34:13 -0700684 const nsecs_t kDequeueReadyTime;
Brian Anderson3da8d272016-07-28 16:20:47 -0700685 const nsecs_t kReleaseTime;
686
687 RefreshEvents mRefreshes[3];
688 };
689
Brian Andersond0010582017-03-07 13:20:31 -0800690 GetFrameTimestampsTest() {}
Brian Anderson3da8d272016-07-28 16:20:47 -0700691
692 virtual void SetUp() {
Brian Anderson3da8d272016-07-28 16:20:47 -0700693 BufferQueue::createBufferQueue(&mProducer, &mConsumer);
694 mFakeConsumer = new FakeConsumer;
695 mCfeh = &mFakeConsumer->mFrameEventHistory;
696 mConsumer->consumerConnect(mFakeConsumer, false);
697 mConsumer->setConsumerName(String8("TestConsumer"));
698 mSurface = new TestSurface(mProducer, &mFenceMap);
699 mWindow = mSurface;
700
701 ASSERT_EQ(NO_ERROR, native_window_api_connect(mWindow.get(),
702 NATIVE_WINDOW_API_CPU));
703 native_window_set_buffer_count(mWindow.get(), 4);
704 }
705
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800706 void disableFrameTimestamps() {
707 mFakeConsumer->mGetFrameTimestampsEnabled = false;
708 native_window_enable_frame_timestamps(mWindow.get(), 0);
709 mFrameTimestampsEnabled = false;
710 }
711
Brian Anderson3da8d272016-07-28 16:20:47 -0700712 void enableFrameTimestamps() {
713 mFakeConsumer->mGetFrameTimestampsEnabled = true;
714 native_window_enable_frame_timestamps(mWindow.get(), 1);
715 mFrameTimestampsEnabled = true;
716 }
717
Brian Anderson1049d1d2016-12-16 17:25:57 -0800718 int getAllFrameTimestamps(uint64_t frameId) {
719 return native_window_get_frame_timestamps(mWindow.get(), frameId,
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700720 &outRequestedPresentTime, &outAcquireTime, &outLatchTime,
721 &outFirstRefreshStartTime, &outLastRefreshStartTime,
722 &outGpuCompositionDoneTime, &outDisplayPresentTime,
Brian Anderson4e606e32017-03-16 15:34:57 -0700723 &outDequeueReadyTime, &outReleaseTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700724 }
725
Brian Anderson3da8d272016-07-28 16:20:47 -0700726 void resetTimestamps() {
727 outRequestedPresentTime = -1;
728 outAcquireTime = -1;
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700729 outLatchTime = -1;
730 outFirstRefreshStartTime = -1;
731 outLastRefreshStartTime = -1;
Brian Anderson3da8d272016-07-28 16:20:47 -0700732 outGpuCompositionDoneTime = -1;
733 outDisplayPresentTime = -1;
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700734 outDequeueReadyTime = -1;
Brian Anderson3da8d272016-07-28 16:20:47 -0700735 outReleaseTime = -1;
736 }
737
Brian Anderson1049d1d2016-12-16 17:25:57 -0800738 uint64_t getNextFrameId() {
739 uint64_t frameId = -1;
740 int status = native_window_get_next_frame_id(mWindow.get(), &frameId);
741 EXPECT_EQ(status, NO_ERROR);
742 return frameId;
743 }
744
Brian Anderson3da8d272016-07-28 16:20:47 -0700745 void dequeueAndQueue(uint64_t frameIndex) {
746 int fence = -1;
747 ANativeWindowBuffer* buffer = nullptr;
748 ASSERT_EQ(NO_ERROR,
749 mWindow->dequeueBuffer(mWindow.get(), &buffer, &fence));
750
751 int oldAddFrameTimestampsCount =
752 mFakeConsumer->mAddFrameTimestampsCount;
753
754 FrameEvents* frame = &mFrames[frameIndex];
755 uint64_t frameNumber = frameIndex + 1;
756
757 NewFrameEventsEntry fe;
758 fe.frameNumber = frameNumber;
759 fe.postedTime = frame->kPostedTime;
760 fe.requestedPresentTime = frame->kRequestedPresentTime;
761 fe.acquireFence = frame->mAcquireConsumer.mFenceTime;
762 mFakeConsumer->mNewFrameEntryOverride = fe;
763
764 mSurface->mFakeFrameEventHistory->setAcquireFenceOverride(
765 frame->mAcquireProducer.mFenceTime,
766 frame->mAcquireConsumer.mFenceTime);
767
768 ASSERT_EQ(NO_ERROR, mWindow->queueBuffer(mWindow.get(), buffer, fence));
769
770 EXPECT_EQ(frameNumber, mFakeConsumer->mLastAddedFrameNumber);
771
772 EXPECT_EQ(
773 oldAddFrameTimestampsCount + (mFrameTimestampsEnabled ? 1 : 0),
774 mFakeConsumer->mAddFrameTimestampsCount);
775 }
776
777 void addFrameEvents(
778 bool gpuComposited, uint64_t iOldFrame, int64_t iNewFrame) {
779 FrameEvents* oldFrame =
780 (iOldFrame == NO_FRAME_INDEX) ? nullptr : &mFrames[iOldFrame];
781 FrameEvents* newFrame = &mFrames[iNewFrame];
782
783 uint64_t nOldFrame = iOldFrame + 1;
784 uint64_t nNewFrame = iNewFrame + 1;
785
Brian Anderson4e606e32017-03-16 15:34:57 -0700786 // Latch, Composite, and Release the frames in a plausible order.
787 // Note: The timestamps won't necessarily match the order, but
Brian Anderson3da8d272016-07-28 16:20:47 -0700788 // that's okay for the purposes of this test.
789 std::shared_ptr<FenceTime> gpuDoneFenceTime = FenceTime::NO_FENCE;
790
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700791 // Composite the previous frame one more time, which helps verify
792 // LastRefresh is updated properly.
793 if (oldFrame != nullptr) {
794 mCfeh->addPreComposition(nOldFrame,
795 oldFrame->mRefreshes[2].kStartTime);
796 gpuDoneFenceTime = gpuComposited ?
797 oldFrame->mRefreshes[2].mGpuCompositionDone.mFenceTime :
798 FenceTime::NO_FENCE;
799 mCfeh->addPostComposition(nOldFrame, gpuDoneFenceTime,
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800800 oldFrame->mRefreshes[2].mPresent.mFenceTime,
801 oldFrame->mRefreshes[2].kCompositorTiming);
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700802 }
803
804 // Latch the new frame.
Brian Anderson3da8d272016-07-28 16:20:47 -0700805 mCfeh->addLatch(nNewFrame, newFrame->kLatchTime);
806
807 mCfeh->addPreComposition(nNewFrame, newFrame->mRefreshes[0].kStartTime);
808 gpuDoneFenceTime = gpuComposited ?
809 newFrame->mRefreshes[0].mGpuCompositionDone.mFenceTime :
810 FenceTime::NO_FENCE;
811 // HWC2 releases the previous buffer after a new latch just before
812 // calling postComposition.
813 if (oldFrame != nullptr) {
Brian Andersonf6386862016-10-31 16:34:13 -0700814 mCfeh->addRelease(nOldFrame, oldFrame->kDequeueReadyTime,
Brian Anderson3da8d272016-07-28 16:20:47 -0700815 std::shared_ptr<FenceTime>(oldFrame->mRelease.mFenceTime));
816 }
817 mCfeh->addPostComposition(nNewFrame, gpuDoneFenceTime,
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800818 newFrame->mRefreshes[0].mPresent.mFenceTime,
819 newFrame->mRefreshes[0].kCompositorTiming);
Brian Anderson3da8d272016-07-28 16:20:47 -0700820
Brian Anderson3da8d272016-07-28 16:20:47 -0700821 mCfeh->addPreComposition(nNewFrame, newFrame->mRefreshes[1].kStartTime);
822 gpuDoneFenceTime = gpuComposited ?
823 newFrame->mRefreshes[1].mGpuCompositionDone.mFenceTime :
824 FenceTime::NO_FENCE;
825 mCfeh->addPostComposition(nNewFrame, gpuDoneFenceTime,
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800826 newFrame->mRefreshes[1].mPresent.mFenceTime,
827 newFrame->mRefreshes[1].kCompositorTiming);
Brian Anderson3da8d272016-07-28 16:20:47 -0700828 }
829
Brian Anderson3da8d272016-07-28 16:20:47 -0700830 sp<IGraphicBufferProducer> mProducer;
831 sp<IGraphicBufferConsumer> mConsumer;
832 sp<FakeConsumer> mFakeConsumer;
833 ConsumerFrameEventHistory* mCfeh;
834 sp<TestSurface> mSurface;
835 sp<ANativeWindow> mWindow;
836
837 FenceToFenceTimeMap mFenceMap;
838
839 bool mFrameTimestampsEnabled = false;
840
841 int64_t outRequestedPresentTime = -1;
842 int64_t outAcquireTime = -1;
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700843 int64_t outLatchTime = -1;
844 int64_t outFirstRefreshStartTime = -1;
845 int64_t outLastRefreshStartTime = -1;
Brian Anderson3da8d272016-07-28 16:20:47 -0700846 int64_t outGpuCompositionDoneTime = -1;
847 int64_t outDisplayPresentTime = -1;
Brian Andersonf7fd56a2016-09-02 10:10:04 -0700848 int64_t outDequeueReadyTime = -1;
Brian Anderson3da8d272016-07-28 16:20:47 -0700849 int64_t outReleaseTime = -1;
850
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800851 FrameEvents mFrames[3] {
852 { mFenceMap, 1000 }, { mFenceMap, 2000 }, { mFenceMap, 3000 } };
Brian Anderson3da8d272016-07-28 16:20:47 -0700853};
854
855
856// This test verifies that the frame timestamps are not retrieved when not
857// explicitly enabled via native_window_enable_frame_timestamps.
858// We want to check this to make sure there's no overhead for users
859// that don't need the timestamp information.
860TEST_F(GetFrameTimestampsTest, DefaultDisabled) {
861 int fence;
862 ANativeWindowBuffer* buffer;
863
864 EXPECT_EQ(0, mFakeConsumer->mAddFrameTimestampsCount);
865 EXPECT_EQ(0, mFakeConsumer->mGetFrameTimestampsCount);
866
Brian Anderson1049d1d2016-12-16 17:25:57 -0800867 const uint64_t fId = getNextFrameId();
868
Brian Anderson3da8d272016-07-28 16:20:47 -0700869 // Verify the producer doesn't get frame timestamps piggybacked on dequeue.
870 ASSERT_EQ(NO_ERROR, mWindow->dequeueBuffer(mWindow.get(), &buffer, &fence));
871 EXPECT_EQ(0, mFakeConsumer->mAddFrameTimestampsCount);
872 EXPECT_EQ(0, mFakeConsumer->mGetFrameTimestampsCount);
873
874 // Verify the producer doesn't get frame timestamps piggybacked on queue.
875 // It is okay that frame timestamps are added in the consumer since it is
876 // still needed for SurfaceFlinger dumps.
877 ASSERT_EQ(NO_ERROR, mWindow->queueBuffer(mWindow.get(), buffer, fence));
878 EXPECT_EQ(1, mFakeConsumer->mAddFrameTimestampsCount);
879 EXPECT_EQ(0, mFakeConsumer->mGetFrameTimestampsCount);
880
881 // Verify attempts to get frame timestamps fail.
Brian Anderson1049d1d2016-12-16 17:25:57 -0800882 int result = getAllFrameTimestamps(fId);
Brian Anderson3da8d272016-07-28 16:20:47 -0700883 EXPECT_EQ(INVALID_OPERATION, result);
884 EXPECT_EQ(0, mFakeConsumer->mGetFrameTimestampsCount);
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800885
886 // Verify compositor timing query fails.
887 nsecs_t compositeDeadline = 0;
888 nsecs_t compositeInterval = 0;
889 nsecs_t compositeToPresentLatency = 0;
890 result = native_window_get_compositor_timing(mWindow.get(),
891 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
892 EXPECT_EQ(INVALID_OPERATION, result);
Brian Anderson3da8d272016-07-28 16:20:47 -0700893}
894
895// This test verifies that the frame timestamps are retrieved if explicitly
896// enabled via native_window_enable_frame_timestamps.
897TEST_F(GetFrameTimestampsTest, EnabledSimple) {
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800898 CompositorTiming initialCompositorTiming {
899 1000000000, // 1s deadline
900 16666667, // 16ms interval
901 50000000, // 50ms present latency
902 };
903 mCfeh->initializeCompositorTiming(initialCompositorTiming);
904
Brian Anderson3da8d272016-07-28 16:20:47 -0700905 enableFrameTimestamps();
906
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800907 // Verify the compositor timing query gets the initial compositor values
908 // after timststamps are enabled; even before the first frame is queued
909 // or dequeued.
910 nsecs_t compositeDeadline = 0;
911 nsecs_t compositeInterval = 0;
912 nsecs_t compositeToPresentLatency = 0;
913 mSurface->setNow(initialCompositorTiming.deadline - 1);
914 int result = native_window_get_compositor_timing(mWindow.get(),
915 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
916 EXPECT_EQ(NO_ERROR, result);
917 EXPECT_EQ(initialCompositorTiming.deadline, compositeDeadline);
918 EXPECT_EQ(initialCompositorTiming.interval, compositeInterval);
919 EXPECT_EQ(initialCompositorTiming.presentLatency,
920 compositeToPresentLatency);
921
Brian Anderson3da8d272016-07-28 16:20:47 -0700922 int fence;
923 ANativeWindowBuffer* buffer;
924
925 EXPECT_EQ(0, mFakeConsumer->mAddFrameTimestampsCount);
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800926 EXPECT_EQ(1, mFakeConsumer->mGetFrameTimestampsCount);
Brian Anderson3da8d272016-07-28 16:20:47 -0700927
Brian Anderson1049d1d2016-12-16 17:25:57 -0800928 const uint64_t fId1 = getNextFrameId();
929
Brian Anderson3da8d272016-07-28 16:20:47 -0700930 // Verify getFrameTimestamps is piggybacked on dequeue.
931 ASSERT_EQ(NO_ERROR, mWindow->dequeueBuffer(mWindow.get(), &buffer, &fence));
932 EXPECT_EQ(0, mFakeConsumer->mAddFrameTimestampsCount);
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800933 EXPECT_EQ(2, mFakeConsumer->mGetFrameTimestampsCount);
Brian Anderson3da8d272016-07-28 16:20:47 -0700934
935 NewFrameEventsEntry f1;
936 f1.frameNumber = 1;
937 f1.postedTime = mFrames[0].kPostedTime;
938 f1.requestedPresentTime = mFrames[0].kRequestedPresentTime;
939 f1.acquireFence = mFrames[0].mAcquireConsumer.mFenceTime;
940 mSurface->mFakeFrameEventHistory->setAcquireFenceOverride(
941 mFrames[0].mAcquireProducer.mFenceTime,
942 mFrames[0].mAcquireConsumer.mFenceTime);
943 mFakeConsumer->mNewFrameEntryOverride = f1;
944 mFrames[0].signalQueueFences();
945
946 // Verify getFrameTimestamps is piggybacked on queue.
947 ASSERT_EQ(NO_ERROR, mWindow->queueBuffer(mWindow.get(), buffer, fence));
948 EXPECT_EQ(1, mFakeConsumer->mAddFrameTimestampsCount);
949 EXPECT_EQ(1u, mFakeConsumer->mLastAddedFrameNumber);
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800950 EXPECT_EQ(3, mFakeConsumer->mGetFrameTimestampsCount);
Brian Anderson3da8d272016-07-28 16:20:47 -0700951
952 // Verify queries for timestamps that the producer doesn't know about
953 // triggers a call to see if the consumer has any new timestamps.
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800954 result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -0700955 EXPECT_EQ(NO_ERROR, result);
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800956 EXPECT_EQ(4, mFakeConsumer->mGetFrameTimestampsCount);
Brian Anderson3da8d272016-07-28 16:20:47 -0700957}
958
Brian Anderson6b376712017-04-04 10:51:39 -0700959TEST_F(GetFrameTimestampsTest, QueryPresentSupported) {
960 bool displayPresentSupported = true;
961 mSurface->mFakeSurfaceComposer->setSupportsPresent(displayPresentSupported);
962
963 // Verify supported bits are forwarded.
964 int supportsPresent = -1;
965 mWindow.get()->query(mWindow.get(),
966 NATIVE_WINDOW_FRAME_TIMESTAMPS_SUPPORTS_PRESENT, &supportsPresent);
967 EXPECT_EQ(displayPresentSupported, supportsPresent);
968}
969
970TEST_F(GetFrameTimestampsTest, QueryPresentNotSupported) {
971 bool displayPresentSupported = false;
972 mSurface->mFakeSurfaceComposer->setSupportsPresent(displayPresentSupported);
973
974 // Verify supported bits are forwarded.
975 int supportsPresent = -1;
976 mWindow.get()->query(mWindow.get(),
977 NATIVE_WINDOW_FRAME_TIMESTAMPS_SUPPORTS_PRESENT, &supportsPresent);
978 EXPECT_EQ(displayPresentSupported, supportsPresent);
979}
980
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800981TEST_F(GetFrameTimestampsTest, SnapToNextTickBasic) {
982 nsecs_t phase = 4000;
983 nsecs_t interval = 1000;
984
985 // Timestamp in previous interval.
986 nsecs_t timestamp = 3500;
987 EXPECT_EQ(4000, ProducerFrameEventHistory::snapToNextTick(
988 timestamp, phase, interval));
989
990 // Timestamp in next interval.
991 timestamp = 4500;
992 EXPECT_EQ(5000, ProducerFrameEventHistory::snapToNextTick(
993 timestamp, phase, interval));
994
995 // Timestamp multiple intervals before.
996 timestamp = 2500;
997 EXPECT_EQ(3000, ProducerFrameEventHistory::snapToNextTick(
998 timestamp, phase, interval));
999
1000 // Timestamp multiple intervals after.
1001 timestamp = 6500;
1002 EXPECT_EQ(7000, ProducerFrameEventHistory::snapToNextTick(
1003 timestamp, phase, interval));
1004
1005 // Timestamp on previous interval.
1006 timestamp = 3000;
1007 EXPECT_EQ(3000, ProducerFrameEventHistory::snapToNextTick(
1008 timestamp, phase, interval));
1009
1010 // Timestamp on next interval.
1011 timestamp = 5000;
1012 EXPECT_EQ(5000, ProducerFrameEventHistory::snapToNextTick(
1013 timestamp, phase, interval));
1014
1015 // Timestamp equal to phase.
1016 timestamp = 4000;
1017 EXPECT_EQ(4000, ProducerFrameEventHistory::snapToNextTick(
1018 timestamp, phase, interval));
1019}
1020
1021// int(big_timestamp / interval) < 0, which can cause a crash or invalid result
1022// if the number of intervals elapsed is internally stored in an int.
1023TEST_F(GetFrameTimestampsTest, SnapToNextTickOverflow) {
1024 nsecs_t phase = 0;
1025 nsecs_t interval = 4000;
1026 nsecs_t big_timestamp = 8635916564000;
1027 int32_t intervals = big_timestamp / interval;
1028
1029 EXPECT_LT(intervals, 0);
1030 EXPECT_EQ(8635916564000, ProducerFrameEventHistory::snapToNextTick(
1031 big_timestamp, phase, interval));
1032 EXPECT_EQ(8635916564000, ProducerFrameEventHistory::snapToNextTick(
1033 big_timestamp, big_timestamp, interval));
1034}
1035
1036// This verifies the compositor timing is updated by refresh events
1037// and piggy backed on a queue, dequeue, and enabling of timestamps..
1038TEST_F(GetFrameTimestampsTest, CompositorTimingUpdatesBasic) {
1039 CompositorTiming initialCompositorTiming {
1040 1000000000, // 1s deadline
1041 16666667, // 16ms interval
1042 50000000, // 50ms present latency
1043 };
1044 mCfeh->initializeCompositorTiming(initialCompositorTiming);
1045
1046 enableFrameTimestamps();
1047
1048 // We get the initial values before any frames are submitted.
1049 nsecs_t compositeDeadline = 0;
1050 nsecs_t compositeInterval = 0;
1051 nsecs_t compositeToPresentLatency = 0;
1052 mSurface->setNow(initialCompositorTiming.deadline - 1);
1053 int result = native_window_get_compositor_timing(mWindow.get(),
1054 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1055 EXPECT_EQ(NO_ERROR, result);
1056 EXPECT_EQ(initialCompositorTiming.deadline, compositeDeadline);
1057 EXPECT_EQ(initialCompositorTiming.interval, compositeInterval);
1058 EXPECT_EQ(initialCompositorTiming.presentLatency,
1059 compositeToPresentLatency);
1060
1061 const uint64_t fId1 = getNextFrameId();
1062 dequeueAndQueue(0);
1063 addFrameEvents(true, NO_FRAME_INDEX, 0);
1064
1065 // Still get the initial values because the frame events for frame 0
1066 // didn't get a chance to piggyback on a queue or dequeue yet.
1067 result = native_window_get_compositor_timing(mWindow.get(),
1068 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1069 EXPECT_EQ(NO_ERROR, result);
1070 EXPECT_EQ(initialCompositorTiming.deadline, compositeDeadline);
1071 EXPECT_EQ(initialCompositorTiming.interval, compositeInterval);
1072 EXPECT_EQ(initialCompositorTiming.presentLatency,
1073 compositeToPresentLatency);
1074
1075 const uint64_t fId2 = getNextFrameId();
1076 dequeueAndQueue(1);
1077 addFrameEvents(true, 0, 1);
1078
1079 // Now expect the composite values associated with frame 1.
1080 mSurface->setNow(mFrames[0].mRefreshes[1].kCompositorTiming.deadline);
1081 result = native_window_get_compositor_timing(mWindow.get(),
1082 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1083 EXPECT_EQ(NO_ERROR, result);
1084 EXPECT_EQ(mFrames[0].mRefreshes[1].kCompositorTiming.deadline,
1085 compositeDeadline);
1086 EXPECT_EQ(mFrames[0].mRefreshes[1].kCompositorTiming.interval,
1087 compositeInterval);
1088 EXPECT_EQ(mFrames[0].mRefreshes[1].kCompositorTiming.presentLatency,
1089 compositeToPresentLatency);
1090
1091 dequeueAndQueue(2);
1092 addFrameEvents(true, 1, 2);
1093
1094 // Now expect the composite values associated with frame 2.
1095 mSurface->setNow(mFrames[1].mRefreshes[1].kCompositorTiming.deadline);
1096 result = native_window_get_compositor_timing(mWindow.get(),
1097 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1098 EXPECT_EQ(NO_ERROR, result);
1099 EXPECT_EQ(mFrames[1].mRefreshes[1].kCompositorTiming.deadline,
1100 compositeDeadline);
1101 EXPECT_EQ(mFrames[1].mRefreshes[1].kCompositorTiming.interval,
1102 compositeInterval);
1103 EXPECT_EQ(mFrames[1].mRefreshes[1].kCompositorTiming.presentLatency,
1104 compositeToPresentLatency);
1105
1106 // Re-enabling frame timestamps should get the latest values.
1107 disableFrameTimestamps();
1108 enableFrameTimestamps();
1109
1110 // Now expect the composite values associated with frame 3.
1111 mSurface->setNow(mFrames[2].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[2].mRefreshes[1].kCompositorTiming.deadline,
1116 compositeDeadline);
1117 EXPECT_EQ(mFrames[2].mRefreshes[1].kCompositorTiming.interval,
1118 compositeInterval);
1119 EXPECT_EQ(mFrames[2].mRefreshes[1].kCompositorTiming.presentLatency,
1120 compositeToPresentLatency);
1121}
1122
1123// This verifies the compositor deadline properly snaps to the the next
1124// deadline based on the current time.
1125TEST_F(GetFrameTimestampsTest, CompositorTimingDeadlineSnaps) {
1126 CompositorTiming initialCompositorTiming {
1127 1000000000, // 1s deadline
1128 16666667, // 16ms interval
1129 50000000, // 50ms present latency
1130 };
1131 mCfeh->initializeCompositorTiming(initialCompositorTiming);
1132
1133 enableFrameTimestamps();
1134
1135 nsecs_t compositeDeadline = 0;
1136 nsecs_t compositeInterval = 0;
1137 nsecs_t compositeToPresentLatency = 0;
1138
1139 // A "now" just before the deadline snaps to the deadline.
1140 mSurface->setNow(initialCompositorTiming.deadline - 1);
1141 int result = native_window_get_compositor_timing(mWindow.get(),
1142 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1143 EXPECT_EQ(NO_ERROR, result);
1144 EXPECT_EQ(initialCompositorTiming.deadline, compositeDeadline);
1145 nsecs_t expectedDeadline = initialCompositorTiming.deadline;
1146 EXPECT_EQ(expectedDeadline, compositeDeadline);
1147
1148 const uint64_t fId1 = getNextFrameId();
1149 dequeueAndQueue(0);
1150 addFrameEvents(true, NO_FRAME_INDEX, 0);
1151
1152 // A "now" just after the deadline snaps properly.
1153 mSurface->setNow(initialCompositorTiming.deadline + 1);
1154 result = native_window_get_compositor_timing(mWindow.get(),
1155 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1156 EXPECT_EQ(NO_ERROR, result);
1157 expectedDeadline =
1158 initialCompositorTiming.deadline +initialCompositorTiming.interval;
1159 EXPECT_EQ(expectedDeadline, compositeDeadline);
1160
1161 const uint64_t fId2 = getNextFrameId();
1162 dequeueAndQueue(1);
1163 addFrameEvents(true, 0, 1);
1164
1165 // A "now" just after the next interval snaps properly.
1166 mSurface->setNow(
1167 mFrames[0].mRefreshes[1].kCompositorTiming.deadline +
1168 mFrames[0].mRefreshes[1].kCompositorTiming.interval + 1);
1169 result = native_window_get_compositor_timing(mWindow.get(),
1170 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1171 EXPECT_EQ(NO_ERROR, result);
1172 expectedDeadline =
1173 mFrames[0].mRefreshes[1].kCompositorTiming.deadline +
1174 mFrames[0].mRefreshes[1].kCompositorTiming.interval * 2;
1175 EXPECT_EQ(expectedDeadline, compositeDeadline);
1176
1177 dequeueAndQueue(2);
1178 addFrameEvents(true, 1, 2);
1179
1180 // A "now" over 1 interval before the deadline snaps properly.
1181 mSurface->setNow(
1182 mFrames[1].mRefreshes[1].kCompositorTiming.deadline -
1183 mFrames[1].mRefreshes[1].kCompositorTiming.interval - 1);
1184 result = native_window_get_compositor_timing(mWindow.get(),
1185 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1186 EXPECT_EQ(NO_ERROR, result);
1187 expectedDeadline =
1188 mFrames[1].mRefreshes[1].kCompositorTiming.deadline -
1189 mFrames[1].mRefreshes[1].kCompositorTiming.interval;
1190 EXPECT_EQ(expectedDeadline, compositeDeadline);
1191
1192 // Re-enabling frame timestamps should get the latest values.
1193 disableFrameTimestamps();
1194 enableFrameTimestamps();
1195
1196 // A "now" over 2 intervals before the deadline snaps properly.
1197 mSurface->setNow(
1198 mFrames[2].mRefreshes[1].kCompositorTiming.deadline -
1199 mFrames[2].mRefreshes[1].kCompositorTiming.interval * 2 - 1);
1200 result = native_window_get_compositor_timing(mWindow.get(),
1201 &compositeDeadline, &compositeInterval, &compositeToPresentLatency);
1202 EXPECT_EQ(NO_ERROR, result);
1203 expectedDeadline =
1204 mFrames[2].mRefreshes[1].kCompositorTiming.deadline -
1205 mFrames[2].mRefreshes[1].kCompositorTiming.interval * 2;
1206 EXPECT_EQ(expectedDeadline, compositeDeadline);
1207}
1208
Brian Anderson1049d1d2016-12-16 17:25:57 -08001209// This verifies the timestamps recorded in the consumer's
1210// FrameTimestampsHistory are properly retrieved by the producer for the
1211// correct frames.
Brian Anderson3da8d272016-07-28 16:20:47 -07001212TEST_F(GetFrameTimestampsTest, TimestampsAssociatedWithCorrectFrame) {
1213 enableFrameTimestamps();
1214
Brian Anderson1049d1d2016-12-16 17:25:57 -08001215 const uint64_t fId1 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001216 dequeueAndQueue(0);
1217 mFrames[0].signalQueueFences();
1218
Brian Anderson1049d1d2016-12-16 17:25:57 -08001219 const uint64_t fId2 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001220 dequeueAndQueue(1);
1221 mFrames[1].signalQueueFences();
1222
1223 addFrameEvents(true, NO_FRAME_INDEX, 0);
1224 mFrames[0].signalRefreshFences();
1225 addFrameEvents(true, 0, 1);
1226 mFrames[0].signalReleaseFences();
1227 mFrames[1].signalRefreshFences();
1228
1229 // Verify timestamps are correct for frame 1.
Brian Anderson3da8d272016-07-28 16:20:47 -07001230 resetTimestamps();
Brian Anderson1049d1d2016-12-16 17:25:57 -08001231 int result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001232 EXPECT_EQ(NO_ERROR, result);
1233 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1234 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001235 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1236 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1237 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001238 EXPECT_EQ(mFrames[0].mRefreshes[0].kGpuCompositionDoneTime,
1239 outGpuCompositionDoneTime);
1240 EXPECT_EQ(mFrames[0].mRefreshes[0].kPresentTime, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001241 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001242 EXPECT_EQ(mFrames[0].kReleaseTime, outReleaseTime);
1243
1244 // Verify timestamps are correct for frame 2.
Brian Anderson3da8d272016-07-28 16:20:47 -07001245 resetTimestamps();
Brian Anderson1049d1d2016-12-16 17:25:57 -08001246 result = getAllFrameTimestamps(fId2);
Brian Anderson3da8d272016-07-28 16:20:47 -07001247 EXPECT_EQ(NO_ERROR, result);
1248 EXPECT_EQ(mFrames[1].kRequestedPresentTime, outRequestedPresentTime);
1249 EXPECT_EQ(mFrames[1].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001250 EXPECT_EQ(mFrames[1].kLatchTime, outLatchTime);
1251 EXPECT_EQ(mFrames[1].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1252 EXPECT_EQ(mFrames[1].mRefreshes[1].kStartTime, outLastRefreshStartTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001253 EXPECT_EQ(mFrames[1].mRefreshes[0].kGpuCompositionDoneTime,
1254 outGpuCompositionDoneTime);
1255 EXPECT_EQ(mFrames[1].mRefreshes[0].kPresentTime, outDisplayPresentTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001256 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDequeueReadyTime);
1257 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001258}
1259
1260// This test verifies the acquire fence recorded by the consumer is not sent
1261// back to the producer and the producer saves its own fence.
1262TEST_F(GetFrameTimestampsTest, QueueTimestampsNoSync) {
1263 enableFrameTimestamps();
Brian Anderson3da8d272016-07-28 16:20:47 -07001264
Brian Anderson3da8d272016-07-28 16:20:47 -07001265 // Dequeue and queue frame 1.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001266 const uint64_t fId1 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001267 dequeueAndQueue(0);
1268
1269 // Verify queue-related timestamps for f1 are available immediately in the
1270 // producer without asking the consumer again, even before signaling the
1271 // acquire fence.
1272 resetTimestamps();
1273 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001274 int result = native_window_get_frame_timestamps(mWindow.get(), fId1,
Brian Anderson3da8d272016-07-28 16:20:47 -07001275 &outRequestedPresentTime, &outAcquireTime, nullptr, nullptr,
Brian Anderson4e606e32017-03-16 15:34:57 -07001276 nullptr, nullptr, nullptr, nullptr, nullptr);
Brian Anderson3da8d272016-07-28 16:20:47 -07001277 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1278 EXPECT_EQ(NO_ERROR, result);
1279 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001280 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outAcquireTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001281
1282 // Signal acquire fences. Verify a sync call still isn't necessary.
1283 mFrames[0].signalQueueFences();
1284
1285 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001286 result = native_window_get_frame_timestamps(mWindow.get(), fId1,
Brian Anderson3da8d272016-07-28 16:20:47 -07001287 &outRequestedPresentTime, &outAcquireTime, nullptr, nullptr,
Brian Anderson4e606e32017-03-16 15:34:57 -07001288 nullptr, nullptr, nullptr, nullptr, nullptr);
Brian Anderson3da8d272016-07-28 16:20:47 -07001289 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1290 EXPECT_EQ(NO_ERROR, result);
1291 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1292 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
1293
1294 // Dequeue and queue frame 2.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001295 const uint64_t fId2 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001296 dequeueAndQueue(1);
1297
1298 // Verify queue-related timestamps for f2 are available immediately in the
1299 // producer without asking the consumer again, even before signaling the
1300 // acquire fence.
1301 resetTimestamps();
1302 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001303 result = native_window_get_frame_timestamps(mWindow.get(), fId2,
Brian Anderson3da8d272016-07-28 16:20:47 -07001304 &outRequestedPresentTime, &outAcquireTime, nullptr, nullptr,
Brian Anderson4e606e32017-03-16 15:34:57 -07001305 nullptr, nullptr, nullptr, nullptr, nullptr);
Brian Anderson3da8d272016-07-28 16:20:47 -07001306 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1307 EXPECT_EQ(NO_ERROR, result);
1308 EXPECT_EQ(mFrames[1].kRequestedPresentTime, outRequestedPresentTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001309 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outAcquireTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001310
1311 // Signal acquire fences. Verify a sync call still isn't necessary.
1312 mFrames[1].signalQueueFences();
1313
1314 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001315 result = native_window_get_frame_timestamps(mWindow.get(), fId2,
Brian Anderson3da8d272016-07-28 16:20:47 -07001316 &outRequestedPresentTime, &outAcquireTime, nullptr, nullptr,
Brian Anderson4e606e32017-03-16 15:34:57 -07001317 nullptr, nullptr, nullptr, nullptr, nullptr);
Brian Anderson3da8d272016-07-28 16:20:47 -07001318 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1319 EXPECT_EQ(NO_ERROR, result);
1320 EXPECT_EQ(mFrames[1].kRequestedPresentTime, outRequestedPresentTime);
1321 EXPECT_EQ(mFrames[1].kProducerAcquireTime, outAcquireTime);
1322}
1323
1324TEST_F(GetFrameTimestampsTest, ZeroRequestedTimestampsNoSync) {
1325 enableFrameTimestamps();
Brian Anderson3da8d272016-07-28 16:20:47 -07001326
1327 // Dequeue and queue frame 1.
1328 dequeueAndQueue(0);
1329 mFrames[0].signalQueueFences();
1330
1331 // Dequeue and queue frame 2.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001332 const uint64_t fId2 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001333 dequeueAndQueue(1);
1334 mFrames[1].signalQueueFences();
1335
1336 addFrameEvents(true, NO_FRAME_INDEX, 0);
1337 mFrames[0].signalRefreshFences();
1338 addFrameEvents(true, 0, 1);
1339 mFrames[0].signalReleaseFences();
1340 mFrames[1].signalRefreshFences();
1341
1342 // Verify a request for no timestamps doesn't result in a sync call.
Brian Anderson3da8d272016-07-28 16:20:47 -07001343 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001344 int result = native_window_get_frame_timestamps(mWindow.get(), fId2,
Brian Anderson6b376712017-04-04 10:51:39 -07001345 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
1346 nullptr, nullptr);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001347 EXPECT_EQ(NO_ERROR, result);
Brian Anderson3da8d272016-07-28 16:20:47 -07001348 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1349}
1350
1351// This test verifies that fences can signal and update timestamps producer
1352// side without an additional sync call to the consumer.
1353TEST_F(GetFrameTimestampsTest, FencesInProducerNoSync) {
1354 enableFrameTimestamps();
Brian Anderson3da8d272016-07-28 16:20:47 -07001355
1356 // Dequeue and queue frame 1.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001357 const uint64_t fId1 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001358 dequeueAndQueue(0);
1359 mFrames[0].signalQueueFences();
1360
1361 // Dequeue and queue frame 2.
1362 dequeueAndQueue(1);
1363 mFrames[1].signalQueueFences();
1364
1365 addFrameEvents(true, NO_FRAME_INDEX, 0);
1366 addFrameEvents(true, 0, 1);
1367
1368 // Verify available timestamps are correct for frame 1, before any
1369 // fence has been signaled.
1370 // Note: A sync call is necessary here since the events triggered by
1371 // addFrameEvents didn't get to piggyback on the earlier queues/dequeues.
Brian Anderson3da8d272016-07-28 16:20:47 -07001372 resetTimestamps();
1373 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001374 int result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001375 EXPECT_EQ(oldCount + 1, mFakeConsumer->mGetFrameTimestampsCount);
1376 EXPECT_EQ(NO_ERROR, result);
1377 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1378 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001379 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1380 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1381 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001382 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outGpuCompositionDoneTime);
1383 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001384 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001385 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001386
1387 // Verify available timestamps are correct for frame 1 again, before any
1388 // fence has been signaled.
1389 // This time a sync call should not be necessary.
Brian Anderson3da8d272016-07-28 16:20:47 -07001390 resetTimestamps();
1391 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001392 result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001393 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1394 EXPECT_EQ(NO_ERROR, result);
1395 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1396 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001397 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1398 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1399 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001400 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outGpuCompositionDoneTime);
1401 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001402 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001403 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001404
1405 // Signal the fences for frame 1.
1406 mFrames[0].signalRefreshFences();
1407 mFrames[0].signalReleaseFences();
1408
1409 // Verify all timestamps are available without a sync call.
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 Anderson3da8d272016-07-28 16:20:47 -07001420 EXPECT_EQ(mFrames[0].mRefreshes[0].kGpuCompositionDoneTime,
1421 outGpuCompositionDoneTime);
1422 EXPECT_EQ(mFrames[0].mRefreshes[0].kPresentTime, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001423 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001424 EXPECT_EQ(mFrames[0].kReleaseTime, outReleaseTime);
1425}
1426
1427// This test verifies that if the frame wasn't GPU composited but has a refresh
1428// event a sync call isn't made to get the GPU composite done time since it will
1429// never exist.
1430TEST_F(GetFrameTimestampsTest, NoGpuNoSync) {
1431 enableFrameTimestamps();
Brian Anderson3da8d272016-07-28 16:20:47 -07001432
Brian Anderson3da8d272016-07-28 16:20:47 -07001433 // Dequeue and queue frame 1.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001434 const uint64_t fId1 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001435 dequeueAndQueue(0);
1436 mFrames[0].signalQueueFences();
1437
1438 // Dequeue and queue frame 2.
1439 dequeueAndQueue(1);
1440 mFrames[1].signalQueueFences();
1441
1442 addFrameEvents(false, NO_FRAME_INDEX, 0);
1443 addFrameEvents(false, 0, 1);
1444
1445 // Verify available timestamps are correct for frame 1, before any
1446 // fence has been signaled.
1447 // Note: A sync call is necessary here since the events triggered by
1448 // addFrameEvents didn't get to piggyback on the earlier queues/dequeues.
1449 resetTimestamps();
1450 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001451 int result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001452 EXPECT_EQ(oldCount + 1, mFakeConsumer->mGetFrameTimestampsCount);
1453 EXPECT_EQ(NO_ERROR, result);
1454 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1455 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001456 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1457 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1458 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001459 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_INVALID, outGpuCompositionDoneTime);
1460 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001461 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001462 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001463
1464 // Signal the fences for frame 1.
1465 mFrames[0].signalRefreshFences();
1466 mFrames[0].signalReleaseFences();
1467
1468 // Verify all timestamps, except GPU composition, are available without a
1469 // sync call.
1470 resetTimestamps();
1471 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001472 result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001473 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1474 EXPECT_EQ(NO_ERROR, result);
1475 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1476 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001477 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1478 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1479 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001480 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_INVALID, outGpuCompositionDoneTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001481 EXPECT_EQ(mFrames[0].mRefreshes[0].kPresentTime, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001482 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001483 EXPECT_EQ(mFrames[0].kReleaseTime, outReleaseTime);
1484}
1485
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001486// This test verifies that if the certain timestamps can't possibly exist for
1487// the most recent frame, then a sync call is not done.
Brian Anderson6b376712017-04-04 10:51:39 -07001488TEST_F(GetFrameTimestampsTest, NoReleaseNoSync) {
Brian Anderson3da8d272016-07-28 16:20:47 -07001489 enableFrameTimestamps();
Brian Anderson3da8d272016-07-28 16:20:47 -07001490
1491 // Dequeue and queue frame 1.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001492 const uint64_t fId1 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001493 dequeueAndQueue(0);
1494 mFrames[0].signalQueueFences();
1495
1496 // Dequeue and queue frame 2.
Brian Anderson1049d1d2016-12-16 17:25:57 -08001497 const uint64_t fId2 = getNextFrameId();
Brian Anderson3da8d272016-07-28 16:20:47 -07001498 dequeueAndQueue(1);
1499 mFrames[1].signalQueueFences();
1500
1501 addFrameEvents(false, NO_FRAME_INDEX, 0);
1502 addFrameEvents(false, 0, 1);
1503
1504 // Verify available timestamps are correct for frame 1, before any
1505 // fence has been signaled.
1506 // Note: A sync call is necessary here since the events triggered by
1507 // addFrameEvents didn't get to piggyback on the earlier queues/dequeues.
Brian Anderson3da8d272016-07-28 16:20:47 -07001508 resetTimestamps();
1509 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001510 int result = getAllFrameTimestamps(fId1);
Brian Anderson3da8d272016-07-28 16:20:47 -07001511 EXPECT_EQ(oldCount + 1, mFakeConsumer->mGetFrameTimestampsCount);
1512 EXPECT_EQ(NO_ERROR, result);
1513 EXPECT_EQ(mFrames[0].kRequestedPresentTime, outRequestedPresentTime);
1514 EXPECT_EQ(mFrames[0].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001515 EXPECT_EQ(mFrames[0].kLatchTime, outLatchTime);
1516 EXPECT_EQ(mFrames[0].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1517 EXPECT_EQ(mFrames[0].mRefreshes[2].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001518 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_INVALID, outGpuCompositionDoneTime);
1519 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDisplayPresentTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001520 EXPECT_EQ(mFrames[0].kDequeueReadyTime, outDequeueReadyTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001521 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001522
1523 mFrames[0].signalRefreshFences();
1524 mFrames[0].signalReleaseFences();
1525 mFrames[1].signalRefreshFences();
1526
Brian Anderson1049d1d2016-12-16 17:25:57 -08001527 // Verify querying for all timestmaps of f2 does not do a sync call. Even
Brian Anderson4e606e32017-03-16 15:34:57 -07001528 // though the lastRefresh, dequeueReady, and release times aren't
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001529 // available, a sync call should not occur because it's not possible for f2
1530 // to encounter the final value for those events until another frame is
1531 // queued.
Brian Anderson3da8d272016-07-28 16:20:47 -07001532 resetTimestamps();
1533 oldCount = mFakeConsumer->mGetFrameTimestampsCount;
Brian Anderson1049d1d2016-12-16 17:25:57 -08001534 result = getAllFrameTimestamps(fId2);
Brian Anderson3da8d272016-07-28 16:20:47 -07001535 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1536 EXPECT_EQ(NO_ERROR, result);
1537 EXPECT_EQ(mFrames[1].kRequestedPresentTime, outRequestedPresentTime);
1538 EXPECT_EQ(mFrames[1].kProducerAcquireTime, outAcquireTime);
Brian Andersonf7fd56a2016-09-02 10:10:04 -07001539 EXPECT_EQ(mFrames[1].kLatchTime, outLatchTime);
1540 EXPECT_EQ(mFrames[1].mRefreshes[0].kStartTime, outFirstRefreshStartTime);
1541 EXPECT_EQ(mFrames[1].mRefreshes[1].kStartTime, outLastRefreshStartTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001542 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_INVALID, outGpuCompositionDoneTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001543 EXPECT_EQ(mFrames[1].mRefreshes[0].kPresentTime, outDisplayPresentTime);
Brian Andersondc96fdf2017-03-20 16:54:25 -07001544 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outDequeueReadyTime);
1545 EXPECT_EQ(NATIVE_WINDOW_TIMESTAMP_PENDING, outReleaseTime);
Brian Anderson3da8d272016-07-28 16:20:47 -07001546}
1547
Brian Anderson6b376712017-04-04 10:51:39 -07001548// This test verifies there are no sync calls for present times
1549// when they aren't supported and that an error is returned.
1550
1551TEST_F(GetFrameTimestampsTest, PresentUnsupportedNoSync) {
1552 enableFrameTimestamps();
1553 mSurface->mFakeSurfaceComposer->setSupportsPresent(false);
1554
1555 // Dequeue and queue frame 1.
1556 const uint64_t fId1 = getNextFrameId();
1557 dequeueAndQueue(0);
1558
1559 // Verify a query for the Present times do not trigger a sync call if they
1560 // are not supported.
1561 resetTimestamps();
1562 int oldCount = mFakeConsumer->mGetFrameTimestampsCount;
1563 int result = native_window_get_frame_timestamps(mWindow.get(), fId1,
1564 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
1565 &outDisplayPresentTime, nullptr, nullptr);
1566 EXPECT_EQ(oldCount, mFakeConsumer->mGetFrameTimestampsCount);
1567 EXPECT_EQ(BAD_VALUE, result);
1568 EXPECT_EQ(-1, outDisplayPresentTime);
1569}
1570
Jamie Gennis134f0422011-03-08 12:18:54 -08001571}