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