Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flickering occurs since flutter-elinux 3.7.6 #334

Open
makotosato-at opened this issue Mar 8, 2023 · 49 comments
Open

Flickering occurs since flutter-elinux 3.7.6 #334

makotosato-at opened this issue Mar 8, 2023 · 49 comments
Labels
bug Something isn't working engine Topics of Flutter Engine and its artifacts wayland Topics of Wayland

Comments

@makotosato-at
Copy link
Contributor

Hello.

I am using an i.MX8MP board and weston.
Using flutter-elinux 3.7.6 and #333, I get flickering in my application.
(It works fine in version 3.3.10.)

I attached a video:

flickering.mp4

Window size is 1920x1080.
In the application, movie@30fps(color bars) and scrolling text are displayed.
Is there any solution?

It doesn't solve anything, but I tried the following and it worked fine:

--- a/src/flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.cc
+++ b/src/flutter/shell/platform/linux_embedded/surface/elinux_egl_surface.cc
@@ -189,6 +189,7 @@ void ELinuxEGLSurface::PopulateExistingDamage(const intptr_t fbo_id,
       }
     }
   }
+  existing_damage->damage[0] = {0, 0, 1920, 1080};
 }
 
 // Auxiliary function used to transform a FlutterRect into the format that is
@HidenoriMatsubayashi HidenoriMatsubayashi added bug Something isn't working wayland Topics of Wayland labels Mar 8, 2023
@HidenoriMatsubayashi
Copy link
Contributor

Can you share the test source files you used?

@makotosato-at
Copy link
Contributor Author

Thanks for your reply.

I attached a test source.
flickering.zip

@0xkelvin
Copy link

0xkelvin commented Mar 9, 2023

thanks for raising this, we facing same issues, so would like to follow up

@HidenoriMatsubayashi
Copy link
Contributor

Is this issue reproducible on Linux desktop PC? Does it happen on only i.mx8m + weston?

@makotosato-at
Copy link
Contributor Author

For now, only imx8mp + weston.

@HidenoriMatsubayashi
Copy link
Contributor

unfortunately, I cannot reproduce this because I don't have imx8mp board.

Can you please try compiler options below?

@makotosato-at
Copy link
Contributor Author

Thank you.
I tried it, but it did not work.

@HidenoriMatsubayashi
Copy link
Contributor

HidenoriMatsubayashi commented Mar 9, 2023

(It works fine in version 3.3.10.)

Hmm, version 3.7.0 also doesn't work, right? If so, it might depend on flutter/engine.

@HidenoriMatsubayashi
Copy link
Contributor

I found similar issue flutter/flutter#100522

@makotosato-at
Copy link
Contributor Author

Thanks for the information.
I will watch this issue.

@calvinchengx
Copy link

This link to 100522 is impeller related.

Root cause of flickering bug is described here - flutter/flutter#121740

And this line of code is the problem - https://github.com/flutter/engine/blob/4a90fbcd69011f8dd593840a0e901d2cede5398b/flow/layers/display_list_raster_cache_item.cc#L112

There was an attempt to fix this bug here - flutter/engine#39690 - but it created the above chicken-and-egg issue 121740.

The root cause is that picture layers used to declare themselves as able to inherit opacity when they became eligible to cache. The problem is that "eligible to cache" doesn't mean that they will be successful. In particular, we only allow 3 pictures to cache per frame so if there were more than 3 children than all of them might say they can inherit opacity, but only 3 would be telling the truth. The fix requires the children to wait until they successfully cache themselves before they declare that they can inherit opacity. The problem is that if the parent is caching the children then it will tell the children not to cache themselves. This policy prevents double-caching where the parent is caching the children who are also caching themselves. Unfortunately, since the children can never cache themselves, they also never declare that they can inherit opacity. Thus, a chicken and egg situation.

The fix will require some careful decisions about the eligibility and potential eligibility of the children to cache themselves and thus inherit opacity.

@barribarrier
Copy link
Contributor

Same problem.
My app flickers for a few seconds on launch and then stabilizes itself (no more flicker)

x64 linux
Sway: 1.7-1
Flutter-elinux: 3.10.1

@JakeSays
Copy link

JakeSays commented Jul 2, 2023

I'm seeing this same thing, flutter version 3.10.05 and using the X11, wayland, and gbm embedders on both a raspberry pi 3a+, and a radxa zero.

@HidenoriMatsubayashi
Copy link
Contributor

@makotosato-at I suppose this issue will not occur on flutter version 3.10.6 (latest stable version). Can you still observe it? If no, let's close this issue.

@0xkelvin
Copy link

0xkelvin commented Aug 6, 2023

hi @HidenoriMatsubayashi it is still happens on 3.10.6

@HidenoriMatsubayashi
Copy link
Contributor

Hello, Kelvin. Okay, thanks.

@JakeSays
Copy link

JakeSays commented Aug 6, 2023

I was able to resolve the issue by enabling damage tracking. I was building without it initially. There is currently a bug in flutter that breaks the non-damage tracking code path.

@HidenoriMatsubayashi HidenoriMatsubayashi added the engine Topics of Flutter Engine and its artifacts label Aug 7, 2023
@makotosato-at
Copy link
Contributor Author

Hello.
@HidenoriMatsubayashi It still occurs.

@JakeSays How do I enable damage tracking?

@JakeSays
Copy link

JakeSays commented Aug 8, 2023

@makotosato-at there's a cmake option USE_DIRTY_REGION_MANAGEMENT that enables it, but it looks like it's on by default. I don't use cmake for building elinux_flutter and had the feature disabled in my build system.

For reference here is the flutter bug: flutter/flutter#119601

@makotosato-at
Copy link
Contributor Author

@JakeSays Thanks. But in my environment, it occurs even if USE_DIRTY_REGION_MANAGEMENT=OFF.

@HidenoriMatsubayashi HidenoriMatsubayashi changed the title Flickering occurs in flutter-elinux 3.7.6. Flickering occurs since flutter-elinux 3.7.6 Aug 11, 2023
@HidenoriMatsubayashi
Copy link
Contributor

HidenoriMatsubayashi commented Aug 11, 2023

I think this is not the embedder's issue and it depends on flutter/engine (+ H/W). Many developers for mobile have reported similar flicker issues (https://github.com/search?q=repo%3Aflutter%2Fflutter+flicker&type=issues). So, we need to watch flutter/engine updates.

@makotosato-at
Copy link
Contributor Author

Hello.
I don't know why.
But, in my environment, the following patch seems to work fine.

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 07fede8..f4e198a 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,29 +168,6 @@ void ELinuxEGLSurface::PopulateExistingDamage(const intptr_t fbo_id,
       0, 0, static_cast<double>(width_px_), static_cast<double>(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

@HidenoriMatsubayashi
Copy link
Contributor

HidenoriMatsubayashi commented Sep 4, 2023

Good catch!

But, those code are basically copied from engine/examples/glfw_drm/FlutterEmbedderGLFW.cc. What values do eglQuerySurface(display_, surface_, EGL_BUFFER_AGE_EXT, &age) and age return? Also, is GL_EXT_buffer_age extension supported in your board?

  // 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.
  }

@makotosato-at
Copy link
Contributor Author

What values do eglQuerySurface(display_, surface_, EGL_BUFFER_AGE_EXT, &age) and age return? Also, is GL_EXT_buffer_age extension supported in your board?

eglQuerySurface(display_, surface_, EGL_BUFFER_AGE_EXT, &age) returns EGL_TRUE and age is 3.
My board supports EGL_EXT_buffer_age.

@HidenoriMatsubayashi
Copy link
Contributor

Okay, but current code looks good to me. Your patch/#334 (comment) equals full repaint or disable DIRTY_REGION_MANAGEMENT, I think.

@HidenoriMatsubayashi
Copy link
Contributor

flutter/flutter#97482 (comment) might be related this flicker issue. We might need to consider 32x32 alignment. And also, I found flutter/flutter#123353.

HidenoriMatsubayashi added a commit to HidenoriMatsubayashi/flutter-embedded-linux that referenced this issue Sep 21, 2023
HidenoriMatsubayashi added a commit to HidenoriMatsubayashi/flutter-embedded-linux that referenced this issue Sep 21, 2023
HidenoriMatsubayashi added a commit that referenced this issue Sep 21, 2023
@HidenoriMatsubayashi
Copy link
Contributor

HidenoriMatsubayashi commented Sep 21, 2023

@makotosato-at if you have a change to verify #385, that would be great.

@makotosato-at
Copy link
Contributor Author

makotosato-at commented Sep 22, 2023

Hello.

In my environment, this issue does not improve if fbo_reset_after_present = false.

I think, if the following PR is merged, this issue will be improved.
flutter/engine#45611

@HidenoriMatsubayashi
Copy link
Contributor

Okay, thanks. I'll revert #385 later. Let's wait to be merged flutter/engine#45611.

@HidenoriMatsubayashi
Copy link
Contributor

HidenoriMatsubayashi commented Sep 28, 2023

Even if flutter/engine#45611 is merged into master branch, it takes 2-3 months to be propagated to the stable channel. So, I'll temporarily merge @makotosato-at 's change (#334 (comment)) into this repo as a workaround.

HidenoriMatsubayashi added a commit to HidenoriMatsubayashi/flutter-embedded-linux that referenced this issue Sep 28, 2023
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 sony#334 for the detailes.

Signed-off-by: Hidenori Matsubayashi <[email protected]>
HidenoriMatsubayashi added a commit that referenced this issue Sep 29, 2023
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 #334 for the details.

Signed-off-by: Hidenori Matsubayashi <[email protected]>
@HidenoriMatsubayashi
Copy link
Contributor

HidenoriMatsubayashi commented Oct 28, 2023

#388 has been applied in flutter-elinux v3.13.9. Once I confirm flutter/engine#45611 is propagated to the stable channel, I'll revert #388.

@HidenoriMatsubayashi
Copy link
Contributor

Once I confirm flutter/engine#45611 is propagated to the stable channel, I'll revert #388.

The change has been included in flutter 3.16.0. I created #401

@HidenoriMatsubayashi
Copy link
Contributor

@makotosato-at Would it be possible for you to confirm if the issue has been fixed in flutter-3.16.1?

@makotosato-at
Copy link
Contributor Author

Hello.
It works fine!
(Set to USE_DIRTY_REGION_MANAGEMENT=OFF)

@HidenoriMatsubayashi
Copy link
Contributor

(Set to USE_DIRTY_REGION_MANAGEMENT=OFF)

Hm? What do you mean?

@makotosato-at
Copy link
Contributor Author

I built flutter-embedded-linux with the following changes to CMakeLists.txt.
option(USE_DIRTY_REGION_MANAGEMENT "Use Flutter dirty region management" OFF)
Then, using the resulting library, it worked fine.

@HidenoriMatsubayashi
Copy link
Contributor

Sorry for the confusion. Can you please use flutter-elinux 3.16.1 as is?

@HidenoriMatsubayashi
Copy link
Contributor

If that works fine, we can close this issue.

@makotosato-at
Copy link
Contributor Author

Sorry.
I tried 3.16.1 as is, but it did not work...

@HidenoriMatsubayashi
Copy link
Contributor

Really? flutter 3.16.1 has flutter/engine#45611 though...

@makotosato-at
Copy link
Contributor Author

I think that improvements have been made.
Before flutter/engine#45611, it did not work, regardless of whether USE_DIRTY_REGION_MANAGEMENT was ON or OFF.
With flutter/engine#45611, it now works when USE_DIRTY_REGION_MANAGEMENT is OFF.

@HidenoriMatsubayashi
Copy link
Contributor

I see...So, it sounds we need to create a change to disable USE_DIRTY_REGION_MANAGEMENT for now.

HidenoriMatsubayashi added a commit to HidenoriMatsubayashi/flutter-embedded-linux that referenced this issue Dec 12, 2023
This change disables 'dirty-region-management' feature to prevent a fricker issue.
See sony#334 for the details.

Signed-off-by: Hidenori Matsubayashi <[email protected]>
HidenoriMatsubayashi added a commit that referenced this issue Dec 12, 2023
This change disables 'dirty-region-management' feature to prevent a fricker issue.
See #334 for the details.

Signed-off-by: Hidenori Matsubayashi <[email protected]>
@HidenoriMatsubayashi
Copy link
Contributor

For now I made #406 as a workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working engine Topics of Flutter Engine and its artifacts wayland Topics of Wayland
Projects
None yet
Development

No branches or pull requests

6 participants