mike@reedtribe.org | 0c87ea8 | 2013-12-30 04:07:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 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 Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "gm/gm.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 9 | #include "include/core/SkBlendMode.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/core/SkCanvas.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 11 | #include "include/core/SkColor.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "include/core/SkColorFilter.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 13 | #include "include/core/SkMatrix.h" |
| 14 | #include "include/core/SkPaint.h" |
| 15 | #include "include/core/SkPoint.h" |
| 16 | #include "include/core/SkRefCnt.h" |
| 17 | #include "include/core/SkScalar.h" |
| 18 | #include "include/core/SkShader.h" |
| 19 | #include "include/core/SkSize.h" |
| 20 | #include "include/core/SkString.h" |
| 21 | #include "include/core/SkTileMode.h" |
| 22 | #include "include/core/SkTypes.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 23 | #include "include/core/SkVertices.h" |
| 24 | #include "include/effects/SkGradientShader.h" |
Brian Osman | 3c35842 | 2020-03-23 10:44:12 -0400 | [diff] [blame] | 25 | #include "include/effects/SkRuntimeEffect.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 26 | #include "include/private/SkTDArray.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 27 | #include "include/utils/SkRandom.h" |
Brian Osman | 3c35842 | 2020-03-23 10:44:12 -0400 | [diff] [blame] | 28 | #include "src/core/SkVerticesPriv.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 29 | #include "src/shaders/SkLocalMatrixShader.h" |
Brian Osman | 3c35842 | 2020-03-23 10:44:12 -0400 | [diff] [blame] | 30 | #include "src/utils/SkPatchUtils.h" |
| 31 | #include "tools/Resources.h" |
Brian Osman | e41fa2d | 2020-03-20 15:45:49 -0400 | [diff] [blame] | 32 | #include "tools/ToolUtils.h" |
mike@reedtribe.org | 0c87ea8 | 2013-12-30 04:07:34 +0000 | [diff] [blame] | 33 | |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 34 | #include <initializer_list> |
| 35 | #include <utility> |
| 36 | |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 37 | static constexpr SkScalar kShaderSize = 40; |
Florin Malita | f614ba2 | 2017-02-16 22:12:41 -0500 | [diff] [blame] | 38 | static sk_sp<SkShader> make_shader1(SkScalar shaderScale) { |
reed@google.com | 85e143c | 2013-12-30 15:51:25 +0000 | [diff] [blame] | 39 | const SkColor colors[] = { |
| 40 | SK_ColorRED, SK_ColorCYAN, SK_ColorGREEN, SK_ColorWHITE, |
| 41 | SK_ColorMAGENTA, SK_ColorBLUE, SK_ColorYELLOW, |
| 42 | }; |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 43 | const SkPoint pts[] = {{kShaderSize / 4, 0}, {3 * kShaderSize / 4, kShaderSize}}; |
Mike Reed | 1f60733 | 2020-05-21 12:11:27 -0400 | [diff] [blame] | 44 | const SkMatrix localMatrix = SkMatrix::Scale(shaderScale, shaderScale); |
mike@reedtribe.org | 0c87ea8 | 2013-12-30 04:07:34 +0000 | [diff] [blame] | 45 | |
Florin Malita | f614ba2 | 2017-02-16 22:12:41 -0500 | [diff] [blame] | 46 | sk_sp<SkShader> grad = SkGradientShader::MakeLinear(pts, colors, nullptr, |
| 47 | SK_ARRAY_COUNT(colors), |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame] | 48 | SkTileMode::kMirror, 0, |
Florin Malita | f614ba2 | 2017-02-16 22:12:41 -0500 | [diff] [blame] | 49 | &localMatrix); |
| 50 | // Throw in a couple of local matrix wrappers for good measure. |
| 51 | return shaderScale == 1 |
| 52 | ? grad |
| 53 | : sk_make_sp<SkLocalMatrixShader>( |
Mike Reed | 1f60733 | 2020-05-21 12:11:27 -0400 | [diff] [blame] | 54 | sk_make_sp<SkLocalMatrixShader>(std::move(grad), SkMatrix::Translate(-10, 0)), |
| 55 | SkMatrix::Translate(10, 0)); |
mike@reedtribe.org | 0c87ea8 | 2013-12-30 04:07:34 +0000 | [diff] [blame] | 56 | } |
| 57 | |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 58 | static sk_sp<SkShader> make_shader2() { |
Mike Reed | c8bea7d | 2019-04-09 13:55:36 -0400 | [diff] [blame] | 59 | return SkShaders::Color(SK_ColorBLUE); |
bsalomon | 093779c | 2016-03-08 11:53:31 -0800 | [diff] [blame] | 60 | } |
| 61 | |
reed | d053ce9 | 2016-03-22 10:17:23 -0700 | [diff] [blame] | 62 | static sk_sp<SkColorFilter> make_color_filter() { |
Mike Reed | b286bc2 | 2019-04-08 16:23:20 -0400 | [diff] [blame] | 63 | return SkColorFilters::Blend(0xFFAABBCC, SkBlendMode::kDarken); |
bsalomon | 093779c | 2016-03-08 11:53:31 -0800 | [diff] [blame] | 64 | } |
| 65 | |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 66 | static constexpr SkScalar kMeshSize = 30; |
| 67 | |
| 68 | // start with the center of a 3x3 grid of vertices. |
| 69 | static constexpr uint16_t kMeshFan[] = { |
| 70 | 4, |
| 71 | 0, 1, 2, 5, 8, 7, 6, 3, 0 |
| 72 | }; |
| 73 | |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 74 | static const int kMeshIndexCnt = (int)SK_ARRAY_COUNT(kMeshFan); |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 75 | static const int kMeshVertexCnt = 9; |
| 76 | |
| 77 | static void fill_mesh(SkPoint pts[kMeshVertexCnt], SkPoint texs[kMeshVertexCnt], |
Florin Malita | f614ba2 | 2017-02-16 22:12:41 -0500 | [diff] [blame] | 78 | SkColor colors[kMeshVertexCnt], SkScalar shaderScale) { |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 79 | pts[0].set(0, 0); |
| 80 | pts[1].set(kMeshSize / 2, 3); |
| 81 | pts[2].set(kMeshSize, 0); |
| 82 | pts[3].set(3, kMeshSize / 2); |
| 83 | pts[4].set(kMeshSize / 2, kMeshSize / 2); |
| 84 | pts[5].set(kMeshSize - 3, kMeshSize / 2); |
| 85 | pts[6].set(0, kMeshSize); |
| 86 | pts[7].set(kMeshSize / 2, kMeshSize - 3); |
| 87 | pts[8].set(kMeshSize, kMeshSize); |
| 88 | |
Florin Malita | f614ba2 | 2017-02-16 22:12:41 -0500 | [diff] [blame] | 89 | const auto shaderSize = kShaderSize * shaderScale; |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 90 | texs[0].set(0, 0); |
Florin Malita | f614ba2 | 2017-02-16 22:12:41 -0500 | [diff] [blame] | 91 | texs[1].set(shaderSize / 2, 0); |
| 92 | texs[2].set(shaderSize, 0); |
| 93 | texs[3].set(0, shaderSize / 2); |
| 94 | texs[4].set(shaderSize / 2, shaderSize / 2); |
| 95 | texs[5].set(shaderSize, shaderSize / 2); |
| 96 | texs[6].set(0, shaderSize); |
| 97 | texs[7].set(shaderSize / 2, shaderSize); |
| 98 | texs[8].set(shaderSize, shaderSize); |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 99 | |
| 100 | SkRandom rand; |
| 101 | for (size_t i = 0; i < kMeshVertexCnt; ++i) { |
| 102 | colors[i] = rand.nextU() | 0xFF000000; |
| 103 | } |
| 104 | } |
| 105 | |
mike@reedtribe.org | 0c87ea8 | 2013-12-30 04:07:34 +0000 | [diff] [blame] | 106 | class VerticesGM : public skiagm::GM { |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 107 | SkPoint fPts[kMeshVertexCnt]; |
| 108 | SkPoint fTexs[kMeshVertexCnt]; |
| 109 | SkColor fColors[kMeshVertexCnt]; |
reed | d053ce9 | 2016-03-22 10:17:23 -0700 | [diff] [blame] | 110 | sk_sp<SkShader> fShader1; |
| 111 | sk_sp<SkShader> fShader2; |
| 112 | sk_sp<SkColorFilter> fColorFilter; |
Florin Malita | f614ba2 | 2017-02-16 22:12:41 -0500 | [diff] [blame] | 113 | SkScalar fShaderScale; |
mike@reedtribe.org | 0c87ea8 | 2013-12-30 04:07:34 +0000 | [diff] [blame] | 114 | |
| 115 | public: |
Mike Reed | 887cdf1 | 2017-04-03 11:11:09 -0400 | [diff] [blame] | 116 | VerticesGM(SkScalar shaderScale) : fShaderScale(shaderScale) {} |
mike@reedtribe.org | 0c87ea8 | 2013-12-30 04:07:34 +0000 | [diff] [blame] | 117 | |
| 118 | protected: |
commit-bot@chromium.org | a90c680 | 2014-04-30 13:20:45 +0000 | [diff] [blame] | 119 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 120 | void onOnceBeforeDraw() override { |
Florin Malita | f614ba2 | 2017-02-16 22:12:41 -0500 | [diff] [blame] | 121 | fill_mesh(fPts, fTexs, fColors, fShaderScale); |
| 122 | fShader1 = make_shader1(fShaderScale); |
reed | 1a9b964 | 2016-03-13 14:13:58 -0700 | [diff] [blame] | 123 | fShader2 = make_shader2(); |
reed | d053ce9 | 2016-03-22 10:17:23 -0700 | [diff] [blame] | 124 | fColorFilter = make_color_filter(); |
mike@reedtribe.org | 0c87ea8 | 2013-12-30 04:07:34 +0000 | [diff] [blame] | 125 | } |
| 126 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 127 | SkString onShortName() override { |
reed@google.com | 60da8f3 | 2014-05-05 20:41:21 +0000 | [diff] [blame] | 128 | SkString name("vertices"); |
Florin Malita | f614ba2 | 2017-02-16 22:12:41 -0500 | [diff] [blame] | 129 | if (fShaderScale != 1) { |
| 130 | name.append("_scaled_shader"); |
| 131 | } |
reed@google.com | 60da8f3 | 2014-05-05 20:41:21 +0000 | [diff] [blame] | 132 | return name; |
mike@reedtribe.org | 0c87ea8 | 2013-12-30 04:07:34 +0000 | [diff] [blame] | 133 | } |
| 134 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 135 | SkISize onISize() override { |
Brian Salomon | 3216180 | 2017-02-10 10:48:15 -0500 | [diff] [blame] | 136 | return SkISize::Make(975, 1175); |
mike@reedtribe.org | 0c87ea8 | 2013-12-30 04:07:34 +0000 | [diff] [blame] | 137 | } |
| 138 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 139 | void onDraw(SkCanvas* canvas) override { |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 140 | const SkBlendMode modes[] = { |
| 141 | SkBlendMode::kClear, |
| 142 | SkBlendMode::kSrc, |
| 143 | SkBlendMode::kDst, |
| 144 | SkBlendMode::kSrcOver, |
| 145 | SkBlendMode::kDstOver, |
| 146 | SkBlendMode::kSrcIn, |
| 147 | SkBlendMode::kDstIn, |
| 148 | SkBlendMode::kSrcOut, |
| 149 | SkBlendMode::kDstOut, |
| 150 | SkBlendMode::kSrcATop, |
| 151 | SkBlendMode::kDstATop, |
| 152 | SkBlendMode::kXor, |
| 153 | SkBlendMode::kPlus, |
| 154 | SkBlendMode::kModulate, |
| 155 | SkBlendMode::kScreen, |
| 156 | SkBlendMode::kOverlay, |
| 157 | SkBlendMode::kDarken, |
| 158 | SkBlendMode::kLighten, |
| 159 | SkBlendMode::kColorDodge, |
| 160 | SkBlendMode::kColorBurn, |
| 161 | SkBlendMode::kHardLight, |
| 162 | SkBlendMode::kSoftLight, |
| 163 | SkBlendMode::kDifference, |
| 164 | SkBlendMode::kExclusion, |
| 165 | SkBlendMode::kMultiply, |
| 166 | SkBlendMode::kHue, |
| 167 | SkBlendMode::kSaturation, |
| 168 | SkBlendMode::kColor, |
| 169 | SkBlendMode::kLuminosity, |
mike@reedtribe.org | 0c87ea8 | 2013-12-30 04:07:34 +0000 | [diff] [blame] | 170 | }; |
skia.committer@gmail.com | 4c91286 | 2013-12-30 07:01:37 +0000 | [diff] [blame] | 171 | |
mike@reedtribe.org | 0c87ea8 | 2013-12-30 04:07:34 +0000 | [diff] [blame] | 172 | SkPaint paint; |
mike@reedtribe.org | 0c87ea8 | 2013-12-30 04:07:34 +0000 | [diff] [blame] | 173 | |
bsalomon | 093779c | 2016-03-08 11:53:31 -0800 | [diff] [blame] | 174 | canvas->translate(4, 4); |
| 175 | int x = 0; |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 176 | for (auto mode : modes) { |
mike@reedtribe.org | 0c87ea8 | 2013-12-30 04:07:34 +0000 | [diff] [blame] | 177 | canvas->save(); |
Mike Reed | 9407e24 | 2019-02-15 16:13:57 -0500 | [diff] [blame] | 178 | for (float alpha : {1.0f, 0.5f}) { |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 179 | for (const auto& cf : {sk_sp<SkColorFilter>(nullptr), fColorFilter}) { |
| 180 | for (const auto& shader : {fShader1, fShader2}) { |
| 181 | static constexpr struct { |
| 182 | bool fHasColors; |
| 183 | bool fHasTexs; |
| 184 | } kAttrs[] = {{true, false}, {false, true}, {true, true}}; |
| 185 | for (auto attrs : kAttrs) { |
| 186 | paint.setShader(shader); |
| 187 | paint.setColorFilter(cf); |
Mike Reed | 9407e24 | 2019-02-15 16:13:57 -0500 | [diff] [blame] | 188 | paint.setAlphaf(alpha); |
Mike Reed | 5fa6645 | 2017-03-16 09:06:34 -0400 | [diff] [blame] | 189 | |
| 190 | const SkColor* colors = attrs.fHasColors ? fColors : nullptr; |
| 191 | const SkPoint* texs = attrs.fHasTexs ? fTexs : nullptr; |
Mike Reed | 887cdf1 | 2017-04-03 11:11:09 -0400 | [diff] [blame] | 192 | auto v = SkVertices::MakeCopy(SkVertices::kTriangleFan_VertexMode, |
| 193 | kMeshVertexCnt, fPts, texs, colors, |
| 194 | kMeshIndexCnt, kMeshFan); |
| 195 | canvas->drawVertices(v, mode, paint); |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 196 | canvas->translate(40, 0); |
| 197 | ++x; |
| 198 | } |
| 199 | } |
| 200 | } |
mike@reedtribe.org | 0c87ea8 | 2013-12-30 04:07:34 +0000 | [diff] [blame] | 201 | } |
| 202 | canvas->restore(); |
bsalomon | 093779c | 2016-03-08 11:53:31 -0800 | [diff] [blame] | 203 | canvas->translate(0, 40); |
mike@reedtribe.org | 0c87ea8 | 2013-12-30 04:07:34 +0000 | [diff] [blame] | 204 | } |
| 205 | } |
| 206 | |
mike@reedtribe.org | 0c87ea8 | 2013-12-30 04:07:34 +0000 | [diff] [blame] | 207 | private: |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 208 | using INHERITED = skiagm::GM; |
mike@reedtribe.org | 0c87ea8 | 2013-12-30 04:07:34 +0000 | [diff] [blame] | 209 | }; |
| 210 | |
reed@google.com | 60da8f3 | 2014-05-05 20:41:21 +0000 | [diff] [blame] | 211 | ///////////////////////////////////////////////////////////////////////////////////// |
| 212 | |
Mike Reed | 887cdf1 | 2017-04-03 11:11:09 -0400 | [diff] [blame] | 213 | DEF_GM(return new VerticesGM(1);) |
| 214 | DEF_GM(return new VerticesGM(1 / kShaderSize);) |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 215 | |
Mike Reed | 887cdf1 | 2017-04-03 11:11:09 -0400 | [diff] [blame] | 216 | static void draw_batching(SkCanvas* canvas) { |
Mike Reed | 97eb4fe | 2017-03-14 12:04:16 -0400 | [diff] [blame] | 217 | // Triangle fans can't batch so we convert to regular triangles, |
| 218 | static constexpr int kNumTris = kMeshIndexCnt - 2; |
Mike Reed | 887cdf1 | 2017-04-03 11:11:09 -0400 | [diff] [blame] | 219 | SkVertices::Builder builder(SkVertices::kTriangles_VertexMode, kMeshVertexCnt, 3 * kNumTris, |
Mike Reed | aa9e332 | 2017-03-16 14:38:48 -0400 | [diff] [blame] | 220 | SkVertices::kHasColors_BuilderFlag | |
| 221 | SkVertices::kHasTexCoords_BuilderFlag); |
Mike Reed | 97eb4fe | 2017-03-14 12:04:16 -0400 | [diff] [blame] | 222 | |
| 223 | SkPoint* pts = builder.positions(); |
| 224 | SkPoint* texs = builder.texCoords(); |
| 225 | SkColor* colors = builder.colors(); |
| 226 | fill_mesh(pts, texs, colors, 1); |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 227 | |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 228 | SkTDArray<SkMatrix> matrices; |
| 229 | matrices.push()->reset(); |
| 230 | matrices.push()->setTranslate(0, 40); |
John Stiles | a212b95 | 2021-08-02 13:26:38 -0400 | [diff] [blame] | 231 | matrices.push() |
| 232 | ->setRotate(45, kMeshSize / 2, kMeshSize / 2) |
| 233 | .postScale(1.2f, .8f, kMeshSize / 2, kMeshSize / 2) |
| 234 | .postTranslate(0, 80); |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 235 | |
Florin Malita | f614ba2 | 2017-02-16 22:12:41 -0500 | [diff] [blame] | 236 | auto shader = make_shader1(1); |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 237 | |
Mike Reed | 97eb4fe | 2017-03-14 12:04:16 -0400 | [diff] [blame] | 238 | uint16_t* indices = builder.indices(); |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 239 | for (size_t i = 0; i < kNumTris; ++i) { |
| 240 | indices[3 * i] = kMeshFan[0]; |
| 241 | indices[3 * i + 1] = kMeshFan[i + 1]; |
| 242 | indices[3 * i + 2] = kMeshFan[i + 2]; |
Mike Reed | 97eb4fe | 2017-03-14 12:04:16 -0400 | [diff] [blame] | 243 | |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 244 | } |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 245 | |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 246 | canvas->save(); |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 247 | canvas->translate(10, 10); |
| 248 | for (bool useShader : {false, true}) { |
| 249 | for (bool useTex : {false, true}) { |
| 250 | for (const auto& m : matrices) { |
| 251 | canvas->save(); |
| 252 | canvas->concat(m); |
| 253 | SkPaint paint; |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 254 | paint.setShader(useShader ? shader : nullptr); |
Mike Reed | 5fa6645 | 2017-03-16 09:06:34 -0400 | [diff] [blame] | 255 | |
| 256 | const SkPoint* t = useTex ? texs : nullptr; |
Mike Reed | 887cdf1 | 2017-04-03 11:11:09 -0400 | [diff] [blame] | 257 | auto v = SkVertices::MakeCopy(SkVertices::kTriangles_VertexMode, kMeshVertexCnt, |
| 258 | pts, t, colors, kNumTris * 3, indices); |
| 259 | canvas->drawVertices(v, SkBlendMode::kModulate, paint); |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 260 | canvas->restore(); |
| 261 | } |
| 262 | canvas->translate(0, 120); |
| 263 | } |
| 264 | } |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 265 | canvas->restore(); |
| 266 | } |
| 267 | |
| 268 | // This test exists to exercise batching in the gpu backend. |
| 269 | DEF_SIMPLE_GM(vertices_batching, canvas, 100, 500) { |
Mike Reed | 887cdf1 | 2017-04-03 11:11:09 -0400 | [diff] [blame] | 270 | draw_batching(canvas); |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 271 | canvas->translate(50, 0); |
Mike Reed | 887cdf1 | 2017-04-03 11:11:09 -0400 | [diff] [blame] | 272 | draw_batching(canvas); |
Brian Salomon | 3f36369 | 2017-02-02 21:05:19 -0500 | [diff] [blame] | 273 | } |
Mike Reed | d32bdaf | 2020-03-06 12:52:52 -0500 | [diff] [blame] | 274 | |
Brian Osman | e41fa2d | 2020-03-20 15:45:49 -0400 | [diff] [blame] | 275 | // Test case for skbug.com/10069. We need to draw the vertices twice (with different matrices) to |
| 276 | // trigger the bug. |
| 277 | DEF_SIMPLE_GM(vertices_perspective, canvas, 256, 256) { |
| 278 | SkPaint paint; |
| 279 | paint.setShader(ToolUtils::create_checkerboard_shader(SK_ColorBLACK, SK_ColorWHITE, 32)); |
| 280 | |
| 281 | SkRect r = SkRect::MakeWH(128, 128); |
| 282 | |
| 283 | SkPoint pos[4]; |
| 284 | r.toQuad(pos); |
| 285 | auto verts = SkVertices::MakeCopy(SkVertices::kTriangleFan_VertexMode, 4, pos, pos, nullptr); |
| 286 | |
| 287 | SkMatrix persp; |
| 288 | persp.setPerspY(SK_Scalar1 / 100); |
| 289 | |
| 290 | canvas->save(); |
| 291 | canvas->concat(persp); |
| 292 | canvas->drawRect(r, paint); |
| 293 | canvas->restore(); |
| 294 | |
| 295 | canvas->save(); |
| 296 | canvas->translate(r.width(), 0); |
| 297 | canvas->concat(persp); |
| 298 | canvas->drawRect(r, paint); |
| 299 | canvas->restore(); |
| 300 | |
| 301 | canvas->save(); |
| 302 | canvas->translate(0, r.height()); |
| 303 | canvas->concat(persp); |
| 304 | canvas->drawVertices(verts, paint); |
| 305 | canvas->restore(); |
| 306 | |
| 307 | canvas->save(); |
| 308 | canvas->translate(r.width(), r.height()); |
| 309 | canvas->concat(persp); |
| 310 | canvas->drawVertices(verts, paint); |
| 311 | canvas->restore(); |
| 312 | } |