Home | History | Annotate | Download | only in gpu
      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 static const size_t DRAW_BUFFER_VBPOOL_BUFFER_SIZE = 1 << 15;
     14 static const int DRAW_BUFFER_VBPOOL_PREALLOC_BUFFERS = 4;
     15 
     16 static const size_t DRAW_BUFFER_IBPOOL_BUFFER_SIZE = 1 << 11;
     17 static const int DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS = 4;
     18 
     19 GrBatchTarget::GrBatchTarget(GrGpu* gpu)
     20     : fGpu(gpu)
     21     , fFlushBuffer(kFlushBufferInitialSizeInBytes)
     22     , fIter(fFlushBuffer)
     23     , fNumberOfDraws(0)
     24     , fCurrentToken(0)
     25     , fLastFlushedToken(0)
     26     , fInlineUpdatesIndex(0) {
     27 
     28     fVertexPool.reset(SkNEW_ARGS(GrVertexBufferAllocPool, (fGpu,
     29                                              DRAW_BUFFER_VBPOOL_BUFFER_SIZE,
     30                                              DRAW_BUFFER_VBPOOL_PREALLOC_BUFFERS)));
     31     fIndexPool.reset(SkNEW_ARGS(GrIndexBufferAllocPool, (fGpu,
     32                                             DRAW_BUFFER_IBPOOL_BUFFER_SIZE,
     33                                             DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS)));
     34 }
     35 
     36 void GrBatchTarget::flushNext(int n)  {
     37     for (; n > 0; n--) {
     38         fLastFlushedToken++;
     39         SkDEBUGCODE(bool verify =) fIter.next();
     40         SkASSERT(verify);
     41 
     42         BufferedFlush* bf = fIter.get();
     43 
     44         // Flush all texture uploads
     45         int uploadCount = fInlineUploads.count();
     46         while (fInlineUpdatesIndex < uploadCount &&
     47                fInlineUploads[fInlineUpdatesIndex]->lastUploadToken() <= fLastFlushedToken) {
     48             fInlineUploads[fInlineUpdatesIndex++]->upload(TextureUploader(fGpu));
     49         }
     50 
     51         GrProgramDesc desc;
     52         const GrPipeline* pipeline = bf->fPipeline;
     53         const GrPrimitiveProcessor* primProc = bf->fPrimitiveProcessor.get();
     54         fGpu->buildProgramDesc(&desc, *primProc, *pipeline, bf->fBatchTracker);
     55 
     56         GrGpu::DrawArgs args(primProc, pipeline, &desc, &bf->fBatchTracker);
     57 
     58         int drawCount = bf->fVertexDraws.count();
     59         const SkSTArray<1, GrVertices, true>& vertexDraws = bf->fVertexDraws;
     60         for (int i = 0; i < drawCount; i++) {
     61             fGpu->draw(args, vertexDraws[i]);
     62         }
     63     }
     64 }
     65 
     66 void* GrBatchTarget::makeVertSpace(size_t vertexSize, int vertexCount,
     67                     const GrVertexBuffer** buffer, int* startVertex) {
     68     return fVertexPool->makeSpace(vertexSize, vertexCount, buffer, startVertex);
     69 }
     70 
     71 uint16_t* GrBatchTarget::makeIndexSpace(int indexCount,
     72                                         const GrIndexBuffer** buffer, int* startIndex) {
     73     return reinterpret_cast<uint16_t*>(fIndexPool->makeSpace(indexCount, buffer, startIndex));
     74 }
     75 
     76