Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: src/core/SkBitmapProcState.cpp

Issue 456843002: short circuit high quality scales that are actually the identity (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Move erroneous assert into parent if() condition Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/core/SkBitmapProcState_matrixProcs.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 // remove the scaling component from the matrix. 160 // remove the scaling component from the matrix.
161 161
162 if (SkPaint::kHigh_FilterLevel == fFilterLevel && 162 if (SkPaint::kHigh_FilterLevel == fFilterLevel &&
163 fInvMatrix.getType() <= (SkMatrix::kScale_Mask | SkMatrix::kTranslate_Ma sk) && 163 fInvMatrix.getType() <= (SkMatrix::kScale_Mask | SkMatrix::kTranslate_Ma sk) &&
164 kN32_SkColorType == fOrigBitmap.colorType() && 164 kN32_SkColorType == fOrigBitmap.colorType() &&
165 cache_size_okay(fOrigBitmap, fInvMatrix)) { 165 cache_size_okay(fOrigBitmap, fInvMatrix)) {
166 166
167 SkScalar invScaleX = fInvMatrix.getScaleX(); 167 SkScalar invScaleX = fInvMatrix.getScaleX();
168 SkScalar invScaleY = fInvMatrix.getScaleY(); 168 SkScalar invScaleY = fInvMatrix.getScaleY();
169 169
170 if (SkScalarNearlyEqual(invScaleX,1.0f) &&
171 SkScalarNearlyEqual(invScaleY,1.0f)) {
172 // short-circuit identity scaling; the output is supposed to
173 // be the same as the input, so we might as well go fast.
174
175 // Note(humper): We could also probably do this if the scales
176 // are close to -1 as well, since the flip doesn't require
177 // any fancy re-sampling...
178
179 // Set our filter level to low -- the only post-filtering this
180 // image might require is some interpolation if the translation
181 // is fractional.
182 fFilterLevel = SkPaint::kLow_FilterLevel;
183 return false;
184 }
185
170 fScaledCacheID = SkScaledImageCache::FindAndLock(fOrigBitmap, 186 fScaledCacheID = SkScaledImageCache::FindAndLock(fOrigBitmap,
171 invScaleX, invScaleY, 187 invScaleX, invScaleY,
172 &fScaledBitmap); 188 &fScaledBitmap);
173 if (fScaledCacheID) { 189 if (fScaledCacheID) {
174 fScaledBitmap.lockPixels(); 190 fScaledBitmap.lockPixels();
175 if (!fScaledBitmap.getPixels()) { 191 if (!fScaledBitmap.getPixels()) {
176 fScaledBitmap.unlockPixels(); 192 fScaledBitmap.unlockPixels();
177 // found a purged entry (discardablememory?), release it 193 // found a purged entry (discardablememory?), release it
178 SkScaledImageCache::Unlock(fScaledCacheID); 194 SkScaledImageCache::Unlock(fScaledCacheID);
179 fScaledCacheID = NULL; 195 fScaledCacheID = NULL;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 SkASSERT(NULL != fScaledBitmap.getPixels()); 227 SkASSERT(NULL != fScaledBitmap.getPixels());
212 } 228 }
213 229
214 SkASSERT(NULL != fScaledBitmap.getPixels()); 230 SkASSERT(NULL != fScaledBitmap.getPixels());
215 fBitmap = &fScaledBitmap; 231 fBitmap = &fScaledBitmap;
216 232
217 // set the inv matrix type to translate-only; 233 // set the inv matrix type to translate-only;
218 fInvMatrix.setTranslate(fInvMatrix.getTranslateX() / fInvMatrix.getScale X(), 234 fInvMatrix.setTranslate(fInvMatrix.getTranslateX() / fInvMatrix.getScale X(),
219 fInvMatrix.getTranslateY() / fInvMatrix.getScale Y()); 235 fInvMatrix.getTranslateY() / fInvMatrix.getScale Y());
220 236
221 // no need for any further filtering; we just did it! 237 // Set our filter level to low -- the only post-filtering this
222 fFilterLevel = SkPaint::kNone_FilterLevel; 238 // image might require is some interpolation if the translation
239 // is fractional.
240 fFilterLevel = SkPaint::kLow_FilterLevel;
223 unlocker.release(); 241 unlocker.release();
224 return true; 242 return true;
225 } 243 }
226 244
227 /* 245 /*
228 * If High, then our special-case for scale-only did not take, and so we 246 * If High, then our special-case for scale-only did not take, and so we
229 * have to make a choice: 247 * have to make a choice:
230 * 1. fall back on mipmaps + bilerp 248 * 1. fall back on mipmaps + bilerp
231 * 2. fall back on scanline bicubic filter 249 * 2. fall back on scanline bicubic filter
232 * For now, we compute the "scale" value from the matrix, and have a 250 * For now, we compute the "scale" value from the matrix, and have a
(...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after
1055 } else { 1073 } else {
1056 size >>= 2; 1074 size >>= 2;
1057 } 1075 }
1058 1076
1059 if (fFilterLevel != SkPaint::kNone_FilterLevel) { 1077 if (fFilterLevel != SkPaint::kNone_FilterLevel) {
1060 size >>= 1; 1078 size >>= 1;
1061 } 1079 }
1062 1080
1063 return size; 1081 return size;
1064 } 1082 }
OLDNEW
« no previous file with comments | « no previous file | src/core/SkBitmapProcState_matrixProcs.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698