• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifdef USE_ROSEN_DRAWING
25 #include "core/components_ng/render/drawing.h"
26 #endif
27 
28 namespace OHOS::Rosen {
29 class RSRecordingCanvas;
30 }
31 
32 namespace OHOS::Ace::NG {
33 class Pattern;
34 
35 class RenderingContext2DModifier : public ContentModifier {
36     DECLARE_ACE_TYPE(RenderingContext2DModifier, ContentModifier)
37 
38 public:
39     RenderingContext2DModifier();
40     ~RenderingContext2DModifier() override = default;
41     void onDraw(DrawingContext& drawingContext) override;
42 
MarkModifierDirty()43     void MarkModifierDirty()
44     {
45         CHECK_NULL_VOID(needRender_);
46         needRender_->Set(!needRender_->Get());
47     }
48 
49 #ifndef USE_ROSEN_DRAWING
UpdateCanvas(std::shared_ptr<OHOS::Rosen::RSRecordingCanvas> rsRecordingCanvas)50     void UpdateCanvas(std::shared_ptr<OHOS::Rosen::RSRecordingCanvas> rsRecordingCanvas)
51 #else
52     void UpdateCanvas(std::shared_ptr<RSRecordingCanvas> rsRecordingCanvas)
53 #endif
54     {
55         rsRecordingCanvas_ = rsRecordingCanvas;
56     }
57 
58 private:
59     RefPtr<PropertyBool> needRender_;
60 #ifndef USE_ROSEN_DRAWING
61     std::shared_ptr<OHOS::Rosen::RSRecordingCanvas> rsRecordingCanvas_;
62 #else
63     std::shared_ptr<RSRecordingCanvas> rsRecordingCanvas_;
64 #endif
65     ACE_DISALLOW_COPY_AND_MOVE(RenderingContext2DModifier);
66 };
67 } // namespace OHOS::Ace::NG
68 
69 #endif