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 #include "SkColorFilter.h" | 9 #include "SkColorFilter.h" |
10 #include "SkConfig8888.h" | 10 #include "SkConfig8888.h" |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 return false; | 412 return false; |
413 } | 413 } |
414 if (ctOut) { | 414 if (ctOut) { |
415 *ctOut = ct; | 415 *ctOut = ct; |
416 } | 416 } |
417 return true; | 417 return true; |
418 } | 418 } |
419 | 419 |
420 /////////////////////////////////////////////////////////////////////////////// | 420 /////////////////////////////////////////////////////////////////////////////// |
421 | 421 |
422 void SkPaint2GrPaintNoShader(GrContext* context, const SkPaint& skPaint, GrColor
grColor, | 422 void SkPaint2GrPaintNoShader(GrContext* context, const SkPaint& skPaint, GrColor
paintColor, |
423 bool constantColor, GrPaint* grPaint) { | 423 bool constantColor, GrPaint* grPaint) { |
424 | 424 |
425 grPaint->setDither(skPaint.isDither()); | 425 grPaint->setDither(skPaint.isDither()); |
426 grPaint->setAntiAlias(skPaint.isAntiAlias()); | 426 grPaint->setAntiAlias(skPaint.isAntiAlias()); |
427 | 427 |
428 SkXfermode::Coeff sm; | 428 SkXfermode::Coeff sm; |
429 SkXfermode::Coeff dm; | 429 SkXfermode::Coeff dm; |
430 | 430 |
431 SkXfermode* mode = skPaint.getXfermode(); | 431 SkXfermode* mode = skPaint.getXfermode(); |
432 GrEffectRef* xferEffect = NULL; | 432 GrEffect* xferEffect = NULL; |
433 if (SkXfermode::AsNewEffectOrCoeff(mode, &xferEffect, &sm, &dm)) { | 433 if (SkXfermode::AsNewEffectOrCoeff(mode, &xferEffect, &sm, &dm)) { |
434 if (NULL != xferEffect) { | 434 if (NULL != xferEffect) { |
435 grPaint->addColorEffect(xferEffect)->unref(); | 435 grPaint->addColorEffect(xferEffect)->unref(); |
436 sm = SkXfermode::kOne_Coeff; | 436 sm = SkXfermode::kOne_Coeff; |
437 dm = SkXfermode::kZero_Coeff; | 437 dm = SkXfermode::kZero_Coeff; |
438 } | 438 } |
439 } else { | 439 } else { |
440 //SkDEBUGCODE(SkDebugf("Unsupported xfer mode.\n");) | 440 //SkDEBUGCODE(SkDebugf("Unsupported xfer mode.\n");) |
441 // Fall back to src-over | 441 // Fall back to src-over |
442 sm = SkXfermode::kOne_Coeff; | 442 sm = SkXfermode::kOne_Coeff; |
443 dm = SkXfermode::kISA_Coeff; | 443 dm = SkXfermode::kISA_Coeff; |
444 } | 444 } |
445 grPaint->setBlendFunc(sk_blend_to_grblend(sm), sk_blend_to_grblend(dm)); | 445 grPaint->setBlendFunc(sk_blend_to_grblend(sm), sk_blend_to_grblend(dm)); |
446 | 446 |
447 //set the color of the paint to the one of the parameter | 447 //set the color of the paint to the one of the parameter |
448 grPaint->setColor(grColor); | 448 grPaint->setColor(paintColor); |
449 | 449 |
450 SkColorFilter* colorFilter = skPaint.getColorFilter(); | 450 SkColorFilter* colorFilter = skPaint.getColorFilter(); |
451 if (NULL != colorFilter) { | 451 if (NULL != colorFilter) { |
452 // if the source color is a constant then apply the filter here once rat
her than per pixel | 452 // if the source color is a constant then apply the filter here once rat
her than per pixel |
453 // in a shader. | 453 // in a shader. |
454 if (constantColor) { | 454 if (constantColor) { |
455 SkColor filtered = colorFilter->filterColor(skPaint.getColor()); | 455 SkColor filtered = colorFilter->filterColor(skPaint.getColor()); |
456 grPaint->setColor(SkColor2GrColor(filtered)); | 456 grPaint->setColor(SkColor2GrColor(filtered)); |
457 } else { | 457 } else { |
458 SkAutoTUnref<GrEffectRef> effect(colorFilter->asNewEffect(context)); | 458 SkAutoTUnref<GrEffect> effect(colorFilter->asNewEffect(context)); |
459 if (NULL != effect.get()) { | 459 if (NULL != effect.get()) { |
460 grPaint->addColorEffect(effect); | 460 grPaint->addColorEffect(effect); |
461 } | 461 } |
462 } | 462 } |
463 } | 463 } |
464 | 464 |
465 #ifndef SK_IGNORE_GPU_DITHER | 465 #ifndef SK_IGNORE_GPU_DITHER |
466 // If the dither flag is set, then we need to see if the underlying context | 466 // If the dither flag is set, then we need to see if the underlying context |
467 // supports it. If not, then install a dither effect. | 467 // supports it. If not, then install a dither effect. |
468 if (skPaint.isDither() && grPaint->numColorStages() > 0) { | 468 if (skPaint.isDither() && grPaint->numColorStages() > 0) { |
469 // What are we rendering into? | 469 // What are we rendering into? |
470 const GrRenderTarget *target = context->getRenderTarget(); | 470 const GrRenderTarget *target = context->getRenderTarget(); |
471 SkASSERT(NULL != target); | 471 SkASSERT(NULL != target); |
472 | 472 |
473 // Suspect the dithering flag has no effect on these configs, otherwise | 473 // Suspect the dithering flag has no effect on these configs, otherwise |
474 // fall back on setting the appropriate state. | 474 // fall back on setting the appropriate state. |
475 if (target->config() == kRGBA_8888_GrPixelConfig || | 475 if (target->config() == kRGBA_8888_GrPixelConfig || |
476 target->config() == kBGRA_8888_GrPixelConfig) { | 476 target->config() == kBGRA_8888_GrPixelConfig) { |
477 // The dither flag is set and the target is likely | 477 // The dither flag is set and the target is likely |
478 // not going to be dithered by the GPU. | 478 // not going to be dithered by the GPU. |
479 SkAutoTUnref<GrEffectRef> effect(GrDitherEffect::Create()); | 479 SkAutoTUnref<GrEffect> effect(GrDitherEffect::Create()); |
480 if (NULL != effect.get()) { | 480 if (NULL != effect.get()) { |
481 grPaint->addColorEffect(effect); | 481 grPaint->addColorEffect(effect); |
482 grPaint->setDither(false); | 482 grPaint->setDither(false); |
483 } | 483 } |
484 } | 484 } |
485 } | 485 } |
486 #endif | 486 #endif |
487 } | 487 } |
488 | 488 |
489 /** | 489 /** |
(...skipping 18 matching lines...) Expand all Loading... |
508 | 508 |
509 void SkPaint2GrPaintShader(GrContext* context, const SkPaint& skPaint, | 509 void SkPaint2GrPaintShader(GrContext* context, const SkPaint& skPaint, |
510 bool constantColor, GrPaint* grPaint) { | 510 bool constantColor, GrPaint* grPaint) { |
511 SkShader* shader = skPaint.getShader(); | 511 SkShader* shader = skPaint.getShader(); |
512 if (NULL == shader) { | 512 if (NULL == shader) { |
513 SkPaint2GrPaintNoShader(context, skPaint, SkColor2GrColor(skPaint.getCol
or()), | 513 SkPaint2GrPaintNoShader(context, skPaint, SkColor2GrColor(skPaint.getCol
or()), |
514 constantColor, grPaint); | 514 constantColor, grPaint); |
515 return; | 515 return; |
516 } | 516 } |
517 | 517 |
518 // SkShader::asNewEffect() may do offscreen rendering. Save off the current
RT, clip, and | 518 GrColor paintColor = SkColor2GrColor(skPaint.getColor()); |
519 // matrix. We don't reset the matrix on the context because SkShader::asNewE
ffect may use | |
520 // GrContext::getMatrix() to know the transformation from local coords to de
vice space. | |
521 GrColor grColor = SkColor2GrColor(skPaint.getColor()); | |
522 | 519 |
523 // Start a new block here in order to preserve our context state after calli
ng | 520 // Start a new block here in order to preserve our context state after calli
ng |
524 // asNewEffect(). Since these calls get passed back to the client, we don't
really | 521 // asNewEffect(). Since these calls get passed back to the client, we don't
really |
525 // want them messing around with the context. | 522 // want them messing around with the context. |
526 { | 523 { |
| 524 // SkShader::asNewEffect() may do offscreen rendering. Save off the curr
ent RT, clip, and |
| 525 // matrix. We don't reset the matrix on the context because SkShader::as
NewEffect may use |
| 526 // GrContext::getMatrix() to know the transformation from local coords t
o device space. |
527 GrContext::AutoRenderTarget art(context, NULL); | 527 GrContext::AutoRenderTarget art(context, NULL); |
528 GrContext::AutoClip ac(context, GrContext::AutoClip::kWideOpen_InitialCl
ip); | 528 GrContext::AutoClip ac(context, GrContext::AutoClip::kWideOpen_InitialCl
ip); |
529 AutoMatrix am(context); | 529 AutoMatrix am(context); |
530 | 530 |
531 // setup the shader as the first color effect on the paint | 531 // Allow the shader to modify paintColor and also create an effect to be
installed as |
532 // the default grColor is the paint's color | 532 // the first color effect on the GrPaint. |
533 GrEffectRef* grEffect = NULL; | 533 GrEffect* effect = NULL; |
534 if (shader->asNewEffect(context, skPaint, NULL, &grColor, &grEffect) &&
NULL != grEffect) { | 534 if (shader->asNewEffect(context, skPaint, NULL, &paintColor, &effect) &&
NULL != effect) { |
535 SkAutoTUnref<GrEffectRef> effect(grEffect); | 535 grPaint->addColorEffect(effect)->unref(); |
536 grPaint->addColorEffect(effect); | |
537 constantColor = false; | 536 constantColor = false; |
538 } | 537 } |
539 } | 538 } |
540 | 539 |
541 // The grcolor is automatically set when calling asneweffect. | 540 // The grcolor is automatically set when calling asneweffect. |
542 // If the shader can be seen as an effect it returns true and adds its effec
t to the grpaint. | 541 // If the shader can be seen as an effect it returns true and adds its effec
t to the grpaint. |
543 SkPaint2GrPaintNoShader(context, skPaint, grColor, constantColor, grPaint); | 542 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint
); |
544 } | 543 } |
OLD | NEW |