blob: 0297efe85a1e8ffa4b5dc17b571963bb586bf97b [file] [log] [blame]
geofflangdf7fff2d42016-11-11 00:34:031// 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
geofflang3ab039d2017-02-22 15:33:587#include "base/command_line.h"
geofflangdf7fff2d42016-11-11 00:34:038#include "gpu/command_buffer/common/gles2_cmd_utils.h"
Geoff Lang619081b2017-08-31 19:23:319#include "gpu/command_buffer/service/context_group.h"
geofflang3ab039d2017-02-22 15:33:5810#include "ui/gl/gl_switches.h"
geofflangdf7fff2d42016-11-11 00:34:0311
Geoff Lang619081b2017-08-31 19:23:3112#if defined(USE_EGL)
13#include "ui/gl/gl_surface_egl.h"
14#endif // defined(USE_EGL)
15
geofflangdf7fff2d42016-11-11 00:34:0316namespace gpu {
17namespace gles2 {
18
19gl::GLContextAttribs GenerateGLContextAttribs(
20 const ContextCreationAttribHelper& attribs_helper,
Geoff Lang619081b2017-08-31 19:23:3121 const ContextGroup* context_group) {
22 DCHECK(context_group != nullptr);
geofflangdf7fff2d42016-11-11 00:34:0323 gl::GLContextAttribs attribs;
24 attribs.gpu_preference = attribs_helper.gpu_preference;
Geoff Lang619081b2017-08-31 19:23:3125 if (context_group->use_passthrough_cmd_decoder()) {
geofflangdf7fff2d42016-11-11 00:34:0326 attribs.bind_generates_resource = attribs_helper.bind_generates_resource;
27 attribs.webgl_compatibility_context =
28 IsWebGLContextType(attribs_helper.context_type);
geofflang3ab039d2017-02-22 15:33:5829
30 // Always use the global texture share group for the passthrough command
31 // decoder
32 attribs.global_texture_share_group = true;
33
Geoff Lang7f82ef42017-09-23 17:56:0234 attribs.robust_resource_initialization = true;
35
geofflang3ab039d2017-02-22 15:33:5836 // 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;
geofflangdf7fff2d42016-11-11 00:34:0348 }
geofflang3ab039d2017-02-22 15:33:5849
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
geofflangdf7fff2d42016-11-11 00:34:0357 return attribs;
58}
59
Geoff Lang619081b2017-08-31 19:23:3160bool 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 Lang7f82ef42017-09-23 17:56:0266 (gl::GLSurfaceEGL::IsRobustResourceInitSupported() ||
67 gl::GLSurfaceEGL::IsDisplayRobustResourceInitSupported()) &&
Geoff Lang619081b2017-08-31 19:23:3168 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
geofflangdf7fff2d42016-11-11 00:34:0376} // namespace gles2
77} // namespace gpu