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