| Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 1 | /* | 
|  | 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 Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 18 | #include <compositionengine/mock/CompositionEngine.h> | 
| Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 19 | #include <compositionengine/mock/Layer.h> | 
|  | 20 | #include <compositionengine/mock/LayerFE.h> | 
|  | 21 | #include <compositionengine/mock/Output.h> | 
|  | 22 | #include <gtest/gtest.h> | 
|  | 23 |  | 
| Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 24 | #include "MockHWC2.h" | 
|  | 25 | #include "MockHWComposer.h" | 
|  | 26 |  | 
| Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 27 | namespace android::compositionengine { | 
|  | 28 | namespace { | 
|  | 29 |  | 
|  | 30 | using testing::StrictMock; | 
|  | 31 |  | 
| Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 32 | constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{42}; | 
|  | 33 |  | 
| Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 34 | class OutputLayerTest : public testing::Test { | 
|  | 35 | public: | 
|  | 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 |  | 
|  | 50 | TEST_F(OutputLayerTest, canInstantiateOutputLayer) {} | 
|  | 51 |  | 
| Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 52 | /* ------------------------------------------------------------------------ | 
|  | 53 | * OutputLayer::initialize() | 
|  | 54 | */ | 
|  | 55 |  | 
|  | 56 | TEST_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 |  | 
|  | 64 | TEST_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 Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 84 | } // namespace | 
|  | 85 | } // namespace android::compositionengine |