Chromium Code Reviews| Index: chrome/browser/ui/window_snapshot/window_snapshot_aura.cc |
| diff --git a/chrome/browser/ui/window_snapshot/window_snapshot_aura.cc b/chrome/browser/ui/window_snapshot/window_snapshot_aura.cc |
| index 3a652136ec15054d37a47e04d344303925ecd94d..385c8dd507180c400b1a48e7820d894babb9ff5f 100644 |
| --- a/chrome/browser/ui/window_snapshot/window_snapshot_aura.cc |
| +++ b/chrome/browser/ui/window_snapshot/window_snapshot_aura.cc |
| @@ -5,16 +5,38 @@ |
| #include "chrome/browser/ui/window_snapshot/window_snapshot.h" |
| #include "base/logging.h" |
| +#include "third_party/skia/include/core/SkBitmap.h" |
| +#include "ui/aura/desktop.h" |
|
sky
2011/11/18 21:08:06
remove desktop include.
|
| +#include "ui/gfx/codec/png_codec.h" |
| +#include "ui/gfx/compositor/compositor.h" |
| #include "ui/gfx/rect.h" |
| namespace browser { |
| -bool GrabWindowSnapshot(gfx::NativeWindow window_handle, |
| +bool GrabWindowSnapshot(gfx::NativeWindow window, |
| std::vector<unsigned char>* png_representation, |
| const gfx::Rect& snapshot_bounds) { |
| - // TODO(saintlou): Stub for Aura. |
| - NOTIMPLEMENTED(); |
| - return false; |
| + ui::Compositor* compositor = window->layer()->GetCompositor(); |
| + |
| + gfx::Rect desktop_snapshot_bounds = gfx::Rect( |
| + snapshot_bounds.origin().Add(window->bounds().origin()), |
| + snapshot_bounds.size()); |
| + |
| + DCHECK_LE(desktop_snapshot_bounds.right() , compositor->size().width()); |
| + DCHECK_LE(desktop_snapshot_bounds.bottom(), compositor->size().height()); |
| + |
| + SkBitmap bitmap; |
| + if (!compositor->ReadPixels(&bitmap, desktop_snapshot_bounds)) |
| + return false; |
| + |
| + unsigned char* pixels = reinterpret_cast<unsigned char*>(bitmap.getPixels()); |
| + |
| + gfx::PNGCodec::Encode(pixels, gfx::PNGCodec::FORMAT_BGRA, |
| + snapshot_bounds.size(), |
| + bitmap.rowBytes(), true, |
| + std::vector<gfx::PNGCodec::Comment>(), |
| + png_representation); |
| + return true; |
| } |
| } // namespace browser |