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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 int height, | 200 int height, |
201 bool is_opaque) { | 201 bool is_opaque) { |
202 BitmapPlatformDevice* device = BitmapPlatformDevice::Create(width, height, | 202 BitmapPlatformDevice* device = BitmapPlatformDevice::Create(width, height, |
203 is_opaque); | 203 is_opaque); |
204 if (device && !is_opaque) | 204 if (device && !is_opaque) |
205 device->accessBitmap(true).eraseARGB(0, 0, 0, 0); | 205 device->accessBitmap(true).eraseARGB(0, 0, 0, 0); |
206 return device; | 206 return device; |
207 } | 207 } |
208 | 208 |
209 // The device will own the HBITMAP, which corresponds to also owning the pixel | 209 // The device will own the HBITMAP, which corresponds to also owning the pixel |
210 // data. Therefore, we do not transfer ownership to the SkDevice's bitmap. | 210 // data. Therefore, we do not transfer ownership to the SkBitmapDevice's bitmap. |
211 BitmapPlatformDevice::BitmapPlatformDevice( | 211 BitmapPlatformDevice::BitmapPlatformDevice( |
212 const skia::RefPtr<BitmapPlatformDeviceData>& data, | 212 const skia::RefPtr<BitmapPlatformDeviceData>& data, |
213 const SkBitmap& bitmap) | 213 const SkBitmap& bitmap) |
214 : SkDevice(bitmap), | 214 : SkBitmapDevice(bitmap), |
215 data_(data) { | 215 data_(data) { |
216 // The data object is already ref'ed for us by create(). | 216 // The data object is already ref'ed for us by create(). |
217 SkDEBUGCODE(begin_paint_count_ = 0); | 217 SkDEBUGCODE(begin_paint_count_ = 0); |
218 SetPlatformDevice(this, this); | 218 SetPlatformDevice(this, this); |
219 } | 219 } |
220 | 220 |
221 BitmapPlatformDevice::~BitmapPlatformDevice() { | 221 BitmapPlatformDevice::~BitmapPlatformDevice() { |
222 SkASSERT(begin_paint_count_ == 0); | 222 SkASSERT(begin_paint_count_ == 0); |
223 } | 223 } |
224 | 224 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 } | 294 } |
295 | 295 |
296 const SkBitmap& BitmapPlatformDevice::onAccessBitmap(SkBitmap* bitmap) { | 296 const SkBitmap& BitmapPlatformDevice::onAccessBitmap(SkBitmap* bitmap) { |
297 // FIXME(brettw) OPTIMIZATION: We should only flush if we know a GDI | 297 // FIXME(brettw) OPTIMIZATION: We should only flush if we know a GDI |
298 // operation has occurred on our DC. | 298 // operation has occurred on our DC. |
299 if (data_->IsBitmapDCCreated()) | 299 if (data_->IsBitmapDCCreated()) |
300 GdiFlush(); | 300 GdiFlush(); |
301 return *bitmap; | 301 return *bitmap; |
302 } | 302 } |
303 | 303 |
304 SkDevice* BitmapPlatformDevice::onCreateCompatibleDevice( | 304 SkBaseDevice* BitmapPlatformDevice::onCreateCompatibleDevice( |
305 SkBitmap::Config config, int width, int height, bool isOpaque, Usage) { | 305 SkBitmap::Config config, int width, int height, bool isOpaque, Usage) { |
306 SkASSERT(config == SkBitmap::kARGB_8888_Config); | 306 SkASSERT(config == SkBitmap::kARGB_8888_Config); |
307 return BitmapPlatformDevice::CreateAndClear(width, height, isOpaque); | 307 return BitmapPlatformDevice::CreateAndClear(width, height, isOpaque); |
308 } | 308 } |
309 | 309 |
310 // PlatformCanvas impl | 310 // PlatformCanvas impl |
311 | 311 |
312 SkCanvas* CreatePlatformCanvas(int width, | 312 SkCanvas* CreatePlatformCanvas(int width, |
313 int height, | 313 int height, |
314 bool is_opaque, | 314 bool is_opaque, |
315 HANDLE shared_section, | 315 HANDLE shared_section, |
316 OnFailureType failureType) { | 316 OnFailureType failureType) { |
317 skia::RefPtr<SkDevice> dev = skia::AdoptRef( | 317 skia::RefPtr<SkBaseDevice> dev = skia::AdoptRef( |
318 BitmapPlatformDevice::Create(width, height, is_opaque, shared_section)); | 318 BitmapPlatformDevice::Create(width, height, is_opaque, shared_section)); |
319 return CreateCanvas(dev, failureType); | 319 return CreateCanvas(dev, failureType); |
320 } | 320 } |
321 | 321 |
322 // Port of PlatformBitmap to win | 322 // Port of PlatformBitmap to win |
323 | 323 |
324 PlatformBitmap::~PlatformBitmap() { | 324 PlatformBitmap::~PlatformBitmap() { |
325 if (surface_) { | 325 if (surface_) { |
326 if (platform_extra_) | 326 if (platform_extra_) |
327 SelectObject(surface_, reinterpret_cast<HGDIOBJ>(platform_extra_)); | 327 SelectObject(surface_, reinterpret_cast<HGDIOBJ>(platform_extra_)); |
(...skipping 19 matching lines...) Expand all Loading... |
347 // PlatformBitmapPixelRef takes ownership of |hbitmap|. | 347 // PlatformBitmapPixelRef takes ownership of |hbitmap|. |
348 bitmap_.setPixelRef( | 348 bitmap_.setPixelRef( |
349 skia::AdoptRef(new PlatformBitmapPixelRef(hbitmap, data)).get()); | 349 skia::AdoptRef(new PlatformBitmapPixelRef(hbitmap, data)).get()); |
350 bitmap_.setIsOpaque(is_opaque); | 350 bitmap_.setIsOpaque(is_opaque); |
351 bitmap_.lockPixels(); | 351 bitmap_.lockPixels(); |
352 | 352 |
353 return true; | 353 return true; |
354 } | 354 } |
355 | 355 |
356 } // namespace skia | 356 } // namespace skia |
OLD | NEW |