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 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 EGLNativeDisplayType g_native_display = EGL_DEFAULT_DISPLAY; | 127 EGLNativeDisplayType g_native_display = EGL_DEFAULT_DISPLAY; |
128 | 128 |
129 const char* g_egl_extensions = nullptr; | 129 const char* g_egl_extensions = nullptr; |
130 bool g_egl_create_context_robustness_supported = false; | 130 bool g_egl_create_context_robustness_supported = false; |
131 bool g_egl_create_context_bind_generates_resource_supported = false; | 131 bool g_egl_create_context_bind_generates_resource_supported = false; |
132 bool g_egl_create_context_webgl_compatability_supported = false; | 132 bool g_egl_create_context_webgl_compatability_supported = false; |
133 bool g_egl_sync_control_supported = false; | 133 bool g_egl_sync_control_supported = false; |
134 bool g_egl_window_fixed_size_supported = false; | 134 bool g_egl_window_fixed_size_supported = false; |
135 bool g_egl_surfaceless_context_supported = false; | 135 bool g_egl_surfaceless_context_supported = false; |
136 bool g_egl_surface_orientation_supported = false; | 136 bool g_egl_surface_orientation_supported = false; |
| 137 bool g_egl_context_priority_supported = false; |
137 bool g_use_direct_composition = false; | 138 bool g_use_direct_composition = false; |
138 | 139 |
139 base::LazyInstance<ANGLEPlatformImpl> g_angle_platform_impl = | 140 base::LazyInstance<ANGLEPlatformImpl> g_angle_platform_impl = |
140 LAZY_INSTANCE_INITIALIZER; | 141 LAZY_INSTANCE_INITIALIZER; |
141 ANGLEPlatformShutdownFunc g_angle_platform_shutdown = nullptr; | 142 ANGLEPlatformShutdownFunc g_angle_platform_shutdown = nullptr; |
142 | 143 |
143 EGLDisplay GetPlatformANGLEDisplay(EGLNativeDisplayType native_display, | 144 EGLDisplay GetPlatformANGLEDisplay(EGLNativeDisplayType native_display, |
144 EGLenum platform_type, | 145 EGLenum platform_type, |
145 bool warpDevice) { | 146 bool warpDevice) { |
146 std::vector<EGLint> display_attribs; | 147 std::vector<EGLint> display_attribs; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 } | 236 } |
236 if (*num_configs == 0) { | 237 if (*num_configs == 0) { |
237 return false; | 238 return false; |
238 } | 239 } |
239 return true; | 240 return true; |
240 } | 241 } |
241 | 242 |
242 EGLConfig ChooseConfig(GLSurfaceFormat format) { | 243 EGLConfig ChooseConfig(GLSurfaceFormat format) { |
243 // Choose an EGL configuration. | 244 // Choose an EGL configuration. |
244 // On X this is only used for PBuffer surfaces. | 245 // On X this is only used for PBuffer surfaces. |
| 246 |
245 std::vector<EGLint> renderable_types; | 247 std::vector<EGLint> renderable_types; |
246 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 248 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
247 switches::kDisableES3GLContext)) { | 249 switches::kDisableES3GLContext)) { |
248 renderable_types.push_back(EGL_OPENGL_ES3_BIT); | 250 renderable_types.push_back(EGL_OPENGL_ES3_BIT); |
249 } | 251 } |
250 renderable_types.push_back(EGL_OPENGL_ES2_BIT); | 252 renderable_types.push_back(EGL_OPENGL_ES2_BIT); |
251 | 253 |
252 EGLint buffer_size = format.GetBufferSize(); | 254 EGLint buffer_size = format.GetBufferSize(); |
253 EGLint alpha_size = 8; | 255 EGLint alpha_size = 8; |
254 bool want_rgb565 = buffer_size == 16; | 256 bool want_rgb565 = buffer_size == 16; |
| 257 EGLint depth_size = format.GetDepthBits(); |
| 258 EGLint stencil_size = format.GetStencilBits(); |
| 259 EGLint samples = format.GetSamples(); |
255 | 260 |
256 #if defined(USE_X11) && !defined(OS_CHROMEOS) | 261 #if defined(USE_X11) && !defined(OS_CHROMEOS) |
257 // If we're using ANGLE_NULL, we may not have a display, in which case we | 262 // If we're using ANGLE_NULL, we may not have a display, in which case we |
258 // can't use XVisualManager. | 263 // can't use XVisualManager. |
259 if (g_native_display) { | 264 if (g_native_display) { |
260 ui::XVisualManager::GetInstance()->ChooseVisualForWindow( | 265 ui::XVisualManager::GetInstance()->ChooseVisualForWindow( |
261 true, nullptr, &buffer_size, nullptr, nullptr); | 266 true, nullptr, &buffer_size, nullptr, nullptr); |
262 alpha_size = buffer_size == 32 ? 8 : 0; | 267 alpha_size = buffer_size == 32 ? 8 : 0; |
263 } | 268 } |
264 #endif | 269 #endif |
265 | 270 |
266 EGLint surface_type = (format.IsSurfaceless() | 271 EGLint surface_type = (format.IsSurfaceless() |
267 ? EGL_DONT_CARE | 272 ? EGL_DONT_CARE |
268 : EGL_WINDOW_BIT | EGL_PBUFFER_BIT); | 273 : EGL_WINDOW_BIT | EGL_PBUFFER_BIT); |
269 | 274 |
270 for (auto renderable_type : renderable_types) { | 275 for (auto renderable_type : renderable_types) { |
271 EGLint config_attribs_8888[] = {EGL_BUFFER_SIZE, | 276 EGLint config_attribs_8888[] = {EGL_BUFFER_SIZE, |
272 buffer_size, | 277 buffer_size, |
273 EGL_ALPHA_SIZE, | 278 EGL_ALPHA_SIZE, |
274 alpha_size, | 279 alpha_size, |
275 EGL_BLUE_SIZE, | 280 EGL_BLUE_SIZE, |
276 8, | 281 8, |
277 EGL_GREEN_SIZE, | 282 EGL_GREEN_SIZE, |
278 8, | 283 8, |
279 EGL_RED_SIZE, | 284 EGL_RED_SIZE, |
280 8, | 285 8, |
| 286 EGL_SAMPLES, |
| 287 samples, |
| 288 EGL_DEPTH_SIZE, |
| 289 depth_size, |
| 290 EGL_STENCIL_SIZE, |
| 291 stencil_size, |
281 EGL_RENDERABLE_TYPE, | 292 EGL_RENDERABLE_TYPE, |
282 renderable_type, | 293 renderable_type, |
283 EGL_SURFACE_TYPE, | 294 EGL_SURFACE_TYPE, |
284 surface_type, | 295 surface_type, |
285 EGL_NONE}; | 296 EGL_NONE}; |
286 | 297 |
287 EGLint config_attribs_565[] = {EGL_BUFFER_SIZE, | 298 EGLint config_attribs_565[] = {EGL_BUFFER_SIZE, |
288 16, | 299 16, |
289 EGL_BLUE_SIZE, | 300 EGL_BLUE_SIZE, |
290 5, | 301 5, |
291 EGL_GREEN_SIZE, | 302 EGL_GREEN_SIZE, |
292 6, | 303 6, |
293 EGL_RED_SIZE, | 304 EGL_RED_SIZE, |
294 5, | 305 5, |
| 306 EGL_SAMPLES, |
| 307 samples, |
| 308 EGL_DEPTH_SIZE, |
| 309 depth_size, |
| 310 EGL_STENCIL_SIZE, |
| 311 stencil_size, |
295 EGL_RENDERABLE_TYPE, | 312 EGL_RENDERABLE_TYPE, |
296 renderable_type, | 313 renderable_type, |
297 EGL_SURFACE_TYPE, | 314 EGL_SURFACE_TYPE, |
298 surface_type, | 315 surface_type, |
299 EGL_NONE}; | 316 EGL_NONE}; |
300 | 317 |
301 EGLint* choose_attributes = config_attribs_8888; | 318 EGLint* choose_attributes = config_attribs_8888; |
302 if (want_rgb565) { | 319 if (want_rgb565) { |
303 choose_attributes = config_attribs_565; | 320 choose_attributes = config_attribs_565; |
304 } | 321 } |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 g_egl_create_context_bind_generates_resource_supported = | 515 g_egl_create_context_bind_generates_resource_supported = |
499 HasEGLExtension("EGL_CHROMIUM_create_context_bind_generates_resource"); | 516 HasEGLExtension("EGL_CHROMIUM_create_context_bind_generates_resource"); |
500 g_egl_create_context_webgl_compatability_supported = | 517 g_egl_create_context_webgl_compatability_supported = |
501 HasEGLExtension("EGL_ANGLE_create_context_webgl_compatibility"); | 518 HasEGLExtension("EGL_ANGLE_create_context_webgl_compatibility"); |
502 g_egl_sync_control_supported = | 519 g_egl_sync_control_supported = |
503 HasEGLExtension("EGL_CHROMIUM_sync_control"); | 520 HasEGLExtension("EGL_CHROMIUM_sync_control"); |
504 g_egl_window_fixed_size_supported = | 521 g_egl_window_fixed_size_supported = |
505 HasEGLExtension("EGL_ANGLE_window_fixed_size"); | 522 HasEGLExtension("EGL_ANGLE_window_fixed_size"); |
506 g_egl_surface_orientation_supported = | 523 g_egl_surface_orientation_supported = |
507 HasEGLExtension("EGL_ANGLE_surface_orientation"); | 524 HasEGLExtension("EGL_ANGLE_surface_orientation"); |
| 525 // TODO(klausw): According to |
| 526 // https://source.android.com/compatibility/android-cdd.html |
| 527 // the EGL_IMG_context_priority extension is mandatory for |
| 528 // Virtual Reality High Performance support, but it's not |
| 529 // showing in the list of reported EGL extensions? |
| 530 g_egl_context_priority_supported = |
| 531 HasEGLExtension("EGL_IMG_context_priority"); |
508 | 532 |
509 // Need EGL_ANGLE_flexible_surface_compatibility to allow surfaces with and | 533 // Need EGL_ANGLE_flexible_surface_compatibility to allow surfaces with and |
510 // without alpha to be bound to the same context. | 534 // without alpha to be bound to the same context. |
511 g_use_direct_composition = | 535 g_use_direct_composition = |
512 HasEGLExtension("EGL_ANGLE_direct_composition") && | 536 HasEGLExtension("EGL_ANGLE_direct_composition") && |
513 HasEGLExtension("EGL_ANGLE_flexible_surface_compatibility") && | 537 HasEGLExtension("EGL_ANGLE_flexible_surface_compatibility") && |
514 !base::CommandLine::ForCurrentProcess()->HasSwitch( | 538 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
515 switches::kDisableDirectComposition); | 539 switches::kDisableDirectComposition); |
516 | 540 |
517 // TODO(oetuaho@nvidia.com): Surfaceless is disabled on Android as a temporary | 541 // TODO(oetuaho@nvidia.com): Surfaceless is disabled on Android as a temporary |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 bool GLSurfaceEGL::IsCreateContextWebGLCompatabilitySupported() { | 626 bool GLSurfaceEGL::IsCreateContextWebGLCompatabilitySupported() { |
603 return g_egl_create_context_webgl_compatability_supported; | 627 return g_egl_create_context_webgl_compatability_supported; |
604 } | 628 } |
605 | 629 |
606 // static | 630 // static |
607 bool GLSurfaceEGL::IsEGLSurfacelessContextSupported() { | 631 bool GLSurfaceEGL::IsEGLSurfacelessContextSupported() { |
608 return g_egl_surfaceless_context_supported; | 632 return g_egl_surfaceless_context_supported; |
609 } | 633 } |
610 | 634 |
611 // static | 635 // static |
| 636 bool GLSurfaceEGL::IsEGLContextPrioritySupported() { |
| 637 return g_egl_context_priority_supported; |
| 638 } |
| 639 |
| 640 // static |
612 bool GLSurfaceEGL::IsDirectCompositionSupported() { | 641 bool GLSurfaceEGL::IsDirectCompositionSupported() { |
613 return g_use_direct_composition; | 642 return g_use_direct_composition; |
614 } | 643 } |
615 | 644 |
616 GLSurfaceEGL::~GLSurfaceEGL() {} | 645 GLSurfaceEGL::~GLSurfaceEGL() {} |
617 | 646 |
618 // InitializeDisplay is necessary because the static binding code | 647 // InitializeDisplay is necessary because the static binding code |
619 // needs a full Display init before it can query the Display extensions. | 648 // needs a full Display init before it can query the Display extensions. |
620 // static | 649 // static |
621 EGLDisplay GLSurfaceEGL::InitializeDisplay( | 650 EGLDisplay GLSurfaceEGL::InitializeDisplay( |
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1241 } | 1270 } |
1242 | 1271 |
1243 void* SurfacelessEGL::GetShareHandle() { | 1272 void* SurfacelessEGL::GetShareHandle() { |
1244 return NULL; | 1273 return NULL; |
1245 } | 1274 } |
1246 | 1275 |
1247 SurfacelessEGL::~SurfacelessEGL() { | 1276 SurfacelessEGL::~SurfacelessEGL() { |
1248 } | 1277 } |
1249 | 1278 |
1250 } // namespace gl | 1279 } // namespace gl |
OLD | NEW |