Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: chrome/browser/ui/window_snapshot/window_snapshot_win.cc

Issue 8139022: Rename ScopedHDC to ScopedCreateDC (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update a comment of ScopedCreateDC Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "ui/gfx/codec/png_codec.h" 10 #include "ui/gfx/codec/png_codec.h"
10 #include "ui/gfx/gdi_util.h" 11 #include "ui/gfx/gdi_util.h"
11 #include "ui/gfx/rect.h" 12 #include "ui/gfx/rect.h"
12 #include "ui/gfx/size.h" 13 #include "ui/gfx/size.h"
13 14
14 namespace browser { 15 namespace browser {
15 16
16 gfx::Rect GrabWindowSnapshot(gfx::NativeWindow window_handle, 17 gfx::Rect GrabWindowSnapshot(gfx::NativeWindow window_handle,
17 std::vector<unsigned char>* png_representation) { 18 std::vector<unsigned char>* png_representation) {
18 // Create a memory DC that's compatible with the window. 19 // Create a memory DC that's compatible with the window.
19 HDC window_hdc = GetWindowDC(window_handle); 20 HDC window_hdc = GetWindowDC(window_handle);
20 base::win::ScopedHDC mem_hdc(CreateCompatibleDC(window_hdc)); 21 base::win::ScopedCreateDC mem_hdc(CreateCompatibleDC(window_hdc));
21 22
22 // Create a DIB that's the same size as the window. 23 // Create a DIB that's the same size as the window.
23 RECT content_rect = {0, 0, 0, 0}; 24 RECT content_rect = {0, 0, 0, 0};
24 ::GetWindowRect(window_handle, &content_rect); 25 ::GetWindowRect(window_handle, &content_rect);
25 content_rect.right++; // Match what PrintWindow wants. 26 content_rect.right++; // Match what PrintWindow wants.
26 int width = content_rect.right - content_rect.left; 27 int width = content_rect.right - content_rect.left;
27 int height = content_rect.bottom - content_rect.top; 28 int height = content_rect.bottom - content_rect.top;
28 BITMAPINFOHEADER hdr; 29 BITMAPINFOHEADER hdr;
29 gfx::CreateBitmapHeader(width, height, &hdr); 30 gfx::CreateBitmapHeader(width, height, &hdr);
30 unsigned char *bit_ptr = NULL; 31 unsigned char *bit_ptr = NULL;
31 base::win::ScopedBitmap bitmap( 32 base::win::ScopedBitmap bitmap(
32 CreateDIBSection(mem_hdc, 33 CreateDIBSection(mem_hdc,
33 reinterpret_cast<BITMAPINFO*>(&hdr), 34 reinterpret_cast<BITMAPINFO*>(&hdr),
34 DIB_RGB_COLORS, 35 DIB_RGB_COLORS,
35 reinterpret_cast<void **>(&bit_ptr), 36 reinterpret_cast<void **>(&bit_ptr),
36 NULL, 0)); 37 NULL, 0));
37 38
38 SelectObject(mem_hdc, bitmap); 39 base::win::ScopedSelectObject select_bitmap(mem_hdc, bitmap);
39 // Clear the bitmap to white (so that rounded corners on windows 40 // Clear the bitmap to white (so that rounded corners on windows
40 // show up on a white background, and strangely-shaped windows 41 // show up on a white background, and strangely-shaped windows
41 // look reasonable). Not capturing an alpha mask saves a 42 // look reasonable). Not capturing an alpha mask saves a
42 // bit of space. 43 // bit of space.
43 PatBlt(mem_hdc, 0, 0, width, height, WHITENESS); 44 PatBlt(mem_hdc, 0, 0, width, height, WHITENESS);
44 // Grab a copy of the window 45 // Grab a copy of the window
45 // First, see if PrintWindow is defined (it's not in Windows 2000). 46 // First, see if PrintWindow is defined (it's not in Windows 2000).
46 typedef BOOL (WINAPI *PrintWindowPointer)(HWND, HDC, UINT); 47 typedef BOOL (WINAPI *PrintWindowPointer)(HWND, HDC, UINT);
47 PrintWindowPointer print_window = 48 PrintWindowPointer print_window =
48 reinterpret_cast<PrintWindowPointer>( 49 reinterpret_cast<PrintWindowPointer>(
(...skipping 16 matching lines...) Expand all
65 gfx::Size(width, height), width * 4, true, 66 gfx::Size(width, height), width * 4, true,
66 std::vector<gfx::PNGCodec::Comment>(), 67 std::vector<gfx::PNGCodec::Comment>(),
67 png_representation); 68 png_representation);
68 69
69 ReleaseDC(window_handle, window_hdc); 70 ReleaseDC(window_handle, window_hdc);
70 71
71 return gfx::Rect(width, height); 72 return gfx::Rect(width, height);
72 } 73 }
73 74
74 } // namespace browser 75 } // namespace browser
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698