OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 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 | 8 |
9 #include "SkGr.h" | 9 #include "SkGr.h" |
10 #include "SkGrPriv.h" | 10 #include "SkGrPriv.h" |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 explicit Invalidator(const GrUniqueKey& key) : fMsg(key) {} | 322 explicit Invalidator(const GrUniqueKey& key) : fMsg(key) {} |
323 private: | 323 private: |
324 GrUniqueKeyInvalidatedMessage fMsg; | 324 GrUniqueKeyInvalidatedMessage fMsg; |
325 | 325 |
326 void onChange() override { SkMessageBus<GrUniqueKeyInvalidatedMessage>::
Post(fMsg); } | 326 void onChange() override { SkMessageBus<GrUniqueKeyInvalidatedMessage>::
Post(fMsg); } |
327 }; | 327 }; |
328 | 328 |
329 pixelRef->addGenIDChangeListener(new Invalidator(key)); | 329 pixelRef->addGenIDChangeListener(new Invalidator(key)); |
330 } | 330 } |
331 | 331 |
332 GrTexture* GrGenerateMipMapsAndUploadToTexture(GrContext* ctx, const SkBitmap& b
itmap) | 332 GrTexture* GrGenerateMipMapsAndUploadToTexture(GrContext* ctx, const SkBitmap& b
itmap, |
| 333 SkSourceGammaTreatment gammaTreat
ment) |
333 { | 334 { |
334 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(bitmap.info(), *ctx->caps()); | 335 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(bitmap.info(), *ctx->caps()); |
335 if (kIndex_8_SkColorType != bitmap.colorType() && !bitmap.readyToDraw()) { | 336 if (kIndex_8_SkColorType != bitmap.colorType() && !bitmap.readyToDraw()) { |
336 GrTexture* texture = load_etc1_texture(ctx, bitmap, desc); | 337 GrTexture* texture = load_etc1_texture(ctx, bitmap, desc); |
337 if (texture) { | 338 if (texture) { |
338 return texture; | 339 return texture; |
339 } | 340 } |
340 } | 341 } |
341 | 342 |
342 sk_sp<GrTexture> texture(create_texture_from_yuv(ctx, bitmap, desc)); | 343 sk_sp<GrTexture> texture(create_texture_from_yuv(ctx, bitmap, desc)); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 | 397 |
397 GrTexture* GrUploadMipMapToTexture(GrContext* ctx, const SkImageInfo& info, | 398 GrTexture* GrUploadMipMapToTexture(GrContext* ctx, const SkImageInfo& info, |
398 const GrMipLevel* texels, int mipLevelCount)
{ | 399 const GrMipLevel* texels, int mipLevelCount)
{ |
399 const GrCaps* caps = ctx->caps(); | 400 const GrCaps* caps = ctx->caps(); |
400 return ctx->textureProvider()->createMipMappedTexture(GrImageInfoToSurfaceDe
sc(info, *caps), | 401 return ctx->textureProvider()->createMipMappedTexture(GrImageInfoToSurfaceDe
sc(info, *caps), |
401 SkBudgeted::kYes, texe
ls, | 402 SkBudgeted::kYes, texe
ls, |
402 mipLevelCount); | 403 mipLevelCount); |
403 } | 404 } |
404 | 405 |
405 GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, const SkBitmap& bitmap, | 406 GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, const SkBitmap& bitmap, |
406 const GrTextureParams& params) { | 407 const GrTextureParams& params, |
| 408 SkSourceGammaTreatment gammaTreatment) { |
407 if (bitmap.getTexture()) { | 409 if (bitmap.getTexture()) { |
408 return GrBitmapTextureAdjuster(&bitmap).refTextureSafeForParams(params,
nullptr); | 410 return GrBitmapTextureAdjuster(&bitmap).refTextureSafeForParams(params,
gammaTreatment, |
| 411 nullptr)
; |
409 } | 412 } |
410 return GrBitmapTextureMaker(ctx, bitmap).refTextureForParams(params); | 413 return GrBitmapTextureMaker(ctx, bitmap).refTextureForParams(params, gammaTr
eatment); |
411 } | 414 } |
412 | 415 |
413 /////////////////////////////////////////////////////////////////////////////// | 416 /////////////////////////////////////////////////////////////////////////////// |
414 | 417 |
415 // alphatype is ignore for now, but if GrPixelConfig is expanded to encompass | 418 // alphatype is ignore for now, but if GrPixelConfig is expanded to encompass |
416 // alpha info, that will be considered. | 419 // alpha info, that will be considered. |
417 GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType ct, SkAlphaType, SkColorProf
ileType pt, | 420 GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType ct, SkAlphaType, SkColorProf
ileType pt, |
418 const GrCaps& caps) { | 421 const GrCaps& caps) { |
419 // We intentionally ignore profile type for non-8888 formats. Anything we ca
n't support | 422 // We intentionally ignore profile type for non-8888 formats. Anything we ca
n't support |
420 // in hardware will be expanded to sRGB 8888 in GrUploadPixmapToTexture. | 423 // in hardware will be expanded to sRGB 8888 in GrUploadPixmapToTexture. |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 grPaint->setAllowSRGBInputs(allowSRGBInputs); | 515 grPaint->setAllowSRGBInputs(allowSRGBInputs); |
513 | 516 |
514 // Setup the initial color considering the shader, the SkPaint color, and th
e presence or not | 517 // Setup the initial color considering the shader, the SkPaint color, and th
e presence or not |
515 // of per-vertex colors. | 518 // of per-vertex colors. |
516 SkAutoTUnref<const GrFragmentProcessor> aufp; | 519 SkAutoTUnref<const GrFragmentProcessor> aufp; |
517 const GrFragmentProcessor* shaderFP = nullptr; | 520 const GrFragmentProcessor* shaderFP = nullptr; |
518 if (!primColorMode || blend_requires_shader(*primColorMode, primitiveIsSrc))
{ | 521 if (!primColorMode || blend_requires_shader(*primColorMode, primitiveIsSrc))
{ |
519 if (shaderProcessor) { | 522 if (shaderProcessor) { |
520 shaderFP = *shaderProcessor; | 523 shaderFP = *shaderProcessor; |
521 } else if (const SkShader* shader = skPaint.getShader()) { | 524 } else if (const SkShader* shader = skPaint.getShader()) { |
| 525 SkSourceGammaTreatment gammaTreatment = allowSRGBInputs |
| 526 ? SkSourceGammaTreatment::kRespect : SkSourceGammaTreatment::kIg
nore; |
522 aufp.reset(shader->asFragmentProcessor(context, viewM, nullptr, | 527 aufp.reset(shader->asFragmentProcessor(context, viewM, nullptr, |
523 skPaint.getFilterQuality())); | 528 skPaint.getFilterQuality(), g
ammaTreatment)); |
524 shaderFP = aufp; | 529 shaderFP = aufp; |
525 if (!shaderFP) { | 530 if (!shaderFP) { |
526 return false; | 531 return false; |
527 } | 532 } |
528 } | 533 } |
529 } | 534 } |
530 | 535 |
531 // Set this in below cases if the output of the shader/paint-color/paint-alp
ha/primXfermode is | 536 // Set this in below cases if the output of the shader/paint-color/paint-alp
ha/primXfermode is |
532 // a known constant value. In that case we can simply apply a color filter d
uring this | 537 // a known constant value. In that case we can simply apply a color filter d
uring this |
533 // conversion without converting the color filter to a GrFragmentProcessor. | 538 // conversion without converting the color filter to a GrFragmentProcessor. |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 bool SkPaintToGrPaintWithTexture(GrContext* context, | 687 bool SkPaintToGrPaintWithTexture(GrContext* context, |
683 const SkPaint& paint, | 688 const SkPaint& paint, |
684 const SkMatrix& viewM, | 689 const SkMatrix& viewM, |
685 const GrFragmentProcessor* fp, | 690 const GrFragmentProcessor* fp, |
686 bool textureIsAlphaOnly, | 691 bool textureIsAlphaOnly, |
687 bool allowSRGBInputs, | 692 bool allowSRGBInputs, |
688 GrPaint* grPaint) { | 693 GrPaint* grPaint) { |
689 SkAutoTUnref<const GrFragmentProcessor> shaderFP; | 694 SkAutoTUnref<const GrFragmentProcessor> shaderFP; |
690 if (textureIsAlphaOnly) { | 695 if (textureIsAlphaOnly) { |
691 if (const SkShader* shader = paint.getShader()) { | 696 if (const SkShader* shader = paint.getShader()) { |
| 697 SkSourceGammaTreatment gammaTreatment = allowSRGBInputs |
| 698 ? SkSourceGammaTreatment::kRespect : SkSourceGammaTreatment::kIg
nore; |
692 shaderFP.reset(shader->asFragmentProcessor(context, | 699 shaderFP.reset(shader->asFragmentProcessor(context, |
693 viewM, | 700 viewM, |
694 nullptr, | 701 nullptr, |
695 paint.getFilterQuality())
); | 702 paint.getFilterQuality(), |
| 703 gammaTreatment)); |
696 if (!shaderFP) { | 704 if (!shaderFP) { |
697 return false; | 705 return false; |
698 } | 706 } |
699 const GrFragmentProcessor* fpSeries[] = { shaderFP.get(), fp }; | 707 const GrFragmentProcessor* fpSeries[] = { shaderFP.get(), fp }; |
700 shaderFP.reset(GrFragmentProcessor::RunInSeries(fpSeries, 2)); | 708 shaderFP.reset(GrFragmentProcessor::RunInSeries(fpSeries, 2)); |
701 } else { | 709 } else { |
702 shaderFP.reset(GrFragmentProcessor::MulOutputByInputUnpremulColor(fp
)); | 710 shaderFP.reset(GrFragmentProcessor::MulOutputByInputUnpremulColor(fp
)); |
703 } | 711 } |
704 } else { | 712 } else { |
705 shaderFP.reset(GrFragmentProcessor::MulOutputByInputAlpha(fp)); | 713 shaderFP.reset(GrFragmentProcessor::MulOutputByInputAlpha(fp)); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
767 SkErrorInternals::SetError( kInvalidPaint_SkError, | 775 SkErrorInternals::SetError( kInvalidPaint_SkError, |
768 "Sorry, I don't understand the filtering
" | 776 "Sorry, I don't understand the filtering
" |
769 "mode you asked for. Falling back to " | 777 "mode you asked for. Falling back to " |
770 "MIPMaps."); | 778 "MIPMaps."); |
771 textureFilterMode = GrTextureParams::kMipMap_FilterMode; | 779 textureFilterMode = GrTextureParams::kMipMap_FilterMode; |
772 break; | 780 break; |
773 | 781 |
774 } | 782 } |
775 return textureFilterMode; | 783 return textureFilterMode; |
776 } | 784 } |
OLD | NEW |