epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 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 Derby | 83e939b | 2017-02-07 14:25:11 -0500 | [diff] [blame] | 8 | #include "SkArenaAlloc.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 9 | #include "SkBlitter.h" |
| 10 | #include "SkAntiRun.h" |
| 11 | #include "SkColor.h" |
| 12 | #include "SkColorFilter.h" |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 13 | #include "SkReadBuffer.h" |
| 14 | #include "SkWriteBuffer.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 15 | #include "SkMask.h" |
| 16 | #include "SkMaskFilter.h" |
Florin Malita | d4a70ee | 2017-06-19 10:21:43 -0400 | [diff] [blame] | 17 | #include "SkPaintPriv.h" |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 18 | #include "SkShaderBase.h" |
commit-bot@chromium.org | a5572e5 | 2014-03-07 03:24:41 +0000 | [diff] [blame] | 19 | #include "SkString.h" |
reed@google.com | 4588490 | 2012-05-11 14:38:51 +0000 | [diff] [blame] | 20 | #include "SkTLazy.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 21 | #include "SkUtils.h" |
halcanary | a681433 | 2015-05-27 08:53:36 -0700 | [diff] [blame] | 22 | #include "SkXfermodeInterpretation.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 23 | |
reed@android.com | 845fdac | 2009-06-23 03:01:32 +0000 | [diff] [blame] | 24 | SkBlitter::~SkBlitter() {} |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 25 | |
reed@google.com | ea03360 | 2012-12-14 13:13:55 +0000 | [diff] [blame] | 26 | bool SkBlitter::isNullBlitter() const { return false; } |
| 27 | |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 28 | const SkPixmap* SkBlitter::justAnOpaqueColor(uint32_t* value) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 29 | return nullptr; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 30 | } |
| 31 | |
herb | 7df9e4a | 2016-06-10 13:01:27 -0700 | [diff] [blame] | 32 | /* |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 33 | void SkBlitter::blitH(int x, int y, int width) { |
tomhudson@google.com | 0c00f21 | 2011-12-28 14:59:50 +0000 | [diff] [blame] | 34 | SkDEBUGFAIL("unimplemented"); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 35 | } |
| 36 | |
herb | 7df9e4a | 2016-06-10 13:01:27 -0700 | [diff] [blame] | 37 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 38 | void SkBlitter::blitAntiH(int x, int y, const SkAlpha antialias[], |
| 39 | const int16_t runs[]) { |
tomhudson@google.com | 0c00f21 | 2011-12-28 14:59:50 +0000 | [diff] [blame] | 40 | SkDEBUGFAIL("unimplemented"); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 41 | } |
herb | 7df9e4a | 2016-06-10 13:01:27 -0700 | [diff] [blame] | 42 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 43 | |
Yuqian Li | df60e36 | 2017-07-25 11:26:31 -0400 | [diff] [blame] | 44 | inline static SkAlpha ScalarToAlpha(SkScalar a) { |
| 45 | return (SkAlpha)(a * 255); |
| 46 | } |
| 47 | |
Mike Klein | ad04a4b | 2017-09-18 19:29:24 +0000 | [diff] [blame] | 48 | void SkBlitter::blitFatAntiRect(const SkRect& rect) { |
| 49 | SkIRect bounds = rect.roundOut(); |
| 50 | SkASSERT(bounds.width() >= 3 && bounds.height() >= 3); |
Yuqian Li | df60e36 | 2017-07-25 11:26:31 -0400 | [diff] [blame] | 51 | |
| 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 | |
| 81 | void 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 Li | bd40a5b | 2017-09-01 15:38:45 -0400 | [diff] [blame] | 101 | // If there are too many deltas, sorting will be slow. Using a mask is much faster. |
Yuqian Li | df60e36 | 2017-07-25 11:26:31 -0400 | [diff] [blame] | 102 | // 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 Li | bd40a5b | 2017-09-01 15:38:45 -0400 | [diff] [blame] | 106 | SkSTArenaAlloc<SkCoverageDeltaMask::MAX_SIZE> alloc; |
| 107 | SkCoverageDeltaMask mask(&alloc, rowIR); |
Yuqian Li | df60e36 | 2017-07-25 11:26:31 -0400 | [diff] [blame] | 108 | 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.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 149 | void SkBlitter::blitV(int x, int y, int height, SkAlpha alpha) { |
| 150 | if (alpha == 255) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 151 | this->blitRect(x, y, 1, height); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 152 | } else { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 153 | int16_t runs[2]; |
| 154 | runs[0] = 1; |
| 155 | runs[1] = 0; |
| 156 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 157 | while (--height >= 0) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 158 | this->blitAntiH(x, y++, &alpha, runs); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 159 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 160 | } |
| 161 | } |
| 162 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 163 | void SkBlitter::blitRect(int x, int y, int width, int height) { |
tomhudson@google.com | a31ac73 | 2011-12-29 16:09:31 +0000 | [diff] [blame] | 164 | SkASSERT(width > 0); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 165 | while (--height >= 0) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 166 | this->blitH(x, y++, width); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 167 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 168 | } |
| 169 | |
liyuqian | 38911a7 | 2016-10-04 11:23:22 -0700 | [diff] [blame] | 170 | /// Default implementation doesn't check for easy optimizations |
| 171 | /// such as alpha == 255; also uses blitV(), which some subclasses |
tomhudson@google.com | 49eac19 | 2011-12-27 13:59:20 +0000 | [diff] [blame] | 172 | /// may not support. |
| 173 | void SkBlitter::blitAntiRect(int x, int y, int width, int height, |
| 174 | SkAlpha leftAlpha, SkAlpha rightAlpha) { |
liyuqian | 38911a7 | 2016-10-04 11:23:22 -0700 | [diff] [blame] | 175 | if (leftAlpha > 0) { // we may send in x = -1 with leftAlpha = 0 |
| 176 | this->blitV(x, y, height, leftAlpha); |
| 177 | } |
| 178 | x++; |
tomhudson@google.com | a31ac73 | 2011-12-29 16:09:31 +0000 | [diff] [blame] | 179 | if (width > 0) { |
tomhudson@google.com | 4714359 | 2011-12-28 17:58:07 +0000 | [diff] [blame] | 180 | this->blitRect(x, y, width, height); |
| 181 | x += width; |
| 182 | } |
liyuqian | 38911a7 | 2016-10-04 11:23:22 -0700 | [diff] [blame] | 183 | if (rightAlpha > 0) { |
| 184 | this->blitV(x, y, height, rightAlpha); |
| 185 | } |
tomhudson@google.com | 49eac19 | 2011-12-27 13:59:20 +0000 | [diff] [blame] | 186 | } |
| 187 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 188 | ////////////////////////////////////////////////////////////////////////////// |
| 189 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 190 | static inline void bits_to_runs(SkBlitter* blitter, int x, int y, |
| 191 | const uint8_t bits[], |
herb | 5520ded | 2015-11-18 10:50:33 -0800 | [diff] [blame] | 192 | uint8_t left_mask, ptrdiff_t rowBytes, |
| 193 | uint8_t right_mask) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 194 | int inFill = 0; |
| 195 | int pos = 0; |
| 196 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 197 | while (--rowBytes >= 0) { |
herb | 5520ded | 2015-11-18 10:50:33 -0800 | [diff] [blame] | 198 | uint8_t b = *bits++ & left_mask; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 199 | if (rowBytes == 0) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 200 | b &= right_mask; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 201 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 202 | |
herb | 5520ded | 2015-11-18 10:50:33 -0800 | [diff] [blame] | 203 | for (uint8_t test = 0x80U; test != 0; test >>= 1) { |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 204 | if (b & test) { |
| 205 | if (!inFill) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 206 | pos = x; |
| 207 | inFill = true; |
| 208 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 209 | } else { |
| 210 | if (inFill) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 211 | blitter->blitH(pos, y, x - pos); |
| 212 | inFill = false; |
| 213 | } |
| 214 | } |
| 215 | x += 1; |
| 216 | } |
herb | 5520ded | 2015-11-18 10:50:33 -0800 | [diff] [blame] | 217 | left_mask = 0xFFU; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | // final cleanup |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 221 | if (inFill) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 222 | blitter->blitH(pos, y, x - pos); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 223 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 224 | } |
| 225 | |
herb | 5520ded | 2015-11-18 10:50:33 -0800 | [diff] [blame] | 226 | // maskBitCount is the number of 1's to place in the mask. It must be in the range between 1 and 8. |
| 227 | static uint8_t generate_right_mask(int maskBitCount) { |
| 228 | return static_cast<uint8_t>(0xFF00U >> maskBitCount); |
| 229 | } |
| 230 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 231 | void SkBlitter::blitMask(const SkMask& mask, const SkIRect& clip) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 232 | SkASSERT(mask.fBounds.contains(clip)); |
| 233 | |
reed | d96e7e5 | 2016-02-17 07:15:29 -0800 | [diff] [blame] | 234 | if (mask.fFormat == SkMask::kLCD16_Format) { |
| 235 | return; // needs to be handled by subclass |
| 236 | } |
| 237 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 238 | if (mask.fFormat == SkMask::kBW_Format) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 239 | int cx = clip.fLeft; |
| 240 | int cy = clip.fTop; |
| 241 | int maskLeft = mask.fBounds.fLeft; |
herb | 5520ded | 2015-11-18 10:50:33 -0800 | [diff] [blame] | 242 | int maskRowBytes = mask.fRowBytes; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 243 | int height = clip.height(); |
| 244 | |
| 245 | const uint8_t* bits = mask.getAddr1(cx, cy); |
| 246 | |
herb | 5520ded | 2015-11-18 10:50:33 -0800 | [diff] [blame] | 247 | SkDEBUGCODE(const uint8_t* endOfImage = |
| 248 | mask.fImage + (mask.fBounds.height() - 1) * maskRowBytes |
| 249 | + ((mask.fBounds.width() + 7) >> 3)); |
| 250 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 251 | if (cx == maskLeft && clip.fRight == mask.fBounds.fRight) { |
| 252 | while (--height >= 0) { |
herb | 5520ded | 2015-11-18 10:50:33 -0800 | [diff] [blame] | 253 | 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.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 259 | cy += 1; |
| 260 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 261 | } else { |
herb | 3be72b0 | 2016-06-24 13:02:31 -0700 | [diff] [blame] | 262 | // Bits is calculated as the offset into the mask at the point {cx, cy} therefore, all |
herb | 5520ded | 2015-11-18 10:50:33 -0800 | [diff] [blame] | 263 | // 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.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 266 | |
herb | 5520ded | 2015-11-18 10:50:33 -0800 | [diff] [blame] | 267 | // 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.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 272 | |
herb | 5520ded | 2015-11-18 10:50:33 -0800 | [diff] [blame] | 273 | // Calculate left byte and mask |
| 274 | const uint8_t* leftByte = bits; |
| 275 | U8CPU leftMask = 0xFFU >> (leftEdge & 7); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 276 | |
herb | 5520ded | 2015-11-18 10:50:33 -0800 | [diff] [blame] | 277 | // 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.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 281 | |
herb | 5520ded | 2015-11-18 10:50:33 -0800 | [diff] [blame] | 282 | // 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.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 291 | } |
| 292 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 293 | } else { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 294 | int width = clip.width(); |
| 295 | SkAutoSTMalloc<64, int16_t> runStorage(width + 1); |
| 296 | int16_t* runs = runStorage.get(); |
reed@google.com | 7989186 | 2011-10-18 15:44:57 +0000 | [diff] [blame] | 297 | const uint8_t* aa = mask.getAddr8(clip.fLeft, clip.fTop); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 298 | |
| 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.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 304 | while (--height >= 0) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 305 | 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 | |
| 314 | void SkBlitter::blitMaskRegion(const SkMask& mask, const SkRegion& clip) { |
| 315 | if (clip.quickReject(mask.fBounds)) { |
| 316 | return; |
| 317 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 318 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 319 | SkRegion::Cliperator clipper(clip, mask.fBounds); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 320 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 321 | while (!clipper.done()) { |
| 322 | const SkIRect& cr = clipper.rect(); |
| 323 | this->blitMask(mask, cr); |
| 324 | clipper.next(); |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | void SkBlitter::blitRectRegion(const SkIRect& rect, const SkRegion& clip) { |
| 329 | SkRegion::Cliperator clipper(clip, rect); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 330 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 331 | 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 | |
| 338 | void SkBlitter::blitRegion(const SkRegion& clip) { |
| 339 | SkRegion::Iterator iter(clip); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 340 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 341 | 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.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 348 | /////////////////////////////////////////////////////////////////////////////// |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 349 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 350 | void SkNullBlitter::blitH(int x, int y, int width) {} |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 351 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 352 | void SkNullBlitter::blitAntiH(int x, int y, const SkAlpha antialias[], |
| 353 | const int16_t runs[]) {} |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 354 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 355 | void SkNullBlitter::blitV(int x, int y, int height, SkAlpha alpha) {} |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 356 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 357 | void SkNullBlitter::blitRect(int x, int y, int width, int height) {} |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 358 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 359 | void SkNullBlitter::blitMask(const SkMask& mask, const SkIRect& clip) {} |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 360 | |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 361 | const SkPixmap* SkNullBlitter::justAnOpaqueColor(uint32_t* value) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 362 | return nullptr; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 363 | } |
| 364 | |
reed@google.com | ea03360 | 2012-12-14 13:13:55 +0000 | [diff] [blame] | 365 | bool SkNullBlitter::isNullBlitter() const { return true; } |
| 366 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 367 | /////////////////////////////////////////////////////////////////////////////// |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 368 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 369 | static int compute_anti_width(const int16_t runs[]) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 370 | int width = 0; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 371 | |
| 372 | for (;;) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 373 | int count = runs[0]; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 374 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 375 | SkASSERT(count >= 0); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 376 | if (count == 0) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 377 | break; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 378 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 379 | width += count; |
| 380 | runs += count; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 381 | } |
| 382 | return width; |
| 383 | } |
| 384 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 385 | static inline bool y_in_rect(int y, const SkIRect& rect) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 386 | return (unsigned)(y - rect.fTop) < (unsigned)rect.height(); |
| 387 | } |
| 388 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 389 | static inline bool x_in_rect(int x, const SkIRect& rect) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 390 | return (unsigned)(x - rect.fLeft) < (unsigned)rect.width(); |
| 391 | } |
| 392 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 393 | void SkRectClipBlitter::blitH(int left, int y, int width) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 394 | SkASSERT(width > 0); |
| 395 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 396 | if (!y_in_rect(y, fClipRect)) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 397 | return; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 398 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 399 | |
| 400 | int right = left + width; |
| 401 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 402 | if (left < fClipRect.fLeft) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 403 | left = fClipRect.fLeft; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 404 | } |
| 405 | if (right > fClipRect.fRight) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 406 | right = fClipRect.fRight; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 407 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 408 | |
| 409 | width = right - left; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 410 | if (width > 0) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 411 | fBlitter->blitH(left, y, width); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 412 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 413 | } |
| 414 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 415 | void 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.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 418 | return; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 419 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 420 | |
| 421 | int x0 = left; |
| 422 | int x1 = left + compute_anti_width(runs); |
| 423 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 424 | if (x1 <= fClipRect.fLeft) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 425 | return; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 426 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 427 | |
| 428 | SkASSERT(x0 < x1); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 429 | if (x0 < fClipRect.fLeft) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 430 | 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.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 438 | if (x1 > fClipRect.fRight) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 439 | 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.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 450 | void SkRectClipBlitter::blitV(int x, int y, int height, SkAlpha alpha) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 451 | SkASSERT(height > 0); |
| 452 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 453 | if (!x_in_rect(x, fClipRect)) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 454 | return; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 455 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 456 | |
| 457 | int y0 = y; |
| 458 | int y1 = y + height; |
| 459 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 460 | if (y0 < fClipRect.fTop) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 461 | y0 = fClipRect.fTop; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 462 | } |
| 463 | if (y1 > fClipRect.fBottom) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 464 | y1 = fClipRect.fBottom; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 465 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 466 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 467 | if (y0 < y1) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 468 | fBlitter->blitV(x, y0, y1 - y0, alpha); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 469 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 470 | } |
| 471 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 472 | void SkRectClipBlitter::blitRect(int left, int y, int width, int height) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 473 | SkIRect r; |
| 474 | |
| 475 | r.set(left, y, left + width, y + height); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 476 | if (r.intersect(fClipRect)) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 477 | fBlitter->blitRect(r.fLeft, r.fTop, r.width(), r.height()); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 478 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 479 | } |
| 480 | |
tomhudson@google.com | 49eac19 | 2011-12-27 13:59:20 +0000 | [diff] [blame] | 481 | void 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.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 512 | void SkRectClipBlitter::blitMask(const SkMask& mask, const SkIRect& clip) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 513 | SkASSERT(mask.fBounds.contains(clip)); |
| 514 | |
| 515 | SkIRect r = clip; |
| 516 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 517 | if (r.intersect(fClipRect)) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 518 | fBlitter->blitMask(mask, r); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 519 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 520 | } |
| 521 | |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 522 | const SkPixmap* SkRectClipBlitter::justAnOpaqueColor(uint32_t* value) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 523 | return fBlitter->justAnOpaqueColor(value); |
| 524 | } |
| 525 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 526 | /////////////////////////////////////////////////////////////////////////////// |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 527 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 528 | void SkRgnClipBlitter::blitH(int x, int y, int width) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 529 | SkRegion::Spanerator span(*fRgn, y, x, x + width); |
| 530 | int left, right; |
| 531 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 532 | while (span.next(&left, &right)) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 533 | SkASSERT(left < right); |
| 534 | fBlitter->blitH(left, y, right - left); |
| 535 | } |
| 536 | } |
| 537 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 538 | void SkRgnClipBlitter::blitAntiH(int x, int y, const SkAlpha aa[], |
| 539 | const int16_t runs[]) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 540 | 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.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 544 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 545 | int prevRite = x; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 546 | while (span.next(&left, &right)) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 547 | SkASSERT(x <= left); |
| 548 | SkASSERT(left < right); |
| 549 | SkASSERT(left >= bounds.fLeft && right <= bounds.fRight); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 550 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 551 | SkAlphaRuns::Break((int16_t*)runs, (uint8_t*)aa, left - x, right - left); |
| 552 | |
| 553 | // now zero before left |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 554 | if (left > prevRite) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 555 | 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.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 559 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 560 | prevRite = right; |
| 561 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 562 | |
| 563 | if (prevRite > x) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 564 | ((int16_t*)runs)[prevRite - x] = 0; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 565 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 566 | 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.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 577 | void SkRgnClipBlitter::blitV(int x, int y, int height, SkAlpha alpha) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 578 | SkIRect bounds; |
| 579 | bounds.set(x, y, x + 1, y + height); |
| 580 | |
| 581 | SkRegion::Cliperator iter(*fRgn, bounds); |
| 582 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 583 | while (!iter.done()) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 584 | 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.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 592 | void SkRgnClipBlitter::blitRect(int x, int y, int width, int height) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 593 | SkIRect bounds; |
| 594 | bounds.set(x, y, x + width, y + height); |
| 595 | |
| 596 | SkRegion::Cliperator iter(*fRgn, bounds); |
| 597 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 598 | while (!iter.done()) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 599 | 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.com | 49eac19 | 2011-12-27 13:59:20 +0000 | [diff] [blame] | 607 | void 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.com | 31bab39 | 2012-01-03 20:12:42 +0000 | [diff] [blame] | 619 | SkASSERT(r.fRight <= x + width + 2); |
tomhudson@google.com | 49eac19 | 2011-12-27 13:59:20 +0000 | [diff] [blame] | 620 | |
| 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.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 629 | fBlitter->blitV(r.fLeft, r.fTop, r.height(), |
tomhudson@google.com | 49eac19 | 2011-12-27 13:59:20 +0000 | [diff] [blame] | 630 | 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.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 645 | void SkRgnClipBlitter::blitMask(const SkMask& mask, const SkIRect& clip) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 646 | 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.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 652 | while (!iter.done()) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 653 | blitter->blitMask(mask, r); |
| 654 | iter.next(); |
| 655 | } |
| 656 | } |
| 657 | |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 658 | const SkPixmap* SkRgnClipBlitter::justAnOpaqueColor(uint32_t* value) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 659 | return fBlitter->justAnOpaqueColor(value); |
| 660 | } |
| 661 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 662 | /////////////////////////////////////////////////////////////////////////////// |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 663 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 664 | SkBlitter* SkBlitterClipper::apply(SkBlitter* blitter, const SkRegion* clip, |
| 665 | const SkIRect* ir) { |
| 666 | if (clip) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 667 | const SkIRect& clipR = clip->getBounds(); |
| 668 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 669 | if (clip->isEmpty() || (ir && !SkIRect::Intersects(clipR, *ir))) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 670 | blitter = &fNullBlitter; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 671 | } else if (clip->isRect()) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 672 | if (ir == nullptr || !clipR.contains(*ir)) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 673 | fRectBlitter.init(blitter, clipR); |
| 674 | blitter = &fRectBlitter; |
| 675 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 676 | } else { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 677 | fRgnBlitter.init(blitter, clip); |
| 678 | blitter = &fRgnBlitter; |
| 679 | } |
| 680 | } |
| 681 | return blitter; |
| 682 | } |
| 683 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 684 | /////////////////////////////////////////////////////////////////////////////// |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 685 | |
| 686 | #include "SkColorShader.h" |
Cary Clark | a4083c9 | 2017-09-15 11:59:23 -0400 | [diff] [blame] | 687 | #include "SkColorData.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 688 | |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 689 | class Sk3DShader : public SkShaderBase { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 690 | public: |
reed | 8a21c9f | 2016-03-08 18:50:00 -0800 | [diff] [blame] | 691 | Sk3DShader(sk_sp<SkShader> proxy) : fProxy(std::move(proxy)) {} |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 692 | |
Herb Derby | 83e939b | 2017-02-07 14:25:11 -0500 | [diff] [blame] | 693 | Context* onMakeContext(const ContextRec& rec, SkArenaAlloc* alloc) const override { |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 694 | SkShaderBase::Context* proxyContext = nullptr; |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 695 | if (fProxy) { |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 696 | proxyContext = as_SB(fProxy)->makeContext(rec, alloc); |
commit-bot@chromium.org | ce56d96 | 2014-05-05 18:39:18 +0000 | [diff] [blame] | 697 | if (!proxyContext) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 698 | return nullptr; |
commit-bot@chromium.org | ce56d96 | 2014-05-05 18:39:18 +0000 | [diff] [blame] | 699 | } |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 700 | } |
Herb Derby | 83e939b | 2017-02-07 14:25:11 -0500 | [diff] [blame] | 701 | return alloc->make<Sk3DShaderContext>(*this, rec, proxyContext); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 702 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 703 | |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 704 | class Sk3DShaderContext : public Context { |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 705 | public: |
| 706 | // Calls proxyContext's destructor but will NOT free its memory. |
commit-bot@chromium.org | e901b6d | 2014-05-01 19:31:31 +0000 | [diff] [blame] | 707 | Sk3DShaderContext(const Sk3DShader& shader, const ContextRec& rec, |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 708 | Context* proxyContext) |
commit-bot@chromium.org | e901b6d | 2014-05-01 19:31:31 +0000 | [diff] [blame] | 709 | : INHERITED(shader, rec) |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 710 | , fMask(nullptr) |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 711 | , fProxyContext(proxyContext) |
| 712 | { |
| 713 | if (!fProxyContext) { |
commit-bot@chromium.org | e901b6d | 2014-05-01 19:31:31 +0000 | [diff] [blame] | 714 | fPMColor = SkPreMultiplyColor(rec.fPaint->getColor()); |
commit-bot@chromium.org | bc2f1dc | 2014-04-23 09:11:58 +0000 | [diff] [blame] | 715 | } |
| 716 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 717 | |
Brian Salomon | d3b6597 | 2017-03-22 12:05:03 -0400 | [diff] [blame] | 718 | ~Sk3DShaderContext() override { |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 719 | if (fProxyContext) { |
| 720 | fProxyContext->~Context(); |
| 721 | } |
| 722 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 723 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 724 | void set3DMask(const SkMask* mask) override { fMask = mask; } |
commit-bot@chromium.org | 001f4ed | 2014-04-16 10:16:39 +0000 | [diff] [blame] | 725 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 726 | void shadeSpan(int x, int y, SkPMColor span[], int count) override { |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 727 | if (fProxyContext) { |
| 728 | fProxyContext->shadeSpan(x, y, span, count); |
| 729 | } |
commit-bot@chromium.org | bc2f1dc | 2014-04-23 09:11:58 +0000 | [diff] [blame] | 730 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 731 | if (fMask == nullptr) { |
| 732 | if (fProxyContext == nullptr) { |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 733 | 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.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 776 | unsigned mul = SkAlpha255To256(mulp[i]); |
| 777 | unsigned add = addp[i]; |
| 778 | |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 779 | 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.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 785 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 786 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 787 | } |
| 788 | } |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 789 | |
| 790 | private: |
| 791 | // Unowned. |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 792 | const SkMask* fMask; |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 793 | // Memory is unowned, but we need to call the destructor. |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 794 | Context* fProxyContext; |
| 795 | SkPMColor fPMColor; |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 796 | |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 797 | typedef Context INHERITED; |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 798 | }; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 799 | |
commit-bot@chromium.org | 0f10f7b | 2014-03-13 18:02:17 +0000 | [diff] [blame] | 800 | #ifndef SK_IGNORE_TO_STRING |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 801 | void toString(SkString* str) const override { |
robertphillips@google.com | 76f9e93 | 2013-01-15 20:17:47 +0000 | [diff] [blame] | 802 | str->append("Sk3DShader: ("); |
| 803 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 804 | if (fProxy) { |
robertphillips@google.com | 76f9e93 | 2013-01-15 20:17:47 +0000 | [diff] [blame] | 805 | str->append("Proxy: "); |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 806 | as_SB(fProxy)->toString(str); |
robertphillips@google.com | 76f9e93 | 2013-01-15 20:17:47 +0000 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | this->INHERITED::toString(str); |
| 810 | |
| 811 | str->append(")"); |
| 812 | } |
| 813 | #endif |
| 814 | |
djsollen@google.com | ba28d03 | 2012-03-26 17:57:35 +0000 | [diff] [blame] | 815 | SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(Sk3DShader) |
| 816 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 817 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 818 | void flatten(SkWriteBuffer& buffer) const override { |
reed | 8a21c9f | 2016-03-08 18:50:00 -0800 | [diff] [blame] | 819 | buffer.writeFlattenable(fProxy.get()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 820 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 821 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 822 | private: |
reed | 8a21c9f | 2016-03-08 18:50:00 -0800 | [diff] [blame] | 823 | sk_sp<SkShader> fProxy; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 824 | |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 825 | typedef SkShaderBase INHERITED; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 826 | }; |
| 827 | |
reed | 60c9b58 | 2016-04-03 09:11:13 -0700 | [diff] [blame] | 828 | sk_sp<SkFlattenable> Sk3DShader::CreateProc(SkReadBuffer& buffer) { |
| 829 | return sk_make_sp<Sk3DShader>(buffer.readShader()); |
reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 830 | } |
| 831 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 832 | class Sk3DBlitter : public SkBlitter { |
| 833 | public: |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 834 | Sk3DBlitter(SkBlitter* proxy, SkShaderBase::Context* shaderContext) |
commit-bot@chromium.org | a5572e5 | 2014-03-07 03:24:41 +0000 | [diff] [blame] | 835 | : fProxy(proxy) |
reed | cc0e311 | 2014-09-10 10:20:24 -0700 | [diff] [blame] | 836 | , fShaderContext(shaderContext) |
commit-bot@chromium.org | a5572e5 | 2014-03-07 03:24:41 +0000 | [diff] [blame] | 837 | {} |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 838 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 839 | void blitH(int x, int y, int width) override { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 840 | fProxy->blitH(x, y, width); |
| 841 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 842 | |
reed | 60c9b58 | 2016-04-03 09:11:13 -0700 | [diff] [blame] | 843 | void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) override { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 844 | fProxy->blitAntiH(x, y, antialias, runs); |
| 845 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 846 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 847 | void blitV(int x, int y, int height, SkAlpha alpha) override { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 848 | fProxy->blitV(x, y, height, alpha); |
| 849 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 850 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 851 | void blitRect(int x, int y, int width, int height) override { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 852 | fProxy->blitRect(x, y, width, height); |
| 853 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 854 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 855 | void blitMask(const SkMask& mask, const SkIRect& clip) override { |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 856 | if (mask.fFormat == SkMask::k3D_Format) { |
reed | cc0e311 | 2014-09-10 10:20:24 -0700 | [diff] [blame] | 857 | fShaderContext->set3DMask(&mask); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 858 | |
| 859 | ((SkMask*)&mask)->fFormat = SkMask::kA8_Format; |
| 860 | fProxy->blitMask(mask, clip); |
| 861 | ((SkMask*)&mask)->fFormat = SkMask::k3D_Format; |
| 862 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 863 | fShaderContext->set3DMask(nullptr); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 864 | } else { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 865 | fProxy->blitMask(mask, clip); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 866 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 867 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 868 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 869 | private: |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 870 | // Both pointers are unowned. They will be deleted by SkSmallAllocator. |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 871 | SkBlitter* fProxy; |
| 872 | SkShaderBase::Context* fShaderContext; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 873 | }; |
| 874 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 875 | /////////////////////////////////////////////////////////////////////////////// |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 876 | |
| 877 | #include "SkCoreBlitters.h" |
| 878 | |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 879 | SkShaderBase::ContextRec::DstType SkBlitter::PreferredShaderDest(const SkImageInfo& dstInfo) { |
reed | 960b2d6 | 2016-06-17 09:26:41 -0700 | [diff] [blame] | 880 | return (dstInfo.gammaCloseToSRGB() || dstInfo.colorType() == kRGBA_F16_SkColorType) |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 881 | ? SkShaderBase::ContextRec::kPM4f_DstType |
| 882 | : SkShaderBase::ContextRec::kPMColor_DstType; |
fmalita | d0c4e09 | 2016-02-22 17:19:04 -0800 | [diff] [blame] | 883 | } |
| 884 | |
Mike Reed | c928fe2 | 2017-06-05 10:20:31 -0400 | [diff] [blame] | 885 | // hack for testing, not to be exposed to clients |
| 886 | bool gSkForceRasterPipelineBlitter; |
| 887 | |
Florin Malita | c4176a2 | 2017-07-11 22:47:21 -0400 | [diff] [blame] | 888 | bool SkBlitter::UseRasterPipelineBlitter(const SkPixmap& device, const SkPaint& paint, |
| 889 | const SkMatrix& matrix) { |
Mike Reed | c928fe2 | 2017-06-05 10:20:31 -0400 | [diff] [blame] | 890 | if (gSkForceRasterPipelineBlitter) { |
| 891 | return true; |
| 892 | } |
Mike Reed | 883c9bc | 2017-07-19 10:57:53 -0400 | [diff] [blame] | 893 | if (device.info().alphaType() == kUnpremul_SkAlphaType) { |
| 894 | return true; |
| 895 | } |
Mike Klein | 9beafc4 | 2017-06-05 06:32:21 -0400 | [diff] [blame] | 896 | #if 0 || defined(SK_FORCE_RASTER_PIPELINE_BLITTER) |
Mike Klein | b60acfc | 2017-05-10 16:13:35 -0400 | [diff] [blame] | 897 | 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 Reed | 428266d | 2017-06-24 18:17:49 -0400 | [diff] [blame] | 903 | if (paint.getColorFilter()) { |
| 904 | return true; |
| 905 | } |
Mike Reed | 90ca377 | 2017-06-28 10:53:36 -0400 | [diff] [blame] | 906 | if (paint.getFilterQuality() == kHigh_SkFilterQuality) { |
| 907 | return true; |
| 908 | } |
Florin Malita | 5769dd2 | 2017-07-12 13:31:25 -0400 | [diff] [blame] | 909 | // ... unless the blend mode is complicated enough. |
Mike Klein | b2ef4d6 | 2017-05-25 16:23:09 -0400 | [diff] [blame] | 910 | if (paint.getBlendMode() > SkBlendMode::kLastSeparableMode) { |
| 911 | return true; |
| 912 | } |
Florin Malita | 5769dd2 | 2017-07-12 13:31:25 -0400 | [diff] [blame] | 913 | if (matrix.hasPerspective()) { |
| 914 | return true; |
| 915 | } |
Florin Malita | 5769dd2 | 2017-07-12 13:31:25 -0400 | [diff] [blame] | 916 | // ... or unless the shader is raster pipeline-only. |
Mike Reed | 3404207 | 2017-08-08 16:29:22 -0400 | [diff] [blame] | 917 | if (paint.getShader() && as_SB(paint.getShader())->isRasterPipelineOnly(matrix)) { |
Florin Malita | c4176a2 | 2017-07-11 22:47:21 -0400 | [diff] [blame] | 918 | return true; |
| 919 | } |
| 920 | |
Mike Klein | b60acfc | 2017-05-10 16:13:35 -0400 | [diff] [blame] | 921 | return device.colorType() != kN32_SkColorType; |
| 922 | #endif |
| 923 | } |
| 924 | |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 925 | SkBlitter* SkBlitter::Choose(const SkPixmap& device, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 926 | const SkMatrix& matrix, |
reed@google.com | 6b7aee3 | 2011-04-19 18:36:09 +0000 | [diff] [blame] | 927 | const SkPaint& origPaint, |
Herb Derby | 83e939b | 2017-02-07 14:25:11 -0500 | [diff] [blame] | 928 | SkArenaAlloc* alloc, |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 929 | bool drawCoverage) { |
Herb Derby | 83e939b | 2017-02-07 14:25:11 -0500 | [diff] [blame] | 930 | SkASSERT(alloc != nullptr); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 931 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 932 | // 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.com | 900ecf2 | 2014-02-20 20:55:37 +0000 | [diff] [blame] | 934 | if (kUnknown_SkColorType == device.colorType() || |
| 935 | (drawCoverage && (kAlpha_8_SkColorType != device.colorType()))) { |
Herb Derby | 83e939b | 2017-02-07 14:25:11 -0500 | [diff] [blame] | 936 | return alloc->make<SkNullBlitter>(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 937 | } |
| 938 | |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 939 | auto* shader = as_SB(origPaint.getShader()); |
reed@google.com | 4588490 | 2012-05-11 14:38:51 +0000 | [diff] [blame] | 940 | SkColorFilter* cf = origPaint.getColorFilter(); |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 941 | SkBlendMode mode = origPaint.getBlendMode(); |
reed | fe63045 | 2016-03-25 09:08:00 -0700 | [diff] [blame] | 942 | sk_sp<Sk3DShader> shader3D; |
reed@google.com | 4588490 | 2012-05-11 14:38:51 +0000 | [diff] [blame] | 943 | |
bsalomon@google.com | 5dc26b9 | 2012-10-11 19:32:32 +0000 | [diff] [blame] | 944 | SkTCopyOnFirstWrite<SkPaint> paint(origPaint); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 945 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 946 | if (origPaint.getMaskFilter() != nullptr && |
reed@google.com | 4588490 | 2012-05-11 14:38:51 +0000 | [diff] [blame] | 947 | origPaint.getMaskFilter()->getFormat() == SkMask::k3D_Format) { |
reed | fe63045 | 2016-03-25 09:08:00 -0700 | [diff] [blame] | 948 | shader3D = sk_make_sp<Sk3DShader>(sk_ref_sp(shader)); |
reed@google.com | 4588490 | 2012-05-11 14:38:51 +0000 | [diff] [blame] | 949 | // we know we haven't initialized lazyPaint yet, so just do it |
reed | fe63045 | 2016-03-25 09:08:00 -0700 | [diff] [blame] | 950 | paint.writable()->setShader(shader3D); |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 951 | shader = as_SB(shader3D.get()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 952 | } |
| 953 | |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 954 | if (mode != SkBlendMode::kSrcOver) { |
halcanary | a681433 | 2015-05-27 08:53:36 -0700 | [diff] [blame] | 955 | bool deviceIsOpaque = kRGB_565_SkColorType == device.colorType(); |
| 956 | switch (SkInterpretXfermode(*paint, deviceIsOpaque)) { |
| 957 | case kSrcOver_SkXfermodeInterpretation: |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 958 | mode = SkBlendMode::kSrcOver; |
| 959 | paint.writable()->setBlendMode(mode); |
reed@android.com | d252db0 | 2009-04-01 18:31:44 +0000 | [diff] [blame] | 960 | break; |
halcanary | a681433 | 2015-05-27 08:53:36 -0700 | [diff] [blame] | 961 | case kSkipDrawing_SkXfermodeInterpretation:{ |
Herb Derby | 83e939b | 2017-02-07 14:25:11 -0500 | [diff] [blame] | 962 | return alloc->make<SkNullBlitter>(); |
commit-bot@chromium.org | a5572e5 | 2014-03-07 03:24:41 +0000 | [diff] [blame] | 963 | } |
reed@android.com | d252db0 | 2009-04-01 18:31:44 +0000 | [diff] [blame] | 964 | default: |
| 965 | break; |
| 966 | } |
| 967 | } |
| 968 | |
reed@google.com | 13201e7 | 2012-11-16 13:20:41 +0000 | [diff] [blame] | 969 | /* |
| 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 | */ |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 974 | if (mode == SkBlendMode::kClear) { |
reed@google.com | 13201e7 | 2012-11-16 13:20:41 +0000 | [diff] [blame] | 975 | SkPaint* p = paint.writable(); |
reed | fe63045 | 2016-03-25 09:08:00 -0700 | [diff] [blame] | 976 | p->setShader(nullptr); |
| 977 | shader = nullptr; |
reed | d053ce9 | 2016-03-22 10:17:23 -0700 | [diff] [blame] | 978 | p->setColorFilter(nullptr); |
| 979 | cf = nullptr; |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 980 | p->setBlendMode(mode = SkBlendMode::kSrc); |
reed@google.com | 13201e7 | 2012-11-16 13:20:41 +0000 | [diff] [blame] | 981 | p->setColor(0); |
| 982 | } |
reed@google.com | 13201e7 | 2012-11-16 13:20:41 +0000 | [diff] [blame] | 983 | |
Mike Klein | e71b167 | 2017-01-13 07:59:23 -0500 | [diff] [blame] | 984 | if (kAlpha_8_SkColorType == device.colorType() && drawCoverage) { |
| 985 | SkASSERT(nullptr == shader); |
| 986 | SkASSERT(paint->isSrcOver()); |
Herb Derby | 83e939b | 2017-02-07 14:25:11 -0500 | [diff] [blame] | 987 | return alloc->make<SkA8_Coverage_Blitter>(device, *paint); |
Mike Klein | e71b167 | 2017-01-13 07:59:23 -0500 | [diff] [blame] | 988 | } |
| 989 | |
Florin Malita | d4a70ee | 2017-06-19 10:21:43 -0400 | [diff] [blame] | 990 | if (paint->isDither() && !SkPaintPriv::ShouldDither(*paint, device.colorType())) { |
| 991 | // Disable dithering when not needed. |
| 992 | paint.writable()->setDither(false); |
| 993 | } |
| 994 | |
Florin Malita | c4176a2 | 2017-07-11 22:47:21 -0400 | [diff] [blame] | 995 | if (UseRasterPipelineBlitter(device, *paint, matrix)) { |
Mike Klein | 44d3279 | 2017-05-10 12:29:38 -0400 | [diff] [blame] | 996 | auto blitter = SkCreateRasterPipelineBlitter(device, *paint, matrix, alloc); |
| 997 | SkASSERT(blitter); |
| 998 | return blitter; |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 999 | } |
| 1000 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1001 | if (nullptr == shader) { |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 1002 | if (mode != SkBlendMode::kSrcOver) { |
reed@google.com | 6b7aee3 | 2011-04-19 18:36:09 +0000 | [diff] [blame] | 1003 | // xfermodes (and filters) require shaders for our current blitters |
reed | fe63045 | 2016-03-25 09:08:00 -0700 | [diff] [blame] | 1004 | paint.writable()->setShader(SkShader::MakeColorShader(paint->getColor())); |
commit-bot@chromium.org | 76a3b2a | 2014-04-24 16:54:46 +0000 | [diff] [blame] | 1005 | paint.writable()->setAlpha(0xFF); |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 1006 | shader = as_SB(paint->getShader()); |
reed@google.com | 6b7aee3 | 2011-04-19 18:36:09 +0000 | [diff] [blame] | 1007 | } else if (cf) { |
| 1008 | // if no shader && no xfermode, we just apply the colorfilter to |
| 1009 | // our color and move on. |
bsalomon@google.com | 5dc26b9 | 2012-10-11 19:32:32 +0000 | [diff] [blame] | 1010 | SkPaint* writablePaint = paint.writable(); |
| 1011 | writablePaint->setColor(cf->filterColor(paint->getColor())); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1012 | writablePaint->setColorFilter(nullptr); |
| 1013 | cf = nullptr; |
reed@google.com | 6b7aee3 | 2011-04-19 18:36:09 +0000 | [diff] [blame] | 1014 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1015 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 1016 | |
reed@google.com | 6b7aee3 | 2011-04-19 18:36:09 +0000 | [diff] [blame] | 1017 | if (cf) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1018 | SkASSERT(shader); |
reed | d053ce9 | 2016-03-22 10:17:23 -0700 | [diff] [blame] | 1019 | paint.writable()->setShader(shader->makeWithColorFilter(sk_ref_sp(cf))); |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 1020 | shader = as_SB(paint->getShader()); |
reed@android.com | 1fc4c60 | 2009-10-02 16:34:57 +0000 | [diff] [blame] | 1021 | // blitters should ignore the presence/absence of a filter, since |
| 1022 | // if there is one, the shader will take care of it. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1023 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 1024 | |
reed@google.com | a641f3f | 2012-12-13 22:16:30 +0000 | [diff] [blame] | 1025 | /* |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 1026 | * We create a SkShader::Context object, and store it on the blitter. |
reed@google.com | a641f3f | 2012-12-13 22:16:30 +0000 | [diff] [blame] | 1027 | */ |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 1028 | SkShaderBase::Context* shaderContext = nullptr; |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 1029 | if (shader) { |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 1030 | const SkShaderBase::ContextRec rec(*paint, matrix, nullptr, |
Brian Osman | 11970e5 | 2016-12-05 15:26:50 -0500 | [diff] [blame] | 1031 | PreferredShaderDest(device.info()), |
| 1032 | device.colorSpace()); |
Herb Derby | 83e939b | 2017-02-07 14:25:11 -0500 | [diff] [blame] | 1033 | // Try to create the ShaderContext |
| 1034 | shaderContext = shader->makeContext(rec, alloc); |
| 1035 | if (!shaderContext) { |
| 1036 | return alloc->make<SkNullBlitter>(); |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 1037 | } |
Herb Derby | 83e939b | 2017-02-07 14:25:11 -0500 | [diff] [blame] | 1038 | SkASSERT(shaderContext); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1039 | } |
| 1040 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1041 | SkBlitter* blitter = nullptr; |
reed@google.com | 900ecf2 | 2014-02-20 20:55:37 +0000 | [diff] [blame] | 1042 | switch (device.colorType()) { |
commit-bot@chromium.org | 28fcae2 | 2014-04-11 17:15:40 +0000 | [diff] [blame] | 1043 | case kN32_SkColorType: |
Florin Malita | 9b868f7 | 2017-05-25 16:43:43 -0400 | [diff] [blame] | 1044 | // 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.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 1053 | } else { |
Florin Malita | 9b868f7 | 2017-05-25 16:43:43 -0400 | [diff] [blame] | 1054 | blitter = alloc->make<SkARGB32_Blitter>(device, *paint); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 1055 | } |
| 1056 | break; |
| 1057 | |
| 1058 | default: |
Mike Reed | b5d9e85 | 2017-06-02 23:14:07 -0400 | [diff] [blame] | 1059 | // should have been handled via raster pipeline. |
| 1060 | SkASSERT(false); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 1061 | break; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1062 | } |
| 1063 | |
reed | 129ed1c | 2016-02-22 06:42:31 -0800 | [diff] [blame] | 1064 | if (!blitter) { |
Herb Derby | 83e939b | 2017-02-07 14:25:11 -0500 | [diff] [blame] | 1065 | blitter = alloc->make<SkNullBlitter>(); |
reed | 129ed1c | 2016-02-22 06:42:31 -0800 | [diff] [blame] | 1066 | } |
| 1067 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 1068 | if (shader3D) { |
commit-bot@chromium.org | a5572e5 | 2014-03-07 03:24:41 +0000 | [diff] [blame] | 1069 | SkBlitter* innerBlitter = blitter; |
Herb Derby | 83e939b | 2017-02-07 14:25:11 -0500 | [diff] [blame] | 1070 | // FIXME - comment about allocator |
commit-bot@chromium.org | a5572e5 | 2014-03-07 03:24:41 +0000 | [diff] [blame] | 1071 | // innerBlitter was allocated by allocator, which will delete it. |
reed | cc0e311 | 2014-09-10 10:20:24 -0700 | [diff] [blame] | 1072 | // 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 Derby | 83e939b | 2017-02-07 14:25:11 -0500 | [diff] [blame] | 1074 | blitter = alloc->make<Sk3DBlitter>(innerBlitter, shaderContext); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1075 | } |
| 1076 | return blitter; |
| 1077 | } |
| 1078 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 1079 | /////////////////////////////////////////////////////////////////////////////// |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1080 | |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 1081 | SkShaderBlitter::SkShaderBlitter(const SkPixmap& device, const SkPaint& paint, |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 1082 | SkShaderBase::Context* shaderContext) |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 1083 | : INHERITED(device) |
| 1084 | , fShader(paint.getShader()) |
| 1085 | , fShaderContext(shaderContext) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1086 | SkASSERT(fShader); |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 1087 | SkASSERT(fShaderContext); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1088 | |
| 1089 | fShader->ref(); |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 1090 | fShaderFlags = fShaderContext->getFlags(); |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 1091 | fConstInY = SkToBool(fShaderFlags & SkShaderBase::kConstInY32_Flag); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1092 | } |
| 1093 | |
reed@android.com | 5119bdb | 2009-06-12 21:27:03 +0000 | [diff] [blame] | 1094 | SkShaderBlitter::~SkShaderBlitter() { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1095 | fShader->unref(); |
| 1096 | } |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 1097 | |
Mike Reed | 28930b4 | 2016-11-09 15:23:26 -0500 | [diff] [blame] | 1098 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 1099 | |
| 1100 | #ifdef SK_DEBUG |
| 1101 | |
| 1102 | void 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 | |
| 1107 | void 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 | |
| 1116 | void 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 | |
| 1121 | void 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 | |
| 1126 | void SkRectClipCheckBlitter::blitAntiRect(int x, int y, int width, int height, |
| 1127 | SkAlpha leftAlpha, SkAlpha rightAlpha) { |
Yuqian Li | 8b9a725 | 2016-11-11 09:40:34 -0500 | [diff] [blame] | 1128 | bool skipLeft = !leftAlpha; |
| 1129 | bool skipRight = !rightAlpha; |
| 1130 | SkASSERT(fClipRect.contains(SkIRect::MakeXYWH(x + skipLeft, y, |
| 1131 | width + 2 - skipRight - skipLeft, height))); |
Mike Reed | 28930b4 | 2016-11-09 15:23:26 -0500 | [diff] [blame] | 1132 | fBlitter->blitAntiRect(x, y, width, height, leftAlpha, rightAlpha); |
| 1133 | } |
| 1134 | |
| 1135 | void 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 | |
| 1141 | const SkPixmap* SkRectClipCheckBlitter::justAnOpaqueColor(uint32_t* value) { |
| 1142 | return fBlitter->justAnOpaqueColor(value); |
| 1143 | } |
| 1144 | |
Yuqian Li | 99bba9e | 2016-11-21 09:44:59 -0500 | [diff] [blame] | 1145 | void 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 | |
| 1150 | void 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 Reed | 28930b4 | 2016-11-09 15:23:26 -0500 | [diff] [blame] | 1155 | #endif |