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

Side by Side Diff: ui/snapshot/snapshot_win.cc

Issue 606453002: Remove implicit HANDLE conversions from ui. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
« no previous file with comments | « ui/native_theme/native_theme_win.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ui/snapshot/snapshot_win.h" 5 #include "ui/snapshot/snapshot_win.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/win/scoped_gdi_object.h" 8 #include "base/win/scoped_gdi_object.h"
9 #include "base/win/scoped_hdc.h" 9 #include "base/win/scoped_hdc.h"
10 #include "base/win/scoped_select_object.h" 10 #include "base/win/scoped_select_object.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 // Create a memory DC that's compatible with the window. 49 // Create a memory DC that's compatible with the window.
50 HDC window_hdc = GetWindowDC(window_handle); 50 HDC window_hdc = GetWindowDC(window_handle);
51 base::win::ScopedCreateDC mem_hdc(CreateCompatibleDC(window_hdc)); 51 base::win::ScopedCreateDC mem_hdc(CreateCompatibleDC(window_hdc));
52 52
53 BITMAPINFOHEADER hdr; 53 BITMAPINFOHEADER hdr;
54 gfx::CreateBitmapHeader(snapshot_bounds.width(), 54 gfx::CreateBitmapHeader(snapshot_bounds.width(),
55 snapshot_bounds.height(), 55 snapshot_bounds.height(),
56 &hdr); 56 &hdr);
57 unsigned char *bit_ptr = NULL; 57 unsigned char *bit_ptr = NULL;
58 base::win::ScopedBitmap bitmap( 58 base::win::ScopedBitmap bitmap(
59 CreateDIBSection(mem_hdc, 59 CreateDIBSection(mem_hdc.Get(),
60 reinterpret_cast<BITMAPINFO*>(&hdr), 60 reinterpret_cast<BITMAPINFO*>(&hdr),
61 DIB_RGB_COLORS, 61 DIB_RGB_COLORS,
62 reinterpret_cast<void **>(&bit_ptr), 62 reinterpret_cast<void **>(&bit_ptr),
63 NULL, 0)); 63 NULL, 0));
64 64
65 base::win::ScopedSelectObject select_bitmap(mem_hdc, bitmap); 65 base::win::ScopedSelectObject select_bitmap(mem_hdc.Get(), bitmap);
66 // Clear the bitmap to white (so that rounded corners on windows 66 // Clear the bitmap to white (so that rounded corners on windows
67 // show up on a white background, and strangely-shaped windows 67 // show up on a white background, and strangely-shaped windows
68 // look reasonable). Not capturing an alpha mask saves a 68 // look reasonable). Not capturing an alpha mask saves a
69 // bit of space. 69 // bit of space.
70 PatBlt(mem_hdc, 0, 0, snapshot_bounds.width(), snapshot_bounds.height(), 70 PatBlt(mem_hdc.Get(), 0, 0, snapshot_bounds.width(), snapshot_bounds.height(),
71 WHITENESS); 71 WHITENESS);
72 // Grab a copy of the window 72 // Grab a copy of the window
73 // First, see if PrintWindow is defined (it's not in Windows 2000). 73 // First, see if PrintWindow is defined (it's not in Windows 2000).
74 typedef BOOL (WINAPI *PrintWindowPointer)(HWND, HDC, UINT); 74 typedef BOOL (WINAPI *PrintWindowPointer)(HWND, HDC, UINT);
75 PrintWindowPointer print_window = 75 PrintWindowPointer print_window =
76 reinterpret_cast<PrintWindowPointer>( 76 reinterpret_cast<PrintWindowPointer>(
77 GetProcAddress(GetModuleHandle(L"User32.dll"), "PrintWindow")); 77 GetProcAddress(GetModuleHandle(L"User32.dll"), "PrintWindow"));
78 78
79 // If PrintWindow is defined, use it. It will work on partially 79 // If PrintWindow is defined, use it. It will work on partially
80 // obscured windows, and works better for out of process sub-windows. 80 // obscured windows, and works better for out of process sub-windows.
81 // Otherwise grab the bits we can get with BitBlt; it's better 81 // Otherwise grab the bits we can get with BitBlt; it's better
82 // than nothing and will work fine in the average case (window is 82 // than nothing and will work fine in the average case (window is
83 // completely on screen). Always BitBlt when grabbing the whole screen. 83 // completely on screen). Always BitBlt when grabbing the whole screen.
84 if (snapshot_bounds.origin() == gfx::Point() && print_window && window_handle) 84 if (snapshot_bounds.origin() == gfx::Point() && print_window && window_handle)
85 (*print_window)(window_handle, mem_hdc, 0); 85 (*print_window)(window_handle, mem_hdc.Get(), 0);
86 else 86 else
87 BitBlt(mem_hdc, 0, 0, snapshot_bounds.width(), snapshot_bounds.height(), 87 BitBlt(mem_hdc.Get(), 0, 0, snapshot_bounds.width(),
88 window_hdc, snapshot_bounds.x(), snapshot_bounds.y(), SRCCOPY); 88 snapshot_bounds.height(), window_hdc, snapshot_bounds.x(),
89 snapshot_bounds.y(), SRCCOPY);
89 90
90 // We now have a copy of the window contents in a DIB, so 91 // We now have a copy of the window contents in a DIB, so
91 // encode it into a useful format for posting to the bug report 92 // encode it into a useful format for posting to the bug report
92 // server. 93 // server.
93 gfx::PNGCodec::Encode(bit_ptr, gfx::PNGCodec::FORMAT_BGRA, 94 gfx::PNGCodec::Encode(bit_ptr, gfx::PNGCodec::FORMAT_BGRA,
94 snapshot_bounds.size(), 95 snapshot_bounds.size(),
95 snapshot_bounds.width() * 4, true, 96 snapshot_bounds.width() * 4, true,
96 std::vector<gfx::PNGCodec::Comment>(), 97 std::vector<gfx::PNGCodec::Comment>(),
97 png_representation); 98 png_representation);
98 99
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 gfx::NativeWindow window, 142 gfx::NativeWindow window,
142 const gfx::Rect& source_rect, 143 const gfx::Rect& source_rect,
143 scoped_refptr<base::TaskRunner> background_task_runner, 144 scoped_refptr<base::TaskRunner> background_task_runner,
144 const GrabWindowSnapshotAsyncPNGCallback& callback) { 145 const GrabWindowSnapshotAsyncPNGCallback& callback) {
145 callback.Run(scoped_refptr<base::RefCountedBytes>()); 146 callback.Run(scoped_refptr<base::RefCountedBytes>());
146 } 147 }
147 148
148 #endif // !defined(USE_AURA) 149 #endif // !defined(USE_AURA)
149 150
150 } // namespace ui 151 } // namespace ui
OLDNEW
« no previous file with comments | « ui/native_theme/native_theme_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698