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 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 GrEffectRef* SkBitmapProcShader::asNewEffect(GrContext* context, const SkPaint&
paint) const { | 357 GrEffectRef* SkBitmapProcShader::asNewEffect(GrContext* context, const SkPaint&
paint) const { |
358 SkMatrix matrix; | 358 SkMatrix matrix; |
359 matrix.setIDiv(fRawBitmap.width(), fRawBitmap.height()); | 359 matrix.setIDiv(fRawBitmap.width(), fRawBitmap.height()); |
360 | 360 |
361 if (this->hasLocalMatrix()) { | 361 SkMatrix inverse; |
362 SkMatrix inverse; | 362 if (!this->getLocalMatrix().invert(&inverse)) { |
363 if (!this->getLocalMatrix().invert(&inverse)) { | 363 return NULL; |
364 return NULL; | |
365 } | |
366 matrix.preConcat(inverse); | |
367 } | 364 } |
| 365 matrix.preConcat(inverse); |
| 366 |
368 SkShader::TileMode tm[] = { | 367 SkShader::TileMode tm[] = { |
369 (TileMode)fState.fTileModeX, | 368 (TileMode)fState.fTileModeX, |
370 (TileMode)fState.fTileModeY, | 369 (TileMode)fState.fTileModeY, |
371 }; | 370 }; |
372 | 371 |
373 // Must set wrap and filter on the sampler before requesting a texture. | 372 // Must set wrap and filter on the sampler before requesting a texture. |
374 SkPaint::FilterLevel paintFilterLevel = paint.getFilterLevel(); | 373 SkPaint::FilterLevel paintFilterLevel = paint.getFilterLevel(); |
375 GrTextureParams::FilterMode textureFilterMode; | 374 GrTextureParams::FilterMode textureFilterMode; |
376 switch(paintFilterLevel) { | 375 switch(paintFilterLevel) { |
377 case SkPaint::kNone_FilterLevel: | 376 case SkPaint::kNone_FilterLevel: |
378 textureFilterMode = GrTextureParams::kNone_FilterMode; | 377 textureFilterMode = GrTextureParams::kNone_FilterMode; |
379 break; | 378 break; |
380 case SkPaint::kLow_FilterLevel: | 379 case SkPaint::kLow_FilterLevel: |
381 textureFilterMode = GrTextureParams::kBilerp_FilterMode; | 380 textureFilterMode = GrTextureParams::kBilerp_FilterMode; |
382 break; | 381 break; |
383 case SkPaint::kMedium_FilterLevel: | 382 case SkPaint::kMedium_FilterLevel: |
384 textureFilterMode = GrTextureParams::kMipMap_FilterMode; | 383 textureFilterMode = GrTextureParams::kMipMap_FilterMode; |
385 break; | 384 break; |
386 case SkPaint::kHigh_FilterLevel: | 385 case SkPaint::kHigh_FilterLevel: |
387 // fall back to no filtering here; we will install another | 386 // Minification can look bad with the bicubic effect. This is an ove
rly aggressive |
388 // shader that will do the HQ filtering. | 387 // check for MIP fallbacks. It doesn't consider the fact that minifi
cation in the local |
389 textureFilterMode = GrTextureParams::kNone_FilterMode; | 388 // matrix could be offset by the view matrix and vice versa. We also
don't know whether |
| 389 // the draw has explicit local coords (e.g. drawVertices) where the
scale factor is |
| 390 // unknown and varies. |
| 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; |
| 396 } else { |
| 397 // Fall back to mip-mapping. |
| 398 paintFilterLevel = SkPaint::kMedium_FilterLevel; |
| 399 textureFilterMode = GrTextureParams::kMipMap_FilterMode; |
| 400 } |
390 break; | 401 break; |
391 default: | 402 default: |
392 SkErrorInternals::SetError( kInvalidPaint_SkError, | 403 SkErrorInternals::SetError( kInvalidPaint_SkError, |
393 "Sorry, I don't understand the filtering
" | 404 "Sorry, I don't understand the filtering
" |
394 "mode you asked for. Falling back to " | 405 "mode you asked for. Falling back to " |
395 "MIPMaps."); | 406 "MIPMaps."); |
396 textureFilterMode = GrTextureParams::kMipMap_FilterMode; | 407 textureFilterMode = GrTextureParams::kMipMap_FilterMode; |
397 break; | 408 break; |
398 | 409 |
399 } | 410 } |
400 GrTextureParams params(tm, textureFilterMode); | 411 GrTextureParams params(tm, textureFilterMode); |
401 GrTexture* texture = GrLockAndRefCachedBitmapTexture(context, fRawBitmap, &p
arams); | 412 GrTexture* texture = GrLockAndRefCachedBitmapTexture(context, fRawBitmap, &p
arams); |
402 | 413 |
403 if (NULL == texture) { | 414 if (NULL == texture) { |
404 SkErrorInternals::SetError( kInternalError_SkError, | 415 SkErrorInternals::SetError( kInternalError_SkError, |
405 "Couldn't convert bitmap to texture."); | 416 "Couldn't convert bitmap to texture."); |
406 return NULL; | 417 return NULL; |
407 } | 418 } |
408 | 419 |
409 GrEffectRef* effect = NULL; | 420 GrEffectRef* effect = NULL; |
410 if (paintFilterLevel == SkPaint::kHigh_FilterLevel) { | 421 if (paintFilterLevel == SkPaint::kHigh_FilterLevel) { |
411 effect = GrBicubicEffect::Create(texture, matrix, params); | 422 effect = GrBicubicEffect::Create(texture, matrix, params); |
412 } else { | 423 } else { |
413 effect = GrSimpleTextureEffect::Create(texture, matrix, params); | 424 effect = GrSimpleTextureEffect::Create(texture, matrix, params); |
414 } | 425 } |
415 GrUnlockAndUnrefCachedBitmapTexture(texture); | 426 GrUnlockAndUnrefCachedBitmapTexture(texture); |
416 return effect; | 427 return effect; |
417 } | 428 } |
418 #endif | 429 #endif |
OLD | NEW |