Do not attach and detach the EGL context on each frame in the rasterizer thread (flutter/engine#3110)
This commit is contained in:
@@ -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<SurfaceFrame> 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<SurfaceFrame> 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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<GPUSurfaceGL>(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<GPUSurfaceGL>(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() {
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user