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_mac.h" | 5 #include "skia/ext/platform_canvas_mac.h" |
6 | 6 |
7 #include "skia/ext/bitmap_platform_device_mac.h" | 7 #include "skia/ext/bitmap_platform_device_mac.h" |
8 #include "SkTypes.h" | 8 #include "SkTypes.h" |
9 | 9 |
10 namespace skia { | 10 namespace skia { |
11 | 11 |
12 PlatformCanvasMac::PlatformCanvasMac() : SkCanvas() { | 12 PlatformCanvasMac::PlatformCanvasMac() : SkCanvas() { |
13 } | 13 } |
14 | 14 |
15 PlatformCanvasMac::PlatformCanvasMac(int width, int height, bool is_opaque) | 15 PlatformCanvasMac::PlatformCanvasMac(int width, int height, bool is_opaque) |
16 : SkCanvas() { | 16 : SkCanvas() { |
17 initialize(width, height, is_opaque); | 17 initialize(width, height, is_opaque); |
18 } | 18 } |
19 | 19 |
20 PlatformCanvasMac::PlatformCanvasMac(int width, | 20 PlatformCanvasMac::PlatformCanvasMac(int width, |
21 int height, | 21 int height, |
22 bool is_opaque, | 22 bool is_opaque, |
23 CGContextRef context) | 23 CGContextRef context) |
24 : SkCanvas() { | 24 : SkCanvas() { |
25 initialize(width, height, is_opaque); | 25 initialize(width, height, is_opaque); |
26 } | 26 } |
27 | 27 |
| 28 PlatformCanvasMac::PlatformCanvasMac(int width, |
| 29 int height, |
| 30 bool is_opaque, |
| 31 uint8_t* data) |
| 32 : SkCanvas() { |
| 33 initialize(width, height, is_opaque, data); |
| 34 } |
| 35 |
28 PlatformCanvasMac::~PlatformCanvasMac() { | 36 PlatformCanvasMac::~PlatformCanvasMac() { |
29 } | 37 } |
30 | 38 |
31 bool PlatformCanvasMac::initialize(int width, | 39 bool PlatformCanvasMac::initialize(int width, |
32 int height, | 40 int height, |
33 bool is_opaque) { | 41 bool is_opaque) { |
34 SkDevice* device = createPlatformDevice(width, height, is_opaque, NULL); | 42 SkDevice* device = createPlatformDevice(width, height, is_opaque, NULL); |
35 if (!device) | 43 if (!device) |
36 return false; | 44 return false; |
37 | 45 |
38 setDevice(device); | 46 setDevice(device); |
39 device->unref(); // was created with refcount 1, and setDevice also refs | 47 device->unref(); // was created with refcount 1, and setDevice also refs |
40 return true; | 48 return true; |
41 } | 49 } |
42 | 50 |
| 51 bool PlatformCanvasMac::initialize(int width, |
| 52 int height, |
| 53 bool is_opaque, |
| 54 uint8_t* data) { |
| 55 CGContextRef context = NULL; |
| 56 CGColorSpaceRef colorSpace; |
| 57 |
| 58 colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); |
| 59 context = CGBitmapContextCreate( |
| 60 data, width, height, 8 /* bits per plane */, 4 * width /* stride */, |
| 61 colorSpace, kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host); |
| 62 CGColorSpaceRelease(colorSpace); |
| 63 if (!context) |
| 64 return false; |
| 65 // Change the coordinate system to match WebCore's |
| 66 CGContextTranslateCTM(context, 0, height); |
| 67 CGContextScaleCTM(context, 1.0, -1.0); |
| 68 |
| 69 SkDevice* device = createPlatformDevice(width, height, is_opaque, context); |
| 70 if (!device) |
| 71 return false; |
| 72 |
| 73 setDevice(device); |
| 74 device->unref(); // was created with refcount 1, and setDevice also refs |
| 75 return true; |
| 76 } |
| 77 |
43 CGContextRef PlatformCanvasMac::beginPlatformPaint() { | 78 CGContextRef PlatformCanvasMac::beginPlatformPaint() { |
44 return getTopPlatformDevice().GetBitmapContext(); | 79 return getTopPlatformDevice().GetBitmapContext(); |
45 } | 80 } |
46 | 81 |
47 void PlatformCanvasMac::endPlatformPaint() { | 82 void PlatformCanvasMac::endPlatformPaint() { |
48 // flushing will be done in onAccessBitmap | 83 // flushing will be done in onAccessBitmap |
49 } | 84 } |
50 | 85 |
51 PlatformDeviceMac& PlatformCanvasMac::getTopPlatformDevice() const { | 86 PlatformDeviceMac& PlatformCanvasMac::getTopPlatformDevice() const { |
52 // All of our devices should be our special PlatformDeviceMac. | 87 // All of our devices should be our special PlatformDeviceMac. |
(...skipping 22 matching lines...) Expand all Loading... |
75 SkASSERT(false); | 110 SkASSERT(false); |
76 return NULL; | 111 return NULL; |
77 } | 112 } |
78 | 113 |
79 // static | 114 // static |
80 size_t PlatformCanvasMac::StrideForWidth(unsigned width) { | 115 size_t PlatformCanvasMac::StrideForWidth(unsigned width) { |
81 return 4 * width; | 116 return 4 * width; |
82 } | 117 } |
83 | 118 |
84 } // namespace skia | 119 } // namespace skia |
OLD | NEW |