From a0276302589e9362ed823e3aeaa5ea1e7c3df56e Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Sun, 15 Sep 2024 11:57:52 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E7=A8=B3=E5=AE=9A=E6=80=A7=E9=97=AE?= =?UTF-8?q?=E9=A2=98,=E4=BF=AE=E6=94=B9=E5=A4=9A=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?=E5=9C=BA=E6=99=AF=E5=8F=AF=E8=83=BD=E5=87=BA=E7=8E=B0=E7=9A=84?= =?UTF-8?q?=E5=8F=AF=E8=A7=81=E6=80=A7=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/ohos_external_texture_gl.cpp | 4 +++ .../platform/ohos/ohos_external_texture_gl.h | 2 +- shell/platform/ohos/platform_view_ohos.cpp | 28 +++++++++++++------ shell/platform/ohos/platform_view_ohos.h | 2 +- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/shell/platform/ohos/ohos_external_texture_gl.cpp b/shell/platform/ohos/ohos_external_texture_gl.cpp index 3c4c9f91a2..a5f2ab3df7 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.cpp +++ b/shell/platform/ohos/ohos_external_texture_gl.cpp @@ -224,6 +224,10 @@ void OHOSExternalTextureGL::OnTextureUnregistered() << ", Id()=" << Id() << ", nativeImage_=" << nativeImage_ << ", backGroundNativeImage_=" << backGroundNativeImage_; + if (state_ != AttachmentState::attached) { + FML_LOG(ERROR) << "OHOSExternalTextureGL::OnTextureUnregistered, the current status is not attached"; + return; + } first_update_ = false; if (nativeImage_ != nullptr) { OH_NativeImage_UnsetOnFrameAvailableListener(nativeImage_); diff --git a/shell/platform/ohos/ohos_external_texture_gl.h b/shell/platform/ohos/ohos_external_texture_gl.h index 3925a4cb33..495eb02594 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.h +++ b/shell/platform/ohos/ohos_external_texture_gl.h @@ -92,7 +92,7 @@ class OHOSExternalTextureGL : public flutter::Texture { enum class AttachmentState { uninitialized, attached, detached }; - AttachmentState state_; + std::atomic state_; bool new_frame_ready_ = false; diff --git a/shell/platform/ohos/platform_view_ohos.cpp b/shell/platform/ohos/platform_view_ohos.cpp index b66be4705f..bad544f3f8 100644 --- a/shell/platform/ohos/platform_view_ohos.cpp +++ b/shell/platform/ohos/platform_view_ohos.cpp @@ -139,9 +139,13 @@ void PlatformViewOHOS::NotifyCreate( fml::TaskRunner::RunNowOrPostTask( task_runners_.GetRasterTaskRunner(), [&latch, surface = ohos_surface_.get(), - native_window = std::move(native_window)]() { - LOGI("NotifyCreate start4"); - surface->SetNativeWindow(native_window); + native_window = std::move(native_window), this]() { + if (GetDestroyed()) { + LOGW("NotifyCreate, GetDestroyed is true, ignore this call."); + } else { + LOGI("NotifyCreate start4"); + surface->SetNativeWindow(native_window); + } latch.Signal(); }); latch.Wait(); @@ -158,9 +162,13 @@ void PlatformViewOHOS::NotifySurfaceWindowChanged( fml::TaskRunner::RunNowOrPostTask( task_runners_.GetRasterTaskRunner(), [&latch, surface = ohos_surface_.get(), - native_window = std::move(native_window)]() { - surface->TeardownOnScreenContext(); - surface->SetNativeWindow(native_window); + native_window = std::move(native_window), this]() { + if (GetDestroyed()) { + LOGW("NotifySurfaceWindowChanged, GetDestroyed is true, ignore this call."); + } else { + surface->TeardownOnScreenContext(); + surface->SetNativeWindow(native_window); + } latch.Signal(); }); latch.Wait(); @@ -173,8 +181,12 @@ void PlatformViewOHOS::NotifyChanged(const SkISize& size) { fml::AutoResetWaitableEvent latch; fml::TaskRunner::RunNowOrPostTask( task_runners_.GetRasterTaskRunner(), // - [&latch, surface = ohos_surface_.get(), size]() { - surface->OnScreenSurfaceResize(size); + [&latch, surface = ohos_surface_.get(), size, this]() { + if (GetDestroyed()) { + LOGW("NotifyChanged, GetDestroyed is true, ignore this call."); + } else { + surface->OnScreenSurfaceResize(size); + } latch.Signal(); }); latch.Wait(); diff --git a/shell/platform/ohos/platform_view_ohos.h b/shell/platform/ohos/platform_view_ohos.h index f7cc0778e1..14c60e884c 100644 --- a/shell/platform/ohos/platform_view_ohos.h +++ b/shell/platform/ohos/platform_view_ohos.h @@ -141,7 +141,7 @@ class PlatformViewOHOS final : public PlatformView { std::map> external_texture_gl_; std::map contextDatas_; - bool isDestroyed_; + std::atomic isDestroyed_; bool GetDestroyed(); -- Gitee From 480195e831fd1314a07e6f927a200db4509d0bd1 Mon Sep 17 00:00:00 2001 From: duanaoqi Date: Wed, 18 Sep 2024 14:22:59 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E5=8D=95=E7=8B=AC=E5=A4=84=E7=90=86?= =?UTF-8?q?=E9=BC=A0=E6=A0=87=E4=BA=A7=E7=94=9F=E7=9A=84touch=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=EF=BC=8C=E4=BC=A0=E9=80=92=E7=BB=99PlatformView?= =?UTF-8?q?=EF=BC=8C=E8=A7=A3=E5=86=B3webview=E6=97=A0=E6=B3=95=E7=82=B9?= =?UTF-8?q?=E5=87=BB=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: duanaoqi --- shell/platform/ohos/ohos_touch_processor.cpp | 26 +++++++++++++++++++ shell/platform/ohos/ohos_touch_processor.h | 3 +++ .../platform/ohos/ohos_xcomponent_adapter.cpp | 1 + 3 files changed, 30 insertions(+) diff --git a/shell/platform/ohos/ohos_touch_processor.cpp b/shell/platform/ohos/ohos_touch_processor.cpp index 4849075ba0..1c04f38f03 100644 --- a/shell/platform/ohos/ohos_touch_processor.cpp +++ b/shell/platform/ohos/ohos_touch_processor.cpp @@ -260,4 +260,30 @@ void OhosTouchProcessor::HandleMouseEvent( ohos_shell_holder->GetPlatformView()->DispatchPointerDataPacket(std::move(packet)); return; } + +void OhosTouchProcessor::HandleVirtualTouchEvent( + int64_t shell_holderID, + OH_NativeXComponent* component, + OH_NativeXComponent_TouchEvent* touchEvent) +{ + int numPoints = touchEvent->numPoints; + float tiltX = 0.0; + float tiltY = 0.0; + auto ohos_shell_holder = reinterpret_cast(shell_holderID); + OH_NativeXComponent_TouchPointToolType toolType; + OH_NativeXComponent_GetTouchPointToolType(component, 0, &toolType); + OH_NativeXComponent_GetTouchPointTiltX(component, 0, &tiltX); + OH_NativeXComponent_GetTouchPointTiltY(component, 0, &tiltY); + std::unique_ptr touchPacket = + std::make_unique(); + touchPacket->touchEventInput = touchEvent; + touchPacket->toolTypeInput = toolType; + touchPacket->tiltX = tiltX; + touchPacket->tiltX = tiltY; + + std::shared_ptr touchPacketString = packagePacketData(std::move(touchPacket)); + int size = CHANGES_POINTER_MEMBER + PER_POINTER_MEMBER * numPoints + TOUCH_EVENT_ADDITIONAL_ATTRIBUTES; + ohos_shell_holder->GetPlatformView()->OnTouchEvent(touchPacketString, size); + return; +} } // namespace flutter \ No newline at end of file diff --git a/shell/platform/ohos/ohos_touch_processor.h b/shell/platform/ohos/ohos_touch_processor.h index 94012bf1a8..1f59bd16a9 100644 --- a/shell/platform/ohos/ohos_touch_processor.h +++ b/shell/platform/ohos/ohos_touch_processor.h @@ -40,6 +40,9 @@ class OhosTouchProcessor { OH_NativeXComponent* component, OH_NativeXComponent_MouseEvent mouseEvent, double offsetY); + void HandleVirtualTouchEvent(int64_t shell_holderID, + OH_NativeXComponent* component, + OH_NativeXComponent_TouchEvent* touchEvent); flutter::PointerData::Change getPointerChangeForAction(int maskedAction); flutter::PointerData::DeviceKind getPointerDeviceTypeForToolType( int toolType); diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.cpp b/shell/platform/ohos/ohos_xcomponent_adapter.cpp index d1b62dcd70..562e17f44b 100644 --- a/shell/platform/ohos/ohos_xcomponent_adapter.cpp +++ b/shell/platform/ohos/ohos_xcomponent_adapter.cpp @@ -378,6 +378,7 @@ void XComponentBase::OnDispatchTouchEvent(OH_NativeXComponent* component, int32_t ret2 = OH_NativeXComponent_GetTouchEventSourceType(component, touchEvent_.id, &sourceType); if (ret2 == OH_NATIVEXCOMPONENT_RESULT_SUCCESS && sourceType == OH_NATIVEXCOMPONENT_SOURCE_TYPE_MOUSE) { + ohosTouchProcessor_.HandleVirtualTouchEvent(std::stoll(shellholderId_), component, &touchEvent_); return; } ohosTouchProcessor_.HandleTouchEvent(std::stoll(shellholderId_), -- Gitee From 4c2c1aea8a585402c202b8db3ccdd05e2e272612 Mon Sep 17 00:00:00 2001 From: duanaoqi Date: Wed, 18 Sep 2024 15:17:00 +0800 Subject: [PATCH 3/5] codecheck fix Signed-off-by: duanaoqi --- shell/platform/ohos/ohos_touch_processor.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/shell/platform/ohos/ohos_touch_processor.h b/shell/platform/ohos/ohos_touch_processor.h index 1f59bd16a9..551a5fc5c6 100644 --- a/shell/platform/ohos/ohos_touch_processor.h +++ b/shell/platform/ohos/ohos_touch_processor.h @@ -40,9 +40,10 @@ class OhosTouchProcessor { OH_NativeXComponent* component, OH_NativeXComponent_MouseEvent mouseEvent, double offsetY); - void HandleVirtualTouchEvent(int64_t shell_holderID, - OH_NativeXComponent* component, - OH_NativeXComponent_TouchEvent* touchEvent); + void HandleVirtualTouchEvent( + int64_t shell_holderID, + OH_NativeXComponent* component, + OH_NativeXComponent_TouchEvent* touchEvent); flutter::PointerData::Change getPointerChangeForAction(int maskedAction); flutter::PointerData::DeviceKind getPointerDeviceTypeForToolType( int toolType); -- Gitee From c0348cad6f4c60dc879a14befebc4542445d6587 Mon Sep 17 00:00:00 2001 From: duanaoqi Date: Wed, 18 Sep 2024 15:41:07 +0800 Subject: [PATCH 4/5] fix codecheck Signed-off-by: duanaoqi --- shell/platform/ohos/ohos_touch_processor.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/shell/platform/ohos/ohos_touch_processor.h b/shell/platform/ohos/ohos_touch_processor.h index 551a5fc5c6..1f59bd16a9 100644 --- a/shell/platform/ohos/ohos_touch_processor.h +++ b/shell/platform/ohos/ohos_touch_processor.h @@ -40,10 +40,9 @@ class OhosTouchProcessor { OH_NativeXComponent* component, OH_NativeXComponent_MouseEvent mouseEvent, double offsetY); - void HandleVirtualTouchEvent( - int64_t shell_holderID, - OH_NativeXComponent* component, - OH_NativeXComponent_TouchEvent* touchEvent); + void HandleVirtualTouchEvent(int64_t shell_holderID, + OH_NativeXComponent* component, + OH_NativeXComponent_TouchEvent* touchEvent); flutter::PointerData::Change getPointerChangeForAction(int maskedAction); flutter::PointerData::DeviceKind getPointerDeviceTypeForToolType( int toolType); -- Gitee From 26bd52f38eddb4fd8396dd7c6ed12393bb3cce6f Mon Sep 17 00:00:00 2001 From: gxzmf <279822581@qq.com> Date: Fri, 20 Sep 2024 19:58:11 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E8=8B=B1=E6=96=87?= =?UTF-8?q?=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gxzmf <279822581@qq.com> --- OAT.xml | 4 +- README.en.md | 139 +++++++++++++++++++++++++-------------------------- 2 files changed, 70 insertions(+), 73 deletions(-) diff --git a/OAT.xml b/OAT.xml index 37b7254e6c..a1e1a7950d 100644 --- a/OAT.xml +++ b/OAT.xml @@ -143,11 +143,11 @@ used to filter file path. - + - + diff --git a/README.en.md b/README.en.md index 05c88e755f..12a823f553 100644 --- a/README.en.md +++ b/README.en.md @@ -1,124 +1,121 @@ Flutter Engine ============== -Original warehouse source: https://github.com/flutter/engine +Source of the original repository: https://github.com/flutter/engine -## Warehouse description: -This warehouse is based on the extension of Flutter's official engine warehouse and can build a Flutter engine program that supports running on OpenHarmony devices. +## Repository Description +This repository is an extension of the Flutter engine repository. It enables Flutter engine to run on OpenHarmony devices. -## Build instructions: +## How to Build * Build environment: -1. Supports building in Linux and Mac, mainly building gen_snapshot for Window environment; +1. Linux or macOS that support Flutter engine; Windows that supports **gen_snapshot**. +2. Access to the **allowed_hosts** field in the DEPS file. -2. Please ensure that the current build environment can access the allowed_hosts field configured in the DEPS file. +* Build steps: +1. Set up a basic environment. For details, see the [official document](https://github.com/flutter/flutter/wiki/Setting-up-the-Engine-development-environment). -* Building steps: -1. Build a basic environment: please refer to the [official](https://github.com/flutter/flutter/wiki/Setting-up-the-Engine-development-environment) website; - - Basic libraries that need to be installed: + The following libraries need to be installed: ``` - sudo apt install python3 - sudo apt install pkg-config - sudo apt install ninja-build + sudo apt install python3 + sudo apt install pkg-config + sudo apt install ninja-build ``` - Configure node: Download `node` and unzip it, and configure it into environment variables: + Configure `node`. Specifically, download `node`, unzip it, and configure it into environment variables. ``` - # nodejs - export NODE_HOME=/home//env/node-v14.19.1-linux-x64 - export PATH=$NODE_HOME/bin:$PATH + # nodejs + export NODE_HOME=/home//env/node-v14.19.1-linux-x64 + export PATH=$NODE_HOME/bin:$PATH ``` - for Window environment: - Refer to [official](https://github.com/flutter/flutter/wiki/Compiling-the-engine#compiling-for-windows) - The "Compiling for Windows" section sets up the Windows build environment + For Windows: + Refer to the section "Compiling for Windows" + in the [official document](https://github.com/flutter/flutter/wiki/Compiling-the-engine#compiling-for-windows). + -2. Configuration file: Create an empty folder engine, create a new `.gclient` file in the engine, and edit the file: +2. Configure the file. Specifically, create an empty folder **engine**, create the **.gclient** file in this folder, and edit the file. ``` - solutions = [ - { - "managed": False, - "name": "src/flutter", - "url": "git@gitee.com:openharmony-sig/flutter_engine.git", - "custom_deps": {}, - "deps_file": "DEPS", - "safesync_url": "", - }, - ] + solutions = [ + { + "managed": False, + "name": "src/flutter", + "url": "git@gitee.com:openharmony-sig/flutter_engine.git", + "custom_deps": {}, + "deps_file": "DEPS", + "safesync_url": "", + }, + ] ``` -3. Synchronize code: In the engine directory, execute `gclient sync`; here the engine source code, official packages repository will be synchronized, and the ohos_setup task will be executed; +3. Synchronize the code. In the **engine** directory, execute `gclient sync`. The engine source code and packages repository will be synchronized, and the **ohos_setup** task will be executed. -4. Download sdk: From [OpenHarmony SDK](https://developer.huawei.com/consumer/cn/develop)Download the matching development tool,Suites that are not downloaded through this channel are not supported +4. Download the SDK. Download the supporting development kits from [HarmonyOS SDK](https://developer.huawei.com/consumer/en/develop). Suites downloaded from other platforms are not supported. ```sh - # Environment variables that need to be set: HarmonyOS SDK, ohpm, hvigor, node - export TOOL_HOME=/Applications/DevEco-Studio.app/Contents # For mac - export DEVECO_SDK_HOME=$TOOL_HOME/sdk # command-line-tools/sdk - export PATH=$TOOL_HOME/tools/ohpm/bin:$PATH # command-line-tools/ohpm/bin - export PATH=$TOOL_HOME/tools/hvigor/bin:$PATH # command-line-tools/hvigor/bin - export PATH=$TOOL_HOME/tools/node/bin:$PATH # command-line-tools/tool/node/bin + # Environment variables to set: HarmonyOS SDK, ohpm, hvigor, and node. + export TOOL_HOME=/Applications/DevEco-Studio.app/Contents # macOS environment + export DEVECO_SDK_HOME=$TOOL_HOME/sdk # command-line-tools/sdk + export PATH=$TOOL_HOME/tools/ohpm/bin:$PATH # command-line-tools/ohpm/bin + export PATH=$TOOL_HOME/tools/hvigor/bin:$PATH # command-line-tools/ hvigor/bin + export PATH=$TOOL_HOME/tools/node/bin:$PATH # command-line-tools/tool/node/bin ``` -5. Start building: In the engine directory, execute `./ohos` to start building the flutter engine that supports ohos devices. +5. Start building. In the **engine** directory, execute `./ohos` to start building the Flutter engine that supports ohos devices. -6. Update code: In the engine directory, execute `./ohos -b master` +6. Update the code. In the **engine** directory, execute `./ohos -b master`. -## Engine Construction product +## Engine Build Products - [Construction product](https://docs.qq.com/sheet/DUnljRVBYUWZKZEtF?tab=BB08J2) + See [Build Products](https://docs.qq.com/sheet/DUnljRVBYUWZKZEtF?tab=BB08J2). -## 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 +## FAQs +1. The message `Member notfound:'isOhos'` is reported during project running.
Install all dart patches 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 patches). Recompile the engine after installing the patches. -2. Prompt Permission denied: Execute chmod +x