OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/gpu/gpu_info_collector.h" | 5 #include "content/gpu/gpu_info_collector.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
13 #include "base/string_piece.h" | 13 #include "base/string_piece.h" |
14 #include "base/string_split.h" | 14 #include "base/string_split.h" |
15 #include "ui/gfx/gl/gl_bindings.h" | 15 #include "ui/gfx/gl/gl_bindings.h" |
16 #include "ui/gfx/gl/gl_context.h" | 16 #include "ui/gfx/gl/gl_context.h" |
17 #include "ui/gfx/gl/gl_surface.h" | 17 #include "ui/gfx/gl/gl_surface.h" |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 // This creates an offscreen GL context for gl queries. Returned GLContext | 21 gfx::GLSurface* InitializeGLSurface() { |
22 // should be deleted in FinalizeGLContext. | |
23 gfx::GLContext* InitializeGLContext() { | |
24 if (!gfx::GLSurface::InitializeOneOff()) { | |
25 LOG(ERROR) << "gfx::GLContext::InitializeOneOff() failed"; | |
26 return NULL; | |
27 } | |
28 scoped_ptr<gfx::GLSurface> surface(gfx::GLSurface::CreateOffscreenGLSurface( | 22 scoped_ptr<gfx::GLSurface> surface(gfx::GLSurface::CreateOffscreenGLSurface( |
29 gfx::Size(1, 1))); | 23 gfx::Size(1, 1))); |
30 if (!surface.get()) { | 24 if (!surface.get()) { |
31 LOG(ERROR) << "gfx::GLContext::CreateOffscreenGLSurface failed"; | 25 LOG(ERROR) << "gfx::GLContext::CreateOffscreenGLSurface failed"; |
32 return NULL; | 26 return NULL; |
33 } | 27 } |
34 | 28 |
35 scoped_ptr<gfx::GLContext> context(gfx::GLContext::CreateGLContext( | 29 return surface.release(); |
36 surface.release(), | 30 } |
37 NULL)); | 31 |
| 32 gfx::GLContext* InitializeGLContext(gfx::GLSurface* surface) { |
| 33 |
| 34 scoped_ptr<gfx::GLContext> context(gfx::GLContext::CreateGLContext(NULL, |
| 35 surface)); |
38 if (!context.get()) { | 36 if (!context.get()) { |
39 LOG(ERROR) << "gfx::GLContext::CreateGLContext failed"; | 37 LOG(ERROR) << "gfx::GLContext::CreateGLContext failed"; |
40 return NULL; | 38 return NULL; |
41 } | 39 } |
42 | 40 |
43 if (!context->MakeCurrent()) { | 41 if (!context->MakeCurrent(surface)) { |
44 LOG(ERROR) << "gfx::GLContext::MakeCurrent() failed"; | 42 LOG(ERROR) << "gfx::GLContext::MakeCurrent() failed"; |
45 return NULL; | 43 return NULL; |
46 } | 44 } |
47 | 45 |
48 return context.release(); | 46 return context.release(); |
49 } | 47 } |
50 | 48 |
51 std::string GetGLString(unsigned int pname) { | 49 std::string GetGLString(unsigned int pname) { |
52 const char* gl_string = | 50 const char* gl_string = |
53 reinterpret_cast<const char*>(glGetString(pname)); | 51 reinterpret_cast<const char*>(glGetString(pname)); |
(...skipping 20 matching lines...) Expand all Loading... |
74 return ""; | 72 return ""; |
75 } | 73 } |
76 | 74 |
77 } // namespace anonymous | 75 } // namespace anonymous |
78 | 76 |
79 namespace gpu_info_collector { | 77 namespace gpu_info_collector { |
80 | 78 |
81 bool CollectGraphicsInfoGL(GPUInfo* gpu_info) { | 79 bool CollectGraphicsInfoGL(GPUInfo* gpu_info) { |
82 DCHECK(gpu_info); | 80 DCHECK(gpu_info); |
83 | 81 |
84 scoped_ptr<gfx::GLContext> context(InitializeGLContext()); | 82 if (!gfx::GLSurface::InitializeOneOff()) { |
| 83 LOG(ERROR) << "gfx::GLContext::InitializeOneOff() failed"; |
| 84 return false; |
| 85 } |
| 86 |
| 87 scoped_ptr<gfx::GLSurface> surface(InitializeGLSurface()); |
| 88 if (!surface.get()) |
| 89 return false; |
| 90 |
| 91 scoped_ptr<gfx::GLContext> context(InitializeGLContext(surface.get())); |
85 if (!context.get()) | 92 if (!context.get()) |
86 return false; | 93 return false; |
87 | 94 |
88 gpu_info->gl_renderer = GetGLString(GL_RENDERER); | 95 gpu_info->gl_renderer = GetGLString(GL_RENDERER); |
89 gpu_info->gl_vendor = GetGLString(GL_VENDOR); | 96 gpu_info->gl_vendor = GetGLString(GL_VENDOR); |
90 gpu_info->gl_version_string =GetGLString(GL_VERSION); | 97 gpu_info->gl_version_string =GetGLString(GL_VERSION); |
91 gpu_info->gl_extensions =GetGLString(GL_EXTENSIONS); | 98 gpu_info->gl_extensions =GetGLString(GL_EXTENSIONS); |
92 | 99 |
93 bool validGLVersionInfo = CollectGLVersionInfo(gpu_info); | 100 bool validGLVersionInfo = CollectGLVersionInfo(gpu_info); |
94 bool validVideoCardInfo = CollectVideoCardInfo(gpu_info); | 101 bool validVideoCardInfo = CollectVideoCardInfo(gpu_info); |
(...skipping 13 matching lines...) Expand all Loading... |
108 | 115 |
109 std::string glsl_version = GetVersionFromString(glsl_version_string); | 116 std::string glsl_version = GetVersionFromString(glsl_version_string); |
110 gpu_info->pixel_shader_version = glsl_version; | 117 gpu_info->pixel_shader_version = glsl_version; |
111 gpu_info->vertex_shader_version = glsl_version; | 118 gpu_info->vertex_shader_version = glsl_version; |
112 | 119 |
113 return true; | 120 return true; |
114 } | 121 } |
115 | 122 |
116 } // namespace gpu_info_collector | 123 } // namespace gpu_info_collector |
117 | 124 |
OLD | NEW |