add a GM to demo dither

Change-Id: Idbed35f2c5a1420b66b68725761a7ceea8cdd3ba
Reviewed-on: https://skia-review.googlesource.com/66461
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Mike Klein <mtklein@chromium.org>
This commit is contained in:
Mike Klein 2017-11-01 17:07:01 -04:00 committed by Skia Commit-Bot
parent b718fbb7f4
commit 2afe7873d8
2 changed files with 35 additions and 0 deletions

34
gm/dither.cpp Normal file
View File

@ -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);
}

View File

@ -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",