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

Fixes #2854 Queue setview calls until the surface is ready #2865

Merged
merged 1 commit into from
Feb 25, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public class WindowWidget extends UIWidget implements SessionChangeListener,
private PromptDelegate mPromptDelegate;
private Executor mUIThreadExecutor;
private WindowViewModel mViewModel;
private CopyOnWriteArrayList<Runnable> mSetViewQueuedCalls;

public interface WindowListener {
default void onFocusRequest(@NonNull WindowWidget aWindow) {}
Expand All @@ -158,6 +159,8 @@ public WindowWidget(Context aContext, int windowId, Session aSession) {
}

private void initialize(Context aContext) {
mSetViewQueuedCalls = new CopyOnWriteArrayList<>();

mWidgetManager = (WidgetManagerDelegate) aContext;
mBorderWidth = SettingsStore.getInstance(aContext).getTransparentBorderWidth();

Expand Down Expand Up @@ -364,28 +367,40 @@ protected void setRestored(boolean restored) {
}

private void setView(View view, boolean switchSurface) {
if (switchSurface) {
pauseCompositor();
}

mView = view;
removeView(view);
mView.setVisibility(VISIBLE);
addView(mView);

if (switchSurface) {
mWidgetPlacement.density = getContext().getResources().getDisplayMetrics().density;
if (mTexture != null && mSurface != null && mRenderer == null) {
// Create the UI Renderer for the current surface.
// Surface must be released when switching back to WebView surface or the browser
// will not render it correctly. See release code in unsetView().
mRenderer = new UISurfaceTextureRenderer(mSurface, mWidgetPlacement.textureWidth(), mWidgetPlacement.textureHeight());
Runnable setView = new Runnable() {
@Override
public void run() {
if (switchSurface) {
pauseCompositor();
}

mView = view;
removeView(view);
mView.setVisibility(VISIBLE);
addView(mView);

if (switchSurface) {
mWidgetPlacement.density = getContext().getResources().getDisplayMetrics().density;
if (mTexture != null && mSurface != null && mRenderer == null) {
// Create the UI Renderer for the current surface.
// Surface must be released when switching back to WebView surface or the browser
// will not render it correctly. See release code in unsetView().
mRenderer = new UISurfaceTextureRenderer(mSurface, mWidgetPlacement.textureWidth(), mWidgetPlacement.textureHeight());
}
mWidgetManager.updateWidget(WindowWidget.this);
mWidgetManager.pushWorldBrightness(this, WidgetManagerDelegate.DEFAULT_DIM_BRIGHTNESS);
mWidgetManager.pushBackHandler(mBackHandler);
setWillNotDraw(false);
postInvalidate();
}
}
mWidgetManager.updateWidget(this);
mWidgetManager.pushWorldBrightness(this, WidgetManagerDelegate.DEFAULT_DIM_BRIGHTNESS);
mWidgetManager.pushBackHandler(mBackHandler);
setWillNotDraw(false);
postInvalidate();
};

if (mAfterFirstPaint) {
setView.run();

} else {
mSetViewQueuedCalls.add(setView);
}
}

Expand Down Expand Up @@ -917,6 +932,7 @@ public void releaseWidget() {
cleanListeners(mSession);
GeckoSession session = mSession.getGeckoSession();

mSetViewQueuedCalls.clear();
if (mSession != null) {
mSession.releaseDisplay();
}
Expand Down Expand Up @@ -1562,6 +1578,7 @@ public void onFirstContentfulPaint(@NonNull GeckoSession session) {
mUIThreadExecutor.execute(mFirstDrawCallback);
mFirstDrawCallback = null;
mAfterFirstPaint = true;
mSetViewQueuedCalls.forEach(Runnable::run);
}
}

Expand Down