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