1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/gl/gl_version_info.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_tokenizer.h"
#include "base/strings/string_util.h"
namespace {
bool DesktopCoreCommonCheck(
bool is_es, unsigned major_version, unsigned minor_version) {
return (!is_es &&
((major_version == 3 && minor_version >= 2) ||
major_version > 3));
}
}
namespace gfx {
GLVersionInfo::GLVersionInfo(const char* version_str, const char* renderer_str,
const char* extensions_str)
: GLVersionInfo(version_str, renderer_str) {
is_desktop_core_profile =
DesktopCoreCommonCheck(is_es, major_version, minor_version) &&
!strstr(extensions_str, "GL_ARB_compatibility");
}
GLVersionInfo::GLVersionInfo(const char* version_str, const char* renderer_str,
const std::set<std::string>& extensions)
: GLVersionInfo(version_str, renderer_str) {
is_desktop_core_profile =
DesktopCoreCommonCheck(is_es, major_version, minor_version) &&
extensions.find("GL_ARB_compatibility") == extensions.end();
}
GLVersionInfo::GLVersionInfo(const char* version_str, const char* renderer_str)
: is_es(false),
is_angle(false),
major_version(0),
minor_version(0),
is_es3(false),
is_desktop_core_profile(false) {
if (version_str) {
ParseVersionString(version_str, &major_version, &minor_version,
&is_es, &is_es3);
}
if (renderer_str) {
is_angle = base::StartsWith(renderer_str, "ANGLE",
base::CompareCase::SENSITIVE);
}
}
void GLVersionInfo::ParseVersionString(const char* version_str,
unsigned* major_version,
unsigned* minor_version,
bool* is_es,
bool* is_es3) {
// Make sure the outputs are always initialized.
*major_version = 0;
*minor_version = 0;
*is_es = false;
*is_es3 = false;
if (!version_str)
return;
std::string lstr(base::ToLowerASCII(version_str));
*is_es = (lstr.length() > 12) && (lstr.substr(0, 9) == "opengl es");
if (*is_es)
lstr = lstr.substr(10, 3);
base::StringTokenizer tokenizer(lstr.begin(), lstr.end(), ".");
unsigned major, minor;
if (tokenizer.GetNext() &&
base::StringToUint(tokenizer.token_piece(), &major)) {
*major_version = major;
if (tokenizer.GetNext() &&
base::StringToUint(tokenizer.token_piece(), &minor)) {
*minor_version = minor;
}
}
if (*is_es && *major_version == 3)
*is_es3 = true;
DCHECK(major_version != 0);
}
} // namespace gfx
|