Chromium Code Reviews| 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 10 matching lines...) Expand all Loading... | |
| 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 Loading... | |
| 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 extern bool gTreatSkColorAsSRGB; | |
|
bsalomon
2016/06/23 15:20:30
What's this?
| |
| 538 if (gTreatSkColorAsSRGB && allowSRGBInputs) { | |
| 539 origColor.fRGBA[0] = exact_srgb_to_linear(origColor.fRGBA[0]); | |
| 540 origColor.fRGBA[1] = exact_srgb_to_linear(origColor.fRGBA[1]); | |
| 541 origColor.fRGBA[2] = exact_srgb_to_linear(origColor.fRGBA[2]); | |
| 542 } | |
| 543 | |
| 532 // Setup the initial color considering the shader, the SkPaint color, and th e presence or not | 544 // Setup the initial color considering the shader, the SkPaint color, and th e presence or not |
| 533 // of per-vertex colors. | 545 // of per-vertex colors. |
| 534 sk_sp<GrFragmentProcessor> shaderFP; | 546 sk_sp<GrFragmentProcessor> shaderFP; |
| 535 if (!primColorMode || blend_requires_shader(*primColorMode, primitiveIsSrc)) { | 547 if (!primColorMode || blend_requires_shader(*primColorMode, primitiveIsSrc)) { |
| 536 if (shaderProcessor) { | 548 if (shaderProcessor) { |
| 537 shaderFP = *shaderProcessor; | 549 shaderFP = *shaderProcessor; |
| 538 } else if (const SkShader* shader = skPaint.getShader()) { | 550 } else if (const SkShader* shader = skPaint.getShader()) { |
| 539 SkSourceGammaTreatment gammaTreatment = allowSRGBInputs | 551 SkSourceGammaTreatment gammaTreatment = allowSRGBInputs |
| 540 ? SkSourceGammaTreatment::kRespect : SkSourceGammaTreatment::kIg nore; | 552 ? SkSourceGammaTreatment::kRespect : SkSourceGammaTreatment::kIg nore; |
| 541 shaderFP = shader->asFragmentProcessor(context, viewM, nullptr, | 553 shaderFP = shader->asFragmentProcessor(context, viewM, nullptr, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 552 bool applyColorFilterToPaintColor = false; | 564 bool applyColorFilterToPaintColor = false; |
| 553 if (shaderFP) { | 565 if (shaderFP) { |
| 554 if (primColorMode) { | 566 if (primColorMode) { |
| 555 // There is a blend between the primitive color and the shader color . The shader sees | 567 // 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 | 568 // 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. | 569 // the primitive color. The blended color is then modulated by the p aint's alpha. |
| 558 | 570 |
| 559 // The geometry processor will insert the primitive color to start t he color chain, so | 571 // The geometry processor will insert the primitive color to start t he color chain, so |
| 560 // the GrPaint color will be ignored. | 572 // the GrPaint color will be ignored. |
| 561 | 573 |
| 562 GrColor shaderInput = SkColorToOpaqueGrColor(skPaint.getColor()); | 574 GrColor shaderInput = origColor.opaque().toGrColor(); |
| 563 | 575 |
| 576 // SRGBTODO: Preserve 4f on this code path | |
| 564 shaderFP = GrFragmentProcessor::OverrideInput(shaderFP, shaderInput) ; | 577 shaderFP = GrFragmentProcessor::OverrideInput(shaderFP, shaderInput) ; |
| 565 if (primitiveIsSrc) { | 578 if (primitiveIsSrc) { |
| 566 shaderFP = GrXfermodeFragmentProcessor::MakeFromDstProcessor(std ::move(shaderFP), | 579 shaderFP = GrXfermodeFragmentProcessor::MakeFromDstProcessor(std ::move(shaderFP), |
| 567 *pr imColorMode); | 580 *pr imColorMode); |
| 568 } else { | 581 } else { |
| 569 shaderFP = GrXfermodeFragmentProcessor::MakeFromSrcProcessor(std ::move(shaderFP), | 582 shaderFP = GrXfermodeFragmentProcessor::MakeFromSrcProcessor(std ::move(shaderFP), |
| 570 *pr imColorMode); | 583 *pr imColorMode); |
| 571 } | 584 } |
| 572 // The above may return null if compose results in a pass through of the prim color. | 585 // The above may return null if compose results in a pass through of the prim color. |
| 573 if (shaderFP) { | 586 if (shaderFP) { |
| 574 grPaint->addColorFragmentProcessor(shaderFP); | 587 grPaint->addColorFragmentProcessor(shaderFP); |
| 575 } | 588 } |
| 576 | 589 |
| 590 // We can ignore origColor here - alpha is unchanged by gamma | |
| 577 GrColor paintAlpha = SkColorAlphaToGrColor(skPaint.getColor()); | 591 GrColor paintAlpha = SkColorAlphaToGrColor(skPaint.getColor()); |
| 578 if (GrColor_WHITE != paintAlpha) { | 592 if (GrColor_WHITE != paintAlpha) { |
| 579 grPaint->addColorFragmentProcessor(GrConstColorProcessor::Make( | 593 grPaint->addColorFragmentProcessor(GrConstColorProcessor::Make( |
| 580 paintAlpha, GrConstColorProcessor::kModulateRGBA_InputMode)) ; | 594 paintAlpha, GrConstColorProcessor::kModulateRGBA_InputMode)) ; |
| 581 } | 595 } |
| 582 } else { | 596 } else { |
| 583 // The shader's FP sees the paint unpremul color | 597 // The shader's FP sees the paint unpremul color |
| 584 grPaint->setColor(SkColorToUnpremulGrColor(skPaint.getColor())); | 598 grPaint->setColor4f(origColor); |
| 585 grPaint->addColorFragmentProcessor(std::move(shaderFP)); | 599 grPaint->addColorFragmentProcessor(std::move(shaderFP)); |
| 586 } | 600 } |
| 587 } else { | 601 } else { |
| 588 if (primColorMode) { | 602 if (primColorMode) { |
| 589 // There is a blend between the primitive color and the paint color. The blend considers | 603 // 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. | 604 // the opaque paint color. The paint's alpha is applied to the post- blended color. |
| 605 // SRGBTODO: Preserve 4f on this code path | |
| 591 sk_sp<GrFragmentProcessor> processor( | 606 sk_sp<GrFragmentProcessor> processor( |
| 592 GrConstColorProcessor::Make(SkColorToOpaqueGrColor(skPaint.getCo lor()), | 607 GrConstColorProcessor::Make(origColor.opaque().toGrColor(), |
| 593 GrConstColorProcessor::kIgnore_Inp utMode)); | 608 GrConstColorProcessor::kIgnore_Inp utMode)); |
| 594 if (primitiveIsSrc) { | 609 if (primitiveIsSrc) { |
| 595 processor = GrXfermodeFragmentProcessor::MakeFromDstProcessor(st d::move(processor), | 610 processor = GrXfermodeFragmentProcessor::MakeFromDstProcessor(st d::move(processor), |
| 596 *p rimColorMode); | 611 *p rimColorMode); |
| 597 } else { | 612 } else { |
| 598 processor = GrXfermodeFragmentProcessor::MakeFromSrcProcessor(st d::move(processor), | 613 processor = GrXfermodeFragmentProcessor::MakeFromSrcProcessor(st d::move(processor), |
| 599 *p rimColorMode); | 614 *p rimColorMode); |
| 600 } | 615 } |
| 601 if (processor) { | 616 if (processor) { |
| 602 grPaint->addColorFragmentProcessor(std::move(processor)); | 617 grPaint->addColorFragmentProcessor(std::move(processor)); |
| 603 } | 618 } |
| 604 | 619 |
| 605 grPaint->setColor(SkColorToOpaqueGrColor(skPaint.getColor())); | 620 grPaint->setColor4f(origColor.opaque()); |
| 606 | 621 |
| 622 // We can ignore origColor here - alpha is unchanged by gamma | |
| 607 GrColor paintAlpha = SkColorAlphaToGrColor(skPaint.getColor()); | 623 GrColor paintAlpha = SkColorAlphaToGrColor(skPaint.getColor()); |
| 608 if (GrColor_WHITE != paintAlpha) { | 624 if (GrColor_WHITE != paintAlpha) { |
| 609 grPaint->addColorFragmentProcessor(GrConstColorProcessor::Make( | 625 grPaint->addColorFragmentProcessor(GrConstColorProcessor::Make( |
| 610 paintAlpha, GrConstColorProcessor::kModulateRGBA_InputMode)) ; | 626 paintAlpha, GrConstColorProcessor::kModulateRGBA_InputMode)) ; |
| 611 } | 627 } |
| 612 } else { | 628 } else { |
| 613 // No shader, no primitive color. | 629 // No shader, no primitive color. |
| 614 grPaint->setColor(SkColorToPremulGrColor(skPaint.getColor())); | 630 grPaint->setColor4f(origColor.premul()); |
| 615 applyColorFilterToPaintColor = true; | 631 applyColorFilterToPaintColor = true; |
| 616 } | 632 } |
| 617 } | 633 } |
| 618 | 634 |
| 619 SkColorFilter* colorFilter = skPaint.getColorFilter(); | 635 SkColorFilter* colorFilter = skPaint.getColorFilter(); |
| 620 if (colorFilter) { | 636 if (colorFilter) { |
| 621 if (applyColorFilterToPaintColor) { | 637 if (applyColorFilterToPaintColor) { |
| 622 grPaint->setColor(SkColorToPremulGrColor(colorFilter->filterColor(sk Paint.getColor()))); | 638 grPaint->setColor4f(GrColor4f::FromSkColor4f( |
| 639 colorFilter->filterColor4f(origColor.toSkColor4f())).premul()); | |
| 623 } else { | 640 } else { |
| 624 sk_sp<GrFragmentProcessor> cfFP(colorFilter->asFragmentProcessor(con text)); | 641 sk_sp<GrFragmentProcessor> cfFP(colorFilter->asFragmentProcessor(con text)); |
| 625 if (cfFP) { | 642 if (cfFP) { |
| 626 grPaint->addColorFragmentProcessor(std::move(cfFP)); | 643 grPaint->addColorFragmentProcessor(std::move(cfFP)); |
| 627 } else { | 644 } else { |
| 628 return false; | 645 return false; |
| 629 } | 646 } |
| 630 } | 647 } |
| 631 } | 648 } |
| 632 | 649 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 782 SkErrorInternals::SetError( kInvalidPaint_SkError, | 799 SkErrorInternals::SetError( kInvalidPaint_SkError, |
| 783 "Sorry, I don't understand the filtering " | 800 "Sorry, I don't understand the filtering " |
| 784 "mode you asked for. Falling back to " | 801 "mode you asked for. Falling back to " |
| 785 "MIPMaps."); | 802 "MIPMaps."); |
| 786 textureFilterMode = GrTextureParams::kMipMap_FilterMode; | 803 textureFilterMode = GrTextureParams::kMipMap_FilterMode; |
| 787 break; | 804 break; |
| 788 | 805 |
| 789 } | 806 } |
| 790 return textureFilterMode; | 807 return textureFilterMode; |
| 791 } | 808 } |
| OLD | NEW |