Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(424)

Side by Side Diff: skia/ext/platform_canvas_mac.cc

Issue 125109: Refactor the PlatformContext layer to have only one class. (Closed)
Patch Set: Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « skia/ext/platform_canvas_mac.h ('k') | skia/ext/platform_canvas_win.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.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 PlatformCanvasMac::PlatformCanvasMac() : SkCanvas() { 12 PlatformCanvas::PlatformCanvas() : SkCanvas() {
13 } 13 }
14 14
15 PlatformCanvasMac::PlatformCanvasMac(int width, int height, bool is_opaque) 15 PlatformCanvas::PlatformCanvas(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 PlatformCanvas::PlatformCanvas(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, 28 PlatformCanvas::PlatformCanvas(int width,
29 int height, 29 int height,
30 bool is_opaque, 30 bool is_opaque,
31 uint8_t* data) 31 uint8_t* data)
32 : SkCanvas() { 32 : SkCanvas() {
33 initialize(width, height, is_opaque, data); 33 initialize(width, height, is_opaque, data);
34 } 34 }
35 35
36 PlatformCanvasMac::~PlatformCanvasMac() { 36 PlatformCanvas::~PlatformCanvas() {
37 } 37 }
38 38
39 bool PlatformCanvasMac::initialize(int width, 39 bool PlatformCanvas::initialize(int width,
40 int height, 40 int height,
41 bool is_opaque) { 41 bool is_opaque,
42 SkDevice* device = createPlatformDevice(width, height, is_opaque, NULL); 42 uint8_t* data) {
43 SkDevice* device = BitmapPlatformDevice::Create(NULL, width, height,
44 is_opaque);
43 if (!device) 45 if (!device)
44 return false; 46 return false;
45 47
46 setDevice(device); 48 setDevice(device);
47 device->unref(); // was created with refcount 1, and setDevice also refs 49 device->unref(); // Was created with refcount 1, and setDevice also refs.
48 return true; 50 return true;
49 } 51 }
50 52
51 bool PlatformCanvasMac::initialize(int width, 53 CGContextRef PlatformCanvas::beginPlatformPaint() {
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
78 CGContextRef PlatformCanvasMac::beginPlatformPaint() {
79 return getTopPlatformDevice().GetBitmapContext(); 54 return getTopPlatformDevice().GetBitmapContext();
80 } 55 }
81 56
82 void PlatformCanvasMac::endPlatformPaint() { 57 void PlatformCanvas::endPlatformPaint() {
83 // flushing will be done in onAccessBitmap 58 // Flushing will be done in onAccessBitmap.
84 } 59 }
85 60
86 PlatformDeviceMac& PlatformCanvasMac::getTopPlatformDevice() const { 61 SkDevice* PlatformCanvas::createDevice(SkBitmap::Config config,
87 // All of our devices should be our special PlatformDeviceMac. 62 int width,
88 SkCanvas::LayerIter iter(const_cast<PlatformCanvasMac*>(this), false); 63 int height,
89 return *static_cast<PlatformDeviceMac*>(iter.device()); 64 bool is_opaque, bool isForLayer) {
90 }
91
92 SkDevice* PlatformCanvasMac::createDevice(SkBitmap::Config config,
93 int width,
94 int height,
95 bool is_opaque, bool isForLayer) {
96 SkASSERT(config == SkBitmap::kARGB_8888_Config); 65 SkASSERT(config == SkBitmap::kARGB_8888_Config);
97 return createPlatformDevice(width, height, is_opaque, NULL); 66 return BitmapPlatformDevice::Create(NULL, width, height, is_opaque);
98 }
99
100 SkDevice* PlatformCanvasMac::createPlatformDevice(int width,
101 int height,
102 bool is_opaque,
103 CGContextRef context) {
104 SkDevice* device = BitmapPlatformDeviceMac::Create(context, width, height,
105 is_opaque);
106 return device;
107 }
108
109 SkDevice* PlatformCanvasMac::setBitmapDevice(const SkBitmap&) {
110 SkASSERT(false);
111 return NULL;
112 }
113
114 // static
115 size_t PlatformCanvasMac::StrideForWidth(unsigned width) {
116 return 4 * width;
117 } 67 }
118 68
119 } // namespace skia 69 } // namespace skia
OLDNEW
« no previous file with comments | « skia/ext/platform_canvas_mac.h ('k') | skia/ext/platform_canvas_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698