1 /* 2 * Copyright (c) 2021 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_CUSTOM_PAINT_CUSTOM_PAINT_ELEMENT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CUSTOM_PAINT_CUSTOM_PAINT_ELEMENT_H 18 19 #include "core/components/custom_paint/render_custom_paint.h" 20 #include "core/pipeline/base/render_element.h" 21 22 namespace OHOS::Ace { 23 24 class CustomPaintElement : public RenderElement { 25 DECLARE_ACE_TYPE(CustomPaintElement, RenderElement); 26 27 public: 28 CustomPaintElement() = default; 29 ~CustomPaintElement() override = default; 30 Update()31 void Update() override 32 { 33 std::list<TaskFunc> tasks; 34 auto paint = AceType::DynamicCast<RenderCustomPaint>(renderNode_); 35 if (paint && paint->HasTask()) { 36 tasks = paint->GetTasks(); 37 } 38 customComponent_ = component_; 39 RenderElement::Update(); 40 if (paint) { 41 paint->SetTasks(tasks); 42 } 43 } 44 CanUpdate(const RefPtr<Component> & newComponent)45 bool CanUpdate(const RefPtr<Component>& newComponent) override 46 { 47 const auto context = renderNode_->GetContext().Upgrade(); 48 if (context && context->GetIsDeclarative()) { 49 return Element::CanUpdate(newComponent); 50 } 51 return (newComponent == customComponent_) && Element::CanUpdate(newComponent); 52 } 53 54 private: 55 WeakPtr<Component> customComponent_; 56 }; 57 } // namespace OHOS::Ace 58 59 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CUSTOM_PAINT_CUSTOM_PAINT_ELEMENT_H 60