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

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

Issue 2497503004: Revert of Refactor context creation parameters into a struct. (Closed)
Patch Set: 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
« no previous file with comments | « ui/gl/gl_context_egl.h ('k') | ui/gl/gl_context_glx.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
35 using ui::GetLastEGLErrorString; 25 using ui::GetLastEGLErrorString;
36 26
37 namespace gl { 27 namespace gl {
38 28
39 GLContextEGL::GLContextEGL(GLShareGroup* share_group) 29 GLContextEGL::GLContextEGL(GLShareGroup* share_group)
40 : GLContextReal(share_group), 30 : GLContextReal(share_group),
41 context_(nullptr), 31 context_(nullptr),
42 display_(nullptr), 32 display_(nullptr),
43 config_(nullptr), 33 config_(nullptr),
44 unbind_fbo_on_makecurrent_(false), 34 unbind_fbo_on_makecurrent_(false),
45 swap_interval_(1) { 35 swap_interval_(1) {
46 } 36 }
47 37
48 bool GLContextEGL::Initialize(GLSurface* compatible_surface, 38 bool GLContextEGL::Initialize(
49 const GLContextAttribs& attribs) { 39 GLSurface* compatible_surface, GpuPreference gpu_preference) {
50 DCHECK(compatible_surface); 40 DCHECK(compatible_surface);
51 DCHECK(!context_); 41 DCHECK(!context_);
52 42
53 display_ = compatible_surface->GetDisplay(); 43 display_ = compatible_surface->GetDisplay();
54 config_ = compatible_surface->GetConfig(); 44 config_ = compatible_surface->GetConfig();
55 45
56 EGLint config_renderable_type = 0; 46 EGLint config_renderable_type = 0;
57 if (!eglGetConfigAttrib(display_, config_, EGL_RENDERABLE_TYPE, 47 if (!eglGetConfigAttrib(display_, config_, EGL_RENDERABLE_TYPE,
58 &config_renderable_type)) { 48 &config_renderable_type)) {
59 LOG(ERROR) << "eglGetConfigAttrib failed with error " 49 LOG(ERROR) << "eglGetConfigAttrib failed with error "
60 << GetLastEGLErrorString(); 50 << GetLastEGLErrorString();
61 return false; 51 return false;
62 } 52 }
63 53
64 EGLint context_client_version = 2; 54 EGLint context_client_version = 2;
65 if ((config_renderable_type & EGL_OPENGL_ES3_BIT) != 0 && 55 if ((config_renderable_type & EGL_OPENGL_ES3_BIT) != 0 &&
66 !base::CommandLine::ForCurrentProcess()->HasSwitch( 56 !base::CommandLine::ForCurrentProcess()->HasSwitch(
67 switches::kDisableES3GLContext)) { 57 switches::kDisableES3GLContext)) {
68 context_client_version = 3; 58 context_client_version = 3;
69 } 59 }
70 60
71 std::vector<EGLint> context_attributes; 61 const EGLint kContextAttributes[] = {
72 context_attributes.push_back(EGL_CONTEXT_CLIENT_VERSION); 62 EGL_CONTEXT_CLIENT_VERSION, context_client_version,
73 context_attributes.push_back(context_client_version); 63 EGL_NONE
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 };
74 71
72 const EGLint* context_attributes = nullptr;
75 if (GLSurfaceEGL::IsCreateContextRobustnessSupported()) { 73 if (GLSurfaceEGL::IsCreateContextRobustnessSupported()) {
76 DVLOG(1) << "EGL_EXT_create_context_robustness supported."; 74 DVLOG(1) << "EGL_EXT_create_context_robustness supported.";
75 context_attributes = kContextRobustnessAttributes;
77 } else { 76 } else {
78 // At some point we should require the presence of the robustness 77 // At some point we should require the presence of the robustness
79 // extension and remove this code path. 78 // extension and remove this code path.
80 DVLOG(1) << "EGL_EXT_create_context_robustness NOT supported."; 79 DVLOG(1) << "EGL_EXT_create_context_robustness NOT supported.";
81 context_attributes.push_back( 80 context_attributes = kContextAttributes;
82 EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT);
83 context_attributes.push_back(EGL_LOSE_CONTEXT_ON_RESET_EXT);
84 } 81 }
85 82
86 if (!eglBindAPI(EGL_OPENGL_ES_API)) { 83 if (!eglBindAPI(EGL_OPENGL_ES_API)) {
87 LOG(ERROR) << "eglBindApi failed with error " 84 LOG(ERROR) << "eglBindApi failed with error "
88 << GetLastEGLErrorString(); 85 << GetLastEGLErrorString();
89 return false; 86 return false;
90 } 87 }
91 88
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
112 context_ = eglCreateContext( 89 context_ = eglCreateContext(
113 display_, config_, share_group() ? share_group()->GetHandle() : nullptr, 90 display_,
114 context_attributes.data()); 91 config_,
92 share_group() ? share_group()->GetHandle() : nullptr,
93 context_attributes);
115 94
116 if (!context_) { 95 if (!context_) {
117 LOG(ERROR) << "eglCreateContext failed with error " 96 LOG(ERROR) << "eglCreateContext failed with error "
118 << GetLastEGLErrorString(); 97 << GetLastEGLErrorString();
119 return false; 98 return false;
120 } 99 }
121 100
122 return true; 101 return true;
123 } 102 }
124 103
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 223
245 bool GLContextEGL::WasAllocatedUsingRobustnessExtension() { 224 bool GLContextEGL::WasAllocatedUsingRobustnessExtension() {
246 return GLSurfaceEGL::IsCreateContextRobustnessSupported(); 225 return GLSurfaceEGL::IsCreateContextRobustnessSupported();
247 } 226 }
248 227
249 GLContextEGL::~GLContextEGL() { 228 GLContextEGL::~GLContextEGL() {
250 Destroy(); 229 Destroy();
251 } 230 }
252 231
253 } // namespace gl 232 } // namespace gl
OLDNEW
« no previous file with comments | « ui/gl/gl_context_egl.h ('k') | ui/gl/gl_context_glx.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698