Chromium Code Reviews| 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 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 370 SkColor filtered = colorFilter->filterColor(skPaint.getColor()); | 370 SkColor filtered = colorFilter->filterColor(skPaint.getColor()); |
| 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 |
|
robertphillips
2014/05/20 14:36:16
Should this be in GrContext like the other two?
| |
| 381 class AutoMatrix { | |
| 382 public: | |
| 383 AutoMatrix(GrContext* context) { | |
| 384 fMatrix = context->getMatrix(); | |
| 385 fContext = context; | |
| 386 } | |
| 387 ~AutoMatrix() { | |
|
robertphillips
2014/05/20 14:36:16
Don't we usually have a "if (NULL != fContext)" gu
| |
| 388 fContext->setMatrix(fMatrix); | |
| 389 } | |
| 390 private: | |
| 391 GrContext* fContext; | |
| 392 SkMatrix fMatrix; | |
| 393 }; | |
| 394 | |
| 381 void SkPaint2GrPaintShader(GrContext* context, const SkPaint& skPaint, | 395 void SkPaint2GrPaintShader(GrContext* context, const SkPaint& skPaint, |
| 382 bool constantColor, GrPaint* grPaint) { | 396 bool constantColor, GrPaint* grPaint) { |
| 383 SkShader* shader = skPaint.getShader(); | 397 SkShader* shader = skPaint.getShader(); |
| 384 if (NULL == shader) { | 398 if (NULL == shader) { |
| 385 SkPaint2GrPaintNoShader(context, skPaint, false, constantColor, grPaint) ; | 399 SkPaint2GrPaintNoShader(context, skPaint, false, constantColor, grPaint) ; |
| 386 return; | 400 return; |
| 387 } | 401 } |
| 388 | 402 |
| 389 // SkShader::asNewEffect() may do offscreen rendering. Setup default drawing state and require | 403 // SkShader::asNewEffect() may do offscreen rendering. Save off the current RT, clip, and |
| 390 // the shader to set a render target. | 404 // matrix. We don't reset the matrix on the context because SkShader::asNewE ffect may use |
| 391 GrContext::AutoWideOpenIdentityDraw awo(context, NULL); | 405 // GrContext::getMatrix() to know the transformation from local coords to de vice space. |
| 406 GrContext::AutoRenderTarget art(context, NULL); | |
| 407 GrContext::AutoClip ac(context, GrContext::AutoClip::kWideOpen_InitialClip); | |
| 408 AutoMatrix am(context); | |
| 392 | 409 |
| 393 // setup the shader as the first color effect on the paint | 410 // setup the shader as the first color effect on the paint |
| 394 SkAutoTUnref<GrEffectRef> effect(shader->asNewEffect(context, skPaint, NULL) ); | 411 SkAutoTUnref<GrEffectRef> effect(shader->asNewEffect(context, skPaint, NULL) ); |
| 395 if (NULL != effect.get()) { | 412 if (NULL != effect.get()) { |
| 396 grPaint->addColorEffect(effect); | 413 grPaint->addColorEffect(effect); |
| 397 // Now setup the rest of the paint. | 414 // Now setup the rest of the paint. |
| 398 SkPaint2GrPaintNoShader(context, skPaint, true, false, grPaint); | 415 SkPaint2GrPaintNoShader(context, skPaint, true, false, grPaint); |
| 399 } else { | 416 } else { |
| 400 // We still don't have SkColorShader::asNewEffect() implemented. | 417 // We still don't have SkColorShader::asNewEffect() implemented. |
| 401 SkShader::GradientInfo info; | 418 SkShader::GradientInfo info; |
| 402 SkColor color; | 419 SkColor color; |
| 403 | 420 |
| 404 info.fColors = &color; | 421 info.fColors = &color; |
| 405 info.fColorOffsets = NULL; | 422 info.fColorOffsets = NULL; |
| 406 info.fColorCount = 1; | 423 info.fColorCount = 1; |
| 407 if (SkShader::kColor_GradientType == shader->asAGradient(&info)) { | 424 if (SkShader::kColor_GradientType == shader->asAGradient(&info)) { |
| 408 SkPaint copy(skPaint); | 425 SkPaint copy(skPaint); |
| 409 copy.setShader(NULL); | 426 copy.setShader(NULL); |
| 410 // modulate the paint alpha by the shader's solid color alpha | 427 // modulate the paint alpha by the shader's solid color alpha |
| 411 U8CPU newA = SkMulDiv255Round(SkColorGetA(color), copy.getAlpha()); | 428 U8CPU newA = SkMulDiv255Round(SkColorGetA(color), copy.getAlpha()); |
| 412 copy.setColor(SkColorSetA(color, newA)); | 429 copy.setColor(SkColorSetA(color, newA)); |
| 413 SkPaint2GrPaintNoShader(context, copy, false, constantColor, grPaint ); | 430 SkPaint2GrPaintNoShader(context, copy, false, constantColor, grPaint ); |
| 414 } else { | 431 } else { |
| 415 SkPaint2GrPaintNoShader(context, skPaint, false, constantColor, grPa int); | 432 SkPaint2GrPaintNoShader(context, skPaint, false, constantColor, grPa int); |
| 416 } | 433 } |
| 417 } | 434 } |
| 418 } | 435 } |
| OLD | NEW |