1 /* 2 * Copyright (c) 2022-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 RENDER_SERVICE_CLIENT_CORE_MODIFIER_RS_MODIFIER_H 17 #define RENDER_SERVICE_CLIENT_CORE_MODIFIER_RS_MODIFIER_H 18 19 #include "common/rs_macros.h" 20 #include "modifier/rs_property.h" 21 22 class SkCanvas; 23 24 namespace OHOS { 25 namespace Rosen { 26 struct RSDrawingContext { 27 SkCanvas* canvas; 28 float width; 29 float height; 30 }; 31 class RSRenderModifier; 32 33 class RSC_EXPORT RSModifier : public std::enable_shared_from_this<RSModifier> { 34 public: RSModifier(const std::shared_ptr<RSPropertyBase> & property)35 explicit RSModifier(const std::shared_ptr<RSPropertyBase>& property) 36 : property_(property ? property : std::make_shared<RSPropertyBase>()) 37 {} 38 39 virtual ~RSModifier() = default; 40 GetProperty()41 virtual std::shared_ptr<RSPropertyBase> GetProperty() 42 { 43 return property_; 44 } 45 GetPropertyId()46 virtual PropertyId GetPropertyId() 47 { 48 return property_->id_; 49 } 50 51 protected: RSModifier(const std::shared_ptr<RSPropertyBase> & property,const RSModifierType type)52 RSModifier(const std::shared_ptr<RSPropertyBase>& property, const RSModifierType type) 53 : property_(property ? property : std::make_shared<RSPropertyBase>()) 54 { 55 property_->type_ = type; 56 } 57 GetModifierType()58 virtual RSModifierType GetModifierType() const 59 { 60 return RSModifierType::INVALID; 61 } 62 AttachProperty(const std::shared_ptr<RSPropertyBase> & property)63 void AttachProperty(const std::shared_ptr<RSPropertyBase>& property) 64 { 65 if (property != nullptr) { 66 property->target_ = property_->target_; 67 property->SetIsCustom(true); 68 property->AttachModifier(shared_from_this()); 69 property->UpdateExtendedProperty(); 70 } 71 } 72 AttachToNode(const std::shared_ptr<RSNode> target)73 void AttachToNode(const std::shared_ptr<RSNode> target) 74 { 75 property_->target_ = std::weak_ptr<RSNode>(target); 76 } 77 DetachFromNode()78 virtual void DetachFromNode() 79 { 80 property_->target_.reset(); 81 } 82 SetMotionPathOption(const std::shared_ptr<RSMotionPathOption> & motionPathOption)83 virtual void SetMotionPathOption(const std::shared_ptr<RSMotionPathOption>& motionPathOption) 84 { 85 property_->SetMotionPathOption(motionPathOption); 86 } 87 UpdateToRender()88 virtual void UpdateToRender() {} 89 90 virtual std::shared_ptr<RSRenderModifier> CreateRenderModifier() const = 0; 91 92 std::shared_ptr<RSPropertyBase> property_; 93 94 friend class RSModifierExtractor; 95 friend class RSModifierManager; 96 friend class RSNode; 97 friend class RSPathAnimation; 98 }; 99 } // namespace Rosen 100 } // namespace OHOS 101 102 #endif // RENDER_SERVICE_CLIENT_CORE_MODIFIER_RS_MODIFIER_H 103