| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/ui/window_snapshot/window_snapshot.h" | 5 #include "chrome/browser/ui/window_snapshot/window_snapshot.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "third_party/skia/include/core/SkBitmap.h" | 8 #include "third_party/skia/include/core/SkBitmap.h" |
| 9 #include "ui/aura/window.h" | 9 #include "ui/aura/window.h" |
| 10 #include "ui/compositor/compositor.h" | 10 #include "ui/compositor/compositor.h" |
| 11 #include "ui/compositor/dip_util.h" | 11 #include "ui/compositor/dip_util.h" |
| 12 #include "ui/compositor/layer.h" | 12 #include "ui/compositor/layer.h" |
| 13 #include "ui/gfx/codec/png_codec.h" | 13 #include "ui/gfx/codec/png_codec.h" |
| 14 #include "ui/gfx/rect.h" | 14 #include "ui/gfx/rect.h" |
| 15 | 15 |
| 16 namespace chrome { | 16 namespace chrome { |
| 17 namespace internal { | 17 namespace internal { |
| 18 | 18 |
| 19 bool GrabWindowSnapshot(gfx::NativeWindow window, | 19 bool GrabWindowSnapshot(gfx::NativeWindow window, |
| 20 std::vector<unsigned char>* png_representation, | 20 std::vector<unsigned char>* png_representation, |
| 21 const gfx::Rect& snapshot_bounds) { | 21 const gfx::Rect& snapshot_bounds) { |
| 22 ui::Compositor* compositor = window->layer()->GetCompositor(); | 22 ui::Compositor* compositor = window->layer()->GetCompositor(); |
| 23 | 23 |
| 24 gfx::Rect read_pixels_bounds = snapshot_bounds; | 24 gfx::Rect read_pixels_bounds = snapshot_bounds; |
| 25 | 25 |
| 26 // When not in compact mode we must take into account the window's position on | 26 // When not in compact mode we must take into account the window's position on |
| 27 // the desktop. | 27 // the desktop. |
| 28 read_pixels_bounds.set_origin( | 28 read_pixels_bounds.set_origin( |
| 29 snapshot_bounds.origin().Add(window->bounds().origin())); | 29 snapshot_bounds.origin().Add(window->bounds().DistanceFromOrigin())); |
| 30 gfx::Rect read_pixels_bounds_in_pixel = | 30 gfx::Rect read_pixels_bounds_in_pixel = |
| 31 ui::ConvertRectToPixel(window->layer(), read_pixels_bounds); | 31 ui::ConvertRectToPixel(window->layer(), read_pixels_bounds); |
| 32 | 32 |
| 33 DCHECK_GE(compositor->size().width(), read_pixels_bounds_in_pixel.right()); | 33 DCHECK_GE(compositor->size().width(), read_pixels_bounds_in_pixel.right()); |
| 34 DCHECK_GE(compositor->size().height(), read_pixels_bounds_in_pixel.bottom()); | 34 DCHECK_GE(compositor->size().height(), read_pixels_bounds_in_pixel.bottom()); |
| 35 DCHECK_LE(0, read_pixels_bounds.x()); | 35 DCHECK_LE(0, read_pixels_bounds.x()); |
| 36 DCHECK_LE(0, read_pixels_bounds.y()); | 36 DCHECK_LE(0, read_pixels_bounds.y()); |
| 37 | 37 |
| 38 SkBitmap bitmap; | 38 SkBitmap bitmap; |
| 39 if (!compositor->ReadPixels(&bitmap, read_pixels_bounds_in_pixel)) | 39 if (!compositor->ReadPixels(&bitmap, read_pixels_bounds_in_pixel)) |
| 40 return false; | 40 return false; |
| 41 | 41 |
| 42 unsigned char* pixels = reinterpret_cast<unsigned char*>(bitmap.getPixels()); | 42 unsigned char* pixels = reinterpret_cast<unsigned char*>(bitmap.getPixels()); |
| 43 | 43 |
| 44 gfx::PNGCodec::Encode(pixels, gfx::PNGCodec::FORMAT_BGRA, | 44 gfx::PNGCodec::Encode(pixels, gfx::PNGCodec::FORMAT_BGRA, |
| 45 read_pixels_bounds_in_pixel.size(), | 45 read_pixels_bounds_in_pixel.size(), |
| 46 bitmap.rowBytes(), true, | 46 bitmap.rowBytes(), true, |
| 47 std::vector<gfx::PNGCodec::Comment>(), | 47 std::vector<gfx::PNGCodec::Comment>(), |
| 48 png_representation); | 48 png_representation); |
| 49 return true; | 49 return true; |
| 50 } | 50 } |
| 51 | 51 |
| 52 } // namespace internal | 52 } // namespace internal |
| 53 } // namespace chrome | 53 } // namespace chrome |
| OLD | NEW |