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 #include <optional>
21 #include <string>
22 
23 #include <compositionengine/impl/HwcBufferCache.h>
24 #include <renderengine/Mesh.h>
25 #include <ui/FloatRect.h>
26 #include <ui/GraphicTypes.h>
27 #include <ui/Rect.h>
28 #include <ui/Region.h>
29 
30 // TODO(b/129481165): remove the #pragma below and fix conversion issues
31 #pragma clang diagnostic push
32 #pragma clang diagnostic ignored "-Wconversion"
33 
34 #include "DisplayHardware/ComposerHal.h"
35 
36 // TODO(b/129481165): remove the #pragma below and fix conversion issues
37 #pragma clang diagnostic pop // ignored "-Wconversion"
38 
39 namespace android {
40 
41 namespace HWC2 {
42 class Layer;
43 } // namespace HWC2
44 
45 class HWComposer;
46 
47 namespace compositionengine::impl {
48 
49 struct OutputLayerCompositionState {
50     // The portion of the layer that is not obscured by opaque layers on top
51     Region visibleRegion;
52 
53     // The portion of the layer that is not obscured and is also opaque
54     Region visibleNonTransparentRegion;
55 
56     // The portion of the layer that is obscured by opaque layers on top
57     Region coveredRegion;
58 
59     // The visibleRegion transformed to output space
60     Region outputSpaceVisibleRegion;
61 
62     // Region cast by the layer's shadow
63     Region shadowRegion;
64 
65     // If true, client composition will be used on this output
66     bool forceClientComposition{false};
67 
68     // If true, when doing client composition, the target may need to be cleared
69     bool clearClientTarget{false};
70 
71     // The display frame for this layer on this output
72     Rect displayFrame;
73 
74     // The source crop for this layer on this output
75     FloatRect sourceCrop;
76 
77     // The buffer transform to use for this layer o on this output.
78     Hwc2::Transform bufferTransform{static_cast<Hwc2::Transform>(0)};
79 
80     // The dataspace for this layer
81     ui::Dataspace dataspace{ui::Dataspace::UNKNOWN};
82 
83     // The Z order index of this layer on this output
84     uint32_t z{0};
85 
86     /*
87      * HWC state
88      */
89 
90     struct Hwc {
HwcOutputLayerCompositionState::Hwc91         explicit Hwc(std::shared_ptr<HWC2::Layer> hwcLayer) : hwcLayer(hwcLayer) {}
92 
93         // The HWC Layer backing this layer
94         std::shared_ptr<HWC2::Layer> hwcLayer;
95 
96         // The most recently set HWC composition type for this layer
97         Hwc2::IComposerClient::Composition hwcCompositionType{
98                 Hwc2::IComposerClient::Composition::INVALID};
99 
100         // The buffer cache for this layer. This is used to lower the
101         // cost of sending reused buffers to the HWC.
102         HwcBufferCache hwcBufferCache;
103     };
104 
105     // The HWC state is optional, and is only set up if there is any potential
106     // HWC acceleration possible.
107     std::optional<Hwc> hwc;
108 
109     // Debugging
110     void dump(std::string& result) const;
111 
112     // Timestamp for when the layer is queued for client composition
113     nsecs_t clientCompositionTimestamp;
114 };
115 
116 } // namespace compositionengine::impl
117 } // namespace android
118