commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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 | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 12 | #include "GrContext.h" |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 13 | #include "GrDefaultGeoProcFactory.h" |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 14 | #include "GrMemoryPool.h" |
Brian Salomon | 576eda1 | 2017-07-14 11:30:17 -0400 | [diff] [blame] | 15 | #include "GrOpFlushState.h" |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 16 | #include "GrPathUtils.h" |
Brian Salomon | 576eda1 | 2017-07-14 11:30:17 -0400 | [diff] [blame] | 17 | #include "GrRenderTargetContextPriv.h" |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 18 | #include "GrTest.h" |
| 19 | #include "SkColorPriv.h" |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 20 | #include "SkGeometry.h" |
Cary Clark | 74f623d | 2017-11-06 20:02:02 -0500 | [diff] [blame] | 21 | #include "SkPointPriv.h" |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 22 | #include "SkTLList.h" |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 23 | #include "effects/GrConvexPolyEffect.h" |
Brian Salomon | 576eda1 | 2017-07-14 11:30:17 -0400 | [diff] [blame] | 24 | #include "ops/GrMeshDrawOp.h" |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 25 | |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 26 | /** outset rendered rect to visualize anti-aliased poly edges */ |
| 27 | static SkRect outset(const SkRect& unsorted) { |
| 28 | SkRect r = unsorted; |
| 29 | r.outset(5.f, 5.f); |
| 30 | return r; |
| 31 | } |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 32 | |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 33 | /** sorts a rect */ |
| 34 | static SkRect sorted_rect(const SkRect& unsorted) { |
| 35 | SkRect r = unsorted; |
| 36 | r.sort(); |
| 37 | return r; |
| 38 | } |
| 39 | |
| 40 | namespace skiagm { |
Brian Salomon | 576eda1 | 2017-07-14 11:30:17 -0400 | [diff] [blame] | 41 | class PolyBoundsOp : public GrMeshDrawOp { |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 42 | public: |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 43 | DEFINE_OP_CLASS_ID |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 44 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 45 | static std::unique_ptr<GrDrawOp> Make(GrContext* context, |
| 46 | GrPaint&& paint, |
| 47 | const SkRect& rect) { |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 48 | GrOpMemoryPool* pool = context->contextPriv().opMemoryPool(); |
| 49 | |
| 50 | return pool->allocate<PolyBoundsOp>(std::move(paint), rect); |
Brian Salomon | 576eda1 | 2017-07-14 11:30:17 -0400 | [diff] [blame] | 51 | } |
| 52 | |
Robert Phillips | b493eeb | 2017-09-13 13:10:52 -0400 | [diff] [blame] | 53 | const char* name() const override { return "PolyBoundsOp"; } |
| 54 | |
Robert Phillips | f1748f5 | 2017-09-14 14:11:24 -0400 | [diff] [blame] | 55 | void visitProxies(const VisitProxyFunc& func) const override { |
Robert Phillips | b493eeb | 2017-09-13 13:10:52 -0400 | [diff] [blame] | 56 | fProcessors.visitProxies(func); |
| 57 | } |
| 58 | |
Brian Salomon | 576eda1 | 2017-07-14 11:30:17 -0400 | [diff] [blame] | 59 | FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; } |
| 60 | |
Brian Osman | 532b3f9 | 2018-07-11 10:02:07 -0400 | [diff] [blame] | 61 | RequiresDstTexture finalize(const GrCaps& caps, const GrAppliedClip* clip) override { |
Brian Osman | 9a725dd | 2017-09-20 09:53:22 -0400 | [diff] [blame] | 62 | auto analysis = fProcessors.finalize(fColor, GrProcessorAnalysisCoverage::kNone, clip, |
Brian Osman | 532b3f9 | 2018-07-11 10:02:07 -0400 | [diff] [blame] | 63 | false, caps, &fColor); |
Brian Salomon | 576eda1 | 2017-07-14 11:30:17 -0400 | [diff] [blame] | 64 | return analysis.requiresDstTexture() ? RequiresDstTexture::kYes : RequiresDstTexture::kNo; |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | private: |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 68 | friend class ::GrOpMemoryPool; // for ctor |
| 69 | |
Brian Salomon | 576eda1 | 2017-07-14 11:30:17 -0400 | [diff] [blame] | 70 | PolyBoundsOp(GrPaint&& paint, const SkRect& rect) |
| 71 | : INHERITED(ClassID()) |
| 72 | , fColor(paint.getColor()) |
| 73 | , fProcessors(std::move(paint)) |
| 74 | , fRect(outset(rect)) { |
| 75 | this->setBounds(sorted_rect(fRect), HasAABloat::kNo, IsZeroArea::kNo); |
| 76 | } |
Brian Salomon | 6b316e9 | 2016-12-16 09:35:49 -0500 | [diff] [blame] | 77 | |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 78 | void onPrepareDraws(Target* target) override { |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 79 | using namespace GrDefaultGeoProcFactory; |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 80 | |
Brian Salomon | 576eda1 | 2017-07-14 11:30:17 -0400 | [diff] [blame] | 81 | Color color(fColor); |
Brian Salomon | 8c852be | 2017-01-04 10:44:42 -0500 | [diff] [blame] | 82 | sk_sp<GrGeometryProcessor> gp(GrDefaultGeoProcFactory::Make( |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 83 | target->caps().shaderCaps(), |
| 84 | color, |
| 85 | Coverage::kSolid_Type, |
| 86 | LocalCoords::kUnused_Type, |
| 87 | SkMatrix::I())); |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 88 | |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 89 | SkASSERT(gp->debugOnly_vertexStride() == sizeof(SkPoint)); |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 90 | QuadHelper helper(target, sizeof(SkPoint), 1); |
| 91 | SkPoint* verts = reinterpret_cast<SkPoint*>(helper.vertices()); |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 92 | if (!verts) { |
joshualitt | 4b31de8 | 2015-03-05 14:33:41 -0800 | [diff] [blame] | 93 | return; |
| 94 | } |
| 95 | |
Brian Salomon | ec42e15 | 2018-05-18 12:52:22 -0400 | [diff] [blame] | 96 | SkPointPriv::SetRectTriStrip(verts, fRect, sizeof(SkPoint)); |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 97 | |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 98 | auto pipe = target->makePipeline(0, std::move(fProcessors), target->detachAppliedClip()); |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 99 | helper.recordDraw(target, std::move(gp), pipe.fPipeline, pipe.fFixedDynamicState); |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 100 | } |
| 101 | |
Brian Salomon | 576eda1 | 2017-07-14 11:30:17 -0400 | [diff] [blame] | 102 | GrColor fColor; |
| 103 | GrProcessorSet fProcessors; |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 104 | SkRect fRect; |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 105 | |
Brian Salomon | 576eda1 | 2017-07-14 11:30:17 -0400 | [diff] [blame] | 106 | typedef GrMeshDrawOp INHERITED; |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 107 | }; |
| 108 | |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 109 | /** |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 110 | * This GM directly exercises a GrProcessor that draws convex polygons. |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 111 | */ |
| 112 | class ConvexPolyEffect : public GM { |
| 113 | public: |
| 114 | ConvexPolyEffect() { |
| 115 | this->setBGColor(0xFFFFFFFF); |
| 116 | } |
| 117 | |
| 118 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 119 | SkString onShortName() override { |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 120 | return SkString("convex_poly_effect"); |
| 121 | } |
| 122 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 123 | SkISize onISize() override { |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 124 | return SkISize::Make(720, 800); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 125 | } |
| 126 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 127 | void onOnceBeforeDraw() override { |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 128 | SkPath tri; |
| 129 | tri.moveTo(5.f, 5.f); |
| 130 | tri.lineTo(100.f, 20.f); |
| 131 | tri.lineTo(15.f, 100.f); |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 132 | |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 133 | fPaths.addToTail(tri); |
| 134 | fPaths.addToTail(SkPath())->reverseAddPath(tri); |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 135 | |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 136 | tri.close(); |
| 137 | fPaths.addToTail(tri); |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 138 | |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 139 | SkPath ngon; |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 140 | constexpr SkScalar kRadius = 50.f; |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 141 | const SkPoint center = { kRadius, kRadius }; |
| 142 | for (int i = 0; i < GrConvexPolyEffect::kMaxEdges; ++i) { |
| 143 | SkScalar angle = 2 * SK_ScalarPI * i / GrConvexPolyEffect::kMaxEdges; |
| 144 | SkPoint point; |
| 145 | point.fY = SkScalarSinCos(angle, &point.fX); |
| 146 | point.scale(kRadius); |
| 147 | point = center + point; |
| 148 | if (0 == i) { |
| 149 | ngon.moveTo(point); |
| 150 | } else { |
| 151 | ngon.lineTo(point); |
| 152 | } |
| 153 | } |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 154 | |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 155 | fPaths.addToTail(ngon); |
| 156 | SkMatrix scaleM; |
| 157 | scaleM.setScale(1.1f, 0.4f); |
| 158 | ngon.transform(scaleM); |
| 159 | fPaths.addToTail(ngon); |
skia.committer@gmail.com | f0b0cda | 2014-02-09 03:02:01 +0000 | [diff] [blame] | 160 | |
bsalomon | 7888de0 | 2016-03-28 15:04:45 -0700 | [diff] [blame] | 161 | SkPath linePath; |
| 162 | linePath.moveTo(5.f, 5.f); |
| 163 | linePath.lineTo(6.f, 6.f); |
| 164 | fPaths.addToTail(linePath); |
| 165 | |
commit-bot@chromium.org | f053980 | 2014-02-08 19:31:05 +0000 | [diff] [blame] | 166 | // integer edges |
| 167 | fRects.addToTail(SkRect::MakeLTRB(5.f, 1.f, 30.f, 25.f)); |
| 168 | // half-integer edges |
| 169 | fRects.addToTail(SkRect::MakeLTRB(5.5f, 0.5f, 29.5f, 24.5f)); |
| 170 | // vertically/horizontally thin rects that cover pixel centers |
| 171 | fRects.addToTail(SkRect::MakeLTRB(5.25f, 0.5f, 5.75f, 24.5f)); |
| 172 | fRects.addToTail(SkRect::MakeLTRB(5.5f, 0.5f, 29.5f, 0.75f)); |
| 173 | // vertically/horizontally thin rects that don't cover pixel centers |
| 174 | fRects.addToTail(SkRect::MakeLTRB(5.55f, 0.5f, 5.75f, 24.5f)); |
| 175 | fRects.addToTail(SkRect::MakeLTRB(5.5f, .05f, 29.5f, .25f)); |
| 176 | // small in x and y |
| 177 | fRects.addToTail(SkRect::MakeLTRB(5.05f, .55f, 5.45f, .85f)); |
| 178 | // inverted in x and y |
| 179 | fRects.addToTail(SkRect::MakeLTRB(100.f, 50.5f, 5.f, 0.5f)); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 180 | } |
| 181 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 182 | void onDraw(SkCanvas* canvas) override { |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 183 | GrRenderTargetContext* renderTargetContext = |
| 184 | canvas->internal_private_accessTopLayerRenderTargetContext(); |
| 185 | if (!renderTargetContext) { |
robertphillips | 175dd9b | 2016-04-28 14:32:04 -0700 | [diff] [blame] | 186 | skiagm::GM::DrawGpuOnlyMessage(canvas); |
joshualitt | f5883a6 | 2016-01-13 07:47:38 -0800 | [diff] [blame] | 187 | return; |
| 188 | } |
| 189 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 190 | GrContext* context = canvas->getGrContext(); |
| 191 | if (!context) { |
| 192 | return; |
| 193 | } |
| 194 | |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 195 | SkScalar y = 0; |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 196 | constexpr SkScalar kDX = 12.f; |
bsalomon | f045d60 | 2015-11-18 19:01:12 -0800 | [diff] [blame] | 197 | for (PathList::Iter iter(fPaths, PathList::Iter::kHead_IterStart); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 198 | iter.get(); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 199 | iter.next()) { |
commit-bot@chromium.org | f053980 | 2014-02-08 19:31:05 +0000 | [diff] [blame] | 200 | const SkPath* path = iter.get(); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 201 | SkScalar x = 0; |
| 202 | |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 203 | for (int et = 0; et < kGrClipEdgeTypeCnt; ++et) { |
robertphillips | 1d24b8d | 2015-03-26 19:57:08 -0700 | [diff] [blame] | 204 | const SkMatrix m = SkMatrix::MakeTrans(x, y); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 205 | SkPath p; |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 206 | path->transform(m, &p); |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 207 | |
Ethan Nicholas | 0f3c732 | 2017-11-09 14:51:17 -0500 | [diff] [blame] | 208 | GrClipEdgeType edgeType = (GrClipEdgeType) et; |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 209 | std::unique_ptr<GrFragmentProcessor> fp(GrConvexPolyEffect::Make(edgeType, p)); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 210 | if (!fp) { |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 211 | continue; |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 212 | } |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 213 | |
robertphillips | 28a838e | 2016-06-23 14:07:00 -0700 | [diff] [blame] | 214 | GrPaint grPaint; |
Brian Salomon | 576eda1 | 2017-07-14 11:30:17 -0400 | [diff] [blame] | 215 | grPaint.setColor4f(GrColor4f(0, 0, 0, 1.f)); |
Brian Salomon | a163392 | 2017-01-09 11:46:10 -0500 | [diff] [blame] | 216 | grPaint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc)); |
robertphillips | 28a838e | 2016-06-23 14:07:00 -0700 | [diff] [blame] | 217 | grPaint.addCoverageFragmentProcessor(std::move(fp)); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 218 | |
Brian Salomon | 576eda1 | 2017-07-14 11:30:17 -0400 | [diff] [blame] | 219 | std::unique_ptr<GrDrawOp> op = |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 220 | PolyBoundsOp::Make(context, std::move(grPaint), p.getBounds()); |
Brian Salomon | 576eda1 | 2017-07-14 11:30:17 -0400 | [diff] [blame] | 221 | renderTargetContext->priv().testingOnly_addDrawOp(std::move(op)); |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 222 | |
bsalomon | 7888de0 | 2016-03-28 15:04:45 -0700 | [diff] [blame] | 223 | x += SkScalarCeilToScalar(path->getBounds().width() + kDX); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 224 | } |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 225 | |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 226 | // Draw AA and non AA paths using normal API for reference. |
| 227 | canvas->save(); |
| 228 | canvas->translate(x, y); |
| 229 | SkPaint paint; |
| 230 | canvas->drawPath(*path, paint); |
| 231 | canvas->translate(path->getBounds().width() + 10.f, 0); |
| 232 | paint.setAntiAlias(true); |
| 233 | canvas->drawPath(*path, paint); |
| 234 | canvas->restore(); |
skia.committer@gmail.com | 4c18e9f | 2014-01-31 03:01:59 +0000 | [diff] [blame] | 235 | |
commit-bot@chromium.org | f053980 | 2014-02-08 19:31:05 +0000 | [diff] [blame] | 236 | y += SkScalarCeilToScalar(path->getBounds().height() + 20.f); |
| 237 | } |
| 238 | |
bsalomon | f045d60 | 2015-11-18 19:01:12 -0800 | [diff] [blame] | 239 | for (RectList::Iter iter(fRects, RectList::Iter::kHead_IterStart); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 240 | iter.get(); |
commit-bot@chromium.org | f053980 | 2014-02-08 19:31:05 +0000 | [diff] [blame] | 241 | iter.next()) { |
| 242 | |
| 243 | SkScalar x = 0; |
| 244 | |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 245 | for (int et = 0; et < kGrClipEdgeTypeCnt; ++et) { |
commit-bot@chromium.org | d85f32c | 2014-02-28 14:43:26 +0000 | [diff] [blame] | 246 | SkRect rect = *iter.get(); |
| 247 | rect.offset(x, y); |
Ethan Nicholas | 0f3c732 | 2017-11-09 14:51:17 -0500 | [diff] [blame] | 248 | GrClipEdgeType edgeType = (GrClipEdgeType) et; |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 249 | std::unique_ptr<GrFragmentProcessor> fp(GrConvexPolyEffect::Make(edgeType, rect)); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 250 | if (!fp) { |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 251 | continue; |
commit-bot@chromium.org | d85f32c | 2014-02-28 14:43:26 +0000 | [diff] [blame] | 252 | } |
| 253 | |
robertphillips | 28a838e | 2016-06-23 14:07:00 -0700 | [diff] [blame] | 254 | GrPaint grPaint; |
Brian Salomon | 576eda1 | 2017-07-14 11:30:17 -0400 | [diff] [blame] | 255 | grPaint.setColor4f(GrColor4f(0, 0, 0, 1.f)); |
Brian Salomon | a163392 | 2017-01-09 11:46:10 -0500 | [diff] [blame] | 256 | grPaint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc)); |
robertphillips | 28a838e | 2016-06-23 14:07:00 -0700 | [diff] [blame] | 257 | grPaint.addCoverageFragmentProcessor(std::move(fp)); |
commit-bot@chromium.org | d85f32c | 2014-02-28 14:43:26 +0000 | [diff] [blame] | 258 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 259 | std::unique_ptr<GrDrawOp> op = PolyBoundsOp::Make(context, std::move(grPaint), |
| 260 | rect); |
Brian Salomon | 576eda1 | 2017-07-14 11:30:17 -0400 | [diff] [blame] | 261 | renderTargetContext->priv().testingOnly_addDrawOp(std::move(op)); |
commit-bot@chromium.org | d85f32c | 2014-02-28 14:43:26 +0000 | [diff] [blame] | 262 | |
bsalomon | 7888de0 | 2016-03-28 15:04:45 -0700 | [diff] [blame] | 263 | x += SkScalarCeilToScalar(rect.width() + kDX); |
commit-bot@chromium.org | f053980 | 2014-02-08 19:31:05 +0000 | [diff] [blame] | 264 | } |
| 265 | |
commit-bot@chromium.org | d85f32c | 2014-02-28 14:43:26 +0000 | [diff] [blame] | 266 | // Draw rect without and with AA using normal API for reference |
commit-bot@chromium.org | f053980 | 2014-02-08 19:31:05 +0000 | [diff] [blame] | 267 | canvas->save(); |
| 268 | canvas->translate(x, y); |
| 269 | SkPaint paint; |
commit-bot@chromium.org | d85f32c | 2014-02-28 14:43:26 +0000 | [diff] [blame] | 270 | canvas->drawRect(*iter.get(), paint); |
bsalomon | 7888de0 | 2016-03-28 15:04:45 -0700 | [diff] [blame] | 271 | x += SkScalarCeilToScalar(iter.get()->width() + kDX); |
commit-bot@chromium.org | f053980 | 2014-02-08 19:31:05 +0000 | [diff] [blame] | 272 | paint.setAntiAlias(true); |
| 273 | canvas->drawRect(*iter.get(), paint); |
| 274 | canvas->restore(); |
| 275 | |
commit-bot@chromium.org | d85f32c | 2014-02-28 14:43:26 +0000 | [diff] [blame] | 276 | y += SkScalarCeilToScalar(iter.get()->height() + 20.f); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 277 | } |
| 278 | } |
| 279 | |
| 280 | private: |
bsalomon | f045d60 | 2015-11-18 19:01:12 -0800 | [diff] [blame] | 281 | typedef SkTLList<SkPath, 1> PathList; |
| 282 | typedef SkTLList<SkRect, 1> RectList; |
| 283 | PathList fPaths; |
| 284 | RectList fRects; |
skia.committer@gmail.com | f0b0cda | 2014-02-09 03:02:01 +0000 | [diff] [blame] | 285 | |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 286 | typedef GM INHERITED; |
| 287 | }; |
| 288 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 289 | DEF_GM(return new ConvexPolyEffect;) |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 290 | } |