OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "skia/ext/bitmap_platform_device_skia.h" | |
6 #include "skia/ext/platform_canvas.h" | |
7 | |
8 namespace skia { | |
9 | |
10 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, | |
11 bool is_opaque) { | |
12 SkBitmap bitmap; | |
13 if (bitmap.tryAllocN32Pixels(width, height, is_opaque)) { | |
14 // Follow the logic in SkCanvas::createDevice(), initialize the bitmap if it | |
15 // is not opaque. | |
16 if (!is_opaque) | |
17 bitmap.eraseARGB(0, 0, 0, 0); | |
18 return new BitmapPlatformDevice(bitmap); | |
19 } | |
20 return NULL; | |
21 } | |
22 | |
23 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height, | |
24 bool is_opaque, | |
25 uint8_t* data) { | |
26 SkBitmap bitmap; | |
27 bitmap.setInfo(SkImageInfo::MakeN32(width, height, | |
28 is_opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType)); | |
29 if (data) | |
30 bitmap.setPixels(data); | |
31 else if (!bitmap.tryAllocPixels()) | |
32 return NULL; | |
33 | |
34 return new BitmapPlatformDevice(bitmap); | |
35 } | |
36 | |
37 BitmapPlatformDevice::BitmapPlatformDevice(const SkBitmap& bitmap) | |
38 : SkBitmapDevice(bitmap) { | |
39 SetPlatformDevice(this, this); | |
40 } | |
41 | |
42 BitmapPlatformDevice::~BitmapPlatformDevice() { | |
43 } | |
44 | |
45 SkBaseDevice* BitmapPlatformDevice::onCreateDevice(const CreateInfo& info, | |
46 const SkPaint*) { | |
47 SkASSERT(info.fInfo.colorType() == kN32_SkColorType); | |
48 return BitmapPlatformDevice::Create(info.fInfo.width(), info.fInfo.height(), | |
49 info.fInfo.isOpaque()); | |
50 } | |
51 | |
52 PlatformSurface BitmapPlatformDevice::BeginPlatformPaint() { | |
53 // TODO(zhenghao): What should we return? The ptr to the address of the | |
54 // pixels? Maybe this won't be called at all. | |
55 return accessBitmap(true).getPixels(); | |
56 } | |
57 | |
58 // PlatformCanvas impl | |
59 | |
60 SkCanvas* CreatePlatformCanvas(int width, int height, bool is_opaque, | |
61 uint8_t* data, OnFailureType failureType) { | |
62 skia::RefPtr<SkBaseDevice> dev = skia::AdoptRef( | |
63 BitmapPlatformDevice::Create(width, height, is_opaque, data)); | |
64 return CreateCanvas(dev, failureType); | |
65 } | |
66 | |
67 // Port of PlatformBitmap to android | |
68 PlatformBitmap::~PlatformBitmap() { | |
69 // Nothing to do. | |
70 } | |
71 | |
72 bool PlatformBitmap::Allocate(int width, int height, bool is_opaque) { | |
73 if (!bitmap_.tryAllocN32Pixels(width, height, is_opaque)) | |
74 return false; | |
75 | |
76 surface_ = bitmap_.getPixels(); | |
77 return true; | |
78 } | |
79 | |
80 } // namespace skia | |
OLD | NEW |