| 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/logging.h" | 10 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
| 12 #include "base/threading/thread_restrictions.h" | 13 #include "base/threading/thread_restrictions.h" |
| 13 #include "third_party/skia/include/core/SkDevice.h" | 14 #include "third_party/skia/include/core/SkDevice.h" |
| 14 #include "third_party/skia/include/core/SkMatrix.h" | 15 #include "third_party/skia/include/core/SkMatrix.h" |
| 15 #include "third_party/skia/include/core/SkPoint.h" | 16 #include "third_party/skia/include/core/SkPoint.h" |
| 16 #include "third_party/skia/include/core/SkRect.h" | 17 #include "third_party/skia/include/core/SkRect.h" |
| 17 #include "third_party/skia/include/core/SkScalar.h" | 18 #include "third_party/skia/include/core/SkScalar.h" |
| 18 #include "ui/gfx/rect.h" | 19 #include "ui/gfx/rect.h" |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 SharedResourcesGL* instance = SharedResourcesGL::GetInstance(); | 330 SharedResourcesGL* instance = SharedResourcesGL::GetInstance(); |
| 330 DCHECK(instance); | 331 DCHECK(instance); |
| 331 instance->MakeSharedContextCurrent(); | 332 instance->MakeSharedContextCurrent(); |
| 332 glDeleteTextures(1, &texture_id_); | 333 glDeleteTextures(1, &texture_id_); |
| 333 } | 334 } |
| 334 } | 335 } |
| 335 | 336 |
| 336 void TextureGL::SetCanvas(const SkCanvas& canvas, | 337 void TextureGL::SetCanvas(const SkCanvas& canvas, |
| 337 const gfx::Point& origin, | 338 const gfx::Point& origin, |
| 338 const gfx::Size& overall_size) { | 339 const gfx::Size& overall_size) { |
| 340 TRACE_EVENT0("ui", "TextureGL::SetCanvas"); |
| 339 const SkBitmap& bitmap = canvas.getDevice()->accessBitmap(false); | 341 const SkBitmap& bitmap = canvas.getDevice()->accessBitmap(false); |
| 340 // Verify bitmap pixels are contiguous. | 342 // Verify bitmap pixels are contiguous. |
| 341 DCHECK_EQ(bitmap.rowBytes(), | 343 DCHECK_EQ(bitmap.rowBytes(), |
| 342 SkBitmap::ComputeRowBytes(bitmap.config(), bitmap.width())); | 344 SkBitmap::ComputeRowBytes(bitmap.config(), bitmap.width())); |
| 343 SkAutoLockPixels lock(bitmap); | 345 SkAutoLockPixels lock(bitmap); |
| 344 void* pixels = bitmap.getPixels(); | 346 void* pixels = bitmap.getPixels(); |
| 345 | 347 |
| 346 if (!texture_id_) { | 348 if (!texture_id_) { |
| 347 // Texture needs to be created. We assume the first call is for | 349 // Texture needs to be created. We assume the first call is for |
| 348 // a full-sized canvas. | 350 // a full-sized canvas. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 367 } else { // Uploading partial texture. | 369 } else { // Uploading partial texture. |
| 368 glBindTexture(GL_TEXTURE_2D, texture_id_); | 370 glBindTexture(GL_TEXTURE_2D, texture_id_); |
| 369 glTexSubImage2D(GL_TEXTURE_2D, 0, origin.x(), origin.y(), | 371 glTexSubImage2D(GL_TEXTURE_2D, 0, origin.x(), origin.y(), |
| 370 bitmap.width(), bitmap.height(), | 372 bitmap.width(), bitmap.height(), |
| 371 GL_RGBA, GL_UNSIGNED_BYTE, pixels); | 373 GL_RGBA, GL_UNSIGNED_BYTE, pixels); |
| 372 } | 374 } |
| 373 } | 375 } |
| 374 | 376 |
| 375 void TextureGL::Draw(const ui::TextureDrawParams& params, | 377 void TextureGL::Draw(const ui::TextureDrawParams& params, |
| 376 const gfx::Rect& clip_bounds_in_texture) { | 378 const gfx::Rect& clip_bounds_in_texture) { |
| 379 TRACE_EVENT0("ui", "TextureGL::Draw"); |
| 377 SharedResourcesGL* instance = SharedResourcesGL::GetInstance(); | 380 SharedResourcesGL* instance = SharedResourcesGL::GetInstance(); |
| 378 DCHECK(instance); | 381 DCHECK(instance); |
| 379 DrawInternal(*instance->program_swizzle(), | 382 DrawInternal(*instance->program_swizzle(), |
| 380 params, | 383 params, |
| 381 clip_bounds_in_texture); | 384 clip_bounds_in_texture); |
| 382 } | 385 } |
| 383 | 386 |
| 384 void TextureGL::DrawInternal(const ui::TextureProgramGL& program, | 387 void TextureGL::DrawInternal(const ui::TextureProgramGL& program, |
| 385 const ui::TextureDrawParams& params, | 388 const ui::TextureDrawParams& params, |
| 386 const gfx::Rect& clip_bounds_in_texture) { | 389 const gfx::Rect& clip_bounds_in_texture) { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 | 511 |
| 509 void CompositorGL::OnWidgetSizeChanged() { | 512 void CompositorGL::OnWidgetSizeChanged() { |
| 510 } | 513 } |
| 511 | 514 |
| 512 Texture* CompositorGL::CreateTexture() { | 515 Texture* CompositorGL::CreateTexture() { |
| 513 Texture* texture = new TextureGL(); | 516 Texture* texture = new TextureGL(); |
| 514 return texture; | 517 return texture; |
| 515 } | 518 } |
| 516 | 519 |
| 517 void CompositorGL::OnNotifyStart(bool clear) { | 520 void CompositorGL::OnNotifyStart(bool clear) { |
| 521 TRACE_EVENT0("ui", "CompositorGL::OnNotifyStart"); |
| 518 started_ = true; | 522 started_ = true; |
| 519 gl_context_->MakeCurrent(gl_surface_.get()); | 523 gl_context_->MakeCurrent(gl_surface_.get()); |
| 520 glViewport(0, 0, size().width(), size().height()); | 524 glViewport(0, 0, size().width(), size().height()); |
| 521 glColorMask(true, true, true, true); | 525 glColorMask(true, true, true, true); |
| 522 | 526 |
| 523 if (clear) { | 527 if (clear) { |
| 524 glClearColor(0, 0, 0, 0); | 528 glClearColor(0, 0, 0, 0); |
| 525 glClear(GL_COLOR_BUFFER_BIT); | 529 glClear(GL_COLOR_BUFFER_BIT); |
| 526 } | 530 } |
| 527 #if !defined(NDEBUG) | 531 #if !defined(NDEBUG) |
| 528 else { | 532 else { |
| 529 // In debug mode, when we're not forcing a clear, clear to 'psychedelic' | 533 // In debug mode, when we're not forcing a clear, clear to 'psychedelic' |
| 530 // purple to make it easy to spot un-rendered regions. | 534 // purple to make it easy to spot un-rendered regions. |
| 531 glClearColor(223.0 / 255, 0, 1, 1); | 535 glClearColor(223.0 / 255, 0, 1, 1); |
| 532 glClear(GL_COLOR_BUFFER_BIT); | 536 glClear(GL_COLOR_BUFFER_BIT); |
| 533 } | 537 } |
| 534 #endif | 538 #endif |
| 535 } | 539 } |
| 536 | 540 |
| 537 void CompositorGL::OnNotifyEnd() { | 541 void CompositorGL::OnNotifyEnd() { |
| 542 TRACE_EVENT0("ui", "CompositorGL::OnNotifyEnd"); |
| 538 DCHECK(started_); | 543 DCHECK(started_); |
| 539 gl_surface_->SwapBuffers(); | 544 gl_surface_->SwapBuffers(); |
| 540 started_ = false; | 545 started_ = false; |
| 541 } | 546 } |
| 542 | 547 |
| 543 void CompositorGL::Blur(const gfx::Rect& bounds) { | 548 void CompositorGL::Blur(const gfx::Rect& bounds) { |
| 544 NOTIMPLEMENTED(); | 549 NOTIMPLEMENTED(); |
| 545 } | 550 } |
| 546 | 551 |
| 547 // static | 552 // static |
| 548 Compositor* Compositor::Create(CompositorDelegate* owner, | 553 Compositor* Compositor::Create(CompositorDelegate* owner, |
| 549 gfx::AcceleratedWidget widget, | 554 gfx::AcceleratedWidget widget, |
| 550 const gfx::Size& size) { | 555 const gfx::Size& size) { |
| 551 if (SharedResourcesGL::GetInstance() == NULL) | 556 if (SharedResourcesGL::GetInstance() == NULL) |
| 552 return NULL; | 557 return NULL; |
| 553 else | 558 else |
| 554 return new CompositorGL(owner, widget, size); | 559 return new CompositorGL(owner, widget, size); |
| 555 } | 560 } |
| 556 | 561 |
| 557 } // namespace ui | 562 } // namespace ui |
| OLD | NEW |