OLD | NEW |
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 "SkBitmapDevice.h" | 8 |
9 #include "SkDevice.h" | 9 #include "SkDevice.h" |
10 #include "SkDeviceProperties.h" | |
11 #include "SkDraw.h" | |
12 #include "SkImageFilter.h" | |
13 #include "SkMetaData.h" | 10 #include "SkMetaData.h" |
14 #include "SkRasterClip.h" | |
15 #include "SkRect.h" | |
16 #include "SkRRect.h" | |
17 #include "SkShader.h" | |
18 | 11 |
19 SK_DEFINE_INST_COUNT(SkBaseDevice) | 12 SK_DEFINE_INST_COUNT(SkBaseDevice) |
20 SK_DEFINE_INST_COUNT(SkBitmapDevice) | 13 |
| 14 #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A) |
| 15 const SkCanvas::Config8888 SkBaseDevice::kPMColorAlias = SkCanvas::kBGRA_Pre
mul_Config8888; |
| 16 #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A) |
| 17 const SkCanvas::Config8888 SkBaseDevice::kPMColorAlias = SkCanvas::kRGBA_Pre
mul_Config8888; |
| 18 #else |
| 19 const SkCanvas::Config8888 SkBaseDevice::kPMColorAlias = (SkCanvas::Config88
88) -1; |
| 20 #endif |
21 | 21 |
22 /////////////////////////////////////////////////////////////////////////////// | 22 /////////////////////////////////////////////////////////////////////////////// |
23 | |
24 #define CHECK_FOR_NODRAW_ANNOTATION(paint) \ | |
25 do { if (paint.isNoDrawAnnotation()) { return; } } while (0) | |
26 | |
27 /////////////////////////////////////////////////////////////////////////////// | |
28 | |
29 SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap) | |
30 : fBitmap(bitmap) { | |
31 SkASSERT(SkBitmap::kARGB_4444_Config != bitmap.config()); | |
32 } | |
33 | |
34 SkBaseDevice::SkBaseDevice() | 23 SkBaseDevice::SkBaseDevice() |
35 : fLeakyProperties(SkDeviceProperties::MakeDefault()) | 24 : fLeakyProperties(SkDeviceProperties::MakeDefault()) |
36 #ifdef SK_DEBUG | 25 #ifdef SK_DEBUG |
37 , fAttachedToCanvas(false) | 26 , fAttachedToCanvas(false) |
38 #endif | 27 #endif |
39 { | 28 { |
40 fOrigin.setZero(); | 29 fOrigin.setZero(); |
41 fMetaData = NULL; | 30 fMetaData = NULL; |
42 } | 31 } |
43 | 32 |
44 SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap, const SkDeviceProperties&
deviceProperties) | |
45 : SkBaseDevice(deviceProperties) | |
46 , fBitmap(bitmap) { | |
47 } | |
48 | |
49 SkBaseDevice::SkBaseDevice(const SkDeviceProperties& deviceProperties) | 33 SkBaseDevice::SkBaseDevice(const SkDeviceProperties& deviceProperties) |
50 : fLeakyProperties(deviceProperties) | 34 : fLeakyProperties(deviceProperties) |
51 #ifdef SK_DEBUG | 35 #ifdef SK_DEBUG |
52 , fAttachedToCanvas(false) | 36 , fAttachedToCanvas(false) |
53 #endif | 37 #endif |
54 { | 38 { |
55 fOrigin.setZero(); | 39 fOrigin.setZero(); |
56 fMetaData = NULL; | 40 fMetaData = NULL; |
57 } | 41 } |
58 | 42 |
59 SkBitmapDevice::SkBitmapDevice(SkBitmap::Config config, int width, int height, b
ool isOpaque) { | |
60 fBitmap.setConfig(config, width, height); | |
61 fBitmap.allocPixels(); | |
62 fBitmap.setIsOpaque(isOpaque); | |
63 if (!isOpaque) { | |
64 fBitmap.eraseColor(SK_ColorTRANSPARENT); | |
65 } | |
66 } | |
67 | |
68 SkBitmapDevice::SkBitmapDevice(SkBitmap::Config config, int width, int height, b
ool isOpaque, | |
69 const SkDeviceProperties& deviceProperties) | |
70 : SkBaseDevice(deviceProperties) { | |
71 | |
72 fBitmap.setConfig(config, width, height); | |
73 fBitmap.allocPixels(); | |
74 fBitmap.setIsOpaque(isOpaque); | |
75 if (!isOpaque) { | |
76 fBitmap.eraseColor(SK_ColorTRANSPARENT); | |
77 } | |
78 } | |
79 | |
80 SkBaseDevice::~SkBaseDevice() { | 43 SkBaseDevice::~SkBaseDevice() { |
81 delete fMetaData; | 44 delete fMetaData; |
82 } | 45 } |
83 | 46 |
84 SkBitmapDevice::~SkBitmapDevice() { | |
85 } | |
86 | |
87 void SkBitmapDevice::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) { | |
88 SkASSERT(bm.width() == fBitmap.width()); | |
89 SkASSERT(bm.height() == fBitmap.height()); | |
90 fBitmap = bm; // intent is to use bm's pixelRef (and rowbytes/config) | |
91 fBitmap.lockPixels(); | |
92 } | |
93 | |
94 SkBaseDevice* SkBaseDevice::createCompatibleDevice(SkBitmap::Config config, | 47 SkBaseDevice* SkBaseDevice::createCompatibleDevice(SkBitmap::Config config, |
95 int width, int height, | 48 int width, int height, |
96 bool isOpaque) { | 49 bool isOpaque) { |
97 return this->onCreateCompatibleDevice(config, width, height, | 50 return this->onCreateCompatibleDevice(config, width, height, |
98 isOpaque, kGeneral_Usage); | 51 isOpaque, kGeneral_Usage); |
99 } | 52 } |
100 | 53 |
101 SkBaseDevice* SkBaseDevice::createCompatibleDeviceForSaveLayer(SkBitmap::Config
config, | 54 SkBaseDevice* SkBaseDevice::createCompatibleDeviceForSaveLayer(SkBitmap::Config
config, |
102 int width, int he
ight, | 55 int width, int he
ight, |
103 bool isOpaque) { | 56 bool isOpaque) { |
104 return this->onCreateCompatibleDevice(config, width, height, | 57 return this->onCreateCompatibleDevice(config, width, height, |
105 isOpaque, kSaveLayer_Usage); | 58 isOpaque, kSaveLayer_Usage); |
106 } | 59 } |
107 | 60 |
108 SkBaseDevice* SkBitmapDevice::onCreateCompatibleDevice(SkBitmap::Config config, | |
109 int width, int height, | |
110 bool isOpaque, | |
111 Usage usage) { | |
112 return SkNEW_ARGS(SkBitmapDevice,(config, width, height, isOpaque, | |
113 this->getDeviceProperties())); | |
114 } | |
115 | |
116 SkMetaData& SkBaseDevice::getMetaData() { | 61 SkMetaData& SkBaseDevice::getMetaData() { |
117 // metadata users are rare, so we lazily allocate it. If that changes we | 62 // 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) | 63 // can decide to just make it a field in the device (rather than a ptr) |
119 if (NULL == fMetaData) { | 64 if (NULL == fMetaData) { |
120 fMetaData = new SkMetaData; | 65 fMetaData = new SkMetaData; |
121 } | 66 } |
122 return *fMetaData; | 67 return *fMetaData; |
123 } | 68 } |
124 | 69 |
125 void SkBitmapDevice::lockPixels() { | |
126 if (fBitmap.lockPixelsAreWritable()) { | |
127 fBitmap.lockPixels(); | |
128 } | |
129 } | |
130 | |
131 void SkBitmapDevice::unlockPixels() { | |
132 if (fBitmap.lockPixelsAreWritable()) { | |
133 fBitmap.unlockPixels(); | |
134 } | |
135 } | |
136 | |
137 const SkBitmap& SkBaseDevice::accessBitmap(bool changePixels) { | 70 const SkBitmap& SkBaseDevice::accessBitmap(bool changePixels) { |
138 const SkBitmap& bitmap = this->onAccessBitmap(); | 71 const SkBitmap& bitmap = this->onAccessBitmap(); |
139 if (changePixels) { | 72 if (changePixels) { |
140 bitmap.notifyPixelsChanged(); | 73 bitmap.notifyPixelsChanged(); |
141 } | 74 } |
142 return bitmap; | 75 return bitmap; |
143 } | 76 } |
144 | 77 |
145 void SkBitmapDevice::getGlobalBounds(SkIRect* bounds) const { | |
146 if (bounds) { | |
147 const SkIPoint& origin = this->getOrigin(); | |
148 bounds->setXYWH(origin.x(), origin.y(), | |
149 fBitmap.width(), fBitmap.height()); | |
150 } | |
151 } | |
152 | |
153 void SkBitmapDevice::clear(SkColor color) { | |
154 fBitmap.eraseColor(color); | |
155 } | |
156 | |
157 const SkBitmap& SkBitmapDevice::onAccessBitmap() { | |
158 return fBitmap; | |
159 } | |
160 | |
161 bool SkBitmapDevice::canHandleImageFilter(SkImageFilter*) { | |
162 return false; | |
163 } | |
164 | |
165 bool SkBitmapDevice::filterImage(SkImageFilter* filter, const SkBitmap& src, | |
166 const SkMatrix& ctm, SkBitmap* result, | |
167 SkIPoint* offset) { | |
168 return false; | |
169 } | |
170 | |
171 bool SkBitmapDevice::allowImageFilter(SkImageFilter*) { | |
172 return true; | |
173 } | |
174 | |
175 /////////////////////////////////////////////////////////////////////////////// | |
176 | |
177 bool SkBaseDevice::readPixels(SkBitmap* bitmap, int x, int y, | 78 bool SkBaseDevice::readPixels(SkBitmap* bitmap, int x, int y, |
178 SkCanvas::Config8888 config8888) { | 79 SkCanvas::Config8888 config8888) { |
179 if (SkBitmap::kARGB_8888_Config != bitmap->config() || | 80 if (SkBitmap::kARGB_8888_Config != bitmap->config() || |
180 NULL != bitmap->getTexture()) { | 81 NULL != bitmap->getTexture()) { |
181 return false; | 82 return false; |
182 } | 83 } |
183 | 84 |
184 const SkBitmap& src = this->accessBitmap(false); | 85 const SkBitmap& src = this->accessBitmap(false); |
185 | 86 |
186 SkIRect srcRect = SkIRect::MakeXYWH(x, y, bitmap->width(), | 87 SkIRect srcRect = SkIRect::MakeXYWH(x, y, bitmap->width(), |
(...skipping 24 matching lines...) Expand all Loading... |
211 bool result = this->onReadPixels(bmpSubset, | 112 bool result = this->onReadPixels(bmpSubset, |
212 srcRect.fLeft, | 113 srcRect.fLeft, |
213 srcRect.fTop, | 114 srcRect.fTop, |
214 config8888); | 115 config8888); |
215 if (result && bmp == &tmp) { | 116 if (result && bmp == &tmp) { |
216 tmp.swap(*bitmap); | 117 tmp.swap(*bitmap); |
217 } | 118 } |
218 return result; | 119 return result; |
219 } | 120 } |
220 | 121 |
221 #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A) | |
222 const SkCanvas::Config8888 SkBaseDevice::kPMColorAlias = | |
223 SkCanvas::kBGRA_Premul_Config8888; | |
224 #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A) | |
225 const SkCanvas::Config8888 SkBaseDevice::kPMColorAlias = | |
226 SkCanvas::kRGBA_Premul_Config8888; | |
227 #else | |
228 const SkCanvas::Config8888 SkBaseDevice::kPMColorAlias = | |
229 (SkCanvas::Config8888) -1; | |
230 #endif | |
231 | |
232 #include <SkConfig8888.h> | |
233 | |
234 bool SkBitmapDevice::onReadPixels(const SkBitmap& bitmap, | |
235 int x, int y, | |
236 SkCanvas::Config8888 config8888) { | |
237 SkASSERT(SkBitmap::kARGB_8888_Config == bitmap.config()); | |
238 SkASSERT(!bitmap.isNull()); | |
239 SkASSERT(SkIRect::MakeWH(this->width(), this->height()).contains(SkIRect::Ma
keXYWH(x, y, bitmap.width(), bitmap.height()))); | |
240 | |
241 SkIRect srcRect = SkIRect::MakeXYWH(x, y, bitmap.width(), | |
242 bitmap.height()); | |
243 const SkBitmap& src = this->accessBitmap(false); | |
244 | |
245 SkBitmap subset; | |
246 if (!src.extractSubset(&subset, srcRect)) { | |
247 return false; | |
248 } | |
249 if (SkBitmap::kARGB_8888_Config != subset.config()) { | |
250 // It'd be preferable to do this directly to bitmap. | |
251 subset.copyTo(&subset, SkBitmap::kARGB_8888_Config); | |
252 } | |
253 SkAutoLockPixels alp(bitmap); | |
254 uint32_t* bmpPixels = reinterpret_cast<uint32_t*>(bitmap.getPixels()); | |
255 SkCopyBitmapToConfig8888(bmpPixels, bitmap.rowBytes(), config8888, subset); | |
256 return true; | |
257 } | |
258 | |
259 void SkBitmapDevice::writePixels(const SkBitmap& bitmap, | |
260 int x, int y, | |
261 SkCanvas::Config8888 config8888) { | |
262 if (bitmap.isNull() || bitmap.getTexture()) { | |
263 return; | |
264 } | |
265 const SkBitmap* sprite = &bitmap; | |
266 // check whether we have to handle a config8888 that doesn't match SkPMColor | |
267 if (SkBitmap::kARGB_8888_Config == bitmap.config() && | |
268 SkCanvas::kNative_Premul_Config8888 != config8888 && | |
269 kPMColorAlias != config8888) { | |
270 | |
271 // We're going to have to convert from a config8888 to the native config | |
272 // First we clip to the device bounds. | |
273 SkBitmap dstBmp = this->accessBitmap(true); | |
274 SkIRect spriteRect = SkIRect::MakeXYWH(x, y, | |
275 bitmap.width(), bitmap.height()); | |
276 SkIRect devRect = SkIRect::MakeWH(dstBmp.width(), dstBmp.height()); | |
277 if (!spriteRect.intersect(devRect)) { | |
278 return; | |
279 } | |
280 | |
281 // write directly to the device if it has pixels and is SkPMColor | |
282 bool drawSprite; | |
283 if (SkBitmap::kARGB_8888_Config == dstBmp.config() && !dstBmp.isNull())
{ | |
284 // we can write directly to the dst when doing the conversion | |
285 dstBmp.extractSubset(&dstBmp, spriteRect); | |
286 drawSprite = false; | |
287 } else { | |
288 // we convert to a temporary bitmap and draw that as a sprite | |
289 dstBmp.setConfig(SkBitmap::kARGB_8888_Config, | |
290 spriteRect.width(), | |
291 spriteRect.height()); | |
292 if (!dstBmp.allocPixels()) { | |
293 return; | |
294 } | |
295 drawSprite = true; | |
296 } | |
297 | |
298 // copy pixels to dstBmp and convert from config8888 to native config. | |
299 SkAutoLockPixels alp(bitmap); | |
300 uint32_t* srcPixels = bitmap.getAddr32(spriteRect.fLeft - x, | |
301 spriteRect.fTop - y); | |
302 SkCopyConfig8888ToBitmap(dstBmp, | |
303 srcPixels, | |
304 bitmap.rowBytes(), | |
305 config8888); | |
306 | |
307 if (drawSprite) { | |
308 // we've clipped the sprite when we made a copy | |
309 x = spriteRect.fLeft; | |
310 y = spriteRect.fTop; | |
311 sprite = &dstBmp; | |
312 } else { | |
313 return; | |
314 } | |
315 } | |
316 | |
317 SkPaint paint; | |
318 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | |
319 SkRasterClip clip(SkIRect::MakeWH(fBitmap.width(), fBitmap.height())); | |
320 SkDraw draw; | |
321 draw.fRC = &clip; | |
322 draw.fClip = &clip.bwRgn(); | |
323 draw.fBitmap = &fBitmap; // canvas should have already called accessBitmap | |
324 draw.fMatrix = &SkMatrix::I(); | |
325 this->drawSprite(draw, *sprite, x, y, paint); | |
326 } | |
327 | |
328 /////////////////////////////////////////////////////////////////////////////// | |
329 | |
330 void SkBitmapDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { | |
331 draw.drawPaint(paint); | |
332 } | |
333 | |
334 void SkBitmapDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, si
ze_t count, | |
335 const SkPoint pts[], const SkPaint& paint) { | |
336 CHECK_FOR_NODRAW_ANNOTATION(paint); | |
337 draw.drawPoints(mode, count, pts, paint); | |
338 } | |
339 | |
340 void SkBitmapDevice::drawRect(const SkDraw& draw, const SkRect& r, const SkPaint
& paint) { | |
341 CHECK_FOR_NODRAW_ANNOTATION(paint); | |
342 draw.drawRect(r, paint); | |
343 } | |
344 | |
345 void SkBitmapDevice::drawOval(const SkDraw& draw, const SkRect& oval, const SkPa
int& paint) { | |
346 CHECK_FOR_NODRAW_ANNOTATION(paint); | |
347 | |
348 SkPath path; | |
349 path.addOval(oval); | |
350 // call the VIRTUAL version, so any subclasses who do handle drawPath aren't | |
351 // required to override drawOval. | |
352 this->drawPath(draw, path, paint, NULL, true); | |
353 } | |
354 | |
355 void SkBitmapDevice::drawRRect(const SkDraw& draw, const SkRRect& rrect, const S
kPaint& paint) { | |
356 CHECK_FOR_NODRAW_ANNOTATION(paint); | |
357 | |
358 SkPath path; | |
359 path.addRRect(rrect); | |
360 // call the VIRTUAL version, so any subclasses who do handle drawPath aren't | |
361 // required to override drawRRect. | |
362 this->drawPath(draw, path, paint, NULL, true); | |
363 } | |
364 | |
365 void SkBitmapDevice::drawPath(const SkDraw& draw, const SkPath& path, | |
366 const SkPaint& paint, const SkMatrix* prePathMatri
x, | |
367 bool pathIsMutable) { | |
368 CHECK_FOR_NODRAW_ANNOTATION(paint); | |
369 draw.drawPath(path, paint, prePathMatrix, pathIsMutable); | |
370 } | |
371 | |
372 void SkBitmapDevice::drawBitmap(const SkDraw& draw, const SkBitmap& bitmap, | |
373 const SkMatrix& matrix, const SkPaint& paint) { | |
374 draw.drawBitmap(bitmap, matrix, paint); | |
375 } | |
376 | |
377 void SkBitmapDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap, | |
378 const SkRect* src, const SkRect& dst, | |
379 const SkPaint& paint, | |
380 SkCanvas::DrawBitmapRectFlags flags) { | |
381 SkMatrix matrix; | |
382 SkRect bitmapBounds, tmpSrc, tmpDst; | |
383 SkBitmap tmpBitmap; | |
384 | |
385 bitmapBounds.isetWH(bitmap.width(), bitmap.height()); | |
386 | |
387 // Compute matrix from the two rectangles | |
388 if (src) { | |
389 tmpSrc = *src; | |
390 } else { | |
391 tmpSrc = bitmapBounds; | |
392 } | |
393 matrix.setRectToRect(tmpSrc, dst, SkMatrix::kFill_ScaleToFit); | |
394 | |
395 const SkRect* dstPtr = &dst; | |
396 const SkBitmap* bitmapPtr = &bitmap; | |
397 | |
398 // clip the tmpSrc to the bounds of the bitmap, and recompute dstRect if | |
399 // needed (if the src was clipped). No check needed if src==null. | |
400 if (src) { | |
401 if (!bitmapBounds.contains(*src)) { | |
402 if (!tmpSrc.intersect(bitmapBounds)) { | |
403 return; // nothing to draw | |
404 } | |
405 // recompute dst, based on the smaller tmpSrc | |
406 matrix.mapRect(&tmpDst, tmpSrc); | |
407 dstPtr = &tmpDst; | |
408 } | |
409 | |
410 // since we may need to clamp to the borders of the src rect within | |
411 // the bitmap, we extract a subset. | |
412 SkIRect srcIR; | |
413 tmpSrc.roundOut(&srcIR); | |
414 if (!bitmap.extractSubset(&tmpBitmap, srcIR)) { | |
415 return; | |
416 } | |
417 bitmapPtr = &tmpBitmap; | |
418 | |
419 // Since we did an extract, we need to adjust the matrix accordingly | |
420 SkScalar dx = 0, dy = 0; | |
421 if (srcIR.fLeft > 0) { | |
422 dx = SkIntToScalar(srcIR.fLeft); | |
423 } | |
424 if (srcIR.fTop > 0) { | |
425 dy = SkIntToScalar(srcIR.fTop); | |
426 } | |
427 if (dx || dy) { | |
428 matrix.preTranslate(dx, dy); | |
429 } | |
430 | |
431 SkRect extractedBitmapBounds; | |
432 extractedBitmapBounds.isetWH(bitmapPtr->width(), bitmapPtr->height()); | |
433 if (extractedBitmapBounds == tmpSrc) { | |
434 // no fractional part in src, we can just call drawBitmap | |
435 goto USE_DRAWBITMAP; | |
436 } | |
437 } else { | |
438 USE_DRAWBITMAP: | |
439 // We can go faster by just calling drawBitmap, which will concat the | |
440 // matrix with the CTM, and try to call drawSprite if it can. If not, | |
441 // it will make a shader and call drawRect, as we do below. | |
442 this->drawBitmap(draw, *bitmapPtr, matrix, paint); | |
443 return; | |
444 } | |
445 | |
446 // construct a shader, so we can call drawRect with the dst | |
447 SkShader* s = SkShader::CreateBitmapShader(*bitmapPtr, | |
448 SkShader::kClamp_TileMode, | |
449 SkShader::kClamp_TileMode); | |
450 if (NULL == s) { | |
451 return; | |
452 } | |
453 s->setLocalMatrix(matrix); | |
454 | |
455 SkPaint paintWithShader(paint); | |
456 paintWithShader.setStyle(SkPaint::kFill_Style); | |
457 paintWithShader.setShader(s)->unref(); | |
458 | |
459 // Call ourself, in case the subclass wanted to share this setup code | |
460 // but handle the drawRect code themselves. | |
461 this->drawRect(draw, *dstPtr, paintWithShader); | |
462 } | |
463 | |
464 void SkBitmapDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap, | |
465 int x, int y, const SkPaint& paint) { | |
466 draw.drawSprite(bitmap, x, y, paint); | |
467 } | |
468 | |
469 void SkBitmapDevice::drawText(const SkDraw& draw, const void* text, size_t len, | |
470 SkScalar x, SkScalar y, const SkPaint& paint) { | |
471 draw.drawText((const char*)text, len, x, y, paint); | |
472 } | |
473 | |
474 void SkBitmapDevice::drawPosText(const SkDraw& draw, const void* text, size_t le
n, | |
475 const SkScalar xpos[], SkScalar y, | |
476 int scalarsPerPos, const SkPaint& paint) { | |
477 draw.drawPosText((const char*)text, len, xpos, y, scalarsPerPos, paint); | |
478 } | |
479 | |
480 void SkBitmapDevice::drawTextOnPath(const SkDraw& draw, const void* text, | |
481 size_t len, const SkPath& path, | |
482 const SkMatrix* matrix, | |
483 const SkPaint& paint) { | |
484 draw.drawTextOnPath((const char*)text, len, path, matrix, paint); | |
485 } | |
486 | |
487 #ifdef SK_BUILD_FOR_ANDROID | |
488 void SkBitmapDevice::drawPosTextOnPath(const SkDraw& draw, const void* text, siz
e_t len, | |
489 const SkPoint pos[], const SkPaint& paint
, | |
490 const SkPath& path, const SkMatrix* matri
x) { | |
491 draw.drawPosTextOnPath((const char*)text, len, pos, paint, path, matrix); | |
492 } | |
493 #endif | |
494 | |
495 void SkBitmapDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode
, | |
496 int vertexCount, | |
497 const SkPoint verts[], const SkPoint textures[
], | |
498 const SkColor colors[], SkXfermode* xmode, | |
499 const uint16_t indices[], int indexCount, | |
500 const SkPaint& paint) { | |
501 draw.drawVertices(vmode, vertexCount, verts, textures, colors, xmode, | |
502 indices, indexCount, paint); | |
503 } | |
504 | |
505 void SkBitmapDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device, | |
506 int x, int y, const SkPaint& paint) { | |
507 const SkBitmap& src = device->accessBitmap(false); | |
508 draw.drawSprite(src, x, y, paint); | |
509 } | |
510 | |
511 /////////////////////////////////////////////////////////////////////////////// | |
512 | |
513 bool SkBitmapDevice::filterTextFlags(const SkPaint& paint, TextFlags* flags) { | |
514 if (!paint.isLCDRenderText() || !paint.isAntiAlias()) { | |
515 // we're cool with the paint as is | |
516 return false; | |
517 } | |
518 | |
519 if (SkBitmap::kARGB_8888_Config != fBitmap.config() || | |
520 paint.getRasterizer() || | |
521 paint.getPathEffect() || | |
522 paint.isFakeBoldText() || | |
523 paint.getStyle() != SkPaint::kFill_Style || | |
524 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) { | |
525 // turn off lcd | |
526 flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag; | |
527 flags->fHinting = paint.getHinting(); | |
528 return true; | |
529 } | |
530 // we're cool with the paint as is | |
531 return false; | |
532 } | |
OLD | NEW |