From 73a2a76148b54f00adbf82fb8b902fe7805b0a1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B0=E7=B3=96=E9=9B=AA=E6=A2=A8?= <1076351865@qqã.com> Date: Fri, 3 May 2024 10:23:58 +0000 Subject: [PATCH 1/5] =?UTF-8?q?=E5=BC=80=E5=90=AFASan=E5=90=8E=E5=86=85?= =?UTF-8?q?=E5=AD=98=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit 0bbbb2ae985cde8226d35ffdb8f87e7f35de246a) --- shell/platform/ohos/napi/platform_view_ohos_napi.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/shell/platform/ohos/napi/platform_view_ohos_napi.cpp b/shell/platform/ohos/napi/platform_view_ohos_napi.cpp index 25247c4157..b0a3db5cf9 100644 --- a/shell/platform/ohos/napi/platform_view_ohos_napi.cpp +++ b/shell/platform/ohos/napi/platform_view_ohos_napi.cpp @@ -301,6 +301,7 @@ void PlatformViewOHOSNapi::FlutterViewHandlePlatformMessage( if (message->hasData()) { fml::MallocMapping mapping = message->releaseData(); char* mapData = (char*)mapping.Release(); + mapData[mapping.GetSize()] = '\0'; status = napi_create_string_utf8(env_, mapData, strlen(mapData), &callbackParam[3]); if (status != napi_ok) { -- Gitee From 5f5856710b16b72f46945fa06fc29820f3760b47 Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Fri, 3 May 2024 17:34:02 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9surface=E7=9A=84=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- shell/platform/ohos/ohos_xcomponent_adapter.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.cpp b/shell/platform/ohos/ohos_xcomponent_adapter.cpp index 991e57f6b5..3c243d7fff 100644 --- a/shell/platform/ohos/ohos_xcomponent_adapter.cpp +++ b/shell/platform/ohos/ohos_xcomponent_adapter.cpp @@ -312,6 +312,7 @@ void XComponentBase::OnSurfaceCreated(OH_NativeXComponent* component, } if (isEngineAttached_) { PlatformViewOHOSNapi::SurfaceCreated(std::stoll(shellholderId_), window); + isSurfaceCreated_ = true; } else { LOGE("OnSurfaceCreated XComponentBase is not attached"); } @@ -339,6 +340,7 @@ void XComponentBase::OnSurfaceDestroyed(OH_NativeXComponent* component, window_ = nullptr; LOGD("XComponentManger::OnSurfaceDestroyed"); if (isEngineAttached_) { + isSurfaceCreated_ = false; PlatformViewOHOSNapi::SurfaceDestroyed(std::stoll(shellholderId_)); } else { LOGE("OnSurfaceCreated OnSurfaceDestroyed is not attached"); -- Gitee From 4c094549f4511e2090de696f50170206fe95132a 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: Thu, 9 May 2024 10:46:13 +0800 Subject: [PATCH 3/5] =?UTF-8?q?Revert:=20"XComponentBase=E5=9C=A8detach?= =?UTF-8?q?=E8=B7=9Fattach=E6=97=B6=E4=B8=8D=E5=86=8D=E5=BC=BA=E5=88=B6?= =?UTF-8?q?=E9=94=80=E6=AF=81Surface"=20Reason:=20=E8=AF=A5=E6=8F=90?= =?UTF-8?q?=E4=BA=A4=E4=BC=9A=E5=AF=BC=E8=87=B4=E9=83=A8=E5=88=86=E5=9C=BA?= =?UTF-8?q?=E6=99=AF=E4=B8=8Battach=E5=BC=95=E6=93=8E=E5=A4=B1=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ohos/napi/platform_view_ohos_napi.cpp | 6 ----- .../ohos/napi/platform_view_ohos_napi.h | 2 -- .../platform/ohos/ohos_xcomponent_adapter.cpp | 25 ++++++------------- shell/platform/ohos/ohos_xcomponent_adapter.h | 1 - 4 files changed, 7 insertions(+), 27 deletions(-) diff --git a/shell/platform/ohos/napi/platform_view_ohos_napi.cpp b/shell/platform/ohos/napi/platform_view_ohos_napi.cpp index 25247c4157..69bd07dcee 100644 --- a/shell/platform/ohos/napi/platform_view_ohos_napi.cpp +++ b/shell/platform/ohos/napi/platform_view_ohos_napi.cpp @@ -1513,12 +1513,6 @@ void PlatformViewOHOSNapi::SurfaceCreated(int64_t shell_holder, void* window) { OHOS_SHELL_HOLDER->GetPlatformView()->NotifyCreate(std::move(native_window)); } -void PlatformViewOHOSNapi::SurfaceWindowChanged(int64_t shell_holder, void* window) { - auto native_window = fml::MakeRefCounted( - static_cast(window)); - OHOS_SHELL_HOLDER->GetPlatformView()->NotifySurfaceWindowChanged(std::move(native_window)); -} - void PlatformViewOHOSNapi::SurfaceChanged(int64_t shell_holder, int32_t width, int32_t height) { diff --git a/shell/platform/ohos/napi/platform_view_ohos_napi.h b/shell/platform/ohos/napi/platform_view_ohos_napi.h index 8bcc4a683d..f998fbf553 100644 --- a/shell/platform/ohos/napi/platform_view_ohos_napi.h +++ b/shell/platform/ohos/napi/platform_view_ohos_napi.h @@ -166,8 +166,6 @@ class PlatformViewOHOSNapi { // Surface相关,XComponent调用 static void SurfaceCreated(int64_t shell_holder, void* window); - static void SurfaceWindowChanged(int64_t shell_holder, void* window); - static void SurfaceChanged( int64_t shell_holder, int32_t width, diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.cpp b/shell/platform/ohos/ohos_xcomponent_adapter.cpp index 3c243d7fff..9c7fee2473 100644 --- a/shell/platform/ohos/ohos_xcomponent_adapter.cpp +++ b/shell/platform/ohos/ohos_xcomponent_adapter.cpp @@ -239,7 +239,6 @@ void XComponentBase::BindXComponentCallback() { XComponentBase::XComponentBase(std::string id){ id_ = id; isEngineAttached_ = false; - isSurfaceCreated_ = false; } XComponentBase::~XComponentBase() {} @@ -249,24 +248,10 @@ void XComponentBase::AttachFlutterEngine(std::string shellholderId) { "XComponentManger::AttachFlutterEngine xcomponentId:%{public}s, " "shellholderId:%{public}s", id_.c_str(), shellholderId.c_str()); - isEngineAttached_ = true; - - if (shellholderId_ == shellholderId && isSurfaceCreated_) { - LOGI("XComponentManger::AttachFlutterEngine XComponentId:%{public}s shellHolderId:%{public}s Surface has been created.", id_.c_str(), shellholderId.c_str()); - PlatformViewOHOSNapi::SurfaceWindowChanged(std::stoll(shellholderId_), window_); - return; - } - - if (!shellholderId_.empty() && shellholderId_ != shellholderId) { - if (window_ != nullptr) { - PlatformViewOHOSNapi::SurfaceDestroyed(std::stoll(shellholderId_)); - } - } - shellholderId_ = shellholderId; + isEngineAttached_ = true; if (window_ != nullptr) { PlatformViewOHOSNapi::SurfaceCreated(std::stoll(shellholderId_), window_); - isSurfaceCreated_ = true; } else { LOGE("OnSurfaceCreated XComponentBase is not attached"); } @@ -277,6 +262,12 @@ void XComponentBase::DetachFlutterEngine() { "XComponentManger::DetachFlutterEngine xcomponentId:%{public}s, " "shellholderId:%{public}s", id_.c_str(), shellholderId_.c_str()); + if (window_ != nullptr) { + PlatformViewOHOSNapi::SurfaceDestroyed(std::stoll(shellholderId_)); + } else { + LOGE("DetachFlutterEngine XComponentBase is not attached"); + } + shellholderId_ = ""; isEngineAttached_ = false; } @@ -312,7 +303,6 @@ void XComponentBase::OnSurfaceCreated(OH_NativeXComponent* component, } if (isEngineAttached_) { PlatformViewOHOSNapi::SurfaceCreated(std::stoll(shellholderId_), window); - isSurfaceCreated_ = true; } else { LOGE("OnSurfaceCreated XComponentBase is not attached"); } @@ -340,7 +330,6 @@ void XComponentBase::OnSurfaceDestroyed(OH_NativeXComponent* component, window_ = nullptr; LOGD("XComponentManger::OnSurfaceDestroyed"); if (isEngineAttached_) { - isSurfaceCreated_ = false; PlatformViewOHOSNapi::SurfaceDestroyed(std::stoll(shellholderId_)); } else { LOGE("OnSurfaceCreated OnSurfaceDestroyed is not attached"); diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.h b/shell/platform/ohos/ohos_xcomponent_adapter.h index af3175f0e5..4fd6ff4990 100644 --- a/shell/platform/ohos/ohos_xcomponent_adapter.h +++ b/shell/platform/ohos/ohos_xcomponent_adapter.h @@ -48,7 +48,6 @@ public: std::string shellholderId_; bool isEngineAttached_; bool isWindowAttached_; - bool isSurfaceCreated_; OH_NativeXComponent* nativeXComponent_; void* window_; uint64_t width_; -- Gitee From 0778dcb96f48dc58815cfe2ec9dd7b6647027f81 Mon Sep 17 00:00:00 2001 From: huangxiaoyao <976125628@qq.com> Date: Fri, 10 May 2024 17:08:55 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbuffer=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E4=B8=BA=E7=A9=BA=E5=AF=BC=E8=87=B4=E7=9A=84=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huangxiaoyao <976125628@qq.com> --- .../main/ets/embedding/engine/FlutterNapi.ets | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterNapi.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterNapi.ets index 428859ce47..1058081faf 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterNapi.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterNapi.ets @@ -275,22 +275,26 @@ export default class FlutterNapi { } decodeImage(buffer: ArrayBuffer, imageGeneratorAddress: number): void { - Log.d(TAG, "called decodeImage=" + buffer.byteLength) - const imageSourceApi = image.createImageSource(buffer); - let tempPixelMap: image.PixelMap | null = null; - imageSourceApi.createPixelMap({ - desiredPixelFormat: image.PixelMapFormat.RGBA_8888 - }).then(pixelMap => { - Log.d(TAG, "called createPixelMap end " + pixelMap.getPixelBytesNumber()) - tempPixelMap = pixelMap - return pixelMap.getImageInfo() - }).then(imageInfo => { - Log.d(TAG, `nativeImageHeaderCallback width=${imageInfo.size.width} height=${imageInfo.size.height} imageGeneratorAddress=${imageGeneratorAddress}`) - flutter.nativeImageDecodeCallback(imageInfo.size.width, imageInfo.size.height, imageGeneratorAddress, tempPixelMap) - }).catch((error: Any) => { - Log.d(TAG, "decodeImage error=" + JSON.stringify(error)) + if (buffer) { + Log.d(TAG, "called decodeImage=" + buffer.byteLength) + const imageSourceApi = image.createImageSource(buffer); + let tempPixelMap: image.PixelMap | null = null; + imageSourceApi.createPixelMap({ + desiredPixelFormat: image.PixelMapFormat.RGBA_8888 + }).then(pixelMap => { + Log.d(TAG, "called createPixelMap end " + pixelMap.getPixelBytesNumber()) + tempPixelMap = pixelMap + return pixelMap.getImageInfo() + }).then(imageInfo => { + Log.d(TAG, `nativeImageHeaderCallback width=${imageInfo.size.width} height=${imageInfo.size.height} imageGeneratorAddress=${imageGeneratorAddress}`) + flutter.nativeImageDecodeCallback(imageInfo.size.width, imageInfo.size.height, imageGeneratorAddress, tempPixelMap) + }).catch((error: Any) => { + Log.d(TAG, "decodeImage error=" + JSON.stringify(error)) + flutter.nativeImageDecodeCallback(0, 0, imageGeneratorAddress, null); + }) + } else { flutter.nativeImageDecodeCallback(0, 0, imageGeneratorAddress, null); - }) + } } setSemanticsEnabled(enabled: boolean, responseId: number): void { -- Gitee From 586581051e2d2dcba11ca94c93bc3fb7ec0bdc4f 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, 11 May 2024 17:42:39 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=85=B1=E4=BA=AB?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E5=89=AA=E8=B4=B4=E6=9D=BF=E4=B8=8D=E7=94=9F?= =?UTF-8?q?=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit demo: https://github.com/alibaba/flutter_boost/blob/main/example/lib/case/clipboard_example.dart --- .../ets/embedding/engine/systemchannels/PlatformChannel.ets | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/PlatformChannel.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/PlatformChannel.ets index 3cde964f7c..5c874cb812 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/PlatformChannel.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/PlatformChannel.ets @@ -382,15 +382,14 @@ class PlatformMethodCallback implements MethodCallHandler { let pasteBoard = pasteboard.getSystemPasteboard(); pasteBoard.getData().then((pasteData) => { let text = pasteData.getPrimaryText(); - let response: Any = new Map().set("text", ""); - response.text = text; + let response: Any = new Map().set("text", text); result.success(response); }).catch((err: Any) => { Log.e(PlatformMethodCallback.TAG, "Failed to get PasteData. Cause: " + JSON.stringify(err)); }); break; case "Clipboard.setData": - let clipboardContent: string = args.text; + let clipboardContent: string = args.get('text'); this.platform.platformMessageHandler.setClipboardData(clipboardContent); result.success(null); break; -- Gitee