From 749840cbcb4f081b8da1cdb6f0594baafb14aedc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rulong=20Chen=EF=BC=88=E9=99=88=E6=B1=9D=E9=BE=99=EF=BC=89?= Date: Wed, 28 Feb 2024 19:04:34 +0800 Subject: [PATCH 01/13] Fix the C++ style issues. --- .../platform/ohos/ohos_xcomponent_adapter.cpp | 167 +++++++++--------- shell/platform/ohos/ohos_xcomponent_adapter.h | 65 ++++--- 2 files changed, 121 insertions(+), 111 deletions(-) diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.cpp b/shell/platform/ohos/ohos_xcomponent_adapter.cpp index a657f6b949..6673f425de 100644 --- a/shell/platform/ohos/ohos_xcomponent_adapter.cpp +++ b/shell/platform/ohos/ohos_xcomponent_adapter.cpp @@ -14,52 +14,55 @@ */ #include "ohos_xcomponent_adapter.h" + +#include + #include "flutter/shell/platform/ohos/napi/platform_view_ohos_napi.h" #include "types.h" -#include -namespace flutter { -XComponentAdapter XComponentAdapter::mXComponentAdapter; +namespace flutter { -XComponentAdapter::XComponentAdapter(/* args */) {} +XComponentAdapter::XComponentAdapter() {} XComponentAdapter::~XComponentAdapter() {} XComponentAdapter* XComponentAdapter::GetInstance() { - return &XComponentAdapter::mXComponentAdapter; + static XComponentAdapter* instance = new XComponentAdapter; + return instance; } bool XComponentAdapter::Export(napi_env env, napi_value exports) { napi_status status; - napi_value exportInstance = nullptr; - OH_NativeXComponent* nativeXComponent = nullptr; + napi_value export_instance = nullptr; + OH_NativeXComponent* native_xcomponent = nullptr; int32_t ret; - char idStr[OH_XCOMPONENT_ID_LEN_MAX + 1] = {}; - uint64_t idSize = OH_XCOMPONENT_ID_LEN_MAX + 1; + char id_str[OH_XCOMPONENT_ID_LEN_MAX + 1] = {}; + uint64_t id_size = OH_XCOMPONENT_ID_LEN_MAX + 1; status = napi_get_named_property(env, exports, OH_NATIVE_XCOMPONENT_OBJ, - &exportInstance); + &export_instance); LOGD("napi_get_named_property,status = %{public}d", status); if (status != napi_ok) { return false; } - status = napi_unwrap(env, exportInstance, - reinterpret_cast(&nativeXComponent)); + status = napi_unwrap(env, export_instance, + reinterpret_cast(&native_xcomponent)); LOGD("napi_unwrap,status = %{public}d", status); if (status != napi_ok) { return false; } - ret = OH_NativeXComponent_GetXComponentId(nativeXComponent, idStr, &idSize); - LOGD("NativeXComponent id:%{public}s", idStr); + ret = + OH_NativeXComponent_GetXComponentId(native_xcomponent, id_str, &id_size); + LOGD("NativeXComponent id:%{public}s", id_str); if (ret != OH_NATIVEXCOMPONENT_RESULT_SUCCESS) { return false; } - std::string id(idStr); + std::string id(id_str); auto context = XComponentAdapter::GetInstance(); if (context) { - context->SetNativeXComponent(id, nativeXComponent); + context->SetNativeXComponent(id, native_xcomponent); return true; } @@ -67,37 +70,38 @@ bool XComponentAdapter::Export(napi_env env, napi_value exports) { } void XComponentAdapter::SetNativeXComponent( - std::string& id, - OH_NativeXComponent* nativeXComponent) { - auto iter = xcomponetMap_.find(id); - if (iter == xcomponetMap_.end()) { + const std::string& id, + OH_NativeXComponent* native_xcomponent) { + auto iter = xcomponent_map_.find(id); + if (iter == xcomponent_map_.end()) { XComponentBase* xcomponet = new XComponentBase(id); - xcomponetMap_[id] = xcomponet; + xcomponent_map_[id] = xcomponet; } - iter = xcomponetMap_.find(id); - if (iter != xcomponetMap_.end()) { - iter->second->SetNativeXComponent(nativeXComponent); + iter = xcomponent_map_.find(id); + if (iter != xcomponent_map_.end()) { + iter->second->SetNativeXComponent(native_xcomponent); } } -void XComponentAdapter::AttachFlutterEngine(std::string& id, - std::string& shellholderId) { - auto iter = xcomponetMap_.find(id); - if (iter == xcomponetMap_.end()) { +void XComponentAdapter::AttachFlutterEngine( + const std::string& id, + const std::string& shell_holder_id) { + auto iter = xcomponent_map_.find(id); + if (iter == xcomponent_map_.end()) { XComponentBase* xcomponet = new XComponentBase(id); - xcomponetMap_[id] = xcomponet; + xcomponent_map_[id] = xcomponet; } - auto findIter = xcomponetMap_.find(id); - if (findIter != xcomponetMap_.end()) { - findIter->second->AttachFlutterEngine(shellholderId); + auto findIter = xcomponent_map_.find(id); + if (findIter != xcomponent_map_.end()) { + findIter->second->AttachFlutterEngine(shell_holder_id); } } -void XComponentAdapter::DetachFlutterEngine(std::string& id) { - auto iter = xcomponetMap_.find(id); - if (iter != xcomponetMap_.end()) { +void XComponentAdapter::DetachFlutterEngine(const std::string& id) { + auto iter = xcomponent_map_.find(id); + if (iter != xcomponent_map_.end()) { iter->second->DetachFlutterEngine(); } } @@ -142,7 +146,7 @@ using OHOS_SurfaceBufferUsage = enum { BUFFER_USAGE_VENDOR_PRI18 = (1ULL << 62), /**< Reserverd for vendor */ BUFFER_USAGE_VENDOR_PRI19 = (1ULL << 63), /**< Reserverd for vendor */ }; -static int32_t SetNativeWindowOpt(OHNativeWindow* nativeWindow, +static int32_t SetNativeWindowOpt(OHNativeWindow* native_window, int32_t width, int height) { // Set the read and write scenarios of the native window buffer. @@ -150,83 +154,79 @@ static int32_t SetNativeWindowOpt(OHNativeWindow* nativeWindow, int32_t usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA; int32_t ret = - OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, usage); + OH_NativeWindow_NativeWindowHandleOpt(native_window, code, usage); if (ret) { LOGE( "Set NativeWindow Usage Failed :window:%{public}p ,w:%{public}d x " "%{public}d:%{public}d", - nativeWindow, width, height, ret); + native_window, width, height, ret); } // Set the width and height of the native window buffer. code = SET_BUFFER_GEOMETRY; ret = - OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, width, height); + OH_NativeWindow_NativeWindowHandleOpt(native_window, code, width, height); if (ret) { LOGE( "Set NativeWindow GEOMETRY Failed :window:%{public}p ,w:%{public}d x " "%{public}d:%{public}d", - nativeWindow, width, height, ret); + native_window, width, height, ret); } // Set the step of the native window buffer. code = SET_STRIDE; int32_t stride = 0x8; - ret = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, stride); + ret = OH_NativeWindow_NativeWindowHandleOpt(native_window, code, stride); if (ret) { LOGE( "Set NativeWindow stride Failed :window:%{public}p ,w:%{public}d x " "%{public}d:%{public}d", - nativeWindow, width, height, ret); + native_window, width, height, ret); } // Set the format of the native window buffer. code = SET_FORMAT; int32_t format = PIXEL_FMT_RGBA_8888; - ret = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, format); + ret = OH_NativeWindow_NativeWindowHandleOpt(native_window, code, format); if (ret) { LOGE( "Set NativeWindow PIXEL_FMT_RGBA_8888 Failed :window:%{public}p " ",w:%{public}d x %{public}d:%{public}d", - nativeWindow, width, height, ret); + native_window, width, height, ret); } return ret; } void OnSurfaceCreatedCB(OH_NativeXComponent* component, void* window) { - for(auto it: XComponentAdapter::GetInstance()->xcomponetMap_) - { - if(it.second->nativeXComponent_ == component) { + for (auto it : XComponentAdapter::GetInstance()->xcomponent_map()) { + if (it.second->native_xcomponent() == component) { it.second->OnSurfaceCreated(component, window); } } } void OnSurfaceChangedCB(OH_NativeXComponent* component, void* window) { - for(auto it: XComponentAdapter::GetInstance()->xcomponetMap_) - { - if(it.second->nativeXComponent_ == component) { + for (auto it : XComponentAdapter::GetInstance()->xcomponent_map()) { + if (it.second->native_xcomponent() == component) { it.second->OnSurfaceChanged(component, window); } } } void OnSurfaceDestroyedCB(OH_NativeXComponent* component, void* window) { - for(auto it = XComponentAdapter::GetInstance()->xcomponetMap_.begin(); - it != XComponentAdapter::GetInstance()->xcomponetMap_.end();) - { - if(it->second->nativeXComponent_ == component) { + for (auto it = XComponentAdapter::GetInstance()->xcomponent_map().begin(); + it != XComponentAdapter::GetInstance()->xcomponent_map().end();) { + if (it->second->native_xcomponent() == component) { it->second->OnSurfaceDestroyed(component, window); delete it->second; - it = XComponentAdapter::GetInstance()->xcomponetMap_.erase(it); + it = XComponentAdapter::GetInstance()->xcomponent_map().erase(it); } else { ++it; } } - } + void DispatchTouchEventCB(OH_NativeXComponent* component, void* window) { - for(auto it: XComponentAdapter::GetInstance()->xcomponetMap_) - { - if(it.second->nativeXComponent_ == component) { + for (auto it : XComponentAdapter::GetInstance()->xcomponent_map()) { + if (it.second->native_xcomponent() == component) { it.second->OnDispatchTouchEvent(component, window); } } @@ -239,22 +239,22 @@ void XComponentBase::BindXComponentCallback() { callback_.DispatchTouchEvent = DispatchTouchEventCB; } -XComponentBase::XComponentBase(std::string id){ +XComponentBase::XComponentBase(const std::string& id) { id_ = id; isEngineAttached_ = false; } XComponentBase::~XComponentBase() {} -void XComponentBase::AttachFlutterEngine(std::string shellholderId) { +void XComponentBase::AttachFlutterEngine(const std::string& shell_holder_id) { LOGD( "XComponentManger::AttachFlutterEngine xcomponentId:%{public}s, " - "shellholderId:%{public}s", - id_.c_str(), shellholderId.c_str()); - shellholderId_ = shellholderId; + "shell_holder_id:%{public}s", + id_.c_str(), shell_holder_id.c_str()); + shell_holder_id_ = shell_holder_id; isEngineAttached_ = true; if (window_ != nullptr) { - PlatformViewOHOSNapi::SurfaceCreated(std::stoll(shellholderId_), window_); + PlatformViewOHOSNapi::SurfaceCreated(std::stoll(shell_holder_id_), window_); } else { LOGE("OnSurfaceCreated XComponentBase is not attached"); } @@ -263,22 +263,23 @@ void XComponentBase::AttachFlutterEngine(std::string shellholderId) { void XComponentBase::DetachFlutterEngine() { LOGD( "XComponentManger::DetachFlutterEngine xcomponentId:%{public}s, " - "shellholderId:%{public}s", - id_.c_str(), shellholderId_.c_str()); + "shell_holder_id:%{public}s", + id_.c_str(), shell_holder_id_.c_str()); if (window_ != nullptr) { - PlatformViewOHOSNapi::SurfaceDestroyed(std::stoll(shellholderId_)); + PlatformViewOHOSNapi::SurfaceDestroyed(std::stoll(shell_holder_id_)); } else { LOGE("DetachFlutterEngine XComponentBase is not attached"); } - shellholderId_ = ""; + shell_holder_id_ = ""; isEngineAttached_ = false; } -void XComponentBase::SetNativeXComponent(OH_NativeXComponent* nativeXComponent){ - nativeXComponent_ = nativeXComponent; - if (nativeXComponent_ != nullptr) { +void XComponentBase::SetNativeXComponent( + OH_NativeXComponent* native_xcomponent) { + native_xcomponent_ = native_xcomponent; + if (native_xcomponent_ != nullptr) { BindXComponentCallback(); - OH_NativeXComponent_RegisterCallback(nativeXComponent_, &callback_); + OH_NativeXComponent_RegisterCallback(native_xcomponent_, &callback_); } } @@ -288,7 +289,7 @@ void XComponentBase::OnSurfaceCreated(OH_NativeXComponent* component, "XComponentManger::OnSurfaceCreated window = %{public}p component = " "%{public}p", window, component); - window_ = window; + window_ = window; int32_t ret = OH_NativeXComponent_GetXComponentSize(component, window, &width_, &height_); if (ret == OH_NATIVEXCOMPONENT_RESULT_SUCCESS) { @@ -305,14 +306,14 @@ void XComponentBase::OnSurfaceCreated(OH_NativeXComponent* component, LOGD("SetNativeWindowOpt failed:%{public}d", ret); } if (isEngineAttached_) { - PlatformViewOHOSNapi::SurfaceCreated(std::stoll(shellholderId_), window); + PlatformViewOHOSNapi::SurfaceCreated(std::stoll(shell_holder_id_), window); } else { LOGE("OnSurfaceCreated XComponentBase is not attached"); } } -void XComponentBase::OnSurfaceChanged(OH_NativeXComponent* component, void* window) -{ +void XComponentBase::OnSurfaceChanged(OH_NativeXComponent* component, + void* window) { LOGD("XComponentManger::OnSurfaceChanged "); int32_t ret = OH_NativeXComponent_GetXComponentSize(component, window, &width_, &height_); @@ -321,7 +322,7 @@ void XComponentBase::OnSurfaceChanged(OH_NativeXComponent* component, void* wind static_cast(width_), static_cast(height_)); } if (isEngineAttached_) { - PlatformViewOHOSNapi::SurfaceChanged(std::stoll(shellholderId_), width_, + PlatformViewOHOSNapi::SurfaceChanged(std::stoll(shell_holder_id_), width_, height_); } else { LOGE("OnSurfaceChanged XComponentBase is not attached"); @@ -333,7 +334,7 @@ void XComponentBase::OnSurfaceDestroyed(OH_NativeXComponent* component, window_ = nullptr; LOGD("XComponentManger::OnSurfaceDestroyed"); if (isEngineAttached_) { - PlatformViewOHOSNapi::SurfaceDestroyed(std::stoll(shellholderId_)); + PlatformViewOHOSNapi::SurfaceDestroyed(std::stoll(shell_holder_id_)); } else { LOGE("OnSurfaceCreated OnSurfaceDestroyed is not attached"); } @@ -343,12 +344,12 @@ void XComponentBase::OnDispatchTouchEvent(OH_NativeXComponent* component, void* window) { LOGD("XComponentManger::DispatchTouchEvent"); int32_t ret = - OH_NativeXComponent_GetTouchEvent(component, window, &touchEvent_); + OH_NativeXComponent_GetTouchEvent(component, window, &touch_event_); if (ret == OH_NATIVEXCOMPONENT_RESULT_SUCCESS) { if (isEngineAttached_) { - LOGD("XComponentManger::HandleTouchEvent"); - ohosTouchProcessor_.HandleTouchEvent(std::stoll(shellholderId_), - component, &touchEvent_); + LOGD("XComponentManger::HandleTouchEvent"); + ohos_touch_processor_.HandleTouchEvent(std::stoll(shell_holder_id_), + component, &touch_event_); } else { LOGE( "XComponentManger::DispatchTouchEvent XComponentBase is not " diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.h b/shell/platform/ohos/ohos_xcomponent_adapter.h index 4fd6ff4990..4533ca581d 100644 --- a/shell/platform/ohos/ohos_xcomponent_adapter.h +++ b/shell/platform/ohos/ohos_xcomponent_adapter.h @@ -13,28 +13,27 @@ * limitations under the License. */ -#ifndef OHOS_XCOMPONENT_ADAPTER_H -#define OHOS_XCOMPONENT_ADAPTER_H +#ifndef PLATFORM_OHOS_OHOS_XCOMPONENT_ADAPTER_H +#define PLATFORM_OHOS_OHOS_XCOMPONENT_ADAPTER_H + #include +#include #include + #include "flutter/shell/platform/ohos/ohos_touch_processor.h" #include "napi/native_api.h" #include "napi_common.h" -#include + namespace flutter { -class XComponentBase -{ -private: - void BindXComponentCallback(); - -public: - XComponentBase(std::string id); +class XComponentBase { + public: + explicit XComponentBase(const std::string& id); ~XComponentBase(); - void AttachFlutterEngine(std::string shellholderId); + void AttachFlutterEngine(const std::string& shell_holder_id); void DetachFlutterEngine(); - void SetNativeXComponent(OH_NativeXComponent* nativeXComponent); + void SetNativeXComponent(OH_NativeXComponent* native_xcomponent); // Callback, called by ACE XComponent void OnSurfaceCreated(OH_NativeXComponent* component, void* window); @@ -42,38 +41,48 @@ public: void OnSurfaceDestroyed(OH_NativeXComponent* component, void* window); void OnDispatchTouchEvent(OH_NativeXComponent* component, void* window); - OH_NativeXComponent_TouchEvent touchEvent_; + OH_NativeXComponent* native_xcomponent() const { return native_xcomponent_; } + + private: + void BindXComponentCallback(); + + OH_NativeXComponent_TouchEvent touch_event_; OH_NativeXComponent_Callback callback_; std::string id_; - std::string shellholderId_; + std::string shell_holder_id_; bool isEngineAttached_; - bool isWindowAttached_; - OH_NativeXComponent* nativeXComponent_; + OH_NativeXComponent* native_xcomponent_; void* window_; uint64_t width_; uint64_t height_; - OhosTouchProcessor ohosTouchProcessor_; - + OhosTouchProcessor ohos_touch_processor_; }; +using XComponentBaseMap = std::map; class XComponentAdapter { public: - XComponentAdapter(/* args */); - ~XComponentAdapter(); static XComponentAdapter* GetInstance(); + + // Forbid copy and assign + XComponentAdapter(const XComponentAdapter&) = delete; + XComponentAdapter& operator=(const XComponentAdapter&) = delete; + bool Export(napi_env env, napi_value exports); - void SetNativeXComponent(std::string& id, - OH_NativeXComponent* nativeXComponent); - void AttachFlutterEngine(std::string& id, std::string& shellholderId); - void DetachFlutterEngine(std::string& id); + void SetNativeXComponent(const std::string& id, + OH_NativeXComponent* native_xcomponent); + void AttachFlutterEngine(const std::string& id, + const std::string& shell_holder_id); + void DetachFlutterEngine(const std::string& id); - public: - std::map xcomponetMap_; + XComponentBaseMap& xcomponent_map() { return xcomponent_map_; } private: - static XComponentAdapter mXComponentAdapter; + XComponentAdapter(); + ~XComponentAdapter(); + + XComponentBaseMap xcomponent_map_; }; } // namespace flutter -#endif \ No newline at end of file +#endif // PLATFORM_OHOS_OHOS_XCOMPONENT_ADAPTER_H \ No newline at end of file -- Gitee From a2beab2214b92911f85e7f181a3d80723f18f29c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rulong=20Chen=EF=BC=88=E9=99=88=E6=B1=9D=E9=BE=99=EF=BC=89?= Date: Sat, 9 Mar 2024 04:15:53 +0000 Subject: [PATCH 02/13] update shell/platform/ohos/ohos_xcomponent_adapter.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rulong Chen(陈汝龙) --- .../platform/ohos/ohos_xcomponent_adapter.cpp | 559 +++++++++--------- 1 file changed, 289 insertions(+), 270 deletions(-) diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.cpp b/shell/platform/ohos/ohos_xcomponent_adapter.cpp index 6673f425de..82c67548d8 100644 --- a/shell/platform/ohos/ohos_xcomponent_adapter.cpp +++ b/shell/platform/ohos/ohos_xcomponent_adapter.cpp @@ -26,336 +26,355 @@ XComponentAdapter::XComponentAdapter() {} XComponentAdapter::~XComponentAdapter() {} -XComponentAdapter* XComponentAdapter::GetInstance() { - static XComponentAdapter* instance = new XComponentAdapter; - return instance; +XComponentAdapter* XComponentAdapter::GetInstance() +{ + static XComponentAdapter* instance = new XComponentAdapter; + return instance; } -bool XComponentAdapter::Export(napi_env env, napi_value exports) { - napi_status status; - napi_value export_instance = nullptr; - OH_NativeXComponent* native_xcomponent = nullptr; - int32_t ret; - char id_str[OH_XCOMPONENT_ID_LEN_MAX + 1] = {}; - uint64_t id_size = OH_XCOMPONENT_ID_LEN_MAX + 1; - - status = napi_get_named_property(env, exports, OH_NATIVE_XCOMPONENT_OBJ, - &export_instance); - LOGD("napi_get_named_property,status = %{public}d", status); - if (status != napi_ok) { - return false; - } +bool XComponentAdapter::Export(napi_env env, napi_value exports) +{ + napi_status status; + napi_value export_instance = nullptr; + OH_NativeXComponent* native_xcomponent = nullptr; + int32_t ret; + char id_str[OH_XCOMPONENT_ID_LEN_MAX + 1] = {}; + uint64_t id_size = OH_XCOMPONENT_ID_LEN_MAX + 1; + + status = napi_get_named_property(env, exports, OH_NATIVE_XCOMPONENT_OBJ, + &export_instance); + LOGD("napi_get_named_property,status = %{public}d", status); + if (status != napi_ok) { + return false; + } - status = napi_unwrap(env, export_instance, - reinterpret_cast(&native_xcomponent)); - LOGD("napi_unwrap,status = %{public}d", status); - if (status != napi_ok) { - return false; - } + status = napi_unwrap(env, export_instance, + reinterpret_cast(&native_xcomponent)); + LOGD("napi_unwrap,status = %{public}d", status); + if (status != napi_ok) { + return false; + } + + ret = + OH_NativeXComponent_GetXComponentId(native_xcomponent, id_str, &id_size); + LOGD("NativeXComponent id:%{public}s", id_str); + if (ret != OH_NATIVEXCOMPONENT_RESULT_SUCCESS) { + return false; + } + std::string id(id_str); + auto context = XComponentAdapter::GetInstance(); + if (context) { + context->SetNativeXComponent(id, native_xcomponent); + return true; + } - ret = - OH_NativeXComponent_GetXComponentId(native_xcomponent, id_str, &id_size); - LOGD("NativeXComponent id:%{public}s", id_str); - if (ret != OH_NATIVEXCOMPONENT_RESULT_SUCCESS) { return false; - } - std::string id(id_str); - auto context = XComponentAdapter::GetInstance(); - if (context) { - context->SetNativeXComponent(id, native_xcomponent); - return true; - } - - return false; } void XComponentAdapter::SetNativeXComponent( const std::string& id, - OH_NativeXComponent* native_xcomponent) { - auto iter = xcomponent_map_.find(id); - if (iter == xcomponent_map_.end()) { - XComponentBase* xcomponet = new XComponentBase(id); - xcomponent_map_[id] = xcomponet; - } - - iter = xcomponent_map_.find(id); - if (iter != xcomponent_map_.end()) { - iter->second->SetNativeXComponent(native_xcomponent); - } + OH_NativeXComponent* native_xcomponent) +{ + auto iter = xcomponent_map_.find(id); + if (iter == xcomponent_map_.end()) { + XComponentBase* xcomponet = new XComponentBase(id); + xcomponent_map_[id] = xcomponet; + } + + iter = xcomponent_map_.find(id); + if (iter != xcomponent_map_.end()) { + iter->second->SetNativeXComponent(native_xcomponent); + } } void XComponentAdapter::AttachFlutterEngine( const std::string& id, - const std::string& shell_holder_id) { - auto iter = xcomponent_map_.find(id); - if (iter == xcomponent_map_.end()) { - XComponentBase* xcomponet = new XComponentBase(id); - xcomponent_map_[id] = xcomponet; - } - - auto findIter = xcomponent_map_.find(id); - if (findIter != xcomponent_map_.end()) { - findIter->second->AttachFlutterEngine(shell_holder_id); - } + const std::string& shell_holder_id) +{ + auto iter = xcomponent_map_.find(id); + if (iter == xcomponent_map_.end()) { + XComponentBase* xcomponet = new XComponentBase(id); + xcomponent_map_[id] = xcomponet; + } + + auto findIter = xcomponent_map_.find(id); + if (findIter != xcomponent_map_.end()) { + findIter->second->AttachFlutterEngine(shell_holder_id); + } } -void XComponentAdapter::DetachFlutterEngine(const std::string& id) { - auto iter = xcomponent_map_.find(id); - if (iter != xcomponent_map_.end()) { - iter->second->DetachFlutterEngine(); - } +void XComponentAdapter::DetachFlutterEngine(const std::string& id) +{ + auto iter = xcomponent_map_.find(id); + if (iter != xcomponent_map_.end()) { + iter->second->DetachFlutterEngine(); + } } #include using OHOS_SurfaceBufferUsage = enum { - BUFFER_USAGE_CPU_READ = (1ULL << 0), /**< CPU read buffer */ - BUFFER_USAGE_CPU_WRITE = (1ULL << 1), /**< CPU write memory */ - BUFFER_USAGE_MEM_MMZ = (1ULL << 2), /**< Media memory zone (MMZ) */ - BUFFER_USAGE_MEM_DMA = (1ULL << 3), /**< Direct memory access (DMA) buffer */ - BUFFER_USAGE_MEM_SHARE = (1ULL << 4), /**< Shared memory buffer*/ - BUFFER_USAGE_MEM_MMZ_CACHE = (1ULL << 5), /**< MMZ with cache*/ - BUFFER_USAGE_MEM_FB = (1ULL << 6), /**< Framebuffer */ - BUFFER_USAGE_ASSIGN_SIZE = (1ULL << 7), /**< Memory assigned */ - BUFFER_USAGE_HW_RENDER = (1ULL << 8), /**< For GPU write case */ - BUFFER_USAGE_HW_TEXTURE = (1ULL << 9), /**< For GPU read case */ - BUFFER_USAGE_HW_COMPOSER = (1ULL << 10), /**< For hardware composer */ - BUFFER_USAGE_PROTECTED = - (1ULL << 11), /**< For safe buffer case, such as DRM */ - BUFFER_USAGE_CAMERA_READ = (1ULL << 12), /**< For camera read case */ - BUFFER_USAGE_CAMERA_WRITE = (1ULL << 13), /**< For camera write case */ - BUFFER_USAGE_VIDEO_ENCODER = (1ULL << 14), /**< For encode case */ - BUFFER_USAGE_VIDEO_DECODER = (1ULL << 15), /**< For decode case */ - BUFFER_USAGE_VENDOR_PRI0 = (1ULL << 44), /**< Reserverd for vendor */ - BUFFER_USAGE_VENDOR_PRI1 = (1ULL << 45), /**< Reserverd for vendor */ - BUFFER_USAGE_VENDOR_PRI2 = (1ULL << 46), /**< Reserverd for vendor */ - BUFFER_USAGE_VENDOR_PRI3 = (1ULL << 47), /**< Reserverd for vendor */ - BUFFER_USAGE_VENDOR_PRI4 = (1ULL << 48), /**< Reserverd for vendor */ - BUFFER_USAGE_VENDOR_PRI5 = (1ULL << 49), /**< Reserverd for vendor */ - BUFFER_USAGE_VENDOR_PRI6 = (1ULL << 50), /**< Reserverd for vendor */ - BUFFER_USAGE_VENDOR_PRI7 = (1ULL << 51), /**< Reserverd for vendor */ - BUFFER_USAGE_VENDOR_PRI8 = (1ULL << 52), /**< Reserverd for vendor */ - BUFFER_USAGE_VENDOR_PRI9 = (1ULL << 53), /**< Reserverd for vendor */ - BUFFER_USAGE_VENDOR_PRI10 = (1ULL << 54), /**< Reserverd for vendor */ - BUFFER_USAGE_VENDOR_PRI11 = (1ULL << 55), /**< Reserverd for vendor */ - BUFFER_USAGE_VENDOR_PRI12 = (1ULL << 56), /**< Reserverd for vendor */ - BUFFER_USAGE_VENDOR_PRI13 = (1ULL << 57), /**< Reserverd for vendor */ - BUFFER_USAGE_VENDOR_PRI14 = (1ULL << 58), /**< Reserverd for vendor */ - BUFFER_USAGE_VENDOR_PRI15 = (1ULL << 59), /**< Reserverd for vendor */ - BUFFER_USAGE_VENDOR_PRI16 = (1ULL << 60), /**< Reserverd for vendor */ - BUFFER_USAGE_VENDOR_PRI17 = (1ULL << 61), /**< Reserverd for vendor */ - BUFFER_USAGE_VENDOR_PRI18 = (1ULL << 62), /**< Reserverd for vendor */ - BUFFER_USAGE_VENDOR_PRI19 = (1ULL << 63), /**< Reserverd for vendor */ + BUFFER_USAGE_CPU_READ = (1ULL << 0), /**< CPU read buffer */ + BUFFER_USAGE_CPU_WRITE = (1ULL << 1), /**< CPU write memory */ + BUFFER_USAGE_MEM_MMZ = (1ULL << 2), /**< Media memory zone (MMZ) */ + BUFFER_USAGE_MEM_DMA = (1ULL << 3), /**< Direct memory access (DMA) buffer */ + BUFFER_USAGE_MEM_SHARE = (1ULL << 4), /**< Shared memory buffer*/ + BUFFER_USAGE_MEM_MMZ_CACHE = (1ULL << 5), /**< MMZ with cache*/ + BUFFER_USAGE_MEM_FB = (1ULL << 6), /**< Framebuffer */ + BUFFER_USAGE_ASSIGN_SIZE = (1ULL << 7), /**< Memory assigned */ + BUFFER_USAGE_HW_RENDER = (1ULL << 8), /**< For GPU write case */ + BUFFER_USAGE_HW_TEXTURE = (1ULL << 9), /**< For GPU read case */ + BUFFER_USAGE_HW_COMPOSER = (1ULL << 10), /**< For hardware composer */ + BUFFER_USAGE_PROTECTED = + (1ULL << 11), /**< For safe buffer case, such as DRM */ + BUFFER_USAGE_CAMERA_READ = (1ULL << 12), /**< For camera read case */ + BUFFER_USAGE_CAMERA_WRITE = (1ULL << 13), /**< For camera write case */ + BUFFER_USAGE_VIDEO_ENCODER = (1ULL << 14), /**< For encode case */ + BUFFER_USAGE_VIDEO_DECODER = (1ULL << 15), /**< For decode case */ + BUFFER_USAGE_VENDOR_PRI0 = (1ULL << 44), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI1 = (1ULL << 45), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI2 = (1ULL << 46), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI3 = (1ULL << 47), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI4 = (1ULL << 48), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI5 = (1ULL << 49), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI6 = (1ULL << 50), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI7 = (1ULL << 51), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI8 = (1ULL << 52), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI9 = (1ULL << 53), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI10 = (1ULL << 54), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI11 = (1ULL << 55), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI12 = (1ULL << 56), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI13 = (1ULL << 57), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI14 = (1ULL << 58), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI15 = (1ULL << 59), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI16 = (1ULL << 60), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI17 = (1ULL << 61), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI18 = (1ULL << 62), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI19 = (1ULL << 63), /**< Reserverd for vendor */ }; static int32_t SetNativeWindowOpt(OHNativeWindow* native_window, int32_t width, - int height) { - // Set the read and write scenarios of the native window buffer. - int code = SET_USAGE; - int32_t usage = - BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA; - int32_t ret = - OH_NativeWindow_NativeWindowHandleOpt(native_window, code, usage); - if (ret) { - LOGE( - "Set NativeWindow Usage Failed :window:%{public}p ,w:%{public}d x " - "%{public}d:%{public}d", - native_window, width, height, ret); - } - // Set the width and height of the native window buffer. - code = SET_BUFFER_GEOMETRY; - ret = - OH_NativeWindow_NativeWindowHandleOpt(native_window, code, width, height); - if (ret) { - LOGE( - "Set NativeWindow GEOMETRY Failed :window:%{public}p ,w:%{public}d x " - "%{public}d:%{public}d", - native_window, width, height, ret); - } - // Set the step of the native window buffer. - code = SET_STRIDE; - int32_t stride = 0x8; - ret = OH_NativeWindow_NativeWindowHandleOpt(native_window, code, stride); - if (ret) { - LOGE( - "Set NativeWindow stride Failed :window:%{public}p ,w:%{public}d x " - "%{public}d:%{public}d", - native_window, width, height, ret); - } - // Set the format of the native window buffer. - code = SET_FORMAT; - int32_t format = PIXEL_FMT_RGBA_8888; - - ret = OH_NativeWindow_NativeWindowHandleOpt(native_window, code, format); - if (ret) { - LOGE( - "Set NativeWindow PIXEL_FMT_RGBA_8888 Failed :window:%{public}p " - ",w:%{public}d x %{public}d:%{public}d", - native_window, width, height, ret); - } - return ret; + int height) +{ + // Set the read and write scenarios of the native window buffer. + int code = SET_USAGE; + int32_t usage = + BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA; + int32_t ret = + OH_NativeWindow_NativeWindowHandleOpt(native_window, code, usage); + if (ret) { + LOGE( + "Set NativeWindow Usage Failed :window:%{public}p ,w:%{public}d x " + "%{public}d:%{public}d", + native_window, width, height, ret); + } + // Set the width and height of the native window buffer. + code = SET_BUFFER_GEOMETRY; + ret = + OH_NativeWindow_NativeWindowHandleOpt(native_window, code, width, height); + if (ret) { + LOGE( + "Set NativeWindow GEOMETRY Failed :window:%{public}p ,w:%{public}d x " + "%{public}d:%{public}d", + native_window, width, height, ret); + } + // Set the step of the native window buffer. + code = SET_STRIDE; + int32_t stride = 0x8; + ret = OH_NativeWindow_NativeWindowHandleOpt(native_window, code, stride); + if (ret) { + LOGE( + "Set NativeWindow stride Failed :window:%{public}p ,w:%{public}d x " + "%{public}d:%{public}d", + native_window, width, height, ret); + } + // Set the format of the native window buffer. + code = SET_FORMAT; + int32_t format = PIXEL_FMT_RGBA_8888; + + ret = OH_NativeWindow_NativeWindowHandleOpt(native_window, code, format); + if (ret) { + LOGE( + "Set NativeWindow PIXEL_FMT_RGBA_8888 Failed :window:%{public}p " + ",w:%{public}d x %{public}d:%{public}d", + native_window, width, height, ret); + } + return ret; } -void OnSurfaceCreatedCB(OH_NativeXComponent* component, void* window) { - for (auto it : XComponentAdapter::GetInstance()->xcomponent_map()) { - if (it.second->native_xcomponent() == component) { - it.second->OnSurfaceCreated(component, window); +void OnSurfaceCreatedCB(OH_NativeXComponent* component, void* window) +{ + for (auto it : XComponentAdapter::GetInstance()->xcomponent_map()) { + if (it.second->native_xcomponent() == component) { + it.second->OnSurfaceCreated(component, window); + } } - } } -void OnSurfaceChangedCB(OH_NativeXComponent* component, void* window) { - for (auto it : XComponentAdapter::GetInstance()->xcomponent_map()) { - if (it.second->native_xcomponent() == component) { - it.second->OnSurfaceChanged(component, window); +void OnSurfaceChangedCB(OH_NativeXComponent* component, void* window) +{ + for (auto it : XComponentAdapter::GetInstance()->xcomponent_map()) { + if (it.second->native_xcomponent() == component) { + it.second->OnSurfaceChanged(component, window); + } } - } } -void OnSurfaceDestroyedCB(OH_NativeXComponent* component, void* window) { - for (auto it = XComponentAdapter::GetInstance()->xcomponent_map().begin(); - it != XComponentAdapter::GetInstance()->xcomponent_map().end();) { - if (it->second->native_xcomponent() == component) { - it->second->OnSurfaceDestroyed(component, window); - delete it->second; - it = XComponentAdapter::GetInstance()->xcomponent_map().erase(it); - } else { - ++it; +void OnSurfaceDestroyedCB(OH_NativeXComponent* component, void* window) +{ + for (auto it = XComponentAdapter::GetInstance()->xcomponent_map().begin(); + it != XComponentAdapter::GetInstance()->xcomponent_map().end();) { + if (it->second->native_xcomponent() == component) { + it->second->OnSurfaceDestroyed(component, window); + delete it->second; + it = XComponentAdapter::GetInstance()->xcomponent_map().erase(it); + } else { + ++it; + } } - } } -void DispatchTouchEventCB(OH_NativeXComponent* component, void* window) { - for (auto it : XComponentAdapter::GetInstance()->xcomponent_map()) { - if (it.second->native_xcomponent() == component) { - it.second->OnDispatchTouchEvent(component, window); +void DispatchTouchEventCB(OH_NativeXComponent* component, void* window) +{ + for (auto it : XComponentAdapter::GetInstance()->xcomponent_map()) { + if (it.second->native_xcomponent() == component) { + it.second->OnDispatchTouchEvent(component, window); + } } - } } -void XComponentBase::BindXComponentCallback() { - callback_.OnSurfaceCreated = OnSurfaceCreatedCB; - callback_.OnSurfaceChanged = OnSurfaceChangedCB; - callback_.OnSurfaceDestroyed = OnSurfaceDestroyedCB; - callback_.DispatchTouchEvent = DispatchTouchEventCB; +void XComponentBase::BindXComponentCallback() +{ + callback_.OnSurfaceCreated = OnSurfaceCreatedCB; + callback_.OnSurfaceChanged = OnSurfaceChangedCB; + callback_.OnSurfaceDestroyed = OnSurfaceDestroyedCB; + callback_.DispatchTouchEvent = DispatchTouchEventCB; } -XComponentBase::XComponentBase(const std::string& id) { - id_ = id; - isEngineAttached_ = false; +XComponentBase::XComponentBase(const std::string& id) +{ + id_ = id; + isEngineAttached_ = false; } XComponentBase::~XComponentBase() {} -void XComponentBase::AttachFlutterEngine(const std::string& shell_holder_id) { - LOGD( - "XComponentManger::AttachFlutterEngine xcomponentId:%{public}s, " - "shell_holder_id:%{public}s", - id_.c_str(), shell_holder_id.c_str()); - shell_holder_id_ = shell_holder_id; - isEngineAttached_ = true; - if (window_ != nullptr) { - PlatformViewOHOSNapi::SurfaceCreated(std::stoll(shell_holder_id_), window_); - } else { - LOGE("OnSurfaceCreated XComponentBase is not attached"); - } +void XComponentBase::AttachFlutterEngine(const std::string& shell_holder_id) +{ + LOGD( + "XComponentManger::AttachFlutterEngine xcomponentId:%{public}s, " + "shell_holder_id:%{public}s", + id_.c_str(), shell_holder_id.c_str()); + shell_holder_id_ = shell_holder_id; + isEngineAttached_ = true; + if (window_ != nullptr) { + PlatformViewOHOSNapi::SurfaceCreated(std::stoll(shell_holder_id_), window_); + } else { + LOGE("OnSurfaceCreated XComponentBase is not attached"); + } } -void XComponentBase::DetachFlutterEngine() { - LOGD( - "XComponentManger::DetachFlutterEngine xcomponentId:%{public}s, " - "shell_holder_id:%{public}s", - id_.c_str(), shell_holder_id_.c_str()); - if (window_ != nullptr) { - PlatformViewOHOSNapi::SurfaceDestroyed(std::stoll(shell_holder_id_)); - } else { - LOGE("DetachFlutterEngine XComponentBase is not attached"); - } - shell_holder_id_ = ""; - isEngineAttached_ = false; +void XComponentBase::DetachFlutterEngine() +{ + LOGD( + "XComponentManger::DetachFlutterEngine xcomponentId:%{public}s, " + "shell_holder_id:%{public}s", + id_.c_str(), shell_holder_id_.c_str()); + if (window_ != nullptr) { + PlatformViewOHOSNapi::SurfaceDestroyed(std::stoll(shell_holder_id_)); + } else { + LOGE("DetachFlutterEngine XComponentBase is not attached"); + } + shell_holder_id_ = ""; + isEngineAttached_ = false; } void XComponentBase::SetNativeXComponent( - OH_NativeXComponent* native_xcomponent) { - native_xcomponent_ = native_xcomponent; - if (native_xcomponent_ != nullptr) { - BindXComponentCallback(); - OH_NativeXComponent_RegisterCallback(native_xcomponent_, &callback_); - } + OH_NativeXComponent* native_xcomponent) +{ + native_xcomponent_ = native_xcomponent; + if (native_xcomponent_ != nullptr) { + BindXComponentCallback(); + OH_NativeXComponent_RegisterCallback(native_xcomponent_, &callback_); + } } void XComponentBase::OnSurfaceCreated(OH_NativeXComponent* component, - void* window) { - LOGD( - "XComponentManger::OnSurfaceCreated window = %{public}p component = " - "%{public}p", - window, component); - window_ = window; - int32_t ret = OH_NativeXComponent_GetXComponentSize(component, window, - &width_, &height_); - if (ret == OH_NATIVEXCOMPONENT_RESULT_SUCCESS) { - LOGD("XComponent Current width:%{public}d,height:%{public}d", - static_cast(width_), static_cast(height_)); - } else { - LOGE("GetXComponentSize result:%{public}d", ret); - } - - LOGD("OnSurfaceCreated,window.size:%{public}d,%{public}d", (int)width_, - (int)height_); - ret = SetNativeWindowOpt((OHNativeWindow*)window, width_, height_); - if (ret) { - LOGD("SetNativeWindowOpt failed:%{public}d", ret); - } - if (isEngineAttached_) { - PlatformViewOHOSNapi::SurfaceCreated(std::stoll(shell_holder_id_), window); - } else { - LOGE("OnSurfaceCreated XComponentBase is not attached"); - } + void* window) +{ + LOGD( + "XComponentManger::OnSurfaceCreated window = %{public}p component = " + "%{public}p", + window, component); + window_ = window; + int32_t ret = OH_NativeXComponent_GetXComponentSize(component, window, + &width_, &height_); + if (ret == OH_NATIVEXCOMPONENT_RESULT_SUCCESS) { + LOGD("XComponent Current width:%{public}d,height:%{public}d", + static_cast(width_), static_cast(height_)); + } else { + LOGE("GetXComponentSize result:%{public}d", ret); + } + + LOGD("OnSurfaceCreated,window.size:%{public}d,%{public}d", (int)width_, + (int)height_); + ret = SetNativeWindowOpt((OHNativeWindow*)window, width_, height_); + if (ret) { + LOGD("SetNativeWindowOpt failed:%{public}d", ret); + } + if (isEngineAttached_) { + PlatformViewOHOSNapi::SurfaceCreated(std::stoll(shell_holder_id_), window); + } else { + LOGE("OnSurfaceCreated XComponentBase is not attached"); + } } void XComponentBase::OnSurfaceChanged(OH_NativeXComponent* component, - void* window) { - LOGD("XComponentManger::OnSurfaceChanged "); - int32_t ret = OH_NativeXComponent_GetXComponentSize(component, window, - &width_, &height_); - if (ret == OH_NATIVEXCOMPONENT_RESULT_SUCCESS) { - LOGD("XComponent Current width:%{public}d,height:%{public}d", - static_cast(width_), static_cast(height_)); - } - if (isEngineAttached_) { - PlatformViewOHOSNapi::SurfaceChanged(std::stoll(shell_holder_id_), width_, - height_); - } else { - LOGE("OnSurfaceChanged XComponentBase is not attached"); - } + void* window) +{ + LOGD("XComponentManger::OnSurfaceChanged "); + int32_t ret = OH_NativeXComponent_GetXComponentSize(component, window, + &width_, &height_); + if (ret == OH_NATIVEXCOMPONENT_RESULT_SUCCESS) { + LOGD("XComponent Current width:%{public}d,height:%{public}d", + static_cast(width_), static_cast(height_)); + } + if (isEngineAttached_) { + PlatformViewOHOSNapi::SurfaceChanged(std::stoll(shell_holder_id_), width_, + height_); + } else { + LOGE("OnSurfaceChanged XComponentBase is not attached"); + } } void XComponentBase::OnSurfaceDestroyed(OH_NativeXComponent* component, - void* window) { - window_ = nullptr; - LOGD("XComponentManger::OnSurfaceDestroyed"); - if (isEngineAttached_) { - PlatformViewOHOSNapi::SurfaceDestroyed(std::stoll(shell_holder_id_)); - } else { - LOGE("OnSurfaceCreated OnSurfaceDestroyed is not attached"); - } + void* window) +{ + window_ = nullptr; + LOGD("XComponentManger::OnSurfaceDestroyed"); + if (isEngineAttached_) { + PlatformViewOHOSNapi::SurfaceDestroyed(std::stoll(shell_holder_id_)); + } else { + LOGE("OnSurfaceCreated OnSurfaceDestroyed is not attached"); + } } void XComponentBase::OnDispatchTouchEvent(OH_NativeXComponent* component, - void* window) { - LOGD("XComponentManger::DispatchTouchEvent"); - int32_t ret = - OH_NativeXComponent_GetTouchEvent(component, window, &touch_event_); - if (ret == OH_NATIVEXCOMPONENT_RESULT_SUCCESS) { - if (isEngineAttached_) { - LOGD("XComponentManger::HandleTouchEvent"); - ohos_touch_processor_.HandleTouchEvent(std::stoll(shell_holder_id_), - component, &touch_event_); - } else { - LOGE( - "XComponentManger::DispatchTouchEvent XComponentBase is not " - "attached"); + void* window) +{ + LOGD("XComponentManger::DispatchTouchEvent"); + int32_t ret = + OH_NativeXComponent_GetTouchEvent(component, window, &touch_event_); + if (ret == OH_NATIVEXCOMPONENT_RESULT_SUCCESS) { + if (isEngineAttached_) { + LOGD("XComponentManger::HandleTouchEvent"); + ohos_touch_processor_.HandleTouchEvent(std::stoll(shell_holder_id_), + component, &touch_event_); + } else { + LOGE( + "XComponentManger::DispatchTouchEvent XComponentBase is not " + "attached"); + } } - } } } // namespace flutter \ No newline at end of file -- Gitee From 9c277144791909a30a6e88efddcb3e711cf89a1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rulong=20Chen=EF=BC=88=E9=99=88=E6=B1=9D=E9=BE=99=EF=BC=89?= Date: Sat, 9 Mar 2024 08:50:47 +0000 Subject: [PATCH 03/13] update shell/platform/ohos/ohos_xcomponent_adapter.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rulong Chen(陈汝龙) --- shell/platform/ohos/ohos_xcomponent_adapter.h | 74 +++++++++---------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.h b/shell/platform/ohos/ohos_xcomponent_adapter.h index 4533ca581d..12ee490fc0 100644 --- a/shell/platform/ohos/ohos_xcomponent_adapter.h +++ b/shell/platform/ohos/ohos_xcomponent_adapter.h @@ -28,59 +28,59 @@ namespace flutter { class XComponentBase { public: - explicit XComponentBase(const std::string& id); - ~XComponentBase(); + explicit XComponentBase(const std::string& id); + ~XComponentBase(); - void AttachFlutterEngine(const std::string& shell_holder_id); - void DetachFlutterEngine(); - void SetNativeXComponent(OH_NativeXComponent* native_xcomponent); + void AttachFlutterEngine(const std::string& shell_holder_id); + void DetachFlutterEngine(); + void SetNativeXComponent(OH_NativeXComponent* native_xcomponent); - // Callback, called by ACE XComponent - void OnSurfaceCreated(OH_NativeXComponent* component, void* window); - void OnSurfaceChanged(OH_NativeXComponent* component, void* window); - void OnSurfaceDestroyed(OH_NativeXComponent* component, void* window); - void OnDispatchTouchEvent(OH_NativeXComponent* component, void* window); + // Callback, called by ACE XComponent + void OnSurfaceCreated(OH_NativeXComponent* component, void* window); + void OnSurfaceChanged(OH_NativeXComponent* component, void* window); + void OnSurfaceDestroyed(OH_NativeXComponent* component, void* window); + void OnDispatchTouchEvent(OH_NativeXComponent* component, void* window); - OH_NativeXComponent* native_xcomponent() const { return native_xcomponent_; } + OH_NativeXComponent* native_xcomponent() const { return native_xcomponent_; } private: - void BindXComponentCallback(); - - OH_NativeXComponent_TouchEvent touch_event_; - OH_NativeXComponent_Callback callback_; - std::string id_; - std::string shell_holder_id_; - bool isEngineAttached_; - OH_NativeXComponent* native_xcomponent_; - void* window_; - uint64_t width_; - uint64_t height_; - OhosTouchProcessor ohos_touch_processor_; + void BindXComponentCallback(); + + OH_NativeXComponent_TouchEvent touch_event_; + OH_NativeXComponent_Callback callback_; + std::string id_; + std::string shell_holder_id_; + bool isEngineAttached_; + OH_NativeXComponent* native_xcomponent_; + void* window_; + uint64_t width_; + uint64_t height_; + OhosTouchProcessor ohos_touch_processor_; }; using XComponentBaseMap = std::map; class XComponentAdapter { public: - static XComponentAdapter* GetInstance(); + static XComponentAdapter* GetInstance(); - // Forbid copy and assign - XComponentAdapter(const XComponentAdapter&) = delete; - XComponentAdapter& operator=(const XComponentAdapter&) = delete; + // Forbid copy and assign + XComponentAdapter(const XComponentAdapter&) = delete; + XComponentAdapter& operator=(const XComponentAdapter&) = delete; - bool Export(napi_env env, napi_value exports); - void SetNativeXComponent(const std::string& id, - OH_NativeXComponent* native_xcomponent); - void AttachFlutterEngine(const std::string& id, - const std::string& shell_holder_id); - void DetachFlutterEngine(const std::string& id); + bool Export(napi_env env, napi_value exports); + void SetNativeXComponent(const std::string& id, + OH_NativeXComponent* native_xcomponent); + void AttachFlutterEngine(const std::string& id, + const std::string& shell_holder_id); + void DetachFlutterEngine(const std::string& id); - XComponentBaseMap& xcomponent_map() { return xcomponent_map_; } + XComponentBaseMap& xcomponent_map() { return xcomponent_map_; } private: - XComponentAdapter(); - ~XComponentAdapter(); + XComponentAdapter(); + ~XComponentAdapter(); - XComponentBaseMap xcomponent_map_; + XComponentBaseMap xcomponent_map_; }; } // namespace flutter -- Gitee From cdf95ec2627fbdb306de69cf4d43d336344afb96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rulong=20Chen=EF=BC=88=E9=99=88=E6=B1=9D=E9=BE=99=EF=BC=89?= Date: Sat, 9 Mar 2024 08:54:15 +0000 Subject: [PATCH 04/13] update shell/platform/ohos/ohos_xcomponent_adapter.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rulong Chen(陈汝龙) --- shell/platform/ohos/ohos_xcomponent_adapter.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.cpp b/shell/platform/ohos/ohos_xcomponent_adapter.cpp index 82c67548d8..9d077520a4 100644 --- a/shell/platform/ohos/ohos_xcomponent_adapter.cpp +++ b/shell/platform/ohos/ohos_xcomponent_adapter.cpp @@ -42,14 +42,14 @@ bool XComponentAdapter::Export(napi_env env, napi_value exports) uint64_t id_size = OH_XCOMPONENT_ID_LEN_MAX + 1; status = napi_get_named_property(env, exports, OH_NATIVE_XCOMPONENT_OBJ, - &export_instance); + &export_instance); LOGD("napi_get_named_property,status = %{public}d", status); if (status != napi_ok) { return false; } status = napi_unwrap(env, export_instance, - reinterpret_cast(&native_xcomponent)); + reinterpret_cast(&native_xcomponent)); LOGD("napi_unwrap,status = %{public}d", status); if (status != napi_ok) { return false; @@ -340,7 +340,7 @@ void XComponentBase::OnSurfaceChanged(OH_NativeXComponent* component, } if (isEngineAttached_) { PlatformViewOHOSNapi::SurfaceChanged(std::stoll(shell_holder_id_), width_, - height_); + height_); } else { LOGE("OnSurfaceChanged XComponentBase is not attached"); } @@ -368,7 +368,7 @@ void XComponentBase::OnDispatchTouchEvent(OH_NativeXComponent* component, if (isEngineAttached_) { LOGD("XComponentManger::HandleTouchEvent"); ohos_touch_processor_.HandleTouchEvent(std::stoll(shell_holder_id_), - component, &touch_event_); + component, &touch_event_); } else { LOGE( "XComponentManger::DispatchTouchEvent XComponentBase is not " -- Gitee From c41efaf8de26483210f7ca25a51813c596f70c80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rulong=20Chen=EF=BC=88=E9=99=88=E6=B1=9D=E9=BE=99=EF=BC=89?= Date: Sat, 9 Mar 2024 09:13:51 +0000 Subject: [PATCH 05/13] update shell/platform/ohos/ohos_xcomponent_adapter.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rulong Chen(陈汝龙) --- shell/platform/ohos/ohos_xcomponent_adapter.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.h b/shell/platform/ohos/ohos_xcomponent_adapter.h index 12ee490fc0..4c37381aa5 100644 --- a/shell/platform/ohos/ohos_xcomponent_adapter.h +++ b/shell/platform/ohos/ohos_xcomponent_adapter.h @@ -28,6 +28,7 @@ namespace flutter { class XComponentBase { public: + using NativeWindowHandle = void*; explicit XComponentBase(const std::string& id); ~XComponentBase(); @@ -36,10 +37,10 @@ class XComponentBase { void SetNativeXComponent(OH_NativeXComponent* native_xcomponent); // Callback, called by ACE XComponent - void OnSurfaceCreated(OH_NativeXComponent* component, void* window); - void OnSurfaceChanged(OH_NativeXComponent* component, void* window); - void OnSurfaceDestroyed(OH_NativeXComponent* component, void* window); - void OnDispatchTouchEvent(OH_NativeXComponent* component, void* window); + void OnSurfaceCreated(OH_NativeXComponent* component, NativeWindowHandle window); + void OnSurfaceChanged(OH_NativeXComponent* component, NativeWindowHandle window); + void OnSurfaceDestroyed(OH_NativeXComponent* component, NativeWindowHandle window); + void OnDispatchTouchEvent(OH_NativeXComponent* component, NativeWindowHandle window); OH_NativeXComponent* native_xcomponent() const { return native_xcomponent_; } -- Gitee From c84886935f9db766e804acf20c4a1b1ccf9b8de5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rulong=20Chen=EF=BC=88=E9=99=88=E6=B1=9D=E9=BE=99=EF=BC=89?= Date: Sat, 9 Mar 2024 09:17:18 +0000 Subject: [PATCH 06/13] update shell/platform/ohos/ohos_xcomponent_adapter.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rulong Chen(陈汝龙) --- shell/platform/ohos/ohos_xcomponent_adapter.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.cpp b/shell/platform/ohos/ohos_xcomponent_adapter.cpp index 9d077520a4..0c4ca121e1 100644 --- a/shell/platform/ohos/ohos_xcomponent_adapter.cpp +++ b/shell/platform/ohos/ohos_xcomponent_adapter.cpp @@ -201,7 +201,7 @@ static int32_t SetNativeWindowOpt(OHNativeWindow* native_window, return ret; } -void OnSurfaceCreatedCB(OH_NativeXComponent* component, void* window) +void OnSurfaceCreatedCB(OH_NativeXComponent* component, OHNativeWindowHandle window) { for (auto it : XComponentAdapter::GetInstance()->xcomponent_map()) { if (it.second->native_xcomponent() == component) { @@ -210,7 +210,7 @@ void OnSurfaceCreatedCB(OH_NativeXComponent* component, void* window) } } -void OnSurfaceChangedCB(OH_NativeXComponent* component, void* window) +void OnSurfaceChangedCB(OH_NativeXComponent* component, OHNativeWindowHandle window) { for (auto it : XComponentAdapter::GetInstance()->xcomponent_map()) { if (it.second->native_xcomponent() == component) { @@ -219,7 +219,7 @@ void OnSurfaceChangedCB(OH_NativeXComponent* component, void* window) } } -void OnSurfaceDestroyedCB(OH_NativeXComponent* component, void* window) +void OnSurfaceDestroyedCB(OH_NativeXComponent* component, OHNativeWindowHandle window) { for (auto it = XComponentAdapter::GetInstance()->xcomponent_map().begin(); it != XComponentAdapter::GetInstance()->xcomponent_map().end();) { @@ -233,7 +233,7 @@ void OnSurfaceDestroyedCB(OH_NativeXComponent* component, void* window) } } -void DispatchTouchEventCB(OH_NativeXComponent* component, void* window) +void DispatchTouchEventCB(OH_NativeXComponent* component, OHNativeWindowHandle window) { for (auto it : XComponentAdapter::GetInstance()->xcomponent_map()) { if (it.second->native_xcomponent() == component) { @@ -299,7 +299,7 @@ void XComponentBase::SetNativeXComponent( } void XComponentBase::OnSurfaceCreated(OH_NativeXComponent* component, - void* window) + OHNativeWindowHandle window) { LOGD( "XComponentManger::OnSurfaceCreated window = %{public}p component = " @@ -329,7 +329,7 @@ void XComponentBase::OnSurfaceCreated(OH_NativeXComponent* component, } void XComponentBase::OnSurfaceChanged(OH_NativeXComponent* component, - void* window) + OHNativeWindowHandle window) { LOGD("XComponentManger::OnSurfaceChanged "); int32_t ret = OH_NativeXComponent_GetXComponentSize(component, window, @@ -347,7 +347,7 @@ void XComponentBase::OnSurfaceChanged(OH_NativeXComponent* component, } void XComponentBase::OnSurfaceDestroyed(OH_NativeXComponent* component, - void* window) + OHNativeWindowHandle window) { window_ = nullptr; LOGD("XComponentManger::OnSurfaceDestroyed"); @@ -359,7 +359,7 @@ void XComponentBase::OnSurfaceDestroyed(OH_NativeXComponent* component, } void XComponentBase::OnDispatchTouchEvent(OH_NativeXComponent* component, - void* window) + OHNativeWindowHandle window) { LOGD("XComponentManger::DispatchTouchEvent"); int32_t ret = -- Gitee From e205dbff1968c2bad44204ef4414e9e0a6b52225 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rulong=20Chen=EF=BC=88=E9=99=88=E6=B1=9D=E9=BE=99=EF=BC=89?= Date: Sat, 9 Mar 2024 09:18:51 +0000 Subject: [PATCH 07/13] update shell/platform/ohos/ohos_xcomponent_adapter.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rulong Chen(陈汝龙) --- shell/platform/ohos/ohos_xcomponent_adapter.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.h b/shell/platform/ohos/ohos_xcomponent_adapter.h index 4c37381aa5..cef61cf80e 100644 --- a/shell/platform/ohos/ohos_xcomponent_adapter.h +++ b/shell/platform/ohos/ohos_xcomponent_adapter.h @@ -25,10 +25,9 @@ #include "napi_common.h" namespace flutter { - +using OHNativeWindowHandle = void*; class XComponentBase { public: - using NativeWindowHandle = void*; explicit XComponentBase(const std::string& id); ~XComponentBase(); @@ -37,10 +36,10 @@ class XComponentBase { void SetNativeXComponent(OH_NativeXComponent* native_xcomponent); // Callback, called by ACE XComponent - void OnSurfaceCreated(OH_NativeXComponent* component, NativeWindowHandle window); - void OnSurfaceChanged(OH_NativeXComponent* component, NativeWindowHandle window); - void OnSurfaceDestroyed(OH_NativeXComponent* component, NativeWindowHandle window); - void OnDispatchTouchEvent(OH_NativeXComponent* component, NativeWindowHandle window); + void OnSurfaceCreated(OH_NativeXComponent* component, OHNativeWindowHandle window); + void OnSurfaceChanged(OH_NativeXComponent* component, OHNativeWindowHandle window); + void OnSurfaceDestroyed(OH_NativeXComponent* component, OHNativeWindowHandle window); + void OnDispatchTouchEvent(OH_NativeXComponent* component, OHNativeWindowHandle window); OH_NativeXComponent* native_xcomponent() const { return native_xcomponent_; } -- Gitee From 7c570701db6bcc3014ae81949f63625f7bf28f0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rulong=20Chen=EF=BC=88=E9=99=88=E6=B1=9D=E9=BE=99=EF=BC=89?= Date: Sat, 9 Mar 2024 09:54:15 +0000 Subject: [PATCH 08/13] update shell/platform/ohos/ohos_xcomponent_adapter.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rulong Chen(陈汝龙) --- shell/platform/ohos/ohos_xcomponent_adapter.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.h b/shell/platform/ohos/ohos_xcomponent_adapter.h index cef61cf80e..26cd21b42c 100644 --- a/shell/platform/ohos/ohos_xcomponent_adapter.h +++ b/shell/platform/ohos/ohos_xcomponent_adapter.h @@ -25,7 +25,6 @@ #include "napi_common.h" namespace flutter { -using OHNativeWindowHandle = void*; class XComponentBase { public: explicit XComponentBase(const std::string& id); @@ -36,10 +35,10 @@ class XComponentBase { void SetNativeXComponent(OH_NativeXComponent* native_xcomponent); // Callback, called by ACE XComponent - void OnSurfaceCreated(OH_NativeXComponent* component, OHNativeWindowHandle window); - void OnSurfaceChanged(OH_NativeXComponent* component, OHNativeWindowHandle window); - void OnSurfaceDestroyed(OH_NativeXComponent* component, OHNativeWindowHandle window); - void OnDispatchTouchEvent(OH_NativeXComponent* component, OHNativeWindowHandle window); + void OnSurfaceCreated(OH_NativeXComponent* component, OHNativeWindow* window); + void OnSurfaceChanged(OH_NativeXComponent* component, OHNativeWindow* window); + void OnSurfaceDestroyed(OH_NativeXComponent* component, OHNativeWindow* window); + void OnDispatchTouchEvent(OH_NativeXComponent* component, OHNativeWindow* window); OH_NativeXComponent* native_xcomponent() const { return native_xcomponent_; } -- Gitee From 0b827c703a48e7946d2b115f76bc7edc069ec7c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rulong=20Chen=EF=BC=88=E9=99=88=E6=B1=9D=E9=BE=99=EF=BC=89?= Date: Sat, 9 Mar 2024 09:56:00 +0000 Subject: [PATCH 09/13] update shell/platform/ohos/ohos_xcomponent_adapter.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rulong Chen(陈汝龙) --- shell/platform/ohos/ohos_xcomponent_adapter.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.cpp b/shell/platform/ohos/ohos_xcomponent_adapter.cpp index 0c4ca121e1..04b1e5c4b5 100644 --- a/shell/platform/ohos/ohos_xcomponent_adapter.cpp +++ b/shell/platform/ohos/ohos_xcomponent_adapter.cpp @@ -201,7 +201,7 @@ static int32_t SetNativeWindowOpt(OHNativeWindow* native_window, return ret; } -void OnSurfaceCreatedCB(OH_NativeXComponent* component, OHNativeWindowHandle window) +void OnSurfaceCreatedCB(OH_NativeXComponent* component, OHNativeWindow* window) { for (auto it : XComponentAdapter::GetInstance()->xcomponent_map()) { if (it.second->native_xcomponent() == component) { @@ -210,7 +210,7 @@ void OnSurfaceCreatedCB(OH_NativeXComponent* component, OHNativeWindowHandle win } } -void OnSurfaceChangedCB(OH_NativeXComponent* component, OHNativeWindowHandle window) +void OnSurfaceChangedCB(OH_NativeXComponent* component, OHNativeWindow* window) { for (auto it : XComponentAdapter::GetInstance()->xcomponent_map()) { if (it.second->native_xcomponent() == component) { @@ -219,7 +219,7 @@ void OnSurfaceChangedCB(OH_NativeXComponent* component, OHNativeWindowHandle win } } -void OnSurfaceDestroyedCB(OH_NativeXComponent* component, OHNativeWindowHandle window) +void OnSurfaceDestroyedCB(OH_NativeXComponent* component, OHNativeWindow* window) { for (auto it = XComponentAdapter::GetInstance()->xcomponent_map().begin(); it != XComponentAdapter::GetInstance()->xcomponent_map().end();) { @@ -233,7 +233,7 @@ void OnSurfaceDestroyedCB(OH_NativeXComponent* component, OHNativeWindowHandle w } } -void DispatchTouchEventCB(OH_NativeXComponent* component, OHNativeWindowHandle window) +void DispatchTouchEventCB(OH_NativeXComponent* component, OHNativeWindow* window) { for (auto it : XComponentAdapter::GetInstance()->xcomponent_map()) { if (it.second->native_xcomponent() == component) { @@ -299,7 +299,7 @@ void XComponentBase::SetNativeXComponent( } void XComponentBase::OnSurfaceCreated(OH_NativeXComponent* component, - OHNativeWindowHandle window) + OHNativeWindow* window) { LOGD( "XComponentManger::OnSurfaceCreated window = %{public}p component = " @@ -329,7 +329,7 @@ void XComponentBase::OnSurfaceCreated(OH_NativeXComponent* component, } void XComponentBase::OnSurfaceChanged(OH_NativeXComponent* component, - OHNativeWindowHandle window) + OHNativeWindow* window) { LOGD("XComponentManger::OnSurfaceChanged "); int32_t ret = OH_NativeXComponent_GetXComponentSize(component, window, @@ -347,7 +347,7 @@ void XComponentBase::OnSurfaceChanged(OH_NativeXComponent* component, } void XComponentBase::OnSurfaceDestroyed(OH_NativeXComponent* component, - OHNativeWindowHandle window) + OHNativeWindow* window) { window_ = nullptr; LOGD("XComponentManger::OnSurfaceDestroyed"); @@ -359,7 +359,7 @@ void XComponentBase::OnSurfaceDestroyed(OH_NativeXComponent* component, } void XComponentBase::OnDispatchTouchEvent(OH_NativeXComponent* component, - OHNativeWindowHandle window) + OHNativeWindow* window) { LOGD("XComponentManger::DispatchTouchEvent"); int32_t ret = -- Gitee From 1863f901e14d16404d4102ca65f1f52f07766c9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rulong=20Chen=EF=BC=88=E9=99=88=E6=B1=9D=E9=BE=99=EF=BC=89?= Date: Sat, 9 Mar 2024 10:43:53 +0000 Subject: [PATCH 10/13] update shell/platform/ohos/ohos_xcomponent_adapter.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rulong Chen(陈汝龙) --- shell/platform/ohos/ohos_xcomponent_adapter.h | 1 + 1 file changed, 1 insertion(+) diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.h b/shell/platform/ohos/ohos_xcomponent_adapter.h index 26cd21b42c..98af86b3b6 100644 --- a/shell/platform/ohos/ohos_xcomponent_adapter.h +++ b/shell/platform/ohos/ohos_xcomponent_adapter.h @@ -18,6 +18,7 @@ #include #include +#include #include #include "flutter/shell/platform/ohos/ohos_touch_processor.h" -- Gitee From 88da83e390a7d9391721af69fe52aa62f2d34867 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rulong=20Chen=EF=BC=88=E9=99=88=E6=B1=9D=E9=BE=99=EF=BC=89?= Date: Sat, 9 Mar 2024 13:30:07 +0000 Subject: [PATCH 11/13] update shell/platform/ohos/ohos_xcomponent_adapter.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rulong Chen(陈汝龙) --- shell/platform/ohos/ohos_xcomponent_adapter.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.h b/shell/platform/ohos/ohos_xcomponent_adapter.h index 98af86b3b6..14141e9e09 100644 --- a/shell/platform/ohos/ohos_xcomponent_adapter.h +++ b/shell/platform/ohos/ohos_xcomponent_adapter.h @@ -18,7 +18,6 @@ #include #include -#include #include #include "flutter/shell/platform/ohos/ohos_touch_processor.h" @@ -36,10 +35,10 @@ class XComponentBase { void SetNativeXComponent(OH_NativeXComponent* native_xcomponent); // Callback, called by ACE XComponent - void OnSurfaceCreated(OH_NativeXComponent* component, OHNativeWindow* window); - void OnSurfaceChanged(OH_NativeXComponent* component, OHNativeWindow* window); - void OnSurfaceDestroyed(OH_NativeXComponent* component, OHNativeWindow* window); - void OnDispatchTouchEvent(OH_NativeXComponent* component, OHNativeWindow* window); + void OnSurfaceCreated(OH_NativeXComponent* component, void* window); + void OnSurfaceChanged(OH_NativeXComponent* component, void* window); + void OnSurfaceDestroyed(OH_NativeXComponent* component, void* window); + void OnDispatchTouchEvent(OH_NativeXComponent* component, void* window); OH_NativeXComponent* native_xcomponent() const { return native_xcomponent_; } -- Gitee From 76fe61789ab81ff46f4994d359ce8bca641c3417 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rulong=20Chen=EF=BC=88=E9=99=88=E6=B1=9D=E9=BE=99=EF=BC=89?= Date: Sat, 9 Mar 2024 13:31:31 +0000 Subject: [PATCH 12/13] update shell/platform/ohos/ohos_xcomponent_adapter.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rulong Chen(陈汝龙) --- .../platform/ohos/ohos_xcomponent_adapter.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.cpp b/shell/platform/ohos/ohos_xcomponent_adapter.cpp index 04b1e5c4b5..50d880798c 100644 --- a/shell/platform/ohos/ohos_xcomponent_adapter.cpp +++ b/shell/platform/ohos/ohos_xcomponent_adapter.cpp @@ -151,7 +151,7 @@ using OHOS_SurfaceBufferUsage = enum { BUFFER_USAGE_VENDOR_PRI18 = (1ULL << 62), /**< Reserverd for vendor */ BUFFER_USAGE_VENDOR_PRI19 = (1ULL << 63), /**< Reserverd for vendor */ }; -static int32_t SetNativeWindowOpt(OHNativeWindow* native_window, +static int32_t SetNativeWindowOpt(void* native_window, int32_t width, int height) { @@ -201,7 +201,7 @@ static int32_t SetNativeWindowOpt(OHNativeWindow* native_window, return ret; } -void OnSurfaceCreatedCB(OH_NativeXComponent* component, OHNativeWindow* window) +void OnSurfaceCreatedCB(OH_NativeXComponent* component, void* window) { for (auto it : XComponentAdapter::GetInstance()->xcomponent_map()) { if (it.second->native_xcomponent() == component) { @@ -210,7 +210,7 @@ void OnSurfaceCreatedCB(OH_NativeXComponent* component, OHNativeWindow* window) } } -void OnSurfaceChangedCB(OH_NativeXComponent* component, OHNativeWindow* window) +void OnSurfaceChangedCB(OH_NativeXComponent* component, void* window) { for (auto it : XComponentAdapter::GetInstance()->xcomponent_map()) { if (it.second->native_xcomponent() == component) { @@ -219,7 +219,7 @@ void OnSurfaceChangedCB(OH_NativeXComponent* component, OHNativeWindow* window) } } -void OnSurfaceDestroyedCB(OH_NativeXComponent* component, OHNativeWindow* window) +void OnSurfaceDestroyedCB(OH_NativeXComponent* component, void* window) { for (auto it = XComponentAdapter::GetInstance()->xcomponent_map().begin(); it != XComponentAdapter::GetInstance()->xcomponent_map().end();) { @@ -233,7 +233,7 @@ void OnSurfaceDestroyedCB(OH_NativeXComponent* component, OHNativeWindow* window } } -void DispatchTouchEventCB(OH_NativeXComponent* component, OHNativeWindow* window) +void DispatchTouchEventCB(OH_NativeXComponent* component, void* window) { for (auto it : XComponentAdapter::GetInstance()->xcomponent_map()) { if (it.second->native_xcomponent() == component) { @@ -299,7 +299,7 @@ void XComponentBase::SetNativeXComponent( } void XComponentBase::OnSurfaceCreated(OH_NativeXComponent* component, - OHNativeWindow* window) + void* window) { LOGD( "XComponentManger::OnSurfaceCreated window = %{public}p component = " @@ -329,7 +329,7 @@ void XComponentBase::OnSurfaceCreated(OH_NativeXComponent* component, } void XComponentBase::OnSurfaceChanged(OH_NativeXComponent* component, - OHNativeWindow* window) + void* window) { LOGD("XComponentManger::OnSurfaceChanged "); int32_t ret = OH_NativeXComponent_GetXComponentSize(component, window, @@ -347,7 +347,7 @@ void XComponentBase::OnSurfaceChanged(OH_NativeXComponent* component, } void XComponentBase::OnSurfaceDestroyed(OH_NativeXComponent* component, - OHNativeWindow* window) + void* window) { window_ = nullptr; LOGD("XComponentManger::OnSurfaceDestroyed"); @@ -359,7 +359,7 @@ void XComponentBase::OnSurfaceDestroyed(OH_NativeXComponent* component, } void XComponentBase::OnDispatchTouchEvent(OH_NativeXComponent* component, - OHNativeWindow* window) + void* window) { LOGD("XComponentManger::DispatchTouchEvent"); int32_t ret = -- Gitee From 8ca787e8513373c2ea218c1bd855c593cc623ecb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rulong=20Chen=EF=BC=88=E9=99=88=E6=B1=9D=E9=BE=99=EF=BC=89?= Date: Sun, 10 Mar 2024 07:31:55 +0000 Subject: [PATCH 13/13] update shell/platform/ohos/ohos_xcomponent_adapter.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rulong Chen(陈汝龙) --- shell/platform/ohos/ohos_xcomponent_adapter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.cpp b/shell/platform/ohos/ohos_xcomponent_adapter.cpp index 50d880798c..9d077520a4 100644 --- a/shell/platform/ohos/ohos_xcomponent_adapter.cpp +++ b/shell/platform/ohos/ohos_xcomponent_adapter.cpp @@ -151,7 +151,7 @@ using OHOS_SurfaceBufferUsage = enum { BUFFER_USAGE_VENDOR_PRI18 = (1ULL << 62), /**< Reserverd for vendor */ BUFFER_USAGE_VENDOR_PRI19 = (1ULL << 63), /**< Reserverd for vendor */ }; -static int32_t SetNativeWindowOpt(void* native_window, +static int32_t SetNativeWindowOpt(OHNativeWindow* native_window, int32_t width, int height) { -- Gitee