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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_RENDERING_CONTEXT_2D_CONTENT_MODIFIER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_RENDERING_CONTEXT_2D_CONTENT_MODIFIER_H 18 19 #include <optional> 20 #include <vector> 21 22 #include "base/memory/ace_type.h" 23 #include "core/components_ng/base/modifier.h" 24 #include "core/components_ng/pattern/canvas/custom_paint_util.h" 25 #include "core/components_ng/render/drawing.h" 26 27 namespace OHOS::Ace::NG { 28 class RenderContext; 29 class CanvasModifier : public ContentModifier { 30 DECLARE_ACE_TYPE(CanvasModifier, ContentModifier); 31 32 public: 33 CanvasModifier(); 34 ~CanvasModifier() override = default; 35 void onDraw(DrawingContext& drawingContext) override; 36 std::string GetDumpInfo(); 37 void GetSimplifyDumpInfo(std::unique_ptr<JsonValue>& array); 38 39 void SetRenderContext(const WeakPtr<RenderContext>& renderContext); 40 SetNeedResetSurface()41 void SetNeedResetSurface() 42 { 43 needResetSurface_ = true; 44 } 45 MarkModifierDirty()46 void MarkModifierDirty() 47 { 48 CHECK_NULL_VOID(needRender_); 49 needRender_->Set(!needRender_->Get()); 50 } 51 UpdateCanvas(std::shared_ptr<RSRecordingCanvas> rsRecordingCanvas)52 void UpdateCanvas(std::shared_ptr<RSRecordingCanvas> rsRecordingCanvas) 53 { 54 rsRecordingCanvas_ = rsRecordingCanvas; 55 } 56 57 private: 58 void ResetSurface(); 59 bool needResetSurface_ = false; 60 WeakPtr<RenderContext> renderContext_; 61 RefPtr<PropertyBool> needRender_; 62 std::shared_ptr<RSRecordingCanvas> rsRecordingCanvas_; 63 SizeT<int32_t> recordingCanvasDrawSize_ = { 0.0f, 0.0f }; 64 SizeT<int32_t> drawCmdSize_ = { 0.0f, 0.0f }; 65 std::vector<CanvasModifierDump> dumpInfos_; 66 ACE_DISALLOW_COPY_AND_MOVE(CanvasModifier); 67 }; 68 } // namespace OHOS::Ace::NG 69 70 #endif 71