| 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 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 return false; | 398 return false; |
| 399 } | 399 } |
| 400 if (ctOut) { | 400 if (ctOut) { |
| 401 *ctOut = ct; | 401 *ctOut = ct; |
| 402 } | 402 } |
| 403 return true; | 403 return true; |
| 404 } | 404 } |
| 405 | 405 |
| 406 /////////////////////////////////////////////////////////////////////////////// | 406 /////////////////////////////////////////////////////////////////////////////// |
| 407 | 407 |
| 408 void SkPaint2GrPaintNoShader(GrContext* context, const SkPaint& skPaint, bool ju
stAlpha, | 408 void SkPaint2GrPaintNoShader(GrContext* context, const SkPaint& skPaint, GrColor
grColor, |
| 409 bool constantColor, GrPaint* grPaint) { | 409 bool constantColor, GrPaint* grPaint) { |
| 410 | 410 |
| 411 grPaint->setDither(skPaint.isDither()); | 411 grPaint->setDither(skPaint.isDither()); |
| 412 grPaint->setAntiAlias(skPaint.isAntiAlias()); | 412 grPaint->setAntiAlias(skPaint.isAntiAlias()); |
| 413 | 413 |
| 414 SkXfermode::Coeff sm; | 414 SkXfermode::Coeff sm; |
| 415 SkXfermode::Coeff dm; | 415 SkXfermode::Coeff dm; |
| 416 | 416 |
| 417 SkXfermode* mode = skPaint.getXfermode(); | 417 SkXfermode* mode = skPaint.getXfermode(); |
| 418 GrEffectRef* xferEffect = NULL; | 418 GrEffectRef* xferEffect = NULL; |
| 419 if (SkXfermode::AsNewEffectOrCoeff(mode, &xferEffect, &sm, &dm)) { | 419 if (SkXfermode::AsNewEffectOrCoeff(mode, &xferEffect, &sm, &dm)) { |
| 420 if (NULL != xferEffect) { | 420 if (NULL != xferEffect) { |
| 421 grPaint->addColorEffect(xferEffect)->unref(); | 421 grPaint->addColorEffect(xferEffect)->unref(); |
| 422 sm = SkXfermode::kOne_Coeff; | 422 sm = SkXfermode::kOne_Coeff; |
| 423 dm = SkXfermode::kZero_Coeff; | 423 dm = SkXfermode::kZero_Coeff; |
| 424 } | 424 } |
| 425 } else { | 425 } else { |
| 426 //SkDEBUGCODE(SkDebugf("Unsupported xfer mode.\n");) | 426 //SkDEBUGCODE(SkDebugf("Unsupported xfer mode.\n");) |
| 427 // Fall back to src-over | 427 // Fall back to src-over |
| 428 sm = SkXfermode::kOne_Coeff; | 428 sm = SkXfermode::kOne_Coeff; |
| 429 dm = SkXfermode::kISA_Coeff; | 429 dm = SkXfermode::kISA_Coeff; |
| 430 } | 430 } |
| 431 grPaint->setBlendFunc(sk_blend_to_grblend(sm), sk_blend_to_grblend(dm)); | 431 grPaint->setBlendFunc(sk_blend_to_grblend(sm), sk_blend_to_grblend(dm)); |
| 432 | 432 |
| 433 if (justAlpha) { | 433 //set the color of the paint to the one of the parameter |
| 434 uint8_t alpha = skPaint.getAlpha(); | 434 grPaint->setColor(grColor); |
| 435 grPaint->setColor(GrColorPackRGBA(alpha, alpha, alpha, alpha)); | |
| 436 // justAlpha is currently set to true only if there is a texture, | |
| 437 // so constantColor should not also be true. | |
| 438 SkASSERT(!constantColor); | |
| 439 } else { | |
| 440 grPaint->setColor(SkColor2GrColor(skPaint.getColor())); | |
| 441 } | |
| 442 | 435 |
| 443 SkColorFilter* colorFilter = skPaint.getColorFilter(); | 436 SkColorFilter* colorFilter = skPaint.getColorFilter(); |
| 444 if (NULL != colorFilter) { | 437 if (NULL != colorFilter) { |
| 445 // if the source color is a constant then apply the filter here once rat
her than per pixel | 438 // if the source color is a constant then apply the filter here once rat
her than per pixel |
| 446 // in a shader. | 439 // in a shader. |
| 447 if (constantColor) { | 440 if (constantColor) { |
| 448 SkColor filtered = colorFilter->filterColor(skPaint.getColor()); | 441 SkColor filtered = colorFilter->filterColor(skPaint.getColor()); |
| 449 grPaint->setColor(SkColor2GrColor(filtered)); | 442 grPaint->setColor(SkColor2GrColor(filtered)); |
| 450 } else { | 443 } else { |
| 451 SkAutoTUnref<GrEffectRef> effect(colorFilter->asNewEffect(context)); | 444 SkAutoTUnref<GrEffectRef> effect(colorFilter->asNewEffect(context)); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 473 } | 466 } |
| 474 private: | 467 private: |
| 475 GrContext* fContext; | 468 GrContext* fContext; |
| 476 SkMatrix fMatrix; | 469 SkMatrix fMatrix; |
| 477 }; | 470 }; |
| 478 | 471 |
| 479 void SkPaint2GrPaintShader(GrContext* context, const SkPaint& skPaint, | 472 void SkPaint2GrPaintShader(GrContext* context, const SkPaint& skPaint, |
| 480 bool constantColor, GrPaint* grPaint) { | 473 bool constantColor, GrPaint* grPaint) { |
| 481 SkShader* shader = skPaint.getShader(); | 474 SkShader* shader = skPaint.getShader(); |
| 482 if (NULL == shader) { | 475 if (NULL == shader) { |
| 483 SkPaint2GrPaintNoShader(context, skPaint, false, constantColor, grPaint)
; | 476 SkPaint2GrPaintNoShader(context, skPaint, SkColor2GrColor(skPaint.getCol
or()), |
| 477 constantColor, grPaint); |
| 484 return; | 478 return; |
| 485 } | 479 } |
| 486 | 480 |
| 487 // SkShader::asNewEffect() may do offscreen rendering. Save off the current
RT, clip, and | 481 // SkShader::asNewEffect() may do offscreen rendering. Save off the current
RT, clip, and |
| 488 // matrix. We don't reset the matrix on the context because SkShader::asNewE
ffect may use | 482 // matrix. We don't reset the matrix on the context because SkShader::asNewE
ffect may use |
| 489 // GrContext::getMatrix() to know the transformation from local coords to de
vice space. | 483 // GrContext::getMatrix() to know the transformation from local coords to de
vice space. |
| 490 GrContext::AutoRenderTarget art(context, NULL); | 484 GrContext::AutoRenderTarget art(context, NULL); |
| 491 GrContext::AutoClip ac(context, GrContext::AutoClip::kWideOpen_InitialClip); | 485 GrContext::AutoClip ac(context, GrContext::AutoClip::kWideOpen_InitialClip); |
| 492 AutoMatrix am(context); | 486 AutoMatrix am(context); |
| 493 | 487 |
| 494 // setup the shader as the first color effect on the paint | 488 // setup the shader as the first color effect on the paint |
| 495 SkAutoTUnref<GrEffectRef> effect(shader->asNewEffect(context, skPaint, NULL)
); | 489 // the default grColor is the paint's color |
| 496 if (NULL != effect.get()) { | 490 GrColor grColor = SkColor2GrColor(skPaint.getColor()); |
| 491 GrEffectRef* grEffect = NULL; |
| 492 if (shader->asNewEffect(context, skPaint, NULL, &grColor, &grEffect) && NULL
!= grEffect) { |
| 493 SkAutoTUnref<GrEffectRef> effect(grEffect); |
| 497 grPaint->addColorEffect(effect); | 494 grPaint->addColorEffect(effect); |
| 498 // Now setup the rest of the paint. | 495 constantColor = false; |
| 499 SkPaint2GrPaintNoShader(context, skPaint, true, false, grPaint); | |
| 500 } else { | |
| 501 // We still don't have SkColorShader::asNewEffect() implemented. | |
| 502 SkShader::GradientInfo info; | |
| 503 SkColor color; | |
| 504 | |
| 505 info.fColors = &color; | |
| 506 info.fColorOffsets = NULL; | |
| 507 info.fColorCount = 1; | |
| 508 if (SkShader::kColor_GradientType == shader->asAGradient(&info)) { | |
| 509 SkPaint copy(skPaint); | |
| 510 copy.setShader(NULL); | |
| 511 // modulate the paint alpha by the shader's solid color alpha | |
| 512 U8CPU newA = SkMulDiv255Round(SkColorGetA(color), copy.getAlpha()); | |
| 513 copy.setColor(SkColorSetA(color, newA)); | |
| 514 SkPaint2GrPaintNoShader(context, copy, false, constantColor, grPaint
); | |
| 515 } else { | |
| 516 SkPaint2GrPaintNoShader(context, skPaint, false, constantColor, grPa
int); | |
| 517 } | |
| 518 } | 496 } |
| 497 // The grcolor is automatically set when calling asneweffect. |
| 498 // If the shader can be seen as an effect it returns true and adds its effec
t to the grpaint. |
| 499 SkPaint2GrPaintNoShader(context, skPaint, grColor, constantColor, grPaint); |
| 519 } | 500 } |
| OLD | NEW |