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 #include "SkGr.h" | 8 #include "SkGr.h" |
9 | 9 |
10 #include "GrDrawTargetCaps.h" | 10 #include "GrDrawTargetCaps.h" |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 } | 457 } |
458 | 458 |
459 /////////////////////////////////////////////////////////////////////////////// | 459 /////////////////////////////////////////////////////////////////////////////// |
460 | 460 |
461 void SkPaint2GrPaintNoShader(GrContext* context, const SkPaint& skPaint, GrColor
paintColor, | 461 void SkPaint2GrPaintNoShader(GrContext* context, const SkPaint& skPaint, GrColor
paintColor, |
462 bool constantColor, GrPaint* grPaint) { | 462 bool constantColor, GrPaint* grPaint) { |
463 | 463 |
464 grPaint->setDither(skPaint.isDither()); | 464 grPaint->setDither(skPaint.isDither()); |
465 grPaint->setAntiAlias(skPaint.isAntiAlias()); | 465 grPaint->setAntiAlias(skPaint.isAntiAlias()); |
466 | 466 |
| 467 SkXfermode::Coeff sm; |
| 468 SkXfermode::Coeff dm; |
| 469 |
467 SkXfermode* mode = skPaint.getXfermode(); | 470 SkXfermode* mode = skPaint.getXfermode(); |
468 GrFragmentProcessor* fragmentProcessor = NULL; | 471 GrFragmentProcessor* fragmentProcessor = NULL; |
469 GrXPFactory* xpFactory = NULL; | 472 GrXPFactory* xpFactory = NULL; |
470 if (SkXfermode::AsFragmentProcessorOrXPFactory(mode, &fragmentProcessor, &xp
Factory)) { | 473 if (SkXfermode::AsFragmentProcessorOrXPFactory(mode, &fragmentProcessor, &xp
Factory, |
| 474 &sm, &dm)) { |
471 if (fragmentProcessor) { | 475 if (fragmentProcessor) { |
472 SkASSERT(NULL == xpFactory); | 476 SkASSERT(NULL == xpFactory); |
473 grPaint->addColorProcessor(fragmentProcessor)->unref(); | 477 grPaint->addColorProcessor(fragmentProcessor)->unref(); |
474 xpFactory = GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode); | 478 xpFactory = GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode); |
| 479 sm = SkXfermode::kOne_Coeff; |
| 480 dm = SkXfermode::kZero_Coeff; |
475 } | 481 } |
476 } else { | 482 } else { |
477 // Fall back to src-over | 483 // Fall back to src-over |
478 xpFactory = GrPorterDuffXPFactory::Create(SkXfermode::kSrcOver_Mode); | 484 xpFactory = GrPorterDuffXPFactory::Create(SkXfermode::kSrcOver_Mode); |
| 485 sm = SkXfermode::kOne_Coeff; |
| 486 dm = SkXfermode::kISA_Coeff; |
479 } | 487 } |
480 SkASSERT(xpFactory); | 488 SkASSERT(xpFactory); |
481 grPaint->setXPFactory(xpFactory)->unref(); | 489 grPaint->setXPFactory(xpFactory)->unref(); |
| 490 grPaint->setBlendFunc(sk_blend_to_grblend(sm), sk_blend_to_grblend(dm)); |
482 | 491 |
483 //set the color of the paint to the one of the parameter | 492 //set the color of the paint to the one of the parameter |
484 grPaint->setColor(paintColor); | 493 grPaint->setColor(paintColor); |
485 | 494 |
486 SkColorFilter* colorFilter = skPaint.getColorFilter(); | 495 SkColorFilter* colorFilter = skPaint.getColorFilter(); |
487 if (colorFilter) { | 496 if (colorFilter) { |
488 // if the source color is a constant then apply the filter here once rat
her than per pixel | 497 // if the source color is a constant then apply the filter here once rat
her than per pixel |
489 // in a shader. | 498 // in a shader. |
490 if (constantColor) { | 499 if (constantColor) { |
491 SkColor filtered = colorFilter->filterColor(skPaint.getColor()); | 500 SkColor filtered = colorFilter->filterColor(skPaint.getColor()); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 if (shader->asFragmentProcessor(context, skPaint, NULL, &paintColor, &fp
) && fp) { | 580 if (shader->asFragmentProcessor(context, skPaint, NULL, &paintColor, &fp
) && fp) { |
572 grPaint->addColorProcessor(fp)->unref(); | 581 grPaint->addColorProcessor(fp)->unref(); |
573 constantColor = false; | 582 constantColor = false; |
574 } | 583 } |
575 } | 584 } |
576 | 585 |
577 // The grcolor is automatically set when calling asFragmentProcessor. | 586 // The grcolor is automatically set when calling asFragmentProcessor. |
578 // If the shader can be seen as an effect it returns true and adds its effec
t to the grpaint. | 587 // If the shader can be seen as an effect it returns true and adds its effec
t to the grpaint. |
579 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint
); | 588 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint
); |
580 } | 589 } |
OLD | NEW |