提交 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() { ...@@ -90,9 +90,6 @@ bool GPUSurfaceGL::Setup() {
context_->setResourceCacheLimits(kMaxGaneshResourceCacheCount, context_->setResourceCacheLimits(kMaxGaneshResourceCacheCount,
kMaxGaneshResourceCacheBytes); kMaxGaneshResourceCacheBytes);
// Clean up the current context.
delegate_->GLContextClearCurrent();
return true; return true;
} }
...@@ -111,10 +108,6 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceGL::AcquireFrame(const SkISize& size) { ...@@ -111,10 +108,6 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceGL::AcquireFrame(const SkISize& size) {
return nullptr; return nullptr;
} }
if (!delegate_->GLContextMakeCurrent()) {
return nullptr;
}
auto weak_this = weak_factory_.GetWeakPtr(); auto weak_this = weak_factory_.GetWeakPtr();
GPUSurfaceFrameGL::SubmitCallback submit_callback = GPUSurfaceFrameGL::SubmitCallback submit_callback =
...@@ -128,8 +121,6 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceGL::AcquireFrame(const SkISize& size) { ...@@ -128,8 +121,6 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceGL::AcquireFrame(const SkISize& size) {
bool GPUSurfaceGL::PresentSurface(SkCanvas* canvas) { bool GPUSurfaceGL::PresentSurface(SkCanvas* canvas) {
if (delegate_ == nullptr || canvas == nullptr) { if (delegate_ == nullptr || canvas == nullptr) {
delegate_->GLContextClearCurrent();
return false; return false;
} }
...@@ -140,8 +131,6 @@ bool GPUSurfaceGL::PresentSurface(SkCanvas* canvas) { ...@@ -140,8 +131,6 @@ bool GPUSurfaceGL::PresentSurface(SkCanvas* canvas) {
delegate_->GLContextPresent(); delegate_->GLContextPresent();
delegate_->GLContextClearCurrent();
return true; return true;
} }
......
...@@ -276,6 +276,8 @@ bool AndroidContextGL::Resize(const SkISize& size) { ...@@ -276,6 +276,8 @@ bool AndroidContextGL::Resize(const SkISize& size) {
std::tie(success, surface_) = std::tie(success, surface_) =
CreateSurface(environment_->Display(), config_, window_); CreateSurface(environment_->Display(), config_, window_);
MakeCurrent();
if (!success) { if (!success) {
LOG(ERROR) << "Unable to create EGL window surface on resize."; LOG(ERROR) << "Unable to create EGL window surface on resize.";
return false; return false;
......
...@@ -127,13 +127,13 @@ public class FlutterView extends SurfaceView ...@@ -127,13 +127,13 @@ public class FlutterView extends SurfaceView
@Override @Override
public void surfaceCreated(SurfaceHolder holder) { public void surfaceCreated(SurfaceHolder holder) {
assert mNativePlatformView != 0; assert mNativePlatformView != 0;
nativeSurfaceCreated(mNativePlatformView, holder.getSurface()); nativeSurfaceCreated(mNativePlatformView, holder.getSurface(), backgroundColor);
} }
@Override @Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
assert mNativePlatformView != 0; assert mNativePlatformView != 0;
nativeSurfaceChanged(mNativePlatformView, backgroundColor); nativeSurfaceChanged(mNativePlatformView, width, height);
} }
@Override @Override
...@@ -571,8 +571,11 @@ public class FlutterView extends SurfaceView ...@@ -571,8 +571,11 @@ public class FlutterView extends SurfaceView
private static native int nativeGetObservatoryPort(); private static native int nativeGetObservatoryPort();
private static native void nativeDetach(long nativePlatformViewAndroid); private static native void nativeDetach(long nativePlatformViewAndroid);
private static native void nativeSurfaceCreated(long nativePlatformViewAndroid, private static native void nativeSurfaceCreated(long nativePlatformViewAndroid,
Surface surface); Surface surface,
private static native void nativeSurfaceChanged(long nativePlatformViewAndroid, int backgroundColor); int backgroundColor);
private static native void nativeSurfaceChanged(long nativePlatformViewAndroid,
int width,
int height);
private static native void nativeSurfaceDestroyed(long nativePlatformViewAndroid); private static native void nativeSurfaceDestroyed(long nativePlatformViewAndroid);
private static native Bitmap nativeGetBitmap(long nativePlatformViewAndroid); private static native Bitmap nativeGetBitmap(long nativePlatformViewAndroid);
......
...@@ -43,7 +43,8 @@ void PlatformViewAndroid::Detach(JNIEnv* env, jobject obj) { ...@@ -43,7 +43,8 @@ void PlatformViewAndroid::Detach(JNIEnv* env, jobject obj) {
void PlatformViewAndroid::SurfaceCreated(JNIEnv* env, void PlatformViewAndroid::SurfaceCreated(JNIEnv* env,
jobject obj, jobject obj,
jobject jsurface) { jobject jsurface,
jint backgroundColor) {
// Note: This frame ensures that any local references used by // Note: This frame ensures that any local references used by
// ANativeWindow_fromSurface are released immediately. This is needed as a // ANativeWindow_fromSurface are released immediately. This is needed as a
// workaround for https://code.google.com/p/android/issues/detail?id=68174 // workaround for https://code.google.com/p/android/issues/detail?id=68174
...@@ -68,21 +69,27 @@ void PlatformViewAndroid::SurfaceCreated(JNIEnv* env, ...@@ -68,21 +69,27 @@ void PlatformViewAndroid::SurfaceCreated(JNIEnv* env,
} }
ANativeWindow_release(window); 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, void PlatformViewAndroid::SurfaceChanged(JNIEnv* env,
jobject obj, jobject obj,
jint backgroundColor) { jint width,
jint height) {
if (!surface_gl_) { if (!surface_gl_) {
return; return;
} }
auto surface = std::make_unique<GPUSurfaceGL>(surface_gl_.get()); blink::Threads::Gpu()->PostTask([this, width, height]() {
NotifyCreated(std::move(surface), [this, backgroundColor] { surface_gl_->OnScreenSurfaceResize(SkISize::Make(width, height));
rasterizer().Clear(backgroundColor, GetSize());
}); });
SetupResourceContextOnIOThread();
UpdateThreadPriorities();
} }
void PlatformViewAndroid::UpdateThreadPriorities() { void PlatformViewAndroid::UpdateThreadPriorities() {
......
...@@ -28,9 +28,9 @@ class PlatformViewAndroid : public PlatformView { ...@@ -28,9 +28,9 @@ class PlatformViewAndroid : public PlatformView {
void Detach(JNIEnv* env, jobject obj); 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); void SurfaceDestroyed(JNIEnv* env, jobject obj);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册