OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gl/gl_surface_egl.h" | 5 #include "ui/gl/gl_surface_egl.h" |
6 | 6 |
7 #if defined(OS_ANDROID) | 7 #if defined(OS_ANDROID) |
8 #include <android/native_window_jni.h> | 8 #include <android/native_window_jni.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 namespace gfx { | 55 namespace gfx { |
56 | 56 |
57 unsigned int NativeViewGLSurfaceEGL::current_swap_generation_ = 0; | 57 unsigned int NativeViewGLSurfaceEGL::current_swap_generation_ = 0; |
58 | 58 |
59 namespace { | 59 namespace { |
60 | 60 |
61 EGLConfig g_config; | 61 EGLConfig g_config; |
62 EGLDisplay g_display; | 62 EGLDisplay g_display; |
63 EGLNativeDisplayType g_native_display; | 63 EGLNativeDisplayType g_native_display; |
64 | 64 |
65 // 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
| |
66 // returned by the GPU platform when we switch to an external app | |
67 // which will temporarily own all screen and GPU resources. | |
68 // Even though Chromium is still in the background. | |
69 // As such, it must be reinitialized each time we come back to the foreground. | |
70 bool g_initialized = false; | |
71 int g_num_surfaces = 0; | |
72 bool g_terminate_pending = false; | |
73 | |
65 const char* g_egl_extensions = NULL; | 74 const char* g_egl_extensions = NULL; |
66 bool g_egl_create_context_robustness_supported = false; | 75 bool g_egl_create_context_robustness_supported = false; |
67 bool g_egl_sync_control_supported = false; | 76 bool g_egl_sync_control_supported = false; |
68 bool g_egl_window_fixed_size_supported = false; | 77 bool g_egl_window_fixed_size_supported = false; |
69 bool g_egl_surfaceless_context_supported = false; | 78 bool g_egl_surfaceless_context_supported = false; |
70 | 79 |
71 class EGLSyncControlVSyncProvider | 80 class EGLSyncControlVSyncProvider |
72 : public gfx::SyncControlVSyncProvider { | 81 : public gfx::SyncControlVSyncProvider { |
73 public: | 82 public: |
74 explicit EGLSyncControlVSyncProvider(EGLSurface surface) | 83 explicit EGLSyncControlVSyncProvider(EGLSurface surface) |
(...skipping 22 matching lines...) Expand all Loading... | |
97 bool GetMscRate(int32* numerator, int32* denominator) override { | 106 bool GetMscRate(int32* numerator, int32* denominator) override { |
98 return false; | 107 return false; |
99 } | 108 } |
100 | 109 |
101 private: | 110 private: |
102 EGLSurface surface_; | 111 EGLSurface surface_; |
103 | 112 |
104 DISALLOW_COPY_AND_ASSIGN(EGLSyncControlVSyncProvider); | 113 DISALLOW_COPY_AND_ASSIGN(EGLSyncControlVSyncProvider); |
105 }; | 114 }; |
106 | 115 |
116 void DeinitializeEgl() { | |
117 if (g_initialized) { | |
118 g_initialized = false; | |
119 eglTerminate(g_display); | |
120 } | |
121 } | |
122 | |
107 } // namespace | 123 } // namespace |
108 | 124 |
109 GLSurfaceEGL::GLSurfaceEGL() {} | 125 GLSurfaceEGL::GLSurfaceEGL() { |
126 ++g_num_surfaces; | |
127 if (!g_initialized) { | |
128 bool result = GLSurfaceEGL::InitializeOneOff(); | |
129 DCHECK(result); | |
130 DCHECK(g_initialized); | |
131 } | |
132 } | |
110 | 133 |
111 bool GLSurfaceEGL::InitializeOneOff() { | 134 bool GLSurfaceEGL::InitializeOneOff() { |
112 static bool initialized = false; | 135 if (g_initialized) |
113 if (initialized) | |
114 return true; | 136 return true; |
115 | 137 |
116 g_native_display = GetPlatformDefaultEGLNativeDisplay(); | 138 g_native_display = GetPlatformDefaultEGLNativeDisplay(); |
117 | 139 |
118 #if defined(OS_WIN) | 140 #if defined(OS_WIN) |
119 g_display = GetPlatformDisplay(g_native_display); | 141 g_display = GetPlatformDisplay(g_native_display); |
120 #else | 142 #else |
121 g_display = eglGetDisplay(g_native_display); | 143 g_display = eglGetDisplay(g_native_display); |
122 #endif | 144 #endif |
123 | 145 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 } | 201 } |
180 | 202 |
181 g_egl_extensions = eglQueryString(g_display, EGL_EXTENSIONS); | 203 g_egl_extensions = eglQueryString(g_display, EGL_EXTENSIONS); |
182 g_egl_create_context_robustness_supported = | 204 g_egl_create_context_robustness_supported = |
183 HasEGLExtension("EGL_EXT_create_context_robustness"); | 205 HasEGLExtension("EGL_EXT_create_context_robustness"); |
184 g_egl_sync_control_supported = | 206 g_egl_sync_control_supported = |
185 HasEGLExtension("EGL_CHROMIUM_sync_control"); | 207 HasEGLExtension("EGL_CHROMIUM_sync_control"); |
186 g_egl_window_fixed_size_supported = | 208 g_egl_window_fixed_size_supported = |
187 HasEGLExtension("EGL_ANGLE_window_fixed_size"); | 209 HasEGLExtension("EGL_ANGLE_window_fixed_size"); |
188 | 210 |
211 // We always succeed beyond this point so set g_initialized here to avoid | |
212 // infinite recursion through CreateGLContext and GetDisplay | |
213 // if g_egl_surfaceless_context_supported. | |
214 g_initialized = true; | |
215 g_terminate_pending = false; | |
216 | |
189 // TODO(oetuaho@nvidia.com): Surfaceless is disabled on Android as a temporary | 217 // TODO(oetuaho@nvidia.com): Surfaceless is disabled on Android as a temporary |
190 // workaround, since code written for Android WebView takes different paths | 218 // workaround, since code written for Android WebView takes different paths |
191 // based on whether GL surface objects have underlying EGL surface handles, | 219 // based on whether GL surface objects have underlying EGL surface handles, |
192 // conflicting with the use of surfaceless. See https://crbug.com/382349 | 220 // conflicting with the use of surfaceless. See https://crbug.com/382349 |
193 #if defined(OS_ANDROID) | 221 #if defined(OS_ANDROID) |
194 DCHECK(!g_egl_surfaceless_context_supported); | 222 DCHECK(!g_egl_surfaceless_context_supported); |
195 #else | 223 #else |
196 // Check if SurfacelessEGL is supported. | 224 // Check if SurfacelessEGL is supported. |
197 g_egl_surfaceless_context_supported = | 225 g_egl_surfaceless_context_supported = |
198 HasEGLExtension("EGL_KHR_surfaceless_context"); | 226 HasEGLExtension("EGL_KHR_surfaceless_context"); |
199 if (g_egl_surfaceless_context_supported) { | 227 if (g_egl_surfaceless_context_supported) { |
200 // EGL_KHR_surfaceless_context is supported but ensure | 228 // EGL_KHR_surfaceless_context is supported but ensure |
201 // GL_OES_surfaceless_context is also supported. We need a current context | 229 // GL_OES_surfaceless_context is also supported. We need a current context |
202 // to query for supported GL extensions. | 230 // to query for supported GL extensions. |
203 scoped_refptr<GLSurface> surface = new SurfacelessEGL(Size(1, 1)); | 231 scoped_refptr<GLSurface> surface = new SurfacelessEGL(Size(1, 1)); |
204 scoped_refptr<GLContext> context = GLContext::CreateGLContext( | 232 scoped_refptr<GLContext> context = GLContext::CreateGLContext( |
205 NULL, surface.get(), PreferIntegratedGpu); | 233 NULL, surface.get(), PreferIntegratedGpu); |
206 if (!context->MakeCurrent(surface.get())) | 234 if (!context->MakeCurrent(surface.get())) |
207 g_egl_surfaceless_context_supported = false; | 235 g_egl_surfaceless_context_supported = false; |
208 | 236 |
209 // Ensure context supports GL_OES_surfaceless_context. | 237 // Ensure context supports GL_OES_surfaceless_context. |
210 if (g_egl_surfaceless_context_supported) { | 238 if (g_egl_surfaceless_context_supported) { |
211 g_egl_surfaceless_context_supported = context->HasExtension( | 239 g_egl_surfaceless_context_supported = context->HasExtension( |
212 "GL_OES_surfaceless_context"); | 240 "GL_OES_surfaceless_context"); |
213 context->ReleaseCurrent(surface.get()); | 241 context->ReleaseCurrent(surface.get()); |
214 } | 242 } |
215 } | 243 } |
216 #endif | 244 #endif |
217 | 245 |
218 initialized = true; | |
219 | |
220 return true; | 246 return true; |
221 } | 247 } |
222 | 248 |
223 EGLDisplay GLSurfaceEGL::GetDisplay() { | 249 EGLDisplay GLSurfaceEGL::GetDisplay() { |
250 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
| |
251 bool result = GLSurfaceEGL::InitializeOneOff(); | |
252 DCHECK(result); | |
253 } | |
224 return g_display; | 254 return g_display; |
225 } | 255 } |
226 | 256 |
227 EGLDisplay GLSurfaceEGL::GetHardwareDisplay() { | 257 EGLDisplay GLSurfaceEGL::GetHardwareDisplay() { |
258 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
| |
259 bool result = GLSurfaceEGL::InitializeOneOff(); | |
260 DCHECK(result); | |
261 } | |
228 return g_display; | 262 return g_display; |
229 } | 263 } |
230 | 264 |
231 EGLNativeDisplayType GLSurfaceEGL::GetNativeDisplay() { | 265 EGLNativeDisplayType GLSurfaceEGL::GetNativeDisplay() { |
266 if (!g_initialized) { | |
267 bool result = GLSurfaceEGL::InitializeOneOff(); | |
268 DCHECK(result); | |
269 } | |
232 return g_native_display; | 270 return g_native_display; |
233 } | 271 } |
234 | 272 |
235 const char* GLSurfaceEGL::GetEGLExtensions() { | 273 const char* GLSurfaceEGL::GetEGLExtensions() { |
274 // No need for InitializeOneOff. Assume that extensions will not change | |
275 // after the first initialization. | |
236 return g_egl_extensions; | 276 return g_egl_extensions; |
237 } | 277 } |
238 | 278 |
239 bool GLSurfaceEGL::HasEGLExtension(const char* name) { | 279 bool GLSurfaceEGL::HasEGLExtension(const char* name) { |
240 return ExtensionsContain(GetEGLExtensions(), name); | 280 return ExtensionsContain(GetEGLExtensions(), name); |
241 } | 281 } |
242 | 282 |
243 bool GLSurfaceEGL::IsCreateContextRobustnessSupported() { | 283 bool GLSurfaceEGL::IsCreateContextRobustnessSupported() { |
244 return g_egl_create_context_robustness_supported; | 284 return g_egl_create_context_robustness_supported; |
245 } | 285 } |
246 | 286 |
247 bool GLSurfaceEGL::IsEGLSurfacelessContextSupported() { | 287 bool GLSurfaceEGL::IsEGLSurfacelessContextSupported() { |
248 return g_egl_surfaceless_context_supported; | 288 return g_egl_surfaceless_context_supported; |
249 } | 289 } |
250 | 290 |
251 GLSurfaceEGL::~GLSurfaceEGL() {} | 291 void GLSurfaceEGL::DestroyAndTerminateDisplay() { |
292 DCHECK(g_initialized); | |
293 DCHECK_EQ(g_num_surfaces, 1); | |
294 Destroy(); | |
295 g_terminate_pending = true; | |
296 } | |
297 | |
298 GLSurfaceEGL::~GLSurfaceEGL() { | |
299 DCHECK_GT(g_num_surfaces, 0) << "Bad surface count"; | |
300 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
| |
301 DeinitializeEgl(); | |
302 g_terminate_pending = false; | |
303 } | |
304 } | |
252 | 305 |
253 #if defined(OS_WIN) | 306 #if defined(OS_WIN) |
254 static const EGLint kDisplayAttribsWarp[] { | 307 static const EGLint kDisplayAttribsWarp[] { |
255 EGL_PLATFORM_ANGLE_TYPE_ANGLE, | 308 EGL_PLATFORM_ANGLE_TYPE_ANGLE, |
256 EGL_PLATFORM_ANGLE_TYPE_D3D11_WARP_ANGLE, | 309 EGL_PLATFORM_ANGLE_TYPE_D3D11_WARP_ANGLE, |
257 EGL_NONE | 310 EGL_NONE |
258 }; | 311 }; |
259 | 312 |
260 // static | 313 // static |
261 EGLDisplay GLSurfaceEGL::GetPlatformDisplay( | 314 EGLDisplay GLSurfaceEGL::GetPlatformDisplay( |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
738 } | 791 } |
739 | 792 |
740 void* SurfacelessEGL::GetShareHandle() { | 793 void* SurfacelessEGL::GetShareHandle() { |
741 return NULL; | 794 return NULL; |
742 } | 795 } |
743 | 796 |
744 SurfacelessEGL::~SurfacelessEGL() { | 797 SurfacelessEGL::~SurfacelessEGL() { |
745 } | 798 } |
746 | 799 |
747 } // namespace gfx | 800 } // namespace gfx |
OLD | NEW |