Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: src/gpu/batches/GrTessellatingPathRenderer.cpp

Issue 1831133004: Revert of Consolidate GPU buffer implementations (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/batches/GrTInstanceBatch.h ('k') | src/gpu/batches/GrTestBatch.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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(GrBuffer* vertexBuffer, SkScalar tol, int* actualCount) { 48 bool cache_match(GrVertexBuffer* 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->createBuffer( 71 fVertexBuffer.reset(fResourceProvider->createVertexBuffer(
72 kVertex_GrBufferType, size, kStatic_GrAccessPattern, 0)); 72 size, GrResourceProvider::kStatic_BufferUsage, 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 GrBuffer* vertexBuffer() { return fVertexBuffer.get(); } 92 GrVertexBuffer* vertexBuffer() { return fVertexBuffer.get(); }
93 private: 93 private:
94 SkAutoTUnref<GrBuffer> fVertexBuffer; 94 SkAutoTUnref<GrVertexBuffer> 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
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<GrBuffer> cachedVertexBuffer(rp->findAndRefTByUniqueKey<GrB uffer>(key)); 161 SkAutoTUnref<GrVertexBuffer> cachedVertexBuffer(
162 rp->findAndRefTByUniqueKey<GrVertexBuffer>(key));
162 int actualCount; 163 int actualCount;
163 SkScalar screenSpaceTol = GrPathUtils::kDefaultTolerance; 164 SkScalar screenSpaceTol = GrPathUtils::kDefaultTolerance;
164 SkScalar tol = GrPathUtils::scaleToleranceToSrc( 165 SkScalar tol = GrPathUtils::scaleToleranceToSrc(
165 screenSpaceTol, fViewMatrix, fPath.getBounds()); 166 screenSpaceTol, fViewMatrix, fPath.getBounds());
166 if (cache_match(cachedVertexBuffer.get(), tol, &actualCount)) { 167 if (cache_match(cachedVertexBuffer.get(), tol, &actualCount)) {
167 this->drawVertices(target, gp, cachedVertexBuffer.get(), 0, actualCo unt); 168 this->drawVertices(target, gp, cachedVertexBuffer.get(), 0, actualCo unt);
168 return; 169 return;
169 } 170 }
170 171
171 SkPath path; 172 SkPath path;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 } else { 219 } else {
219 coverageType = Coverage::kNone_Type; 220 coverageType = Coverage::kNone_Type;
220 } 221 }
221 Coverage coverage(coverageType); 222 Coverage coverage(coverageType);
222 gp.reset(GrDefaultGeoProcFactory::Create(color, coverage, localCoord s, 223 gp.reset(GrDefaultGeoProcFactory::Create(color, coverage, localCoord s,
223 fViewMatrix)); 224 fViewMatrix));
224 } 225 }
225 this->draw(target, gp.get()); 226 this->draw(target, gp.get());
226 } 227 }
227 228
228 void drawVertices(Target* target, const GrGeometryProcessor* gp, const GrBuf fer* vb, 229 void drawVertices(Target* target, const GrGeometryProcessor* gp, const GrVer texBuffer* vb,
229 int firstVertex, int count) const { 230 int firstVertex, int count) const {
230 SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); 231 SkASSERT(gp->getVertexStride() == sizeof(SkPoint));
231 232
232 GrPrimitiveType primitiveType = TESSELLATOR_WIREFRAME ? kLines_GrPrimiti veType 233 GrPrimitiveType primitiveType = TESSELLATOR_WIREFRAME ? kLines_GrPrimiti veType
233 : kTriangles_GrPri mitiveType; 234 : kTriangles_GrPri mitiveType;
234 target->initDraw(gp); 235 target->initDraw(gp);
235 236
236 GrMesh mesh; 237 GrMesh mesh;
237 mesh.init(primitiveType, vb, firstVertex, count); 238 mesh.init(primitiveType, vb, firstVertex, count);
238 target->draw(mesh); 239 target->draw(mesh);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 bool result = viewMatrix.invert(&vmi); 322 bool result = viewMatrix.invert(&vmi);
322 if (!result) { 323 if (!result) {
323 SkFAIL("Cannot invert matrix\n"); 324 SkFAIL("Cannot invert matrix\n");
324 } 325 }
325 vmi.mapRect(&clipBounds); 326 vmi.mapRect(&clipBounds);
326 GrStrokeInfo strokeInfo = GrTest::TestStrokeInfo(random); 327 GrStrokeInfo strokeInfo = GrTest::TestStrokeInfo(random);
327 return TessellatingPathBatch::Create(color, path, strokeInfo, viewMatrix, cl ipBounds); 328 return TessellatingPathBatch::Create(color, path, strokeInfo, viewMatrix, cl ipBounds);
328 } 329 }
329 330
330 #endif 331 #endif
OLDNEW
« no previous file with comments | « src/gpu/batches/GrTInstanceBatch.h ('k') | src/gpu/batches/GrTestBatch.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698