Lloyd Pique | feb73d7 | 2018-12-04 17:23:44 -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 | |
| 17 | #pragma once |
| 18 | |
Lloyd Pique | f16688f | 2019-02-19 17:47:57 -0800 | [diff] [blame] | 19 | #include <optional> |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 20 | #include <ostream> |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 21 | #include <unordered_set> |
Lloyd Pique | f16688f | 2019-02-19 17:47:57 -0800 | [diff] [blame] | 22 | |
Lloyd Pique | 3b5a69e | 2020-01-16 17:51:01 -0800 | [diff] [blame] | 23 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 24 | #pragma clang diagnostic push |
| 25 | #pragma clang diagnostic ignored "-Wconversion" |
| 26 | |
Lloyd Pique | f16688f | 2019-02-19 17:47:57 -0800 | [diff] [blame] | 27 | #include <renderengine/LayerSettings.h> |
Lloyd Pique | 3b5a69e | 2020-01-16 17:51:01 -0800 | [diff] [blame] | 28 | |
| 29 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 30 | #pragma clang diagnostic pop // ignored "-Wconversion" |
| 31 | |
Lloyd Pique | feb73d7 | 2018-12-04 17:23:44 -0800 | [diff] [blame] | 32 | #include <utils/RefBase.h> |
Lloyd Pique | 0e1c05e | 2019-01-29 18:42:48 -0800 | [diff] [blame] | 33 | #include <utils/Timers.h> |
Lloyd Pique | feb73d7 | 2018-12-04 17:23:44 -0800 | [diff] [blame] | 34 | |
Lloyd Pique | cb54b3b | 2019-01-29 18:42:54 -0800 | [diff] [blame] | 35 | namespace android { |
| 36 | |
| 37 | class Fence; |
| 38 | |
| 39 | namespace compositionengine { |
Lloyd Pique | feb73d7 | 2018-12-04 17:23:44 -0800 | [diff] [blame] | 40 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 41 | struct LayerFECompositionState; |
| 42 | |
Lloyd Pique | feb73d7 | 2018-12-04 17:23:44 -0800 | [diff] [blame] | 43 | // Defines the interface used by the CompositionEngine to make requests |
| 44 | // of the front-end layer |
Lloyd Pique | cb54b3b | 2019-01-29 18:42:54 -0800 | [diff] [blame] | 45 | class LayerFE : public virtual RefBase { |
| 46 | public: |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 47 | // Gets the raw front-end composition state data for the layer |
| 48 | virtual const LayerFECompositionState* getCompositionState() const = 0; |
| 49 | |
Lloyd Pique | 0e1c05e | 2019-01-29 18:42:48 -0800 | [diff] [blame] | 50 | // 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 Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 55 | // 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 Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 66 | // Gets the per frame content (buffer or color) state for the layer. |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 67 | Content, |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 68 | |
| 69 | // Gets the cursor state for the layer. |
| 70 | Cursor, |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 71 | }; |
| 72 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 73 | // Prepares the output-independent composition state for the layer. The |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 74 | // StateSubset argument selects what portion of the state is actually needed |
| 75 | // by the CompositionEngine code, since computing everything may be |
| 76 | // expensive. |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 77 | virtual void prepareCompositionState(StateSubset) = 0; |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 78 | |
Lloyd Pique | f16688f | 2019-02-19 17:47:57 -0800 | [diff] [blame] | 79 | 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 Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 95 | const bool supportsProtectedContent; |
Lloyd Pique | f16688f | 2019-02-19 17:47:57 -0800 | [diff] [blame] | 96 | |
| 97 | // Modified by each call to prepareClientComposition to indicate the |
| 98 | // region of the target buffer that should be cleared. |
| 99 | Region& clearRegion; |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 100 | |
| 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 Pique | f16688f | 2019-02-19 17:47:57 -0800 | [diff] [blame] | 115 | }; |
| 116 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 117 | // 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 Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 127 | // 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 Pique | f16688f | 2019-02-19 17:47:57 -0800 | [diff] [blame] | 131 | ClientCompositionTargetSettings&) = 0; |
| 132 | |
Lloyd Pique | cb54b3b | 2019-01-29 18:42:54 -0800 | [diff] [blame] | 133 | // Called after the layer is displayed to update the presentation fence |
| 134 | virtual void onLayerDisplayed(const sp<Fence>&) = 0; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 135 | |
| 136 | // Gets some kind of identifier for the layer for debug purposes. |
| 137 | virtual const char* getDebugName() const = 0; |
Lloyd Pique | cb54b3b | 2019-01-29 18:42:54 -0800 | [diff] [blame] | 138 | }; |
Lloyd Pique | feb73d7 | 2018-12-04 17:23:44 -0800 | [diff] [blame] | 139 | |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 140 | // TODO(b/121291683): Specialize std::hash<> for sp<T> so these and others can |
| 141 | // be removed. |
| 142 | struct LayerFESpHash { |
| 143 | size_t operator()(const sp<LayerFE>& p) const { return std::hash<LayerFE*>()(p.get()); } |
| 144 | }; |
| 145 | |
| 146 | using LayerFESet = std::unordered_set<sp<LayerFE>, LayerFESpHash>; |
| 147 | |
Lloyd Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 148 | static 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 Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 154 | 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 Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 158 | } |
| 159 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 160 | static 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 Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 167 | // Defining PrintTo helps with Google Tests. |
| 168 | static 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 Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 179 | *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 Pique | a486334 | 2019-12-04 18:45:02 -0800 | [diff] [blame] | 185 | *os << "\n}"; |
| 186 | } |
| 187 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 188 | static 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 Pique | cb54b3b | 2019-01-29 18:42:54 -0800 | [diff] [blame] | 196 | } // namespace compositionengine |
| 197 | } // namespace android |