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