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

Side by Side Diff: src/core/SkBitmapProcShader.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: add braces to case 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
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 "SkColorPriv.h" 8 #include "SkColorPriv.h"
9 #include "SkReadBuffer.h" 9 #include "SkReadBuffer.h"
10 #include "SkWriteBuffer.h" 10 #include "SkWriteBuffer.h"
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 #endif 375 #endif
376 376
377 /////////////////////////////////////////////////////////////////////////////// 377 ///////////////////////////////////////////////////////////////////////////////
378 378
379 #if SK_SUPPORT_GPU 379 #if SK_SUPPORT_GPU
380 380
381 #include "GrTextureAccess.h" 381 #include "GrTextureAccess.h"
382 #include "effects/GrSimpleTextureEffect.h" 382 #include "effects/GrSimpleTextureEffect.h"
383 #include "SkGr.h" 383 #include "SkGr.h"
384 384
385 // Note that this will return -1 if either matrix is perspective.
386 static SkScalar get_combined_min_stretch(const SkMatrix& viewMatrix, const SkMat rix& localMatrix) {
387 if (localMatrix.isIdentity()) {
388 return viewMatrix.getMinScale();
389 } else {
390 SkMatrix combined;
391 combined.setConcat(viewMatrix, localMatrix);
392 return combined.getMinScale();
393 }
394 }
395
396 GrEffectRef* SkBitmapProcShader::asNewEffect(GrContext* context, const SkPaint& paint, 385 GrEffectRef* SkBitmapProcShader::asNewEffect(GrContext* context, const SkPaint& paint,
397 const SkMatrix* localMatrix) const { 386 const SkMatrix* localMatrix) const {
398 SkMatrix matrix; 387 SkMatrix matrix;
399 matrix.setIDiv(fRawBitmap.width(), fRawBitmap.height()); 388 matrix.setIDiv(fRawBitmap.width(), fRawBitmap.height());
400 389
401 SkMatrix lmInverse; 390 SkMatrix lmInverse;
402 if (!this->getLocalMatrix().invert(&lmInverse)) { 391 if (!this->getLocalMatrix().invert(&lmInverse)) {
403 return NULL; 392 return NULL;
404 } 393 }
405 if (localMatrix) { 394 if (localMatrix) {
(...skipping 16 matching lines...) Expand all
422 // are provided by the caller. 411 // are provided by the caller.
423 SkPaint::FilterLevel paintFilterLevel = paint.getFilterLevel(); 412 SkPaint::FilterLevel paintFilterLevel = paint.getFilterLevel();
424 GrTextureParams::FilterMode textureFilterMode; 413 GrTextureParams::FilterMode textureFilterMode;
425 switch(paintFilterLevel) { 414 switch(paintFilterLevel) {
426 case SkPaint::kNone_FilterLevel: 415 case SkPaint::kNone_FilterLevel:
427 textureFilterMode = GrTextureParams::kNone_FilterMode; 416 textureFilterMode = GrTextureParams::kNone_FilterMode;
428 break; 417 break;
429 case SkPaint::kLow_FilterLevel: 418 case SkPaint::kLow_FilterLevel:
430 textureFilterMode = GrTextureParams::kBilerp_FilterMode; 419 textureFilterMode = GrTextureParams::kBilerp_FilterMode;
431 break; 420 break;
432 case SkPaint::kMedium_FilterLevel: 421 case SkPaint::kMedium_FilterLevel: {
433 if (get_combined_min_stretch(context->getMatrix(), this->getLocalMat rix()) < 422 SkMatrix matrix;
434 SK_Scalar1) { 423 matrix.setConcat(context->getMatrix(), this->getLocalMatrix());
424 if (matrix.getMinScale() < SK_Scalar1) {
435 textureFilterMode = GrTextureParams::kMipMap_FilterMode; 425 textureFilterMode = GrTextureParams::kMipMap_FilterMode;
436 } else { 426 } else {
437 // Don't trigger MIP level generation unnecessarily. 427 // Don't trigger MIP level generation unnecessarily.
438 textureFilterMode = GrTextureParams::kBilerp_FilterMode; 428 textureFilterMode = GrTextureParams::kBilerp_FilterMode;
439 } 429 }
440 break; 430 break;
robertphillips 2014/05/20 15:34:50 Indent on this '}'?
bsalomon 2014/05/20 16:13:06 Done.
441 case SkPaint::kHigh_FilterLevel: 431 }
442 // Minification can look bad with bicubic filtering. 432 case SkPaint::kHigh_FilterLevel: {
443 if (get_combined_min_stretch(context->getMatrix(), this->getLocalMat rix()) >= 433 SkMatrix matrix;
444 SK_Scalar1) { 434 matrix.setConcat(context->getMatrix(), this->getLocalMatrix());
445 // fall back to no filtering here; we will install another shade r that will do the 435 GrBicubicEffect::ShouldUseBicubic(matrix, &textureFilterMode);
446 // HQ filtering. 436 if (GrTextureParams::kNone_FilterMode == textureFilterMode) {
robertphillips 2014/05/20 15:34:50 Why not textureFilterMode ?
bsalomon 2014/05/20 16:13:06 It is now always set by ShouldUseBicubic.
447 textureFilterMode = GrTextureParams::kNone_FilterMode; 437 paintFilterLevel = SkPaint::kNone_FilterLevel;
448 } else { 438 } else if (GrTextureParams::kBilerp_FilterMode == textureFilterMode) {
449 // Fall back to MIP-mapping. 439 paintFilterLevel = SkPaint::kLow_FilterLevel;
440 } else if (GrTextureParams::kMipMap_FilterMode == textureFilterMode) {
450 paintFilterLevel = SkPaint::kMedium_FilterLevel; 441 paintFilterLevel = SkPaint::kMedium_FilterLevel;
451 textureFilterMode = GrTextureParams::kMipMap_FilterMode;
452 } 442 }
453 break; 443 break;
444 }
454 default: 445 default:
455 SkErrorInternals::SetError( kInvalidPaint_SkError, 446 SkErrorInternals::SetError( kInvalidPaint_SkError,
456 "Sorry, I don't understand the filtering " 447 "Sorry, I don't understand the filtering "
457 "mode you asked for. Falling back to " 448 "mode you asked for. Falling back to "
458 "MIPMaps."); 449 "MIPMaps.");
459 textureFilterMode = GrTextureParams::kMipMap_FilterMode; 450 textureFilterMode = GrTextureParams::kMipMap_FilterMode;
460 break; 451 break;
461 452
462 } 453 }
463 GrTextureParams params(tm, textureFilterMode); 454 GrTextureParams params(tm, textureFilterMode);
464 GrTexture* texture = GrLockAndRefCachedBitmapTexture(context, fRawBitmap, &p arams); 455 GrTexture* texture = GrLockAndRefCachedBitmapTexture(context, fRawBitmap, &p arams);
465 456
466 if (NULL == texture) { 457 if (NULL == texture) {
467 SkErrorInternals::SetError( kInternalError_SkError, 458 SkErrorInternals::SetError( kInternalError_SkError,
468 "Couldn't convert bitmap to texture."); 459 "Couldn't convert bitmap to texture.");
469 return NULL; 460 return NULL;
470 } 461 }
471 462
472 GrEffectRef* effect = NULL; 463 GrEffectRef* effect = NULL;
473 if (paintFilterLevel == SkPaint::kHigh_FilterLevel) { 464 if (paintFilterLevel == SkPaint::kHigh_FilterLevel) {
474 effect = GrBicubicEffect::Create(texture, matrix, tm); 465 effect = GrBicubicEffect::Create(texture, matrix, tm);
475 } else { 466 } else {
476 effect = GrSimpleTextureEffect::Create(texture, matrix, params); 467 effect = GrSimpleTextureEffect::Create(texture, matrix, params);
477 } 468 }
478 GrUnlockAndUnrefCachedBitmapTexture(texture); 469 GrUnlockAndUnrefCachedBitmapTexture(texture);
479 return effect; 470 return effect;
480 } 471 }
481 #endif 472 #endif
OLDNEW
« no previous file with comments | « include/core/SkMatrix.h ('k') | src/gpu/SkGpuDevice.cpp » ('j') | src/gpu/SkGpuDevice.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698