bug6783.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  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. #include "gm/gm.h"
  8. #include "include/core/SkCanvas.h"
  9. #include "include/core/SkColor.h"
  10. #include "include/core/SkFilterQuality.h"
  11. #include "include/core/SkImage.h"
  12. #include "include/core/SkMatrix.h"
  13. #include "include/core/SkPaint.h"
  14. #include "include/core/SkRect.h"
  15. #include "include/core/SkRefCnt.h"
  16. #include "include/core/SkShader.h"
  17. #include "include/core/SkSurface.h"
  18. #include "include/core/SkTileMode.h"
  19. // This GM reproduces skia:6783, which demonstrated a bug in repeat and mirror
  20. // image sampling tiling modes as implemented in software. We want to tile to
  21. // [0,limit), and the old incorrect logic was:
  22. //
  23. // limit = ulp_before(limit)
  24. // val = val - floor(val/limit)*limit (This is repeat; mirror is similar.)
  25. //
  26. // while the correct logic is more like:
  27. //
  28. // val = val - floor(val/limit)*limit
  29. // val = min(val, ulp_before(limit))
  30. //
  31. // You would see ugly jaggies on the blue/yellow edge near the bottom left if
  32. // the bug were still present. All stripes should now look roughly the same.
  33. DEF_SIMPLE_GM(bug6783, canvas, 500, 500) {
  34. sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(100, 100);
  35. SkPaint p;
  36. p.setColor(SK_ColorYELLOW);
  37. surface->getCanvas()->drawPaint(p);
  38. p.setColor(SK_ColorBLUE);
  39. surface->getCanvas()->drawRect(SkRect::MakeWH(50, 100), p);
  40. sk_sp<SkImage> img = surface->makeImageSnapshot();
  41. SkMatrix m = SkMatrix::Concat(SkMatrix::MakeTrans(25, 214),
  42. SkMatrix::MakeScale(2, 2));
  43. m.preSkew(0.5f, 0.5f);
  44. // The bug was present at all filter levels, but you might not notice it at kNone.
  45. p.setFilterQuality(kLow_SkFilterQuality);
  46. // It's only important to repeat or mirror in x to show off the bug.
  47. p.setShader(img->makeShader(SkTileMode::kRepeat, SkTileMode::kClamp, &m));
  48. canvas->drawPaint(p);
  49. }