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 "base/debug/gdi_debug_util_win.h" | 8 #include "base/debug/gdi_debug_util_win.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "skia/ext/bitmap_platform_device_win.h" | 10 #include "skia/ext/bitmap_platform_device_win.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 } | 113 } |
114 | 114 |
115 // We use this static factory function instead of the regular constructor so | 115 // We use this static factory function instead of the regular constructor so |
116 // that we can create the pixel data before calling the constructor. This is | 116 // that we can create the pixel data before calling the constructor. This is |
117 // required so that we can call the base class' constructor with the pixel | 117 // required so that we can call the base class' constructor with the pixel |
118 // data. | 118 // data. |
119 BitmapPlatformDevice* BitmapPlatformDevice::Create( | 119 BitmapPlatformDevice* BitmapPlatformDevice::Create( |
120 int width, | 120 int width, |
121 int height, | 121 int height, |
122 bool is_opaque, | 122 bool is_opaque, |
123 HANDLE shared_section) { | 123 HANDLE shared_section, |
| 124 bool do_clear) { |
124 | 125 |
125 void* data; | 126 void* data; |
126 HBITMAP hbitmap = CreateHBitmap(width, height, is_opaque, shared_section, | 127 HBITMAP hbitmap = CreateHBitmap(width, height, is_opaque, shared_section, |
127 &data); | 128 &data); |
128 if (!hbitmap) | 129 if (!hbitmap) |
129 return NULL; | 130 return NULL; |
130 | 131 |
131 SkBitmap bitmap; | 132 SkBitmap bitmap; |
132 if (!InstallHBitmapPixels(&bitmap, width, height, is_opaque, data, hbitmap)) | 133 if (!InstallHBitmapPixels(&bitmap, width, height, is_opaque, data, hbitmap)) |
133 return NULL; | 134 return NULL; |
134 | 135 |
| 136 if (do_clear) |
| 137 bitmap.eraseColor(0); |
| 138 |
135 #ifndef NDEBUG | 139 #ifndef NDEBUG |
136 // If we were given data, then don't clobber it! | 140 // If we were given data, then don't clobber it! |
137 if (!shared_section && is_opaque) | 141 if (!shared_section && is_opaque) |
138 // To aid in finding bugs, we set the background color to something | 142 // To aid in finding bugs, we set the background color to something |
139 // obviously wrong so it will be noticable when it is not cleared | 143 // obviously wrong so it will be noticable when it is not cleared |
140 bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green | 144 bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green |
141 #endif | 145 #endif |
142 | 146 |
143 // The device object will take ownership of the HBITMAP. The initial refcount | 147 // The device object will take ownership of the HBITMAP. The initial refcount |
144 // of the data object will be 1, which is what the constructor expects. | 148 // of the data object will be 1, which is what the constructor expects. |
145 return new BitmapPlatformDevice(hbitmap, bitmap); | 149 return new BitmapPlatformDevice(hbitmap, bitmap); |
146 } | 150 } |
147 | 151 |
148 // static | 152 // static |
149 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, | 153 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, |
150 bool is_opaque) { | 154 bool is_opaque) { |
151 return Create(width, height, is_opaque, NULL); | 155 const HANDLE shared_section = NULL; |
152 } | 156 const bool do_clear = false; |
153 | 157 return Create(width, height, is_opaque, shared_section, do_clear); |
154 // static | |
155 BitmapPlatformDevice* BitmapPlatformDevice::CreateAndClear(int width, | |
156 int height, | |
157 bool is_opaque) { | |
158 BitmapPlatformDevice* device = BitmapPlatformDevice::Create(width, height, | |
159 is_opaque); | |
160 if (device && !is_opaque) | |
161 device->clear(0); | |
162 return device; | |
163 } | 158 } |
164 | 159 |
165 // The device will own the HBITMAP, which corresponds to also owning the pixel | 160 // The device will own the HBITMAP, which corresponds to also owning the pixel |
166 // data. Therefore, we do not transfer ownership to the SkBitmapDevice's bitmap. | 161 // data. Therefore, we do not transfer ownership to the SkBitmapDevice's bitmap. |
167 BitmapPlatformDevice::BitmapPlatformDevice( | 162 BitmapPlatformDevice::BitmapPlatformDevice( |
168 HBITMAP hbitmap, | 163 HBITMAP hbitmap, |
169 const SkBitmap& bitmap) | 164 const SkBitmap& bitmap) |
170 : SkBitmapDevice(bitmap), | 165 : SkBitmapDevice(bitmap), |
171 hbitmap_(hbitmap), | 166 hbitmap_(hbitmap), |
172 old_hbitmap_(NULL), | 167 old_hbitmap_(NULL), |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 | 259 |
265 const SkBitmap& BitmapPlatformDevice::onAccessBitmap() { | 260 const SkBitmap& BitmapPlatformDevice::onAccessBitmap() { |
266 // FIXME(brettw) OPTIMIZATION: We should only flush if we know a GDI | 261 // FIXME(brettw) OPTIMIZATION: We should only flush if we know a GDI |
267 // operation has occurred on our DC. | 262 // operation has occurred on our DC. |
268 if (IsBitmapDCCreated()) | 263 if (IsBitmapDCCreated()) |
269 GdiFlush(); | 264 GdiFlush(); |
270 return SkBitmapDevice::onAccessBitmap(); | 265 return SkBitmapDevice::onAccessBitmap(); |
271 } | 266 } |
272 | 267 |
273 SkBaseDevice* BitmapPlatformDevice::onCreateCompatibleDevice( | 268 SkBaseDevice* BitmapPlatformDevice::onCreateCompatibleDevice( |
274 const CreateInfo& info) { | 269 const CreateInfo& cinfo) { |
275 SkASSERT(info.fInfo.colorType() == kN32_SkColorType); | 270 const SkImageInfo& info = cinfo.fInfo; |
276 return BitmapPlatformDevice::CreateAndClear(info.fInfo.width(), | 271 const bool do_clear = !info.isOpaque(); |
277 info.fInfo.height(), | 272 SkASSERT(info.colorType() == kN32_SkColorType); |
278 info.fInfo.isOpaque()); | 273 return Create(info.width(), info.height(), info.isOpaque(), NULL, do_clear); |
279 } | 274 } |
280 | 275 |
281 // PlatformCanvas impl | 276 // PlatformCanvas impl |
282 | 277 |
283 SkCanvas* CreatePlatformCanvas(int width, | 278 SkCanvas* CreatePlatformCanvas(int width, |
284 int height, | 279 int height, |
285 bool is_opaque, | 280 bool is_opaque, |
286 HANDLE shared_section, | 281 HANDLE shared_section, |
287 OnFailureType failureType) { | 282 OnFailureType failureType) { |
288 skia::RefPtr<SkBaseDevice> dev = skia::AdoptRef( | 283 skia::RefPtr<SkBaseDevice> dev = skia::AdoptRef( |
(...skipping 26 matching lines...) Expand all Loading... |
315 platform_extra_ = reinterpret_cast<intptr_t>(stock_bitmap); | 310 platform_extra_ = reinterpret_cast<intptr_t>(stock_bitmap); |
316 | 311 |
317 if (!InstallHBitmapPixels(&bitmap_, width, height, is_opaque, data, hbitmap)) | 312 if (!InstallHBitmapPixels(&bitmap_, width, height, is_opaque, data, hbitmap)) |
318 return false; | 313 return false; |
319 bitmap_.lockPixels(); | 314 bitmap_.lockPixels(); |
320 | 315 |
321 return true; | 316 return true; |
322 } | 317 } |
323 | 318 |
324 } // namespace skia | 319 } // namespace skia |
OLD | NEW |