blob: 5eb5dd80d03a903e08b316e12c5cd653ff769518 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
2 * Copyright 2006 The Android Open Source Project
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
Herb Derby83e939b2017-02-07 14:25:11 -05008#include "SkArenaAlloc.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +00009#include "SkBlitter.h"
10#include "SkAntiRun.h"
11#include "SkColor.h"
12#include "SkColorFilter.h"
commit-bot@chromium.org8b0e8ac2014-01-30 18:58:24 +000013#include "SkReadBuffer.h"
14#include "SkWriteBuffer.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000015#include "SkMask.h"
16#include "SkMaskFilter.h"
Florin Malitad4a70ee2017-06-19 10:21:43 -040017#include "SkPaintPriv.h"
Florin Malita4aed1382017-05-25 10:38:07 -040018#include "SkShaderBase.h"
commit-bot@chromium.orga5572e52014-03-07 03:24:41 +000019#include "SkString.h"
reed@google.com45884902012-05-11 14:38:51 +000020#include "SkTLazy.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000021#include "SkUtils.h"
halcanarya6814332015-05-27 08:53:36 -070022#include "SkXfermodeInterpretation.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000023
reed@android.com845fdac2009-06-23 03:01:32 +000024SkBlitter::~SkBlitter() {}
reed@android.com8a1c16f2008-12-17 15:59:43 +000025
reed@google.comea033602012-12-14 13:13:55 +000026bool SkBlitter::isNullBlitter() const { return false; }
27
reed41e010c2015-06-09 12:16:53 -070028const SkPixmap* SkBlitter::justAnOpaqueColor(uint32_t* value) {
halcanary96fcdcc2015-08-27 07:41:13 -070029 return nullptr;
reed@android.com8a1c16f2008-12-17 15:59:43 +000030}
31
herb7df9e4a2016-06-10 13:01:27 -070032/*
reed@google.com82065d62011-02-07 15:30:46 +000033void SkBlitter::blitH(int x, int y, int width) {
tomhudson@google.com0c00f212011-12-28 14:59:50 +000034 SkDEBUGFAIL("unimplemented");
reed@android.com8a1c16f2008-12-17 15:59:43 +000035}
36
herb7df9e4a2016-06-10 13:01:27 -070037
reed@google.com82065d62011-02-07 15:30:46 +000038void SkBlitter::blitAntiH(int x, int y, const SkAlpha antialias[],
39 const int16_t runs[]) {
tomhudson@google.com0c00f212011-12-28 14:59:50 +000040 SkDEBUGFAIL("unimplemented");
reed@android.com8a1c16f2008-12-17 15:59:43 +000041}
herb7df9e4a2016-06-10 13:01:27 -070042 */
reed@android.com8a1c16f2008-12-17 15:59:43 +000043
Yuqian Lidf60e362017-07-25 11:26:31 -040044inline static SkAlpha ScalarToAlpha(SkScalar a) {
45 return (SkAlpha)(a * 255);
46}
47
Mike Kleinad04a4b2017-09-18 19:29:24 +000048void SkBlitter::blitFatAntiRect(const SkRect& rect) {
49 SkIRect bounds = rect.roundOut();
50 SkASSERT(bounds.width() >= 3 && bounds.height() >= 3);
Yuqian Lidf60e362017-07-25 11:26:31 -040051
52 int runSize = bounds.width() + 1; // +1 so we can set runs[bounds.width()] = 0
53 void* storage = this->allocBlitMemory(runSize * (sizeof(int16_t) + sizeof(SkAlpha)));
54 int16_t* runs = reinterpret_cast<int16_t*>(storage);
55 SkAlpha* alphas = reinterpret_cast<SkAlpha*>(runs + runSize);
56
57 runs[0] = 1;
58 runs[1] = bounds.width() - 2;
59 runs[bounds.width() - 1] = 1;
60 runs[bounds.width()] = 0;
61
62 SkScalar partialL = bounds.fLeft + 1 - rect.fLeft;
63 SkScalar partialR = rect.fRight - (bounds.fRight - 1);
64 SkScalar partialT = bounds.fTop + 1 - rect.fTop;
65 SkScalar partialB = rect.fBottom - (bounds.fBottom - 1);
66
67 alphas[0] = ScalarToAlpha(partialL * partialT);
68 alphas[1] = ScalarToAlpha(partialT);
69 alphas[bounds.width() - 1] = ScalarToAlpha(partialR * partialT);
70 this->blitAntiH(bounds.fLeft, bounds.fTop, alphas, runs);
71
72 this->blitAntiRect(bounds.fLeft, bounds.fTop + 1, bounds.width() - 2, bounds.height() - 2,
73 ScalarToAlpha(partialL), ScalarToAlpha(partialR));
74
75 alphas[0] = ScalarToAlpha(partialL * partialB);
76 alphas[1] = ScalarToAlpha(partialB);
77 alphas[bounds.width() - 1] = ScalarToAlpha(partialR * partialB);
78 this->blitAntiH(bounds.fLeft, bounds.fBottom - 1, alphas, runs);
79}
80
81void SkBlitter::blitCoverageDeltas(SkCoverageDeltaList* deltas, const SkIRect& clip,
82 bool isEvenOdd, bool isInverse, bool isConvex) {
83 int runSize = clip.width() + 1; // +1 so we can set runs[clip.width()] = 0
84 void* storage = this->allocBlitMemory(runSize * (sizeof(int16_t) + sizeof(SkAlpha)));
85 int16_t* runs = reinterpret_cast<int16_t*>(storage);
86 SkAlpha* alphas = reinterpret_cast<SkAlpha*>(runs + runSize);
87 runs[clip.width()] = 0; // we must set the last run to 0 so blitAntiH can stop there
88
89 bool canUseMask = !deltas->forceRLE() &&
90 SkCoverageDeltaMask::CanHandle(SkIRect::MakeLTRB(0, 0, clip.width(), 1));
91 const SkAntiRect& antiRect = deltas->getAntiRect();
92 for(int y = deltas->top(); y < deltas->bottom(); ++y) {
93 // If antiRect is non-empty and we're at its top row, blit it and skip to the bottom
94 if (antiRect.fHeight && y == antiRect.fY) {
95 this->blitAntiRect(antiRect.fX, antiRect.fY, antiRect.fWidth, antiRect.fHeight,
96 antiRect.fLeftAlpha, antiRect.fRightAlpha);
97 y += antiRect.fHeight - 1; // -1 because ++y in the for loop
98 continue;
99 }
100
Yuqian Libd40a5b2017-09-01 15:38:45 -0400101 // If there are too many deltas, sorting will be slow. Using a mask is much faster.
Yuqian Lidf60e362017-07-25 11:26:31 -0400102 // This is such an important optimization that will bring ~2x speedup for benches like
103 // path_fill_small_long_line and path_stroke_small_sawtooth.
104 if (canUseMask && !deltas->sorted(y) && deltas->count(y) << 3 >= clip.width()) {
105 SkIRect rowIR = SkIRect::MakeLTRB(clip.fLeft, y, clip.fRight, y + 1);
Yuqian Libd40a5b2017-09-01 15:38:45 -0400106 SkSTArenaAlloc<SkCoverageDeltaMask::MAX_SIZE> alloc;
107 SkCoverageDeltaMask mask(&alloc, rowIR);
Yuqian Lidf60e362017-07-25 11:26:31 -0400108 for(int i = 0; i < deltas->count(y); ++i) {
109 const SkCoverageDelta& delta = deltas->getDelta(y, i);
110 mask.addDelta(delta.fX, y, delta.fDelta);
111 }
112 mask.convertCoverageToAlpha(isEvenOdd, isInverse, isConvex);
113 this->blitMask(mask.prepareSkMask(), rowIR);
114 continue;
115 }
116
117 // The normal flow of blitting deltas starts from here. First sort deltas.
118 deltas->sort(y);
119
120 int i = 0; // init delta index to 0
121 int lastX = clip.fLeft; // init x to clip.fLeft
122 SkFixed coverage = 0; // init coverage to 0
123
124 // skip deltas with x less than clip.fLeft; they must be precision errors
125 for(; i < deltas->count(y) && deltas->getDelta(y, i).fX < clip.fLeft; ++i);
126 for(; i < deltas->count(y) && deltas->getDelta(y, i).fX < clip.fRight; ++i) {
127 const SkCoverageDelta& delta = deltas->getDelta(y, i);
128 SkASSERT(delta.fX >= lastX); // delta must be x sorted
129 if (delta.fX > lastX) { // we have proceeded to a new x (different from lastX)
130 SkAlpha alpha = isConvex ? ConvexCoverageToAlpha(coverage, isInverse)
131 : CoverageToAlpha(coverage, isEvenOdd, isInverse);
132 alphas[lastX - clip.fLeft] = alpha; // set alpha at lastX
133 runs[lastX - clip.fLeft] = delta.fX - lastX; // set the run length
134 lastX = delta.fX; // now set lastX to current x
135 }
136 coverage += delta.fDelta; // cumulate coverage with the current delta
137 }
138
139 // Set the alpha and run length from the right-most delta to the right clip boundary
140 SkAlpha alpha = isConvex ? ConvexCoverageToAlpha(coverage, isInverse)
141 : CoverageToAlpha(coverage, isEvenOdd, isInverse);
142 alphas[lastX - clip.fLeft] = alpha;
143 runs[lastX - clip.fLeft] = clip.fRight - lastX;
144
145 this->blitAntiH(clip.fLeft, y, alphas, runs); // finally blit the current row
146 }
147}
148
reed@google.com82065d62011-02-07 15:30:46 +0000149void SkBlitter::blitV(int x, int y, int height, SkAlpha alpha) {
150 if (alpha == 255) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000151 this->blitRect(x, y, 1, height);
reed@google.com82065d62011-02-07 15:30:46 +0000152 } else {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000153 int16_t runs[2];
154 runs[0] = 1;
155 runs[1] = 0;
156
reed@google.com82065d62011-02-07 15:30:46 +0000157 while (--height >= 0) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000158 this->blitAntiH(x, y++, &alpha, runs);
reed@google.com82065d62011-02-07 15:30:46 +0000159 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000160 }
161}
162
reed@google.com82065d62011-02-07 15:30:46 +0000163void SkBlitter::blitRect(int x, int y, int width, int height) {
tomhudson@google.coma31ac732011-12-29 16:09:31 +0000164 SkASSERT(width > 0);
reed@google.com82065d62011-02-07 15:30:46 +0000165 while (--height >= 0) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000166 this->blitH(x, y++, width);
reed@google.com82065d62011-02-07 15:30:46 +0000167 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000168}
169
liyuqian38911a72016-10-04 11:23:22 -0700170/// Default implementation doesn't check for easy optimizations
171/// such as alpha == 255; also uses blitV(), which some subclasses
tomhudson@google.com49eac192011-12-27 13:59:20 +0000172/// may not support.
173void SkBlitter::blitAntiRect(int x, int y, int width, int height,
174 SkAlpha leftAlpha, SkAlpha rightAlpha) {
liyuqian38911a72016-10-04 11:23:22 -0700175 if (leftAlpha > 0) { // we may send in x = -1 with leftAlpha = 0
176 this->blitV(x, y, height, leftAlpha);
177 }
178 x++;
tomhudson@google.coma31ac732011-12-29 16:09:31 +0000179 if (width > 0) {
tomhudson@google.com47143592011-12-28 17:58:07 +0000180 this->blitRect(x, y, width, height);
181 x += width;
182 }
liyuqian38911a72016-10-04 11:23:22 -0700183 if (rightAlpha > 0) {
184 this->blitV(x, y, height, rightAlpha);
185 }
tomhudson@google.com49eac192011-12-27 13:59:20 +0000186}
187
reed@android.com8a1c16f2008-12-17 15:59:43 +0000188//////////////////////////////////////////////////////////////////////////////
189
reed@google.com82065d62011-02-07 15:30:46 +0000190static inline void bits_to_runs(SkBlitter* blitter, int x, int y,
191 const uint8_t bits[],
herb5520ded2015-11-18 10:50:33 -0800192 uint8_t left_mask, ptrdiff_t rowBytes,
193 uint8_t right_mask) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000194 int inFill = 0;
195 int pos = 0;
196
reed@google.com82065d62011-02-07 15:30:46 +0000197 while (--rowBytes >= 0) {
herb5520ded2015-11-18 10:50:33 -0800198 uint8_t b = *bits++ & left_mask;
reed@google.com82065d62011-02-07 15:30:46 +0000199 if (rowBytes == 0) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000200 b &= right_mask;
reed@google.com82065d62011-02-07 15:30:46 +0000201 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000202
herb5520ded2015-11-18 10:50:33 -0800203 for (uint8_t test = 0x80U; test != 0; test >>= 1) {
reed@google.com82065d62011-02-07 15:30:46 +0000204 if (b & test) {
205 if (!inFill) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000206 pos = x;
207 inFill = true;
208 }
reed@google.com82065d62011-02-07 15:30:46 +0000209 } else {
210 if (inFill) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000211 blitter->blitH(pos, y, x - pos);
212 inFill = false;
213 }
214 }
215 x += 1;
216 }
herb5520ded2015-11-18 10:50:33 -0800217 left_mask = 0xFFU;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000218 }
219
220 // final cleanup
reed@google.com82065d62011-02-07 15:30:46 +0000221 if (inFill) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000222 blitter->blitH(pos, y, x - pos);
reed@google.com82065d62011-02-07 15:30:46 +0000223 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000224}
225
herb5520ded2015-11-18 10:50:33 -0800226// maskBitCount is the number of 1's to place in the mask. It must be in the range between 1 and 8.
227static uint8_t generate_right_mask(int maskBitCount) {
228 return static_cast<uint8_t>(0xFF00U >> maskBitCount);
229}
230
reed@google.com82065d62011-02-07 15:30:46 +0000231void SkBlitter::blitMask(const SkMask& mask, const SkIRect& clip) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000232 SkASSERT(mask.fBounds.contains(clip));
233
reedd96e7e52016-02-17 07:15:29 -0800234 if (mask.fFormat == SkMask::kLCD16_Format) {
235 return; // needs to be handled by subclass
236 }
237
reed@google.com82065d62011-02-07 15:30:46 +0000238 if (mask.fFormat == SkMask::kBW_Format) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000239 int cx = clip.fLeft;
240 int cy = clip.fTop;
241 int maskLeft = mask.fBounds.fLeft;
herb5520ded2015-11-18 10:50:33 -0800242 int maskRowBytes = mask.fRowBytes;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000243 int height = clip.height();
244
245 const uint8_t* bits = mask.getAddr1(cx, cy);
246
herb5520ded2015-11-18 10:50:33 -0800247 SkDEBUGCODE(const uint8_t* endOfImage =
248 mask.fImage + (mask.fBounds.height() - 1) * maskRowBytes
249 + ((mask.fBounds.width() + 7) >> 3));
250
reed@google.com82065d62011-02-07 15:30:46 +0000251 if (cx == maskLeft && clip.fRight == mask.fBounds.fRight) {
252 while (--height >= 0) {
herb5520ded2015-11-18 10:50:33 -0800253 int affectedRightBit = mask.fBounds.width() - 1;
254 ptrdiff_t rowBytes = (affectedRightBit >> 3) + 1;
255 SkASSERT(bits + rowBytes <= endOfImage);
256 U8CPU rightMask = generate_right_mask((affectedRightBit & 7) + 1);
257 bits_to_runs(this, cx, cy, bits, 0xFF, rowBytes, rightMask);
258 bits += maskRowBytes;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000259 cy += 1;
260 }
reed@google.com82065d62011-02-07 15:30:46 +0000261 } else {
herb3be72b02016-06-24 13:02:31 -0700262 // Bits is calculated as the offset into the mask at the point {cx, cy} therefore, all
herb5520ded2015-11-18 10:50:33 -0800263 // addressing into the bit mask is relative to that point. Since this is an address
264 // calculated from a arbitrary bit in that byte, calculate the left most bit.
265 int bitsLeft = cx - ((cx - maskLeft) & 7);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000266
herb5520ded2015-11-18 10:50:33 -0800267 // Everything is relative to the bitsLeft.
268 int leftEdge = cx - bitsLeft;
269 SkASSERT(leftEdge >= 0);
270 int rightEdge = clip.fRight - bitsLeft;
271 SkASSERT(rightEdge > leftEdge);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000272
herb5520ded2015-11-18 10:50:33 -0800273 // Calculate left byte and mask
274 const uint8_t* leftByte = bits;
275 U8CPU leftMask = 0xFFU >> (leftEdge & 7);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000276
herb5520ded2015-11-18 10:50:33 -0800277 // Calculate right byte and mask
278 int affectedRightBit = rightEdge - 1;
279 const uint8_t* rightByte = bits + (affectedRightBit >> 3);
280 U8CPU rightMask = generate_right_mask((affectedRightBit & 7) + 1);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000281
herb5520ded2015-11-18 10:50:33 -0800282 // leftByte and rightByte are byte locations therefore, to get a count of bytes the
283 // code must add one.
284 ptrdiff_t rowBytes = rightByte - leftByte + 1;
285
286 while (--height >= 0) {
287 SkASSERT(bits + rowBytes <= endOfImage);
288 bits_to_runs(this, bitsLeft, cy, bits, leftMask, rowBytes, rightMask);
289 bits += maskRowBytes;
290 cy += 1;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000291 }
292 }
reed@google.com82065d62011-02-07 15:30:46 +0000293 } else {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000294 int width = clip.width();
295 SkAutoSTMalloc<64, int16_t> runStorage(width + 1);
296 int16_t* runs = runStorage.get();
reed@google.com79891862011-10-18 15:44:57 +0000297 const uint8_t* aa = mask.getAddr8(clip.fLeft, clip.fTop);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000298
299 sk_memset16((uint16_t*)runs, 1, width);
300 runs[width] = 0;
301
302 int height = clip.height();
303 int y = clip.fTop;
reed@google.com82065d62011-02-07 15:30:46 +0000304 while (--height >= 0) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000305 this->blitAntiH(clip.fLeft, y, aa, runs);
306 aa += mask.fRowBytes;
307 y += 1;
308 }
309 }
310}
311
312/////////////////////// these guys are not virtual, just a helpers
313
314void SkBlitter::blitMaskRegion(const SkMask& mask, const SkRegion& clip) {
315 if (clip.quickReject(mask.fBounds)) {
316 return;
317 }
reed@google.com82065d62011-02-07 15:30:46 +0000318
reed@android.com8a1c16f2008-12-17 15:59:43 +0000319 SkRegion::Cliperator clipper(clip, mask.fBounds);
reed@google.com82065d62011-02-07 15:30:46 +0000320
reed@android.com8a1c16f2008-12-17 15:59:43 +0000321 while (!clipper.done()) {
322 const SkIRect& cr = clipper.rect();
323 this->blitMask(mask, cr);
324 clipper.next();
325 }
326}
327
328void SkBlitter::blitRectRegion(const SkIRect& rect, const SkRegion& clip) {
329 SkRegion::Cliperator clipper(clip, rect);
reed@google.com82065d62011-02-07 15:30:46 +0000330
reed@android.com8a1c16f2008-12-17 15:59:43 +0000331 while (!clipper.done()) {
332 const SkIRect& cr = clipper.rect();
333 this->blitRect(cr.fLeft, cr.fTop, cr.width(), cr.height());
334 clipper.next();
335 }
336}
337
338void SkBlitter::blitRegion(const SkRegion& clip) {
339 SkRegion::Iterator iter(clip);
reed@google.com82065d62011-02-07 15:30:46 +0000340
reed@android.com8a1c16f2008-12-17 15:59:43 +0000341 while (!iter.done()) {
342 const SkIRect& cr = iter.rect();
343 this->blitRect(cr.fLeft, cr.fTop, cr.width(), cr.height());
344 iter.next();
345 }
346}
347
reed@google.com82065d62011-02-07 15:30:46 +0000348///////////////////////////////////////////////////////////////////////////////
reed@android.com8a1c16f2008-12-17 15:59:43 +0000349
reed@google.com82065d62011-02-07 15:30:46 +0000350void SkNullBlitter::blitH(int x, int y, int width) {}
reed@android.com8a1c16f2008-12-17 15:59:43 +0000351
reed@google.com82065d62011-02-07 15:30:46 +0000352void SkNullBlitter::blitAntiH(int x, int y, const SkAlpha antialias[],
353 const int16_t runs[]) {}
reed@android.com8a1c16f2008-12-17 15:59:43 +0000354
reed@google.com82065d62011-02-07 15:30:46 +0000355void SkNullBlitter::blitV(int x, int y, int height, SkAlpha alpha) {}
reed@android.com8a1c16f2008-12-17 15:59:43 +0000356
reed@google.com82065d62011-02-07 15:30:46 +0000357void SkNullBlitter::blitRect(int x, int y, int width, int height) {}
reed@android.com8a1c16f2008-12-17 15:59:43 +0000358
reed@google.com82065d62011-02-07 15:30:46 +0000359void SkNullBlitter::blitMask(const SkMask& mask, const SkIRect& clip) {}
reed@android.com8a1c16f2008-12-17 15:59:43 +0000360
reed41e010c2015-06-09 12:16:53 -0700361const SkPixmap* SkNullBlitter::justAnOpaqueColor(uint32_t* value) {
halcanary96fcdcc2015-08-27 07:41:13 -0700362 return nullptr;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000363}
364
reed@google.comea033602012-12-14 13:13:55 +0000365bool SkNullBlitter::isNullBlitter() const { return true; }
366
reed@google.com82065d62011-02-07 15:30:46 +0000367///////////////////////////////////////////////////////////////////////////////
reed@android.com8a1c16f2008-12-17 15:59:43 +0000368
reed@google.com82065d62011-02-07 15:30:46 +0000369static int compute_anti_width(const int16_t runs[]) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000370 int width = 0;
reed@google.com82065d62011-02-07 15:30:46 +0000371
372 for (;;) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000373 int count = runs[0];
reed@google.com82065d62011-02-07 15:30:46 +0000374
reed@android.com8a1c16f2008-12-17 15:59:43 +0000375 SkASSERT(count >= 0);
reed@google.com82065d62011-02-07 15:30:46 +0000376 if (count == 0) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000377 break;
reed@google.com82065d62011-02-07 15:30:46 +0000378 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000379 width += count;
380 runs += count;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000381 }
382 return width;
383}
384
reed@google.com82065d62011-02-07 15:30:46 +0000385static inline bool y_in_rect(int y, const SkIRect& rect) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000386 return (unsigned)(y - rect.fTop) < (unsigned)rect.height();
387}
388
reed@google.com82065d62011-02-07 15:30:46 +0000389static inline bool x_in_rect(int x, const SkIRect& rect) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000390 return (unsigned)(x - rect.fLeft) < (unsigned)rect.width();
391}
392
reed@google.com82065d62011-02-07 15:30:46 +0000393void SkRectClipBlitter::blitH(int left, int y, int width) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000394 SkASSERT(width > 0);
395
reed@google.com82065d62011-02-07 15:30:46 +0000396 if (!y_in_rect(y, fClipRect)) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000397 return;
reed@google.com82065d62011-02-07 15:30:46 +0000398 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000399
400 int right = left + width;
401
reed@google.com82065d62011-02-07 15:30:46 +0000402 if (left < fClipRect.fLeft) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000403 left = fClipRect.fLeft;
reed@google.com82065d62011-02-07 15:30:46 +0000404 }
405 if (right > fClipRect.fRight) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000406 right = fClipRect.fRight;
reed@google.com82065d62011-02-07 15:30:46 +0000407 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000408
409 width = right - left;
reed@google.com82065d62011-02-07 15:30:46 +0000410 if (width > 0) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000411 fBlitter->blitH(left, y, width);
reed@google.com82065d62011-02-07 15:30:46 +0000412 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000413}
414
reed@google.com82065d62011-02-07 15:30:46 +0000415void SkRectClipBlitter::blitAntiH(int left, int y, const SkAlpha aa[],
416 const int16_t runs[]) {
417 if (!y_in_rect(y, fClipRect) || left >= fClipRect.fRight) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000418 return;
reed@google.com82065d62011-02-07 15:30:46 +0000419 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000420
421 int x0 = left;
422 int x1 = left + compute_anti_width(runs);
423
reed@google.com82065d62011-02-07 15:30:46 +0000424 if (x1 <= fClipRect.fLeft) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000425 return;
reed@google.com82065d62011-02-07 15:30:46 +0000426 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000427
428 SkASSERT(x0 < x1);
reed@google.com82065d62011-02-07 15:30:46 +0000429 if (x0 < fClipRect.fLeft) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000430 int dx = fClipRect.fLeft - x0;
431 SkAlphaRuns::BreakAt((int16_t*)runs, (uint8_t*)aa, dx);
432 runs += dx;
433 aa += dx;
434 x0 = fClipRect.fLeft;
435 }
436
437 SkASSERT(x0 < x1 && runs[x1 - x0] == 0);
reed@google.com82065d62011-02-07 15:30:46 +0000438 if (x1 > fClipRect.fRight) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000439 x1 = fClipRect.fRight;
440 SkAlphaRuns::BreakAt((int16_t*)runs, (uint8_t*)aa, x1 - x0);
441 ((int16_t*)runs)[x1 - x0] = 0;
442 }
443
444 SkASSERT(x0 < x1 && runs[x1 - x0] == 0);
445 SkASSERT(compute_anti_width(runs) == x1 - x0);
446
447 fBlitter->blitAntiH(x0, y, aa, runs);
448}
449
reed@google.com82065d62011-02-07 15:30:46 +0000450void SkRectClipBlitter::blitV(int x, int y, int height, SkAlpha alpha) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000451 SkASSERT(height > 0);
452
reed@google.com82065d62011-02-07 15:30:46 +0000453 if (!x_in_rect(x, fClipRect)) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000454 return;
reed@google.com82065d62011-02-07 15:30:46 +0000455 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000456
457 int y0 = y;
458 int y1 = y + height;
459
reed@google.com82065d62011-02-07 15:30:46 +0000460 if (y0 < fClipRect.fTop) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000461 y0 = fClipRect.fTop;
reed@google.com82065d62011-02-07 15:30:46 +0000462 }
463 if (y1 > fClipRect.fBottom) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000464 y1 = fClipRect.fBottom;
reed@google.com82065d62011-02-07 15:30:46 +0000465 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000466
reed@google.com82065d62011-02-07 15:30:46 +0000467 if (y0 < y1) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000468 fBlitter->blitV(x, y0, y1 - y0, alpha);
reed@google.com82065d62011-02-07 15:30:46 +0000469 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000470}
471
reed@google.com82065d62011-02-07 15:30:46 +0000472void SkRectClipBlitter::blitRect(int left, int y, int width, int height) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000473 SkIRect r;
474
475 r.set(left, y, left + width, y + height);
reed@google.com82065d62011-02-07 15:30:46 +0000476 if (r.intersect(fClipRect)) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000477 fBlitter->blitRect(r.fLeft, r.fTop, r.width(), r.height());
reed@google.com82065d62011-02-07 15:30:46 +0000478 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000479}
480
tomhudson@google.com49eac192011-12-27 13:59:20 +0000481void SkRectClipBlitter::blitAntiRect(int left, int y, int width, int height,
482 SkAlpha leftAlpha, SkAlpha rightAlpha) {
483 SkIRect r;
484
485 // The *true* width of the rectangle blitted is width+2:
486 r.set(left, y, left + width + 2, y + height);
487 if (r.intersect(fClipRect)) {
488 if (r.fLeft != left) {
489 SkASSERT(r.fLeft > left);
490 leftAlpha = 255;
491 }
492 if (r.fRight != left + width + 2) {
493 SkASSERT(r.fRight < left + width + 2);
494 rightAlpha = 255;
495 }
496 if (255 == leftAlpha && 255 == rightAlpha) {
497 fBlitter->blitRect(r.fLeft, r.fTop, r.width(), r.height());
498 } else if (1 == r.width()) {
499 if (r.fLeft == left) {
500 fBlitter->blitV(r.fLeft, r.fTop, r.height(), leftAlpha);
501 } else {
502 SkASSERT(r.fLeft == left + width + 1);
503 fBlitter->blitV(r.fLeft, r.fTop, r.height(), rightAlpha);
504 }
505 } else {
506 fBlitter->blitAntiRect(r.fLeft, r.fTop, r.width() - 2, r.height(),
507 leftAlpha, rightAlpha);
508 }
509 }
510}
511
reed@google.com82065d62011-02-07 15:30:46 +0000512void SkRectClipBlitter::blitMask(const SkMask& mask, const SkIRect& clip) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000513 SkASSERT(mask.fBounds.contains(clip));
514
515 SkIRect r = clip;
516
reed@google.com82065d62011-02-07 15:30:46 +0000517 if (r.intersect(fClipRect)) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000518 fBlitter->blitMask(mask, r);
reed@google.com82065d62011-02-07 15:30:46 +0000519 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000520}
521
reed41e010c2015-06-09 12:16:53 -0700522const SkPixmap* SkRectClipBlitter::justAnOpaqueColor(uint32_t* value) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000523 return fBlitter->justAnOpaqueColor(value);
524}
525
reed@google.com82065d62011-02-07 15:30:46 +0000526///////////////////////////////////////////////////////////////////////////////
reed@android.com8a1c16f2008-12-17 15:59:43 +0000527
reed@google.com82065d62011-02-07 15:30:46 +0000528void SkRgnClipBlitter::blitH(int x, int y, int width) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000529 SkRegion::Spanerator span(*fRgn, y, x, x + width);
530 int left, right;
531
reed@google.com82065d62011-02-07 15:30:46 +0000532 while (span.next(&left, &right)) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000533 SkASSERT(left < right);
534 fBlitter->blitH(left, y, right - left);
535 }
536}
537
reed@google.com82065d62011-02-07 15:30:46 +0000538void SkRgnClipBlitter::blitAntiH(int x, int y, const SkAlpha aa[],
539 const int16_t runs[]) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000540 int width = compute_anti_width(runs);
541 SkRegion::Spanerator span(*fRgn, y, x, x + width);
542 int left, right;
543 SkDEBUGCODE(const SkIRect& bounds = fRgn->getBounds();)
reed@google.com82065d62011-02-07 15:30:46 +0000544
reed@android.com8a1c16f2008-12-17 15:59:43 +0000545 int prevRite = x;
reed@google.com82065d62011-02-07 15:30:46 +0000546 while (span.next(&left, &right)) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000547 SkASSERT(x <= left);
548 SkASSERT(left < right);
549 SkASSERT(left >= bounds.fLeft && right <= bounds.fRight);
reed@google.com82065d62011-02-07 15:30:46 +0000550
reed@android.com8a1c16f2008-12-17 15:59:43 +0000551 SkAlphaRuns::Break((int16_t*)runs, (uint8_t*)aa, left - x, right - left);
552
553 // now zero before left
reed@google.com82065d62011-02-07 15:30:46 +0000554 if (left > prevRite) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000555 int index = prevRite - x;
556 ((uint8_t*)aa)[index] = 0; // skip runs after right
557 ((int16_t*)runs)[index] = SkToS16(left - prevRite);
558 }
reed@google.com82065d62011-02-07 15:30:46 +0000559
reed@android.com8a1c16f2008-12-17 15:59:43 +0000560 prevRite = right;
561 }
reed@google.com82065d62011-02-07 15:30:46 +0000562
563 if (prevRite > x) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000564 ((int16_t*)runs)[prevRite - x] = 0;
reed@google.com82065d62011-02-07 15:30:46 +0000565
reed@android.com8a1c16f2008-12-17 15:59:43 +0000566 if (x < 0) {
567 int skip = runs[0];
568 SkASSERT(skip >= -x);
569 aa += skip;
570 runs += skip;
571 x += skip;
572 }
573 fBlitter->blitAntiH(x, y, aa, runs);
574 }
575}
576
reed@google.com82065d62011-02-07 15:30:46 +0000577void SkRgnClipBlitter::blitV(int x, int y, int height, SkAlpha alpha) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000578 SkIRect bounds;
579 bounds.set(x, y, x + 1, y + height);
580
581 SkRegion::Cliperator iter(*fRgn, bounds);
582
reed@google.com82065d62011-02-07 15:30:46 +0000583 while (!iter.done()) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000584 const SkIRect& r = iter.rect();
585 SkASSERT(bounds.contains(r));
586
587 fBlitter->blitV(x, r.fTop, r.height(), alpha);
588 iter.next();
589 }
590}
591
reed@google.com82065d62011-02-07 15:30:46 +0000592void SkRgnClipBlitter::blitRect(int x, int y, int width, int height) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000593 SkIRect bounds;
594 bounds.set(x, y, x + width, y + height);
595
596 SkRegion::Cliperator iter(*fRgn, bounds);
597
reed@google.com82065d62011-02-07 15:30:46 +0000598 while (!iter.done()) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000599 const SkIRect& r = iter.rect();
600 SkASSERT(bounds.contains(r));
601
602 fBlitter->blitRect(r.fLeft, r.fTop, r.width(), r.height());
603 iter.next();
604 }
605}
606
tomhudson@google.com49eac192011-12-27 13:59:20 +0000607void SkRgnClipBlitter::blitAntiRect(int x, int y, int width, int height,
608 SkAlpha leftAlpha, SkAlpha rightAlpha) {
609 // The *true* width of the rectangle to blit is width + 2
610 SkIRect bounds;
611 bounds.set(x, y, x + width + 2, y + height);
612
613 SkRegion::Cliperator iter(*fRgn, bounds);
614
615 while (!iter.done()) {
616 const SkIRect& r = iter.rect();
617 SkASSERT(bounds.contains(r));
618 SkASSERT(r.fLeft >= x);
tomhudson@google.com31bab392012-01-03 20:12:42 +0000619 SkASSERT(r.fRight <= x + width + 2);
tomhudson@google.com49eac192011-12-27 13:59:20 +0000620
621 SkAlpha effectiveLeftAlpha = (r.fLeft == x) ? leftAlpha : 255;
622 SkAlpha effectiveRightAlpha = (r.fRight == x + width + 2) ?
623 rightAlpha : 255;
624
625 if (255 == effectiveLeftAlpha && 255 == effectiveRightAlpha) {
626 fBlitter->blitRect(r.fLeft, r.fTop, r.width(), r.height());
627 } else if (1 == r.width()) {
628 if (r.fLeft == x) {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000629 fBlitter->blitV(r.fLeft, r.fTop, r.height(),
tomhudson@google.com49eac192011-12-27 13:59:20 +0000630 effectiveLeftAlpha);
631 } else {
632 SkASSERT(r.fLeft == x + width + 1);
633 fBlitter->blitV(r.fLeft, r.fTop, r.height(),
634 effectiveRightAlpha);
635 }
636 } else {
637 fBlitter->blitAntiRect(r.fLeft, r.fTop, r.width() - 2, r.height(),
638 effectiveLeftAlpha, effectiveRightAlpha);
639 }
640 iter.next();
641 }
642}
643
644
reed@google.com82065d62011-02-07 15:30:46 +0000645void SkRgnClipBlitter::blitMask(const SkMask& mask, const SkIRect& clip) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000646 SkASSERT(mask.fBounds.contains(clip));
647
648 SkRegion::Cliperator iter(*fRgn, clip);
649 const SkIRect& r = iter.rect();
650 SkBlitter* blitter = fBlitter;
651
reed@google.com82065d62011-02-07 15:30:46 +0000652 while (!iter.done()) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000653 blitter->blitMask(mask, r);
654 iter.next();
655 }
656}
657
reed41e010c2015-06-09 12:16:53 -0700658const SkPixmap* SkRgnClipBlitter::justAnOpaqueColor(uint32_t* value) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000659 return fBlitter->justAnOpaqueColor(value);
660}
661
reed@google.com82065d62011-02-07 15:30:46 +0000662///////////////////////////////////////////////////////////////////////////////
reed@android.com8a1c16f2008-12-17 15:59:43 +0000663
reed@google.com82065d62011-02-07 15:30:46 +0000664SkBlitter* SkBlitterClipper::apply(SkBlitter* blitter, const SkRegion* clip,
665 const SkIRect* ir) {
666 if (clip) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000667 const SkIRect& clipR = clip->getBounds();
668
reed@google.com82065d62011-02-07 15:30:46 +0000669 if (clip->isEmpty() || (ir && !SkIRect::Intersects(clipR, *ir))) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000670 blitter = &fNullBlitter;
reed@google.com82065d62011-02-07 15:30:46 +0000671 } else if (clip->isRect()) {
halcanary96fcdcc2015-08-27 07:41:13 -0700672 if (ir == nullptr || !clipR.contains(*ir)) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000673 fRectBlitter.init(blitter, clipR);
674 blitter = &fRectBlitter;
675 }
reed@google.com82065d62011-02-07 15:30:46 +0000676 } else {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000677 fRgnBlitter.init(blitter, clip);
678 blitter = &fRgnBlitter;
679 }
680 }
681 return blitter;
682}
683
reed@google.com82065d62011-02-07 15:30:46 +0000684///////////////////////////////////////////////////////////////////////////////
reed@android.com8a1c16f2008-12-17 15:59:43 +0000685
686#include "SkColorShader.h"
Cary Clarka4083c92017-09-15 11:59:23 -0400687#include "SkColorData.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +0000688
Florin Malita4aed1382017-05-25 10:38:07 -0400689class Sk3DShader : public SkShaderBase {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000690public:
reed8a21c9f2016-03-08 18:50:00 -0800691 Sk3DShader(sk_sp<SkShader> proxy) : fProxy(std::move(proxy)) {}
reed@google.com82065d62011-02-07 15:30:46 +0000692
Herb Derby83e939b2017-02-07 14:25:11 -0500693 Context* onMakeContext(const ContextRec& rec, SkArenaAlloc* alloc) const override {
Florin Malita4aed1382017-05-25 10:38:07 -0400694 SkShaderBase::Context* proxyContext = nullptr;
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +0000695 if (fProxy) {
Florin Malita4aed1382017-05-25 10:38:07 -0400696 proxyContext = as_SB(fProxy)->makeContext(rec, alloc);
commit-bot@chromium.orgce56d962014-05-05 18:39:18 +0000697 if (!proxyContext) {
halcanary96fcdcc2015-08-27 07:41:13 -0700698 return nullptr;
commit-bot@chromium.orgce56d962014-05-05 18:39:18 +0000699 }
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +0000700 }
Herb Derby83e939b2017-02-07 14:25:11 -0500701 return alloc->make<Sk3DShaderContext>(*this, rec, proxyContext);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000702 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000703
Florin Malita4aed1382017-05-25 10:38:07 -0400704 class Sk3DShaderContext : public Context {
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +0000705 public:
706 // Calls proxyContext's destructor but will NOT free its memory.
commit-bot@chromium.orge901b6d2014-05-01 19:31:31 +0000707 Sk3DShaderContext(const Sk3DShader& shader, const ContextRec& rec,
Florin Malita4aed1382017-05-25 10:38:07 -0400708 Context* proxyContext)
commit-bot@chromium.orge901b6d2014-05-01 19:31:31 +0000709 : INHERITED(shader, rec)
halcanary96fcdcc2015-08-27 07:41:13 -0700710 , fMask(nullptr)
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +0000711 , fProxyContext(proxyContext)
712 {
713 if (!fProxyContext) {
commit-bot@chromium.orge901b6d2014-05-01 19:31:31 +0000714 fPMColor = SkPreMultiplyColor(rec.fPaint->getColor());
commit-bot@chromium.orgbc2f1dc2014-04-23 09:11:58 +0000715 }
716 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000717
Brian Salomond3b65972017-03-22 12:05:03 -0400718 ~Sk3DShaderContext() override {
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +0000719 if (fProxyContext) {
720 fProxyContext->~Context();
721 }
722 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000723
mtklein36352bf2015-03-25 18:17:31 -0700724 void set3DMask(const SkMask* mask) override { fMask = mask; }
commit-bot@chromium.org001f4ed2014-04-16 10:16:39 +0000725
mtklein36352bf2015-03-25 18:17:31 -0700726 void shadeSpan(int x, int y, SkPMColor span[], int count) override {
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +0000727 if (fProxyContext) {
728 fProxyContext->shadeSpan(x, y, span, count);
729 }
commit-bot@chromium.orgbc2f1dc2014-04-23 09:11:58 +0000730
halcanary96fcdcc2015-08-27 07:41:13 -0700731 if (fMask == nullptr) {
732 if (fProxyContext == nullptr) {
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +0000733 sk_memset32(span, fPMColor, count);
734 }
735 return;
736 }
737
738 SkASSERT(fMask->fBounds.contains(x, y));
739 SkASSERT(fMask->fBounds.contains(x + count - 1, y));
740
741 size_t size = fMask->computeImageSize();
742 const uint8_t* alpha = fMask->getAddr8(x, y);
743 const uint8_t* mulp = alpha + size;
744 const uint8_t* addp = mulp + size;
745
746 if (fProxyContext) {
747 for (int i = 0; i < count; i++) {
748 if (alpha[i]) {
749 SkPMColor c = span[i];
750 if (c) {
751 unsigned a = SkGetPackedA32(c);
752 unsigned r = SkGetPackedR32(c);
753 unsigned g = SkGetPackedG32(c);
754 unsigned b = SkGetPackedB32(c);
755
756 unsigned mul = SkAlpha255To256(mulp[i]);
757 unsigned add = addp[i];
758
759 r = SkFastMin32(SkAlphaMul(r, mul) + add, a);
760 g = SkFastMin32(SkAlphaMul(g, mul) + add, a);
761 b = SkFastMin32(SkAlphaMul(b, mul) + add, a);
762
763 span[i] = SkPackARGB32(a, r, g, b);
764 }
765 } else {
766 span[i] = 0;
767 }
768 }
769 } else { // color
770 unsigned a = SkGetPackedA32(fPMColor);
771 unsigned r = SkGetPackedR32(fPMColor);
772 unsigned g = SkGetPackedG32(fPMColor);
773 unsigned b = SkGetPackedB32(fPMColor);
774 for (int i = 0; i < count; i++) {
775 if (alpha[i]) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000776 unsigned mul = SkAlpha255To256(mulp[i]);
777 unsigned add = addp[i];
778
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +0000779 span[i] = SkPackARGB32( a,
780 SkFastMin32(SkAlphaMul(r, mul) + add, a),
781 SkFastMin32(SkAlphaMul(g, mul) + add, a),
782 SkFastMin32(SkAlphaMul(b, mul) + add, a));
783 } else {
784 span[i] = 0;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000785 }
reed@google.com82065d62011-02-07 15:30:46 +0000786 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000787 }
788 }
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +0000789
790 private:
791 // Unowned.
Florin Malita4aed1382017-05-25 10:38:07 -0400792 const SkMask* fMask;
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +0000793 // Memory is unowned, but we need to call the destructor.
Florin Malita4aed1382017-05-25 10:38:07 -0400794 Context* fProxyContext;
795 SkPMColor fPMColor;
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +0000796
Florin Malita4aed1382017-05-25 10:38:07 -0400797 typedef Context INHERITED;
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +0000798 };
reed@google.com82065d62011-02-07 15:30:46 +0000799
commit-bot@chromium.org0f10f7b2014-03-13 18:02:17 +0000800#ifndef SK_IGNORE_TO_STRING
mtklein36352bf2015-03-25 18:17:31 -0700801 void toString(SkString* str) const override {
robertphillips@google.com76f9e932013-01-15 20:17:47 +0000802 str->append("Sk3DShader: (");
803
bsalomon49f085d2014-09-05 13:34:00 -0700804 if (fProxy) {
robertphillips@google.com76f9e932013-01-15 20:17:47 +0000805 str->append("Proxy: ");
Florin Malita4aed1382017-05-25 10:38:07 -0400806 as_SB(fProxy)->toString(str);
robertphillips@google.com76f9e932013-01-15 20:17:47 +0000807 }
808
809 this->INHERITED::toString(str);
810
811 str->append(")");
812 }
813#endif
814
djsollen@google.comba28d032012-03-26 17:57:35 +0000815 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(Sk3DShader)
816
reed@android.com8a1c16f2008-12-17 15:59:43 +0000817protected:
mtklein36352bf2015-03-25 18:17:31 -0700818 void flatten(SkWriteBuffer& buffer) const override {
reed8a21c9f2016-03-08 18:50:00 -0800819 buffer.writeFlattenable(fProxy.get());
reed@android.com8a1c16f2008-12-17 15:59:43 +0000820 }
reed@google.com82065d62011-02-07 15:30:46 +0000821
reed@android.com8a1c16f2008-12-17 15:59:43 +0000822private:
reed8a21c9f2016-03-08 18:50:00 -0800823 sk_sp<SkShader> fProxy;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000824
Florin Malita4aed1382017-05-25 10:38:07 -0400825 typedef SkShaderBase INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000826};
827
reed60c9b582016-04-03 09:11:13 -0700828sk_sp<SkFlattenable> Sk3DShader::CreateProc(SkReadBuffer& buffer) {
829 return sk_make_sp<Sk3DShader>(buffer.readShader());
reed9fa60da2014-08-21 07:59:51 -0700830}
831
reed@android.com8a1c16f2008-12-17 15:59:43 +0000832class Sk3DBlitter : public SkBlitter {
833public:
Florin Malita4aed1382017-05-25 10:38:07 -0400834 Sk3DBlitter(SkBlitter* proxy, SkShaderBase::Context* shaderContext)
commit-bot@chromium.orga5572e52014-03-07 03:24:41 +0000835 : fProxy(proxy)
reedcc0e3112014-09-10 10:20:24 -0700836 , fShaderContext(shaderContext)
commit-bot@chromium.orga5572e52014-03-07 03:24:41 +0000837 {}
reed@android.com8a1c16f2008-12-17 15:59:43 +0000838
mtklein36352bf2015-03-25 18:17:31 -0700839 void blitH(int x, int y, int width) override {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000840 fProxy->blitH(x, y, width);
841 }
reed@google.com82065d62011-02-07 15:30:46 +0000842
reed60c9b582016-04-03 09:11:13 -0700843 void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) override {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000844 fProxy->blitAntiH(x, y, antialias, runs);
845 }
reed@google.com82065d62011-02-07 15:30:46 +0000846
mtklein36352bf2015-03-25 18:17:31 -0700847 void blitV(int x, int y, int height, SkAlpha alpha) override {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000848 fProxy->blitV(x, y, height, alpha);
849 }
reed@google.com82065d62011-02-07 15:30:46 +0000850
mtklein36352bf2015-03-25 18:17:31 -0700851 void blitRect(int x, int y, int width, int height) override {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000852 fProxy->blitRect(x, y, width, height);
853 }
reed@google.com82065d62011-02-07 15:30:46 +0000854
mtklein36352bf2015-03-25 18:17:31 -0700855 void blitMask(const SkMask& mask, const SkIRect& clip) override {
reed@google.com82065d62011-02-07 15:30:46 +0000856 if (mask.fFormat == SkMask::k3D_Format) {
reedcc0e3112014-09-10 10:20:24 -0700857 fShaderContext->set3DMask(&mask);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000858
859 ((SkMask*)&mask)->fFormat = SkMask::kA8_Format;
860 fProxy->blitMask(mask, clip);
861 ((SkMask*)&mask)->fFormat = SkMask::k3D_Format;
862
halcanary96fcdcc2015-08-27 07:41:13 -0700863 fShaderContext->set3DMask(nullptr);
reed@google.com82065d62011-02-07 15:30:46 +0000864 } else {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000865 fProxy->blitMask(mask, clip);
reed@google.com82065d62011-02-07 15:30:46 +0000866 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000867 }
reed@google.com82065d62011-02-07 15:30:46 +0000868
reed@android.com8a1c16f2008-12-17 15:59:43 +0000869private:
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +0000870 // Both pointers are unowned. They will be deleted by SkSmallAllocator.
Florin Malita4aed1382017-05-25 10:38:07 -0400871 SkBlitter* fProxy;
872 SkShaderBase::Context* fShaderContext;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000873};
874
reed@google.com82065d62011-02-07 15:30:46 +0000875///////////////////////////////////////////////////////////////////////////////
reed@android.com8a1c16f2008-12-17 15:59:43 +0000876
877#include "SkCoreBlitters.h"
878
Florin Malita4aed1382017-05-25 10:38:07 -0400879SkShaderBase::ContextRec::DstType SkBlitter::PreferredShaderDest(const SkImageInfo& dstInfo) {
reed960b2d62016-06-17 09:26:41 -0700880 return (dstInfo.gammaCloseToSRGB() || dstInfo.colorType() == kRGBA_F16_SkColorType)
Florin Malita4aed1382017-05-25 10:38:07 -0400881 ? SkShaderBase::ContextRec::kPM4f_DstType
882 : SkShaderBase::ContextRec::kPMColor_DstType;
fmalitad0c4e092016-02-22 17:19:04 -0800883}
884
Mike Reedc928fe22017-06-05 10:20:31 -0400885// hack for testing, not to be exposed to clients
886bool gSkForceRasterPipelineBlitter;
887
Florin Malitac4176a22017-07-11 22:47:21 -0400888bool SkBlitter::UseRasterPipelineBlitter(const SkPixmap& device, const SkPaint& paint,
889 const SkMatrix& matrix) {
Mike Reedc928fe22017-06-05 10:20:31 -0400890 if (gSkForceRasterPipelineBlitter) {
891 return true;
892 }
Mike Reed883c9bc2017-07-19 10:57:53 -0400893 if (device.info().alphaType() == kUnpremul_SkAlphaType) {
894 return true;
895 }
Mike Klein9beafc42017-06-05 06:32:21 -0400896#if 0 || defined(SK_FORCE_RASTER_PIPELINE_BLITTER)
Mike Kleinb60acfc2017-05-10 16:13:35 -0400897 return true;
898#else
899 // By policy we choose not to handle legacy 8888 with SkRasterPipelineBlitter.
900 if (device.colorSpace()) {
901 return true;
902 }
Mike Reed428266d2017-06-24 18:17:49 -0400903 if (paint.getColorFilter()) {
904 return true;
905 }
Mike Reed90ca3772017-06-28 10:53:36 -0400906 if (paint.getFilterQuality() == kHigh_SkFilterQuality) {
907 return true;
908 }
Florin Malita5769dd22017-07-12 13:31:25 -0400909 // ... unless the blend mode is complicated enough.
Mike Kleinb2ef4d62017-05-25 16:23:09 -0400910 if (paint.getBlendMode() > SkBlendMode::kLastSeparableMode) {
911 return true;
912 }
Florin Malita5769dd22017-07-12 13:31:25 -0400913 if (matrix.hasPerspective()) {
914 return true;
915 }
Florin Malita5769dd22017-07-12 13:31:25 -0400916 // ... or unless the shader is raster pipeline-only.
Mike Reed34042072017-08-08 16:29:22 -0400917 if (paint.getShader() && as_SB(paint.getShader())->isRasterPipelineOnly(matrix)) {
Florin Malitac4176a22017-07-11 22:47:21 -0400918 return true;
919 }
920
Mike Kleinb60acfc2017-05-10 16:13:35 -0400921 return device.colorType() != kN32_SkColorType;
922#endif
923}
924
reed41e010c2015-06-09 12:16:53 -0700925SkBlitter* SkBlitter::Choose(const SkPixmap& device,
reed@android.com8a1c16f2008-12-17 15:59:43 +0000926 const SkMatrix& matrix,
reed@google.com6b7aee32011-04-19 18:36:09 +0000927 const SkPaint& origPaint,
Herb Derby83e939b2017-02-07 14:25:11 -0500928 SkArenaAlloc* alloc,
reed@google.com126f7f52013-11-07 16:06:53 +0000929 bool drawCoverage) {
Herb Derby83e939b2017-02-07 14:25:11 -0500930 SkASSERT(alloc != nullptr);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000931
reed@android.com8a1c16f2008-12-17 15:59:43 +0000932 // which check, in case we're being called by a client with a dummy device
933 // (e.g. they have a bounder that always aborts the draw)
reed@google.com900ecf22014-02-20 20:55:37 +0000934 if (kUnknown_SkColorType == device.colorType() ||
935 (drawCoverage && (kAlpha_8_SkColorType != device.colorType()))) {
Herb Derby83e939b2017-02-07 14:25:11 -0500936 return alloc->make<SkNullBlitter>();
reed@android.com8a1c16f2008-12-17 15:59:43 +0000937 }
938
Florin Malita4aed1382017-05-25 10:38:07 -0400939 auto* shader = as_SB(origPaint.getShader());
reed@google.com45884902012-05-11 14:38:51 +0000940 SkColorFilter* cf = origPaint.getColorFilter();
reed374772b2016-10-05 17:33:02 -0700941 SkBlendMode mode = origPaint.getBlendMode();
reedfe630452016-03-25 09:08:00 -0700942 sk_sp<Sk3DShader> shader3D;
reed@google.com45884902012-05-11 14:38:51 +0000943
bsalomon@google.com5dc26b92012-10-11 19:32:32 +0000944 SkTCopyOnFirstWrite<SkPaint> paint(origPaint);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000945
halcanary96fcdcc2015-08-27 07:41:13 -0700946 if (origPaint.getMaskFilter() != nullptr &&
reed@google.com45884902012-05-11 14:38:51 +0000947 origPaint.getMaskFilter()->getFormat() == SkMask::k3D_Format) {
reedfe630452016-03-25 09:08:00 -0700948 shader3D = sk_make_sp<Sk3DShader>(sk_ref_sp(shader));
reed@google.com45884902012-05-11 14:38:51 +0000949 // we know we haven't initialized lazyPaint yet, so just do it
reedfe630452016-03-25 09:08:00 -0700950 paint.writable()->setShader(shader3D);
Florin Malita4aed1382017-05-25 10:38:07 -0400951 shader = as_SB(shader3D.get());
reed@android.com8a1c16f2008-12-17 15:59:43 +0000952 }
953
reed374772b2016-10-05 17:33:02 -0700954 if (mode != SkBlendMode::kSrcOver) {
halcanarya6814332015-05-27 08:53:36 -0700955 bool deviceIsOpaque = kRGB_565_SkColorType == device.colorType();
956 switch (SkInterpretXfermode(*paint, deviceIsOpaque)) {
957 case kSrcOver_SkXfermodeInterpretation:
reed374772b2016-10-05 17:33:02 -0700958 mode = SkBlendMode::kSrcOver;
959 paint.writable()->setBlendMode(mode);
reed@android.comd252db02009-04-01 18:31:44 +0000960 break;
halcanarya6814332015-05-27 08:53:36 -0700961 case kSkipDrawing_SkXfermodeInterpretation:{
Herb Derby83e939b2017-02-07 14:25:11 -0500962 return alloc->make<SkNullBlitter>();
commit-bot@chromium.orga5572e52014-03-07 03:24:41 +0000963 }
reed@android.comd252db02009-04-01 18:31:44 +0000964 default:
965 break;
966 }
967 }
968
reed@google.com13201e72012-11-16 13:20:41 +0000969 /*
970 * If the xfermode is CLEAR, then we can completely ignore the installed
971 * color/shader/colorfilter, and just pretend we're SRC + color==0. This
972 * will fall into our optimizations for SRC mode.
973 */
reed374772b2016-10-05 17:33:02 -0700974 if (mode == SkBlendMode::kClear) {
reed@google.com13201e72012-11-16 13:20:41 +0000975 SkPaint* p = paint.writable();
reedfe630452016-03-25 09:08:00 -0700976 p->setShader(nullptr);
977 shader = nullptr;
reedd053ce92016-03-22 10:17:23 -0700978 p->setColorFilter(nullptr);
979 cf = nullptr;
reed374772b2016-10-05 17:33:02 -0700980 p->setBlendMode(mode = SkBlendMode::kSrc);
reed@google.com13201e72012-11-16 13:20:41 +0000981 p->setColor(0);
982 }
reed@google.com13201e72012-11-16 13:20:41 +0000983
Mike Kleine71b1672017-01-13 07:59:23 -0500984 if (kAlpha_8_SkColorType == device.colorType() && drawCoverage) {
985 SkASSERT(nullptr == shader);
986 SkASSERT(paint->isSrcOver());
Herb Derby83e939b2017-02-07 14:25:11 -0500987 return alloc->make<SkA8_Coverage_Blitter>(device, *paint);
Mike Kleine71b1672017-01-13 07:59:23 -0500988 }
989
Florin Malitad4a70ee2017-06-19 10:21:43 -0400990 if (paint->isDither() && !SkPaintPriv::ShouldDither(*paint, device.colorType())) {
991 // Disable dithering when not needed.
992 paint.writable()->setDither(false);
993 }
994
Florin Malitac4176a22017-07-11 22:47:21 -0400995 if (UseRasterPipelineBlitter(device, *paint, matrix)) {
Mike Klein44d32792017-05-10 12:29:38 -0400996 auto blitter = SkCreateRasterPipelineBlitter(device, *paint, matrix, alloc);
997 SkASSERT(blitter);
998 return blitter;
mtklein9a5c47f2016-07-22 11:05:04 -0700999 }
1000
halcanary96fcdcc2015-08-27 07:41:13 -07001001 if (nullptr == shader) {
reed374772b2016-10-05 17:33:02 -07001002 if (mode != SkBlendMode::kSrcOver) {
reed@google.com6b7aee32011-04-19 18:36:09 +00001003 // xfermodes (and filters) require shaders for our current blitters
reedfe630452016-03-25 09:08:00 -07001004 paint.writable()->setShader(SkShader::MakeColorShader(paint->getColor()));
commit-bot@chromium.org76a3b2a2014-04-24 16:54:46 +00001005 paint.writable()->setAlpha(0xFF);
Florin Malita4aed1382017-05-25 10:38:07 -04001006 shader = as_SB(paint->getShader());
reed@google.com6b7aee32011-04-19 18:36:09 +00001007 } else if (cf) {
1008 // if no shader && no xfermode, we just apply the colorfilter to
1009 // our color and move on.
bsalomon@google.com5dc26b92012-10-11 19:32:32 +00001010 SkPaint* writablePaint = paint.writable();
1011 writablePaint->setColor(cf->filterColor(paint->getColor()));
halcanary96fcdcc2015-08-27 07:41:13 -07001012 writablePaint->setColorFilter(nullptr);
1013 cf = nullptr;
reed@google.com6b7aee32011-04-19 18:36:09 +00001014 }
reed@android.com8a1c16f2008-12-17 15:59:43 +00001015 }
reed@google.com82065d62011-02-07 15:30:46 +00001016
reed@google.com6b7aee32011-04-19 18:36:09 +00001017 if (cf) {
reed@android.com8a1c16f2008-12-17 15:59:43 +00001018 SkASSERT(shader);
reedd053ce92016-03-22 10:17:23 -07001019 paint.writable()->setShader(shader->makeWithColorFilter(sk_ref_sp(cf)));
Florin Malita4aed1382017-05-25 10:38:07 -04001020 shader = as_SB(paint->getShader());
reed@android.com1fc4c602009-10-02 16:34:57 +00001021 // blitters should ignore the presence/absence of a filter, since
1022 // if there is one, the shader will take care of it.
reed@android.com8a1c16f2008-12-17 15:59:43 +00001023 }
reed@google.com82065d62011-02-07 15:30:46 +00001024
reed@google.coma641f3f2012-12-13 22:16:30 +00001025 /*
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +00001026 * We create a SkShader::Context object, and store it on the blitter.
reed@google.coma641f3f2012-12-13 22:16:30 +00001027 */
Florin Malita4aed1382017-05-25 10:38:07 -04001028 SkShaderBase::Context* shaderContext = nullptr;
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +00001029 if (shader) {
Florin Malita4aed1382017-05-25 10:38:07 -04001030 const SkShaderBase::ContextRec rec(*paint, matrix, nullptr,
Brian Osman11970e52016-12-05 15:26:50 -05001031 PreferredShaderDest(device.info()),
1032 device.colorSpace());
Herb Derby83e939b2017-02-07 14:25:11 -05001033 // Try to create the ShaderContext
1034 shaderContext = shader->makeContext(rec, alloc);
1035 if (!shaderContext) {
1036 return alloc->make<SkNullBlitter>();
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +00001037 }
Herb Derby83e939b2017-02-07 14:25:11 -05001038 SkASSERT(shaderContext);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001039 }
1040
halcanary96fcdcc2015-08-27 07:41:13 -07001041 SkBlitter* blitter = nullptr;
reed@google.com900ecf22014-02-20 20:55:37 +00001042 switch (device.colorType()) {
commit-bot@chromium.org28fcae22014-04-11 17:15:40 +00001043 case kN32_SkColorType:
Florin Malita9b868f72017-05-25 16:43:43 -04001044 // sRGB and general color spaces are handled via raster pipeline.
1045 SkASSERT(!device.colorSpace());
1046
1047 if (shader) {
1048 blitter = alloc->make<SkARGB32_Shader_Blitter>(device, *paint, shaderContext);
1049 } else if (paint->getColor() == SK_ColorBLACK) {
1050 blitter = alloc->make<SkARGB32_Black_Blitter>(device, *paint);
1051 } else if (paint->getAlpha() == 0xFF) {
1052 blitter = alloc->make<SkARGB32_Opaque_Blitter>(device, *paint);
reed@google.com82065d62011-02-07 15:30:46 +00001053 } else {
Florin Malita9b868f72017-05-25 16:43:43 -04001054 blitter = alloc->make<SkARGB32_Blitter>(device, *paint);
reed@google.com82065d62011-02-07 15:30:46 +00001055 }
1056 break;
1057
1058 default:
Mike Reedb5d9e852017-06-02 23:14:07 -04001059 // should have been handled via raster pipeline.
1060 SkASSERT(false);
reed@google.com82065d62011-02-07 15:30:46 +00001061 break;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001062 }
1063
reed129ed1c2016-02-22 06:42:31 -08001064 if (!blitter) {
Herb Derby83e939b2017-02-07 14:25:11 -05001065 blitter = alloc->make<SkNullBlitter>();
reed129ed1c2016-02-22 06:42:31 -08001066 }
1067
reed@google.com82065d62011-02-07 15:30:46 +00001068 if (shader3D) {
commit-bot@chromium.orga5572e52014-03-07 03:24:41 +00001069 SkBlitter* innerBlitter = blitter;
Herb Derby83e939b2017-02-07 14:25:11 -05001070 // FIXME - comment about allocator
commit-bot@chromium.orga5572e52014-03-07 03:24:41 +00001071 // innerBlitter was allocated by allocator, which will delete it.
reedcc0e3112014-09-10 10:20:24 -07001072 // We know shaderContext or its proxies is of type Sk3DShaderContext, so we need to
1073 // wrapper the blitter to notify it when we see an emboss mask.
Herb Derby83e939b2017-02-07 14:25:11 -05001074 blitter = alloc->make<Sk3DBlitter>(innerBlitter, shaderContext);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001075 }
1076 return blitter;
1077}
1078
reed@google.com82065d62011-02-07 15:30:46 +00001079///////////////////////////////////////////////////////////////////////////////
reed@android.com8a1c16f2008-12-17 15:59:43 +00001080
reed41e010c2015-06-09 12:16:53 -07001081SkShaderBlitter::SkShaderBlitter(const SkPixmap& device, const SkPaint& paint,
Florin Malita4aed1382017-05-25 10:38:07 -04001082 SkShaderBase::Context* shaderContext)
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +00001083 : INHERITED(device)
1084 , fShader(paint.getShader())
1085 , fShaderContext(shaderContext) {
reed@android.com8a1c16f2008-12-17 15:59:43 +00001086 SkASSERT(fShader);
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +00001087 SkASSERT(fShaderContext);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001088
1089 fShader->ref();
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +00001090 fShaderFlags = fShaderContext->getFlags();
Florin Malita4aed1382017-05-25 10:38:07 -04001091 fConstInY = SkToBool(fShaderFlags & SkShaderBase::kConstInY32_Flag);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001092}
1093
reed@android.com5119bdb2009-06-12 21:27:03 +00001094SkShaderBlitter::~SkShaderBlitter() {
reed@android.com8a1c16f2008-12-17 15:59:43 +00001095 fShader->unref();
1096}
commit-bot@chromium.org87fcd952014-04-23 19:10:51 +00001097
Mike Reed28930b42016-11-09 15:23:26 -05001098///////////////////////////////////////////////////////////////////////////////////////////////////
1099
1100#ifdef SK_DEBUG
1101
1102void SkRectClipCheckBlitter::blitH(int x, int y, int width) {
1103 SkASSERT(fClipRect.contains(SkIRect::MakeXYWH(x, y, width, 1)));
1104 fBlitter->blitH(x, y, width);
1105}
1106
1107void SkRectClipCheckBlitter::blitAntiH(int x, int y, const SkAlpha aa[], const int16_t runs[]) {
1108 const int16_t* iter = runs;
1109 for (; *iter; iter += *iter)
1110 ;
1111 int width = iter - runs;
1112 SkASSERT(fClipRect.contains(SkIRect::MakeXYWH(x, y, width, 1)));
1113 fBlitter->blitAntiH(x, y, aa, runs);
1114}
1115
1116void SkRectClipCheckBlitter::blitV(int x, int y, int height, SkAlpha alpha) {
1117 SkASSERT(fClipRect.contains(SkIRect::MakeXYWH(x, y, 1, height)));
1118 fBlitter->blitV(x, y, height, alpha);
1119}
1120
1121void SkRectClipCheckBlitter::blitRect(int x, int y, int width, int height) {
1122 SkASSERT(fClipRect.contains(SkIRect::MakeXYWH(x, y, width, height)));
1123 fBlitter->blitRect(x, y, width, height);
1124}
1125
1126void SkRectClipCheckBlitter::blitAntiRect(int x, int y, int width, int height,
1127 SkAlpha leftAlpha, SkAlpha rightAlpha) {
Yuqian Li8b9a7252016-11-11 09:40:34 -05001128 bool skipLeft = !leftAlpha;
1129 bool skipRight = !rightAlpha;
1130 SkASSERT(fClipRect.contains(SkIRect::MakeXYWH(x + skipLeft, y,
1131 width + 2 - skipRight - skipLeft, height)));
Mike Reed28930b42016-11-09 15:23:26 -05001132 fBlitter->blitAntiRect(x, y, width, height, leftAlpha, rightAlpha);
1133}
1134
1135void SkRectClipCheckBlitter::blitMask(const SkMask& mask, const SkIRect& clip) {
1136 SkASSERT(mask.fBounds.contains(clip));
1137 SkASSERT(fClipRect.contains(clip));
1138 fBlitter->blitMask(mask, clip);
1139}
1140
1141const SkPixmap* SkRectClipCheckBlitter::justAnOpaqueColor(uint32_t* value) {
1142 return fBlitter->justAnOpaqueColor(value);
1143}
1144
Yuqian Li99bba9e2016-11-21 09:44:59 -05001145void SkRectClipCheckBlitter::blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) {
1146 SkASSERT(fClipRect.contains(SkIRect::MakeXYWH(x, y, 2, 1)));
1147 fBlitter->blitAntiH2(x, y, a0, a1);
1148}
1149
1150void SkRectClipCheckBlitter::blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) {
1151 SkASSERT(fClipRect.contains(SkIRect::MakeXYWH(x, y, 1, 2)));
1152 fBlitter->blitAntiV2(x, y, a0, a1);
1153}
1154
Mike Reed28930b42016-11-09 15:23:26 -05001155#endif