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

Side by Side Diff: src/gpu/GrBatchTarget.h

Issue 876673002: Hairline batch (Closed) Base URL: https://skia.googlesource.com/skia.git@2_defer
Patch Set: cleanup Created 5 years, 10 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/GrBatch.h ('k') | src/gpu/GrBatchTarget.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 #ifndef GrBatchBuffer_DEFINED 8 #ifndef GrBatchBuffer_DEFINED
9 #define GrBatchBuffer_DEFINED 9 #define GrBatchBuffer_DEFINED
10 10
11 #include "GrPendingProgramElement.h" 11 #include "GrPendingProgramElement.h"
12 #include "GrPipeline.h"
12 #include "GrGpu.h" 13 #include "GrGpu.h"
13 #include "GrTRecorder.h" 14 #include "GrTRecorder.h"
14 15
15 /* 16 /*
16 * GrBatch instances use this object to allocate space for their geometry and to issue the draws 17 * GrBatch instances use this object to allocate space for their geometry and to issue the draws
17 * that render their batch. 18 * that render their batch.
18 */ 19 */
19 20
21 class GrIndexBufferAllocPool;
22 class GrVertexBufferAllocPool;
23
20 class GrBatchTarget : public SkNoncopyable { 24 class GrBatchTarget : public SkNoncopyable {
21 public: 25 public:
22 GrBatchTarget(GrGpu* gpu, 26 GrBatchTarget(GrGpu* gpu,
23 GrVertexBufferAllocPool* vpool, 27 GrVertexBufferAllocPool* vpool,
24 GrIndexBufferAllocPool* ipool) 28 GrIndexBufferAllocPool* ipool)
25 : fGpu(gpu) 29 : fGpu(gpu)
26 , fVertexPool(vpool) 30 , fVertexPool(vpool)
27 , fIndexPool(ipool) 31 , fIndexPool(ipool)
28 , fFlushBuffer(kFlushBufferInitialSizeInBytes) 32 , fFlushBuffer(kFlushBufferInitialSizeInBytes)
29 , fIter(fFlushBuffer) {} 33 , fIter(fFlushBuffer)
34 , fNumberOfDraws(0) {}
30 35
31 typedef GrDrawTarget::DrawInfo DrawInfo; 36 typedef GrDrawTarget::DrawInfo DrawInfo;
32 void initDraw(const GrPrimitiveProcessor* primProc, const GrPipeline* pipeli ne) { 37 void initDraw(const GrPrimitiveProcessor* primProc, const GrPipeline* pipeli ne) {
33 GrNEW_APPEND_TO_RECORDER(fFlushBuffer, BufferedFlush, (primProc, pipelin e)); 38 GrNEW_APPEND_TO_RECORDER(fFlushBuffer, BufferedFlush, (primProc, pipelin e));
39 fNumberOfDraws++;
34 } 40 }
35 41
36 void draw(const GrDrawTarget::DrawInfo& draw) { 42 void draw(const GrDrawTarget::DrawInfo& draw) {
37 fFlushBuffer.back().fDraws.push_back(draw); 43 fFlushBuffer.back().fDraws.push_back(draw);
38 } 44 }
39 45
40 // TODO this is temporary until batch is everywhere 46 // TODO this is temporary until batch is everywhere
41 //void flush(); 47 //void flush();
48 void resetNumberOfDraws() { fNumberOfDraws = 0; }
49 int numberOfDraws() const { return fNumberOfDraws; }
42 void preFlush() { fIter = FlushBuffer::Iter(fFlushBuffer); } 50 void preFlush() { fIter = FlushBuffer::Iter(fFlushBuffer); }
43 void flushNext(); 51 void flushNext(int n) {
52 for (; n > 0; n--) {
53 SkDEBUGCODE(bool verify =) fIter.next();
54 SkASSERT(verify);
55 GrProgramDesc desc;
56 BufferedFlush* bf = fIter.get();
57 const GrPipeline* pipeline = bf->fPipeline;
58 const GrPrimitiveProcessor* primProc = bf->fPrimitiveProcessor.get() ;
59 fGpu->buildProgramDesc(&desc, *primProc, *pipeline, bf->fBatchTracke r);
60
61 GrGpu::DrawArgs args(primProc, pipeline, &desc, &bf->fBatchTracker);
62
63 int drawCount = bf->fDraws.count();
64 const SkSTArray<1, DrawInfo, true>& draws = bf->fDraws;
65 for (int i = 0; i < drawCount; i++) {
66 fGpu->draw(args, draws[i]);
67 }
68 }
69 }
44 void postFlush() { SkASSERT(!fIter.next()); fFlushBuffer.reset(); } 70 void postFlush() { SkASSERT(!fIter.next()); fFlushBuffer.reset(); }
45 71
46 // TODO This goes away when everything uses batch 72 // TODO This goes away when everything uses batch
47 GrBatchTracker* currentBatchTracker() { 73 GrBatchTracker* currentBatchTracker() {
48 SkASSERT(!fFlushBuffer.empty()); 74 SkASSERT(!fFlushBuffer.empty());
49 return &fFlushBuffer.back().fBatchTracker; 75 return &fFlushBuffer.back().fBatchTracker;
50 } 76 }
51 77
78 const GrDrawTargetCaps& caps() const { return *fGpu->caps(); }
79
52 GrVertexBufferAllocPool* vertexPool() { return fVertexPool; } 80 GrVertexBufferAllocPool* vertexPool() { return fVertexPool; }
53 GrIndexBufferAllocPool* indexPool() { return fIndexPool; } 81 GrIndexBufferAllocPool* indexPool() { return fIndexPool; }
54 82
55 private: 83 private:
56 GrGpu* fGpu; 84 GrGpu* fGpu;
57 GrVertexBufferAllocPool* fVertexPool; 85 GrVertexBufferAllocPool* fVertexPool;
58 GrIndexBufferAllocPool* fIndexPool; 86 GrIndexBufferAllocPool* fIndexPool;
59 87
60 typedef void* TBufferAlign; // This wouldn't be enough align if a command us ed long double. 88 typedef void* TBufferAlign; // This wouldn't be enough align if a command us ed long double.
61 89
62 struct BufferedFlush { 90 struct BufferedFlush {
63 BufferedFlush(const GrPrimitiveProcessor* primProc, const GrPipeline* pi peline) 91 BufferedFlush(const GrPrimitiveProcessor* primProc, const GrPipeline* pi peline)
64 : fPrimitiveProcessor(primProc) 92 : fPrimitiveProcessor(primProc)
65 , fPipeline(pipeline) 93 , fPipeline(pipeline) {}
66 , fDraws(kDrawRecorderInitialSizeInBytes) {}
67 typedef GrPendingProgramElement<const GrPrimitiveProcessor> ProgramPrimi tiveProcessor; 94 typedef GrPendingProgramElement<const GrPrimitiveProcessor> ProgramPrimi tiveProcessor;
68 ProgramPrimitiveProcessor fPrimitiveProcessor; 95 ProgramPrimitiveProcessor fPrimitiveProcessor;
69 const GrPipeline* fPipeline; 96 const GrPipeline* fPipeline;
70 GrBatchTracker fBatchTracker; 97 GrBatchTracker fBatchTracker;
71 SkSTArray<4, DrawInfo, true> fDraws; 98 SkSTArray<1, DrawInfo, true> fDraws;
72 }; 99 };
73 100
74 enum { 101 enum {
75 kFlushBufferInitialSizeInBytes = 8 * sizeof(BufferedFlush), 102 kFlushBufferInitialSizeInBytes = 8 * sizeof(BufferedFlush),
76 kDrawRecorderInitialSizeInBytes = 8 * sizeof(DrawInfo),
77 }; 103 };
78 104
79 typedef GrTRecorder<BufferedFlush, TBufferAlign> FlushBuffer; 105 typedef GrTRecorder<BufferedFlush, TBufferAlign> FlushBuffer;
80 106
81 FlushBuffer fFlushBuffer; 107 FlushBuffer fFlushBuffer;
82 // TODO this is temporary 108 // TODO this is temporary
83 FlushBuffer::Iter fIter; 109 FlushBuffer::Iter fIter;
110 int fNumberOfDraws;
84 }; 111 };
85 112
86 #endif 113 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrBatch.h ('k') | src/gpu/GrBatchTarget.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698