OLD | NEW |
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 "SkBitmapProcShader.h" | 8 #include "SkBitmapProcShader.h" |
9 #include "SkBitmapProcState.h" | 9 #include "SkBitmapProcState.h" |
10 #include "SkBitmapProvider.h" | 10 #include "SkBitmapProvider.h" |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 #endif | 411 #endif |
412 | 412 |
413 /////////////////////////////////////////////////////////////////////////////// | 413 /////////////////////////////////////////////////////////////////////////////// |
414 | 414 |
415 #if SK_SUPPORT_GPU | 415 #if SK_SUPPORT_GPU |
416 | 416 |
417 #include "GrTextureAccess.h" | 417 #include "GrTextureAccess.h" |
418 #include "SkGr.h" | 418 #include "SkGr.h" |
419 #include "effects/GrSimpleTextureEffect.h" | 419 #include "effects/GrSimpleTextureEffect.h" |
420 | 420 |
421 sk_sp<GrFragmentProcessor> SkBitmapProcShader::asFragmentProcessor(GrContext* co
ntext, | 421 sk_sp<GrFragmentProcessor> SkBitmapProcShader::asFragmentProcessor(const AsFPArg
s& args) const { |
422 const SkMatrix& viewM, const SkMatr
ix* localMatrix, | |
423 SkFilterQuality filterQuality, | |
424 SkSourceGammaTreatment gammaTreatme
nt) const { | |
425 SkMatrix matrix; | 422 SkMatrix matrix; |
426 matrix.setIDiv(fRawBitmap.width(), fRawBitmap.height()); | 423 matrix.setIDiv(fRawBitmap.width(), fRawBitmap.height()); |
427 | 424 |
428 SkMatrix lmInverse; | 425 SkMatrix lmInverse; |
429 if (!this->getLocalMatrix().invert(&lmInverse)) { | 426 if (!this->getLocalMatrix().invert(&lmInverse)) { |
430 return nullptr; | 427 return nullptr; |
431 } | 428 } |
432 if (localMatrix) { | 429 if (args.fLocalMatrix) { |
433 SkMatrix inv; | 430 SkMatrix inv; |
434 if (!localMatrix->invert(&inv)) { | 431 if (!args.fLocalMatrix->invert(&inv)) { |
435 return nullptr; | 432 return nullptr; |
436 } | 433 } |
437 lmInverse.postConcat(inv); | 434 lmInverse.postConcat(inv); |
438 } | 435 } |
439 matrix.preConcat(lmInverse); | 436 matrix.preConcat(lmInverse); |
440 | 437 |
441 SkShader::TileMode tm[] = { | 438 SkShader::TileMode tm[] = { |
442 (TileMode)fTileModeX, | 439 (TileMode)fTileModeX, |
443 (TileMode)fTileModeY, | 440 (TileMode)fTileModeY, |
444 }; | 441 }; |
445 | 442 |
446 // Must set wrap and filter on the sampler before requesting a texture. In t
wo places below | 443 // Must set wrap and filter on the sampler before requesting a texture. In t
wo places below |
447 // we check the matrix scale factors to determine how to interpret the filte
r quality setting. | 444 // we check the matrix scale factors to determine how to interpret the filte
r quality setting. |
448 // This completely ignores the complexity of the drawVertices case where exp
licit local coords | 445 // This completely ignores the complexity of the drawVertices case where exp
licit local coords |
449 // are provided by the caller. | 446 // are provided by the caller. |
450 bool doBicubic; | 447 bool doBicubic; |
451 GrTextureParams::FilterMode textureFilterMode = | 448 GrTextureParams::FilterMode textureFilterMode = |
452 GrSkFilterQualityToGrFilterMode(filterQuality, viewM, this->getLocal
Matrix(), | 449 GrSkFilterQualityToGrFilterMode(args.fFilterQuality, *args.fViewMatr
ix, |
453 &doBicubic); | 450 this->getLocalMatrix(), &doBicubic); |
454 GrTextureParams params(tm, textureFilterMode); | 451 GrTextureParams params(tm, textureFilterMode); |
455 SkAutoTUnref<GrTexture> texture(GrRefCachedBitmapTexture(context, fRawBitmap
, params, | 452 SkAutoTUnref<GrTexture> texture(GrRefCachedBitmapTexture(args.fContext, fRaw
Bitmap, params, |
456 gammaTreatment)); | 453 args.fGammaTreatmen
t)); |
457 | 454 |
458 if (!texture) { | 455 if (!texture) { |
459 SkErrorInternals::SetError( kInternalError_SkError, | 456 SkErrorInternals::SetError( kInternalError_SkError, |
460 "Couldn't convert bitmap to texture."); | 457 "Couldn't convert bitmap to texture."); |
461 return nullptr; | 458 return nullptr; |
462 } | 459 } |
463 SkColorSpace* dstColorSpace = nullptr; // XFORMTODO | 460 SkColorSpace* dstColorSpace = nullptr; // XFORMTODO |
464 sk_sp<GrColorSpaceXform> colorSpaceXform = GrColorSpaceXform::Make(fRawBitma
p.colorSpace(), | 461 sk_sp<GrColorSpaceXform> colorSpaceXform = GrColorSpaceXform::Make(fRawBitma
p.colorSpace(), |
465 dstColorS
pace); | 462 dstColorS
pace); |
466 sk_sp<GrFragmentProcessor> inner; | 463 sk_sp<GrFragmentProcessor> inner; |
467 if (doBicubic) { | 464 if (doBicubic) { |
468 inner = GrBicubicEffect::Make(texture, std::move(colorSpaceXform), matri
x, tm); | 465 inner = GrBicubicEffect::Make(texture, std::move(colorSpaceXform), matri
x, tm); |
469 } else { | 466 } else { |
470 inner = GrSimpleTextureEffect::Make(texture, std::move(colorSpaceXform),
matrix, params); | 467 inner = GrSimpleTextureEffect::Make(texture, std::move(colorSpaceXform),
matrix, params); |
471 } | 468 } |
472 | 469 |
473 if (kAlpha_8_SkColorType == fRawBitmap.colorType()) { | 470 if (kAlpha_8_SkColorType == fRawBitmap.colorType()) { |
474 return GrFragmentProcessor::MulOutputByInputUnpremulColor(std::move(inne
r)); | 471 return GrFragmentProcessor::MulOutputByInputUnpremulColor(std::move(inne
r)); |
475 } | 472 } |
476 return GrFragmentProcessor::MulOutputByInputAlpha(std::move(inner)); | 473 return GrFragmentProcessor::MulOutputByInputAlpha(std::move(inner)); |
477 } | 474 } |
478 | 475 |
479 #endif | 476 #endif |
OLD | NEW |