| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "GrTessellatingPathRenderer.h" | 8 #include "GrTessellatingPathRenderer.h" |
| 9 | 9 |
| 10 #include "GrBatchFlushState.h" | 10 #include "GrBatchFlushState.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 } // namespace | 100 } // namespace |
| 101 | 101 |
| 102 GrTessellatingPathRenderer::GrTessellatingPathRenderer() { | 102 GrTessellatingPathRenderer::GrTessellatingPathRenderer() { |
| 103 } | 103 } |
| 104 | 104 |
| 105 bool GrTessellatingPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) cons
t { | 105 bool GrTessellatingPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) cons
t { |
| 106 // This path renderer can draw all fill styles, all stroke styles except hai
rlines, but does | 106 // This path renderer can draw all fill styles, all stroke styles except hai
rlines, but does |
| 107 // not do antialiasing. It can do convex and concave paths, but we'll leave
the convex ones to | 107 // not do antialiasing. It can do convex and concave paths, but we'll leave
the convex ones to |
| 108 // simpler algorithms. Similary, we skip the non-hairlines that can be treat
ed as hairline. | 108 // simpler algorithms. Similarly, we skip the non-hairlines that can be trea
ted as hairline. |
| 109 // An arbitrary path effect could produce a hairline result so we pass on th
ose. | 109 // An arbitrary path effect could produce a hairline result so we pass on th
ose. We also skip |
| 110 return !IsStrokeHairlineOrEquivalent(*args.fStyle, *args.fViewMatrix, nullpt
r) && | 110 // volatile paths since they are not cacheable. |
| 111 return !args.fAntiAlias && !args.fPath->isVolatile() && |
| 111 !args.fStyle->strokeRec().isHairlineStyle() && | 112 !args.fStyle->strokeRec().isHairlineStyle() && |
| 112 !args.fStyle->hasNonDashPathEffect() && !args.fAntiAlias && !args.fPa
th->isConvex(); | 113 !args.fStyle->hasNonDashPathEffect() && |
| 114 !IsStrokeHairlineOrEquivalent(*args.fStyle, *args.fViewMatrix, nullpt
r) && |
| 115 !args.fPath->isConvex(); |
| 113 } | 116 } |
| 114 | 117 |
| 115 class TessellatingPathBatch : public GrVertexBatch { | 118 class TessellatingPathBatch : public GrVertexBatch { |
| 116 public: | 119 public: |
| 117 DEFINE_BATCH_CLASS_ID | 120 DEFINE_BATCH_CLASS_ID |
| 118 | 121 |
| 119 static GrDrawBatch* Create(const GrColor& color, | 122 static GrDrawBatch* Create(const GrColor& color, |
| 120 const SkPath& path, | 123 const SkPath& path, |
| 121 const GrStyle& style, | 124 const GrStyle& style, |
| 122 const SkMatrix& viewMatrix, | 125 const SkMatrix& viewMatrix, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 153 if (fStyle.applies()) { | 156 if (fStyle.applies()) { |
| 154 styleScale = GrStyle::MatrixToScaleFactor(fViewMatrix); | 157 styleScale = GrStyle::MatrixToScaleFactor(fViewMatrix); |
| 155 } | 158 } |
| 156 | 159 |
| 157 // construct a cache key from the path's genID and the view matrix | 160 // construct a cache key from the path's genID and the view matrix |
| 158 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain()
; | 161 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain()
; |
| 159 GrUniqueKey key; | 162 GrUniqueKey key; |
| 160 int clipBoundsCnt = | 163 int clipBoundsCnt = |
| 161 fPath.isInverseFillType() ? sizeof(fClipBounds) / sizeof(uint32_t) :
0; | 164 fPath.isInverseFillType() ? sizeof(fClipBounds) / sizeof(uint32_t) :
0; |
| 162 int styleDataCnt = GrStyle::KeySize(fStyle, GrStyle::Apply::kPathEffectA
ndStrokeRec); | 165 int styleDataCnt = GrStyle::KeySize(fStyle, GrStyle::Apply::kPathEffectA
ndStrokeRec); |
| 163 if (styleDataCnt >= 0) { | 166 // We should have excluded anything we wouldn't know how to cache. |
| 164 GrUniqueKey::Builder builder(&key, kDomain, 2 + clipBoundsCnt + styl
eDataCnt); | 167 SkASSERT(styleDataCnt >= 0); |
| 165 builder[0] = fPath.getGenerationID(); | 168 GrUniqueKey::Builder builder(&key, kDomain, 2 + clipBoundsCnt + styleDat
aCnt); |
| 166 builder[1] = fPath.getFillType(); | 169 builder[0] = fPath.getGenerationID(); |
| 167 // For inverse fills, the tessellation is dependent on clip bounds. | 170 builder[1] = fPath.getFillType(); |
| 168 if (fPath.isInverseFillType()) { | 171 // For inverse fills, the tessellation is dependent on clip bounds. |
| 169 memcpy(&builder[2], &fClipBounds, sizeof(fClipBounds)); | 172 if (fPath.isInverseFillType()) { |
| 170 } | 173 memcpy(&builder[2], &fClipBounds, sizeof(fClipBounds)); |
| 171 if (styleDataCnt) { | 174 } |
| 172 GrStyle::WriteKey(&builder[2 + clipBoundsCnt], fStyle, | 175 if (styleDataCnt) { |
| 173 GrStyle::Apply::kPathEffectAndStrokeRec, style
Scale); | 176 GrStyle::WriteKey(&builder[2 + clipBoundsCnt], fStyle, |
| 174 } | 177 GrStyle::Apply::kPathEffectAndStrokeRec, styleScal
e); |
| 175 builder.finish(); | 178 } |
| 176 SkAutoTUnref<GrBuffer> cachedVertexBuffer(rp->findAndRefTByUniqueKey
<GrBuffer>(key)); | 179 builder.finish(); |
| 177 int actualCount; | 180 SkAutoTUnref<GrBuffer> cachedVertexBuffer(rp->findAndRefTByUniqueKey<GrB
uffer>(key)); |
| 178 if (cache_match(cachedVertexBuffer.get(), tol, &actualCount)) { | 181 int actualCount; |
| 179 this->drawVertices(target, gp, cachedVertexBuffer.get(), 0, actu
alCount); | 182 if (cache_match(cachedVertexBuffer.get(), tol, &actualCount)) { |
| 180 return; | 183 this->drawVertices(target, gp, cachedVertexBuffer.get(), 0, actualCo
unt); |
| 181 } | 184 return; |
| 182 } | 185 } |
| 183 | 186 |
| 184 SkPath path; | 187 SkPath path; |
| 185 if (fStyle.applies()) { | 188 if (fStyle.applies()) { |
| 186 SkStrokeRec::InitStyle fill; | 189 SkStrokeRec::InitStyle fill; |
| 187 SkAssertResult(fStyle.applyToPath(&path, &fill, fPath, styleScale)); | 190 SkAssertResult(fStyle.applyToPath(&path, &fill, fPath, styleScale)); |
| 188 SkASSERT(SkStrokeRec::kFill_InitStyle == fill); | 191 SkASSERT(SkStrokeRec::kFill_InitStyle == fill); |
| 189 } else { | 192 } else { |
| 190 path = fPath; | 193 path = fPath; |
| 191 } | 194 } |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 } | 321 } |
| 319 vmi.mapRect(&clipBounds); | 322 vmi.mapRect(&clipBounds); |
| 320 GrStyle style; | 323 GrStyle style; |
| 321 do { | 324 do { |
| 322 GrTest::TestStyle(random, &style); | 325 GrTest::TestStyle(random, &style); |
| 323 } while (style.strokeRec().isHairlineStyle()); | 326 } while (style.strokeRec().isHairlineStyle()); |
| 324 return TessellatingPathBatch::Create(color, path, style, viewMatrix, clipBou
nds); | 327 return TessellatingPathBatch::Create(color, path, style, viewMatrix, clipBou
nds); |
| 325 } | 328 } |
| 326 | 329 |
| 327 #endif | 330 #endif |
| OLD | NEW |