• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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_shared_fd.h"
24 
25 namespace OHOS {
26     namespace HDI {
27         namespace DISPLAY {
28             const uint32_t INVALIDE_LAYER_ID = 0xffffffff;
29             const uint32_t FENCE_TIMEOUT = 3000;
30             struct HdiLayerBuffer {
31             public:
32                 explicit HdiLayerBuffer(const BufferHandle &hdl);
33                 virtual ~HdiLayerBuffer();
34                 HdiLayerBuffer &operator=(const BufferHandle &right);
GetPhysicalAddrHdiLayerBuffer35                 uint64_t GetPhysicalAddr() const
36                 {
37                     return mPhyAddr;
38                 }
GetHeightHdiLayerBuffer39                 int32_t GetHeight() const
40                 {
41                     return mHeight;
42                 }
GetWightHdiLayerBuffer43                 int32_t GetWight() const
44                 {
45                     return mWidth;
46                 }
GetStrideHdiLayerBuffer47                 int32_t GetStride() const
48                 {
49                     return mStride;
50                 }
GetFormatHdiLayerBuffer51                 int32_t GetFormat() const
52                 {
53                     return mFormat;
54                 }
GetFbHdiLayerBuffer55                 int GetFb() const
56                 {
57                     return mFd;
58                 }
59                 BufferHandle mHandle;
60 
61             private:
62                 uint64_t mPhyAddr = 0;
63                 int32_t mHeight = 0;
64                 int32_t mWidth = 0;
65                 int32_t mStride = 0;
66                 int32_t mFormat = 0;
67                 int mFd = -1;
68             };
69 
70             class HdiLayer {
71             public:
HdiLayer(LayerType type)72                 explicit HdiLayer(LayerType type) : mType(type)
73                 {
74                 }
75                 int32_t Init();
GetId()76                 uint32_t GetId() const
77                 {
78                     return mId;
79                 }
GetZorder()80                 uint32_t GetZorder() const
81                 {
82                     return mZorder;
83                 }
GetLayerDisplayRect()84                 const IRect &GetLayerDisplayRect() const
85                 {
86                     return mDisplayRect;
87                 }
GetLayerCrop()88                 const IRect &GetLayerCrop() const
89                 {
90                     return mCrop;
91                 }
GetLayerPreMulti()92                 bool GetLayerPreMulti() const
93                 {
94                     return mPreMul;
95                 }
GetAlpha()96                 const LayerAlpha &GetAlpha() const
97                 {
98                     return mAlpha;
99                 }
GetType()100                 LayerType GetType() const
101                 {
102                     return mType;
103                 }
GetTransFormType()104                 TransformType GetTransFormType() const
105                 {
106                     return mTransformType;
107                 }
GetLayerBlenType()108                 BlendType GetLayerBlenType() const
109                 {
110                     return mBlendType;
111                 }
GetCompositionType()112                 CompositionType GetCompositionType() const
113                 {
114                     return mCompositionType;
115                 }
SetDeviceSelect(CompositionType type)116                 void SetDeviceSelect(CompositionType type)
117                 {
118                     DISPLAY_DEBUGLOG("%{public}d", type);
119                     mDeviceSelect = type;
120                 }
GetDeviceSelect()121                 CompositionType GetDeviceSelect() const
122                 {
123                     return mDeviceSelect;
124                 }
125 
GetAcquireFenceFd()126                 int GetAcquireFenceFd()
127                 {
128                     return mAcquireFence.GetFd();
129                 }
GetReleaseFenceFd()130                 int GetReleaseFenceFd()
131                 {
132                     return mReleaseFence.GetFd();
133                 }
SetReleaseFence(int fd)134                 void SetReleaseFence(int fd)
135                 {
136                     mReleaseFence = fd;
137                 };
138                 void ClearColor(uint32_t color);
139 
140                 void SetPixel(const BufferHandle &handle, int x, int y, uint32_t color);
141 
142                 void WaitAcquireFence();
143                 virtual int32_t SetLayerSize(IRect *rect);
144                 virtual int32_t SetLayerCrop(IRect *rect);
145                 virtual void SetLayerZorder(uint32_t zorder);
146                 virtual int32_t SetLayerPreMulti(bool preMul);
147                 virtual int32_t SetLayerAlpha(LayerAlpha *alpha);
148                 virtual int32_t SetTransformMode(TransformType type);
149                 virtual int32_t SetLayerDirtyRegion(IRect *region);
150                 virtual int32_t SetLayerVisibleRegion(uint32_t num, IRect *rect);
151                 virtual int32_t SetLayerBuffer(const BufferHandle *buffer, int32_t fence);
152                 virtual int32_t SetLayerCompositionType(CompositionType type);
153                 virtual int32_t SetLayerBlendType(BlendType type);
GetCurrentBuffer()154                 virtual HdiLayerBuffer *GetCurrentBuffer()
155                 {
156                     return mHdiBuffer.get();
157                 }
~HdiLayer()158                 virtual ~HdiLayer()
159                 {
160                 }
161 
162             private:
163                 static uint32_t GetIdleId();
164                 static uint32_t mIdleId;
165                 static std::unordered_set<uint32_t> mIdSets;
166 
167                 uint32_t mId = 0;
168                 HdiSharedFd mAcquireFence;
169                 HdiSharedFd mReleaseFence;
170                 LayerType mType;
171 
172                 IRect mDisplayRect;
173                 IRect mCrop;
174                 uint32_t mZorder = -1;
175                 bool mPreMul = false;
176                 LayerAlpha mAlpha;
177                 int32_t mFenceTimeOut = FENCE_TIMEOUT;
178                 TransformType mTransformType = ROTATE_BUTT;
179                 CompositionType mCompositionType = COMPOSITION_CLIENT;
180                 CompositionType mDeviceSelect = COMPOSITION_CLIENT;
181                 BlendType mBlendType;
182                 std::unique_ptr<HdiLayerBuffer> mHdiBuffer;
183             };
184 
185             struct SortLayersByZ {
operatorSortLayersByZ186                 bool operator()(const HdiLayer *lhs, const HdiLayer *rhs) const
187                 {
188                     if (lhs == nullptr || rhs == nullptr) {
189                         return (lhs == nullptr) && (rhs == nullptr);
190                     }
191                     return lhs->GetZorder() < rhs->GetZorder();
192                 }
193             };
194         } // namespace OHOS
195     }     // namespace HDI
196 } // namespace DISPLAY
197 
198 #endif // HDI_LAYER_H