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 "DisplayTransactionTestHelpers.h"
21
22 namespace android {
23 namespace {
24
25 class OnInitializeDisplaysTest : public DisplayTransactionTest {};
26
TEST_F(OnInitializeDisplaysTest,onInitializeDisplaysSetsUpPrimaryDisplay)27 TEST_F(OnInitializeDisplaysTest, onInitializeDisplaysSetsUpPrimaryDisplay) {
28 using Case = SimplePrimaryDisplayCase;
29
30 // --------------------------------------------------------------------
31 // Preconditions
32
33 // A primary display is set up
34 Case::Display::injectHwcDisplay(this);
35 auto primaryDisplay = Case::Display::makeFakeExistingDisplayInjector(this);
36 primaryDisplay.inject();
37
38 // --------------------------------------------------------------------
39 // Call Expectations
40
41 // We expect the surface interceptor to possibly be used, but we treat it as
42 // disabled since it is called as a side effect rather than directly by this
43 // function.
44 EXPECT_CALL(*mSurfaceInterceptor, isEnabled()).WillOnce(Return(false));
45
46 // We expect a call to get the active display config.
47 Case::Display::setupHwcGetActiveConfigCallExpectations(this);
48
49 // We expect a scheduled commit for the display transaction.
50 EXPECT_CALL(*mFlinger.scheduler(), scheduleFrame()).Times(1);
51
52 EXPECT_CALL(*mVSyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0));
53
54 // --------------------------------------------------------------------
55 // Invocation
56
57 mFlinger.onInitializeDisplays();
58
59 // --------------------------------------------------------------------
60 // Postconditions
61
62 // The primary display should have a current state
63 ASSERT_TRUE(hasCurrentDisplayState(primaryDisplay.token()));
64 const auto& primaryDisplayState = getCurrentDisplayState(primaryDisplay.token());
65
66 // The primary display state should be reset
67 EXPECT_EQ(ui::DEFAULT_LAYER_STACK, primaryDisplayState.layerStack);
68 EXPECT_EQ(ui::ROTATION_0, primaryDisplayState.orientation);
69 EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.orientedDisplaySpaceRect);
70 EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.layerStackSpaceRect);
71
72 // The width and height should both be zero
73 EXPECT_EQ(0u, primaryDisplayState.width);
74 EXPECT_EQ(0u, primaryDisplayState.height);
75
76 // The display should be set to PowerMode::ON
77 ASSERT_TRUE(hasDisplayDevice(primaryDisplay.token()));
78 auto displayDevice = primaryDisplay.mutableDisplayDevice();
79 EXPECT_EQ(PowerMode::ON, displayDevice->getPowerMode());
80
81 // The display refresh period should be set in the orientedDisplaySpaceRect tracker.
82 FrameStats stats;
83 mFlinger.getAnimFrameTracker().getStats(&stats);
84 EXPECT_EQ(DEFAULT_VSYNC_PERIOD, stats.refreshPeriodNano);
85
86 // The display transaction needed flag should be set.
87 EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
88
89 // The compositor timing should be set to default values
90 const auto& compositorTiming = mFlinger.getCompositorTiming();
91 EXPECT_EQ(-DEFAULT_VSYNC_PERIOD, compositorTiming.deadline);
92 EXPECT_EQ(DEFAULT_VSYNC_PERIOD, compositorTiming.interval);
93 EXPECT_EQ(DEFAULT_VSYNC_PERIOD, compositorTiming.presentLatency);
94 }
95
96 } // namespace
97 } // namespace android
98