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

Side by Side Diff: src/core/SkDevice.cpp

Issue 22978012: Split SkDevice into SkBaseDevice and SkBitmapDevice (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Moved code around to make code review easier Created 7 years, 4 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 | Annotate | Revision Log
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "SkDevice.h" 8 #include "SkDevice.h"
9 #include "SkDeviceProperties.h" 9 #include "SkDeviceProperties.h"
10 #include "SkDraw.h" 10 #include "SkDraw.h"
11 #include "SkImageFilter.h" 11 #include "SkImageFilter.h"
12 #include "SkMetaData.h" 12 #include "SkMetaData.h"
13 #include "SkRasterClip.h" 13 #include "SkRasterClip.h"
14 #include "SkRect.h" 14 #include "SkRect.h"
15 #include "SkRRect.h" 15 #include "SkRRect.h"
16 #include "SkShader.h" 16 #include "SkShader.h"
17 17
18 SK_DEFINE_INST_COUNT(SkDevice) 18 SK_DEFINE_INST_COUNT(SkDevice)
19 SK_DEFINE_INST_COUNT(SkRasterDevice)
19 20
20 /////////////////////////////////////////////////////////////////////////////// 21 ///////////////////////////////////////////////////////////////////////////////
21 22
22 #define CHECK_FOR_NODRAW_ANNOTATION(paint) \ 23 #define CHECK_FOR_NODRAW_ANNOTATION(paint) \
23 do { if (paint.isNoDrawAnnotation()) { return; } } while (0) 24 do { if (paint.isNoDrawAnnotation()) { return; } } while (0)
24 25
25 /////////////////////////////////////////////////////////////////////////////// 26 ///////////////////////////////////////////////////////////////////////////////
26 27
27 SkDevice::SkDevice(const SkBitmap& bitmap) 28 SkRasterDevice::SkRasterDevice(const SkBitmap& bitmap)
28 : fBitmap(bitmap), fLeakyProperties(SkDeviceProperties::MakeDefault()) 29 : fBitmap(bitmap) {
30 SkASSERT(SkBitmap::kARGB_4444_Config != bitmap.config());
31 }
32
33 SkDevice::SkDevice()
34 : fLeakyProperties(SkDeviceProperties::MakeDefault())
29 #ifdef SK_DEBUG 35 #ifdef SK_DEBUG
30 , fAttachedToCanvas(false) 36 , fAttachedToCanvas(false)
31 #endif 37 #endif
32 {
33 fOrigin.setZero();
34 fMetaData = NULL;
35
36 SkASSERT(SkBitmap::kARGB_4444_Config != bitmap.config());
37 }
38
39 SkDevice::SkDevice(const SkBitmap& bitmap, const SkDeviceProperties& devicePrope rties)
40 : fBitmap(bitmap), fLeakyProperties(deviceProperties)
41 #ifdef SK_DEBUG
42 , fAttachedToCanvas(false)
43 #endif
44 { 38 {
45 fOrigin.setZero(); 39 fOrigin.setZero();
46 fMetaData = NULL; 40 fMetaData = NULL;
47 } 41 }
48 42
49 SkDevice::SkDevice(SkBitmap::Config config, int width, int height, bool isOpaque ) 43 SkRasterDevice::SkRasterDevice(const SkBitmap& bitmap, const SkDeviceProperties& deviceProperties)
50 : fLeakyProperties(SkDeviceProperties::MakeDefault()) 44 : SkDevice(deviceProperties)
45 , fBitmap(bitmap) {
46 }
47
48 SkDevice::SkDevice(const SkDeviceProperties& deviceProperties)
49 : fLeakyProperties(deviceProperties)
51 #ifdef SK_DEBUG 50 #ifdef SK_DEBUG
52 , fAttachedToCanvas(false) 51 , fAttachedToCanvas(false)
53 #endif 52 #endif
54 { 53 {
55 fOrigin.setZero(); 54 fOrigin.setZero();
56 fMetaData = NULL; 55 fMetaData = NULL;
56 }
57 57
58 SkRasterDevice::SkRasterDevice(SkBitmap::Config config, int width, int height, b ool isOpaque) {
58 fBitmap.setConfig(config, width, height); 59 fBitmap.setConfig(config, width, height);
59 fBitmap.allocPixels(); 60 fBitmap.allocPixels();
60 fBitmap.setIsOpaque(isOpaque); 61 fBitmap.setIsOpaque(isOpaque);
61 if (!isOpaque) { 62 if (!isOpaque) {
62 fBitmap.eraseColor(SK_ColorTRANSPARENT); 63 fBitmap.eraseColor(SK_ColorTRANSPARENT);
63 } 64 }
64 } 65 }
65 66
66 SkDevice::SkDevice(SkBitmap::Config config, int width, int height, bool isOpaque , 67 SkRasterDevice::SkRasterDevice(SkBitmap::Config config, int width, int height, b ool isOpaque,
67 const SkDeviceProperties& deviceProperties) 68 const SkDeviceProperties& deviceProperties)
68 : fLeakyProperties(deviceProperties) 69 : SkDevice(deviceProperties) {
69 #ifdef SK_DEBUG
70 , fAttachedToCanvas(false)
71 #endif
72 {
73 fOrigin.setZero();
74 fMetaData = NULL;
75 70
76 fBitmap.setConfig(config, width, height); 71 fBitmap.setConfig(config, width, height);
77 fBitmap.allocPixels(); 72 fBitmap.allocPixels();
78 fBitmap.setIsOpaque(isOpaque); 73 fBitmap.setIsOpaque(isOpaque);
79 if (!isOpaque) { 74 if (!isOpaque) {
80 fBitmap.eraseColor(SK_ColorTRANSPARENT); 75 fBitmap.eraseColor(SK_ColorTRANSPARENT);
81 } 76 }
82 } 77 }
83 78
84 SkDevice::~SkDevice() { 79 SkDevice::~SkDevice() {
85 delete fMetaData; 80 delete fMetaData;
86 } 81 }
87 82
88 void SkDevice::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) { 83 SkRasterDevice::~SkRasterDevice() {
84 }
85
86 void SkRasterDevice::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) {
89 SkASSERT(bm.width() == fBitmap.width()); 87 SkASSERT(bm.width() == fBitmap.width());
90 SkASSERT(bm.height() == fBitmap.height()); 88 SkASSERT(bm.height() == fBitmap.height());
91 fBitmap = bm; // intent is to use bm's pixelRef (and rowbytes/config) 89 fBitmap = bm; // intent is to use bm's pixelRef (and rowbytes/config)
92 fBitmap.lockPixels(); 90 fBitmap.lockPixels();
93 } 91 }
94 92
95 SkDevice* SkDevice::createCompatibleDevice(SkBitmap::Config config, 93 SkDevice* SkDevice::createCompatibleDevice(SkBitmap::Config config,
96 int width, int height, 94 int width, int height,
97 bool isOpaque) { 95 bool isOpaque) {
98 return this->onCreateCompatibleDevice(config, width, height, 96 return this->onCreateCompatibleDevice(config, width, height,
99 isOpaque, kGeneral_Usage); 97 isOpaque, kGeneral_Usage);
100 } 98 }
101 99
102 SkDevice* SkDevice::createCompatibleDeviceForSaveLayer(SkBitmap::Config config, 100 SkDevice* SkDevice::createCompatibleDeviceForSaveLayer(SkBitmap::Config config,
103 int width, int height, 101 int width, int height,
104 bool isOpaque) { 102 bool isOpaque) {
105 return this->onCreateCompatibleDevice(config, width, height, 103 return this->onCreateCompatibleDevice(config, width, height,
106 isOpaque, kSaveLayer_Usage); 104 isOpaque, kSaveLayer_Usage);
107 } 105 }
108 106
109 SkDevice* SkDevice::onCreateCompatibleDevice(SkBitmap::Config config, 107 SkDevice* SkRasterDevice::onCreateCompatibleDevice(SkBitmap::Config config,
110 int width, int height, 108 int width, int height,
111 bool isOpaque, 109 bool isOpaque,
112 Usage usage) { 110 Usage usage) {
113 return SkNEW_ARGS(SkDevice,(config, width, height, isOpaque, fLeakyPropertie s)); 111 return SkNEW_ARGS(SkRasterDevice,(config, width, height, isOpaque, this->get DeviceProperties()));
114 } 112 }
115 113
116 SkMetaData& SkDevice::getMetaData() { 114 SkMetaData& SkDevice::getMetaData() {
117 // metadata users are rare, so we lazily allocate it. If that changes we 115 // metadata users are rare, so we lazily allocate it. If that changes we
118 // can decide to just make it a field in the device (rather than a ptr) 116 // can decide to just make it a field in the device (rather than a ptr)
119 if (NULL == fMetaData) { 117 if (NULL == fMetaData) {
120 fMetaData = new SkMetaData; 118 fMetaData = new SkMetaData;
121 } 119 }
122 return *fMetaData; 120 return *fMetaData;
123 } 121 }
124 122
125 void SkDevice::lockPixels() { 123 void SkRasterDevice::lockPixels() {
126 if (fBitmap.lockPixelsAreWritable()) { 124 if (fBitmap.lockPixelsAreWritable()) {
127 fBitmap.lockPixels(); 125 fBitmap.lockPixels();
128 } 126 }
129 } 127 }
130 128
131 void SkDevice::unlockPixels() { 129 void SkRasterDevice::unlockPixels() {
132 if (fBitmap.lockPixelsAreWritable()) { 130 if (fBitmap.lockPixelsAreWritable()) {
133 fBitmap.unlockPixels(); 131 fBitmap.unlockPixels();
134 } 132 }
135 } 133 }
136 134
137 const SkBitmap& SkDevice::accessBitmap(bool changePixels) { 135 const SkBitmap& SkDevice::accessBitmap(bool changePixels) {
138 const SkBitmap& bitmap = this->onAccessBitmap(&fBitmap); 136 const SkBitmap& bitmap = this->onAccessBitmap();
139 if (changePixels) { 137 if (changePixels) {
140 bitmap.notifyPixelsChanged(); 138 bitmap.notifyPixelsChanged();
141 } 139 }
142 return bitmap; 140 return bitmap;
143 } 141 }
144 142
145 void SkDevice::getGlobalBounds(SkIRect* bounds) const { 143 void SkRasterDevice::getGlobalBounds(SkIRect* bounds) const {
146 if (bounds) { 144 if (bounds) {
147 bounds->setXYWH(fOrigin.x(), fOrigin.y(), 145 const SkIPoint& origin = this->getOrigin();
146 bounds->setXYWH(origin.x(), origin.y(),
148 fBitmap.width(), fBitmap.height()); 147 fBitmap.width(), fBitmap.height());
149 } 148 }
150 } 149 }
151 150
152 void SkDevice::clear(SkColor color) { 151 void SkRasterDevice::clear(SkColor color) {
153 fBitmap.eraseColor(color); 152 fBitmap.eraseColor(color);
154 } 153 }
155 154
156 const SkBitmap& SkDevice::onAccessBitmap(SkBitmap* bitmap) {return *bitmap;} 155 const SkBitmap& SkRasterDevice::onAccessBitmap() {
157 156 return fBitmap;
158 void SkDevice::setMatrixClip(const SkMatrix& matrix, const SkRegion& region,
159 const SkClipStack& clipStack) {
160 } 157 }
161 158
162 bool SkDevice::canHandleImageFilter(SkImageFilter*) { 159 bool SkRasterDevice::canHandleImageFilter(SkImageFilter*) {
163 return false; 160 return false;
164 } 161 }
165 162
166 bool SkDevice::filterImage(SkImageFilter* filter, const SkBitmap& src, 163 bool SkRasterDevice::filterImage(SkImageFilter* filter, const SkBitmap& src,
167 const SkMatrix& ctm, SkBitmap* result, 164 const SkMatrix& ctm, SkBitmap* result,
168 SkIPoint* offset) { 165 SkIPoint* offset) {
169 return false; 166 return false;
170 } 167 }
171 168
172 bool SkDevice::allowImageFilter(SkImageFilter*) { 169 bool SkRasterDevice::allowImageFilter(SkImageFilter*) {
173 return true; 170 return true;
174 } 171 }
175 172
176 /////////////////////////////////////////////////////////////////////////////// 173 ///////////////////////////////////////////////////////////////////////////////
177 174
178 bool SkDevice::readPixels(SkBitmap* bitmap, int x, int y, 175 bool SkDevice::readPixels(SkBitmap* bitmap, int x, int y,
179 SkCanvas::Config8888 config8888) { 176 SkCanvas::Config8888 config8888) {
180 if (SkBitmap::kARGB_8888_Config != bitmap->config() || 177 if (SkBitmap::kARGB_8888_Config != bitmap->config() ||
181 NULL != bitmap->getTexture()) { 178 NULL != bitmap->getTexture()) {
182 return false; 179 return false;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A) 222 #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A)
226 const SkCanvas::Config8888 SkDevice::kPMColorAlias = 223 const SkCanvas::Config8888 SkDevice::kPMColorAlias =
227 SkCanvas::kRGBA_Premul_Config8888; 224 SkCanvas::kRGBA_Premul_Config8888;
228 #else 225 #else
229 const SkCanvas::Config8888 SkDevice::kPMColorAlias = 226 const SkCanvas::Config8888 SkDevice::kPMColorAlias =
230 (SkCanvas::Config8888) -1; 227 (SkCanvas::Config8888) -1;
231 #endif 228 #endif
232 229
233 #include <SkConfig8888.h> 230 #include <SkConfig8888.h>
234 231
235 bool SkDevice::onReadPixels(const SkBitmap& bitmap, 232 bool SkRasterDevice::onReadPixels(const SkBitmap& bitmap,
236 int x, int y, 233 int x, int y,
237 SkCanvas::Config8888 config8888) { 234 SkCanvas::Config8888 config8888) {
238 SkASSERT(SkBitmap::kARGB_8888_Config == bitmap.config()); 235 SkASSERT(SkBitmap::kARGB_8888_Config == bitmap.config());
239 SkASSERT(!bitmap.isNull()); 236 SkASSERT(!bitmap.isNull());
240 SkASSERT(SkIRect::MakeWH(this->width(), this->height()).contains(SkIRect::Ma keXYWH(x, y, bitmap.width(), bitmap.height()))); 237 SkASSERT(SkIRect::MakeWH(this->width(), this->height()).contains(SkIRect::Ma keXYWH(x, y, bitmap.width(), bitmap.height())));
241 238
242 SkIRect srcRect = SkIRect::MakeXYWH(x, y, bitmap.width(), 239 SkIRect srcRect = SkIRect::MakeXYWH(x, y, bitmap.width(),
243 bitmap.height()); 240 bitmap.height());
244 const SkBitmap& src = this->accessBitmap(false); 241 const SkBitmap& src = this->accessBitmap(false);
245 242
246 SkBitmap subset; 243 SkBitmap subset;
247 if (!src.extractSubset(&subset, srcRect)) { 244 if (!src.extractSubset(&subset, srcRect)) {
248 return false; 245 return false;
249 } 246 }
250 if (SkBitmap::kARGB_8888_Config != subset.config()) { 247 if (SkBitmap::kARGB_8888_Config != subset.config()) {
251 // It'd be preferable to do this directly to bitmap. 248 // It'd be preferable to do this directly to bitmap.
252 subset.copyTo(&subset, SkBitmap::kARGB_8888_Config); 249 subset.copyTo(&subset, SkBitmap::kARGB_8888_Config);
253 } 250 }
254 SkAutoLockPixels alp(bitmap); 251 SkAutoLockPixels alp(bitmap);
255 uint32_t* bmpPixels = reinterpret_cast<uint32_t*>(bitmap.getPixels()); 252 uint32_t* bmpPixels = reinterpret_cast<uint32_t*>(bitmap.getPixels());
256 SkCopyBitmapToConfig8888(bmpPixels, bitmap.rowBytes(), config8888, subset); 253 SkCopyBitmapToConfig8888(bmpPixels, bitmap.rowBytes(), config8888, subset);
257 return true; 254 return true;
258 } 255 }
259 256
260 void SkDevice::writePixels(const SkBitmap& bitmap, 257 void SkRasterDevice::writePixels(const SkBitmap& bitmap,
261 int x, int y, 258 int x, int y,
262 SkCanvas::Config8888 config8888) { 259 SkCanvas::Config8888 config8888) {
263 if (bitmap.isNull() || bitmap.getTexture()) { 260 if (bitmap.isNull() || bitmap.getTexture()) {
264 return; 261 return;
265 } 262 }
266 const SkBitmap* sprite = &bitmap; 263 const SkBitmap* sprite = &bitmap;
267 // check whether we have to handle a config8888 that doesn't match SkPMColor 264 // check whether we have to handle a config8888 that doesn't match SkPMColor
268 if (SkBitmap::kARGB_8888_Config == bitmap.config() && 265 if (SkBitmap::kARGB_8888_Config == bitmap.config() &&
269 SkCanvas::kNative_Premul_Config8888 != config8888 && 266 SkCanvas::kNative_Premul_Config8888 != config8888 &&
270 kPMColorAlias != config8888) { 267 kPMColorAlias != config8888) {
271 268
272 // We're going to have to convert from a config8888 to the native config 269 // We're going to have to convert from a config8888 to the native config
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 SkDraw draw; 318 SkDraw draw;
322 draw.fRC = &clip; 319 draw.fRC = &clip;
323 draw.fClip = &clip.bwRgn(); 320 draw.fClip = &clip.bwRgn();
324 draw.fBitmap = &fBitmap; // canvas should have already called accessBitmap 321 draw.fBitmap = &fBitmap; // canvas should have already called accessBitmap
325 draw.fMatrix = &SkMatrix::I(); 322 draw.fMatrix = &SkMatrix::I();
326 this->drawSprite(draw, *sprite, x, y, paint); 323 this->drawSprite(draw, *sprite, x, y, paint);
327 } 324 }
328 325
329 /////////////////////////////////////////////////////////////////////////////// 326 ///////////////////////////////////////////////////////////////////////////////
330 327
331 void SkDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { 328 void SkRasterDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) {
332 draw.drawPaint(paint); 329 draw.drawPaint(paint);
333 } 330 }
334 331
335 void SkDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, size_t c ount, 332 void SkRasterDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, si ze_t count,
336 const SkPoint pts[], const SkPaint& paint) { 333 const SkPoint pts[], const SkPaint& paint) {
337 CHECK_FOR_NODRAW_ANNOTATION(paint); 334 CHECK_FOR_NODRAW_ANNOTATION(paint);
338 draw.drawPoints(mode, count, pts, paint); 335 draw.drawPoints(mode, count, pts, paint);
339 } 336 }
340 337
341 void SkDevice::drawRect(const SkDraw& draw, const SkRect& r, const SkPaint& pain t) { 338 void SkRasterDevice::drawRect(const SkDraw& draw, const SkRect& r, const SkPaint & paint) {
342 CHECK_FOR_NODRAW_ANNOTATION(paint); 339 CHECK_FOR_NODRAW_ANNOTATION(paint);
343 draw.drawRect(r, paint); 340 draw.drawRect(r, paint);
344 } 341 }
345 342
346 void SkDevice::drawOval(const SkDraw& draw, const SkRect& oval, const SkPaint& p aint) { 343 void SkRasterDevice::drawOval(const SkDraw& draw, const SkRect& oval, const SkPa int& paint) {
347 CHECK_FOR_NODRAW_ANNOTATION(paint); 344 CHECK_FOR_NODRAW_ANNOTATION(paint);
348 345
349 SkPath path; 346 SkPath path;
350 path.addOval(oval); 347 path.addOval(oval);
351 // call the VIRTUAL version, so any subclasses who do handle drawPath aren't 348 // call the VIRTUAL version, so any subclasses who do handle drawPath aren't
352 // required to override drawOval. 349 // required to override drawOval.
353 this->drawPath(draw, path, paint, NULL, true); 350 this->drawPath(draw, path, paint, NULL, true);
354 } 351 }
355 352
356 void SkDevice::drawRRect(const SkDraw& draw, const SkRRect& rrect, const SkPaint & paint) { 353 void SkRasterDevice::drawRRect(const SkDraw& draw, const SkRRect& rrect, const S kPaint& paint) {
357 CHECK_FOR_NODRAW_ANNOTATION(paint); 354 CHECK_FOR_NODRAW_ANNOTATION(paint);
358 355
359 SkPath path; 356 SkPath path;
360 path.addRRect(rrect); 357 path.addRRect(rrect);
361 // call the VIRTUAL version, so any subclasses who do handle drawPath aren't 358 // call the VIRTUAL version, so any subclasses who do handle drawPath aren't
362 // required to override drawRRect. 359 // required to override drawRRect.
363 this->drawPath(draw, path, paint, NULL, true); 360 this->drawPath(draw, path, paint, NULL, true);
364 } 361 }
365 362
366 void SkDevice::drawPath(const SkDraw& draw, const SkPath& path, 363 void SkRasterDevice::drawPath(const SkDraw& draw, const SkPath& path,
367 const SkPaint& paint, const SkMatrix* prePathMatrix, 364 const SkPaint& paint, const SkMatrix* prePathMatri x,
368 bool pathIsMutable) { 365 bool pathIsMutable) {
369 CHECK_FOR_NODRAW_ANNOTATION(paint); 366 CHECK_FOR_NODRAW_ANNOTATION(paint);
370 draw.drawPath(path, paint, prePathMatrix, pathIsMutable); 367 draw.drawPath(path, paint, prePathMatrix, pathIsMutable);
371 } 368 }
372 369
373 void SkDevice::drawBitmap(const SkDraw& draw, const SkBitmap& bitmap, 370 void SkRasterDevice::drawBitmap(const SkDraw& draw, const SkBitmap& bitmap,
374 const SkMatrix& matrix, const SkPaint& paint) { 371 const SkMatrix& matrix, const SkPaint& paint) {
375 draw.drawBitmap(bitmap, matrix, paint); 372 draw.drawBitmap(bitmap, matrix, paint);
376 } 373 }
377 374
378 void SkDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap, 375 void SkRasterDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap,
379 const SkRect* src, const SkRect& dst, 376 const SkRect* src, const SkRect& dst,
380 const SkPaint& paint) { 377 const SkPaint& paint) {
381 SkMatrix matrix; 378 SkMatrix matrix;
382 SkRect bitmapBounds, tmpSrc, tmpDst; 379 SkRect bitmapBounds, tmpSrc, tmpDst;
383 SkBitmap tmpBitmap; 380 SkBitmap tmpBitmap;
384 381
385 bitmapBounds.isetWH(bitmap.width(), bitmap.height()); 382 bitmapBounds.isetWH(bitmap.width(), bitmap.height());
386 383
387 // Compute matrix from the two rectangles 384 // Compute matrix from the two rectangles
388 if (src) { 385 if (src) {
389 tmpSrc = *src; 386 tmpSrc = *src;
390 } else { 387 } else {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 451
455 SkPaint paintWithShader(paint); 452 SkPaint paintWithShader(paint);
456 paintWithShader.setStyle(SkPaint::kFill_Style); 453 paintWithShader.setStyle(SkPaint::kFill_Style);
457 paintWithShader.setShader(s)->unref(); 454 paintWithShader.setShader(s)->unref();
458 455
459 // Call ourself, in case the subclass wanted to share this setup code 456 // Call ourself, in case the subclass wanted to share this setup code
460 // but handle the drawRect code themselves. 457 // but handle the drawRect code themselves.
461 this->drawRect(draw, *dstPtr, paintWithShader); 458 this->drawRect(draw, *dstPtr, paintWithShader);
462 } 459 }
463 460
464 void SkDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap, 461 void SkRasterDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
465 int x, int y, const SkPaint& paint) { 462 int x, int y, const SkPaint& paint) {
466 draw.drawSprite(bitmap, x, y, paint); 463 draw.drawSprite(bitmap, x, y, paint);
467 } 464 }
468 465
469 void SkDevice::drawText(const SkDraw& draw, const void* text, size_t len, 466 void SkRasterDevice::drawText(const SkDraw& draw, const void* text, size_t len,
470 SkScalar x, SkScalar y, const SkPaint& paint) { 467 SkScalar x, SkScalar y, const SkPaint& paint) {
471 draw.drawText((const char*)text, len, x, y, paint); 468 draw.drawText((const char*)text, len, x, y, paint);
472 } 469 }
473 470
474 void SkDevice::drawPosText(const SkDraw& draw, const void* text, size_t len, 471 void SkRasterDevice::drawPosText(const SkDraw& draw, const void* text, size_t le n,
475 const SkScalar xpos[], SkScalar y, 472 const SkScalar xpos[], SkScalar y,
476 int scalarsPerPos, const SkPaint& paint) { 473 int scalarsPerPos, const SkPaint& paint) {
477 draw.drawPosText((const char*)text, len, xpos, y, scalarsPerPos, paint); 474 draw.drawPosText((const char*)text, len, xpos, y, scalarsPerPos, paint);
478 } 475 }
479 476
480 void SkDevice::drawTextOnPath(const SkDraw& draw, const void* text, 477 void SkRasterDevice::drawTextOnPath(const SkDraw& draw, const void* text,
481 size_t len, const SkPath& path, 478 size_t len, const SkPath& path,
482 const SkMatrix* matrix, 479 const SkMatrix* matrix,
483 const SkPaint& paint) { 480 const SkPaint& paint) {
484 draw.drawTextOnPath((const char*)text, len, path, matrix, paint); 481 draw.drawTextOnPath((const char*)text, len, path, matrix, paint);
485 } 482 }
486 483
487 #ifdef SK_BUILD_FOR_ANDROID 484 #ifdef SK_BUILD_FOR_ANDROID
488 void SkDevice::drawPosTextOnPath(const SkDraw& draw, const void* text, size_t le n, 485 void SkRasterDevice::drawPosTextOnPath(const SkDraw& draw, const void* text, siz e_t len,
489 const SkPoint pos[], const SkPaint& paint, 486 const SkPoint pos[], const SkPaint& paint ,
490 const SkPath& path, const SkMatrix* matrix) { 487 const SkPath& path, const SkMatrix* matri x) {
491 draw.drawPosTextOnPath((const char*)text, len, pos, paint, path, matrix); 488 draw.drawPosTextOnPath((const char*)text, len, pos, paint, path, matrix);
492 } 489 }
493 #endif 490 #endif
494 491
495 void SkDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, 492 void SkRasterDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode ,
496 int vertexCount, 493 int vertexCount,
497 const SkPoint verts[], const SkPoint textures[], 494 const SkPoint verts[], const SkPoint textures[ ],
498 const SkColor colors[], SkXfermode* xmode, 495 const SkColor colors[], SkXfermode* xmode,
499 const uint16_t indices[], int indexCount, 496 const uint16_t indices[], int indexCount,
500 const SkPaint& paint) { 497 const SkPaint& paint) {
501 draw.drawVertices(vmode, vertexCount, verts, textures, colors, xmode, 498 draw.drawVertices(vmode, vertexCount, verts, textures, colors, xmode,
502 indices, indexCount, paint); 499 indices, indexCount, paint);
503 } 500 }
504 501
505 void SkDevice::drawDevice(const SkDraw& draw, SkDevice* device, 502 void SkRasterDevice::drawDevice(const SkDraw& draw, SkDevice* device,
506 int x, int y, const SkPaint& paint) { 503 int x, int y, const SkPaint& paint) {
507 const SkBitmap& src = device->accessBitmap(false); 504 const SkBitmap& src = device->accessBitmap(false);
508 draw.drawSprite(src, x, y, paint); 505 draw.drawSprite(src, x, y, paint);
509 } 506 }
510 507
511 /////////////////////////////////////////////////////////////////////////////// 508 ///////////////////////////////////////////////////////////////////////////////
512 509
513 bool SkDevice::filterTextFlags(const SkPaint& paint, TextFlags* flags) { 510 bool SkRasterDevice::filterTextFlags(const SkPaint& paint, TextFlags* flags) {
514 if (!paint.isLCDRenderText() || !paint.isAntiAlias()) { 511 if (!paint.isLCDRenderText() || !paint.isAntiAlias()) {
515 // we're cool with the paint as is 512 // we're cool with the paint as is
516 return false; 513 return false;
517 } 514 }
518 515
519 if (SkBitmap::kARGB_8888_Config != fBitmap.config() || 516 if (SkBitmap::kARGB_8888_Config != fBitmap.config() ||
520 paint.getRasterizer() || 517 paint.getRasterizer() ||
521 paint.getPathEffect() || 518 paint.getPathEffect() ||
522 paint.isFakeBoldText() || 519 paint.isFakeBoldText() ||
523 paint.getStyle() != SkPaint::kFill_Style || 520 paint.getStyle() != SkPaint::kFill_Style ||
524 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) { 521 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) {
525 // turn off lcd 522 // turn off lcd
526 flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag; 523 flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag;
527 flags->fHinting = paint.getHinting(); 524 flags->fHinting = paint.getHinting();
528 return true; 525 return true;
529 } 526 }
530 // we're cool with the paint as is 527 // we're cool with the paint as is
531 return false; 528 return false;
532 } 529 }
OLDNEW
« include/core/SkDevice.h ('K') | « src/core/SkCanvas.cpp ('k') | src/core/SkPicture.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698