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