skia2/gm/crbug_938592.cpp
Mike Reed fae8fceb4a Use SkTileMode instead of nested enum
Add guard to transition clients

Change-Id: Ia7a3e8f95722f91e84af262168dadf89a78707da
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/205720
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
Auto-Submit: Mike Reed <reed@google.com>
2019-04-03 15:24:18 +00:00

45 lines
1.7 KiB
C++

/*
* Copyright 2019 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkCanvas.h"
#include "SkGradientShader.h"
#include "SkPaint.h"
#include "gm.h"
// This draws a hard stop gradient applied to a rectangle. The hard stops fall at half pixel
// boundaries in y. On some GPUs we've found that the winding of the two triangles that make up the
// rectangle can affect whether the interpolants for local coords wind up agreeing across a row.
// When they disagree the hard stop gradient appears jagged. We draw the rectangle four times:
// no-mirroring, mirror in x, mirror in y, and mirror in x and y.
DEF_SIMPLE_GM(crbug_938592, canvas, 500, 300) {
static constexpr SkPoint pts[] = {{0, 0}, {0, 30}};
static constexpr SkScalar pos[] = {0.f, 9.f / 20, 9.f / 20, 11.f / 20, 11.f / 20, 20.f / 20};
static constexpr SkColor c0 = SK_ColorBLUE;
static constexpr SkColor c1 = SK_ColorRED;
static constexpr SkColor c2 = SK_ColorGREEN;
static constexpr SkColor colors[] = {c0, c0, c1, c1, c2, c2};
auto grad = SkGradientShader::MakeLinear(pts, colors, pos, 6, SkTileMode::kClamp);
SkPaint paint;
paint.setShader(grad);
static constexpr int kMirrorX = 400;
static constexpr int kMirrorY = 200;
canvas->translate(50, 50);
for (int i = 0; i < 4; ++i) {
canvas->save();
if (i & 0b01) {
canvas->translate(0, kMirrorY);
canvas->scale(1.f, -1.f);
}
if (i & 0b10) {
canvas->translate(kMirrorX, 0);
canvas->scale(-1.f, 1.f);
}
canvas->drawRect({0, 0, 150, 30}, paint);
canvas->restore();
}
}