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

Side by Side Diff: src/gpu/effects/GrBicubicEffect.cpp

Issue 282293004: Centralize decision about whether to do bicubic filtering, and fallbacks to mip, bilerp, or nearest (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « src/gpu/effects/GrBicubicEffect.h ('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 #include "GrBicubicEffect.h" 1 #include "GrBicubicEffect.h"
2 2
3 #define DS(x) SkDoubleToScalar(x) 3 #define DS(x) SkDoubleToScalar(x)
4 4
5 const SkScalar GrBicubicEffect::gMitchellCoefficients[16] = { 5 const SkScalar GrBicubicEffect::gMitchellCoefficients[16] = {
6 DS( 1.0 / 18.0), DS(-9.0 / 18.0), DS( 15.0 / 18.0), DS( -7.0 / 18.0), 6 DS( 1.0 / 18.0), DS(-9.0 / 18.0), DS( 15.0 / 18.0), DS( -7.0 / 18.0),
7 DS(16.0 / 18.0), DS( 0.0 / 18.0), DS(-36.0 / 18.0), DS( 21.0 / 18.0), 7 DS(16.0 / 18.0), DS( 0.0 / 18.0), DS(-36.0 / 18.0), DS( 21.0 / 18.0),
8 DS( 1.0 / 18.0), DS( 9.0 / 18.0), DS( 27.0 / 18.0), DS(-21.0 / 18.0), 8 DS( 1.0 / 18.0), DS( 9.0 / 18.0), DS( 27.0 / 18.0), DS(-21.0 / 18.0),
9 DS( 0.0 / 18.0), DS( 0.0 / 18.0), DS( -6.0 / 18.0), DS( 7.0 / 18.0), 9 DS( 0.0 / 18.0), DS( 0.0 / 18.0), DS( -6.0 / 18.0), DS( 7.0 / 18.0),
10 }; 10 };
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 const GrDrawTargetCaps&, 170 const GrDrawTargetCaps&,
171 GrTexture* textures[]) { 171 GrTexture* textures[]) {
172 int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx : 172 int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx :
173 GrEffectUnitTest::kAlphaTextureIdx; 173 GrEffectUnitTest::kAlphaTextureIdx;
174 SkScalar coefficients[16]; 174 SkScalar coefficients[16];
175 for (int i = 0; i < 16; i++) { 175 for (int i = 0; i < 16; i++) {
176 coefficients[i] = random->nextSScalar1(); 176 coefficients[i] = random->nextSScalar1();
177 } 177 }
178 return GrBicubicEffect::Create(textures[texIdx], coefficients); 178 return GrBicubicEffect::Create(textures[texIdx], coefficients);
179 } 179 }
180
181 //////////////////////////////////////////////////////////////////////////////
182
183 bool GrBicubicEffect::ShouldUseBicubic(const SkMatrix& matrix,
184 GrTextureParams::FilterMode* filterMode) {
185 if (matrix.isIdentity()) {
186 *filterMode = GrTextureParams::kNone_FilterMode;
187 return false;
188 }
189
190 SkScalar scales[2];
191 if (!matrix.getMinMaxScales(scales) || scales[0] < SK_Scalar1) {
192 // Bicubic doesn't handle arbitrary minimization well, as src texels can be skipped
193 // entirely,
194 *filterMode = GrTextureParams::kMipMap_FilterMode;
195 return false;
196 }
197 // At this point if scales[1] == SK_Scalar1 then the matrix doesn't do any s caling.
198 if (scales[1] == SK_Scalar1) {
199 if (matrix.rectStaysRect() && SkScalarIsInt(matrix.getTranslateX()) &&
200 SkScalarIsInt(matrix.getTranslateY())) {
201 *filterMode = GrTextureParams::kNone_FilterMode;
202 } else {
203 // Use bilerp to handle rotation or fractional translation.
204 *filterMode = GrTextureParams::kBilerp_FilterMode;
205 }
206 return false;
207 }
208 // When we use the bicubic filtering effect each sample is read from the tex ture using
209 // nearest neighbor sampling.
210 *filterMode = GrTextureParams::kNone_FilterMode;
211 return true;
212 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrBicubicEffect.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698