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