| 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 "GrDrawTarget.h" | 11 #include "GrDrawTarget.h" |
| 12 #include "GrAllocPool.h" | 12 #include "GrAllocPool.h" |
| 13 #include "GrAllocator.h" | 13 #include "GrAllocator.h" |
| 14 #include "GrIndexBuffer.h" |
| 15 #include "GrRenderTarget.h" |
| 14 #include "GrPath.h" | 16 #include "GrPath.h" |
| 17 #include "GrPathRange.h" |
| 18 #include "GrSurface.h" |
| 19 #include "GrVertexBuffer.h" |
| 15 | 20 |
| 16 #include "SkClipStack.h" | 21 #include "SkClipStack.h" |
| 17 #include "SkTemplates.h" | 22 #include "SkTemplates.h" |
| 18 #include "SkTypes.h" | 23 #include "SkTypes.h" |
| 19 | 24 |
| 20 class GrGpu; | 25 class GrGpu; |
| 21 class GrIndexBufferAllocPool; | 26 class GrIndexBufferAllocPool; |
| 22 class GrPathRange; | |
| 23 class GrVertexBufferAllocPool; | 27 class GrVertexBufferAllocPool; |
| 24 | 28 |
| 25 /** | 29 /** |
| 26 * GrInOrderDrawBuffer is an implementation of GrDrawTarget that queues up draws
for eventual | 30 * GrInOrderDrawBuffer is an implementation of GrDrawTarget that queues up draws
for eventual |
| 27 * playback into a GrGpu. In theory one draw buffer could playback into another.
When index or | 31 * playback into a GrGpu. In theory one draw buffer could playback into another.
When index or |
| 28 * vertex buffers are used as geometry sources it is the callers the draw buffer
only holds | 32 * vertex buffers are used as geometry sources it is the callers the draw buffer
only holds |
| 29 * references to the buffers. It is the callers responsibility to ensure that th
e data is still | 33 * references to the buffers. It is the callers responsibility to ensure that th
e data is still |
| 30 * valid when the draw buffer is played back into a GrGpu. Similarly, it is the
caller's | 34 * valid when the draw buffer is played back into a GrGpu. Similarly, it is the
caller's |
| 31 * responsibility to ensure that all referenced textures, buffers, and render-ta
rgets are associated | 35 * responsibility to ensure that all referenced textures, buffers, and render-ta
rgets are associated |
| 32 * in the GrGpu object that the buffer is played back into. The buffer requires
VB and IB pools to | 36 * in the GrGpu object that the buffer is played back into. The buffer requires
VB and IB pools to |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 kDraw_Cmd = 1, | 91 kDraw_Cmd = 1, |
| 88 kStencilPath_Cmd = 2, | 92 kStencilPath_Cmd = 2, |
| 89 kSetState_Cmd = 3, | 93 kSetState_Cmd = 3, |
| 90 kSetClip_Cmd = 4, | 94 kSetClip_Cmd = 4, |
| 91 kClear_Cmd = 5, | 95 kClear_Cmd = 5, |
| 92 kCopySurface_Cmd = 6, | 96 kCopySurface_Cmd = 6, |
| 93 kDrawPath_Cmd = 7, | 97 kDrawPath_Cmd = 7, |
| 94 kDrawPaths_Cmd = 8, | 98 kDrawPaths_Cmd = 8, |
| 95 }; | 99 }; |
| 96 | 100 |
| 97 class DrawRecord : public DrawInfo { | 101 class Draw : public DrawInfo { |
| 98 public: | 102 public: |
| 99 DrawRecord(const DrawInfo& info) : DrawInfo(info) {} | 103 Draw(const DrawInfo& info, const GrVertexBuffer* vb, const GrIndexBuffer
* ib) |
| 100 const GrVertexBuffer* fVertexBuffer; | 104 : DrawInfo(info) |
| 101 const GrIndexBuffer* fIndexBuffer; | 105 , fVertexBuffer(vb, GrGpuResourceRef::kRead_IOType) |
| 106 , fIndexBuffer(ib, GrGpuResourceRef::kRead_IOType) {} |
| 107 |
| 108 const GrVertexBuffer* vertexBuffer() const { return fVertexBuffer.get();
} |
| 109 const GrIndexBuffer* indexBuffer() const { return fIndexBuffer.get(); } |
| 110 |
| 111 private: |
| 112 GrPendingIOResource<const GrVertexBuffer> fVertexBuffer; |
| 113 GrPendingIOResource<const GrIndexBuffer> fIndexBuffer; |
| 102 }; | 114 }; |
| 103 | 115 |
| 104 struct StencilPath : public ::SkNoncopyable { | 116 struct StencilPath : public ::SkNoncopyable { |
| 105 StencilPath(); | 117 StencilPath(const GrPath* path) : fPath(path, GrGpuResourceRef::kRead_IO
Type) {} |
| 106 | 118 |
| 107 SkAutoTUnref<const GrPath> fPath; | 119 const GrPath* path() const { return fPath.get(); } |
| 108 SkPath::FillType fFill; | 120 |
| 121 SkPath::FillType fFill; |
| 122 |
| 123 private: |
| 124 GrPendingIOResource<const GrPath> fPath; |
| 109 }; | 125 }; |
| 110 | 126 |
| 111 struct DrawPath : public ::SkNoncopyable { | 127 struct DrawPath : public ::SkNoncopyable { |
| 112 DrawPath(); | 128 DrawPath(const GrPath* path) : fPath(path, GrGpuResourceRef::kRead_IOTyp
e) {} |
| 113 | 129 |
| 114 SkAutoTUnref<const GrPath> fPath; | 130 const GrPath* path() const { return fPath.get(); } |
| 115 SkPath::FillType fFill; | 131 |
| 116 GrDeviceCoordTexture fDstCopy; | 132 SkPath::FillType fFill; |
| 133 GrDeviceCoordTexture fDstCopy; |
| 134 |
| 135 private: |
| 136 GrPendingIOResource<const GrPath> fPath; |
| 117 }; | 137 }; |
| 118 | 138 |
| 119 struct DrawPaths : public ::SkNoncopyable { | 139 struct DrawPaths : public ::SkNoncopyable { |
| 120 DrawPaths(); | 140 DrawPaths(const GrPathRange* pathRange) |
| 121 ~DrawPaths(); | 141 : fPathRange(pathRange, GrGpuResourceRef::kRead_IOType) {} |
| 122 | 142 |
| 123 SkAutoTUnref<const GrPathRange> fPathRange; | 143 ~DrawPaths() { |
| 124 uint32_t* fIndices; | 144 if (fTransforms) { |
| 125 size_t fCount; | 145 SkDELETE_ARRAY(fTransforms); |
| 126 float* fTransforms; | 146 } |
| 127 PathTransformType fTransformsType; | 147 if (fIndices) { |
| 128 SkPath::FillType fFill; | 148 SkDELETE_ARRAY(fIndices); |
| 129 GrDeviceCoordTexture fDstCopy; | 149 } |
| 150 } |
| 151 |
| 152 const GrPathRange* pathRange() const { return fPathRange.get(); } |
| 153 |
| 154 uint32_t* fIndices; |
| 155 size_t fCount; |
| 156 float* fTransforms; |
| 157 PathTransformType fTransformsType; |
| 158 SkPath::FillType fFill; |
| 159 GrDeviceCoordTexture fDstCopy; |
| 160 |
| 161 private: |
| 162 GrPendingIOResource<const GrPathRange> fPathRange; |
| 130 }; | 163 }; |
| 131 | 164 |
| 132 // This is also used to record a discard by setting the color to GrColor_ILL
EGAL | 165 // This is also used to record a discard by setting the color to GrColor_ILL
EGAL |
| 133 struct Clear : public ::SkNoncopyable { | 166 struct Clear : public ::SkNoncopyable { |
| 134 Clear() : fRenderTarget(NULL) {} | 167 Clear(GrRenderTarget* rt) : fRenderTarget(rt, GrGpuResourceRef::kWrite_I
OType) {} |
| 135 ~Clear() { SkSafeUnref(fRenderTarget); } | 168 ~Clear() { } |
| 169 GrRenderTarget* renderTarget() const { return fRenderTarget.get(); } |
| 136 | 170 |
| 137 SkIRect fRect; | 171 SkIRect fRect; |
| 138 GrColor fColor; | 172 GrColor fColor; |
| 139 bool fCanIgnoreRect; | 173 bool fCanIgnoreRect; |
| 140 GrRenderTarget* fRenderTarget; | 174 |
| 175 private: |
| 176 GrPendingIOResource<GrRenderTarget> fRenderTarget; |
| 141 }; | 177 }; |
| 142 | 178 |
| 143 struct CopySurface : public ::SkNoncopyable { | 179 struct CopySurface : public ::SkNoncopyable { |
| 144 SkAutoTUnref<GrSurface> fDst; | 180 CopySurface(GrSurface* dst, GrSurface* src) |
| 145 SkAutoTUnref<GrSurface> fSrc; | 181 : fDst(dst, GrGpuResourceRef::kWrite_IOType) |
| 146 SkIRect fSrcRect; | 182 , fSrc(src, GrGpuResourceRef::kRead_IOType) {} |
| 147 SkIPoint fDstPoint; | 183 |
| 184 GrSurface* dst() const { return fDst.get(); } |
| 185 GrSurface* src() const { return fSrc.get(); } |
| 186 |
| 187 SkIPoint fDstPoint; |
| 188 SkIRect fSrcRect; |
| 189 |
| 190 private: |
| 191 GrPendingIOResource<GrSurface> fDst; |
| 192 GrPendingIOResource<GrSurface> fSrc; |
| 148 }; | 193 }; |
| 149 | 194 |
| 150 struct Clip : public ::SkNoncopyable { | 195 struct Clip : public ::SkNoncopyable { |
| 151 SkClipStack fStack; | 196 SkClipStack fStack; |
| 152 SkIPoint fOrigin; | 197 SkIPoint fOrigin; |
| 153 }; | 198 }; |
| 154 | 199 |
| 155 // overrides from GrDrawTarget | 200 // overrides from GrDrawTarget |
| 156 virtual void onDraw(const DrawInfo&) SK_OVERRIDE; | 201 virtual void onDraw(const DrawInfo&) SK_OVERRIDE; |
| 157 virtual void onDrawRect(const SkRect& rect, | 202 virtual void onDrawRect(const SkRect& rect, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 int concatInstancedDraw(const DrawInfo& info); | 247 int concatInstancedDraw(const DrawInfo& info); |
| 203 | 248 |
| 204 // Determines whether the current draw operation requieres a new drawstate a
nd if so records it. | 249 // Determines whether the current draw operation requieres a new drawstate a
nd if so records it. |
| 205 void recordStateIfNecessary(); | 250 void recordStateIfNecessary(); |
| 206 // We lazily record clip changes in order to skip clips that have no effect. | 251 // We lazily record clip changes in order to skip clips that have no effect. |
| 207 bool needsNewClip() const; | 252 bool needsNewClip() const; |
| 208 | 253 |
| 209 // these functions record a command | 254 // these functions record a command |
| 210 void recordState(); | 255 void recordState(); |
| 211 void recordClip(); | 256 void recordClip(); |
| 212 DrawRecord* recordDraw(const DrawInfo&); | 257 Draw* recordDraw(const DrawInfo&, const GrVertexBuffer*, const GrI
ndexBuffer*); |
| 213 StencilPath* recordStencilPath(); | 258 StencilPath* recordStencilPath(const GrPath*); |
| 214 DrawPath* recordDrawPath(); | 259 DrawPath* recordDrawPath(const GrPath*); |
| 215 DrawPaths* recordDrawPaths(); | 260 DrawPaths* recordDrawPaths(const GrPathRange*); |
| 216 Clear* recordClear(); | 261 Clear* recordClear(GrRenderTarget*); |
| 217 CopySurface* recordCopySurface(); | 262 CopySurface* recordCopySurface(GrSurface* dst, GrSurface* src); |
| 263 |
| 264 virtual bool isIssued(uint32_t drawID) { return drawID != fDrawID; } |
| 265 void addToCmdBuffer(uint8_t cmd); |
| 218 | 266 |
| 219 // TODO: Use a single allocator for commands and records | 267 // TODO: Use a single allocator for commands and records |
| 220 enum { | 268 enum { |
| 221 kCmdPreallocCnt = 32, | 269 kCmdPreallocCnt = 32, |
| 222 kDrawPreallocCnt = 16, | 270 kDrawPreallocCnt = 16, |
| 223 kStencilPathPreallocCnt = 8, | 271 kStencilPathPreallocCnt = 8, |
| 224 kDrawPathPreallocCnt = 8, | 272 kDrawPathPreallocCnt = 8, |
| 225 kDrawPathsPreallocCnt = 8, | 273 kDrawPathsPreallocCnt = 8, |
| 226 kStatePreallocCnt = 8, | 274 kStatePreallocCnt = 8, |
| 227 kClipPreallocCnt = 8, | 275 kClipPreallocCnt = 8, |
| 228 kClearPreallocCnt = 8, | 276 kClearPreallocCnt = 8, |
| 229 kGeoPoolStatePreAllocCnt = 4, | 277 kGeoPoolStatePreAllocCnt = 4, |
| 230 kCopySurfacePreallocCnt = 4, | 278 kCopySurfacePreallocCnt = 4, |
| 231 }; | 279 }; |
| 232 | 280 |
| 233 typedef GrTAllocator<DrawRecord> DrawAllocator; | 281 typedef GrTAllocator<Draw> DrawAllocator; |
| 234 typedef GrTAllocator<StencilPath> StencilPathAllocator
; | 282 typedef GrTAllocator<StencilPath> StencilPathAllocator; |
| 235 typedef GrTAllocator<DrawPath> DrawPathAllocator; | 283 typedef GrTAllocator<DrawPath> DrawPathAllocator; |
| 236 typedef GrTAllocator<DrawPaths> DrawPathsAllocator; | 284 typedef GrTAllocator<DrawPaths> DrawPathsAllocator; |
| 237 typedef GrTAllocator<GrDrawState> StateAllocator; | 285 typedef GrTAllocator<GrDrawState> StateAllocator; |
| 238 typedef GrTAllocator<Clear> ClearAllocator; | 286 typedef GrTAllocator<Clear> ClearAllocator; |
| 239 typedef GrTAllocator<CopySurface> CopySurfaceAllocator
; | 287 typedef GrTAllocator<CopySurface> CopySurfaceAllocator; |
| 240 typedef GrTAllocator<Clip> ClipAllocator; | 288 typedef GrTAllocator<Clip> ClipAllocator; |
| 241 | 289 |
| 242 GrSTAllocator<kDrawPreallocCnt, DrawRecord> fDraws; | 290 GrSTAllocator<kDrawPreallocCnt, Draw> fDraws; |
| 243 GrSTAllocator<kStencilPathPreallocCnt, StencilPath> fStencilP
aths; | 291 GrSTAllocator<kStencilPathPreallocCnt, StencilPath> fStencilPaths; |
| 244 GrSTAllocator<kDrawPathPreallocCnt, DrawPath> fDrawPath
; | 292 GrSTAllocator<kDrawPathPreallocCnt, DrawPath> fDrawPath; |
| 245 GrSTAllocator<kDrawPathsPreallocCnt, DrawPaths> fDrawPath
s; | 293 GrSTAllocator<kDrawPathsPreallocCnt, DrawPaths> fDrawPaths; |
| 246 GrSTAllocator<kStatePreallocCnt, GrDrawState> fStates; | 294 GrSTAllocator<kStatePreallocCnt, GrDrawState> fStates; |
| 247 GrSTAllocator<kClearPreallocCnt, Clear> fClears; | 295 GrSTAllocator<kClearPreallocCnt, Clear> fClears; |
| 248 GrSTAllocator<kCopySurfacePreallocCnt, CopySurface> fCopySurf
aces; | 296 GrSTAllocator<kCopySurfacePreallocCnt, CopySurface> fCopySurfaces; |
| 249 GrSTAllocator<kClipPreallocCnt, Clip> fClips; | 297 GrSTAllocator<kClipPreallocCnt, Clip> fClips; |
| 250 | 298 |
| 251 SkTArray<GrTraceMarkerSet, false> fGpuCmdMa
rkers; | 299 SkTArray<GrTraceMarkerSet, false> fGpuCmdMarkers; |
| 252 | 300 SkSTArray<kCmdPreallocCnt, uint8_t, true> fCmds; |
| 253 SkSTArray<kCmdPreallocCnt, uint8_t, true> fCmds; | 301 GrDrawTarget* fDstGpu; |
| 254 | 302 bool fClipSet; |
| 255 GrDrawTarget* fDstGpu; | |
| 256 | |
| 257 bool fClipSet; | |
| 258 | 303 |
| 259 enum ClipProxyState { | 304 enum ClipProxyState { |
| 260 kUnknown_ClipProxyState, | 305 kUnknown_ClipProxyState, |
| 261 kValid_ClipProxyState, | 306 kValid_ClipProxyState, |
| 262 kInvalid_ClipProxyState | 307 kInvalid_ClipProxyState |
| 263 }; | 308 }; |
| 264 ClipProxyState fClipProxyState; | |
| 265 SkRect fClipProxy; | |
| 266 | 309 |
| 267 GrVertexBufferAllocPool& fVertexPool; | 310 ClipProxyState fClipProxyState; |
| 268 | 311 SkRect fClipProxy; |
| 269 GrIndexBufferAllocPool& fIndexPool; | 312 GrVertexBufferAllocPool& fVertexPool; |
| 313 GrIndexBufferAllocPool& fIndexPool; |
| 270 | 314 |
| 271 struct GeometryPoolState { | 315 struct GeometryPoolState { |
| 272 const GrVertexBuffer* fPoolVertexBuffer; | 316 const GrVertexBuffer* fPoolVertexBuffer; |
| 273 int fPoolStartVertex; | 317 int fPoolStartVertex; |
| 274 const GrIndexBuffer* fPoolIndexBuffer; | 318 const GrIndexBuffer* fPoolIndexBuffer; |
| 275 int fPoolStartIndex; | 319 int fPoolStartIndex; |
| 276 // caller may conservatively over reserve vertices / indices. | 320 // caller may conservatively over reserve vertices / indices. |
| 277 // we release unused space back to allocator if possible | 321 // we release unused space back to allocator if possible |
| 278 // can only do this if there isn't an intervening pushGeometrySource() | 322 // can only do this if there isn't an intervening pushGeometrySource() |
| 279 size_t fUsedPoolVertexBytes; | 323 size_t fUsedPoolVertexBytes; |
| 280 size_t fUsedPoolIndexBytes; | 324 size_t fUsedPoolIndexBytes; |
| 281 }; | 325 }; |
| 282 SkSTArray<kGeoPoolStatePreAllocCnt, GeometryPoolState> fGeoPoolStateStack; | |
| 283 | 326 |
| 284 virtual bool isIssued(uint32_t drawID) { return drawID != fDrawID; } | 327 typedef SkSTArray<kGeoPoolStatePreAllocCnt, GeometryPoolState> GeoPoolStateS
tack; |
| 285 | 328 |
| 286 void addToCmdBuffer(uint8_t cmd); | 329 GeoPoolStateStack fGeoPoolStateStack; |
| 287 | 330 bool fFlushing; |
| 288 bool fFlushing; | 331 uint32_t fDrawID; |
| 289 uint32_t fDrawID; | |
| 290 | 332 |
| 291 typedef GrDrawTarget INHERITED; | 333 typedef GrDrawTarget INHERITED; |
| 292 }; | 334 }; |
| 293 | 335 |
| 294 #endif | 336 #endif |
| OLD | NEW |