aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Florin Malita <fmalita@chromium.org>2017-06-19 10:21:43 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-06-19 14:59:38 +0000
commitd4a70ee36717493cc071f878b16b037463e6ce9a (patch)
tree91ee41cf719bb3e63cea243aecea2bc73a8a1c83 /src
parent0bdaf05fc17ebe5d4ad01d70c80df2425e83c737 (diff)
Disable dithering of const paints
... except for 565. Change-Id: I8ab633661c54583478234a46942ef804eb74a619 Reviewed-on: https://skia-review.googlesource.com/19880 Commit-Queue: Florin Malita <fmalita@chromium.org> Reviewed-by: Mike Klein <mtklein@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com> Reviewed-by: Mike Reed <reed@google.com> Reviewed-by: Herb Derby <herb@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/core/SkBlitter.cpp6
-rw-r--r--src/core/SkPaintPriv.cpp21
-rw-r--r--src/core/SkPaintPriv.h2
-rw-r--r--src/gpu/SkGr.cpp7
4 files changed, 34 insertions, 2 deletions
diff --git a/src/core/SkBlitter.cpp b/src/core/SkBlitter.cpp
index 81e261d9a4..b1caaf585d 100644
--- a/src/core/SkBlitter.cpp
+++ b/src/core/SkBlitter.cpp
@@ -14,6 +14,7 @@
#include "SkWriteBuffer.h"
#include "SkMask.h"
#include "SkMaskFilter.h"
+#include "SkPaintPriv.h"
#include "SkShaderBase.h"
#include "SkString.h"
#include "SkTLazy.h"
@@ -867,6 +868,11 @@ SkBlitter* SkBlitter::Choose(const SkPixmap& device,
return alloc->make<SkA8_Coverage_Blitter>(device, *paint);
}
+ if (paint->isDither() && !SkPaintPriv::ShouldDither(*paint, device.colorType())) {
+ // Disable dithering when not needed.
+ paint.writable()->setDither(false);
+ }
+
if (UseRasterPipelineBlitter(device, *paint)) {
auto blitter = SkCreateRasterPipelineBlitter(device, *paint, matrix, alloc);
SkASSERT(blitter);
diff --git a/src/core/SkPaintPriv.cpp b/src/core/SkPaintPriv.cpp
index 7dfb2e30ff..b37c28655d 100644
--- a/src/core/SkPaintPriv.cpp
+++ b/src/core/SkPaintPriv.cpp
@@ -10,7 +10,7 @@
#include "SkPaintPriv.h"
#include "SkImage.h"
#include "SkPaint.h"
-#include "SkShader.h"
+#include "SkShaderBase.h"
#include "SkXfermodePriv.h"
static bool changes_alpha(const SkPaint& paint) {
@@ -69,3 +69,22 @@ void SkPaintPriv::ScaleFontMetrics(SkPaint::FontMetrics* metrics, SkScalar scale
metrics->fUnderlinePosition *= scale;
}
+bool SkPaintPriv::ShouldDither(const SkPaint& p, SkColorType dstCT) {
+ // The paint dither flag can veto.
+ if (!p.isDither()) {
+ return false;
+ }
+
+#ifndef SK_SUPPORT_LEGACY_DITHERING
+ // We always dither 565 when requested.
+ if (dstCT == SkColorType::kRGB_565_SkColorType) {
+ return true;
+ }
+
+ // Otherwise, dither is only needed for non-const paints.
+ return p.getImageFilter() || p.getMaskFilter()
+ || !p.getShader() || !as_SB(p.getShader())->isConstant();
+#else
+ return true;
+#endif
+}
diff --git a/src/core/SkPaintPriv.h b/src/core/SkPaintPriv.h
index e5c98f5e1a..663ed2d836 100644
--- a/src/core/SkPaintPriv.h
+++ b/src/core/SkPaintPriv.h
@@ -8,6 +8,7 @@
#ifndef SkPaintPriv_DEFINED
#define SkPaintPriv_DEFINED
+#include "SkImageInfo.h"
#include "SkPaint.h"
#include "SkMatrix.h"
@@ -62,6 +63,7 @@ public:
MakeTextMatrix(matrix, paint.getTextSize(), paint.getTextScaleX(), paint.getTextSkewX());
}
+ static bool ShouldDither(const SkPaint&, SkColorType);
};
#endif
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index 8b54aaa780..9adcb1a9ec 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -28,6 +28,7 @@
#include "SkMessageBus.h"
#include "SkMipMap.h"
#include "SkPM4fPriv.h"
+#include "SkPaintPriv.h"
#include "SkPixelRef.h"
#include "SkResourceCache.h"
#include "SkShaderBase.h"
@@ -542,7 +543,11 @@ static inline bool skpaint_to_grpaint_impl(GrContext* context,
}
#ifndef SK_IGNORE_GPU_DITHER
- if (skPaint.isDither() && grPaint->numColorFragmentProcessors() > 0 && !rtc->isGammaCorrect()) {
+ // Conservative default, in case GrPixelConfigToColorType() fails.
+ SkColorType ct = SkColorType::kRGB_565_SkColorType;
+ GrPixelConfigToColorType(rtc->config(), &ct);
+ if (SkPaintPriv::ShouldDither(skPaint, ct) && grPaint->numColorFragmentProcessors() > 0
+ && !rtc->isGammaCorrect()) {
grPaint->addColorFragmentProcessor(GrDitherEffect::Make());
}
#endif