blob: 9e1b1cc0492086fa193dd2eaa34422b20557df0a [file] [log] [blame]
[email protected]a37d7ff2014-01-17 21:31:001// Copyright 2014 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 "ui/gl/gl_version_info.h"
6
sieverse3b17fd52015-01-29 04:00:537#include "base/strings/string_number_conversions.h"
cwallez3b2dfed2016-06-27 20:03:278#include "base/strings/string_split.h"
sieverse3b17fd52015-01-29 04:00:539#include "base/strings/string_tokenizer.h"
[email protected]a37d7ff2014-01-17 21:31:0010#include "base/strings/string_util.h"
11
kbrb1cca002015-04-11 02:55:2012namespace {
13
14bool DesktopCoreCommonCheck(
15 bool is_es, unsigned major_version, unsigned minor_version) {
16 return (!is_es &&
17 ((major_version == 3 && minor_version >= 2) ||
18 major_version > 3));
19}
20
21}
22
kylechar7a463842016-05-26 14:46:1223namespace gl {
[email protected]a37d7ff2014-01-17 21:31:0024
cwallez3b2dfed2016-06-27 20:03:2725GLVersionInfo::GLVersionInfo(const char* version_str,
26 const char* renderer_str,
Antoine Labour20d16202017-09-05 23:05:2927 const ExtensionSet& extensions)
[email protected]a37d7ff2014-01-17 21:31:0028 : is_es(false),
sieverse3b17fd52015-01-29 04:00:5329 is_angle(false),
junov0c614142016-07-21 18:56:0230 is_mesa(false),
capnc13a0742017-03-22 16:51:2231 is_swiftshader(false),
sieverse3b17fd52015-01-29 04:00:5332 major_version(0),
33 minor_version(0),
zmo9192d282016-04-29 18:22:5834 is_es2(false),
kbrc9f0e10c2015-03-31 19:49:1235 is_es3(false),
cwallez3b2dfed2016-06-27 20:03:2736 is_desktop_core_profile(false),
Antoine Labour20d16202017-09-05 23:05:2937 is_es3_capable(false) {
38 Initialize(version_str, renderer_str, extensions);
39}
cwallez3b2dfed2016-06-27 20:03:2740
41void GLVersionInfo::Initialize(const char* version_str,
42 const char* renderer_str,
Antoine Labour20d16202017-09-05 23:05:2943 const ExtensionSet& extensions) {
[email protected]a37d7ff2014-01-17 21:31:0044 if (version_str) {
kbrc9f0e10c2015-03-31 19:49:1245 ParseVersionString(version_str, &major_version, &minor_version,
zmo9192d282016-04-29 18:22:5846 &is_es, &is_es2, &is_es3);
[email protected]a37d7ff2014-01-17 21:31:0047 }
[email protected]17a961192014-02-14 15:20:5248 if (renderer_str) {
brettw95509312015-07-16 23:57:3349 is_angle = base::StartsWith(renderer_str, "ANGLE",
50 base::CompareCase::SENSITIVE);
junov0c614142016-07-21 18:56:0251 is_mesa = base::StartsWith(renderer_str, "Mesa",
52 base::CompareCase::SENSITIVE);
capnc13a0742017-03-22 16:51:2253 is_swiftshader = base::StartsWith(renderer_str, "Google SwiftShader",
54 base::CompareCase::SENSITIVE);
[email protected]17a961192014-02-14 15:20:5255 }
cwallez3b2dfed2016-06-27 20:03:2756 is_desktop_core_profile =
57 DesktopCoreCommonCheck(is_es, major_version, minor_version) &&
Antoine Labour20d16202017-09-05 23:05:2958 !HasExtension(extensions, "GL_ARB_compatibility");
cwallez3b2dfed2016-06-27 20:03:2759 is_es3_capable = IsES3Capable(extensions);
60}
61
Antoine Labour20d16202017-09-05 23:05:2962bool GLVersionInfo::IsES3Capable(const ExtensionSet& extensions) const {
cwallez3b2dfed2016-06-27 20:03:2763 // Version ES3 capable without extensions needed.
64 if (IsAtLeastGLES(3, 0) || IsAtLeastGL(4, 2)) {
65 return true;
66 }
67
zmo05f50f9b2016-10-29 00:40:2968 // Don't try supporting ES3 on ES2, or desktop before 3.3.
69 if (is_es || !IsAtLeastGL(3, 3)) {
cwallez3b2dfed2016-06-27 20:03:2770 return false;
71 }
72
zmo05f50f9b2016-10-29 00:40:2973 bool has_transform_feedback =
Antoine Labour20d16202017-09-05 23:05:2974 (IsAtLeastGL(4, 0) ||
75 HasExtension(extensions, "GL_ARB_transform_feedback2"));
kbr2bd1f052016-12-05 20:41:1976
77 // This code used to require the GL_ARB_gpu_shader5 extension in order to
78 // have support for dynamic indexing of sampler arrays, which was
79 // optionally supported in ESSL 1.00. However, since this is expressly
80 // forbidden in ESSL 3.00, and some desktop drivers (specifically
81 // Mesa/Gallium on AMD GPUs) don't support it, we no longer require it.
82
zmo05f50f9b2016-10-29 00:40:2983 // tex storage is available in core spec since GL 4.2.
Antoine Labour20d16202017-09-05 23:05:2984 bool has_tex_storage = HasExtension(extensions, "GL_ARB_texture_storage");
zmo05f50f9b2016-10-29 00:40:2985
86 // TODO(cwallez) check for texture related extensions. See crbug.com/623577
87
kbr2bd1f052016-12-05 20:41:1988 return (has_transform_feedback && has_tex_storage);
[email protected]a37d7ff2014-01-17 21:31:0089}
90
kbrc9f0e10c2015-03-31 19:49:1291void GLVersionInfo::ParseVersionString(const char* version_str,
92 unsigned* major_version,
93 unsigned* minor_version,
94 bool* is_es,
zmo9192d282016-04-29 18:22:5895 bool* is_es2,
kbrc9f0e10c2015-03-31 19:49:1296 bool* is_es3) {
97 // Make sure the outputs are always initialized.
98 *major_version = 0;
99 *minor_version = 0;
100 *is_es = false;
zmo9192d282016-04-29 18:22:58101 *is_es2 = false;
kbrc9f0e10c2015-03-31 19:49:12102 *is_es3 = false;
zmo9a7b17e2015-05-06 00:22:33103 if (!version_str)
104 return;
brettw8e2106d2015-08-11 19:30:22105 std::string lstr(base::ToLowerASCII(version_str));
kbrc9f0e10c2015-03-31 19:49:12106 *is_es = (lstr.length() > 12) && (lstr.substr(0, 9) == "opengl es");
107 if (*is_es)
108 lstr = lstr.substr(10, 3);
xinghua.cao49993312016-06-22 07:21:50109 base::StringTokenizer tokenizer(lstr.begin(), lstr.end(), ". ");
kbrc9f0e10c2015-03-31 19:49:12110 unsigned major, minor;
111 if (tokenizer.GetNext() &&
112 base::StringToUint(tokenizer.token_piece(), &major)) {
113 *major_version = major;
114 if (tokenizer.GetNext() &&
115 base::StringToUint(tokenizer.token_piece(), &minor)) {
116 *minor_version = minor;
117 }
118 }
zmo9192d282016-04-29 18:22:58119 if (*is_es && *major_version == 2)
120 *is_es2 = true;
kbrc9f0e10c2015-03-31 19:49:12121 if (*is_es && *major_version == 3)
122 *is_es3 = true;
martina.kollarova9709e1c2016-03-07 09:28:11123 DCHECK(major_version != 0);
kbrc9f0e10c2015-03-31 19:49:12124}
125
kylechar7a463842016-05-26 14:46:12126} // namespace gl