1 /*
2 * Copyright 2020 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 "DualDisplayTransactionTest.h"
21
22 namespace android {
23 namespace {
24
25 constexpr bool kExpectSetPowerModeOnce = false;
26 struct InitializeDisplaysTest : DualDisplayTransactionTest<hal::PowerMode::OFF, hal::PowerMode::OFF,
27 kExpectSetPowerModeOnce> {};
28
TEST_F(InitializeDisplaysTest,initializesDisplays)29 TEST_F(InitializeDisplaysTest, initializesDisplays) {
30 // Scheduled by the display transaction, and by powering on each display.
31 EXPECT_CALL(*mFlinger.scheduler(), scheduleFrame()).Times(3);
32
33 EXPECT_CALL(static_cast<mock::VSyncTracker&>(
34 mFlinger.scheduler()->getVsyncSchedule()->getTracker()),
35 nextAnticipatedVSyncTimeFrom(_, _))
36 .WillRepeatedly(Return(0));
37
38 FTL_FAKE_GUARD(kMainThreadContext, mFlinger.initializeDisplays());
39
40 for (const auto& display : {mInnerDisplay, mOuterDisplay}) {
41 const auto token = display->getDisplayToken().promote();
42 ASSERT_TRUE(token);
43
44 ASSERT_TRUE(hasCurrentDisplayState(token));
45 const auto& state = getCurrentDisplayState(token);
46
47 const ui::LayerStack expectedLayerStack = display == mInnerDisplay
48 ? ui::DEFAULT_LAYER_STACK
49 : ui::LayerStack::fromValue(ui::DEFAULT_LAYER_STACK.id + 1);
50
51 EXPECT_EQ(expectedLayerStack, state.layerStack);
52 EXPECT_EQ(ui::ROTATION_0, state.orientation);
53 EXPECT_EQ(Rect::INVALID_RECT, state.orientedDisplaySpaceRect);
54 EXPECT_EQ(Rect::INVALID_RECT, state.layerStackSpaceRect);
55
56 EXPECT_EQ(0u, state.width);
57 EXPECT_EQ(0u, state.height);
58
59 ASSERT_TRUE(hasDisplayDevice(token));
60 EXPECT_EQ(PowerMode::ON, getDisplayDevice(token).getPowerMode());
61 }
62
63 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
64 }
65
66 } // namespace
67 } // namespace android
68