From 6aa43c75e2319901ccd1b6ba486dd42f47d6bb13 Mon Sep 17 00:00:00 2001 From: keminLuo Date: Tue, 19 Nov 2024 09:59:51 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E8=A7=A3=E5=86=B3updateViewportMetrics?= =?UTF-8?q?=E9=A2=91=E7=B9=81=E8=B0=83=E7=94=A8=EF=BC=9B=E6=96=B0=E5=A2=9E?= =?UTF-8?q?trace=E8=B7=9F=E8=B8=AA=E4=B8=BB=E7=BA=BF=E7=A8=8B=E5=92=8CUI?= =?UTF-8?q?=E7=BA=BF=E7=A8=8B=E8=A7=A6=E6=91=B8=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: keminLuo --- fml/platform/ohos/message_loop_ohos.cc | 2 +- .../flutter/src/main/ets/view/FlutterView.ets | 10 ++++--- shell/platform/ohos/ohos_touch_processor.cpp | 8 ++++++ shell/platform/ohos/platform_view_ohos.cpp | 27 +++++++++++++++++++ shell/platform/ohos/platform_view_ohos.h | 10 +++++++ 5 files changed, 52 insertions(+), 5 deletions(-) diff --git a/fml/platform/ohos/message_loop_ohos.cc b/fml/platform/ohos/message_loop_ohos.cc index 5e528abe99..c918e9e66c 100644 --- a/fml/platform/ohos/message_loop_ohos.cc +++ b/fml/platform/ohos/message_loop_ohos.cc @@ -33,7 +33,7 @@ void MessageLoopOhos::OnPollCallback(uv_poll_t* handle, int status, int events) { if (status < 0) { - FML_DLOG(ERROR) << "Poll error:" << uv_strerror(status); + FML_LOG(ERROR) << "Poll error:" << uv_strerror(status); return; } 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 7c88fdec45..26889cc34b 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 @@ -158,13 +158,15 @@ export class FlutterView { this.gestureAvoidArea = this.mainWindow?.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM_GESTURE); this.keyboardAvoidArea = this.mainWindow?.getWindowAvoidArea(window.AvoidAreaType.TYPE_KEYBOARD); - //监听系统设置显示大小改变 + // Subscribes to display changes. Example: event that the display size is changed. try { display.on("change", ()=>{ this.displayInfo = display.getDefaultDisplaySync(); - this.viewportMetrics.devicePixelRatio = this.displayInfo?.densityPixels; - Log.i(TAG, "Display on: " + JSON.stringify(this.displayInfo)) - this.updateViewportMetrics() + if (this.viewportMetrics.devicePixelRatio != this.displayInfo?.densityPixels) { + this.viewportMetrics.devicePixelRatio = this.displayInfo?.densityPixels; + Log.i(TAG, "Display on: " + JSON.stringify(this.displayInfo)) + this.updateViewportMetrics() + } }); } catch (e) { Log.e(TAG, "displayInfo error" + JSON.stringify(e)); diff --git a/shell/platform/ohos/ohos_touch_processor.cpp b/shell/platform/ohos/ohos_touch_processor.cpp index 2e0af90819..c5cb4c697d 100644 --- a/shell/platform/ohos/ohos_touch_processor.cpp +++ b/shell/platform/ohos/ohos_touch_processor.cpp @@ -16,6 +16,7 @@ #include "flutter/shell/platform/ohos/ohos_touch_processor.h" #include "flutter/lib/ui/window/pointer_data_packet.h" #include "flutter/shell/platform/ohos/ohos_shell_holder.h" +#include "flutter/fml/trace_event.h" namespace flutter { @@ -151,6 +152,7 @@ void OhosTouchProcessor::HandleTouchEvent( if (touchEvent == nullptr) { return; } + FML_TRACE_EVENT("flutter", "HandleTouchEvent", "timeStamp", touchEvent->timeStamp); const int numTouchPoints = 1; std::unique_ptr packet = std::make_unique(numTouchPoints); PointerData pointerData; @@ -197,6 +199,12 @@ void OhosTouchProcessor::HandleTouchEvent( ohos_shell_holder->GetPlatformView()->DispatchPointerDataPacket( std::move(packet)); + // For DFX + fml::closure task = [timeStampDFX = touchEvent->timeStamp](void){ + FML_TRACE_EVENT("flutter", "HandleTouchEventUI", "timeStamp", touchEvent->timeStamp); + }; + ohos_shell_holder->GetPlatformView()->RunTask(OHOS_THREAD_TYPE::OHOS_THREAD_TYPE_UI, task); + int numPoints = touchEvent->numPoints; float tiltX = 0.0; float tiltY = 0.0; diff --git a/shell/platform/ohos/platform_view_ohos.cpp b/shell/platform/ohos/platform_view_ohos.cpp index adc8d5ec3d..af274ce75a 100644 --- a/shell/platform/ohos/platform_view_ohos.cpp +++ b/shell/platform/ohos/platform_view_ohos.cpp @@ -577,6 +577,33 @@ void PlatformViewOHOS::OnTouchEvent(const std::shared_ptr touchPa return napi_facade_->FlutterViewOnTouchEvent(touchPacketString, size); } +void PlatformViewOHOS::RunTask(OHOS_THREAD_TYPE type, const fml::closure& task) +{ + fml::RefPtr TaskRunnerPtr = nullptr; + switch(type) { + case OHOS_THREAD_TYPE::OHOS_THREAD_TYPE_PLATFORM: + TaskRunnerPtr = task_runners_.GetPlatformTaskRunner(); + break; + case OHOS_THREAD_TYPE::OHOS_THREAD_TYPE_UI: + TaskRunnerPtr = task_runners_.GetUITaskRunner(); + break; + case OHOS_THREAD_TYPE::OHOS_THREAD_TYPE_RASTER: + TaskRunnerPtr = task_runners_.GetRasterTaskRunner(); + break; + case OHOS_THREAD_TYPE::OHOS_THREAD_TYPE_IO: + TaskRunnerPtr = task_runners_.GetIOTaskRunner(); + break; + default: + break; + } + + if (!TaskRunnerPtr) { + return; + } + + fml::TaskRunner::RunNowOrPostTask(TaskRunnerPtr, task); +} + OhosImageFrameData::OhosImageFrameData( PlatformViewOHOS* context, int64_t texture_id) diff --git a/shell/platform/ohos/platform_view_ohos.h b/shell/platform/ohos/platform_view_ohos.h index 14c60e884c..bcf1ffc053 100644 --- a/shell/platform/ohos/platform_view_ohos.h +++ b/shell/platform/ohos/platform_view_ohos.h @@ -38,6 +38,13 @@ namespace flutter { +enum OHOS_THREAD_TYPE_TYPE { + OHOS_THREAD_TYPE_PLATFORM, + OHOS_THREAD_TYPE_UI, + OHOS_THREAD_TYPE_RASTER, + OHOS_THREAD_TYPE_IO, +}; + class OhosSurfaceFactoryImpl : public OhosSurfaceFactory { public: OhosSurfaceFactoryImpl(const std::shared_ptr& context, @@ -128,8 +135,11 @@ class PlatformViewOHOS final : public PlatformView { const override { return platform_message_handler_; } + void OnTouchEvent(std::shared_ptr touchPacketString, int size); + void RunTask(OHOS_THREAD_TYPE type, const fml::closure& task); + private: const std::shared_ptr napi_facade_; std::shared_ptr ohos_context_; -- Gitee From 9508d58c9946d12a98f0e0d8af161cc74551b18e Mon Sep 17 00:00:00 2001 From: keminLuo Date: Tue, 19 Nov 2024 22:05:38 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=A7=A3=E5=86=B3updateViewportMetrics?= =?UTF-8?q?=E9=A2=91=E7=B9=81=E8=B0=83=E7=94=A8=EF=BC=9B=E6=96=B0=E5=A2=9E?= =?UTF-8?q?trace=E8=B7=9F=E8=B8=AA=E4=B8=BB=E7=BA=BF=E7=A8=8B=E5=92=8CUI?= =?UTF-8?q?=20=E7=BA=BF=E7=A8=8B=E8=A7=A6=E6=91=B8=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: keminLuo --- shell/platform/ohos/ohos_touch_processor.cpp | 14 ++++-- shell/platform/ohos/ohos_touch_processor.h | 51 +++++++++++--------- shell/platform/ohos/platform_view_ohos.cpp | 2 +- shell/platform/ohos/platform_view_ohos.h | 2 +- 4 files changed, 40 insertions(+), 29 deletions(-) diff --git a/shell/platform/ohos/ohos_touch_processor.cpp b/shell/platform/ohos/ohos_touch_processor.cpp index c5cb4c697d..73ace2d742 100644 --- a/shell/platform/ohos/ohos_touch_processor.cpp +++ b/shell/platform/ohos/ohos_touch_processor.cpp @@ -14,6 +14,7 @@ */ #include "flutter/shell/platform/ohos/ohos_touch_processor.h" + #include "flutter/lib/ui/window/pointer_data_packet.h" #include "flutter/shell/platform/ohos/ohos_shell_holder.h" #include "flutter/fml/trace_event.h" @@ -183,7 +184,6 @@ void OhosTouchProcessor::HandleTouchEvent( pointerData.change == PointerData::Change::kMove) { pointerData.buttons = kPointerButtonTouchContact; } - } else if (pointerData.kind == PointerData::DeviceKind::kMouse) { } pointerData.pan_x = 0.0; pointerData.pan_y = 0.0; @@ -200,11 +200,19 @@ void OhosTouchProcessor::HandleTouchEvent( std::move(packet)); // For DFX - fml::closure task = [timeStampDFX = touchEvent->timeStamp](void){ + fml::closure task = [timeStampDFX = touchEvent->timeStamp](void) { FML_TRACE_EVENT("flutter", "HandleTouchEventUI", "timeStamp", touchEvent->timeStamp); }; ohos_shell_holder->GetPlatformView()->RunTask(OHOS_THREAD_TYPE::OHOS_THREAD_TYPE_UI, task); + PlatformViewOnTouchEvent(shell_holderID, toolType, component, touchEvent); +} + +void OhosTouchProcessor::PlatformViewOnTouchEvent(int64_t shellHolderID, + OH_NativeXComponent_TouchPointToolType toolType, + OH_NativeXComponent* component, + OH_NativeXComponent_TouchEvent* touchEvent) +{ int numPoints = touchEvent->numPoints; float tiltX = 0.0; float tiltY = 0.0; @@ -219,8 +227,8 @@ void OhosTouchProcessor::HandleTouchEvent( std::shared_ptr touchPacketString = packagePacketData(std::move(touchPacket)); int size = CHANGES_POINTER_MEMBER + PER_POINTER_MEMBER * numPoints + TOUCH_EVENT_ADDITIONAL_ATTRIBUTES; + auto ohos_shell_holder = reinterpret_cast(shellHolderID); ohos_shell_holder->GetPlatformView()->OnTouchEvent(touchPacketString, size); - return; } void OhosTouchProcessor::HandleMouseEvent( diff --git a/shell/platform/ohos/ohos_touch_processor.h b/shell/platform/ohos/ohos_touch_processor.h index 1f59bd16a9..892bd67293 100644 --- a/shell/platform/ohos/ohos_touch_processor.h +++ b/shell/platform/ohos/ohos_touch_processor.h @@ -24,7 +24,7 @@ namespace flutter { class OhosTouchProcessor { - public: +public: typedef struct { OH_NativeXComponent_TouchEvent* touchEventInput; OH_NativeXComponent_TouchPointToolType toolTypeInput; @@ -32,32 +32,35 @@ class OhosTouchProcessor { float tiltY; } TouchPacket; - public: - void HandleTouchEvent(int64_t shell_holderID, - OH_NativeXComponent* component, - OH_NativeXComponent_TouchEvent* touchEvent); - void HandleMouseEvent(int64_t shell_holderID, - 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); - flutter::PointerData::Change getPointerChangeForMouseAction( - OH_NativeXComponent_MouseEventAction mouseAction); - PointerButtonMouse getPointerButtonFromMouse( - OH_NativeXComponent_MouseEventButton mouseButton); +public: + void HandleTouchEvent(int64_t shell_holderID, + OH_NativeXComponent* component, + OH_NativeXComponent_TouchEvent* touchEvent); + void HandleMouseEvent(int64_t shell_holderID, + 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); + flutter::PointerData::Change getPointerChangeForMouseAction( + OH_NativeXComponent_MouseEventAction mouseAction); + PointerButtonMouse getPointerButtonFromMouse( + OH_NativeXComponent_MouseEventButton mouseButton); - private: - std::shared_ptr packagePacketData(std::unique_ptr touchPacket); +public: + OH_NativeXComponent_TouchPointToolType touchType_; - public: - OH_NativeXComponent_TouchPointToolType touchType_; +private: + std::shared_ptr packagePacketData(std::unique_ptr touchPacket); - private: + void PlatformViewOnTouchEvent(int64_t shellHolderID, + OH_NativeXComponent_TouchPointToolType toolType, + OH_NativeXComponent* component, + OH_NativeXComponent_TouchEvent* touchEvent); }; } // namespace flutter #endif // XComponent_OhosTouchProcessor_H \ 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 af274ce75a..f2aa040bc2 100644 --- a/shell/platform/ohos/platform_view_ohos.cpp +++ b/shell/platform/ohos/platform_view_ohos.cpp @@ -580,7 +580,7 @@ void PlatformViewOHOS::OnTouchEvent(const std::shared_ptr touchPa void PlatformViewOHOS::RunTask(OHOS_THREAD_TYPE type, const fml::closure& task) { fml::RefPtr TaskRunnerPtr = nullptr; - switch(type) { + switch (type) { case OHOS_THREAD_TYPE::OHOS_THREAD_TYPE_PLATFORM: TaskRunnerPtr = task_runners_.GetPlatformTaskRunner(); break; diff --git a/shell/platform/ohos/platform_view_ohos.h b/shell/platform/ohos/platform_view_ohos.h index bcf1ffc053..0d46543c51 100644 --- a/shell/platform/ohos/platform_view_ohos.h +++ b/shell/platform/ohos/platform_view_ohos.h @@ -38,7 +38,7 @@ namespace flutter { -enum OHOS_THREAD_TYPE_TYPE { +enum class OHOS_THREAD_TYPE { OHOS_THREAD_TYPE_PLATFORM, OHOS_THREAD_TYPE_UI, OHOS_THREAD_TYPE_RASTER, -- Gitee From 82e87bcc4fcfb778a43a7d3b32691af6a1a7bb67 Mon Sep 17 00:00:00 2001 From: keminLuo Date: Wed, 20 Nov 2024 09:56:45 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E8=AF=AD=E6=B3=95=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: keminLuo --- shell/platform/ohos/ohos_touch_processor.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/shell/platform/ohos/ohos_touch_processor.cpp b/shell/platform/ohos/ohos_touch_processor.cpp index 73ace2d742..32d2ed1ef8 100644 --- a/shell/platform/ohos/ohos_touch_processor.cpp +++ b/shell/platform/ohos/ohos_touch_processor.cpp @@ -201,17 +201,18 @@ void OhosTouchProcessor::HandleTouchEvent( // For DFX fml::closure task = [timeStampDFX = touchEvent->timeStamp](void) { - FML_TRACE_EVENT("flutter", "HandleTouchEventUI", "timeStamp", touchEvent->timeStamp); + FML_TRACE_EVENT("flutter", "HandleTouchEventUI", "timeStamp", timeStampDFX); }; ohos_shell_holder->GetPlatformView()->RunTask(OHOS_THREAD_TYPE::OHOS_THREAD_TYPE_UI, task); PlatformViewOnTouchEvent(shell_holderID, toolType, component, touchEvent); } -void OhosTouchProcessor::PlatformViewOnTouchEvent(int64_t shellHolderID, - OH_NativeXComponent_TouchPointToolType toolType, - OH_NativeXComponent* component, - OH_NativeXComponent_TouchEvent* touchEvent) +void OhosTouchProcessor::PlatformViewOnTouchEvent( + int64_t shellHolderID, + OH_NativeXComponent_TouchPointToolType toolType, + OH_NativeXComponent* component, + OH_NativeXComponent_TouchEvent* touchEvent) { int numPoints = touchEvent->numPoints; float tiltX = 0.0; -- Gitee