Chromium Code Reviews| 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/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| (...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 551 if (debug_overdraw) | 551 if (debug_overdraw) |
| 552 glBlendFunc(GL_ONE, GL_ONE); | 552 glBlendFunc(GL_ONE, GL_ONE); |
| 553 else | 553 else |
| 554 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | 554 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
| 555 } | 555 } |
| 556 | 556 |
| 557 CompositorGL::~CompositorGL() { | 557 CompositorGL::~CompositorGL() { |
| 558 gl_context_ = NULL; | 558 gl_context_ = NULL; |
| 559 } | 559 } |
| 560 | 560 |
| 561 bool CompositorGL::ReadPixels(SkBitmap* bitmap) { | 561 bool CompositorGL::ReadPixels(SkBitmap* bitmap, const gfx::Rect& bounds) { |
| 562 MakeCurrent(); | 562 MakeCurrent(); |
| 563 | 563 |
| 564 if (bounds.right() > size().width() || bounds.bottom() > size().height()) | |
| 565 return false; | |
| 566 | |
| 564 bitmap->setConfig(SkBitmap::kARGB_8888_Config, | 567 bitmap->setConfig(SkBitmap::kARGB_8888_Config, |
| 565 size().width(), | 568 bounds.width(), |
| 566 size().height()); | 569 bounds.height()); |
| 567 bitmap->allocPixels(); | 570 bitmap->allocPixels(); |
| 568 SkAutoLockPixels lock(*bitmap); | 571 SkAutoLockPixels lock(*bitmap); |
| 569 unsigned char* pixels = static_cast<unsigned char*>(bitmap->getPixels()); | 572 unsigned char* pixels = static_cast<unsigned char*>(bitmap->getPixels()); |
| 570 | 573 |
| 571 // Check that it's a tight pixel packing | 574 // Check that it's a tight pixel packing |
| 572 DCHECK_EQ(bitmap->rowBytes(), | 575 DCHECK_EQ(bitmap->rowBytes(), |
| 573 SkBitmap::ComputeRowBytes(bitmap->config(), bitmap->width())); | 576 SkBitmap::ComputeRowBytes(bitmap->config(), bitmap->width())); |
| 574 | 577 |
| 575 GLint current_alignment = 0; | 578 GLint current_alignment = 0; |
| 576 glGetIntegerv(GL_PACK_ALIGNMENT, ¤t_alignment); | 579 glGetIntegerv(GL_PACK_ALIGNMENT, ¤t_alignment); |
| 577 glPixelStorei(GL_PACK_ALIGNMENT, 4); | 580 glPixelStorei(GL_PACK_ALIGNMENT, 4); |
| 578 glReadPixels(0, | 581 glReadPixels(bounds.x(), |
| 579 0, | 582 size().height() - bounds.y() - bounds.height(), |
|
Ian Vollick
2011/11/18 18:13:45
I think it would be helpful to have a comment like
| |
| 580 size().width(), | 583 bounds.width(), |
| 581 size().height(), | 584 bounds.height(), |
| 582 GL_RGBA, | 585 GL_RGBA, |
| 583 GL_UNSIGNED_BYTE, | 586 GL_UNSIGNED_BYTE, |
| 584 pixels); | 587 pixels); |
| 585 glPixelStorei(GL_PACK_ALIGNMENT, current_alignment); | 588 glPixelStorei(GL_PACK_ALIGNMENT, current_alignment); |
| 586 | 589 |
| 587 SwizzleRGBAToBGRAAndFlip(pixels, size()); | 590 SwizzleRGBAToBGRAAndFlip(pixels, bounds.size()); |
| 588 return true; | 591 return true; |
| 589 } | 592 } |
| 590 | 593 |
| 591 void CompositorGL::MakeCurrent() { | 594 void CompositorGL::MakeCurrent() { |
| 592 gl_context_->MakeCurrent(gl_surface_.get()); | 595 gl_context_->MakeCurrent(gl_surface_.get()); |
| 593 } | 596 } |
| 594 | 597 |
| 595 void CompositorGL::OnWidgetSizeChanged() { | 598 void CompositorGL::OnWidgetSizeChanged() { |
| 596 } | 599 } |
| 597 | 600 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 636 Compositor* Compositor::Create(CompositorDelegate* owner, | 639 Compositor* Compositor::Create(CompositorDelegate* owner, |
| 637 gfx::AcceleratedWidget widget, | 640 gfx::AcceleratedWidget widget, |
| 638 const gfx::Size& size) { | 641 const gfx::Size& size) { |
| 639 if (SharedResourcesGL::GetInstance() == NULL) | 642 if (SharedResourcesGL::GetInstance() == NULL) |
| 640 return NULL; | 643 return NULL; |
| 641 else | 644 else |
| 642 return new CompositorGL(owner, widget, size); | 645 return new CompositorGL(owner, widget, size); |
| 643 } | 646 } |
| 644 | 647 |
| 645 } // namespace ui | 648 } // namespace ui |
| OLD | NEW |