3 * Copyright 2006 The Android Open Source Project
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
10 #include "SkBlitter.h"
11 #include "SkAntiRun.h"
13 #include "SkColorFilter.h"
14 #include "SkFilterShader.h"
15 #include "SkReadBuffer.h"
16 #include "SkWriteBuffer.h"
18 #include "SkMaskFilter.h"
19 #include "SkTemplatesPriv.h"
22 #include "SkXfermode.h"
25 SkBlitter::~SkBlitter() {}
27 bool SkBlitter::isNullBlitter() const { return false; }
29 const SkBitmap* SkBlitter::justAnOpaqueColor(uint32_t* value) {
33 void SkBlitter::blitH(int x, int y, int width) {
34 SkDEBUGFAIL("unimplemented");
37 void SkBlitter::blitAntiH(int x, int y, const SkAlpha antialias[],
38 const int16_t runs[]) {
39 SkDEBUGFAIL("unimplemented");
42 void SkBlitter::blitV(int x, int y, int height, SkAlpha alpha) {
44 this->blitRect(x, y, 1, height);
50 while (--height >= 0) {
51 this->blitAntiH(x, y++, &alpha, runs);
56 void SkBlitter::blitRect(int x, int y, int width, int height) {
58 while (--height >= 0) {
59 this->blitH(x, y++, width);
63 /// Default implementation doesn't check for any easy optimizations
64 /// such as alpha == 0 or 255; also uses blitV(), which some subclasses
66 void SkBlitter::blitAntiRect(int x, int y, int width, int height,
67 SkAlpha leftAlpha, SkAlpha rightAlpha) {
68 this->blitV(x++, y, height, leftAlpha);
70 this->blitRect(x, y, width, height);
73 this->blitV(x, y, height, rightAlpha);
76 //////////////////////////////////////////////////////////////////////////////
78 static inline void bits_to_runs(SkBlitter* blitter, int x, int y,
80 U8CPU left_mask, int rowBytes,
85 while (--rowBytes >= 0) {
86 unsigned b = *bits++ & left_mask;
91 for (unsigned test = 0x80; test != 0; test >>= 1) {
99 blitter->blitH(pos, y, x - pos);
110 blitter->blitH(pos, y, x - pos);
114 void SkBlitter::blitMask(const SkMask& mask, const SkIRect& clip) {
115 SkASSERT(mask.fBounds.contains(clip));
117 if (mask.fFormat == SkMask::kBW_Format) {
120 int maskLeft = mask.fBounds.fLeft;
121 int mask_rowBytes = mask.fRowBytes;
122 int height = clip.height();
124 const uint8_t* bits = mask.getAddr1(cx, cy);
126 if (cx == maskLeft && clip.fRight == mask.fBounds.fRight) {
127 while (--height >= 0) {
128 bits_to_runs(this, cx, cy, bits, 0xFF, mask_rowBytes, 0xFF);
129 bits += mask_rowBytes;
133 int left_edge = cx - maskLeft;
134 SkASSERT(left_edge >= 0);
135 int rite_edge = clip.fRight - maskLeft;
136 SkASSERT(rite_edge > left_edge);
138 int left_mask = 0xFF >> (left_edge & 7);
139 int rite_mask = 0xFF << (8 - (rite_edge & 7));
140 int full_runs = (rite_edge >> 3) - ((left_edge + 7) >> 3);
142 // check for empty right mask, so we don't read off the end (or go slower than we need to)
143 if (rite_mask == 0) {
144 SkASSERT(full_runs >= 0);
148 if (left_mask == 0xFF) {
152 // back up manually so we can keep in sync with our byte-aligned src
153 // have cx reflect our actual starting x-coord
157 SkASSERT((left_mask & rite_mask) != 0);
158 while (--height >= 0) {
159 bits_to_runs(this, cx, cy, bits, left_mask, 1, rite_mask);
160 bits += mask_rowBytes;
164 while (--height >= 0) {
165 bits_to_runs(this, cx, cy, bits, left_mask, full_runs + 2, rite_mask);
166 bits += mask_rowBytes;
172 int width = clip.width();
173 SkAutoSTMalloc<64, int16_t> runStorage(width + 1);
174 int16_t* runs = runStorage.get();
175 const uint8_t* aa = mask.getAddr8(clip.fLeft, clip.fTop);
177 sk_memset16((uint16_t*)runs, 1, width);
180 int height = clip.height();
182 while (--height >= 0) {
183 this->blitAntiH(clip.fLeft, y, aa, runs);
184 aa += mask.fRowBytes;
190 /////////////////////// these guys are not virtual, just a helpers
192 void SkBlitter::blitMaskRegion(const SkMask& mask, const SkRegion& clip) {
193 if (clip.quickReject(mask.fBounds)) {
197 SkRegion::Cliperator clipper(clip, mask.fBounds);
199 while (!clipper.done()) {
200 const SkIRect& cr = clipper.rect();
201 this->blitMask(mask, cr);
206 void SkBlitter::blitRectRegion(const SkIRect& rect, const SkRegion& clip) {
207 SkRegion::Cliperator clipper(clip, rect);
209 while (!clipper.done()) {
210 const SkIRect& cr = clipper.rect();
211 this->blitRect(cr.fLeft, cr.fTop, cr.width(), cr.height());
216 void SkBlitter::blitRegion(const SkRegion& clip) {
217 SkRegion::Iterator iter(clip);
219 while (!iter.done()) {
220 const SkIRect& cr = iter.rect();
221 this->blitRect(cr.fLeft, cr.fTop, cr.width(), cr.height());
226 ///////////////////////////////////////////////////////////////////////////////
228 void SkNullBlitter::blitH(int x, int y, int width) {}
230 void SkNullBlitter::blitAntiH(int x, int y, const SkAlpha antialias[],
231 const int16_t runs[]) {}
233 void SkNullBlitter::blitV(int x, int y, int height, SkAlpha alpha) {}
235 void SkNullBlitter::blitRect(int x, int y, int width, int height) {}
237 void SkNullBlitter::blitMask(const SkMask& mask, const SkIRect& clip) {}
239 const SkBitmap* SkNullBlitter::justAnOpaqueColor(uint32_t* value) {
243 bool SkNullBlitter::isNullBlitter() const { return true; }
245 ///////////////////////////////////////////////////////////////////////////////
247 static int compute_anti_width(const int16_t runs[]) {
253 SkASSERT(count >= 0);
263 static inline bool y_in_rect(int y, const SkIRect& rect) {
264 return (unsigned)(y - rect.fTop) < (unsigned)rect.height();
267 static inline bool x_in_rect(int x, const SkIRect& rect) {
268 return (unsigned)(x - rect.fLeft) < (unsigned)rect.width();
271 void SkRectClipBlitter::blitH(int left, int y, int width) {
274 if (!y_in_rect(y, fClipRect)) {
278 int right = left + width;
280 if (left < fClipRect.fLeft) {
281 left = fClipRect.fLeft;
283 if (right > fClipRect.fRight) {
284 right = fClipRect.fRight;
287 width = right - left;
289 fBlitter->blitH(left, y, width);
293 void SkRectClipBlitter::blitAntiH(int left, int y, const SkAlpha aa[],
294 const int16_t runs[]) {
295 if (!y_in_rect(y, fClipRect) || left >= fClipRect.fRight) {
300 int x1 = left + compute_anti_width(runs);
302 if (x1 <= fClipRect.fLeft) {
307 if (x0 < fClipRect.fLeft) {
308 int dx = fClipRect.fLeft - x0;
309 SkAlphaRuns::BreakAt((int16_t*)runs, (uint8_t*)aa, dx);
312 x0 = fClipRect.fLeft;
315 SkASSERT(x0 < x1 && runs[x1 - x0] == 0);
316 if (x1 > fClipRect.fRight) {
317 x1 = fClipRect.fRight;
318 SkAlphaRuns::BreakAt((int16_t*)runs, (uint8_t*)aa, x1 - x0);
319 ((int16_t*)runs)[x1 - x0] = 0;
322 SkASSERT(x0 < x1 && runs[x1 - x0] == 0);
323 SkASSERT(compute_anti_width(runs) == x1 - x0);
325 fBlitter->blitAntiH(x0, y, aa, runs);
328 void SkRectClipBlitter::blitV(int x, int y, int height, SkAlpha alpha) {
329 SkASSERT(height > 0);
331 if (!x_in_rect(x, fClipRect)) {
338 if (y0 < fClipRect.fTop) {
341 if (y1 > fClipRect.fBottom) {
342 y1 = fClipRect.fBottom;
346 fBlitter->blitV(x, y0, y1 - y0, alpha);
350 void SkRectClipBlitter::blitRect(int left, int y, int width, int height) {
353 r.set(left, y, left + width, y + height);
354 if (r.intersect(fClipRect)) {
355 fBlitter->blitRect(r.fLeft, r.fTop, r.width(), r.height());
359 void SkRectClipBlitter::blitAntiRect(int left, int y, int width, int height,
360 SkAlpha leftAlpha, SkAlpha rightAlpha) {
363 // The *true* width of the rectangle blitted is width+2:
364 r.set(left, y, left + width + 2, y + height);
365 if (r.intersect(fClipRect)) {
366 if (r.fLeft != left) {
367 SkASSERT(r.fLeft > left);
370 if (r.fRight != left + width + 2) {
371 SkASSERT(r.fRight < left + width + 2);
374 if (255 == leftAlpha && 255 == rightAlpha) {
375 fBlitter->blitRect(r.fLeft, r.fTop, r.width(), r.height());
376 } else if (1 == r.width()) {
377 if (r.fLeft == left) {
378 fBlitter->blitV(r.fLeft, r.fTop, r.height(), leftAlpha);
380 SkASSERT(r.fLeft == left + width + 1);
381 fBlitter->blitV(r.fLeft, r.fTop, r.height(), rightAlpha);
384 fBlitter->blitAntiRect(r.fLeft, r.fTop, r.width() - 2, r.height(),
385 leftAlpha, rightAlpha);
390 void SkRectClipBlitter::blitMask(const SkMask& mask, const SkIRect& clip) {
391 SkASSERT(mask.fBounds.contains(clip));
395 if (r.intersect(fClipRect)) {
396 fBlitter->blitMask(mask, r);
400 const SkBitmap* SkRectClipBlitter::justAnOpaqueColor(uint32_t* value) {
401 return fBlitter->justAnOpaqueColor(value);
404 ///////////////////////////////////////////////////////////////////////////////
406 void SkRgnClipBlitter::blitH(int x, int y, int width) {
407 SkRegion::Spanerator span(*fRgn, y, x, x + width);
410 while (span.next(&left, &right)) {
411 SkASSERT(left < right);
412 fBlitter->blitH(left, y, right - left);
416 void SkRgnClipBlitter::blitAntiH(int x, int y, const SkAlpha aa[],
417 const int16_t runs[]) {
418 int width = compute_anti_width(runs);
419 SkRegion::Spanerator span(*fRgn, y, x, x + width);
421 SkDEBUGCODE(const SkIRect& bounds = fRgn->getBounds();)
424 while (span.next(&left, &right)) {
426 SkASSERT(left < right);
427 SkASSERT(left >= bounds.fLeft && right <= bounds.fRight);
429 SkAlphaRuns::Break((int16_t*)runs, (uint8_t*)aa, left - x, right - left);
431 // now zero before left
432 if (left > prevRite) {
433 int index = prevRite - x;
434 ((uint8_t*)aa)[index] = 0; // skip runs after right
435 ((int16_t*)runs)[index] = SkToS16(left - prevRite);
442 ((int16_t*)runs)[prevRite - x] = 0;
446 SkASSERT(skip >= -x);
451 fBlitter->blitAntiH(x, y, aa, runs);
455 void SkRgnClipBlitter::blitV(int x, int y, int height, SkAlpha alpha) {
457 bounds.set(x, y, x + 1, y + height);
459 SkRegion::Cliperator iter(*fRgn, bounds);
461 while (!iter.done()) {
462 const SkIRect& r = iter.rect();
463 SkASSERT(bounds.contains(r));
465 fBlitter->blitV(x, r.fTop, r.height(), alpha);
470 void SkRgnClipBlitter::blitRect(int x, int y, int width, int height) {
472 bounds.set(x, y, x + width, y + height);
474 SkRegion::Cliperator iter(*fRgn, bounds);
476 while (!iter.done()) {
477 const SkIRect& r = iter.rect();
478 SkASSERT(bounds.contains(r));
480 fBlitter->blitRect(r.fLeft, r.fTop, r.width(), r.height());
485 void SkRgnClipBlitter::blitAntiRect(int x, int y, int width, int height,
486 SkAlpha leftAlpha, SkAlpha rightAlpha) {
487 // The *true* width of the rectangle to blit is width + 2
489 bounds.set(x, y, x + width + 2, y + height);
491 SkRegion::Cliperator iter(*fRgn, bounds);
493 while (!iter.done()) {
494 const SkIRect& r = iter.rect();
495 SkASSERT(bounds.contains(r));
496 SkASSERT(r.fLeft >= x);
497 SkASSERT(r.fRight <= x + width + 2);
499 SkAlpha effectiveLeftAlpha = (r.fLeft == x) ? leftAlpha : 255;
500 SkAlpha effectiveRightAlpha = (r.fRight == x + width + 2) ?
503 if (255 == effectiveLeftAlpha && 255 == effectiveRightAlpha) {
504 fBlitter->blitRect(r.fLeft, r.fTop, r.width(), r.height());
505 } else if (1 == r.width()) {
507 fBlitter->blitV(r.fLeft, r.fTop, r.height(),
510 SkASSERT(r.fLeft == x + width + 1);
511 fBlitter->blitV(r.fLeft, r.fTop, r.height(),
512 effectiveRightAlpha);
515 fBlitter->blitAntiRect(r.fLeft, r.fTop, r.width() - 2, r.height(),
516 effectiveLeftAlpha, effectiveRightAlpha);
523 void SkRgnClipBlitter::blitMask(const SkMask& mask, const SkIRect& clip) {
524 SkASSERT(mask.fBounds.contains(clip));
526 SkRegion::Cliperator iter(*fRgn, clip);
527 const SkIRect& r = iter.rect();
528 SkBlitter* blitter = fBlitter;
530 while (!iter.done()) {
531 blitter->blitMask(mask, r);
536 const SkBitmap* SkRgnClipBlitter::justAnOpaqueColor(uint32_t* value) {
537 return fBlitter->justAnOpaqueColor(value);
540 ///////////////////////////////////////////////////////////////////////////////
542 SkBlitter* SkBlitterClipper::apply(SkBlitter* blitter, const SkRegion* clip,
545 const SkIRect& clipR = clip->getBounds();
547 if (clip->isEmpty() || (ir && !SkIRect::Intersects(clipR, *ir))) {
548 blitter = &fNullBlitter;
549 } else if (clip->isRect()) {
550 if (ir == NULL || !clipR.contains(*ir)) {
551 fRectBlitter.init(blitter, clipR);
552 blitter = &fRectBlitter;
555 fRgnBlitter.init(blitter, clip);
556 blitter = &fRgnBlitter;
562 ///////////////////////////////////////////////////////////////////////////////
564 #include "SkColorShader.h"
565 #include "SkColorPriv.h"
567 class Sk3DShader : public SkShader {
569 Sk3DShader(SkShader* proxy) : fProxy(proxy) {
574 virtual ~Sk3DShader() {
578 void setMask(const SkMask* mask) { fMask = mask; }
580 virtual bool setContext(const SkBitmap& device, const SkPaint& paint,
581 const SkMatrix& matrix) SK_OVERRIDE {
582 if (!this->INHERITED::setContext(device, paint, matrix)) {
586 if (!fProxy->setContext(device, paint, matrix)) {
587 // must keep our set/end context calls balanced
588 this->INHERITED::endContext();
592 fPMColor = SkPreMultiplyColor(paint.getColor());
597 virtual void endContext() SK_OVERRIDE {
599 fProxy->endContext();
601 this->INHERITED::endContext();
604 virtual void shadeSpan(int x, int y, SkPMColor span[], int count) SK_OVERRIDE {
606 fProxy->shadeSpan(x, y, span, count);
610 if (fProxy == NULL) {
611 sk_memset32(span, fPMColor, count);
616 SkASSERT(fMask->fBounds.contains(x, y));
617 SkASSERT(fMask->fBounds.contains(x + count - 1, y));
619 size_t size = fMask->computeImageSize();
620 const uint8_t* alpha = fMask->getAddr8(x, y);
621 const uint8_t* mulp = alpha + size;
622 const uint8_t* addp = mulp + size;
625 for (int i = 0; i < count; i++) {
627 SkPMColor c = span[i];
629 unsigned a = SkGetPackedA32(c);
630 unsigned r = SkGetPackedR32(c);
631 unsigned g = SkGetPackedG32(c);
632 unsigned b = SkGetPackedB32(c);
634 unsigned mul = SkAlpha255To256(mulp[i]);
635 unsigned add = addp[i];
637 r = SkFastMin32(SkAlphaMul(r, mul) + add, a);
638 g = SkFastMin32(SkAlphaMul(g, mul) + add, a);
639 b = SkFastMin32(SkAlphaMul(b, mul) + add, a);
641 span[i] = SkPackARGB32(a, r, g, b);
648 unsigned a = SkGetPackedA32(fPMColor);
649 unsigned r = SkGetPackedR32(fPMColor);
650 unsigned g = SkGetPackedG32(fPMColor);
651 unsigned b = SkGetPackedB32(fPMColor);
652 for (int i = 0; i < count; i++) {
654 unsigned mul = SkAlpha255To256(mulp[i]);
655 unsigned add = addp[i];
657 span[i] = SkPackARGB32( a,
658 SkFastMin32(SkAlphaMul(r, mul) + add, a),
659 SkFastMin32(SkAlphaMul(g, mul) + add, a),
660 SkFastMin32(SkAlphaMul(b, mul) + add, a));
669 virtual void toString(SkString* str) const SK_OVERRIDE {
670 str->append("Sk3DShader: (");
672 if (NULL != fProxy) {
673 str->append("Proxy: ");
674 fProxy->toString(str);
677 this->INHERITED::toString(str);
683 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(Sk3DShader)
686 Sk3DShader(SkReadBuffer& buffer) : INHERITED(buffer) {
687 fProxy = buffer.readShader();
688 fPMColor = buffer.readColor();
692 virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE {
693 this->INHERITED::flatten(buffer);
694 buffer.writeFlattenable(fProxy);
695 buffer.writeColor(fPMColor);
703 typedef SkShader INHERITED;
706 class Sk3DBlitter : public SkBlitter {
708 Sk3DBlitter(SkBlitter* proxy, Sk3DShader* shader, void (*killProc)(void*))
709 : fProxy(proxy), f3DShader(shader), fKillProc(killProc) {
713 virtual ~Sk3DBlitter() {
718 virtual void blitH(int x, int y, int width) {
719 fProxy->blitH(x, y, width);
722 virtual void blitAntiH(int x, int y, const SkAlpha antialias[],
723 const int16_t runs[]) {
724 fProxy->blitAntiH(x, y, antialias, runs);
727 virtual void blitV(int x, int y, int height, SkAlpha alpha) {
728 fProxy->blitV(x, y, height, alpha);
731 virtual void blitRect(int x, int y, int width, int height) {
732 fProxy->blitRect(x, y, width, height);
735 virtual void blitMask(const SkMask& mask, const SkIRect& clip) {
736 if (mask.fFormat == SkMask::k3D_Format) {
737 f3DShader->setMask(&mask);
739 ((SkMask*)&mask)->fFormat = SkMask::kA8_Format;
740 fProxy->blitMask(mask, clip);
741 ((SkMask*)&mask)->fFormat = SkMask::k3D_Format;
743 f3DShader->setMask(NULL);
745 fProxy->blitMask(mask, clip);
751 Sk3DShader* f3DShader;
752 void (*fKillProc)(void*);
755 ///////////////////////////////////////////////////////////////////////////////
757 #include "SkCoreBlitters.h"
759 class SkAutoCallProc {
761 typedef void (*Proc)(void*);
763 SkAutoCallProc(void* obj, Proc proc)
764 : fObj(obj), fProc(proc) {}
772 void* get() const { return fObj; }
784 #define SkAutoCallProc(...) SK_REQUIRE_LOCAL_VAR(SkAutoCallProc)
786 static void destroy_blitter(void* blitter) {
787 ((SkBlitter*)blitter)->~SkBlitter();
790 static void delete_blitter(void* blitter) {
791 SkDELETE((SkBlitter*)blitter);
794 static bool just_solid_color(const SkPaint& paint) {
795 if (paint.getAlpha() == 0xFF && paint.getColorFilter() == NULL) {
796 SkShader* shader = paint.getShader();
797 if (NULL == shader ||
798 (shader->getFlags() & SkShader::kOpaqueAlpha_Flag)) {
805 /** By analyzing the paint (with an xfermode), we may decide we can take
806 special action. This enum lists our possible actions
809 kNormal_XferInterp, // no special interpretation, draw normally
810 kSrcOver_XferInterp, // draw as if in srcover mode
811 kSkipDrawing_XferInterp // draw nothing
814 static XferInterp interpret_xfermode(const SkPaint& paint, SkXfermode* xfer,
815 SkBitmap::Config deviceConfig) {
816 SkXfermode::Mode mode;
818 if (SkXfermode::AsMode(xfer, &mode)) {
820 case SkXfermode::kSrc_Mode:
821 if (just_solid_color(paint)) {
822 return kSrcOver_XferInterp;
825 case SkXfermode::kDst_Mode:
826 return kSkipDrawing_XferInterp;
827 case SkXfermode::kSrcOver_Mode:
828 return kSrcOver_XferInterp;
829 case SkXfermode::kDstOver_Mode:
830 if (SkBitmap::kRGB_565_Config == deviceConfig) {
831 return kSkipDrawing_XferInterp;
834 case SkXfermode::kSrcIn_Mode:
835 if (SkBitmap::kRGB_565_Config == deviceConfig &&
836 just_solid_color(paint)) {
837 return kSrcOver_XferInterp;
840 case SkXfermode::kDstIn_Mode:
841 if (just_solid_color(paint)) {
842 return kSkipDrawing_XferInterp;
849 return kNormal_XferInterp;
852 SkBlitter* SkBlitter::Choose(const SkBitmap& device,
853 const SkMatrix& matrix,
854 const SkPaint& origPaint,
855 void* storage, size_t storageSize,
857 SkASSERT(storageSize == 0 || storage != NULL);
859 SkBlitter* blitter = NULL;
861 // which check, in case we're being called by a client with a dummy device
862 // (e.g. they have a bounder that always aborts the draw)
863 if (SkBitmap::kNo_Config == device.config() ||
864 (drawCoverage && (SkBitmap::kA8_Config != device.config()))) {
865 SK_PLACEMENT_NEW(blitter, SkNullBlitter, storage, storageSize);
869 SkShader* shader = origPaint.getShader();
870 SkColorFilter* cf = origPaint.getColorFilter();
871 SkXfermode* mode = origPaint.getXfermode();
872 Sk3DShader* shader3D = NULL;
874 SkTCopyOnFirstWrite<SkPaint> paint(origPaint);
876 if (origPaint.getMaskFilter() != NULL &&
877 origPaint.getMaskFilter()->getFormat() == SkMask::k3D_Format) {
878 shader3D = SkNEW_ARGS(Sk3DShader, (shader));
879 // we know we haven't initialized lazyPaint yet, so just do it
880 paint.writable()->setShader(shader3D)->unref();
885 switch (interpret_xfermode(*paint, mode, device.config())) {
886 case kSrcOver_XferInterp:
888 paint.writable()->setXfermode(NULL);
890 case kSkipDrawing_XferInterp:
891 SK_PLACEMENT_NEW(blitter, SkNullBlitter, storage, storageSize);
899 * If the xfermode is CLEAR, then we can completely ignore the installed
900 * color/shader/colorfilter, and just pretend we're SRC + color==0. This
901 * will fall into our optimizations for SRC mode.
903 if (SkXfermode::IsMode(mode, SkXfermode::kClear_Mode)) {
904 SkPaint* p = paint.writable();
905 shader = p->setShader(NULL);
906 cf = p->setColorFilter(NULL);
907 mode = p->setXfermodeMode(SkXfermode::kSrc_Mode);
911 if (NULL == shader) {
913 // xfermodes (and filters) require shaders for our current blitters
914 shader = SkNEW(SkColorShader);
915 paint.writable()->setShader(shader)->unref();
917 // if no shader && no xfermode, we just apply the colorfilter to
918 // our color and move on.
919 SkPaint* writablePaint = paint.writable();
920 writablePaint->setColor(cf->filterColor(paint->getColor()));
921 writablePaint->setColorFilter(NULL);
928 shader = SkNEW_ARGS(SkFilterShader, (shader, cf));
929 paint.writable()->setShader(shader)->unref();
930 // blitters should ignore the presence/absence of a filter, since
931 // if there is one, the shader will take care of it.
935 * We need to have balanced calls to the shader:
938 * We make the first call here, in case it fails we can abort the draw.
939 * The endContext() call is made by the blitter (assuming setContext did
940 * not fail) in its destructor.
942 if (shader && !shader->setContext(device, *paint, matrix)) {
943 SK_PLACEMENT_NEW(blitter, SkNullBlitter, storage, storageSize);
948 switch (device.config()) {
949 case SkBitmap::kA8_Config:
951 SkASSERT(NULL == shader);
952 SkASSERT(NULL == paint->getXfermode());
953 SK_PLACEMENT_NEW_ARGS(blitter, SkA8_Coverage_Blitter,
954 storage, storageSize, (device, *paint));
956 SK_PLACEMENT_NEW_ARGS(blitter, SkA8_Shader_Blitter,
957 storage, storageSize, (device, *paint));
959 SK_PLACEMENT_NEW_ARGS(blitter, SkA8_Blitter,
960 storage, storageSize, (device, *paint));
964 case SkBitmap::kRGB_565_Config:
965 blitter = SkBlitter_ChooseD565(device, *paint, storage, storageSize);
968 case SkBitmap::kARGB_8888_Config:
970 SK_PLACEMENT_NEW_ARGS(blitter, SkARGB32_Shader_Blitter,
971 storage, storageSize, (device, *paint));
972 } else if (paint->getColor() == SK_ColorBLACK) {
973 SK_PLACEMENT_NEW_ARGS(blitter, SkARGB32_Black_Blitter,
974 storage, storageSize, (device, *paint));
975 } else if (paint->getAlpha() == 0xFF) {
976 SK_PLACEMENT_NEW_ARGS(blitter, SkARGB32_Opaque_Blitter,
977 storage, storageSize, (device, *paint));
979 SK_PLACEMENT_NEW_ARGS(blitter, SkARGB32_Blitter,
980 storage, storageSize, (device, *paint));
985 SkDEBUGFAIL("unsupported device config");
986 SK_PLACEMENT_NEW(blitter, SkNullBlitter, storage, storageSize);
991 void (*proc)(void*) = ((void*)storage == (void*)blitter) ? destroy_blitter : delete_blitter;
992 SkAutoCallProc tmp(blitter, proc);
994 blitter = SkNEW_ARGS(Sk3DBlitter, (blitter, shader3D, proc));
1000 ///////////////////////////////////////////////////////////////////////////////
1002 const uint16_t gMask_0F0F = 0xF0F;
1003 const uint32_t gMask_00FF00FF = 0xFF00FF;
1005 ///////////////////////////////////////////////////////////////////////////////
1007 SkShaderBlitter::SkShaderBlitter(const SkBitmap& device, const SkPaint& paint)
1008 : INHERITED(device) {
1009 fShader = paint.getShader();
1011 SkASSERT(fShader->setContextHasBeenCalled());
1014 fShaderFlags = fShader->getFlags();
1017 SkShaderBlitter::~SkShaderBlitter() {
1018 SkASSERT(fShader->setContextHasBeenCalled());
1019 fShader->endContext();