Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -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 | |
| 19 | #include <cstdint> |
| 20 | |
Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 21 | #include <gui/HdrMetadata.h> |
| 22 | #include <math/mat4.h> |
| 23 | #include <ui/FloatRect.h> |
Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 24 | #include <ui/Rect.h> |
| 25 | #include <ui/Region.h> |
| 26 | #include <ui/Transform.h> |
| 27 | |
Lloyd Pique | 3b5a69e | 2020-01-16 17:51:01 -0800 | [diff] [blame] | 28 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 29 | #pragma clang diagnostic push |
| 30 | #pragma clang diagnostic ignored "-Wconversion" |
| 31 | |
| 32 | #include <gui/BufferQueue.h> |
| 33 | #include <ui/GraphicBuffer.h> |
| 34 | #include <ui/GraphicTypes.h> |
| 35 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 36 | #include "DisplayHardware/Hal.h" |
Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 37 | |
Lloyd Pique | 3b5a69e | 2020-01-16 17:51:01 -0800 | [diff] [blame] | 38 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 39 | #pragma clang diagnostic pop // ignored "-Wconversion" |
| 40 | |
Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 41 | namespace android::compositionengine { |
| 42 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 43 | namespace hal = android::hardware::graphics::composer::hal; |
| 44 | |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 45 | // More complex metadata for this layer |
| 46 | struct GenericLayerMetadataEntry { |
| 47 | // True if the metadata may affect the composed result. |
| 48 | // See setLayerGenericMetadata in IComposerClient.hal |
| 49 | bool mandatory; |
| 50 | |
| 51 | // Byte blob or parcel |
| 52 | std::vector<uint8_t> value; |
| 53 | |
| 54 | std::string dumpAsString() const; |
| 55 | }; |
| 56 | |
| 57 | inline bool operator==(const GenericLayerMetadataEntry& lhs, const GenericLayerMetadataEntry& rhs) { |
| 58 | return lhs.mandatory == rhs.mandatory && lhs.value == rhs.value; |
| 59 | } |
| 60 | |
| 61 | // Defining PrintTo helps with Google Tests. |
| 62 | inline void PrintTo(const GenericLayerMetadataEntry& v, ::std::ostream* os) { |
| 63 | *os << v.dumpAsString(); |
| 64 | } |
| 65 | |
| 66 | using GenericLayerMetadataMap = std::unordered_map<std::string, GenericLayerMetadataEntry>; |
| 67 | |
Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 68 | /* |
| 69 | * Used by LayerFE::getCompositionState |
| 70 | */ |
| 71 | struct LayerFECompositionState { |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 72 | // If set to true, forces client composition on all output layers until |
| 73 | // the next geometry change. |
| 74 | bool forceClientComposition{false}; |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 75 | |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 76 | // TODO(b/121291683): Reorganize and rename the contents of this structure |
| 77 | |
| 78 | /* |
| 79 | * Visibility state |
| 80 | */ |
| 81 | // the layer stack this layer belongs to |
| 82 | std::optional<uint32_t> layerStackId; |
| 83 | |
| 84 | // If true, this layer should be only visible on the internal display |
| 85 | bool internalOnly{false}; |
| 86 | |
| 87 | // If false, this layer should not be considered visible |
| 88 | bool isVisible{true}; |
| 89 | |
| 90 | // True if the layer is completely opaque |
| 91 | bool isOpaque{true}; |
| 92 | |
| 93 | // If true, invalidates the entire visible region |
| 94 | bool contentDirty{false}; |
| 95 | |
| 96 | // The alpha value for this layer |
| 97 | float alpha{1.f}; |
| 98 | |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 99 | // Background blur in pixels |
| 100 | int backgroundBlurRadius{0}; |
| 101 | |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 102 | // The transform from layer local coordinates to composition coordinates |
| 103 | ui::Transform geomLayerTransform; |
| 104 | |
| 105 | // The inverse of the layer transform |
| 106 | ui::Transform geomInverseLayerTransform; |
| 107 | |
| 108 | // The hint from the layer producer as to what portion of the layer is |
| 109 | // transparent. |
| 110 | Region transparentRegionHint; |
| 111 | |
| 112 | // The blend mode for this layer |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 113 | hal::BlendMode blendMode{hal::BlendMode::INVALID}; |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 114 | |
| 115 | // The bounds of the layer in layer local coordinates |
| 116 | FloatRect geomLayerBounds; |
| 117 | |
Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 118 | // length of the shadow in screen space |
| 119 | float shadowRadius; |
| 120 | |
Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 121 | /* |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 122 | * Geometry state |
| 123 | */ |
| 124 | |
| 125 | bool isSecure{false}; |
| 126 | bool geomUsesSourceCrop{false}; |
| 127 | bool geomBufferUsesDisplayInverseTransform{false}; |
| 128 | uint32_t geomBufferTransform{0}; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 129 | Rect geomBufferSize; |
| 130 | Rect geomContentCrop; |
| 131 | Rect geomCrop; |
Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 132 | |
| 133 | /* |
| 134 | * Extra metadata |
| 135 | */ |
| 136 | |
| 137 | // The type for this layer |
| 138 | int type{0}; |
| 139 | |
| 140 | // The appId for this layer |
| 141 | int appId{0}; |
| 142 | |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 143 | GenericLayerMetadataMap metadata; |
| 144 | |
Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 145 | /* |
| 146 | * Per-frame content |
| 147 | */ |
| 148 | |
| 149 | // The type of composition for this layer |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 150 | hal::Composition compositionType{hal::Composition::INVALID}; |
Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 151 | |
| 152 | // The buffer and related state |
| 153 | sp<GraphicBuffer> buffer; |
| 154 | int bufferSlot{BufferQueue::INVALID_BUFFER_SLOT}; |
| 155 | sp<Fence> acquireFence; |
| 156 | Region surfaceDamage; |
| 157 | |
| 158 | // The handle to use for a sideband stream for this layer |
| 159 | sp<NativeHandle> sidebandStream; |
| 160 | |
| 161 | // The color for this layer |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 162 | half4 color; |
Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 163 | |
| 164 | /* |
| 165 | * Per-frame presentation state |
| 166 | */ |
| 167 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 168 | // If true, this layer will use the dataspace chosen for the output and |
| 169 | // ignore the dataspace value just below |
| 170 | bool isColorspaceAgnostic{false}; |
| 171 | |
Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 172 | // The dataspace for this layer |
| 173 | ui::Dataspace dataspace{ui::Dataspace::UNKNOWN}; |
| 174 | |
| 175 | // The metadata for this layer |
| 176 | HdrMetadata hdrMetadata; |
| 177 | |
| 178 | // The color transform |
| 179 | mat4 colorTransform; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 180 | bool colorTransformIsIdentity{true}; |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 181 | |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 182 | // True if the layer has protected content |
| 183 | bool hasProtectedContent{false}; |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 184 | |
| 185 | /* |
| 186 | * Cursor state |
| 187 | */ |
| 188 | |
| 189 | // The output-independent frame for the cursor |
| 190 | Rect cursorFrame; |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 191 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 192 | virtual ~LayerFECompositionState(); |
| 193 | |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 194 | // Debugging |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 195 | virtual void dump(std::string& out) const; |
Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 196 | }; |
| 197 | |
| 198 | } // namespace android::compositionengine |