blob: 5b54e1ce6a2e00dfbce91a462c75527b0902429e [file] [log] [blame]
Mike Klein0cc60b82017-06-22 11:00:17 -07001/*
2* Copyright 2017 Google Inc.
3*
4* Use of this source code is governed by a BSD-style license that can be
5* found in the LICENSE file.
6*/
7
8#include "gm.h"
9#include "SkSurface.h"
10
11// This GM reproduces skia:6783, which demonstrated a bug in repeat and mirror
12// image sampling tiling modes as implemented in software. We want to tile to
13// [0,limit), and the old incorrect logic was:
14//
15// limit = ulp_before(limit)
16// val = val - floor(val/limit)*limit (This is repeat; mirror is similar.)
17//
18// while the correct logic is more like:
19//
20// val = val - floor(val/limit)*limit
21// val = min(val, ulp_before(limit))
22//
23// You would see ugly jaggies on the blue/yellow edge near the bottom left if
24// the bug were still present. All stripes should now look roughly the same.
25
26DEF_SIMPLE_GM(bug6783, canvas, 500, 500) {
27 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(100, 100);
28
29 SkPaint p;
30 p.setColor(SK_ColorYELLOW);
31 surface->getCanvas()->drawPaint(p);
32 p.setColor(SK_ColorBLUE);
33 surface->getCanvas()->drawRect(SkRect::MakeWH(50, 100), p);
34
35 sk_sp<SkImage> img = surface->makeImageSnapshot();
36
37 SkMatrix m = SkMatrix::Concat(SkMatrix::MakeTrans(25, 214),
38 SkMatrix::MakeScale(2, 2));
39 m.preSkew(0.5f, 0.5f);
40
41 // The bug was present at all filter levels, but you might not notice it at kNone.
42 p.setFilterQuality(kLow_SkFilterQuality);
43
44 // It's only important to repeat or mirror in x to show off the bug.
45 p.setShader(img->makeShader(SkShader::kRepeat_TileMode, SkShader::kClamp_TileMode, &m));
46 canvas->drawPaint(p);
47}