1 /* 2 * Copyright (c) 2021-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_CLIENT_CORE_RENDER_RS_RENDER_THREAD_VISITOR_H 17 #define RENDER_SERVICE_CLIENT_CORE_RENDER_RS_RENDER_THREAD_VISITOR_H 18 19 #include <memory> 20 #include <map> 21 #include <set> 22 23 #include "pipeline/rs_dirty_region_manager.h" 24 #include "pipeline/rs_paint_filter_canvas.h" 25 #include "transaction/rs_transaction_proxy.h" 26 #include "visitor/rs_node_visitor.h" 27 28 #ifdef USE_ROSEN_DRAWING 29 #include "draw/brush.h" 30 #include "draw/color.h" 31 #include "draw/pen.h" 32 #endif 33 34 namespace OHOS { 35 namespace Rosen { 36 class RSDirtyRegionManager; 37 class RSProperties; 38 class RSRenderNode; 39 40 class RSRenderThreadVisitor : public RSNodeVisitor { 41 public: 42 RSRenderThreadVisitor(); 43 virtual ~RSRenderThreadVisitor(); 44 45 void PrepareChildren(RSRenderNode& node) override; 46 void PrepareCanvasRenderNode(RSCanvasRenderNode& node) override; PrepareDisplayRenderNode(RSDisplayRenderNode & node)47 void PrepareDisplayRenderNode(RSDisplayRenderNode& node) override {} PrepareProxyRenderNode(RSProxyRenderNode & node)48 void PrepareProxyRenderNode(RSProxyRenderNode& node) override {} 49 void PrepareRootRenderNode(RSRootRenderNode& node) override; 50 void PrepareSurfaceRenderNode(RSSurfaceRenderNode& node) override; 51 void PrepareEffectRenderNode(RSEffectRenderNode& node) override; 52 53 void ProcessChildren(RSRenderNode& node) override; 54 void ProcessCanvasRenderNode(RSCanvasRenderNode& node) override; ProcessDisplayRenderNode(RSDisplayRenderNode & node)55 void ProcessDisplayRenderNode(RSDisplayRenderNode& node) override {} 56 void ProcessProxyRenderNode(RSProxyRenderNode& node) override; 57 void ProcessRootRenderNode(RSRootRenderNode& node) override; 58 void ProcessSurfaceRenderNode(RSSurfaceRenderNode& node) override; 59 void ProcessEffectRenderNode(RSEffectRenderNode& node) override; 60 61 void AddSurfaceChangedCallBack(uint64_t id, 62 const std::function<void(float, float, float, float)>& callback) override; 63 void RemoveSurfaceChangedCallBack(uint64_t id) override; 64 65 // Partial render status and renderForce flag should be updated by rt thread 66 void SetPartialRenderStatus(PartialRenderType status, bool isRenderForced); 67 private: 68 #ifndef USE_ROSEN_DRAWING 69 void DrawRectOnCanvas(const RectI& dirtyRect, const SkColor color, const SkPaint::Style fillType, float alpha, 70 int strokeWidth = 6); 71 #else 72 enum class RSPaintStyle { 73 FILL, 74 STROKE 75 }; 76 void DrawRectOnCanvas(const RectI& dirtyRect, const Drawing::ColorQuad color, RSPaintStyle fillType, float alpha, 77 int strokeWidth = 6); 78 #endif // USE_ROSEN_DRAWING 79 void DrawDirtyRegion(); 80 // Update damageRegion based on buffer age, and then set it through egl api 81 #ifdef NEW_RENDER_CONTEXT 82 void UpdateDirtyAndSetEGLDamageRegion(std::shared_ptr<RSRenderSurface>& surface); 83 #else 84 void UpdateDirtyAndSetEGLDamageRegion(std::unique_ptr<RSSurfaceFrame>& surfaceFrame); 85 #endif 86 // Reset and update children node's info like outOfParent and isRemoveChild 87 void ResetAndPrepareChildrenNode(RSRenderNode& node, std::shared_ptr<RSBaseRenderNode> nodeParent); 88 void ProcessSurfaceViewInRT(RSSurfaceRenderNode& node); 89 int CacRotationFromTransformType(GraphicTransformType transform); 90 91 bool UpdateAnimatePropertyCacheSurface(RSRenderNode& node); 92 void ProcessShadowFirst(RSRenderNode& node); 93 94 std::shared_ptr<RSDirtyRegionManager> curDirtyManager_; 95 bool isRenderForced_ = false; 96 bool isEglSetDamageRegion_ = false; 97 bool isOpDropped_ = false; 98 DirtyRegionDebugType dfxDirtyType_ = DirtyRegionDebugType::DISABLED; 99 PartialRenderType partialRenderStatus_ = PartialRenderType::DISABLED; 100 RectI curDirtyRegion_ = RectI(); 101 bool dirtyFlag_ = false; 102 bool isIdle_ = true; 103 std::shared_ptr<RSPaintFilterCanvas> canvas_ = nullptr; 104 uint32_t queueSize_ = 0; 105 uint64_t uiTimestamp_ = 0; 106 107 void ClipHoleForSurfaceNode(RSSurfaceRenderNode& node); 108 109 std::vector<NodeId> childSurfaceNodeIds_; 110 #ifndef USE_ROSEN_DRAWING 111 SkMatrix parentSurfaceNodeMatrix_; 112 std::optional<SkIRect> effectRegion_ = std::nullopt; 113 std::vector<std::shared_ptr<DrawCmdList>> drawCmdListVector_; 114 #else 115 Drawing::Matrix parentSurfaceNodeMatrix_; 116 std::optional<Drawing::RectI> effectRegion_ = std::nullopt; 117 std::vector<std::shared_ptr<Drawing::DrawCmdList>> drawCmdListVector_; 118 #endif // USE_ROSEN_DRAWING 119 120 std::map<NodeId, std::function<void(float, float, float, float)>> surfaceCallbacks_; 121 122 static void SendCommandFromRT(std::unique_ptr<RSCommand>& command, NodeId nodeId, FollowType followType); 123 static bool IsValidRootRenderNode(RSRootRenderNode& node); 124 private: 125 void ProcessTextureSurfaceRenderNode(RSSurfaceRenderNode& node); 126 void ProcessOtherSurfaceRenderNode(RSSurfaceRenderNode& node); 127 }; 128 } // namespace Rosen 129 } // namespace OHOS 130 131 #endif // RENDER_SERVICE_CLIENT_CORE_RENDER_RS_RENDER_THREAD_VISITOR_H 132