Chromium Code Reviews| 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 "base/win/scoped_select_object.h" | 9 #include "base/win/scoped_select_object.h" |
| 10 #include "ui/gfx/codec/png_codec.h" | 10 #include "ui/gfx/codec/png_codec.h" |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 36 // Create a memory DC that's compatible with the window. | 36 // Create a memory DC that's compatible with the window. |
| 37 HDC window_hdc = GetWindowDC(window_handle); | 37 HDC window_hdc = GetWindowDC(window_handle); |
| 38 base::win::ScopedCreateDC mem_hdc(CreateCompatibleDC(window_hdc)); | 38 base::win::ScopedCreateDC mem_hdc(CreateCompatibleDC(window_hdc)); |
| 39 | 39 |
| 40 BITMAPINFOHEADER hdr; | 40 BITMAPINFOHEADER hdr; |
| 41 gfx::CreateBitmapHeader(snapshot_bounds.width(), | 41 gfx::CreateBitmapHeader(snapshot_bounds.width(), |
| 42 snapshot_bounds.height(), | 42 snapshot_bounds.height(), |
| 43 &hdr); | 43 &hdr); |
| 44 unsigned char *bit_ptr = NULL; | 44 unsigned char *bit_ptr = NULL; |
| 45 base::win::ScopedBitmap bitmap( | 45 base::win::ScopedBitmap bitmap( |
| 46 CreateDIBSection(mem_hdc, | 46 CreateDIBSection(mem_hdc.Get(), |
| 47 reinterpret_cast<BITMAPINFO*>(&hdr), | 47 reinterpret_cast<BITMAPINFO*>(&hdr), |
| 48 DIB_RGB_COLORS, | 48 DIB_RGB_COLORS, |
| 49 reinterpret_cast<void **>(&bit_ptr), | 49 reinterpret_cast<void **>(&bit_ptr), |
| 50 NULL, 0)); | 50 NULL, 0)); |
| 51 | 51 |
| 52 base::win::ScopedSelectObject select_bitmap(mem_hdc, bitmap); | 52 base::win::ScopedSelectObject select_bitmap(mem_hdc.Get(), bitmap); |
| 53 // Clear the bitmap to white (so that rounded corners on windows | 53 // Clear the bitmap to white (so that rounded corners on windows |
| 54 // show up on a white background, and strangely-shaped windows | 54 // show up on a white background, and strangely-shaped windows |
| 55 // look reasonable). Not capturing an alpha mask saves a | 55 // look reasonable). Not capturing an alpha mask saves a |
| 56 // bit of space. | 56 // bit of space. |
| 57 PatBlt(mem_hdc, 0, 0, snapshot_bounds.width(), snapshot_bounds.height(), | 57 PatBlt(mem_hdc.Get(), 0, 0, snapshot_bounds.width(), snapshot_bounds.height(), |
| 58 WHITENESS); | 58 WHITENESS); |
| 59 // Grab a copy of the window | |
| 60 // First, see if PrintWindow is defined (it's not in Windows 2000). | |
| 61 typedef BOOL (WINAPI *PrintWindowPointer)(HWND, HDC, UINT); | |
| 62 PrintWindowPointer print_window = | |
|
cpu_(ooo_6.6-7.5)
2012/02/08 00:03:20
Removing win2k hack.
| |
| 63 reinterpret_cast<PrintWindowPointer>( | |
| 64 GetProcAddress(GetModuleHandle(L"User32.dll"), "PrintWindow")); | |
| 65 | 59 |
| 66 // If PrintWindow is defined, use it. It will work on partially | 60 if (snapshot_bounds.origin() == gfx::Point()) { |
|
Peter Kasting
2012/02/08 00:38:49
Nit: If you reverse this conditional you can combi
cpu_(ooo_6.6-7.5)
2012/02/10 19:41:55
Done.
| |
| 67 // obscured windows, and works better for out of process sub-windows. | 61 if (!PrintWindow(window_handle, mem_hdc.Get(), 0)) { |
| 68 // Otherwise grab the bits we can get with BitBlt; it's better | 62 NOTREACHED(); |
| 69 // than nothing and will work fine in the average case (window is | 63 } |
| 70 // completely on screen). | 64 } else { |
| 71 if (snapshot_bounds.origin() == gfx::Point() && print_window) | 65 BitBlt(mem_hdc.Get(), |
| 72 (*print_window)(window_handle, mem_hdc, 0); | 66 0, 0, snapshot_bounds.width(), snapshot_bounds.height(), |
| 73 else | 67 window_hdc, |
| 74 BitBlt(mem_hdc, 0, 0, snapshot_bounds.width(), snapshot_bounds.height(), | 68 snapshot_bounds.x(), snapshot_bounds.y(), |
| 75 window_hdc, snapshot_bounds.x(), snapshot_bounds.y(), SRCCOPY); | 69 SRCCOPY); |
| 70 } | |
| 76 | 71 |
| 77 // We now have a copy of the window contents in a DIB, so | 72 // We now have a copy of the window contents in a DIB, so |
| 78 // encode it into a useful format for posting to the bug report | 73 // encode it into a useful format for posting to the bug report |
| 79 // server. | 74 // server. |
| 80 gfx::PNGCodec::Encode(bit_ptr, gfx::PNGCodec::FORMAT_BGRA, | 75 gfx::PNGCodec::Encode(bit_ptr, gfx::PNGCodec::FORMAT_BGRA, |
| 81 snapshot_bounds.size(), | 76 snapshot_bounds.size(), |
| 82 snapshot_bounds.width() * 4, true, | 77 snapshot_bounds.width() * 4, true, |
| 83 std::vector<gfx::PNGCodec::Comment>(), | 78 std::vector<gfx::PNGCodec::Comment>(), |
| 84 png_representation); | 79 png_representation); |
| 85 | 80 |
| 86 ReleaseDC(window_handle, window_hdc); | 81 ReleaseDC(window_handle, window_hdc); |
| 87 | 82 |
| 88 return true; | 83 return true; |
| 89 } | 84 } |
| 90 | 85 |
| 91 } // namespace browser | 86 } // namespace browser |
| OLD | NEW |