Update UnusedResources lint suppressions.
[chromium-blink-merge.git] / ui / gl / gl_version_info.cc
blob5eff43a1cc63439c22ea22d649b610c6e2313a97
1 // 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.
5 #include "ui/gl/gl_version_info.h"
7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/string_tokenizer.h"
9 #include "base/strings/string_util.h"
11 namespace {
13 bool 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));
23 namespace gfx {
25 GLVersionInfo::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 =
29 DesktopCoreCommonCheck(is_es, major_version, minor_version) &&
30 !strstr(extensions_str, "GL_ARB_compatibility");
33 GLVersionInfo::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 =
37 DesktopCoreCommonCheck(is_es, major_version, minor_version) &&
38 extensions.find("GL_ARB_compatibility") == extensions.end();
41 GLVersionInfo::GLVersionInfo(const char* version_str, const char* renderer_str)
42 : is_es(false),
43 is_angle(false),
44 major_version(0),
45 minor_version(0),
46 is_es3(false),
47 is_desktop_core_profile(false) {
48 if (version_str) {
49 ParseVersionString(version_str, &major_version, &minor_version,
50 &is_es, &is_es3);
52 if (renderer_str) {
53 is_angle = base::StartsWithASCII(renderer_str, "ANGLE", true);
57 void 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;
67 if (!version_str)
68 return;
69 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;
83 if (*is_es && *major_version == 3)
84 *is_es3 = true;
87 } // namespace gfx