Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(226)

Side by Side Diff: src/gpu/SkGr.cpp

Issue 321253002: Simple GPU based dithering (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Sync to head Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gyp/skia_for_chromium_defines.gypi ('k') | src/gpu/effects/GrDitherEffect.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 if (constantColor) { 454 if (constantColor) {
454 SkColor filtered = colorFilter->filterColor(skPaint.getColor()); 455 SkColor filtered = colorFilter->filterColor(skPaint.getColor());
455 grPaint->setColor(SkColor2GrColor(filtered)); 456 grPaint->setColor(SkColor2GrColor(filtered));
456 } else { 457 } else {
457 SkAutoTUnref<GrEffectRef> effect(colorFilter->asNewEffect(context)); 458 SkAutoTUnref<GrEffectRef> effect(colorFilter->asNewEffect(context));
458 if (NULL != effect.get()) { 459 if (NULL != effect.get()) {
459 grPaint->addColorEffect(effect); 460 grPaint->addColorEffect(effect);
460 } 461 }
461 } 462 }
462 } 463 }
464
465 #ifndef SK_IGNORE_GPU_DITHER
466 // If the dither flag is set, then we need to see if the underlying context
467 // supports it. If not, then install a dither effect.
468 if (skPaint.isDither() && grPaint->numColorStages() > 0) {
469 // What are we rendering into?
470 const GrRenderTarget *target = context->getRenderTarget();
471 SkASSERT(NULL != target);
472
473 // Suspect the dithering flag has no effect on these configs, otherwise
474 // fall back on setting the appropriate state.
475 if (target->config() == kRGBA_8888_GrPixelConfig ||
476 target->config() == kBGRA_8888_GrPixelConfig) {
477 // The dither flag is set and the target is likely
478 // not going to be dithered by the GPU.
479 SkAutoTUnref<GrEffectRef> effect(GrDitherEffect::Create());
480 if (NULL != effect.get()) {
481 grPaint->addColorEffect(effect);
482 grPaint->setDither(false);
483 }
484 }
485 }
486 #endif
463 } 487 }
464 488
465 /** 489 /**
466 * Unlike GrContext::AutoMatrix, this doesn't require setting a new matrix. GrCo ntext::AutoMatrix 490 * Unlike GrContext::AutoMatrix, this doesn't require setting a new matrix. GrCo ntext::AutoMatrix
467 * likes to set the new matrix in its constructor because it is usually necessar y to simulataneously 491 * likes to set the new matrix in its constructor because it is usually necessar y to simulataneously
468 * update a GrPaint. This AutoMatrix is used while initially setting up GrPaint, however. 492 * update a GrPaint. This AutoMatrix is used while initially setting up GrPaint, however.
469 */ 493 */
470 class AutoMatrix { 494 class AutoMatrix {
471 public: 495 public:
472 AutoMatrix(GrContext* context) { 496 AutoMatrix(GrContext* context) {
(...skipping 14 matching lines...) Expand all
487 SkShader* shader = skPaint.getShader(); 511 SkShader* shader = skPaint.getShader();
488 if (NULL == shader) { 512 if (NULL == shader) {
489 SkPaint2GrPaintNoShader(context, skPaint, SkColor2GrColor(skPaint.getCol or()), 513 SkPaint2GrPaintNoShader(context, skPaint, SkColor2GrColor(skPaint.getCol or()),
490 constantColor, grPaint); 514 constantColor, grPaint);
491 return; 515 return;
492 } 516 }
493 517
494 // SkShader::asNewEffect() may do offscreen rendering. Save off the current RT, clip, and 518 // SkShader::asNewEffect() may do offscreen rendering. Save off the current RT, clip, and
495 // matrix. We don't reset the matrix on the context because SkShader::asNewE ffect may use 519 // matrix. We don't reset the matrix on the context because SkShader::asNewE ffect may use
496 // GrContext::getMatrix() to know the transformation from local coords to de vice space. 520 // GrContext::getMatrix() to know the transformation from local coords to de vice space.
497 GrContext::AutoRenderTarget art(context, NULL); 521 GrColor grColor = SkColor2GrColor(skPaint.getColor());
498 GrContext::AutoClip ac(context, GrContext::AutoClip::kWideOpen_InitialClip);
499 AutoMatrix am(context);
500 522
501 // setup the shader as the first color effect on the paint 523 // Start a new block here in order to preserve our context state after calli ng
502 // the default grColor is the paint's color 524 // asNewEffect(). Since these calls get passed back to the client, we don't really
503 GrColor grColor = SkColor2GrColor(skPaint.getColor()); 525 // want them messing around with the context.
504 GrEffectRef* grEffect = NULL; 526 {
505 if (shader->asNewEffect(context, skPaint, NULL, &grColor, &grEffect) && NULL != grEffect) { 527 GrContext::AutoRenderTarget art(context, NULL);
506 SkAutoTUnref<GrEffectRef> effect(grEffect); 528 GrContext::AutoClip ac(context, GrContext::AutoClip::kWideOpen_InitialCl ip);
507 grPaint->addColorEffect(effect); 529 AutoMatrix am(context);
508 constantColor = false; 530
531 // setup the shader as the first color effect on the paint
532 // the default grColor is the paint's color
533 GrEffectRef* grEffect = NULL;
534 if (shader->asNewEffect(context, skPaint, NULL, &grColor, &grEffect) && NULL != grEffect) {
535 SkAutoTUnref<GrEffectRef> effect(grEffect);
536 grPaint->addColorEffect(effect);
537 constantColor = false;
538 }
509 } 539 }
540
510 // The grcolor is automatically set when calling asneweffect. 541 // The grcolor is automatically set when calling asneweffect.
511 // If the shader can be seen as an effect it returns true and adds its effec t to the grpaint. 542 // If the shader can be seen as an effect it returns true and adds its effec t to the grpaint.
512 SkPaint2GrPaintNoShader(context, skPaint, grColor, constantColor, grPaint); 543 SkPaint2GrPaintNoShader(context, skPaint, grColor, constantColor, grPaint);
513 } 544 }
OLDNEW
« no previous file with comments | « gyp/skia_for_chromium_defines.gypi ('k') | src/gpu/effects/GrDitherEffect.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698