skia2/gm/bug6783.cpp
Mike Klein c0bd9f9fe5 rewrite includes to not need so much -Ifoo
Current strategy: everything from the top

Things to look at first are the manual changes:

   - added tools/rewrite_includes.py
   - removed -Idirectives from BUILD.gn
   - various compile.sh simplifications
   - tweak tools/embed_resources.py
   - update gn/find_headers.py to write paths from the top
   - update gn/gn_to_bp.py SkUserConfig.h layout
     so that #include "include/config/SkUserConfig.h" always
     gets the header we want.

No-Presubmit: true
Change-Id: I73a4b181654e0e38d229bc456c0d0854bae3363e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/209706
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Hal Canary <halcanary@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
2019-04-24 16:27:11 +00:00

48 lines
1.6 KiB
C++

/*
* 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/gm.h"
#include "include/core/SkSurface.h"
// This GM reproduces skia:6783, which demonstrated a bug in repeat and mirror
// image sampling tiling modes as implemented in software. We want to tile to
// [0,limit), and the old incorrect logic was:
//
// limit = ulp_before(limit)
// val = val - floor(val/limit)*limit (This is repeat; mirror is similar.)
//
// while the correct logic is more like:
//
// val = val - floor(val/limit)*limit
// val = min(val, ulp_before(limit))
//
// You would see ugly jaggies on the blue/yellow edge near the bottom left if
// the bug were still present. All stripes should now look roughly the same.
DEF_SIMPLE_GM(bug6783, canvas, 500, 500) {
sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(100, 100);
SkPaint p;
p.setColor(SK_ColorYELLOW);
surface->getCanvas()->drawPaint(p);
p.setColor(SK_ColorBLUE);
surface->getCanvas()->drawRect(SkRect::MakeWH(50, 100), p);
sk_sp<SkImage> img = surface->makeImageSnapshot();
SkMatrix m = SkMatrix::Concat(SkMatrix::MakeTrans(25, 214),
SkMatrix::MakeScale(2, 2));
m.preSkew(0.5f, 0.5f);
// The bug was present at all filter levels, but you might not notice it at kNone.
p.setFilterQuality(kLow_SkFilterQuality);
// It's only important to repeat or mirror in x to show off the bug.
p.setShader(img->makeShader(SkTileMode::kRepeat, SkTileMode::kClamp, &m));
canvas->drawPaint(p);
}