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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_XCOMPONENT_XCOMPONENT_MODEL_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_XCOMPONENT_XCOMPONENT_MODEL_H 18 19 #include <mutex> 20 #include <optional> 21 22 #include "base/memory/ace_type.h" 23 #include "core/common/container.h" 24 #include "core/components/common/layout/constants.h" 25 #include "core/components_ng/pattern/xcomponent/inner_xcomponent_controller.h" 26 27 namespace OHOS::Ace { 28 using LoadEvent = std::function<void(const std::string&)>; 29 using DestroyEvent = std::function<void(const std::string&)>; 30 using DetachCallback = std::function<void(const std::string&)>; 31 using SurfaceCreatedEvent = std::function<void(const std::string&, const std::string&)>; 32 using SurfaceChangedEvent = std::function<void(const std::string&, const NG::RectF&)>; 33 using SurfaceDestroyedEvent = std::function<void(const std::string&, const std::string&)>; 34 35 class ACE_FORCE_EXPORT XComponentModel { 36 public: 37 static XComponentModel* GetInstance(); IsBackGroundColorAvailable(const XComponentType & type)38 static bool IsBackGroundColorAvailable(const XComponentType& type) 39 { 40 return type == XComponentType::TEXTURE || type == XComponentType::NODE || 41 (type == XComponentType::SURFACE && Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_ELEVEN)); 42 } IsCommonEventAvailable(const XComponentType & type,std::optional<std::string> & libraryName)43 static bool IsCommonEventAvailable(const XComponentType& type, std::optional<std::string>& libraryName) 44 { 45 return type == XComponentType::NODE || 46 (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TWELVE) && !libraryName.has_value()); 47 } 48 virtual ~XComponentModel() = default; 49 Create(XComponentType type)50 virtual void Create(XComponentType type) {} 51 virtual void Create(const std::optional<std::string>& id, XComponentType type, 52 const std::optional<std::string>& libraryname, 53 const std::shared_ptr<InnerXComponentController>& xcomponentController) = 0; Create(int32_t,float,float,const std::string &,XComponentType,const std::string &,const std::shared_ptr<InnerXComponentController> &)54 virtual RefPtr<AceType> Create(int32_t /* nodeId */, float /* width */, float /* height */, 55 const std::string& /* id */, XComponentType /* type */, const std::string& /* libraryname */, 56 const std::shared_ptr<InnerXComponentController>& /* xcomponentController */) 57 { 58 return nullptr; 59 }; 60 virtual void SetSoPath(const std::string& soPath) = 0; 61 virtual void SetOnLoad(LoadEvent&& onLoad) = 0; 62 virtual void SetOnDestroy(DestroyEvent&& onDestroy) = 0; RegisterOnCreate(const RefPtr<AceType> & node,LoadEvent && onLoad)63 virtual void RegisterOnCreate(const RefPtr<AceType>& node, LoadEvent&& onLoad) {}; RegisterOnDestroy(const RefPtr<AceType> & node,DestroyEvent && onDestroy)64 virtual void RegisterOnDestroy(const RefPtr<AceType>& node, DestroyEvent&& onDestroy) {}; IsTexture()65 virtual bool IsTexture() 66 { 67 return false; 68 } SetDetachCallback(DetachCallback && onDetach)69 virtual void SetDetachCallback(DetachCallback&& onDetach) {} GetType()70 virtual XComponentType GetType() 71 { 72 return XComponentType::UNKNOWN; 73 } SetControllerOnCreated(SurfaceCreatedEvent && onCreated)74 virtual void SetControllerOnCreated(SurfaceCreatedEvent&& onCreated) {} SetControllerOnChanged(SurfaceChangedEvent && onChanged)75 virtual void SetControllerOnChanged(SurfaceChangedEvent&& onChanged) {} SetControllerOnDestroyed(SurfaceDestroyedEvent && onDestroyed)76 virtual void SetControllerOnDestroyed(SurfaceDestroyedEvent&& onDestroyed) {} GetLibraryName()77 virtual std::optional<std::string> GetLibraryName() 78 { 79 return std::nullopt; 80 } EnableAnalyzer(bool enable)81 virtual void EnableAnalyzer(bool enable) {} SetImageAIOptions(void * options)82 virtual void SetImageAIOptions(void* options) {} SetRenderFit(RenderFit renderFit)83 virtual void SetRenderFit(RenderFit renderFit) {} EnableSecure(bool isSecure)84 virtual void EnableSecure(bool isSecure) {} HdrBrightness(float hdrBrightness)85 virtual void HdrBrightness(float hdrBrightness) {} EnableTransparentLayer(bool isTransparentLayer)86 virtual void EnableTransparentLayer(bool isTransparentLayer) {} SetScreenId(uint64_t screenId)87 virtual void SetScreenId(uint64_t screenId) {} 88 }; 89 } // namespace OHOS::Ace 90 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_XCOMPONENT_XCOMPONENT_MODEL_H 91