OLD | NEW |
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 <windows.h> | 5 #include <windows.h> |
6 #include <psapi.h> | 6 #include <psapi.h> |
7 | 7 |
8 #include "skia/ext/bitmap_platform_device_win.h" | 8 #include "skia/ext/bitmap_platform_device_win.h" |
9 #include "skia/ext/bitmap_platform_device_data.h" | 9 #include "skia/ext/bitmap_platform_device_data.h" |
10 #include "skia/ext/platform_canvas.h" | 10 #include "skia/ext/platform_canvas.h" |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 SkDevice* bitmap_device = BitmapPlatformDevice::CreateAndClear(width, height, | 266 SkDevice* bitmap_device = BitmapPlatformDevice::CreateAndClear(width, height, |
267 isOpaque); | 267 isOpaque); |
268 return bitmap_device; | 268 return bitmap_device; |
269 } | 269 } |
270 | 270 |
271 // Port of PlatformBitmap to win | 271 // Port of PlatformBitmap to win |
272 | 272 |
273 PlatformBitmap::~PlatformBitmap() { | 273 PlatformBitmap::~PlatformBitmap() { |
274 if (surface_) | 274 if (surface_) |
275 DeleteDC(surface_); | 275 DeleteDC(surface_); |
| 276 |
| 277 HBITMAP hbitmap = (HBITMAP)platform_extra_; |
| 278 if (hbitmap) |
| 279 DeleteObject(hbitmap); |
276 } | 280 } |
277 | 281 |
278 bool PlatformBitmap::Allocate(int width, int height, bool is_opaque) { | 282 bool PlatformBitmap::Allocate(int width, int height, bool is_opaque) { |
279 HBITMAP hbitmap = CreateHBitmap(width, height, is_opaque, 0, &bitmap_); | 283 HBITMAP hbitmap = CreateHBitmap(width, height, is_opaque, 0, &bitmap_); |
280 if (!hbitmap) | 284 if (!hbitmap) |
281 return false; | 285 return false; |
282 | 286 |
283 surface_ = CreateCompatibleDC(NULL); | 287 surface_ = CreateCompatibleDC(NULL); |
284 InitializeDC(surface_); | 288 InitializeDC(surface_); |
285 HGDIOBJ old_bitmap = SelectObject(surface_, hbitmap); | 289 HGDIOBJ old_bitmap = SelectObject(surface_, hbitmap); |
286 // When the memory DC is created, its display surface is exactly one | 290 // When the memory DC is created, its display surface is exactly one |
287 // monochrome pixel wide and one monochrome pixel high. Since we select our | 291 // monochrome pixel wide and one monochrome pixel high. Since we select our |
288 // own bitmap, we must delete the previous one. | 292 // own bitmap, we must delete the previous one. |
289 DeleteObject(old_bitmap); | 293 DeleteObject(old_bitmap); |
| 294 // remember the hbitmap, so we can free it in our destructor |
| 295 platform_extra_ = (intptr_t)hbitmap; |
290 return true; | 296 return true; |
291 } | 297 } |
292 | 298 |
293 } // namespace skia | 299 } // namespace skia |
OLD | NEW |