blob: 48424fb92da8d92fc32eb77dd557ee0d7ce18120 [file] [log] [blame]
Lloyd Piquef58625d2017-12-19 13:22:33 -08001/*
2 * Copyright (C) 2018 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
17#undef LOG_TAG
18#define LOG_TAG "LibSurfaceFlingerUnittests"
19
20#include <gmock/gmock.h>
21#include <gtest/gtest.h>
22
23#include <log/log.h>
24
25#include "TestableSurfaceFlinger.h"
Lloyd Piquecbe00012018-02-02 15:40:42 -080026#include "mock/DisplayHardware/MockComposer.h"
27#include "mock/DisplayHardware/MockDisplaySurface.h"
28#include "mock/MockEventControlThread.h"
29#include "mock/MockEventThread.h"
30#include "mock/MockMessageQueue.h"
31#include "mock/MockNativeWindowSurface.h"
32#include "mock/MockSurfaceInterceptor.h"
33#include "mock/RenderEngine/MockRenderEngine.h"
34#include "mock/gui/MockGraphicBufferConsumer.h"
35#include "mock/gui/MockGraphicBufferProducer.h"
36#include "mock/system/window/MockNativeWindow.h"
Lloyd Piquef58625d2017-12-19 13:22:33 -080037
38namespace android {
39namespace {
40
Lloyd Piquee39cad22017-12-20 17:01:29 -080041using testing::_;
42using testing::ByMove;
43using testing::DoAll;
44using testing::Mock;
45using testing::Return;
46using testing::SetArgPointee;
47
48using android::hardware::graphics::common::V1_0::Hdr;
Peiyong Lin0e7a7912018-04-05 14:36:36 -070049using android::hardware::graphics::common::V1_1::ColorMode;
Lloyd Piquee39cad22017-12-20 17:01:29 -080050using android::Hwc2::Error;
51using android::Hwc2::IComposer;
52using android::Hwc2::IComposerClient;
53
Lloyd Piquebc792092018-01-17 11:52:30 -080054using HWC2Display = TestableSurfaceFlinger::HWC2Display;
Lloyd Pique1fa4d462018-01-22 18:03:16 -080055using HotplugEvent = TestableSurfaceFlinger::HotplugEvent;
Lloyd Piquebc792092018-01-17 11:52:30 -080056
Lloyd Piquee39cad22017-12-20 17:01:29 -080057constexpr int32_t DEFAULT_REFRESH_RATE = 1666666666;
58constexpr int32_t DEFAULT_DPI = 320;
59
Lloyd Pique1fa4d462018-01-22 18:03:16 -080060constexpr int DEFAULT_CONFIG_ID = 0;
61
Lloyd Piquef58625d2017-12-19 13:22:33 -080062class DisplayTransactionTest : public testing::Test {
63protected:
64 DisplayTransactionTest();
65 ~DisplayTransactionTest() override;
66
Lloyd Pique1fa4d462018-01-22 18:03:16 -080067 // --------------------------------------------------------------------
68 // Precondition helpers
Lloyd Piquef58625d2017-12-19 13:22:33 -080069
Lloyd Pique1fa4d462018-01-22 18:03:16 -080070 void setupComposer(int virtualDisplayCount);
71 void setupFakeHwcDisplay(hwc2_display_t displayId, DisplayDevice::DisplayType type, int width,
72 int height);
73
74 struct FakeDisplayDeviceFactory {
75 public:
76 FakeDisplayDeviceFactory(TestableSurfaceFlinger& flinger, sp<BBinder>& displayToken,
77 DisplayDevice::DisplayType type, int hwcId)
78 : mFlinger(flinger), mDisplayToken(displayToken), mType(type), mHwcId(hwcId) {}
79
80 sp<DisplayDevice> build() {
81 return new DisplayDevice(mFlinger.mFlinger.get(), mType, mHwcId, false, mDisplayToken,
82 mNativeWindow, mDisplaySurface, std::move(mRenderSurface), 0,
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -070083 0, false, {}, 0, HWC_POWER_MODE_NORMAL);
Lloyd Pique1fa4d462018-01-22 18:03:16 -080084 }
85
86 FakeDisplayDeviceFactory& setNativeWindow(const sp<ANativeWindow>& nativeWindow) {
87 mNativeWindow = nativeWindow;
88 return *this;
89 }
90
91 FakeDisplayDeviceFactory& setDisplaySurface(const sp<DisplaySurface>& displaySurface) {
92 mDisplaySurface = displaySurface;
93 return *this;
94 }
95
96 FakeDisplayDeviceFactory& setRenderSurface(std::unique_ptr<RE::Surface> renderSurface) {
97 mRenderSurface = std::move(renderSurface);
98 return *this;
99 }
100
101 TestableSurfaceFlinger& mFlinger;
102 sp<BBinder>& mDisplayToken;
103 DisplayDevice::DisplayType mType;
104 int mHwcId;
105 sp<ANativeWindow> mNativeWindow;
106 sp<DisplaySurface> mDisplaySurface;
107 std::unique_ptr<RE::Surface> mRenderSurface;
108 };
109
110 sp<BBinder> setupFakeExistingPhysicalDisplay(hwc2_display_t displayId,
111 DisplayDevice::DisplayType type);
112
113 void setupFakeBufferQueueFactory();
114 void setupFakeNativeWindowSurfaceFactory(int displayWidth, int displayHeight, bool critical,
115 bool async);
116 void expectFramebufferUsageSet(int width, int height, int grallocUsage);
117 void expectHwcHotplugCalls(hwc2_display_t displayId, int displayWidth, int displayHeight);
118
119 // --------------------------------------------------------------------
120 // Call expectation helpers
121
122 void expectRESurfaceCreationCalls();
123 void expectPhysicalDisplayDeviceCreationCalls(hwc2_display_t displayId, int displayWidth,
124 int displayHeight, bool critical, bool async);
125
126 // --------------------------------------------------------------------
127 // Postcondition helpers
128
129 bool hasTransactionFlagSet(int flag);
130 bool hasDisplayDevice(sp<IBinder> displayToken);
131 sp<DisplayDevice> getDisplayDevice(sp<IBinder> displayToken);
132 bool hasCurrentDisplayState(sp<IBinder> displayToken);
133 const DisplayDeviceState& getCurrentDisplayState(sp<IBinder> displayToken);
134 bool hasDrawingDisplayState(sp<IBinder> displayToken);
135 const DisplayDeviceState& getDrawingDisplayState(sp<IBinder> displayToken);
136
137 // --------------------------------------------------------------------
138 // Test instances
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800139
Lloyd Piquebc792092018-01-17 11:52:30 -0800140 std::unordered_set<HWC2::Capability> mCapabilities;
141
Lloyd Piquef58625d2017-12-19 13:22:33 -0800142 TestableSurfaceFlinger mFlinger;
Lloyd Piquee39cad22017-12-20 17:01:29 -0800143 mock::EventThread* mEventThread = new mock::EventThread();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800144 mock::EventControlThread* mEventControlThread = new mock::EventControlThread();
Lloyd Piquee39cad22017-12-20 17:01:29 -0800145
146 // These mocks are created by the test, but are destroyed by SurfaceFlinger
147 // by virtue of being stored into a std::unique_ptr. However we still need
148 // to keep a reference to them for use in setting up call expectations.
149 RE::mock::RenderEngine* mRenderEngine = new RE::mock::RenderEngine();
150 Hwc2::mock::Composer* mComposer = new Hwc2::mock::Composer();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800151 mock::MessageQueue* mMessageQueue = new mock::MessageQueue();
152 mock::SurfaceInterceptor* mSurfaceInterceptor = new mock::SurfaceInterceptor();
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800153
154 // These mocks are created only when expected to be created via a factory.
155 sp<mock::GraphicBufferConsumer> mConsumer;
156 sp<mock::GraphicBufferProducer> mProducer;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800157 mock::NativeWindowSurface* mNativeWindowSurface = nullptr;
158 sp<mock::NativeWindow> mNativeWindow;
159 RE::mock::Surface* mRenderSurface = nullptr;
160 std::vector<std::unique_ptr<HWC2Display>> mFakeHwcDisplays;
Lloyd Piquef58625d2017-12-19 13:22:33 -0800161};
162
163DisplayTransactionTest::DisplayTransactionTest() {
164 const ::testing::TestInfo* const test_info =
165 ::testing::UnitTest::GetInstance()->current_test_info();
166 ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
Lloyd Piquee39cad22017-12-20 17:01:29 -0800167
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800168 mFlinger.setCreateBufferQueueFunction([](auto, auto, auto) {
169 ADD_FAILURE() << "Unexpected request to create a buffer queue.";
170 });
171
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800172 mFlinger.setCreateNativeWindowSurface([](auto) {
173 ADD_FAILURE() << "Unexpected request to create a native window surface.";
174 return nullptr;
175 });
176
177 mFlinger.mutableEventControlThread().reset(mEventControlThread);
Lloyd Piquee39cad22017-12-20 17:01:29 -0800178 mFlinger.mutableEventThread().reset(mEventThread);
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800179 mFlinger.mutableEventQueue().reset(mMessageQueue);
Lloyd Piquee39cad22017-12-20 17:01:29 -0800180 mFlinger.setupRenderEngine(std::unique_ptr<RE::RenderEngine>(mRenderEngine));
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800181 mFlinger.mutableInterceptor().reset(mSurfaceInterceptor);
Lloyd Piquee39cad22017-12-20 17:01:29 -0800182
183 setupComposer(0);
Lloyd Piquef58625d2017-12-19 13:22:33 -0800184}
185
186DisplayTransactionTest::~DisplayTransactionTest() {
187 const ::testing::TestInfo* const test_info =
188 ::testing::UnitTest::GetInstance()->current_test_info();
189 ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
190}
191
Lloyd Piquee39cad22017-12-20 17:01:29 -0800192void DisplayTransactionTest::setupComposer(int virtualDisplayCount) {
193 EXPECT_CALL(*mComposer, getCapabilities())
194 .WillOnce(Return(std::vector<IComposer::Capability>()));
195 EXPECT_CALL(*mComposer, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount));
196 mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer));
Lloyd Piquef58625d2017-12-19 13:22:33 -0800197
Lloyd Piquee39cad22017-12-20 17:01:29 -0800198 Mock::VerifyAndClear(mComposer);
199}
200
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800201void DisplayTransactionTest::setupFakeHwcDisplay(hwc2_display_t displayId,
202 DisplayDevice::DisplayType type, int width,
203 int height) {
204 auto display = std::make_unique<HWC2Display>(*mComposer, mCapabilities, displayId,
205 HWC2::DisplayType::Physical);
206 display->mutableIsConnected() = true;
207 display->mutableConfigs().emplace(DEFAULT_CONFIG_ID,
208 HWC2::Display::Config::Builder(*display, DEFAULT_CONFIG_ID)
209 .setWidth(width)
210 .setHeight(height)
211 .setVsyncPeriod(DEFAULT_REFRESH_RATE)
212 .setDpiX(DEFAULT_DPI)
213 .setDpiY(DEFAULT_DPI)
214 .build());
Lloyd Piquee39cad22017-12-20 17:01:29 -0800215
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800216 mFlinger.mutableHwcDisplayData()[type].reset();
217 mFlinger.mutableHwcDisplayData()[type].hwcDisplay = display.get();
218 mFlinger.mutableHwcDisplaySlots().emplace(displayId, type);
Lloyd Piquee39cad22017-12-20 17:01:29 -0800219
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800220 mFakeHwcDisplays.push_back(std::move(display));
Lloyd Piquee39cad22017-12-20 17:01:29 -0800221}
222
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800223sp<BBinder> DisplayTransactionTest::setupFakeExistingPhysicalDisplay(
224 hwc2_display_t displayId, DisplayDevice::DisplayType type) {
225 setupFakeHwcDisplay(displayId, type, 0, 0);
226
227 sp<BBinder> displayToken = new BBinder();
228 mFlinger.mutableBuiltinDisplays()[type] = displayToken;
229 mFlinger.mutableDisplays()
230 .add(displayToken,
231 FakeDisplayDeviceFactory(mFlinger, displayToken, type, type).build());
232
Dominik Laskowski663bd282018-04-19 15:26:54 -0700233 DisplayDeviceState state;
234 state.type = type;
235 state.isSecure = true;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800236 mFlinger.mutableCurrentState().displays.add(displayToken, state);
237 mFlinger.mutableDrawingState().displays.add(displayToken, state);
238
239 return displayToken;
240}
241
242void DisplayTransactionTest::setupFakeBufferQueueFactory() {
243 // This setup is only expected once per test.
244 ASSERT_TRUE(mConsumer == nullptr && mProducer == nullptr);
245
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800246 mConsumer = new mock::GraphicBufferConsumer();
247 mProducer = new mock::GraphicBufferProducer();
248
249 mFlinger.setCreateBufferQueueFunction([this](auto outProducer, auto outConsumer, bool) {
250 *outProducer = mProducer;
251 *outConsumer = mConsumer;
252 });
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800253}
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800254
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800255void DisplayTransactionTest::setupFakeNativeWindowSurfaceFactory(int displayWidth,
256 int displayHeight, bool critical,
257 bool async) {
258 // This setup is only expected once per test.
259 ASSERT_TRUE(mNativeWindowSurface == nullptr);
260
261 mNativeWindowSurface = new mock::NativeWindowSurface();
262 mNativeWindow = new mock::NativeWindow();
263
264 mFlinger.setCreateNativeWindowSurface(
265 [this](auto) { return std::unique_ptr<NativeWindowSurface>(mNativeWindowSurface); });
266
267 EXPECT_CALL(*mNativeWindowSurface, getNativeWindow()).WillOnce(Return(mNativeWindow));
268
269 EXPECT_CALL(*mNativeWindow, perform(19)).Times(1);
270
271 EXPECT_CALL(*mRenderSurface, setAsync(async)).Times(1);
272 EXPECT_CALL(*mRenderSurface, setCritical(critical)).Times(1);
273 EXPECT_CALL(*mRenderSurface, setNativeWindow(mNativeWindow.get())).Times(1);
274 EXPECT_CALL(*mRenderSurface, queryWidth()).WillOnce(Return(displayWidth));
275 EXPECT_CALL(*mRenderSurface, queryHeight()).WillOnce(Return(displayHeight));
276}
277
278void DisplayTransactionTest::expectFramebufferUsageSet(int width, int height, int grallocUsage) {
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800279 EXPECT_CALL(*mConsumer, consumerConnect(_, false)).WillOnce(Return(NO_ERROR));
280 EXPECT_CALL(*mConsumer, setConsumerName(_)).WillRepeatedly(Return(NO_ERROR));
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800281 EXPECT_CALL(*mConsumer, setConsumerUsageBits(grallocUsage)).WillRepeatedly(Return(NO_ERROR));
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800282 EXPECT_CALL(*mConsumer, setDefaultBufferSize(width, height)).WillRepeatedly(Return(NO_ERROR));
283 EXPECT_CALL(*mConsumer, setMaxAcquiredBufferCount(_)).WillRepeatedly(Return(NO_ERROR));
284
285 EXPECT_CALL(*mProducer, allocateBuffers(0, 0, 0, 0)).WillRepeatedly(Return());
286}
287
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800288void DisplayTransactionTest::expectHwcHotplugCalls(hwc2_display_t displayId, int displayWidth,
289 int displayHeight) {
290 EXPECT_CALL(*mComposer, getDisplayType(displayId, _))
291 .WillOnce(DoAll(SetArgPointee<1>(IComposerClient::DisplayType::PHYSICAL),
292 Return(Error::NONE)));
293 EXPECT_CALL(*mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE));
294 EXPECT_CALL(*mComposer, getDisplayConfigs(_, _))
295 .WillOnce(DoAll(SetArgPointee<1>(std::vector<unsigned>{0}), Return(Error::NONE)));
296 EXPECT_CALL(*mComposer, getDisplayAttribute(displayId, 0, IComposerClient::Attribute::WIDTH, _))
297 .WillOnce(DoAll(SetArgPointee<3>(displayWidth), Return(Error::NONE)));
298 EXPECT_CALL(*mComposer,
299 getDisplayAttribute(displayId, 0, IComposerClient::Attribute::HEIGHT, _))
300 .WillOnce(DoAll(SetArgPointee<3>(displayHeight), Return(Error::NONE)));
301 EXPECT_CALL(*mComposer,
302 getDisplayAttribute(displayId, 0, IComposerClient::Attribute::VSYNC_PERIOD, _))
303 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_REFRESH_RATE), Return(Error::NONE)));
304 EXPECT_CALL(*mComposer, getDisplayAttribute(displayId, 0, IComposerClient::Attribute::DPI_X, _))
305 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE)));
306 EXPECT_CALL(*mComposer, getDisplayAttribute(displayId, 0, IComposerClient::Attribute::DPI_Y, _))
307 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE)));
308}
Lloyd Piquee39cad22017-12-20 17:01:29 -0800309
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800310void DisplayTransactionTest::expectRESurfaceCreationCalls() {
311 // This setup is only expected once per test.
312 ASSERT_TRUE(mRenderSurface == nullptr);
Lloyd Piquee39cad22017-12-20 17:01:29 -0800313
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800314 mRenderSurface = new RE::mock::Surface();
315 EXPECT_CALL(*mRenderEngine, createSurface())
316 .WillOnce(Return(ByMove(std::unique_ptr<RE::Surface>(mRenderSurface))));
317}
Lloyd Piquee39cad22017-12-20 17:01:29 -0800318
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800319void DisplayTransactionTest::expectPhysicalDisplayDeviceCreationCalls(hwc2_display_t displayId,
320 int displayWidth,
321 int displayHeight,
322 bool critical, bool async) {
323 EXPECT_CALL(*mComposer, getActiveConfig(displayId, _))
324 .WillOnce(DoAll(SetArgPointee<1>(DEFAULT_CONFIG_ID), Return(Error::NONE)));
325 EXPECT_CALL(*mComposer, getColorModes(displayId, _)).Times(0);
326 EXPECT_CALL(*mComposer, getHdrCapabilities(displayId, _, _, _, _))
Lloyd Piquee39cad22017-12-20 17:01:29 -0800327 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>()), Return(Error::NONE)));
328
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800329 setupFakeBufferQueueFactory();
330 expectFramebufferUsageSet(displayWidth, displayHeight,
331 GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_COMPOSER |
332 GRALLOC_USAGE_HW_FB);
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800333
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800334 setupFakeNativeWindowSurfaceFactory(displayWidth, displayHeight, critical, async);
335}
336
337bool DisplayTransactionTest::hasTransactionFlagSet(int flag) {
338 return mFlinger.mutableTransactionFlags() & flag;
339}
340
341bool DisplayTransactionTest::hasDisplayDevice(sp<IBinder> displayToken) {
342 return mFlinger.mutableDisplays().indexOfKey(displayToken) >= 0;
343}
344
345sp<DisplayDevice> DisplayTransactionTest::getDisplayDevice(sp<IBinder> displayToken) {
346 return mFlinger.mutableDisplays().valueFor(displayToken);
347}
348
349bool DisplayTransactionTest::hasCurrentDisplayState(sp<IBinder> displayToken) {
350 return mFlinger.mutableCurrentState().displays.indexOfKey(displayToken) >= 0;
351}
352
353const DisplayDeviceState& DisplayTransactionTest::getCurrentDisplayState(sp<IBinder> displayToken) {
354 return mFlinger.mutableCurrentState().displays.valueFor(displayToken);
355}
356
357bool DisplayTransactionTest::hasDrawingDisplayState(sp<IBinder> displayToken) {
358 return mFlinger.mutableDrawingState().displays.indexOfKey(displayToken) >= 0;
359}
360
361const DisplayDeviceState& DisplayTransactionTest::getDrawingDisplayState(sp<IBinder> displayToken) {
362 return mFlinger.mutableDrawingState().displays.valueFor(displayToken);
363}
364
365/* ------------------------------------------------------------------------
366 * SurfaceFlinger::handleTransactionLocked(eDisplayTransactionNeeded)
367 */
368
369TEST_F(DisplayTransactionTest, handleTransactionLockedProcessesHotplugConnectPrimary) {
370 constexpr hwc2_display_t externalDisplayId = 102;
371 constexpr hwc2_display_t displayId = 123;
372 constexpr int displayWidth = 1920;
373 constexpr int displayHeight = 1080;
374
375 // --------------------------------------------------------------------
376 // Preconditions
377
378 // An external display may already be set up
379 setupFakeHwcDisplay(externalDisplayId, DisplayDevice::DISPLAY_EXTERNAL, 3840, 2160);
380
381 // A hotplug connect comes in for a new display
382 mFlinger.mutablePendingHotplugEvents().emplace_back(
383 HotplugEvent{displayId, HWC2::Connection::Connected});
384
385 // --------------------------------------------------------------------
386 // Call Expectations
387
388 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillOnce(Return(false));
389 expectHwcHotplugCalls(displayId, displayWidth, displayHeight);
390 expectRESurfaceCreationCalls();
391 expectPhysicalDisplayDeviceCreationCalls(displayId, displayWidth, displayHeight, true, false);
392
393 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
Lloyd Piquee39cad22017-12-20 17:01:29 -0800394
395 EXPECT_CALL(*mEventThread, onHotplugReceived(DisplayDevice::DISPLAY_PRIMARY, true)).Times(1);
396
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800397 // --------------------------------------------------------------------
398 // Invocation
Lloyd Piquee39cad22017-12-20 17:01:29 -0800399
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800400 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
Lloyd Piquee39cad22017-12-20 17:01:29 -0800401
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800402 // --------------------------------------------------------------------
403 // Postconditions
404
405 // HWComposer should have an entry for the display
406 EXPECT_TRUE(mFlinger.mutableHwcDisplaySlots().count(displayId) == 1);
407
408 // The display should have set up as a primary built-in display.
409 auto displayToken = mFlinger.mutableBuiltinDisplays()[DisplayDevice::DISPLAY_PRIMARY];
410 ASSERT_TRUE(displayToken != nullptr);
411
412 // The display device should have been set up in the list of displays.
413 ASSERT_TRUE(hasDisplayDevice(displayToken));
414 const auto& device = getDisplayDevice(displayToken);
Lloyd Piquee39cad22017-12-20 17:01:29 -0800415 EXPECT_TRUE(device->isSecure());
416 EXPECT_TRUE(device->isPrimary());
417
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800418 // The display should have been set up in the current display state
419 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
420 const auto& current = getCurrentDisplayState(displayToken);
421 EXPECT_EQ(DisplayDevice::DISPLAY_PRIMARY, current.type);
422
423 // The display should have been set up in the drawing display state
424 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
425 const auto& draw = getDrawingDisplayState(displayToken);
Lloyd Piquee39cad22017-12-20 17:01:29 -0800426 EXPECT_EQ(DisplayDevice::DISPLAY_PRIMARY, draw.type);
427
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800428 // --------------------------------------------------------------------
429 // Cleanup conditions
430
431 EXPECT_CALL(*mComposer, setVsyncEnabled(displayId, IComposerClient::Vsync::DISABLE))
432 .WillOnce(Return(Error::NONE));
433 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
Lloyd Piquef58625d2017-12-19 13:22:33 -0800434}
435
436} // namespace
437} // namespace android