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 "SkColorPriv.h" | 8 #include "SkColorPriv.h" |
9 #include "SkFlattenableBuffers.h" | 9 #include "SkFlattenableBuffers.h" |
10 #include "SkPixelRef.h" | 10 #include "SkPixelRef.h" |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
347 #endif | 347 #endif |
348 | 348 |
349 /////////////////////////////////////////////////////////////////////////////// | 349 /////////////////////////////////////////////////////////////////////////////// |
350 | 350 |
351 #if SK_SUPPORT_GPU | 351 #if SK_SUPPORT_GPU |
352 | 352 |
353 #include "GrTextureAccess.h" | 353 #include "GrTextureAccess.h" |
354 #include "effects/GrSimpleTextureEffect.h" | 354 #include "effects/GrSimpleTextureEffect.h" |
355 #include "SkGr.h" | 355 #include "SkGr.h" |
356 | 356 |
357 // Note that this will return -1 if either matrix is perspective. | |
358 static SkScalar get_combined_min_stretch(const SkMatrix& viewMatrix, const SkMat rix& localMatrix) { | |
359 if (localMatrix.isIdentity()) { | |
360 return viewMatrix.getMinStretch(); | |
reed1
2013/12/16 21:31:52
since we detect identity inside setConcat (for bot
| |
361 } else { | |
362 SkMatrix combined; | |
363 combined.setConcat(viewMatrix, localMatrix); | |
364 return combined.getMinStretch(); | |
365 } | |
366 } | |
367 | |
357 GrEffectRef* SkBitmapProcShader::asNewEffect(GrContext* context, const SkPaint& paint) const { | 368 GrEffectRef* SkBitmapProcShader::asNewEffect(GrContext* context, const SkPaint& paint) const { |
358 SkMatrix matrix; | 369 SkMatrix matrix; |
359 matrix.setIDiv(fRawBitmap.width(), fRawBitmap.height()); | 370 matrix.setIDiv(fRawBitmap.width(), fRawBitmap.height()); |
360 | 371 |
361 SkMatrix inverse; | 372 SkMatrix lmInverse; |
362 if (!this->getLocalMatrix().invert(&inverse)) { | 373 if (!this->getLocalMatrix().invert(&lmInverse)) { |
363 return NULL; | 374 return NULL; |
364 } | 375 } |
365 matrix.preConcat(inverse); | 376 matrix.preConcat(lmInverse); |
366 | 377 |
367 SkShader::TileMode tm[] = { | 378 SkShader::TileMode tm[] = { |
368 (TileMode)fState.fTileModeX, | 379 (TileMode)fState.fTileModeX, |
369 (TileMode)fState.fTileModeY, | 380 (TileMode)fState.fTileModeY, |
370 }; | 381 }; |
371 | 382 |
372 // Must set wrap and filter on the sampler before requesting a texture. | 383 // Must set wrap and filter on the sampler before requesting a texture. In t wo places below |
384 // we check the matrix scale factors to determine how to interpret the filte r quality setting. | |
385 // This completely ignores the complexity of the drawVertices case where exp licit local coords | |
386 // are provided by the caller. | |
373 SkPaint::FilterLevel paintFilterLevel = paint.getFilterLevel(); | 387 SkPaint::FilterLevel paintFilterLevel = paint.getFilterLevel(); |
374 GrTextureParams::FilterMode textureFilterMode; | 388 GrTextureParams::FilterMode textureFilterMode; |
375 switch(paintFilterLevel) { | 389 switch(paintFilterLevel) { |
376 case SkPaint::kNone_FilterLevel: | 390 case SkPaint::kNone_FilterLevel: |
377 textureFilterMode = GrTextureParams::kNone_FilterMode; | 391 textureFilterMode = GrTextureParams::kNone_FilterMode; |
378 break; | 392 break; |
379 case SkPaint::kLow_FilterLevel: | 393 case SkPaint::kLow_FilterLevel: |
380 textureFilterMode = GrTextureParams::kBilerp_FilterMode; | 394 textureFilterMode = GrTextureParams::kBilerp_FilterMode; |
381 break; | 395 break; |
382 case SkPaint::kMedium_FilterLevel: | 396 case SkPaint::kMedium_FilterLevel: |
383 textureFilterMode = GrTextureParams::kMipMap_FilterMode; | 397 if (get_combined_min_stretch(context->getMatrix(), this->getLocalMat rix()) < |
robertphillips
2013/12/16 20:41:12
Wouldn't the real test be if the tri-lerp factor w
bsalomon
2013/12/16 20:47:49
Do you mean allow some small amount of down-scalin
| |
398 SK_Scalar1) { | |
399 textureFilterMode = GrTextureParams::kMipMap_FilterMode; | |
400 } else { | |
401 // Don't trigger MIP level generation unnecessarily. | |
402 textureFilterMode = GrTextureParams::kBilerp_FilterMode; | |
403 } | |
384 break; | 404 break; |
385 case SkPaint::kHigh_FilterLevel: | 405 case SkPaint::kHigh_FilterLevel: |
386 // Minification can look bad with the bicubic effect. This is an ove rly aggressive | 406 // Minification can look bad with bicubic filtering. |
387 // check for MIP fallbacks. It doesn't consider the fact that minifi cation in the local | 407 if (get_combined_min_stretch(context->getMatrix(), this->getLocalMat rix()) >= |
388 // matrix could be offset by the view matrix and vice versa. We also don't know whether | 408 SK_Scalar1) { |
389 // the draw has explicit local coords (e.g. drawVertices) where the scale factor is | 409 // fall back to no filtering here; we will install another shade r that will do the |
390 // unknown and varies. | 410 // HQ filtering. |
391 if (context->getMatrix().getMinStretch() >= SK_Scalar1 && | |
392 this->getLocalMatrix().getMaxStretch() <= SK_Scalar1) { | |
393 // fall back to no filtering here; we will install another | |
394 // shader that will do the HQ filtering. | |
395 textureFilterMode = GrTextureParams::kNone_FilterMode; | 411 textureFilterMode = GrTextureParams::kNone_FilterMode; |
396 } else { | 412 } else { |
397 // Fall back to mip-mapping. | 413 // Fall back to MIP-mapping. |
398 paintFilterLevel = SkPaint::kMedium_FilterLevel; | 414 paintFilterLevel = SkPaint::kMedium_FilterLevel; |
399 textureFilterMode = GrTextureParams::kMipMap_FilterMode; | 415 textureFilterMode = GrTextureParams::kMipMap_FilterMode; |
400 } | 416 } |
401 break; | 417 break; |
402 default: | 418 default: |
403 SkErrorInternals::SetError( kInvalidPaint_SkError, | 419 SkErrorInternals::SetError( kInvalidPaint_SkError, |
404 "Sorry, I don't understand the filtering " | 420 "Sorry, I don't understand the filtering " |
405 "mode you asked for. Falling back to " | 421 "mode you asked for. Falling back to " |
406 "MIPMaps."); | 422 "MIPMaps."); |
407 textureFilterMode = GrTextureParams::kMipMap_FilterMode; | 423 textureFilterMode = GrTextureParams::kMipMap_FilterMode; |
(...skipping 12 matching lines...) Expand all Loading... | |
420 GrEffectRef* effect = NULL; | 436 GrEffectRef* effect = NULL; |
421 if (paintFilterLevel == SkPaint::kHigh_FilterLevel) { | 437 if (paintFilterLevel == SkPaint::kHigh_FilterLevel) { |
422 effect = GrBicubicEffect::Create(texture, matrix, tm); | 438 effect = GrBicubicEffect::Create(texture, matrix, tm); |
423 } else { | 439 } else { |
424 effect = GrSimpleTextureEffect::Create(texture, matrix, params); | 440 effect = GrSimpleTextureEffect::Create(texture, matrix, params); |
425 } | 441 } |
426 GrUnlockAndUnrefCachedBitmapTexture(texture); | 442 GrUnlockAndUnrefCachedBitmapTexture(texture); |
427 return effect; | 443 return effect; |
428 } | 444 } |
429 #endif | 445 #endif |
OLD | NEW |