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