1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
/*
* Copyright 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#undef LOG_TAG
#define LOG_TAG "LibSurfaceFlingerUnittests"
#include "DisplayTransactionTestHelpers.h"
namespace android {
namespace {
class OnInitializeDisplaysTest : public DisplayTransactionTest {};
TEST_F(OnInitializeDisplaysTest, onInitializeDisplaysSetsUpPrimaryDisplay) {
using Case = SimplePrimaryDisplayCase;
// --------------------------------------------------------------------
// Preconditions
// A primary display is set up
Case::Display::injectHwcDisplay(this);
auto primaryDisplay = Case::Display::makeFakeExistingDisplayInjector(this);
primaryDisplay.inject();
// --------------------------------------------------------------------
// Call Expectations
// We expect the surface interceptor to possibly be used, but we treat it as
// disabled since it is called as a side effect rather than directly by this
// function.
EXPECT_CALL(*mSurfaceInterceptor, isEnabled()).WillOnce(Return(false));
// We expect a call to get the active display config.
Case::Display::setupHwcGetActiveConfigCallExpectations(this);
// We expect a scheduled commit for the display transaction.
EXPECT_CALL(*mFlinger.scheduler(), scheduleFrame()).Times(1);
EXPECT_CALL(*mVSyncTracker, nextAnticipatedVSyncTimeFrom(_)).WillRepeatedly(Return(0));
// --------------------------------------------------------------------
// Invocation
mFlinger.onInitializeDisplays();
// --------------------------------------------------------------------
// Postconditions
// The primary display should have a current state
ASSERT_TRUE(hasCurrentDisplayState(primaryDisplay.token()));
const auto& primaryDisplayState = getCurrentDisplayState(primaryDisplay.token());
// The primary display state should be reset
EXPECT_EQ(ui::DEFAULT_LAYER_STACK, primaryDisplayState.layerStack);
EXPECT_EQ(ui::ROTATION_0, primaryDisplayState.orientation);
EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.orientedDisplaySpaceRect);
EXPECT_EQ(Rect::INVALID_RECT, primaryDisplayState.layerStackSpaceRect);
// The width and height should both be zero
EXPECT_EQ(0u, primaryDisplayState.width);
EXPECT_EQ(0u, primaryDisplayState.height);
// The display should be set to PowerMode::ON
ASSERT_TRUE(hasDisplayDevice(primaryDisplay.token()));
auto displayDevice = primaryDisplay.mutableDisplayDevice();
EXPECT_EQ(PowerMode::ON, displayDevice->getPowerMode());
// The display refresh period should be set in the orientedDisplaySpaceRect tracker.
FrameStats stats;
mFlinger.getAnimFrameTracker().getStats(&stats);
EXPECT_EQ(DEFAULT_VSYNC_PERIOD, stats.refreshPeriodNano);
// The display transaction needed flag should be set.
EXPECT_TRUE(hasTransactionFlagSet(eDisplayTransactionNeeded));
// The compositor timing should be set to default values
const auto& compositorTiming = mFlinger.getCompositorTiming();
EXPECT_EQ(-DEFAULT_VSYNC_PERIOD, compositorTiming.deadline);
EXPECT_EQ(DEFAULT_VSYNC_PERIOD, compositorTiming.interval);
EXPECT_EQ(DEFAULT_VSYNC_PERIOD, compositorTiming.presentLatency);
}
} // namespace
} // namespace android
|