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::NG { 33 class NodePaintMethod; 34 35 // PaintWrapper are used to flush dirty render task. 36 class PaintWrapper : public virtual AceType { 37 DECLARE_ACE_TYPE(PaintWrapper, AceType) 38 39 public: 40 PaintWrapper(WeakPtr<RenderContext> renderContext, RefPtr<GeometryNode> geometryNode, 41 RefPtr<PaintProperty> layoutProperty, RefPtr<ExtensionHandler> handler = nullptr); 42 ~PaintWrapper() override; 43 44 void SetNodePaintMethod(const RefPtr<NodePaintMethod>& nodePaintImpl); 45 SetTaskThread(TaskThread taskThread)46 void SetTaskThread(TaskThread taskThread) 47 { 48 taskThread_ = taskThread; 49 } 50 51 void FlushRender(); 52 CanRunOnWhichThread()53 TaskThread CanRunOnWhichThread() const 54 { 55 return taskThread_; 56 } 57 CheckShouldRunOnMain()58 bool CheckShouldRunOnMain() const 59 { 60 return (CanRunOnWhichThread() & MAIN_TASK) == MAIN_TASK; 61 } 62 GetPaintProperty()63 const RefPtr<PaintProperty>& GetPaintProperty() const 64 { 65 return paintProperty_; 66 } 67 GetGeometryNode()68 const RefPtr<GeometryNode>& GetGeometryNode() const 69 { 70 return geometryNode_; 71 } 72 GetRenderContext()73 RefPtr<RenderContext> GetRenderContext() const 74 { 75 return renderContext_.Upgrade(); 76 } 77 GetContentSize()78 SizeF GetContentSize() const 79 { 80 return geometryNode_->GetContentSize(); 81 } 82 GetContentOffset()83 OffsetF GetContentOffset() const 84 { 85 return geometryNode_->GetContentOffset(); 86 } 87 HasForegroundColor()88 bool HasForegroundColor() const 89 { 90 auto renderContext = renderContext_.Upgrade(); 91 return renderContext->HasForegroundColor(); 92 } 93 HasForegroundColorStrategy()94 bool HasForegroundColorStrategy() const 95 { 96 auto renderContext = renderContext_.Upgrade(); 97 return renderContext->HasForegroundColorStrategy(); 98 } 99 GetForegroundColor()100 Color GetForegroundColor() const 101 { 102 auto renderContext = renderContext_.Upgrade(); 103 return renderContext->GetForegroundColor().value_or(Color::FOREGROUND); 104 } 105 106 void FlushOverlayModifier(); 107 108 void FlushContentModifier(); 109 110 void FlushForegroundModifier(); 111 112 private: 113 WeakPtr<RenderContext> renderContext_; 114 RefPtr<GeometryNode> geometryNode_; 115 RefPtr<PaintProperty> paintProperty_; 116 RefPtr<NodePaintMethod> nodePaintImpl_; 117 RefPtr<ExtensionHandler> extensionHandler_; 118 TaskThread taskThread_ = MAIN_TASK; 119 }; 120 } // namespace OHOS::Ace::NG 121 122 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PAINTS_PAINT_WRAPPER_H 123