sony / flutter-embedded-linux

Embedded Linux embedding for Flutter
BSD 3-Clause "New" or "Revised" License
1.16k stars 122 forks source link

Turning the display OFF/ON swaps the width and height of the application #410

Closed makotosato-at closed 3 months ago

makotosato-at commented 3 months ago

Hello.

I'm using RPi4 and weston. I use weston as transform=rotate-270 in weston.ini.

In my environment, the following procedure will swap the width and height of the application.

  1. Launch the application -> application_launch
  2. Turn off the display
  3. Turn on the display -> display_turn_off_then_turn_on

Is there any solution to this problem?

I attach the trace logs. application_launch.txt display_turn_off_then_turn_on.txt

-- flutter-elinux 3.19.3 weston 9.0.0 Linux raspberrypi 6.1.21-v8+ #1642 SMP PREEMPT Mon Apr 3 17:24:16 BST 2023 aarch64 GNU/Linux

HidenoriMatsubayashi commented 3 months ago

Questions.

If both are "Yes", this issue depends on only wayland backend of this software.

HidenoriMatsubayashi commented 3 months ago

Also, are you using --fullscreen option?

makotosato-at commented 3 months ago

Thank you for reply.

Does flutter-elinux with X11 work without the issue?

Yes.

Do other wayland apps work?

Yes. (For example, weston-terminal works fine.)

Also, are you using --fullscreen option?

Yes. I use --fullscreen (-f) option.

I tried the following patch and it works.

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 fa147f6..0652954 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<ELinuxWindowWayland*>(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<ELinuxWindowWayland*>(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 2d1343d..dcfe1bb 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_;
HidenoriMatsubayashi commented 3 months ago

Makes sense. Could you please send a PR?

int32t transform = WL_OUTPUT_TRANSFORM_NORMAL;

Can we use current_rotation_ var instead of the creation of transform_?

makotosato-at commented 3 months ago

Can we use currentrotation var instead of the creation of transform_?

Unfortunately no.

current_rotation_ is used in GetRotationDegree()

uint16_t ELinuxWindowWayland::GetRotationDegree() const {
  return current_rotation_;
}

but, the value of output_transform is 0 to 7.

enum wl_output_transform {
    WL_OUTPUT_TRANSFORM_NORMAL = 0,
    WL_OUTPUT_TRANSFORM_90 = 1,
    WL_OUTPUT_TRANSFORM_180 = 2,
    WL_OUTPUT_TRANSFORM_270 = 3,
    WL_OUTPUT_TRANSFORM_FLIPPED = 4,
    WL_OUTPUT_TRANSFORM_FLIPPED_90 = 5,
    WL_OUTPUT_TRANSFORM_FLIPPED_180 = 6,
    WL_OUTPUT_TRANSFORM_FLIPPED_270 = 7,
};
HidenoriMatsubayashi commented 3 months ago

but, the value of output_transform is 0 to 7.

Isn't it sufficient to just convert the value when assigning it to current_rotation_? Also, it feels incorrect because it would result in a discrepancy with the information on the Flutter Engine side.

HidenoriMatsubayashi commented 3 months ago

Apologies, it was a misunderstanding on my part. Your original patch is correct because this involves rotation on the Wayland compositor side, so there's no need to convey this information to the Flutter Engine side.

Can you please send the pull request?

makotosato-at commented 3 months ago

Thank you. I sent a PR.

HidenoriMatsubayashi commented 3 months ago

Closing.