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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
50 hdr.biBitCount = 32; | 50 hdr.biBitCount = 32; |
51 hdr.biCompression = BI_RGB; // no compression | 51 hdr.biCompression = BI_RGB; // no compression |
52 hdr.biSizeImage = 0; | 52 hdr.biSizeImage = 0; |
53 hdr.biXPelsPerMeter = 1; | 53 hdr.biXPelsPerMeter = 1; |
54 hdr.biYPelsPerMeter = 1; | 54 hdr.biYPelsPerMeter = 1; |
55 hdr.biClrUsed = 0; | 55 hdr.biClrUsed = 0; |
56 hdr.biClrImportant = 0; | 56 hdr.biClrImportant = 0; |
57 | 57 |
58 HBITMAP hbitmap = CreateDIBSection(NULL, reinterpret_cast<BITMAPINFO*>(&hdr), | 58 HBITMAP hbitmap = CreateDIBSection(NULL, reinterpret_cast<BITMAPINFO*>(&hdr), |
59 0, data, shared_section, 0); | 59 0, data, shared_section, 0); |
60 | |
61 if (!hbitmap) { | |
62 // Attempt to create a smaller DIBSection to debug whether | |
63 // the failure was due to memory exhaustion/fragmentation | |
64 // or GDI resource exhaution. | |
65 // See crbug.com/275046 | |
66 hdr.biWidth = 5; | |
67 hdr.biHeight = 5; | |
68 void* small_data; | |
69 HBITMAP small_bitmap = CreateDIBSection(NULL, reinterpret_cast<BITMAPINFO*>( &hdr), | |
70 0, &small_data, shared_section, 0); | |
71 SkASSERT(small_bitmap); | |
72 DeleteObject(small_bitmap); | |
73 BITMAP bitmap_data; | |
74 if (GetObject(small_bitmap, sizeof(BITMAP), &bitmap_data)) | |
75 SkASSERT(DeleteObject(small_bitmap)); | |
76 } | |
77 | |
60 return hbitmap; | 78 return hbitmap; |
61 } | 79 } |
62 | 80 |
63 PlatformBitmapPixelRef::PlatformBitmapPixelRef(HBITMAP bitmap_handle, | 81 PlatformBitmapPixelRef::PlatformBitmapPixelRef(HBITMAP bitmap_handle, |
64 void* pixels) | 82 void* pixels) |
65 : bitmap_handle_(bitmap_handle), | 83 : bitmap_handle_(bitmap_handle), |
66 pixels_(pixels) { | 84 pixels_(pixels) { |
67 setPreLocked(pixels, NULL); | 85 setPreLocked(pixels, NULL); |
68 } | 86 } |
69 | 87 |
70 PlatformBitmapPixelRef::~PlatformBitmapPixelRef() { | 88 PlatformBitmapPixelRef::~PlatformBitmapPixelRef() { |
71 if (bitmap_handle_) | 89 if (bitmap_handle_) |
72 DeleteObject(bitmap_handle_); | 90 SkASSERT(DeleteObject(bitmap_handle_)); |
reed1
2013/11/04 16:49:28
SkASSERT becomes a no-op in release builds, so I t
| |
73 } | 91 } |
74 | 92 |
75 void* PlatformBitmapPixelRef::onLockPixels(SkColorTable** color_table) { | 93 void* PlatformBitmapPixelRef::onLockPixels(SkColorTable** color_table) { |
76 *color_table = NULL; | 94 *color_table = NULL; |
77 return pixels_; | 95 return pixels_; |
78 } | 96 } |
79 | 97 |
80 void PlatformBitmapPixelRef::onUnlockPixels() { | 98 void PlatformBitmapPixelRef::onUnlockPixels() { |
81 // Nothing to do. | 99 // Nothing to do. |
82 return; | 100 return; |
(...skipping 16 matching lines...) Expand all Loading... | |
99 rect.set(0, 0, bitmap_data.bmWidth, bitmap_data.bmHeight); | 117 rect.set(0, 0, bitmap_data.bmWidth, bitmap_data.bmHeight); |
100 clip_region_ = SkRegion(rect); | 118 clip_region_ = SkRegion(rect); |
101 } | 119 } |
102 } | 120 } |
103 | 121 |
104 BitmapPlatformDevice::BitmapPlatformDeviceData::~BitmapPlatformDeviceData() { | 122 BitmapPlatformDevice::BitmapPlatformDeviceData::~BitmapPlatformDeviceData() { |
105 if (hdc_) | 123 if (hdc_) |
106 ReleaseBitmapDC(); | 124 ReleaseBitmapDC(); |
107 | 125 |
108 // this will free the bitmap data as well as the bitmap handle | 126 // this will free the bitmap data as well as the bitmap handle |
109 DeleteObject(bitmap_context_); | 127 SkASSERT(DeleteObject(bitmap_context_)); |
110 } | 128 } |
111 | 129 |
112 HDC BitmapPlatformDevice::BitmapPlatformDeviceData::GetBitmapDC() { | 130 HDC BitmapPlatformDevice::BitmapPlatformDeviceData::GetBitmapDC() { |
113 if (!hdc_) { | 131 if (!hdc_) { |
114 hdc_ = CreateCompatibleDC(NULL); | 132 hdc_ = CreateCompatibleDC(NULL); |
115 InitializeDC(hdc_); | 133 InitializeDC(hdc_); |
116 HGDIOBJ old_bitmap = SelectObject(hdc_, bitmap_context_); | 134 HGDIOBJ old_bitmap = SelectObject(hdc_, bitmap_context_); |
117 // When the memory DC is created, its display surface is exactly one | 135 // When the memory DC is created, its display surface is exactly one |
118 // monochrome pixel wide and one monochrome pixel high. Since we select our | 136 // monochrome pixel wide and one monochrome pixel high. Since we select our |
119 // own bitmap, we must delete the previous one. | 137 // own bitmap, we must delete the previous one. |
120 DeleteObject(old_bitmap); | 138 SkASSERT(DeleteObject(old_bitmap)); |
121 } | 139 } |
122 | 140 |
123 LoadConfig(); | 141 LoadConfig(); |
124 return hdc_; | 142 return hdc_; |
125 } | 143 } |
126 | 144 |
127 void BitmapPlatformDevice::BitmapPlatformDeviceData::ReleaseBitmapDC() { | 145 void BitmapPlatformDevice::BitmapPlatformDeviceData::ReleaseBitmapDC() { |
128 SkASSERT(hdc_); | 146 SkASSERT(hdc_); |
129 DeleteDC(hdc_); | 147 DeleteDC(hdc_); |
130 hdc_ = NULL; | 148 hdc_ = NULL; |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
347 is_opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); | 365 is_opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); |
348 // PlatformBitmapPixelRef takes ownership of |hbitmap|. | 366 // PlatformBitmapPixelRef takes ownership of |hbitmap|. |
349 bitmap_.setPixelRef( | 367 bitmap_.setPixelRef( |
350 skia::AdoptRef(new PlatformBitmapPixelRef(hbitmap, data)).get()); | 368 skia::AdoptRef(new PlatformBitmapPixelRef(hbitmap, data)).get()); |
351 bitmap_.lockPixels(); | 369 bitmap_.lockPixels(); |
352 | 370 |
353 return true; | 371 return true; |
354 } | 372 } |
355 | 373 |
356 } // namespace skia | 374 } // namespace skia |
OLD | NEW |