blob: 0705b5c7f819f8c7723c4a2e1874bc271ebfc607 [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>
Lloyd Pique1fa4d462018-01-22 18:03:16 -080024#include "system/window.h"
Lloyd Piquef58625d2017-12-19 13:22:33 -080025
Lloyd Piquee39cad22017-12-20 17:01:29 -080026#include "MockComposer.h"
Lloyd Pique1fa4d462018-01-22 18:03:16 -080027#include "MockDisplaySurface.h"
28#include "MockEventControlThread.h"
Lloyd Piquee39cad22017-12-20 17:01:29 -080029#include "MockEventThread.h"
Lloyd Pique5b36f3f2018-01-17 11:57:07 -080030#include "MockGraphicBufferConsumer.h"
31#include "MockGraphicBufferProducer.h"
Lloyd Pique1fa4d462018-01-22 18:03:16 -080032#include "MockMessageQueue.h"
33#include "MockNativeWindow.h"
34#include "MockNativeWindowSurface.h"
Lloyd Piquee39cad22017-12-20 17:01:29 -080035#include "MockRenderEngine.h"
Lloyd Pique1fa4d462018-01-22 18:03:16 -080036#include "MockSurfaceInterceptor.h"
Lloyd Piquef58625d2017-12-19 13:22:33 -080037#include "TestableSurfaceFlinger.h"
38
39namespace android {
40namespace {
41
Lloyd Piquee39cad22017-12-20 17:01:29 -080042using testing::_;
43using testing::ByMove;
44using testing::DoAll;
45using testing::Mock;
46using testing::Return;
47using testing::SetArgPointee;
48
49using android::hardware::graphics::common::V1_0::Hdr;
Peiyong Lin0e7a7912018-04-05 14:36:36 -070050using android::hardware::graphics::common::V1_1::ColorMode;
Lloyd Piquee39cad22017-12-20 17:01:29 -080051using android::Hwc2::Error;
52using android::Hwc2::IComposer;
53using android::Hwc2::IComposerClient;
54
Lloyd Piquebc792092018-01-17 11:52:30 -080055using HWC2Display = TestableSurfaceFlinger::HWC2Display;
Lloyd Pique1fa4d462018-01-22 18:03:16 -080056using HotplugEvent = TestableSurfaceFlinger::HotplugEvent;
Lloyd Piquebc792092018-01-17 11:52:30 -080057
Lloyd Piquee39cad22017-12-20 17:01:29 -080058constexpr int32_t DEFAULT_REFRESH_RATE = 1666666666;
59constexpr int32_t DEFAULT_DPI = 320;
60
Lloyd Pique1fa4d462018-01-22 18:03:16 -080061constexpr int DEFAULT_CONFIG_ID = 0;
62
Lloyd Piquef58625d2017-12-19 13:22:33 -080063class DisplayTransactionTest : public testing::Test {
64protected:
65 DisplayTransactionTest();
66 ~DisplayTransactionTest() override;
67
Lloyd Pique1fa4d462018-01-22 18:03:16 -080068 // --------------------------------------------------------------------
69 // Precondition helpers
Lloyd Piquef58625d2017-12-19 13:22:33 -080070
Lloyd Pique1fa4d462018-01-22 18:03:16 -080071 void setupComposer(int virtualDisplayCount);
72 void setupFakeHwcDisplay(hwc2_display_t displayId, DisplayDevice::DisplayType type, int width,
73 int height);
74
75 struct FakeDisplayDeviceFactory {
76 public:
77 FakeDisplayDeviceFactory(TestableSurfaceFlinger& flinger, sp<BBinder>& displayToken,
78 DisplayDevice::DisplayType type, int hwcId)
79 : mFlinger(flinger), mDisplayToken(displayToken), mType(type), mHwcId(hwcId) {}
80
81 sp<DisplayDevice> build() {
82 return new DisplayDevice(mFlinger.mFlinger.get(), mType, mHwcId, false, mDisplayToken,
83 mNativeWindow, mDisplaySurface, std::move(mRenderSurface), 0,
84 0, false, false, HWC_POWER_MODE_NORMAL);
85 }
86
87 FakeDisplayDeviceFactory& setNativeWindow(const sp<ANativeWindow>& nativeWindow) {
88 mNativeWindow = nativeWindow;
89 return *this;
90 }
91
92 FakeDisplayDeviceFactory& setDisplaySurface(const sp<DisplaySurface>& displaySurface) {
93 mDisplaySurface = displaySurface;
94 return *this;
95 }
96
97 FakeDisplayDeviceFactory& setRenderSurface(std::unique_ptr<RE::Surface> renderSurface) {
98 mRenderSurface = std::move(renderSurface);
99 return *this;
100 }
101
102 TestableSurfaceFlinger& mFlinger;
103 sp<BBinder>& mDisplayToken;
104 DisplayDevice::DisplayType mType;
105 int mHwcId;
106 sp<ANativeWindow> mNativeWindow;
107 sp<DisplaySurface> mDisplaySurface;
108 std::unique_ptr<RE::Surface> mRenderSurface;
109 };
110
111 sp<BBinder> setupFakeExistingPhysicalDisplay(hwc2_display_t displayId,
112 DisplayDevice::DisplayType type);
113
114 void setupFakeBufferQueueFactory();
115 void setupFakeNativeWindowSurfaceFactory(int displayWidth, int displayHeight, bool critical,
116 bool async);
117 void expectFramebufferUsageSet(int width, int height, int grallocUsage);
118 void expectHwcHotplugCalls(hwc2_display_t displayId, int displayWidth, int displayHeight);
119
120 // --------------------------------------------------------------------
121 // Call expectation helpers
122
123 void expectRESurfaceCreationCalls();
124 void expectPhysicalDisplayDeviceCreationCalls(hwc2_display_t displayId, int displayWidth,
125 int displayHeight, bool critical, bool async);
126
127 // --------------------------------------------------------------------
128 // Postcondition helpers
129
130 bool hasTransactionFlagSet(int flag);
131 bool hasDisplayDevice(sp<IBinder> displayToken);
132 sp<DisplayDevice> getDisplayDevice(sp<IBinder> displayToken);
133 bool hasCurrentDisplayState(sp<IBinder> displayToken);
134 const DisplayDeviceState& getCurrentDisplayState(sp<IBinder> displayToken);
135 bool hasDrawingDisplayState(sp<IBinder> displayToken);
136 const DisplayDeviceState& getDrawingDisplayState(sp<IBinder> displayToken);
137
138 // --------------------------------------------------------------------
139 // Test instances
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800140
Lloyd Piquebc792092018-01-17 11:52:30 -0800141 std::unordered_set<HWC2::Capability> mCapabilities;
142
Lloyd Piquef58625d2017-12-19 13:22:33 -0800143 TestableSurfaceFlinger mFlinger;
Lloyd Piquee39cad22017-12-20 17:01:29 -0800144 mock::EventThread* mEventThread = new mock::EventThread();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800145 mock::EventControlThread* mEventControlThread = new mock::EventControlThread();
Lloyd Piquee39cad22017-12-20 17:01:29 -0800146
147 // These mocks are created by the test, but are destroyed by SurfaceFlinger
148 // by virtue of being stored into a std::unique_ptr. However we still need
149 // to keep a reference to them for use in setting up call expectations.
150 RE::mock::RenderEngine* mRenderEngine = new RE::mock::RenderEngine();
151 Hwc2::mock::Composer* mComposer = new Hwc2::mock::Composer();
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800152 mock::MessageQueue* mMessageQueue = new mock::MessageQueue();
153 mock::SurfaceInterceptor* mSurfaceInterceptor = new mock::SurfaceInterceptor();
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800154
155 // These mocks are created only when expected to be created via a factory.
156 sp<mock::GraphicBufferConsumer> mConsumer;
157 sp<mock::GraphicBufferProducer> mProducer;
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800158 mock::NativeWindowSurface* mNativeWindowSurface = nullptr;
159 sp<mock::NativeWindow> mNativeWindow;
160 RE::mock::Surface* mRenderSurface = nullptr;
161 std::vector<std::unique_ptr<HWC2Display>> mFakeHwcDisplays;
Lloyd Piquef58625d2017-12-19 13:22:33 -0800162};
163
164DisplayTransactionTest::DisplayTransactionTest() {
165 const ::testing::TestInfo* const test_info =
166 ::testing::UnitTest::GetInstance()->current_test_info();
167 ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name());
Lloyd Piquee39cad22017-12-20 17:01:29 -0800168
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800169 mFlinger.setCreateBufferQueueFunction([](auto, auto, auto) {
170 ADD_FAILURE() << "Unexpected request to create a buffer queue.";
171 });
172
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800173 mFlinger.setCreateNativeWindowSurface([](auto) {
174 ADD_FAILURE() << "Unexpected request to create a native window surface.";
175 return nullptr;
176 });
177
178 mFlinger.mutableEventControlThread().reset(mEventControlThread);
Lloyd Piquee39cad22017-12-20 17:01:29 -0800179 mFlinger.mutableEventThread().reset(mEventThread);
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800180 mFlinger.mutableEventQueue().reset(mMessageQueue);
Lloyd Piquee39cad22017-12-20 17:01:29 -0800181 mFlinger.setupRenderEngine(std::unique_ptr<RE::RenderEngine>(mRenderEngine));
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800182 mFlinger.mutableInterceptor().reset(mSurfaceInterceptor);
Lloyd Piquee39cad22017-12-20 17:01:29 -0800183
184 setupComposer(0);
Lloyd Piquef58625d2017-12-19 13:22:33 -0800185}
186
187DisplayTransactionTest::~DisplayTransactionTest() {
188 const ::testing::TestInfo* const test_info =
189 ::testing::UnitTest::GetInstance()->current_test_info();
190 ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
191}
192
Lloyd Piquee39cad22017-12-20 17:01:29 -0800193void DisplayTransactionTest::setupComposer(int virtualDisplayCount) {
194 EXPECT_CALL(*mComposer, getCapabilities())
195 .WillOnce(Return(std::vector<IComposer::Capability>()));
196 EXPECT_CALL(*mComposer, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount));
197 mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer));
Lloyd Piquef58625d2017-12-19 13:22:33 -0800198
Lloyd Piquee39cad22017-12-20 17:01:29 -0800199 Mock::VerifyAndClear(mComposer);
200}
201
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800202void DisplayTransactionTest::setupFakeHwcDisplay(hwc2_display_t displayId,
203 DisplayDevice::DisplayType type, int width,
204 int height) {
205 auto display = std::make_unique<HWC2Display>(*mComposer, mCapabilities, displayId,
206 HWC2::DisplayType::Physical);
207 display->mutableIsConnected() = true;
208 display->mutableConfigs().emplace(DEFAULT_CONFIG_ID,
209 HWC2::Display::Config::Builder(*display, DEFAULT_CONFIG_ID)
210 .setWidth(width)
211 .setHeight(height)
212 .setVsyncPeriod(DEFAULT_REFRESH_RATE)
213 .setDpiX(DEFAULT_DPI)
214 .setDpiY(DEFAULT_DPI)
215 .build());
Lloyd Piquee39cad22017-12-20 17:01:29 -0800216
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800217 mFlinger.mutableHwcDisplayData()[type].reset();
218 mFlinger.mutableHwcDisplayData()[type].hwcDisplay = display.get();
219 mFlinger.mutableHwcDisplaySlots().emplace(displayId, type);
Lloyd Piquee39cad22017-12-20 17:01:29 -0800220
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800221 mFakeHwcDisplays.push_back(std::move(display));
Lloyd Piquee39cad22017-12-20 17:01:29 -0800222}
223
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800224sp<BBinder> DisplayTransactionTest::setupFakeExistingPhysicalDisplay(
225 hwc2_display_t displayId, DisplayDevice::DisplayType type) {
226 setupFakeHwcDisplay(displayId, type, 0, 0);
227
228 sp<BBinder> displayToken = new BBinder();
229 mFlinger.mutableBuiltinDisplays()[type] = displayToken;
230 mFlinger.mutableDisplays()
231 .add(displayToken,
232 FakeDisplayDeviceFactory(mFlinger, displayToken, type, type).build());
233
234 DisplayDeviceState state(type, true);
235 mFlinger.mutableCurrentState().displays.add(displayToken, state);
236 mFlinger.mutableDrawingState().displays.add(displayToken, state);
237
238 return displayToken;
239}
240
241void DisplayTransactionTest::setupFakeBufferQueueFactory() {
242 // This setup is only expected once per test.
243 ASSERT_TRUE(mConsumer == nullptr && mProducer == nullptr);
244
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800245 mConsumer = new mock::GraphicBufferConsumer();
246 mProducer = new mock::GraphicBufferProducer();
247
248 mFlinger.setCreateBufferQueueFunction([this](auto outProducer, auto outConsumer, bool) {
249 *outProducer = mProducer;
250 *outConsumer = mConsumer;
251 });
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800252}
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800253
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800254void DisplayTransactionTest::setupFakeNativeWindowSurfaceFactory(int displayWidth,
255 int displayHeight, bool critical,
256 bool async) {
257 // This setup is only expected once per test.
258 ASSERT_TRUE(mNativeWindowSurface == nullptr);
259
260 mNativeWindowSurface = new mock::NativeWindowSurface();
261 mNativeWindow = new mock::NativeWindow();
262
263 mFlinger.setCreateNativeWindowSurface(
264 [this](auto) { return std::unique_ptr<NativeWindowSurface>(mNativeWindowSurface); });
265
266 EXPECT_CALL(*mNativeWindowSurface, getNativeWindow()).WillOnce(Return(mNativeWindow));
267
268 EXPECT_CALL(*mNativeWindow, perform(19)).Times(1);
269
270 EXPECT_CALL(*mRenderSurface, setAsync(async)).Times(1);
271 EXPECT_CALL(*mRenderSurface, setCritical(critical)).Times(1);
272 EXPECT_CALL(*mRenderSurface, setNativeWindow(mNativeWindow.get())).Times(1);
273 EXPECT_CALL(*mRenderSurface, queryWidth()).WillOnce(Return(displayWidth));
274 EXPECT_CALL(*mRenderSurface, queryHeight()).WillOnce(Return(displayHeight));
275}
276
277void DisplayTransactionTest::expectFramebufferUsageSet(int width, int height, int grallocUsage) {
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800278 EXPECT_CALL(*mConsumer, consumerConnect(_, false)).WillOnce(Return(NO_ERROR));
279 EXPECT_CALL(*mConsumer, setConsumerName(_)).WillRepeatedly(Return(NO_ERROR));
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800280 EXPECT_CALL(*mConsumer, setConsumerUsageBits(grallocUsage)).WillRepeatedly(Return(NO_ERROR));
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800281 EXPECT_CALL(*mConsumer, setDefaultBufferSize(width, height)).WillRepeatedly(Return(NO_ERROR));
282 EXPECT_CALL(*mConsumer, setMaxAcquiredBufferCount(_)).WillRepeatedly(Return(NO_ERROR));
283
284 EXPECT_CALL(*mProducer, allocateBuffers(0, 0, 0, 0)).WillRepeatedly(Return());
285}
286
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800287void DisplayTransactionTest::expectHwcHotplugCalls(hwc2_display_t displayId, int displayWidth,
288 int displayHeight) {
289 EXPECT_CALL(*mComposer, getDisplayType(displayId, _))
290 .WillOnce(DoAll(SetArgPointee<1>(IComposerClient::DisplayType::PHYSICAL),
291 Return(Error::NONE)));
292 EXPECT_CALL(*mComposer, setClientTargetSlotCount(_)).WillOnce(Return(Error::NONE));
293 EXPECT_CALL(*mComposer, getDisplayConfigs(_, _))
294 .WillOnce(DoAll(SetArgPointee<1>(std::vector<unsigned>{0}), Return(Error::NONE)));
295 EXPECT_CALL(*mComposer, getDisplayAttribute(displayId, 0, IComposerClient::Attribute::WIDTH, _))
296 .WillOnce(DoAll(SetArgPointee<3>(displayWidth), Return(Error::NONE)));
297 EXPECT_CALL(*mComposer,
298 getDisplayAttribute(displayId, 0, IComposerClient::Attribute::HEIGHT, _))
299 .WillOnce(DoAll(SetArgPointee<3>(displayHeight), Return(Error::NONE)));
300 EXPECT_CALL(*mComposer,
301 getDisplayAttribute(displayId, 0, IComposerClient::Attribute::VSYNC_PERIOD, _))
302 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_REFRESH_RATE), Return(Error::NONE)));
303 EXPECT_CALL(*mComposer, getDisplayAttribute(displayId, 0, IComposerClient::Attribute::DPI_X, _))
304 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE)));
305 EXPECT_CALL(*mComposer, getDisplayAttribute(displayId, 0, IComposerClient::Attribute::DPI_Y, _))
306 .WillOnce(DoAll(SetArgPointee<3>(DEFAULT_DPI), Return(Error::NONE)));
307}
Lloyd Piquee39cad22017-12-20 17:01:29 -0800308
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800309void DisplayTransactionTest::expectRESurfaceCreationCalls() {
310 // This setup is only expected once per test.
311 ASSERT_TRUE(mRenderSurface == nullptr);
Lloyd Piquee39cad22017-12-20 17:01:29 -0800312
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800313 mRenderSurface = new RE::mock::Surface();
314 EXPECT_CALL(*mRenderEngine, createSurface())
315 .WillOnce(Return(ByMove(std::unique_ptr<RE::Surface>(mRenderSurface))));
316}
Lloyd Piquee39cad22017-12-20 17:01:29 -0800317
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800318void DisplayTransactionTest::expectPhysicalDisplayDeviceCreationCalls(hwc2_display_t displayId,
319 int displayWidth,
320 int displayHeight,
321 bool critical, bool async) {
322 EXPECT_CALL(*mComposer, getActiveConfig(displayId, _))
323 .WillOnce(DoAll(SetArgPointee<1>(DEFAULT_CONFIG_ID), Return(Error::NONE)));
324 EXPECT_CALL(*mComposer, getColorModes(displayId, _)).Times(0);
325 EXPECT_CALL(*mComposer, getHdrCapabilities(displayId, _, _, _, _))
Lloyd Piquee39cad22017-12-20 17:01:29 -0800326 .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hdr>()), Return(Error::NONE)));
327
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800328 setupFakeBufferQueueFactory();
329 expectFramebufferUsageSet(displayWidth, displayHeight,
330 GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_COMPOSER |
331 GRALLOC_USAGE_HW_FB);
Lloyd Pique5b36f3f2018-01-17 11:57:07 -0800332
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800333 setupFakeNativeWindowSurfaceFactory(displayWidth, displayHeight, critical, async);
334}
335
336bool DisplayTransactionTest::hasTransactionFlagSet(int flag) {
337 return mFlinger.mutableTransactionFlags() & flag;
338}
339
340bool DisplayTransactionTest::hasDisplayDevice(sp<IBinder> displayToken) {
341 return mFlinger.mutableDisplays().indexOfKey(displayToken) >= 0;
342}
343
344sp<DisplayDevice> DisplayTransactionTest::getDisplayDevice(sp<IBinder> displayToken) {
345 return mFlinger.mutableDisplays().valueFor(displayToken);
346}
347
348bool DisplayTransactionTest::hasCurrentDisplayState(sp<IBinder> displayToken) {
349 return mFlinger.mutableCurrentState().displays.indexOfKey(displayToken) >= 0;
350}
351
352const DisplayDeviceState& DisplayTransactionTest::getCurrentDisplayState(sp<IBinder> displayToken) {
353 return mFlinger.mutableCurrentState().displays.valueFor(displayToken);
354}
355
356bool DisplayTransactionTest::hasDrawingDisplayState(sp<IBinder> displayToken) {
357 return mFlinger.mutableDrawingState().displays.indexOfKey(displayToken) >= 0;
358}
359
360const DisplayDeviceState& DisplayTransactionTest::getDrawingDisplayState(sp<IBinder> displayToken) {
361 return mFlinger.mutableDrawingState().displays.valueFor(displayToken);
362}
363
364/* ------------------------------------------------------------------------
365 * SurfaceFlinger::handleTransactionLocked(eDisplayTransactionNeeded)
366 */
367
368TEST_F(DisplayTransactionTest, handleTransactionLockedProcessesHotplugConnectPrimary) {
369 constexpr hwc2_display_t externalDisplayId = 102;
370 constexpr hwc2_display_t displayId = 123;
371 constexpr int displayWidth = 1920;
372 constexpr int displayHeight = 1080;
373
374 // --------------------------------------------------------------------
375 // Preconditions
376
377 // An external display may already be set up
378 setupFakeHwcDisplay(externalDisplayId, DisplayDevice::DISPLAY_EXTERNAL, 3840, 2160);
379
380 // A hotplug connect comes in for a new display
381 mFlinger.mutablePendingHotplugEvents().emplace_back(
382 HotplugEvent{displayId, HWC2::Connection::Connected});
383
384 // --------------------------------------------------------------------
385 // Call Expectations
386
387 EXPECT_CALL(*mComposer, isUsingVrComposer()).WillOnce(Return(false));
388 expectHwcHotplugCalls(displayId, displayWidth, displayHeight);
389 expectRESurfaceCreationCalls();
390 expectPhysicalDisplayDeviceCreationCalls(displayId, displayWidth, displayHeight, true, false);
391
392 EXPECT_CALL(*mSurfaceInterceptor, saveDisplayCreation(_)).Times(1);
Lloyd Piquee39cad22017-12-20 17:01:29 -0800393
394 EXPECT_CALL(*mEventThread, onHotplugReceived(DisplayDevice::DISPLAY_PRIMARY, true)).Times(1);
395
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800396 // --------------------------------------------------------------------
397 // Invocation
Lloyd Piquee39cad22017-12-20 17:01:29 -0800398
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800399 mFlinger.handleTransactionLocked(eDisplayTransactionNeeded);
Lloyd Piquee39cad22017-12-20 17:01:29 -0800400
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800401 // --------------------------------------------------------------------
402 // Postconditions
403
404 // HWComposer should have an entry for the display
405 EXPECT_TRUE(mFlinger.mutableHwcDisplaySlots().count(displayId) == 1);
406
407 // The display should have set up as a primary built-in display.
408 auto displayToken = mFlinger.mutableBuiltinDisplays()[DisplayDevice::DISPLAY_PRIMARY];
409 ASSERT_TRUE(displayToken != nullptr);
410
411 // The display device should have been set up in the list of displays.
412 ASSERT_TRUE(hasDisplayDevice(displayToken));
413 const auto& device = getDisplayDevice(displayToken);
Lloyd Piquee39cad22017-12-20 17:01:29 -0800414 EXPECT_TRUE(device->isSecure());
415 EXPECT_TRUE(device->isPrimary());
416
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800417 // The display should have been set up in the current display state
418 ASSERT_TRUE(hasCurrentDisplayState(displayToken));
419 const auto& current = getCurrentDisplayState(displayToken);
420 EXPECT_EQ(DisplayDevice::DISPLAY_PRIMARY, current.type);
421
422 // The display should have been set up in the drawing display state
423 ASSERT_TRUE(hasDrawingDisplayState(displayToken));
424 const auto& draw = getDrawingDisplayState(displayToken);
Lloyd Piquee39cad22017-12-20 17:01:29 -0800425 EXPECT_EQ(DisplayDevice::DISPLAY_PRIMARY, draw.type);
426
Lloyd Pique1fa4d462018-01-22 18:03:16 -0800427 // --------------------------------------------------------------------
428 // Cleanup conditions
429
430 EXPECT_CALL(*mComposer, setVsyncEnabled(displayId, IComposerClient::Vsync::DISABLE))
431 .WillOnce(Return(Error::NONE));
432 EXPECT_CALL(*mConsumer, consumerDisconnect()).WillOnce(Return(NO_ERROR));
Lloyd Piquef58625d2017-12-19 13:22:33 -0800433}
434
435} // namespace
436} // namespace android