senorblanco | d6ed19c | 2015-02-26 06:58:17 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | |
Chris Dalton | 17dc418 | 2020-03-25 16:18:16 -0600 | [diff] [blame] | 8 | #include "src/gpu/ops/GrTriangulatingPathRenderer.h" |
Brian Salomon | 71fe945 | 2020-03-02 16:59:40 -0500 | [diff] [blame] | 9 | |
| 10 | #include "include/private/SkIDChangeListener.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "src/core/SkGeometry.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 12 | #include "src/gpu/GrAuditTrail.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "src/gpu/GrCaps.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "src/gpu/GrDefaultGeoProcFactory.h" |
| 15 | #include "src/gpu/GrDrawOpTest.h" |
Chris Dalton | d081dce | 2020-01-23 12:09:04 -0700 | [diff] [blame] | 16 | #include "src/gpu/GrEagerVertexAllocator.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 17 | #include "src/gpu/GrOpFlushState.h" |
Robert Phillips | 740d34f | 2020-03-11 09:36:13 -0400 | [diff] [blame] | 18 | #include "src/gpu/GrProgramInfo.h" |
Robert Phillips | 3ac83b2f | 2020-10-26 13:50:57 -0400 | [diff] [blame^] | 19 | #include "src/gpu/GrRecordingContextPriv.h" |
Michael Ludwig | 7c12e28 | 2020-05-29 09:54:07 -0400 | [diff] [blame] | 20 | #include "src/gpu/GrRenderTargetContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 21 | #include "src/gpu/GrResourceCache.h" |
| 22 | #include "src/gpu/GrResourceProvider.h" |
Chris Dalton | eb694b7 | 2020-03-16 09:25:50 -0600 | [diff] [blame] | 23 | #include "src/gpu/GrSimpleMesh.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 24 | #include "src/gpu/GrStyle.h" |
Robert Phillips | 3ac83b2f | 2020-10-26 13:50:57 -0400 | [diff] [blame^] | 25 | #include "src/gpu/GrThreadSafeCache.h" |
Chris Dalton | 17dc418 | 2020-03-25 16:18:16 -0600 | [diff] [blame] | 26 | #include "src/gpu/GrTriangulator.h" |
Michael Ludwig | 663afe5 | 2019-06-03 16:46:19 -0400 | [diff] [blame] | 27 | #include "src/gpu/geometry/GrPathUtils.h" |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 28 | #include "src/gpu/geometry/GrStyledShape.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 29 | #include "src/gpu/ops/GrMeshDrawOp.h" |
Robert Phillips | 55f681f | 2020-02-28 08:58:15 -0500 | [diff] [blame] | 30 | #include "src/gpu/ops/GrSimpleMeshDrawOpHelperWithStencil.h" |
joshualitt | 7441782 | 2015-08-07 11:42:16 -0700 | [diff] [blame] | 31 | |
Chris Dalton | 17dc418 | 2020-03-25 16:18:16 -0600 | [diff] [blame] | 32 | #include <cstdio> |
Brian Salomon | 71fe945 | 2020-03-02 16:59:40 -0500 | [diff] [blame] | 33 | |
Stephen White | a7701e0 | 2018-01-23 15:35:05 -0500 | [diff] [blame] | 34 | #ifndef GR_AA_TESSELLATOR_MAX_VERB_COUNT |
| 35 | #define GR_AA_TESSELLATOR_MAX_VERB_COUNT 10 |
| 36 | #endif |
| 37 | |
senorblanco | d6ed19c | 2015-02-26 06:58:17 -0800 | [diff] [blame] | 38 | /* |
Chris Dalton | 17dc418 | 2020-03-25 16:18:16 -0600 | [diff] [blame] | 39 | * This path renderer linearizes and decomposes the path into triangles using GrTriangulator, |
| 40 | * uploads the triangles to a vertex buffer, and renders them with a single draw call. It can do |
| 41 | * screenspace antialiasing with a one-pixel coverage ramp. |
senorblanco | d6ed19c | 2015-02-26 06:58:17 -0800 | [diff] [blame] | 42 | */ |
senorblanco | d6ed19c | 2015-02-26 06:58:17 -0800 | [diff] [blame] | 43 | namespace { |
| 44 | |
Robert Phillips | 3ac83b2f | 2020-10-26 13:50:57 -0400 | [diff] [blame^] | 45 | // The TessInfo struct contains ancillary data not specifically required for the triangle |
| 46 | // data (which is stored in a GrThreadSafeCache::VertexData object). |
| 47 | // The 'fNumVertices' field is a temporary exception. It is still needed to support the |
| 48 | // AA triangulated path case - which doesn't use the GrThreadSafeCache nor the VertexData object). |
| 49 | // When there is an associated VertexData, its numVertices should always match the TessInfo's |
| 50 | // value. |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 51 | struct TessInfo { |
Robert Phillips | 3ac83b2f | 2020-10-26 13:50:57 -0400 | [diff] [blame^] | 52 | int fNumVertices; |
| 53 | int fNumCountedCurves; |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 54 | SkScalar fTolerance; |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 55 | }; |
| 56 | |
Robert Phillips | 3ac83b2f | 2020-10-26 13:50:57 -0400 | [diff] [blame^] | 57 | static sk_sp<SkData> create_data(int numVertices, int numCountedCurves, SkScalar tol) { |
| 58 | TessInfo info { numVertices, numCountedCurves, tol }; |
Robert Phillips | 6cc9d8d | 2020-10-20 09:42:33 -0400 | [diff] [blame] | 59 | return SkData::MakeWithCopy(&info, sizeof(info)); |
| 60 | } |
| 61 | |
Robert Phillips | 3ac83b2f | 2020-10-26 13:50:57 -0400 | [diff] [blame^] | 62 | bool cache_match(const SkData* data, SkScalar tol, |
| 63 | int* actualNumVertices, int* actualNumCountedCurves) { |
Robert Phillips | 6cc9d8d | 2020-10-20 09:42:33 -0400 | [diff] [blame] | 64 | SkASSERT(data); |
| 65 | |
| 66 | const TessInfo* info = static_cast<const TessInfo*>(data->data()); |
Robert Phillips | 3ac83b2f | 2020-10-26 13:50:57 -0400 | [diff] [blame^] | 67 | if (info->fNumCountedCurves == 0 || info->fTolerance < 3.0f * tol) { |
| 68 | if (actualNumVertices) { |
| 69 | *actualNumVertices = info->fNumVertices; |
| 70 | } |
| 71 | if (actualNumCountedCurves) { |
| 72 | *actualNumCountedCurves = info->fNumCountedCurves; |
| 73 | } |
Robert Phillips | 6cc9d8d | 2020-10-20 09:42:33 -0400 | [diff] [blame] | 74 | return true; |
| 75 | } |
| 76 | return false; |
| 77 | } |
| 78 | |
ethannicholas | e9709e8 | 2016-01-07 13:34:16 -0800 | [diff] [blame] | 79 | // When the SkPathRef genID changes, invalidate a corresponding GrResource described by key. |
Brian Salomon | 99a813c | 2020-03-02 12:50:47 -0500 | [diff] [blame] | 80 | class UniqueKeyInvalidator : public SkIDChangeListener { |
ethannicholas | e9709e8 | 2016-01-07 13:34:16 -0800 | [diff] [blame] | 81 | public: |
Brian Salomon | 99a813c | 2020-03-02 12:50:47 -0500 | [diff] [blame] | 82 | UniqueKeyInvalidator(const GrUniqueKey& key, uint32_t contextUniqueID) |
Brian Salomon | 238069b | 2018-07-11 15:58:57 -0400 | [diff] [blame] | 83 | : fMsg(key, contextUniqueID) {} |
| 84 | |
ethannicholas | e9709e8 | 2016-01-07 13:34:16 -0800 | [diff] [blame] | 85 | private: |
| 86 | GrUniqueKeyInvalidatedMessage fMsg; |
| 87 | |
Brian Salomon | 99a813c | 2020-03-02 12:50:47 -0500 | [diff] [blame] | 88 | void changed() override { SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(fMsg); } |
ethannicholas | e9709e8 | 2016-01-07 13:34:16 -0800 | [diff] [blame] | 89 | }; |
| 90 | |
Chris Dalton | d081dce | 2020-01-23 12:09:04 -0700 | [diff] [blame] | 91 | class StaticVertexAllocator : public GrEagerVertexAllocator { |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 92 | public: |
Chris Dalton | d081dce | 2020-01-23 12:09:04 -0700 | [diff] [blame] | 93 | StaticVertexAllocator(GrResourceProvider* resourceProvider, bool canMapVB) |
Robert Phillips | 6ffcb23 | 2020-10-14 12:40:13 -0400 | [diff] [blame] | 94 | : fResourceProvider(resourceProvider) |
| 95 | , fCanMapVB(canMapVB) |
| 96 | , fVertices(nullptr) { |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 97 | } |
Robert Phillips | 6ffcb23 | 2020-10-14 12:40:13 -0400 | [diff] [blame] | 98 | |
Chris Dalton | d081dce | 2020-01-23 12:09:04 -0700 | [diff] [blame] | 99 | #ifdef SK_DEBUG |
| 100 | ~StaticVertexAllocator() override { |
| 101 | SkASSERT(!fLockStride); |
| 102 | } |
| 103 | #endif |
| 104 | void* lock(size_t stride, int eagerCount) override { |
| 105 | SkASSERT(!fLockStride); |
| 106 | SkASSERT(stride); |
| 107 | size_t size = eagerCount * stride; |
Brian Salomon | ae64c19 | 2019-02-05 09:41:37 -0500 | [diff] [blame] | 108 | fVertexBuffer = fResourceProvider->createBuffer(size, GrGpuBufferType::kVertex, |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 109 | kStatic_GrAccessPattern); |
John Stiles | a008b0f | 2020-08-16 08:48:02 -0400 | [diff] [blame] | 110 | if (!fVertexBuffer) { |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 111 | return nullptr; |
| 112 | } |
| 113 | if (fCanMapVB) { |
senorblanco | f57372d | 2016-08-31 10:36:19 -0700 | [diff] [blame] | 114 | fVertices = fVertexBuffer->map(); |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 115 | } else { |
Chris Dalton | d081dce | 2020-01-23 12:09:04 -0700 | [diff] [blame] | 116 | fVertices = sk_malloc_throw(eagerCount * stride); |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 117 | } |
Chris Dalton | d081dce | 2020-01-23 12:09:04 -0700 | [diff] [blame] | 118 | fLockStride = stride; |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 119 | return fVertices; |
| 120 | } |
| 121 | void unlock(int actualCount) override { |
Chris Dalton | d081dce | 2020-01-23 12:09:04 -0700 | [diff] [blame] | 122 | SkASSERT(fLockStride); |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 123 | if (fCanMapVB) { |
| 124 | fVertexBuffer->unmap(); |
| 125 | } else { |
Chris Dalton | d081dce | 2020-01-23 12:09:04 -0700 | [diff] [blame] | 126 | fVertexBuffer->updateData(fVertices, actualCount * fLockStride); |
senorblanco | f57372d | 2016-08-31 10:36:19 -0700 | [diff] [blame] | 127 | sk_free(fVertices); |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 128 | } |
| 129 | fVertices = nullptr; |
Chris Dalton | d081dce | 2020-01-23 12:09:04 -0700 | [diff] [blame] | 130 | fLockStride = 0; |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 131 | } |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 132 | sk_sp<GrGpuBuffer> detachVertexBuffer() { return std::move(fVertexBuffer); } |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 133 | |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 134 | private: |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 135 | sk_sp<GrGpuBuffer> fVertexBuffer; |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 136 | GrResourceProvider* fResourceProvider; |
| 137 | bool fCanMapVB; |
senorblanco | f57372d | 2016-08-31 10:36:19 -0700 | [diff] [blame] | 138 | void* fVertices; |
Chris Dalton | d081dce | 2020-01-23 12:09:04 -0700 | [diff] [blame] | 139 | size_t fLockStride = 0; |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 140 | }; |
| 141 | |
ethannicholas | e9709e8 | 2016-01-07 13:34:16 -0800 | [diff] [blame] | 142 | } // namespace |
senorblanco | d6ed19c | 2015-02-26 06:58:17 -0800 | [diff] [blame] | 143 | |
Robert Phillips | 3ac83b2f | 2020-10-26 13:50:57 -0400 | [diff] [blame^] | 144 | |
Chris Dalton | 17dc418 | 2020-03-25 16:18:16 -0600 | [diff] [blame] | 145 | GrTriangulatingPathRenderer::GrTriangulatingPathRenderer() |
Stephen White | 8a3c059 | 2019-05-29 11:26:16 -0400 | [diff] [blame] | 146 | : fMaxVerbCount(GR_AA_TESSELLATOR_MAX_VERB_COUNT) { |
senorblanco | d6ed19c | 2015-02-26 06:58:17 -0800 | [diff] [blame] | 147 | } |
| 148 | |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 149 | GrPathRenderer::CanDrawPath |
Chris Dalton | 17dc418 | 2020-03-25 16:18:16 -0600 | [diff] [blame] | 150 | GrTriangulatingPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const { |
Chris Dalton | e5ede4b | 2017-09-07 18:33:08 +0000 | [diff] [blame] | 151 | // This path renderer can draw fill styles, and can do screenspace antialiasing via a |
| 152 | // one-pixel coverage ramp. It can do convex and concave paths, but we'll leave the convex |
| 153 | // ones to simpler algorithms. We pass on paths that have styles, though they may come back |
Chris Dalton | 09e5689 | 2019-03-13 00:22:01 -0600 | [diff] [blame] | 154 | // around after applying the styling information to the geometry to create a filled path. |
Chris Dalton | e5ede4b | 2017-09-07 18:33:08 +0000 | [diff] [blame] | 155 | if (!args.fShape->style().isSimpleFill() || args.fShape->knownToBeConvex()) { |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 156 | return CanDrawPath::kNo; |
senorblanco | f57372d | 2016-08-31 10:36:19 -0700 | [diff] [blame] | 157 | } |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 158 | switch (args.fAAType) { |
| 159 | case GrAAType::kNone: |
| 160 | case GrAAType::kMSAA: |
| 161 | // Prefer MSAA, if any antialiasing. In the non-analytic-AA case, We skip paths that |
| 162 | // don't have a key since the real advantage of this path renderer comes from caching |
| 163 | // the tessellated geometry. |
| 164 | if (!args.fShape->hasUnstyledKey()) { |
| 165 | return CanDrawPath::kNo; |
| 166 | } |
| 167 | break; |
| 168 | case GrAAType::kCoverage: |
| 169 | // Use analytic AA if we don't have MSAA. In this case, we do not cache, so we accept |
| 170 | // paths without keys. |
| 171 | SkPath path; |
| 172 | args.fShape->asPath(&path); |
| 173 | if (path.countVerbs() > fMaxVerbCount) { |
| 174 | return CanDrawPath::kNo; |
| 175 | } |
| 176 | break; |
senorblanco | f57372d | 2016-08-31 10:36:19 -0700 | [diff] [blame] | 177 | } |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 178 | return CanDrawPath::kYes; |
senorblanco | d6ed19c | 2015-02-26 06:58:17 -0800 | [diff] [blame] | 179 | } |
| 180 | |
Brian Salomon | 9530f7e | 2017-07-11 09:03:10 -0400 | [diff] [blame] | 181 | namespace { |
| 182 | |
Chris Dalton | 17dc418 | 2020-03-25 16:18:16 -0600 | [diff] [blame] | 183 | class TriangulatingPathOp final : public GrMeshDrawOp { |
Brian Salomon | 9530f7e | 2017-07-11 09:03:10 -0400 | [diff] [blame] | 184 | private: |
| 185 | using Helper = GrSimpleMeshDrawOpHelperWithStencil; |
| 186 | |
senorblanco | 9ba3972 | 2015-03-05 07:13:42 -0800 | [diff] [blame] | 187 | public: |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 188 | DEFINE_OP_CLASS_ID |
senorblanco | 9ba3972 | 2015-03-05 07:13:42 -0800 | [diff] [blame] | 189 | |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 190 | static GrOp::Owner Make(GrRecordingContext* context, |
| 191 | GrPaint&& paint, |
| 192 | const GrStyledShape& shape, |
| 193 | const SkMatrix& viewMatrix, |
| 194 | SkIRect devClipBounds, |
| 195 | GrAAType aaType, |
| 196 | const GrUserStencilSettings* stencilSettings) { |
Chris Dalton | 17dc418 | 2020-03-25 16:18:16 -0600 | [diff] [blame] | 197 | return Helper::FactoryHelper<TriangulatingPathOp>(context, std::move(paint), shape, |
| 198 | viewMatrix, devClipBounds, aaType, |
| 199 | stencilSettings); |
senorblanco | 9ba3972 | 2015-03-05 07:13:42 -0800 | [diff] [blame] | 200 | } |
| 201 | |
Chris Dalton | 17dc418 | 2020-03-25 16:18:16 -0600 | [diff] [blame] | 202 | const char* name() const override { return "TriangulatingPathOp"; } |
senorblanco | 9ba3972 | 2015-03-05 07:13:42 -0800 | [diff] [blame] | 203 | |
Chris Dalton | 1706cbf | 2019-05-21 19:35:29 -0600 | [diff] [blame] | 204 | void visitProxies(const VisitProxyFunc& func) const override { |
Robert Phillips | 740d34f | 2020-03-11 09:36:13 -0400 | [diff] [blame] | 205 | if (fProgramInfo) { |
Chris Dalton | be45742 | 2020-03-16 18:05:03 -0600 | [diff] [blame] | 206 | fProgramInfo->visitFPProxies(func); |
Robert Phillips | 740d34f | 2020-03-11 09:36:13 -0400 | [diff] [blame] | 207 | } else { |
| 208 | fHelper.visitProxies(func); |
| 209 | } |
Robert Phillips | b493eeb | 2017-09-13 13:10:52 -0400 | [diff] [blame] | 210 | } |
| 211 | |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 212 | TriangulatingPathOp(GrProcessorSet* processorSet, |
Chris Dalton | 17dc418 | 2020-03-25 16:18:16 -0600 | [diff] [blame] | 213 | const SkPMColor4f& color, |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 214 | const GrStyledShape& shape, |
Chris Dalton | 17dc418 | 2020-03-25 16:18:16 -0600 | [diff] [blame] | 215 | const SkMatrix& viewMatrix, |
| 216 | const SkIRect& devClipBounds, |
| 217 | GrAAType aaType, |
| 218 | const GrUserStencilSettings* stencilSettings) |
Brian Salomon | 9530f7e | 2017-07-11 09:03:10 -0400 | [diff] [blame] | 219 | : INHERITED(ClassID()) |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 220 | , fHelper(processorSet, aaType, stencilSettings) |
Brian Salomon | 9530f7e | 2017-07-11 09:03:10 -0400 | [diff] [blame] | 221 | , fColor(color) |
| 222 | , fShape(shape) |
| 223 | , fViewMatrix(viewMatrix) |
| 224 | , fDevClipBounds(devClipBounds) |
| 225 | , fAntiAlias(GrAAType::kCoverage == aaType) { |
| 226 | SkRect devBounds; |
| 227 | viewMatrix.mapRect(&devBounds, shape.bounds()); |
| 228 | if (shape.inverseFilled()) { |
| 229 | // Because the clip bounds are used to add a contour for inverse fills, they must also |
| 230 | // include the path bounds. |
| 231 | devBounds.join(SkRect::Make(fDevClipBounds)); |
| 232 | } |
Greg Daniel | 5faf474 | 2019-10-01 15:14:44 -0400 | [diff] [blame] | 233 | this->setBounds(devBounds, HasAABloat::kNo, IsHairline::kNo); |
Brian Salomon | 9530f7e | 2017-07-11 09:03:10 -0400 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | FixedFunctionFlags fixedFunctionFlags() const override { return fHelper.fixedFunctionFlags(); } |
| 237 | |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 238 | GrProcessorSet::Analysis finalize( |
| 239 | const GrCaps& caps, const GrAppliedClip* clip, bool hasMixedSampledCoverage, |
| 240 | GrClampType clampType) override { |
Brian Salomon | 9530f7e | 2017-07-11 09:03:10 -0400 | [diff] [blame] | 241 | GrProcessorAnalysisCoverage coverage = fAntiAlias |
| 242 | ? GrProcessorAnalysisCoverage::kSingleChannel |
| 243 | : GrProcessorAnalysisCoverage::kNone; |
Brian Osman | 8fa7ab4 | 2019-03-18 10:22:42 -0400 | [diff] [blame] | 244 | // This Op uses uniform (not vertex) color, so doesn't need to track wide color. |
| 245 | return fHelper.finalizeProcessors( |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 246 | caps, clip, hasMixedSampledCoverage, clampType, coverage, &fColor, nullptr); |
Brian Salomon | 9530f7e | 2017-07-11 09:03:10 -0400 | [diff] [blame] | 247 | } |
| 248 | |
Brian Salomon | 92aee3d | 2016-12-21 09:20:25 -0500 | [diff] [blame] | 249 | private: |
senorblanco | f57372d | 2016-08-31 10:36:19 -0700 | [diff] [blame] | 250 | SkPath getPath() const { |
| 251 | SkASSERT(!fShape.style().applies()); |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 252 | SkPath path; |
| 253 | fShape.asPath(&path); |
senorblanco | f57372d | 2016-08-31 10:36:19 -0700 | [diff] [blame] | 254 | return path; |
| 255 | } |
| 256 | |
Robert Phillips | 6ffcb23 | 2020-10-14 12:40:13 -0400 | [diff] [blame] | 257 | static void CreateKey(GrUniqueKey* key, |
| 258 | const GrStyledShape& shape, |
| 259 | const SkIRect& devClipBounds) { |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 260 | static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); |
Robert Phillips | 6ffcb23 | 2020-10-14 12:40:13 -0400 | [diff] [blame] | 261 | |
| 262 | bool inverseFill = shape.inverseFilled(); |
| 263 | |
| 264 | static constexpr int kClipBoundsCnt = sizeof(devClipBounds) / sizeof(uint32_t); |
| 265 | int shapeKeyDataCnt = shape.unstyledKeySize(); |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 266 | SkASSERT(shapeKeyDataCnt >= 0); |
Robert Phillips | 6ffcb23 | 2020-10-14 12:40:13 -0400 | [diff] [blame] | 267 | GrUniqueKey::Builder builder(key, kDomain, shapeKeyDataCnt + kClipBoundsCnt, "Path"); |
| 268 | shape.writeUnstyledKey(&builder[0]); |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 269 | // For inverse fills, the tessellation is dependent on clip bounds. |
| 270 | if (inverseFill) { |
Robert Phillips | 6ffcb23 | 2020-10-14 12:40:13 -0400 | [diff] [blame] | 271 | memcpy(&builder[shapeKeyDataCnt], &devClipBounds, sizeof(devClipBounds)); |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 272 | } else { |
Robert Phillips | 6ffcb23 | 2020-10-14 12:40:13 -0400 | [diff] [blame] | 273 | memset(&builder[shapeKeyDataCnt], 0, sizeof(devClipBounds)); |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 274 | } |
Robert Phillips | 6ffcb23 | 2020-10-14 12:40:13 -0400 | [diff] [blame] | 275 | |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 276 | builder.finish(); |
Robert Phillips | 6ffcb23 | 2020-10-14 12:40:13 -0400 | [diff] [blame] | 277 | } |
| 278 | |
Robert Phillips | 9dfc6d8 | 2020-10-20 10:05:58 -0400 | [diff] [blame] | 279 | // Triangulate the provided 'shape' in the shape's coordinate space. 'tol' should already |
| 280 | // have been mapped back from device space. |
| 281 | static int Triangulate(GrEagerVertexAllocator* allocator, |
| 282 | const SkMatrix& viewMatrix, |
| 283 | const GrStyledShape& shape, |
| 284 | const SkIRect& devClipBounds, |
| 285 | SkScalar tol, |
| 286 | int* numCountedCurves) { |
| 287 | SkRect clipBounds = SkRect::Make(devClipBounds); |
| 288 | |
| 289 | SkMatrix vmi; |
| 290 | if (!viewMatrix.invert(&vmi)) { |
| 291 | return 0; |
| 292 | } |
| 293 | vmi.mapRect(&clipBounds); |
| 294 | |
| 295 | SkASSERT(!shape.style().applies()); |
| 296 | SkPath path; |
| 297 | shape.asPath(&path); |
| 298 | |
| 299 | return GrTriangulator::PathToTriangles(path, tol, clipBounds, allocator, |
| 300 | GrTriangulator::Mode::kNormal, numCountedCurves); |
| 301 | } |
| 302 | |
Robert Phillips | 6ffcb23 | 2020-10-14 12:40:13 -0400 | [diff] [blame] | 303 | void createNonAAMesh(Target* target) { |
| 304 | SkASSERT(!fAntiAlias); |
| 305 | GrResourceProvider* rp = target->resourceProvider(); |
| 306 | |
| 307 | GrUniqueKey key; |
| 308 | CreateKey(&key, fShape, fDevClipBounds); |
| 309 | |
Robert Phillips | 6cc9d8d | 2020-10-20 09:42:33 -0400 | [diff] [blame] | 310 | SkScalar tol = GrPathUtils::scaleToleranceToSrc(GrPathUtils::kDefaultTolerance, |
| 311 | fViewMatrix, fShape.bounds()); |
| 312 | |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 313 | sk_sp<GrGpuBuffer> cachedVertexBuffer(rp->findByUniqueKey<GrGpuBuffer>(key)); |
Robert Phillips | 6cc9d8d | 2020-10-20 09:42:33 -0400 | [diff] [blame] | 314 | if (cachedVertexBuffer) { |
Robert Phillips | 3ac83b2f | 2020-10-26 13:50:57 -0400 | [diff] [blame^] | 315 | int actualVertexCount; |
Robert Phillips | 6cc9d8d | 2020-10-20 09:42:33 -0400 | [diff] [blame] | 316 | |
| 317 | if (cache_match(cachedVertexBuffer->getUniqueKey().getCustomData(), tol, |
Robert Phillips | 3ac83b2f | 2020-10-26 13:50:57 -0400 | [diff] [blame^] | 318 | &actualVertexCount, nullptr)) { |
| 319 | fMesh = CreateMesh(target, std::move(cachedVertexBuffer), 0, actualVertexCount); |
Robert Phillips | 6cc9d8d | 2020-10-20 09:42:33 -0400 | [diff] [blame] | 320 | return; |
| 321 | } |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 322 | } |
| 323 | |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 324 | bool canMapVB = GrCaps::kNone_MapFlags != target->caps().mapBufferFlags(); |
Chris Dalton | d081dce | 2020-01-23 12:09:04 -0700 | [diff] [blame] | 325 | StaticVertexAllocator allocator(rp, canMapVB); |
Robert Phillips | 9dfc6d8 | 2020-10-20 10:05:58 -0400 | [diff] [blame] | 326 | |
| 327 | int numCountedCurves; |
| 328 | int vertexCount = Triangulate(&allocator, fViewMatrix, fShape, fDevClipBounds, tol, |
| 329 | &numCountedCurves); |
Chris Dalton | 8e2b694 | 2020-04-22 15:55:00 -0600 | [diff] [blame] | 330 | if (vertexCount == 0) { |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 331 | return; |
| 332 | } |
Robert Phillips | 9dfc6d8 | 2020-10-20 10:05:58 -0400 | [diff] [blame] | 333 | |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 334 | sk_sp<GrGpuBuffer> vb = allocator.detachVertexBuffer(); |
Robert Phillips | 6cc9d8d | 2020-10-20 09:42:33 -0400 | [diff] [blame] | 335 | |
| 336 | key.setCustomData(create_data(vertexCount, numCountedCurves, tol)); |
| 337 | |
Brian Salomon | 99a813c | 2020-03-02 12:50:47 -0500 | [diff] [blame] | 338 | fShape.addGenIDChangeListener( |
| 339 | sk_make_sp<UniqueKeyInvalidator>(key, target->contextUniqueID())); |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 340 | rp->assignUniqueKeyToResource(key, vb.get()); |
| 341 | |
Robert Phillips | 3ac83b2f | 2020-10-26 13:50:57 -0400 | [diff] [blame^] | 342 | fMesh = CreateMesh(target, std::move(vb), 0, vertexCount); |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 343 | } |
| 344 | |
Robert Phillips | 6ffcb23 | 2020-10-14 12:40:13 -0400 | [diff] [blame] | 345 | void createAAMesh(Target* target) { |
senorblanco | f57372d | 2016-08-31 10:36:19 -0700 | [diff] [blame] | 346 | SkASSERT(fAntiAlias); |
Robert Phillips | 6ffcb23 | 2020-10-14 12:40:13 -0400 | [diff] [blame] | 347 | SkPath path = this->getPath(); |
senorblanco | f57372d | 2016-08-31 10:36:19 -0700 | [diff] [blame] | 348 | if (path.isEmpty()) { |
| 349 | return; |
| 350 | } |
| 351 | SkRect clipBounds = SkRect::Make(fDevClipBounds); |
| 352 | path.transform(fViewMatrix); |
| 353 | SkScalar tol = GrPathUtils::kDefaultTolerance; |
Chris Dalton | d081dce | 2020-01-23 12:09:04 -0700 | [diff] [blame] | 354 | sk_sp<const GrBuffer> vertexBuffer; |
| 355 | int firstVertex; |
Chris Dalton | 8e2b694 | 2020-04-22 15:55:00 -0600 | [diff] [blame] | 356 | int numCountedCurves; |
Chris Dalton | d081dce | 2020-01-23 12:09:04 -0700 | [diff] [blame] | 357 | GrEagerDynamicVertexAllocator allocator(target, &vertexBuffer, &firstVertex); |
Chris Dalton | 8e2b694 | 2020-04-22 15:55:00 -0600 | [diff] [blame] | 358 | int vertexCount = GrTriangulator::PathToTriangles(path, tol, clipBounds, &allocator, |
| 359 | GrTriangulator::Mode::kEdgeAntialias, |
| 360 | &numCountedCurves); |
| 361 | if (vertexCount == 0) { |
senorblanco | f57372d | 2016-08-31 10:36:19 -0700 | [diff] [blame] | 362 | return; |
| 363 | } |
Robert Phillips | 3ac83b2f | 2020-10-26 13:50:57 -0400 | [diff] [blame^] | 364 | fMesh = CreateMesh(target, std::move(vertexBuffer), firstVertex, vertexCount); |
senorblanco | f57372d | 2016-08-31 10:36:19 -0700 | [diff] [blame] | 365 | } |
| 366 | |
Robert Phillips | 2669a7b | 2020-03-12 12:07:19 -0400 | [diff] [blame] | 367 | GrProgramInfo* programInfo() override { return fProgramInfo; } |
| 368 | |
Robert Phillips | 4133dc4 | 2020-03-11 15:55:55 -0400 | [diff] [blame] | 369 | void onCreateProgramInfo(const GrCaps* caps, |
| 370 | SkArenaAlloc* arena, |
Brian Salomon | 8afde5f | 2020-04-01 16:22:00 -0400 | [diff] [blame] | 371 | const GrSurfaceProxyView* writeView, |
Robert Phillips | 4133dc4 | 2020-03-11 15:55:55 -0400 | [diff] [blame] | 372 | GrAppliedClip&& appliedClip, |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 373 | const GrXferProcessor::DstProxyView& dstProxyView, |
| 374 | GrXferBarrierFlags renderPassXferBarriers) override { |
Robert Phillips | 7cd0bfe | 2019-11-20 16:08:10 -0500 | [diff] [blame] | 375 | GrGeometryProcessor* gp; |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 376 | { |
| 377 | using namespace GrDefaultGeoProcFactory; |
| 378 | |
| 379 | Color color(fColor); |
Brian Salomon | 9530f7e | 2017-07-11 09:03:10 -0400 | [diff] [blame] | 380 | LocalCoords::Type localCoordsType = fHelper.usesLocalCoords() |
Brian Salomon | 8c852be | 2017-01-04 10:44:42 -0500 | [diff] [blame] | 381 | ? LocalCoords::kUsePosition_Type |
| 382 | : LocalCoords::kUnused_Type; |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 383 | Coverage::Type coverageType; |
senorblanco | f57372d | 2016-08-31 10:36:19 -0700 | [diff] [blame] | 384 | if (fAntiAlias) { |
Brian Osman | 605c6d5 | 2019-03-15 12:10:35 -0400 | [diff] [blame] | 385 | if (fHelper.compatibleWithCoverageAsAlpha()) { |
Brian Osman | 80879d4 | 2019-01-07 16:15:27 -0500 | [diff] [blame] | 386 | coverageType = Coverage::kAttributeTweakAlpha_Type; |
senorblanco | f57372d | 2016-08-31 10:36:19 -0700 | [diff] [blame] | 387 | } else { |
| 388 | coverageType = Coverage::kAttribute_Type; |
| 389 | } |
Brian Salomon | 8c852be | 2017-01-04 10:44:42 -0500 | [diff] [blame] | 390 | } else { |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 391 | coverageType = Coverage::kSolid_Type; |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 392 | } |
senorblanco | f57372d | 2016-08-31 10:36:19 -0700 | [diff] [blame] | 393 | if (fAntiAlias) { |
Brian Osman | f0aee74 | 2020-03-12 09:28:44 -0400 | [diff] [blame] | 394 | gp = GrDefaultGeoProcFactory::MakeForDeviceSpace(arena, color, coverageType, |
Brian Salomon | 8c852be | 2017-01-04 10:44:42 -0500 | [diff] [blame] | 395 | localCoordsType, fViewMatrix); |
senorblanco | f57372d | 2016-08-31 10:36:19 -0700 | [diff] [blame] | 396 | } else { |
Brian Osman | f0aee74 | 2020-03-12 09:28:44 -0400 | [diff] [blame] | 397 | gp = GrDefaultGeoProcFactory::Make(arena, color, coverageType, localCoordsType, |
Brian Salomon | 8c852be | 2017-01-04 10:44:42 -0500 | [diff] [blame] | 398 | fViewMatrix); |
senorblanco | f57372d | 2016-08-31 10:36:19 -0700 | [diff] [blame] | 399 | } |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 400 | } |
Robert Phillips | 7cd0bfe | 2019-11-20 16:08:10 -0500 | [diff] [blame] | 401 | if (!gp) { |
Robert Phillips | 4133dc4 | 2020-03-11 15:55:55 -0400 | [diff] [blame] | 402 | return; |
Stephen White | cc70083 | 2017-02-15 11:45:16 -0500 | [diff] [blame] | 403 | } |
Robert Phillips | 740d34f | 2020-03-11 09:36:13 -0400 | [diff] [blame] | 404 | |
Chris Dalton | dcc8c54 | 2020-01-28 17:55:56 -0700 | [diff] [blame] | 405 | #ifdef SK_DEBUG |
Chris Dalton | 17dc418 | 2020-03-25 16:18:16 -0600 | [diff] [blame] | 406 | auto mode = (fAntiAlias) ? GrTriangulator::Mode::kEdgeAntialias |
| 407 | : GrTriangulator::Mode::kNormal; |
| 408 | SkASSERT(GrTriangulator::GetVertexStride(mode) == gp->vertexStride()); |
Chris Dalton | dcc8c54 | 2020-01-28 17:55:56 -0700 | [diff] [blame] | 409 | #endif |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 410 | |
Chris Dalton | 17dc418 | 2020-03-25 16:18:16 -0600 | [diff] [blame] | 411 | GrPrimitiveType primitiveType = TRIANGULATOR_WIREFRAME ? GrPrimitiveType::kLines |
| 412 | : GrPrimitiveType::kTriangles; |
Robert Phillips | e94cdd2 | 2019-11-04 14:15:58 -0500 | [diff] [blame] | 413 | |
Brian Salomon | 8afde5f | 2020-04-01 16:22:00 -0400 | [diff] [blame] | 414 | fProgramInfo = fHelper.createProgramInfoWithStencil(caps, arena, writeView, |
Robert Phillips | 4133dc4 | 2020-03-11 15:55:55 -0400 | [diff] [blame] | 415 | std::move(appliedClip), dstProxyView, |
Greg Daniel | d358cbe | 2020-09-11 09:33:54 -0400 | [diff] [blame] | 416 | gp, primitiveType, |
| 417 | renderPassXferBarriers); |
Robert Phillips | 740d34f | 2020-03-11 09:36:13 -0400 | [diff] [blame] | 418 | } |
| 419 | |
Robert Phillips | 473a848 | 2020-10-20 10:44:15 -0400 | [diff] [blame] | 420 | void onPrePrepareDraws(GrRecordingContext* rContext, |
| 421 | const GrSurfaceProxyView* writeView, |
| 422 | GrAppliedClip* clip, |
| 423 | const GrXferProcessor::DstProxyView& dstProxyView, |
| 424 | GrXferBarrierFlags renderPassXferBarriers) override { |
| 425 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
| 426 | |
| 427 | INHERITED::onPrePrepareDraws(rContext, writeView, clip, dstProxyView, |
| 428 | renderPassXferBarriers); |
| 429 | } |
| 430 | |
Robert Phillips | 740d34f | 2020-03-11 09:36:13 -0400 | [diff] [blame] | 431 | void onPrepareDraws(Target* target) override { |
| 432 | if (fAntiAlias) { |
Robert Phillips | 6ffcb23 | 2020-10-14 12:40:13 -0400 | [diff] [blame] | 433 | this->createAAMesh(target); |
Robert Phillips | 740d34f | 2020-03-11 09:36:13 -0400 | [diff] [blame] | 434 | } else { |
Robert Phillips | 6ffcb23 | 2020-10-14 12:40:13 -0400 | [diff] [blame] | 435 | this->createNonAAMesh(target); |
Robert Phillips | 740d34f | 2020-03-11 09:36:13 -0400 | [diff] [blame] | 436 | } |
| 437 | } |
| 438 | |
Robert Phillips | 3ac83b2f | 2020-10-26 13:50:57 -0400 | [diff] [blame^] | 439 | static GrSimpleMesh* CreateMesh(Target* target, sk_sp<const GrBuffer> vb, |
| 440 | int firstVertex, int count) { |
| 441 | auto mesh = target->allocMesh(); |
| 442 | mesh->set(std::move(vb), count, firstVertex); |
| 443 | return mesh; |
Chris Dalton | 07cdcfc9 | 2019-02-26 11:13:22 -0700 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override { |
Robert Phillips | 740d34f | 2020-03-11 09:36:13 -0400 | [diff] [blame] | 447 | if (!fProgramInfo) { |
Robert Phillips | 4133dc4 | 2020-03-11 15:55:55 -0400 | [diff] [blame] | 448 | this->createProgramInfo(flushState); |
Robert Phillips | 740d34f | 2020-03-11 09:36:13 -0400 | [diff] [blame] | 449 | } |
Robert Phillips | 3968fcb | 2019-12-05 16:40:31 -0500 | [diff] [blame] | 450 | |
Robert Phillips | 740d34f | 2020-03-11 09:36:13 -0400 | [diff] [blame] | 451 | if (!fProgramInfo || !fMesh) { |
| 452 | return; |
| 453 | } |
| 454 | |
Chris Dalton | 765ed36 | 2020-03-16 17:34:44 -0600 | [diff] [blame] | 455 | flushState->bindPipelineAndScissorClip(*fProgramInfo, chainBounds); |
| 456 | flushState->bindTextures(fProgramInfo->primProc(), nullptr, fProgramInfo->pipeline()); |
| 457 | flushState->drawMesh(*fMesh); |
senorblanco | 9ba3972 | 2015-03-05 07:13:42 -0800 | [diff] [blame] | 458 | } |
| 459 | |
John Stiles | af36652 | 2020-08-13 09:57:34 -0400 | [diff] [blame] | 460 | #if GR_TEST_UTILS |
| 461 | SkString onDumpInfo() const override { |
| 462 | return SkStringPrintf("Color 0x%08x, aa: %d\n%s", |
| 463 | fColor.toBytes_RGBA(), fAntiAlias, fHelper.dumpInfo().c_str()); |
| 464 | } |
| 465 | #endif |
| 466 | |
Robert Phillips | 740d34f | 2020-03-11 09:36:13 -0400 | [diff] [blame] | 467 | Helper fHelper; |
| 468 | SkPMColor4f fColor; |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 469 | GrStyledShape fShape; |
Robert Phillips | 740d34f | 2020-03-11 09:36:13 -0400 | [diff] [blame] | 470 | SkMatrix fViewMatrix; |
| 471 | SkIRect fDevClipBounds; |
| 472 | bool fAntiAlias; |
| 473 | |
Chris Dalton | eb694b7 | 2020-03-16 09:25:50 -0600 | [diff] [blame] | 474 | GrSimpleMesh* fMesh = nullptr; |
Robert Phillips | 740d34f | 2020-03-11 09:36:13 -0400 | [diff] [blame] | 475 | GrProgramInfo* fProgramInfo = nullptr; |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 476 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 477 | using INHERITED = GrMeshDrawOp; |
senorblanco | 9ba3972 | 2015-03-05 07:13:42 -0800 | [diff] [blame] | 478 | }; |
| 479 | |
Brian Salomon | 9530f7e | 2017-07-11 09:03:10 -0400 | [diff] [blame] | 480 | } // anonymous namespace |
| 481 | |
Chris Dalton | 17dc418 | 2020-03-25 16:18:16 -0600 | [diff] [blame] | 482 | bool GrTriangulatingPathRenderer::onDrawPath(const DrawPathArgs& args) { |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 483 | GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(), |
Chris Dalton | 17dc418 | 2020-03-25 16:18:16 -0600 | [diff] [blame] | 484 | "GrTriangulatingPathRenderer::onDrawPath"); |
Michael Ludwig | 7c12e28 | 2020-05-29 09:54:07 -0400 | [diff] [blame] | 485 | |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 486 | GrOp::Owner op = TriangulatingPathOp::Make( |
Michael Ludwig | 7c12e28 | 2020-05-29 09:54:07 -0400 | [diff] [blame] | 487 | args.fContext, std::move(args.fPaint), *args.fShape, *args.fViewMatrix, |
| 488 | *args.fClipConservativeBounds, args.fAAType, args.fUserStencilSettings); |
| 489 | args.fRenderTargetContext->addDrawOp(args.fClip, std::move(op)); |
senorblanco | d6ed19c | 2015-02-26 06:58:17 -0800 | [diff] [blame] | 490 | return true; |
| 491 | } |
joshualitt | 2fbd406 | 2015-05-07 13:06:41 -0700 | [diff] [blame] | 492 | |
| 493 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 494 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 495 | #if GR_TEST_UTILS |
joshualitt | 2fbd406 | 2015-05-07 13:06:41 -0700 | [diff] [blame] | 496 | |
Chris Dalton | 17dc418 | 2020-03-25 16:18:16 -0600 | [diff] [blame] | 497 | GR_DRAW_OP_TEST_DEFINE(TriangulatingPathOp) { |
joshualitt | 2fbd406 | 2015-05-07 13:06:41 -0700 | [diff] [blame] | 498 | SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); |
John Stiles | 31954bf | 2020-08-07 17:35:54 -0400 | [diff] [blame] | 499 | const SkPath& path = GrTest::TestPath(random); |
bsalomon | d3030ac | 2016-09-01 07:20:29 -0700 | [diff] [blame] | 500 | SkIRect devClipBounds = SkIRect::MakeLTRB( |
senorblanco | f57372d | 2016-08-31 10:36:19 -0700 | [diff] [blame] | 501 | random->nextU(), random->nextU(), random->nextU(), random->nextU()); |
bsalomon | d3030ac | 2016-09-01 07:20:29 -0700 | [diff] [blame] | 502 | devClipBounds.sort(); |
Brian Salomon | 9530f7e | 2017-07-11 09:03:10 -0400 | [diff] [blame] | 503 | static constexpr GrAAType kAATypes[] = {GrAAType::kNone, GrAAType::kMSAA, GrAAType::kCoverage}; |
| 504 | GrAAType aaType; |
| 505 | do { |
| 506 | aaType = kAATypes[random->nextULessThan(SK_ARRAY_COUNT(kAATypes))]; |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 507 | } while(GrAAType::kMSAA == aaType && numSamples <= 1); |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 508 | GrStyle style; |
| 509 | do { |
| 510 | GrTest::TestStyle(random, &style); |
senorblanco | f57372d | 2016-08-31 10:36:19 -0700 | [diff] [blame] | 511 | } while (!style.isSimpleFill()); |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 512 | GrStyledShape shape(path, style); |
Chris Dalton | 17dc418 | 2020-03-25 16:18:16 -0600 | [diff] [blame] | 513 | return TriangulatingPathOp::Make(context, std::move(paint), shape, viewMatrix, devClipBounds, |
| 514 | aaType, GrGetRandomStencil(random, context)); |
joshualitt | 2fbd406 | 2015-05-07 13:06:41 -0700 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | #endif |