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; | |
138 bool g_use_direct_composition = false; | 137 bool g_use_direct_composition = false; |
139 | 138 |
140 base::LazyInstance<ANGLEPlatformImpl> g_angle_platform_impl = | 139 base::LazyInstance<ANGLEPlatformImpl> g_angle_platform_impl = |
141 LAZY_INSTANCE_INITIALIZER; | 140 LAZY_INSTANCE_INITIALIZER; |
142 ANGLEPlatformShutdownFunc g_angle_platform_shutdown = nullptr; | 141 ANGLEPlatformShutdownFunc g_angle_platform_shutdown = nullptr; |
143 | 142 |
144 EGLDisplay GetPlatformANGLEDisplay(EGLNativeDisplayType native_display, | 143 EGLDisplay GetPlatformANGLEDisplay(EGLNativeDisplayType native_display, |
145 EGLenum platform_type, | 144 EGLenum platform_type, |
146 bool warpDevice) { | 145 bool warpDevice) { |
147 std::vector<EGLint> display_attribs; | 146 std::vector<EGLint> display_attribs; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 } | 235 } |
237 if (*num_configs == 0) { | 236 if (*num_configs == 0) { |
238 return false; | 237 return false; |
239 } | 238 } |
240 return true; | 239 return true; |
241 } | 240 } |
242 | 241 |
243 EGLConfig ChooseConfig(GLSurfaceFormat format) { | 242 EGLConfig ChooseConfig(GLSurfaceFormat format) { |
244 // Choose an EGL configuration. | 243 // Choose an EGL configuration. |
245 // On X this is only used for PBuffer surfaces. | 244 // On X this is only used for PBuffer surfaces. |
246 | |
247 std::vector<EGLint> renderable_types; | 245 std::vector<EGLint> renderable_types; |
248 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 246 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
249 switches::kDisableES3GLContext)) { | 247 switches::kDisableES3GLContext)) { |
250 renderable_types.push_back(EGL_OPENGL_ES3_BIT); | 248 renderable_types.push_back(EGL_OPENGL_ES3_BIT); |
251 } | 249 } |
252 renderable_types.push_back(EGL_OPENGL_ES2_BIT); | 250 renderable_types.push_back(EGL_OPENGL_ES2_BIT); |
253 | 251 |
254 EGLint buffer_size = format.GetBufferSize(); | 252 EGLint buffer_size = format.GetBufferSize(); |
255 EGLint alpha_size = 8; | 253 EGLint alpha_size = 8; |
256 bool want_rgb565 = buffer_size == 16; | 254 bool want_rgb565 = buffer_size == 16; |
257 EGLint depth_size = format.GetDepthBits(); | |
258 EGLint stencil_size = format.GetStencilBits(); | |
259 EGLint samples = format.GetSamples(); | |
260 | 255 |
261 #if defined(USE_X11) && !defined(OS_CHROMEOS) | 256 #if defined(USE_X11) && !defined(OS_CHROMEOS) |
262 // If we're using ANGLE_NULL, we may not have a display, in which case we | 257 // If we're using ANGLE_NULL, we may not have a display, in which case we |
263 // can't use XVisualManager. | 258 // can't use XVisualManager. |
264 if (g_native_display) { | 259 if (g_native_display) { |
265 ui::XVisualManager::GetInstance()->ChooseVisualForWindow( | 260 ui::XVisualManager::GetInstance()->ChooseVisualForWindow( |
266 true, nullptr, &buffer_size, nullptr, nullptr); | 261 true, nullptr, &buffer_size, nullptr, nullptr); |
267 alpha_size = buffer_size == 32 ? 8 : 0; | 262 alpha_size = buffer_size == 32 ? 8 : 0; |
268 } | 263 } |
269 #endif | 264 #endif |
270 | 265 |
271 EGLint surface_type = (format.IsSurfaceless() | 266 EGLint surface_type = (format.IsSurfaceless() |
272 ? EGL_DONT_CARE | 267 ? EGL_DONT_CARE |
273 : EGL_WINDOW_BIT | EGL_PBUFFER_BIT); | 268 : EGL_WINDOW_BIT | EGL_PBUFFER_BIT); |
274 | 269 |
275 for (auto renderable_type : renderable_types) { | 270 for (auto renderable_type : renderable_types) { |
276 EGLint config_attribs_8888[] = {EGL_BUFFER_SIZE, | 271 EGLint config_attribs_8888[] = {EGL_BUFFER_SIZE, |
277 buffer_size, | 272 buffer_size, |
278 EGL_ALPHA_SIZE, | 273 EGL_ALPHA_SIZE, |
279 alpha_size, | 274 alpha_size, |
280 EGL_BLUE_SIZE, | 275 EGL_BLUE_SIZE, |
281 8, | 276 8, |
282 EGL_GREEN_SIZE, | 277 EGL_GREEN_SIZE, |
283 8, | 278 8, |
284 EGL_RED_SIZE, | 279 EGL_RED_SIZE, |
285 8, | 280 8, |
286 EGL_SAMPLES, | |
287 samples, | |
288 EGL_DEPTH_SIZE, | |
289 depth_size, | |
290 EGL_STENCIL_SIZE, | |
291 stencil_size, | |
292 EGL_RENDERABLE_TYPE, | 281 EGL_RENDERABLE_TYPE, |
293 renderable_type, | 282 renderable_type, |
294 EGL_SURFACE_TYPE, | 283 EGL_SURFACE_TYPE, |
295 surface_type, | 284 surface_type, |
296 EGL_NONE}; | 285 EGL_NONE}; |
297 | 286 |
298 EGLint config_attribs_565[] = {EGL_BUFFER_SIZE, | 287 EGLint config_attribs_565[] = {EGL_BUFFER_SIZE, |
299 16, | 288 16, |
300 EGL_BLUE_SIZE, | 289 EGL_BLUE_SIZE, |
301 5, | 290 5, |
302 EGL_GREEN_SIZE, | 291 EGL_GREEN_SIZE, |
303 6, | 292 6, |
304 EGL_RED_SIZE, | 293 EGL_RED_SIZE, |
305 5, | 294 5, |
306 EGL_SAMPLES, | |
307 samples, | |
308 EGL_DEPTH_SIZE, | |
309 depth_size, | |
310 EGL_STENCIL_SIZE, | |
311 stencil_size, | |
312 EGL_RENDERABLE_TYPE, | 295 EGL_RENDERABLE_TYPE, |
313 renderable_type, | 296 renderable_type, |
314 EGL_SURFACE_TYPE, | 297 EGL_SURFACE_TYPE, |
315 surface_type, | 298 surface_type, |
316 EGL_NONE}; | 299 EGL_NONE}; |
317 | 300 |
318 EGLint* choose_attributes = config_attribs_8888; | 301 EGLint* choose_attributes = config_attribs_8888; |
319 if (want_rgb565) { | 302 if (want_rgb565) { |
320 choose_attributes = config_attribs_565; | 303 choose_attributes = config_attribs_565; |
321 } | 304 } |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 g_egl_create_context_bind_generates_resource_supported = | 498 g_egl_create_context_bind_generates_resource_supported = |
516 HasEGLExtension("EGL_CHROMIUM_create_context_bind_generates_resource"); | 499 HasEGLExtension("EGL_CHROMIUM_create_context_bind_generates_resource"); |
517 g_egl_create_context_webgl_compatability_supported = | 500 g_egl_create_context_webgl_compatability_supported = |
518 HasEGLExtension("EGL_ANGLE_create_context_webgl_compatibility"); | 501 HasEGLExtension("EGL_ANGLE_create_context_webgl_compatibility"); |
519 g_egl_sync_control_supported = | 502 g_egl_sync_control_supported = |
520 HasEGLExtension("EGL_CHROMIUM_sync_control"); | 503 HasEGLExtension("EGL_CHROMIUM_sync_control"); |
521 g_egl_window_fixed_size_supported = | 504 g_egl_window_fixed_size_supported = |
522 HasEGLExtension("EGL_ANGLE_window_fixed_size"); | 505 HasEGLExtension("EGL_ANGLE_window_fixed_size"); |
523 g_egl_surface_orientation_supported = | 506 g_egl_surface_orientation_supported = |
524 HasEGLExtension("EGL_ANGLE_surface_orientation"); | 507 HasEGLExtension("EGL_ANGLE_surface_orientation"); |
525 // According to | |
526 // https://source.android.com/compatibility/android-cdd.html the | |
527 // EGL_IMG_context_priority extension is mandatory for Virtual | |
528 // Reality High Performance support, but it's not showing in the | |
529 // list of reported EGL extensions even though it's supported on | |
530 // Daydream ready devices. As a fallback, check if other related | |
531 // extensions that were added for VR support are present, and assume | |
532 // that this implies context priority is also supported. | |
533 // TODO(klausw): is there a better way to do this? Filed | |
534 // https://github.com/googlevr/gvr-android-sdk/issues/330 for | |
535 // followup. | |
536 g_egl_context_priority_supported = | |
537 HasEGLExtension("EGL_IMG_context_priority") || ( | |
538 HasEGLExtension("EGL_ANDROID_front_buffer_auto_refresh") && | |
539 HasEGLExtension("EGL_ANDROID_create_native_client_buffer")); | |
540 | 508 |
541 // Need EGL_ANGLE_flexible_surface_compatibility to allow surfaces with and | 509 // Need EGL_ANGLE_flexible_surface_compatibility to allow surfaces with and |
542 // without alpha to be bound to the same context. | 510 // without alpha to be bound to the same context. |
543 g_use_direct_composition = | 511 g_use_direct_composition = |
544 HasEGLExtension("EGL_ANGLE_direct_composition") && | 512 HasEGLExtension("EGL_ANGLE_direct_composition") && |
545 HasEGLExtension("EGL_ANGLE_flexible_surface_compatibility") && | 513 HasEGLExtension("EGL_ANGLE_flexible_surface_compatibility") && |
546 !base::CommandLine::ForCurrentProcess()->HasSwitch( | 514 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
547 switches::kDisableDirectComposition); | 515 switches::kDisableDirectComposition); |
548 | 516 |
549 // TODO(oetuaho@nvidia.com): Surfaceless is disabled on Android as a temporary | 517 // TODO(oetuaho@nvidia.com): Surfaceless is disabled on Android as a temporary |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 eglTerminate(g_display); | 557 eglTerminate(g_display); |
590 g_display = EGL_NO_DISPLAY; | 558 g_display = EGL_NO_DISPLAY; |
591 | 559 |
592 g_egl_extensions = nullptr; | 560 g_egl_extensions = nullptr; |
593 g_egl_create_context_robustness_supported = false; | 561 g_egl_create_context_robustness_supported = false; |
594 g_egl_create_context_bind_generates_resource_supported = false; | 562 g_egl_create_context_bind_generates_resource_supported = false; |
595 g_egl_create_context_webgl_compatability_supported = false; | 563 g_egl_create_context_webgl_compatability_supported = false; |
596 g_egl_sync_control_supported = false; | 564 g_egl_sync_control_supported = false; |
597 g_egl_window_fixed_size_supported = false; | 565 g_egl_window_fixed_size_supported = false; |
598 g_egl_surface_orientation_supported = false; | 566 g_egl_surface_orientation_supported = false; |
599 g_egl_context_priority_supported = false; | |
600 g_use_direct_composition = false; | 567 g_use_direct_composition = false; |
601 g_egl_surfaceless_context_supported = false; | 568 g_egl_surfaceless_context_supported = false; |
602 | 569 |
603 initialized_ = false; | 570 initialized_ = false; |
604 } | 571 } |
605 | 572 |
606 // static | 573 // static |
607 EGLDisplay GLSurfaceEGL::GetHardwareDisplay() { | 574 EGLDisplay GLSurfaceEGL::GetHardwareDisplay() { |
608 return g_display; | 575 return g_display; |
609 } | 576 } |
(...skipping 25 matching lines...) Expand all Loading... |
635 bool GLSurfaceEGL::IsCreateContextWebGLCompatabilitySupported() { | 602 bool GLSurfaceEGL::IsCreateContextWebGLCompatabilitySupported() { |
636 return g_egl_create_context_webgl_compatability_supported; | 603 return g_egl_create_context_webgl_compatability_supported; |
637 } | 604 } |
638 | 605 |
639 // static | 606 // static |
640 bool GLSurfaceEGL::IsEGLSurfacelessContextSupported() { | 607 bool GLSurfaceEGL::IsEGLSurfacelessContextSupported() { |
641 return g_egl_surfaceless_context_supported; | 608 return g_egl_surfaceless_context_supported; |
642 } | 609 } |
643 | 610 |
644 // static | 611 // static |
645 bool GLSurfaceEGL::IsEGLContextPrioritySupported() { | |
646 return g_egl_context_priority_supported; | |
647 } | |
648 | |
649 // static | |
650 bool GLSurfaceEGL::IsDirectCompositionSupported() { | 612 bool GLSurfaceEGL::IsDirectCompositionSupported() { |
651 return g_use_direct_composition; | 613 return g_use_direct_composition; |
652 } | 614 } |
653 | 615 |
654 GLSurfaceEGL::~GLSurfaceEGL() {} | 616 GLSurfaceEGL::~GLSurfaceEGL() {} |
655 | 617 |
656 // InitializeDisplay is necessary because the static binding code | 618 // InitializeDisplay is necessary because the static binding code |
657 // needs a full Display init before it can query the Display extensions. | 619 // needs a full Display init before it can query the Display extensions. |
658 // static | 620 // static |
659 EGLDisplay GLSurfaceEGL::InitializeDisplay( | 621 EGLDisplay GLSurfaceEGL::InitializeDisplay( |
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1279 } | 1241 } |
1280 | 1242 |
1281 void* SurfacelessEGL::GetShareHandle() { | 1243 void* SurfacelessEGL::GetShareHandle() { |
1282 return NULL; | 1244 return NULL; |
1283 } | 1245 } |
1284 | 1246 |
1285 SurfacelessEGL::~SurfacelessEGL() { | 1247 SurfacelessEGL::~SurfacelessEGL() { |
1286 } | 1248 } |
1287 | 1249 |
1288 } // namespace gl | 1250 } // namespace gl |
OLD | NEW |