From 780b79424dc89d160b86b443e38874e7d0b4901c Mon Sep 17 00:00:00 2001 From: Michael Klimushyn Date: Tue, 4 Sep 2018 17:41:59 -0700 Subject: [PATCH] Enable transparent FlutterViews - Changes rasterizer to clear the canvas with `SkColor_TRANSPARENT` - Removes the unused `backgroundColor` param from `FlutterView.java` --- shell/common/rasterizer.cc | 4 ++-- .../android/io/flutter/view/FlutterView.java | 14 ++------------ .../platform/android/platform_view_android_jni.cc | 5 ++--- 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/shell/common/rasterizer.cc b/shell/common/rasterizer.cc index 6f0ddd53a1907..48707f398b147 100644 --- a/shell/common/rasterizer.cc +++ b/shell/common/rasterizer.cc @@ -114,7 +114,7 @@ bool Rasterizer::DrawToSurface(flow::LayerTree& layer_tree) { surface_->GetContext(), canvas, surface_->GetRootTransformation(), true); if (canvas) { - canvas->clear(SK_ColorBLACK); + canvas->clear(SK_ColorTRANSPARENT); } if (compositor_frame && compositor_frame->Raster(layer_tree, false)) { @@ -186,7 +186,7 @@ static sk_sp ScreenshotLayerTreeAsImage( auto frame = compositor_context.AcquireFrame( surface_context, canvas, root_surface_transformation, false); - canvas->clear(SK_ColorBLACK); + canvas->clear(SK_ColorTRANSPARENT); frame->Raster(*tree, true); canvas->flush(); diff --git a/shell/platform/android/io/flutter/view/FlutterView.java b/shell/platform/android/io/flutter/view/FlutterView.java index 33c8c834742be..1fbb14e3b3264 100644 --- a/shell/platform/android/io/flutter/view/FlutterView.java +++ b/shell/platform/android/io/flutter/view/FlutterView.java @@ -131,20 +131,11 @@ public FlutterView(Context context, AttributeSet attrs, FlutterNativeView native } mNativeView.attachViewAndActivity(this, activity); - int color = 0xFF000000; - TypedValue typedValue = new TypedValue(); - context.getTheme().resolveAttribute(android.R.attr.colorBackground, typedValue, true); - if (typedValue.type >= TypedValue.TYPE_FIRST_COLOR_INT && typedValue.type <= TypedValue.TYPE_LAST_COLOR_INT) { - color = typedValue.data; - } - // TODO(abarth): Consider letting the developer override this color. - final int backgroundColor = color; - mSurfaceCallback = new SurfaceHolder.Callback() { @Override public void surfaceCreated(SurfaceHolder holder) { assertAttached(); - nativeSurfaceCreated(mNativeView.get(), holder.getSurface(), backgroundColor); + nativeSurfaceCreated(mNativeView.get(), holder.getSurface()); } @Override @@ -651,8 +642,7 @@ public Bitmap getBitmap() { return nativeGetBitmap(mNativeView.get()); } - private static native void nativeSurfaceCreated(long nativePlatformViewAndroid, Surface surface, - int backgroundColor); + private static native void nativeSurfaceCreated(long nativePlatformViewAndroid, Surface surface); private static native void nativeSurfaceChanged(long nativePlatformViewAndroid, int width, int height); diff --git a/shell/platform/android/platform_view_android_jni.cc b/shell/platform/android/platform_view_android_jni.cc index 315ac0b55bdc0..6dd4b9ab3350a 100644 --- a/shell/platform/android/platform_view_android_jni.cc +++ b/shell/platform/android/platform_view_android_jni.cc @@ -176,8 +176,7 @@ static jstring GetObservatoryUri(JNIEnv* env, jclass clazz) { static void SurfaceCreated(JNIEnv* env, jobject jcaller, jlong shell_holder, - jobject jsurface, - jint backgroundColor) { + jobject jsurface) { // Note: This frame ensures that any local references used by // ANativeWindow_fromSurface are released immediately. This is needed as a // workaround for https://code.google.com/p/android/issues/detail?id=68174 @@ -638,7 +637,7 @@ bool PlatformViewAndroid::Register(JNIEnv* env) { static const JNINativeMethod view_methods[] = { { .name = "nativeSurfaceCreated", - .signature = "(JLandroid/view/Surface;I)V", + .signature = "(JLandroid/view/Surface;)V", .fnPtr = reinterpret_cast(&shell::SurfaceCreated), }, {