| OLD | NEW |
| 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 Loading... |
| 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 DCHECK(bytes); |
| 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 ¤t_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; |
| 177 GLint num_renderers = 0; |
| 178 if (CGLQueryRendererInfo(display_mask, |
| 179 &renderer_info, |
| 180 &num_renderers) != kCGLNoError) |
| 181 return false; |
| 182 |
| 183 ScopedCGLRendererInfoObj scoper(renderer_info); |
| 184 |
| 185 for (GLint renderer_index = 0; |
| 186 renderer_index < num_renderers; |
| 187 ++renderer_index) { |
| 188 // Skip this if this renderer is not the current renderer. |
| 189 GLint renderer_id = 0; |
| 190 if (CGLDescribeRenderer(renderer_info, |
| 191 renderer_index, |
| 192 kCGLRPRendererID, |
| 193 &renderer_id) != kCGLNoError) |
| 194 continue; |
| 195 if (renderer_id != current_renderer_id) |
| 196 continue; |
| 197 // Retrieve the video memory for the renderer. |
| 198 GLint video_memory = 0; |
| 199 if (CGLDescribeRenderer(renderer_info, |
| 200 renderer_index, |
| 201 kCGLRPVideoMemory, |
| 202 &video_memory) != kCGLNoError) |
| 203 continue; |
| 204 *bytes = video_memory; |
| 205 return true; |
| 206 } |
| 207 |
| 208 return false; |
| 209 } |
| 210 |
| 157 GLContextCGL::~GLContextCGL() { | 211 GLContextCGL::~GLContextCGL() { |
| 158 Destroy(); | 212 Destroy(); |
| 159 } | 213 } |
| 160 | 214 |
| 161 GpuPreference GLContextCGL::GetGpuPreference() { | 215 GpuPreference GLContextCGL::GetGpuPreference() { |
| 162 return gpu_preference_; | 216 return gpu_preference_; |
| 163 } | 217 } |
| 164 | 218 |
| 165 void GLContextCGL::ForceUseOfDiscreteGPU() { | 219 void GLContextCGL::ForceUseOfDiscreteGPU() { |
| 166 static CGLPixelFormatObj format = NULL; | 220 static CGLPixelFormatObj format = NULL; |
| 167 if (format) | 221 if (format) |
| 168 return; | 222 return; |
| 169 CGLPixelFormatAttribute attribs[1]; | 223 CGLPixelFormatAttribute attribs[1]; |
| 170 attribs[0] = static_cast<CGLPixelFormatAttribute>(0); | 224 attribs[0] = static_cast<CGLPixelFormatAttribute>(0); |
| 171 GLint num_pixel_formats = 0; | 225 GLint num_pixel_formats = 0; |
| 172 CGLChoosePixelFormat(attribs, &format, &num_pixel_formats); | 226 CGLChoosePixelFormat(attribs, &format, &num_pixel_formats); |
| 173 // format is deliberately leaked. | 227 // format is deliberately leaked. |
| 174 } | 228 } |
| 175 | 229 |
| 230 void ScopedCGLDestroyRendererInfo::operator()(CGLRendererInfoObj x) const { |
| 231 CGLDestroyRendererInfo(x); |
| 232 } |
| 233 |
| 176 } // namespace gfx | 234 } // namespace gfx |
| OLD | NEW |