From a64c4822d685c00cf261d52156dbcaf34c7a5033 Mon Sep 17 00:00:00 2001 From: zhan-linlin <17301907374@163.com> Date: Wed, 17 Jan 2024 16:03:50 +0800 Subject: [PATCH 01/73] IssueNo: zhan-linlin 17301907374@163.com Sig: OpenHarmony-SIG/flutter-engine Feature or Bugfix: Bugfix Binary Source: No Signed-off-by: zhan-linlin <17301907374@163.com> --- .../flutter_embedding/flutter/src/main/ets/util/Log.ets | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/util/Log.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/util/Log.ets index 437b52f180..8dcfb79903 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/util/Log.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/util/Log.ets @@ -91,6 +91,12 @@ export default class Log { */ static e(tag: string, format: string, ...args: ESObject[]) { if (Log.isLoggable(HiLog.LogLevel.ERROR)) { + args.format((item: ESObject, index: number) => { + if (item instanceof Error) { + args[index] = item.message + item.stack; + } + format+="%{public}s"; + }) HiLog.error(DOMAIN, TAG, tag + SYMBOL + format, args); } } -- Gitee From a2b02ef02e3a06212d1cbbcfab7c201f9ca5f1bf Mon Sep 17 00:00:00 2001 From: zmf <279822581@qq.com> Date: Thu, 18 Jan 2024 16:00:38 +0800 Subject: [PATCH 02/73] =?UTF-8?q?=E7=A7=BB=E9=99=A4skia=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E7=BB=98=E5=88=B6=E5=A4=9A=E4=BD=99=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zmf <279822581@qq.com> --- attachment/repos/skia.patch | 53 ------------------- .../renderer/backend/vulkan/context_vk.cc | 1 + 2 files changed, 1 insertion(+), 53 deletions(-) diff --git a/attachment/repos/skia.patch b/attachment/repos/skia.patch index 455594c1ba..d993bdffa7 100644 --- a/attachment/repos/skia.patch +++ b/attachment/repos/skia.patch @@ -327,59 +327,6 @@ index b43526fe1f..fb34289da7 100644 ldflags = [ "-rdynamic", "-Wl,-rpath,\$ORIGIN", -diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp -index ab23b24edd..c5f714712b 100644 ---- a/src/core/SkCanvas.cpp -+++ b/src/core/SkCanvas.cpp -@@ -82,6 +82,16 @@ static_assert(std::max(3,4) == 4); - - using Slug = sktext::gpu::Slug; - -+#ifdef TARGET_OS_OHOS -+#include -+#define SKIA_LOG_INFO LOG_INFO -+#define SKIA_TAG "XComSkia" -+//int OH_LOG_Print(int type, HiLog_LogLevel level, unsigned int domain, const char *tag, const char *fmt, ...) ; -+#define OHOS_LOG_DEBUG(...) (void) OH_LOG_Print(LOG_APP,SKIA_LOG_INFO,LOG_DOMAIN,SKIA_TAG,__VA_ARGS__) -+#else -+#define OHOS_LOG_DEBUG(...) -+#endif -+ - /////////////////////////////////////////////////////////////////////////////////////////////////// - - /* -@@ -2044,7 +2054,7 @@ void SkCanvas::onDrawPaint(const SkPaint& paint) { - } - - void SkCanvas::internalDrawPaint(const SkPaint& paint) { -- // drawPaint does not call internalQuickReject() because computing its geometry is not free -+ // drawPaint does not call exitinternalQuickReject() because computing its geometry is not free - // (see getLocalClipBounds(), and the two conditions below are sufficient. - if (paint.nothingToDraw() || this->isClipEmpty()) { - return; -@@ -2358,16 +2368,22 @@ void SkCanvas::onDrawImageRect2(const SkImage* image, const SkRect& src, const S - SkPaint realPaint = clean_paint_for_drawImage(paint); - SkSamplingOptions realSampling = clean_sampling_for_constraint(sampling, constraint); - -+ OHOS_LOG_DEBUG("SkCanvas::onDrawImageRect2 ...enter "); - if (this->internalQuickReject(dst, realPaint)) { -+ OHOS_LOG_DEBUG("SkCanvas::onDrawImageRect2 ...internalQuickReject rejected"); - return; - } - -+ OHOS_LOG_DEBUG("SkCanvas::onDrawImageRect2 ...aboutToDraw"); - auto layer = this->aboutToDraw(this, realPaint, &dst, CheckForOverwrite::kYes, - image->isOpaque() ? kOpaque_ShaderOverrideOpacity - : kNotOpaque_ShaderOverrideOpacity); -+ - if (layer) { -+ OHOS_LOG_DEBUG("SkCanvas::onDrawImageRect2 ...topDevice->drawImageRect"); - this->topDevice()->drawImageRect(image, &src, dst, realSampling, layer->paint(), constraint); - } -+ OHOS_LOG_DEBUG("SkCanvas::onDrawImageRect2 ...exit"); - } - - void SkCanvas::onDrawImageLattice2(const SkImage* image, const Lattice& lattice, const SkRect& dst, diff --git a/src/gpu/ganesh/gl/egl/GrGLMakeEGLInterface.cpp b/src/gpu/ganesh/gl/egl/GrGLMakeEGLInterface.cpp index 78225b4610..c2105852b1 100644 --- a/src/gpu/ganesh/gl/egl/GrGLMakeEGLInterface.cpp diff --git a/impeller/renderer/backend/vulkan/context_vk.cc b/impeller/renderer/backend/vulkan/context_vk.cc index db5574ce4f..0427f9fdf0 100644 --- a/impeller/renderer/backend/vulkan/context_vk.cc +++ b/impeller/renderer/backend/vulkan/context_vk.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. // FLUTTER_NOLINT: https://github.com/flutter/flutter/issues/68331 +#pragma clang diagnostic ignored "-Wc++11-narrowing" #include "impeller/renderer/backend/vulkan/context_vk.h" -- Gitee From f183262964b0c4e636e1d36e25e680bc990e26f1 Mon Sep 17 00:00:00 2001 From: xiaoxiang Date: Mon, 22 Jan 2024 16:05:22 +0800 Subject: [PATCH 03/73] =?UTF-8?q?DetachFlutterEngine=E6=97=B6=E4=B8=8D?= =?UTF-8?q?=E5=B0=86window=E8=AE=BE=E7=BD=AE=E4=B8=BAnullptr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiaoxiang --- shell/platform/ohos/ohos_xcomponent_adapter.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.cpp b/shell/platform/ohos/ohos_xcomponent_adapter.cpp index f592b7e0df..a657f6b949 100644 --- a/shell/platform/ohos/ohos_xcomponent_adapter.cpp +++ b/shell/platform/ohos/ohos_xcomponent_adapter.cpp @@ -268,10 +268,9 @@ void XComponentBase::DetachFlutterEngine() { if (window_ != nullptr) { PlatformViewOHOSNapi::SurfaceDestroyed(std::stoll(shellholderId_)); } else { - LOGE("OnSurfaceCreated XComponentBase is not attached"); + LOGE("DetachFlutterEngine XComponentBase is not attached"); } shellholderId_ = ""; - window_ = nullptr; isEngineAttached_ = false; } -- Gitee From ab1485441047a3226d41d7ab38059342cbde7213 Mon Sep 17 00:00:00 2001 From: xiaoxiang Date: Tue, 23 Jan 2024 16:04:40 +0800 Subject: [PATCH 04/73] =?UTF-8?q?=E7=A1=AE=E8=AE=A4aboutToAppear=E7=9A=84?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E5=8F=AA=E4=BC=9A=E8=BF=9B=E4=B8=80=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiaoxiang --- .../ohos/flutter_embedding/flutter/index.ets | 20 ++++++++++++++++-- .../main/ets/embedding/ohos/FlutterEntry.ets | 21 ++++++++++++------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/index.ets b/shell/platform/ohos/flutter_embedding/flutter/index.ets index 3c96b70703..a69f1c32bb 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/index.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/index.ets @@ -13,6 +13,22 @@ * limitations under the License. */ -export { FlutterAbility } from './src/main/ets/embedding/ohos/FlutterAbility' +import FlutterManager from './src/main/ets/embedding/ohos/FlutterManager'; +import { FlutterAbility } from './src/main/ets/embedding/ohos/FlutterAbility' +import { FlutterPage } from './src/main/ets/embedding/ohos/FlutterPage' +import { FlutterPlugin } from './src/main/ets/embedding/engine/plugins/FlutterPlugin' +import { FlutterView } from './src/main/ets/view/FlutterView'; +import FlutterEntry from './src/main/ets/embedding/ohos/FlutterEntry'; +import FlutterEngine from './src/main/ets/embedding/engine/FlutterEngine'; +import PlatformPlugin from './src/main/ets/plugin/PlatformPlugin'; -export { FlutterPage } from './src/main/ets/embedding/ohos/FlutterPage' +export { + PlatformPlugin, + FlutterPlugin, + FlutterView, + FlutterEntry, + FlutterEngine, + FlutterAbility, + FlutterManager, + FlutterPage +} \ No newline at end of file diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterEntry.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterEntry.ets index e995319b54..e66095a173 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterEntry.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterEntry.ets @@ -40,24 +40,29 @@ export default class FlutterEntry implements Host { private windowStage: window.WindowStage | null = null private parameters: ESObject = {}; private engineConfigurator: FlutterEngineConfigurator | null = null + private hasInit: boolean = false; constructor(context: Context, params: ESObject = {}) { this.context = context; this.uiAbility = FlutterManager.getInstance().getUIAbility(context); this.parameters = params; this.windowStage = FlutterManager.getInstance().getWindowStage(this.uiAbility); + this.hasInit = false; } async aboutToAppear() { Log.i(TAG, 'aboutToAppear'); - this.delegate = new FlutterAbilityAndEntryDelegate(this); - this.flutterView = this.delegate?.createView(this.context); - await this?.delegate?.onAttach(this.context); - Log.i(TAG, 'onAttach end'); - this?.delegate?.platformPlugin?.setUIAbilityContext(this.uiAbility!!.context); - this.delegate?.onCreate(); - this.delegate?.onWindowStageCreate() - this.windowStage?.on('windowStageEvent', this.windowStageEventCallback); + if (this.hasInit == false) { + this.delegate = new FlutterAbilityAndEntryDelegate(this); + this.flutterView = this.delegate?.createView(this.context); + await this?.delegate?.onAttach(this.context); + Log.i(TAG, 'onAttach end'); + this?.delegate?.platformPlugin?.setUIAbilityContext(this.uiAbility!!.context); + this.delegate?.onCreate(); + this.delegate?.onWindowStageCreate() + this.windowStage?.on('windowStageEvent', this.windowStageEventCallback); + this.hasInit = true; + } } private windowStageEventCallback = (data: window.WindowStageEventType) => { -- Gitee From 746e9759805deea8229f1fc76201b80573b1a94b Mon Sep 17 00:00:00 2001 From: xiaoxiang Date: Tue, 23 Jan 2024 16:39:50 +0800 Subject: [PATCH 05/73] =?UTF-8?q?index.d.ets=E6=9A=B4=E9=9C=B2=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiaoxiang --- .../ohos/flutter_embedding/flutter/index.ets | 183 ++++++++++++++++-- 1 file changed, 171 insertions(+), 12 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/index.ets b/shell/platform/ohos/flutter_embedding/flutter/index.ets index a69f1c32bb..21cb665ac4 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/index.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/index.ets @@ -13,22 +13,181 @@ * limitations under the License. */ -import FlutterManager from './src/main/ets/embedding/ohos/FlutterManager'; -import { FlutterAbility } from './src/main/ets/embedding/ohos/FlutterAbility' -import { FlutterPage } from './src/main/ets/embedding/ohos/FlutterPage' -import { FlutterPlugin } from './src/main/ets/embedding/engine/plugins/FlutterPlugin' -import { FlutterView } from './src/main/ets/view/FlutterView'; -import FlutterEntry from './src/main/ets/embedding/ohos/FlutterEntry'; +import FlutterInjector from './src/main/ets/FlutterInjector'; +import FlutterPluginRegistry from './src/main/ets/app/FlutterPluginRegistry'; +import FlutterComponent from './src/main/ets/component/FlutterComponent'; import FlutterEngine from './src/main/ets/embedding/engine/FlutterEngine'; +import FlutterEngineCache from './src/main/ets/embedding/engine/FlutterEngineCache'; +import FlutterEngineConnectionRegistry from './src/main/ets/embedding/engine/FlutterEngineConnectionRegistry'; +import FlutterEngineGroup from './src/main/ets/embedding/engine/FlutterEngineGroup'; +import FlutterEngineGroupCache from './src/main/ets/embedding/engine/FlutterEngineGroupCache'; +import FlutterNapi from './src/main/ets/embedding/engine/FlutterNapi'; +import { FlutterOverlaySurface } from './src/main/ets/embedding/engine/FlutterOverlaySurface'; +import FlutterShellArgs from './src/main/ets/embedding/engine/FlutterShellArgs'; +import DartExecutor from './src/main/ets/embedding/engine/dart/DartExecutor'; +import { DartMessenger } from './src/main/ets/embedding/engine/dart/DartMessenger'; +import { PlatformMessageHandler } from './src/main/ets/embedding/engine/dart/PlatformMessageHandler'; +import ApplicationInfoLoader from './src/main/ets/embedding/engine/loader/ApplicationInfoLoader'; +import FlutterApplicationInfo from './src/main/ets/embedding/engine/loader/FlutterApplicationInfo'; +import FlutterLoader from './src/main/ets/embedding/engine/loader/FlutterLoader'; +import { FlutterMutatorView } from './src/main/ets/embedding/engine/mutatorsstack/FlutterMutatorView'; +import { FlutterMutatorsStack } from './src/main/ets/embedding/engine/mutatorsstack/FlutterMutatorsStack'; +import { FlutterPlugin } from './src/main/ets/embedding/engine/plugins/FlutterPlugin'; +import AbilityAware from './src/main/ets/embedding/engine/plugins/ability/AbilityAware'; +import AbilityControlSurface from './src/main/ets/embedding/engine/plugins/ability/AbilityControlSurface'; +import { AbilityPluginBinding } from './src/main/ets/embedding/engine/plugins/ability/AbilityPluginBinding'; +import GeneratedPluginRegister from './src/main/ets/embedding/engine/plugins/util/GeneratedPluginRegister'; +import { FlutterUiDisplayListener } from './src/main/ets/embedding/engine/renderer/FlutterUiDisplayListener'; +import AccessibilityChannel from './src/main/ets/embedding/engine/systemchannels/AccessibilityChannel'; +import KeyEventChannel from './src/main/ets/embedding/engine/systemchannels/KeyEventChannel'; +import LifecycleChannel from './src/main/ets/embedding/engine/systemchannels/LifecycleChannel'; +import LocalizationChannel from './src/main/ets/embedding/engine/systemchannels/LocalizationChannel'; +import MouseCursorChannel from './src/main/ets/embedding/engine/systemchannels/MouseCursorChannel'; +import NavigationChannel from './src/main/ets/embedding/engine/systemchannels/NavigationChannel'; +import PlatformChannel from './src/main/ets/embedding/engine/systemchannels/PlatformChannel'; +import PlatformViewsChannel from './src/main/ets/embedding/engine/systemchannels/PlatformViewsChannel'; +import RestorationChannel from './src/main/ets/embedding/engine/systemchannels/RestorationChannel'; +import SettingsChannel from './src/main/ets/embedding/engine/systemchannels/SettingsChannel'; +import SystemChannel from './src/main/ets/embedding/engine/systemchannels/SystemChannel'; +import TestChannel from './src/main/ets/embedding/engine/systemchannels/TestChannel'; +import TextInputChannel from './src/main/ets/embedding/engine/systemchannels/TextInputChannel'; +import ExclusiveAppComponent from './src/main/ets/embedding/ohos/ExclusiveAppComponent'; +import { FlutterAbility } from './src/main/ets/embedding/ohos/FlutterAbility'; +import { FlutterAbilityAndEntryDelegate } from './src/main/ets/embedding/ohos/FlutterAbilityAndEntryDelegate'; +import FlutterAbilityLaunchConfigs from './src/main/ets/embedding/ohos/FlutterAbilityLaunchConfigs'; +import FlutterEngineConfigurator from './src/main/ets/embedding/ohos/FlutterEngineConfigurator'; +import FlutterEngineProvider from './src/main/ets/embedding/ohos/FlutterEngineProvider'; +import FlutterEntry from './src/main/ets/embedding/ohos/FlutterEntry'; +import FlutterManager from './src/main/ets/embedding/ohos/FlutterManager'; +import { FlutterPage } from './src/main/ets/embedding/ohos/FlutterPage'; +import KeyboardManager from './src/main/ets/embedding/ohos/KeyboardManager'; +import OhosTouchProcessor from './src/main/ets/embedding/ohos/OhosTouchProcessor'; +import Settings from './src/main/ets/embedding/ohos/Settings'; +import { TouchEventTracker } from './src/main/ets/embedding/ohos/TouchEventTracker'; +import WindowInfoRepositoryCallbackAdapterWrapper + from './src/main/ets/embedding/ohos/WindowInfoRepositoryCallbackAdapterWrapper'; import PlatformPlugin from './src/main/ets/plugin/PlatformPlugin'; +import BasicMessageChannel from './src/main/ets/plugin/common/BasicMessageChannel'; +import BinaryCodec from './src/main/ets/plugin/common/BinaryCodec'; +import { BinaryMessenger } from './src/main/ets/plugin/common/BinaryMessenger'; +import EventChannel from './src/main/ets/plugin/common/EventChannel'; +import FlutterException from './src/main/ets/plugin/common/FlutterException'; +import JSONMessageCodec from './src/main/ets/plugin/common/JSONMessageCodec'; +import JSONMethodCodec from './src/main/ets/plugin/common/JSONMethodCodec'; +import MessageCodec from './src/main/ets/plugin/common/MessageCodec'; +import MethodCall from './src/main/ets/plugin/common/MethodCall'; +import MethodChannel from './src/main/ets/plugin/common/MethodChannel'; +import MethodCodec from './src/main/ets/plugin/common/MethodCodec'; +import StandardMessageCodec from './src/main/ets/plugin/common/StandardMessageCodec'; +import StandardMethodCodec from './src/main/ets/plugin/common/StandardMethodCodec'; +import StringCodec from './src/main/ets/plugin/common/StringCodec'; +import { ListenableEditingState } from './src/main/ets/plugin/editing/ListenableEditingState'; +import { TextEditingDelta } from './src/main/ets/plugin/editing/TextEditingDelta'; +import TextInputPlugin from './src/main/ets/plugin/editing/TextInputPlugin'; +import LocalizationPlugin from './src/main/ets/plugin/localization/LocalizationPlugin'; +import MouseCursorPlugin from './src/main/ets/plugin/mouse/MouseCursorPlugin'; +import { AccessibilityEventsDelegate } from './src/main/ets/plugin/platform/AccessibilityEventsDelegate'; +import { PlatformOverlayView } from './src/main/ets/plugin/platform/PlatformOverlayView'; +import PlatformView from './src/main/ets/plugin/platform/PlatformView'; +import PlatformViewFactory from './src/main/ets/plugin/platform/PlatformViewFactory'; +import PlatformViewRegistry from './src/main/ets/plugin/platform/PlatformViewRegistry'; +import PlatformViewRegistryImpl from './src/main/ets/plugin/platform/PlatformViewRegistryImpl'; +import { PlatformViewWrapper } from './src/main/ets/plugin/platform/PlatformViewWrapper'; +import { PlatformViewsAccessibilityDelegate } from './src/main/ets/plugin/platform/PlatformViewsAccessibilityDelegate'; +import PlatformViewsController from './src/main/ets/plugin/platform/PlatformViewsController'; +import AccessibilityBridge from './src/main/ets/view/AccessibilityBridge'; +import { FlutterCallbackInformation } from './src/main/ets/view/FlutterCallbackInformation'; +import FlutterNativeView from './src/main/ets/view/FlutterNativeView'; +import FlutterRunArguments from './src/main/ets/view/FlutterRunArguments'; +import { FlutterView } from './src/main/ets/view/FlutterView'; +import { TextureRegistry } from './src/main/ets/view/TextureRegistry'; export { - PlatformPlugin, - FlutterPlugin, - FlutterView, - FlutterEntry, + FlutterInjector, + FlutterPluginRegistry, + FlutterComponent, FlutterEngine, + FlutterEngineCache, + FlutterEngineConnectionRegistry, + FlutterEngineGroup, + FlutterEngineGroupCache, + FlutterNapi, + FlutterOverlaySurface, + FlutterShellArgs, + DartExecutor, + DartMessenger, + PlatformMessageHandler, + ApplicationInfoLoader, + FlutterApplicationInfo, + FlutterLoader, + FlutterMutatorView, + FlutterMutatorsStack, + FlutterPlugin, + AbilityAware, + AbilityControlSurface, + AbilityPluginBinding, + GeneratedPluginRegister, + FlutterUiDisplayListener, + AccessibilityChannel, + KeyEventChannel, + LifecycleChannel, + LocalizationChannel, + MouseCursorChannel, + NavigationChannel, + PlatformChannel, + PlatformViewsChannel, + RestorationChannel, + SettingsChannel, + SystemChannel, + TestChannel, + TextInputChannel, + ExclusiveAppComponent, FlutterAbility, + FlutterAbilityAndEntryDelegate, + FlutterAbilityLaunchConfigs, + FlutterEngineConfigurator, + FlutterEngineProvider, + FlutterEntry, FlutterManager, - FlutterPage -} \ No newline at end of file + FlutterPage, + KeyboardManager, + OhosTouchProcessor, + Settings, + TouchEventTracker, + WindowInfoRepositoryCallbackAdapterWrapper, + PlatformPlugin, + BasicMessageChannel, + BinaryCodec, + BinaryMessenger, + EventChannel, + FlutterException, + JSONMessageCodec, + JSONMethodCodec, + MessageCodec, + MethodCall, + MethodChannel, + MethodCodec, + StandardMessageCodec, + StandardMethodCodec, + StringCodec, + ListenableEditingState, + TextEditingDelta, + TextInputPlugin, + LocalizationPlugin, + MouseCursorPlugin, + AccessibilityEventsDelegate, + PlatformOverlayView, + PlatformView, + PlatformViewFactory, + PlatformViewRegistry, + PlatformViewRegistryImpl, + PlatformViewWrapper, + PlatformViewsAccessibilityDelegate, + PlatformViewsController, + AccessibilityBridge, + FlutterCallbackInformation, + FlutterNativeView, + FlutterRunArguments, + FlutterView, + TextureRegistry, +} -- Gitee From 49921622ebe4be0f44dbc3585d976cc41168c0a0 Mon Sep 17 00:00:00 2001 From: xiaoxiang Date: Wed, 24 Jan 2024 12:59:51 +0800 Subject: [PATCH 06/73] lint Signed-off-by: xiaoxiang --- .../ohos/flutter_embedding/flutter/index.ets | 2 - .../main/ets/app/FlutterPluginRegistry.ets | 6 +- .../ets/plugin/common/BinaryMessenger.ets | 6 +- .../main/ets/plugin/common/EventChannel.ets | 14 +- .../src/main/ets/view/FlutterNativeView.ets | 137 ------------------ .../src/main/ets/view/FlutterRunArguments.ets | 6 + 6 files changed, 20 insertions(+), 151 deletions(-) delete mode 100644 shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterNativeView.ets diff --git a/shell/platform/ohos/flutter_embedding/flutter/index.ets b/shell/platform/ohos/flutter_embedding/flutter/index.ets index 21cb665ac4..c146ae457d 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/index.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/index.ets @@ -97,7 +97,6 @@ import { PlatformViewsAccessibilityDelegate } from './src/main/ets/plugin/platfo import PlatformViewsController from './src/main/ets/plugin/platform/PlatformViewsController'; import AccessibilityBridge from './src/main/ets/view/AccessibilityBridge'; import { FlutterCallbackInformation } from './src/main/ets/view/FlutterCallbackInformation'; -import FlutterNativeView from './src/main/ets/view/FlutterNativeView'; import FlutterRunArguments from './src/main/ets/view/FlutterRunArguments'; import { FlutterView } from './src/main/ets/view/FlutterView'; import { TextureRegistry } from './src/main/ets/view/TextureRegistry'; @@ -186,7 +185,6 @@ export { PlatformViewsController, AccessibilityBridge, FlutterCallbackInformation, - FlutterNativeView, FlutterRunArguments, FlutterView, TextureRegistry, diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/app/FlutterPluginRegistry.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/app/FlutterPluginRegistry.ets index 2a2a44964d..4eabe6ad35 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/app/FlutterPluginRegistry.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/app/FlutterPluginRegistry.ets @@ -18,11 +18,13 @@ import PlatformViewController from '../plugin/platform/PlatformViewsController' export default class FlutterPluginRegistry { private mPlatformViewsController: PlatformViewController; - private mFlutterView: FlutterView; - private mContext: common.Context; + private mFlutterView: FlutterView | null; + private mContext: common.Context | null; constructor() { this.mPlatformViewsController = new PlatformViewController(); + this.mFlutterView = null; + this.mContext = null; } attach(flutterView: FlutterView, context: common.Context): void { diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/BinaryMessenger.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/BinaryMessenger.ets index e0b55276be..68925a8b1a 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/BinaryMessenger.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/BinaryMessenger.ets @@ -49,7 +49,7 @@ export interface BinaryReply { * outgoing replies must place the reply bytes between position zero and current position. * Reply receivers can read from the buffer directly. */ - reply(reply: ArrayBuffer): void; + reply(reply: ArrayBuffer | null): void; } /** Handler for incoming binary messages from Flutter. */ @@ -96,7 +96,7 @@ export interface BinaryMessenger { * @param message the message payload, a direct-allocated {@link ByteBuffer} with the message * bytes between position zero and current position, or null. */ - send(channel: String, message: ArrayBuffer): void; + send(channel: String, message: ArrayBuffer | null): void; /** * Sends a binary message to the Flutter application, optionally expecting a reply. @@ -127,7 +127,7 @@ export interface BinaryMessenger { * the handler. Specifying null means execute on the platform thread. */ //setMessageHandler(channel: String, handler: BinaryMessageHandler) - setMessageHandler(channel: String, handler: BinaryMessageHandler, taskQueue?: TaskQueue): void; + setMessageHandler(channel: String, handler: BinaryMessageHandler | null, taskQueue?: TaskQueue): void; // { // if (taskQueue != null) { // throw new Error("setMessageHandler called with nonnull taskQueue is not supported.") diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/EventChannel.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/EventChannel.ets index 166659a32e..cc792fbb52 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/EventChannel.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/EventChannel.ets @@ -40,7 +40,7 @@ export default class EventChannel { private messenger: BinaryMessenger; private name: string; private codec: MethodCodec; - private taskQueue: TaskQueue; + private taskQueue: TaskQueue | undefined; constructor(messenger: BinaryMessenger, name: string, codec?: MethodCodec, taskQueue?: TaskQueue) { this.messenger = messenger @@ -240,22 +240,22 @@ class EventSinkImplementation implements EventSink { } } -class AtomicReference { - private value: T; +class AtomicReference { + private value: T | null; - constructor(value: T) { + constructor(value: T | null) { this.value = value } - get(): T { + get(): T | null { return this.value; } - set(newValue: T): void { + set(newValue: T | null): void { this.value = newValue; } - getAndSet(newValue: T) { + getAndSet(newValue: T | null): T | null { const oldValue = this.value; this.value = newValue; return oldValue; diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterNativeView.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterNativeView.ets deleted file mode 100644 index 9138ad7285..0000000000 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterNativeView.ets +++ /dev/null @@ -1,137 +0,0 @@ -/* -* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import common from '@ohos.app.ability.common'; -import DartExecutor from '../embedding/engine/dart/DartExecutor'; -import { EngineLifecycleListener } from '../embedding/engine/FlutterEngine'; -import FlutterNapi from '../embedding/engine/FlutterNapi'; -import Log from '../util/Log'; -import FlutterPluginRegistry from '../app/FlutterPluginRegistry'; -import FlutterRunArguments from './FlutterRunArguments'; -import { FlutterView } from './FlutterView'; - -const TAG: string = "FlutterNativeView"; - -export default class FlutterNativeView { - private mContext: common.Context; - private mPluginRegistry: FlutterPluginRegistry; - private mFlutterNapi: FlutterNapi; - private dartExecutor: DartExecutor; - private mFlutterView: FlutterView; - private applicationIsRunning: boolean; - - constructor(context: common.Context, isBackgroundView?: boolean) { - if (isBackgroundView) { - Log.i(TAG, "isBackgroundView is no longer supported and will be ignored"); - } - this.mContext = context; - this.mPluginRegistry = new FlutterPluginRegistry(); - this.mFlutterNapi = new FlutterNapi(); - //this.mFlutterNapi.addIsDisplayingFlutterUiListener(this.flutterUiDisplayListener); - this.dartExecutor = new DartExecutor(this.mFlutterNapi, this.mContext.resourceManager); - this.mFlutterNapi.addEngineLifecycleListener(new EngineLifecycleListenerImpl(this.mFlutterView, this.mPluginRegistry)); - this.attach(this.mFlutterNapi, this.dartExecutor); - this.assertAttached(this.mFlutterNapi); - } - - attach(flutterNapi: FlutterNapi, dartExecutor: DartExecutor): void { - flutterNapi.attachToNative(); - dartExecutor.onAttachedToNAPI(); - } - - assertAttached(flutterNapi: FlutterNapi): void { - if (!this.isAttached(flutterNapi)) { - throw new Error('Platform View is not attached'); - } - } - - isAttached(flutterNapi: FlutterNapi): boolean { - return flutterNapi.isAttached(); - } - - detachFromFlutterView(): void { - this.mPluginRegistry.detach(); - this.mFlutterView = null; - } - - destroy(): void { - this.mPluginRegistry.destroy(); - this.dartExecutor.onDetachedFromNAPI(); - this.mFlutterView = null; - //this.mFlutterNapi.removeIsDisplayingFlutterUiListener(this.flutterUiDisplayListener); - this.applicationIsRunning = false; - } - - getDartExecutor(): DartExecutor { - return this.dartExecutor; - } - - getPluginRegistry(): FlutterPluginRegistry { - return this.mPluginRegistry; - } - - attachViewAndAbility(flutterView: FlutterView, context: common.Context): void { - this.mFlutterView = flutterView; - this.mPluginRegistry.attach(flutterView, context); - } - - runFromBundle(args: FlutterRunArguments): void { - if (args.entrypoint == null) { - throw new Error("an entrypoint must be specific"); - } - this.assertAttached(this.mFlutterNapi); - if (this.applicationIsRunning) { - throw new Error("this flutter engine instance is already running an application"); - } - this.mFlutterNapi.runBundleAndSnapshotFromLibrary(args.bundlePath, args.entrypoint, args.libraryPath, this.mContext.resourceManager, null); - this.applicationIsRunning = true; - } - - isApplicationRunning(): boolean { - return this.applicationIsRunning; - } - - // getObservatoryUri(): string { - // return this.mFlutterNapi.getObservatoryUri(); - // } -} - -class EngineLifecycleListenerImpl implements EngineLifecycleListener { - private flutterView: FlutterView; - private pluginRegistry: FlutterPluginRegistry; - - onPreEngineRestart(): void { - if (this.flutterView != null) { - //this.flutterView.resetAccessibilityTree(); - } - - if (this.pluginRegistry == null) { - return; - } - - this.pluginRegistry.onPreEngineRestart(); - } - - onEngineWillDestroy(): void { - - } - - constructor(flutterView: FlutterView, pluginRegistry: FlutterPluginRegistry) { - this.flutterView = flutterView; - this.pluginRegistry = pluginRegistry; - } -} - - diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterRunArguments.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterRunArguments.ets index d17ec28d1f..c81e33f381 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterRunArguments.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterRunArguments.ets @@ -17,4 +17,10 @@ export default class FlutterRunArguments { public bundlePath: string; public entrypoint: string; public libraryPath: string; + + constructor(bundlePath: string, entrypoint: string, libraryPath: string) { + this.bundlePath = bundlePath; + this.entrypoint = entrypoint; + this.libraryPath = libraryPath; + } } \ No newline at end of file -- Gitee From f1fcec04102e24d44f08f4a9084637b9be04ea94 Mon Sep 17 00:00:00 2001 From: wwyang <137208408@qq.com> Date: Fri, 26 Jan 2024 17:29:51 +0800 Subject: [PATCH 07/73] =?UTF-8?q?=E8=A7=A3=E5=86=B3XComponent=20type?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E9=94=99=E8=AF=AF=E5=BC=95=E8=B5=B7=E7=9A=84?= =?UTF-8?q?flutterpage=E5=88=87=E6=8D=A2=E6=97=B6=E5=87=BA=E7=8E=B0?= =?UTF-8?q?=E9=BB=91=E5=B1=8F=E5=92=8Cflutterpage=E5=8D=8A=E5=B1=8F?= =?UTF-8?q?=E9=80=8F=E6=98=8E=E6=97=A0=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 Signed-off-by: wwyang <137208408@qq.com> --- .../flutter/src/main/ets/component/XComponentStruct.ets | 2 +- .../flutter/src/main/ets/embedding/ohos/FlutterPage.ets | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/component/XComponentStruct.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/component/XComponentStruct.ets index e9d66ef987..d8198a8b32 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/component/XComponentStruct.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/component/XComponentStruct.ets @@ -21,7 +21,7 @@ struct XComponentStruct { dvModelParams: DVModelParameters = new DVModelParameters(); build() { - XComponent({ id: (this.dvModelParams as Record)["xComponentId"], type: 'texture', libraryname: 'flutter'}) + XComponent({ id: (this.dvModelParams as Record)["xComponentId"], type: XComponentType.TEXTURE, libraryname: 'flutter'}) .onLoad((context) => { this.context = context; }) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets index 483813fa6a..53e7ef62d1 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets @@ -46,7 +46,7 @@ export struct FlutterPage { build() { Stack() { - XComponent({ id: this.viewId, type: 'texture', libraryname: 'flutter' }) + XComponent({ id: this.viewId, type: XComponentType.TEXTURE, libraryname: 'flutter' }) .focusable(true) .onLoad((context) => { this.flutterView?.onSurfaceCreated() -- Gitee From 330b1673786ee314a521d40625b488bfb50884ed Mon Sep 17 00:00:00 2001 From: zhan-linlin <17301907374@163.com> Date: Mon, 29 Jan 2024 15:26:30 +0800 Subject: [PATCH 08/73] =?UTF-8?q?=E5=A4=84=E7=90=86=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhan-linlin <17301907374@163.com> --- .../ohos/flutter_embedding/flutter/src/main/ets/util/Log.ets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/util/Log.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/util/Log.ets index 8dcfb79903..33796b25fe 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/util/Log.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/util/Log.ets @@ -91,7 +91,7 @@ export default class Log { */ static e(tag: string, format: string, ...args: ESObject[]) { if (Log.isLoggable(HiLog.LogLevel.ERROR)) { - args.format((item: ESObject, index: number) => { + args.forEach((item: ESObject, index: number) => { if (item instanceof Error) { args[index] = item.message + item.stack; } -- Gitee From 4bfbf9b80e295b87c921f15811bf057f0fa40e56 Mon Sep 17 00:00:00 2001 From: zhan-linlin <17301907374@163.com> Date: Tue, 30 Jan 2024 16:03:31 +0800 Subject: [PATCH 09/73] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=A2=9E=E9=87=8F?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E6=89=A7=E8=A1=8C=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhan-linlin <17301907374@163.com> --- .../systemchannels/TextInputChannel.ets | 62 ++++++++++++----- .../plugin/editing/ListenableEditingState.ets | 67 +++++++++++++++---- .../ets/plugin/editing/TextEditingDelta.ets | 30 ++++++++- .../ets/plugin/editing/TextInputPlugin.ets | 60 +++++++++-------- 4 files changed, 160 insertions(+), 59 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/TextInputChannel.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/TextInputChannel.ets index c02c3ad005..315a433f84 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/TextInputChannel.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/TextInputChannel.ets @@ -20,6 +20,8 @@ import TextInputPlugin from '../../../plugin/editing/TextInputPlugin'; import Log from '../../../util/Log'; import DartExecutor from '../dart/DartExecutor'; import inputMethod from '@ohos.inputMethod'; +import ArrayList from '@ohos.util.ArrayList'; +import { TextEditingDelta, TextEditingDeltaJson } from '../../../plugin/editing/TextEditingDelta'; const TAG = "TextInputChannel"; @@ -56,6 +58,18 @@ export default class TextInputChannel { return state; } + createEditingDeltaJSON(batchDeltas: ArrayList): EditingDelta { + let deltas: Array = []; + batchDeltas.forEach((val, idx, array) => { + deltas.push(val.toJSON()); + }) + + let state: EditingDelta = { + deltas: deltas, + }; + return state; + } + /** * Instructs Flutter to update its text input editing state to reflect the given configuration. */ @@ -72,6 +86,12 @@ export default class TextInputChannel { this.channel.invokeMethod('TextInputClient.updateEditingState', [inputClientId, state]); } + updateEditingStateWithDeltas(inputClientId: number, batchDeltas: ArrayList): void { + Log.d(TAG, "updateEditingStateWithDeltas:" + "batchDeltas length: " + batchDeltas.length); + const state: ESObject = this.createEditingDeltaJSON(batchDeltas); + this.channel.invokeMethod('TextInputClient.updateEditingStateWithDeltas', [inputClientId, state]); + } + newline(inputClientId: number): void { Log.d(TAG, "Sending 'newline' message."); this.channel.invokeMethod("TextInputClient.performAction", [inputClientId, "TextInputAction.newline"]); @@ -124,7 +144,6 @@ export default class TextInputChannel { performPrivateCommand(inputClientId: number, action: string, data: ESObject) { } - } interface EditingState { @@ -135,6 +154,12 @@ interface EditingState { composingExtent: number; } + +interface EditingDelta { + deltas: Array; +} + + export interface TextInputMethodHandler { show(): void; @@ -175,12 +200,12 @@ export class Configuration { enableSuggestions: boolean, enableIMEPersonalizedLearning: boolean, enableDeltaModel: boolean, - textCapitalization:TextCapitalization, + textCapitalization: TextCapitalization, inputType: InputType, inputAction: Number, actionLabel: String, - autofill :boolean, - contentListString:[], + autofill: boolean, + contentListString: [], fields: Configuration[] ) { this.obscureText = obscureText; @@ -197,8 +222,9 @@ export class Configuration { this.fields = fields } + static getTextCapitalizationFromValue(encodedName: string): TextCapitalization { - let textKeys= ["CHARACTERS", "WORDS","SENTENCES", "NONE"]; + let textKeys = ["CHARACTERS", "WORDS", "SENTENCES", "NONE"]; for (let textKey of textKeys) { if (TextCapitalization[textKey] === encodedName) { return textKey as TextCapitalization; @@ -206,8 +232,9 @@ export class Configuration { } throw new Error("No such TextCapitalization: " + encodedName); } - private static inputActionFromTextInputAction(inputActionName:string):number{ - switch(inputActionName){ + + private static inputActionFromTextInputAction(inputActionName: string): number { + switch (inputActionName) { case "TextInputAction.previous": return inputMethod.EnterKeyType.PREVIOUS case "TextInputAction.unspecified": @@ -228,23 +255,24 @@ export class Configuration { } } - static fromJson(json:ESObject) { - const inputActionName:string = json.inputAction; + + static fromJson(json: ESObject) { + const inputActionName: string = json.inputAction; if (!inputActionName) { throw new Error("Configuration JSON missing 'inputAction' property."); } - let fields:Array = new Array(); + let fields: Array = new Array(); if (json.fields !== null && json.fields !== undefined) { - fields = json.fields.map((field:ESObject):ESObject => Configuration.fromJson(field)); + fields = json.fields.map((field: ESObject): ESObject => Configuration.fromJson(field)); } - const inputAction:number = Configuration.inputActionFromTextInputAction(inputActionName); + const inputAction: number = Configuration.inputActionFromTextInputAction(inputActionName); // Build list of content commit mime types from the data in the JSON list. - const contentList:Array = []; + const contentList: Array = []; if (json.contentCommitMimeTypes !== null && json.contentCommitMimeTypes !== undefined) { - json.contentCommitMimeTypes.forEach((type:ESObject) => { + json.contentCommitMimeTypes.forEach((type: ESObject) => { contentList.push(type); }); } @@ -263,7 +291,6 @@ export class Configuration { fields ); } - } enum TextCapitalization { @@ -304,7 +331,7 @@ export class InputType { } static getTextInputTypeFromValue(encodedName: string): TextInputType { - let textKeys = [ "TEXT", "DATETIME","NAME" , "POSTAL_ADDRESS", "NUMBER", "PHONE", "MULTILINE", "EMAIL_ADDRESS", "URL", "VISIBLE_PASSWORD", "NONE" ,]; + let textKeys = ["TEXT", "DATETIME", "NAME", "POSTAL_ADDRESS", "NUMBER", "PHONE", "MULTILINE", "EMAIL_ADDRESS", "URL", "VISIBLE_PASSWORD", "NONE",]; for (let textKey of textKeys) { if (TextInputType[textKey] === encodedName) { return textKey as TextInputType; @@ -403,7 +430,7 @@ class TextInputCallback implements MethodCallHandler { break; case "TextInput.setClient": const textInputClientId: number = args[0] as number; - const jsonConfiguration :string = args[1] ; + const jsonConfiguration: string = args[1]; const config: Configuration | null = Configuration.fromJson(jsonConfiguration); this.textInputMethodHandler.setClient(textInputClientId, config); @@ -442,5 +469,4 @@ class TextInputCallback implements MethodCallHandler { break; } } - } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/ListenableEditingState.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/ListenableEditingState.ets index 953f7cad09..4c215d195d 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/ListenableEditingState.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/ListenableEditingState.ets @@ -19,10 +19,11 @@ import inputMethod from '@ohos.inputMethod'; import ArrayList from '@ohos.util.ArrayList'; import { TextEditingDelta } from './TextEditingDelta'; import TextInputChannel from '../../embedding/engine/systemchannels/TextInputChannel'; -const TAG = "ListenableEditingState"; -export class ListenableEditingState { - private TextInputChannel: TextInputChannel | null = null ; +const TAG = "ListenableEditingState"; + +export class ListenableEditingState { + private TextInputChannel: TextInputChannel | null = null; private client: number = 0 //Cache used to storage software keyboard input action private mStringCache: string; @@ -56,6 +57,34 @@ export class ListenableEditingState { this.mComposingEndCache = -1; } + extractBatchTextEditingDeltas(): ArrayList { + let currentBatchDeltas = new ArrayList(); + this.mBatchTextEditingDeltas.forEach((data) => { + currentBatchDeltas.add(data); + }) + this.mBatchTextEditingDeltas.clear(); + return currentBatchDeltas; + } + + clearBatchDeltas():void { + this.mBatchTextEditingDeltas.clear(); + } + + replace(start: number, end: number, tb: String, tbStart: number, tbEnd: number): void { + const placeIndex = this.mSelectionStartCache < this.mSelectionEndCache ? this.mSelectionStartCache : this.mSelectionEndCache; + + this.mBatchTextEditingDeltas.add( + new TextEditingDelta( + this.mStringCache.toString(), + placeIndex + tbEnd, + placeIndex + tbEnd, + this.getComposingStart(), + this.getComposingEnd(), + start, + end + tbStart, + tb.toString() + )); + } getSelectionStart(): number { return this.mSelectionStartCache; @@ -116,17 +145,23 @@ export class ListenableEditingState { } handleInsertTextEvent(text: string): void { + let start = this.mSelectionStartCache < this.mSelectionEndCache? this.mSelectionStartCache :this.mSelectionEndCache; + let end = this.mSelectionStartCache > this.mSelectionEndCache? this.mSelectionStartCache :this.mSelectionEndCache; + const length = text.length; + this.replace(start,end,text,0,length); + if(this.mStringCache.length == this.mSelectionStartCache) { //Insert text one by one - this.mStringCache += text; + let tempStr: string = this.mStringCache.substring(0,start) + text + this.mStringCache.substring(end); + this.mStringCache = tempStr; this.setSelectionStart(this.mStringCache.length); this.setSelectionEnd(this.mStringCache.length); } else if(this.mStringCache.length > this.mSelectionStartCache) { //Insert text in the middle of string - let tempStr: string = this.mStringCache.substring(0, this.mSelectionStartCache) + text + this.mStringCache.substring(this.mSelectionStartCache); + let tempStr: string = this.mStringCache.substring(0, start) + text + this.mStringCache.substring(end); this.mStringCache = tempStr; - this.mSelectionStartCache += text.length; + this.mSelectionStartCache = start+text.length; this.mSelectionEndCache = this.mSelectionStartCache; } if(this.mListeners == null) { @@ -217,22 +252,30 @@ export class ListenableEditingState { } handleDeleteEvent(leftOrRight: boolean, length: number): void { + let start = this.mSelectionStartCache < this.mSelectionEndCache? this.mSelectionStartCache :this.mSelectionEndCache; + let end = this.mSelectionStartCache > this.mSelectionEndCache? this.mSelectionStartCache :this.mSelectionEndCache; + if(leftOrRight == false) { //delete left - if(this.mSelectionStartCache == 0) { + if(start == 0 && end == 0) { return; } - this.mSelectionStartCache -= length; - let tempStr: string = this.mStringCache.slice(0, this.mSelectionStartCache) + this.mStringCache.slice(this.mSelectionStartCache + length); + const startData = start== end ?start-1:start; + const tbEnd = start== end ?-1:0; + this.replace(startData,end,"",0,tbEnd); + this.mSelectionStartCache = startData; + let tempStr: string = this.mStringCache.slice(0, startData) + this.mStringCache.slice(end); this.mStringCache = tempStr; this.mSelectionEndCache = this.mSelectionStartCache; } else if(leftOrRight == true) { //delete right - if(this.mSelectionStartCache == this.mStringCache.length) { + if(start == this.mStringCache.length) { return; } - this.mSelectionEndCache += length; - let tempStr: string = this.mStringCache.slice(0,this.mSelectionStartCache) + this.mStringCache.slice(this.mSelectionEndCache); + const tbStart= start== end ?1:0; + this.replace(start,end,"",tbStart,0); + this.mSelectionEndCache = start; + let tempStr: string = this.mStringCache.slice(0,start ) + (end+1>=this.mStringCache.length?"":this.mStringCache.slice( end +1 )); this.mStringCache = tempStr; this.mSelectionStartCache = this.mSelectionEndCache; } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextEditingDelta.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextEditingDelta.ets index 1aa1b2d872..495c4a5182 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextEditingDelta.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextEditingDelta.ets @@ -38,11 +38,11 @@ export class TextEditingDelta { this.newSelectionEnd = selectionEnd; this.newComposingStart = composingStart; this.newComposingEnd = composingEnd; - if(replacementDestinationStart === undefined || + if (replacementDestinationStart === undefined || replacementDestinationEnd === undefined || replacementSource === undefined) { this.setDeltas(oldEditable, "", -1, -1); - } else { + } else { this.setDeltas( oldEditable, replacementSource, @@ -58,4 +58,30 @@ export class TextEditingDelta { this.deltaStart = newStart; this.deltaEnd = newExtent; } + + toJSON(): TextEditingDeltaJson { + let state: TextEditingDeltaJson = { + oldText: this.oldText.toString(), + deltaText: this.deltaText.toString(), + deltaStart: this.deltaStart, + deltaEnd: this.deltaEnd, + selectionBase: this.newSelectionStart, + selectionExtent: this.newSelectionEnd, + composingBase: this.newComposingStart, + composingExtent: this.newComposingEnd, + }; + return state; + } +} + + +export interface TextEditingDeltaJson { + oldText: string; + deltaText: string; + deltaStart: number; + deltaEnd: number; + selectionBase: number; + selectionExtent: number; + composingBase: number; + composingExtent: number; } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets index ca7f22a339..9252bf0b02 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets @@ -13,14 +13,17 @@ * limitations under the License. */ -import TextInputChannel, { Configuration, TextEditState, +import TextInputChannel, { + Configuration, + TextEditState, TextInputMethodHandler, - TextInputType } from '../../embedding/engine/systemchannels/TextInputChannel'; + TextInputType +} from '../../embedding/engine/systemchannels/TextInputChannel'; import inputMethod from '@ohos.inputMethod'; import Log from '../../util/Log'; import { EditingStateWatcher, ListenableEditingState } from './ListenableEditingState'; -export default class TextInputPlugin implements EditingStateWatcher{ +export default class TextInputPlugin implements EditingStateWatcher { private static TAG = "TextInputPlugin"; private textInputChannel: TextInputChannel; private mTextInputHandler: TextInputMethodHandlerImpl; @@ -42,19 +45,25 @@ export default class TextInputPlugin implements EditingStateWatcher{ didChangeEditingState(textChanged: boolean, selectionChanged: boolean, composingRegionChanged: boolean): void { let editable = this.mTextInputHandler.mEditable; let inputTarget = this.mTextInputHandler.inputTarget; - this.textInputChannel.updateEditingState(inputTarget.id, editable.getStringCache(), - editable.getSelectionStart(), editable.getSelectionEnd(), - editable.getComposingStart(), editable.getComposingEnd()) + let configuration = this.mTextInputHandler.configuration; + if (configuration!= null && configuration.enableDeltaModel) { + this.textInputChannel.updateEditingStateWithDeltas(inputTarget.id,editable.extractBatchTextEditingDeltas()); + editable.clearBatchDeltas(); + } else { + this.textInputChannel.updateEditingState(inputTarget.id, editable.getStringCache(), + editable.getSelectionStart(), editable.getSelectionEnd(), + editable.getComposingStart(), editable.getComposingEnd()) + } + } detach(): void { this.mTextInputHandler.inputMethodController.detach((err) => { - if(err) { + if (err) { Log.e(TextInputPlugin.TAG, "Failed to detach: " + JSON.stringify(err)); } }) } - } class TextInputMethodHandlerImpl implements TextInputMethodHandler { @@ -62,7 +71,7 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { private textConfig: inputMethod.TextConfig; inputMethodController: inputMethod.InputMethodController; inputTarget: InputTarget; - private configuration: Configuration | null = null; + public configuration: Configuration | null = null; mEditable: ListenableEditingState; private mRestartInputPending: boolean = false; private plugin: EditingStateWatcher | ESObject; @@ -74,7 +83,7 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { inputAttribute: { textInputType: 0, enterKeyType: 1 - }}; + } }; this.plugin = plugin; this.mEditable = new ListenableEditingState(null, 0); this.inputMethodController = inputMethod.getController(); @@ -82,7 +91,7 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { } show(): void { - if(this.keyboardStatus == KeyboardStatus.SHOW){ + if (this.keyboardStatus == KeyboardStatus.SHOW) { return; } this.showTextInput(); @@ -103,7 +112,7 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { } setClient(textInputClientId: number, configuration: Configuration | null): void { - Log.d(TextInputMethodHandlerImpl.TAG,"textInputClientId: " + textInputClientId); + Log.d(TextInputMethodHandlerImpl.TAG, "textInputClientId: " + textInputClientId); this.setTextInputClient(textInputClientId, configuration); } @@ -116,7 +125,7 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { } setEditingState(editingState: TextEditState): void { - Log.d(TextInputMethodHandlerImpl.TAG, "text:" + editingState.text +" selectionStart:" + editingState.selectionStart + " selectionEnd:" + Log.d(TextInputMethodHandlerImpl.TAG, "text:" + editingState.text + " selectionStart:" + editingState.selectionStart + " selectionEnd:" + editingState.selectionEnd + " composingStart:" + editingState.composingStart + " composingEnd" + editingState.composingEnd); this.mEditable.updateTextInputState(editingState); } @@ -127,10 +136,10 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { private async showTextInput(): Promise { await this.attach(true); - if(this.imcFlag != true) { + if (this.imcFlag != true) { this.listenKeyBoardEvent(); } - this.inputMethodController.showTextInput().then(()=> { + this.inputMethodController.showTextInput().then(() => { Log.d(TextInputMethodHandlerImpl.TAG, "Succeeded in showing softKeyboard"); }).catch((err: ESObject) => { Log.e(TextInputMethodHandlerImpl.TAG, "Failed to show softKeyboard:" + JSON.stringify(err)); @@ -145,7 +154,7 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { }) } - async attach(showKeyboard: boolean): Promise { + async attach(showKeyboard: boolean): Promise { try { await this.inputMethodController.attach(showKeyboard, this.textConfig); } catch (err) { @@ -154,17 +163,15 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { } setTextInputClient(client: number, configuration: Configuration | null): void { - const INPUT_TYPE_NAME = ['NONE', 'TEXT', 'MULTILINE', 'NUMBER', 'PHONE','DATETIME','EMAIL_ADDRESS','URL','VISIBLE_PASSWORD'] - if(configuration) - { + const INPUT_TYPE_NAME = ['NONE', 'TEXT', 'MULTILINE', 'NUMBER', 'PHONE', 'DATETIME', 'EMAIL_ADDRESS', 'URL', 'VISIBLE_PASSWORD'] + if (configuration) { this.configuration = configuration; - if(configuration.inputType) - { - this.textConfig.inputAttribute.textInputType =INPUT_TYPE_NAME.indexOf(configuration.inputType.type) + if (configuration.inputType) { + this.textConfig.inputAttribute.textInputType = INPUT_TYPE_NAME.indexOf(configuration.inputType.type) this.textConfig.inputAttribute.enterKeyType = configuration.inputAction as ESObject; } } - if(this.canShowTextInput()) { + if (this.canShowTextInput()) { this.inputTarget = new InputTarget(Type.FRAMEWORK_CLIENT, client); } else { this.inputTarget = new InputTarget(Type.NO_TARGET, client); @@ -178,7 +185,7 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { } canShowTextInput(): boolean { - if(this.configuration == null || this.configuration.inputType == null) { + if (this.configuration == null || this.configuration.inputType == null) { return true; } return this.configuration.inputType.type != TextInputType.NONE; @@ -228,7 +235,7 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { try { this.inputMethodController.on('sendKeyboardStatus', (state) => { - if(state == KeyboardStatus.HIDE) { + if (state == KeyboardStatus.HIDE) { this.keyboardStatus = KeyboardStatus.HIDE; this.plugin.textInputChannel.onConnectionClosed(this.inputTarget.id); } @@ -261,7 +268,7 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { } public clearTextInputClient(): void { - if(this.inputTarget.type == Type.VIRTUAL_DISPLAY_PLATFORM_VIEW) { + if (this.inputTarget.type == Type.VIRTUAL_DISPLAY_PLATFORM_VIEW) { return; } this.mEditable.removeEditingStateListener(this.plugin); @@ -295,5 +302,4 @@ export class InputTarget { this.type = type; this.id = id; } - } \ No newline at end of file -- Gitee From 349d7ce4ff04fe0d720407c6879a8b8a3cac4833 Mon Sep 17 00:00:00 2001 From: zhan-linlin <17301907374@163.com> Date: Tue, 30 Jan 2024 16:34:39 +0800 Subject: [PATCH 10/73] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=A2=9E=E9=87=8F?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E6=89=A7=E8=A1=8C=E9=80=BB=E8=BE=91=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhan-linlin <17301907374@163.com> --- .../plugin/editing/ListenableEditingState.ets | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/ListenableEditingState.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/ListenableEditingState.ets index 4c215d195d..0726ab0fb4 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/ListenableEditingState.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/ListenableEditingState.ets @@ -66,7 +66,7 @@ export class ListenableEditingState { return currentBatchDeltas; } - clearBatchDeltas():void { + clearBatchDeltas(): void { this.mBatchTextEditingDeltas.clear(); } @@ -145,26 +145,26 @@ export class ListenableEditingState { } handleInsertTextEvent(text: string): void { - let start = this.mSelectionStartCache < this.mSelectionEndCache? this.mSelectionStartCache :this.mSelectionEndCache; - let end = this.mSelectionStartCache > this.mSelectionEndCache? this.mSelectionStartCache :this.mSelectionEndCache; + let start = this.mSelectionStartCache < this.mSelectionEndCache ? this.mSelectionStartCache : this.mSelectionEndCache; + let end = this.mSelectionStartCache > this.mSelectionEndCache ? this.mSelectionStartCache : this.mSelectionEndCache; const length = text.length; - this.replace(start,end,text,0,length); + this.replace(start, end, text, 0, length); - if(this.mStringCache.length == this.mSelectionStartCache) { + if (this.mStringCache.length == this.mSelectionStartCache) { //Insert text one by one - let tempStr: string = this.mStringCache.substring(0,start) + text + this.mStringCache.substring(end); + let tempStr: string = this.mStringCache.substring(0, start) + text + this.mStringCache.substring(end); this.mStringCache = tempStr; this.setSelectionStart(this.mStringCache.length); this.setSelectionEnd(this.mStringCache.length); - } else if(this.mStringCache.length > this.mSelectionStartCache) { + } else if (this.mStringCache.length > this.mSelectionStartCache) { //Insert text in the middle of string let tempStr: string = this.mStringCache.substring(0, start) + text + this.mStringCache.substring(end); this.mStringCache = tempStr; - this.mSelectionStartCache = start+text.length; + this.mSelectionStartCache = start + text.length; this.mSelectionEndCache = this.mSelectionStartCache; } - if(this.mListeners == null) { + if (this.mListeners == null) { Log.e(TAG, "mListeners is null"); return; } @@ -174,7 +174,7 @@ export class ListenableEditingState { updateTextInputState(state: TextEditState): void { this.beginBatchEdit(); this.setStringCache(state.text); - if(state.hasSelection()) { + if (state.hasSelection()) { this.setSelectionStart(state.selectionStart); this.setSelectionEnd(state.selectionEnd); } else { @@ -252,30 +252,30 @@ export class ListenableEditingState { } handleDeleteEvent(leftOrRight: boolean, length: number): void { - let start = this.mSelectionStartCache < this.mSelectionEndCache? this.mSelectionStartCache :this.mSelectionEndCache; - let end = this.mSelectionStartCache > this.mSelectionEndCache? this.mSelectionStartCache :this.mSelectionEndCache; + let start = this.mSelectionStartCache < this.mSelectionEndCache ? this.mSelectionStartCache : this.mSelectionEndCache; + let end = this.mSelectionStartCache > this.mSelectionEndCache ? this.mSelectionStartCache : this.mSelectionEndCache; - if(leftOrRight == false) { + if (leftOrRight == false) { //delete left - if(start == 0 && end == 0) { + if (start == 0 && end == 0) { return; } - const startData = start== end ?start-1:start; - const tbEnd = start== end ?-1:0; - this.replace(startData,end,"",0,tbEnd); + const startData = start == end ? start - 1 : start; + const tbEnd = start == end ? -1 : 0; + this.replace(startData, end, "", 0, tbEnd); this.mSelectionStartCache = startData; let tempStr: string = this.mStringCache.slice(0, startData) + this.mStringCache.slice(end); this.mStringCache = tempStr; this.mSelectionEndCache = this.mSelectionStartCache; - } else if(leftOrRight == true) { + } else if (leftOrRight == true) { //delete right - if(start == this.mStringCache.length) { + if (start == this.mStringCache.length) { return; } - const tbStart= start== end ?1:0; - this.replace(start,end,"",tbStart,0); + const tbStart = start == end ? 1 : 0; + this.replace(start, end, "", tbStart, 0); this.mSelectionEndCache = start; - let tempStr: string = this.mStringCache.slice(0,start ) + (end+1>=this.mStringCache.length?"":this.mStringCache.slice( end +1 )); + let tempStr: string = this.mStringCache.slice(0, start) + (end + 1 >= this.mStringCache.length ? "" : this.mStringCache.slice(end + 1)); this.mStringCache = tempStr; this.mSelectionStartCache = this.mSelectionEndCache; } -- Gitee From 26f1d5d00880b0522fe21ce88676f0f20aa8132c Mon Sep 17 00:00:00 2001 From: xiaoxiang Date: Tue, 30 Jan 2024 17:03:35 +0800 Subject: [PATCH 11/73] =?UTF-8?q?=E6=9A=B4=E9=9C=B2util=E7=9A=84=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiaoxiang --- .../ohos/flutter_embedding/flutter/index.ets | 14 ++++++++++++++ .../flutter/src/main/ets/util/PathUtils.ets | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/index.ets b/shell/platform/ohos/flutter_embedding/flutter/index.ets index c146ae457d..a9e43723cb 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/index.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/index.ets @@ -100,6 +100,13 @@ import { FlutterCallbackInformation } from './src/main/ets/view/FlutterCallbackI import FlutterRunArguments from './src/main/ets/view/FlutterRunArguments'; import { FlutterView } from './src/main/ets/view/FlutterView'; import { TextureRegistry } from './src/main/ets/view/TextureRegistry'; +import { ByteBuffer } from './src/main/ets/util/ByteBuffer'; +import Log from './src/main/ets/util/Log'; +import MessageChannelUtils from './src/main/ets/util/MessageChannelUtils'; +import PathUtils from './src/main/ets/util/PathUtils'; +import StringUtils from './src/main/ets/util/StringUtils'; +import ToolUtils from './src/main/ets/util/ToolUtils'; +import { TraceSection } from './src/main/ets/util/TraceSection'; export { FlutterInjector, @@ -188,4 +195,11 @@ export { FlutterRunArguments, FlutterView, TextureRegistry, + ByteBuffer, + Log, + MessageChannelUtils, + PathUtils, + StringUtils, + ToolUtils, + TraceSection, } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/util/PathUtils.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/util/PathUtils.ets index 691ea0f360..f47bcb68b0 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/util/PathUtils.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/util/PathUtils.ets @@ -30,7 +30,7 @@ export default class PathUtils { return context.cacheDir; } - static getDataDirectory(context: common.Context): string { + static getDataDirectory(context: common.Context): string | null { const name = "flutter"; const flutterDir = context.filesDir + "/" + name; if (!fs.accessSync(flutterDir)) { -- Gitee From 25142f9038c258accacbfd1aac86c39ad9a367f2 Mon Sep 17 00:00:00 2001 From: xiaoxiang Date: Wed, 31 Jan 2024 01:16:03 +0800 Subject: [PATCH 12/73] =?UTF-8?q?=E4=BF=AE=E5=A4=8DStandardMessageCodec?= =?UTF-8?q?=E8=A7=A3=E7=A0=81type=E7=B1=BB=E5=9E=8B=E6=97=B6=E4=BD=BF?= =?UTF-8?q?=E7=94=A8readint8=E4=B8=8D=E5=8C=B9=E9=85=8D=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiaoxiang --- .../flutter/src/main/ets/plugin/common/StandardMessageCodec.ets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/StandardMessageCodec.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/StandardMessageCodec.ets index 2ee2ef39b2..88de0fc5de 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/StandardMessageCodec.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/StandardMessageCodec.ets @@ -233,7 +233,7 @@ export default class StandardMessageCodec implements MessageCodec { } readValue(buffer: ByteBuffer): ESObject { - let type = buffer.readInt8() + let type = buffer.readUint8() return this.readValueOfType(type, buffer); } -- Gitee From f2eba99d185ea437db160f2f185d046f59503069 Mon Sep 17 00:00:00 2001 From: huangxiaoyao <976125628@qq.com> Date: Thu, 1 Feb 2024 20:21:26 +0800 Subject: [PATCH 13/73] =?UTF-8?q?=E4=BF=AE=E5=A4=8DFlutterEntry=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96=E5=8F=82=E6=95=B0=E8=8E=B7=E5=8F=96=E4=B8=8D?= =?UTF-8?q?=E5=88=B0=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> --- .../ohos/FlutterAbilityLaunchConfigs.ets | 11 ++++++- .../main/ets/embedding/ohos/FlutterEntry.ets | 30 +++++++++---------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityLaunchConfigs.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityLaunchConfigs.ets index 996f455b9d..a1ae4bdb86 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityLaunchConfigs.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityLaunchConfigs.ets @@ -43,4 +43,13 @@ export default class FlutterAbilityLaunchConfigs { static DEFAULT_DART_ENTRYPOINT = "main"; static DEFAULT_INITIAL_ROUTE = "/"; static DEFAULT_BACKGROUND_MODE = BackgroundMode.opaque -} \ No newline at end of file +} + +export interface ParamsConfigs { + should_attach_engine_to_ability?: boolean; + dart_entrypoint?: string; + route?: string; + cached_engine_id?: string; + dart_entrypoint_args?: Array; + cached_engine_group_id?: string | null; +} diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterEntry.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterEntry.ets index e66095a173..a9984b3f9e 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterEntry.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterEntry.ets @@ -21,7 +21,7 @@ import ExclusiveAppComponent from './ExclusiveAppComponent'; import { FlutterPlugin } from '../engine/plugins/FlutterPlugin'; import List from '@ohos.util.List'; import { FlutterAbilityAndEntryDelegate, Host } from './FlutterAbilityAndEntryDelegate'; -import FlutterAbilityLaunchConfigs from './FlutterAbilityLaunchConfigs'; +import FlutterAbilityLaunchConfigs, { ParamsConfigs } from './FlutterAbilityLaunchConfigs'; import Log from '../../util/Log'; import { FlutterView } from '../../view/FlutterView'; import FlutterManager from './FlutterManager'; @@ -38,11 +38,11 @@ export default class FlutterEntry implements Host { private flutterView: FlutterView | null = null private context: Context; private windowStage: window.WindowStage | null = null - private parameters: ESObject = {}; + private parameters: ParamsConfigs; private engineConfigurator: FlutterEngineConfigurator | null = null private hasInit: boolean = false; - - constructor(context: Context, params: ESObject = {}) { + + constructor(context: Context, params: ParamsConfigs) { this.context = context; this.uiAbility = FlutterManager.getInstance().getUIAbility(context); this.parameters = params; @@ -143,15 +143,15 @@ export default class FlutterEntry implements Host { } shouldAttachEngineToAbility(): boolean { - return this.parameters![FlutterEntry.ARG_SHOULD_ATTACH_ENGINE_TO_ABILITY] as boolean + return this.parameters!.should_attach_engine_to_ability as boolean } getCachedEngineId(): string { - return this.parameters![FlutterAbilityLaunchConfigs.EXTRA_CACHED_ENGINE_ID] as string + return this.parameters!.cached_engine_id as string } getCachedEngineGroupId(): string | null { - return this.parameters![FlutterAbilityLaunchConfigs.EXTRA_CACHED_ENGINE_GROUP_ID] as string + return this.parameters!.cached_engine_group_id as string } shouldDestroyEngineWithHost(): boolean { @@ -167,8 +167,8 @@ export default class FlutterEntry implements Host { } getDartEntrypointArgs(): string[] { - if (this.parameters![FlutterAbilityLaunchConfigs.EXTRA_DART_ENTRYPOINT_ARGS]) { - return this.parameters![FlutterAbilityLaunchConfigs.EXTRA_DART_ENTRYPOINT_ARGS] as Array; + if (this.parameters!.dart_entrypoint_args) { + return this.parameters!.dart_entrypoint_args as Array; } return new Array() } @@ -182,15 +182,15 @@ export default class FlutterEntry implements Host { } getDartEntrypointFunctionName(): string { - if (this.parameters![FlutterAbilityLaunchConfigs.EXTRA_DART_ENTRYPOINT]) { - return this.parameters![FlutterAbilityLaunchConfigs.EXTRA_DART_ENTRYPOINT] as string; + if (this.parameters!.dart_entrypoint) { + return this.parameters!.dart_entrypoint as string; } return FlutterAbilityLaunchConfigs.DEFAULT_DART_ENTRYPOINT } getInitialRoute(): string { - if (this.parameters![FlutterAbilityLaunchConfigs.EXTRA_INITIAL_ROUTE]) { - return this.parameters![FlutterAbilityLaunchConfigs.EXTRA_INITIAL_ROUTE] as string + if (this.parameters!.route) { + return this.parameters!.route as string } return ""; } @@ -200,8 +200,8 @@ export default class FlutterEntry implements Host { } shouldRestoreAndSaveState(): boolean { - if (this.parameters![FlutterAbilityLaunchConfigs.EXTRA_CACHED_ENGINE_ID] != undefined) { - return this.parameters![FlutterAbilityLaunchConfigs.EXTRA_CACHED_ENGINE_ID] as boolean; + if (this.parameters!.cached_engine_id != undefined) { + return true; } if (this.getCachedEngineId() != null && this.getCachedEngineId().length > 0) { // Prevent overwriting the existing state in a cached engine with restoration state. -- Gitee From e34b1ca4e603fffbe18d5c5c8062f0c7a311dc63 Mon Sep 17 00:00:00 2001 From: huangxiaoyao <976125628@qq.com> Date: Fri, 2 Feb 2024 12:43:36 +0800 Subject: [PATCH 14/73] =?UTF-8?q?=E4=BF=AE=E5=A4=8DFlutterEntry=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96=E5=8F=82=E6=95=B0=E8=8E=B7=E5=8F=96=E4=B8=8D?= =?UTF-8?q?=E5=88=B0=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> --- .../ohos/FlutterAbilityLaunchConfigs.ets | 11 +------ .../main/ets/embedding/ohos/FlutterEntry.ets | 30 +++++++++---------- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityLaunchConfigs.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityLaunchConfigs.ets index a1ae4bdb86..996f455b9d 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityLaunchConfigs.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityLaunchConfigs.ets @@ -43,13 +43,4 @@ export default class FlutterAbilityLaunchConfigs { static DEFAULT_DART_ENTRYPOINT = "main"; static DEFAULT_INITIAL_ROUTE = "/"; static DEFAULT_BACKGROUND_MODE = BackgroundMode.opaque -} - -export interface ParamsConfigs { - should_attach_engine_to_ability?: boolean; - dart_entrypoint?: string; - route?: string; - cached_engine_id?: string; - dart_entrypoint_args?: Array; - cached_engine_group_id?: string | null; -} +} \ No newline at end of file diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterEntry.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterEntry.ets index a9984b3f9e..d90be8a48b 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterEntry.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterEntry.ets @@ -21,7 +21,7 @@ import ExclusiveAppComponent from './ExclusiveAppComponent'; import { FlutterPlugin } from '../engine/plugins/FlutterPlugin'; import List from '@ohos.util.List'; import { FlutterAbilityAndEntryDelegate, Host } from './FlutterAbilityAndEntryDelegate'; -import FlutterAbilityLaunchConfigs, { ParamsConfigs } from './FlutterAbilityLaunchConfigs'; +import FlutterAbilityLaunchConfigs from './FlutterAbilityLaunchConfigs'; import Log from '../../util/Log'; import { FlutterView } from '../../view/FlutterView'; import FlutterManager from './FlutterManager'; @@ -38,11 +38,11 @@ export default class FlutterEntry implements Host { private flutterView: FlutterView | null = null private context: Context; private windowStage: window.WindowStage | null = null - private parameters: ParamsConfigs; + private parameters: Record = {}; private engineConfigurator: FlutterEngineConfigurator | null = null private hasInit: boolean = false; - - constructor(context: Context, params: ParamsConfigs) { + + constructor(context: Context, params: Record = {}) { this.context = context; this.uiAbility = FlutterManager.getInstance().getUIAbility(context); this.parameters = params; @@ -143,15 +143,15 @@ export default class FlutterEntry implements Host { } shouldAttachEngineToAbility(): boolean { - return this.parameters!.should_attach_engine_to_ability as boolean + return this.parameters![FlutterEntry.ARG_SHOULD_ATTACH_ENGINE_TO_ABILITY] as boolean } getCachedEngineId(): string { - return this.parameters!.cached_engine_id as string + return this.parameters![FlutterAbilityLaunchConfigs.EXTRA_CACHED_ENGINE_ID] as string } getCachedEngineGroupId(): string | null { - return this.parameters!.cached_engine_group_id as string + return this.parameters![FlutterAbilityLaunchConfigs.EXTRA_CACHED_ENGINE_GROUP_ID] as string } shouldDestroyEngineWithHost(): boolean { @@ -167,8 +167,8 @@ export default class FlutterEntry implements Host { } getDartEntrypointArgs(): string[] { - if (this.parameters!.dart_entrypoint_args) { - return this.parameters!.dart_entrypoint_args as Array; + if (this.parameters![FlutterAbilityLaunchConfigs.EXTRA_DART_ENTRYPOINT_ARGS]) { + return this.parameters![FlutterAbilityLaunchConfigs.EXTRA_DART_ENTRYPOINT_ARGS] as Array; } return new Array() } @@ -182,15 +182,15 @@ export default class FlutterEntry implements Host { } getDartEntrypointFunctionName(): string { - if (this.parameters!.dart_entrypoint) { - return this.parameters!.dart_entrypoint as string; + if (this.parameters![FlutterAbilityLaunchConfigs.EXTRA_DART_ENTRYPOINT]) { + return this.parameters![FlutterAbilityLaunchConfigs.EXTRA_DART_ENTRYPOINT] as string; } return FlutterAbilityLaunchConfigs.DEFAULT_DART_ENTRYPOINT } getInitialRoute(): string { - if (this.parameters!.route) { - return this.parameters!.route as string + if (this.parameters![FlutterAbilityLaunchConfigs.EXTRA_INITIAL_ROUTE]) { + return this.parameters![FlutterAbilityLaunchConfigs.EXTRA_INITIAL_ROUTE] as string } return ""; } @@ -200,8 +200,8 @@ export default class FlutterEntry implements Host { } shouldRestoreAndSaveState(): boolean { - if (this.parameters!.cached_engine_id != undefined) { - return true; + if (this.parameters![FlutterAbilityLaunchConfigs.EXTRA_CACHED_ENGINE_ID] != undefined) { + return this.parameters![FlutterAbilityLaunchConfigs.EXTRA_CACHED_ENGINE_ID] as boolean; } if (this.getCachedEngineId() != null && this.getCachedEngineId().length > 0) { // Prevent overwriting the existing state in a cached engine with restoration state. -- Gitee From 9c767ce6c012d44308856bed73f548877a433bc1 Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Sat, 17 Feb 2024 09:36:00 +0800 Subject: [PATCH 15/73] =?UTF-8?q?=E6=9B=B4=E6=96=B0hvigor=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E7=89=88=E6=9C=AC=E4=B8=BA3.2.1-s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- README.en.md | 2 -- README.md | 2 -- 2 files changed, 4 deletions(-) diff --git a/README.en.md b/README.en.md index 1b57e89b92..3fdf8e6498 100644 --- a/README.en.md +++ b/README.en.md @@ -92,5 +92,3 @@ export OHOS_SDK_HOME= 3. The har file output path is: shell/platform/ohos/flutter_embedding/flutter/build ps: If you are using the Beta version of DevEco Studio and encounter the error "must have required property 'compatibleSdkVersion', location: build-profile.json5:17:11" when compiling the project, please refer to the "DevEco Studio Environment Configuration Guide." docx》Chapter '6 Creating Projects and Running Hello World' [Configuration Plugin] Modify the shell/platform/ohos/flutter_embedding/hvigor/hvigor-config.json5 file. - -[hvigor-dependencies-config](shell/platform/ohos/flutter_embedding/dependencies/hvigor-dependencies-config.md) diff --git a/README.md b/README.md index 5cb27d599c..e19e793031 100644 --- a/README.md +++ b/README.md @@ -94,5 +94,3 @@ export OHOS_SDK_HOME= 3. har文件输出路径为:shell/platform/ohos/flutter_embedding/flutter/build ps:如果你使用的是DevEco Studio的Beta版本,编译工程时遇到“must have required property 'compatibleSdkVersion', location: build-profile.json5:17:11"错误,请参考《DevEco Studio环境配置指导.docx》中的‘6 创建工程和运行Hello World’【配置插件】章节修改 shell/platform/ohos/flutter_embedding/hvigor/hvigor-config.json5文件。 - -[hvigor本地依赖配置](shell/platform/ohos/flutter_embedding/dependencies/hvigor-dependencies-config.md) -- Gitee From d67dc5395271bbc0d7a9ff4ea22d71d4eb3e165b Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Sat, 17 Feb 2024 09:36:00 +0800 Subject: [PATCH 16/73] =?UTF-8?q?so=E6=96=87=E4=BB=B6=E6=89=93=E5=8C=85?= =?UTF-8?q?=E5=88=B0flutter=5Fembedding.har=E6=96=87=E4=BB=B6=E9=87=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- attachment/repos/build.patch | 245 +++++++++++++++++++++++++++++------ shell/platform/ohos/BUILD.gn | 79 ++++++++++- 2 files changed, 274 insertions(+), 50 deletions(-) diff --git a/attachment/repos/build.patch b/attachment/repos/build.patch index c3df91e35f..d1bf7b82e2 100644 --- a/attachment/repos/build.patch +++ b/attachment/repos/build.patch @@ -12,18 +12,10 @@ index 4e62965..ea49a53 100644 libs = [ "dl" ] } diff --git a/build/config/BUILDCONFIG.gn b/build/config/BUILDCONFIG.gn -index b8d0f47..d789796 100644 +index b8d0f47..a3d1ed9 100644 --- a/build/config/BUILDCONFIG.gn +++ b/build/config/BUILDCONFIG.gn -@@ -34,6 +34,7 @@ - # When writing build files, to do something only for the host: - # if (current_toolchain == host_toolchain) { ... - -+ - if (target_os == "") { - target_os = host_os - } -@@ -190,6 +191,7 @@ if (current_os == "win") { +@@ -190,6 +190,7 @@ if (current_os == "win") { is_fuchsia_host = false is_ios = false is_linux = false @@ -31,7 +23,7 @@ index b8d0f47..d789796 100644 is_mac = false is_posix = false is_win = true -@@ -198,6 +200,7 @@ if (current_os == "win") { +@@ -198,6 +199,7 @@ if (current_os == "win") { is_android = false is_chromeos = false is_fuchsia = false @@ -39,7 +31,7 @@ index b8d0f47..d789796 100644 is_fuchsia_host = false is_ios = false is_linux = false -@@ -212,6 +215,7 @@ if (current_os == "win") { +@@ -212,6 +214,7 @@ if (current_os == "win") { is_fuchsia_host = false is_ios = false is_linux = false @@ -47,7 +39,7 @@ index b8d0f47..d789796 100644 is_mac = false is_posix = true is_win = false -@@ -223,6 +227,7 @@ if (current_os == "win") { +@@ -223,6 +226,7 @@ if (current_os == "win") { is_fuchsia_host = false is_ios = false is_linux = true @@ -55,7 +47,7 @@ index b8d0f47..d789796 100644 is_mac = false is_posix = true is_win = false -@@ -237,6 +242,7 @@ if (current_os == "win") { +@@ -237,6 +241,7 @@ if (current_os == "win") { is_fuchsia_host = false is_ios = false is_linux = false @@ -63,7 +55,7 @@ index b8d0f47..d789796 100644 is_mac = false is_posix = true is_win = false -@@ -248,6 +254,19 @@ if (current_os == "win") { +@@ -248,6 +253,19 @@ if (current_os == "win") { is_fuchsia_host = false is_ios = true is_linux = false @@ -83,7 +75,7 @@ index b8d0f47..d789796 100644 is_mac = false is_posix = true is_win = false -@@ -259,6 +278,7 @@ if (current_os == "win") { +@@ -259,6 +277,7 @@ if (current_os == "win") { is_fuchsia_host = false is_ios = false is_linux = true @@ -91,7 +83,7 @@ index b8d0f47..d789796 100644 is_mac = false is_posix = true is_win = false -@@ -270,6 +290,7 @@ if (current_os == "win") { +@@ -270,6 +289,7 @@ if (current_os == "win") { is_fuchsia_host = false is_ios = false is_linux = false @@ -99,7 +91,7 @@ index b8d0f47..d789796 100644 is_mac = false is_posix = true is_win = false -@@ -281,6 +302,7 @@ if (current_os == "win") { +@@ -281,6 +301,7 @@ if (current_os == "win") { is_fuchsia_host = false is_ios = false is_linux = false @@ -107,7 +99,7 @@ index b8d0f47..d789796 100644 is_mac = false is_posix = false is_win = false -@@ -313,7 +335,7 @@ if (!is_clang && using_sanitizer) { +@@ -313,7 +334,7 @@ if (!is_clang && using_sanitizer) { is_clang = true } @@ -116,18 +108,18 @@ index b8d0f47..d789796 100644 if (is_msan && !is_linux) { assert(false, "Memory sanitizer is only available on Linux.") -@@ -365,7 +387,9 @@ if (is_posix) { +@@ -365,7 +386,9 @@ if (is_posix) { ] } -if (is_linux) { -+if(is_ohos || (is_linux && host_os == "mac")){ ++if (is_ohos || (is_linux && host_os == "mac")) { + _native_compiler_configs += [ "//build/config/ohos:sdk" ] -+ }else if (is_linux) { ++} else if (is_linux) { _native_compiler_configs += [ "//build/config/linux:sdk" ] } else if (is_mac) { _native_compiler_configs += [ "//build/config/mac:sdk" ] -@@ -510,8 +534,18 @@ shlib_toolchain = false +@@ -510,8 +533,18 @@ shlib_toolchain = false if (custom_toolchain != "") { assert(custom_sysroot != "") assert(custom_target_triple != "") @@ -147,22 +139,20 @@ index b8d0f47..d789796 100644 } else if (is_win) { if (is_clang) { host_toolchain = "//build/toolchain/win:clang_$host_cpu" -@@ -544,6 +578,21 @@ if (custom_toolchain != "") { +@@ -544,6 +577,19 @@ if (custom_toolchain != "") { } else { set_default_toolchain("//build/toolchain/android:$current_cpu") } +} else if (is_ohos) { ++ set_default_toolchain("//build/toolchain/custom") + if (host_os == "linux") { + if (is_clang) { + host_toolchain = "//build/toolchain/linux:clang_$host_cpu" -+ set_default_toolchain("//build/toolchain/linux:clang_$current_cpu") + } else { + host_toolchain = "//build/toolchain/linux:$host_cpu" -+ set_default_toolchain("//build/toolchain/linux:$current_cpu") + } + } else if (host_os == "mac") { + host_toolchain = "//build/toolchain/mac:clang_$host_cpu" -+ set_default_toolchain("//build/toolchain/ohos:clang_$current_cpu") + } else { + assert(false, "Unknown host for ohos cross compile") + } @@ -170,10 +160,10 @@ index b8d0f47..d789796 100644 if (is_clang) { host_toolchain = "//build/toolchain/linux:clang_$host_cpu" diff --git a/build/config/compiler/BUILD.gn b/build/config/compiler/BUILD.gn -index ba20010..24a7d4e 100644 +index ba20010..67371f5 100644 --- a/build/config/compiler/BUILD.gn +++ b/build/config/compiler/BUILD.gn -@@ -191,11 +191,18 @@ config("compiler") { +@@ -191,10 +191,16 @@ config("compiler") { # CPU architecture. We may or may not be doing a cross compile now, so for # simplicity we always explicitly set the architecture. if (current_cpu == "x64") { @@ -181,61 +171,64 @@ index ba20010..24a7d4e 100644 - "-m64", - "-march=x86-64", - ] -+ if ( is_ohos ){ ++ if (is_ohos) { + cflags += [ + "-m64", + ] -+ }else { ++ } else { + cflags += [ + "-m64", + "-march=x86-64", + ] + } ldflags += [ "-m64" ] -+ } else if (current_cpu == "x86") { cflags += [ "-m32" ] - ldflags += [ "-m32" ] -@@ -315,7 +322,7 @@ config("compiler") { +@@ -315,7 +321,7 @@ config("compiler") { # Linux/Android common flags setup. # --------------------------------- - if (is_linux || is_android) { -+ if (is_linux || is_android || is_ohos ) { ++ if (is_linux || is_android || is_ohos) { cflags += [ "-fPIC", "-pipe", # Use pipes for communicating between sub-processes. Faster. -@@ -334,7 +341,16 @@ config("compiler") { +@@ -334,7 +340,16 @@ config("compiler") { # Linux-specific compiler flags setup. # ------------------------------------ - if (is_linux) { -+ if (is_ohos ) { ++ if (is_ohos) { + cflags += [ "-pthread" ] + ldflags += [ "-pthread" ] + + if (current_cpu == "arm64") { -+ cflags += [ "--target=aarch64-linux-ohos" ] -+ ldflags += [ "--target=aarch64-linux-ohos" ] ++ cflags += [ "--target=aarch64-linux-ohos" ] ++ ldflags += [ "--target=aarch64-linux-ohos" ] + cflags += [ "-DBORINGSSL_CLANG_SUPPORTS_DOT_ARCH" ] + } -+ }else if (is_linux ) { ++ } else if (is_linux) { cflags += [ "-pthread" ] ldflags += [ "-pthread" ] -@@ -521,8 +537,8 @@ config("runtime_library") { +@@ -521,9 +536,13 @@ config("runtime_library") { ldflags += [ "-nostdlib++" ] } include_dirs = [ - "//third_party/libcxx/include", "//third_party/libcxxabi/include", -+ "$custom_toolchain/include/c++/v1", ] ++ if (custom_toolchain != "") { ++ include_dirs += [ "$custom_toolchain/include/c++/v1" ] ++ } else { ++ include_dirs += [ "//third_party/libcxx/include" ] ++ } } + # Android standard library setup. diff --git a/build/config/ohos/BUILD.gn b/build/config/ohos/BUILD.gn new file mode 100644 -index 0000000..1d29b40 +index 0000000..b2675d2 --- /dev/null +++ b/build/config/ohos/BUILD.gn @@ -0,0 +1,29 @@ @@ -243,6 +236,7 @@ index 0000000..1d29b40 +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + ++import("//build/config/ohos/config.gni") +import("//build/config/ohos/pkg_config.gni") +import("//build/config/features.gni") +import("//build/config/sysroot.gni") @@ -267,7 +261,25 @@ index 0000000..1d29b40 +config("fontconfig") { + libs = [ ] +} +diff --git a/build/config/ohos/config.gni b/build/config/ohos/config.gni +new file mode 100644 +index 0000000..0022d70 +--- /dev/null ++++ b/build/config/ohos/config.gni +@@ -0,0 +1,13 @@ ++# Copyright 2014 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. + ++# This file contains common system config stuff for the Ohos build. ++ ++if (is_ohos) { ++ if (current_cpu == "arm64") { ++ ohos_app_abi = "arm64-v8a" ++ } else { ++ assert(false, "Unknown Ohos ABI: " + current_cpu) ++ } ++} diff --git a/build/config/ohos/pkg-config.py b/build/config/ohos/pkg-config.py new file mode 100644 index 0000000..b4a6aff @@ -703,6 +715,153 @@ index 7987e51..cd7b060 100644 if (current_cpu == "x64") { sysroot = rebase_path("//build/linux/debian_sid_amd64-sysroot") } else { +diff --git a/build/ohos/ohos_create_flutter_har.py b/build/ohos/ohos_create_flutter_har.py +new file mode 100644 +index 0000000..4e052ed +--- /dev/null ++++ b/build/ohos/ohos_create_flutter_har.py +@@ -0,0 +1,141 @@ ++#!/usr/bin/env python3 ++# ++# Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. ++# Licensed under the Apache License, Version 2.0 (the "License"); ++# you may not use this file except in compliance with the License. ++# You may obtain a copy of the License at ++# ++# http://www.apache.org/licenses/LICENSE-2.0 ++# ++# Unless required by applicable law or agreed to in writing, software ++# distributed under the License is distributed on an "AS IS" BASIS, ++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++# See the License for the specific language governing permissions and ++# limitations under the License. ++ ++"""Create a HAR incorporating all the components required to build a Flutter application""" ++ ++import argparse ++import logging ++import os ++import re ++import shutil ++import subprocess ++import sys ++ ++ ++HAR_CONFIG_TEMPLATE = """ ++{ ++ "app": { ++ "signingConfigs": [], ++ "products": [ ++ { ++ "name": "default", ++ "signingConfig": "default", ++ "compileSdkVersion": "%s", ++ "compatibleSdkVersion": "%s", ++ "runtimeOS": "HarmonyOS", ++ } ++ ] ++ }, ++ "modules": [ ++ { ++ "name": "flutter", ++ "srcPath": "./flutter" ++ } ++ ] ++} ++""" ++ ++ ++def updateConfig(buildDir, apiInt): ++ apiStr = "4.1.0(11)" if apiInt == 11 else "4.0.0(10)" ++ jsonFile = os.path.join(buildDir, "build-profile.json5") ++ with open(jsonFile, "w", encoding="utf-8") as file: ++ file.write(HAR_CONFIG_TEMPLATE % (apiStr, apiStr)) ++ ++ ++# 执行命令 ++def runCommand(command, checkCode=True, timeout=None): ++ logging.info("runCommand start, command = %s" % (command)) ++ code = subprocess.Popen(command, shell=True).wait(timeout) ++ if code != 0: ++ logging.error("runCommand error, code = %s, command = %s" % (code, command)) ++ if checkCode: ++ exit(code) ++ else: ++ logging.info("runCommand finish, code = %s, command = %s" % (code, command)) ++ ++ ++# 替换文件中的字符串 ++def replaceStr(file, regex, newstr): ++ with open(file, "r", encoding="utf-8") as f1: ++ lines = f1.readlines() ++ with open(file, "w+", encoding="utf-8") as f2: ++ for line in lines: ++ a = re.sub(regex, newstr, line) ++ f2.writelines(a) ++ ++ ++# 编译har文件 ++def buildHar(buildDir, apiInt, buildType): ++ updateConfig(buildDir, apiInt) ++ isDebug = "true" if buildType == "debug" else "false" ++ isProfile = "true" if buildType == "profile" else "false" ++ dirEmbedding = buildDir ++ targetFile = os.path.join( ++ buildDir, ++ "flutter/src/main/ets/embedding/engine/loader/FlutterApplicationInfo.ets", ++ ) ++ logging.info("isDebugMode=%s, isProfile=%s" % (isDebug, isProfile)) ++ replaceStr(targetFile, "isDebugMode = .*", "isDebugMode = %s;" % isDebug) ++ replaceStr(targetFile, "isProfile = .*", "isProfile = %s;" % isProfile) ++ runCommand( ++ ("cd %s && " % dirEmbedding) ++ + (".%s" % os.sep) ++ + "hvigorw --mode module -p module=flutter@default -p product=default assembleHar --no-daemon" ++ ) ++ ++ ++def main(): ++ parser = argparse.ArgumentParser() ++ parser.add_argument("--embedding_src", help="Path of embedding source code.") ++ parser.add_argument("--build_dir", help="Path to build.") ++ parser.add_argument( ++ "--build_type", ++ choices=["debug", "release", "profile"], ++ help="Type to build har.", ++ ) ++ parser.add_argument("--output", help="Path to output har.") ++ parser.add_argument("--native_lib", action="append", help="Native code library.") ++ parser.add_argument("--ohos_abi", help="Native code ABI.") ++ parser.add_argument( ++ "--ohos_api_int", type=int, choices=[10, 11], help="Ohos api int." ++ ) ++ options = parser.parse_args() ++ # copy source code ++ if os.path.exists(options.build_dir): ++ shutil.rmtree(options.build_dir) ++ shutil.copytree(options.embedding_src, options.build_dir) ++ ++ # copy so files ++ for file in options.native_lib: ++ dir_name, full_file_name = os.path.split(file) ++ targetDir = os.path.join(options.build_dir, "flutter/libs", options.ohos_abi) ++ if not os.path.exists(targetDir): ++ os.makedirs(targetDir) ++ shutil.copyfile( ++ file, ++ os.path.join(targetDir, full_file_name), ++ ) ++ buildHar(options.build_dir, options.ohos_api_int, options.build_type) ++ shutil.copyfile( ++ os.path.join( ++ options.build_dir, "flutter/build/default/outputs/default/flutter.har" ++ ), ++ options.output, ++ ) ++ ++ ++if __name__ == "__main__": ++ sys.exit(main()) diff --git a/build/ohos/sysroot_ld_path.sh b/build/ohos/sysroot_ld_path.sh new file mode 100755 index 0000000..4b8bf73 diff --git a/shell/platform/ohos/BUILD.gn b/shell/platform/ohos/BUILD.gn index 8d18085468..aa2f620ed7 100644 --- a/shell/platform/ohos/BUILD.gn +++ b/shell/platform/ohos/BUILD.gn @@ -13,16 +13,19 @@ assert(is_ohos) +import("//build/config/ohos/config.gni") +import("//build/toolchain/clang.gni") import("//flutter/build/zip_bundle.gni") -import("//flutter/shell/platform/glfw/config.gni") -import("//flutter/testing/testing.gni") -import("//build/config/ohos/pkg_config.gni") +import("//flutter/common/config.gni") import("//flutter/shell/gpu/gpu.gni") +import("//flutter/shell/version/version.gni") +import("//flutter/testing/testing.gni") group("ohos") { deps = [ ":flutter", #":publish_headers_ohos", + ":ohos_har" ] } shell_gpu_configuration("ohos_gpu_configuration") { @@ -195,10 +198,6 @@ executable("flutter_ohos_unittests") { shared_library("flutter") { deps = [ ":flutter_ohos_src" ] - if (flutter_runtime_mode == "profile") { - deps += [ "//flutter/shell/vmservice:vmservice_snapshot" ] - } - ldflags = ["--rtlib=compiler-rt", "-fuse-ld=lld", "-static-libstdc++", @@ -268,3 +267,69 @@ shared_library("flutter") { # ] # files = tmp_files #} + +declare_args() { + embedding_artifact_id = "flutter_embedding_$flutter_runtime_mode" + embedding_har_filename = "$embedding_artifact_id.har" + embedding_har_path = "$root_out_dir/$embedding_har_filename" + engine_artifact_id = + string_replace(ohos_app_abi, "-", "_") + "_" + flutter_runtime_mode + engine_har_filename = "$engine_artifact_id.har" + + ohos_zip_archive_dir = "ohos-$target_cpu" + if (flutter_runtime_mode != "debug") { + ohos_zip_archive_dir += "-$flutter_runtime_mode" + } +} + +action("ohos_har") { + script = "//build/ohos/ohos_create_flutter_har.py" + + if (stripped_symbols) { + engine_library = "so.unstripped/libflutter.so" + } else { + engine_library = "libflutter.so" + } + #engine_library = "libflutter.so" + + inputs = [ + # "$root_build_dir/$embedding_har_filename", + "$root_build_dir/$engine_library", + ] + + outputs = [ + "$root_build_dir/flutter.har", + # "$root_build_dir/$engine_har_filename", + ] + + args = [ + "--embedding_src", + "../../flutter/shell/platform/ohos/flutter_embedding", + "--build_dir", + "./ohos/flutter_embedding", + "--build_type", + flutter_runtime_mode, + "--output", + rebase_path("flutter_embedding.har", root_build_dir, root_build_dir), + "--native_lib", + rebase_path("$engine_library", root_build_dir, root_build_dir), + "--ohos_abi", + ohos_app_abi, + ] + + deps = [ + ":flutter" + ] + + if (flutter_runtime_mode == "profile") { + deps += [ "//flutter/shell/vmservice:vmservice_snapshot" ] + args += [ + "--native_lib", + rebase_path( + "$root_gen_dir/flutter/shell/vmservice/ohos/libs/$ohos_app_abi/libvmservice_snapshot.so", + root_build_dir, + root_build_dir), + ] + } +} + -- Gitee From 2361c3a63beb16270b2b9fdf5fea5c8123a14467 Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Sat, 17 Feb 2024 09:36:00 +0800 Subject: [PATCH 17/73] =?UTF-8?q?=E4=BF=AE=E6=94=B9ets=E8=AF=AD=E6=B3=95?= =?UTF-8?q?=E6=A3=80=E6=B5=8B=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- .../flutter/src/main/ets/app/FlutterPluginRegistry.ets | 4 ++-- .../main/ets/embedding/engine/dart/DartExecutor.ets | 2 +- .../main/ets/embedding/engine/dart/DartMessenger.ets | 4 ++-- .../src/main/ets/plugin/common/BasicMessageChannel.ets | 2 +- .../flutter/src/main/ets/plugin/common/BinaryCodec.ets | 4 ++-- .../src/main/ets/plugin/common/EventChannel.ets | 10 +++++----- .../src/main/ets/plugin/common/JSONMessageCodec.ets | 4 ++-- .../src/main/ets/plugin/common/MessageCodec.ets | 2 +- .../src/main/ets/plugin/common/MethodChannel.ets | 2 +- .../main/ets/plugin/common/StandardMessageCodec.ets | 2 +- .../flutter/src/main/ets/plugin/common/StringCodec.ets | 2 +- 11 files changed, 19 insertions(+), 19 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/app/FlutterPluginRegistry.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/app/FlutterPluginRegistry.ets index 4eabe6ad35..758b5f6e1c 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/app/FlutterPluginRegistry.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/app/FlutterPluginRegistry.ets @@ -18,8 +18,8 @@ import PlatformViewController from '../plugin/platform/PlatformViewsController' export default class FlutterPluginRegistry { private mPlatformViewsController: PlatformViewController; - private mFlutterView: FlutterView | null; - private mContext: common.Context | null; + private mFlutterView: FlutterView | null = null; + private mContext: common.Context | null = null; constructor() { this.mPlatformViewsController = new PlatformViewController(); diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/dart/DartExecutor.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/dart/DartExecutor.ets index 46d08cd458..383927204c 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/dart/DartExecutor.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/dart/DartExecutor.ets @@ -172,7 +172,7 @@ export default class DartExecutor implements BinaryMessenger { this.getBinaryMessenger().send(channel, message, callback); } - setMessageHandler(channel: String, handler: BinaryMessageHandler, taskQueue?: TaskQueue): void { + setMessageHandler(channel: String, handler: BinaryMessageHandler | null, taskQueue?: TaskQueue): void { this.getBinaryMessenger().setMessageHandler(channel, handler, taskQueue); } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/dart/DartMessenger.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/dart/DartMessenger.ets index 6e9bfab834..3567d610f4 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/dart/DartMessenger.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/dart/DartMessenger.ets @@ -68,7 +68,7 @@ export class DartMessenger implements BinaryMessenger, PlatformMessageHandler { } - setMessageHandler(channel: String, handler: BinaryMessageHandler, taskQueue?: TaskQueue): void { + setMessageHandler(channel: String, handler: BinaryMessageHandler | null, taskQueue?: TaskQueue): void { if (handler == null) { Log.d(TAG, "Removing handler for channel '" + channel + "'"); this.messageHandlers.delete(channel); @@ -255,7 +255,7 @@ class Reply implements BinaryReply { this.replyId = replyId; } - reply(reply: ArrayBuffer) { + reply(reply: ArrayBuffer | null) { if (this.done) { throw new Error("Reply already submitted"); } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/BasicMessageChannel.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/BasicMessageChannel.ets index 796f8edb89..4b627aea9e 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/BasicMessageChannel.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/BasicMessageChannel.ets @@ -136,7 +136,7 @@ class IncomingReplyHandler implements BinaryReply { this.codec = codec } - reply(reply: ArrayBuffer) { + reply(reply: ArrayBuffer | null) { try { this.callback(this.codec.decodeMessage(reply)); } catch (e) { diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/BinaryCodec.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/BinaryCodec.ets index 578436417d..1c15c76210 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/BinaryCodec.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/BinaryCodec.ets @@ -37,9 +37,9 @@ export default class BinaryCodec implements MessageCodec { return message } - decodeMessage(message: ArrayBuffer): ArrayBuffer { + decodeMessage(message: ArrayBuffer | null): ArrayBuffer { if (message == null) { - return message; + return new ArrayBuffer(0); } else if (this.returnsDirectByteBufferFromDecoding) { return message; } else { diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/EventChannel.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/EventChannel.ets index cc792fbb52..0c2ee0884c 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/EventChannel.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/EventChannel.ets @@ -40,13 +40,13 @@ export default class EventChannel { private messenger: BinaryMessenger; private name: string; private codec: MethodCodec; - private taskQueue: TaskQueue | undefined; + private taskQueue: TaskQueue | null; constructor(messenger: BinaryMessenger, name: string, codec?: MethodCodec, taskQueue?: TaskQueue) { this.messenger = messenger this.name = name this.codec = codec ? codec : StandardMethodCodec.INSTANCE - this.taskQueue = taskQueue + this.taskQueue = taskQueue ?? null } @@ -236,11 +236,11 @@ class EventSinkImplementation implements EventSink { return; } this.hasEnded = true; - this.messenger.send(this.name, null); + this.messenger.send(this.name, new ArrayBuffer(0)); } } -class AtomicReference { +class AtomicReference { private value: T | null; constructor(value: T | null) { @@ -255,7 +255,7 @@ class AtomicReference { this.value = newValue; } - getAndSet(newValue: T | null): T | null { + getAndSet(newValue: T | null) { const oldValue = this.value; this.value = newValue; return oldValue; diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/JSONMessageCodec.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/JSONMessageCodec.ets index e766db57fc..e37a3d27e5 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/JSONMessageCodec.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/JSONMessageCodec.ets @@ -44,9 +44,9 @@ export default class JSONMessageCodec implements MessageCodec { return StringCodec.INSTANCE.encodeMessage(JSON.stringify(this.toBaseData(message))); } - decodeMessage(message: ArrayBuffer): ESObject { + decodeMessage(message: ArrayBuffer | null): ESObject { if (message == null) { - return null; + return StringUtils.stringToArrayBuffer(""); } try { const jsonStr = StringCodec.INSTANCE.decodeMessage(message); diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/MessageCodec.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/MessageCodec.ets index 663d57af19..6cb2c033b6 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/MessageCodec.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/MessageCodec.ets @@ -26,5 +26,5 @@ export default interface MessageCodec { * Decodes the specified message from binary. * */ - decodeMessage(message: ArrayBuffer): T; + decodeMessage(message: ArrayBuffer | null): T; } \ No newline at end of file diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/MethodChannel.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/MethodChannel.ets index f42df11830..e9c3a7cc15 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/MethodChannel.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/MethodChannel.ets @@ -165,7 +165,7 @@ export class IncomingResultHandler implements BinaryReply { this.codec = codec } - reply(reply: ArrayBuffer): void { + reply(reply: ArrayBuffer | null): void { try { if (reply == null) { this.callback.notImplemented(); diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/StandardMessageCodec.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/StandardMessageCodec.ets index 88de0fc5de..df27a12328 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/StandardMessageCodec.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/StandardMessageCodec.ets @@ -76,7 +76,7 @@ export default class StandardMessageCodec implements MessageCodec { return stream.buffer } - decodeMessage(message: ArrayBuffer): ESObject { + decodeMessage(message: ArrayBuffer | null): ESObject { if (message == null) { return null } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/StringCodec.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/StringCodec.ets index b824ac1f90..3ce96e365c 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/StringCodec.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/StringCodec.ets @@ -33,7 +33,7 @@ export default class StringCodec implements MessageCodec { return StringUtils.stringToArrayBuffer(message); } - decodeMessage(message: ArrayBuffer): string { + decodeMessage(message: ArrayBuffer | null): string { if (message == null) { return ""; } -- Gitee From b5f0fe4f6b1210326c122095b133c1e64687374e Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Sat, 17 Feb 2024 09:36:00 +0800 Subject: [PATCH 18/73] =?UTF-8?q?=E4=BF=AE=E6=94=B9engine=E4=BA=A7?= =?UTF-8?q?=E7=89=A9=E7=9B=B8=E5=85=B3=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- attachment/repos/bootstrap/ohos.py | 12 +- build/archives/BUILD.gn | 8 +- build/dart/rules.gni | 2 +- common/config.gni | 4 + shell/platform/ohos/BUILD.gn | 187 +++++++++++++++++++++++++++-- tools/gn | 14 ++- 6 files changed, 202 insertions(+), 25 deletions(-) diff --git a/attachment/repos/bootstrap/ohos.py b/attachment/repos/bootstrap/ohos.py index 21022e0454..f59d783c8f 100644 --- a/attachment/repos/bootstrap/ohos.py +++ b/attachment/repos/bootstrap/ohos.py @@ -315,17 +315,9 @@ def zipFiles(buildInfo, useZip2=False): TIME_STR, ) prefixInZip = os.path.join("src", "out", outputName) + excludes = ["obj", "exe.unstripped", "so.unstripped"] if IS_WINDOWS: - excludes = [ - ".*\.ilk", - ".*\.pdb", - ] - else: - excludes = [ - "obj", - "exe.unstripped", - "so.unstripped", - ] + excludes.extend([".*\.ilk", ".*\.pdb"]) zipFileDir(fileIn, fileName, prefixInZip, excludes=excludes, useZip2=useZip2) diff --git a/build/archives/BUILD.gn b/build/archives/BUILD.gn index 90993ddb42..dd4fbdc665 100644 --- a/build/archives/BUILD.gn +++ b/build/archives/BUILD.gn @@ -20,7 +20,7 @@ generated_file("artifacts_entitlement_config") { } } -if (build_engine_artifacts && !is_android) { +if (build_engine_artifacts && !is_android && !is_ohos) { zip_bundle("artifacts") { deps = [ "//flutter/flutter_frontend_server:frontend_server", @@ -129,6 +129,12 @@ if (build_engine_artifacts && !is_android) { } } +if (is_ohos) { + group("artifacts") { + deps = [ "//flutter/shell/platform/ohos:flutter_har_zip" ] + } +} + if (host_os == "linux" || host_os == "win") { group("embedder") { deps = [ "//flutter/shell/platform/embedder:embedder-archive" ] diff --git a/build/dart/rules.gni b/build/dart/rules.gni index c239d536c1..d92acff60e 100644 --- a/build/dart/rules.gni +++ b/build/dart/rules.gni @@ -155,7 +155,7 @@ template("flutter_snapshot") { } else { output_aot_lib = "libapp.so" } - libapp = "$target_gen_dir/ohos/libs/$output_aot_lib" + libapp = "$target_gen_dir/ohos/libs/$ohos_app_abi/$output_aot_lib" outputs += [ libapp ] args += [ "--snapshot_kind=app-aot-elf", diff --git a/common/config.gni b/common/config.gni index 21a43ba4f8..d74f2c9bc2 100644 --- a/common/config.gni +++ b/common/config.gni @@ -6,6 +6,10 @@ if (is_android) { import("//build/config/android/config.gni") } +if (is_ohos) { + import("//build/config/ohos/config.gni") +} + if (target_cpu == "arm" || target_cpu == "arm64") { import("//build/config/arm.gni") } diff --git a/shell/platform/ohos/BUILD.gn b/shell/platform/ohos/BUILD.gn index aa2f620ed7..f60b29c347 100644 --- a/shell/platform/ohos/BUILD.gn +++ b/shell/platform/ohos/BUILD.gn @@ -23,10 +23,15 @@ import("//flutter/testing/testing.gni") group("ohos") { deps = [ - ":flutter", + ":flutter_shell_native", #":publish_headers_ohos", - ":ohos_har" + #":ohos_har", + ":flutter_har_zip", + ":ohos_symbols", ] + if (target_cpu != "x86") { + deps += [ ":gen_snapshot" ] + } } shell_gpu_configuration("ohos_gpu_configuration") { enable_software = true @@ -195,7 +200,8 @@ executable("flutter_ohos_unittests") { ] } -shared_library("flutter") { +shared_library("flutter_shell_native") { + output_name = "flutter" deps = [ ":flutter_ohos_src" ] ldflags = ["--rtlib=compiler-rt", @@ -280,17 +286,17 @@ declare_args() { if (flutter_runtime_mode != "debug") { ohos_zip_archive_dir += "-$flutter_runtime_mode" } + ohos_api_int = 11 } action("ohos_har") { script = "//build/ohos/ohos_create_flutter_har.py" if (stripped_symbols) { - engine_library = "so.unstripped/libflutter.so" - } else { engine_library = "libflutter.so" + } else { + engine_library = "so.unstripped/libflutter.so" } - #engine_library = "libflutter.so" inputs = [ # "$root_build_dir/$embedding_har_filename", @@ -306,19 +312,21 @@ action("ohos_har") { "--embedding_src", "../../flutter/shell/platform/ohos/flutter_embedding", "--build_dir", - "./ohos/flutter_embedding", + "./obj/ohos/flutter_embedding", "--build_type", flutter_runtime_mode, "--output", - rebase_path("flutter_embedding.har", root_build_dir, root_build_dir), + rebase_path("flutter.har", root_build_dir, root_build_dir), "--native_lib", rebase_path("$engine_library", root_build_dir, root_build_dir), "--ohos_abi", ohos_app_abi, + "--ohos_api_int", + ohos_api_int ] deps = [ - ":flutter" + ":flutter_shell_native" ] if (flutter_runtime_mode == "profile") { @@ -333,3 +341,164 @@ action("ohos_har") { } } +zip_bundle("flutter_har_zip") { + output = "$ohos_zip_archive_dir/artifacts.zip" + files = [ + { + source = "$root_build_dir/flutter.har" + destination = "flutter.har" + } + ] + + deps = [ ":ohos_har" ] +} + +zip_bundle("ohos_symbols") { + output = "$ohos_zip_archive_dir/symbols.zip" + files = [ + { + source = "$root_build_dir/so.unstripped/libflutter.so" + destination = "libflutter.so" + }, + ] + + deps = [ ":flutter_shell_native" ] +} + +generated_file("ohos_entitlement_config") { + outputs = [ "$target_gen_dir/ohos_entitlements.txt" ] + contents = [ "gen_snapshot" ] + deps = [] +} + +if (target_cpu != "x86") { + zip_bundle("gen_snapshot") { + gen_snapshot_bin = "gen_snapshot" + gen_snapshot_out_dir = get_label_info( + "//third_party/dart/runtime/bin:gen_snapshot($host_toolchain)", + "root_out_dir") + gen_snapshot_path = rebase_path("$gen_snapshot_out_dir/$gen_snapshot_bin") + + if (host_os == "linux") { + output = "$ohos_zip_archive_dir/linux-x64.zip" + } else if (host_os == "mac") { + output = "$ohos_zip_archive_dir/darwin-x64.zip" + } else if (host_os == "win") { + output = "$ohos_zip_archive_dir/windows-x64.zip" + gen_snapshot_bin = "gen_snapshot.exe" + gen_snapshot_path = rebase_path("$root_out_dir/$gen_snapshot_bin") + } + + files = [ + { + source = gen_snapshot_path + destination = gen_snapshot_bin + }, + ] + + deps = [ "//third_party/dart/runtime/bin:gen_snapshot($host_toolchain)" ] + } + + # TODO(godofredoc): Remove gen_snapshot and rename new_gen_snapshot when v2 migration is complete. + # BUG: https://github.com/flutter/flutter/issues/105351 + zip_bundle("new_gen_snapshot") { + gen_snapshot_bin = "gen_snapshot" + gen_snapshot_out_dir = get_label_info( + "//third_party/dart/runtime/bin:gen_snapshot($host_toolchain)", + "root_out_dir") + gen_snapshot_path = rebase_path("$gen_snapshot_out_dir/$gen_snapshot_bin") + + if (host_os == "linux") { + output = "$ohos_zip_archive_dir/$full_platform_name-$flutter_runtime_mode/linux-x64.zip" + } else if (host_os == "mac") { + output = "$ohos_zip_archive_dir/$full_platform_name-$flutter_runtime_mode/darwin-x64.zip" + } else if (host_os == "win") { + output = "$ohos_zip_archive_dir/$full_platform_name-$flutter_runtime_mode/windows-x64.zip" + gen_snapshot_bin = "gen_snapshot.exe" + gen_snapshot_path = rebase_path("$root_out_dir/$gen_snapshot_bin") + } + + files = [ + { + source = gen_snapshot_path + destination = gen_snapshot_bin + }, + ] + + deps = [ "//third_party/dart/runtime/bin:gen_snapshot($host_toolchain)" ] + + if (host_os == "mac") { + deps += [ ":ohos_entitlement_config" ] + files += [ + { + source = "$target_gen_dir/ohos_entitlements.txt" + destination = "entitlements.txt" + }, + ] + } + } +} + +if (target_cpu == "x64" || target_cpu == "arm64") { + zip_bundle("analyze_snapshot") { + deps = + [ "//third_party/dart/runtime/bin:analyze_snapshot($host_toolchain)" ] + + analyze_snapshot_bin = "analyze_snapshot" + analyze_snapshot_out_dir = + get_label_info( + "//third_party/dart/runtime/bin:analyze_snapshot($host_toolchain)", + "root_out_dir") + analyze_snapshot_path = + rebase_path("$analyze_snapshot_out_dir/$analyze_snapshot_bin") + + if (host_os == "linux") { + output = "$ohos_zip_archive_dir/analyze-snapshot-linux-x64.zip" + } else if (host_os == "mac") { + output = "$ohos_zip_archive_dir/analyze-snapshot-darwin-x64.zip" + } else if (host_os == "win") { + output = "$ohos_zip_archive_dir/analyze-snapshot-windows-x64.zip" + analyze_snapshot_bin = "analyze-snapshot.exe" + analyze_snapshot_path = rebase_path("$root_out_dir/$analyze_snapshot_bin") + } + + files = [ + { + source = analyze_snapshot_path + destination = analyze_snapshot_bin + }, + ] + } + + # TODO(godofredoc): Remove analyze_snapshot and rename new_analyze_snapshot when v2 migration is complete. + # BUG: https://github.com/flutter/flutter/issues/105351 + zip_bundle("new_analyze_snapshot") { + deps = + [ "//third_party/dart/runtime/bin:analyze_snapshot($host_toolchain)" ] + + analyze_snapshot_bin = "analyze_snapshot" + analyze_snapshot_out_dir = + get_label_info( + "//third_party/dart/runtime/bin:analyze_snapshot($host_toolchain)", + "root_out_dir") + analyze_snapshot_path = + rebase_path("$analyze_snapshot_out_dir/$analyze_snapshot_bin") + + if (host_os == "linux") { + output = "$ohos_zip_archive_dir/$full_platform_name-$flutter_runtime_mode/analyze-snapshot-linux-x64.zip" + } else if (host_os == "mac") { + output = "$ohos_zip_archive_dir/$full_platform_name-$flutter_runtime_mode/analyze-snapshot-darwin-x64.zip" + } else if (host_os == "win") { + output = "$ohos_zip_archive_dir/$full_platform_name-$flutter_runtime_mode/analyze-snapshot-windows-x64.zip" + analyze_snapshot_bin = "analyze-snapshot.exe" + analyze_snapshot_path = rebase_path("$root_out_dir/$analyze_snapshot_bin") + } + + files = [ + { + source = analyze_snapshot_path + destination = analyze_snapshot_bin + }, + ] + } +} diff --git a/tools/gn b/tools/gn index a5efe0f75d..98a207a1be 100755 --- a/tools/gn +++ b/tools/gn @@ -303,6 +303,9 @@ def to_gn_args(args): gn_args['is_official_build'] = True # Disable Skia test utilities. gn_args['android_full_debug' ] = args.target_os == 'android' and args.unoptimized + + gn_args['ohos_api_int'] = args.ohos_api_int + if args.clang is None: gn_args['is_clang'] = True else: @@ -761,6 +764,9 @@ def parse_args(args): parser.add_argument( '--ohos-cpu', type=str, choices=['x64', 'x86', 'arm64', 'arm'] ) + parser.add_argument( + '--ohos-api-int', type=int, choices=[10, 11], default=10 + ) parser.add_argument( '--fuchsia-cpu', type=str, choices=['x64', 'arm64'], default='x64' ) @@ -1047,10 +1053,10 @@ def main(argv): print('XX target_os:%s' % args.target_os) if args.target_os == 'ohos': - if args.ohos_cpu is not None: - args.linux_cpu = args.ohos_cpu - elif args.linux_cpu is not None : - args.ohos_cpu = args.linux_cpu + if args.ohos_cpu is not None: + args.linux_cpu = args.ohos_cpu + elif args.linux_cpu is not None : + args.ohos_cpu = args.linux_cpu if not args.web: if args.ide != '': -- Gitee From bc849c310715f58bf51f342d30e563a00b681fa3 Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Sat, 17 Feb 2024 09:36:40 +0800 Subject: [PATCH 19/73] =?UTF-8?q?=E6=9B=B4=E6=96=B0hvigor=E5=88=B04.0.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- .../ohos/flutter_embedding/hvigor/hvigor-config.json5 | 11 ++++++----- shell/platform/ohos/flutter_embedding/hvigorfile.ts | 8 ++++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/hvigor/hvigor-config.json5 b/shell/platform/ohos/flutter_embedding/hvigor/hvigor-config.json5 index 3496547c0b..5c4892a18d 100755 --- a/shell/platform/ohos/flutter_embedding/hvigor/hvigor-config.json5 +++ b/shell/platform/ohos/flutter_embedding/hvigor/hvigor-config.json5 @@ -12,9 +12,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -{ - "hvigorVersion": "4.0.2", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "4.0.2", - } + +{ + "hvigorVersion": "4.0.2", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "4.0.2", + } } diff --git a/shell/platform/ohos/flutter_embedding/hvigorfile.ts b/shell/platform/ohos/flutter_embedding/hvigorfile.ts index 5a172b770e..8f2d2aafe6 100755 --- a/shell/platform/ohos/flutter_embedding/hvigorfile.ts +++ b/shell/platform/ohos/flutter_embedding/hvigorfile.ts @@ -13,5 +13,9 @@ * limitations under the License. */ -// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. -export { appTasks } from '@ohos/hvigor-ohos-plugin'; \ No newline at end of file +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file -- Gitee From c684e30a8533f6b080a3bec26850e750286f6754 Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Sat, 17 Feb 2024 09:36:40 +0800 Subject: [PATCH 20/73] =?UTF-8?q?hvigor=E6=89=93=E5=8C=85=E5=8A=A0?= =?UTF-8?q?=E4=B8=8Aclean=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- attachment/repos/build.patch | 4 ++-- shell/platform/ohos/flutter_embedding/.gitignore | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/attachment/repos/build.patch b/attachment/repos/build.patch index d1bf7b82e2..c9f4260f96 100644 --- a/attachment/repos/build.patch +++ b/attachment/repos/build.patch @@ -717,7 +717,7 @@ index 7987e51..cd7b060 100644 } else { diff --git a/build/ohos/ohos_create_flutter_har.py b/build/ohos/ohos_create_flutter_har.py new file mode 100644 -index 0000000..4e052ed +index 0000000..12fb407 --- /dev/null +++ b/build/ohos/ohos_create_flutter_har.py @@ -0,0 +1,141 @@ @@ -816,7 +816,7 @@ index 0000000..4e052ed + runCommand( + ("cd %s && " % dirEmbedding) + + (".%s" % os.sep) -+ + "hvigorw --mode module -p module=flutter@default -p product=default assembleHar --no-daemon" ++ + "hvigorw clean --mode module -p module=flutter@default -p product=default assembleHar --no-daemon" + ) + + diff --git a/shell/platform/ohos/flutter_embedding/.gitignore b/shell/platform/ohos/flutter_embedding/.gitignore index 4510e76666..969cec852a 100644 --- a/shell/platform/ohos/flutter_embedding/.gitignore +++ b/shell/platform/ohos/flutter_embedding/.gitignore @@ -8,3 +8,4 @@ /.clang-format /.clang-tidy **/.test +flutter/BuildProfile.ets -- Gitee From bedbee328aaed3664da8a5444f2e715a01c9c529 Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Sat, 17 Feb 2024 09:36:40 +0800 Subject: [PATCH 21/73] =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BD=BF=E7=94=A8hvigo?= =?UTF-8?q?rw=E7=9A=84=E5=8F=82=E6=95=B0=E6=8C=87=E5=AE=9A=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- attachment/repos/build.patch | 44 ++++++++----------- .../flutter_embedding/build-profile.json5 | 11 +++++ .../engine/loader/FlutterApplicationInfo.ets | 6 ++- 3 files changed, 33 insertions(+), 28 deletions(-) diff --git a/attachment/repos/build.patch b/attachment/repos/build.patch index c9f4260f96..7dd52e5b16 100644 --- a/attachment/repos/build.patch +++ b/attachment/repos/build.patch @@ -717,10 +717,10 @@ index 7987e51..cd7b060 100644 } else { diff --git a/build/ohos/ohos_create_flutter_har.py b/build/ohos/ohos_create_flutter_har.py new file mode 100644 -index 0000000..12fb407 +index 0000000..fc46359 --- /dev/null +++ b/build/ohos/ohos_create_flutter_har.py -@@ -0,0 +1,141 @@ +@@ -0,0 +1,133 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. @@ -759,6 +759,17 @@ index 0000000..12fb407 + "compatibleSdkVersion": "%s", + "runtimeOS": "HarmonyOS", + } ++ ], ++ "buildModeSet": [ ++ { ++ "name": "debug", ++ }, ++ { ++ "name": "release" ++ }, ++ { ++ "name": "profile" ++ }, + ] + }, + "modules": [ @@ -771,6 +782,7 @@ index 0000000..12fb407 +""" + + ++# 更新har的配置文件,指定编译使用的api版本 +def updateConfig(buildDir, apiInt): + apiStr = "4.1.0(11)" if apiInt == 11 else "4.0.0(10)" + jsonFile = os.path.join(buildDir, "build-profile.json5") @@ -790,33 +802,13 @@ index 0000000..12fb407 + logging.info("runCommand finish, code = %s, command = %s" % (code, command)) + + -+# 替换文件中的字符串 -+def replaceStr(file, regex, newstr): -+ with open(file, "r", encoding="utf-8") as f1: -+ lines = f1.readlines() -+ with open(file, "w+", encoding="utf-8") as f2: -+ for line in lines: -+ a = re.sub(regex, newstr, line) -+ f2.writelines(a) -+ -+ -+# 编译har文件 ++# 编译har文件,通过hvigorw的命令行参数指定编译类型(debug/release/profile) +def buildHar(buildDir, apiInt, buildType): + updateConfig(buildDir, apiInt) -+ isDebug = "true" if buildType == "debug" else "false" -+ isProfile = "true" if buildType == "profile" else "false" -+ dirEmbedding = buildDir -+ targetFile = os.path.join( -+ buildDir, -+ "flutter/src/main/ets/embedding/engine/loader/FlutterApplicationInfo.ets", -+ ) -+ logging.info("isDebugMode=%s, isProfile=%s" % (isDebug, isProfile)) -+ replaceStr(targetFile, "isDebugMode = .*", "isDebugMode = %s;" % isDebug) -+ replaceStr(targetFile, "isProfile = .*", "isProfile = %s;" % isProfile) + runCommand( -+ ("cd %s && " % dirEmbedding) -+ + (".%s" % os.sep) -+ + "hvigorw clean --mode module -p module=flutter@default -p product=default assembleHar --no-daemon" ++ "cd %s && .%shvigorw clean --mode module " % (buildDir, os.sep) ++ + "-p module=flutter@default -p product=default -p buildMode=%s " % buildType ++ + "assembleHar --no-daemon" + ) + + diff --git a/shell/platform/ohos/flutter_embedding/build-profile.json5 b/shell/platform/ohos/flutter_embedding/build-profile.json5 index ae4533ee39..2d2ee02569 100755 --- a/shell/platform/ohos/flutter_embedding/build-profile.json5 +++ b/shell/platform/ohos/flutter_embedding/build-profile.json5 @@ -24,6 +24,17 @@ "compatibleSdkVersion": "4.1.0(11)", "runtimeOS": "HarmonyOS", } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + }, + { + "name": "profile" + }, ] }, "modules": [ diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/loader/FlutterApplicationInfo.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/loader/FlutterApplicationInfo.ets index 272615d612..8ff3aec5b8 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/loader/FlutterApplicationInfo.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/loader/FlutterApplicationInfo.ets @@ -13,6 +13,8 @@ * limitations under the License. */ +import BuildProfile from "../../../../../../BuildProfile.ets"; + const DEFAULT_AOT_SHARED_LIBRARY_NAME = "libapp.so"; const DEFAULT_VM_SNAPSHOT_DATA = "vm_snapshot_data"; const DEFAULT_ISOLATE_SNAPSHOT_DATA = "isolate_snapshot_data"; @@ -49,7 +51,7 @@ export default class FlutterApplicationInfo { this.domainNetworkPolicy = domainNetworkPolicy == null ? "" : domainNetworkPolicy; this.nativeLibraryDir = nativeLibraryDir; this.automaticallyRegisterPlugins = automaticallyRegisterPlugins; - this.isDebugMode = false; - this.isProfile = false; + this.isDebugMode = "debug" == String(BuildProfile.BUILD_MODE_NAME); + this.isProfile = "profile" == String(BuildProfile.BUILD_MODE_NAME); } } \ No newline at end of file -- Gitee From 2daf9f88956e0bda7fca8f8a979407169fb9d1eb Mon Sep 17 00:00:00 2001 From: gtbluesky Date: Sun, 18 Feb 2024 16:35:14 +0800 Subject: [PATCH 22/73] =?UTF-8?q?=E5=AF=B9=E5=A4=96=E6=9A=B4=E9=9C=B2Platf?= =?UTF-8?q?ormPluginCallback=EF=BC=8C=E5=9C=A8=E6=B7=B7=E5=90=88=E6=A0=88?= =?UTF-8?q?=E5=9C=BA=E6=99=AF=E4=B8=8B=E9=9C=80=E8=A6=81=E5=AF=B9=E5=85=B6?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E8=B5=8B=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gtbluesky --- .../flutter/src/main/ets/plugin/PlatformPlugin.ets | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/PlatformPlugin.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/PlatformPlugin.ets index 44b8ebe6d9..ac2f801700 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/PlatformPlugin.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/PlatformPlugin.ets @@ -34,7 +34,7 @@ import common from '@ohos.app.ability.common'; */ export default class PlatformPlugin { private static TAG = "PlatformPlugin"; - private callback = new PlatformPluginCallback(); + callback = new PlatformPluginCallback(); constructor(platformChannel: PlatformChannel, context: common.Context, platformPluginDelegate?: PlatformPluginDelegate) { this.callback.platformChannel = platformChannel; @@ -92,7 +92,7 @@ export interface PlatformPluginDelegate { popSystemNavigator(): boolean; } -class PlatformPluginCallback implements PlatformMessageHandler { +export class PlatformPluginCallback implements PlatformMessageHandler { private static TAG = "PlatformPluginCallback"; platform: PlatformPlugin | null = null; windowClass: window.Window | null = null; -- Gitee From bbbf42ce63ff07263bb6d8d99247081ecd12302b Mon Sep 17 00:00:00 2001 From: huangxiaoyao <976125628@qq.com> Date: Tue, 20 Feb 2024 16:45:55 +0800 Subject: [PATCH 23/73] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8E=9F=E7=94=9F?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E6=89=93=E5=BC=80flutter=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E8=BF=94=E5=9B=9E=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> --- .../ets/embedding/ohos/FlutterAbilityAndEntryDelegate.ets | 8 +++++++- .../flutter/src/main/ets/embedding/ohos/FlutterEntry.ets | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityAndEntryDelegate.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityAndEntryDelegate.ets index 056d8c0b5c..df276bd2e5 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityAndEntryDelegate.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityAndEntryDelegate.ets @@ -39,6 +39,7 @@ import GeneratedPluginRegister from '../engine/plugins/util/GeneratedPluginRegis import { UIContext } from '@ohos.arkui.UIContext'; import { FlutterView } from '../../view/FlutterView'; import FlutterManager from './FlutterManager'; +import router from '@ohos.router'; const TAG = "FlutterAbilityDelegate"; const PLUGINS_RESTORATION_BUNDLE_KEY = "plugins"; @@ -97,7 +98,7 @@ class FlutterAbilityAndEntryDelegate implements ExclusiveAppComponent } if (this.flutterEngine) { this.textInputPlugin = new TextInputPlugin(this.flutterEngine.getTextInputChannel()!); - this.platformPlugin = new PlatformPlugin(this.flutterEngine.getPlatformChannel()!, this.context); + this.platformPlugin = new PlatformPlugin(this.flutterEngine.getPlatformChannel()!, this.context, this); this.settings = new Settings(this.flutterEngine.getSettingsChannel()!); this.flutterEngine.getSystemLanguages(); } @@ -107,6 +108,11 @@ class FlutterAbilityAndEntryDelegate implements ExclusiveAppComponent this.host?.configureFlutterEngine(this.flutterEngine!!); } + popSystemNavigator(): boolean { + router.back(); + return true; + } + /** * 加载app.so资源或者snapshot */ diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterEntry.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterEntry.ets index d90be8a48b..2d5a4a0ef8 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterEntry.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterEntry.ets @@ -124,6 +124,11 @@ export default class FlutterEntry implements Host { this?.delegate?.onBackground(); } + onBackPress() { + Log.d(TAG, "FlutterEntry onBackPress==="); + this?.delegate?.flutterEngine?.getNavigationChannel()?.popRoute(); + } + shouldDispatchAppLifecycleState(): boolean { return true; } -- Gitee From 06c916d33621c783dfaf062c89884e38f8d22148 Mon Sep 17 00:00:00 2001 From: cjand <1747143535@qq.com> Date: Wed, 21 Feb 2024 18:06:57 +0800 Subject: [PATCH 24/73] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cjand <1747143535@qq.com> --- .../ets/plugin/common/BasicMessageChannel.ets | 8 +++--- .../ohos/flutter_embedding/local.properties | 27 +++++-------------- 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/BasicMessageChannel.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/BasicMessageChannel.ets index 4b627aea9e..5a58b8c3ca 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/BasicMessageChannel.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/BasicMessageChannel.ets @@ -74,7 +74,7 @@ export default class BasicMessageChannel { * * @param handler a {@link MessageHandler}, or null to deregister. */ - setMessageHandler(handler: MessageHandler): void { + setMessageHandler(handler: MessageHandler | null): void { // We call the 2 parameter variant specifically to avoid breaking changes in // mock verify calls. // See https://github.com/flutter/flutter/issues/92582. @@ -146,17 +146,17 @@ class IncomingReplyHandler implements BinaryReply { } class IncomingMessageHandler implements BinaryMessageHandler { - private handler: MessageHandler + private handler: MessageHandler | null private codec: MessageCodec - constructor(handler: MessageHandler, codec: MessageCodec) { + constructor(handler: MessageHandler | null, codec: MessageCodec) { this.handler = handler; this.codec = codec } onMessage(message: ArrayBuffer, callback: BinaryReply) { try { - this.handler.onMessage( + this.handler?.onMessage( this.codec.decodeMessage(message), { reply: (reply: T): void => { diff --git a/shell/platform/ohos/flutter_embedding/local.properties b/shell/platform/ohos/flutter_embedding/local.properties index 42b3cf913e..127b42ca13 100755 --- a/shell/platform/ohos/flutter_embedding/local.properties +++ b/shell/platform/ohos/flutter_embedding/local.properties @@ -1,23 +1,10 @@ -# Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# This file is automatically generated by DevEco Studio. -# Do not modify this file -- YOUR CHANGES WILL BE ERASED! -# -# This file should *NOT* be checked into Version Control Systems, -# as it contains information specific to your local configuration. -# +# This file is automatically generated by DevEco Studio. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file should *NOT* be checked into Version Control Systems, +# as it contains information specific to your local configuration. +# # For customization when using a Version Control System, please read the header note. sdk.dir= nodejs.dir= - +hwsdk.dir=D:/env/sdk \ No newline at end of file -- Gitee From ece184fd8a6640304f067439e6285f0771451aff Mon Sep 17 00:00:00 2001 From: cjand <1747143535@qq.com> Date: Thu, 22 Feb 2024 10:12:28 +0800 Subject: [PATCH 25/73] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cjand <1747143535@qq.com> --- .../ohos/flutter_embedding/local.properties | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/local.properties b/shell/platform/ohos/flutter_embedding/local.properties index 127b42ca13..bc8cf2a57b 100755 --- a/shell/platform/ohos/flutter_embedding/local.properties +++ b/shell/platform/ohos/flutter_embedding/local.properties @@ -1,10 +1,22 @@ +# Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + # This file is automatically generated by DevEco Studio. # Do not modify this file -- YOUR CHANGES WILL BE ERASED! # # This file should *NOT* be checked into Version Control Systems, # as it contains information specific to your local configuration. # -# For customization when using a Version Control System, please read the header note. -sdk.dir= -nodejs.dir= -hwsdk.dir=D:/env/sdk \ No newline at end of file +# For customization when using a Version Control System, please read the header note. +sdk.dir= +nodejs.dir= -- Gitee From 4cf54877c0f7fd677a45f6fc6454679c7c976d4d Mon Sep 17 00:00:00 2001 From: SimpleLove520 <1960997571@qq.com> Date: Thu, 22 Feb 2024 10:13:13 +0800 Subject: [PATCH 26/73] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dwebview=E5=8F=AF?= =?UTF-8?q?=E8=83=BD=E4=BC=9A=E8=A6=86=E7=9B=96=E9=A1=B6=E9=83=A8=E5=AF=BC?= =?UTF-8?q?=E8=88=AA=E6=A0=8F=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: SimpleLove520 <1960997571@qq.com> --- .../main/ets/embedding/ohos/FlutterPage.ets | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets index 53e7ef62d1..e29e877c56 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets @@ -35,13 +35,13 @@ const TAG = "FlutterPage"; */ @Component export struct FlutterPage { - @State rootDvModel: DVModel | undefined = undefined + @State rootDvModel: DVModelChildren | undefined = undefined @Prop viewId: string = "" private flutterView?: FlutterView | null aboutToAppear() { this.flutterView = FlutterManager.getInstance().getFlutterView(this.viewId); - this.rootDvModel = this.flutterView!!.getDVModel() + this.rootDvModel = this.flutterView!!.getDVModel().children } build() { @@ -56,13 +56,14 @@ export struct FlutterPage { Log.d(TAG, "XComponent onDestroy "); this.flutterView?.onSurfaceDestroyed() }) - DynamicView({ - model: this.rootDvModel, - params: this.rootDvModel!!.params as DVModelParameters, - events: this.rootDvModel!!.events as DVModelEvents, - children: this.rootDvModel!!.children as DVModelChildren, - customBuilder: this.rootDvModel!!.builder as ($$: Record<"params", DVModelParameters>) => void - //customBuilder: this.rootDvModel.model.builder as ($$: { params: DVModelParameters }) => void + ForEach(this.rootDvModel!!, (child:ESObject) =>{ + DynamicView({ + model: child as DVModel, + params:child.params, + events:child.events, + children:child.children, + customBuilder:child.builder + }) }) } .onAreaChange((oldValue: Area, newValue: Area) => { -- Gitee From 1e986bf7239fd4b8b01f3729cbfa3f5835e588b8 Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Mon, 22 Jan 2024 17:33:46 +0800 Subject: [PATCH 27/73] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BC=96=E8=AF=91host?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E7=9A=84=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- fml/logging_unittests.cc | 4 ++++ impeller/playground/playground_impl.cc | 4 ++++ impeller/renderer/backend/vulkan/render_pass_vk.cc | 2 ++ 3 files changed, 10 insertions(+) diff --git a/fml/logging_unittests.cc b/fml/logging_unittests.cc index a64d33e52f..74caf80d71 100644 --- a/fml/logging_unittests.cc +++ b/fml/logging_unittests.cc @@ -16,6 +16,10 @@ #include "gmock/gmock.h" #endif +#ifdef __clang__ +#pragma clang diagnostic ignored "-Wreturn-type" +#endif + namespace fml { namespace testing { diff --git a/impeller/playground/playground_impl.cc b/impeller/playground/playground_impl.cc index 613de6e411..e26f84ff6b 100644 --- a/impeller/playground/playground_impl.cc +++ b/impeller/playground/playground_impl.cc @@ -19,6 +19,10 @@ #include "impeller/playground/backend/vulkan/playground_impl_vk.h" #endif // IMPELLER_ENABLE_VULKAN +#ifdef __clang__ +#pragma clang diagnostic ignored "-Wreturn-type" +#endif + namespace impeller { std::unique_ptr PlaygroundImpl::Create( diff --git a/impeller/renderer/backend/vulkan/render_pass_vk.cc b/impeller/renderer/backend/vulkan/render_pass_vk.cc index 08d4cd6fad..2d20bd0510 100644 --- a/impeller/renderer/backend/vulkan/render_pass_vk.cc +++ b/impeller/renderer/backend/vulkan/render_pass_vk.cc @@ -1,7 +1,9 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#ifdef __clang__ #pragma clang diagnostic ignored "-Wreturn-type" +#endif #include "impeller/renderer/backend/vulkan/render_pass_vk.h" -- Gitee From 531b458df4a870413f05fd8f47c60e0dac3582e3 Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Thu, 25 Jan 2024 15:29:00 +0800 Subject: [PATCH 28/73] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BC=96=E8=AF=91andro?= =?UTF-8?q?id=E7=9B=B8=E5=85=B3=E7=9A=84=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- impeller/tools/impeller.gni | 4 ++-- shell/platform/android/android_surface_gl_impeller.cc | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/impeller/tools/impeller.gni b/impeller/tools/impeller.gni index 3df2553437..6490cd7a9d 100644 --- a/impeller/tools/impeller.gni +++ b/impeller/tools/impeller.gni @@ -17,8 +17,8 @@ declare_args() { impeller_enable_opengles = is_linux || is_win || is_android ||is_ohos # Whether the Vulkan backend is enabled. - #impeller_enable_vulkan = is_mac || is_linux || is_win || is_android - impeller_enable_vulkan = is_win || is_android + impeller_enable_vulkan = is_mac || is_linux || is_win || is_android + #impeller_enable_vulkan = is_win || is_android # Whether to use a prebuilt impellerc. # If this is the empty string, impellerc will be built. diff --git a/shell/platform/android/android_surface_gl_impeller.cc b/shell/platform/android/android_surface_gl_impeller.cc index 89cbf668a7..5d66ab422f 100644 --- a/shell/platform/android/android_surface_gl_impeller.cc +++ b/shell/platform/android/android_surface_gl_impeller.cc @@ -12,6 +12,10 @@ #include "flutter/impeller/toolkit/egl/surface.h" #include "flutter/shell/gpu/gpu_surface_gl_impeller.h" +#ifdef __clang__ +#pragma clang diagnostic ignored "-Wreturn-type" +#endif + namespace flutter { class AndroidSurfaceGLImpeller::ReactorWorker final -- Gitee From b860d612cfebbfb2867c61030ae86462a297a8f2 Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Thu, 25 Jan 2024 20:47:55 +0800 Subject: [PATCH 29/73] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- impeller/tools/impeller.gni | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/impeller/tools/impeller.gni b/impeller/tools/impeller.gni index 6490cd7a9d..0c54d8de36 100644 --- a/impeller/tools/impeller.gni +++ b/impeller/tools/impeller.gni @@ -17,8 +17,8 @@ declare_args() { impeller_enable_opengles = is_linux || is_win || is_android ||is_ohos # Whether the Vulkan backend is enabled. - impeller_enable_vulkan = is_mac || is_linux || is_win || is_android - #impeller_enable_vulkan = is_win || is_android + #impeller_enable_vulkan = is_mac || is_linux || is_win || is_android + impeller_enable_vulkan = (is_win || is_android || is_linux) && !is_ohos # Whether to use a prebuilt impellerc. # If this is the empty string, impellerc will be built. -- Gitee From fc92008a47bb226430160d46805df7f20fe29a35 Mon Sep 17 00:00:00 2001 From: zmf <279822581@qq.com> Date: Thu, 22 Feb 2024 22:55:20 +0800 Subject: [PATCH 30/73] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=BAHOS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zmf <279822581@qq.com> --- OAT.xml | 1 + README.en.md | 4 +-- README.md | 4 +-- attachment/repos/bootstrap/ohos.py | 50 ++++++++++++++---------------- 4 files changed, 29 insertions(+), 30 deletions(-) diff --git a/OAT.xml b/OAT.xml index 2e84930ccc..32c103d0c2 100644 --- a/OAT.xml +++ b/OAT.xml @@ -92,6 +92,7 @@ used to filter file path. + +export HOS_SDK_HOME= ``` 5. Start building: In the engine directory, execute `./ohos` to start building the flutter engine that supports ohos devices. diff --git a/README.md b/README.md index e19e793031..7fdff825d8 100644 --- a/README.md +++ b/README.md @@ -53,10 +53,10 @@ Flutter Engine 3. 同步代码:在engine目录,执行`gclient sync`;这里会同步engine源码、官方packages仓,还有执行ohos_setup任务; -4. 下载sdk: 在[每日构建](http://ci.openharmony.cn/workbench/cicd/dailybuild/dailylist)下载ohos-sdk-full,配置以下环境变量: +4. 下载sdk: 从[鸿蒙套件列表](https://developer.harmonyos.com/deveco-developer-suite/enabling/kit?currentPage=1&pageSize=100)下载配套开发工具,暂不支持非该渠道下载的套件 ```sh -export OHOS_SDK_HOME= +export HOS_SDK_HOME= ``` 5. 开始构建:在engine目录,执行`./ohos`,即可开始构建支持ohos设备的flutter engine。 diff --git a/attachment/repos/bootstrap/ohos.py b/attachment/repos/bootstrap/ohos.py index f59d783c8f..6df73753d4 100644 --- a/attachment/repos/bootstrap/ohos.py +++ b/attachment/repos/bootstrap/ohos.py @@ -123,17 +123,16 @@ def findNativeInCurrentDir(): def getNdkHome(): - OHOS_NDK_HOME = os.getenv("OHOS_NDK_HOME") - if not OHOS_NDK_HOME: - OHOS_NDK_HOME = findNativeInCurrentDir() - if not OHOS_NDK_HOME: - OHOS_SDK_HOME = os.getenv("OHOS_SDK_HOME") + HOS_NDK_HOME = os.getenv("HOS_NDK_HOME") + if not HOS_NDK_HOME: + HOS_NDK_HOME = findNativeInCurrentDir() + if not HOS_NDK_HOME: + HOS_SDK_HOME = os.getenv("HOS_SDK_HOME") sdkInt = 0 if ('openharmony' in os.getenv("HOS_SDK_HOME")): - print('dddd') - OHOS_SDK_HOME = "%s/openharmony" % os.getenv("HOS_SDK_HOME") - if os.path.exists(OHOS_SDK_HOME): - for dir in os.listdir(OHOS_SDK_HOME): + HOS_SDK_HOME = "%s/openharmony" % os.getenv("HOS_SDK_HOME") + if os.path.exists(HOS_SDK_HOME): + for dir in os.listdir(HOS_SDK_HOME): try: tmpInt = int(dir) sdkInt = max(sdkInt, tmpInt) @@ -142,46 +141,45 @@ def getNdkHome(): if sdkInt == 0: logging.error( "Ohos sdkInt parse failed, please config the correct environment variable." - " Such as: 'export OHOS_SDK_HOME=~/ohos/sdk/openharmony'." + " Such as: 'export HOS_SDK_HOME=~/ohos/sdk/openharmony'." ) exit(20) - OHOS_NDK_HOME = os.path.join(OHOS_SDK_HOME, str(sdkInt), "native") + HOS_NDK_HOME = os.path.join(HOS_SDK_HOME, str(sdkInt), "native") else: - print('go here') - OHOS_NDK_HOME = "%s/HarmonyOS-NEXT-DP1/base/native" % os.getenv("HOS_SDK_HOME") - logging.info("OHOS_NDK_HOME = %s" % OHOS_NDK_HOME) + HOS_NDK_HOME = "%s/HarmonyOS-NEXT-DP1/base/native" % os.getenv("HOS_SDK_HOME") + logging.info("HOS_NDK_HOME = %s" % HOS_NDK_HOME) if ( - (not os.path.exists(OHOS_NDK_HOME)) - or (not os.path.exists(OHOS_NDK_HOME + "/sysroot")) - or (not os.path.exists(OHOS_NDK_HOME + "/llvm/bin")) - or (not os.path.exists(OHOS_NDK_HOME + "/build-tools/cmake/bin")) + (not os.path.exists(HOS_NDK_HOME)) + or (not os.path.exists(HOS_NDK_HOME + "/sysroot")) + or (not os.path.exists(HOS_NDK_HOME + "/llvm/bin")) + or (not os.path.exists(HOS_NDK_HOME + "/build-tools/cmake/bin")) ): logging.error( """ - Please set the environment variables for HarmonyOS SDK to "HOS_SDK_HOME" or "OHOS_SDK_HOME". + Please set the environment variables for HarmonyOS SDK to "HOS_SDK_HOME" or "HOS_SDK_HOME". We will use both native/llvm and native/sysroot. Please ensure that the file "native/llvm/bin/clang" exists and is executable.""" ) exit(10) - return OHOS_NDK_HOME + return HOS_NDK_HOME # 指定engine编译的配置参数 def engineConfig(buildInfo, extraParam=""): - OHOS_NDK_HOME = getNdkHome() - # export PATH=$OHOS_NDK_HOME/build-tools/cmake/bin:$OHOS_NDK_HOME/llvm/bin:$PATH + HOS_NDK_HOME = getNdkHome() + # export PATH=$HOS_NDK_HOME/build-tools/cmake/bin:$HOS_NDK_HOME/llvm/bin:$PATH lastPath = os.getenv("PATH") os.environ["PATH"] = ( - "%s%s" % (os.path.join(OHOS_NDK_HOME, "build-tools", "cmake", "bin"), PATH_SEP) - + "%s%s" % (os.path.join(OHOS_NDK_HOME, "build-tools", "llvm", "bin"), PATH_SEP) + "%s%s" % (os.path.join(HOS_NDK_HOME, "build-tools", "cmake", "bin"), PATH_SEP) + + "%s%s" % (os.path.join(HOS_NDK_HOME, "build-tools", "llvm", "bin"), PATH_SEP) + "%s%s" % (os.path.abspath("depot_tools"), PATH_SEP) + lastPath ) unixCommand = "" if not IS_WINDOWS: unixCommand = ( - "--target-sysroot %s " % os.path.join(OHOS_NDK_HOME, "sysroot") - + "--target-toolchain %s " % os.path.join(OHOS_NDK_HOME, "llvm") + "--target-sysroot %s " % os.path.join(HOS_NDK_HOME, "sysroot") + + "--target-toolchain %s " % os.path.join(HOS_NDK_HOME, "llvm") + "--target-triple %s " % buildInfo.targetTriple ) OPT = "--unoptimized --no-lto " if buildInfo.buildType == "debug" else "" -- Gitee From 3b3900813d44d2f7df8c13919813d6e5e110bd75 Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Fri, 23 Feb 2024 18:05:14 +0800 Subject: [PATCH 31/73] =?UTF-8?q?=E7=BC=96=E8=AF=91host=E4=BA=A7=E7=89=A9?= =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- fml/message_loop_impl_unittests.cc | 2 +- tools/gn | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/fml/message_loop_impl_unittests.cc b/fml/message_loop_impl_unittests.cc index 1846f8c9d4..4225ef84e5 100644 --- a/fml/message_loop_impl_unittests.cc +++ b/fml/message_loop_impl_unittests.cc @@ -13,7 +13,7 @@ #define TIMESENSITIVE(x) TimeSensitiveTest_##x TEST(MessageLoopImpl, TIMESENSITIVE(WakeUpTimersAreSingletons)) { - auto loop_impl = fml::MessageLoopImpl::Create(); + auto loop_impl = fml::MessageLoopImpl::Create(nullptr); const auto t1 = fml::TimeDelta::FromMilliseconds(10); const auto t2 = fml::TimeDelta::FromMilliseconds(30); diff --git a/tools/gn b/tools/gn index 98a207a1be..a9f38074da 100755 --- a/tools/gn +++ b/tools/gn @@ -280,9 +280,6 @@ def to_gn_args(args): if args.enable_unittests: gn_args['enable_unittests'] = args.enable_unittests - gn_args['enable_unittests'] = False - print("enable_unittests:%s" % gn_args['enable_unittests'] ); - # Skia GN args. gn_args['skia_enable_flutter_defines' ] = True # Enable Flutter API guards in Skia. -- Gitee From f9e335d544e7bee445831183534e88980b19f9b0 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: Fri, 23 Feb 2024 19:28:21 +0800 Subject: [PATCH 32/73] Fix compiler error. See https://gitee.com/openharmony-sig/flutter_engine/issues/I93DI6 for more details. --- tools/gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/gn b/tools/gn index 98a207a1be..8f6f1fef7d 100755 --- a/tools/gn +++ b/tools/gn @@ -765,7 +765,7 @@ def parse_args(args): '--ohos-cpu', type=str, choices=['x64', 'x86', 'arm64', 'arm'] ) parser.add_argument( - '--ohos-api-int', type=int, choices=[10, 11], default=10 + '--ohos-api-int', type=int, choices=[10, 11], default=11 ) parser.add_argument( '--fuchsia-cpu', type=str, choices=['x64', 'arm64'], default='x64' -- Gitee From 584ade22a010b87fbfc626614584572981bb4918 Mon Sep 17 00:00:00 2001 From: 18719058668 <718092089@qq.com> Date: Mon, 26 Feb 2024 15:35:14 +0800 Subject: [PATCH 33/73] =?UTF-8?q?=E5=A4=96=E6=8E=A5=E7=BA=B9=E7=90=86?= =?UTF-8?q?=E5=8A=9F=E8=83=BDets=E5=B1=82=E5=90=88=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 18719058668 <718092089@qq.com> --- .../src/main/cpp/types/libflutter/index.d.ets | 10 +- .../ets/embedding/engine/FlutterEngine.ets | 15 +- .../FlutterEngineConnectionRegistry.ets | 2 +- .../main/ets/embedding/engine/FlutterNapi.ets | 20 +++ .../embedding/engine/loader/FlutterLoader.ets | 6 +- .../engine/plugins/FlutterPlugin.ets | 9 +- .../engine/renderer/FlutterRenderer.ets | 138 ++++++++++++++++++ .../engine/renderer/SurfaceTextureWrapper.ets | 30 ++++ .../ets/embedding/ohos/FlutterAbility.ets | 4 + .../ohos/FlutterAbilityAndEntryDelegate.ets | 4 + .../plugin/common/StandardMessageCodec.ets | 2 +- .../src/main/ets/view/TextureRegistry.ets | 20 ++- 12 files changed, 248 insertions(+), 12 deletions(-) create mode 100644 shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/renderer/FlutterRenderer.ets create mode 100644 shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/renderer/SurfaceTextureWrapper.ets diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/cpp/types/libflutter/index.d.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/cpp/types/libflutter/index.d.ets index c53957c7aa..6cb09bd9f0 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/cpp/types/libflutter/index.d.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/cpp/types/libflutter/index.d.ets @@ -99,4 +99,12 @@ export const nativeXComponentDetachFlutterEngine: (xcomponentId: number, nativeS */ export const nativeDestroy: ( nativeShellHolderId: number -) => void; \ No newline at end of file +) => void; + +export const nativeInitNativeImage: (nativeShellHolderId: number, textureId: number, aImage: image.Image) => void; + +export const nativeUnregisterTexture: (nativeShellHolderId: number, textureId: number) => void; + +export const nativeRegisterPixelMap: (nativeShellHolderId: number, textureId: number, pixelMap: PixelMap) => void; + +export const nativeRegisterTexture: (nativeShellHolderId: number, textureId: number) => number; \ No newline at end of file diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterEngine.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterEngine.ets index 880e9bc785..b99be906f1 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterEngine.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterEngine.ets @@ -42,7 +42,7 @@ import PlatformViewsController from '../../plugin/platform/PlatformViewsControll import { FlutterPlugin } from './plugins/FlutterPlugin'; import List from '@ohos.util.List'; import GeneratedPluginRegister from './plugins/util/GeneratedPluginRegister'; - +import { FlutterRenderer } from './renderer/FlutterRenderer'; const TAG = "FlutterEngine"; @@ -68,6 +68,7 @@ export default class FlutterEngine implements EngineLifecycleListener{ private accessibilityChannel: AccessibilityChannel | null = null; private localeChannel: LocalizationChannel | null = null; private flutterNapi: FlutterNapi; + private renderer: FlutterRenderer; private pluginRegistry: FlutterEngineConnectionRegistry | null = null; private textInputPlugin: TextInputPlugin | null = null; private localizationPlugin: LocalizationPlugin | null = null; @@ -99,6 +100,8 @@ export default class FlutterEngine implements EngineLifecycleListener{ } this.flutterLoader = flutterLoader; + this.renderer = new FlutterRenderer(this.flutterNapi); + if(platformViewsController == null) { platformViewsController = new PlatformViewsController(); } @@ -141,6 +144,8 @@ export default class FlutterEngine implements EngineLifecycleListener{ if (automaticallyRegisterPlugins && plugins) { GeneratedPluginRegister.registerGeneratedPlugins(this, plugins); } + + Log.d(TAG, "Call init finished.") } private attachToNapi(): void { @@ -218,6 +223,10 @@ export default class FlutterEngine implements EngineLifecycleListener{ return this.flutterNapi; } + getFlutterRenderer(): FlutterRenderer { + return this.renderer; + } + getDartExecutor(): DartExecutor { return this.dartExecutor } @@ -234,6 +243,10 @@ export default class FlutterEngine implements EngineLifecycleListener{ return this.settingsChannel; } + getFlutterLoader() { + return this.flutterLoader; + } + onPreEngineRestart(): void { } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterEngineConnectionRegistry.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterEngineConnectionRegistry.ets index be25395a31..90044b0dfc 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterEngineConnectionRegistry.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterEngineConnectionRegistry.ets @@ -55,7 +55,7 @@ export default class FlutterEngineConnectionRegistry implements PluginRegistry, constructor(appContext: common.Context, flutterEngine: FlutterEngine, flutterLoader: FlutterLoader) { this.flutterEngine = flutterEngine; - this.pluginBinding = new FlutterPluginBinding(appContext, flutterEngine, flutterEngine.getDartExecutor(), new DefaultFlutterAssets(flutterLoader), flutterEngine.getPlatformViewsController()?.getRegistry()); + this.pluginBinding = new FlutterPluginBinding(appContext, flutterEngine, flutterEngine.getDartExecutor(), new DefaultFlutterAssets(flutterLoader), flutterEngine.getFlutterRenderer(), flutterEngine.getPlatformViewsController()?.getRegistry()); } add(plugin: FlutterPlugin): void { 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 4b8d9a3a54..271ec23e6e 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 @@ -373,6 +373,26 @@ export default class FlutterNapi { detachFromNativeAndReleaseResources() { flutter.nativeDestroy(this.nativeShellHolderId!!); } + + initNativeImage(textureId: number, aImage: image.Image) { + Log.d(TAG, "called initNativeImage "); + flutter.nativeInitNativeImage(this.nativeShellHolderId!, textureId, aImage); + } + + unregisterTexture(textureId: number): void { + Log.d(TAG, "called unregisterTexture "); + flutter.nativeUnregisterTexture(this.nativeShellHolderId!, textureId); + } + + registerPixelMap(textureId: number, pixelMap: PixelMap): void { + Log.d(TAG, "called registerPixelMap "); + flutter.nativeRegisterPixelMap(this.nativeShellHolderId!, textureId, pixelMap); + } + + registerTexture(textureId: number): number { + Log.d(TAG, "called unregisterTexture "); + return flutter.nativeRegisterTexture(this.nativeShellHolderId!, textureId); + } } export interface AccessibilityDelegate { diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/loader/FlutterLoader.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/loader/FlutterLoader.ets index 89e7cf3264..2317af9f61 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/loader/FlutterLoader.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/loader/FlutterLoader.ets @@ -170,7 +170,6 @@ export default class FlutterLoader { if (this.initialized) { return; } - Log.d(TAG, "ensureInitializationComplete") if (shellArgs == null) { shellArgs = new Array(); } @@ -231,6 +230,7 @@ export default class FlutterLoader { costTime ); this.initialized = true; + Log.d(TAG, "ensureInitializationComplete") } findAppBundlePath(): string { @@ -274,6 +274,10 @@ export default class FlutterLoader { }) : new Array(); } + isInitialized(): boolean { + return this.initialized; + } + } class InitResult { diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/plugins/FlutterPlugin.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/plugins/FlutterPlugin.ets index 1b8ea40a05..92e08f8dd9 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/plugins/FlutterPlugin.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/plugins/FlutterPlugin.ets @@ -17,6 +17,7 @@ import common from '@ohos.app.ability.common'; import { BinaryMessenger } from '../../../plugin/common/BinaryMessenger'; import PlatformViewFactory from '../../../plugin/platform/PlatformViewFactory'; import PlatformViewRegistry from '../../../plugin/platform/PlatformViewRegistry'; +import { TextureRegistry } from '../../../view/TextureRegistry'; import FlutterEngine from '../FlutterEngine'; export interface FlutterPlugin { @@ -52,13 +53,15 @@ export class FlutterPluginBinding { private flutterEngine: FlutterEngine; private binaryMessenger: BinaryMessenger; private flutterAssets: FlutterAssets; + private textureRegistry: TextureRegistry; private platformViewRegistry: PlatformViewRegistry; - constructor(applicationContext: common.Context, flutterEngine: FlutterEngine, binaryMessenger: BinaryMessenger, flutterAssets: FlutterAssets, platformViewRegistry?: PlatformViewRegistry) { + constructor(applicationContext: common.Context, flutterEngine: FlutterEngine, binaryMessenger: BinaryMessenger, flutterAssets: FlutterAssets, textureRegistry: TextureRegistry, platformViewRegistry?: PlatformViewRegistry) { this.applicationContext = applicationContext; this.flutterEngine = flutterEngine; this.binaryMessenger = binaryMessenger; this.flutterAssets = flutterAssets; + this.textureRegistry = textureRegistry; this.platformViewRegistry = platformViewRegistry ?? new EmptyPlatformViewRegistry(); } @@ -78,6 +81,10 @@ export class FlutterPluginBinding { return this.flutterAssets; } + getTextureRegistry(): TextureRegistry { + return this.textureRegistry; + } + public getPlatformViewRegistry(): PlatformViewRegistry { return this.platformViewRegistry; } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/renderer/FlutterRenderer.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/renderer/FlutterRenderer.ets new file mode 100644 index 0000000000..e31ee486f5 --- /dev/null +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/renderer/FlutterRenderer.ets @@ -0,0 +1,138 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import image from '@ohos.multimedia.image'; +import { BusinessError } from '@ohos.base'; +import { SurfaceTextureEntry, TextureRegistry } from '../../../view/TextureRegistry'; +import { FlutterAbility } from '../../ohos/FlutterAbility'; +import FlutterNapi from '../FlutterNapi'; +import { SurfaceTextureWrapper } from './SurfaceTextureWrapper'; +import Log from '../../../util/Log'; + +const TAG = "FlutterRenderer" +export class FlutterRenderer implements TextureRegistry { + private nextTextureId: number = 0; + private flutterNapi: FlutterNapi; + + constructor(flutterNapi: FlutterNapi) { + this.flutterNapi = flutterNapi; + } + createSurfaceTexture(): SurfaceTextureEntry { + let receiver: image.ImageReceiver = this.getImageReceiver(); + return this.registerSurfaceTexture(receiver); + } + + getTextureId(): number { + this.nextTextureId = this.nextTextureId + 1; + Log.i(TAG, "getTextureId: ", this.nextTextureId ) + return this.nextTextureId; + } + + registerTexture(textureId: number): SurfaceTextureEntry { + let surfaceTextureRegistryEntry = new SurfaceTextureRegistryEntry(this.nextTextureId); + let surfaceId = this.flutterNapi.registerTexture(textureId); + Log.i(TAG, "registerTexture, surfaceId=" + surfaceId); + surfaceTextureRegistryEntry.setSurfaceId(surfaceId); + return surfaceTextureRegistryEntry; + } + + registerSurfaceTexture(receiver: image.ImageReceiver): SurfaceTextureEntry { + this.nextTextureId = this.nextTextureId + 1; + let surfaceTextureRegistryEntry = new SurfaceTextureRegistryEntry(this.nextTextureId); + surfaceTextureRegistryEntry.setImageReceiver(receiver); + this.registerImage(surfaceTextureRegistryEntry.getTextureId(), surfaceTextureRegistryEntry.textureWrapper()); + return surfaceTextureRegistryEntry; + } + + registerPixelMap(pixelMap: PixelMap): number { + let textureId = this.nextTextureId + 1; + this.flutterNapi.registerPixelMap(textureId, pixelMap); + return textureId; + } + + unregisterTexture(textureId: number): void { + this.flutterNapi.unregisterTexture(textureId); + } + onTrimMemory(level: number) { + throw new Error('Method not implemented.'); + } + + private getImageReceiver(): image.ImageReceiver { + let receiver: image.ImageReceiver = image.createImageReceiver(640, 480, 4, 8); + if (receiver !== undefined) { + console.info('[camera test] ImageReceiver is ok'); + } else { + console.info('[camera test] ImageReceiver is not ok'); + } + return receiver; + } + private registerImage(textureId: number, surfaceTextureWrapper: SurfaceTextureWrapper): void { + let receiver = surfaceTextureWrapper.getImageReceiver(); + receiver.on('imageArrival', () => { + receiver.readNextImage((err: BusinessError, nextImage: image.Image) => { + if (err || nextImage === undefined) { + return; + } + this.flutterNapi.initNativeImage(textureId, nextImage); + console.log("[camera test] format: " + nextImage.format); + nextImage.release((err : BusinessError) =>{ + if (err != undefined) { + console.log('Failed to release the image source instance.'); + } else { + console.log('Succeeded in releasing the image source instance.'); + } + }); + }) + }) + } +} + +export class SurfaceTextureRegistryEntry implements SurfaceTextureEntry { + private textureId: number = 0; + private surfaceId: number = 0; + private surfaceTextureWrapper: SurfaceTextureWrapper | null = null; + private released: boolean = false; + + constructor(id: number) { + this.textureId = id; + } + + getImageReceiver(): image.ImageReceiver { + return this.surfaceTextureWrapper!.getImageReceiver(); + } + + setImageReceiver(receiver: image.ImageReceiver): void { + this.surfaceTextureWrapper = new SurfaceTextureWrapper(receiver); + } + + getTextureId(): number { + return this.textureId; + } + + getSurfaceId(): number { + return this.surfaceId; + } + + setSurfaceId(surfaceId: number): void { + this.surfaceId = surfaceId; + } + + textureWrapper(): SurfaceTextureWrapper { + return this.surfaceTextureWrapper!; + } + release() { + throw new Error('Method not implemented.'); + } +} \ No newline at end of file diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/renderer/SurfaceTextureWrapper.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/renderer/SurfaceTextureWrapper.ets new file mode 100644 index 0000000000..b1da18061b --- /dev/null +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/renderer/SurfaceTextureWrapper.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import image from '@ohos.multimedia.image'; + +export class SurfaceTextureWrapper { + private receiver: image.ImageReceiver; + private released: boolean = false; + private attached: boolean = false; + + constructor(receiver: image.ImageReceiver) { + this.receiver = receiver; + } + + getImageReceiver(): image.ImageReceiver { + return this.receiver; + } +} \ No newline at end of file diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets index a5869a3cbf..7c63ef9873 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets @@ -208,6 +208,10 @@ export class FlutterAbility extends UIAbility implements Host { return this; } + getFlutterAbilityAndEntryDelegate(): FlutterAbilityAndEntryDelegate | null{ + return this.delegate ?? null; + } + shouldDispatchAppLifecycleState(): boolean { return true; } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityAndEntryDelegate.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityAndEntryDelegate.ets index df276bd2e5..baf4d2e3da 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityAndEntryDelegate.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityAndEntryDelegate.ets @@ -403,6 +403,10 @@ class FlutterAbilityAndEntryDelegate implements ExclusiveAppComponent return this.flutterEngine?.getFlutterNapi() ?? null } + getFlutterEngine(): FlutterEngine | null { + return this.flutterEngine ?? null; + } + detachFromFlutterEngine() { if (this.host?.shouldDestroyEngineWithHost()) { // The host owns the engine and should never have its engine taken by another exclusive diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/StandardMessageCodec.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/StandardMessageCodec.ets index df27a12328..8e740f95fd 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/StandardMessageCodec.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/StandardMessageCodec.ets @@ -339,7 +339,7 @@ export default class StandardMessageCodec implements MessageCodec { break; } default: - throw new Error("Message corrupted"); + throw new Error("Message corrupted, type=" + type); } return result; } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/TextureRegistry.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/TextureRegistry.ets index a37ab971b7..fa79eb238c 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/TextureRegistry.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/TextureRegistry.ets @@ -12,25 +12,33 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import image from '@ohos.multimedia.image'; export interface TextureRegistry { createSurfaceTexture(): SurfaceTextureEntry; - registerSurfaceTexture(): SurfaceTextureEntry; - + getTextureId(): number; + registerTexture(textureId: number): SurfaceTextureEntry; + registerSurfaceTexture(receiver: image.ImageReceiver): SurfaceTextureEntry; + registerPixelMap(pixelMap: PixelMap): number; + unregisterTexture(textureId: number): void; onTrimMemory(level: number) : void; } -interface SurfaceTextureEntry { - id(): number; +export interface SurfaceTextureEntry { + getTextureId(): number; + + getSurfaceId(): number; + + getImageReceiver(): image.ImageReceiver; release(): void; } -interface OnFrameConsumedListener { +export interface OnFrameConsumedListener { onFrameConsumed(): void; } -interface OnTrimMemoryListener { +export interface OnTrimMemoryListener { onTrimMemory(level: number) : void; } \ No newline at end of file -- Gitee From 775833ff9fcae8184e682b057411ad193557caf5 Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Mon, 26 Feb 2024 15:17:37 +0800 Subject: [PATCH 34/73] =?UTF-8?q?=E5=A4=96=E6=8E=A5=E7=BA=B9=E7=90=86engin?= =?UTF-8?q?e=E7=9B=B8=E5=85=B3=E6=94=B9=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- shell/platform/ohos/BUILD.gn | 3 + shell/platform/ohos/library_loader.cpp | 17 ++ .../ohos/napi/platform_view_ohos_napi.cpp | 79 +++++- .../ohos/napi/platform_view_ohos_napi.h | 15 ++ .../ohos/ohos_external_texture_gl.cpp | 228 ++++++++++++++++-- .../platform/ohos/ohos_external_texture_gl.h | 45 +++- shell/platform/ohos/ohos_unified_surface.cpp | 22 ++ shell/platform/ohos/ohos_unified_surface.h | 80 ++++++ shell/platform/ohos/platform_view_ohos.cpp | 96 ++++++++ shell/platform/ohos/platform_view_ohos.h | 30 +++ 10 files changed, 596 insertions(+), 19 deletions(-) create mode 100644 shell/platform/ohos/ohos_unified_surface.cpp create mode 100644 shell/platform/ohos/ohos_unified_surface.h diff --git a/shell/platform/ohos/BUILD.gn b/shell/platform/ohos/BUILD.gn index f60b29c347..7b888c0d6e 100644 --- a/shell/platform/ohos/BUILD.gn +++ b/shell/platform/ohos/BUILD.gn @@ -225,6 +225,9 @@ shared_library("flutter_shell_native") { ldflags += ["-lrawfile.z"] ldflags += ["-lEGL"] ldflags += ["-lGLESv3"] + # ldflags += ["-lGLESv2"] + ldflags += ["-limage_ndk.z"] + ldflags += ["-lnative_image"] ldflags += ["-lc++_shared"] ldflags += ["-lm"] diff --git a/shell/platform/ohos/library_loader.cpp b/shell/platform/ohos/library_loader.cpp index 6e38f769bc..f6c52a6aff 100644 --- a/shell/platform/ohos/library_loader.cpp +++ b/shell/platform/ohos/library_loader.cpp @@ -107,8 +107,25 @@ static napi_value Init(napi_env env, napi_value exports) { DECLARE_NAPI_FUNCTION( "nativeXComponentDetachFlutterEngine", flutter::PlatformViewOHOSNapi::nativeXComponentDetachFlutterEngine), + DECLARE_NAPI_FUNCTION( + "nativeInitNativeImage", + flutter::PlatformViewOHOSNapi::nativeInitNativeImage), + DECLARE_NAPI_FUNCTION( + "nativeRegisterTexture", + flutter::PlatformViewOHOSNapi::nativeRegisterTexture), + DECLARE_NAPI_FUNCTION( + "nativeUnregisterTexture", + flutter::PlatformViewOHOSNapi::nativeUnregisterTexture), + DECLARE_NAPI_FUNCTION( + "nativeMarkTextureFrameAvailable", + flutter::PlatformViewOHOSNapi::nativeMarkTextureFrameAvailable), + DECLARE_NAPI_FUNCTION( + "nativeRegisterPixelMap", + flutter::PlatformViewOHOSNapi::nativeRegisterPixelMap), }; + + FML_DLOG(INFO) << "Init NAPI size=" << sizeof(desc) / sizeof(desc[0]); napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); bool ret = flutter::XComponentAdapter::GetInstance()->Export(env, exports); if (!ret) { diff --git a/shell/platform/ohos/napi/platform_view_ohos_napi.cpp b/shell/platform/ohos/napi/platform_view_ohos_napi.cpp index 3572bee972..848ac957d7 100644 --- a/shell/platform/ohos/napi/platform_view_ohos_napi.cpp +++ b/shell/platform/ohos/napi/platform_view_ohos_napi.cpp @@ -27,6 +27,9 @@ #include "flutter/shell/platform/ohos/surface/ohos_native_window.h" #include "unicode/uchar.h" #include "flutter/shell/platform/ohos/ohos_xcomponent_adapter.h" +#include +#include +#include #define OHOS_SHELL_HOLDER (reinterpret_cast(shell_holder)) namespace flutter { @@ -303,7 +306,7 @@ void PlatformViewOHOSNapi::FlutterViewHandlePlatformMessage( FML_DLOG(ERROR) << "napi_create_string_utf8 err " << status; return; } - + FML_DLOG(INFO) << "FlutterViewHandlePlatformMessage mapData= " << mapData; if (mapData) { delete mapData; } @@ -1419,6 +1422,80 @@ napi_value PlatformViewOHOSNapi::nativeGetSystemLanguages( return nullptr; } +napi_value PlatformViewOHOSNapi::nativeInitNativeImage( + napi_env env, + napi_callback_info info) { + FML_DLOG(INFO)<<"PlatformViewOHOSNapi::nativeInitNativeImage"; + size_t argc = 3; + napi_value args[3] = {nullptr}; + int64_t shell_holder, textureId; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, nullptr, nullptr)); + NAPI_CALL(env, napi_get_value_int64(env, args[0], &shell_holder)); + NAPI_CALL(env, napi_get_value_int64(env, args[1], &textureId)); + ImageNative *imageNative = OH_Image_InitImageNative(env, args[2]); + // std::unique_ptr uImage; + OHOS_SHELL_HOLDER->GetPlatformView()->RegisterExternalTextureByImage(textureId, imageNative); + return nullptr; +} + +napi_value PlatformViewOHOSNapi::nativeRegisterTexture(napi_env env, + napi_callback_info info) +{ + FML_DLOG(INFO)<<"PlatformViewOHOSNapi::nativeRegisterTexture"; + size_t argc = 2; + napi_value args[2] = {nullptr}; + int64_t shell_holder, textureId; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, nullptr, nullptr)); + NAPI_CALL(env, napi_get_value_int64(env, args[0], &shell_holder)); + NAPI_CALL(env, napi_get_value_int64(env, args[1], &textureId)); + int64_t surfaceId = OHOS_SHELL_HOLDER->GetPlatformView()->RegisterExternalTexture(textureId); + napi_value res; + napi_create_int64(env, surfaceId, &res); + return res; +} + +napi_value PlatformViewOHOSNapi::nativeUnregisterTexture( + napi_env env, napi_callback_info info) +{ + FML_DLOG(INFO)<<"PlatformViewOHOSNapi::nativeUnregisterTexture"; + size_t argc = 2; + napi_value args[2] = {nullptr}; + int64_t shell_holder, textureId; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, nullptr, nullptr)); + NAPI_CALL(env, napi_get_value_int64(env, args[0], &shell_holder)); + NAPI_CALL(env, napi_get_value_int64(env, args[1], &textureId)); + OHOS_SHELL_HOLDER->GetPlatformView()->UnRegisterExternalTexture(textureId); + return nullptr; +} + +napi_value PlatformViewOHOSNapi::nativeMarkTextureFrameAvailable( + napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value args[2] = {nullptr}; + int64_t shell_holder, textureId; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, nullptr, nullptr)); + NAPI_CALL(env, napi_get_value_int64(env, args[0], &shell_holder)); + NAPI_CALL(env, napi_get_value_int64(env, args[1], &textureId)); + OHOS_SHELL_HOLDER->GetPlatformView()->MarkTextureFrameAvailable(textureId); + return nullptr; +} + +napi_value PlatformViewOHOSNapi::nativeRegisterPixelMap(napi_env env, + napi_callback_info info) +{ + FML_DLOG(INFO)<<"PlatformViewOHOSNapi::nativeRegisterPixelMap"; + size_t argc = 3; + napi_value args[3] = {nullptr}; + int64_t shell_holder, textureId; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, nullptr, nullptr)); + NAPI_CALL(env, napi_get_value_int64(env, args[0], &shell_holder)); + NAPI_CALL(env, napi_get_value_int64(env, args[1], &textureId)); + NativePixelMap *nativePixelMap = OH_PixelMap_InitNativePixelMap(env, args[2]); + OHOS_SHELL_HOLDER->GetPlatformView()->RegisterExternalTextureByPixelMap(textureId, nativePixelMap); + return nullptr; +} + void PlatformViewOHOSNapi::SurfaceCreated(int64_t shell_holder, void* window) { auto native_window = fml::MakeRefCounted( static_cast(window)); diff --git a/shell/platform/ohos/napi/platform_view_ohos_napi.h b/shell/platform/ohos/napi/platform_view_ohos_napi.h index 1e83a43017..8339308b00 100644 --- a/shell/platform/ohos/napi/platform_view_ohos_napi.h +++ b/shell/platform/ohos/napi/platform_view_ohos_napi.h @@ -143,6 +143,21 @@ class PlatformViewOHOSNapi { napi_env env, napi_callback_info info); // 应用下发系统语言设置 + static napi_value nativeInitNativeImage(napi_env env, + napi_callback_info info); + + static napi_value nativeUnregisterTexture(napi_env env, + napi_callback_info info); + + static napi_value nativeMarkTextureFrameAvailable(napi_env env, + napi_callback_info info); + + static napi_value nativeRegisterPixelMap(napi_env env, + napi_callback_info info); + + static napi_value nativeRegisterTexture(napi_env env, + napi_callback_info info); + // Surface相关,XComponent调用 static void SurfaceCreated(int64_t shell_holder, void* window); static void SurfaceChanged(int64_t shell_holder, diff --git a/shell/platform/ohos/ohos_external_texture_gl.cpp b/shell/platform/ohos/ohos_external_texture_gl.cpp index f2ffccbaa8..7533b43364 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.cpp +++ b/shell/platform/ohos/ohos_external_texture_gl.cpp @@ -14,7 +14,6 @@ */ #include "ohos_external_texture_gl.h" -#include #include @@ -25,13 +24,33 @@ #include "third_party/skia/include/gpu/GrBackendSurface.h" #include "third_party/skia/include/gpu/GrDirectContext.h" +#include +#include + +#define EGL_PLATFORM_OHOS_KHR 0x34E0 + namespace flutter { +using GetPlatformDisplayExt = PFNEGLGETPLATFORMDISPLAYEXTPROC; +constexpr char CHARACTER_WHITESPACE = ' '; +constexpr const char *CHARACTER_STRING_WHITESPACE = " "; +constexpr const char *EGL_EXT_PLATFORM_WAYLAND = "EGL_EXT_platform_wayland"; +constexpr const char *EGL_KHR_PLATFORM_WAYLAND = "EGL_KHR_platform_wayland"; +constexpr const char *EGL_GET_PLATFORM_DISPLAY_EXT = "eglGetPlatformDisplayEXT"; -OHOSExternalTextureGL::OHOSExternalTextureGL(int id) - : Texture(id), transform(SkMatrix::I()) {} +OHOSExternalTextureGL::OHOSExternalTextureGL(int64_t id, const std::shared_ptr& ohos_surface) + : Texture(id), ohos_surface_(std::move(ohos_surface)), transform(SkMatrix::I()) { + nativeImage_ = nullptr; + nativeWindow_ = nullptr; + eglContext_ = EGL_NO_CONTEXT; + eglDisplay_ = EGL_NO_DISPLAY; + buffer_ = nullptr; + pixelMap_ = nullptr; + lastImage_ = nullptr; +} OHOSExternalTextureGL::~OHOSExternalTextureGL() { if (state_ == AttachmentState::attached) { + glDeleteTextures(1, &texture_name_); } } @@ -40,17 +59,46 @@ void OHOSExternalTextureGL::Paint(PaintContext& context, bool freeze, const SkSamplingOptions& sampling) { if (state_ == AttachmentState::detached) { + FML_DLOG(ERROR) << "OHOSExternalTextureGL::Paint"; return; } if (state_ == AttachmentState::uninitialized) { - Attach(static_cast(texture_name_)); - state_ = AttachmentState::attached; + OHOSSurface* ohos_surface_ptr = ohos_surface_.get(); + OhosSurfaceGLSkia* ohosSurfaceGLSkia_ = (OhosSurfaceGLSkia*)ohos_surface_ptr; + auto result = ohosSurfaceGLSkia_->GLContextMakeCurrent(); + if (result->GetResult()) { + FML_DLOG(INFO)<<"ResourceContextMakeCurrent successed"; + glGenTextures(1, &texture_name_); + FML_DLOG(INFO) << "OHOSExternalTextureGL::Paint, glGenTextures texture_name_=" << texture_name_; + if (nativeImage_ == nullptr) { + nativeImage_ = OH_NativeImage_Create(texture_name_, GL_TEXTURE_EXTERNAL_OES); + if (nativeImage_ == nullptr) { + FML_DLOG(ERROR) << "Error with OH_NativeImage_Create"; + return; + } + nativeWindow_ = OH_NativeImage_AcquireNativeWindow(nativeImage_); + if (nativeWindow_ == nullptr) { + FML_DLOG(ERROR) << "Error with OH_NativeImage_AcquireNativeWindow"; + return; + } + } + + int32_t ret = OH_NativeImage_AttachContext(nativeImage_, texture_name_); + if(ret != 0) { + FML_DLOG(FATAL)<<"OHOSExternalTextureGL OH_NativeImage_AttachContext err code:"<< ret; + } + state_ = AttachmentState::attached; + } else { + FML_DLOG(FATAL)<<"ResourceContextMakeCurrent failed"; + } } if (!freeze && new_frame_ready_) { Update(); new_frame_ready_ = false; } - GrGLTextureInfo textureInfo = {0, texture_name_, GL_RGBA8_OES}; + + GrGLTextureInfo textureInfo = {GL_TEXTURE_EXTERNAL_OES, texture_name_, + GL_RGBA8_OES}; GrBackendTexture backendTexture(1, 1, GrMipMapped::kNo, textureInfo); sk_sp image = SkImage::MakeFromTexture( context.gr_context, backendTexture, kTopLeft_GrSurfaceOrigin, @@ -61,8 +109,8 @@ void OHOSExternalTextureGL::Paint(PaintContext& context, // The incoming texture is vertically flipped, so we flip it // back. OpenGL's coordinate system has Positive Y equivalent to up, while // Skia's coordinate system has Negative Y equvalent to up. - context.canvas->translate(bounds.x(), bounds.y() + bounds.height()); - context.canvas->scale(bounds.width(), -bounds.height()); + context.canvas->translate(bounds.x(), bounds.y()); + context.canvas->scale(bounds.width(), bounds.height()); if (!transform.isIdentity()) { sk_sp shader = image->makeShader( @@ -81,41 +129,193 @@ void OHOSExternalTextureGL::Paint(PaintContext& context, } void OHOSExternalTextureGL::OnGrContextCreated() { + FML_DLOG(INFO)<<" OHOSExternalTextureGL::OnGrContextCreated"; state_ = AttachmentState::uninitialized; } void OHOSExternalTextureGL::OnGrContextDestroyed() { + FML_DLOG(INFO)<<" OHOSExternalTextureGL::OnGrContextDestroyed"; if (state_ == AttachmentState::attached) { Detach(); + glDeleteTextures(1, &texture_name_); + OH_NativeImage_Destroy(&nativeImage_); } state_ = AttachmentState::detached; } void OHOSExternalTextureGL::MarkNewFrameAvailable() { + FML_DLOG(INFO)<<" OHOSExternalTextureGL::MarkNewFrameAvailable"; new_frame_ready_ = true; } void OHOSExternalTextureGL::OnTextureUnregistered() { - // do nothing -} - -void OHOSExternalTextureGL::Attach(int textureName) { + FML_DLOG(INFO)<<" OHOSExternalTextureGL::OnTextureUnregistered"; // do nothing } void OHOSExternalTextureGL::Update() { + ProducePixelMapToNativeImage(); + int32_t ret = OH_NativeImage_UpdateSurfaceImage(nativeImage_); + if (ret != 0) { + FML_DLOG(FATAL)<<"OHOSExternalTextureGL OH_NativeImage_UpdateSurfaceImage err code:"<< ret; + } UpdateTransform(); } void OHOSExternalTextureGL::Detach() { - // do nothing + OH_NativeImage_DetachContext(nativeImage_); + OH_NativeWindow_DestroyNativeWindow(nativeWindow_); } void OHOSExternalTextureGL::UpdateTransform() { + float m[16] = { 0.0f }; + int32_t ret = OH_NativeImage_GetTransformMatrix(nativeImage_, m); + if(ret != 0) { + FML_DLOG(FATAL)<<"OHOSExternalTextureGL OH_NativeImage_GetTransformMatrix err code:"<< ret; + } + // transform ohos 4x4 matrix to skia 3x3 matrix + FML_DLOG(INFO)<<"OHOSExternalTextureGL::UpdateTransform "<virAddr, handle->size, PROT_READ | PROT_WRITE, MAP_SHARED, handle->fd, 0); + if (mappedAddr == MAP_FAILED) { + FML_DLOG(FATAL)<<"OHOSExternalTextureGL mmap failed"; + return; + } + + void *pixelAddr = nullptr; + ret = OH_PixelMap_AccessPixels(pixelMap_, &pixelAddr); + if (ret != IMAGE_RESULT_SUCCESS) { + FML_DLOG(FATAL)<<"OHOSExternalTextureGL OH_PixelMap_AccessPixels err:"<< ret; + return; + } + + uint32_t *value = static_cast(pixelAddr); + uint32_t *pixel = static_cast(mappedAddr); + uint32_t rowDataSize = 256; // DMA内存会自动补齐,分配内存时是 256 的整数倍 + while (rowDataSize < pixelMapInfo.rowSize) { + rowDataSize += 256; + } + + FML_DLOG(INFO) << "OHOSExternalTextureGL pixelMapInfo w:" << pixelMapInfo.width << " h:" << pixelMapInfo.height; + FML_DLOG(INFO) << "OHOSExternalTextureGL pixelMapInfo rowSize:" << pixelMapInfo.rowSize << " format:" << pixelMapInfo.pixelFormat; + FML_DLOG(INFO) << "OHOSExternalTextureGL pixelMapInfo rowDataSize:" << rowDataSize; + + // 复制图片纹理数据到内存中,需要处理DMA内存补齐相关的逻辑 + for (uint32_t i = 0; i < pixelMapInfo.height; i++) { + memcpy(pixel, value, rowDataSize); + pixel += rowDataSize / 4; + value += pixelMapInfo.width; + } + + OH_PixelMap_UnAccessPixels(pixelMap_); + //munmap after use + ret = munmap(mappedAddr, handle->size); + if (ret == -1) { + FML_DLOG(FATAL)<<"OHOSExternalTextureGL munmap failed"; + return; + } + Region region{nullptr, 0}; + ret = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow_, buffer_, fenceFd, region); + if(ret != 0) { + FML_DLOG(FATAL)<<"OHOSExternalTextureGL OH_NativeWindow_NativeWindowFlushBuffer err:"<< ret; + } +} + +EGLDisplay OHOSExternalTextureGL::GetPlatformEglDisplay(EGLenum platform, void *native_display, const EGLint *attrib_list) +{ + GetPlatformDisplayExt eglGetPlatformDisplayExt = NULL; + + if (!eglGetPlatformDisplayExt) { + const char* extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS); + if (extensions && + (CheckEglExtension(extensions, EGL_EXT_PLATFORM_WAYLAND) || + CheckEglExtension(extensions, EGL_KHR_PLATFORM_WAYLAND))) { + eglGetPlatformDisplayExt = (GetPlatformDisplayExt)eglGetProcAddress(EGL_GET_PLATFORM_DISPLAY_EXT); + } + } + + if (eglGetPlatformDisplayExt) { + return eglGetPlatformDisplayExt(platform, native_display, attrib_list); + } + + return eglGetDisplay((EGLNativeDisplayType)native_display); +} + +bool OHOSExternalTextureGL::CheckEglExtension(const char *extensions, const char *extension) +{ + size_t extlen = strlen(extension); + const char *end = extensions + strlen(extensions); + while (extensions < end) { + size_t n = 0; + if (*extensions == CHARACTER_WHITESPACE) { + extensions++; + continue; + } + n = strcspn(extensions, CHARACTER_STRING_WHITESPACE); + if (n == extlen && strncmp(extension, extensions, n) == 0) { + return true; + } + extensions += n; + } + return false; +} + +void OHOSExternalTextureGL::DispatchPixelMap(NativePixelMap* pixelMap) +{ + if(pixelMap != nullptr) { + pixelMap_ = pixelMap; + } +} + } // namespace flutter \ No newline at end of file diff --git a/shell/platform/ohos/ohos_external_texture_gl.h b/shell/platform/ohos/ohos_external_texture_gl.h index aa08880048..0e900e60a4 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.h +++ b/shell/platform/ohos/ohos_external_texture_gl.h @@ -15,20 +15,32 @@ #ifndef OHOS_EXTERNAL_TEXTURE_GL_H #define OHOS_EXTERNAL_TEXTURE_GL_H -#include + +#include +#include +#include #include "flutter/common/graphics/texture.h" +#include "flutter/shell/platform/ohos/surface/ohos_surface.h" +#include "flutter/shell/platform/ohos/ohos_surface_gl_skia.h" #include "napi/platform_view_ohos_napi.h" +#include +#include +#include +#include +#include // maybe now unused namespace flutter { class OHOSExternalTextureGL : public flutter::Texture { public: - explicit OHOSExternalTextureGL(int id); + explicit OHOSExternalTextureGL(int64_t id, const std::shared_ptr& ohos_surface); ~OHOSExternalTextureGL() override; + OH_NativeImage *nativeImage_; + void Paint(PaintContext& context, const SkRect& bounds, bool freeze, @@ -42,15 +54,23 @@ class OHOSExternalTextureGL : public flutter::Texture { void OnTextureUnregistered() override; - private: - void Attach(int textureName); + void DispatchImage(ImageNative* image); + + void DispatchPixelMap(NativePixelMap* pixelMap); + private: void Update(); void Detach(); void UpdateTransform(); + EGLDisplay GetPlatformEglDisplay(EGLenum platform, void *native_display, const EGLint *attrib_list); + + bool CheckEglExtension(const char *extensions, const char *extension); + + void ProducePixelMapToNativeImage(); + enum class AttachmentState { uninitialized, attached, detached }; AttachmentState state_ = AttachmentState::uninitialized; @@ -59,8 +79,25 @@ class OHOSExternalTextureGL : public flutter::Texture { GLuint texture_name_ = 0; + std::shared_ptr ohos_surface_; + SkMatrix transform; + OHNativeWindow *nativeWindow_; + + OHNativeWindowBuffer *buffer_; + + NativePixelMap* pixelMap_; + + ImageNative* lastImage_; + + OhosPixelMapInfos pixelMapInfo; + + int fenceFd = -1; + + EGLContext eglContext_; + EGLDisplay eglDisplay_; + FML_DISALLOW_COPY_AND_ASSIGN(OHOSExternalTextureGL); }; } // namespace flutter diff --git a/shell/platform/ohos/ohos_unified_surface.cpp b/shell/platform/ohos/ohos_unified_surface.cpp new file mode 100644 index 0000000000..73c3a0c954 --- /dev/null +++ b/shell/platform/ohos/ohos_unified_surface.cpp @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "flutter/shell/platform/ohos/ohos_unified_surface.h" +namespace flutter { + +OHOSUnifiedSurface::OHOSUnifiedSurface() {} + + +} // namespace flutter \ No newline at end of file diff --git a/shell/platform/ohos/ohos_unified_surface.h b/shell/platform/ohos/ohos_unified_surface.h new file mode 100644 index 0000000000..49aa35a3d6 --- /dev/null +++ b/shell/platform/ohos/ohos_unified_surface.h @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_UNIFIED_SURFACE_H +#define OHOS_UNIFIED_SURFACE_H + +#include +#include "flutter/flow/surface.h" +#include "flutter/shell/platform/ohos/context/ohos_context.h" +#include "flutter/shell/platform/ohos/surface/ohos_native_window.h" +#include "flutter/shell/platform/ohos/surface/ohos_surface.h" +#include "flutter/shell/platform/ohos/ohos_surface_gl_skia.h" +#include "third_party/skia/include/core/SkSize.h" + +namespace flutter { + +class OHOSUnifiedSurface : public GPUSurfaceGLDelegate, + public OHOSSurface { + public: + ~OHOSUnifiedSurface() {} + bool IsValid() {} + void TeardownOnScreenContext() {} + + bool OnScreenSurfaceResize(const SkISize& size) {} + + bool ResourceContextMakeCurrent() {} + + bool ResourceContextClearCurrent() {} + + bool SetNativeWindow(fml::RefPtr window) {} + + std::unique_ptr CreateSnapshotSurface() + + std::unique_ptr CreateGPUSurface( + GrDirectContext* gr_context = nullptr) {} + + std::shared_ptr GetImpellerContext() {} + + std::unique_ptr GLContextMakeCurrent() {} + + bool GLContextClearCurrent() {} + + void GLContextSetDamageRegion(const std::optional& region) {} + + bool GLContextPresent(const GLPresentInfo& present_info) {} + + GLFBOInfo GLContextFBO(GLFrameInfo frame_info) {} + + bool GLContextFBOResetAfterPresent() {} + + SurfaceFrame::FramebufferInfo GLContextFramebufferInfo() {} + + SkMatrix GLContextSurfaceTransformation() {} + + sk_sp GetGLInterface() {} + + static sk_sp GetDefaultPlatformGLInterface() {} + + using GLProcResolver = + std::function; + + GLProcResolver GetGLProcResolver() {} + + bool AllowsDrawingWhenGpuDisabled() {} +}; +} // namespace flutter + +#endif \ No newline at end of file diff --git a/shell/platform/ohos/platform_view_ohos.cpp b/shell/platform/ohos/platform_view_ohos.cpp index b0a382254a..19f45611cf 100644 --- a/shell/platform/ohos/platform_view_ohos.cpp +++ b/shell/platform/ohos/platform_view_ohos.cpp @@ -25,6 +25,9 @@ #include "napi_common.h" #include "ohos_context_gl_impeller.h" #include "ohos_surface_gl_impeller.h" +#include "ohos_external_texture_gl.h" + +#include namespace flutter { @@ -387,4 +390,97 @@ void PlatformViewOHOS::FireFirstFrameCallback() { napi_facade_->FlutterViewOnFirstFrame(); } +void PlatformViewOHOS::RegisterExternalTextureByImage( + int64_t texture_id, + ImageNative* image) { + if(ohos_context_->RenderingApi() == OHOSRenderingAPI::kOpenGLES) { + auto iter = external_texture_gl_.find(texture_id); + if(iter != external_texture_gl_.end()) { + iter->second->DispatchImage(image); + } else { + std::shared_ptr ohos_external_gl = std::make_shared(texture_id, ohos_surface_); + external_texture_gl_[texture_id] = ohos_external_gl; + RegisterTexture(ohos_external_gl); + ohos_external_gl->DispatchImage(image); + } + } +} + +uint64_t PlatformViewOHOS::RegisterExternalTexture(int64_t texture_id) { + uint64_t surface_id = 0; + int ret = -1; + if (ohos_context_->RenderingApi() == OHOSRenderingAPI::kOpenGLES) { + std::shared_ptr ohos_external_gl = std::make_shared(texture_id, ohos_surface_); + ohos_external_gl->nativeImage_ = OH_NativeImage_Create(texture_id, GL_TEXTURE_EXTERNAL_OES); + if (ohos_external_gl->nativeImage_ == nullptr) { + FML_DLOG(ERROR) << "Error with OH_NativeImage_Create"; + return surface_id; + } + void* contextData = new OhosImageFrameData(this, texture_id); + nativeImageFrameAvailableListener_.context = contextData; + nativeImageFrameAvailableListener_.onFrameAvailable = &PlatformViewOHOS::OnNativeImageFrameAvailable; + ret = OH_NativeImage_SetOnFrameAvailableListener(ohos_external_gl->nativeImage_, nativeImageFrameAvailableListener_); + if (ret != 0) { + FML_DLOG(ERROR) << "Error with OH_NativeImage_SetOnFrameAvailableListener"; + return surface_id; + } + ret = OH_NativeImage_GetSurfaceId(ohos_external_gl->nativeImage_, &surface_id); + if (ret != 0) { + FML_DLOG(ERROR) << "Error with OH_NativeImage_GetSurfaceId"; + return surface_id; + } + RegisterTexture(ohos_external_gl); + } + return surface_id; +} + +void PlatformViewOHOS::OnNativeImageFrameAvailable(void *data) { + auto frameData = reinterpret_cast(data); + if (frameData == nullptr || frameData->context_ == nullptr) { + FML_DLOG(ERROR) << "OnNativeImageFrameAvailable, frameData or context_ is null."; + return; + } + std::shared_ptr ohos_surface = frameData->context_->ohos_surface_; + const TaskRunners task_runners = frameData->context_->task_runners_;; + if (ohos_surface) { + fml::AutoResetWaitableEvent latch; + fml::TaskRunner::RunNowOrPostTask( + task_runners.GetPlatformTaskRunner(), + [&latch, surface = ohos_surface.get(), frameData]() { + frameData->context_->MarkTextureFrameAvailable(frameData->texture_id_); + latch.Signal(); + }); + latch.Wait(); + } +} + +void PlatformViewOHOS::UnRegisterExternalTexture(int64_t texture_id) +{ + external_texture_gl_.erase(texture_id); + UnregisterTexture(texture_id); +} + +void PlatformViewOHOS::RegisterExternalTextureByPixelMap(int64_t texture_id, NativePixelMap* pixelMap) +{ + if (ohos_context_->RenderingApi() == OHOSRenderingAPI::kOpenGLES) { + auto iter = external_texture_gl_.find(texture_id); + if (iter != external_texture_gl_.end()) { + iter->second->DispatchPixelMap(pixelMap); + } else { + std::shared_ptr ohos_external_gl = std::make_shared(texture_id, ohos_surface_); + external_texture_gl_[texture_id] = ohos_external_gl; + RegisterTexture(ohos_external_gl); + ohos_external_gl->DispatchPixelMap(pixelMap); + } + MarkTextureFrameAvailable(texture_id); + } +} + +OhosImageFrameData::OhosImageFrameData( + PlatformViewOHOS* context, + int64_t texture_id) + : context_(context), texture_id_(texture_id) {} + +OhosImageFrameData::~OhosImageFrameData() = default; + } // namespace flutter diff --git a/shell/platform/ohos/platform_view_ohos.h b/shell/platform/ohos/platform_view_ohos.h index a1b863ed34..387022cc08 100644 --- a/shell/platform/ohos/platform_view_ohos.h +++ b/shell/platform/ohos/platform_view_ohos.h @@ -31,6 +31,9 @@ #include "flutter/shell/platform/ohos/surface/ohos_snapshot_surface_producer.h" #include "flutter/shell/platform/ohos/surface/ohos_surface.h" #include "flutter/shell/platform/ohos/vsync_waiter_ohos.h" +#include +#include "ohos_external_texture_gl.h" +#include namespace flutter { @@ -84,6 +87,15 @@ class PlatformViewOHOS final : public PlatformView { int action, void* actionData, int actionDataLenth); + void RegisterExternalTextureByImage( + int64_t texture_id, + ImageNative* image); + + uint64_t RegisterExternalTexture(int64_t texture_id); + + void RegisterExternalTextureByPixelMap(int64_t texture_id, NativePixelMap* pixelMap); + + void UnRegisterExternalTexture(int64_t texture_id); // |PlatformView| void LoadDartDeferredLibrary( @@ -117,6 +129,7 @@ class PlatformViewOHOS final : public PlatformView { std::shared_ptr platform_message_handler_; std::shared_ptr surface_factory_; + std::map> external_texture_gl_; // |PlatformView| void UpdateSemantics( @@ -164,6 +177,23 @@ class PlatformViewOHOS final : public PlatformView { void FireFirstFrameCallback(); FML_DISALLOW_COPY_AND_ASSIGN(PlatformViewOHOS); + + OH_OnFrameAvailableListener nativeImageFrameAvailableListener_{}; + + static void OnNativeImageFrameAvailable(void *data); +}; + +class OhosImageFrameData { + public: + OhosImageFrameData(PlatformViewOHOS* context, + int64_t texture_id); + + ~OhosImageFrameData(); + + PlatformViewOHOS* context_; + + int64_t texture_id_; }; + } // namespace flutter #endif -- Gitee From df2e5f20b8ad8cfb7c8235b7595ef908881cf83d Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Mon, 26 Feb 2024 20:23:45 +0800 Subject: [PATCH 35/73] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=97=A8=E7=A6=81?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E7=9A=84=E4=BB=A3=E7=A0=81=E6=A0=BC=E5=BC=8F?= =?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: hezhengyi --- shell/platform/ohos/library_loader.cpp | 2 +- .../ohos/napi/platform_view_ohos_napi.cpp | 47 +++-- .../ohos/napi/platform_view_ohos_napi.h | 26 ++- .../ohos/ohos_external_texture_gl.cpp | 191 ++++++++++-------- .../platform/ohos/ohos_external_texture_gl.h | 17 +- shell/platform/ohos/ohos_unified_surface.h | 2 +- shell/platform/ohos/platform_view_ohos.cpp | 32 +-- shell/platform/ohos/platform_view_ohos.h | 9 +- 8 files changed, 185 insertions(+), 141 deletions(-) diff --git a/shell/platform/ohos/library_loader.cpp b/shell/platform/ohos/library_loader.cpp index f6c52a6aff..415bf46a65 100644 --- a/shell/platform/ohos/library_loader.cpp +++ b/shell/platform/ohos/library_loader.cpp @@ -112,7 +112,7 @@ static napi_value Init(napi_env env, napi_value exports) { flutter::PlatformViewOHOSNapi::nativeInitNativeImage), DECLARE_NAPI_FUNCTION( "nativeRegisterTexture", - flutter::PlatformViewOHOSNapi::nativeRegisterTexture), + flutter::PlatformViewOHOSNapi::nativeRegisterTexture), DECLARE_NAPI_FUNCTION( "nativeUnregisterTexture", flutter::PlatformViewOHOSNapi::nativeUnregisterTexture), diff --git a/shell/platform/ohos/napi/platform_view_ohos_napi.cpp b/shell/platform/ohos/napi/platform_view_ohos_napi.cpp index 848ac957d7..6c927d8bc2 100644 --- a/shell/platform/ohos/napi/platform_view_ohos_napi.cpp +++ b/shell/platform/ohos/napi/platform_view_ohos_napi.cpp @@ -16,20 +16,21 @@ #include "platform_view_ohos_napi.h" #include #include +#include +#include +#include #include #include #include -#include "../types.h" + #include "flutter/fml/make_copyable.h" #include "flutter/fml/platform/ohos/napi_util.h" #include "flutter/shell/platform/ohos/ohos_main.h" #include "flutter/shell/platform/ohos/ohos_shell_holder.h" #include "flutter/shell/platform/ohos/surface/ohos_native_window.h" +#include "flutter/shell/platform/ohos/types.h" #include "unicode/uchar.h" #include "flutter/shell/platform/ohos/ohos_xcomponent_adapter.h" -#include -#include -#include #define OHOS_SHELL_HOLDER (reinterpret_cast(shell_holder)) namespace flutter { @@ -1424,11 +1425,13 @@ napi_value PlatformViewOHOSNapi::nativeGetSystemLanguages( napi_value PlatformViewOHOSNapi::nativeInitNativeImage( napi_env env, - napi_callback_info info) { + napi_callback_info info) +{ FML_DLOG(INFO)<<"PlatformViewOHOSNapi::nativeInitNativeImage"; size_t argc = 3; napi_value args[3] = {nullptr}; - int64_t shell_holder, textureId; + int64_t shell_holder; + int64_t textureId; NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, nullptr, nullptr)); NAPI_CALL(env, napi_get_value_int64(env, args[0], &shell_holder)); NAPI_CALL(env, napi_get_value_int64(env, args[1], &textureId)); @@ -1438,13 +1441,14 @@ napi_value PlatformViewOHOSNapi::nativeInitNativeImage( return nullptr; } -napi_value PlatformViewOHOSNapi::nativeRegisterTexture(napi_env env, - napi_callback_info info) -{ +napi_value PlatformViewOHOSNapi::nativeRegisterTexture( + napi_env env, + napi_callback_info info) { FML_DLOG(INFO)<<"PlatformViewOHOSNapi::nativeRegisterTexture"; size_t argc = 2; napi_value args[2] = {nullptr}; - int64_t shell_holder, textureId; + int64_t shell_holder; + int64_t textureId; NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, nullptr, nullptr)); NAPI_CALL(env, napi_get_value_int64(env, args[0], &shell_holder)); NAPI_CALL(env, napi_get_value_int64(env, args[1], &textureId)); @@ -1455,12 +1459,13 @@ napi_value PlatformViewOHOSNapi::nativeRegisterTexture(napi_env env, } napi_value PlatformViewOHOSNapi::nativeUnregisterTexture( - napi_env env, napi_callback_info info) -{ + napi_env env, + napi_callback_info info) { FML_DLOG(INFO)<<"PlatformViewOHOSNapi::nativeUnregisterTexture"; size_t argc = 2; napi_value args[2] = {nullptr}; - int64_t shell_holder, textureId; + int64_t shell_holder; + int64_t textureId; NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, nullptr, nullptr)); NAPI_CALL(env, napi_get_value_int64(env, args[0], &shell_holder)); NAPI_CALL(env, napi_get_value_int64(env, args[1], &textureId)); @@ -1469,11 +1474,12 @@ napi_value PlatformViewOHOSNapi::nativeUnregisterTexture( } napi_value PlatformViewOHOSNapi::nativeMarkTextureFrameAvailable( - napi_env env, napi_callback_info info) -{ + napi_env env, + napi_callback_info info) { size_t argc = 2; napi_value args[2] = {nullptr}; - int64_t shell_holder, textureId; + int64_t shell_holder; + int64_t textureId; NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, nullptr, nullptr)); NAPI_CALL(env, napi_get_value_int64(env, args[0], &shell_holder)); NAPI_CALL(env, napi_get_value_int64(env, args[1], &textureId)); @@ -1481,13 +1487,14 @@ napi_value PlatformViewOHOSNapi::nativeMarkTextureFrameAvailable( return nullptr; } -napi_value PlatformViewOHOSNapi::nativeRegisterPixelMap(napi_env env, - napi_callback_info info) -{ +napi_value PlatformViewOHOSNapi::nativeRegisterPixelMap( + napi_env env, + napi_callback_info info) { FML_DLOG(INFO)<<"PlatformViewOHOSNapi::nativeRegisterPixelMap"; size_t argc = 3; napi_value args[3] = {nullptr}; - int64_t shell_holder, textureId; + int64_t shell_holder; + int64_t textureId; NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, nullptr, nullptr)); NAPI_CALL(env, napi_get_value_int64(env, args[0], &shell_holder)); NAPI_CALL(env, napi_get_value_int64(env, args[1], &textureId)); diff --git a/shell/platform/ohos/napi/platform_view_ohos_napi.h b/shell/platform/ohos/napi/platform_view_ohos_napi.h index 8339308b00..f998fbf553 100644 --- a/shell/platform/ohos/napi/platform_view_ohos_napi.h +++ b/shell/platform/ohos/napi/platform_view_ohos_napi.h @@ -16,7 +16,6 @@ #ifndef PLATFORM_VIEW_OHOS_NAPI_H #define PLATFORM_VIEW_OHOS_NAPI_H #include -#include "../napi_common.h" #include "flutter/assets/directory_asset_bundle.h" #include "flutter/common/settings.h" #include "flutter/fml/file.h" @@ -27,6 +26,7 @@ #include "flutter/lib/ui/plugins/callback_cache.h" #include "flutter/runtime/dart_service_isolate.h" #include "flutter/shell/common/run_configuration.h" +#include "flutter/shell/platform/ohos/napi_common.h" #include "napi/native_api.h" // class for all c++ to call js function namespace flutter { @@ -143,26 +143,34 @@ class PlatformViewOHOSNapi { napi_env env, napi_callback_info info); // 应用下发系统语言设置 - static napi_value nativeInitNativeImage(napi_env env, + static napi_value nativeInitNativeImage( + napi_env env, napi_callback_info info); - static napi_value nativeUnregisterTexture(napi_env env, + static napi_value nativeUnregisterTexture( + napi_env env, napi_callback_info info); - static napi_value nativeMarkTextureFrameAvailable(napi_env env, + static napi_value nativeMarkTextureFrameAvailable( + napi_env env, napi_callback_info info); - static napi_value nativeRegisterPixelMap(napi_env env, + static napi_value nativeRegisterPixelMap( + napi_env env, napi_callback_info info); - static napi_value nativeRegisterTexture(napi_env env, + static napi_value nativeRegisterTexture( + napi_env env, napi_callback_info info); // Surface相关,XComponent调用 static void SurfaceCreated(int64_t shell_holder, void* window); - static void SurfaceChanged(int64_t shell_holder, - int32_t width, - int32_t height); + + static void SurfaceChanged( + int64_t shell_holder, + int32_t width, + int32_t height); + static void SurfaceDestroyed(int64_t shell_holder); static int64_t GetShellHolder(); static napi_value nativeXComponentAttachFlutterEngine( diff --git a/shell/platform/ohos/ohos_external_texture_gl.cpp b/shell/platform/ohos/ohos_external_texture_gl.cpp index 7533b43364..5047168738 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.cpp +++ b/shell/platform/ohos/ohos_external_texture_gl.cpp @@ -15,6 +15,8 @@ #include "ohos_external_texture_gl.h" +#include +#include #include #include "third_party/skia/include/core/SkAlphaType.h" @@ -24,10 +26,9 @@ #include "third_party/skia/include/gpu/GrBackendSurface.h" #include "third_party/skia/include/gpu/GrDirectContext.h" -#include -#include - #define EGL_PLATFORM_OHOS_KHR 0x34E0 +#define DMA_SIZE 256 // DMA内存分配的分块大小 +#define PIXEL_SIZE 4 // 像素点占用4个字节 namespace flutter { using GetPlatformDisplayExt = PFNEGLGETPLATFORMDISPLAYEXTPROC; @@ -38,7 +39,8 @@ constexpr const char *EGL_KHR_PLATFORM_WAYLAND = "EGL_KHR_platform_wayland"; constexpr const char *EGL_GET_PLATFORM_DISPLAY_EXT = "eglGetPlatformDisplayEXT"; OHOSExternalTextureGL::OHOSExternalTextureGL(int64_t id, const std::shared_ptr& ohos_surface) - : Texture(id), ohos_surface_(std::move(ohos_surface)), transform(SkMatrix::I()) { + : Texture(id), ohos_surface_(std::move(ohos_surface)), transform(SkMatrix::I()) +{ nativeImage_ = nullptr; nativeWindow_ = nullptr; eglContext_ = EGL_NO_CONTEXT; @@ -48,57 +50,63 @@ OHOSExternalTextureGL::OHOSExternalTextureGL(int64_t id, const std::shared_ptrGLContextMakeCurrent(); + if (result->GetResult()) { + FML_DLOG(INFO)<<"ResourceContextMakeCurrent successed"; + glGenTextures(1, &texture_name_); + FML_DLOG(INFO) << "OHOSExternalTextureGL::Paint, glGenTextures texture_name_=" << texture_name_; + if (nativeImage_ == nullptr) { + nativeImage_ = OH_NativeImage_Create(texture_name_, GL_TEXTURE_EXTERNAL_OES); + if (nativeImage_ == nullptr) { + FML_DLOG(ERROR) << "Error with OH_NativeImage_Create"; + return; + } + nativeWindow_ = OH_NativeImage_AcquireNativeWindow(nativeImage_); + if (nativeWindow_ == nullptr) { + FML_DLOG(ERROR) << "Error with OH_NativeImage_AcquireNativeWindow"; + return; + } + } + + int32_t ret = OH_NativeImage_AttachContext(nativeImage_, texture_name_); + if (ret != 0) { + FML_DLOG(FATAL)<<"OHOSExternalTextureGL OH_NativeImage_AttachContext err code:"<< ret; + } + state_ = AttachmentState::attached; + } else { + FML_DLOG(FATAL)<<"ResourceContextMakeCurrent failed"; + } +} + void OHOSExternalTextureGL::Paint(PaintContext& context, const SkRect& bounds, bool freeze, - const SkSamplingOptions& sampling) { + const SkSamplingOptions& sampling) +{ if (state_ == AttachmentState::detached) { FML_DLOG(ERROR) << "OHOSExternalTextureGL::Paint"; return; } if (state_ == AttachmentState::uninitialized) { - OHOSSurface* ohos_surface_ptr = ohos_surface_.get(); - OhosSurfaceGLSkia* ohosSurfaceGLSkia_ = (OhosSurfaceGLSkia*)ohos_surface_ptr; - auto result = ohosSurfaceGLSkia_->GLContextMakeCurrent(); - if (result->GetResult()) { - FML_DLOG(INFO)<<"ResourceContextMakeCurrent successed"; - glGenTextures(1, &texture_name_); - FML_DLOG(INFO) << "OHOSExternalTextureGL::Paint, glGenTextures texture_name_=" << texture_name_; - if (nativeImage_ == nullptr) { - nativeImage_ = OH_NativeImage_Create(texture_name_, GL_TEXTURE_EXTERNAL_OES); - if (nativeImage_ == nullptr) { - FML_DLOG(ERROR) << "Error with OH_NativeImage_Create"; - return; - } - nativeWindow_ = OH_NativeImage_AcquireNativeWindow(nativeImage_); - if (nativeWindow_ == nullptr) { - FML_DLOG(ERROR) << "Error with OH_NativeImage_AcquireNativeWindow"; - return; - } - } - - int32_t ret = OH_NativeImage_AttachContext(nativeImage_, texture_name_); - if(ret != 0) { - FML_DLOG(FATAL)<<"OHOSExternalTextureGL OH_NativeImage_AttachContext err code:"<< ret; - } - state_ = AttachmentState::attached; - } else { - FML_DLOG(FATAL)<<"ResourceContextMakeCurrent failed"; - } + Attach(); } if (!freeze && new_frame_ready_) { Update(); new_frame_ready_ = false; } - GrGLTextureInfo textureInfo = {GL_TEXTURE_EXTERNAL_OES, texture_name_, - GL_RGBA8_OES}; + GrGLTextureInfo textureInfo = { + GL_TEXTURE_EXTERNAL_OES, texture_name_, GL_RGBA8_OES}; GrBackendTexture backendTexture(1, 1, GrMipMapped::kNo, textureInfo); sk_sp image = SkImage::MakeFromTexture( context.gr_context, backendTexture, kTopLeft_GrSurfaceOrigin, @@ -128,7 +136,8 @@ void OHOSExternalTextureGL::Paint(PaintContext& context, } } -void OHOSExternalTextureGL::OnGrContextCreated() { +void OHOSExternalTextureGL::OnGrContextCreated() +{ FML_DLOG(INFO)<<" OHOSExternalTextureGL::OnGrContextCreated"; state_ = AttachmentState::uninitialized; } @@ -143,17 +152,20 @@ void OHOSExternalTextureGL::OnGrContextDestroyed() { state_ = AttachmentState::detached; } -void OHOSExternalTextureGL::MarkNewFrameAvailable() { +void OHOSExternalTextureGL::MarkNewFrameAvailable() +{ FML_DLOG(INFO)<<" OHOSExternalTextureGL::MarkNewFrameAvailable"; new_frame_ready_ = true; } -void OHOSExternalTextureGL::OnTextureUnregistered() { +void OHOSExternalTextureGL::OnTextureUnregistered() +{ FML_DLOG(INFO)<<" OHOSExternalTextureGL::OnTextureUnregistered"; // do nothing } -void OHOSExternalTextureGL::Update() { +void OHOSExternalTextureGL::Update() +{ ProducePixelMapToNativeImage(); int32_t ret = OH_NativeImage_UpdateSurfaceImage(nativeImage_); if (ret != 0) { @@ -162,21 +174,20 @@ void OHOSExternalTextureGL::Update() { UpdateTransform(); } -void OHOSExternalTextureGL::Detach() { +void OHOSExternalTextureGL::Detach() +{ OH_NativeImage_DetachContext(nativeImage_); OH_NativeWindow_DestroyNativeWindow(nativeWindow_); } -void OHOSExternalTextureGL::UpdateTransform() { +void OHOSExternalTextureGL::UpdateTransform() +{ float m[16] = { 0.0f }; int32_t ret = OH_NativeImage_GetTransformMatrix(nativeImage_, m); - if(ret != 0) { + if (ret != 0) { FML_DLOG(FATAL)<<"OHOSExternalTextureGL OH_NativeImage_GetTransformMatrix err code:"<< ret; } // transform ohos 4x4 matrix to skia 3x3 matrix - FML_DLOG(INFO)<<"OHOSExternalTextureGL::UpdateTransform "<virAddr, handle->size, PROT_READ | PROT_WRITE, MAP_SHARED, handle->fd, 0); @@ -234,7 +216,7 @@ void OHOSExternalTextureGL::ProducePixelMapToNativeImage() } void *pixelAddr = nullptr; - ret = OH_PixelMap_AccessPixels(pixelMap_, &pixelAddr); + int64_t ret = OH_PixelMap_AccessPixels(pixelMap_, &pixelAddr); if (ret != IMAGE_RESULT_SUCCESS) { FML_DLOG(FATAL)<<"OHOSExternalTextureGL OH_PixelMap_AccessPixels err:"<< ret; return; @@ -242,21 +224,23 @@ void OHOSExternalTextureGL::ProducePixelMapToNativeImage() uint32_t *value = static_cast(pixelAddr); uint32_t *pixel = static_cast(mappedAddr); - uint32_t rowDataSize = 256; // DMA内存会自动补齐,分配内存时是 256 的整数倍 + uint32_t rowDataSize = DMA_SIZE; // DMA内存会自动补齐,分配内存时是 256 的整数倍 while (rowDataSize < pixelMapInfo.rowSize) { - rowDataSize += 256; + rowDataSize += DMA_SIZE; } - FML_DLOG(INFO) << "OHOSExternalTextureGL pixelMapInfo w:" << pixelMapInfo.width << " h:" << pixelMapInfo.height; - FML_DLOG(INFO) << "OHOSExternalTextureGL pixelMapInfo rowSize:" << pixelMapInfo.rowSize << " format:" << pixelMapInfo.pixelFormat; + FML_DLOG(INFO) << "OHOSExternalTextureGL pixelMapInfo w:" << pixelMapInfo.width + << " h:" << pixelMapInfo.height; + FML_DLOG(INFO) << "OHOSExternalTextureGL pixelMapInfo rowSize:" << pixelMapInfo.rowSize + << " format:" << pixelMapInfo.pixelFormat; FML_DLOG(INFO) << "OHOSExternalTextureGL pixelMapInfo rowDataSize:" << rowDataSize; // 复制图片纹理数据到内存中,需要处理DMA内存补齐相关的逻辑 for (uint32_t i = 0; i < pixelMapInfo.height; i++) { memcpy(pixel, value, rowDataSize); - pixel += rowDataSize / 4; + pixel += rowDataSize / PIXEL_SIZE; value += pixelMapInfo.width; - } + } OH_PixelMap_UnAccessPixels(pixelMap_); //munmap after use @@ -265,15 +249,48 @@ void OHOSExternalTextureGL::ProducePixelMapToNativeImage() FML_DLOG(FATAL)<<"OHOSExternalTextureGL munmap failed"; return; } +} + +void OHOSExternalTextureGL::ProducePixelMapToNativeImage() +{ + if (pixelMap_ == nullptr) { + FML_DLOG(ERROR) << "OHOSExternalTextureGL pixelMap in null"; + return; + } + if (state_ == AttachmentState::detached) { + FML_DLOG(ERROR) << "OHOSExternalTextureGL AttachmentState err"; + return; + } + int32_t ret = -1; + ret = OH_PixelMap_GetImageInfo(pixelMap_, &pixelMapInfo); + if (ret != 0) { + FML_DLOG(ERROR) << "OHOSExternalTextureGL OH_PixelMap_GetImageInfo err:" << ret; + } + + int code = SET_BUFFER_GEOMETRY; + ret = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow_, code, pixelMapInfo.width, pixelMapInfo.height); + if (ret != 0) { + FML_DLOG(ERROR) << "OHOSExternalTextureGL OH_NativeWindow_NativeWindowHandleOpt err:" << ret; + } + + if (buffer_ != nullptr) { + OH_NativeWindow_NativeWindowAbortBuffer(nativeWindow_, buffer_); + buffer_ = nullptr; + } + ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow_, &buffer_, &fenceFd); + if (ret != 0) { + FML_DLOG(ERROR) << "OHOSExternalTextureGL OH_NativeWindow_NativeWindowRequestBuffer err:" << ret; + } + HandlePixelMapBuffer(); Region region{nullptr, 0}; ret = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow_, buffer_, fenceFd, region); - if(ret != 0) { + if (ret != 0) { FML_DLOG(FATAL)<<"OHOSExternalTextureGL OH_NativeWindow_NativeWindowFlushBuffer err:"<< ret; } } -EGLDisplay OHOSExternalTextureGL::GetPlatformEglDisplay(EGLenum platform, void *native_display, const EGLint *attrib_list) -{ +EGLDisplay OHOSExternalTextureGL::GetPlatformEglDisplay(EGLenum platform, void *native_display, + const EGLint *attrib_list) { GetPlatformDisplayExt eglGetPlatformDisplayExt = NULL; if (!eglGetPlatformDisplayExt) { @@ -313,7 +330,7 @@ bool OHOSExternalTextureGL::CheckEglExtension(const char *extensions, const char void OHOSExternalTextureGL::DispatchPixelMap(NativePixelMap* pixelMap) { - if(pixelMap != nullptr) { + if (pixelMap != nullptr) { pixelMap_ = pixelMap; } } diff --git a/shell/platform/ohos/ohos_external_texture_gl.h b/shell/platform/ohos/ohos_external_texture_gl.h index 0e900e60a4..88949d3dbd 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.h +++ b/shell/platform/ohos/ohos_external_texture_gl.h @@ -20,15 +20,16 @@ #include #include -#include "flutter/common/graphics/texture.h" -#include "flutter/shell/platform/ohos/surface/ohos_surface.h" -#include "flutter/shell/platform/ohos/ohos_surface_gl_skia.h" -#include "napi/platform_view_ohos_napi.h" #include -#include -#include #include #include +#include +#include + +#include "flutter/common/graphics/texture.h" +#include "flutter/shell/platform/ohos/napi/platform_view_ohos_napi.h" +#include "flutter/shell/platform/ohos/ohos_surface_gl_skia.h" +#include "flutter/shell/platform/ohos/surface/ohos_surface.h" // maybe now unused namespace flutter { @@ -59,6 +60,8 @@ class OHOSExternalTextureGL : public flutter::Texture { void DispatchPixelMap(NativePixelMap* pixelMap); private: + void Attach(); + void Update(); void Detach(); @@ -69,6 +72,8 @@ class OHOSExternalTextureGL : public flutter::Texture { bool CheckEglExtension(const char *extensions, const char *extension); + void HandlePixelMapBuffer(); + void ProducePixelMapToNativeImage(); enum class AttachmentState { uninitialized, attached, detached }; diff --git a/shell/platform/ohos/ohos_unified_surface.h b/shell/platform/ohos/ohos_unified_surface.h index 49aa35a3d6..591ba0dddf 100644 --- a/shell/platform/ohos/ohos_unified_surface.h +++ b/shell/platform/ohos/ohos_unified_surface.h @@ -41,7 +41,7 @@ class OHOSUnifiedSurface : public GPUSurfaceGLDelegate, bool SetNativeWindow(fml::RefPtr window) {} - std::unique_ptr CreateSnapshotSurface() + std::unique_ptr CreateSnapshotSurface() std::unique_ptr CreateGPUSurface( GrDirectContext* gr_context = nullptr) {} diff --git a/shell/platform/ohos/platform_view_ohos.cpp b/shell/platform/ohos/platform_view_ohos.cpp index 19f45611cf..85919a1f1a 100644 --- a/shell/platform/ohos/platform_view_ohos.cpp +++ b/shell/platform/ohos/platform_view_ohos.cpp @@ -170,7 +170,8 @@ void PlatformViewOHOS::NotifyChanged(const SkISize& size) { } // |PlatformView| -void PlatformViewOHOS::NotifyDestroyed() { +void PlatformViewOHOS::NotifyDestroyed() +{ LOGI("PlatformViewOHOS NotifyDestroyed enter"); PlatformView::NotifyDestroyed(); if (ohos_surface_) { @@ -392,13 +393,15 @@ void PlatformViewOHOS::FireFirstFrameCallback() { void PlatformViewOHOS::RegisterExternalTextureByImage( int64_t texture_id, - ImageNative* image) { - if(ohos_context_->RenderingApi() == OHOSRenderingAPI::kOpenGLES) { + ImageNative* image) +{ + if (ohos_context_->RenderingApi() == OHOSRenderingAPI::kOpenGLES) { auto iter = external_texture_gl_.find(texture_id); - if(iter != external_texture_gl_.end()) { + if (iter != external_texture_gl_.end()) { iter->second->DispatchImage(image); } else { - std::shared_ptr ohos_external_gl = std::make_shared(texture_id, ohos_surface_); + std::shared_ptr ohos_external_gl = + std::make_shared(texture_id, ohos_surface_); external_texture_gl_[texture_id] = ohos_external_gl; RegisterTexture(ohos_external_gl); ohos_external_gl->DispatchImage(image); @@ -406,20 +409,23 @@ void PlatformViewOHOS::RegisterExternalTextureByImage( } } -uint64_t PlatformViewOHOS::RegisterExternalTexture(int64_t texture_id) { +uint64_t PlatformViewOHOS::RegisterExternalTexture(int64_t texture_id) +{ uint64_t surface_id = 0; int ret = -1; if (ohos_context_->RenderingApi() == OHOSRenderingAPI::kOpenGLES) { - std::shared_ptr ohos_external_gl = std::make_shared(texture_id, ohos_surface_); + std::shared_ptr ohos_external_gl = + std::make_shared(texture_id, ohos_surface_); ohos_external_gl->nativeImage_ = OH_NativeImage_Create(texture_id, GL_TEXTURE_EXTERNAL_OES); if (ohos_external_gl->nativeImage_ == nullptr) { FML_DLOG(ERROR) << "Error with OH_NativeImage_Create"; return surface_id; } void* contextData = new OhosImageFrameData(this, texture_id); - nativeImageFrameAvailableListener_.context = contextData; - nativeImageFrameAvailableListener_.onFrameAvailable = &PlatformViewOHOS::OnNativeImageFrameAvailable; - ret = OH_NativeImage_SetOnFrameAvailableListener(ohos_external_gl->nativeImage_, nativeImageFrameAvailableListener_); + OH_OnFrameAvailableListener listener; + listener.context = contextData; + listener.onFrameAvailable = &PlatformViewOHOS::OnNativeImageFrameAvailable; + ret = OH_NativeImage_SetOnFrameAvailableListener(ohos_external_gl->nativeImage_, listener); if (ret != 0) { FML_DLOG(ERROR) << "Error with OH_NativeImage_SetOnFrameAvailableListener"; return surface_id; @@ -434,7 +440,8 @@ uint64_t PlatformViewOHOS::RegisterExternalTexture(int64_t texture_id) { return surface_id; } -void PlatformViewOHOS::OnNativeImageFrameAvailable(void *data) { +void PlatformViewOHOS::OnNativeImageFrameAvailable(void *data) +{ auto frameData = reinterpret_cast(data); if (frameData == nullptr || frameData->context_ == nullptr) { FML_DLOG(ERROR) << "OnNativeImageFrameAvailable, frameData or context_ is null."; @@ -467,7 +474,8 @@ void PlatformViewOHOS::RegisterExternalTextureByPixelMap(int64_t texture_id, Nat if (iter != external_texture_gl_.end()) { iter->second->DispatchPixelMap(pixelMap); } else { - std::shared_ptr ohos_external_gl = std::make_shared(texture_id, ohos_surface_); + std::shared_ptr ohos_external_gl = + std::make_shared(texture_id, ohos_surface_); external_texture_gl_[texture_id] = ohos_external_gl; RegisterTexture(ohos_external_gl); ohos_external_gl->DispatchPixelMap(pixelMap); diff --git a/shell/platform/ohos/platform_view_ohos.h b/shell/platform/ohos/platform_view_ohos.h index 387022cc08..a9793dd73a 100644 --- a/shell/platform/ohos/platform_view_ohos.h +++ b/shell/platform/ohos/platform_view_ohos.h @@ -21,19 +21,20 @@ #include #include +#include +#include + #include "flutter/fml/memory/weak_ptr.h" #include "flutter/lib/ui/window/platform_message.h" #include "flutter/shell/common/platform_view.h" #include "flutter/shell/platform/ohos/context/ohos_context.h" #include "flutter/shell/platform/ohos/napi/platform_view_ohos_napi.h" +#include "flutter/shell/platform/ohos/ohos_external_texture_gl.h" #include "flutter/shell/platform/ohos/platform_message_handler_ohos.h" #include "flutter/shell/platform/ohos/surface/ohos_native_window.h" #include "flutter/shell/platform/ohos/surface/ohos_snapshot_surface_producer.h" #include "flutter/shell/platform/ohos/surface/ohos_surface.h" #include "flutter/shell/platform/ohos/vsync_waiter_ohos.h" -#include -#include "ohos_external_texture_gl.h" -#include namespace flutter { @@ -178,8 +179,6 @@ class PlatformViewOHOS final : public PlatformView { FML_DISALLOW_COPY_AND_ASSIGN(PlatformViewOHOS); - OH_OnFrameAvailableListener nativeImageFrameAvailableListener_{}; - static void OnNativeImageFrameAvailable(void *data); }; -- Gitee From b88e455ab4483cf533bd2009eecb01589d50157b Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Mon, 26 Feb 2024 22:25:25 +0800 Subject: [PATCH 36/73] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=97=A8=E7=A6=81?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E7=9A=84=E4=BB=A3=E7=A0=81=E6=A0=BC=E5=BC=8F?= =?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: hezhengyi --- .../ohos/napi/platform_view_ohos_napi.cpp | 12 ++++++++---- .../ohos/ohos_external_texture_gl.cpp | 19 ++++++++++++------- shell/platform/ohos/platform_view_ohos.cpp | 4 ++-- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/shell/platform/ohos/napi/platform_view_ohos_napi.cpp b/shell/platform/ohos/napi/platform_view_ohos_napi.cpp index 6c927d8bc2..69bd07dcee 100644 --- a/shell/platform/ohos/napi/platform_view_ohos_napi.cpp +++ b/shell/platform/ohos/napi/platform_view_ohos_napi.cpp @@ -1443,7 +1443,8 @@ napi_value PlatformViewOHOSNapi::nativeInitNativeImage( napi_value PlatformViewOHOSNapi::nativeRegisterTexture( napi_env env, - napi_callback_info info) { + napi_callback_info info) +{ FML_DLOG(INFO)<<"PlatformViewOHOSNapi::nativeRegisterTexture"; size_t argc = 2; napi_value args[2] = {nullptr}; @@ -1460,7 +1461,8 @@ napi_value PlatformViewOHOSNapi::nativeRegisterTexture( napi_value PlatformViewOHOSNapi::nativeUnregisterTexture( napi_env env, - napi_callback_info info) { + napi_callback_info info) +{ FML_DLOG(INFO)<<"PlatformViewOHOSNapi::nativeUnregisterTexture"; size_t argc = 2; napi_value args[2] = {nullptr}; @@ -1475,7 +1477,8 @@ napi_value PlatformViewOHOSNapi::nativeUnregisterTexture( napi_value PlatformViewOHOSNapi::nativeMarkTextureFrameAvailable( napi_env env, - napi_callback_info info) { + napi_callback_info info) +{ size_t argc = 2; napi_value args[2] = {nullptr}; int64_t shell_holder; @@ -1489,7 +1492,8 @@ napi_value PlatformViewOHOSNapi::nativeMarkTextureFrameAvailable( napi_value PlatformViewOHOSNapi::nativeRegisterPixelMap( napi_env env, - napi_callback_info info) { + napi_callback_info info) +{ FML_DLOG(INFO)<<"PlatformViewOHOSNapi::nativeRegisterPixelMap"; size_t argc = 3; napi_value args[3] = {nullptr}; diff --git a/shell/platform/ohos/ohos_external_texture_gl.cpp b/shell/platform/ohos/ohos_external_texture_gl.cpp index 5047168738..fa99b84b7e 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.cpp +++ b/shell/platform/ohos/ohos_external_texture_gl.cpp @@ -27,8 +27,9 @@ #include "third_party/skia/include/gpu/GrDirectContext.h" #define EGL_PLATFORM_OHOS_KHR 0x34E0 -#define DMA_SIZE 256 // DMA内存分配的分块大小 -#define PIXEL_SIZE 4 // 像素点占用4个字节 + +const int DMA_SIZE = 256 // DMA内存分配的分块大小 +const int PIXEL_SIZE = 4 // 像素点占用4个字节 namespace flutter { using GetPlatformDisplayExt = PFNEGLGETPLATFORMDISPLAYEXTPROC; @@ -57,7 +58,8 @@ OHOSExternalTextureGL::~OHOSExternalTextureGL() } } -void OHOSExternalTextureGL::Attach() { +void OHOSExternalTextureGL::Attach() +{ OHOSSurface* ohos_surface_ptr = ohos_surface_.get(); OhosSurfaceGLSkia* ohosSurfaceGLSkia_ = (OhosSurfaceGLSkia*)ohos_surface_ptr; auto result = ohosSurfaceGLSkia_->GLContextMakeCurrent(); @@ -142,7 +144,8 @@ void OHOSExternalTextureGL::OnGrContextCreated() state_ = AttachmentState::uninitialized; } -void OHOSExternalTextureGL::OnGrContextDestroyed() { +void OHOSExternalTextureGL::OnGrContextDestroyed() +{ FML_DLOG(INFO)<<" OHOSExternalTextureGL::OnGrContextDestroyed"; if (state_ == AttachmentState::attached) { Detach(); @@ -206,7 +209,8 @@ void OHOSExternalTextureGL::DispatchImage(ImageNative* image) lastImage_ = image; } -void OHOSExternalTextureGL::HandlePixelMapBuffer() { +void OHOSExternalTextureGL::HandlePixelMapBuffer() +{ BufferHandle *handle = OH_NativeWindow_GetBufferHandleFromNative(buffer_); // get virAddr of bufferHandl by mmap sys interface void *mappedAddr = mmap(handle->virAddr, handle->size, PROT_READ | PROT_WRITE, MAP_SHARED, handle->fd, 0); @@ -243,7 +247,7 @@ void OHOSExternalTextureGL::HandlePixelMapBuffer() { } OH_PixelMap_UnAccessPixels(pixelMap_); - //munmap after use + // munmap after use ret = munmap(mappedAddr, handle->size); if (ret == -1) { FML_DLOG(FATAL)<<"OHOSExternalTextureGL munmap failed"; @@ -290,7 +294,8 @@ void OHOSExternalTextureGL::ProducePixelMapToNativeImage() } EGLDisplay OHOSExternalTextureGL::GetPlatformEglDisplay(EGLenum platform, void *native_display, - const EGLint *attrib_list) { + const EGLint *attrib_list) +{ GetPlatformDisplayExt eglGetPlatformDisplayExt = NULL; if (!eglGetPlatformDisplayExt) { diff --git a/shell/platform/ohos/platform_view_ohos.cpp b/shell/platform/ohos/platform_view_ohos.cpp index 85919a1f1a..d1e0e0fb8b 100644 --- a/shell/platform/ohos/platform_view_ohos.cpp +++ b/shell/platform/ohos/platform_view_ohos.cpp @@ -448,7 +448,7 @@ void PlatformViewOHOS::OnNativeImageFrameAvailable(void *data) return; } std::shared_ptr ohos_surface = frameData->context_->ohos_surface_; - const TaskRunners task_runners = frameData->context_->task_runners_;; + const TaskRunners task_runners = frameData->context_->task_runners_; if (ohos_surface) { fml::AutoResetWaitableEvent latch; fml::TaskRunner::RunNowOrPostTask( @@ -474,7 +474,7 @@ void PlatformViewOHOS::RegisterExternalTextureByPixelMap(int64_t texture_id, Nat if (iter != external_texture_gl_.end()) { iter->second->DispatchPixelMap(pixelMap); } else { - std::shared_ptr ohos_external_gl = + std::shared_ptr ohos_external_gl = std::make_shared(texture_id, ohos_surface_); external_texture_gl_[texture_id] = ohos_external_gl; RegisterTexture(ohos_external_gl); -- Gitee From 5ff2c399da58b9546548ebe4450b873c572fa5d1 Mon Sep 17 00:00:00 2001 From: hazy Date: Mon, 26 Feb 2024 15:26:45 +0000 Subject: [PATCH 37/73] update shell/platform/ohos/ohos_external_texture_gl.cpp. Signed-off-by: hazy --- shell/platform/ohos/ohos_external_texture_gl.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/platform/ohos/ohos_external_texture_gl.cpp b/shell/platform/ohos/ohos_external_texture_gl.cpp index fa99b84b7e..9515f268e1 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.cpp +++ b/shell/platform/ohos/ohos_external_texture_gl.cpp @@ -28,8 +28,8 @@ #define EGL_PLATFORM_OHOS_KHR 0x34E0 -const int DMA_SIZE = 256 // DMA内存分配的分块大小 -const int PIXEL_SIZE = 4 // 像素点占用4个字节 +const int DMA_SIZE = 256; // DMA内存分配的分块大小 +const int PIXEL_SIZE = 4; // 像素点占用4个字节 namespace flutter { using GetPlatformDisplayExt = PFNEGLGETPLATFORMDISPLAYEXTPROC; -- Gitee From d1ac307266caff62f90dda448a654f417733cab5 Mon Sep 17 00:00:00 2001 From: zhan-linlin <17301907374@163.com> Date: Tue, 27 Feb 2024 14:39:49 +0800 Subject: [PATCH 38/73] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E9=80=9A=E9=81=93=E4=BC=A0=E9=80=92map=E6=97=B6=E4=B8=BAnull?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhan-linlin <17301907374@163.com> --- .../src/main/ets/plugin/common/MethodCall.ets | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/MethodCall.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/MethodCall.ets index 0042c25c3b..2482962862 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/MethodCall.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/MethodCall.ets @@ -14,6 +14,10 @@ */ import ToolUtils from '../../util/ToolUtils'; +import TreeMap from '@ohos.util.TreeMap'; +import HashMap from '@ohos.util.HashMap'; +import LightWeightMap from '@ohos.util.LightWeightMap'; + /** Command object representing a method call on a {@link MethodChannel}. */ export default class MethodCall { /** The name of the called method. */ @@ -30,7 +34,16 @@ export default class MethodCall { constructor(method: string, args: ESObject) { this.method = method - this.args = args + if (args instanceof Map || args instanceof HashMap || args instanceof TreeMap + || args instanceof LightWeightMap ) { + let obj: ESObject = {}; + args.forEach((value: ESObject, key: ESObject)=>{ + obj[key] = value; + }) + this.args = obj; + }else { + this.args = args; + } } argument(key: string): ESObject { -- Gitee From 7565f6e2896c90d4dd0717b7fbd8f674924949c7 Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Wed, 28 Feb 2024 09:38:16 +0800 Subject: [PATCH 39/73] =?UTF-8?q?=E4=BF=AE=E6=94=B9ohos=5Fapi=5Finit?= =?UTF-8?q?=E8=B5=8B=E5=80=BC=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- tools/gn | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/gn b/tools/gn index a9f38074da..881c32f7ec 100755 --- a/tools/gn +++ b/tools/gn @@ -301,8 +301,9 @@ def to_gn_args(args): gn_args['android_full_debug' ] = args.target_os == 'android' and args.unoptimized - gn_args['ohos_api_int'] = args.ohos_api_int - + if args.target_os == 'ohos': + gn_args['ohos_api_int'] = args.ohos_api_int + if args.clang is None: gn_args['is_clang'] = True else: -- Gitee From 72849744b71d08eb50d43e550ca559a04786c30c Mon Sep 17 00:00:00 2001 From: cjand <1747143535@qq.com> Date: Wed, 28 Feb 2024 15:21:31 +0800 Subject: [PATCH 40/73] =?UTF-8?q?=E6=B7=BB=E5=8A=A0JSONMessageCodes?= =?UTF-8?q?=E7=9A=84Array/Object=E7=9A=84=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cjand <1747143535@qq.com> --- .../src/main/ets/plugin/common/JSONMessageCodec.ets | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/JSONMessageCodec.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/JSONMessageCodec.ets index e37a3d27e5..b5b71c760b 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/JSONMessageCodec.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/JSONMessageCodec.ets @@ -68,6 +68,18 @@ export default class JSONMessageCodec implements MessageCodec { messageObj[this.toBaseData(key)] = this.toBaseData(value); }); return messageObj; + } else if (message instanceof Array) { + let messageArr:Array = []; + message.forEach((value:ESObject)=>{ + messageArr.push(this.toBaseData(value)); + }) + return messageArr; + } else if (message instanceof Object) { + let messageObj: ESObject = {}; + Object.keys(message).forEach((key:ESObject)=>{ + messageObj[this.toBaseData(key)] = this.toBaseData(message[key]); + }) + return messageObj; } else { return message; } -- Gitee From ebdb7f4e8810fa13d546f61a4ead405aee6da217 Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Thu, 29 Feb 2024 19:03:31 +0800 Subject: [PATCH 41/73] =?UTF-8?q?=E4=BF=AE=E6=94=B9flutter=5Fembedding?= =?UTF-8?q?=E4=B8=AD=E6=B6=88=E6=81=AF=E9=80=9A=E9=81=93=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- .../src/main/ets/plugin/common/MethodCall.ets | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/MethodCall.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/MethodCall.ets index 2482962862..12920e4945 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/MethodCall.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/MethodCall.ets @@ -33,17 +33,8 @@ export default class MethodCall { args: ESObject; constructor(method: string, args: ESObject) { - this.method = method - if (args instanceof Map || args instanceof HashMap || args instanceof TreeMap - || args instanceof LightWeightMap ) { - let obj: ESObject = {}; - args.forEach((value: ESObject, key: ESObject)=>{ - obj[key] = value; - }) - this.args = obj; - }else { - this.args = args; - } + this.method = method; + this.args = args; } argument(key: string): ESObject { -- Gitee From 368819054c5106b5cac6a3669523a87852ae4580 Mon Sep 17 00:00:00 2001 From: xiaoxiang Date: Fri, 1 Mar 2024 14:45:35 +0800 Subject: [PATCH 42/73] add get_flutterViewList Signed-off-by: xiaoxiang --- .../flutter/src/main/ets/embedding/ohos/FlutterManager.ets | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterManager.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterManager.ets index 88362ab53a..43f42053b8 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterManager.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterManager.ets @@ -68,6 +68,10 @@ export default class FlutterManager { return this.flutterViewList.get(viewId) ?? null; } + getFlutterViewList(): Map { + return this.flutterViewList; + } + private putFlutterView(viewId: string, flutterView?: FlutterView): void { if (flutterView != null) { this.flutterViewList.set(viewId, flutterView); -- Gitee From 73e0d13d419922c3cd20c6a5598ffbac4cc4e33f Mon Sep 17 00:00:00 2001 From: xiaoxiang Date: Fri, 1 Mar 2024 17:21:35 +0800 Subject: [PATCH 43/73] add get_flutterViewList Signed-off-by: xiaoxiang --- .../flutter_embedding/flutter/src/main/ets/view/FlutterView.ets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterView.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterView.ets index 0e19662f6c..163550dfbd 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterView.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterView.ets @@ -177,7 +177,7 @@ export class FlutterView { this.updateViewportMetrics() } - private isAttachedToFlutterEngine(): boolean { + public isAttachedToFlutterEngine(): boolean { return this.flutterEngine != null } -- Gitee From c217c3e34204156a69f8c7c008eaa34bb6a08173 Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Mon, 4 Mar 2024 21:04:12 +0800 Subject: [PATCH 44/73] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E4=B8=8D=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E7=9A=84async?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- .../flutter/src/main/ets/embedding/ohos/FlutterAbility.ets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets index 7c63ef9873..537f0fd8bc 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets @@ -124,7 +124,7 @@ export class FlutterAbility extends UIAbility implements Host { * window状态改变回调 * @param windowStage */ - async onWindowStageCreate(windowStage: window.WindowStage) { + onWindowStageCreate(windowStage: window.WindowStage) { FlutterManager.getInstance().pushWindowStage(this, windowStage); this.mainWindow = windowStage.getMainWindowSync(); try { -- Gitee From afcfc0f8ea647c99f1b8afa4ebc628987f4f1429 Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Tue, 5 Mar 2024 17:24:42 +0800 Subject: [PATCH 45/73] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dmacos=E7=BC=96=E8=AF=91?= =?UTF-8?q?engine=E7=9A=84host=E4=BA=A7=E7=89=A9=E6=8A=A5=E9=94=99?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- impeller/tools/impeller.gni | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/impeller/tools/impeller.gni b/impeller/tools/impeller.gni index 0c54d8de36..28484b966a 100644 --- a/impeller/tools/impeller.gni +++ b/impeller/tools/impeller.gni @@ -11,13 +11,12 @@ declare_args() { impeller_enable_playground = false # Whether the Metal backend is enabled. - impeller_enable_metal = is_ios + impeller_enable_metal = is_mac || is_ios # Whether the OpenGLES backend is enabled. - impeller_enable_opengles = is_linux || is_win || is_android ||is_ohos + impeller_enable_opengles = is_mac || is_linux || is_win || is_android || is_ohos # Whether the Vulkan backend is enabled. - #impeller_enable_vulkan = is_mac || is_linux || is_win || is_android impeller_enable_vulkan = (is_win || is_android || is_linux) && !is_ohos # Whether to use a prebuilt impellerc. -- Gitee From 3d9f7f30847b69427c140ef977b78d1987e4f207 Mon Sep 17 00:00:00 2001 From: 18719058668 <718092089@qq.com> Date: Tue, 5 Mar 2024 20:25:22 +0800 Subject: [PATCH 46/73] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A4=96=E6=8E=A5?= =?UTF-8?q?=E7=BA=B9=E7=90=86=E5=A4=9A=E5=BC=A0=E5=9B=BE=E7=89=87=E5=9C=BA?= =?UTF-8?q?=E6=99=AFbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 18719058668 <718092089@qq.com> --- .../main/ets/embedding/engine/renderer/FlutterRenderer.ets | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/renderer/FlutterRenderer.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/renderer/FlutterRenderer.ets index e31ee486f5..f1624aaa4d 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/renderer/FlutterRenderer.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/renderer/FlutterRenderer.ets @@ -57,9 +57,9 @@ export class FlutterRenderer implements TextureRegistry { } registerPixelMap(pixelMap: PixelMap): number { - let textureId = this.nextTextureId + 1; - this.flutterNapi.registerPixelMap(textureId, pixelMap); - return textureId; + this.nextTextureId = this.nextTextureId + 1; + this.flutterNapi.registerPixelMap(this.nextTextureId, pixelMap); + return this.nextTextureId; } unregisterTexture(textureId: number): void { -- Gitee From ad73b68eda7701eae6fd4e41f6589656ca2b2635 Mon Sep 17 00:00:00 2001 From: wcedla Date: Wed, 6 Mar 2024 23:05:22 +0800 Subject: [PATCH 47/73] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dwindows=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E5=AF=B9dart.patch=E6=8D=A2=E8=A1=8C=E7=AC=A6?= =?UTF-8?q?=E7=9A=84=E5=A4=84=E7=90=86=E6=96=B9=E5=BC=8F=E4=B8=8D=E5=90=8C?= =?UTF-8?q?=E5=AF=BC=E8=87=B4dart=20vm=20snapshot=20hash=E4=B8=8E=E9=A2=84?= =?UTF-8?q?=E6=9C=9F=E4=B8=8D=E5=90=8C=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wcedla --- .gitattributes | 3 ++- README.en.md | 13 ++++++++++++- README.md | 11 +++++++++++ attachment/repos/dart.patch0 | 2 +- attachment/repos/dart.patch1 | 2 +- attachment/repos/dart.patch2 | 2 +- 6 files changed, 28 insertions(+), 5 deletions(-) diff --git a/.gitattributes b/.gitattributes index 915d1ed51d..7d94e09613 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,4 @@ # Dart sources have to be normalized so that source offsets in kernel files # with source embedded in them match across all platforms. -*.dart text eol=lf \ No newline at end of file +*.dart text eol=lf +*.patch* text eol=lf \ No newline at end of file diff --git a/README.en.md b/README.en.md index 3fdf8e6498..b9ebea7120 100644 --- a/README.en.md +++ b/README.en.md @@ -64,13 +64,24 @@ export OHOS_SDK_HOME= ## FAQ: 1. When running the project, an error of Member notfound:'isOhos' is reported: Please ensure that all dart patches are applied in the src/third_party/dart directory (the patches are located in the src/flutter/attachment/repos directory, and you can use git apply to apply the patch). Recompile the engine after patching - + 2. Prompt Permission denied: Execute chmod +x