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