1 /* 2 * Copyright (c) 2025 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_PATTERNS_XCOMPONENT_XCOMPONENT_PATTERN_V2_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_XCOMPONENT_XCOMPONENT_PATTERN_V2_H 18 #include "core/components_ng/pattern/xcomponent/xcomponent_pattern.h" 19 #include "core/components_ng/pattern/xcomponent/xcomponent_surface_holder.h" 20 21 namespace OHOS::Ace::NG { 22 class XComponentPatternV2 : public XComponentPattern { 23 DECLARE_ACE_TYPE(XComponentPatternV2, XComponentPattern); 24 public: 25 XComponentPatternV2() = default; 26 XComponentPatternV2(XComponentType type, XComponentNodeType nodeType); 27 ~XComponentPatternV2() override = default; 28 void SetSurfaceHolder(OH_ArkUI_SurfaceHolder* surfaceHolder); 29 OH_ArkUI_SurfaceHolder* GetSurfaceHolder(); 30 int32_t Initialize(); 31 int32_t Finalize(); 32 int32_t SetAutoInitialize(bool autoInitialize); 33 int32_t IsInitialized(bool& isInitialized); 34 IsCreateSurfaceHolderForbidden()35 bool IsCreateSurfaceHolderForbidden() 36 { 37 return (hasGotNativeXComponent_ || usesSuperMethod_); 38 } 39 GetXComponentNodeType()40 XComponentNodeType GetXComponentNodeType() const 41 { 42 return nodeType_; 43 } 44 IsBindNative()45 bool IsBindNative() override 46 { 47 return true; 48 } 49 50 private: 51 void OnAttachToFrameNode() override; 52 void OnAttachToMainTree() override; 53 void BeforeSyncGeometryProperties(const DirtySwapConfig& config) override; 54 void OnDetachFromMainTree() override; 55 void OnDetachFromFrameNode(FrameNode* frameNode) override; 56 void OnWindowHide() override; 57 void OnWindowShow() override; 58 void OnRebuildFrame() override; 59 void OnModifyDone() override; 60 void DumpInfo() override; 61 62 void InitSurface(); 63 int32_t HandleSurfaceCreated(); 64 int32_t HandleSurfaceDestroyed(); 65 void InitializeRenderContext(); 66 std::pair<bool, bool> UpdateSurfaceRect(); 67 void HandleSurfaceChangeEvent(bool offsetChanged, bool sizeChanged, bool frameOffsetChange); 68 void XComponentSizeChange(const RectF& surfaceRect); 69 void OnSurfaceChanged(const RectF& surfaceRect); 70 UpdateUsesSuperMethod()71 void UpdateUsesSuperMethod() 72 { 73 if (usesSuperMethod_) { 74 return; 75 } 76 usesSuperMethod_ = (isCNode_ && !isLifecycleInterfaceCalled_ && !surfaceHolder_); 77 } 78 79 bool autoInitialize_ = true; 80 bool isInitialized_ = false; 81 bool isLifecycleInterfaceCalled_ = false; 82 bool usesSuperMethod_ = false; 83 bool needNotifySizeChanged_ = false; 84 OH_ArkUI_SurfaceHolder* surfaceHolder_ = nullptr; 85 XComponentNodeType nodeType_ = XComponentNodeType::UNKNOWN; 86 }; 87 } // namespace OHOS::Ace::NG 88 89 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_XCOMPONENT_XCOMPONENT_PATTERN_V2_H 90