| OLD | NEW |
| (Empty) |
| 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 "GrBatchTarget.h" | |
| 9 | |
| 10 #include "GrBatchAtlas.h" | |
| 11 #include "GrPipeline.h" | |
| 12 | |
| 13 GrBatchTarget::GrBatchTarget(GrGpu* gpu) | |
| 14 : fGpu(gpu) | |
| 15 , fVertexPool(gpu) | |
| 16 , fIndexPool(gpu) | |
| 17 , fFlushBuffer(kFlushBufferInitialSizeInBytes) | |
| 18 , fIter(fFlushBuffer) | |
| 19 , fNumberOfDraws(0) | |
| 20 , fCurrentToken(0) | |
| 21 , fLastFlushedToken(0) | |
| 22 , fInlineUpdatesIndex(0) { | |
| 23 } | |
| 24 | |
| 25 void GrBatchTarget::flushNext(int n) { | |
| 26 for (; n > 0; n--) { | |
| 27 fLastFlushedToken++; | |
| 28 SkDEBUGCODE(bool verify =) fIter.next(); | |
| 29 SkASSERT(verify); | |
| 30 | |
| 31 BufferedFlush* bf = fIter.get(); | |
| 32 | |
| 33 // Flush all texture uploads | |
| 34 int uploadCount = fInlineUploads.count(); | |
| 35 while (fInlineUpdatesIndex < uploadCount && | |
| 36 fInlineUploads[fInlineUpdatesIndex]->lastUploadToken() <= fLastFl
ushedToken) { | |
| 37 fInlineUploads[fInlineUpdatesIndex++]->upload(TextureUploader(fGpu))
; | |
| 38 } | |
| 39 | |
| 40 GrProgramDesc desc; | |
| 41 const GrPipeline* pipeline = bf->fPipeline; | |
| 42 const GrPrimitiveProcessor* primProc = bf->fPrimitiveProcessor.get(); | |
| 43 fGpu->buildProgramDesc(&desc, *primProc, *pipeline, bf->fBatchTracker); | |
| 44 | |
| 45 GrGpu::DrawArgs args(primProc, pipeline, &desc, &bf->fBatchTracker); | |
| 46 | |
| 47 int drawCount = bf->fVertexDraws.count(); | |
| 48 const SkSTArray<1, GrVertices, true>& vertexDraws = bf->fVertexDraws; | |
| 49 for (int i = 0; i < drawCount; i++) { | |
| 50 fGpu->draw(args, vertexDraws[i]); | |
| 51 } | |
| 52 } | |
| 53 } | |
| 54 | |
| 55 void* GrBatchTarget::makeVertSpace(size_t vertexSize, int vertexCount, | |
| 56 const GrVertexBuffer** buffer, int* startVertex) { | |
| 57 return fVertexPool.makeSpace(vertexSize, vertexCount, buffer, startVertex); | |
| 58 } | |
| 59 | |
| 60 uint16_t* GrBatchTarget::makeIndexSpace(int indexCount, | |
| 61 const GrIndexBuffer** buffer, int* start
Index) { | |
| 62 return reinterpret_cast<uint16_t*>(fIndexPool.makeSpace(indexCount, buffer,
startIndex)); | |
| 63 } | |
| 64 | |
| OLD | NEW |