• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 all layers on top. This includes transparent and
67     // opaque.
68     Region coveredRegion;
69 
70     // The portion of the layer that is obscured by all layers on top excluding display overlays.
71     // This only has a value if there's something needing it, like when a
72     // TrustedPresentationListener is set.
73     std::optional<Region> coveredRegionExcludingDisplayOverlays;
74 
75     // The visibleRegion transformed to output space
76     Region outputSpaceVisibleRegion;
77 
78     // Region cast by the layer's shadow
79     Region shadowRegion;
80 
81     // If true, client composition will be used on this output
82     bool forceClientComposition{false};
83 
84     // If true, when doing client composition, the target may need to be cleared
85     bool clearClientTarget{false};
86 
87     // The display frame for this layer on this output
88     Rect displayFrame;
89 
90     // The source crop for this layer on this output
91     FloatRect sourceCrop;
92 
93     // The buffer transform to use for this layer on this output.
94     Hwc2::Transform bufferTransform{static_cast<Hwc2::Transform>(0)};
95 
96     // The dataspace for this layer
97     ui::Dataspace dataspace{ui::Dataspace::UNKNOWN};
98 
99     // A hint to the HWC that this region is transparent and may be skipped in
100     // order to save power.
101     Region outputSpaceBlockingRegionHint;
102 
103     // Overrides the buffer, acquire fence, and display frame stored in LayerFECompositionState
104     struct {
105         std::shared_ptr<renderengine::ExternalTexture> buffer = nullptr;
106         sp<Fence> acquireFence = nullptr;
107         Rect displayFrame = {};
108         ui::Dataspace dataspace{ui::Dataspace::UNKNOWN};
109         ProjectionSpace displaySpace;
110         Region damageRegion = Region::INVALID_REGION;
111         Region visibleRegion;
112 
113         // The OutputLayer pointed to by this field will be rearranged to draw
114         // behind the OutputLayer represented by this CompositionState and will
115         // be visible through it. Unowned - the OutputLayer's lifetime will
116         // outlast this.)
117         compositionengine::OutputLayer* peekThroughLayer = nullptr;
118         // True when this layer's blur has been cached with a previous layer, so that this layer
119         // does not need to request blurring.
120         // TODO(b/188816867): support blur regions too, which are less likely to be common if a
121         // device supports cross-window blurs. Blur region support should be doable, but we would
122         // need to make sure that layer caching works well with the blur region transform passed
123         // into RenderEngine
124         bool disableBackgroundBlur = false;
125     } overrideInfo;
126 
127     /*
128      * HWC state
129      */
130 
131     struct Hwc {
HwcOutputLayerCompositionState::Hwc132         explicit Hwc(std::shared_ptr<HWC2::Layer> hwcLayer) : hwcLayer(hwcLayer) {}
133 
134         // The HWC Layer backing this layer
135         std::shared_ptr<HWC2::Layer> hwcLayer;
136 
137         // The most recently set HWC composition type for this layer
138         aidl::android::hardware::graphics::composer3::Composition hwcCompositionType{
139                 aidl::android::hardware::graphics::composer3::Composition::INVALID};
140 
141         // The buffer cache for this layer. This is used to lower the
142         // cost of sending reused buffers to the HWC.
143         HwcBufferCache hwcBufferCache;
144 
145         // The previously-active buffer for this layer.
146         uint64_t activeBufferId;
147         uint32_t activeBufferSlot;
148 
149         // Set to true when overridden info has been sent to HW composer
150         bool stateOverridden = false;
151 
152         // True when this layer was skipped as part of SF-side layer caching.
153         bool layerSkipped = false;
154     };
155 
156     // The HWC state is optional, and is only set up if there is any potential
157     // HWC acceleration possible.
158     std::optional<Hwc> hwc;
159 
160     // Debugging
161     void dump(std::string& result) const;
162 
163     // Timestamp for when the layer is queued for client composition
164     nsecs_t clientCompositionTimestamp{0};
165 
166     static constexpr float kDefaultWhitePointNits = 200.f;
167     float whitePointNits = kDefaultWhitePointNits;
168     // Dimming ratio of the layer from [0, 1]
169     static constexpr float kDefaultDimmingRatio = 1.f;
170     float dimmingRatio = kDefaultDimmingRatio;
171 };
172 
173 } // namespace compositionengine::impl
174 } // namespace android
175