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

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

Issue 2088303002: Add GrColor4f type, store that in GrPaint. Linearize based on global flag. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix conversion to SkColor4f with new channel order 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/GrPaint.cpp ('k') | no next file » | 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 10 matching lines...) Expand all
21 21
22 #include "SkColorFilter.h" 22 #include "SkColorFilter.h"
23 #include "SkConfig8888.h" 23 #include "SkConfig8888.h"
24 #include "SkCanvas.h" 24 #include "SkCanvas.h"
25 #include "SkData.h" 25 #include "SkData.h"
26 #include "SkErrorInternals.h" 26 #include "SkErrorInternals.h"
27 #include "SkGrPixelRef.h" 27 #include "SkGrPixelRef.h"
28 #include "SkMessageBus.h" 28 #include "SkMessageBus.h"
29 #include "SkMipMap.h" 29 #include "SkMipMap.h"
30 #include "SkPixelRef.h" 30 #include "SkPixelRef.h"
31 #include "SkPM4fPriv.h"
31 #include "SkResourceCache.h" 32 #include "SkResourceCache.h"
32 #include "SkTemplates.h" 33 #include "SkTemplates.h"
33 #include "SkYUVPlanesCache.h" 34 #include "SkYUVPlanesCache.h"
34 #include "effects/GrBicubicEffect.h" 35 #include "effects/GrBicubicEffect.h"
35 #include "effects/GrConstColorProcessor.h" 36 #include "effects/GrConstColorProcessor.h"
36 #include "effects/GrDitherEffect.h" 37 #include "effects/GrDitherEffect.h"
37 #include "effects/GrPorterDuffXferProcessor.h" 38 #include "effects/GrPorterDuffXferProcessor.h"
38 #include "effects/GrXfermodeFragmentProcessor.h" 39 #include "effects/GrXfermodeFragmentProcessor.h"
39 #include "effects/GrYUVEffect.h" 40 #include "effects/GrYUVEffect.h"
40 41
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 const SkPaint& skPaint, 523 const SkPaint& skPaint,
523 const SkMatrix& viewM, 524 const SkMatrix& viewM,
524 sk_sp<GrFragmentProcessor>* shaderPro cessor, 525 sk_sp<GrFragmentProcessor>* shaderPro cessor,
525 SkXfermode::Mode* primColorMode, 526 SkXfermode::Mode* primColorMode,
526 bool primitiveIsSrc, 527 bool primitiveIsSrc,
527 bool allowSRGBInputs, 528 bool allowSRGBInputs,
528 GrPaint* grPaint) { 529 GrPaint* grPaint) {
529 grPaint->setAntiAlias(skPaint.isAntiAlias()); 530 grPaint->setAntiAlias(skPaint.isAntiAlias());
530 grPaint->setAllowSRGBInputs(allowSRGBInputs); 531 grPaint->setAllowSRGBInputs(allowSRGBInputs);
531 532
533 // Raw translation of the SkPaint color to our 4f format:
534 GrColor4f origColor = GrColor4f::FromGrColor(SkColorToUnpremulGrColor(skPain t.getColor()));
535
536 // Linearize, if the color is meant to be in sRGB gamma:
537 if (allowSRGBInputs) {
538 origColor.fRGBA[0] = exact_srgb_to_linear(origColor.fRGBA[0]);
539 origColor.fRGBA[1] = exact_srgb_to_linear(origColor.fRGBA[1]);
540 origColor.fRGBA[2] = exact_srgb_to_linear(origColor.fRGBA[2]);
541 }
542
532 // Setup the initial color considering the shader, the SkPaint color, and th e presence or not 543 // Setup the initial color considering the shader, the SkPaint color, and th e presence or not
533 // of per-vertex colors. 544 // of per-vertex colors.
534 sk_sp<GrFragmentProcessor> shaderFP; 545 sk_sp<GrFragmentProcessor> shaderFP;
535 if (!primColorMode || blend_requires_shader(*primColorMode, primitiveIsSrc)) { 546 if (!primColorMode || blend_requires_shader(*primColorMode, primitiveIsSrc)) {
536 if (shaderProcessor) { 547 if (shaderProcessor) {
537 shaderFP = *shaderProcessor; 548 shaderFP = *shaderProcessor;
538 } else if (const SkShader* shader = skPaint.getShader()) { 549 } else if (const SkShader* shader = skPaint.getShader()) {
539 SkSourceGammaTreatment gammaTreatment = allowSRGBInputs 550 SkSourceGammaTreatment gammaTreatment = allowSRGBInputs
540 ? SkSourceGammaTreatment::kRespect : SkSourceGammaTreatment::kIg nore; 551 ? SkSourceGammaTreatment::kRespect : SkSourceGammaTreatment::kIg nore;
541 shaderFP = shader->asFragmentProcessor(context, viewM, nullptr, 552 shaderFP = shader->asFragmentProcessor(context, viewM, nullptr,
(...skipping 10 matching lines...) Expand all
552 bool applyColorFilterToPaintColor = false; 563 bool applyColorFilterToPaintColor = false;
553 if (shaderFP) { 564 if (shaderFP) {
554 if (primColorMode) { 565 if (primColorMode) {
555 // There is a blend between the primitive color and the shader color . The shader sees 566 // There is a blend between the primitive color and the shader color . The shader sees
556 // the opaque paint color. The shader's output is blended using the provided mode by 567 // the opaque paint color. The shader's output is blended using the provided mode by
557 // the primitive color. The blended color is then modulated by the p aint's alpha. 568 // the primitive color. The blended color is then modulated by the p aint's alpha.
558 569
559 // The geometry processor will insert the primitive color to start t he color chain, so 570 // The geometry processor will insert the primitive color to start t he color chain, so
560 // the GrPaint color will be ignored. 571 // the GrPaint color will be ignored.
561 572
562 GrColor shaderInput = SkColorToOpaqueGrColor(skPaint.getColor()); 573 GrColor shaderInput = origColor.opaque().toGrColor();
563 574
575 // SRGBTODO: Preserve 4f on this code path
564 shaderFP = GrFragmentProcessor::OverrideInput(shaderFP, shaderInput) ; 576 shaderFP = GrFragmentProcessor::OverrideInput(shaderFP, shaderInput) ;
565 if (primitiveIsSrc) { 577 if (primitiveIsSrc) {
566 shaderFP = GrXfermodeFragmentProcessor::MakeFromDstProcessor(std ::move(shaderFP), 578 shaderFP = GrXfermodeFragmentProcessor::MakeFromDstProcessor(std ::move(shaderFP),
567 *pr imColorMode); 579 *pr imColorMode);
568 } else { 580 } else {
569 shaderFP = GrXfermodeFragmentProcessor::MakeFromSrcProcessor(std ::move(shaderFP), 581 shaderFP = GrXfermodeFragmentProcessor::MakeFromSrcProcessor(std ::move(shaderFP),
570 *pr imColorMode); 582 *pr imColorMode);
571 } 583 }
572 // The above may return null if compose results in a pass through of the prim color. 584 // The above may return null if compose results in a pass through of the prim color.
573 if (shaderFP) { 585 if (shaderFP) {
574 grPaint->addColorFragmentProcessor(shaderFP); 586 grPaint->addColorFragmentProcessor(shaderFP);
575 } 587 }
576 588
589 // We can ignore origColor here - alpha is unchanged by gamma
577 GrColor paintAlpha = SkColorAlphaToGrColor(skPaint.getColor()); 590 GrColor paintAlpha = SkColorAlphaToGrColor(skPaint.getColor());
578 if (GrColor_WHITE != paintAlpha) { 591 if (GrColor_WHITE != paintAlpha) {
579 grPaint->addColorFragmentProcessor(GrConstColorProcessor::Make( 592 grPaint->addColorFragmentProcessor(GrConstColorProcessor::Make(
580 paintAlpha, GrConstColorProcessor::kModulateRGBA_InputMode)) ; 593 paintAlpha, GrConstColorProcessor::kModulateRGBA_InputMode)) ;
581 } 594 }
582 } else { 595 } else {
583 // The shader's FP sees the paint unpremul color 596 // The shader's FP sees the paint unpremul color
584 grPaint->setColor(SkColorToUnpremulGrColor(skPaint.getColor())); 597 grPaint->setColor4f(origColor);
585 grPaint->addColorFragmentProcessor(std::move(shaderFP)); 598 grPaint->addColorFragmentProcessor(std::move(shaderFP));
586 } 599 }
587 } else { 600 } else {
588 if (primColorMode) { 601 if (primColorMode) {
589 // There is a blend between the primitive color and the paint color. The blend considers 602 // There is a blend between the primitive color and the paint color. The blend considers
590 // the opaque paint color. The paint's alpha is applied to the post- blended color. 603 // the opaque paint color. The paint's alpha is applied to the post- blended color.
604 // SRGBTODO: Preserve 4f on this code path
591 sk_sp<GrFragmentProcessor> processor( 605 sk_sp<GrFragmentProcessor> processor(
592 GrConstColorProcessor::Make(SkColorToOpaqueGrColor(skPaint.getCo lor()), 606 GrConstColorProcessor::Make(origColor.opaque().toGrColor(),
593 GrConstColorProcessor::kIgnore_Inp utMode)); 607 GrConstColorProcessor::kIgnore_Inp utMode));
594 if (primitiveIsSrc) { 608 if (primitiveIsSrc) {
595 processor = GrXfermodeFragmentProcessor::MakeFromDstProcessor(st d::move(processor), 609 processor = GrXfermodeFragmentProcessor::MakeFromDstProcessor(st d::move(processor),
596 *p rimColorMode); 610 *p rimColorMode);
597 } else { 611 } else {
598 processor = GrXfermodeFragmentProcessor::MakeFromSrcProcessor(st d::move(processor), 612 processor = GrXfermodeFragmentProcessor::MakeFromSrcProcessor(st d::move(processor),
599 *p rimColorMode); 613 *p rimColorMode);
600 } 614 }
601 if (processor) { 615 if (processor) {
602 grPaint->addColorFragmentProcessor(std::move(processor)); 616 grPaint->addColorFragmentProcessor(std::move(processor));
603 } 617 }
604 618
605 grPaint->setColor(SkColorToOpaqueGrColor(skPaint.getColor())); 619 grPaint->setColor4f(origColor.opaque());
606 620
621 // We can ignore origColor here - alpha is unchanged by gamma
607 GrColor paintAlpha = SkColorAlphaToGrColor(skPaint.getColor()); 622 GrColor paintAlpha = SkColorAlphaToGrColor(skPaint.getColor());
608 if (GrColor_WHITE != paintAlpha) { 623 if (GrColor_WHITE != paintAlpha) {
609 grPaint->addColorFragmentProcessor(GrConstColorProcessor::Make( 624 grPaint->addColorFragmentProcessor(GrConstColorProcessor::Make(
610 paintAlpha, GrConstColorProcessor::kModulateRGBA_InputMode)) ; 625 paintAlpha, GrConstColorProcessor::kModulateRGBA_InputMode)) ;
611 } 626 }
612 } else { 627 } else {
613 // No shader, no primitive color. 628 // No shader, no primitive color.
614 grPaint->setColor(SkColorToPremulGrColor(skPaint.getColor())); 629 grPaint->setColor4f(origColor.premul());
615 applyColorFilterToPaintColor = true; 630 applyColorFilterToPaintColor = true;
616 } 631 }
617 } 632 }
618 633
619 SkColorFilter* colorFilter = skPaint.getColorFilter(); 634 SkColorFilter* colorFilter = skPaint.getColorFilter();
620 if (colorFilter) { 635 if (colorFilter) {
621 if (applyColorFilterToPaintColor) { 636 if (applyColorFilterToPaintColor) {
622 grPaint->setColor(SkColorToPremulGrColor(colorFilter->filterColor(sk Paint.getColor()))); 637 grPaint->setColor4f(GrColor4f::FromSkColor4f(
638 colorFilter->filterColor4f(origColor.toSkColor4f())).premul());
623 } else { 639 } else {
624 sk_sp<GrFragmentProcessor> cfFP(colorFilter->asFragmentProcessor(con text)); 640 sk_sp<GrFragmentProcessor> cfFP(colorFilter->asFragmentProcessor(con text));
625 if (cfFP) { 641 if (cfFP) {
626 grPaint->addColorFragmentProcessor(std::move(cfFP)); 642 grPaint->addColorFragmentProcessor(std::move(cfFP));
627 } else { 643 } else {
628 return false; 644 return false;
629 } 645 }
630 } 646 }
631 } 647 }
632 648
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 SkErrorInternals::SetError( kInvalidPaint_SkError, 798 SkErrorInternals::SetError( kInvalidPaint_SkError,
783 "Sorry, I don't understand the filtering " 799 "Sorry, I don't understand the filtering "
784 "mode you asked for. Falling back to " 800 "mode you asked for. Falling back to "
785 "MIPMaps."); 801 "MIPMaps.");
786 textureFilterMode = GrTextureParams::kMipMap_FilterMode; 802 textureFilterMode = GrTextureParams::kMipMap_FilterMode;
787 break; 803 break;
788 804
789 } 805 }
790 return textureFilterMode; 806 return textureFilterMode;
791 } 807 }
OLDNEW
« no previous file with comments | « src/gpu/GrPaint.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698