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

Side by Side Diff: chrome/renderer/print_web_view_helper_win.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/renderer/print_web_view_helper.h" 5 #include "chrome/renderer/print_web_view_helper.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/process_util.h" 10 #include "base/process_util.h"
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 // Therefore, expecting a metafile with page count 1. 272 // Therefore, expecting a metafile with page count 1.
273 DCHECK_EQ(1U, metafile->GetPageCount()); 273 DCHECK_EQ(1U, metafile->GetPageCount());
274 274
275 // Close the device context to retrieve the compiled metafile. 275 // Close the device context to retrieve the compiled metafile.
276 if (!metafile->FinishDocument()) 276 if (!metafile->FinishDocument())
277 NOTREACHED(); 277 NOTREACHED();
278 278
279 // Page used alpha blend, but printer doesn't support it. Rewrite the 279 // Page used alpha blend, but printer doesn't support it. Rewrite the
280 // metafile and flatten out the transparency. 280 // metafile and flatten out the transparency.
281 base::win::ScopedGetDC screen_dc(NULL); 281 base::win::ScopedGetDC screen_dc(NULL);
282 base::win::ScopedCreateDC bitmap_dc(CreateCompatibleDC(screen_dc)); 282 base::win::ScopedCreateDC bitmap_dc(CreateCompatibleDC(screen_dc.Get()));
283 if (!bitmap_dc) 283 if (!bitmap_dc.Get())
284 NOTREACHED() << "Bitmap DC creation failed"; 284 NOTREACHED() << "Bitmap DC creation failed";
285 SetGraphicsMode(bitmap_dc, GM_ADVANCED); 285 SetGraphicsMode(bitmap_dc.Get(), GM_ADVANCED);
286 void* bits = NULL; 286 void* bits = NULL;
287 BITMAPINFO hdr; 287 BITMAPINFO hdr;
288 gfx::CreateBitmapHeader(page_size.width(), page_size.height(), 288 gfx::CreateBitmapHeader(page_size.width(), page_size.height(),
289 &hdr.bmiHeader); 289 &hdr.bmiHeader);
290 base::win::ScopedBitmap hbitmap(CreateDIBSection( 290 base::win::ScopedBitmap hbitmap(CreateDIBSection(
291 bitmap_dc, &hdr, DIB_RGB_COLORS, &bits, NULL, 0)); 291 bitmap_dc.Get(), &hdr, DIB_RGB_COLORS, &bits, NULL, 0));
292 if (!hbitmap) 292 if (!hbitmap)
293 NOTREACHED() << "Raster bitmap creation for printing failed"; 293 NOTREACHED() << "Raster bitmap creation for printing failed";
294 294
295 base::win::ScopedSelectObject selectBitmap(bitmap_dc, hbitmap); 295 base::win::ScopedSelectObject selectBitmap(bitmap_dc.Get(), hbitmap);
296 RECT rect = { 0, 0, page_size.width(), page_size.height() }; 296 RECT rect = { 0, 0, page_size.width(), page_size.height() };
297 HBRUSH whiteBrush = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH)); 297 HBRUSH whiteBrush = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH));
298 FillRect(bitmap_dc, &rect, whiteBrush); 298 FillRect(bitmap_dc.Get(), &rect, whiteBrush);
299 299
300 Metafile* metafile2(new printing::NativeMetafile); 300 Metafile* metafile2(new printing::NativeMetafile);
301 metafile2->Init(); 301 metafile2->Init();
302 HDC hdc = metafile2->context(); 302 HDC hdc = metafile2->context();
303 DCHECK(hdc); 303 DCHECK(hdc);
304 skia::InitializeDC(hdc); 304 skia::InitializeDC(hdc);
305 305
306 RECT metafile_bounds = metafile->GetPageBounds(1).ToRECT(); 306 RECT metafile_bounds = metafile->GetPageBounds(1).ToRECT();
307 // Process the old metafile, placing all non-AlphaBlend calls into the 307 // Process the old metafile, placing all non-AlphaBlend calls into the
308 // new metafile, and copying the results of all the AlphaBlend calls 308 // new metafile, and copying the results of all the AlphaBlend calls
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 shared_buf.Unmap(); 342 shared_buf.Unmap();
343 return false; 343 return false;
344 } 344 }
345 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); 345 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle);
346 shared_buf.Unmap(); 346 shared_buf.Unmap();
347 347
348 Send(new PrintHostMsg_DuplicateSection(routing_id(), *shared_mem_handle, 348 Send(new PrintHostMsg_DuplicateSection(routing_id(), *shared_mem_handle,
349 shared_mem_handle)); 349 shared_mem_handle));
350 return true; 350 return true;
351 } 351 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698