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

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

Issue 845103005: GrBatchPrototype (Closed) Base URL: https://skia.googlesource.com/skia.git@lc2
Patch Set: removing dstread 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/GrGeometryProcessor.cpp ('k') | src/gpu/GrInOrderDrawBuffer.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 2011 Google Inc. 2 * Copyright 2011 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 GrInOrderDrawBuffer_DEFINED 8 #ifndef GrInOrderDrawBuffer_DEFINED
9 #define GrInOrderDrawBuffer_DEFINED 9 #define GrInOrderDrawBuffer_DEFINED
10 10
11 #include "GrFlushToGpuDrawTarget.h" 11 #include "GrFlushToGpuDrawTarget.h"
12
13 #include "GrBatch.h"
14 #include "GrBatchTarget.h"
12 #include "GrPipeline.h" 15 #include "GrPipeline.h"
13 #include "GrPath.h" 16 #include "GrPath.h"
14 #include "GrTRecorder.h" 17 #include "GrTRecorder.h"
15 18
16 /** 19 /**
17 * GrInOrderDrawBuffer is an implementation of GrDrawTarget that queues up draws for eventual 20 * GrInOrderDrawBuffer is an implementation of GrDrawTarget that queues up draws for eventual
18 * playback into a GrGpu. In theory one draw buffer could playback into another. When index or 21 * playback into a GrGpu. In theory one draw buffer could playback into another. When index or
19 * vertex buffers are used as geometry sources it is the callers the draw buffer only holds 22 * vertex buffers are used as geometry sources it is the callers the draw buffer only holds
20 * references to the buffers. It is the callers responsibility to ensure that th e data is still 23 * references to the buffers. It is the callers responsibility to ensure that th e data is still
21 * valid when the draw buffer is played back into a GrGpu. Similarly, it is the caller's 24 * valid when the draw buffer is played back into a GrGpu. Similarly, it is the caller's
(...skipping 21 matching lines...) Expand all
43 46
44 // tracking for draws 47 // tracking for draws
45 DrawToken getCurrentDrawToken() SK_OVERRIDE { return DrawToken(this, fDrawID ); } 48 DrawToken getCurrentDrawToken() SK_OVERRIDE { return DrawToken(this, fDrawID ); }
46 49
47 void clearStencilClip(const SkIRect& rect, 50 void clearStencilClip(const SkIRect& rect,
48 bool insideClip, 51 bool insideClip,
49 GrRenderTarget* renderTarget) SK_OVERRIDE; 52 GrRenderTarget* renderTarget) SK_OVERRIDE;
50 53
51 void discard(GrRenderTarget*) SK_OVERRIDE; 54 void discard(GrRenderTarget*) SK_OVERRIDE;
52 55
56 void willReserveVertexAndIndexSpace(int vertexCount,
57 size_t vertexStride,
58 int indexCount);
59
53 private: 60 private:
54 typedef GrGpu::DrawArgs DrawArgs; 61 typedef GrGpu::DrawArgs DrawArgs;
55 enum { 62 enum {
56 kDraw_Cmd = 1, 63 kDraw_Cmd = 1,
57 kStencilPath_Cmd = 2, 64 kStencilPath_Cmd = 2,
58 kSetState_Cmd = 3, 65 kSetState_Cmd = 3,
59 kClear_Cmd = 4, 66 kClear_Cmd = 4,
60 kCopySurface_Cmd = 5, 67 kCopySurface_Cmd = 5,
61 kDrawPath_Cmd = 6, 68 kDrawPath_Cmd = 6,
62 kDrawPaths_Cmd = 7, 69 kDrawPaths_Cmd = 7,
70 kDrawBatch_Cmd = 8,
63 }; 71 };
64 72
65 struct SetState; 73 struct SetState;
66 74
67 struct Cmd : ::SkNoncopyable { 75 struct Cmd : ::SkNoncopyable {
68 Cmd(uint8_t type) : fType(type) {} 76 Cmd(uint8_t type) : fType(type) {}
69 virtual ~Cmd() {} 77 virtual ~Cmd() {}
70 78
71 virtual void execute(GrInOrderDrawBuffer*, const SetState*) = 0; 79 virtual void execute(GrInOrderDrawBuffer*, const SetState*) = 0;
72 80
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 SkIPoint fDstPoint; 181 SkIPoint fDstPoint;
174 SkIRect fSrcRect; 182 SkIRect fSrcRect;
175 183
176 private: 184 private:
177 GrPendingIOResource<GrSurface, kWrite_GrIOType> fDst; 185 GrPendingIOResource<GrSurface, kWrite_GrIOType> fDst;
178 GrPendingIOResource<GrSurface, kRead_GrIOType> fSrc; 186 GrPendingIOResource<GrSurface, kRead_GrIOType> fSrc;
179 }; 187 };
180 188
181 // TODO: rename to SetPipeline once pp, batch tracker, and desc are removed 189 // TODO: rename to SetPipeline once pp, batch tracker, and desc are removed
182 struct SetState : public Cmd { 190 struct SetState : public Cmd {
191 // TODO get rid of the prim proc version of this when we use batch every where
183 SetState(const GrPipelineBuilder& pipelineBuilder, const GrPrimitiveProc essor* primProc, 192 SetState(const GrPipelineBuilder& pipelineBuilder, const GrPrimitiveProc essor* primProc,
184 const GrDrawTargetCaps& caps, 193 const GrDrawTargetCaps& caps,
185 const GrScissorState& scissor, const GrDeviceCoordTexture* dstC opy) 194 const GrScissorState& scissor, const GrDeviceCoordTexture* dstC opy)
186 : Cmd(kSetState_Cmd) 195 : Cmd(kSetState_Cmd)
187 , fPrimitiveProcessor(primProc) 196 , fPrimitiveProcessor(primProc)
188 , fPipeline(pipelineBuilder, primProc, caps, scissor, dstCopy) {} 197 , fPipeline(pipelineBuilder, primProc, caps, scissor, dstCopy) {}
189 198
199 SetState(GrBatch* batch,
200 const GrPipelineBuilder& pipelineBuilder,
201 const GrDrawTargetCaps& caps,
202 const GrScissorState& scissor, const GrDeviceCoordTexture* dstC opy)
203 : Cmd(kSetState_Cmd)
204 , fPipeline(batch, pipelineBuilder, caps, scissor, dstCopy) {}
205
190 void execute(GrInOrderDrawBuffer*, const SetState*) SK_OVERRIDE; 206 void execute(GrInOrderDrawBuffer*, const SetState*) SK_OVERRIDE;
191 207
192 typedef GrPendingProgramElement<const GrPrimitiveProcessor> ProgramPrimi tiveProcessor; 208 typedef GrPendingProgramElement<const GrPrimitiveProcessor> ProgramPrimi tiveProcessor;
193 ProgramPrimitiveProcessor fPrimitiveProcessor; 209 ProgramPrimitiveProcessor fPrimitiveProcessor;
194 const GrPipeline fPipeline; 210 const GrPipeline fPipeline;
195 GrProgramDesc fDesc; 211 GrProgramDesc fDesc;
196 GrBatchTracker fBatchTracker; 212 GrBatchTracker fBatchTracker;
197 }; 213 };
198 214
215 struct DrawBatch : public Cmd {
216 DrawBatch(GrBatch* batch) : Cmd(kDrawBatch_Cmd), fBatch(SkRef(batch)) {
217 SkASSERT(!batch->isUsed());
218 }
219
220 void execute(GrInOrderDrawBuffer*, const SetState*) SK_OVERRIDE;
221
222 // TODO it wouldn't be too hard to let batches allocate in the cmd buffe r
223 SkAutoTUnref<GrBatch> fBatch;
224 };
225
199 typedef void* TCmdAlign; // This wouldn't be enough align if a command used long double. 226 typedef void* TCmdAlign; // This wouldn't be enough align if a command used long double.
200 typedef GrTRecorder<Cmd, TCmdAlign> CmdBuffer; 227 typedef GrTRecorder<Cmd, TCmdAlign> CmdBuffer;
201 228
202 void onReset() SK_OVERRIDE; 229 void onReset() SK_OVERRIDE;
203 void onFlush() SK_OVERRIDE; 230 void onFlush() SK_OVERRIDE;
204 231
205 // overrides from GrDrawTarget 232 // overrides from GrDrawTarget
206 void onDraw(const GrPipelineBuilder&, 233 void onDraw(const GrPipelineBuilder&,
207 const GrGeometryProcessor*, 234 const GrGeometryProcessor*,
208 const DrawInfo&, 235 const DrawInfo&,
209 const GrScissorState&, 236 const GrScissorState&,
210 const GrDeviceCoordTexture* dstCopy) SK_OVERRIDE; 237 const GrDeviceCoordTexture* dstCopy) SK_OVERRIDE;
238 void onDrawBatch(GrBatch*,
239 const GrPipelineBuilder&,
240 const GrScissorState&,
241 const GrDeviceCoordTexture* dstCopy) SK_OVERRIDE;
211 void onDrawRect(GrPipelineBuilder*, 242 void onDrawRect(GrPipelineBuilder*,
212 GrColor, 243 GrColor,
213 const SkMatrix& viewMatrix, 244 const SkMatrix& viewMatrix,
214 const SkRect& rect, 245 const SkRect& rect,
215 const SkRect* localRect, 246 const SkRect* localRect,
216 const SkMatrix* localMatrix) SK_OVERRIDE; 247 const SkMatrix* localMatrix) SK_OVERRIDE;
217 248
218 void onStencilPath(const GrPipelineBuilder&, 249 void onStencilPath(const GrPipelineBuilder&,
219 const GrPathProcessor*, 250 const GrPathProcessor*,
220 const GrPath*, 251 const GrPath*,
(...skipping 25 matching lines...) Expand all
246 const SkIRect& srcRect, 277 const SkIRect& srcRect,
247 const SkIPoint& dstPoint) SK_OVERRIDE; 278 const SkIPoint& dstPoint) SK_OVERRIDE;
248 279
249 // Attempts to concat instances from info onto the previous draw. info must represent an 280 // Attempts to concat instances from info onto the previous draw. info must represent an
250 // instanced draw. The caller must have already recorded a new draw state an d clip if necessary. 281 // instanced draw. The caller must have already recorded a new draw state an d clip if necessary.
251 int concatInstancedDraw(const GrPipelineBuilder&, const DrawInfo&); 282 int concatInstancedDraw(const GrPipelineBuilder&, const DrawInfo&);
252 283
253 // Determines whether the current draw operation requires a new GrPipeline a nd if so 284 // Determines whether the current draw operation requires a new GrPipeline a nd if so
254 // records it. If the draw can be skipped false is returned and no new GrPip eline is 285 // records it. If the draw can be skipped false is returned and no new GrPip eline is
255 // recorded. 286 // recorded.
287 // TODO delete the primproc variant when we have batches everywhere
256 bool SK_WARN_UNUSED_RESULT recordStateAndShouldDraw(const GrPipelineBuilder& , 288 bool SK_WARN_UNUSED_RESULT recordStateAndShouldDraw(const GrPipelineBuilder& ,
257 const GrPrimitiveProcess or*, 289 const GrPrimitiveProcess or*,
258 const GrScissorState&, 290 const GrScissorState&,
259 const GrDeviceCoordTextu re*); 291 const GrDeviceCoordTextu re*);
292 bool SK_WARN_UNUSED_RESULT recordStateAndShouldDraw(GrBatch*,
293 const GrPipelineBuilder& ,
294 const GrScissorState&,
295 const GrDeviceCoordTextu re*);
296
260 // We lazily record clip changes in order to skip clips that have no effect. 297 // We lazily record clip changes in order to skip clips that have no effect.
261 void recordClipIfNecessary(); 298 void recordClipIfNecessary();
262 // Records any trace markers for a command after adding it to the buffer. 299 // Records any trace markers for a command after adding it to the buffer.
263 void recordTraceMarkersIfNecessary(); 300 void recordTraceMarkersIfNecessary();
264 301
265 bool isIssued(uint32_t drawID) SK_OVERRIDE { return drawID != fDrawID; } 302 bool isIssued(uint32_t drawID) SK_OVERRIDE { return drawID != fDrawID; }
266 303
304 GrBatchTarget* getBatchTarget() { return &fBatchTarget; }
305
267 // TODO: Use a single allocator for commands and records 306 // TODO: Use a single allocator for commands and records
268 enum { 307 enum {
269 kCmdBufferInitialSizeInBytes = 8 * 1024, 308 kCmdBufferInitialSizeInBytes = 8 * 1024,
270 kPathIdxBufferMinReserve = 2 * 64, // 64 uint16_t's 309 kPathIdxBufferMinReserve = 2 * 64, // 64 uint16_t's
271 kPathXformBufferMinReserve = 2 * 64, // 64 two-float transforms 310 kPathXformBufferMinReserve = 2 * 64, // 64 two-float transforms
272 }; 311 };
273 312
274 CmdBuffer fCmdBuffer; 313 CmdBuffer fCmdBuffer;
275 SetState* fPrevState; 314 SetState* fPrevState;
276 SkTArray<GrTraceMarkerSet, false> fGpuCmdMarkers; 315 SkTArray<GrTraceMarkerSet, false> fGpuCmdMarkers;
277 SkTDArray<char> fPathIndexBuffer; 316 SkTDArray<char> fPathIndexBuffer;
278 SkTDArray<float> fPathTransformBuffer; 317 SkTDArray<float> fPathTransformBuffer;
279 uint32_t fDrawID; 318 uint32_t fDrawID;
319 GrBatchTarget fBatchTarget;
320 // TODO hack until batch is everywhere
321 DrawBatch* fDrawBatch;
322
323 void closeBatch();
280 324
281 typedef GrFlushToGpuDrawTarget INHERITED; 325 typedef GrFlushToGpuDrawTarget INHERITED;
282 }; 326 };
283 327
284 #endif 328 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrGeometryProcessor.cpp ('k') | src/gpu/GrInOrderDrawBuffer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698