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" |
| 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 if (NULL == target) { | |
|
bsalomon
2014/06/12 16:24:11
I'd like to understand how this happens. Falling b
| |
| 470 target = context->getGpu()->getDrawState().getRenderTarget(); | |
| 471 } | |
| 472 | |
| 473 if (NULL != target && | |
| 474 (target->config() == kRGBA_8888_GrPixelConfig || | |
| 475 target->config() == kBGRA_8888_GrPixelConfig)) { | |
| 476 // The dither flag is set and the target is likely | |
| 477 // not going to be dithered by the GPU. | |
| 478 SkAutoTUnref<GrEffectRef> effect(GrDitherEffect::Create()); | |
| 479 if (NULL != effect.get()) { | |
| 480 grPaint->addColorEffect(effect); | |
| 481 grPaint->setDither(false); | |
| 482 } | |
| 483 } | |
| 484 } | |
| 485 #endif | |
| 461 } | 486 } |
| 462 | 487 |
| 463 /** | 488 /** |
| 464 * Unlike GrContext::AutoMatrix, this doesn't require setting a new matrix. GrCo ntext::AutoMatrix | 489 * 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 | 490 * 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. | 491 * update a GrPaint. This AutoMatrix is used while initially setting up GrPaint, however. |
| 467 */ | 492 */ |
| 468 class AutoMatrix { | 493 class AutoMatrix { |
| 469 public: | 494 public: |
| 470 AutoMatrix(GrContext* context) { | 495 AutoMatrix(GrContext* context) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 502 GrEffectRef* grEffect = NULL; | 527 GrEffectRef* grEffect = NULL; |
| 503 if (shader->asNewEffect(context, skPaint, NULL, &grColor, &grEffect) && NULL != grEffect) { | 528 if (shader->asNewEffect(context, skPaint, NULL, &grColor, &grEffect) && NULL != grEffect) { |
| 504 SkAutoTUnref<GrEffectRef> effect(grEffect); | 529 SkAutoTUnref<GrEffectRef> effect(grEffect); |
| 505 grPaint->addColorEffect(effect); | 530 grPaint->addColorEffect(effect); |
| 506 constantColor = false; | 531 constantColor = false; |
| 507 } | 532 } |
| 508 // The grcolor is automatically set when calling asneweffect. | 533 // 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. | 534 // 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); | 535 SkPaint2GrPaintNoShader(context, skPaint, grColor, constantColor, grPaint); |
| 511 } | 536 } |
| OLD | NEW |