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 "ui/gfx/gl/gl_context_cgl.h" | 5 #include "ui/gfx/gl/gl_context_cgl.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "ui/gfx/gl/gl_bindings.h" | 10 #include "ui/gfx/gl/gl_bindings.h" |
11 #include "ui/gfx/gl/gl_surface_cgl.h" | 11 #include "ui/gfx/gl/gl_surface_cgl.h" |
12 | 12 |
13 namespace gfx { | 13 namespace gfx { |
14 | 14 |
15 GLContextCGL::GLContextCGL(GLShareGroup* share_group) | 15 GLContextCGL::GLContextCGL(GLShareGroup* share_group) |
16 : GLContext(share_group), | 16 : GLContext(share_group), |
17 context_(NULL), | 17 context_(NULL), |
18 gpu_preference_(PreferIntegratedGpu) { | 18 gpu_preference_(PreferIntegratedGpu) { |
19 } | 19 } |
20 | 20 |
21 GLContextCGL::~GLContextCGL() { | 21 GLContextCGL::~GLContextCGL() { |
22 Destroy(); | 22 Destroy(); |
23 } | 23 } |
24 | 24 |
25 bool GLContextCGL::Initialize( | 25 bool GLContextCGL::Initialize( |
26 GLSurface* compatible_surface, GpuPreference gpu_preference) { | 26 GLSurface* compatible_surface, GpuPreference gpu_preference) { |
27 DCHECK(compatible_surface); | 27 DCHECK(compatible_surface); |
28 | 28 |
29 // Ensure the GPU preference is compatible with contexts already in the | |
30 // share group. | |
31 GLContextCGL* share_context = share_group() ? | 29 GLContextCGL* share_context = share_group() ? |
32 static_cast<GLContextCGL*>(share_group()->GetContext()) : NULL; | 30 static_cast<GLContextCGL*>(share_group()->GetContext()) : NULL; |
33 if (share_context && gpu_preference != share_context->GetGpuPreference()) | 31 if (SupportsDualGpus()) { |
34 return false; | 32 // Ensure the GPU preference is compatible with contexts already in the |
| 33 // share group. |
| 34 if (share_context && gpu_preference != share_context->GetGpuPreference()) |
| 35 return false; |
| 36 } |
35 | 37 |
36 std::vector<CGLPixelFormatAttribute> attribs; | 38 std::vector<CGLPixelFormatAttribute> attribs; |
37 attribs.push_back(kCGLPFAPBuffer); | 39 attribs.push_back(kCGLPFAPBuffer); |
38 bool using_offline_renderer = | 40 bool using_offline_renderer = |
39 SupportsDualGpus() && gpu_preference == PreferIntegratedGpu; | 41 SupportsDualGpus() && gpu_preference == PreferIntegratedGpu; |
40 if (using_offline_renderer) { | 42 if (using_offline_renderer) { |
41 attribs.push_back(kCGLPFAAllowOfflineRenderers); | 43 attribs.push_back(kCGLPFAAllowOfflineRenderers); |
42 } | 44 } |
43 attribs.push_back((CGLPixelFormatAttribute) 0); | 45 attribs.push_back((CGLPixelFormatAttribute) 0); |
44 | 46 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 void GLContextCGL::SetSwapInterval(int interval) { | 155 void GLContextCGL::SetSwapInterval(int interval) { |
154 DCHECK(IsCurrent(NULL)); | 156 DCHECK(IsCurrent(NULL)); |
155 LOG(WARNING) << "GLContex: GLContextCGL::SetSwapInterval is ignored."; | 157 LOG(WARNING) << "GLContex: GLContextCGL::SetSwapInterval is ignored."; |
156 } | 158 } |
157 | 159 |
158 GpuPreference GLContextCGL::GetGpuPreference() { | 160 GpuPreference GLContextCGL::GetGpuPreference() { |
159 return gpu_preference_; | 161 return gpu_preference_; |
160 } | 162 } |
161 | 163 |
162 } // namespace gfx | 164 } // namespace gfx |
OLD | NEW |