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/Rect.h>
27 #include <ui/Region.h>
28 
29 #include "DisplayHardware/ComposerHal.h"
30 
31 namespace HWC2 {
32 class Layer;
33 } // namespace HWC2
34 
35 namespace android {
36 
37 class HWComposer;
38 
39 namespace compositionengine::impl {
40 
41 struct OutputLayerCompositionState {
42     // The region of this layer which is visible on this output
43     Region visibleRegion;
44 
45     // If true, client composition will be used on this output
46     bool forceClientComposition{false};
47 
48     // If true, when doing client composition, the target may need to be cleared
49     bool clearClientTarget{false};
50 
51     // The display frame for this layer on this output
52     Rect displayFrame;
53 
54     // The source crop for this layer on this output
55     FloatRect sourceCrop;
56 
57     // The buffer transform to use for this layer o on this output.
58     Hwc2::Transform bufferTransform{static_cast<Hwc2::Transform>(0)};
59 
60     // The Z order index of this layer on this output
61     uint32_t z;
62 
63     /*
64      * HWC state
65      */
66 
67     struct Hwc {
HwcOutputLayerCompositionState::Hwc68         explicit Hwc(std::shared_ptr<HWC2::Layer> hwcLayer) : hwcLayer(hwcLayer) {}
69 
70         // The HWC Layer backing this layer
71         std::shared_ptr<HWC2::Layer> hwcLayer;
72 
73         // The HWC composition type for this layer
74         Hwc2::IComposerClient::Composition hwcCompositionType{
75                 Hwc2::IComposerClient::Composition::INVALID};
76 
77         // The buffer cache for this layer. This is used to lower the
78         // cost of sending reused buffers to the HWC.
79         HwcBufferCache hwcBufferCache;
80     };
81 
82     // The HWC state is optional, and is only set up if there is any potential
83     // HWC acceleration possible.
84     std::optional<Hwc> hwc;
85 
86     // Debugging
87     void dump(std::string& result) const;
88 };
89 
90 } // namespace compositionengine::impl
91 } // namespace android
92