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 | |
| 8 | #include "GrTessellatingPathRenderer.h" |
| 9 | |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 10 | #include "GrAuditTrail.h" |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 11 | #include "GrBatchFlushState.h" |
joshualitt | 2fbd406 | 2015-05-07 13:06:41 -0700 | [diff] [blame] | 12 | #include "GrBatchTest.h" |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 13 | #include "GrClip.h" |
senorblanco | d6ed19c | 2015-02-26 06:58:17 -0800 | [diff] [blame] | 14 | #include "GrDefaultGeoProcFactory.h" |
egdaniel | 0e1853c | 2016-03-17 11:35:45 -0700 | [diff] [blame] | 15 | #include "GrMesh.h" |
senorblanco | d6ed19c | 2015-02-26 06:58:17 -0800 | [diff] [blame] | 16 | #include "GrPathUtils.h" |
bsalomon | bb24383 | 2016-07-22 07:10:19 -0700 | [diff] [blame^] | 17 | #include "GrPipelineBuilder.h" |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 18 | #include "GrResourceCache.h" |
| 19 | #include "GrResourceProvider.h" |
ethannicholas | e9709e8 | 2016-01-07 13:34:16 -0800 | [diff] [blame] | 20 | #include "GrTessellator.h" |
senorblanco | d6ed19c | 2015-02-26 06:58:17 -0800 | [diff] [blame] | 21 | #include "SkGeometry.h" |
| 22 | |
bsalomon | 16b9913 | 2015-08-13 14:55:50 -0700 | [diff] [blame] | 23 | #include "batches/GrVertexBatch.h" |
joshualitt | 7441782 | 2015-08-07 11:42:16 -0700 | [diff] [blame] | 24 | |
senorblanco | d6ed19c | 2015-02-26 06:58:17 -0800 | [diff] [blame] | 25 | #include <stdio.h> |
| 26 | |
| 27 | /* |
ethannicholas | e9709e8 | 2016-01-07 13:34:16 -0800 | [diff] [blame] | 28 | * This path renderer tessellates the path into triangles using GrTessellator, uploads the triangles |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 29 | * to a vertex buffer, and renders them with a single draw call. It does not currently do |
senorblanco | d6ed19c | 2015-02-26 06:58:17 -0800 | [diff] [blame] | 30 | * antialiasing, so it must be used in conjunction with multisampling. |
senorblanco | d6ed19c | 2015-02-26 06:58:17 -0800 | [diff] [blame] | 31 | */ |
senorblanco | d6ed19c | 2015-02-26 06:58:17 -0800 | [diff] [blame] | 32 | namespace { |
| 33 | |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 34 | struct TessInfo { |
| 35 | SkScalar fTolerance; |
senorblanco | 06f989a | 2015-09-02 09:05:17 -0700 | [diff] [blame] | 36 | int fCount; |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 37 | }; |
| 38 | |
ethannicholas | e9709e8 | 2016-01-07 13:34:16 -0800 | [diff] [blame] | 39 | // When the SkPathRef genID changes, invalidate a corresponding GrResource described by key. |
| 40 | class PathInvalidator : public SkPathRef::GenIDChangeListener { |
| 41 | public: |
| 42 | explicit PathInvalidator(const GrUniqueKey& key) : fMsg(key) {} |
| 43 | private: |
| 44 | GrUniqueKeyInvalidatedMessage fMsg; |
| 45 | |
| 46 | void onChange() override { |
| 47 | SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(fMsg); |
| 48 | } |
| 49 | }; |
| 50 | |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 51 | bool cache_match(GrBuffer* vertexBuffer, SkScalar tol, int* actualCount) { |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 52 | if (!vertexBuffer) { |
| 53 | return false; |
| 54 | } |
| 55 | const SkData* data = vertexBuffer->getUniqueKey().getCustomData(); |
| 56 | SkASSERT(data); |
| 57 | const TessInfo* info = static_cast<const TessInfo*>(data->data()); |
| 58 | if (info->fTolerance == 0 || info->fTolerance < 3.0f * tol) { |
senorblanco | 06f989a | 2015-09-02 09:05:17 -0700 | [diff] [blame] | 59 | *actualCount = info->fCount; |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 60 | return true; |
| 61 | } |
| 62 | return false; |
| 63 | } |
| 64 | |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 65 | class StaticVertexAllocator : public GrTessellator::VertexAllocator { |
| 66 | public: |
senorblanco | af1e21e | 2016-03-16 10:25:58 -0700 | [diff] [blame] | 67 | StaticVertexAllocator(GrResourceProvider* resourceProvider, bool canMapVB) |
| 68 | : fResourceProvider(resourceProvider) |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 69 | , fCanMapVB(canMapVB) |
| 70 | , fVertices(nullptr) { |
| 71 | } |
| 72 | SkPoint* lock(int vertexCount) override { |
| 73 | size_t size = vertexCount * sizeof(SkPoint); |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 74 | fVertexBuffer.reset(fResourceProvider->createBuffer( |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 75 | size, kVertex_GrBufferType, kStatic_GrAccessPattern, 0)); |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 76 | if (!fVertexBuffer.get()) { |
| 77 | return nullptr; |
| 78 | } |
| 79 | if (fCanMapVB) { |
| 80 | fVertices = static_cast<SkPoint*>(fVertexBuffer->map()); |
| 81 | } else { |
| 82 | fVertices = new SkPoint[vertexCount]; |
| 83 | } |
| 84 | return fVertices; |
| 85 | } |
| 86 | void unlock(int actualCount) override { |
| 87 | if (fCanMapVB) { |
| 88 | fVertexBuffer->unmap(); |
| 89 | } else { |
| 90 | fVertexBuffer->updateData(fVertices, actualCount * sizeof(SkPoint)); |
| 91 | delete[] fVertices; |
| 92 | } |
| 93 | fVertices = nullptr; |
| 94 | } |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 95 | GrBuffer* vertexBuffer() { return fVertexBuffer.get(); } |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 96 | private: |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 97 | SkAutoTUnref<GrBuffer> fVertexBuffer; |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 98 | GrResourceProvider* fResourceProvider; |
| 99 | bool fCanMapVB; |
| 100 | SkPoint* fVertices; |
| 101 | }; |
| 102 | |
ethannicholas | e9709e8 | 2016-01-07 13:34:16 -0800 | [diff] [blame] | 103 | } // namespace |
senorblanco | d6ed19c | 2015-02-26 06:58:17 -0800 | [diff] [blame] | 104 | |
| 105 | GrTessellatingPathRenderer::GrTessellatingPathRenderer() { |
| 106 | } |
| 107 | |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 108 | bool GrTessellatingPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const { |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 109 | // This path renderer can draw fill styles but does not do antialiasing. It can do convex and |
| 110 | // concave paths, but we'll leave the convex ones to simpler algorithms. We pass on paths that |
| 111 | // have styles, though they may come back around after applying the styling information to the |
| 112 | // geometry to create a filled path. We also skip paths that don't have a key since the real |
| 113 | // advantage of this path renderer comes from caching the tessellated geometry. |
| 114 | return !args.fShape->style().applies() && args.fShape->style().isSimpleFill() && |
| 115 | !args.fAntiAlias && args.fShape->hasUnstyledKey() && !args.fShape->knownToBeConvex(); |
senorblanco | d6ed19c | 2015-02-26 06:58:17 -0800 | [diff] [blame] | 116 | } |
| 117 | |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 118 | class TessellatingPathBatch : public GrVertexBatch { |
senorblanco | 9ba3972 | 2015-03-05 07:13:42 -0800 | [diff] [blame] | 119 | public: |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 120 | DEFINE_BATCH_CLASS_ID |
senorblanco | 9ba3972 | 2015-03-05 07:13:42 -0800 | [diff] [blame] | 121 | |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 122 | static GrDrawBatch* Create(const GrColor& color, |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 123 | const GrShape& shape, |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 124 | const SkMatrix& viewMatrix, |
| 125 | SkRect clipBounds) { |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 126 | return new TessellatingPathBatch(color, shape, viewMatrix, clipBounds); |
senorblanco | 9ba3972 | 2015-03-05 07:13:42 -0800 | [diff] [blame] | 127 | } |
| 128 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 129 | const char* name() const override { return "TessellatingPathBatch"; } |
senorblanco | 9ba3972 | 2015-03-05 07:13:42 -0800 | [diff] [blame] | 130 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 131 | void computePipelineOptimizations(GrInitInvariantOutput* color, |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 132 | GrInitInvariantOutput* coverage, |
| 133 | GrBatchToXPOverrides* overrides) const override { |
| 134 | color->setKnownFourComponents(fColor); |
| 135 | coverage->setUnknownSingleComponent(); |
senorblanco | 9ba3972 | 2015-03-05 07:13:42 -0800 | [diff] [blame] | 136 | } |
| 137 | |
bsalomon | e46f9fe | 2015-08-18 06:05:14 -0700 | [diff] [blame] | 138 | private: |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 139 | void initBatchTracker(const GrXPOverridesForBatch& overrides) override { |
senorblanco | 9ba3972 | 2015-03-05 07:13:42 -0800 | [diff] [blame] | 140 | // Handle any color overrides |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 141 | if (!overrides.readsColor()) { |
senorblanco | 9ba3972 | 2015-03-05 07:13:42 -0800 | [diff] [blame] | 142 | fColor = GrColor_ILLEGAL; |
senorblanco | 9ba3972 | 2015-03-05 07:13:42 -0800 | [diff] [blame] | 143 | } |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 144 | overrides.getOverrideColorIfSet(&fColor); |
| 145 | fPipelineInfo = overrides; |
senorblanco | 9ba3972 | 2015-03-05 07:13:42 -0800 | [diff] [blame] | 146 | } |
| 147 | |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 148 | void draw(Target* target, const GrGeometryProcessor* gp) const { |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 149 | GrResourceProvider* rp = target->resourceProvider(); |
| 150 | SkScalar screenSpaceTol = GrPathUtils::kDefaultTolerance; |
| 151 | SkScalar tol = GrPathUtils::scaleToleranceToSrc(screenSpaceTol, fViewMatrix, |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 152 | fShape.bounds()); |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 153 | |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 154 | SkPath path; |
| 155 | fShape.asPath(&path); |
| 156 | bool inverseFill = path.isInverseFillType(); |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 157 | // construct a cache key from the path's genID and the view matrix |
| 158 | static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); |
| 159 | GrUniqueKey key; |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 160 | static constexpr int kClipBoundsCnt = sizeof(fClipBounds) / sizeof(uint32_t); |
| 161 | int shapeKeyDataCnt = fShape.unstyledKeySize(); |
| 162 | SkASSERT(shapeKeyDataCnt >= 0); |
| 163 | GrUniqueKey::Builder builder(&key, kDomain, shapeKeyDataCnt + kClipBoundsCnt); |
| 164 | fShape.writeUnstyledKey(&builder[0]); |
| 165 | // For inverse fills, the tessellation is dependent on clip bounds. |
| 166 | if (inverseFill) { |
| 167 | memcpy(&builder[shapeKeyDataCnt], &fClipBounds, sizeof(fClipBounds)); |
| 168 | } else { |
| 169 | memset(&builder[shapeKeyDataCnt], 0, sizeof(fClipBounds)); |
| 170 | } |
| 171 | builder.finish(); |
| 172 | SkAutoTUnref<GrBuffer> cachedVertexBuffer(rp->findAndRefTByUniqueKey<GrBuffer>(key)); |
| 173 | int actualCount; |
| 174 | if (cache_match(cachedVertexBuffer.get(), tol, &actualCount)) { |
| 175 | this->drawVertices(target, gp, cachedVertexBuffer.get(), 0, actualCount); |
| 176 | return; |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 177 | } |
| 178 | |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 179 | bool isLinear; |
| 180 | bool canMapVB = GrCaps::kNone_MapFlags != target->caps().mapBufferFlags(); |
senorblanco | af1e21e | 2016-03-16 10:25:58 -0700 | [diff] [blame] | 181 | StaticVertexAllocator allocator(rp, canMapVB); |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 182 | int count = GrTessellator::PathToTriangles(path, tol, fClipBounds, &allocator, &isLinear); |
| 183 | if (count == 0) { |
| 184 | return; |
| 185 | } |
senorblanco | af1e21e | 2016-03-16 10:25:58 -0700 | [diff] [blame] | 186 | this->drawVertices(target, gp, allocator.vertexBuffer(), 0, count); |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 187 | TessInfo info; |
| 188 | info.fTolerance = isLinear ? 0 : tol; |
| 189 | info.fCount = count; |
| 190 | SkAutoTUnref<SkData> data(SkData::NewWithCopy(&info, sizeof(info))); |
| 191 | key.setCustomData(data.get()); |
| 192 | rp->assignUniqueKeyToResource(key, allocator.vertexBuffer()); |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | void onPrepareDraws(Target* target) const override { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 196 | sk_sp<GrGeometryProcessor> gp; |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 197 | { |
| 198 | using namespace GrDefaultGeoProcFactory; |
| 199 | |
| 200 | Color color(fColor); |
| 201 | LocalCoords localCoords(fPipelineInfo.readsLocalCoords() ? |
| 202 | LocalCoords::kUsePosition_Type : |
| 203 | LocalCoords::kUnused_Type); |
| 204 | Coverage::Type coverageType; |
| 205 | if (fPipelineInfo.readsCoverage()) { |
| 206 | coverageType = Coverage::kSolid_Type; |
| 207 | } else { |
| 208 | coverageType = Coverage::kNone_Type; |
| 209 | } |
| 210 | Coverage coverage(coverageType); |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 211 | gp = GrDefaultGeoProcFactory::Make(color, coverage, localCoords, fViewMatrix); |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 212 | } |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 213 | this->draw(target, gp.get()); |
| 214 | } |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 215 | |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 216 | void drawVertices(Target* target, const GrGeometryProcessor* gp, const GrBuffer* vb, |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 217 | int firstVertex, int count) const { |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 218 | SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); |
senorblanco | 9ba3972 | 2015-03-05 07:13:42 -0800 | [diff] [blame] | 219 | |
ethannicholas | e9709e8 | 2016-01-07 13:34:16 -0800 | [diff] [blame] | 220 | GrPrimitiveType primitiveType = TESSELLATOR_WIREFRAME ? kLines_GrPrimitiveType |
| 221 | : kTriangles_GrPrimitiveType; |
egdaniel | 0e1853c | 2016-03-17 11:35:45 -0700 | [diff] [blame] | 222 | GrMesh mesh; |
| 223 | mesh.init(primitiveType, vb, firstVertex, count); |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 224 | target->draw(gp, mesh); |
senorblanco | 9ba3972 | 2015-03-05 07:13:42 -0800 | [diff] [blame] | 225 | } |
| 226 | |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 227 | bool onCombineIfPossible(GrBatch*, const GrCaps&) override { return false; } |
senorblanco | 9ba3972 | 2015-03-05 07:13:42 -0800 | [diff] [blame] | 228 | |
senorblanco | 9ba3972 | 2015-03-05 07:13:42 -0800 | [diff] [blame] | 229 | TessellatingPathBatch(const GrColor& color, |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 230 | const GrShape& shape, |
senorblanco | 9ba3972 | 2015-03-05 07:13:42 -0800 | [diff] [blame] | 231 | const SkMatrix& viewMatrix, |
| 232 | const SkRect& clipBounds) |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 233 | : INHERITED(ClassID()) |
| 234 | , fColor(color) |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 235 | , fShape(shape) |
bsalomon | db4758c | 2015-11-23 11:14:20 -0800 | [diff] [blame] | 236 | , fViewMatrix(viewMatrix) { |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 237 | const SkRect& pathBounds = shape.bounds(); |
bsalomon | db4758c | 2015-11-23 11:14:20 -0800 | [diff] [blame] | 238 | fClipBounds = clipBounds; |
| 239 | // Because the clip bounds are used to add a contour for inverse fills, they must also |
| 240 | // include the path bounds. |
| 241 | fClipBounds.join(pathBounds); |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 242 | const SkRect& srcBounds = shape.inverseFilled() ? fClipBounds : pathBounds; |
| 243 | this->setTransformedBounds(srcBounds, viewMatrix, HasAABloat::kNo, IsZeroArea::kNo); |
senorblanco | 9ba3972 | 2015-03-05 07:13:42 -0800 | [diff] [blame] | 244 | } |
| 245 | |
bsalomon | 91d844d | 2015-08-10 10:47:29 -0700 | [diff] [blame] | 246 | GrColor fColor; |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 247 | GrShape fShape; |
bsalomon | 91d844d | 2015-08-10 10:47:29 -0700 | [diff] [blame] | 248 | SkMatrix fViewMatrix; |
| 249 | SkRect fClipBounds; // in source space |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 250 | GrXPOverridesForBatch fPipelineInfo; |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 251 | |
| 252 | typedef GrVertexBatch INHERITED; |
senorblanco | 9ba3972 | 2015-03-05 07:13:42 -0800 | [diff] [blame] | 253 | }; |
| 254 | |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 255 | bool GrTessellatingPathRenderer::onDrawPath(const DrawPathArgs& args) { |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 256 | GR_AUDIT_TRAIL_AUTO_FRAME(args.fDrawContext->auditTrail(), |
joshualitt | de83b41 | 2016-01-14 09:58:36 -0800 | [diff] [blame] | 257 | "GrTessellatingPathRenderer::onDrawPath"); |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 258 | SkASSERT(!args.fAntiAlias); |
senorblanco | d6ed19c | 2015-02-26 06:58:17 -0800 | [diff] [blame] | 259 | |
senorblanco | d6ed19c | 2015-02-26 06:58:17 -0800 | [diff] [blame] | 260 | SkIRect clipBoundsI; |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 261 | args.fClip->getConservativeBounds(args.fDrawContext->width(), args.fDrawContext->height(), |
| 262 | &clipBoundsI); |
senorblanco | d6ed19c | 2015-02-26 06:58:17 -0800 | [diff] [blame] | 263 | SkRect clipBounds = SkRect::Make(clipBoundsI); |
| 264 | SkMatrix vmi; |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 265 | if (!args.fViewMatrix->invert(&vmi)) { |
senorblanco | d6ed19c | 2015-02-26 06:58:17 -0800 | [diff] [blame] | 266 | return false; |
| 267 | } |
| 268 | vmi.mapRect(&clipBounds); |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 269 | SkPath path; |
| 270 | args.fShape->asPath(&path); |
robertphillips | 3950f0d | 2016-07-07 07:33:13 -0700 | [diff] [blame] | 271 | SkAutoTUnref<GrDrawBatch> batch(TessellatingPathBatch::Create(args.fPaint->getColor(), |
| 272 | *args.fShape, |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 273 | *args.fViewMatrix, clipBounds)); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 274 | |
bsalomon | bb24383 | 2016-07-22 07:10:19 -0700 | [diff] [blame^] | 275 | GrPipelineBuilder pipelineBuilder(*args.fPaint, args.fDrawContext->mustUseHWAA(*args.fPaint)); |
| 276 | pipelineBuilder.setUserStencil(args.fUserStencilSettings); |
| 277 | |
| 278 | args.fDrawContext->drawBatch(pipelineBuilder, *args.fClip, batch); |
senorblanco | d6ed19c | 2015-02-26 06:58:17 -0800 | [diff] [blame] | 279 | |
| 280 | return true; |
| 281 | } |
joshualitt | 2fbd406 | 2015-05-07 13:06:41 -0700 | [diff] [blame] | 282 | |
| 283 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 284 | |
| 285 | #ifdef GR_TEST_UTILS |
| 286 | |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 287 | DRAW_BATCH_TEST_DEFINE(TesselatingPathBatch) { |
joshualitt | 2fbd406 | 2015-05-07 13:06:41 -0700 | [diff] [blame] | 288 | GrColor color = GrRandomColor(random); |
| 289 | SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); |
| 290 | SkPath path = GrTest::TestPath(random); |
| 291 | SkRect clipBounds = GrTest::TestRect(random); |
| 292 | SkMatrix vmi; |
| 293 | bool result = viewMatrix.invert(&vmi); |
| 294 | if (!result) { |
| 295 | SkFAIL("Cannot invert matrix\n"); |
| 296 | } |
| 297 | vmi.mapRect(&clipBounds); |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 298 | GrStyle style; |
| 299 | do { |
| 300 | GrTest::TestStyle(random, &style); |
| 301 | } while (style.strokeRec().isHairlineStyle()); |
bsalomon | ee43241 | 2016-06-27 07:18:18 -0700 | [diff] [blame] | 302 | GrShape shape(path, style); |
| 303 | return TessellatingPathBatch::Create(color, shape, viewMatrix, clipBounds); |
joshualitt | 2fbd406 | 2015-05-07 13:06:41 -0700 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | #endif |