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_OPINC_DRAW_CACHE_H 17 #define RS_OPINC_DRAW_CACHE_H 18 19 #include "common/rs_common_def.h" 20 #include "drawable/rs_render_node_drawable_adapter.h" 21 22 namespace OHOS::Rosen { 23 namespace DrawableV2 { 24 class RSOpincDrawCache { 25 public: 26 RSOpincDrawCache() = default; 27 ~RSOpincDrawCache() = default; 28 29 static bool IsAutoCacheEnable(); 30 SetScreenRectInfo(RectI info)31 static void SetScreenRectInfo(RectI info) 32 { 33 screenRectInfo_ = info; 34 } 35 GetNodeCacheType()36 static NodeStrategyType& GetNodeCacheType() 37 { 38 return nodeCacheType_; 39 } 40 SetNodeCacheType(NodeStrategyType type)41 static void SetNodeCacheType(NodeStrategyType type) 42 { 43 nodeCacheType_ = type; 44 } 45 46 // opinc switch 47 bool IsAutoCacheDebugEnable(); 48 int32_t GetOpincCacheMaxWidth() const; 49 int32_t GetOpincCacheMaxHeight() const; 50 51 void OpincCalculateBefore(Drawing::Canvas& canvas, 52 const RSRenderParams& params, bool& isOpincDropNodeExt); 53 void OpincCalculateAfter(Drawing::Canvas& canvas, bool& isOpincDropNodeExt); 54 void BeforeDrawCache(Drawing::Canvas& canvas, RSRenderParams& params, bool& isOpincDropNodeExt); 55 void AfterDrawCache(Drawing::Canvas& canvas, RSRenderParams& params, bool& isOpincDropNodeExt, 56 int& opincRootTotalCount); 57 58 bool DrawAutoCache(RSPaintFilterCanvas& canvas, Drawing::Image& image, 59 const Drawing::SamplingOptions& samplingOption, Drawing::SrcRectConstraint constraint); 60 void DrawAutoCacheDfx(RSPaintFilterCanvas& canvas, 61 std::vector<std::pair<RectI, std::string>>& autoCacheRenderNodeInfos); 62 void DrawOpincDisabledDfx(Drawing::Canvas& canvas, RSRenderParams& params); 63 void DrawableCacheStateReset(RSRenderParams& params); 64 bool PreDrawableCacheState(RSRenderParams& params, bool& isOpincDropNodeExt); 65 void OpincCanvasUnionTranslate(RSPaintFilterCanvas& canvas); 66 void ResumeOpincCanvasTranslate(RSPaintFilterCanvas& canvas); 67 68 bool IsOpListDrawAreaEnable(); 69 70 bool IsTranslate(Drawing::Matrix& mat); 71 72 // opinc root state IsOpincRootNode()73 bool IsOpincRootNode() 74 { 75 return isOpincRootNode_; 76 } 77 GetOpListUnionArea()78 const Drawing::Rect& GetOpListUnionArea() 79 { 80 return opListDrawAreas_.GetOpInfo().unionRect; 81 } 82 GetOpListHandle()83 const Drawing::OpListHandle& GetOpListHandle() 84 { 85 return opListDrawAreas_; 86 } 87 IsComputeDrawAreaSucc()88 bool IsComputeDrawAreaSucc() 89 { 90 return isDrawAreaEnable_ == DrawAreaEnableState::DRAW_AREA_ENABLE; 91 } 92 GetDrawAreaEnableState()93 DrawAreaEnableState GetDrawAreaEnableState() 94 { 95 return isDrawAreaEnable_; 96 } 97 OpincGetCachedMark()98 bool OpincGetCachedMark() const 99 { 100 return isOpincMarkCached_; 101 } 102 GetRecordState()103 NodeRecordState GetRecordState() const 104 { 105 return recordState_; 106 } 107 GetRootNodeStrategyType()108 NodeStrategyType GetRootNodeStrategyType() const 109 { 110 return rootNodeStragyType_; 111 } 112 IsOpCanCache()113 bool IsOpCanCache() const 114 { 115 return opCanCache_; 116 } 117 protected: 118 thread_local static inline NodeStrategyType nodeCacheType_ = NodeStrategyType::CACHE_NONE; 119 static inline RectI screenRectInfo_ = {0, 0, 0, 0}; 120 private: 121 // opinc cache state 122 void NodeCacheStateDisable(); 123 bool BeforeDrawCacheProcessChildNode(RSRenderParams& params); 124 void BeforeDrawCacheFindRootNode(Drawing::Canvas& canvas, const RSRenderParams& params, bool& isOpincDropNodeExt); 125 bool IsOpincNodeInScreenRect(RSRenderParams& params); 126 127 NodeRecordState recordState_ = NodeRecordState::RECORD_NONE; 128 NodeStrategyType rootNodeStragyType_ = NodeStrategyType::CACHE_NONE; 129 NodeStrategyType temNodeStragyType_ = NodeStrategyType::CACHE_NONE; 130 DrawAreaEnableState isDrawAreaEnable_ = DrawAreaEnableState::DRAW_AREA_INIT; 131 Drawing::OpListHandle opListDrawAreas_; 132 bool opCanCache_ = false; 133 int64_t reuseCount_ = 0; 134 bool isOpincRootNode_ = false; 135 bool isOpincDropNodeExtTemp_ = true; 136 bool isOpincCaculateStart_ = false; 137 bool isOpincMarkCached_ = false; 138 }; // RSOpincDrawCache 139 } 140 } 141 #endif // RS_OPINC_DRAW_CACHE_H