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