2 * Copyright 2006 The Android Open Source Project
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
11 #include "SkColorPriv.h"
13 #include "SkDeviceLooper.h"
15 #include "SkMaskFilter.h"
17 #include "SkPathEffect.h"
18 #include "SkRasterClip.h"
19 #include "SkRasterizer.h"
23 #include "SkSmallAllocator.h"
26 #include "SkTextMapStateProc.h"
29 #include "SkVertState.h"
31 #include "SkAutoKern.h"
32 #include "SkBitmapProcShader.h"
33 #include "SkDrawProcs.h"
34 #include "SkMatrixUtils.h"
37 //#define TRACE_BITMAP_DRAWS
40 /** Helper for allocating small blitters on the stack.
42 class SkAutoBlitterChoose : SkNoncopyable {
44 SkAutoBlitterChoose() {
47 SkAutoBlitterChoose(const SkBitmap& device, const SkMatrix& matrix,
48 const SkPaint& paint, bool drawCoverage = false) {
49 fBlitter = SkBlitter::Choose(device, matrix, paint, &fAllocator,
53 SkBlitter* operator->() { return fBlitter; }
54 SkBlitter* get() const { return fBlitter; }
56 void choose(const SkBitmap& device, const SkMatrix& matrix,
57 const SkPaint& paint, bool drawCoverage = false) {
59 fBlitter = SkBlitter::Choose(device, matrix, paint, &fAllocator,
64 // Owned by fAllocator, which will handle the delete.
66 SkTBlitterAllocator fAllocator;
68 #define SkAutoBlitterChoose(...) SK_REQUIRE_LOCAL_VAR(SkAutoBlitterChoose)
71 * Since we are providing the storage for the shader (to avoid the perf cost
72 * of calling new) we insist that in our destructor we can account for all
73 * owners of the shader.
75 class SkAutoBitmapShaderInstall : SkNoncopyable {
77 SkAutoBitmapShaderInstall(const SkBitmap& src, const SkPaint& paint,
78 const SkMatrix* localMatrix = NULL)
79 : fPaint(paint) /* makes a copy of the paint */ {
80 fPaint.setShader(CreateBitmapShader(src, SkShader::kClamp_TileMode,
81 SkShader::kClamp_TileMode,
82 localMatrix, &fAllocator));
83 // we deliberately left the shader with an owner-count of 2
84 SkASSERT(2 == fPaint.getShader()->getRefCnt());
87 ~SkAutoBitmapShaderInstall() {
88 // since fAllocator will destroy shader, we insist that owners == 2
89 SkASSERT(2 == fPaint.getShader()->getRefCnt());
91 fPaint.setShader(NULL); // unref the shader by 1
95 // return the new paint that has the shader applied
96 const SkPaint& paintWithShader() const { return fPaint; }
99 // copy of caller's paint (which we then modify)
101 // Stores the shader.
102 SkTBlitterAllocator fAllocator;
104 #define SkAutoBitmapShaderInstall(...) SK_REQUIRE_LOCAL_VAR(SkAutoBitmapShaderInstall)
106 ///////////////////////////////////////////////////////////////////////////////
109 sk_bzero(this, sizeof(*this));
112 SkDraw::SkDraw(const SkDraw& src) {
113 memcpy(this, &src, sizeof(*this));
116 bool SkDraw::computeConservativeLocalClipBounds(SkRect* localBounds) const {
117 if (fRC->isEmpty()) {
122 if (!fMatrix->invert(&inverse)) {
126 SkIRect devBounds = fRC->getBounds();
127 // outset to have slop for antialasing and hairlines
128 devBounds.outset(1, 1);
129 inverse.mapRect(localBounds, SkRect::Make(devBounds));
133 ///////////////////////////////////////////////////////////////////////////////
135 typedef void (*BitmapXferProc)(void* pixels, size_t bytes, uint32_t data);
137 static void D_Clear_BitmapXferProc(void* pixels, size_t bytes, uint32_t) {
138 sk_bzero(pixels, bytes);
141 static void D_Dst_BitmapXferProc(void*, size_t, uint32_t data) {}
143 static void D32_Src_BitmapXferProc(void* pixels, size_t bytes, uint32_t data) {
144 sk_memset32((uint32_t*)pixels, data, SkToInt(bytes >> 2));
147 static void D16_Src_BitmapXferProc(void* pixels, size_t bytes, uint32_t data) {
148 sk_memset16((uint16_t*)pixels, data, SkToInt(bytes >> 1));
151 static void DA8_Src_BitmapXferProc(void* pixels, size_t bytes, uint32_t data) {
152 memset(pixels, data, bytes);
155 static BitmapXferProc ChooseBitmapXferProc(const SkBitmap& bitmap,
156 const SkPaint& paint,
158 // todo: we can apply colorfilter up front if no shader, so we wouldn't
159 // need to abort this fastpath
160 if (paint.getShader() || paint.getColorFilter()) {
164 SkXfermode::Mode mode;
165 if (!SkXfermode::AsMode(paint.getXfermode(), &mode)) {
169 SkColor color = paint.getColor();
171 // collaps modes based on color...
172 if (SkXfermode::kSrcOver_Mode == mode) {
173 unsigned alpha = SkColorGetA(color);
175 mode = SkXfermode::kDst_Mode;
176 } else if (0xFF == alpha) {
177 mode = SkXfermode::kSrc_Mode;
182 case SkXfermode::kClear_Mode:
183 // SkDebugf("--- D_Clear_BitmapXferProc\n");
184 return D_Clear_BitmapXferProc; // ignore data
185 case SkXfermode::kDst_Mode:
186 // SkDebugf("--- D_Dst_BitmapXferProc\n");
187 return D_Dst_BitmapXferProc; // ignore data
188 case SkXfermode::kSrc_Mode: {
190 should I worry about dithering for the lower depths?
192 SkPMColor pmc = SkPreMultiplyColor(color);
193 switch (bitmap.colorType()) {
194 case kN32_SkColorType:
198 // SkDebugf("--- D32_Src_BitmapXferProc\n");
199 return D32_Src_BitmapXferProc;
200 case kRGB_565_SkColorType:
202 *data = SkPixel32ToPixel16(pmc);
204 // SkDebugf("--- D16_Src_BitmapXferProc\n");
205 return D16_Src_BitmapXferProc;
206 case kAlpha_8_SkColorType:
208 *data = SkGetPackedA32(pmc);
210 // SkDebugf("--- DA8_Src_BitmapXferProc\n");
211 return DA8_Src_BitmapXferProc;
223 static void CallBitmapXferProc(const SkBitmap& bitmap, const SkIRect& rect,
224 BitmapXferProc proc, uint32_t procData) {
226 switch (bitmap.colorType()) {
227 case kN32_SkColorType:
230 case kRGB_565_SkColorType:
233 case kAlpha_8_SkColorType:
237 SkDEBUGFAIL("Can't use xferproc on this config");
241 uint8_t* pixels = (uint8_t*)bitmap.getPixels();
243 const size_t rowBytes = bitmap.rowBytes();
244 const int widthBytes = rect.width() << shiftPerPixel;
246 // skip down to the first scanline and X position
247 pixels += rect.fTop * rowBytes + (rect.fLeft << shiftPerPixel);
248 for (int scans = rect.height() - 1; scans >= 0; --scans) {
249 proc(pixels, widthBytes, procData);
254 void SkDraw::drawPaint(const SkPaint& paint) const {
255 SkDEBUGCODE(this->validate();)
257 if (fRC->isEmpty()) {
262 devRect.set(0, 0, fBitmap->width(), fBitmap->height());
265 /* If we don't have a shader (i.e. we're just a solid color) we may
266 be faster to operate directly on the device bitmap, rather than invoking
267 a blitter. Esp. true for xfermodes, which require a colorshader to be
268 present, which is just redundant work. Since we're drawing everywhere
269 in the clip, we don't have to worry about antialiasing.
271 uint32_t procData = 0; // to avoid the warning
272 BitmapXferProc proc = ChooseBitmapXferProc(*fBitmap, paint, &procData);
274 if (D_Dst_BitmapXferProc == proc) { // nothing to do
278 SkRegion::Iterator iter(fRC->bwRgn());
279 while (!iter.done()) {
280 CallBitmapXferProc(*fBitmap, iter.rect(), proc, procData);
287 // normal case: use a blitter
288 SkAutoBlitterChoose blitter(*fBitmap, *fMatrix, paint);
289 SkScan::FillIRect(devRect, *fRC, blitter.get());
292 ///////////////////////////////////////////////////////////////////////////////
295 SkCanvas::PointMode fMode;
296 const SkPaint* fPaint;
297 const SkRegion* fClip;
298 const SkRasterClip* fRC;
303 typedef void (*Proc)(const PtProcRec&, const SkPoint devPts[], int count,
306 bool init(SkCanvas::PointMode, const SkPaint&, const SkMatrix* matrix,
307 const SkRasterClip*);
308 Proc chooseProc(SkBlitter** blitter);
311 SkAAClipBlitterWrapper fWrapper;
314 static void bw_pt_rect_hair_proc(const PtProcRec& rec, const SkPoint devPts[],
315 int count, SkBlitter* blitter) {
316 SkASSERT(rec.fClip->isRect());
317 const SkIRect& r = rec.fClip->getBounds();
319 for (int i = 0; i < count; i++) {
320 int x = SkScalarFloorToInt(devPts[i].fX);
321 int y = SkScalarFloorToInt(devPts[i].fY);
322 if (r.contains(x, y)) {
323 blitter->blitH(x, y, 1);
328 static void bw_pt_rect_16_hair_proc(const PtProcRec& rec,
329 const SkPoint devPts[], int count,
330 SkBlitter* blitter) {
331 SkASSERT(rec.fRC->isRect());
332 const SkIRect& r = rec.fRC->getBounds();
334 const SkBitmap* bitmap = blitter->justAnOpaqueColor(&value);
337 uint16_t* addr = bitmap->getAddr16(0, 0);
338 size_t rb = bitmap->rowBytes();
340 for (int i = 0; i < count; i++) {
341 int x = SkScalarFloorToInt(devPts[i].fX);
342 int y = SkScalarFloorToInt(devPts[i].fY);
343 if (r.contains(x, y)) {
344 ((uint16_t*)((char*)addr + y * rb))[x] = SkToU16(value);
349 static void bw_pt_rect_32_hair_proc(const PtProcRec& rec,
350 const SkPoint devPts[], int count,
351 SkBlitter* blitter) {
352 SkASSERT(rec.fRC->isRect());
353 const SkIRect& r = rec.fRC->getBounds();
355 const SkBitmap* bitmap = blitter->justAnOpaqueColor(&value);
358 SkPMColor* addr = bitmap->getAddr32(0, 0);
359 size_t rb = bitmap->rowBytes();
361 for (int i = 0; i < count; i++) {
362 int x = SkScalarFloorToInt(devPts[i].fX);
363 int y = SkScalarFloorToInt(devPts[i].fY);
364 if (r.contains(x, y)) {
365 ((SkPMColor*)((char*)addr + y * rb))[x] = value;
370 static void bw_pt_hair_proc(const PtProcRec& rec, const SkPoint devPts[],
371 int count, SkBlitter* blitter) {
372 for (int i = 0; i < count; i++) {
373 int x = SkScalarFloorToInt(devPts[i].fX);
374 int y = SkScalarFloorToInt(devPts[i].fY);
375 if (rec.fClip->contains(x, y)) {
376 blitter->blitH(x, y, 1);
381 static void bw_line_hair_proc(const PtProcRec& rec, const SkPoint devPts[],
382 int count, SkBlitter* blitter) {
383 for (int i = 0; i < count; i += 2) {
384 SkScan::HairLine(devPts[i], devPts[i+1], *rec.fRC, blitter);
388 static void bw_poly_hair_proc(const PtProcRec& rec, const SkPoint devPts[],
389 int count, SkBlitter* blitter) {
390 for (int i = 0; i < count - 1; i++) {
391 SkScan::HairLine(devPts[i], devPts[i+1], *rec.fRC, blitter);
397 static void aa_line_hair_proc(const PtProcRec& rec, const SkPoint devPts[],
398 int count, SkBlitter* blitter) {
399 for (int i = 0; i < count; i += 2) {
400 SkScan::AntiHairLine(devPts[i], devPts[i+1], *rec.fRC, blitter);
404 static void aa_poly_hair_proc(const PtProcRec& rec, const SkPoint devPts[],
405 int count, SkBlitter* blitter) {
406 for (int i = 0; i < count - 1; i++) {
407 SkScan::AntiHairLine(devPts[i], devPts[i+1], *rec.fRC, blitter);
411 // square procs (strokeWidth > 0 but matrix is square-scale (sx == sy)
413 static void bw_square_proc(const PtProcRec& rec, const SkPoint devPts[],
414 int count, SkBlitter* blitter) {
415 const SkFixed radius = rec.fRadius;
416 for (int i = 0; i < count; i++) {
417 SkFixed x = SkScalarToFixed(devPts[i].fX);
418 SkFixed y = SkScalarToFixed(devPts[i].fY);
421 r.fLeft = x - radius;
423 r.fRight = x + radius;
424 r.fBottom = y + radius;
426 SkScan::FillXRect(r, *rec.fRC, blitter);
430 static void aa_square_proc(const PtProcRec& rec, const SkPoint devPts[],
431 int count, SkBlitter* blitter) {
432 const SkFixed radius = rec.fRadius;
433 for (int i = 0; i < count; i++) {
434 SkFixed x = SkScalarToFixed(devPts[i].fX);
435 SkFixed y = SkScalarToFixed(devPts[i].fY);
438 r.fLeft = x - radius;
440 r.fRight = x + radius;
441 r.fBottom = y + radius;
443 SkScan::AntiFillXRect(r, *rec.fRC, blitter);
447 // If this guy returns true, then chooseProc() must return a valid proc
448 bool PtProcRec::init(SkCanvas::PointMode mode, const SkPaint& paint,
449 const SkMatrix* matrix, const SkRasterClip* rc) {
450 if (paint.getPathEffect()) {
453 SkScalar width = paint.getStrokeWidth();
459 fRadius = SK_FixedHalf;
462 if (paint.getStrokeCap() != SkPaint::kRound_Cap &&
463 matrix->rectStaysRect() && SkCanvas::kPoints_PointMode == mode) {
464 SkScalar sx = matrix->get(SkMatrix::kMScaleX);
465 SkScalar sy = matrix->get(SkMatrix::kMScaleY);
466 if (SkScalarNearlyZero(sx - sy)) {
475 fRadius = SkScalarToFixed(SkScalarMul(width, sx)) >> 1;
482 PtProcRec::Proc PtProcRec::chooseProc(SkBlitter** blitterPtr) {
485 SkBlitter* blitter = *blitterPtr;
487 fClip = &fRC->bwRgn();
489 fWrapper.init(*fRC, blitter);
490 fClip = &fWrapper.getRgn();
491 blitter = fWrapper.getBlitter();
492 *blitterPtr = blitter;
496 SkASSERT(0 == SkCanvas::kPoints_PointMode);
497 SkASSERT(1 == SkCanvas::kLines_PointMode);
498 SkASSERT(2 == SkCanvas::kPolygon_PointMode);
499 SkASSERT((unsigned)fMode <= (unsigned)SkCanvas::kPolygon_PointMode);
501 if (fPaint->isAntiAlias()) {
502 if (0 == fPaint->getStrokeWidth()) {
503 static const Proc gAAProcs[] = {
504 aa_square_proc, aa_line_hair_proc, aa_poly_hair_proc
506 proc = gAAProcs[fMode];
507 } else if (fPaint->getStrokeCap() != SkPaint::kRound_Cap) {
508 SkASSERT(SkCanvas::kPoints_PointMode == fMode);
509 proc = aa_square_proc;
512 if (fRadius <= SK_FixedHalf) { // small radii and hairline
513 if (SkCanvas::kPoints_PointMode == fMode && fClip->isRect()) {
515 const SkBitmap* bm = blitter->justAnOpaqueColor(&value);
516 if (bm && kRGB_565_SkColorType == bm->colorType()) {
517 proc = bw_pt_rect_16_hair_proc;
518 } else if (bm && kN32_SkColorType == bm->colorType()) {
519 proc = bw_pt_rect_32_hair_proc;
521 proc = bw_pt_rect_hair_proc;
524 static Proc gBWProcs[] = {
525 bw_pt_hair_proc, bw_line_hair_proc, bw_poly_hair_proc
527 proc = gBWProcs[fMode];
530 proc = bw_square_proc;
536 // each of these costs 8-bytes of stack space, so don't make it too large
537 // must be even for lines/polygon to work
538 #define MAX_DEV_PTS 32
540 void SkDraw::drawPoints(SkCanvas::PointMode mode, size_t count,
541 const SkPoint pts[], const SkPaint& paint,
542 bool forceUseDevice) const {
543 // if we're in lines mode, force count to be even
544 if (SkCanvas::kLines_PointMode == mode) {
548 if ((long)count <= 0) {
552 SkASSERT(pts != NULL);
553 SkDEBUGCODE(this->validate();)
556 if (fRC->isEmpty()) {
561 if (!forceUseDevice && rec.init(mode, paint, fMatrix, fRC)) {
562 SkAutoBlitterChoose blitter(*fBitmap, *fMatrix, paint);
564 SkPoint devPts[MAX_DEV_PTS];
565 const SkMatrix* matrix = fMatrix;
566 SkBlitter* bltr = blitter.get();
567 PtProcRec::Proc proc = rec.chooseProc(&bltr);
568 // we have to back up subsequent passes if we're in polygon mode
569 const size_t backup = (SkCanvas::kPolygon_PointMode == mode);
572 int n = SkToInt(count);
573 if (n > MAX_DEV_PTS) {
576 matrix->mapPoints(devPts, pts, n);
577 proc(rec, devPts, n, bltr);
579 SkASSERT(SkToInt(count) >= n);
584 } while (count != 0);
587 case SkCanvas::kPoints_PointMode: {
588 // temporarily mark the paint as filling.
589 SkPaint newPaint(paint);
590 newPaint.setStyle(SkPaint::kFill_Style);
592 SkScalar width = newPaint.getStrokeWidth();
593 SkScalar radius = SkScalarHalf(width);
595 if (newPaint.getStrokeCap() == SkPaint::kRound_Cap) {
599 path.addCircle(0, 0, radius);
600 for (size_t i = 0; i < count; i++) {
601 preMatrix.setTranslate(pts[i].fX, pts[i].fY);
602 // pass true for the last point, since we can modify
605 fDevice->drawPath(*this, path, newPaint, &preMatrix,
608 this->drawPath(path, newPaint, &preMatrix,
615 for (size_t i = 0; i < count; i++) {
616 r.fLeft = pts[i].fX - radius;
617 r.fTop = pts[i].fY - radius;
618 r.fRight = r.fLeft + width;
619 r.fBottom = r.fTop + width;
621 fDevice->drawRect(*this, r, newPaint);
623 this->drawRect(r, newPaint);
629 case SkCanvas::kLines_PointMode:
630 #ifndef SK_DISABLE_DASHING_OPTIMIZATION
631 if (2 == count && paint.getPathEffect()) {
632 // most likely a dashed line - see if it is one of the ones
634 SkStrokeRec rec(paint);
635 SkPathEffect::PointData pointData;
641 SkRect cullRect = SkRect::Make(fRC->getBounds());
643 if (paint.getPathEffect()->asPoints(&pointData, path, rec,
644 *fMatrix, &cullRect)) {
645 // 'asPoints' managed to find some fast path
648 newP.setPathEffect(NULL);
649 newP.setStyle(SkPaint::kFill_Style);
651 if (!pointData.fFirst.isEmpty()) {
653 fDevice->drawPath(*this, pointData.fFirst, newP);
655 this->drawPath(pointData.fFirst, newP);
659 if (!pointData.fLast.isEmpty()) {
661 fDevice->drawPath(*this, pointData.fLast, newP);
663 this->drawPath(pointData.fLast, newP);
667 if (pointData.fSize.fX == pointData.fSize.fY) {
668 // The rest of the dashed line can just be drawn as points
669 SkASSERT(pointData.fSize.fX == SkScalarHalf(newP.getStrokeWidth()));
671 if (SkPathEffect::PointData::kCircles_PointFlag & pointData.fFlags) {
672 newP.setStrokeCap(SkPaint::kRound_Cap);
674 newP.setStrokeCap(SkPaint::kButt_Cap);
678 fDevice->drawPoints(*this,
679 SkCanvas::kPoints_PointMode,
680 pointData.fNumPoints,
684 this->drawPoints(SkCanvas::kPoints_PointMode,
685 pointData.fNumPoints,
692 // The rest of the dashed line must be drawn as rects
693 SkASSERT(!(SkPathEffect::PointData::kCircles_PointFlag &
698 for (int i = 0; i < pointData.fNumPoints; ++i) {
699 r.set(pointData.fPoints[i].fX - pointData.fSize.fX,
700 pointData.fPoints[i].fY - pointData.fSize.fY,
701 pointData.fPoints[i].fX + pointData.fSize.fX,
702 pointData.fPoints[i].fY + pointData.fSize.fY);
704 fDevice->drawRect(*this, r, newP);
706 this->drawRect(r, newP);
714 #endif // DISABLE_DASHING_OPTIMIZATION
715 // couldn't take fast path so fall through!
716 case SkCanvas::kPolygon_PointMode: {
720 p.setStyle(SkPaint::kStroke_Style);
721 size_t inc = (SkCanvas::kLines_PointMode == mode) ? 2 : 1;
722 for (size_t i = 0; i < count; i += inc) {
724 path.lineTo(pts[i+1]);
726 fDevice->drawPath(*this, path, p, NULL, true);
728 this->drawPath(path, p, NULL, true);
738 static bool easy_rect_join(const SkPaint& paint, const SkMatrix& matrix,
739 SkPoint* strokeSize) {
740 if (SkPaint::kMiter_Join != paint.getStrokeJoin() ||
741 paint.getStrokeMiter() < SK_ScalarSqrt2) {
745 SkASSERT(matrix.rectStaysRect());
746 SkPoint pt = { paint.getStrokeWidth(), paint.getStrokeWidth() };
747 matrix.mapVectors(strokeSize, &pt, 1);
748 strokeSize->fX = SkScalarAbs(strokeSize->fX);
749 strokeSize->fY = SkScalarAbs(strokeSize->fY);
753 SkDraw::RectType SkDraw::ComputeRectType(const SkPaint& paint,
754 const SkMatrix& matrix,
755 SkPoint* strokeSize) {
757 const SkScalar width = paint.getStrokeWidth();
758 const bool zeroWidth = (0 == width);
759 SkPaint::Style style = paint.getStyle();
761 if ((SkPaint::kStrokeAndFill_Style == style) && zeroWidth) {
762 style = SkPaint::kFill_Style;
765 if (paint.getPathEffect() || paint.getMaskFilter() ||
766 paint.getRasterizer() || !matrix.rectStaysRect() ||
767 SkPaint::kStrokeAndFill_Style == style) {
768 rtype = kPath_RectType;
769 } else if (SkPaint::kFill_Style == style) {
770 rtype = kFill_RectType;
771 } else if (zeroWidth) {
772 rtype = kHair_RectType;
773 } else if (easy_rect_join(paint, matrix, strokeSize)) {
774 rtype = kStroke_RectType;
776 rtype = kPath_RectType;
781 static const SkPoint* rect_points(const SkRect& r) {
782 return SkTCast<const SkPoint*>(&r);
785 static SkPoint* rect_points(SkRect& r) {
786 return SkTCast<SkPoint*>(&r);
789 void SkDraw::drawRect(const SkRect& rect, const SkPaint& paint) const {
790 SkDEBUGCODE(this->validate();)
793 if (fRC->isEmpty()) {
798 RectType rtype = ComputeRectType(paint, *fMatrix, &strokeSize);
800 if (kPath_RectType == rtype) {
803 tmp.setFillType(SkPath::kWinding_FillType);
804 this->drawPath(tmp, paint, NULL, true);
808 const SkMatrix& matrix = *fMatrix;
811 // transform rect into devRect
812 matrix.mapPoints(rect_points(devRect), rect_points(rect), 2);
815 // look for the quick exit, before we build a blitter
817 devRect.roundOut(&ir);
818 if (paint.getStyle() != SkPaint::kFill_Style) {
819 // extra space for hairlines
820 if (paint.getStrokeWidth() == 0) {
823 SkScalar radius = SkScalarHalf(paint.getStrokeWidth());
824 ir.outset(radius, radius);
827 if (fRC->quickReject(ir)) {
831 SkDeviceLooper looper(*fBitmap, *fRC, ir, paint.isAntiAlias());
832 while (looper.next()) {
834 looper.mapRect(&localDevRect, devRect);
835 SkMatrix localMatrix;
836 looper.mapMatrix(&localMatrix, matrix);
838 SkAutoBlitterChoose blitterStorage(looper.getBitmap(), localMatrix,
840 const SkRasterClip& clip = looper.getRC();
841 SkBlitter* blitter = blitterStorage.get();
843 // we want to "fill" if we are kFill or kStrokeAndFill, since in the latter
844 // case we are also hairline (if we've gotten to here), which devolves to
845 // effectively just kFill
848 if (paint.isAntiAlias()) {
849 SkScan::AntiFillRect(localDevRect, clip, blitter);
851 SkScan::FillRect(localDevRect, clip, blitter);
854 case kStroke_RectType:
855 if (paint.isAntiAlias()) {
856 SkScan::AntiFrameRect(localDevRect, strokeSize, clip, blitter);
858 SkScan::FrameRect(localDevRect, strokeSize, clip, blitter);
862 if (paint.isAntiAlias()) {
863 SkScan::AntiHairRect(localDevRect, clip, blitter);
865 SkScan::HairRect(localDevRect, clip, blitter);
869 SkDEBUGFAIL("bad rtype");
874 void SkDraw::drawDevMask(const SkMask& srcM, const SkPaint& paint) const {
875 if (srcM.fBounds.isEmpty()) {
879 const SkMask* mask = &srcM;
882 if (paint.getMaskFilter() &&
883 paint.getMaskFilter()->filterMask(&dstM, srcM, *fMatrix, NULL)) {
888 SkAutoMaskFreeImage ami(dstM.fImage);
890 SkAutoBlitterChoose blitterChooser(*fBitmap, *fMatrix, paint);
891 SkBlitter* blitter = blitterChooser.get();
893 SkAAClipBlitterWrapper wrapper;
894 const SkRegion* clipRgn;
897 clipRgn = &fRC->bwRgn();
899 wrapper.init(*fRC, blitter);
900 clipRgn = &wrapper.getRgn();
901 blitter = wrapper.getBlitter();
903 blitter->blitMaskRegion(*mask, *clipRgn);
906 static SkScalar fast_len(const SkVector& vec) {
907 SkScalar x = SkScalarAbs(vec.fX);
908 SkScalar y = SkScalarAbs(vec.fY);
912 return x + SkScalarHalf(y);
915 static bool xfermodeSupportsCoverageAsAlpha(SkXfermode* xfer) {
916 SkXfermode::Coeff dc;
917 if (!SkXfermode::AsCoeff(xfer, NULL, &dc)) {
922 case SkXfermode::kOne_Coeff:
923 case SkXfermode::kISA_Coeff:
924 case SkXfermode::kISC_Coeff:
931 bool SkDrawTreatAAStrokeAsHairline(SkScalar strokeWidth, const SkMatrix& matrix,
932 SkScalar* coverage) {
933 SkASSERT(strokeWidth > 0);
934 // We need to try to fake a thick-stroke with a modulated hairline.
936 if (matrix.hasPerspective()) {
940 SkVector src[2], dst[2];
941 src[0].set(strokeWidth, 0);
942 src[1].set(0, strokeWidth);
943 matrix.mapVectors(dst, src, 2);
944 SkScalar len0 = fast_len(dst[0]);
945 SkScalar len1 = fast_len(dst[1]);
946 if (len0 <= SK_Scalar1 && len1 <= SK_Scalar1) {
948 *coverage = SkScalarAve(len0, len1);
955 void SkDraw::drawRRect(const SkRRect& rrect, const SkPaint& paint) const {
956 SkDEBUGCODE(this->validate());
958 if (fRC->isEmpty()) {
963 // TODO: Investigate optimizing these options. They are in the same
964 // order as SkDraw::drawPath, which handles each case. It may be
965 // that there is no way to optimize for these using the SkRRect path.
967 if (SkDrawTreatAsHairline(paint, *fMatrix, &coverage)) {
971 if (paint.getPathEffect() || paint.getStyle() != SkPaint::kFill_Style) {
975 if (paint.getRasterizer()) {
980 if (paint.getMaskFilter()) {
981 // Transform the rrect into device space.
983 if (rrect.transform(*fMatrix, &devRRect)) {
984 SkAutoBlitterChoose blitter(*fBitmap, *fMatrix, paint);
985 if (paint.getMaskFilter()->filterRRect(devRRect, *fMatrix, *fRC, blitter.get(),
986 SkPaint::kFill_Style)) {
987 return; // filterRRect() called the blitter, so we're done
993 // Now fall back to the default case of using a path.
995 path.addRRect(rrect);
996 this->drawPath(path, paint, NULL, true);
999 void SkDraw::drawPath(const SkPath& origSrcPath, const SkPaint& origPaint,
1000 const SkMatrix* prePathMatrix, bool pathIsMutable,
1001 bool drawCoverage, SkBlitter* customBlitter) const {
1002 SkDEBUGCODE(this->validate();)
1005 if (fRC->isEmpty()) {
1009 SkPath* pathPtr = (SkPath*)&origSrcPath;
1013 const SkMatrix* matrix = fMatrix;
1015 if (prePathMatrix) {
1016 if (origPaint.getPathEffect() || origPaint.getStyle() != SkPaint::kFill_Style ||
1017 origPaint.getRasterizer()) {
1018 SkPath* result = pathPtr;
1020 if (!pathIsMutable) {
1022 pathIsMutable = true;
1024 pathPtr->transform(*prePathMatrix, result);
1027 tmpMatrix.setConcat(*matrix, *prePathMatrix);
1028 matrix = &tmpMatrix;
1031 // at this point we're done with prePathMatrix
1032 SkDEBUGCODE(prePathMatrix = (const SkMatrix*)0x50FF8001;)
1034 SkTCopyOnFirstWrite<SkPaint> paint(origPaint);
1038 if (SkDrawTreatAsHairline(origPaint, *matrix, &coverage)) {
1039 if (SK_Scalar1 == coverage) {
1040 paint.writable()->setStrokeWidth(0);
1041 } else if (xfermodeSupportsCoverageAsAlpha(origPaint.getXfermode())) {
1044 newAlpha = SkToU8(SkScalarRoundToInt(coverage *
1045 origPaint.getAlpha()));
1047 // this is the old technique, which we preserve for now so
1048 // we don't change previous results (testing)
1049 // the new way seems fine, its just (a tiny bit) different
1050 int scale = (int)SkScalarMul(coverage, 256);
1051 newAlpha = origPaint.getAlpha() * scale >> 8;
1053 SkPaint* writablePaint = paint.writable();
1054 writablePaint->setStrokeWidth(0);
1055 writablePaint->setAlpha(newAlpha);
1060 if (paint->getPathEffect() || paint->getStyle() != SkPaint::kFill_Style) {
1062 const SkRect* cullRectPtr = NULL;
1063 if (this->computeConservativeLocalClipBounds(&cullRect)) {
1064 cullRectPtr = &cullRect;
1066 doFill = paint->getFillPath(*pathPtr, &tmpPath, cullRectPtr);
1070 if (paint->getRasterizer()) {
1072 if (paint->getRasterizer()->rasterize(*pathPtr, *matrix,
1073 &fRC->getBounds(), paint->getMaskFilter(), &mask,
1074 SkMask::kComputeBoundsAndRenderImage_CreateMode)) {
1075 this->drawDevMask(mask, *paint);
1076 SkMask::FreeImage(mask.fImage);
1081 // avoid possibly allocating a new path in transform if we can
1082 SkPath* devPathPtr = pathIsMutable ? pathPtr : &tmpPath;
1084 // transform the path into device space
1085 pathPtr->transform(*matrix, devPathPtr);
1087 SkBlitter* blitter = NULL;
1088 SkAutoBlitterChoose blitterStorage;
1089 if (NULL == customBlitter) {
1090 blitterStorage.choose(*fBitmap, *fMatrix, *paint, drawCoverage);
1091 blitter = blitterStorage.get();
1093 blitter = customBlitter;
1096 if (paint->getMaskFilter()) {
1097 SkPaint::Style style = doFill ? SkPaint::kFill_Style :
1098 SkPaint::kStroke_Style;
1099 if (paint->getMaskFilter()->filterPath(*devPathPtr, *fMatrix, *fRC, blitter, style)) {
1100 return; // filterPath() called the blitter, so we're done
1104 void (*proc)(const SkPath&, const SkRasterClip&, SkBlitter*);
1106 if (paint->isAntiAlias()) {
1107 proc = SkScan::AntiFillPath;
1109 proc = SkScan::FillPath;
1111 } else { // hairline
1112 if (paint->isAntiAlias()) {
1113 proc = SkScan::AntiHairPath;
1115 proc = SkScan::HairPath;
1118 proc(*devPathPtr, *fRC, blitter);
1121 /** For the purposes of drawing bitmaps, if a matrix is "almost" translate
1122 go ahead and treat it as if it were, so that subsequent code can go fast.
1124 static bool just_translate(const SkMatrix& matrix, const SkBitmap& bitmap) {
1125 unsigned bits = 0; // TODO: find a way to allow the caller to tell us to
1126 // respect filtering.
1127 return SkTreatAsSprite(matrix, bitmap.width(), bitmap.height(), bits);
1130 void SkDraw::drawBitmapAsMask(const SkBitmap& bitmap,
1131 const SkPaint& paint) const {
1132 SkASSERT(bitmap.colorType() == kAlpha_8_SkColorType);
1134 if (just_translate(*fMatrix, bitmap)) {
1135 int ix = SkScalarRoundToInt(fMatrix->getTranslateX());
1136 int iy = SkScalarRoundToInt(fMatrix->getTranslateY());
1138 SkAutoLockPixels alp(bitmap);
1139 if (!bitmap.readyToDraw()) {
1144 mask.fBounds.set(ix, iy, ix + bitmap.width(), iy + bitmap.height());
1145 mask.fFormat = SkMask::kA8_Format;
1146 mask.fRowBytes = SkToU32(bitmap.rowBytes());
1147 mask.fImage = bitmap.getAddr8(0, 0);
1149 this->drawDevMask(mask, paint);
1150 } else { // need to xform the bitmap first
1155 SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height()));
1156 fMatrix->mapRect(&r);
1157 r.round(&mask.fBounds);
1159 // set the mask's bounds to the transformed bitmap-bounds,
1160 // clipped to the actual device
1163 devBounds.set(0, 0, fBitmap->width(), fBitmap->height());
1164 // need intersect(l, t, r, b) on irect
1165 if (!mask.fBounds.intersect(devBounds)) {
1170 mask.fFormat = SkMask::kA8_Format;
1171 mask.fRowBytes = SkAlign4(mask.fBounds.width());
1172 size_t size = mask.computeImageSize();
1174 // the mask is too big to allocated, draw nothing
1178 // allocate (and clear) our temp buffer to hold the transformed bitmap
1179 SkAutoMalloc storage(size);
1180 mask.fImage = (uint8_t*)storage.get();
1181 memset(mask.fImage, 0, size);
1183 // now draw our bitmap(src) into mask(dst), transformed by the matrix
1186 device.installPixels(SkImageInfo::MakeA8(mask.fBounds.width(), mask.fBounds.height()),
1187 mask.fImage, mask.fRowBytes);
1190 // need the unclipped top/left for the translate
1191 c.translate(-SkIntToScalar(mask.fBounds.fLeft),
1192 -SkIntToScalar(mask.fBounds.fTop));
1195 // We can't call drawBitmap, or we'll infinitely recurse. Instead
1196 // we manually build a shader and draw that into our new mask
1198 tmpPaint.setFlags(paint.getFlags());
1199 SkAutoBitmapShaderInstall install(bitmap, tmpPaint);
1201 rr.set(0, 0, SkIntToScalar(bitmap.width()),
1202 SkIntToScalar(bitmap.height()));
1203 c.drawRect(rr, install.paintWithShader());
1205 this->drawDevMask(mask, paint);
1209 static bool clipped_out(const SkMatrix& m, const SkRasterClip& c,
1210 const SkRect& srcR) {
1214 m.mapRect(&dstR, srcR);
1215 dstR.roundOut(&devIR);
1216 return c.quickReject(devIR);
1219 static bool clipped_out(const SkMatrix& matrix, const SkRasterClip& clip,
1220 int width, int height) {
1222 r.set(0, 0, SkIntToScalar(width), SkIntToScalar(height));
1223 return clipped_out(matrix, clip, r);
1226 static bool clipHandlesSprite(const SkRasterClip& clip, int x, int y,
1227 const SkBitmap& bitmap) {
1228 return clip.isBW() ||
1229 clip.quickContains(x, y, x + bitmap.width(), y + bitmap.height());
1232 void SkDraw::drawBitmap(const SkBitmap& bitmap, const SkMatrix& prematrix,
1233 const SkPaint& origPaint) const {
1234 SkDEBUGCODE(this->validate();)
1237 if (fRC->isEmpty() ||
1238 bitmap.width() == 0 || bitmap.height() == 0 ||
1239 bitmap.colorType() == kUnknown_SkColorType) {
1243 SkPaint paint(origPaint);
1244 paint.setStyle(SkPaint::kFill_Style);
1247 matrix.setConcat(*fMatrix, prematrix);
1249 if (clipped_out(matrix, *fRC, bitmap.width(), bitmap.height())) {
1253 if (bitmap.colorType() != kAlpha_8_SkColorType && just_translate(matrix, bitmap)) {
1255 // It is safe to call lock pixels now, since we know the matrix is
1256 // (more or less) identity.
1258 SkAutoLockPixels alp(bitmap);
1259 if (!bitmap.readyToDraw()) {
1262 int ix = SkScalarRoundToInt(matrix.getTranslateX());
1263 int iy = SkScalarRoundToInt(matrix.getTranslateY());
1264 if (clipHandlesSprite(*fRC, ix, iy, bitmap)) {
1265 SkTBlitterAllocator allocator;
1266 // blitter will be owned by the allocator.
1267 SkBlitter* blitter = SkBlitter::ChooseSprite(*fBitmap, paint, bitmap,
1268 ix, iy, &allocator);
1271 ir.set(ix, iy, ix + bitmap.width(), iy + bitmap.height());
1273 SkScan::FillIRect(ir, *fRC, blitter);
1279 // now make a temp draw on the stack, and use it
1282 draw.fMatrix = &matrix;
1284 if (bitmap.colorType() == kAlpha_8_SkColorType) {
1285 draw.drawBitmapAsMask(bitmap, paint);
1287 SkAutoBitmapShaderInstall install(bitmap, paint);
1290 r.set(0, 0, SkIntToScalar(bitmap.width()),
1291 SkIntToScalar(bitmap.height()));
1292 // is this ok if paint has a rasterizer?
1293 draw.drawRect(r, install.paintWithShader());
1297 void SkDraw::drawSprite(const SkBitmap& bitmap, int x, int y,
1298 const SkPaint& origPaint) const {
1299 SkDEBUGCODE(this->validate();)
1302 if (fRC->isEmpty() ||
1303 bitmap.width() == 0 || bitmap.height() == 0 ||
1304 bitmap.colorType() == kUnknown_SkColorType) {
1309 bounds.set(x, y, x + bitmap.width(), y + bitmap.height());
1311 if (fRC->quickReject(bounds)) {
1312 return; // nothing to draw
1315 SkPaint paint(origPaint);
1316 paint.setStyle(SkPaint::kFill_Style);
1318 if (NULL == paint.getColorFilter() && clipHandlesSprite(*fRC, x, y, bitmap)) {
1319 SkTBlitterAllocator allocator;
1320 // blitter will be owned by the allocator.
1321 SkBlitter* blitter = SkBlitter::ChooseSprite(*fBitmap, paint, bitmap,
1325 SkScan::FillIRect(bounds, *fRC, blitter);
1333 // get a scalar version of our rect
1336 // create shader with offset
1337 matrix.setTranslate(r.fLeft, r.fTop);
1338 SkAutoBitmapShaderInstall install(bitmap, paint, &matrix);
1339 const SkPaint& shaderPaint = install.paintWithShader();
1343 draw.fMatrix = &matrix;
1344 // call ourself with a rect
1345 // is this OK if paint has a rasterizer?
1346 draw.drawRect(r, shaderPaint);
1349 ///////////////////////////////////////////////////////////////////////////////
1351 #include "SkScalerContext.h"
1352 #include "SkGlyphCache.h"
1353 #include "SkTextToPathIter.h"
1354 #include "SkUtils.h"
1356 static void measure_text(SkGlyphCache* cache, SkDrawCacheProc glyphCacheProc,
1357 const char text[], size_t byteLength, SkVector* stopVector) {
1358 SkFixed x = 0, y = 0;
1359 const char* stop = text + byteLength;
1361 SkAutoKern autokern;
1363 while (text < stop) {
1364 // don't need x, y here, since all subpixel variants will have the
1366 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0);
1368 x += autokern.adjust(glyph) + glyph.fAdvanceX;
1369 y += glyph.fAdvanceY;
1371 stopVector->set(SkFixedToScalar(x), SkFixedToScalar(y));
1373 SkASSERT(text == stop);
1376 bool SkDraw::ShouldDrawTextAsPaths(const SkPaint& paint, const SkMatrix& ctm) {
1377 // hairline glyphs are fast enough so we don't need to cache them
1378 if (SkPaint::kStroke_Style == paint.getStyle() && 0 == paint.getStrokeWidth()) {
1382 // we don't cache perspective
1383 if (ctm.hasPerspective()) {
1388 return SkPaint::TooBigToUseCache(ctm, *paint.setTextMatrix(&textM));
1391 void SkDraw::drawText_asPaths(const char text[], size_t byteLength,
1392 SkScalar x, SkScalar y,
1393 const SkPaint& paint) const {
1394 SkDEBUGCODE(this->validate();)
1396 SkTextToPathIter iter(text, byteLength, paint, true);
1399 matrix.setScale(iter.getPathScale(), iter.getPathScale());
1400 matrix.postTranslate(x, y);
1402 const SkPath* iterPath;
1403 SkScalar xpos, prevXPos = 0;
1405 while (iter.next(&iterPath, &xpos)) {
1406 matrix.postTranslate(xpos - prevXPos, 0);
1408 const SkPaint& pnt = iter.getPaint();
1410 fDevice->drawPath(*this, *iterPath, pnt, &matrix, false);
1412 this->drawPath(*iterPath, pnt, &matrix, false);
1419 // disable warning : local variable used without having been initialized
1420 #if defined _WIN32 && _MSC_VER >= 1300
1421 #pragma warning ( push )
1422 #pragma warning ( disable : 4701 )
1425 //////////////////////////////////////////////////////////////////////////////
1427 static void D1G_RectClip(const SkDraw1Glyph& state, SkFixed fx, SkFixed fy, const SkGlyph& glyph) {
1428 int left = SkFixedFloorToInt(fx);
1429 int top = SkFixedFloorToInt(fy);
1430 SkASSERT(glyph.fWidth > 0 && glyph.fHeight > 0);
1431 SkASSERT((NULL == state.fClip && state.fAAClip) ||
1432 (state.fClip && NULL == state.fAAClip && state.fClip->isRect()));
1434 left += glyph.fLeft;
1437 int right = left + glyph.fWidth;
1438 int bottom = top + glyph.fHeight;
1442 SkIRect* bounds = &mask.fBounds;
1444 mask.fBounds.set(left, top, right, bottom);
1446 // this extra test is worth it, assuming that most of the time it succeeds
1447 // since we can avoid writing to storage
1448 if (!state.fClipBounds.containsNoEmptyCheck(left, top, right, bottom)) {
1449 if (!storage.intersectNoEmptyCheck(mask.fBounds, state.fClipBounds))
1454 uint8_t* aa = (uint8_t*)glyph.fImage;
1456 aa = (uint8_t*)state.fCache->findImage(glyph);
1458 return; // can't rasterize glyph
1462 mask.fRowBytes = glyph.rowBytes();
1463 mask.fFormat = static_cast<SkMask::Format>(glyph.fMaskFormat);
1465 state.blitMask(mask, *bounds);
1468 static void D1G_RgnClip(const SkDraw1Glyph& state, SkFixed fx, SkFixed fy, const SkGlyph& glyph) {
1469 int left = SkFixedFloorToInt(fx);
1470 int top = SkFixedFloorToInt(fy);
1471 SkASSERT(glyph.fWidth > 0 && glyph.fHeight > 0);
1472 SkASSERT(!state.fClip->isRect());
1476 left += glyph.fLeft;
1479 mask.fBounds.set(left, top, left + glyph.fWidth, top + glyph.fHeight);
1480 SkRegion::Cliperator clipper(*state.fClip, mask.fBounds);
1482 if (!clipper.done()) {
1483 const SkIRect& cr = clipper.rect();
1484 const uint8_t* aa = (const uint8_t*)glyph.fImage;
1486 aa = (uint8_t*)state.fCache->findImage(glyph);
1492 mask.fRowBytes = glyph.rowBytes();
1493 mask.fFormat = static_cast<SkMask::Format>(glyph.fMaskFormat);
1494 mask.fImage = (uint8_t*)aa;
1496 state.blitMask(mask, cr);
1498 } while (!clipper.done());
1502 static bool hasCustomD1GProc(const SkDraw& draw) {
1503 return draw.fProcs && draw.fProcs->fD1GProc;
1506 static bool needsRasterTextBlit(const SkDraw& draw) {
1507 return !hasCustomD1GProc(draw);
1510 SkDraw1Glyph::Proc SkDraw1Glyph::init(const SkDraw* draw, SkBlitter* blitter, SkGlyphCache* cache,
1511 const SkPaint& pnt) {
1517 if (cache->isSubpixel()) {
1518 fHalfSampleX = fHalfSampleY = (SK_FixedHalf >> SkGlyph::kSubBits);
1520 fHalfSampleX = fHalfSampleY = SK_FixedHalf;
1523 if (hasCustomD1GProc(*draw)) {
1524 // todo: fix this assumption about clips w/ custom
1525 fClip = draw->fClip;
1526 fClipBounds = fClip->getBounds();
1527 return draw->fProcs->fD1GProc;
1530 if (draw->fRC->isBW()) {
1532 fClip = &draw->fRC->bwRgn();
1533 fClipBounds = fClip->getBounds();
1534 if (fClip->isRect()) {
1535 return D1G_RectClip;
1540 fAAClip = &draw->fRC->aaRgn();
1542 fClipBounds = fAAClip->getBounds();
1543 return D1G_RectClip;
1547 void SkDraw1Glyph::blitMaskAsSprite(const SkMask& mask) const {
1548 SkASSERT(SkMask::kARGB32_Format == mask.fFormat);
1551 bm.installPixels(SkImageInfo::MakeN32Premul(mask.fBounds.width(), mask.fBounds.height()),
1552 (SkPMColor*)mask.fImage, mask.fRowBytes);
1554 fDraw->drawSprite(bm, mask.fBounds.x(), mask.fBounds.y(), *fPaint);
1557 ///////////////////////////////////////////////////////////////////////////////
1559 void SkDraw::drawText(const char text[], size_t byteLength,
1560 SkScalar x, SkScalar y, const SkPaint& paint) const {
1561 SkASSERT(byteLength == 0 || text != NULL);
1563 SkDEBUGCODE(this->validate();)
1566 if (text == NULL || byteLength == 0 || fRC->isEmpty()) {
1570 // SkScalarRec doesn't currently have a way of representing hairline stroke and
1571 // will fill if its frame-width is 0.
1572 if (ShouldDrawTextAsPaths(paint, *fMatrix)) {
1573 this->drawText_asPaths(text, byteLength, x, y, paint);
1577 SkDrawCacheProc glyphCacheProc = paint.getDrawCacheProc();
1579 SkAutoGlyphCache autoCache(paint, &fDevice->getLeakyProperties(), fMatrix);
1580 SkGlyphCache* cache = autoCache.getCache();
1582 // transform our starting point
1585 fMatrix->mapXY(x, y, &loc);
1590 // need to measure first
1591 if (paint.getTextAlign() != SkPaint::kLeft_Align) {
1594 measure_text(cache, glyphCacheProc, text, byteLength, &stop);
1596 SkScalar stopX = stop.fX;
1597 SkScalar stopY = stop.fY;
1599 if (paint.getTextAlign() == SkPaint::kCenter_Align) {
1600 stopX = SkScalarHalf(stopX);
1601 stopY = SkScalarHalf(stopY);
1607 const char* stop = text + byteLength;
1609 SkAAClipBlitter aaBlitter;
1610 SkAutoBlitterChoose blitterChooser;
1611 SkBlitter* blitter = NULL;
1612 if (needsRasterTextBlit(*this)) {
1613 blitterChooser.choose(*fBitmap, *fMatrix, paint);
1614 blitter = blitterChooser.get();
1616 aaBlitter.init(blitter, &fRC->aaRgn());
1617 blitter = &aaBlitter;
1621 SkAutoKern autokern;
1623 SkDraw1Glyph::Proc proc = d1g.init(this, blitter, cache, paint);
1625 SkFixed fxMask = ~0;
1626 SkFixed fyMask = ~0;
1627 if (cache->isSubpixel()) {
1628 SkAxisAlignment baseline = SkComputeAxisAlignmentForHText(*fMatrix);
1629 if (kX_SkAxisAlignment == baseline) {
1631 d1g.fHalfSampleY = SK_FixedHalf;
1632 } else if (kY_SkAxisAlignment == baseline) {
1634 d1g.fHalfSampleX = SK_FixedHalf;
1638 SkFixed fx = SkScalarToFixed(x) + d1g.fHalfSampleX;
1639 SkFixed fy = SkScalarToFixed(y) + d1g.fHalfSampleY;
1641 while (text < stop) {
1642 const SkGlyph& glyph = glyphCacheProc(cache, &text, fx & fxMask, fy & fyMask);
1644 fx += autokern.adjust(glyph);
1647 proc(d1g, fx, fy, glyph);
1650 fx += glyph.fAdvanceX;
1651 fy += glyph.fAdvanceY;
1655 //////////////////////////////////////////////////////////////////////////////
1657 void SkDraw::drawPosText_asPaths(const char text[], size_t byteLength,
1658 const SkScalar pos[], SkScalar constY,
1659 int scalarsPerPosition,
1660 const SkPaint& origPaint) const {
1661 // setup our std paint, in hopes of getting hits in the cache
1662 SkPaint paint(origPaint);
1663 SkScalar matrixScale = paint.setupForAsPaths();
1666 matrix.setScale(matrixScale, matrixScale);
1668 // Temporarily jam in kFill, so we only ever ask for the raw outline from the cache.
1669 paint.setStyle(SkPaint::kFill_Style);
1670 paint.setPathEffect(NULL);
1672 SkDrawCacheProc glyphCacheProc = paint.getDrawCacheProc();
1673 SkAutoGlyphCache autoCache(paint, NULL, NULL);
1674 SkGlyphCache* cache = autoCache.getCache();
1676 const char* stop = text + byteLength;
1677 SkTextAlignProcScalar alignProc(paint.getTextAlign());
1678 SkTextMapStateProc tmsProc(SkMatrix::I(), constY, scalarsPerPosition);
1680 // Now restore the original settings, so we "draw" with whatever style/stroking.
1681 paint.setStyle(origPaint.getStyle());
1682 paint.setPathEffect(origPaint.getPathEffect());
1684 while (text < stop) {
1685 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0);
1687 const SkPath* path = cache->findPath(glyph);
1690 tmsProc(pos, &tmsLoc);
1692 alignProc(tmsLoc, glyph, &loc);
1694 matrix[SkMatrix::kMTransX] = loc.fX;
1695 matrix[SkMatrix::kMTransY] = loc.fY;
1697 fDevice->drawPath(*this, *path, paint, &matrix, false);
1699 this->drawPath(*path, paint, &matrix, false);
1703 pos += scalarsPerPosition;
1707 void SkDraw::drawPosText(const char text[], size_t byteLength,
1708 const SkScalar pos[], SkScalar constY,
1709 int scalarsPerPosition, const SkPaint& paint) const {
1710 SkASSERT(byteLength == 0 || text != NULL);
1711 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
1713 SkDEBUGCODE(this->validate();)
1716 if (text == NULL || byteLength == 0 || fRC->isEmpty()) {
1720 if (ShouldDrawTextAsPaths(paint, *fMatrix)) {
1721 this->drawPosText_asPaths(text, byteLength, pos, constY,
1722 scalarsPerPosition, paint);
1726 SkDrawCacheProc glyphCacheProc = paint.getDrawCacheProc();
1727 SkAutoGlyphCache autoCache(paint, &fDevice->getLeakyProperties(), fMatrix);
1728 SkGlyphCache* cache = autoCache.getCache();
1730 SkAAClipBlitterWrapper wrapper;
1731 SkAutoBlitterChoose blitterChooser;
1732 SkBlitter* blitter = NULL;
1733 if (needsRasterTextBlit(*this)) {
1734 blitterChooser.choose(*fBitmap, *fMatrix, paint);
1735 blitter = blitterChooser.get();
1737 wrapper.init(*fRC, blitter);
1738 blitter = wrapper.getBlitter();
1742 const char* stop = text + byteLength;
1743 SkTextAlignProc alignProc(paint.getTextAlign());
1745 SkDraw1Glyph::Proc proc = d1g.init(this, blitter, cache, paint);
1746 SkTextMapStateProc tmsProc(*fMatrix, constY, scalarsPerPosition);
1748 if (cache->isSubpixel()) {
1749 // maybe we should skip the rounding if linearText is set
1750 SkAxisAlignment baseline = SkComputeAxisAlignmentForHText(*fMatrix);
1752 SkFixed fxMask = ~0;
1753 SkFixed fyMask = ~0;
1754 if (kX_SkAxisAlignment == baseline) {
1756 #ifndef SK_IGNORE_SUBPIXEL_AXIS_ALIGN_FIX
1757 d1g.fHalfSampleY = SK_FixedHalf;
1759 } else if (kY_SkAxisAlignment == baseline) {
1761 #ifndef SK_IGNORE_SUBPIXEL_AXIS_ALIGN_FIX
1762 d1g.fHalfSampleX = SK_FixedHalf;
1766 if (SkPaint::kLeft_Align == paint.getTextAlign()) {
1767 while (text < stop) {
1769 tmsProc(pos, &tmsLoc);
1770 SkFixed fx = SkScalarToFixed(tmsLoc.fX) + d1g.fHalfSampleX;
1771 SkFixed fy = SkScalarToFixed(tmsLoc.fY) + d1g.fHalfSampleY;
1773 const SkGlyph& glyph = glyphCacheProc(cache, &text,
1774 fx & fxMask, fy & fyMask);
1777 proc(d1g, fx, fy, glyph);
1779 pos += scalarsPerPosition;
1782 while (text < stop) {
1783 const char* currentText = text;
1784 const SkGlyph& metricGlyph = glyphCacheProc(cache, &text, 0, 0);
1786 if (metricGlyph.fWidth) {
1787 SkDEBUGCODE(SkFixed prevAdvX = metricGlyph.fAdvanceX;)
1788 SkDEBUGCODE(SkFixed prevAdvY = metricGlyph.fAdvanceY;)
1790 tmsProc(pos, &tmsLoc);
1792 alignProc(tmsLoc, metricGlyph, &fixedLoc);
1794 SkFixed fx = fixedLoc.fX + d1g.fHalfSampleX;
1795 SkFixed fy = fixedLoc.fY + d1g.fHalfSampleY;
1797 // have to call again, now that we've been "aligned"
1798 const SkGlyph& glyph = glyphCacheProc(cache, ¤tText,
1799 fx & fxMask, fy & fyMask);
1800 // the assumption is that the metrics haven't changed
1801 SkASSERT(prevAdvX == glyph.fAdvanceX);
1802 SkASSERT(prevAdvY == glyph.fAdvanceY);
1803 SkASSERT(glyph.fWidth);
1805 proc(d1g, fx, fy, glyph);
1807 pos += scalarsPerPosition;
1810 } else { // not subpixel
1811 if (SkPaint::kLeft_Align == paint.getTextAlign()) {
1812 while (text < stop) {
1813 // the last 2 parameters are ignored
1814 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0);
1818 tmsProc(pos, &tmsLoc);
1821 SkScalarToFixed(tmsLoc.fX) + SK_FixedHalf, //d1g.fHalfSampleX,
1822 SkScalarToFixed(tmsLoc.fY) + SK_FixedHalf, //d1g.fHalfSampleY,
1825 pos += scalarsPerPosition;
1828 while (text < stop) {
1829 // the last 2 parameters are ignored
1830 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0);
1834 tmsProc(pos, &tmsLoc);
1837 alignProc(tmsLoc, glyph, &fixedLoc);
1840 fixedLoc.fX + SK_FixedHalf, //d1g.fHalfSampleX,
1841 fixedLoc.fY + SK_FixedHalf, //d1g.fHalfSampleY,
1844 pos += scalarsPerPosition;
1850 #if defined _WIN32 && _MSC_VER >= 1300
1851 #pragma warning ( pop )
1854 ///////////////////////////////////////////////////////////////////////////////
1856 #include "SkPathMeasure.h"
1858 static void morphpoints(SkPoint dst[], const SkPoint src[], int count,
1859 SkPathMeasure& meas, const SkMatrix& matrix) {
1860 SkMatrix::MapXYProc proc = matrix.getMapXYProc();
1862 for (int i = 0; i < count; i++) {
1866 proc(matrix, src[i].fX, src[i].fY, &pos);
1867 SkScalar sx = pos.fX;
1868 SkScalar sy = pos.fY;
1870 if (!meas.getPosTan(sx, &pos, &tangent)) {
1871 // set to 0 if the measure failed, so that we just set dst == pos
1875 /* This is the old way (that explains our approach but is way too slow
1880 matrix.setSinCos(tangent.fY, tangent.fX);
1881 matrix.preTranslate(-sx, 0);
1882 matrix.postTranslate(pos.fX, pos.fY);
1883 matrix.mapPoints(&dst[i], &pt, 1);
1885 dst[i].set(pos.fX - SkScalarMul(tangent.fY, sy),
1886 pos.fY + SkScalarMul(tangent.fX, sy));
1892 Need differentially more subdivisions when the follow-path is curvy. Not sure how to
1893 determine that, but we need it. I guess a cheap answer is let the caller tell us,
1894 but that seems like a cop-out. Another answer is to get Rob Johnson to figure it out.
1896 static void morphpath(SkPath* dst, const SkPath& src, SkPathMeasure& meas,
1897 const SkMatrix& matrix) {
1898 SkPath::Iter iter(src, false);
1899 SkPoint srcP[4], dstP[3];
1902 while ((verb = iter.next(srcP)) != SkPath::kDone_Verb) {
1904 case SkPath::kMove_Verb:
1905 morphpoints(dstP, srcP, 1, meas, matrix);
1906 dst->moveTo(dstP[0]);
1908 case SkPath::kLine_Verb:
1909 // turn lines into quads to look bendy
1910 srcP[0].fX = SkScalarAve(srcP[0].fX, srcP[1].fX);
1911 srcP[0].fY = SkScalarAve(srcP[0].fY, srcP[1].fY);
1912 morphpoints(dstP, srcP, 2, meas, matrix);
1913 dst->quadTo(dstP[0], dstP[1]);
1915 case SkPath::kQuad_Verb:
1916 morphpoints(dstP, &srcP[1], 2, meas, matrix);
1917 dst->quadTo(dstP[0], dstP[1]);
1919 case SkPath::kCubic_Verb:
1920 morphpoints(dstP, &srcP[1], 3, meas, matrix);
1921 dst->cubicTo(dstP[0], dstP[1], dstP[2]);
1923 case SkPath::kClose_Verb:
1927 SkDEBUGFAIL("unknown verb");
1933 void SkDraw::drawTextOnPath(const char text[], size_t byteLength,
1934 const SkPath& follow, const SkMatrix* matrix,
1935 const SkPaint& paint) const {
1936 SkASSERT(byteLength == 0 || text != NULL);
1939 if (text == NULL || byteLength == 0 || fRC->isEmpty()) {
1943 SkTextToPathIter iter(text, byteLength, paint, true);
1944 SkPathMeasure meas(follow, false);
1945 SkScalar hOffset = 0;
1947 // need to measure first
1948 if (paint.getTextAlign() != SkPaint::kLeft_Align) {
1949 SkScalar pathLen = meas.getLength();
1950 if (paint.getTextAlign() == SkPaint::kCenter_Align) {
1951 pathLen = SkScalarHalf(pathLen);
1956 const SkPath* iterPath;
1958 SkMatrix scaledMatrix;
1959 SkScalar scale = iter.getPathScale();
1961 scaledMatrix.setScale(scale, scale);
1963 while (iter.next(&iterPath, &xpos)) {
1966 SkMatrix m(scaledMatrix);
1968 m.postTranslate(xpos + hOffset, 0);
1970 m.postConcat(*matrix);
1972 morphpath(&tmp, *iterPath, meas, m);
1974 fDevice->drawPath(*this, tmp, iter.getPaint(), NULL, true);
1976 this->drawPath(tmp, iter.getPaint(), NULL, true);
1982 ///////////////////////////////////////////////////////////////////////////////
1984 typedef void (*HairProc)(const SkPoint&, const SkPoint&, const SkRasterClip&,
1987 static HairProc ChooseHairProc(bool doAntiAlias) {
1988 return doAntiAlias ? SkScan::AntiHairLine : SkScan::HairLine;
1991 static bool texture_to_matrix(const VertState& state, const SkPoint verts[],
1992 const SkPoint texs[], SkMatrix* matrix) {
1993 SkPoint src[3], dst[3];
1995 src[0] = texs[state.f0];
1996 src[1] = texs[state.f1];
1997 src[2] = texs[state.f2];
1998 dst[0] = verts[state.f0];
1999 dst[1] = verts[state.f1];
2000 dst[2] = verts[state.f2];
2001 return matrix->setPolyToPoly(src, dst, 3);
2004 class SkTriColorShader : public SkShader {
2006 SkTriColorShader() {}
2008 virtual size_t contextSize() const SK_OVERRIDE;
2010 class TriColorShaderContext : public SkShader::Context {
2012 TriColorShaderContext(const SkTriColorShader& shader, const ContextRec&);
2013 virtual ~TriColorShaderContext();
2015 bool setup(const SkPoint pts[], const SkColor colors[], int, int, int);
2017 virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count) SK_OVERRIDE;
2020 SkMatrix fDstToUnit;
2021 SkPMColor fColors[3];
2023 typedef SkShader::Context INHERITED;
2026 SK_TO_STRING_OVERRIDE()
2027 SK_DECLARE_NOT_FLATTENABLE_PROCS(SkTriColorShader)
2030 virtual Context* onCreateContext(const ContextRec& rec, void* storage) const SK_OVERRIDE {
2031 return SkNEW_PLACEMENT_ARGS(storage, TriColorShaderContext, (*this, rec));
2035 typedef SkShader INHERITED;
2038 bool SkTriColorShader::TriColorShaderContext::setup(const SkPoint pts[], const SkColor colors[],
2039 int index0, int index1, int index2) {
2041 fColors[0] = SkPreMultiplyColor(colors[index0]);
2042 fColors[1] = SkPreMultiplyColor(colors[index1]);
2043 fColors[2] = SkPreMultiplyColor(colors[index2]);
2047 m.set(0, pts[index1].fX - pts[index0].fX);
2048 m.set(1, pts[index2].fX - pts[index0].fX);
2049 m.set(2, pts[index0].fX);
2050 m.set(3, pts[index1].fY - pts[index0].fY);
2051 m.set(4, pts[index2].fY - pts[index0].fY);
2052 m.set(5, pts[index0].fY);
2053 if (!m.invert(&im)) {
2056 // We can't call getTotalInverse(), because we explicitly don't want to look at the localmatrix
2057 // as our interators are intrinsically tied to the vertices, and nothing else.
2059 if (!this->getCTM().invert(&ctmInv)) {
2062 fDstToUnit.setConcat(im, ctmInv);
2066 #include "SkColorPriv.h"
2067 #include "SkComposeShader.h"
2069 static int ScalarTo256(SkScalar v) {
2070 int scale = SkScalarToFixed(v) >> 8;
2077 return SkAlpha255To256(scale);
2081 SkTriColorShader::TriColorShaderContext::TriColorShaderContext(const SkTriColorShader& shader,
2082 const ContextRec& rec)
2083 : INHERITED(shader, rec) {}
2085 SkTriColorShader::TriColorShaderContext::~TriColorShaderContext() {}
2087 size_t SkTriColorShader::contextSize() const {
2088 return sizeof(TriColorShaderContext);
2090 void SkTriColorShader::TriColorShaderContext::shadeSpan(int x, int y, SkPMColor dstC[], int count) {
2091 const int alphaScale = Sk255To256(this->getPaintAlpha());
2095 for (int i = 0; i < count; i++) {
2096 fDstToUnit.mapXY(SkIntToScalar(x), SkIntToScalar(y), &src);
2099 int scale1 = ScalarTo256(src.fX);
2100 int scale2 = ScalarTo256(src.fY);
2101 int scale0 = 256 - scale1 - scale2;
2103 if (scale1 > scale2) {
2104 scale2 = 256 - scale1;
2106 scale1 = 256 - scale2;
2111 if (256 != alphaScale) {
2112 scale0 = SkAlphaMul(scale0, alphaScale);
2113 scale1 = SkAlphaMul(scale1, alphaScale);
2114 scale2 = SkAlphaMul(scale2, alphaScale);
2117 dstC[i] = SkAlphaMulQ(fColors[0], scale0) +
2118 SkAlphaMulQ(fColors[1], scale1) +
2119 SkAlphaMulQ(fColors[2], scale2);
2123 #ifndef SK_IGNORE_TO_STRING
2124 void SkTriColorShader::toString(SkString* str) const {
2125 str->append("SkTriColorShader: (");
2127 this->INHERITED::toString(str);
2133 void SkDraw::drawVertices(SkCanvas::VertexMode vmode, int count,
2134 const SkPoint vertices[], const SkPoint textures[],
2135 const SkColor colors[], SkXfermode* xmode,
2136 const uint16_t indices[], int indexCount,
2137 const SkPaint& paint) const {
2138 SkASSERT(0 == count || vertices);
2140 // abort early if there is nothing to draw
2141 if (count < 3 || (indices && indexCount < 3) || fRC->isEmpty()) {
2145 // transform out vertices into device coordinates
2146 SkAutoSTMalloc<16, SkPoint> storage(count);
2147 SkPoint* devVerts = storage.get();
2148 fMatrix->mapPoints(devVerts, vertices, count);
2151 We can draw the vertices in 1 of 4 ways:
2153 - solid color (no shader/texture[], no colors[])
2154 - just colors (no shader/texture[], has colors[])
2155 - just texture (has shader/texture[], no colors[])
2156 - colors * texture (has shader/texture[], has colors[])
2158 Thus for texture drawing, we need both texture[] and a shader.
2161 SkTriColorShader triShader; // must be above declaration of p
2164 SkShader* shader = p.getShader();
2165 if (NULL == shader) {
2166 // if we have no shader, we ignore the texture coordinates
2168 } else if (NULL == textures) {
2169 // if we don't have texture coordinates, ignore the shader
2174 // setup the custom shader (if needed)
2175 SkAutoTUnref<SkComposeShader> composeShader;
2177 if (NULL == textures) {
2178 // just colors (no texture)
2179 shader = p.setShader(&triShader);
2183 bool releaseMode = false;
2184 if (NULL == xmode) {
2185 xmode = SkXfermode::Create(SkXfermode::kModulate_Mode);
2188 composeShader.reset(SkNEW_ARGS(SkComposeShader, (&triShader, shader, xmode)));
2189 p.setShader(composeShader);
2196 SkAutoBlitterChoose blitter(*fBitmap, *fMatrix, p);
2197 // Abort early if we failed to create a shader context.
2198 if (blitter->isNullBlitter()) {
2202 // setup our state and function pointer for iterating triangles
2203 VertState state(count, indices, indexCount);
2204 VertState::Proc vertProc = state.chooseProc(vmode);
2206 if (textures || colors) {
2207 while (vertProc(&state)) {
2210 if (texture_to_matrix(state, vertices, textures, &tempM)) {
2211 SkShader::ContextRec rec(*fBitmap, p, *fMatrix);
2212 rec.fLocalMatrix = &tempM;
2213 if (!blitter->resetShaderContext(rec)) {
2219 // Find the context for triShader.
2220 SkTriColorShader::TriColorShaderContext* triColorShaderContext;
2222 SkShader::Context* shaderContext = blitter->getShaderContext();
2223 SkASSERT(shaderContext);
2224 if (p.getShader() == &triShader) {
2225 triColorShaderContext =
2226 static_cast<SkTriColorShader::TriColorShaderContext*>(shaderContext);
2228 // The shader is a compose shader and triShader is its first shader.
2229 SkASSERT(p.getShader() == composeShader);
2230 SkASSERT(composeShader->getShaderA() == &triShader);
2231 SkComposeShader::ComposeShaderContext* composeShaderContext =
2232 static_cast<SkComposeShader::ComposeShaderContext*>(shaderContext);
2233 SkShader::Context* shaderContextA = composeShaderContext->getShaderContextA();
2234 triColorShaderContext =
2235 static_cast<SkTriColorShader::TriColorShaderContext*>(shaderContextA);
2238 if (!triColorShaderContext->setup(vertices, colors,
2239 state.f0, state.f1, state.f2)) {
2245 devVerts[state.f0], devVerts[state.f1], devVerts[state.f2]
2247 SkScan::FillTriangle(tmp, *fRC, blitter.get());
2250 // no colors[] and no texture, stroke hairlines with paint's color.
2251 HairProc hairProc = ChooseHairProc(paint.isAntiAlias());
2252 const SkRasterClip& clip = *fRC;
2253 while (vertProc(&state)) {
2254 hairProc(devVerts[state.f0], devVerts[state.f1], clip, blitter.get());
2255 hairProc(devVerts[state.f1], devVerts[state.f2], clip, blitter.get());
2256 hairProc(devVerts[state.f2], devVerts[state.f0], clip, blitter.get());
2261 ///////////////////////////////////////////////////////////////////////////////
2262 ///////////////////////////////////////////////////////////////////////////////
2266 void SkDraw::validate() const {
2267 SkASSERT(fBitmap != NULL);
2268 SkASSERT(fMatrix != NULL);
2269 SkASSERT(fClip != NULL);
2270 SkASSERT(fRC != NULL);
2272 const SkIRect& cr = fRC->getBounds();
2275 br.set(0, 0, fBitmap->width(), fBitmap->height());
2276 SkASSERT(cr.isEmpty() || br.contains(cr));
2281 ////////////////////////////////////////////////////////////////////////////////////////////////
2285 #include "SkRegion.h"
2286 #include "SkBlitter.h"
2288 static bool compute_bounds(const SkPath& devPath, const SkIRect* clipBounds,
2289 const SkMaskFilter* filter, const SkMatrix* filterMatrix,
2291 if (devPath.isEmpty()) {
2295 // init our bounds from the path
2297 SkRect pathBounds = devPath.getBounds();
2298 pathBounds.inset(-SK_ScalarHalf, -SK_ScalarHalf);
2299 pathBounds.roundOut(bounds);
2302 SkIPoint margin = SkIPoint::Make(0, 0);
2304 SkASSERT(filterMatrix);
2308 srcM.fBounds = *bounds;
2309 srcM.fFormat = SkMask::kA8_Format;
2311 if (!filter->filterMask(&dstM, srcM, *filterMatrix, &margin)) {
2316 // (possibly) trim the bounds to reflect the clip
2317 // (plus whatever slop the filter needs)
2319 SkIRect tmp = *clipBounds;
2320 // Ugh. Guard against gigantic margins from wacky filters. Without this
2321 // check we can request arbitrary amounts of slop beyond our visible
2322 // clip, and bring down the renderer (at least on finite RAM machines
2323 // like handsets, etc.). Need to balance this invented value between
2324 // quality of large filters like blurs, and the corresponding memory
2326 static const int MAX_MARGIN = 128;
2327 tmp.inset(-SkMin32(margin.fX, MAX_MARGIN),
2328 -SkMin32(margin.fY, MAX_MARGIN));
2329 if (!bounds->intersect(tmp)) {
2337 static void draw_into_mask(const SkMask& mask, const SkPath& devPath,
2338 SkPaint::Style style) {
2345 bm.installPixels(SkImageInfo::MakeA8(mask.fBounds.width(), mask.fBounds.height()),
2346 mask.fImage, mask.fRowBytes);
2348 clip.setRect(SkIRect::MakeWH(mask.fBounds.width(), mask.fBounds.height()));
2349 matrix.setTranslate(-SkIntToScalar(mask.fBounds.fLeft),
2350 -SkIntToScalar(mask.fBounds.fTop));
2354 draw.fClip = &clip.bwRgn();
2355 draw.fMatrix = &matrix;
2356 paint.setAntiAlias(true);
2357 paint.setStyle(style);
2358 draw.drawPath(devPath, paint);
2361 bool SkDraw::DrawToMask(const SkPath& devPath, const SkIRect* clipBounds,
2362 const SkMaskFilter* filter, const SkMatrix* filterMatrix,
2363 SkMask* mask, SkMask::CreateMode mode,
2364 SkPaint::Style style) {
2365 if (SkMask::kJustRenderImage_CreateMode != mode) {
2366 if (!compute_bounds(devPath, clipBounds, filter, filterMatrix, &mask->fBounds))
2370 if (SkMask::kComputeBoundsAndRenderImage_CreateMode == mode) {
2371 mask->fFormat = SkMask::kA8_Format;
2372 mask->fRowBytes = mask->fBounds.width();
2373 size_t size = mask->computeImageSize();
2375 // we're too big to allocate the mask, abort
2378 mask->fImage = SkMask::AllocImage(size);
2379 memset(mask->fImage, 0, mask->computeImageSize());
2382 if (SkMask::kJustComputeBounds_CreateMode != mode) {
2383 draw_into_mask(*mask, devPath, style);