1 /* 2 * Copyright (c) 2024 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 RENDER_SERVICE_DRAWABLE_DFX_RS_DIRTY_RECTS_DFX_H 17 #define RENDER_SERVICE_DRAWABLE_DFX_RS_DIRTY_RECTS_DFX_H 18 19 #include <string> 20 21 #include "system/rs_system_parameters.h" 22 23 #include "common/rs_occlusion_region.h" 24 #include "drawable/rs_display_render_node_drawable.h" 25 #include "drawable/rs_surface_render_node_drawable.h" 26 #include "params/rs_display_render_params.h" 27 #include "params/rs_render_params.h" 28 #include "params/rs_render_thread_params.h" 29 #include "params/rs_surface_render_params.h" 30 #include "pipeline/rs_display_render_node.h" 31 #include "pipeline/rs_recording_canvas.h" 32 #include "pipeline/rs_surface_render_node.h" 33 #include "pipeline/rs_uni_render_thread.h" 34 namespace OHOS::Rosen { 35 36 class RSDirtyRectsDfx { 37 public: RSDirtyRectsDfx(DrawableV2::RSDisplayRenderNodeDrawable & targetDrawable)38 explicit RSDirtyRectsDfx(DrawableV2::RSDisplayRenderNodeDrawable& targetDrawable) 39 : targetDrawable_(targetDrawable), displayParams_(targetDrawable.GetRenderParams()) 40 {} 41 ~RSDirtyRectsDfx() = default; 42 43 enum class RSPaintStyle { FILL, STROKE }; 44 void OnDraw(RSPaintFilterCanvas& canvas); 45 void OnDrawVirtual(RSPaintFilterCanvas& canvas); SetDirtyRegion(Occlusion::Region & dirtyRegion)46 void SetDirtyRegion(Occlusion::Region& dirtyRegion) 47 { 48 dirtyRegion_ = dirtyRegion; 49 } 50 SetVirtualDirtyRects(const std::vector<RectI> & virtualDirtyRects,const ScreenInfo & screenInfo)51 void SetVirtualDirtyRects(const std::vector<RectI>& virtualDirtyRects, const ScreenInfo& screenInfo) 52 { 53 virtualDirtyRects_ = virtualDirtyRects; 54 screenInfo_ = screenInfo; 55 } 56 57 private: 58 Occlusion::Region dirtyRegion_; 59 std::vector<RectI> virtualDirtyRects_; 60 ScreenInfo screenInfo_; 61 const DrawableV2::RSDisplayRenderNodeDrawable& targetDrawable_; 62 const std::unique_ptr<RSRenderParams>& displayParams_; 63 64 bool RefreshRateRotationProcess(RSPaintFilterCanvas& canvas, ScreenRotation rotation, uint64_t screenId); 65 void DrawCurrentRefreshRate(RSPaintFilterCanvas& canvas); 66 void DrawDirtyRectForDFX(RSPaintFilterCanvas& canvas, RectI dirtyRect, 67 const Drawing::Color color, const RSPaintStyle fillType, int edgeWidth = 6) const; 68 bool DrawDetailedTypesOfDirtyRegionForDFX(RSPaintFilterCanvas& canvas, 69 DrawableV2::RSSurfaceRenderNodeDrawable& surfaceDrawable) const; 70 void DrawSurfaceOpaqueRegionForDFX(RSPaintFilterCanvas& canvas, RSSurfaceRenderParams& surfaceParams) const; 71 72 void DrawDirtyRegionForDFX(RSPaintFilterCanvas& canvas, const std::vector<RectI>& dirtyRects) const; 73 void DrawAllSurfaceDirtyRegionForDFX(RSPaintFilterCanvas& canvas) const; 74 void DrawAllSurfaceOpaqueRegionForDFX(RSPaintFilterCanvas& canvas) const; 75 void DrawTargetSurfaceDirtyRegionForDFX(RSPaintFilterCanvas& canvas) const; 76 void DrawTargetSurfaceVisibleRegionForDFX(RSPaintFilterCanvas& canvas) const; 77 void DrawAndTraceSingleDirtyRegionTypeForDFX(RSPaintFilterCanvas& canvas, 78 DrawableV2::RSSurfaceRenderNodeDrawable& surfaceDrawable, DirtyRegionType dirtyType, bool isDrawn = true) const; 79 void DrawDirtyRegionInVirtual(RSPaintFilterCanvas& canvas) const; 80 81 // dfx check if surface name is in dfx target list CheckIfSurfaceTargetedForDFX(std::string nodeName)82 inline bool CheckIfSurfaceTargetedForDFX(std::string nodeName) const 83 { 84 auto surfaceName = RSUniRenderThread::Instance().GetRSRenderThreadParams()->dfxTargetSurfaceNames_; 85 return (std::find(surfaceName.begin(), surfaceName.end(), nodeName) != surfaceName.end()); 86 } 87 }; 88 } // namespace OHOS::Rosen 89 #endif // RENDER_SERVICE_DRAWABLE_DFX_RS_DIRTY_RECTS_DFX_H 90