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 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 const SkIPoint& dstPoint) SK_OVERRIDE; | 87 const SkIPoint& dstPoint) SK_OVERRIDE; |
88 | 88 |
89 virtual void clearStencilClip(const SkIRect& rect, | 89 virtual void clearStencilClip(const SkIRect& rect, |
90 bool insideClip, | 90 bool insideClip, |
91 GrRenderTarget* renderTarget) SK_OVERRIDE; | 91 GrRenderTarget* renderTarget) SK_OVERRIDE; |
92 | 92 |
93 virtual void discard(GrRenderTarget*) SK_OVERRIDE; | 93 virtual void discard(GrRenderTarget*) SK_OVERRIDE; |
94 | 94 |
95 virtual void initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* des
c) SK_OVERRIDE; | 95 virtual void initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* des
c) SK_OVERRIDE; |
96 | 96 |
97 protected: | |
98 virtual void clipWillBeSet(const GrClipData* newClip) SK_OVERRIDE; | |
99 | |
100 private: | 97 private: |
| 98 typedef GrClipMaskManager::ScissorState ScissorState; |
101 enum { | 99 enum { |
102 kDraw_Cmd = 1, | 100 kDraw_Cmd = 1, |
103 kStencilPath_Cmd = 2, | 101 kStencilPath_Cmd = 2, |
104 kSetState_Cmd = 3, | 102 kSetState_Cmd = 3, |
105 kSetClip_Cmd = 4, | 103 kClear_Cmd = 4, |
106 kClear_Cmd = 5, | 104 kCopySurface_Cmd = 5, |
107 kCopySurface_Cmd = 6, | 105 kDrawPath_Cmd = 6, |
108 kDrawPath_Cmd = 7, | 106 kDrawPaths_Cmd = 7, |
109 kDrawPaths_Cmd = 8, | |
110 }; | 107 }; |
111 | 108 |
112 struct Cmd : ::SkNoncopyable { | 109 struct Cmd : ::SkNoncopyable { |
113 Cmd(uint8_t type) : fType(type) {} | 110 Cmd(uint8_t type) : fType(type) {} |
114 virtual ~Cmd() {} | 111 virtual ~Cmd() {} |
115 | 112 |
116 virtual void execute(GrClipTarget*) = 0; | 113 virtual void execute(GrClipTarget*) = 0; |
117 | 114 |
118 uint8_t fType; | 115 uint8_t fType; |
119 }; | 116 }; |
120 | 117 |
121 struct Draw : public Cmd { | 118 struct Draw : public Cmd { |
122 Draw(const DrawInfo& info, const GrVertexBuffer* vb, const GrIndexBuffer
* ib) | 119 Draw(const DrawInfo& info, |
| 120 const ScissorState& scissorState, |
| 121 const GrVertexBuffer* vb, |
| 122 const GrIndexBuffer* ib) |
123 : Cmd(kDraw_Cmd) | 123 : Cmd(kDraw_Cmd) |
124 , fInfo(info) | 124 , fInfo(info) |
| 125 , fScissorState(scissorState) |
125 , fVertexBuffer(vb) | 126 , fVertexBuffer(vb) |
126 , fIndexBuffer(ib) {} | 127 , fIndexBuffer(ib) {} |
127 | 128 |
128 const GrVertexBuffer* vertexBuffer() const { return fVertexBuffer.get();
} | 129 const GrVertexBuffer* vertexBuffer() const { return fVertexBuffer.get();
} |
129 const GrIndexBuffer* indexBuffer() const { return fIndexBuffer.get(); } | 130 const GrIndexBuffer* indexBuffer() const { return fIndexBuffer.get(); } |
130 | 131 |
131 virtual void execute(GrClipTarget*); | 132 virtual void execute(GrClipTarget*); |
132 | 133 |
133 DrawInfo fInfo; | 134 DrawInfo fInfo; |
| 135 ScissorState fScissorState; |
134 | 136 |
135 private: | 137 private: |
136 GrPendingIOResource<const GrVertexBuffer, kRead_GrIOType> fVertexBuff
er; | 138 GrPendingIOResource<const GrVertexBuffer, kRead_GrIOType> fVertexBuff
er; |
137 GrPendingIOResource<const GrIndexBuffer, kRead_GrIOType> fIndexBuffe
r; | 139 GrPendingIOResource<const GrIndexBuffer, kRead_GrIOType> fIndexBuffe
r; |
138 }; | 140 }; |
139 | 141 |
140 struct StencilPath : public Cmd { | 142 struct StencilPath : public Cmd { |
141 StencilPath(const GrPath* path) : Cmd(kStencilPath_Cmd), fPath(path) {} | 143 StencilPath(const GrPath* path) : Cmd(kStencilPath_Cmd), fPath(path) {} |
142 | 144 |
143 const GrPath* path() const { return fPath.get(); } | 145 const GrPath* path() const { return fPath.get(); } |
144 | 146 |
145 virtual void execute(GrClipTarget*); | 147 virtual void execute(GrClipTarget*); |
146 | 148 |
147 GrPathRendering::FillType fFill; | 149 ScissorState fScissorState; |
| 150 GrStencilSettings fStencilSettings; |
148 | 151 |
149 private: | 152 private: |
150 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; | 153 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; |
151 }; | 154 }; |
152 | 155 |
153 struct DrawPath : public Cmd { | 156 struct DrawPath : public Cmd { |
154 DrawPath(const GrPath* path) : Cmd(kDrawPath_Cmd), fPath(path) {} | 157 DrawPath(const GrPath* path) : Cmd(kDrawPath_Cmd), fPath(path) {} |
155 | 158 |
156 const GrPath* path() const { return fPath.get(); } | 159 const GrPath* path() const { return fPath.get(); } |
157 | 160 |
158 virtual void execute(GrClipTarget*); | 161 virtual void execute(GrClipTarget*); |
159 | 162 |
160 GrPathRendering::FillType fFill; | 163 GrDeviceCoordTexture fDstCopy; |
161 GrDeviceCoordTexture fDstCopy; | 164 ScissorState fScissorState; |
| 165 GrStencilSettings fStencilSettings; |
162 | 166 |
163 private: | 167 private: |
164 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; | 168 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; |
165 }; | 169 }; |
166 | 170 |
167 struct DrawPaths : public Cmd { | 171 struct DrawPaths : public Cmd { |
168 DrawPaths(const GrPathRange* pathRange) : Cmd(kDrawPaths_Cmd), fPathRang
e(pathRange) {} | 172 DrawPaths(const GrPathRange* pathRange) : Cmd(kDrawPaths_Cmd), fPathRang
e(pathRange) {} |
169 | 173 |
170 const GrPathRange* pathRange() const { return fPathRange.get(); } | 174 const GrPathRange* pathRange() const { return fPathRange.get(); } |
171 uint32_t* indices() { return reinterpret_cast<uint32_t*>(CmdBuffer::GetD
ataForItem(this)); } | 175 uint32_t* indices() { return reinterpret_cast<uint32_t*>(CmdBuffer::GetD
ataForItem(this)); } |
172 float* transforms() { return reinterpret_cast<float*>(&this->indices()[f
Count]); } | 176 float* transforms() { return reinterpret_cast<float*>(&this->indices()[f
Count]); } |
173 | 177 |
174 virtual void execute(GrClipTarget*); | 178 virtual void execute(GrClipTarget*); |
175 | 179 |
176 size_t fCount; | 180 size_t fCount; |
177 PathTransformType fTransformsType; | 181 PathTransformType fTransformsType; |
178 GrPathRendering::FillType fFill; | 182 GrDeviceCoordTexture fDstCopy; |
179 GrDeviceCoordTexture fDstCopy; | 183 ScissorState fScissorState; |
| 184 GrStencilSettings fStencilSettings; |
180 | 185 |
181 private: | 186 private: |
182 GrPendingIOResource<const GrPathRange, kRead_GrIOType> fPathRange; | 187 GrPendingIOResource<const GrPathRange, kRead_GrIOType> fPathRange; |
183 }; | 188 }; |
184 | 189 |
185 // This is also used to record a discard by setting the color to GrColor_ILL
EGAL | 190 // This is also used to record a discard by setting the color to GrColor_ILL
EGAL |
186 struct Clear : public Cmd { | 191 struct Clear : public Cmd { |
187 Clear(GrRenderTarget* rt) : Cmd(kClear_Cmd), fRenderTarget(rt) {} | 192 Clear(GrRenderTarget* rt) : Cmd(kClear_Cmd), fRenderTarget(rt) {} |
188 | 193 |
189 GrRenderTarget* renderTarget() const { return fRenderTarget.get(); } | 194 GrRenderTarget* renderTarget() const { return fRenderTarget.get(); } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 }; | 235 }; |
231 | 236 |
232 struct SetState : public Cmd { | 237 struct SetState : public Cmd { |
233 SetState(const GrDrawState& state) : Cmd(kSetState_Cmd), fState(state) {
} | 238 SetState(const GrDrawState& state) : Cmd(kSetState_Cmd), fState(state) {
} |
234 | 239 |
235 virtual void execute(GrClipTarget*); | 240 virtual void execute(GrClipTarget*); |
236 | 241 |
237 GrDrawState fState; | 242 GrDrawState fState; |
238 }; | 243 }; |
239 | 244 |
240 struct SetClip : public Cmd { | |
241 SetClip(const GrClipData* clipData) | |
242 : Cmd(kSetClip_Cmd), | |
243 fStackStorage(*clipData->fClipStack) { | |
244 fClipData.fClipStack = &fStackStorage; | |
245 fClipData.fOrigin = clipData->fOrigin; | |
246 } | |
247 | |
248 virtual void execute(GrClipTarget*); | |
249 | |
250 GrClipData fClipData; | |
251 | |
252 private: | |
253 SkClipStack fStackStorage; | |
254 }; | |
255 | |
256 typedef void* TCmdAlign; // This wouldn't be enough align if a command used
long double. | 245 typedef void* TCmdAlign; // This wouldn't be enough align if a command used
long double. |
257 typedef GrTRecorder<Cmd, TCmdAlign> CmdBuffer; | 246 typedef GrTRecorder<Cmd, TCmdAlign> CmdBuffer; |
258 | 247 |
259 // overrides from GrDrawTarget | 248 // overrides from GrDrawTarget |
260 virtual void onDraw(const DrawInfo&) SK_OVERRIDE; | 249 virtual void onDraw(const DrawInfo&, const GrClipMaskManager::ScissorState&)
SK_OVERRIDE; |
261 virtual void onDrawRect(const SkRect& rect, | 250 virtual void onDrawRect(const SkRect& rect, |
262 const SkRect* localRect, | 251 const SkRect* localRect, |
263 const SkMatrix* localMatrix) SK_OVERRIDE; | 252 const SkMatrix* localMatrix) SK_OVERRIDE; |
264 | 253 |
265 virtual void onStencilPath(const GrPath*, GrPathRendering::FillType) SK_OVER
RIDE; | 254 virtual void onStencilPath(const GrPath*, |
266 virtual void onDrawPath(const GrPath*, GrPathRendering::FillType, | 255 const GrClipMaskManager::ScissorState&, |
| 256 const GrStencilSettings&) SK_OVERRIDE; |
| 257 virtual void onDrawPath(const GrPath*, |
| 258 const GrClipMaskManager::ScissorState&, |
| 259 const GrStencilSettings&, |
267 const GrDeviceCoordTexture* dstCopy) SK_OVERRIDE; | 260 const GrDeviceCoordTexture* dstCopy) SK_OVERRIDE; |
268 virtual void onDrawPaths(const GrPathRange*, | 261 virtual void onDrawPaths(const GrPathRange*, |
269 const uint32_t indices[], int count, | 262 const uint32_t indices[], |
270 const float transforms[], PathTransformType, | 263 int count, |
271 GrPathRendering::FillType, const GrDeviceCoordTextu
re*) SK_OVERRIDE; | 264 const float transforms[], |
| 265 PathTransformType, |
| 266 const GrClipMaskManager::ScissorState&, |
| 267 const GrStencilSettings&, |
| 268 const GrDeviceCoordTexture*) SK_OVERRIDE; |
272 virtual void onClear(const SkIRect* rect, | 269 virtual void onClear(const SkIRect* rect, |
273 GrColor color, | 270 GrColor color, |
274 bool canIgnoreRect, | 271 bool canIgnoreRect, |
275 GrRenderTarget* renderTarget) SK_OVERRIDE; | 272 GrRenderTarget* renderTarget) SK_OVERRIDE; |
276 | 273 |
277 virtual bool onReserveVertexSpace(size_t vertexSize, | 274 virtual bool onReserveVertexSpace(size_t vertexSize, |
278 int vertexCount, | 275 int vertexCount, |
279 void** vertices) SK_OVERRIDE; | 276 void** vertices) SK_OVERRIDE; |
280 virtual bool onReserveIndexSpace(int indexCount, | 277 virtual bool onReserveIndexSpace(int indexCount, |
281 void** indices) SK_OVERRIDE; | 278 void** indices) SK_OVERRIDE; |
282 virtual void releaseReservedVertexSpace() SK_OVERRIDE; | 279 virtual void releaseReservedVertexSpace() SK_OVERRIDE; |
283 virtual void releaseReservedIndexSpace() SK_OVERRIDE; | 280 virtual void releaseReservedIndexSpace() SK_OVERRIDE; |
284 virtual void geometrySourceWillPush() SK_OVERRIDE; | 281 virtual void geometrySourceWillPush() SK_OVERRIDE; |
285 virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) SK
_OVERRIDE; | 282 virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) SK
_OVERRIDE; |
286 virtual void willReserveVertexAndIndexSpace(int vertexCount, | 283 virtual void willReserveVertexAndIndexSpace(int vertexCount, |
287 int indexCount) SK_OVERRIDE; | 284 int indexCount) SK_OVERRIDE; |
288 | 285 |
289 bool quickInsideClip(const SkRect& devBounds); | |
290 | |
291 virtual void didAddGpuTraceMarker() SK_OVERRIDE {} | 286 virtual void didAddGpuTraceMarker() SK_OVERRIDE {} |
292 virtual void didRemoveGpuTraceMarker() SK_OVERRIDE {} | 287 virtual void didRemoveGpuTraceMarker() SK_OVERRIDE {} |
293 | 288 |
294 // Attempts to concat instances from info onto the previous draw. info must
represent an | 289 // Attempts to concat instances from info onto the previous draw. info must
represent an |
295 // instanced draw. The caller must have already recorded a new draw state an
d clip if necessary. | 290 // instanced draw. The caller must have already recorded a new draw state an
d clip if necessary. |
296 int concatInstancedDraw(const DrawInfo& info); | 291 int concatInstancedDraw(const DrawInfo& info, const GrClipMaskManager::Sciss
orState&); |
297 | 292 |
298 // Determines whether the current draw operation requieres a new drawstate a
nd if so records it. | 293 // Determines whether the current draw operation requieres a new drawstate a
nd if so records it. |
299 void recordStateIfNecessary(); | 294 void recordStateIfNecessary(); |
300 // We lazily record clip changes in order to skip clips that have no effect. | 295 // We lazily record clip changes in order to skip clips that have no effect. |
301 void recordClipIfNecessary(); | 296 void recordClipIfNecessary(); |
302 // Records any trace markers for a command after adding it to the buffer. | 297 // Records any trace markers for a command after adding it to the buffer. |
303 void recordTraceMarkersIfNecessary(); | 298 void recordTraceMarkersIfNecessary(); |
304 | 299 |
305 virtual bool isIssued(uint32_t drawID) { return drawID != fDrawID; } | 300 virtual bool isIssued(uint32_t drawID) { return drawID != fDrawID; } |
306 | 301 |
307 // TODO: Use a single allocator for commands and records | 302 // TODO: Use a single allocator for commands and records |
308 enum { | 303 enum { |
309 kCmdBufferInitialSizeInBytes = 64 * 1024, | 304 kCmdBufferInitialSizeInBytes = 64 * 1024, |
310 kGeoPoolStatePreAllocCnt = 4, | 305 kGeoPoolStatePreAllocCnt = 4, |
311 }; | 306 }; |
312 | 307 |
313 CmdBuffer fCmdBuffer; | 308 CmdBuffer fCmdBuffer; |
314 GrDrawState* fLastState; | 309 GrDrawState* fLastState; |
315 GrClipData* fLastClip; | |
316 | |
317 SkTArray<GrTraceMarkerSet, false> fGpuCmdMarkers; | 310 SkTArray<GrTraceMarkerSet, false> fGpuCmdMarkers; |
318 GrClipTarget* fDstGpu; | 311 GrClipTarget* fDstGpu; |
319 bool fClipSet; | 312 GrVertexBufferAllocPool& fVertexPool; |
320 | 313 GrIndexBufferAllocPool& fIndexPool; |
321 enum ClipProxyState { | |
322 kUnknown_ClipProxyState, | |
323 kValid_ClipProxyState, | |
324 kInvalid_ClipProxyState | |
325 }; | |
326 | |
327 ClipProxyState fClipProxyState; | |
328 SkRect fClipProxy; | |
329 GrVertexBufferAllocPool& fVertexPool; | |
330 GrIndexBufferAllocPool& fIndexPool; | |
331 | 314 |
332 struct GeometryPoolState { | 315 struct GeometryPoolState { |
333 const GrVertexBuffer* fPoolVertexBuffer; | 316 const GrVertexBuffer* fPoolVertexBuffer; |
334 int fPoolStartVertex; | 317 int fPoolStartVertex; |
335 const GrIndexBuffer* fPoolIndexBuffer; | 318 const GrIndexBuffer* fPoolIndexBuffer; |
336 int fPoolStartIndex; | 319 int fPoolStartIndex; |
337 // caller may conservatively over reserve vertices / indices. | 320 // caller may conservatively over reserve vertices / indices. |
338 // we release unused space back to allocator if possible | 321 // we release unused space back to allocator if possible |
339 // can only do this if there isn't an intervening pushGeometrySource() | 322 // can only do this if there isn't an intervening pushGeometrySource() |
340 size_t fUsedPoolVertexBytes; | 323 size_t fUsedPoolVertexBytes; |
341 size_t fUsedPoolIndexBytes; | 324 size_t fUsedPoolIndexBytes; |
342 }; | 325 }; |
343 | 326 |
344 typedef SkSTArray<kGeoPoolStatePreAllocCnt, GeometryPoolState> GeoPoolStateS
tack; | 327 typedef SkSTArray<kGeoPoolStatePreAllocCnt, GeometryPoolState> GeoPoolStateS
tack; |
345 | 328 |
346 GeoPoolStateStack fGeoPoolStateStack; | 329 GeoPoolStateStack fGeoPoolStateStack; |
347 bool fFlushing; | 330 bool fFlushing; |
348 uint32_t fDrawID; | 331 uint32_t fDrawID; |
349 | 332 |
350 typedef GrClipTarget INHERITED; | 333 typedef GrClipTarget INHERITED; |
351 }; | 334 }; |
352 | 335 |
353 #endif | 336 #endif |
OLD | NEW |