From 47d1474d116ffe95eb6d54bdce6b1c5f3e8fecc8 Mon Sep 17 00:00:00 2001 From: "vitalybuka@chromium.org" Date: Sat, 26 Jan 2013 04:09:10 +0000 Subject: Fixed code disabled by invalide DCHECK use. Other minor cleanup. BUG=172198 Review URL: https://chromiumcodereview.appspot.com/12038105 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@179020 0039d316-1c4b-4281-b951-d872f2087c98 --- printing/image_win.cc | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'printing/image_win.cc') diff --git a/printing/image_win.cc b/printing/image_win.cc index de731e0..fdf99c8 100644 --- a/printing/image_win.cc +++ b/printing/image_win.cc @@ -4,11 +4,15 @@ #include "printing/image.h" +#include "base/win/scoped_gdi_object.h" +#include "base/win/scoped_hdc.h" +#include "base/win/scoped_select_object.h" #include "printing/metafile.h" #include "skia/ext/platform_device.h" #include "ui/gfx/gdi_util.h" // EMF support #include "ui/gfx/rect.h" + namespace { // A simple class which temporarily overrides system settings. @@ -50,7 +54,7 @@ bool Image::LoadMetafile(const Metafile& metafile) { DisableFontSmoothing disable_in_this_scope; // Create a temporary HDC and bitmap to retrieve the rendered data. - HDC hdc = CreateCompatibleDC(NULL); + base::win::ScopedCreateDC hdc(::CreateCompatibleDC(NULL)); BITMAPV4HEADER hdr; DCHECK_EQ(rect.x(), 0); DCHECK_EQ(rect.y(), 0); @@ -62,12 +66,12 @@ bool Image::LoadMetafile(const Metafile& metafile) { size_ = rect.size(); gfx::CreateBitmapV4Header(rect.width(), rect.height(), &hdr); - void* bits; - HBITMAP bitmap = CreateDIBSection(hdc, - reinterpret_cast(&hdr), 0, - &bits, NULL, 0); + unsigned char* bits = NULL; + base::win::ScopedBitmap bitmap( + ::CreateDIBSection(hdc, reinterpret_cast(&hdr), 0, + reinterpret_cast(&bits), NULL, 0)); DCHECK(bitmap); - DCHECK(SelectObject(hdc, bitmap)); + base::win::ScopedSelectObject select_object(hdc, bitmap); skia::InitializeDC(hdc); @@ -77,11 +81,7 @@ bool Image::LoadMetafile(const Metafile& metafile) { size_t bytes = row_length_ * size_.height(); DCHECK(bytes); - data_.resize(bytes); - memcpy(&*data_.begin(), bits, bytes); - - DeleteDC(hdc); - DeleteObject(bitmap); + data_.assign(bits, bits + bytes); return success; } -- cgit v1.1