1 /*
2  * Copyright 2022 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 #ifndef ANDROID_HWC_LAYER_H
18 #define ANDROID_HWC_LAYER_H
19 
20 #include <optional>
21 #include <vector>
22 
23 #include "Common.h"
24 #include "FencedBuffer.h"
25 
26 namespace aidl::android::hardware::graphics::composer3::impl {
27 
28 class Layer {
29    public:
30     explicit Layer();
31 
32     Layer(const Layer&) = delete;
33     Layer& operator=(const Layer&) = delete;
34 
35     Layer(Layer&&) = delete;
36     Layer& operator=(Layer&&) = delete;
37 
getId()38     int64_t getId() const { return mId; }
39 
40     HWC3::Error setCursorPosition(const common::Point& cursorPosition);
41     common::Point getCursorPosition() const;
42 
43     HWC3::Error setBuffer(buffer_handle_t buffer, const ndk::ScopedFileDescriptor& fence);
44     FencedBuffer& getBuffer();
45     buffer_handle_t waitAndGetBuffer();
46 
47     HWC3::Error setSurfaceDamage(const std::vector<std::optional<common::Rect>>& damage);
48 
49     HWC3::Error setBlendMode(common::BlendMode mode);
50     common::BlendMode getBlendMode() const;
51 
52     HWC3::Error setColor(Color color);
53     Color getColor() const;
54 
55     HWC3::Error setCompositionType(Composition composition);
56     Composition getCompositionType() const;
57 
58     HWC3::Error setDataspace(common::Dataspace dataspace);
59     common::Dataspace getDataspace() const;
60 
61     HWC3::Error setDisplayFrame(common::Rect frame);
62     common::Rect getDisplayFrame() const;
63 
64     HWC3::Error setPlaneAlpha(float alpha);
65     float getPlaneAlpha() const;
66 
67     HWC3::Error setSidebandStream(buffer_handle_t stream);
68 
69     HWC3::Error setSourceCrop(common::FRect crop);
70     common::FRect getSourceCrop() const;
71     common::Rect getSourceCropInt() const;
72 
73     HWC3::Error setTransform(common::Transform transform);
74     common::Transform getTransform() const;
75 
76     HWC3::Error setVisibleRegion(const std::vector<std::optional<common::Rect>>& visible);
77     std::size_t getNumVisibleRegions() const;
78 
79     HWC3::Error setZOrder(int32_t z);
80     int32_t getZOrder() const;
81 
82     HWC3::Error setPerFrameMetadata(
83         const std::vector<std::optional<PerFrameMetadata>>& perFrameMetadata);
84 
85     HWC3::Error setColorTransform(const std::vector<float>& colorTransform);
86     const std::optional<std::array<float, 16>>& getColorTransform() const;
87 
88     HWC3::Error setBrightness(float brightness);
89     float getBrightness() const;
90 
91     HWC3::Error setPerFrameMetadataBlobs(
92         const std::vector<std::optional<PerFrameMetadataBlob>>& perFrameMetadata);
93 
94     HWC3::Error setLuts(const Luts& luts);
95     bool hasLuts() const;
96 
97     // For log use only.
98     void logCompositionFallbackIfChanged(Composition to);
99 
100    private:
101     const int64_t mId;
102     common::Point mCursorPosition;
103     FencedBuffer mBuffer;
104     common::BlendMode mBlendMode = common::BlendMode::NONE;
105     Color mColor = {0, 0, 0, 0};
106     Composition mCompositionType = Composition::INVALID;
107     common::Dataspace mDataspace = common::Dataspace::UNKNOWN;
108     struct CompositionTypeFallback {
109         Composition from;
110         Composition to;
111     };
112     // For log use only.
113     std::optional<CompositionTypeFallback> mLastCompositionFallback = std::nullopt;
114     common::Rect mDisplayFrame = {0, 0, -1, -1};
115     float mPlaneAlpha = 0.0f;
116     common::FRect mSourceCrop = {0.0f, 0.0f, -1.0f, -1.0f};
117     common::Transform mTransform = common::Transform{0};
118     std::vector<common::Rect> mVisibleRegion;
119     int32_t mZOrder = 0;
120     std::optional<std::array<float, 16>> mColorTransform;
121     float mBrightness = 1.0f;
122     bool mHasLuts = false;
123 };
124 
125 }  // namespace aidl::android::hardware::graphics::composer3::impl
126 
127 #endif
128