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 <compositionengine/ProjectionSpace.h> 20 #include <compositionengine/impl/HwcBufferCache.h> 21 #include <gui/DisplayLuts.h> 22 #include <renderengine/ExternalTexture.h> 23 #include <ui/FloatRect.h> 24 #include <ui/GraphicTypes.h> 25 #include <ui/PictureProfileHandle.h> 26 #include <ui/Rect.h> 27 #include <ui/Region.h> 28 29 #include <cstdint> 30 #include <optional> 31 #include <string> 32 33 // TODO(b/129481165): remove the #pragma below and fix conversion issues 34 #pragma clang diagnostic push 35 #pragma clang diagnostic ignored "-Wconversion" 36 #pragma clang diagnostic ignored "-Wextra" 37 38 #include "DisplayHardware/ComposerHal.h" 39 40 #include <aidl/android/hardware/graphics/composer3/Composition.h> 41 42 // TODO(b/129481165): remove the #pragma below and fix conversion issues 43 #pragma clang diagnostic pop // ignored "-Wconversion -Wextra" 44 45 namespace android { 46 47 namespace HWC2 { 48 class Layer; 49 } // namespace HWC2 50 51 class HWComposer; 52 53 namespace compositionengine { 54 class OutputLayer; 55 } // namespace compositionengine 56 57 namespace compositionengine::impl { 58 59 // Note that fields that affect HW composer state may need to be mirrored into 60 // android::compositionengine::impl::planner::LayerState 61 struct OutputLayerCompositionState { 62 // The portion of the layer that is not obscured by opaque layers on top 63 Region visibleRegion; 64 65 // The portion of the layer that is not obscured and is also opaque 66 Region visibleNonTransparentRegion; 67 68 // The portion of the layer that is obscured by all layers on top. This includes transparent and 69 // opaque. 70 Region coveredRegion; 71 72 // The portion of the layer that is obscured by all layers on top excluding display overlays. 73 // This only has a value if there's something needing it, like when a 74 // TrustedPresentationListener is set. 75 std::optional<Region> coveredRegionExcludingDisplayOverlays; 76 77 // The visibleRegion transformed to output space 78 Region outputSpaceVisibleRegion; 79 80 // Region cast by the layer's shadow 81 Region shadowRegion; 82 83 // If true, client composition will be used on this output 84 bool forceClientComposition{false}; 85 86 // If true, when doing client composition, the target may need to be cleared 87 bool clearClientTarget{false}; 88 89 // The display frame for this layer on this output 90 Rect displayFrame; 91 92 // The source crop for this layer on this output 93 FloatRect sourceCrop; 94 95 // The buffer transform to use for this layer on this output. 96 Hwc2::Transform bufferTransform{static_cast<Hwc2::Transform>(0)}; 97 98 // The dataspace for this layer 99 ui::Dataspace dataspace{ui::Dataspace::UNKNOWN}; 100 101 // A hint to the HWC that this region is transparent and may be skipped in 102 // order to save power. 103 Region outputSpaceBlockingRegionHint; 104 105 // The picture profile for this layer. 106 PictureProfileHandle pictureProfileHandle; 107 108 // Overrides the buffer, acquire fence, and display frame stored in LayerFECompositionState 109 struct { 110 std::shared_ptr<renderengine::ExternalTexture> buffer = nullptr; 111 sp<Fence> acquireFence = nullptr; 112 Rect displayFrame = {}; 113 ui::Dataspace dataspace{ui::Dataspace::UNKNOWN}; 114 ProjectionSpace displaySpace; 115 Region damageRegion = Region::INVALID_REGION; 116 Region visibleRegion; 117 118 // The OutputLayer pointed to by this field will be rearranged to draw 119 // behind the OutputLayer represented by this CompositionState and will 120 // be visible through it. Unowned - the OutputLayer's lifetime will 121 // outlast this.) 122 compositionengine::OutputLayer* peekThroughLayer = nullptr; 123 // True when this layer's blur has been cached with a previous layer, so that this layer 124 // does not need to request blurring. 125 // TODO(b/188816867): support blur regions too, which are less likely to be common if a 126 // device supports cross-window blurs. Blur region support should be doable, but we would 127 // need to make sure that layer caching works well with the blur region transform passed 128 // into RenderEngine 129 bool disableBackgroundBlur = false; 130 } overrideInfo; 131 132 /* 133 * HWC state 134 */ 135 136 struct Hwc { HwcOutputLayerCompositionState::Hwc137 explicit Hwc(std::shared_ptr<HWC2::Layer> hwcLayer) : hwcLayer(hwcLayer) {} 138 139 // The HWC Layer backing this layer 140 std::shared_ptr<HWC2::Layer> hwcLayer; 141 142 // The most recently set HWC composition type for this layer 143 aidl::android::hardware::graphics::composer3::Composition hwcCompositionType{ 144 aidl::android::hardware::graphics::composer3::Composition::INVALID}; 145 146 // The buffer cache for this layer. This is used to lower the 147 // cost of sending reused buffers to the HWC. 148 HwcBufferCache hwcBufferCache; 149 150 // The previously-active buffer for this layer. 151 uint64_t activeBufferId; 152 uint32_t activeBufferSlot; 153 154 // Set to true when overridden info has been sent to HW composer 155 bool stateOverridden = false; 156 157 // True when this layer was skipped as part of SF-side layer caching. 158 bool layerSkipped = false; 159 160 // lut information 161 std::shared_ptr<gui::DisplayLuts> luts; 162 }; 163 164 // The HWC state is optional, and is only set up if there is any potential 165 // HWC acceleration possible. 166 std::optional<Hwc> hwc; 167 168 // Debugging 169 void dump(std::string& result) const; 170 171 // Timestamp for when the layer is queued for client composition 172 nsecs_t clientCompositionTimestamp{0}; 173 174 static constexpr float kDefaultWhitePointNits = 200.f; 175 float whitePointNits = kDefaultWhitePointNits; 176 // Dimming ratio of the layer from [0, 1] 177 static constexpr float kDefaultDimmingRatio = 1.f; 178 float dimmingRatio = kDefaultDimmingRatio; 179 }; 180 181 } // namespace compositionengine::impl 182 } // namespace android 183