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

Side by Side Diff: ui/gl/gl_context_cgl.cc

Issue 10957009: Get real GPU memory values on NV+Linux and OS X (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix GLX build Created 8 years, 3 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/gl/gl_context_cgl.h" 5 #include "ui/gl/gl_context_cgl.h"
6 6
7 #include <OpenGL/CGLRenderers.h> 7 #include <OpenGL/CGLRenderers.h>
8 #include <OpenGL/CGLTypes.h>
8 #include <vector> 9 #include <vector>
9 10
10 #include "base/debug/trace_event.h" 11 #include "base/debug/trace_event.h"
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "ui/gl/gl_bindings.h" 13 #include "ui/gl/gl_bindings.h"
13 #include "ui/gl/gl_implementation.h" 14 #include "ui/gl/gl_implementation.h"
14 #include "ui/gl/gl_surface_cgl.h" 15 #include "ui/gl/gl_surface_cgl.h"
15 16
16 namespace gfx { 17 namespace gfx {
17 18
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 148
148 void* GLContextCGL::GetHandle() { 149 void* GLContextCGL::GetHandle() {
149 return context_; 150 return context_;
150 } 151 }
151 152
152 void GLContextCGL::SetSwapInterval(int interval) { 153 void GLContextCGL::SetSwapInterval(int interval) {
153 DCHECK(IsCurrent(NULL)); 154 DCHECK(IsCurrent(NULL));
154 LOG(WARNING) << "GLContex: GLContextCGL::SetSwapInterval is ignored."; 155 LOG(WARNING) << "GLContex: GLContextCGL::SetSwapInterval is ignored.";
155 } 156 }
156 157
158
159 bool GLContextCGL::GetTotalGpuMemory(size_t& bytes) {
160 bool got_current_gpu_memory_value = false;
161 bytes = 0;
162
163 CGLContextObj context = reinterpret_cast<CGLContextObj>(context_);
164 if (!context)
165 return false;
166
167 // Retrieve the current renderer ID
168 GLint current_renderer_id = 0;
169 if (CGLGetParameter(context,
170 kCGLCPCurrentRendererID,
171 &current_renderer_id) != kCGLNoError)
172 return false;
173
174 // Iterate through the list of all renderers
175 GLuint display_mask = static_cast<GLuint>(-1);
176 CGLRendererInfoObj renderer_info = NULL;
Ken Russell (switch to Gerrit) 2012/09/20 06:47:23 Use ScopedGenericObj parameterized with a ScopedDe
177 GLint num_renderers = 0;
178 if (CGLQueryRendererInfo(display_mask,
179 &renderer_info,
180 &num_renderers) != kCGLNoError)
181 return false;
182 for (GLint renderer_index = 0;
183 renderer_index < num_renderers;
184 ++renderer_index) {
185 // Skip this if this renderer is not the current renderer.
186 GLint renderer_id = 0;
187 if (CGLDescribeRenderer(renderer_info,
188 renderer_index,
189 kCGLRPRendererID,
190 &renderer_id) != kCGLNoError)
191 continue;
192 if (renderer_id != current_renderer_id)
193 continue;
194 // Retrieve the video memory for the renderer.
195 GLint video_memory = 0;
196 if (CGLDescribeRenderer(renderer_info,
197 renderer_index,
198 kCGLRPVideoMemory,
199 &video_memory) != kCGLNoError)
200 continue;
201 bytes = video_memory;
202 got_current_gpu_memory_value = true;
203 break;
204 }
205
206 CGLDestroyRendererInfo(renderer_info);
207 return got_current_gpu_memory_value;
208 }
209
157 GLContextCGL::~GLContextCGL() { 210 GLContextCGL::~GLContextCGL() {
158 Destroy(); 211 Destroy();
159 } 212 }
160 213
161 GpuPreference GLContextCGL::GetGpuPreference() { 214 GpuPreference GLContextCGL::GetGpuPreference() {
162 return gpu_preference_; 215 return gpu_preference_;
163 } 216 }
164 217
165 void GLContextCGL::ForceUseOfDiscreteGPU() { 218 void GLContextCGL::ForceUseOfDiscreteGPU() {
166 static CGLPixelFormatObj format = NULL; 219 static CGLPixelFormatObj format = NULL;
167 if (format) 220 if (format)
168 return; 221 return;
169 CGLPixelFormatAttribute attribs[1]; 222 CGLPixelFormatAttribute attribs[1];
170 attribs[0] = static_cast<CGLPixelFormatAttribute>(0); 223 attribs[0] = static_cast<CGLPixelFormatAttribute>(0);
171 GLint num_pixel_formats = 0; 224 GLint num_pixel_formats = 0;
172 CGLChoosePixelFormat(attribs, &format, &num_pixel_formats); 225 CGLChoosePixelFormat(attribs, &format, &num_pixel_formats);
173 // format is deliberately leaked. 226 // format is deliberately leaked.
174 } 227 }
175 228
176 } // namespace gfx 229 } // namespace gfx
OLDNEW
« ui/gl/gl_context.h ('K') | « ui/gl/gl_context_cgl.h ('k') | ui/gl/gl_context_glx.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698