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

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

Issue 1225923010: Refugee from Dead Machine 4: MDB Monster Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Last update from dead machine Created 4 years, 7 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/GrBatchFlushState.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
(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 #ifndef GrBatchBuffer_DEFINED
9 #define GrBatchBuffer_DEFINED
10
11 #include "GrBatchAtlas.h"
12 #if 0
13 #include "GrBufferAllocPool.h"
14 #include "GrContext.h"
15 #include "GrPendingProgramElement.h"
16 #include "GrPipeline.h"
17 #include "GrTRecorder.h"
18 #include "GrVertices.h"
19
20 /*
21 * GrBatch instances use this object to allocate space for their geometry and to issue the draws
22 * that render their batch.
23 */
24 class GrBatchTarget : public SkNoncopyable {
25 public:
26 typedef GrBatchAtlas::BatchToken BatchToken;
27 GrBatchTarget(GrFoo* foo, GrGpu* gpu, GrRenderTarget* dst);
28
29 void initDraw(const GrPrimitiveProcessor* primProc, const GrPipeline* pipeli ne) {
30 GrNEW_APPEND_TO_RECORDER(fFlushBuffer, BufferedFlush, (primProc, pipelin e));
31 fNumberOfDraws++;
32 fFoo1->inc();
33 //fCurrentToken1++;
34 //SkASSERT(fFoo->currentToken(fCurrentToken1));
35 }
36
37 class TextureUploader {
38 public:
39 TextureUploader(GrGpu* gpu) : fGpu(gpu) { SkASSERT(gpu); }
40
41 /**
42 * Updates the pixels in a rectangle of a texture.
43 *
44 * @param left left edge of the rectangle to write (inclusive)
45 * @param top top edge of the rectangle to write (inclusive)
46 * @param width width of rectangle to write in pixels.
47 * @param height height of rectangle to write in pixels.
48 * @param config the pixel config of the source buffer
49 * @param buffer memory to read pixels from
50 * @param rowBytes number of bytes between consecutive rows. Zero
51 * means rows are tightly packed.
52 */
53 bool writeTexturePixels(GrTexture* texture,
54 int left, int top, int width, int height,
55 GrPixelConfig config, const void* buffer,
56 size_t rowBytes) {
57 return fGpu->writePixels(texture, left, top, width, height, config, buffer, rowBytes);
58 }
59
60 private:
61 GrGpu* fGpu;
62 };
63
64 class Uploader : public SkRefCnt {
65 public:
66 Uploader(BatchToken lastUploadToken) : fLastUploadToken(lastUploadToken) {}
67 BatchToken lastUploadToken() const { return fLastUploadToken; }
68 virtual void upload(TextureUploader)=0;
69
70 private:
71 BatchToken fLastUploadToken;
72 };
73
74 void upload(Uploader* upload) {
75 if (this->asapToken() == upload->lastUploadToken()) {
76 fAsapUploads.push_back().reset(SkRef(upload));
77 } else {
78 fInlineUploads.push_back().reset(SkRef(upload));
79 }
80 }
81
82 void draw(const GrVertices& vertices) {
83 fFlushBuffer.back().fVertexDraws.push_back(vertices);
84 }
85
86 bool isIssued(BatchToken token) const { return fLastFlushedToken >= token; }
87 BatchToken currentToken1() const {
88 //SkASSERT(fCurrentToken1 == fFoo->currentToken(fCurrentToken1));
89 return fFoo1->currentToken();
90 }
91 BatchToken asapToken() const { return fLastFlushedToken + 1; }
92
93 // TODO much of this complexity goes away when batch is everywhere
94 void resetNumberOfDraws() { fNumberOfDraws = 0; }
95 int numberOfDraws() const { return fNumberOfDraws; }
96 void preFlush() {
97 this->unmapVertexAndIndexBuffers();
98 int updateCount = fAsapUploads.count();
99 for (int i = 0; i < updateCount; i++) {
100 fAsapUploads[i]->upload(TextureUploader(fGpu1));
101 }
102 fInlineUpdatesIndex = 0;
103 fIter = FlushBuffer::Iter(fFlushBuffer);
104 }
105 void flushNext(int n);
106 void postFlush() {
107 SkASSERT(!fIter.next());
108 fFlushBuffer.reset();
109 fAsapUploads.reset();
110 fInlineUploads.reset();
111 }
112
113 const GrCaps& caps() const { return *fGpu1->caps(); }
114
115 GrResourceProvider* resourceProvider() const { return fGpu1->getContext()->r esourceProvider(); }
116
117 void* makeVertSpace(size_t vertexSize, int vertexCount,
118 const GrVertexBuffer** buffer, int* startVertex);
119 uint16_t* makeIndexSpace(int indexCount,
120 const GrIndexBuffer** buffer, int* startIndex);
121
122 // A helper for draws which overallocate and then return data to the pool
123 void putBackIndices(size_t indices) { fIndexPool.putBack(indices * sizeof(ui nt16_t)); }
124
125 void putBackVertices(size_t vertices, size_t vertexStride) {
126 fVertexPool.putBack(vertices * vertexStride);
127 }
128
129 void reset() {
130 fVertexPool.reset();
131 fIndexPool.reset();
132 }
133
134 private:
135 void unmapVertexAndIndexBuffers() {
136 fVertexPool.unmap();
137 fIndexPool.unmap();
138 }
139
140 GrGpu* fGpu1;
141 GrVertexBufferAllocPool fVertexPool;
142 GrIndexBufferAllocPool fIndexPool;
143
144 typedef void* TBufferAlign; // This wouldn't be enough align if a command us ed long double.
145
146 struct BufferedFlush {
147 BufferedFlush(const GrPrimitiveProcessor* primProc, const GrPipeline* pi peline)
148 : fPrimitiveProcessor(primProc)
149 , fPipeline(pipeline) {}
150 typedef GrPendingProgramElement<const GrPrimitiveProcessor> ProgramPrimi tiveProcessor;
151 ProgramPrimitiveProcessor fPrimitiveProcessor;
152 const GrPipeline* fPipeline;
153 GrBatchTracker fBatchTracker;
154 SkSTArray<1, GrVertices, true> fVertexDraws;
155 };
156
157 enum {
158 kFlushBufferInitialSizeInBytes = 8 * sizeof(BufferedFlush),
159 };
160
161 typedef GrTRecorder<BufferedFlush, TBufferAlign> FlushBuffer;
162
163 FlushBuffer fFlushBuffer;
164 // TODO this is temporary
165 FlushBuffer::Iter fIter;
166 int fNumberOfDraws;
167 public:
168 //BatchToken fCurrentToken1;
169 GrFoo* fFoo1;
170 GrRenderTarget* fRT;
171 BatchToken fLastFlushedToken; // The next token to be flushed
172 SkTArray<SkAutoTUnref<Uploader>, true> fAsapUploads;
173 SkTArray<SkAutoTUnref<Uploader>, true> fInlineUploads;
174 int fInlineUpdatesIndex;
175 };
176
177 #endif
178 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrBatchFlushState.h ('k') | src/gpu/GrBatchTarget.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698