Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: chrome/gpu/gpu_info_collector.cc

Issue 6684015: Move chrome\gpu to content\gpu. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/gpu/gpu_info_collector.h ('k') | chrome/gpu/gpu_info_collector_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2006-2010 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 "chrome/gpu/gpu_info_collector.h"
6
7 #include <string>
8 #include <vector>
9
10 #include "app/gfx/gl/gl_bindings.h"
11 #include "app/gfx/gl/gl_context.h"
12 #include "base/logging.h"
13 #include "base/string_number_conversions.h"
14 #include "base/string_piece.h"
15 #include "base/string_split.h"
16
17 namespace {
18
19 // This creates an offscreen GL context for gl queries. Returned GLContext
20 // should be deleted in FinalizeGLContext.
21 gfx::GLContext* InitializeGLContext() {
22 if (!gfx::GLContext::InitializeOneOff()) {
23 LOG(ERROR) << "gfx::GLContext::InitializeOneOff() failed";
24 return NULL;
25 }
26 gfx::GLContext* context = gfx::GLContext::CreateOffscreenGLContext(NULL);
27 if (context == NULL) {
28 LOG(ERROR) << "gfx::GLContext::CreateOffscreenGLContext(NULL) failed";
29 return NULL;
30 }
31 if (!context->MakeCurrent()) {
32 LOG(ERROR) << "gfx::GLContext::MakeCurrent() failed";
33 context->Destroy();
34 delete context;
35 return NULL;
36 }
37 return context;
38 }
39
40 // This destroy and delete the GL context.
41 void FinalizeGLContext(gfx::GLContext** context) {
42 DCHECK(context);
43 if (*context) {
44 (*context)->Destroy();
45 delete *context;
46 *context = NULL;
47 }
48 }
49
50 std::string GetGLString(unsigned int pname) {
51 const char* gl_string =
52 reinterpret_cast<const char*>(glGetString(pname));
53 if (gl_string)
54 return std::string(gl_string);
55 return "";
56 }
57
58 uint32 GetVersionNumberFromString(const std::string& version_string) {
59 int major = 0, minor = 0;
60 size_t begin = version_string.find_first_of("0123456789");
61 if (begin != std::string::npos) {
62 size_t end = version_string.find_first_not_of("01234567890.", begin);
63 std::string sub_string;
64 if (end != std::string::npos)
65 sub_string = version_string.substr(begin, end - begin);
66 else
67 sub_string = version_string.substr(begin);
68 std::vector<std::string> pieces;
69 base::SplitString(sub_string, '.', &pieces);
70 if (pieces.size() >= 2) {
71 base::StringToInt(pieces[0], &major);
72 base::StringToInt(pieces[1], &minor);
73 }
74 }
75 return ((major << 8) + minor);
76 }
77
78 } // namespace anonymous
79
80 namespace gpu_info_collector {
81
82 bool CollectGraphicsInfoGL(GPUInfo* gpu_info) {
83 DCHECK(gpu_info);
84
85 gfx::GLContext* context = InitializeGLContext();
86 if (context == NULL)
87 return false;
88
89 gpu_info->gl_renderer = GetGLString(GL_RENDERER);
90 gpu_info->gl_vendor = GetGLString(GL_VENDOR);
91 gpu_info->gl_version_string =GetGLString(GL_VERSION);
92 gpu_info->gl_extensions =GetGLString(GL_EXTENSIONS);
93
94 bool validGLVersionInfo = CollectGLVersionInfo(gpu_info);
95 bool validVideoCardInfo = CollectVideoCardInfo(gpu_info);
96 bool validDriverInfo = CollectDriverInfoGL(gpu_info);
97
98 FinalizeGLContext(&context);
99
100 return (validGLVersionInfo && validVideoCardInfo && validDriverInfo);
101 }
102
103 bool CollectGLVersionInfo(GPUInfo* gpu_info) {
104 DCHECK(gpu_info);
105
106 std::string gl_version_string = gpu_info->gl_version_string;
107 std::string glsl_version_string =
108 GetGLString(GL_SHADING_LANGUAGE_VERSION);
109
110 uint32 gl_version = GetVersionNumberFromString(gl_version_string);
111 gpu_info->gl_version = gl_version;
112
113 uint32 glsl_version = GetVersionNumberFromString(glsl_version_string);
114 gpu_info->pixel_shader_version = glsl_version;
115 gpu_info->vertex_shader_version = glsl_version;
116
117 return true;
118 }
119
120 } // namespace gpu_info_collector
121
OLDNEW
« no previous file with comments | « chrome/gpu/gpu_info_collector.h ('k') | chrome/gpu/gpu_info_collector_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698