diff --git a/engine/src/flutter/shell/gpu/gpu_surface_gl.cc b/engine/src/flutter/shell/gpu/gpu_surface_gl.cc index a17cd77753..6181bb8934 100644 --- a/engine/src/flutter/shell/gpu/gpu_surface_gl.cc +++ b/engine/src/flutter/shell/gpu/gpu_surface_gl.cc @@ -90,9 +90,6 @@ bool GPUSurfaceGL::Setup() { context_->setResourceCacheLimits(kMaxGaneshResourceCacheCount, kMaxGaneshResourceCacheBytes); - // Clean up the current context. - delegate_->GLContextClearCurrent(); - return true; } @@ -111,10 +108,6 @@ std::unique_ptr GPUSurfaceGL::AcquireFrame(const SkISize& size) { return nullptr; } - if (!delegate_->GLContextMakeCurrent()) { - return nullptr; - } - auto weak_this = weak_factory_.GetWeakPtr(); GPUSurfaceFrameGL::SubmitCallback submit_callback = @@ -128,8 +121,6 @@ std::unique_ptr GPUSurfaceGL::AcquireFrame(const SkISize& size) { bool GPUSurfaceGL::PresentSurface(SkCanvas* canvas) { if (delegate_ == nullptr || canvas == nullptr) { - delegate_->GLContextClearCurrent(); - return false; } @@ -140,8 +131,6 @@ bool GPUSurfaceGL::PresentSurface(SkCanvas* canvas) { delegate_->GLContextPresent(); - delegate_->GLContextClearCurrent(); - return true; } diff --git a/engine/src/flutter/shell/platform/android/android_context_gl.cc b/engine/src/flutter/shell/platform/android/android_context_gl.cc index 24b889ace0..6472477fd5 100644 --- a/engine/src/flutter/shell/platform/android/android_context_gl.cc +++ b/engine/src/flutter/shell/platform/android/android_context_gl.cc @@ -276,6 +276,8 @@ bool AndroidContextGL::Resize(const SkISize& size) { std::tie(success, surface_) = CreateSurface(environment_->Display(), config_, window_); + MakeCurrent(); + if (!success) { LOG(ERROR) << "Unable to create EGL window surface on resize."; return false; diff --git a/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java b/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java index 27e005f378..bc569ded72 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java @@ -127,13 +127,13 @@ public class FlutterView extends SurfaceView @Override public void surfaceCreated(SurfaceHolder holder) { assert mNativePlatformView != 0; - nativeSurfaceCreated(mNativePlatformView, holder.getSurface()); + nativeSurfaceCreated(mNativePlatformView, holder.getSurface(), backgroundColor); } @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { assert mNativePlatformView != 0; - nativeSurfaceChanged(mNativePlatformView, backgroundColor); + nativeSurfaceChanged(mNativePlatformView, width, height); } @Override @@ -571,8 +571,11 @@ public class FlutterView extends SurfaceView private static native int nativeGetObservatoryPort(); private static native void nativeDetach(long nativePlatformViewAndroid); private static native void nativeSurfaceCreated(long nativePlatformViewAndroid, - Surface surface); - private static native void nativeSurfaceChanged(long nativePlatformViewAndroid, int backgroundColor); + Surface surface, + int backgroundColor); + private static native void nativeSurfaceChanged(long nativePlatformViewAndroid, + int width, + int height); private static native void nativeSurfaceDestroyed(long nativePlatformViewAndroid); private static native Bitmap nativeGetBitmap(long nativePlatformViewAndroid); diff --git a/engine/src/flutter/shell/platform/android/platform_view_android.cc b/engine/src/flutter/shell/platform/android/platform_view_android.cc index 34f8276fd6..30d6048ef8 100644 --- a/engine/src/flutter/shell/platform/android/platform_view_android.cc +++ b/engine/src/flutter/shell/platform/android/platform_view_android.cc @@ -43,7 +43,8 @@ void PlatformViewAndroid::Detach(JNIEnv* env, jobject obj) { void PlatformViewAndroid::SurfaceCreated(JNIEnv* env, jobject obj, - jobject jsurface) { + jobject jsurface, + jint backgroundColor) { // 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 @@ -68,21 +69,27 @@ void PlatformViewAndroid::SurfaceCreated(JNIEnv* env, } ANativeWindow_release(window); + + auto gl_surface = std::make_unique(surface_gl_.get()); + NotifyCreated(std::move(gl_surface), [this, backgroundColor] { + rasterizer().Clear(backgroundColor, GetSize()); + }); + + SetupResourceContextOnIOThread(); + UpdateThreadPriorities(); } void PlatformViewAndroid::SurfaceChanged(JNIEnv* env, jobject obj, - jint backgroundColor) { + jint width, + jint height) { if (!surface_gl_) { return; } - auto surface = std::make_unique(surface_gl_.get()); - NotifyCreated(std::move(surface), [this, backgroundColor] { - rasterizer().Clear(backgroundColor, GetSize()); + blink::Threads::Gpu()->PostTask([this, width, height]() { + surface_gl_->OnScreenSurfaceResize(SkISize::Make(width, height)); }); - SetupResourceContextOnIOThread(); - UpdateThreadPriorities(); } void PlatformViewAndroid::UpdateThreadPriorities() { diff --git a/engine/src/flutter/shell/platform/android/platform_view_android.h b/engine/src/flutter/shell/platform/android/platform_view_android.h index 5231394f55..3a04f2ce09 100644 --- a/engine/src/flutter/shell/platform/android/platform_view_android.h +++ b/engine/src/flutter/shell/platform/android/platform_view_android.h @@ -28,9 +28,9 @@ class PlatformViewAndroid : public PlatformView { void Detach(JNIEnv* env, jobject obj); - void SurfaceCreated(JNIEnv* env, jobject obj, jobject jsurface); + void SurfaceCreated(JNIEnv* env, jobject obj, jobject jsurface, jint backgroundColor); - void SurfaceChanged(JNIEnv* env, jobject obj, jint backgroundColor); + void SurfaceChanged(JNIEnv* env, jobject obj, jint width, jint height); void SurfaceDestroyed(JNIEnv* env, jobject obj);