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" |
11 #include "SkData.h" | 11 #include "SkData.h" |
12 #include "SkMessageBus.h" | 12 #include "SkMessageBus.h" |
13 #include "SkPixelRef.h" | 13 #include "SkPixelRef.h" |
14 #include "GrResourceCache.h" | 14 #include "GrResourceCache.h" |
15 #include "GrGpu.h" | 15 #include "GrGpu.h" |
| 16 #include "effects/GrDitherEffect.h" |
16 #include "GrDrawTargetCaps.h" | 17 #include "GrDrawTargetCaps.h" |
17 | 18 |
18 #ifndef SK_IGNORE_ETC1_SUPPORT | 19 #ifndef SK_IGNORE_ETC1_SUPPORT |
19 # include "ktx.h" | 20 # include "ktx.h" |
20 # include "etc1.h" | 21 # include "etc1.h" |
21 #endif | 22 #endif |
22 | 23 |
23 /* Fill out buffer with the compressed format Ganesh expects from a colortable | 24 /* Fill out buffer with the compressed format Ganesh expects from a colortable |
24 based bitmap. [palette (colortable) + indices]. | 25 based bitmap. [palette (colortable) + indices]. |
25 | 26 |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 if (constantColor) { | 452 if (constantColor) { |
452 SkColor filtered = colorFilter->filterColor(skPaint.getColor()); | 453 SkColor filtered = colorFilter->filterColor(skPaint.getColor()); |
453 grPaint->setColor(SkColor2GrColor(filtered)); | 454 grPaint->setColor(SkColor2GrColor(filtered)); |
454 } else { | 455 } else { |
455 SkAutoTUnref<GrEffectRef> effect(colorFilter->asNewEffect(context)); | 456 SkAutoTUnref<GrEffectRef> effect(colorFilter->asNewEffect(context)); |
456 if (NULL != effect.get()) { | 457 if (NULL != effect.get()) { |
457 grPaint->addColorEffect(effect); | 458 grPaint->addColorEffect(effect); |
458 } | 459 } |
459 } | 460 } |
460 } | 461 } |
| 462 |
| 463 #ifndef SK_IGNORE_GPU_DITHER |
| 464 // If the dither flag is set, then we need to see if the underlying context |
| 465 // supports it. If not, then install a dither effect. |
| 466 if (skPaint.isDither()) { |
| 467 // What are we rendering into? |
| 468 const GrRenderTarget *target = context->getRenderTarget(); |
| 469 SkASSERT(NULL != target); |
| 470 |
| 471 // Suspect the dithering flag has no effect on these configs, otherwise |
| 472 // fall back on setting the appropriate state. |
| 473 if (target->config() == kRGBA_8888_GrPixelConfig || |
| 474 target->config() == kBGRA_8888_GrPixelConfig) { |
| 475 // The dither flag is set and the target is likely |
| 476 // not going to be dithered by the GPU. |
| 477 SkAutoTUnref<GrEffectRef> effect(GrDitherEffect::Create()); |
| 478 if (NULL != effect.get()) { |
| 479 grPaint->addColorEffect(effect); |
| 480 grPaint->setDither(false); |
| 481 } |
| 482 } |
| 483 } |
| 484 #endif |
461 } | 485 } |
462 | 486 |
463 /** | 487 /** |
464 * Unlike GrContext::AutoMatrix, this doesn't require setting a new matrix. GrCo
ntext::AutoMatrix | 488 * Unlike GrContext::AutoMatrix, this doesn't require setting a new matrix. GrCo
ntext::AutoMatrix |
465 * likes to set the new matrix in its constructor because it is usually necessar
y to simulataneously | 489 * likes to set the new matrix in its constructor because it is usually necessar
y to simulataneously |
466 * update a GrPaint. This AutoMatrix is used while initially setting up GrPaint,
however. | 490 * update a GrPaint. This AutoMatrix is used while initially setting up GrPaint,
however. |
467 */ | 491 */ |
468 class AutoMatrix { | 492 class AutoMatrix { |
469 public: | 493 public: |
470 AutoMatrix(GrContext* context) { | 494 AutoMatrix(GrContext* context) { |
(...skipping 14 matching lines...) Expand all Loading... |
485 SkShader* shader = skPaint.getShader(); | 509 SkShader* shader = skPaint.getShader(); |
486 if (NULL == shader) { | 510 if (NULL == shader) { |
487 SkPaint2GrPaintNoShader(context, skPaint, SkColor2GrColor(skPaint.getCol
or()), | 511 SkPaint2GrPaintNoShader(context, skPaint, SkColor2GrColor(skPaint.getCol
or()), |
488 constantColor, grPaint); | 512 constantColor, grPaint); |
489 return; | 513 return; |
490 } | 514 } |
491 | 515 |
492 // SkShader::asNewEffect() may do offscreen rendering. Save off the current
RT, clip, and | 516 // SkShader::asNewEffect() may do offscreen rendering. Save off the current
RT, clip, and |
493 // matrix. We don't reset the matrix on the context because SkShader::asNewE
ffect may use | 517 // matrix. We don't reset the matrix on the context because SkShader::asNewE
ffect may use |
494 // GrContext::getMatrix() to know the transformation from local coords to de
vice space. | 518 // GrContext::getMatrix() to know the transformation from local coords to de
vice space. |
495 GrContext::AutoRenderTarget art(context, NULL); | 519 GrColor grColor = SkColor2GrColor(skPaint.getColor()); |
496 GrContext::AutoClip ac(context, GrContext::AutoClip::kWideOpen_InitialClip); | 520 { |
497 AutoMatrix am(context); | 521 GrContext::AutoRenderTarget art(context, NULL); |
| 522 GrContext::AutoClip ac(context, GrContext::AutoClip::kWideOpen_InitialCl
ip); |
| 523 AutoMatrix am(context); |
498 | 524 |
499 // setup the shader as the first color effect on the paint | 525 // setup the shader as the first color effect on the paint |
500 // the default grColor is the paint's color | 526 // the default grColor is the paint's color |
501 GrColor grColor = SkColor2GrColor(skPaint.getColor()); | 527 GrEffectRef* grEffect = NULL; |
502 GrEffectRef* grEffect = NULL; | 528 if (shader->asNewEffect(context, skPaint, NULL, &grColor, &grEffect) &&
NULL != grEffect) { |
503 if (shader->asNewEffect(context, skPaint, NULL, &grColor, &grEffect) && NULL
!= grEffect) { | 529 SkAutoTUnref<GrEffectRef> effect(grEffect); |
504 SkAutoTUnref<GrEffectRef> effect(grEffect); | 530 grPaint->addColorEffect(effect); |
505 grPaint->addColorEffect(effect); | 531 constantColor = false; |
506 constantColor = false; | 532 } |
507 } | 533 } |
| 534 |
508 // The grcolor is automatically set when calling asneweffect. | 535 // The grcolor is automatically set when calling asneweffect. |
509 // If the shader can be seen as an effect it returns true and adds its effec
t to the grpaint. | 536 // If the shader can be seen as an effect it returns true and adds its effec
t to the grpaint. |
510 SkPaint2GrPaintNoShader(context, skPaint, grColor, constantColor, grPaint); | 537 SkPaint2GrPaintNoShader(context, skPaint, grColor, constantColor, grPaint); |
511 } | 538 } |
OLD | NEW |