Commit 0535832c authored by Mohamed Heikal's avatar Mohamed Heikal Committed by Commit Bot

[Android] Fix flicker due to delayed attachment of SurfaceView

SurfaceView(s) used by the CompositorSurfaceManagerImpl are normally
attached during the inflation of the CompositorView. Normally that is
before the first draw of the application window happens (in
Activity#OnCreate). However, if the inflation is delayed (if it happens
on a background thread), this means that the SurfaceView is attached
after a draw event has occurred.

At the time of the first attach of a SurfaceView to the view hierarchy
(regardless of the SurfaceView's actual opacity), the window
transparency hint changes (because the window creates a transparent hole
and attaches the SurfaceView to that hole). This may cause older android
versions to destroy the window and redraw it causing a flicker. This one
line CL sets the window transparency hint early so that when the
SurfaceView gets attached later, the transparency hint need not change
and no flickering occurs.

Also removes misleading comments added earlier when this bug was not understood
well enough.

Bug: 855888,704866
Change-Id: If213b238a708fe1da5fce7808b0ec2e8cec4998a
Reviewed-on: https://chromium-review.googlesource.com/1125288Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Commit-Queue: Mohamed Heikal <mheikal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#572618}
parent 4b347210
...@@ -519,10 +519,7 @@ public abstract class ChromeActivity extends AsyncInitializationActivity ...@@ -519,10 +519,7 @@ public abstract class ChromeActivity extends AsyncInitializationActivity
// If the UI was inflated on a background thread, then the CompositorView may not have been // If the UI was inflated on a background thread, then the CompositorView may not have been
// fully initialized yet as that may require the creation of a handler which is not allowed // fully initialized yet as that may require the creation of a handler which is not allowed
// outside the UI thread. This call should fully initialize the CompositorView if it hasn't // outside the UI thread. This call should fully initialize the CompositorView if it hasn't
// been yet. If inflation was performed on a background thread, this call should be made in // been yet.
// the same Looper call as setting the content view or transferring the view hierarchy, ie.
// before a UI redraw, otherwise some visual artifacts may occur, see
// https://crbug.com/704866
mCompositorViewHolder.setRootView(rootView); mCompositorViewHolder.setRootView(rootView);
// Setting fitsSystemWindows to false ensures that the root view doesn't consume the // Setting fitsSystemWindows to false ensures that the root view doesn't consume the
......
...@@ -10,6 +10,7 @@ import android.app.PendingIntent; ...@@ -10,6 +10,7 @@ import android.app.PendingIntent;
import android.content.Intent; import android.content.Intent;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.PixelFormat;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
...@@ -271,6 +272,15 @@ public class WebappActivity extends SingleTabActivity { ...@@ -271,6 +272,15 @@ public class WebappActivity extends SingleTabActivity {
@Override @Override
protected void doLayoutInflation() { protected void doLayoutInflation() {
// Because we delay the layout inflation, the CompositorSurfaceManager and its
// SurfaceView(s) are created and attached late (ie after the first draw). At the time of
// the first attach of a SurfaceView to the view hierarchy (regardless of the SurfaceView's
// actual opacity), the window transparency hint changes (because the window creates a
// transparent hole and attaches the SurfaceView to that hole). This may cause older android
// versions to destroy the window and redraw it causing a flicker. This line sets the window
// transparency hint early so that when the SurfaceView gets attached later, the
// transparency hint need not change and no flickering occurs.
getWindow().setFormat(PixelFormat.TRANSLUCENT);
// No need to inflate layout synchronously since splash screen is displayed. // No need to inflate layout synchronously since splash screen is displayed.
new Thread() { new Thread() {
@Override @Override
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment