blob: c3cec4dc1d6f78c918f84a45c17ce79cb0911eeb [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
22
[email protected]a37d7ff2014-01-17 21:31:0023namespace gfx {
24
kbrc9f0e10c2015-03-31 19:49:1225GLVersionInfo::GLVersionInfo(const char* version_str, const char* renderer_str,
26 const char* extensions_str)
27 : GLVersionInfo(version_str, renderer_str) {
28 is_desktop_core_profile =
kbrb1cca002015-04-11 02:55:2029 DesktopCoreCommonCheck(is_es, major_version, minor_version) &&
kbrc9f0e10c2015-03-31 19:49:1230 !strstr(extensions_str, "GL_ARB_compatibility");
31}
32
33GLVersionInfo::GLVersionInfo(const char* version_str, const char* renderer_str,
34 const std::set<std::string>& extensions)
35 : GLVersionInfo(version_str, renderer_str) {
36 is_desktop_core_profile =
kbrb1cca002015-04-11 02:55:2037 DesktopCoreCommonCheck(is_es, major_version, minor_version) &&
kbrc9f0e10c2015-03-31 19:49:1238 extensions.find("GL_ARB_compatibility") == extensions.end();
39}
40
[email protected]17a961192014-02-14 15:20:5241GLVersionInfo::GLVersionInfo(const char* version_str, const char* renderer_str)
[email protected]a37d7ff2014-01-17 21:31:0042 : is_es(false),
sieverse3b17fd52015-01-29 04:00:5343 is_angle(false),
44 major_version(0),
45 minor_version(0),
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,
50 &is_es, &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,
62 bool* is_es3) {
63 // Make sure the outputs are always initialized.
64 *major_version = 0;
65 *minor_version = 0;
66 *is_es = false;
67 *is_es3 = false;
zmo9a7b17e2015-05-06 00:22:3368 if (!version_str)
69 return;
kbrc9f0e10c2015-03-31 19:49:1270 std::string lstr(base::StringToLowerASCII(std::string(version_str)));
71 *is_es = (lstr.length() > 12) && (lstr.substr(0, 9) == "opengl es");
72 if (*is_es)
73 lstr = lstr.substr(10, 3);
74 base::StringTokenizer tokenizer(lstr.begin(), lstr.end(), ".");
75 unsigned major, minor;
76 if (tokenizer.GetNext() &&
77 base::StringToUint(tokenizer.token_piece(), &major)) {
78 *major_version = major;
79 if (tokenizer.GetNext() &&
80 base::StringToUint(tokenizer.token_piece(), &minor)) {
81 *minor_version = minor;
82 }
83 }
84 if (*is_es && *major_version == 3)
85 *is_es3 = true;
86}
87
[email protected]a37d7ff2014-01-17 21:31:0088} // namespace gfx