| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 GrGpu::DrawType drawType) | 190 GrGpu::DrawType drawType) |
| 186 : Cmd(kSetState_Cmd) | 191 : Cmd(kSetState_Cmd) |
| 187 , fPrimitiveProcessor(primProc) | 192 , fPrimitiveProcessor(primProc) |
| 188 , fState(drawState, primProc, caps, scissor, dstCopy, drawType) {} | 193 , fState(drawState, primProc, caps, scissor, dstCopy, drawType) {} |
| 189 | 194 |
| 195 SetState(GrBatch* batch, |
| 196 const GrDrawState& drawState, |
| 197 const GrDrawTargetCaps& caps, |
| 198 const GrScissorState& scissor, const GrDeviceCoordTexture* dstC
opy, |
| 199 GrGpu::DrawType drawType) |
| 200 : Cmd(kSetState_Cmd) |
| 201 , fState(batch, drawState, caps, scissor, dstCopy, drawType) {} |
| 202 |
| 190 void execute(GrInOrderDrawBuffer*, const SetState*) SK_OVERRIDE; | 203 void execute(GrInOrderDrawBuffer*, const SetState*) SK_OVERRIDE; |
| 191 | 204 |
| 192 typedef GrPendingProgramElement<const GrPrimitiveProcessor> ProgramPrimi
tiveProcessor; | 205 typedef GrPendingProgramElement<const GrPrimitiveProcessor> ProgramPrimi
tiveProcessor; |
| 193 ProgramPrimitiveProcessor fPrimitiveProcessor; | 206 ProgramPrimitiveProcessor fPrimitiveProcessor; |
| 194 const GrOptDrawState fState; | 207 const GrOptDrawState fState; |
| 195 GrProgramDesc fDesc; | 208 GrProgramDesc fDesc; |
| 196 GrBatchTracker fBatchTracker; | 209 GrBatchTracker fBatchTracker; |
| 197 }; | 210 }; |
| 198 | 211 |
| 212 struct BatchDraw : public Cmd { |
| 213 BatchDraw(GrBatch* batch) : Cmd(kBatchDraw), fBatch(batch) {} |
| 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 SkAutoTDelete<GrBatch> fBatch; |
| 219 }; |
| 220 |
| 199 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. |
| 200 typedef GrTRecorder<Cmd, TCmdAlign> CmdBuffer; | 222 typedef GrTRecorder<Cmd, TCmdAlign> CmdBuffer; |
| 201 | 223 |
| 202 void onReset() SK_OVERRIDE; | 224 void onReset() SK_OVERRIDE; |
| 203 void onFlush() SK_OVERRIDE; | 225 void onFlush() SK_OVERRIDE; |
| 204 | 226 |
| 205 // overrides from GrDrawTarget | 227 // overrides from GrDrawTarget |
| 206 void onDraw(const GrDrawState&, | 228 void onDraw(const GrDrawState&, |
| 207 const GrGeometryProcessor*, | 229 const GrGeometryProcessor*, |
| 208 const DrawInfo&, | 230 const DrawInfo&, |
| 209 const GrScissorState&, | 231 const GrScissorState&, |
| 210 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; |
| 211 void onDrawRect(GrDrawState*, | 238 void onDrawRect(GrDrawState*, |
| 212 GrColor, | 239 GrColor, |
| 213 const SkMatrix& viewMatrix, | 240 const SkMatrix& viewMatrix, |
| 214 const SkRect& rect, | 241 const SkRect& rect, |
| 215 const SkRect* localRect, | 242 const SkRect* localRect, |
| 216 const SkMatrix* localMatrix) SK_OVERRIDE; | 243 const SkMatrix* localMatrix) SK_OVERRIDE; |
| 217 | 244 |
| 218 void onStencilPath(const GrDrawState&, | 245 void onStencilPath(const GrDrawState&, |
| 219 const GrPathProcessor*, | 246 const GrPathProcessor*, |
| 220 const GrPath*, | 247 const GrPath*, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 246 const SkIRect& srcRect, | 273 const SkIRect& srcRect, |
| 247 const SkIPoint& dstPoint) SK_OVERRIDE; | 274 const SkIPoint& dstPoint) SK_OVERRIDE; |
| 248 | 275 |
| 249 // 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 |
| 250 // 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. |
| 251 int concatInstancedDraw(const GrDrawState&, const DrawInfo&); | 278 int concatInstancedDraw(const GrDrawState&, const DrawInfo&); |
| 252 | 279 |
| 253 // 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 |
| 254 // 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 |
| 255 // recorded. | 282 // recorded. |
| 283 // TODO delete the primproc variant when we have batches everywhere |
| 256 bool SK_WARN_UNUSED_RESULT recordStateAndShouldDraw(const GrDrawState&, | 284 bool SK_WARN_UNUSED_RESULT recordStateAndShouldDraw(const GrDrawState&, |
| 257 const GrPrimitiveProcess
or*, | 285 const GrPrimitiveProcess
or*, |
| 258 GrGpu::DrawType, | 286 GrGpu::DrawType, |
| 259 const GrScissorState&, | 287 const GrScissorState&, |
| 260 const GrDeviceCoordTextu
re*); | 288 const GrDeviceCoordTextu
re*); |
| 289 bool SK_WARN_UNUSED_RESULT recordStateAndShouldDraw(GrBatch*, |
| 290 const GrDrawState&, |
| 291 GrGpu::DrawType, |
| 292 const GrScissorState&, |
| 293 const GrDeviceCoordTextu
re*); |
| 294 |
| 261 // We lazily record clip changes in order to skip clips that have no effect. | 295 // We lazily record clip changes in order to skip clips that have no effect. |
| 262 void recordClipIfNecessary(); | 296 void recordClipIfNecessary(); |
| 263 // Records any trace markers for a command after adding it to the buffer. | 297 // Records any trace markers for a command after adding it to the buffer. |
| 264 void recordTraceMarkersIfNecessary(); | 298 void recordTraceMarkersIfNecessary(); |
| 265 | 299 |
| 266 bool isIssued(uint32_t drawID) SK_OVERRIDE { return drawID != fDrawID; } | 300 bool isIssued(uint32_t drawID) SK_OVERRIDE { return drawID != fDrawID; } |
| 267 | 301 |
| 302 GrBatchBuffer* getBatchBuffer() { return &fBatchBuffer; } |
| 303 |
| 268 // TODO: Use a single allocator for commands and records | 304 // TODO: Use a single allocator for commands and records |
| 269 enum { | 305 enum { |
| 270 kCmdBufferInitialSizeInBytes = 8 * 1024, | 306 kCmdBufferInitialSizeInBytes = 8 * 1024, |
| 271 kPathIdxBufferMinReserve = 2 * 64, // 64 uint16_t's | 307 kPathIdxBufferMinReserve = 2 * 64, // 64 uint16_t's |
| 272 kPathXformBufferMinReserve = 2 * 64, // 64 two-float transforms | 308 kPathXformBufferMinReserve = 2 * 64, // 64 two-float transforms |
| 273 }; | 309 }; |
| 274 | 310 |
| 275 CmdBuffer fCmdBuffer; | 311 CmdBuffer fCmdBuffer; |
| 276 SetState* fPrevState; | 312 SetState* fPrevState; |
| 277 SkTArray<GrTraceMarkerSet, false> fGpuCmdMarkers; | 313 SkTArray<GrTraceMarkerSet, false> fGpuCmdMarkers; |
| 278 SkTDArray<char> fPathIndexBuffer; | 314 SkTDArray<char> fPathIndexBuffer; |
| 279 SkTDArray<float> fPathTransformBuffer; | 315 SkTDArray<float> fPathTransformBuffer; |
| 280 uint32_t fDrawID; | 316 uint32_t fDrawID; |
| 317 GrBatchBuffer fBatchBuffer; |
| 281 | 318 |
| 282 typedef GrFlushToGpuDrawTarget INHERITED; | 319 typedef GrFlushToGpuDrawTarget INHERITED; |
| 283 }; | 320 }; |
| 284 | 321 |
| 285 #endif | 322 #endif |
| OLD | NEW |