| 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 27 matching lines...) Expand all Loading... |
| 38 public: | 38 public: |
| 39 explicit PathInvalidator(const GrUniqueKey& key) : fMsg(key) {} | 39 explicit PathInvalidator(const GrUniqueKey& key) : fMsg(key) {} |
| 40 private: | 40 private: |
| 41 GrUniqueKeyInvalidatedMessage fMsg; | 41 GrUniqueKeyInvalidatedMessage fMsg; |
| 42 | 42 |
| 43 void onChange() override { | 43 void onChange() override { |
| 44 SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(fMsg); | 44 SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(fMsg); |
| 45 } | 45 } |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 bool cache_match(GrVertexBuffer* vertexBuffer, SkScalar tol, int* actualCount) { | 48 bool cache_match(GrBuffer* vertexBuffer, SkScalar tol, int* actualCount) { |
| 49 if (!vertexBuffer) { | 49 if (!vertexBuffer) { |
| 50 return false; | 50 return false; |
| 51 } | 51 } |
| 52 const SkData* data = vertexBuffer->getUniqueKey().getCustomData(); | 52 const SkData* data = vertexBuffer->getUniqueKey().getCustomData(); |
| 53 SkASSERT(data); | 53 SkASSERT(data); |
| 54 const TessInfo* info = static_cast<const TessInfo*>(data->data()); | 54 const TessInfo* info = static_cast<const TessInfo*>(data->data()); |
| 55 if (info->fTolerance == 0 || info->fTolerance < 3.0f * tol) { | 55 if (info->fTolerance == 0 || info->fTolerance < 3.0f * tol) { |
| 56 *actualCount = info->fCount; | 56 *actualCount = info->fCount; |
| 57 return true; | 57 return true; |
| 58 } | 58 } |
| 59 return false; | 59 return false; |
| 60 } | 60 } |
| 61 | 61 |
| 62 class StaticVertexAllocator : public GrTessellator::VertexAllocator { | 62 class StaticVertexAllocator : public GrTessellator::VertexAllocator { |
| 63 public: | 63 public: |
| 64 StaticVertexAllocator(GrResourceProvider* resourceProvider, bool canMapVB) | 64 StaticVertexAllocator(GrResourceProvider* resourceProvider, bool canMapVB) |
| 65 : fResourceProvider(resourceProvider) | 65 : fResourceProvider(resourceProvider) |
| 66 , fCanMapVB(canMapVB) | 66 , fCanMapVB(canMapVB) |
| 67 , fVertices(nullptr) { | 67 , fVertices(nullptr) { |
| 68 } | 68 } |
| 69 SkPoint* lock(int vertexCount) override { | 69 SkPoint* lock(int vertexCount) override { |
| 70 size_t size = vertexCount * sizeof(SkPoint); | 70 size_t size = vertexCount * sizeof(SkPoint); |
| 71 fVertexBuffer.reset(fResourceProvider->createVertexBuffer( | 71 fVertexBuffer.reset(fResourceProvider->createBuffer( |
| 72 size, GrResourceProvider::kStatic_BufferUsage, 0)); | 72 kVertex_GrBufferType, size, kStatic_GrAccessPattern, 0)); |
| 73 if (!fVertexBuffer.get()) { | 73 if (!fVertexBuffer.get()) { |
| 74 return nullptr; | 74 return nullptr; |
| 75 } | 75 } |
| 76 if (fCanMapVB) { | 76 if (fCanMapVB) { |
| 77 fVertices = static_cast<SkPoint*>(fVertexBuffer->map()); | 77 fVertices = static_cast<SkPoint*>(fVertexBuffer->map()); |
| 78 } else { | 78 } else { |
| 79 fVertices = new SkPoint[vertexCount]; | 79 fVertices = new SkPoint[vertexCount]; |
| 80 } | 80 } |
| 81 return fVertices; | 81 return fVertices; |
| 82 } | 82 } |
| 83 void unlock(int actualCount) override { | 83 void unlock(int actualCount) override { |
| 84 if (fCanMapVB) { | 84 if (fCanMapVB) { |
| 85 fVertexBuffer->unmap(); | 85 fVertexBuffer->unmap(); |
| 86 } else { | 86 } else { |
| 87 fVertexBuffer->updateData(fVertices, actualCount * sizeof(SkPoint)); | 87 fVertexBuffer->updateData(fVertices, actualCount * sizeof(SkPoint)); |
| 88 delete[] fVertices; | 88 delete[] fVertices; |
| 89 } | 89 } |
| 90 fVertices = nullptr; | 90 fVertices = nullptr; |
| 91 } | 91 } |
| 92 GrVertexBuffer* vertexBuffer() { return fVertexBuffer.get(); } | 92 GrBuffer* vertexBuffer() { return fVertexBuffer.get(); } |
| 93 private: | 93 private: |
| 94 SkAutoTUnref<GrVertexBuffer> fVertexBuffer; | 94 SkAutoTUnref<GrBuffer> fVertexBuffer; |
| 95 GrResourceProvider* fResourceProvider; | 95 GrResourceProvider* fResourceProvider; |
| 96 bool fCanMapVB; | 96 bool fCanMapVB; |
| 97 SkPoint* fVertices; | 97 SkPoint* fVertices; |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 } // namespace | 100 } // namespace |
| 101 | 101 |
| 102 GrTessellatingPathRenderer::GrTessellatingPathRenderer() { | 102 GrTessellatingPathRenderer::GrTessellatingPathRenderer() { |
| 103 } | 103 } |
| 104 | 104 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 GrUniqueKey::Builder builder(&key, kDomain, 2 + clipBoundsSize32 + strok
eDataSize32); | 151 GrUniqueKey::Builder builder(&key, kDomain, 2 + clipBoundsSize32 + strok
eDataSize32); |
| 152 builder[0] = fPath.getGenerationID(); | 152 builder[0] = fPath.getGenerationID(); |
| 153 builder[1] = fPath.getFillType(); | 153 builder[1] = fPath.getFillType(); |
| 154 // For inverse fills, the tessellation is dependent on clip bounds. | 154 // For inverse fills, the tessellation is dependent on clip bounds. |
| 155 if (fPath.isInverseFillType()) { | 155 if (fPath.isInverseFillType()) { |
| 156 memcpy(&builder[2], &fClipBounds, sizeof(fClipBounds)); | 156 memcpy(&builder[2], &fClipBounds, sizeof(fClipBounds)); |
| 157 } | 157 } |
| 158 fStroke.asUniqueKeyFragment(&builder[2 + clipBoundsSize32]); | 158 fStroke.asUniqueKeyFragment(&builder[2 + clipBoundsSize32]); |
| 159 builder.finish(); | 159 builder.finish(); |
| 160 GrResourceProvider* rp = target->resourceProvider(); | 160 GrResourceProvider* rp = target->resourceProvider(); |
| 161 SkAutoTUnref<GrVertexBuffer> cachedVertexBuffer( | 161 SkAutoTUnref<GrBuffer> cachedVertexBuffer(rp->findAndRefTByUniqueKey<GrB
uffer>(key)); |
| 162 rp->findAndRefTByUniqueKey<GrVertexBuffer>(key)); | |
| 163 int actualCount; | 162 int actualCount; |
| 164 SkScalar screenSpaceTol = GrPathUtils::kDefaultTolerance; | 163 SkScalar screenSpaceTol = GrPathUtils::kDefaultTolerance; |
| 165 SkScalar tol = GrPathUtils::scaleToleranceToSrc( | 164 SkScalar tol = GrPathUtils::scaleToleranceToSrc( |
| 166 screenSpaceTol, fViewMatrix, fPath.getBounds()); | 165 screenSpaceTol, fViewMatrix, fPath.getBounds()); |
| 167 if (cache_match(cachedVertexBuffer.get(), tol, &actualCount)) { | 166 if (cache_match(cachedVertexBuffer.get(), tol, &actualCount)) { |
| 168 this->drawVertices(target, gp, cachedVertexBuffer.get(), 0, actualCo
unt); | 167 this->drawVertices(target, gp, cachedVertexBuffer.get(), 0, actualCo
unt); |
| 169 return; | 168 return; |
| 170 } | 169 } |
| 171 | 170 |
| 172 SkPath path; | 171 SkPath path; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 } else { | 218 } else { |
| 220 coverageType = Coverage::kNone_Type; | 219 coverageType = Coverage::kNone_Type; |
| 221 } | 220 } |
| 222 Coverage coverage(coverageType); | 221 Coverage coverage(coverageType); |
| 223 gp.reset(GrDefaultGeoProcFactory::Create(color, coverage, localCoord
s, | 222 gp.reset(GrDefaultGeoProcFactory::Create(color, coverage, localCoord
s, |
| 224 fViewMatrix)); | 223 fViewMatrix)); |
| 225 } | 224 } |
| 226 this->draw(target, gp.get()); | 225 this->draw(target, gp.get()); |
| 227 } | 226 } |
| 228 | 227 |
| 229 void drawVertices(Target* target, const GrGeometryProcessor* gp, const GrVer
texBuffer* vb, | 228 void drawVertices(Target* target, const GrGeometryProcessor* gp, const GrBuf
fer* vb, |
| 230 int firstVertex, int count) const { | 229 int firstVertex, int count) const { |
| 231 SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); | 230 SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); |
| 232 | 231 |
| 233 GrPrimitiveType primitiveType = TESSELLATOR_WIREFRAME ? kLines_GrPrimiti
veType | 232 GrPrimitiveType primitiveType = TESSELLATOR_WIREFRAME ? kLines_GrPrimiti
veType |
| 234 : kTriangles_GrPri
mitiveType; | 233 : kTriangles_GrPri
mitiveType; |
| 235 target->initDraw(gp); | 234 target->initDraw(gp); |
| 236 | 235 |
| 237 GrMesh mesh; | 236 GrMesh mesh; |
| 238 mesh.init(primitiveType, vb, firstVertex, count); | 237 mesh.init(primitiveType, vb, firstVertex, count); |
| 239 target->draw(mesh); | 238 target->draw(mesh); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 bool result = viewMatrix.invert(&vmi); | 321 bool result = viewMatrix.invert(&vmi); |
| 323 if (!result) { | 322 if (!result) { |
| 324 SkFAIL("Cannot invert matrix\n"); | 323 SkFAIL("Cannot invert matrix\n"); |
| 325 } | 324 } |
| 326 vmi.mapRect(&clipBounds); | 325 vmi.mapRect(&clipBounds); |
| 327 GrStrokeInfo strokeInfo = GrTest::TestStrokeInfo(random); | 326 GrStrokeInfo strokeInfo = GrTest::TestStrokeInfo(random); |
| 328 return TessellatingPathBatch::Create(color, path, strokeInfo, viewMatrix, cl
ipBounds); | 327 return TessellatingPathBatch::Create(color, path, strokeInfo, viewMatrix, cl
ipBounds); |
| 329 } | 328 } |
| 330 | 329 |
| 331 #endif | 330 #endif |
| OLD | NEW |