| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "skia/ext/bitmap_platform_device_skia.h" | 5 #include "skia/ext/bitmap_platform_device_skia.h" |
| 6 #include "skia/ext/platform_canvas.h" | 6 #include "skia/ext/platform_canvas.h" |
| 7 | 7 |
| 8 namespace skia { | 8 namespace skia { |
| 9 | 9 |
| 10 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, | 10 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, |
| 11 bool is_opaque) { | 11 bool is_opaque) { |
| 12 SkBitmap bitmap; | 12 SkBitmap bitmap; |
| 13 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height, 0, | 13 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height, 0, |
| 14 is_opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); | 14 is_opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); |
| 15 if (bitmap.allocPixels()) { | 15 if (bitmap.allocPixels()) { |
| 16 // Follow the logic in SkCanvas::createDevice(), initialize the bitmap if it | 16 // Follow the logic in SkCanvas::createDevice(), initialize the bitmap if it |
| 17 // is not opaque. | 17 // is not opaque. |
| 18 if (!is_opaque) | 18 if (!is_opaque) |
| 19 bitmap.eraseARGB(0, 0, 0, 0); | 19 bitmap.eraseARGB(0, 0, 0, 0); |
| 20 return new BitmapPlatformDevice(bitmap); | 20 return new BitmapPlatformDevice(bitmap); |
| 21 } | 21 } |
| 22 return NULL; | 22 return NULL; |
| 23 } | 23 } |
| 24 | 24 |
| 25 BitmapPlatformDevice* BitmapPlatformDevice::CreateAndClear(int width, | 25 BitmapPlatformDevice* BitmapPlatformDevice::CreateAndClear(int width, |
| 26 int height, | 26 int height, |
| 27 bool is_opaque) { | 27 bool is_opaque) { |
| 28 BitmapPlatformDevice* device = Create(width, height, is_opaque); | 28 BitmapPlatformDevice* device = Create(width, height, is_opaque); |
| 29 if (!is_opaque) | 29 if (!is_opaque) |
| 30 device->accessBitmap(true).eraseARGB(0, 0, 0, 0); | 30 device->clear(0); |
| 31 return device; | 31 return device; |
| 32 } | 32 } |
| 33 | 33 |
| 34 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, | 34 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, |
| 35 bool is_opaque, | 35 bool is_opaque, |
| 36 uint8_t* data) { | 36 uint8_t* data) { |
| 37 SkBitmap bitmap; | 37 SkBitmap bitmap; |
| 38 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height, 0, | 38 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height, 0, |
| 39 is_opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); | 39 is_opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); |
| 40 if (data) | 40 if (data) |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 bitmap_.setConfig(SkBitmap::kARGB_8888_Config, width, height, 0, | 90 bitmap_.setConfig(SkBitmap::kARGB_8888_Config, width, height, 0, |
| 91 is_opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); | 91 is_opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); |
| 92 if (!bitmap_.allocPixels()) | 92 if (!bitmap_.allocPixels()) |
| 93 return false; | 93 return false; |
| 94 | 94 |
| 95 surface_ = bitmap_.getPixels(); | 95 surface_ = bitmap_.getPixels(); |
| 96 return true; | 96 return true; |
| 97 } | 97 } |
| 98 | 98 |
| 99 } // namespace skia | 99 } // namespace skia |
| OLD | NEW |