Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_version_info.h" | 5 #include "ui/gl/gl_version_info.h" |
| 6 | 6 |
| 7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "base/strings/string_split.h" | |
| 8 #include "base/strings/string_tokenizer.h" | 9 #include "base/strings/string_tokenizer.h" |
| 9 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 10 | 11 |
| 11 namespace { | 12 namespace { |
| 12 | 13 |
| 13 bool DesktopCoreCommonCheck( | 14 bool DesktopCoreCommonCheck( |
| 14 bool is_es, unsigned major_version, unsigned minor_version) { | 15 bool is_es, unsigned major_version, unsigned minor_version) { |
| 15 return (!is_es && | 16 return (!is_es && |
| 16 ((major_version == 3 && minor_version >= 2) || | 17 ((major_version == 3 && minor_version >= 2) || |
| 17 major_version > 3)); | 18 major_version > 3)); |
| 18 } | 19 } |
| 19 | 20 |
| 20 } | 21 } |
| 21 | 22 |
| 22 namespace gl { | 23 namespace gl { |
| 23 | 24 |
| 24 GLVersionInfo::GLVersionInfo(const char* version_str, const char* renderer_str, | 25 GLVersionInfo::GLVersionInfo(const char* version_str, |
| 26 const char* renderer_str, | |
| 25 const char* extensions_str) | 27 const char* extensions_str) |
| 26 : GLVersionInfo(version_str, renderer_str) { | 28 : GLVersionInfo() { |
| 27 is_desktop_core_profile = | 29 std::set<std::string> extensions; |
| 28 DesktopCoreCommonCheck(is_es, major_version, minor_version) && | 30 if (extensions_str) { |
| 29 !strstr(extensions_str, "GL_ARB_compatibility"); | 31 auto split = base::SplitString(extensions_str, " ", base::KEEP_WHITESPACE, |
| 32 base::SPLIT_WANT_NONEMPTY); | |
| 33 extensions.insert(split.begin(), split.end()); | |
| 34 } | |
| 35 Initialize(version_str, renderer_str, extensions); | |
| 30 } | 36 } |
| 31 | 37 |
| 32 GLVersionInfo::GLVersionInfo(const char* version_str, const char* renderer_str, | 38 GLVersionInfo::GLVersionInfo(const char* version_str, |
| 39 const char* renderer_str, | |
| 33 const std::set<std::string>& extensions) | 40 const std::set<std::string>& extensions) |
| 34 : GLVersionInfo(version_str, renderer_str) { | 41 : GLVersionInfo() { |
| 35 is_desktop_core_profile = | 42 Initialize(version_str, renderer_str, extensions); |
| 36 DesktopCoreCommonCheck(is_es, major_version, minor_version) && | |
| 37 extensions.find("GL_ARB_compatibility") == extensions.end(); | |
| 38 } | 43 } |
| 39 | 44 |
| 40 GLVersionInfo::GLVersionInfo(const char* version_str, const char* renderer_str) | 45 GLVersionInfo::GLVersionInfo() |
| 41 : is_es(false), | 46 : is_es(false), |
| 42 is_angle(false), | 47 is_angle(false), |
| 43 major_version(0), | 48 major_version(0), |
| 44 minor_version(0), | 49 minor_version(0), |
| 45 is_es2(false), | 50 is_es2(false), |
| 46 is_es3(false), | 51 is_es3(false), |
| 47 is_desktop_core_profile(false) { | 52 is_desktop_core_profile(false), |
| 53 is_es3_capable(false) {} | |
| 54 | |
| 55 void GLVersionInfo::Initialize(const char* version_str, | |
| 56 const char* renderer_str, | |
| 57 const std::set<std::string>& extensions) { | |
| 48 if (version_str) { | 58 if (version_str) { |
| 49 ParseVersionString(version_str, &major_version, &minor_version, | 59 ParseVersionString(version_str, &major_version, &minor_version, |
| 50 &is_es, &is_es2, &is_es3); | 60 &is_es, &is_es2, &is_es3); |
| 51 } | 61 } |
| 52 if (renderer_str) { | 62 if (renderer_str) { |
| 53 is_angle = base::StartsWith(renderer_str, "ANGLE", | 63 is_angle = base::StartsWith(renderer_str, "ANGLE", |
| 54 base::CompareCase::SENSITIVE); | 64 base::CompareCase::SENSITIVE); |
| 55 } | 65 } |
| 66 is_desktop_core_profile = | |
| 67 DesktopCoreCommonCheck(is_es, major_version, minor_version) && | |
| 68 extensions.find("GL_ARB_compatibility") == extensions.end(); | |
| 69 is_es3_capable = IsES3Capable(extensions); | |
| 70 } | |
| 71 | |
| 72 bool GLVersionInfo::IsES3Capable( | |
| 73 const std::set<std::string>& extensions) const { | |
| 74 auto hasExtension = [&extensions](std::string extension) -> bool { | |
|
piman
2016/06/24 21:38:56
nit: has_extension
Corentin Wallez
2016/06/27 15:35:42
Done
| |
| 75 return extensions.find(extension) != extensions.end(); | |
| 76 }; | |
| 77 | |
| 78 // Version ES3 capable without extensions needed. | |
| 79 if (IsAtLeastGLES(3, 0) || IsAtLeastGL(4, 2)) { | |
| 80 return true; | |
| 81 } | |
| 82 | |
| 83 // Don't try supporting ES3 on ES2, or desktop before 3.2 because there are no | |
| 84 // extension that allow querying for GL_MAX_FRAGMENT_INPUT_COMPONENTS | |
| 85 if (is_es || !IsAtLeastGL(3, 2)) { | |
| 86 return false; | |
| 87 } | |
| 88 | |
| 89 bool hasShaderPacking = IsAtLeastGL(4, 2) || | |
|
piman
2016/06/24 21:38:56
nit: has_shader_packing
piman
2016/06/24 21:38:56
nit: we already did early out if IsAtLeastGL(4, 2)
Corentin Wallez
2016/06/27 15:35:42
Done (both)
| |
| 90 hasExtension("GL_ARB_shading_bit_packing") || | |
| 91 hasExtension("GL_ARB_shader_bit_encoding"); | |
| 92 bool hasTransformFeedback = | |
|
piman
2016/06/24 21:38:56
nit: has_transform_feedback
Corentin Wallez
2016/06/27 15:35:42
Done
| |
| 93 IsAtLeastGL(4, 0) || hasExtension("GL_ARB_transform_feedback2"); | |
| 94 bool hasSamplers = IsAtLeastGL(3, 3) || hasExtension("GL_ARB_sampler_object"); | |
|
piman
2016/06/24 21:38:56
nit: has_samplers
Corentin Wallez
2016/06/27 15:35:42
Done
| |
| 95 bool hasSwizzle = IsAtLeastGL(3, 3) || | |
|
piman
2016/06/24 21:38:56
nit: has_swizzle
Corentin Wallez
2016/06/27 15:35:42
Done
| |
| 96 hasExtension("GL_ARB_texture_swizzle") || | |
| 97 hasExtension("GL_EXT_texture_swizzle"); | |
| 98 bool hasAttribLocation = | |
|
piman
2016/06/24 21:38:56
nit: has_attrib_location
Corentin Wallez
2016/06/27 15:35:42
Done
| |
| 99 IsAtLeastGL(3, 3) || hasExtension("GL_ARB_explicit_attrib_location"); | |
| 100 | |
| 101 // TODO(cwallez) check for texture related extensions. | |
|
Zhenyao Mo
2016/06/24 21:35:50
Please create a bug so we don't end up forgetting
Corentin Wallez
2016/06/27 15:35:42
Done
| |
| 102 | |
| 103 return hasShaderPacking && hasTransformFeedback && hasSamplers && | |
| 104 hasSwizzle && hasAttribLocation; | |
| 56 } | 105 } |
| 57 | 106 |
| 58 void GLVersionInfo::ParseVersionString(const char* version_str, | 107 void GLVersionInfo::ParseVersionString(const char* version_str, |
| 59 unsigned* major_version, | 108 unsigned* major_version, |
| 60 unsigned* minor_version, | 109 unsigned* minor_version, |
| 61 bool* is_es, | 110 bool* is_es, |
| 62 bool* is_es2, | 111 bool* is_es2, |
| 63 bool* is_es3) { | 112 bool* is_es3) { |
| 64 // Make sure the outputs are always initialized. | 113 // Make sure the outputs are always initialized. |
| 65 *major_version = 0; | 114 *major_version = 0; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 84 } | 133 } |
| 85 } | 134 } |
| 86 if (*is_es && *major_version == 2) | 135 if (*is_es && *major_version == 2) |
| 87 *is_es2 = true; | 136 *is_es2 = true; |
| 88 if (*is_es && *major_version == 3) | 137 if (*is_es && *major_version == 3) |
| 89 *is_es3 = true; | 138 *is_es3 = true; |
| 90 DCHECK(major_version != 0); | 139 DCHECK(major_version != 0); |
| 91 } | 140 } |
| 92 | 141 |
| 93 } // namespace gl | 142 } // namespace gl |
| OLD | NEW |