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 | |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 10 | #include "GrBatchFlushState.h" |
joshualitt | 2fbd406 | 2015-05-07 13:06:41 -0700 | [diff] [blame] | 11 | #include "GrBatchTest.h" |
senorblanco | d6ed19c | 2015-02-26 06:58:17 -0800 | [diff] [blame] | 12 | #include "GrDefaultGeoProcFactory.h" |
| 13 | #include "GrPathUtils.h" |
bsalomon | cb8979d | 2015-05-05 09:51:38 -0700 | [diff] [blame] | 14 | #include "GrVertices.h" |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 15 | #include "GrResourceCache.h" |
| 16 | #include "GrResourceProvider.h" |
ethannicholas | e9709e8 | 2016-01-07 13:34:16 -0800 | [diff] [blame] | 17 | #include "GrTessellator.h" |
senorblanco | d6ed19c | 2015-02-26 06:58:17 -0800 | [diff] [blame] | 18 | #include "SkGeometry.h" |
| 19 | |
bsalomon | 16b9913 | 2015-08-13 14:55:50 -0700 | [diff] [blame] | 20 | #include "batches/GrVertexBatch.h" |
joshualitt | 7441782 | 2015-08-07 11:42:16 -0700 | [diff] [blame] | 21 | |
senorblanco | d6ed19c | 2015-02-26 06:58:17 -0800 | [diff] [blame] | 22 | #include <stdio.h> |
| 23 | |
| 24 | /* |
ethannicholas | e9709e8 | 2016-01-07 13:34:16 -0800 | [diff] [blame] | 25 | * This path renderer tessellates the path into triangles using GrTessellator, uploads the triangles |
| 26 | * 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] | 27 | * antialiasing, so it must be used in conjunction with multisampling. |
senorblanco | d6ed19c | 2015-02-26 06:58:17 -0800 | [diff] [blame] | 28 | */ |
senorblanco | d6ed19c | 2015-02-26 06:58:17 -0800 | [diff] [blame] | 29 | namespace { |
| 30 | |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 31 | struct TessInfo { |
| 32 | SkScalar fTolerance; |
senorblanco | 06f989a | 2015-09-02 09:05:17 -0700 | [diff] [blame] | 33 | int fCount; |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 34 | }; |
| 35 | |
ethannicholas | e9709e8 | 2016-01-07 13:34:16 -0800 | [diff] [blame] | 36 | // When the SkPathRef genID changes, invalidate a corresponding GrResource described by key. |
| 37 | class PathInvalidator : public SkPathRef::GenIDChangeListener { |
| 38 | public: |
| 39 | explicit PathInvalidator(const GrUniqueKey& key) : fMsg(key) {} |
| 40 | private: |
| 41 | GrUniqueKeyInvalidatedMessage fMsg; |
| 42 | |
| 43 | void onChange() override { |
| 44 | SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(fMsg); |
| 45 | } |
| 46 | }; |
| 47 | |
senorblanco | 06f989a | 2015-09-02 09:05:17 -0700 | [diff] [blame] | 48 | bool cache_match(GrVertexBuffer* vertexBuffer, SkScalar tol, int* actualCount) { |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 49 | if (!vertexBuffer) { |
| 50 | return false; |
| 51 | } |
| 52 | const SkData* data = vertexBuffer->getUniqueKey().getCustomData(); |
| 53 | SkASSERT(data); |
| 54 | const TessInfo* info = static_cast<const TessInfo*>(data->data()); |
| 55 | if (info->fTolerance == 0 || info->fTolerance < 3.0f * tol) { |
senorblanco | 06f989a | 2015-09-02 09:05:17 -0700 | [diff] [blame] | 56 | *actualCount = info->fCount; |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 57 | return true; |
| 58 | } |
| 59 | return false; |
| 60 | } |
| 61 | |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 62 | class StaticVertexAllocator : public GrTessellator::VertexAllocator { |
| 63 | public: |
senorblanco | af1e21e | 2016-03-16 10:25:58 -0700 | [diff] [blame^] | 64 | StaticVertexAllocator(GrResourceProvider* resourceProvider, bool canMapVB) |
| 65 | : fResourceProvider(resourceProvider) |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 66 | , fCanMapVB(canMapVB) |
| 67 | , fVertices(nullptr) { |
| 68 | } |
| 69 | SkPoint* lock(int vertexCount) override { |
| 70 | size_t size = vertexCount * sizeof(SkPoint); |
senorblanco | af1e21e | 2016-03-16 10:25:58 -0700 | [diff] [blame^] | 71 | fVertexBuffer.reset(fResourceProvider->createVertexBuffer( |
| 72 | size, GrResourceProvider::kStatic_BufferUsage, 0)); |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 73 | if (!fVertexBuffer.get()) { |
| 74 | return nullptr; |
| 75 | } |
| 76 | if (fCanMapVB) { |
| 77 | fVertices = static_cast<SkPoint*>(fVertexBuffer->map()); |
| 78 | } else { |
| 79 | fVertices = new SkPoint[vertexCount]; |
| 80 | } |
| 81 | return fVertices; |
| 82 | } |
| 83 | void unlock(int actualCount) override { |
| 84 | if (fCanMapVB) { |
| 85 | fVertexBuffer->unmap(); |
| 86 | } else { |
| 87 | fVertexBuffer->updateData(fVertices, actualCount * sizeof(SkPoint)); |
| 88 | delete[] fVertices; |
| 89 | } |
| 90 | fVertices = nullptr; |
| 91 | } |
senorblanco | af1e21e | 2016-03-16 10:25:58 -0700 | [diff] [blame^] | 92 | GrVertexBuffer* vertexBuffer() { return fVertexBuffer.get(); } |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 93 | private: |
senorblanco | af1e21e | 2016-03-16 10:25:58 -0700 | [diff] [blame^] | 94 | SkAutoTUnref<GrVertexBuffer> fVertexBuffer; |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 95 | GrResourceProvider* fResourceProvider; |
| 96 | bool fCanMapVB; |
| 97 | SkPoint* fVertices; |
| 98 | }; |
| 99 | |
ethannicholas | e9709e8 | 2016-01-07 13:34:16 -0800 | [diff] [blame] | 100 | } // namespace |
senorblanco | d6ed19c | 2015-02-26 06:58:17 -0800 | [diff] [blame] | 101 | |
| 102 | GrTessellatingPathRenderer::GrTessellatingPathRenderer() { |
| 103 | } |
| 104 | |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 105 | bool GrTessellatingPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const { |
senorblanco | b4f9d0e | 2015-08-06 10:28:55 -0700 | [diff] [blame] | 106 | // This path renderer can draw all fill styles, all stroke styles except hairlines, but does |
| 107 | // not do antialiasing. It can do convex and concave paths, but we'll leave the convex ones to |
| 108 | // simpler algorithms. |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 109 | return !IsStrokeHairlineOrEquivalent(*args.fStroke, *args.fViewMatrix, nullptr) && |
senorblanco | b4f9d0e | 2015-08-06 10:28:55 -0700 | [diff] [blame] | 110 | !args.fAntiAlias && !args.fPath->isConvex(); |
senorblanco | d6ed19c | 2015-02-26 06:58:17 -0800 | [diff] [blame] | 111 | } |
| 112 | |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 113 | class TessellatingPathBatch : public GrVertexBatch { |
senorblanco | 9ba3972 | 2015-03-05 07:13:42 -0800 | [diff] [blame] | 114 | public: |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 115 | DEFINE_BATCH_CLASS_ID |
senorblanco | 9ba3972 | 2015-03-05 07:13:42 -0800 | [diff] [blame] | 116 | |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 117 | static GrDrawBatch* Create(const GrColor& color, |
| 118 | const SkPath& path, |
| 119 | const GrStrokeInfo& stroke, |
| 120 | const SkMatrix& viewMatrix, |
| 121 | SkRect clipBounds) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 122 | return new TessellatingPathBatch(color, path, stroke, viewMatrix, clipBounds); |
senorblanco | 9ba3972 | 2015-03-05 07:13:42 -0800 | [diff] [blame] | 123 | } |
| 124 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 125 | const char* name() const override { return "TessellatingPathBatch"; } |
senorblanco | 9ba3972 | 2015-03-05 07:13:42 -0800 | [diff] [blame] | 126 | |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 127 | void computePipelineOptimizations(GrInitInvariantOutput* color, |
| 128 | GrInitInvariantOutput* coverage, |
| 129 | GrBatchToXPOverrides* overrides) const override { |
| 130 | color->setKnownFourComponents(fColor); |
| 131 | coverage->setUnknownSingleComponent(); |
senorblanco | 9ba3972 | 2015-03-05 07:13:42 -0800 | [diff] [blame] | 132 | } |
| 133 | |
bsalomon | e46f9fe | 2015-08-18 06:05:14 -0700 | [diff] [blame] | 134 | private: |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 135 | void initBatchTracker(const GrXPOverridesForBatch& overrides) override { |
senorblanco | 9ba3972 | 2015-03-05 07:13:42 -0800 | [diff] [blame] | 136 | // Handle any color overrides |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 137 | if (!overrides.readsColor()) { |
senorblanco | 9ba3972 | 2015-03-05 07:13:42 -0800 | [diff] [blame] | 138 | fColor = GrColor_ILLEGAL; |
senorblanco | 9ba3972 | 2015-03-05 07:13:42 -0800 | [diff] [blame] | 139 | } |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 140 | overrides.getOverrideColorIfSet(&fColor); |
| 141 | fPipelineInfo = overrides; |
senorblanco | 9ba3972 | 2015-03-05 07:13:42 -0800 | [diff] [blame] | 142 | } |
| 143 | |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 144 | void draw(Target* target, const GrGeometryProcessor* gp) const { |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 145 | // construct a cache key from the path's genID and the view matrix |
| 146 | static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); |
| 147 | GrUniqueKey key; |
| 148 | int clipBoundsSize32 = |
| 149 | fPath.isInverseFillType() ? sizeof(fClipBounds) / sizeof(uint32_t) : 0; |
senorblanco | b4f9d0e | 2015-08-06 10:28:55 -0700 | [diff] [blame] | 150 | int strokeDataSize32 = fStroke.computeUniqueKeyFragmentData32Cnt(); |
| 151 | GrUniqueKey::Builder builder(&key, kDomain, 2 + clipBoundsSize32 + strokeDataSize32); |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 152 | builder[0] = fPath.getGenerationID(); |
| 153 | builder[1] = fPath.getFillType(); |
| 154 | // For inverse fills, the tessellation is dependent on clip bounds. |
| 155 | if (fPath.isInverseFillType()) { |
| 156 | memcpy(&builder[2], &fClipBounds, sizeof(fClipBounds)); |
| 157 | } |
senorblanco | b4f9d0e | 2015-08-06 10:28:55 -0700 | [diff] [blame] | 158 | fStroke.asUniqueKeyFragment(&builder[2 + clipBoundsSize32]); |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 159 | builder.finish(); |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 160 | GrResourceProvider* rp = target->resourceProvider(); |
senorblanco | af1e21e | 2016-03-16 10:25:58 -0700 | [diff] [blame^] | 161 | SkAutoTUnref<GrVertexBuffer> cachedVertexBuffer( |
| 162 | rp->findAndRefTByUniqueKey<GrVertexBuffer>(key)); |
senorblanco | 06f989a | 2015-09-02 09:05:17 -0700 | [diff] [blame] | 163 | int actualCount; |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 164 | SkScalar screenSpaceTol = GrPathUtils::kDefaultTolerance; |
| 165 | SkScalar tol = GrPathUtils::scaleToleranceToSrc( |
| 166 | screenSpaceTol, fViewMatrix, fPath.getBounds()); |
senorblanco | af1e21e | 2016-03-16 10:25:58 -0700 | [diff] [blame^] | 167 | if (cache_match(cachedVertexBuffer.get(), tol, &actualCount)) { |
| 168 | this->drawVertices(target, gp, cachedVertexBuffer.get(), 0, actualCount); |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 169 | return; |
| 170 | } |
| 171 | |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 172 | SkPath path; |
| 173 | GrStrokeInfo stroke(fStroke); |
| 174 | if (stroke.isDashed()) { |
| 175 | if (!stroke.applyDashToPath(&path, &stroke, fPath)) { |
| 176 | return; |
| 177 | } |
| 178 | } else { |
| 179 | path = fPath; |
| 180 | } |
| 181 | if (!stroke.isFillStyle()) { |
| 182 | stroke.setResScale(SkScalarAbs(fViewMatrix.getMaxScale())); |
| 183 | if (!stroke.applyToPath(&path, path)) { |
| 184 | return; |
| 185 | } |
| 186 | stroke.setFillStyle(); |
| 187 | } |
| 188 | bool isLinear; |
| 189 | bool canMapVB = GrCaps::kNone_MapFlags != target->caps().mapBufferFlags(); |
senorblanco | af1e21e | 2016-03-16 10:25:58 -0700 | [diff] [blame^] | 190 | StaticVertexAllocator allocator(rp, canMapVB); |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 191 | int count = GrTessellator::PathToTriangles(path, tol, fClipBounds, &allocator, &isLinear); |
| 192 | if (count == 0) { |
| 193 | return; |
| 194 | } |
senorblanco | af1e21e | 2016-03-16 10:25:58 -0700 | [diff] [blame^] | 195 | this->drawVertices(target, gp, allocator.vertexBuffer(), 0, count); |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 196 | if (!fPath.isVolatile()) { |
| 197 | TessInfo info; |
| 198 | info.fTolerance = isLinear ? 0 : tol; |
| 199 | info.fCount = count; |
| 200 | SkAutoTUnref<SkData> data(SkData::NewWithCopy(&info, sizeof(info))); |
| 201 | key.setCustomData(data.get()); |
senorblanco | af1e21e | 2016-03-16 10:25:58 -0700 | [diff] [blame^] | 202 | rp->assignUniqueKeyToResource(key, allocator.vertexBuffer()); |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 203 | SkPathPriv::AddGenIDChangeListener(fPath, new PathInvalidator(key)); |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | void onPrepareDraws(Target* target) const override { |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 208 | SkAutoTUnref<const GrGeometryProcessor> gp; |
| 209 | { |
| 210 | using namespace GrDefaultGeoProcFactory; |
| 211 | |
| 212 | Color color(fColor); |
| 213 | LocalCoords localCoords(fPipelineInfo.readsLocalCoords() ? |
| 214 | LocalCoords::kUsePosition_Type : |
| 215 | LocalCoords::kUnused_Type); |
| 216 | Coverage::Type coverageType; |
| 217 | if (fPipelineInfo.readsCoverage()) { |
| 218 | coverageType = Coverage::kSolid_Type; |
| 219 | } else { |
| 220 | coverageType = Coverage::kNone_Type; |
| 221 | } |
| 222 | Coverage coverage(coverageType); |
| 223 | gp.reset(GrDefaultGeoProcFactory::Create(color, coverage, localCoords, |
| 224 | fViewMatrix)); |
| 225 | } |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 226 | this->draw(target, gp.get()); |
| 227 | } |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 228 | |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 229 | void drawVertices(Target* target, const GrGeometryProcessor* gp, const GrVertexBuffer* vb, |
| 230 | int firstVertex, int count) const { |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 231 | target->initDraw(gp, this->pipeline()); |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 232 | SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); |
senorblanco | 9ba3972 | 2015-03-05 07:13:42 -0800 | [diff] [blame] | 233 | |
ethannicholas | e9709e8 | 2016-01-07 13:34:16 -0800 | [diff] [blame] | 234 | GrPrimitiveType primitiveType = TESSELLATOR_WIREFRAME ? kLines_GrPrimitiveType |
| 235 | : kTriangles_GrPrimitiveType; |
bsalomon | cb8979d | 2015-05-05 09:51:38 -0700 | [diff] [blame] | 236 | GrVertices vertices; |
senorblanco | 6599eff | 2016-03-10 08:38:45 -0800 | [diff] [blame] | 237 | vertices.init(primitiveType, vb, firstVertex, count); |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 238 | target->draw(vertices); |
senorblanco | 9ba3972 | 2015-03-05 07:13:42 -0800 | [diff] [blame] | 239 | } |
| 240 | |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 241 | bool onCombineIfPossible(GrBatch*, const GrCaps&) override { return false; } |
senorblanco | 9ba3972 | 2015-03-05 07:13:42 -0800 | [diff] [blame] | 242 | |
senorblanco | 9ba3972 | 2015-03-05 07:13:42 -0800 | [diff] [blame] | 243 | TessellatingPathBatch(const GrColor& color, |
| 244 | const SkPath& path, |
senorblanco | b4f9d0e | 2015-08-06 10:28:55 -0700 | [diff] [blame] | 245 | const GrStrokeInfo& stroke, |
senorblanco | 9ba3972 | 2015-03-05 07:13:42 -0800 | [diff] [blame] | 246 | const SkMatrix& viewMatrix, |
| 247 | const SkRect& clipBounds) |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 248 | : INHERITED(ClassID()) |
| 249 | , fColor(color) |
senorblanco | 9ba3972 | 2015-03-05 07:13:42 -0800 | [diff] [blame] | 250 | , fPath(path) |
senorblanco | b4f9d0e | 2015-08-06 10:28:55 -0700 | [diff] [blame] | 251 | , fStroke(stroke) |
bsalomon | db4758c | 2015-11-23 11:14:20 -0800 | [diff] [blame] | 252 | , fViewMatrix(viewMatrix) { |
| 253 | const SkRect& pathBounds = path.getBounds(); |
| 254 | fClipBounds = clipBounds; |
| 255 | // Because the clip bounds are used to add a contour for inverse fills, they must also |
| 256 | // include the path bounds. |
| 257 | fClipBounds.join(pathBounds); |
| 258 | if (path.isInverseFillType()) { |
| 259 | fBounds = fClipBounds; |
| 260 | } else { |
| 261 | fBounds = path.getBounds(); |
| 262 | } |
senorblanco | b4f9d0e | 2015-08-06 10:28:55 -0700 | [diff] [blame] | 263 | if (!stroke.isFillStyle()) { |
| 264 | SkScalar radius = SkScalarHalf(stroke.getWidth()); |
| 265 | if (stroke.getJoin() == SkPaint::kMiter_Join) { |
| 266 | SkScalar scale = stroke.getMiter(); |
| 267 | if (scale > SK_Scalar1) { |
| 268 | radius = SkScalarMul(radius, scale); |
| 269 | } |
| 270 | } |
| 271 | fBounds.outset(radius, radius); |
| 272 | } |
joshualitt | 99c7c07 | 2015-05-01 13:43:30 -0700 | [diff] [blame] | 273 | viewMatrix.mapRect(&fBounds); |
senorblanco | 9ba3972 | 2015-03-05 07:13:42 -0800 | [diff] [blame] | 274 | } |
| 275 | |
bsalomon | 91d844d | 2015-08-10 10:47:29 -0700 | [diff] [blame] | 276 | GrColor fColor; |
| 277 | SkPath fPath; |
| 278 | GrStrokeInfo fStroke; |
| 279 | SkMatrix fViewMatrix; |
| 280 | SkRect fClipBounds; // in source space |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 281 | GrXPOverridesForBatch fPipelineInfo; |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 282 | |
| 283 | typedef GrVertexBatch INHERITED; |
senorblanco | 9ba3972 | 2015-03-05 07:13:42 -0800 | [diff] [blame] | 284 | }; |
| 285 | |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 286 | bool GrTessellatingPathRenderer::onDrawPath(const DrawPathArgs& args) { |
joshualitt | de83b41 | 2016-01-14 09:58:36 -0800 | [diff] [blame] | 287 | GR_AUDIT_TRAIL_AUTO_FRAME(args.fTarget->getAuditTrail(), |
| 288 | "GrTessellatingPathRenderer::onDrawPath"); |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 289 | SkASSERT(!args.fAntiAlias); |
| 290 | const GrRenderTarget* rt = args.fPipelineBuilder->getRenderTarget(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 291 | if (nullptr == rt) { |
senorblanco | d6ed19c | 2015-02-26 06:58:17 -0800 | [diff] [blame] | 292 | return false; |
| 293 | } |
| 294 | |
senorblanco | d6ed19c | 2015-02-26 06:58:17 -0800 | [diff] [blame] | 295 | SkIRect clipBoundsI; |
robertphillips | 7bceedc | 2015-12-01 12:51:26 -0800 | [diff] [blame] | 296 | args.fPipelineBuilder->clip().getConservativeBounds(rt->width(), rt->height(), &clipBoundsI); |
senorblanco | d6ed19c | 2015-02-26 06:58:17 -0800 | [diff] [blame] | 297 | SkRect clipBounds = SkRect::Make(clipBoundsI); |
| 298 | SkMatrix vmi; |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 299 | if (!args.fViewMatrix->invert(&vmi)) { |
senorblanco | d6ed19c | 2015-02-26 06:58:17 -0800 | [diff] [blame] | 300 | return false; |
| 301 | } |
| 302 | vmi.mapRect(&clipBounds); |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 303 | SkAutoTUnref<GrDrawBatch> batch(TessellatingPathBatch::Create(args.fColor, *args.fPath, |
| 304 | *args.fStroke, *args.fViewMatrix, |
| 305 | clipBounds)); |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 306 | args.fTarget->drawBatch(*args.fPipelineBuilder, batch); |
senorblanco | d6ed19c | 2015-02-26 06:58:17 -0800 | [diff] [blame] | 307 | |
| 308 | return true; |
| 309 | } |
joshualitt | 2fbd406 | 2015-05-07 13:06:41 -0700 | [diff] [blame] | 310 | |
| 311 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 312 | |
| 313 | #ifdef GR_TEST_UTILS |
| 314 | |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 315 | DRAW_BATCH_TEST_DEFINE(TesselatingPathBatch) { |
joshualitt | 2fbd406 | 2015-05-07 13:06:41 -0700 | [diff] [blame] | 316 | GrColor color = GrRandomColor(random); |
| 317 | SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); |
| 318 | SkPath path = GrTest::TestPath(random); |
| 319 | SkRect clipBounds = GrTest::TestRect(random); |
| 320 | SkMatrix vmi; |
| 321 | bool result = viewMatrix.invert(&vmi); |
| 322 | if (!result) { |
| 323 | SkFAIL("Cannot invert matrix\n"); |
| 324 | } |
| 325 | vmi.mapRect(&clipBounds); |
senorblanco | b4f9d0e | 2015-08-06 10:28:55 -0700 | [diff] [blame] | 326 | GrStrokeInfo strokeInfo = GrTest::TestStrokeInfo(random); |
| 327 | return TessellatingPathBatch::Create(color, path, strokeInfo, viewMatrix, clipBounds); |
joshualitt | 2fbd406 | 2015-05-07 13:06:41 -0700 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | #endif |