Chromium Code Reviews| 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_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" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 #ifndef EGL_CHROMIUM_create_context_bind_generates_resource | 25 #ifndef EGL_CHROMIUM_create_context_bind_generates_resource |
| 26 #define EGL_CHROMIUM_create_context_bind_generates_resource 1 | 26 #define EGL_CHROMIUM_create_context_bind_generates_resource 1 |
| 27 #define EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM 0x3AAD | 27 #define EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM 0x3AAD |
| 28 #endif /* EGL_CHROMIUM_create_context_bind_generates_resource */ | 28 #endif /* EGL_CHROMIUM_create_context_bind_generates_resource */ |
| 29 | 29 |
| 30 #ifndef EGL_ANGLE_create_context_webgl_compatibility | 30 #ifndef EGL_ANGLE_create_context_webgl_compatibility |
| 31 #define EGL_ANGLE_create_context_webgl_compatibility 1 | 31 #define EGL_ANGLE_create_context_webgl_compatibility 1 |
| 32 #define EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE 0x3AAC | 32 #define EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE 0x3AAC |
| 33 #endif /* EGL_ANGLE_create_context_webgl_compatibility */ | 33 #endif /* EGL_ANGLE_create_context_webgl_compatibility */ |
| 34 | 34 |
| 35 #ifndef EGL_ANGLE_display_texture_share_group | |
| 36 #define EGL_ANGLE_display_texture_share_group 1 | |
| 37 #define EGL_DISPLAY_TEXTURE_SHARE_GROUP_ANGLE 0x3AAF | |
| 38 #endif /* EGL_ANGLE_display_texture_share_group */ | |
| 39 | |
| 35 using ui::GetLastEGLErrorString; | 40 using ui::GetLastEGLErrorString; |
| 36 | 41 |
| 37 namespace gl { | 42 namespace gl { |
| 38 | 43 |
| 39 GLContextEGL::GLContextEGL(GLShareGroup* share_group) | 44 GLContextEGL::GLContextEGL(GLShareGroup* share_group) |
| 40 : GLContextReal(share_group), | 45 : GLContextReal(share_group), |
| 41 context_(nullptr), | 46 context_(nullptr), |
| 42 display_(nullptr), | 47 display_(nullptr), |
| 43 config_(nullptr), | 48 config_(nullptr), |
| 44 unbind_fbo_on_makecurrent_(false), | 49 unbind_fbo_on_makecurrent_(false), |
| 45 swap_interval_(1) { | 50 swap_interval_(1) { |
| 46 } | 51 } |
| 47 | 52 |
| 48 bool GLContextEGL::Initialize(GLSurface* compatible_surface, | 53 bool GLContextEGL::Initialize(GLSurface* compatible_surface, |
| 49 const GLContextAttribs& attribs) { | 54 const GLContextAttribs& attribs) { |
| 50 DCHECK(compatible_surface); | 55 DCHECK(compatible_surface); |
| 51 DCHECK(!context_); | 56 DCHECK(!context_); |
| 52 | 57 |
| 53 display_ = compatible_surface->GetDisplay(); | 58 display_ = compatible_surface->GetDisplay(); |
| 54 config_ = compatible_surface->GetConfig(); | 59 config_ = compatible_surface->GetConfig(); |
| 55 | 60 |
| 56 EGLint config_renderable_type = 0; | 61 EGLint config_renderable_type = 0; |
| 57 if (!eglGetConfigAttrib(display_, config_, EGL_RENDERABLE_TYPE, | 62 if (!eglGetConfigAttrib(display_, config_, EGL_RENDERABLE_TYPE, |
| 58 &config_renderable_type)) { | 63 &config_renderable_type)) { |
| 59 LOG(ERROR) << "eglGetConfigAttrib failed with error " | 64 LOG(ERROR) << "eglGetConfigAttrib failed with error " |
| 60 << GetLastEGLErrorString(); | 65 << GetLastEGLErrorString(); |
| 61 return false; | 66 return false; |
| 62 } | 67 } |
| 63 | 68 |
| 64 EGLint context_client_version = 2; | 69 EGLint context_client_major_version = attribs.client_major_es_version; |
| 65 if ((config_renderable_type & EGL_OPENGL_ES3_BIT) != 0 && | 70 EGLint context_client_minor_version = attribs.client_minor_es_version; |
| 66 !base::CommandLine::ForCurrentProcess()->HasSwitch( | 71 |
| 67 switches::kDisableES3GLContext)) { | 72 // If the requested context is ES3 but the config cannot support ES3, request |
| 68 context_client_version = 3; | 73 // ES2 instead. |
| 74 if ((config_renderable_type & EGL_OPENGL_ES3_BIT) == 0 && | |
| 75 context_client_major_version >= 3) { | |
| 76 context_client_major_version = 2; | |
| 77 context_client_minor_version = 0; | |
|
Zhenyao Mo
2017/02/16 22:43:11
Should we fail here and let the caller decides wha
Geoff Lang
2017/02/21 20:35:32
Yea, I think it would make sense to first ask to s
| |
| 69 } | 78 } |
| 70 | 79 |
| 71 std::vector<EGLint> context_attributes; | 80 std::vector<EGLint> context_attributes; |
| 72 context_attributes.push_back(EGL_CONTEXT_CLIENT_VERSION); | 81 |
| 73 context_attributes.push_back(context_client_version); | 82 // EGL_KHR_create_context allows requesting both a major and minor context |
| 83 // version | |
| 84 if (GLSurfaceEGL::HasEGLExtension("EGL_KHR_create_context")) { | |
| 85 context_attributes.push_back(EGL_CONTEXT_MAJOR_VERSION); | |
| 86 context_attributes.push_back(context_client_major_version); | |
| 87 | |
| 88 context_attributes.push_back(EGL_CONTEXT_MINOR_VERSION); | |
| 89 context_attributes.push_back(context_client_minor_version); | |
| 90 } else { | |
| 91 context_attributes.push_back(EGL_CONTEXT_CLIENT_VERSION); | |
| 92 context_attributes.push_back(context_client_major_version); | |
| 93 | |
| 94 // Can only request 2.0 or 3.0 contexts without the EGL_KHR_create_context | |
| 95 // extension, DCHECK to make sure we update the code to support devices | |
| 96 // without this extension | |
| 97 DCHECK(context_client_minor_version == 0); | |
| 98 } | |
| 74 | 99 |
| 75 if (GLSurfaceEGL::IsCreateContextRobustnessSupported()) { | 100 if (GLSurfaceEGL::IsCreateContextRobustnessSupported()) { |
| 76 DVLOG(1) << "EGL_EXT_create_context_robustness supported."; | 101 DVLOG(1) << "EGL_EXT_create_context_robustness supported."; |
| 77 context_attributes.push_back( | 102 context_attributes.push_back( |
| 78 EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT); | 103 EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT); |
| 79 context_attributes.push_back(EGL_LOSE_CONTEXT_ON_RESET_EXT); | 104 context_attributes.push_back(EGL_LOSE_CONTEXT_ON_RESET_EXT); |
| 80 } else { | 105 } else { |
| 81 // At some point we should require the presence of the robustness | 106 // At some point we should require the presence of the robustness |
| 82 // extension and remove this code path. | 107 // extension and remove this code path. |
| 83 DVLOG(1) << "EGL_EXT_create_context_robustness NOT supported."; | 108 DVLOG(1) << "EGL_EXT_create_context_robustness NOT supported."; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 98 } | 123 } |
| 99 | 124 |
| 100 if (GLSurfaceEGL::IsCreateContextWebGLCompatabilitySupported()) { | 125 if (GLSurfaceEGL::IsCreateContextWebGLCompatabilitySupported()) { |
| 101 context_attributes.push_back(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE); | 126 context_attributes.push_back(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE); |
| 102 context_attributes.push_back( | 127 context_attributes.push_back( |
| 103 attribs.webgl_compatibility_context ? EGL_TRUE : EGL_FALSE); | 128 attribs.webgl_compatibility_context ? EGL_TRUE : EGL_FALSE); |
| 104 } else { | 129 } else { |
| 105 DCHECK(!attribs.webgl_compatibility_context); | 130 DCHECK(!attribs.webgl_compatibility_context); |
| 106 } | 131 } |
| 107 | 132 |
| 133 if (GLSurfaceEGL::HasEGLExtension("EGL_ANGLE_display_texture_share_group")) { | |
| 134 context_attributes.push_back(EGL_DISPLAY_TEXTURE_SHARE_GROUP_ANGLE); | |
| 135 context_attributes.push_back( | |
| 136 attribs.global_texture_share_group ? EGL_TRUE : EGL_FALSE); | |
| 137 } else { | |
| 138 DCHECK(!attribs.global_texture_share_group); | |
| 139 } | |
| 140 | |
| 108 // Append final EGL_NONE to signal the context attributes are finished | 141 // Append final EGL_NONE to signal the context attributes are finished |
| 109 context_attributes.push_back(EGL_NONE); | 142 context_attributes.push_back(EGL_NONE); |
| 110 context_attributes.push_back(EGL_NONE); | 143 context_attributes.push_back(EGL_NONE); |
| 111 | 144 |
| 112 context_ = eglCreateContext( | 145 context_ = eglCreateContext( |
| 113 display_, config_, share_group() ? share_group()->GetHandle() : nullptr, | 146 display_, config_, share_group() ? share_group()->GetHandle() : nullptr, |
| 114 context_attributes.data()); | 147 context_attributes.data()); |
| 115 | 148 |
| 116 if (!context_) { | 149 if (!context_) { |
| 117 LOG(ERROR) << "eglCreateContext failed with error " | 150 LOG(ERROR) << "eglCreateContext failed with error " |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 | 277 |
| 245 bool GLContextEGL::WasAllocatedUsingRobustnessExtension() { | 278 bool GLContextEGL::WasAllocatedUsingRobustnessExtension() { |
| 246 return GLSurfaceEGL::IsCreateContextRobustnessSupported(); | 279 return GLSurfaceEGL::IsCreateContextRobustnessSupported(); |
| 247 } | 280 } |
| 248 | 281 |
| 249 GLContextEGL::~GLContextEGL() { | 282 GLContextEGL::~GLContextEGL() { |
| 250 Destroy(); | 283 Destroy(); |
| 251 } | 284 } |
| 252 | 285 |
| 253 } // namespace gl | 286 } // namespace gl |
| OLD | NEW |