| Index: ui/gl/gl_surface_egl.cc
|
| diff --git a/ui/gl/gl_surface_egl.cc b/ui/gl/gl_surface_egl.cc
|
| index c34ca0e70e7a25396a82cd9310a90c2ef0630cd6..085f969847afd7dc8cf63446fbdb546f829e9464 100644
|
| --- a/ui/gl/gl_surface_egl.cc
|
| +++ b/ui/gl/gl_surface_egl.cc
|
| @@ -62,6 +62,14 @@ EGLConfig g_config;
|
| EGLDisplay g_display;
|
| EGLNativeDisplayType g_native_display;
|
|
|
| +// In the Cast environment, we need to destroy the displayType
|
| +// returned by the GPU platform when we switch to an external app
|
| +// which will temporarily own all screen and GPU resources.
|
| +// Even though Chromium is still in the background.
|
| +// As such, it must be reinitialized each time we come back to the foreground.
|
| +bool g_initialized = false;
|
| +int g_num_surfaces = 0;
|
| +
|
| const char* g_egl_extensions = NULL;
|
| bool g_egl_create_context_robustness_supported = false;
|
| bool g_egl_sync_control_supported = false;
|
| @@ -104,13 +112,26 @@ class EGLSyncControlVSyncProvider
|
| DISALLOW_COPY_AND_ASSIGN(EGLSyncControlVSyncProvider);
|
| };
|
|
|
| +void DeinitializeEgl() {
|
| + if (g_initialized) {
|
| + g_initialized = false;
|
| + eglTerminate(g_display);
|
| + }
|
| +}
|
| +
|
| } // namespace
|
|
|
| -GLSurfaceEGL::GLSurfaceEGL() {}
|
| +GLSurfaceEGL::GLSurfaceEGL() {
|
| + ++g_num_surfaces;
|
| + if (!g_initialized) {
|
| + bool result = GLSurfaceEGL::InitializeOneOff();
|
| + DCHECK(result);
|
| + DCHECK(g_initialized);
|
| + }
|
| +}
|
|
|
| bool GLSurfaceEGL::InitializeOneOff() {
|
| - static bool initialized = false;
|
| - if (initialized)
|
| + if (g_initialized)
|
| return true;
|
|
|
| g_native_display = GetPlatformDefaultEGLNativeDisplay();
|
| @@ -186,6 +207,11 @@ bool GLSurfaceEGL::InitializeOneOff() {
|
| g_egl_window_fixed_size_supported =
|
| HasEGLExtension("EGL_ANGLE_window_fixed_size");
|
|
|
| + // We always succeed beyond this point so set g_initialized here to avoid
|
| + // infinite recursion through CreateGLContext and GetDisplay
|
| + // if g_egl_surfaceless_context_supported.
|
| + g_initialized = true;
|
| +
|
| // TODO(oetuaho@nvidia.com): Surfaceless is disabled on Android as a temporary
|
| // workaround, since code written for Android WebView takes different paths
|
| // based on whether GL surface objects have underlying EGL surface handles,
|
| @@ -215,24 +241,36 @@ bool GLSurfaceEGL::InitializeOneOff() {
|
| }
|
| #endif
|
|
|
| - initialized = true;
|
| -
|
| return true;
|
| }
|
|
|
| EGLDisplay GLSurfaceEGL::GetDisplay() {
|
| + if (!g_initialized) {
|
| + bool result = GLSurfaceEGL::InitializeOneOff();
|
| + DCHECK(result);
|
| + }
|
| return g_display;
|
| }
|
|
|
| EGLDisplay GLSurfaceEGL::GetHardwareDisplay() {
|
| + if (!g_initialized) {
|
| + bool result = GLSurfaceEGL::InitializeOneOff();
|
| + DCHECK(result);
|
| + }
|
| return g_display;
|
| }
|
|
|
| EGLNativeDisplayType GLSurfaceEGL::GetNativeDisplay() {
|
| + if (!g_initialized) {
|
| + bool result = GLSurfaceEGL::InitializeOneOff();
|
| + DCHECK(result);
|
| + }
|
| return g_native_display;
|
| }
|
|
|
| const char* GLSurfaceEGL::GetEGLExtensions() {
|
| + // No need for InitializeOneOff. Assume that extensions will not change
|
| + // after the first initialization.
|
| return g_egl_extensions;
|
| }
|
|
|
| @@ -248,7 +286,13 @@ bool GLSurfaceEGL::IsEGLSurfacelessContextSupported() {
|
| return g_egl_surfaceless_context_supported;
|
| }
|
|
|
| -GLSurfaceEGL::~GLSurfaceEGL() {}
|
| +GLSurfaceEGL::~GLSurfaceEGL() {
|
| + DCHECK_GT(g_num_surfaces, 0) << "Bad surface count";
|
| + if (--g_num_surfaces == 0) {
|
| + DVLOG(1) << "Destroyed last EGL surface. Deinitializing.";
|
| + DeinitializeEgl();
|
| + }
|
| +}
|
|
|
| #if defined(OS_WIN)
|
| static const EGLint kDisplayAttribsWarp[] {
|
|
|