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

Side by Side Diff: chrome/browser/aeropeek_manager.cc

Issue 9212020: Make scoped dc objects smarter. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 8 years, 10 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) 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/aeropeek_manager.h" 5 #include "chrome/browser/aeropeek_manager.h"
6 6
7 #include <dwmapi.h> 7 #include <dwmapi.h>
8 #include <shobjidl.h> 8 #include <shobjidl.h>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 204
205 thumbnail_bitmap = skia::ImageOperations::Resize( 205 thumbnail_bitmap = skia::ImageOperations::Resize(
206 tab_bitmap, skia::ImageOperations::RESIZE_LANCZOS3, 206 tab_bitmap, skia::ImageOperations::RESIZE_LANCZOS3,
207 thumbnail_size.width(), thumbnail_size.height()); 207 thumbnail_size.width(), thumbnail_size.height());
208 } 208 }
209 209
210 // Create a DIB, copy the resized image, and send the DIB to Windows. 210 // Create a DIB, copy the resized image, and send the DIB to Windows.
211 // We can delete this DIB after sending it to Windows since Windows creates 211 // We can delete this DIB after sending it to Windows since Windows creates
212 // a copy of the DIB and use it. 212 // a copy of the DIB and use it.
213 base::win::ScopedCreateDC hdc(CreateCompatibleDC(NULL)); 213 base::win::ScopedCreateDC hdc(CreateCompatibleDC(NULL));
214 if (!hdc.Get()) { 214 if (!hdc.get()) {
215 LOG(ERROR) << "cannot create a memory DC: " << GetLastError(); 215 LOG(ERROR) << "cannot create a memory DC: " << GetLastError();
216 return; 216 return;
217 } 217 }
218 218
219 BITMAPINFOHEADER header; 219 BITMAPINFOHEADER header;
220 gfx::CreateBitmapHeader(thumbnail_size.width(), thumbnail_size.height(), 220 gfx::CreateBitmapHeader(thumbnail_size.width(), thumbnail_size.height(),
221 &header); 221 &header);
222 222
223 void* bitmap_data = NULL; 223 void* bitmap_data = NULL;
224 base::win::ScopedBitmap bitmap( 224 base::win::ScopedBitmap bitmap(
225 CreateDIBSection(hdc, reinterpret_cast<BITMAPINFO*>(&header), 225 CreateDIBSection(hdc.get(), reinterpret_cast<BITMAPINFO*>(&header),
226 DIB_RGB_COLORS, &bitmap_data, NULL, 0)); 226 DIB_RGB_COLORS, &bitmap_data, NULL, 0));
227 227
228 if (!bitmap.Get() || !bitmap_data) { 228 if (!bitmap.Get() || !bitmap_data) {
229 LOG(ERROR) << "cannot create a bitmap: " << GetLastError(); 229 LOG(ERROR) << "cannot create a bitmap: " << GetLastError();
230 return; 230 return;
231 } 231 }
232 232
233 SkAutoLockPixels lock(thumbnail_bitmap); 233 SkAutoLockPixels lock(thumbnail_bitmap);
234 int* content_pixels = reinterpret_cast<int*>(bitmap_data); 234 int* content_pixels = reinterpret_cast<int*>(bitmap_data);
235 for (int y = 0; y < thumbnail_size.height(); ++y) { 235 for (int y = 0; y < thumbnail_size.height(); ++y) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 // This task is used if an AeroPeek window receives a 267 // This task is used if an AeroPeek window receives a
268 // WM_DWMSENDICONICLIVEPREVIEWBITMAP message. 268 // WM_DWMSENDICONICLIVEPREVIEWBITMAP message.
269 void SendLivePreviewCallback( 269 void SendLivePreviewCallback(
270 HWND aeropeek_window, const gfx::Rect& content_bounds, 270 HWND aeropeek_window, const gfx::Rect& content_bounds,
271 const SkBitmap& tab_bitmap) { 271 const SkBitmap& tab_bitmap) {
272 // Create a DIB for the user-perceived content area of the tab, copy the 272 // Create a DIB for the user-perceived content area of the tab, copy the
273 // tab image into the DIB, and send it to Windows. 273 // tab image into the DIB, and send it to Windows.
274 // We don't need to paste this tab image onto the frame image since Windows 274 // We don't need to paste this tab image onto the frame image since Windows
275 // automatically pastes it for us. 275 // automatically pastes it for us.
276 base::win::ScopedCreateDC hdc(CreateCompatibleDC(NULL)); 276 base::win::ScopedCreateDC hdc(CreateCompatibleDC(NULL));
277 if (!hdc.Get()) { 277 if (!hdc.get()) {
278 LOG(ERROR) << "cannot create a memory DC: " << GetLastError(); 278 LOG(ERROR) << "cannot create a memory DC: " << GetLastError();
279 return; 279 return;
280 } 280 }
281 281
282 BITMAPINFOHEADER header; 282 BITMAPINFOHEADER header;
283 gfx::CreateBitmapHeader(content_bounds.width(), content_bounds.height(), 283 gfx::CreateBitmapHeader(content_bounds.width(), content_bounds.height(),
284 &header); 284 &header);
285 285
286 void* bitmap_data = NULL; 286 void* bitmap_data = NULL;
287 base::win::ScopedBitmap bitmap( 287 base::win::ScopedBitmap bitmap(
288 CreateDIBSection(hdc.Get(), reinterpret_cast<BITMAPINFO*>(&header), 288 CreateDIBSection(hdc.get(), reinterpret_cast<BITMAPINFO*>(&header),
289 DIB_RGB_COLORS, &bitmap_data, NULL, 0)); 289 DIB_RGB_COLORS, &bitmap_data, NULL, 0));
290 if (!bitmap.Get() || !bitmap_data) { 290 if (!bitmap.Get() || !bitmap_data) {
291 LOG(ERROR) << "cannot create a bitmap: " << GetLastError(); 291 LOG(ERROR) << "cannot create a bitmap: " << GetLastError();
292 return; 292 return;
293 } 293 }
294 294
295 // Copy the tab image onto the DIB. 295 // Copy the tab image onto the DIB.
296 SkAutoLockPixels lock(tab_bitmap); 296 SkAutoLockPixels lock(tab_bitmap);
297 int* content_pixels = reinterpret_cast<int*>(bitmap_data); 297 int* content_pixels = reinterpret_cast<int*>(bitmap_data);
298 for (int y = 0; y < content_bounds.height(); ++y) { 298 for (int y = 0; y < content_bounds.height(); ++y) {
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 // This code is just copied from "thumbnail_generator.cc". 1004 // This code is just copied from "thumbnail_generator.cc".
1005 skia::PlatformCanvas canvas; 1005 skia::PlatformCanvas canvas;
1006 if (!backing_store->CopyFromBackingStore(gfx::Rect(backing_store->size()), 1006 if (!backing_store->CopyFromBackingStore(gfx::Rect(backing_store->size()),
1007 &canvas)) 1007 &canvas))
1008 return false; 1008 return false;
1009 1009
1010 const SkBitmap& bitmap = skia::GetTopDevice(canvas)->accessBitmap(false); 1010 const SkBitmap& bitmap = skia::GetTopDevice(canvas)->accessBitmap(false);
1011 bitmap.copyTo(preview, SkBitmap::kARGB_8888_Config); 1011 bitmap.copyTo(preview, SkBitmap::kARGB_8888_Config);
1012 return true; 1012 return true;
1013 } 1013 }
OLDNEW
« no previous file with comments | « base/win/scoped_hdc_unittest.cc ('k') | chrome/browser/ui/window_snapshot/window_snapshot_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698