1 /* 2 * Copyright (c) 2022 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_CORE_PIPELINE_RS_UNI_RENDER_UTIL_H 17 #define RENDER_SERVICE_CORE_PIPELINE_RS_UNI_RENDER_UTIL_H 18 19 #include <list> 20 #include <set> 21 #include "surface.h" 22 #include "sync_fence.h" 23 #include "pipeline/rs_base_render_util.h" 24 #include "pipeline/rs_display_render_node.h" 25 #include "pipeline/rs_surface_render_node.h" 26 #include "pipeline/rs_paint_filter_canvas.h" 27 #include "pipeline/rs_render_node_map.h" 28 #include "common/rs_obj_abs_geometry.h" 29 30 #ifdef USE_ROSEN_DRAWING 31 #include "utils/matrix.h" 32 #endif 33 34 namespace OHOS { 35 namespace Rosen { 36 class RSUniRenderUtil { 37 public: 38 // merge history dirty region of current display node and its child surfacenode(app windows) 39 // for mirror display, call this function twice will introduce additional dirtyhistory in dirtymanager 40 static void MergeDirtyHistory(std::shared_ptr<RSDisplayRenderNode>& node, int32_t bufferAge, 41 bool useAlignedDirtyRegion = false); 42 43 /* we want to set visible dirty region of each surfacenode into DamageRegionKHR interface, hence 44 * occlusion is calculated. 45 * make sure this function is called after merge dirty history 46 */ 47 static Occlusion::Region MergeVisibleDirtyRegion(std::shared_ptr<RSDisplayRenderNode>& node, 48 bool useAlignedDirtyRegion = false); 49 static bool HandleSubThreadNode(RSRenderNode& node, RSPaintFilterCanvas& canvas); 50 static bool HandleCaptureNode(RSRenderNode& node, RSPaintFilterCanvas& canvas); 51 static void SrcRectScaleDown(BufferDrawParam& params, const RSSurfaceRenderNode& node); 52 static BufferDrawParam CreateBufferDrawParam(const RSSurfaceRenderNode& node, 53 bool forceCPU, uint32_t threadIndex = UNI_MAIN_THREAD_INDEX); 54 static BufferDrawParam CreateBufferDrawParam(const RSDisplayRenderNode& node, bool forceCPU); 55 static BufferDrawParam CreateLayerBufferDrawParam(const LayerInfoPtr& layer, bool forceCPU); 56 #ifndef USE_ROSEN_DRAWING 57 static void DrawCachedImage(RSSurfaceRenderNode& node, RSPaintFilterCanvas& canvas, sk_sp<SkImage> image); 58 static Occlusion::Region AlignedDirtyRegion(const Occlusion::Region& dirtyRegion, int32_t alignedBits = 32); 59 static int GetRotationFromMatrix(SkMatrix matrix); 60 #else 61 static void DrawCachedImage( 62 RSSurfaceRenderNode& node, RSPaintFilterCanvas& canvas, std::shared_ptr<Drawing::Image> image); 63 static Occlusion::Region AlignedDirtyRegion(const Occlusion::Region& dirtyRegion, int32_t alignedBits = 32); 64 static int GetRotationFromMatrix(Drawing::Matrix matrix); 65 #endif 66 static void AssignWindowNodes(const std::shared_ptr<RSDisplayRenderNode>& displayNode, 67 std::list<std::shared_ptr<RSSurfaceRenderNode>>& mainThreadNodes, 68 std::list<std::shared_ptr<RSSurfaceRenderNode>>& subThreadNodes, uint64_t focusNodeId = 0, 69 DeviceType deviceType = DeviceType::PHONE); 70 static void ClearSurfaceIfNeed(const RSRenderNodeMap& map, const std::shared_ptr<RSDisplayRenderNode>& displayNode, 71 std::set<std::shared_ptr<RSBaseRenderNode>>& oldChildren); 72 static void ClearCacheSurface(RSRenderNode& node, uint32_t threadIndex); 73 #ifndef USE_ROSEN_DRAWING 74 static void ClearNodeCacheSurface(sk_sp<SkSurface>& cacheSurface, sk_sp<SkSurface>& cacheCompletedSurface, 75 uint32_t cacheSurfaceThreadIndex, uint32_t completedSurfaceThreadIndex); 76 #else 77 static void ClearNodeCacheSurface(std::shared_ptr<Drawing::Surface>& cacheSurface, 78 std::shared_ptr<Drawing::Surface>& cacheCompletedSurface, 79 uint32_t cacheSurfaceThreadIndex, uint32_t completedSurfaceThreadIndex); 80 #endif 81 static void CacheSubThreadNodes(std::list<std::shared_ptr<RSSurfaceRenderNode>>& oldSubThreadNodes, 82 std::list<std::shared_ptr<RSSurfaceRenderNode>>& subThreadNodes); 83 // use floor value of translateX and translateY in matrix of canvas to avoid jittering 84 static void FloorTransXYInCanvasMatrix(RSPaintFilterCanvas& canvas); 85 private: 86 static void AssignMainThreadNode(std::list<std::shared_ptr<RSSurfaceRenderNode>>& mainThreadNodes, 87 const std::shared_ptr<RSSurfaceRenderNode>& node); 88 static void AssignSubThreadNode(std::list<std::shared_ptr<RSSurfaceRenderNode>>& subThreadNodes, 89 const std::shared_ptr<RSSurfaceRenderNode>& node, DeviceType deviceType = DeviceType::PHONE); 90 static void SortSubThreadNodes(std::list<std::shared_ptr<RSSurfaceRenderNode>>& subThreadNodes); 91 static void HandleHardwareNode(const std::shared_ptr<RSSurfaceRenderNode>& node); 92 static void ClearCacheSurface(const std::shared_ptr<RSSurfaceRenderNode>& node, uint32_t threadIndex); 93 static void PostReleaseSurfaceTask(sk_sp<SkSurface>& surface, uint32_t threadIndex); 94 }; 95 } 96 } 97 #endif // RENDER_SERVICE_CORE_PIPELINE_RS_UNI_RENDER_UTIL_H 98