• 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_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     int32_t Init();
GetId()74     uint32_t GetId() const
75     {
76         return mId;
77     }
GetZorder()78     uint32_t GetZorder() const
79     {
80         return mZorder;
81     }
GetLayerDisplayRect()82     const IRect &GetLayerDisplayRect() const
83     {
84         return mDisplayRect;
85     }
GetLayerCrop()86     const IRect &GetLayerCrop() const
87     {
88         return mCrop;
89     }
GetLayerPreMulti()90     bool GetLayerPreMulti() const
91     {
92         return mPreMul;
93     }
GetAlpha()94     const LayerAlpha &GetAlpha() const
95     {
96         return mAlpha;
97     }
GetType()98     LayerType GetType() const
99     {
100         return mType;
101     }
GetTransFormType()102     TransformType GetTransFormType() const
103     {
104         return mTransformType;
105     }
GetLayerBlenType()106     BlendType GetLayerBlenType() const
107     {
108         return mBlendType;
109     }
GetCompositionType()110     CompositionType GetCompositionType() const
111     {
112         return mCompositionType;
113     }
SetDeviceSelect(CompositionType type)114     void SetDeviceSelect(CompositionType type)
115     {
116         DISPLAY_DEBUGLOG("%{public}d", type);
117         mDeviceSelect = type;
118     }
GetDeviceSelect()119     CompositionType GetDeviceSelect() const
120     {
121         return mDeviceSelect;
122     }
123 
GetAcquireFenceFd()124     int GetAcquireFenceFd()
125     {
126         return mAcquireFence.GetFd();
127     }
GetReleaseFenceFd()128     int GetReleaseFenceFd()
129     {
130         return mReleaseFence.GetFd();
131     }
SetReleaseFence(int fd)132     void SetReleaseFence(int fd)
133     {
134         mReleaseFence = fd;
135     };
136     void ClearColor(uint32_t color);
137 
138     void SetPixel(const BufferHandle &handle, int x, int y, uint32_t color);
139 
140     void WaitAcquireFence();
141     virtual int32_t SetLayerSize(IRect *rect);
142     virtual int32_t SetLayerCrop(IRect *rect);
143     virtual void SetLayerZorder(uint32_t zorder);
144     virtual int32_t SetLayerPreMulti(bool preMul);
145     virtual int32_t SetLayerAlpha(LayerAlpha *alpha);
146     virtual int32_t SetTransformMode(TransformType type);
147     virtual int32_t SetLayerDirtyRegion(IRect *region);
148     virtual int32_t SetLayerVisibleRegion(uint32_t num, IRect *rect);
149     virtual int32_t SetLayerBuffer(const BufferHandle *buffer, int32_t fence);
150     virtual int32_t SetLayerCompositionType(CompositionType type);
151     virtual int32_t SetLayerBlendType(BlendType type);
GetCurrentBuffer()152     virtual HdiLayerBuffer *GetCurrentBuffer()
153     {
154         return mHdiBuffer.get();
155     }
~HdiLayer()156     virtual ~HdiLayer() {}
157 
158 private:
159     static uint32_t GetIdleId();
160     static uint32_t mIdleId;
161     static std::unordered_set<uint32_t> mIdSets;
162 
163     uint32_t mId = 0;
164     HdiFd mAcquireFence;
165     HdiFd mReleaseFence;
166     LayerType mType;
167 
168     IRect mDisplayRect;
169     IRect mCrop;
170     uint32_t mZorder = -1;
171     bool mPreMul = false;
172     LayerAlpha mAlpha;
173     int32_t mFenceTimeOut = FENCE_TIMEOUT;
174     TransformType mTransformType = ROTATE_BUTT;
175     CompositionType mCompositionType = COMPOSITION_CLIENT;
176     CompositionType mDeviceSelect = COMPOSITION_CLIENT;
177     BlendType mBlendType;
178     std::unique_ptr<HdiLayerBuffer> mHdiBuffer;
179 };
180 
181 struct SortLayersByZ {
operatorSortLayersByZ182     bool operator () (const HdiLayer *lhs, const HdiLayer *rhs) const
183     {
184         if (lhs == nullptr || rhs == nullptr) {
185             return (lhs == nullptr) && (rhs == nullptr);
186         }
187         return lhs->GetZorder() < rhs->GetZorder();
188     }
189 };
190 } // namespace OHOS
191 } // namespace HDI
192 } // namespace DISPLAY
193 
194 #endif // HDI_LAYER_H