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 "SkScaledImageCache.h" |
15 | 16 |
16 #if !SK_ARM_NEON_IS_NONE | 17 #if !SK_ARM_NEON_IS_NONE |
17 // These are defined in src/opts/SkBitmapProcState_arm_neon.cpp | 18 // These are defined in src/opts/SkBitmapProcState_arm_neon.cpp |
18 extern const SkBitmapProcState::SampleProc16 gSkBitmapProcStateSample16_neon[]; | 19 extern const SkBitmapProcState::SampleProc16 gSkBitmapProcStateSample16_neon[]; |
19 extern const SkBitmapProcState::SampleProc32 gSkBitmapProcStateSample32_neon[]; | 20 extern const SkBitmapProcState::SampleProc32 gSkBitmapProcStateSample32_neon[]; |
20 extern void S16_D16_filter_DX_neon(const SkBitmapProcState&, const uint32_t*, i
nt, uint16_t*); | 21 extern void S16_D16_filter_DX_neon(const SkBitmapProcState&, const uint32_t*, i
nt, uint16_t*); |
21 extern void Clamp_S16_D16_filter_DX_shaderproc_neon(const SkBitmapProcState&, i
nt, int, uint16_t*, int); | 22 extern void Clamp_S16_D16_filter_DX_shaderproc_neon(const SkBitmapProcState&, i
nt, int, uint16_t*, int); |
22 extern void Repeat_S16_D16_filter_DX_shaderproc_neon(const SkBitmapProcState&,
int, int, uint16_t*, int); | 23 extern void Repeat_S16_D16_filter_DX_shaderproc_neon(const SkBitmapProcState&,
int, int, uint16_t*, int); |
23 extern void SI8_opaque_D32_filter_DX_neon(const SkBitmapProcState&, const uint3
2_t*, int, SkPMColor*); | 24 extern void SI8_opaque_D32_filter_DX_neon(const SkBitmapProcState&, const uint3
2_t*, int, SkPMColor*); |
24 extern void SI8_opaque_D32_filter_DX_shaderproc_neon(const SkBitmapProcState&,
int, int, uint32_t*, int); | 25 extern void SI8_opaque_D32_filter_DX_shaderproc_neon(const SkBitmapProcState&,
int, int, uint32_t*, int); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 // STEP 1: Highest quality direct scale? | 136 // STEP 1: Highest quality direct scale? |
136 | 137 |
137 // Check to see if the transformation matrix is simple, and if we're | 138 // Check to see if the transformation matrix is simple, and if we're |
138 // doing high quality scaling. If so, do the bitmap scale here and | 139 // doing high quality scaling. If so, do the bitmap scale here and |
139 // remove the scaling component from the matrix. | 140 // remove the scaling component from the matrix. |
140 | 141 |
141 if (SkPaint::kHigh_FilterLevel == fFilterLevel && | 142 if (SkPaint::kHigh_FilterLevel == fFilterLevel && |
142 fInvMatrix.getType() <= (SkMatrix::kScale_Mask | SkMatrix::kTranslate_Ma
sk) && | 143 fInvMatrix.getType() <= (SkMatrix::kScale_Mask | SkMatrix::kTranslate_Ma
sk) && |
143 fOrigBitmap.config() == SkBitmap::kARGB_8888_Config) { | 144 fOrigBitmap.config() == SkBitmap::kARGB_8888_Config) { |
144 | 145 |
145 int dest_width = SkScalarCeilToInt(fOrigBitmap.width() / fInvMatrix.get
ScaleX()); | 146 SkScalar invScaleX = fInvMatrix.getScaleX(); |
146 int dest_height = SkScalarCeilToInt(fOrigBitmap.height() / fInvMatrix.ge
tScaleY()); | 147 SkScalar invScaleY = fInvMatrix.getScaleY(); |
| 148 |
| 149 SkASSERT(NULL == fScaledCacheID); |
| 150 fScaledCacheID = SkScaledImageCache::FindAndLock(fOrigBitmap, |
| 151 invScaleX, invScaleY, |
| 152 &fScaledBitmap); |
| 153 if (NULL == fScaledCacheID) { |
| 154 int dest_width = SkScalarCeilToInt(fOrigBitmap.width() / invScaleX)
; |
| 155 int dest_height = SkScalarCeilToInt(fOrigBitmap.height() / invScaleY
); |
147 | 156 |
148 // All the criteria are met; let's make a new bitmap. | 157 // All the criteria are met; let's make a new bitmap. |
149 | 158 |
150 fScaledBitmap = SkBitmapScaler::Resize( fOrigBitmap, SkBitmapScaler::RES
IZE_BEST, | 159 fScaledBitmap = SkBitmapScaler::Resize(fOrigBitmap, |
151 dest_width, dest_height, fConvol
utionProcs ); | 160 SkBitmapScaler::RESIZE_BEST, |
152 | 161 dest_width, |
| 162 dest_height, |
| 163 fConvolutionProcs); |
| 164 fScaledCacheID = SkScaledImageCache::AddAndLock(fOrigBitmap, |
| 165 invScaleX, |
| 166 invScaleY, |
| 167 fScaledBitmap); |
| 168 } |
153 fScaledBitmap.lockPixels(); | 169 fScaledBitmap.lockPixels(); |
154 | 170 |
155 fBitmap = &fScaledBitmap; | 171 fBitmap = &fScaledBitmap; |
156 | 172 |
157 // set the inv matrix type to translate-only; | 173 // set the inv matrix type to translate-only; |
158 | 174 |
159 fInvMatrix.setTranslate( 1/fInvMatrix.getScaleX() * fInvMatrix.getTransl
ateX(), | 175 fInvMatrix.setTranslate( 1/fInvMatrix.getScaleX() * fInvMatrix.getTransl
ateX(), |
160 1/fInvMatrix.getScaleY() * fInvMatrix.getTransl
ateY() ); | 176 1/fInvMatrix.getScaleY() * fInvMatrix.getTransl
ateY() ); |
161 | 177 |
162 // no need for any further filtering; we just did it! | 178 // no need for any further filtering; we just did it! |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 | 243 |
228 // Now that we've built the mipmaps (if applicable), we set the filter-level | 244 // Now that we've built the mipmaps (if applicable), we set the filter-level |
229 // bilinear interpolation. | 245 // bilinear interpolation. |
230 fFilterLevel = SkPaint::kLow_FilterLevel; | 246 fFilterLevel = SkPaint::kLow_FilterLevel; |
231 } | 247 } |
232 | 248 |
233 void SkBitmapProcState::endContext() { | 249 void SkBitmapProcState::endContext() { |
234 SkDELETE(fBitmapFilter); | 250 SkDELETE(fBitmapFilter); |
235 fBitmapFilter = NULL; | 251 fBitmapFilter = NULL; |
236 fScaledBitmap.reset(); | 252 fScaledBitmap.reset(); |
| 253 |
| 254 if (fScaledCacheID) { |
| 255 SkScaledImageCache::Unlock(fScaledCacheID); |
| 256 fScaledCacheID = NULL; |
| 257 } |
237 } | 258 } |
238 | 259 |
239 bool SkBitmapProcState::chooseProcs(const SkMatrix& inv, const SkPaint& paint) { | 260 bool SkBitmapProcState::chooseProcs(const SkMatrix& inv, const SkPaint& paint) { |
240 if (fOrigBitmap.width() == 0 || fOrigBitmap.height() == 0) { | 261 if (fOrigBitmap.width() == 0 || fOrigBitmap.height() == 0) { |
241 return false; | 262 return false; |
242 } | 263 } |
243 | 264 |
244 bool trivialMatrix = (inv.getType() & ~SkMatrix::kTranslate_Mask) == 0; | 265 bool trivialMatrix = (inv.getType() & ~SkMatrix::kTranslate_Mask) == 0; |
245 bool clampClamp = SkShader::kClamp_TileMode == fTileModeX && | 266 bool clampClamp = SkShader::kClamp_TileMode == fTileModeX && |
246 SkShader::kClamp_TileMode == fTileModeY; | 267 SkShader::kClamp_TileMode == fTileModeY; |
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
895 } else { | 916 } else { |
896 size >>= 2; | 917 size >>= 2; |
897 } | 918 } |
898 | 919 |
899 if (fFilterLevel != SkPaint::kNone_FilterLevel) { | 920 if (fFilterLevel != SkPaint::kNone_FilterLevel) { |
900 size >>= 1; | 921 size >>= 1; |
901 } | 922 } |
902 | 923 |
903 return size; | 924 return size; |
904 } | 925 } |
OLD | NEW |