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