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 428859ce4776efd9e9f0bc163864213de8ff0f86..1058081fafc2766b3bc7080ac497a8f345061521 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 { 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 3cde964f7c085eaf20d35897bc65932bf1b13c3a..5c874cb812ab3dbc4747a461198513ed1faae56c 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; diff --git a/shell/platform/ohos/napi/platform_view_ohos_napi.cpp b/shell/platform/ohos/napi/platform_view_ohos_napi.cpp index 25247c4157bbe4bdadce6d0b83ceb3cb385fa2eb..142fe4558b83b22a4f9f6cf88a594109f9e6d835 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) { @@ -1513,12 +1514,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 8bcc4a683d24f08f7d1673292fb27908619f7490..f998fbf553c2809abb2c5da737685c68009a8ce0 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 991e57f6b5a09e857b8f672fd35e352e25c5af5c..9c7fee2473fb2469228138661c94e9f22b88885b 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; } diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.h b/shell/platform/ohos/ohos_xcomponent_adapter.h index af3175f0e51f4b986fa058e32fb6b634c3ce000b..4fd6ff49902c6c02c1745b7bbd265a48d7f93fd0 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_;