commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +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 | |
| 8 | // This test only works with the GPU backend. |
| 9 | |
| 10 | #include "gm.h" |
| 11 | |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 12 | #if SK_SUPPORT_GPU |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 13 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 14 | #include "GrRenderTargetContextPriv.h" |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 15 | #include "GrContext.h" |
| 16 | #include "GrPathUtils.h" |
| 17 | #include "GrTest.h" |
| 18 | #include "SkColorPriv.h" |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 19 | #include "SkGeometry.h" |
| 20 | |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 21 | #include "ops/GrTestMeshDrawOp.h" |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame] | 22 | |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 23 | #include "effects/GrBezierEffect.h" |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 24 | |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 25 | static inline SkScalar eval_line(const SkPoint& p, const SkScalar lineEq[3], SkScalar sign) { |
| 26 | return sign * (lineEq[0] * p.fX + lineEq[1] * p.fY + lineEq[2]); |
| 27 | } |
| 28 | |
| 29 | namespace skiagm { |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 30 | |
Brian Salomon | 6b316e9 | 2016-12-16 09:35:49 -0500 | [diff] [blame] | 31 | class BezierCubicOrConicTestOp : public GrTestMeshDrawOp { |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 32 | public: |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 33 | DEFINE_OP_CLASS_ID |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 34 | |
Brian Salomon | 6b316e9 | 2016-12-16 09:35:49 -0500 | [diff] [blame] | 35 | const char* name() const override { return "BezierCubicOrConicTestOp"; } |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 36 | |
Brian Salomon | 649a341 | 2017-03-09 13:50:43 -0500 | [diff] [blame] | 37 | static std::unique_ptr<GrMeshDrawOp> Make(sk_sp<GrGeometryProcessor> gp, const SkRect& rect, |
| 38 | GrColor color, const SkScalar klmEqs[9], |
| 39 | SkScalar sign) { |
| 40 | return std::unique_ptr<GrMeshDrawOp>( |
Brian Salomon | 9e50f7b | 2017-03-06 12:02:34 -0500 | [diff] [blame] | 41 | new BezierCubicOrConicTestOp(gp, rect, color, klmEqs, sign)); |
Brian Salomon | 6b316e9 | 2016-12-16 09:35:49 -0500 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | private: |
Brian Salomon | 9e50f7b | 2017-03-06 12:02:34 -0500 | [diff] [blame] | 45 | BezierCubicOrConicTestOp(sk_sp<GrGeometryProcessor> gp, const SkRect& rect, GrColor color, |
Brian Salomon | 6b316e9 | 2016-12-16 09:35:49 -0500 | [diff] [blame] | 46 | const SkScalar klmEqs[9], SkScalar sign) |
Brian Salomon | 9e50f7b | 2017-03-06 12:02:34 -0500 | [diff] [blame] | 47 | : INHERITED(ClassID(), rect, color), fRect(rect), fGeometryProcessor(std::move(gp)) { |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 48 | for (int i = 0; i < 9; i++) { |
| 49 | fKlmEqs[i] = klmEqs[i]; |
| 50 | } |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 51 | fSign = sign; |
| 52 | } |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 53 | struct Vertex { |
| 54 | SkPoint fPosition; |
| 55 | float fKLM[4]; // The last value is ignored. The effect expects a vec4f. |
| 56 | }; |
| 57 | |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 58 | void onPrepareDraws(Target* target) const override { |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 59 | QuadHelper helper; |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 60 | size_t vertexStride = fGeometryProcessor->getVertexStride(); |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 61 | SkASSERT(vertexStride == sizeof(Vertex)); |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 62 | Vertex* verts = reinterpret_cast<Vertex*>(helper.init(target, vertexStride, 1)); |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 63 | if (!verts) { |
joshualitt | 4b31de8 | 2015-03-05 14:33:41 -0800 | [diff] [blame] | 64 | return; |
| 65 | } |
Brian Salomon | 9e50f7b | 2017-03-06 12:02:34 -0500 | [diff] [blame] | 66 | verts[0].fPosition.setRectFan(fRect.fLeft, fRect.fTop, fRect.fRight, fRect.fBottom, |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 67 | sizeof(Vertex)); |
| 68 | for (int v = 0; v < 4; ++v) { |
| 69 | verts[v].fKLM[0] = eval_line(verts[v].fPosition, fKlmEqs + 0, fSign); |
| 70 | verts[v].fKLM[1] = eval_line(verts[v].fPosition, fKlmEqs + 3, fSign); |
| 71 | verts[v].fKLM[2] = eval_line(verts[v].fPosition, fKlmEqs + 6, 1.f); |
| 72 | } |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 73 | helper.recordDraw(target, fGeometryProcessor.get()); |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 74 | } |
| 75 | |
Brian Salomon | 9e50f7b | 2017-03-06 12:02:34 -0500 | [diff] [blame] | 76 | SkScalar fKlmEqs[9]; |
| 77 | SkScalar fSign; |
| 78 | SkRect fRect; |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 79 | sk_sp<GrGeometryProcessor> fGeometryProcessor; |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 80 | |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 81 | static constexpr int kVertsPerCubic = 4; |
| 82 | static constexpr int kIndicesPerCubic = 6; |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 83 | |
Brian Salomon | 6b316e9 | 2016-12-16 09:35:49 -0500 | [diff] [blame] | 84 | typedef GrTestMeshDrawOp INHERITED; |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 85 | }; |
| 86 | |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 87 | /** |
| 88 | * This GM directly exercises effects that draw Bezier curves in the GPU backend. |
| 89 | */ |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 90 | class BezierCubicEffects : public GM { |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 91 | public: |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 92 | BezierCubicEffects() { |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 93 | this->setBGColor(0xFFFFFFFF); |
| 94 | } |
| 95 | |
| 96 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 97 | SkString onShortName() override { |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 98 | return SkString("bezier_cubic_effects"); |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 99 | } |
| 100 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 101 | SkISize onISize() override { |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 102 | return SkISize::Make(800, 800); |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 103 | } |
| 104 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 105 | void onDraw(SkCanvas* canvas) override { |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 106 | GrRenderTargetContext* renderTargetContext = |
| 107 | canvas->internal_private_accessTopLayerRenderTargetContext(); |
| 108 | if (!renderTargetContext) { |
halcanary | 2a24338 | 2015-09-09 08:16:41 -0700 | [diff] [blame] | 109 | skiagm::GM::DrawGpuOnlyMessage(canvas); |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 110 | return; |
| 111 | } |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 112 | |
robertphillips | 175dd9b | 2016-04-28 14:32:04 -0700 | [diff] [blame] | 113 | GrContext* context = canvas->getGrContext(); |
| 114 | if (!context) { |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 115 | return; |
| 116 | } |
| 117 | |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 118 | struct Vertex { |
| 119 | SkPoint fPosition; |
| 120 | float fKLM[4]; // The last value is ignored. The effect expects a vec4f. |
| 121 | }; |
| 122 | |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 123 | constexpr int kNumCubics = 15; |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 124 | SkRandom rand; |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 125 | |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 126 | // Mult by 3 for each edge effect type |
| 127 | int numCols = SkScalarCeilToInt(SkScalarSqrt(SkIntToScalar(kNumCubics*3))); |
| 128 | int numRows = SkScalarCeilToInt(SkIntToScalar(kNumCubics*3) / numCols); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 129 | SkScalar w = SkIntToScalar(renderTargetContext->width()) / numCols; |
| 130 | SkScalar h = SkIntToScalar(renderTargetContext->height()) / numRows; |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 131 | int row = 0; |
| 132 | int col = 0; |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 133 | constexpr GrColor color = 0xff000000; |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 134 | |
| 135 | for (int i = 0; i < kNumCubics; ++i) { |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 136 | SkPoint baseControlPts[] = { |
| 137 | {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, |
| 138 | {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, |
| 139 | {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, |
| 140 | {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)} |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 141 | }; |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 142 | for(int edgeType = 0; edgeType < kGrProcessorEdgeTypeCnt; ++edgeType) { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 143 | sk_sp<GrGeometryProcessor> gp; |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 144 | GrPrimitiveEdgeType et = (GrPrimitiveEdgeType)edgeType; |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 145 | gp = GrCubicEffect::Make(color, SkMatrix::I(), et, *context->caps()); |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 146 | if (!gp) { |
| 147 | continue; |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 148 | } |
Mike Reed | df85c38 | 2017-02-14 10:59:19 -0500 | [diff] [blame] | 149 | SkScalar x = col * w; |
| 150 | SkScalar y = row * h; |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 151 | SkPoint controlPts[] = { |
| 152 | {x + baseControlPts[0].fX, y + baseControlPts[0].fY}, |
| 153 | {x + baseControlPts[1].fX, y + baseControlPts[1].fY}, |
| 154 | {x + baseControlPts[2].fX, y + baseControlPts[2].fY}, |
| 155 | {x + baseControlPts[3].fX, y + baseControlPts[3].fY} |
| 156 | }; |
| 157 | SkPoint chopped[10]; |
| 158 | SkScalar klmEqs[9]; |
Greg Daniel | 8199d94 | 2017-03-14 10:20:24 -0400 | [diff] [blame] | 159 | int loopIndex; |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 160 | int cnt = GrPathUtils::chopCubicAtLoopIntersection(controlPts, |
| 161 | chopped, |
| 162 | klmEqs, |
Greg Daniel | 8199d94 | 2017-03-14 10:20:24 -0400 | [diff] [blame] | 163 | &loopIndex); |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 164 | |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 165 | SkPaint ctrlPtPaint; |
| 166 | ctrlPtPaint.setColor(rand.nextU() | 0xFF000000); |
Greg Daniel | 8199d94 | 2017-03-14 10:20:24 -0400 | [diff] [blame] | 167 | canvas->drawCircle(controlPts[0].fX, controlPts[0].fY, 8.f, ctrlPtPaint); |
| 168 | for (int i = 1; i < 4; ++i) { |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 169 | canvas->drawCircle(controlPts[i].fX, controlPts[i].fY, 6.f, ctrlPtPaint); |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 170 | } |
| 171 | |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 172 | SkPaint polyPaint; |
| 173 | polyPaint.setColor(0xffA0A0A0); |
| 174 | polyPaint.setStrokeWidth(0); |
| 175 | polyPaint.setStyle(SkPaint::kStroke_Style); |
| 176 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, 4, controlPts, polyPaint); |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 177 | |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 178 | SkPaint choppedPtPaint; |
| 179 | choppedPtPaint.setColor(~ctrlPtPaint.getColor() | 0xFF000000); |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 180 | |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 181 | for (int c = 0; c < cnt; ++c) { |
| 182 | SkPoint* pts = chopped + 3 * c; |
| 183 | |
| 184 | for (int i = 0; i < 4; ++i) { |
| 185 | canvas->drawCircle(pts[i].fX, pts[i].fY, 3.f, choppedPtPaint); |
| 186 | } |
| 187 | |
| 188 | SkRect bounds; |
| 189 | bounds.set(pts, 4); |
| 190 | |
| 191 | SkPaint boundsPaint; |
| 192 | boundsPaint.setColor(0xff808080); |
| 193 | boundsPaint.setStrokeWidth(0); |
| 194 | boundsPaint.setStyle(SkPaint::kStroke_Style); |
| 195 | canvas->drawRect(bounds, boundsPaint); |
| 196 | |
robertphillips | 28a838e | 2016-06-23 14:07:00 -0700 | [diff] [blame] | 197 | GrPaint grPaint; |
Brian Salomon | a163392 | 2017-01-09 11:46:10 -0500 | [diff] [blame] | 198 | grPaint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc)); |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 199 | |
Greg Daniel | 8199d94 | 2017-03-14 10:20:24 -0400 | [diff] [blame] | 200 | SkScalar sign = 1.0f; |
| 201 | if (c == loopIndex && cnt != 3) { |
| 202 | sign = -1.0f; |
| 203 | } |
| 204 | |
Brian Salomon | 649a341 | 2017-03-09 13:50:43 -0500 | [diff] [blame] | 205 | std::unique_ptr<GrMeshDrawOp> op = |
Greg Daniel | 8199d94 | 2017-03-14 10:20:24 -0400 | [diff] [blame] | 206 | BezierCubicOrConicTestOp::Make(gp, bounds, color, klmEqs, sign); |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 207 | |
Brian Salomon | 649a341 | 2017-03-09 13:50:43 -0500 | [diff] [blame] | 208 | renderTargetContext->priv().testingOnly_addMeshDrawOp( |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 209 | std::move(grPaint), GrAAType::kNone, std::move(op)); |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 210 | } |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 211 | ++col; |
| 212 | if (numCols == col) { |
| 213 | col = 0; |
| 214 | ++row; |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 215 | } |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 216 | } |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | private: |
| 221 | typedef GM INHERITED; |
| 222 | }; |
| 223 | |
| 224 | ////////////////////////////////////////////////////////////////////////////// |
| 225 | |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 226 | /** |
| 227 | * This GM directly exercises effects that draw Bezier curves in the GPU backend. |
| 228 | */ |
| 229 | class BezierConicEffects : public GM { |
| 230 | public: |
| 231 | BezierConicEffects() { |
| 232 | this->setBGColor(0xFFFFFFFF); |
| 233 | } |
| 234 | |
| 235 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 236 | SkString onShortName() override { |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 237 | return SkString("bezier_conic_effects"); |
| 238 | } |
| 239 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 240 | SkISize onISize() override { |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 241 | return SkISize::Make(800, 800); |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 242 | } |
| 243 | |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 244 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 245 | void onDraw(SkCanvas* canvas) override { |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 246 | GrRenderTargetContext* renderTargetContext = |
| 247 | canvas->internal_private_accessTopLayerRenderTargetContext(); |
| 248 | if (!renderTargetContext) { |
halcanary | 2a24338 | 2015-09-09 08:16:41 -0700 | [diff] [blame] | 249 | skiagm::GM::DrawGpuOnlyMessage(canvas); |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 250 | return; |
| 251 | } |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 252 | |
robertphillips | 175dd9b | 2016-04-28 14:32:04 -0700 | [diff] [blame] | 253 | GrContext* context = canvas->getGrContext(); |
| 254 | if (!context) { |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 255 | return; |
| 256 | } |
| 257 | |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 258 | struct Vertex { |
| 259 | SkPoint fPosition; |
| 260 | float fKLM[4]; // The last value is ignored. The effect expects a vec4f. |
| 261 | }; |
| 262 | |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 263 | constexpr int kNumConics = 10; |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 264 | SkRandom rand; |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 265 | |
| 266 | // Mult by 3 for each edge effect type |
| 267 | int numCols = SkScalarCeilToInt(SkScalarSqrt(SkIntToScalar(kNumConics*3))); |
| 268 | int numRows = SkScalarCeilToInt(SkIntToScalar(kNumConics*3) / numCols); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 269 | SkScalar w = SkIntToScalar(renderTargetContext->width()) / numCols; |
| 270 | SkScalar h = SkIntToScalar(renderTargetContext->height()) / numRows; |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 271 | int row = 0; |
| 272 | int col = 0; |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 273 | constexpr GrColor color = 0xff000000; |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 274 | |
| 275 | for (int i = 0; i < kNumConics; ++i) { |
| 276 | SkPoint baseControlPts[] = { |
| 277 | {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, |
| 278 | {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, |
| 279 | {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)} |
| 280 | }; |
| 281 | SkScalar weight = rand.nextRangeF(0.f, 2.f); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 282 | for(int edgeType = 0; edgeType < kGrProcessorEdgeTypeCnt; ++edgeType) { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 283 | sk_sp<GrGeometryProcessor> gp; |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 284 | GrPrimitiveEdgeType et = (GrPrimitiveEdgeType)edgeType; |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 285 | gp = GrConicEffect::Make(color, SkMatrix::I(), et, |
| 286 | *context->caps(), SkMatrix::I(), false); |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 287 | if (!gp) { |
| 288 | continue; |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 289 | } |
| 290 | |
Mike Reed | df85c38 | 2017-02-14 10:59:19 -0500 | [diff] [blame] | 291 | SkScalar x = col * w; |
| 292 | SkScalar y = row * h; |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 293 | SkPoint controlPts[] = { |
| 294 | {x + baseControlPts[0].fX, y + baseControlPts[0].fY}, |
| 295 | {x + baseControlPts[1].fX, y + baseControlPts[1].fY}, |
| 296 | {x + baseControlPts[2].fX, y + baseControlPts[2].fY} |
| 297 | }; |
| 298 | SkConic dst[4]; |
| 299 | SkScalar klmEqs[9]; |
| 300 | int cnt = chop_conic(controlPts, dst, weight); |
| 301 | GrPathUtils::getConicKLM(controlPts, weight, klmEqs); |
| 302 | |
| 303 | SkPaint ctrlPtPaint; |
| 304 | ctrlPtPaint.setColor(rand.nextU() | 0xFF000000); |
| 305 | for (int i = 0; i < 3; ++i) { |
| 306 | canvas->drawCircle(controlPts[i].fX, controlPts[i].fY, 6.f, ctrlPtPaint); |
| 307 | } |
| 308 | |
| 309 | SkPaint polyPaint; |
| 310 | polyPaint.setColor(0xffA0A0A0); |
| 311 | polyPaint.setStrokeWidth(0); |
| 312 | polyPaint.setStyle(SkPaint::kStroke_Style); |
| 313 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, 3, controlPts, polyPaint); |
| 314 | |
| 315 | SkPaint choppedPtPaint; |
| 316 | choppedPtPaint.setColor(~ctrlPtPaint.getColor() | 0xFF000000); |
| 317 | |
| 318 | for (int c = 0; c < cnt; ++c) { |
| 319 | SkPoint* pts = dst[c].fPts; |
| 320 | for (int i = 0; i < 3; ++i) { |
| 321 | canvas->drawCircle(pts[i].fX, pts[i].fY, 3.f, choppedPtPaint); |
| 322 | } |
| 323 | |
| 324 | SkRect bounds; |
| 325 | //SkPoint bPts[] = {{0.f, 0.f}, {800.f, 800.f}}; |
| 326 | //bounds.set(bPts, 2); |
| 327 | bounds.set(pts, 3); |
| 328 | |
| 329 | SkPaint boundsPaint; |
| 330 | boundsPaint.setColor(0xff808080); |
| 331 | boundsPaint.setStrokeWidth(0); |
| 332 | boundsPaint.setStyle(SkPaint::kStroke_Style); |
| 333 | canvas->drawRect(bounds, boundsPaint); |
| 334 | |
robertphillips | 28a838e | 2016-06-23 14:07:00 -0700 | [diff] [blame] | 335 | GrPaint grPaint; |
Brian Salomon | a163392 | 2017-01-09 11:46:10 -0500 | [diff] [blame] | 336 | grPaint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc)); |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 337 | |
Brian Salomon | 649a341 | 2017-03-09 13:50:43 -0500 | [diff] [blame] | 338 | std::unique_ptr<GrMeshDrawOp> op = |
Brian Salomon | 6b316e9 | 2016-12-16 09:35:49 -0500 | [diff] [blame] | 339 | BezierCubicOrConicTestOp::Make(gp, bounds, color, klmEqs, 1.f); |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 340 | |
Brian Salomon | 649a341 | 2017-03-09 13:50:43 -0500 | [diff] [blame] | 341 | renderTargetContext->priv().testingOnly_addMeshDrawOp( |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 342 | std::move(grPaint), GrAAType::kNone, std::move(op)); |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 343 | } |
| 344 | ++col; |
| 345 | if (numCols == col) { |
| 346 | col = 0; |
| 347 | ++row; |
| 348 | } |
| 349 | } |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | private: |
| 354 | // Uses the max curvature function for quads to estimate |
| 355 | // where to chop the conic. If the max curvature is not |
| 356 | // found along the curve segment it will return 1 and |
| 357 | // dst[0] is the original conic. If it returns 2 the dst[0] |
| 358 | // and dst[1] are the two new conics. |
| 359 | int split_conic(const SkPoint src[3], SkConic dst[2], const SkScalar weight) { |
| 360 | SkScalar t = SkFindQuadMaxCurvature(src); |
| 361 | if (t == 0) { |
| 362 | if (dst) { |
| 363 | dst[0].set(src, weight); |
| 364 | } |
| 365 | return 1; |
| 366 | } else { |
| 367 | if (dst) { |
| 368 | SkConic conic; |
| 369 | conic.set(src, weight); |
caryclark | 414c429 | 2016-09-26 11:03:54 -0700 | [diff] [blame] | 370 | if (!conic.chopAt(t, dst)) { |
| 371 | dst[0].set(src, weight); |
| 372 | return 1; |
| 373 | } |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 374 | } |
| 375 | return 2; |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | // Calls split_conic on the entire conic and then once more on each subsection. |
| 380 | // Most cases will result in either 1 conic (chop point is not within t range) |
| 381 | // or 3 points (split once and then one subsection is split again). |
| 382 | int chop_conic(const SkPoint src[3], SkConic dst[4], const SkScalar weight) { |
| 383 | SkConic dstTemp[2]; |
| 384 | int conicCnt = split_conic(src, dstTemp, weight); |
| 385 | if (2 == conicCnt) { |
| 386 | int conicCnt2 = split_conic(dstTemp[0].fPts, dst, dstTemp[0].fW); |
| 387 | conicCnt = conicCnt2 + split_conic(dstTemp[1].fPts, &dst[conicCnt2], dstTemp[1].fW); |
| 388 | } else { |
| 389 | dst[0] = dstTemp[0]; |
| 390 | } |
| 391 | return conicCnt; |
| 392 | } |
| 393 | |
| 394 | typedef GM INHERITED; |
| 395 | }; |
| 396 | |
| 397 | ////////////////////////////////////////////////////////////////////////////// |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 398 | |
Brian Salomon | 6b316e9 | 2016-12-16 09:35:49 -0500 | [diff] [blame] | 399 | class BezierQuadTestOp : public GrTestMeshDrawOp { |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 400 | public: |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 401 | DEFINE_OP_CLASS_ID |
Brian Salomon | 6b316e9 | 2016-12-16 09:35:49 -0500 | [diff] [blame] | 402 | const char* name() const override { return "BezierQuadTestOp"; } |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 403 | |
Brian Salomon | 649a341 | 2017-03-09 13:50:43 -0500 | [diff] [blame] | 404 | static std::unique_ptr<GrMeshDrawOp> Make(sk_sp<GrGeometryProcessor> gp, const SkRect& rect, |
| 405 | GrColor color, |
| 406 | const GrPathUtils::QuadUVMatrix& devToUV) { |
| 407 | return std::unique_ptr<GrMeshDrawOp>(new BezierQuadTestOp(gp, rect, color, devToUV)); |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | private: |
Brian Salomon | 9e50f7b | 2017-03-06 12:02:34 -0500 | [diff] [blame] | 411 | BezierQuadTestOp(sk_sp<GrGeometryProcessor> gp, const SkRect& rect, GrColor color, |
Brian Salomon | 6b316e9 | 2016-12-16 09:35:49 -0500 | [diff] [blame] | 412 | const GrPathUtils::QuadUVMatrix& devToUV) |
Brian Salomon | 9e50f7b | 2017-03-06 12:02:34 -0500 | [diff] [blame] | 413 | : INHERITED(ClassID(), rect, color) |
Brian Salomon | 6b316e9 | 2016-12-16 09:35:49 -0500 | [diff] [blame] | 414 | , fDevToUV(devToUV) |
Brian Salomon | 9e50f7b | 2017-03-06 12:02:34 -0500 | [diff] [blame] | 415 | , fRect(rect) |
Brian Salomon | 6b316e9 | 2016-12-16 09:35:49 -0500 | [diff] [blame] | 416 | , fGeometryProcessor(std::move(gp)) {} |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 417 | |
| 418 | struct Vertex { |
| 419 | SkPoint fPosition; |
| 420 | float fKLM[4]; // The last value is ignored. The effect expects a vec4f. |
| 421 | }; |
| 422 | |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 423 | void onPrepareDraws(Target* target) const override { |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 424 | QuadHelper helper; |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 425 | size_t vertexStride = fGeometryProcessor->getVertexStride(); |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 426 | SkASSERT(vertexStride == sizeof(Vertex)); |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 427 | Vertex* verts = reinterpret_cast<Vertex*>(helper.init(target, vertexStride, 1)); |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 428 | if (!verts) { |
joshualitt | 4b31de8 | 2015-03-05 14:33:41 -0800 | [diff] [blame] | 429 | return; |
| 430 | } |
Brian Salomon | 9e50f7b | 2017-03-06 12:02:34 -0500 | [diff] [blame] | 431 | verts[0].fPosition.setRectFan(fRect.fLeft, fRect.fTop, fRect.fRight, fRect.fBottom, |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 432 | sizeof(Vertex)); |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 433 | fDevToUV.apply<4, sizeof(Vertex), sizeof(SkPoint)>(verts); |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 434 | helper.recordDraw(target, fGeometryProcessor.get()); |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 435 | } |
| 436 | |
Brian Salomon | 9e50f7b | 2017-03-06 12:02:34 -0500 | [diff] [blame] | 437 | GrPathUtils::QuadUVMatrix fDevToUV; |
| 438 | SkRect fRect; |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 439 | sk_sp<GrGeometryProcessor> fGeometryProcessor; |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 440 | |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 441 | static constexpr int kVertsPerCubic = 4; |
| 442 | static constexpr int kIndicesPerCubic = 6; |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 443 | |
Brian Salomon | 6b316e9 | 2016-12-16 09:35:49 -0500 | [diff] [blame] | 444 | typedef GrTestMeshDrawOp INHERITED; |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 445 | }; |
| 446 | |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 447 | /** |
| 448 | * This GM directly exercises effects that draw Bezier quad curves in the GPU backend. |
| 449 | */ |
| 450 | class BezierQuadEffects : public GM { |
| 451 | public: |
| 452 | BezierQuadEffects() { |
| 453 | this->setBGColor(0xFFFFFFFF); |
| 454 | } |
| 455 | |
| 456 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 457 | SkString onShortName() override { |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 458 | return SkString("bezier_quad_effects"); |
| 459 | } |
| 460 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 461 | SkISize onISize() override { |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 462 | return SkISize::Make(800, 800); |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 463 | } |
| 464 | |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 465 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 466 | void onDraw(SkCanvas* canvas) override { |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 467 | GrRenderTargetContext* renderTargetContext = |
| 468 | canvas->internal_private_accessTopLayerRenderTargetContext(); |
| 469 | if (!renderTargetContext) { |
halcanary | 2a24338 | 2015-09-09 08:16:41 -0700 | [diff] [blame] | 470 | skiagm::GM::DrawGpuOnlyMessage(canvas); |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 471 | return; |
| 472 | } |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 473 | |
robertphillips | 175dd9b | 2016-04-28 14:32:04 -0700 | [diff] [blame] | 474 | GrContext* context = canvas->getGrContext(); |
| 475 | if (!context) { |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 476 | return; |
| 477 | } |
| 478 | |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 479 | struct Vertex { |
| 480 | SkPoint fPosition; |
| 481 | float fUV[4]; // The last two values are ignored. The effect expects a vec4f. |
| 482 | }; |
| 483 | |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 484 | constexpr int kNumQuads = 5; |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 485 | SkRandom rand; |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 486 | |
| 487 | int numCols = SkScalarCeilToInt(SkScalarSqrt(SkIntToScalar(kNumQuads*3))); |
| 488 | int numRows = SkScalarCeilToInt(SkIntToScalar(kNumQuads*3) / numCols); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 489 | SkScalar w = SkIntToScalar(renderTargetContext->width()) / numCols; |
| 490 | SkScalar h = SkIntToScalar(renderTargetContext->height()) / numRows; |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 491 | int row = 0; |
| 492 | int col = 0; |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 493 | constexpr GrColor color = 0xff000000; |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 494 | |
| 495 | for (int i = 0; i < kNumQuads; ++i) { |
| 496 | SkPoint baseControlPts[] = { |
| 497 | {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, |
| 498 | {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)}, |
| 499 | {rand.nextRangeF(0.f, w), rand.nextRangeF(0.f, h)} |
| 500 | }; |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 501 | for(int edgeType = 0; edgeType < kGrProcessorEdgeTypeCnt; ++edgeType) { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 502 | sk_sp<GrGeometryProcessor> gp; |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 503 | GrPrimitiveEdgeType et = (GrPrimitiveEdgeType)edgeType; |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 504 | gp = GrQuadEffect::Make(color, SkMatrix::I(), et, |
| 505 | *context->caps(), SkMatrix::I(), false); |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 506 | if (!gp) { |
| 507 | continue; |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 508 | } |
| 509 | |
Mike Reed | df85c38 | 2017-02-14 10:59:19 -0500 | [diff] [blame] | 510 | SkScalar x = col * w; |
| 511 | SkScalar y = row * h; |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 512 | SkPoint controlPts[] = { |
| 513 | {x + baseControlPts[0].fX, y + baseControlPts[0].fY}, |
| 514 | {x + baseControlPts[1].fX, y + baseControlPts[1].fY}, |
| 515 | {x + baseControlPts[2].fX, y + baseControlPts[2].fY} |
| 516 | }; |
| 517 | SkPoint chopped[5]; |
| 518 | int cnt = SkChopQuadAtMaxCurvature(controlPts, chopped); |
| 519 | |
| 520 | SkPaint ctrlPtPaint; |
| 521 | ctrlPtPaint.setColor(rand.nextU() | 0xFF000000); |
| 522 | for (int i = 0; i < 3; ++i) { |
| 523 | canvas->drawCircle(controlPts[i].fX, controlPts[i].fY, 6.f, ctrlPtPaint); |
| 524 | } |
| 525 | |
| 526 | SkPaint polyPaint; |
| 527 | polyPaint.setColor(0xffA0A0A0); |
| 528 | polyPaint.setStrokeWidth(0); |
| 529 | polyPaint.setStyle(SkPaint::kStroke_Style); |
| 530 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, 3, controlPts, polyPaint); |
| 531 | |
| 532 | SkPaint choppedPtPaint; |
| 533 | choppedPtPaint.setColor(~ctrlPtPaint.getColor() | 0xFF000000); |
| 534 | |
| 535 | for (int c = 0; c < cnt; ++c) { |
| 536 | SkPoint* pts = chopped + 2 * c; |
| 537 | |
| 538 | for (int i = 0; i < 3; ++i) { |
| 539 | canvas->drawCircle(pts[i].fX, pts[i].fY, 3.f, choppedPtPaint); |
| 540 | } |
| 541 | |
| 542 | SkRect bounds; |
| 543 | bounds.set(pts, 3); |
| 544 | |
| 545 | SkPaint boundsPaint; |
| 546 | boundsPaint.setColor(0xff808080); |
| 547 | boundsPaint.setStrokeWidth(0); |
| 548 | boundsPaint.setStyle(SkPaint::kStroke_Style); |
| 549 | canvas->drawRect(bounds, boundsPaint); |
| 550 | |
robertphillips | 28a838e | 2016-06-23 14:07:00 -0700 | [diff] [blame] | 551 | GrPaint grPaint; |
Brian Salomon | a163392 | 2017-01-09 11:46:10 -0500 | [diff] [blame] | 552 | grPaint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc)); |
joshualitt | 3f284d7 | 2015-02-11 11:34:58 -0800 | [diff] [blame] | 553 | |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 554 | GrPathUtils::QuadUVMatrix DevToUV(pts); |
| 555 | |
Brian Salomon | 649a341 | 2017-03-09 13:50:43 -0500 | [diff] [blame] | 556 | std::unique_ptr<GrMeshDrawOp> op = |
Brian Salomon | f833478 | 2017-01-03 09:42:58 -0500 | [diff] [blame] | 557 | BezierQuadTestOp::Make(gp, bounds, color, DevToUV); |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 558 | |
Brian Salomon | 649a341 | 2017-03-09 13:50:43 -0500 | [diff] [blame] | 559 | renderTargetContext->priv().testingOnly_addMeshDrawOp( |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 560 | std::move(grPaint), GrAAType::kNone, std::move(op)); |
commit-bot@chromium.org | 53a0b6c | 2013-08-23 18:05:01 +0000 | [diff] [blame] | 561 | } |
| 562 | ++col; |
| 563 | if (numCols == col) { |
| 564 | col = 0; |
| 565 | ++row; |
| 566 | } |
| 567 | } |
| 568 | } |
| 569 | } |
| 570 | |
| 571 | private: |
| 572 | typedef GM INHERITED; |
| 573 | }; |
| 574 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 575 | DEF_GM(return new BezierCubicEffects;) |
| 576 | DEF_GM(return new BezierConicEffects;) |
| 577 | DEF_GM(return new BezierQuadEffects;) |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | #endif |