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 <optional>
21 #include <string>
22 #include <vector>
23 
24 #include <ui/Transform.h>
25 #include <utils/StrongPointer.h>
26 
27 // TODO(b/129481165): remove the #pragma below and fix conversion issues
28 #pragma clang diagnostic push
29 #pragma clang diagnostic ignored "-Wconversion"
30 #pragma clang diagnostic ignored "-Wextra"
31 
32 #include <ui/DisplayIdentification.h>
33 #include "DisplayHardware/ComposerHal.h"
34 
35 #include "LayerFE.h"
36 
37 #include <aidl/android/hardware/graphics/composer3/Composition.h>
38 
39 // TODO(b/129481165): remove the #pragma below and fix conversion issues
40 #pragma clang diagnostic pop // ignored "-Wconversion -Wextra"
41 
42 namespace android {
43 
44 namespace HWC2 {
45 class Layer;
46 } // namespace HWC2
47 
48 namespace compositionengine {
49 
50 class CompositionEngine;
51 class Output;
52 
53 namespace impl {
54 struct OutputLayerCompositionState;
55 } // namespace impl
56 
57 /**
58  * An output layer contains the output-dependent composition state for a layer
59  */
60 class OutputLayer {
61 public:
62     virtual ~OutputLayer();
63 
64     // Sets the HWC2::Layer associated with this layer
65     virtual void setHwcLayer(std::shared_ptr<HWC2::Layer>) = 0;
66 
67     // Gets the output which owns this output layer
68     virtual const Output& getOutput() const = 0;
69 
70     // Gets the front-end layer interface this output layer represents
71     virtual LayerFE& getLayerFE() const = 0;
72 
73     using CompositionState = compositionengine::impl::OutputLayerCompositionState;
74 
75     // Gets the raw composition state data for the layer
76     // TODO(lpique): Make this protected once it is only internally called.
77     virtual const CompositionState& getState() const = 0;
78 
79     // Allows mutable access to the raw composition state data for the layer.
80     // This is meant to be used by the various functions that are part of the
81     // composition process.
82     // TODO(lpique): Make this protected once it is only internally called.
83     virtual CompositionState& editState() = 0;
84 
85     // Clear the cache entries for a set of buffers that SurfaceFlinger no
86     // longer cares about.
87     virtual void uncacheBuffers(const std::vector<uint64_t>& bufferIdsToUncache) = 0;
88 
89     // Recalculates the state of the output layer from the output-independent
90     // layer. If includeGeometry is false, the geometry state can be skipped.
91     // internalDisplayRotationFlags must be set to the rotation flags for the
92     // internal display, and is used to properly compute the inverse-display
93     // transform, if needed.
94     virtual void updateCompositionState(
95             bool includeGeometry, bool forceClientComposition,
96             ui::Transform::RotationFlags internalDisplayRotationFlags) = 0;
97 
98     // Writes the geometry state to the HWC, or does nothing if this layer does
99     // not use the HWC. If includeGeometry is false, the geometry state can be
100     // skipped. If skipLayer is true, then the alpha of the layer is forced to
101     // 0 so that HWC will ignore it. z specifies the order to draw the layer in
102     // (starting with 0 for the back layer, and increasing for each following
103     // layer). zIsOverridden specifies whether the layer has been reordered.
104     // isPeekingThrough specifies whether this layer will be shown through a
105     // hole punch in a layer above it.
106     virtual void writeStateToHWC(bool includeGeometry, bool skipLayer, uint32_t z,
107                                  bool zIsOverridden, bool isPeekingThrough) = 0;
108 
109     // Updates the cursor position with the HWC
110     virtual void writeCursorPositionToHWC() const = 0;
111 
112     // Returns the HWC2::Layer associated with this layer, if it exists
113     virtual HWC2::Layer* getHwcLayer() const = 0;
114 
115     // Returns true if the current layer state requires client composition
116     virtual bool requiresClientComposition() const = 0;
117 
118     // Returns true if the current layer should be treated as a cursor layer
119     virtual bool isHardwareCursor() const = 0;
120 
121     // Applies a HWC device requested composition type change
122     virtual void applyDeviceCompositionTypeChange(
123             aidl::android::hardware::graphics::composer3::Composition) = 0;
124 
125     // Prepares to apply any HWC device layer requests
126     virtual void prepareForDeviceLayerRequests() = 0;
127 
128     // Applies a HWC device layer request
129     virtual void applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest request) = 0;
130 
131     // Returns true if the composition settings scale pixels
132     virtual bool needsFiltering() const = 0;
133 
134     // Returns LayerSettings to be used by RenderEngine if the layer has been overridden
135     // during the composition process
136     virtual std::optional<LayerFE::LayerSettings> getOverrideCompositionSettings() const = 0;
137 
138     // Debugging
139     virtual void dump(std::string& result) const = 0;
140 };
141 
142 } // namespace compositionengine
143 } // namespace android
144