Commit e278a03e authored by Bo Liu's avatar Bo Liu Committed by Commit Bot

weblayer: Set compositor background wrt dark mode

Set the background color on ContentViewRenderView according to the dark
mode, ie set it to black if dark mode is enabled.

Then also set the same background on the compositor which is the the
part that actually appears to make a difference visually.

This is meant to be merged back to 86.

Bug: 1127873
Change-Id: Ifcb9fa47af1e578b963f3f47ba5dc2b8252b80b8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2412189
Commit-Queue: Bo <boliu@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#807122}
parent 08799226
...@@ -144,6 +144,13 @@ ContentViewRenderView::GetResourceManager(JNIEnv* env) { ...@@ -144,6 +144,13 @@ ContentViewRenderView::GetResourceManager(JNIEnv* env) {
return compositor_->GetResourceManager().GetJavaObject(); return compositor_->GetResourceManager().GetJavaObject();
} }
void ContentViewRenderView::UpdateBackgroundColor(JNIEnv* env) {
if (!compositor_)
return;
compositor_->SetBackgroundColor(
Java_ContentViewRenderView_getBackgroundColor(env, java_obj_));
}
void ContentViewRenderView::UpdateLayerTreeHost() { void ContentViewRenderView::UpdateLayerTreeHost() {
// TODO(wkorman): Rename Layout to UpdateLayerTreeHost in all Android // TODO(wkorman): Rename Layout to UpdateLayerTreeHost in all Android
// Compositor related classes. // Compositor related classes.
...@@ -179,6 +186,7 @@ void ContentViewRenderView::InitCompositor() { ...@@ -179,6 +186,7 @@ void ContentViewRenderView::InitCompositor() {
cc::ElementId(root_container_layer_->id())); cc::ElementId(root_container_layer_->id()));
root_container_layer_->SetIsDrawable(false); root_container_layer_->SetIsDrawable(false);
compositor_->SetRootLayer(root_container_layer_); compositor_->SetRootLayer(root_container_layer_);
UpdateBackgroundColor(base::android::AttachCurrentThread());
} }
} // namespace weblayer } // namespace weblayer
...@@ -62,6 +62,7 @@ class ContentViewRenderView : public content::CompositorClient { ...@@ -62,6 +62,7 @@ class ContentViewRenderView : public content::CompositorClient {
void SetNeedsRedraw(JNIEnv* env); void SetNeedsRedraw(JNIEnv* env);
void EvictCachedSurface(JNIEnv* env); void EvictCachedSurface(JNIEnv* env);
base::android::ScopedJavaLocalRef<jobject> GetResourceManager(JNIEnv* env); base::android::ScopedJavaLocalRef<jobject> GetResourceManager(JNIEnv* env);
void UpdateBackgroundColor(JNIEnv* env);
// CompositorClient implementation // CompositorClient implementation
void UpdateLayerTreeHost() override; void UpdateLayerTreeHost() override;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package org.chromium.weblayer_private; package org.chromium.weblayer_private;
import android.content.Context; import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.PixelFormat; import android.graphics.PixelFormat;
import android.graphics.Rect; import android.graphics.Rect;
...@@ -633,7 +634,6 @@ public class ContentViewRenderView extends RelativeLayout { ...@@ -633,7 +634,6 @@ public class ContentViewRenderView extends RelativeLayout {
mSurfaceParent = new SurfaceParent(context); mSurfaceParent = new SurfaceParent(context);
addView(mSurfaceParent, addView(mSurfaceParent,
new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
setBackgroundColor(Color.WHITE);
mInsetObserverView = InsetObserverView.create(context); mInsetObserverView = InsetObserverView.create(context);
addView(mInsetObserverView); addView(mInsetObserverView);
...@@ -670,6 +670,7 @@ public class ContentViewRenderView extends RelativeLayout { ...@@ -670,6 +670,7 @@ public class ContentViewRenderView extends RelativeLayout {
} }
}; };
mWindowAndroid.getDisplay().addObserver(mDisplayAndroidObserver); mWindowAndroid.getDisplay().addObserver(mDisplayAndroidObserver);
updateBackgroundColor();
} }
public void requestMode(@Mode int mode, ValueCallback<Boolean> callback) { public void requestMode(@Mode int mode, ValueCallback<Boolean> callback) {
...@@ -742,6 +743,12 @@ public class ContentViewRenderView extends RelativeLayout { ...@@ -742,6 +743,12 @@ public class ContentViewRenderView extends RelativeLayout {
} }
} }
@Override
protected void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
updateBackgroundColor();
}
/** /**
* Sets the background color of the surface / texture view. This method is necessary because * Sets the background color of the surface / texture view. This method is necessary because
* the background color of ContentViewRenderView itself is covered by the background of * the background color of ContentViewRenderView itself is covered by the background of
...@@ -758,6 +765,7 @@ public class ContentViewRenderView extends RelativeLayout { ...@@ -758,6 +765,7 @@ public class ContentViewRenderView extends RelativeLayout {
if (mCurrent != null) { if (mCurrent != null) {
mCurrent.setBackgroundColor(color); mCurrent.setBackgroundColor(color);
} }
ContentViewRenderViewJni.get().updateBackgroundColor(mNativeContentViewRenderView);
} }
public InsetObserverView getInsetObserverView() { public InsetObserverView getInsetObserverView() {
...@@ -838,6 +846,18 @@ public class ContentViewRenderView extends RelativeLayout { ...@@ -838,6 +846,18 @@ public class ContentViewRenderView extends RelativeLayout {
return mNativeContentViewRenderView; return mNativeContentViewRenderView;
} }
private void updateBackgroundColor() {
int uiMode = getContext().getResources().getConfiguration().uiMode;
boolean darkThemeEnabled =
(uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES;
setBackgroundColor(darkThemeEnabled ? Color.BLACK : Color.WHITE);
}
@CalledByNative
private int getBackgroundColor() {
return mBackgroundColor;
}
private boolean shouldAvoidSurfaceResizeForSoftKeyboard() { private boolean shouldAvoidSurfaceResizeForSoftKeyboard() {
// TextureView is more common with embedding use cases that should lead to resize. // TextureView is more common with embedding use cases that should lead to resize.
boolean usingSurfaceView = mCurrent != null && mCurrent.getMode() == MODE_SURFACE_VIEW; boolean usingSurfaceView = mCurrent != null && mCurrent.getMode() == MODE_SURFACE_VIEW;
...@@ -877,5 +897,6 @@ public class ContentViewRenderView extends RelativeLayout { ...@@ -877,5 +897,6 @@ public class ContentViewRenderView extends RelativeLayout {
void setNeedsRedraw(long nativeContentViewRenderView); void setNeedsRedraw(long nativeContentViewRenderView);
void evictCachedSurface(long nativeContentViewRenderView); void evictCachedSurface(long nativeContentViewRenderView);
ResourceManager getResourceManager(long nativeContentViewRenderView); ResourceManager getResourceManager(long nativeContentViewRenderView);
void updateBackgroundColor(long nativeContentViewRenderView);
} }
} }
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