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

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

Issue 675823002: Fix the way we patch up the matrix for scaled images that aren't (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 1 month 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
« gm/tiledscaledbitmap.cpp ('K') | « gyp/gmslides.gypi ('k') | no next file » | 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 * 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 "SkBitmapProcState.h" 9 #include "SkBitmapProcState.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 < (maximumAllocation * invMat.getScaleX() * invMat.getScaleY()); 122 < (maximumAllocation * invMat.getScaleX() * invMat.getScaleY());
123 } 123 }
124 124
125 // TODO -- we may want to pass the clip into this function so we only scale 125 // TODO -- we may want to pass the clip into this function so we only scale
126 // the portion of the image that we're going to need. This will complicate 126 // the portion of the image that we're going to need. This will complicate
127 // the interface to the cache, but might be well worth it. 127 // the interface to the cache, but might be well worth it.
128 128
129 bool SkBitmapProcState::possiblyScaleImage() { 129 bool SkBitmapProcState::possiblyScaleImage() {
130 SkASSERT(NULL == fBitmap); 130 SkASSERT(NULL == fBitmap);
131 131
132 fAdjustedMatrix = false;
133
134 if (fFilterLevel <= SkPaint::kLow_FilterLevel) { 132 if (fFilterLevel <= SkPaint::kLow_FilterLevel) {
135 return false; 133 return false;
136 } 134 }
137 // Check to see if the transformation matrix is simple, and if we're 135 // 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 136 // doing high quality scaling. If so, do the bitmap scale here and
139 // remove the (non-fractional) scaling component from the matrix. 137 // remove the (non-fractional) scaling component from the matrix.
140 138
141 SkScalar invScaleX = fInvMatrix.getScaleX(); 139 SkScalar invScaleX = fInvMatrix.getScaleX();
142 SkScalar invScaleY = fInvMatrix.getScaleY(); 140 SkScalar invScaleY = fInvMatrix.getScaleY();
143 141
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 } 187 }
190 188
191 SkASSERT(fScaledBitmap.getPixels()); 189 SkASSERT(fScaledBitmap.getPixels());
192 fScaledBitmap.setImmutable(); 190 fScaledBitmap.setImmutable();
193 SkBitmapCache::Add(fOrigBitmap, roundedDestWidth, roundedDestHeight, fScaledBitmap); 191 SkBitmapCache::Add(fOrigBitmap, roundedDestWidth, roundedDestHeight, fScaledBitmap);
194 } 192 }
195 193
196 SkASSERT(fScaledBitmap.getPixels()); 194 SkASSERT(fScaledBitmap.getPixels());
197 fBitmap = &fScaledBitmap; 195 fBitmap = &fScaledBitmap;
198 196
199 // set the inv matrix type to translate-only; 197 // clean up the inverse matrix by incorporating the scale we just perfor med.
200 fInvMatrix.setTranslate(fInvMatrix.getTranslateX() / fInvMatrix.getScale X(),
201 fInvMatrix.getTranslateY() / fInvMatrix.getScale Y());
202 198
203 #ifndef SK_IGNORE_PROPER_FRACTIONAL_SCALING 199 fInvMatrix.postScale(roundedDestWidth / fOrigBitmap.width(),
204 // reintroduce any fractional scaling missed by our integral scale done above. 200 roundedDestHeight / fOrigBitmap.height());
205
206 float fractionalScaleX = roundedDestWidth/trueDestWidth;
207 float fractionalScaleY = roundedDestHeight/trueDestHeight;
208
209 fInvMatrix.postScale(fractionalScaleX, fractionalScaleY);
210 #endif
211 fAdjustedMatrix = true;
212 201
213 // Set our filter level to low -- the only post-filtering this 202 // Set our filter level to low -- the only post-filtering this
214 // image might require is some interpolation if the translation 203 // image might require is some interpolation if the translation
215 // is fractional or if there's any remaining scaling to be done. 204 // is fractional or if there's any remaining scaling to be done.
216 fFilterLevel = SkPaint::kLow_FilterLevel; 205 fFilterLevel = SkPaint::kLow_FilterLevel;
217 return true; 206 return true;
218 } 207 }
219 208
220 /* 209 /*
221 * If High, then our special-case for scale-only did not take, and so we 210 * If High, then our special-case for scale-only did not take, and so we
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 // If we are "still" kMedium_FilterLevel, then the request was not fulfilled by possiblyScale, 354 // If we are "still" kMedium_FilterLevel, then the request was not fulfilled by possiblyScale,
366 // so we downgrade to kLow (so the rest of the sniffing code can assume that ) 355 // so we downgrade to kLow (so the rest of the sniffing code can assume that )
367 if (SkPaint::kMedium_FilterLevel == fFilterLevel) { 356 if (SkPaint::kMedium_FilterLevel == fFilterLevel) {
368 fFilterLevel = SkPaint::kLow_FilterLevel; 357 fFilterLevel = SkPaint::kLow_FilterLevel;
369 } 358 }
370 359
371 bool trivialMatrix = (fInvMatrix.getType() & ~SkMatrix::kTranslate_Mask) == 0; 360 bool trivialMatrix = (fInvMatrix.getType() & ~SkMatrix::kTranslate_Mask) == 0;
372 bool clampClamp = SkShader::kClamp_TileMode == fTileModeX && 361 bool clampClamp = SkShader::kClamp_TileMode == fTileModeX &&
373 SkShader::kClamp_TileMode == fTileModeY; 362 SkShader::kClamp_TileMode == fTileModeY;
374 363
375 if (!(fAdjustedMatrix || clampClamp || trivialMatrix)) { 364 // TODO(reed): The following conditional and matrix division could really us e
376 fInvMatrix.postIDiv(fOrigBitmap.width(), fOrigBitmap.height()); 365 // a comment!
366
367 if (!(clampClamp || trivialMatrix)) {
368 fInvMatrix.postIDiv(fBitmap->width(), fBitmap->height());
377 } 369 }
378 370
379 // Now that all possible changes to the matrix have taken place, check 371 // Now that all possible changes to the matrix have taken place, check
380 // to see if we're really close to a no-scale matrix. If so, explicitly 372 // to see if we're really close to a no-scale matrix. If so, explicitly
381 // set it to be so. Subsequent code may inspect this matrix to choose 373 // set it to be so. Subsequent code may inspect this matrix to choose
382 // a faster path in this case. 374 // a faster path in this case.
383 375
384 // This code will only execute if the matrix has some scale component; 376 // This code will only execute if the matrix has some scale component;
385 // if it's already pure translate then we won't do this inversion. 377 // if it's already pure translate then we won't do this inversion.
386 378
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after
1012 } else { 1004 } else {
1013 size >>= 2; 1005 size >>= 2;
1014 } 1006 }
1015 1007
1016 if (fFilterLevel != SkPaint::kNone_FilterLevel) { 1008 if (fFilterLevel != SkPaint::kNone_FilterLevel) {
1017 size >>= 1; 1009 size >>= 1;
1018 } 1010 }
1019 1011
1020 return size; 1012 return size;
1021 } 1013 }
OLDNEW
« gm/tiledscaledbitmap.cpp ('K') | « gyp/gmslides.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698