• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef HDI_LAYER_H
17 #define HDI_LAYER_H
18 #include <unordered_set>
19 #include <memory>
20 #include "buffer_handle.h"
21 #include "display_common.h"
22 #include "hdi_device_common.h"
23 #include "hdi_fd.h"
24 
25 namespace OHOS {
26 namespace HDI {
27 namespace DISPLAY {
28 const uint32_t INVALIDE_LAYER_ID = 0xffffffff;
29 struct HdiLayerBuffer {
30 public:
31     explicit HdiLayerBuffer(const BufferHandle &hdl);
32     virtual ~HdiLayerBuffer();
33     HdiLayerBuffer &operator = (const BufferHandle &right);
GetPhysicalAddrHdiLayerBuffer34     uint64_t GetPhysicalAddr() const
35     {
36         return mPhyAddr;
37     }
GetHeightHdiLayerBuffer38     int32_t GetHeight() const
39     {
40         return mHeight;
41     }
GetWightHdiLayerBuffer42     int32_t GetWight() const
43     {
44         return mWidth;
45     }
GetStrideHdiLayerBuffer46     int32_t GetStride() const
47     {
48         return mStride;
49     }
GetFormatHdiLayerBuffer50     int32_t GetFormat() const
51     {
52         return mFormat;
53     }
GetFbHdiLayerBuffer54     int GetFb() const
55     {
56         return mFd;
57     }
58     BufferHandle mHandle;
59 
60 private:
61     uint64_t mPhyAddr = 0;
62     int32_t mHeight = 0;
63     int32_t mWidth = 0;
64     int32_t mStride = 0;
65     int32_t mFormat = 0;
66     int mFd = -1;
67 };
68 
69 class HdiLayer {
70 public:
HdiLayer(LayerType type)71     explicit HdiLayer(LayerType type) : mType(type) {}
72     int32_t Init();
GetId()73     uint32_t GetId() const
74     {
75         return mId;
76     }
GetZorder()77     uint32_t GetZorder() const
78     {
79         return mZorder;
80     }
GetLayerDisplayRect()81     const IRect &GetLayerDisplayRect() const
82     {
83         return mDisplayRect;
84     }
GetLayerCrop()85     const IRect &GetLayerCrop() const
86     {
87         return mCrop;
88     }
GetLayerPreMulti()89     bool GetLayerPreMulti() const
90     {
91         return mPreMul;
92     }
GetAlpha()93     const LayerAlpha &GetAlpha() const
94     {
95         return mAlpha;
96     }
GetType()97     LayerType GetType() const
98     {
99         return mType;
100     }
GetTransFormType()101     TransformType GetTransFormType() const
102     {
103         return mTransformType;
104     }
GetLayerBlenType()105     BlendType GetLayerBlenType() const
106     {
107         return mBlendType;
108     }
GetCompositionType()109     CompositionType GetCompositionType() const
110     {
111         return mCompositionType;
112     }
SetDeviceSelect(CompositionType type)113     void SetDeviceSelect(CompositionType type)
114     {
115         DISPLAY_LOGD("%{public}d", type);
116         mDeviceSelect = type;
117     }
GetDeviceSelect()118     CompositionType GetDeviceSelect() const
119     {
120         return mDeviceSelect;
121     }
122 
GetAcquireFenceFd()123     int GetAcquireFenceFd()
124     {
125         return mAcquireFence.GetFd();
126     }
127 
GetReleaseFenceFd()128     int GetReleaseFenceFd()
129     {
130         return mReleaseFence.GetFd();
131     }
132 
IsVisible()133     bool IsVisible()
134     {
135         return mVisible;
136     }
137 
SetReleaseFence(int fd)138     void SetReleaseFence(int fd)
139     {
140         mReleaseFence = fd;
141     };
142     void ClearColor(uint32_t color);
143 
144     void SetPixel(const BufferHandle &handle, int x, int y, uint32_t color);
145 
146     virtual int32_t SetLayerSize(IRect *rect);
147     virtual int32_t SetLayerCrop(IRect *rect);
148     virtual void SetLayerZorder(uint32_t zorder);
149     virtual int32_t SetLayerPreMulti(bool preMul);
150     virtual int32_t SetLayerAlpha(LayerAlpha *alpha);
151     virtual int32_t SetTransformMode(TransformType type);
152     virtual int32_t SetLayerDirtyRegion(IRect *region);
153     virtual int32_t SetLayerVisibleRegion(uint32_t num, IRect *rect);
154     virtual int32_t SetLayerBuffer(const BufferHandle *buffer, int32_t fence);
155     virtual int32_t SetLayerCompositionType(CompositionType type);
156     virtual int32_t SetLayerBlendType(BlendType type);
157     virtual int32_t SetLayerVisible(bool visible);
GetCurrentBuffer()158     virtual HdiLayerBuffer *GetCurrentBuffer()
159     {
160         return mHdiBuffer.get();
161     }
~HdiLayer()162     virtual ~HdiLayer() {}
163 
164 private:
165     static uint32_t GetIdleId();
166     static uint32_t mIdleId;
167     static std::unordered_set<uint32_t> mIdSets;
168     bool mVisible = true;
169     uint32_t mId = 0;
170     HdiFd mAcquireFence;
171     HdiFd mReleaseFence;
172     LayerType mType;
173 
174     IRect mDisplayRect;
175     IRect mCrop;
176     uint32_t mZorder = -1;
177     bool mPreMul = false;
178     LayerAlpha mAlpha;
179     TransformType mTransformType;
180     CompositionType mCompositionType = COMPOSITION_CLIENT;
181     CompositionType mDeviceSelect = COMPOSITION_CLIENT;
182     BlendType mBlendType;
183     std::unique_ptr<HdiLayerBuffer> mHdiBuffer;
184 };
185 
186 struct SortLayersByZ {
operatorSortLayersByZ187     bool operator () (const HdiLayer *lhs, const HdiLayer *rhs) const
188     {
189         if (lhs == nullptr || rhs == nullptr) {
190             return (lhs == nullptr) && (rhs == nullptr);
191         }
192         return lhs->GetZorder() < rhs->GetZorder();
193     }
194 };
195 } // namespace OHOS
196 } // namespace HDI
197 } // namespace DISPLAY
198 
199 #endif // HDI_LAYER_H
200