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