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 "GrCmdBuffer.h" |
14 #include "GrIndexBuffer.h" | 15 #include "GrIndexBuffer.h" |
15 #include "GrRenderTarget.h" | 16 #include "GrRenderTarget.h" |
16 #include "GrPath.h" | 17 #include "GrPath.h" |
17 #include "GrPathRange.h" | 18 #include "GrPathRange.h" |
18 #include "GrSurface.h" | 19 #include "GrSurface.h" |
19 #include "GrVertexBuffer.h" | 20 #include "GrVertexBuffer.h" |
20 | 21 |
21 #include "SkClipStack.h" | 22 #include "SkClipStack.h" |
22 #include "SkTemplates.h" | 23 #include "SkTemplates.h" |
23 #include "SkTypes.h" | 24 #include "SkTypes.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 GrRenderTarget* renderTarget) SK_OVERRIDE; | 81 GrRenderTarget* renderTarget) SK_OVERRIDE; |
81 | 82 |
82 virtual void discard(GrRenderTarget*) SK_OVERRIDE; | 83 virtual void discard(GrRenderTarget*) SK_OVERRIDE; |
83 | 84 |
84 virtual void initCopySurfaceDstDesc(const GrSurface* src, GrTextureDesc* des
c) SK_OVERRIDE; | 85 virtual void initCopySurfaceDstDesc(const GrSurface* src, GrTextureDesc* des
c) SK_OVERRIDE; |
85 | 86 |
86 protected: | 87 protected: |
87 virtual void clipWillBeSet(const GrClipData* newClip) SK_OVERRIDE; | 88 virtual void clipWillBeSet(const GrClipData* newClip) SK_OVERRIDE; |
88 | 89 |
89 private: | 90 private: |
90 enum Cmd { | 91 enum { |
91 kDraw_Cmd = 1, | 92 kDraw_Cmd = 1, |
92 kStencilPath_Cmd = 2, | 93 kStencilPath_Cmd = 2, |
93 kSetState_Cmd = 3, | 94 kSetState_Cmd = 3, |
94 kSetClip_Cmd = 4, | 95 kSetClip_Cmd = 4, |
95 kClear_Cmd = 5, | 96 kClear_Cmd = 5, |
96 kCopySurface_Cmd = 6, | 97 kCopySurface_Cmd = 6, |
97 kDrawPath_Cmd = 7, | 98 kDrawPath_Cmd = 7, |
98 kDrawPaths_Cmd = 8, | 99 kDrawPaths_Cmd = 8, |
99 }; | 100 }; |
100 | 101 |
101 class Draw : public DrawInfo { | 102 typedef void* TCmdAlign; // This wouldn't be enough align if a command used
long double. |
| 103 typedef GrCmdBuffer<TCmdAlign> CmdBuffer; |
| 104 |
| 105 class Draw : public DrawInfo, public CmdBuffer::Cmd { |
102 public: | 106 public: |
| 107 enum { kCmdType = kDraw_Cmd }; |
103 Draw(const DrawInfo& info, const GrVertexBuffer* vb, const GrIndexBuffer
* ib) | 108 Draw(const DrawInfo& info, const GrVertexBuffer* vb, const GrIndexBuffer
* ib) |
104 : DrawInfo(info) | 109 : DrawInfo(info) |
105 , fVertexBuffer(vb) | 110 , fVertexBuffer(vb) |
106 , fIndexBuffer(ib) {} | 111 , fIndexBuffer(ib) {} |
107 | 112 |
108 const GrVertexBuffer* vertexBuffer() const { return fVertexBuffer.get();
} | 113 const GrVertexBuffer* vertexBuffer() const { return fVertexBuffer.get();
} |
109 const GrIndexBuffer* indexBuffer() const { return fIndexBuffer.get(); } | 114 const GrIndexBuffer* indexBuffer() const { return fIndexBuffer.get(); } |
110 | 115 |
| 116 virtual void execute(GrDrawTarget*); |
| 117 |
111 private: | 118 private: |
112 GrPendingIOResource<const GrVertexBuffer, GrIORef::kRead_IOType> fVer
texBuffer; | 119 GrPendingIOResource<const GrVertexBuffer, GrIORef::kRead_IOType> fVer
texBuffer; |
113 GrPendingIOResource<const GrIndexBuffer, GrIORef::kRead_IOType> fInd
exBuffer; | 120 GrPendingIOResource<const GrIndexBuffer, GrIORef::kRead_IOType> fInd
exBuffer; |
114 }; | 121 }; |
115 | 122 |
116 struct StencilPath : public ::SkNoncopyable { | 123 struct StencilPath : public CmdBuffer::Cmd { |
| 124 enum { kCmdType = kStencilPath_Cmd }; |
117 StencilPath(const GrPath* path) : fPath(path) {} | 125 StencilPath(const GrPath* path) : fPath(path) {} |
118 | 126 |
119 const GrPath* path() const { return fPath.get(); } | 127 const GrPath* path() const { return fPath.get(); } |
120 | 128 |
| 129 virtual void execute(GrDrawTarget*); |
| 130 |
121 SkPath::FillType fFill; | 131 SkPath::FillType fFill; |
122 | 132 |
123 private: | 133 private: |
124 GrPendingIOResource<const GrPath, GrIORef::kRead_IOType> fPath; | 134 GrPendingIOResource<const GrPath, GrIORef::kRead_IOType> fPath; |
125 }; | 135 }; |
126 | 136 |
127 struct DrawPath : public ::SkNoncopyable { | 137 struct DrawPath : public CmdBuffer::Cmd { |
| 138 enum { kCmdType = kDrawPath_Cmd }; |
128 DrawPath(const GrPath* path) : fPath(path) {} | 139 DrawPath(const GrPath* path) : fPath(path) {} |
129 | 140 |
130 const GrPath* path() const { return fPath.get(); } | 141 const GrPath* path() const { return fPath.get(); } |
131 | 142 |
| 143 virtual void execute(GrDrawTarget*); |
| 144 |
132 SkPath::FillType fFill; | 145 SkPath::FillType fFill; |
133 GrDeviceCoordTexture fDstCopy; | 146 GrDeviceCoordTexture fDstCopy; |
134 | 147 |
135 private: | 148 private: |
136 GrPendingIOResource<const GrPath, GrIORef::kRead_IOType> fPath; | 149 GrPendingIOResource<const GrPath, GrIORef::kRead_IOType> fPath; |
137 }; | 150 }; |
138 | 151 |
139 struct DrawPaths : public ::SkNoncopyable { | 152 struct DrawPaths : public CmdBuffer::Cmd { |
| 153 enum { kCmdType = kDrawPaths_Cmd }; |
140 DrawPaths(const GrPathRange* pathRange) | 154 DrawPaths(const GrPathRange* pathRange) |
141 : fPathRange(pathRange) {} | 155 : fPathRange(pathRange) {} |
142 | 156 |
143 ~DrawPaths() { | 157 const GrPathRange* pathRange() const { return fPathRange.get(); } |
144 if (fTransforms) { | 158 uint32_t* indices() { return fData; } |
145 SkDELETE_ARRAY(fTransforms); | 159 float* transforms() { return reinterpret_cast<float*>(&fData[fCount]); } |
146 } | |
147 if (fIndices) { | |
148 SkDELETE_ARRAY(fIndices); | |
149 } | |
150 } | |
151 | 160 |
152 const GrPathRange* pathRange() const { return fPathRange.get(); } | 161 virtual void execute(GrDrawTarget*); |
153 | 162 |
154 uint32_t* fIndices; | |
155 size_t fCount; | 163 size_t fCount; |
156 float* fTransforms; | |
157 PathTransformType fTransformsType; | 164 PathTransformType fTransformsType; |
158 SkPath::FillType fFill; | 165 SkPath::FillType fFill; |
159 GrDeviceCoordTexture fDstCopy; | 166 GrDeviceCoordTexture fDstCopy; |
160 | 167 |
161 private: | 168 private: |
162 GrPendingIOResource<const GrPathRange, GrIORef::kRead_IOType> fPathRange
; | 169 GrPendingIOResource<const GrPathRange, GrIORef::kRead_IOType> fPathRange
; |
| 170 uint32_t fData[0]; |
163 }; | 171 }; |
164 | 172 |
165 // This is also used to record a discard by setting the color to GrColor_ILL
EGAL | 173 // This is also used to record a discard by setting the color to GrColor_ILL
EGAL |
166 struct Clear : public ::SkNoncopyable { | 174 struct Clear : public CmdBuffer::Cmd { |
| 175 enum { kCmdType = kClear_Cmd }; |
167 Clear(GrRenderTarget* rt) : fRenderTarget(rt) {} | 176 Clear(GrRenderTarget* rt) : fRenderTarget(rt) {} |
168 ~Clear() { } | 177 |
169 GrRenderTarget* renderTarget() const { return fRenderTarget.get(); } | 178 GrRenderTarget* renderTarget() const { return fRenderTarget.get(); } |
170 | 179 |
| 180 virtual void execute(GrDrawTarget*); |
| 181 |
171 SkIRect fRect; | 182 SkIRect fRect; |
172 GrColor fColor; | 183 GrColor fColor; |
173 bool fCanIgnoreRect; | 184 bool fCanIgnoreRect; |
174 | 185 |
175 private: | 186 private: |
176 GrPendingIOResource<GrRenderTarget, GrIORef::kWrite_IOType> fRenderTarge
t; | 187 GrPendingIOResource<GrRenderTarget, GrIORef::kWrite_IOType> fRenderTarge
t; |
177 }; | 188 }; |
178 | 189 |
179 struct CopySurface : public ::SkNoncopyable { | 190 struct CopySurface : public CmdBuffer::Cmd { |
| 191 enum { kCmdType = kCopySurface_Cmd }; |
180 CopySurface(GrSurface* dst, GrSurface* src) : fDst(dst), fSrc(src) {} | 192 CopySurface(GrSurface* dst, GrSurface* src) : fDst(dst), fSrc(src) {} |
181 | 193 |
182 GrSurface* dst() const { return fDst.get(); } | 194 GrSurface* dst() const { return fDst.get(); } |
183 GrSurface* src() const { return fSrc.get(); } | 195 GrSurface* src() const { return fSrc.get(); } |
184 | 196 |
| 197 virtual void execute(GrDrawTarget*); |
| 198 |
185 SkIPoint fDstPoint; | 199 SkIPoint fDstPoint; |
186 SkIRect fSrcRect; | 200 SkIRect fSrcRect; |
187 | 201 |
188 private: | 202 private: |
189 GrPendingIOResource<GrSurface, GrIORef::kWrite_IOType> fDst; | 203 GrPendingIOResource<GrSurface, GrIORef::kWrite_IOType> fDst; |
190 GrPendingIOResource<GrSurface, GrIORef::kRead_IOType> fSrc; | 204 GrPendingIOResource<GrSurface, GrIORef::kRead_IOType> fSrc; |
191 }; | 205 }; |
192 | 206 |
193 struct Clip : public ::SkNoncopyable { | 207 struct SetState : public CmdBuffer::Cmd { |
194 SkClipStack fStack; | 208 enum { kCmdType = kSetState_Cmd }; |
195 SkIPoint fOrigin; | 209 SetState(const GrDrawState& state) : fState(state) {} |
| 210 |
| 211 virtual void execute(GrDrawTarget*); |
| 212 |
| 213 GrDrawState fState; |
| 214 }; |
| 215 |
| 216 struct SetClip : public CmdBuffer::Cmd { |
| 217 enum { kCmdType = kSetClip_Cmd }; |
| 218 SetClip(const GrClipData* clipData) : fStackStorage(*clipData->fClipStac
k) { |
| 219 fClipData.fClipStack = &fStackStorage; |
| 220 fClipData.fOrigin = clipData->fOrigin; |
| 221 } |
| 222 |
| 223 virtual void execute(GrDrawTarget*); |
| 224 |
| 225 GrClipData fClipData; |
| 226 |
| 227 private: |
| 228 SkClipStack fStackStorage; |
196 }; | 229 }; |
197 | 230 |
198 // overrides from GrDrawTarget | 231 // overrides from GrDrawTarget |
199 virtual void onDraw(const DrawInfo&) SK_OVERRIDE; | 232 virtual void onDraw(const DrawInfo&) SK_OVERRIDE; |
200 virtual void onDrawRect(const SkRect& rect, | 233 virtual void onDrawRect(const SkRect& rect, |
201 const SkRect* localRect, | 234 const SkRect* localRect, |
202 const SkMatrix* localMatrix) SK_OVERRIDE; | 235 const SkMatrix* localMatrix) SK_OVERRIDE; |
203 | 236 |
204 virtual void onStencilPath(const GrPath*, SkPath::FillType) SK_OVERRIDE; | 237 virtual void onStencilPath(const GrPath*, SkPath::FillType) SK_OVERRIDE; |
205 virtual void onDrawPath(const GrPath*, SkPath::FillType, | 238 virtual void onDrawPath(const GrPath*, SkPath::FillType, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 virtual void didAddGpuTraceMarker() SK_OVERRIDE {} | 273 virtual void didAddGpuTraceMarker() SK_OVERRIDE {} |
241 virtual void didRemoveGpuTraceMarker() SK_OVERRIDE {} | 274 virtual void didRemoveGpuTraceMarker() SK_OVERRIDE {} |
242 | 275 |
243 // 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 |
244 // 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. |
245 int concatInstancedDraw(const DrawInfo& info); | 278 int concatInstancedDraw(const DrawInfo& info); |
246 | 279 |
247 // Determines whether the current draw operation requieres a new drawstate a
nd if so records it. | 280 // Determines whether the current draw operation requieres a new drawstate a
nd if so records it. |
248 void recordStateIfNecessary(); | 281 void recordStateIfNecessary(); |
249 // We lazily record clip changes in order to skip clips that have no effect. | 282 // We lazily record clip changes in order to skip clips that have no effect. |
250 bool needsNewClip() const; | 283 void recordClipIfNecessary(); |
251 | 284 // Records any trace markers for a command after adding it to the buffer. |
252 // these functions record a command | 285 void recordTraceMarkersIfNecessary(); |
253 void recordState(); | |
254 void recordClip(); | |
255 Draw* recordDraw(const DrawInfo&, const GrVertexBuffer*, const GrI
ndexBuffer*); | |
256 StencilPath* recordStencilPath(const GrPath*); | |
257 DrawPath* recordDrawPath(const GrPath*); | |
258 DrawPaths* recordDrawPaths(const GrPathRange*); | |
259 Clear* recordClear(GrRenderTarget*); | |
260 CopySurface* recordCopySurface(GrSurface* dst, GrSurface* src); | |
261 | 286 |
262 virtual bool isIssued(uint32_t drawID) { return drawID != fDrawID; } | 287 virtual bool isIssued(uint32_t drawID) { return drawID != fDrawID; } |
263 void addToCmdBuffer(uint8_t cmd); | |
264 | 288 |
265 // TODO: Use a single allocator for commands and records | 289 // TODO: Use a single allocator for commands and records |
266 enum { | 290 enum { |
267 kCmdPreallocCnt = 32, | 291 kCmdBufferInitialSizeInBytes = 64 * 1024, |
268 kDrawPreallocCnt = 16, | 292 kGeoPoolStatePreAllocCnt = 4, |
269 kStencilPathPreallocCnt = 8, | |
270 kDrawPathPreallocCnt = 8, | |
271 kDrawPathsPreallocCnt = 8, | |
272 kStatePreallocCnt = 8, | |
273 kClipPreallocCnt = 8, | |
274 kClearPreallocCnt = 8, | |
275 kGeoPoolStatePreAllocCnt = 4, | |
276 kCopySurfacePreallocCnt = 4, | |
277 }; | 293 }; |
278 | 294 |
279 typedef GrTAllocator<Draw> DrawAllocator; | 295 CmdBuffer fCmdBuffer; |
280 typedef GrTAllocator<StencilPath> StencilPathAllocator; | 296 GrDrawState* fLastState; |
281 typedef GrTAllocator<DrawPath> DrawPathAllocator; | 297 GrClipData* fLastClip; |
282 typedef GrTAllocator<DrawPaths> DrawPathsAllocator; | |
283 typedef GrTAllocator<GrDrawState> StateAllocator; | |
284 typedef GrTAllocator<Clear> ClearAllocator; | |
285 typedef GrTAllocator<CopySurface> CopySurfaceAllocator; | |
286 typedef GrTAllocator<Clip> ClipAllocator; | |
287 | 298 |
288 GrSTAllocator<kDrawPreallocCnt, Draw> fDraws; | 299 SkTArray<GrTraceMarkerSet, false> fGpuCmdMarkers; |
289 GrSTAllocator<kStencilPathPreallocCnt, StencilPath> fStencilPaths; | 300 GrDrawTarget* fDstGpu; |
290 GrSTAllocator<kDrawPathPreallocCnt, DrawPath> fDrawPath; | 301 bool fClipSet; |
291 GrSTAllocator<kDrawPathsPreallocCnt, DrawPaths> fDrawPaths; | |
292 GrSTAllocator<kStatePreallocCnt, GrDrawState> fStates; | |
293 GrSTAllocator<kClearPreallocCnt, Clear> fClears; | |
294 GrSTAllocator<kCopySurfacePreallocCnt, CopySurface> fCopySurfaces; | |
295 GrSTAllocator<kClipPreallocCnt, Clip> fClips; | |
296 | |
297 SkTArray<GrTraceMarkerSet, false> fGpuCmdMarkers; | |
298 SkSTArray<kCmdPreallocCnt, uint8_t, true> fCmds; | |
299 GrDrawTarget* fDstGpu; | |
300 bool fClipSet; | |
301 | 302 |
302 enum ClipProxyState { | 303 enum ClipProxyState { |
303 kUnknown_ClipProxyState, | 304 kUnknown_ClipProxyState, |
304 kValid_ClipProxyState, | 305 kValid_ClipProxyState, |
305 kInvalid_ClipProxyState | 306 kInvalid_ClipProxyState |
306 }; | 307 }; |
307 | 308 |
308 ClipProxyState fClipProxyState; | 309 ClipProxyState fClipProxyState; |
309 SkRect fClipProxy; | 310 SkRect fClipProxy; |
310 GrVertexBufferAllocPool& fVertexPool; | 311 GrVertexBufferAllocPool& fVertexPool; |
(...skipping 14 matching lines...) Expand all Loading... |
325 typedef SkSTArray<kGeoPoolStatePreAllocCnt, GeometryPoolState> GeoPoolStateS
tack; | 326 typedef SkSTArray<kGeoPoolStatePreAllocCnt, GeometryPoolState> GeoPoolStateS
tack; |
326 | 327 |
327 GeoPoolStateStack fGeoPoolStateStack; | 328 GeoPoolStateStack fGeoPoolStateStack; |
328 bool fFlushing; | 329 bool fFlushing; |
329 uint32_t fDrawID; | 330 uint32_t fDrawID; |
330 | 331 |
331 typedef GrDrawTarget INHERITED; | 332 typedef GrDrawTarget INHERITED; |
332 }; | 333 }; |
333 | 334 |
334 #endif | 335 #endif |
OLD | NEW |