Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(414)

Side by Side Diff: ui/gfx/compositor/compositor_gl.cc

Issue 8558033: Revert 110783 - Adds a bounds parameter to ui::Compositor::ReadPixels (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/gfx/compositor/compositor_gl.h ('k') | ui/gfx/compositor/layer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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, const gfx::Rect& bounds) { 561 bool CompositorGL::ReadPixels(SkBitmap* bitmap) {
562 MakeCurrent(); 562 MakeCurrent();
563 563
564 if (bounds.right() > size().width() || bounds.bottom() > size().height())
565 return false;
566
567 bitmap->setConfig(SkBitmap::kARGB_8888_Config, 564 bitmap->setConfig(SkBitmap::kARGB_8888_Config,
568 bounds.width(), 565 size().width(),
569 bounds.height()); 566 size().height());
570 bitmap->allocPixels(); 567 bitmap->allocPixels();
571 SkAutoLockPixels lock(*bitmap); 568 SkAutoLockPixels lock(*bitmap);
572 unsigned char* pixels = static_cast<unsigned char*>(bitmap->getPixels()); 569 unsigned char* pixels = static_cast<unsigned char*>(bitmap->getPixels());
573 570
574 // Check that it's a tight pixel packing 571 // Check that it's a tight pixel packing
575 DCHECK_EQ(bitmap->rowBytes(), 572 DCHECK_EQ(bitmap->rowBytes(),
576 SkBitmap::ComputeRowBytes(bitmap->config(), bitmap->width())); 573 SkBitmap::ComputeRowBytes(bitmap->config(), bitmap->width()));
577 574
578 GLint current_alignment = 0; 575 GLint current_alignment = 0;
579 glGetIntegerv(GL_PACK_ALIGNMENT, &current_alignment); 576 glGetIntegerv(GL_PACK_ALIGNMENT, &current_alignment);
580 glPixelStorei(GL_PACK_ALIGNMENT, 4); 577 glPixelStorei(GL_PACK_ALIGNMENT, 4);
581 578 glReadPixels(0,
582 // Flip vertically to convert to OpenGL coordinates. 579 0,
583 glReadPixels(bounds.x(), 580 size().width(),
584 size().height() - bounds.y() - bounds.height(), 581 size().height(),
585 bounds.width(),
586 bounds.height(),
587 GL_RGBA, 582 GL_RGBA,
588 GL_UNSIGNED_BYTE, 583 GL_UNSIGNED_BYTE,
589 pixels); 584 pixels);
590 glPixelStorei(GL_PACK_ALIGNMENT, current_alignment); 585 glPixelStorei(GL_PACK_ALIGNMENT, current_alignment);
591 586
592 SwizzleRGBAToBGRAAndFlip(pixels, bounds.size()); 587 SwizzleRGBAToBGRAAndFlip(pixels, size());
593 return true; 588 return true;
594 } 589 }
595 590
596 void CompositorGL::MakeCurrent() { 591 void CompositorGL::MakeCurrent() {
597 gl_context_->MakeCurrent(gl_surface_.get()); 592 gl_context_->MakeCurrent(gl_surface_.get());
598 } 593 }
599 594
600 void CompositorGL::OnWidgetSizeChanged() { 595 void CompositorGL::OnWidgetSizeChanged() {
601 } 596 }
602 597
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 Compositor* Compositor::Create(CompositorDelegate* owner, 636 Compositor* Compositor::Create(CompositorDelegate* owner,
642 gfx::AcceleratedWidget widget, 637 gfx::AcceleratedWidget widget,
643 const gfx::Size& size) { 638 const gfx::Size& size) {
644 if (SharedResourcesGL::GetInstance() == NULL) 639 if (SharedResourcesGL::GetInstance() == NULL)
645 return NULL; 640 return NULL;
646 else 641 else
647 return new CompositorGL(owner, widget, size); 642 return new CompositorGL(owner, widget, size);
648 } 643 }
649 644
650 } // namespace ui 645 } // namespace ui
OLDNEW
« no previous file with comments | « ui/gfx/compositor/compositor_gl.h ('k') | ui/gfx/compositor/layer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698