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