Chromium Code Reviews| 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..1166161b580e662cc5ac4051872789589512a992 100644 |
| --- a/ui/gl/gl_surface_egl.cc |
| +++ b/ui/gl/gl_surface_egl.cc |
| @@ -62,6 +62,15 @@ EGLConfig g_config; |
| EGLDisplay g_display; |
| EGLNativeDisplayType g_native_display; |
| +// In the Cast environment, we need to destroy the displayType |
|
dcheng
2014/11/21 03:06:04
What is "displayType"? Is this reference to a Chro
GusFernandez
2014/11/21 19:13:56
I clarified the comment and also
s/g_native_displa
|
| +// 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; |
| +bool g_terminate_pending = false; |
| + |
| const char* g_egl_extensions = NULL; |
| bool g_egl_create_context_robustness_supported = false; |
| bool g_egl_sync_control_supported = false; |
| @@ -104,13 +113,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 +208,12 @@ 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; |
| + g_terminate_pending = false; |
| + |
| // 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 +243,36 @@ bool GLSurfaceEGL::InitializeOneOff() { |
| } |
| #endif |
| - initialized = true; |
| - |
| return true; |
| } |
| EGLDisplay GLSurfaceEGL::GetDisplay() { |
| + if (!g_initialized) { |
|
dcheng
2014/11/21 03:06:04
This isn't a static method. How could we get here
GusFernandez
2014/11/21 19:13:56
Agreed. This is old code and no longer needed now
|
| + bool result = GLSurfaceEGL::InitializeOneOff(); |
| + DCHECK(result); |
| + } |
| return g_display; |
| } |
| EGLDisplay GLSurfaceEGL::GetHardwareDisplay() { |
| + if (!g_initialized) { |
|
dcheng
2014/11/21 03:06:04
Why is this safe to do if there are no live GLSurf
GusFernandez
2014/11/21 19:13:56
Platform ensures that no EGL objects are used by c
dcheng
2014/11/21 20:43:00
I know these are static, but I don't follow the re
|
| + 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 +288,20 @@ bool GLSurfaceEGL::IsEGLSurfacelessContextSupported() { |
| return g_egl_surfaceless_context_supported; |
| } |
| -GLSurfaceEGL::~GLSurfaceEGL() {} |
| +void GLSurfaceEGL::DestroyAndTerminateDisplay() { |
| + DCHECK(g_initialized); |
| + DCHECK_EQ(g_num_surfaces, 1); |
| + Destroy(); |
| + g_terminate_pending = true; |
| +} |
| + |
| +GLSurfaceEGL::~GLSurfaceEGL() { |
| + DCHECK_GT(g_num_surfaces, 0) << "Bad surface count"; |
| + if (--g_num_surfaces == 0 && g_terminate_pending) { |
|
dcheng
2014/11/21 03:06:04
Why isn't this simply gated on --g_num_surfaces ==
GusFernandez
2014/11/21 19:13:56
This is to resolve a problem with Win GL unit test
dcheng
2014/11/21 20:43:00
Shouldn't we fix the tests, rather than having to
|
| + DeinitializeEgl(); |
| + g_terminate_pending = false; |
| + } |
| +} |
| #if defined(OS_WIN) |
| static const EGLint kDisplayAttribsWarp[] { |