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