Skip to content
This repository has been archived by the owner on Feb 25, 2025. It is now read-only.

Commit

Permalink
Enable transparent FlutterViews (#6163)
Browse files Browse the repository at this point in the history
- Changes rasterizer to clear the canvas with `SkColor_TRANSPARENT`
- Removes the unused `backgroundColor` param from `FlutterView.java`
  • Loading branch information
mklim authored Sep 5, 2018
1 parent 3a7d0b5 commit 0981731
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 17 deletions.
4 changes: 2 additions & 2 deletions shell/common/rasterizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,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)) {
Expand Down Expand Up @@ -191,7 +191,7 @@ static sk_sp<SkData> 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();

Expand Down
14 changes: 2 additions & 12 deletions shell/platform/android/io/flutter/view/FlutterView.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,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
Expand Down Expand Up @@ -634,8 +625,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);

Expand Down
5 changes: 2 additions & 3 deletions shell/platform/android/platform_view_android_jni.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<void*>(&shell::SurfaceCreated),
},
{
Expand Down

0 comments on commit 0981731

Please sign in to comment.