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

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

Issue 2182603003: Just pass the draw context to paint conversion (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase Created 4 years, 4 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
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"
11 11
12 #include "GrCaps.h" 12 #include "GrCaps.h"
13 #include "GrContext.h" 13 #include "GrContext.h"
14 #include "GrDrawContext.h"
14 #include "GrGpuResourcePriv.h" 15 #include "GrGpuResourcePriv.h"
15 #include "GrImageIDTextureAdjuster.h" 16 #include "GrImageIDTextureAdjuster.h"
16 #include "GrTextureParamsAdjuster.h" 17 #include "GrTextureParamsAdjuster.h"
17 #include "GrTexturePriv.h" 18 #include "GrTexturePriv.h"
18 #include "GrTypes.h" 19 #include "GrTypes.h"
19 #include "GrXferProcessor.h" 20 #include "GrXferProcessor.h"
20 #include "GrYUVProvider.h" 21 #include "GrYUVProvider.h"
21 22
22 #include "SkColorFilter.h" 23 #include "SkColorFilter.h"
23 #include "SkConfig8888.h" 24 #include "SkConfig8888.h"
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 509
509 static inline bool blend_requires_shader(const SkXfermode::Mode mode, bool primi tiveIsSrc) { 510 static inline bool blend_requires_shader(const SkXfermode::Mode mode, bool primi tiveIsSrc) {
510 if (primitiveIsSrc) { 511 if (primitiveIsSrc) {
511 return SkXfermode::kSrc_Mode != mode; 512 return SkXfermode::kSrc_Mode != mode;
512 } else { 513 } else {
513 return SkXfermode::kDst_Mode != mode; 514 return SkXfermode::kDst_Mode != mode;
514 } 515 }
515 } 516 }
516 517
517 static inline bool skpaint_to_grpaint_impl(GrContext* context, 518 static inline bool skpaint_to_grpaint_impl(GrContext* context,
519 GrDrawContext* dc,
518 const SkPaint& skPaint, 520 const SkPaint& skPaint,
519 const SkMatrix& viewM, 521 const SkMatrix& viewM,
520 sk_sp<GrFragmentProcessor>* shaderPro cessor, 522 sk_sp<GrFragmentProcessor>* shaderPro cessor,
521 SkXfermode::Mode* primColorMode, 523 SkXfermode::Mode* primColorMode,
522 bool primitiveIsSrc, 524 bool primitiveIsSrc,
523 bool allowSRGBInputs,
524 SkColorSpace* dstColorSpace,
525 GrPaint* grPaint) { 525 GrPaint* grPaint) {
526 grPaint->setAntiAlias(skPaint.isAntiAlias()); 526 grPaint->setAntiAlias(skPaint.isAntiAlias());
527 grPaint->setAllowSRGBInputs(allowSRGBInputs); 527 grPaint->setAllowSRGBInputs(dc->isGammaCorrect());
528 528
529 // Raw translation of the SkPaint color to our 4f format: 529 // Raw translation of the SkPaint color to our 4f format:
530 GrColor4f origColor = GrColor4f::FromGrColor(SkColorToUnpremulGrColor(skPain t.getColor())); 530 GrColor4f origColor = GrColor4f::FromGrColor(SkColorToUnpremulGrColor(skPain t.getColor()));
531 531
532 // Linearize, if the color is meant to be in sRGB gamma: 532 // Linearize, if the color is meant to be in sRGB gamma:
533 if (allowSRGBInputs) { 533 if (dc->isGammaCorrect()) {
534 origColor.fRGBA[0] = exact_srgb_to_linear(origColor.fRGBA[0]); 534 origColor.fRGBA[0] = exact_srgb_to_linear(origColor.fRGBA[0]);
535 origColor.fRGBA[1] = exact_srgb_to_linear(origColor.fRGBA[1]); 535 origColor.fRGBA[1] = exact_srgb_to_linear(origColor.fRGBA[1]);
536 origColor.fRGBA[2] = exact_srgb_to_linear(origColor.fRGBA[2]); 536 origColor.fRGBA[2] = exact_srgb_to_linear(origColor.fRGBA[2]);
537 } 537 }
538 538
539 // Setup the initial color considering the shader, the SkPaint color, and th e presence or not 539 // Setup the initial color considering the shader, the SkPaint color, and th e presence or not
540 // of per-vertex colors. 540 // of per-vertex colors.
541 sk_sp<GrFragmentProcessor> shaderFP; 541 sk_sp<GrFragmentProcessor> shaderFP;
542 if (!primColorMode || blend_requires_shader(*primColorMode, primitiveIsSrc)) { 542 if (!primColorMode || blend_requires_shader(*primColorMode, primitiveIsSrc)) {
543 if (shaderProcessor) { 543 if (shaderProcessor) {
544 shaderFP = *shaderProcessor; 544 shaderFP = *shaderProcessor;
545 } else if (const SkShader* shader = skPaint.getShader()) { 545 } else if (const SkShader* shader = skPaint.getShader()) {
546 SkSourceGammaTreatment gammaTreatment = allowSRGBInputs
547 ? SkSourceGammaTreatment::kRespect : SkSourceGammaTreatment::kIg nore;
548 shaderFP = shader->asFragmentProcessor(SkShader::AsFPArgs(context, & viewM, nullptr, 546 shaderFP = shader->asFragmentProcessor(SkShader::AsFPArgs(context, & viewM, nullptr,
549 skPaint.ge tFilterQuality(), 547 skPaint.ge tFilterQuality(),
550 dstColorSp ace, 548 dc->getCol orSpace(),
551 gammaTreat ment)); 549 dc->source GammaTreatment()));
552 if (!shaderFP) { 550 if (!shaderFP) {
553 return false; 551 return false;
554 } 552 }
555 } 553 }
556 } 554 }
557 555
558 // Set this in below cases if the output of the shader/paint-color/paint-alp ha/primXfermode is 556 // Set this in below cases if the output of the shader/paint-color/paint-alp ha/primXfermode is
559 // a known constant value. In that case we can simply apply a color filter d uring this 557 // a known constant value. In that case we can simply apply a color filter d uring this
560 // conversion without converting the color filter to a GrFragmentProcessor. 558 // conversion without converting the color filter to a GrFragmentProcessor.
561 bool applyColorFilterToPaintColor = false; 559 bool applyColorFilterToPaintColor = false;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 644
647 // When the xfermode is null on the SkPaint (meaning kSrcOver) we need the X PFactory field on 645 // When the xfermode is null on the SkPaint (meaning kSrcOver) we need the X PFactory field on
648 // the GrPaint to also be null (also kSrcOver). 646 // the GrPaint to also be null (also kSrcOver).
649 SkASSERT(!grPaint->getXPFactory()); 647 SkASSERT(!grPaint->getXPFactory());
650 SkXfermode* xfermode = skPaint.getXfermode(); 648 SkXfermode* xfermode = skPaint.getXfermode();
651 if (xfermode) { 649 if (xfermode) {
652 grPaint->setXPFactory(xfermode->asXPFactory()); 650 grPaint->setXPFactory(xfermode->asXPFactory());
653 } 651 }
654 652
655 #ifndef SK_IGNORE_GPU_DITHER 653 #ifndef SK_IGNORE_GPU_DITHER
656 if (skPaint.isDither() && grPaint->numColorFragmentProcessors() > 0 && !allo wSRGBInputs) { 654 if (skPaint.isDither() && grPaint->numColorFragmentProcessors() > 0 && !dc-> isGammaCorrect()) {
657 grPaint->addColorFragmentProcessor(GrDitherEffect::Make()); 655 grPaint->addColorFragmentProcessor(GrDitherEffect::Make());
658 } 656 }
659 #endif 657 #endif
660 return true; 658 return true;
661 } 659 }
662 660
663 bool SkPaintToGrPaint(GrContext* context, const SkPaint& skPaint, const SkMatrix & viewM, 661 bool SkPaintToGrPaint(GrContext* context, GrDrawContext* dc, const SkPaint& skPa int,
664 bool allowSRGBInputs, SkColorSpace* dstColorSpace, GrPaint * grPaint) { 662 const SkMatrix& viewM, GrPaint* grPaint) {
665 return skpaint_to_grpaint_impl(context, skPaint, viewM, nullptr, nullptr, fa lse, 663 return skpaint_to_grpaint_impl(context, dc, skPaint, viewM, nullptr, nullptr , false, grPaint);
666 allowSRGBInputs, dstColorSpace, grPaint);
667 } 664 }
668 665
669 /** 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. */
670 bool SkPaintToGrPaintReplaceShader(GrContext* context, 667 bool SkPaintToGrPaintReplaceShader(GrContext* context,
668 GrDrawContext* dc,
671 const SkPaint& skPaint, 669 const SkPaint& skPaint,
672 sk_sp<GrFragmentProcessor> shaderFP, 670 sk_sp<GrFragmentProcessor> shaderFP,
673 bool allowSRGBInputs,
674 SkColorSpace* dstColorSpace,
675 GrPaint* grPaint) { 671 GrPaint* grPaint) {
676 if (!shaderFP) { 672 if (!shaderFP) {
677 return false; 673 return false;
678 } 674 }
679 return skpaint_to_grpaint_impl(context, skPaint, SkMatrix::I(), &shaderFP, n ullptr, false, 675 return skpaint_to_grpaint_impl(context, dc, skPaint, SkMatrix::I(), &shaderF P, nullptr, false,
680 allowSRGBInputs, dstColorSpace, grPaint); 676 grPaint);
681 } 677 }
682 678
683 /** Ignores the SkShader (if any) on skPaint. */ 679 /** Ignores the SkShader (if any) on skPaint. */
684 bool SkPaintToGrPaintNoShader(GrContext* context, 680 bool SkPaintToGrPaintNoShader(GrContext* context,
681 GrDrawContext* dc,
685 const SkPaint& skPaint, 682 const SkPaint& skPaint,
686 bool allowSRGBInputs,
687 SkColorSpace* dstColorSpace,
688 GrPaint* grPaint) { 683 GrPaint* grPaint) {
689 // Use a ptr to a nullptr to to indicate that the SkShader is ignored and no t replaced. 684 // Use a ptr to a nullptr to to indicate that the SkShader is ignored and no t replaced.
690 static sk_sp<GrFragmentProcessor> kNullShaderFP(nullptr); 685 static sk_sp<GrFragmentProcessor> kNullShaderFP(nullptr);
691 static sk_sp<GrFragmentProcessor>* kIgnoreShader = &kNullShaderFP; 686 static sk_sp<GrFragmentProcessor>* kIgnoreShader = &kNullShaderFP;
692 return skpaint_to_grpaint_impl(context, skPaint, SkMatrix::I(), kIgnoreShade r, nullptr, false, 687 return skpaint_to_grpaint_impl(context, dc, skPaint, SkMatrix::I(), kIgnoreS hader, nullptr,
693 allowSRGBInputs, dstColorSpace, grPaint); 688 false, grPaint);
694 } 689 }
695 690
696 /** Blends the SkPaint's shader (or color if no shader) with a per-primitive col or which must 691 /** Blends the SkPaint's shader (or color if no shader) with a per-primitive col or which must
697 be setup as a vertex attribute using the specified SkXfermode::Mode. */ 692 be setup as a vertex attribute using the specified SkXfermode::Mode. */
698 bool SkPaintToGrPaintWithXfermode(GrContext* context, 693 bool SkPaintToGrPaintWithXfermode(GrContext* context,
694 GrDrawContext* dc,
699 const SkPaint& skPaint, 695 const SkPaint& skPaint,
700 const SkMatrix& viewM, 696 const SkMatrix& viewM,
701 SkXfermode::Mode primColorMode, 697 SkXfermode::Mode primColorMode,
702 bool primitiveIsSrc, 698 bool primitiveIsSrc,
703 bool allowSRGBInputs,
704 SkColorSpace* dstColorSpace,
705 GrPaint* grPaint) { 699 GrPaint* grPaint) {
706 return skpaint_to_grpaint_impl(context, skPaint, viewM, nullptr, &primColorM ode, primitiveIsSrc, 700 return skpaint_to_grpaint_impl(context, dc, skPaint, viewM, nullptr, &primCo lorMode,
707 allowSRGBInputs, dstColorSpace, grPaint); 701 primitiveIsSrc, grPaint);
708 } 702 }
709 703
710 bool SkPaintToGrPaintWithTexture(GrContext* context, 704 bool SkPaintToGrPaintWithTexture(GrContext* context,
705 GrDrawContext* dc,
711 const SkPaint& paint, 706 const SkPaint& paint,
712 const SkMatrix& viewM, 707 const SkMatrix& viewM,
713 sk_sp<GrFragmentProcessor> fp, 708 sk_sp<GrFragmentProcessor> fp,
714 bool textureIsAlphaOnly, 709 bool textureIsAlphaOnly,
715 bool allowSRGBInputs,
716 SkColorSpace* dstColorSpace,
717 GrPaint* grPaint) { 710 GrPaint* grPaint) {
718 sk_sp<GrFragmentProcessor> shaderFP; 711 sk_sp<GrFragmentProcessor> shaderFP;
719 if (textureIsAlphaOnly) { 712 if (textureIsAlphaOnly) {
720 if (const SkShader* shader = paint.getShader()) { 713 if (const SkShader* shader = paint.getShader()) {
721 SkSourceGammaTreatment gammaTreatment = allowSRGBInputs
722 ? SkSourceGammaTreatment::kRespect : SkSourceGammaTreatment::kIg nore;
723 shaderFP = shader->asFragmentProcessor(SkShader::AsFPArgs(context, 714 shaderFP = shader->asFragmentProcessor(SkShader::AsFPArgs(context,
724 &viewM, 715 &viewM,
725 nullptr, 716 nullptr,
726 paint.getF ilterQuality(), 717 paint.getF ilterQuality(),
727 dstColorSp ace, 718 dc->getCol orSpace(),
728 gammaTreat ment)); 719 dc->source GammaTreatment()));
729 if (!shaderFP) { 720 if (!shaderFP) {
730 return false; 721 return false;
731 } 722 }
732 sk_sp<GrFragmentProcessor> fpSeries[] = { std::move(shaderFP), std:: move(fp) }; 723 sk_sp<GrFragmentProcessor> fpSeries[] = { std::move(shaderFP), std:: move(fp) };
733 shaderFP = GrFragmentProcessor::RunInSeries(fpSeries, 2); 724 shaderFP = GrFragmentProcessor::RunInSeries(fpSeries, 2);
734 } else { 725 } else {
735 shaderFP = GrFragmentProcessor::MulOutputByInputUnpremulColor(fp); 726 shaderFP = GrFragmentProcessor::MulOutputByInputUnpremulColor(fp);
736 } 727 }
737 } else { 728 } else {
738 shaderFP = GrFragmentProcessor::MulOutputByInputAlpha(fp); 729 shaderFP = GrFragmentProcessor::MulOutputByInputAlpha(fp);
739 } 730 }
740 731
741 return SkPaintToGrPaintReplaceShader(context, paint, std::move(shaderFP), al lowSRGBInputs, 732 return SkPaintToGrPaintReplaceShader(context, dc, paint, std::move(shaderFP) , grPaint);
742 dstColorSpace, grPaint);
743 } 733 }
744 734
745 735
746 //////////////////////////////////////////////////////////////////////////////// //////////////// 736 //////////////////////////////////////////////////////////////////////////////// ////////////////
747 737
748 GrTextureParams::FilterMode GrSkFilterQualityToGrFilterMode(SkFilterQuality pain tFilterQuality, 738 GrTextureParams::FilterMode GrSkFilterQualityToGrFilterMode(SkFilterQuality pain tFilterQuality,
749 const SkMatrix& view M, 739 const SkMatrix& view M,
750 const SkMatrix& loca lM, 740 const SkMatrix& loca lM,
751 bool* doBicubic) { 741 bool* doBicubic) {
752 *doBicubic = false; 742 *doBicubic = false;
(...skipping 26 matching lines...) Expand all
779 SkErrorInternals::SetError( kInvalidPaint_SkError, 769 SkErrorInternals::SetError( kInvalidPaint_SkError,
780 "Sorry, I don't understand the filtering " 770 "Sorry, I don't understand the filtering "
781 "mode you asked for. Falling back to " 771 "mode you asked for. Falling back to "
782 "MIPMaps."); 772 "MIPMaps.");
783 textureFilterMode = GrTextureParams::kMipMap_FilterMode; 773 textureFilterMode = GrTextureParams::kMipMap_FilterMode;
784 break; 774 break;
785 775
786 } 776 }
787 return textureFilterMode; 777 return textureFilterMode;
788 } 778 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698