提交 d9d23336 编写于 作者: J Jason Simmons 提交者: GitHub

Do not attach and detach the EGL context on each frame in the rasterizer thread (#3110)

上级 2dc88cc6
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册