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 | |
10 #include "GrDrawTargetCaps.h" | |
11 #include "GrGpu.h" | |
12 #include "GrXferProcessor.h" | |
9 #include "SkColorFilter.h" | 13 #include "SkColorFilter.h" |
10 #include "SkConfig8888.h" | 14 #include "SkConfig8888.h" |
11 #include "SkData.h" | 15 #include "SkData.h" |
12 #include "SkMessageBus.h" | 16 #include "SkMessageBus.h" |
13 #include "SkPixelRef.h" | 17 #include "SkPixelRef.h" |
14 #include "SkTextureCompressor.h" | 18 #include "SkTextureCompressor.h" |
15 #include "GrGpu.h" | |
16 #include "effects/GrDitherEffect.h" | 19 #include "effects/GrDitherEffect.h" |
17 #include "GrDrawTargetCaps.h" | 20 #include "effects/GrPorterDuffXferProcessor.h" |
18 #include "effects/GrYUVtoRGBEffect.h" | 21 #include "effects/GrYUVtoRGBEffect.h" |
19 | 22 |
20 #ifndef SK_IGNORE_ETC1_SUPPORT | 23 #ifndef SK_IGNORE_ETC1_SUPPORT |
21 # include "ktx.h" | 24 # include "ktx.h" |
22 # include "etc1.h" | 25 # include "etc1.h" |
23 #endif | 26 #endif |
24 | 27 |
25 /* Fill out buffer with the compressed format Ganesh expects from a colortable | 28 /* Fill out buffer with the compressed format Ganesh expects from a colortable |
26 based bitmap. [palette (colortable) + indices]. | 29 based bitmap. [palette (colortable) + indices]. |
27 | 30 |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
460 void SkPaint2GrPaintNoShader(GrContext* context, const SkPaint& skPaint, GrColor paintColor, | 463 void SkPaint2GrPaintNoShader(GrContext* context, const SkPaint& skPaint, GrColor paintColor, |
461 bool constantColor, GrPaint* grPaint) { | 464 bool constantColor, GrPaint* grPaint) { |
462 | 465 |
463 grPaint->setDither(skPaint.isDither()); | 466 grPaint->setDither(skPaint.isDither()); |
464 grPaint->setAntiAlias(skPaint.isAntiAlias()); | 467 grPaint->setAntiAlias(skPaint.isAntiAlias()); |
465 | 468 |
466 SkXfermode::Coeff sm; | 469 SkXfermode::Coeff sm; |
467 SkXfermode::Coeff dm; | 470 SkXfermode::Coeff dm; |
468 | 471 |
469 SkXfermode* mode = skPaint.getXfermode(); | 472 SkXfermode* mode = skPaint.getXfermode(); |
470 GrFragmentProcessor* xferProcessor = NULL; | 473 GrFragmentProcessor* fragmentProcessor = NULL; |
471 if (SkXfermode::asFragmentProcessorOrCoeff(mode, &xferProcessor, &sm, &dm)) { | 474 GrXPFactory* xpFactory = NULL; |
472 if (xferProcessor) { | 475 if (SkXfermode::asFragmentProcessorOrXPFactoryOrCoeff(mode, &fragmentProcess or, &xpFactory, |
473 grPaint->addColorProcessor(xferProcessor)->unref(); | 476 &sm, &dm)) { |
477 if (xpFactory) { | |
474 sm = SkXfermode::kOne_Coeff; | 478 sm = SkXfermode::kOne_Coeff; |
475 dm = SkXfermode::kZero_Coeff; | 479 dm = SkXfermode::kZero_Coeff; |
480 } else if (fragmentProcessor) { | |
481 grPaint->addColorProcessor(fragmentProcessor)->unref(); | |
482 xpFactory = GrPorterDuffXPFactory::Create(SkXfermode::kOne_Coeff, | |
483 SkXfermode::kZero_Coeff); | |
484 sm = SkXfermode::kOne_Coeff; | |
485 dm = SkXfermode::kZero_Coeff; | |
486 } else { | |
487 // Xfer mode can be implemented as porter-duff coeffs | |
488 xpFactory = GrPorterDuffXPFactory::Create(sm, dm); | |
bsalomon
2014/11/26 21:02:45
why not make the asThisThatOrTheOther function do
egdaniel
2014/12/01 18:18:24
Moved to awseomeOrGreatOrPerfectorAmazingFunctionN
| |
476 } | 489 } |
477 } else { | 490 } else { |
478 //SkDEBUGCODE(SkDebugf("Unsupported xfer mode.\n");) | |
479 // Fall back to src-over | 491 // Fall back to src-over |
492 xpFactory = GrPorterDuffXPFactory::Create(SkXfermode::kOne_Coeff, | |
493 SkXfermode::kISA_Coeff); | |
480 sm = SkXfermode::kOne_Coeff; | 494 sm = SkXfermode::kOne_Coeff; |
481 dm = SkXfermode::kISA_Coeff; | 495 dm = SkXfermode::kISA_Coeff; |
482 } | 496 } |
497 SkASSERT(xpFactory); | |
498 grPaint->setXPFactory(xpFactory)->unref(); | |
483 grPaint->setBlendFunc(sk_blend_to_grblend(sm), sk_blend_to_grblend(dm)); | 499 grPaint->setBlendFunc(sk_blend_to_grblend(sm), sk_blend_to_grblend(dm)); |
484 | 500 |
485 //set the color of the paint to the one of the parameter | 501 //set the color of the paint to the one of the parameter |
486 grPaint->setColor(paintColor); | 502 grPaint->setColor(paintColor); |
487 | 503 |
488 SkColorFilter* colorFilter = skPaint.getColorFilter(); | 504 SkColorFilter* colorFilter = skPaint.getColorFilter(); |
489 if (colorFilter) { | 505 if (colorFilter) { |
490 // if the source color is a constant then apply the filter here once rat her than per pixel | 506 // if the source color is a constant then apply the filter here once rat her than per pixel |
491 // in a shader. | 507 // in a shader. |
492 if (constantColor) { | 508 if (constantColor) { |
493 SkColor filtered = colorFilter->filterColor(skPaint.getColor()); | 509 SkColor filtered = colorFilter->filterColor(skPaint.getColor()); |
494 grPaint->setColor(SkColor2GrColor(filtered)); | 510 grPaint->setColor(SkColor2GrColor(filtered)); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
573 if (shader->asFragmentProcessor(context, skPaint, NULL, &paintColor, &fp ) && fp) { | 589 if (shader->asFragmentProcessor(context, skPaint, NULL, &paintColor, &fp ) && fp) { |
574 grPaint->addColorProcessor(fp)->unref(); | 590 grPaint->addColorProcessor(fp)->unref(); |
575 constantColor = false; | 591 constantColor = false; |
576 } | 592 } |
577 } | 593 } |
578 | 594 |
579 // The grcolor is automatically set when calling asFragmentProcessor. | 595 // The grcolor is automatically set when calling asFragmentProcessor. |
580 // If the shader can be seen as an effect it returns true and adds its effec t to the grpaint. | 596 // If the shader can be seen as an effect it returns true and adds its effec t to the grpaint. |
581 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint ); | 597 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint ); |
582 } | 598 } |
OLD | NEW |