1 /* 2 * Copyright (c) 2021-2023 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 #ifndef RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_DIRTY_REGION_MANAGER_H 16 #define RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_DIRTY_REGION_MANAGER_H 17 18 #include <map> 19 #include <vector> 20 21 #include "common/rs_macros.h" 22 #include "common/rs_rect.h" 23 #include "platform/common/rs_system_properties.h" 24 25 namespace OHOS { 26 namespace Rosen { 27 enum DebugRegionType { 28 CURRENT_SUB, 29 CURRENT_WHOLE, 30 MULTI_HISTORY, 31 EGL_DAMAGE, 32 TYPE_MAX 33 }; 34 35 class RSB_EXPORT RSDirtyRegionManager final { 36 public: 37 static constexpr int32_t ALIGNED_BITS = 32; 38 RSDirtyRegionManager(); 39 ~RSDirtyRegionManager() = default; 40 void MergeDirtyRect(const RectI& rect); 41 void IntersectDirtyRect(const RectI& rect); 42 // Clip dirtyRegion intersected with surfaceRect 43 void ClipDirtyRectWithinSurface(); 44 void Clear(); 45 // return merged historical region 46 const RectI& GetDirtyRegion() const; 47 // return merged historical region upsize down in surface 48 RectI GetDirtyRegionFlipWithinSurface() const; 49 // return current frame's region 50 const RectI& GetLatestDirtyRegion() const; 51 // return merged historical region upsize down in surface 52 RectI GetRectFlipWithinSurface(const RectI& rect) const; 53 // Get aligned rect as times of alignedBits 54 static RectI GetPixelAlignedRect(const RectI& rect, int32_t alignedBits = ALIGNED_BITS); 55 bool IsDirty() const; 56 void UpdateDirty(); 57 void UpdateDirtyByAligned(int32_t alignedBits = ALIGNED_BITS); 58 void UpdateDirtyCanvasNodes(NodeId id, const RectI& rect); 59 void UpdateDirtySurfaceNodes(NodeId id, const RectI& rect); 60 void GetDirtyCanvasNodes(std::map<NodeId, RectI>& target) const; 61 void GetDirtySurfaceNodes(std::map<NodeId, RectI>& target) const; 62 bool SetBufferAge(const int age); 63 bool SetSurfaceSize(const int32_t width, const int32_t height); GetSurfaceRect()64 RectI GetSurfaceRect() const 65 { 66 return surfaceRect_; 67 } 68 void ResetDirtyAsSurfaceSize(); 69 70 void UpdateDebugRegionTypeEnable(); 71 IsDebugRegionTypeEnable(DebugRegionType var)72 inline bool IsDebugRegionTypeEnable(DebugRegionType var) const 73 { 74 if (var < DebugRegionType::TYPE_MAX) { 75 return debugRegionEnabled_[var]; 76 } 77 return false; 78 } 79 IsDebugEnabled()80 inline bool IsDebugEnabled() const 81 { 82 return RSSystemProperties::GetDirtyRegionDebugType() != DirtyRegionDebugType::DISABLED; 83 } 84 85 private: 86 RectI MergeHistory(unsigned int age, RectI rect) const; 87 void PushHistory(RectI rect); 88 // get his rect according to index offset 89 RectI GetHistory(unsigned int i) const; 90 91 RectI surfaceRect_; 92 RectI dirtyRegion_; 93 std::map<NodeId, RectI> dirtyCanvasNodes_; 94 std::map<NodeId, RectI> dirtySurfaceNodes_; 95 std::vector<bool> debugRegionEnabled_; 96 std::vector<RectI> dirtyHistory_; 97 int historyHead_ = -1; 98 unsigned int historySize_ = 0; 99 const unsigned HISTORY_QUEUE_MAX_SIZE = 4; 100 // may add new set function for bufferAge 101 unsigned int bufferAge_ = HISTORY_QUEUE_MAX_SIZE; 102 }; 103 } // namespace Rosen 104 } // namespace OHOS 105 106 #endif // RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_DIRTY_REGION_MANAGER_H 107