From 9152f58fc51f32beb473e1198c2b118b24747057 Mon Sep 17 00:00:00 2001 From: "senorblanco@chromium.org" Date: Wed, 4 Dec 2013 06:46:16 +0000 Subject: [PATCH] In order to respect Win32 semantics (and appease Dr.Memory), stash the initial GDI bitmap created with the DC in BitmapPlatformDevice(win), and select it back into the DC just before destruction. BUG=110783 Review URL: https://codereview.chromium.org/100393007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@238610 0039d316-1c4b-4281-b951-d872f2087c98 --- skia/ext/bitmap_platform_device_win.cc | 9 ++++----- skia/ext/bitmap_platform_device_win.h | 4 ++++ tools/valgrind/drmemory/suppressions.txt | 18 ------------------ 3 files changed, 8 insertions(+), 23 deletions(-) diff --git a/skia/ext/bitmap_platform_device_win.cc b/skia/ext/bitmap_platform_device_win.cc index 0dfc3244fa26..ed01a35d229c 100644 --- a/skia/ext/bitmap_platform_device_win.cc +++ b/skia/ext/bitmap_platform_device_win.cc @@ -147,11 +147,7 @@ HDC BitmapPlatformDevice::GetBitmapDC() { if (!hdc_) { hdc_ = CreateCompatibleDC(NULL); InitializeDC(hdc_); - HGDIOBJ old_bitmap = SelectObject(hdc_, hbitmap_); - // When the memory DC is created, its display surface is exactly one - // monochrome pixel wide and one monochrome pixel high. Since we select our - // own bitmap, we must delete the previous one. - DeleteObject(old_bitmap); + old_hbitmap_ = static_cast(SelectObject(hdc_, hbitmap_)); } LoadConfig(); @@ -160,8 +156,10 @@ HDC BitmapPlatformDevice::GetBitmapDC() { void BitmapPlatformDevice::ReleaseBitmapDC() { SkASSERT(hdc_); + SelectObject(hdc_, old_hbitmap_); DeleteDC(hdc_); hdc_ = NULL; + old_hbitmap_ = NULL; } bool BitmapPlatformDevice::IsBitmapDCCreated() @@ -248,6 +246,7 @@ BitmapPlatformDevice::BitmapPlatformDevice( const SkBitmap& bitmap) : SkBitmapDevice(bitmap), hbitmap_(hbitmap), + old_hbitmap_(NULL), hdc_(NULL), config_dirty_(true), // Want to load the config next time. transform_(SkMatrix::I()) { diff --git a/skia/ext/bitmap_platform_device_win.h b/skia/ext/bitmap_platform_device_win.h index d2c1603d28e5..5d8afdc7781e 100644 --- a/skia/ext/bitmap_platform_device_win.h +++ b/skia/ext/bitmap_platform_device_win.h @@ -81,6 +81,10 @@ class SK_API BitmapPlatformDevice : public SkBitmapDevice, public PlatformDevice // It's only stored here in order to lazy-create the DC (below). HBITMAP hbitmap_; + // Previous bitmap held by the DC. This will be selected back before the + // DC is destroyed. + HBITMAP old_hbitmap_; + // Lazily-created DC used to draw into the bitmap; see GetBitmapDC(). HDC hdc_; diff --git a/tools/valgrind/drmemory/suppressions.txt b/tools/valgrind/drmemory/suppressions.txt index 1463a3a5dbc6..467c94b64c0e 100644 --- a/tools/valgrind/drmemory/suppressions.txt +++ b/tools/valgrind/drmemory/suppressions.txt @@ -445,21 +445,3 @@ skia.dll!SkScalerContext::getImage skia.dll!SkGlyphCache::findImage skia.dll!D1G_NoBounder_RectClip skia.dll!SkDraw::drawText - -GDI USAGE ERROR -name=http://crbug.com/110783 -system call NtGdiDeleteObjectApp -GDI32.dll!DeleteDC -GDI32.dll!DeleteDC -skia.dll!skia::BitmapPlatformDevice::ReleaseBitmapDC -skia.dll!skia::BitmapPlatformDevice::~BitmapPlatformDevice -skia.dll!skia::BitmapPlatformDevice::`vector deleting destructor' -skia.dll!SkRefCntBase::internal_dispose -skia.dll!SkRefCntBase::unref -skia.dll!DeviceCM::~DeviceCM -skia.dll!DeviceCM::`scalar deleting destructor' -skia.dll!SkCanvas::internalRestore -skia.dll!SkCanvas::restore -*!skia::`anonymous namespace'::LayerSaver::~LayerSaver -*!skia::PlatformCanvas_FillLayer_Test::TestBody -*!testing::internal::HandleExceptionsInMethodIfSupported -- 2.11.4.GIT