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_gl.h" | 5 #include "ui/gfx/compositor/compositor_gl.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 initialized_ = false; | 297 initialized_ = false; |
298 } | 298 } |
299 | 299 |
300 bool SharedResourcesGL::MakeSharedContextCurrent() { | 300 bool SharedResourcesGL::MakeSharedContextCurrent() { |
301 if (!initialized_) | 301 if (!initialized_) |
302 return false; | 302 return false; |
303 else | 303 else |
304 return context_->MakeCurrent(surface_.get()); | 304 return context_->MakeCurrent(surface_.get()); |
305 } | 305 } |
306 | 306 |
| 307 gfx::ScopedMakeCurrent* SharedResourcesGL::GetScopedMakeCurrent() { |
| 308 return new gfx::ScopedMakeCurrent(context_.get(), surface_.get()); |
| 309 } |
| 310 |
307 scoped_refptr<gfx::GLContext> SharedResourcesGL::CreateContext( | 311 scoped_refptr<gfx::GLContext> SharedResourcesGL::CreateContext( |
308 gfx::GLSurface* surface) { | 312 gfx::GLSurface* surface) { |
309 if (initialized_) | 313 if (initialized_) |
310 return gfx::GLContext::CreateGLContext( | 314 return gfx::GLContext::CreateGLContext( |
311 context_->share_group(), | 315 context_->share_group(), |
312 surface, | 316 surface, |
313 gfx::PreferIntegratedGpu); | 317 gfx::PreferIntegratedGpu); |
314 else | 318 else |
315 return NULL; | 319 return NULL; |
316 } | 320 } |
317 | 321 |
318 void* SharedResourcesGL::GetDisplay() { | 322 void* SharedResourcesGL::GetDisplay() { |
319 return surface_->GetDisplay(); | 323 return surface_->GetDisplay(); |
320 } | 324 } |
321 | 325 |
322 TextureGL::TextureGL() : texture_id_(0) { | 326 TextureGL::TextureGL() : texture_id_(0) { |
323 } | 327 } |
324 | 328 |
325 TextureGL::TextureGL(const gfx::Size& size) : texture_id_(0), size_(size) { | 329 TextureGL::TextureGL(const gfx::Size& size) : texture_id_(0), size_(size) { |
326 } | 330 } |
327 | 331 |
328 TextureGL::~TextureGL() { | 332 TextureGL::~TextureGL() { |
329 if (texture_id_) { | 333 if (texture_id_) { |
330 SharedResourcesGL* instance = SharedResourcesGL::GetInstance(); | 334 SharedResourcesGL* instance = SharedResourcesGL::GetInstance(); |
331 DCHECK(instance); | 335 DCHECK(instance); |
332 instance->MakeSharedContextCurrent(); | 336 scoped_ptr<gfx::ScopedMakeCurrent> bind(instance->GetScopedMakeCurrent()); |
333 glDeleteTextures(1, &texture_id_); | 337 glDeleteTextures(1, &texture_id_); |
334 } | 338 } |
335 } | 339 } |
336 | 340 |
337 void TextureGL::SetCanvas(const SkCanvas& canvas, | 341 void TextureGL::SetCanvas(const SkCanvas& canvas, |
338 const gfx::Point& origin, | 342 const gfx::Point& origin, |
339 const gfx::Size& overall_size) { | 343 const gfx::Size& overall_size) { |
340 TRACE_EVENT0("ui", "TextureGL::SetCanvas"); | 344 TRACE_EVENT0("ui", "TextureGL::SetCanvas"); |
341 const SkBitmap& bitmap = canvas.getDevice()->accessBitmap(false); | 345 const SkBitmap& bitmap = canvas.getDevice()->accessBitmap(false); |
342 // Verify bitmap pixels are contiguous. | 346 // Verify bitmap pixels are contiguous. |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 Compositor* Compositor::Create(CompositorDelegate* owner, | 557 Compositor* Compositor::Create(CompositorDelegate* owner, |
554 gfx::AcceleratedWidget widget, | 558 gfx::AcceleratedWidget widget, |
555 const gfx::Size& size) { | 559 const gfx::Size& size) { |
556 if (SharedResourcesGL::GetInstance() == NULL) | 560 if (SharedResourcesGL::GetInstance() == NULL) |
557 return NULL; | 561 return NULL; |
558 else | 562 else |
559 return new CompositorGL(owner, widget, size); | 563 return new CompositorGL(owner, widget, size); |
560 } | 564 } |
561 | 565 |
562 } // namespace ui | 566 } // namespace ui |
OLD | NEW |