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 if (bitmap.allocN32Pixels(width, height, is_opaque)) { |
14 is_opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); | |
15 if (bitmap.allocPixels()) { | |
16 // Follow the logic in SkCanvas::createDevice(), initialize the bitmap if it | 14 // Follow the logic in SkCanvas::createDevice(), initialize the bitmap if it |
17 // is not opaque. | 15 // is not opaque. |
18 if (!is_opaque) | 16 if (!is_opaque) |
19 bitmap.eraseARGB(0, 0, 0, 0); | 17 bitmap.eraseARGB(0, 0, 0, 0); |
20 return new BitmapPlatformDevice(bitmap); | 18 return new BitmapPlatformDevice(bitmap); |
21 } | 19 } |
22 return NULL; | 20 return NULL; |
23 } | 21 } |
24 | 22 |
25 BitmapPlatformDevice* BitmapPlatformDevice::CreateAndClear(int width, | 23 BitmapPlatformDevice* BitmapPlatformDevice::CreateAndClear(int width, |
26 int height, | 24 int height, |
27 bool is_opaque) { | 25 bool is_opaque) { |
28 BitmapPlatformDevice* device = Create(width, height, is_opaque); | 26 BitmapPlatformDevice* device = Create(width, height, is_opaque); |
29 if (!is_opaque) | 27 if (!is_opaque) |
30 device->clear(0); | 28 device->clear(0); |
31 return device; | 29 return device; |
32 } | 30 } |
33 | 31 |
34 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, | 32 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, |
35 bool is_opaque, | 33 bool is_opaque, |
36 uint8_t* data) { | 34 uint8_t* data) { |
37 SkBitmap bitmap; | 35 SkBitmap bitmap; |
38 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height, 0, | 36 bitmap.setInfo(SkImageInfo::MakeN32(width, height, |
39 is_opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); | 37 is_opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType)); |
40 if (data) | 38 if (data) |
41 bitmap.setPixels(data); | 39 bitmap.setPixels(data); |
42 else if (!bitmap.allocPixels()) | 40 else if (!bitmap.allocPixels()) |
43 return NULL; | 41 return NULL; |
44 | 42 |
45 return new BitmapPlatformDevice(bitmap); | 43 return new BitmapPlatformDevice(bitmap); |
46 } | 44 } |
47 | 45 |
48 BitmapPlatformDevice::BitmapPlatformDevice(const SkBitmap& bitmap) | 46 BitmapPlatformDevice::BitmapPlatformDevice(const SkBitmap& bitmap) |
49 : SkBitmapDevice(bitmap) { | 47 : SkBitmapDevice(bitmap) { |
(...skipping 30 matching lines...) Expand all Loading... |
80 BitmapPlatformDevice::Create(width, height, is_opaque, data)); | 78 BitmapPlatformDevice::Create(width, height, is_opaque, data)); |
81 return CreateCanvas(dev, failureType); | 79 return CreateCanvas(dev, failureType); |
82 } | 80 } |
83 | 81 |
84 // Port of PlatformBitmap to android | 82 // Port of PlatformBitmap to android |
85 PlatformBitmap::~PlatformBitmap() { | 83 PlatformBitmap::~PlatformBitmap() { |
86 // Nothing to do. | 84 // Nothing to do. |
87 } | 85 } |
88 | 86 |
89 bool PlatformBitmap::Allocate(int width, int height, bool is_opaque) { | 87 bool PlatformBitmap::Allocate(int width, int height, bool is_opaque) { |
90 bitmap_.setConfig(SkBitmap::kARGB_8888_Config, width, height, 0, | 88 if (!bitmap_.allocN32Pixels(width, height, is_opaque)) |
91 is_opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); | |
92 if (!bitmap_.allocPixels()) | |
93 return false; | 89 return false; |
94 | 90 |
95 surface_ = bitmap_.getPixels(); | 91 surface_ = bitmap_.getPixels(); |
96 return true; | 92 return true; |
97 } | 93 } |
98 | 94 |
99 } // namespace skia | 95 } // namespace skia |
OLD | NEW |