geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 1 | // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "gpu/command_buffer/service/service_utils.h" |
| 6 | |
geofflang | 3ab039d | 2017-02-22 15:33:58 | [diff] [blame] | 7 | #include "base/command_line.h" |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 8 | #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
Geoff Lang | 619081b | 2017-08-31 19:23:31 | [diff] [blame] | 9 | #include "gpu/command_buffer/service/context_group.h" |
geofflang | 3ab039d | 2017-02-22 15:33:58 | [diff] [blame] | 10 | #include "ui/gl/gl_switches.h" |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 11 | |
Geoff Lang | 619081b | 2017-08-31 19:23:31 | [diff] [blame] | 12 | #if defined(USE_EGL) |
| 13 | #include "ui/gl/gl_surface_egl.h" |
| 14 | #endif // defined(USE_EGL) |
| 15 | |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 16 | namespace gpu { |
| 17 | namespace gles2 { |
| 18 | |
| 19 | gl::GLContextAttribs GenerateGLContextAttribs( |
| 20 | const ContextCreationAttribHelper& attribs_helper, |
Geoff Lang | 619081b | 2017-08-31 19:23:31 | [diff] [blame] | 21 | const ContextGroup* context_group) { |
| 22 | DCHECK(context_group != nullptr); |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 23 | gl::GLContextAttribs attribs; |
| 24 | attribs.gpu_preference = attribs_helper.gpu_preference; |
Geoff Lang | 619081b | 2017-08-31 19:23:31 | [diff] [blame] | 25 | if (context_group->use_passthrough_cmd_decoder()) { |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 26 | attribs.bind_generates_resource = attribs_helper.bind_generates_resource; |
| 27 | attribs.webgl_compatibility_context = |
| 28 | IsWebGLContextType(attribs_helper.context_type); |
geofflang | 3ab039d | 2017-02-22 15:33:58 | [diff] [blame] | 29 | |
| 30 | // Always use the global texture share group for the passthrough command |
| 31 | // decoder |
| 32 | attribs.global_texture_share_group = true; |
| 33 | |
Geoff Lang | 7f82ef4 | 2017-09-23 17:56:02 | [diff] [blame^] | 34 | attribs.robust_resource_initialization = true; |
| 35 | |
geofflang | 3ab039d | 2017-02-22 15:33:58 | [diff] [blame] | 36 | // Request a specific context version instead of always 3.0 |
| 37 | if (IsWebGL2OrES3ContextType(attribs_helper.context_type)) { |
| 38 | attribs.client_major_es_version = 3; |
| 39 | attribs.client_minor_es_version = 0; |
| 40 | } else { |
| 41 | DCHECK(IsWebGL1OrES2ContextType(attribs_helper.context_type)); |
| 42 | attribs.client_major_es_version = 2; |
| 43 | attribs.client_minor_es_version = 0; |
| 44 | } |
| 45 | } else { |
| 46 | attribs.client_major_es_version = 3; |
| 47 | attribs.client_minor_es_version = 0; |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 48 | } |
geofflang | 3ab039d | 2017-02-22 15:33:58 | [diff] [blame] | 49 | |
| 50 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 51 | switches::kDisableES3GLContext)) { |
| 52 | // Forcefully disable ES3 contexts |
| 53 | attribs.client_major_es_version = 2; |
| 54 | attribs.client_minor_es_version = 0; |
| 55 | } |
| 56 | |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 57 | return attribs; |
| 58 | } |
| 59 | |
Geoff Lang | 619081b | 2017-08-31 19:23:31 | [diff] [blame] | 60 | bool PassthroughCommandDecoderSupported() { |
| 61 | #if defined(USE_EGL) |
| 62 | // Using the passthrough command buffer requires that specific ANGLE |
| 63 | // extensions are exposed |
| 64 | return gl::GLSurfaceEGL::IsCreateContextBindGeneratesResourceSupported() && |
| 65 | gl::GLSurfaceEGL::IsCreateContextWebGLCompatabilitySupported() && |
Geoff Lang | 7f82ef4 | 2017-09-23 17:56:02 | [diff] [blame^] | 66 | (gl::GLSurfaceEGL::IsRobustResourceInitSupported() || |
| 67 | gl::GLSurfaceEGL::IsDisplayRobustResourceInitSupported()) && |
Geoff Lang | 619081b | 2017-08-31 19:23:31 | [diff] [blame] | 68 | gl::GLSurfaceEGL::IsDisplayTextureShareGroupSupported() && |
| 69 | gl::GLSurfaceEGL::IsCreateContextClientArraysSupported(); |
| 70 | #else |
| 71 | // The passthrough command buffer is only supported on top of ANGLE/EGL |
| 72 | return false; |
| 73 | #endif // defined(USE_EGL) |
| 74 | } // namespace gles2 |
| 75 | |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 76 | } // namespace gles2 |
| 77 | } // namespace gpu |