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