| 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 | 12 #include "GrTargetCommands.h" |
| 13 #include "GrBatch.h" | |
| 14 #include "GrBatchTarget.h" | |
| 15 #include "SkChunkAlloc.h" | 13 #include "SkChunkAlloc.h" |
| 16 #include "GrPipeline.h" | |
| 17 #include "GrPath.h" | |
| 18 #include "GrTRecorder.h" | |
| 19 | |
| 20 class GrInOrderDrawBuffer; | |
| 21 | |
| 22 class GrTargetCommands : ::SkNoncopyable { | |
| 23 struct SetState; | |
| 24 | |
| 25 public: | |
| 26 GrTargetCommands(GrGpu* gpu, | |
| 27 GrVertexBufferAllocPool* vertexPool, | |
| 28 GrIndexBufferAllocPool* indexPool) | |
| 29 : fCmdBuffer(kCmdBufferInitialSizeInBytes) | |
| 30 , fPrevState(NULL) | |
| 31 , fBatchTarget(gpu, vertexPool, indexPool) | |
| 32 , fDrawBatch(NULL) { | |
| 33 } | |
| 34 | |
| 35 struct Cmd : ::SkNoncopyable { | |
| 36 enum { | |
| 37 kDraw_Cmd = 1, | |
| 38 kStencilPath_Cmd = 2, | |
| 39 kSetState_Cmd = 3, | |
| 40 kClear_Cmd = 4, | |
| 41 kCopySurface_Cmd = 5, | |
| 42 kDrawPath_Cmd = 6, | |
| 43 kDrawPaths_Cmd = 7, | |
| 44 kDrawBatch_Cmd = 8, | |
| 45 }; | |
| 46 | |
| 47 Cmd(uint8_t type) : fType(type) {} | |
| 48 virtual ~Cmd() {} | |
| 49 | |
| 50 virtual void execute(GrGpu*, const SetState*) = 0; | |
| 51 | |
| 52 uint8_t type() const { return fType & kCmdMask; } | |
| 53 | |
| 54 bool isTraced() const { return SkToBool(fType & kTraceCmdBit); } | |
| 55 void makeTraced() { fType |= kTraceCmdBit; } | |
| 56 | |
| 57 private: | |
| 58 static const int kCmdMask = 0x7F; | |
| 59 static const int kTraceCmdBit = 0x80; | |
| 60 | |
| 61 uint8_t fType; | |
| 62 }; | |
| 63 | |
| 64 void reset(); | |
| 65 void flush(GrInOrderDrawBuffer*); | |
| 66 | |
| 67 Cmd* recordClearStencilClip(GrInOrderDrawBuffer*, | |
| 68 const SkIRect& rect, | |
| 69 bool insideClip, | |
| 70 GrRenderTarget* renderTarget); | |
| 71 | |
| 72 Cmd* recordDiscard(GrInOrderDrawBuffer*, GrRenderTarget*); | |
| 73 | |
| 74 Cmd* recordDraw(GrInOrderDrawBuffer*, | |
| 75 const GrGeometryProcessor*, | |
| 76 const GrDrawTarget::DrawInfo&, | |
| 77 const GrDrawTarget::PipelineInfo&); | |
| 78 Cmd* recordDrawBatch(GrInOrderDrawBuffer*, | |
| 79 GrBatch*, | |
| 80 const GrDrawTarget::PipelineInfo&); | |
| 81 void recordDrawRect(GrInOrderDrawBuffer*, | |
| 82 GrPipelineBuilder*, | |
| 83 GrColor, | |
| 84 const SkMatrix& viewMatrix, | |
| 85 const SkRect& rect, | |
| 86 const SkRect* localRect, | |
| 87 const SkMatrix* localMatrix); | |
| 88 Cmd* recordStencilPath(GrInOrderDrawBuffer*, | |
| 89 const GrPipelineBuilder&, | |
| 90 const GrPathProcessor*, | |
| 91 const GrPath*, | |
| 92 const GrScissorState&, | |
| 93 const GrStencilSettings&); | |
| 94 Cmd* recordDrawPath(GrInOrderDrawBuffer*, | |
| 95 const GrPathProcessor*, | |
| 96 const GrPath*, | |
| 97 const GrStencilSettings&, | |
| 98 const GrDrawTarget::PipelineInfo&); | |
| 99 Cmd* recordDrawPaths(GrInOrderDrawBuffer*, | |
| 100 const GrPathProcessor*, | |
| 101 const GrPathRange*, | |
| 102 const void*, | |
| 103 GrDrawTarget::PathIndexType, | |
| 104 const float transformValues[], | |
| 105 GrDrawTarget::PathTransformType , | |
| 106 int, | |
| 107 const GrStencilSettings&, | |
| 108 const GrDrawTarget::PipelineInfo&); | |
| 109 Cmd* recordClear(GrInOrderDrawBuffer*, | |
| 110 const SkIRect* rect, | |
| 111 GrColor, | |
| 112 bool canIgnoreRect, | |
| 113 GrRenderTarget*); | |
| 114 Cmd* recordCopySurface(GrInOrderDrawBuffer*, | |
| 115 GrSurface* dst, | |
| 116 GrSurface* src, | |
| 117 const SkIRect& srcRect, | |
| 118 const SkIPoint& dstPoint); | |
| 119 | |
| 120 protected: | |
| 121 void willReserveVertexAndIndexSpace(int vertexCount, | |
| 122 size_t vertexStride, | |
| 123 int indexCount); | |
| 124 | |
| 125 private: | |
| 126 friend class GrInOrderDrawBuffer; | |
| 127 | |
| 128 typedef GrGpu::DrawArgs DrawArgs; | |
| 129 | |
| 130 // Attempts to concat instances from info onto the previous draw. info must
represent an | |
| 131 // instanced draw. The caller must have already recorded a new draw state an
d clip if necessary. | |
| 132 int concatInstancedDraw(GrInOrderDrawBuffer*, const GrDrawTarget::DrawInfo&)
; | |
| 133 | |
| 134 bool SK_WARN_UNUSED_RESULT setupPipelineAndShouldDraw(GrInOrderDrawBuffer*, | |
| 135 const GrPrimitiveProce
ssor*, | |
| 136 const GrDrawTarget::Pi
pelineInfo&); | |
| 137 bool SK_WARN_UNUSED_RESULT setupPipelineAndShouldDraw(GrInOrderDrawBuffer*, | |
| 138 GrBatch*, | |
| 139 const GrDrawTarget::Pi
pelineInfo&); | |
| 140 | |
| 141 struct Draw : public Cmd { | |
| 142 Draw(const GrDrawTarget::DrawInfo& info) : Cmd(kDraw_Cmd), fInfo(info) {
} | |
| 143 | |
| 144 void execute(GrGpu*, const SetState*) SK_OVERRIDE; | |
| 145 | |
| 146 GrDrawTarget::DrawInfo fInfo; | |
| 147 }; | |
| 148 | |
| 149 struct StencilPath : public Cmd { | |
| 150 StencilPath(const GrPath* path, GrRenderTarget* rt) | |
| 151 : Cmd(kStencilPath_Cmd) | |
| 152 , fRenderTarget(rt) | |
| 153 , fPath(path) {} | |
| 154 | |
| 155 const GrPath* path() const { return fPath.get(); } | |
| 156 | |
| 157 void execute(GrGpu*, const SetState*) SK_OVERRIDE; | |
| 158 | |
| 159 SkMatrix fViewMatrix; | |
| 160 bool fUseHWAA; | |
| 161 GrStencilSettings fStencil; | |
| 162 GrScissorState fScissor; | |
| 163 private: | |
| 164 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; | |
| 165 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; | |
| 166 }; | |
| 167 | |
| 168 struct DrawPath : public Cmd { | |
| 169 DrawPath(const GrPath* path) : Cmd(kDrawPath_Cmd), fPath(path) {} | |
| 170 | |
| 171 const GrPath* path() const { return fPath.get(); } | |
| 172 | |
| 173 void execute(GrGpu*, const SetState*) SK_OVERRIDE; | |
| 174 | |
| 175 GrStencilSettings fStencilSettings; | |
| 176 | |
| 177 private: | |
| 178 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; | |
| 179 }; | |
| 180 | |
| 181 struct DrawPaths : public Cmd { | |
| 182 DrawPaths(const GrPathRange* pathRange) : Cmd(kDrawPaths_Cmd), fPathRang
e(pathRange) {} | |
| 183 | |
| 184 const GrPathRange* pathRange() const { return fPathRange.get(); } | |
| 185 | |
| 186 void execute(GrGpu*, const SetState*) SK_OVERRIDE; | |
| 187 | |
| 188 char* fIndices; | |
| 189 GrDrawTarget::PathIndexType fIndexType; | |
| 190 float* fTransforms; | |
| 191 GrDrawTarget::PathTransformType fTransformType; | |
| 192 int fCount; | |
| 193 GrStencilSettings fStencilSettings; | |
| 194 | |
| 195 private: | |
| 196 GrPendingIOResource<const GrPathRange, kRead_GrIOType> fPathRange; | |
| 197 }; | |
| 198 | |
| 199 // This is also used to record a discard by setting the color to GrColor_ILL
EGAL | |
| 200 struct Clear : public Cmd { | |
| 201 Clear(GrRenderTarget* rt) : Cmd(kClear_Cmd), fRenderTarget(rt) {} | |
| 202 | |
| 203 GrRenderTarget* renderTarget() const { return fRenderTarget.get(); } | |
| 204 | |
| 205 void execute(GrGpu*, const SetState*) SK_OVERRIDE; | |
| 206 | |
| 207 SkIRect fRect; | |
| 208 GrColor fColor; | |
| 209 bool fCanIgnoreRect; | |
| 210 | |
| 211 private: | |
| 212 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; | |
| 213 }; | |
| 214 | |
| 215 // This command is ONLY used by the clip mask manager to clear the stencil c
lip bits | |
| 216 struct ClearStencilClip : public Cmd { | |
| 217 ClearStencilClip(GrRenderTarget* rt) : Cmd(kClear_Cmd), fRenderTarget(rt
) {} | |
| 218 | |
| 219 GrRenderTarget* renderTarget() const { return fRenderTarget.get(); } | |
| 220 | |
| 221 void execute(GrGpu*, const SetState*) SK_OVERRIDE; | |
| 222 | |
| 223 SkIRect fRect; | |
| 224 bool fInsideClip; | |
| 225 | |
| 226 private: | |
| 227 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; | |
| 228 }; | |
| 229 | |
| 230 struct CopySurface : public Cmd { | |
| 231 CopySurface(GrSurface* dst, GrSurface* src) : Cmd(kCopySurface_Cmd), fDs
t(dst), fSrc(src) {} | |
| 232 | |
| 233 GrSurface* dst() const { return fDst.get(); } | |
| 234 GrSurface* src() const { return fSrc.get(); } | |
| 235 | |
| 236 void execute(GrGpu*, const SetState*) SK_OVERRIDE; | |
| 237 | |
| 238 SkIPoint fDstPoint; | |
| 239 SkIRect fSrcRect; | |
| 240 | |
| 241 private: | |
| 242 GrPendingIOResource<GrSurface, kWrite_GrIOType> fDst; | |
| 243 GrPendingIOResource<GrSurface, kRead_GrIOType> fSrc; | |
| 244 }; | |
| 245 | |
| 246 // TODO: rename to SetPipeline once pp, batch tracker, and desc are removed | |
| 247 struct SetState : public Cmd { | |
| 248 // TODO get rid of the prim proc parameter when we use batch everywhere | |
| 249 SetState(const GrPrimitiveProcessor* primProc = NULL) | |
| 250 : Cmd(kSetState_Cmd) | |
| 251 , fPrimitiveProcessor(primProc) {} | |
| 252 | |
| 253 ~SetState() { reinterpret_cast<GrPipeline*>(fPipeline.get())->~GrPipelin
e(); } | |
| 254 | |
| 255 // This function is only for getting the location in memory where we wil
l create our | |
| 256 // pipeline object. | |
| 257 GrPipeline* pipelineLocation() { return reinterpret_cast<GrPipeline*>(fP
ipeline.get()); } | |
| 258 | |
| 259 const GrPipeline* getPipeline() const { | |
| 260 return reinterpret_cast<const GrPipeline*>(fPipeline.get()); | |
| 261 } | |
| 262 | |
| 263 void execute(GrGpu*, const SetState*) SK_OVERRIDE; | |
| 264 | |
| 265 typedef GrPendingProgramElement<const GrPrimitiveProcessor> ProgramPrimi
tiveProcessor; | |
| 266 ProgramPrimitiveProcessor fPrimitiveProcessor; | |
| 267 SkAlignedSStorage<sizeof(GrPipeline)> fPipeline; | |
| 268 GrProgramDesc fDesc; | |
| 269 GrBatchTracker fBatchTracker; | |
| 270 }; | |
| 271 | |
| 272 struct DrawBatch : public Cmd { | |
| 273 DrawBatch(GrBatch* batch, GrBatchTarget* batchTarget) | |
| 274 : Cmd(kDrawBatch_Cmd) | |
| 275 , fBatch(SkRef(batch)) | |
| 276 , fBatchTarget(batchTarget) { | |
| 277 SkASSERT(!batch->isUsed()); | |
| 278 } | |
| 279 | |
| 280 void execute(GrGpu*, const SetState*) SK_OVERRIDE; | |
| 281 | |
| 282 // TODO it wouldn't be too hard to let batches allocate in the cmd buffe
r | |
| 283 SkAutoTUnref<GrBatch> fBatch; | |
| 284 | |
| 285 private: | |
| 286 GrBatchTarget* fBatchTarget; | |
| 287 }; | |
| 288 | |
| 289 static const int kCmdBufferInitialSizeInBytes = 8 * 1024; | |
| 290 | |
| 291 typedef void* TCmdAlign; // This wouldn't be enough align if a command used
long double. | |
| 292 typedef GrTRecorder<Cmd, TCmdAlign> CmdBuffer; | |
| 293 | |
| 294 CmdBuffer fCmdBuffer; | |
| 295 SetState* fPrevState; | |
| 296 GrBatchTarget fBatchTarget; | |
| 297 // TODO hack until batch is everywhere | |
| 298 GrTargetCommands::DrawBatch* fDrawBatch; | |
| 299 | |
| 300 // This will go away when everything uses batch. However, in the short ter
m anything which | |
| 301 // might be put into the GrInOrderDrawBuffer needs to make sure it closes t
he last batch | |
| 302 void closeBatch(); | |
| 303 }; | |
| 304 | 14 |
| 305 /** | 15 /** |
| 306 * GrInOrderDrawBuffer is an implementation of GrDrawTarget that queues up draws
for eventual | 16 * GrInOrderDrawBuffer is an implementation of GrDrawTarget that queues up draws
for eventual |
| 307 * playback into a GrGpu. In theory one draw buffer could playback into another.
When index or | 17 * playback into a GrGpu. In theory one draw buffer could playback into another.
When index or |
| 308 * vertex buffers are used as geometry sources it is the callers the draw buffer
only holds | 18 * vertex buffers are used as geometry sources it is the callers the draw buffer
only holds |
| 309 * references to the buffers. It is the callers responsibility to ensure that th
e data is still | 19 * references to the buffers. It is the callers responsibility to ensure that th
e data is still |
| 310 * valid when the draw buffer is played back into a GrGpu. Similarly, it is the
caller's | 20 * valid when the draw buffer is played back into a GrGpu. Similarly, it is the
caller's |
| 311 * responsibility to ensure that all referenced textures, buffers, and render-ta
rgets are associated | 21 * responsibility to ensure that all referenced textures, buffers, and render-ta
rgets are associated |
| 312 * in the GrGpu object that the buffer is played back into. The buffer requires
VB and IB pools to | 22 * in the GrGpu object that the buffer is played back into. The buffer requires
VB and IB pools to |
| 313 * store geometry. | 23 * store geometry. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 return false; | 85 return false; |
| 376 } | 86 } |
| 377 | 87 |
| 378 *ib = geomSrc.fIndexBuffer; | 88 *ib = geomSrc.fIndexBuffer; |
| 379 return true; | 89 return true; |
| 380 } | 90 } |
| 381 | 91 |
| 382 private: | 92 private: |
| 383 friend class GrTargetCommands; | 93 friend class GrTargetCommands; |
| 384 | 94 |
| 385 typedef GrGpu::DrawArgs DrawArgs; | |
| 386 | |
| 387 void onReset() SK_OVERRIDE; | 95 void onReset() SK_OVERRIDE; |
| 388 void onFlush() SK_OVERRIDE; | 96 void onFlush() SK_OVERRIDE; |
| 389 | 97 |
| 390 // overrides from GrDrawTarget | 98 // overrides from GrDrawTarget |
| 391 void onDraw(const GrGeometryProcessor*, const DrawInfo&, const PipelineInfo&
) SK_OVERRIDE; | 99 void onDraw(const GrGeometryProcessor*, const DrawInfo&, const PipelineInfo&
) SK_OVERRIDE; |
| 392 void onDrawBatch(GrBatch*, const PipelineInfo&) SK_OVERRIDE; | 100 void onDrawBatch(GrBatch*, const PipelineInfo&) SK_OVERRIDE; |
| 393 void onDrawRect(GrPipelineBuilder*, | 101 void onDrawRect(GrPipelineBuilder*, |
| 394 GrColor, | 102 GrColor, |
| 395 const SkMatrix& viewMatrix, | 103 const SkMatrix& viewMatrix, |
| 396 const SkRect& rect, | 104 const SkRect& rect, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 GrTargetCommands fCommands; | 155 GrTargetCommands fCommands; |
| 448 SkTArray<GrTraceMarkerSet, false> fGpuCmdMarkers; | 156 SkTArray<GrTraceMarkerSet, false> fGpuCmdMarkers; |
| 449 SkChunkAlloc fPathIndexBuffer; | 157 SkChunkAlloc fPathIndexBuffer; |
| 450 SkChunkAlloc fPathTransformBuffer; | 158 SkChunkAlloc fPathTransformBuffer; |
| 451 uint32_t fDrawID; | 159 uint32_t fDrawID; |
| 452 | 160 |
| 453 typedef GrFlushToGpuDrawTarget INHERITED; | 161 typedef GrFlushToGpuDrawTarget INHERITED; |
| 454 }; | 162 }; |
| 455 | 163 |
| 456 #endif | 164 #endif |
| OLD | NEW |