From 04ca9a5cb5fc6c8d1c7a6e5a226095d5154c54a3 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Thu, 28 Mar 2019 11:33:56 -0700 Subject: [PATCH] Create a new resource loading EGL context for each PlatformView instance on Android (flutter/engine#8330) Using one global resource loading context will fail if two PlatformViews are running concurrently with two different IO threads. --- .../platform/android/android_surface_gl.cc | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/engine/src/flutter/shell/platform/android/android_surface_gl.cc b/engine/src/flutter/shell/platform/android/android_surface_gl.cc index 4e1ff9f41c..83586b4030 100644 --- a/engine/src/flutter/shell/platform/android/android_surface_gl.cc +++ b/engine/src/flutter/shell/platform/android/android_surface_gl.cc @@ -11,35 +11,23 @@ namespace shell { -static fml::RefPtr GlobalResourceLoadingContext() { - // AndroidSurfaceGL instances are only ever created on the platform thread. So - // there is no need to lock here. - - static fml::RefPtr global_context; - - if (global_context) { - return global_context; - } - +static fml::RefPtr CreateResourceLoadingContext() { auto environment = fml::MakeRefCounted(); - if (!environment->IsValid()) { return nullptr; } auto context = fml::MakeRefCounted(environment); - if (!context->IsValid()) { return nullptr; } - global_context = context; - return global_context; + return context; } AndroidSurfaceGL::AndroidSurfaceGL() { // Acquire the offscreen context. - offscreen_context_ = GlobalResourceLoadingContext(); + offscreen_context_ = CreateResourceLoadingContext(); if (!offscreen_context_ || !offscreen_context_->IsValid()) { offscreen_context_ = nullptr;