| 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 "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 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 kDrawBatch_Cmd = 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 // TODO: rename to SetPipeline once pp, batch tracker, and desc are removed | 185 // TODO: rename to SetPipeline once pp, batch tracker, and desc are removed |
| 182 struct SetState : public Cmd { | 186 struct SetState : public Cmd { |
| 187 // 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, | 188 SetState(const GrPipelineBuilder& pipelineBuilder, const GrPrimitiveProc
essor* primProc, |
| 184 const GrDrawTargetCaps& caps, | 189 const GrDrawTargetCaps& caps, |
| 185 const GrScissorState& scissor, const GrDeviceCoordTexture* dstC
opy) | 190 const GrScissorState& scissor, const GrDeviceCoordTexture* dstC
opy) |
| 186 : Cmd(kSetState_Cmd) | 191 : Cmd(kSetState_Cmd) |
| 187 , fPrimitiveProcessor(primProc) | 192 , fPrimitiveProcessor(primProc) |
| 188 , fPipeline(pipelineBuilder, primProc, caps, scissor, dstCopy) {} | 193 , fPipeline(pipelineBuilder, primProc, caps, scissor, dstCopy) {} |
| 189 | 194 |
| 195 SetState(GrBatch* batch, |
| 196 const GrPipelineBuilder& pipelineBuilder, |
| 197 const GrDrawTargetCaps& caps, |
| 198 const GrScissorState& scissor, const GrDeviceCoordTexture* dstC
opy) |
| 199 : Cmd(kSetState_Cmd) |
| 200 , fPipeline(batch, pipelineBuilder, caps, scissor, dstCopy) {} |
| 201 |
| 190 void execute(GrInOrderDrawBuffer*, const SetState*) SK_OVERRIDE; | 202 void execute(GrInOrderDrawBuffer*, const SetState*) SK_OVERRIDE; |
| 191 | 203 |
| 192 typedef GrPendingProgramElement<const GrPrimitiveProcessor> ProgramPrimi
tiveProcessor; | 204 typedef GrPendingProgramElement<const GrPrimitiveProcessor> ProgramPrimi
tiveProcessor; |
| 193 ProgramPrimitiveProcessor fPrimitiveProcessor; | 205 ProgramPrimitiveProcessor fPrimitiveProcessor; |
| 194 const GrPipeline fPipeline; | 206 const GrPipeline fPipeline; |
| 195 GrProgramDesc fDesc; | 207 GrProgramDesc fDesc; |
| 196 GrBatchTracker fBatchTracker; | 208 GrBatchTracker fBatchTracker; |
| 197 }; | 209 }; |
| 198 | 210 |
| 211 struct DrawBatch : public Cmd { |
| 212 DrawBatch(GrBatch* batch) : Cmd(kDrawBatch_Cmd), fBatch(SkRef(batch)) { |
| 213 SkASSERT(!batch->isUsed()); |
| 214 } |
| 215 |
| 216 void execute(GrInOrderDrawBuffer*, const SetState*) SK_OVERRIDE; |
| 217 |
| 218 // TODO it wouldn't be too hard to let batches allocate in the cmd buffe
r |
| 219 SkAutoTUnref<GrBatch> fBatch; |
| 220 }; |
| 221 |
| 199 typedef void* TCmdAlign; // This wouldn't be enough align if a command used
long double. | 222 typedef void* TCmdAlign; // This wouldn't be enough align if a command used
long double. |
| 200 typedef GrTRecorder<Cmd, TCmdAlign> CmdBuffer; | 223 typedef GrTRecorder<Cmd, TCmdAlign> CmdBuffer; |
| 201 | 224 |
| 202 void onReset() SK_OVERRIDE; | 225 void onReset() SK_OVERRIDE; |
| 203 void onFlush() SK_OVERRIDE; | 226 void onFlush() SK_OVERRIDE; |
| 204 | 227 |
| 205 // overrides from GrDrawTarget | 228 // overrides from GrDrawTarget |
| 206 void onDraw(const GrPipelineBuilder&, | 229 void onDraw(const GrPipelineBuilder&, |
| 207 const GrGeometryProcessor*, | 230 const GrGeometryProcessor*, |
| 208 const DrawInfo&, | 231 const DrawInfo&, |
| 209 const GrScissorState&, | 232 const GrScissorState&, |
| 210 const GrDeviceCoordTexture* dstCopy) SK_OVERRIDE; | 233 const GrDeviceCoordTexture* dstCopy) SK_OVERRIDE; |
| 234 void onDrawBatch(GrBatch*, |
| 235 const GrPipelineBuilder&, |
| 236 const GrScissorState&, |
| 237 const GrDeviceCoordTexture* dstCopy) SK_OVERRIDE; |
| 211 void onDrawRect(GrPipelineBuilder*, | 238 void onDrawRect(GrPipelineBuilder*, |
| 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 GrPipelineBuilder&, | 245 void onStencilPath(const GrPipelineBuilder&, |
| 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 GrPipelineBuilder&, const DrawInfo&); | 278 int concatInstancedDraw(const GrPipelineBuilder&, const DrawInfo&); |
| 252 | 279 |
| 253 // Determines whether the current draw operation requires a new GrPipeline a
nd if so | 280 // 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 | 281 // records it. If the draw can be skipped false is returned and no new GrPip
eline is |
| 255 // recorded. | 282 // recorded. |
| 283 // TODO delete the primproc variant when we have batches everywhere |
| 256 bool SK_WARN_UNUSED_RESULT recordStateAndShouldDraw(const GrPipelineBuilder&
, | 284 bool SK_WARN_UNUSED_RESULT recordStateAndShouldDraw(const GrPipelineBuilder&
, |
| 257 const GrPrimitiveProcess
or*, | 285 const GrPrimitiveProcess
or*, |
| 258 const GrScissorState&, | 286 const GrScissorState&, |
| 259 const GrDeviceCoordTextu
re*); | 287 const GrDeviceCoordTextu
re*); |
| 288 bool SK_WARN_UNUSED_RESULT recordStateAndShouldDraw(GrBatch*, |
| 289 const GrPipelineBuilder&
, |
| 290 const GrScissorState&, |
| 291 const GrDeviceCoordTextu
re*); |
| 292 |
| 260 // 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. |
| 261 void recordClipIfNecessary(); | 294 void recordClipIfNecessary(); |
| 262 // 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. |
| 263 void recordTraceMarkersIfNecessary(); | 296 void recordTraceMarkersIfNecessary(); |
| 264 | 297 |
| 265 bool isIssued(uint32_t drawID) SK_OVERRIDE { return drawID != fDrawID; } | 298 bool isIssued(uint32_t drawID) SK_OVERRIDE { return drawID != fDrawID; } |
| 266 | 299 |
| 300 GrBatchTarget* getBatchTarget() { return &fBatchTarget; } |
| 301 |
| 267 // TODO: Use a single allocator for commands and records | 302 // TODO: Use a single allocator for commands and records |
| 268 enum { | 303 enum { |
| 269 kCmdBufferInitialSizeInBytes = 8 * 1024, | 304 kCmdBufferInitialSizeInBytes = 8 * 1024, |
| 270 kPathIdxBufferMinReserve = 2 * 64, // 64 uint16_t's | 305 kPathIdxBufferMinReserve = 2 * 64, // 64 uint16_t's |
| 271 kPathXformBufferMinReserve = 2 * 64, // 64 two-float transforms | 306 kPathXformBufferMinReserve = 2 * 64, // 64 two-float transforms |
| 272 }; | 307 }; |
| 273 | 308 |
| 274 CmdBuffer fCmdBuffer; | 309 CmdBuffer fCmdBuffer; |
| 275 SetState* fPrevState; | 310 SetState* fPrevState; |
| 276 SkTArray<GrTraceMarkerSet, false> fGpuCmdMarkers; | 311 SkTArray<GrTraceMarkerSet, false> fGpuCmdMarkers; |
| 277 SkTDArray<char> fPathIndexBuffer; | 312 SkTDArray<char> fPathIndexBuffer; |
| 278 SkTDArray<float> fPathTransformBuffer; | 313 SkTDArray<float> fPathTransformBuffer; |
| 279 uint32_t fDrawID; | 314 uint32_t fDrawID; |
| 315 GrBatchTarget fBatchTarget; |
| 280 | 316 |
| 281 typedef GrFlushToGpuDrawTarget INHERITED; | 317 typedef GrFlushToGpuDrawTarget INHERITED; |
| 282 }; | 318 }; |
| 283 | 319 |
| 284 #endif | 320 #endif |
| OLD | NEW |