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 | |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 17 | #include <android-base/stringprintf.h> |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame^] | 18 | #include <compositionengine/CompositionEngine.h> |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 19 | #include <compositionengine/Layer.h> |
| 20 | #include <compositionengine/LayerFE.h> |
| 21 | #include <compositionengine/Output.h> |
| 22 | #include <compositionengine/impl/OutputLayer.h> |
| 23 | |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame^] | 24 | #include "DisplayHardware/HWComposer.h" |
| 25 | |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 26 | namespace android::compositionengine { |
| 27 | |
| 28 | OutputLayer::~OutputLayer() = default; |
| 29 | |
| 30 | namespace impl { |
| 31 | |
| 32 | std::unique_ptr<compositionengine::OutputLayer> createOutputLayer( |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame^] | 33 | const CompositionEngine& compositionEngine, std::optional<DisplayId> displayId, |
| 34 | const compositionengine::Output& output, std::shared_ptr<compositionengine::Layer> layer, |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 35 | sp<compositionengine::LayerFE> layerFE) { |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame^] | 36 | auto result = std::make_unique<OutputLayer>(output, layer, layerFE); |
| 37 | result->initialize(compositionEngine, displayId); |
| 38 | return result; |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | OutputLayer::OutputLayer(const Output& output, std::shared_ptr<Layer> layer, sp<LayerFE> layerFE) |
| 42 | : mOutput(output), mLayer(layer), mLayerFE(layerFE) {} |
| 43 | |
| 44 | OutputLayer::~OutputLayer() = default; |
| 45 | |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame^] | 46 | void OutputLayer::initialize(const CompositionEngine& compositionEngine, |
| 47 | std::optional<DisplayId> displayId) { |
| 48 | if (!displayId) { |
| 49 | return; |
| 50 | } |
| 51 | |
| 52 | auto& hwc = compositionEngine.getHwComposer(); |
| 53 | |
| 54 | mState.hwc.emplace(std::shared_ptr<HWC2::Layer>(hwc.createLayer(*displayId), |
| 55 | [&hwc, displayId](HWC2::Layer* layer) { |
| 56 | hwc.destroyLayer(*displayId, layer); |
| 57 | })); |
| 58 | } |
| 59 | |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 60 | const compositionengine::Output& OutputLayer::getOutput() const { |
| 61 | return mOutput; |
| 62 | } |
| 63 | |
| 64 | compositionengine::Layer& OutputLayer::getLayer() const { |
| 65 | return *mLayer; |
| 66 | } |
| 67 | |
| 68 | compositionengine::LayerFE& OutputLayer::getLayerFE() const { |
| 69 | return *mLayerFE; |
| 70 | } |
| 71 | |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 72 | const OutputLayerCompositionState& OutputLayer::getState() const { |
| 73 | return mState; |
| 74 | } |
| 75 | |
| 76 | OutputLayerCompositionState& OutputLayer::editState() { |
| 77 | return mState; |
| 78 | } |
| 79 | |
| 80 | void OutputLayer::dump(std::string& out) const { |
| 81 | using android::base::StringAppendF; |
| 82 | |
| 83 | StringAppendF(&out, " Output Layer %p\n", this); |
| 84 | mState.dump(out); |
| 85 | } |
| 86 | |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 87 | } // namespace impl |
| 88 | } // namespace android::compositionengine |