• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PAINTS_PAINT_WRAPPER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PAINTS_PAINT_WRAPPER_H
18 
19 #include <functional>
20 #include <memory>
21 
22 #include "base/geometry/ng/offset_t.h"
23 #include "base/geometry/ng/size_t.h"
24 #include "base/memory/ace_type.h"
25 #include "base/memory/referenced.h"
26 #include "base/thread/cancelable_callback.h"
27 #include "core/components_ng/base/geometry_node.h"
28 #include "core/components_ng/render/paint_property.h"
29 #include "core/components_ng/render/render_context.h"
30 #include "core/pipeline_ng/ui_task_scheduler.h"
31 
32 namespace OHOS::Ace::Kit {
33 class NodePaintMethod;
34 }
35 
36 namespace OHOS::Ace::NG {
37 class NodePaintMethod;
38 
39 // PaintWrapper are used to flush dirty render task.
40 class PaintWrapper : public virtual AceType {
41     DECLARE_ACE_TYPE(PaintWrapper, AceType);
42 
43 public:
44     PaintWrapper(WeakPtr<RenderContext> renderContext, RefPtr<GeometryNode> geometryNode,
45         RefPtr<PaintProperty> paintProperty, RefPtr<ExtensionHandler> handler = nullptr);
46     ~PaintWrapper() override;
47 
48     void SetNodePaintMethod(const RefPtr<NodePaintMethod>& nodePaintImpl);
49 
50     void SetKitNodePaintMethod(const RefPtr<Kit::NodePaintMethod>& nodePaintMethod);
51 
SetTaskThread(TaskThread taskThread)52     void SetTaskThread(TaskThread taskThread)
53     {
54         taskThread_ = taskThread;
55     }
56 
57     void FlushRender();
58 
CanRunOnWhichThread()59     TaskThread CanRunOnWhichThread() const
60     {
61         return taskThread_;
62     }
63 
CheckShouldRunOnMain()64     bool CheckShouldRunOnMain() const
65     {
66         return (CanRunOnWhichThread() & MAIN_TASK) == MAIN_TASK;
67     }
68 
GetPaintProperty()69     const RefPtr<PaintProperty>& GetPaintProperty() const
70     {
71         return paintProperty_;
72     }
73 
GetGeometryNode()74     const RefPtr<GeometryNode>& GetGeometryNode() const
75     {
76         return geometryNode_;
77     }
78 
GetRenderContext()79     RefPtr<RenderContext> GetRenderContext() const
80     {
81         return renderContext_.Upgrade();
82     }
83 
GetContentSize()84     SizeF GetContentSize() const
85     {
86         return geometryNode_->GetContentSize();
87     }
88 
GetContentOffset()89     OffsetF GetContentOffset() const
90     {
91         return geometryNode_->GetContentOffset();
92     }
93 
HasForegroundColor()94     bool HasForegroundColor() const
95     {
96         auto renderContext = renderContext_.Upgrade();
97         return renderContext->HasForegroundColor();
98     }
99 
HasForegroundColorStrategy()100     bool HasForegroundColorStrategy() const
101     {
102         auto renderContext = renderContext_.Upgrade();
103         return renderContext->HasForegroundColorStrategy();
104     }
105 
GetForegroundColor()106     Color GetForegroundColor() const
107     {
108         auto renderContext = renderContext_.Upgrade();
109         return renderContext->GetForegroundColor().value_or(Color::FOREGROUND);
110     }
111 
112     void FlushOverlayModifier();
113 
114     void FlushContentModifier();
115 
116     void FlushForegroundModifier();
117 
118 private:
119     WeakPtr<RenderContext> renderContext_;
120     RefPtr<GeometryNode> geometryNode_;
121     RefPtr<PaintProperty> paintProperty_;
122     RefPtr<NodePaintMethod> nodePaintImpl_;
123     RefPtr<ExtensionHandler> extensionHandler_;
124     TaskThread taskThread_ = MAIN_TASK;
125     RefPtr<Kit::NodePaintMethod> nodePaintMethod_;
126 };
127 } // namespace OHOS::Ace::NG
128 
129 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PAINTS_PAINT_WRAPPER_H
130