diff --git a/fml/platform/ohos/message_loop_ohos.cc b/fml/platform/ohos/message_loop_ohos.cc index 5e528abe9991ce6d8d7a6b48d4ca7be19db9532a..c918e9e66ccc861f3218867f7bc9b90fdd76148a 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 fe4b58e228ef4cdf8343db3b0386052ec6843a9f..b54f8a6bc8093f725477daf759e40bf84d12d273 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 @@ -165,13 +165,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 2e0af9081903b8bdb9c67f2fbe91c2af5647f1e5..32d2ed1ef8d0f420c4c0af25ca01194e299d1923 100644 --- a/shell/platform/ohos/ohos_touch_processor.cpp +++ b/shell/platform/ohos/ohos_touch_processor.cpp @@ -14,8 +14,10 @@ */ #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 +153,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; @@ -181,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; @@ -197,6 +199,21 @@ 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", 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) +{ int numPoints = touchEvent->numPoints; float tiltX = 0.0; float tiltY = 0.0; @@ -211,8 +228,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 1f59bd16a98b0f171a2ef36c62d774cbc7315e92..892bd672939a038bb718bb7e17b87afb10f9f61a 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 9647a882c9f76c6462209a412cf4150683b4ccdc..4285b3d8fd7824ebad4dcdf8d8962f565bdc4490 100644 --- a/shell/platform/ohos/platform_view_ohos.cpp +++ b/shell/platform/ohos/platform_view_ohos.cpp @@ -586,6 +586,33 @@ void PlatformViewOHOS::OnTouchEvent( 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) : context_(context), texture_id_(texture_id) {} diff --git a/shell/platform/ohos/platform_view_ohos.h b/shell/platform/ohos/platform_view_ohos.h index cca65a2fc5f4b1d5d9c423a60a8d3600c5dae33d..8e1b233b3b069218dfa94f6fb2f6872968a03def 100644 --- a/shell/platform/ohos/platform_view_ohos.h +++ b/shell/platform/ohos/platform_view_ohos.h @@ -40,6 +40,13 @@ namespace flutter { +enum class OHOS_THREAD_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, @@ -130,8 +137,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_;