• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 InitializeDisplaysTest : public DisplayTransactionTest {};
26 
TEST_F(InitializeDisplaysTest,commitsPrimaryDisplay)27 TEST_F(InitializeDisplaysTest, commitsPrimaryDisplay) {
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 a call to get the active display config.
42     Case::Display::setupHwcGetActiveConfigCallExpectations(this);
43 
44     // We expect a scheduled commit for the display transaction.
45     EXPECT_CALL(*mFlinger.scheduler(), scheduleFrame()).Times(1);
46 
47     EXPECT_CALL(static_cast<mock::VSyncTracker&>(
48                         mFlinger.scheduler()->getVsyncSchedule()->getTracker()),
49                 nextAnticipatedVSyncTimeFrom(_))
50             .WillRepeatedly(Return(0));
51 
52     // --------------------------------------------------------------------
53     // Invocation
54 
55     FTL_FAKE_GUARD(kMainThreadContext, mFlinger.initializeDisplays());
56 
57     // --------------------------------------------------------------------
58     // Postconditions
59 
60     // The primary display should have a current state
61     ASSERT_TRUE(hasCurrentDisplayState(primaryDisplay.token()));
62     const auto& primaryDisplayState = getCurrentDisplayState(primaryDisplay.token());
63 
64     // The primary display state should be reset
65     EXPECT_EQ(ui::DEFAULT_LAYER_STACK, primaryDisplayState.layerStack);
66     EXPECT_EQ(ui::ROTATION_0, primaryDisplayState.orientation);
67     EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.orientedDisplaySpaceRect);
68     EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.layerStackSpaceRect);
69 
70     // The width and height should both be zero
71     EXPECT_EQ(0u, primaryDisplayState.width);
72     EXPECT_EQ(0u, primaryDisplayState.height);
73 
74     // The display should be set to PowerMode::ON
75     ASSERT_TRUE(hasDisplayDevice(primaryDisplay.token()));
76     auto displayDevice = primaryDisplay.mutableDisplayDevice();
77     EXPECT_EQ(PowerMode::ON, displayDevice->getPowerMode());
78 
79     // The display transaction needed flag should be set.
80     EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
81 }
82 
83 } // namespace
84 } // namespace android
85