blob: f7dcf6f08e51996d54851657ffd00a50bfb8202e [file] [log] [blame]
Lloyd Piquecc01a452018-12-04 17:24:00 -08001/*
2 * Copyright 2019 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#include <compositionengine/impl/OutputLayer.h>
Lloyd Pique07e33212018-12-18 16:33:37 -080018#include <compositionengine/mock/CompositionEngine.h>
Lloyd Piquecc01a452018-12-04 17:24:00 -080019#include <compositionengine/mock/Layer.h>
20#include <compositionengine/mock/LayerFE.h>
21#include <compositionengine/mock/Output.h>
22#include <gtest/gtest.h>
23
Lloyd Pique07e33212018-12-18 16:33:37 -080024#include "MockHWC2.h"
25#include "MockHWComposer.h"
26
Lloyd Piquecc01a452018-12-04 17:24:00 -080027namespace android::compositionengine {
28namespace {
29
30using testing::StrictMock;
31
Lloyd Pique07e33212018-12-18 16:33:37 -080032constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{42};
33
Lloyd Piquecc01a452018-12-04 17:24:00 -080034class OutputLayerTest : public testing::Test {
35public:
36 ~OutputLayerTest() override = default;
37
38 compositionengine::mock::Output mOutput;
39 std::shared_ptr<compositionengine::mock::Layer> mLayer{
40 new StrictMock<compositionengine::mock::Layer>()};
41 sp<compositionengine::mock::LayerFE> mLayerFE{
42 new StrictMock<compositionengine::mock::LayerFE>()};
43 impl::OutputLayer mOutputLayer{mOutput, mLayer, mLayerFE};
44};
45
46/* ------------------------------------------------------------------------
47 * Basic construction
48 */
49
50TEST_F(OutputLayerTest, canInstantiateOutputLayer) {}
51
Lloyd Pique07e33212018-12-18 16:33:37 -080052/* ------------------------------------------------------------------------
53 * OutputLayer::initialize()
54 */
55
56TEST_F(OutputLayerTest, initializingOutputLayerWithoutHwcDoesNothingInteresting) {
57 StrictMock<compositionengine::mock::CompositionEngine> compositionEngine;
58
59 mOutputLayer.initialize(compositionEngine, std::nullopt);
60
61 EXPECT_FALSE(mOutputLayer.getState().hwc);
62}
63
64TEST_F(OutputLayerTest, initializingOutputLayerWithHwcDisplayCreatesHwcLayer) {
65 StrictMock<compositionengine::mock::CompositionEngine> compositionEngine;
66 StrictMock<android::mock::HWComposer> hwc;
67 StrictMock<HWC2::mock::Layer> hwcLayer;
68
69 EXPECT_CALL(compositionEngine, getHwComposer()).WillOnce(ReturnRef(hwc));
70 EXPECT_CALL(hwc, createLayer(DEFAULT_DISPLAY_ID)).WillOnce(Return(&hwcLayer));
71
72 mOutputLayer.initialize(compositionEngine, DEFAULT_DISPLAY_ID);
73
74 const auto& state = mOutputLayer.getState();
75 ASSERT_TRUE(state.hwc);
76
77 const auto& hwcState = *state.hwc;
78 EXPECT_EQ(&hwcLayer, hwcState.hwcLayer.get());
79
80 EXPECT_CALL(hwc, destroyLayer(DEFAULT_DISPLAY_ID, &hwcLayer));
81 mOutputLayer.editState().hwc.reset();
82}
83
Lloyd Piquecc01a452018-12-04 17:24:00 -080084} // namespace
85} // namespace android::compositionengine