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 <OpenGL/CGLRenderers.h> | |
7 #include <vector> | 8 #include <vector> |
8 | 9 |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "ui/gfx/gl/gl_bindings.h" | 11 #include "ui/gfx/gl/gl_bindings.h" |
12 #include "ui/gfx/gl/gl_implementation.h" | |
11 #include "ui/gfx/gl/gl_surface_cgl.h" | 13 #include "ui/gfx/gl/gl_surface_cgl.h" |
12 | 14 |
13 namespace gfx { | 15 namespace gfx { |
14 | 16 |
15 GLContextCGL::GLContextCGL(GLShareGroup* share_group) | 17 GLContextCGL::GLContextCGL(GLShareGroup* share_group) |
16 : GLContext(share_group), | 18 : GLContext(share_group), |
17 context_(NULL), | 19 context_(NULL), |
18 gpu_preference_(PreferIntegratedGpu) { | 20 gpu_preference_(PreferIntegratedGpu) { |
19 } | 21 } |
20 | 22 |
(...skipping 14 matching lines...) Expand all Loading... | |
35 return false; | 37 return false; |
36 } | 38 } |
37 | 39 |
38 std::vector<CGLPixelFormatAttribute> attribs; | 40 std::vector<CGLPixelFormatAttribute> attribs; |
39 attribs.push_back(kCGLPFAPBuffer); | 41 attribs.push_back(kCGLPFAPBuffer); |
40 bool using_offline_renderer = | 42 bool using_offline_renderer = |
41 SupportsDualGpus() && gpu_preference == PreferIntegratedGpu; | 43 SupportsDualGpus() && gpu_preference == PreferIntegratedGpu; |
42 if (using_offline_renderer) { | 44 if (using_offline_renderer) { |
43 attribs.push_back(kCGLPFAAllowOfflineRenderers); | 45 attribs.push_back(kCGLPFAAllowOfflineRenderers); |
44 } | 46 } |
47 if (GetGLImplementation() == kGLImplementationAppleGL) { | |
48 attribs.push_back(kCGLPFARendererID); | |
49 attribs.push_back((CGLPixelFormatAttribute) kCGLRendererGenericFloatID); | |
Ken Russell (switch to Gerrit)
2011/12/06 19:23:47
What are the interactions with (a) the dual-GPU co
Stephen White
2011/12/06 19:49:04
Since this is strictly a software renderer, it sho
Ken Russell (switch to Gerrit)
2011/12/06 22:49:45
Sorry, there isn't currently. I don't know how to
| |
50 } | |
45 attribs.push_back((CGLPixelFormatAttribute) 0); | 51 attribs.push_back((CGLPixelFormatAttribute) 0); |
46 | 52 |
47 CGLPixelFormatObj format; | 53 CGLPixelFormatObj format; |
48 GLint num_pixel_formats; | 54 GLint num_pixel_formats; |
49 if (CGLChoosePixelFormat(&attribs.front(), | 55 if (CGLChoosePixelFormat(&attribs.front(), |
50 &format, | 56 &format, |
51 &num_pixel_formats) != kCGLNoError) { | 57 &num_pixel_formats) != kCGLNoError) { |
52 LOG(ERROR) << "Error choosing pixel format."; | 58 LOG(ERROR) << "Error choosing pixel format."; |
53 return false; | 59 return false; |
54 } | 60 } |
(...skipping 24 matching lines...) Expand all Loading... | |
79 CGLDestroyContext(static_cast<CGLContextObj>(context_)); | 85 CGLDestroyContext(static_cast<CGLContextObj>(context_)); |
80 context_ = NULL; | 86 context_ = NULL; |
81 } | 87 } |
82 } | 88 } |
83 | 89 |
84 bool GLContextCGL::MakeCurrent(GLSurface* surface) { | 90 bool GLContextCGL::MakeCurrent(GLSurface* surface) { |
85 DCHECK(context_); | 91 DCHECK(context_); |
86 if (IsCurrent(surface)) | 92 if (IsCurrent(surface)) |
87 return true; | 93 return true; |
88 | 94 |
89 if (CGLSetPBuffer(static_cast<CGLContextObj>(context_), | |
90 static_cast<CGLPBufferObj>(surface->GetHandle()), | |
91 0, | |
92 0, | |
93 0) != kCGLNoError) { | |
94 LOG(ERROR) << "Error attaching pbuffer to context."; | |
95 Destroy(); | |
96 return false; | |
97 } | |
98 | |
99 if (CGLSetCurrentContext( | 95 if (CGLSetCurrentContext( |
100 static_cast<CGLContextObj>(context_)) != kCGLNoError) { | 96 static_cast<CGLContextObj>(context_)) != kCGLNoError) { |
101 LOG(ERROR) << "Unable to make gl context current."; | 97 LOG(ERROR) << "Unable to make gl context current."; |
102 return false; | 98 return false; |
103 } | 99 } |
104 | 100 |
105 SetCurrent(this, surface); | 101 SetCurrent(this, surface); |
106 if (!InitializeExtensionBindings()) { | 102 if (!InitializeExtensionBindings()) { |
107 ReleaseCurrent(surface); | 103 ReleaseCurrent(surface); |
108 return false; | 104 return false; |
109 } | 105 } |
110 | 106 |
111 if (!surface->OnMakeCurrent(this)) { | 107 if (!surface->OnMakeCurrent(this)) { |
112 LOG(ERROR) << "Unable to make gl context current."; | 108 LOG(ERROR) << "Unable to make gl context current."; |
113 return false; | 109 return false; |
114 } | 110 } |
115 | 111 |
116 return true; | 112 return true; |
117 } | 113 } |
118 | 114 |
119 void GLContextCGL::ReleaseCurrent(GLSurface* surface) { | 115 void GLContextCGL::ReleaseCurrent(GLSurface* surface) { |
120 if (!IsCurrent(surface)) | 116 if (!IsCurrent(surface)) |
121 return; | 117 return; |
122 | 118 |
123 SetCurrent(NULL, NULL); | 119 SetCurrent(NULL, NULL); |
124 CGLSetCurrentContext(NULL); | 120 CGLSetCurrentContext(NULL); |
125 CGLSetPBuffer(static_cast<CGLContextObj>(context_), NULL, 0, 0, 0); | |
126 } | 121 } |
127 | 122 |
128 bool GLContextCGL::IsCurrent(GLSurface* surface) { | 123 bool GLContextCGL::IsCurrent(GLSurface* surface) { |
129 bool native_context_is_current = CGLGetCurrentContext() == context_; | 124 bool native_context_is_current = CGLGetCurrentContext() == context_; |
130 | 125 |
131 // If our context is current then our notion of which GLContext is | 126 // If our context is current then our notion of which GLContext is |
132 // current must be correct. On the other hand, third-party code | 127 // current must be correct. On the other hand, third-party code |
133 // using OpenGL might change the current context. | 128 // using OpenGL might change the current context. |
134 DCHECK(!native_context_is_current || (GetCurrent() == this)); | 129 DCHECK(!native_context_is_current || (GetCurrent() == this)); |
135 | 130 |
136 if (!native_context_is_current) | 131 if (!native_context_is_current) |
137 return false; | 132 return false; |
138 | 133 |
139 if (surface) { | |
140 CGLPBufferObj current_surface = NULL; | |
141 GLenum face; | |
142 GLint level; | |
143 GLint screen; | |
144 CGLGetPBuffer(static_cast<CGLContextObj>(context_), | |
145 ¤t_surface, | |
146 &face, | |
147 &level, | |
148 &screen); | |
149 if (current_surface != surface->GetHandle()) | |
150 return false; | |
151 } | |
152 | |
153 return true; | 134 return true; |
154 } | 135 } |
155 | 136 |
156 void* GLContextCGL::GetHandle() { | 137 void* GLContextCGL::GetHandle() { |
157 return context_; | 138 return context_; |
158 } | 139 } |
159 | 140 |
160 void GLContextCGL::SetSwapInterval(int interval) { | 141 void GLContextCGL::SetSwapInterval(int interval) { |
161 DCHECK(IsCurrent(NULL)); | 142 DCHECK(IsCurrent(NULL)); |
162 LOG(WARNING) << "GLContex: GLContextCGL::SetSwapInterval is ignored."; | 143 LOG(WARNING) << "GLContex: GLContextCGL::SetSwapInterval is ignored."; |
163 } | 144 } |
164 | 145 |
165 GpuPreference GLContextCGL::GetGpuPreference() { | 146 GpuPreference GLContextCGL::GetGpuPreference() { |
166 return gpu_preference_; | 147 return gpu_preference_; |
167 } | 148 } |
168 | 149 |
169 } // namespace gfx | 150 } // namespace gfx |
OLD | NEW |