crbug_938592.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright 2019 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/SkPaint.h"
  11. #include "include/core/SkPoint.h"
  12. #include "include/core/SkScalar.h"
  13. #include "include/core/SkShader.h"
  14. #include "include/core/SkTileMode.h"
  15. #include "include/effects/SkGradientShader.h"
  16. // This draws a hard stop gradient applied to a rectangle. The hard stops fall at half pixel
  17. // boundaries in y. On some GPUs we've found that the winding of the two triangles that make up the
  18. // rectangle can affect whether the interpolants for local coords wind up agreeing across a row.
  19. // When they disagree the hard stop gradient appears jagged. We draw the rectangle four times:
  20. // no-mirroring, mirror in x, mirror in y, and mirror in x and y.
  21. DEF_SIMPLE_GM(crbug_938592, canvas, 500, 300) {
  22. static constexpr SkPoint pts[] = {{0, 0}, {0, 30}};
  23. static constexpr SkScalar pos[] = {0.f, 9.f / 20, 9.f / 20, 11.f / 20, 11.f / 20, 20.f / 20};
  24. static constexpr SkColor c0 = SK_ColorBLUE;
  25. static constexpr SkColor c1 = SK_ColorRED;
  26. static constexpr SkColor c2 = SK_ColorGREEN;
  27. static constexpr SkColor colors[] = {c0, c0, c1, c1, c2, c2};
  28. auto grad = SkGradientShader::MakeLinear(pts, colors, pos, 6, SkTileMode::kClamp);
  29. SkPaint paint;
  30. paint.setShader(grad);
  31. static constexpr int kMirrorX = 400;
  32. static constexpr int kMirrorY = 200;
  33. canvas->translate(50, 50);
  34. for (int i = 0; i < 4; ++i) {
  35. canvas->save();
  36. if (i & 0b01) {
  37. canvas->translate(0, kMirrorY);
  38. canvas->scale(1.f, -1.f);
  39. }
  40. if (i & 0b10) {
  41. canvas->translate(kMirrorX, 0);
  42. canvas->scale(-1.f, 1.f);
  43. }
  44. canvas->drawRect({0, 0, 150, 30}, paint);
  45. canvas->restore();
  46. }
  47. }