| 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 | 10 |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 return SkXfermode::kDst_Mode != mode; | 422 return SkXfermode::kDst_Mode != mode; |
| 423 } | 423 } |
| 424 } | 424 } |
| 425 | 425 |
| 426 static inline bool skpaint_to_grpaint_impl(GrContext* context, | 426 static inline bool skpaint_to_grpaint_impl(GrContext* context, |
| 427 const SkPaint& skPaint, | 427 const SkPaint& skPaint, |
| 428 const SkMatrix& viewM, | 428 const SkMatrix& viewM, |
| 429 const GrFragmentProcessor** shaderPro
cessor, | 429 const GrFragmentProcessor** shaderPro
cessor, |
| 430 SkXfermode::Mode* primColorMode, | 430 SkXfermode::Mode* primColorMode, |
| 431 bool primitiveIsSrc, | 431 bool primitiveIsSrc, |
| 432 GrPaint* grPaint) { | 432 GrPaint* grPaint, |
| 433 GrRenderTarget* dstRT) { |
| 433 grPaint->setAntiAlias(skPaint.isAntiAlias()); | 434 grPaint->setAntiAlias(skPaint.isAntiAlias()); |
| 434 | 435 |
| 435 // Setup the initial color considering the shader, the SkPaint color, and th
e presence or not | 436 // Setup the initial color considering the shader, the SkPaint color, and th
e presence or not |
| 436 // of per-vertex colors. | 437 // of per-vertex colors. |
| 437 SkAutoTUnref<const GrFragmentProcessor> aufp; | 438 SkAutoTUnref<const GrFragmentProcessor> aufp; |
| 438 const GrFragmentProcessor* shaderFP = nullptr; | 439 const GrFragmentProcessor* shaderFP = nullptr; |
| 439 if (!primColorMode || blend_requires_shader(*primColorMode, primitiveIsSrc))
{ | 440 if (!primColorMode || blend_requires_shader(*primColorMode, primitiveIsSrc))
{ |
| 440 if (shaderProcessor) { | 441 if (shaderProcessor) { |
| 441 shaderFP = *shaderProcessor; | 442 shaderFP = *shaderProcessor; |
| 442 } else if (const SkShader* shader = skPaint.getShader()) { | 443 } else if (const SkShader* shader = skPaint.getShader()) { |
| 443 aufp.reset(shader->asFragmentProcessor(context, viewM, nullptr, | 444 aufp.reset(shader->asFragmentProcessor(context, viewM, nullptr, |
| 444 skPaint.getFilterQuality())); | 445 skPaint.getFilterQuality(), |
| 446 dstRT)); |
| 445 shaderFP = aufp; | 447 shaderFP = aufp; |
| 446 if (!shaderFP) { | 448 if (!shaderFP) { |
| 447 return false; | 449 return false; |
| 448 } | 450 } |
| 449 } | 451 } |
| 450 } | 452 } |
| 451 | 453 |
| 452 // Set this in below cases if the output of the shader/paint-color/paint-alp
ha/primXfermode is | 454 // Set this in below cases if the output of the shader/paint-color/paint-alp
ha/primXfermode is |
| 453 // a known constant value. In that case we can simply apply a color filter d
uring this | 455 // a known constant value. In that case we can simply apply a color filter d
uring this |
| 454 // conversion without converting the color filter to a GrFragmentProcessor. | 456 // conversion without converting the color filter to a GrFragmentProcessor. |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 applyColorFilterToPaintColor = true; | 524 applyColorFilterToPaintColor = true; |
| 523 } | 525 } |
| 524 } | 526 } |
| 525 | 527 |
| 526 SkColorFilter* colorFilter = skPaint.getColorFilter(); | 528 SkColorFilter* colorFilter = skPaint.getColorFilter(); |
| 527 if (colorFilter) { | 529 if (colorFilter) { |
| 528 if (applyColorFilterToPaintColor) { | 530 if (applyColorFilterToPaintColor) { |
| 529 grPaint->setColor(SkColorToPremulGrColor(colorFilter->filterColor(sk
Paint.getColor()))); | 531 grPaint->setColor(SkColorToPremulGrColor(colorFilter->filterColor(sk
Paint.getColor()))); |
| 530 } else { | 532 } else { |
| 531 SkAutoTUnref<const GrFragmentProcessor> cfFP( | 533 SkAutoTUnref<const GrFragmentProcessor> cfFP( |
| 532 colorFilter->asFragmentProcessor(context)); | 534 colorFilter->asFragmentProcessor(context, dstRT)); |
| 533 if (cfFP) { | 535 if (cfFP) { |
| 534 grPaint->addColorFragmentProcessor(cfFP); | 536 grPaint->addColorFragmentProcessor(cfFP); |
| 535 } else { | 537 } else { |
| 536 return false; | 538 return false; |
| 537 } | 539 } |
| 538 } | 540 } |
| 539 } | 541 } |
| 540 | 542 |
| 541 SkXfermode* mode = skPaint.getXfermode(); | 543 SkXfermode* mode = skPaint.getXfermode(); |
| 542 GrXPFactory* xpFactory = nullptr; | 544 GrXPFactory* xpFactory = nullptr; |
| 543 if (!SkXfermode::AsXPFactory(mode, &xpFactory)) { | 545 if (!SkXfermode::AsXPFactory(mode, &xpFactory)) { |
| 544 // Fall back to src-over | 546 // Fall back to src-over |
| 545 // return false here? | 547 // return false here? |
| 546 xpFactory = GrPorterDuffXPFactory::Create(SkXfermode::kSrcOver_Mode); | 548 xpFactory = GrPorterDuffXPFactory::Create(SkXfermode::kSrcOver_Mode); |
| 547 } | 549 } |
| 548 SkASSERT(xpFactory); | 550 SkASSERT(xpFactory); |
| 549 grPaint->setXPFactory(xpFactory)->unref(); | 551 grPaint->setXPFactory(xpFactory)->unref(); |
| 550 | 552 |
| 551 #ifndef SK_IGNORE_GPU_DITHER | 553 #ifndef SK_IGNORE_GPU_DITHER |
| 552 if (skPaint.isDither() && grPaint->numColorFragmentProcessors() > 0) { | 554 if (skPaint.isDither() && grPaint->numColorFragmentProcessors() > 0) { |
| 553 grPaint->addColorFragmentProcessor(GrDitherEffect::Create())->unref(); | 555 grPaint->addColorFragmentProcessor(GrDitherEffect::Create())->unref(); |
| 554 } | 556 } |
| 555 #endif | 557 #endif |
| 556 return true; | 558 return true; |
| 557 } | 559 } |
| 558 | 560 |
| 559 bool SkPaintToGrPaint(GrContext* context, const SkPaint& skPaint, const SkMatrix
& viewM, | 561 bool SkPaintToGrPaint(GrContext* context, const SkPaint& skPaint, const SkMatrix
& viewM, |
| 560 GrPaint* grPaint) { | 562 GrPaint* grPaint, GrRenderTarget* dstRT) { |
| 561 return skpaint_to_grpaint_impl(context, skPaint, viewM, nullptr, nullptr, fa
lse, grPaint); | 563 return skpaint_to_grpaint_impl(context, skPaint, viewM, nullptr, nullptr, fa
lse, grPaint, dstRT); |
| 562 } | 564 } |
| 563 | 565 |
| 564 /** Replaces the SkShader (if any) on skPaint with the passed in GrFragmentProce
ssor. */ | 566 /** Replaces the SkShader (if any) on skPaint with the passed in GrFragmentProce
ssor. */ |
| 565 bool SkPaintToGrPaintReplaceShader(GrContext* context, | 567 bool SkPaintToGrPaintReplaceShader(GrContext* context, |
| 566 const SkPaint& skPaint, | 568 const SkPaint& skPaint, |
| 567 const GrFragmentProcessor* shaderFP, | 569 const GrFragmentProcessor* shaderFP, |
| 568 GrPaint* grPaint) { | 570 GrPaint* grPaint, GrRenderTarget* dstRT) { |
| 569 if (!shaderFP) { | 571 if (!shaderFP) { |
| 570 return false; | 572 return false; |
| 571 } | 573 } |
| 572 return skpaint_to_grpaint_impl(context, skPaint, SkMatrix::I(), &shaderFP, n
ullptr, false, | 574 return skpaint_to_grpaint_impl(context, skPaint, SkMatrix::I(), &shaderFP, n
ullptr, false, |
| 573 grPaint); | 575 grPaint, dstRT); |
| 574 } | 576 } |
| 575 | 577 |
| 576 /** Ignores the SkShader (if any) on skPaint. */ | 578 /** Ignores the SkShader (if any) on skPaint. */ |
| 577 bool SkPaintToGrPaintNoShader(GrContext* context, | 579 bool SkPaintToGrPaintNoShader(GrContext* context, |
| 578 const SkPaint& skPaint, | 580 const SkPaint& skPaint, |
| 579 GrPaint* grPaint) { | 581 GrPaint* grPaint, GrRenderTarget* dstRT) { |
| 580 // Use a ptr to a nullptr to to indicate that the SkShader is ignored and no
t replaced. | 582 // Use a ptr to a nullptr to to indicate that the SkShader is ignored and no
t replaced. |
| 581 static const GrFragmentProcessor* kNullShaderFP = nullptr; | 583 static const GrFragmentProcessor* kNullShaderFP = nullptr; |
| 582 static const GrFragmentProcessor** kIgnoreShader = &kNullShaderFP; | 584 static const GrFragmentProcessor** kIgnoreShader = &kNullShaderFP; |
| 583 return skpaint_to_grpaint_impl(context, skPaint, SkMatrix::I(), kIgnoreShade
r, nullptr, false, | 585 return skpaint_to_grpaint_impl(context, skPaint, SkMatrix::I(), kIgnoreShade
r, nullptr, false, |
| 584 grPaint); | 586 grPaint, dstRT); |
| 585 } | 587 } |
| 586 | 588 |
| 587 /** Blends the SkPaint's shader (or color if no shader) with a per-primitive col
or which must | 589 /** Blends the SkPaint's shader (or color if no shader) with a per-primitive col
or which must |
| 588 be setup as a vertex attribute using the specified SkXfermode::Mode. */ | 590 be setup as a vertex attribute using the specified SkXfermode::Mode. */ |
| 589 bool SkPaintToGrPaintWithXfermode(GrContext* context, | 591 bool SkPaintToGrPaintWithXfermode(GrContext* context, |
| 590 const SkPaint& skPaint, | 592 const SkPaint& skPaint, |
| 591 const SkMatrix& viewM, | 593 const SkMatrix& viewM, |
| 592 SkXfermode::Mode primColorMode, | 594 SkXfermode::Mode primColorMode, |
| 593 bool primitiveIsSrc, | 595 bool primitiveIsSrc, |
| 594 GrPaint* grPaint) { | 596 GrPaint* grPaint, |
| 597 GrRenderTarget* dstRT) { |
| 595 return skpaint_to_grpaint_impl(context, skPaint, viewM, nullptr, &primColorM
ode, primitiveIsSrc, | 598 return skpaint_to_grpaint_impl(context, skPaint, viewM, nullptr, &primColorM
ode, primitiveIsSrc, |
| 596 grPaint); | 599 grPaint, dstRT); |
| 597 } | 600 } |
| 598 | 601 |
| 599 | 602 |
| 600 ////////////////////////////////////////////////////////////////////////////////
//////////////// | 603 ////////////////////////////////////////////////////////////////////////////////
//////////////// |
| 601 | 604 |
| 602 SkImageInfo GrMakeInfoFromTexture(GrTexture* tex, int w, int h, bool isOpaque) { | 605 SkImageInfo GrMakeInfoFromTexture(GrTexture* tex, int w, int h, bool isOpaque) { |
| 603 #ifdef SK_DEBUG | 606 #ifdef SK_DEBUG |
| 604 const GrSurfaceDesc& desc = tex->desc(); | 607 const GrSurfaceDesc& desc = tex->desc(); |
| 605 SkASSERT(w <= desc.fWidth); | 608 SkASSERT(w <= desc.fWidth); |
| 606 SkASSERT(h <= desc.fHeight); | 609 SkASSERT(h <= desc.fHeight); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 SkErrorInternals::SetError( kInvalidPaint_SkError, | 658 SkErrorInternals::SetError( kInvalidPaint_SkError, |
| 656 "Sorry, I don't understand the filtering
" | 659 "Sorry, I don't understand the filtering
" |
| 657 "mode you asked for. Falling back to " | 660 "mode you asked for. Falling back to " |
| 658 "MIPMaps."); | 661 "MIPMaps."); |
| 659 textureFilterMode = GrTextureParams::kMipMap_FilterMode; | 662 textureFilterMode = GrTextureParams::kMipMap_FilterMode; |
| 660 break; | 663 break; |
| 661 | 664 |
| 662 } | 665 } |
| 663 return textureFilterMode; | 666 return textureFilterMode; |
| 664 } | 667 } |
| OLD | NEW |