OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 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 GrDrawTarget_DEFINED | 8 #ifndef GrDrawTarget_DEFINED |
9 #define GrDrawTarget_DEFINED | 9 #define GrDrawTarget_DEFINED |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "SkPath.h" | 24 #include "SkPath.h" |
25 #include "SkStrokeRec.h" | 25 #include "SkStrokeRec.h" |
26 #include "SkTArray.h" | 26 #include "SkTArray.h" |
27 #include "SkTLazy.h" | 27 #include "SkTLazy.h" |
28 #include "SkTypes.h" | 28 #include "SkTypes.h" |
29 #include "SkXfermode.h" | 29 #include "SkXfermode.h" |
30 | 30 |
31 class GrBatch; | 31 class GrBatch; |
32 class GrClip; | 32 class GrClip; |
33 class GrDrawTargetCaps; | 33 class GrDrawTargetCaps; |
34 class GrGeometryProcessor; | |
35 class GrPath; | 34 class GrPath; |
36 class GrPathRange; | 35 class GrPathRange; |
37 class GrPipeline; | 36 class GrPipeline; |
38 | 37 |
39 class GrDrawTarget : public SkRefCnt { | 38 class GrDrawTarget : public SkRefCnt { |
40 public: | 39 public: |
41 SK_DECLARE_INST_COUNT(GrDrawTarget) | 40 SK_DECLARE_INST_COUNT(GrDrawTarget) |
42 | 41 |
43 typedef GrPathRange::PathIndexType PathIndexType; | 42 typedef GrPathRange::PathIndexType PathIndexType; |
44 typedef GrPathRendering::PathTransformType PathTransformType; | 43 typedef GrPathRendering::PathTransformType PathTransformType; |
45 | 44 |
46 /////////////////////////////////////////////////////////////////////////// | 45 /////////////////////////////////////////////////////////////////////////// |
47 | 46 |
48 // The context may not be fully constructed and should not be used during Gr
DrawTarget | 47 // The context may not be fully constructed and should not be used during Gr
DrawTarget |
49 // construction. | 48 // construction. |
50 GrDrawTarget(GrContext* context); | 49 GrDrawTarget(GrContext* context); |
51 virtual ~GrDrawTarget(); | 50 virtual ~GrDrawTarget() {} |
52 | 51 |
53 /** | 52 /** |
54 * Gets the capabilities of the draw target. | 53 * Gets the capabilities of the draw target. |
55 */ | 54 */ |
56 const GrDrawTargetCaps* caps() const { return fCaps.get(); } | 55 const GrDrawTargetCaps* caps() const { return fCaps.get(); } |
57 | 56 |
58 /** | |
59 * There are two types of "sources" of geometry (vertices and indices) for | |
60 * draw calls made on the target. When performing an indexed draw, the | |
61 * indices and vertices can use different source types. Once a source is | |
62 * specified it can be used for multiple draws. However, the time at which | |
63 * the geometry data is no longer editable depends on the source type. | |
64 * | |
65 * Sometimes it is necessary to perform a draw while upstack code has | |
66 * already specified geometry that it isn't finished with. So there are push | |
67 * and pop methods. This allows the client to push the sources, draw | |
68 * something using alternate sources, and then pop to restore the original | |
69 * sources. | |
70 * | |
71 * Aside from pushes and pops, a source remains valid until another source | |
72 * is set or resetVertexSource / resetIndexSource is called. Drawing from | |
73 * a reset source is an error. | |
74 * | |
75 * The two types of sources are: | |
76 * | |
77 * 1. Reserve. This is most useful when the caller has data it must | |
78 * transform before drawing and is not long-lived. The caller requests | |
79 * that the draw target make room for some amount of vertex and/or index | |
80 * data. The target provides ptrs to hold the vertex and/or index data. | |
81 * | |
82 * The data is writable up until the next drawIndexed, drawNonIndexed, | |
83 * drawIndexedInstances, drawRect, copySurface, or pushGeometrySource. At | |
84 * this point the data is frozen and the ptrs are no longer valid. | |
85 * | |
86 * Where the space is allocated and how it is uploaded to the GPU is | |
87 * subclass-dependent. | |
88 * | |
89 * 2. Vertex and Index Buffers. This is most useful for geometry that will | |
90 * is long-lived. When the data in the buffer is consumed depends on the | |
91 * GrDrawTarget subclass. For deferred subclasses the caller has to | |
92 * guarantee that the data is still available in the buffers at playback. | |
93 * (TODO: Make this more automatic as we have done for read/write pixels) | |
94 */ | |
95 | |
96 /** | |
97 * Reserves space for vertices and/or indices. Zero can be specifed as | |
98 * either the vertex or index count if the caller desires to only reserve | |
99 * space for only indices or only vertices. If zero is specifed for | |
100 * vertexCount then the vertex source will be unmodified and likewise for | |
101 * indexCount. | |
102 * | |
103 * If the function returns true then the reserve suceeded and the vertices | |
104 * and indices pointers will point to the space created. | |
105 * | |
106 * If the target cannot make space for the request then this function will | |
107 * return false. If vertexCount was non-zero then upon failure the vertex | |
108 * source is reset and likewise for indexCount. | |
109 * | |
110 * The pointers to the space allocated for vertices and indices remain valid | |
111 * until a drawIndexed, drawNonIndexed, drawIndexedInstances, drawRect, | |
112 * copySurface, or push/popGeomtrySource is called. At that point logically
a | |
113 * snapshot of the data is made and the pointers are invalid. | |
114 * | |
115 * @param vertexCount the number of vertices to reserve space for. Can be | |
116 * 0. Vertex size is queried from the current GrPipeline
Builder. | |
117 * @param indexCount the number of indices to reserve space for. Can be 0. | |
118 * @param vertices will point to reserved vertex space if vertexCount is | |
119 * non-zero. Illegal to pass NULL if vertexCount > 0. | |
120 * @param indices will point to reserved index space if indexCount is | |
121 * non-zero. Illegal to pass NULL if indexCount > 0. | |
122 */ | |
123 bool reserveVertexAndIndexSpace(int vertexCount, | |
124 size_t vertexStride, | |
125 int indexCount, | |
126 void** vertices, | |
127 void** indices); | |
128 | |
129 /** | |
130 * Provides hints to caller about the number of vertices and indices | |
131 * that can be allocated cheaply. This can be useful if caller is reserving | |
132 * space but doesn't know exactly how much geometry is needed. | |
133 * | |
134 * Also may hint whether the draw target should be flushed first. This is | |
135 * useful for deferred targets. | |
136 * | |
137 * @param vertexCount in: hint about how many vertices the caller would | |
138 * like to allocate. Vertex size is queried from the | |
139 * current GrPipelineBuilder. | |
140 * out: a hint about the number of vertices that can be | |
141 * allocated cheaply. Negative means no hint. | |
142 * Ignored if NULL. | |
143 * @param indexCount in: hint about how many indices the caller would | |
144 * like to allocate. | |
145 * out: a hint about the number of indices that can be | |
146 * allocated cheaply. Negative means no hint. | |
147 * Ignored if NULL. | |
148 * | |
149 * @return true if target should be flushed based on the input values. | |
150 */ | |
151 virtual bool geometryHints(size_t vertexStride, int* vertexCount, int* index
Count) const; | |
152 | |
153 /** | |
154 * Sets source of vertex data for the next draw. Data does not have to be | |
155 * in the buffer until drawIndexed, drawNonIndexed, or drawIndexedInstances. | |
156 * | |
157 * @param buffer vertex buffer containing vertex data. Must be | |
158 * unlocked before draw call. Vertex size is queried | |
159 * from current GrPipelineBuilder. | |
160 */ | |
161 void setVertexSourceToBuffer(const GrVertexBuffer* buffer, size_t vertexStri
de); | |
162 | |
163 /** | |
164 * Sets source of index data for the next indexed draw. Data does not have | |
165 * to be in the buffer until drawIndexed. | |
166 * | |
167 * @param buffer index buffer containing indices. Must be unlocked | |
168 * before indexed draw call. | |
169 */ | |
170 void setIndexSourceToBuffer(const GrIndexBuffer* buffer); | |
171 | |
172 /** | |
173 * Resets vertex source. Drawing from reset vertices is illegal. Set vertex | |
174 * source to reserved, array, or buffer before next draw. May be able to fre
e | |
175 * up temporary storage allocated by setVertexSourceToArray or | |
176 * reserveVertexSpace. | |
177 */ | |
178 void resetVertexSource(); | |
179 | |
180 /** | |
181 * Resets index source. Indexed Drawing from reset indices is illegal. Set | |
182 * index source to reserved, array, or buffer before next indexed draw. May | |
183 * be able to free up temporary storage allocated by setIndexSourceToArray | |
184 * or reserveIndexSpace. | |
185 */ | |
186 void resetIndexSource(); | |
187 | |
188 /** | |
189 * Query to find out if the vertex or index source is reserved. | |
190 */ | |
191 bool hasReservedVerticesOrIndices() const { | |
192 return kReserved_GeometrySrcType == this->getGeomSrc().fVertexSrc || | |
193 kReserved_GeometrySrcType == this->getGeomSrc().fIndexSrc; | |
194 } | |
195 | |
196 /** | |
197 * Pushes and resets the vertex/index sources. Any reserved vertex / index | |
198 * data is finalized (i.e. cannot be updated after the matching pop but can | |
199 * be drawn from). Must be balanced by a pop. | |
200 */ | |
201 void pushGeometrySource(); | |
202 | |
203 /** | |
204 * Pops the vertex / index sources from the matching push. | |
205 */ | |
206 void popGeometrySource(); | |
207 | |
208 /** | |
209 * Draws indexed geometry using the current state and current vertex / index | |
210 * sources. | |
211 * | |
212 * @param type The type of primitives to draw. | |
213 * @param startVertex the vertex in the vertex array/buffer corresponding | |
214 * to index 0 | |
215 * @param startIndex first index to read from index src. | |
216 * @param vertexCount one greater than the max index. | |
217 * @param indexCount the number of index elements to read. The index count | |
218 * is effectively trimmed to the last completely | |
219 * specified primitive. | |
220 * @param devBounds optional bounds hint. This is a promise from the call
er, | |
221 * not a request for clipping. | |
222 */ | |
223 void drawIndexed(GrPipelineBuilder*, | |
224 const GrGeometryProcessor*, | |
225 GrPrimitiveType type, | |
226 int startVertex, | |
227 int startIndex, | |
228 int vertexCount, | |
229 int indexCount, | |
230 const SkRect* devBounds = NULL); | |
231 | |
232 /** | |
233 * Draws non-indexed geometry using the current state and current vertex | |
234 * sources. | |
235 * | |
236 * @param type The type of primitives to draw. | |
237 * @param startVertex the vertex in the vertex array/buffer corresponding | |
238 * to index 0 | |
239 * @param vertexCount one greater than the max index. | |
240 * @param devBounds optional bounds hint. This is a promise from the call
er, | |
241 * not a request for clipping. | |
242 */ | |
243 void drawNonIndexed(GrPipelineBuilder*, | |
244 const GrGeometryProcessor*, | |
245 GrPrimitiveType type, | |
246 int startVertex, | |
247 int vertexCount, | |
248 const SkRect* devBounds = NULL); | |
249 | |
250 // TODO devbounds should live on the batch | 57 // TODO devbounds should live on the batch |
251 void drawBatch(GrPipelineBuilder*, GrBatch*, const SkRect* devBounds = NULL)
; | 58 void drawBatch(GrPipelineBuilder*, GrBatch*, const SkRect* devBounds = NULL)
; |
252 | 59 |
253 /** | 60 /** |
254 * Draws path into the stencil buffer. The fill must be either even/odd or | 61 * Draws path into the stencil buffer. The fill must be either even/odd or |
255 * winding (not inverse or hairline). It will respect the HW antialias flag | 62 * winding (not inverse or hairline). It will respect the HW antialias flag |
256 * on the GrPipelineBuilder (if possible in the 3D API). Note, we will neve
r have an inverse | 63 * on the GrPipelineBuilder (if possible in the 3D API). Note, we will neve
r have an inverse |
257 * fill with stencil path | 64 * fill with stencil path |
258 */ | 65 */ |
259 void stencilPath(GrPipelineBuilder*, const GrPathProcessor*, const GrPath*, | 66 void stencilPath(GrPipelineBuilder*, const GrPathProcessor*, const GrPath*, |
(...skipping 23 matching lines...) Expand all Loading... |
283 const GrPathProcessor*, | 90 const GrPathProcessor*, |
284 const GrPathRange* pathRange, | 91 const GrPathRange* pathRange, |
285 const void* indices, | 92 const void* indices, |
286 PathIndexType indexType, | 93 PathIndexType indexType, |
287 const float transformValues[], | 94 const float transformValues[], |
288 PathTransformType transformType, | 95 PathTransformType transformType, |
289 int count, | 96 int count, |
290 GrPathRendering::FillType fill); | 97 GrPathRendering::FillType fill); |
291 | 98 |
292 /** | 99 /** |
293 * Helper function for drawing rects. It performs a geometry src push and po
p | 100 * Helper function for drawing rects. |
294 * and thus will finalize any reserved geometry. | |
295 * | 101 * |
296 * @param rect the rect to draw | 102 * @param rect the rect to draw |
297 * @param localRect optional rect that specifies local coords to map onto | 103 * @param localRect optional rect that specifies local coords to map onto |
298 * rect. If NULL then rect serves as the local coords. | 104 * rect. If NULL then rect serves as the local coords. |
299 * @param localMatrix Optional local matrix. The local coordinates are speci
fied by localRect, | 105 * @param localMatrix Optional local matrix. The local coordinates are speci
fied by localRect, |
300 * or if it is NULL by rect. This matrix applies to the c
oordinate implied by | 106 * or if it is NULL by rect. This matrix applies to the c
oordinate implied by |
301 * that rectangle before it is input to GrCoordTransforms
that read local | 107 * that rectangle before it is input to GrCoordTransforms
that read local |
302 * coordinates | 108 * coordinates |
303 */ | 109 */ |
304 void drawRect(GrPipelineBuilder* pipelineBuilder, | 110 void drawRect(GrPipelineBuilder* pipelineBuilder, |
(...skipping 11 matching lines...) Expand all Loading... |
316 void drawSimpleRect(GrPipelineBuilder* ds, GrColor color, const SkMatrix& vi
ewM, | 122 void drawSimpleRect(GrPipelineBuilder* ds, GrColor color, const SkMatrix& vi
ewM, |
317 const SkRect& rect) { | 123 const SkRect& rect) { |
318 this->drawRect(ds, color, viewM, rect, NULL, NULL); | 124 this->drawRect(ds, color, viewM, rect, NULL, NULL); |
319 } | 125 } |
320 void drawSimpleRect(GrPipelineBuilder* ds, GrColor color, const SkMatrix& vi
ewM, | 126 void drawSimpleRect(GrPipelineBuilder* ds, GrColor color, const SkMatrix& vi
ewM, |
321 const SkIRect& irect) { | 127 const SkIRect& irect) { |
322 SkRect rect = SkRect::Make(irect); | 128 SkRect rect = SkRect::Make(irect); |
323 this->drawRect(ds, color, viewM, rect, NULL, NULL); | 129 this->drawRect(ds, color, viewM, rect, NULL, NULL); |
324 } | 130 } |
325 | 131 |
326 /** | |
327 * This call is used to draw multiple instances of some geometry with a | |
328 * given number of vertices (V) and indices (I) per-instance. The indices in | |
329 * the index source must have the form i[k+I] == i[k] + V. Also, all indices | |
330 * i[kI] ... i[(k+1)I-1] must be elements of the range kV ... (k+1)V-1. As a | |
331 * concrete example, the following index buffer for drawing a series of | |
332 * quads each as two triangles each satisfies these conditions with V=4 and | |
333 * I=6: | |
334 * (0,1,2,0,2,3, 4,5,6,4,6,7, 8,9,10,8,10,11, ...) | |
335 * | |
336 * The call assumes that the pattern of indices fills the entire index | |
337 * source. The size of the index buffer limits the number of instances that | |
338 * can be drawn by the GPU in a single draw. However, the caller may specify | |
339 * any (positive) number for instanceCount and if necessary multiple GPU | |
340 * draws will be issued. Moreover, when drawIndexedInstances is called | |
341 * multiple times it may be possible for GrDrawTarget to group them into a | |
342 * single GPU draw. | |
343 * | |
344 * @param type the type of primitives to draw | |
345 * @param instanceCount the number of instances to draw. Each instance | |
346 * consists of verticesPerInstance vertices indexed by | |
347 * indicesPerInstance indices drawn as the primitive | |
348 * type specified by type. | |
349 * @param verticesPerInstance The number of vertices in each instance (V | |
350 * in the above description). | |
351 * @param indicesPerInstance The number of indices in each instance (I | |
352 * in the above description). | |
353 * @param devBounds optional bounds hint. This is a promise from the call
er, | |
354 * not a request for clipping. | |
355 */ | |
356 void drawIndexedInstances(GrPipelineBuilder*, | |
357 const GrGeometryProcessor*, | |
358 GrPrimitiveType type, | |
359 int instanceCount, | |
360 int verticesPerInstance, | |
361 int indicesPerInstance, | |
362 const SkRect* devBounds = NULL); | |
363 | 132 |
364 /** | 133 /** |
365 * Clear the passed in render target. Ignores the GrPipelineBuilder and clip
. Clears the whole | 134 * Clear the passed in render target. Ignores the GrPipelineBuilder and clip
. Clears the whole |
366 * thing if rect is NULL, otherwise just the rect. If canIgnoreRect is set t
hen the entire | 135 * thing if rect is NULL, otherwise just the rect. If canIgnoreRect is set t
hen the entire |
367 * render target can be optionally cleared. | 136 * render target can be optionally cleared. |
368 */ | 137 */ |
369 void clear(const SkIRect* rect, | 138 void clear(const SkIRect* rect, |
370 GrColor color, | 139 GrColor color, |
371 bool canIgnoreRect, | 140 bool canIgnoreRect, |
372 GrRenderTarget* renderTarget); | 141 GrRenderTarget* renderTarget); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 const GrSurface* src, | 187 const GrSurface* src, |
419 const SkIRect& srcRect, | 188 const SkIRect& srcRect, |
420 const SkIPoint& dstPoint); | 189 const SkIPoint& dstPoint); |
421 | 190 |
422 /** | 191 /** |
423 * Release any resources that are cached but not currently in use. This | 192 * Release any resources that are cached but not currently in use. This |
424 * is intended to give an application some recourse when resources are low. | 193 * is intended to give an application some recourse when resources are low. |
425 */ | 194 */ |
426 virtual void purgeResources() {}; | 195 virtual void purgeResources() {}; |
427 | 196 |
428 //////////////////////////////////////////////////////////////////////////// | |
429 | |
430 class AutoReleaseGeometry : public ::SkNoncopyable { | |
431 public: | |
432 AutoReleaseGeometry(GrDrawTarget* target, | |
433 int vertexCount, | |
434 size_t vertexStride, | |
435 int indexCount); | |
436 AutoReleaseGeometry(); | |
437 ~AutoReleaseGeometry(); | |
438 bool set(GrDrawTarget* target, | |
439 int vertexCount, | |
440 size_t vertexStride, | |
441 int indexCount); | |
442 bool succeeded() const { return SkToBool(fTarget); } | |
443 void* vertices() const { SkASSERT(this->succeeded()); return fVertices;
} | |
444 void* indices() const { SkASSERT(this->succeeded()); return fIndices; } | |
445 SkPoint* positions() const { | |
446 return static_cast<SkPoint*>(this->vertices()); | |
447 } | |
448 | |
449 private: | |
450 void reset(); | |
451 | |
452 GrDrawTarget* fTarget; | |
453 void* fVertices; | |
454 void* fIndices; | |
455 }; | |
456 | |
457 //////////////////////////////////////////////////////////////////////////// | |
458 | |
459 /** | |
460 * Saves the geometry src state at construction and restores in the destruct
or. It also saves | |
461 * and then restores the vertex attrib state. | |
462 */ | |
463 class AutoGeometryPush : public ::SkNoncopyable { | |
464 public: | |
465 AutoGeometryPush(GrDrawTarget* target) { | |
466 SkASSERT(target); | |
467 fTarget = target; | |
468 target->pushGeometrySource(); | |
469 } | |
470 | |
471 ~AutoGeometryPush() { fTarget->popGeometrySource(); } | |
472 | |
473 private: | |
474 GrDrawTarget* fTarget; | |
475 }; | |
476 | |
477 /////////////////////////////////////////////////////////////////////////// | 197 /////////////////////////////////////////////////////////////////////////// |
478 // Draw execution tracking (for font atlases and other resources) | 198 // Draw execution tracking (for font atlases and other resources) |
479 class DrawToken { | 199 class DrawToken { |
480 public: | 200 public: |
481 DrawToken(GrDrawTarget* drawTarget, uint32_t drawID) : | 201 DrawToken(GrDrawTarget* drawTarget, uint32_t drawID) : |
482 fDrawTarget(drawTarget), fDrawID(drawID) {} | 202 fDrawTarget(drawTarget), fDrawID(drawID) {} |
483 | 203 |
484 bool isIssued() { return fDrawTarget && fDrawTarget->isIssued(fDrawID);
} | 204 bool isIssued() { return fDrawTarget && fDrawTarget->isIssued(fDrawID);
} |
485 | 205 |
486 private: | 206 private: |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 bool isIndexed() const { return fIndexCount > 0; } | 241 bool isIndexed() const { return fIndexCount > 0; } |
522 #ifdef SK_DEBUG | 242 #ifdef SK_DEBUG |
523 bool isInstanced() const; // this version is longer because of asserts | 243 bool isInstanced() const; // this version is longer because of asserts |
524 #else | 244 #else |
525 bool isInstanced() const { return fInstanceCount > 0; } | 245 bool isInstanced() const { return fInstanceCount > 0; } |
526 #endif | 246 #endif |
527 | 247 |
528 // adds or remove instances | 248 // adds or remove instances |
529 void adjustInstanceCount(int instanceOffset); | 249 void adjustInstanceCount(int instanceOffset); |
530 // shifts the start vertex | 250 // shifts the start vertex |
531 void adjustStartVertex(int vertexOffset); | 251 void adjustStartVertex(int vertexOffset) { |
| 252 fStartVertex += vertexOffset; |
| 253 SkASSERT(fStartVertex >= 0); |
| 254 } |
532 // shifts the start index | 255 // shifts the start index |
533 void adjustStartIndex(int indexOffset); | 256 void adjustStartIndex(int indexOffset) { |
534 | 257 SkASSERT(this->isIndexed()); |
| 258 fStartIndex += indexOffset; |
| 259 SkASSERT(fStartIndex >= 0); |
| 260 } |
535 void setDevBounds(const SkRect& bounds) { | 261 void setDevBounds(const SkRect& bounds) { |
536 fDevBoundsStorage = bounds; | 262 fDevBoundsStorage = bounds; |
537 fDevBounds = &fDevBoundsStorage; | 263 fDevBounds = &fDevBoundsStorage; |
538 } | 264 } |
539 const GrVertexBuffer* vertexBuffer() const { return fVertexBuffer.get();
} | 265 const GrVertexBuffer* vertexBuffer() const { return fVertexBuffer.get();
} |
540 const GrIndexBuffer* indexBuffer() const { return fIndexBuffer.get(); } | 266 const GrIndexBuffer* indexBuffer() const { return fIndexBuffer.get(); } |
541 void setVertexBuffer(const GrVertexBuffer* vb) { | 267 void setVertexBuffer(const GrVertexBuffer* vb) { |
542 fVertexBuffer.reset(vb); | 268 fVertexBuffer.reset(vb); |
543 } | 269 } |
544 void setIndexBuffer(const GrIndexBuffer* ib) { | 270 void setIndexBuffer(const GrIndexBuffer* ib) { |
(...skipping 15 matching lines...) Expand all Loading... |
560 int fVerticesPerInstance; | 286 int fVerticesPerInstance; |
561 int fIndicesPerInstance; | 287 int fIndicesPerInstance; |
562 | 288 |
563 SkRect fDevBoundsStorage; | 289 SkRect fDevBoundsStorage; |
564 SkRect* fDevBounds; | 290 SkRect* fDevBounds; |
565 | 291 |
566 GrPendingIOResource<const GrVertexBuffer, kRead_GrIOType> fVertexBuffer; | 292 GrPendingIOResource<const GrVertexBuffer, kRead_GrIOType> fVertexBuffer; |
567 GrPendingIOResource<const GrIndexBuffer, kRead_GrIOType> fIndexBuffer; | 293 GrPendingIOResource<const GrIndexBuffer, kRead_GrIOType> fIndexBuffer; |
568 }; | 294 }; |
569 | 295 |
570 /** | |
571 * Used to populate the vertex and index buffer on the draw info before onDr
aw is called. | |
572 */ | |
573 virtual void setDrawBuffers(DrawInfo*, size_t vertexStride) = 0; | |
574 bool programUnitTest(int maxStages); | 296 bool programUnitTest(int maxStages); |
575 | 297 |
576 protected: | 298 protected: |
577 friend class GrTargetCommands; // for PipelineInfo | 299 friend class GrTargetCommands; // for PipelineInfo |
578 | 300 |
579 enum GeometrySrcType { | |
580 kNone_GeometrySrcType, //<! src has not been specified | |
581 kReserved_GeometrySrcType, //<! src was set using reserve*Space | |
582 kBuffer_GeometrySrcType //<! src was set using set*SourceToBuffer | |
583 }; | |
584 | |
585 struct GeometrySrcState { | |
586 GeometrySrcType fVertexSrc; | |
587 union { | |
588 // valid if src type is buffer | |
589 const GrVertexBuffer* fVertexBuffer; | |
590 // valid if src type is reserved or array | |
591 int fVertexCount; | |
592 }; | |
593 | |
594 GeometrySrcType fIndexSrc; | |
595 union { | |
596 // valid if src type is buffer | |
597 const GrIndexBuffer* fIndexBuffer; | |
598 // valid if src type is reserved or array | |
599 int fIndexCount; | |
600 }; | |
601 | |
602 size_t fVertexSize; | |
603 }; | |
604 | |
605 int indexCountInCurrentSource() const { | |
606 const GeometrySrcState& src = this->getGeomSrc(); | |
607 switch (src.fIndexSrc) { | |
608 case kNone_GeometrySrcType: | |
609 return 0; | |
610 case kReserved_GeometrySrcType: | |
611 return src.fIndexCount; | |
612 case kBuffer_GeometrySrcType: | |
613 return static_cast<int>(src.fIndexBuffer->gpuMemorySize() / size
of(uint16_t)); | |
614 default: | |
615 SkFAIL("Unexpected Index Source."); | |
616 return 0; | |
617 } | |
618 } | |
619 | |
620 GrContext* getContext() { return fContext; } | 301 GrContext* getContext() { return fContext; } |
621 const GrContext* getContext() const { return fContext; } | 302 const GrContext* getContext() const { return fContext; } |
622 | 303 |
623 // subclasses must call this in their destructors to ensure all vertex | |
624 // and index sources have been released (including those held by | |
625 // pushGeometrySource()) | |
626 void releaseGeometry(); | |
627 | |
628 // accessors for derived classes | |
629 const GeometrySrcState& getGeomSrc() const { return fGeoSrcStateStack.back()
; } | |
630 // it is preferable to call this rather than getGeomSrc()->fVertexSize becau
se of the assert. | |
631 size_t getVertexSize() const { | |
632 // the vertex layout is only valid if a vertex source has been specified
. | |
633 SkASSERT(this->getGeomSrc().fVertexSrc != kNone_GeometrySrcType); | |
634 return this->getGeomSrc().fVertexSize; | |
635 } | |
636 | |
637 // Subclass must initialize this in its constructor. | 304 // Subclass must initialize this in its constructor. |
638 SkAutoTUnref<const GrDrawTargetCaps> fCaps; | 305 SkAutoTUnref<const GrDrawTargetCaps> fCaps; |
639 | 306 |
640 const GrTraceMarkerSet& getActiveTraceMarkers() { return fActiveTraceMarkers
; } | 307 const GrTraceMarkerSet& getActiveTraceMarkers() { return fActiveTraceMarkers
; } |
641 | 308 |
642 // Makes a copy of the dst if it is necessary for the draw. Returns false if
a copy is required | 309 // Makes a copy of the dst if it is necessary for the draw. Returns false if
a copy is required |
643 // but couldn't be made. Otherwise, returns true. This method needs to be p
rotected because it | 310 // but couldn't be made. Otherwise, returns true. This method needs to be p
rotected because it |
644 // needs to be accessed by GLPrograms to setup a correct drawstate | 311 // needs to be accessed by GLPrograms to setup a correct drawstate |
645 bool setupDstReadIfNecessary(const GrPipelineBuilder&, | 312 bool setupDstReadIfNecessary(const GrPipelineBuilder&, |
646 const GrProcOptInfo& colorPOI, | 313 const GrProcOptInfo& colorPOI, |
(...skipping 20 matching lines...) Expand all Loading... |
667 | 334 |
668 GrPipelineBuilder* fPipelineBuilder; | 335 GrPipelineBuilder* fPipelineBuilder; |
669 GrScissorState* fScissor; | 336 GrScissorState* fScissor; |
670 GrProcOptInfo fColorPOI; | 337 GrProcOptInfo fColorPOI; |
671 GrProcOptInfo fCoveragePOI; | 338 GrProcOptInfo fCoveragePOI; |
672 GrDeviceCoordTexture fDstCopy; | 339 GrDeviceCoordTexture fDstCopy; |
673 }; | 340 }; |
674 | 341 |
675 void setupPipeline(const PipelineInfo& pipelineInfo, GrPipeline* pipeline); | 342 void setupPipeline(const PipelineInfo& pipelineInfo, GrPipeline* pipeline); |
676 | 343 |
677 // A subclass can optionally overload this function to be notified before | |
678 // vertex and index space is reserved. | |
679 virtual void willReserveVertexAndIndexSpace(int vertexCount, | |
680 size_t vertexStride, | |
681 int indexCount) {} | |
682 | |
683 private: | 344 private: |
684 /** | 345 /** |
685 * This will be called before allocating a texture as a dst for copySurface.
This function | 346 * This will be called before allocating a texture as a dst for copySurface.
This function |
686 * populates the dstDesc's config, flags, and origin so as to maximize effic
iency and guarantee | 347 * populates the dstDesc's config, flags, and origin so as to maximize effic
iency and guarantee |
687 * success of the copySurface call. | 348 * success of the copySurface call. |
688 */ | 349 */ |
689 void initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* dstDesc) { | 350 void initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* dstDesc) { |
690 if (!this->onInitCopySurfaceDstDesc(src, dstDesc)) { | 351 if (!this->onInitCopySurfaceDstDesc(src, dstDesc)) { |
691 dstDesc->fOrigin = kDefault_GrSurfaceOrigin; | 352 dstDesc->fOrigin = kDefault_GrSurfaceOrigin; |
692 dstDesc->fFlags = kRenderTarget_GrSurfaceFlag; | 353 dstDesc->fFlags = kRenderTarget_GrSurfaceFlag; |
693 dstDesc->fConfig = src->config(); | 354 dstDesc->fConfig = src->config(); |
694 } | 355 } |
695 } | 356 } |
696 | 357 |
697 /** Internal implementation of canCopySurface. */ | 358 /** Internal implementation of canCopySurface. */ |
698 bool internalCanCopySurface(const GrSurface* dst, | 359 bool internalCanCopySurface(const GrSurface* dst, |
699 const GrSurface* src, | 360 const GrSurface* src, |
700 const SkIRect& clippedSrcRect, | 361 const SkIRect& clippedSrcRect, |
701 const SkIPoint& clippedDstRect); | 362 const SkIPoint& clippedDstRect); |
702 | 363 |
703 // implemented by subclass to allocate space for reserved geom | |
704 virtual bool onReserveVertexSpace(size_t vertexSize, int vertexCount, void**
vertices) = 0; | |
705 virtual bool onReserveIndexSpace(int indexCount, void** indices) = 0; | |
706 // implemented by subclass to handle release of reserved geom space | |
707 virtual void releaseReservedVertexSpace() = 0; | |
708 virtual void releaseReservedIndexSpace() = 0; | |
709 // subclass overrides to be notified just before geo src state is pushed/pop
ped. | |
710 virtual void geometrySourceWillPush() = 0; | |
711 virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) =
0; | |
712 // subclass called to perform drawing | |
713 virtual void onDraw(const GrGeometryProcessor*, const DrawInfo&, const Pipel
ineInfo&) = 0; | |
714 virtual void onDrawBatch(GrBatch*, const PipelineInfo&) = 0; | 364 virtual void onDrawBatch(GrBatch*, const PipelineInfo&) = 0; |
715 // TODO copy in order drawbuffer onDrawRect to here | 365 // TODO copy in order drawbuffer onDrawRect to here |
716 virtual void onDrawRect(GrPipelineBuilder*, | 366 virtual void onDrawRect(GrPipelineBuilder*, |
717 GrColor color, | 367 GrColor color, |
718 const SkMatrix& viewMatrix, | 368 const SkMatrix& viewMatrix, |
719 const SkRect& rect, | 369 const SkRect& rect, |
720 const SkRect* localRect, | 370 const SkRect* localRect, |
721 const SkMatrix* localMatrix) = 0; | 371 const SkMatrix* localMatrix) = 0; |
722 | 372 |
723 virtual void onStencilPath(const GrPipelineBuilder&, | 373 virtual void onStencilPath(const GrPipelineBuilder&, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
759 const SkIRect& srcRect, | 409 const SkIRect& srcRect, |
760 const SkIPoint& dstPoint) = 0; | 410 const SkIPoint& dstPoint) = 0; |
761 /** | 411 /** |
762 * This will be called before allocating a texture to be a dst for onCopySur
face. Only the | 412 * This will be called before allocating a texture to be a dst for onCopySur
face. Only the |
763 * dstDesc's config, flags, and origin need be set by the function. If the s
ubclass cannot | 413 * dstDesc's config, flags, and origin need be set by the function. If the s
ubclass cannot |
764 * create a surface that would succeed its implementation of onCopySurface,
it should return | 414 * create a surface that would succeed its implementation of onCopySurface,
it should return |
765 * false. The base class will fall back to creating a render target to draw
into using the src. | 415 * false. The base class will fall back to creating a render target to draw
into using the src. |
766 */ | 416 */ |
767 virtual bool onInitCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* d
stDesc) = 0; | 417 virtual bool onInitCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* d
stDesc) = 0; |
768 | 418 |
769 // helpers for reserving vertex and index space. | |
770 bool reserveVertexSpace(size_t vertexSize, | |
771 int vertexCount, | |
772 void** vertices); | |
773 bool reserveIndexSpace(int indexCount, void** indices); | |
774 | |
775 // called by drawIndexed and drawNonIndexed. Use a negative indexCount to | |
776 // indicate non-indexed drawing. | |
777 bool checkDraw(const GrPipelineBuilder&, | |
778 const GrGeometryProcessor*, | |
779 GrPrimitiveType type, | |
780 int startVertex, | |
781 int startIndex, | |
782 int vertexCount, | |
783 int indexCount) const; | |
784 // called when setting a new vert/idx source to unref prev vb/ib | |
785 void releasePreviousVertexSource(); | |
786 void releasePreviousIndexSource(); | |
787 | |
788 // Check to see if this set of draw commands has been sent out | 419 // Check to see if this set of draw commands has been sent out |
789 virtual bool isIssued(uint32_t drawID) { return true; } | 420 virtual bool isIssued(uint32_t drawID) { return true; } |
790 void getPathStencilSettingsForFilltype(GrPathRendering::FillType, | 421 void getPathStencilSettingsForFilltype(GrPathRendering::FillType, |
791 const GrStencilAttachment*, | 422 const GrStencilAttachment*, |
792 GrStencilSettings*); | 423 GrStencilSettings*); |
793 virtual GrClipMaskManager* clipMaskManager() = 0; | 424 virtual GrClipMaskManager* clipMaskManager() = 0; |
794 virtual bool setupClip(GrPipelineBuilder*, | 425 virtual bool setupClip(GrPipelineBuilder*, |
795 GrPipelineBuilder::AutoRestoreFragmentProcessors*, | 426 GrPipelineBuilder::AutoRestoreFragmentProcessors*, |
796 GrPipelineBuilder::AutoRestoreStencil*, | 427 GrPipelineBuilder::AutoRestoreStencil*, |
797 GrScissorState*, | 428 GrScissorState*, |
798 const SkRect* devBounds) = 0; | 429 const SkRect* devBounds) = 0; |
799 | 430 |
800 enum { | |
801 kPreallocGeoSrcStateStackCnt = 4, | |
802 }; | |
803 SkSTArray<kPreallocGeoSrcStateStackCnt, GeometrySrcState, true> fGeoSrcState
Stack; | |
804 // The context owns us, not vice-versa, so this ptr is not ref'ed by DrawTar
get. | 431 // The context owns us, not vice-versa, so this ptr is not ref'ed by DrawTar
get. |
805 GrContext* fContext; | 432 GrContext* fContext; |
806 // To keep track that we always have at least as many debug marker adds as r
emoves | 433 // To keep track that we always have at least as many debug marker adds as r
emoves |
807 int fGpuTraceMar
kerCount; | 434 int fGpuTraceMar
kerCount; |
808 GrTraceMarkerSet fActiveTrace
Markers; | 435 GrTraceMarkerSet fActiveTrace
Markers; |
809 GrTraceMarkerSet fStoredTrace
Markers; | 436 GrTraceMarkerSet fStoredTrace
Markers; |
810 | 437 |
811 typedef SkRefCnt INHERITED; | 438 typedef SkRefCnt INHERITED; |
812 }; | 439 }; |
813 | 440 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
853 virtual bool setupClip(GrPipelineBuilder*, | 480 virtual bool setupClip(GrPipelineBuilder*, |
854 GrPipelineBuilder::AutoRestoreFragmentProcessors*, | 481 GrPipelineBuilder::AutoRestoreFragmentProcessors*, |
855 GrPipelineBuilder::AutoRestoreStencil*, | 482 GrPipelineBuilder::AutoRestoreStencil*, |
856 GrScissorState* scissorState, | 483 GrScissorState* scissorState, |
857 const SkRect* devBounds) override; | 484 const SkRect* devBounds) override; |
858 | 485 |
859 typedef GrDrawTarget INHERITED; | 486 typedef GrDrawTarget INHERITED; |
860 }; | 487 }; |
861 | 488 |
862 #endif | 489 #endif |
OLD | NEW |