• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #pragma once
18 
19 #include <cstdint>
20 #include <memory>
21 #include <string>
22 
23 #include <compositionengine/LayerFE.h>
24 #include <compositionengine/OutputLayer.h>
25 #include <ui/FloatRect.h>
26 #include <ui/Rect.h>
27 
28 #include <ui/DisplayIdentification.h>
29 
30 #include <aidl/android/hardware/graphics/composer3/Composition.h>
31 
32 namespace android::compositionengine {
33 
34 struct LayerFECompositionState;
35 
36 namespace impl {
37 
38 // The implementation class contains the common implementation, but does not
39 // actually contain the final layer state.
40 class OutputLayer : public virtual compositionengine::OutputLayer {
41 public:
42     ~OutputLayer() override;
43 
44     void setHwcLayer(std::shared_ptr<HWC2::Layer>) override;
45 
46     void updateCompositionState(bool includeGeometry, bool forceClientComposition,
47                                 ui::Transform::RotationFlags) override;
48     void writeStateToHWC(bool includeGeometry, bool skipLayer, uint32_t z, bool zIsOverridden,
49                          bool isPeekingThrough) override;
50     void writeCursorPositionToHWC() const override;
51 
52     HWC2::Layer* getHwcLayer() const override;
53     bool requiresClientComposition() const override;
54     bool isHardwareCursor() const override;
55     void applyDeviceCompositionTypeChange(
56             aidl::android::hardware::graphics::composer3::Composition) override;
57     void prepareForDeviceLayerRequests() override;
58     void applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest request) override;
59     bool needsFiltering() const override;
60     std::vector<LayerFE::LayerSettings> getOverrideCompositionList() const override;
61 
62     void dump(std::string&) const override;
63     virtual FloatRect calculateOutputSourceCrop(uint32_t internalDisplayRotationFlags) const;
64     virtual Rect calculateOutputDisplayFrame() const;
65     virtual uint32_t calculateOutputRelativeBufferTransform(
66             uint32_t internalDisplayRotationFlags) const;
67 
68 protected:
69     // Implemented by the final implementation for the final state it uses.
70     virtual void dumpState(std::string&) const = 0;
71 
72 private:
73     Rect calculateInitialCrop() const;
74     void writeOutputDependentGeometryStateToHWC(
75             HWC2::Layer*, aidl::android::hardware::graphics::composer3::Composition, uint32_t z);
76     void writeOutputIndependentGeometryStateToHWC(HWC2::Layer*, const LayerFECompositionState&,
77                                                   bool skipLayer);
78     void writeOutputDependentPerFrameStateToHWC(HWC2::Layer*);
79     void writeOutputIndependentPerFrameStateToHWC(
80             HWC2::Layer*, const LayerFECompositionState&,
81             aidl::android::hardware::graphics::composer3::Composition compositionType,
82             bool skipLayer);
83     void writeSolidColorStateToHWC(HWC2::Layer*, const LayerFECompositionState&);
84     void writeSidebandStateToHWC(HWC2::Layer*, const LayerFECompositionState&);
85     void writeBufferStateToHWC(HWC2::Layer*, const LayerFECompositionState&, bool skipLayer);
86     void writeCompositionTypeToHWC(HWC2::Layer*,
87                                    aidl::android::hardware::graphics::composer3::Composition,
88                                    bool isPeekingThrough, bool skipLayer);
89     void detectDisallowedCompositionTypeChange(
90             aidl::android::hardware::graphics::composer3::Composition from,
91             aidl::android::hardware::graphics::composer3::Composition to) const;
92     bool isClientCompositionForced(bool isPeekingThrough) const;
93 };
94 
95 // This template factory function standardizes the implementation details of the
96 // final class using the types actually required by the implementation. This is
97 // not possible to do in the base class as those types may not even be visible
98 // to the base code.
99 template <typename BaseOutputLayer>
createOutputLayerTemplated(const Output & output,sp<LayerFE> layerFE)100 std::unique_ptr<BaseOutputLayer> createOutputLayerTemplated(const Output& output,
101                                                             sp<LayerFE> layerFE) {
102     class OutputLayer final : public BaseOutputLayer {
103     public:
104 // Clang incorrectly complains that these are unused.
105 #pragma clang diagnostic push
106 #pragma clang diagnostic ignored "-Wunused-local-typedef"
107 
108         using OutputLayerCompositionState = std::remove_const_t<
109                 std::remove_reference_t<decltype(std::declval<BaseOutputLayer>().getState())>>;
110         using Output = std::remove_const_t<
111                 std::remove_reference_t<decltype(std::declval<BaseOutputLayer>().getOutput())>>;
112         using LayerFE =
113                 std::remove_reference_t<decltype(std::declval<BaseOutputLayer>().getLayerFE())>;
114 
115 #pragma clang diagnostic pop
116 
117         OutputLayer(const Output& output, const sp<LayerFE>& layerFE)
118               : mOutput(output), mLayerFE(layerFE) {}
119         ~OutputLayer() override = default;
120 
121     private:
122         // compositionengine::OutputLayer overrides
123         const Output& getOutput() const override { return mOutput; }
124         LayerFE& getLayerFE() const override { return *mLayerFE; }
125         const OutputLayerCompositionState& getState() const override { return mState; }
126         OutputLayerCompositionState& editState() override { return mState; }
127 
128         // compositionengine::impl::OutputLayer overrides
129         void dumpState(std::string& out) const override { mState.dump(out); }
130 
131         const Output& mOutput;
132         const sp<LayerFE> mLayerFE;
133         OutputLayerCompositionState mState;
134     };
135 
136     return std::make_unique<OutputLayer>(output, layerFE);
137 }
138 
139 std::unique_ptr<OutputLayer> createOutputLayer(const compositionengine::Output&,
140                                                const sp<LayerFE>&);
141 
142 } // namespace impl
143 } // namespace android::compositionengine
144