• 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_BACKEND_HDI_LAYER_INFO_H
17 #define HDI_BACKEND_HDI_LAYER_INFO_H
18 
19 #include <string>
20 #include "iconsumer_surface.h"
21 #include <surface.h>
22 #include <sync_fence.h>
23 #include "hdi_log.h"
24 
25 namespace OHOS {
26 namespace Rosen {
27 static const std::map<GraphicTransformType, std::string> TransformTypeStrs = {
28     {GRAPHIC_ROTATE_NONE,                    "0 <no rotation>"},
29     {GRAPHIC_ROTATE_90,                      "1 <rotation by 90 degrees>"},
30     {GRAPHIC_ROTATE_180,                     "2 <rotation by 180 degrees>"},
31     {GRAPHIC_ROTATE_270,                     "3 <rotation by 270 degrees>"},
32     {GRAPHIC_FLIP_H,                         "4 <flip horizontally>"},
33     {GRAPHIC_FLIP_V,                         "5 <flip vertically>"},
34     {GRAPHIC_FLIP_H_ROT90,                   "6 <flip horizontally and rotate 90 degrees>"},
35     {GRAPHIC_FLIP_V_ROT90,                   "7 <flip vertically and rotate 90 degrees>"},
36     {GRAPHIC_FLIP_H_ROT180,                  "8 <flip horizontally and rotate 180 degrees>"},
37     {GRAPHIC_FLIP_V_ROT180,                  "9 <flip vertically and rotate 180 degrees>"},
38     {GRAPHIC_FLIP_H_ROT270,                  "10 <flip horizontally and rotate 270 degrees>"},
39     {GRAPHIC_FLIP_V_ROT270,                  "11 <flip vertically and rotate 270 degrees>"},
40     {GRAPHIC_ROTATE_BUTT,                    "12 <uninitialized>"},
41 };
42 
43 static const std::map<GraphicCompositionType, std::string> CompositionTypeStrs = {
44     {GRAPHIC_COMPOSITION_CLIENT,             "0 <client composistion>"},
45     {GRAPHIC_COMPOSITION_DEVICE,             "1 <device composistion>"},
46     {GRAPHIC_COMPOSITION_CURSOR,             "2 <cursor composistion>"},
47     {GRAPHIC_COMPOSITION_VIDEO,              "3 <video composistion>"},
48     {GRAPHIC_COMPOSITION_DEVICE_CLEAR,       "4 <device clear composistion>"},
49     {GRAPHIC_COMPOSITION_CLIENT_CLEAR,       "5 <client clear composistion>"},
50     {GRAPHIC_COMPOSITION_TUNNEL,             "6 <tunnel composistion>"},
51     {GRAPHIC_COMPOSITION_BUTT,               "7 <uninitialized>"},
52 };
53 
54 static const std::map<GraphicBlendType, std::string> BlendTypeStrs = {
55     {GRAPHIC_BLEND_NONE,                     "0 <No blending>"},
56     {GRAPHIC_BLEND_CLEAR,                    "1 <CLEAR blending>"},
57     {GRAPHIC_BLEND_SRC,                      "2 <SRC blending>"},
58     {GRAPHIC_BLEND_SRCOVER,                  "3 <SRC_OVER blending>"},
59     {GRAPHIC_BLEND_DSTOVER,                  "4 <DST_OVER blending>"},
60     {GRAPHIC_BLEND_SRCIN,                    "5 <SRC_IN blending>"},
61     {GRAPHIC_BLEND_DSTIN,                    "6 <DST_IN blending>"},
62     {GRAPHIC_BLEND_SRCOUT,                   "7 <SRC_OUT blending>"},
63     {GRAPHIC_BLEND_DSTOUT,                   "8 <DST_OUT blending>"},
64     {GRAPHIC_BLEND_SRCATOP,                  "9 <SRC_ATOP blending>"},
65     {GRAPHIC_BLEND_DSTATOP,                  "10 <DST_ATOP blending>"},
66     {GRAPHIC_BLEND_ADD,                      "11 <ADD blending>"},
67     {GRAPHIC_BLEND_XOR,                      "12 <XOR blending>"},
68     {GRAPHIC_BLEND_DST,                      "13 <DST blending>"},
69     {GRAPHIC_BLEND_AKS,                      "14 <AKS blending>"},
70     {GRAPHIC_BLEND_AKD,                      "15 <AKD blending>"},
71     {GRAPHIC_BLEND_BUTT,                     "16 <Uninitialized>"},
72 };
73 
74 class HdiLayerInfo {
75 public:
76     HdiLayerInfo() = default;
77     virtual ~HdiLayerInfo() = default;
78 
79     enum class LayerMask {
80         LAYER_MASK_NORMAL = 0,
81         LAYER_MASK_HBM_SYNC = 1,   // enable fingerprint
82     };
83 
84     /* rs create and set/get layer info begin */
CreateHdiLayerInfo()85     static std::shared_ptr<HdiLayerInfo> CreateHdiLayerInfo()
86     {
87         return std::make_shared<HdiLayerInfo>();
88     }
89 
SetSurface(const sptr<IConsumerSurface> & surface)90     void SetSurface(const sptr<IConsumerSurface> &surface)
91     {
92         cSurface_ = surface;
93     }
94 
SetBuffer(const sptr<SurfaceBuffer> & sbuffer,const sptr<SyncFence> & acquireFence)95     void SetBuffer(const sptr<SurfaceBuffer> &sbuffer, const sptr<SyncFence> &acquireFence)
96     {
97         sbuffer_ = sbuffer;
98         acquireFence_ = acquireFence;
99     }
100 
SetPreBuffer(const sptr<SurfaceBuffer> & buffer)101     void SetPreBuffer(const sptr<SurfaceBuffer> &buffer)
102     {
103         pbuffer_ = buffer;
104     }
105 
SetZorder(int32_t zOrder)106     void SetZorder(int32_t zOrder)
107     {
108         zOrder_ = static_cast<uint32_t>(zOrder);
109     }
110 
SetAlpha(const GraphicLayerAlpha & alpha)111     void SetAlpha(const GraphicLayerAlpha &alpha)
112     {
113         layerAlpha_ = alpha;
114     }
115 
SetTransform(GraphicTransformType type)116     void SetTransform(GraphicTransformType type)
117     {
118         transformType_ = type;
119     }
120 
SetCompositionType(GraphicCompositionType type)121     void SetCompositionType(GraphicCompositionType type)
122     {
123         compositionType_ = type;
124     }
125 
SetVisibleRegions(const std::vector<GraphicIRect> & visibleRegions)126     void SetVisibleRegions(const std::vector<GraphicIRect> &visibleRegions)
127     {
128         visibleRegions_ = visibleRegions;
129     }
130 
SetDirtyRegions(const std::vector<GraphicIRect> & dirtyRegions)131     void SetDirtyRegions(const std::vector<GraphicIRect> &dirtyRegions)
132     {
133         dirtyRegions_ = dirtyRegions;
134     }
135 
SetBlendType(GraphicBlendType type)136     void SetBlendType(GraphicBlendType type)
137     {
138         blendType_ = type;
139     }
140 
SetCropRect(const GraphicIRect & crop)141     void SetCropRect(const GraphicIRect &crop)
142     {
143         cropRect_ = crop;
144     }
145 
SetPreMulti(bool preMulti)146     void SetPreMulti(bool preMulti)
147     {
148         preMulti_ = preMulti;
149     }
150 
SetLayerSize(const GraphicIRect & layerRect)151     void SetLayerSize(const GraphicIRect &layerRect)
152     {
153         layerRect_ = layerRect;
154     }
155 
SetBoundSize(const GraphicIRect & boundRect)156     void SetBoundSize(const GraphicIRect &boundRect)
157     {
158         boundRect_ = boundRect;
159     }
160 
SetLayerAdditionalInfo(void * info)161     void SetLayerAdditionalInfo(void *info)
162     {
163         additionalInfo_ = info;
164     }
165 
GetLayerAdditionalInfo()166     void* GetLayerAdditionalInfo()
167     {
168         return additionalInfo_;
169     }
170 
SetColorTransform(const std::vector<float> & matrix)171     void SetColorTransform(const std::vector<float> &matrix)
172     {
173         colorTransformMatrix_ = matrix;
174     }
175 
SetColorDataSpace(GraphicColorDataSpace colorSpace)176     void SetColorDataSpace(GraphicColorDataSpace colorSpace)
177     {
178         colorSpace_ = colorSpace;
179     }
180 
SetMetaData(const std::vector<GraphicHDRMetaData> & metaData)181     void SetMetaData(const std::vector<GraphicHDRMetaData> &metaData)
182     {
183         metaData_ = metaData;
184     }
185 
SetMetaDataSet(const GraphicHDRMetaDataSet & metaDataSet)186     void SetMetaDataSet(const GraphicHDRMetaDataSet &metaDataSet)
187     {
188         metaDataSet_ = metaDataSet;
189     }
190 
SetMatrix(GraphicMatrix matrix)191     void SetMatrix(GraphicMatrix matrix)
192     {
193         matrix_ = matrix;
194     }
195 
SetGravity(int32_t gravity)196     void SetGravity(int32_t gravity)
197     {
198         gravity_ = gravity;
199     }
200 
SetTunnelHandleChange(bool change)201     void SetTunnelHandleChange(bool change)
202     {
203         tunnelHandleChange_ = change;
204     }
205 
SetTunnelHandle(const sptr<SurfaceTunnelHandle> & handle)206     void SetTunnelHandle(const sptr<SurfaceTunnelHandle> &handle)
207     {
208         tunnelHandle_ = handle;
209     }
210 
IsSupportedPresentTimestamp()211     bool IsSupportedPresentTimestamp() const
212     {
213         return IsSupportedPresentTimestamp_;
214     }
215 
GetPresentTimestamp()216     const GraphicPresentTimestamp &GetPresentTimestamp()
217     {
218         return presentTimestamp_;
219     }
220 
221     /* rs create and set/get layer info end */
222 
223     /* hdiLayer get layer info begin */
GetSurface()224     sptr<IConsumerSurface> GetSurface() const
225     {
226         return cSurface_;
227     }
228 
GetBuffer()229     sptr<SurfaceBuffer> GetBuffer() const
230     {
231         return sbuffer_;
232     }
233 
GetPreBuffer()234     sptr<SurfaceBuffer> GetPreBuffer() const
235     {
236         return pbuffer_;
237     }
238 
GetZorder()239     uint32_t GetZorder() const
240     {
241         return zOrder_;
242     }
243 
GetAcquireFence()244     sptr<SyncFence> GetAcquireFence() const
245     {
246         return acquireFence_;
247     }
248 
GetAlpha()249     const GraphicLayerAlpha &GetAlpha()
250     {
251         return layerAlpha_;
252     }
253 
GetTransformType()254     GraphicTransformType GetTransformType() const
255     {
256         return transformType_;
257     }
258 
GetCompositionType()259     GraphicCompositionType GetCompositionType() const
260     {
261         return compositionType_;
262     }
263 
GetVisibleRegions()264     const std::vector<GraphicIRect> &GetVisibleRegions()
265     {
266         return visibleRegions_;
267     }
268 
GetDirtyRegions()269     const std::vector<GraphicIRect> &GetDirtyRegions()
270     {
271         return dirtyRegions_;
272     }
273 
GetBlendType()274     GraphicBlendType GetBlendType() const
275     {
276         return blendType_;
277     }
278 
GetCropRect()279     const GraphicIRect &GetCropRect()
280     {
281         return cropRect_;
282     }
283 
GetLayerSize()284     const GraphicIRect &GetLayerSize()
285     {
286         return layerRect_;
287     }
288 
GetBoundSize()289     GraphicIRect GetBoundSize() const
290     {
291         return boundRect_;
292     }
293 
GetMatrix()294     GraphicMatrix GetMatrix() const
295     {
296         return matrix_;
297     }
298 
GetGravity()299     int32_t GetGravity() const
300     {
301         return gravity_;
302     }
303 
IsPreMulti()304     bool IsPreMulti() const
305     {
306         return preMulti_;
307     }
308 
GetColorTransform()309     const std::vector<float> &GetColorTransform()
310     {
311         return colorTransformMatrix_;
312     }
313 
GetColorDataSpace()314     GraphicColorDataSpace GetColorDataSpace() const
315     {
316         return colorSpace_;
317     }
318 
GetMetaData()319     std::vector<GraphicHDRMetaData> &GetMetaData()
320     {
321         return metaData_;
322     }
323 
GetMetaDataSet()324     GraphicHDRMetaDataSet &GetMetaDataSet()
325     {
326         return metaDataSet_;
327     }
328 
GetTunnelHandleChange()329     bool GetTunnelHandleChange() const
330     {
331         return tunnelHandleChange_;
332     }
333 
GetTunnelHandle()334     sptr<SurfaceTunnelHandle> GetTunnelHandle() const
335     {
336         return tunnelHandle_;
337     }
338 
SetIsSupportedPresentTimestamp(bool isSupported)339     void SetIsSupportedPresentTimestamp(bool isSupported)
340     {
341         IsSupportedPresentTimestamp_ = isSupported;
342     }
343 
SetPresentTimestamp(const GraphicPresentTimestamp & timestamp)344     void SetPresentTimestamp(const GraphicPresentTimestamp &timestamp)
345     {
346         presentTimestamp_ = timestamp;
347     }
348 
CopyLayerInfo(const std::shared_ptr<HdiLayerInfo> & layerInfo)349     void CopyLayerInfo(const std::shared_ptr<HdiLayerInfo> &layerInfo)
350     {
351         zOrder_ = layerInfo->GetZorder();
352         layerRect_ = layerInfo->GetLayerSize();
353         boundRect_ = layerInfo->GetBoundSize();
354         visibleRegions_ = layerInfo->GetVisibleRegions();
355         dirtyRegions_ = layerInfo->GetDirtyRegions();
356         cropRect_ = layerInfo->GetCropRect();
357         matrix_ = layerInfo->GetMatrix();
358         gravity_ = layerInfo->GetGravity();
359         layerAlpha_ = layerInfo->GetAlpha();
360         transformType_ = layerInfo->GetTransformType();
361         compositionType_ = layerInfo->GetCompositionType();
362         blendType_ = layerInfo->GetBlendType();
363         colorTransformMatrix_ = layerInfo->GetColorTransform();
364         colorSpace_ = layerInfo->GetColorDataSpace();
365         metaData_ = layerInfo->GetMetaData();
366         metaDataSet_ = layerInfo->GetMetaDataSet();
367         tunnelHandle_ = layerInfo->GetTunnelHandle();
368         tunnelHandleChange_ = layerInfo->GetTunnelHandleChange();
369         sbuffer_ = layerInfo->GetBuffer();
370         pbuffer_= layerInfo->GetPreBuffer();
371         acquireFence_ = layerInfo->GetAcquireFence();
372         preMulti_ = layerInfo->IsPreMulti();
373     }
374 
Dump(std::string & result)375     void Dump(std::string &result) const
376     {
377         if (TransformTypeStrs.find(transformType_) != TransformTypeStrs.end() &&
378             CompositionTypeStrs.find(compositionType_) != CompositionTypeStrs.end() &&
379             BlendTypeStrs.find(blendType_) != BlendTypeStrs.end()) {
380             result += " zOrder = " + std::to_string(zOrder_) +
381                 ", visibleNum = " + std::to_string(visibleRegions_.size()) +
382                 ", transformType = " + TransformTypeStrs.at(transformType_) +
383                 ", compositionType = " + CompositionTypeStrs.at(compositionType_) +
384                 ", blendType = " + BlendTypeStrs.at(blendType_) +
385                 ", layerAlpha = [enGlobalAlpha(" + std::to_string(layerAlpha_.enGlobalAlpha) + "), enPixelAlpha(" +
386                 std::to_string(layerAlpha_.enPixelAlpha) + "), alpha0(" +
387                 std::to_string(layerAlpha_.alpha0) + "), alpha1(" +
388                 std::to_string(layerAlpha_.alpha1) + "), gAlpha(" +
389                 std::to_string(layerAlpha_.gAlpha) + ")].\n";
390         }
391         result += " layerRect = [" + std::to_string(layerRect_.x) + ", " +
392             std::to_string(layerRect_.y) + ", " +
393             std::to_string(layerRect_.w) + ", " +
394             std::to_string(layerRect_.h) + "], ";
395         result += "cropRect = [" + std::to_string(cropRect_.x) + ", " +
396             std::to_string(cropRect_.y) + ", " +
397             std::to_string(cropRect_.w) + ", " +
398             std::to_string(cropRect_.h) + "],";
399         for (decltype(visibleRegions_.size()) i = 0; i < visibleRegions_.size(); i++) {
400             result += "visibleRegions[" + std::to_string(i) + "] = [" +
401                 std::to_string(visibleRegions_[i].x) + ", " +
402                 std::to_string(visibleRegions_[i].y) + ", " +
403                 std::to_string(visibleRegions_[i].w) + ", " +
404                 std::to_string(visibleRegions_[i].h) + "], ";
405         }
406         for (decltype(dirtyRegions_.size()) i = 0; i < dirtyRegions_.size(); i++) {
407             result += "dirtyRegions[" + std::to_string(i) + "] = [" +
408                 std::to_string(dirtyRegions_[i].x) + ", " +
409                 std::to_string(dirtyRegions_[i].y) + ", " +
410                 std::to_string(dirtyRegions_[i].w) + ", " +
411                 std::to_string(dirtyRegions_[i].h) + "], ";
412         }
413         if (cSurface_ != nullptr) {
414             cSurface_->Dump(result);
415         }
416     }
417 
SetLayerMaskInfo(LayerMask mask)418     RosenError SetLayerMaskInfo(LayerMask mask)
419     {
420         switch (mask) {
421             case LayerMask::LAYER_MASK_NORMAL:
422             case LayerMask::LAYER_MASK_HBM_SYNC:
423                 break;
424             default:
425                 HLOGE("Invalid argument [mask:%{public}d]", static_cast<int32_t>(mask));
426                 return ROSEN_ERROR_INVALID_ARGUMENTS;
427         }
428 
429         layerMask_ = mask;
430         return ROSEN_ERROR_OK;
431     }
432 
GetLayerMaskInfo()433     LayerMask GetLayerMaskInfo()
434     {
435         return layerMask_;
436     }
437     /* hdiLayer get layer info end */
438 
439 private:
440     uint32_t zOrder_ = 0;
441     GraphicIRect layerRect_;
442     GraphicIRect boundRect_; // node's bound width and height related to this layer, used for uni render redraw
443     std::vector<GraphicIRect> visibleRegions_;
444     std::vector<GraphicIRect> dirtyRegions_;
445     GraphicIRect cropRect_;
446     GraphicMatrix matrix_; // matrix used for uni render redraw
447     int32_t gravity_; // used for uni render redraw
448     GraphicLayerAlpha layerAlpha_;
449     GraphicTransformType transformType_ = GraphicTransformType::GRAPHIC_ROTATE_BUTT;
450     GraphicCompositionType compositionType_;
451     GraphicBlendType blendType_;
452     std::vector<float> colorTransformMatrix_;
453     GraphicColorDataSpace colorSpace_ = GraphicColorDataSpace::GRAPHIC_COLOR_DATA_SPACE_UNKNOWN;
454     std::vector<GraphicHDRMetaData> metaData_;
455     GraphicHDRMetaDataSet metaDataSet_;
456     sptr<SurfaceTunnelHandle> tunnelHandle_ = nullptr;
457     bool tunnelHandleChange_ = false;
458     bool IsSupportedPresentTimestamp_ = false;
459     GraphicPresentTimestamp presentTimestamp_ = {GRAPHIC_DISPLAY_PTS_UNSUPPORTED, 0};
460 
461     void *additionalInfo_ = nullptr;
462     sptr<IConsumerSurface> cSurface_ = nullptr;
463     sptr<SyncFence> acquireFence_ = SyncFence::INVALID_FENCE;
464     sptr<SurfaceBuffer> sbuffer_ = nullptr;
465     sptr<SurfaceBuffer> pbuffer_ = nullptr;
466     bool preMulti_ = false;
467     LayerMask layerMask_ = LayerMask::LAYER_MASK_NORMAL;
468 };
469 } // namespace Rosen
470 } // namespace OHOS
471 
472 #endif // HDI_BACKEND_HDI_LAYER_INFO_H