| Index: skia/ext/raster_handle_allocator_win.cc
|
| diff --git a/skia/ext/raster_handle_allocator_win.cc b/skia/ext/raster_handle_allocator_win.cc
|
| index 93e1a252159d01b11b9bafc31041737b20676a0e..e78d622e48074d1de95c1abea70a5073dd11aa99 100644
|
| --- a/skia/ext/raster_handle_allocator_win.cc
|
| +++ b/skia/ext/raster_handle_allocator_win.cc
|
| @@ -20,10 +20,22 @@
|
| namespace {
|
|
|
| static void DeleteHDCCallback(void*, void* context) {
|
| + DCHECK_NE(context, nullptr);
|
| HDC hdc = static_cast<HDC>(context);
|
| - HBITMAP hbitmap = static_cast<HBITMAP>(SelectObject(hdc, nullptr));
|
| - DeleteObject(hbitmap);
|
| - DeleteDC(hdc);
|
| +
|
| + // We must get this before we call RestoreDC, as that will drop hbitmap and
|
| + // reselect the original/default bitmap.
|
| + HGDIOBJ hbitmap = GetCurrentObject(hdc, OBJ_BITMAP);
|
| + DCHECK_NE(hbitmap, nullptr);
|
| +
|
| + bool success = RestoreDC(hdc, -1); // effectly performs the deselect of hbitmap
|
| + DCHECK(success);
|
| +
|
| + // Now we are the only owner, so we can delete our bitmap
|
| + success = DeleteObject(hbitmap);
|
| + DCHECK(success);
|
| + success = DeleteDC(hdc);
|
| + DCHECK(success);
|
| }
|
|
|
| // Allocate the layer and fill in the fields for the Rec, or return false
|
| @@ -52,6 +64,13 @@ static bool Create(int width,
|
| return false;
|
| }
|
| SetGraphicsMode(hdc, GM_ADVANCED);
|
| +
|
| + int saveIndex = SaveDC(hdc); // so we can Restore in the delete callback
|
| + DCHECK_NE(saveIndex, 0);
|
| +
|
| + // Be sure to select *after* we called SaveDC.
|
| + // Because we're using save/restore, we don't need to explicitly track the
|
| + // returned "previous" value.
|
| SelectObject(hdc, hbitmap);
|
|
|
| rec->fReleaseProc = DeleteHDCCallback;
|
|
|