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"
13 bool DesktopCoreCommonCheck(
14 bool is_es
, unsigned major_version
, unsigned minor_version
) {
16 ((major_version
== 3 && minor_version
>= 2) ||
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
)
47 is_desktop_core_profile(false) {
49 ParseVersionString(version_str
, &major_version
, &minor_version
,
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
,
63 // Make sure the outputs are always initialized.
70 std::string
lstr(base::StringToLowerASCII(std::string(version_str
)));
71 *is_es
= (lstr
.length() > 12) && (lstr
.substr(0, 9) == "opengl 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)