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