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 if (bitmap.tryAllocN32Pixels(width, height, is_opaque)) { | 13 if (bitmap.tryAllocN32Pixels(width, height, is_opaque)) { |
14 // Follow the logic in SkCanvas::createDevice(), initialize the bitmap if it | 14 // Follow the logic in SkCanvas::createDevice(), initialize the bitmap if it |
15 // is not opaque. | 15 // is not opaque. |
16 if (!is_opaque) | 16 if (!is_opaque) |
17 bitmap.eraseARGB(0, 0, 0, 0); | 17 bitmap.eraseARGB(0, 0, 0, 0); |
18 return new BitmapPlatformDevice(bitmap); | 18 return new BitmapPlatformDevice(bitmap); |
19 } | 19 } |
20 return NULL; | 20 return nullptr; |
21 } | 21 } |
22 | 22 |
23 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, | 23 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, |
24 bool is_opaque, | 24 bool is_opaque, |
25 uint8_t* data) { | 25 uint8_t* data) { |
26 SkBitmap bitmap; | 26 SkBitmap bitmap; |
27 bitmap.setInfo(SkImageInfo::MakeN32(width, height, | 27 bitmap.setInfo(SkImageInfo::MakeN32(width, height, |
28 is_opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType)); | 28 is_opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType)); |
29 if (data) | 29 if (data) |
30 bitmap.setPixels(data); | 30 bitmap.setPixels(data); |
31 else if (!bitmap.tryAllocPixels()) | 31 else if (!bitmap.tryAllocPixels()) |
32 return NULL; | 32 return nullptr; |
33 | 33 |
34 return new BitmapPlatformDevice(bitmap); | 34 return new BitmapPlatformDevice(bitmap); |
35 } | 35 } |
36 | 36 |
37 BitmapPlatformDevice::BitmapPlatformDevice(const SkBitmap& bitmap) | 37 BitmapPlatformDevice::BitmapPlatformDevice(const SkBitmap& bitmap) |
38 : SkBitmapDevice(bitmap) { | 38 : SkBitmapDevice(bitmap) { |
39 SetPlatformDevice(this, this); | 39 SetPlatformDevice(this, this); |
40 } | 40 } |
41 | 41 |
42 BitmapPlatformDevice::~BitmapPlatformDevice() { | 42 BitmapPlatformDevice::~BitmapPlatformDevice() { |
43 } | 43 } |
44 | 44 |
45 SkBaseDevice* BitmapPlatformDevice::onCreateDevice(const CreateInfo& info, | 45 SkBaseDevice* BitmapPlatformDevice::onCreateDevice(const CreateInfo& info, |
46 const SkPaint*) { | 46 const SkPaint*) { |
47 SkASSERT(info.fInfo.colorType() == kN32_SkColorType); | 47 SkASSERT(info.fInfo.colorType() == kN32_SkColorType); |
48 return BitmapPlatformDevice::Create(info.fInfo.width(), info.fInfo.height(), | 48 return BitmapPlatformDevice::Create(info.fInfo.width(), info.fInfo.height(), |
49 info.fInfo.isOpaque()); | 49 info.fInfo.isOpaque()); |
50 } | 50 } |
51 | 51 |
52 NativeDrawingContext BitmapPlatformDevice::BeginPlatformPaint( | 52 NativeDrawingContext BitmapPlatformDevice::BeginPlatformPaint( |
reed1
2017/01/05 16:40:33
Can we remove this method from the API entirely? I
| |
53 const SkMatrix& transform, | 53 const SkMatrix&, |
54 const SkIRect& clip_bounds) { | 54 const SkIRect&) { |
55 // TODO(zhenghao): What should we return? The ptr to the address of the | 55 NOTREACHED(); |
56 // pixels? Maybe this won't be called at all. | 56 return nullptr; |
57 SkPixmap pixmap; | |
58 return accessPixels(&pixmap) ? pixmap.writable_addr() : nullptr; | |
59 } | 57 } |
60 | 58 |
61 // PlatformCanvas impl | 59 // PlatformCanvas impl |
62 | 60 |
63 std::unique_ptr<SkCanvas> CreatePlatformCanvasWithPixels( | 61 std::unique_ptr<SkCanvas> CreatePlatformCanvasWithPixels( |
64 int width, | 62 int width, |
65 int height, | 63 int height, |
66 bool is_opaque, | 64 bool is_opaque, |
67 uint8_t* data, | 65 uint8_t* data, |
68 OnFailureType failureType) { | 66 OnFailureType failureType) { |
69 sk_sp<SkBaseDevice> dev( | 67 sk_sp<SkBaseDevice> dev( |
70 BitmapPlatformDevice::Create(width, height, is_opaque, data)); | 68 BitmapPlatformDevice::Create(width, height, is_opaque, data)); |
71 return CreateCanvas(dev, failureType); | 69 return CreateCanvas(dev, failureType); |
72 } | 70 } |
73 | 71 |
74 } // namespace skia | 72 } // namespace skia |
OLD | NEW |