| 1 |
/* |
| 2 |
* Copyright 2011 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 "gm/gm.h" |
| 9 |
#include "include/core/SkCanvas.h" |
| 10 |
#include "include/core/SkColor.h" |
| 11 |
#include "include/core/SkPaint.h" |
| 12 |
#include "include/core/SkPoint.h" |
| 13 |
#include "include/core/SkRect.h" |
| 14 |
#include "include/core/SkScalar.h" |
| 15 |
#include "include/core/SkSurface.h" |
| 16 |
#include "include/effects/SkGradient.h" |
| 17 |
#include "tools/Resources.h" |
| 18 |
|
| 19 |
|
| 20 |
// This tests using clip shader and then changing the canvas matrix before drawing. It also verifies |
| 21 |
// that we don't incorrectly disable linear filtering of a clip image shader. |
| 22 |
DEF_SIMPLE_GM(clipshadermatrix, canvas, 145, 128) { |
| 23 |
auto clipSurface = SkSurfaces::Raster(SkImageInfo::MakeA8({70, 60})); |
| 24 |
// Hard edged oval clip |
| 25 |
clipSurface->getCanvas()->drawOval(SkRect::MakeXYWH(0, 10, 64, 44), SkPaint{}); |
| 26 |
auto clipShader = clipSurface->makeImageSnapshot()->makeShader( |
| 27 |
SkTileMode::kDecal, SkTileMode::kDecal, SkFilterMode::kLinear); |
| 28 |
|
| 29 |
canvas->translate(5, 0); |
| 30 |
for (auto tx : {0.f, 68.5f}) { |
| 31 |
for (auto ty : {0.f, 66.5f}) { |
| 32 |
canvas->save(); |
| 33 |
|
| 34 |
canvas->translate(tx, ty); |
| 35 |
canvas->clipShader(clipShader); |
| 36 |
canvas->translate(-tx, -ty); |
| 37 |
|
| 38 |
SkMatrix m; |
| 39 |
m.setSkew(0.03f, 0.f); |
| 40 |
m.setPerspY( 0.0007f); |
| 41 |
m.setPerspX(-0.002f); |
| 42 |
m.setScaleX(1.2f); m.setScaleY(0.8f); |
| 43 |
m.preRotate(30.f); |
| 44 |
canvas->concat(m); |
| 45 |
|
| 46 |
SkPoint center = {64, 64}; |
| 47 |
SkAssertResult(m.invert(&m)); |
| 48 |
center = m.mapPoint(center); |
| 49 |
const SkColor4f colors[] {SkColors::kYellow, SkColors::kGreen, SkColors::kBlue, |
| 50 |
SkColors::kMagenta, SkColors::kCyan , SkColors::kYellow}; |
| 51 |
auto gradient = SkShaders::RadialGradient(center, 32, |
| 52 |
{{colors, {}, SkTileMode::kMirror}, {}}); |
| 53 |
|
| 54 |
SkPaint paint; |
| 55 |
paint.setShader(std::move(gradient)); |
| 56 |
canvas->drawPaint(paint); |
| 57 |
|
| 58 |
canvas->restore(); |
| 59 |
} |
| 60 |
} |
| 61 |
} |