Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: ui/gl/gl_context_egl.cc

Issue 2480373002: Refactor context creation parameters into a struct. (Closed)
Patch Set: address piman's comments Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_context_egl.h" 5 #include "ui/gl/gl_context_egl.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/trace_event/trace_event.h" 11 #include "base/trace_event/trace_event.h"
12 #include "build/build_config.h" 12 #include "build/build_config.h"
13 #include "third_party/khronos/EGL/egl.h" 13 #include "third_party/khronos/EGL/egl.h"
14 #include "third_party/khronos/EGL/eglext.h" 14 #include "third_party/khronos/EGL/eglext.h"
15 #include "ui/gl/egl_util.h" 15 #include "ui/gl/egl_util.h"
16 #include "ui/gl/gl_bindings.h" 16 #include "ui/gl/gl_bindings.h"
17 #include "ui/gl/gl_surface_egl.h" 17 #include "ui/gl/gl_surface_egl.h"
18 18
19 #if defined(USE_X11) 19 #if defined(USE_X11)
20 extern "C" { 20 extern "C" {
21 #include <X11/Xlib.h> 21 #include <X11/Xlib.h>
22 } 22 }
23 #endif 23 #endif
24 24
25 #ifndef EGL_CHROMIUM_create_context_bind_generates_resource
26 #define EGL_CHROMIUM_create_context_bind_generates_resource 1
27 #define EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM 0x3AAD
28 #endif /* EGL_CHROMIUM_create_context_bind_generates_resource */
29
30 #ifndef EGL_ANGLE_create_context_webgl_compatibility
31 #define EGL_ANGLE_create_context_webgl_compatibility 1
32 #define EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE 0x3AAC
33 #endif /* EGL_ANGLE_create_context_webgl_compatibility */
34
25 using ui::GetLastEGLErrorString; 35 using ui::GetLastEGLErrorString;
26 36
27 namespace gl { 37 namespace gl {
28 38
29 GLContextEGL::GLContextEGL(GLShareGroup* share_group) 39 GLContextEGL::GLContextEGL(GLShareGroup* share_group)
30 : GLContextReal(share_group), 40 : GLContextReal(share_group),
31 context_(nullptr), 41 context_(nullptr),
32 display_(nullptr), 42 display_(nullptr),
33 config_(nullptr), 43 config_(nullptr),
34 unbind_fbo_on_makecurrent_(false), 44 unbind_fbo_on_makecurrent_(false),
35 swap_interval_(1) { 45 swap_interval_(1) {
36 } 46 }
37 47
38 bool GLContextEGL::Initialize( 48 bool GLContextEGL::Initialize(GLSurface* compatible_surface,
39 GLSurface* compatible_surface, GpuPreference gpu_preference) { 49 const GLContextAttribs& attribs) {
40 DCHECK(compatible_surface); 50 DCHECK(compatible_surface);
41 DCHECK(!context_); 51 DCHECK(!context_);
42 52
43 display_ = compatible_surface->GetDisplay(); 53 display_ = compatible_surface->GetDisplay();
44 config_ = compatible_surface->GetConfig(); 54 config_ = compatible_surface->GetConfig();
45 55
46 EGLint config_renderable_type = 0; 56 EGLint config_renderable_type = 0;
47 if (!eglGetConfigAttrib(display_, config_, EGL_RENDERABLE_TYPE, 57 if (!eglGetConfigAttrib(display_, config_, EGL_RENDERABLE_TYPE,
48 &config_renderable_type)) { 58 &config_renderable_type)) {
49 LOG(ERROR) << "eglGetConfigAttrib failed with error " 59 LOG(ERROR) << "eglGetConfigAttrib failed with error "
50 << GetLastEGLErrorString(); 60 << GetLastEGLErrorString();
51 return false; 61 return false;
52 } 62 }
53 63
54 EGLint context_client_version = 2; 64 EGLint context_client_version = 2;
55 if ((config_renderable_type & EGL_OPENGL_ES3_BIT) != 0 && 65 if ((config_renderable_type & EGL_OPENGL_ES3_BIT) != 0 &&
56 !base::CommandLine::ForCurrentProcess()->HasSwitch( 66 !base::CommandLine::ForCurrentProcess()->HasSwitch(
57 switches::kDisableES3GLContext)) { 67 switches::kDisableES3GLContext)) {
58 context_client_version = 3; 68 context_client_version = 3;
59 } 69 }
60 70
61 const EGLint kContextAttributes[] = { 71 std::vector<EGLint> context_attributes;
62 EGL_CONTEXT_CLIENT_VERSION, context_client_version, 72 context_attributes.push_back(EGL_CONTEXT_CLIENT_VERSION);
63 EGL_NONE 73 context_attributes.push_back(context_client_version);
64 };
65 const EGLint kContextRobustnessAttributes[] = {
66 EGL_CONTEXT_CLIENT_VERSION, context_client_version,
67 EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT,
68 EGL_LOSE_CONTEXT_ON_RESET_EXT,
69 EGL_NONE
70 };
71 74
72 const EGLint* context_attributes = nullptr;
73 if (GLSurfaceEGL::IsCreateContextRobustnessSupported()) { 75 if (GLSurfaceEGL::IsCreateContextRobustnessSupported()) {
74 DVLOG(1) << "EGL_EXT_create_context_robustness supported."; 76 DVLOG(1) << "EGL_EXT_create_context_robustness supported.";
75 context_attributes = kContextRobustnessAttributes;
76 } else { 77 } else {
77 // At some point we should require the presence of the robustness 78 // At some point we should require the presence of the robustness
78 // extension and remove this code path. 79 // extension and remove this code path.
79 DVLOG(1) << "EGL_EXT_create_context_robustness NOT supported."; 80 DVLOG(1) << "EGL_EXT_create_context_robustness NOT supported.";
80 context_attributes = kContextAttributes; 81 context_attributes.push_back(
82 EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT);
83 context_attributes.push_back(EGL_LOSE_CONTEXT_ON_RESET_EXT);
81 } 84 }
82 85
83 if (!eglBindAPI(EGL_OPENGL_ES_API)) { 86 if (!eglBindAPI(EGL_OPENGL_ES_API)) {
84 LOG(ERROR) << "eglBindApi failed with error " 87 LOG(ERROR) << "eglBindApi failed with error "
85 << GetLastEGLErrorString(); 88 << GetLastEGLErrorString();
86 return false; 89 return false;
87 } 90 }
88 91
92 if (GLSurfaceEGL::IsCreateContextBindGeneratesResourceSupported()) {
93 context_attributes.push_back(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM);
94 context_attributes.push_back(attribs.bind_generates_resource ? EGL_TRUE
95 : EGL_FALSE);
96 } else {
97 DCHECK(attribs.bind_generates_resource);
98 }
99
100 if (GLSurfaceEGL::IsCreateContextWebGLCompatabilitySupported()) {
101 context_attributes.push_back(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE);
102 context_attributes.push_back(
103 attribs.webgl_compatibility_context ? EGL_TRUE : EGL_FALSE);
104 } else {
105 DCHECK(!attribs.webgl_compatibility_context);
106 }
107
108 // Append final EGL_NONE to signal the context attributes are finished
109 context_attributes.push_back(EGL_NONE);
110 context_attributes.push_back(EGL_NONE);
111
89 context_ = eglCreateContext( 112 context_ = eglCreateContext(
90 display_, 113 display_, config_, share_group() ? share_group()->GetHandle() : nullptr,
91 config_, 114 context_attributes.data());
92 share_group() ? share_group()->GetHandle() : nullptr,
93 context_attributes);
94 115
95 if (!context_) { 116 if (!context_) {
96 LOG(ERROR) << "eglCreateContext failed with error " 117 LOG(ERROR) << "eglCreateContext failed with error "
97 << GetLastEGLErrorString(); 118 << GetLastEGLErrorString();
98 return false; 119 return false;
99 } 120 }
100 121
101 return true; 122 return true;
102 } 123 }
103 124
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 244
224 bool GLContextEGL::WasAllocatedUsingRobustnessExtension() { 245 bool GLContextEGL::WasAllocatedUsingRobustnessExtension() {
225 return GLSurfaceEGL::IsCreateContextRobustnessSupported(); 246 return GLSurfaceEGL::IsCreateContextRobustnessSupported();
226 } 247 }
227 248
228 GLContextEGL::~GLContextEGL() { 249 GLContextEGL::~GLContextEGL() {
229 Destroy(); 250 Destroy();
230 } 251 }
231 252
232 } // namespace gl 253 } // namespace gl
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698