epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
reed | 0461713 | 2014-08-21 09:46:49 -0700 | [diff] [blame] | 7 | |
| 8 | #include "SkBitmapCache.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 9 | #include "SkBitmapProcState.h" |
| 10 | #include "SkColorPriv.h" |
| 11 | #include "SkFilterProc.h" |
| 12 | #include "SkPaint.h" |
| 13 | #include "SkShader.h" // for tilemodes |
digit@google.com | 3ada0ef | 2012-08-13 14:06:34 +0000 | [diff] [blame] | 14 | #include "SkUtilsArm.h" |
humper@google.com | 138ebc3 | 2013-07-19 20:20:04 +0000 | [diff] [blame] | 15 | #include "SkBitmapScaler.h" |
reed@google.com | d94697c | 2013-07-24 14:31:33 +0000 | [diff] [blame] | 16 | #include "SkMipMap.h" |
reed@google.com | cee9dcb | 2013-09-13 16:04:49 +0000 | [diff] [blame] | 17 | #include "SkPixelRef.h" |
commit-bot@chromium.org | f449156 | 2014-05-28 17:30:02 +0000 | [diff] [blame] | 18 | #include "SkImageEncoder.h" |
reed | 011f39a | 2014-08-28 13:35:23 -0700 | [diff] [blame] | 19 | #include "SkResourceCache.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 20 | |
digit@google.com | 3ada0ef | 2012-08-13 14:06:34 +0000 | [diff] [blame] | 21 | #if !SK_ARM_NEON_IS_NONE |
| 22 | // These are defined in src/opts/SkBitmapProcState_arm_neon.cpp |
| 23 | extern const SkBitmapProcState::SampleProc16 gSkBitmapProcStateSample16_neon[]; |
| 24 | extern const SkBitmapProcState::SampleProc32 gSkBitmapProcStateSample32_neon[]; |
| 25 | extern void S16_D16_filter_DX_neon(const SkBitmapProcState&, const uint32_t*, int, uint16_t*); |
| 26 | extern void Clamp_S16_D16_filter_DX_shaderproc_neon(const SkBitmapProcState&, int, int, uint16_t*, int); |
| 27 | extern void Repeat_S16_D16_filter_DX_shaderproc_neon(const SkBitmapProcState&, int, int, uint16_t*, int); |
| 28 | extern void SI8_opaque_D32_filter_DX_neon(const SkBitmapProcState&, const uint32_t*, int, SkPMColor*); |
| 29 | extern void SI8_opaque_D32_filter_DX_shaderproc_neon(const SkBitmapProcState&, int, int, uint32_t*, int); |
| 30 | extern void Clamp_SI8_opaque_D32_filter_DX_shaderproc_neon(const SkBitmapProcState&, int, int, uint32_t*, int); |
| 31 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 32 | |
mtklein | 14e4d39 | 2014-10-23 14:35:01 -0700 | [diff] [blame] | 33 | extern void Clamp_S32_opaque_D32_nofilter_DX_shaderproc(const SkBitmapProcState&, int, int, uint32_t*, int); |
| 34 | |
digit@google.com | 3ada0ef | 2012-08-13 14:06:34 +0000 | [diff] [blame] | 35 | #define NAME_WRAP(x) x |
| 36 | #include "SkBitmapProcState_filter.h" |
| 37 | #include "SkBitmapProcState_procs.h" |
reed@android.com | b577b41 | 2009-10-27 17:49:32 +0000 | [diff] [blame] | 38 | |
reed@android.com | a44b4cc | 2009-07-16 02:03:58 +0000 | [diff] [blame] | 39 | /////////////////////////////////////////////////////////////////////////////// |
| 40 | |
reed@google.com | ee056a8 | 2013-04-18 15:33:27 +0000 | [diff] [blame] | 41 | // true iff the matrix contains, at most, scale and translate elements |
| 42 | static bool matrix_only_scale_translate(const SkMatrix& m) { |
| 43 | return m.getType() <= (SkMatrix::kScale_Mask | SkMatrix::kTranslate_Mask); |
| 44 | } |
| 45 | |
reed@google.com | c0e88e0 | 2012-10-17 21:11:56 +0000 | [diff] [blame] | 46 | /** |
| 47 | * For the purposes of drawing bitmaps, if a matrix is "almost" translate |
| 48 | * go ahead and treat it as if it were, so that subsequent code can go fast. |
| 49 | */ |
| 50 | static bool just_trans_clamp(const SkMatrix& matrix, const SkBitmap& bitmap) { |
reed@google.com | ee056a8 | 2013-04-18 15:33:27 +0000 | [diff] [blame] | 51 | SkASSERT(matrix_only_scale_translate(matrix)); |
reed@google.com | c0e88e0 | 2012-10-17 21:11:56 +0000 | [diff] [blame] | 52 | |
reed@google.com | ee056a8 | 2013-04-18 15:33:27 +0000 | [diff] [blame] | 53 | if (matrix.getType() & SkMatrix::kScale_Mask) { |
| 54 | SkRect src, dst; |
| 55 | bitmap.getBounds(&src); |
reed@google.com | f707adc | 2013-04-18 15:37:14 +0000 | [diff] [blame] | 56 | |
| 57 | // Can't call mapRect(), since that will fix up inverted rectangles, |
| 58 | // e.g. when scale is negative, and we don't want to return true for |
| 59 | // those. |
| 60 | matrix.mapPoints(SkTCast<SkPoint*>(&dst), |
| 61 | SkTCast<const SkPoint*>(&src), |
| 62 | 2); |
reed@google.com | ee056a8 | 2013-04-18 15:33:27 +0000 | [diff] [blame] | 63 | |
| 64 | // Now round all 4 edges to device space, and then compare the device |
| 65 | // width/height to the original. Note: we must map all 4 and subtract |
| 66 | // rather than map the "width" and compare, since we care about the |
| 67 | // phase (in pixel space) that any translate in the matrix might impart. |
| 68 | SkIRect idst; |
| 69 | dst.round(&idst); |
| 70 | return idst.width() == bitmap.width() && idst.height() == bitmap.height(); |
reed@google.com | c0e88e0 | 2012-10-17 21:11:56 +0000 | [diff] [blame] | 71 | } |
| 72 | // if we got here, we're either kTranslate_Mask or identity |
| 73 | return true; |
| 74 | } |
| 75 | |
| 76 | static bool just_trans_general(const SkMatrix& matrix) { |
reed@google.com | ee056a8 | 2013-04-18 15:33:27 +0000 | [diff] [blame] | 77 | SkASSERT(matrix_only_scale_translate(matrix)); |
reed@google.com | c0e88e0 | 2012-10-17 21:11:56 +0000 | [diff] [blame] | 78 | |
reed@google.com | ee056a8 | 2013-04-18 15:33:27 +0000 | [diff] [blame] | 79 | if (matrix.getType() & SkMatrix::kScale_Mask) { |
reed@google.com | c0e88e0 | 2012-10-17 21:11:56 +0000 | [diff] [blame] | 80 | const SkScalar tol = SK_Scalar1 / 32768; |
skia.committer@gmail.com | 989a95e | 2012-10-18 02:01:23 +0000 | [diff] [blame] | 81 | |
reed@google.com | c0e88e0 | 2012-10-17 21:11:56 +0000 | [diff] [blame] | 82 | if (!SkScalarNearlyZero(matrix[SkMatrix::kMScaleX] - SK_Scalar1, tol)) { |
| 83 | return false; |
| 84 | } |
| 85 | if (!SkScalarNearlyZero(matrix[SkMatrix::kMScaleY] - SK_Scalar1, tol)) { |
| 86 | return false; |
| 87 | } |
| 88 | } |
| 89 | // if we got here, treat us as either kTranslate_Mask or identity |
| 90 | return true; |
| 91 | } |
| 92 | |
| 93 | /////////////////////////////////////////////////////////////////////////////// |
| 94 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 95 | static bool valid_for_filtering(unsigned dimension) { |
| 96 | // for filtering, width and height must fit in 14bits, since we use steal |
| 97 | // 2 bits from each to store our 4bit subpixel data |
| 98 | return (dimension & ~0x3FFF) == 0; |
| 99 | } |
| 100 | |
reed | 0c2da0c | 2015-02-19 18:39:49 -0800 | [diff] [blame] | 101 | static SkScalar effective_matrix_scale(const SkMatrix& mat) { |
| 102 | SkScalar dx = SkVector::Length(mat.getScaleX(), mat.getSkewY()); |
| 103 | SkScalar dy = SkVector::Length(mat.getSkewX(), mat.getScaleY()); |
| 104 | #ifdef SK_SUPPORT_LEGACY_MIPMAP_EFFECTIVE_SCALE |
| 105 | return SkMaxScalar(dx, dy); |
| 106 | #else |
| 107 | return SkScalarSqrt(dx * dy); |
| 108 | #endif |
reed@google.com | 9cfc83c | 2013-07-22 17:18:18 +0000 | [diff] [blame] | 109 | } |
| 110 | |
halcanary | 805ef15 | 2014-07-17 06:58:01 -0700 | [diff] [blame] | 111 | // Check to see that the size of the bitmap that would be produced by |
| 112 | // scaling by the given inverted matrix is less than the maximum allowed. |
| 113 | static inline bool cache_size_okay(const SkBitmap& bm, const SkMatrix& invMat) { |
reed | 1d9e80f | 2015-01-26 11:24:37 -0800 | [diff] [blame] | 114 | size_t maximumAllocation = SkResourceCache::GetEffectiveSingleAllocationByteLimit(); |
halcanary | 805ef15 | 2014-07-17 06:58:01 -0700 | [diff] [blame] | 115 | if (0 == maximumAllocation) { |
| 116 | return true; |
| 117 | } |
| 118 | // float matrixScaleFactor = 1.0 / (invMat.scaleX * invMat.scaleY); |
| 119 | // return ((origBitmapSize * matrixScaleFactor) < maximumAllocationSize); |
| 120 | // Skip the division step: |
| 121 | return bm.info().getSafeSize(bm.info().minRowBytes()) |
| 122 | < (maximumAllocation * invMat.getScaleX() * invMat.getScaleY()); |
| 123 | } |
| 124 | |
reed | f7094c4 | 2015-01-16 12:05:19 -0800 | [diff] [blame] | 125 | /* |
| 126 | * Extract the "best" scale factors from a matrix. |
| 127 | */ |
| 128 | static bool extract_scale(const SkMatrix& matrix, SkVector* scale) { |
| 129 | SkASSERT(!matrix.hasPerspective()); |
| 130 | SkScalar sx = SkPoint::Length(matrix[SkMatrix::kMScaleX], matrix[SkMatrix::kMSkewY]); |
| 131 | SkScalar sy = SkPoint::Length(matrix[SkMatrix::kMSkewX], matrix[SkMatrix::kMScaleY]); |
| 132 | if (!SkScalarIsFinite(sx) || !SkScalarIsFinite(sy) || |
| 133 | SkScalarNearlyZero(sx) || SkScalarNearlyZero(sy)) |
| 134 | { |
| 135 | return false; |
| 136 | } |
| 137 | scale->set(sx, sy); |
| 138 | return true; |
| 139 | } |
| 140 | |
| 141 | /* |
| 142 | * High quality is implemented by performing up-right scale-only filtering and then |
| 143 | * using bilerp for any remaining transformations. |
| 144 | */ |
| 145 | void SkBitmapProcState::processHQRequest() { |
| 146 | SkASSERT(SkPaint::kHigh_FilterLevel == fFilterLevel); |
| 147 | |
| 148 | // Our default return state is to downgrade the request to Medium, w/ or w/o setting fBitmap |
| 149 | // to a valid bitmap. If we succeed, we will set this to Low instead. |
| 150 | fFilterLevel = SkPaint::kMedium_FilterLevel; |
| 151 | |
| 152 | if (kN32_SkColorType != fOrigBitmap.colorType() || !cache_size_okay(fOrigBitmap, fInvMatrix) || |
| 153 | fInvMatrix.hasPerspective()) |
| 154 | { |
| 155 | return; // can't handle the reqeust |
| 156 | } |
| 157 | |
| 158 | SkScalar invScaleX = fInvMatrix.getScaleX(); |
| 159 | SkScalar invScaleY = fInvMatrix.getScaleY(); |
| 160 | if (fInvMatrix.getType() & SkMatrix::kAffine_Mask) { |
| 161 | SkVector scale; |
| 162 | if (!extract_scale(fInvMatrix, &scale)) { |
| 163 | return; // can't find suitable scale factors |
| 164 | } |
| 165 | invScaleX = scale.x(); |
| 166 | invScaleY = scale.y(); |
| 167 | } |
| 168 | if (SkScalarNearlyEqual(invScaleX, 1) && SkScalarNearlyEqual(invScaleY, 1)) { |
| 169 | return; // no need for HQ |
| 170 | } |
| 171 | |
| 172 | SkScalar trueDestWidth = fOrigBitmap.width() / invScaleX; |
| 173 | SkScalar trueDestHeight = fOrigBitmap.height() / invScaleY; |
| 174 | SkScalar roundedDestWidth = SkScalarRoundToScalar(trueDestWidth); |
| 175 | SkScalar roundedDestHeight = SkScalarRoundToScalar(trueDestHeight); |
| 176 | |
| 177 | if (!SkBitmapCache::Find(fOrigBitmap, roundedDestWidth, roundedDestHeight, &fScaledBitmap)) { |
| 178 | if (!SkBitmapScaler::Resize(&fScaledBitmap, |
| 179 | fOrigBitmap, |
| 180 | SkBitmapScaler::RESIZE_BEST, |
| 181 | roundedDestWidth, |
| 182 | roundedDestHeight, |
| 183 | SkResourceCache::GetAllocator())) { |
| 184 | return; // we failed to create fScaledBitmap |
| 185 | } |
| 186 | |
| 187 | SkASSERT(fScaledBitmap.getPixels()); |
| 188 | fScaledBitmap.setImmutable(); |
| 189 | SkBitmapCache::Add(fOrigBitmap, roundedDestWidth, roundedDestHeight, fScaledBitmap); |
| 190 | } |
| 191 | |
| 192 | SkASSERT(fScaledBitmap.getPixels()); |
| 193 | fBitmap = &fScaledBitmap; |
| 194 | |
| 195 | fInvMatrix.postScale(roundedDestWidth / fOrigBitmap.width(), |
| 196 | roundedDestHeight / fOrigBitmap.height()); |
| 197 | fFilterLevel = SkPaint::kLow_FilterLevel; |
| 198 | } |
| 199 | |
| 200 | /* |
| 201 | * Modulo internal errors, this should always succeed *if* the matrix is downscaling |
| 202 | * (in this case, we have the inverse, so it succeeds if fInvMatrix is upscaling) |
| 203 | */ |
| 204 | void SkBitmapProcState::processMediumRequest() { |
| 205 | SkASSERT(SkPaint::kMedium_FilterLevel == fFilterLevel); |
| 206 | |
| 207 | // Our default return state is to downgrade the request to Low, w/ or w/o setting fBitmap |
| 208 | // to a valid bitmap. |
| 209 | fFilterLevel = SkPaint::kLow_FilterLevel; |
| 210 | |
reed | 0c2da0c | 2015-02-19 18:39:49 -0800 | [diff] [blame] | 211 | SkScalar invScale = effective_matrix_scale(fInvMatrix); |
reed | f7094c4 | 2015-01-16 12:05:19 -0800 | [diff] [blame] | 212 | |
reed | 0c2da0c | 2015-02-19 18:39:49 -0800 | [diff] [blame] | 213 | if (invScale > SK_Scalar1) { |
reed | f7094c4 | 2015-01-16 12:05:19 -0800 | [diff] [blame] | 214 | fCurrMip.reset(SkMipMapCache::FindAndRef(fOrigBitmap)); |
| 215 | if (NULL == fCurrMip.get()) { |
| 216 | fCurrMip.reset(SkMipMapCache::AddAndRef(fOrigBitmap)); |
| 217 | if (NULL == fCurrMip.get()) { |
| 218 | return; |
| 219 | } |
| 220 | } |
| 221 | // diagnostic for a crasher... |
| 222 | if (NULL == fCurrMip->data()) { |
| 223 | sk_throw(); |
| 224 | } |
| 225 | |
reed | 0c2da0c | 2015-02-19 18:39:49 -0800 | [diff] [blame] | 226 | SkScalar levelScale = SkScalarInvert(invScale); |
reed | f7094c4 | 2015-01-16 12:05:19 -0800 | [diff] [blame] | 227 | SkMipMap::Level level; |
| 228 | if (fCurrMip->extractLevel(levelScale, &level)) { |
| 229 | SkScalar invScaleFixup = level.fScale; |
| 230 | fInvMatrix.postScale(invScaleFixup, invScaleFixup); |
| 231 | |
| 232 | const SkImageInfo info = fOrigBitmap.info().makeWH(level.fWidth, level.fHeight); |
| 233 | // todo: if we could wrap the fCurrMip in a pixelref, then we could just install |
| 234 | // that here, and not need to explicitly track it ourselves. |
| 235 | fScaledBitmap.installPixels(info, level.fPixels, level.fRowBytes); |
| 236 | fBitmap = &fScaledBitmap; |
| 237 | } else { |
| 238 | // failed to extract, so release the mipmap |
| 239 | fCurrMip.reset(NULL); |
| 240 | } |
| 241 | } |
| 242 | } |
| 243 | |
reed@google.com | cee9dcb | 2013-09-13 16:04:49 +0000 | [diff] [blame] | 244 | bool SkBitmapProcState::lockBaseBitmap() { |
mtklein | 96d68b7 | 2015-02-20 12:40:40 -0800 | [diff] [blame^] | 245 | // TODO(reed): use bitmap cache here? |
| 246 | fScaledBitmap = fOrigBitmap; |
| 247 | fScaledBitmap.lockPixels(); |
| 248 | if (NULL == fScaledBitmap.getPixels()) { |
| 249 | return false; |
reed@google.com | cee9dcb | 2013-09-13 16:04:49 +0000 | [diff] [blame] | 250 | } |
reed@google.com | cee9dcb | 2013-09-13 16:04:49 +0000 | [diff] [blame] | 251 | fBitmap = &fScaledBitmap; |
| 252 | return true; |
humper@google.com | 9c96d4b | 2013-07-14 01:44:59 +0000 | [diff] [blame] | 253 | } |
| 254 | |
reed | 89dee42 | 2014-12-04 08:06:17 -0800 | [diff] [blame] | 255 | static bool valid_for_drawing(const SkBitmap& bm) { |
| 256 | if (0 == bm.width() || 0 == bm.height()) { |
| 257 | return false; // nothing to draw |
| 258 | } |
| 259 | if (NULL == bm.pixelRef()) { |
| 260 | return false; // no pixels to read |
| 261 | } |
| 262 | if (bm.getTexture()) { |
| 263 | // we can handle texture (ugh) since lockPixels will perform a read-back |
| 264 | return true; |
| 265 | } |
| 266 | if (kIndex_8_SkColorType == bm.colorType()) { |
| 267 | SkAutoLockPixels alp(bm); // but we need to call it before getColorTable() is safe. |
| 268 | if (!bm.getColorTable()) { |
| 269 | return false; |
| 270 | } |
| 271 | } |
| 272 | return true; |
| 273 | } |
| 274 | |
reed | f7094c4 | 2015-01-16 12:05:19 -0800 | [diff] [blame] | 275 | /* |
| 276 | * Analyze filter-quality and matrix, and decide how to implement that. |
| 277 | * |
| 278 | * In general, we cascade down the request level [ High ... None ] |
| 279 | * - for a given level, if we can fulfill it, fine, else |
| 280 | * - else we downgrade to the next lower level and try again. |
| 281 | * We can always fulfill requests for Low and None |
| 282 | * - sometimes we will "ignore" Low and give None, but this is likely a legacy perf hack |
| 283 | * and may be removed. |
| 284 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 285 | bool SkBitmapProcState::chooseProcs(const SkMatrix& inv, const SkPaint& paint) { |
reed | 89dee42 | 2014-12-04 08:06:17 -0800 | [diff] [blame] | 286 | if (!valid_for_drawing(fOrigBitmap)) { |
| 287 | return false; |
| 288 | } |
reed@android.com | a44b4cc | 2009-07-16 02:03:58 +0000 | [diff] [blame] | 289 | |
reed@google.com | cee9dcb | 2013-09-13 16:04:49 +0000 | [diff] [blame] | 290 | fBitmap = NULL; |
reed@google.com | ef0e319 | 2013-09-09 13:42:39 +0000 | [diff] [blame] | 291 | fInvMatrix = inv; |
reed@google.com | 9cfc83c | 2013-07-22 17:18:18 +0000 | [diff] [blame] | 292 | fFilterLevel = paint.getFilterLevel(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 293 | |
reed | f7094c4 | 2015-01-16 12:05:19 -0800 | [diff] [blame] | 294 | if (SkPaint::kHigh_FilterLevel == fFilterLevel) { |
| 295 | this->processHQRequest(); |
| 296 | } |
| 297 | SkASSERT(fFilterLevel < SkPaint::kHigh_FilterLevel); |
| 298 | |
| 299 | if (SkPaint::kMedium_FilterLevel == fFilterLevel) { |
| 300 | this->processMediumRequest(); |
| 301 | } |
| 302 | SkASSERT(fFilterLevel < SkPaint::kMedium_FilterLevel); |
| 303 | |
| 304 | if (NULL == fBitmap) { |
| 305 | if (!this->lockBaseBitmap()) { |
| 306 | return false; |
| 307 | } |
| 308 | } |
| 309 | SkASSERT(fBitmap); |
commit-bot@chromium.org | 84f7a06 | 2014-04-17 16:46:07 +0000 | [diff] [blame] | 310 | |
reed@google.com | ef0e319 | 2013-09-09 13:42:39 +0000 | [diff] [blame] | 311 | bool trivialMatrix = (fInvMatrix.getType() & ~SkMatrix::kTranslate_Mask) == 0; |
| 312 | bool clampClamp = SkShader::kClamp_TileMode == fTileModeX && |
| 313 | SkShader::kClamp_TileMode == fTileModeY; |
skia.committer@gmail.com | 9a070f2 | 2013-09-10 07:01:44 +0000 | [diff] [blame] | 314 | |
humper | 535e3b2 | 2014-10-27 10:32:06 -0700 | [diff] [blame] | 315 | // Most of the scanline procs deal with "unit" texture coordinates, as this |
| 316 | // makes it easy to perform tiling modes (repeat = (x & 0xFFFF)). To generate |
| 317 | // those, we divide the matrix by its dimensions here. |
| 318 | // |
| 319 | // We don't do this if we're either trivial (can ignore the matrix) or clamping |
| 320 | // in both X and Y since clamping to width,height is just as easy as to 0xFFFF. |
| 321 | |
| 322 | if (!(clampClamp || trivialMatrix)) { |
| 323 | fInvMatrix.postIDiv(fBitmap->width(), fBitmap->height()); |
reed@google.com | ef0e319 | 2013-09-09 13:42:39 +0000 | [diff] [blame] | 324 | } |
| 325 | |
humper@google.com | 9c96d4b | 2013-07-14 01:44:59 +0000 | [diff] [blame] | 326 | // Now that all possible changes to the matrix have taken place, check |
| 327 | // to see if we're really close to a no-scale matrix. If so, explicitly |
| 328 | // set it to be so. Subsequent code may inspect this matrix to choose |
| 329 | // a faster path in this case. |
| 330 | |
| 331 | // This code will only execute if the matrix has some scale component; |
| 332 | // if it's already pure translate then we won't do this inversion. |
| 333 | |
| 334 | if (matrix_only_scale_translate(fInvMatrix)) { |
reed@google.com | ee056a8 | 2013-04-18 15:33:27 +0000 | [diff] [blame] | 335 | SkMatrix forward; |
humper@google.com | 9c96d4b | 2013-07-14 01:44:59 +0000 | [diff] [blame] | 336 | if (fInvMatrix.invert(&forward)) { |
| 337 | if (clampClamp ? just_trans_clamp(forward, *fBitmap) |
reed | f7094c4 | 2015-01-16 12:05:19 -0800 | [diff] [blame] | 338 | : just_trans_general(forward)) { |
reed@google.com | ce1f3cc | 2013-01-05 14:37:48 +0000 | [diff] [blame] | 339 | SkScalar tx = -SkScalarRoundToScalar(forward.getTranslateX()); |
| 340 | SkScalar ty = -SkScalarRoundToScalar(forward.getTranslateY()); |
humper@google.com | 9c96d4b | 2013-07-14 01:44:59 +0000 | [diff] [blame] | 341 | fInvMatrix.setTranslate(tx, ty); |
reed@google.com | ce1f3cc | 2013-01-05 14:37:48 +0000 | [diff] [blame] | 342 | } |
reed@google.com | c0e88e0 | 2012-10-17 21:11:56 +0000 | [diff] [blame] | 343 | } |
| 344 | } |
| 345 | |
humper@google.com | 9c96d4b | 2013-07-14 01:44:59 +0000 | [diff] [blame] | 346 | fInvProc = fInvMatrix.getMapXYProc(); |
| 347 | fInvType = fInvMatrix.getType(); |
| 348 | fInvSx = SkScalarToFixed(fInvMatrix.getScaleX()); |
| 349 | fInvSxFractionalInt = SkScalarToFractionalInt(fInvMatrix.getScaleX()); |
| 350 | fInvKy = SkScalarToFixed(fInvMatrix.getSkewY()); |
| 351 | fInvKyFractionalInt = SkScalarToFractionalInt(fInvMatrix.getSkewY()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 352 | |
| 353 | fAlphaScale = SkAlpha255To256(paint.getAlpha()); |
skia.committer@gmail.com | fa1bd5f | 2013-07-13 07:00:56 +0000 | [diff] [blame] | 354 | |
reed@android.com | 7a99eb1 | 2009-07-16 01:13:14 +0000 | [diff] [blame] | 355 | fShaderProc32 = NULL; |
| 356 | fShaderProc16 = NULL; |
| 357 | fSampleProc32 = NULL; |
| 358 | fSampleProc16 = NULL; |
mtklein | 96d68b7 | 2015-02-20 12:40:40 -0800 | [diff] [blame^] | 359 | |
humper@google.com | 9c96d4b | 2013-07-14 01:44:59 +0000 | [diff] [blame] | 360 | // recompute the triviality of the matrix here because we may have |
| 361 | // changed it! |
| 362 | |
| 363 | trivialMatrix = (fInvMatrix.getType() & ~SkMatrix::kTranslate_Mask) == 0; |
| 364 | |
reed@google.com | 9cfc83c | 2013-07-22 17:18:18 +0000 | [diff] [blame] | 365 | if (SkPaint::kLow_FilterLevel == fFilterLevel) { |
humper@google.com | 9c96d4b | 2013-07-14 01:44:59 +0000 | [diff] [blame] | 366 | // Only try bilerp if the matrix is "interesting" and |
| 367 | // the image has a suitable size. |
| 368 | |
| 369 | if (fInvType <= SkMatrix::kTranslate_Mask || |
reed | f7094c4 | 2015-01-16 12:05:19 -0800 | [diff] [blame] | 370 | !valid_for_filtering(fBitmap->width() | fBitmap->height())) |
| 371 | { |
reed@google.com | 9cfc83c | 2013-07-22 17:18:18 +0000 | [diff] [blame] | 372 | fFilterLevel = SkPaint::kNone_FilterLevel; |
humper@google.com | 9c96d4b | 2013-07-14 01:44:59 +0000 | [diff] [blame] | 373 | } |
| 374 | } |
| 375 | |
reed | 26feeba | 2015-01-14 12:28:22 -0800 | [diff] [blame] | 376 | return this->chooseScanlineProcs(trivialMatrix, clampClamp, paint); |
| 377 | } |
humper@google.com | 9c96d4b | 2013-07-14 01:44:59 +0000 | [diff] [blame] | 378 | |
reed | 26feeba | 2015-01-14 12:28:22 -0800 | [diff] [blame] | 379 | bool SkBitmapProcState::chooseScanlineProcs(bool trivialMatrix, bool clampClamp, |
| 380 | const SkPaint& paint) { |
humper@google.com | 9c96d4b | 2013-07-14 01:44:59 +0000 | [diff] [blame] | 381 | fMatrixProc = this->chooseMatrixProc(trivialMatrix); |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 382 | // TODO(dominikg): SkASSERT(fMatrixProc) instead? chooseMatrixProc never returns NULL. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 383 | if (NULL == fMatrixProc) { |
| 384 | return false; |
| 385 | } |
| 386 | |
| 387 | /////////////////////////////////////////////////////////////////////// |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 388 | |
reed | 00adc75 | 2014-07-12 21:10:52 -0700 | [diff] [blame] | 389 | const SkAlphaType at = fBitmap->alphaType(); |
| 390 | |
humper@google.com | 9c96d4b | 2013-07-14 01:44:59 +0000 | [diff] [blame] | 391 | // No need to do this if we're doing HQ sampling; if filter quality is |
| 392 | // still set to HQ by the time we get here, then we must have installed |
mtklein@google.com | 0dc546c | 2013-08-26 16:21:35 +0000 | [diff] [blame] | 393 | // the shader procs above and can skip all this. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 394 | |
reed@google.com | 9cfc83c | 2013-07-22 17:18:18 +0000 | [diff] [blame] | 395 | if (fFilterLevel < SkPaint::kHigh_FilterLevel) { |
skia.committer@gmail.com | fa1bd5f | 2013-07-13 07:00:56 +0000 | [diff] [blame] | 396 | |
humper@google.com | 9c96d4b | 2013-07-14 01:44:59 +0000 | [diff] [blame] | 397 | int index = 0; |
| 398 | if (fAlphaScale < 256) { // note: this distinction is not used for D16 |
| 399 | index |= 1; |
reed@android.com | aa9152a | 2009-07-17 21:24:56 +0000 | [diff] [blame] | 400 | } |
humper@google.com | 9c96d4b | 2013-07-14 01:44:59 +0000 | [diff] [blame] | 401 | if (fInvType <= (SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask)) { |
| 402 | index |= 2; |
| 403 | } |
reed@google.com | 9cfc83c | 2013-07-22 17:18:18 +0000 | [diff] [blame] | 404 | if (fFilterLevel > SkPaint::kNone_FilterLevel) { |
humper@google.com | 9c96d4b | 2013-07-14 01:44:59 +0000 | [diff] [blame] | 405 | index |= 4; |
| 406 | } |
| 407 | // bits 3,4,5 encoding the source bitmap format |
commit-bot@chromium.org | cba7378 | 2014-05-29 15:57:47 +0000 | [diff] [blame] | 408 | switch (fBitmap->colorType()) { |
| 409 | case kN32_SkColorType: |
reed | 00adc75 | 2014-07-12 21:10:52 -0700 | [diff] [blame] | 410 | if (kPremul_SkAlphaType != at && kOpaque_SkAlphaType != at) { |
| 411 | return false; |
| 412 | } |
humper@google.com | 9c96d4b | 2013-07-14 01:44:59 +0000 | [diff] [blame] | 413 | index |= 0; |
| 414 | break; |
commit-bot@chromium.org | cba7378 | 2014-05-29 15:57:47 +0000 | [diff] [blame] | 415 | case kRGB_565_SkColorType: |
humper@google.com | 9c96d4b | 2013-07-14 01:44:59 +0000 | [diff] [blame] | 416 | index |= 8; |
| 417 | break; |
commit-bot@chromium.org | cba7378 | 2014-05-29 15:57:47 +0000 | [diff] [blame] | 418 | case kIndex_8_SkColorType: |
reed | 00adc75 | 2014-07-12 21:10:52 -0700 | [diff] [blame] | 419 | if (kPremul_SkAlphaType != at && kOpaque_SkAlphaType != at) { |
| 420 | return false; |
| 421 | } |
humper@google.com | 9c96d4b | 2013-07-14 01:44:59 +0000 | [diff] [blame] | 422 | index |= 16; |
| 423 | break; |
commit-bot@chromium.org | cba7378 | 2014-05-29 15:57:47 +0000 | [diff] [blame] | 424 | case kARGB_4444_SkColorType: |
reed | 00adc75 | 2014-07-12 21:10:52 -0700 | [diff] [blame] | 425 | if (kPremul_SkAlphaType != at && kOpaque_SkAlphaType != at) { |
| 426 | return false; |
| 427 | } |
humper@google.com | 9c96d4b | 2013-07-14 01:44:59 +0000 | [diff] [blame] | 428 | index |= 24; |
| 429 | break; |
commit-bot@chromium.org | cba7378 | 2014-05-29 15:57:47 +0000 | [diff] [blame] | 430 | case kAlpha_8_SkColorType: |
humper@google.com | 9c96d4b | 2013-07-14 01:44:59 +0000 | [diff] [blame] | 431 | index |= 32; |
| 432 | fPaintPMColor = SkPreMultiplyColor(paint.getColor()); |
| 433 | break; |
| 434 | default: |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 435 | // TODO(dominikg): Should we ever get here? SkASSERT(false) instead? |
humper@google.com | 9c96d4b | 2013-07-14 01:44:59 +0000 | [diff] [blame] | 436 | return false; |
| 437 | } |
reed@android.com | c9a1d4b | 2009-08-03 15:05:55 +0000 | [diff] [blame] | 438 | |
reed | 26feeba | 2015-01-14 12:28:22 -0800 | [diff] [blame] | 439 | #if !SK_ARM_NEON_IS_ALWAYS |
humper@google.com | 9c96d4b | 2013-07-14 01:44:59 +0000 | [diff] [blame] | 440 | static const SampleProc32 gSkBitmapProcStateSample32[] = { |
| 441 | S32_opaque_D32_nofilter_DXDY, |
| 442 | S32_alpha_D32_nofilter_DXDY, |
| 443 | S32_opaque_D32_nofilter_DX, |
| 444 | S32_alpha_D32_nofilter_DX, |
| 445 | S32_opaque_D32_filter_DXDY, |
| 446 | S32_alpha_D32_filter_DXDY, |
| 447 | S32_opaque_D32_filter_DX, |
| 448 | S32_alpha_D32_filter_DX, |
skia.committer@gmail.com | 3e2345a | 2013-05-24 07:01:26 +0000 | [diff] [blame] | 449 | |
humper@google.com | 9c96d4b | 2013-07-14 01:44:59 +0000 | [diff] [blame] | 450 | S16_opaque_D32_nofilter_DXDY, |
| 451 | S16_alpha_D32_nofilter_DXDY, |
| 452 | S16_opaque_D32_nofilter_DX, |
| 453 | S16_alpha_D32_nofilter_DX, |
| 454 | S16_opaque_D32_filter_DXDY, |
| 455 | S16_alpha_D32_filter_DXDY, |
| 456 | S16_opaque_D32_filter_DX, |
| 457 | S16_alpha_D32_filter_DX, |
| 458 | |
| 459 | SI8_opaque_D32_nofilter_DXDY, |
| 460 | SI8_alpha_D32_nofilter_DXDY, |
| 461 | SI8_opaque_D32_nofilter_DX, |
| 462 | SI8_alpha_D32_nofilter_DX, |
| 463 | SI8_opaque_D32_filter_DXDY, |
| 464 | SI8_alpha_D32_filter_DXDY, |
| 465 | SI8_opaque_D32_filter_DX, |
| 466 | SI8_alpha_D32_filter_DX, |
| 467 | |
| 468 | S4444_opaque_D32_nofilter_DXDY, |
| 469 | S4444_alpha_D32_nofilter_DXDY, |
| 470 | S4444_opaque_D32_nofilter_DX, |
| 471 | S4444_alpha_D32_nofilter_DX, |
| 472 | S4444_opaque_D32_filter_DXDY, |
| 473 | S4444_alpha_D32_filter_DXDY, |
| 474 | S4444_opaque_D32_filter_DX, |
| 475 | S4444_alpha_D32_filter_DX, |
| 476 | |
| 477 | // A8 treats alpha/opaque the same (equally efficient) |
| 478 | SA8_alpha_D32_nofilter_DXDY, |
| 479 | SA8_alpha_D32_nofilter_DXDY, |
| 480 | SA8_alpha_D32_nofilter_DX, |
| 481 | SA8_alpha_D32_nofilter_DX, |
| 482 | SA8_alpha_D32_filter_DXDY, |
| 483 | SA8_alpha_D32_filter_DXDY, |
| 484 | SA8_alpha_D32_filter_DX, |
| 485 | SA8_alpha_D32_filter_DX |
| 486 | }; |
| 487 | |
| 488 | static const SampleProc16 gSkBitmapProcStateSample16[] = { |
| 489 | S32_D16_nofilter_DXDY, |
| 490 | S32_D16_nofilter_DX, |
| 491 | S32_D16_filter_DXDY, |
| 492 | S32_D16_filter_DX, |
| 493 | |
| 494 | S16_D16_nofilter_DXDY, |
| 495 | S16_D16_nofilter_DX, |
| 496 | S16_D16_filter_DXDY, |
| 497 | S16_D16_filter_DX, |
| 498 | |
| 499 | SI8_D16_nofilter_DXDY, |
| 500 | SI8_D16_nofilter_DX, |
| 501 | SI8_D16_filter_DXDY, |
| 502 | SI8_D16_filter_DX, |
| 503 | |
| 504 | // Don't support 4444 -> 565 |
| 505 | NULL, NULL, NULL, NULL, |
| 506 | // Don't support A8 -> 565 |
| 507 | NULL, NULL, NULL, NULL |
| 508 | }; |
reed | 26feeba | 2015-01-14 12:28:22 -0800 | [diff] [blame] | 509 | #endif |
humper@google.com | 9c96d4b | 2013-07-14 01:44:59 +0000 | [diff] [blame] | 510 | |
| 511 | fSampleProc32 = SK_ARM_NEON_WRAP(gSkBitmapProcStateSample32)[index]; |
| 512 | index >>= 1; // shift away any opaque/alpha distinction |
| 513 | fSampleProc16 = SK_ARM_NEON_WRAP(gSkBitmapProcStateSample16)[index]; |
| 514 | |
| 515 | // our special-case shaderprocs |
| 516 | if (SK_ARM_NEON_WRAP(S16_D16_filter_DX) == fSampleProc16) { |
| 517 | if (clampClamp) { |
| 518 | fShaderProc16 = SK_ARM_NEON_WRAP(Clamp_S16_D16_filter_DX_shaderproc); |
| 519 | } else if (SkShader::kRepeat_TileMode == fTileModeX && |
| 520 | SkShader::kRepeat_TileMode == fTileModeY) { |
| 521 | fShaderProc16 = SK_ARM_NEON_WRAP(Repeat_S16_D16_filter_DX_shaderproc); |
| 522 | } |
| 523 | } else if (SK_ARM_NEON_WRAP(SI8_opaque_D32_filter_DX) == fSampleProc32 && clampClamp) { |
| 524 | fShaderProc32 = SK_ARM_NEON_WRAP(Clamp_SI8_opaque_D32_filter_DX_shaderproc); |
mtklein | 14e4d39 | 2014-10-23 14:35:01 -0700 | [diff] [blame] | 525 | } else if (S32_opaque_D32_nofilter_DX == fSampleProc32 && clampClamp) { |
| 526 | fShaderProc32 = Clamp_S32_opaque_D32_nofilter_DX_shaderproc; |
humper@google.com | 9c96d4b | 2013-07-14 01:44:59 +0000 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | if (NULL == fShaderProc32) { |
| 530 | fShaderProc32 = this->chooseShaderProc32(); |
| 531 | } |
humper@google.com | b088947 | 2013-07-09 21:37:14 +0000 | [diff] [blame] | 532 | } |
mtklein | 96d68b7 | 2015-02-20 12:40:40 -0800 | [diff] [blame^] | 533 | |
reed@android.com | c9a1d4b | 2009-08-03 15:05:55 +0000 | [diff] [blame] | 534 | // see if our platform has any accelerated overrides |
| 535 | this->platformProcs(); |
mtklein | 96d68b7 | 2015-02-20 12:40:40 -0800 | [diff] [blame^] | 536 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 537 | return true; |
| 538 | } |
| 539 | |
reed@google.com | 9a4c746 | 2012-10-12 18:21:37 +0000 | [diff] [blame] | 540 | static void Clamp_S32_D32_nofilter_trans_shaderproc(const SkBitmapProcState& s, |
| 541 | int x, int y, |
| 542 | SkPMColor* SK_RESTRICT colors, |
| 543 | int count) { |
| 544 | SkASSERT(((s.fInvType & ~SkMatrix::kTranslate_Mask)) == 0); |
| 545 | SkASSERT(s.fInvKy == 0); |
| 546 | SkASSERT(count > 0 && colors != NULL); |
reed@google.com | 9cfc83c | 2013-07-22 17:18:18 +0000 | [diff] [blame] | 547 | SkASSERT(SkPaint::kNone_FilterLevel == s.fFilterLevel); |
skia.committer@gmail.com | 20c301b | 2012-10-17 02:01:13 +0000 | [diff] [blame] | 548 | |
reed@google.com | 9a4c746 | 2012-10-12 18:21:37 +0000 | [diff] [blame] | 549 | const int maxX = s.fBitmap->width() - 1; |
reed@google.com | f7698de | 2012-10-12 20:50:24 +0000 | [diff] [blame] | 550 | const int maxY = s.fBitmap->height() - 1; |
| 551 | int ix = s.fFilterOneX + x; |
| 552 | int iy = SkClampMax(s.fFilterOneY + y, maxY); |
| 553 | #ifdef SK_DEBUG |
reed@google.com | 9a4c746 | 2012-10-12 18:21:37 +0000 | [diff] [blame] | 554 | { |
| 555 | SkPoint pt; |
humper@google.com | 9c96d4b | 2013-07-14 01:44:59 +0000 | [diff] [blame] | 556 | s.fInvProc(s.fInvMatrix, SkIntToScalar(x) + SK_ScalarHalf, |
reed@google.com | 9a4c746 | 2012-10-12 18:21:37 +0000 | [diff] [blame] | 557 | SkIntToScalar(y) + SK_ScalarHalf, &pt); |
reed@google.com | f7698de | 2012-10-12 20:50:24 +0000 | [diff] [blame] | 558 | int iy2 = SkClampMax(SkScalarFloorToInt(pt.fY), maxY); |
| 559 | int ix2 = SkScalarFloorToInt(pt.fX); |
skia.committer@gmail.com | 20c301b | 2012-10-17 02:01:13 +0000 | [diff] [blame] | 560 | |
reed@google.com | f7698de | 2012-10-12 20:50:24 +0000 | [diff] [blame] | 561 | SkASSERT(iy == iy2); |
| 562 | SkASSERT(ix == ix2); |
reed@google.com | 9a4c746 | 2012-10-12 18:21:37 +0000 | [diff] [blame] | 563 | } |
reed@google.com | f7698de | 2012-10-12 20:50:24 +0000 | [diff] [blame] | 564 | #endif |
| 565 | const SkPMColor* row = s.fBitmap->getAddr32(0, iy); |
skia.committer@gmail.com | 20c301b | 2012-10-17 02:01:13 +0000 | [diff] [blame] | 566 | |
reed@google.com | 9a4c746 | 2012-10-12 18:21:37 +0000 | [diff] [blame] | 567 | // clamp to the left |
| 568 | if (ix < 0) { |
| 569 | int n = SkMin32(-ix, count); |
| 570 | sk_memset32(colors, row[0], n); |
| 571 | count -= n; |
| 572 | if (0 == count) { |
| 573 | return; |
| 574 | } |
| 575 | colors += n; |
| 576 | SkASSERT(-ix == n); |
| 577 | ix = 0; |
| 578 | } |
| 579 | // copy the middle |
| 580 | if (ix <= maxX) { |
| 581 | int n = SkMin32(maxX - ix + 1, count); |
| 582 | memcpy(colors, row + ix, n * sizeof(SkPMColor)); |
| 583 | count -= n; |
| 584 | if (0 == count) { |
| 585 | return; |
| 586 | } |
| 587 | colors += n; |
| 588 | } |
| 589 | SkASSERT(count > 0); |
| 590 | // clamp to the right |
| 591 | sk_memset32(colors, row[maxX], count); |
| 592 | } |
| 593 | |
reed@google.com | a8d9930 | 2012-10-16 20:23:25 +0000 | [diff] [blame] | 594 | static inline int sk_int_mod(int x, int n) { |
| 595 | SkASSERT(n > 0); |
| 596 | if ((unsigned)x >= (unsigned)n) { |
| 597 | if (x < 0) { |
| 598 | x = n + ~(~x % n); |
| 599 | } else { |
| 600 | x = x % n; |
| 601 | } |
| 602 | } |
| 603 | return x; |
| 604 | } |
| 605 | |
robertphillips@google.com | 8b8bf4d | 2013-01-18 16:38:40 +0000 | [diff] [blame] | 606 | static inline int sk_int_mirror(int x, int n) { |
| 607 | x = sk_int_mod(x, 2 * n); |
| 608 | if (x >= n) { |
| 609 | x = n + ~(x - n); |
| 610 | } |
| 611 | return x; |
| 612 | } |
| 613 | |
reed@google.com | a8d9930 | 2012-10-16 20:23:25 +0000 | [diff] [blame] | 614 | static void Repeat_S32_D32_nofilter_trans_shaderproc(const SkBitmapProcState& s, |
| 615 | int x, int y, |
| 616 | SkPMColor* SK_RESTRICT colors, |
| 617 | int count) { |
| 618 | SkASSERT(((s.fInvType & ~SkMatrix::kTranslate_Mask)) == 0); |
| 619 | SkASSERT(s.fInvKy == 0); |
| 620 | SkASSERT(count > 0 && colors != NULL); |
reed@google.com | 9cfc83c | 2013-07-22 17:18:18 +0000 | [diff] [blame] | 621 | SkASSERT(SkPaint::kNone_FilterLevel == s.fFilterLevel); |
skia.committer@gmail.com | 20c301b | 2012-10-17 02:01:13 +0000 | [diff] [blame] | 622 | |
reed@google.com | a8d9930 | 2012-10-16 20:23:25 +0000 | [diff] [blame] | 623 | const int stopX = s.fBitmap->width(); |
| 624 | const int stopY = s.fBitmap->height(); |
| 625 | int ix = s.fFilterOneX + x; |
| 626 | int iy = sk_int_mod(s.fFilterOneY + y, stopY); |
| 627 | #ifdef SK_DEBUG |
| 628 | { |
| 629 | SkPoint pt; |
humper@google.com | 9c96d4b | 2013-07-14 01:44:59 +0000 | [diff] [blame] | 630 | s.fInvProc(s.fInvMatrix, SkIntToScalar(x) + SK_ScalarHalf, |
reed@google.com | a8d9930 | 2012-10-16 20:23:25 +0000 | [diff] [blame] | 631 | SkIntToScalar(y) + SK_ScalarHalf, &pt); |
| 632 | int iy2 = sk_int_mod(SkScalarFloorToInt(pt.fY), stopY); |
| 633 | int ix2 = SkScalarFloorToInt(pt.fX); |
skia.committer@gmail.com | 20c301b | 2012-10-17 02:01:13 +0000 | [diff] [blame] | 634 | |
reed@google.com | a8d9930 | 2012-10-16 20:23:25 +0000 | [diff] [blame] | 635 | SkASSERT(iy == iy2); |
| 636 | SkASSERT(ix == ix2); |
| 637 | } |
| 638 | #endif |
| 639 | const SkPMColor* row = s.fBitmap->getAddr32(0, iy); |
| 640 | |
| 641 | ix = sk_int_mod(ix, stopX); |
| 642 | for (;;) { |
| 643 | int n = SkMin32(stopX - ix, count); |
| 644 | memcpy(colors, row + ix, n * sizeof(SkPMColor)); |
| 645 | count -= n; |
| 646 | if (0 == count) { |
| 647 | return; |
| 648 | } |
| 649 | colors += n; |
| 650 | ix = 0; |
| 651 | } |
| 652 | } |
| 653 | |
robertphillips@google.com | 8b8bf4d | 2013-01-18 16:38:40 +0000 | [diff] [blame] | 654 | static void S32_D32_constX_shaderproc(const SkBitmapProcState& s, |
| 655 | int x, int y, |
| 656 | SkPMColor* SK_RESTRICT colors, |
| 657 | int count) { |
| 658 | SkASSERT((s.fInvType & ~(SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask)) == 0); |
| 659 | SkASSERT(s.fInvKy == 0); |
| 660 | SkASSERT(count > 0 && colors != NULL); |
| 661 | SkASSERT(1 == s.fBitmap->width()); |
| 662 | |
scroggo@google.com | ad51132 | 2013-02-22 15:50:37 +0000 | [diff] [blame] | 663 | int iY0; |
| 664 | int iY1 SK_INIT_TO_AVOID_WARNING; |
| 665 | int iSubY SK_INIT_TO_AVOID_WARNING; |
robertphillips@google.com | 8b8bf4d | 2013-01-18 16:38:40 +0000 | [diff] [blame] | 666 | |
reed@google.com | 9cfc83c | 2013-07-22 17:18:18 +0000 | [diff] [blame] | 667 | if (SkPaint::kNone_FilterLevel != s.fFilterLevel) { |
robertphillips@google.com | 8b8bf4d | 2013-01-18 16:38:40 +0000 | [diff] [blame] | 668 | SkBitmapProcState::MatrixProc mproc = s.getMatrixProc(); |
| 669 | uint32_t xy[2]; |
| 670 | |
| 671 | mproc(s, xy, 1, x, y); |
| 672 | |
| 673 | iY0 = xy[0] >> 18; |
| 674 | iY1 = xy[0] & 0x3FFF; |
| 675 | iSubY = (xy[0] >> 14) & 0xF; |
| 676 | } else { |
| 677 | int yTemp; |
| 678 | |
| 679 | if (s.fInvType > SkMatrix::kTranslate_Mask) { |
| 680 | SkPoint pt; |
humper@google.com | 9c96d4b | 2013-07-14 01:44:59 +0000 | [diff] [blame] | 681 | s.fInvProc(s.fInvMatrix, |
robertphillips@google.com | 8b8bf4d | 2013-01-18 16:38:40 +0000 | [diff] [blame] | 682 | SkIntToScalar(x) + SK_ScalarHalf, |
skia.committer@gmail.com | 36df7ed | 2013-01-19 07:05:38 +0000 | [diff] [blame] | 683 | SkIntToScalar(y) + SK_ScalarHalf, |
robertphillips@google.com | 8b8bf4d | 2013-01-18 16:38:40 +0000 | [diff] [blame] | 684 | &pt); |
robertphillips@google.com | 1e30523 | 2013-01-22 20:29:16 +0000 | [diff] [blame] | 685 | // When the matrix has a scale component the setup code in |
skia.committer@gmail.com | 98ded84 | 2013-01-23 07:06:17 +0000 | [diff] [blame] | 686 | // chooseProcs multiples the inverse matrix by the inverse of the |
robertphillips@google.com | 1e30523 | 2013-01-22 20:29:16 +0000 | [diff] [blame] | 687 | // bitmap's width and height. Since this method is going to do |
| 688 | // its own tiling and sampling we need to undo that here. |
robertphillips@google.com | d507775 | 2013-01-23 00:36:02 +0000 | [diff] [blame] | 689 | if (SkShader::kClamp_TileMode != s.fTileModeX || |
| 690 | SkShader::kClamp_TileMode != s.fTileModeY) { |
| 691 | yTemp = SkScalarFloorToInt(pt.fY * s.fBitmap->height()); |
| 692 | } else { |
| 693 | yTemp = SkScalarFloorToInt(pt.fY); |
| 694 | } |
robertphillips@google.com | 8b8bf4d | 2013-01-18 16:38:40 +0000 | [diff] [blame] | 695 | } else { |
| 696 | yTemp = s.fFilterOneY + y; |
| 697 | } |
| 698 | |
| 699 | const int stopY = s.fBitmap->height(); |
| 700 | switch (s.fTileModeY) { |
| 701 | case SkShader::kClamp_TileMode: |
| 702 | iY0 = SkClampMax(yTemp, stopY-1); |
| 703 | break; |
| 704 | case SkShader::kRepeat_TileMode: |
| 705 | iY0 = sk_int_mod(yTemp, stopY); |
| 706 | break; |
| 707 | case SkShader::kMirror_TileMode: |
| 708 | default: |
| 709 | iY0 = sk_int_mirror(yTemp, stopY); |
| 710 | break; |
| 711 | } |
| 712 | |
| 713 | #ifdef SK_DEBUG |
| 714 | { |
| 715 | SkPoint pt; |
humper@google.com | 9c96d4b | 2013-07-14 01:44:59 +0000 | [diff] [blame] | 716 | s.fInvProc(s.fInvMatrix, |
robertphillips@google.com | 8b8bf4d | 2013-01-18 16:38:40 +0000 | [diff] [blame] | 717 | SkIntToScalar(x) + SK_ScalarHalf, |
skia.committer@gmail.com | 36df7ed | 2013-01-19 07:05:38 +0000 | [diff] [blame] | 718 | SkIntToScalar(y) + SK_ScalarHalf, |
robertphillips@google.com | 8b8bf4d | 2013-01-18 16:38:40 +0000 | [diff] [blame] | 719 | &pt); |
robertphillips@google.com | d507775 | 2013-01-23 00:36:02 +0000 | [diff] [blame] | 720 | if (s.fInvType > SkMatrix::kTranslate_Mask && |
| 721 | (SkShader::kClamp_TileMode != s.fTileModeX || |
| 722 | SkShader::kClamp_TileMode != s.fTileModeY)) { |
robertphillips@google.com | 1e30523 | 2013-01-22 20:29:16 +0000 | [diff] [blame] | 723 | pt.fY *= s.fBitmap->height(); |
| 724 | } |
robertphillips@google.com | 8b8bf4d | 2013-01-18 16:38:40 +0000 | [diff] [blame] | 725 | int iY2; |
| 726 | |
| 727 | switch (s.fTileModeY) { |
| 728 | case SkShader::kClamp_TileMode: |
| 729 | iY2 = SkClampMax(SkScalarFloorToInt(pt.fY), stopY-1); |
| 730 | break; |
| 731 | case SkShader::kRepeat_TileMode: |
| 732 | iY2 = sk_int_mod(SkScalarFloorToInt(pt.fY), stopY); |
| 733 | break; |
| 734 | case SkShader::kMirror_TileMode: |
| 735 | default: |
| 736 | iY2 = sk_int_mirror(SkScalarFloorToInt(pt.fY), stopY); |
| 737 | break; |
| 738 | } |
| 739 | |
| 740 | SkASSERT(iY0 == iY2); |
| 741 | } |
| 742 | #endif |
| 743 | } |
| 744 | |
| 745 | const SkPMColor* row0 = s.fBitmap->getAddr32(0, iY0); |
| 746 | SkPMColor color; |
| 747 | |
reed@google.com | 9cfc83c | 2013-07-22 17:18:18 +0000 | [diff] [blame] | 748 | if (SkPaint::kNone_FilterLevel != s.fFilterLevel) { |
robertphillips@google.com | 8b8bf4d | 2013-01-18 16:38:40 +0000 | [diff] [blame] | 749 | const SkPMColor* row1 = s.fBitmap->getAddr32(0, iY1); |
| 750 | |
| 751 | if (s.fAlphaScale < 256) { |
| 752 | Filter_32_alpha(iSubY, *row0, *row1, &color, s.fAlphaScale); |
| 753 | } else { |
| 754 | Filter_32_opaque(iSubY, *row0, *row1, &color); |
| 755 | } |
| 756 | } else { |
| 757 | if (s.fAlphaScale < 256) { |
| 758 | color = SkAlphaMulQ(*row0, s.fAlphaScale); |
| 759 | } else { |
| 760 | color = *row0; |
| 761 | } |
| 762 | } |
| 763 | |
| 764 | sk_memset32(colors, color, count); |
| 765 | } |
| 766 | |
reed@google.com | 6bb92bc | 2012-11-20 19:45:16 +0000 | [diff] [blame] | 767 | static void DoNothing_shaderproc(const SkBitmapProcState&, int x, int y, |
| 768 | SkPMColor* SK_RESTRICT colors, int count) { |
| 769 | // if we get called, the matrix is too tricky, so we just draw nothing |
| 770 | sk_memset32(colors, 0, count); |
| 771 | } |
| 772 | |
| 773 | bool SkBitmapProcState::setupForTranslate() { |
reed@google.com | a8d9930 | 2012-10-16 20:23:25 +0000 | [diff] [blame] | 774 | SkPoint pt; |
humper@google.com | 9c96d4b | 2013-07-14 01:44:59 +0000 | [diff] [blame] | 775 | fInvProc(fInvMatrix, SK_ScalarHalf, SK_ScalarHalf, &pt); |
reed@google.com | 6bb92bc | 2012-11-20 19:45:16 +0000 | [diff] [blame] | 776 | |
| 777 | /* |
| 778 | * if the translate is larger than our ints, we can get random results, or |
| 779 | * worse, we might get 0x80000000, which wreaks havoc on us, since we can't |
| 780 | * negate it. |
| 781 | */ |
| 782 | const SkScalar too_big = SkIntToScalar(1 << 30); |
| 783 | if (SkScalarAbs(pt.fX) > too_big || SkScalarAbs(pt.fY) > too_big) { |
| 784 | return false; |
| 785 | } |
| 786 | |
reed@google.com | a8d9930 | 2012-10-16 20:23:25 +0000 | [diff] [blame] | 787 | // Since we know we're not filtered, we re-purpose these fields allow |
| 788 | // us to go from device -> src coordinates w/ just an integer add, |
| 789 | // rather than running through the inverse-matrix |
| 790 | fFilterOneX = SkScalarFloorToInt(pt.fX); |
| 791 | fFilterOneY = SkScalarFloorToInt(pt.fY); |
reed@google.com | 6bb92bc | 2012-11-20 19:45:16 +0000 | [diff] [blame] | 792 | return true; |
reed@google.com | a8d9930 | 2012-10-16 20:23:25 +0000 | [diff] [blame] | 793 | } |
| 794 | |
reed@google.com | 9a4c746 | 2012-10-12 18:21:37 +0000 | [diff] [blame] | 795 | SkBitmapProcState::ShaderProc32 SkBitmapProcState::chooseShaderProc32() { |
robertphillips@google.com | 8b8bf4d | 2013-01-18 16:38:40 +0000 | [diff] [blame] | 796 | |
commit-bot@chromium.org | cba7378 | 2014-05-29 15:57:47 +0000 | [diff] [blame] | 797 | if (kN32_SkColorType != fBitmap->colorType()) { |
robertphillips@google.com | 8b8bf4d | 2013-01-18 16:38:40 +0000 | [diff] [blame] | 798 | return NULL; |
| 799 | } |
| 800 | |
| 801 | static const unsigned kMask = SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask; |
| 802 | |
| 803 | if (1 == fBitmap->width() && 0 == (fInvType & ~kMask)) { |
reed@google.com | 9cfc83c | 2013-07-22 17:18:18 +0000 | [diff] [blame] | 804 | if (SkPaint::kNone_FilterLevel == fFilterLevel && |
humper@google.com | 9c96d4b | 2013-07-14 01:44:59 +0000 | [diff] [blame] | 805 | fInvType <= SkMatrix::kTranslate_Mask && |
| 806 | !this->setupForTranslate()) { |
robertphillips@google.com | 8b8bf4d | 2013-01-18 16:38:40 +0000 | [diff] [blame] | 807 | return DoNothing_shaderproc; |
| 808 | } |
| 809 | return S32_D32_constX_shaderproc; |
| 810 | } |
| 811 | |
reed@google.com | 9a4c746 | 2012-10-12 18:21:37 +0000 | [diff] [blame] | 812 | if (fAlphaScale < 256) { |
| 813 | return NULL; |
| 814 | } |
| 815 | if (fInvType > SkMatrix::kTranslate_Mask) { |
| 816 | return NULL; |
| 817 | } |
reed@google.com | 9cfc83c | 2013-07-22 17:18:18 +0000 | [diff] [blame] | 818 | if (SkPaint::kNone_FilterLevel != fFilterLevel) { |
reed@google.com | 9a4c746 | 2012-10-12 18:21:37 +0000 | [diff] [blame] | 819 | return NULL; |
| 820 | } |
reed@google.com | 9a4c746 | 2012-10-12 18:21:37 +0000 | [diff] [blame] | 821 | |
reed@google.com | a8d9930 | 2012-10-16 20:23:25 +0000 | [diff] [blame] | 822 | SkShader::TileMode tx = (SkShader::TileMode)fTileModeX; |
| 823 | SkShader::TileMode ty = (SkShader::TileMode)fTileModeY; |
| 824 | |
| 825 | if (SkShader::kClamp_TileMode == tx && SkShader::kClamp_TileMode == ty) { |
reed@google.com | 6bb92bc | 2012-11-20 19:45:16 +0000 | [diff] [blame] | 826 | if (this->setupForTranslate()) { |
| 827 | return Clamp_S32_D32_nofilter_trans_shaderproc; |
| 828 | } |
| 829 | return DoNothing_shaderproc; |
reed@google.com | 9a4c746 | 2012-10-12 18:21:37 +0000 | [diff] [blame] | 830 | } |
reed@google.com | a8d9930 | 2012-10-16 20:23:25 +0000 | [diff] [blame] | 831 | if (SkShader::kRepeat_TileMode == tx && SkShader::kRepeat_TileMode == ty) { |
reed@google.com | 6bb92bc | 2012-11-20 19:45:16 +0000 | [diff] [blame] | 832 | if (this->setupForTranslate()) { |
| 833 | return Repeat_S32_D32_nofilter_trans_shaderproc; |
| 834 | } |
| 835 | return DoNothing_shaderproc; |
reed@google.com | a8d9930 | 2012-10-16 20:23:25 +0000 | [diff] [blame] | 836 | } |
reed@google.com | 9a4c746 | 2012-10-12 18:21:37 +0000 | [diff] [blame] | 837 | return NULL; |
| 838 | } |
| 839 | |
reed@android.com | 4c128c4 | 2009-08-14 13:54:37 +0000 | [diff] [blame] | 840 | /////////////////////////////////////////////////////////////////////////////// |
reed@google.com | 9fe287b | 2012-03-27 15:54:28 +0000 | [diff] [blame] | 841 | |
| 842 | #ifdef SK_DEBUG |
| 843 | |
| 844 | static void check_scale_nofilter(uint32_t bitmapXY[], int count, |
| 845 | unsigned mx, unsigned my) { |
| 846 | unsigned y = *bitmapXY++; |
| 847 | SkASSERT(y < my); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 848 | |
reed@google.com | 9fe287b | 2012-03-27 15:54:28 +0000 | [diff] [blame] | 849 | const uint16_t* xptr = reinterpret_cast<const uint16_t*>(bitmapXY); |
| 850 | for (int i = 0; i < count; ++i) { |
| 851 | SkASSERT(xptr[i] < mx); |
| 852 | } |
| 853 | } |
| 854 | |
| 855 | static void check_scale_filter(uint32_t bitmapXY[], int count, |
| 856 | unsigned mx, unsigned my) { |
| 857 | uint32_t YY = *bitmapXY++; |
| 858 | unsigned y0 = YY >> 18; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 859 | unsigned y1 = YY & 0x3FFF; |
reed@google.com | 9fe287b | 2012-03-27 15:54:28 +0000 | [diff] [blame] | 860 | SkASSERT(y0 < my); |
| 861 | SkASSERT(y1 < my); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 862 | |
reed@google.com | 9fe287b | 2012-03-27 15:54:28 +0000 | [diff] [blame] | 863 | for (int i = 0; i < count; ++i) { |
| 864 | uint32_t XX = bitmapXY[i]; |
| 865 | unsigned x0 = XX >> 18; |
| 866 | unsigned x1 = XX & 0x3FFF; |
| 867 | SkASSERT(x0 < mx); |
| 868 | SkASSERT(x1 < mx); |
| 869 | } |
| 870 | } |
| 871 | |
| 872 | static void check_affine_nofilter(uint32_t bitmapXY[], int count, |
| 873 | unsigned mx, unsigned my) { |
| 874 | for (int i = 0; i < count; ++i) { |
| 875 | uint32_t XY = bitmapXY[i]; |
| 876 | unsigned x = XY & 0xFFFF; |
| 877 | unsigned y = XY >> 16; |
| 878 | SkASSERT(x < mx); |
| 879 | SkASSERT(y < my); |
| 880 | } |
| 881 | } |
| 882 | |
| 883 | static void check_affine_filter(uint32_t bitmapXY[], int count, |
| 884 | unsigned mx, unsigned my) { |
| 885 | for (int i = 0; i < count; ++i) { |
| 886 | uint32_t YY = *bitmapXY++; |
| 887 | unsigned y0 = YY >> 18; |
| 888 | unsigned y1 = YY & 0x3FFF; |
| 889 | SkASSERT(y0 < my); |
| 890 | SkASSERT(y1 < my); |
| 891 | |
| 892 | uint32_t XX = *bitmapXY++; |
| 893 | unsigned x0 = XX >> 18; |
| 894 | unsigned x1 = XX & 0x3FFF; |
| 895 | SkASSERT(x0 < mx); |
| 896 | SkASSERT(x1 < mx); |
| 897 | } |
| 898 | } |
| 899 | |
| 900 | void SkBitmapProcState::DebugMatrixProc(const SkBitmapProcState& state, |
| 901 | uint32_t bitmapXY[], int count, |
| 902 | int x, int y) { |
| 903 | SkASSERT(bitmapXY); |
| 904 | SkASSERT(count > 0); |
| 905 | |
| 906 | state.fMatrixProc(state, bitmapXY, count, x, y); |
| 907 | |
| 908 | void (*proc)(uint32_t bitmapXY[], int count, unsigned mx, unsigned my); |
| 909 | |
| 910 | // There are four formats possible: |
| 911 | // scale -vs- affine |
| 912 | // filter -vs- nofilter |
| 913 | if (state.fInvType <= (SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask)) { |
reed@google.com | 9cfc83c | 2013-07-22 17:18:18 +0000 | [diff] [blame] | 914 | proc = state.fFilterLevel != SkPaint::kNone_FilterLevel ? check_scale_filter : check_scale_nofilter; |
reed@google.com | 9fe287b | 2012-03-27 15:54:28 +0000 | [diff] [blame] | 915 | } else { |
reed@google.com | 9cfc83c | 2013-07-22 17:18:18 +0000 | [diff] [blame] | 916 | proc = state.fFilterLevel != SkPaint::kNone_FilterLevel ? check_affine_filter : check_affine_nofilter; |
reed@google.com | 9fe287b | 2012-03-27 15:54:28 +0000 | [diff] [blame] | 917 | } |
| 918 | proc(bitmapXY, count, state.fBitmap->width(), state.fBitmap->height()); |
| 919 | } |
| 920 | |
| 921 | SkBitmapProcState::MatrixProc SkBitmapProcState::getMatrixProc() const { |
| 922 | return DebugMatrixProc; |
| 923 | } |
| 924 | |
| 925 | #endif |
| 926 | |
| 927 | /////////////////////////////////////////////////////////////////////////////// |
reed@android.com | 4c128c4 | 2009-08-14 13:54:37 +0000 | [diff] [blame] | 928 | /* |
| 929 | The storage requirements for the different matrix procs are as follows, |
| 930 | where each X or Y is 2 bytes, and N is the number of pixels/elements: |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 931 | |
reed@android.com | 4c128c4 | 2009-08-14 13:54:37 +0000 | [diff] [blame] | 932 | scale/translate nofilter Y(4bytes) + N * X |
| 933 | affine/perspective nofilter N * (X Y) |
| 934 | scale/translate filter Y Y + N * (X X) |
| 935 | affine/perspective filter N * (Y Y X X) |
| 936 | */ |
| 937 | int SkBitmapProcState::maxCountForBufferSize(size_t bufferSize) const { |
| 938 | int32_t size = static_cast<int32_t>(bufferSize); |
reed@android.com | 4c128c4 | 2009-08-14 13:54:37 +0000 | [diff] [blame] | 939 | |
| 940 | size &= ~3; // only care about 4-byte aligned chunks |
| 941 | if (fInvType <= (SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask)) { |
| 942 | size -= 4; // the shared Y (or YY) coordinate |
| 943 | if (size < 0) { |
| 944 | size = 0; |
| 945 | } |
reed@android.com | 258cb22 | 2010-04-14 13:36:33 +0000 | [diff] [blame] | 946 | size >>= 1; |
reed@android.com | 4c128c4 | 2009-08-14 13:54:37 +0000 | [diff] [blame] | 947 | } else { |
reed@android.com | 258cb22 | 2010-04-14 13:36:33 +0000 | [diff] [blame] | 948 | size >>= 2; |
reed@android.com | 4c128c4 | 2009-08-14 13:54:37 +0000 | [diff] [blame] | 949 | } |
| 950 | |
reed@google.com | 9cfc83c | 2013-07-22 17:18:18 +0000 | [diff] [blame] | 951 | if (fFilterLevel != SkPaint::kNone_FilterLevel) { |
reed@android.com | 258cb22 | 2010-04-14 13:36:33 +0000 | [diff] [blame] | 952 | size >>= 1; |
| 953 | } |
| 954 | |
| 955 | return size; |
reed@android.com | 4c128c4 | 2009-08-14 13:54:37 +0000 | [diff] [blame] | 956 | } |
mtklein | 14e4d39 | 2014-10-23 14:35:01 -0700 | [diff] [blame] | 957 | |
| 958 | /////////////////////// |
| 959 | |
| 960 | void Clamp_S32_opaque_D32_nofilter_DX_shaderproc(const SkBitmapProcState& s, int x, int y, |
| 961 | SkPMColor* SK_RESTRICT dst, int count) { |
| 962 | SkASSERT((s.fInvType & ~(SkMatrix::kTranslate_Mask | |
| 963 | SkMatrix::kScale_Mask)) == 0); |
| 964 | |
| 965 | const unsigned maxX = s.fBitmap->width() - 1; |
| 966 | SkFractionalInt fx; |
| 967 | int dstY; |
| 968 | { |
| 969 | SkPoint pt; |
| 970 | s.fInvProc(s.fInvMatrix, SkIntToScalar(x) + SK_ScalarHalf, SkIntToScalar(y) + SK_ScalarHalf, |
| 971 | &pt); |
| 972 | fx = SkScalarToFractionalInt(pt.fY); |
| 973 | const unsigned maxY = s.fBitmap->height() - 1; |
| 974 | dstY = SkClampMax(SkFractionalIntToInt(fx), maxY); |
| 975 | fx = SkScalarToFractionalInt(pt.fX); |
| 976 | } |
| 977 | |
| 978 | const SkPMColor* SK_RESTRICT src = s.fBitmap->getAddr32(0, dstY); |
| 979 | const SkFractionalInt dx = s.fInvSxFractionalInt; |
| 980 | |
| 981 | // Check if we're safely inside [0...maxX] so no need to clamp each computed index. |
| 982 | // |
| 983 | if ((uint64_t)SkFractionalIntToInt(fx) <= maxX && |
| 984 | (uint64_t)SkFractionalIntToInt(fx + dx * (count - 1)) <= maxX) |
| 985 | { |
| 986 | int count4 = count >> 2; |
| 987 | for (int i = 0; i < count4; ++i) { |
| 988 | SkPMColor src0 = src[SkFractionalIntToInt(fx)]; fx += dx; |
| 989 | SkPMColor src1 = src[SkFractionalIntToInt(fx)]; fx += dx; |
| 990 | SkPMColor src2 = src[SkFractionalIntToInt(fx)]; fx += dx; |
| 991 | SkPMColor src3 = src[SkFractionalIntToInt(fx)]; fx += dx; |
| 992 | dst[0] = src0; |
| 993 | dst[1] = src1; |
| 994 | dst[2] = src2; |
| 995 | dst[3] = src3; |
| 996 | dst += 4; |
| 997 | } |
| 998 | for (int i = (count4 << 2); i < count; ++i) { |
| 999 | unsigned index = SkFractionalIntToInt(fx); |
| 1000 | SkASSERT(index <= maxX); |
| 1001 | *dst++ = src[index]; |
| 1002 | fx += dx; |
| 1003 | } |
| 1004 | } else { |
| 1005 | for (int i = 0; i < count; ++i) { |
| 1006 | dst[i] = src[SkClampMax(SkFractionalIntToInt(fx), maxX)]; |
| 1007 | fx += dx; |
| 1008 | } |
| 1009 | } |
| 1010 | } |
| 1011 | |