aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gm/dither.cpp34
-rw-r--r--gn/gm.gni1
2 files changed, 35 insertions, 0 deletions
diff --git a/gm/dither.cpp b/gm/dither.cpp
new file mode 100644
index 0000000000..bdd52384eb
--- /dev/null
+++ b/gm/dither.cpp
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "gm.h"
+#include "SkSurface.h"
+#include "SkGradientShader.h"
+
+// This GM should make dithering somewhat visible when drawn into 565.
+
+DEF_SIMPLE_GM(dither, canvas, 256,256) {
+ // Create a compatible surface that's 8x8, as large as the largest dither pattern we use.
+ auto surface = canvas->makeSurface(canvas->imageInfo().makeWH(8,8));
+ if (!surface) {
+ surface = SkSurface::MakeRasterN32Premul(8,8);
+ }
+
+ // Draw a vertical red->green gradient.
+ SkPaint paint;
+ paint.setBlendMode(SkBlendMode::kSrc);
+ paint.setDither(true);
+ SkPoint pts[] = { {0,0}, {0,8} };
+ SkColor colors[] = { 0xffff0000, 0xff00ff00 };
+ paint.setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, 2,
+ SkShader::kClamp_TileMode));
+ surface->getCanvas()->drawPaint(paint);
+
+ // Snap that and draw with a 32x zoom.
+ canvas->scale(32,32);
+ canvas->drawImage(surface->makeImageSnapshot(), 0,0);
+}
diff --git a/gn/gm.gni b/gn/gm.gni
index 441c041e6f..27b92a9d83 100644
--- a/gn/gm.gni
+++ b/gn/gm.gni
@@ -102,6 +102,7 @@ gm_sources = [
"$_gm/discard.cpp",
"$_gm/displacement.cpp",
"$_gm/distantclip.cpp",
+ "$_gm/dither.cpp",
"$_gm/downsamplebitmap.cpp",
"$_gm/draw_bitmap_rect_skbug4374.cpp",
"$_gm/drawable.cpp",