| 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 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 if (debug_overdraw) | 554 if (debug_overdraw) |
| 555 glBlendFunc(GL_ONE, GL_ONE); | 555 glBlendFunc(GL_ONE, GL_ONE); |
| 556 else | 556 else |
| 557 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | 557 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
| 558 } | 558 } |
| 559 | 559 |
| 560 CompositorGL::~CompositorGL() { | 560 CompositorGL::~CompositorGL() { |
| 561 gl_context_ = NULL; | 561 gl_context_ = NULL; |
| 562 } | 562 } |
| 563 | 563 |
| 564 void CompositorGL::ReadPixels(SkBitmap* bitmap) { | 564 bool CompositorGL::ReadPixels(SkBitmap* bitmap) { |
| 565 MakeCurrent(); | 565 MakeCurrent(); |
| 566 | 566 |
| 567 bitmap->setConfig(SkBitmap::kARGB_8888_Config, | 567 bitmap->setConfig(SkBitmap::kARGB_8888_Config, |
| 568 size().width(), | 568 size().width(), |
| 569 size().height()); | 569 size().height()); |
| 570 bitmap->allocPixels(); | 570 bitmap->allocPixels(); |
| 571 SkAutoLockPixels lock(*bitmap); | 571 SkAutoLockPixels lock(*bitmap); |
| 572 unsigned char* pixels = static_cast<unsigned char*>(bitmap->getPixels()); | 572 unsigned char* pixels = static_cast<unsigned char*>(bitmap->getPixels()); |
| 573 | 573 |
| 574 // Check that it's a tight pixel packing | 574 // Check that it's a tight pixel packing |
| 575 DCHECK_EQ(bitmap->rowBytes(), | 575 DCHECK_EQ(bitmap->rowBytes(), |
| 576 SkBitmap::ComputeRowBytes(bitmap->config(), bitmap->width())); | 576 SkBitmap::ComputeRowBytes(bitmap->config(), bitmap->width())); |
| 577 | 577 |
| 578 GLint current_alignment = 0; | 578 GLint current_alignment = 0; |
| 579 glGetIntegerv(GL_PACK_ALIGNMENT, ¤t_alignment); | 579 glGetIntegerv(GL_PACK_ALIGNMENT, ¤t_alignment); |
| 580 glPixelStorei(GL_PACK_ALIGNMENT, 4); | 580 glPixelStorei(GL_PACK_ALIGNMENT, 4); |
| 581 glReadPixels(0, | 581 glReadPixels(0, |
| 582 0, | 582 0, |
| 583 size().width(), | 583 size().width(), |
| 584 size().height(), | 584 size().height(), |
| 585 GL_RGBA, | 585 GL_RGBA, |
| 586 GL_UNSIGNED_BYTE, | 586 GL_UNSIGNED_BYTE, |
| 587 pixels); | 587 pixels); |
| 588 glPixelStorei(GL_PACK_ALIGNMENT, current_alignment); | 588 glPixelStorei(GL_PACK_ALIGNMENT, current_alignment); |
| 589 | 589 |
| 590 // Swizzle from RGBA to BGRA | 590 SwizzleRGBAToBGRAAndFlip(pixels, size()); |
| 591 size_t bitmap_size = 4 * size().width() * size().height(); | 591 return true; |
| 592 for(size_t i = 0; i < bitmap_size; i += 4) | |
| 593 std::swap(pixels[i], pixels[i + 2]); | |
| 594 | |
| 595 // Vertical flip to transform from GL co-ords | |
| 596 size_t row_size = 4 * size().width(); | |
| 597 scoped_array<unsigned char> tmp_row(new unsigned char[row_size]); | |
| 598 for(int row = 0; row < size().height() / 2; row++) { | |
| 599 memcpy(tmp_row.get(), | |
| 600 &pixels[row * row_size], | |
| 601 row_size); | |
| 602 memcpy(&pixels[row * row_size], | |
| 603 &pixels[bitmap_size - (row + 1) * row_size], | |
| 604 row_size); | |
| 605 memcpy(&pixels[bitmap_size - (row + 1) * row_size], | |
| 606 tmp_row.get(), | |
| 607 row_size); | |
| 608 } | |
| 609 } | 592 } |
| 610 | 593 |
| 611 void CompositorGL::MakeCurrent() { | 594 void CompositorGL::MakeCurrent() { |
| 612 gl_context_->MakeCurrent(gl_surface_.get()); | 595 gl_context_->MakeCurrent(gl_surface_.get()); |
| 613 } | 596 } |
| 614 | 597 |
| 615 void CompositorGL::OnWidgetSizeChanged() { | 598 void CompositorGL::OnWidgetSizeChanged() { |
| 616 } | 599 } |
| 617 | 600 |
| 618 Texture* CompositorGL::CreateTexture() { | 601 Texture* CompositorGL::CreateTexture() { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 Compositor* Compositor::Create(CompositorDelegate* owner, | 639 Compositor* Compositor::Create(CompositorDelegate* owner, |
| 657 gfx::AcceleratedWidget widget, | 640 gfx::AcceleratedWidget widget, |
| 658 const gfx::Size& size) { | 641 const gfx::Size& size) { |
| 659 if (SharedResourcesGL::GetInstance() == NULL) | 642 if (SharedResourcesGL::GetInstance() == NULL) |
| 660 return NULL; | 643 return NULL; |
| 661 else | 644 else |
| 662 return new CompositorGL(owner, widget, size); | 645 return new CompositorGL(owner, widget, size); |
| 663 } | 646 } |
| 664 | 647 |
| 665 } // namespace ui | 648 } // namespace ui |
| OLD | NEW |