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

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

Issue 845103005: GrBatchPrototype (Closed) Base URL: https://skia.googlesource.com/skia.git@lc2
Patch Set: a bit more tweaking Created 5 years, 11 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
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 "GrBatchBuffer.h"
12 #include "GrOptDrawState.h" 15 #include "GrOptDrawState.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 24 matching lines...) Expand all
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
53 private: 56 private:
54 typedef GrGpu::DrawArgs DrawArgs; 57 typedef GrGpu::DrawArgs DrawArgs;
55 enum { 58 enum {
56 kDraw_Cmd = 1, 59 kDraw_Cmd = 1,
57 kStencilPath_Cmd = 2, 60 kStencilPath_Cmd = 2,
58 kSetState_Cmd = 3, 61 kSetState_Cmd = 3,
59 kClear_Cmd = 4, 62 kClear_Cmd = 4,
60 kCopySurface_Cmd = 5, 63 kCopySurface_Cmd = 5,
61 kDrawPath_Cmd = 6, 64 kDrawPath_Cmd = 6,
62 kDrawPaths_Cmd = 7, 65 kDrawPaths_Cmd = 7,
66 kBatchDraw = 8,
63 }; 67 };
64 68
65 struct SetState; 69 struct SetState;
66 70
67 struct Cmd : ::SkNoncopyable { 71 struct Cmd : ::SkNoncopyable {
68 Cmd(uint8_t type) : fType(type) {} 72 Cmd(uint8_t type) : fType(type) {}
69 virtual ~Cmd() {} 73 virtual ~Cmd() {}
70 74
71 virtual void execute(GrInOrderDrawBuffer*, const SetState*) = 0; 75 virtual void execute(GrInOrderDrawBuffer*, const SetState*) = 0;
72 76
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 176
173 SkIPoint fDstPoint; 177 SkIPoint fDstPoint;
174 SkIRect fSrcRect; 178 SkIRect fSrcRect;
175 179
176 private: 180 private:
177 GrPendingIOResource<GrSurface, kWrite_GrIOType> fDst; 181 GrPendingIOResource<GrSurface, kWrite_GrIOType> fDst;
178 GrPendingIOResource<GrSurface, kRead_GrIOType> fSrc; 182 GrPendingIOResource<GrSurface, kRead_GrIOType> fSrc;
179 }; 183 };
180 184
181 struct SetState : public Cmd { 185 struct SetState : public Cmd {
186 // TODO get rid of the prim proc version of this when we use batch every where
182 SetState(const GrDrawState& drawState, const GrPrimitiveProcessor* primP roc, 187 SetState(const GrDrawState& drawState, const GrPrimitiveProcessor* primP roc,
183 const GrDrawTargetCaps& caps, 188 const GrDrawTargetCaps& caps,
184 const GrScissorState& scissor, const GrDeviceCoordTexture* dstC opy) 189 const GrScissorState& scissor, const GrDeviceCoordTexture* dstC opy)
185 : Cmd(kSetState_Cmd) 190 : Cmd(kSetState_Cmd)
186 , fPrimitiveProcessor(primProc) 191 , fPrimitiveProcessor(primProc)
187 , fState(drawState, primProc, caps, scissor, dstCopy) {} 192 , fState(drawState, primProc, caps, scissor, dstCopy) {}
188 193
194 SetState(GrBatch* batch,
195 const GrDrawState& drawState,
196 const GrDrawTargetCaps& caps,
197 const GrScissorState& scissor, const GrDeviceCoordTexture* dstC opy)
198 : Cmd(kSetState_Cmd)
199 , fState(batch, drawState, caps, scissor, dstCopy) {}
200
189 void execute(GrInOrderDrawBuffer*, const SetState*) SK_OVERRIDE; 201 void execute(GrInOrderDrawBuffer*, const SetState*) SK_OVERRIDE;
190 202
191 typedef GrPendingProgramElement<const GrPrimitiveProcessor> ProgramPrimi tiveProcessor; 203 typedef GrPendingProgramElement<const GrPrimitiveProcessor> ProgramPrimi tiveProcessor;
192 ProgramPrimitiveProcessor fPrimitiveProcessor; 204 ProgramPrimitiveProcessor fPrimitiveProcessor;
193 const GrOptDrawState fState; 205 const GrOptDrawState fState;
194 GrProgramDesc fDesc; 206 GrProgramDesc fDesc;
195 GrBatchTracker fBatchTracker; 207 GrBatchTracker fBatchTracker;
196 }; 208 };
197 209
210 struct BatchDraw : public Cmd {
211 BatchDraw(GrBatch* batch) : Cmd(kBatchDraw), fBatch(SkRef(batch)) {
212 SkASSERT(!batch->isUsed());
213 }
214
215 void execute(GrInOrderDrawBuffer*, const SetState*) SK_OVERRIDE;
216
217 // TODO it wouldn't be too hard to let batches allocate in the cmd buffe r
218 SkAutoTUnref<GrBatch> fBatch;
219 };
220
198 typedef void* TCmdAlign; // This wouldn't be enough align if a command used long double. 221 typedef void* TCmdAlign; // This wouldn't be enough align if a command used long double.
199 typedef GrTRecorder<Cmd, TCmdAlign> CmdBuffer; 222 typedef GrTRecorder<Cmd, TCmdAlign> CmdBuffer;
200 223
201 void onReset() SK_OVERRIDE; 224 void onReset() SK_OVERRIDE;
202 void onFlush() SK_OVERRIDE; 225 void onFlush() SK_OVERRIDE;
203 226
204 // overrides from GrDrawTarget 227 // overrides from GrDrawTarget
205 void onDraw(const GrDrawState&, 228 void onDraw(const GrDrawState&,
206 const GrGeometryProcessor*, 229 const GrGeometryProcessor*,
207 const DrawInfo&, 230 const DrawInfo&,
208 const GrScissorState&, 231 const GrScissorState&,
209 const GrDeviceCoordTexture* dstCopy) SK_OVERRIDE; 232 const GrDeviceCoordTexture* dstCopy) SK_OVERRIDE;
233 void onBatchDraw(GrBatch*,
234 const GrDrawState&,
235 GrPrimitiveType type,
236 const GrScissorState&,
237 const GrDeviceCoordTexture* dstCopy) SK_OVERRIDE;
210 void onDrawRect(GrDrawState*, 238 void onDrawRect(GrDrawState*,
211 GrColor, 239 GrColor,
212 const SkMatrix& viewMatrix, 240 const SkMatrix& viewMatrix,
213 const SkRect& rect, 241 const SkRect& rect,
214 const SkRect* localRect, 242 const SkRect* localRect,
215 const SkMatrix* localMatrix) SK_OVERRIDE; 243 const SkMatrix* localMatrix) SK_OVERRIDE;
216 244
217 void onStencilPath(const GrDrawState&, 245 void onStencilPath(const GrDrawState&,
218 const GrPathProcessor*, 246 const GrPathProcessor*,
219 const GrPath*, 247 const GrPath*,
(...skipping 25 matching lines...) Expand all
245 const SkIRect& srcRect, 273 const SkIRect& srcRect,
246 const SkIPoint& dstPoint) SK_OVERRIDE; 274 const SkIPoint& dstPoint) SK_OVERRIDE;
247 275
248 // Attempts to concat instances from info onto the previous draw. info must represent an 276 // Attempts to concat instances from info onto the previous draw. info must represent an
249 // instanced draw. The caller must have already recorded a new draw state an d clip if necessary. 277 // instanced draw. The caller must have already recorded a new draw state an d clip if necessary.
250 int concatInstancedDraw(const GrDrawState&, const DrawInfo&); 278 int concatInstancedDraw(const GrDrawState&, const DrawInfo&);
251 279
252 // Determines whether the current draw operation requires a new GrOptDrawSta te and if so 280 // Determines whether the current draw operation requires a new GrOptDrawSta te and if so
253 // records it. If the draw can be skipped false is returned and no new GrOpt DrawState is 281 // records it. If the draw can be skipped false is returned and no new GrOpt DrawState is
254 // recorded. 282 // recorded.
283 // TODO delete the primproc variant when we have batches everywhere
255 bool SK_WARN_UNUSED_RESULT recordStateAndShouldDraw(const GrDrawState&, 284 bool SK_WARN_UNUSED_RESULT recordStateAndShouldDraw(const GrDrawState&,
256 const GrPrimitiveProcess or*, 285 const GrPrimitiveProcess or*,
257 const GrScissorState&, 286 const GrScissorState&,
258 const GrDeviceCoordTextu re*); 287 const GrDeviceCoordTextu re*);
288 bool SK_WARN_UNUSED_RESULT recordStateAndShouldDraw(GrBatch*,
289 const GrDrawState&,
290 const GrScissorState&,
291 const GrDeviceCoordTextu re*);
292
259 // We lazily record clip changes in order to skip clips that have no effect. 293 // We lazily record clip changes in order to skip clips that have no effect.
260 void recordClipIfNecessary(); 294 void recordClipIfNecessary();
261 // Records any trace markers for a command after adding it to the buffer. 295 // Records any trace markers for a command after adding it to the buffer.
262 void recordTraceMarkersIfNecessary(); 296 void recordTraceMarkersIfNecessary();
263 297
264 bool isIssued(uint32_t drawID) SK_OVERRIDE { return drawID != fDrawID; } 298 bool isIssued(uint32_t drawID) SK_OVERRIDE { return drawID != fDrawID; }
265 299
300 GrBatchBuffer* getBatchBuffer() { return &fBatchBuffer; }
301
266 // TODO: Use a single allocator for commands and records 302 // TODO: Use a single allocator for commands and records
267 enum { 303 enum {
268 kCmdBufferInitialSizeInBytes = 8 * 1024, 304 kCmdBufferInitialSizeInBytes = 8 * 1024,
269 kPathIdxBufferMinReserve = 2 * 64, // 64 uint16_t's 305 kPathIdxBufferMinReserve = 2 * 64, // 64 uint16_t's
270 kPathXformBufferMinReserve = 2 * 64, // 64 two-float transforms 306 kPathXformBufferMinReserve = 2 * 64, // 64 two-float transforms
271 }; 307 };
272 308
273 CmdBuffer fCmdBuffer; 309 CmdBuffer fCmdBuffer;
274 SetState* fPrevState; 310 SetState* fPrevState;
275 SkTArray<GrTraceMarkerSet, false> fGpuCmdMarkers; 311 SkTArray<GrTraceMarkerSet, false> fGpuCmdMarkers;
276 SkTDArray<char> fPathIndexBuffer; 312 SkTDArray<char> fPathIndexBuffer;
277 SkTDArray<float> fPathTransformBuffer; 313 SkTDArray<float> fPathTransformBuffer;
278 uint32_t fDrawID; 314 uint32_t fDrawID;
315 GrBatchBuffer fBatchBuffer;
279 316
280 typedef GrFlushToGpuDrawTarget INHERITED; 317 typedef GrFlushToGpuDrawTarget INHERITED;
281 }; 318 };
282 319
283 #endif 320 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698