blob: 6cc90cb3ee729e376058f761f95b59d11039be1e [file] [log] [blame]
Lloyd Piquefeb73d72018-12-04 17:23:44 -08001/*
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
Lloyd Piquef16688f2019-02-19 17:47:57 -080019#include <optional>
Lloyd Piquea4863342019-12-04 18:45:02 -080020#include <ostream>
Lloyd Piquec29e4c62019-03-07 21:48:19 -080021#include <unordered_set>
Lloyd Piquef16688f2019-02-19 17:47:57 -080022
Lloyd Pique3b5a69e2020-01-16 17:51:01 -080023// TODO(b/129481165): remove the #pragma below and fix conversion issues
24#pragma clang diagnostic push
25#pragma clang diagnostic ignored "-Wconversion"
26
Lloyd Piquef16688f2019-02-19 17:47:57 -080027#include <renderengine/LayerSettings.h>
Lloyd Pique3b5a69e2020-01-16 17:51:01 -080028
29// TODO(b/129481165): remove the #pragma below and fix conversion issues
30#pragma clang diagnostic pop // ignored "-Wconversion"
31
Lloyd Piquefeb73d72018-12-04 17:23:44 -080032#include <utils/RefBase.h>
Lloyd Pique0e1c05e2019-01-29 18:42:48 -080033#include <utils/Timers.h>
Lloyd Piquefeb73d72018-12-04 17:23:44 -080034
Lloyd Piquecb54b3b2019-01-29 18:42:54 -080035namespace android {
36
37class Fence;
38
39namespace compositionengine {
Lloyd Piquefeb73d72018-12-04 17:23:44 -080040
Lloyd Piquea83776c2019-01-29 18:42:32 -080041struct LayerFECompositionState;
42
Lloyd Piquefeb73d72018-12-04 17:23:44 -080043// Defines the interface used by the CompositionEngine to make requests
44// of the front-end layer
Lloyd Piquecb54b3b2019-01-29 18:42:54 -080045class LayerFE : public virtual RefBase {
46public:
Lloyd Piquede196652020-01-22 17:29:58 -080047 // Gets the raw front-end composition state data for the layer
48 virtual const LayerFECompositionState* getCompositionState() const = 0;
49
Lloyd Pique0e1c05e2019-01-29 18:42:48 -080050 // Called before composition starts. Should return true if this layer has
51 // pending updates which would require an extra display refresh cycle to
52 // process.
53 virtual bool onPreComposition(nsecs_t refreshStartTime) = 0;
54
Lloyd Piquec6687342019-03-07 21:34:57 -080055 // Used with latchCompositionState()
56 enum class StateSubset {
57 // Gets the basic geometry (bounds, transparent region, visibility,
58 // transforms, alpha) for the layer, for computing visibility and
59 // coverage.
60 BasicGeometry,
61
62 // Gets the full geometry (crops, buffer transforms, metadata) and
63 // content (buffer or color) state for the layer.
64 GeometryAndContent,
65
Lloyd Piquede196652020-01-22 17:29:58 -080066 // Gets the per frame content (buffer or color) state for the layer.
Lloyd Piquec6687342019-03-07 21:34:57 -080067 Content,
Lloyd Piquede196652020-01-22 17:29:58 -080068
69 // Gets the cursor state for the layer.
70 Cursor,
Lloyd Piquec6687342019-03-07 21:34:57 -080071 };
72
Lloyd Piquede196652020-01-22 17:29:58 -080073 // Prepares the output-independent composition state for the layer. The
Lloyd Piquec6687342019-03-07 21:34:57 -080074 // StateSubset argument selects what portion of the state is actually needed
75 // by the CompositionEngine code, since computing everything may be
76 // expensive.
Lloyd Piquede196652020-01-22 17:29:58 -080077 virtual void prepareCompositionState(StateSubset) = 0;
Lloyd Piquec7b0c752019-03-07 20:59:59 -080078
Lloyd Piquef16688f2019-02-19 17:47:57 -080079 struct ClientCompositionTargetSettings {
80 // The clip region, or visible region that is being rendered to
81 const Region& clip;
82
83 // If true, the layer should use an identity transform for its position
84 // transform. Used only by the captureScreen API call.
85 const bool useIdentityTransform;
86
87 // If set to true, the layer should enable filtering when rendering.
88 const bool needsFiltering;
89
90 // If set to true, the buffer is being sent to a destination that is
91 // expected to treat the buffer contents as secure.
92 const bool isSecure;
93
94 // If set to true, the target buffer has protected content support.
Lloyd Pique688abd42019-02-15 15:42:24 -080095 const bool supportsProtectedContent;
Lloyd Piquef16688f2019-02-19 17:47:57 -080096
97 // Modified by each call to prepareClientComposition to indicate the
98 // region of the target buffer that should be cleared.
99 Region& clearRegion;
Vishnu Nairb87d94f2020-02-13 09:17:36 -0800100
101 // Viewport of the target being rendered to. This is used to determine
102 // the shadow light position.
103 const Rect& viewport;
104
105 // Dataspace of the output so we can optimize how to render the shadow
106 // by avoiding unnecessary color space conversions.
107 const ui::Dataspace dataspace;
108
109 // True if the region excluding the shadow is visible.
110 const bool realContentIsVisible;
111
112 // If set to true, change the layer settings to render a clear output.
113 // This may be requested by the HWC
114 const bool clearContent;
Lloyd Piquef16688f2019-02-19 17:47:57 -0800115 };
116
Vishnu Nair9b079a22020-01-21 14:36:08 -0800117 // A superset of LayerSettings required by RenderEngine to compose a layer
118 // and buffer info to determine duplicate client composition requests.
119 struct LayerSettings : renderengine::LayerSettings {
120 // Currently latched buffer if, 0 if invalid.
121 uint64_t bufferId = 0;
122
123 // Currently latched frame number, 0 if invalid.
124 uint64_t frameNumber = 0;
125 };
126
Vishnu Nairb87d94f2020-02-13 09:17:36 -0800127 // Returns the z-ordered list of LayerSettings to pass to RenderEngine::drawLayers. The list
128 // may contain shadows casted by the layer or the content of the layer itself. If the layer
129 // does not render then an empty list will be returned.
130 virtual std::vector<LayerSettings> prepareClientCompositionList(
Lloyd Piquef16688f2019-02-19 17:47:57 -0800131 ClientCompositionTargetSettings&) = 0;
132
Lloyd Piquecb54b3b2019-01-29 18:42:54 -0800133 // Called after the layer is displayed to update the presentation fence
134 virtual void onLayerDisplayed(const sp<Fence>&) = 0;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800135
136 // Gets some kind of identifier for the layer for debug purposes.
137 virtual const char* getDebugName() const = 0;
Lloyd Piquecb54b3b2019-01-29 18:42:54 -0800138};
Lloyd Piquefeb73d72018-12-04 17:23:44 -0800139
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800140// TODO(b/121291683): Specialize std::hash<> for sp<T> so these and others can
141// be removed.
142struct LayerFESpHash {
143 size_t operator()(const sp<LayerFE>& p) const { return std::hash<LayerFE*>()(p.get()); }
144};
145
146using LayerFESet = std::unordered_set<sp<LayerFE>, LayerFESpHash>;
147
Lloyd Piquea4863342019-12-04 18:45:02 -0800148static inline bool operator==(const LayerFE::ClientCompositionTargetSettings& lhs,
149 const LayerFE::ClientCompositionTargetSettings& rhs) {
150 return lhs.clip.hasSameRects(rhs.clip) &&
151 lhs.useIdentityTransform == rhs.useIdentityTransform &&
152 lhs.needsFiltering == rhs.needsFiltering && lhs.isSecure == rhs.isSecure &&
153 lhs.supportsProtectedContent == rhs.supportsProtectedContent &&
Vishnu Nairb87d94f2020-02-13 09:17:36 -0800154 lhs.clearRegion.hasSameRects(rhs.clearRegion) && lhs.viewport == rhs.viewport &&
155 lhs.dataspace == rhs.dataspace &&
156 lhs.realContentIsVisible == rhs.realContentIsVisible &&
157 lhs.clearContent == rhs.clearContent;
Lloyd Piquea4863342019-12-04 18:45:02 -0800158}
159
Vishnu Nair9b079a22020-01-21 14:36:08 -0800160static inline bool operator==(const LayerFE::LayerSettings& lhs,
161 const LayerFE::LayerSettings& rhs) {
162 return static_cast<const renderengine::LayerSettings&>(lhs) ==
163 static_cast<const renderengine::LayerSettings&>(rhs) &&
164 lhs.bufferId == rhs.bufferId && lhs.frameNumber == rhs.frameNumber;
165}
166
Lloyd Piquea4863342019-12-04 18:45:02 -0800167// Defining PrintTo helps with Google Tests.
168static inline void PrintTo(const LayerFE::ClientCompositionTargetSettings& settings,
169 ::std::ostream* os) {
170 *os << "ClientCompositionTargetSettings{";
171 *os << "\n .clip = \n";
172 PrintTo(settings.clip, os);
173 *os << "\n .useIdentityTransform = " << settings.useIdentityTransform;
174 *os << "\n .needsFiltering = " << settings.needsFiltering;
175 *os << "\n .isSecure = " << settings.isSecure;
176 *os << "\n .supportsProtectedContent = " << settings.supportsProtectedContent;
177 *os << "\n .clearRegion = ";
178 PrintTo(settings.clearRegion, os);
Vishnu Nairb87d94f2020-02-13 09:17:36 -0800179 *os << "\n .viewport = ";
180 PrintTo(settings.viewport, os);
181 *os << "\n .dataspace = ";
182 PrintTo(settings.dataspace, os);
183 *os << "\n .realContentIsVisible = " << settings.realContentIsVisible;
184 *os << "\n .clearContent = " << settings.clearContent;
Lloyd Piquea4863342019-12-04 18:45:02 -0800185 *os << "\n}";
186}
187
Vishnu Nair9b079a22020-01-21 14:36:08 -0800188static inline void PrintTo(const LayerFE::LayerSettings& settings, ::std::ostream* os) {
189 *os << "LayerFE::LayerSettings{";
190 PrintTo(static_cast<const renderengine::LayerSettings&>(settings), os);
191 *os << "\n .bufferId = " << settings.bufferId;
192 *os << "\n .frameNumber = " << settings.frameNumber;
193 *os << "\n}";
194}
195
Lloyd Piquecb54b3b2019-01-29 18:42:54 -0800196} // namespace compositionengine
197} // namespace android