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

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

Issue 975303005: Creation of GrBatchAtlas and Distancefieldpathrenderer batch (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: nit Created 5 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/GrBatchAtlas.cpp ('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 "GrBatchAtlas.h"
11 #include "GrBufferAllocPool.h" 12 #include "GrBufferAllocPool.h"
12 #include "GrPendingProgramElement.h" 13 #include "GrPendingProgramElement.h"
13 #include "GrPipeline.h" 14 #include "GrPipeline.h"
14 #include "GrGpu.h" 15 #include "GrGpu.h"
15 #include "GrTRecorder.h" 16 #include "GrTRecorder.h"
16 17
17 /* 18 /*
18 * GrBatch instances use this object to allocate space for their geometry and to issue the draws 19 * GrBatch instances use this object to allocate space for their geometry and to issue the draws
19 * that render their batch. 20 * that render their batch.
20 */ 21 */
21 22
22 class GrIndexBufferAllocPool; 23 class GrIndexBufferAllocPool;
23 class GrVertexBufferAllocPool; 24 class GrVertexBufferAllocPool;
24 25
25 class GrBatchTarget : public SkNoncopyable { 26 class GrBatchTarget : public SkNoncopyable {
26 public: 27 public:
28 typedef GrBatchAtlas::BatchToken BatchToken;
27 GrBatchTarget(GrGpu* gpu, 29 GrBatchTarget(GrGpu* gpu,
28 GrVertexBufferAllocPool* vpool, 30 GrVertexBufferAllocPool* vpool,
29 GrIndexBufferAllocPool* ipool) 31 GrIndexBufferAllocPool* ipool);
30 : fGpu(gpu)
31 , fVertexPool(vpool)
32 , fIndexPool(ipool)
33 , fFlushBuffer(kFlushBufferInitialSizeInBytes)
34 , fIter(fFlushBuffer)
35 , fNumberOfDraws(0) {}
36 32
37 typedef GrDrawTarget::DrawInfo DrawInfo; 33 typedef GrDrawTarget::DrawInfo DrawInfo;
38 void initDraw(const GrPrimitiveProcessor* primProc, const GrPipeline* pipeli ne) { 34 void initDraw(const GrPrimitiveProcessor* primProc, const GrPipeline* pipeli ne) {
39 GrNEW_APPEND_TO_RECORDER(fFlushBuffer, BufferedFlush, (primProc, pipelin e)); 35 GrNEW_APPEND_TO_RECORDER(fFlushBuffer, BufferedFlush, (primProc, pipelin e));
40 fNumberOfDraws++; 36 fNumberOfDraws++;
37 fCurrentToken++;
38 }
39
40 class TextureUploader {
41 public:
42 TextureUploader(GrGpu* gpu) : fGpu(gpu) { SkASSERT(gpu); }
43
44 /**
45 * Updates the pixels in a rectangle of a texture.
46 *
47 * @param left left edge of the rectangle to write (inclusive)
48 * @param top top edge of the rectangle to write (inclusive)
49 * @param width width of rectangle to write in pixels.
50 * @param height height of rectangle to write in pixels.
51 * @param config the pixel config of the source buffer
52 * @param buffer memory to read pixels from
53 * @param rowBytes number of bytes between consecutive rows. Zero
54 * means rows are tightly packed.
55 */
56 bool writeTexturePixels(GrTexture* texture,
57 int left, int top, int width, int height,
58 GrPixelConfig config, const void* buffer,
59 size_t rowBytes) {
60 return fGpu->writeTexturePixels(texture, left, top, width, height, c onfig, buffer,
61 rowBytes);
62 }
63
64 private:
65 GrGpu* fGpu;
66 };
67
68 class Uploader : public SkRefCnt {
69 public:
70 Uploader(BatchToken lastUploadToken) : fLastUploadToken(lastUploadToken) {}
71 BatchToken lastUploadToken() const { return fLastUploadToken; }
72 virtual void upload(TextureUploader)=0;
73
74 private:
75 BatchToken fLastUploadToken;
76 };
77
78 void upload(Uploader* upload) {
79 if (this->asapToken() == upload->lastUploadToken()) {
80 fAsapUploads.push_back().reset(SkRef(upload));
81 } else {
82 fInlineUploads.push_back().reset(SkRef(upload));
83 }
41 } 84 }
42 85
43 void draw(const GrDrawTarget::DrawInfo& draw) { 86 void draw(const GrDrawTarget::DrawInfo& draw) {
44 fFlushBuffer.back().fDraws.push_back(draw); 87 fFlushBuffer.back().fDraws.push_back(draw);
45 } 88 }
46 89
47 // TODO this is temporary until batch is everywhere 90 bool isIssued(BatchToken token) const { return fLastFlushedToken >= token; }
48 //void flush(); 91 BatchToken currentToken() const { return fCurrentToken; }
92 BatchToken asapToken() const { return fLastFlushedToken + 1; }
93
94 // TODO much of this complexity goes away when batch is everywhere
49 void resetNumberOfDraws() { fNumberOfDraws = 0; } 95 void resetNumberOfDraws() { fNumberOfDraws = 0; }
50 int numberOfDraws() const { return fNumberOfDraws; } 96 int numberOfDraws() const { return fNumberOfDraws; }
51 void preFlush() { fIter = FlushBuffer::Iter(fFlushBuffer); } 97 void preFlush() {
52 void flushNext(int n) { 98 int updateCount = fAsapUploads.count();
53 for (; n > 0; n--) { 99 for (int i = 0; i < updateCount; i++) {
54 SkDEBUGCODE(bool verify =) fIter.next(); 100 fAsapUploads[i]->upload(TextureUploader(fGpu));
55 SkASSERT(verify);
56 GrProgramDesc desc;
57 BufferedFlush* bf = fIter.get();
58 const GrPipeline* pipeline = bf->fPipeline;
59 const GrPrimitiveProcessor* primProc = bf->fPrimitiveProcessor.get() ;
60 fGpu->buildProgramDesc(&desc, *primProc, *pipeline, bf->fBatchTracke r);
61
62 GrGpu::DrawArgs args(primProc, pipeline, &desc, &bf->fBatchTracker);
63
64 int drawCount = bf->fDraws.count();
65 const SkSTArray<1, DrawInfo, true>& draws = bf->fDraws;
66 for (int i = 0; i < drawCount; i++) {
67 fGpu->draw(args, draws[i]);
68 }
69 } 101 }
102 fInlineUpdatesIndex = 0;
103 fIter = FlushBuffer::Iter(fFlushBuffer);
70 } 104 }
71 void postFlush() { SkASSERT(!fIter.next()); fFlushBuffer.reset(); } 105 void flushNext(int n);
106 void postFlush() {
107 SkASSERT(!fIter.next());
108 fFlushBuffer.reset();
109 fAsapUploads.reset();
110 fInlineUploads.reset();
111 }
72 112
73 // TODO This goes away when everything uses batch 113 // TODO This goes away when everything uses batch
74 GrBatchTracker* currentBatchTracker() { 114 GrBatchTracker* currentBatchTracker() {
75 SkASSERT(!fFlushBuffer.empty()); 115 SkASSERT(!fFlushBuffer.empty());
76 return &fFlushBuffer.back().fBatchTracker; 116 return &fFlushBuffer.back().fBatchTracker;
77 } 117 }
78 118
79 const GrDrawTargetCaps& caps() const { return *fGpu->caps(); } 119 const GrDrawTargetCaps& caps() const { return *fGpu->caps(); }
80 120
81 GrVertexBufferAllocPool* vertexPool() { return fVertexPool; } 121 GrVertexBufferAllocPool* vertexPool() { return fVertexPool; }
82 GrIndexBufferAllocPool* indexPool() { return fIndexPool; } 122 GrIndexBufferAllocPool* indexPool() { return fIndexPool; }
83 123
124 const static int kVertsPerRect = 4;
125 const static int kIndicesPerRect = 6;
84 const GrIndexBuffer* quadIndexBuffer() const { return fGpu->getQuadIndexBuff er(); } 126 const GrIndexBuffer* quadIndexBuffer() const { return fGpu->getQuadIndexBuff er(); }
85 127
86 // A helper for draws which overallocate and then return data to the pool 128 // A helper for draws which overallocate and then return data to the pool
87 void putBackIndices(size_t indices) { fIndexPool->putBack(indices * sizeof(u int16_t)); } 129 void putBackIndices(size_t indices) { fIndexPool->putBack(indices * sizeof(u int16_t)); }
88 130
89 void putBackVertices(size_t vertices, size_t vertexStride) { 131 void putBackVertices(size_t vertices, size_t vertexStride) {
90 fVertexPool->putBack(vertices * vertexStride); 132 fVertexPool->putBack(vertices * vertexStride);
91 } 133 }
92 134
93 private: 135 private:
(...skipping 17 matching lines...) Expand all
111 enum { 153 enum {
112 kFlushBufferInitialSizeInBytes = 8 * sizeof(BufferedFlush), 154 kFlushBufferInitialSizeInBytes = 8 * sizeof(BufferedFlush),
113 }; 155 };
114 156
115 typedef GrTRecorder<BufferedFlush, TBufferAlign> FlushBuffer; 157 typedef GrTRecorder<BufferedFlush, TBufferAlign> FlushBuffer;
116 158
117 FlushBuffer fFlushBuffer; 159 FlushBuffer fFlushBuffer;
118 // TODO this is temporary 160 // TODO this is temporary
119 FlushBuffer::Iter fIter; 161 FlushBuffer::Iter fIter;
120 int fNumberOfDraws; 162 int fNumberOfDraws;
163 BatchToken fCurrentToken;
164 BatchToken fLastFlushedToken; // The next token to be flushed
165 SkTArray<SkAutoTUnref<Uploader>, true> fAsapUploads;
166 SkTArray<SkAutoTUnref<Uploader>, true> fInlineUploads;
167 int fInlineUpdatesIndex;
121 }; 168 };
122 169
123 #endif 170 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrBatchAtlas.cpp ('k') | src/gpu/GrBatchTarget.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698