2017-06-22 18:00:17 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
2019-05-01 14:59:30 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkImage.h"
|
|
|
|
#include "include/core/SkMatrix.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkShader.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkSurface.h"
|
2019-05-01 14:59:30 +00:00
|
|
|
#include "include/core/SkTileMode.h"
|
2017-06-22 18:00:17 +00:00
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
2020-05-21 16:11:27 +00:00
|
|
|
SkMatrix m = SkMatrix::Translate(25, 214) * SkMatrix::Scale(2, 2);
|
2017-06-22 18:00:17 +00:00
|
|
|
m.preSkew(0.5f, 0.5f);
|
|
|
|
|
2020-12-08 18:16:56 +00:00
|
|
|
// The bug was present at all filter levels, but you might not notice it at nearest.
|
2021-01-15 02:59:01 +00:00
|
|
|
SkSamplingOptions sampling(SkFilterMode::kLinear);
|
2017-06-22 18:00:17 +00:00
|
|
|
|
|
|
|
// It's only important to repeat or mirror in x to show off the bug.
|
2020-12-08 18:16:56 +00:00
|
|
|
p.setShader(img->makeShader(SkTileMode::kRepeat, SkTileMode::kClamp, sampling, m));
|
2017-06-22 18:00:17 +00:00
|
|
|
canvas->drawPaint(p);
|
|
|
|
}
|