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

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

Issue 1831133004: Revert of Consolidate GPU buffer implementations (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 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/GrVertexBatch.h ('k') | src/gpu/effects/GrDashingEffect.cpp » ('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 "GrVertexBatch.h" 8 #include "GrVertexBatch.h"
9 #include "GrBatchFlushState.h" 9 #include "GrBatchFlushState.h"
10 #include "GrResourceProvider.h" 10 #include "GrResourceProvider.h"
11 11
12 GrVertexBatch::GrVertexBatch(uint32_t classID) : INHERITED(classID) {} 12 GrVertexBatch::GrVertexBatch(uint32_t classID) : INHERITED(classID) {}
13 13
14 void GrVertexBatch::onPrepare(GrBatchFlushState* state) { 14 void GrVertexBatch::onPrepare(GrBatchFlushState* state) {
15 Target target(state, this); 15 Target target(state, this);
16 this->onPrepareDraws(&target); 16 this->onPrepareDraws(&target);
17 } 17 }
18 18
19 void* GrVertexBatch::InstancedHelper::init(Target* target, GrPrimitiveType primT ype, 19 void* GrVertexBatch::InstancedHelper::init(Target* target, GrPrimitiveType primT ype,
20 size_t vertexStride, const GrBuffer* indexBuffer, 20 size_t vertexStride, const GrIndexBuf fer* indexBuffer,
21 int verticesPerInstance, int indicesP erInstance, 21 int verticesPerInstance, int indicesP erInstance,
22 int instancesToDraw) { 22 int instancesToDraw) {
23 SkASSERT(target); 23 SkASSERT(target);
24 if (!indexBuffer) { 24 if (!indexBuffer) {
25 return nullptr; 25 return nullptr;
26 } 26 }
27 const GrBuffer* vertexBuffer; 27 const GrVertexBuffer* vertexBuffer;
28 int firstVertex; 28 int firstVertex;
29 int vertexCount = verticesPerInstance * instancesToDraw; 29 int vertexCount = verticesPerInstance * instancesToDraw;
30 void* vertices = target->makeVertexSpace(vertexStride, vertexCount, &vertexB uffer, &firstVertex); 30 void* vertices = target->makeVertexSpace(vertexStride, vertexCount, &vertexB uffer, &firstVertex);
31 if (!vertices) { 31 if (!vertices) {
32 SkDebugf("Vertices could not be allocated for instanced rendering."); 32 SkDebugf("Vertices could not be allocated for instanced rendering.");
33 return nullptr; 33 return nullptr;
34 } 34 }
35 SkASSERT(vertexBuffer); 35 SkASSERT(vertexBuffer);
36 size_t ibSize = indexBuffer->gpuMemorySize(); 36 size_t ibSize = indexBuffer->gpuMemorySize();
37 int maxInstancesPerDraw = static_cast<int>(ibSize / (sizeof(uint16_t) * indi cesPerInstance)); 37 int maxInstancesPerDraw = static_cast<int>(ibSize / (sizeof(uint16_t) * indi cesPerInstance));
38 38
39 fMesh.initInstanced(primType, vertexBuffer, indexBuffer, 39 fMesh.initInstanced(primType, vertexBuffer, indexBuffer,
40 firstVertex, verticesPerInstance, indicesPerInstance, instancesToDraw, 40 firstVertex, verticesPerInstance, indicesPerInstance, instancesToDraw,
41 maxInstancesPerDraw); 41 maxInstancesPerDraw);
42 return vertices; 42 return vertices;
43 } 43 }
44 44
45 void GrVertexBatch::InstancedHelper::recordDraw(Target* target) { 45 void GrVertexBatch::InstancedHelper::recordDraw(Target* target) {
46 SkASSERT(fMesh.instanceCount()); 46 SkASSERT(fMesh.instanceCount());
47 target->draw(fMesh); 47 target->draw(fMesh);
48 } 48 }
49 49
50 void* GrVertexBatch::QuadHelper::init(Target* target, size_t vertexStride, 50 void* GrVertexBatch::QuadHelper::init(Target* target, size_t vertexStride,
51 int quadsToDraw) { 51 int quadsToDraw) {
52 SkAutoTUnref<const GrBuffer> quadIndexBuffer( 52 SkAutoTUnref<const GrIndexBuffer> quadIndexBuffer(
53 target->resourceProvider()->refQuadIndexBuffer()); 53 target->resourceProvider()->refQuadIndexBuffer());
54 if (!quadIndexBuffer) { 54 if (!quadIndexBuffer) {
55 SkDebugf("Could not get quad index buffer."); 55 SkDebugf("Could not get quad index buffer.");
56 return nullptr; 56 return nullptr;
57 } 57 }
58 return this->INHERITED::init(target, kTriangles_GrPrimitiveType, vertexStrid e, 58 return this->INHERITED::init(target, kTriangles_GrPrimitiveType, vertexStrid e,
59 quadIndexBuffer, kVerticesPerQuad, kIndicesPerQ uad, quadsToDraw); 59 quadIndexBuffer, kVerticesPerQuad, kIndicesPerQ uad, quadsToDraw);
60 } 60 }
61 61
62 void GrVertexBatch::onDraw(GrBatchFlushState* state) { 62 void GrVertexBatch::onDraw(GrBatchFlushState* state) {
63 int uploadCnt = fInlineUploads.count(); 63 int uploadCnt = fInlineUploads.count();
64 int currUpload = 0; 64 int currUpload = 0;
65 65
66 // Iterate of all the drawArrays. Before issuing the draws in each array, pe rform any inline 66 // Iterate of all the drawArrays. Before issuing the draws in each array, pe rform any inline
67 // uploads. 67 // uploads.
68 for (DrawArrayList::Iter da(fDrawArrays); da.get(); da.next()) { 68 for (DrawArrayList::Iter da(fDrawArrays); da.get(); da.next()) {
69 state->advanceLastFlushedToken(); 69 state->advanceLastFlushedToken();
70 while (currUpload < uploadCnt && 70 while (currUpload < uploadCnt &&
71 fInlineUploads[currUpload]->lastUploadToken() <= state->lastFlush edToken()) { 71 fInlineUploads[currUpload]->lastUploadToken() <= state->lastFlush edToken()) {
72 fInlineUploads[currUpload++]->upload(state->uploader()); 72 fInlineUploads[currUpload++]->upload(state->uploader());
73 } 73 }
74 const GrVertexBatch::DrawArray& drawArray = *da.get(); 74 const GrVertexBatch::DrawArray& drawArray = *da.get();
75 75
76 state->gpu()->draw(*this->pipeline(), 76 state->gpu()->draw(*this->pipeline(),
77 *drawArray.fPrimitiveProcessor.get(), 77 *drawArray.fPrimitiveProcessor.get(),
78 drawArray.fDraws.begin(), 78 drawArray.fDraws.begin(),
79 drawArray.fDraws.count()); 79 drawArray.fDraws.count());
80 } 80 }
81 } 81 }
OLDNEW
« no previous file with comments | « src/gpu/batches/GrVertexBatch.h ('k') | src/gpu/effects/GrDashingEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698