OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/platform_canvas.h" | 5 #include "skia/ext/platform_canvas.h" |
6 | 6 |
7 #include "skia/ext/bitmap_platform_device_mac.h" | 7 #include "skia/ext/bitmap_platform_device_mac.h" |
8 #include "third_party/skia/include/core/SkTypes.h" | 8 #include "third_party/skia/include/core/SkTypes.h" |
9 | 9 |
10 namespace skia { | 10 namespace skia { |
11 | 11 |
12 PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque) | 12 PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque) |
13 : SkCanvas(SkNEW(BitmapPlatformDeviceFactory)) { | 13 : SkCanvas(SkNEW(BitmapPlatformDeviceFactory)) { |
14 initialize(width, height, is_opaque); | 14 initialize(width, height, is_opaque); |
15 } | 15 } |
16 | 16 |
17 PlatformCanvas::PlatformCanvas(int width, | 17 PlatformCanvas::PlatformCanvas(int width, |
18 int height, | 18 int height, |
19 bool is_opaque, | 19 bool is_opaque, |
20 CGContextRef context) | 20 CGContextRef context) |
21 : SkCanvas(SkNEW(BitmapPlatformDeviceFactory)) { | 21 : SkCanvas(SkNEW(BitmapPlatformDeviceFactory)) { |
22 initialize(width, height, is_opaque); | 22 initialize(context, width, height, is_opaque); |
23 } | 23 } |
24 | 24 |
25 PlatformCanvas::PlatformCanvas(int width, | 25 PlatformCanvas::PlatformCanvas(int width, |
26 int height, | 26 int height, |
27 bool is_opaque, | 27 bool is_opaque, |
28 uint8_t* data) | 28 uint8_t* data) |
29 : SkCanvas(SkNEW(BitmapPlatformDeviceFactory)) { | 29 : SkCanvas(SkNEW(BitmapPlatformDeviceFactory)) { |
30 initialize(width, height, is_opaque, data); | 30 initialize(width, height, is_opaque, data); |
31 } | 31 } |
32 | 32 |
33 PlatformCanvas::~PlatformCanvas() { | 33 PlatformCanvas::~PlatformCanvas() { |
34 } | 34 } |
35 | 35 |
36 bool PlatformCanvas::initialize(int width, | 36 bool PlatformCanvas::initialize(int width, |
37 int height, | 37 int height, |
38 bool is_opaque, | 38 bool is_opaque, |
39 uint8_t* data) { | 39 uint8_t* data) { |
40 SkDevice* device = BitmapPlatformDevice::CreateWithData(data, width, height, | 40 return initializeWithDevice(BitmapPlatformDevice::CreateWithData( |
41 is_opaque); | 41 data, width, height, is_opaque)); |
42 if (!device) | 42 } |
43 return false; | |
44 | 43 |
45 setDevice(device); | 44 bool PlatformCanvas::initialize(CGContextRef context, |
46 device->unref(); // Was created with refcount 1, and setDevice also refs. | 45 int width, |
47 return true; | 46 int height, |
| 47 bool is_opaque) { |
| 48 return initializeWithDevice(BitmapPlatformDevice::Create( |
| 49 context, width, height, is_opaque)); |
48 } | 50 } |
49 | 51 |
50 CGContextRef PlatformCanvas::beginPlatformPaint() { | 52 CGContextRef PlatformCanvas::beginPlatformPaint() { |
51 return getTopPlatformDevice().GetBitmapContext(); | 53 return getTopPlatformDevice().GetBitmapContext(); |
52 } | 54 } |
53 | 55 |
54 void PlatformCanvas::endPlatformPaint() { | 56 void PlatformCanvas::endPlatformPaint() { |
55 // Flushing will be done in onAccessBitmap. | 57 // Flushing will be done in onAccessBitmap. |
56 } | 58 } |
57 | 59 |
58 } // namespace skia | 60 } // namespace skia |
OLD | NEW |