| 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 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 grPaint->setColor(SkColor2GrColor(filtered)); | 371 grPaint->setColor(SkColor2GrColor(filtered)); |
| 372 } else { | 372 } else { |
| 373 SkAutoTUnref<GrEffectRef> effect(colorFilter->asNewEffect(context)); | 373 SkAutoTUnref<GrEffectRef> effect(colorFilter->asNewEffect(context)); |
| 374 if (NULL != effect.get()) { | 374 if (NULL != effect.get()) { |
| 375 grPaint->addColorEffect(effect); | 375 grPaint->addColorEffect(effect); |
| 376 } | 376 } |
| 377 } | 377 } |
| 378 } | 378 } |
| 379 } | 379 } |
| 380 | 380 |
| 381 /** |
| 382 * Unlike GrContext::AutoMatrix, this doesn't require setting a new matrix. GrCo
ntext::AutoMatrix |
| 383 * likes to set the new matrix in its constructor because it is usually necessar
y to simulataneously |
| 384 * update a GrPaint. This AutoMatrix is used while initially setting up GrPaint,
however. |
| 385 */ |
| 386 class AutoMatrix { |
| 387 public: |
| 388 AutoMatrix(GrContext* context) { |
| 389 fMatrix = context->getMatrix(); |
| 390 fContext = context; |
| 391 } |
| 392 ~AutoMatrix() { |
| 393 SkASSERT(NULL != fContext); |
| 394 fContext->setMatrix(fMatrix); |
| 395 } |
| 396 private: |
| 397 GrContext* fContext; |
| 398 SkMatrix fMatrix; |
| 399 }; |
| 400 |
| 381 void SkPaint2GrPaintShader(GrContext* context, const SkPaint& skPaint, | 401 void SkPaint2GrPaintShader(GrContext* context, const SkPaint& skPaint, |
| 382 bool constantColor, GrPaint* grPaint) { | 402 bool constantColor, GrPaint* grPaint) { |
| 383 SkShader* shader = skPaint.getShader(); | 403 SkShader* shader = skPaint.getShader(); |
| 384 if (NULL == shader) { | 404 if (NULL == shader) { |
| 385 SkPaint2GrPaintNoShader(context, skPaint, false, constantColor, grPaint)
; | 405 SkPaint2GrPaintNoShader(context, skPaint, false, constantColor, grPaint)
; |
| 386 return; | 406 return; |
| 387 } | 407 } |
| 388 | 408 |
| 389 // SkShader::asNewEffect() may do offscreen rendering. Setup default drawing
state and require | 409 // SkShader::asNewEffect() may do offscreen rendering. Save off the current
RT, clip, and |
| 390 // the shader to set a render target. | 410 // matrix. We don't reset the matrix on the context because SkShader::asNewE
ffect may use |
| 391 GrContext::AutoWideOpenIdentityDraw awo(context, NULL); | 411 // GrContext::getMatrix() to know the transformation from local coords to de
vice space. |
| 412 GrContext::AutoRenderTarget art(context, NULL); |
| 413 GrContext::AutoClip ac(context, GrContext::AutoClip::kWideOpen_InitialClip); |
| 414 AutoMatrix am(context); |
| 392 | 415 |
| 393 // setup the shader as the first color effect on the paint | 416 // setup the shader as the first color effect on the paint |
| 394 SkAutoTUnref<GrEffectRef> effect(shader->asNewEffect(context, skPaint, NULL)
); | 417 SkAutoTUnref<GrEffectRef> effect(shader->asNewEffect(context, skPaint, NULL)
); |
| 395 if (NULL != effect.get()) { | 418 if (NULL != effect.get()) { |
| 396 grPaint->addColorEffect(effect); | 419 grPaint->addColorEffect(effect); |
| 397 // Now setup the rest of the paint. | 420 // Now setup the rest of the paint. |
| 398 SkPaint2GrPaintNoShader(context, skPaint, true, false, grPaint); | 421 SkPaint2GrPaintNoShader(context, skPaint, true, false, grPaint); |
| 399 } else { | 422 } else { |
| 400 // We still don't have SkColorShader::asNewEffect() implemented. | 423 // We still don't have SkColorShader::asNewEffect() implemented. |
| 401 SkShader::GradientInfo info; | 424 SkShader::GradientInfo info; |
| 402 SkColor color; | 425 SkColor color; |
| 403 | 426 |
| 404 info.fColors = &color; | 427 info.fColors = &color; |
| 405 info.fColorOffsets = NULL; | 428 info.fColorOffsets = NULL; |
| 406 info.fColorCount = 1; | 429 info.fColorCount = 1; |
| 407 if (SkShader::kColor_GradientType == shader->asAGradient(&info)) { | 430 if (SkShader::kColor_GradientType == shader->asAGradient(&info)) { |
| 408 SkPaint copy(skPaint); | 431 SkPaint copy(skPaint); |
| 409 copy.setShader(NULL); | 432 copy.setShader(NULL); |
| 410 // modulate the paint alpha by the shader's solid color alpha | 433 // modulate the paint alpha by the shader's solid color alpha |
| 411 U8CPU newA = SkMulDiv255Round(SkColorGetA(color), copy.getAlpha()); | 434 U8CPU newA = SkMulDiv255Round(SkColorGetA(color), copy.getAlpha()); |
| 412 copy.setColor(SkColorSetA(color, newA)); | 435 copy.setColor(SkColorSetA(color, newA)); |
| 413 SkPaint2GrPaintNoShader(context, copy, false, constantColor, grPaint
); | 436 SkPaint2GrPaintNoShader(context, copy, false, constantColor, grPaint
); |
| 414 } else { | 437 } else { |
| 415 SkPaint2GrPaintNoShader(context, skPaint, false, constantColor, grPa
int); | 438 SkPaint2GrPaintNoShader(context, skPaint, false, constantColor, grPa
int); |
| 416 } | 439 } |
| 417 } | 440 } |
| 418 } | 441 } |
| OLD | NEW |