aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Reck <jreck@google.com>2023-04-05 13:57:59 -0400
committerSkCQ <skcq-be@skia-corp.google.com.iam.gserviceaccount.com>2023-04-05 18:59:09 +0000
commite89ff8d458496ca5cafd633f74708a34a76de0af (patch)
tree6daf406c231dd0bbb4d86e9e4d1babe91b0d3c6e
parent430a04c92e06c21b57d84466c4e37ad19c11908b (diff)
downloadskia-e89ff8d458496ca5cafd633f74708a34a76de0af.tar.gz
Add always dither SkSurfaceProps flag
Allows an SkSurface to be configured to always dither such as when rendering to restricted bit depths for the desired colorspace Bug: skia:14238 Change-Id: Ie63dda58b1e13d8a7dd6d22771ca3525e1508e4e Reviewed-on: https://skia-review.googlesource.com/c/skia/+/666861 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: John Reck <jreck@google.com>
-rw-r--r--include/core/SkSurfaceProps.h9
-rw-r--r--src/gpu/ganesh/SkGr.cpp4
2 files changed, 11 insertions, 2 deletions
diff --git a/include/core/SkSurfaceProps.h b/include/core/SkSurfaceProps.h
index 357af25dec..4790f258e4 100644
--- a/include/core/SkSurfaceProps.h
+++ b/include/core/SkSurfaceProps.h
@@ -54,7 +54,10 @@ public:
enum Flags {
kUseDeviceIndependentFonts_Flag = 1 << 0,
// Use internal MSAA to render to non-MSAA GPU surfaces.
- kDynamicMSAA_Flag = 1 << 1
+ kDynamicMSAA_Flag = 1 << 1,
+ // If set, all rendering will have dithering enabled
+ // Currently this only impacts GPU backends
+ kAlwaysDither_Flag = 1 << 2,
};
/** Deprecated alias used by Chromium. Will be removed. */
static const Flags kUseDistanceFieldFonts_Flag = kUseDeviceIndependentFonts_Flag;
@@ -77,6 +80,10 @@ public:
return SkToBool(fFlags & kUseDeviceIndependentFonts_Flag);
}
+ bool isAlwaysDither() const {
+ return SkToBool(fFlags & kAlwaysDither_Flag);
+ }
+
bool operator==(const SkSurfaceProps& that) const {
return fFlags == that.fFlags && fPixelGeometry == that.fPixelGeometry;
}
diff --git a/src/gpu/ganesh/SkGr.cpp b/src/gpu/ganesh/SkGr.cpp
index 22c91e8a34..dba4075915 100644
--- a/src/gpu/ganesh/SkGr.cpp
+++ b/src/gpu/ganesh/SkGr.cpp
@@ -18,6 +18,7 @@
#include "include/core/SkPoint.h"
#include "include/core/SkRect.h"
#include "include/core/SkSize.h"
+#include "include/core/SkSurfaceProps.h"
#include "include/effects/SkRuntimeEffect.h"
#include "include/gpu/GrBackendSurface.h"
#include "include/gpu/GrRecordingContext.h"
@@ -565,7 +566,8 @@ static inline bool skpaint_to_grpaint_impl(
#ifndef SK_IGNORE_GPU_DITHER
GrColorType ct = dstColorInfo.colorType();
- if (SkPaintPriv::ShouldDither(skPaint, GrColorTypeToSkColorType(ct)) && paintFP != nullptr) {
+ if (paintFP != nullptr && (
+ surfaceProps.isAlwaysDither() || SkPaintPriv::ShouldDither(skPaint, GrColorTypeToSkColorType(ct)))) {
float ditherRange = dither_range_for_config(ct);
paintFP = make_dither_effect(
context, std::move(paintFP), ditherRange, context->priv().caps());