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(const SkMatrix& transfo
rm, | |
53 const SkIRect& clip_bou
nds) { | |
54 // TODO(zhenghao): What should we return? The ptr to the address of the | |
55 // pixels? Maybe this won't be called at all. | |
56 SkPixmap pixmap; | |
57 return accessPixels(&pixmap) ? pixmap.writable_addr() : nullptr; | |
58 } | |
59 | |
60 // PlatformCanvas impl | |
61 | |
62 SkCanvas* CreatePlatformCanvas(int width, int height, bool is_opaque, | |
63 uint8_t* data, OnFailureType failureType) { | |
64 sk_sp<SkBaseDevice> dev( | |
65 BitmapPlatformDevice::Create(width, height, is_opaque, data)); | |
66 return CreateCanvas(dev, failureType); | |
67 } | |
68 | |
69 } // namespace skia | |
OLD | NEW |