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