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

Side by Side Diff: src/gpu/SkGr.cpp

Issue 2180503002: Add destination color space to AsFPArgs. Eliminates last XFORMTODO. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 5 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
« no previous file with comments | « src/gpu/SkGpuDevice_drawTexture.cpp ('k') | src/gpu/SkGrPriv.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 } 511 }
512 } 512 }
513 513
514 static inline bool skpaint_to_grpaint_impl(GrContext* context, 514 static inline bool skpaint_to_grpaint_impl(GrContext* context,
515 const SkPaint& skPaint, 515 const SkPaint& skPaint,
516 const SkMatrix& viewM, 516 const SkMatrix& viewM,
517 sk_sp<GrFragmentProcessor>* shaderPro cessor, 517 sk_sp<GrFragmentProcessor>* shaderPro cessor,
518 SkXfermode::Mode* primColorMode, 518 SkXfermode::Mode* primColorMode,
519 bool primitiveIsSrc, 519 bool primitiveIsSrc,
520 bool allowSRGBInputs, 520 bool allowSRGBInputs,
521 SkColorSpace* dstColorSpace,
521 GrPaint* grPaint) { 522 GrPaint* grPaint) {
522 grPaint->setAntiAlias(skPaint.isAntiAlias()); 523 grPaint->setAntiAlias(skPaint.isAntiAlias());
523 grPaint->setAllowSRGBInputs(allowSRGBInputs); 524 grPaint->setAllowSRGBInputs(allowSRGBInputs);
524 525
525 // Raw translation of the SkPaint color to our 4f format: 526 // Raw translation of the SkPaint color to our 4f format:
526 GrColor4f origColor = GrColor4f::FromGrColor(SkColorToUnpremulGrColor(skPain t.getColor())); 527 GrColor4f origColor = GrColor4f::FromGrColor(SkColorToUnpremulGrColor(skPain t.getColor()));
527 528
528 // Linearize, if the color is meant to be in sRGB gamma: 529 // Linearize, if the color is meant to be in sRGB gamma:
529 if (allowSRGBInputs) { 530 if (allowSRGBInputs) {
530 origColor.fRGBA[0] = exact_srgb_to_linear(origColor.fRGBA[0]); 531 origColor.fRGBA[0] = exact_srgb_to_linear(origColor.fRGBA[0]);
531 origColor.fRGBA[1] = exact_srgb_to_linear(origColor.fRGBA[1]); 532 origColor.fRGBA[1] = exact_srgb_to_linear(origColor.fRGBA[1]);
532 origColor.fRGBA[2] = exact_srgb_to_linear(origColor.fRGBA[2]); 533 origColor.fRGBA[2] = exact_srgb_to_linear(origColor.fRGBA[2]);
533 } 534 }
534 535
535 // Setup the initial color considering the shader, the SkPaint color, and th e presence or not 536 // Setup the initial color considering the shader, the SkPaint color, and th e presence or not
536 // of per-vertex colors. 537 // of per-vertex colors.
537 sk_sp<GrFragmentProcessor> shaderFP; 538 sk_sp<GrFragmentProcessor> shaderFP;
538 if (!primColorMode || blend_requires_shader(*primColorMode, primitiveIsSrc)) { 539 if (!primColorMode || blend_requires_shader(*primColorMode, primitiveIsSrc)) {
539 if (shaderProcessor) { 540 if (shaderProcessor) {
540 shaderFP = *shaderProcessor; 541 shaderFP = *shaderProcessor;
541 } else if (const SkShader* shader = skPaint.getShader()) { 542 } else if (const SkShader* shader = skPaint.getShader()) {
542 SkSourceGammaTreatment gammaTreatment = allowSRGBInputs 543 SkSourceGammaTreatment gammaTreatment = allowSRGBInputs
543 ? SkSourceGammaTreatment::kRespect : SkSourceGammaTreatment::kIg nore; 544 ? SkSourceGammaTreatment::kRespect : SkSourceGammaTreatment::kIg nore;
544 shaderFP = shader->asFragmentProcessor(SkShader::AsFPArgs(context, & viewM, nullptr, 545 shaderFP = shader->asFragmentProcessor(SkShader::AsFPArgs(context, & viewM, nullptr,
545 skPaint.ge tFilterQuality(), 546 skPaint.ge tFilterQuality(),
547 dstColorSp ace,
546 gammaTreat ment)); 548 gammaTreat ment));
547 if (!shaderFP) { 549 if (!shaderFP) {
548 return false; 550 return false;
549 } 551 }
550 } 552 }
551 } 553 }
552 554
553 // Set this in below cases if the output of the shader/paint-color/paint-alp ha/primXfermode is 555 // Set this in below cases if the output of the shader/paint-color/paint-alp ha/primXfermode is
554 // a known constant value. In that case we can simply apply a color filter d uring this 556 // a known constant value. In that case we can simply apply a color filter d uring this
555 // conversion without converting the color filter to a GrFragmentProcessor. 557 // conversion without converting the color filter to a GrFragmentProcessor.
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 651
650 #ifndef SK_IGNORE_GPU_DITHER 652 #ifndef SK_IGNORE_GPU_DITHER
651 if (skPaint.isDither() && grPaint->numColorFragmentProcessors() > 0 && !allo wSRGBInputs) { 653 if (skPaint.isDither() && grPaint->numColorFragmentProcessors() > 0 && !allo wSRGBInputs) {
652 grPaint->addColorFragmentProcessor(GrDitherEffect::Make()); 654 grPaint->addColorFragmentProcessor(GrDitherEffect::Make());
653 } 655 }
654 #endif 656 #endif
655 return true; 657 return true;
656 } 658 }
657 659
658 bool SkPaintToGrPaint(GrContext* context, const SkPaint& skPaint, const SkMatrix & viewM, 660 bool SkPaintToGrPaint(GrContext* context, const SkPaint& skPaint, const SkMatrix & viewM,
659 bool allowSRGBInputs, GrPaint* grPaint) { 661 bool allowSRGBInputs, SkColorSpace* dstColorSpace, GrPaint * grPaint) {
660 return skpaint_to_grpaint_impl(context, skPaint, viewM, nullptr, nullptr, fa lse, 662 return skpaint_to_grpaint_impl(context, skPaint, viewM, nullptr, nullptr, fa lse,
661 allowSRGBInputs, grPaint); 663 allowSRGBInputs, dstColorSpace, grPaint);
662 } 664 }
663 665
664 /** Replaces the SkShader (if any) on skPaint with the passed in GrFragmentProce ssor. */ 666 /** Replaces the SkShader (if any) on skPaint with the passed in GrFragmentProce ssor. */
665 bool SkPaintToGrPaintReplaceShader(GrContext* context, 667 bool SkPaintToGrPaintReplaceShader(GrContext* context,
666 const SkPaint& skPaint, 668 const SkPaint& skPaint,
667 sk_sp<GrFragmentProcessor> shaderFP, 669 sk_sp<GrFragmentProcessor> shaderFP,
668 bool allowSRGBInputs, 670 bool allowSRGBInputs,
671 SkColorSpace* dstColorSpace,
669 GrPaint* grPaint) { 672 GrPaint* grPaint) {
670 if (!shaderFP) { 673 if (!shaderFP) {
671 return false; 674 return false;
672 } 675 }
673 return skpaint_to_grpaint_impl(context, skPaint, SkMatrix::I(), &shaderFP, n ullptr, false, 676 return skpaint_to_grpaint_impl(context, skPaint, SkMatrix::I(), &shaderFP, n ullptr, false,
674 allowSRGBInputs, grPaint); 677 allowSRGBInputs, dstColorSpace, grPaint);
675 } 678 }
676 679
677 /** Ignores the SkShader (if any) on skPaint. */ 680 /** Ignores the SkShader (if any) on skPaint. */
678 bool SkPaintToGrPaintNoShader(GrContext* context, 681 bool SkPaintToGrPaintNoShader(GrContext* context,
679 const SkPaint& skPaint, 682 const SkPaint& skPaint,
680 bool allowSRGBInputs, 683 bool allowSRGBInputs,
684 SkColorSpace* dstColorSpace,
681 GrPaint* grPaint) { 685 GrPaint* grPaint) {
682 // Use a ptr to a nullptr to to indicate that the SkShader is ignored and no t replaced. 686 // Use a ptr to a nullptr to to indicate that the SkShader is ignored and no t replaced.
683 static sk_sp<GrFragmentProcessor> kNullShaderFP(nullptr); 687 static sk_sp<GrFragmentProcessor> kNullShaderFP(nullptr);
684 static sk_sp<GrFragmentProcessor>* kIgnoreShader = &kNullShaderFP; 688 static sk_sp<GrFragmentProcessor>* kIgnoreShader = &kNullShaderFP;
685 return skpaint_to_grpaint_impl(context, skPaint, SkMatrix::I(), kIgnoreShade r, nullptr, false, 689 return skpaint_to_grpaint_impl(context, skPaint, SkMatrix::I(), kIgnoreShade r, nullptr, false,
686 allowSRGBInputs, grPaint); 690 allowSRGBInputs, dstColorSpace, grPaint);
687 } 691 }
688 692
689 /** Blends the SkPaint's shader (or color if no shader) with a per-primitive col or which must 693 /** Blends the SkPaint's shader (or color if no shader) with a per-primitive col or which must
690 be setup as a vertex attribute using the specified SkXfermode::Mode. */ 694 be setup as a vertex attribute using the specified SkXfermode::Mode. */
691 bool SkPaintToGrPaintWithXfermode(GrContext* context, 695 bool SkPaintToGrPaintWithXfermode(GrContext* context,
692 const SkPaint& skPaint, 696 const SkPaint& skPaint,
693 const SkMatrix& viewM, 697 const SkMatrix& viewM,
694 SkXfermode::Mode primColorMode, 698 SkXfermode::Mode primColorMode,
695 bool primitiveIsSrc, 699 bool primitiveIsSrc,
696 bool allowSRGBInputs, 700 bool allowSRGBInputs,
701 SkColorSpace* dstColorSpace,
697 GrPaint* grPaint) { 702 GrPaint* grPaint) {
698 return skpaint_to_grpaint_impl(context, skPaint, viewM, nullptr, &primColorM ode, primitiveIsSrc, 703 return skpaint_to_grpaint_impl(context, skPaint, viewM, nullptr, &primColorM ode, primitiveIsSrc,
699 allowSRGBInputs, grPaint); 704 allowSRGBInputs, dstColorSpace, grPaint);
700 } 705 }
701 706
702 bool SkPaintToGrPaintWithTexture(GrContext* context, 707 bool SkPaintToGrPaintWithTexture(GrContext* context,
703 const SkPaint& paint, 708 const SkPaint& paint,
704 const SkMatrix& viewM, 709 const SkMatrix& viewM,
705 sk_sp<GrFragmentProcessor> fp, 710 sk_sp<GrFragmentProcessor> fp,
706 bool textureIsAlphaOnly, 711 bool textureIsAlphaOnly,
707 bool allowSRGBInputs, 712 bool allowSRGBInputs,
713 SkColorSpace* dstColorSpace,
708 GrPaint* grPaint) { 714 GrPaint* grPaint) {
709 sk_sp<GrFragmentProcessor> shaderFP; 715 sk_sp<GrFragmentProcessor> shaderFP;
710 if (textureIsAlphaOnly) { 716 if (textureIsAlphaOnly) {
711 if (const SkShader* shader = paint.getShader()) { 717 if (const SkShader* shader = paint.getShader()) {
712 SkSourceGammaTreatment gammaTreatment = allowSRGBInputs 718 SkSourceGammaTreatment gammaTreatment = allowSRGBInputs
713 ? SkSourceGammaTreatment::kRespect : SkSourceGammaTreatment::kIg nore; 719 ? SkSourceGammaTreatment::kRespect : SkSourceGammaTreatment::kIg nore;
714 shaderFP = shader->asFragmentProcessor(SkShader::AsFPArgs(context, 720 shaderFP = shader->asFragmentProcessor(SkShader::AsFPArgs(context,
715 &viewM, 721 &viewM,
716 nullptr, 722 nullptr,
717 paint.getF ilterQuality(), 723 paint.getF ilterQuality(),
724 dstColorSp ace,
718 gammaTreat ment)); 725 gammaTreat ment));
719 if (!shaderFP) { 726 if (!shaderFP) {
720 return false; 727 return false;
721 } 728 }
722 sk_sp<GrFragmentProcessor> fpSeries[] = { std::move(shaderFP), std:: move(fp) }; 729 sk_sp<GrFragmentProcessor> fpSeries[] = { std::move(shaderFP), std:: move(fp) };
723 shaderFP = GrFragmentProcessor::RunInSeries(fpSeries, 2); 730 shaderFP = GrFragmentProcessor::RunInSeries(fpSeries, 2);
724 } else { 731 } else {
725 shaderFP = GrFragmentProcessor::MulOutputByInputUnpremulColor(fp); 732 shaderFP = GrFragmentProcessor::MulOutputByInputUnpremulColor(fp);
726 } 733 }
727 } else { 734 } else {
728 shaderFP = GrFragmentProcessor::MulOutputByInputAlpha(fp); 735 shaderFP = GrFragmentProcessor::MulOutputByInputAlpha(fp);
729 } 736 }
730 737
731 return SkPaintToGrPaintReplaceShader(context, paint, std::move(shaderFP), al lowSRGBInputs, 738 return SkPaintToGrPaintReplaceShader(context, paint, std::move(shaderFP), al lowSRGBInputs,
732 grPaint); 739 dstColorSpace, grPaint);
733 } 740 }
734 741
735 742
736 //////////////////////////////////////////////////////////////////////////////// //////////////// 743 //////////////////////////////////////////////////////////////////////////////// ////////////////
737 744
738 GrTextureParams::FilterMode GrSkFilterQualityToGrFilterMode(SkFilterQuality pain tFilterQuality, 745 GrTextureParams::FilterMode GrSkFilterQualityToGrFilterMode(SkFilterQuality pain tFilterQuality,
739 const SkMatrix& view M, 746 const SkMatrix& view M,
740 const SkMatrix& loca lM, 747 const SkMatrix& loca lM,
741 bool* doBicubic) { 748 bool* doBicubic) {
742 *doBicubic = false; 749 *doBicubic = false;
(...skipping 26 matching lines...) Expand all
769 SkErrorInternals::SetError( kInvalidPaint_SkError, 776 SkErrorInternals::SetError( kInvalidPaint_SkError,
770 "Sorry, I don't understand the filtering " 777 "Sorry, I don't understand the filtering "
771 "mode you asked for. Falling back to " 778 "mode you asked for. Falling back to "
772 "MIPMaps."); 779 "MIPMaps.");
773 textureFilterMode = GrTextureParams::kMipMap_FilterMode; 780 textureFilterMode = GrTextureParams::kMipMap_FilterMode;
774 break; 781 break;
775 782
776 } 783 }
777 return textureFilterMode; 784 return textureFilterMode;
778 } 785 }
OLDNEW
« no previous file with comments | « src/gpu/SkGpuDevice_drawTexture.cpp ('k') | src/gpu/SkGrPriv.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698