Chromium Code Reviews| 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..013cd50aa0e48846a302aece98266d4fcef41264 100644 |
| --- a/skia/ext/raster_handle_allocator_win.cc |
| +++ b/skia/ext/raster_handle_allocator_win.cc |
| @@ -21,9 +21,20 @@ namespace { |
| static void DeleteHDCCallback(void*, void* context) { |
| 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. |
| + HBITMAP hbitmap = static_cast<HBITMAP>(GetCurrentObject(hdc, OBJ_BITMAP)); |
| + DCHECK(hbitmap); |
|
f(malita)
2017/01/13 15:51:57
nit: DCHECK_NE(hbitmap, nullptr)
reed1
2017/01/13 15:58:08
Done.
|
| + |
| + int success = RestoreDC(hdc, -1); // effectly performs the deselect of hbitmap |
|
f(malita)
2017/01/13 15:51:57
nit: bool
reed1
2017/01/13 15:58:08
Done.
|
| + DCHECK(success); |
| + |
| + // Now we are the only owner, so we can delete our bitmap |
| + success = DeleteObject(hbitmap); |
| + DCHECK(hbitmap); |
|
f(malita)
2017/01/13 15:51:57
DCHECK_NE
reed1
2017/01/13 15:58:08
Done.
|
| + success = DeleteDC(hdc); |
| + DCHECK(hbitmap); |
|
f(malita)
2017/01/13 15:51:57
DCHECK_NE
reed1
2017/01/13 15:58:08
Done.
|
| } |
| // Allocate the layer and fill in the fields for the Rec, or return false |
| @@ -52,6 +63,11 @@ static bool Create(int width, |
| return false; |
| } |
| SetGraphicsMode(hdc, GM_ADVANCED); |
| + |
| + int saveIndex = SaveDC(hdc); // so we can Restore in the delete callback |
| + DCHECK(saveIndex != 0); |
|
f(malita)
2017/01/13 15:52:44
DCHECK_NE(saveIndex, 0)
reed1
2017/01/13 15:58:08
Done.
|
| + |
| + // Be sure to select *after* we called SaveDC. |
| SelectObject(hdc, hbitmap); |
| rec->fReleaseProc = DeleteHDCCallback; |