blob: 5eff43a1cc63439c22ea22d649b610c6e2313a97 [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) {
brettw44ce0ec52015-06-12 01:57:5753 is_angle = base::StartsWithASCII(renderer_str, "ANGLE", true);
[email protected]17a961192014-02-14 15:20:5254 }
[email protected]a37d7ff2014-01-17 21:31:0055}
56
kbrc9f0e10c2015-03-31 19:49:1257void GLVersionInfo::ParseVersionString(const char* version_str,
58 unsigned* major_version,
59 unsigned* minor_version,
60 bool* is_es,
61 bool* is_es3) {
62 // Make sure the outputs are always initialized.
63 *major_version = 0;
64 *minor_version = 0;
65 *is_es = false;
66 *is_es3 = false;
zmo9a7b17e2015-05-06 00:22:3367 if (!version_str)
68 return;
kbrc9f0e10c2015-03-31 19:49:1269 std::string lstr(base::StringToLowerASCII(std::string(version_str)));
70 *is_es = (lstr.length() > 12) && (lstr.substr(0, 9) == "opengl es");
71 if (*is_es)
72 lstr = lstr.substr(10, 3);
73 base::StringTokenizer tokenizer(lstr.begin(), lstr.end(), ".");
74 unsigned major, minor;
75 if (tokenizer.GetNext() &&
76 base::StringToUint(tokenizer.token_piece(), &major)) {
77 *major_version = major;
78 if (tokenizer.GetNext() &&
79 base::StringToUint(tokenizer.token_piece(), &minor)) {
80 *minor_version = minor;
81 }
82 }
83 if (*is_es && *major_version == 3)
84 *is_es3 = true;
85}
86
[email protected]a37d7ff2014-01-17 21:31:0087} // namespace gfx