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 "chrome/browser/ui/window_snapshot/window_snapshot.h" | 5 #include "chrome/browser/ui/window_snapshot/window_snapshot.h" |
6 | 6 |
7 #include "base/win/scoped_gdi_object.h" | 7 #include "base/win/scoped_gdi_object.h" |
8 #include "base/win/scoped_hdc.h" | 8 #include "base/win/scoped_hdc.h" |
9 #include "ui/gfx/codec/png_codec.h" | 9 #include "ui/gfx/codec/png_codec.h" |
10 #include "ui/gfx/gdi_util.h" | 10 #include "ui/gfx/gdi_util.h" |
11 #include "ui/gfx/rect.h" | 11 #include "ui/gfx/rect.h" |
| 12 #include "ui/gfx/size.h" |
12 | 13 |
13 namespace browser { | 14 namespace browser { |
14 | 15 |
15 gfx::Rect GrabWindowSnapshot(gfx::NativeWindow window_handle, | 16 gfx::Rect GrabWindowSnapshot(gfx::NativeWindow window_handle, |
16 std::vector<unsigned char>* png_representation) { | 17 std::vector<unsigned char>* png_representation) { |
17 // Create a memory DC that's compatible with the window. | 18 // Create a memory DC that's compatible with the window. |
18 HDC window_hdc = GetWindowDC(window_handle); | 19 HDC window_hdc = GetWindowDC(window_handle); |
19 base::win::ScopedHDC mem_hdc(CreateCompatibleDC(window_hdc)); | 20 base::win::ScopedHDC mem_hdc(CreateCompatibleDC(window_hdc)); |
20 | 21 |
21 // Create a DIB that's the same size as the window. | 22 // Create a DIB that's the same size as the window. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 // completely on screen). | 55 // completely on screen). |
55 if (print_window) | 56 if (print_window) |
56 (*print_window)(window_handle, mem_hdc, 0); | 57 (*print_window)(window_handle, mem_hdc, 0); |
57 else | 58 else |
58 BitBlt(mem_hdc, 0, 0, width, height, window_hdc, 0, 0, SRCCOPY); | 59 BitBlt(mem_hdc, 0, 0, width, height, window_hdc, 0, 0, SRCCOPY); |
59 | 60 |
60 // We now have a copy of the window contents in a DIB, so | 61 // We now have a copy of the window contents in a DIB, so |
61 // encode it into a useful format for posting to the bug report | 62 // encode it into a useful format for posting to the bug report |
62 // server. | 63 // server. |
63 gfx::PNGCodec::Encode(bit_ptr, gfx::PNGCodec::FORMAT_BGRA, | 64 gfx::PNGCodec::Encode(bit_ptr, gfx::PNGCodec::FORMAT_BGRA, |
64 width, height, width * 4, true, | 65 gfx::Size(width, height), width * 4, true, |
| 66 std::vector<gfx::PNGCodec::Comment>(), |
65 png_representation); | 67 png_representation); |
66 | 68 |
67 ReleaseDC(window_handle, window_hdc); | 69 ReleaseDC(window_handle, window_hdc); |
68 | 70 |
69 return gfx::Rect(width, height); | 71 return gfx::Rect(width, height); |
70 } | 72 } |
71 | 73 |
72 } // namespace browser | 74 } // namespace browser |
OLD | NEW |