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

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

Issue 1845283003: Gamma-correctness pushed into Skia, top-down. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase Created 4 years, 8 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"
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 return SkXfermode::kDst_Mode != mode; 488 return SkXfermode::kDst_Mode != mode;
489 } 489 }
490 } 490 }
491 491
492 static inline bool skpaint_to_grpaint_impl(GrContext* context, 492 static inline bool skpaint_to_grpaint_impl(GrContext* context,
493 const SkPaint& skPaint, 493 const SkPaint& skPaint,
494 const SkMatrix& viewM, 494 const SkMatrix& viewM,
495 const GrFragmentProcessor** shaderPro cessor, 495 const GrFragmentProcessor** shaderPro cessor,
496 SkXfermode::Mode* primColorMode, 496 SkXfermode::Mode* primColorMode,
497 bool primitiveIsSrc, 497 bool primitiveIsSrc,
498 bool allowSRGBInputs,
498 GrPaint* grPaint) { 499 GrPaint* grPaint) {
499 grPaint->setAntiAlias(skPaint.isAntiAlias()); 500 grPaint->setAntiAlias(skPaint.isAntiAlias());
501 grPaint->setAllowSRGBInputs(allowSRGBInputs);
500 502
501 // Setup the initial color considering the shader, the SkPaint color, and th e presence or not 503 // Setup the initial color considering the shader, the SkPaint color, and th e presence or not
502 // of per-vertex colors. 504 // of per-vertex colors.
503 SkAutoTUnref<const GrFragmentProcessor> aufp; 505 SkAutoTUnref<const GrFragmentProcessor> aufp;
504 const GrFragmentProcessor* shaderFP = nullptr; 506 const GrFragmentProcessor* shaderFP = nullptr;
505 if (!primColorMode || blend_requires_shader(*primColorMode, primitiveIsSrc)) { 507 if (!primColorMode || blend_requires_shader(*primColorMode, primitiveIsSrc)) {
506 if (shaderProcessor) { 508 if (shaderProcessor) {
507 shaderFP = *shaderProcessor; 509 shaderFP = *shaderProcessor;
508 } else if (const SkShader* shader = skPaint.getShader()) { 510 } else if (const SkShader* shader = skPaint.getShader()) {
509 aufp.reset(shader->asFragmentProcessor(context, viewM, nullptr, 511 aufp.reset(shader->asFragmentProcessor(context, viewM, nullptr,
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 618
617 #ifndef SK_IGNORE_GPU_DITHER 619 #ifndef SK_IGNORE_GPU_DITHER
618 if (skPaint.isDither() && grPaint->numColorFragmentProcessors() > 0) { 620 if (skPaint.isDither() && grPaint->numColorFragmentProcessors() > 0) {
619 grPaint->addColorFragmentProcessor(GrDitherEffect::Create())->unref(); 621 grPaint->addColorFragmentProcessor(GrDitherEffect::Create())->unref();
620 } 622 }
621 #endif 623 #endif
622 return true; 624 return true;
623 } 625 }
624 626
625 bool SkPaintToGrPaint(GrContext* context, const SkPaint& skPaint, const SkMatrix & viewM, 627 bool SkPaintToGrPaint(GrContext* context, const SkPaint& skPaint, const SkMatrix & viewM,
626 GrPaint* grPaint) { 628 bool allowSRGBInputs, GrPaint* grPaint) {
627 return skpaint_to_grpaint_impl(context, skPaint, viewM, nullptr, nullptr, fa lse, grPaint); 629 return skpaint_to_grpaint_impl(context, skPaint, viewM, nullptr, nullptr, fa lse,
630 allowSRGBInputs, grPaint);
628 } 631 }
629 632
630 /** Replaces the SkShader (if any) on skPaint with the passed in GrFragmentProce ssor. */ 633 /** Replaces the SkShader (if any) on skPaint with the passed in GrFragmentProce ssor. */
631 bool SkPaintToGrPaintReplaceShader(GrContext* context, 634 bool SkPaintToGrPaintReplaceShader(GrContext* context,
632 const SkPaint& skPaint, 635 const SkPaint& skPaint,
633 const GrFragmentProcessor* shaderFP, 636 const GrFragmentProcessor* shaderFP,
637 bool allowSRGBInputs,
634 GrPaint* grPaint) { 638 GrPaint* grPaint) {
635 if (!shaderFP) { 639 if (!shaderFP) {
636 return false; 640 return false;
637 } 641 }
638 return skpaint_to_grpaint_impl(context, skPaint, SkMatrix::I(), &shaderFP, n ullptr, false, 642 return skpaint_to_grpaint_impl(context, skPaint, SkMatrix::I(), &shaderFP, n ullptr, false,
639 grPaint); 643 allowSRGBInputs, grPaint);
640 } 644 }
641 645
642 /** Ignores the SkShader (if any) on skPaint. */ 646 /** Ignores the SkShader (if any) on skPaint. */
643 bool SkPaintToGrPaintNoShader(GrContext* context, 647 bool SkPaintToGrPaintNoShader(GrContext* context,
644 const SkPaint& skPaint, 648 const SkPaint& skPaint,
649 bool allowSRGBInputs,
645 GrPaint* grPaint) { 650 GrPaint* grPaint) {
646 // Use a ptr to a nullptr to to indicate that the SkShader is ignored and no t replaced. 651 // Use a ptr to a nullptr to to indicate that the SkShader is ignored and no t replaced.
647 static const GrFragmentProcessor* kNullShaderFP = nullptr; 652 static const GrFragmentProcessor* kNullShaderFP = nullptr;
648 static const GrFragmentProcessor** kIgnoreShader = &kNullShaderFP; 653 static const GrFragmentProcessor** kIgnoreShader = &kNullShaderFP;
649 return skpaint_to_grpaint_impl(context, skPaint, SkMatrix::I(), kIgnoreShade r, nullptr, false, 654 return skpaint_to_grpaint_impl(context, skPaint, SkMatrix::I(), kIgnoreShade r, nullptr, false,
650 grPaint); 655 allowSRGBInputs, grPaint);
651 } 656 }
652 657
653 /** Blends the SkPaint's shader (or color if no shader) with a per-primitive col or which must 658 /** Blends the SkPaint's shader (or color if no shader) with a per-primitive col or which must
654 be setup as a vertex attribute using the specified SkXfermode::Mode. */ 659 be setup as a vertex attribute using the specified SkXfermode::Mode. */
655 bool SkPaintToGrPaintWithXfermode(GrContext* context, 660 bool SkPaintToGrPaintWithXfermode(GrContext* context,
656 const SkPaint& skPaint, 661 const SkPaint& skPaint,
657 const SkMatrix& viewM, 662 const SkMatrix& viewM,
658 SkXfermode::Mode primColorMode, 663 SkXfermode::Mode primColorMode,
659 bool primitiveIsSrc, 664 bool primitiveIsSrc,
665 bool allowSRGBInputs,
660 GrPaint* grPaint) { 666 GrPaint* grPaint) {
661 return skpaint_to_grpaint_impl(context, skPaint, viewM, nullptr, &primColorM ode, primitiveIsSrc, 667 return skpaint_to_grpaint_impl(context, skPaint, viewM, nullptr, &primColorM ode, primitiveIsSrc,
662 grPaint); 668 allowSRGBInputs, grPaint);
663 } 669 }
664 670
665 bool SkPaintToGrPaintWithTexture(GrContext* context, 671 bool SkPaintToGrPaintWithTexture(GrContext* context,
666 const SkPaint& paint, 672 const SkPaint& paint,
667 const SkMatrix& viewM, 673 const SkMatrix& viewM,
668 const GrFragmentProcessor* fp, 674 const GrFragmentProcessor* fp,
669 bool textureIsAlphaOnly, 675 bool textureIsAlphaOnly,
676 bool allowSRGBInputs,
670 GrPaint* grPaint) { 677 GrPaint* grPaint) {
671 SkAutoTUnref<const GrFragmentProcessor> shaderFP; 678 SkAutoTUnref<const GrFragmentProcessor> shaderFP;
672 if (textureIsAlphaOnly) { 679 if (textureIsAlphaOnly) {
673 if (const SkShader* shader = paint.getShader()) { 680 if (const SkShader* shader = paint.getShader()) {
674 shaderFP.reset(shader->asFragmentProcessor(context, 681 shaderFP.reset(shader->asFragmentProcessor(context,
675 viewM, 682 viewM,
676 nullptr, 683 nullptr,
677 paint.getFilterQuality()) ); 684 paint.getFilterQuality()) );
678 if (!shaderFP) { 685 if (!shaderFP) {
679 return false; 686 return false;
680 } 687 }
681 const GrFragmentProcessor* fpSeries[] = { shaderFP.get(), fp }; 688 const GrFragmentProcessor* fpSeries[] = { shaderFP.get(), fp };
682 shaderFP.reset(GrFragmentProcessor::RunInSeries(fpSeries, 2)); 689 shaderFP.reset(GrFragmentProcessor::RunInSeries(fpSeries, 2));
683 } else { 690 } else {
684 shaderFP.reset(GrFragmentProcessor::MulOutputByInputUnpremulColor(fp )); 691 shaderFP.reset(GrFragmentProcessor::MulOutputByInputUnpremulColor(fp ));
685 } 692 }
686 } else { 693 } else {
687 shaderFP.reset(GrFragmentProcessor::MulOutputByInputAlpha(fp)); 694 shaderFP.reset(GrFragmentProcessor::MulOutputByInputAlpha(fp));
688 } 695 }
689 696
690 return SkPaintToGrPaintReplaceShader(context, paint, shaderFP.get(), grPaint ); 697 return SkPaintToGrPaintReplaceShader(context, paint, shaderFP.get(), allowSR GBInputs, grPaint);
691 } 698 }
692 699
693 700
694 //////////////////////////////////////////////////////////////////////////////// //////////////// 701 //////////////////////////////////////////////////////////////////////////////// ////////////////
695 702
696 SkImageInfo GrMakeInfoFromTexture(GrTexture* tex, int w, int h, bool isOpaque) { 703 SkImageInfo GrMakeInfoFromTexture(GrTexture* tex, int w, int h, bool isOpaque) {
697 #ifdef SK_DEBUG 704 #ifdef SK_DEBUG
698 const GrSurfaceDesc& desc = tex->desc(); 705 const GrSurfaceDesc& desc = tex->desc();
699 SkASSERT(w <= desc.fWidth); 706 SkASSERT(w <= desc.fWidth);
700 SkASSERT(h <= desc.fHeight); 707 SkASSERT(h <= desc.fHeight);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 SkErrorInternals::SetError( kInvalidPaint_SkError, 756 SkErrorInternals::SetError( kInvalidPaint_SkError,
750 "Sorry, I don't understand the filtering " 757 "Sorry, I don't understand the filtering "
751 "mode you asked for. Falling back to " 758 "mode you asked for. Falling back to "
752 "MIPMaps."); 759 "MIPMaps.");
753 textureFilterMode = GrTextureParams::kMipMap_FilterMode; 760 textureFilterMode = GrTextureParams::kMipMap_FilterMode;
754 break; 761 break;
755 762
756 } 763 }
757 return textureFilterMode; 764 return textureFilterMode;
758 } 765 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698