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

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

Issue 7021014: GLContext no longer holds a pointer to a GLSurface. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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
OLDNEW
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));
38 if (!context.get()) { 35 if (!context.get()) {
39 LOG(ERROR) << "gfx::GLContext::CreateGLContext failed"; 36 LOG(ERROR) << "gfx::GLContext::CreateGLContext failed";
40 return NULL; 37 return NULL;
41 } 38 }
42 39
43 if (!context->MakeCurrent()) { 40 if (!context->MakeCurrent(surface)) {
44 LOG(ERROR) << "gfx::GLContext::MakeCurrent() failed"; 41 LOG(ERROR) << "gfx::GLContext::MakeCurrent() failed";
45 return NULL; 42 return NULL;
46 } 43 }
47 44
48 return context.release(); 45 return context.release();
49 } 46 }
50 47
51 std::string GetGLString(unsigned int pname) { 48 std::string GetGLString(unsigned int pname) {
52 const char* gl_string = 49 const char* gl_string =
53 reinterpret_cast<const char*>(glGetString(pname)); 50 reinterpret_cast<const char*>(glGetString(pname));
(...skipping 20 matching lines...) Expand all
74 return ""; 71 return "";
75 } 72 }
76 73
77 } // namespace anonymous 74 } // namespace anonymous
78 75
79 namespace gpu_info_collector { 76 namespace gpu_info_collector {
80 77
81 bool CollectGraphicsInfoGL(GPUInfo* gpu_info) { 78 bool CollectGraphicsInfoGL(GPUInfo* gpu_info) {
82 DCHECK(gpu_info); 79 DCHECK(gpu_info);
83 80
84 scoped_ptr<gfx::GLContext> context(InitializeGLContext()); 81 if (!gfx::GLSurface::InitializeOneOff()) {
82 LOG(ERROR) << "gfx::GLContext::InitializeOneOff() failed";
83 return false;
84 }
85
86 scoped_ptr<gfx::GLSurface> surface(InitializeGLSurface());
87 if (!surface.get())
88 return false;
89
90 scoped_ptr<gfx::GLContext> context(InitializeGLContext(surface.get()));
85 if (!context.get()) 91 if (!context.get())
86 return false; 92 return false;
87 93
88 gpu_info->gl_renderer = GetGLString(GL_RENDERER); 94 gpu_info->gl_renderer = GetGLString(GL_RENDERER);
89 gpu_info->gl_vendor = GetGLString(GL_VENDOR); 95 gpu_info->gl_vendor = GetGLString(GL_VENDOR);
90 gpu_info->gl_version_string =GetGLString(GL_VERSION); 96 gpu_info->gl_version_string =GetGLString(GL_VERSION);
91 gpu_info->gl_extensions =GetGLString(GL_EXTENSIONS); 97 gpu_info->gl_extensions =GetGLString(GL_EXTENSIONS);
92 98
93 bool validGLVersionInfo = CollectGLVersionInfo(gpu_info); 99 bool validGLVersionInfo = CollectGLVersionInfo(gpu_info);
94 bool validVideoCardInfo = CollectVideoCardInfo(gpu_info); 100 bool validVideoCardInfo = CollectVideoCardInfo(gpu_info);
(...skipping 13 matching lines...) Expand all
108 114
109 std::string glsl_version = GetVersionFromString(glsl_version_string); 115 std::string glsl_version = GetVersionFromString(glsl_version_string);
110 gpu_info->pixel_shader_version = glsl_version; 116 gpu_info->pixel_shader_version = glsl_version;
111 gpu_info->vertex_shader_version = glsl_version; 117 gpu_info->vertex_shader_version = glsl_version;
112 118
113 return true; 119 return true;
114 } 120 }
115 121
116 } // namespace gpu_info_collector 122 } // namespace gpu_info_collector
117 123
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698