[Android] Implement 3-way sensor fallback for Device Orientation.
[chromium-blink-merge.git] / ui / gl / gl_version_info.cc
blobcc960b0a3a8fc0adb764f2a5457b46cfe9eb1352
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::StartsWith(renderer_str, "ANGLE",
54 base::CompareCase::SENSITIVE);
58 void 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;
68 if (!version_str)
69 return;
70 std::string lstr(base::ToLowerASCII(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;
84 if (*is_es && *major_version == 3)
85 *is_es3 = true;
88 } // namespace gfx