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" | 14 #include "GrIndexBuffer.h" |
15 #include "GrRenderTarget.h" | 15 #include "GrRenderTarget.h" |
16 #include "GrPath.h" | 16 #include "GrPath.h" |
17 #include "GrPathRange.h" | 17 #include "GrPathRange.h" |
18 #include "GrSurface.h" | 18 #include "GrSurface.h" |
| 19 #include "GrTRecorder.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" |
24 | 25 |
25 class GrGpu; | 26 class GrGpu; |
26 class GrIndexBufferAllocPool; | 27 class GrIndexBufferAllocPool; |
27 class GrVertexBufferAllocPool; | 28 class GrVertexBufferAllocPool; |
28 | 29 |
(...skipping 51 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 struct Cmd : ::SkNoncopyable { |
102 public: | 103 Cmd(uint8_t type) : fType(type) {} |
| 104 virtual ~Cmd() {} |
| 105 |
| 106 virtual void execute(GrDrawTarget*) = 0; |
| 107 |
| 108 uint8_t fType; |
| 109 }; |
| 110 |
| 111 struct Draw : public Cmd { |
103 Draw(const DrawInfo& info, const GrVertexBuffer* vb, const GrIndexBuffer
* ib) | 112 Draw(const DrawInfo& info, const GrVertexBuffer* vb, const GrIndexBuffer
* ib) |
104 : DrawInfo(info) | 113 : Cmd(kDraw_Cmd) |
| 114 , fInfo(info) |
105 , fVertexBuffer(vb) | 115 , fVertexBuffer(vb) |
106 , fIndexBuffer(ib) {} | 116 , fIndexBuffer(ib) {} |
107 | 117 |
108 const GrVertexBuffer* vertexBuffer() const { return fVertexBuffer.get();
} | 118 const GrVertexBuffer* vertexBuffer() const { return fVertexBuffer.get();
} |
109 const GrIndexBuffer* indexBuffer() const { return fIndexBuffer.get(); } | 119 const GrIndexBuffer* indexBuffer() const { return fIndexBuffer.get(); } |
110 | 120 |
| 121 virtual void execute(GrDrawTarget*); |
| 122 |
| 123 DrawInfo fInfo; |
| 124 |
111 private: | 125 private: |
112 GrPendingIOResource<const GrVertexBuffer, kRead_GrIOType> fVertexBuff
er; | 126 GrPendingIOResource<const GrVertexBuffer, kRead_GrIOType> fVertexBuff
er; |
113 GrPendingIOResource<const GrIndexBuffer, kRead_GrIOType> fIndexBuffe
r; | 127 GrPendingIOResource<const GrIndexBuffer, kRead_GrIOType> fIndexBuffe
r; |
114 }; | 128 }; |
115 | 129 |
116 struct StencilPath : public ::SkNoncopyable { | 130 struct StencilPath : public Cmd { |
117 StencilPath(const GrPath* path) : fPath(path) {} | 131 StencilPath(const GrPath* path) : Cmd(kStencilPath_Cmd), fPath(path) {} |
118 | 132 |
119 const GrPath* path() const { return fPath.get(); } | 133 const GrPath* path() const { return fPath.get(); } |
120 | 134 |
| 135 virtual void execute(GrDrawTarget*); |
| 136 |
121 SkPath::FillType fFill; | 137 SkPath::FillType fFill; |
122 | 138 |
123 private: | 139 private: |
124 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; | 140 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; |
125 }; | 141 }; |
126 | 142 |
127 struct DrawPath : public ::SkNoncopyable { | 143 struct DrawPath : public Cmd { |
128 DrawPath(const GrPath* path) : fPath(path) {} | 144 DrawPath(const GrPath* path) : Cmd(kDrawPath_Cmd), fPath(path) {} |
129 | 145 |
130 const GrPath* path() const { return fPath.get(); } | 146 const GrPath* path() const { return fPath.get(); } |
131 | 147 |
| 148 virtual void execute(GrDrawTarget*); |
| 149 |
132 SkPath::FillType fFill; | 150 SkPath::FillType fFill; |
133 GrDeviceCoordTexture fDstCopy; | 151 GrDeviceCoordTexture fDstCopy; |
134 | 152 |
135 private: | 153 private: |
136 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; | 154 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; |
137 }; | 155 }; |
138 | 156 |
139 struct DrawPaths : public ::SkNoncopyable { | 157 struct DrawPaths : public Cmd { |
140 DrawPaths(const GrPathRange* pathRange) | 158 DrawPaths(const GrPathRange* pathRange) : Cmd(kDrawPaths_Cmd), fPathRang
e(pathRange) {} |
141 : fPathRange(pathRange) {} | |
142 | |
143 ~DrawPaths() { | |
144 if (fTransforms) { | |
145 SkDELETE_ARRAY(fTransforms); | |
146 } | |
147 if (fIndices) { | |
148 SkDELETE_ARRAY(fIndices); | |
149 } | |
150 } | |
151 | 159 |
152 const GrPathRange* pathRange() const { return fPathRange.get(); } | 160 const GrPathRange* pathRange() const { return fPathRange.get(); } |
| 161 uint32_t* indices() { return reinterpret_cast<uint32_t*>(CmdBuffer::GetD
ataForItem(this)); } |
| 162 float* transforms() { return reinterpret_cast<float*>(&this->indices()[f
Count]); } |
153 | 163 |
154 uint32_t* fIndices; | 164 virtual void execute(GrDrawTarget*); |
| 165 |
155 size_t fCount; | 166 size_t fCount; |
156 float* fTransforms; | |
157 PathTransformType fTransformsType; | 167 PathTransformType fTransformsType; |
158 SkPath::FillType fFill; | 168 SkPath::FillType fFill; |
159 GrDeviceCoordTexture fDstCopy; | 169 GrDeviceCoordTexture fDstCopy; |
160 | 170 |
161 private: | 171 private: |
162 GrPendingIOResource<const GrPathRange, kRead_GrIOType> fPathRange; | 172 GrPendingIOResource<const GrPathRange, kRead_GrIOType> fPathRange; |
163 }; | 173 }; |
164 | 174 |
165 // This is also used to record a discard by setting the color to GrColor_ILL
EGAL | 175 // This is also used to record a discard by setting the color to GrColor_ILL
EGAL |
166 struct Clear : public ::SkNoncopyable { | 176 struct Clear : public Cmd { |
167 Clear(GrRenderTarget* rt) : fRenderTarget(rt) {} | 177 Clear(GrRenderTarget* rt) : Cmd(kClear_Cmd), fRenderTarget(rt) {} |
168 ~Clear() { } | 178 |
169 GrRenderTarget* renderTarget() const { return fRenderTarget.get(); } | 179 GrRenderTarget* renderTarget() const { return fRenderTarget.get(); } |
170 | 180 |
| 181 virtual void execute(GrDrawTarget*); |
| 182 |
171 SkIRect fRect; | 183 SkIRect fRect; |
172 GrColor fColor; | 184 GrColor fColor; |
173 bool fCanIgnoreRect; | 185 bool fCanIgnoreRect; |
174 | 186 |
175 private: | 187 private: |
176 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; | 188 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; |
177 }; | 189 }; |
178 | 190 |
179 struct CopySurface : public ::SkNoncopyable { | 191 struct CopySurface : public Cmd { |
180 CopySurface(GrSurface* dst, GrSurface* src) : fDst(dst), fSrc(src) {} | 192 CopySurface(GrSurface* dst, GrSurface* src) : Cmd(kCopySurface_Cmd), fDs
t(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, kWrite_GrIOType> fDst; | 203 GrPendingIOResource<GrSurface, kWrite_GrIOType> fDst; |
190 GrPendingIOResource<GrSurface, kRead_GrIOType> fSrc; | 204 GrPendingIOResource<GrSurface, kRead_GrIOType> fSrc; |
191 }; | 205 }; |
192 | 206 |
193 struct Clip : public ::SkNoncopyable { | 207 struct SetState : public Cmd { |
194 SkClipStack fStack; | 208 SetState(const GrDrawState& state) : Cmd(kSetState_Cmd), fState(state) {
} |
195 SkIPoint fOrigin; | 209 |
| 210 virtual void execute(GrDrawTarget*); |
| 211 |
| 212 GrDrawState fState; |
196 }; | 213 }; |
197 | 214 |
| 215 struct SetClip : public Cmd { |
| 216 SetClip(const GrClipData* clipData) |
| 217 : Cmd(kSetClip_Cmd), |
| 218 fStackStorage(*clipData->fClipStack) { |
| 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; |
| 229 }; |
| 230 |
| 231 typedef void* TCmdAlign; // This wouldn't be enough align if a command used
long double. |
| 232 typedef GrTRecorder<Cmd, TCmdAlign> CmdBuffer; |
| 233 |
198 // overrides from GrDrawTarget | 234 // overrides from GrDrawTarget |
199 virtual void onDraw(const DrawInfo&) SK_OVERRIDE; | 235 virtual void onDraw(const DrawInfo&) SK_OVERRIDE; |
200 virtual void onDrawRect(const SkRect& rect, | 236 virtual void onDrawRect(const SkRect& rect, |
201 const SkRect* localRect, | 237 const SkRect* localRect, |
202 const SkMatrix* localMatrix) SK_OVERRIDE; | 238 const SkMatrix* localMatrix) SK_OVERRIDE; |
203 | 239 |
204 virtual void onStencilPath(const GrPath*, SkPath::FillType) SK_OVERRIDE; | 240 virtual void onStencilPath(const GrPath*, SkPath::FillType) SK_OVERRIDE; |
205 virtual void onDrawPath(const GrPath*, SkPath::FillType, | 241 virtual void onDrawPath(const GrPath*, SkPath::FillType, |
206 const GrDeviceCoordTexture* dstCopy) SK_OVERRIDE; | 242 const GrDeviceCoordTexture* dstCopy) SK_OVERRIDE; |
207 virtual void onDrawPaths(const GrPathRange*, | 243 virtual void onDrawPaths(const GrPathRange*, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 virtual void didAddGpuTraceMarker() SK_OVERRIDE {} | 276 virtual void didAddGpuTraceMarker() SK_OVERRIDE {} |
241 virtual void didRemoveGpuTraceMarker() SK_OVERRIDE {} | 277 virtual void didRemoveGpuTraceMarker() SK_OVERRIDE {} |
242 | 278 |
243 // Attempts to concat instances from info onto the previous draw. info must
represent an | 279 // 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. | 280 // instanced draw. The caller must have already recorded a new draw state an
d clip if necessary. |
245 int concatInstancedDraw(const DrawInfo& info); | 281 int concatInstancedDraw(const DrawInfo& info); |
246 | 282 |
247 // Determines whether the current draw operation requieres a new drawstate a
nd if so records it. | 283 // Determines whether the current draw operation requieres a new drawstate a
nd if so records it. |
248 void recordStateIfNecessary(); | 284 void recordStateIfNecessary(); |
249 // We lazily record clip changes in order to skip clips that have no effect. | 285 // We lazily record clip changes in order to skip clips that have no effect. |
250 bool needsNewClip() const; | 286 void recordClipIfNecessary(); |
251 | 287 // Records any trace markers for a command after adding it to the buffer. |
252 // these functions record a command | 288 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 | 289 |
262 virtual bool isIssued(uint32_t drawID) { return drawID != fDrawID; } | 290 virtual bool isIssued(uint32_t drawID) { return drawID != fDrawID; } |
263 void addToCmdBuffer(uint8_t cmd); | |
264 | 291 |
265 // TODO: Use a single allocator for commands and records | 292 // TODO: Use a single allocator for commands and records |
266 enum { | 293 enum { |
267 kCmdPreallocCnt = 32, | 294 kCmdBufferInitialSizeInBytes = 64 * 1024, |
268 kDrawPreallocCnt = 16, | 295 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 }; | 296 }; |
278 | 297 |
279 typedef GrTAllocator<Draw> DrawAllocator; | 298 CmdBuffer fCmdBuffer; |
280 typedef GrTAllocator<StencilPath> StencilPathAllocator; | 299 GrDrawState* fLastState; |
281 typedef GrTAllocator<DrawPath> DrawPathAllocator; | 300 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 | 301 |
288 GrSTAllocator<kDrawPreallocCnt, Draw> fDraws; | 302 SkTArray<GrTraceMarkerSet, false> fGpuCmdMarkers; |
289 GrSTAllocator<kStencilPathPreallocCnt, StencilPath> fStencilPaths; | 303 GrDrawTarget* fDstGpu; |
290 GrSTAllocator<kDrawPathPreallocCnt, DrawPath> fDrawPath; | 304 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 | 305 |
302 enum ClipProxyState { | 306 enum ClipProxyState { |
303 kUnknown_ClipProxyState, | 307 kUnknown_ClipProxyState, |
304 kValid_ClipProxyState, | 308 kValid_ClipProxyState, |
305 kInvalid_ClipProxyState | 309 kInvalid_ClipProxyState |
306 }; | 310 }; |
307 | 311 |
308 ClipProxyState fClipProxyState; | 312 ClipProxyState fClipProxyState; |
309 SkRect fClipProxy; | 313 SkRect fClipProxy; |
310 GrVertexBufferAllocPool& fVertexPool; | 314 GrVertexBufferAllocPool& fVertexPool; |
(...skipping 14 matching lines...) Expand all Loading... |
325 typedef SkSTArray<kGeoPoolStatePreAllocCnt, GeometryPoolState> GeoPoolStateS
tack; | 329 typedef SkSTArray<kGeoPoolStatePreAllocCnt, GeometryPoolState> GeoPoolStateS
tack; |
326 | 330 |
327 GeoPoolStateStack fGeoPoolStateStack; | 331 GeoPoolStateStack fGeoPoolStateStack; |
328 bool fFlushing; | 332 bool fFlushing; |
329 uint32_t fDrawID; | 333 uint32_t fDrawID; |
330 | 334 |
331 typedef GrDrawTarget INHERITED; | 335 typedef GrDrawTarget INHERITED; |
332 }; | 336 }; |
333 | 337 |
334 #endif | 338 #endif |
OLD | NEW |