blob: cce2715b3703c60013a41cfb2ea8720eab4c14fc [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"
8#include "base/strings/string_tokenizer.h"
[email protected]a37d7ff2014-01-17 21:31:009#include "base/strings/string_util.h"
10
kbrb1cca002015-04-11 02:55:2011namespace {
12
13bool DesktopCoreCommonCheck(
14 bool is_es, unsigned major_version, unsigned minor_version) {
15 return (!is_es &&
16 ((major_version == 3 && minor_version >= 2) ||
17 major_version > 3));
18}
19
20}
21
kylechar7a463842016-05-26 14:46:1222namespace gl {
[email protected]a37d7ff2014-01-17 21:31:0023
kbrc9f0e10c2015-03-31 19:49:1224GLVersionInfo::GLVersionInfo(const char* version_str, const char* renderer_str,
25 const char* extensions_str)
26 : GLVersionInfo(version_str, renderer_str) {
27 is_desktop_core_profile =
kbrb1cca002015-04-11 02:55:2028 DesktopCoreCommonCheck(is_es, major_version, minor_version) &&
kbrc9f0e10c2015-03-31 19:49:1229 !strstr(extensions_str, "GL_ARB_compatibility");
30}
31
32GLVersionInfo::GLVersionInfo(const char* version_str, const char* renderer_str,
33 const std::set<std::string>& extensions)
34 : GLVersionInfo(version_str, renderer_str) {
35 is_desktop_core_profile =
kbrb1cca002015-04-11 02:55:2036 DesktopCoreCommonCheck(is_es, major_version, minor_version) &&
kbrc9f0e10c2015-03-31 19:49:1237 extensions.find("GL_ARB_compatibility") == extensions.end();
38}
39
[email protected]17a961192014-02-14 15:20:5240GLVersionInfo::GLVersionInfo(const char* version_str, const char* renderer_str)
[email protected]a37d7ff2014-01-17 21:31:0041 : is_es(false),
sieverse3b17fd52015-01-29 04:00:5342 is_angle(false),
43 major_version(0),
44 minor_version(0),
zmo9192d282016-04-29 18:22:5845 is_es2(false),
kbrc9f0e10c2015-03-31 19:49:1246 is_es3(false),
47 is_desktop_core_profile(false) {
[email protected]a37d7ff2014-01-17 21:31:0048 if (version_str) {
kbrc9f0e10c2015-03-31 19:49:1249 ParseVersionString(version_str, &major_version, &minor_version,
zmo9192d282016-04-29 18:22:5850 &is_es, &is_es2, &is_es3);
[email protected]a37d7ff2014-01-17 21:31:0051 }
[email protected]17a961192014-02-14 15:20:5252 if (renderer_str) {
brettw95509312015-07-16 23:57:3353 is_angle = base::StartsWith(renderer_str, "ANGLE",
54 base::CompareCase::SENSITIVE);
[email protected]17a961192014-02-14 15:20:5255 }
[email protected]a37d7ff2014-01-17 21:31:0056}
57
kbrc9f0e10c2015-03-31 19:49:1258void GLVersionInfo::ParseVersionString(const char* version_str,
59 unsigned* major_version,
60 unsigned* minor_version,
61 bool* is_es,
zmo9192d282016-04-29 18:22:5862 bool* is_es2,
kbrc9f0e10c2015-03-31 19:49:1263 bool* is_es3) {
64 // Make sure the outputs are always initialized.
65 *major_version = 0;
66 *minor_version = 0;
67 *is_es = false;
zmo9192d282016-04-29 18:22:5868 *is_es2 = false;
kbrc9f0e10c2015-03-31 19:49:1269 *is_es3 = false;
zmo9a7b17e2015-05-06 00:22:3370 if (!version_str)
71 return;
brettw8e2106d2015-08-11 19:30:2272 std::string lstr(base::ToLowerASCII(version_str));
kbrc9f0e10c2015-03-31 19:49:1273 *is_es = (lstr.length() > 12) && (lstr.substr(0, 9) == "opengl es");
74 if (*is_es)
75 lstr = lstr.substr(10, 3);
76 base::StringTokenizer tokenizer(lstr.begin(), lstr.end(), ".");
77 unsigned major, minor;
78 if (tokenizer.GetNext() &&
79 base::StringToUint(tokenizer.token_piece(), &major)) {
80 *major_version = major;
81 if (tokenizer.GetNext() &&
82 base::StringToUint(tokenizer.token_piece(), &minor)) {
83 *minor_version = minor;
84 }
85 }
zmo9192d282016-04-29 18:22:5886 if (*is_es && *major_version == 2)
87 *is_es2 = true;
kbrc9f0e10c2015-03-31 19:49:1288 if (*is_es && *major_version == 3)
89 *is_es3 = true;
martina.kollarova9709e1c2016-03-07 09:28:1190 DCHECK(major_version != 0);
kbrc9f0e10c2015-03-31 19:49:1291}
92
kylechar7a463842016-05-26 14:46:1293} // namespace gl