| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 #include "SkBitmapProcState.h" | 8 #include "SkBitmapProcState.h" |
| 9 #include "SkColorPriv.h" | 9 #include "SkColorPriv.h" |
| 10 #include "SkFilterProc.h" | 10 #include "SkFilterProc.h" |
| 11 #include "SkPaint.h" | 11 #include "SkPaint.h" |
| 12 #include "SkShader.h" // for tilemodes | 12 #include "SkShader.h" // for tilemodes |
| 13 #include "SkUtilsArm.h" | 13 #include "SkUtilsArm.h" |
| 14 #include "SkBitmapScaler.h" | 14 #include "SkBitmapScaler.h" |
| 15 #include "SkMipMap.h" |
| 15 #include "SkScaledImageCache.h" | 16 #include "SkScaledImageCache.h" |
| 16 | 17 |
| 17 #if !SK_ARM_NEON_IS_NONE | 18 #if !SK_ARM_NEON_IS_NONE |
| 18 // These are defined in src/opts/SkBitmapProcState_arm_neon.cpp | 19 // These are defined in src/opts/SkBitmapProcState_arm_neon.cpp |
| 19 extern const SkBitmapProcState::SampleProc16 gSkBitmapProcStateSample16_neon[]; | 20 extern const SkBitmapProcState::SampleProc16 gSkBitmapProcStateSample16_neon[]; |
| 20 extern const SkBitmapProcState::SampleProc32 gSkBitmapProcStateSample32_neon[]; | 21 extern const SkBitmapProcState::SampleProc32 gSkBitmapProcStateSample32_neon[]; |
| 21 extern void S16_D16_filter_DX_neon(const SkBitmapProcState&, const uint32_t*, i
nt, uint16_t*); | 22 extern void S16_D16_filter_DX_neon(const SkBitmapProcState&, const uint32_t*, i
nt, uint16_t*); |
| 22 extern void Clamp_S16_D16_filter_DX_shaderproc_neon(const SkBitmapProcState&, i
nt, int, uint16_t*, int); | 23 extern void Clamp_S16_D16_filter_DX_shaderproc_neon(const SkBitmapProcState&, i
nt, int, uint16_t*, int); |
| 23 extern void Repeat_S16_D16_filter_DX_shaderproc_neon(const SkBitmapProcState&,
int, int, uint16_t*, int); | 24 extern void Repeat_S16_D16_filter_DX_shaderproc_neon(const SkBitmapProcState&,
int, int, uint16_t*, int); |
| 24 extern void SI8_opaque_D32_filter_DX_neon(const SkBitmapProcState&, const uint3
2_t*, int, SkPMColor*); | 25 extern void SI8_opaque_D32_filter_DX_neon(const SkBitmapProcState&, const uint3
2_t*, int, SkPMColor*); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 } | 86 } |
| 86 | 87 |
| 87 /////////////////////////////////////////////////////////////////////////////// | 88 /////////////////////////////////////////////////////////////////////////////// |
| 88 | 89 |
| 89 static bool valid_for_filtering(unsigned dimension) { | 90 static bool valid_for_filtering(unsigned dimension) { |
| 90 // for filtering, width and height must fit in 14bits, since we use steal | 91 // for filtering, width and height must fit in 14bits, since we use steal |
| 91 // 2 bits from each to store our 4bit subpixel data | 92 // 2 bits from each to store our 4bit subpixel data |
| 92 return (dimension & ~0x3FFF) == 0; | 93 return (dimension & ~0x3FFF) == 0; |
| 93 } | 94 } |
| 94 | 95 |
| 95 static bool effective_matrix_scale_sqrd(const SkMatrix& mat) { | 96 static SkScalar effective_matrix_scale_sqrd(const SkMatrix& mat) { |
| 96 SkPoint v1, v2; | 97 SkPoint v1, v2; |
| 97 | 98 |
| 98 v1.fX = mat.getScaleX(); | 99 v1.fX = mat.getScaleX(); |
| 99 v1.fY = mat.getSkewY(); | 100 v1.fY = mat.getSkewY(); |
| 100 | 101 |
| 101 v2.fX = mat.getSkewX(); | 102 v2.fX = mat.getSkewX(); |
| 102 v2.fY = mat.getScaleY(); | 103 v2.fY = mat.getScaleY(); |
| 103 | 104 |
| 104 return SkMaxScalar(v1.lengthSqd(), v2.lengthSqd()); | 105 return SkMaxScalar(v1.lengthSqd(), v2.lengthSqd()); |
| 105 } | 106 } |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 } | 219 } |
| 219 | 220 |
| 220 SkASSERT(SkPaint::kMedium_FilterLevel == fFilterLevel); | 221 SkASSERT(SkPaint::kMedium_FilterLevel == fFilterLevel); |
| 221 | 222 |
| 222 /** | 223 /** |
| 223 * Medium quality means use a mipmap for down-scaling, and just bilper | 224 * Medium quality means use a mipmap for down-scaling, and just bilper |
| 224 * for upscaling. Since we're examining the inverse matrix, we look for | 225 * for upscaling. Since we're examining the inverse matrix, we look for |
| 225 * a scale > 1 to indicate down scaling by the CTM. | 226 * a scale > 1 to indicate down scaling by the CTM. |
| 226 */ | 227 */ |
| 227 if (scaleSqd > SK_Scalar1) { | 228 if (scaleSqd > SK_Scalar1) { |
| 228 if (!fOrigBitmap.hasMipMap()) { | 229 const SkMipMap* mip = NULL; |
| 229 fOrigBitmap.buildMipMap(); | 230 |
| 230 // build may fail, so we need to check again | 231 SkASSERT(NULL == fScaledCacheID); |
| 232 fScaledCacheID = SkScaledImageCache::FindAndLockMip(fOrigBitmap, &mip); |
| 233 if (!fScaledCacheID) { |
| 234 SkASSERT(NULL == mip); |
| 235 mip = SkMipMap::Build(fOrigBitmap); |
| 236 if (mip) { |
| 237 fScaledCacheID = SkScaledImageCache::AddAndLockMip(fOrigBitmap, |
| 238 mip); |
| 239 mip->unref(); // the cache took a ref |
| 240 SkASSERT(fScaledCacheID); |
| 241 } |
| 242 } else { |
| 243 SkASSERT(mip); |
| 231 } | 244 } |
| 232 if (fOrigBitmap.hasMipMap()) { | 245 |
| 233 int shift = fOrigBitmap.extractMipLevel(&fScaledBitmap, | 246 if (mip) { |
| 234 SkScalarToFixed(fInvMatrix.getScaleX()), | 247 SkScalar levelScale = SkScalarInvert(SkScalarSqrt(scaleSqd)); |
| 235 SkScalarToFixed(fInvMatrix.getSkewY())); | 248 SkMipMap::Level level; |
| 236 if (shift > 0) { | 249 if (mip->extractLevel(levelScale, &level)) { |
| 237 SkScalar scale = SkFixedToScalar(SK_Fixed1 >> shift); | 250 SkScalar invScaleFixup = level.fScale; |
| 238 fInvMatrix.postScale(scale, scale); | 251 fInvMatrix.postScale(invScaleFixup, invScaleFixup); |
| 252 |
| 253 fScaledBitmap.setConfig(fOrigBitmap.config(), |
| 254 level.fWidth, level.fHeight, |
| 255 level.fRowBytes); |
| 256 fScaledBitmap.setPixels(level.fPixels); |
| 239 fBitmap = &fScaledBitmap; | 257 fBitmap = &fScaledBitmap; |
| 240 } | 258 } |
| 241 } | 259 } |
| 242 } | 260 } |
| 243 | 261 |
| 244 // Now that we've built the mipmaps (if applicable), we set the filter-level | 262 /* |
| 245 // bilinear interpolation. | 263 * At this point, we may or may not have built a mipmap. Regardless, we |
| 264 * now fall back on Low so will bilerp whatever fBitmap now points at. |
| 265 */ |
| 246 fFilterLevel = SkPaint::kLow_FilterLevel; | 266 fFilterLevel = SkPaint::kLow_FilterLevel; |
| 247 } | 267 } |
| 248 | 268 |
| 249 void SkBitmapProcState::endContext() { | 269 void SkBitmapProcState::endContext() { |
| 250 SkDELETE(fBitmapFilter); | 270 SkDELETE(fBitmapFilter); |
| 251 fBitmapFilter = NULL; | 271 fBitmapFilter = NULL; |
| 252 fScaledBitmap.reset(); | 272 fScaledBitmap.reset(); |
| 253 | 273 |
| 254 if (fScaledCacheID) { | 274 if (fScaledCacheID) { |
| 255 SkScaledImageCache::Unlock(fScaledCacheID); | 275 SkScaledImageCache::Unlock(fScaledCacheID); |
| (...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 916 } else { | 936 } else { |
| 917 size >>= 2; | 937 size >>= 2; |
| 918 } | 938 } |
| 919 | 939 |
| 920 if (fFilterLevel != SkPaint::kNone_FilterLevel) { | 940 if (fFilterLevel != SkPaint::kNone_FilterLevel) { |
| 921 size >>= 1; | 941 size >>= 1; |
| 922 } | 942 } |
| 923 | 943 |
| 924 return size; | 944 return size; |
| 925 } | 945 } |
| OLD | NEW |