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/compositor/compositor.h" | 5 #include "ui/gfx/compositor/compositor.h" |
6 | 6 |
7 #include <GL/gl.h> | 7 #include <GL/gl.h> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 void MakeCurrent(); | 56 void MakeCurrent(); |
57 gfx::Size GetSize(); | 57 gfx::Size GetSize(); |
58 | 58 |
59 private: | 59 private: |
60 // Overridden from Compositor. | 60 // Overridden from Compositor. |
61 virtual Texture* CreateTexture() OVERRIDE; | 61 virtual Texture* CreateTexture() OVERRIDE; |
62 virtual void NotifyStart() OVERRIDE; | 62 virtual void NotifyStart() OVERRIDE; |
63 virtual void NotifyEnd() OVERRIDE; | 63 virtual void NotifyEnd() OVERRIDE; |
64 | 64 |
65 // The GL context used for compositing. | 65 // The GL context used for compositing. |
| 66 scoped_ptr<gfx::GLSurface> gl_surface_; |
66 scoped_ptr<gfx::GLContext> gl_context_; | 67 scoped_ptr<gfx::GLContext> gl_context_; |
67 gfx::Size size_; | 68 gfx::Size size_; |
68 | 69 |
69 // Keep track of whether compositing has started or not. | 70 // Keep track of whether compositing has started or not. |
70 bool started_; | 71 bool started_; |
71 | 72 |
72 DISALLOW_COPY_AND_ASSIGN(CompositorGL); | 73 DISALLOW_COPY_AND_ASSIGN(CompositorGL); |
73 }; | 74 }; |
74 | 75 |
75 TextureGL::TextureGL(CompositorGL* compositor) : texture_id_(0), | 76 TextureGL::TextureGL(CompositorGL* compositor) : texture_id_(0), |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 | 188 |
188 if (!t.matrix().isIdentity()) { | 189 if (!t.matrix().isIdentity()) { |
189 glLoadIdentity(); | 190 glLoadIdentity(); |
190 } | 191 } |
191 | 192 |
192 glDisable(GL_TEXTURE_2D); | 193 glDisable(GL_TEXTURE_2D); |
193 } | 194 } |
194 | 195 |
195 CompositorGL::CompositorGL(gfx::AcceleratedWidget widget) | 196 CompositorGL::CompositorGL(gfx::AcceleratedWidget widget) |
196 : started_(false) { | 197 : started_(false) { |
197 scoped_ptr<gfx::GLSurface> surface( | 198 gl_surface_.reset(gfx::GLSurface::CreateViewGLSurface(widget)); |
198 gfx::GLSurface::CreateViewGLSurface(widget)); | 199 gl_context_.reset(gfx::GLContext::CreateGLContext(NULL, gl_surface.get())), |
199 gl_context_.reset(gfx::GLContext::CreateGLContext(surface.release(), NULL)), | |
200 gl_context_->MakeCurrent(); | 200 gl_context_->MakeCurrent(); |
201 glColorMask(true, true, true, true); | 201 glColorMask(true, true, true, true); |
202 glEnable(GL_BLEND); | 202 glEnable(GL_BLEND); |
203 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | 203 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
204 } | 204 } |
205 | 205 |
206 CompositorGL::~CompositorGL() { | 206 CompositorGL::~CompositorGL() { |
207 } | 207 } |
208 | 208 |
209 void CompositorGL::MakeCurrent() { | 209 void CompositorGL::MakeCurrent() { |
210 gl_context_->MakeCurrent(); | 210 gl_context_->MakeCurrent(); |
211 } | 211 } |
212 | 212 |
213 gfx::Size CompositorGL::GetSize() { | 213 gfx::Size CompositorGL::GetSize() { |
214 return gl_context_->GetSize(); | 214 return gl_context_->GetSize(); |
215 } | 215 } |
216 | 216 |
217 Texture* CompositorGL::CreateTexture() { | 217 Texture* CompositorGL::CreateTexture() { |
218 Texture* texture = new TextureGL(this); | 218 Texture* texture = new TextureGL(this); |
219 return texture; | 219 return texture; |
220 } | 220 } |
221 | 221 |
222 void CompositorGL::NotifyStart() { | 222 void CompositorGL::NotifyStart() { |
223 started_ = true; | 223 started_ = true; |
224 gl_context_->MakeCurrent(); | 224 gl_context_->MakeCurrent(gl_surface_.get()); |
225 glViewport(0, 0, | 225 glViewport(0, 0, |
226 gl_context_->GetSize().width(), gl_context_->GetSize().height()); | 226 gl_context_->GetSize().width(), gl_context_->GetSize().height()); |
227 | 227 |
228 // Clear to 'psychedelic' purple to make it easy to spot un-rendered regions. | 228 // Clear to 'psychedelic' purple to make it easy to spot un-rendered regions. |
229 glClearColor(223.0 / 255, 0, 1, 1); | 229 glClearColor(223.0 / 255, 0, 1, 1); |
230 glColorMask(true, true, true, true); | 230 glColorMask(true, true, true, true); |
231 glClear(GL_COLOR_BUFFER_BIT); | 231 glClear(GL_COLOR_BUFFER_BIT); |
232 // Disable alpha writes, since we're using blending anyways. | 232 // Disable alpha writes, since we're using blending anyways. |
233 glColorMask(true, true, true, false); | 233 glColorMask(true, true, true, false); |
234 } | 234 } |
235 | 235 |
236 void CompositorGL::NotifyEnd() { | 236 void CompositorGL::NotifyEnd() { |
237 DCHECK(started_); | 237 DCHECK(started_); |
238 gl_context_->SwapBuffers(); | 238 gl_surface_->SwapBuffers(); |
239 started_ = false; | 239 started_ = false; |
240 } | 240 } |
241 | 241 |
242 } // namespace | 242 } // namespace |
243 | 243 |
244 // static | 244 // static |
245 Compositor* Compositor::Create(gfx::AcceleratedWidget widget) { | 245 Compositor* Compositor::Create(gfx::AcceleratedWidget widget) { |
246 // The following line of code exists soley to disable IO restrictions | 246 // The following line of code exists soley to disable IO restrictions |
247 // on this thread long enough to perform the GL bindings. | 247 // on this thread long enough to perform the GL bindings. |
248 // TODO(backer) Remove this when GL initialisation cleaned up. | 248 // TODO(backer) Remove this when GL initialisation cleaned up. |
(...skipping 16 matching lines...) Expand all Loading... |
265 private: | 265 private: |
266 // Overridden from Compositor. | 266 // Overridden from Compositor. |
267 void NotifyStart() OVERRIDE; | 267 void NotifyStart() OVERRIDE; |
268 void NotifyEnd() OVERRIDE; | 268 void NotifyEnd() OVERRIDE; |
269 void DrawTextureWithTransform(TextureID txt, | 269 void DrawTextureWithTransform(TextureID txt, |
270 const ui::Transform& transform) OVERRIDE; | 270 const ui::Transform& transform) OVERRIDE; |
271 void SaveTransform() OVERRIDE; | 271 void SaveTransform() OVERRIDE; |
272 void RestoreTransform() OVERRIDE; | 272 void RestoreTransform() OVERRIDE; |
273 | 273 |
274 // The GL context used for compositing. | 274 // The GL context used for compositing. |
| 275 scoped_ptr<gfx::GLSurface> gl_surface_; |
275 scoped_ptr<gfx::GLContext> gl_context_; | 276 scoped_ptr<gfx::GLContext> gl_context_; |
276 | 277 |
277 // Keep track of whether compositing has started or not. | 278 // Keep track of whether compositing has started or not. |
278 bool started_; | 279 bool started_; |
279 | 280 |
280 DISALLOW_COPY_AND_ASSIGN(CompositorGL); | 281 DISALLOW_COPY_AND_ASSIGN(CompositorGL); |
281 }; | 282 }; |
282 | 283 |
283 CompositorGL::CompositorGL(gfx::AcceleratedWidget widget) | 284 CompositorGL::CompositorGL(gfx::AcceleratedWidget widget) |
284 : started_(false) { | 285 : started_(false) { |
285 scoped_ptr<gfx::GLSurface> surface( | 286 gl_surface_.reset(gfx::GLSurface::CreateViewGLSurface(widget)); |
286 gfx::GLSurface::CreateViewGLSurface(widget)); | 287 gl_context_.reset(gfx::GLContext::CreateGLContext(NULL, gl_surface_.get())); |
287 gl_context_.reset(gfx::GLContext::CreateGLContext(surface.release(), NULL)); | |
288 } | 288 } |
289 | 289 |
290 void CompositorGL::NotifyStart() { | 290 void CompositorGL::NotifyStart() { |
291 started_ = true; | 291 started_ = true; |
292 gl_context_->MakeCurrent(); | 292 gl_context_->MakeCurrent(gl_surface_.get()); |
293 } | 293 } |
294 | 294 |
295 void CompositorGL::NotifyEnd() { | 295 void CompositorGL::NotifyEnd() { |
296 DCHECK(started_); | 296 DCHECK(started_); |
297 gl_context_->SwapBuffers(); | 297 gl_surface_->SwapBuffers(); |
298 started_ = false; | 298 started_ = false; |
299 } | 299 } |
300 | 300 |
301 void CompositorGL::DrawTextureWithTransform(TextureID txt, | 301 void CompositorGL::DrawTextureWithTransform(TextureID txt, |
302 const ui::Transform& transform) { | 302 const ui::Transform& transform) { |
303 DCHECK(started_); | 303 DCHECK(started_); |
304 | 304 |
305 // TODO(wjmaclean): | 305 // TODO(wjmaclean): |
306 NOTIMPLEMENTED(); | 306 NOTIMPLEMENTED(); |
307 } | 307 } |
(...skipping 10 matching lines...) Expand all Loading... |
318 | 318 |
319 // static | 319 // static |
320 Compositor* Compositor::Create(gfx::AcceleratedWidget widget) { | 320 Compositor* Compositor::Create(gfx::AcceleratedWidget widget) { |
321 if (gfx::GetGLImplementation() != gfx::kGLImplementationNone) | 321 if (gfx::GetGLImplementation() != gfx::kGLImplementationNone) |
322 return new CompositorGL(widget); | 322 return new CompositorGL(widget); |
323 return NULL; | 323 return NULL; |
324 } | 324 } |
325 #endif | 325 #endif |
326 | 326 |
327 } // namespace ui | 327 } // namespace ui |
OLD | NEW |