From 61301fb9f3e598eb9f08bcd591b40e9eb030438d Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Mon, 25 Oct 2021 15:25:48 +0900 Subject: [PATCH 001/112] Merge the latest cpp shared common source file from flutter/engine repo (#232) Merged from https://github.com/flutter/engine/pull/29270 --- src/flutter/shell/platform/common/json_message_codec.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/flutter/shell/platform/common/json_message_codec.cc b/src/flutter/shell/platform/common/json_message_codec.cc index b91e57e4..ae362f73 100644 --- a/src/flutter/shell/platform/common/json_message_codec.cc +++ b/src/flutter/shell/platform/common/json_message_codec.cc @@ -37,9 +37,7 @@ std::unique_ptr JsonMessageCodec::DecodeMessageInternal( auto json_message = std::make_unique(); rapidjson::ParseResult result = json_message->Parse(raw_message, message_size); - bool parsing_successful = - result == rapidjson::ParseErrorCode::kParseErrorNone; - if (!parsing_successful) { + if (result.IsError()) { std::cerr << "Unable to parse JSON message:" << std::endl << rapidjson::GetParseError_En(result.Code()) << std::endl; return nullptr; From be0a03f403cd78cf8299797818e56c4a1b362259 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Thu, 28 Oct 2021 11:07:00 +0900 Subject: [PATCH 002/112] Add verifying code format (#233) - Reformat source code files by clang-format - Add code format check in GitHub actions --- .github/workflows/build-test.yml | 6 + src/client_wrapper/flutter_view_controller.cc | 3 +- .../platform/linux_embedded/flutter_elinux.cc | 18 +- .../linux_embedded/flutter_elinux_engine.cc | 18 +- .../linux_embedded/flutter_elinux_engine.h | 6 +- .../flutter_elinux_texture_registrar.h | 4 +- .../linux_embedded/flutter_elinux_view.cc | 40 ++- .../linux_embedded/flutter_elinux_view.h | 22 +- .../plugins/key_event_plugin.cc | 16 +- .../linux_embedded/plugins/key_event_plugin.h | 10 +- .../plugins/lifecycle_plugin.cc | 4 +- .../plugins/mouse_cursor_plugin.cc | 4 +- .../plugins/navigation_plugin.cc | 4 +- .../linux_embedded/plugins/platform_plugin.cc | 4 +- .../plugins/platform_views_plugin.cc | 3 +- .../plugins/text_input_plugin.cc | 4 +- .../public/flutter_platform_views.h | 7 +- .../linux_embedded/surface/context_egl.cc | 4 +- .../surface/elinux_egl_surface.cc | 7 +- .../surface/surface_decoration.cc | 8 +- .../linux_embedded/surface/surface_gl.cc | 4 +- .../platform/linux_embedded/task_runner.cc | 4 +- .../platform/linux_embedded/task_runner.h | 3 +- .../linux_embedded/window/elinux_window_drm.h | 12 +- .../window/elinux_window_wayland.cc | 260 +++++++++++++----- .../window/elinux_window_wayland.h | 6 +- .../window/elinux_window_x11.cc | 15 +- .../linux_embedded/window/elinux_window_x11.h | 4 +- .../linux_embedded/window/native_window_drm.h | 3 +- .../window/native_window_drm_eglstream.cc | 10 +- .../window/native_window_drm_eglstream.h | 7 +- .../window/native_window_drm_gbm.cc | 3 +- .../window/native_window_drm_gbm.h | 3 +- .../window/native_window_wayland.h | 3 +- .../native_window_wayland_decoration.cc | 7 +- .../window/native_window_wayland_decoration.h | 3 +- .../window/native_window_x11.cc | 6 +- .../linux_embedded/window/native_window_x11.h | 4 +- .../renderer/window_decorations_wayland.cc | 11 +- .../renderer/window_decorations_wayland.h | 6 +- .../window_binding_handler_delegate.h | 17 +- 41 files changed, 414 insertions(+), 169 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index b4a834fe..ddd680ed 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -16,8 +16,14 @@ jobs: - name: Install libraries run: | sudo apt update + sudo apt install clang-format sudo apt install libgles2-mesa-dev libegl1-mesa-dev libxkbcommon-dev libwayland-dev libdrm-dev libgbm-dev libinput-dev libudev-dev libsystemd-dev wayland-protocols libx11-dev + - name: Verify formatting + run: | + find src/flutter/shell/platform/linux_embedded/ -iname *.h -o -iname *.cc | xargs clang-format --dry-run --Werror + find src/client_wrapper -iname *.h -o -iname *.cc | xargs clang-format --dry-run --Werror + - name: Create Build Environment run: cmake -E make_directory ${{github.workspace}}/build diff --git a/src/client_wrapper/flutter_view_controller.cc b/src/client_wrapper/flutter_view_controller.cc index afd61d08..e7b52622 100644 --- a/src/client_wrapper/flutter_view_controller.cc +++ b/src/client_wrapper/flutter_view_controller.cc @@ -10,7 +10,8 @@ namespace flutter { FlutterViewController::FlutterViewController( - const ViewProperties& view_properties, const DartProject& project) { + const ViewProperties& view_properties, + const DartProject& project) { engine_ = std::make_unique(project); FlutterDesktopViewProperties c_view_properties = {}; diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux.cc index e8633d10..1279155b 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux.cc @@ -160,7 +160,8 @@ void FlutterDesktopEngineReloadSystemFonts(FlutterDesktopEngineRef engine) { } FlutterDesktopPluginRegistrarRef FlutterDesktopEngineGetPluginRegistrar( - FlutterDesktopEngineRef engine, const char* plugin_name) { + FlutterDesktopEngineRef engine, + const char* plugin_name) { // Currently, one registrar acts as the registrar for all plugins, so the // name is ignored. It is part of the API to reduce churn in the future when // aligning more closely with the Flutter registrar system. @@ -208,7 +209,8 @@ bool FlutterDesktopMessengerSendWithReply(FlutterDesktopMessengerRef messenger, } bool FlutterDesktopMessengerSend(FlutterDesktopMessengerRef messenger, - const char* channel, const uint8_t* message, + const char* channel, + const uint8_t* message, const size_t message_size) { return FlutterDesktopMessengerSendWithReply(messenger, channel, message, message_size, nullptr, nullptr); @@ -216,7 +218,8 @@ bool FlutterDesktopMessengerSend(FlutterDesktopMessengerRef messenger, void FlutterDesktopMessengerSendResponse( FlutterDesktopMessengerRef messenger, - const FlutterDesktopMessageResponseHandle* handle, const uint8_t* data, + const FlutterDesktopMessageResponseHandle* handle, + const uint8_t* data, size_t data_length) { messenger->engine->SendPlatformMessageResponse(handle, data, data_length); } @@ -242,19 +245,22 @@ int64_t FlutterDesktopTextureRegistrarRegisterExternalTexture( } bool FlutterDesktopTextureRegistrarUnregisterExternalTexture( - FlutterDesktopTextureRegistrarRef texture_registrar, int64_t texture_id) { + FlutterDesktopTextureRegistrarRef texture_registrar, + int64_t texture_id) { return TextureRegistrarFromHandle(texture_registrar) ->UnregisterTexture(texture_id); } bool FlutterDesktopTextureRegistrarMarkExternalTextureFrameAvailable( - FlutterDesktopTextureRegistrarRef texture_registrar, int64_t texture_id) { + FlutterDesktopTextureRegistrarRef texture_registrar, + int64_t texture_id) { return TextureRegistrarFromHandle(texture_registrar) ->MarkTextureFrameAvailable(texture_id); } void FlutterDesktopRegisterPlatformViewFactory( - FlutterDesktopPluginRegistrarRef registrar, const char* view_type, + FlutterDesktopPluginRegistrarRef registrar, + const char* view_type, std::unique_ptr view_factory) { registrar->engine->view()->RegisterPlatformViewFactory( view_type, std::move(view_factory)); diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc index 13c69c39..033cc3d5 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc @@ -139,7 +139,9 @@ FlutterELinuxEngine::FlutterELinuxEngine(const FlutterProjectBundle& project) vsync_waiter_ = std::make_unique(); } -FlutterELinuxEngine::~FlutterELinuxEngine() { Stop(); } +FlutterELinuxEngine::~FlutterELinuxEngine() { + Stop(); +} bool FlutterELinuxEngine::RunWithEntrypoint(const char* entrypoint) { if (!project_->HasValidPaths()) { @@ -263,7 +265,9 @@ bool FlutterELinuxEngine::Stop() { return false; } -void FlutterELinuxEngine::SetView(FlutterELinuxView* view) { view_ = view; } +void FlutterELinuxEngine::SetView(FlutterELinuxView* view) { + view_ = view; +} // Returns the currently configured Plugin Registrar. FlutterDesktopPluginRegistrarRef FlutterELinuxEngine::GetRegistrar() { @@ -289,8 +293,11 @@ void FlutterELinuxEngine::SendPointerEvent(const FlutterPointerEvent& event) { } bool FlutterELinuxEngine::SendPlatformMessage( - const char* channel, const uint8_t* message, const size_t message_size, - const FlutterDesktopBinaryReply reply, void* user_data) { + const char* channel, + const uint8_t* message, + const size_t message_size, + const FlutterDesktopBinaryReply reply, + void* user_data) { FlutterPlatformMessageResponseHandle* response_handle = nullptr; if (reply != nullptr && user_data != nullptr) { FlutterEngineResult result = @@ -320,7 +327,8 @@ bool FlutterELinuxEngine::SendPlatformMessage( } void FlutterELinuxEngine::SendPlatformMessageResponse( - const FlutterDesktopMessageResponseHandle* handle, const uint8_t* data, + const FlutterDesktopMessageResponseHandle* handle, + const uint8_t* data, size_t data_length) { embedder_api_.SendPlatformMessageResponse(engine_, handle, data, data_length); } diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h index 9824e5cc..11a378b6 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h @@ -84,14 +84,16 @@ class FlutterELinuxEngine { // Sends the given message to the engine, calling |reply| with |user_data| // when a reponse is received from the engine if they are non-null. - bool SendPlatformMessage(const char* channel, const uint8_t* message, + bool SendPlatformMessage(const char* channel, + const uint8_t* message, const size_t message_size, const FlutterDesktopBinaryReply reply, void* user_data); // Sends the given data as the response to an earlier platform message. void SendPlatformMessageResponse( - const FlutterDesktopMessageResponseHandle* handle, const uint8_t* data, + const FlutterDesktopMessageResponseHandle* handle, + const uint8_t* data, size_t data_length); // Callback passed to Flutter engine for notifying window of platform diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_texture_registrar.h b/src/flutter/shell/platform/linux_embedded/flutter_elinux_texture_registrar.h index 511f2cb5..0b46a1fa 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_texture_registrar.h +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_texture_registrar.h @@ -36,7 +36,9 @@ class FlutterELinuxTextureRegistrar { // Attempts to populate the given |texture| by copying the // contents of the texture identified by |texture_id|. // Returns true on success. - bool PopulateTexture(int64_t texture_id, size_t width, size_t height, + bool PopulateTexture(int64_t texture_id, + size_t width, + size_t height, FlutterOpenGLTexture* texture); private: diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc index e7929acd..9a85b6a9 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc @@ -82,7 +82,9 @@ void FlutterELinuxView::OnPointerMove(double x, double y) { } void FlutterELinuxView::OnPointerDown( - double x, double y, FlutterPointerMouseButtons flutter_button) { + double x, + double y, + FlutterPointerMouseButtons flutter_button) { if (flutter_button != 0) { uint64_t mouse_buttons = mouse_state_.buttons | flutter_button; SetMouseButtons(mouse_buttons); @@ -90,7 +92,8 @@ void FlutterELinuxView::OnPointerDown( } } -void FlutterELinuxView::OnPointerUp(double x, double y, +void FlutterELinuxView::OnPointerUp(double x, + double y, FlutterPointerMouseButtons flutter_button) { if (flutter_button != 0) { uint64_t mouse_buttons = mouse_state_.buttons & ~flutter_button; @@ -99,9 +102,13 @@ void FlutterELinuxView::OnPointerUp(double x, double y, } } -void FlutterELinuxView::OnPointerLeave() { SendPointerLeave(); } +void FlutterELinuxView::OnPointerLeave() { + SendPointerLeave(); +} -void FlutterELinuxView::OnTouchDown(uint32_t time, int32_t id, double x, +void FlutterELinuxView::OnTouchDown(uint32_t time, + int32_t id, + double x, double y) { auto* point = GgeTouchPoint(id); if (!point) { @@ -150,7 +157,9 @@ void FlutterELinuxView::OnTouchUp(uint32_t time, int32_t id) { engine_->SendPointerEvent(event); } -void FlutterELinuxView::OnTouchMotion(uint32_t time, int32_t id, double x, +void FlutterELinuxView::OnTouchMotion(uint32_t time, + int32_t id, + double x, double y) { auto* point = GgeTouchPoint(id); if (!point) { @@ -194,7 +203,8 @@ void FlutterELinuxView::OnKey(uint32_t key, bool pressed) { void FlutterELinuxView::OnKeyModifiers(uint32_t mods_depressed, uint32_t mods_latched, - uint32_t mods_locked, uint32_t group) { + uint32_t mods_locked, + uint32_t group) { keyboard_handler_->OnModifiers(mods_depressed, mods_latched, mods_locked, group); } @@ -210,8 +220,11 @@ void FlutterELinuxView::OnVirtualSpecialKey(uint32_t keycode) { textinput_handler_->OnKeyPressed(keycode, code_point); } -void FlutterELinuxView::OnScroll(double x, double y, double delta_x, - double delta_y, int scroll_offset_multiplier) { +void FlutterELinuxView::OnScroll(double x, + double y, + double delta_x, + double delta_y, + int scroll_offset_multiplier) { SendScroll(x, y, delta_x, delta_y, scroll_offset_multiplier); } @@ -240,7 +253,8 @@ FlutterELinuxView::touch_point* FlutterELinuxView::GgeTouchPoint(int32_t id) { } // Sends new size information to FlutterEngine. -void FlutterELinuxView::SendWindowMetrics(size_t width, size_t height, +void FlutterELinuxView::SendWindowMetrics(size_t width, + size_t height, double dpiScale) const { FlutterWindowMetricsEvent event = {}; event.struct_size = sizeof(event); @@ -304,7 +318,9 @@ void FlutterELinuxView::SendPointerLeave() { SendPointerEventWithData(event); } -void FlutterELinuxView::SendScroll(double x, double y, double delta_x, +void FlutterELinuxView::SendScroll(double x, + double y, + double delta_x, double delta_y, int scroll_offset_multiplier) { FlutterPointerEvent event = {}; @@ -395,7 +411,9 @@ ELinuxRenderSurfaceTarget* FlutterELinuxView::GetRenderSurfaceTarget() const { return binding_handler_->GetRenderSurfaceTarget(); } -FlutterELinuxEngine* FlutterELinuxView::GetEngine() { return engine_.get(); } +FlutterELinuxEngine* FlutterELinuxView::GetEngine() { + return engine_.get(); +} int32_t FlutterELinuxView::GetFrameRate() { return binding_handler_->GetFrameRate(); diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.h b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.h index 68bd9396..b8e057d0 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.h +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.h @@ -85,11 +85,13 @@ class FlutterELinuxView : public WindowBindingHandlerDelegate { void OnPointerMove(double x, double y) override; // |WindowBindingHandlerDelegate| - void OnPointerDown(double x, double y, + void OnPointerDown(double x, + double y, FlutterPointerMouseButtons button) override; // |WindowBindingHandlerDelegate| - void OnPointerUp(double x, double y, + void OnPointerUp(double x, + double y, FlutterPointerMouseButtons button) override; // |WindowBindingHandlerDelegate| @@ -111,8 +113,10 @@ class FlutterELinuxView : public WindowBindingHandlerDelegate { void OnKeyMap(uint32_t format, int fd, uint32_t size) override; // |WindowBindingHandlerDelegate| - void OnKeyModifiers(uint32_t mods_depressed, uint32_t mods_latched, - uint32_t mods_locked, uint32_t group) override; + void OnKeyModifiers(uint32_t mods_depressed, + uint32_t mods_latched, + uint32_t mods_locked, + uint32_t group) override; // |WindowBindingHandlerDelegate| void OnKey(uint32_t key, bool pressed) override; @@ -124,7 +128,10 @@ class FlutterELinuxView : public WindowBindingHandlerDelegate { void OnVirtualSpecialKey(uint32_t keycode) override; // |WindowBindingHandlerDelegate| - void OnScroll(double x, double y, double delta_x, double delta_y, + void OnScroll(double x, + double y, + double delta_x, + double delta_y, int scroll_offset_multiplier) override; // |WindowBindingHandlerDelegate| @@ -193,7 +200,10 @@ class FlutterELinuxView : public WindowBindingHandlerDelegate { void SendPointerLeave(); // Reports scroll wheel events to Flutter engine. - void SendScroll(double x, double y, double delta_x, double delta_y, + void SendScroll(double x, + double y, + double delta_x, + double delta_y, int scroll_offset_multiplier); // Sets |event_data|'s phase to either kMove or kHover depending on the diff --git a/src/flutter/shell/platform/linux_embedded/plugins/key_event_plugin.cc b/src/flutter/shell/platform/linux_embedded/plugins/key_event_plugin.cc index 60b52697..dff808e2 100644 --- a/src/flutter/shell/platform/linux_embedded/plugins/key_event_plugin.cc +++ b/src/flutter/shell/platform/linux_embedded/plugins/key_event_plugin.cc @@ -41,7 +41,9 @@ constexpr char kXkboptionsKey[] = "XKBOPTIONS"; KeyeventPlugin::KeyeventPlugin(BinaryMessenger* messenger) : channel_(std::make_unique>( - messenger, kChannelName, &flutter::JsonMessageCodec::GetInstance())), + messenger, + kChannelName, + &flutter::JsonMessageCodec::GetInstance())), xkb_context_(xkb_context_new(XKB_CONTEXT_NO_FLAGS)) { #if defined(DISPLAY_BACKEND_TYPE_WAYLAND) xkb_keymap_ = nullptr; @@ -105,16 +107,20 @@ void KeyeventPlugin::OnKey(uint32_t keycode, bool pressed) { SendKeyEvent(keyscancode, unicode, mods, pressed); } -void KeyeventPlugin::OnModifiers(uint32_t mods_depressed, uint32_t mods_latched, - uint32_t mods_locked, uint32_t group) { +void KeyeventPlugin::OnModifiers(uint32_t mods_depressed, + uint32_t mods_latched, + uint32_t mods_locked, + uint32_t group) { xkb_state_update_mask(xkb_state_, mods_depressed, mods_latched, mods_locked, 0, 0, group); xkb_mods_mask_ = xkb_state_serialize_mods(xkb_state_, XKB_STATE_MODS_EFFECTIVE); } -void KeyeventPlugin::SendKeyEvent(uint32_t keycode, uint32_t unicode, - uint32_t modifiers, bool pressed) { +void KeyeventPlugin::SendKeyEvent(uint32_t keycode, + uint32_t unicode, + uint32_t modifiers, + bool pressed) { rapidjson::Document event(rapidjson::kObjectType); auto& allocator = event.GetAllocator(); event.AddMember(kKeyCodeKey, keycode, allocator); diff --git a/src/flutter/shell/platform/linux_embedded/plugins/key_event_plugin.h b/src/flutter/shell/platform/linux_embedded/plugins/key_event_plugin.h index 6de36a45..d7e4fe47 100644 --- a/src/flutter/shell/platform/linux_embedded/plugins/key_event_plugin.h +++ b/src/flutter/shell/platform/linux_embedded/plugins/key_event_plugin.h @@ -25,15 +25,19 @@ class KeyeventPlugin { void OnKey(uint32_t keycode, bool pressed); - void OnModifiers(uint32_t mods_depressed, uint32_t mods_latched, - uint32_t mods_locked, uint32_t group); + void OnModifiers(uint32_t mods_depressed, + uint32_t mods_latched, + uint32_t mods_locked, + uint32_t group); uint32_t GetCodePoint(uint32_t keycode); bool IsTextInputSuppressed(uint32_t code_point); private: - void SendKeyEvent(uint32_t keycode, uint32_t unicode, uint32_t modifiers, + void SendKeyEvent(uint32_t keycode, + uint32_t unicode, + uint32_t modifiers, bool pressed); void OnModifiers(uint32_t keycode, bool pressed); xkb_keymap* CreateKeymap(xkb_context* context); diff --git a/src/flutter/shell/platform/linux_embedded/plugins/lifecycle_plugin.cc b/src/flutter/shell/platform/linux_embedded/plugins/lifecycle_plugin.cc index 6ea582f2..59a9fc0f 100644 --- a/src/flutter/shell/platform/linux_embedded/plugins/lifecycle_plugin.cc +++ b/src/flutter/shell/platform/linux_embedded/plugins/lifecycle_plugin.cc @@ -19,7 +19,9 @@ constexpr char kDetached[] = "AppLifecycleState.detached"; LifecyclePlugin::LifecyclePlugin(BinaryMessenger* messenger) : channel_(std::make_unique>( - messenger, kChannelName, &StandardMessageCodec::GetInstance())) {} + messenger, + kChannelName, + &StandardMessageCodec::GetInstance())) {} void LifecyclePlugin::OnInactive() const { ELINUX_LOG(DEBUG) << "App lifecycle changed to inactive state."; diff --git a/src/flutter/shell/platform/linux_embedded/plugins/mouse_cursor_plugin.cc b/src/flutter/shell/platform/linux_embedded/plugins/mouse_cursor_plugin.cc index 957f71b5..af695d45 100644 --- a/src/flutter/shell/platform/linux_embedded/plugins/mouse_cursor_plugin.cc +++ b/src/flutter/shell/platform/linux_embedded/plugins/mouse_cursor_plugin.cc @@ -31,7 +31,9 @@ constexpr char kKindKey[] = "kind"; MouseCursorPlugin::MouseCursorPlugin(BinaryMessenger* messenger, WindowBindingHandler* delegate) : channel_(std::make_unique>( - messenger, kChannelName, &StandardMethodCodec::GetInstance())), + messenger, + kChannelName, + &StandardMethodCodec::GetInstance())), delegate_(delegate) { channel_->SetMethodCallHandler( [this](const MethodCall& call, diff --git a/src/flutter/shell/platform/linux_embedded/plugins/navigation_plugin.cc b/src/flutter/shell/platform/linux_embedded/plugins/navigation_plugin.cc index 35c07e02..e23b09c4 100644 --- a/src/flutter/shell/platform/linux_embedded/plugins/navigation_plugin.cc +++ b/src/flutter/shell/platform/linux_embedded/plugins/navigation_plugin.cc @@ -19,7 +19,9 @@ constexpr char kPopRouteMethod[] = "popRoute"; NavigationPlugin::NavigationPlugin(BinaryMessenger* messenger) : channel_(std::make_unique>( - messenger, kChannelName, &flutter::JsonMethodCodec::GetInstance())) {} + messenger, + kChannelName, + &flutter::JsonMethodCodec::GetInstance())) {} void NavigationPlugin::SetInitialRoute(std::string route) const { ELINUX_LOG(DEBUG) << "SetInitialRoute = " << route; diff --git a/src/flutter/shell/platform/linux_embedded/plugins/platform_plugin.cc b/src/flutter/shell/platform/linux_embedded/plugins/platform_plugin.cc index 2d6de395..7670c157 100644 --- a/src/flutter/shell/platform/linux_embedded/plugins/platform_plugin.cc +++ b/src/flutter/shell/platform/linux_embedded/plugins/platform_plugin.cc @@ -37,7 +37,9 @@ constexpr char kUnknownClipboardFormatError[] = PlatformPlugin::PlatformPlugin(BinaryMessenger* messenger, WindowBindingHandler* delegate) : channel_(std::make_unique>( - messenger, kChannelName, &flutter::JsonMethodCodec::GetInstance())), + messenger, + kChannelName, + &flutter::JsonMethodCodec::GetInstance())), delegate_(delegate) { channel_->SetMethodCallHandler( [this]( diff --git a/src/flutter/shell/platform/linux_embedded/plugins/platform_views_plugin.cc b/src/flutter/shell/platform/linux_embedded/plugins/platform_views_plugin.cc index 2a618882..85c553e8 100644 --- a/src/flutter/shell/platform/linux_embedded/plugins/platform_views_plugin.cc +++ b/src/flutter/shell/platform/linux_embedded/plugins/platform_views_plugin.cc @@ -32,7 +32,8 @@ constexpr char kParamsKey[] = "params"; PlatformViewsPlugin::PlatformViewsPlugin(BinaryMessenger* messenger) : channel_( std::make_unique>( - messenger, kChannelName, + messenger, + kChannelName, &flutter::StandardMethodCodec::GetInstance())), current_view_id_(-1) { channel_->SetMethodCallHandler( diff --git a/src/flutter/shell/platform/linux_embedded/plugins/text_input_plugin.cc b/src/flutter/shell/platform/linux_embedded/plugins/text_input_plugin.cc index 5c89f72a..3cc932c9 100644 --- a/src/flutter/shell/platform/linux_embedded/plugins/text_input_plugin.cc +++ b/src/flutter/shell/platform/linux_embedded/plugins/text_input_plugin.cc @@ -98,7 +98,9 @@ void TextInputPlugin::OnKeyPressed(uint32_t keycode, uint32_t code_point) { TextInputPlugin::TextInputPlugin(BinaryMessenger* messenger, WindowBindingHandler* delegate) : channel_(std::make_unique>( - messenger, kChannelName, &flutter::JsonMethodCodec::GetInstance())), + messenger, + kChannelName, + &flutter::JsonMethodCodec::GetInstance())), delegate_(delegate), active_model_(nullptr) { channel_->SetMethodCallHandler( diff --git a/src/flutter/shell/platform/linux_embedded/public/flutter_platform_views.h b/src/flutter/shell/platform/linux_embedded/public/flutter_platform_views.h index 8efbf2f9..5ecb2f30 100644 --- a/src/flutter/shell/platform/linux_embedded/public/flutter_platform_views.h +++ b/src/flutter/shell/platform/linux_embedded/public/flutter_platform_views.h @@ -53,7 +53,9 @@ class FlutterDesktopPlatformViewFactory { flutter::PluginRegistrar* GetPluginRegistrar() const { return registrar_; } virtual FlutterDesktopPlatformView* Create( - int view_id, double width, double height, + int view_id, + double width, + double height, const std::vector& params) = 0; virtual void Dispose() = 0; @@ -67,7 +69,8 @@ extern "C" { #endif void FlutterDesktopRegisterPlatformViewFactory( - FlutterDesktopPluginRegistrarRef registrar, const char* view_type, + FlutterDesktopPluginRegistrarRef registrar, + const char* view_type, std::unique_ptr view_factory); #if defined(__cplusplus) diff --git a/src/flutter/shell/platform/linux_embedded/surface/context_egl.cc b/src/flutter/shell/platform/linux_embedded/surface/context_egl.cc index 85c4a31e..978af656 100644 --- a/src/flutter/shell/platform/linux_embedded/surface/context_egl.cc +++ b/src/flutter/shell/platform/linux_embedded/surface/context_egl.cc @@ -105,7 +105,9 @@ std::unique_ptr ContextEgl::CreateOffscreenSurface( resource_context_); } -bool ContextEgl::IsValid() const { return valid_; } +bool ContextEgl::IsValid() const { + return valid_; +} bool ContextEgl::ClearCurrent() const { if (eglGetCurrentContext() != context_) { diff --git a/src/flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.cc b/src/flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.cc index f25af190..b47567f9 100644 --- a/src/flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.cc +++ b/src/flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.cc @@ -9,7 +9,8 @@ namespace flutter { -ELinuxEGLSurface::ELinuxEGLSurface(EGLSurface surface, EGLDisplay display, +ELinuxEGLSurface::ELinuxEGLSurface(EGLSurface surface, + EGLDisplay display, EGLContext context) : surface_(surface), display_(display), context_(context){}; @@ -23,7 +24,9 @@ ELinuxEGLSurface::~ELinuxEGLSurface() { } } -bool ELinuxEGLSurface::IsValid() const { return surface_ != EGL_NO_SURFACE; } +bool ELinuxEGLSurface::IsValid() const { + return surface_ != EGL_NO_SURFACE; +} bool ELinuxEGLSurface::MakeCurrent() const { if (eglMakeCurrent(display_, surface_, surface_, context_) != EGL_TRUE) { diff --git a/src/flutter/shell/platform/linux_embedded/surface/surface_decoration.cc b/src/flutter/shell/platform/linux_embedded/surface/surface_decoration.cc index b4c7bb4e..dc7e932c 100644 --- a/src/flutter/shell/platform/linux_embedded/surface/surface_decoration.cc +++ b/src/flutter/shell/platform/linux_embedded/surface/surface_decoration.cc @@ -12,7 +12,9 @@ SurfaceDecoration::SurfaceDecoration(std::unique_ptr context) { context_ = std::move(context); } -bool SurfaceDecoration::IsValid() const { return context_->IsValid(); }; +bool SurfaceDecoration::IsValid() const { + return context_->IsValid(); +}; bool SurfaceDecoration::SetNativeWindow(NativeWindow* window) { native_window_ = window; @@ -60,7 +62,9 @@ bool SurfaceDecoration::GLContextPresent(uint32_t fbo_id) const { return surface_->SwapBuffers(); } -uint32_t SurfaceDecoration::GLContextFBO() const { return 0; } +uint32_t SurfaceDecoration::GLContextFBO() const { + return 0; +} void* SurfaceDecoration::GlProcResolver(const char* name) const { return context_->GlProcResolver(name); diff --git a/src/flutter/shell/platform/linux_embedded/surface/surface_gl.cc b/src/flutter/shell/platform/linux_embedded/surface/surface_gl.cc index 314c5025..7467dd84 100644 --- a/src/flutter/shell/platform/linux_embedded/surface/surface_gl.cc +++ b/src/flutter/shell/platform/linux_embedded/surface/surface_gl.cc @@ -26,7 +26,9 @@ bool SurfaceGl::GLContextPresent(uint32_t fbo_id) const { return true; } -uint32_t SurfaceGl::GLContextFBO() const { return 0; } +uint32_t SurfaceGl::GLContextFBO() const { + return 0; +} void* SurfaceGl::GlProcResolver(const char* name) const { return context_->GlProcResolver(name); diff --git a/src/flutter/shell/platform/linux_embedded/task_runner.cc b/src/flutter/shell/platform/linux_embedded/task_runner.cc index fd28fe96..8a5b617a 100644 --- a/src/flutter/shell/platform/linux_embedded/task_runner.cc +++ b/src/flutter/shell/platform/linux_embedded/task_runner.cc @@ -5,8 +5,8 @@ #include "flutter/shell/platform/linux_embedded/task_runner.h" #include -#include #include +#include namespace flutter { @@ -22,7 +22,7 @@ bool TaskRunner::RunsTasksOnCurrentThread() const { } void TaskRunner::PostFlutterTask(FlutterTask flutter_task, - uint64_t flutter_target_time_nanos) { + uint64_t flutter_target_time_nanos) { Task task; task.fire_time = TimePointFromFlutterTime(flutter_target_time_nanos); task.variant = flutter_task; diff --git a/src/flutter/shell/platform/linux_embedded/task_runner.h b/src/flutter/shell/platform/linux_embedded/task_runner.h index 723a75ac..9b88d3d8 100644 --- a/src/flutter/shell/platform/linux_embedded/task_runner.h +++ b/src/flutter/shell/platform/linux_embedded/task_runner.h @@ -26,7 +26,8 @@ class TaskRunner { using TaskExpiredCallback = std::function; using TaskClosure = std::function; - TaskRunner(std::thread::id main_thread_id, CurrentTimeProc get_current_time, + TaskRunner(std::thread::id main_thread_id, + CurrentTimeProc get_current_time, const TaskExpiredCallback& on_task_expired); ~TaskRunner() = default; diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h b/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h index 3c120999..724b5fc2 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h @@ -194,8 +194,8 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { protected: static constexpr libinput_interface kLibinputInterface = { - .open_restricted = [](const char* path, int flags, - void* user_data) -> int { + .open_restricted = + [](const char* path, int flags, void* user_data) -> int { auto ret = open(path, flags | O_CLOEXEC); if (ret == -1) { ELINUX_LOG(ERROR) @@ -275,7 +275,9 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { return true; } - static int OnUdevDrmEvent(sd_event_source* source, int fd, uint32_t revents, + static int OnUdevDrmEvent(sd_event_source* source, + int fd, + uint32_t revents, void* data) { auto self = reinterpret_cast(data); auto device = udev_monitor_receive_device(self->udev_monitor_); @@ -326,7 +328,9 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { return std::strcmp(value, kPropertyOn) == 0; } - static int OnLibinputEvent(sd_event_source* source, int fd, uint32_t revents, + static int OnLibinputEvent(sd_event_source* source, + int fd, + uint32_t revents, void* data) { auto self = reinterpret_cast(data); auto ret = libinput_dispatch(self->libinput_); diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc index 98751f61..c196131d 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc @@ -43,8 +43,11 @@ constexpr char kClipboardMimeTypeText[] = "text/plain"; const wl_registry_listener ELinuxWindowWayland::kWlRegistryListener = { .global = - [](void* data, wl_registry* wl_registry, uint32_t name, - const char* interface, uint32_t version) { + [](void* data, + wl_registry* wl_registry, + uint32_t name, + const char* interface, + uint32_t version) { auto self = reinterpret_cast(data); self->WlRegistryHandler(wl_registry, name, interface, version); }, @@ -56,7 +59,8 @@ const wl_registry_listener ELinuxWindowWayland::kWlRegistryListener = { }; const xdg_wm_base_listener ELinuxWindowWayland::kXdgWmBaseListener = { - .ping = [](void* data, xdg_wm_base* xdg_wm_base, + .ping = [](void* data, + xdg_wm_base* xdg_wm_base, uint32_t serial) { xdg_wm_base_pong(xdg_wm_base, serial); }, }; @@ -81,8 +85,11 @@ const xdg_surface_listener ELinuxWindowWayland::kXdgSurfaceListener = { const xdg_toplevel_listener ELinuxWindowWayland::kXdgToplevelListener = { .configure = - [](void* data, xdg_toplevel* xdg_toplevel, int32_t width, - int32_t height, wl_array* states) { + [](void* data, + xdg_toplevel* xdg_toplevel, + int32_t width, + int32_t height, + wl_array* states) { auto is_maximized = false; auto is_resizing = false; uint32_t* state = static_cast(states->data); @@ -154,8 +161,12 @@ const wp_presentation_feedback_listener .presented = [](void* data, struct wp_presentation_feedback* wp_presentation_feedback, - uint32_t tv_sec_hi, uint32_t tv_sec_lo, uint32_t tv_nsec, - uint32_t refresh, uint32_t seq_hi, uint32_t seq_lo, + uint32_t tv_sec_hi, + uint32_t tv_sec_lo, + uint32_t tv_nsec, + uint32_t refresh, + uint32_t seq_hi, + uint32_t seq_lo, uint32_t flags) { auto self = reinterpret_cast(data); self->last_frame_time_nanos_ = @@ -233,8 +244,11 @@ const wl_seat_listener ELinuxWindowWayland::kWlSeatListener = { }; const wl_pointer_listener ELinuxWindowWayland::kWlPointerListener = { - .enter = [](void* data, wl_pointer* wl_pointer, uint32_t serial, - wl_surface* surface, wl_fixed_t surface_x, + .enter = [](void* data, + wl_pointer* wl_pointer, + uint32_t serial, + wl_surface* surface, + wl_fixed_t surface_x, wl_fixed_t surface_y) -> void { auto self = reinterpret_cast(data); self->wl_current_surface_ = surface; @@ -253,7 +267,9 @@ const wl_pointer_listener ELinuxWindowWayland::kWlPointerListener = { self->pointer_y_ = y; } }, - .leave = [](void* data, wl_pointer* pointer, uint32_t serial, + .leave = [](void* data, + wl_pointer* pointer, + uint32_t serial, wl_surface* surface) -> void { auto self = reinterpret_cast(data); self->wl_current_surface_ = surface; @@ -265,8 +281,11 @@ const wl_pointer_listener ELinuxWindowWayland::kWlPointerListener = { self->pointer_y_ = -1; } }, - .motion = [](void* data, wl_pointer* pointer, uint32_t time, - wl_fixed_t surface_x, wl_fixed_t surface_y) -> void { + .motion = [](void* data, + wl_pointer* pointer, + uint32_t time, + wl_fixed_t surface_x, + wl_fixed_t surface_y) -> void { auto self = reinterpret_cast(data); if (self->binding_handler_delegate_) { double x = wl_fixed_to_double(surface_x); @@ -276,8 +295,12 @@ const wl_pointer_listener ELinuxWindowWayland::kWlPointerListener = { self->pointer_y_ = y; } }, - .button = [](void* data, wl_pointer* pointer, uint32_t serial, - uint32_t time, uint32_t button, uint32_t status) -> void { + .button = [](void* data, + wl_pointer* pointer, + uint32_t serial, + uint32_t time, + uint32_t button, + uint32_t status) -> void { auto self = reinterpret_cast(data); self->serial_ = serial; @@ -360,7 +383,10 @@ const wl_pointer_listener ELinuxWindowWayland::kWlPointerListener = { } } }, - .axis = [](void* data, wl_pointer* wl_pointer, uint32_t time, uint32_t axis, + .axis = [](void* data, + wl_pointer* wl_pointer, + uint32_t time, + uint32_t axis, wl_fixed_t value) -> void { auto self = reinterpret_cast(data); if (self->binding_handler_delegate_) { @@ -376,8 +402,13 @@ const wl_pointer_listener ELinuxWindowWayland::kWlPointerListener = { }; const wl_touch_listener ELinuxWindowWayland::kWlTouchListener = { - .down = [](void* data, wl_touch* wl_touch, uint32_t serial, uint32_t time, - wl_surface* surface, int32_t id, wl_fixed_t surface_x, + .down = [](void* data, + wl_touch* wl_touch, + uint32_t serial, + uint32_t time, + wl_surface* surface, + int32_t id, + wl_fixed_t surface_x, wl_fixed_t surface_y) -> void { auto self = reinterpret_cast(data); self->serial_ = serial; @@ -387,7 +418,10 @@ const wl_touch_listener ELinuxWindowWayland::kWlTouchListener = { self->binding_handler_delegate_->OnTouchDown(time, id, x, y); } }, - .up = [](void* data, wl_touch* wl_touch, uint32_t serial, uint32_t time, + .up = [](void* data, + wl_touch* wl_touch, + uint32_t serial, + uint32_t time, int32_t id) -> void { auto self = reinterpret_cast(data); self->serial_ = serial; @@ -395,8 +429,12 @@ const wl_touch_listener ELinuxWindowWayland::kWlTouchListener = { self->binding_handler_delegate_->OnTouchUp(time, id); } }, - .motion = [](void* data, wl_touch* wl_touch, uint32_t time, int32_t id, - wl_fixed_t surface_x, wl_fixed_t surface_y) -> void { + .motion = [](void* data, + wl_touch* wl_touch, + uint32_t time, + int32_t id, + wl_fixed_t surface_x, + wl_fixed_t surface_y) -> void { auto self = reinterpret_cast(data); if (self->binding_handler_delegate_) { double x = wl_fixed_to_double(surface_x); @@ -414,7 +452,10 @@ const wl_touch_listener ELinuxWindowWayland::kWlTouchListener = { }; const wl_keyboard_listener ELinuxWindowWayland::kWlKeyboardListener = { - .keymap = [](void* data, wl_keyboard* wl_keyboard, uint32_t format, int fd, + .keymap = [](void* data, + wl_keyboard* wl_keyboard, + uint32_t format, + int fd, uint32_t size) -> void { auto self = reinterpret_cast(data); assert(format == WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1); @@ -422,18 +463,27 @@ const wl_keyboard_listener ELinuxWindowWayland::kWlKeyboardListener = { self->binding_handler_delegate_->OnKeyMap(format, fd, size); } }, - .enter = [](void* data, wl_keyboard* wl_keyboard, uint32_t serial, - wl_surface* surface, wl_array* keys) -> void { + .enter = [](void* data, + wl_keyboard* wl_keyboard, + uint32_t serial, + wl_surface* surface, + wl_array* keys) -> void { auto self = reinterpret_cast(data); self->serial_ = serial; }, - .leave = [](void* data, wl_keyboard* wl_keyboard, uint32_t serial, + .leave = [](void* data, + wl_keyboard* wl_keyboard, + uint32_t serial, wl_surface* surface) -> void { auto self = reinterpret_cast(data); self->serial_ = serial; }, - .key = [](void* data, wl_keyboard* wl_keyboard, uint32_t serial, - uint32_t time, uint32_t key, uint32_t state) -> void { + .key = [](void* data, + wl_keyboard* wl_keyboard, + uint32_t serial, + uint32_t time, + uint32_t key, + uint32_t state) -> void { auto self = reinterpret_cast(data); self->serial_ = serial; if (self->binding_handler_delegate_) { @@ -441,26 +491,40 @@ const wl_keyboard_listener ELinuxWindowWayland::kWlKeyboardListener = { key, state == WL_KEYBOARD_KEY_STATE_PRESSED); } }, - .modifiers = [](void* data, wl_keyboard* wl_keyboard, uint32_t serial, - uint32_t mods_depressed, uint32_t mods_latched, - uint32_t mods_locked, uint32_t group) -> void { + .modifiers = [](void* data, + wl_keyboard* wl_keyboard, + uint32_t serial, + uint32_t mods_depressed, + uint32_t mods_latched, + uint32_t mods_locked, + uint32_t group) -> void { auto self = reinterpret_cast(data); if (self->binding_handler_delegate_) { self->binding_handler_delegate_->OnKeyModifiers( mods_depressed, mods_latched, mods_locked, group); } }, - .repeat_info = [](void* data, wl_keyboard* wl_keyboard, int rate, - int delay) -> void {}, + .repeat_info = [](void* data, wl_keyboard* wl_keyboard, int rate, int delay) + -> void {}, }; const wl_output_listener ELinuxWindowWayland::kWlOutputListener = { - .geometry = [](void* data, wl_output* wl_output, int32_t x, int32_t y, - int32_t physical_width, int32_t physical_height, - int32_t subpixel, const char* make, const char* model, + .geometry = [](void* data, + wl_output* wl_output, + int32_t x, + int32_t y, + int32_t physical_width, + int32_t physical_height, + int32_t subpixel, + const char* make, + const char* model, int32_t output_transform) -> void {}, - .mode = [](void* data, wl_output* wl_output, uint32_t flags, int32_t width, - int32_t height, int32_t refresh) -> void { + .mode = [](void* data, + wl_output* wl_output, + uint32_t flags, + int32_t width, + int32_t height, + int32_t refresh) -> void { auto self = reinterpret_cast(data); if (flags & WL_OUTPUT_MODE_CURRENT) { ELINUX_LOG(INFO) << "Display output info: width = " << width @@ -496,7 +560,8 @@ const wl_output_listener ELinuxWindowWayland::kWlOutputListener = { const zwp_text_input_v1_listener ELinuxWindowWayland::kZwpTextInputV1Listener = { - .enter = [](void* data, zwp_text_input_v1* zwp_text_input_v1, + .enter = [](void* data, + zwp_text_input_v1* zwp_text_input_v1, wl_surface* surface) -> void { auto self = reinterpret_cast(data); // If there is no input data, the backspace key cannot be used, @@ -512,13 +577,16 @@ const zwp_text_input_v1_listener ELinuxWindowWayland::kZwpTextInputV1Listener = zwp_text_input_v1_hide_input_panel(self->zwp_text_input_v1_); } }, - .modifiers_map = [](void* data, zwp_text_input_v1* zwp_text_input_v1, + .modifiers_map = [](void* data, + zwp_text_input_v1* zwp_text_input_v1, wl_array* map) -> void {}, .input_panel_state = [](void* data, zwp_text_input_v1* zwp_text_input_v1, uint32_t state) -> void {}, - .preedit_string = [](void* data, zwp_text_input_v1* zwp_text_input_v1, - uint32_t serial, const char* text, + .preedit_string = [](void* data, + zwp_text_input_v1* zwp_text_input_v1, + uint32_t serial, + const char* text, const char* commit) -> void { auto self = reinterpret_cast(data); if (self->binding_handler_delegate_ && strlen(text)) { @@ -532,13 +600,18 @@ const zwp_text_input_v1_listener ELinuxWindowWayland::kZwpTextInputV1Listener = " ", 1, 1); } }, - .preedit_styling = [](void* data, zwp_text_input_v1* zwp_text_input_v1, - uint32_t index, uint32_t length, + .preedit_styling = [](void* data, + zwp_text_input_v1* zwp_text_input_v1, + uint32_t index, + uint32_t length, uint32_t style) -> void {}, - .preedit_cursor = [](void* data, zwp_text_input_v1* zwp_text_input_v1, + .preedit_cursor = [](void* data, + zwp_text_input_v1* zwp_text_input_v1, int32_t index) -> void {}, - .commit_string = [](void* data, zwp_text_input_v1* zwp_text_input_v1, - uint32_t serial, const char* text) -> void { + .commit_string = [](void* data, + zwp_text_input_v1* zwp_text_input_v1, + uint32_t serial, + const char* text) -> void { // commit_string is notified only when the space key is pressed. auto self = reinterpret_cast(data); if (self->binding_handler_delegate_ && strlen(text)) { @@ -551,11 +624,14 @@ const zwp_text_input_v1_listener ELinuxWindowWayland::kZwpTextInputV1Listener = " ", 1, 1); } }, - .cursor_position = [](void* data, zwp_text_input_v1* zwp_text_input_v1, - int32_t index, int32_t anchor) -> void {}, + .cursor_position = [](void* data, + zwp_text_input_v1* zwp_text_input_v1, + int32_t index, + int32_t anchor) -> void {}, .delete_surrounding_text = [](void* data, zwp_text_input_v1* zwp_text_input_v1, - int32_t index, uint32_t length) -> void { + int32_t index, + uint32_t length) -> void { auto self = reinterpret_cast(data); if (self->binding_handler_delegate_) { self->binding_handler_delegate_->OnVirtualSpecialKey(KEY_BACKSPACE); @@ -567,9 +643,13 @@ const zwp_text_input_v1_listener ELinuxWindowWayland::kZwpTextInputV1Listener = " ", 1, 1); } }, - .keysym = [](void* data, zwp_text_input_v1* zwp_text_input_v1, - uint32_t serial, uint32_t time, uint32_t sym, - uint32_t state, uint32_t modifiers) -> void { + .keysym = [](void* data, + zwp_text_input_v1* zwp_text_input_v1, + uint32_t serial, + uint32_t time, + uint32_t sym, + uint32_t state, + uint32_t modifiers) -> void { auto self = reinterpret_cast(data); if ((state == WL_KEYBOARD_KEY_STATE_PRESSED) && (self->binding_handler_delegate_)) { @@ -597,15 +677,20 @@ const zwp_text_input_v1_listener ELinuxWindowWayland::kZwpTextInputV1Listener = } } }, - .language = [](void* data, zwp_text_input_v1* zwp_text_input_v1, - uint32_t serial, const char* language) -> void {}, - .text_direction = [](void* data, zwp_text_input_v1* zwp_text_input_v1, - uint32_t serial, uint32_t direction) -> void {}, + .language = [](void* data, + zwp_text_input_v1* zwp_text_input_v1, + uint32_t serial, + const char* language) -> void {}, + .text_direction = [](void* data, + zwp_text_input_v1* zwp_text_input_v1, + uint32_t serial, + uint32_t direction) -> void {}, }; const zwp_text_input_v3_listener ELinuxWindowWayland::kZwpTextInputV3Listener = { - .enter = [](void* data, zwp_text_input_v3* zwp_text_input_v3, + .enter = [](void* data, + zwp_text_input_v3* zwp_text_input_v3, wl_surface* surface) -> void { // To appear the on-screen keyboard when the user returns to a Flutter // app which needs to show the on-screen keyboard. @@ -614,36 +699,51 @@ const zwp_text_input_v3_listener ELinuxWindowWayland::kZwpTextInputV3Listener = self->ShowVirtualKeyboard(); } }, - .leave = [](void* data, zwp_text_input_v3* zwp_text_input_v3, + .leave = [](void* data, + zwp_text_input_v3* zwp_text_input_v3, wl_surface* surface) -> void {}, - .preedit_string = [](void* data, zwp_text_input_v3* zwp_text_input_v3, - const char* text, int32_t cursor_begin, + .preedit_string = [](void* data, + zwp_text_input_v3* zwp_text_input_v3, + const char* text, + int32_t cursor_begin, int32_t cursor_end) -> void {}, - .commit_string = [](void* data, zwp_text_input_v3* zwp_text_input_v3, + .commit_string = [](void* data, + zwp_text_input_v3* zwp_text_input_v3, const char* text) -> void { auto self = reinterpret_cast(data); if (self->binding_handler_delegate_ && strlen(text)) { self->binding_handler_delegate_->OnVirtualKey(text[0]); } }, - .delete_surrounding_text = - [](void* data, zwp_text_input_v3* zwp_text_input_v3, - uint32_t before_length, uint32_t after_length) -> void {}, - .done = [](void* data, zwp_text_input_v3* zwp_text_input_v3, + .delete_surrounding_text = [](void* data, + zwp_text_input_v3* zwp_text_input_v3, + uint32_t before_length, + uint32_t after_length) -> void {}, + .done = [](void* data, + zwp_text_input_v3* zwp_text_input_v3, uint32_t serial) -> void {}, }; const wl_data_device_listener ELinuxWindowWayland::kWlDataDeviceListener = { - .data_offer = [](void* data, wl_data_device* wl_data_device, + .data_offer = [](void* data, + wl_data_device* wl_data_device, wl_data_offer* offer) -> void {}, - .enter = [](void* data, wl_data_device* wl_data_device, uint32_t serial, - wl_surface* surface, wl_fixed_t x, wl_fixed_t y, + .enter = [](void* data, + wl_data_device* wl_data_device, + uint32_t serial, + wl_surface* surface, + wl_fixed_t x, + wl_fixed_t y, wl_data_offer* offer) -> void {}, .leave = [](void* data, wl_data_device* wl_data_device) -> void {}, - .motion = [](void* data, wl_data_device* wl_data_device, uint32_t time, - wl_fixed_t x, wl_fixed_t y) -> void {}, + .motion = [](void* data, + wl_data_device* wl_data_device, + uint32_t time, + wl_fixed_t x, + wl_fixed_t y) -> void {}, .drop = [](void* data, wl_data_device* wl_data_device) -> void {}, - .selection = [](void* data, wl_data_device* wl_data_device, + .selection = [](void* data, + wl_data_device* wl_data_device, wl_data_offer* offer) -> void { auto self = reinterpret_cast(data); if (self->wl_data_offer_) { @@ -654,10 +754,13 @@ const wl_data_device_listener ELinuxWindowWayland::kWlDataDeviceListener = { }; const wl_data_source_listener ELinuxWindowWayland::kWlDataSourceListener = { - .target = [](void* data, wl_data_source* wl_data_source, + .target = [](void* data, + wl_data_source* wl_data_source, const char* mime_type) -> void {}, - .send = [](void* data, wl_data_source* wl_data_source, - const char* mime_type, int32_t fd) -> void { + .send = [](void* data, + wl_data_source* wl_data_source, + const char* mime_type, + int32_t fd) -> void { if (strcmp(mime_type, kClipboardMimeTypeText)) { ELINUX_LOG(ERROR) << "Not expected mime_type: " << mime_type; return; @@ -679,7 +782,8 @@ const wl_data_source_listener ELinuxWindowWayland::kWlDataSourceListener = { .dnd_drop_performed = [](void* data, wl_data_source* wl_data_source) -> void {}, .dnd_finished = [](void* data, wl_data_source* wl_data_source) -> void {}, - .action = [](void* data, wl_data_source* wl_data_source, + .action = [](void* data, + wl_data_source* wl_data_source, uint32_t dnd_action) -> void {}, }; @@ -892,13 +996,17 @@ ELinuxRenderSurfaceTarget* ELinuxWindowWayland::GetRenderSurfaceTarget() const { return render_surface_.get(); } -double ELinuxWindowWayland::GetDpiScale() { return current_scale_; } +double ELinuxWindowWayland::GetDpiScale() { + return current_scale_; +} PhysicalWindowBounds ELinuxWindowWayland::GetPhysicalWindowBounds() { return {GetCurrentWidth(), GetCurrentHeight()}; } -int32_t ELinuxWindowWayland::GetFrameRate() { return frame_rate_; } +int32_t ELinuxWindowWayland::GetFrameRate() { + return frame_rate_; +} bool ELinuxWindowWayland::DispatchEvent() { if (!IsValid()) { diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h index 1eb19012..5a73232e 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h @@ -80,8 +80,10 @@ class ELinuxWindowWayland : public ELinuxWindow, public WindowBindingHandler { wl_pointer* pointer; }; - void WlRegistryHandler(wl_registry* wl_registry, uint32_t name, - const char* interface, uint32_t version); + void WlRegistryHandler(wl_registry* wl_registry, + uint32_t name, + const char* interface, + uint32_t version); void WlUnRegistryHandler(wl_registry* wl_registry, uint32_t name); diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.cc index 868dccfc..3d475888 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.cc @@ -143,13 +143,17 @@ ELinuxRenderSurfaceTarget* ELinuxWindowX11::GetRenderSurfaceTarget() const { return render_surface_.get(); } -double ELinuxWindowX11::GetDpiScale() { return current_scale_; } +double ELinuxWindowX11::GetDpiScale() { + return current_scale_; +} PhysicalWindowBounds ELinuxWindowX11::GetPhysicalWindowBounds() { return {GetCurrentWidth(), GetCurrentHeight()}; } -int32_t ELinuxWindowX11::GetFrameRate() { return 60000; } +int32_t ELinuxWindowX11::GetFrameRate() { + return 60000; +} void ELinuxWindowX11::UpdateFlutterCursor(const std::string& cursor_name) { // TODO: implement here @@ -159,14 +163,17 @@ void ELinuxWindowX11::UpdateVirtualKeyboardStatus(const bool show) { // currently not supported. } -std::string ELinuxWindowX11::GetClipboardData() { return clipboard_data_; } +std::string ELinuxWindowX11::GetClipboardData() { + return clipboard_data_; +} void ELinuxWindowX11::SetClipboardData(const std::string& data) { clipboard_data_ = data; } void ELinuxWindowX11::HandlePointerButtonEvent(uint32_t button, - bool button_pressed, int16_t x, + bool button_pressed, + int16_t x, int16_t y) { if (binding_handler_delegate_) { FlutterPointerMouseButtons flutter_button; diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.h b/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.h index 2a972fb5..7eb73262 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.h +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.h @@ -60,7 +60,9 @@ class ELinuxWindowX11 : public ELinuxWindow, public WindowBindingHandler { private: // Handles the events of the mouse button. - void HandlePointerButtonEvent(uint32_t button, bool button_pressed, int16_t x, + void HandlePointerButtonEvent(uint32_t button, + bool button_pressed, + int16_t x, int16_t y); // A pointer to a FlutterWindowsView that can be used to update engine diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_drm.h b/src/flutter/shell/platform/linux_embedded/window/native_window_drm.h index e2c96270..4ec29050 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_drm.h +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_drm.h @@ -25,7 +25,8 @@ class NativeWindowDrm : public NativeWindow { virtual bool ShowCursor(double x, double y) = 0; - virtual bool UpdateCursor(const std::string& cursor_name, double x, + virtual bool UpdateCursor(const std::string& cursor_name, + double x, double y) = 0; virtual bool DismissCursor() = 0; diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_drm_eglstream.cc b/src/flutter/shell/platform/linux_embedded/window/native_window_drm_eglstream.cc index b5449ae5..b762321a 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_drm_eglstream.cc +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_drm_eglstream.cc @@ -70,7 +70,8 @@ bool NativeWindowDrmEglstream::ShowCursor(double x, double y) { } bool NativeWindowDrmEglstream::UpdateCursor(const std::string& cursor_name, - double x, double y) { + double x, + double y) { if (cursor_name.compare(cursor_name_) == 0) { return true; } @@ -162,7 +163,8 @@ uint32_t NativeWindowDrmEglstream::FindPrimaryPlaneId( return -1; } -uint64_t NativeWindowDrmEglstream::GetPropertyValue(uint32_t id, uint32_t type, +uint64_t NativeWindowDrmEglstream::GetPropertyValue(uint32_t id, + uint32_t type, const char* prop_name) { uint64_t value = -1; auto properties = drmModeObjectGetProperties(drm_device_, id, type); @@ -233,7 +235,9 @@ bool NativeWindowDrmEglstream::AssignAtomicRequest(drmModeAtomicReqPtr atomic) { template bool NativeWindowDrmEglstream::AssignAtomicPropertyValue( - drmModeAtomicReqPtr atomic, uint32_t id, uint32_t type, + drmModeAtomicReqPtr atomic, + uint32_t id, + uint32_t type, NativeWindowDrmEglstream::DrmProperty (&table)[N]) { auto properties = drmModeObjectGetProperties(drm_device_, id, type); if (properties) { diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_drm_eglstream.h b/src/flutter/shell/platform/linux_embedded/window/native_window_drm_eglstream.h index cd998fc5..994dfe38 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_drm_eglstream.h +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_drm_eglstream.h @@ -23,7 +23,8 @@ class NativeWindowDrmEglstream : public NativeWindowDrm { bool ShowCursor(double x, double y) override; // |NativeWindowDrm| - bool UpdateCursor(const std::string& cursor_name, double x, + bool UpdateCursor(const std::string& cursor_name, + double x, double y) override; // |NativeWindowDrm| @@ -55,7 +56,9 @@ class NativeWindowDrmEglstream : public NativeWindowDrm { template bool AssignAtomicPropertyValue( - drmModeAtomicReqPtr atomic, uint32_t id, uint32_t type, + drmModeAtomicReqPtr atomic, + uint32_t id, + uint32_t type, NativeWindowDrmEglstream::DrmProperty (&table)[N]); uint32_t drm_plane_id_; diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_drm_gbm.cc b/src/flutter/shell/platform/linux_embedded/window/native_window_drm_gbm.cc index 8775bb99..a24443a7 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_drm_gbm.cc +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_drm_gbm.cc @@ -92,7 +92,8 @@ bool NativeWindowDrmGbm::ShowCursor(double x, double y) { return true; } -bool NativeWindowDrmGbm::UpdateCursor(const std::string& cursor_name, double x, +bool NativeWindowDrmGbm::UpdateCursor(const std::string& cursor_name, + double x, double y) { if (cursor_name.compare(cursor_name_) == 0) { return true; diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_drm_gbm.h b/src/flutter/shell/platform/linux_embedded/window/native_window_drm_gbm.h index f30113b2..0a062273 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_drm_gbm.h +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_drm_gbm.h @@ -24,7 +24,8 @@ class NativeWindowDrmGbm : public NativeWindowDrm { bool ShowCursor(double x, double y) override; // |NativeWindowDrm| - bool UpdateCursor(const std::string& cursor_name, double x, + bool UpdateCursor(const std::string& cursor_name, + double x, double y) override; // |NativeWindowDrm| diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_wayland.h b/src/flutter/shell/platform/linux_embedded/window/native_window_wayland.h index c8cc41d2..5688058f 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_wayland.h +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_wayland.h @@ -13,7 +13,8 @@ namespace flutter { class NativeWindowWayland : public NativeWindow { public: - NativeWindowWayland(wl_compositor* compositor, const size_t width, + NativeWindowWayland(wl_compositor* compositor, + const size_t width, const size_t height); ~NativeWindowWayland(); diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_wayland_decoration.cc b/src/flutter/shell/platform/linux_embedded/window/native_window_wayland_decoration.cc index 063d9143..20486eee 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_wayland_decoration.cc +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_wayland_decoration.cc @@ -9,8 +9,11 @@ namespace flutter { NativeWindowWaylandDecoration::NativeWindowWaylandDecoration( - wl_compositor* compositor, wl_subcompositor* subcompositor, - wl_surface* parent_surface, const size_t width, const size_t height) { + wl_compositor* compositor, + wl_subcompositor* subcompositor, + wl_surface* parent_surface, + const size_t width, + const size_t height) { surface_ = wl_compositor_create_surface(compositor); if (!surface_) { ELINUX_LOG(ERROR) << "Failed to create the compositor surface."; diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_wayland_decoration.h b/src/flutter/shell/platform/linux_embedded/window/native_window_wayland_decoration.h index 4670d8bd..d270c338 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_wayland_decoration.h +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_wayland_decoration.h @@ -16,7 +16,8 @@ class NativeWindowWaylandDecoration : public NativeWindow { public: NativeWindowWaylandDecoration(wl_compositor* compositor, wl_subcompositor* subcompositor, - wl_surface* parent_surface, const size_t width, + wl_surface* parent_surface, + const size_t width, const size_t height); ~NativeWindowWaylandDecoration(); diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_x11.cc b/src/flutter/shell/platform/linux_embedded/window/native_window_x11.cc index 310d7b47..05374de3 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_x11.cc +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_x11.cc @@ -19,8 +19,10 @@ static constexpr char kWmDeleteWindow[] = "WM_DELETE_WINDOW"; static constexpr char kWindowTitle[] = "Flutter for Embedded Linux"; } // namespace -NativeWindowX11::NativeWindowX11(Display* display, VisualID visual_id, - const size_t width, const size_t height) { +NativeWindowX11::NativeWindowX11(Display* display, + VisualID visual_id, + const size_t width, + const size_t height) { XVisualInfo visualTemplate; visualTemplate.visualid = visual_id; diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_x11.h b/src/flutter/shell/platform/linux_embedded/window/native_window_x11.h index 4a77c2c3..03afa8c3 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_x11.h +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_x11.h @@ -13,7 +13,9 @@ namespace flutter { class NativeWindowX11 : public NativeWindow { public: - NativeWindowX11(Display* display, VisualID visual_id, const size_t width, + NativeWindowX11(Display* display, + VisualID visual_id, + const size_t width, const size_t height); ~NativeWindowX11() = default; diff --git a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.cc index 1c8cdb7d..35af9d04 100644 --- a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.cc @@ -18,8 +18,11 @@ constexpr uint kButtonMargin = 10; } // namespace WindowDecorationsWayland::WindowDecorationsWayland( - wl_display* display, wl_compositor* compositor, - wl_subcompositor* subcompositor, wl_surface* root_surface, int32_t width, + wl_display* display, + wl_compositor* compositor, + wl_subcompositor* subcompositor, + wl_surface* root_surface, + int32_t width, int32_t height) { constexpr bool sub_egl_display = true; @@ -114,6 +117,8 @@ void WindowDecorationsWayland::DestroyContext() { } } -int32_t WindowDecorationsWayland::Height() const { return kTitleBarHeight; } +int32_t WindowDecorationsWayland::Height() const { + return kTitleBarHeight; +} } // namespace flutter diff --git a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.h b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.h index 4b71350b..607d0c3e 100644 --- a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.h +++ b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.h @@ -26,9 +26,11 @@ namespace flutter { class WindowDecorationsWayland { public: - WindowDecorationsWayland(wl_display* display, wl_compositor* compositor, + WindowDecorationsWayland(wl_display* display, + wl_compositor* compositor, wl_subcompositor* subcompositor, - wl_surface* root_surface, int32_t width, + wl_surface* root_surface, + int32_t width, int32_t height); ~WindowDecorationsWayland(); diff --git a/src/flutter/shell/platform/linux_embedded/window_binding_handler_delegate.h b/src/flutter/shell/platform/linux_embedded/window_binding_handler_delegate.h index 1984a53b..73f1330d 100644 --- a/src/flutter/shell/platform/linux_embedded/window_binding_handler_delegate.h +++ b/src/flutter/shell/platform/linux_embedded/window_binding_handler_delegate.h @@ -21,12 +21,14 @@ class WindowBindingHandlerDelegate { // Notifies delegate that backing window mouse pointer button has been // pressed. Typically called by currently configured WindowBindingHandler - virtual void OnPointerDown(double x, double y, + virtual void OnPointerDown(double x, + double y, FlutterPointerMouseButtons button) = 0; // Notifies delegate that backing window mouse pointer button has been // released. Typically called by currently configured WindowBindingHandler - virtual void OnPointerUp(double x, double y, + virtual void OnPointerUp(double x, + double y, FlutterPointerMouseButtons button) = 0; // Notifies delegate that backing window mouse pointer has left the window. @@ -65,8 +67,10 @@ class WindowBindingHandlerDelegate { // Notifies delegate that backing window key has been modifired. // Typically called by currently configured WindowBindingHandler - virtual void OnKeyModifiers(uint32_t mods_depressed, uint32_t mods_latched, - uint32_t mods_locked, uint32_t group) = 0; + virtual void OnKeyModifiers(uint32_t mods_depressed, + uint32_t mods_latched, + uint32_t mods_locked, + uint32_t group) = 0; // Notifies delegate that backing window key has been pressed. // Typically called by currently configured WindowBindingHandler @@ -82,7 +86,10 @@ class WindowBindingHandlerDelegate { // Notifies delegate that backing window size has recevied scroll. // Typically called by currently configured WindowBindingHandler - virtual void OnScroll(double x, double y, double delta_x, double delta_y, + virtual void OnScroll(double x, + double y, + double delta_x, + double delta_y, int scroll_offset_multiplier) = 0; // Notifies delegate that backing window vsync has happened. From 129937a80600a2c90f8488505c77648e937b8cb2 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Tue, 9 Nov 2021 11:01:27 +0900 Subject: [PATCH 003/112] Revert: Fix synchronized frame on Wayland (#221) (#235) * Revert: Fix synchronized frame on Wayland (#221) --- .../platform/linux_embedded/surface/elinux_egl_surface.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.cc b/src/flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.cc index b47567f9..8a758174 100644 --- a/src/flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.cc +++ b/src/flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.cc @@ -35,8 +35,14 @@ bool ELinuxEGLSurface::MakeCurrent() const { return false; } -#if defined(DISPLAY_BACKEND_TYPE_WAYLAND) +#if defined(ENABLE_EGL_ASYNC_BUFFER_SWAPPING) // Non-blocking when swappipping buffers on Wayland. + // However, we might encounter rendering problems on some Wayland compositors + // (e.g. weston 9.0) when we use them. + // See also: + // - https://github.com/sony/flutter-embedded-linux/issues/230 + // - https://github.com/sony/flutter-embedded-linux/issues/234 + // - https://github.com/sony/flutter-embedded-linux/issues/220 if (eglSwapInterval(display_, 0) != EGL_TRUE) { ELINUX_LOG(ERROR) << "Failed to eglSwapInterval(Free): " << get_egl_error_cause(); From f2e6dec6c4a99610834976b09487368346346366 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Thu, 25 Nov 2021 14:05:58 +0900 Subject: [PATCH 004/112] Merge common shared cpp source files 11/25/2021 (#238) * Merged from - https://github.com/flutter/engine/commit/eac4cd2817d764dfa5d84b3d94b9c71d8e2b1787#diff-338cf9d4ad1b92f8828c57038f18706f6762fa2a9aec81e21ce07d1d1cd41508 - https://github.com/flutter/engine/commit/29ea28d67b2d4c9cad0add3cfb9d0c6171146aa1 --- .../common/client_wrapper/include/flutter/encodable_value.h | 3 +++ .../client_wrapper/include/flutter/engine_method_result.h | 2 +- .../common/client_wrapper/include/flutter/texture_registrar.h | 2 +- .../shell/platform/common/client_wrapper/standard_codec.cc | 4 ++-- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/flutter/shell/platform/common/client_wrapper/include/flutter/encodable_value.h b/src/flutter/shell/platform/common/client_wrapper/include/flutter/encodable_value.h index dec1bdfc..3b46f99f 100644 --- a/src/flutter/shell/platform/common/client_wrapper/include/flutter/encodable_value.h +++ b/src/flutter/shell/platform/common/client_wrapper/include/flutter/encodable_value.h @@ -63,7 +63,9 @@ class CustomEncodableValue { ~CustomEncodableValue() = default; // Allow implicit conversion to std::any to allow direct use of any_cast. + // NOLINTNEXTLINE(google-explicit-constructor) operator std::any&() { return value_; } + // NOLINTNEXTLINE(google-explicit-constructor) operator const std::any&() const { return value_; } #if defined(FLUTTER_ENABLE_RTTI) && FLUTTER_ENABLE_RTTI @@ -182,6 +184,7 @@ class EncodableValue : public internal::EncodableValueVariant { // to use it with EncodableValue, so the risk of unintended conversions is // minimal, and it avoids the need for the verbose: // EncodableValue(CustomEncodableValue(...)). + // NOLINTNEXTLINE(google-explicit-constructor) EncodableValue(const CustomEncodableValue& v) : super(v) {} // Override the conversion constructors from std::variant to make them diff --git a/src/flutter/shell/platform/common/client_wrapper/include/flutter/engine_method_result.h b/src/flutter/shell/platform/common/client_wrapper/include/flutter/engine_method_result.h index c29ff09b..3cc8b6a2 100644 --- a/src/flutter/shell/platform/common/client_wrapper/include/flutter/engine_method_result.h +++ b/src/flutter/shell/platform/common/client_wrapper/include/flutter/engine_method_result.h @@ -21,7 +21,7 @@ namespace internal { // vary based on the template type. class ReplyManager { public: - ReplyManager(BinaryReply reply_handler_); + explicit ReplyManager(BinaryReply reply_handler_); ~ReplyManager(); // Prevent copying. diff --git a/src/flutter/shell/platform/common/client_wrapper/include/flutter/texture_registrar.h b/src/flutter/shell/platform/common/client_wrapper/include/flutter/texture_registrar.h index 5b59829f..6aa2c6b1 100644 --- a/src/flutter/shell/platform/common/client_wrapper/include/flutter/texture_registrar.h +++ b/src/flutter/shell/platform/common/client_wrapper/include/flutter/texture_registrar.h @@ -27,7 +27,7 @@ class PixelBufferTexture { // As the callback is usually invoked from the render thread, the callee must // take care of proper synchronization. It also needs to be ensured that the // returned buffer isn't released prior to unregistering this texture. - PixelBufferTexture(CopyBufferCallback copy_buffer_callback) + explicit PixelBufferTexture(CopyBufferCallback copy_buffer_callback) : copy_buffer_callback_(copy_buffer_callback) {} // Returns the callback-provided FlutterDesktopPixelBuffer that contains the diff --git a/src/flutter/shell/platform/common/client_wrapper/standard_codec.cc b/src/flutter/shell/platform/common/client_wrapper/standard_codec.cc index f16a0f97..807e0681 100644 --- a/src/flutter/shell/platform/common/client_wrapper/standard_codec.cc +++ b/src/flutter/shell/platform/common/client_wrapper/standard_codec.cc @@ -231,11 +231,11 @@ size_t StandardCodecSerializer::ReadSize(ByteStreamReader* stream) const { if (byte < 254) { return byte; } else if (byte == 254) { - uint16_t value; + uint16_t value = 0; stream->ReadBytes(reinterpret_cast(&value), 2); return value; } else { - uint32_t value; + uint32_t value = 0; stream->ReadBytes(reinterpret_cast(&value), 4); return value; } From f96b35c56310eac57e3d7954cfd0b8568e4da01c Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Thu, 2 Dec 2021 15:26:05 +0900 Subject: [PATCH 005/112] [drm] Fix: mouse cursor is visible even when no mouse is connected (#239) Fixed https://github.com/sony/flutter-embedded-linux/issues/237 --- .../linux_embedded/window/elinux_window_drm.h | 76 ++++++++++++++++--- 1 file changed, 64 insertions(+), 12 deletions(-) diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h b/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h index 724b5fc2..3d916446 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h @@ -11,7 +11,9 @@ #include #include +#include #include +#include #include "flutter/shell/platform/linux_embedded/logger.h" #include "flutter/shell/platform/linux_embedded/surface/surface_gl.h" @@ -400,23 +402,36 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { void OnDeviceAdded(libinput_event* event) { auto device = libinput_event_get_device(event); - if (view_properties_.use_mouse_cursor && - libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER)) { - // When launching the application, either route will be used depending on - // the timing. - if (native_window_) { - native_window_->ShowCursor(pointer_x_, pointer_y_); - } else { - is_pending_cursor_add_event_ = true; - } - } + auto device_data = std::make_unique(); + size_t timestamp = + std::chrono::duration_cast( + std::chrono::high_resolution_clock::now().time_since_epoch()) + .count(); + + device_data->id = timestamp; + device_data->is_pointer_device = false; + libinput_device_set_user_data(device, device_data.get()); + libinput_devices_[timestamp] = std::move(device_data); } void OnDeviceRemoved(libinput_event* event) { auto device = libinput_event_get_device(event); + auto device_data = reinterpret_cast( + libinput_device_get_user_data(device)); + if (view_properties_.use_mouse_cursor && libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER)) { - native_window_->DismissCursor(); + if (device_data && device_data->is_pointer_device) { + if (--libinput_pointer_devices_ == 0) { + native_window_->DismissCursor(); + } + } + } + + if (device_data) { + if (libinput_devices_.count(device_data->id) > 0) { + libinput_devices_.erase(libinput_devices_.find(device_data->id)); + } } } @@ -432,6 +447,7 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { } void OnPointerMotion(libinput_event* event) { + DetectPointerDevice(event); if (binding_handler_delegate_) { auto pointer_event = libinput_event_get_pointer_event(event); auto dx = libinput_event_pointer_get_dx(pointer_event); @@ -453,6 +469,7 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { } void OnPointerMotionAbsolute(libinput_event* event) { + DetectPointerDevice(event); if (binding_handler_delegate_) { auto pointer_event = libinput_event_get_pointer_event(event); auto x = libinput_event_pointer_get_absolute_x_transformed( @@ -467,6 +484,7 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { } void OnPointerButton(libinput_event* event) { + DetectPointerDevice(event); if (binding_handler_delegate_) { auto pointer_event = libinput_event_get_pointer_event(event); auto button = libinput_event_pointer_get_button(pointer_event); @@ -505,6 +523,7 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { } void OnPointerAxis(libinput_event* event) { + DetectPointerDevice(event); if (binding_handler_delegate_) { auto pointer_event = libinput_event_get_pointer_event(event); if (libinput_event_pointer_has_axis( @@ -520,6 +539,32 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { } } + void DetectPointerDevice(libinput_event* event) { + auto device = libinput_event_get_device(event); + auto device_data = reinterpret_cast( + libinput_device_get_user_data(device)); + + // Shows the mouse cursor only when connecting mouse devices. + // The mouse cursor is not displayed by touch inputs. + if (device_data && !device_data->is_pointer_device) { + device_data->is_pointer_device = true; + libinput_pointer_devices_++; + ShowMouseCursor(); + } + } + + void ShowMouseCursor() { + if (view_properties_.use_mouse_cursor && libinput_pointer_devices_ == 1) { + // When launching the application, either route will be used depending on + // the timing. + if (native_window_) { + native_window_->ShowCursor(pointer_x_, pointer_y_); + } else { + is_pending_cursor_add_event_ = true; + } + } + } + void OnTouchDown(libinput_event* event) { if (binding_handler_delegate_) { auto touch_event = libinput_event_get_touch_event(event); @@ -592,6 +637,11 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { kScrollOffsetMultiplier); } + struct LibinputDeviceData { + size_t id; + bool is_pointer_device; + }; + // A pointer to a FlutterWindowsView that can be used to update engine // windowing and input state. WindowBindingHandlerDelegate* binding_handler_delegate_ = nullptr; @@ -601,9 +651,11 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { bool display_valid_; bool is_pending_cursor_add_event_; - sd_event* libinput_event_loop_; libinput* libinput_; + std::unordered_map> + libinput_devices_; + int libinput_pointer_devices_ = 0; sd_event* udev_drm_event_loop_ = nullptr; udev_monitor* udev_monitor_ = nullptr; From 9dec787a64077ba99a229bad0adbb69c52ee874e Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Thu, 9 Dec 2021 11:08:12 +0900 Subject: [PATCH 006/112] Merge the latest embedder (v.2.8.0) (#242) Update for v 2.8.0 --- .../shell/platform/embedder/embedder.h | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/flutter/shell/platform/embedder/embedder.h b/src/flutter/shell/platform/embedder/embedder.h index 0a63b558..e8b769ef 100644 --- a/src/flutter/shell/platform/embedder/embedder.h +++ b/src/flutter/shell/platform/embedder/embedder.h @@ -313,6 +313,7 @@ typedef bool (*TextureFrameCallback)(void* /* user data */, size_t /* height */, FlutterOpenGLTexture* /* texture out */); typedef void (*VsyncCallback)(void* /* user data */, intptr_t /* baton */); +typedef void (*OnPreEngineRestartCallback)(void* /* user data */); /// A structure to represent the width and height. typedef struct { @@ -371,7 +372,7 @@ typedef uint32_t (*UIntFrameInfoCallback)( /// /// See: \ref FlutterOpenGLRendererConfig.present_with_info. typedef struct { - /// The size of this struct. Must be sizeof(FlutterFrameInfo). + /// The size of this struct. Must be sizeof(FlutterPresentInfo). size_t struct_size; /// Id of the fbo backing the surface that was presented. uint32_t fbo_id; @@ -1394,9 +1395,10 @@ typedef struct { /// `switches.h` engine source file. const char* const* command_line_argv; /// The callback invoked by the engine in order to give the embedder the - /// chance to respond to platform messages from the Dart application. The - /// callback will be invoked on the thread on which the `FlutterEngineRun` - /// call is made. + /// chance to respond to platform messages from the Dart application. + /// The callback will be invoked on the thread on which the `FlutterEngineRun` + /// call is made. The second parameter, `user_data`, is supplied when + /// `FlutterEngineRun` or `FlutterEngineInitialize` is called. FlutterPlatformMessageCallback platform_message_callback; /// The VM snapshot data buffer used in AOT operation. This buffer must be /// mapped in as read-only. For more information refer to the documentation on @@ -1577,6 +1579,16 @@ typedef struct { // or component name to embedder's logger. This string will be passed to to // callbacks on `log_message_callback`. Defaults to "flutter" if unspecified. const char* log_tag; + + // A callback that is invoked right before the engine is restarted. + // + // This optional callback is typically used to reset states to as if the + // engine has just been started, and usually indicates the user has requested + // a hot restart (Shift-R in the Flutter CLI.) It is not called the first time + // the engine starts. + // + // The first argument is the `user_data` from `FlutterEngineInitialize`. + OnPreEngineRestartCallback on_pre_engine_restart_callback; } FlutterProjectArgs; #ifndef FLUTTER_ENGINE_NO_PROTOTYPES From 7e390a500dc4be92d52c7d13d5b061ecce0422ca Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Mon, 21 Feb 2022 14:38:59 +0900 Subject: [PATCH 007/112] Add window rotation support (#250) See https://github.com/sony/flutter-embedded-linux/issues/248 --- .../command_options.h | 62 +++++++++---- .../flutter_embedder_options.h | 40 ++++++-- .../flutter-drm-eglstream-backend/main.cc | 1 + .../flutter-drm-gbm-backend/command_options.h | 62 +++++++++---- .../flutter_embedder_options.h | 40 ++++++-- examples/flutter-drm-gbm-backend/main.cc | 1 + .../command_options.h | 62 +++++++++---- .../flutter_embedder_options.h | 40 ++++++-- .../flutter-external-texture-plugin/main.cc | 1 + .../command_options.h | 62 +++++++++---- .../flutter_embedder_options.h | 40 ++++++-- examples/flutter-video-player-plugin/main.cc | 1 + .../flutter-wayland-client/command_options.h | 62 +++++++++---- .../flutter_embedder_options.h | 40 ++++++-- examples/flutter-wayland-client/main.cc | 1 + examples/flutter-x11-client/command_options.h | 62 +++++++++---- .../flutter_embedder_options.h | 40 ++++++-- examples/flutter-x11-client/main.cc | 1 + src/client_wrapper/flutter_view_controller.cc | 8 ++ .../include/flutter/flutter_view_controller.h | 14 +++ .../linux_embedded/flutter_elinux_engine.cc | 5 + .../linux_embedded/flutter_elinux_view.cc | 91 ++++++++++++++++--- .../linux_embedded/flutter_elinux_view.h | 13 +++ .../linux_embedded/public/flutter_elinux.h | 15 +++ .../linux_embedded/window/elinux_window.h | 13 +++ .../linux_embedded/window/elinux_window_drm.h | 21 ++++- .../window/elinux_window_wayland.cc | 16 ++++ .../window/elinux_window_wayland.h | 3 + .../window/elinux_window_x11.cc | 22 ++++- .../linux_embedded/window/elinux_window_x11.h | 3 + .../linux_embedded/window_binding_handler.h | 3 + 31 files changed, 675 insertions(+), 170 deletions(-) diff --git a/examples/flutter-drm-eglstream-backend/command_options.h b/examples/flutter-drm-eglstream-backend/command_options.h index 977cdc83..107a152d 100644 --- a/examples/flutter-drm-eglstream-backend/command_options.h +++ b/examples/flutter-drm-eglstream-backend/command_options.h @@ -39,30 +39,40 @@ class CommandOptions { CommandOptions() = default; ~CommandOptions() = default; - void AddWithoutValue(const std::string& name, const std::string& short_name, - const std::string& description, bool required) { + void AddWithoutValue(const std::string& name, + const std::string& short_name, + const std::string& description, + bool required) { Add(name, short_name, description, "", ReaderString(), required, false); } - void AddInt(const std::string& name, const std::string& short_name, - const std::string& description, const int& default_value, + void AddInt(const std::string& name, + const std::string& short_name, + const std::string& description, + const int& default_value, bool required) { Add(name, short_name, description, default_value, ReaderInt(), required, true); } - void AddString(const std::string& name, const std::string& short_name, + void AddString(const std::string& name, + const std::string& short_name, const std::string& description, - const std::string& default_value, bool required) { + const std::string& default_value, + bool required) { Add(name, short_name, description, default_value, ReaderString(), required, true); } template - void Add(const std::string& name, const std::string& short_name, - const std::string& description, const T default_value, - F reader = F(), bool required = true, bool required_value = true) { + void Add(const std::string& name, + const std::string& short_name, + const std::string& description, + const T default_value, + F reader = F(), + bool required = true, + bool required_value = true) { if (options_.find(name) != options_.end()) { std::cerr << "Already registered option: " << name << std::endl; return; @@ -213,7 +223,7 @@ class CommandOptions { } size_t index_adjust = 0; - constexpr int kSpacerNum = 5; + constexpr int kSpacerNum = 10; auto need_value = registration_order_options_[i]->IsRequiredValue(); ostream << kOptionStyleNormal << registration_order_options_[i]->GetName(); @@ -242,8 +252,11 @@ class CommandOptions { class Option { public: - Option(const std::string& name, const std::string& short_name, - const std::string& description, bool required, bool required_value) + Option(const std::string& name, + const std::string& short_name, + const std::string& description, + bool required, + bool required_value) : name_(name), short_name_(short_name), description_(description), @@ -288,9 +301,12 @@ class CommandOptions { template class OptionValue : public Option { public: - OptionValue(const std::string& name, const std::string& short_name, - const std::string& description, const T& default_value, - bool required, bool required_value) + OptionValue(const std::string& name, + const std::string& short_name, + const std::string& description, + const T& default_value, + bool required, + bool required_value) : Option(name, short_name, description, required, required_value), default_value_(default_value), value_(default_value){}; @@ -316,10 +332,18 @@ class CommandOptions { template class OptionValueReader : public OptionValue { public: - OptionValueReader(const std::string& name, const std::string& short_name, - const std::string& description, const T default_value, - F reader, bool required, bool required_value) - : OptionValue(name, short_name, description, default_value, required, + OptionValueReader(const std::string& name, + const std::string& short_name, + const std::string& description, + const T default_value, + F reader, + bool required, + bool required_value) + : OptionValue(name, + short_name, + description, + default_value, + required, required_value), reader_(reader) {} ~OptionValueReader() = default; diff --git a/examples/flutter-drm-eglstream-backend/flutter_embedder_options.h b/examples/flutter-drm-eglstream-backend/flutter_embedder_options.h index 51e378fc..4c229135 100644 --- a/examples/flutter-drm-eglstream-backend/flutter_embedder_options.h +++ b/examples/flutter-drm-eglstream-backend/flutter_embedder_options.h @@ -14,18 +14,21 @@ class FlutterEmbedderOptions { public: FlutterEmbedderOptions() { - options_.AddString("bundle", "b", "Path to Flutter app bundle", "./bundle", - true); + options_.AddString("bundle", "b", "Path to Flutter project bundle", + "./bundle", true); options_.AddWithoutValue("no-cursor", "n", "No mouse cursor/pointer", false); + options_.AddInt("rotation", "r", + "Window rotation(degree) [0(default)|90|180|270]", 0, + false); #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) // no more options. #elif defined(FLUTTER_TARGET_BACKEND_X11) options_.AddWithoutValue("fullscreen", "f", "Always full-screen display", false); - options_.AddInt("width", "w", "Flutter app window width", 1280, false); - options_.AddInt("height", "h", "Flutter app window height", 720, false); + options_.AddInt("width", "w", "Window width", 1280, false); + options_.AddInt("height", "h", "Window height", 720, false); #else // FLUTTER_TARGET_BACKEND_WAYLAND options_.AddWithoutValue("onscreen-keyboard", "k", "Enable on-screen keyboard", false); @@ -33,8 +36,8 @@ class FlutterEmbedderOptions { "Enable window decorations", false); options_.AddWithoutValue("fullscreen", "f", "Always full-screen display", false); - options_.AddInt("width", "w", "Flutter app window width", 1280, false); - options_.AddInt("height", "h", "Flutter app window height", 720, false); + options_.AddInt("width", "w", "Window width", 1280, false); + options_.AddInt("height", "h", "Window height", 720, false); #endif } ~FlutterEmbedderOptions() = default; @@ -48,6 +51,26 @@ class FlutterEmbedderOptions { bundle_path_ = options_.GetValue("bundle"); use_mouse_cursor_ = !options_.Exist("no-cursor"); + if (options_.Exist("rotation")) { + switch (options_.GetValue("rotation")) { + case 90: + window_view_rotation_ = + flutter::FlutterViewController::ViewRotation::kRotation_90; + break; + case 180: + window_view_rotation_ = + flutter::FlutterViewController::ViewRotation::kRotation_180; + break; + case 270: + window_view_rotation_ = + flutter::FlutterViewController::ViewRotation::kRotation_270; + break; + default: + window_view_rotation_ = + flutter::FlutterViewController::ViewRotation::kRotation_0; + break; + } + } #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) @@ -86,6 +109,9 @@ class FlutterEmbedderOptions { } int WindowWidth() const { return window_width_; } int WindowHeight() const { return window_height_; } + flutter::FlutterViewController::ViewRotation WindowRotation() const { + return window_view_rotation_; + } private: commandline::CommandOptions options_; @@ -98,6 +124,8 @@ class FlutterEmbedderOptions { flutter::FlutterViewController::ViewMode::kNormal; int window_width_ = 1280; int window_height_ = 720; + flutter::FlutterViewController::ViewRotation window_view_rotation_ = + flutter::FlutterViewController::ViewRotation::kRotation_0; }; #endif // FLUTTER_EMBEDDER_OPTIONS_ diff --git a/examples/flutter-drm-eglstream-backend/main.cc b/examples/flutter-drm-eglstream-backend/main.cc index 92a6513c..fa4e11b8 100644 --- a/examples/flutter-drm-eglstream-backend/main.cc +++ b/examples/flutter-drm-eglstream-backend/main.cc @@ -29,6 +29,7 @@ int main(int argc, char** argv) { view_properties.width = options.WindowWidth(); view_properties.height = options.WindowHeight(); view_properties.view_mode = options.WindowViewMode(); + view_properties.view_rotation = options.WindowRotation(); view_properties.use_mouse_cursor = options.IsUseMouseCursor(); view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); view_properties.use_window_decoration = options.IsUseWindowDecoraation(); diff --git a/examples/flutter-drm-gbm-backend/command_options.h b/examples/flutter-drm-gbm-backend/command_options.h index 977cdc83..107a152d 100644 --- a/examples/flutter-drm-gbm-backend/command_options.h +++ b/examples/flutter-drm-gbm-backend/command_options.h @@ -39,30 +39,40 @@ class CommandOptions { CommandOptions() = default; ~CommandOptions() = default; - void AddWithoutValue(const std::string& name, const std::string& short_name, - const std::string& description, bool required) { + void AddWithoutValue(const std::string& name, + const std::string& short_name, + const std::string& description, + bool required) { Add(name, short_name, description, "", ReaderString(), required, false); } - void AddInt(const std::string& name, const std::string& short_name, - const std::string& description, const int& default_value, + void AddInt(const std::string& name, + const std::string& short_name, + const std::string& description, + const int& default_value, bool required) { Add(name, short_name, description, default_value, ReaderInt(), required, true); } - void AddString(const std::string& name, const std::string& short_name, + void AddString(const std::string& name, + const std::string& short_name, const std::string& description, - const std::string& default_value, bool required) { + const std::string& default_value, + bool required) { Add(name, short_name, description, default_value, ReaderString(), required, true); } template - void Add(const std::string& name, const std::string& short_name, - const std::string& description, const T default_value, - F reader = F(), bool required = true, bool required_value = true) { + void Add(const std::string& name, + const std::string& short_name, + const std::string& description, + const T default_value, + F reader = F(), + bool required = true, + bool required_value = true) { if (options_.find(name) != options_.end()) { std::cerr << "Already registered option: " << name << std::endl; return; @@ -213,7 +223,7 @@ class CommandOptions { } size_t index_adjust = 0; - constexpr int kSpacerNum = 5; + constexpr int kSpacerNum = 10; auto need_value = registration_order_options_[i]->IsRequiredValue(); ostream << kOptionStyleNormal << registration_order_options_[i]->GetName(); @@ -242,8 +252,11 @@ class CommandOptions { class Option { public: - Option(const std::string& name, const std::string& short_name, - const std::string& description, bool required, bool required_value) + Option(const std::string& name, + const std::string& short_name, + const std::string& description, + bool required, + bool required_value) : name_(name), short_name_(short_name), description_(description), @@ -288,9 +301,12 @@ class CommandOptions { template class OptionValue : public Option { public: - OptionValue(const std::string& name, const std::string& short_name, - const std::string& description, const T& default_value, - bool required, bool required_value) + OptionValue(const std::string& name, + const std::string& short_name, + const std::string& description, + const T& default_value, + bool required, + bool required_value) : Option(name, short_name, description, required, required_value), default_value_(default_value), value_(default_value){}; @@ -316,10 +332,18 @@ class CommandOptions { template class OptionValueReader : public OptionValue { public: - OptionValueReader(const std::string& name, const std::string& short_name, - const std::string& description, const T default_value, - F reader, bool required, bool required_value) - : OptionValue(name, short_name, description, default_value, required, + OptionValueReader(const std::string& name, + const std::string& short_name, + const std::string& description, + const T default_value, + F reader, + bool required, + bool required_value) + : OptionValue(name, + short_name, + description, + default_value, + required, required_value), reader_(reader) {} ~OptionValueReader() = default; diff --git a/examples/flutter-drm-gbm-backend/flutter_embedder_options.h b/examples/flutter-drm-gbm-backend/flutter_embedder_options.h index 51e378fc..4c229135 100644 --- a/examples/flutter-drm-gbm-backend/flutter_embedder_options.h +++ b/examples/flutter-drm-gbm-backend/flutter_embedder_options.h @@ -14,18 +14,21 @@ class FlutterEmbedderOptions { public: FlutterEmbedderOptions() { - options_.AddString("bundle", "b", "Path to Flutter app bundle", "./bundle", - true); + options_.AddString("bundle", "b", "Path to Flutter project bundle", + "./bundle", true); options_.AddWithoutValue("no-cursor", "n", "No mouse cursor/pointer", false); + options_.AddInt("rotation", "r", + "Window rotation(degree) [0(default)|90|180|270]", 0, + false); #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) // no more options. #elif defined(FLUTTER_TARGET_BACKEND_X11) options_.AddWithoutValue("fullscreen", "f", "Always full-screen display", false); - options_.AddInt("width", "w", "Flutter app window width", 1280, false); - options_.AddInt("height", "h", "Flutter app window height", 720, false); + options_.AddInt("width", "w", "Window width", 1280, false); + options_.AddInt("height", "h", "Window height", 720, false); #else // FLUTTER_TARGET_BACKEND_WAYLAND options_.AddWithoutValue("onscreen-keyboard", "k", "Enable on-screen keyboard", false); @@ -33,8 +36,8 @@ class FlutterEmbedderOptions { "Enable window decorations", false); options_.AddWithoutValue("fullscreen", "f", "Always full-screen display", false); - options_.AddInt("width", "w", "Flutter app window width", 1280, false); - options_.AddInt("height", "h", "Flutter app window height", 720, false); + options_.AddInt("width", "w", "Window width", 1280, false); + options_.AddInt("height", "h", "Window height", 720, false); #endif } ~FlutterEmbedderOptions() = default; @@ -48,6 +51,26 @@ class FlutterEmbedderOptions { bundle_path_ = options_.GetValue("bundle"); use_mouse_cursor_ = !options_.Exist("no-cursor"); + if (options_.Exist("rotation")) { + switch (options_.GetValue("rotation")) { + case 90: + window_view_rotation_ = + flutter::FlutterViewController::ViewRotation::kRotation_90; + break; + case 180: + window_view_rotation_ = + flutter::FlutterViewController::ViewRotation::kRotation_180; + break; + case 270: + window_view_rotation_ = + flutter::FlutterViewController::ViewRotation::kRotation_270; + break; + default: + window_view_rotation_ = + flutter::FlutterViewController::ViewRotation::kRotation_0; + break; + } + } #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) @@ -86,6 +109,9 @@ class FlutterEmbedderOptions { } int WindowWidth() const { return window_width_; } int WindowHeight() const { return window_height_; } + flutter::FlutterViewController::ViewRotation WindowRotation() const { + return window_view_rotation_; + } private: commandline::CommandOptions options_; @@ -98,6 +124,8 @@ class FlutterEmbedderOptions { flutter::FlutterViewController::ViewMode::kNormal; int window_width_ = 1280; int window_height_ = 720; + flutter::FlutterViewController::ViewRotation window_view_rotation_ = + flutter::FlutterViewController::ViewRotation::kRotation_0; }; #endif // FLUTTER_EMBEDDER_OPTIONS_ diff --git a/examples/flutter-drm-gbm-backend/main.cc b/examples/flutter-drm-gbm-backend/main.cc index 92a6513c..fa4e11b8 100644 --- a/examples/flutter-drm-gbm-backend/main.cc +++ b/examples/flutter-drm-gbm-backend/main.cc @@ -29,6 +29,7 @@ int main(int argc, char** argv) { view_properties.width = options.WindowWidth(); view_properties.height = options.WindowHeight(); view_properties.view_mode = options.WindowViewMode(); + view_properties.view_rotation = options.WindowRotation(); view_properties.use_mouse_cursor = options.IsUseMouseCursor(); view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); view_properties.use_window_decoration = options.IsUseWindowDecoraation(); diff --git a/examples/flutter-external-texture-plugin/command_options.h b/examples/flutter-external-texture-plugin/command_options.h index 977cdc83..107a152d 100644 --- a/examples/flutter-external-texture-plugin/command_options.h +++ b/examples/flutter-external-texture-plugin/command_options.h @@ -39,30 +39,40 @@ class CommandOptions { CommandOptions() = default; ~CommandOptions() = default; - void AddWithoutValue(const std::string& name, const std::string& short_name, - const std::string& description, bool required) { + void AddWithoutValue(const std::string& name, + const std::string& short_name, + const std::string& description, + bool required) { Add(name, short_name, description, "", ReaderString(), required, false); } - void AddInt(const std::string& name, const std::string& short_name, - const std::string& description, const int& default_value, + void AddInt(const std::string& name, + const std::string& short_name, + const std::string& description, + const int& default_value, bool required) { Add(name, short_name, description, default_value, ReaderInt(), required, true); } - void AddString(const std::string& name, const std::string& short_name, + void AddString(const std::string& name, + const std::string& short_name, const std::string& description, - const std::string& default_value, bool required) { + const std::string& default_value, + bool required) { Add(name, short_name, description, default_value, ReaderString(), required, true); } template - void Add(const std::string& name, const std::string& short_name, - const std::string& description, const T default_value, - F reader = F(), bool required = true, bool required_value = true) { + void Add(const std::string& name, + const std::string& short_name, + const std::string& description, + const T default_value, + F reader = F(), + bool required = true, + bool required_value = true) { if (options_.find(name) != options_.end()) { std::cerr << "Already registered option: " << name << std::endl; return; @@ -213,7 +223,7 @@ class CommandOptions { } size_t index_adjust = 0; - constexpr int kSpacerNum = 5; + constexpr int kSpacerNum = 10; auto need_value = registration_order_options_[i]->IsRequiredValue(); ostream << kOptionStyleNormal << registration_order_options_[i]->GetName(); @@ -242,8 +252,11 @@ class CommandOptions { class Option { public: - Option(const std::string& name, const std::string& short_name, - const std::string& description, bool required, bool required_value) + Option(const std::string& name, + const std::string& short_name, + const std::string& description, + bool required, + bool required_value) : name_(name), short_name_(short_name), description_(description), @@ -288,9 +301,12 @@ class CommandOptions { template class OptionValue : public Option { public: - OptionValue(const std::string& name, const std::string& short_name, - const std::string& description, const T& default_value, - bool required, bool required_value) + OptionValue(const std::string& name, + const std::string& short_name, + const std::string& description, + const T& default_value, + bool required, + bool required_value) : Option(name, short_name, description, required, required_value), default_value_(default_value), value_(default_value){}; @@ -316,10 +332,18 @@ class CommandOptions { template class OptionValueReader : public OptionValue { public: - OptionValueReader(const std::string& name, const std::string& short_name, - const std::string& description, const T default_value, - F reader, bool required, bool required_value) - : OptionValue(name, short_name, description, default_value, required, + OptionValueReader(const std::string& name, + const std::string& short_name, + const std::string& description, + const T default_value, + F reader, + bool required, + bool required_value) + : OptionValue(name, + short_name, + description, + default_value, + required, required_value), reader_(reader) {} ~OptionValueReader() = default; diff --git a/examples/flutter-external-texture-plugin/flutter_embedder_options.h b/examples/flutter-external-texture-plugin/flutter_embedder_options.h index 51e378fc..4c229135 100644 --- a/examples/flutter-external-texture-plugin/flutter_embedder_options.h +++ b/examples/flutter-external-texture-plugin/flutter_embedder_options.h @@ -14,18 +14,21 @@ class FlutterEmbedderOptions { public: FlutterEmbedderOptions() { - options_.AddString("bundle", "b", "Path to Flutter app bundle", "./bundle", - true); + options_.AddString("bundle", "b", "Path to Flutter project bundle", + "./bundle", true); options_.AddWithoutValue("no-cursor", "n", "No mouse cursor/pointer", false); + options_.AddInt("rotation", "r", + "Window rotation(degree) [0(default)|90|180|270]", 0, + false); #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) // no more options. #elif defined(FLUTTER_TARGET_BACKEND_X11) options_.AddWithoutValue("fullscreen", "f", "Always full-screen display", false); - options_.AddInt("width", "w", "Flutter app window width", 1280, false); - options_.AddInt("height", "h", "Flutter app window height", 720, false); + options_.AddInt("width", "w", "Window width", 1280, false); + options_.AddInt("height", "h", "Window height", 720, false); #else // FLUTTER_TARGET_BACKEND_WAYLAND options_.AddWithoutValue("onscreen-keyboard", "k", "Enable on-screen keyboard", false); @@ -33,8 +36,8 @@ class FlutterEmbedderOptions { "Enable window decorations", false); options_.AddWithoutValue("fullscreen", "f", "Always full-screen display", false); - options_.AddInt("width", "w", "Flutter app window width", 1280, false); - options_.AddInt("height", "h", "Flutter app window height", 720, false); + options_.AddInt("width", "w", "Window width", 1280, false); + options_.AddInt("height", "h", "Window height", 720, false); #endif } ~FlutterEmbedderOptions() = default; @@ -48,6 +51,26 @@ class FlutterEmbedderOptions { bundle_path_ = options_.GetValue("bundle"); use_mouse_cursor_ = !options_.Exist("no-cursor"); + if (options_.Exist("rotation")) { + switch (options_.GetValue("rotation")) { + case 90: + window_view_rotation_ = + flutter::FlutterViewController::ViewRotation::kRotation_90; + break; + case 180: + window_view_rotation_ = + flutter::FlutterViewController::ViewRotation::kRotation_180; + break; + case 270: + window_view_rotation_ = + flutter::FlutterViewController::ViewRotation::kRotation_270; + break; + default: + window_view_rotation_ = + flutter::FlutterViewController::ViewRotation::kRotation_0; + break; + } + } #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) @@ -86,6 +109,9 @@ class FlutterEmbedderOptions { } int WindowWidth() const { return window_width_; } int WindowHeight() const { return window_height_; } + flutter::FlutterViewController::ViewRotation WindowRotation() const { + return window_view_rotation_; + } private: commandline::CommandOptions options_; @@ -98,6 +124,8 @@ class FlutterEmbedderOptions { flutter::FlutterViewController::ViewMode::kNormal; int window_width_ = 1280; int window_height_ = 720; + flutter::FlutterViewController::ViewRotation window_view_rotation_ = + flutter::FlutterViewController::ViewRotation::kRotation_0; }; #endif // FLUTTER_EMBEDDER_OPTIONS_ diff --git a/examples/flutter-external-texture-plugin/main.cc b/examples/flutter-external-texture-plugin/main.cc index 92a6513c..fa4e11b8 100644 --- a/examples/flutter-external-texture-plugin/main.cc +++ b/examples/flutter-external-texture-plugin/main.cc @@ -29,6 +29,7 @@ int main(int argc, char** argv) { view_properties.width = options.WindowWidth(); view_properties.height = options.WindowHeight(); view_properties.view_mode = options.WindowViewMode(); + view_properties.view_rotation = options.WindowRotation(); view_properties.use_mouse_cursor = options.IsUseMouseCursor(); view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); view_properties.use_window_decoration = options.IsUseWindowDecoraation(); diff --git a/examples/flutter-video-player-plugin/command_options.h b/examples/flutter-video-player-plugin/command_options.h index 977cdc83..107a152d 100644 --- a/examples/flutter-video-player-plugin/command_options.h +++ b/examples/flutter-video-player-plugin/command_options.h @@ -39,30 +39,40 @@ class CommandOptions { CommandOptions() = default; ~CommandOptions() = default; - void AddWithoutValue(const std::string& name, const std::string& short_name, - const std::string& description, bool required) { + void AddWithoutValue(const std::string& name, + const std::string& short_name, + const std::string& description, + bool required) { Add(name, short_name, description, "", ReaderString(), required, false); } - void AddInt(const std::string& name, const std::string& short_name, - const std::string& description, const int& default_value, + void AddInt(const std::string& name, + const std::string& short_name, + const std::string& description, + const int& default_value, bool required) { Add(name, short_name, description, default_value, ReaderInt(), required, true); } - void AddString(const std::string& name, const std::string& short_name, + void AddString(const std::string& name, + const std::string& short_name, const std::string& description, - const std::string& default_value, bool required) { + const std::string& default_value, + bool required) { Add(name, short_name, description, default_value, ReaderString(), required, true); } template - void Add(const std::string& name, const std::string& short_name, - const std::string& description, const T default_value, - F reader = F(), bool required = true, bool required_value = true) { + void Add(const std::string& name, + const std::string& short_name, + const std::string& description, + const T default_value, + F reader = F(), + bool required = true, + bool required_value = true) { if (options_.find(name) != options_.end()) { std::cerr << "Already registered option: " << name << std::endl; return; @@ -213,7 +223,7 @@ class CommandOptions { } size_t index_adjust = 0; - constexpr int kSpacerNum = 5; + constexpr int kSpacerNum = 10; auto need_value = registration_order_options_[i]->IsRequiredValue(); ostream << kOptionStyleNormal << registration_order_options_[i]->GetName(); @@ -242,8 +252,11 @@ class CommandOptions { class Option { public: - Option(const std::string& name, const std::string& short_name, - const std::string& description, bool required, bool required_value) + Option(const std::string& name, + const std::string& short_name, + const std::string& description, + bool required, + bool required_value) : name_(name), short_name_(short_name), description_(description), @@ -288,9 +301,12 @@ class CommandOptions { template class OptionValue : public Option { public: - OptionValue(const std::string& name, const std::string& short_name, - const std::string& description, const T& default_value, - bool required, bool required_value) + OptionValue(const std::string& name, + const std::string& short_name, + const std::string& description, + const T& default_value, + bool required, + bool required_value) : Option(name, short_name, description, required, required_value), default_value_(default_value), value_(default_value){}; @@ -316,10 +332,18 @@ class CommandOptions { template class OptionValueReader : public OptionValue { public: - OptionValueReader(const std::string& name, const std::string& short_name, - const std::string& description, const T default_value, - F reader, bool required, bool required_value) - : OptionValue(name, short_name, description, default_value, required, + OptionValueReader(const std::string& name, + const std::string& short_name, + const std::string& description, + const T default_value, + F reader, + bool required, + bool required_value) + : OptionValue(name, + short_name, + description, + default_value, + required, required_value), reader_(reader) {} ~OptionValueReader() = default; diff --git a/examples/flutter-video-player-plugin/flutter_embedder_options.h b/examples/flutter-video-player-plugin/flutter_embedder_options.h index 51e378fc..4c229135 100644 --- a/examples/flutter-video-player-plugin/flutter_embedder_options.h +++ b/examples/flutter-video-player-plugin/flutter_embedder_options.h @@ -14,18 +14,21 @@ class FlutterEmbedderOptions { public: FlutterEmbedderOptions() { - options_.AddString("bundle", "b", "Path to Flutter app bundle", "./bundle", - true); + options_.AddString("bundle", "b", "Path to Flutter project bundle", + "./bundle", true); options_.AddWithoutValue("no-cursor", "n", "No mouse cursor/pointer", false); + options_.AddInt("rotation", "r", + "Window rotation(degree) [0(default)|90|180|270]", 0, + false); #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) // no more options. #elif defined(FLUTTER_TARGET_BACKEND_X11) options_.AddWithoutValue("fullscreen", "f", "Always full-screen display", false); - options_.AddInt("width", "w", "Flutter app window width", 1280, false); - options_.AddInt("height", "h", "Flutter app window height", 720, false); + options_.AddInt("width", "w", "Window width", 1280, false); + options_.AddInt("height", "h", "Window height", 720, false); #else // FLUTTER_TARGET_BACKEND_WAYLAND options_.AddWithoutValue("onscreen-keyboard", "k", "Enable on-screen keyboard", false); @@ -33,8 +36,8 @@ class FlutterEmbedderOptions { "Enable window decorations", false); options_.AddWithoutValue("fullscreen", "f", "Always full-screen display", false); - options_.AddInt("width", "w", "Flutter app window width", 1280, false); - options_.AddInt("height", "h", "Flutter app window height", 720, false); + options_.AddInt("width", "w", "Window width", 1280, false); + options_.AddInt("height", "h", "Window height", 720, false); #endif } ~FlutterEmbedderOptions() = default; @@ -48,6 +51,26 @@ class FlutterEmbedderOptions { bundle_path_ = options_.GetValue("bundle"); use_mouse_cursor_ = !options_.Exist("no-cursor"); + if (options_.Exist("rotation")) { + switch (options_.GetValue("rotation")) { + case 90: + window_view_rotation_ = + flutter::FlutterViewController::ViewRotation::kRotation_90; + break; + case 180: + window_view_rotation_ = + flutter::FlutterViewController::ViewRotation::kRotation_180; + break; + case 270: + window_view_rotation_ = + flutter::FlutterViewController::ViewRotation::kRotation_270; + break; + default: + window_view_rotation_ = + flutter::FlutterViewController::ViewRotation::kRotation_0; + break; + } + } #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) @@ -86,6 +109,9 @@ class FlutterEmbedderOptions { } int WindowWidth() const { return window_width_; } int WindowHeight() const { return window_height_; } + flutter::FlutterViewController::ViewRotation WindowRotation() const { + return window_view_rotation_; + } private: commandline::CommandOptions options_; @@ -98,6 +124,8 @@ class FlutterEmbedderOptions { flutter::FlutterViewController::ViewMode::kNormal; int window_width_ = 1280; int window_height_ = 720; + flutter::FlutterViewController::ViewRotation window_view_rotation_ = + flutter::FlutterViewController::ViewRotation::kRotation_0; }; #endif // FLUTTER_EMBEDDER_OPTIONS_ diff --git a/examples/flutter-video-player-plugin/main.cc b/examples/flutter-video-player-plugin/main.cc index 92a6513c..fa4e11b8 100644 --- a/examples/flutter-video-player-plugin/main.cc +++ b/examples/flutter-video-player-plugin/main.cc @@ -29,6 +29,7 @@ int main(int argc, char** argv) { view_properties.width = options.WindowWidth(); view_properties.height = options.WindowHeight(); view_properties.view_mode = options.WindowViewMode(); + view_properties.view_rotation = options.WindowRotation(); view_properties.use_mouse_cursor = options.IsUseMouseCursor(); view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); view_properties.use_window_decoration = options.IsUseWindowDecoraation(); diff --git a/examples/flutter-wayland-client/command_options.h b/examples/flutter-wayland-client/command_options.h index 977cdc83..107a152d 100644 --- a/examples/flutter-wayland-client/command_options.h +++ b/examples/flutter-wayland-client/command_options.h @@ -39,30 +39,40 @@ class CommandOptions { CommandOptions() = default; ~CommandOptions() = default; - void AddWithoutValue(const std::string& name, const std::string& short_name, - const std::string& description, bool required) { + void AddWithoutValue(const std::string& name, + const std::string& short_name, + const std::string& description, + bool required) { Add(name, short_name, description, "", ReaderString(), required, false); } - void AddInt(const std::string& name, const std::string& short_name, - const std::string& description, const int& default_value, + void AddInt(const std::string& name, + const std::string& short_name, + const std::string& description, + const int& default_value, bool required) { Add(name, short_name, description, default_value, ReaderInt(), required, true); } - void AddString(const std::string& name, const std::string& short_name, + void AddString(const std::string& name, + const std::string& short_name, const std::string& description, - const std::string& default_value, bool required) { + const std::string& default_value, + bool required) { Add(name, short_name, description, default_value, ReaderString(), required, true); } template - void Add(const std::string& name, const std::string& short_name, - const std::string& description, const T default_value, - F reader = F(), bool required = true, bool required_value = true) { + void Add(const std::string& name, + const std::string& short_name, + const std::string& description, + const T default_value, + F reader = F(), + bool required = true, + bool required_value = true) { if (options_.find(name) != options_.end()) { std::cerr << "Already registered option: " << name << std::endl; return; @@ -213,7 +223,7 @@ class CommandOptions { } size_t index_adjust = 0; - constexpr int kSpacerNum = 5; + constexpr int kSpacerNum = 10; auto need_value = registration_order_options_[i]->IsRequiredValue(); ostream << kOptionStyleNormal << registration_order_options_[i]->GetName(); @@ -242,8 +252,11 @@ class CommandOptions { class Option { public: - Option(const std::string& name, const std::string& short_name, - const std::string& description, bool required, bool required_value) + Option(const std::string& name, + const std::string& short_name, + const std::string& description, + bool required, + bool required_value) : name_(name), short_name_(short_name), description_(description), @@ -288,9 +301,12 @@ class CommandOptions { template class OptionValue : public Option { public: - OptionValue(const std::string& name, const std::string& short_name, - const std::string& description, const T& default_value, - bool required, bool required_value) + OptionValue(const std::string& name, + const std::string& short_name, + const std::string& description, + const T& default_value, + bool required, + bool required_value) : Option(name, short_name, description, required, required_value), default_value_(default_value), value_(default_value){}; @@ -316,10 +332,18 @@ class CommandOptions { template class OptionValueReader : public OptionValue { public: - OptionValueReader(const std::string& name, const std::string& short_name, - const std::string& description, const T default_value, - F reader, bool required, bool required_value) - : OptionValue(name, short_name, description, default_value, required, + OptionValueReader(const std::string& name, + const std::string& short_name, + const std::string& description, + const T default_value, + F reader, + bool required, + bool required_value) + : OptionValue(name, + short_name, + description, + default_value, + required, required_value), reader_(reader) {} ~OptionValueReader() = default; diff --git a/examples/flutter-wayland-client/flutter_embedder_options.h b/examples/flutter-wayland-client/flutter_embedder_options.h index 51e378fc..4c229135 100644 --- a/examples/flutter-wayland-client/flutter_embedder_options.h +++ b/examples/flutter-wayland-client/flutter_embedder_options.h @@ -14,18 +14,21 @@ class FlutterEmbedderOptions { public: FlutterEmbedderOptions() { - options_.AddString("bundle", "b", "Path to Flutter app bundle", "./bundle", - true); + options_.AddString("bundle", "b", "Path to Flutter project bundle", + "./bundle", true); options_.AddWithoutValue("no-cursor", "n", "No mouse cursor/pointer", false); + options_.AddInt("rotation", "r", + "Window rotation(degree) [0(default)|90|180|270]", 0, + false); #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) // no more options. #elif defined(FLUTTER_TARGET_BACKEND_X11) options_.AddWithoutValue("fullscreen", "f", "Always full-screen display", false); - options_.AddInt("width", "w", "Flutter app window width", 1280, false); - options_.AddInt("height", "h", "Flutter app window height", 720, false); + options_.AddInt("width", "w", "Window width", 1280, false); + options_.AddInt("height", "h", "Window height", 720, false); #else // FLUTTER_TARGET_BACKEND_WAYLAND options_.AddWithoutValue("onscreen-keyboard", "k", "Enable on-screen keyboard", false); @@ -33,8 +36,8 @@ class FlutterEmbedderOptions { "Enable window decorations", false); options_.AddWithoutValue("fullscreen", "f", "Always full-screen display", false); - options_.AddInt("width", "w", "Flutter app window width", 1280, false); - options_.AddInt("height", "h", "Flutter app window height", 720, false); + options_.AddInt("width", "w", "Window width", 1280, false); + options_.AddInt("height", "h", "Window height", 720, false); #endif } ~FlutterEmbedderOptions() = default; @@ -48,6 +51,26 @@ class FlutterEmbedderOptions { bundle_path_ = options_.GetValue("bundle"); use_mouse_cursor_ = !options_.Exist("no-cursor"); + if (options_.Exist("rotation")) { + switch (options_.GetValue("rotation")) { + case 90: + window_view_rotation_ = + flutter::FlutterViewController::ViewRotation::kRotation_90; + break; + case 180: + window_view_rotation_ = + flutter::FlutterViewController::ViewRotation::kRotation_180; + break; + case 270: + window_view_rotation_ = + flutter::FlutterViewController::ViewRotation::kRotation_270; + break; + default: + window_view_rotation_ = + flutter::FlutterViewController::ViewRotation::kRotation_0; + break; + } + } #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) @@ -86,6 +109,9 @@ class FlutterEmbedderOptions { } int WindowWidth() const { return window_width_; } int WindowHeight() const { return window_height_; } + flutter::FlutterViewController::ViewRotation WindowRotation() const { + return window_view_rotation_; + } private: commandline::CommandOptions options_; @@ -98,6 +124,8 @@ class FlutterEmbedderOptions { flutter::FlutterViewController::ViewMode::kNormal; int window_width_ = 1280; int window_height_ = 720; + flutter::FlutterViewController::ViewRotation window_view_rotation_ = + flutter::FlutterViewController::ViewRotation::kRotation_0; }; #endif // FLUTTER_EMBEDDER_OPTIONS_ diff --git a/examples/flutter-wayland-client/main.cc b/examples/flutter-wayland-client/main.cc index 92a6513c..fa4e11b8 100644 --- a/examples/flutter-wayland-client/main.cc +++ b/examples/flutter-wayland-client/main.cc @@ -29,6 +29,7 @@ int main(int argc, char** argv) { view_properties.width = options.WindowWidth(); view_properties.height = options.WindowHeight(); view_properties.view_mode = options.WindowViewMode(); + view_properties.view_rotation = options.WindowRotation(); view_properties.use_mouse_cursor = options.IsUseMouseCursor(); view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); view_properties.use_window_decoration = options.IsUseWindowDecoraation(); diff --git a/examples/flutter-x11-client/command_options.h b/examples/flutter-x11-client/command_options.h index 977cdc83..107a152d 100644 --- a/examples/flutter-x11-client/command_options.h +++ b/examples/flutter-x11-client/command_options.h @@ -39,30 +39,40 @@ class CommandOptions { CommandOptions() = default; ~CommandOptions() = default; - void AddWithoutValue(const std::string& name, const std::string& short_name, - const std::string& description, bool required) { + void AddWithoutValue(const std::string& name, + const std::string& short_name, + const std::string& description, + bool required) { Add(name, short_name, description, "", ReaderString(), required, false); } - void AddInt(const std::string& name, const std::string& short_name, - const std::string& description, const int& default_value, + void AddInt(const std::string& name, + const std::string& short_name, + const std::string& description, + const int& default_value, bool required) { Add(name, short_name, description, default_value, ReaderInt(), required, true); } - void AddString(const std::string& name, const std::string& short_name, + void AddString(const std::string& name, + const std::string& short_name, const std::string& description, - const std::string& default_value, bool required) { + const std::string& default_value, + bool required) { Add(name, short_name, description, default_value, ReaderString(), required, true); } template - void Add(const std::string& name, const std::string& short_name, - const std::string& description, const T default_value, - F reader = F(), bool required = true, bool required_value = true) { + void Add(const std::string& name, + const std::string& short_name, + const std::string& description, + const T default_value, + F reader = F(), + bool required = true, + bool required_value = true) { if (options_.find(name) != options_.end()) { std::cerr << "Already registered option: " << name << std::endl; return; @@ -213,7 +223,7 @@ class CommandOptions { } size_t index_adjust = 0; - constexpr int kSpacerNum = 5; + constexpr int kSpacerNum = 10; auto need_value = registration_order_options_[i]->IsRequiredValue(); ostream << kOptionStyleNormal << registration_order_options_[i]->GetName(); @@ -242,8 +252,11 @@ class CommandOptions { class Option { public: - Option(const std::string& name, const std::string& short_name, - const std::string& description, bool required, bool required_value) + Option(const std::string& name, + const std::string& short_name, + const std::string& description, + bool required, + bool required_value) : name_(name), short_name_(short_name), description_(description), @@ -288,9 +301,12 @@ class CommandOptions { template class OptionValue : public Option { public: - OptionValue(const std::string& name, const std::string& short_name, - const std::string& description, const T& default_value, - bool required, bool required_value) + OptionValue(const std::string& name, + const std::string& short_name, + const std::string& description, + const T& default_value, + bool required, + bool required_value) : Option(name, short_name, description, required, required_value), default_value_(default_value), value_(default_value){}; @@ -316,10 +332,18 @@ class CommandOptions { template class OptionValueReader : public OptionValue { public: - OptionValueReader(const std::string& name, const std::string& short_name, - const std::string& description, const T default_value, - F reader, bool required, bool required_value) - : OptionValue(name, short_name, description, default_value, required, + OptionValueReader(const std::string& name, + const std::string& short_name, + const std::string& description, + const T default_value, + F reader, + bool required, + bool required_value) + : OptionValue(name, + short_name, + description, + default_value, + required, required_value), reader_(reader) {} ~OptionValueReader() = default; diff --git a/examples/flutter-x11-client/flutter_embedder_options.h b/examples/flutter-x11-client/flutter_embedder_options.h index 51e378fc..4c229135 100644 --- a/examples/flutter-x11-client/flutter_embedder_options.h +++ b/examples/flutter-x11-client/flutter_embedder_options.h @@ -14,18 +14,21 @@ class FlutterEmbedderOptions { public: FlutterEmbedderOptions() { - options_.AddString("bundle", "b", "Path to Flutter app bundle", "./bundle", - true); + options_.AddString("bundle", "b", "Path to Flutter project bundle", + "./bundle", true); options_.AddWithoutValue("no-cursor", "n", "No mouse cursor/pointer", false); + options_.AddInt("rotation", "r", + "Window rotation(degree) [0(default)|90|180|270]", 0, + false); #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) // no more options. #elif defined(FLUTTER_TARGET_BACKEND_X11) options_.AddWithoutValue("fullscreen", "f", "Always full-screen display", false); - options_.AddInt("width", "w", "Flutter app window width", 1280, false); - options_.AddInt("height", "h", "Flutter app window height", 720, false); + options_.AddInt("width", "w", "Window width", 1280, false); + options_.AddInt("height", "h", "Window height", 720, false); #else // FLUTTER_TARGET_BACKEND_WAYLAND options_.AddWithoutValue("onscreen-keyboard", "k", "Enable on-screen keyboard", false); @@ -33,8 +36,8 @@ class FlutterEmbedderOptions { "Enable window decorations", false); options_.AddWithoutValue("fullscreen", "f", "Always full-screen display", false); - options_.AddInt("width", "w", "Flutter app window width", 1280, false); - options_.AddInt("height", "h", "Flutter app window height", 720, false); + options_.AddInt("width", "w", "Window width", 1280, false); + options_.AddInt("height", "h", "Window height", 720, false); #endif } ~FlutterEmbedderOptions() = default; @@ -48,6 +51,26 @@ class FlutterEmbedderOptions { bundle_path_ = options_.GetValue("bundle"); use_mouse_cursor_ = !options_.Exist("no-cursor"); + if (options_.Exist("rotation")) { + switch (options_.GetValue("rotation")) { + case 90: + window_view_rotation_ = + flutter::FlutterViewController::ViewRotation::kRotation_90; + break; + case 180: + window_view_rotation_ = + flutter::FlutterViewController::ViewRotation::kRotation_180; + break; + case 270: + window_view_rotation_ = + flutter::FlutterViewController::ViewRotation::kRotation_270; + break; + default: + window_view_rotation_ = + flutter::FlutterViewController::ViewRotation::kRotation_0; + break; + } + } #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) @@ -86,6 +109,9 @@ class FlutterEmbedderOptions { } int WindowWidth() const { return window_width_; } int WindowHeight() const { return window_height_; } + flutter::FlutterViewController::ViewRotation WindowRotation() const { + return window_view_rotation_; + } private: commandline::CommandOptions options_; @@ -98,6 +124,8 @@ class FlutterEmbedderOptions { flutter::FlutterViewController::ViewMode::kNormal; int window_width_ = 1280; int window_height_ = 720; + flutter::FlutterViewController::ViewRotation window_view_rotation_ = + flutter::FlutterViewController::ViewRotation::kRotation_0; }; #endif // FLUTTER_EMBEDDER_OPTIONS_ diff --git a/examples/flutter-x11-client/main.cc b/examples/flutter-x11-client/main.cc index 92a6513c..fa4e11b8 100644 --- a/examples/flutter-x11-client/main.cc +++ b/examples/flutter-x11-client/main.cc @@ -29,6 +29,7 @@ int main(int argc, char** argv) { view_properties.width = options.WindowWidth(); view_properties.height = options.WindowHeight(); view_properties.view_mode = options.WindowViewMode(); + view_properties.view_rotation = options.WindowRotation(); view_properties.use_mouse_cursor = options.IsUseMouseCursor(); view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); view_properties.use_window_decoration = options.IsUseWindowDecoraation(); diff --git a/src/client_wrapper/flutter_view_controller.cc b/src/client_wrapper/flutter_view_controller.cc index e7b52622..8387919d 100644 --- a/src/client_wrapper/flutter_view_controller.cc +++ b/src/client_wrapper/flutter_view_controller.cc @@ -17,6 +17,14 @@ FlutterViewController::FlutterViewController( FlutterDesktopViewProperties c_view_properties = {}; c_view_properties.width = view_properties.width; c_view_properties.height = view_properties.height; + c_view_properties.view_rotation = + (view_properties.view_rotation == ViewRotation::kRotation_90) + ? FlutterDesktopViewRotation::kRotation_90 + : (view_properties.view_rotation == ViewRotation::kRotation_180) + ? FlutterDesktopViewRotation::kRotation_180 + : (view_properties.view_rotation == ViewRotation::kRotation_270) + ? FlutterDesktopViewRotation::kRotation_270 + : FlutterDesktopViewRotation::kRotation_0; c_view_properties.view_mode = (view_properties.view_mode == ViewMode::kFullscreen) ? FlutterDesktopViewMode::kFullscreen diff --git a/src/client_wrapper/include/flutter/flutter_view_controller.h b/src/client_wrapper/include/flutter/flutter_view_controller.h index 0d9926df..a5762e47 100644 --- a/src/client_wrapper/include/flutter/flutter_view_controller.h +++ b/src/client_wrapper/include/flutter/flutter_view_controller.h @@ -32,6 +32,17 @@ class FlutterViewController { kFullscreen = 1, }; + enum ViewRotation { + // Rotation constant: 0 degree rotation (natural orientation) + kRotation_0 = 0, + // Rotation constant: 90 degree rotation. + kRotation_90 = 1, + // Rotation constant: 180 degree rotation. + kRotation_180 = 2, + // Rotation constant: 270 degree rotation. + kRotation_270 = 3, + }; + // Properties for configuring a Flutter view instance. typedef struct { // View width. @@ -40,6 +51,9 @@ class FlutterViewController { // View height. int height; + // View rotation. + ViewRotation view_rotation; + // View display mode. If you set kFullscreen, the parameters of both `width` // and `height` will be ignored. ViewMode view_mode; diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc index 033cc3d5..6df08e56 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc @@ -81,6 +81,11 @@ FlutterRendererConfig GetRendererConfig() { return host->texture_registrar()->PopulateTexture(texture_id, width, height, texture); }; + config.open_gl.surface_transformation = + [](void* user_data) -> FlutterTransformation { + auto host = static_cast(user_data); + return host->view()->GetRootSurfaceTransformation(); + }; return config; } diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc index 9a85b6a9..d5461760 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc @@ -5,6 +5,7 @@ #include "flutter/shell/platform/linux_embedded/flutter_elinux_view.h" #include +#include #include "flutter/shell/platform/linux_embedded/logger.h" @@ -12,6 +13,22 @@ namespace flutter { namespace { constexpr int kMicrosecondsPerMillisecond = 1000; + +inline FlutterTransformation FlutterTransformationMake(const uint16_t& degree) { + double radian = degree * M_PI / 180.0; + FlutterTransformation transformation = {}; + transformation.scaleX = cos(radian); + transformation.skewX = -sin(radian); + transformation.transX = 0; + transformation.skewY = sin(radian); + transformation.scaleY = cos(radian); + transformation.transY = 0; + transformation.pers0 = 0; + transformation.pers1 = 0; + transformation.pers2 = 1; + return transformation; +} + } // namespace FlutterELinuxView::FlutterELinuxView( @@ -78,7 +95,8 @@ void FlutterELinuxView::OnWindowSizeChanged(size_t width, size_t height) const { } void FlutterELinuxView::OnPointerMove(double x, double y) { - SendPointerMove(x, y); + auto trimmed_xy = GetPointerRotation(x, y); + SendPointerMove(trimmed_xy.first, trimmed_xy.second); } void FlutterELinuxView::OnPointerDown( @@ -87,8 +105,9 @@ void FlutterELinuxView::OnPointerDown( FlutterPointerMouseButtons flutter_button) { if (flutter_button != 0) { uint64_t mouse_buttons = mouse_state_.buttons | flutter_button; + auto trimmed_xy = GetPointerRotation(x, y); SetMouseButtons(mouse_buttons); - SendPointerDown(x, y); + SendPointerDown(trimmed_xy.first, trimmed_xy.second); } } @@ -96,9 +115,10 @@ void FlutterELinuxView::OnPointerUp(double x, double y, FlutterPointerMouseButtons flutter_button) { if (flutter_button != 0) { + auto trimmed_xy = GetPointerRotation(x, y); uint64_t mouse_buttons = mouse_state_.buttons & ~flutter_button; SetMouseButtons(mouse_buttons); - SendPointerUp(x, y); + SendPointerUp(trimmed_xy.first, trimmed_xy.second); } } @@ -110,20 +130,21 @@ void FlutterELinuxView::OnTouchDown(uint32_t time, int32_t id, double x, double y) { + auto trimmed_xy = GetPointerRotation(x, y); auto* point = GgeTouchPoint(id); if (!point) { return; } point->event_mask = TouchEvent::kDown; - point->x = x; - point->y = y; + point->x = trimmed_xy.first; + point->y = trimmed_xy.second; FlutterPointerEvent event = { .struct_size = sizeof(event), .phase = FlutterPointerPhase::kDown, .timestamp = time * kMicrosecondsPerMillisecond, - .x = x, - .y = y, + .x = point->x, + .y = point->y, .device = id, .signal_kind = kFlutterPointerSignalKindNone, .scroll_delta_x = 0, @@ -161,20 +182,21 @@ void FlutterELinuxView::OnTouchMotion(uint32_t time, int32_t id, double x, double y) { + auto trimmed_xy = GetPointerRotation(x, y); auto* point = GgeTouchPoint(id); if (!point) { return; } point->event_mask = TouchEvent::kMotion; - point->x = x; - point->y = y; + point->x = trimmed_xy.first; + point->y = trimmed_xy.second; FlutterPointerEvent event = { .struct_size = sizeof(event), .phase = FlutterPointerPhase::kMove, .timestamp = time * kMicrosecondsPerMillisecond, - .x = x, - .y = y, + .x = point->x, + .y = point->y, .device = id, .signal_kind = kFlutterPointerSignalKindNone, .scroll_delta_x = 0, @@ -225,7 +247,9 @@ void FlutterELinuxView::OnScroll(double x, double delta_x, double delta_y, int scroll_offset_multiplier) { - SendScroll(x, y, delta_x, delta_y, scroll_offset_multiplier); + auto trimmed_xy = GetPointerRotation(x, y); + SendScroll(trimmed_xy.first, trimmed_xy.second, delta_x, delta_y, + scroll_offset_multiplier); } void FlutterELinuxView::OnVsync(uint64_t last_frame_time_nanos, @@ -419,4 +443,47 @@ int32_t FlutterELinuxView::GetFrameRate() { return binding_handler_->GetFrameRate(); } +FlutterTransformation FlutterELinuxView::GetRootSurfaceTransformation() { + auto degree = binding_handler_->GetRotationDegree(); + if (view_rotation_degree_ != degree) { + view_rotation_transformation_ = FlutterTransformationMake(degree); + } + view_rotation_degree_ = degree; + + auto bounds = binding_handler_->GetPhysicalWindowBounds(); + switch (degree) { + case 90: + view_rotation_transformation_.transX = bounds.height; + break; + case 180: + view_rotation_transformation_.transX = bounds.width; + view_rotation_transformation_.transY = bounds.height; + break; + case 270: + view_rotation_transformation_.transY = bounds.width; + break; + default: + break; + } + return view_rotation_transformation_; +} + +std::pair FlutterELinuxView::GetPointerRotation(double x, + double y) { + auto degree = binding_handler_->GetRotationDegree(); + auto bounds = binding_handler_->GetPhysicalWindowBounds(); + std::pair res = {x, y}; + + if (degree == 90) { + res.first = y; + res.second = bounds.height - x; + } else if (degree == 180) { + res.first = bounds.width - x; + res.second = bounds.height - y; + } else if (degree == 270) { + res.first = bounds.width - y; + res.second = x; + } + return res; +} } // namespace flutter diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.h b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.h index b8e057d0..1133443f 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.h +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.h @@ -61,6 +61,9 @@ class FlutterELinuxView : public WindowBindingHandlerDelegate { // Return the currently configured ELinuxRenderSurfaceTarget. ELinuxRenderSurfaceTarget* GetRenderSurfaceTarget() const; + // Returns the FlutterTransformation of this view. + FlutterTransformation GetRootSurfaceTransformation(); + // Returns the engine backing this view. FlutterELinuxEngine* GetEngine(); @@ -234,6 +237,9 @@ class FlutterELinuxView : public WindowBindingHandlerDelegate { // Updates the currently pressed buttons. void SetMouseButtons(uint64_t buttons) { mouse_state_.buttons = buttons; } + // Returns a trimmed pointer of user inputs with the window rotation. + std::pair GetPointerRotation(double x, double y); + // The engine associated with this view. std::unique_ptr engine_; @@ -269,6 +275,13 @@ class FlutterELinuxView : public WindowBindingHandlerDelegate { // Current user touch event status. touch_event touch_event_; + + // Current view rotation (degree). + uint16_t view_rotation_degree_ = 0; + + // Current view rotation (FlutterTransformation). + FlutterTransformation view_rotation_transformation_ = { + 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0}; }; } // namespace flutter diff --git a/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h b/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h index 134624d1..dd6da5e2 100644 --- a/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h +++ b/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h @@ -62,6 +62,18 @@ enum FlutterDesktopViewMode { kFullscreen = 1, }; +// The View rotation setting. +enum FlutterDesktopViewRotation { + // Rotation constant: 0 degree rotation (natural orientation) + kRotation_0 = 0, + // Rotation constant: 90 degree rotation. + kRotation_90 = 1, + // Rotation constant: 180 degree rotation. + kRotation_180 = 2, + // Rotation constant: 270 degree rotation. + kRotation_270 = 3, +}; + // Properties for configuring a Flutter view instance. typedef struct { // View width. @@ -70,6 +82,9 @@ typedef struct { // View height. int height; + // View rotation setting. + FlutterDesktopViewRotation view_rotation; + // View display mode. If you set kFullscreen, the parameters of both `width` // and `height` will be ignored. FlutterDesktopViewMode view_mode; diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window.h b/src/flutter/shell/platform/linux_embedded/window/elinux_window.h index 476bcf98..d5ac0c4e 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window.h +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window.h @@ -21,8 +21,21 @@ class ELinuxWindow { uint32_t GetCurrentHeight() const { return view_properties_.height; } + void SetRotation(FlutterDesktopViewRotation rotation) { + if (rotation == FlutterDesktopViewRotation::kRotation_90) { + current_rotation_ = 90; + } else if (rotation == FlutterDesktopViewRotation::kRotation_180) { + current_rotation_ = 180; + } else if (rotation == FlutterDesktopViewRotation::kRotation_270) { + current_rotation_ = 270; + } else { + current_rotation_ = 0; + } + } + FlutterDesktopViewProperties view_properties_; double current_scale_ = 1.0; + uint16_t current_rotation_ = 0; double pointer_x_ = 0; double pointer_y_ = 0; std::string clipboard_data_ = ""; diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h b/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h index 3d916446..d616a945 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h @@ -34,6 +34,7 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { ELinuxWindowDrm(FlutterDesktopViewProperties view_properties) : display_valid_(false), is_pending_cursor_add_event_(false) { view_properties_ = view_properties; + SetRotation(view_properties_.view_rotation); auto udev = udev_new(); if (!udev) { @@ -111,6 +112,10 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { << " is not set, use " << kDrmDeviceDefaultFilename; device_filename = const_cast(kDrmDeviceDefaultFilename); } + + if (current_rotation_ == 90 || current_rotation_ == 270) { + std::swap(width, height); + } native_window_ = std::make_unique(device_filename); if (!native_window_->IsValid()) { ELINUX_LOG(ERROR) << "Failed to create the native window"; @@ -163,6 +168,9 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { return render_surface_.get(); } + // |FlutterWindowBindingHandler| + uint16_t GetRotationDegree() const override { return current_rotation_; } + // |FlutterWindowBindingHandler| double GetDpiScale() override { return current_scale_; } @@ -290,10 +298,15 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { if (self->IsUdevEventHotplug(*device) && self->native_window_->ConfigureDisplay()) { - if (self->view_properties_.width != self->native_window_->Width() || - self->view_properties_.height != self->native_window_->Height()) { - self->view_properties_.width = self->native_window_->Width(); - self->view_properties_.height = self->native_window_->Height(); + auto width = self->native_window_->Width(); + auto height = self->native_window_->Height(); + if (self->current_rotation_ == 90 || self->current_rotation_ == 270) { + std::swap(width, height); + } + if (self->view_properties_.width != width || + self->view_properties_.height != height) { + self->view_properties_.width = width; + self->view_properties_.height = height; ELINUX_LOG(INFO) << "Display output resolution: " << self->view_properties_.width << "x" << self->view_properties_.height; diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc index c196131d..be0c75e7 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc @@ -110,6 +110,10 @@ const xdg_toplevel_listener ELinuxWindowWayland::kXdgToplevelListener = { } auto self = reinterpret_cast(data); + if (self->current_rotation_ == 90 || self->current_rotation_ == 270) { + std::swap(width, height); + } + int32_t next_width = 0; int32_t next_height = 0; if (is_maximized || is_resizing) { @@ -527,6 +531,10 @@ const wl_output_listener ELinuxWindowWayland::kWlOutputListener = { int32_t refresh) -> void { auto self = reinterpret_cast(data); if (flags & WL_OUTPUT_MODE_CURRENT) { + if (self->current_rotation_ == 90 || self->current_rotation_ == 270) { + std::swap(width, height); + } + ELINUX_LOG(INFO) << "Display output info: width = " << width << ", height = " << height << ", refresh = " << refresh; @@ -818,6 +826,7 @@ ELinuxWindowWayland::ELinuxWindowWayland( frame_rate_(60000), window_decorations_(nullptr) { view_properties_ = view_properties; + SetRotation(view_properties_.view_rotation); wl_display_ = wl_display_connect(nullptr); if (!wl_display_) { @@ -996,6 +1005,10 @@ ELinuxRenderSurfaceTarget* ELinuxWindowWayland::GetRenderSurfaceTarget() const { return render_surface_.get(); } +uint16_t ELinuxWindowWayland::GetRotationDegree() const { + return current_rotation_; +} + double ELinuxWindowWayland::GetDpiScale() { return current_scale_; } @@ -1088,6 +1101,9 @@ bool ELinuxWindowWayland::CreateRenderSurface(int32_t width, int32_t height) { } } + if (current_rotation_ == 90 || current_rotation_ == 270) { + std::swap(width, height); + } native_window_ = std::make_unique(wl_compositor_, width, height); diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h index 5a73232e..d62ebd5a 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h @@ -52,6 +52,9 @@ class ELinuxWindowWayland : public ELinuxWindow, public WindowBindingHandler { // |FlutterWindowBindingHandler| ELinuxRenderSurfaceTarget* GetRenderSurfaceTarget() const override; + // |FlutterWindowBindingHandler| + uint16_t GetRotationDegree() const override; + // |FlutterWindowBindingHandler| double GetDpiScale() override; diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.cc index 3d475888..792fa76a 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.cc @@ -23,6 +23,7 @@ constexpr int kButton9 = 9; ELinuxWindowX11::ELinuxWindowX11(FlutterDesktopViewProperties view_properties) { view_properties_ = view_properties; + SetRotation(view_properties_.view_rotation); display_ = XOpenDisplay(NULL); if (!display_) { @@ -89,10 +90,16 @@ bool ELinuxWindowX11::DispatchEvent() { } break; case ConfigureNotify: { - if (((event.xconfigure.width != view_properties_.width) || - (event.xconfigure.height != view_properties_.height))) { - view_properties_.width = event.xconfigure.width; - view_properties_.height = event.xconfigure.height; + auto width = event.xconfigure.width; + auto height = event.xconfigure.height; + if (current_rotation_ == 90 || current_rotation_ == 270) { + std::swap(width, height); + } + + if (((width != view_properties_.width) || + (height != view_properties_.height))) { + view_properties_.width = width; + view_properties_.height = height; if (binding_handler_delegate_) { binding_handler_delegate_->OnWindowSizeChanged( view_properties_.width, view_properties_.height); @@ -116,6 +123,9 @@ bool ELinuxWindowX11::CreateRenderSurface(int32_t width, int32_t height) { auto context_egl = std::make_unique(std::make_unique(display_)); + if (current_rotation_ == 90 || current_rotation_ == 270) { + std::swap(width, height); + } native_window_ = std::make_unique( display_, context_egl->GetAttrib(EGL_NATIVE_VISUAL_ID), width, height); if (!native_window_->IsValid()) { @@ -143,6 +153,10 @@ ELinuxRenderSurfaceTarget* ELinuxWindowX11::GetRenderSurfaceTarget() const { return render_surface_.get(); } +uint16_t ELinuxWindowX11::GetRotationDegree() const { + return current_rotation_; +} + double ELinuxWindowX11::GetDpiScale() { return current_scale_; } diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.h b/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.h index 7eb73262..80683534 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.h +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.h @@ -37,6 +37,9 @@ class ELinuxWindowX11 : public ELinuxWindow, public WindowBindingHandler { // |FlutterWindowBindingHandler| ELinuxRenderSurfaceTarget* GetRenderSurfaceTarget() const override; + // |FlutterWindowBindingHandler| + uint16_t GetRotationDegree() const override; + // |FlutterWindowBindingHandler| double GetDpiScale() override; diff --git a/src/flutter/shell/platform/linux_embedded/window_binding_handler.h b/src/flutter/shell/platform/linux_embedded/window_binding_handler.h index 56957f92..83aa7920 100644 --- a/src/flutter/shell/platform/linux_embedded/window_binding_handler.h +++ b/src/flutter/shell/platform/linux_embedded/window_binding_handler.h @@ -47,6 +47,9 @@ class WindowBindingHandler { // such as key presses, mouse position updates etc. virtual void SetView(WindowBindingHandlerDelegate* view) = 0; + // Returns the rotation(degree) for the backing window. + virtual uint16_t GetRotationDegree() const = 0; + // Returns the scale factor for the backing window. virtual double GetDpiScale() = 0; From 6eeb4f210db5aedd15a3840113017edce23afacb Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Fri, 11 Mar 2022 10:06:06 +0900 Subject: [PATCH 008/112] Rename enum value of FlutterDesktopViewMode Renamed FlutterDesktopViewMode enum value to avoid conflict with the latest embedder.h --- src/client_wrapper/flutter_view_controller.cc | 2 +- .../shell/platform/linux_embedded/public/flutter_elinux.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client_wrapper/flutter_view_controller.cc b/src/client_wrapper/flutter_view_controller.cc index 8387919d..4dbd58a4 100644 --- a/src/client_wrapper/flutter_view_controller.cc +++ b/src/client_wrapper/flutter_view_controller.cc @@ -28,7 +28,7 @@ FlutterViewController::FlutterViewController( c_view_properties.view_mode = (view_properties.view_mode == ViewMode::kFullscreen) ? FlutterDesktopViewMode::kFullscreen - : FlutterDesktopViewMode::kNormal; + : FlutterDesktopViewMode::kNormalscreen; c_view_properties.use_mouse_cursor = view_properties.use_mouse_cursor; c_view_properties.use_onscreen_keyboard = view_properties.use_onscreen_keyboard; diff --git a/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h b/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h index dd6da5e2..4b7cb0da 100644 --- a/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h +++ b/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h @@ -57,7 +57,7 @@ typedef struct { // The View display mode. enum FlutterDesktopViewMode { // Shows the Flutter view by user specific size. - kNormal = 0, + kNormalscreen = 0, // Shows always the Flutter view by fullscreen. kFullscreen = 1, }; From a07efc4412820c6aebd8fa47e1eb40716bda9841 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Thu, 24 Mar 2022 09:50:41 +0900 Subject: [PATCH 009/112] merge embedder.h from flutter/engine (#252) Merged the latest `embedder.h` from https://github.com/flutter/engine/commit/6c67716b081a3614305f99b4e6ade2562f974fee --- .../shell/platform/embedder/embedder.h | 169 +++++++++++++++++- 1 file changed, 168 insertions(+), 1 deletion(-) diff --git a/src/flutter/shell/platform/embedder/embedder.h b/src/flutter/shell/platform/embedder/embedder.h index e8b769ef..4cefaab8 100644 --- a/src/flutter/shell/platform/embedder/embedder.h +++ b/src/flutter/shell/platform/embedder/embedder.h @@ -76,6 +76,7 @@ typedef enum { /// iOS version >= 10.0 (device), 13.0 (simulator) /// macOS version >= 10.14 kMetal, + kVulkan, } FlutterRendererType; /// Additional accessibility features that may be enabled by the platform. @@ -225,6 +226,18 @@ typedef enum { kFlutterTextDirectionLTR = 2, } FlutterTextDirection; +/// Valid values for priority of Thread. +typedef enum { + /// Suitable for threads that shouldn't disrupt high priority work. + kBackground = 0, + /// Default priority level. + kNormal = 1, + /// Suitable for threads which generate data for the display. + kDisplay = 2, + /// Suitable for thread which raster data. + kRaster = 3, +} FlutterThreadPriority; + typedef struct _FlutterEngine* FLUTTER_API_SYMBOL(FlutterEngine); typedef struct { @@ -494,7 +507,7 @@ typedef struct { size_t struct_size; /// Embedder provided unique identifier to the texture buffer. Given that the /// `texture` handle is passed to the engine to render to, the texture buffer - /// is itseld owned by the embedder. This `texture_id` is then also given to + /// is itself owned by the embedder. This `texture_id` is then also given to /// the embedder in the present callback. int64_t texture_id; /// Handle to the MTLTexture that is owned by the embedder. Engine will render @@ -541,6 +554,104 @@ typedef struct { FlutterMetalTextureFrameCallback external_texture_frame_callback; } FlutterMetalRendererConfig; +/// Alias for VkInstance. +typedef void* FlutterVulkanInstanceHandle; + +/// Alias for VkPhysicalDevice. +typedef void* FlutterVulkanPhysicalDeviceHandle; + +/// Alias for VkDevice. +typedef void* FlutterVulkanDeviceHandle; + +/// Alias for VkQueue. +typedef void* FlutterVulkanQueueHandle; + +/// Alias for VkImage. +typedef uint64_t FlutterVulkanImageHandle; + +typedef struct { + /// The size of this struct. Must be sizeof(FlutterVulkanImage). + size_t struct_size; + /// Handle to the VkImage that is owned by the embedder. The engine will + /// bind this image for writing the frame. + FlutterVulkanImageHandle image; + /// The VkFormat of the image (for example: VK_FORMAT_R8G8B8A8_UNORM). + uint32_t format; +} FlutterVulkanImage; + +/// Callback to fetch a Vulkan function pointer for a given instance. Normally, +/// this should return the results of vkGetInstanceProcAddr. +typedef void* (*FlutterVulkanInstanceProcAddressCallback)( + void* /* user data */, + FlutterVulkanInstanceHandle /* instance */, + const char* /* name */); + +/// Callback for when a VkImage is requested. +typedef FlutterVulkanImage (*FlutterVulkanImageCallback)( + void* /* user data */, + const FlutterFrameInfo* /* frame info */); + +/// Callback for when a VkImage has been written to and is ready for use by the +/// embedder. +typedef bool (*FlutterVulkanPresentCallback)( + void* /* user data */, + const FlutterVulkanImage* /* image */); + +typedef struct { + /// The size of this struct. Must be sizeof(FlutterVulkanRendererConfig). + size_t struct_size; + + /// The Vulkan API version. This should match the value set in + /// VkApplicationInfo::apiVersion when the VkInstance was created. + uint32_t version; + /// VkInstance handle. Must not be destroyed before `FlutterEngineShutdown` is + /// called. + FlutterVulkanInstanceHandle instance; + /// VkPhysicalDevice handle. + FlutterVulkanPhysicalDeviceHandle physical_device; + /// VkDevice handle. Must not be destroyed before `FlutterEngineShutdown` is + /// called. + FlutterVulkanDeviceHandle device; + /// The queue family index of the VkQueue supplied in the next field. + uint32_t queue_family_index; + /// VkQueue handle. + FlutterVulkanQueueHandle queue; + /// The number of instance extensions available for enumerating in the next + /// field. + size_t enabled_instance_extension_count; + /// Array of enabled instance extension names. This should match the names + /// passed to `VkInstanceCreateInfo.ppEnabledExtensionNames` when the instance + /// was created, but any subset of enabled instance extensions may be + /// specified. + /// This field is optional; `nullptr` may be specified. + /// This memory is only accessed during the call to FlutterEngineInitialize. + const char** enabled_instance_extensions; + /// The number of device extensions available for enumerating in the next + /// field. + size_t enabled_device_extension_count; + /// Array of enabled logical device extension names. This should match the + /// names passed to `VkDeviceCreateInfo.ppEnabledExtensionNames` when the + /// logical device was created, but any subset of enabled logical device + /// extensions may be specified. + /// This field is optional; `nullptr` may be specified. + /// This memory is only accessed during the call to FlutterEngineInitialize. + /// For example: VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME + const char** enabled_device_extensions; + /// The callback invoked when resolving Vulkan function pointers. + FlutterVulkanInstanceProcAddressCallback get_instance_proc_address_callback; + /// The callback invoked when the engine requests a VkImage from the embedder + /// for rendering the next frame. + /// Not used if a FlutterCompositor is supplied in FlutterProjectArgs. + FlutterVulkanImageCallback get_next_image_callback; + /// The callback invoked when a VkImage has been written to and is ready for + /// use by the embedder. Prior to calling this callback, the engine performs + /// a host sync, and so the VkImage can be used in a pipeline by the embedder + /// without any additional synchronization. + /// Not used if a FlutterCompositor is supplied in FlutterProjectArgs. + FlutterVulkanPresentCallback present_image_callback; + +} FlutterVulkanRendererConfig; + typedef struct { /// The size of this struct. Must be sizeof(FlutterSoftwareRendererConfig). size_t struct_size; @@ -557,6 +668,7 @@ typedef struct { FlutterOpenGLRendererConfig open_gl; FlutterSoftwareRendererConfig software; FlutterMetalRendererConfig metal; + FlutterVulkanRendererConfig vulkan; }; } FlutterRendererConfig; @@ -617,6 +729,12 @@ typedef enum { kRemove, /// The pointer moved while up. kHover, + /// A pan/zoom started on this pointer. + kPanZoomStart, + /// The pan/zoom updated. + kPanZoomUpdate, + /// The pan/zoom ended. + kPanZoomEnd, } FlutterPointerPhase; /// The device type that created a pointer event. @@ -624,6 +742,7 @@ typedef enum { kFlutterPointerDeviceKindMouse = 1, kFlutterPointerDeviceKindTouch, kFlutterPointerDeviceKindStylus, + kFlutterPointerDeviceKindTrackpad, } FlutterPointerDeviceKind; /// Flags for the `buttons` field of `FlutterPointerEvent` when `device_kind` @@ -672,6 +791,14 @@ typedef struct { FlutterPointerDeviceKind device_kind; /// The buttons currently pressed, if any. int64_t buttons; + /// The x offset of the pan/zoom in physical pixels. + double pan_x; + /// The y offset of the pan/zoom in physical pixels. + double pan_y; + /// The scale of the pan/zoom, where 1.0 is the initial scale. + double scale; + /// The rotation of the pan/zoom in radians, where 0.0 is the initial angle. + double rotation; } FlutterPointerEvent; typedef enum { @@ -946,6 +1073,9 @@ typedef struct { /// and platform task runners. This makes the Flutter engine use the same /// thread for both task runners. const FlutterTaskRunnerDescription* render_task_runner; + /// Specify a callback that is used to set the thread priority for embedder + /// task runners. + void (*thread_priority_setter)(FlutterThreadPriority); } FlutterCustomTaskRunners; typedef struct { @@ -989,6 +1119,25 @@ typedef struct { }; } FlutterMetalBackingStore; +typedef struct { + /// The size of this struct. Must be sizeof(FlutterVulkanBackingStore). + size_t struct_size; + /// The image that the layer will be rendered to. This image must already be + /// available for the engine to bind for writing when it's given to the engine + /// via the backing store creation callback. The engine will perform a host + /// sync for all layers prior to calling the compositor present callback, and + /// so the written layer images can be freely bound by the embedder without + /// any additional synchronization. + const FlutterVulkanImage* image; + /// A baton that is not interpreted by the engine in any way. It will be given + /// back to the embedder in the destruction callback below. Embedder resources + /// may be associated with this baton. + void* user_data; + /// The callback invoked by the engine when it no longer needs this backing + /// store. + VoidCallback destruction_callback; +} FlutterVulkanBackingStore; + typedef enum { /// Indicates that the Flutter application requested that an opacity be /// applied to the platform view. @@ -1048,6 +1197,8 @@ typedef enum { kFlutterBackingStoreTypeSoftware, /// Specifies a Metal backing store. This is backed by a Metal texture. kFlutterBackingStoreTypeMetal, + /// Specifies a Vulkan backing store. This is backed by a Vulkan VkImage. + kFlutterBackingStoreTypeVulkan, } FlutterBackingStoreType; typedef struct { @@ -1069,6 +1220,8 @@ typedef struct { FlutterSoftwareBackingStore software; // The description of the Metal backing store. FlutterMetalBackingStore metal; + // The description of the Vulkan backing store. + FlutterVulkanBackingStore vulkan; }; } FlutterBackingStore; @@ -2251,6 +2404,17 @@ FlutterEngineResult FlutterEngineNotifyDisplayUpdate( const FlutterEngineDisplay* displays, size_t display_count); +//------------------------------------------------------------------------------ +/// @brief Schedule a new frame to redraw the content. +/// +/// @param[in] engine A running engine instance. +/// +/// @return the result of the call made to the engine. +/// +FLUTTER_EXPORT +FlutterEngineResult FlutterEngineScheduleFrame(FLUTTER_API_SYMBOL(FlutterEngine) + engine); + #endif // !FLUTTER_ENGINE_NO_PROTOTYPES // Typedefs for the function pointers in FlutterEngineProcTable. @@ -2367,6 +2531,8 @@ typedef FlutterEngineResult (*FlutterEngineNotifyDisplayUpdateFnPtr)( FlutterEngineDisplaysUpdateType update_type, const FlutterEngineDisplay* displays, size_t display_count); +typedef FlutterEngineResult (*FlutterEngineScheduleFrameFnPtr)( + FLUTTER_API_SYMBOL(FlutterEngine) engine); /// Function-pointer-based versions of the APIs above. typedef struct { @@ -2411,6 +2577,7 @@ typedef struct { FlutterEnginePostCallbackOnAllNativeThreadsFnPtr PostCallbackOnAllNativeThreads; FlutterEngineNotifyDisplayUpdateFnPtr NotifyDisplayUpdate; + FlutterEngineScheduleFrameFnPtr ScheduleFrame; } FlutterEngineProcTable; //------------------------------------------------------------------------------ From 86c676a3dce7989c55768c6839c86674374ee63a Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Thu, 7 Apr 2022 15:31:28 +0900 Subject: [PATCH 010/112] Merged the latest embedder.h from flutter/engine (04/07/2022) (#255) See https://github.com/flutter/engine/commit/5f2b5660f2551a60021b66cfd267abc2aa97bfec --- src/flutter/shell/platform/embedder/embedder.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/flutter/shell/platform/embedder/embedder.h b/src/flutter/shell/platform/embedder/embedder.h index 4cefaab8..66a25c7f 100644 --- a/src/flutter/shell/platform/embedder/embedder.h +++ b/src/flutter/shell/platform/embedder/embedder.h @@ -92,8 +92,12 @@ typedef enum { /// Request that text be rendered at a bold font weight. kFlutterAccessibilityFeatureBoldText = 1 << 3, /// Request that certain animations be simplified and parallax effects - // removed. + /// removed. kFlutterAccessibilityFeatureReduceMotion = 1 << 4, + /// Request that UI be rendered with darker colors. + kFlutterAccessibilityFeatureHighContrast = 1 << 5, + /// Request to show on/off labels inside switches. + kFlutterAccessibilityFeatureOnOffSwitchLabels = 1 << 6, } FlutterAccessibilityFeature; /// The set of possible actions that can be conveyed to a semantics node. @@ -149,6 +153,8 @@ typedef enum { kFlutterSemanticsActionMoveCursorForwardByWord = 1 << 19, /// Move the cursor backward by one word. kFlutterSemanticsActionMoveCursorBackwardByWord = 1 << 20, + /// Replace the current text in the text field. + kFlutterSemanticsActionSetText = 1 << 21, } FlutterSemanticsAction; /// The set of properties that may be associated with a semantics node. @@ -203,6 +209,12 @@ typedef enum { /// `PageView` widget does not have implicit scrolling, so that users don't /// navigate to the next page when reaching the end of the current one. kFlutterSemanticsFlagHasImplicitScrolling = 1 << 18, + /// Whether the value of the semantics node is coming from a multi-line text + /// field. + /// + /// This is used for text fields to distinguish single-line text fields from + /// multi-line ones. + kFlutterSemanticsFlagIsMultiline = 1 << 19, /// Whether the semantic node is read only. /// /// Only applicable when kFlutterSemanticsFlagIsTextField flag is on. From 047c0d1133c64f34076f5bc6f62a9919d53add61 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Fri, 8 Apr 2022 14:36:11 +0900 Subject: [PATCH 011/112] Fix drm backends rotation option bug (#257) --- .../linux_embedded/window/elinux_window_drm.h | 57 ++++++++++++------- .../window/native_window_drm.cc | 10 +++- .../linux_embedded/window/native_window_drm.h | 4 +- .../window/native_window_drm_eglstream.cc | 5 +- .../window/native_window_drm_eglstream.h | 3 +- .../window/native_window_drm_gbm.cc | 5 +- .../window/native_window_drm_gbm.h | 2 +- 7 files changed, 54 insertions(+), 32 deletions(-) diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h b/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h index d616a945..55e29854 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h @@ -113,10 +113,7 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { device_filename = const_cast(kDrmDeviceDefaultFilename); } - if (current_rotation_ == 90 || current_rotation_ == 270) { - std::swap(width, height); - } - native_window_ = std::make_unique(device_filename); + native_window_ = std::make_unique(device_filename, current_rotation_); if (!native_window_->IsValid()) { ELINUX_LOG(ERROR) << "Failed to create the native window"; return false; @@ -297,7 +294,7 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { } if (self->IsUdevEventHotplug(*device) && - self->native_window_->ConfigureDisplay()) { + self->native_window_->ConfigureDisplay(self->current_rotation_)) { auto width = self->native_window_->Width(); auto height = self->native_window_->Height(); if (self->current_rotation_ == 90 || self->current_rotation_ == 270) { @@ -462,18 +459,22 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { void OnPointerMotion(libinput_event* event) { DetectPointerDevice(event); if (binding_handler_delegate_) { + auto width = view_properties_.width; + auto height = view_properties_.height; + if (current_rotation_ == 90 || current_rotation_ == 270) { + std::swap(width, height); + } + auto pointer_event = libinput_event_get_pointer_event(event); auto dx = libinput_event_pointer_get_dx(pointer_event); auto dy = libinput_event_pointer_get_dy(pointer_event); auto new_pointer_x = pointer_x_ + dx; new_pointer_x = std::max(0.0, new_pointer_x); - new_pointer_x = std::min(static_cast(view_properties_.width - 1), - new_pointer_x); + new_pointer_x = std::min(static_cast(width - 1), new_pointer_x); auto new_pointer_y = pointer_y_ + dy; new_pointer_y = std::max(0.0, new_pointer_y); - new_pointer_y = std::min(static_cast(view_properties_.height - 1), - new_pointer_y); + new_pointer_y = std::min(static_cast(height - 1), new_pointer_y); binding_handler_delegate_->OnPointerMove(new_pointer_x, new_pointer_y); pointer_x_ = new_pointer_x; @@ -482,13 +483,19 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { } void OnPointerMotionAbsolute(libinput_event* event) { + auto width = view_properties_.width; + auto height = view_properties_.height; + if (current_rotation_ == 90 || current_rotation_ == 270) { + std::swap(width, height); + } + DetectPointerDevice(event); if (binding_handler_delegate_) { auto pointer_event = libinput_event_get_pointer_event(event); - auto x = libinput_event_pointer_get_absolute_x_transformed( - pointer_event, view_properties_.width); - auto y = libinput_event_pointer_get_absolute_y_transformed( - pointer_event, view_properties_.height); + auto x = libinput_event_pointer_get_absolute_x_transformed(pointer_event, + width); + auto y = libinput_event_pointer_get_absolute_y_transformed(pointer_event, + height); binding_handler_delegate_->OnPointerMove(x, y); pointer_x_ = x; @@ -580,13 +587,17 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { void OnTouchDown(libinput_event* event) { if (binding_handler_delegate_) { + auto width = view_properties_.width; + auto height = view_properties_.height; + if (current_rotation_ == 90 || current_rotation_ == 270) { + std::swap(width, height); + } + auto touch_event = libinput_event_get_touch_event(event); auto time = libinput_event_touch_get_time(touch_event); auto slot = libinput_event_touch_get_seat_slot(touch_event); - auto x = libinput_event_touch_get_x_transformed(touch_event, - view_properties_.width); - auto y = libinput_event_touch_get_y_transformed(touch_event, - view_properties_.height); + auto x = libinput_event_touch_get_x_transformed(touch_event, width); + auto y = libinput_event_touch_get_y_transformed(touch_event, height); binding_handler_delegate_->OnTouchDown(time, slot, x, y); } } @@ -602,13 +613,17 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { void OnTouchMotion(libinput_event* event) { if (binding_handler_delegate_) { + auto width = view_properties_.width; + auto height = view_properties_.height; + if (current_rotation_ == 90 || current_rotation_ == 270) { + std::swap(width, height); + } + auto touch_event = libinput_event_get_touch_event(event); auto time = libinput_event_touch_get_time(touch_event); auto slot = libinput_event_touch_get_seat_slot(touch_event); - auto x = libinput_event_touch_get_x_transformed(touch_event, - view_properties_.width); - auto y = libinput_event_touch_get_y_transformed(touch_event, - view_properties_.height); + auto x = libinput_event_touch_get_x_transformed(touch_event, width); + auto y = libinput_event_touch_get_y_transformed(touch_event, height); binding_handler_delegate_->OnTouchMotion(time, slot, x, y); } } diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_drm.cc b/src/flutter/shell/platform/linux_embedded/window/native_window_drm.cc index cf9c48ff..1f57165c 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_drm.cc +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_drm.cc @@ -15,14 +15,15 @@ namespace flutter { -NativeWindowDrm::NativeWindowDrm(const char* device_filename) { +NativeWindowDrm::NativeWindowDrm(const char* device_filename, + const uint16_t rotation) { drm_device_ = open(device_filename, O_RDWR | O_CLOEXEC); if (drm_device_ == -1) { ELINUX_LOG(ERROR) << "Couldn't open " << device_filename; return; } - if (!ConfigureDisplay()) { + if (!ConfigureDisplay(rotation)) { return; } @@ -46,7 +47,7 @@ bool NativeWindowDrm::MoveCursor(double x, double y) { return true; } -bool NativeWindowDrm::ConfigureDisplay() { +bool NativeWindowDrm::ConfigureDisplay(const uint16_t rotation) { auto resources = drmModeGetResources(drm_device_); if (!resources) { ELINUX_LOG(ERROR) << "Couldn't get resources"; @@ -64,6 +65,9 @@ bool NativeWindowDrm::ConfigureDisplay() { drm_mode_info_ = connector->modes[0]; width_ = drm_mode_info_.hdisplay; height_ = drm_mode_info_.vdisplay; + if (rotation == 90 || rotation == 270) { + std::swap(width_, height_); + } ELINUX_LOG(INFO) << "resolution: " << width_ << "x" << height_; auto* encoder = FindEncoder(resources, connector); diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_drm.h b/src/flutter/shell/platform/linux_embedded/window/native_window_drm.h index 4ec29050..6259f6aa 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_drm.h +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_drm.h @@ -16,10 +16,10 @@ namespace flutter { class NativeWindowDrm : public NativeWindow { public: - NativeWindowDrm(const char* device_filename); + NativeWindowDrm(const char* device_filename, const uint16_t rotation); virtual ~NativeWindowDrm(); - bool ConfigureDisplay(); + bool ConfigureDisplay(const uint16_t rotation); bool MoveCursor(double x, double y); diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_drm_eglstream.cc b/src/flutter/shell/platform/linux_embedded/window/native_window_drm_eglstream.cc index b762321a..a78fd033 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_drm_eglstream.cc +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_drm_eglstream.cc @@ -18,8 +18,9 @@ namespace { constexpr char kCursorNameNone[] = "none"; } // namespace -NativeWindowDrmEglstream::NativeWindowDrmEglstream(const char* device_filename) - : NativeWindowDrm(device_filename) { +NativeWindowDrmEglstream::NativeWindowDrmEglstream(const char* device_filename, + const uint16_t rotation) + : NativeWindowDrm(device_filename, rotation) { if (!valid_) { return; } diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_drm_eglstream.h b/src/flutter/shell/platform/linux_embedded/window/native_window_drm_eglstream.h index 994dfe38..f3e469d5 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_drm_eglstream.h +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_drm_eglstream.h @@ -16,7 +16,8 @@ namespace flutter { class NativeWindowDrmEglstream : public NativeWindowDrm { public: - NativeWindowDrmEglstream(const char* device_filename); + NativeWindowDrmEglstream(const char* device_filename, + const uint16_t rotation); ~NativeWindowDrmEglstream(); // |NativeWindowDrm| diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_drm_gbm.cc b/src/flutter/shell/platform/linux_embedded/window/native_window_drm_gbm.cc index a24443a7..3effb666 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_drm_gbm.cc +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_drm_gbm.cc @@ -19,8 +19,9 @@ constexpr uint32_t kCursorBufferWidth = 64; constexpr uint32_t kCursorBufferHeight = 64; } // namespace -NativeWindowDrmGbm::NativeWindowDrmGbm(const char* device_filename) - : NativeWindowDrm(device_filename) { +NativeWindowDrmGbm::NativeWindowDrmGbm(const char* device_filename, + const uint16_t rotation) + : NativeWindowDrm(device_filename, rotation) { if (!valid_) { return; } diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_drm_gbm.h b/src/flutter/shell/platform/linux_embedded/window/native_window_drm_gbm.h index 0a062273..6b9b9ecd 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_drm_gbm.h +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_drm_gbm.h @@ -17,7 +17,7 @@ namespace flutter { class NativeWindowDrmGbm : public NativeWindowDrm { public: - NativeWindowDrmGbm(const char* device_filename); + NativeWindowDrmGbm(const char* device_filename, const uint16_t rotation); ~NativeWindowDrmGbm(); // |NativeWindowDrm| From 12cee2fa600271db82b1eb0b4c6ab2abab09e2a6 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Wed, 13 Apr 2022 10:26:22 +0900 Subject: [PATCH 012/112] Fix uninitialization of member var (#258) --- .../shell/platform/linux_embedded/plugins/text_input_plugin.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flutter/shell/platform/linux_embedded/plugins/text_input_plugin.h b/src/flutter/shell/platform/linux_embedded/plugins/text_input_plugin.h index af9caf27..3f48d9b6 100644 --- a/src/flutter/shell/platform/linux_embedded/plugins/text_input_plugin.h +++ b/src/flutter/shell/platform/linux_embedded/plugins/text_input_plugin.h @@ -39,7 +39,7 @@ class TextInputPlugin { std::unique_ptr> channel_; // The active client id. - int client_id_; + int client_id_ = 0; // The active model. nullptr if not set. std::unique_ptr active_model_; From 63a688c43e13a6e64561de83de543bb4b34a94dc Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Fri, 22 Apr 2022 12:45:13 +0900 Subject: [PATCH 013/112] Add AUTHORS file (#259) Signed-off-by: Hidenori.Matsubayashi --- AUTHORS | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 AUTHORS diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 00000000..649f420b --- /dev/null +++ b/AUTHORS @@ -0,0 +1,8 @@ +# Below is a list of people and organizations that have contributed +# to sony/flutter-embedded-linux. Names should be added to the list +# like so: +# +# Name/Organization + +Sony Group Corporation +Hidenori Matsubayashi (hidenori.matsubayashi@gmail.com) From 4280a80ebf320b5dc2166ed9ec40ab14916185c6 Mon Sep 17 00:00:00 2001 From: Cem Philipp Freimoser Date: Sun, 10 Jul 2022 13:25:08 +0000 Subject: [PATCH 014/112] Added Pi 3 Model B to readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 2244d108..95d6543e 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ This embedder supports x64 and Arm64 (aarch64, ARMv8) architectures on Linux whi | [Jetson Nano](https://developer.nvidia.com/embedded/jetson-nano-developer-kit) | NVIDIA | JetPack 4.3 | DRM | :heavy_check_mark: ([#1](https://github.com/sony/flutter-embedded-linux/issues/1))| | [Raspberry Pi 4 Model B](https://www.raspberrypi.org/products/raspberry-pi-4-model-b/) | Raspberry Pi Foundation | Ubuntu 20.10 | Wayland | :heavy_check_mark: | | [Raspberry Pi 4 Model B](https://www.raspberrypi.org/products/raspberry-pi-4-model-b/) | Raspberry Pi Foundation | Ubuntu 20.10 | DRM | :heavy_check_mark: ([#9](https://github.com/sony/flutter-embedded-linux/issues/9)) | +| [Raspberry Pi 3 Model B](https://www.raspberrypi.com/products/raspberry-pi-3-model-b/) | Raspberry Pi Foundation | Raspberry Pi OS bullseye | Wayland | :heavy_check_mark: | | [i.MX 8MQuad EVK](https://www.nxp.com/design/development-boards/i-mx-evaluation-and-development-boards/evaluation-kit-for-the-i-mx-8m-applications-processor:MCIMX8M-EVK) | NXP | Sumo (kernel 4.14.98) | Wayland | :heavy_check_mark: | | [i.MX 8M Mini EVKB](https://www.nxp.com/design/development-boards/i-mx-evaluation-and-development-boards/evaluation-kit-for-the-i-mx-8m-mini-applications-processor:8MMINILPD4-EVK) | NXP | Zeus (kernel 5.4.70) | Wayland | :heavy_check_mark: | | [RB5 Development Kit](https://developer.qualcomm.com/qualcomm-robotics-rb5-kit) | Qualcomm | Ubuntu 18.04.05 | DRM | :heavy_check_mark: | From fa17772be59e8458d41e1598a1976e52cd27adc8 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Sun, 24 Jul 2022 09:25:12 +0900 Subject: [PATCH 015/112] Update embedder header file (#271) Signed-off-by: Hidenori Matsubayashi --- .../shell/platform/embedder/embedder.h | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/src/flutter/shell/platform/embedder/embedder.h b/src/flutter/shell/platform/embedder/embedder.h index 66a25c7f..43fd5bd5 100644 --- a/src/flutter/shell/platform/embedder/embedder.h +++ b/src/flutter/shell/platform/embedder/embedder.h @@ -284,6 +284,62 @@ typedef enum { kFlutterOpenGLTargetTypeFramebuffer, } FlutterOpenGLTargetType; +/// A pixel format to be used for software rendering. +/// +/// A single pixel always stored as a POT number of bytes. (so in practice +/// either 1, 2, 4, 8, 16 bytes per pixel) +/// +/// There are two kinds of pixel formats: +/// - formats where all components are 8 bits, called array formats +/// The component order as specified in the pixel format name is the +/// order of the components' bytes in memory, with the leftmost component +/// occupying the lowest memory address. +/// +/// - all other formats are called packed formats, and the component order +/// as specified in the format name refers to the order in the native type. +/// for example, for kRGB565, the R component uses the 5 least significant +/// bits of the uint16_t pixel value. +/// +/// Each pixel format in this list is documented with an example on how to get +/// the color components from the pixel. +/// - for packed formats, p is the pixel value as a word. For example, you can +/// get the pixel value for a RGB565 formatted buffer like this: +/// uint16_t p = ((const uint16_t*) allocation)[row_bytes * y / bpp + x]; +/// (with bpp being the bytes per pixel, so 2 for RGB565) +/// +/// - for array formats, p is a pointer to the pixel value. For example, you +/// can get the p for a RGBA8888 formatted buffer like this: +/// const uint8_t *p = ((const uint8_t*) allocation) + row_bytes*y + x*4; +typedef enum { + /// pixel with 8 bit grayscale value. + /// The grayscale value is the luma value calculated from r, g, b + /// according to BT.709. (gray = r*0.2126 + g*0.7152 + b*0.0722) + kGray8, + + /// pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word. + /// r = p & 0x3F; g = (p>>5) & 0x3F; b = p>>11; + kRGB565, + + /// pixel with 4 bits for alpha, red, green, blue; in 16-bit word. + /// r = p & 0xF; g = (p>>4) & 0xF; b = (p>>8) & 0xF; a = p>>12; + kRGBA4444, + + /// pixel with 8 bits for red, green, blue, alpha. + /// r = p[0]; g = p[1]; b = p[2]; a = p[3]; + kRGBA8888, + + /// pixel with 8 bits for red, green and blue and 8 unused bits. + /// r = p[0]; g = p[1]; b = p[2]; + kRGBX8888, + + /// pixel with 8 bits for blue, green, red and alpha. + /// r = p[2]; g = p[1]; b = p[0]; a = p[3]; + kBGRA8888, + + /// either kBGRA8888 or kRGBA8888 depending on CPU endianess and OS + kNative32, +} FlutterSoftwarePixelFormat; + typedef struct { /// Target texture of the active texture unit (example GL_TEXTURE_2D or /// GL_TEXTURE_RECTANGLE). @@ -773,6 +829,7 @@ typedef enum { typedef enum { kFlutterPointerSignalKindNone, kFlutterPointerSignalKindScroll, + kFlutterPointerSignalKindScrollInertiaCancel, } FlutterPointerSignalKind; typedef struct { @@ -1120,6 +1177,27 @@ typedef struct { VoidCallback destruction_callback; } FlutterSoftwareBackingStore; +typedef struct { + size_t struct_size; + /// A pointer to the raw bytes of the allocation described by this software + /// backing store. + const void* allocation; + /// The number of bytes in a single row of the allocation. + size_t row_bytes; + /// The number of rows in the allocation. + size_t height; + /// A baton that is not interpreted by the engine in any way. It will be given + /// back to the embedder in the destruction callback below. Embedder resources + /// may be associated with this baton. + void* user_data; + /// The callback invoked by the engine when it no longer needs this backing + /// store. + VoidCallback destruction_callback; + /// The pixel format that the engine should use to render into the allocation. + /// In most cases, kR + FlutterSoftwarePixelFormat pixel_format; +} FlutterSoftwareBackingStore2; + typedef struct { /// The size of this struct. Must be sizeof(FlutterMetalBackingStore). size_t struct_size; @@ -1211,6 +1289,9 @@ typedef enum { kFlutterBackingStoreTypeMetal, /// Specifies a Vulkan backing store. This is backed by a Vulkan VkImage. kFlutterBackingStoreTypeVulkan, + /// Specifies a allocation that the engine should render into using + /// software rendering. + kFlutterBackingStoreTypeSoftware2, } FlutterBackingStoreType; typedef struct { @@ -1230,6 +1311,8 @@ typedef struct { FlutterOpenGLBackingStore open_gl; /// The description of the software backing store. FlutterSoftwareBackingStore software; + /// The description of the software backing store. + FlutterSoftwareBackingStore2 software2; // The description of the Metal backing store. FlutterMetalBackingStore metal; // The description of the Vulkan backing store. From 9ef4043d5e6bc19ad52230430d6f44ebccf0b4bd Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Wed, 3 Aug 2022 21:10:58 +0900 Subject: [PATCH 016/112] [Merge] Fix incorrect public C API argument type (#275) Signed-off-by: Hidenori Matsubayashi --- .../shell/platform/linux_embedded/public/flutter_elinux.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h b/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h index 4b7cb0da..913c1fac 100644 --- a/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h +++ b/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h @@ -195,8 +195,7 @@ FlutterDesktopEngineGetMessenger(FlutterDesktopEngineRef engine); // Returns the texture registrar associated with the engine. FLUTTER_EXPORT FlutterDesktopTextureRegistrarRef -FlutterDesktopEngineGetTextureRegistrar( - FlutterDesktopTextureRegistrarRef texture_registrar); +FlutterDesktopEngineGetTextureRegistrar(FlutterDesktopEngineRef engine); #if defined(__cplusplus) } // extern "C" From 8ed1e7e77304882b62feaba1ae9b4672765c6c74 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Wed, 3 Aug 2022 22:05:08 +0900 Subject: [PATCH 017/112] Update flutter_texture_registrar APIs (#276) * Update flutter_texture_registrar APIs Signed-off-by: Hidenori Matsubayashi --- cmake/build.cmake | 2 +- .../client_wrapper/core_implementations.cc | 30 ++-- .../include/flutter/texture_registrar.h | 32 +++- .../common/public/flutter_texture_registrar.h | 97 ++++++++++- .../embedder/embedder_struct_macros.h | 32 ++++ .../linux_embedded/external_texture.h | 61 +++++++ .../linux_embedded/external_texture_gl.cc | 153 ------------------ .../linux_embedded/external_texture_gl.h | 56 ------- .../external_texture_pixelbuffer.cc | 82 ++++++++++ .../external_texture_pixelbuffer.h | 52 ++++++ .../linux_embedded/flutter_elinux_engine.cc | 5 +- .../linux_embedded/flutter_elinux_engine.h | 3 + .../flutter_elinux_texture_registrar.cc | 68 ++++++-- .../flutter_elinux_texture_registrar.h | 14 +- 14 files changed, 443 insertions(+), 244 deletions(-) create mode 100644 src/flutter/shell/platform/embedder/embedder_struct_macros.h create mode 100644 src/flutter/shell/platform/linux_embedded/external_texture.h delete mode 100644 src/flutter/shell/platform/linux_embedded/external_texture_gl.cc delete mode 100644 src/flutter/shell/platform/linux_embedded/external_texture_gl.h create mode 100644 src/flutter/shell/platform/linux_embedded/external_texture_pixelbuffer.cc create mode 100644 src/flutter/shell/platform/linux_embedded/external_texture_pixelbuffer.h diff --git a/cmake/build.cmake b/cmake/build.cmake index a14bdc0d..c64fd5ce 100644 --- a/cmake/build.cmake +++ b/cmake/build.cmake @@ -119,7 +119,7 @@ set(ELINUX_COMMON_SRC "src/flutter/shell/platform/linux_embedded/task_runner.cc" "src/flutter/shell/platform/linux_embedded/system_utils.cc" "src/flutter/shell/platform/linux_embedded/logger.cc" - "src/flutter/shell/platform/linux_embedded/external_texture_gl.cc" + "src/flutter/shell/platform/linux_embedded/external_texture_pixelbuffer.cc" "src/flutter/shell/platform/linux_embedded/vsync_waiter.cc" "src/flutter/shell/platform/linux_embedded/flutter_elinux_texture_registrar.cc" "src/flutter/shell/platform/linux_embedded/plugins/keyboard_glfw_util.cc" diff --git a/src/flutter/shell/platform/common/client_wrapper/core_implementations.cc b/src/flutter/shell/platform/common/client_wrapper/core_implementations.cc index 1412db7c..e90b26cd 100644 --- a/src/flutter/shell/platform/common/client_wrapper/core_implementations.cc +++ b/src/flutter/shell/platform/common/client_wrapper/core_implementations.cc @@ -157,25 +157,37 @@ TextureRegistrarImpl::TextureRegistrarImpl( TextureRegistrarImpl::~TextureRegistrarImpl() = default; int64_t TextureRegistrarImpl::RegisterTexture(TextureVariant* texture) { + FlutterDesktopTextureInfo info = {}; if (auto pixel_buffer_texture = std::get_if(texture)) { - FlutterDesktopTextureInfo info = {}; info.type = kFlutterDesktopPixelBufferTexture; info.pixel_buffer_config.user_data = pixel_buffer_texture; info.pixel_buffer_config.callback = [](size_t width, size_t height, void* user_data) -> const FlutterDesktopPixelBuffer* { auto texture = static_cast(user_data); - auto buffer = texture->CopyPixelBuffer(width, height); - return buffer; + return texture->CopyPixelBuffer(width, height); }; - - int64_t texture_id = FlutterDesktopTextureRegistrarRegisterExternalTexture( - texture_registrar_ref_, &info); - return texture_id; + } else if (auto gpu_surface_texture = + std::get_if(texture)) { + info.type = kFlutterDesktopGpuSurfaceTexture; + info.gpu_surface_config.struct_size = + sizeof(FlutterDesktopGpuSurfaceTextureConfig); + info.gpu_surface_config.type = gpu_surface_texture->surface_type(); + info.gpu_surface_config.user_data = gpu_surface_texture; + info.gpu_surface_config.callback = + [](size_t width, size_t height, + void* user_data) -> const FlutterDesktopGpuSurfaceDescriptor* { + auto texture = static_cast(user_data); + return texture->ObtainDescriptor(width, height); + }; + } else { + std::cerr << "Attempting to register unknown texture variant." << std::endl; + return -1; } - std::cerr << "Attempting to register unknown texture variant." << std::endl; - return -1; + int64_t texture_id = FlutterDesktopTextureRegistrarRegisterExternalTexture( + texture_registrar_ref_, &info); + return texture_id; } // namespace flutter bool TextureRegistrarImpl::MarkTextureFrameAvailable(int64_t texture_id) { diff --git a/src/flutter/shell/platform/common/client_wrapper/include/flutter/texture_registrar.h b/src/flutter/shell/platform/common/client_wrapper/include/flutter/texture_registrar.h index 6aa2c6b1..7a2078f1 100644 --- a/src/flutter/shell/platform/common/client_wrapper/include/flutter/texture_registrar.h +++ b/src/flutter/shell/platform/common/client_wrapper/include/flutter/texture_registrar.h @@ -42,10 +42,40 @@ class PixelBufferTexture { const CopyBufferCallback copy_buffer_callback_; }; +// A GPU surface-based texture. +class GpuSurfaceTexture { + public: + // A callback used for retrieving surface descriptors. + typedef std::function< + const FlutterDesktopGpuSurfaceDescriptor*(size_t width, size_t height)> + ObtainDescriptorCallback; + + GpuSurfaceTexture(FlutterDesktopGpuSurfaceType surface_type, + ObtainDescriptorCallback obtain_descriptor_callback) + : surface_type_(surface_type), + obtain_descriptor_callback_(obtain_descriptor_callback) {} + + // Returns the callback-provided FlutterDesktopGpuSurfaceDescriptor that + // contains the surface handle. The intended surface size is specified by + // |width| and |height|. + const FlutterDesktopGpuSurfaceDescriptor* ObtainDescriptor( + size_t width, + size_t height) const { + return obtain_descriptor_callback_(width, height); + } + + // Gets the surface type. + FlutterDesktopGpuSurfaceType surface_type() const { return surface_type_; } + + private: + const FlutterDesktopGpuSurfaceType surface_type_; + const ObtainDescriptorCallback obtain_descriptor_callback_; +}; + // The available texture variants. // Only PixelBufferTexture is currently implemented. // Other variants are expected to be added in the future. -typedef std::variant TextureVariant; +typedef std::variant TextureVariant; // An object keeping track of external textures. // diff --git a/src/flutter/shell/platform/common/public/flutter_texture_registrar.h b/src/flutter/shell/platform/common/public/flutter_texture_registrar.h index b115234e..3ca0785e 100644 --- a/src/flutter/shell/platform/common/public/flutter_texture_registrar.h +++ b/src/flutter/shell/platform/common/public/flutter_texture_registrar.h @@ -23,9 +23,35 @@ typedef struct FlutterDesktopTextureRegistrar* // Additional types may be added in the future. typedef enum { // A Pixel buffer-based texture. - kFlutterDesktopPixelBufferTexture + kFlutterDesktopPixelBufferTexture, + // A platform-specific GPU surface-backed texture. + kFlutterDesktopGpuSurfaceTexture } FlutterDesktopTextureType; +// Supported GPU surface types. +typedef enum { + // Uninitialized. + kFlutterDesktopGpuSurfaceTypeNone, + // A DXGI shared texture handle (Windows only). + // See + // https://docs.microsoft.com/en-us/windows/win32/api/dxgi/nf-dxgi-idxgiresource-getsharedhandle + kFlutterDesktopGpuSurfaceTypeDxgiSharedHandle, + // A |ID3D11Texture2D| (Windows only). + kFlutterDesktopGpuSurfaceTypeD3d11Texture2D, +} FlutterDesktopGpuSurfaceType; + +// Supported pixel formats. +typedef enum { + // Uninitialized. + kFlutterDesktopPixelFormatNone, + // Represents a 32-bit RGBA color format with 8 bits each for red, green, blue + // and alpha. + kFlutterDesktopPixelFormatRGBA8888, + // Represents a 32-bit BGRA color format with 8 bits each for blue, green, red + // and alpha. + kFlutterDesktopPixelFormatBGRA8888 +} FlutterDesktopPixelFormat; + // An image buffer object. typedef struct { // The pixel data buffer. @@ -34,22 +60,72 @@ typedef struct { size_t width; // Height of the pixel buffer. size_t height; + // An optional callback that gets invoked when the |buffer| can be released. + void (*release_callback)(void* release_context); + // Opaque data passed to |release_callback|. + void* release_context; } FlutterDesktopPixelBuffer; +// A GPU surface descriptor. +typedef struct { + // The size of this struct. Must be + // sizeof(FlutterDesktopGpuSurfaceDescriptor). + size_t struct_size; + // The surface handle. The expected type depends on the + // |FlutterDesktopGpuSurfaceType|. + // + // Provide a |ID3D11Texture2D*| when using + // |kFlutterDesktopGpuSurfaceTypeD3d11Texture2D| or a |HANDLE| when using + // |kFlutterDesktopGpuSurfaceTypeDxgiSharedHandle|. + // + // The referenced resource needs to stay valid until it has been opened by + // Flutter. Consider incrementing the resource's reference count in the + // |FlutterDesktopGpuSurfaceTextureCallback| and registering a + // |release_callback| for decrementing the reference count once it has been + // opened. + void* handle; + // The physical width. + size_t width; + // The physical height. + size_t height; + // The visible width. + // It might be less or equal to the physical |width|. + size_t visible_width; + // The visible height. + // It might be less or equal to the physical |height|. + size_t visible_height; + // The pixel format which might be optional depending on the surface type. + FlutterDesktopPixelFormat format; + // An optional callback that gets invoked when the |handle| has been opened. + void (*release_callback)(void* release_context); + // Opaque data passed to |release_callback|. + void* release_context; +} FlutterDesktopGpuSurfaceDescriptor; + // The pixel buffer copy callback definition provided to // the Flutter engine to copy the texture. // It is invoked with the intended surface size specified by |width| and -// |height| and the |user_data| held by FlutterDesktopPixelBufferTextureConfig. +// |height| and the |user_data| held by +// |FlutterDesktopPixelBufferTextureConfig|. // // As this is usually called from the render thread, the callee must take // care of proper synchronization. It also needs to be ensured that the -// returned FlutterDesktopPixelBuffer isn't released prior to unregistering +// returned |FlutterDesktopPixelBuffer| isn't released prior to unregistering // the corresponding texture. typedef const FlutterDesktopPixelBuffer* ( *FlutterDesktopPixelBufferTextureCallback)(size_t width, size_t height, void* user_data); +// The GPU surface callback definition provided to the Flutter engine to obtain +// the surface. It is invoked with the intended surface size specified by +// |width| and |height| and the |user_data| held by +// |FlutterDesktopGpuSurfaceTextureConfig|. +typedef const FlutterDesktopGpuSurfaceDescriptor* ( + *FlutterDesktopGpuSurfaceTextureCallback)(size_t width, + size_t height, + void* user_data); + // An object used to configure pixel buffer textures. typedef struct { // The callback used by the engine to copy the pixel buffer object. @@ -58,10 +134,25 @@ typedef struct { void* user_data; } FlutterDesktopPixelBufferTextureConfig; +// An object used to configure GPU-surface textures. +typedef struct { + // The size of this struct. Must be + // sizeof(FlutterDesktopGpuSurfaceTextureConfig). + size_t struct_size; + // The concrete surface type (e.g. + // |kFlutterDesktopGpuSurfaceTypeDxgiSharedHandle|) + FlutterDesktopGpuSurfaceType type; + // The callback used by the engine to obtain the surface descriptor. + FlutterDesktopGpuSurfaceTextureCallback callback; + // Opaque data that will get passed to the provided |callback|. + void* user_data; +} FlutterDesktopGpuSurfaceTextureConfig; + typedef struct { FlutterDesktopTextureType type; union { FlutterDesktopPixelBufferTextureConfig pixel_buffer_config; + FlutterDesktopGpuSurfaceTextureConfig gpu_surface_config; }; } FlutterDesktopTextureInfo; diff --git a/src/flutter/shell/platform/embedder/embedder_struct_macros.h b/src/flutter/shell/platform/embedder/embedder_struct_macros.h new file mode 100644 index 00000000..8bd30979 --- /dev/null +++ b/src/flutter/shell/platform/embedder/embedder_struct_macros.h @@ -0,0 +1,32 @@ +// 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. + +#ifndef FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_SAFE_ACCESS_H_ +#define FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_SAFE_ACCESS_H_ + +#include + +// Checks if the given struct contains a member, whether set or not. +#define STRUCT_HAS_MEMBER(pointer, member) \ + ((offsetof(std::remove_pointer::type, member) + \ + sizeof(pointer->member) <= \ + pointer->struct_size)) + +#define SAFE_ACCESS(pointer, member, default_value) \ + ([=]() { \ + if (STRUCT_HAS_MEMBER(pointer, member)) { \ + return pointer->member; \ + } \ + return static_castmember)>((default_value)); \ + })() + +/// Checks if the member exists and is non-null. +#define SAFE_EXISTS(pointer, member) \ + (SAFE_ACCESS(pointer, member, nullptr) != nullptr) + +/// Checks if exactly one of member1 or member2 exists and is non-null. +#define SAFE_EXISTS_ONE_OF(pointer, member1, member2) \ + (SAFE_EXISTS(pointer, member1) != SAFE_EXISTS(pointer, member2)) + +#endif // FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_SAFE_ACCESS_H_ diff --git a/src/flutter/shell/platform/linux_embedded/external_texture.h b/src/flutter/shell/platform/linux_embedded/external_texture.h new file mode 100644 index 00000000..e6e92c8f --- /dev/null +++ b/src/flutter/shell/platform/linux_embedded/external_texture.h @@ -0,0 +1,61 @@ +// 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. + +#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_EXTERNAL_TEXTURE_H_ +#define FLUTTER_SHELL_PLATFORM_WINDOWS_EXTERNAL_TEXTURE_H_ + +#include "flutter/shell/platform/embedder/embedder.h" + +#ifdef USE_GLES3 +#include +#else +#include +#include +#endif + +namespace flutter { + +typedef void (*glGenTexturesProc)(GLsizei n, GLuint* textures); +typedef void (*glDeleteTexturesProc)(GLsizei n, const GLuint* textures); +typedef void (*glBindTextureProc)(GLenum target, GLuint texture); +typedef void (*glTexParameteriProc)(GLenum target, GLenum pname, GLint param); +typedef void (*glTexImage2DProc)(GLenum target, + GLint level, + GLint internalformat, + GLsizei width, + GLsizei height, + GLint border, + GLenum format, + GLenum type, + const void* data); + +// A struct containing pointers to resolved gl* functions. +struct GlProcs { + glGenTexturesProc glGenTextures; + glDeleteTexturesProc glDeleteTextures; + glBindTextureProc glBindTexture; + glTexParameteriProc glTexParameteri; + glTexImage2DProc glTexImage2D; + bool valid; +}; + +// Abstract external texture. +class ExternalTexture { + public: + virtual ~ExternalTexture() = default; + + // Returns the unique id of this texture. + int64_t texture_id() const { return reinterpret_cast(this); }; + + // Attempts to populate the specified |opengl_texture| with texture details + // such as the name, width, height and the pixel format. + // Returns true on success. + virtual bool PopulateTexture(size_t width, + size_t height, + FlutterOpenGLTexture* opengl_texture) = 0; +}; + +} // namespace flutter + +#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_EXTERNAL_TEXTURE_H_ diff --git a/src/flutter/shell/platform/linux_embedded/external_texture_gl.cc b/src/flutter/shell/platform/linux_embedded/external_texture_gl.cc deleted file mode 100644 index 0b0935ea..00000000 --- a/src/flutter/shell/platform/linux_embedded/external_texture_gl.cc +++ /dev/null @@ -1,153 +0,0 @@ -// 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. - -#include "flutter/shell/platform/linux_embedded/external_texture_gl.h" - -#include - -#ifdef USE_GLES3 -#include -#else -#include -#include -#endif - -namespace { - -typedef void (*glGenTexturesProc)(GLsizei n, GLuint* textures); -typedef void (*glDeleteTexturesProc)(GLsizei n, const GLuint* textures); -typedef void (*glBindTextureProc)(GLenum target, GLuint texture); -typedef void (*glTexParameteriProc)(GLenum target, GLenum pname, GLint param); -typedef void (*glTexImage2DProc)(GLenum target, - GLint level, - GLint internalformat, - GLsizei width, - GLsizei height, - GLint border, - GLenum format, - GLenum type, - const void* data); - -// A struct containing pointers to resolved gl* functions. -struct GlProcs { - glGenTexturesProc glGenTextures; - glDeleteTexturesProc glDeleteTextures; - glBindTextureProc glBindTexture; - glTexParameteriProc glTexParameteri; - glTexImage2DProc glTexImage2D; - bool valid; -}; - -static const GlProcs& GlProcs() { - static struct GlProcs procs = {}; - static bool initialized = false; - if (!initialized) { - procs.glGenTextures = - reinterpret_cast(eglGetProcAddress("glGenTextures")); - procs.glDeleteTextures = reinterpret_cast( - eglGetProcAddress("glDeleteTextures")); - procs.glBindTexture = - reinterpret_cast(eglGetProcAddress("glBindTexture")); - procs.glTexParameteri = reinterpret_cast( - eglGetProcAddress("glTexParameteri")); - procs.glTexImage2D = - reinterpret_cast(eglGetProcAddress("glTexImage2D")); - - procs.valid = procs.glGenTextures && procs.glDeleteTextures && - procs.glBindTexture && procs.glTexParameteri && - procs.glTexImage2D; - initialized = true; - } - return procs; -} - -} // namespace - -namespace flutter { - -struct ExternalTextureGLState { - GLuint gl_texture = 0; -}; - -ExternalTextureGL::ExternalTextureGL( - FlutterDesktopPixelBufferTextureCallback texture_callback, - void* user_data) - : state_(std::make_unique()), - texture_callback_(texture_callback), - user_data_(user_data) {} - -ExternalTextureGL::~ExternalTextureGL() { - const auto& gl = GlProcs(); - if (gl.valid && state_->gl_texture != 0) { - gl.glDeleteTextures(1, &state_->gl_texture); - } -} - -bool ExternalTextureGL::PopulateTexture(size_t width, - size_t height, - FlutterOpenGLTexture* opengl_texture) { - if (!CopyPixelBuffer(width, height)) { - return false; - } - - // Populate the texture object used by the engine. - opengl_texture->target = GL_TEXTURE_2D; - opengl_texture->name = state_->gl_texture; -#ifdef USE_GLES3 - opengl_texture->format = GL_RGBA8; -#else - opengl_texture->format = GL_RGBA8_OES; -#endif - opengl_texture->destruction_callback = nullptr; - opengl_texture->user_data = nullptr; - opengl_texture->width = width; - opengl_texture->height = height; - - return true; -} - -bool ExternalTextureGL::CopyPixelBuffer(size_t& width, size_t& height) { - const FlutterDesktopPixelBuffer* pixel_buffer = - texture_callback_(width, height, user_data_); - const auto& gl = GlProcs(); - if (!gl.valid || !pixel_buffer || !pixel_buffer->buffer) { - return false; - } - width = pixel_buffer->width; - height = pixel_buffer->height; - - if (state_->gl_texture == 0) { - gl.glGenTextures(1, &state_->gl_texture); - - gl.glBindTexture(GL_TEXTURE_2D, state_->gl_texture); - -#ifdef USE_GLES3 - gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); - gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); -#else - gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, - GL_CLAMP_TO_BORDER_OES); - gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, - GL_CLAMP_TO_BORDER_OES); -#endif - - gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - - } else { - gl.glBindTexture(GL_TEXTURE_2D, state_->gl_texture); - } -#ifdef USE_GLES3 - gl.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, pixel_buffer->width, - pixel_buffer->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, - pixel_buffer->buffer); -#else - gl.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pixel_buffer->width, - pixel_buffer->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, - pixel_buffer->buffer); -#endif - return true; -} - -} // namespace flutter diff --git a/src/flutter/shell/platform/linux_embedded/external_texture_gl.h b/src/flutter/shell/platform/linux_embedded/external_texture_gl.h deleted file mode 100644 index 45819d6c..00000000 --- a/src/flutter/shell/platform/linux_embedded/external_texture_gl.h +++ /dev/null @@ -1,56 +0,0 @@ -// 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. - -#ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_EXTERNAL_TEXTURE_GL_H_ -#define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_EXTERNAL_TEXTURE_GL_H_ - -#include - -#include - -#include "flutter/shell/platform/common/public/flutter_texture_registrar.h" -#include "flutter/shell/platform/embedder/embedder.h" - -namespace flutter { - -typedef struct ExternalTextureGLState ExternalTextureGLState; - -// An abstraction of an OpenGL texture. -class ExternalTextureGL { - public: - ExternalTextureGL(FlutterDesktopPixelBufferTextureCallback texture_callback, - void* user_data); - - virtual ~ExternalTextureGL(); - - // Returns the unique id of this texture. - int64_t texture_id() { return reinterpret_cast(this); } - - void MarkFrameAvailable(); - - // Attempts to populate the specified |opengl_texture| with texture details - // such as the name, width, height and the pixel format upon successfully - // copying the buffer provided by |texture_callback_|. See |CopyPixelBuffer|. - // Returns true on success or false if the pixel buffer could not be copied. - bool PopulateTexture(size_t width, - size_t height, - FlutterOpenGLTexture* opengl_texture); - - private: - // Attempts to copy the pixel buffer returned by |texture_callback_| to - // OpenGL. - // The |width| and |height| will be set to the actual bounds of the copied - // pixel buffer. - // Returns true on success or false if the pixel buffer returned - // by |texture_callback_| was invalid. - bool CopyPixelBuffer(size_t& width, size_t& height); - - std::unique_ptr state_; - FlutterDesktopPixelBufferTextureCallback texture_callback_ = nullptr; - void* user_data_ = nullptr; -}; - -} // namespace flutter - -#endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_EXTERNAL_TEXTURE_GL_H_ diff --git a/src/flutter/shell/platform/linux_embedded/external_texture_pixelbuffer.cc b/src/flutter/shell/platform/linux_embedded/external_texture_pixelbuffer.cc new file mode 100644 index 00000000..1b962691 --- /dev/null +++ b/src/flutter/shell/platform/linux_embedded/external_texture_pixelbuffer.cc @@ -0,0 +1,82 @@ +// 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. + +#include "flutter/shell/platform/linux_embedded/external_texture_pixelbuffer.h" + +namespace flutter { + +struct ExternalTexturePixelBufferState { + GLuint gl_texture = 0; +}; + +ExternalTexturePixelBuffer::ExternalTexturePixelBuffer( + FlutterDesktopPixelBufferTextureCallback texture_callback, + void* user_data, + const GlProcs& gl_procs) + : state_(std::make_unique()), + texture_callback_(texture_callback), + user_data_(user_data), + gl_(gl_procs) {} + +ExternalTexturePixelBuffer::~ExternalTexturePixelBuffer() { + if (state_->gl_texture != 0) { + gl_.glDeleteTextures(1, &state_->gl_texture); + } +} + +bool ExternalTexturePixelBuffer::PopulateTexture( + size_t width, + size_t height, + FlutterOpenGLTexture* opengl_texture) { + if (!CopyPixelBuffer(width, height)) { + return false; + } + + // Populate the texture object used by the engine. + opengl_texture->target = GL_TEXTURE_2D; + opengl_texture->name = state_->gl_texture; +#ifdef USE_GLES3 + opengl_texture->format = GL_RGBA8; +#else + opengl_texture->format = GL_RGBA8_OES; +#endif + opengl_texture->destruction_callback = nullptr; + opengl_texture->user_data = nullptr; + opengl_texture->width = width; + opengl_texture->height = height; + + return true; +} + +bool ExternalTexturePixelBuffer::CopyPixelBuffer(size_t& width, + size_t& height) { + const FlutterDesktopPixelBuffer* pixel_buffer = + texture_callback_(width, height, user_data_); + if (!pixel_buffer || !pixel_buffer->buffer) { + return false; + } + width = pixel_buffer->width; + height = pixel_buffer->height; + + if (state_->gl_texture == 0) { + gl_.glGenTextures(1, &state_->gl_texture); + + gl_.glBindTexture(GL_TEXTURE_2D, state_->gl_texture); + gl_.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + gl_.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + gl_.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + gl_.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + } else { + gl_.glBindTexture(GL_TEXTURE_2D, state_->gl_texture); + } + gl_.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pixel_buffer->width, + pixel_buffer->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, + pixel_buffer->buffer); + if (pixel_buffer->release_callback) { + pixel_buffer->release_callback(pixel_buffer->release_context); + } + return true; +} + +} // namespace flutter diff --git a/src/flutter/shell/platform/linux_embedded/external_texture_pixelbuffer.h b/src/flutter/shell/platform/linux_embedded/external_texture_pixelbuffer.h new file mode 100644 index 00000000..0d6dc67c --- /dev/null +++ b/src/flutter/shell/platform/linux_embedded/external_texture_pixelbuffer.h @@ -0,0 +1,52 @@ +// 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. + +#ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_EXTERNAL_TEXTURE_PIXELBUFFER_H_ +#define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_EXTERNAL_TEXTURE_PIXELBUFFER_H_ + +#include + +#include + +#include "flutter/shell/platform/common/public/flutter_texture_registrar.h" + +#include "flutter/shell/platform/linux_embedded/external_texture.h" + +namespace flutter { + +typedef struct ExternalTexturePixelBufferState ExternalTexturePixelBufferState; + +// An abstraction of an pixel-buffer based texture. +class ExternalTexturePixelBuffer : public ExternalTexture { + public: + ExternalTexturePixelBuffer( + FlutterDesktopPixelBufferTextureCallback texture_callback, + void* user_data, + const GlProcs& gl_procs); + + virtual ~ExternalTexturePixelBuffer(); + + // |ExternalTexture| + bool PopulateTexture(size_t width, + size_t height, + FlutterOpenGLTexture* opengl_texture) override; + + private: + // Attempts to copy the pixel buffer returned by |texture_callback_| to + // OpenGL. + // The |width| and |height| will be set to the actual bounds of the copied + // pixel buffer. + // Returns true on success or false if the pixel buffer returned + // by |texture_callback_| was invalid. + bool CopyPixelBuffer(size_t& width, size_t& height); + + std::unique_ptr state_; + FlutterDesktopPixelBufferTextureCallback texture_callback_ = nullptr; + void* const user_data_ = nullptr; + const GlProcs& gl_; +}; + +} // namespace flutter + +#endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_EXTERNAL_TEXTURE_PIXELBUFFER_H_ diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc index 6df08e56..38e6a028 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc @@ -131,7 +131,10 @@ FlutterELinuxEngine::FlutterELinuxEngine(const FlutterProjectBundle& project) messenger_wrapper_ = std::make_unique(messenger_.get()); message_dispatcher_ = std::make_unique(messenger_.get()); - texture_registrar_ = std::make_unique(this); + + FlutterELinuxTextureRegistrar::ResolveGlFunctions(gl_procs_); + texture_registrar_ = + std::make_unique(this, gl_procs_); // Set up internal channels. // TODO: Replace this with an embedder.h API. See diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h index 11a378b6..83de54d2 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h @@ -158,6 +158,9 @@ class FlutterELinuxEngine { // The texture registrar. std::unique_ptr texture_registrar_; + // Resolved OpenGL functions used by external texture implementations. + GlProcs gl_procs_ = {}; + // The MethodChannel used for communication with the Flutter engine. std::unique_ptr> settings_channel_; diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_texture_registrar.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux_texture_registrar.cc index 8899c5fc..29fcbdd9 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_texture_registrar.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_texture_registrar.cc @@ -4,38 +4,55 @@ #include "flutter/shell/platform/linux_embedded/flutter_elinux_texture_registrar.h" -#include "flutter/shell/platform/linux_embedded/flutter_elinux_engine.h" - #include #include +#include "flutter/shell/platform/embedder/embedder_struct_macros.h" +#include "flutter/shell/platform/linux_embedded/external_texture_pixelbuffer.h" +#include "flutter/shell/platform/linux_embedded/flutter_elinux_engine.h" +#include "flutter/shell/platform/linux_embedded/flutter_elinux_view.h" + +namespace { +static constexpr int64_t kInvalidTexture = -1; +} + namespace flutter { FlutterELinuxTextureRegistrar::FlutterELinuxTextureRegistrar( - FlutterELinuxEngine* engine) - : engine_(engine) {} + FlutterELinuxEngine* engine, + const GlProcs& gl_procs) + : engine_(engine), gl_procs_(gl_procs) {} int64_t FlutterELinuxTextureRegistrar::RegisterTexture( const FlutterDesktopTextureInfo* texture_info) { - if (texture_info->type != kFlutterDesktopPixelBufferTexture) { - std::cerr << "Attempted to register texture of unsupport type." - << std::endl; - return -1; + if (!gl_procs_.valid) { + return kInvalidTexture; } - if (!texture_info->pixel_buffer_config.callback) { - std::cerr << "Invalid pixel buffer texture callback." << std::endl; - return -1; + if (texture_info->type == kFlutterDesktopPixelBufferTexture) { + if (!texture_info->pixel_buffer_config.callback) { + std::cerr << "Invalid pixel buffer texture callback." << std::endl; + return kInvalidTexture; + } + + return EmplaceTexture(std::make_unique( + texture_info->pixel_buffer_config.callback, + texture_info->pixel_buffer_config.user_data, gl_procs_)); + } else if (texture_info->type == kFlutterDesktopGpuSurfaceTexture) { + std::cerr << "GpuSurfaceTexture is not yet supported." << std::endl; + return kInvalidTexture; } - auto texture_gl = std::make_unique( - texture_info->pixel_buffer_config.callback, - texture_info->pixel_buffer_config.user_data); - int64_t texture_id = texture_gl->texture_id(); + std::cerr << "Attempted to register texture of unsupport type." << std::endl; + return kInvalidTexture; +} +int64_t FlutterELinuxTextureRegistrar::EmplaceTexture( + std::unique_ptr texture) { + int64_t texture_id = texture->texture_id(); { std::lock_guard lock(map_mutex_); - textures_[texture_id] = std::move(texture_gl); + textures_[texture_id] = std::move(texture); } engine_->task_runner()->RunNowOrPostTask([engine = engine_, texture_id]() { @@ -74,7 +91,7 @@ bool FlutterELinuxTextureRegistrar::PopulateTexture( size_t width, size_t height, FlutterOpenGLTexture* opengl_texture) { - flutter::ExternalTextureGL* texture; + flutter::ExternalTexture* texture; { std::lock_guard lock(map_mutex_); auto it = textures_.find(texture_id); @@ -86,4 +103,21 @@ bool FlutterELinuxTextureRegistrar::PopulateTexture( return texture->PopulateTexture(width, height, opengl_texture); } +void FlutterELinuxTextureRegistrar::ResolveGlFunctions(GlProcs& procs) { + procs.glGenTextures = + reinterpret_cast(eglGetProcAddress("glGenTextures")); + procs.glDeleteTextures = reinterpret_cast( + eglGetProcAddress("glDeleteTextures")); + procs.glBindTexture = + reinterpret_cast(eglGetProcAddress("glBindTexture")); + procs.glTexParameteri = reinterpret_cast( + eglGetProcAddress("glTexParameteri")); + procs.glTexImage2D = + reinterpret_cast(eglGetProcAddress("glTexImage2D")); + + procs.valid = procs.glGenTextures && procs.glDeleteTextures && + procs.glBindTexture && procs.glTexParameteri && + procs.glTexImage2D; +} + }; // namespace flutter diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_texture_registrar.h b/src/flutter/shell/platform/linux_embedded/flutter_elinux_texture_registrar.h index 0b46a1fa..7ad57a2f 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_texture_registrar.h +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_texture_registrar.h @@ -9,7 +9,8 @@ #include #include -#include "flutter/shell/platform/linux_embedded/external_texture_gl.h" +#include "flutter/shell/platform/common/public/flutter_texture_registrar.h" +#include "flutter/shell/platform/linux_embedded/external_texture.h" namespace flutter { @@ -19,7 +20,8 @@ class FlutterELinuxEngine; // Thread safety: All member methods are thread safe. class FlutterELinuxTextureRegistrar { public: - explicit FlutterELinuxTextureRegistrar(FlutterELinuxEngine* engine); + explicit FlutterELinuxTextureRegistrar(FlutterELinuxEngine* engine, + const GlProcs& gl_procs); // Registers a texture described by the given |texture_info| object. // Returns the non-zero, positive texture id or -1 on error. @@ -41,13 +43,19 @@ class FlutterELinuxTextureRegistrar { size_t height, FlutterOpenGLTexture* texture); + // Populates the OpenGL function pointers in |gl_procs|. + static void ResolveGlFunctions(GlProcs& gl_procs); + private: FlutterELinuxEngine* engine_ = nullptr; + const GlProcs& gl_procs_; // All registered textures, keyed by their IDs. - std::unordered_map> + std::unordered_map> textures_; std::mutex map_mutex_; + + int64_t EmplaceTexture(std::unique_ptr texture); }; }; // namespace flutter From ecc39c2401374771db34ab588e50a9d55189f8dc Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Sun, 7 Aug 2022 10:36:22 +0900 Subject: [PATCH 018/112] Add EGL alpha component of the color buffer option (#278) * Add EGL alpha component of the color buffer option Signed-off-by: Hidenori Matsubayashi --- CMakeLists.txt | 1 + cmake/build.cmake | 7 ++++++ .../linux_embedded/surface/context_egl.cc | 24 ++++++++++--------- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9fe0192a..7cfedf0c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ project("flutter_elinux" LANGUAGES CXX C) # Build options. option(BACKEND_TYPE "Select WAYLAND, DRM-GBM, DRM-EGLSTREAM, or X11 as the display backend type" WAYLAND) option(USE_GLES3 "Use OpenGL ES3 (default is OpenGL ES2)" OFF) +option(ENABLE_EGL_ALPHA_COMPONENT_OF_COLOR_BUFFER "Enable alpha component of the EGL color buffer" ON) option(BUILD_ELINUX_SO "Build .so file of elinux embedder" OFF) option(ENABLE_ELINUX_EMBEDDER_LOG "Enable logger of eLinux embedder" ON) option(FLUTTER_RELEASE "Build Flutter Engine with release mode" OFF) diff --git a/cmake/build.cmake b/cmake/build.cmake index c64fd5ce..c1ae62e4 100644 --- a/cmake/build.cmake +++ b/cmake/build.cmake @@ -99,6 +99,13 @@ if(ENABLE_ELINUX_EMBEDDER_LOG) ) endif() +# Enable alpha component of the egl color buffer. +if(ENABLE_EGL_ALPHA_COMPONENT_OF_COLOR_BUFFER) + add_definitions( + -DENABLE_EGL_ALPHA_COMPONENT_OF_COLOR_BUFFER + ) +endif() + set(CPP_WRAPPER_SOURCES_CORE "src/flutter/shell/platform/common/client_wrapper/engine_method_result.cc" "src/flutter/shell/platform/common/client_wrapper/standard_codec.cc" diff --git a/src/flutter/shell/platform/linux_embedded/surface/context_egl.cc b/src/flutter/shell/platform/linux_embedded/surface/context_egl.cc index 978af656..f723bd57 100644 --- a/src/flutter/shell/platform/linux_embedded/surface/context_egl.cc +++ b/src/flutter/shell/platform/linux_embedded/surface/context_egl.cc @@ -14,17 +14,19 @@ ContextEgl::ContextEgl(std::unique_ptr environment, : environment_(std::move(environment)), config_(nullptr) { EGLint config_count = 0; const EGLint attribs[] = { - // clang-format off - EGL_SURFACE_TYPE, egl_surface_type, - EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, - EGL_RED_SIZE, 8, - EGL_GREEN_SIZE, 8, - EGL_BLUE_SIZE, 8, - EGL_ALPHA_SIZE, 8, - EGL_DEPTH_SIZE, 0, - EGL_STENCIL_SIZE, 0, - EGL_NONE - // clang-format on + // clang-format off + EGL_SURFACE_TYPE, egl_surface_type, + EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, + EGL_RED_SIZE, 8, + EGL_GREEN_SIZE, 8, + EGL_BLUE_SIZE, 8, +#if defined(ENABLE_EGL_ALPHA_COMPONENT_OF_COLOR_BUFFER) + EGL_ALPHA_SIZE, 8, +#endif + EGL_DEPTH_SIZE, 0, + EGL_STENCIL_SIZE, 0, + EGL_NONE + // clang-format on }; if (eglChooseConfig(environment_->Display(), attribs, &config_, 1, &config_count) != EGL_TRUE) { From 8ddb112b192b71acb3fe91ad867b10dff34edd97 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Sun, 7 Aug 2022 14:12:19 +0900 Subject: [PATCH 019/112] Update versions of the wayland protocols correctly (#280) * Update versions of the wayland protocols correctly Signed-off-by: Hidenori Matsubayashi --- .../window/elinux_window_wayland.cc | 38 +++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc index be0c75e7..31c9fac3 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -245,6 +246,8 @@ const wl_seat_listener ELinuxWindowWayland::kWlSeatListener = { self->wl_keyboard_ = nullptr; } }, + .name = [](void* data, struct wl_seat* wl_seat, const char* name) -> void { + }, }; const wl_pointer_listener ELinuxWindowWayland::kWlPointerListener = { @@ -259,7 +262,7 @@ const wl_pointer_listener ELinuxWindowWayland::kWlPointerListener = { self->serial_ = serial; if (self->view_properties_.use_mouse_cursor) { - self->cursor_info_.pointer = wl_pointer; + self->cursor_info_.pointer = self->wl_pointer_; self->cursor_info_.serial = serial; } @@ -1271,41 +1274,50 @@ void ELinuxWindowWayland::WlRegistryHandler(wl_registry* wl_registry, const char* interface, uint32_t version) { if (!strcmp(interface, wl_compositor_interface.name)) { + constexpr uint32_t kMaxVersion = 5; wl_compositor_ = static_cast( - wl_registry_bind(wl_registry, name, &wl_compositor_interface, 1)); + wl_registry_bind(wl_registry, name, &wl_compositor_interface, + std::min(kMaxVersion, version))); return; } if (!strcmp(interface, wl_subcompositor_interface.name)) { - wl_subcompositor_ = static_cast( - wl_registry_bind(wl_registry, name, &wl_subcompositor_interface, 1)); + constexpr uint32_t kMaxVersion = 1; + wl_subcompositor_ = static_cast(wl_registry_bind( + wl_registry, name, &wl_subcompositor_interface, kMaxVersion)); } if (!strcmp(interface, xdg_wm_base_interface.name)) { + constexpr uint32_t kMaxVersion = 3; xdg_wm_base_ = static_cast( - wl_registry_bind(wl_registry, name, &xdg_wm_base_interface, 1)); + wl_registry_bind(wl_registry, name, &xdg_wm_base_interface, + std::min(kMaxVersion, version))); xdg_wm_base_add_listener(xdg_wm_base_, &kXdgWmBaseListener, this); return; } if (!strcmp(interface, wl_seat_interface.name)) { - wl_seat_ = static_cast( - wl_registry_bind(wl_registry, name, &wl_seat_interface, 1)); + constexpr uint32_t kMaxVersion = 4; + wl_seat_ = static_cast(wl_registry_bind( + wl_registry, name, &wl_seat_interface, std::min(kMaxVersion, version))); wl_seat_add_listener(wl_seat_, &kWlSeatListener, this); return; } if (!strcmp(interface, wl_output_interface.name)) { + constexpr uint32_t kMaxVersion = 2; wl_output_ = static_cast( - wl_registry_bind(wl_registry, name, &wl_output_interface, 1)); + wl_registry_bind(wl_registry, name, &wl_output_interface, + std::min(kMaxVersion, version))); wl_output_add_listener(wl_output_, &kWlOutputListener, this); return; } if (!strcmp(interface, wl_shm_interface.name)) { if (view_properties_.use_mouse_cursor) { + constexpr uint32_t kMaxVersion = 1; wl_shm_ = static_cast( - wl_registry_bind(wl_registry, name, &wl_shm_interface, 1)); + wl_registry_bind(wl_registry, name, &wl_shm_interface, kMaxVersion)); wl_cursor_theme_ = wl_cursor_theme_load(nullptr, 32, wl_shm_); if (!wl_cursor_theme_) { ELINUX_LOG(ERROR) << "Failed to load cursor theme."; @@ -1318,18 +1330,22 @@ void ELinuxWindowWayland::WlRegistryHandler(wl_registry* wl_registry, if (!strcmp(interface, kZwpTextInputManagerV1)) { if (view_properties_.use_onscreen_keyboard) { + constexpr uint32_t kMaxVersion = 1; zwp_text_input_manager_v1_ = static_cast(wl_registry_bind( - wl_registry, name, &zwp_text_input_manager_v1_interface, 1)); + wl_registry, name, &zwp_text_input_manager_v1_interface, + kMaxVersion)); } return; } if (!strcmp(interface, kZwpTextInputManagerV3)) { if (view_properties_.use_onscreen_keyboard) { + constexpr uint32_t kMaxVersion = 1; zwp_text_input_manager_v3_ = static_cast(wl_registry_bind( - wl_registry, name, &zwp_text_input_manager_v3_interface, 1)); + wl_registry, name, &zwp_text_input_manager_v3_interface, + std::min(kMaxVersion, version))); } return; } From f1de80f92b03704d54317bb70cf94ec0c87ba24a Mon Sep 17 00:00:00 2001 From: andreadaoud <110679408+andreadaoud@users.noreply.github.com> Date: Fri, 19 Aug 2022 12:12:18 +0800 Subject: [PATCH 020/112] Add support for setting scale factor from parameters (#277) * Add support for setting scale factor from parameters Signed-off-by: Andrea Daoud * Add force scale factor support to command line arguments Signed-off-by: Andrea Daoud * Add myself to AUTHORS Signed-off-by: Andrea Daoud Signed-off-by: Andrea Daoud --- AUTHORS | 1 + .../command_options.h | 13 +++++++++++++ .../flutter_embedder_options.h | 15 +++++++++++++++ examples/flutter-drm-eglstream-backend/main.cc | 2 ++ .../flutter-drm-gbm-backend/command_options.h | 13 +++++++++++++ .../flutter_embedder_options.h | 15 +++++++++++++++ examples/flutter-drm-gbm-backend/main.cc | 2 ++ .../command_options.h | 13 +++++++++++++ .../flutter_embedder_options.h | 15 +++++++++++++++ examples/flutter-external-texture-plugin/main.cc | 2 ++ .../flutter-video-player-plugin/command_options.h | 13 +++++++++++++ .../flutter_embedder_options.h | 15 +++++++++++++++ examples/flutter-video-player-plugin/main.cc | 2 ++ examples/flutter-wayland-client/command_options.h | 13 +++++++++++++ .../flutter_embedder_options.h | 15 +++++++++++++++ examples/flutter-wayland-client/main.cc | 2 ++ examples/flutter-x11-client/command_options.h | 13 +++++++++++++ .../flutter-x11-client/flutter_embedder_options.h | 15 +++++++++++++++ examples/flutter-x11-client/main.cc | 2 ++ src/client_wrapper/flutter_view_controller.cc | 2 ++ .../include/flutter/flutter_view_controller.h | 4 ++++ .../linux_embedded/public/flutter_elinux.h | 4 ++++ .../linux_embedded/window/elinux_window_drm.h | 2 ++ .../window/elinux_window_wayland.cc | 5 ++++- .../linux_embedded/window/elinux_window_x11.cc | 2 ++ 25 files changed, 199 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index 649f420b..8244baf0 100644 --- a/AUTHORS +++ b/AUTHORS @@ -6,3 +6,4 @@ Sony Group Corporation Hidenori Matsubayashi (hidenori.matsubayashi@gmail.com) +Andrea Daoud (andreadaoud6@gmail.com) diff --git a/examples/flutter-drm-eglstream-backend/command_options.h b/examples/flutter-drm-eglstream-backend/command_options.h index 107a152d..ad49e840 100644 --- a/examples/flutter-drm-eglstream-backend/command_options.h +++ b/examples/flutter-drm-eglstream-backend/command_options.h @@ -56,6 +56,15 @@ class CommandOptions { ReaderInt(), required, true); } + void AddDouble(const std::string& name, + const std::string& short_name, + const std::string& description, + const double& default_value, + bool required) { + Add(name, short_name, description, default_value, + ReaderDouble(), required, true); + } + void AddString(const std::string& name, const std::string& short_name, const std::string& description, @@ -250,6 +259,10 @@ class CommandOptions { std::string operator()(const std::string& value) { return value; } }; + struct ReaderDouble { + double operator()(const std::string& value) { return std::stod(value); } + }; + class Option { public: Option(const std::string& name, diff --git a/examples/flutter-drm-eglstream-backend/flutter_embedder_options.h b/examples/flutter-drm-eglstream-backend/flutter_embedder_options.h index 4c229135..cc8193fc 100644 --- a/examples/flutter-drm-eglstream-backend/flutter_embedder_options.h +++ b/examples/flutter-drm-eglstream-backend/flutter_embedder_options.h @@ -21,6 +21,9 @@ class FlutterEmbedderOptions { options_.AddInt("rotation", "r", "Window rotation(degree) [0(default)|90|180|270]", 0, false); + options_.AddDouble("force-scale-factor", "s", + "Force a scale factor instead using default value", 1.0, + false); #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) // no more options. @@ -72,6 +75,14 @@ class FlutterEmbedderOptions { } } + if (options_.Exist("force-scale-factor")) { + is_force_scale_factor_ = true; + scale_factor_ = options_.GetValue("force-scale-factor"); + } else { + is_force_scale_factor_ = false; + scale_factor_ = 1.0; + } + #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) use_onscreen_keyboard_ = false; @@ -112,6 +123,8 @@ class FlutterEmbedderOptions { flutter::FlutterViewController::ViewRotation WindowRotation() const { return window_view_rotation_; } + bool IsForceScaleFactor() const { return is_force_scale_factor_; } + double ScaleFactor() const { return scale_factor_; } private: commandline::CommandOptions options_; @@ -126,6 +139,8 @@ class FlutterEmbedderOptions { int window_height_ = 720; flutter::FlutterViewController::ViewRotation window_view_rotation_ = flutter::FlutterViewController::ViewRotation::kRotation_0; + bool is_force_scale_factor_; + double scale_factor_; }; #endif // FLUTTER_EMBEDDER_OPTIONS_ diff --git a/examples/flutter-drm-eglstream-backend/main.cc b/examples/flutter-drm-eglstream-backend/main.cc index fa4e11b8..fbc049d6 100644 --- a/examples/flutter-drm-eglstream-backend/main.cc +++ b/examples/flutter-drm-eglstream-backend/main.cc @@ -33,6 +33,8 @@ int main(int argc, char** argv) { view_properties.use_mouse_cursor = options.IsUseMouseCursor(); view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); view_properties.use_window_decoration = options.IsUseWindowDecoraation(); + view_properties.force_scale_factor = options.IsForceScaleFactor(); + view_properties.scale_factor = options.ScaleFactor(); // The Flutter instance hosted by this window. FlutterWindow window(view_properties, project); diff --git a/examples/flutter-drm-gbm-backend/command_options.h b/examples/flutter-drm-gbm-backend/command_options.h index 107a152d..ad49e840 100644 --- a/examples/flutter-drm-gbm-backend/command_options.h +++ b/examples/flutter-drm-gbm-backend/command_options.h @@ -56,6 +56,15 @@ class CommandOptions { ReaderInt(), required, true); } + void AddDouble(const std::string& name, + const std::string& short_name, + const std::string& description, + const double& default_value, + bool required) { + Add(name, short_name, description, default_value, + ReaderDouble(), required, true); + } + void AddString(const std::string& name, const std::string& short_name, const std::string& description, @@ -250,6 +259,10 @@ class CommandOptions { std::string operator()(const std::string& value) { return value; } }; + struct ReaderDouble { + double operator()(const std::string& value) { return std::stod(value); } + }; + class Option { public: Option(const std::string& name, diff --git a/examples/flutter-drm-gbm-backend/flutter_embedder_options.h b/examples/flutter-drm-gbm-backend/flutter_embedder_options.h index 4c229135..cc8193fc 100644 --- a/examples/flutter-drm-gbm-backend/flutter_embedder_options.h +++ b/examples/flutter-drm-gbm-backend/flutter_embedder_options.h @@ -21,6 +21,9 @@ class FlutterEmbedderOptions { options_.AddInt("rotation", "r", "Window rotation(degree) [0(default)|90|180|270]", 0, false); + options_.AddDouble("force-scale-factor", "s", + "Force a scale factor instead using default value", 1.0, + false); #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) // no more options. @@ -72,6 +75,14 @@ class FlutterEmbedderOptions { } } + if (options_.Exist("force-scale-factor")) { + is_force_scale_factor_ = true; + scale_factor_ = options_.GetValue("force-scale-factor"); + } else { + is_force_scale_factor_ = false; + scale_factor_ = 1.0; + } + #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) use_onscreen_keyboard_ = false; @@ -112,6 +123,8 @@ class FlutterEmbedderOptions { flutter::FlutterViewController::ViewRotation WindowRotation() const { return window_view_rotation_; } + bool IsForceScaleFactor() const { return is_force_scale_factor_; } + double ScaleFactor() const { return scale_factor_; } private: commandline::CommandOptions options_; @@ -126,6 +139,8 @@ class FlutterEmbedderOptions { int window_height_ = 720; flutter::FlutterViewController::ViewRotation window_view_rotation_ = flutter::FlutterViewController::ViewRotation::kRotation_0; + bool is_force_scale_factor_; + double scale_factor_; }; #endif // FLUTTER_EMBEDDER_OPTIONS_ diff --git a/examples/flutter-drm-gbm-backend/main.cc b/examples/flutter-drm-gbm-backend/main.cc index fa4e11b8..fbc049d6 100644 --- a/examples/flutter-drm-gbm-backend/main.cc +++ b/examples/flutter-drm-gbm-backend/main.cc @@ -33,6 +33,8 @@ int main(int argc, char** argv) { view_properties.use_mouse_cursor = options.IsUseMouseCursor(); view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); view_properties.use_window_decoration = options.IsUseWindowDecoraation(); + view_properties.force_scale_factor = options.IsForceScaleFactor(); + view_properties.scale_factor = options.ScaleFactor(); // The Flutter instance hosted by this window. FlutterWindow window(view_properties, project); diff --git a/examples/flutter-external-texture-plugin/command_options.h b/examples/flutter-external-texture-plugin/command_options.h index 107a152d..ad49e840 100644 --- a/examples/flutter-external-texture-plugin/command_options.h +++ b/examples/flutter-external-texture-plugin/command_options.h @@ -56,6 +56,15 @@ class CommandOptions { ReaderInt(), required, true); } + void AddDouble(const std::string& name, + const std::string& short_name, + const std::string& description, + const double& default_value, + bool required) { + Add(name, short_name, description, default_value, + ReaderDouble(), required, true); + } + void AddString(const std::string& name, const std::string& short_name, const std::string& description, @@ -250,6 +259,10 @@ class CommandOptions { std::string operator()(const std::string& value) { return value; } }; + struct ReaderDouble { + double operator()(const std::string& value) { return std::stod(value); } + }; + class Option { public: Option(const std::string& name, diff --git a/examples/flutter-external-texture-plugin/flutter_embedder_options.h b/examples/flutter-external-texture-plugin/flutter_embedder_options.h index 4c229135..cc8193fc 100644 --- a/examples/flutter-external-texture-plugin/flutter_embedder_options.h +++ b/examples/flutter-external-texture-plugin/flutter_embedder_options.h @@ -21,6 +21,9 @@ class FlutterEmbedderOptions { options_.AddInt("rotation", "r", "Window rotation(degree) [0(default)|90|180|270]", 0, false); + options_.AddDouble("force-scale-factor", "s", + "Force a scale factor instead using default value", 1.0, + false); #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) // no more options. @@ -72,6 +75,14 @@ class FlutterEmbedderOptions { } } + if (options_.Exist("force-scale-factor")) { + is_force_scale_factor_ = true; + scale_factor_ = options_.GetValue("force-scale-factor"); + } else { + is_force_scale_factor_ = false; + scale_factor_ = 1.0; + } + #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) use_onscreen_keyboard_ = false; @@ -112,6 +123,8 @@ class FlutterEmbedderOptions { flutter::FlutterViewController::ViewRotation WindowRotation() const { return window_view_rotation_; } + bool IsForceScaleFactor() const { return is_force_scale_factor_; } + double ScaleFactor() const { return scale_factor_; } private: commandline::CommandOptions options_; @@ -126,6 +139,8 @@ class FlutterEmbedderOptions { int window_height_ = 720; flutter::FlutterViewController::ViewRotation window_view_rotation_ = flutter::FlutterViewController::ViewRotation::kRotation_0; + bool is_force_scale_factor_; + double scale_factor_; }; #endif // FLUTTER_EMBEDDER_OPTIONS_ diff --git a/examples/flutter-external-texture-plugin/main.cc b/examples/flutter-external-texture-plugin/main.cc index fa4e11b8..fbc049d6 100644 --- a/examples/flutter-external-texture-plugin/main.cc +++ b/examples/flutter-external-texture-plugin/main.cc @@ -33,6 +33,8 @@ int main(int argc, char** argv) { view_properties.use_mouse_cursor = options.IsUseMouseCursor(); view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); view_properties.use_window_decoration = options.IsUseWindowDecoraation(); + view_properties.force_scale_factor = options.IsForceScaleFactor(); + view_properties.scale_factor = options.ScaleFactor(); // The Flutter instance hosted by this window. FlutterWindow window(view_properties, project); diff --git a/examples/flutter-video-player-plugin/command_options.h b/examples/flutter-video-player-plugin/command_options.h index 107a152d..ad49e840 100644 --- a/examples/flutter-video-player-plugin/command_options.h +++ b/examples/flutter-video-player-plugin/command_options.h @@ -56,6 +56,15 @@ class CommandOptions { ReaderInt(), required, true); } + void AddDouble(const std::string& name, + const std::string& short_name, + const std::string& description, + const double& default_value, + bool required) { + Add(name, short_name, description, default_value, + ReaderDouble(), required, true); + } + void AddString(const std::string& name, const std::string& short_name, const std::string& description, @@ -250,6 +259,10 @@ class CommandOptions { std::string operator()(const std::string& value) { return value; } }; + struct ReaderDouble { + double operator()(const std::string& value) { return std::stod(value); } + }; + class Option { public: Option(const std::string& name, diff --git a/examples/flutter-video-player-plugin/flutter_embedder_options.h b/examples/flutter-video-player-plugin/flutter_embedder_options.h index 4c229135..cc8193fc 100644 --- a/examples/flutter-video-player-plugin/flutter_embedder_options.h +++ b/examples/flutter-video-player-plugin/flutter_embedder_options.h @@ -21,6 +21,9 @@ class FlutterEmbedderOptions { options_.AddInt("rotation", "r", "Window rotation(degree) [0(default)|90|180|270]", 0, false); + options_.AddDouble("force-scale-factor", "s", + "Force a scale factor instead using default value", 1.0, + false); #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) // no more options. @@ -72,6 +75,14 @@ class FlutterEmbedderOptions { } } + if (options_.Exist("force-scale-factor")) { + is_force_scale_factor_ = true; + scale_factor_ = options_.GetValue("force-scale-factor"); + } else { + is_force_scale_factor_ = false; + scale_factor_ = 1.0; + } + #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) use_onscreen_keyboard_ = false; @@ -112,6 +123,8 @@ class FlutterEmbedderOptions { flutter::FlutterViewController::ViewRotation WindowRotation() const { return window_view_rotation_; } + bool IsForceScaleFactor() const { return is_force_scale_factor_; } + double ScaleFactor() const { return scale_factor_; } private: commandline::CommandOptions options_; @@ -126,6 +139,8 @@ class FlutterEmbedderOptions { int window_height_ = 720; flutter::FlutterViewController::ViewRotation window_view_rotation_ = flutter::FlutterViewController::ViewRotation::kRotation_0; + bool is_force_scale_factor_; + double scale_factor_; }; #endif // FLUTTER_EMBEDDER_OPTIONS_ diff --git a/examples/flutter-video-player-plugin/main.cc b/examples/flutter-video-player-plugin/main.cc index fa4e11b8..fbc049d6 100644 --- a/examples/flutter-video-player-plugin/main.cc +++ b/examples/flutter-video-player-plugin/main.cc @@ -33,6 +33,8 @@ int main(int argc, char** argv) { view_properties.use_mouse_cursor = options.IsUseMouseCursor(); view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); view_properties.use_window_decoration = options.IsUseWindowDecoraation(); + view_properties.force_scale_factor = options.IsForceScaleFactor(); + view_properties.scale_factor = options.ScaleFactor(); // The Flutter instance hosted by this window. FlutterWindow window(view_properties, project); diff --git a/examples/flutter-wayland-client/command_options.h b/examples/flutter-wayland-client/command_options.h index 107a152d..ad49e840 100644 --- a/examples/flutter-wayland-client/command_options.h +++ b/examples/flutter-wayland-client/command_options.h @@ -56,6 +56,15 @@ class CommandOptions { ReaderInt(), required, true); } + void AddDouble(const std::string& name, + const std::string& short_name, + const std::string& description, + const double& default_value, + bool required) { + Add(name, short_name, description, default_value, + ReaderDouble(), required, true); + } + void AddString(const std::string& name, const std::string& short_name, const std::string& description, @@ -250,6 +259,10 @@ class CommandOptions { std::string operator()(const std::string& value) { return value; } }; + struct ReaderDouble { + double operator()(const std::string& value) { return std::stod(value); } + }; + class Option { public: Option(const std::string& name, diff --git a/examples/flutter-wayland-client/flutter_embedder_options.h b/examples/flutter-wayland-client/flutter_embedder_options.h index 4c229135..cc8193fc 100644 --- a/examples/flutter-wayland-client/flutter_embedder_options.h +++ b/examples/flutter-wayland-client/flutter_embedder_options.h @@ -21,6 +21,9 @@ class FlutterEmbedderOptions { options_.AddInt("rotation", "r", "Window rotation(degree) [0(default)|90|180|270]", 0, false); + options_.AddDouble("force-scale-factor", "s", + "Force a scale factor instead using default value", 1.0, + false); #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) // no more options. @@ -72,6 +75,14 @@ class FlutterEmbedderOptions { } } + if (options_.Exist("force-scale-factor")) { + is_force_scale_factor_ = true; + scale_factor_ = options_.GetValue("force-scale-factor"); + } else { + is_force_scale_factor_ = false; + scale_factor_ = 1.0; + } + #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) use_onscreen_keyboard_ = false; @@ -112,6 +123,8 @@ class FlutterEmbedderOptions { flutter::FlutterViewController::ViewRotation WindowRotation() const { return window_view_rotation_; } + bool IsForceScaleFactor() const { return is_force_scale_factor_; } + double ScaleFactor() const { return scale_factor_; } private: commandline::CommandOptions options_; @@ -126,6 +139,8 @@ class FlutterEmbedderOptions { int window_height_ = 720; flutter::FlutterViewController::ViewRotation window_view_rotation_ = flutter::FlutterViewController::ViewRotation::kRotation_0; + bool is_force_scale_factor_; + double scale_factor_; }; #endif // FLUTTER_EMBEDDER_OPTIONS_ diff --git a/examples/flutter-wayland-client/main.cc b/examples/flutter-wayland-client/main.cc index fa4e11b8..fbc049d6 100644 --- a/examples/flutter-wayland-client/main.cc +++ b/examples/flutter-wayland-client/main.cc @@ -33,6 +33,8 @@ int main(int argc, char** argv) { view_properties.use_mouse_cursor = options.IsUseMouseCursor(); view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); view_properties.use_window_decoration = options.IsUseWindowDecoraation(); + view_properties.force_scale_factor = options.IsForceScaleFactor(); + view_properties.scale_factor = options.ScaleFactor(); // The Flutter instance hosted by this window. FlutterWindow window(view_properties, project); diff --git a/examples/flutter-x11-client/command_options.h b/examples/flutter-x11-client/command_options.h index 107a152d..ad49e840 100644 --- a/examples/flutter-x11-client/command_options.h +++ b/examples/flutter-x11-client/command_options.h @@ -56,6 +56,15 @@ class CommandOptions { ReaderInt(), required, true); } + void AddDouble(const std::string& name, + const std::string& short_name, + const std::string& description, + const double& default_value, + bool required) { + Add(name, short_name, description, default_value, + ReaderDouble(), required, true); + } + void AddString(const std::string& name, const std::string& short_name, const std::string& description, @@ -250,6 +259,10 @@ class CommandOptions { std::string operator()(const std::string& value) { return value; } }; + struct ReaderDouble { + double operator()(const std::string& value) { return std::stod(value); } + }; + class Option { public: Option(const std::string& name, diff --git a/examples/flutter-x11-client/flutter_embedder_options.h b/examples/flutter-x11-client/flutter_embedder_options.h index 4c229135..cc8193fc 100644 --- a/examples/flutter-x11-client/flutter_embedder_options.h +++ b/examples/flutter-x11-client/flutter_embedder_options.h @@ -21,6 +21,9 @@ class FlutterEmbedderOptions { options_.AddInt("rotation", "r", "Window rotation(degree) [0(default)|90|180|270]", 0, false); + options_.AddDouble("force-scale-factor", "s", + "Force a scale factor instead using default value", 1.0, + false); #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) // no more options. @@ -72,6 +75,14 @@ class FlutterEmbedderOptions { } } + if (options_.Exist("force-scale-factor")) { + is_force_scale_factor_ = true; + scale_factor_ = options_.GetValue("force-scale-factor"); + } else { + is_force_scale_factor_ = false; + scale_factor_ = 1.0; + } + #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) use_onscreen_keyboard_ = false; @@ -112,6 +123,8 @@ class FlutterEmbedderOptions { flutter::FlutterViewController::ViewRotation WindowRotation() const { return window_view_rotation_; } + bool IsForceScaleFactor() const { return is_force_scale_factor_; } + double ScaleFactor() const { return scale_factor_; } private: commandline::CommandOptions options_; @@ -126,6 +139,8 @@ class FlutterEmbedderOptions { int window_height_ = 720; flutter::FlutterViewController::ViewRotation window_view_rotation_ = flutter::FlutterViewController::ViewRotation::kRotation_0; + bool is_force_scale_factor_; + double scale_factor_; }; #endif // FLUTTER_EMBEDDER_OPTIONS_ diff --git a/examples/flutter-x11-client/main.cc b/examples/flutter-x11-client/main.cc index fa4e11b8..fbc049d6 100644 --- a/examples/flutter-x11-client/main.cc +++ b/examples/flutter-x11-client/main.cc @@ -33,6 +33,8 @@ int main(int argc, char** argv) { view_properties.use_mouse_cursor = options.IsUseMouseCursor(); view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); view_properties.use_window_decoration = options.IsUseWindowDecoraation(); + view_properties.force_scale_factor = options.IsForceScaleFactor(); + view_properties.scale_factor = options.ScaleFactor(); // The Flutter instance hosted by this window. FlutterWindow window(view_properties, project); diff --git a/src/client_wrapper/flutter_view_controller.cc b/src/client_wrapper/flutter_view_controller.cc index 4dbd58a4..28996256 100644 --- a/src/client_wrapper/flutter_view_controller.cc +++ b/src/client_wrapper/flutter_view_controller.cc @@ -34,6 +34,8 @@ FlutterViewController::FlutterViewController( view_properties.use_onscreen_keyboard; c_view_properties.use_window_decoration = view_properties.use_window_decoration; + c_view_properties.force_scale_factor = view_properties.force_scale_factor; + c_view_properties.scale_factor = view_properties.scale_factor; controller_ = FlutterDesktopViewControllerCreate(c_view_properties, engine_->RelinquishEngine()); diff --git a/src/client_wrapper/include/flutter/flutter_view_controller.h b/src/client_wrapper/include/flutter/flutter_view_controller.h index a5762e47..b27506ea 100644 --- a/src/client_wrapper/include/flutter/flutter_view_controller.h +++ b/src/client_wrapper/include/flutter/flutter_view_controller.h @@ -67,6 +67,10 @@ class FlutterViewController { // Uses the window decoration such as toolbar and max/min buttons. // This option is only active for Wayland backend. bool use_window_decoration; + + // Force scale factor specified by command line argument + bool force_scale_factor; + double scale_factor; } ViewProperties; // Creates a FlutterView that can be parented into a Windows View hierarchy diff --git a/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h b/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h index 913c1fac..a8b0b5d8 100644 --- a/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h +++ b/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h @@ -98,6 +98,10 @@ typedef struct { // Uses the window decoration such as toolbar and max/min buttons. // This option is only active for Wayland backend. bool use_window_decoration; + + // Force scale factor specified by command line argument + bool force_scale_factor; + double scale_factor; } FlutterDesktopViewProperties; // ========== View Controller ========== diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h b/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h index 55e29854..0c6f9ea8 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h @@ -34,6 +34,8 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { ELinuxWindowDrm(FlutterDesktopViewProperties view_properties) : display_valid_(false), is_pending_cursor_add_event_(false) { view_properties_ = view_properties; + current_scale_ = + view_properties.force_scale_factor ? view_properties.scale_factor : 1.0; SetRotation(view_properties_.view_rotation); auto udev = udev_new(); diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc index 31c9fac3..282128ca 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc @@ -565,7 +565,8 @@ const wl_output_listener ELinuxWindowWayland::kWlOutputListener = { .scale = [](void* data, wl_output* wl_output, int32_t scale) -> void { auto self = reinterpret_cast(data); ELINUX_LOG(INFO) << "Display output scale: " << scale; - self->current_scale_ = scale; + if (!self->view_properties_.force_scale_factor) + self->current_scale_ = scale; }, }; @@ -829,6 +830,8 @@ ELinuxWindowWayland::ELinuxWindowWayland( frame_rate_(60000), window_decorations_(nullptr) { view_properties_ = view_properties; + current_scale_ = + view_properties.force_scale_factor ? view_properties.scale_factor : 1.0; SetRotation(view_properties_.view_rotation); wl_display_ = wl_display_connect(nullptr); diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.cc index 792fa76a..03a52c87 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.cc @@ -23,6 +23,8 @@ constexpr int kButton9 = 9; ELinuxWindowX11::ELinuxWindowX11(FlutterDesktopViewProperties view_properties) { view_properties_ = view_properties; + current_scale_ = + view_properties.force_scale_factor ? view_properties.scale_factor : 1.0; SetRotation(view_properties_.view_rotation); display_ = XOpenDisplay(NULL); From 6df84828d87bf684785d016e83c1bdff10d928c3 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Sat, 20 Aug 2022 16:19:26 +0900 Subject: [PATCH 021/112] Remove unnecessary comments (#285) Signed-off-by: Hidenori Matsubayashi --- examples/flutter-drm-eglstream-backend/command_options.h | 4 +--- examples/flutter-drm-gbm-backend/command_options.h | 4 +--- examples/flutter-external-texture-plugin/command_options.h | 4 +--- examples/flutter-video-player-plugin/command_options.h | 4 +--- examples/flutter-wayland-client/command_options.h | 4 +--- examples/flutter-x11-client/command_options.h | 4 +--- 6 files changed, 6 insertions(+), 18 deletions(-) diff --git a/examples/flutter-drm-eglstream-backend/command_options.h b/examples/flutter-drm-eglstream-backend/command_options.h index ad49e840..b0de9316 100644 --- a/examples/flutter-drm-eglstream-backend/command_options.h +++ b/examples/flutter-drm-eglstream-backend/command_options.h @@ -1,4 +1,4 @@ -// Copyright 2021 Sony Corporation. All rights reserved. +// Copyright 2022 Sony Corporation. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -13,8 +13,6 @@ #include #include -// todo: Supports other types besides int, string. - namespace commandline { namespace { diff --git a/examples/flutter-drm-gbm-backend/command_options.h b/examples/flutter-drm-gbm-backend/command_options.h index ad49e840..b0de9316 100644 --- a/examples/flutter-drm-gbm-backend/command_options.h +++ b/examples/flutter-drm-gbm-backend/command_options.h @@ -1,4 +1,4 @@ -// Copyright 2021 Sony Corporation. All rights reserved. +// Copyright 2022 Sony Corporation. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -13,8 +13,6 @@ #include #include -// todo: Supports other types besides int, string. - namespace commandline { namespace { diff --git a/examples/flutter-external-texture-plugin/command_options.h b/examples/flutter-external-texture-plugin/command_options.h index ad49e840..b0de9316 100644 --- a/examples/flutter-external-texture-plugin/command_options.h +++ b/examples/flutter-external-texture-plugin/command_options.h @@ -1,4 +1,4 @@ -// Copyright 2021 Sony Corporation. All rights reserved. +// Copyright 2022 Sony Corporation. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -13,8 +13,6 @@ #include #include -// todo: Supports other types besides int, string. - namespace commandline { namespace { diff --git a/examples/flutter-video-player-plugin/command_options.h b/examples/flutter-video-player-plugin/command_options.h index ad49e840..b0de9316 100644 --- a/examples/flutter-video-player-plugin/command_options.h +++ b/examples/flutter-video-player-plugin/command_options.h @@ -1,4 +1,4 @@ -// Copyright 2021 Sony Corporation. All rights reserved. +// Copyright 2022 Sony Corporation. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -13,8 +13,6 @@ #include #include -// todo: Supports other types besides int, string. - namespace commandline { namespace { diff --git a/examples/flutter-wayland-client/command_options.h b/examples/flutter-wayland-client/command_options.h index ad49e840..b0de9316 100644 --- a/examples/flutter-wayland-client/command_options.h +++ b/examples/flutter-wayland-client/command_options.h @@ -1,4 +1,4 @@ -// Copyright 2021 Sony Corporation. All rights reserved. +// Copyright 2022 Sony Corporation. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -13,8 +13,6 @@ #include #include -// todo: Supports other types besides int, string. - namespace commandline { namespace { diff --git a/examples/flutter-x11-client/command_options.h b/examples/flutter-x11-client/command_options.h index ad49e840..b0de9316 100644 --- a/examples/flutter-x11-client/command_options.h +++ b/examples/flutter-x11-client/command_options.h @@ -1,4 +1,4 @@ -// Copyright 2021 Sony Corporation. All rights reserved. +// Copyright 2022 Sony Corporation. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -13,8 +13,6 @@ #include #include -// todo: Supports other types besides int, string. - namespace commandline { namespace { From c01f99b8f43968d02633ec9e630e2ff6749939ba Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Sun, 21 Aug 2022 08:48:34 +0900 Subject: [PATCH 022/112] Add vsync cmake option (default: disabled) (#286) Signed-off-by: Hidenori Matsubayashi --- CMakeLists.txt | 1 + cmake/build.cmake | 7 +++++++ .../shell/platform/linux_embedded/flutter_elinux_engine.cc | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7cfedf0c..f8384def 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,7 @@ project("flutter_elinux" LANGUAGES CXX C) option(BACKEND_TYPE "Select WAYLAND, DRM-GBM, DRM-EGLSTREAM, or X11 as the display backend type" WAYLAND) option(USE_GLES3 "Use OpenGL ES3 (default is OpenGL ES2)" OFF) option(ENABLE_EGL_ALPHA_COMPONENT_OF_COLOR_BUFFER "Enable alpha component of the EGL color buffer" ON) +option(ENABLE_VSYNC "Enable embedder vsync" OFF) option(BUILD_ELINUX_SO "Build .so file of elinux embedder" OFF) option(ENABLE_ELINUX_EMBEDDER_LOG "Enable logger of eLinux embedder" ON) option(FLUTTER_RELEASE "Build Flutter Engine with release mode" OFF) diff --git a/cmake/build.cmake b/cmake/build.cmake index c1ae62e4..ae4feb48 100644 --- a/cmake/build.cmake +++ b/cmake/build.cmake @@ -99,6 +99,13 @@ if(ENABLE_ELINUX_EMBEDDER_LOG) ) endif() +# Enable embedder vsync. +if(ENABLE_VSYNC) + add_definitions( + -DENABLE_VSYNC + ) +endif() + # Enable alpha component of the egl color buffer. if(ENABLE_EGL_ALPHA_COMPONENT_OF_COLOR_BUFFER) add_definitions( diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc index 38e6a028..df2c6f8d 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc @@ -219,7 +219,7 @@ bool FlutterELinuxEngine::RunWithEntrypoint(const char* entrypoint) { // todo: disable vsync temporarily because flutter apps will freeze when we use // this interface. See also: // https://github.com/sony/flutter-embedded-linux/issues/176 -#if 0 +#if defined(ENABLE_VSYNC) // todo: add drm/x11 support. // https://github.com/sony/flutter-embedded-linux/issues/136 // https://github.com/sony/flutter-embedded-linux/issues/137 From 9a1c5e1af740e48763797a6b4718286e6a0a2c2a Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Sat, 17 Sep 2022 09:38:33 +0900 Subject: [PATCH 023/112] Update README (#291) Signed-off-by: Hidenori Matsubayashi --- README.md | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 95d6543e..85ee9334 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,16 @@ [![build-test](https://github.com/sony/flutter-embedded-linux/actions/workflows/build-test.yml/badge.svg)](https://github.com/sony/flutter-embedded-linux/actions/workflows/build-test.yml) -This project was created to develop **non-official** embedded Linux embeddings of [Flutter](https://flutter.dev/). This embedder is focusing on embedded Linux system use cases. It is also implemented based on Flutter desktop for Windows and has some unique features to use it in embedded systems. +This project was created to develop **non-official** embedded Linux embeddings of [Flutter](https://flutter.dev/). This embedder is focusing on embedded Linux (eLinux) system use cases. It is also implemented based on Flutter desktop for Windows and has some unique features to use it in embedded systems. -### flutter-elinux -Note that this project is the source code of the embedder. If you develop your flutter app for eLinux, use [flutter-elinux](https://github.com/sony/flutter-elinux), which is a non-official extension to the [Flutter SDK](https://github.com/flutter/flutter) to build and debug Flutter apps for embedded Linux devices. +If you develop flutter apps for eLinux, use [flutter-elinux](https://github.com/sony/flutter-elinux), which is a non-official extension to the [Flutter SDK](https://github.com/flutter/flutter) to build and debug Flutter apps for embedded Linux devices. + +### Repositories + +- [flutter-elinux](https://github.com/sony/flutter-elinux): Flutter tools for eLinux +- [flutter-elinux-plugins](https://github.com/sony/flutter-elinux-plugins): Flutter plugins for eLinux +- [flutter-embedded-linux](https://github.com/sony/flutter-embedded-linux): eLinux embedding for Flutter +- [meta-flutter](https://github.com/sony/meta-flutter): Yocto recipes of eLinux embedding for Flutter ## Objective & Goal Our objective is to use Flutter in embedded systems. We're developing this embedder to use Flutter in embedded products. Ultimately we would like to propose and contribute this software to the mainline of [Flutter Engine](https://github.com/flutter/engine), which means we would like to add an embedded systems version into the Flutter repo for all embedded developers. Please note that this is just our ideal, not the official opinion of the Flutter community. @@ -30,13 +36,6 @@ We would be grateful if you could give us feedback on bugs and new feature reque - API compatibility with Flutter desktop for Windows and GLFW - APIs such as MethodChannel and EventChannel are completely the same with them -## Companion repos -| Repo | Purpose | -| ------------- | ------------- | -| [flutter-elinux](https://github.com/sony/flutter-elinux) | Flutter tools for eLinux | -| [flutter-elinux-plugins](https://github.com/sony/flutter-elinux-plugins) | Flutter plugins for eLinux | -| [meta-flutter](https://github.com/sony/meta-flutter) | Yocto recipes of eLinux embedding for Flutter | - ## Documentation Documentation for this software can be found at [Wiki](https://github.com/sony/flutter-embedded-linux/wiki). From 48a047cf977850b19075ece95f4d8f6079bd389a Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Mon, 24 Oct 2022 22:51:16 +0900 Subject: [PATCH 024/112] drm: add multiple dri cards support using FLUTTER_DRM_DEVIE env (#295) Fixed https://github.com/sony/flutter-elinux/issues/143 Signed-off-by: Hidenori Matsubayashi --- .../linux_embedded/window/elinux_window_drm.h | 54 +++++++++++++++---- 1 file changed, 44 insertions(+), 10 deletions(-) diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h b/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h index 0c6f9ea8..e9e5edcc 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h @@ -13,7 +13,9 @@ #include #include +#include #include +#include #include "flutter/shell/platform/linux_embedded/logger.h" #include "flutter/shell/platform/linux_embedded/surface/surface_gl.h" @@ -108,23 +110,42 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { // |FlutterWindowBindingHandler| bool CreateRenderSurface(int32_t width, int32_t height) override { + std::vector devices; auto device_filename = std::getenv(kFlutterDrmDeviceEnvironmentKey); - if ((!device_filename) || (device_filename[0] == '\0')) { + if (device_filename && device_filename[0] != '\0') { + devices = split(std::string(device_filename), ':'); + } + if (devices.empty()) { ELINUX_LOG(WARNING) << kFlutterDrmDeviceEnvironmentKey << " is not set, use " << kDrmDeviceDefaultFilename; - device_filename = const_cast(kDrmDeviceDefaultFilename); - } + devices.push_back(const_cast(kDrmDeviceDefaultFilename)); + } + + bool device_found = false; + for (auto i = 0; i < devices.size(); i++) { + native_window_ = + std::make_unique(devices[i].c_str(), current_rotation_); + if (!native_window_->IsValid()) { + ELINUX_LOG(ERROR) << "Failed to create the native window (" + << devices[i] << ")."; + native_window_ = nullptr; + continue; + } - native_window_ = std::make_unique(device_filename, current_rotation_); - if (!native_window_->IsValid()) { - ELINUX_LOG(ERROR) << "Failed to create the native window"; - return false; - } + if (!RegisterUdevDrmEventLoop(devices[i].c_str())) { + ELINUX_LOG(ERROR) << "Failed to register udev drm event loop (" + << devices[i] << ")."; + native_window_ = nullptr; + continue; + } - if (!RegisterUdevDrmEventLoop(device_filename)) { - ELINUX_LOG(ERROR) << "Failed to register udev drm event loop."; + device_found = true; + ELINUX_LOG(INFO) << devices[i] << " was selected as the DRM device."; + } + if (!device_found) { return false; } + display_valid_ = true; render_surface_ = native_window_->CreateRenderSurface(); @@ -667,6 +688,19 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { kScrollOffsetMultiplier); } + std::vector split(std::string s, char delim) { + std::vector res; + std::string item; + std::stringstream ss(s); + + while (getline(ss, item, delim)) { + if (!item.empty()) { + res.push_back(item); + } + } + return res; + } + struct LibinputDeviceData { size_t id; bool is_pointer_device; From 2bbd057d907dbf7a09e211b6976d1ecd725243f6 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Thu, 3 Nov 2022 13:00:21 +0900 Subject: [PATCH 025/112] Merge common source file from flutter/engine (#296) Signed-off-by: Hidenori Matsubayashi --- .../include/flutter/event_channel.h | 132 ++++++++++-------- 1 file changed, 70 insertions(+), 62 deletions(-) diff --git a/src/flutter/shell/platform/common/client_wrapper/include/flutter/event_channel.h b/src/flutter/shell/platform/common/client_wrapper/include/flutter/event_channel.h index fe0e1414..08c242a2 100644 --- a/src/flutter/shell/platform/common/client_wrapper/include/flutter/event_channel.h +++ b/src/flutter/shell/platform/common/client_wrapper/include/flutter/event_channel.h @@ -47,10 +47,13 @@ class EventChannel { // Registers a stream handler on this channel. // If no handler has been registered, any incoming stream setup requests will // be handled silently by providing an empty stream. + // + // Note that the EventChannel does not own the handler and will not + // unregister it on destruction. The caller is responsible for unregistering + // the handler if it should no longer be called. void SetStreamHandler(std::unique_ptr> handler) { if (!handler) { messenger_->SetMessageHandler(name_, nullptr); - is_listening_ = false; return; } @@ -61,69 +64,75 @@ class EventChannel { const MethodCodec* codec = codec_; const std::string channel_name = name_; const BinaryMessenger* messenger = messenger_; - BinaryMessageHandler binary_handler = [shared_handler, codec, channel_name, - messenger, - this](const uint8_t* message, - const size_t message_size, - BinaryReply reply) { - constexpr char kOnListenMethod[] = "listen"; - constexpr char kOnCancelMethod[] = "cancel"; - - std::unique_ptr> method_call = - codec->DecodeMethodCall(message, message_size); - if (!method_call) { - std::cerr << "Unable to construct method call from message on channel: " - << channel_name << std::endl; - reply(nullptr, 0); - return; - } - - const std::string& method = method_call->method_name(); - if (method.compare(kOnListenMethod) == 0) { - if (is_listening_) { - std::unique_ptr> error = - shared_handler->OnCancel(nullptr); - if (error) { - std::cerr << "Failed to cancel existing stream: " - << (error->error_code) << ", " << (error->error_message) - << ", " << (error->error_details); + BinaryMessageHandler binary_handler = + [shared_handler, codec, channel_name, messenger, + // Mutable state to track the handler's listening status. + is_listening = bool(false)](const uint8_t* message, + const size_t message_size, + BinaryReply reply) mutable { + constexpr char kOnListenMethod[] = "listen"; + constexpr char kOnCancelMethod[] = "cancel"; + + std::unique_ptr> method_call = + codec->DecodeMethodCall(message, message_size); + if (!method_call) { + std::cerr + << "Unable to construct method call from message on channel: " + << channel_name << std::endl; + reply(nullptr, 0); + return; } - } - is_listening_ = true; - - std::unique_ptr> result; - auto sink = std::make_unique( - messenger, channel_name, codec); - std::unique_ptr> error = - shared_handler->OnListen(method_call->arguments(), std::move(sink)); - if (error) { - result = codec->EncodeErrorEnvelope( - error->error_code, error->error_message, error->error_details); - } else { - result = codec->EncodeSuccessEnvelope(); - } - reply(result->data(), result->size()); - } else if (method.compare(kOnCancelMethod) == 0) { - std::unique_ptr> result; - if (is_listening_) { - std::unique_ptr> error = - shared_handler->OnCancel(method_call->arguments()); - if (error) { - result = codec->EncodeErrorEnvelope( - error->error_code, error->error_message, error->error_details); + + const std::string& method = method_call->method_name(); + if (method.compare(kOnListenMethod) == 0) { + if (is_listening) { + std::unique_ptr> error = + shared_handler->OnCancel(nullptr); + if (error) { + std::cerr << "Failed to cancel existing stream: " + << (error->error_code) << ", " + << (error->error_message) << ", " + << (error->error_details); + } + } + is_listening = true; + + std::unique_ptr> result; + auto sink = std::make_unique( + messenger, channel_name, codec); + std::unique_ptr> error = + shared_handler->OnListen(method_call->arguments(), + std::move(sink)); + if (error) { + result = codec->EncodeErrorEnvelope(error->error_code, + error->error_message, + error->error_details); + } else { + result = codec->EncodeSuccessEnvelope(); + } + reply(result->data(), result->size()); + } else if (method.compare(kOnCancelMethod) == 0) { + std::unique_ptr> result; + if (is_listening) { + std::unique_ptr> error = + shared_handler->OnCancel(method_call->arguments()); + if (error) { + result = codec->EncodeErrorEnvelope(error->error_code, + error->error_message, + error->error_details); + } else { + result = codec->EncodeSuccessEnvelope(); + } + is_listening = false; + } else { + result = codec->EncodeErrorEnvelope( + "error", "No active stream to cancel", nullptr); + } + reply(result->data(), result->size()); } else { - result = codec->EncodeSuccessEnvelope(); + reply(nullptr, 0); } - is_listening_ = false; - } else { - result = codec->EncodeErrorEnvelope( - "error", "No active stream to cancel", nullptr); - } - reply(result->data(), result->size()); - } else { - reply(nullptr, 0); - } - }; + }; messenger_->SetMessageHandler(name_, std::move(binary_handler)); } @@ -165,7 +174,6 @@ class EventChannel { BinaryMessenger* messenger_; const std::string name_; const MethodCodec* codec_; - bool is_listening_ = false; }; } // namespace flutter From 913c6ed58fa24fda4b9fd9957fe322f9ff4c756e Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Sat, 12 Nov 2022 11:23:48 +0900 Subject: [PATCH 026/112] Merge embedder.h from flutter/engine (#299) From https://github.com/flutter/engine/commit/3d9f48580a5cdcc84c64c711980bdc9ef43429d1 Signed-off-by: Hidenori Matsubayashi --- .../shell/platform/embedder/embedder.h | 148 ++++++++++++++++-- 1 file changed, 134 insertions(+), 14 deletions(-) diff --git a/src/flutter/shell/platform/embedder/embedder.h b/src/flutter/shell/platform/embedder/embedder.h index 43fd5bd5..7bef2e52 100644 --- a/src/flutter/shell/platform/embedder/embedder.h +++ b/src/flutter/shell/platform/embedder/embedder.h @@ -227,6 +227,8 @@ typedef enum { kFlutterSemanticsFlagIsSlider = 1 << 23, /// Whether the semantics node represents a keyboard key. kFlutterSemanticsFlagIsKeyboardKey = 1 << 24, + /// Whether the semantics node represents a tristate checkbox in mixed state. + kFlutterSemanticsFlagIsCheckStateMixed = 1 << 25, } FlutterSemanticsFlag; typedef enum { @@ -433,6 +435,16 @@ typedef struct { FlutterSize lower_left_corner_radius; } FlutterRoundedRect; +/// A structure to represent a damage region. +typedef struct { + /// The size of this struct. Must be sizeof(FlutterDamage). + size_t struct_size; + /// The number of rectangles within the damage region. + size_t num_rects; + /// The actual damage region(s) in question. + FlutterRect* damage; +} FlutterDamage; + /// This information is passed to the embedder when requesting a frame buffer /// object. /// @@ -449,6 +461,13 @@ typedef uint32_t (*UIntFrameInfoCallback)( void* /* user data */, const FlutterFrameInfo* /* frame info */); +/// Callback for when a frame buffer object is requested with necessary +/// information for partial repaint. +typedef void (*FlutterFrameBufferWithDamageCallback)( + void* /* user data */, + const intptr_t /* fbo id */, + FlutterDamage* /* existing damage */); + /// This information is passed to the embedder when a surface is presented. /// /// See: \ref FlutterOpenGLRendererConfig.present_with_info. @@ -457,6 +476,10 @@ typedef struct { size_t struct_size; /// Id of the fbo backing the surface that was presented. uint32_t fbo_id; + /// Damage representing the area that the compositor needs to render. + FlutterDamage frame_damage; + /// Damage used to set the buffer's damage region. + FlutterDamage buffer_damage; } FlutterPresentInfo; /// Callback for when a surface is presented. @@ -471,7 +494,10 @@ typedef struct { BoolCallback clear_current; /// Specifying one (and only one) of `present` or `present_with_info` is /// required. Specifying both is an error and engine initialization will be - /// terminated. The return value indicates success of the present call. + /// terminated. The return value indicates success of the present call. If + /// the intent is to use dirty region management, present_with_info must be + /// defined as present will not succeed in communicating information about + /// damage. BoolCallback present; /// Specifying one (and only one) of the `fbo_callback` or /// `fbo_with_frame_info_callback` is required. Specifying both is an error @@ -520,8 +546,27 @@ typedef struct { /// required. Specifying both is an error and engine initialization will be /// terminated. When using this variant, the embedder is passed a /// `FlutterPresentInfo` struct that the embedder can use to release any - /// resources. The return value indicates success of the present call. + /// resources. The return value indicates success of the present call. This + /// callback is essential for dirty region management. If not defined, all the + /// pixels on the screen will be rendered at every frame (regardless of + /// whether damage is actually being computed or not). This is because the + /// information that is passed along to the callback contains the frame and + /// buffer damage that are essential for dirty region management. BoolPresentInfoCallback present_with_info; + /// Specifying this callback is a requirement for dirty region management. + /// Dirty region management will only render the areas of the screen that have + /// changed in between frames, greatly reducing rendering times and energy + /// consumption. To take advantage of these benefits, it is necessary to + /// define populate_existing_damage as a callback that takes user + /// data, an FBO ID, and an existing damage FlutterDamage. The callback should + /// use the given FBO ID to identify the FBO's exisiting damage (i.e. areas + /// that have changed since the FBO was last used) and use it to populate the + /// given existing damage variable. This callback is dependent on either + /// fbo_callback or fbo_with_frame_info_callback being defined as they are + /// responsible for providing populate_existing_damage with the FBO's + /// ID. Not specifying populate_existing_damage will result in full + /// repaint (i.e. rendering all the pixels on the screen at every frame). + FlutterFrameBufferWithDamageCallback populate_existing_damage; } FlutterOpenGLRendererConfig; /// Alias for id. @@ -539,6 +584,12 @@ typedef enum { kRGBA, } FlutterMetalExternalTexturePixelFormat; +/// YUV color space for the YUV external texture. +typedef enum { + kBT601FullRange, + kBT601LimitedRange, +} FlutterMetalExternalTextureYUVColorSpace; + typedef struct { /// The size of this struct. Must be sizeof(FlutterMetalExternalTexture). size_t struct_size; @@ -559,6 +610,8 @@ typedef struct { /// `FlutterEngineUnregisterExternalTexture`, the embedder has to release /// these textures. FlutterMetalTextureHandle* textures; + /// The YUV color space of the YUV external texture. + FlutterMetalExternalTextureYUVColorSpace yuv_color_space; } FlutterMetalExternalTexture; /// Callback to provide an external texture for a given texture_id. @@ -830,6 +883,7 @@ typedef enum { kFlutterPointerSignalKindNone, kFlutterPointerSignalKindScroll, kFlutterPointerSignalKindScrollInertiaCancel, + kFlutterPointerSignalKindScale, } FlutterPointerSignalKind; typedef struct { @@ -977,7 +1031,8 @@ typedef void (*FlutterDataCallback)(const uint8_t* /* data */, typedef int64_t FlutterPlatformViewIdentifier; /// `FlutterSemanticsNode` ID used as a sentinel to signal the end of a batch of -/// semantics node updates. +/// semantics node updates. This is unused if using +/// `FlutterUpdateSemanticsCallback`. FLUTTER_EXPORT extern const int32_t kFlutterSemanticsNodeIdBatchEnd; @@ -986,7 +1041,7 @@ extern const int32_t kFlutterSemanticsNodeIdBatchEnd; /// The semantics tree is maintained during the semantics phase of the pipeline /// (i.e., during PipelineOwner.flushSemantics), which happens after /// compositing. Updates are then pushed to embedders via the registered -/// `FlutterUpdateSemanticsNodeCallback`. +/// `FlutterUpdateSemanticsCallback`. typedef struct { /// The size of this struct. Must be sizeof(FlutterSemanticsNode). size_t struct_size; @@ -1028,8 +1083,8 @@ typedef struct { /// A value that `value` will have after a kFlutterSemanticsActionDecrease` /// action has been performed. const char* decreased_value; - /// The reading direction for `label`, `value`, `hint`, `increasedValue`, and - /// `decreasedValue`. + /// The reading direction for `label`, `value`, `hint`, `increasedValue`, + /// `decreasedValue`, and `tooltip`. FlutterTextDirection text_direction; /// The bounding box for this node in its coordinate system. FlutterRect rect; @@ -1050,10 +1105,13 @@ typedef struct { /// Identifier of the platform view associated with this semantics node, or /// -1 if none. FlutterPlatformViewIdentifier platform_view_id; + /// A textual tooltip attached to the node. + const char* tooltip; } FlutterSemanticsNode; /// `FlutterSemanticsCustomAction` ID used as a sentinel to signal the end of a -/// batch of semantics custom action updates. +/// batch of semantics custom action updates. This is unused if using +/// `FlutterUpdateSemanticsCallback`. FLUTTER_EXPORT extern const int32_t kFlutterSemanticsCustomActionIdBatchEnd; @@ -1080,6 +1138,20 @@ typedef struct { const char* hint; } FlutterSemanticsCustomAction; +/// A batch of updates to semantics nodes and custom actions. +typedef struct { + /// The size of the struct. Must be sizeof(FlutterSemanticsUpdate). + size_t struct_size; + /// The number of semantics node updates. + size_t nodes_count; + // Array of semantics nodes. Has length `nodes_count`. + FlutterSemanticsNode* nodes; + /// The number of semantics custom action updates. + size_t custom_actions_count; + /// Array of semantics custom actions. Has length `custom_actions_count`. + FlutterSemanticsCustomAction* custom_actions; +} FlutterSemanticsUpdate; + typedef void (*FlutterUpdateSemanticsNodeCallback)( const FlutterSemanticsNode* /* semantics node */, void* /* user data */); @@ -1088,6 +1160,10 @@ typedef void (*FlutterUpdateSemanticsCustomActionCallback)( const FlutterSemanticsCustomAction* /* semantics custom action */, void* /* user data */); +typedef void (*FlutterUpdateSemanticsCallback)( + const FlutterSemanticsUpdate* /* semantics update */, + void* /* user data*/); + typedef struct _FlutterTaskRunner* FlutterTaskRunner; typedef struct { @@ -1683,24 +1759,32 @@ typedef struct { /// The callback invoked by the engine in root isolate scope. Called /// immediately after the root isolate has been created and marked runnable. VoidCallback root_isolate_create_callback; - /// The callback invoked by the engine in order to give the embedder the - /// chance to respond to semantics node updates from the Dart application. + /// The legacy callback invoked by the engine in order to give the embedder + /// the chance to respond to semantics node updates from the Dart application. /// Semantics node updates are sent in batches terminated by a 'batch end' /// callback that is passed a sentinel `FlutterSemanticsNode` whose `id` field /// has the value `kFlutterSemanticsNodeIdBatchEnd`. /// /// The callback will be invoked on the thread on which the `FlutterEngineRun` /// call is made. + /// + /// @deprecated Prefer using `update_semantics_callback` instead. If this + /// calback is provided, `update_semantics_callback` must not + /// be provided. FlutterUpdateSemanticsNodeCallback update_semantics_node_callback; - /// The callback invoked by the engine in order to give the embedder the - /// chance to respond to updates to semantics custom actions from the Dart - /// application. Custom action updates are sent in batches terminated by a + /// The legacy callback invoked by the engine in order to give the embedder + /// the chance to respond to updates to semantics custom actions from the Dart + /// application. Custom action updates are sent in batches terminated by a /// 'batch end' callback that is passed a sentinel /// `FlutterSemanticsCustomAction` whose `id` field has the value /// `kFlutterSemanticsCustomActionIdBatchEnd`. /// /// The callback will be invoked on the thread on which the `FlutterEngineRun` /// call is made. + /// + /// @deprecated Prefer using `update_semantics_callback` instead. If this + /// calback is provided, `update_semantics_callback` must not + /// be provided. FlutterUpdateSemanticsCustomActionCallback update_semantics_custom_action_callback; /// Path to a directory used to store data that is cached across runs of a @@ -1837,6 +1921,17 @@ typedef struct { // // The first argument is the `user_data` from `FlutterEngineInitialize`. OnPreEngineRestartCallback on_pre_engine_restart_callback; + + /// The callback invoked by the engine in order to give the embedder the + /// chance to respond to updates to semantics nodes and custom actions from + /// the Dart application. + /// + /// The callback will be invoked on the thread on which the `FlutterEngineRun` + /// call is made. + /// + /// If this callback is provided, update_semantics_node_callback and + /// update_semantics_custom_action_callback must not be provided. + FlutterUpdateSemanticsCallback update_semantics_callback; } FlutterProjectArgs; #ifndef FLUTTER_ENGINE_NO_PROTOTYPES @@ -2178,8 +2273,8 @@ FlutterEngineResult FlutterEngineMarkExternalTextureFrameAvailable( /// @param[in] engine A running engine instance. /// @param[in] enabled When enabled, changes to the semantic contents of the /// window are sent via the -/// `FlutterUpdateSemanticsNodeCallback` registered to -/// `update_semantics_node_callback` in +/// `FlutterUpdateSemanticsCallback` registered to +/// `update_semantics_callback` in /// `FlutterProjectArgs`. /// /// @return The result of the call. @@ -2510,6 +2605,26 @@ FLUTTER_EXPORT FlutterEngineResult FlutterEngineScheduleFrame(FLUTTER_API_SYMBOL(FlutterEngine) engine); +//------------------------------------------------------------------------------ +/// @brief Schedule a callback to be called after the next frame is drawn. +/// This must be called from the platform thread. The callback is +/// executed only once from the raster thread; embedders must +/// re-thread if necessary. Performing blocking calls +/// in this callback may introduce application jank. +/// +/// @param[in] engine A running engine instance. +/// @param[in] callback The callback to execute. +/// @param[in] user_data A baton passed by the engine to the callback. This +/// baton is not interpreted by the engine in any way. +/// +/// @return The result of the call. +/// +FLUTTER_EXPORT +FlutterEngineResult FlutterEngineSetNextFrameCallback( + FLUTTER_API_SYMBOL(FlutterEngine) engine, + VoidCallback callback, + void* user_data); + #endif // !FLUTTER_ENGINE_NO_PROTOTYPES // Typedefs for the function pointers in FlutterEngineProcTable. @@ -2628,6 +2743,10 @@ typedef FlutterEngineResult (*FlutterEngineNotifyDisplayUpdateFnPtr)( size_t display_count); typedef FlutterEngineResult (*FlutterEngineScheduleFrameFnPtr)( FLUTTER_API_SYMBOL(FlutterEngine) engine); +typedef FlutterEngineResult (*FlutterEngineSetNextFrameCallbackFnPtr)( + FLUTTER_API_SYMBOL(FlutterEngine) engine, + VoidCallback callback, + void* user_data); /// Function-pointer-based versions of the APIs above. typedef struct { @@ -2673,6 +2792,7 @@ typedef struct { PostCallbackOnAllNativeThreads; FlutterEngineNotifyDisplayUpdateFnPtr NotifyDisplayUpdate; FlutterEngineScheduleFrameFnPtr ScheduleFrame; + FlutterEngineSetNextFrameCallbackFnPtr SetNextFrameCallback; } FlutterEngineProcTable; //------------------------------------------------------------------------------ From ee731f304f4e1a3322da048dae5b38baae0d4612 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Fri, 18 Nov 2022 12:31:58 +0900 Subject: [PATCH 027/112] Fix uninitialized var for touch_events (#301) Fixed #300 --- .../shell/platform/linux_embedded/flutter_elinux_view.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.h b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.h index 1133443f..cdcb9617 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.h +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.h @@ -176,7 +176,12 @@ class FlutterELinuxView : public WindowBindingHandlerDelegate { }; struct touch_event { - touch_point points[10]; + touch_point points[10] = { + {false, -1, 0, 0, 0}, {false, -1, 0, 0, 0}, {false, -1, 0, 0, 0}, + {false, -1, 0, 0, 0}, {false, -1, 0, 0, 0}, {false, -1, 0, 0, 0}, + {false, -1, 0, 0, 0}, {false, -1, 0, 0, 0}, {false, -1, 0, 0, 0}, + {false, -1, 0, 0, 0}, + }; }; // From 1aaebdac0d26005d50bbe26aa0aa08b78ce9065f Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Sat, 10 Dec 2022 10:45:23 +0900 Subject: [PATCH 028/112] Fix code format check errors (#303) Signed-off-by: Hidenori Matsubayashi --- src/client_wrapper/flutter_view_controller.cc | 10 +++++----- .../platform/linux_embedded/flutter_elinux_view.cc | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/client_wrapper/flutter_view_controller.cc b/src/client_wrapper/flutter_view_controller.cc index 28996256..98fce7ee 100644 --- a/src/client_wrapper/flutter_view_controller.cc +++ b/src/client_wrapper/flutter_view_controller.cc @@ -20,11 +20,11 @@ FlutterViewController::FlutterViewController( c_view_properties.view_rotation = (view_properties.view_rotation == ViewRotation::kRotation_90) ? FlutterDesktopViewRotation::kRotation_90 - : (view_properties.view_rotation == ViewRotation::kRotation_180) - ? FlutterDesktopViewRotation::kRotation_180 - : (view_properties.view_rotation == ViewRotation::kRotation_270) - ? FlutterDesktopViewRotation::kRotation_270 - : FlutterDesktopViewRotation::kRotation_0; + : (view_properties.view_rotation == ViewRotation::kRotation_180) + ? FlutterDesktopViewRotation::kRotation_180 + : (view_properties.view_rotation == ViewRotation::kRotation_270) + ? FlutterDesktopViewRotation::kRotation_270 + : FlutterDesktopViewRotation::kRotation_0; c_view_properties.view_mode = (view_properties.view_mode == ViewMode::kFullscreen) ? FlutterDesktopViewMode::kFullscreen diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc index d5461760..03eab017 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc @@ -301,11 +301,11 @@ void FlutterELinuxView::SetEventPhaseFromCursorButtonState( // For details about this logic, see FlutterPointerPhase in the embedder.h // file. event_data->phase = - mouse_state_.buttons == 0 - ? mouse_state_.flutter_state_is_down ? FlutterPointerPhase::kUp - : FlutterPointerPhase::kHover - : mouse_state_.flutter_state_is_down ? FlutterPointerPhase::kMove - : FlutterPointerPhase::kDown; + mouse_state_.buttons == 0 ? mouse_state_.flutter_state_is_down + ? FlutterPointerPhase::kUp + : FlutterPointerPhase::kHover + : mouse_state_.flutter_state_is_down ? FlutterPointerPhase::kMove + : FlutterPointerPhase::kDown; } void FlutterELinuxView::SendPointerMove(double x, double y) { From 3cdde96d604e3a8b7168a9d5a32b404479007207 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20H=C4=83loiu?= Date: Sat, 10 Dec 2022 14:43:08 +0200 Subject: [PATCH 029/112] Use string message codec for lifecycle plugin (#302) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Valentin Hăloiu --- AUTHORS | 1 + cmake/build.cmake | 1 + .../include/flutter/string_message_codec.h | 45 +++++++++++++++++++ .../client_wrapper/string_message_codec.cc | 34 ++++++++++++++ .../plugins/lifecycle_plugin.cc | 14 +++--- .../linux_embedded/plugins/lifecycle_plugin.h | 2 +- 6 files changed, 89 insertions(+), 8 deletions(-) create mode 100644 src/flutter/shell/platform/common/client_wrapper/include/flutter/string_message_codec.h create mode 100644 src/flutter/shell/platform/common/client_wrapper/string_message_codec.cc diff --git a/AUTHORS b/AUTHORS index 8244baf0..6fb4a7df 100644 --- a/AUTHORS +++ b/AUTHORS @@ -7,3 +7,4 @@ Sony Group Corporation Hidenori Matsubayashi (hidenori.matsubayashi@gmail.com) Andrea Daoud (andreadaoud6@gmail.com) +Valentin Hăloiu (valentin.haloiu@gmail.com) diff --git a/cmake/build.cmake b/cmake/build.cmake index ae4feb48..e69ba5ee 100644 --- a/cmake/build.cmake +++ b/cmake/build.cmake @@ -116,6 +116,7 @@ endif() set(CPP_WRAPPER_SOURCES_CORE "src/flutter/shell/platform/common/client_wrapper/engine_method_result.cc" "src/flutter/shell/platform/common/client_wrapper/standard_codec.cc" + "src/flutter/shell/platform/common/client_wrapper/string_message_codec.cc" ) set(CPP_WRAPPER_SOURCES_PLUGIN "src/flutter/shell/platform/common/client_wrapper/plugin_registrar.cc" diff --git a/src/flutter/shell/platform/common/client_wrapper/include/flutter/string_message_codec.h b/src/flutter/shell/platform/common/client_wrapper/include/flutter/string_message_codec.h new file mode 100644 index 00000000..11f31d41 --- /dev/null +++ b/src/flutter/shell/platform/common/client_wrapper/include/flutter/string_message_codec.h @@ -0,0 +1,45 @@ +// Copyright 2022 Sony Corporation. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef __CODE_FLUTTER_EMBEDDED_LINUX_SRC_FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_STRING_MESSAGE_CODEC_H_ +#define __CODE_FLUTTER_EMBEDDED_LINUX_SRC_FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_STRING_MESSAGE_CODEC_H_ + +#include "message_codec.h" + +namespace flutter { + +// A message encoding/decoding mechanism for communications to/from the Flutter +// engine via UTF-8 encoded string messages. +// +// This codec is guaranteed to be compatible with the corresponding +// [StringCodec](https://api.flutter.dev/flutter/services/StringCodec-class.html) +// on the Dart side. These parts of the Flutter SDK are evolved synchronously. +class StringMessageCodec : public MessageCodec { + public: + // Returns the shared instance of the codec. + static const StringMessageCodec& GetInstance(); + + ~StringMessageCodec() = default; + + // Prevent copying. + StringMessageCodec(StringMessageCodec const&) = delete; + StringMessageCodec& operator=(StringMessageCodec const&) = delete; + + protected: + // Instances should be obtained via GetInstance. + StringMessageCodec() = default; + + // |flutter::MessageCodec| + std::unique_ptr DecodeMessageInternal( + const uint8_t* binary_message, + const size_t message_size) const override; + + // |flutter::MessageCodec| + std::unique_ptr> EncodeMessageInternal( + const std::string& message) const override; +}; + +} // namespace flutter + +#endif // __CODE_FLUTTER_EMBEDDED_LINUX_SRC_FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_STRING_MESSAGE_CODEC_H_ diff --git a/src/flutter/shell/platform/common/client_wrapper/string_message_codec.cc b/src/flutter/shell/platform/common/client_wrapper/string_message_codec.cc new file mode 100644 index 00000000..d0c12bac --- /dev/null +++ b/src/flutter/shell/platform/common/client_wrapper/string_message_codec.cc @@ -0,0 +1,34 @@ +// Copyright 2022 Sony Corporation. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "include/flutter/string_message_codec.h" + +#include + +namespace flutter { + +// static +const StringMessageCodec& StringMessageCodec::GetInstance() { + static StringMessageCodec sInstance; + return sInstance; +} + +std::unique_ptr> StringMessageCodec::EncodeMessageInternal( + const std::string& message) const { + return std::make_unique>(message.begin(), message.end()); +} + +std::unique_ptr StringMessageCodec::DecodeMessageInternal( + const uint8_t* binary_message, + const size_t message_size) const { + if (!binary_message) { + return nullptr; + } + + auto raw_message = reinterpret_cast(binary_message); + + return std::make_unique(raw_message, message_size); +} + +} // namespace flutter diff --git a/src/flutter/shell/platform/linux_embedded/plugins/lifecycle_plugin.cc b/src/flutter/shell/platform/linux_embedded/plugins/lifecycle_plugin.cc index 59a9fc0f..009d82eb 100644 --- a/src/flutter/shell/platform/linux_embedded/plugins/lifecycle_plugin.cc +++ b/src/flutter/shell/platform/linux_embedded/plugins/lifecycle_plugin.cc @@ -4,7 +4,7 @@ #include "flutter/shell/platform/linux_embedded/plugins/lifecycle_plugin.h" -#include "flutter/shell/platform/common/client_wrapper/include/flutter/standard_message_codec.h" +#include "flutter/shell/platform/common/client_wrapper/include/flutter/string_message_codec.h" #include "flutter/shell/platform/linux_embedded/logger.h" namespace flutter { @@ -18,29 +18,29 @@ constexpr char kDetached[] = "AppLifecycleState.detached"; } // namespace LifecyclePlugin::LifecyclePlugin(BinaryMessenger* messenger) - : channel_(std::make_unique>( + : channel_(std::make_unique>( messenger, kChannelName, - &StandardMessageCodec::GetInstance())) {} + &StringMessageCodec::GetInstance())) {} void LifecyclePlugin::OnInactive() const { ELINUX_LOG(DEBUG) << "App lifecycle changed to inactive state."; - channel_->Send(EncodableValue(std::string(kInactive))); + channel_->Send(std::string(kInactive)); } void LifecyclePlugin::OnResumed() const { ELINUX_LOG(DEBUG) << "App lifecycle changed to resumed state."; - channel_->Send(EncodableValue(std::string(kResumed))); + channel_->Send(std::string(kResumed)); } void LifecyclePlugin::OnPaused() const { ELINUX_LOG(DEBUG) << "App lifecycle changed to paused state."; - channel_->Send(EncodableValue(std::string(kPaused))); + channel_->Send(std::string(kPaused)); } void LifecyclePlugin::OnDetached() const { ELINUX_LOG(DEBUG) << "App lifecycle changed to detached state."; - channel_->Send(EncodableValue(std::string(kDetached))); + channel_->Send(std::string(kDetached)); } } // namespace flutter diff --git a/src/flutter/shell/platform/linux_embedded/plugins/lifecycle_plugin.h b/src/flutter/shell/platform/linux_embedded/plugins/lifecycle_plugin.h index f93881c2..aa9507c2 100644 --- a/src/flutter/shell/platform/linux_embedded/plugins/lifecycle_plugin.h +++ b/src/flutter/shell/platform/linux_embedded/plugins/lifecycle_plugin.h @@ -26,7 +26,7 @@ class LifecyclePlugin { void OnDetached() const; private: - std::unique_ptr> channel_; + std::unique_ptr> channel_; }; } // namespace flutter From bfb616a0f74d2f7f4c2884b48b7ed18046bc064c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20H=C4=83loiu?= Date: Wed, 14 Dec 2022 01:20:53 +0200 Subject: [PATCH 030/112] Add support for HighDPI cursor themes (#304) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Valentin Hăloiu --- .../window/elinux_window_wayland.cc | 74 +++++++++++++------ .../window/elinux_window_wayland.h | 20 +++-- 2 files changed, 66 insertions(+), 28 deletions(-) diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc index 282128ca..61c6d6be 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc @@ -819,7 +819,6 @@ ELinuxWindowWayland::ELinuxWindowWayland( wl_data_device_(nullptr), wl_data_offer_(nullptr), wl_data_source_(nullptr), - wl_cursor_theme_(nullptr), serial_(0), zwp_text_input_manager_v1_(nullptr), zwp_text_input_manager_v3_(nullptr), @@ -834,6 +833,13 @@ ELinuxWindowWayland::ELinuxWindowWayland( view_properties.force_scale_factor ? view_properties.scale_factor : 1.0; SetRotation(view_properties_.view_rotation); + auto xcursor_size_string = std::getenv(kXcursorSizeEnvironmentKey); + cursor_size_ = + xcursor_size_string ? atoi(xcursor_size_string) : kDefaultPointerSize; + if (cursor_size_ <= 0) { + cursor_size_ = kDefaultPointerSize; + } + wl_display_ = wl_display_connect(nullptr); if (!wl_display_) { ELINUX_LOG(ERROR) << "Failed to connect to the Wayland display."; @@ -889,10 +895,10 @@ ELinuxWindowWayland::~ELinuxWindowWayland() { display_valid_ = false; running_ = false; - if (wl_cursor_theme_) { - wl_cursor_theme_destroy(wl_cursor_theme_); - wl_cursor_theme_ = nullptr; + for (auto theme : wl_cursor_themes_) { + wl_cursor_theme_destroy(theme.second); } + wl_cursor_themes_.clear(); { if (zwp_text_input_v1_) { @@ -1201,7 +1207,7 @@ void ELinuxWindowWayland::UpdateFlutterCursor(const std::string& cursor_name) { return; } - auto wl_cursor = GetWlCursor(cursor_name); + auto wl_cursor = GetWlCursor(cursor_name, cursor_size_ * current_scale_); if (!wl_cursor) { return; } @@ -1213,6 +1219,7 @@ void ELinuxWindowWayland::UpdateFlutterCursor(const std::string& cursor_name) { image->hotspot_y); wl_surface_attach(wl_cursor_surface_, buffer, 0, 0); wl_surface_damage(wl_cursor_surface_, 0, 0, image->width, image->height); + wl_surface_set_buffer_scale(wl_cursor_surface_, current_scale_); wl_surface_commit(wl_cursor_surface_); } } @@ -1321,12 +1328,6 @@ void ELinuxWindowWayland::WlRegistryHandler(wl_registry* wl_registry, constexpr uint32_t kMaxVersion = 1; wl_shm_ = static_cast( wl_registry_bind(wl_registry, name, &wl_shm_interface, kMaxVersion)); - wl_cursor_theme_ = wl_cursor_theme_load(nullptr, 32, wl_shm_); - if (!wl_cursor_theme_) { - ELINUX_LOG(ERROR) << "Failed to load cursor theme."; - return; - } - CreateSupportedWlCursorList(); } return; } @@ -1378,8 +1379,22 @@ void ELinuxWindowWayland::WlRegistryHandler(wl_registry* wl_registry, void ELinuxWindowWayland::WlUnRegistryHandler(wl_registry* wl_registry, uint32_t name) {} -void ELinuxWindowWayland::CreateSupportedWlCursorList() { - std::vector wl_cursor_themes{ +bool ELinuxWindowWayland::LoadCursorTheme(uint32_t size) { + if (!wl_shm_) { + ELINUX_LOG(ERROR) << "Failed to load cursor theme because shared memory " + "buffers are not available."; + return false; + } + + auto theme = wl_cursor_theme_load(nullptr, size, wl_shm_); + if (!theme) { + ELINUX_LOG(ERROR) << "Failed to load cursor theme for size: " << size; + return false; + } + + wl_cursor_themes_[size] = theme; + + std::vector wl_cursor_names{ kWlCursorThemeLeftPtr, kWlCursorThemeBottomLeftCorner, kWlCursorThemeBottomRightCorner, @@ -1395,18 +1410,24 @@ void ELinuxWindowWayland::CreateSupportedWlCursorList() { kWlCursorThemeWatch, }; - for (const auto& theme : wl_cursor_themes) { - auto wl_cursor = - wl_cursor_theme_get_cursor(wl_cursor_theme_, theme.c_str()); + std::unordered_map cursor_list; + + for (const auto& cursor_name : wl_cursor_names) { + auto wl_cursor = wl_cursor_theme_get_cursor(theme, cursor_name.c_str()); if (!wl_cursor) { - ELINUX_LOG(ERROR) << "Unsupported cursor theme: " << theme.c_str(); + ELINUX_LOG(ERROR) << "Unsupported cursor theme: " << cursor_name.c_str(); continue; } - supported_wl_cursor_list_[theme] = wl_cursor; + cursor_list[cursor_name] = wl_cursor; } + + supported_wl_cursor_list_.insert(std::make_pair(size, cursor_list)); + + return true; } -wl_cursor* ELinuxWindowWayland::GetWlCursor(const std::string& cursor_name) { +wl_cursor* ELinuxWindowWayland::GetWlCursor(const std::string& cursor_name, + uint32_t size) { // Convert the cursor theme name from Flutter's cursor value to Wayland's one. // However, Wayland has not all cursor themes corresponding to Flutter. // If there is no Wayland's cursor theme corresponding to the Flutter's cursor @@ -1450,17 +1471,24 @@ wl_cursor* ELinuxWindowWayland::GetWlCursor(const std::string& cursor_name) { {"zoomOut", ""}, }; + if (supported_wl_cursor_list_.find(size) == supported_wl_cursor_list_.end()) { + if (!LoadCursorTheme(size)) { + return nullptr; + } + } + + auto cursor_list = supported_wl_cursor_list_.at(size); + if (flutter_to_wayland_cursor_map.find(cursor_name) != flutter_to_wayland_cursor_map.end()) { auto theme = flutter_to_wayland_cursor_map.at(cursor_name); - if (!theme.empty() && supported_wl_cursor_list_.find(theme) != - supported_wl_cursor_list_.end()) { - return supported_wl_cursor_list_[theme]; + if (!theme.empty() && cursor_list.find(theme) != cursor_list.end()) { + return cursor_list[theme]; } } ELINUX_LOG(ERROR) << "Unsupported cursor: " << cursor_name.c_str(); - return supported_wl_cursor_list_[kWlCursorThemeLeftPtr]; + return cursor_list[kWlCursorThemeLeftPtr]; } void ELinuxWindowWayland::ShowVirtualKeyboard() { diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h index d62ebd5a..bd7aadcc 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h @@ -29,6 +29,10 @@ extern "C" { namespace flutter { +namespace { +constexpr char kXcursorSizeEnvironmentKey[] = "XCURSOR_SIZE"; +} // namespace + class ELinuxWindowWayland : public ELinuxWindow, public WindowBindingHandler { public: ELinuxWindowWayland(FlutterDesktopViewProperties view_properties); @@ -90,9 +94,9 @@ class ELinuxWindowWayland : public ELinuxWindow, public WindowBindingHandler { void WlUnRegistryHandler(wl_registry* wl_registry, uint32_t name); - void CreateSupportedWlCursorList(); + bool LoadCursorTheme(uint32_t size); - wl_cursor* GetWlCursor(const std::string& cursor_name); + wl_cursor* GetWlCursor(const std::string& cursor_name, uint32_t size); void ShowVirtualKeyboard(); @@ -115,6 +119,7 @@ class ELinuxWindowWayland : public ELinuxWindow, public WindowBindingHandler { static const wp_presentation_listener kWpPresentationListener; static const wp_presentation_feedback_listener kWpPresentationFeedbackListener; + static constexpr size_t kDefaultPointerSize = 24; // A pointer to a FlutterWindowsView that can be used to update engine // windowing and input state. @@ -149,7 +154,6 @@ class ELinuxWindowWayland : public ELinuxWindow, public WindowBindingHandler { wl_touch* wl_touch_; wl_keyboard* wl_keyboard_; wl_surface* wl_cursor_surface_; - wl_cursor_theme* wl_cursor_theme_; xdg_wm_base* xdg_wm_base_; xdg_surface* xdg_surface_; xdg_toplevel* xdg_toplevel_; @@ -167,9 +171,15 @@ class ELinuxWindowWayland : public ELinuxWindow, public WindowBindingHandler { int32_t frame_rate_; CursorInfo cursor_info_; + size_t cursor_size_; + + // List of cursor name and wl_cursor supported by Wayland keyed by their + // (scaled) size. + std::unordered_map> + supported_wl_cursor_list_; - // List of cursor name and wl_cursor supported by Wayland. - std::unordered_map supported_wl_cursor_list_; + // List of loaded Wayland cursor themes keyed by their (scaled) size. + std::unordered_map wl_cursor_themes_; wl_data_device_manager* wl_data_device_manager_; wl_data_device* wl_data_device_; From 905bf392bb11b20ad11228dbeed02f13b4c9794f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20H=C4=83loiu?= Date: Sun, 18 Dec 2022 01:26:03 +0200 Subject: [PATCH 031/112] Clear cursor name when leaving window (#305) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Valentin Hăloiu --- .../platform/linux_embedded/window/elinux_window_wayland.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc index 61c6d6be..89e08fc8 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc @@ -282,6 +282,12 @@ const wl_pointer_listener ELinuxWindowWayland::kWlPointerListener = { self->wl_current_surface_ = surface; self->serial_ = serial; + if (self->view_properties_.use_mouse_cursor) { + // Clear the cursor name in order to make sure it gets redrawn next time + // it enters the surface. + self->cursor_info_.cursor_name.clear(); + } + if (self->binding_handler_delegate_) { self->binding_handler_delegate_->OnPointerLeave(); self->pointer_x_ = -1; From 9dd66b9cb69bbfea0bcc39fda10cead94ec4ec5b Mon Sep 17 00:00:00 2001 From: Flafy Date: Wed, 21 Dec 2022 03:17:59 +0200 Subject: [PATCH 032/112] fix: use wayland-protocols from pkg-config rather than system (#306) Signed-off-by: FlafyDev --- AUTHORS | 1 + cmake/build.cmake | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index 6fb4a7df..02e75d5d 100644 --- a/AUTHORS +++ b/AUTHORS @@ -8,3 +8,4 @@ Sony Group Corporation Hidenori Matsubayashi (hidenori.matsubayashi@gmail.com) Andrea Daoud (andreadaoud6@gmail.com) Valentin Hăloiu (valentin.haloiu@gmail.com) +FlafyDev diff --git a/cmake/build.cmake b/cmake/build.cmake index e69ba5ee..8ea841a6 100644 --- a/cmake/build.cmake +++ b/cmake/build.cmake @@ -38,7 +38,8 @@ elseif(${BACKEND_TYPE} STREQUAL "X11") "src/flutter/shell/platform/linux_embedded/window/native_window_x11.cc") else() include(cmake/generate_wayland_protocols.cmake) - set(_wayland_protocols_xml_dir "$ENV{PKG_CONFIG_SYSROOT_DIR}/usr/share/wayland-protocols") + pkg_get_variable(WAYLAND_PROTOCOLS_DATADIR wayland-protocols pkgdatadir) + set(_wayland_protocols_xml_dir "${WAYLAND_PROTOCOLS_DATADIR}") set(_wayland_protocols_src_dir "${CMAKE_CURRENT_SOURCE_DIR}/src/third_party/wayland/protocols") file(MAKE_DIRECTORY "${_wayland_protocols_src_dir}") From 02263619e09ec639791b0da22adeebf9ed12463d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20H=C4=83loiu?= Date: Tue, 27 Dec 2022 12:24:56 +0200 Subject: [PATCH 033/112] Use scale factor from the window's list of entered outputs (#307) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Valentin Hăloiu --- .../window/elinux_window_wayland.cc | 76 ++++++++++++++++++- .../window/elinux_window_wayland.h | 12 ++- 2 files changed, 84 insertions(+), 4 deletions(-) diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc index 89e08fc8..3abeb9a8 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc @@ -148,6 +148,40 @@ const xdg_toplevel_listener ELinuxWindowWayland::kXdgToplevelListener = { self->running_ = false; }}; +const wl_surface_listener ELinuxWindowWayland::kWlSurfaceListener = { + .enter = + [](void* data, wl_surface* wl_surface, wl_output* output) { + // The compositor can send a null output: crbug.com/1332540 + if (!output) { + ELINUX_LOG(ERROR) << "cannot enter a NULL output"; + return; + } + + const uint32_t output_id = + wl_proxy_get_id(reinterpret_cast(output)); + ELINUX_LOG(TRACE) << "window entered output " << output_id; + auto self = reinterpret_cast(data); + + self->entered_outputs_.insert(output_id); + self->UpdateWindowScale(); + }, + .leave = + [](void* data, wl_surface* wl_surface, wl_output* output) { + // The compositor can send a null output: crbug.com/1332540 + if (!output) { + ELINUX_LOG(ERROR) << "cannot leave a NULL output"; + return; + } + + const uint32_t output_id = + wl_proxy_get_id(reinterpret_cast(output)); + ELINUX_LOG(TRACE) << "window left output " << output_id; + auto self = reinterpret_cast(data); + + self->entered_outputs_.erase(output_id); + self->UpdateWindowScale(); + }}; + const wp_presentation_listener ELinuxWindowWayland::kWpPresentationListener = { .clock_id = [](void* data, wp_presentation* wp_presentation, uint32_t clk_id) { @@ -570,9 +604,16 @@ const wl_output_listener ELinuxWindowWayland::kWlOutputListener = { .done = [](void* data, wl_output* wl_output) -> void {}, .scale = [](void* data, wl_output* wl_output, int32_t scale) -> void { auto self = reinterpret_cast(data); - ELINUX_LOG(INFO) << "Display output scale: " << scale; - if (!self->view_properties_.force_scale_factor) - self->current_scale_ = scale; + + const uint32_t output_id = + wl_proxy_get_id(reinterpret_cast(wl_output)); + + ELINUX_LOG(INFO) << "Display scale for output(" << output_id + << "): " << scale; + + self->wl_output_scale_factors_[output_id] = scale; + + self->UpdateWindowScale(); }, }; @@ -1125,6 +1166,8 @@ bool ELinuxWindowWayland::CreateRenderSurface(int32_t width, int32_t height) { native_window_ = std::make_unique(wl_compositor_, width, height); + wl_surface_add_listener(native_window_->Surface(), &kWlSurfaceListener, this); + xdg_surface_ = xdg_wm_base_get_xdg_surface(xdg_wm_base_, native_window_->Surface()); if (!xdg_surface_) { @@ -1527,4 +1570,31 @@ void ELinuxWindowWayland::DismissVirtualKeybaord() { } } +void ELinuxWindowWayland::UpdateWindowScale() { + if (this->view_properties_.force_scale_factor) + return; + + double scale_factor = 1.0; + for (auto output_id : entered_outputs_) { + if (wl_output_scale_factors_.find(output_id) == + wl_output_scale_factors_.end()) + continue; + + auto output_scale_factor = wl_output_scale_factors_.at(output_id); + if (output_scale_factor > scale_factor) + scale_factor = output_scale_factor; + } + + if (this->current_scale_ == scale_factor) + return; + + ELINUX_LOG(TRACE) << "Window scale has changed: " << scale_factor; + this->current_scale_ = scale_factor; + + if (this->binding_handler_delegate_) { + this->binding_handler_delegate_->OnWindowSizeChanged( + this->view_properties_.width, this->view_properties_.height); + } +} + } // namespace flutter diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h index bd7aadcc..b1a0c51e 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h @@ -10,7 +10,7 @@ #include #include -#include +#include #include "flutter/shell/platform/linux_embedded/surface/surface_gl.h" #include "flutter/shell/platform/linux_embedded/window/elinux_window.h" @@ -102,10 +102,14 @@ class ELinuxWindowWayland : public ELinuxWindow, public WindowBindingHandler { void DismissVirtualKeybaord(); + // Updates the surface scale of the window from the list of entered outputs. + void UpdateWindowScale(); + static const wl_registry_listener kWlRegistryListener; static const xdg_wm_base_listener kXdgWmBaseListener; static const xdg_surface_listener kXdgSurfaceListener; static const xdg_toplevel_listener kXdgToplevelListener; + static const wl_surface_listener kWlSurfaceListener; static const wl_seat_listener kWlSeatListener; static const wl_pointer_listener kWlPointerListener; static const wl_touch_listener kWlTouchListener; @@ -181,6 +185,12 @@ class ELinuxWindowWayland : public ELinuxWindow, public WindowBindingHandler { // List of loaded Wayland cursor themes keyed by their (scaled) size. std::unordered_map wl_cursor_themes_; + // List of outputs that the window is currently rendered on. + std::unordered_set entered_outputs_; + + // List of output scale factors keyed by their ids. + std::unordered_map wl_output_scale_factors_; + wl_data_device_manager* wl_data_device_manager_; wl_data_device* wl_data_device_; wl_data_offer* wl_data_offer_; From 640a72ff843ecec351a24f86ed8251915d411922 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20H=C4=83loiu?= Date: Thu, 29 Dec 2022 02:07:06 +0200 Subject: [PATCH 034/112] Use positive height for button resize argument (#309) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Valentin Hăloiu --- .../window/renderer/window_decorations_wayland.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.cc index 35af9d04..7cf26094 100644 --- a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.cc @@ -95,7 +95,7 @@ void WindowDecorationsWayland::Resize(const int32_t width, buttons_[i]->SetPosition( width - kButtonWidth * (i + 1) - kButtonMargin * (i + 1), -(kButtonHeight + (kTitleBarHeight - kButtonHeight) / 2)); - buttons_[i]->Resize(kButtonWidth, -kButtonHeight); + buttons_[i]->Resize(kButtonWidth, kButtonHeight); } } From 2790806e8d5528d6227ce79da34eeac4cb5edf3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20H=C4=83loiu?= Date: Thu, 29 Dec 2022 02:13:27 +0200 Subject: [PATCH 035/112] Continue listening to presentation feedback after discarded frame (#310) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Valentin Hăloiu --- .../linux_embedded/window/elinux_window_wayland.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc index 3abeb9a8..3b4d0a1f 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc @@ -226,7 +226,18 @@ const wp_presentation_feedback_listener }, .discarded = [](void* data, - struct wp_presentation_feedback* wp_presentation_feedback) {}, + struct wp_presentation_feedback* wp_presentation_feedback) { + auto self = reinterpret_cast(data); + + if (self->window_decorations_) { + self->window_decorations_->Draw(); + } + + wp_presentation_feedback_add_listener( + ::wp_presentation_feedback(self->wp_presentation_, + self->native_window_->Surface()), + &kWpPresentationFeedbackListener, data); + }, }; const wl_callback_listener ELinuxWindowWayland::kWlSurfaceFrameListener = { From 1298b57711e9a4d3e6c6a8cf030a84dce5e36a6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20H=C4=83loiu?= Date: Fri, 30 Dec 2022 02:05:55 +0200 Subject: [PATCH 036/112] Fix cursor hotspot for scale factors different than 1 (#311) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Valentin Hăloiu --- .../platform/linux_embedded/window/elinux_window_wayland.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc index 3b4d0a1f..df4ca359 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc @@ -1274,9 +1274,9 @@ void ELinuxWindowWayland::UpdateFlutterCursor(const std::string& cursor_name) { auto image = wl_cursor->images[0]; auto buffer = wl_cursor_image_get_buffer(image); if (buffer) { - wl_pointer_set_cursor(cursor_info_.pointer, cursor_info_.serial, - wl_cursor_surface_, image->hotspot_x, - image->hotspot_y); + wl_pointer_set_cursor( + cursor_info_.pointer, cursor_info_.serial, wl_cursor_surface_, + image->hotspot_x / current_scale_, image->hotspot_y / current_scale_); wl_surface_attach(wl_cursor_surface_, buffer, 0, 0); wl_surface_damage(wl_cursor_surface_, 0, 0, image->width, image->height); wl_surface_set_buffer_scale(wl_cursor_surface_, current_scale_); From 4d30263afbd248074c51629ba292b42e29cb7573 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20H=C4=83loiu?= Date: Fri, 30 Dec 2022 02:53:51 +0200 Subject: [PATCH 037/112] Subtract client decorations height from flutter surface height (#312) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Valentin Hăloiu --- .../window/elinux_window_wayland.cc | 16 +++++++++++++--- .../window/elinux_window_wayland.h | 3 +++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc index df4ca359..8328e127 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc @@ -138,8 +138,9 @@ const xdg_toplevel_listener ELinuxWindowWayland::kXdgToplevelListener = { self->window_decorations_->Resize(next_width, next_height); } if (self->binding_handler_delegate_) { - self->binding_handler_delegate_->OnWindowSizeChanged(next_width, - next_height); + self->binding_handler_delegate_->OnWindowSizeChanged( + next_width, + next_height - self->WindowDecorationsPhysicalHeight()); } }, .close = @@ -1604,8 +1605,17 @@ void ELinuxWindowWayland::UpdateWindowScale() { if (this->binding_handler_delegate_) { this->binding_handler_delegate_->OnWindowSizeChanged( - this->view_properties_.width, this->view_properties_.height); + this->view_properties_.width, + this->view_properties_.height - + this->WindowDecorationsPhysicalHeight()); } } +uint32_t ELinuxWindowWayland::WindowDecorationsPhysicalHeight() const { + if (!this->window_decorations_) + return 0; + + return this->window_decorations_->Height() * current_scale_; +} + } // namespace flutter diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h index b1a0c51e..476e61a0 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h @@ -105,6 +105,9 @@ class ELinuxWindowWayland : public ELinuxWindow, public WindowBindingHandler { // Updates the surface scale of the window from the list of entered outputs. void UpdateWindowScale(); + // Get window decorations height in physical pixels. + uint32_t WindowDecorationsPhysicalHeight() const; + static const wl_registry_listener kWlRegistryListener; static const xdg_wm_base_listener kXdgWmBaseListener; static const xdg_surface_listener kXdgSurfaceListener; From 5316c729959078b445ed556623d11dc410c9352a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20H=C4=83loiu?= Date: Fri, 30 Dec 2022 03:03:31 +0200 Subject: [PATCH 038/112] Annotate code with coordinate system information (#313) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Valentin Hăloiu --- .../linux_embedded/flutter_elinux_view.cc | 67 ++++++++++--------- .../linux_embedded/flutter_elinux_view.h | 36 ++++++---- .../linux_embedded/surface/surface_base.cc | 6 +- .../linux_embedded/surface/surface_base.h | 4 +- .../surface/surface_decoration.cc | 4 +- .../surface/surface_decoration.h | 6 +- .../linux_embedded/window/elinux_window.h | 4 ++ .../window/elinux_window_wayland.cc | 19 +++--- .../window/elinux_window_wayland.h | 2 +- .../linux_embedded/window/native_window.h | 18 +++-- .../window/native_window_wayland.cc | 19 +++--- .../window/native_window_wayland.h | 8 ++- .../native_window_wayland_decoration.cc | 28 ++++---- .../window/native_window_wayland_decoration.h | 10 +-- .../window/renderer/window_decoration.h | 8 ++- .../renderer/window_decoration_button.cc | 10 +-- .../renderer/window_decoration_button.h | 4 +- .../renderer/window_decoration_titlebar.cc | 11 +-- .../renderer/window_decoration_titlebar.h | 4 +- .../renderer/window_decorations_wayland.cc | 56 +++++++++------- .../renderer/window_decorations_wayland.h | 11 ++- .../linux_embedded/window_binding_handler.h | 4 +- .../window_binding_handler_delegate.h | 30 ++++++--- 23 files changed, 216 insertions(+), 153 deletions(-) diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc index 03eab017..43dfc11e 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc @@ -86,36 +86,37 @@ void FlutterELinuxView::RegisterPlatformViewFactory( platform_views_handler_->RegisterViewFactory(view_type, std::move(factory)); } -void FlutterELinuxView::OnWindowSizeChanged(size_t width, size_t height) const { - if (!GetRenderSurfaceTarget()->OnScreenSurfaceResize(width, height)) { +void FlutterELinuxView::OnWindowSizeChanged(size_t width_px, + size_t height_px) const { + if (!GetRenderSurfaceTarget()->OnScreenSurfaceResize(width_px, height_px)) { ELINUX_LOG(ERROR) << "Failed to change surface size."; return; } - SendWindowMetrics(width, height, binding_handler_->GetDpiScale()); + SendWindowMetrics(width_px, height_px, binding_handler_->GetDpiScale()); } -void FlutterELinuxView::OnPointerMove(double x, double y) { - auto trimmed_xy = GetPointerRotation(x, y); +void FlutterELinuxView::OnPointerMove(double x_px, double y_px) { + auto trimmed_xy = GetPointerRotation(x_px, y_px); SendPointerMove(trimmed_xy.first, trimmed_xy.second); } void FlutterELinuxView::OnPointerDown( - double x, - double y, + double x_px, + double y_px, FlutterPointerMouseButtons flutter_button) { if (flutter_button != 0) { uint64_t mouse_buttons = mouse_state_.buttons | flutter_button; - auto trimmed_xy = GetPointerRotation(x, y); + auto trimmed_xy = GetPointerRotation(x_px, y_px); SetMouseButtons(mouse_buttons); SendPointerDown(trimmed_xy.first, trimmed_xy.second); } } -void FlutterELinuxView::OnPointerUp(double x, - double y, +void FlutterELinuxView::OnPointerUp(double x_px, + double y_px, FlutterPointerMouseButtons flutter_button) { if (flutter_button != 0) { - auto trimmed_xy = GetPointerRotation(x, y); + auto trimmed_xy = GetPointerRotation(x_px, y_px); uint64_t mouse_buttons = mouse_state_.buttons & ~flutter_button; SetMouseButtons(mouse_buttons); SendPointerUp(trimmed_xy.first, trimmed_xy.second); @@ -277,13 +278,13 @@ FlutterELinuxView::touch_point* FlutterELinuxView::GgeTouchPoint(int32_t id) { } // Sends new size information to FlutterEngine. -void FlutterELinuxView::SendWindowMetrics(size_t width, - size_t height, +void FlutterELinuxView::SendWindowMetrics(size_t width_px, + size_t height_px, double dpiScale) const { FlutterWindowMetricsEvent event = {}; event.struct_size = sizeof(event); - event.width = width; - event.height = height; + event.width = width_px; + event.height = height_px; event.pixel_ratio = dpiScale; engine_->SendWindowMetricsEvent(event); } @@ -308,28 +309,28 @@ void FlutterELinuxView::SetEventPhaseFromCursorButtonState( : FlutterPointerPhase::kDown; } -void FlutterELinuxView::SendPointerMove(double x, double y) { +void FlutterELinuxView::SendPointerMove(double x_px, double y_px) { FlutterPointerEvent event = {}; - event.x = x; - event.y = y; + event.x = x_px; + event.y = y_px; SetEventPhaseFromCursorButtonState(&event); SendPointerEventWithData(event); } -void FlutterELinuxView::SendPointerDown(double x, double y) { +void FlutterELinuxView::SendPointerDown(double x_px, double y_px) { FlutterPointerEvent event = {}; SetEventPhaseFromCursorButtonState(&event); - event.x = x; - event.y = y; + event.x = x_px; + event.y = y_px; SendPointerEventWithData(event); SetMouseFlutterStateDown(true); } -void FlutterELinuxView::SendPointerUp(double x, double y) { +void FlutterELinuxView::SendPointerUp(double x_px, double y_px) { FlutterPointerEvent event = {}; SetEventPhaseFromCursorButtonState(&event); - event.x = x; - event.y = y; + event.x = x_px; + event.y = y_px; SendPointerEventWithData(event); if (event.phase == FlutterPointerPhase::kUp) { SetMouseFlutterStateDown(false); @@ -468,21 +469,21 @@ FlutterTransformation FlutterELinuxView::GetRootSurfaceTransformation() { return view_rotation_transformation_; } -std::pair FlutterELinuxView::GetPointerRotation(double x, - double y) { +std::pair FlutterELinuxView::GetPointerRotation(double x_px, + double y_px) { auto degree = binding_handler_->GetRotationDegree(); auto bounds = binding_handler_->GetPhysicalWindowBounds(); - std::pair res = {x, y}; + std::pair res = {x_px, y_px}; if (degree == 90) { - res.first = y; - res.second = bounds.height - x; + res.first = y_px; + res.second = bounds.height - x_px; } else if (degree == 180) { - res.first = bounds.width - x; - res.second = bounds.height - y; + res.first = bounds.width - x_px; + res.second = bounds.height - y_px; } else if (degree == 270) { - res.first = bounds.width - y; - res.second = x; + res.first = bounds.width - y_px; + res.second = x_px; } return res; } diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.h b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.h index cdcb9617..d335ecbe 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.h +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.h @@ -82,19 +82,19 @@ class FlutterELinuxView : public WindowBindingHandlerDelegate { void SendInitialBounds(); // |WindowBindingHandlerDelegate| - void OnWindowSizeChanged(size_t width, size_t height) const override; + void OnWindowSizeChanged(size_t width_px, size_t height_px) const override; // |WindowBindingHandlerDelegate| - void OnPointerMove(double x, double y) override; + void OnPointerMove(double x_px, double y_px) override; // |WindowBindingHandlerDelegate| - void OnPointerDown(double x, - double y, + void OnPointerDown(double x_px, + double y_px, FlutterPointerMouseButtons button) override; // |WindowBindingHandlerDelegate| - void OnPointerUp(double x, - double y, + void OnPointerUp(double x_px, + double y_px, FlutterPointerMouseButtons button) override; // |WindowBindingHandlerDelegate| @@ -188,17 +188,27 @@ class FlutterELinuxView : public WindowBindingHandlerDelegate { touch_point* GgeTouchPoint(int32_t id); // Sends a window metrics update to the Flutter engine using current window - // dimensions in physical - void SendWindowMetrics(size_t width, size_t height, double dpiscale) const; + // dimensions in physical pixels. + // @param[in] width_px Physical width of the window. + // @param[in] height_px Physical height of the window. + void SendWindowMetrics(size_t width_px, + size_t height_px, + double dpiscale) const; // Reports a mouse movement to Flutter engine. - void SendPointerMove(double x, double y); + // @param[in] x_px The x coordinate of the pointer event in physical pixels. + // @param[in] y_px The y coordinate of the pointer event in physical pixels. + void SendPointerMove(double x_px, double y_px); // Reports mouse press to Flutter engine. - void SendPointerDown(double x, double y); + // @param[in] x_px The x coordinate of the pointer event in physical pixels. + // @param[in] y_px The y coordinate of the pointer event in physical pixels. + void SendPointerDown(double x_px, double y_px); // Reports mouse release to Flutter engine. - void SendPointerUp(double x, double y); + // @param[in] x_px The x coordinate of the pointer event in physical pixels. + // @param[in] y_px The y coordinate of the pointer event in physical pixels. + void SendPointerUp(double x_px, double y_px); // Reports mouse left the window client area. // @@ -243,7 +253,9 @@ class FlutterELinuxView : public WindowBindingHandlerDelegate { void SetMouseButtons(uint64_t buttons) { mouse_state_.buttons = buttons; } // Returns a trimmed pointer of user inputs with the window rotation. - std::pair GetPointerRotation(double x, double y); + // @param[in] x_px The x coordinate of the pointer event in physical pixels. + // @param[in] y_px The y coordinate of the pointer event in physical pixels. + std::pair GetPointerRotation(double x_px, double y_px); // The engine associated with this view. std::unique_ptr engine_; diff --git a/src/flutter/shell/platform/linux_embedded/surface/surface_base.cc b/src/flutter/shell/platform/linux_embedded/surface/surface_base.cc index f27f4f21..1067ad57 100644 --- a/src/flutter/shell/platform/linux_embedded/surface/surface_base.cc +++ b/src/flutter/shell/platform/linux_embedded/surface/surface_base.cc @@ -29,9 +29,9 @@ bool SurfaceBase::SetNativeWindow(NativeWindow* window) { return true; }; -bool SurfaceBase::OnScreenSurfaceResize(const size_t width, - const size_t height) { - if (!native_window_->Resize(width, height)) { +bool SurfaceBase::OnScreenSurfaceResize(const size_t width_px, + const size_t height_px) { + if (!native_window_->Resize(width_px, height_px)) { ELINUX_LOG(ERROR) << "Failed to resize."; return false; } diff --git a/src/flutter/shell/platform/linux_embedded/surface/surface_base.h b/src/flutter/shell/platform/linux_embedded/surface/surface_base.h index d1c5e2af..1b7e23a8 100644 --- a/src/flutter/shell/platform/linux_embedded/surface/surface_base.h +++ b/src/flutter/shell/platform/linux_embedded/surface/surface_base.h @@ -28,7 +28,9 @@ class SurfaceBase { // On-screen surface needs to be recreated after window size changed only when // using DRM-GBM backend. Because gbm-surface is recreated when the window // size changed. - bool OnScreenSurfaceResize(const size_t width, const size_t height); + // @param[in] width_px Physical width of the surface. + // @param[in] height_px Physical height of the surface. + bool OnScreenSurfaceResize(const size_t width_px, const size_t height_px); // Clears current on-screen context. bool ClearCurrentContext() const; diff --git a/src/flutter/shell/platform/linux_embedded/surface/surface_decoration.cc b/src/flutter/shell/platform/linux_embedded/surface/surface_decoration.cc index dc7e932c..fb73a275 100644 --- a/src/flutter/shell/platform/linux_embedded/surface/surface_decoration.cc +++ b/src/flutter/shell/platform/linux_embedded/surface/surface_decoration.cc @@ -27,8 +27,8 @@ bool SurfaceDecoration::SetNativeWindow(NativeWindow* window) { return true; }; -bool SurfaceDecoration::Resize(const size_t width, const size_t height) { - if (!native_window_->Resize(width, height)) { +bool SurfaceDecoration::Resize(const size_t width_px, const size_t height_px) { + if (!native_window_->Resize(width_px, height_px)) { ELINUX_LOG(ERROR) << "Failed to resize."; return false; } diff --git a/src/flutter/shell/platform/linux_embedded/surface/surface_decoration.h b/src/flutter/shell/platform/linux_embedded/surface/surface_decoration.h index 243a3ee1..1e44ed89 100644 --- a/src/flutter/shell/platform/linux_embedded/surface/surface_decoration.h +++ b/src/flutter/shell/platform/linux_embedded/surface/surface_decoration.h @@ -26,8 +26,10 @@ class SurfaceDecoration : public SurfaceGlDelegate { // Sets a netive platform's window. bool SetNativeWindow(NativeWindow* window); - // Changes an decoration surface size. - bool Resize(const size_t width, const size_t height); + // Changes a decoration surface size. + // @param[in] width_px Physical width of the surface. + // @param[in] height_px Physical height of the surface. + bool Resize(const size_t width_px, const size_t height_px); // Clears and destroys current decoration context. void DestroyContext(); diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window.h b/src/flutter/shell/platform/linux_embedded/window/elinux_window.h index d5ac0c4e..8c3911c2 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window.h +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window.h @@ -17,8 +17,10 @@ class ELinuxWindow { protected: virtual bool IsValid() const = 0; + // Get current window width in physical pixels. uint32_t GetCurrentWidth() const { return view_properties_.width; } + // Get current window height in physical pixels. uint32_t GetCurrentHeight() const { return view_properties_.height; } void SetRotation(FlutterDesktopViewRotation rotation) { @@ -36,7 +38,9 @@ class ELinuxWindow { FlutterDesktopViewProperties view_properties_; double current_scale_ = 1.0; uint16_t current_rotation_ = 0; + // The x coordinate of the pointer in physical pixels. double pointer_x_ = 0; + // The y coordinate of the pointer in physical pixels. double pointer_y_ = 0; std::string clipboard_data_ = ""; }; diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc index 8328e127..11328e5a 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc @@ -1140,7 +1140,8 @@ bool ELinuxWindowWayland::DispatchEvent() { return true; } -bool ELinuxWindowWayland::CreateRenderSurface(int32_t width, int32_t height) { +bool ELinuxWindowWayland::CreateRenderSurface(int32_t width_px, + int32_t height_px) { if (!display_valid_) { ELINUX_LOG(ERROR) << "Wayland display is invalid."; return false; @@ -1157,12 +1158,12 @@ bool ELinuxWindowWayland::CreateRenderSurface(int32_t width, int32_t height) { } if (view_properties_.view_mode == FlutterDesktopViewMode::kFullscreen) { - width = view_properties_.width; - height = view_properties_.height; + width_px = view_properties_.width; + height_px = view_properties_.height; } - ELINUX_LOG(TRACE) << "Created the Wayland surface: " << width << "x" - << height; + ELINUX_LOG(TRACE) << "Created the Wayland surface: " << width_px << "x" + << height_px; if (view_properties_.use_mouse_cursor) { wl_cursor_surface_ = wl_compositor_create_surface(wl_compositor_); if (!wl_cursor_surface_) { @@ -1173,10 +1174,10 @@ bool ELinuxWindowWayland::CreateRenderSurface(int32_t width, int32_t height) { } if (current_rotation_ == 90 || current_rotation_ == 270) { - std::swap(width, height); + std::swap(width_px, height_px); } - native_window_ = - std::make_unique(wl_compositor_, width, height); + native_window_ = std::make_unique(wl_compositor_, + width_px, height_px); wl_surface_add_listener(native_window_->Surface(), &kWlSurfaceListener, this); @@ -1212,7 +1213,7 @@ bool ELinuxWindowWayland::CreateRenderSurface(int32_t width, int32_t height) { if (view_properties_.use_window_decoration) { window_decorations_ = std::make_unique( wl_display_, wl_compositor_, wl_subcompositor_, - native_window_->Surface(), width, height); + native_window_->Surface(), width_px, height_px); } return true; diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h index 476e61a0..6860adaf 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h @@ -45,7 +45,7 @@ class ELinuxWindowWayland : public ELinuxWindow, public WindowBindingHandler { bool DispatchEvent() override; // |FlutterWindowBindingHandler| - bool CreateRenderSurface(int32_t width, int32_t height) override; + bool CreateRenderSurface(int32_t width_px, int32_t height_px) override; // |FlutterWindowBindingHandler| void DestroyRenderSurface() override; diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window.h b/src/flutter/shell/platform/linux_embedded/window/native_window.h index bbe80954..2d0f77a2 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window.h +++ b/src/flutter/shell/platform/linux_embedded/window/native_window.h @@ -21,6 +21,7 @@ class NativeWindow { // Gets a window (GBM surface) for offscreen resource. EGLNativeWindowType WindowOffscreen() const { return window_offscreen_; } + // Get physical width of the window. int32_t Width() const { if (!valid_) { return -1; @@ -28,6 +29,7 @@ class NativeWindow { return width_; } + // Get physical height of the window. int32_t Height() const { if (!valid_) { return -1; @@ -39,12 +41,16 @@ class NativeWindow { // Sets a window position. Basically, this API is used for window decorations // such as titlebar. - virtual void SetPosition(const int32_t x, const int32_t y) { - x_ = x; - y_ = y; + // @param[in] x_dip The x coordinate in logical pixels. + // @param[in] y_dip The y coordinate in logical pixels. + virtual void SetPosition(const int32_t x_dip, const int32_t y_dip) { + x_ = x_dip; + y_ = y_dip; }; - virtual bool Resize(const size_t width, const size_t height) = 0; + // @param[in] width_px Physical width of the window. + // @param[in] height_px Physical height of the window. + virtual bool Resize(const size_t width_px, const size_t height_px) = 0; // Swaps frame buffers. This API performs processing only for the DRM-GBM // backend. It is prepared to make the interface common. @@ -53,9 +59,13 @@ class NativeWindow { protected: EGLNativeWindowType window_; EGLNativeWindowType window_offscreen_; + // Physical width of the window. int32_t width_; + // Physical height of the window. int32_t height_; + // The x coordinate of the window in logical pixels. int32_t x_; + // The y coordinate of the window in logical pixels. int32_t y_; bool valid_ = false; }; diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/native_window_wayland.cc index 6f5aa398..c35df018 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_wayland.cc @@ -9,15 +9,15 @@ namespace flutter { NativeWindowWayland::NativeWindowWayland(wl_compositor* compositor, - const size_t width, - const size_t height) { + const size_t width_px, + const size_t height_px) { surface_ = wl_compositor_create_surface(compositor); if (!surface_) { ELINUX_LOG(ERROR) << "Failed to create the compositor surface."; return; } - window_ = wl_egl_window_create(surface_, width, height); + window_ = wl_egl_window_create(surface_, width_px, height_px); if (!window_) { ELINUX_LOG(ERROR) << "Failed to create the EGL window."; return; @@ -40,8 +40,8 @@ NativeWindowWayland::NativeWindowWayland(wl_compositor* compositor, } } - width_ = width; - height_ = height; + width_ = width_px; + height_ = height_px; valid_ = true; } @@ -67,15 +67,16 @@ NativeWindowWayland::~NativeWindowWayland() { } } -bool NativeWindowWayland::Resize(const size_t width, const size_t height) { +bool NativeWindowWayland::Resize(const size_t width_px, + const size_t height_px) { if (!valid_) { ELINUX_LOG(ERROR) << "Failed to resize the window."; return false; } - wl_egl_window_resize(window_, width, height, 0, 0); + wl_egl_window_resize(window_, width_px, height_px, 0, 0); - width_ = width; - height_ = height; + width_ = width_px; + height_ = height_px; return true; } diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_wayland.h b/src/flutter/shell/platform/linux_embedded/window/native_window_wayland.h index 5688058f..b28b0f93 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_wayland.h +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_wayland.h @@ -13,13 +13,15 @@ namespace flutter { class NativeWindowWayland : public NativeWindow { public: + // @param[in] width_px Physical width of the window. + // @param[in] height_px Physical height of the window. NativeWindowWayland(wl_compositor* compositor, - const size_t width, - const size_t height); + const size_t width_px, + const size_t height_px); ~NativeWindowWayland(); // |NativeWindow| - bool Resize(const size_t width, const size_t height) override; + bool Resize(const size_t width_px, const size_t height_px) override; wl_surface* Surface() const { return surface_; } diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_wayland_decoration.cc b/src/flutter/shell/platform/linux_embedded/window/native_window_wayland_decoration.cc index 20486eee..56eea3eb 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_wayland_decoration.cc +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_wayland_decoration.cc @@ -12,8 +12,8 @@ NativeWindowWaylandDecoration::NativeWindowWaylandDecoration( wl_compositor* compositor, wl_subcompositor* subcompositor, wl_surface* parent_surface, - const size_t width, - const size_t height) { + const size_t width_px, + const size_t height_px) { surface_ = wl_compositor_create_surface(compositor); if (!surface_) { ELINUX_LOG(ERROR) << "Failed to create the compositor surface."; @@ -35,8 +35,8 @@ NativeWindowWaylandDecoration::NativeWindowWaylandDecoration( return; } - width_ = width; - height_ = height; + width_ = width_px; + height_ = height_px; valid_ = true; } @@ -52,29 +52,29 @@ NativeWindowWaylandDecoration::~NativeWindowWaylandDecoration() { } } -bool NativeWindowWaylandDecoration::Resize(const size_t width, - const size_t height) { +bool NativeWindowWaylandDecoration::Resize(const size_t width_px, + const size_t height_px) { if (!valid_) { ELINUX_LOG(ERROR) << "Failed to resize the window."; return false; } - width_ = width; - height_ = height; - wl_egl_window_resize(window_, width, height, 0, 0); + width_ = width_px; + height_ = height_px; + wl_egl_window_resize(window_, width_px, height_px, 0, 0); return true; } -void NativeWindowWaylandDecoration::SetPosition(const int32_t x, - const int32_t y) { +void NativeWindowWaylandDecoration::SetPosition(const int32_t x_dip, + const int32_t y_dip) { if (!valid_) { ELINUX_LOG(ERROR) << "Failed to set the position of the window."; return; } - x_ = x; - y_ = y; - wl_subsurface_set_position(subsurface_, x, y); + x_ = x_dip; + y_ = y_dip; + wl_subsurface_set_position(subsurface_, x_dip, y_dip); } } // namespace flutter diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_wayland_decoration.h b/src/flutter/shell/platform/linux_embedded/window/native_window_wayland_decoration.h index d270c338..72664006 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_wayland_decoration.h +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_wayland_decoration.h @@ -14,18 +14,20 @@ namespace flutter { class NativeWindowWaylandDecoration : public NativeWindow { public: + // @param[in] width_px Physical width of the window. + // @param[in] height_px Physical height of the window. NativeWindowWaylandDecoration(wl_compositor* compositor, wl_subcompositor* subcompositor, wl_surface* parent_surface, - const size_t width, - const size_t height); + const size_t width_px, + const size_t height_px); ~NativeWindowWaylandDecoration(); // |NativeWindow| - bool Resize(const size_t width, const size_t height) override; + bool Resize(const size_t width_px, const size_t height_px) override; // |NativeWindow| - void SetPosition(const int32_t x, const int32_t y) override; + void SetPosition(const int32_t x_dip, const int32_t y_dip) override; wl_surface* Surface() const { return surface_; } diff --git a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration.h b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration.h index d722d54c..eb98d9a1 100644 --- a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration.h +++ b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration.h @@ -28,9 +28,13 @@ class WindowDecoration { virtual void Draw() = 0; - virtual void SetPosition(const int32_t x, const int32_t y) = 0; + // @param[in] x_dip The x coordinate in logical pixels. + // @param[in] y_dip The y coordinate in logical pixels. + virtual void SetPosition(const int32_t x_dip, const int32_t y_dip) = 0; - virtual void Resize(const int32_t width, const int32_t height) = 0; + // @param[in] width_px Physical width of the window. + // @param[in] height_px Physical height of the window. + virtual void Resize(const size_t width_px, const size_t height_px) = 0; void DestroyContext() const { render_surface_->DestroyContext(); }; diff --git a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration_button.cc b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration_button.cc index 60f071a7..aff6d693 100644 --- a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration_button.cc +++ b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration_button.cc @@ -198,12 +198,14 @@ void WindowDecorationButton::Draw() { render_surface_->GLContextPresent(0); } -void WindowDecorationButton::SetPosition(const int32_t x, const int32_t y) { - native_window_->SetPosition(x, y); +void WindowDecorationButton::SetPosition(const int32_t x_dip, + const int32_t y_dip) { + native_window_->SetPosition(x_dip, y_dip); } -void WindowDecorationButton::Resize(const int32_t width, const int32_t height) { - render_surface_->Resize(width, height); +void WindowDecorationButton::Resize(const size_t width_px, + const size_t height_px) { + render_surface_->Resize(width_px, height_px); } void WindowDecorationButton::LoadShader() { diff --git a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration_button.h b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration_button.h index 89e8fc95..19eee254 100644 --- a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration_button.h +++ b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration_button.h @@ -21,10 +21,10 @@ class WindowDecorationButton : public WindowDecoration { void Draw() override; // |WindowDecoration| - void SetPosition(const int32_t x, const int32_t y) override; + void SetPosition(const int32_t x_dip, const int32_t y_dip) override; // |WindowDecoration| - void Resize(const int32_t width, const int32_t height) override; + void Resize(const size_t width_px, const size_t height_px) override; private: void LoadShader(); diff --git a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration_titlebar.cc b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration_titlebar.cc index 47b8e69c..240418d9 100644 --- a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration_titlebar.cc +++ b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration_titlebar.cc @@ -69,13 +69,14 @@ void WindowDecorationTitlebar::Draw() { render_surface_->GLContextPresent(0); } -void WindowDecorationTitlebar::SetPosition(const int32_t x, const int32_t y) { - native_window_->SetPosition(x, y); +void WindowDecorationTitlebar::SetPosition(const int32_t x_dip, + const int32_t y_dip) { + native_window_->SetPosition(x_dip, y_dip); } -void WindowDecorationTitlebar::Resize(const int32_t width, - const int32_t height) { - render_surface_->Resize(width, height); +void WindowDecorationTitlebar::Resize(const size_t width_px, + const size_t height_px) { + render_surface_->Resize(width_px, height_px); } } // namespace flutter diff --git a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration_titlebar.h b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration_titlebar.h index 9cb5fce5..74a53ed4 100644 --- a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration_titlebar.h +++ b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration_titlebar.h @@ -19,10 +19,10 @@ class WindowDecorationTitlebar : public WindowDecoration { void Draw() override; // |WindowDecoration| - void SetPosition(const int32_t x, const int32_t y) override; + void SetPosition(const int32_t x_dip, const int32_t y_dip) override; // |WindowDecoration| - void Resize(const int32_t width, const int32_t height) override; + void Resize(const size_t width_px, const size_t height_px) override; }; } // namespace flutter diff --git a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.cc index 7cf26094..dd172296 100644 --- a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.cc @@ -10,11 +10,11 @@ namespace flutter { namespace { -constexpr uint kTitleBarHeight = 30; +constexpr uint kTitleBarHeightDIP = 30; -constexpr uint kButtonWidth = 15; -constexpr uint kButtonHeight = 15; -constexpr uint kButtonMargin = 10; +constexpr uint kButtonWidthDIP = 15; +constexpr uint kButtonHeightDIP = 15; +constexpr uint kButtonMarginDIP = 10; } // namespace WindowDecorationsWayland::WindowDecorationsWayland( @@ -22,53 +22,57 @@ WindowDecorationsWayland::WindowDecorationsWayland( wl_compositor* compositor, wl_subcompositor* subcompositor, wl_surface* root_surface, - int32_t width, - int32_t height) { + int32_t width_dip, + int32_t height_dip) { constexpr bool sub_egl_display = true; // title-bar. titlebar_ = std::make_unique( - std::make_unique( - compositor, subcompositor, root_surface, width, kTitleBarHeight), + std::make_unique(compositor, subcompositor, + root_surface, width_dip, + kTitleBarHeightDIP), std::make_unique(std::make_unique( std::make_unique(display, sub_egl_display)))); - titlebar_->SetPosition(0, -kTitleBarHeight); + titlebar_->SetPosition(0, -kTitleBarHeightDIP); // close button. auto type = WindowDecorationButton::DecorationType::CLOSE_BUTTON; buttons_.push_back(std::make_unique( type, std::make_unique( - compositor, subcompositor, root_surface, kButtonWidth, kButtonHeight), + compositor, subcompositor, root_surface, kButtonWidthDIP, + kButtonHeightDIP), std::make_unique(std::make_unique( std::make_unique(display, sub_egl_display))))); buttons_[type]->SetPosition( - width - kButtonWidth - kButtonMargin, - -(kButtonHeight + (kTitleBarHeight - kButtonHeight) / 2)); + width_dip - kButtonWidthDIP - kButtonMarginDIP, + -(kButtonHeightDIP + (kTitleBarHeightDIP - kButtonHeightDIP) / 2)); // maximise button. type = WindowDecorationButton::DecorationType::MAXIMISE_BUTTON; buttons_.push_back(std::make_unique( type, std::make_unique( - compositor, subcompositor, root_surface, kButtonWidth, kButtonHeight), + compositor, subcompositor, root_surface, kButtonWidthDIP, + kButtonHeightDIP), std::make_unique(std::make_unique( std::make_unique(display, sub_egl_display))))); buttons_[type]->SetPosition( - width - kButtonWidth * 2 - kButtonMargin * 2, - -(kButtonHeight + (kTitleBarHeight - kButtonHeight) / 2)); + width_dip - kButtonWidthDIP * 2 - kButtonMarginDIP * 2, + -(kButtonHeightDIP + (kTitleBarHeightDIP - kButtonHeightDIP) / 2)); // minimise button. type = WindowDecorationButton::DecorationType::MINIMISE_BUTTON; buttons_.push_back(std::make_unique( type, std::make_unique( - compositor, subcompositor, root_surface, kButtonWidth, kButtonHeight), + compositor, subcompositor, root_surface, kButtonWidthDIP, + kButtonHeightDIP), std::make_unique(std::make_unique( std::make_unique(display, sub_egl_display))))); buttons_[type]->SetPosition( - width - kButtonWidth * 3 - kButtonMargin * 3, - -(kButtonHeight + (kTitleBarHeight - kButtonHeight) / 2)); + width_dip - kButtonWidthDIP * 3 - kButtonMarginDIP * 3, + -(kButtonHeightDIP + (kTitleBarHeightDIP - kButtonHeightDIP) / 2)); } WindowDecorationsWayland::~WindowDecorationsWayland() { @@ -86,16 +90,16 @@ void WindowDecorationsWayland::Draw() { } } -void WindowDecorationsWayland::Resize(const int32_t width, - const int32_t height) { - titlebar_->SetPosition(0, -kTitleBarHeight); - titlebar_->Resize(width, kTitleBarHeight); +void WindowDecorationsWayland::Resize(const int32_t width_dip, + const int32_t height_dip) { + titlebar_->SetPosition(0, -kTitleBarHeightDIP); + titlebar_->Resize(width_dip, kTitleBarHeightDIP); for (auto i = 0; i < buttons_.size(); i++) { buttons_[i]->SetPosition( - width - kButtonWidth * (i + 1) - kButtonMargin * (i + 1), - -(kButtonHeight + (kTitleBarHeight - kButtonHeight) / 2)); - buttons_[i]->Resize(kButtonWidth, kButtonHeight); + width_dip - kButtonWidthDIP * (i + 1) - kButtonMarginDIP * (i + 1), + -(kButtonHeightDIP + (kTitleBarHeightDIP - kButtonHeightDIP) / 2)); + buttons_[i]->Resize(kButtonWidthDIP, kButtonHeightDIP); } } @@ -118,7 +122,7 @@ void WindowDecorationsWayland::DestroyContext() { } int32_t WindowDecorationsWayland::Height() const { - return kTitleBarHeight; + return kTitleBarHeightDIP; } } // namespace flutter diff --git a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.h b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.h index 607d0c3e..43f265b6 100644 --- a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.h +++ b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.h @@ -26,21 +26,26 @@ namespace flutter { class WindowDecorationsWayland { public: + // @param[in] width_dip Logical width of the window (i.e. surface width). + // @param[in] height_dip Logical height of the window (i.e. surface height). WindowDecorationsWayland(wl_display* display, wl_compositor* compositor, wl_subcompositor* subcompositor, wl_surface* root_surface, - int32_t width, - int32_t height); + int32_t width_dip, + int32_t height_dip); ~WindowDecorationsWayland(); void Draw(); - void Resize(const int32_t width, const int32_t height); + // @param[in] width_dip Logical width of the window (i.e. surface width). + // @param[in] height_dip Logical height of the window (i.e. surface height). + void Resize(const int32_t width_dip, const int32_t height_dip); bool IsMatched(wl_surface* surface, WindowDecoration::DecorationType decoration_type) const; + // Get height in logical pixels. int32_t Height() const; private: diff --git a/src/flutter/shell/platform/linux_embedded/window_binding_handler.h b/src/flutter/shell/platform/linux_embedded/window_binding_handler.h index 83aa7920..ce8fffb4 100644 --- a/src/flutter/shell/platform/linux_embedded/window_binding_handler.h +++ b/src/flutter/shell/platform/linux_embedded/window_binding_handler.h @@ -34,7 +34,9 @@ class WindowBindingHandler { virtual bool DispatchEvent() = 0; // Create a surface. - virtual bool CreateRenderSurface(int32_t width, int32_t height) = 0; + // @param[in] width_px Physical width of the surface. + // @param[in] height_px Physical height of the surface. + virtual bool CreateRenderSurface(int32_t width_px, int32_t height_px) = 0; // Destroy a surface which is currently used. virtual void DestroyRenderSurface() = 0; diff --git a/src/flutter/shell/platform/linux_embedded/window_binding_handler_delegate.h b/src/flutter/shell/platform/linux_embedded/window_binding_handler_delegate.h index 73f1330d..944e0e07 100644 --- a/src/flutter/shell/platform/linux_embedded/window_binding_handler_delegate.h +++ b/src/flutter/shell/platform/linux_embedded/window_binding_handler_delegate.h @@ -11,24 +11,32 @@ namespace flutter { class WindowBindingHandlerDelegate { public: - // Notifies delegate that backing window size has changed. - // Typically called by currently configured WindowBindingHandler - virtual void OnWindowSizeChanged(size_t width, size_t height) const = 0; - - // Notifies delegate that backing window mouse has moved. - // Typically called by currently configured WindowBindingHandler - virtual void OnPointerMove(double x, double y) = 0; + // Notifies delegate that backing window size has changed. Typically called by + // currently configured WindowBindingHandler + // @param[in] width_px Physical width of the window. + // @param[in] height_px Physical height of the window. + virtual void OnWindowSizeChanged(size_t width_px, size_t height_px) const = 0; + + // Notifies delegate that backing window mouse has moved. Typically called by + // currently configured WindowBindingHandler + // @param[in] x_px The x coordinate of the pointer event in physical pixels. + // @param[in] y_px The y coordinate of the pointer event in physical pixels. + virtual void OnPointerMove(double x_px, double y_px) = 0; // Notifies delegate that backing window mouse pointer button has been // pressed. Typically called by currently configured WindowBindingHandler - virtual void OnPointerDown(double x, - double y, + // @param[in] x_px The x coordinate of the pointer event in physical pixels. + // @param[in] y_px The y coordinate of the pointer event in physical pixels. + virtual void OnPointerDown(double x_px, + double y_px, FlutterPointerMouseButtons button) = 0; // Notifies delegate that backing window mouse pointer button has been // released. Typically called by currently configured WindowBindingHandler - virtual void OnPointerUp(double x, - double y, + // @param[in] x_px The x coordinate of the pointer event in physical pixels. + // @param[in] y_px The y coordinate of the pointer event in physical pixels. + virtual void OnPointerUp(double x_px, + double y_px, FlutterPointerMouseButtons button) = 0; // Notifies delegate that backing window mouse pointer has left the window. From d88c3c55d9bce06a864f5b51a6d5a9a71293a336 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20H=C4=83loiu?= Date: Fri, 30 Dec 2022 21:34:43 +0200 Subject: [PATCH 039/112] Add HighDPI support for Wayland (#314) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Valentin Hăloiu --- .../linux_embedded/public/flutter_elinux.h | 4 +- .../linux_embedded/window/elinux_window.h | 8 ++- .../window/elinux_window_wayland.cc | 54 ++++++++++++------- .../native_window_wayland_decoration.cc | 9 ++++ .../window/native_window_wayland_decoration.h | 4 ++ .../window/renderer/window_decoration.h | 4 ++ .../renderer/window_decoration_button.cc | 4 ++ .../renderer/window_decoration_button.h | 3 ++ .../renderer/window_decoration_titlebar.cc | 4 ++ .../renderer/window_decoration_titlebar.h | 3 ++ .../renderer/window_decorations_wayland.cc | 31 ++++++----- .../renderer/window_decorations_wayland.h | 9 +++- 12 files changed, 99 insertions(+), 38 deletions(-) diff --git a/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h b/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h index a8b0b5d8..22115437 100644 --- a/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h +++ b/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h @@ -76,10 +76,10 @@ enum FlutterDesktopViewRotation { // Properties for configuring a Flutter view instance. typedef struct { - // View width. + // View width in logical pixels. int width; - // View height. + // View height in logical pixels. int height; // View rotation setting. diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window.h b/src/flutter/shell/platform/linux_embedded/window/elinux_window.h index 8c3911c2..eaec182d 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window.h +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window.h @@ -18,10 +18,14 @@ class ELinuxWindow { virtual bool IsValid() const = 0; // Get current window width in physical pixels. - uint32_t GetCurrentWidth() const { return view_properties_.width; } + uint32_t GetCurrentWidth() const { + return view_properties_.width * current_scale_; + } // Get current window height in physical pixels. - uint32_t GetCurrentHeight() const { return view_properties_.height; } + uint32_t GetCurrentHeight() const { + return view_properties_.height * current_scale_; + } void SetRotation(FlutterDesktopViewRotation rotation) { if (rotation == FlutterDesktopViewRotation::kRotation_90) { diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc index 11328e5a..106d2a86 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc @@ -135,12 +135,14 @@ const xdg_toplevel_listener ELinuxWindowWayland::kXdgToplevelListener = { self->view_properties_.width = next_width; self->view_properties_.height = next_height; if (self->window_decorations_) { - self->window_decorations_->Resize(next_width, next_height); + self->window_decorations_->Resize(next_width, next_height, + self->current_scale_); } if (self->binding_handler_delegate_) { self->binding_handler_delegate_->OnWindowSizeChanged( - next_width, - next_height - self->WindowDecorationsPhysicalHeight()); + next_width * self->current_scale_, + next_height * self->current_scale_ - + self->WindowDecorationsPhysicalHeight()); } }, .close = @@ -313,11 +315,11 @@ const wl_pointer_listener ELinuxWindowWayland::kWlPointerListener = { } if (self->binding_handler_delegate_) { - double x = wl_fixed_to_double(surface_x); - double y = wl_fixed_to_double(surface_y); - self->binding_handler_delegate_->OnPointerMove(x, y); - self->pointer_x_ = x; - self->pointer_y_ = y; + double x_px = wl_fixed_to_double(surface_x) * self->current_scale_; + double y_px = wl_fixed_to_double(surface_y) * self->current_scale_; + self->binding_handler_delegate_->OnPointerMove(x_px, y_px); + self->pointer_x_ = x_px; + self->pointer_y_ = y_px; } }, .leave = [](void* data, @@ -347,11 +349,11 @@ const wl_pointer_listener ELinuxWindowWayland::kWlPointerListener = { wl_fixed_t surface_y) -> void { auto self = reinterpret_cast(data); if (self->binding_handler_delegate_) { - double x = wl_fixed_to_double(surface_x); - double y = wl_fixed_to_double(surface_y); - self->binding_handler_delegate_->OnPointerMove(x, y); - self->pointer_x_ = x; - self->pointer_y_ = y; + double x_px = wl_fixed_to_double(surface_x) * self->current_scale_; + double y_px = wl_fixed_to_double(surface_y) * self->current_scale_; + self->binding_handler_delegate_->OnPointerMove(x_px, y_px); + self->pointer_x_ = x_px; + self->pointer_y_ = y_px; } }, .button = [](void* data, @@ -604,7 +606,10 @@ const wl_output_listener ELinuxWindowWayland::kWlOutputListener = { self->view_properties_.height = height; if (self->window_decorations_) { - self->window_decorations_->Resize(width, height); + int32_t width_dip = width / self->current_scale_; + int32_t height_dip = height / self->current_scale_; + self->window_decorations_->Resize(width_dip, height_dip, + self->current_scale_); } if (self->binding_handler_delegate_) { @@ -1158,8 +1163,8 @@ bool ELinuxWindowWayland::CreateRenderSurface(int32_t width_px, } if (view_properties_.view_mode == FlutterDesktopViewMode::kFullscreen) { - width_px = view_properties_.width; - height_px = view_properties_.height; + width_px = view_properties_.width * current_scale_; + height_px = view_properties_.height * current_scale_; } ELINUX_LOG(TRACE) << "Created the Wayland surface: " << width_px << "x" @@ -1192,6 +1197,7 @@ bool ELinuxWindowWayland::CreateRenderSurface(int32_t width_px, xdg_toplevel_ = xdg_surface_get_toplevel(xdg_surface_); xdg_toplevel_set_title(xdg_toplevel_, "Flutter"); xdg_toplevel_add_listener(xdg_toplevel_, &kXdgToplevelListener, this); + wl_surface_set_buffer_scale(native_window_->Surface(), current_scale_); wl_surface_commit(native_window_->Surface()); { @@ -1211,9 +1217,11 @@ bool ELinuxWindowWayland::CreateRenderSurface(int32_t width_px, render_surface_->SetNativeWindow(native_window_.get()); if (view_properties_.use_window_decoration) { + int32_t width_dip = width_px / current_scale_; + int32_t height_dip = height_px / current_scale_; window_decorations_ = std::make_unique( wl_display_, wl_compositor_, wl_subcompositor_, - native_window_->Surface(), width_px, height_px); + native_window_->Surface(), width_dip, height_dip, current_scale_); } return true; @@ -1604,10 +1612,18 @@ void ELinuxWindowWayland::UpdateWindowScale() { ELINUX_LOG(TRACE) << "Window scale has changed: " << scale_factor; this->current_scale_ = scale_factor; + wl_surface_set_buffer_scale(native_window_->Surface(), current_scale_); + + if (this->window_decorations_) { + this->window_decorations_->Resize(this->view_properties_.width, + this->view_properties_.height, + this->current_scale_); + } + if (this->binding_handler_delegate_) { this->binding_handler_delegate_->OnWindowSizeChanged( - this->view_properties_.width, - this->view_properties_.height - + this->view_properties_.width * this->current_scale_, + this->view_properties_.height * this->current_scale_ - this->WindowDecorationsPhysicalHeight()); } } diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_wayland_decoration.cc b/src/flutter/shell/platform/linux_embedded/window/native_window_wayland_decoration.cc index 56eea3eb..6595dbc3 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_wayland_decoration.cc +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_wayland_decoration.cc @@ -77,4 +77,13 @@ void NativeWindowWaylandDecoration::SetPosition(const int32_t x_dip, wl_subsurface_set_position(subsurface_, x_dip, y_dip); } +void NativeWindowWaylandDecoration::SetScaleFactor(float scale_factor) { + if (!valid_) { + ELINUX_LOG(ERROR) << "Failed to set the scale factor of the window."; + return; + } + + wl_surface_set_buffer_scale(surface_, scale_factor); +} + } // namespace flutter diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_wayland_decoration.h b/src/flutter/shell/platform/linux_embedded/window/native_window_wayland_decoration.h index 72664006..c48c0954 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_wayland_decoration.h +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_wayland_decoration.h @@ -29,6 +29,10 @@ class NativeWindowWaylandDecoration : public NativeWindow { // |NativeWindow| void SetPosition(const int32_t x_dip, const int32_t y_dip) override; + // Sets the scale factor for the next commit. Scale factor persists until a + // new one is set. + void SetScaleFactor(float scale_factor); + wl_surface* Surface() const { return surface_; } private: diff --git a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration.h b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration.h index eb98d9a1..9b36eebf 100644 --- a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration.h +++ b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration.h @@ -36,6 +36,10 @@ class WindowDecoration { // @param[in] height_px Physical height of the window. virtual void Resize(const size_t width_px, const size_t height_px) = 0; + // Sets the scale factor for the next commit. Scale factor persists until a + // new one is set. + virtual void SetScaleFactor(float scale_factor) = 0; + void DestroyContext() const { render_surface_->DestroyContext(); }; wl_surface* Surface() const { return native_window_->Surface(); }; diff --git a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration_button.cc b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration_button.cc index aff6d693..d7964d8c 100644 --- a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration_button.cc +++ b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration_button.cc @@ -208,6 +208,10 @@ void WindowDecorationButton::Resize(const size_t width_px, render_surface_->Resize(width_px, height_px); } +void WindowDecorationButton::SetScaleFactor(float scale_factor) { + native_window_->SetScaleFactor(scale_factor); +} + void WindowDecorationButton::LoadShader() { if (shader_) { return; diff --git a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration_button.h b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration_button.h index 19eee254..abd4e04a 100644 --- a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration_button.h +++ b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration_button.h @@ -26,6 +26,9 @@ class WindowDecorationButton : public WindowDecoration { // |WindowDecoration| void Resize(const size_t width_px, const size_t height_px) override; + // |WindowDecoration| + void SetScaleFactor(float scale_factor) override; + private: void LoadShader(); diff --git a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration_titlebar.cc b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration_titlebar.cc index 240418d9..fd9f2da3 100644 --- a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration_titlebar.cc +++ b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration_titlebar.cc @@ -79,4 +79,8 @@ void WindowDecorationTitlebar::Resize(const size_t width_px, render_surface_->Resize(width_px, height_px); } +void WindowDecorationTitlebar::SetScaleFactor(float scale_factor) { + native_window_->SetScaleFactor(scale_factor); +} + } // namespace flutter diff --git a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration_titlebar.h b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration_titlebar.h index 74a53ed4..a8ce9093 100644 --- a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration_titlebar.h +++ b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration_titlebar.h @@ -23,6 +23,9 @@ class WindowDecorationTitlebar : public WindowDecoration { // |WindowDecoration| void Resize(const size_t width_px, const size_t height_px) override; + + // |WindowDecoration| + void SetScaleFactor(float scale_factor) override; }; } // namespace flutter diff --git a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.cc index dd172296..d118573b 100644 --- a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.cc @@ -23,14 +23,15 @@ WindowDecorationsWayland::WindowDecorationsWayland( wl_subcompositor* subcompositor, wl_surface* root_surface, int32_t width_dip, - int32_t height_dip) { + int32_t height_dip, + double pixel_ratio) { constexpr bool sub_egl_display = true; // title-bar. titlebar_ = std::make_unique( - std::make_unique(compositor, subcompositor, - root_surface, width_dip, - kTitleBarHeightDIP), + std::make_unique( + compositor, subcompositor, root_surface, width_dip * pixel_ratio, + kTitleBarHeightDIP * pixel_ratio), std::make_unique(std::make_unique( std::make_unique(display, sub_egl_display)))); titlebar_->SetPosition(0, -kTitleBarHeightDIP); @@ -40,8 +41,8 @@ WindowDecorationsWayland::WindowDecorationsWayland( buttons_.push_back(std::make_unique( type, std::make_unique( - compositor, subcompositor, root_surface, kButtonWidthDIP, - kButtonHeightDIP), + compositor, subcompositor, root_surface, + kButtonWidthDIP * pixel_ratio, kButtonHeightDIP * pixel_ratio), std::make_unique(std::make_unique( std::make_unique(display, sub_egl_display))))); buttons_[type]->SetPosition( @@ -53,8 +54,8 @@ WindowDecorationsWayland::WindowDecorationsWayland( buttons_.push_back(std::make_unique( type, std::make_unique( - compositor, subcompositor, root_surface, kButtonWidthDIP, - kButtonHeightDIP), + compositor, subcompositor, root_surface, + kButtonWidthDIP * pixel_ratio, kButtonHeightDIP * pixel_ratio), std::make_unique(std::make_unique( std::make_unique(display, sub_egl_display))))); buttons_[type]->SetPosition( @@ -66,8 +67,8 @@ WindowDecorationsWayland::WindowDecorationsWayland( buttons_.push_back(std::make_unique( type, std::make_unique( - compositor, subcompositor, root_surface, kButtonWidthDIP, - kButtonHeightDIP), + compositor, subcompositor, root_surface, + kButtonWidthDIP * pixel_ratio, kButtonHeightDIP * pixel_ratio), std::make_unique(std::make_unique( std::make_unique(display, sub_egl_display))))); buttons_[type]->SetPosition( @@ -91,15 +92,19 @@ void WindowDecorationsWayland::Draw() { } void WindowDecorationsWayland::Resize(const int32_t width_dip, - const int32_t height_dip) { + const int32_t height_dip, + double pixel_ratio) { + titlebar_->SetScaleFactor(pixel_ratio); titlebar_->SetPosition(0, -kTitleBarHeightDIP); - titlebar_->Resize(width_dip, kTitleBarHeightDIP); + titlebar_->Resize(width_dip * pixel_ratio, kTitleBarHeightDIP * pixel_ratio); for (auto i = 0; i < buttons_.size(); i++) { + buttons_[i]->SetScaleFactor(pixel_ratio); buttons_[i]->SetPosition( width_dip - kButtonWidthDIP * (i + 1) - kButtonMarginDIP * (i + 1), -(kButtonHeightDIP + (kTitleBarHeightDIP - kButtonHeightDIP) / 2)); - buttons_[i]->Resize(kButtonWidthDIP, kButtonHeightDIP); + buttons_[i]->Resize(kButtonWidthDIP * pixel_ratio, + kButtonHeightDIP * pixel_ratio); } } diff --git a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.h b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.h index 43f265b6..9910841e 100644 --- a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.h +++ b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.h @@ -28,19 +28,24 @@ class WindowDecorationsWayland { public: // @param[in] width_dip Logical width of the window (i.e. surface width). // @param[in] height_dip Logical height of the window (i.e. surface height). + // @param[in] pixel_ratio Physical / logical pixels ratio. WindowDecorationsWayland(wl_display* display, wl_compositor* compositor, wl_subcompositor* subcompositor, wl_surface* root_surface, int32_t width_dip, - int32_t height_dip); + int32_t height_dip, + double pixel_ratio); ~WindowDecorationsWayland(); void Draw(); // @param[in] width_dip Logical width of the window (i.e. surface width). // @param[in] height_dip Logical height of the window (i.e. surface height). - void Resize(const int32_t width_dip, const int32_t height_dip); + // @param[in] pixel_ratio Physical / logical pixels ratio. + void Resize(const int32_t width_dip, + const int32_t height_dip, + double pixel_ratio); bool IsMatched(wl_surface* surface, WindowDecoration::DecorationType decoration_type) const; From 916143556b510e6bf7fb6e52fdb9ede1c27ec85f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20H=C4=83loiu?= Date: Mon, 2 Jan 2023 01:50:56 +0200 Subject: [PATCH 040/112] Make window title and app ID configurable (#316) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Valentin Hăloiu --- .../flutter_embedder_options.h | 13 +++++++++++-- examples/flutter-drm-eglstream-backend/main.cc | 2 ++ .../flutter_embedder_options.h | 13 +++++++++++-- examples/flutter-drm-gbm-backend/main.cc | 2 ++ .../flutter_embedder_options.h | 13 +++++++++++-- examples/flutter-external-texture-plugin/main.cc | 2 ++ .../flutter_embedder_options.h | 13 +++++++++++-- examples/flutter-video-player-plugin/main.cc | 2 ++ .../flutter_embedder_options.h | 13 +++++++++++-- examples/flutter-wayland-client/main.cc | 2 ++ .../flutter-x11-client/flutter_embedder_options.h | 13 +++++++++++-- examples/flutter-x11-client/main.cc | 2 ++ src/client_wrapper/flutter_view_controller.cc | 6 ++++++ .../include/flutter/flutter_view_controller.h | 8 ++++++++ .../platform/linux_embedded/public/flutter_elinux.h | 7 +++++++ .../linux_embedded/window/elinux_window_wayland.cc | 7 ++++++- 16 files changed, 105 insertions(+), 13 deletions(-) diff --git a/examples/flutter-drm-eglstream-backend/flutter_embedder_options.h b/examples/flutter-drm-eglstream-backend/flutter_embedder_options.h index cc8193fc..45fd4b32 100644 --- a/examples/flutter-drm-eglstream-backend/flutter_embedder_options.h +++ b/examples/flutter-drm-eglstream-backend/flutter_embedder_options.h @@ -22,8 +22,8 @@ class FlutterEmbedderOptions { "Window rotation(degree) [0(default)|90|180|270]", 0, false); options_.AddDouble("force-scale-factor", "s", - "Force a scale factor instead using default value", 1.0, - false); + "Force a scale factor instead using default value", 1.0, + false); #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) // no more options. @@ -33,6 +33,9 @@ class FlutterEmbedderOptions { options_.AddInt("width", "w", "Window width", 1280, false); options_.AddInt("height", "h", "Window height", 720, false); #else // FLUTTER_TARGET_BACKEND_WAYLAND + options_.AddString("title", "t", "Window title", "Flutter", false); + options_.AddString("app-id", "a", "XDG App ID", "dev.flutter.elinux", + false); options_.AddWithoutValue("onscreen-keyboard", "k", "Enable on-screen keyboard", false); options_.AddWithoutValue("window-decoration", "d", @@ -53,6 +56,8 @@ class FlutterEmbedderOptions { } bundle_path_ = options_.GetValue("bundle"); + window_title_ = options_.GetValue("title"); + window_app_id_ = options_.GetValue("app-id"); use_mouse_cursor_ = !options_.Exist("no-cursor"); if (options_.Exist("rotation")) { switch (options_.GetValue("rotation")) { @@ -112,6 +117,8 @@ class FlutterEmbedderOptions { } std::string BundlePath() const { return bundle_path_; } + std::string WindowTitle() const { return window_title_; } + std::string WindowAppID() const { return window_app_id_; } bool IsUseMouseCursor() const { return use_mouse_cursor_; } bool IsUseOnscreenKeyboard() const { return use_onscreen_keyboard_; } bool IsUseWindowDecoraation() const { return use_window_decoration_; } @@ -130,6 +137,8 @@ class FlutterEmbedderOptions { commandline::CommandOptions options_; std::string bundle_path_; + std::string window_title_; + std::string window_app_id_; bool use_mouse_cursor_ = true; bool use_onscreen_keyboard_ = false; bool use_window_decoration_ = false; diff --git a/examples/flutter-drm-eglstream-backend/main.cc b/examples/flutter-drm-eglstream-backend/main.cc index fbc049d6..eb8a6d28 100644 --- a/examples/flutter-drm-eglstream-backend/main.cc +++ b/examples/flutter-drm-eglstream-backend/main.cc @@ -30,6 +30,8 @@ int main(int argc, char** argv) { view_properties.height = options.WindowHeight(); view_properties.view_mode = options.WindowViewMode(); view_properties.view_rotation = options.WindowRotation(); + view_properties.title = options.WindowTitle(); + view_properties.app_id = options.WindowAppID(); view_properties.use_mouse_cursor = options.IsUseMouseCursor(); view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); view_properties.use_window_decoration = options.IsUseWindowDecoraation(); diff --git a/examples/flutter-drm-gbm-backend/flutter_embedder_options.h b/examples/flutter-drm-gbm-backend/flutter_embedder_options.h index cc8193fc..45fd4b32 100644 --- a/examples/flutter-drm-gbm-backend/flutter_embedder_options.h +++ b/examples/flutter-drm-gbm-backend/flutter_embedder_options.h @@ -22,8 +22,8 @@ class FlutterEmbedderOptions { "Window rotation(degree) [0(default)|90|180|270]", 0, false); options_.AddDouble("force-scale-factor", "s", - "Force a scale factor instead using default value", 1.0, - false); + "Force a scale factor instead using default value", 1.0, + false); #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) // no more options. @@ -33,6 +33,9 @@ class FlutterEmbedderOptions { options_.AddInt("width", "w", "Window width", 1280, false); options_.AddInt("height", "h", "Window height", 720, false); #else // FLUTTER_TARGET_BACKEND_WAYLAND + options_.AddString("title", "t", "Window title", "Flutter", false); + options_.AddString("app-id", "a", "XDG App ID", "dev.flutter.elinux", + false); options_.AddWithoutValue("onscreen-keyboard", "k", "Enable on-screen keyboard", false); options_.AddWithoutValue("window-decoration", "d", @@ -53,6 +56,8 @@ class FlutterEmbedderOptions { } bundle_path_ = options_.GetValue("bundle"); + window_title_ = options_.GetValue("title"); + window_app_id_ = options_.GetValue("app-id"); use_mouse_cursor_ = !options_.Exist("no-cursor"); if (options_.Exist("rotation")) { switch (options_.GetValue("rotation")) { @@ -112,6 +117,8 @@ class FlutterEmbedderOptions { } std::string BundlePath() const { return bundle_path_; } + std::string WindowTitle() const { return window_title_; } + std::string WindowAppID() const { return window_app_id_; } bool IsUseMouseCursor() const { return use_mouse_cursor_; } bool IsUseOnscreenKeyboard() const { return use_onscreen_keyboard_; } bool IsUseWindowDecoraation() const { return use_window_decoration_; } @@ -130,6 +137,8 @@ class FlutterEmbedderOptions { commandline::CommandOptions options_; std::string bundle_path_; + std::string window_title_; + std::string window_app_id_; bool use_mouse_cursor_ = true; bool use_onscreen_keyboard_ = false; bool use_window_decoration_ = false; diff --git a/examples/flutter-drm-gbm-backend/main.cc b/examples/flutter-drm-gbm-backend/main.cc index fbc049d6..eb8a6d28 100644 --- a/examples/flutter-drm-gbm-backend/main.cc +++ b/examples/flutter-drm-gbm-backend/main.cc @@ -30,6 +30,8 @@ int main(int argc, char** argv) { view_properties.height = options.WindowHeight(); view_properties.view_mode = options.WindowViewMode(); view_properties.view_rotation = options.WindowRotation(); + view_properties.title = options.WindowTitle(); + view_properties.app_id = options.WindowAppID(); view_properties.use_mouse_cursor = options.IsUseMouseCursor(); view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); view_properties.use_window_decoration = options.IsUseWindowDecoraation(); diff --git a/examples/flutter-external-texture-plugin/flutter_embedder_options.h b/examples/flutter-external-texture-plugin/flutter_embedder_options.h index cc8193fc..45fd4b32 100644 --- a/examples/flutter-external-texture-plugin/flutter_embedder_options.h +++ b/examples/flutter-external-texture-plugin/flutter_embedder_options.h @@ -22,8 +22,8 @@ class FlutterEmbedderOptions { "Window rotation(degree) [0(default)|90|180|270]", 0, false); options_.AddDouble("force-scale-factor", "s", - "Force a scale factor instead using default value", 1.0, - false); + "Force a scale factor instead using default value", 1.0, + false); #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) // no more options. @@ -33,6 +33,9 @@ class FlutterEmbedderOptions { options_.AddInt("width", "w", "Window width", 1280, false); options_.AddInt("height", "h", "Window height", 720, false); #else // FLUTTER_TARGET_BACKEND_WAYLAND + options_.AddString("title", "t", "Window title", "Flutter", false); + options_.AddString("app-id", "a", "XDG App ID", "dev.flutter.elinux", + false); options_.AddWithoutValue("onscreen-keyboard", "k", "Enable on-screen keyboard", false); options_.AddWithoutValue("window-decoration", "d", @@ -53,6 +56,8 @@ class FlutterEmbedderOptions { } bundle_path_ = options_.GetValue("bundle"); + window_title_ = options_.GetValue("title"); + window_app_id_ = options_.GetValue("app-id"); use_mouse_cursor_ = !options_.Exist("no-cursor"); if (options_.Exist("rotation")) { switch (options_.GetValue("rotation")) { @@ -112,6 +117,8 @@ class FlutterEmbedderOptions { } std::string BundlePath() const { return bundle_path_; } + std::string WindowTitle() const { return window_title_; } + std::string WindowAppID() const { return window_app_id_; } bool IsUseMouseCursor() const { return use_mouse_cursor_; } bool IsUseOnscreenKeyboard() const { return use_onscreen_keyboard_; } bool IsUseWindowDecoraation() const { return use_window_decoration_; } @@ -130,6 +137,8 @@ class FlutterEmbedderOptions { commandline::CommandOptions options_; std::string bundle_path_; + std::string window_title_; + std::string window_app_id_; bool use_mouse_cursor_ = true; bool use_onscreen_keyboard_ = false; bool use_window_decoration_ = false; diff --git a/examples/flutter-external-texture-plugin/main.cc b/examples/flutter-external-texture-plugin/main.cc index fbc049d6..eb8a6d28 100644 --- a/examples/flutter-external-texture-plugin/main.cc +++ b/examples/flutter-external-texture-plugin/main.cc @@ -30,6 +30,8 @@ int main(int argc, char** argv) { view_properties.height = options.WindowHeight(); view_properties.view_mode = options.WindowViewMode(); view_properties.view_rotation = options.WindowRotation(); + view_properties.title = options.WindowTitle(); + view_properties.app_id = options.WindowAppID(); view_properties.use_mouse_cursor = options.IsUseMouseCursor(); view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); view_properties.use_window_decoration = options.IsUseWindowDecoraation(); diff --git a/examples/flutter-video-player-plugin/flutter_embedder_options.h b/examples/flutter-video-player-plugin/flutter_embedder_options.h index cc8193fc..45fd4b32 100644 --- a/examples/flutter-video-player-plugin/flutter_embedder_options.h +++ b/examples/flutter-video-player-plugin/flutter_embedder_options.h @@ -22,8 +22,8 @@ class FlutterEmbedderOptions { "Window rotation(degree) [0(default)|90|180|270]", 0, false); options_.AddDouble("force-scale-factor", "s", - "Force a scale factor instead using default value", 1.0, - false); + "Force a scale factor instead using default value", 1.0, + false); #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) // no more options. @@ -33,6 +33,9 @@ class FlutterEmbedderOptions { options_.AddInt("width", "w", "Window width", 1280, false); options_.AddInt("height", "h", "Window height", 720, false); #else // FLUTTER_TARGET_BACKEND_WAYLAND + options_.AddString("title", "t", "Window title", "Flutter", false); + options_.AddString("app-id", "a", "XDG App ID", "dev.flutter.elinux", + false); options_.AddWithoutValue("onscreen-keyboard", "k", "Enable on-screen keyboard", false); options_.AddWithoutValue("window-decoration", "d", @@ -53,6 +56,8 @@ class FlutterEmbedderOptions { } bundle_path_ = options_.GetValue("bundle"); + window_title_ = options_.GetValue("title"); + window_app_id_ = options_.GetValue("app-id"); use_mouse_cursor_ = !options_.Exist("no-cursor"); if (options_.Exist("rotation")) { switch (options_.GetValue("rotation")) { @@ -112,6 +117,8 @@ class FlutterEmbedderOptions { } std::string BundlePath() const { return bundle_path_; } + std::string WindowTitle() const { return window_title_; } + std::string WindowAppID() const { return window_app_id_; } bool IsUseMouseCursor() const { return use_mouse_cursor_; } bool IsUseOnscreenKeyboard() const { return use_onscreen_keyboard_; } bool IsUseWindowDecoraation() const { return use_window_decoration_; } @@ -130,6 +137,8 @@ class FlutterEmbedderOptions { commandline::CommandOptions options_; std::string bundle_path_; + std::string window_title_; + std::string window_app_id_; bool use_mouse_cursor_ = true; bool use_onscreen_keyboard_ = false; bool use_window_decoration_ = false; diff --git a/examples/flutter-video-player-plugin/main.cc b/examples/flutter-video-player-plugin/main.cc index fbc049d6..eb8a6d28 100644 --- a/examples/flutter-video-player-plugin/main.cc +++ b/examples/flutter-video-player-plugin/main.cc @@ -30,6 +30,8 @@ int main(int argc, char** argv) { view_properties.height = options.WindowHeight(); view_properties.view_mode = options.WindowViewMode(); view_properties.view_rotation = options.WindowRotation(); + view_properties.title = options.WindowTitle(); + view_properties.app_id = options.WindowAppID(); view_properties.use_mouse_cursor = options.IsUseMouseCursor(); view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); view_properties.use_window_decoration = options.IsUseWindowDecoraation(); diff --git a/examples/flutter-wayland-client/flutter_embedder_options.h b/examples/flutter-wayland-client/flutter_embedder_options.h index cc8193fc..45fd4b32 100644 --- a/examples/flutter-wayland-client/flutter_embedder_options.h +++ b/examples/flutter-wayland-client/flutter_embedder_options.h @@ -22,8 +22,8 @@ class FlutterEmbedderOptions { "Window rotation(degree) [0(default)|90|180|270]", 0, false); options_.AddDouble("force-scale-factor", "s", - "Force a scale factor instead using default value", 1.0, - false); + "Force a scale factor instead using default value", 1.0, + false); #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) // no more options. @@ -33,6 +33,9 @@ class FlutterEmbedderOptions { options_.AddInt("width", "w", "Window width", 1280, false); options_.AddInt("height", "h", "Window height", 720, false); #else // FLUTTER_TARGET_BACKEND_WAYLAND + options_.AddString("title", "t", "Window title", "Flutter", false); + options_.AddString("app-id", "a", "XDG App ID", "dev.flutter.elinux", + false); options_.AddWithoutValue("onscreen-keyboard", "k", "Enable on-screen keyboard", false); options_.AddWithoutValue("window-decoration", "d", @@ -53,6 +56,8 @@ class FlutterEmbedderOptions { } bundle_path_ = options_.GetValue("bundle"); + window_title_ = options_.GetValue("title"); + window_app_id_ = options_.GetValue("app-id"); use_mouse_cursor_ = !options_.Exist("no-cursor"); if (options_.Exist("rotation")) { switch (options_.GetValue("rotation")) { @@ -112,6 +117,8 @@ class FlutterEmbedderOptions { } std::string BundlePath() const { return bundle_path_; } + std::string WindowTitle() const { return window_title_; } + std::string WindowAppID() const { return window_app_id_; } bool IsUseMouseCursor() const { return use_mouse_cursor_; } bool IsUseOnscreenKeyboard() const { return use_onscreen_keyboard_; } bool IsUseWindowDecoraation() const { return use_window_decoration_; } @@ -130,6 +137,8 @@ class FlutterEmbedderOptions { commandline::CommandOptions options_; std::string bundle_path_; + std::string window_title_; + std::string window_app_id_; bool use_mouse_cursor_ = true; bool use_onscreen_keyboard_ = false; bool use_window_decoration_ = false; diff --git a/examples/flutter-wayland-client/main.cc b/examples/flutter-wayland-client/main.cc index fbc049d6..eb8a6d28 100644 --- a/examples/flutter-wayland-client/main.cc +++ b/examples/flutter-wayland-client/main.cc @@ -30,6 +30,8 @@ int main(int argc, char** argv) { view_properties.height = options.WindowHeight(); view_properties.view_mode = options.WindowViewMode(); view_properties.view_rotation = options.WindowRotation(); + view_properties.title = options.WindowTitle(); + view_properties.app_id = options.WindowAppID(); view_properties.use_mouse_cursor = options.IsUseMouseCursor(); view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); view_properties.use_window_decoration = options.IsUseWindowDecoraation(); diff --git a/examples/flutter-x11-client/flutter_embedder_options.h b/examples/flutter-x11-client/flutter_embedder_options.h index cc8193fc..45fd4b32 100644 --- a/examples/flutter-x11-client/flutter_embedder_options.h +++ b/examples/flutter-x11-client/flutter_embedder_options.h @@ -22,8 +22,8 @@ class FlutterEmbedderOptions { "Window rotation(degree) [0(default)|90|180|270]", 0, false); options_.AddDouble("force-scale-factor", "s", - "Force a scale factor instead using default value", 1.0, - false); + "Force a scale factor instead using default value", 1.0, + false); #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) // no more options. @@ -33,6 +33,9 @@ class FlutterEmbedderOptions { options_.AddInt("width", "w", "Window width", 1280, false); options_.AddInt("height", "h", "Window height", 720, false); #else // FLUTTER_TARGET_BACKEND_WAYLAND + options_.AddString("title", "t", "Window title", "Flutter", false); + options_.AddString("app-id", "a", "XDG App ID", "dev.flutter.elinux", + false); options_.AddWithoutValue("onscreen-keyboard", "k", "Enable on-screen keyboard", false); options_.AddWithoutValue("window-decoration", "d", @@ -53,6 +56,8 @@ class FlutterEmbedderOptions { } bundle_path_ = options_.GetValue("bundle"); + window_title_ = options_.GetValue("title"); + window_app_id_ = options_.GetValue("app-id"); use_mouse_cursor_ = !options_.Exist("no-cursor"); if (options_.Exist("rotation")) { switch (options_.GetValue("rotation")) { @@ -112,6 +117,8 @@ class FlutterEmbedderOptions { } std::string BundlePath() const { return bundle_path_; } + std::string WindowTitle() const { return window_title_; } + std::string WindowAppID() const { return window_app_id_; } bool IsUseMouseCursor() const { return use_mouse_cursor_; } bool IsUseOnscreenKeyboard() const { return use_onscreen_keyboard_; } bool IsUseWindowDecoraation() const { return use_window_decoration_; } @@ -130,6 +137,8 @@ class FlutterEmbedderOptions { commandline::CommandOptions options_; std::string bundle_path_; + std::string window_title_; + std::string window_app_id_; bool use_mouse_cursor_ = true; bool use_onscreen_keyboard_ = false; bool use_window_decoration_ = false; diff --git a/examples/flutter-x11-client/main.cc b/examples/flutter-x11-client/main.cc index fbc049d6..eb8a6d28 100644 --- a/examples/flutter-x11-client/main.cc +++ b/examples/flutter-x11-client/main.cc @@ -30,6 +30,8 @@ int main(int argc, char** argv) { view_properties.height = options.WindowHeight(); view_properties.view_mode = options.WindowViewMode(); view_properties.view_rotation = options.WindowRotation(); + view_properties.title = options.WindowTitle(); + view_properties.app_id = options.WindowAppID(); view_properties.use_mouse_cursor = options.IsUseMouseCursor(); view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); view_properties.use_window_decoration = options.IsUseWindowDecoraation(); diff --git a/src/client_wrapper/flutter_view_controller.cc b/src/client_wrapper/flutter_view_controller.cc index 98fce7ee..8891bc87 100644 --- a/src/client_wrapper/flutter_view_controller.cc +++ b/src/client_wrapper/flutter_view_controller.cc @@ -29,6 +29,12 @@ FlutterViewController::FlutterViewController( (view_properties.view_mode == ViewMode::kFullscreen) ? FlutterDesktopViewMode::kFullscreen : FlutterDesktopViewMode::kNormalscreen; + c_view_properties.title = view_properties.title.has_value() + ? (*view_properties.title).c_str() + : nullptr; + c_view_properties.app_id = view_properties.app_id.has_value() + ? (*view_properties.app_id).c_str() + : nullptr; c_view_properties.use_mouse_cursor = view_properties.use_mouse_cursor; c_view_properties.use_onscreen_keyboard = view_properties.use_onscreen_keyboard; diff --git a/src/client_wrapper/include/flutter/flutter_view_controller.h b/src/client_wrapper/include/flutter/flutter_view_controller.h index b27506ea..64fdad43 100644 --- a/src/client_wrapper/include/flutter/flutter_view_controller.h +++ b/src/client_wrapper/include/flutter/flutter_view_controller.h @@ -9,6 +9,7 @@ #include #include +#include #include "dart_project.h" #include "flutter_engine.h" @@ -58,6 +59,13 @@ class FlutterViewController { // and `height` will be ignored. ViewMode view_mode; + // View title. + std::optional title; + + // View XDG application ID. As a best practice, it is suggested to select an + // app ID that matches the basename of the application's .desktop file. + std::optional app_id; + // Uses mouse cursor. bool use_mouse_cursor; diff --git a/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h b/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h index 22115437..eb3989e5 100644 --- a/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h +++ b/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h @@ -89,6 +89,13 @@ typedef struct { // and `height` will be ignored. FlutterDesktopViewMode view_mode; + // View title. + const char* title; + + // View XDG application ID. As a best practice, it is suggested to select an + // app ID that matches the basename of the application's .desktop file. + const char* app_id; + // Uses mouse cursor. bool use_mouse_cursor; diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc index 106d2a86..d63cc030 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc @@ -1195,7 +1195,12 @@ bool ELinuxWindowWayland::CreateRenderSurface(int32_t width_px, xdg_surface_add_listener(xdg_surface_, &kXdgSurfaceListener, this); xdg_toplevel_ = xdg_surface_get_toplevel(xdg_surface_); - xdg_toplevel_set_title(xdg_toplevel_, "Flutter"); + if (view_properties_.title != nullptr) { + xdg_toplevel_set_title(xdg_toplevel_, view_properties_.title); + } + if (view_properties_.app_id != nullptr) { + xdg_toplevel_set_app_id(xdg_toplevel_, view_properties_.app_id); + } xdg_toplevel_add_listener(xdg_toplevel_, &kXdgToplevelListener, this); wl_surface_set_buffer_scale(native_window_->Surface(), current_scale_); wl_surface_commit(native_window_->Surface()); From cfd702d4885138ffc010adc36a7936c4e295eb8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20H=C4=83loiu?= Date: Tue, 3 Jan 2023 01:28:30 +0200 Subject: [PATCH 041/112] Set decoration button GL viewport to fix resize issues (#317) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Valentin Hăloiu --- .../window/renderer/window_decoration_button.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration_button.cc b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration_button.cc index d7964d8c..a13b8954 100644 --- a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration_button.cc +++ b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decoration_button.cc @@ -21,6 +21,7 @@ struct GlProcs { PFNGLENABLEPROC glEnable; PFNGLCLEARCOLORPROC glClearColor; PFNGLCLEARPROC glClear; + PFNGLVIEWPORTPROC glViewport; PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray; PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer; PFNGLDRAWARRAYSPROC glDrawArrays; @@ -41,6 +42,8 @@ static const GlProcs& GlProcs() { eglGetProcAddress("glClearColor")); procs.glClear = reinterpret_cast(eglGetProcAddress("glClear")); + procs.glViewport = + reinterpret_cast(eglGetProcAddress("glViewport")); procs.glEnableVertexAttribArray = reinterpret_cast( eglGetProcAddress("glEnableVertexAttribArray")); @@ -61,7 +64,7 @@ static const GlProcs& GlProcs() { procs.valid = procs.glEnable && procs.glClearColor && procs.glClear && procs.glEnableVertexAttribArray && procs.glLineWidth && procs.glVertexAttribPointer && procs.glDrawArrays && - procs.glDisableVertexAttribArray && + procs.glDisableVertexAttribArray && procs.glViewport && procs.glBindAttribLocation && procs.glUseProgram; if (!procs.valid) { ELINUX_LOG(ERROR) << "Failed to load GlProcs"; @@ -116,6 +119,7 @@ void WindowDecorationButton::Draw() { { gl.glClearColor(100 / 255.0f, 100 / 255.0f, 100 / 255.0f, 1.0f); gl.glClear(GL_COLOR_BUFFER_BIT); + gl.glViewport(0, 0, native_window_->Width(), native_window_->Height()); { if (!shader_) { LoadShader(); From ad3847b9b85fdc3526b577e3752d0419f19ffc41 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Tue, 3 Jan 2023 11:58:54 +0900 Subject: [PATCH 042/112] Fixed #318 (#319) Fixed #318 Signed-off-by: Hidenori Matsubayashi --- .../flutter-drm-eglstream-backend/flutter_embedder_options.h | 4 ++-- examples/flutter-drm-gbm-backend/flutter_embedder_options.h | 4 ++-- .../flutter_embedder_options.h | 4 ++-- .../flutter-video-player-plugin/flutter_embedder_options.h | 4 ++-- examples/flutter-wayland-client/flutter_embedder_options.h | 4 ++-- examples/flutter-x11-client/flutter_embedder_options.h | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/examples/flutter-drm-eglstream-backend/flutter_embedder_options.h b/examples/flutter-drm-eglstream-backend/flutter_embedder_options.h index 45fd4b32..612b88aa 100644 --- a/examples/flutter-drm-eglstream-backend/flutter_embedder_options.h +++ b/examples/flutter-drm-eglstream-backend/flutter_embedder_options.h @@ -56,8 +56,6 @@ class FlutterEmbedderOptions { } bundle_path_ = options_.GetValue("bundle"); - window_title_ = options_.GetValue("title"); - window_app_id_ = options_.GetValue("app-id"); use_mouse_cursor_ = !options_.Exist("no-cursor"); if (options_.Exist("rotation")) { switch (options_.GetValue("rotation")) { @@ -103,6 +101,8 @@ class FlutterEmbedderOptions { window_width_ = options_.GetValue("width"); window_height_ = options_.GetValue("height"); #else // FLUTTER_TARGET_BACKEND_WAYLAND + window_title_ = options_.GetValue("title"); + window_app_id_ = options_.GetValue("app-id"); use_onscreen_keyboard_ = options_.Exist("onscreen-keyboard"); use_window_decoration_ = options_.Exist("window-decoration"); window_view_mode_ = diff --git a/examples/flutter-drm-gbm-backend/flutter_embedder_options.h b/examples/flutter-drm-gbm-backend/flutter_embedder_options.h index 45fd4b32..612b88aa 100644 --- a/examples/flutter-drm-gbm-backend/flutter_embedder_options.h +++ b/examples/flutter-drm-gbm-backend/flutter_embedder_options.h @@ -56,8 +56,6 @@ class FlutterEmbedderOptions { } bundle_path_ = options_.GetValue("bundle"); - window_title_ = options_.GetValue("title"); - window_app_id_ = options_.GetValue("app-id"); use_mouse_cursor_ = !options_.Exist("no-cursor"); if (options_.Exist("rotation")) { switch (options_.GetValue("rotation")) { @@ -103,6 +101,8 @@ class FlutterEmbedderOptions { window_width_ = options_.GetValue("width"); window_height_ = options_.GetValue("height"); #else // FLUTTER_TARGET_BACKEND_WAYLAND + window_title_ = options_.GetValue("title"); + window_app_id_ = options_.GetValue("app-id"); use_onscreen_keyboard_ = options_.Exist("onscreen-keyboard"); use_window_decoration_ = options_.Exist("window-decoration"); window_view_mode_ = diff --git a/examples/flutter-external-texture-plugin/flutter_embedder_options.h b/examples/flutter-external-texture-plugin/flutter_embedder_options.h index 45fd4b32..612b88aa 100644 --- a/examples/flutter-external-texture-plugin/flutter_embedder_options.h +++ b/examples/flutter-external-texture-plugin/flutter_embedder_options.h @@ -56,8 +56,6 @@ class FlutterEmbedderOptions { } bundle_path_ = options_.GetValue("bundle"); - window_title_ = options_.GetValue("title"); - window_app_id_ = options_.GetValue("app-id"); use_mouse_cursor_ = !options_.Exist("no-cursor"); if (options_.Exist("rotation")) { switch (options_.GetValue("rotation")) { @@ -103,6 +101,8 @@ class FlutterEmbedderOptions { window_width_ = options_.GetValue("width"); window_height_ = options_.GetValue("height"); #else // FLUTTER_TARGET_BACKEND_WAYLAND + window_title_ = options_.GetValue("title"); + window_app_id_ = options_.GetValue("app-id"); use_onscreen_keyboard_ = options_.Exist("onscreen-keyboard"); use_window_decoration_ = options_.Exist("window-decoration"); window_view_mode_ = diff --git a/examples/flutter-video-player-plugin/flutter_embedder_options.h b/examples/flutter-video-player-plugin/flutter_embedder_options.h index 45fd4b32..612b88aa 100644 --- a/examples/flutter-video-player-plugin/flutter_embedder_options.h +++ b/examples/flutter-video-player-plugin/flutter_embedder_options.h @@ -56,8 +56,6 @@ class FlutterEmbedderOptions { } bundle_path_ = options_.GetValue("bundle"); - window_title_ = options_.GetValue("title"); - window_app_id_ = options_.GetValue("app-id"); use_mouse_cursor_ = !options_.Exist("no-cursor"); if (options_.Exist("rotation")) { switch (options_.GetValue("rotation")) { @@ -103,6 +101,8 @@ class FlutterEmbedderOptions { window_width_ = options_.GetValue("width"); window_height_ = options_.GetValue("height"); #else // FLUTTER_TARGET_BACKEND_WAYLAND + window_title_ = options_.GetValue("title"); + window_app_id_ = options_.GetValue("app-id"); use_onscreen_keyboard_ = options_.Exist("onscreen-keyboard"); use_window_decoration_ = options_.Exist("window-decoration"); window_view_mode_ = diff --git a/examples/flutter-wayland-client/flutter_embedder_options.h b/examples/flutter-wayland-client/flutter_embedder_options.h index 45fd4b32..612b88aa 100644 --- a/examples/flutter-wayland-client/flutter_embedder_options.h +++ b/examples/flutter-wayland-client/flutter_embedder_options.h @@ -56,8 +56,6 @@ class FlutterEmbedderOptions { } bundle_path_ = options_.GetValue("bundle"); - window_title_ = options_.GetValue("title"); - window_app_id_ = options_.GetValue("app-id"); use_mouse_cursor_ = !options_.Exist("no-cursor"); if (options_.Exist("rotation")) { switch (options_.GetValue("rotation")) { @@ -103,6 +101,8 @@ class FlutterEmbedderOptions { window_width_ = options_.GetValue("width"); window_height_ = options_.GetValue("height"); #else // FLUTTER_TARGET_BACKEND_WAYLAND + window_title_ = options_.GetValue("title"); + window_app_id_ = options_.GetValue("app-id"); use_onscreen_keyboard_ = options_.Exist("onscreen-keyboard"); use_window_decoration_ = options_.Exist("window-decoration"); window_view_mode_ = diff --git a/examples/flutter-x11-client/flutter_embedder_options.h b/examples/flutter-x11-client/flutter_embedder_options.h index 45fd4b32..612b88aa 100644 --- a/examples/flutter-x11-client/flutter_embedder_options.h +++ b/examples/flutter-x11-client/flutter_embedder_options.h @@ -56,8 +56,6 @@ class FlutterEmbedderOptions { } bundle_path_ = options_.GetValue("bundle"); - window_title_ = options_.GetValue("title"); - window_app_id_ = options_.GetValue("app-id"); use_mouse_cursor_ = !options_.Exist("no-cursor"); if (options_.Exist("rotation")) { switch (options_.GetValue("rotation")) { @@ -103,6 +101,8 @@ class FlutterEmbedderOptions { window_width_ = options_.GetValue("width"); window_height_ = options_.GetValue("height"); #else // FLUTTER_TARGET_BACKEND_WAYLAND + window_title_ = options_.GetValue("title"); + window_app_id_ = options_.GetValue("app-id"); use_onscreen_keyboard_ = options_.Exist("onscreen-keyboard"); use_window_decoration_ = options_.Exist("window-decoration"); window_view_mode_ = From ce3a7f50c14982cfda869d8c84a98bd648c3b6ca Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Tue, 3 Jan 2023 12:57:19 +0900 Subject: [PATCH 043/112] Add x11 window title support (#320) Signed-off-by: Hidenori Matsubayashi --- .../flutter_embedder_options.h | 2 ++ .../flutter-drm-gbm-backend/flutter_embedder_options.h | 2 ++ .../flutter_embedder_options.h | 2 ++ .../flutter-video-player-plugin/flutter_embedder_options.h | 2 ++ examples/flutter-wayland-client/flutter_embedder_options.h | 2 ++ examples/flutter-x11-client/flutter_embedder_options.h | 2 ++ .../platform/linux_embedded/window/elinux_window_x11.cc | 3 ++- .../platform/linux_embedded/window/native_window_x11.cc | 7 +++---- .../platform/linux_embedded/window/native_window_x11.h | 1 + 9 files changed, 18 insertions(+), 5 deletions(-) diff --git a/examples/flutter-drm-eglstream-backend/flutter_embedder_options.h b/examples/flutter-drm-eglstream-backend/flutter_embedder_options.h index 612b88aa..dede8b9e 100644 --- a/examples/flutter-drm-eglstream-backend/flutter_embedder_options.h +++ b/examples/flutter-drm-eglstream-backend/flutter_embedder_options.h @@ -28,6 +28,7 @@ class FlutterEmbedderOptions { defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) // no more options. #elif defined(FLUTTER_TARGET_BACKEND_X11) + options_.AddString("title", "t", "Window title", "Flutter", false); options_.AddWithoutValue("fullscreen", "f", "Always full-screen display", false); options_.AddInt("width", "w", "Window width", 1280, false); @@ -94,6 +95,7 @@ class FlutterEmbedderOptions { #elif defined(FLUTTER_TARGET_BACKEND_X11) use_onscreen_keyboard_ = false; use_window_decoration_ = false; + window_title_ = options_.GetValue("title"); window_view_mode_ = options_.Exist("fullscreen") ? flutter::FlutterViewController::ViewMode::kFullscreen diff --git a/examples/flutter-drm-gbm-backend/flutter_embedder_options.h b/examples/flutter-drm-gbm-backend/flutter_embedder_options.h index 612b88aa..dede8b9e 100644 --- a/examples/flutter-drm-gbm-backend/flutter_embedder_options.h +++ b/examples/flutter-drm-gbm-backend/flutter_embedder_options.h @@ -28,6 +28,7 @@ class FlutterEmbedderOptions { defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) // no more options. #elif defined(FLUTTER_TARGET_BACKEND_X11) + options_.AddString("title", "t", "Window title", "Flutter", false); options_.AddWithoutValue("fullscreen", "f", "Always full-screen display", false); options_.AddInt("width", "w", "Window width", 1280, false); @@ -94,6 +95,7 @@ class FlutterEmbedderOptions { #elif defined(FLUTTER_TARGET_BACKEND_X11) use_onscreen_keyboard_ = false; use_window_decoration_ = false; + window_title_ = options_.GetValue("title"); window_view_mode_ = options_.Exist("fullscreen") ? flutter::FlutterViewController::ViewMode::kFullscreen diff --git a/examples/flutter-external-texture-plugin/flutter_embedder_options.h b/examples/flutter-external-texture-plugin/flutter_embedder_options.h index 612b88aa..dede8b9e 100644 --- a/examples/flutter-external-texture-plugin/flutter_embedder_options.h +++ b/examples/flutter-external-texture-plugin/flutter_embedder_options.h @@ -28,6 +28,7 @@ class FlutterEmbedderOptions { defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) // no more options. #elif defined(FLUTTER_TARGET_BACKEND_X11) + options_.AddString("title", "t", "Window title", "Flutter", false); options_.AddWithoutValue("fullscreen", "f", "Always full-screen display", false); options_.AddInt("width", "w", "Window width", 1280, false); @@ -94,6 +95,7 @@ class FlutterEmbedderOptions { #elif defined(FLUTTER_TARGET_BACKEND_X11) use_onscreen_keyboard_ = false; use_window_decoration_ = false; + window_title_ = options_.GetValue("title"); window_view_mode_ = options_.Exist("fullscreen") ? flutter::FlutterViewController::ViewMode::kFullscreen diff --git a/examples/flutter-video-player-plugin/flutter_embedder_options.h b/examples/flutter-video-player-plugin/flutter_embedder_options.h index 612b88aa..dede8b9e 100644 --- a/examples/flutter-video-player-plugin/flutter_embedder_options.h +++ b/examples/flutter-video-player-plugin/flutter_embedder_options.h @@ -28,6 +28,7 @@ class FlutterEmbedderOptions { defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) // no more options. #elif defined(FLUTTER_TARGET_BACKEND_X11) + options_.AddString("title", "t", "Window title", "Flutter", false); options_.AddWithoutValue("fullscreen", "f", "Always full-screen display", false); options_.AddInt("width", "w", "Window width", 1280, false); @@ -94,6 +95,7 @@ class FlutterEmbedderOptions { #elif defined(FLUTTER_TARGET_BACKEND_X11) use_onscreen_keyboard_ = false; use_window_decoration_ = false; + window_title_ = options_.GetValue("title"); window_view_mode_ = options_.Exist("fullscreen") ? flutter::FlutterViewController::ViewMode::kFullscreen diff --git a/examples/flutter-wayland-client/flutter_embedder_options.h b/examples/flutter-wayland-client/flutter_embedder_options.h index 612b88aa..dede8b9e 100644 --- a/examples/flutter-wayland-client/flutter_embedder_options.h +++ b/examples/flutter-wayland-client/flutter_embedder_options.h @@ -28,6 +28,7 @@ class FlutterEmbedderOptions { defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) // no more options. #elif defined(FLUTTER_TARGET_BACKEND_X11) + options_.AddString("title", "t", "Window title", "Flutter", false); options_.AddWithoutValue("fullscreen", "f", "Always full-screen display", false); options_.AddInt("width", "w", "Window width", 1280, false); @@ -94,6 +95,7 @@ class FlutterEmbedderOptions { #elif defined(FLUTTER_TARGET_BACKEND_X11) use_onscreen_keyboard_ = false; use_window_decoration_ = false; + window_title_ = options_.GetValue("title"); window_view_mode_ = options_.Exist("fullscreen") ? flutter::FlutterViewController::ViewMode::kFullscreen diff --git a/examples/flutter-x11-client/flutter_embedder_options.h b/examples/flutter-x11-client/flutter_embedder_options.h index 612b88aa..dede8b9e 100644 --- a/examples/flutter-x11-client/flutter_embedder_options.h +++ b/examples/flutter-x11-client/flutter_embedder_options.h @@ -28,6 +28,7 @@ class FlutterEmbedderOptions { defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) // no more options. #elif defined(FLUTTER_TARGET_BACKEND_X11) + options_.AddString("title", "t", "Window title", "Flutter", false); options_.AddWithoutValue("fullscreen", "f", "Always full-screen display", false); options_.AddInt("width", "w", "Window width", 1280, false); @@ -94,6 +95,7 @@ class FlutterEmbedderOptions { #elif defined(FLUTTER_TARGET_BACKEND_X11) use_onscreen_keyboard_ = false; use_window_decoration_ = false; + window_title_ = options_.GetValue("title"); window_view_mode_ = options_.Exist("fullscreen") ? flutter::FlutterViewController::ViewMode::kFullscreen diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.cc index 03a52c87..9d52a494 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.cc @@ -129,7 +129,8 @@ bool ELinuxWindowX11::CreateRenderSurface(int32_t width, int32_t height) { std::swap(width, height); } native_window_ = std::make_unique( - display_, context_egl->GetAttrib(EGL_NATIVE_VISUAL_ID), width, height); + display_, context_egl->GetAttrib(EGL_NATIVE_VISUAL_ID), + view_properties_.title, width, height); if (!native_window_->IsValid()) { ELINUX_LOG(ERROR) << "Failed to create the native window"; return false; diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_x11.cc b/src/flutter/shell/platform/linux_embedded/window/native_window_x11.cc index 05374de3..1266b6f0 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_x11.cc +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_x11.cc @@ -16,11 +16,11 @@ namespace flutter { namespace { static constexpr char kWmDeleteWindow[] = "WM_DELETE_WINDOW"; -static constexpr char kWindowTitle[] = "Flutter for Embedded Linux"; } // namespace NativeWindowX11::NativeWindowX11(Display* display, VisualID visual_id, + const char* title, const size_t width, const size_t height) { XVisualInfo visualTemplate; @@ -59,11 +59,10 @@ NativeWindowX11::NativeWindowX11(Display* display, // Set the window title. { XTextProperty property; - property.value = - reinterpret_cast(const_cast(kWindowTitle)); + property.value = reinterpret_cast(const_cast(title)); property.encoding = XA_STRING; property.format = 8; - property.nitems = std::strlen(kWindowTitle); + property.nitems = std::strlen(title); XSetWMName(display, window_, &property); } diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_x11.h b/src/flutter/shell/platform/linux_embedded/window/native_window_x11.h index 03afa8c3..ed39458e 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_x11.h +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_x11.h @@ -15,6 +15,7 @@ class NativeWindowX11 : public NativeWindow { public: NativeWindowX11(Display* display, VisualID visual_id, + const char* title, const size_t width, const size_t height); ~NativeWindowX11() = default; From a03e1861f806e2bb459789d1075fb47eb9f64258 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20H=C4=83loiu?= Date: Thu, 5 Jan 2023 01:04:32 +0200 Subject: [PATCH 044/112] Always respect XDG configure size regardless of state (#321) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous logic was ignoring most of the toplevel configure events unless the window was maximized or was being resized. This pull-request removes that check in order to always respect the size suggested by the compositor. This is particularly important for tiling compositors (e.g.: sway) where the window can be arbitrarily resized by the compositor even when it's not maximized (e.g.: when it's part of a tiled layout). The screen recordings below show some comparison videos of the old and new behavior. Signed-off-by: Valentin Hăloiu --- .../window/elinux_window_wayland.cc | 28 ++----------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc index d63cc030..86eb33ad 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc @@ -91,36 +91,14 @@ const xdg_toplevel_listener ELinuxWindowWayland::kXdgToplevelListener = { int32_t width, int32_t height, wl_array* states) { - auto is_maximized = false; - auto is_resizing = false; - uint32_t* state = static_cast(states->data); - for (auto i = 0; i < states->size; i++) { - switch (*state) { - case XDG_TOPLEVEL_STATE_MAXIMIZED: - is_maximized = true; - break; - case XDG_TOPLEVEL_STATE_RESIZING: - is_resizing = true; - break; - case XDG_TOPLEVEL_STATE_ACTIVATED: - case XDG_TOPLEVEL_STATE_FULLSCREEN: - default: - break; - } - state++; - } - auto self = reinterpret_cast(data); if (self->current_rotation_ == 90 || self->current_rotation_ == 270) { std::swap(width, height); } - int32_t next_width = 0; - int32_t next_height = 0; - if (is_maximized || is_resizing) { - next_width = width; - next_height = height; - } else if (self->restore_window_required_) { + int32_t next_width = width; + int32_t next_height = height; + if (self->restore_window_required_) { self->restore_window_required_ = false; next_width = self->restore_window_width_; next_height = self->restore_window_height_; From 16aac2ca2ba5003a247e8436b9bd67d2d89224c0 Mon Sep 17 00:00:00 2001 From: Makoto Sato <51475851+makotosato-at@users.noreply.github.com> Date: Mon, 6 Feb 2023 13:23:46 +0900 Subject: [PATCH 045/112] Add support EGLImage-based texture (#327) Signed-off-by: Makoto Sato --- AUTHORS | 1 + cmake/build.cmake | 1 + .../client_wrapper/core_implementations.cc | 9 ++ .../include/flutter/texture_registrar.h | 34 ++++++- .../common/public/flutter_texture_registrar.h | 34 ++++++- .../linux_embedded/external_texture.h | 3 + .../external_texture_egl_image.cc | 89 +++++++++++++++++++ .../external_texture_egl_image.h | 54 +++++++++++ .../flutter_elinux_texture_registrar.cc | 16 +++- 9 files changed, 237 insertions(+), 4 deletions(-) create mode 100644 src/flutter/shell/platform/linux_embedded/external_texture_egl_image.cc create mode 100644 src/flutter/shell/platform/linux_embedded/external_texture_egl_image.h diff --git a/AUTHORS b/AUTHORS index 02e75d5d..3a8e080d 100644 --- a/AUTHORS +++ b/AUTHORS @@ -9,3 +9,4 @@ Hidenori Matsubayashi (hidenori.matsubayashi@gmail.com) Andrea Daoud (andreadaoud6@gmail.com) Valentin Hăloiu (valentin.haloiu@gmail.com) FlafyDev +Makoto Sato (makoto.sato@atmark-techno.com) diff --git a/cmake/build.cmake b/cmake/build.cmake index 8ea841a6..42308b4d 100644 --- a/cmake/build.cmake +++ b/cmake/build.cmake @@ -136,6 +136,7 @@ set(ELINUX_COMMON_SRC "src/flutter/shell/platform/linux_embedded/system_utils.cc" "src/flutter/shell/platform/linux_embedded/logger.cc" "src/flutter/shell/platform/linux_embedded/external_texture_pixelbuffer.cc" + "src/flutter/shell/platform/linux_embedded/external_texture_egl_image.cc" "src/flutter/shell/platform/linux_embedded/vsync_waiter.cc" "src/flutter/shell/platform/linux_embedded/flutter_elinux_texture_registrar.cc" "src/flutter/shell/platform/linux_embedded/plugins/keyboard_glfw_util.cc" diff --git a/src/flutter/shell/platform/common/client_wrapper/core_implementations.cc b/src/flutter/shell/platform/common/client_wrapper/core_implementations.cc index e90b26cd..3aae66ca 100644 --- a/src/flutter/shell/platform/common/client_wrapper/core_implementations.cc +++ b/src/flutter/shell/platform/common/client_wrapper/core_implementations.cc @@ -180,6 +180,15 @@ int64_t TextureRegistrarImpl::RegisterTexture(TextureVariant* texture) { auto texture = static_cast(user_data); return texture->ObtainDescriptor(width, height); }; + } else if (auto egl_image_texture = std::get_if(texture)) { + info.type = kFlutterDesktopEGLImageTexture; + info.egl_image_config.user_data = egl_image_texture; + info.egl_image_config.callback = + [](size_t width, size_t height, void* egl_display, void* egl_context, + void* user_data) -> const FlutterDesktopEGLImage* { + auto texture = static_cast(user_data); + return texture->GetEGLImage(width, height, egl_display, egl_context); + }; } else { std::cerr << "Attempting to register unknown texture variant." << std::endl; return -1; diff --git a/src/flutter/shell/platform/common/client_wrapper/include/flutter/texture_registrar.h b/src/flutter/shell/platform/common/client_wrapper/include/flutter/texture_registrar.h index 7a2078f1..4abe19d9 100644 --- a/src/flutter/shell/platform/common/client_wrapper/include/flutter/texture_registrar.h +++ b/src/flutter/shell/platform/common/client_wrapper/include/flutter/texture_registrar.h @@ -42,6 +42,38 @@ class PixelBufferTexture { const CopyBufferCallback copy_buffer_callback_; }; +// A EGLImage texture. +class EGLImageTexture { + public: + // A callback used for retrieving pixel buffers. + typedef std::function + GetEGLImageCallback; + + // Creates a EGLImage texture that uses the provided |get_egl_image_cb| to + // retrieve the EGLImage. + // As the callback is usually invoked from the render thread, the callee must + // take care of proper synchronization. It also needs to be ensured that the + // returned buffer isn't released prior to unregistering this texture. + explicit EGLImageTexture(GetEGLImageCallback get_egl_image_callback) + : get_egl_image_callback_(get_egl_image_callback) {} + + // Returns the callback-provided FlutterDesktopEGLImage. + // The intended surface size is specified by |width| and + // |height|. + const FlutterDesktopEGLImage* GetEGLImage(size_t width, + size_t height, + void* egl_display, + void* egl_context) const { + return get_egl_image_callback_(width, height, egl_display, egl_context); + } + + private: + const GetEGLImageCallback get_egl_image_callback_; +}; + // A GPU surface-based texture. class GpuSurfaceTexture { public: @@ -75,7 +107,7 @@ class GpuSurfaceTexture { // The available texture variants. // Only PixelBufferTexture is currently implemented. // Other variants are expected to be added in the future. -typedef std::variant TextureVariant; +typedef std::variant TextureVariant; // An object keeping track of external textures. // diff --git a/src/flutter/shell/platform/common/public/flutter_texture_registrar.h b/src/flutter/shell/platform/common/public/flutter_texture_registrar.h index 3ca0785e..cc0dbd2d 100644 --- a/src/flutter/shell/platform/common/public/flutter_texture_registrar.h +++ b/src/flutter/shell/platform/common/public/flutter_texture_registrar.h @@ -25,7 +25,9 @@ typedef enum { // A Pixel buffer-based texture. kFlutterDesktopPixelBufferTexture, // A platform-specific GPU surface-backed texture. - kFlutterDesktopGpuSurfaceTexture + kFlutterDesktopGpuSurfaceTexture, + // An EGLImage-based texture + kFlutterDesktopEGLImageTexture } FlutterDesktopTextureType; // Supported GPU surface types. @@ -66,6 +68,20 @@ typedef struct { void* release_context; } FlutterDesktopPixelBuffer; +// An EGLImage object. +typedef struct { + // The EGLImage object.(opaque) + const void* egl_image; + // Width of the EGLImage. + size_t width; + // Height of the EGLImage. + size_t height; + // An optional callback that gets invoked when the |egl_image| can be released. + void (*release_callback)(void* release_context); + // Opaque data passed to |release_callback|. + void* release_context; +} FlutterDesktopEGLImage; + // A GPU surface descriptor. typedef struct { // The size of this struct. Must be @@ -126,6 +142,13 @@ typedef const FlutterDesktopGpuSurfaceDescriptor* ( size_t height, void* user_data); +typedef const FlutterDesktopEGLImage* ( + *FlutterDesktopEGLImageTextureCallback)(size_t width, + size_t height, + void* egl_display, + void* egl_context, + void* user_data); + // An object used to configure pixel buffer textures. typedef struct { // The callback used by the engine to copy the pixel buffer object. @@ -148,11 +171,20 @@ typedef struct { void* user_data; } FlutterDesktopGpuSurfaceTextureConfig; +// An object used to configure EGLImage textures. +typedef struct { + // The callback used by the engine to get the EGLImage object. + FlutterDesktopEGLImageTextureCallback callback; + // Opaque data that will get passed to the provided |callback|. + void* user_data; +} FlutterDesktopEGLImageTextureConfig; + typedef struct { FlutterDesktopTextureType type; union { FlutterDesktopPixelBufferTextureConfig pixel_buffer_config; FlutterDesktopGpuSurfaceTextureConfig gpu_surface_config; + FlutterDesktopEGLImageTextureConfig egl_image_config; }; } FlutterDesktopTextureInfo; diff --git a/src/flutter/shell/platform/linux_embedded/external_texture.h b/src/flutter/shell/platform/linux_embedded/external_texture.h index e6e92c8f..0a4ce93d 100644 --- a/src/flutter/shell/platform/linux_embedded/external_texture.h +++ b/src/flutter/shell/platform/linux_embedded/external_texture.h @@ -29,6 +29,8 @@ typedef void (*glTexImage2DProc)(GLenum target, GLenum format, GLenum type, const void* data); +typedef void (*glEGLImageTargetTexture2DOESProc)(GLenum target, + GLeglImageOES image); // A struct containing pointers to resolved gl* functions. struct GlProcs { @@ -37,6 +39,7 @@ struct GlProcs { glBindTextureProc glBindTexture; glTexParameteriProc glTexParameteri; glTexImage2DProc glTexImage2D; + glEGLImageTargetTexture2DOESProc glEGLImageTargetTexture2DOES; bool valid; }; diff --git a/src/flutter/shell/platform/linux_embedded/external_texture_egl_image.cc b/src/flutter/shell/platform/linux_embedded/external_texture_egl_image.cc new file mode 100644 index 00000000..843b2f98 --- /dev/null +++ b/src/flutter/shell/platform/linux_embedded/external_texture_egl_image.cc @@ -0,0 +1,89 @@ +// 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. + +#include "flutter/shell/platform/linux_embedded/external_texture_egl_image.h" +#include +#include + +namespace flutter { + +struct ExternalTextureEGLImageState { + GLuint gl_texture = 0; +}; + +ExternalTextureEGLImage::ExternalTextureEGLImage( + FlutterDesktopEGLImageTextureCallback texture_callback, + void* user_data, + const GlProcs& gl_procs) + : state_(std::make_unique()), + texture_callback_(texture_callback), + user_data_(user_data), + gl_(gl_procs) {} + +ExternalTextureEGLImage::~ExternalTextureEGLImage() { + if (state_->gl_texture != 0) { + gl_.glDeleteTextures(1, &state_->gl_texture); + } +} + +bool ExternalTextureEGLImage::PopulateTexture( + size_t width, + size_t height, + FlutterOpenGLTexture* opengl_texture) { + if (!GetEGLImage(width, height, eglGetCurrentDisplay(), + eglGetCurrentContext())) { + return false; + } + + // Populate the texture object used by the engine. + opengl_texture->target = GL_TEXTURE_2D; + opengl_texture->name = state_->gl_texture; +#ifdef USE_GLES3 + opengl_texture->format = GL_RGBA8; +#else + opengl_texture->format = GL_RGBA8_OES; +#endif + opengl_texture->destruction_callback = nullptr; + opengl_texture->user_data = nullptr; + opengl_texture->width = width; + opengl_texture->height = height; + + return true; +} + +bool ExternalTextureEGLImage::GetEGLImage(size_t& width, + size_t& height, + void* egl_display, + void* egl_context) { + using namespace std; + + const FlutterDesktopEGLImage* egl_image = + texture_callback_(width, height, egl_display, egl_context, user_data_); + if (!egl_image || !egl_image->egl_image) { + return false; + } + width = egl_image->width; + height = egl_image->height; + + if (state_->gl_texture == 0) { + gl_.glGenTextures(1, &state_->gl_texture); + + gl_.glBindTexture(GL_TEXTURE_2D, state_->gl_texture); + gl_.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + gl_.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + gl_.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + gl_.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + } else { + gl_.glBindTexture(GL_TEXTURE_2D, state_->gl_texture); + } + gl_.glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, + (EGLImageKHR)egl_image->egl_image); + + if (egl_image->release_callback) { + egl_image->release_callback(egl_image->release_context); + } + return true; +} + +} // namespace flutter diff --git a/src/flutter/shell/platform/linux_embedded/external_texture_egl_image.h b/src/flutter/shell/platform/linux_embedded/external_texture_egl_image.h new file mode 100644 index 00000000..7dfaaeb4 --- /dev/null +++ b/src/flutter/shell/platform/linux_embedded/external_texture_egl_image.h @@ -0,0 +1,54 @@ +// 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. + +#ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_EXTERNAL_TEXTURE_EGL_IMAGE_H_ +#define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_EXTERNAL_TEXTURE_EGL_IMAGE_H_ + +#include + +#include + +#include "flutter/shell/platform/common/public/flutter_texture_registrar.h" + +#include "flutter/shell/platform/linux_embedded/external_texture.h" + +namespace flutter { + +typedef struct ExternalTextureEGLImageState ExternalTextureEGLImageState; + +// An abstraction of an EGL Image based texture. +class ExternalTextureEGLImage : public ExternalTexture { + public: + ExternalTextureEGLImage( + FlutterDesktopEGLImageTextureCallback texture_callback, + void* user_data, + const GlProcs& gl_procs); + + virtual ~ExternalTextureEGLImage(); + + // |ExternalTexture| + bool PopulateTexture(size_t width, + size_t height, + FlutterOpenGLTexture* opengl_texture) override; + + private: + // Attempts to get the EGLImage returned by |texture_callback_| to + // OpenGL. + // The |width| and |height| will be set to the actual bounds of the EGLImage + // Returns true on success or false if the EGLImage returned + // by |texture_callback_| was invalid. + bool GetEGLImage(size_t& width, + size_t& height, + void* egl_display, + void* egl_context); + + std::unique_ptr state_; + FlutterDesktopEGLImageTextureCallback texture_callback_ = nullptr; + void* const user_data_ = nullptr; + const GlProcs& gl_; +}; + +} // namespace flutter + +#endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_EXTERNAL_TEXTURE_EGL_IMAGE_H_ diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_texture_registrar.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux_texture_registrar.cc index 29fcbdd9..be4899fe 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_texture_registrar.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_texture_registrar.cc @@ -8,6 +8,7 @@ #include #include "flutter/shell/platform/embedder/embedder_struct_macros.h" +#include "flutter/shell/platform/linux_embedded/external_texture_egl_image.h" #include "flutter/shell/platform/linux_embedded/external_texture_pixelbuffer.h" #include "flutter/shell/platform/linux_embedded/flutter_elinux_engine.h" #include "flutter/shell/platform/linux_embedded/flutter_elinux_view.h" @@ -38,6 +39,15 @@ int64_t FlutterELinuxTextureRegistrar::RegisterTexture( return EmplaceTexture(std::make_unique( texture_info->pixel_buffer_config.callback, texture_info->pixel_buffer_config.user_data, gl_procs_)); + } else if (texture_info->type == kFlutterDesktopEGLImageTexture) { + if (!texture_info->egl_image_config.callback) { + std::cerr << "Invalid EGLImage texture callback." << std::endl; + return kInvalidTexture; + } + + return EmplaceTexture(std::make_unique( + texture_info->egl_image_config.callback, + texture_info->egl_image_config.user_data, gl_procs_)); } else if (texture_info->type == kFlutterDesktopGpuSurfaceTexture) { std::cerr << "GpuSurfaceTexture is not yet supported." << std::endl; return kInvalidTexture; @@ -114,10 +124,12 @@ void FlutterELinuxTextureRegistrar::ResolveGlFunctions(GlProcs& procs) { eglGetProcAddress("glTexParameteri")); procs.glTexImage2D = reinterpret_cast(eglGetProcAddress("glTexImage2D")); - + procs.glEGLImageTargetTexture2DOES = + reinterpret_cast( + eglGetProcAddress("glEGLImageTargetTexture2DOES")); procs.valid = procs.glGenTextures && procs.glDeleteTextures && procs.glBindTexture && procs.glTexParameteri && - procs.glTexImage2D; + procs.glTexImage2D && procs.glEGLImageTargetTexture2DOES; } }; // namespace flutter From c71ea47f50bfa07d6537afdb323e465c03866048 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Sat, 25 Feb 2023 17:58:42 +0900 Subject: [PATCH 046/112] add dirty region management (#331) Fixed #326 Signed-off-by: Hidenori Matsubayashi --- CMakeLists.txt | 1 + cmake/build.cmake | 5 + .../linux_embedded/flutter_elinux_engine.cc | 20 +++ .../linux_embedded/flutter_elinux_view.cc | 9 ++ .../linux_embedded/flutter_elinux_view.h | 3 + .../linux_embedded/surface/egl_utils.cc | 15 +- .../linux_embedded/surface/egl_utils.h | 3 +- .../surface/elinux_egl_surface.cc | 153 +++++++++++++++++- .../surface/elinux_egl_surface.h | 33 +++- .../linux_embedded/surface/surface_base.cc | 4 +- .../surface/surface_decoration.cc | 11 +- .../surface/surface_decoration.h | 9 +- .../linux_embedded/surface/surface_gl.cc | 15 +- .../linux_embedded/surface/surface_gl.h | 9 +- .../surface/surface_gl_delegate.h | 10 +- 15 files changed, 286 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f8384def..8ef7a33a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,7 @@ project("flutter_elinux" LANGUAGES CXX C) # Build options. option(BACKEND_TYPE "Select WAYLAND, DRM-GBM, DRM-EGLSTREAM, or X11 as the display backend type" WAYLAND) +option(USE_DIRTY_REGION_MANAGEMENT "Use Flutter dirty region management" ON) option(USE_GLES3 "Use OpenGL ES3 (default is OpenGL ES2)" OFF) option(ENABLE_EGL_ALPHA_COMPONENT_OF_COLOR_BUFFER "Enable alpha component of the EGL color buffer" ON) option(ENABLE_VSYNC "Enable embedder vsync" OFF) diff --git a/cmake/build.cmake b/cmake/build.cmake index 42308b4d..e97728f1 100644 --- a/cmake/build.cmake +++ b/cmake/build.cmake @@ -81,6 +81,11 @@ else() "src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.cc") endif() +# Use flutter dirty region management +if(USE_DIRTY_REGION_MANAGEMENT) + add_definitions(-DUSE_OPENGL_DIRTY_REGION_MANAGEMENT) +endif() + # OpenGL ES version. if(USE_GLES3) add_definitions(-DUSE_GLES3) diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc index df2c6f8d..87683fa9 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc @@ -42,6 +42,25 @@ FlutterRendererConfig GetRendererConfig() { } return host->view()->ClearCurrent(); }; +#if defined(USE_OPENGL_DIRTY_REGION_MANAGEMENT) + config.open_gl.fbo_reset_after_present = false; + config.open_gl.present_with_info = + [](void* user_data, const FlutterPresentInfo* info) -> bool { + auto host = static_cast(user_data); + if (!host->view()) { + return false; + } + return host->view()->PresentWithInfo(info); + }; + config.open_gl.populate_existing_damage = + [](void* user_data, const intptr_t fbo_id, + FlutterDamage* existing_damage) -> void { + auto host = static_cast(user_data); + if (host->view()) { + host->view()->PopulateExistingDamage(fbo_id, existing_damage); + } + }; +#else config.open_gl.present = [](void* user_data) -> bool { auto host = static_cast(user_data); if (!host->view()) { @@ -49,6 +68,7 @@ FlutterRendererConfig GetRendererConfig() { } return host->view()->Present(); }; +#endif config.open_gl.fbo_callback = [](void* user_data) -> uint32_t { auto host = static_cast(user_data); if (!host->view()) { diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc index 43dfc11e..ce02b388 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc @@ -415,6 +415,15 @@ bool FlutterELinuxView::Present() { return GetRenderSurfaceTarget()->GLContextPresent(0); } +bool FlutterELinuxView::PresentWithInfo(const FlutterPresentInfo* info) { + return GetRenderSurfaceTarget()->GLContextPresentWithInfo(info); +} + +void FlutterELinuxView::PopulateExistingDamage(const intptr_t fbo_id, + FlutterDamage* existing_damage) { + GetRenderSurfaceTarget()->PopulateExistingDamage(fbo_id, existing_damage); +} + uint32_t FlutterELinuxView::GetOnscreenFBO() { return GetRenderSurfaceTarget()->GLContextFBO(); } diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.h b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.h index d335ecbe..c554b497 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.h +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.h @@ -75,6 +75,9 @@ class FlutterELinuxView : public WindowBindingHandlerDelegate { bool MakeCurrent(); bool ClearCurrent(); bool Present(); + bool PresentWithInfo(const FlutterPresentInfo* info); + void PopulateExistingDamage(const intptr_t fbo_id, + FlutterDamage* existing_damage); uint32_t GetOnscreenFBO(); bool MakeResourceCurrent(); diff --git a/src/flutter/shell/platform/linux_embedded/surface/egl_utils.cc b/src/flutter/shell/platform/linux_embedded/surface/egl_utils.cc index 619c51bf..23647bcd 100644 --- a/src/flutter/shell/platform/linux_embedded/surface/egl_utils.cc +++ b/src/flutter/shell/platform/linux_embedded/surface/egl_utils.cc @@ -1,5 +1,5 @@ -// Copyright 2021 Sony Corporation. All rights reserved. +// Copyright 2023 Sony Corporation. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -7,6 +7,7 @@ #include +#include #include #include @@ -40,4 +41,14 @@ std::string get_egl_error_cause() { return nullptr; } -} // namespace flutter \ No newline at end of file +// Auxiliary function used to check if the given list of extensions contains the +// requested extension name. +bool has_egl_extension(const char* extensions, const char* name) { + const char* r = std::strstr(extensions, name); + auto len = std::strlen(name); + + // check that the extension name is terminated by space or null terminator + return r != nullptr && (r[len] == ' ' || r[len] == 0); +} + +} // namespace flutter diff --git a/src/flutter/shell/platform/linux_embedded/surface/egl_utils.h b/src/flutter/shell/platform/linux_embedded/surface/egl_utils.h index a64196df..80692000 100644 --- a/src/flutter/shell/platform/linux_embedded/surface/egl_utils.h +++ b/src/flutter/shell/platform/linux_embedded/surface/egl_utils.h @@ -1,4 +1,4 @@ -// Copyright 2021 Sony Corporation. All rights reserved. +// Copyright 2023 Sony Corporation. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -10,6 +10,7 @@ namespace flutter { std::string get_egl_error_cause(); +bool has_egl_extension(const char* extensions, const char* name); } // namespace flutter diff --git a/src/flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.cc b/src/flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.cc index 8a758174..1e01ca57 100644 --- a/src/flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.cc +++ b/src/flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.cc @@ -1,4 +1,4 @@ -// Copyright 2021 Sony Corporation. All rights reserved. +// Copyright 2023 Sony Corporation. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -9,10 +9,41 @@ namespace flutter { +constexpr size_t kInitialWindowWidthPx = 1280; +constexpr size_t kInitialWindowHeightPx = 720; + +// Maximum damage history - for triple buffering we need to store damage for +// last two frames; Some Android devices (Pixel 4) use quad buffering. +constexpr const int kMaxHistorySize = 10; + ELinuxEGLSurface::ELinuxEGLSurface(EGLSurface surface, EGLDisplay display, EGLContext context) - : surface_(surface), display_(display), context_(context){}; + : surface_(surface), + display_(display), + context_(context), + width_px_(kInitialWindowWidthPx), + height_px_(kInitialWindowHeightPx) { + const char* extensions = eglQueryString(display_, EGL_EXTENSIONS); + + if (has_egl_extension(extensions, "EGL_KHR_partial_update")) { + eglSetDamageRegionKHR_ = reinterpret_cast( + eglGetProcAddress("eglSetDamageRegionKHR")); + } + + if (has_egl_extension(extensions, "EGL_EXT_swap_buffers_with_damage")) { + eglSwapBuffersWithDamageEXT_ = + reinterpret_cast( + eglGetProcAddress("eglSwapBuffersWithDamageEXT")); + } else if (has_egl_extension(extensions, + "EGL_KHR_swap_buffers_with_damage")) { + eglSwapBuffersWithDamageEXT_ = + reinterpret_cast( + eglGetProcAddress("eglSwapBuffersWithDamageKHR")); + } else { + // do nothing. + } +}; ELinuxEGLSurface::~ELinuxEGLSurface() { if (surface_ != EGL_NO_SURFACE) { @@ -28,6 +59,12 @@ bool ELinuxEGLSurface::IsValid() const { return surface_ != EGL_NO_SURFACE; } +void ELinuxEGLSurface::SurfaceResize(const size_t width_px, + const size_t height_px) { + width_px_ = width_px; + height_px_ = height_px; +} + bool ELinuxEGLSurface::MakeCurrent() const { if (eglMakeCurrent(display_, surface_, surface_, context_) != EGL_TRUE) { ELINUX_LOG(ERROR) << "Failed to make the EGL context current: " @@ -54,11 +91,119 @@ bool ELinuxEGLSurface::MakeCurrent() const { bool ELinuxEGLSurface::SwapBuffers() const { if (eglSwapBuffers(display_, surface_) != EGL_TRUE) { - ELINUX_LOG(ERROR) << "Failed to swap the EGL buffer: " - << get_egl_error_cause(); + ELINUX_LOG(ERROR) << "eglSwapBuffers failed: " << get_egl_error_cause(); return false; } return true; } +// Reference of dirty region management: +// https://github.com/flutter/engine/blob/main/examples/glfw_drm/FlutterEmbedderGLFW.cc + +bool ELinuxEGLSurface::SwapBuffers(const FlutterPresentInfo* info) { + // Free the existing damage that was allocated to this frame. + if (existing_damage_map_.find(info->fbo_id) != existing_damage_map_.end() && + existing_damage_map_[info->fbo_id] != nullptr) { + free(existing_damage_map_[info->fbo_id]); + existing_damage_map_[info->fbo_id] = nullptr; + } + + // Set the buffer damage as the damage region. + if (eglSetDamageRegionKHR_) { + auto buffer_rects = RectToInts(info->buffer_damage.damage[0]); + if (eglSetDamageRegionKHR_(display_, surface_, buffer_rects.data(), 1) != + EGL_TRUE) { + ELINUX_LOG(ERROR) << "eglSetDamageRegionKHR failed: " + << get_egl_error_cause(); + return false; + } + } + + // Add frame damage to damage history + damage_history_.push_back(info->frame_damage.damage[0]); + if (damage_history_.size() > kMaxHistorySize) { + damage_history_.pop_front(); + } + + if (eglSwapBuffersWithDamageEXT_) { + auto frame_rects = RectToInts(info->frame_damage.damage[0]); + if (eglSwapBuffersWithDamageEXT_(display_, surface_, frame_rects.data(), + 1) != EGL_TRUE) { + ELINUX_LOG(ERROR) << "eglSwapBuffersWithDamageEXT failed: " + << get_egl_error_cause(); + return false; + } + } else { + // If the required extensions for partial repaint were not provided, do + // full repaint. + if (eglSwapBuffers(display_, surface_) != EGL_TRUE) { + ELINUX_LOG(ERROR) << "eglSwapBuffers failed: " << get_egl_error_cause(); + return false; + } + } + + return true; +} + +void ELinuxEGLSurface::PopulateExistingDamage(const intptr_t fbo_id, + FlutterDamage* existing_damage) { + // Given the FBO age, create existing damage region by joining all frame + // damages since FBO was last used + EGLint age = 0; + if (eglQuerySurface(display_, surface_, EGL_BUFFER_AGE_EXT, &age) != + EGL_TRUE || + age == 0) { + age = 4; // Virtually no driver should have a swapchain length > 4. + } + + existing_damage->num_rects = 1; + + // Allocate the array of rectangles for the existing damage. + existing_damage_map_[fbo_id] = static_cast( + malloc(sizeof(FlutterRect) * existing_damage->num_rects)); + + existing_damage_map_[fbo_id][0] = FlutterRect{ + 0, 0, static_cast(width_px_), static_cast(height_px_)}; + existing_damage->damage = existing_damage_map_[fbo_id]; + + if (age > 1) { + --age; + // join up to (age - 1) last rects from damage history + for (auto i = damage_history_.rbegin(); + i != damage_history_.rend() && age > 0; ++i, --age) { + if (i == damage_history_.rbegin()) { + if (i != damage_history_.rend()) { + existing_damage->damage[0] = {i->left, i->top, i->right, i->bottom}; + } + } else { + // Auxiliary function to union the damage regions comprised by two + // FlutterRect element. It saves the result of this join in the rect + // variable. + FlutterRect* rect = &(existing_damage->damage[0]); + const FlutterRect additional_rect = *i; + + rect->left = std::min(rect->left, additional_rect.left); + rect->top = std::min(rect->top, additional_rect.top); + rect->right = std::max(rect->right, additional_rect.right); + rect->bottom = std::max(rect->bottom, additional_rect.bottom); + } + } + } +} + +// Auxiliary function used to transform a FlutterRect into the format that is +// expected by the EGL functions (i.e. array of EGLint). +std::array ELinuxEGLSurface::RectToInts(const FlutterRect rect) { + EGLint height; + eglQuerySurface(display_, surface_, EGL_HEIGHT, &height); + + std::array res{ + static_cast(rect.left), + height - static_cast(rect.bottom), + static_cast(rect.right) - static_cast(rect.left), + static_cast(rect.bottom) - static_cast(rect.top), + }; + return res; +} + } // namespace flutter diff --git a/src/flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.h b/src/flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.h index 452a7df7..d10b709e 100644 --- a/src/flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.h +++ b/src/flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.h @@ -1,4 +1,4 @@ -// Copyright 2021 Sony Corporation. All rights reserved. +// Copyright 2023 Sony Corporation. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -6,6 +6,13 @@ #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_SURFACE_ELINUX_EGL_SURFACE_H_ #include +#include + +#include +#include +#include + +#include "flutter/shell/platform/embedder/embedder.h" namespace flutter { @@ -17,14 +24,38 @@ class ELinuxEGLSurface { bool IsValid() const; + void SurfaceResize(const size_t width_px, const size_t height_px); + bool MakeCurrent() const; bool SwapBuffers() const; + bool SwapBuffers(const FlutterPresentInfo* info); + + void PopulateExistingDamage(const intptr_t fbo_id, + FlutterDamage* existing_damage); + private: + // Auxiliary function used to transform a FlutterRect into the format that is + // expected by the EGL functions (i.e. array of EGLint). + std::array RectToInts(const FlutterRect rect); + EGLDisplay display_; EGLSurface surface_; EGLContext context_; + + size_t width_px_; + size_t height_px_; + + PFNEGLSETDAMAGEREGIONKHRPROC eglSetDamageRegionKHR_ = nullptr; + PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC eglSwapBuffersWithDamageEXT_ = nullptr; + + // Keeps track of the most recent frame damages so that existing damage can + // be easily computed. + std::list damage_history_; + + // Keeps track of the existing damage associated with each FBO ID + std::unordered_map existing_damage_map_; }; } // namespace flutter diff --git a/src/flutter/shell/platform/linux_embedded/surface/surface_base.cc b/src/flutter/shell/platform/linux_embedded/surface/surface_base.cc index 1067ad57..91ca8a1d 100644 --- a/src/flutter/shell/platform/linux_embedded/surface/surface_base.cc +++ b/src/flutter/shell/platform/linux_embedded/surface/surface_base.cc @@ -1,4 +1,4 @@ -// Copyright 2021 Sony Corporation. All rights reserved. +// Copyright 2023 Sony Corporation. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -31,6 +31,7 @@ bool SurfaceBase::SetNativeWindow(NativeWindow* window) { bool SurfaceBase::OnScreenSurfaceResize(const size_t width_px, const size_t height_px) { + onscreen_surface_->SurfaceResize(width_px, height_px); if (!native_window_->Resize(width_px, height_px)) { ELINUX_LOG(ERROR) << "Failed to resize."; return false; @@ -44,6 +45,7 @@ bool SurfaceBase::OnScreenSurfaceResize(const size_t width_px, onscreen_surface_ = nullptr; return false; } + onscreen_surface_->SurfaceResize(width_px, height_px); } return true; }; diff --git a/src/flutter/shell/platform/linux_embedded/surface/surface_decoration.cc b/src/flutter/shell/platform/linux_embedded/surface/surface_decoration.cc index fb73a275..e33f92f8 100644 --- a/src/flutter/shell/platform/linux_embedded/surface/surface_decoration.cc +++ b/src/flutter/shell/platform/linux_embedded/surface/surface_decoration.cc @@ -1,4 +1,4 @@ -// Copyright 2021 Sony Corporation. All rights reserved. +// Copyright 2023 Sony Corporation. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -62,6 +62,15 @@ bool SurfaceDecoration::GLContextPresent(uint32_t fbo_id) const { return surface_->SwapBuffers(); } +bool SurfaceDecoration::GLContextPresentWithInfo( + const FlutterPresentInfo* info) const { + return true; +} + +void SurfaceDecoration::PopulateExistingDamage( + const intptr_t fbo_id, + FlutterDamage* existing_damage) const {} + uint32_t SurfaceDecoration::GLContextFBO() const { return 0; } diff --git a/src/flutter/shell/platform/linux_embedded/surface/surface_decoration.h b/src/flutter/shell/platform/linux_embedded/surface/surface_decoration.h index 1e44ed89..8c051712 100644 --- a/src/flutter/shell/platform/linux_embedded/surface/surface_decoration.h +++ b/src/flutter/shell/platform/linux_embedded/surface/surface_decoration.h @@ -1,4 +1,4 @@ -// Copyright 2021 Sony Corporation. All rights reserved. +// Copyright 2023 Sony Corporation. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -43,6 +43,13 @@ class SurfaceDecoration : public SurfaceGlDelegate { // |SurfaceGlDelegate| bool GLContextPresent(uint32_t fbo_id) const override; + // |SurfaceGlDelegate| + bool GLContextPresentWithInfo(const FlutterPresentInfo* info) const override; + + // |SurfaceGlDelegate| + void PopulateExistingDamage(const intptr_t fbo_id, + FlutterDamage* existing_damage) const override; + // |SurfaceGlDelegate| uint32_t GLContextFBO() const override; diff --git a/src/flutter/shell/platform/linux_embedded/surface/surface_gl.cc b/src/flutter/shell/platform/linux_embedded/surface/surface_gl.cc index 7467dd84..cdd0eb40 100644 --- a/src/flutter/shell/platform/linux_embedded/surface/surface_gl.cc +++ b/src/flutter/shell/platform/linux_embedded/surface/surface_gl.cc @@ -1,4 +1,4 @@ -// Copyright 2021 Sony Corporation. All rights reserved. +// Copyright 2023 Sony Corporation. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -26,6 +26,19 @@ bool SurfaceGl::GLContextPresent(uint32_t fbo_id) const { return true; } +bool SurfaceGl::GLContextPresentWithInfo(const FlutterPresentInfo* info) const { + if (!onscreen_surface_->SwapBuffers(info)) { + return false; + } + native_window_->SwapBuffers(); + return true; +} + +void SurfaceGl::PopulateExistingDamage(const intptr_t fbo_id, + FlutterDamage* existing_damage) const { + onscreen_surface_->PopulateExistingDamage(fbo_id, existing_damage); +} + uint32_t SurfaceGl::GLContextFBO() const { return 0; } diff --git a/src/flutter/shell/platform/linux_embedded/surface/surface_gl.h b/src/flutter/shell/platform/linux_embedded/surface/surface_gl.h index e6b19997..44dee0bd 100644 --- a/src/flutter/shell/platform/linux_embedded/surface/surface_gl.h +++ b/src/flutter/shell/platform/linux_embedded/surface/surface_gl.h @@ -1,4 +1,4 @@ -// Copyright 2021 Sony Corporation. All rights reserved. +// Copyright 2023 Sony Corporation. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -27,6 +27,13 @@ class SurfaceGl final : public SurfaceBase, public SurfaceGlDelegate { // |SurfaceGlDelegate| bool GLContextPresent(uint32_t fbo_id) const override; + // |SurfaceGlDelegate| + bool GLContextPresentWithInfo(const FlutterPresentInfo* info) const override; + + // |SurfaceGlDelegate| + void PopulateExistingDamage(const intptr_t fbo_id, + FlutterDamage* existing_damage) const override; + // |SurfaceGlDelegate| uint32_t GLContextFBO() const override; diff --git a/src/flutter/shell/platform/linux_embedded/surface/surface_gl_delegate.h b/src/flutter/shell/platform/linux_embedded/surface/surface_gl_delegate.h index 392b277b..709185f7 100644 --- a/src/flutter/shell/platform/linux_embedded/surface/surface_gl_delegate.h +++ b/src/flutter/shell/platform/linux_embedded/surface/surface_gl_delegate.h @@ -1,5 +1,5 @@ -// Copyright 2021 Sony Corporation. All rights reserved. +// Copyright 2023 Sony Corporation. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -8,6 +8,8 @@ #include +#include "flutter/shell/platform/embedder/embedder.h" + namespace flutter { class SurfaceGlDelegate { @@ -18,6 +20,12 @@ class SurfaceGlDelegate { virtual bool GLContextPresent(uint32_t fbo_id) const = 0; + virtual bool GLContextPresentWithInfo( + const FlutterPresentInfo* info) const = 0; + + virtual void PopulateExistingDamage(const intptr_t fbo_id, + FlutterDamage* existing_damage) const = 0; + virtual uint32_t GLContextFBO() const = 0; virtual void* GlProcResolver(const char* name) const = 0; From 9b58e60c789ef81a6cda0eba9b33170e0db98adc Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Tue, 7 Mar 2023 00:21:51 +0900 Subject: [PATCH 047/112] engine: enable fbo_reset_after_present by default (#333) Signed-off-by: Hidenori Matsubayashi --- .../shell/platform/linux_embedded/flutter_elinux_engine.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc index 87683fa9..069ab7e9 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc @@ -42,8 +42,8 @@ FlutterRendererConfig GetRendererConfig() { } return host->view()->ClearCurrent(); }; + config.open_gl.fbo_reset_after_present = true; #if defined(USE_OPENGL_DIRTY_REGION_MANAGEMENT) - config.open_gl.fbo_reset_after_present = false; config.open_gl.present_with_info = [](void* user_data, const FlutterPresentInfo* info) -> bool { auto host = static_cast(user_data); From 393c4e09f56f0f65dcbfa68110147d4846b1f7c6 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Tue, 4 Apr 2023 10:09:24 +0900 Subject: [PATCH 048/112] wayland: fix "xdg_surface has never been configured" error (#336) Fixed #330 Signed-off-by: Hidenori Matsubayashi --- .../window/elinux_window_wayland.cc | 90 ++++++++++--------- .../window/elinux_window_wayland.h | 2 + 2 files changed, 49 insertions(+), 43 deletions(-) diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc index 86eb33ad..55d59f1a 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc @@ -9,8 +9,8 @@ #include #include #include -#include +#include #include #include #include @@ -68,6 +68,8 @@ const xdg_wm_base_listener ELinuxWindowWayland::kXdgWmBaseListener = { const xdg_surface_listener ELinuxWindowWayland::kXdgSurfaceListener = { .configure = [](void* data, xdg_surface* xdg_surface, uint32_t serial) { + ELINUX_LOG(TRACE) << "xdg_surface_listener.configure"; + auto self = reinterpret_cast(data); constexpr int32_t x = 0; int32_t y = 0; @@ -81,6 +83,9 @@ const xdg_surface_listener ELinuxWindowWayland::kXdgSurfaceListener = { self->view_properties_.width, self->view_properties_.height); xdg_surface_ack_configure(xdg_surface, serial); + if (self->wait_for_configure_) { + self->wait_for_configure_ = false; + } }, }; @@ -91,13 +96,17 @@ const xdg_toplevel_listener ELinuxWindowWayland::kXdgToplevelListener = { int32_t width, int32_t height, wl_array* states) { + ELINUX_LOG(TRACE) + << "xdg_toplevel_listener.configure: " << width << ", " << height; + auto self = reinterpret_cast(data); if (self->current_rotation_ == 90 || self->current_rotation_ == 270) { std::swap(width, height); } int32_t next_width = width; - int32_t next_height = height; + int32_t next_height = + height - self->WindowDecorationsPhysicalHeight(); if (self->restore_window_required_) { self->restore_window_required_ = false; next_width = self->restore_window_width_; @@ -112,16 +121,7 @@ const xdg_toplevel_listener ELinuxWindowWayland::kXdgToplevelListener = { self->view_properties_.width = next_width; self->view_properties_.height = next_height; - if (self->window_decorations_) { - self->window_decorations_->Resize(next_width, next_height, - self->current_scale_); - } - if (self->binding_handler_delegate_) { - self->binding_handler_delegate_->OnWindowSizeChanged( - next_width * self->current_scale_, - next_height * self->current_scale_ - - self->WindowDecorationsPhysicalHeight()); - } + self->request_redraw_ = true; }, .close = [](void* data, xdg_toplevel* xdg_toplevel) { @@ -582,17 +582,7 @@ const wl_output_listener ELinuxWindowWayland::kWlOutputListener = { FlutterDesktopViewMode::kFullscreen) { self->view_properties_.width = width; self->view_properties_.height = height; - - if (self->window_decorations_) { - int32_t width_dip = width / self->current_scale_; - int32_t height_dip = height / self->current_scale_; - self->window_decorations_->Resize(width_dip, height_dip, - self->current_scale_); - } - - if (self->binding_handler_delegate_) { - self->binding_handler_delegate_->OnWindowSizeChanged(width, height); - } + self->request_redraw_ = true; } } }, @@ -895,7 +885,6 @@ ELinuxWindowWayland::ELinuxWindowWayland( } wl_registry_add_listener(wl_registry_, &kWlRegistryListener, this); - wl_display_dispatch(wl_display_); wl_display_roundtrip(wl_display_); if (wl_data_device_manager_ && wl_seat_) { @@ -1085,6 +1074,20 @@ bool ELinuxWindowWayland::DispatchEvent() { return false; } + if (request_redraw_) { + request_redraw_ = false; + if (window_decorations_) { + window_decorations_->Resize(view_properties_.width, + view_properties_.height, current_scale_); + } + if (binding_handler_delegate_) { + binding_handler_delegate_->OnWindowSizeChanged( + view_properties_.width * current_scale_, + view_properties_.height * current_scale_ - + WindowDecorationsPhysicalHeight()); + } + } + // Prepare to call wl_display_read_events. while (wl_display_prepare_read(wl_display_) != 0) { // If Wayland compositor terminates, -1 is returned. @@ -1181,7 +1184,6 @@ bool ELinuxWindowWayland::CreateRenderSurface(int32_t width_px, } xdg_toplevel_add_listener(xdg_toplevel_, &kXdgToplevelListener, this); wl_surface_set_buffer_scale(native_window_->Surface(), current_scale_); - wl_surface_commit(native_window_->Surface()); { auto* callback = wl_surface_frame(native_window_->Surface()); @@ -1195,6 +1197,13 @@ bool ELinuxWindowWayland::CreateRenderSurface(int32_t width_px, } } + if (view_properties_.view_mode == FlutterDesktopViewMode::kFullscreen) { + xdg_toplevel_set_fullscreen(xdg_toplevel_, NULL); + } + + wait_for_configure_ = true; + wl_surface_commit(native_window_->Surface()); + render_surface_ = std::make_unique(std::make_unique( std::make_unique(wl_display_))); render_surface_->SetNativeWindow(native_window_.get()); @@ -1207,6 +1216,11 @@ bool ELinuxWindowWayland::CreateRenderSurface(int32_t width_px, native_window_->Surface(), width_dip, height_dip, current_scale_); } + // Wait for making sure that xdg_surface has been configured. + while (wait_for_configure_) { + wl_display_dispatch(wl_display_); + } + return true; } @@ -1575,7 +1589,7 @@ void ELinuxWindowWayland::DismissVirtualKeybaord() { } void ELinuxWindowWayland::UpdateWindowScale() { - if (this->view_properties_.force_scale_factor) + if (view_properties_.force_scale_factor) return; double scale_factor = 1.0; @@ -1589,33 +1603,23 @@ void ELinuxWindowWayland::UpdateWindowScale() { scale_factor = output_scale_factor; } - if (this->current_scale_ == scale_factor) + if (current_scale_ == scale_factor) { return; + } ELINUX_LOG(TRACE) << "Window scale has changed: " << scale_factor; - this->current_scale_ = scale_factor; + current_scale_ = scale_factor; wl_surface_set_buffer_scale(native_window_->Surface(), current_scale_); - - if (this->window_decorations_) { - this->window_decorations_->Resize(this->view_properties_.width, - this->view_properties_.height, - this->current_scale_); - } - - if (this->binding_handler_delegate_) { - this->binding_handler_delegate_->OnWindowSizeChanged( - this->view_properties_.width * this->current_scale_, - this->view_properties_.height * this->current_scale_ - - this->WindowDecorationsPhysicalHeight()); - } + request_redraw_ = true; } uint32_t ELinuxWindowWayland::WindowDecorationsPhysicalHeight() const { - if (!this->window_decorations_) + if (!window_decorations_) { return 0; + } - return this->window_decorations_->Height() * current_scale_; + return window_decorations_->Height() * current_scale_; } } // namespace flutter diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h index 6860adaf..00bf0b09 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h @@ -145,6 +145,8 @@ class ELinuxWindowWayland : public ELinuxWindow, public WindowBindingHandler { bool display_valid_; bool running_; + bool wait_for_configure_ = false; + bool request_redraw_ = false; bool maximised_; uint32_t last_frame_time_; From 43caf24dd4a75a967f04760409bcfa3641deffed Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Wed, 12 Apr 2023 07:05:12 +0900 Subject: [PATCH 049/112] wayland: add window size clipping (#337) Fixed https://github.com/sony/flutter-elinux/issues/176 Signed-off-by: Hidenori Matsubayashi --- .../window/elinux_window_wayland.cc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc index 55d59f1a..8a84022a 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc @@ -584,6 +584,25 @@ const wl_output_listener ELinuxWindowWayland::kWlOutputListener = { self->view_properties_.height = height; self->request_redraw_ = true; } + + if (self->view_properties_.width > width) { + ELINUX_LOG(WARNING) + << "Requested width size(" << self->view_properties_.width << ") " + << "is larger than display size(" << width + << ")" + ", clipping"; + self->view_properties_.width = width; + self->request_redraw_ = true; + } + if (self->view_properties_.height > height) { + ELINUX_LOG(WARNING) << "Requested height size(" + << self->view_properties_.height << ") " + << "is larger than display size(" << height + << ")" + ", clipping"; + self->view_properties_.height = height; + self->request_redraw_ = true; + } } }, .done = [](void* data, wl_output* wl_output) -> void {}, From 3dedfc0b674c1c5b2e9a4ddc0a86542cfd70ba56 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Sat, 29 Apr 2023 22:16:37 +0900 Subject: [PATCH 050/112] embedder: update embedder's header file (#339) Signed-off-by: Hidenori Matsubayashi --- .../shell/platform/embedder/embedder.h | 219 +++++++++++++++--- 1 file changed, 192 insertions(+), 27 deletions(-) diff --git a/src/flutter/shell/platform/embedder/embedder.h b/src/flutter/shell/platform/embedder/embedder.h index 7bef2e52..1710299f 100644 --- a/src/flutter/shell/platform/embedder/embedder.h +++ b/src/flutter/shell/platform/embedder/embedder.h @@ -25,9 +25,16 @@ // - Function signatures (names, argument counts, argument order, and argument // type) cannot change. // - The core behavior of existing functions cannot change. +// - Instead of nesting structures by value within another structure, prefer +// nesting by pointer. This ensures that adding members to the nested struct +// does not break the ABI of the parent struct. +// - Instead of array of structures, prefer array of pointers to structures. +// This ensures that array indexing does not break if members are added +// to the structure. // // These changes are allowed: -// - Adding new struct members at the end of a structure. +// - Adding new struct members at the end of a structure as long as the struct +// is not nested within another struct by value. // - Adding new enum members with a new value. // - Renaming a struct member as long as its type, size, and intent remain the // same. @@ -299,8 +306,8 @@ typedef enum { /// /// - all other formats are called packed formats, and the component order /// as specified in the format name refers to the order in the native type. -/// for example, for kRGB565, the R component uses the 5 least significant -/// bits of the uint16_t pixel value. +/// for example, for kFlutterSoftwarePixelFormatRGB565, the R component +/// uses the 5 least significant bits of the uint16_t pixel value. /// /// Each pixel format in this list is documented with an example on how to get /// the color components from the pixel. @@ -316,30 +323,31 @@ typedef enum { /// pixel with 8 bit grayscale value. /// The grayscale value is the luma value calculated from r, g, b /// according to BT.709. (gray = r*0.2126 + g*0.7152 + b*0.0722) - kGray8, + kFlutterSoftwarePixelFormatGray8, /// pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word. /// r = p & 0x3F; g = (p>>5) & 0x3F; b = p>>11; - kRGB565, + kFlutterSoftwarePixelFormatRGB565, /// pixel with 4 bits for alpha, red, green, blue; in 16-bit word. /// r = p & 0xF; g = (p>>4) & 0xF; b = (p>>8) & 0xF; a = p>>12; - kRGBA4444, + kFlutterSoftwarePixelFormatRGBA4444, /// pixel with 8 bits for red, green, blue, alpha. /// r = p[0]; g = p[1]; b = p[2]; a = p[3]; - kRGBA8888, + kFlutterSoftwarePixelFormatRGBA8888, /// pixel with 8 bits for red, green and blue and 8 unused bits. /// r = p[0]; g = p[1]; b = p[2]; - kRGBX8888, + kFlutterSoftwarePixelFormatRGBX8888, /// pixel with 8 bits for blue, green, red and alpha. /// r = p[2]; g = p[1]; b = p[0]; a = p[3]; - kBGRA8888, + kFlutterSoftwarePixelFormatBGRA8888, - /// either kBGRA8888 or kRGBA8888 depending on CPU endianess and OS - kNative32, + /// either kFlutterSoftwarePixelFormatBGRA8888 or + /// kFlutterSoftwarePixelFormatRGBA8888 depending on CPU endianess and OS + kFlutterSoftwarePixelFormatNative32, } FlutterSoftwarePixelFormat; typedef struct { @@ -448,7 +456,9 @@ typedef struct { /// This information is passed to the embedder when requesting a frame buffer /// object. /// -/// See: \ref FlutterOpenGLRendererConfig.fbo_with_frame_info_callback. +/// See: \ref FlutterOpenGLRendererConfig.fbo_with_frame_info_callback, +/// \ref FlutterMetalRendererConfig.get_next_drawable_callback, +/// and \ref FlutterVulkanRendererConfig.get_next_image_callback. typedef struct { /// The size of this struct. Must be sizeof(FlutterFrameInfo). size_t struct_size; @@ -633,6 +643,8 @@ typedef struct { int64_t texture_id; /// Handle to the MTLTexture that is owned by the embedder. Engine will render /// the frame into this texture. + /// + /// A NULL texture is considered invalid. FlutterMetalTextureHandle texture; /// A baton that is not interpreted by the engine in any way. It will be given /// back to the embedder in the destruction callback below. Embedder resources @@ -826,7 +838,7 @@ typedef enum { /// any other buttons are still pressed when one button is released, that /// should be sent as a kMove rather than a kUp. kUp, - /// The pointer, which must have been been up, is now down. + /// The pointer, which must have been up, is now down. /// /// For touch, this means that the pointer has come into contact with the /// screen. For a mouse, it means a button is now pressed. Note that if any @@ -1032,7 +1044,7 @@ typedef int64_t FlutterPlatformViewIdentifier; /// `FlutterSemanticsNode` ID used as a sentinel to signal the end of a batch of /// semantics node updates. This is unused if using -/// `FlutterUpdateSemanticsCallback`. +/// `FlutterUpdateSemanticsCallback2`. FLUTTER_EXPORT extern const int32_t kFlutterSemanticsNodeIdBatchEnd; @@ -1042,6 +1054,11 @@ extern const int32_t kFlutterSemanticsNodeIdBatchEnd; /// (i.e., during PipelineOwner.flushSemantics), which happens after /// compositing. Updates are then pushed to embedders via the registered /// `FlutterUpdateSemanticsCallback`. +/// +/// @deprecated Use `FlutterSemanticsNode2` instead. In order to preserve +/// ABI compatibility for existing users, no new fields will be +/// added to this struct. New fields will continue to be added +/// to `FlutterSemanticsNode2`. typedef struct { /// The size of this struct. Must be sizeof(FlutterSemanticsNode). size_t struct_size; @@ -1109,9 +1126,84 @@ typedef struct { const char* tooltip; } FlutterSemanticsNode; +/// A node in the Flutter semantics tree. +/// +/// The semantics tree is maintained during the semantics phase of the pipeline +/// (i.e., during PipelineOwner.flushSemantics), which happens after +/// compositing. Updates are then pushed to embedders via the registered +/// `FlutterUpdateSemanticsCallback2`. +/// +/// @see https://api.flutter.dev/flutter/semantics/SemanticsNode-class.html +typedef struct { + /// The size of this struct. Must be sizeof(FlutterSemanticsNode). + size_t struct_size; + /// The unique identifier for this node. + int32_t id; + /// The set of semantics flags associated with this node. + FlutterSemanticsFlag flags; + /// The set of semantics actions applicable to this node. + FlutterSemanticsAction actions; + /// The position at which the text selection originates. + int32_t text_selection_base; + /// The position at which the text selection terminates. + int32_t text_selection_extent; + /// The total number of scrollable children that contribute to semantics. + int32_t scroll_child_count; + /// The index of the first visible semantic child of a scroll node. + int32_t scroll_index; + /// The current scrolling position in logical pixels if the node is + /// scrollable. + double scroll_position; + /// The maximum in-range value for `scrollPosition` if the node is scrollable. + double scroll_extent_max; + /// The minimum in-range value for `scrollPosition` if the node is scrollable. + double scroll_extent_min; + /// The elevation along the z-axis at which the rect of this semantics node is + /// located above its parent. + double elevation; + /// Describes how much space the semantics node takes up along the z-axis. + double thickness; + /// A textual description of the node. + const char* label; + /// A brief description of the result of performing an action on the node. + const char* hint; + /// A textual description of the current value of the node. + const char* value; + /// A value that `value` will have after a kFlutterSemanticsActionIncrease` + /// action has been performed. + const char* increased_value; + /// A value that `value` will have after a kFlutterSemanticsActionDecrease` + /// action has been performed. + const char* decreased_value; + /// The reading direction for `label`, `value`, `hint`, `increasedValue`, + /// `decreasedValue`, and `tooltip`. + FlutterTextDirection text_direction; + /// The bounding box for this node in its coordinate system. + FlutterRect rect; + /// The transform from this node's coordinate system to its parent's + /// coordinate system. + FlutterTransformation transform; + /// The number of children this node has. + size_t child_count; + /// Array of child node IDs in traversal order. Has length `child_count`. + const int32_t* children_in_traversal_order; + /// Array of child node IDs in hit test order. Has length `child_count`. + const int32_t* children_in_hit_test_order; + /// The number of custom accessibility action associated with this node. + size_t custom_accessibility_actions_count; + /// Array of `FlutterSemanticsCustomAction` IDs associated with this node. + /// Has length `custom_accessibility_actions_count`. + const int32_t* custom_accessibility_actions; + /// Identifier of the platform view associated with this semantics node, or + /// -1 if none. + FlutterPlatformViewIdentifier platform_view_id; + /// A textual tooltip attached to the node. + const char* tooltip; +} FlutterSemanticsNode2; + /// `FlutterSemanticsCustomAction` ID used as a sentinel to signal the end of a /// batch of semantics custom action updates. This is unused if using -/// `FlutterUpdateSemanticsCallback`. +/// `FlutterUpdateSemanticsCallback2`. FLUTTER_EXPORT extern const int32_t kFlutterSemanticsCustomActionIdBatchEnd; @@ -1124,6 +1216,11 @@ extern const int32_t kFlutterSemanticsCustomActionIdBatchEnd; /// Action overrides are custom actions that the application developer requests /// to be used in place of the standard actions in the `FlutterSemanticsAction` /// enum. +/// +/// @deprecated Use `FlutterSemanticsCustomAction2` instead. In order to +/// preserve ABI compatility for existing users, no new fields +/// will be added to this struct. New fields will continue to +/// be added to `FlutterSemanticsCustomAction2`. typedef struct { /// The size of the struct. Must be sizeof(FlutterSemanticsCustomAction). size_t struct_size; @@ -1138,7 +1235,37 @@ typedef struct { const char* hint; } FlutterSemanticsCustomAction; +/// A custom semantics action, or action override. +/// +/// Custom actions can be registered by applications in order to provide +/// semantic actions other than the standard actions available through the +/// `FlutterSemanticsAction` enum. +/// +/// Action overrides are custom actions that the application developer requests +/// to be used in place of the standard actions in the `FlutterSemanticsAction` +/// enum. +/// +/// @see +/// https://api.flutter.dev/flutter/semantics/CustomSemanticsAction-class.html +typedef struct { + /// The size of the struct. Must be sizeof(FlutterSemanticsCustomAction). + size_t struct_size; + /// The unique custom action or action override ID. + int32_t id; + /// For overridden standard actions, corresponds to the + /// `FlutterSemanticsAction` to override. + FlutterSemanticsAction override_action; + /// The user-readable name of this custom semantics action. + const char* label; + /// The hint description of this custom semantics action. + const char* hint; +} FlutterSemanticsCustomAction2; + /// A batch of updates to semantics nodes and custom actions. +/// +/// @deprecated Use `FlutterSemanticsUpdate2` instead. Adding members +/// to `FlutterSemanticsNode` or `FlutterSemanticsCustomAction` +/// breaks the ABI of this struct. typedef struct { /// The size of the struct. Must be sizeof(FlutterSemanticsUpdate). size_t struct_size; @@ -1152,6 +1279,21 @@ typedef struct { FlutterSemanticsCustomAction* custom_actions; } FlutterSemanticsUpdate; +/// A batch of updates to semantics nodes and custom actions. +typedef struct { + /// The size of the struct. Must be sizeof(FlutterSemanticsUpdate2). + size_t struct_size; + /// The number of semantics node updates. + size_t node_count; + // Array of semantics node pointers. Has length `node_count`. + FlutterSemanticsNode2** nodes; + /// The number of semantics custom action updates. + size_t custom_action_count; + /// Array of semantics custom action pointers. Has length + /// `custom_action_count`. + FlutterSemanticsCustomAction2** custom_actions; +} FlutterSemanticsUpdate2; + typedef void (*FlutterUpdateSemanticsNodeCallback)( const FlutterSemanticsNode* /* semantics node */, void* /* user data */); @@ -1164,6 +1306,10 @@ typedef void (*FlutterUpdateSemanticsCallback)( const FlutterSemanticsUpdate* /* semantics update */, void* /* user data*/); +typedef void (*FlutterUpdateSemanticsCallback2)( + const FlutterSemanticsUpdate2* /* semantics update */, + void* /* user data*/); + typedef struct _FlutterTaskRunner* FlutterTaskRunner; typedef struct { @@ -1768,9 +1914,11 @@ typedef struct { /// The callback will be invoked on the thread on which the `FlutterEngineRun` /// call is made. /// - /// @deprecated Prefer using `update_semantics_callback` instead. If this - /// calback is provided, `update_semantics_callback` must not - /// be provided. + /// @deprecated Use `update_semantics_callback2` instead. Only one of + /// `update_semantics_node_callback`, + /// `update_semantics_callback`, and + /// `update_semantics_callback2` may be provided; the others + /// should be set to null. FlutterUpdateSemanticsNodeCallback update_semantics_node_callback; /// The legacy callback invoked by the engine in order to give the embedder /// the chance to respond to updates to semantics custom actions from the Dart @@ -1782,9 +1930,11 @@ typedef struct { /// The callback will be invoked on the thread on which the `FlutterEngineRun` /// call is made. /// - /// @deprecated Prefer using `update_semantics_callback` instead. If this - /// calback is provided, `update_semantics_callback` must not - /// be provided. + /// @deprecated Use `update_semantics_callback2` instead. Only one of + /// `update_semantics_node_callback`, + /// `update_semantics_callback`, and + /// `update_semantics_callback2` may be provided; the others + /// should be set to null. FlutterUpdateSemanticsCustomActionCallback update_semantics_custom_action_callback; /// Path to a directory used to store data that is cached across runs of a @@ -1929,9 +2079,24 @@ typedef struct { /// The callback will be invoked on the thread on which the `FlutterEngineRun` /// call is made. /// - /// If this callback is provided, update_semantics_node_callback and - /// update_semantics_custom_action_callback must not be provided. + /// @deprecated Use `update_semantics_callback2` instead. Only one of + /// `update_semantics_node_callback`, + /// `update_semantics_callback`, and + /// `update_semantics_callback2` may be provided; the others + /// must be set to null. FlutterUpdateSemanticsCallback update_semantics_callback; + + /// The callback invoked by the engine in order to give the embedder the + /// chance to respond to updates to semantics nodes and custom actions from + /// the Dart application. + /// + /// The callback will be invoked on the thread on which the `FlutterEngineRun` + /// call is made. + /// + /// Only one of `update_semantics_node_callback`, `update_semantics_callback`, + /// and `update_semantics_callback2` may be provided; the others must be set + /// to null. + FlutterUpdateSemanticsCallback2 update_semantics_callback2; } FlutterProjectArgs; #ifndef FLUTTER_ENGINE_NO_PROTOTYPES @@ -2273,8 +2438,8 @@ FlutterEngineResult FlutterEngineMarkExternalTextureFrameAvailable( /// @param[in] engine A running engine instance. /// @param[in] enabled When enabled, changes to the semantic contents of the /// window are sent via the -/// `FlutterUpdateSemanticsCallback` registered to -/// `update_semantics_callback` in +/// `FlutterUpdateSemanticsCallback2` registered to +/// `update_semantics_callback2` in /// `FlutterProjectArgs`. /// /// @return The result of the call. @@ -2301,7 +2466,7 @@ FlutterEngineResult FlutterEngineUpdateAccessibilityFeatures( /// @brief Dispatch a semantics action to the specified semantics node. /// /// @param[in] engine A running engine instance. -/// @param[in] identifier The semantics action identifier. +/// @param[in] node_id The semantics node identifier. /// @param[in] action The semantics action. /// @param[in] data Data associated with the action. /// @param[in] data_length The data length. @@ -2311,7 +2476,7 @@ FlutterEngineResult FlutterEngineUpdateAccessibilityFeatures( FLUTTER_EXPORT FlutterEngineResult FlutterEngineDispatchSemanticsAction( FLUTTER_API_SYMBOL(FlutterEngine) engine, - uint64_t id, + uint64_t node_id, FlutterSemanticsAction action, const uint8_t* data, size_t data_length); From 048334d81725493da5c3b766a507930c064a1980 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Fri, 16 Jun 2023 09:23:27 +0900 Subject: [PATCH 051/112] readme: remove description related to tested devices (#343) This change moves the description related to tested devices to Wiki. Signed-off-by: Hidenori Matsubayashi --- README.md | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/README.md b/README.md index 85ee9334..cd06c6b8 100644 --- a/README.md +++ b/README.md @@ -40,34 +40,7 @@ We would be grateful if you could give us feedback on bugs and new feature reque Documentation for this software can be found at [Wiki](https://github.com/sony/flutter-embedded-linux/wiki). ## Supported platforms -This embedder supports x64 and Arm64 (aarch64, ARMv8) architectures on Linux which supports either Wayland backend or DRM backend. - -### Tested devices -| Board / SoC | Vendor | OS / BSP | Backend | Status | -| :-------------: | :-------------: | :-------------: | :-------------: | :-------------: | -| [Jetson Nano](https://developer.nvidia.com/embedded/jetson-nano-developer-kit) | NVIDIA | JetPack 4.3 | Wayland | :heavy_check_mark: | -| [Jetson Nano](https://developer.nvidia.com/embedded/jetson-nano-developer-kit) | NVIDIA | JetPack 4.3 | DRM | :heavy_check_mark: ([#1](https://github.com/sony/flutter-embedded-linux/issues/1))| -| [Raspberry Pi 4 Model B](https://www.raspberrypi.org/products/raspberry-pi-4-model-b/) | Raspberry Pi Foundation | Ubuntu 20.10 | Wayland | :heavy_check_mark: | -| [Raspberry Pi 4 Model B](https://www.raspberrypi.org/products/raspberry-pi-4-model-b/) | Raspberry Pi Foundation | Ubuntu 20.10 | DRM | :heavy_check_mark: ([#9](https://github.com/sony/flutter-embedded-linux/issues/9)) | -| [Raspberry Pi 3 Model B](https://www.raspberrypi.com/products/raspberry-pi-3-model-b/) | Raspberry Pi Foundation | Raspberry Pi OS bullseye | Wayland | :heavy_check_mark: | -| [i.MX 8MQuad EVK](https://www.nxp.com/design/development-boards/i-mx-evaluation-and-development-boards/evaluation-kit-for-the-i-mx-8m-applications-processor:MCIMX8M-EVK) | NXP | Sumo (kernel 4.14.98) | Wayland | :heavy_check_mark: | -| [i.MX 8M Mini EVKB](https://www.nxp.com/design/development-boards/i-mx-evaluation-and-development-boards/evaluation-kit-for-the-i-mx-8m-mini-applications-processor:8MMINILPD4-EVK) | NXP | Zeus (kernel 5.4.70) | Wayland | :heavy_check_mark: | -| [RB5 Development Kit](https://developer.qualcomm.com/qualcomm-robotics-rb5-kit) | Qualcomm | Ubuntu 18.04.05 | DRM | :heavy_check_mark: | -| Zynq | Xilinx | - | - | Not tested | -| Desktop (x86_64) | Intel | Ubuntu 20.04 | Wayland | :heavy_check_mark: | -| Desktop (x86_64) | Intel | Ubuntu 20.04 | DRM | :heavy_check_mark: | -| Desktop (x86_64) | Intel | Ubuntu 20.04 | X11 | :heavy_check_mark: | -| QEMU (x86_64) | QEMU | [AGL (Automotive Grade Linux)](https://wiki.automotivelinux.org/) koi | Wayland | :heavy_check_mark: | -| QEMU (x86_64) | QEMU | [AGL (Automotive Grade Linux)](https://wiki.automotivelinux.org/) koi | DRM | :heavy_check_mark: | - -Note - - i.MX 8M platforms don't support applications using EGL on GBM, which means the DRM-GBM backend won't work on i.MX 8M devices. - -### Tested Wayland compositors -||||||||||| -| :-: | :-: | :-: | :-: | :-: | :-: | :-: | :-: | :-: | :-: | -[Weston](https://gitlab.freedesktop.org/wayland/weston/-/blob/master/README.md) | :heavy_check_mark: | [Sway](https://swaywm.org/) | :heavy_check_mark: | [Wayfire](https://wayfire.org/) | :heavy_check_mark: | [Gnome](https://www.gnome.org/) | :heavy_check_mark: | [Phosh](https://source.puri.sm/Librem5/phosh) | :heavy_check_mark: | -| [Cage](https://www.hjdskes.nl/projects/cage/) | :heavy_check_mark: | [Lomiri](https://lomiri.com/) | :heavy_check_mark: | [Plasma Wayland](https://community.kde.org/Plasma/Wayland) | :heavy_check_mark: | [Plasma Mobile](https://www.plasma-mobile.org/) | :heavy_check_mark: | [GlacierUX](https://wiki.merproject.org/wiki/Nemo/Glacier) | :heavy_check_mark: | +This embedder supports x64 and Arm64 (aarch64, ARMv8) architectures on Linux which supports either Wayland backend or DRM backend. See [Support status](https://github.com/sony/flutter-elinux/wiki/Support-status) for details. ## Contributing **Now, we cannot accept any Pull Request (PR).** Because We are building a system (e.g. CLA) to accept PRs, so please wait for a while the system is getting ready! However, we are always welcome to report bugs and request new features by creating issues. From cff33ca5aaabf5adf5e4cb965ea743c9e5ab7043 Mon Sep 17 00:00:00 2001 From: t123yh Date: Tue, 20 Jun 2023 10:46:26 +0800 Subject: [PATCH 052/112] Enhancements to initialization code in drm backend (#344) * Check if drm_crtc is nullptr before attempting to set mode In native_window_drm, there's no check against null drm_crtc. So if drm_crtc is null, and SwapBuffers() is called, a Segmentation Fault will occur. This adds check against it. Signed-off-by: Yunhao Tian * Add logic to initialize drm encoder and crtc In RK3399 board, when the system just booted up, there's no encoder attached to connector, and no crtc attached to encoder. In this case drm backend will fail to get an encoder. This commit adds code to find suitable encoder and crtc from resources, when absent. Signed-off-by: Yunhao Tian * Add myself to AUTHORS --------- Signed-off-by: Yunhao Tian --- AUTHORS | 1 + .../window/native_window_drm.cc | 55 +++++++++++++++++-- .../window/native_window_drm_gbm.cc | 12 ++-- 3 files changed, 58 insertions(+), 10 deletions(-) diff --git a/AUTHORS b/AUTHORS index 3a8e080d..34746af2 100644 --- a/AUTHORS +++ b/AUTHORS @@ -10,3 +10,4 @@ Andrea Daoud (andreadaoud6@gmail.com) Valentin Hăloiu (valentin.haloiu@gmail.com) FlafyDev Makoto Sato (makoto.sato@atmark-techno.com) +Yunhao Tian (t123yh@outlook.com) diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_drm.cc b/src/flutter/shell/platform/linux_embedded/window/native_window_drm.cc index 1f57165c..22e6e7d9 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_drm.cc +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_drm.cc @@ -77,8 +77,18 @@ bool NativeWindowDrm::ConfigureDisplay(const uint16_t rotation) { drmModeFreeResources(resources); return false; } - if (encoder->crtc_id) { - drm_crtc_ = drmModeGetCrtc(drm_device_, encoder->crtc_id); + if (!encoder->crtc_id) { + // if there is no current CRTC, make sure to attach a suitable one + for (int c = 0; c < resources->count_crtcs; c++) { + if (encoder->possible_crtcs & (1 << c)) { + encoder->crtc_id = resources->crtcs[c]; + break; + } + } + } + drm_crtc_ = drmModeGetCrtc(drm_device_, encoder->crtc_id); + if (!drm_crtc_) { + ELINUX_LOG(WARNING) << "Couldn't find a suitable crtc"; } drmModeFreeEncoder(encoder); @@ -103,11 +113,44 @@ drmModeConnectorPtr NativeWindowDrm::FindConnector(drmModeResPtr resources) { drmModeEncoder* NativeWindowDrm::FindEncoder(drmModeRes* resources, drmModeConnector* connector) { - if (connector->encoder_id) { - return drmModeGetEncoder(drm_device_, connector->encoder_id); + drmModeEncoder* encoder = nullptr; + // Find a suitable encoder + for (int e = 0; e < resources->count_encoders; e++) { + bool found = false; + encoder = drmModeGetEncoder(drm_device_, resources->encoders[e]); + for (int ce = 0; ce < connector->count_encoders; ce++) { + if (encoder && encoder->encoder_id == connector->encoders[ce]) { + ELINUX_LOG(DEBUG) << "Using encoder id " << encoder->encoder_id; + found = true; + break; + } + } + if (found) + break; + drmModeFreeEncoder(encoder); + encoder = nullptr; } - // no encoder found - return nullptr; + + // If encoder is not connected to the connector, + // try to find a suitable one + if (!encoder) { + for (int e = 0; e < connector->count_encoders; e++) { + encoder = drmModeGetEncoder(drm_device_, connector->encoders[e]); + for (int c = 0; c < resources->count_crtcs; c++) { + if (encoder->possible_crtcs & (1 << c)) { + encoder->crtc_id = resources->crtcs[c]; + break; + } + } + if (encoder->crtc_id) + break; + drmModeFreeEncoder(encoder); + encoder = nullptr; + } + } + + // Will return nullptr if a suitable encoder is still not found + return encoder; } const uint32_t* NativeWindowDrm::GetCursorData(const std::string& cursor_name) { diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_drm_gbm.cc b/src/flutter/shell/platform/linux_embedded/window/native_window_drm_gbm.cc index 3effb666..8c342c00 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_drm_gbm.cc +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_drm_gbm.cc @@ -175,10 +175,14 @@ void NativeWindowDrmGbm::SwapBuffers() { if (result != 0) { ELINUX_LOG(ERROR) << "Failed to add a framebuffer. (" << result << ")"; } - result = drmModeSetCrtc(drm_device_, drm_crtc_->crtc_id, fb, 0, 0, - &drm_connector_id_, 1, &drm_mode_info_); - if (result != 0) { - ELINUX_LOG(ERROR) << "Failed to set crct mode. (" << result << ")"; + if (!drm_crtc_) { + ELINUX_LOG(ERROR) << "crtc is null, cannot set mode."; + } else { + result = drmModeSetCrtc(drm_device_, drm_crtc_->crtc_id, fb, 0, 0, + &drm_connector_id_, 1, &drm_mode_info_); + if (result != 0) { + ELINUX_LOG(ERROR) << "Failed to set crct mode. (" << result << ")"; + } } if (gbm_previous_bo_) { From 23a83396202fd349cdbe222bfe53b42f09d73393 Mon Sep 17 00:00:00 2001 From: Luke Howard Date: Mon, 17 Jul 2023 08:53:46 +0200 Subject: [PATCH 053/112] embedder: don't use reference params in C APIs (#345) (#346) flutter_elinux.h is a C API, so reference parameters are unavailable. Change FlutterDesktopViewControllerCreate() and FlutterDesktopEngineCreate() to instead take a pointer. Based fix for upstream issue (flutter/engine#25439). Developer's Certificate of Origin 1.1 By making a contribution to this project, I certify that: (a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or (b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or (c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it. (d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved. --- AUTHORS | 1 + src/client_wrapper/flutter_engine.cc | 2 +- src/client_wrapper/flutter_view_controller.cc | 2 +- .../platform/linux_embedded/flutter_elinux.cc | 14 +++++++------- .../linux_embedded/public/flutter_elinux.h | 4 ++-- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/AUTHORS b/AUTHORS index 34746af2..1812758d 100644 --- a/AUTHORS +++ b/AUTHORS @@ -11,3 +11,4 @@ Valentin Hăloiu (valentin.haloiu@gmail.com) FlafyDev Makoto Sato (makoto.sato@atmark-techno.com) Yunhao Tian (t123yh@outlook.com) +Luke Howard diff --git a/src/client_wrapper/flutter_engine.cc b/src/client_wrapper/flutter_engine.cc index a1fc0c46..4cf26678 100644 --- a/src/client_wrapper/flutter_engine.cc +++ b/src/client_wrapper/flutter_engine.cc @@ -30,7 +30,7 @@ FlutterEngine::FlutterEngine(const DartProject& project) { c_engine_properties.dart_entrypoint_argv = entrypoint_argv.size() > 0 ? entrypoint_argv.data() : nullptr; - engine_ = FlutterDesktopEngineCreate(c_engine_properties); + engine_ = FlutterDesktopEngineCreate(&c_engine_properties); auto core_messenger = FlutterDesktopEngineGetMessenger(engine_); messenger_ = std::make_unique(core_messenger); diff --git a/src/client_wrapper/flutter_view_controller.cc b/src/client_wrapper/flutter_view_controller.cc index 8891bc87..3d9b7ea8 100644 --- a/src/client_wrapper/flutter_view_controller.cc +++ b/src/client_wrapper/flutter_view_controller.cc @@ -43,7 +43,7 @@ FlutterViewController::FlutterViewController( c_view_properties.force_scale_factor = view_properties.force_scale_factor; c_view_properties.scale_factor = view_properties.scale_factor; - controller_ = FlutterDesktopViewControllerCreate(c_view_properties, + controller_ = FlutterDesktopViewControllerCreate(&c_view_properties, engine_->RelinquishEngine()); if (!controller_) { std::cerr << "Failed to create view controller." << std::endl; diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux.cc index 1279155b..1ac196b7 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux.cc @@ -72,21 +72,21 @@ uint64_t FlutterDesktopEngineProcessMessages(FlutterDesktopEngineRef engine) { } FlutterDesktopViewControllerRef FlutterDesktopViewControllerCreate( - const FlutterDesktopViewProperties& view_properties, + const FlutterDesktopViewProperties* view_properties, FlutterDesktopEngineRef engine) { std::unique_ptr window_wrapper = #if defined(DISPLAY_BACKEND_TYPE_DRM_GBM) std::make_unique>( - view_properties); + *view_properties); #elif defined(DISPLAY_BACKEND_TYPE_DRM_EGLSTREAM) std::make_unique< flutter::ELinuxWindowDrm>( - view_properties); + *view_properties); #elif defined(DISPLAY_BACKEND_TYPE_X11) - std::make_unique(view_properties); + std::make_unique(*view_properties); #else - std::make_unique(view_properties); + std::make_unique(*view_properties); #endif auto state = std::make_unique(); @@ -134,8 +134,8 @@ int32_t FlutterDesktopViewGetFrameRate(FlutterDesktopViewRef view) { } FlutterDesktopEngineRef FlutterDesktopEngineCreate( - const FlutterDesktopEngineProperties& engine_properties) { - flutter::FlutterProjectBundle project(engine_properties); + const FlutterDesktopEngineProperties* engine_properties) { + flutter::FlutterProjectBundle project(*engine_properties); auto engine = std::make_unique(project); return HandleForEngine(engine.release()); } diff --git a/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h b/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h index eb3989e5..d97d5fa0 100644 --- a/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h +++ b/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h @@ -128,7 +128,7 @@ typedef struct { // an error. FLUTTER_EXPORT FlutterDesktopViewControllerRef FlutterDesktopViewControllerCreate( - const FlutterDesktopViewProperties& view_properties, + const FlutterDesktopViewProperties* view_properties, FlutterDesktopEngineRef engine); // Shuts down the engine instance associated with |controller|, and cleans up @@ -161,7 +161,7 @@ FlutterDesktopViewGetFrameRate(FlutterDesktopViewRef view); // The caller owns the returned reference, and is responsible for calling // FlutterDesktopEngineDestroy. FLUTTER_EXPORT FlutterDesktopEngineRef FlutterDesktopEngineCreate( - const FlutterDesktopEngineProperties& engine_properties); + const FlutterDesktopEngineProperties* engine_properties); // Shuts down and destroys the given engine instance. Returns true if the // shutdown was successful, or if the engine was not running. From 5c86492e74ab7130778656f7763550121254036e Mon Sep 17 00:00:00 2001 From: Luke Howard Date: Mon, 17 Jul 2023 13:21:37 +0200 Subject: [PATCH 054/112] embedder: locking and refcount support in FlutterDesktopMessenger (#347) Import locking and reference counting support for FlutterDesktopMessenger from upstream (#345) --- .../common/public/flutter_messenger.h | 47 ++++++++++++++++ .../platform/linux_embedded/flutter_elinux.cc | 35 ++++++++++-- .../linux_embedded/flutter_elinux_engine.cc | 6 +- .../linux_embedded/flutter_elinux_engine.h | 7 ++- .../linux_embedded/flutter_elinux_state.h | 56 ++++++++++++++++++- 5 files changed, 140 insertions(+), 11 deletions(-) diff --git a/src/flutter/shell/platform/common/public/flutter_messenger.h b/src/flutter/shell/platform/common/public/flutter_messenger.h index 854ff985..87c33beb 100644 --- a/src/flutter/shell/platform/common/public/flutter_messenger.h +++ b/src/flutter/shell/platform/common/public/flutter_messenger.h @@ -87,6 +87,53 @@ FLUTTER_EXPORT void FlutterDesktopMessengerSetCallback( FlutterDesktopMessageCallback callback, void* user_data); +// Increments the reference count for the |messenger|. +// +// Operation is thread-safe. +// +// See also: |FlutterDesktopMessengerRelease| +FLUTTER_EXPORT FlutterDesktopMessengerRef +FlutterDesktopMessengerAddRef(FlutterDesktopMessengerRef messenger); + +// Decrements the reference count for the |messenger|. +// +// Operation is thread-safe. +// +// See also: |FlutterDesktopMessengerAddRef| +FLUTTER_EXPORT void FlutterDesktopMessengerRelease( + FlutterDesktopMessengerRef messenger); + +// Returns `true` if the |FlutterDesktopMessengerRef| still references a running +// engine. +// +// This check should be made inside of a |FlutterDesktopMessengerLock| and +// before any other calls are made to the FlutterDesktopMessengerRef when using +// it from a thread other than the platform thread. +FLUTTER_EXPORT bool FlutterDesktopMessengerIsAvailable( + FlutterDesktopMessengerRef messenger); + +// Locks the `FlutterDesktopMessengerRef` ensuring that +// |FlutterDesktopMessengerIsAvailable| does not change while locked. +// +// All calls to the FlutterDesktopMessengerRef from threads other than the +// platform thread should happen inside of a lock. +// +// Operation is thread-safe. +// +// Returns the |messenger| value. +// +// See also: |FlutterDesktopMessengerUnlock| +FLUTTER_EXPORT FlutterDesktopMessengerRef +FlutterDesktopMessengerLock(FlutterDesktopMessengerRef messenger); + +// Unlocks the `FlutterDesktopMessengerRef`. +// +// Operation is thread-safe. +// +// See also: |FlutterDesktopMessengerLock| +FLUTTER_EXPORT void FlutterDesktopMessengerUnlock( + FlutterDesktopMessengerRef messenger); + #if defined(__cplusplus) } // extern "C" #endif diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux.cc index 1ac196b7..990a2cdc 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux.cc @@ -204,8 +204,8 @@ bool FlutterDesktopMessengerSendWithReply(FlutterDesktopMessengerRef messenger, const size_t message_size, const FlutterDesktopBinaryReply reply, void* user_data) { - return messenger->engine->SendPlatformMessage(channel, message, message_size, - reply, user_data); + return messenger->GetEngine()->SendPlatformMessage( + channel, message, message_size, reply, user_data); } bool FlutterDesktopMessengerSend(FlutterDesktopMessengerRef messenger, @@ -221,15 +221,40 @@ void FlutterDesktopMessengerSendResponse( const FlutterDesktopMessageResponseHandle* handle, const uint8_t* data, size_t data_length) { - messenger->engine->SendPlatformMessageResponse(handle, data, data_length); + messenger->GetEngine()->SendPlatformMessageResponse(handle, data, + data_length); } void FlutterDesktopMessengerSetCallback(FlutterDesktopMessengerRef messenger, const char* channel, FlutterDesktopMessageCallback callback, void* user_data) { - messenger->engine->message_dispatcher()->SetMessageCallback(channel, callback, - user_data); + messenger->GetEngine()->message_dispatcher()->SetMessageCallback( + channel, callback, user_data); +} + +FlutterDesktopMessengerRef FlutterDesktopMessengerAddRef( + FlutterDesktopMessengerRef messenger) { + messenger->AddRef(); + return messenger; +} + +void FlutterDesktopMessengerRelease(FlutterDesktopMessengerRef messenger) { + messenger->Release(); +} + +bool FlutterDesktopMessengerIsAvailable(FlutterDesktopMessengerRef messenger) { + return messenger->GetEngine() != nullptr; +} + +FlutterDesktopMessengerRef FlutterDesktopMessengerLock( + FlutterDesktopMessengerRef messenger) { + messenger->GetMutex().lock(); + return messenger; +} + +void FlutterDesktopMessengerUnlock(FlutterDesktopMessengerRef messenger) { + messenger->GetMutex().unlock(); } FlutterDesktopTextureRegistrarRef FlutterDesktopRegistrarGetTextureRegistrar( diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc index 069ab7e9..c0ef315c 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc @@ -143,8 +143,10 @@ FlutterELinuxEngine::FlutterELinuxEngine(const FlutterProjectBundle& project) }); // Set up the legacy structs backing the API handles. - messenger_ = std::make_unique(); - messenger_->engine = this; + messenger_ = FlutterDesktopMessengerReferenceOwner( + FlutterDesktopMessengerAddRef(new FlutterDesktopMessenger()), + &FlutterDesktopMessengerRelease); + messenger_->SetEngine(this); plugin_registrar_ = std::make_unique(); plugin_registrar_->engine = this; diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h index 83de54d2..11283307 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h @@ -27,6 +27,10 @@ namespace flutter { class FlutterELinuxView; +using FlutterDesktopMessengerReferenceOwner = + std::unique_ptr; + class FlutterELinuxEngine { public: explicit FlutterELinuxEngine(const FlutterProjectBundle& project); @@ -144,7 +148,8 @@ class FlutterELinuxEngine { std::unique_ptr task_runner_; // The plugin messenger handle given to API clients. - std::unique_ptr messenger_; + FlutterDesktopMessengerReferenceOwner messenger_ = { + nullptr, [](FlutterDesktopMessengerRef ref) {}}; // A wrapper around messenger_ for interacting with client_wrapper-level APIs. std::unique_ptr messenger_wrapper_; diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_state.h b/src/flutter/shell/platform/linux_embedded/flutter_elinux_state.h index 92a9d582..8248f7e8 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_state.h +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_state.h @@ -5,7 +5,15 @@ #ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_FLUTTER_ELINUX_STATE_H_ #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_FLUTTER_ELINUX_STATE_H_ +#include #include +#include + +#if __has_include() +#include +#else +#define SWIFT_SHARED_REFERENCE(_retain, _release) +#endif #include "flutter/shell/platform/common/client_wrapper/include/flutter/plugin_registrar.h" #include "flutter/shell/platform/common/incoming_message_dispatcher.h" @@ -38,8 +46,50 @@ struct FlutterDesktopPluginRegistrar { // Wrapper to distinguish the messenger ref from the engine ref given out // in the C API. struct FlutterDesktopMessenger { - // The engine that owns this state object. - flutter::FlutterELinuxEngine* engine = nullptr; -}; + FlutterDesktopMessenger() = default; + + /// Increments the reference count. + /// + /// Thread-safe. + void AddRef() { ref_count_.fetch_add(1); } + + /// Decrements the reference count and deletes the object if the count has + /// gone to zero. + /// + /// Thread-safe. + void Release() { + int32_t old_count = ref_count_.fetch_sub(1); + if (old_count <= 1) { + delete this; + } + } + + /// Getter for the engine field. + flutter::FlutterELinuxEngine* GetEngine() const { return engine_; } + + /// Setter for the engine field. + /// Thread-safe. + void SetEngine(flutter::FlutterELinuxEngine* engine) { + std::scoped_lock lock(mutex_); + engine_ = engine; + } + + /// Returns the mutex associated with the |FlutterDesktopMessenger|. + /// + /// This mutex is used to synchronize reading or writing state inside the + /// |FlutterDesktopMessenger| (ie |engine_|). + std::mutex& GetMutex() { return mutex_; } + + FlutterDesktopMessenger(const FlutterDesktopMessenger& value) = delete; + FlutterDesktopMessenger& operator=(const FlutterDesktopMessenger& value) = + delete; + + private: + // The engine that backs this messenger. + flutter::FlutterELinuxEngine* engine_; + std::atomic ref_count_ = 0; + std::mutex mutex_; +} SWIFT_SHARED_REFERENCE(FlutterDesktopMessengerAddRef, + FlutterDesktopMessengerRelease); #endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_FLUTTER_ELINUX_STATE_H_ From 05b0377d52662a33d53370f745e2f127d4ec0248 Mon Sep 17 00:00:00 2001 From: Makoto Sato <51475851+makotosato-at@users.noreply.github.com> Date: Wed, 2 Aug 2023 17:56:13 +0900 Subject: [PATCH 055/112] wayland: fix fullscreen not working on Wayland (#351) Signed-off-by: Makoto Sato --- .../platform/linux_embedded/window/elinux_window_wayland.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc index 8a84022a..64b72e4e 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc @@ -86,6 +86,7 @@ const xdg_surface_listener ELinuxWindowWayland::kXdgSurfaceListener = { if (self->wait_for_configure_) { self->wait_for_configure_ = false; } + self->request_redraw_ = true; }, }; From 22fe98d26fade7503b0c6b793fd93c4432474604 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Fri, 4 Aug 2023 08:58:50 +0000 Subject: [PATCH 056/112] embedder: update embedder's header file (#353) Merged from https://github.com/flutter/engine/commit/b0d97ba45f46c95a1328cd7b4c8787a62638aeea Signed-off-by: Hidenori Matsubayashi --- .../shell/platform/embedder/embedder.h | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/flutter/shell/platform/embedder/embedder.h b/src/flutter/shell/platform/embedder/embedder.h index 1710299f..a1e9036b 100644 --- a/src/flutter/shell/platform/embedder/embedder.h +++ b/src/flutter/shell/platform/embedder/embedder.h @@ -236,6 +236,11 @@ typedef enum { kFlutterSemanticsFlagIsKeyboardKey = 1 << 24, /// Whether the semantics node represents a tristate checkbox in mixed state. kFlutterSemanticsFlagIsCheckStateMixed = 1 << 25, + /// The semantics node has the quality of either being "expanded" or + /// "collapsed". + kFlutterSemanticsFlagHasExpandedState = 1 << 26, + /// Whether a semantic node that hasExpandedState is currently expanded. + kFlutterSemanticsFlagIsExpanded = 1 << 27, } FlutterSemanticsFlag; typedef enum { @@ -676,9 +681,13 @@ typedef struct { FlutterMetalCommandQueueHandle present_command_queue; /// The callback that gets invoked when the engine requests the embedder for a /// texture to render to. + /// + /// Not used if a FlutterCompositor is supplied in FlutterProjectArgs. FlutterMetalTextureCallback get_next_drawable_callback; /// The callback presented to the embedder to present a fully populated metal /// texture to the user. + /// + /// Not used if a FlutterCompositor is supplied in FlutterProjectArgs. FlutterMetalPresentCallback present_drawable_callback; /// When the embedder specifies that a texture has a frame available, the /// engine will call this method (on an internal engine managed thread) so @@ -805,6 +814,11 @@ typedef struct { }; } FlutterRendererConfig; +/// Display refers to a graphics hardware system consisting of a framebuffer, +/// typically a monitor or a screen. This ID is unique per display and is +/// stable until the Flutter application restarts. +typedef uint64_t FlutterEngineDisplayId; + typedef struct { /// The size of this struct. Must be sizeof(FlutterWindowMetricsEvent). size_t struct_size; @@ -826,6 +840,8 @@ typedef struct { double physical_view_inset_bottom; /// Left inset of window. double physical_view_inset_left; + /// The identifier of the display the view is rendering on. + FlutterEngineDisplayId display_id; } FlutterWindowMetricsEvent; /// The phase of the pointer event. @@ -1653,11 +1669,6 @@ typedef const FlutterLocale* (*FlutterComputePlatformResolvedLocaleCallback)( const FlutterLocale** /* supported_locales*/, size_t /* Number of locales*/); -/// Display refers to a graphics hardware system consisting of a framebuffer, -/// typically a monitor or a screen. This ID is unique per display and is -/// stable until the Flutter application restarts. -typedef uint64_t FlutterEngineDisplayId; - typedef struct { /// This size of this struct. Must be sizeof(FlutterDisplay). size_t struct_size; @@ -1673,6 +1684,16 @@ typedef struct { /// This represents the refresh period in frames per second. This value may be /// zero if the device is not running or unavailable or unknown. double refresh_rate; + + /// The width of the display, in physical pixels. + size_t width; + + /// The height of the display, in physical pixels. + size_t height; + + /// The pixel ratio of the display, which is used to convert physical pixels + /// to logical pixels. + double device_pixel_ratio; } FlutterEngineDisplay; /// The update type parameter that is passed to From a17214315034cd0dceda828fd1bc0ba24c2ec013 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Fri, 4 Aug 2023 09:16:18 +0000 Subject: [PATCH 057/112] elinux: fix missing FlutterDesktopPluginRegistrarGetView() header (#354) Fixed #348 Signed-off-by: Hidenori Matsubayashi --- .../shell/platform/linux_embedded/public/flutter_elinux.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h b/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h index d97d5fa0..5693f095 100644 --- a/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h +++ b/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h @@ -200,6 +200,10 @@ FLUTTER_EXPORT FlutterDesktopPluginRegistrarRef FlutterDesktopEngineGetPluginRegistrar(FlutterDesktopEngineRef engine, const char* plugin_name); +// Returns the view associated with this registrar's engine instance. +FLUTTER_EXPORT FlutterDesktopViewRef FlutterDesktopPluginRegistrarGetView( + FlutterDesktopPluginRegistrarRef registrar); + // Returns the messenger associated with the engine. FLUTTER_EXPORT FlutterDesktopMessengerRef FlutterDesktopEngineGetMessenger(FlutterDesktopEngineRef engine); From 9f08f4ce8d0c0e3ff21c581404919a78e7ee3f26 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Fri, 4 Aug 2023 12:28:45 +0000 Subject: [PATCH 058/112] impeller: add impeller initial implementation (#355) Signed-off-by: Hidenori Matsubayashi --- .../shell/platform/common/engine_switches.cc | 2 - .../platform/linux_embedded/flutter_elinux.cc | 5 +- .../linux_embedded/flutter_elinux_engine.cc | 10 ++++ .../linux_embedded/flutter_elinux_engine.h | 8 +++ .../linux_embedded/flutter_elinux_view.cc | 5 +- .../linux_embedded/flutter_project_bundle.cc | 17 +++++- .../linux_embedded/flutter_project_bundle.h | 6 ++ .../linux_embedded/surface/context_egl.cc | 57 +++++++++++++++++-- .../linux_embedded/surface/context_egl.h | 1 + .../linux_embedded/window/elinux_window_drm.h | 8 ++- .../window/elinux_window_wayland.cc | 10 ++-- .../window/elinux_window_wayland.h | 6 +- .../window/elinux_window_x11.cc | 10 ++-- .../linux_embedded/window/elinux_window_x11.h | 6 +- .../linux_embedded/window/native_window_drm.h | 5 +- .../window/native_window_drm_eglstream.cc | 5 +- .../window/native_window_drm_eglstream.h | 4 +- .../window/native_window_drm_gbm.cc | 7 ++- .../window/native_window_drm_gbm.h | 4 +- .../renderer/window_decorations_wayland.cc | 15 +++-- .../renderer/window_decorations_wayland.h | 3 +- .../linux_embedded/window_binding_handler.h | 9 ++- 22 files changed, 155 insertions(+), 48 deletions(-) diff --git a/src/flutter/shell/platform/common/engine_switches.cc b/src/flutter/shell/platform/common/engine_switches.cc index 5c750f13..37b98fae 100644 --- a/src/flutter/shell/platform/common/engine_switches.cc +++ b/src/flutter/shell/platform/common/engine_switches.cc @@ -16,7 +16,6 @@ std::vector GetSwitchesFromEnvironment() { // Read engine switches from the environment in debug/profile. If release mode // support is needed in the future, it should likely use a whitelist. #ifndef FLUTTER_RELEASE -#ifndef WINUWP const char* switch_count_key = "FLUTTER_ENGINE_SWITCHES"; const int kMaxSwitchCount = 50; const char* switch_count_string = std::getenv(switch_count_key); @@ -37,7 +36,6 @@ std::vector GetSwitchesFromEnvironment() { << ", but " << switch_key.str() << " is missing." << std::endl; } } -#endif // !WINUWP #endif // !FLUTTER_RELEASE return switches; } diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux.cc index 990a2cdc..99313f2d 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux.cc @@ -92,13 +92,10 @@ FlutterDesktopViewControllerRef FlutterDesktopViewControllerCreate( auto state = std::make_unique(); state->view = std::make_unique(std::move(window_wrapper)); - if (!state->view->CreateRenderSurface()) { - return nullptr; - } - // Take ownership of the engine, starting it if necessary. state->view->SetEngine( std::unique_ptr(EngineFromHandle(engine))); + state->view->CreateRenderSurface(); if (!state->view->GetEngine()->running()) { if (!state->view->GetEngine()->RunWithEntrypoint(nullptr)) { return nullptr; diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc index c0ef315c..d081cdfb 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc @@ -142,6 +142,11 @@ FlutterELinuxEngine::FlutterELinuxEngine(const FlutterProjectBundle& project) } }); + // Check for impeller support. + auto& switches = project_->GetSwitches(); + enable_impeller_ = std::find(switches.begin(), switches.end(), + "--enable-impeller=true") != switches.end(); + // Set up the legacy structs backing the API handles. messenger_ = FlutterDesktopMessengerReferenceOwner( FlutterDesktopMessengerAddRef(new FlutterDesktopMessenger()), @@ -173,6 +178,11 @@ FlutterELinuxEngine::~FlutterELinuxEngine() { Stop(); } +void FlutterELinuxEngine::SetSwitches( + const std::vector& switches) { + project_->SetSwitches(switches); +} + bool FlutterELinuxEngine::RunWithEntrypoint(const char* entrypoint) { if (!project_->HasValidPaths()) { ELINUX_LOG(ERROR) << "Missing or unresolvable paths to assets."; diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h index 11283307..e6595262 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h @@ -68,6 +68,9 @@ class FlutterELinuxEngine { void SetPluginRegistrarDestructionCallback( FlutterDesktopOnPluginRegistrarDestroyed callback); + // Sets switches member to the given switches. + void SetSwitches(const std::vector& switches); + FlutterDesktopMessengerRef messenger() { return messenger_.get(); } IncomingMessageDispatcher* message_dispatcher() { @@ -121,6 +124,9 @@ class FlutterELinuxEngine { void OnVsync(uint64_t last_frame_time_nanos, uint64_t vsync_interval_time_nanos); + // Gets the status whether Impeller is enabled. + bool IsImpellerEnabled() const { return enable_impeller_; } + private: // Allows swapping out embedder_api_ calls in tests. friend class EngineEmbedderApiModifier; @@ -176,6 +182,8 @@ class FlutterELinuxEngine { // The vsync waiter. std::unique_ptr vsync_waiter_; + + bool enable_impeller_ = false; }; } // namespace flutter diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc index ce02b388..131d114c 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc @@ -434,7 +434,10 @@ bool FlutterELinuxView::MakeResourceCurrent() { bool FlutterELinuxView::CreateRenderSurface() { PhysicalWindowBounds bounds = binding_handler_->GetPhysicalWindowBounds(); - return binding_handler_->CreateRenderSurface(bounds.width, bounds.height); + auto impeller_enable = engine_.get()->IsImpellerEnabled(); + std::cout << "impeller: " << impeller_enable << std::endl; + return binding_handler_->CreateRenderSurface(bounds.width, bounds.height, + impeller_enable); } void FlutterELinuxView::DestroyRenderSurface() { diff --git a/src/flutter/shell/platform/linux_embedded/flutter_project_bundle.cc b/src/flutter/shell/platform/linux_embedded/flutter_project_bundle.cc index bd974261..31681244 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_project_bundle.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_project_bundle.cc @@ -85,8 +85,23 @@ UniqueAotDataPtr FlutterProjectBundle::LoadAotData( return UniqueAotDataPtr(data); } +void FlutterProjectBundle::SetSwitches( + const std::vector& switches) { + engine_switches_ = switches; +} + const std::vector FlutterProjectBundle::GetSwitches() { - return GetSwitchesFromEnvironment(); + if (engine_switches_.size() == 0) { + return GetSwitchesFromEnvironment(); + } + std::vector switches; + switches.insert(switches.end(), engine_switches_.begin(), + engine_switches_.end()); + + auto env_switches = GetSwitchesFromEnvironment(); + switches.insert(switches.end(), env_switches.begin(), env_switches.end()); + + return switches; } const std::string FlutterProjectBundle::GetExecutableDirectory() { diff --git a/src/flutter/shell/platform/linux_embedded/flutter_project_bundle.h b/src/flutter/shell/platform/linux_embedded/flutter_project_bundle.h index fdec398d..503fcd38 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_project_bundle.h +++ b/src/flutter/shell/platform/linux_embedded/flutter_project_bundle.h @@ -45,6 +45,9 @@ class FlutterProjectBundle { // Returns any switches that should be passed to the engine. const std::vector GetSwitches(); + // Sets engine switches. + void SetSwitches(const std::vector& switches); + // Attempts to load AOT data for this bundle. The returned data must be // retained until any engine instance it is passed to has been shut down. // @@ -69,6 +72,9 @@ class FlutterProjectBundle { // Dart entrypoint arguments. std::vector dart_entrypoint_arguments_; + + // Engine switches. + std::vector engine_switches_; }; } // namespace flutter diff --git a/src/flutter/shell/platform/linux_embedded/surface/context_egl.cc b/src/flutter/shell/platform/linux_embedded/surface/context_egl.cc index f723bd57..bea6dbb4 100644 --- a/src/flutter/shell/platform/linux_embedded/surface/context_egl.cc +++ b/src/flutter/shell/platform/linux_embedded/surface/context_egl.cc @@ -10,6 +10,7 @@ namespace flutter { ContextEgl::ContextEgl(std::unique_ptr environment, + bool enable_impeller, EGLint egl_surface_type) : environment_(std::move(environment)), config_(nullptr) { EGLint config_count = 0; @@ -28,11 +29,57 @@ ContextEgl::ContextEgl(std::unique_ptr environment, EGL_NONE // clang-format on }; - if (eglChooseConfig(environment_->Display(), attribs, &config_, 1, - &config_count) != EGL_TRUE) { - ELINUX_LOG(ERROR) << "Failed to choose EGL surface config: " - << get_egl_error_cause(); - return; + const EGLint impeller_config_attributes[] = { + // clang-format off + EGL_RED_SIZE, 8, + EGL_GREEN_SIZE, 8, + EGL_BLUE_SIZE, 8, +#if defined(ENABLE_EGL_ALPHA_COMPONENT_OF_COLOR_BUFFER) + EGL_ALPHA_SIZE, 8, +#endif + EGL_DEPTH_SIZE, 0, + EGL_STENCIL_SIZE, 8, + EGL_SAMPLE_BUFFERS, 1, + EGL_SAMPLES, 4, + EGL_NONE + // clang-format on + }; + const EGLint impeller_config_attributes_no_msaa[] = { + // clang-format off + EGL_RED_SIZE, 8, + EGL_GREEN_SIZE, 8, + EGL_BLUE_SIZE, 8, +#if defined(ENABLE_EGL_ALPHA_COMPONENT_OF_COLOR_BUFFER) + EGL_ALPHA_SIZE, 8, +#endif + EGL_DEPTH_SIZE, 0, + EGL_STENCIL_SIZE, 8, + EGL_NONE + // clang-format on + }; + + if (enable_impeller) { + // First try the MSAA configuration. + if ((eglChooseConfig(environment_->Display(), impeller_config_attributes, + &config_, 1, &config_count) == EGL_FALSE) || + (config_count == 0)) { + // Next fall back to disabled MSAA. + if ((eglChooseConfig(environment_->Display(), + impeller_config_attributes_no_msaa, &config_, 1, + &config_count) == EGL_FALSE) || + (config_count == 0)) { + ELINUX_LOG(ERROR) << "Failed to choose EGL surface config: " + << get_egl_error_cause(); + return; + } + } + } else { + if (eglChooseConfig(environment_->Display(), attribs, &config_, 1, + &config_count) != EGL_TRUE) { + ELINUX_LOG(ERROR) << "Failed to choose EGL surface config: " + << get_egl_error_cause(); + return; + } } if (config_count == 0 || config_ == nullptr) { diff --git a/src/flutter/shell/platform/linux_embedded/surface/context_egl.h b/src/flutter/shell/platform/linux_embedded/surface/context_egl.h index b443e191..4950a816 100644 --- a/src/flutter/shell/platform/linux_embedded/surface/context_egl.h +++ b/src/flutter/shell/platform/linux_embedded/surface/context_egl.h @@ -18,6 +18,7 @@ namespace flutter { class ContextEgl { public: ContextEgl(std::unique_ptr environment, + bool enable_impeller, EGLint egl_surface_type = EGL_WINDOW_BIT); ~ContextEgl() = default; diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h b/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h index e9e5edcc..beaec990 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h @@ -1,4 +1,4 @@ -// Copyright 2021 Sony Corporation. All rights reserved. +// Copyright 2023 Sony Corporation. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -109,7 +109,9 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { } // |FlutterWindowBindingHandler| - bool CreateRenderSurface(int32_t width, int32_t height) override { + bool CreateRenderSurface(int32_t width, + int32_t height, + bool enable_impeller) override { std::vector devices; auto device_filename = std::getenv(kFlutterDrmDeviceEnvironmentKey); if (device_filename && device_filename[0] != '\0') { @@ -148,7 +150,7 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { display_valid_ = true; - render_surface_ = native_window_->CreateRenderSurface(); + render_surface_ = native_window_->CreateRenderSurface(enable_impeller); if (!render_surface_->SetNativeWindow(native_window_.get())) { return false; } diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc index 64b72e4e..2e684e56 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc @@ -1,4 +1,4 @@ -// Copyright 2021 Sony Corporation. All rights reserved. +// Copyright 2023 Sony Corporation. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -1147,7 +1147,8 @@ bool ELinuxWindowWayland::DispatchEvent() { } bool ELinuxWindowWayland::CreateRenderSurface(int32_t width_px, - int32_t height_px) { + int32_t height_px, + bool enable_impeller) { if (!display_valid_) { ELINUX_LOG(ERROR) << "Wayland display is invalid."; return false; @@ -1225,7 +1226,7 @@ bool ELinuxWindowWayland::CreateRenderSurface(int32_t width_px, wl_surface_commit(native_window_->Surface()); render_surface_ = std::make_unique(std::make_unique( - std::make_unique(wl_display_))); + std::make_unique(wl_display_), enable_impeller)); render_surface_->SetNativeWindow(native_window_.get()); if (view_properties_.use_window_decoration) { @@ -1233,7 +1234,8 @@ bool ELinuxWindowWayland::CreateRenderSurface(int32_t width_px, int32_t height_dip = height_px / current_scale_; window_decorations_ = std::make_unique( wl_display_, wl_compositor_, wl_subcompositor_, - native_window_->Surface(), width_dip, height_dip, current_scale_); + native_window_->Surface(), width_dip, height_dip, current_scale_, + enable_impeller); } // Wait for making sure that xdg_surface has been configured. diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h index 00bf0b09..fad7dc1d 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h @@ -1,4 +1,4 @@ -// Copyright 2021 Sony Corporation. All rights reserved. +// Copyright 2023 Sony Corporation. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -45,7 +45,9 @@ class ELinuxWindowWayland : public ELinuxWindow, public WindowBindingHandler { bool DispatchEvent() override; // |FlutterWindowBindingHandler| - bool CreateRenderSurface(int32_t width_px, int32_t height_px) override; + bool CreateRenderSurface(int32_t width_px, + int32_t height_px, + bool enable_impeller) override; // |FlutterWindowBindingHandler| void DestroyRenderSurface() override; diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.cc index 9d52a494..15ede0d4 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.cc @@ -1,4 +1,4 @@ -// Copyright 2021 Sony Corporation. All rights reserved. +// Copyright 2023 Sony Corporation. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -121,9 +121,11 @@ bool ELinuxWindowX11::DispatchEvent() { return true; } -bool ELinuxWindowX11::CreateRenderSurface(int32_t width, int32_t height) { - auto context_egl = - std::make_unique(std::make_unique(display_)); +bool ELinuxWindowX11::CreateRenderSurface(int32_t width, + int32_t height, + bool enable_impeller) { + auto context_egl = std::make_unique( + std::make_unique(display_), enable_impeller); if (current_rotation_ == 90 || current_rotation_ == 270) { std::swap(width, height); diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.h b/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.h index 80683534..9d364526 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.h +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.h @@ -1,4 +1,4 @@ -// Copyright 2021 Sony Corporation. All rights reserved. +// Copyright 2023 Sony Corporation. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -26,7 +26,9 @@ class ELinuxWindowX11 : public ELinuxWindow, public WindowBindingHandler { bool DispatchEvent() override; // |FlutterWindowBindingHandler| - bool CreateRenderSurface(int32_t width, int32_t height) override; + bool CreateRenderSurface(int32_t width, + int32_t height, + bool enable_impeller) override; // |FlutterWindowBindingHandler| void DestroyRenderSurface() override; diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_drm.h b/src/flutter/shell/platform/linux_embedded/window/native_window_drm.h index 6259f6aa..9a40b100 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_drm.h +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_drm.h @@ -1,4 +1,4 @@ -// Copyright 2021 Sony Corporation. All rights reserved. +// Copyright 2023 Sony Corporation. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -31,7 +31,8 @@ class NativeWindowDrm : public NativeWindow { virtual bool DismissCursor() = 0; - virtual std::unique_ptr CreateRenderSurface() = 0; + virtual std::unique_ptr CreateRenderSurface( + bool enable_impeller) = 0; protected: drmModeConnectorPtr FindConnector(drmModeResPtr resources); diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_drm_eglstream.cc b/src/flutter/shell/platform/linux_embedded/window/native_window_drm_eglstream.cc index a78fd033..97242219 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_drm_eglstream.cc +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_drm_eglstream.cc @@ -1,4 +1,4 @@ -// Copyright 2021 Sony Corporation. All rights reserved. +// Copyright 2023 Sony Corporation. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -91,7 +91,8 @@ bool NativeWindowDrmEglstream::DismissCursor() { return true; } -std::unique_ptr NativeWindowDrmEglstream::CreateRenderSurface() { +std::unique_ptr NativeWindowDrmEglstream::CreateRenderSurface( + bool enable_impeller) { return std::make_unique(std::make_unique( std::make_unique())); } diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_drm_eglstream.h b/src/flutter/shell/platform/linux_embedded/window/native_window_drm_eglstream.h index f3e469d5..27561a61 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_drm_eglstream.h +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_drm_eglstream.h @@ -1,4 +1,4 @@ -// Copyright 2021 Sony Corporation. All rights reserved. +// Copyright 2023 Sony Corporation. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -32,7 +32,7 @@ class NativeWindowDrmEglstream : public NativeWindowDrm { bool DismissCursor() override; // |NativeWindowDrm| - std::unique_ptr CreateRenderSurface() override; + std::unique_ptr CreateRenderSurface(bool enable_impeller) override; // |NativeWindow| bool Resize(const size_t width, const size_t height) override; diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_drm_gbm.cc b/src/flutter/shell/platform/linux_embedded/window/native_window_drm_gbm.cc index 8c342c00..10f4779c 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_drm_gbm.cc +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_drm_gbm.cc @@ -1,4 +1,4 @@ -// Copyright 2021 Sony Corporation. All rights reserved. +// Copyright 2023 Sony Corporation. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -129,9 +129,10 @@ bool NativeWindowDrmGbm::DismissCursor() { return true; } -std::unique_ptr NativeWindowDrmGbm::CreateRenderSurface() { +std::unique_ptr NativeWindowDrmGbm::CreateRenderSurface( + bool enable_impeller) { return std::make_unique(std::make_unique( - std::make_unique(gbm_device_))); + std::make_unique(gbm_device_), enable_impeller)); } bool NativeWindowDrmGbm::IsNeedRecreateSurfaceAfterResize() const { diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_drm_gbm.h b/src/flutter/shell/platform/linux_embedded/window/native_window_drm_gbm.h index 6b9b9ecd..e888b269 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_drm_gbm.h +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_drm_gbm.h @@ -1,4 +1,4 @@ -// Copyright 2021 Sony Corporation. All rights reserved. +// Copyright 2023 Sony Corporation. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -32,7 +32,7 @@ class NativeWindowDrmGbm : public NativeWindowDrm { bool DismissCursor() override; // |NativeWindowDrm| - std::unique_ptr CreateRenderSurface() override; + std::unique_ptr CreateRenderSurface(bool enable_impeller) override; // |NativeWindow| bool IsNeedRecreateSurfaceAfterResize() const override; diff --git a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.cc index d118573b..531cb5bc 100644 --- a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.cc @@ -24,7 +24,8 @@ WindowDecorationsWayland::WindowDecorationsWayland( wl_surface* root_surface, int32_t width_dip, int32_t height_dip, - double pixel_ratio) { + double pixel_ratio, + bool enable_impeller) { constexpr bool sub_egl_display = true; // title-bar. @@ -33,7 +34,8 @@ WindowDecorationsWayland::WindowDecorationsWayland( compositor, subcompositor, root_surface, width_dip * pixel_ratio, kTitleBarHeightDIP * pixel_ratio), std::make_unique(std::make_unique( - std::make_unique(display, sub_egl_display)))); + std::make_unique(display, sub_egl_display), + enable_impeller))); titlebar_->SetPosition(0, -kTitleBarHeightDIP); // close button. @@ -44,7 +46,8 @@ WindowDecorationsWayland::WindowDecorationsWayland( compositor, subcompositor, root_surface, kButtonWidthDIP * pixel_ratio, kButtonHeightDIP * pixel_ratio), std::make_unique(std::make_unique( - std::make_unique(display, sub_egl_display))))); + std::make_unique(display, sub_egl_display), + enable_impeller)))); buttons_[type]->SetPosition( width_dip - kButtonWidthDIP - kButtonMarginDIP, -(kButtonHeightDIP + (kTitleBarHeightDIP - kButtonHeightDIP) / 2)); @@ -57,7 +60,8 @@ WindowDecorationsWayland::WindowDecorationsWayland( compositor, subcompositor, root_surface, kButtonWidthDIP * pixel_ratio, kButtonHeightDIP * pixel_ratio), std::make_unique(std::make_unique( - std::make_unique(display, sub_egl_display))))); + std::make_unique(display, sub_egl_display), + enable_impeller)))); buttons_[type]->SetPosition( width_dip - kButtonWidthDIP * 2 - kButtonMarginDIP * 2, -(kButtonHeightDIP + (kTitleBarHeightDIP - kButtonHeightDIP) / 2)); @@ -70,7 +74,8 @@ WindowDecorationsWayland::WindowDecorationsWayland( compositor, subcompositor, root_surface, kButtonWidthDIP * pixel_ratio, kButtonHeightDIP * pixel_ratio), std::make_unique(std::make_unique( - std::make_unique(display, sub_egl_display))))); + std::make_unique(display, sub_egl_display), + enable_impeller)))); buttons_[type]->SetPosition( width_dip - kButtonWidthDIP * 3 - kButtonMarginDIP * 3, -(kButtonHeightDIP + (kTitleBarHeightDIP - kButtonHeightDIP) / 2)); diff --git a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.h b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.h index 9910841e..3e60b3ed 100644 --- a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.h +++ b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.h @@ -35,7 +35,8 @@ class WindowDecorationsWayland { wl_surface* root_surface, int32_t width_dip, int32_t height_dip, - double pixel_ratio); + double pixel_ratio, + bool enable_impeller); ~WindowDecorationsWayland(); void Draw(); diff --git a/src/flutter/shell/platform/linux_embedded/window_binding_handler.h b/src/flutter/shell/platform/linux_embedded/window_binding_handler.h index ce8fffb4..34499df8 100644 --- a/src/flutter/shell/platform/linux_embedded/window_binding_handler.h +++ b/src/flutter/shell/platform/linux_embedded/window_binding_handler.h @@ -34,9 +34,12 @@ class WindowBindingHandler { virtual bool DispatchEvent() = 0; // Create a surface. - // @param[in] width_px Physical width of the surface. - // @param[in] height_px Physical height of the surface. - virtual bool CreateRenderSurface(int32_t width_px, int32_t height_px) = 0; + // @param[in] width_px Physical width of the surface. + // @param[in] height_px Physical height of the surface. + // @param[in] enable_impeller Enable impeller. + virtual bool CreateRenderSurface(int32_t width_px, + int32_t height_px, + bool enable_impeller) = 0; // Destroy a surface which is currently used. virtual void DestroyRenderSurface() = 0; From 9dcb3d4d053e7c0b4edf1d39654b76b6449b5ea6 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Fri, 4 Aug 2023 12:52:15 +0000 Subject: [PATCH 059/112] impeller: remove unnecessary debug comment (#356) Signed-off-by: Hidenori Matsubayashi --- src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc index 131d114c..2f4d8548 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc @@ -435,7 +435,6 @@ bool FlutterELinuxView::MakeResourceCurrent() { bool FlutterELinuxView::CreateRenderSurface() { PhysicalWindowBounds bounds = binding_handler_->GetPhysicalWindowBounds(); auto impeller_enable = engine_.get()->IsImpellerEnabled(); - std::cout << "impeller: " << impeller_enable << std::endl; return binding_handler_->CreateRenderSurface(bounds.width, bounds.height, impeller_enable); } From bfcffb300f1a3448e45741f92e9ba1d350e86eff Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Fri, 4 Aug 2023 14:30:40 +0000 Subject: [PATCH 060/112] wayland: re-enable vsync (#357) Signed-off-by: Hidenori Matsubayashi --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ef7a33a..723556b3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ option(BACKEND_TYPE "Select WAYLAND, DRM-GBM, DRM-EGLSTREAM, or X11 as the displ option(USE_DIRTY_REGION_MANAGEMENT "Use Flutter dirty region management" ON) option(USE_GLES3 "Use OpenGL ES3 (default is OpenGL ES2)" OFF) option(ENABLE_EGL_ALPHA_COMPONENT_OF_COLOR_BUFFER "Enable alpha component of the EGL color buffer" ON) -option(ENABLE_VSYNC "Enable embedder vsync" OFF) +option(ENABLE_VSYNC "Enable embedder vsync" ON) option(BUILD_ELINUX_SO "Build .so file of elinux embedder" OFF) option(ENABLE_ELINUX_EMBEDDER_LOG "Enable logger of eLinux embedder" ON) option(FLUTTER_RELEASE "Build Flutter Engine with release mode" OFF) From 070302587ece6c79b0b2b2b16dc0c7236eb5ba57 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Sat, 5 Aug 2023 07:12:42 +0000 Subject: [PATCH 061/112] wayland: add xdg-decoration support (#358) I've tested this change on Sway. Fixed #216 Signed-off-by: Hidenori Matsubayashi --- cmake/build.cmake | 6 ++ .../window/elinux_window_wayland.cc | 82 +++++++++++++++++-- .../window/elinux_window_wayland.h | 10 +++ 3 files changed, 91 insertions(+), 7 deletions(-) diff --git a/cmake/build.cmake b/cmake/build.cmake index e97728f1..cde9cc92 100644 --- a/cmake/build.cmake +++ b/cmake/build.cmake @@ -63,6 +63,11 @@ else() CODE_FILE "${_wayland_protocols_src_dir}/presentation-time-protocol.c" HEADER_FILE "${_wayland_protocols_src_dir}/presentation-time-protocol.h") + generate_wayland_client_protocol( + PROTOCOL_FILE "${_wayland_protocols_xml_dir}/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml" + CODE_FILE "${_wayland_protocols_src_dir}/xdg-decoration-unstable-v1-protocol.c" + HEADER_FILE "${_wayland_protocols_src_dir}/xdg-decoration-unstable-v1-protocol.h") + add_definitions(-DFLUTTER_TARGET_BACKEND_WAYLAND) add_definitions(-DDISPLAY_BACKEND_TYPE_WAYLAND) set(DISPLAY_BACKEND_SRC @@ -70,6 +75,7 @@ else() "${_wayland_protocols_src_dir}/text-input-unstable-v1-protocol.c" "${_wayland_protocols_src_dir}/text-input-unstable-v3-protocol.c" "${_wayland_protocols_src_dir}/presentation-time-protocol.c" + "${_wayland_protocols_src_dir}/xdg-decoration-unstable-v1-protocol.c" "src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc" "src/flutter/shell/platform/linux_embedded/window/native_window_wayland.cc" "src/flutter/shell/platform/linux_embedded/window/native_window_wayland_decoration.cc" diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc index 2e684e56..5d5ee1bf 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc @@ -23,6 +23,7 @@ namespace flutter { namespace { constexpr char kZwpTextInputManagerV1[] = "zwp_text_input_manager_v1"; constexpr char kZwpTextInputManagerV3[] = "zwp_text_input_manager_v3"; +constexpr char kZxdgDecorationManagerV1[] = "zxdg_decoration_manager_v1"; constexpr char kWlCursorThemeBottomLeftCorner[] = "bottom_left_corner"; constexpr char kWlCursorThemeBottomRightCorner[] = "bottom_right_corner"; @@ -73,7 +74,7 @@ const xdg_surface_listener ELinuxWindowWayland::kXdgSurfaceListener = { auto self = reinterpret_cast(data); constexpr int32_t x = 0; int32_t y = 0; - if (self->view_properties_.use_window_decoration) { + if (self->window_decorations_) { // TODO: Moves the window to the bottom to show the window // decorations, but the bottom area of the window will be hidden // because of this shifting. @@ -851,6 +852,28 @@ const wl_data_source_listener ELinuxWindowWayland::kWlDataSourceListener = { uint32_t dnd_action) -> void {}, }; +const zxdg_toplevel_decoration_v1_listener + ELinuxWindowWayland::kZxdgToplevelDecorationV1Listener = { + .configure = + [](void* data, + struct zxdg_toplevel_decoration_v1* zxdg_toplevel_decoration_v1, + uint32_t mode) -> void { + ELINUX_LOG(INFO) + << "zxdg_toplevel_decoration_v1_listener.configure: mode is " + << ((mode == ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE) + ? "server-side" + : "client-side"); + auto self = reinterpret_cast(data); + if (self->view_properties_.use_window_decoration && + mode == ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE && + !self->window_decorations_) { + int32_t width_dip = self->view_properties_.width; + int32_t height_dip = self->view_properties_.height; + self->CreateDecoration(width_dip, height_dip); + } + }, +}; + ELinuxWindowWayland::ELinuxWindowWayland( FlutterDesktopViewProperties view_properties) : cursor_info_({"", 0, nullptr}), @@ -973,6 +996,18 @@ ELinuxWindowWayland::~ELinuxWindowWayland() { } } + { + if (zxdg_decoration_manager_v1_) { + zxdg_decoration_manager_v1_destroy(zxdg_decoration_manager_v1_); + zxdg_decoration_manager_v1_ = nullptr; + } + + if (zxdg_toplevel_decoration_v1_) { + zxdg_toplevel_decoration_v1_destroy(zxdg_toplevel_decoration_v1_); + zxdg_toplevel_decoration_v1_ = nullptr; + } + } + if (wl_data_offer_) { wl_data_offer_destroy(wl_data_offer_); wl_data_offer_ = nullptr; @@ -1149,6 +1184,8 @@ bool ELinuxWindowWayland::DispatchEvent() { bool ELinuxWindowWayland::CreateRenderSurface(int32_t width_px, int32_t height_px, bool enable_impeller) { + enable_impeller_ = enable_impeller; + if (!display_valid_) { ELINUX_LOG(ERROR) << "Wayland display is invalid."; return false; @@ -1230,12 +1267,22 @@ bool ELinuxWindowWayland::CreateRenderSurface(int32_t width_px, render_surface_->SetNativeWindow(native_window_.get()); if (view_properties_.use_window_decoration) { - int32_t width_dip = width_px / current_scale_; - int32_t height_dip = height_px / current_scale_; - window_decorations_ = std::make_unique( - wl_display_, wl_compositor_, wl_subcompositor_, - native_window_->Surface(), width_dip, height_dip, current_scale_, - enable_impeller); + if (zxdg_decoration_manager_v1_) { + ELINUX_LOG(INFO) << "Use server-side xdg-decoration mode"; + zxdg_toplevel_decoration_v1_ = + zxdg_decoration_manager_v1_get_toplevel_decoration( + zxdg_decoration_manager_v1_, xdg_toplevel_); + zxdg_toplevel_decoration_v1_set_mode( + zxdg_toplevel_decoration_v1_, + ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE); + zxdg_toplevel_decoration_v1_add_listener( + zxdg_toplevel_decoration_v1_, &kZxdgToplevelDecorationV1Listener, + this); + } else { + int32_t width_dip = width_px / current_scale_; + int32_t height_dip = height_px / current_scale_; + CreateDecoration(width_dip, height_dip); + } } // Wait for making sure that xdg_surface has been configured. @@ -1246,6 +1293,18 @@ bool ELinuxWindowWayland::CreateRenderSurface(int32_t width_px, return true; } +void ELinuxWindowWayland::CreateDecoration(int32_t width_dip, + int32_t height_dip) { + if (window_decorations_) { + ELINUX_LOG(WARNING) << "Window decoration has already created"; + return; + } + + window_decorations_ = std::make_unique( + wl_display_, wl_compositor_, wl_subcompositor_, native_window_->Surface(), + width_dip, height_dip, current_scale_, enable_impeller_); +} + void ELinuxWindowWayland::DestroyRenderSurface() { // destroy the main surface before destroying the client window on Wayland. if (window_decorations_) { @@ -1463,6 +1522,15 @@ void ELinuxWindowWayland::WlRegistryHandler(wl_registry* wl_registry, this); return; } + + if (!strcmp(interface, kZxdgDecorationManagerV1)) { + constexpr uint32_t kMaxVersion = 1; + zxdg_decoration_manager_v1_ = + static_cast(wl_registry_bind( + wl_registry, name, &zxdg_decoration_manager_v1_interface, + std::min(kMaxVersion, version))); + return; + } } void ELinuxWindowWayland::WlUnRegistryHandler(wl_registry* wl_registry, diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h index fad7dc1d..6ba5f722 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h @@ -24,6 +24,7 @@ extern "C" { #include "wayland/protocols/presentation-time-protocol.h" #include "wayland/protocols/text-input-unstable-v1-client-protocol.h" #include "wayland/protocols/text-input-unstable-v3-client-protocol.h" +#include "wayland/protocols/xdg-decoration-unstable-v1-protocol.h" #include "wayland/protocols/xdg-shell-client-protocol.h" } @@ -107,6 +108,8 @@ class ELinuxWindowWayland : public ELinuxWindow, public WindowBindingHandler { // Updates the surface scale of the window from the list of entered outputs. void UpdateWindowScale(); + void CreateDecoration(int32_t width_dip, int32_t height_dip); + // Get window decorations height in physical pixels. uint32_t WindowDecorationsPhysicalHeight() const; @@ -128,6 +131,8 @@ class ELinuxWindowWayland : public ELinuxWindow, public WindowBindingHandler { static const wp_presentation_listener kWpPresentationListener; static const wp_presentation_feedback_listener kWpPresentationFeedbackListener; + static const zxdg_toplevel_decoration_v1_listener + kZxdgToplevelDecorationV1Listener; static constexpr size_t kDefaultPointerSize = 24; // A pointer to a FlutterWindowsView that can be used to update engine @@ -151,6 +156,7 @@ class ELinuxWindowWayland : public ELinuxWindow, public WindowBindingHandler { bool request_redraw_ = false; bool maximised_; uint32_t last_frame_time_; + bool enable_impeller_ = false; // Indicates that exists a keyboard show request from Flutter Engine. bool is_requested_show_virtual_keyboard_; @@ -175,6 +181,10 @@ class ELinuxWindowWayland : public ELinuxWindow, public WindowBindingHandler { zwp_text_input_v1* zwp_text_input_v1_; zwp_text_input_v3* zwp_text_input_v3_; + // xdg-decoration protocol for window decoration (server-side). + zxdg_decoration_manager_v1* zxdg_decoration_manager_v1_ = nullptr; + zxdg_toplevel_decoration_v1* zxdg_toplevel_decoration_v1_ = nullptr; + // Frame information for Vsync events. wp_presentation* wp_presentation_; uint32_t wp_presentation_clk_id_; From 266a92fc5a949be5754720e92184bcf5865dd862 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Sat, 5 Aug 2023 12:31:34 +0000 Subject: [PATCH 062/112] wayland: fix wrong height when using decoration option (#359) This change fixes a wrong height size when decoration ("-d") option is used. Signed-off-by: Hidenori Matsubayashi --- .../platform/linux_embedded/window/elinux_window_wayland.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc index 5d5ee1bf..562c9df9 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc @@ -107,8 +107,7 @@ const xdg_toplevel_listener ELinuxWindowWayland::kXdgToplevelListener = { } int32_t next_width = width; - int32_t next_height = - height - self->WindowDecorationsPhysicalHeight(); + int32_t next_height = height; if (self->restore_window_required_) { self->restore_window_required_ = false; next_width = self->restore_window_width_; From 589c117b73e56de30a907ae3b4498724ae32d75a Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Sat, 5 Aug 2023 13:58:47 +0000 Subject: [PATCH 063/112] wayland: delete old todo comment for vsync (#360) Signed-off-by: Hidenori Matsubayashi --- .../shell/platform/linux_embedded/flutter_elinux_engine.cc | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc index d081cdfb..d2510cd0 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc @@ -248,9 +248,6 @@ bool FlutterELinuxEngine::RunWithEntrypoint(const char* entrypoint) { auto host = static_cast(user_data); return host->HandlePlatformMessage(engine_message); }; -// todo: disable vsync temporarily because flutter apps will freeze when we use -// this interface. See also: -// https://github.com/sony/flutter-embedded-linux/issues/176 #if defined(ENABLE_VSYNC) // todo: add drm/x11 support. // https://github.com/sony/flutter-embedded-linux/issues/136 From 83d9b6f3cea741ed6d738d824bdda4fb2af23604 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Sun, 6 Aug 2023 07:58:32 +0000 Subject: [PATCH 064/112] client_wrapper: merge common/client_wrapper (#361) Merged the latest source files from flutter/engine repo. * src/flutter/shell/platform/common/client_wrapper/include/flutter/encodable_value.h => https://github.com/flutter/engine/commit/a3c5a319fccb7b137949ee7f410bf2510148dd3d * src/flutter/shell/platform/common/client_wrapper/include/flutter/event_channel.h src/flutter/shell/platform/common/client_wrapper/include/flutter/event_stream_handler.h => https://github.com/flutter/engine/commit/52574efd2a88390575423b6407ffd13a39f58429 * src/flutter/shell/platform/common/client_wrapper/include/flutter/method_channel.h => https://github.com/flutter/engine/commit/4165d4b9b6f1843e91ccbf13a4c12a32d48ca648 * src/flutter/shell/platform/common/client_wrapper/include/flutter/plugin_registrar.h => https://github.com/flutter/engine/commit/6d263ea56a62a9cec738f5cfa6c1afcacfd14e9d * src/flutter/shell/platform/common/client_wrapper/standard_codec.cc => https://github.com/flutter/engine/commit/71ee5f19bc164c140055007d39bb3240d04a2376 Signed-off-by: Hidenori Matsubayashi --- .../include/flutter/encodable_value.h | 7 +++++++ .../include/flutter/event_channel.h | 4 ++-- .../include/flutter/event_stream_handler.h | 17 ++++++++++------- .../include/flutter/method_channel.h | 7 ++++--- .../include/flutter/plugin_registrar.h | 4 ++-- .../common/client_wrapper/standard_codec.cc | 2 +- 6 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/flutter/shell/platform/common/client_wrapper/include/flutter/encodable_value.h b/src/flutter/shell/platform/common/client_wrapper/include/flutter/encodable_value.h index 3b46f99f..3a191205 100644 --- a/src/flutter/shell/platform/common/client_wrapper/include/flutter/encodable_value.h +++ b/src/flutter/shell/platform/common/client_wrapper/include/flutter/encodable_value.h @@ -215,6 +215,13 @@ class EncodableValue : public internal::EncodableValueVariant { } return std::get(*this); } + + // Explicitly provide operator<, delegating to std::variant's operator<. + // There are issues with with the way the standard library-provided + // < and <=> comparisons interact with classes derived from variant. + friend bool operator<(const EncodableValue& lhs, const EncodableValue& rhs) { + return static_cast(lhs) < static_cast(rhs); + } }; } // namespace flutter diff --git a/src/flutter/shell/platform/common/client_wrapper/include/flutter/event_channel.h b/src/flutter/shell/platform/common/client_wrapper/include/flutter/event_channel.h index 08c242a2..6a3ef09b 100644 --- a/src/flutter/shell/platform/common/client_wrapper/include/flutter/event_channel.h +++ b/src/flutter/shell/platform/common/client_wrapper/include/flutter/event_channel.h @@ -106,7 +106,7 @@ class EventChannel { if (error) { result = codec->EncodeErrorEnvelope(error->error_code, error->error_message, - error->error_details); + error->error_details.get()); } else { result = codec->EncodeSuccessEnvelope(); } @@ -119,7 +119,7 @@ class EventChannel { if (error) { result = codec->EncodeErrorEnvelope(error->error_code, error->error_message, - error->error_details); + error->error_details.get()); } else { result = codec->EncodeSuccessEnvelope(); } diff --git a/src/flutter/shell/platform/common/client_wrapper/include/flutter/event_stream_handler.h b/src/flutter/shell/platform/common/client_wrapper/include/flutter/event_stream_handler.h index 9eced6cf..9c1d8941 100644 --- a/src/flutter/shell/platform/common/client_wrapper/include/flutter/event_stream_handler.h +++ b/src/flutter/shell/platform/common/client_wrapper/include/flutter/event_stream_handler.h @@ -5,6 +5,9 @@ #ifndef FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_EVENT_STREAM_HANDLER_H_ #define FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_EVENT_STREAM_HANDLER_H_ +#include +#include + #include "event_sink.h" namespace flutter { @@ -13,16 +16,16 @@ class EncodableValue; template struct StreamHandlerError { - const std::string& error_code; - const std::string& error_message; - const T* error_details; + const std::string error_code; + const std::string error_message; + const std::unique_ptr error_details; - StreamHandlerError(const std::string& error_code, - const std::string& error_message, - const T* error_details) + StreamHandlerError(const std::string error_code, + const std::string error_message, + std::unique_ptr&& error_details) : error_code(error_code), error_message(error_message), - error_details(error_details) {} + error_details(std::move(error_details)) {} }; // Handler for stream setup and teardown requests. diff --git a/src/flutter/shell/platform/common/client_wrapper/include/flutter/method_channel.h b/src/flutter/shell/platform/common/client_wrapper/include/flutter/method_channel.h index e9ed6161..6e39a644 100644 --- a/src/flutter/shell/platform/common/client_wrapper/include/flutter/method_channel.h +++ b/src/flutter/shell/platform/common/client_wrapper/include/flutter/method_channel.h @@ -91,9 +91,10 @@ class MethodChannel { // Registers a handler that should be called any time a method call is // received on this channel. A null handler will remove any previous handler. // - // Note that the MethodChannel does not own the handler, and will not - // unregister it on destruction, so the caller is responsible for - // unregistering explicitly if it should no longer be called. + // The handler will be owned by the underlying BinaryMessageHandler. + // Destroying the MethodChannel will not unregister the handler, so + // the caller is responsible for unregistering explicitly if the handler + // stops being valid before the engine is destroyed. void SetMethodCallHandler(MethodCallHandler handler) const { if (!handler) { messenger_->SetMessageHandler(name_, nullptr); diff --git a/src/flutter/shell/platform/common/client_wrapper/include/flutter/plugin_registrar.h b/src/flutter/shell/platform/common/client_wrapper/include/flutter/plugin_registrar.h index 858119e3..15cf9968 100644 --- a/src/flutter/shell/platform/common/client_wrapper/include/flutter/plugin_registrar.h +++ b/src/flutter/shell/platform/common/client_wrapper/include/flutter/plugin_registrar.h @@ -49,8 +49,8 @@ class PluginRegistrar { // Takes ownership of |plugin|. // // Plugins are not required to call this method if they have other lifetime - // management, but this is a convient place for plugins to be owned to ensure - // that they stay valid for any registered callbacks. + // management, but this is a convenient place for plugins to be owned to + // ensure that they stay valid for any registered callbacks. void AddPlugin(std::unique_ptr plugin); protected: diff --git a/src/flutter/shell/platform/common/client_wrapper/standard_codec.cc b/src/flutter/shell/platform/common/client_wrapper/standard_codec.cc index 807e0681..5e93d407 100644 --- a/src/flutter/shell/platform/common/client_wrapper/standard_codec.cc +++ b/src/flutter/shell/platform/common/client_wrapper/standard_codec.cc @@ -98,7 +98,7 @@ EncodableValue StandardCodecSerializer::ReadValue( void StandardCodecSerializer::WriteValue(const EncodableValue& value, ByteStreamWriter* stream) const { stream->WriteByte(static_cast(EncodedTypeForValue(value))); - // TODO: Consider replacing this this with a std::visitor. + // TODO(cbracken): Consider replacing this with std::visit. switch (value.index()) { case 0: case 1: From e5646da717f756ae0f13a1f6d5c771bb5218a465 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Mon, 7 Aug 2023 12:11:28 +0000 Subject: [PATCH 065/112] cmake: add ENABLE_EGL_ASYNC_BUFFER_SWAPPING option (#362) This change adds ENABLE_EGL_ASYNC_BUFFER_SWAPPING not to sync compositor redraw (vblank). Related issue #220 Signed-off-by: Hidenori Matsubayashi --- CMakeLists.txt | 1 + cmake/build.cmake | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 723556b3..4e7f0691 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,7 @@ option(USE_DIRTY_REGION_MANAGEMENT "Use Flutter dirty region management" ON) option(USE_GLES3 "Use OpenGL ES3 (default is OpenGL ES2)" OFF) option(ENABLE_EGL_ALPHA_COMPONENT_OF_COLOR_BUFFER "Enable alpha component of the EGL color buffer" ON) option(ENABLE_VSYNC "Enable embedder vsync" ON) +option(ENABLE_EGL_ASYNC_BUFFER_SWAPPING "Do not sync to compositor redraw (eglSwapInterval 0)" OFF) option(BUILD_ELINUX_SO "Build .so file of elinux embedder" OFF) option(ENABLE_ELINUX_EMBEDDER_LOG "Enable logger of eLinux embedder" ON) option(FLUTTER_RELEASE "Build Flutter Engine with release mode" OFF) diff --git a/cmake/build.cmake b/cmake/build.cmake index cde9cc92..56eda140 100644 --- a/cmake/build.cmake +++ b/cmake/build.cmake @@ -118,6 +118,13 @@ if(ENABLE_VSYNC) ) endif() +# Do not sync to compositor redraw (eglSwapInterval 0). +if(ENABLE_EGL_ASYNC_BUFFER_SWAPPING) + add_definitions( + -DENABLE_EGL_ASYNC_BUFFER_SWAPPING + ) +endif() + # Enable alpha component of the egl color buffer. if(ENABLE_EGL_ALPHA_COMPONENT_OF_COLOR_BUFFER) add_definitions( From eb2687ada4ab4f53504de37886eb6d72ebd400ec Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Mon, 7 Aug 2023 13:39:47 +0000 Subject: [PATCH 066/112] egl: add async buffer swapping command option (#363) Fixed #220 Signed-off-by: Hidenori Matsubayashi --- CMakeLists.txt | 1 - cmake/build.cmake | 7 --- .../flutter_embedder_options.h | 50 +++++++++++++++---- .../flutter-drm-eglstream-backend/main.cc | 1 + .../flutter_embedder_options.h | 50 +++++++++++++++---- examples/flutter-drm-gbm-backend/main.cc | 1 + .../flutter_embedder_options.h | 50 +++++++++++++++---- .../flutter-external-texture-plugin/main.cc | 1 + .../flutter_embedder_options.h | 50 +++++++++++++++---- examples/flutter-video-player-plugin/main.cc | 1 + .../flutter_embedder_options.h | 50 +++++++++++++++---- examples/flutter-wayland-client/main.cc | 1 + .../flutter_embedder_options.h | 50 +++++++++++++++---- examples/flutter-x11-client/main.cc | 1 + src/client_wrapper/flutter_view_controller.cc | 1 + .../include/flutter/flutter_view_controller.h | 5 ++ .../linux_embedded/public/flutter_elinux.h | 5 ++ .../linux_embedded/surface/context_egl.cc | 5 +- .../surface/context_egl_stream.cc | 2 +- .../surface/elinux_egl_surface.cc | 14 +++--- .../surface/elinux_egl_surface.h | 6 ++- .../linux_embedded/window/elinux_window_drm.h | 4 +- .../window/elinux_window_wayland.cc | 7 +-- .../window/elinux_window_x11.cc | 2 +- .../linux_embedded/window/native_window.h | 3 ++ .../window/native_window_drm.cc | 4 +- .../linux_embedded/window/native_window_drm.h | 4 +- .../window/native_window_drm_eglstream.cc | 6 ++- .../window/native_window_drm_eglstream.h | 3 +- .../window/native_window_drm_gbm.cc | 6 ++- .../window/native_window_drm_gbm.h | 4 +- .../window/native_window_wayland.cc | 4 +- .../window/native_window_wayland.h | 3 +- .../native_window_wayland_decoration.cc | 4 +- .../window/native_window_wayland_decoration.h | 3 +- .../window/native_window_x11.cc | 4 +- .../linux_embedded/window/native_window_x11.h | 3 +- .../renderer/window_decorations_wayland.cc | 14 ++++-- .../renderer/window_decorations_wayland.h | 3 +- 39 files changed, 329 insertions(+), 104 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e7f0691..723556b3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,6 @@ option(USE_DIRTY_REGION_MANAGEMENT "Use Flutter dirty region management" ON) option(USE_GLES3 "Use OpenGL ES3 (default is OpenGL ES2)" OFF) option(ENABLE_EGL_ALPHA_COMPONENT_OF_COLOR_BUFFER "Enable alpha component of the EGL color buffer" ON) option(ENABLE_VSYNC "Enable embedder vsync" ON) -option(ENABLE_EGL_ASYNC_BUFFER_SWAPPING "Do not sync to compositor redraw (eglSwapInterval 0)" OFF) option(BUILD_ELINUX_SO "Build .so file of elinux embedder" OFF) option(ENABLE_ELINUX_EMBEDDER_LOG "Enable logger of eLinux embedder" ON) option(FLUTTER_RELEASE "Build Flutter Engine with release mode" OFF) diff --git a/cmake/build.cmake b/cmake/build.cmake index 56eda140..cde9cc92 100644 --- a/cmake/build.cmake +++ b/cmake/build.cmake @@ -118,13 +118,6 @@ if(ENABLE_VSYNC) ) endif() -# Do not sync to compositor redraw (eglSwapInterval 0). -if(ENABLE_EGL_ASYNC_BUFFER_SWAPPING) - add_definitions( - -DENABLE_EGL_ASYNC_BUFFER_SWAPPING - ) -endif() - # Enable alpha component of the egl color buffer. if(ENABLE_EGL_ALPHA_COMPONENT_OF_COLOR_BUFFER) add_definitions( diff --git a/examples/flutter-drm-eglstream-backend/flutter_embedder_options.h b/examples/flutter-drm-eglstream-backend/flutter_embedder_options.h index dede8b9e..8a5cfd41 100644 --- a/examples/flutter-drm-eglstream-backend/flutter_embedder_options.h +++ b/examples/flutter-drm-eglstream-backend/flutter_embedder_options.h @@ -24,6 +24,10 @@ class FlutterEmbedderOptions { options_.AddDouble("force-scale-factor", "s", "Force a scale factor instead using default value", 1.0, false); + options_.AddWithoutValue( + "async-vblank", "v", + "Don't sync to compositor redraw/vblank (eglSwapInterval 0)", false); + #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) // no more options. @@ -87,6 +91,8 @@ class FlutterEmbedderOptions { scale_factor_ = 1.0; } + enable_vsync_ = !options_.Exist("async-vblank"); + #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) use_onscreen_keyboard_ = false; @@ -118,22 +124,45 @@ class FlutterEmbedderOptions { return true; } - std::string BundlePath() const { return bundle_path_; } - std::string WindowTitle() const { return window_title_; } - std::string WindowAppID() const { return window_app_id_; } - bool IsUseMouseCursor() const { return use_mouse_cursor_; } - bool IsUseOnscreenKeyboard() const { return use_onscreen_keyboard_; } - bool IsUseWindowDecoraation() const { return use_window_decoration_; } + std::string BundlePath() const { + return bundle_path_; + } + std::string WindowTitle() const { + return window_title_; + } + std::string WindowAppID() const { + return window_app_id_; + } + bool IsUseMouseCursor() const { + return use_mouse_cursor_; + } + bool IsUseOnscreenKeyboard() const { + return use_onscreen_keyboard_; + } + bool IsUseWindowDecoraation() const { + return use_window_decoration_; + } flutter::FlutterViewController::ViewMode WindowViewMode() const { return window_view_mode_; } - int WindowWidth() const { return window_width_; } - int WindowHeight() const { return window_height_; } + int WindowWidth() const { + return window_width_; + } + int WindowHeight() const { + return window_height_; + } flutter::FlutterViewController::ViewRotation WindowRotation() const { return window_view_rotation_; } - bool IsForceScaleFactor() const { return is_force_scale_factor_; } - double ScaleFactor() const { return scale_factor_; } + bool IsForceScaleFactor() const { + return is_force_scale_factor_; + } + double ScaleFactor() const { + return scale_factor_; + } + bool EnableVsync() const { + return enable_vsync_; + } private: commandline::CommandOptions options_; @@ -152,6 +181,7 @@ class FlutterEmbedderOptions { flutter::FlutterViewController::ViewRotation::kRotation_0; bool is_force_scale_factor_; double scale_factor_; + bool enable_vsync_; }; #endif // FLUTTER_EMBEDDER_OPTIONS_ diff --git a/examples/flutter-drm-eglstream-backend/main.cc b/examples/flutter-drm-eglstream-backend/main.cc index eb8a6d28..e1da779c 100644 --- a/examples/flutter-drm-eglstream-backend/main.cc +++ b/examples/flutter-drm-eglstream-backend/main.cc @@ -37,6 +37,7 @@ int main(int argc, char** argv) { view_properties.use_window_decoration = options.IsUseWindowDecoraation(); view_properties.force_scale_factor = options.IsForceScaleFactor(); view_properties.scale_factor = options.ScaleFactor(); + view_properties.enable_vsync = options.EnableVsync(); // The Flutter instance hosted by this window. FlutterWindow window(view_properties, project); diff --git a/examples/flutter-drm-gbm-backend/flutter_embedder_options.h b/examples/flutter-drm-gbm-backend/flutter_embedder_options.h index dede8b9e..8a5cfd41 100644 --- a/examples/flutter-drm-gbm-backend/flutter_embedder_options.h +++ b/examples/flutter-drm-gbm-backend/flutter_embedder_options.h @@ -24,6 +24,10 @@ class FlutterEmbedderOptions { options_.AddDouble("force-scale-factor", "s", "Force a scale factor instead using default value", 1.0, false); + options_.AddWithoutValue( + "async-vblank", "v", + "Don't sync to compositor redraw/vblank (eglSwapInterval 0)", false); + #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) // no more options. @@ -87,6 +91,8 @@ class FlutterEmbedderOptions { scale_factor_ = 1.0; } + enable_vsync_ = !options_.Exist("async-vblank"); + #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) use_onscreen_keyboard_ = false; @@ -118,22 +124,45 @@ class FlutterEmbedderOptions { return true; } - std::string BundlePath() const { return bundle_path_; } - std::string WindowTitle() const { return window_title_; } - std::string WindowAppID() const { return window_app_id_; } - bool IsUseMouseCursor() const { return use_mouse_cursor_; } - bool IsUseOnscreenKeyboard() const { return use_onscreen_keyboard_; } - bool IsUseWindowDecoraation() const { return use_window_decoration_; } + std::string BundlePath() const { + return bundle_path_; + } + std::string WindowTitle() const { + return window_title_; + } + std::string WindowAppID() const { + return window_app_id_; + } + bool IsUseMouseCursor() const { + return use_mouse_cursor_; + } + bool IsUseOnscreenKeyboard() const { + return use_onscreen_keyboard_; + } + bool IsUseWindowDecoraation() const { + return use_window_decoration_; + } flutter::FlutterViewController::ViewMode WindowViewMode() const { return window_view_mode_; } - int WindowWidth() const { return window_width_; } - int WindowHeight() const { return window_height_; } + int WindowWidth() const { + return window_width_; + } + int WindowHeight() const { + return window_height_; + } flutter::FlutterViewController::ViewRotation WindowRotation() const { return window_view_rotation_; } - bool IsForceScaleFactor() const { return is_force_scale_factor_; } - double ScaleFactor() const { return scale_factor_; } + bool IsForceScaleFactor() const { + return is_force_scale_factor_; + } + double ScaleFactor() const { + return scale_factor_; + } + bool EnableVsync() const { + return enable_vsync_; + } private: commandline::CommandOptions options_; @@ -152,6 +181,7 @@ class FlutterEmbedderOptions { flutter::FlutterViewController::ViewRotation::kRotation_0; bool is_force_scale_factor_; double scale_factor_; + bool enable_vsync_; }; #endif // FLUTTER_EMBEDDER_OPTIONS_ diff --git a/examples/flutter-drm-gbm-backend/main.cc b/examples/flutter-drm-gbm-backend/main.cc index eb8a6d28..e1da779c 100644 --- a/examples/flutter-drm-gbm-backend/main.cc +++ b/examples/flutter-drm-gbm-backend/main.cc @@ -37,6 +37,7 @@ int main(int argc, char** argv) { view_properties.use_window_decoration = options.IsUseWindowDecoraation(); view_properties.force_scale_factor = options.IsForceScaleFactor(); view_properties.scale_factor = options.ScaleFactor(); + view_properties.enable_vsync = options.EnableVsync(); // The Flutter instance hosted by this window. FlutterWindow window(view_properties, project); diff --git a/examples/flutter-external-texture-plugin/flutter_embedder_options.h b/examples/flutter-external-texture-plugin/flutter_embedder_options.h index dede8b9e..8a5cfd41 100644 --- a/examples/flutter-external-texture-plugin/flutter_embedder_options.h +++ b/examples/flutter-external-texture-plugin/flutter_embedder_options.h @@ -24,6 +24,10 @@ class FlutterEmbedderOptions { options_.AddDouble("force-scale-factor", "s", "Force a scale factor instead using default value", 1.0, false); + options_.AddWithoutValue( + "async-vblank", "v", + "Don't sync to compositor redraw/vblank (eglSwapInterval 0)", false); + #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) // no more options. @@ -87,6 +91,8 @@ class FlutterEmbedderOptions { scale_factor_ = 1.0; } + enable_vsync_ = !options_.Exist("async-vblank"); + #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) use_onscreen_keyboard_ = false; @@ -118,22 +124,45 @@ class FlutterEmbedderOptions { return true; } - std::string BundlePath() const { return bundle_path_; } - std::string WindowTitle() const { return window_title_; } - std::string WindowAppID() const { return window_app_id_; } - bool IsUseMouseCursor() const { return use_mouse_cursor_; } - bool IsUseOnscreenKeyboard() const { return use_onscreen_keyboard_; } - bool IsUseWindowDecoraation() const { return use_window_decoration_; } + std::string BundlePath() const { + return bundle_path_; + } + std::string WindowTitle() const { + return window_title_; + } + std::string WindowAppID() const { + return window_app_id_; + } + bool IsUseMouseCursor() const { + return use_mouse_cursor_; + } + bool IsUseOnscreenKeyboard() const { + return use_onscreen_keyboard_; + } + bool IsUseWindowDecoraation() const { + return use_window_decoration_; + } flutter::FlutterViewController::ViewMode WindowViewMode() const { return window_view_mode_; } - int WindowWidth() const { return window_width_; } - int WindowHeight() const { return window_height_; } + int WindowWidth() const { + return window_width_; + } + int WindowHeight() const { + return window_height_; + } flutter::FlutterViewController::ViewRotation WindowRotation() const { return window_view_rotation_; } - bool IsForceScaleFactor() const { return is_force_scale_factor_; } - double ScaleFactor() const { return scale_factor_; } + bool IsForceScaleFactor() const { + return is_force_scale_factor_; + } + double ScaleFactor() const { + return scale_factor_; + } + bool EnableVsync() const { + return enable_vsync_; + } private: commandline::CommandOptions options_; @@ -152,6 +181,7 @@ class FlutterEmbedderOptions { flutter::FlutterViewController::ViewRotation::kRotation_0; bool is_force_scale_factor_; double scale_factor_; + bool enable_vsync_; }; #endif // FLUTTER_EMBEDDER_OPTIONS_ diff --git a/examples/flutter-external-texture-plugin/main.cc b/examples/flutter-external-texture-plugin/main.cc index eb8a6d28..e1da779c 100644 --- a/examples/flutter-external-texture-plugin/main.cc +++ b/examples/flutter-external-texture-plugin/main.cc @@ -37,6 +37,7 @@ int main(int argc, char** argv) { view_properties.use_window_decoration = options.IsUseWindowDecoraation(); view_properties.force_scale_factor = options.IsForceScaleFactor(); view_properties.scale_factor = options.ScaleFactor(); + view_properties.enable_vsync = options.EnableVsync(); // The Flutter instance hosted by this window. FlutterWindow window(view_properties, project); diff --git a/examples/flutter-video-player-plugin/flutter_embedder_options.h b/examples/flutter-video-player-plugin/flutter_embedder_options.h index dede8b9e..8a5cfd41 100644 --- a/examples/flutter-video-player-plugin/flutter_embedder_options.h +++ b/examples/flutter-video-player-plugin/flutter_embedder_options.h @@ -24,6 +24,10 @@ class FlutterEmbedderOptions { options_.AddDouble("force-scale-factor", "s", "Force a scale factor instead using default value", 1.0, false); + options_.AddWithoutValue( + "async-vblank", "v", + "Don't sync to compositor redraw/vblank (eglSwapInterval 0)", false); + #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) // no more options. @@ -87,6 +91,8 @@ class FlutterEmbedderOptions { scale_factor_ = 1.0; } + enable_vsync_ = !options_.Exist("async-vblank"); + #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) use_onscreen_keyboard_ = false; @@ -118,22 +124,45 @@ class FlutterEmbedderOptions { return true; } - std::string BundlePath() const { return bundle_path_; } - std::string WindowTitle() const { return window_title_; } - std::string WindowAppID() const { return window_app_id_; } - bool IsUseMouseCursor() const { return use_mouse_cursor_; } - bool IsUseOnscreenKeyboard() const { return use_onscreen_keyboard_; } - bool IsUseWindowDecoraation() const { return use_window_decoration_; } + std::string BundlePath() const { + return bundle_path_; + } + std::string WindowTitle() const { + return window_title_; + } + std::string WindowAppID() const { + return window_app_id_; + } + bool IsUseMouseCursor() const { + return use_mouse_cursor_; + } + bool IsUseOnscreenKeyboard() const { + return use_onscreen_keyboard_; + } + bool IsUseWindowDecoraation() const { + return use_window_decoration_; + } flutter::FlutterViewController::ViewMode WindowViewMode() const { return window_view_mode_; } - int WindowWidth() const { return window_width_; } - int WindowHeight() const { return window_height_; } + int WindowWidth() const { + return window_width_; + } + int WindowHeight() const { + return window_height_; + } flutter::FlutterViewController::ViewRotation WindowRotation() const { return window_view_rotation_; } - bool IsForceScaleFactor() const { return is_force_scale_factor_; } - double ScaleFactor() const { return scale_factor_; } + bool IsForceScaleFactor() const { + return is_force_scale_factor_; + } + double ScaleFactor() const { + return scale_factor_; + } + bool EnableVsync() const { + return enable_vsync_; + } private: commandline::CommandOptions options_; @@ -152,6 +181,7 @@ class FlutterEmbedderOptions { flutter::FlutterViewController::ViewRotation::kRotation_0; bool is_force_scale_factor_; double scale_factor_; + bool enable_vsync_; }; #endif // FLUTTER_EMBEDDER_OPTIONS_ diff --git a/examples/flutter-video-player-plugin/main.cc b/examples/flutter-video-player-plugin/main.cc index eb8a6d28..e1da779c 100644 --- a/examples/flutter-video-player-plugin/main.cc +++ b/examples/flutter-video-player-plugin/main.cc @@ -37,6 +37,7 @@ int main(int argc, char** argv) { view_properties.use_window_decoration = options.IsUseWindowDecoraation(); view_properties.force_scale_factor = options.IsForceScaleFactor(); view_properties.scale_factor = options.ScaleFactor(); + view_properties.enable_vsync = options.EnableVsync(); // The Flutter instance hosted by this window. FlutterWindow window(view_properties, project); diff --git a/examples/flutter-wayland-client/flutter_embedder_options.h b/examples/flutter-wayland-client/flutter_embedder_options.h index dede8b9e..8a5cfd41 100644 --- a/examples/flutter-wayland-client/flutter_embedder_options.h +++ b/examples/flutter-wayland-client/flutter_embedder_options.h @@ -24,6 +24,10 @@ class FlutterEmbedderOptions { options_.AddDouble("force-scale-factor", "s", "Force a scale factor instead using default value", 1.0, false); + options_.AddWithoutValue( + "async-vblank", "v", + "Don't sync to compositor redraw/vblank (eglSwapInterval 0)", false); + #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) // no more options. @@ -87,6 +91,8 @@ class FlutterEmbedderOptions { scale_factor_ = 1.0; } + enable_vsync_ = !options_.Exist("async-vblank"); + #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) use_onscreen_keyboard_ = false; @@ -118,22 +124,45 @@ class FlutterEmbedderOptions { return true; } - std::string BundlePath() const { return bundle_path_; } - std::string WindowTitle() const { return window_title_; } - std::string WindowAppID() const { return window_app_id_; } - bool IsUseMouseCursor() const { return use_mouse_cursor_; } - bool IsUseOnscreenKeyboard() const { return use_onscreen_keyboard_; } - bool IsUseWindowDecoraation() const { return use_window_decoration_; } + std::string BundlePath() const { + return bundle_path_; + } + std::string WindowTitle() const { + return window_title_; + } + std::string WindowAppID() const { + return window_app_id_; + } + bool IsUseMouseCursor() const { + return use_mouse_cursor_; + } + bool IsUseOnscreenKeyboard() const { + return use_onscreen_keyboard_; + } + bool IsUseWindowDecoraation() const { + return use_window_decoration_; + } flutter::FlutterViewController::ViewMode WindowViewMode() const { return window_view_mode_; } - int WindowWidth() const { return window_width_; } - int WindowHeight() const { return window_height_; } + int WindowWidth() const { + return window_width_; + } + int WindowHeight() const { + return window_height_; + } flutter::FlutterViewController::ViewRotation WindowRotation() const { return window_view_rotation_; } - bool IsForceScaleFactor() const { return is_force_scale_factor_; } - double ScaleFactor() const { return scale_factor_; } + bool IsForceScaleFactor() const { + return is_force_scale_factor_; + } + double ScaleFactor() const { + return scale_factor_; + } + bool EnableVsync() const { + return enable_vsync_; + } private: commandline::CommandOptions options_; @@ -152,6 +181,7 @@ class FlutterEmbedderOptions { flutter::FlutterViewController::ViewRotation::kRotation_0; bool is_force_scale_factor_; double scale_factor_; + bool enable_vsync_; }; #endif // FLUTTER_EMBEDDER_OPTIONS_ diff --git a/examples/flutter-wayland-client/main.cc b/examples/flutter-wayland-client/main.cc index eb8a6d28..e1da779c 100644 --- a/examples/flutter-wayland-client/main.cc +++ b/examples/flutter-wayland-client/main.cc @@ -37,6 +37,7 @@ int main(int argc, char** argv) { view_properties.use_window_decoration = options.IsUseWindowDecoraation(); view_properties.force_scale_factor = options.IsForceScaleFactor(); view_properties.scale_factor = options.ScaleFactor(); + view_properties.enable_vsync = options.EnableVsync(); // The Flutter instance hosted by this window. FlutterWindow window(view_properties, project); diff --git a/examples/flutter-x11-client/flutter_embedder_options.h b/examples/flutter-x11-client/flutter_embedder_options.h index dede8b9e..8a5cfd41 100644 --- a/examples/flutter-x11-client/flutter_embedder_options.h +++ b/examples/flutter-x11-client/flutter_embedder_options.h @@ -24,6 +24,10 @@ class FlutterEmbedderOptions { options_.AddDouble("force-scale-factor", "s", "Force a scale factor instead using default value", 1.0, false); + options_.AddWithoutValue( + "async-vblank", "v", + "Don't sync to compositor redraw/vblank (eglSwapInterval 0)", false); + #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) // no more options. @@ -87,6 +91,8 @@ class FlutterEmbedderOptions { scale_factor_ = 1.0; } + enable_vsync_ = !options_.Exist("async-vblank"); + #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) use_onscreen_keyboard_ = false; @@ -118,22 +124,45 @@ class FlutterEmbedderOptions { return true; } - std::string BundlePath() const { return bundle_path_; } - std::string WindowTitle() const { return window_title_; } - std::string WindowAppID() const { return window_app_id_; } - bool IsUseMouseCursor() const { return use_mouse_cursor_; } - bool IsUseOnscreenKeyboard() const { return use_onscreen_keyboard_; } - bool IsUseWindowDecoraation() const { return use_window_decoration_; } + std::string BundlePath() const { + return bundle_path_; + } + std::string WindowTitle() const { + return window_title_; + } + std::string WindowAppID() const { + return window_app_id_; + } + bool IsUseMouseCursor() const { + return use_mouse_cursor_; + } + bool IsUseOnscreenKeyboard() const { + return use_onscreen_keyboard_; + } + bool IsUseWindowDecoraation() const { + return use_window_decoration_; + } flutter::FlutterViewController::ViewMode WindowViewMode() const { return window_view_mode_; } - int WindowWidth() const { return window_width_; } - int WindowHeight() const { return window_height_; } + int WindowWidth() const { + return window_width_; + } + int WindowHeight() const { + return window_height_; + } flutter::FlutterViewController::ViewRotation WindowRotation() const { return window_view_rotation_; } - bool IsForceScaleFactor() const { return is_force_scale_factor_; } - double ScaleFactor() const { return scale_factor_; } + bool IsForceScaleFactor() const { + return is_force_scale_factor_; + } + double ScaleFactor() const { + return scale_factor_; + } + bool EnableVsync() const { + return enable_vsync_; + } private: commandline::CommandOptions options_; @@ -152,6 +181,7 @@ class FlutterEmbedderOptions { flutter::FlutterViewController::ViewRotation::kRotation_0; bool is_force_scale_factor_; double scale_factor_; + bool enable_vsync_; }; #endif // FLUTTER_EMBEDDER_OPTIONS_ diff --git a/examples/flutter-x11-client/main.cc b/examples/flutter-x11-client/main.cc index eb8a6d28..e1da779c 100644 --- a/examples/flutter-x11-client/main.cc +++ b/examples/flutter-x11-client/main.cc @@ -37,6 +37,7 @@ int main(int argc, char** argv) { view_properties.use_window_decoration = options.IsUseWindowDecoraation(); view_properties.force_scale_factor = options.IsForceScaleFactor(); view_properties.scale_factor = options.ScaleFactor(); + view_properties.enable_vsync = options.EnableVsync(); // The Flutter instance hosted by this window. FlutterWindow window(view_properties, project); diff --git a/src/client_wrapper/flutter_view_controller.cc b/src/client_wrapper/flutter_view_controller.cc index 3d9b7ea8..9b412a3a 100644 --- a/src/client_wrapper/flutter_view_controller.cc +++ b/src/client_wrapper/flutter_view_controller.cc @@ -42,6 +42,7 @@ FlutterViewController::FlutterViewController( view_properties.use_window_decoration; c_view_properties.force_scale_factor = view_properties.force_scale_factor; c_view_properties.scale_factor = view_properties.scale_factor; + c_view_properties.enable_vsync = view_properties.enable_vsync; controller_ = FlutterDesktopViewControllerCreate(&c_view_properties, engine_->RelinquishEngine()); diff --git a/src/client_wrapper/include/flutter/flutter_view_controller.h b/src/client_wrapper/include/flutter/flutter_view_controller.h index 64fdad43..b0403c5c 100644 --- a/src/client_wrapper/include/flutter/flutter_view_controller.h +++ b/src/client_wrapper/include/flutter/flutter_view_controller.h @@ -79,6 +79,11 @@ class FlutterViewController { // Force scale factor specified by command line argument bool force_scale_factor; double scale_factor; + + // Enable Vsync. + // True: Sync to compositor redraw/v-blank (eglSwapInterval 1) + // False: Do not sync to compositor redraw/v-blank (eglSwapInterval 0) + bool enable_vsync; } ViewProperties; // Creates a FlutterView that can be parented into a Windows View hierarchy diff --git a/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h b/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h index 5693f095..d5f22347 100644 --- a/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h +++ b/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h @@ -109,6 +109,11 @@ typedef struct { // Force scale factor specified by command line argument bool force_scale_factor; double scale_factor; + + // Enable Vsync. + // True: Sync to compositor redraw/v-blank (eglSwapInterval 1) + // False: Do not sync to compositor redraw/v-blank (eglSwapInterval 0) + bool enable_vsync; } FlutterDesktopViewProperties; // ========== View Controller ========== diff --git a/src/flutter/shell/platform/linux_embedded/surface/context_egl.cc b/src/flutter/shell/platform/linux_embedded/surface/context_egl.cc index bea6dbb4..ac87ab10 100644 --- a/src/flutter/shell/platform/linux_embedded/surface/context_egl.cc +++ b/src/flutter/shell/platform/linux_embedded/surface/context_egl.cc @@ -119,7 +119,7 @@ std::unique_ptr ContextEgl::CreateOnscreenSurface( << get_egl_error_cause(); } return std::make_unique(surface, environment_->Display(), - context_); + context_, window->EnableVsync()); } std::unique_ptr ContextEgl::CreateOffscreenSurface( @@ -151,7 +151,8 @@ std::unique_ptr ContextEgl::CreateOffscreenSurface( } #endif return std::make_unique(surface, environment_->Display(), - resource_context_); + resource_context_, + window->EnableVsync()); } bool ContextEgl::IsValid() const { diff --git a/src/flutter/shell/platform/linux_embedded/surface/context_egl_stream.cc b/src/flutter/shell/platform/linux_embedded/surface/context_egl_stream.cc index 40822ccb..2f1df0c5 100644 --- a/src/flutter/shell/platform/linux_embedded/surface/context_egl_stream.cc +++ b/src/flutter/shell/platform/linux_embedded/surface/context_egl_stream.cc @@ -65,7 +65,7 @@ std::unique_ptr ContextEglStream::CreateOnscreenSurface( ELINUX_LOG(ERROR) << "Failed to create EGL stream producer surface"; } return std::make_unique(surface, environment_->Display(), - context_); + context_, window->EnableVsync()); } bool ContextEglStream::SetEglExtensionFunctionPointers() { diff --git a/src/flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.cc b/src/flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.cc index 1e01ca57..07fede87 100644 --- a/src/flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.cc +++ b/src/flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.cc @@ -18,10 +18,12 @@ constexpr const int kMaxHistorySize = 10; ELinuxEGLSurface::ELinuxEGLSurface(EGLSurface surface, EGLDisplay display, - EGLContext context) + EGLContext context, + bool vsync_enabled) : surface_(surface), display_(display), context_(context), + vsync_enabled_(vsync_enabled), width_px_(kInitialWindowWidthPx), height_px_(kInitialWindowHeightPx) { const char* extensions = eglQueryString(display_, EGL_EXTENSIONS); @@ -72,7 +74,6 @@ bool ELinuxEGLSurface::MakeCurrent() const { return false; } -#if defined(ENABLE_EGL_ASYNC_BUFFER_SWAPPING) // Non-blocking when swappipping buffers on Wayland. // However, we might encounter rendering problems on some Wayland compositors // (e.g. weston 9.0) when we use them. @@ -80,11 +81,12 @@ bool ELinuxEGLSurface::MakeCurrent() const { // - https://github.com/sony/flutter-embedded-linux/issues/230 // - https://github.com/sony/flutter-embedded-linux/issues/234 // - https://github.com/sony/flutter-embedded-linux/issues/220 - if (eglSwapInterval(display_, 0) != EGL_TRUE) { - ELINUX_LOG(ERROR) << "Failed to eglSwapInterval(Free): " - << get_egl_error_cause(); + if (!vsync_enabled_) { + if (eglSwapInterval(display_, 0) != EGL_TRUE) { + ELINUX_LOG(ERROR) << "Failed to eglSwapInterval(Free): " + << get_egl_error_cause(); + } } -#endif return true; } diff --git a/src/flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.h b/src/flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.h index d10b709e..885b1138 100644 --- a/src/flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.h +++ b/src/flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.h @@ -19,7 +19,10 @@ namespace flutter { class ELinuxEGLSurface { public: // Note that EGLSurface will be destroyed in this class's destructor. - ELinuxEGLSurface(EGLSurface surface, EGLDisplay display, EGLContext context); + ELinuxEGLSurface(EGLSurface surface, + EGLDisplay display, + EGLContext context, + bool vsync_enabled); ~ELinuxEGLSurface(); bool IsValid() const; @@ -43,6 +46,7 @@ class ELinuxEGLSurface { EGLDisplay display_; EGLSurface surface_; EGLContext context_; + bool vsync_enabled_; size_t width_px_; size_t height_px_; diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h b/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h index beaec990..92c70ad7 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h @@ -125,8 +125,8 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { bool device_found = false; for (auto i = 0; i < devices.size(); i++) { - native_window_ = - std::make_unique(devices[i].c_str(), current_rotation_); + native_window_ = std::make_unique( + devices[i].c_str(), current_rotation_, view_properties_.enable_vsync); if (!native_window_->IsValid()) { ELINUX_LOG(ERROR) << "Failed to create the native window (" << devices[i] << ")."; diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc index 562c9df9..9d2cd7c8 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc @@ -1219,8 +1219,8 @@ bool ELinuxWindowWayland::CreateRenderSurface(int32_t width_px, if (current_rotation_ == 90 || current_rotation_ == 270) { std::swap(width_px, height_px); } - native_window_ = std::make_unique(wl_compositor_, - width_px, height_px); + native_window_ = std::make_unique( + wl_compositor_, width_px, height_px, view_properties_.enable_vsync); wl_surface_add_listener(native_window_->Surface(), &kWlSurfaceListener, this); @@ -1301,7 +1301,8 @@ void ELinuxWindowWayland::CreateDecoration(int32_t width_dip, window_decorations_ = std::make_unique( wl_display_, wl_compositor_, wl_subcompositor_, native_window_->Surface(), - width_dip, height_dip, current_scale_, enable_impeller_); + width_dip, height_dip, current_scale_, enable_impeller_, + view_properties_.enable_vsync); } void ELinuxWindowWayland::DestroyRenderSurface() { diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.cc index 15ede0d4..ea4e4dfc 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.cc @@ -132,7 +132,7 @@ bool ELinuxWindowX11::CreateRenderSurface(int32_t width, } native_window_ = std::make_unique( display_, context_egl->GetAttrib(EGL_NATIVE_VISUAL_ID), - view_properties_.title, width, height); + view_properties_.title, width, height, view_properties_.enable_vsync); if (!native_window_->IsValid()) { ELINUX_LOG(ERROR) << "Failed to create the native window"; return false; diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window.h b/src/flutter/shell/platform/linux_embedded/window/native_window.h index 2d0f77a2..a224b79a 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window.h +++ b/src/flutter/shell/platform/linux_embedded/window/native_window.h @@ -37,6 +37,8 @@ class NativeWindow { return height_; } + bool EnableVsync() const { return enable_vsync_; } + virtual bool IsNeedRecreateSurfaceAfterResize() const { return false; } // Sets a window position. Basically, this API is used for window decorations @@ -59,6 +61,7 @@ class NativeWindow { protected: EGLNativeWindowType window_; EGLNativeWindowType window_offscreen_; + bool enable_vsync_; // Physical width of the window. int32_t width_; // Physical height of the window. diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_drm.cc b/src/flutter/shell/platform/linux_embedded/window/native_window_drm.cc index 22e6e7d9..97d8363c 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_drm.cc +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_drm.cc @@ -16,7 +16,8 @@ namespace flutter { NativeWindowDrm::NativeWindowDrm(const char* device_filename, - const uint16_t rotation) { + const uint16_t rotation, + bool enable_vsync) { drm_device_ = open(device_filename, O_RDWR | O_CLOEXEC); if (drm_device_ == -1) { ELINUX_LOG(ERROR) << "Couldn't open " << device_filename; @@ -27,6 +28,7 @@ NativeWindowDrm::NativeWindowDrm(const char* device_filename, return; } + enable_vsync_ = enable_vsync; valid_ = true; } diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_drm.h b/src/flutter/shell/platform/linux_embedded/window/native_window_drm.h index 9a40b100..2a21b569 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_drm.h +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_drm.h @@ -16,7 +16,9 @@ namespace flutter { class NativeWindowDrm : public NativeWindow { public: - NativeWindowDrm(const char* device_filename, const uint16_t rotation); + NativeWindowDrm(const char* device_filename, + const uint16_t rotation, + bool enable_vsync); virtual ~NativeWindowDrm(); bool ConfigureDisplay(const uint16_t rotation); diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_drm_eglstream.cc b/src/flutter/shell/platform/linux_embedded/window/native_window_drm_eglstream.cc index 97242219..48f8e969 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_drm_eglstream.cc +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_drm_eglstream.cc @@ -19,12 +19,14 @@ constexpr char kCursorNameNone[] = "none"; } // namespace NativeWindowDrmEglstream::NativeWindowDrmEglstream(const char* device_filename, - const uint16_t rotation) - : NativeWindowDrm(device_filename, rotation) { + const uint16_t rotation, + bool enable_vsync) + : NativeWindowDrm(device_filename, rotation, enable_vsync) { if (!valid_) { return; } + enable_vsync_ = enable_vsync; valid_ = ConfigureDisplayAdditional(); // drmIsMaster() is a relatively new API, and the main target of EGLStream is diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_drm_eglstream.h b/src/flutter/shell/platform/linux_embedded/window/native_window_drm_eglstream.h index 27561a61..4bbe59bc 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_drm_eglstream.h +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_drm_eglstream.h @@ -17,7 +17,8 @@ namespace flutter { class NativeWindowDrmEglstream : public NativeWindowDrm { public: NativeWindowDrmEglstream(const char* device_filename, - const uint16_t rotation); + const uint16_t rotation, + bool enable_vsync); ~NativeWindowDrmEglstream(); // |NativeWindowDrm| diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_drm_gbm.cc b/src/flutter/shell/platform/linux_embedded/window/native_window_drm_gbm.cc index 10f4779c..4565fcb8 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_drm_gbm.cc +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_drm_gbm.cc @@ -20,11 +20,13 @@ constexpr uint32_t kCursorBufferHeight = 64; } // namespace NativeWindowDrmGbm::NativeWindowDrmGbm(const char* device_filename, - const uint16_t rotation) - : NativeWindowDrm(device_filename, rotation) { + const uint16_t rotation, + bool enable_vsync) + : NativeWindowDrm(device_filename, rotation, enable_vsync) { if (!valid_) { return; } + enable_vsync_ = enable_vsync; if (!drmIsMaster(drm_device_)) { ELINUX_LOG(ERROR) diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_drm_gbm.h b/src/flutter/shell/platform/linux_embedded/window/native_window_drm_gbm.h index e888b269..d0a2ca5f 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_drm_gbm.h +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_drm_gbm.h @@ -17,7 +17,9 @@ namespace flutter { class NativeWindowDrmGbm : public NativeWindowDrm { public: - NativeWindowDrmGbm(const char* device_filename, const uint16_t rotation); + NativeWindowDrmGbm(const char* device_filename, + const uint16_t rotation, + bool enable_vsync); ~NativeWindowDrmGbm(); // |NativeWindowDrm| diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/native_window_wayland.cc index c35df018..46087281 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_wayland.cc @@ -10,7 +10,8 @@ namespace flutter { NativeWindowWayland::NativeWindowWayland(wl_compositor* compositor, const size_t width_px, - const size_t height_px) { + const size_t height_px, + bool enable_vsync) { surface_ = wl_compositor_create_surface(compositor); if (!surface_) { ELINUX_LOG(ERROR) << "Failed to create the compositor surface."; @@ -40,6 +41,7 @@ NativeWindowWayland::NativeWindowWayland(wl_compositor* compositor, } } + enable_vsync_ = enable_vsync; width_ = width_px; height_ = height_px; valid_ = true; diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_wayland.h b/src/flutter/shell/platform/linux_embedded/window/native_window_wayland.h index b28b0f93..c7b8c275 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_wayland.h +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_wayland.h @@ -17,7 +17,8 @@ class NativeWindowWayland : public NativeWindow { // @param[in] height_px Physical height of the window. NativeWindowWayland(wl_compositor* compositor, const size_t width_px, - const size_t height_px); + const size_t height_px, + bool enable_vsync); ~NativeWindowWayland(); // |NativeWindow| diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_wayland_decoration.cc b/src/flutter/shell/platform/linux_embedded/window/native_window_wayland_decoration.cc index 6595dbc3..5f813962 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_wayland_decoration.cc +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_wayland_decoration.cc @@ -13,7 +13,8 @@ NativeWindowWaylandDecoration::NativeWindowWaylandDecoration( wl_subcompositor* subcompositor, wl_surface* parent_surface, const size_t width_px, - const size_t height_px) { + const size_t height_px, + bool enable_vsync) { surface_ = wl_compositor_create_surface(compositor); if (!surface_) { ELINUX_LOG(ERROR) << "Failed to create the compositor surface."; @@ -35,6 +36,7 @@ NativeWindowWaylandDecoration::NativeWindowWaylandDecoration( return; } + enable_vsync_ = enable_vsync; width_ = width_px; height_ = height_px; valid_ = true; diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_wayland_decoration.h b/src/flutter/shell/platform/linux_embedded/window/native_window_wayland_decoration.h index c48c0954..dc84f3f4 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_wayland_decoration.h +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_wayland_decoration.h @@ -20,7 +20,8 @@ class NativeWindowWaylandDecoration : public NativeWindow { wl_subcompositor* subcompositor, wl_surface* parent_surface, const size_t width_px, - const size_t height_px); + const size_t height_px, + bool enable_vsync); ~NativeWindowWaylandDecoration(); // |NativeWindow| diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_x11.cc b/src/flutter/shell/platform/linux_embedded/window/native_window_x11.cc index 1266b6f0..51f3cc11 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_x11.cc +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_x11.cc @@ -22,7 +22,8 @@ NativeWindowX11::NativeWindowX11(Display* display, VisualID visual_id, const char* title, const size_t width, - const size_t height) { + const size_t height, + bool enable_vsync) { XVisualInfo visualTemplate; visualTemplate.visualid = visual_id; @@ -68,6 +69,7 @@ NativeWindowX11::NativeWindowX11(Display* display, XMapWindow(display, window_); + enable_vsync_ = enable_vsync; width_ = width; height_ = height; valid_ = true; diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_x11.h b/src/flutter/shell/platform/linux_embedded/window/native_window_x11.h index ed39458e..878d864d 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_x11.h +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_x11.h @@ -17,7 +17,8 @@ class NativeWindowX11 : public NativeWindow { VisualID visual_id, const char* title, const size_t width, - const size_t height); + const size_t height, + bool enable_vsync); ~NativeWindowX11() = default; // |NativeWindow| diff --git a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.cc index 531cb5bc..5aa5fb59 100644 --- a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.cc @@ -25,14 +25,15 @@ WindowDecorationsWayland::WindowDecorationsWayland( int32_t width_dip, int32_t height_dip, double pixel_ratio, - bool enable_impeller) { + bool enable_impeller, + bool enable_vsync) { constexpr bool sub_egl_display = true; // title-bar. titlebar_ = std::make_unique( std::make_unique( compositor, subcompositor, root_surface, width_dip * pixel_ratio, - kTitleBarHeightDIP * pixel_ratio), + kTitleBarHeightDIP * pixel_ratio, enable_vsync), std::make_unique(std::make_unique( std::make_unique(display, sub_egl_display), enable_impeller))); @@ -44,7 +45,8 @@ WindowDecorationsWayland::WindowDecorationsWayland( type, std::make_unique( compositor, subcompositor, root_surface, - kButtonWidthDIP * pixel_ratio, kButtonHeightDIP * pixel_ratio), + kButtonWidthDIP * pixel_ratio, kButtonHeightDIP * pixel_ratio, + enable_vsync), std::make_unique(std::make_unique( std::make_unique(display, sub_egl_display), enable_impeller)))); @@ -58,7 +60,8 @@ WindowDecorationsWayland::WindowDecorationsWayland( type, std::make_unique( compositor, subcompositor, root_surface, - kButtonWidthDIP * pixel_ratio, kButtonHeightDIP * pixel_ratio), + kButtonWidthDIP * pixel_ratio, kButtonHeightDIP * pixel_ratio, + enable_vsync), std::make_unique(std::make_unique( std::make_unique(display, sub_egl_display), enable_impeller)))); @@ -72,7 +75,8 @@ WindowDecorationsWayland::WindowDecorationsWayland( type, std::make_unique( compositor, subcompositor, root_surface, - kButtonWidthDIP * pixel_ratio, kButtonHeightDIP * pixel_ratio), + kButtonWidthDIP * pixel_ratio, kButtonHeightDIP * pixel_ratio, + enable_vsync), std::make_unique(std::make_unique( std::make_unique(display, sub_egl_display), enable_impeller)))); diff --git a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.h b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.h index 3e60b3ed..910bf009 100644 --- a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.h +++ b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.h @@ -36,7 +36,8 @@ class WindowDecorationsWayland { int32_t width_dip, int32_t height_dip, double pixel_ratio, - bool enable_impeller); + bool enable_impeller, + bool enable_vsync); ~WindowDecorationsWayland(); void Draw(); From 8d8ab0a823219a5b849da61d9a90ad5695712965 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Tue, 8 Aug 2023 14:03:32 +0000 Subject: [PATCH 067/112] plugins: add settings_plugin (#364) Related issue #2 Signed-off-by: Hidenori Matsubayashi --- cmake/build.cmake | 1 + .../linux_embedded/flutter_elinux_engine.cc | 23 ++----- .../linux_embedded/flutter_elinux_engine.h | 7 +- .../linux_embedded/flutter_elinux_view.cc | 12 ++++ .../linux_embedded/flutter_elinux_view.h | 7 ++ .../linux_embedded/plugins/settings_plugin.cc | 67 +++++++++++++++++++ .../linux_embedded/plugins/settings_plugin.h | 56 ++++++++++++++++ .../window_binding_handler_delegate.h | 3 + 8 files changed, 153 insertions(+), 23 deletions(-) create mode 100644 src/flutter/shell/platform/linux_embedded/plugins/settings_plugin.cc create mode 100644 src/flutter/shell/platform/linux_embedded/plugins/settings_plugin.h diff --git a/cmake/build.cmake b/cmake/build.cmake index cde9cc92..7bd34f7e 100644 --- a/cmake/build.cmake +++ b/cmake/build.cmake @@ -157,6 +157,7 @@ set(ELINUX_COMMON_SRC "src/flutter/shell/platform/linux_embedded/plugins/navigation_plugin.cc" "src/flutter/shell/platform/linux_embedded/plugins/platform_plugin.cc" "src/flutter/shell/platform/linux_embedded/plugins/platform_views_plugin.cc" + "src/flutter/shell/platform/linux_embedded/plugins/settings_plugin.cc" "src/flutter/shell/platform/linux_embedded/plugins/text_input_plugin.cc" "src/flutter/shell/platform/linux_embedded/surface/context_egl.cc" "src/flutter/shell/platform/linux_embedded/surface/egl_utils.cc" diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc index d2510cd0..e71961e8 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc @@ -163,14 +163,6 @@ FlutterELinuxEngine::FlutterELinuxEngine(const FlutterProjectBundle& project) texture_registrar_ = std::make_unique(this, gl_procs_); - // Set up internal channels. - // TODO: Replace this with an embedder.h API. See - // https://github.com/flutter/flutter/issues/71099 - settings_channel_ = - std::make_unique>( - messenger_wrapper_.get(), "flutter/settings", - &JsonMessageCodec::GetInstance()); - vsync_waiter_ = std::make_unique(); } @@ -285,7 +277,10 @@ bool FlutterELinuxEngine::RunWithEntrypoint(const char* entrypoint) { return false; } - SendSystemSettings(); + // TODO: add theme initial value support. + view_->UpdateHighContrastEnabled(false); + + SendSystemLocales(); return true; } @@ -389,7 +384,7 @@ void FlutterELinuxEngine::ReloadSystemFonts() { embedder_api_.ReloadSystemFonts(engine_); } -void FlutterELinuxEngine::SendSystemSettings() { +void FlutterELinuxEngine::SendSystemLocales() { auto languages = flutter::GetPreferredLanguageInfo(); auto flutter_locales = flutter::ConvertToFlutterLocale(languages); @@ -405,14 +400,6 @@ void FlutterELinuxEngine::SendSystemSettings() { if (result != kSuccess) { ELINUX_LOG(ERROR) << "Failed to set up Flutter locales."; } - - rapidjson::Document settings(rapidjson::kObjectType); - auto& allocator = settings.GetAllocator(); - // todo: Use set values instead of fixed values. - settings.AddMember("alwaysUse24HourFormat", true, allocator); - settings.AddMember("textScaleFactor", 1.0, allocator); - settings.AddMember("platformBrightness", "light", allocator); - settings_channel_->Send(settings); } bool FlutterELinuxEngine::RegisterExternalTexture(int64_t texture_id) { diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h index e6595262..c05c1fa3 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h @@ -131,11 +131,11 @@ class FlutterELinuxEngine { // Allows swapping out embedder_api_ calls in tests. friend class EngineEmbedderApiModifier; - // Sends system settings (e.g., locale) to the engine. + // Sends system locales to the engine. // // Should be called just after the engine is run, and after any relevant // system changes. - void SendSystemSettings(); + void SendSystemLocales(); // The handle to the embedder.h engine instance. FLUTTER_API_SYMBOL(FlutterEngine) engine_ = nullptr; @@ -172,9 +172,6 @@ class FlutterELinuxEngine { // Resolved OpenGL functions used by external texture implementations. GlProcs gl_procs_ = {}; - // The MethodChannel used for communication with the Flutter engine. - std::unique_ptr> settings_channel_; - // A callback to be called when the engine (and thus the plugin registrar) // is being destroyed. FlutterDesktopOnPluginRegistrarDestroyed diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc index 2f4d8548..c5c22693 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc @@ -60,6 +60,10 @@ void FlutterELinuxView::SetEngine(std::unique_ptr engine) { // Set up the system channel handlers. auto internal_plugin_messenger = internal_plugin_registrar_->messenger(); + + // Set up internal channels. + // TODO: Replace this with an embedder.h API. See + // https://github.com/flutter/flutter/issues/71099 keyboard_handler_ = std::make_unique(internal_plugin_messenger); textinput_handler_ = std::make_unique( @@ -74,6 +78,8 @@ void FlutterELinuxView::SetEngine(std::unique_ptr engine) { std::make_unique(internal_plugin_messenger); platform_views_handler_ = std::make_unique(internal_plugin_messenger); + settings_handler_ = std::make_unique( + internal_plugin_messenger, binding_handler_.get()); PhysicalWindowBounds bounds = binding_handler_->GetPhysicalWindowBounds(); SendWindowMetrics(bounds.width, bounds.height, @@ -498,4 +504,10 @@ std::pair FlutterELinuxView::GetPointerRotation(double x_px, } return res; } + +void FlutterELinuxView::UpdateHighContrastEnabled(bool enabled) { + // TODO: add UpdateAccessibilityFeatures support + settings_handler_->UpdateHighContrastMode(enabled); +} + } // namespace flutter diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.h b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.h index c554b497..1a5ff519 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.h +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.h @@ -19,6 +19,7 @@ #include "flutter/shell/platform/linux_embedded/plugins/navigation_plugin.h" #include "flutter/shell/platform/linux_embedded/plugins/platform_plugin.h" #include "flutter/shell/platform/linux_embedded/plugins/platform_views_plugin.h" +#include "flutter/shell/platform/linux_embedded/plugins/settings_plugin.h" #include "flutter/shell/platform/linux_embedded/plugins/text_input_plugin.h" #include "flutter/shell/platform/linux_embedded/public/flutter_elinux.h" #include "flutter/shell/platform/linux_embedded/public/flutter_platform_views.h" @@ -144,6 +145,9 @@ class FlutterELinuxView : public WindowBindingHandlerDelegate { void OnVsync(uint64_t frame_start_time_nanos, uint64_t frame_target_time_nanos) override; + // |WindowBindingHandlerDelegate| + void UpdateHighContrastEnabled(bool enabled) override; + private: // Struct holding the mouse state. The engine doesn't keep track of which // mouse buttons have been pressed, so it's the embedding's responsibility. @@ -290,6 +294,9 @@ class FlutterELinuxView : public WindowBindingHandlerDelegate { // Handler for flutter/platform_views channel. std::unique_ptr platform_views_handler_; + // Handler for flutter/settings channel. + std::unique_ptr settings_handler_; + // Currently configured WindowBindingHandler for view. std::unique_ptr binding_handler_; diff --git a/src/flutter/shell/platform/linux_embedded/plugins/settings_plugin.cc b/src/flutter/shell/platform/linux_embedded/plugins/settings_plugin.cc new file mode 100644 index 00000000..3492cdb5 --- /dev/null +++ b/src/flutter/shell/platform/linux_embedded/plugins/settings_plugin.cc @@ -0,0 +1,67 @@ +// Copyright 2023 Sony Corporation. All rights reserved. +// 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. + +#include "flutter/shell/platform/linux_embedded/plugins/settings_plugin.h" + +#include "flutter/shell/platform/common/json_message_codec.h" + +namespace flutter { + +namespace { +constexpr char kChannelName[] = "flutter/settings"; + +constexpr char kAlwaysUse24HourFormat[] = "alwaysUse24HourFormat"; +constexpr char kTextScaleFactor[] = "textScaleFactor"; +constexpr char kPlatformBrightness[] = "platformBrightness"; + +constexpr char kPlatformBrightnessDark[] = "dark"; +constexpr char kPlatformBrightnessLight[] = "light"; +} // namespace + +SettingsPlugin::SettingsPlugin(BinaryMessenger* messenger, + WindowBindingHandler* delegate) + : channel_(std::make_unique>( + messenger, + kChannelName, + &JsonMessageCodec::GetInstance())), + delegate_(delegate) {} + +void SettingsPlugin::SendSettings() { + rapidjson::Document settings(rapidjson::kObjectType); + auto& allocator = settings.GetAllocator(); + settings.AddMember(kAlwaysUse24HourFormat, GetAlwaysUse24HourFormat(), + allocator); + settings.AddMember(kTextScaleFactor, GetTextScaleFactor(), allocator); + + if (GetPreferredBrightness() == PlatformBrightness::kDark) { + settings.AddMember(kPlatformBrightness, kPlatformBrightnessDark, allocator); + } else { + settings.AddMember(kPlatformBrightness, kPlatformBrightnessLight, + allocator); + } + channel_->Send(settings); +} + +bool SettingsPlugin::GetAlwaysUse24HourFormat() { + // The current OS does not have 24 hour format factor. + return true; +} + +float SettingsPlugin::GetTextScaleFactor() { + // The current OS does not have text scale factor. + return 1.0; +} + +SettingsPlugin::PlatformBrightness SettingsPlugin::GetPreferredBrightness() { + // The current OS does not have brightness factor. + return PlatformBrightness::kLight; +} + +void SettingsPlugin::UpdateHighContrastMode(bool is_high_contrast) { + is_high_contrast_ = is_high_contrast; + SendSettings(); +} + +} // namespace flutter diff --git a/src/flutter/shell/platform/linux_embedded/plugins/settings_plugin.h b/src/flutter/shell/platform/linux_embedded/plugins/settings_plugin.h new file mode 100644 index 00000000..25f10585 --- /dev/null +++ b/src/flutter/shell/platform/linux_embedded/plugins/settings_plugin.h @@ -0,0 +1,56 @@ +// Copyright 2023 Sony Corporation. All rights reserved. +// 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. + +#ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_PLUGINS_SETTINGS_PLUGIN_H_ +#define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_PLUGINS_SETTINGS_PLUGIN_H_ + +#include + +#include + +#include "flutter/shell/platform/common/client_wrapper/include/flutter/basic_message_channel.h" +#include "flutter/shell/platform/common/client_wrapper/include/flutter/binary_messenger.h" +#include "flutter/shell/platform/linux_embedded/window_binding_handler.h" + +namespace flutter { + +// Abstract settings plugin. +// +// Used to look up and notify Flutter of user-configured system settings. +// These are typically set in the control panel. +class SettingsPlugin { + public: + enum struct PlatformBrightness { kDark, kLight }; + + explicit SettingsPlugin(BinaryMessenger* messenger, + WindowBindingHandler* delegate); + ~SettingsPlugin() = default; + + // Sends settings (e.g., platform brightness) to the engine. + void SendSettings(); + + // Update the high contrast status of the system. + void UpdateHighContrastMode(bool is_high_contrast); + + private: + // Returns `true` if the user uses 24 hour time. + bool GetAlwaysUse24HourFormat(); + + // Returns the user-preferred text scale factor. + float GetTextScaleFactor(); + + // Returns the user-preferred brightness. + PlatformBrightness GetPreferredBrightness(); + + bool is_high_contrast_ = false; + + private: + std::unique_ptr> channel_; + WindowBindingHandler* delegate_; +}; + +} // namespace flutter + +#endif // FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_PLUGINS_SETTINGS_PLUGIN_H_ diff --git a/src/flutter/shell/platform/linux_embedded/window_binding_handler_delegate.h b/src/flutter/shell/platform/linux_embedded/window_binding_handler_delegate.h index 944e0e07..fd7369e4 100644 --- a/src/flutter/shell/platform/linux_embedded/window_binding_handler_delegate.h +++ b/src/flutter/shell/platform/linux_embedded/window_binding_handler_delegate.h @@ -104,6 +104,9 @@ class WindowBindingHandlerDelegate { // Typically called by currently configured WindowBindingHandler virtual void OnVsync(uint64_t last_frame_time_nanos, uint64_t vsync_interval_time_nanos) = 0; + + // Update the status of the high contrast feature + virtual void UpdateHighContrastEnabled(bool enabled) = 0; }; } // namespace flutter From d562681fd4589e7462f4c49c131798e8e8552fa1 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Wed, 9 Aug 2023 11:06:56 +0000 Subject: [PATCH 068/112] wayland: add trace level logs to wayland listeners (#365) This change adds trace level logs to improve logging and debuggability. Signed-off-by: Hidenori Matsubayashi --- .../window/elinux_window_wayland.cc | 189 +++++++++++++++--- 1 file changed, 158 insertions(+), 31 deletions(-) diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc index 9d2cd7c8..08ea910d 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc @@ -50,20 +50,26 @@ const wl_registry_listener ELinuxWindowWayland::kWlRegistryListener = { uint32_t name, const char* interface, uint32_t version) { + ELINUX_LOG(TRACE) << "wl_registry_listener.global"; + auto self = reinterpret_cast(data); self->WlRegistryHandler(wl_registry, name, interface, version); }, .global_remove = [](void* data, wl_registry* wl_registry, uint32_t name) { + ELINUX_LOG(TRACE) << "wl_registry_listener.global_remove"; + auto self = reinterpret_cast(data); self->WlUnRegistryHandler(wl_registry, name); }, }; const xdg_wm_base_listener ELinuxWindowWayland::kXdgWmBaseListener = { - .ping = [](void* data, - xdg_wm_base* xdg_wm_base, - uint32_t serial) { xdg_wm_base_pong(xdg_wm_base, serial); }, + .ping = + [](void* data, xdg_wm_base* xdg_wm_base, uint32_t serial) { + ELINUX_LOG(TRACE) << "xdg_wm_base_listener.ping"; + xdg_wm_base_pong(xdg_wm_base, serial); + }, }; const xdg_surface_listener ELinuxWindowWayland::kXdgSurfaceListener = { @@ -120,12 +126,16 @@ const xdg_toplevel_listener ELinuxWindowWayland::kXdgToplevelListener = { return; } + ELINUX_LOG(TRACE) + << "request redraw: " << next_width << ", " << next_height; self->view_properties_.width = next_width; self->view_properties_.height = next_height; self->request_redraw_ = true; }, .close = [](void* data, xdg_toplevel* xdg_toplevel) { + ELINUX_LOG(TRACE) << "xdg_toplevel_listener.close"; + auto self = reinterpret_cast(data); self->running_ = false; }}; @@ -133,6 +143,8 @@ const xdg_toplevel_listener ELinuxWindowWayland::kXdgToplevelListener = { const wl_surface_listener ELinuxWindowWayland::kWlSurfaceListener = { .enter = [](void* data, wl_surface* wl_surface, wl_output* output) { + ELINUX_LOG(TRACE) << "wl_surface_listener.enter"; + // The compositor can send a null output: crbug.com/1332540 if (!output) { ELINUX_LOG(ERROR) << "cannot enter a NULL output"; @@ -149,6 +161,8 @@ const wl_surface_listener ELinuxWindowWayland::kWlSurfaceListener = { }, .leave = [](void* data, wl_surface* wl_surface, wl_output* output) { + ELINUX_LOG(TRACE) << "wl_surface_listener.leave"; + // The compositor can send a null output: crbug.com/1332540 if (!output) { ELINUX_LOG(ERROR) << "cannot leave a NULL output"; @@ -167,9 +181,11 @@ const wl_surface_listener ELinuxWindowWayland::kWlSurfaceListener = { const wp_presentation_listener ELinuxWindowWayland::kWpPresentationListener = { .clock_id = [](void* data, wp_presentation* wp_presentation, uint32_t clk_id) { + ELINUX_LOG(TRACE) << "wp_presentation_listener.clock_id"; + auto self = reinterpret_cast(data); self->wp_presentation_clk_id_ = clk_id; - ELINUX_LOG(TRACE) << "presentation info: clk_id = " << clk_id; + ELINUX_LOG(TRACE) << "clk_id = " << clk_id; }, }; @@ -178,7 +194,10 @@ const wp_presentation_feedback_listener .sync_output = [](void* data, struct wp_presentation_feedback* wp_presentation_feedback, - wl_output* output) {}, + wl_output* output) { + ELINUX_LOG(TRACE) + << "wp_presentation_feedback_listener.sync_output"; + }, .presented = [](void* data, struct wp_presentation_feedback* wp_presentation_feedback, @@ -189,6 +208,9 @@ const wp_presentation_feedback_listener uint32_t seq_hi, uint32_t seq_lo, uint32_t flags) { + ELINUX_LOG(TRACE) + << "wp_presentation_feedback_listener.presented"; + auto self = reinterpret_cast(data); self->last_frame_time_nanos_ = (((static_cast(tv_sec_hi) << 32) + tv_sec_lo) * @@ -209,8 +231,10 @@ const wp_presentation_feedback_listener .discarded = [](void* data, struct wp_presentation_feedback* wp_presentation_feedback) { - auto self = reinterpret_cast(data); + ELINUX_LOG(TRACE) + << "wp_presentation_feedback_listener.discarded"; + auto self = reinterpret_cast(data); if (self->window_decorations_) { self->window_decorations_->Draw(); } @@ -225,6 +249,8 @@ const wp_presentation_feedback_listener const wl_callback_listener ELinuxWindowWayland::kWlSurfaceFrameListener = { .done = [](void* data, wl_callback* wl_callback, uint32_t time) { + ELINUX_LOG(TRACE) << "wl_callback_listener.done"; + // The presentation-time is an extended protocol and isn't supported // by all compositors. This path is for when it wasn't supported. auto self = reinterpret_cast(data); @@ -246,8 +272,9 @@ const wl_callback_listener ELinuxWindowWayland::kWlSurfaceFrameListener = { const wl_seat_listener ELinuxWindowWayland::kWlSeatListener = { .capabilities = [](void* data, wl_seat* seat, uint32_t caps) -> void { - auto self = reinterpret_cast(data); + ELINUX_LOG(TRACE) << "wl_seat_listener.capabilities"; + auto self = reinterpret_cast(data); if ((caps & WL_SEAT_CAPABILITY_POINTER) && !self->wl_pointer_) { self->wl_pointer_ = wl_seat_get_pointer(seat); wl_pointer_add_listener(self->wl_pointer_, &kWlPointerListener, self); @@ -274,6 +301,7 @@ const wl_seat_listener ELinuxWindowWayland::kWlSeatListener = { } }, .name = [](void* data, struct wl_seat* wl_seat, const char* name) -> void { + ELINUX_LOG(TRACE) << "wl_seat_listener.name"; }, }; @@ -284,6 +312,8 @@ const wl_pointer_listener ELinuxWindowWayland::kWlPointerListener = { wl_surface* surface, wl_fixed_t surface_x, wl_fixed_t surface_y) -> void { + ELINUX_LOG(TRACE) << "wl_pointer_listener.enter"; + auto self = reinterpret_cast(data); self->wl_current_surface_ = surface; self->serial_ = serial; @@ -305,6 +335,8 @@ const wl_pointer_listener ELinuxWindowWayland::kWlPointerListener = { wl_pointer* pointer, uint32_t serial, wl_surface* surface) -> void { + ELINUX_LOG(TRACE) << "wl_pointer_listener.leave"; + auto self = reinterpret_cast(data); self->wl_current_surface_ = surface; self->serial_ = serial; @@ -326,6 +358,8 @@ const wl_pointer_listener ELinuxWindowWayland::kWlPointerListener = { uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) -> void { + ELINUX_LOG(TRACE) << "wl_pointer_listener.motion"; + auto self = reinterpret_cast(data); if (self->binding_handler_delegate_) { double x_px = wl_fixed_to_double(surface_x) * self->current_scale_; @@ -341,6 +375,8 @@ const wl_pointer_listener ELinuxWindowWayland::kWlPointerListener = { uint32_t time, uint32_t button, uint32_t status) -> void { + ELINUX_LOG(TRACE) << "wl_pointer_listener.button"; + auto self = reinterpret_cast(data); self->serial_ = serial; @@ -428,6 +464,8 @@ const wl_pointer_listener ELinuxWindowWayland::kWlPointerListener = { uint32_t time, uint32_t axis, wl_fixed_t value) -> void { + ELINUX_LOG(TRACE) << "wl_pointer_listener.axis"; + auto self = reinterpret_cast(data); if (self->binding_handler_delegate_) { double delta = wl_fixed_to_double(value); @@ -450,6 +488,8 @@ const wl_touch_listener ELinuxWindowWayland::kWlTouchListener = { int32_t id, wl_fixed_t surface_x, wl_fixed_t surface_y) -> void { + ELINUX_LOG(TRACE) << "wl_touch_listener.down"; + auto self = reinterpret_cast(data); self->serial_ = serial; if (self->binding_handler_delegate_) { @@ -463,6 +503,8 @@ const wl_touch_listener ELinuxWindowWayland::kWlTouchListener = { uint32_t serial, uint32_t time, int32_t id) -> void { + ELINUX_LOG(TRACE) << "wl_touch_listener.up"; + auto self = reinterpret_cast(data); self->serial_ = serial; if (self->binding_handler_delegate_) { @@ -475,6 +517,8 @@ const wl_touch_listener ELinuxWindowWayland::kWlTouchListener = { int32_t id, wl_fixed_t surface_x, wl_fixed_t surface_y) -> void { + ELINUX_LOG(TRACE) << "wl_touch_listener.motion"; + auto self = reinterpret_cast(data); if (self->binding_handler_delegate_) { double x = wl_fixed_to_double(surface_x); @@ -484,6 +528,8 @@ const wl_touch_listener ELinuxWindowWayland::kWlTouchListener = { }, .frame = [](void* data, wl_touch* wl_touch) -> void {}, .cancel = [](void* data, wl_touch* wl_touch) -> void { + ELINUX_LOG(TRACE) << "wl_touch_listener.cancel"; + auto self = reinterpret_cast(data); if (self->binding_handler_delegate_) { self->binding_handler_delegate_->OnTouchCancel(); @@ -497,6 +543,8 @@ const wl_keyboard_listener ELinuxWindowWayland::kWlKeyboardListener = { uint32_t format, int fd, uint32_t size) -> void { + ELINUX_LOG(TRACE) << "wl_keyboard_listener.keymap"; + auto self = reinterpret_cast(data); assert(format == WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1); if (self->binding_handler_delegate_) { @@ -508,6 +556,8 @@ const wl_keyboard_listener ELinuxWindowWayland::kWlKeyboardListener = { uint32_t serial, wl_surface* surface, wl_array* keys) -> void { + ELINUX_LOG(TRACE) << "wl_keyboard_listener.enter"; + auto self = reinterpret_cast(data); self->serial_ = serial; }, @@ -515,6 +565,8 @@ const wl_keyboard_listener ELinuxWindowWayland::kWlKeyboardListener = { wl_keyboard* wl_keyboard, uint32_t serial, wl_surface* surface) -> void { + ELINUX_LOG(TRACE) << "wl_keyboard_listener.leave"; + auto self = reinterpret_cast(data); self->serial_ = serial; }, @@ -524,6 +576,8 @@ const wl_keyboard_listener ELinuxWindowWayland::kWlKeyboardListener = { uint32_t time, uint32_t key, uint32_t state) -> void { + ELINUX_LOG(TRACE) << "wl_keyboard_listener.key"; + auto self = reinterpret_cast(data); self->serial_ = serial; if (self->binding_handler_delegate_) { @@ -538,6 +592,8 @@ const wl_keyboard_listener ELinuxWindowWayland::kWlKeyboardListener = { uint32_t mods_latched, uint32_t mods_locked, uint32_t group) -> void { + ELINUX_LOG(TRACE) << "wl_keyboard_listener.modifiers"; + auto self = reinterpret_cast(data); if (self->binding_handler_delegate_) { self->binding_handler_delegate_->OnKeyModifiers( @@ -545,7 +601,7 @@ const wl_keyboard_listener ELinuxWindowWayland::kWlKeyboardListener = { } }, .repeat_info = [](void* data, wl_keyboard* wl_keyboard, int rate, int delay) - -> void {}, + -> void { ELINUX_LOG(TRACE) << "wl_keyboard_listener.repeat_info"; }, }; const wl_output_listener ELinuxWindowWayland::kWlOutputListener = { @@ -558,13 +614,17 @@ const wl_output_listener ELinuxWindowWayland::kWlOutputListener = { int32_t subpixel, const char* make, const char* model, - int32_t output_transform) -> void {}, + int32_t output_transform) -> void { + ELINUX_LOG(TRACE) << "wl_output_listener.geometry"; + }, .mode = [](void* data, wl_output* wl_output, uint32_t flags, int32_t width, int32_t height, int32_t refresh) -> void { + ELINUX_LOG(TRACE) << "wl_output_listener.mode"; + auto self = reinterpret_cast(data); if (flags & WL_OUTPUT_MODE_CURRENT) { if (self->current_rotation_ == 90 || self->current_rotation_ == 270) { @@ -606,10 +666,13 @@ const wl_output_listener ELinuxWindowWayland::kWlOutputListener = { } } }, - .done = [](void* data, wl_output* wl_output) -> void {}, + .done = [](void* data, wl_output* wl_output) -> void { + ELINUX_LOG(TRACE) << "wl_output_listener.done"; + }, .scale = [](void* data, wl_output* wl_output, int32_t scale) -> void { - auto self = reinterpret_cast(data); + ELINUX_LOG(TRACE) << "wl_output_listener.scale"; + auto self = reinterpret_cast(data); const uint32_t output_id = wl_proxy_get_id(reinterpret_cast(wl_output)); @@ -627,6 +690,8 @@ const zwp_text_input_v1_listener ELinuxWindowWayland::kZwpTextInputV1Listener = .enter = [](void* data, zwp_text_input_v1* zwp_text_input_v1, wl_surface* surface) -> void { + ELINUX_LOG(TRACE) << "zwp_text_input_v1_listener.enter"; + auto self = reinterpret_cast(data); // If there is no input data, the backspace key cannot be used, // so set dummy data. @@ -636,6 +701,8 @@ const zwp_text_input_v1_listener ELinuxWindowWayland::kZwpTextInputV1Listener = } }, .leave = [](void* data, zwp_text_input_v1* zwp_text_input_v1) -> void { + ELINUX_LOG(TRACE) << "zwp_text_input_v1_listener.leave"; + auto self = reinterpret_cast(data); if (self->zwp_text_input_v1_) { zwp_text_input_v1_hide_input_panel(self->zwp_text_input_v1_); @@ -643,15 +710,21 @@ const zwp_text_input_v1_listener ELinuxWindowWayland::kZwpTextInputV1Listener = }, .modifiers_map = [](void* data, zwp_text_input_v1* zwp_text_input_v1, - wl_array* map) -> void {}, + wl_array* map) -> void { + ELINUX_LOG(TRACE) << "zwp_text_input_v1_listener.modifiers_map"; + }, .input_panel_state = [](void* data, zwp_text_input_v1* zwp_text_input_v1, - uint32_t state) -> void {}, + uint32_t state) -> void { + ELINUX_LOG(TRACE) << "zwp_text_input_v1_listener.input_panel_state"; + }, .preedit_string = [](void* data, zwp_text_input_v1* zwp_text_input_v1, uint32_t serial, const char* text, const char* commit) -> void { + ELINUX_LOG(TRACE) << "zwp_text_input_v1_listener.preedit_string"; + auto self = reinterpret_cast(data); if (self->binding_handler_delegate_ && strlen(text)) { self->binding_handler_delegate_->OnVirtualKey(text[0]); @@ -668,14 +741,20 @@ const zwp_text_input_v1_listener ELinuxWindowWayland::kZwpTextInputV1Listener = zwp_text_input_v1* zwp_text_input_v1, uint32_t index, uint32_t length, - uint32_t style) -> void {}, + uint32_t style) -> void { + ELINUX_LOG(TRACE) << "zwp_text_input_v1_listener.preedit_styling"; + }, .preedit_cursor = [](void* data, zwp_text_input_v1* zwp_text_input_v1, - int32_t index) -> void {}, + int32_t index) -> void { + ELINUX_LOG(TRACE) << "zwp_text_input_v1_listener.preedit_cursor"; + }, .commit_string = [](void* data, zwp_text_input_v1* zwp_text_input_v1, uint32_t serial, const char* text) -> void { + ELINUX_LOG(TRACE) << "zwp_text_input_v1_listener.commit_string"; + // commit_string is notified only when the space key is pressed. auto self = reinterpret_cast(data); if (self->binding_handler_delegate_ && strlen(text)) { @@ -691,11 +770,16 @@ const zwp_text_input_v1_listener ELinuxWindowWayland::kZwpTextInputV1Listener = .cursor_position = [](void* data, zwp_text_input_v1* zwp_text_input_v1, int32_t index, - int32_t anchor) -> void {}, + int32_t anchor) -> void { + ELINUX_LOG(TRACE) << "zwp_text_input_v1_listener.cursor_position"; + }, .delete_surrounding_text = [](void* data, zwp_text_input_v1* zwp_text_input_v1, int32_t index, uint32_t length) -> void { + ELINUX_LOG(TRACE) + << "zwp_text_input_v1_listener.delete_surrounding_text"; + auto self = reinterpret_cast(data); if (self->binding_handler_delegate_) { self->binding_handler_delegate_->OnVirtualSpecialKey(KEY_BACKSPACE); @@ -714,6 +798,8 @@ const zwp_text_input_v1_listener ELinuxWindowWayland::kZwpTextInputV1Listener = uint32_t sym, uint32_t state, uint32_t modifiers) -> void { + ELINUX_LOG(TRACE) << "zwp_text_input_v1_listener.keysym"; + auto self = reinterpret_cast(data); if ((state == WL_KEYBOARD_KEY_STATE_PRESSED) && (self->binding_handler_delegate_)) { @@ -744,11 +830,15 @@ const zwp_text_input_v1_listener ELinuxWindowWayland::kZwpTextInputV1Listener = .language = [](void* data, zwp_text_input_v1* zwp_text_input_v1, uint32_t serial, - const char* language) -> void {}, + const char* language) -> void { + ELINUX_LOG(TRACE) << "zwp_text_input_v1_listener.language"; + }, .text_direction = [](void* data, zwp_text_input_v1* zwp_text_input_v1, uint32_t serial, - uint32_t direction) -> void {}, + uint32_t direction) -> void { + ELINUX_LOG(TRACE) << "zwp_text_input_v1_listener.text_direction"; + }, }; const zwp_text_input_v3_listener ELinuxWindowWayland::kZwpTextInputV3Listener = @@ -756,6 +846,8 @@ const zwp_text_input_v3_listener ELinuxWindowWayland::kZwpTextInputV3Listener = .enter = [](void* data, zwp_text_input_v3* zwp_text_input_v3, wl_surface* surface) -> void { + ELINUX_LOG(TRACE) << "zwp_text_input_v3_listener.enter"; + // To appear the on-screen keyboard when the user returns to a Flutter // app which needs to show the on-screen keyboard. auto self = reinterpret_cast(data); @@ -765,15 +857,21 @@ const zwp_text_input_v3_listener ELinuxWindowWayland::kZwpTextInputV3Listener = }, .leave = [](void* data, zwp_text_input_v3* zwp_text_input_v3, - wl_surface* surface) -> void {}, + wl_surface* surface) -> void { + ELINUX_LOG(TRACE) << "zwp_text_input_v3_listener.leave"; + }, .preedit_string = [](void* data, zwp_text_input_v3* zwp_text_input_v3, const char* text, int32_t cursor_begin, - int32_t cursor_end) -> void {}, + int32_t cursor_end) -> void { + ELINUX_LOG(TRACE) << "zwp_text_input_v3_listener.preedit_string"; + }, .commit_string = [](void* data, zwp_text_input_v3* zwp_text_input_v3, const char* text) -> void { + ELINUX_LOG(TRACE) << "zwp_text_input_v3_listener.commit_string"; + auto self = reinterpret_cast(data); if (self->binding_handler_delegate_ && strlen(text)) { self->binding_handler_delegate_->OnVirtualKey(text[0]); @@ -782,33 +880,50 @@ const zwp_text_input_v3_listener ELinuxWindowWayland::kZwpTextInputV3Listener = .delete_surrounding_text = [](void* data, zwp_text_input_v3* zwp_text_input_v3, uint32_t before_length, - uint32_t after_length) -> void {}, + uint32_t after_length) -> void { + ELINUX_LOG(TRACE) + << "zwp_text_input_v3_listener.delete_surrounding_text"; + }, .done = [](void* data, zwp_text_input_v3* zwp_text_input_v3, - uint32_t serial) -> void {}, + uint32_t serial) -> void { + ELINUX_LOG(TRACE) << "zwp_text_input_v3_listener.done"; + }, }; const wl_data_device_listener ELinuxWindowWayland::kWlDataDeviceListener = { .data_offer = [](void* data, wl_data_device* wl_data_device, - wl_data_offer* offer) -> void {}, + wl_data_offer* offer) -> void { + ELINUX_LOG(TRACE) << "wl_data_device_listener.data_offer"; + }, .enter = [](void* data, wl_data_device* wl_data_device, uint32_t serial, wl_surface* surface, wl_fixed_t x, wl_fixed_t y, - wl_data_offer* offer) -> void {}, - .leave = [](void* data, wl_data_device* wl_data_device) -> void {}, + wl_data_offer* offer) -> void { + ELINUX_LOG(TRACE) << "wl_data_device_listener.enter"; + }, + .leave = [](void* data, wl_data_device* wl_data_device) -> void { + ELINUX_LOG(TRACE) << "wl_data_device_listener.leave"; + }, .motion = [](void* data, wl_data_device* wl_data_device, uint32_t time, wl_fixed_t x, - wl_fixed_t y) -> void {}, - .drop = [](void* data, wl_data_device* wl_data_device) -> void {}, + wl_fixed_t y) -> void { + ELINUX_LOG(TRACE) << "wl_data_device_listener.motion"; + }, + .drop = [](void* data, wl_data_device* wl_data_device) -> void { + ELINUX_LOG(TRACE) << "wl_data_device_listener.drop"; + }, .selection = [](void* data, wl_data_device* wl_data_device, wl_data_offer* offer) -> void { + ELINUX_LOG(TRACE) << "wl_data_device_listener.selection"; + auto self = reinterpret_cast(data); if (self->wl_data_offer_) { wl_data_offer_destroy(self->wl_data_offer_); @@ -820,11 +935,15 @@ const wl_data_device_listener ELinuxWindowWayland::kWlDataDeviceListener = { const wl_data_source_listener ELinuxWindowWayland::kWlDataSourceListener = { .target = [](void* data, wl_data_source* wl_data_source, - const char* mime_type) -> void {}, + const char* mime_type) -> void { + ELINUX_LOG(TRACE) << "wl_data_device_listener.target"; + }, .send = [](void* data, wl_data_source* wl_data_source, const char* mime_type, int32_t fd) -> void { + ELINUX_LOG(TRACE) << "wl_data_device_listener.send"; + if (strcmp(mime_type, kClipboardMimeTypeText)) { ELINUX_LOG(ERROR) << "Not expected mime_type: " << mime_type; return; @@ -836,6 +955,8 @@ const wl_data_source_listener ELinuxWindowWayland::kWlDataSourceListener = { close(fd); }, .cancelled = [](void* data, wl_data_source* wl_data_source) -> void { + ELINUX_LOG(TRACE) << "wl_data_device_listener.cancelled"; + auto self = reinterpret_cast(data); self->clipboard_data_ = ""; if (self->wl_data_source_) { @@ -844,11 +965,17 @@ const wl_data_source_listener ELinuxWindowWayland::kWlDataSourceListener = { } }, .dnd_drop_performed = [](void* data, - wl_data_source* wl_data_source) -> void {}, - .dnd_finished = [](void* data, wl_data_source* wl_data_source) -> void {}, + wl_data_source* wl_data_source) -> void { + ELINUX_LOG(TRACE) << "wl_data_device_listener.dnd_drop_performed"; + }, + .dnd_finished = [](void* data, wl_data_source* wl_data_source) -> void { + ELINUX_LOG(TRACE) << "wl_data_device_listener.dnd_finished"; + }, .action = [](void* data, wl_data_source* wl_data_source, - uint32_t dnd_action) -> void {}, + uint32_t dnd_action) -> void { + ELINUX_LOG(TRACE) << "wl_data_device_listener.action"; + }, }; const zxdg_toplevel_decoration_v1_listener From fe14f60aec0c7e929e055983d73b3e9bba8e04a5 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Wed, 9 Aug 2023 12:31:50 +0000 Subject: [PATCH 069/112] wayland: fix layout is skewed issue when using decoration option (#366) This change fixes the layout issue that is skewed when using decoration option. Related PR #359 Signed-off-by: Hidenori Matsubayashi --- .../linux_embedded/window/elinux_window.h | 2 ++ .../window/elinux_window_wayland.cc | 30 ++++++++++++++----- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window.h b/src/flutter/shell/platform/linux_embedded/window/elinux_window.h index eaec182d..8c4e9d15 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window.h +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window.h @@ -40,6 +40,8 @@ class ELinuxWindow { } FlutterDesktopViewProperties view_properties_; + int32_t display_max_width_ = -1; + int32_t display_max_height_ = -1; double current_scale_ = 1.0; uint16_t current_rotation_ = 0; // The x coordinate of the pointer in physical pixels. diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc index 08ea910d..1c74ad08 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc @@ -78,17 +78,28 @@ const xdg_surface_listener ELinuxWindowWayland::kXdgSurfaceListener = { ELINUX_LOG(TRACE) << "xdg_surface_listener.configure"; auto self = reinterpret_cast(data); - constexpr int32_t x = 0; - int32_t y = 0; if (self->window_decorations_) { - // TODO: Moves the window to the bottom to show the window - // decorations, but the bottom area of the window will be hidden - // because of this shifting. + // Shift the window position to the bottom to show decoration + // even when the window is displayed in the upper left corner + // of the screen + constexpr int32_t x = 0; + int32_t y = 0; y = -self->window_decorations_->Height(); + + auto width = self->view_properties_.width; + auto height = self->view_properties_.height; + if (!self->maximised_) { + height -= y; + } + + // clip + if (self->display_max_height_ > 0) { + height = std::min(height, self->display_max_height_); + } + + xdg_surface_set_window_geometry(xdg_surface, x, y, width, height); } - xdg_surface_set_window_geometry(xdg_surface, x, y, - self->view_properties_.width, - self->view_properties_.height); + xdg_surface_ack_configure(xdg_surface, serial); if (self->wait_for_configure_) { self->wait_for_configure_ = false; @@ -634,6 +645,9 @@ const wl_output_listener ELinuxWindowWayland::kWlOutputListener = { ELINUX_LOG(INFO) << "Display output info: width = " << width << ", height = " << height << ", refresh = " << refresh; + self->display_max_width_ = width; + self->display_max_height_ = height; + // Some composers send 0 for the refresh value. if (refresh != 0) { self->frame_rate_ = refresh; From c5a7852198a9821d4c58a5c33bf0185b57a2c05a Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Thu, 10 Aug 2023 13:18:23 +0000 Subject: [PATCH 070/112] settings_plugin: add text-scaling-factor commandline option (#367) This change adds text-scaling-factor to command-line option. Related issue #2 Signed-off-by: Hidenori Matsubayashi --- .../flutter_embedder_options.h | 8 ++++++++ examples/flutter-drm-eglstream-backend/main.cc | 1 + .../flutter_embedder_options.h | 8 ++++++++ examples/flutter-drm-gbm-backend/main.cc | 1 + .../flutter_embedder_options.h | 8 ++++++++ examples/flutter-external-texture-plugin/main.cc | 1 + .../flutter_embedder_options.h | 8 ++++++++ examples/flutter-video-player-plugin/main.cc | 1 + .../flutter_embedder_options.h | 8 ++++++++ examples/flutter-wayland-client/main.cc | 1 + .../flutter-x11-client/flutter_embedder_options.h | 8 ++++++++ examples/flutter-x11-client/main.cc | 1 + src/client_wrapper/flutter_view_controller.cc | 1 + .../include/flutter/flutter_view_controller.h | 3 +++ .../platform/linux_embedded/flutter_elinux.cc | 3 +++ .../linux_embedded/flutter_elinux_engine.cc | 14 +++++++++----- .../linux_embedded/flutter_elinux_engine.h | 3 +++ .../platform/linux_embedded/flutter_elinux_view.cc | 4 ++++ .../platform/linux_embedded/flutter_elinux_view.h | 3 +++ .../linux_embedded/plugins/settings_plugin.cc | 8 ++++++-- .../linux_embedded/plugins/settings_plugin.h | 8 +++++--- .../linux_embedded/public/flutter_elinux.h | 3 +++ .../window_binding_handler_delegate.h | 3 +++ 23 files changed, 97 insertions(+), 10 deletions(-) diff --git a/examples/flutter-drm-eglstream-backend/flutter_embedder_options.h b/examples/flutter-drm-eglstream-backend/flutter_embedder_options.h index 8a5cfd41..04138b3f 100644 --- a/examples/flutter-drm-eglstream-backend/flutter_embedder_options.h +++ b/examples/flutter-drm-eglstream-backend/flutter_embedder_options.h @@ -21,6 +21,8 @@ class FlutterEmbedderOptions { options_.AddInt("rotation", "r", "Window rotation(degree) [0(default)|90|180|270]", 0, false); + options_.AddDouble("text-scaling-factor", "x", "Text scaling factor", 1.0, + false); options_.AddDouble("force-scale-factor", "s", "Force a scale factor instead using default value", 1.0, false); @@ -83,6 +85,8 @@ class FlutterEmbedderOptions { } } + text_scale_factor_ = options_.GetValue("text-scaling-factor"); + if (options_.Exist("force-scale-factor")) { is_force_scale_factor_ = true; scale_factor_ = options_.GetValue("force-scale-factor"); @@ -154,6 +158,9 @@ class FlutterEmbedderOptions { flutter::FlutterViewController::ViewRotation WindowRotation() const { return window_view_rotation_; } + double TextScaleFactor() const { + return text_scale_factor_; + } bool IsForceScaleFactor() const { return is_force_scale_factor_; } @@ -181,6 +188,7 @@ class FlutterEmbedderOptions { flutter::FlutterViewController::ViewRotation::kRotation_0; bool is_force_scale_factor_; double scale_factor_; + double text_scale_factor_; bool enable_vsync_; }; diff --git a/examples/flutter-drm-eglstream-backend/main.cc b/examples/flutter-drm-eglstream-backend/main.cc index e1da779c..37b179e0 100644 --- a/examples/flutter-drm-eglstream-backend/main.cc +++ b/examples/flutter-drm-eglstream-backend/main.cc @@ -35,6 +35,7 @@ int main(int argc, char** argv) { view_properties.use_mouse_cursor = options.IsUseMouseCursor(); view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); view_properties.use_window_decoration = options.IsUseWindowDecoraation(); + view_properties.text_scale_factor = options.TextScaleFactor(); view_properties.force_scale_factor = options.IsForceScaleFactor(); view_properties.scale_factor = options.ScaleFactor(); view_properties.enable_vsync = options.EnableVsync(); diff --git a/examples/flutter-drm-gbm-backend/flutter_embedder_options.h b/examples/flutter-drm-gbm-backend/flutter_embedder_options.h index 8a5cfd41..04138b3f 100644 --- a/examples/flutter-drm-gbm-backend/flutter_embedder_options.h +++ b/examples/flutter-drm-gbm-backend/flutter_embedder_options.h @@ -21,6 +21,8 @@ class FlutterEmbedderOptions { options_.AddInt("rotation", "r", "Window rotation(degree) [0(default)|90|180|270]", 0, false); + options_.AddDouble("text-scaling-factor", "x", "Text scaling factor", 1.0, + false); options_.AddDouble("force-scale-factor", "s", "Force a scale factor instead using default value", 1.0, false); @@ -83,6 +85,8 @@ class FlutterEmbedderOptions { } } + text_scale_factor_ = options_.GetValue("text-scaling-factor"); + if (options_.Exist("force-scale-factor")) { is_force_scale_factor_ = true; scale_factor_ = options_.GetValue("force-scale-factor"); @@ -154,6 +158,9 @@ class FlutterEmbedderOptions { flutter::FlutterViewController::ViewRotation WindowRotation() const { return window_view_rotation_; } + double TextScaleFactor() const { + return text_scale_factor_; + } bool IsForceScaleFactor() const { return is_force_scale_factor_; } @@ -181,6 +188,7 @@ class FlutterEmbedderOptions { flutter::FlutterViewController::ViewRotation::kRotation_0; bool is_force_scale_factor_; double scale_factor_; + double text_scale_factor_; bool enable_vsync_; }; diff --git a/examples/flutter-drm-gbm-backend/main.cc b/examples/flutter-drm-gbm-backend/main.cc index e1da779c..37b179e0 100644 --- a/examples/flutter-drm-gbm-backend/main.cc +++ b/examples/flutter-drm-gbm-backend/main.cc @@ -35,6 +35,7 @@ int main(int argc, char** argv) { view_properties.use_mouse_cursor = options.IsUseMouseCursor(); view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); view_properties.use_window_decoration = options.IsUseWindowDecoraation(); + view_properties.text_scale_factor = options.TextScaleFactor(); view_properties.force_scale_factor = options.IsForceScaleFactor(); view_properties.scale_factor = options.ScaleFactor(); view_properties.enable_vsync = options.EnableVsync(); diff --git a/examples/flutter-external-texture-plugin/flutter_embedder_options.h b/examples/flutter-external-texture-plugin/flutter_embedder_options.h index 8a5cfd41..04138b3f 100644 --- a/examples/flutter-external-texture-plugin/flutter_embedder_options.h +++ b/examples/flutter-external-texture-plugin/flutter_embedder_options.h @@ -21,6 +21,8 @@ class FlutterEmbedderOptions { options_.AddInt("rotation", "r", "Window rotation(degree) [0(default)|90|180|270]", 0, false); + options_.AddDouble("text-scaling-factor", "x", "Text scaling factor", 1.0, + false); options_.AddDouble("force-scale-factor", "s", "Force a scale factor instead using default value", 1.0, false); @@ -83,6 +85,8 @@ class FlutterEmbedderOptions { } } + text_scale_factor_ = options_.GetValue("text-scaling-factor"); + if (options_.Exist("force-scale-factor")) { is_force_scale_factor_ = true; scale_factor_ = options_.GetValue("force-scale-factor"); @@ -154,6 +158,9 @@ class FlutterEmbedderOptions { flutter::FlutterViewController::ViewRotation WindowRotation() const { return window_view_rotation_; } + double TextScaleFactor() const { + return text_scale_factor_; + } bool IsForceScaleFactor() const { return is_force_scale_factor_; } @@ -181,6 +188,7 @@ class FlutterEmbedderOptions { flutter::FlutterViewController::ViewRotation::kRotation_0; bool is_force_scale_factor_; double scale_factor_; + double text_scale_factor_; bool enable_vsync_; }; diff --git a/examples/flutter-external-texture-plugin/main.cc b/examples/flutter-external-texture-plugin/main.cc index e1da779c..37b179e0 100644 --- a/examples/flutter-external-texture-plugin/main.cc +++ b/examples/flutter-external-texture-plugin/main.cc @@ -35,6 +35,7 @@ int main(int argc, char** argv) { view_properties.use_mouse_cursor = options.IsUseMouseCursor(); view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); view_properties.use_window_decoration = options.IsUseWindowDecoraation(); + view_properties.text_scale_factor = options.TextScaleFactor(); view_properties.force_scale_factor = options.IsForceScaleFactor(); view_properties.scale_factor = options.ScaleFactor(); view_properties.enable_vsync = options.EnableVsync(); diff --git a/examples/flutter-video-player-plugin/flutter_embedder_options.h b/examples/flutter-video-player-plugin/flutter_embedder_options.h index 8a5cfd41..04138b3f 100644 --- a/examples/flutter-video-player-plugin/flutter_embedder_options.h +++ b/examples/flutter-video-player-plugin/flutter_embedder_options.h @@ -21,6 +21,8 @@ class FlutterEmbedderOptions { options_.AddInt("rotation", "r", "Window rotation(degree) [0(default)|90|180|270]", 0, false); + options_.AddDouble("text-scaling-factor", "x", "Text scaling factor", 1.0, + false); options_.AddDouble("force-scale-factor", "s", "Force a scale factor instead using default value", 1.0, false); @@ -83,6 +85,8 @@ class FlutterEmbedderOptions { } } + text_scale_factor_ = options_.GetValue("text-scaling-factor"); + if (options_.Exist("force-scale-factor")) { is_force_scale_factor_ = true; scale_factor_ = options_.GetValue("force-scale-factor"); @@ -154,6 +158,9 @@ class FlutterEmbedderOptions { flutter::FlutterViewController::ViewRotation WindowRotation() const { return window_view_rotation_; } + double TextScaleFactor() const { + return text_scale_factor_; + } bool IsForceScaleFactor() const { return is_force_scale_factor_; } @@ -181,6 +188,7 @@ class FlutterEmbedderOptions { flutter::FlutterViewController::ViewRotation::kRotation_0; bool is_force_scale_factor_; double scale_factor_; + double text_scale_factor_; bool enable_vsync_; }; diff --git a/examples/flutter-video-player-plugin/main.cc b/examples/flutter-video-player-plugin/main.cc index e1da779c..37b179e0 100644 --- a/examples/flutter-video-player-plugin/main.cc +++ b/examples/flutter-video-player-plugin/main.cc @@ -35,6 +35,7 @@ int main(int argc, char** argv) { view_properties.use_mouse_cursor = options.IsUseMouseCursor(); view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); view_properties.use_window_decoration = options.IsUseWindowDecoraation(); + view_properties.text_scale_factor = options.TextScaleFactor(); view_properties.force_scale_factor = options.IsForceScaleFactor(); view_properties.scale_factor = options.ScaleFactor(); view_properties.enable_vsync = options.EnableVsync(); diff --git a/examples/flutter-wayland-client/flutter_embedder_options.h b/examples/flutter-wayland-client/flutter_embedder_options.h index 8a5cfd41..04138b3f 100644 --- a/examples/flutter-wayland-client/flutter_embedder_options.h +++ b/examples/flutter-wayland-client/flutter_embedder_options.h @@ -21,6 +21,8 @@ class FlutterEmbedderOptions { options_.AddInt("rotation", "r", "Window rotation(degree) [0(default)|90|180|270]", 0, false); + options_.AddDouble("text-scaling-factor", "x", "Text scaling factor", 1.0, + false); options_.AddDouble("force-scale-factor", "s", "Force a scale factor instead using default value", 1.0, false); @@ -83,6 +85,8 @@ class FlutterEmbedderOptions { } } + text_scale_factor_ = options_.GetValue("text-scaling-factor"); + if (options_.Exist("force-scale-factor")) { is_force_scale_factor_ = true; scale_factor_ = options_.GetValue("force-scale-factor"); @@ -154,6 +158,9 @@ class FlutterEmbedderOptions { flutter::FlutterViewController::ViewRotation WindowRotation() const { return window_view_rotation_; } + double TextScaleFactor() const { + return text_scale_factor_; + } bool IsForceScaleFactor() const { return is_force_scale_factor_; } @@ -181,6 +188,7 @@ class FlutterEmbedderOptions { flutter::FlutterViewController::ViewRotation::kRotation_0; bool is_force_scale_factor_; double scale_factor_; + double text_scale_factor_; bool enable_vsync_; }; diff --git a/examples/flutter-wayland-client/main.cc b/examples/flutter-wayland-client/main.cc index e1da779c..37b179e0 100644 --- a/examples/flutter-wayland-client/main.cc +++ b/examples/flutter-wayland-client/main.cc @@ -35,6 +35,7 @@ int main(int argc, char** argv) { view_properties.use_mouse_cursor = options.IsUseMouseCursor(); view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); view_properties.use_window_decoration = options.IsUseWindowDecoraation(); + view_properties.text_scale_factor = options.TextScaleFactor(); view_properties.force_scale_factor = options.IsForceScaleFactor(); view_properties.scale_factor = options.ScaleFactor(); view_properties.enable_vsync = options.EnableVsync(); diff --git a/examples/flutter-x11-client/flutter_embedder_options.h b/examples/flutter-x11-client/flutter_embedder_options.h index 8a5cfd41..04138b3f 100644 --- a/examples/flutter-x11-client/flutter_embedder_options.h +++ b/examples/flutter-x11-client/flutter_embedder_options.h @@ -21,6 +21,8 @@ class FlutterEmbedderOptions { options_.AddInt("rotation", "r", "Window rotation(degree) [0(default)|90|180|270]", 0, false); + options_.AddDouble("text-scaling-factor", "x", "Text scaling factor", 1.0, + false); options_.AddDouble("force-scale-factor", "s", "Force a scale factor instead using default value", 1.0, false); @@ -83,6 +85,8 @@ class FlutterEmbedderOptions { } } + text_scale_factor_ = options_.GetValue("text-scaling-factor"); + if (options_.Exist("force-scale-factor")) { is_force_scale_factor_ = true; scale_factor_ = options_.GetValue("force-scale-factor"); @@ -154,6 +158,9 @@ class FlutterEmbedderOptions { flutter::FlutterViewController::ViewRotation WindowRotation() const { return window_view_rotation_; } + double TextScaleFactor() const { + return text_scale_factor_; + } bool IsForceScaleFactor() const { return is_force_scale_factor_; } @@ -181,6 +188,7 @@ class FlutterEmbedderOptions { flutter::FlutterViewController::ViewRotation::kRotation_0; bool is_force_scale_factor_; double scale_factor_; + double text_scale_factor_; bool enable_vsync_; }; diff --git a/examples/flutter-x11-client/main.cc b/examples/flutter-x11-client/main.cc index e1da779c..37b179e0 100644 --- a/examples/flutter-x11-client/main.cc +++ b/examples/flutter-x11-client/main.cc @@ -35,6 +35,7 @@ int main(int argc, char** argv) { view_properties.use_mouse_cursor = options.IsUseMouseCursor(); view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); view_properties.use_window_decoration = options.IsUseWindowDecoraation(); + view_properties.text_scale_factor = options.TextScaleFactor(); view_properties.force_scale_factor = options.IsForceScaleFactor(); view_properties.scale_factor = options.ScaleFactor(); view_properties.enable_vsync = options.EnableVsync(); diff --git a/src/client_wrapper/flutter_view_controller.cc b/src/client_wrapper/flutter_view_controller.cc index 9b412a3a..42e3d217 100644 --- a/src/client_wrapper/flutter_view_controller.cc +++ b/src/client_wrapper/flutter_view_controller.cc @@ -40,6 +40,7 @@ FlutterViewController::FlutterViewController( view_properties.use_onscreen_keyboard; c_view_properties.use_window_decoration = view_properties.use_window_decoration; + c_view_properties.text_scale_factor = view_properties.text_scale_factor; c_view_properties.force_scale_factor = view_properties.force_scale_factor; c_view_properties.scale_factor = view_properties.scale_factor; c_view_properties.enable_vsync = view_properties.enable_vsync; diff --git a/src/client_wrapper/include/flutter/flutter_view_controller.h b/src/client_wrapper/include/flutter/flutter_view_controller.h index b0403c5c..1659a561 100644 --- a/src/client_wrapper/include/flutter/flutter_view_controller.h +++ b/src/client_wrapper/include/flutter/flutter_view_controller.h @@ -76,6 +76,9 @@ class FlutterViewController { // This option is only active for Wayland backend. bool use_window_decoration; + // Text scaling factor. + double text_scale_factor; + // Force scale factor specified by command line argument bool force_scale_factor; double scale_factor; diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux.cc index 99313f2d..4ceb5986 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux.cc @@ -100,6 +100,9 @@ FlutterDesktopViewControllerRef FlutterDesktopViewControllerCreate( if (!state->view->GetEngine()->RunWithEntrypoint(nullptr)) { return nullptr; } + + const float text_scaling_factor = view_properties->text_scale_factor; + state->view->GetEngine()->SetSystemSettings(text_scaling_factor); } // Must happen after engine is running. diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc index e71961e8..76e83b30 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc @@ -277,11 +277,6 @@ bool FlutterELinuxEngine::RunWithEntrypoint(const char* entrypoint) { return false; } - // TODO: add theme initial value support. - view_->UpdateHighContrastEnabled(false); - - SendSystemLocales(); - return true; } @@ -384,6 +379,15 @@ void FlutterELinuxEngine::ReloadSystemFonts() { embedder_api_.ReloadSystemFonts(engine_); } +void FlutterELinuxEngine::SetSystemSettings(float text_scaling_factor) { + view_->UpdateTextScaleFactor(text_scaling_factor); + + // TODO: add theme initial value support. + view_->UpdateHighContrastEnabled(false); + + SendSystemLocales(); +} + void FlutterELinuxEngine::SendSystemLocales() { auto languages = flutter::GetPreferredLanguageInfo(); auto flutter_locales = flutter::ConvertToFlutterLocale(languages); diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h index c05c1fa3..57087073 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h @@ -127,6 +127,9 @@ class FlutterELinuxEngine { // Gets the status whether Impeller is enabled. bool IsImpellerEnabled() const { return enable_impeller_; } + // Sets system settings. + void SetSystemSettings(float text_scaling_factor); + private: // Allows swapping out embedder_api_ calls in tests. friend class EngineEmbedderApiModifier; diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc index c5c22693..ec625d62 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc @@ -510,4 +510,8 @@ void FlutterELinuxView::UpdateHighContrastEnabled(bool enabled) { settings_handler_->UpdateHighContrastMode(enabled); } +void FlutterELinuxView::UpdateTextScaleFactor(float factor) { + settings_handler_->UpdateTextScaleFactor(factor); +} + } // namespace flutter diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.h b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.h index 1a5ff519..977bd3e1 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.h +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.h @@ -148,6 +148,9 @@ class FlutterELinuxView : public WindowBindingHandlerDelegate { // |WindowBindingHandlerDelegate| void UpdateHighContrastEnabled(bool enabled) override; + // |WindowBindingHandlerDelegate| + void UpdateTextScaleFactor(float factor) override; + private: // Struct holding the mouse state. The engine doesn't keep track of which // mouse buttons have been pressed, so it's the embedding's responsibility. diff --git a/src/flutter/shell/platform/linux_embedded/plugins/settings_plugin.cc b/src/flutter/shell/platform/linux_embedded/plugins/settings_plugin.cc index 3492cdb5..6e118739 100644 --- a/src/flutter/shell/platform/linux_embedded/plugins/settings_plugin.cc +++ b/src/flutter/shell/platform/linux_embedded/plugins/settings_plugin.cc @@ -50,8 +50,12 @@ bool SettingsPlugin::GetAlwaysUse24HourFormat() { } float SettingsPlugin::GetTextScaleFactor() { - // The current OS does not have text scale factor. - return 1.0; + return text_scaling_factor_; +} + +void SettingsPlugin::UpdateTextScaleFactor(float factor) { + text_scaling_factor_ = factor; + SendSettings(); } SettingsPlugin::PlatformBrightness SettingsPlugin::GetPreferredBrightness() { diff --git a/src/flutter/shell/platform/linux_embedded/plugins/settings_plugin.h b/src/flutter/shell/platform/linux_embedded/plugins/settings_plugin.h index 25f10585..0029f695 100644 --- a/src/flutter/shell/platform/linux_embedded/plugins/settings_plugin.h +++ b/src/flutter/shell/platform/linux_embedded/plugins/settings_plugin.h @@ -34,6 +34,9 @@ class SettingsPlugin { // Update the high contrast status of the system. void UpdateHighContrastMode(bool is_high_contrast); + // Update the text scale factor of the system. + void UpdateTextScaleFactor(float factor); + private: // Returns `true` if the user uses 24 hour time. bool GetAlwaysUse24HourFormat(); @@ -44,11 +47,10 @@ class SettingsPlugin { // Returns the user-preferred brightness. PlatformBrightness GetPreferredBrightness(); - bool is_high_contrast_ = false; - - private: std::unique_ptr> channel_; WindowBindingHandler* delegate_; + bool is_high_contrast_ = false; + float text_scaling_factor_ = 1.0; }; } // namespace flutter diff --git a/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h b/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h index d5f22347..97d93436 100644 --- a/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h +++ b/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h @@ -106,6 +106,9 @@ typedef struct { // This option is only active for Wayland backend. bool use_window_decoration; + // Text scaling factor. + double text_scale_factor; + // Force scale factor specified by command line argument bool force_scale_factor; double scale_factor; diff --git a/src/flutter/shell/platform/linux_embedded/window_binding_handler_delegate.h b/src/flutter/shell/platform/linux_embedded/window_binding_handler_delegate.h index fd7369e4..3bc6429d 100644 --- a/src/flutter/shell/platform/linux_embedded/window_binding_handler_delegate.h +++ b/src/flutter/shell/platform/linux_embedded/window_binding_handler_delegate.h @@ -107,6 +107,9 @@ class WindowBindingHandlerDelegate { // Update the status of the high contrast feature virtual void UpdateHighContrastEnabled(bool enabled) = 0; + + // Update the status of the text scaling factor feature + virtual void UpdateTextScaleFactor(float factor) = 0; }; } // namespace flutter From 36af86f40527a41d3ff245f2f33ade9c421cc073 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Fri, 11 Aug 2023 01:50:36 +0000 Subject: [PATCH 071/112] wayland: fix missing scaling of decoration buttons (#368) This change fixes wrong placement of decoration buttons. Signed-off-by: Hidenori Matsubayashi --- .../window/renderer/window_decorations_wayland.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.cc index 5aa5fb59..b6c63c3b 100644 --- a/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/renderer/window_decorations_wayland.cc @@ -51,7 +51,7 @@ WindowDecorationsWayland::WindowDecorationsWayland( std::make_unique(display, sub_egl_display), enable_impeller)))); buttons_[type]->SetPosition( - width_dip - kButtonWidthDIP - kButtonMarginDIP, + width_dip * pixel_ratio - kButtonWidthDIP - kButtonMarginDIP, -(kButtonHeightDIP + (kTitleBarHeightDIP - kButtonHeightDIP) / 2)); // maximise button. @@ -66,7 +66,7 @@ WindowDecorationsWayland::WindowDecorationsWayland( std::make_unique(display, sub_egl_display), enable_impeller)))); buttons_[type]->SetPosition( - width_dip - kButtonWidthDIP * 2 - kButtonMarginDIP * 2, + width_dip * pixel_ratio - kButtonWidthDIP * 2 - kButtonMarginDIP * 2, -(kButtonHeightDIP + (kTitleBarHeightDIP - kButtonHeightDIP) / 2)); // minimise button. @@ -81,7 +81,7 @@ WindowDecorationsWayland::WindowDecorationsWayland( std::make_unique(display, sub_egl_display), enable_impeller)))); buttons_[type]->SetPosition( - width_dip - kButtonWidthDIP * 3 - kButtonMarginDIP * 3, + width_dip * pixel_ratio - kButtonWidthDIP * 3 - kButtonMarginDIP * 3, -(kButtonHeightDIP + (kTitleBarHeightDIP - kButtonHeightDIP) / 2)); } @@ -110,7 +110,8 @@ void WindowDecorationsWayland::Resize(const int32_t width_dip, for (auto i = 0; i < buttons_.size(); i++) { buttons_[i]->SetScaleFactor(pixel_ratio); buttons_[i]->SetPosition( - width_dip - kButtonWidthDIP * (i + 1) - kButtonMarginDIP * (i + 1), + width_dip * pixel_ratio - kButtonWidthDIP * (i + 1) - + kButtonMarginDIP * (i + 1), -(kButtonHeightDIP + (kTitleBarHeightDIP - kButtonHeightDIP) / 2)); buttons_[i]->Resize(kButtonWidthDIP * pixel_ratio, kButtonHeightDIP * pixel_ratio); From d496f1f63efaa1aeda5f55e81a1306343cc3ca94 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Wed, 16 Aug 2023 04:47:35 +0000 Subject: [PATCH 072/112] accessibility: add --enable-high-contrast option (#370) This change add "--enable-high-contrast" command-line option to request that UI be rendered with darker colors. Related issues #2, #168 Signed-off-by: Hidenori Matsubayashi --- .../flutter_embedder_options.h | 8 ++++++++ examples/flutter-drm-eglstream-backend/main.cc | 1 + .../flutter_embedder_options.h | 8 ++++++++ examples/flutter-drm-gbm-backend/main.cc | 1 + .../flutter_embedder_options.h | 8 ++++++++ examples/flutter-external-texture-plugin/main.cc | 1 + .../flutter_embedder_options.h | 8 ++++++++ examples/flutter-video-player-plugin/main.cc | 1 + .../flutter_embedder_options.h | 8 ++++++++ examples/flutter-wayland-client/main.cc | 1 + .../flutter-x11-client/flutter_embedder_options.h | 8 ++++++++ examples/flutter-x11-client/main.cc | 1 + src/client_wrapper/flutter_view_controller.cc | 1 + .../include/flutter/flutter_view_controller.h | 3 +++ .../shell/platform/linux_embedded/flutter_elinux.cc | 3 ++- .../linux_embedded/flutter_elinux_engine.cc | 13 ++++++++----- .../platform/linux_embedded/flutter_elinux_engine.h | 5 ++++- .../platform/linux_embedded/flutter_elinux_view.cc | 11 ++++++++++- .../linux_embedded/plugins/settings_plugin.cc | 9 +++++++-- .../linux_embedded/plugins/settings_plugin.h | 4 ++++ .../platform/linux_embedded/public/flutter_elinux.h | 3 +++ 21 files changed, 96 insertions(+), 10 deletions(-) diff --git a/examples/flutter-drm-eglstream-backend/flutter_embedder_options.h b/examples/flutter-drm-eglstream-backend/flutter_embedder_options.h index 04138b3f..41d0bd10 100644 --- a/examples/flutter-drm-eglstream-backend/flutter_embedder_options.h +++ b/examples/flutter-drm-eglstream-backend/flutter_embedder_options.h @@ -23,6 +23,9 @@ class FlutterEmbedderOptions { false); options_.AddDouble("text-scaling-factor", "x", "Text scaling factor", 1.0, false); + options_.AddWithoutValue("enable-high-contrast", "i", + "Request that UI be rendered with darker colors.", + false); options_.AddDouble("force-scale-factor", "s", "Force a scale factor instead using default value", 1.0, false); @@ -86,6 +89,7 @@ class FlutterEmbedderOptions { } text_scale_factor_ = options_.GetValue("text-scaling-factor"); + enable_high_contrast_ = options_.Exist("enable-high-contrast"); if (options_.Exist("force-scale-factor")) { is_force_scale_factor_ = true; @@ -161,6 +165,9 @@ class FlutterEmbedderOptions { double TextScaleFactor() const { return text_scale_factor_; } + bool EnableHighContrast() const { + return enable_high_contrast_; + } bool IsForceScaleFactor() const { return is_force_scale_factor_; } @@ -189,6 +196,7 @@ class FlutterEmbedderOptions { bool is_force_scale_factor_; double scale_factor_; double text_scale_factor_; + bool enable_high_contrast_; bool enable_vsync_; }; diff --git a/examples/flutter-drm-eglstream-backend/main.cc b/examples/flutter-drm-eglstream-backend/main.cc index 37b179e0..579daee6 100644 --- a/examples/flutter-drm-eglstream-backend/main.cc +++ b/examples/flutter-drm-eglstream-backend/main.cc @@ -36,6 +36,7 @@ int main(int argc, char** argv) { view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); view_properties.use_window_decoration = options.IsUseWindowDecoraation(); view_properties.text_scale_factor = options.TextScaleFactor(); + view_properties.enable_high_contrast = options.EnableHighContrast(); view_properties.force_scale_factor = options.IsForceScaleFactor(); view_properties.scale_factor = options.ScaleFactor(); view_properties.enable_vsync = options.EnableVsync(); diff --git a/examples/flutter-drm-gbm-backend/flutter_embedder_options.h b/examples/flutter-drm-gbm-backend/flutter_embedder_options.h index 04138b3f..41d0bd10 100644 --- a/examples/flutter-drm-gbm-backend/flutter_embedder_options.h +++ b/examples/flutter-drm-gbm-backend/flutter_embedder_options.h @@ -23,6 +23,9 @@ class FlutterEmbedderOptions { false); options_.AddDouble("text-scaling-factor", "x", "Text scaling factor", 1.0, false); + options_.AddWithoutValue("enable-high-contrast", "i", + "Request that UI be rendered with darker colors.", + false); options_.AddDouble("force-scale-factor", "s", "Force a scale factor instead using default value", 1.0, false); @@ -86,6 +89,7 @@ class FlutterEmbedderOptions { } text_scale_factor_ = options_.GetValue("text-scaling-factor"); + enable_high_contrast_ = options_.Exist("enable-high-contrast"); if (options_.Exist("force-scale-factor")) { is_force_scale_factor_ = true; @@ -161,6 +165,9 @@ class FlutterEmbedderOptions { double TextScaleFactor() const { return text_scale_factor_; } + bool EnableHighContrast() const { + return enable_high_contrast_; + } bool IsForceScaleFactor() const { return is_force_scale_factor_; } @@ -189,6 +196,7 @@ class FlutterEmbedderOptions { bool is_force_scale_factor_; double scale_factor_; double text_scale_factor_; + bool enable_high_contrast_; bool enable_vsync_; }; diff --git a/examples/flutter-drm-gbm-backend/main.cc b/examples/flutter-drm-gbm-backend/main.cc index 37b179e0..579daee6 100644 --- a/examples/flutter-drm-gbm-backend/main.cc +++ b/examples/flutter-drm-gbm-backend/main.cc @@ -36,6 +36,7 @@ int main(int argc, char** argv) { view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); view_properties.use_window_decoration = options.IsUseWindowDecoraation(); view_properties.text_scale_factor = options.TextScaleFactor(); + view_properties.enable_high_contrast = options.EnableHighContrast(); view_properties.force_scale_factor = options.IsForceScaleFactor(); view_properties.scale_factor = options.ScaleFactor(); view_properties.enable_vsync = options.EnableVsync(); diff --git a/examples/flutter-external-texture-plugin/flutter_embedder_options.h b/examples/flutter-external-texture-plugin/flutter_embedder_options.h index 04138b3f..41d0bd10 100644 --- a/examples/flutter-external-texture-plugin/flutter_embedder_options.h +++ b/examples/flutter-external-texture-plugin/flutter_embedder_options.h @@ -23,6 +23,9 @@ class FlutterEmbedderOptions { false); options_.AddDouble("text-scaling-factor", "x", "Text scaling factor", 1.0, false); + options_.AddWithoutValue("enable-high-contrast", "i", + "Request that UI be rendered with darker colors.", + false); options_.AddDouble("force-scale-factor", "s", "Force a scale factor instead using default value", 1.0, false); @@ -86,6 +89,7 @@ class FlutterEmbedderOptions { } text_scale_factor_ = options_.GetValue("text-scaling-factor"); + enable_high_contrast_ = options_.Exist("enable-high-contrast"); if (options_.Exist("force-scale-factor")) { is_force_scale_factor_ = true; @@ -161,6 +165,9 @@ class FlutterEmbedderOptions { double TextScaleFactor() const { return text_scale_factor_; } + bool EnableHighContrast() const { + return enable_high_contrast_; + } bool IsForceScaleFactor() const { return is_force_scale_factor_; } @@ -189,6 +196,7 @@ class FlutterEmbedderOptions { bool is_force_scale_factor_; double scale_factor_; double text_scale_factor_; + bool enable_high_contrast_; bool enable_vsync_; }; diff --git a/examples/flutter-external-texture-plugin/main.cc b/examples/flutter-external-texture-plugin/main.cc index 37b179e0..579daee6 100644 --- a/examples/flutter-external-texture-plugin/main.cc +++ b/examples/flutter-external-texture-plugin/main.cc @@ -36,6 +36,7 @@ int main(int argc, char** argv) { view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); view_properties.use_window_decoration = options.IsUseWindowDecoraation(); view_properties.text_scale_factor = options.TextScaleFactor(); + view_properties.enable_high_contrast = options.EnableHighContrast(); view_properties.force_scale_factor = options.IsForceScaleFactor(); view_properties.scale_factor = options.ScaleFactor(); view_properties.enable_vsync = options.EnableVsync(); diff --git a/examples/flutter-video-player-plugin/flutter_embedder_options.h b/examples/flutter-video-player-plugin/flutter_embedder_options.h index 04138b3f..41d0bd10 100644 --- a/examples/flutter-video-player-plugin/flutter_embedder_options.h +++ b/examples/flutter-video-player-plugin/flutter_embedder_options.h @@ -23,6 +23,9 @@ class FlutterEmbedderOptions { false); options_.AddDouble("text-scaling-factor", "x", "Text scaling factor", 1.0, false); + options_.AddWithoutValue("enable-high-contrast", "i", + "Request that UI be rendered with darker colors.", + false); options_.AddDouble("force-scale-factor", "s", "Force a scale factor instead using default value", 1.0, false); @@ -86,6 +89,7 @@ class FlutterEmbedderOptions { } text_scale_factor_ = options_.GetValue("text-scaling-factor"); + enable_high_contrast_ = options_.Exist("enable-high-contrast"); if (options_.Exist("force-scale-factor")) { is_force_scale_factor_ = true; @@ -161,6 +165,9 @@ class FlutterEmbedderOptions { double TextScaleFactor() const { return text_scale_factor_; } + bool EnableHighContrast() const { + return enable_high_contrast_; + } bool IsForceScaleFactor() const { return is_force_scale_factor_; } @@ -189,6 +196,7 @@ class FlutterEmbedderOptions { bool is_force_scale_factor_; double scale_factor_; double text_scale_factor_; + bool enable_high_contrast_; bool enable_vsync_; }; diff --git a/examples/flutter-video-player-plugin/main.cc b/examples/flutter-video-player-plugin/main.cc index 37b179e0..579daee6 100644 --- a/examples/flutter-video-player-plugin/main.cc +++ b/examples/flutter-video-player-plugin/main.cc @@ -36,6 +36,7 @@ int main(int argc, char** argv) { view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); view_properties.use_window_decoration = options.IsUseWindowDecoraation(); view_properties.text_scale_factor = options.TextScaleFactor(); + view_properties.enable_high_contrast = options.EnableHighContrast(); view_properties.force_scale_factor = options.IsForceScaleFactor(); view_properties.scale_factor = options.ScaleFactor(); view_properties.enable_vsync = options.EnableVsync(); diff --git a/examples/flutter-wayland-client/flutter_embedder_options.h b/examples/flutter-wayland-client/flutter_embedder_options.h index 04138b3f..41d0bd10 100644 --- a/examples/flutter-wayland-client/flutter_embedder_options.h +++ b/examples/flutter-wayland-client/flutter_embedder_options.h @@ -23,6 +23,9 @@ class FlutterEmbedderOptions { false); options_.AddDouble("text-scaling-factor", "x", "Text scaling factor", 1.0, false); + options_.AddWithoutValue("enable-high-contrast", "i", + "Request that UI be rendered with darker colors.", + false); options_.AddDouble("force-scale-factor", "s", "Force a scale factor instead using default value", 1.0, false); @@ -86,6 +89,7 @@ class FlutterEmbedderOptions { } text_scale_factor_ = options_.GetValue("text-scaling-factor"); + enable_high_contrast_ = options_.Exist("enable-high-contrast"); if (options_.Exist("force-scale-factor")) { is_force_scale_factor_ = true; @@ -161,6 +165,9 @@ class FlutterEmbedderOptions { double TextScaleFactor() const { return text_scale_factor_; } + bool EnableHighContrast() const { + return enable_high_contrast_; + } bool IsForceScaleFactor() const { return is_force_scale_factor_; } @@ -189,6 +196,7 @@ class FlutterEmbedderOptions { bool is_force_scale_factor_; double scale_factor_; double text_scale_factor_; + bool enable_high_contrast_; bool enable_vsync_; }; diff --git a/examples/flutter-wayland-client/main.cc b/examples/flutter-wayland-client/main.cc index 37b179e0..579daee6 100644 --- a/examples/flutter-wayland-client/main.cc +++ b/examples/flutter-wayland-client/main.cc @@ -36,6 +36,7 @@ int main(int argc, char** argv) { view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); view_properties.use_window_decoration = options.IsUseWindowDecoraation(); view_properties.text_scale_factor = options.TextScaleFactor(); + view_properties.enable_high_contrast = options.EnableHighContrast(); view_properties.force_scale_factor = options.IsForceScaleFactor(); view_properties.scale_factor = options.ScaleFactor(); view_properties.enable_vsync = options.EnableVsync(); diff --git a/examples/flutter-x11-client/flutter_embedder_options.h b/examples/flutter-x11-client/flutter_embedder_options.h index 04138b3f..41d0bd10 100644 --- a/examples/flutter-x11-client/flutter_embedder_options.h +++ b/examples/flutter-x11-client/flutter_embedder_options.h @@ -23,6 +23,9 @@ class FlutterEmbedderOptions { false); options_.AddDouble("text-scaling-factor", "x", "Text scaling factor", 1.0, false); + options_.AddWithoutValue("enable-high-contrast", "i", + "Request that UI be rendered with darker colors.", + false); options_.AddDouble("force-scale-factor", "s", "Force a scale factor instead using default value", 1.0, false); @@ -86,6 +89,7 @@ class FlutterEmbedderOptions { } text_scale_factor_ = options_.GetValue("text-scaling-factor"); + enable_high_contrast_ = options_.Exist("enable-high-contrast"); if (options_.Exist("force-scale-factor")) { is_force_scale_factor_ = true; @@ -161,6 +165,9 @@ class FlutterEmbedderOptions { double TextScaleFactor() const { return text_scale_factor_; } + bool EnableHighContrast() const { + return enable_high_contrast_; + } bool IsForceScaleFactor() const { return is_force_scale_factor_; } @@ -189,6 +196,7 @@ class FlutterEmbedderOptions { bool is_force_scale_factor_; double scale_factor_; double text_scale_factor_; + bool enable_high_contrast_; bool enable_vsync_; }; diff --git a/examples/flutter-x11-client/main.cc b/examples/flutter-x11-client/main.cc index 37b179e0..579daee6 100644 --- a/examples/flutter-x11-client/main.cc +++ b/examples/flutter-x11-client/main.cc @@ -36,6 +36,7 @@ int main(int argc, char** argv) { view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); view_properties.use_window_decoration = options.IsUseWindowDecoraation(); view_properties.text_scale_factor = options.TextScaleFactor(); + view_properties.enable_high_contrast = options.EnableHighContrast(); view_properties.force_scale_factor = options.IsForceScaleFactor(); view_properties.scale_factor = options.ScaleFactor(); view_properties.enable_vsync = options.EnableVsync(); diff --git a/src/client_wrapper/flutter_view_controller.cc b/src/client_wrapper/flutter_view_controller.cc index 42e3d217..47f81529 100644 --- a/src/client_wrapper/flutter_view_controller.cc +++ b/src/client_wrapper/flutter_view_controller.cc @@ -41,6 +41,7 @@ FlutterViewController::FlutterViewController( c_view_properties.use_window_decoration = view_properties.use_window_decoration; c_view_properties.text_scale_factor = view_properties.text_scale_factor; + c_view_properties.enable_high_contrast = view_properties.enable_high_contrast; c_view_properties.force_scale_factor = view_properties.force_scale_factor; c_view_properties.scale_factor = view_properties.scale_factor; c_view_properties.enable_vsync = view_properties.enable_vsync; diff --git a/src/client_wrapper/include/flutter/flutter_view_controller.h b/src/client_wrapper/include/flutter/flutter_view_controller.h index 1659a561..2abf0e6a 100644 --- a/src/client_wrapper/include/flutter/flutter_view_controller.h +++ b/src/client_wrapper/include/flutter/flutter_view_controller.h @@ -79,6 +79,9 @@ class FlutterViewController { // Text scaling factor. double text_scale_factor; + // Enable high contrast. Request that UI be rendered with darker colors. + bool enable_high_contrast; + // Force scale factor specified by command line argument bool force_scale_factor; double scale_factor; diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux.cc index 4ceb5986..d3c3dee3 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux.cc @@ -102,7 +102,8 @@ FlutterDesktopViewControllerRef FlutterDesktopViewControllerCreate( } const float text_scaling_factor = view_properties->text_scale_factor; - state->view->GetEngine()->SetSystemSettings(text_scaling_factor); + state->view->GetEngine()->SetSystemSettings( + text_scaling_factor, view_properties->enable_high_contrast); } // Must happen after engine is running. diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc index 76e83b30..8354eaf1 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc @@ -379,12 +379,10 @@ void FlutterELinuxEngine::ReloadSystemFonts() { embedder_api_.ReloadSystemFonts(engine_); } -void FlutterELinuxEngine::SetSystemSettings(float text_scaling_factor) { +void FlutterELinuxEngine::SetSystemSettings(float text_scaling_factor, + bool enable_high_contrast) { view_->UpdateTextScaleFactor(text_scaling_factor); - - // TODO: add theme initial value support. - view_->UpdateHighContrastEnabled(false); - + view_->UpdateHighContrastEnabled(enable_high_contrast); SendSystemLocales(); } @@ -437,4 +435,9 @@ void FlutterELinuxEngine::OnVsync(uint64_t last_frame_time_nanos, frame_target_time_nanos); } +void FlutterELinuxEngine::UpdateAccessibilityFeatures( + FlutterAccessibilityFeature flags) { + embedder_api_.UpdateAccessibilityFeatures(engine_, flags); +} + } // namespace flutter diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h index 57087073..28bbf43c 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h @@ -128,7 +128,10 @@ class FlutterELinuxEngine { bool IsImpellerEnabled() const { return enable_impeller_; } // Sets system settings. - void SetSystemSettings(float text_scaling_factor); + void SetSystemSettings(float text_scaling_factor, bool enable_high_contrast); + + // Updates accessibility, e.g. switch to high contrast mode + void UpdateAccessibilityFeatures(FlutterAccessibilityFeature flags); private: // Allows swapping out embedder_api_ calls in tests. diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc index ec625d62..745ee3cb 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc @@ -506,7 +506,16 @@ std::pair FlutterELinuxView::GetPointerRotation(double x_px, } void FlutterELinuxView::UpdateHighContrastEnabled(bool enabled) { - // TODO: add UpdateAccessibilityFeatures support + int flags = 0; + if (enabled) { + flags |= + FlutterAccessibilityFeature::kFlutterAccessibilityFeatureHighContrast; + } else { + flags &= + ~FlutterAccessibilityFeature::kFlutterAccessibilityFeatureHighContrast; + } + engine_.get()->UpdateAccessibilityFeatures( + static_cast(flags)); settings_handler_->UpdateHighContrastMode(enabled); } diff --git a/src/flutter/shell/platform/linux_embedded/plugins/settings_plugin.cc b/src/flutter/shell/platform/linux_embedded/plugins/settings_plugin.cc index 6e118739..7603bfe9 100644 --- a/src/flutter/shell/platform/linux_embedded/plugins/settings_plugin.cc +++ b/src/flutter/shell/platform/linux_embedded/plugins/settings_plugin.cc @@ -45,8 +45,13 @@ void SettingsPlugin::SendSettings() { } bool SettingsPlugin::GetAlwaysUse24HourFormat() { - // The current OS does not have 24 hour format factor. - return true; + return is_always_use_24hour_format_; +} + +void SettingsPlugin::UpdateAlwaysUse24HourFormat( + bool is_always_use_24hour_format) { + is_always_use_24hour_format_ = is_always_use_24hour_format; + SendSettings(); } float SettingsPlugin::GetTextScaleFactor() { diff --git a/src/flutter/shell/platform/linux_embedded/plugins/settings_plugin.h b/src/flutter/shell/platform/linux_embedded/plugins/settings_plugin.h index 0029f695..03a1be37 100644 --- a/src/flutter/shell/platform/linux_embedded/plugins/settings_plugin.h +++ b/src/flutter/shell/platform/linux_embedded/plugins/settings_plugin.h @@ -31,6 +31,9 @@ class SettingsPlugin { // Sends settings (e.g., platform brightness) to the engine. void SendSettings(); + // Update the always use 24hour-format status of the system. + void UpdateAlwaysUse24HourFormat(bool is_always_use_24hour_format); + // Update the high contrast status of the system. void UpdateHighContrastMode(bool is_high_contrast); @@ -50,6 +53,7 @@ class SettingsPlugin { std::unique_ptr> channel_; WindowBindingHandler* delegate_; bool is_high_contrast_ = false; + bool is_always_use_24hour_format_ = true; float text_scaling_factor_ = 1.0; }; diff --git a/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h b/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h index 97d93436..2597aa47 100644 --- a/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h +++ b/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h @@ -109,6 +109,9 @@ typedef struct { // Text scaling factor. double text_scale_factor; + // Enable high contrast. Request that UI be rendered with darker colors. + bool enable_high_contrast; + // Force scale factor specified by command line argument bool force_scale_factor; double scale_factor; From f177e1034e2608598ede827f99066638e1266c29 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Wed, 16 Aug 2023 13:56:14 +0000 Subject: [PATCH 073/112] touch-input: fix app crashes on any touch input (#371) This change adds a touch pointer state check and increase device id from touch inputs to fix https://github.com/sony/flutter-elinux/issues/126. Signed-off-by: Hidenori Matsubayashi --- .../linux_embedded/flutter_elinux_view.cc | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc index 745ee3cb..c1bb4803 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc @@ -137,6 +137,13 @@ void FlutterELinuxView::OnTouchDown(uint32_t time, int32_t id, double x, double y) { + // Increase device-id to avoid + // "FML_DCHECK(states_.find(pointer_data.device) == states_.end());" + // exception in flutter/engine. + // This is because "device-id = 0" is used for mouse inputs. + // See engine/lib/ui/window/pointer_data_packet_converter.cc + id += 1; + auto trimmed_xy = GetPointerRotation(x, y); auto* point = GgeTouchPoint(id); if (!point) { @@ -163,10 +170,25 @@ void FlutterELinuxView::OnTouchDown(uint32_t time, } void FlutterELinuxView::OnTouchUp(uint32_t time, int32_t id) { + // Increase device-id to avoid + // "FML_DCHECK(states_.find(pointer_data.device) == states_.end());" + // exception in flutter/engine. + // This is because "device-id = 0" is used for mouse inputs. + // See engine/lib/ui/window/pointer_data_packet_converter.cc + id += 1; + auto* point = GgeTouchPoint(id); if (!point) { return; } + + // Makes sure we have an existing touch pointer in down state to + // avoid "FML_DCHECK(iter != states_.end())" exception in flutter/engine. + // See engine/lib/ui/window/pointer_data_packet_converter.cc + if (point->event_mask != TouchEvent::kDown && + point->event_mask != TouchEvent::kMotion) { + return; + } point->event_mask = TouchEvent::kUp; FlutterPointerEvent event = { @@ -189,11 +211,26 @@ void FlutterELinuxView::OnTouchMotion(uint32_t time, int32_t id, double x, double y) { + // Increase device-id to avoid avoid + // "FML_DCHECK(states_.find(pointer_data.device) == states_.end());" + // exception in flutter/engine. + // This is because "device-id = 0" is used for mouse inputs. + // See engine/lib/ui/window/pointer_data_packet_converter.cc + id += 1; + auto trimmed_xy = GetPointerRotation(x, y); auto* point = GgeTouchPoint(id); if (!point) { return; } + + // Makes sure we have an existing touch pointer in down state to + // avoid "FML_DCHECK(iter != states_.end())" exception in flutter/engine. + // See engine/lib/ui/window/pointer_data_packet_converter.cc + if (point->event_mask != TouchEvent::kDown && + point->event_mask != TouchEvent::kMotion) { + return; + } point->event_mask = TouchEvent::kMotion; point->x = trimmed_xy.first; point->y = trimmed_xy.second; From 23589c382dbddf8542da4c72aff4ff42a96dca44 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Thu, 17 Aug 2023 05:30:00 +0000 Subject: [PATCH 074/112] common: fix syntax error in event_channel.h (#372) This change fixes the following build error in event_channel.h. ----- /home/hidenori/work/flutter/flutter-elinux-plugins/packages/camera/example/elinux/flutter/ephemeral/cpp_client_wrapper/include/flutter/e vent_channel.h:95:27: error: invalid operands to binary expression ('basic_ostream>' and 'const std::unique_ptr') << (error->error_details); ^ ~~~~~~~~~~~~~~~~~~~~~~ /home/hidenori/work/flutter/flutter-elinux-plugins/packages/camera/example/elinux/flutter/ephemeral/.plugin_symlinks/camera_elinux/elinu x/channels/event_channel_image_stream.cc:44:18: note: in instantiation of member function 'flutter::EventChannel<>::SetStreamHandler' requested here event_channel->SetStreamHandler(std::move(event_channel_handler)); ^ /usr/bin/../lib/gcc/aarch64-linux-gnu/11/../../../../include/c++/11/system_error:279:5: note: candidate function template not viable: no known conversion from 'const std::unique_ptr' to 'const std::error_code' for 2nd argument operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __e) ^ /usr/bin/../lib/gcc/aarch64-linux-gnu/11/../../../../include/c++/11/ostream:518:5: note: candidate function template not viable: no known conversion from 'const std::unique_ptr' to 'char' for 2nd argument operator<<(basic_ostream<_CharT, _Traits>& __out, char __c) ----- Signed-off-by: Hidenori Matsubayashi --- .../common/client_wrapper/include/flutter/event_channel.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flutter/shell/platform/common/client_wrapper/include/flutter/event_channel.h b/src/flutter/shell/platform/common/client_wrapper/include/flutter/event_channel.h index 6a3ef09b..c96e6408 100644 --- a/src/flutter/shell/platform/common/client_wrapper/include/flutter/event_channel.h +++ b/src/flutter/shell/platform/common/client_wrapper/include/flutter/event_channel.h @@ -92,7 +92,7 @@ class EventChannel { std::cerr << "Failed to cancel existing stream: " << (error->error_code) << ", " << (error->error_message) << ", " - << (error->error_details); + << (error->error_details.get()); } } is_listening = true; From 7f83ccb9a9790ab31758e76b3b5498be2af32af7 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Thu, 17 Aug 2023 20:39:32 +0000 Subject: [PATCH 075/112] lifecycle_plugin: add hidden state (#373) This change adds a new state hidden to lifecycle plugin. Signed-off-by: Hidenori Matsubayashi --- .../platform/linux_embedded/plugins/lifecycle_plugin.cc | 7 +++++++ .../platform/linux_embedded/plugins/lifecycle_plugin.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/src/flutter/shell/platform/linux_embedded/plugins/lifecycle_plugin.cc b/src/flutter/shell/platform/linux_embedded/plugins/lifecycle_plugin.cc index 009d82eb..002457db 100644 --- a/src/flutter/shell/platform/linux_embedded/plugins/lifecycle_plugin.cc +++ b/src/flutter/shell/platform/linux_embedded/plugins/lifecycle_plugin.cc @@ -15,6 +15,8 @@ constexpr char kInactive[] = "AppLifecycleState.inactive"; constexpr char kResumed[] = "AppLifecycleState.resumed"; constexpr char kPaused[] = "AppLifecycleState.paused"; constexpr char kDetached[] = "AppLifecycleState.detached"; +constexpr char kHidden[] = "AppLifecycleState.hidden"; + } // namespace LifecyclePlugin::LifecyclePlugin(BinaryMessenger* messenger) @@ -43,4 +45,9 @@ void LifecyclePlugin::OnDetached() const { channel_->Send(std::string(kDetached)); } +void LifecyclePlugin::OnHidden() const { + ELINUX_LOG(DEBUG) << "App lifecycle changed to hidden state."; + channel_->Send(std::string(kHidden)); +} + } // namespace flutter diff --git a/src/flutter/shell/platform/linux_embedded/plugins/lifecycle_plugin.h b/src/flutter/shell/platform/linux_embedded/plugins/lifecycle_plugin.h index aa9507c2..784fbd61 100644 --- a/src/flutter/shell/platform/linux_embedded/plugins/lifecycle_plugin.h +++ b/src/flutter/shell/platform/linux_embedded/plugins/lifecycle_plugin.h @@ -25,6 +25,8 @@ class LifecyclePlugin { void OnDetached() const; + void OnHidden() const; + private: std::unique_ptr> channel_; }; From 549415f9f70698661fad9fdf64055f1af67040b0 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Fri, 18 Aug 2023 01:23:13 +0000 Subject: [PATCH 076/112] wayland: add notification of display changes to embedder (#374) This change adds notification of display changes to embedder support in Wayland backend. Signed-off-by: Hidenori Matsubayashi --- .../linux_embedded/flutter_elinux_engine.cc | 8 ++++++++ .../linux_embedded/flutter_elinux_engine.h | 5 +++++ .../linux_embedded/flutter_elinux_view.cc | 19 +++++++++++++++++++ .../linux_embedded/flutter_elinux_view.h | 6 ++++++ .../linux_embedded/window/elinux_window.h | 17 +++++++++++++++++ .../linux_embedded/window/elinux_window_drm.h | 4 ---- .../window/elinux_window_wayland.cc | 2 +- .../window/elinux_window_wayland.h | 5 ----- .../linux_embedded/window/elinux_window_x11.h | 4 ---- .../window_binding_handler_delegate.h | 10 ++++++++++ 10 files changed, 66 insertions(+), 14 deletions(-) diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc index 8354eaf1..2fbec1eb 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc @@ -440,4 +440,12 @@ void FlutterELinuxEngine::UpdateAccessibilityFeatures( embedder_api_.UpdateAccessibilityFeatures(engine_, flags); } +void FlutterELinuxEngine::UpdateDisplayInfo( + FlutterEngineDisplaysUpdateType update_type, + const FlutterEngineDisplay* displays, + size_t display_count) { + embedder_api_.NotifyDisplayUpdate(engine_, update_type, displays, + display_count); +} + } // namespace flutter diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h index 28bbf43c..b705941e 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h @@ -133,6 +133,11 @@ class FlutterELinuxEngine { // Updates accessibility, e.g. switch to high contrast mode void UpdateAccessibilityFeatures(FlutterAccessibilityFeature flags); + // Update display information. + void UpdateDisplayInfo(FlutterEngineDisplaysUpdateType update_type, + const FlutterEngineDisplay* displays, + size_t display_count); + private: // Allows swapping out embedder_api_ calls in tests. friend class EngineEmbedderApiModifier; diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc index c1bb4803..68d0bac4 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc @@ -560,4 +560,23 @@ void FlutterELinuxView::UpdateTextScaleFactor(float factor) { settings_handler_->UpdateTextScaleFactor(factor); } +void FlutterELinuxView::UpdateDisplayInfo(double refresh_rate, + size_t width_px, + size_t height_px, + double pixel_ratio) { + const FlutterEngineDisplaysUpdateType update_type = + kFlutterEngineDisplaysUpdateTypeStartup; + const FlutterEngineDisplay displays = { + .struct_size = sizeof(FlutterEngineDisplay), + .display_id = 0, + .single_display = true, + .refresh_rate = refresh_rate, + .width = width_px, + .height = height_px, + .device_pixel_ratio = pixel_ratio, + }; + const size_t display_count = 1; + engine_.get()->UpdateDisplayInfo(update_type, &displays, display_count); +} + } // namespace flutter diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.h b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.h index 977bd3e1..08740eff 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.h +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.h @@ -151,6 +151,12 @@ class FlutterELinuxView : public WindowBindingHandlerDelegate { // |WindowBindingHandlerDelegate| void UpdateTextScaleFactor(float factor) override; + // |WindowBindingHandlerDelegate| + void UpdateDisplayInfo(double refresh_rate, + size_t width_px, + size_t height_px, + double pixel_ratio) override; + private: // Struct holding the mouse state. The engine doesn't keep track of which // mouse buttons have been pressed, so it's the embedding's responsibility. diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window.h b/src/flutter/shell/platform/linux_embedded/window/elinux_window.h index 8c4e9d15..e9b6bf66 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window.h +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window.h @@ -5,7 +5,10 @@ #ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_ELINUX_WINDOW_H_ #define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_ELINUX_WINDOW_H_ +#include + #include "flutter/shell/platform/linux_embedded/public/flutter_elinux.h" +#include "flutter/shell/platform/linux_embedded/window_binding_handler.h" namespace flutter { @@ -39,9 +42,23 @@ class ELinuxWindow { } } + void NotifyDisplayInfoUpdates() const { + if (binding_handler_delegate_) { + binding_handler_delegate_->UpdateDisplayInfo( + std::trunc(1000000.0 / frame_rate_), GetCurrentWidth(), + GetCurrentHeight(), current_scale_); + } + } + FlutterDesktopViewProperties view_properties_; + + // A pointer to a FlutterWindowsView that can be used to update engine + // windowing and input state. + WindowBindingHandlerDelegate* binding_handler_delegate_ = nullptr; + int32_t display_max_width_ = -1; int32_t display_max_height_ = -1; + int32_t frame_rate_ = 60000; double current_scale_ = 1.0; uint16_t current_rotation_ = 0; // The x coordinate of the pointer in physical pixels. diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h b/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h index 92c70ad7..272bc9be 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h @@ -708,10 +708,6 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { bool is_pointer_device; }; - // A pointer to a FlutterWindowsView that can be used to update engine - // windowing and input state. - WindowBindingHandlerDelegate* binding_handler_delegate_ = nullptr; - std::unique_ptr native_window_; std::unique_ptr render_surface_; diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc index 1c74ad08..1f62cf31 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc @@ -1041,7 +1041,6 @@ ELinuxWindowWayland::ELinuxWindowWayland( zwp_text_input_v3_(nullptr), wp_presentation_(nullptr), wp_presentation_clk_id_(UINT32_MAX), - frame_rate_(60000), window_decorations_(nullptr) { view_properties_ = view_properties; current_scale_ = @@ -1281,6 +1280,7 @@ bool ELinuxWindowWayland::DispatchEvent() { view_properties_.height * current_scale_ - WindowDecorationsPhysicalHeight()); } + NotifyDisplayInfoUpdates(); } // Prepare to call wl_display_read_events. diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h index 6ba5f722..2d1343d5 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h @@ -135,10 +135,6 @@ class ELinuxWindowWayland : public ELinuxWindow, public WindowBindingHandler { kZxdgToplevelDecorationV1Listener; static constexpr size_t kDefaultPointerSize = 24; - // A pointer to a FlutterWindowsView that can be used to update engine - // windowing and input state. - WindowBindingHandlerDelegate* binding_handler_delegate_ = nullptr; - std::unique_ptr native_window_; std::unique_ptr render_surface_; @@ -189,7 +185,6 @@ class ELinuxWindowWayland : public ELinuxWindow, public WindowBindingHandler { wp_presentation* wp_presentation_; uint32_t wp_presentation_clk_id_; uint64_t last_frame_time_nanos_; - int32_t frame_rate_; CursorInfo cursor_info_; size_t cursor_size_; diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.h b/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.h index 9d364526..eb11171e 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.h +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.h @@ -70,10 +70,6 @@ class ELinuxWindowX11 : public ELinuxWindow, public WindowBindingHandler { int16_t x, int16_t y); - // A pointer to a FlutterWindowsView that can be used to update engine - // windowing and input state. - WindowBindingHandlerDelegate* binding_handler_delegate_ = nullptr; - Display* display_ = nullptr; std::unique_ptr native_window_; std::unique_ptr render_surface_; diff --git a/src/flutter/shell/platform/linux_embedded/window_binding_handler_delegate.h b/src/flutter/shell/platform/linux_embedded/window_binding_handler_delegate.h index 3bc6429d..ad51a5d2 100644 --- a/src/flutter/shell/platform/linux_embedded/window_binding_handler_delegate.h +++ b/src/flutter/shell/platform/linux_embedded/window_binding_handler_delegate.h @@ -110,6 +110,16 @@ class WindowBindingHandlerDelegate { // Update the status of the text scaling factor feature virtual void UpdateTextScaleFactor(float factor) = 0; + + // Update the status of the corresponding to display changes. + // @param[in] refresh_rate Refresh rate of the display. + // @param[in] width_px Physical width of the display. + // @param[in] height_px Physical height of the display. + // @param[in] pixel_ratio Pixel ratio of the display. + virtual void UpdateDisplayInfo(double refresh_rate, + size_t width_px, + size_t height_px, + double pixel_ratio) = 0; }; } // namespace flutter From a33ae027cee6792a4e142d8d5c135544f66ea1f7 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Fri, 18 Aug 2023 22:04:24 +0000 Subject: [PATCH 077/112] wayland: disable vsync waiter (#376) Disable vsync waiter as it may be causing rendering issues. Related issue (maybe) https://github.com/sony/flutter-elinux/issues/205 Signed-off-by: Hidenori Matsubayashi --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 723556b3..19abd447 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ option(BACKEND_TYPE "Select WAYLAND, DRM-GBM, DRM-EGLSTREAM, or X11 as the displ option(USE_DIRTY_REGION_MANAGEMENT "Use Flutter dirty region management" ON) option(USE_GLES3 "Use OpenGL ES3 (default is OpenGL ES2)" OFF) option(ENABLE_EGL_ALPHA_COMPONENT_OF_COLOR_BUFFER "Enable alpha component of the EGL color buffer" ON) -option(ENABLE_VSYNC "Enable embedder vsync" ON) +option(ENABLE_VSYNC "Enable embedder vsync" OFF) # todo: need to investigate https://github.com/sony/flutter-embedded-linux/pull/376 when enabling this option. option(BUILD_ELINUX_SO "Build .so file of elinux embedder" OFF) option(ENABLE_ELINUX_EMBEDDER_LOG "Enable logger of eLinux embedder" ON) option(FLUTTER_RELEASE "Build Flutter Engine with release mode" OFF) From 3113b7b097cd9b17767a9b1d27cec9c262565233 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Sun, 20 Aug 2023 12:10:54 +0000 Subject: [PATCH 078/112] platform-views: implement more APIs in platform views (#375) Related issue: https://github.com/sony/flutter-embedded-linux/issues/41 Signed-off-by: Hidenori Matsubayashi --- .../plugins/platform_views_plugin.cc | 116 ++++++++++++++++-- .../plugins/platform_views_plugin.h | 20 +++ .../public/flutter_platform_views.h | 11 +- 3 files changed, 136 insertions(+), 11 deletions(-) diff --git a/src/flutter/shell/platform/linux_embedded/plugins/platform_views_plugin.cc b/src/flutter/shell/platform/linux_embedded/plugins/platform_views_plugin.cc index 85c553e8..c2bc5cf2 100644 --- a/src/flutter/shell/platform/linux_embedded/plugins/platform_views_plugin.cc +++ b/src/flutter/shell/platform/linux_embedded/plugins/platform_views_plugin.cc @@ -21,12 +21,16 @@ constexpr char kAcceptGestureMethod[] = "acceptGesture"; constexpr char kRejectGestureMethod[] = "rejectGesture"; constexpr char kEnterMethod[] = "enter"; constexpr char kExitMethod[] = "exit"; +constexpr char kOffsetMethod[] = "offset"; constexpr char kViewTypeKey[] = "viewType"; constexpr char kIdKey[] = "id"; constexpr char kWidthKey[] = "width"; constexpr char kHeightKey[] = "height"; constexpr char kParamsKey[] = "params"; + +constexpr char kTopKey[] = "top"; +constexpr char kLeftKey[] = "left"; } // namespace PlatformViewsPlugin::PlatformViewsPlugin(BinaryMessenger* messenger) @@ -63,6 +67,7 @@ void PlatformViewsPlugin::RegisterViewFactory( << view_type; return; } + ELINUX_LOG(DEBUG) << view_type << " was registered"; platform_view_factories_[view_type] = std::move(factory); } @@ -78,13 +83,13 @@ void PlatformViewsPlugin::HandleMethodCall( } else if (method.compare(kDisposeMethod) == 0) { PlatformViewsDispose(arguments, std::move(result)); } else if (method.compare(kResizeMethod) == 0) { - result->NotImplemented(); + PlatformViewsResize(arguments, std::move(result)); } else if (method.compare(kSetDirectionMethod) == 0) { result->NotImplemented(); } else if (method.compare(kClearFocusMethod) == 0) { - result->NotImplemented(); + PlatformViewsClearFocus(arguments, std::move(result)); } else if (method.compare(kTouchMethod) == 0) { - result->NotImplemented(); + PlatformViewsTouch(arguments, std::move(result)); } else if (method.compare(kAcceptGestureMethod) == 0) { result->NotImplemented(); } else if (method.compare(kRejectGestureMethod) == 0) { @@ -93,6 +98,8 @@ void PlatformViewsPlugin::HandleMethodCall( result->NotImplemented(); } else if (method.compare(kExitMethod) == 0) { result->NotImplemented(); + } else if (method.compare(kOffsetMethod) == 0) { + PlatformViewsOffset(arguments, std::move(result)); } else { ELINUX_LOG(WARNING) << "Platform Views unexpected method is called: " << method; @@ -109,10 +116,6 @@ void PlatformViewsPlugin::PlatformViewsCreate( return; } auto view_id = LookupEncodableMap(arguments, kIdKey); - if (!view_id) { - result->Error("Couldn't find the view id in the arguments"); - return; - } auto view_width = LookupEncodableMap(arguments, kWidthKey); if (!view_width) { result->Error("Couldn't find width in the arguments"); @@ -153,17 +156,110 @@ void PlatformViewsPlugin::PlatformViewsDispose( const flutter::EncodableValue& arguments, std::unique_ptr> result) { auto view_id = LookupEncodableMap(arguments, kIdKey); - if (!view_id) { + ELINUX_LOG(DEBUG) << "Dispose the platform view: id = " << view_id; + if (platform_views_.find(view_id) == platform_views_.end()) { result->Error("Couldn't find the view id in the arguments"); return; } + platform_views_[view_id]->Dispose(); + result->Success(); +} - ELINUX_LOG(DEBUG) << "Dispose the platform view: id = " << view_id; +void PlatformViewsPlugin::PlatformViewsClearFocus( + const flutter::EncodableValue& arguments, + std::unique_ptr> result) { + auto view_id = LookupEncodableMap(arguments, kIdKey); + ELINUX_LOG(DEBUG) << "ClearFocus the platform view: id = " << view_id; if (platform_views_.find(view_id) == platform_views_.end()) { result->Error("Couldn't find the view id in the arguments"); return; } - platform_views_[view_id]->Dispose(); + platform_views_[view_id]->SetFocus(false); + platform_views_[view_id]->ClearFocus(); + + result->Success(); +} + +void PlatformViewsPlugin::PlatformViewsResize( + const flutter::EncodableValue& arguments, + std::unique_ptr> result) { + auto view_id = LookupEncodableMap(arguments, kIdKey); + auto view_width = LookupEncodableMap(arguments, kWidthKey); + if (!view_width) { + result->Error("Couldn't find width in the arguments"); + return; + } + auto view_height = LookupEncodableMap(arguments, kHeightKey); + if (!view_height) { + result->Error("Couldn't find height in the arguments"); + return; + } + + ELINUX_LOG(DEBUG) << "Resize the platform view: id = " << view_id + << ", width = " << view_width + << ", height = " << view_height; + if (platform_views_.find(view_id) == platform_views_.end()) { + result->Error("Couldn't find the view id in the arguments"); + return; + } + + if (!view_width || !view_height) { + result->Error("width and height must be greater than zero"); + return; + } + + platform_views_[view_id]->Resize(view_width, view_height); + + result->Success(arguments); +} + +void PlatformViewsPlugin::PlatformViewsTouch( + const flutter::EncodableValue& arguments, + std::unique_ptr> result) { + auto list = std::get(arguments); + auto view_id = std::get(list[0]); + auto event_type = std::get(list[3]); + auto device_id = std::get(list[11]); + + auto pointer_coords = std::get(list[6]); + if (pointer_coords.size() < 1) { + result->Error("Couldn't find the pointer_coords in the arguments"); + return; + } + auto pointer_coord = std::get(pointer_coords[0]); + auto x = std::get(pointer_coord[7]); + auto y = std::get(pointer_coord[8]); + + ELINUX_LOG(ERROR) << "Touch the platform view: id = " << view_id + << ", device_id = " << device_id + << ", event_type = " << event_type << ", x = " << x + << ", y = " << y; + if (platform_views_.find(view_id) == platform_views_.end()) { + result->Error("Couldn't find the view id in the arguments"); + return; + } + + platform_views_[view_id]->Touch(device_id, event_type, x, y); + + result->Success(); +} + +void PlatformViewsPlugin::PlatformViewsOffset( + const flutter::EncodableValue& arguments, + std::unique_ptr> result) { + auto view_id = LookupEncodableMap(arguments, kIdKey); + auto view_top = LookupEncodableMap(arguments, kTopKey); + auto view_left = LookupEncodableMap(arguments, kLeftKey); + ELINUX_LOG(DEBUG) << "Offset the platform view: " + << "id = " << view_id << ", top = " << view_top + << ", left = " << view_left; + if (platform_views_.find(view_id) == platform_views_.end()) { + result->Error("Couldn't find the view id in the arguments"); + return; + } + + platform_views_[view_id]->Offset(view_top, view_left); + result->Success(); } diff --git a/src/flutter/shell/platform/linux_embedded/plugins/platform_views_plugin.h b/src/flutter/shell/platform/linux_embedded/plugins/platform_views_plugin.h index 2530481f..8c17e078 100644 --- a/src/flutter/shell/platform/linux_embedded/plugins/platform_views_plugin.h +++ b/src/flutter/shell/platform/linux_embedded/plugins/platform_views_plugin.h @@ -52,6 +52,26 @@ class PlatformViewsPlugin { const flutter::EncodableValue& arguments, std::unique_ptr> result); + // Called when "clearFocus" method is called + void PlatformViewsClearFocus( + const flutter::EncodableValue& arguments, + std::unique_ptr> result); + + // Called when "resize" method is called + void PlatformViewsResize( + const flutter::EncodableValue& arguments, + std::unique_ptr> result); + + // Called when "touch" method is called + void PlatformViewsTouch( + const flutter::EncodableValue& arguments, + std::unique_ptr> result); + + // Called when "offset" method is called + void PlatformViewsOffset( + const flutter::EncodableValue& arguments, + std::unique_ptr> result); + // Method channel instance. std::unique_ptr> channel_; diff --git a/src/flutter/shell/platform/linux_embedded/public/flutter_platform_views.h b/src/flutter/shell/platform/linux_embedded/public/flutter_platform_views.h index 5ecb2f30..a1ff65ec 100644 --- a/src/flutter/shell/platform/linux_embedded/public/flutter_platform_views.h +++ b/src/flutter/shell/platform/linux_embedded/public/flutter_platform_views.h @@ -9,10 +9,11 @@ #include #include +#include +#include #include "flutter_export.h" #include "flutter_messenger.h" -#include "plugin_registrar.h" class FlutterDesktopPlatformView { public: @@ -31,12 +32,20 @@ class FlutterDesktopPlatformView { void SetFocus(bool focus) { focused_ = focus; } + virtual void ClearFocus() = 0; + bool IsFocused() const { return focused_; } void SetTextureId(int texture_id) { texture_id_ = texture_id; } int GetTextureId() const { return texture_id_; } + virtual void Resize(double width, double height) = 0; + + virtual void Touch(int device_id, int event_type, double x, double y) = 0; + + virtual void Offset(double top, double left) = 0; + private: flutter::PluginRegistrar* registrar_; int view_id_; From 0501df9c1d2ff71aa346541020de7bf3a5e25d35 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Sun, 20 Aug 2023 12:22:45 +0000 Subject: [PATCH 079/112] github-actions: update actions/checkout from v2 to v3 (#377) This change updates actions/checkout version from v2 to v3. Signed-off-by: Hidenori Matsubayashi --- .github/workflows/build-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index ddd680ed..69b58791 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Install libraries run: | From 98e15f31976b8712949afe963322e950de7cfdb2 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Mon, 21 Aug 2023 11:21:44 +0000 Subject: [PATCH 080/112] platform-views: fix wrong log level (#378) This change fixes a wrong log level setting in platform-views implementation. Signed-off-by: Hidenori Matsubayashi --- .../platform/linux_embedded/plugins/platform_views_plugin.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flutter/shell/platform/linux_embedded/plugins/platform_views_plugin.cc b/src/flutter/shell/platform/linux_embedded/plugins/platform_views_plugin.cc index c2bc5cf2..81b29462 100644 --- a/src/flutter/shell/platform/linux_embedded/plugins/platform_views_plugin.cc +++ b/src/flutter/shell/platform/linux_embedded/plugins/platform_views_plugin.cc @@ -230,7 +230,7 @@ void PlatformViewsPlugin::PlatformViewsTouch( auto x = std::get(pointer_coord[7]); auto y = std::get(pointer_coord[8]); - ELINUX_LOG(ERROR) << "Touch the platform view: id = " << view_id + ELINUX_LOG(TRACE) << "Touch the platform view: id = " << view_id << ", device_id = " << device_id << ", event_type = " << event_type << ", x = " << x << ", y = " << y; From 311e9f189a55971c997916c13df49d5e46df4d26 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Mon, 21 Aug 2023 12:23:50 +0000 Subject: [PATCH 081/112] platform-views: fix wrong size of texture id (#379) This change fixes wrong size of texture id. Related issue: #41 Signed-off-by: Hidenori Matsubayashi --- .../platform/linux_embedded/public/flutter_platform_views.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/flutter/shell/platform/linux_embedded/public/flutter_platform_views.h b/src/flutter/shell/platform/linux_embedded/public/flutter_platform_views.h index a1ff65ec..0e7c9d52 100644 --- a/src/flutter/shell/platform/linux_embedded/public/flutter_platform_views.h +++ b/src/flutter/shell/platform/linux_embedded/public/flutter_platform_views.h @@ -36,9 +36,9 @@ class FlutterDesktopPlatformView { bool IsFocused() const { return focused_; } - void SetTextureId(int texture_id) { texture_id_ = texture_id; } + void SetTextureId(int64_t texture_id) { texture_id_ = texture_id; } - int GetTextureId() const { return texture_id_; } + int64_t GetTextureId() const { return texture_id_; } virtual void Resize(double width, double height) = 0; @@ -49,7 +49,7 @@ class FlutterDesktopPlatformView { private: flutter::PluginRegistrar* registrar_; int view_id_; - int texture_id_; + int64_t texture_id_; bool focused_; }; From c696e5b2fcedc9ad9752d8c113bc1f9cdc39be64 Mon Sep 17 00:00:00 2001 From: Snarpix Date: Fri, 25 Aug 2023 23:30:36 +0200 Subject: [PATCH 082/112] Fixed ContextEgl construction for eglstreams. Added support for Nvidia Tegra TX1/TX2 (#381) Signed-off-by: Stanislav Shmarov --- AUTHORS | 1 + .../surface/context_egl_stream.cc | 2 +- .../linux_embedded/window/elinux_window_drm.h | 47 ++++++++++--------- .../window/native_window_drm.cc | 6 ++- .../linux_embedded/window/native_window_drm.h | 2 + 5 files changed, 34 insertions(+), 24 deletions(-) diff --git a/AUTHORS b/AUTHORS index 1812758d..d82960b5 100644 --- a/AUTHORS +++ b/AUTHORS @@ -12,3 +12,4 @@ FlafyDev Makoto Sato (makoto.sato@atmark-techno.com) Yunhao Tian (t123yh@outlook.com) Luke Howard +Stanislav Shmarov diff --git a/src/flutter/shell/platform/linux_embedded/surface/context_egl_stream.cc b/src/flutter/shell/platform/linux_embedded/surface/context_egl_stream.cc index 2f1df0c5..61d699f7 100644 --- a/src/flutter/shell/platform/linux_embedded/surface/context_egl_stream.cc +++ b/src/flutter/shell/platform/linux_embedded/surface/context_egl_stream.cc @@ -11,7 +11,7 @@ namespace flutter { ContextEglStream::ContextEglStream( std::unique_ptr environment) - : ContextEgl(std::move(environment), EGL_STREAM_BIT_KHR) { + : ContextEgl(std::move(environment), false, EGL_STREAM_BIT_KHR) { if (!valid_) { return; } diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h b/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h index 272bc9be..8b6c0767 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -262,29 +263,31 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { } constexpr char kFileNameSeparator[] = "/"; - auto pos = device_filename.find_last_of(kFileNameSeparator); - if (pos == std::string::npos) { - ELINUX_LOG(ERROR) << "Failed to get device name position."; - udev_unref(udev); - return false; - } + if (device_filename != "drm-nvdc") { + auto pos = device_filename.find_last_of(kFileNameSeparator); + if (pos == std::string::npos) { + ELINUX_LOG(ERROR) << "Failed to get device name position."; + udev_unref(udev); + return false; + } - auto device_name = device_filename.substr(pos + 1); - auto device = udev_device_new_from_subsystem_sysname( - udev, kUdevMonitorSubsystemDrm, device_name.c_str()); - if (!device) { - ELINUX_LOG(ERROR) << "Failed to get device from " << device_name; - udev_unref(udev); - return false; - } + auto device_name = device_filename.substr(pos + 1); + auto device = udev_device_new_from_subsystem_sysname( + udev, kUdevMonitorSubsystemDrm, device_name.c_str()); + if (!device) { + ELINUX_LOG(ERROR) << "Failed to get device from " << device_name; + udev_unref(udev); + return false; + } - auto sysnum = udev_device_get_sysnum(device); - if (!sysnum) { - ELINUX_LOG(ERROR) << "Failed to get device id."; - udev_unref(udev); - return false; + auto sysnum = udev_device_get_sysnum(device); + if (!sysnum) { + ELINUX_LOG(ERROR) << "Failed to get device id."; + udev_unref(udev); + return false; + } + drm_device_id_ = std::atoi(sysnum); } - drm_device_id_ = std::atoi(sysnum); udev_unref(udev); if (sd_event_new(&udev_drm_event_loop_) < 0) { @@ -348,7 +351,7 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { if (!sysnum) { ELINUX_LOG(ERROR) << "Failed to get device id."; return false; - } else if (std::atoi(sysnum) != drm_device_id_) { + } else if (drm_device_id_ && std::atoi(sysnum) != *drm_device_id_) { ELINUX_LOG(ERROR) << "Not expected device id."; return false; } @@ -721,7 +724,7 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { sd_event* udev_drm_event_loop_ = nullptr; udev_monitor* udev_monitor_ = nullptr; - int drm_device_id_; + std::optional drm_device_id_; }; } // namespace flutter diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_drm.cc b/src/flutter/shell/platform/linux_embedded/window/native_window_drm.cc index 97d8363c..59a29021 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_drm.cc +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_drm.cc @@ -18,7 +18,11 @@ namespace flutter { NativeWindowDrm::NativeWindowDrm(const char* device_filename, const uint16_t rotation, bool enable_vsync) { - drm_device_ = open(device_filename, O_RDWR | O_CLOEXEC); + if (!strcmp("drm-nvdc", device_filename)) { + drm_device_ = drmOpen(device_filename, nullptr); + } else { + drm_device_ = open(device_filename, O_RDWR | O_CLOEXEC); + } if (drm_device_ == -1) { ELINUX_LOG(ERROR) << "Couldn't open " << device_filename; return; diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_drm.h b/src/flutter/shell/platform/linux_embedded/window/native_window_drm.h index 2a21b569..bae9ec06 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_drm.h +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_drm.h @@ -7,6 +7,8 @@ #include +#include +#include #include #include "flutter/shell/platform/linux_embedded/surface/surface_gl.h" From 6d652df06f94ffd42bd330bde9d77971db92985e Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Thu, 21 Sep 2023 11:37:54 +0000 Subject: [PATCH 083/112] engine: disable fbo_reset_after_present to avoid flicker issues on some H/W (#385) See https://github.com/sony/flutter-embedded-linux/issues/334 Signed-off-by: Hidenori Matsubayashi --- .../shell/platform/linux_embedded/flutter_elinux_engine.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc index 2fbec1eb..798aa139 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc @@ -42,7 +42,10 @@ FlutterRendererConfig GetRendererConfig() { } return host->view()->ClearCurrent(); }; - config.open_gl.fbo_reset_after_present = true; + // Temporary disabled fbo_reset_after_present to avoid flicker and other + // rendering issues on some H/W. See + // https://github.com/sony/flutter-embedded-linux/issues/334 + config.open_gl.fbo_reset_after_present = false; #if defined(USE_OPENGL_DIRTY_REGION_MANAGEMENT) config.open_gl.present_with_info = [](void* user_data, const FlutterPresentInfo* info) -> bool { From ac2a2c66427b5bbb2af6338312f3b27dc04556ab Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Fri, 22 Sep 2023 10:48:50 +0000 Subject: [PATCH 084/112] Revert "engine: disable fbo_reset_after_present to avoid flicker issues on some H/W (#385)" (#386) This reverts commit 6d652df06f94ffd42bd330bde9d77971db92985e. Related issue #334 --- .../shell/platform/linux_embedded/flutter_elinux_engine.cc | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc index 798aa139..2fbec1eb 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc @@ -42,10 +42,7 @@ FlutterRendererConfig GetRendererConfig() { } return host->view()->ClearCurrent(); }; - // Temporary disabled fbo_reset_after_present to avoid flicker and other - // rendering issues on some H/W. See - // https://github.com/sony/flutter-embedded-linux/issues/334 - config.open_gl.fbo_reset_after_present = false; + config.open_gl.fbo_reset_after_present = true; #if defined(USE_OPENGL_DIRTY_REGION_MANAGEMENT) config.open_gl.present_with_info = [](void* user_data, const FlutterPresentInfo* info) -> bool { From 820ee198b3a888cbe9dd06a9fffb3930c7166fc0 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Fri, 29 Sep 2023 18:00:52 +0900 Subject: [PATCH 085/112] WAR: temporarily disable partial repaints (#388) This change disables the partial repaints temporarily because of the flicker issue. Once the root cause in flutter/engine was fixed and its change propagated to the stable channel, this will be lifted up. See https://github.com/sony/flutter-embedded-linux/issues/334 for the details. Signed-off-by: Hidenori Matsubayashi --- .../platform/linux_embedded/surface/elinux_egl_surface.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.cc b/src/flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.cc index 07fede87..2efe002b 100644 --- a/src/flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.cc +++ b/src/flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.cc @@ -168,6 +168,11 @@ void ELinuxEGLSurface::PopulateExistingDamage(const intptr_t fbo_id, 0, 0, static_cast(width_px_), static_cast(height_px_)}; existing_damage->damage = existing_damage_map_[fbo_id]; + // Temporarily disabled partial repaints due to + // https://github.com/sony/flutter-embedded-linux/issues/334. Once + // https://github.com/flutter/engine/pull/45611 was merged and propagated to + // the stable channel, this will be lifted up. +#if 0 if (age > 1) { --age; // join up to (age - 1) last rects from damage history @@ -191,6 +196,7 @@ void ELinuxEGLSurface::PopulateExistingDamage(const intptr_t fbo_id, } } } +#endif } // Auxiliary function used to transform a FlutterRect into the format that is From 32d8a7a83481150e0226787c7dbfb42d741e6d5c Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Sat, 30 Sep 2023 08:30:13 +0900 Subject: [PATCH 086/112] x11: support fullscreen option (#389) This change adds fullscreen option support. Related issues: - https://github.com/sony/flutter-embedded-linux/issues/37 - https://github.com/sony/flutter-elinux/issues/136 Signed-off-by: Hidenori Matsubayashi --- .../window/elinux_window_x11.cc | 3 ++- .../window/native_window_x11.cc | 21 ++++++++++++++----- .../linux_embedded/window/native_window_x11.h | 3 ++- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.cc index ea4e4dfc..862c4d64 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.cc @@ -132,7 +132,8 @@ bool ELinuxWindowX11::CreateRenderSurface(int32_t width, } native_window_ = std::make_unique( display_, context_egl->GetAttrib(EGL_NATIVE_VISUAL_ID), - view_properties_.title, width, height, view_properties_.enable_vsync); + view_properties_.title, width, height, view_properties_.enable_vsync, + view_properties_.view_mode == FlutterDesktopViewMode::kFullscreen); if (!native_window_->IsValid()) { ELINUX_LOG(ERROR) << "Failed to create the native window"; return false; diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_x11.cc b/src/flutter/shell/platform/linux_embedded/window/native_window_x11.cc index 51f3cc11..e6da1ea1 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_x11.cc +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_x11.cc @@ -23,7 +23,8 @@ NativeWindowX11::NativeWindowX11(Display* display, const char* title, const size_t width, const size_t height, - bool enable_vsync) { + bool enable_vsync, + bool fullscreen) { XVisualInfo visualTemplate; visualTemplate.visualid = visual_id; @@ -44,10 +45,20 @@ NativeWindowX11::NativeWindowX11(Display* display, ButtonReleaseMask | PointerMotionMask | EnterWindowMask | LeaveWindowMask | FocusChangeMask | StructureNotifyMask; - window_ = - XCreateWindow(display, RootWindow(display, visual->screen), 0, 0, width, - height, 0, visual->depth, InputOutput, visual->visual, - CWBorderPixel | CWColormap | CWEventMask, &windowAttribs); + auto window_width = width; + auto window_height = height; + if (fullscreen) { + XWindowAttributes attr; + XGetWindowAttributes(display, RootWindow(display, visual->screen), &attr); + window_width = attr.width; + window_height = attr.height; + windowAttribs.override_redirect = True; + } + + window_ = XCreateWindow( + display, RootWindow(display, visual->screen), 0, 0, window_width, + window_height, 0, visual->depth, InputOutput, visual->visual, + CWBorderPixel | CWColormap | CWEventMask, &windowAttribs); if (!window_) { ELINUX_LOG(ERROR) << "Failed to the create window."; return; diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_x11.h b/src/flutter/shell/platform/linux_embedded/window/native_window_x11.h index 878d864d..9cb9f786 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_x11.h +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_x11.h @@ -18,7 +18,8 @@ class NativeWindowX11 : public NativeWindow { const char* title, const size_t width, const size_t height, - bool enable_vsync); + bool enable_vsync, + bool fullscreen); ~NativeWindowX11() = default; // |NativeWindow| From 6add553a4ff72b11c11466999b8f030e8e033a65 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Sun, 1 Oct 2023 07:30:38 +0900 Subject: [PATCH 087/112] wayland: fix wrong scale factor logic in xdg_toplevel_listener (#390) This change fixes a wrong scale factor logic in configure callback of xdg_toplevel_listener when the scale value is not 1.0. Signed-off-by: Hidenori Matsubayashi --- .../window/elinux_window_wayland.cc | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc index 1f62cf31..eaa62469 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc @@ -123,24 +123,24 @@ const xdg_toplevel_listener ELinuxWindowWayland::kXdgToplevelListener = { std::swap(width, height); } - int32_t next_width = width; - int32_t next_height = height; + int32_t next_width_dip = width / self->current_scale_; + int32_t next_height_dip = height / self->current_scale_; if (self->restore_window_required_) { self->restore_window_required_ = false; - next_width = self->restore_window_width_; - next_height = self->restore_window_height_; + next_width_dip = self->restore_window_width_; + next_height_dip = self->restore_window_height_; } - if (!next_width || !next_height || - (self->view_properties_.width == next_width && - self->view_properties_.height == next_height)) { + if (!next_width_dip || !next_height_dip || + (self->view_properties_.width == next_width_dip && + self->view_properties_.height == next_height_dip)) { return; } - ELINUX_LOG(TRACE) - << "request redraw: " << next_width << ", " << next_height; - self->view_properties_.width = next_width; - self->view_properties_.height = next_height; + ELINUX_LOG(TRACE) << "request redraw: " << next_width_dip << ", " + << next_height_dip; + self->view_properties_.width = next_width_dip; + self->view_properties_.height = next_height_dip; self->request_redraw_ = true; }, .close = @@ -1274,6 +1274,11 @@ bool ELinuxWindowWayland::DispatchEvent() { window_decorations_->Resize(view_properties_.width, view_properties_.height, current_scale_); } + + ELINUX_LOG(ERROR) << "width: " << view_properties_.width; + ELINUX_LOG(ERROR) << "height: " << view_properties_.height; + ELINUX_LOG(ERROR) << "current_scale: " << current_scale_; + if (binding_handler_delegate_) { binding_handler_delegate_->OnWindowSizeChanged( view_properties_.width * current_scale_, @@ -1820,8 +1825,9 @@ void ELinuxWindowWayland::DismissVirtualKeybaord() { } void ELinuxWindowWayland::UpdateWindowScale() { - if (view_properties_.force_scale_factor) + if (view_properties_.force_scale_factor) { return; + } double scale_factor = 1.0; for (auto output_id : entered_outputs_) { From 5bee5a884549db2e624ac4bb746720f42ba75264 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Sun, 1 Oct 2023 07:41:32 +0900 Subject: [PATCH 088/112] egl: update commets for eglSwapInterval (#391) Signed-off-by: Hidenori Matsubayashi --- .../platform/linux_embedded/surface/elinux_egl_surface.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.cc b/src/flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.cc index 2efe002b..576fcf6e 100644 --- a/src/flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.cc +++ b/src/flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.cc @@ -75,8 +75,14 @@ bool ELinuxEGLSurface::MakeCurrent() const { } // Non-blocking when swappipping buffers on Wayland. + // OpenGL swap intervals can be used to prevent screen tearing. + // If enabled, the raster thread blocks until the v-blank. + // This is unnecessary if DWM composition is enabled. + // See: https://www.khronos.org/opengl/wiki/Swap_Interval + // See: https://learn.microsoft.com/windows/win32/dwm/composition-ovw + // // However, we might encounter rendering problems on some Wayland compositors - // (e.g. weston 9.0) when we use them. + // (e.g. weston 9.0). // See also: // - https://github.com/sony/flutter-embedded-linux/issues/230 // - https://github.com/sony/flutter-embedded-linux/issues/234 From 505468a7476665f4b2c06fa919d05a54c9e2f097 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Mon, 2 Oct 2023 12:33:18 +0900 Subject: [PATCH 089/112] engine: add text_scaling_factor option value check (#393) Fixed #392 Signed-off-by: Hidenori Matsubayashi --- .../shell/platform/linux_embedded/flutter_elinux_engine.cc | 5 +++++ .../platform/linux_embedded/window/elinux_window_wayland.cc | 4 ---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc index 2fbec1eb..9e49c9e4 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc @@ -381,6 +381,11 @@ void FlutterELinuxEngine::ReloadSystemFonts() { void FlutterELinuxEngine::SetSystemSettings(float text_scaling_factor, bool enable_high_contrast) { + if (text_scaling_factor == 0) { + ELINUX_LOG(WARNING) << "text-scaling-factor value must be greater than 0"; + text_scaling_factor = 1.0; + } + view_->UpdateTextScaleFactor(text_scaling_factor); view_->UpdateHighContrastEnabled(enable_high_contrast); SendSystemLocales(); diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc index eaa62469..12c682c9 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc @@ -1275,10 +1275,6 @@ bool ELinuxWindowWayland::DispatchEvent() { view_properties_.height, current_scale_); } - ELINUX_LOG(ERROR) << "width: " << view_properties_.width; - ELINUX_LOG(ERROR) << "height: " << view_properties_.height; - ELINUX_LOG(ERROR) << "current_scale: " << current_scale_; - if (binding_handler_delegate_) { binding_handler_delegate_->OnWindowSizeChanged( view_properties_.width * current_scale_, From d5fe4688c4cb758bfa1db8305b5c867b85e42e5c Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Mon, 30 Oct 2023 21:11:19 +0900 Subject: [PATCH 090/112] wayland: fix wrong xdg_surface buffer size issue (#397) This change fixes https://github.com/sony/flutter-embedded-linux/issues/396. Signed-off-by: Hidenori Matsubayashi --- .../linux_embedded/window/elinux_window_wayland.cc | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc index 12c682c9..f0e9e254 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc @@ -78,16 +78,16 @@ const xdg_surface_listener ELinuxWindowWayland::kXdgSurfaceListener = { ELINUX_LOG(TRACE) << "xdg_surface_listener.configure"; auto self = reinterpret_cast(data); + constexpr int32_t x = 0; + int32_t y = 0; + auto width = self->view_properties_.width; + auto height = self->view_properties_.height; + if (self->window_decorations_) { // Shift the window position to the bottom to show decoration // even when the window is displayed in the upper left corner // of the screen - constexpr int32_t x = 0; - int32_t y = 0; y = -self->window_decorations_->Height(); - - auto width = self->view_properties_.width; - auto height = self->view_properties_.height; if (!self->maximised_) { height -= y; } @@ -96,9 +96,8 @@ const xdg_surface_listener ELinuxWindowWayland::kXdgSurfaceListener = { if (self->display_max_height_ > 0) { height = std::min(height, self->display_max_height_); } - - xdg_surface_set_window_geometry(xdg_surface, x, y, width, height); } + xdg_surface_set_window_geometry(xdg_surface, x, y, width, height); xdg_surface_ack_configure(xdg_surface, serial); if (self->wait_for_configure_) { From 1902050004452cb90d8d3d92489c6324e3c6e327 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Sat, 4 Nov 2023 20:32:00 +0900 Subject: [PATCH 091/112] embedder: merge embedder.h from flutter/engine (#394) Merged from https://github.com/flutter/engine/commit/f358bde6ce0e54bd5eb5fc6e2910d291b7578548 Signed-off-by: Hidenori Matsubayashi --- .../shell/platform/embedder/embedder.h | 137 +++++++++++++++++- 1 file changed, 134 insertions(+), 3 deletions(-) diff --git a/src/flutter/shell/platform/embedder/embedder.h b/src/flutter/shell/platform/embedder/embedder.h index a1e9036b..cfef518d 100644 --- a/src/flutter/shell/platform/embedder/embedder.h +++ b/src/flutter/shell/platform/embedder/embedder.h @@ -25,9 +25,9 @@ // - Function signatures (names, argument counts, argument order, and argument // type) cannot change. // - The core behavior of existing functions cannot change. -// - Instead of nesting structures by value within another structure, prefer -// nesting by pointer. This ensures that adding members to the nested struct -// does not break the ABI of the parent struct. +// - Instead of nesting structures by value within another structure/union, +// prefer nesting by pointer. This ensures that adding members to the nested +// struct does not break the ABI of the parent struct/union. // - Instead of array of structures, prefer array of pointers to structures. // This ensures that array indexing does not break if members are added // to the structure. @@ -757,6 +757,11 @@ typedef struct { /// The queue family index of the VkQueue supplied in the next field. uint32_t queue_family_index; /// VkQueue handle. + /// The queue should not be used without protection from a mutex to make sure + /// it is not used simultaneously with other threads. That mutex should match + /// the one injected via the |get_instance_proc_address_callback|. + /// There is a proposal to remove the need for the mutex at + /// https://github.com/flutter/flutter/issues/134573. FlutterVulkanQueueHandle queue; /// The number of instance extensions available for enumerating in the next /// field. @@ -780,6 +785,12 @@ typedef struct { /// For example: VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME const char** enabled_device_extensions; /// The callback invoked when resolving Vulkan function pointers. + /// At a bare minimum this should be used to swap out any calls that operate + /// on vkQueue's for threadsafe variants that obtain locks for their duration. + /// The functions to swap out are "vkQueueSubmit" and "vkQueueWaitIdle". An + /// example of how to do that can be found in the test + /// "EmbedderTest.CanSwapOutVulkanCalls" unit-test in + /// //shell/platform/embedder/tests/embedder_vk_unittests.cc. FlutterVulkanInstanceProcAddressCallback get_instance_proc_address_callback; /// The callback invoked when the engine requests a VkImage from the embedder /// for rendering the next frame. @@ -1064,6 +1075,57 @@ typedef int64_t FlutterPlatformViewIdentifier; FLUTTER_EXPORT extern const int32_t kFlutterSemanticsNodeIdBatchEnd; +// The enumeration of possible string attributes that affect how assistive +// technologies announce a string. +// +// See dart:ui's implementers of the StringAttribute abstract class. +typedef enum { + // Indicates the string should be announced character by character. + kSpellOut, + // Indicates the string should be announced using the specified locale. + kLocale, +} FlutterStringAttributeType; + +// Indicates the assistive technology should announce out the string character +// by character. +// +// See dart:ui's SpellOutStringAttribute. +typedef struct { + /// The size of this struct. Must be sizeof(FlutterSpellOutStringAttribute). + size_t struct_size; +} FlutterSpellOutStringAttribute; + +// Indicates the assistive technology should announce the string using the +// specified locale. +// +// See dart:ui's LocaleStringAttribute. +typedef struct { + /// The size of this struct. Must be sizeof(FlutterLocaleStringAttribute). + size_t struct_size; + // The locale of this attribute. + const char* locale; +} FlutterLocaleStringAttribute; + +// Indicates how the assistive technology should treat the string. +// +// See dart:ui's StringAttribute. +typedef struct { + /// The size of this struct. Must be sizeof(FlutterStringAttribute). + size_t struct_size; + // The position this attribute starts. + size_t start; + // The next position after the attribute ends. + size_t end; + /// The type of the attribute described by the subsequent union. + FlutterStringAttributeType type; + union { + // Indicates the string should be announced character by character. + const FlutterSpellOutStringAttribute* spell_out; + // Indicates the string should be announced using the specified locale. + const FlutterLocaleStringAttribute* locale; + }; +} FlutterStringAttribute; + /// A node that represents some semantic data. /// /// The semantics tree is maintained during the semantics phase of the pipeline @@ -1215,6 +1277,31 @@ typedef struct { FlutterPlatformViewIdentifier platform_view_id; /// A textual tooltip attached to the node. const char* tooltip; + // The number of string attributes associated with the `label`. + size_t label_attribute_count; + // Array of string attributes associated with the `label`. + // Has length `label_attribute_count`. + const FlutterStringAttribute** label_attributes; + // The number of string attributes associated with the `hint`. + size_t hint_attribute_count; + // Array of string attributes associated with the `hint`. + // Has length `hint_attribute_count`. + const FlutterStringAttribute** hint_attributes; + // The number of string attributes associated with the `value`. + size_t value_attribute_count; + // Array of string attributes associated with the `value`. + // Has length `value_attribute_count`. + const FlutterStringAttribute** value_attributes; + // The number of string attributes associated with the `increased_value`. + size_t increased_value_attribute_count; + // Array of string attributes associated with the `increased_value`. + // Has length `increased_value_attribute_count`. + const FlutterStringAttribute** increased_value_attributes; + // The number of string attributes associated with the `decreased_value`. + size_t decreased_value_attribute_count; + // Array of string attributes associated with the `decreased_value`. + // Has length `decreased_value_attribute_count`. + const FlutterStringAttribute** decreased_value_attributes; } FlutterSemanticsNode2; /// `FlutterSemanticsCustomAction` ID used as a sentinel to signal the end of a @@ -1326,6 +1413,20 @@ typedef void (*FlutterUpdateSemanticsCallback2)( const FlutterSemanticsUpdate2* /* semantics update */, void* /* user data*/); +/// An update to whether a message channel has a listener set or not. +typedef struct { + // The size of the struct. Must be sizeof(FlutterChannelUpdate). + size_t struct_size; + /// The name of the channel. + const char* channel; + /// True if a listener has been set, false if one has been cleared. + bool listening; +} FlutterChannelUpdate; + +typedef void (*FlutterChannelUpdateCallback)( + const FlutterChannelUpdate* /* channel update */, + void* /* user data */); + typedef struct _FlutterTaskRunner* FlutterTaskRunner; typedef struct { @@ -1573,6 +1674,27 @@ typedef enum { kFlutterLayerContentTypePlatformView, } FlutterLayerContentType; +/// A region represented by a collection of non-overlapping rectangles. +typedef struct { + /// The size of this struct. Must be sizeof(FlutterRegion). + size_t struct_size; + /// Number of rectangles in the region. + size_t rects_count; + /// The rectangles that make up the region. + FlutterRect* rects; +} FlutterRegion; + +/// Contains additional information about the backing store provided +/// during presentation to the embedder. +typedef struct { + size_t struct_size; + + /// The area of the backing store that contains Flutter contents. Pixels + /// outside of this area are transparent and the embedder may choose not + /// to render them. Coordinates are in physical pixels. + FlutterRegion* paint_region; +} FlutterBackingStorePresentInfo; + typedef struct { /// This size of this struct. Must be sizeof(FlutterLayer). size_t struct_size; @@ -1592,6 +1714,10 @@ typedef struct { FlutterPoint offset; /// The size of the layer (in physical pixels). FlutterSize size; + + /// Extra information for the backing store that the embedder may + /// use during presentation. + FlutterBackingStorePresentInfo* backing_store_present_info; } FlutterLayer; typedef bool (*FlutterBackingStoreCreateCallback)( @@ -2118,6 +2244,11 @@ typedef struct { /// and `update_semantics_callback2` may be provided; the others must be set /// to null. FlutterUpdateSemanticsCallback2 update_semantics_callback2; + + /// The callback invoked by the engine in response to a channel listener + /// being registered on the framework side. The callback is invoked from + /// a task posted to the platform thread. + FlutterChannelUpdateCallback channel_update_callback; } FlutterProjectArgs; #ifndef FLUTTER_ENGINE_NO_PROTOTYPES From bd5e4b67aad84d42c42aa7222fde33274baa08bf Mon Sep 17 00:00:00 2001 From: Makoto Sato <51475851+makotosato-at@users.noreply.github.com> Date: Thu, 9 Nov 2023 18:35:25 +0900 Subject: [PATCH 092/112] egl_stream: add cast to EGLAttrib (#400) Signed-off-by: Makoto Sato --- .../shell/platform/linux_embedded/surface/context_egl_stream.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flutter/shell/platform/linux_embedded/surface/context_egl_stream.cc b/src/flutter/shell/platform/linux_embedded/surface/context_egl_stream.cc index 61d699f7..4a13f498 100644 --- a/src/flutter/shell/platform/linux_embedded/surface/context_egl_stream.cc +++ b/src/flutter/shell/platform/linux_embedded/surface/context_egl_stream.cc @@ -28,7 +28,7 @@ std::unique_ptr ContextEglStream::CreateOnscreenSurface( EGLOutputLayerEXT layer; EGLAttrib layer_attribs[] = { // clang-format off - EGL_DRM_PLANE_EXT, static_cast(window)->PlaneId(), + EGL_DRM_PLANE_EXT, static_cast(static_cast(window)->PlaneId()), EGL_NONE // clang-format on }; From 6b14cf0887fef389a2df23336947245e6d2ce10a Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Thu, 16 Nov 2023 19:35:02 +0900 Subject: [PATCH 093/112] Revert "WAR: temporarily disable partial repaints (#388)" (#401) This reverts commit 820ee198b3a888cbe9dd06a9fffb3930c7166fc0. --- .../platform/linux_embedded/surface/elinux_egl_surface.cc | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.cc b/src/flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.cc index 576fcf6e..914ab736 100644 --- a/src/flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.cc +++ b/src/flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.cc @@ -174,11 +174,6 @@ void ELinuxEGLSurface::PopulateExistingDamage(const intptr_t fbo_id, 0, 0, static_cast(width_px_), static_cast(height_px_)}; existing_damage->damage = existing_damage_map_[fbo_id]; - // Temporarily disabled partial repaints due to - // https://github.com/sony/flutter-embedded-linux/issues/334. Once - // https://github.com/flutter/engine/pull/45611 was merged and propagated to - // the stable channel, this will be lifted up. -#if 0 if (age > 1) { --age; // join up to (age - 1) last rects from damage history @@ -202,7 +197,6 @@ void ELinuxEGLSurface::PopulateExistingDamage(const intptr_t fbo_id, } } } -#endif } // Auxiliary function used to transform a FlutterRect into the format that is From c22c4ff9ebd7b79e7e8a951e9831fda2bbf8a281 Mon Sep 17 00:00:00 2001 From: Fredrik Magnussen Date: Tue, 28 Nov 2023 14:38:55 +0100 Subject: [PATCH 094/112] Fixes issue #403: Segmentation fault when updating destroyed mouse pointer (#404) * Fixes issue #403: Segmentation fault when updating destroyed mouse pointer. Signed-off-by: fredrmag --- .../platform/linux_embedded/window/elinux_window_wayland.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc index f0e9e254..067c1f87 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc @@ -1481,6 +1481,9 @@ void ELinuxWindowWayland::UpdateVirtualKeyboardStatus(const bool show) { void ELinuxWindowWayland::UpdateFlutterCursor(const std::string& cursor_name) { if (view_properties_.use_mouse_cursor) { + if (!wl_pointer_) { + return; + } if (cursor_name.compare(cursor_info_.cursor_name) == 0) { return; } From eec5bc9917e13c6ee78faa28c06a98c6ca38c7a9 Mon Sep 17 00:00:00 2001 From: Makoto Sato <51475851+makotosato-at@users.noreply.github.com> Date: Mon, 11 Dec 2023 15:55:37 +0900 Subject: [PATCH 095/112] wayland: fix wp_presentation_feedback leak (#405) Signed-off-by: Makoto Sato --- .../platform/linux_embedded/window/elinux_window_wayland.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc index 067c1f87..fa147f6e 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc @@ -233,6 +233,7 @@ const wp_presentation_feedback_listener self->window_decorations_->Draw(); } + wp_presentation_feedback_destroy(wp_presentation_feedback); wp_presentation_feedback_add_listener( ::wp_presentation_feedback(self->wp_presentation_, self->native_window_->Surface()), @@ -249,6 +250,7 @@ const wp_presentation_feedback_listener self->window_decorations_->Draw(); } + wp_presentation_feedback_destroy(wp_presentation_feedback); wp_presentation_feedback_add_listener( ::wp_presentation_feedback(self->wp_presentation_, self->native_window_->Surface()), From 28de1eb56d6afff0ae7bdc68787a0ae620ccc51d Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Wed, 13 Dec 2023 06:39:31 +0900 Subject: [PATCH 096/112] WAR: disable USE_DIRTY_REGION_MANAGEMENT option (#406) This change disables 'dirty-region-management' feature to prevent a fricker issue. See #334 for the details. Signed-off-by: Hidenori Matsubayashi --- CMakeLists.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 19abd447..0150694c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,10 +11,13 @@ project("flutter_elinux" LANGUAGES CXX C) # Build options. option(BACKEND_TYPE "Select WAYLAND, DRM-GBM, DRM-EGLSTREAM, or X11 as the display backend type" WAYLAND) -option(USE_DIRTY_REGION_MANAGEMENT "Use Flutter dirty region management" ON) +# Disabled USE_DIRTY_REGION_MANAGEMENT due flicker issue. +# See https://github.com/sony/flutter-embedded-linux/issues/334 +option(USE_DIRTY_REGION_MANAGEMENT "Use Flutter dirty region management" OFF) option(USE_GLES3 "Use OpenGL ES3 (default is OpenGL ES2)" OFF) option(ENABLE_EGL_ALPHA_COMPONENT_OF_COLOR_BUFFER "Enable alpha component of the EGL color buffer" ON) -option(ENABLE_VSYNC "Enable embedder vsync" OFF) # todo: need to investigate https://github.com/sony/flutter-embedded-linux/pull/376 when enabling this option. + # todo: need to investigate https://github.com/sony/flutter-embedded-linux/pull/376 when enabling this option. +option(ENABLE_VSYNC "Enable embedder vsync" OFF) option(BUILD_ELINUX_SO "Build .so file of elinux embedder" OFF) option(ENABLE_ELINUX_EMBEDDER_LOG "Enable logger of eLinux embedder" ON) option(FLUTTER_RELEASE "Build Flutter Engine with release mode" OFF) From 185d73a596b7be5793f0febc0967f0e576cb8ce7 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Fri, 16 Feb 2024 20:05:56 +0900 Subject: [PATCH 097/112] embedder: merge embedder.h from flutter/engine (#408) Merged from https://github.com/flutter/engine/commits/3.19.0/shell/platform/embedder/embedder.h Signed-off-by: Hidenori Matsubayashi --- src/flutter/common/constants.h | 38 +++++++++++++++++++ .../shell/platform/embedder/embedder.h | 28 ++++++++++++-- .../embedder/embedder_struct_macros.h | 6 +-- .../linux_embedded/flutter_elinux_view.cc | 13 +++++++ 4 files changed, 79 insertions(+), 6 deletions(-) create mode 100644 src/flutter/common/constants.h diff --git a/src/flutter/common/constants.h b/src/flutter/common/constants.h new file mode 100644 index 00000000..668aa4f6 --- /dev/null +++ b/src/flutter/common/constants.h @@ -0,0 +1,38 @@ +// 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. + +#ifndef FLUTTER_COMMON_CONSTANTS_H_ +#define FLUTTER_COMMON_CONSTANTS_H_ + +namespace flutter { +constexpr double kMegaByteSizeInBytes = (1 << 20); + +// The ID for the implicit view if the implicit view is enabled. +// +// The implicit view is a compatibility mechanism to help the transition from +// the older single-view APIs to the newer multi-view APIs. The two sets of APIs +// use different models for view management. The implicit view mechanism allows +// single-view APIs to operate a special view as if other views don't exist. +// +// In the regular multi-view model, all views should be created by +// `Shell::AddView` before being used, and removed by `Shell::RemoveView` to +// signify that they are gone. If a view is added or removed, the framework +// (`PlatformDispatcher`) will be notified. New view IDs are always unique, +// never reused. Operating a non-existing view is an error. +// +// The implicit view is another special view in addition to the "regular views" +// as above. The shell starts up having the implicit view, which has a fixed +// view ID of `kFlutterImplicitViewId` and is available throughout the lifetime +// of the shell. `Shell::AddView` or `RemoveView` must not be called for this +// view. Even when the window that shows the view is closed, the framework is +// unaware and might continue rendering into or operating this view. +// +// The single-view APIs, which are APIs that do not specify view IDs, operate +// the implicit view. The multi-view APIs can operate all views, including the +// implicit view if the target ID is `kFlutterImplicitViewId`, unless specified +// otherwise. +constexpr int64_t kFlutterImplicitViewId = 0; +} // namespace flutter + +#endif // FLUTTER_COMMON_CONSTANTS_H_ diff --git a/src/flutter/shell/platform/embedder/embedder.h b/src/flutter/shell/platform/embedder/embedder.h index cfef518d..d8adf5e7 100644 --- a/src/flutter/shell/platform/embedder/embedder.h +++ b/src/flutter/shell/platform/embedder/embedder.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef FLUTTER_EMBEDDER_H_ -#define FLUTTER_EMBEDDER_H_ +#ifndef FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_H_ +#define FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_H_ #include #include @@ -266,6 +266,12 @@ typedef enum { typedef struct _FlutterEngine* FLUTTER_API_SYMBOL(FlutterEngine); +/// Unique identifier for views. +/// +/// View IDs are generated by the embedder and are +/// opaque to the engine; the engine does not interpret view IDs in any way. +typedef int64_t FlutterViewId; + typedef struct { /// horizontal scale factor double scaleX; @@ -961,6 +967,8 @@ typedef struct { double scale; /// The rotation of the pan/zoom in radians, where 0.0 is the initial angle. double rotation; + /// The identifier of the view that received the pointer event. + FlutterViewId view_id; } FlutterPointerEvent; typedef enum { @@ -969,6 +977,14 @@ typedef enum { kFlutterKeyEventTypeRepeat, } FlutterKeyEventType; +typedef enum { + kFlutterKeyEventDeviceTypeKeyboard = 1, + kFlutterKeyEventDeviceTypeDirectionalPad, + kFlutterKeyEventDeviceTypeGamepad, + kFlutterKeyEventDeviceTypeJoystick, + kFlutterKeyEventDeviceTypeHdmi, +} FlutterKeyEventDeviceType; + /// A structure to represent a key event. /// /// Sending `FlutterKeyEvent` via `FlutterEngineSendKeyEvent` results in a @@ -1032,6 +1048,8 @@ typedef struct { /// An event being synthesized means that the `timestamp` might greatly /// deviate from the actual time when the event occurs physically. bool synthesized; + /// The source device for the key event. + FlutterKeyEventDeviceType device_type; } FlutterKeyEvent; typedef void (*FlutterKeyEventCallback)(bool /* handled */, @@ -2253,6 +2271,8 @@ typedef struct { #ifndef FLUTTER_ENGINE_NO_PROTOTYPES +// NOLINTBEGIN(google-objc-function-naming) + //------------------------------------------------------------------------------ /// @brief Creates the necessary data structures to launch a Flutter Dart /// application in AOT mode. The data may only be collected after @@ -3124,8 +3144,10 @@ FLUTTER_EXPORT FlutterEngineResult FlutterEngineGetProcAddresses( FlutterEngineProcTable* table); +// NOLINTEND(google-objc-function-naming) + #if defined(__cplusplus) } // extern "C" #endif -#endif // FLUTTER_EMBEDDER_H_ +#endif // FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_H_ diff --git a/src/flutter/shell/platform/embedder/embedder_struct_macros.h b/src/flutter/shell/platform/embedder/embedder_struct_macros.h index 8bd30979..483fd2ab 100644 --- a/src/flutter/shell/platform/embedder/embedder_struct_macros.h +++ b/src/flutter/shell/platform/embedder/embedder_struct_macros.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_SAFE_ACCESS_H_ -#define FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_SAFE_ACCESS_H_ +#ifndef FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_STRUCT_MACROS_H_ +#define FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_STRUCT_MACROS_H_ #include @@ -29,4 +29,4 @@ #define SAFE_EXISTS_ONE_OF(pointer, member1, member2) \ (SAFE_EXISTS(pointer, member1) != SAFE_EXISTS(pointer, member2)) -#endif // FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_SAFE_ACCESS_H_ +#endif // FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_STRUCT_MACROS_H_ diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc index 68d0bac4..9775d200 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc @@ -7,6 +7,7 @@ #include #include +#include "flutter/common/constants.h" #include "flutter/shell/platform/linux_embedded/logger.h" namespace flutter { @@ -165,6 +166,9 @@ void FlutterELinuxView::OnTouchDown(uint32_t time, .scroll_delta_y = 0, .device_kind = kFlutterPointerDeviceKindTouch, .buttons = 0, + // TODO: Use the correct view ID for pointer events once the + // eLinux embedder supports multiple views. + .view_id = flutter::kFlutterImplicitViewId, }; engine_->SendPointerEvent(event); } @@ -203,6 +207,9 @@ void FlutterELinuxView::OnTouchUp(uint32_t time, int32_t id) { .scroll_delta_y = 0, .device_kind = kFlutterPointerDeviceKindTouch, .buttons = 0, + // TODO: Use the correct view ID for pointer events once the + // eLinux embedder supports multiple views. + .view_id = flutter::kFlutterImplicitViewId, }; engine_->SendPointerEvent(event); } @@ -247,6 +254,9 @@ void FlutterELinuxView::OnTouchMotion(uint32_t time, .scroll_delta_y = 0, .device_kind = kFlutterPointerDeviceKindTouch, .buttons = 0, + // TODO: Use the correct view ID for pointer events once the + // eLinux embedder supports multiple views. + .view_id = flutter::kFlutterImplicitViewId, }; engine_->SendPointerEvent(event); } @@ -424,6 +434,9 @@ void FlutterELinuxView::SendPointerEventWithData( FlutterPointerEvent event = event_data; event.device_kind = kFlutterPointerDeviceKindMouse; event.buttons = mouse_state_.buttons; + // TODO: Use the correct view ID for pointer events once the + // eLinux embedder supports multiple views. + event.view_id = flutter::kFlutterImplicitViewId; // Set metadata that's always the same regardless of the event. event.struct_size = sizeof(event); From a73994f40470adafec1c24570926ff18079c0f26 Mon Sep 17 00:00:00 2001 From: Makoto Sato <51475851+makotosato-at@users.noreply.github.com> Date: Thu, 28 Mar 2024 16:39:49 +0900 Subject: [PATCH 098/112] wayland: fix screen rotation issue on Wayland (#411) Signed-off-by: Makoto Sato --- .../linux_embedded/window/elinux_window_wayland.cc | 8 +++++++- .../linux_embedded/window/elinux_window_wayland.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc index fa147f6e..78220b1d 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc @@ -628,6 +628,8 @@ const wl_output_listener ELinuxWindowWayland::kWlOutputListener = { const char* model, int32_t output_transform) -> void { ELINUX_LOG(TRACE) << "wl_output_listener.geometry"; + auto self = reinterpret_cast(data); + self->transform_ = output_transform; }, .mode = [](void* data, wl_output* wl_output, @@ -639,7 +641,11 @@ const wl_output_listener ELinuxWindowWayland::kWlOutputListener = { auto self = reinterpret_cast(data); if (flags & WL_OUTPUT_MODE_CURRENT) { - if (self->current_rotation_ == 90 || self->current_rotation_ == 270) { + if (self->current_rotation_ == 90 || self->current_rotation_ == 270 || + self->transform_ == WL_OUTPUT_TRANSFORM_90 || + self->transform_ == WL_OUTPUT_TRANSFORM_270 || + self->transform_ == WL_OUTPUT_TRANSFORM_FLIPPED_90 || + self->transform_ == WL_OUTPUT_TRANSFORM_FLIPPED_270) { std::swap(width, height); } diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h index 2d1343d5..dcfe1bb4 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h @@ -153,6 +153,7 @@ class ELinuxWindowWayland : public ELinuxWindow, public WindowBindingHandler { bool maximised_; uint32_t last_frame_time_; bool enable_impeller_ = false; + int32_t transform_ = WL_OUTPUT_TRANSFORM_NORMAL; // Indicates that exists a keyboard show request from Flutter Engine. bool is_requested_show_virtual_keyboard_; From f296db8ed6c75cf5b0bb5c1bc1414038f43a1ef3 Mon Sep 17 00:00:00 2001 From: Sebastian Urban Date: Wed, 8 May 2024 23:09:02 +0200 Subject: [PATCH 099/112] wayland: text input protocol uses UTF-8 encoding (#415) * wayland: text input protocol uses UTF-8 encoding The Wayland text input protocol sends text in UTF-8 encoding, but the Flutter TextInputModel expects UTF-16. This adds the missing conversion from UTF-8 to UTF-16. Signed-off-by: Sebastian Urban * Add Sebastian Urban to AUTHORS --------- Signed-off-by: Sebastian Urban --- AUTHORS | 1 + .../window/elinux_window_wayland.cc | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/AUTHORS b/AUTHORS index d82960b5..98613147 100644 --- a/AUTHORS +++ b/AUTHORS @@ -13,3 +13,4 @@ Makoto Sato (makoto.sato@atmark-techno.com) Yunhao Tian (t123yh@outlook.com) Luke Howard Stanislav Shmarov +Sebastian Urban diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc index 78220b1d..debed756 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include #include "flutter/shell/platform/linux_embedded/logger.h" @@ -748,7 +750,10 @@ const zwp_text_input_v1_listener ELinuxWindowWayland::kZwpTextInputV1Listener = auto self = reinterpret_cast(data); if (self->binding_handler_delegate_ && strlen(text)) { - self->binding_handler_delegate_->OnVirtualKey(text[0]); + std::wstring_convert, char16_t> + utf8_converter; + std::u16string utf16_text = utf8_converter.from_bytes(text); + self->binding_handler_delegate_->OnVirtualKey(utf16_text[0]); } if (self->zwp_text_input_v1_) { zwp_text_input_v1_reset(self->zwp_text_input_v1_); @@ -779,7 +784,10 @@ const zwp_text_input_v1_listener ELinuxWindowWayland::kZwpTextInputV1Listener = // commit_string is notified only when the space key is pressed. auto self = reinterpret_cast(data); if (self->binding_handler_delegate_ && strlen(text)) { - self->binding_handler_delegate_->OnVirtualKey(text[0]); + std::wstring_convert, char16_t> + utf8_converter; + std::u16string utf16_text = utf8_converter.from_bytes(text); + self->binding_handler_delegate_->OnVirtualKey(utf16_text[0]); } // If there is no input data, the backspace key cannot be used, // so set dummy data. @@ -895,7 +903,10 @@ const zwp_text_input_v3_listener ELinuxWindowWayland::kZwpTextInputV3Listener = auto self = reinterpret_cast(data); if (self->binding_handler_delegate_ && strlen(text)) { - self->binding_handler_delegate_->OnVirtualKey(text[0]); + std::wstring_convert, char16_t> + utf8_converter; + std::u16string utf16_text = utf8_converter.from_bytes(text); + self->binding_handler_delegate_->OnVirtualKey(utf16_text[0]); } }, .delete_surrounding_text = [](void* data, From 97438621dbd6b5899859c052ad2ef55843373de4 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Sat, 18 May 2024 06:15:47 +0900 Subject: [PATCH 100/112] embedder: merge embedder.h from flutter/engine (#416) Merged from https://github.com/flutter/engine/commits/3.22.0/shell/platform/embedder/embedder.h Signed-off-by: Hidenori Matsubayashi --- .../shell/platform/embedder/embedder.h | 116 +++++++++++++++++- 1 file changed, 113 insertions(+), 3 deletions(-) diff --git a/src/flutter/shell/platform/embedder/embedder.h b/src/flutter/shell/platform/embedder/embedder.h index d8adf5e7..d26e2215 100644 --- a/src/flutter/shell/platform/embedder/embedder.h +++ b/src/flutter/shell/platform/embedder/embedder.h @@ -831,6 +831,53 @@ typedef struct { }; } FlutterRendererConfig; +typedef struct { + /// The size of this struct. + /// Must be sizeof(FlutterRemoveViewResult). + size_t struct_size; + + /// True if the remove view operation succeeded. + bool removed; + + /// The |FlutterRemoveViewInfo.user_data|. + void* user_data; +} FlutterRemoveViewResult; + +/// The callback invoked by the engine when the engine has attempted to remove +/// a view. +/// +/// The |FlutterRemoveViewResult| will be deallocated once the callback returns. +typedef void (*FlutterRemoveViewCallback)( + const FlutterRemoveViewResult* /* result */); + +typedef struct { + /// The size of this struct. + /// Must be sizeof(FlutterRemoveViewInfo). + size_t struct_size; + + /// The identifier for the view to remove. + /// + /// The implicit view cannot be removed if it is enabled. + FlutterViewId view_id; + + /// A baton that is not interpreted by the engine in any way. + /// It will be given back to the embedder in |remove_view_callback|. + /// Embedder resources may be associated with this baton. + void* user_data; + + /// Called once the engine has attempted to remove the view. + /// This callback is required. + /// + /// The embedder must not destroy the underlying surface until the callback is + /// invoked with a `removed` value of `true`. + /// + /// This callback is invoked on an internal engine managed thread. + /// Embedders must re-thread if necessary. + /// + /// The |result| argument will be deallocated when the callback returns. + FlutterRemoveViewCallback remove_view_callback; +} FlutterRemoveViewInfo; + /// Display refers to a graphics hardware system consisting of a framebuffer, /// typically a monitor or a screen. This ID is unique per display and is /// stable until the Flutter application restarts. @@ -859,6 +906,8 @@ typedef struct { double physical_view_inset_left; /// The identifier of the display the view is rendering on. FlutterEngineDisplayId display_id; + /// The view that this event is describing. + int64_t view_id; } FlutterWindowMetricsEvent; /// The phase of the pointer event. @@ -1736,8 +1785,30 @@ typedef struct { /// Extra information for the backing store that the embedder may /// use during presentation. FlutterBackingStorePresentInfo* backing_store_present_info; + + // Time in nanoseconds at which this frame is scheduled to be presented. 0 if + // not known. See FlutterEngineGetCurrentTime(). + uint64_t presentation_time; } FlutterLayer; +typedef struct { + /// The size of this struct. + /// Must be sizeof(FlutterPresentViewInfo). + size_t struct_size; + + /// The identifier of the target view. + FlutterViewId view_id; + + /// The layers that should be composited onto the view. + const FlutterLayer** layers; + + /// The count of layers. + size_t layers_count; + + /// The |FlutterCompositor.user_data|. + void* user_data; +} FlutterPresentViewInfo; + typedef bool (*FlutterBackingStoreCreateCallback)( const FlutterBackingStoreConfig* config, FlutterBackingStore* backing_store_out, @@ -1751,13 +1822,20 @@ typedef bool (*FlutterLayersPresentCallback)(const FlutterLayer** layers, size_t layers_count, void* user_data); +/// The callback invoked when the embedder should present to a view. +/// +/// The |FlutterPresentViewInfo| will be deallocated once the callback returns. +typedef bool (*FlutterPresentViewCallback)( + const FlutterPresentViewInfo* /* present info */); + typedef struct { /// This size of this struct. Must be sizeof(FlutterCompositor). size_t struct_size; /// A baton that in not interpreted by the engine in any way. If it passed /// back to the embedder in `FlutterCompositor.create_backing_store_callback`, - /// `FlutterCompositor.collect_backing_store_callback` and - /// `FlutterCompositor.present_layers_callback` + /// `FlutterCompositor.collect_backing_store_callback`, + /// `FlutterCompositor.present_layers_callback`, and + /// `FlutterCompositor.present_view_callback`. void* user_data; /// A callback invoked by the engine to obtain a backing store for a specific /// `FlutterLayer`. @@ -1771,10 +1849,23 @@ typedef struct { /// embedder may collect any resources associated with the backing store. FlutterBackingStoreCollectCallback collect_backing_store_callback; /// Callback invoked by the engine to composite the contents of each layer - /// onto the screen. + /// onto the implicit view. + /// + /// DEPRECATED: Use |present_view_callback| to support multiple views. + /// + /// Only one of `present_layers_callback` and `present_view_callback` may be + /// provided. Providing both is an error and engine initialization will + /// terminate. FlutterLayersPresentCallback present_layers_callback; /// Avoid caching backing stores provided by this compositor. bool avoid_backing_store_cache; + /// Callback invoked by the engine to composite the contents of each layer + /// onto the specified view. + /// + /// Only one of `present_layers_callback` and `present_view_callback` may be + /// provided. Providing both is an error and engine initialization will + /// terminate. + FlutterPresentViewCallback present_view_callback; } FlutterCompositor; typedef struct { @@ -2414,6 +2505,25 @@ FLUTTER_EXPORT FlutterEngineResult FlutterEngineRunInitialized( FLUTTER_API_SYMBOL(FlutterEngine) engine); +//------------------------------------------------------------------------------ +/// @brief Removes a view. +/// +/// This is an asynchronous operation. The view's resources must not +/// be cleaned up until the |remove_view_callback| is invoked with +/// a |removed| value of `true`. +/// +/// @param[in] engine A running engine instance. +/// @param[in] info The remove view arguments. This can be deallocated +/// once |FlutterEngineRemoveView| returns, before +/// |remove_view_callback| is invoked. +/// +/// @return The result of *starting* the asynchronous operation. If +/// `kSuccess`, the |remove_view_callback| will be invoked. +FLUTTER_EXPORT +FlutterEngineResult FlutterEngineRemoveView(FLUTTER_API_SYMBOL(FlutterEngine) + engine, + const FlutterRemoveViewInfo* info); + FLUTTER_EXPORT FlutterEngineResult FlutterEngineSendWindowMetricsEvent( FLUTTER_API_SYMBOL(FlutterEngine) engine, From 434d509ffefdd1b2ab023ef1ccad7bb4048bd990 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93mar=20H=C3=B6gni=20Gu=C3=B0marsson?= Date: Thu, 23 May 2024 23:58:38 +0000 Subject: [PATCH 101/112] Multiple seats (#417) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added the ability to have multiple seats, this allows f.e. weston screenshare and a local touch input to work at the same time. Signed-off-by: Ómar Högni Guðmarsson --- AUTHORS | 1 + .../window/elinux_window_wayland.cc | 171 ++++++++++-------- .../window/elinux_window_wayland.h | 12 +- 3 files changed, 107 insertions(+), 77 deletions(-) diff --git a/AUTHORS b/AUTHORS index 98613147..151ed913 100644 --- a/AUTHORS +++ b/AUTHORS @@ -14,3 +14,4 @@ Yunhao Tian (t123yh@outlook.com) Luke Howard Stanislav Shmarov Sebastian Urban +Ómar Högni Guðmarsson diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc index debed756..33848c83 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc @@ -289,29 +289,32 @@ const wl_seat_listener ELinuxWindowWayland::kWlSeatListener = { ELINUX_LOG(TRACE) << "wl_seat_listener.capabilities"; auto self = reinterpret_cast(data); - if ((caps & WL_SEAT_CAPABILITY_POINTER) && !self->wl_pointer_) { - self->wl_pointer_ = wl_seat_get_pointer(seat); - wl_pointer_add_listener(self->wl_pointer_, &kWlPointerListener, self); - } else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && self->wl_pointer_) { - wl_pointer_destroy(self->wl_pointer_); - self->wl_pointer_ = nullptr; + auto [iter_inputs, _] = + self->seat_inputs_map_.emplace(seat, seat_inputs()); + auto& inputs = iter_inputs->second; + + if ((caps & WL_SEAT_CAPABILITY_POINTER) && !inputs.pointer) { + inputs.pointer = wl_seat_get_pointer(seat); + wl_pointer_add_listener(inputs.pointer, &kWlPointerListener, self); + } else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && inputs.pointer) { + wl_pointer_destroy(inputs.pointer); + inputs.pointer = nullptr; } - if ((caps & WL_SEAT_CAPABILITY_TOUCH) && !self->wl_touch_) { - self->wl_touch_ = wl_seat_get_touch(seat); - wl_touch_add_listener(self->wl_touch_, &kWlTouchListener, self); - } else if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && self->wl_touch_) { - wl_touch_destroy(self->wl_touch_); - self->wl_touch_ = nullptr; + if ((caps & WL_SEAT_CAPABILITY_TOUCH) && !inputs.touch) { + inputs.touch = wl_seat_get_touch(seat); + wl_touch_add_listener(inputs.touch, &kWlTouchListener, self); + } else if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && inputs.touch) { + wl_touch_destroy(inputs.touch); + inputs.touch = nullptr; } - if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !self->wl_keyboard_) { - self->wl_keyboard_ = wl_seat_get_keyboard(seat); - wl_keyboard_add_listener(self->wl_keyboard_, &kWlKeyboardListener, - self); - } else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && self->wl_keyboard_) { - wl_keyboard_destroy(self->wl_keyboard_); - self->wl_keyboard_ = nullptr; + if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !inputs.keyboard) { + inputs.keyboard = wl_seat_get_keyboard(seat); + wl_keyboard_add_listener(inputs.keyboard, &kWlKeyboardListener, self); + } else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && inputs.keyboard) { + wl_keyboard_destroy(inputs.keyboard); + inputs.keyboard = nullptr; } }, .name = [](void* data, struct wl_seat* wl_seat, const char* name) -> void { @@ -333,7 +336,7 @@ const wl_pointer_listener ELinuxWindowWayland::kWlPointerListener = { self->serial_ = serial; if (self->view_properties_.use_mouse_cursor) { - self->cursor_info_.pointer = self->wl_pointer_; + self->cursor_info_.pointer = wl_pointer; self->cursor_info_.serial = serial; } @@ -399,7 +402,14 @@ const wl_pointer_listener ELinuxWindowWayland::kWlPointerListener = { self->window_decorations_->IsMatched( self->wl_current_surface_, WindowDecoration::DecorationType::TITLE_BAR)) { - xdg_toplevel_move(self->xdg_toplevel_, self->wl_seat_, serial); + for (auto& [seat, inputs] : self->seat_inputs_map_) { + if (inputs.pointer == pointer) { + xdg_toplevel_move(self->xdg_toplevel_, seat, serial); + return; + } + } + ELINUX_LOG(TRACE) + << "Failed to find the pointer for moving the window"; return; } @@ -1043,11 +1053,8 @@ ELinuxWindowWayland::ELinuxWindowWayland( wl_compositor_(nullptr), wl_subcompositor_(nullptr), wl_current_surface_(nullptr), - wl_seat_(nullptr), - wl_pointer_(nullptr), - wl_touch_(nullptr), - wl_keyboard_(nullptr), wl_shm_(nullptr), + seat_inputs_map_(), wl_data_device_manager_(nullptr), wl_data_device_(nullptr), wl_data_offer_(nullptr), @@ -1087,34 +1094,37 @@ ELinuxWindowWayland::ELinuxWindowWayland( wl_registry_add_listener(wl_registry_, &kWlRegistryListener, this); wl_display_roundtrip(wl_display_); - if (wl_data_device_manager_ && wl_seat_) { - wl_data_device_ = wl_data_device_manager_get_data_device( - wl_data_device_manager_, wl_seat_); - wl_data_device_add_listener(wl_data_device_, &kWlDataDeviceListener, this); - } + for (auto& [seat, _] : seat_inputs_map_) { + if (wl_data_device_manager_ && seat) { + wl_data_device_ = + wl_data_device_manager_get_data_device(wl_data_device_manager_, seat); + wl_data_device_add_listener(wl_data_device_, &kWlDataDeviceListener, + this); + } - // Setup text-input protocol for onscreen keyboard inputs. - { - if (zwp_text_input_manager_v3_ && wl_seat_) { - zwp_text_input_v3_ = zwp_text_input_manager_v3_get_text_input( - zwp_text_input_manager_v3_, wl_seat_); - if (!zwp_text_input_v3_) { - ELINUX_LOG(ERROR) << "Failed to create the text input manager v3."; - return; - } - zwp_text_input_v3_add_listener(zwp_text_input_v3_, - &kZwpTextInputV3Listener, this); - } else if (zwp_text_input_manager_v1_) { - zwp_text_input_v1_ = zwp_text_input_manager_v1_create_text_input( - zwp_text_input_manager_v1_); - if (!zwp_text_input_v1_) { - ELINUX_LOG(ERROR) << "Failed to create text input manager v1."; - return; + // Setup text-input protocol for onscreen keyboard inputs. + { + if (zwp_text_input_manager_v3_ && seat) { + zwp_text_input_v3_ = zwp_text_input_manager_v3_get_text_input( + zwp_text_input_manager_v3_, seat); + if (!zwp_text_input_v3_) { + ELINUX_LOG(ERROR) << "Failed to create the text input manager v3."; + return; + } + zwp_text_input_v3_add_listener(zwp_text_input_v3_, + &kZwpTextInputV3Listener, this); + } else if (zwp_text_input_manager_v1_) { + zwp_text_input_v1_ = zwp_text_input_manager_v1_create_text_input( + zwp_text_input_manager_v1_); + if (!zwp_text_input_v1_) { + ELINUX_LOG(ERROR) << "Failed to create text input manager v1."; + return; + } + zwp_text_input_v1_add_listener(zwp_text_input_v1_, + &kZwpTextInputV1Listener, this); + } else { + // do nothing. } - zwp_text_input_v1_add_listener(zwp_text_input_v1_, - &kZwpTextInputV1Listener, this); - } else { - // do nothing. } } @@ -1190,26 +1200,29 @@ ELinuxWindowWayland::~ELinuxWindowWayland() { wl_data_device_manager_ = nullptr; } - if (wl_pointer_) { - wl_pointer_destroy(wl_pointer_); - wl_pointer_ = nullptr; - } + for (auto& [seat, inputs] : seat_inputs_map_) { + if (inputs.pointer) { + wl_pointer_destroy(inputs.pointer); + inputs.pointer = nullptr; + } - if (wl_touch_) { - wl_touch_destroy(wl_touch_); - wl_touch_ = nullptr; - } + if (inputs.touch) { + wl_touch_destroy(inputs.touch); + inputs.touch = nullptr; + } - if (wl_keyboard_) { - wl_keyboard_destroy(wl_keyboard_); - wl_keyboard_ = nullptr; - } + if (inputs.keyboard) { + wl_keyboard_destroy(inputs.keyboard); + inputs.keyboard = nullptr; + } - if (wl_seat_) { - wl_seat_destroy(wl_seat_); - wl_seat_ = nullptr; + if (seat) { + wl_seat_destroy(seat); + } } + seat_inputs_map_.clear(); + if (wl_output_) { wl_output_destroy(wl_output_); wl_output_ = nullptr; @@ -1486,7 +1499,7 @@ void ELinuxWindowWayland::DestroyRenderSurface() { void ELinuxWindowWayland::UpdateVirtualKeyboardStatus(const bool show) { // Not supported virtual keyboard. - if (!(zwp_text_input_v1_ || zwp_text_input_v3_) || !wl_seat_) { + if (!(zwp_text_input_v1_ || zwp_text_input_v3_) || seat_inputs_map_.empty()) { return; } @@ -1500,7 +1513,14 @@ void ELinuxWindowWayland::UpdateVirtualKeyboardStatus(const bool show) { void ELinuxWindowWayland::UpdateFlutterCursor(const std::string& cursor_name) { if (view_properties_.use_mouse_cursor) { - if (!wl_pointer_) { + wl_pointer* pointer = nullptr; + for (auto& [_, inputs] : seat_inputs_map_) { + if (inputs.pointer != nullptr) { + pointer = inputs.pointer; + break; + } + } + if (!pointer) { return; } if (cursor_name.compare(cursor_info_.cursor_name) == 0) { @@ -1619,9 +1639,12 @@ void ELinuxWindowWayland::WlRegistryHandler(wl_registry* wl_registry, if (!strcmp(interface, wl_seat_interface.name)) { constexpr uint32_t kMaxVersion = 4; - wl_seat_ = static_cast(wl_registry_bind( - wl_registry, name, &wl_seat_interface, std::min(kMaxVersion, version))); - wl_seat_add_listener(wl_seat_, &kWlSeatListener, this); + auto [inserted, _] = + seat_inputs_map_.emplace(static_cast(wl_registry_bind( + wl_registry, name, &wl_seat_interface, + std::min(kMaxVersion, version))), + seat_inputs()); + wl_seat_add_listener(inserted->first, &kWlSeatListener, this); return; } @@ -1826,7 +1849,8 @@ void ELinuxWindowWayland::ShowVirtualKeyboard() { } else { if (native_window_) { zwp_text_input_v1_show_input_panel(zwp_text_input_v1_); - zwp_text_input_v1_activate(zwp_text_input_v1_, wl_seat_, + zwp_text_input_v1_activate(zwp_text_input_v1_, + seat_inputs_map_.begin()->first, native_window_->Surface()); } } @@ -1837,7 +1861,8 @@ void ELinuxWindowWayland::DismissVirtualKeybaord() { zwp_text_input_v3_disable(zwp_text_input_v3_); zwp_text_input_v3_commit(zwp_text_input_v3_); } else { - zwp_text_input_v1_deactivate(zwp_text_input_v1_, wl_seat_); + zwp_text_input_v1_deactivate(zwp_text_input_v1_, + seat_inputs_map_.begin()->first); } } diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h index dcfe1bb4..a4e454c4 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h @@ -34,6 +34,13 @@ namespace { constexpr char kXcursorSizeEnvironmentKey[] = "XCURSOR_SIZE"; } // namespace +// Track input devices for each seat +struct seat_inputs { + wl_pointer* pointer = nullptr; + wl_touch* touch = nullptr; + wl_keyboard* keyboard = nullptr; +}; + class ELinuxWindowWayland : public ELinuxWindow, public WindowBindingHandler { public: ELinuxWindowWayland(FlutterDesktopViewProperties view_properties); @@ -161,12 +168,9 @@ class ELinuxWindowWayland : public ELinuxWindow, public WindowBindingHandler { wl_display* wl_display_; wl_registry* wl_registry_; wl_compositor* wl_compositor_; - wl_seat* wl_seat_; wl_output* wl_output_; wl_shm* wl_shm_; - wl_pointer* wl_pointer_; - wl_touch* wl_touch_; - wl_keyboard* wl_keyboard_; + std::unordered_map seat_inputs_map_; wl_surface* wl_cursor_surface_; xdg_wm_base* xdg_wm_base_; xdg_surface* xdg_surface_; From d73e35a3be61fd20ab82e5ecd3e8bb69fd864196 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93mar=20H=C3=B6gni=20Gu=C3=B0marsson?= Date: Tue, 28 May 2024 14:11:13 +0000 Subject: [PATCH 102/112] wayland: Fix pointer not being drawn on second VNC connect. (#418) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use global_remove event to clean-up seat map. Signed-off-by: Ómar Högni Guðmarsson --- .../window/elinux_window_wayland.cc | 61 +++++++++++++------ .../window/elinux_window_wayland.h | 1 + 2 files changed, 45 insertions(+), 17 deletions(-) diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc index 33848c83..5bd8e0c2 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc @@ -289,15 +289,18 @@ const wl_seat_listener ELinuxWindowWayland::kWlSeatListener = { ELINUX_LOG(TRACE) << "wl_seat_listener.capabilities"; auto self = reinterpret_cast(data); - auto [iter_inputs, _] = - self->seat_inputs_map_.emplace(seat, seat_inputs()); - auto& inputs = iter_inputs->second; + auto seat_iter = self->seat_inputs_map_.find(seat); + if (seat_iter == self->seat_inputs_map_.end()) { + ELINUX_LOG(ERROR) << "Failed to find the seat"; + return; + } + auto& inputs = seat_iter->second; if ((caps & WL_SEAT_CAPABILITY_POINTER) && !inputs.pointer) { inputs.pointer = wl_seat_get_pointer(seat); wl_pointer_add_listener(inputs.pointer, &kWlPointerListener, self); } else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && inputs.pointer) { - wl_pointer_destroy(inputs.pointer); + wl_pointer_release(inputs.pointer); inputs.pointer = nullptr; } @@ -305,7 +308,7 @@ const wl_seat_listener ELinuxWindowWayland::kWlSeatListener = { inputs.touch = wl_seat_get_touch(seat); wl_touch_add_listener(inputs.touch, &kWlTouchListener, self); } else if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && inputs.touch) { - wl_touch_destroy(inputs.touch); + wl_touch_release(inputs.touch); inputs.touch = nullptr; } @@ -313,7 +316,7 @@ const wl_seat_listener ELinuxWindowWayland::kWlSeatListener = { inputs.keyboard = wl_seat_get_keyboard(seat); wl_keyboard_add_listener(inputs.keyboard, &kWlKeyboardListener, self); } else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && inputs.keyboard) { - wl_keyboard_destroy(inputs.keyboard); + wl_keyboard_release(inputs.keyboard); inputs.keyboard = nullptr; } }, @@ -347,6 +350,11 @@ const wl_pointer_listener ELinuxWindowWayland::kWlPointerListener = { self->pointer_x_ = x_px; self->pointer_y_ = y_px; } + + // Force redraw even though it is the same cursor name + auto copy = self->cursor_info_.cursor_name; + self->cursor_info_.cursor_name.clear(); + self->UpdateFlutterCursor(copy); }, .leave = [](void* data, wl_pointer* pointer, @@ -1513,16 +1521,6 @@ void ELinuxWindowWayland::UpdateVirtualKeyboardStatus(const bool show) { void ELinuxWindowWayland::UpdateFlutterCursor(const std::string& cursor_name) { if (view_properties_.use_mouse_cursor) { - wl_pointer* pointer = nullptr; - for (auto& [_, inputs] : seat_inputs_map_) { - if (inputs.pointer != nullptr) { - pointer = inputs.pointer; - break; - } - } - if (!pointer) { - return; - } if (cursor_name.compare(cursor_info_.cursor_name) == 0) { return; } @@ -1644,6 +1642,7 @@ void ELinuxWindowWayland::WlRegistryHandler(wl_registry* wl_registry, wl_registry, name, &wl_seat_interface, std::min(kMaxVersion, version))), seat_inputs()); + registry_names_to_seat_ptr_.emplace(name, inserted->first); wl_seat_add_listener(inserted->first, &kWlSeatListener, this); return; } @@ -1720,7 +1719,35 @@ void ELinuxWindowWayland::WlRegistryHandler(wl_registry* wl_registry, } void ELinuxWindowWayland::WlUnRegistryHandler(wl_registry* wl_registry, - uint32_t name) {} + uint32_t name) { + // Just remove seats for now, as we don't need to do anything else. + // But there is also no interface name here. + auto seat_iter = registry_names_to_seat_ptr_.find(name); + if (seat_iter != registry_names_to_seat_ptr_.end()) { + auto seat = seat_iter->second; + auto seat_inputs_iter = seat_inputs_map_.find(seat); + if (seat_inputs_iter != seat_inputs_map_.end()) { + auto& inputs = seat_inputs_iter->second; + if (inputs.pointer) { + wl_pointer_release(inputs.pointer); + inputs.pointer = nullptr; + } + if (inputs.touch) { + wl_touch_release(inputs.touch); + inputs.touch = nullptr; + } + if (inputs.keyboard) { + wl_keyboard_release(inputs.keyboard); + inputs.keyboard = nullptr; + } + seat_inputs_map_.erase(seat_inputs_iter); + } + if (seat) { + wl_seat_destroy(seat); + } + registry_names_to_seat_ptr_.erase(name); + } +} bool ELinuxWindowWayland::LoadCursorTheme(uint32_t size) { if (!wl_shm_) { diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h index a4e454c4..8ccb84ba 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h @@ -171,6 +171,7 @@ class ELinuxWindowWayland : public ELinuxWindow, public WindowBindingHandler { wl_output* wl_output_; wl_shm* wl_shm_; std::unordered_map seat_inputs_map_; + std::unordered_map registry_names_to_seat_ptr_; wl_surface* wl_cursor_surface_; xdg_wm_base* xdg_wm_base_; xdg_surface* xdg_surface_; From 595f7f5bb02a32eb09a3ad136a5f9736e0fa7244 Mon Sep 17 00:00:00 2001 From: "Athaariq \"Eric\" Ardhiansyah" Date: Mon, 3 Jun 2024 06:34:17 +0700 Subject: [PATCH 103/112] Add libuv support as a replacement of systemd + some CMake fixes (#420) * git: prevent accidental push on generated files Signed-off-by: Athaariq Ardhiansyah * cmake: fix wrong option usage The option() function only dedicated for boolean type. For enumerated string, better use both set(... CACHE STRING ...) and set_property(CACHE ... PROPERTY STRINGS ...). Signed-off-by: Athaariq Ardhiansyah * cmake: fix wrong string cache syntax in set() For further information, visit the documentation at https://cmake.org/cmake/help/latest/command/set.html#set-cache-entry Signed-off-by: Athaariq Ardhiansyah * cmake: warn if BUILD_ELINUX_SO is OFF but BACKEND_TYPE was modified This commit prevents other new contributors from mistakenly blame CMakeLists.txt. Therefore, I added a warning just in case they forgot to turn on BUILD_ELINUX_SO while modifying BACKEND_TYPE. Signed-off-by: Athaariq Ardhiansyah * cmake: enforce regex exactness for safety Signed-off-by: Athaariq Ardhiansyah * drm: add libuv support as systemd replacement Not all embedded systems can include systemd due to their constrained resource limit. Our requirement from libsystemd is only event loop (sd-event). Therefore, libuv is perfect as drop-in replacement of sd-event. I tested the changes on Raspberry Pi 5 with Buildroot (yes, I am working on it too) and a x86-64 laptop with Arch Linux. Both are working as intended. Interestingly, libuv makes flutter-elinux smoother on my laptop. I have no idea how to benchmark it, but it is a good sign for us. For now, I am assuming users are still relying on libsystemd. Therefore, libuv only be used if the target device has no systemd. If maintainer want to drop the systemd dependency, I suggest to deprecate it gracefully and plan to drop it later. Otherwise, it would be a breaking change. Signed-off-by: Athaariq Ardhiansyah * author: add Athaariq Ardhiansyah Signed-off-by: Athaariq Ardhiansyah * style: overhaul to comply the standard Signed-off-by: Athaariq Ardhiansyah * style: format with clang-format v14.0.6 I realized that clang-format is inconsistent between its versions. So, Arch Linux (clang v17) and Ubuntu Jammy (clang v14) will output different formatting result. For Arch Linux users, the clang14 package has no clang-format included. You need to compile the entire clang on your own until the downstream maintainer include it. Signed-off-by: Athaariq Ardhiansyah * cmake: fix error for CMake before v3.28 On some distributions with non-latest CMake, it will fail on configuration due to its incapability of substition from unset variable to an empty string. To fix this, we need to add double quotes between variables that will be tested by EQUAL, LESS, GREATER, and other related keywords. For better compatibility, use STREQUAL instead of EQUAL if possible. Signed-off-by: Athaariq Ardhiansyah --------- Signed-off-by: Athaariq Ardhiansyah --- .gitignore | 1 + AUTHORS | 1 + CMakeLists.txt | 8 +- cmake/build.cmake | 16 ++- cmake/package.cmake | 13 ++- .../include/flutter/encodable_value.h | 4 +- .../include/flutter/texture_registrar.h | 3 +- .../platform/common/json_method_codec.cc | 3 +- .../common/public/flutter_texture_registrar.h | 15 +-- .../shell/platform/common/text_range.h | 4 +- .../linux_embedded/window/elinux_window_drm.h | 107 ++++++++++++++++-- 11 files changed, 147 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index 4b17e1c8..d199025c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .vscode/ /build/ +/src/third_party/wayland/protocols/* \ No newline at end of file diff --git a/AUTHORS b/AUTHORS index 151ed913..368deab2 100644 --- a/AUTHORS +++ b/AUTHORS @@ -15,3 +15,4 @@ Luke Howard Stanislav Shmarov Sebastian Urban Ómar Högni Guðmarsson +Athaariq Ardhiansyah diff --git a/CMakeLists.txt b/CMakeLists.txt index 0150694c..a467410a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,8 @@ set(CMAKE_CXX_STANDARD 17) project("flutter_elinux" LANGUAGES CXX C) # Build options. -option(BACKEND_TYPE "Select WAYLAND, DRM-GBM, DRM-EGLSTREAM, or X11 as the display backend type" WAYLAND) +set(BACKEND_TYPE "WAYLAND" CACHE STRING "Select WAYLAND, DRM-GBM, DRM-EGLSTREAM, or X11 as the display backend type") +set_property(CACHE BACKEND_TYPE PROPERTY STRINGS "WAYLAND" "DRM-GBM" "DRM-EGLSTREAM" "X11") # Disabled USE_DIRTY_REGION_MANAGEMENT due flicker issue. # See https://github.com/sony/flutter-embedded-linux/issues/334 option(USE_DIRTY_REGION_MANAGEMENT "Use Flutter dirty region management" OFF) @@ -24,8 +25,11 @@ option(FLUTTER_RELEASE "Build Flutter Engine with release mode" OFF) if(NOT BUILD_ELINUX_SO) # Load the user project. - set(USER_PROJECT_PATH "examples/flutter-wayland-client" CACHE STRING "") + set(USER_PROJECT_PATH "" CACHE STRING "examples/flutter-wayland-client") message("User project: ${USER_PROJECT_PATH}") + if(NOT ${BACKEND_TYPE} STREQUAL "WAYLAND") + message(WARNING "BACKEND_TYPE variable is ignored because BUILD_ELINUX_SO is OFF") + endif() include(${USER_PROJECT_PATH}/cmake/user_config.cmake) else() # Set the filename of elinux .so file diff --git a/cmake/build.cmake b/cmake/build.cmake index 7bd34f7e..ad69502b 100644 --- a/cmake/build.cmake +++ b/cmake/build.cmake @@ -249,6 +249,7 @@ target_link_libraries(${TARGET} ${LIBINPUT_LIBRARIES} ${LIBUDEV_LIBRARIES} ${LIBSYSTEMD_LIBRARIES} + ${LIBUV_LIBRARIES} ${X11_LIBRARIES} ${LIBWESTON_LIBRARIES} ${FLUTTER_EMBEDDER_LIB} @@ -256,11 +257,16 @@ target_link_libraries(${TARGET} ${USER_APP_LIBRARIES} ) -if(${BACKEND_TYPE} MATCHES "DRM-(GBM|EGLSTREAM)") -target_link_libraries(${TARGET} - PRIVATE - Threads::Threads -) +if(${BACKEND_TYPE} MATCHES "^DRM-(GBM|EGLSTREAM)$") + target_link_libraries(${TARGET} + PRIVATE + Threads::Threads + ) + + # Indicate whether libsystemd must replace libuv + if("${LIBSYSTEMD_FOUND}" STREQUAL "1") + add_definitions(-DUSE_LIBSYSTEMD) + endif() endif() set(FLUTTER_EMBEDDER_LIB "${CMAKE_CURRENT_SOURCE_DIR}/build/libflutter_engine.so") diff --git a/cmake/package.cmake b/cmake/package.cmake index 390d8113..7a2ebcaa 100644 --- a/cmake/package.cmake +++ b/cmake/package.cmake @@ -9,17 +9,26 @@ pkg_check_modules(EGL REQUIRED egl) pkg_check_modules(XKBCOMMON REQUIRED xkbcommon) # depends on backend type. -if(${BACKEND_TYPE} MATCHES "DRM-(GBM|EGLSTREAM)") +if(${BACKEND_TYPE} MATCHES "^DRM-(GBM|EGLSTREAM)$") # DRM backend pkg_check_modules(DRM REQUIRED libdrm) pkg_check_modules(LIBINPUT REQUIRED libinput) pkg_check_modules(LIBUDEV REQUIRED libudev) - pkg_check_modules(LIBSYSTEMD REQUIRED libsystemd) + pkg_check_modules(LIBSYSTEMD libsystemd) + pkg_check_modules(LIBUV libuv) if(${BACKEND_TYPE} STREQUAL "DRM-GBM") pkg_check_modules(GBM REQUIRED gbm) endif() set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) + # Check if either systemd or libuv exist + if((NOT "${LIBSYSTEMD_FOUND}" STREQUAL "1") AND (NOT "${LIBUV_FOUND}" STREQUAL "1")) + message(FATAL_ERROR + "${BACKEND_TYPE} backend requires either libsystemd or libuv, but + they're not exist.") + elseif(("${LIBSYSTEMD_FOUND}" STREQUAL "1") AND ("${LIBUV_FOUND}" STREQUAL "1")) + message("!! NOTICE: libsystemd found, libuv won't be used.") + endif() elseif(${BACKEND_TYPE} STREQUAL "X11") pkg_check_modules(X11 REQUIRED x11) else() diff --git a/src/flutter/shell/platform/common/client_wrapper/include/flutter/encodable_value.h b/src/flutter/shell/platform/common/client_wrapper/include/flutter/encodable_value.h index 3a191205..bf243fde 100644 --- a/src/flutter/shell/platform/common/client_wrapper/include/flutter/encodable_value.h +++ b/src/flutter/shell/platform/common/client_wrapper/include/flutter/encodable_value.h @@ -70,7 +70,9 @@ class CustomEncodableValue { #if defined(FLUTTER_ENABLE_RTTI) && FLUTTER_ENABLE_RTTI // Passthrough to std::any's type(). - const std::type_info& type() const noexcept { return value_.type(); } + const std::type_info& type() const noexcept { + return value_.type(); + } #endif // This operator exists only to provide a stable ordering for use as a diff --git a/src/flutter/shell/platform/common/client_wrapper/include/flutter/texture_registrar.h b/src/flutter/shell/platform/common/client_wrapper/include/flutter/texture_registrar.h index 4abe19d9..0777e528 100644 --- a/src/flutter/shell/platform/common/client_wrapper/include/flutter/texture_registrar.h +++ b/src/flutter/shell/platform/common/client_wrapper/include/flutter/texture_registrar.h @@ -107,7 +107,8 @@ class GpuSurfaceTexture { // The available texture variants. // Only PixelBufferTexture is currently implemented. // Other variants are expected to be added in the future. -typedef std::variant TextureVariant; +typedef std::variant + TextureVariant; // An object keeping track of external textures. // diff --git a/src/flutter/shell/platform/common/json_method_codec.cc b/src/flutter/shell/platform/common/json_method_codec.cc index cc4ffec6..9ccb79c8 100644 --- a/src/flutter/shell/platform/common/json_method_codec.cc +++ b/src/flutter/shell/platform/common/json_method_codec.cc @@ -104,7 +104,8 @@ JsonMethodCodec::EncodeErrorEnvelopeInternal( rapidjson::Document envelope(rapidjson::kArrayType); auto& allocator = envelope.GetAllocator(); envelope.PushBack(rapidjson::Value(error_code.c_str(), allocator), allocator); - envelope.PushBack(rapidjson::Value(error_message.c_str(), allocator), allocator); + envelope.PushBack(rapidjson::Value(error_message.c_str(), allocator), + allocator); rapidjson::Value details_value; if (error_details) { details_value.CopyFrom(*error_details, allocator); diff --git a/src/flutter/shell/platform/common/public/flutter_texture_registrar.h b/src/flutter/shell/platform/common/public/flutter_texture_registrar.h index cc0dbd2d..fb564382 100644 --- a/src/flutter/shell/platform/common/public/flutter_texture_registrar.h +++ b/src/flutter/shell/platform/common/public/flutter_texture_registrar.h @@ -76,7 +76,8 @@ typedef struct { size_t width; // Height of the EGLImage. size_t height; - // An optional callback that gets invoked when the |egl_image| can be released. + // An optional callback that gets invoked when the |egl_image| can be + // released. void (*release_callback)(void* release_context); // Opaque data passed to |release_callback|. void* release_context; @@ -142,12 +143,12 @@ typedef const FlutterDesktopGpuSurfaceDescriptor* ( size_t height, void* user_data); -typedef const FlutterDesktopEGLImage* ( - *FlutterDesktopEGLImageTextureCallback)(size_t width, - size_t height, - void* egl_display, - void* egl_context, - void* user_data); +typedef const FlutterDesktopEGLImage* (*FlutterDesktopEGLImageTextureCallback)( + size_t width, + size_t height, + void* egl_display, + void* egl_context, + void* user_data); // An object used to configure pixel buffer textures. typedef struct { diff --git a/src/flutter/shell/platform/common/text_range.h b/src/flutter/shell/platform/common/text_range.h index a7b3760b..6a0deff6 100644 --- a/src/flutter/shell/platform/common/text_range.h +++ b/src/flutter/shell/platform/common/text_range.h @@ -7,7 +7,7 @@ #include -//#include "flutter/fml/logging.h" +// #include "flutter/fml/logging.h" namespace flutter { @@ -66,7 +66,7 @@ class TextRange { // // Asserts that the range is of length 0. size_t position() const { - //FML_DCHECK(base_ == extent_); + // FML_DCHECK(base_ == extent_); return extent_; } diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h b/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h index 8b6c0767..0bbb883a 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h @@ -8,9 +8,14 @@ #include #include #include -#include #include +#ifdef USE_LIBSYSTEMD +#include +#else +#include +#endif + #include #include #include @@ -61,6 +66,7 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { return; } +#ifdef USE_LIBSYSTEMD ret = sd_event_new(&libinput_event_loop_); if (ret < 0) { ELINUX_LOG(ERROR) << "Failed to create libinput event loop."; @@ -74,20 +80,46 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { libinput_event_loop_ = sd_event_unref(libinput_event_loop_); return; } +#else // #ifdef USE_LIBSYSTEMD + ret = uv_loop_init(&main_loop_); + if (ret) { + ELINUX_LOG(ERROR) << "Failed to create main event loop."; + return; + } + ret = uv_poll_init(&main_loop_, &libinput_event_loop_, + libinput_get_fd(libinput_)); + if (ret) { + ELINUX_LOG(ERROR) << "Failed to create libinput event loop."; + return; + } + libinput_event_loop_.data = this; + ret = uv_poll_start(&libinput_event_loop_, + UV_READABLE | UV_DISCONNECT | UV_PRIORITIZED, + OnLibinputEvent); + if (ret) { + ELINUX_LOG(ERROR) << "Failed to listen for user input."; + return; + } +#endif // #ifdef USE_LIBSYSTEMD } ~ELinuxWindowDrm() { +#ifdef USE_LIBSYSTEMD if (udev_drm_event_loop_) { sd_event_unref(udev_drm_event_loop_); } +#endif if (udev_monitor_) { udev_monitor_unref(udev_monitor_); } +#ifdef USE_LIBSYSTEMD if (libinput_event_loop_) { sd_event_unref(libinput_event_loop_); } +#endif + libinput_unref(libinput_); display_valid_ = false; } @@ -103,9 +135,13 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { // |FlutterWindowBindingHandler| bool DispatchEvent() override { +#ifdef USE_LIBSYSTEMD constexpr uint64_t kMaxWaitTime = 0; sd_event_run(libinput_event_loop_, kMaxWaitTime); sd_event_run(udev_drm_event_loop_, kMaxWaitTime); +#else + uv_run(&main_loop_, UV_RUN_NOWAIT); +#endif return true; } @@ -192,10 +228,14 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { } // |FlutterWindowBindingHandler| - uint16_t GetRotationDegree() const override { return current_rotation_; } + uint16_t GetRotationDegree() const override { + return current_rotation_; + } // |FlutterWindowBindingHandler| - double GetDpiScale() override { return current_scale_; } + double GetDpiScale() override { + return current_scale_; + } // |FlutterWindowBindingHandler| PhysicalWindowBounds GetPhysicalWindowBounds() override { @@ -203,7 +243,9 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { } // |FlutterWindowBindingHandler| - int32_t GetFrameRate() override { return 60000; } + int32_t GetFrameRate() override { + return 60000; + } // |FlutterWindowBindingHandler| void UpdateFlutterCursor(const std::string& cursor_name) override { @@ -218,7 +260,9 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { } // |FlutterWindowBindingHandler| - std::string GetClipboardData() override { return clipboard_data_; } + std::string GetClipboardData() override { + return clipboard_data_; + } // |FlutterWindowBindingHandler| void SetClipboardData(const std::string& data) override { @@ -290,6 +334,7 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { } udev_unref(udev); +#ifdef USE_LIBSYSTEMD if (sd_event_new(&udev_drm_event_loop_) < 0) { ELINUX_LOG(ERROR) << "Failed to create udev drm event loop."; return false; @@ -301,6 +346,22 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { ELINUX_LOG(ERROR) << "Failed to listen for udev drm event."; return false; } +#else // #ifdef USE_LIBSYSTEMD + if (uv_poll_init(&main_loop_, &udev_drm_event_loop_, + udev_monitor_get_fd(udev_monitor_))) { + ELINUX_LOG(ERROR) << "Failed to create udev drm event loop."; + return false; + } + + udev_drm_event_loop_.data = this; + + if (uv_poll_start(&udev_drm_event_loop_, + UV_READABLE | UV_DISCONNECT | UV_PRIORITIZED, + OnUdevDrmEvent)) { + ELINUX_LOG(ERROR) << "Failed to listen for udev drm event."; + return false; + } +#endif // #ifdef USE_LIBSYSTEMD if (udev_monitor_enable_receiving(udev_monitor_) < 0) { ELINUX_LOG(ERROR) << "Failed to enable udev monitor receiving."; @@ -310,6 +371,7 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { return true; } +#ifdef USE_LIBSYSTEMD static int OnUdevDrmEvent(sd_event_source* source, int fd, uint32_t revents, @@ -320,6 +382,15 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { ELINUX_LOG(ERROR) << "Failed to receive udev device."; return -1; } +#else + static void OnUdevDrmEvent(uv_poll_t* handle, int status, int events) { + auto self = reinterpret_cast(handle->data); + auto device = udev_monitor_receive_device(self->udev_monitor_); + if (!device) { + ELINUX_LOG(ERROR) << "Failed to receive udev device."; + return; + } +#endif if (self->IsUdevEventHotplug(*device) && self->native_window_->ConfigureDisplay(self->current_rotation_)) { @@ -343,7 +414,10 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { } udev_device_unref(device); + +#ifdef USE_LIBSYSTEMD return 0; +#endif } bool IsUdevEventHotplug(udev_device& device) { @@ -368,6 +442,7 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { return std::strcmp(value, kPropertyOn) == 0; } +#ifdef USE_LIBSYSTEMD static int OnLibinputEvent(sd_event_source* source, int fd, uint32_t revents, @@ -378,6 +453,15 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { ELINUX_LOG(ERROR) << "Failed to dispatch libinput events."; return -ret; } +#else + static void OnLibinputEvent(uv_poll_t* handle, int uv_status, int uv_events) { + auto self = reinterpret_cast(handle->data); + auto ret = libinput_dispatch(self->libinput_); + if (ret < 0) { + ELINUX_LOG(ERROR) << "Failed to dispatch libinput events."; + return; + } +#endif auto previous_pointer_x = self->pointer_x_; auto previous_pointer_y = self->pointer_y_; @@ -435,7 +519,9 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { self->native_window_->MoveCursor(self->pointer_x_, self->pointer_y_); } +#ifdef USE_LIBSYSTEMD return 0; +#endif } void OnDeviceAdded(libinput_event* event) { @@ -716,15 +802,22 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { bool display_valid_; bool is_pending_cursor_add_event_; - sd_event* libinput_event_loop_; libinput* libinput_; std::unordered_map> libinput_devices_; int libinput_pointer_devices_ = 0; - sd_event* udev_drm_event_loop_ = nullptr; udev_monitor* udev_monitor_ = nullptr; std::optional drm_device_id_; + +#ifdef USE_LIBSYSTEMD + sd_event* libinput_event_loop_; + sd_event* udev_drm_event_loop_ = nullptr; +#else + uv_loop_t main_loop_; + uv_poll_t libinput_event_loop_; + uv_poll_t udev_drm_event_loop_; +#endif }; } // namespace flutter From 30b3d4aa78f5a14714caabf755f69a6afa9602a1 Mon Sep 17 00:00:00 2001 From: Anton Sakhon <58438890+Kofhein@users.noreply.github.com> Date: Fri, 6 Sep 2024 15:35:58 +0300 Subject: [PATCH 104/112] Added marshalling to main thread messages sent from native side (#422) * Added marshalling to main thread messages sent from native side --------- Co-authored-by: Anton Sakhon --- AUTHORS | 1 + .../client_wrapper/core_implementations.cc | 13 ++++--- .../common/public/flutter_messenger.h | 3 +- .../platform/linux_embedded/flutter_elinux.cc | 34 +++++++++++++------ 4 files changed, 36 insertions(+), 15 deletions(-) diff --git a/AUTHORS b/AUTHORS index 368deab2..85298807 100644 --- a/AUTHORS +++ b/AUTHORS @@ -16,3 +16,4 @@ Stanislav Shmarov Sebastian Urban Ómar Högni Guðmarsson Athaariq Ardhiansyah +Anton Sakhon diff --git a/src/flutter/shell/platform/common/client_wrapper/core_implementations.cc b/src/flutter/shell/platform/common/client_wrapper/core_implementations.cc index 3aae66ca..8110a0c3 100644 --- a/src/flutter/shell/platform/common/client_wrapper/core_implementations.cc +++ b/src/flutter/shell/platform/common/client_wrapper/core_implementations.cc @@ -66,6 +66,11 @@ BinaryMessengerImpl::BinaryMessengerImpl( BinaryMessengerImpl::~BinaryMessengerImpl() = default; +void CaptureCleaner(void* lambda) { + auto& cleanup = *reinterpret_cast*>(lambda); + cleanup(); +} + void BinaryMessengerImpl::Send(const std::string& channel, const uint8_t* message, size_t message_size, @@ -89,10 +94,10 @@ void BinaryMessengerImpl::Send(const std::string& channel, }; bool result = FlutterDesktopMessengerSendWithReply( messenger_, channel.c_str(), message, message_size, message_reply, - captures); - if (!result) { - delete captures; - } + captures, [](void* captures_data) { + auto captures = reinterpret_cast(captures_data); + delete captures; + }); } void BinaryMessengerImpl::SetMessageHandler(const std::string& channel, diff --git a/src/flutter/shell/platform/common/public/flutter_messenger.h b/src/flutter/shell/platform/common/public/flutter_messenger.h index 87c33beb..bb182cdf 100644 --- a/src/flutter/shell/platform/common/public/flutter_messenger.h +++ b/src/flutter/shell/platform/common/public/flutter_messenger.h @@ -63,7 +63,8 @@ FLUTTER_EXPORT bool FlutterDesktopMessengerSendWithReply( const uint8_t* message, const size_t message_size, const FlutterDesktopBinaryReply reply, - void* user_data); + void* user_data, + void (*cleanup)(void* captures_data)); // Sends a reply to a FlutterDesktopMessage for the given response handle. // diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux.cc index d3c3dee3..fd3754a4 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux.cc @@ -199,22 +199,36 @@ void FlutterDesktopPluginRegistrarSetDestructionHandler( registrar->engine->SetPluginRegistrarDestructionCallback(callback); } -bool FlutterDesktopMessengerSendWithReply(FlutterDesktopMessengerRef messenger, - const char* channel, - const uint8_t* message, - const size_t message_size, - const FlutterDesktopBinaryReply reply, - void* user_data) { - return messenger->GetEngine()->SendPlatformMessage( - channel, message, message_size, reply, user_data); +bool FlutterDesktopMessengerSendWithReply( + FlutterDesktopMessengerRef messenger, + const char* channel, + const uint8_t* message, + const size_t message_size, + const FlutterDesktopBinaryReply reply, + void* user_data, + void (*cleanup)(void* captures_data)) { + // As we pass data to lambda and it's pointers we need to make sure that we + // send valid data + std::string channel_copy(channel); + std::vector message_copy(message, message + message_size); + + messenger->GetEngine()->task_runner()->PostTask([=]() { + if (!messenger->GetEngine()->SendPlatformMessage( + channel_copy.c_str(), message_copy.data(), message_copy.size(), + reply, user_data) && + user_data) { + cleanup(user_data); + } + }); + return true; } bool FlutterDesktopMessengerSend(FlutterDesktopMessengerRef messenger, const char* channel, const uint8_t* message, const size_t message_size) { - return FlutterDesktopMessengerSendWithReply(messenger, channel, message, - message_size, nullptr, nullptr); + return FlutterDesktopMessengerSendWithReply( + messenger, channel, message, message_size, nullptr, nullptr, nullptr); } void FlutterDesktopMessengerSendResponse( From 63b57ca74991ce6782736a1adb8b63928797272f Mon Sep 17 00:00:00 2001 From: Anton Sakhon <58438890+Kofhein@users.noreply.github.com> Date: Fri, 6 Sep 2024 16:47:21 +0300 Subject: [PATCH 105/112] Removed unused variable (#423) --- .../platform/common/client_wrapper/core_implementations.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/flutter/shell/platform/common/client_wrapper/core_implementations.cc b/src/flutter/shell/platform/common/client_wrapper/core_implementations.cc index 8110a0c3..983feb3e 100644 --- a/src/flutter/shell/platform/common/client_wrapper/core_implementations.cc +++ b/src/flutter/shell/platform/common/client_wrapper/core_implementations.cc @@ -92,7 +92,8 @@ void BinaryMessengerImpl::Send(const std::string& channel, captures->reply(data, data_size); delete captures; }; - bool result = FlutterDesktopMessengerSendWithReply( + + FlutterDesktopMessengerSendWithReply( messenger_, channel.c_str(), message, message_size, message_reply, captures, [](void* captures_data) { auto captures = reinterpret_cast(captures_data); From 9dc1156ca709a54ea07ce5873f8d7f6357e98c9c Mon Sep 17 00:00:00 2001 From: barribarrier <98932277+barribarrier@users.noreply.github.com> Date: Fri, 20 Sep 2024 07:17:30 -0400 Subject: [PATCH 106/112] Specify DRM connector with FLUTTER_DRM_CONNECTOR (#425) * Specify DRM connector with FLUTTER_DRM_CONNECTOR * Update AUTHORS --------- Co-authored-by: barri --- AUTHORS | 1 + .../window/native_window_drm.cc | 76 +++++++++++++++++++ .../linux_embedded/window/native_window_drm.h | 4 + 3 files changed, 81 insertions(+) diff --git a/AUTHORS b/AUTHORS index 85298807..6a816263 100644 --- a/AUTHORS +++ b/AUTHORS @@ -17,3 +17,4 @@ Sebastian Urban Ómar Högni Guðmarsson Athaariq Ardhiansyah Anton Sakhon +Bari Rao diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_drm.cc b/src/flutter/shell/platform/linux_embedded/window/native_window_drm.cc index 59a29021..73023fd2 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_drm.cc +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_drm.cc @@ -14,6 +14,31 @@ #include "flutter/shell/platform/linux_embedded/surface/cursor_data.h" namespace flutter { +namespace { +constexpr char kFlutterDrmConnectorEnvironmentKey[] = "FLUTTER_DRM_CONNECTOR"; +static const std::unordered_map connector_names = { + {DRM_MODE_CONNECTOR_Unknown, "Unknown"}, + {DRM_MODE_CONNECTOR_VGA, "VGA"}, + {DRM_MODE_CONNECTOR_DVII, "DVI-I"}, + {DRM_MODE_CONNECTOR_DVID, "DVI-D"}, + {DRM_MODE_CONNECTOR_DVIA, "DVI-A"}, + {DRM_MODE_CONNECTOR_Composite, "Composite"}, + {DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO"}, + {DRM_MODE_CONNECTOR_LVDS, "LVDS"}, + {DRM_MODE_CONNECTOR_Component, "Component"}, + {DRM_MODE_CONNECTOR_9PinDIN, "DIN"}, + {DRM_MODE_CONNECTOR_DisplayPort, "DP"}, + {DRM_MODE_CONNECTOR_HDMIA, "HDMI-A"}, + {DRM_MODE_CONNECTOR_HDMIB, "HDMI-B"}, + {DRM_MODE_CONNECTOR_TV, "TV"}, + {DRM_MODE_CONNECTOR_eDP, "eDP"}, + {DRM_MODE_CONNECTOR_VIRTUAL, "Virtual"}, + {DRM_MODE_CONNECTOR_DSI, "DSI"}, + {DRM_MODE_CONNECTOR_DPI, "DPI"}, + {DRM_MODE_CONNECTOR_WRITEBACK, "Writeback"}, + {DRM_MODE_CONNECTOR_SPI, "SPI"}, + {DRM_MODE_CONNECTOR_USB, "USB"}}; +} // namespace NativeWindowDrm::NativeWindowDrm(const char* device_filename, const uint16_t rotation, @@ -104,11 +129,62 @@ bool NativeWindowDrm::ConfigureDisplay(const uint16_t rotation) { return true; } +std::string NativeWindowDrm::GetConnectorName(uint32_t connector_type, + uint32_t connector_type_id) { + auto it = connector_names.find(connector_type); + std::string name = it != connector_names.end() ? it->second : "Unknown"; + return name + "-" + std::to_string(connector_type_id); +} + +drmModeConnectorPtr NativeWindowDrm::GetConnectorByName( + drmModeResPtr resources, + const char* connector_name) { + for (int i = 0; i < resources->count_connectors; i++) { + auto connector = drmModeGetConnector(drm_device_, resources->connectors[i]); + if (!connector) { + continue; + } + auto other_connector_name = GetConnectorName(connector->connector_type, + connector->connector_type_id); + if (connector_name == other_connector_name) { + return connector; + } + drmModeFreeConnector(connector); + } + return nullptr; +} + drmModeConnectorPtr NativeWindowDrm::FindConnector(drmModeResPtr resources) { + auto connector_name = std::getenv(kFlutterDrmConnectorEnvironmentKey); + if (connector_name && connector_name[0] != '\0') { + auto connector = GetConnectorByName(resources, connector_name); + if (!connector) { + ELINUX_LOG(ERROR) << "Couldn't find connector with name " + << connector_name; + return nullptr; + } + + if (connector->connection == DRM_MODE_CONNECTED) { + ELINUX_LOG(DEBUG) << "Using connector " << connector_name; + return connector; + } else { + ELINUX_LOG(ERROR) << "Connector " << connector_name + << " is not connected."; + drmModeFreeConnector(connector); + return nullptr; + } + } + for (int i = 0; i < resources->count_connectors; i++) { auto connector = drmModeGetConnector(drm_device_, resources->connectors[i]); + if (!connector) { + continue; + } // pick the first connected connector if (connector->connection == DRM_MODE_CONNECTED) { + auto other_connetor_name = GetConnectorName(connector->connector_type, + connector->connector_type_id); + ELINUX_LOG(DEBUG) << "Using connector " << other_connetor_name; return connector; } drmModeFreeConnector(connector); diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window_drm.h b/src/flutter/shell/platform/linux_embedded/window/native_window_drm.h index bae9ec06..3d72f7ac 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window_drm.h +++ b/src/flutter/shell/platform/linux_embedded/window/native_window_drm.h @@ -39,6 +39,10 @@ class NativeWindowDrm : public NativeWindow { bool enable_impeller) = 0; protected: + std::string GetConnectorName(uint32_t connector_type, + uint32_t connector_type_id); + drmModeConnectorPtr GetConnectorByName(drmModeResPtr resources, + const char* connector_name); drmModeConnectorPtr FindConnector(drmModeResPtr resources); drmModeEncoder* FindEncoder(drmModeRes* resources, From 9d0ff07b5e1cccbead808ddff0f13f1c5ceeae52 Mon Sep 17 00:00:00 2001 From: barribarrier <98932277+barribarrier@users.noreply.github.com> Date: Mon, 30 Sep 2024 08:06:07 -0400 Subject: [PATCH 107/112] Destroy textures on raster thread (#427) * Destroy textures on raster thread Signed-off-by: Bari Rao * Fix format Signed-off-by: Bari Rao --------- Signed-off-by: Bari Rao --- src/flutter/fml/closure.h | 77 +++++++++++++++++++ src/flutter/fml/macros.h | 44 +++++++++++ .../client_wrapper/core_implementations.cc | 27 ++++++- .../include/flutter/texture_registrar.h | 9 ++- .../client_wrapper/texture_registrar_impl.h | 4 + .../common/public/flutter_texture_registrar.h | 12 +-- .../platform/linux_embedded/flutter_elinux.cc | 15 +++- .../linux_embedded/flutter_elinux_engine.cc | 20 +++++ .../linux_embedded/flutter_elinux_engine.h | 3 + .../flutter_elinux_texture_registrar.cc | 30 +++++--- .../flutter_elinux_texture_registrar.h | 4 +- 11 files changed, 219 insertions(+), 26 deletions(-) create mode 100644 src/flutter/fml/closure.h create mode 100644 src/flutter/fml/macros.h diff --git a/src/flutter/fml/closure.h b/src/flutter/fml/closure.h new file mode 100644 index 00000000..264a95f7 --- /dev/null +++ b/src/flutter/fml/closure.h @@ -0,0 +1,77 @@ +// 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. + +#ifndef FLUTTER_FML_CLOSURE_H_ +#define FLUTTER_FML_CLOSURE_H_ + +#include + +#include "flutter/fml/macros.h" + +namespace fml { + +using closure = std::function; + +//------------------------------------------------------------------------------ +/// @brief Wraps a closure that is invoked in the destructor unless +/// released by the caller. +/// +/// This is especially useful in dealing with APIs that return a +/// resource by accepting ownership of a sub-resource and a closure +/// that releases that resource. When such APIs are chained, each +/// link in the chain must check that the next member in the chain +/// has accepted the resource. If not, it must invoke the closure +/// eagerly. Not doing this results in a resource leak in the +/// erroneous case. Using this wrapper, the closure can be released +/// once the next call in the chain has successfully accepted +/// ownership of the resource. If not, the closure gets invoked +/// automatically at the end of the scope. This covers the cases +/// where there are early returns as well. +/// +class ScopedCleanupClosure final { + public: + ScopedCleanupClosure() = default; + + ScopedCleanupClosure(ScopedCleanupClosure&& other) { + closure_ = other.Release(); + } + + ScopedCleanupClosure& operator=(ScopedCleanupClosure&& other) { + closure_ = other.Release(); + return *this; + } + + explicit ScopedCleanupClosure(const fml::closure& closure) + : closure_(closure) {} + + ~ScopedCleanupClosure() { Reset(); } + + fml::closure SetClosure(const fml::closure& closure) { + auto old_closure = closure_; + closure_ = closure; + return old_closure; + } + + fml::closure Release() { + fml::closure closure = closure_; + closure_ = nullptr; + return closure; + } + + void Reset() { + if (closure_) { + closure_(); + closure_ = nullptr; + } + } + + private: + fml::closure closure_; + + FML_DISALLOW_COPY_AND_ASSIGN(ScopedCleanupClosure); +}; + +} // namespace fml + +#endif // FLUTTER_FML_CLOSURE_H_ diff --git a/src/flutter/fml/macros.h b/src/flutter/fml/macros.h new file mode 100644 index 00000000..7de4ddf1 --- /dev/null +++ b/src/flutter/fml/macros.h @@ -0,0 +1,44 @@ +// 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. + +#ifndef FLUTTER_FML_MACROS_H_ +#define FLUTTER_FML_MACROS_H_ + +#ifndef FML_USED_ON_EMBEDDER + +#define FML_EMBEDDER_ONLY [[deprecated]] + +#else // FML_USED_ON_EMBEDDER + +#define FML_EMBEDDER_ONLY + +#endif // FML_USED_ON_EMBEDDER + +#define FML_DISALLOW_COPY(TypeName) TypeName(const TypeName&) = delete + +#define FML_DISALLOW_ASSIGN(TypeName) \ + TypeName& operator=(const TypeName&) = delete + +#define FML_DISALLOW_MOVE(TypeName) \ + TypeName(TypeName&&) = delete; \ + TypeName& operator=(TypeName&&) = delete + +#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName) \ + TypeName(const TypeName&) = delete; \ + TypeName& operator=(const TypeName&) = delete + +#define FML_DISALLOW_COPY_ASSIGN_AND_MOVE(TypeName) \ + TypeName(const TypeName&) = delete; \ + TypeName(TypeName&&) = delete; \ + TypeName& operator=(const TypeName&) = delete; \ + TypeName& operator=(TypeName&&) = delete + +#define FML_DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ + TypeName() = delete; \ + FML_DISALLOW_COPY_ASSIGN_AND_MOVE(TypeName) + +#define FML_FRIEND_TEST(test_case_name, test_name) \ + friend class test_case_name##_##test_name##_Test + +#endif // FLUTTER_FML_MACROS_H_ diff --git a/src/flutter/shell/platform/common/client_wrapper/core_implementations.cc b/src/flutter/shell/platform/common/client_wrapper/core_implementations.cc index 983feb3e..ec0d6dd9 100644 --- a/src/flutter/shell/platform/common/client_wrapper/core_implementations.cc +++ b/src/flutter/shell/platform/common/client_wrapper/core_implementations.cc @@ -210,9 +210,32 @@ bool TextureRegistrarImpl::MarkTextureFrameAvailable(int64_t texture_id) { texture_registrar_ref_, texture_id); } +void TextureRegistrarImpl::UnregisterTexture(int64_t texture_id, + std::function callback) { + if (callback == nullptr) { + FlutterDesktopTextureRegistrarUnregisterExternalTexture( + texture_registrar_ref_, texture_id, nullptr, nullptr); + return; + } + + struct Captures { + std::function callback; + }; + auto captures = new Captures(); + captures->callback = std::move(callback); + FlutterDesktopTextureRegistrarUnregisterExternalTexture( + texture_registrar_ref_, texture_id, + [](void* opaque) { + auto captures = reinterpret_cast(opaque); + captures->callback(); + delete captures; + }, + captures); +} + bool TextureRegistrarImpl::UnregisterTexture(int64_t texture_id) { - return FlutterDesktopTextureRegistrarUnregisterExternalTexture( - texture_registrar_ref_, texture_id); + UnregisterTexture(texture_id, nullptr); + return true; } } // namespace flutter diff --git a/src/flutter/shell/platform/common/client_wrapper/include/flutter/texture_registrar.h b/src/flutter/shell/platform/common/client_wrapper/include/flutter/texture_registrar.h index 0777e528..9b13025f 100644 --- a/src/flutter/shell/platform/common/client_wrapper/include/flutter/texture_registrar.h +++ b/src/flutter/shell/platform/common/client_wrapper/include/flutter/texture_registrar.h @@ -128,8 +128,13 @@ class TextureRegistrar { // the callback that was provided upon creating the texture. virtual bool MarkTextureFrameAvailable(int64_t texture_id) = 0; - // Unregisters an existing Texture object. - // Textures must not be unregistered while they're in use. + // Asynchronously unregisters an existing texture object. + // Upon completion, the optional |callback| gets invoked. + virtual void UnregisterTexture(int64_t texture_id, + std::function callback) = 0; + + // Unregisters an existing texture object. + // DEPRECATED: Use UnregisterTexture(texture_id, optional_callback) instead. virtual bool UnregisterTexture(int64_t texture_id) = 0; }; diff --git a/src/flutter/shell/platform/common/client_wrapper/texture_registrar_impl.h b/src/flutter/shell/platform/common/client_wrapper/texture_registrar_impl.h index df51f6dd..bd01839d 100644 --- a/src/flutter/shell/platform/common/client_wrapper/texture_registrar_impl.h +++ b/src/flutter/shell/platform/common/client_wrapper/texture_registrar_impl.h @@ -27,6 +27,10 @@ class TextureRegistrarImpl : public TextureRegistrar { // |flutter::TextureRegistrar| bool MarkTextureFrameAvailable(int64_t texture_id) override; + // |flutter::TextureRegistrar| + void UnregisterTexture(int64_t texture_id, + std::function callback) override; + // |flutter::TextureRegistrar| bool UnregisterTexture(int64_t texture_id) override; diff --git a/src/flutter/shell/platform/common/public/flutter_texture_registrar.h b/src/flutter/shell/platform/common/public/flutter_texture_registrar.h index fb564382..a56c3107 100644 --- a/src/flutter/shell/platform/common/public/flutter_texture_registrar.h +++ b/src/flutter/shell/platform/common/public/flutter_texture_registrar.h @@ -195,13 +195,15 @@ FLUTTER_EXPORT int64_t FlutterDesktopTextureRegistrarRegisterExternalTexture( FlutterDesktopTextureRegistrarRef texture_registrar, const FlutterDesktopTextureInfo* info); -// Unregisters an existing texture from the Flutter engine for a |texture_id|. -// Returns true on success or false if the specified texture doesn't exist. +// Asynchronously unregisters the texture identified by |texture_id| from the +// Flutter engine. +// An optional |callback| gets invoked upon completion. // This function can be called from any thread. -// However, textures must not be unregistered while they're in use. -FLUTTER_EXPORT bool FlutterDesktopTextureRegistrarUnregisterExternalTexture( +FLUTTER_EXPORT void FlutterDesktopTextureRegistrarUnregisterExternalTexture( FlutterDesktopTextureRegistrarRef texture_registrar, - int64_t texture_id); + int64_t texture_id, + void (*callback)(void* user_data), + void* user_data); // Marks that a new texture frame is available for a given |texture_id|. // Returns true on success or false if the specified texture doesn't exist. diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux.cc index fd3754a4..2d3587f3 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux.cc @@ -284,11 +284,18 @@ int64_t FlutterDesktopTextureRegistrarRegisterExternalTexture( ->RegisterTexture(texture_info); } -bool FlutterDesktopTextureRegistrarUnregisterExternalTexture( +void FlutterDesktopTextureRegistrarUnregisterExternalTexture( FlutterDesktopTextureRegistrarRef texture_registrar, - int64_t texture_id) { - return TextureRegistrarFromHandle(texture_registrar) - ->UnregisterTexture(texture_id); + int64_t texture_id, + void (*callback)(void* user_data), + void* user_data) { + auto registrar = TextureRegistrarFromHandle(texture_registrar); + if (callback) { + registrar->UnregisterTexture( + texture_id, [callback, user_data]() { callback(user_data); }); + return; + } + registrar->UnregisterTexture(texture_id); } bool FlutterDesktopTextureRegistrarMarkExternalTextureFrameAvailable( diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc index 9e49c9e4..c09bca5e 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc @@ -425,6 +425,26 @@ bool FlutterELinuxEngine::MarkExternalTextureFrameAvailable( engine_, texture_id) == kSuccess); } +bool FlutterELinuxEngine::PostRasterThreadTask(fml::closure callback) { + struct Captures { + fml::closure callback; + }; + auto captures = new Captures(); + captures->callback = std::move(callback); + if (embedder_api_.PostRenderThreadTask( + engine_, + [](void* opaque) { + auto captures = reinterpret_cast(opaque); + captures->callback(); + delete captures; + }, + captures) == kSuccess) { + return true; + } + delete captures; + return false; +} + void FlutterELinuxEngine::OnVsync(uint64_t last_frame_time_nanos, uint64_t vsync_interval_time_nanos) { uint64_t current_time_nanos = embedder_api_.GetCurrentTime(); diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h index b705941e..4bcc7f10 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h @@ -120,6 +120,9 @@ class FlutterELinuxEngine { // given |texture_id|. bool MarkExternalTextureFrameAvailable(int64_t texture_id); + // Posts the given callback onto the raster thread. + bool PostRasterThreadTask(fml::closure callback); + // Notifies the engine about the vsync event. void OnVsync(uint64_t last_frame_time_nanos, uint64_t vsync_interval_time_nanos); diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_texture_registrar.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux_texture_registrar.cc index be4899fe..66a603c3 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_texture_registrar.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_texture_registrar.cc @@ -72,20 +72,28 @@ int64_t FlutterELinuxTextureRegistrar::EmplaceTexture( return texture_id; } -bool FlutterELinuxTextureRegistrar::UnregisterTexture(int64_t texture_id) { - { - std::lock_guard lock(map_mutex_); - auto it = textures_.find(texture_id); - if (it == textures_.end()) { - return false; - } - textures_.erase(it); - } - +void FlutterELinuxTextureRegistrar::UnregisterTexture(int64_t texture_id, + fml::closure callback) { engine_->task_runner()->RunNowOrPostTask([engine = engine_, texture_id]() { engine->UnregisterExternalTexture(texture_id); }); - return true; + + bool posted = engine_->PostRasterThreadTask([this, texture_id, callback]() { + { + std::lock_guard lock(map_mutex_); + auto it = textures_.find(texture_id); + if (it != textures_.end()) { + textures_.erase(it); + } + } + if (callback) { + callback(); + } + }); + + if (!posted && callback) { + callback(); + } } bool FlutterELinuxTextureRegistrar::MarkTextureFrameAvailable( diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_texture_registrar.h b/src/flutter/shell/platform/linux_embedded/flutter_elinux_texture_registrar.h index 7ad57a2f..8770ad57 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_texture_registrar.h +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_texture_registrar.h @@ -9,6 +9,7 @@ #include #include +#include "flutter/fml/closure.h" #include "flutter/shell/platform/common/public/flutter_texture_registrar.h" #include "flutter/shell/platform/linux_embedded/external_texture.h" @@ -28,8 +29,7 @@ class FlutterELinuxTextureRegistrar { int64_t RegisterTexture(const FlutterDesktopTextureInfo* texture_info); // Attempts to unregister the texture identified by |texture_id|. - // Returns true if the texture was successfully unregistered. - bool UnregisterTexture(int64_t texture_id); + void UnregisterTexture(int64_t texture_id, fml::closure callback = nullptr); // Notifies the engine about a new frame being available. // Returns true on success. From a938f2b2064bb25b58c5207f6f5c3dfb9972fadf Mon Sep 17 00:00:00 2001 From: Luke Howard Date: Wed, 30 Oct 2024 21:35:12 +1100 Subject: [PATCH 108/112] Ensure FlutterDesktopViewControllerState declares default destructor (#428) types containing std::unique_ptr to incomplete types require a destructor to be defined as the size is unavailable, otherwise the following error is raised at compile time: /usr/lib/gcc/aarch64-linux-gnu/13/../../../../include/c++/13/bits/unique_ptr.h:97:16: error: invalid application of 'sizeof' to an incomplete type 'flutter::FlutterELinuxView' 91 | _GLIBCXX23_CONSTEXPR 92 | void 93 | operator()(_Tp* __ptr) const | `- note: in instantiation of member function 'std::default_delete::operator()' requested here 94 | { 95 | static_assert(!is_void<_Tp>::value, 96 | "can't delete pointer to incomplete type"); 97 | static_assert(sizeof(_Tp)>0, | `- error: invalid application of 'sizeof' to an incomplete type 'flutter::FlutterELinuxView' 98 | "can't delete pointer to incomplete type"); 99 | delete __ptr; Signed-off-by: Luke Howard --- .../shell/platform/linux_embedded/flutter_elinux_state.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_state.h b/src/flutter/shell/platform/linux_embedded/flutter_elinux_state.h index 8248f7e8..aea43c4c 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_state.h +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_state.h @@ -34,6 +34,8 @@ struct FlutterELinuxView; struct FlutterDesktopViewControllerState { // The view that backs this state object. std::unique_ptr view; + + ~FlutterDesktopViewControllerState() = default; }; // Wrapper to distinguish the plugin registrar ref from the engine ref given out From 679d3612e4a6a65ade648a98581a48c4bd5713e4 Mon Sep 17 00:00:00 2001 From: Hidenori Date: Sat, 14 Dec 2024 05:10:34 +0900 Subject: [PATCH 109/112] linux_embedded: fix github actions' failure (#431) This change fixes the CI failure due to code format warnings. Signed-off-by: Hidenori Matsubayashi --- .../linux_embedded/flutter_elinux_engine.cc | 10 ++++------ .../plugins/platform_views_plugin.cc | 5 ++--- .../linux_embedded/surface/context_egl.cc | 20 +++++++++---------- .../linux_embedded/window/elinux_window_drm.h | 16 ++++----------- .../window/elinux_window_wayland.cc | 10 +++++----- .../linux_embedded/window/native_window.h | 2 +- 6 files changed, 26 insertions(+), 37 deletions(-) diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc index c09bca5e..45a922e2 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc @@ -371,8 +371,7 @@ void FlutterELinuxEngine::HandlePlatformMessage( auto message = ConvertToDesktopMessage(*engine_message); - message_dispatcher_->HandleMessage( - message, [this] {}, [this] {}); + message_dispatcher_->HandleMessage(message, [this] {}, [this] {}); } void FlutterELinuxEngine::ReloadSystemFonts() { @@ -398,10 +397,9 @@ void FlutterELinuxEngine::SendSystemLocales() { // Convert the locale list to the locale pointer list that must be provided. std::vector flutter_locale_list; flutter_locale_list.reserve(flutter_locales.size()); - std::transform( - flutter_locales.begin(), flutter_locales.end(), - std::back_inserter(flutter_locale_list), - [](const auto& arg) -> const auto* { return &arg; }); + std::transform(flutter_locales.begin(), flutter_locales.end(), + std::back_inserter(flutter_locale_list), + [](const auto& arg) -> const auto* { return &arg; }); auto result = embedder_api_.UpdateLocales(engine_, flutter_locale_list.data(), flutter_locale_list.size()); if (result != kSuccess) { diff --git a/src/flutter/shell/platform/linux_embedded/plugins/platform_views_plugin.cc b/src/flutter/shell/platform/linux_embedded/plugins/platform_views_plugin.cc index 81b29462..fb2a513e 100644 --- a/src/flutter/shell/platform/linux_embedded/plugins/platform_views_plugin.cc +++ b/src/flutter/shell/platform/linux_embedded/plugins/platform_views_plugin.cc @@ -250,9 +250,8 @@ void PlatformViewsPlugin::PlatformViewsOffset( auto view_id = LookupEncodableMap(arguments, kIdKey); auto view_top = LookupEncodableMap(arguments, kTopKey); auto view_left = LookupEncodableMap(arguments, kLeftKey); - ELINUX_LOG(DEBUG) << "Offset the platform view: " - << "id = " << view_id << ", top = " << view_top - << ", left = " << view_left; + ELINUX_LOG(DEBUG) << "Offset the platform view: " << "id = " << view_id + << ", top = " << view_top << ", left = " << view_left; if (platform_views_.find(view_id) == platform_views_.end()) { result->Error("Couldn't find the view id in the arguments"); return; diff --git a/src/flutter/shell/platform/linux_embedded/surface/context_egl.cc b/src/flutter/shell/platform/linux_embedded/surface/context_egl.cc index ac87ab10..855687c2 100644 --- a/src/flutter/shell/platform/linux_embedded/surface/context_egl.cc +++ b/src/flutter/shell/platform/linux_embedded/surface/context_egl.cc @@ -15,7 +15,7 @@ ContextEgl::ContextEgl(std::unique_ptr environment, : environment_(std::move(environment)), config_(nullptr) { EGLint config_count = 0; const EGLint attribs[] = { - // clang-format off + // clang-format off EGL_SURFACE_TYPE, egl_surface_type, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_RED_SIZE, 8, @@ -27,10 +27,10 @@ ContextEgl::ContextEgl(std::unique_ptr environment, EGL_DEPTH_SIZE, 0, EGL_STENCIL_SIZE, 0, EGL_NONE - // clang-format on + // clang-format on }; const EGLint impeller_config_attributes[] = { - // clang-format off + // clang-format off EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, @@ -42,10 +42,10 @@ ContextEgl::ContextEgl(std::unique_ptr environment, EGL_SAMPLE_BUFFERS, 1, EGL_SAMPLES, 4, EGL_NONE - // clang-format on + // clang-format on }; const EGLint impeller_config_attributes_no_msaa[] = { - // clang-format off + // clang-format off EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, @@ -55,7 +55,7 @@ ContextEgl::ContextEgl(std::unique_ptr environment, EGL_DEPTH_SIZE, 0, EGL_STENCIL_SIZE, 8, EGL_NONE - // clang-format on + // clang-format on }; if (enable_impeller) { @@ -136,8 +136,8 @@ std::unique_ptr ContextEgl::CreateOffscreenSurface( EGLSurface surface = eglCreatePbufferSurface(environment_->Display(), config_, attribs); if (surface == EGL_NO_SURFACE) { - ELINUX_LOG(WARNING) << "Failed to create EGL off-screen surface." - << "(" << get_egl_error_cause() << ")"; + ELINUX_LOG(WARNING) << "Failed to create EGL off-screen surface." << "(" + << get_egl_error_cause() << ")"; } #else // eglCreatePbufferSurface isn't supported on both Wayland and GBM. @@ -146,8 +146,8 @@ std::unique_ptr ContextEgl::CreateOffscreenSurface( EGLSurface surface = eglCreateWindowSurface( environment_->Display(), config_, window->WindowOffscreen(), attribs); if (surface == EGL_NO_SURFACE) { - ELINUX_LOG(WARNING) << "Failed to create EGL off-screen surface." - << "(" << get_egl_error_cause() << ")"; + ELINUX_LOG(WARNING) << "Failed to create EGL off-screen surface." << "(" + << get_egl_error_cause() << ")"; } #endif return std::make_unique(surface, environment_->Display(), diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h b/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h index 0bbb883a..fa1fb9e9 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h @@ -228,14 +228,10 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { } // |FlutterWindowBindingHandler| - uint16_t GetRotationDegree() const override { - return current_rotation_; - } + uint16_t GetRotationDegree() const override { return current_rotation_; } // |FlutterWindowBindingHandler| - double GetDpiScale() override { - return current_scale_; - } + double GetDpiScale() override { return current_scale_; } // |FlutterWindowBindingHandler| PhysicalWindowBounds GetPhysicalWindowBounds() override { @@ -243,9 +239,7 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { } // |FlutterWindowBindingHandler| - int32_t GetFrameRate() override { - return 60000; - } + int32_t GetFrameRate() override { return 60000; } // |FlutterWindowBindingHandler| void UpdateFlutterCursor(const std::string& cursor_name) override { @@ -260,9 +254,7 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { } // |FlutterWindowBindingHandler| - std::string GetClipboardData() override { - return clipboard_data_; - } + std::string GetClipboardData() override { return clipboard_data_; } // |FlutterWindowBindingHandler| void SetClipboardData(const std::string& data) override { diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc index 5bd8e0c2..6467bf94 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc @@ -697,11 +697,11 @@ const wl_output_listener ELinuxWindowWayland::kWlOutputListener = { self->request_redraw_ = true; } if (self->view_properties_.height > height) { - ELINUX_LOG(WARNING) << "Requested height size(" - << self->view_properties_.height << ") " - << "is larger than display size(" << height - << ")" - ", clipping"; + ELINUX_LOG(WARNING) + << "Requested height size(" << self->view_properties_.height + << ") " << "is larger than display size(" << height + << ")" + ", clipping"; self->view_properties_.height = height; self->request_redraw_ = true; } diff --git a/src/flutter/shell/platform/linux_embedded/window/native_window.h b/src/flutter/shell/platform/linux_embedded/window/native_window.h index a224b79a..57c40362 100644 --- a/src/flutter/shell/platform/linux_embedded/window/native_window.h +++ b/src/flutter/shell/platform/linux_embedded/window/native_window.h @@ -56,7 +56,7 @@ class NativeWindow { // Swaps frame buffers. This API performs processing only for the DRM-GBM // backend. It is prepared to make the interface common. - virtual void SwapBuffers(){/* do nothing. */}; + virtual void SwapBuffers() { /* do nothing. */ }; protected: EGLNativeWindowType window_; From 61b90d507d68b1db2ec891bf06537def68fc3ab8 Mon Sep 17 00:00:00 2001 From: Hidenori Date: Sat, 14 Dec 2024 05:16:58 +0900 Subject: [PATCH 110/112] embedder: merge embedder.h from flutter/engine (#430) Merged from https://github.com/flutter/engine/commits/3.27.0/shell/platform/embedder/embedder.h Signed-off-by: Hidenori Matsubayashi --- .../shell/platform/embedder/embedder.h | 273 +++++++++++++++--- 1 file changed, 232 insertions(+), 41 deletions(-) diff --git a/src/flutter/shell/platform/embedder/embedder.h b/src/flutter/shell/platform/embedder/embedder.h index d26e2215..9e9b875a 100644 --- a/src/flutter/shell/platform/embedder/embedder.h +++ b/src/flutter/shell/platform/embedder/embedder.h @@ -162,6 +162,8 @@ typedef enum { kFlutterSemanticsActionMoveCursorBackwardByWord = 1 << 20, /// Replace the current text in the text field. kFlutterSemanticsActionSetText = 1 << 21, + /// Request that the respective focusable widget gain input focus. + kFlutterSemanticsActionFocus = 1 << 22, } FlutterSemanticsAction; /// The set of properties that may be associated with a semantics node. @@ -302,6 +304,9 @@ typedef enum { /// Specifies an OpenGL frame-buffer target type. Framebuffers are specified /// using the FlutterOpenGLFramebuffer struct. kFlutterOpenGLTargetTypeFramebuffer, + /// Specifies an OpenGL on-screen surface target type. Surfaces are specified + /// using the FlutterOpenGLSurface struct. + kFlutterOpenGLTargetTypeSurface, } FlutterOpenGLTargetType; /// A pixel format to be used for software rendering. @@ -385,9 +390,14 @@ typedef struct { } FlutterOpenGLTexture; typedef struct { - /// The target of the color attachment of the frame-buffer. For example, - /// GL_TEXTURE_2D or GL_RENDERBUFFER. In case of ambiguity when dealing with - /// Window bound frame-buffers, 0 may be used. + /// The format of the color attachment of the frame-buffer. For example, + /// GL_RGBA8. + /// + /// In case of ambiguity when dealing with Window bound frame-buffers, 0 may + /// be used. + /// + /// @bug This field is incorrectly named as "target" when it actually + /// refers to a format. uint32_t target; /// The name of the framebuffer. @@ -401,6 +411,62 @@ typedef struct { VoidCallback destruction_callback; } FlutterOpenGLFramebuffer; +typedef bool (*FlutterOpenGLSurfaceCallback)(void* /* user data */, + bool* /* opengl state changed */); + +typedef struct { + /// The size of this struct. Must be sizeof(FlutterOpenGLSurface). + size_t struct_size; + + /// User data to be passed to the make_current, clear_current and + /// destruction callbacks. + void* user_data; + + /// Callback invoked (on an engine-managed thread) that asks the embedder to + /// make the surface current. + /// + /// Should return true if the operation succeeded, false if the surface could + /// not be made current and rendering should be cancelled. + /// + /// The second parameter 'opengl state changed' should be set to true if + /// any OpenGL API state is different than before this callback was called. + /// In that case, Flutter will invalidate the internal OpenGL API state cache, + /// which is a somewhat expensive operation. + /// + /// @attention required. (non-null) + FlutterOpenGLSurfaceCallback make_current_callback; + + /// Callback invoked (on an engine-managed thread) when the current surface + /// can be cleared. + /// + /// Should return true if the operation succeeded, false if an error ocurred. + /// That error will be logged but otherwise not handled by the engine. + /// + /// The second parameter 'opengl state changed' is the same as with the + /// @ref make_current_callback. + /// + /// The embedder might clear the surface here after it was previously made + /// current. That's not required however, it's also possible to clear it in + /// the destruction callback. There's no way to signal OpenGL state + /// changes in the destruction callback though. + /// + /// @attention required. (non-null) + FlutterOpenGLSurfaceCallback clear_current_callback; + + /// Callback invoked (on an engine-managed thread) that asks the embedder to + /// collect the surface. + /// + /// @attention required. (non-null) + VoidCallback destruction_callback; + + /// The surface format. + /// + /// Allowed values: + /// - GL_RGBA8 + /// - GL_BGRA8_EXT + uint32_t format; +} FlutterOpenGLSurface; + typedef bool (*BoolCallback)(void* /* user data */); typedef FlutterTransformation (*TransformationCallback)(void* /* user data */); typedef uint32_t (*UIntCallback)(void* /* user data */); @@ -831,6 +897,86 @@ typedef struct { }; } FlutterRendererConfig; +/// Display refers to a graphics hardware system consisting of a framebuffer, +/// typically a monitor or a screen. This ID is unique per display and is +/// stable until the Flutter application restarts. +typedef uint64_t FlutterEngineDisplayId; + +typedef struct { + /// The size of this struct. Must be sizeof(FlutterWindowMetricsEvent). + size_t struct_size; + /// Physical width of the window. + size_t width; + /// Physical height of the window. + size_t height; + /// Scale factor for the physical screen. + double pixel_ratio; + /// Horizontal physical location of the left side of the window on the screen. + size_t left; + /// Vertical physical location of the top of the window on the screen. + size_t top; + /// Top inset of window. + double physical_view_inset_top; + /// Right inset of window. + double physical_view_inset_right; + /// Bottom inset of window. + double physical_view_inset_bottom; + /// Left inset of window. + double physical_view_inset_left; + /// The identifier of the display the view is rendering on. + FlutterEngineDisplayId display_id; + /// The view that this event is describing. + int64_t view_id; +} FlutterWindowMetricsEvent; + +typedef struct { + /// The size of this struct. + /// Must be sizeof(FlutterAddViewResult). + size_t struct_size; + + /// True if the add view operation succeeded. + bool added; + + /// The |FlutterAddViewInfo.user_data|. + void* user_data; +} FlutterAddViewResult; + +/// The callback invoked by the engine when the engine has attempted to add a +/// view. +/// +/// The |FlutterAddViewResult| is only guaranteed to be valid during this +/// callback. +typedef void (*FlutterAddViewCallback)(const FlutterAddViewResult* result); + +typedef struct { + /// The size of this struct. + /// Must be sizeof(FlutterAddViewInfo). + size_t struct_size; + + /// The identifier for the view to add. This must be unique. + FlutterViewId view_id; + + /// The view's properties. + /// + /// The metric's |view_id| must match this struct's |view_id|. + const FlutterWindowMetricsEvent* view_metrics; + + /// A baton that is not interpreted by the engine in any way. It will be given + /// back to the embedder in |add_view_callback|. Embedder resources may be + /// associated with this baton. + void* user_data; + + /// Called once the engine has attempted to add the view. This callback is + /// required. + /// + /// The embedder/app must not use the view until the callback is invoked with + /// an `added` value of `true`. + /// + /// This callback is invoked on an internal engine managed thread. Embedders + /// must re-thread if necessary. + FlutterAddViewCallback add_view_callback; +} FlutterAddViewInfo; + typedef struct { /// The size of this struct. /// Must be sizeof(FlutterRemoveViewResult). @@ -846,7 +992,8 @@ typedef struct { /// The callback invoked by the engine when the engine has attempted to remove /// a view. /// -/// The |FlutterRemoveViewResult| will be deallocated once the callback returns. +/// The |FlutterRemoveViewResult| is only guaranteed to be valid during this +/// callback. typedef void (*FlutterRemoveViewCallback)( const FlutterRemoveViewResult* /* result */); @@ -878,38 +1025,6 @@ typedef struct { FlutterRemoveViewCallback remove_view_callback; } FlutterRemoveViewInfo; -/// Display refers to a graphics hardware system consisting of a framebuffer, -/// typically a monitor or a screen. This ID is unique per display and is -/// stable until the Flutter application restarts. -typedef uint64_t FlutterEngineDisplayId; - -typedef struct { - /// The size of this struct. Must be sizeof(FlutterWindowMetricsEvent). - size_t struct_size; - /// Physical width of the window. - size_t width; - /// Physical height of the window. - size_t height; - /// Scale factor for the physical screen. - double pixel_ratio; - /// Horizontal physical location of the left side of the window on the screen. - size_t left; - /// Vertical physical location of the top of the window on the screen. - size_t top; - /// Top inset of window. - double physical_view_inset_top; - /// Right inset of window. - double physical_view_inset_right; - /// Bottom inset of window. - double physical_view_inset_bottom; - /// Left inset of window. - double physical_view_inset_left; - /// The identifier of the display the view is rendering on. - FlutterEngineDisplayId display_id; - /// The view that this event is describing. - int64_t view_id; -} FlutterWindowMetricsEvent; - /// The phase of the pointer event. typedef enum { kCancel, @@ -1482,7 +1597,7 @@ typedef void (*FlutterUpdateSemanticsCallback2)( /// An update to whether a message channel has a listener set or not. typedef struct { - // The size of the struct. Must be sizeof(FlutterChannelUpdate). + /// The size of the struct. Must be sizeof(FlutterChannelUpdate). size_t struct_size; /// The name of the channel. const char* channel; @@ -1563,6 +1678,9 @@ typedef struct { /// A framebuffer for Flutter to render into. The embedder must ensure that /// the framebuffer is complete. FlutterOpenGLFramebuffer framebuffer; + /// A surface for Flutter to render into. Basically a wrapper around + /// a closure that'll be called when the surface should be made current. + FlutterOpenGLSurface surface; }; } FlutterOpenGLBackingStore; @@ -1584,6 +1702,7 @@ typedef struct { } FlutterSoftwareBackingStore; typedef struct { + /// The size of this struct. Must be sizeof(FlutterSoftwareBackingStore2). size_t struct_size; /// A pointer to the raw bytes of the allocation described by this software /// backing store. @@ -1731,6 +1850,9 @@ typedef struct { size_t struct_size; /// The size of the render target the engine expects to render into. FlutterSize size; + /// The identifier for the view that the engine will use this backing store to + /// render into. + FlutterViewId view_id; } FlutterBackingStoreConfig; typedef enum { @@ -1754,6 +1876,7 @@ typedef struct { /// Contains additional information about the backing store provided /// during presentation to the embedder. typedef struct { + /// The size of this struct. Must be sizeof(FlutterBackingStorePresentInfo). size_t struct_size; /// The area of the backing store that contains Flutter contents. Pixels @@ -1844,18 +1967,26 @@ typedef struct { /// `FlutterBackingStore::struct_size` when specifying a new backing store to /// the engine. This only matters if the embedder expects to be used with /// engines older than the version whose headers it used during compilation. + /// + /// The callback should return true if the operation was successful. FlutterBackingStoreCreateCallback create_backing_store_callback; /// A callback invoked by the engine to release the backing store. The /// embedder may collect any resources associated with the backing store. + /// + /// The callback should return true if the operation was successful. FlutterBackingStoreCollectCallback collect_backing_store_callback; /// Callback invoked by the engine to composite the contents of each layer /// onto the implicit view. /// - /// DEPRECATED: Use |present_view_callback| to support multiple views. + /// DEPRECATED: Use `present_view_callback` to support multiple views. + /// If this callback is provided, `FlutterEngineAddView` and + /// `FlutterEngineRemoveView` should not be used. /// /// Only one of `present_layers_callback` and `present_view_callback` may be /// provided. Providing both is an error and engine initialization will /// terminate. + /// + /// The callback should return true if the operation was successful. FlutterLayersPresentCallback present_layers_callback; /// Avoid caching backing stores provided by this compositor. bool avoid_backing_store_cache; @@ -1865,6 +1996,8 @@ typedef struct { /// Only one of `present_layers_callback` and `present_view_callback` may be /// provided. Providing both is an error and engine initialization will /// terminate. + /// + /// The callback should return true if the operation was successful. FlutterPresentViewCallback present_view_callback; } FlutterCompositor; @@ -1905,7 +2038,7 @@ typedef const FlutterLocale* (*FlutterComputePlatformResolvedLocaleCallback)( size_t /* Number of locales*/); typedef struct { - /// This size of this struct. Must be sizeof(FlutterDisplay). + /// The size of this struct. Must be sizeof(FlutterEngineDisplay). size_t struct_size; FlutterEngineDisplayId display_id; @@ -2175,6 +2308,10 @@ typedef struct { /// `update_semantics_callback`, and /// `update_semantics_callback2` may be provided; the others /// should be set to null. + /// + /// This callback is incompatible with multiple views. If this + /// callback is provided, `FlutterEngineAddView` and + /// `FlutterEngineRemoveView` should not be used. FlutterUpdateSemanticsNodeCallback update_semantics_node_callback; /// The legacy callback invoked by the engine in order to give the embedder /// the chance to respond to updates to semantics custom actions from the Dart @@ -2191,6 +2328,10 @@ typedef struct { /// `update_semantics_callback`, and /// `update_semantics_callback2` may be provided; the others /// should be set to null. + /// + /// This callback is incompatible with multiple views. If this + /// callback is provided, `FlutterEngineAddView` and + /// `FlutterEngineRemoveView` should not be used. FlutterUpdateSemanticsCustomActionCallback update_semantics_custom_action_callback; /// Path to a directory used to store data that is cached across runs of a @@ -2340,6 +2481,10 @@ typedef struct { /// `update_semantics_callback`, and /// `update_semantics_callback2` may be provided; the others /// must be set to null. + /// + /// This callback is incompatible with multiple views. If this + /// callback is provided, `FlutterEngineAddView` and + /// `FlutterEngineRemoveView` should not be used. FlutterUpdateSemanticsCallback update_semantics_callback; /// The callback invoked by the engine in order to give the embedder the @@ -2505,12 +2650,50 @@ FLUTTER_EXPORT FlutterEngineResult FlutterEngineRunInitialized( FLUTTER_API_SYMBOL(FlutterEngine) engine); +//------------------------------------------------------------------------------ +/// @brief Adds a view. +/// +/// This is an asynchronous operation. The view should not be used +/// until the |info.add_view_callback| is invoked with an |added| +/// value of true. The embedder should prepare resources in advance +/// but be ready to clean up on failure. +/// +/// A frame is scheduled if the operation succeeds. +/// +/// The callback is invoked on a thread managed by the engine. The +/// embedder should re-thread if needed. +/// +/// Attempting to add the implicit view will fail and will return +/// kInvalidArguments. Attempting to add a view with an already +/// existing view ID will fail, and |info.add_view_callback| will be +/// invoked with an |added| value of false. +/// +/// @param[in] engine A running engine instance. +/// @param[in] info The add view arguments. This can be deallocated +/// once |FlutterEngineAddView| returns, before +/// |add_view_callback| is invoked. +/// +/// @return The result of *starting* the asynchronous operation. If +/// `kSuccess`, the |add_view_callback| will be invoked. +FLUTTER_EXPORT +FlutterEngineResult FlutterEngineAddView(FLUTTER_API_SYMBOL(FlutterEngine) + engine, + const FlutterAddViewInfo* info); + //------------------------------------------------------------------------------ /// @brief Removes a view. /// /// This is an asynchronous operation. The view's resources must not -/// be cleaned up until the |remove_view_callback| is invoked with -/// a |removed| value of `true`. +/// be cleaned up until |info.remove_view_callback| is invoked with +/// a |removed| value of true. +/// +/// The callback is invoked on a thread managed by the engine. The +/// embedder should re-thread if needed. +/// +/// Attempting to remove the implicit view will fail and will return +/// kInvalidArguments. Attempting to remove a view with a +/// non-existent view ID will fail, and |info.remove_view_callback| +/// will be invoked with a |removed| value of false. /// /// @param[in] engine A running engine instance. /// @param[in] info The remove view arguments. This can be deallocated @@ -3194,6 +3377,12 @@ typedef FlutterEngineResult (*FlutterEngineSetNextFrameCallbackFnPtr)( FLUTTER_API_SYMBOL(FlutterEngine) engine, VoidCallback callback, void* user_data); +typedef FlutterEngineResult (*FlutterEngineAddViewFnPtr)( + FLUTTER_API_SYMBOL(FlutterEngine) engine, + const FlutterAddViewInfo* info); +typedef FlutterEngineResult (*FlutterEngineRemoveViewFnPtr)( + FLUTTER_API_SYMBOL(FlutterEngine) engine, + const FlutterRemoveViewInfo* info); /// Function-pointer-based versions of the APIs above. typedef struct { @@ -3240,6 +3429,8 @@ typedef struct { FlutterEngineNotifyDisplayUpdateFnPtr NotifyDisplayUpdate; FlutterEngineScheduleFrameFnPtr ScheduleFrame; FlutterEngineSetNextFrameCallbackFnPtr SetNextFrameCallback; + FlutterEngineAddViewFnPtr AddView; + FlutterEngineRemoveViewFnPtr RemoveView; } FlutterEngineProcTable; //------------------------------------------------------------------------------ From 4e74babc7d46fcd5614b1b4ca7e5a1519c430c06 Mon Sep 17 00:00:00 2001 From: Luke Howard Date: Mon, 10 Feb 2025 20:37:40 +1100 Subject: [PATCH 111/112] Mark FlutterELinuxEngine, FlutterELinuxView and FlutterELinuxTextureRegistrar as unsafe references for importing into Swift, consolidating Swift annotation macro wrappers into flutter_export.h. This patch allows the importing of C++ engine APIs into Swift, using the Swift C++ bridging layer. Signed-off-by: Luke Howard --- .../client_wrapper/include/flutter/texture_registrar.h | 2 +- .../shell/platform/common/public/flutter_export.h | 9 +++++++++ .../shell/platform/common/public/flutter_messenger.h | 8 ++++---- .../platform/common/public/flutter_plugin_registrar.h | 2 +- .../platform/linux_embedded/flutter_elinux_engine.h | 6 ++++-- .../shell/platform/linux_embedded/flutter_elinux_state.h | 6 ------ .../linux_embedded/flutter_elinux_texture_registrar.h | 2 +- .../shell/platform/linux_embedded/flutter_elinux_view.h | 2 +- .../platform/linux_embedded/public/flutter_elinux.h | 4 ++-- 9 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/flutter/shell/platform/common/client_wrapper/include/flutter/texture_registrar.h b/src/flutter/shell/platform/common/client_wrapper/include/flutter/texture_registrar.h index 9b13025f..43f1147c 100644 --- a/src/flutter/shell/platform/common/client_wrapper/include/flutter/texture_registrar.h +++ b/src/flutter/shell/platform/common/client_wrapper/include/flutter/texture_registrar.h @@ -136,7 +136,7 @@ class TextureRegistrar { // Unregisters an existing texture object. // DEPRECATED: Use UnregisterTexture(texture_id, optional_callback) instead. virtual bool UnregisterTexture(int64_t texture_id) = 0; -}; +} SWIFT_UNSAFE_REFERENCE; } // namespace flutter diff --git a/src/flutter/shell/platform/common/public/flutter_export.h b/src/flutter/shell/platform/common/public/flutter_export.h index 38cac85b..5fe8c593 100644 --- a/src/flutter/shell/platform/common/public/flutter_export.h +++ b/src/flutter/shell/platform/common/public/flutter_export.h @@ -25,4 +25,13 @@ #endif // FLUTTER_DESKTOP_LIBRARY +#if __has_include() +#include +#else +#define SWIFT_UNSAFE_REFERENCE +#define SWIFT_SHARED_REFERENCE(_retain, _release) +#define SWIFT_RETURNS_RETAINED +#define SWIFT_RETURNS_UNRETAINED +#endif + #endif // FLUTTER_SHELL_PLATFORM_COMMON_PUBLIC_FLUTTER_EXPORT_H_ diff --git a/src/flutter/shell/platform/common/public/flutter_messenger.h b/src/flutter/shell/platform/common/public/flutter_messenger.h index bb182cdf..d06385ca 100644 --- a/src/flutter/shell/platform/common/public/flutter_messenger.h +++ b/src/flutter/shell/platform/common/public/flutter_messenger.h @@ -93,8 +93,8 @@ FLUTTER_EXPORT void FlutterDesktopMessengerSetCallback( // Operation is thread-safe. // // See also: |FlutterDesktopMessengerRelease| -FLUTTER_EXPORT FlutterDesktopMessengerRef -FlutterDesktopMessengerAddRef(FlutterDesktopMessengerRef messenger); +FLUTTER_EXPORT FlutterDesktopMessengerRef FlutterDesktopMessengerAddRef( + FlutterDesktopMessengerRef messenger) SWIFT_RETURNS_RETAINED; // Decrements the reference count for the |messenger|. // @@ -124,8 +124,8 @@ FLUTTER_EXPORT bool FlutterDesktopMessengerIsAvailable( // Returns the |messenger| value. // // See also: |FlutterDesktopMessengerUnlock| -FLUTTER_EXPORT FlutterDesktopMessengerRef -FlutterDesktopMessengerLock(FlutterDesktopMessengerRef messenger); +FLUTTER_EXPORT FlutterDesktopMessengerRef FlutterDesktopMessengerLock( + FlutterDesktopMessengerRef messenger) SWIFT_RETURNS_UNRETAINED; // Unlocks the `FlutterDesktopMessengerRef`. // diff --git a/src/flutter/shell/platform/common/public/flutter_plugin_registrar.h b/src/flutter/shell/platform/common/public/flutter_plugin_registrar.h index b0847069..23a13b6d 100644 --- a/src/flutter/shell/platform/common/public/flutter_plugin_registrar.h +++ b/src/flutter/shell/platform/common/public/flutter_plugin_registrar.h @@ -26,7 +26,7 @@ typedef void (*FlutterDesktopOnPluginRegistrarDestroyed)( // Returns the engine messenger associated with this registrar. FLUTTER_EXPORT FlutterDesktopMessengerRef FlutterDesktopPluginRegistrarGetMessenger( - FlutterDesktopPluginRegistrarRef registrar); + FlutterDesktopPluginRegistrarRef registrar) SWIFT_RETURNS_UNRETAINED; // Returns the texture registrar associated with this registrar. FLUTTER_EXPORT FlutterDesktopTextureRegistrarRef diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h index 4bcc7f10..c7eeee4d 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h @@ -71,7 +71,9 @@ class FlutterELinuxEngine { // Sets switches member to the given switches. void SetSwitches(const std::vector& switches); - FlutterDesktopMessengerRef messenger() { return messenger_.get(); } + FlutterDesktopMessengerRef messenger() SWIFT_RETURNS_UNRETAINED { + return messenger_.get(); + } IncomingMessageDispatcher* message_dispatcher() { return message_dispatcher_.get(); @@ -195,7 +197,7 @@ class FlutterELinuxEngine { std::unique_ptr vsync_waiter_; bool enable_impeller_ = false; -}; +} SWIFT_UNSAFE_REFERENCE; } // namespace flutter diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_state.h b/src/flutter/shell/platform/linux_embedded/flutter_elinux_state.h index aea43c4c..061f1e87 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_state.h +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_state.h @@ -9,12 +9,6 @@ #include #include -#if __has_include() -#include -#else -#define SWIFT_SHARED_REFERENCE(_retain, _release) -#endif - #include "flutter/shell/platform/common/client_wrapper/include/flutter/plugin_registrar.h" #include "flutter/shell/platform/common/incoming_message_dispatcher.h" #include "flutter/shell/platform/embedder/embedder.h" diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_texture_registrar.h b/src/flutter/shell/platform/linux_embedded/flutter_elinux_texture_registrar.h index 8770ad57..6e75cb00 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_texture_registrar.h +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_texture_registrar.h @@ -56,7 +56,7 @@ class FlutterELinuxTextureRegistrar { std::mutex map_mutex_; int64_t EmplaceTexture(std::unique_ptr texture); -}; +} SWIFT_UNSAFE_REFERENCE; }; // namespace flutter diff --git a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.h b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.h index 08740eff..0d6ed8d5 100644 --- a/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.h +++ b/src/flutter/shell/platform/linux_embedded/flutter_elinux_view.h @@ -318,7 +318,7 @@ class FlutterELinuxView : public WindowBindingHandlerDelegate { // Current view rotation (FlutterTransformation). FlutterTransformation view_rotation_transformation_ = { 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0}; -}; +} SWIFT_UNSAFE_REFERENCE; } // namespace flutter diff --git a/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h b/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h index 2597aa47..eacb5269 100644 --- a/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h +++ b/src/flutter/shell/platform/linux_embedded/public/flutter_elinux.h @@ -216,8 +216,8 @@ FLUTTER_EXPORT FlutterDesktopViewRef FlutterDesktopPluginRegistrarGetView( FlutterDesktopPluginRegistrarRef registrar); // Returns the messenger associated with the engine. -FLUTTER_EXPORT FlutterDesktopMessengerRef -FlutterDesktopEngineGetMessenger(FlutterDesktopEngineRef engine); +FLUTTER_EXPORT FlutterDesktopMessengerRef FlutterDesktopEngineGetMessenger( + FlutterDesktopEngineRef engine) SWIFT_RETURNS_UNRETAINED; // Returns the texture registrar associated with the engine. FLUTTER_EXPORT FlutterDesktopTextureRegistrarRef From 846588a8cf1e6708fb3a5f39a21e18e32004de7a Mon Sep 17 00:00:00 2001 From: Takahiro Okayama Date: Tue, 18 Mar 2025 11:19:47 +0900 Subject: [PATCH 112/112] Update contributing policy to be the same as flutter-elinux. --- CONTRIBUTING.md | 2 ++ README.md | 7 ------- 2 files changed, 2 insertions(+), 7 deletions(-) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..4f2807de --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,2 @@ +# Contributing to flutter-embedded-linux +Welcome to this project. We welcome all your contribution and feedback. If you've never submitted code before, you must add your (or your organization's) name and contact info to the [AUTHORS](./AUTHORS) file. diff --git a/README.md b/README.md index cd06c6b8..c5c6bd64 100644 --- a/README.md +++ b/README.md @@ -41,10 +41,3 @@ Documentation for this software can be found at [Wiki](https://github.com/sony/f ## Supported platforms This embedder supports x64 and Arm64 (aarch64, ARMv8) architectures on Linux which supports either Wayland backend or DRM backend. See [Support status](https://github.com/sony/flutter-elinux/wiki/Support-status) for details. - -## Contributing -**Now, we cannot accept any Pull Request (PR).** Because We are building a system (e.g. CLA) to accept PRs, so please wait for a while the system is getting ready! However, we are always welcome to report bugs and request new features by creating issues. - -With the assumption, our final goal of this software openly is to be merged this embedder into [Flutter Engine](https://github.com/flutter/engine) after getting feedbacks. And [Google CLA](https://cla.developers.google.com/about/google-corporate) will be required when we do that in the future. Therefore, we cannot easily accept an external PR. However, you can free to create issues for reporting bugs and requesting new features. - -See also: [Contributing to the Flutter engine](https://github.com/flutter/engine/blob/master/CONTRIBUTING.md)