1 /* 2 * Copyright (c) 2025 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 RS_HDR_MANAGER_H 17 #define RS_HDR_MANAGER_H 18 19 #include <condition_variable> 20 #include <unordered_map> 21 #include <set> 22 #include <vector> 23 24 #include "drawable/rs_surface_render_node_drawable.h" 25 #include "ffrt.h" 26 #include "ffrt_inner.h" 27 #include "pipeline/main_thread/rs_main_thread.h" 28 #include "pipeline/rs_processor.h" 29 #include "pipeline/rs_surface_render_node.h" 30 #include "transaction/rs_render_service_client.h" 31 32 constexpr int GRAPH_NUM = 4; 33 34 namespace OHOS::Rosen { 35 #define ROTATION_90 90 36 #define ROTATION_270 270 37 #define HDR_EPSILON 1e-8f 38 #define HPAE_TIMEOUT 32 39 40 class RSHdrManager { 41 public: 42 static RSHdrManager &Instance(); 43 void UpdateHdrNodes(RSSurfaceRenderNode &node, bool isCurrentFrameBufferConsumed); 44 void PostHdrSubTasks(); 45 bool GetCurFrameHeterogHandleCanBeUsed(); IsHeterogComputingHdrOn()46 bool IsHeterogComputingHdrOn() 47 { 48 return isHeterogComputingHdrOn_; 49 } 50 51 private: 52 RSHdrManager(); 53 ~RSHdrManager() = default; 54 RSHdrManager(const RSHdrManager &); 55 RSHdrManager(const RSHdrManager &&); 56 RSHdrManager &operator = (const RSHdrManager &); 57 RSHdrManager &operator = (const RSHdrManager &&); 58 void ReverseParentNode(std::shared_ptr<RSRenderNode> node); 59 bool EquRect(RectI a, RectI b); 60 RectI RectRound(RectI src); 61 62 void GetFixDstRectStatus(std::shared_ptr<DrawableV2::RSSurfaceRenderNodeDrawable> drawable, 63 bool isUifistR, RSSurfaceRenderParams *surfaceParams, RectI &boundSize, 64 bool &isFixDstRect); 65 int32_t BuildHDRTask(RSSurfaceRenderParams *surfaceParams, MdcRectT srcRect, uint32_t* taskId, void** taskPtr); 66 bool IsHDRSurfaceNodeSkipped(std::shared_ptr<DrawableV2::RSSurfaceRenderNodeDrawable> surfaceDrawable); 67 bool PrepareHapeTask(std::shared_ptr<DrawableV2::RSSurfaceRenderNodeDrawable> surfaceDrawable, 68 uint64_t curFrameId); 69 void FindParentLeashWindowNode(); 70 ScreenId GetScreenIDByDrawable(std::shared_ptr<DrawableV2::RSSurfaceRenderNodeDrawable> drawable); 71 72 std::shared_ptr<RSSurfaceRenderNode> windowSceneNode_; 73 std::unordered_map<NodeId, NodeId> ownedLeashWindowIdMap_; 74 std::shared_ptr<RSSurfaceRenderNode> appWindowNode_; 75 std::unordered_map<NodeId, NodeId> ownedAppWindowIdMap_; 76 std::unordered_map<NodeId, std::shared_ptr<RSSurfaceRenderNode>> pendingPostNodes_; 77 78 std::unordered_map<NodeId, RectI> nodeSrcRect_; 79 std::unordered_map<NodeId, bool> isCurrentFrameBufferConsumedMap_; 80 void* taskPtr_ = nullptr; 81 std::atomic<uint32_t> taskId_ = 0; 82 uint32_t buildHDRTaskStatus = 0; 83 int32_t queryTaskStatus = 0; 84 std::mutex HpaeMtx_; 85 std::condition_variable cond_; 86 std::atomic<bool> destroyedFlag_{true}; 87 bool isFixedDstBuffer_ = false; 88 RectI dst_ = {0, 0, 0, 0}; 89 sptr<SurfaceBuffer> dstBuffer_ = nullptr; 90 bool curFrameHeterogHandleCanBeUesed_ = false; 91 bool isHeterogComputingHdrOn_ = false; 92 93 void ProcessPendingNode(uint32_t nodeId, uint64_t curFrameId); 94 bool CheckWindowOwnership(uint32_t nodeId); 95 bool ValidateSurface(RSSurfaceRenderParams* surfaceParams); 96 bool PrepareAndSubmitHdrTask( 97 std::shared_ptr<DrawableV2::RSSurfaceRenderNodeDrawable> nodeDrawable, 98 RSSurfaceRenderParams* surfaceParams, uint32_t nodeId, uint64_t curFrameId); 99 }; 100 } 101 #endif // RS_HDR_MANAGER_H 102