Skip to content

Commit

Permalink
Fixes the issue with the library brightness (#2870)
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed Feb 26, 2020
1 parent ebd4ae9 commit 3664482
Showing 1 changed file with 47 additions and 40 deletions.
Expand Up @@ -367,32 +367,29 @@ protected void setRestored(boolean restored) {
}

private void setView(View view, boolean switchSurface) {
Runnable setView = new Runnable() {
@Override
public void run() {
if (switchSurface) {
pauseCompositor();
}
Runnable setView = () -> {
if (switchSurface) {
pauseCompositor();
}

mView = view;
removeView(view);
mView.setVisibility(VISIBLE);
addView(mView);
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();
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(WindowWidget.this, WidgetManagerDelegate.DEFAULT_DIM_BRIGHTNESS);
mWidgetManager.pushBackHandler(mBackHandler);
setWillNotDraw(false);
postInvalidate();
}
};

Expand All @@ -405,27 +402,36 @@ public void run() {
}

private void unsetView(View view, boolean switchSurface) {
if (mView != null && mView == view) {
mView = null;
removeView(view);
view.setVisibility(GONE);
Runnable unsetView = () -> {
if (mView != null && mView == view) {
mView = null;
removeView(view);
view.setVisibility(GONE);

if (switchSurface) {
setWillNotDraw(true);
if (mTexture != null) {
// Surface must be recreated here when not using layers.
// When using layers the new Surface is received via the setSurface() method.
if (mRenderer != null) {
mRenderer.release();
mRenderer = null;
if (switchSurface) {
setWillNotDraw(true);
if (mTexture != null) {
// Surface must be recreated here when not using layers.
// When using layers the new Surface is received via the setSurface() method.
if (mRenderer != null) {
mRenderer.release();
mRenderer = null;
}
mSurface = new Surface(mTexture);
}
mSurface = new Surface(mTexture);
mWidgetPlacement.density = 1.0f;
mWidgetManager.updateWidget(WindowWidget.this);
mWidgetManager.popWorldBrightness(WindowWidget.this);
mWidgetManager.popBackHandler(mBackHandler);
}
mWidgetPlacement.density = 1.0f;
mWidgetManager.updateWidget(this);
mWidgetManager.popWorldBrightness(this);
mWidgetManager.popBackHandler(mBackHandler);
}
};

if (mAfterFirstPaint) {
unsetView.run();

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

Expand Down Expand Up @@ -1579,6 +1585,7 @@ public void onFirstContentfulPaint(@NonNull GeckoSession session) {
mFirstDrawCallback = null;
mAfterFirstPaint = true;
mSetViewQueuedCalls.forEach(Runnable::run);
mSetViewQueuedCalls.clear();
}
}

Expand Down

0 comments on commit 3664482

Please sign in to comment.