blob: 415faf341c15b9898060907781a8412e4416c6e8 [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
11namespace gfx {
12
kbrc9f0e10c2015-03-31 19:49:1213GLVersionInfo::GLVersionInfo(const char* version_str, const char* renderer_str,
14 const char* extensions_str)
15 : GLVersionInfo(version_str, renderer_str) {
16 is_desktop_core_profile =
17 !is_es && major_version >= 3 &&
18 !strstr(extensions_str, "GL_ARB_compatibility");
19}
20
21GLVersionInfo::GLVersionInfo(const char* version_str, const char* renderer_str,
22 const std::set<std::string>& extensions)
23 : GLVersionInfo(version_str, renderer_str) {
24 is_desktop_core_profile =
25 !is_es && major_version >= 3 &&
26 extensions.find("GL_ARB_compatibility") == extensions.end();
27}
28
[email protected]17a961192014-02-14 15:20:5229GLVersionInfo::GLVersionInfo(const char* version_str, const char* renderer_str)
[email protected]a37d7ff2014-01-17 21:31:0030 : is_es(false),
sieverse3b17fd52015-01-29 04:00:5331 is_angle(false),
32 major_version(0),
33 minor_version(0),
kbrc9f0e10c2015-03-31 19:49:1234 is_es3(false),
35 is_desktop_core_profile(false) {
[email protected]a37d7ff2014-01-17 21:31:0036 if (version_str) {
kbrc9f0e10c2015-03-31 19:49:1237 ParseVersionString(version_str, &major_version, &minor_version,
38 &is_es, &is_es3);
[email protected]a37d7ff2014-01-17 21:31:0039 }
[email protected]17a961192014-02-14 15:20:5240 if (renderer_str) {
41 is_angle = StartsWithASCII(renderer_str, "ANGLE", true);
42 }
[email protected]a37d7ff2014-01-17 21:31:0043}
44
kbrc9f0e10c2015-03-31 19:49:1245void GLVersionInfo::ParseVersionString(const char* version_str,
46 unsigned* major_version,
47 unsigned* minor_version,
48 bool* is_es,
49 bool* is_es3) {
50 // Make sure the outputs are always initialized.
51 *major_version = 0;
52 *minor_version = 0;
53 *is_es = false;
54 *is_es3 = false;
55 std::string lstr(base::StringToLowerASCII(std::string(version_str)));
56 *is_es = (lstr.length() > 12) && (lstr.substr(0, 9) == "opengl es");
57 if (*is_es)
58 lstr = lstr.substr(10, 3);
59 base::StringTokenizer tokenizer(lstr.begin(), lstr.end(), ".");
60 unsigned major, minor;
61 if (tokenizer.GetNext() &&
62 base::StringToUint(tokenizer.token_piece(), &major)) {
63 *major_version = major;
64 if (tokenizer.GetNext() &&
65 base::StringToUint(tokenizer.token_piece(), &minor)) {
66 *minor_version = minor;
67 }
68 }
69 if (*is_es && *major_version == 3)
70 *is_es3 = true;
71}
72
[email protected]a37d7ff2014-01-17 21:31:0073} // namespace gfx