1 /* 2 * Copyright (c) 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 16 #ifndef ROSEN_RENDER_SERVICE_BASE_PIPELINE_RS_CANVAS_DRAWING_RENDER_NODE_H 17 #define ROSEN_RENDER_SERVICE_BASE_PIPELINE_RS_CANVAS_DRAWING_RENDER_NODE_H 18 19 #include <functional> 20 #include <memory> 21 22 #include "pipeline/rs_canvas_render_node.h" 23 24 namespace OHOS { 25 namespace Rosen { 26 struct RSModifierContext; 27 #ifndef USE_ROSEN_DRAWING 28 using ThreadInfo = std::pair<uint64_t, std::function<void(sk_sp<SkSurface>)>>; 29 #else 30 using ThreadInfo = std::pair<uint64_t, std::function<void(std::shared_ptr<Drawing::Surface>)>>; 31 #endif 32 33 class RSB_EXPORT RSCanvasDrawingRenderNode : public RSCanvasRenderNode { 34 public: 35 using WeakPtr = std::weak_ptr<RSCanvasDrawingRenderNode>; 36 using SharedPtr = std::shared_ptr<RSCanvasDrawingRenderNode>; 37 static inline constexpr RSRenderNodeType Type = RSRenderNodeType::CANVAS_DRAWING_NODE; 38 39 explicit RSCanvasDrawingRenderNode(NodeId id, std::weak_ptr<RSContext> context = {}); 40 virtual ~RSCanvasDrawingRenderNode(); 41 42 void ProcessRenderContents(RSPaintFilterCanvas& canvas) override; 43 GetType()44 RSRenderNodeType GetType() const override 45 { 46 return Type; 47 } 48 49 #ifndef USE_ROSEN_DRAWING 50 SkBitmap GetBitmap(); 51 bool GetPixelmap(const std::shared_ptr<Media::PixelMap> pixelmap, const SkRect* rect); 52 #else 53 bool GetBitmap(Drawing::Bitmap& bitmap); 54 #endif 55 SetSurfaceClearFunc(ThreadInfo threadInfo)56 void SetSurfaceClearFunc(ThreadInfo threadInfo) 57 { 58 curThreadInfo_ = threadInfo; 59 } 60 61 private: 62 void ApplyDrawCmdModifier(RSModifierContext& context, RSModifierType type) const override; 63 bool ResetSurface(int width, int height, RSPaintFilterCanvas& canvas); 64 bool GetSizeFromDrawCmdModifiers(int& width, int& height); 65 bool IsNeedResetSurface(const int& width, const int& height) const; 66 67 #ifndef USE_ROSEN_DRAWING 68 sk_sp<SkSurface> skSurface_; 69 SkBitmap skBitmap_; 70 #else 71 std::shared_ptr<Drawing::Bitmap> bitmap_; 72 std::shared_ptr<Drawing::Surface> surface_; 73 #endif 74 std::unique_ptr<RSPaintFilterCanvas> canvas_; 75 ThreadInfo curThreadInfo_ = {}; 76 ThreadInfo preThreadInfo_ = {}; 77 std::mutex mutex_; 78 }; 79 80 } // namespace Rosen 81 } // namespace OHOS 82 83 #endif // ROSEN_RENDER_SERVICE_BASE_PIPELINE_RS_CANVAS_DRAWING_RENDER_NODE_H