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