| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkBitmapCache.h" | 8 #include "SkBitmapCache.h" |
| 9 #include "SkBitmapController.h" | 9 #include "SkBitmapController.h" |
| 10 #include "SkBitmapProcState.h" | 10 #include "SkBitmapProcState.h" |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 fInvKy = SkScalarToFixed(fInvMatrix.getSkewY()); | 188 fInvKy = SkScalarToFixed(fInvMatrix.getSkewY()); |
| 189 fInvKyFractionalInt = SkScalarToFractionalInt(fInvMatrix.getSkewY()); | 189 fInvKyFractionalInt = SkScalarToFractionalInt(fInvMatrix.getSkewY()); |
| 190 | 190 |
| 191 fAlphaScale = SkAlpha255To256(paint.getAlpha()); | 191 fAlphaScale = SkAlpha255To256(paint.getAlpha()); |
| 192 | 192 |
| 193 fShaderProc32 = nullptr; | 193 fShaderProc32 = nullptr; |
| 194 fShaderProc16 = nullptr; | 194 fShaderProc16 = nullptr; |
| 195 fSampleProc32 = nullptr; | 195 fSampleProc32 = nullptr; |
| 196 fSampleProc16 = nullptr; | 196 fSampleProc16 = nullptr; |
| 197 | 197 |
| 198 #ifndef SK_SUPPORT_LEGACY_BITMAP_SAMPLER_BIAS |
| 199 // We only need a bias when the scale is positive: for negative scales |
| 200 // we're rounding in the right direction intrinsically. |
| 201 fInvBiasX = -(fInvMatrix.getScaleX() > 0); |
| 202 fInvBiasY = -(fInvMatrix.getScaleY() > 0); |
| 203 #else |
| 204 fInvBiasX = fInvBiasY = 0; |
| 205 #endif |
| 206 |
| 198 // recompute the triviality of the matrix here because we may have | 207 // recompute the triviality of the matrix here because we may have |
| 199 // changed it! | 208 // changed it! |
| 200 | 209 |
| 201 trivialMatrix = (fInvMatrix.getType() & ~SkMatrix::kTranslate_Mask) == 0; | 210 trivialMatrix = (fInvMatrix.getType() & ~SkMatrix::kTranslate_Mask) == 0; |
| 202 | 211 |
| 203 if (kLow_SkFilterQuality == fFilterLevel) { | 212 if (kLow_SkFilterQuality == fFilterLevel) { |
| 204 // Only try bilerp if the matrix is "interesting" and | 213 // Only try bilerp if the matrix is "interesting" and |
| 205 // the image has a suitable size. | 214 // the image has a suitable size. |
| 206 | 215 |
| 207 if (fInvType <= SkMatrix::kTranslate_Mask || | 216 if (fInvType <= SkMatrix::kTranslate_Mask || |
| (...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 816 SkASSERT((s.fInvType & ~(SkMatrix::kTranslate_Mask | | 825 SkASSERT((s.fInvType & ~(SkMatrix::kTranslate_Mask | |
| 817 SkMatrix::kScale_Mask)) == 0); | 826 SkMatrix::kScale_Mask)) == 0); |
| 818 | 827 |
| 819 const unsigned maxX = s.fPixmap.width() - 1; | 828 const unsigned maxX = s.fPixmap.width() - 1; |
| 820 SkFractionalInt fx; | 829 SkFractionalInt fx; |
| 821 int dstY; | 830 int dstY; |
| 822 { | 831 { |
| 823 SkPoint pt; | 832 SkPoint pt; |
| 824 s.fInvProc(s.fInvMatrix, SkIntToScalar(x) + SK_ScalarHalf, SkIntToScalar
(y) + SK_ScalarHalf, | 833 s.fInvProc(s.fInvMatrix, SkIntToScalar(x) + SK_ScalarHalf, SkIntToScalar
(y) + SK_ScalarHalf, |
| 825 &pt); | 834 &pt); |
| 826 fx = SkScalarToFractionalInt(pt.fY) | 835 fx = SkScalarToFractionalInt(pt.fY) + SkFixedToFractionalInt(s.fInvBiasY
); |
| 827 + bitmap_sampler_inv_bias(s.fInvMatrix.getScaleY()); | |
| 828 const unsigned maxY = s.fPixmap.height() - 1; | 836 const unsigned maxY = s.fPixmap.height() - 1; |
| 829 dstY = SkClampMax(SkFractionalIntToInt(fx), maxY); | 837 dstY = SkClampMax(SkFractionalIntToInt(fx), maxY); |
| 830 fx = SkScalarToFractionalInt(pt.fX) | 838 fx = SkScalarToFractionalInt(pt.fX) + SkFixedToFractionalInt(s.fInvBiasX
); |
| 831 + bitmap_sampler_inv_bias(s.fInvMatrix.getScaleX()); | |
| 832 } | 839 } |
| 833 | 840 |
| 834 const SkPMColor* SK_RESTRICT src = s.fPixmap.addr32(0, dstY); | 841 const SkPMColor* SK_RESTRICT src = s.fPixmap.addr32(0, dstY); |
| 835 const SkFractionalInt dx = s.fInvSxFractionalInt; | 842 const SkFractionalInt dx = s.fInvSxFractionalInt; |
| 836 | 843 |
| 837 // Check if we're safely inside [0...maxX] so no need to clamp each computed
index. | 844 // Check if we're safely inside [0...maxX] so no need to clamp each computed
index. |
| 838 // | 845 // |
| 839 if ((uint64_t)SkFractionalIntToInt(fx) <= maxX && | 846 if ((uint64_t)SkFractionalIntToInt(fx) <= maxX && |
| 840 (uint64_t)SkFractionalIntToInt(fx + dx * (count - 1)) <= maxX) | 847 (uint64_t)SkFractionalIntToInt(fx + dx * (count - 1)) <= maxX) |
| 841 { | 848 { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 858 fx += dx; | 865 fx += dx; |
| 859 } | 866 } |
| 860 } else { | 867 } else { |
| 861 for (int i = 0; i < count; ++i) { | 868 for (int i = 0; i < count; ++i) { |
| 862 dst[i] = src[SkClampMax(SkFractionalIntToInt(fx), maxX)]; | 869 dst[i] = src[SkClampMax(SkFractionalIntToInt(fx), maxX)]; |
| 863 fx += dx; | 870 fx += dx; |
| 864 } | 871 } |
| 865 } | 872 } |
| 866 } | 873 } |
| 867 | 874 |
| OLD | NEW |