blob: a011aaef997799ac8234b455a8853ca98638730c [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@google.comac10a2d2010-12-22 21:39:39 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2010 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
reed@google.comac10a2d2010-12-22 21:39:39 +00007 */
8
9
epoger@google.comec3ed6a2011-07-28 14:26:00 +000010
reed@google.comac10a2d2010-12-22 21:39:39 +000011#ifndef GrDrawTarget_DEFINED
12#define GrDrawTarget_DEFINED
13
bsalomon@google.com8d67c072012-12-13 20:38:14 +000014#include "GrClipData.h"
tomhudson@google.com93813632011-10-27 20:21:16 +000015#include "GrDrawState.h"
bsalomon@google.com934c5702012-03-20 21:17:58 +000016#include "GrIndexBuffer.h"
bsalomon@google.comb9086a02012-11-01 18:02:54 +000017#include "SkMatrix.h"
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000018#include "GrRefCnt.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000019
bsalomon@google.com8d67c072012-12-13 20:38:14 +000020#include "SkClipStack.h"
sugoi@google.com12b4e272012-12-06 20:13:11 +000021#include "SkPath.h"
bsalomon@google.com46f7afb2012-01-18 19:51:55 +000022#include "SkTLazy.h"
robertphillips@google.coma2d71482012-08-01 20:08:47 +000023#include "SkTArray.h"
bsalomon@google.com8d67c072012-12-13 20:38:14 +000024#include "SkXfermode.h"
Scroggo97c88c22011-05-11 14:05:25 +000025
robertphillips@google.coma2d71482012-08-01 20:08:47 +000026class GrClipData;
bsalomon@google.com64aef2b2012-06-11 15:36:13 +000027class GrPath;
reed@google.comac10a2d2010-12-22 21:39:39 +000028class GrVertexBuffer;
sugoi@google.com5f74cf82012-12-17 21:16:45 +000029class SkStrokeRec;
sugoi@google.com12b4e272012-12-06 20:13:11 +000030
reed@google.comac10a2d2010-12-22 21:39:39 +000031class GrDrawTarget : public GrRefCnt {
bsalomon@google.comf6601872012-08-28 21:11:35 +000032protected:
33 /** This helper class allows GrDrawTarget subclasses to set the caps values without having to be
34 made a friend of GrDrawTarget::Caps. */
35 class CapsInternals {
36 public:
bsalomon@google.com18c9c192011-09-22 21:01:31 +000037 bool f8BitPaletteSupport : 1;
bsalomon@google.com18c9c192011-09-22 21:01:31 +000038 bool fNPOTTextureTileSupport : 1;
bsalomon@google.com18c9c192011-09-22 21:01:31 +000039 bool fTwoSidedStencilSupport : 1;
40 bool fStencilWrapOpsSupport : 1;
41 bool fHWAALineSupport : 1;
bsalomon@google.com18c9c192011-09-22 21:01:31 +000042 bool fShaderDerivativeSupport : 1;
bsalomon@google.comedfe1aa2011-09-29 14:40:26 +000043 bool fGeometryShaderSupport : 1;
bsalomon@google.com18c9c192011-09-22 21:01:31 +000044 bool fFSAASupport : 1;
45 bool fDualSourceBlendingSupport : 1;
46 bool fBufferLockSupport : 1;
bsalomon@google.com64aef2b2012-06-11 15:36:13 +000047 bool fPathStencilingSupport : 1;
bsalomon@google.com8a70eef2013-03-19 13:58:55 +000048
bsalomon@google.com18c9c192011-09-22 21:01:31 +000049 int fMaxRenderTargetSize;
50 int fMaxTextureSize;
bsalomon@google.com8a70eef2013-03-19 13:58:55 +000051 int fMaxSampleCount;
bsalomon@google.com18c9c192011-09-22 21:01:31 +000052 };
53
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000054 class DrawInfo;
55
bsalomon@google.comf6601872012-08-28 21:11:35 +000056public:
57 SK_DECLARE_INST_COUNT(GrDrawTarget)
58
59 /**
60 * Represents the draw target capabilities.
61 */
62 class Caps {
63 public:
64 Caps() { memset(this, 0, sizeof(Caps)); }
65 Caps(const Caps& c) { *this = c; }
66 Caps& operator= (const Caps& c) {
67 memcpy(this, &c, sizeof(Caps));
68 return *this;
69 }
70 void print() const;
71
72 bool eightBitPaletteSupport() const { return fInternals.f8BitPaletteSupport; }
73 bool npotTextureTileSupport() const { return fInternals.fNPOTTextureTileSupport; }
74 bool twoSidedStencilSupport() const { return fInternals.fTwoSidedStencilSupport; }
75 bool stencilWrapOpsSupport() const { return fInternals.fStencilWrapOpsSupport; }
76 bool hwAALineSupport() const { return fInternals.fHWAALineSupport; }
77 bool shaderDerivativeSupport() const { return fInternals.fShaderDerivativeSupport; }
78 bool geometryShaderSupport() const { return fInternals.fGeometryShaderSupport; }
79 bool fsaaSupport() const { return fInternals.fFSAASupport; }
80 bool dualSourceBlendingSupport() const { return fInternals.fDualSourceBlendingSupport; }
81 bool bufferLockSupport() const { return fInternals.fBufferLockSupport; }
82 bool pathStencilingSupport() const { return fInternals.fPathStencilingSupport; }
83
84 int maxRenderTargetSize() const { return fInternals.fMaxRenderTargetSize; }
85 int maxTextureSize() const { return fInternals.fMaxTextureSize; }
bsalomon@google.com8a70eef2013-03-19 13:58:55 +000086 // Will be 0 if MSAA is not supported
87 int maxSampleCount() const { return fInternals.fMaxSampleCount; }
bsalomon@google.comf6601872012-08-28 21:11:35 +000088 private:
89 CapsInternals fInternals;
bsalomon@google.com0d82fe52012-08-28 21:39:15 +000090 friend class GrDrawTarget; // to set values of fInternals
bsalomon@google.comf6601872012-08-28 21:11:35 +000091 };
92
reed@google.comac10a2d2010-12-22 21:39:39 +000093 ///////////////////////////////////////////////////////////////////////////
94
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000095 // The context may not be fully constructed and should not be used during GrDrawTarget
96 // construction.
97 GrDrawTarget(GrContext* context);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000098 virtual ~GrDrawTarget();
reed@google.comac10a2d2010-12-22 21:39:39 +000099
100 /**
bsalomon@google.com18c9c192011-09-22 21:01:31 +0000101 * Gets the capabilities of the draw target.
102 */
103 const Caps& getCaps() const { return fCaps; }
104
105 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000106 * Sets the current clip to the region specified by clip. All draws will be
107 * clipped against this clip if kClip_StateBit is enabled.
108 *
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +0000109 * Setting the clip may (or may not) zero out the client's stencil bits.
110 *
reed@google.comac10a2d2010-12-22 21:39:39 +0000111 * @param description of the clipping region
112 */
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000113 void setClip(const GrClipData* clip);
reed@google.comac10a2d2010-12-22 21:39:39 +0000114
115 /**
116 * Gets the current clip.
117 *
118 * @return the clip.
119 */
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000120 const GrClipData* getClip() const;
reed@google.comac10a2d2010-12-22 21:39:39 +0000121
bsalomon@google.coma5d056a2012-03-27 15:59:58 +0000122 /**
123 * Sets the draw state object for the draw target. Note that this does not
124 * make a copy. The GrDrawTarget will take a reference to passed object.
125 * Passing NULL will cause the GrDrawTarget to use its own internal draw
126 * state object rather than an externally provided one.
127 */
128 void setDrawState(GrDrawState* drawState);
129
130 /**
131 * Read-only access to the GrDrawTarget's current draw state.
132 */
133 const GrDrawState& getDrawState() const { return *fDrawState; }
134
135 /**
136 * Read-write access to the GrDrawTarget's current draw state. Note that
137 * this doesn't ref.
138 */
139 GrDrawState* drawState() { return fDrawState; }
bsalomon@google.com3d0835b2011-12-08 16:12:03 +0000140
bsalomon@google.com3d0835b2011-12-08 16:12:03 +0000141 /**
bsalomon@google.comd46e2422011-09-23 17:40:07 +0000142 * Color alpha and coverage are two inputs to the drawing pipeline. For some
143 * blend modes it is safe to fold the coverage into constant or per-vertex
144 * color alpha value. For other blend modes they must be handled separately.
145 * Depending on features available in the underlying 3D API this may or may
146 * not be possible.
147 *
bsalomon@google.come79c8152012-03-29 19:07:12 +0000148 * This function considers the current draw state and the draw target's
149 * capabilities to determine whether coverage can be handled correctly. The
150 * following assumptions are made:
151 * 1. The caller intends to somehow specify coverage. This can be
152 * specified either by enabling a coverage stage on the GrDrawState or
153 * via the vertex layout.
bsalomon@google.com2b446732013-02-12 16:47:41 +0000154 * 2. Other than enabling coverage stages or enabling coverage in the
155 * layout, the current configuration of the target's GrDrawState is as
156 * it will be at draw time.
bsalomon@google.comd46e2422011-09-23 17:40:07 +0000157 */
158 bool canApplyCoverage() const;
159
160 /**
bsalomon@google.com2b446732013-02-12 16:47:41 +0000161 * Given the current draw state and hw support, will HW AA lines be used (if
162 * a line primitive type is drawn)?
bsalomon@google.com471d4712011-08-23 15:45:25 +0000163 */
tomhudson@google.com93813632011-10-27 20:21:16 +0000164 bool willUseHWAALines() const;
bsalomon@google.com471d4712011-08-23 15:45:25 +0000165
bsalomon@google.com3d0835b2011-12-08 16:12:03 +0000166 /**
bsalomon@google.come3d70952012-03-13 12:40:53 +0000167 * There are three types of "sources" of geometry (vertices and indices) for
168 * draw calls made on the target. When performing an indexed draw, the
169 * indices and vertices can use different source types. Once a source is
bsalomon@google.com934c5702012-03-20 21:17:58 +0000170 * specified it can be used for multiple draws. However, the time at which
171 * the geometry data is no longer editable depends on the source type.
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000172 *
173 * Sometimes it is necessary to perform a draw while upstack code has
bsalomon@google.come3d70952012-03-13 12:40:53 +0000174 * already specified geometry that it isn't finished with. So there are push
175 * and pop methods. This allows the client to push the sources, draw
176 * something using alternate sources, and then pop to restore the original
177 * sources.
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000178 *
bsalomon@google.come3d70952012-03-13 12:40:53 +0000179 * Aside from pushes and pops, a source remains valid until another source
180 * is set or resetVertexSource / resetIndexSource is called. Drawing from
181 * a reset source is an error.
182 *
183 * The three types of sources are:
184 *
185 * 1. A cpu array (set*SourceToArray). This is useful when the caller
186 * already provided vertex data in a format compatible with a
187 * GrVertexLayout. The data in the array is consumed at the time that
188 * set*SourceToArray is called and subsequent edits to the array will not
189 * be reflected in draws.
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000190 *
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000191 * 2. Reserve. This is most useful when the caller has data it must
192 * transform before drawing and is not long-lived. The caller requests
193 * that the draw target make room for some amount of vertex and/or index
194 * data. The target provides ptrs to hold the vertex and/or index data.
195 *
rmistry@google.comd6176b02012-08-23 18:14:13 +0000196 * The data is writable up until the next drawIndexed, drawNonIndexed,
bsalomon@google.com934c5702012-03-20 21:17:58 +0000197 * drawIndexedInstances, or pushGeometrySource. At this point the data is
198 * frozen and the ptrs are no longer valid.
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000199 *
bsalomon@google.come3d70952012-03-13 12:40:53 +0000200 * Where the space is allocated and how it is uploaded to the GPU is
201 * subclass-dependent.
202 *
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000203 * 3. Vertex and Index Buffers. This is most useful for geometry that will
bsalomon@google.come3d70952012-03-13 12:40:53 +0000204 * is long-lived. When the data in the buffer is consumed depends on the
rmistry@google.comd6176b02012-08-23 18:14:13 +0000205 * GrDrawTarget subclass. For deferred subclasses the caller has to
bsalomon@google.come3d70952012-03-13 12:40:53 +0000206 * guarantee that the data is still available in the buffers at playback.
207 * (TODO: Make this more automatic as we have done for read/write pixels)
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000208 *
209 * The size of each vertex is determined by querying the current GrDrawState.
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000210 */
211
212 /**
bsalomon@google.come3d70952012-03-13 12:40:53 +0000213 * Reserves space for vertices and/or indices. Zero can be specifed as
214 * either the vertex or index count if the caller desires to only reserve
rmistry@google.comd6176b02012-08-23 18:14:13 +0000215 * space for only indices or only vertices. If zero is specifed for
bsalomon@google.come3d70952012-03-13 12:40:53 +0000216 * vertexCount then the vertex source will be unmodified and likewise for
217 * indexCount.
reed@google.comac10a2d2010-12-22 21:39:39 +0000218 *
bsalomon@google.come3d70952012-03-13 12:40:53 +0000219 * If the function returns true then the reserve suceeded and the vertices
220 * and indices pointers will point to the space created.
reed@google.comac10a2d2010-12-22 21:39:39 +0000221 *
bsalomon@google.come3d70952012-03-13 12:40:53 +0000222 * If the target cannot make space for the request then this function will
223 * return false. If vertexCount was non-zero then upon failure the vertex
224 * source is reset and likewise for indexCount.
reed@google.comac10a2d2010-12-22 21:39:39 +0000225 *
bsalomon@google.come3d70952012-03-13 12:40:53 +0000226 * The pointers to the space allocated for vertices and indices remain valid
bsalomon@google.com934c5702012-03-20 21:17:58 +0000227 * until a drawIndexed, drawNonIndexed, drawIndexedInstances, or push/
228 * popGeomtrySource is called. At that point logically a snapshot of the
229 * data is made and the pointers are invalid.
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000230 *
bsalomon@google.come3d70952012-03-13 12:40:53 +0000231 * @param vertexCount the number of vertices to reserve space for. Can be
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000232 * 0. Vertex size is queried from the current GrDrawState.
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000233 * @param indexCount the number of indices to reserve space for. Can be 0.
bsalomon@google.come3d70952012-03-13 12:40:53 +0000234 * @param vertices will point to reserved vertex space if vertexCount is
rmistry@google.comd6176b02012-08-23 18:14:13 +0000235 * non-zero. Illegal to pass NULL if vertexCount > 0.
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000236 * @param indices will point to reserved index space if indexCount is
237 * non-zero. Illegal to pass NULL if indexCount > 0.
238 */
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000239 bool reserveVertexAndIndexSpace(int vertexCount,
bsalomon@google.com97805382012-03-13 14:32:07 +0000240 int indexCount,
241 void** vertices,
242 void** indices);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000243
reed@google.comac10a2d2010-12-22 21:39:39 +0000244 /**
245 * Provides hints to caller about the number of vertices and indices
246 * that can be allocated cheaply. This can be useful if caller is reserving
247 * space but doesn't know exactly how much geometry is needed.
248 *
249 * Also may hint whether the draw target should be flushed first. This is
250 * useful for deferred targets.
251 *
reed@google.comac10a2d2010-12-22 21:39:39 +0000252 * @param vertexCount in: hint about how many vertices the caller would
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000253 * like to allocate. Vertex size is queried from the
254 * current GrDrawState.
reed@google.comac10a2d2010-12-22 21:39:39 +0000255 * out: a hint about the number of vertices that can be
256 * allocated cheaply. Negative means no hint.
257 * Ignored if NULL.
258 * @param indexCount in: hint about how many indices the caller would
259 * like to allocate.
260 * out: a hint about the number of indices that can be
261 * allocated cheaply. Negative means no hint.
262 * Ignored if NULL.
263 *
264 * @return true if target should be flushed based on the input values.
265 */
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000266 virtual bool geometryHints(int* vertexCount,
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000267 int* indexCount) const;
reed@google.comac10a2d2010-12-22 21:39:39 +0000268
269 /**
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000270 * Sets source of vertex data for the next draw. Array must contain
271 * the vertex data when this is called.
reed@google.comac10a2d2010-12-22 21:39:39 +0000272 *
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000273 * @param vertexArray cpu array containing vertex data.
skia.committer@gmail.comae683922013-02-06 07:01:54 +0000274 * @param vertexCount the number of vertices in the array. Vertex size is
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000275 * queried from the current GrDrawState.
reed@google.comac10a2d2010-12-22 21:39:39 +0000276 */
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000277 void setVertexSourceToArray(const void* vertexArray, int vertexCount);
reed@google.comac10a2d2010-12-22 21:39:39 +0000278
279 /**
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000280 * Sets source of index data for the next indexed draw. Array must contain
281 * the indices when this is called.
reed@google.comac10a2d2010-12-22 21:39:39 +0000282 *
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000283 * @param indexArray cpu array containing index data.
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000284 * @param indexCount the number of indices in the array.
reed@google.comac10a2d2010-12-22 21:39:39 +0000285 */
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000286 void setIndexSourceToArray(const void* indexArray, int indexCount);
reed@google.comac10a2d2010-12-22 21:39:39 +0000287
288 /**
289 * Sets source of vertex data for the next draw. Data does not have to be
bsalomon@google.com934c5702012-03-20 21:17:58 +0000290 * in the buffer until drawIndexed, drawNonIndexed, or drawIndexedInstances.
reed@google.comac10a2d2010-12-22 21:39:39 +0000291 *
292 * @param buffer vertex buffer containing vertex data. Must be
skia.committer@gmail.comae683922013-02-06 07:01:54 +0000293 * unlocked before draw call. Vertex size is queried
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000294 * from current GrDrawState.
reed@google.comac10a2d2010-12-22 21:39:39 +0000295 */
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000296 void setVertexSourceToBuffer(const GrVertexBuffer* buffer);
reed@google.comac10a2d2010-12-22 21:39:39 +0000297
298 /**
299 * Sets source of index data for the next indexed draw. Data does not have
bsalomon@google.com934c5702012-03-20 21:17:58 +0000300 * to be in the buffer until drawIndexed.
reed@google.comac10a2d2010-12-22 21:39:39 +0000301 *
302 * @param buffer index buffer containing indices. Must be unlocked
303 * before indexed draw call.
304 */
305 void setIndexSourceToBuffer(const GrIndexBuffer* buffer);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000306
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000307 /**
308 * Resets vertex source. Drawing from reset vertices is illegal. Set vertex
309 * source to reserved, array, or buffer before next draw. May be able to free
310 * up temporary storage allocated by setVertexSourceToArray or
311 * reserveVertexSpace.
312 */
313 void resetVertexSource();
rmistry@google.comd6176b02012-08-23 18:14:13 +0000314
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000315 /**
316 * Resets index source. Indexed Drawing from reset indices is illegal. Set
317 * index source to reserved, array, or buffer before next indexed draw. May
318 * be able to free up temporary storage allocated by setIndexSourceToArray
319 * or reserveIndexSpace.
320 */
bsalomon@google.com97805382012-03-13 14:32:07 +0000321 void resetIndexSource();
rmistry@google.comd6176b02012-08-23 18:14:13 +0000322
bsalomon@google.com97805382012-03-13 14:32:07 +0000323 /**
324 * Query to find out if the vertex or index source is reserved.
325 */
326 bool hasReservedVerticesOrIndices() const {
bsalomon@google.com73d98aa2012-03-13 14:41:19 +0000327 return kReserved_GeometrySrcType == this->getGeomSrc().fVertexSrc ||
bsalomon@google.com97805382012-03-13 14:32:07 +0000328 kReserved_GeometrySrcType == this->getGeomSrc().fIndexSrc;
329 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000330
331 /**
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000332 * Pushes and resets the vertex/index sources. Any reserved vertex / index
333 * data is finalized (i.e. cannot be updated after the matching pop but can
334 * be drawn from). Must be balanced by a pop.
335 */
336 void pushGeometrySource();
337
338 /**
339 * Pops the vertex / index sources from the matching push.
340 */
341 void popGeometrySource();
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000342
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000343 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000344 * Draws indexed geometry using the current state and current vertex / index
345 * sources.
346 *
347 * @param type The type of primitives to draw.
348 * @param startVertex the vertex in the vertex array/buffer corresponding
349 * to index 0
350 * @param startIndex first index to read from index src.
351 * @param vertexCount one greater than the max index.
352 * @param indexCount the number of index elements to read. The index count
353 * is effectively trimmed to the last completely
354 * specified primitive.
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000355 * @param devBounds optional bounds hint. This is a promise from the caller,
356 * not a request for clipping.
reed@google.comac10a2d2010-12-22 21:39:39 +0000357 */
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000358 void drawIndexed(GrPrimitiveType type,
359 int startVertex,
360 int startIndex,
361 int vertexCount,
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000362 int indexCount,
363 const SkRect* devBounds = NULL);
reed@google.comac10a2d2010-12-22 21:39:39 +0000364
365 /**
366 * Draws non-indexed geometry using the current state and current vertex
367 * sources.
368 *
369 * @param type The type of primitives to draw.
370 * @param startVertex the vertex in the vertex array/buffer corresponding
371 * to index 0
372 * @param vertexCount one greater than the max index.
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000373 * @param devBounds optional bounds hint. This is a promise from the caller,
374 * not a request for clipping.
reed@google.comac10a2d2010-12-22 21:39:39 +0000375 */
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000376 void drawNonIndexed(GrPrimitiveType type,
377 int startVertex,
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000378 int vertexCount,
379 const SkRect* devBounds = NULL);
reed@google.comac10a2d2010-12-22 21:39:39 +0000380
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000381 /**
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000382 * Draws path into the stencil buffer. The fill must be either even/odd or
383 * winding (not inverse or hairline). It will respect the HW antialias flag
384 * on the draw state (if possible in the 3D API).
385 */
sugoi@google.com5f74cf82012-12-17 21:16:45 +0000386 void stencilPath(const GrPath*, const SkStrokeRec& stroke, SkPath::FillType fill);
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000387
388 /**
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000389 * Helper function for drawing rects. This does not use the current index
390 * and vertex sources. After returning, the vertex and index sources may
391 * have changed. They should be reestablished before the next drawIndexed
392 * or drawNonIndexed. This cannot be called between reserving and releasing
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000393 * geometry.
skia.committer@gmail.com044679e2013-02-15 07:16:57 +0000394 *
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000395 * A subclass may override this to perform more optimal rect rendering. Its
396 * draws should be funneled through one of the public GrDrawTarget draw methods
397 * (e.g. drawNonIndexed, drawIndexedInstances, ...). The base class draws a two
398 * triangle fan using drawNonIndexed from reserved vertex space.
skia.committer@gmail.com044679e2013-02-15 07:16:57 +0000399 *
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000400 * @param rect the rect to draw
401 * @param matrix optional matrix applied to rect (before viewMatrix)
jvanverth@google.com39768252013-02-14 15:25:44 +0000402 * @param srcRects specifies rect for explicit texture coordinates.
403 * if srcRect is non-NULL then that rect will be used
404 * as the coordinates for the given stage.
405 * @param srcMatrix optional matrix applied to srcRect. If
skia.committer@gmail.com044679e2013-02-15 07:16:57 +0000406 * srcRect is non-NULL and srcMatrix is non-NULL
407 * then srcRect will be transformed by srcMatrix.
jvanverth@google.com39768252013-02-14 15:25:44 +0000408 * srcMatrix can be NULL when no srcMatrix is desired.
skia.committer@gmail.com044679e2013-02-15 07:16:57 +0000409 * @param stage the stage to be given explicit texture coordinates.
jvanverth@google.com39768252013-02-14 15:25:44 +0000410 * Ignored if srcRect is NULL.
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000411 */
bsalomon@google.comd302f142011-03-03 13:54:13 +0000412 virtual void drawRect(const GrRect& rect,
bsalomon@google.comb9086a02012-11-01 18:02:54 +0000413 const SkMatrix* matrix,
jvanverth@google.com39768252013-02-14 15:25:44 +0000414 const GrRect* srcRect,
415 const SkMatrix* srcMatrix,
416 int stage);
417
bsalomon@google.comcf939ae2012-12-13 19:59:23 +0000418 /**
419 * Helper for drawRect when the caller doesn't need separate src rects or
420 * matrices.
421 */
422 void drawSimpleRect(const GrRect& rect, const SkMatrix* matrix = NULL) {
jvanverth@google.com39768252013-02-14 15:25:44 +0000423 drawRect(rect, matrix, NULL, NULL, 0);
bsalomon@google.comcf939ae2012-12-13 19:59:23 +0000424 }
425 void drawSimpleRect(const GrIRect& irect, const SkMatrix* matrix = NULL) {
426 SkRect rect = SkRect::MakeFromIRect(irect);
jvanverth@google.com39768252013-02-14 15:25:44 +0000427 this->drawRect(rect, matrix, NULL, NULL, 0);
bsalomon@google.comcf939ae2012-12-13 19:59:23 +0000428 }
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000429
430 /**
bsalomon@google.com934c5702012-03-20 21:17:58 +0000431 * This call is used to draw multiple instances of some geometry with a
432 * given number of vertices (V) and indices (I) per-instance. The indices in
433 * the index source must have the form i[k+I] == i[k] + V. Also, all indices
434 * i[kI] ... i[(k+1)I-1] must be elements of the range kV ... (k+1)V-1. As a
435 * concrete example, the following index buffer for drawing a series of
436 * quads each as two triangles each satisfies these conditions with V=4 and
437 * I=6:
438 * (0,1,2,0,2,3, 4,5,6,4,6,7, 8,9,10,8,10,11, ...)
439 *
440 * The call assumes that the pattern of indices fills the entire index
441 * source. The size of the index buffer limits the number of instances that
442 * can be drawn by the GPU in a single draw. However, the caller may specify
443 * any (positive) number for instanceCount and if necessary multiple GPU
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000444 * draws will be issued. Moreover, when drawIndexedInstances is called
bsalomon@google.com934c5702012-03-20 21:17:58 +0000445 * multiple times it may be possible for GrDrawTarget to group them into a
446 * single GPU draw.
447 *
448 * @param type the type of primitives to draw
449 * @param instanceCount the number of instances to draw. Each instance
450 * consists of verticesPerInstance vertices indexed by
451 * indicesPerInstance indices drawn as the primitive
452 * type specified by type.
453 * @param verticesPerInstance The number of vertices in each instance (V
454 * in the above description).
455 * @param indicesPerInstance The number of indices in each instance (I
456 * in the above description).
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000457 * @param devBounds optional bounds hint. This is a promise from the caller,
458 * not a request for clipping.
bsalomon@google.com934c5702012-03-20 21:17:58 +0000459 */
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000460 void drawIndexedInstances(GrPrimitiveType type,
461 int instanceCount,
462 int verticesPerInstance,
463 int indicesPerInstance,
464 const SkRect* devBounds = NULL);
bsalomon@google.com934c5702012-03-20 21:17:58 +0000465
466 /**
rmistry@google.comd6176b02012-08-23 18:14:13 +0000467 * Clear the current render target if one isn't passed in. Ignores the
468 * clip and all other draw state (blend mode, stages, etc). Clears the
robertphillips@google.comc82a8b72012-06-21 20:15:48 +0000469 * whole thing if rect is NULL, otherwise just the rect.
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000470 */
rmistry@google.comd6176b02012-08-23 18:14:13 +0000471 virtual void clear(const GrIRect* rect,
robertphillips@google.comc82a8b72012-06-21 20:15:48 +0000472 GrColor color,
473 GrRenderTarget* renderTarget = NULL) = 0;
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000474
robertphillips@google.comff175842012-05-14 19:31:39 +0000475 /**
476 * Release any resources that are cached but not currently in use. This
477 * is intended to give an application some recourse when resources are low.
478 */
479 virtual void purgeResources() {};
480
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000481 /**
482 * For subclass internal use to invoke a call to onDraw(). See DrawInfo below.
483 */
484 void executeDraw(const DrawInfo& info) { this->onDraw(info); }
485
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000486 ////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +0000487
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000488 /**
489 * See AutoStateRestore below.
490 */
491 enum ASRInit {
492 kPreserve_ASRInit,
493 kReset_ASRInit
494 };
495
496 /**
497 * Saves off the current state and restores it in the destructor. It will
498 * install a new GrDrawState object on the target (setDrawState) and restore
499 * the previous one in the destructor. The caller should call drawState() to
500 * get the new draw state after the ASR is installed.
501 *
502 * GrDrawState* state = target->drawState();
503 * AutoStateRestore asr(target, GrDrawTarget::kReset_ASRInit).
504 * state->setRenderTarget(rt); // state refers to the GrDrawState set on
505 * // target before asr was initialized.
506 * // Therefore, rt is set on the GrDrawState
507 * // that will be restored after asr's
508 * // destructor rather than target's current
rmistry@google.comd6176b02012-08-23 18:14:13 +0000509 * // GrDrawState.
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000510 */
reed@google.comac10a2d2010-12-22 21:39:39 +0000511 class AutoStateRestore : ::GrNoncopyable {
512 public:
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000513 /**
514 * Default ASR will have no effect unless set() is subsequently called.
515 */
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000516 AutoStateRestore();
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000517
518 /**
519 * Saves the state on target. The state will be restored when the ASR
520 * is destroyed. If this constructor is used do not call set().
521 *
522 * @param init Should the newly installed GrDrawState be a copy of the
523 * previous state or a default-initialized GrDrawState.
524 */
525 AutoStateRestore(GrDrawTarget* target, ASRInit init);
526
reed@google.comac10a2d2010-12-22 21:39:39 +0000527 ~AutoStateRestore();
528
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000529 /**
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000530 * Saves the state on target. The state will be restored when the ASR
531 * is destroyed. This should only be called once per ASR object and only
532 * when the default constructor was used. For nested saves use multiple
533 * ASR objects.
534 *
535 * @param init Should the newly installed GrDrawState be a copy of the
536 * previous state or a default-initialized GrDrawState.
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000537 */
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000538 void set(GrDrawTarget* target, ASRInit init);
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000539
reed@google.comac10a2d2010-12-22 21:39:39 +0000540 private:
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000541 GrDrawTarget* fDrawTarget;
542 SkTLazy<GrDrawState> fTempState;
543 GrDrawState* fSavedState;
reed@google.comac10a2d2010-12-22 21:39:39 +0000544 };
545
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000546 ////////////////////////////////////////////////////////////////////////////
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000547
reed@google.comac10a2d2010-12-22 21:39:39 +0000548 class AutoReleaseGeometry : ::GrNoncopyable {
549 public:
550 AutoReleaseGeometry(GrDrawTarget* target,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000551 int vertexCount,
552 int indexCount);
553 AutoReleaseGeometry();
554 ~AutoReleaseGeometry();
bsalomon@google.com5782d712011-01-21 21:03:59 +0000555 bool set(GrDrawTarget* target,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000556 int vertexCount,
557 int indexCount);
bsalomon@google.coma47a48d2011-04-26 20:22:11 +0000558 bool succeeded() const { return NULL != fTarget; }
bsalomon@google.com6513cd02011-08-05 20:12:30 +0000559 void* vertices() const { GrAssert(this->succeeded()); return fVertices; }
560 void* indices() const { GrAssert(this->succeeded()); return fIndices; }
reed@google.comac10a2d2010-12-22 21:39:39 +0000561 GrPoint* positions() const {
bsalomon@google.com6513cd02011-08-05 20:12:30 +0000562 return static_cast<GrPoint*>(this->vertices());
reed@google.comac10a2d2010-12-22 21:39:39 +0000563 }
564
565 private:
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000566 void reset();
rmistry@google.comd6176b02012-08-23 18:14:13 +0000567
reed@google.comac10a2d2010-12-22 21:39:39 +0000568 GrDrawTarget* fTarget;
reed@google.comac10a2d2010-12-22 21:39:39 +0000569 void* fVertices;
570 void* fIndices;
571 };
572
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000573 ////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +0000574
575 class AutoClipRestore : ::GrNoncopyable {
576 public:
577 AutoClipRestore(GrDrawTarget* target) {
578 fTarget = target;
579 fClip = fTarget->getClip();
580 }
581
bsalomon@google.com8d67c072012-12-13 20:38:14 +0000582 AutoClipRestore(GrDrawTarget* target, const SkIRect& newClip);
583
reed@google.comac10a2d2010-12-22 21:39:39 +0000584 ~AutoClipRestore() {
585 fTarget->setClip(fClip);
586 }
587 private:
bsalomon@google.com8d67c072012-12-13 20:38:14 +0000588 GrDrawTarget* fTarget;
589 const GrClipData* fClip;
590 SkTLazy<SkClipStack> fStack;
591 GrClipData fReplacementClip;
reed@google.comac10a2d2010-12-22 21:39:39 +0000592 };
rmistry@google.comd6176b02012-08-23 18:14:13 +0000593
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000594 ////////////////////////////////////////////////////////////////////////////
rmistry@google.comd6176b02012-08-23 18:14:13 +0000595
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000596 class AutoGeometryAndStatePush : ::GrNoncopyable {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000597 public:
skia.committer@gmail.comae683922013-02-06 07:01:54 +0000598 AutoGeometryAndStatePush(GrDrawTarget* target, ASRInit init)
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000599 : fState(target, init) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000600 GrAssert(NULL != target);
601 fTarget = target;
602 target->pushGeometrySource();
603 }
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000604 ~AutoGeometryAndStatePush() {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000605 fTarget->popGeometrySource();
606 }
607 private:
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000608 GrDrawTarget* fTarget;
609 AutoStateRestore fState;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000610 };
reed@google.comac10a2d2010-12-22 21:39:39 +0000611
reed@google.comac10a2d2010-12-22 21:39:39 +0000612protected:
bsalomon@google.com471d4712011-08-23 15:45:25 +0000613
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000614 enum GeometrySrcType {
615 kNone_GeometrySrcType, //<! src has not been specified
616 kReserved_GeometrySrcType, //<! src was set using reserve*Space
617 kArray_GeometrySrcType, //<! src was set using set*SourceToArray
618 kBuffer_GeometrySrcType //<! src was set using set*SourceToBuffer
619 };
rmistry@google.comd6176b02012-08-23 18:14:13 +0000620
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000621 struct GeometrySrcState {
622 GeometrySrcType fVertexSrc;
623 union {
624 // valid if src type is buffer
625 const GrVertexBuffer* fVertexBuffer;
626 // valid if src type is reserved or array
627 int fVertexCount;
628 };
rmistry@google.comd6176b02012-08-23 18:14:13 +0000629
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000630 GeometrySrcType fIndexSrc;
631 union {
632 // valid if src type is buffer
633 const GrIndexBuffer* fIndexBuffer;
634 // valid if src type is reserved or array
635 int fIndexCount;
636 };
rmistry@google.comd6176b02012-08-23 18:14:13 +0000637
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000638 size_t fVertexSize;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000639 };
bsalomon@google.com934c5702012-03-20 21:17:58 +0000640
641 int indexCountInCurrentSource() const {
642 const GeometrySrcState& src = this->getGeomSrc();
643 switch (src.fIndexSrc) {
644 case kNone_GeometrySrcType:
645 return 0;
646 case kReserved_GeometrySrcType:
647 case kArray_GeometrySrcType:
648 return src.fIndexCount;
649 case kBuffer_GeometrySrcType:
650 return src.fIndexBuffer->sizeInBytes() / sizeof(uint16_t);
651 default:
652 GrCrash("Unexpected Index Source.");
653 return 0;
654 }
655 }
bsalomon@google.coma47a48d2011-04-26 20:22:11 +0000656
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000657 GrContext* getContext() { return fContext; }
658 const GrContext* getContext() const { return fContext; }
659
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000660 // allows derived class to set the caps
661 CapsInternals* capsInternals() { return &fCaps.fInternals; }
662
663 // A subclass may override this function if it wishes to be notified when the clip is changed.
664 // The override should call INHERITED::clipWillBeSet().
665 virtual void clipWillBeSet(const GrClipData* clipData);
666
667 // subclasses must call this in their destructors to ensure all vertex
668 // and index sources have been released (including those held by
669 // pushGeometrySource())
670 void releaseGeometry();
671
672 // accessors for derived classes
673 const GeometrySrcState& getGeomSrc() const { return fGeoSrcStateStack.back(); }
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000674 // it is preferable to call this rather than getGeomSrc()->fVertexSize because of the assert.
675 size_t getVertexSize() const {
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000676 // the vertex layout is only valid if a vertex source has been specified.
677 GrAssert(this->getGeomSrc().fVertexSrc != kNone_GeometrySrcType);
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000678 return this->getGeomSrc().fVertexSize;
bsalomon@google.coma47a48d2011-04-26 20:22:11 +0000679 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000680
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000681 Caps fCaps;
682
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000683 /**
684 * Used to communicate draws to subclass's onDraw function.
685 */
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000686 class DrawInfo {
687 public:
688 DrawInfo(const DrawInfo& di) { (*this) = di; }
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000689 DrawInfo& operator =(const DrawInfo& di);
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000690
691 GrPrimitiveType primitiveType() const { return fPrimitiveType; }
692 int startVertex() const { return fStartVertex; }
693 int startIndex() const { return fStartIndex; }
694 int vertexCount() const { return fVertexCount; }
695 int indexCount() const { return fIndexCount; }
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000696 int verticesPerInstance() const { return fVerticesPerInstance; }
697 int indicesPerInstance() const { return fIndicesPerInstance; }
698 int instanceCount() const { return fInstanceCount; }
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000699
700 bool isIndexed() const { return fIndexCount > 0; }
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000701#if GR_DEBUG
702 bool isInstanced() const; // this version is longer because of asserts
703#else
704 bool isInstanced() const { return fInstanceCount > 0; }
705#endif
706
707 // adds or remove instances
708 void adjustInstanceCount(int instanceOffset);
709 // shifts the start vertex
710 void adjustStartVertex(int vertexOffset);
711 // shifts the start index
712 void adjustStartIndex(int indexOffset);
713
714 void setDevBounds(const SkRect& bounds) {
715 fDevBoundsStorage = bounds;
716 fDevBounds = &fDevBoundsStorage;
717 }
718 const SkRect* getDevBounds() const { return fDevBounds; }
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000719
720 private:
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000721 DrawInfo() { fDevBounds = NULL; }
722
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000723 friend class GrDrawTarget;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000724
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000725 GrPrimitiveType fPrimitiveType;
726
727 int fStartVertex;
728 int fStartIndex;
729 int fVertexCount;
730 int fIndexCount;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000731
732 int fInstanceCount;
733 int fVerticesPerInstance;
734 int fIndicesPerInstance;
735
736 SkRect fDevBoundsStorage;
737 SkRect* fDevBounds;
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000738 };
739
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000740private:
741 // A subclass can optionally overload this function to be notified before
742 // vertex and index space is reserved.
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000743 virtual void willReserveVertexAndIndexSpace(int vertexCount, int indexCount) {}
bsalomon@google.com97805382012-03-13 14:32:07 +0000744
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000745 // implemented by subclass to allocate space for reserved geom
jvanverth@google.coma6338982013-01-31 21:34:25 +0000746 virtual bool onReserveVertexSpace(size_t vertexSize, int vertexCount, void** vertices) = 0;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000747 virtual bool onReserveIndexSpace(int indexCount, void** indices) = 0;
748 // implemented by subclass to handle release of reserved geom space
749 virtual void releaseReservedVertexSpace() = 0;
750 virtual void releaseReservedIndexSpace() = 0;
751 // subclass must consume array contents when set
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000752 virtual void onSetVertexSourceToArray(const void* vertexArray, int vertexCount) = 0;
753 virtual void onSetIndexSourceToArray(const void* indexArray, int indexCount) = 0;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000754 // subclass is notified that geom source will be set away from an array
755 virtual void releaseVertexArray() = 0;
756 virtual void releaseIndexArray() = 0;
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000757 // subclass overrides to be notified just before geo src state is pushed/popped.
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000758 virtual void geometrySourceWillPush() = 0;
759 virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) = 0;
760 // subclass called to perform drawing
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000761 virtual void onDraw(const DrawInfo&) = 0;
sugoi@google.com5f74cf82012-12-17 21:16:45 +0000762 virtual void onStencilPath(const GrPath*, const SkStrokeRec& stroke, SkPath::FillType fill) = 0;
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000763
bsalomon@google.come3d70952012-03-13 12:40:53 +0000764 // helpers for reserving vertex and index space.
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000765 bool reserveVertexSpace(size_t vertexSize,
bsalomon@google.come3d70952012-03-13 12:40:53 +0000766 int vertexCount,
767 void** vertices);
768 bool reserveIndexSpace(int indexCount, void** indices);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000769
bsalomon@google.come8262622011-11-07 02:30:51 +0000770 // called by drawIndexed and drawNonIndexed. Use a negative indexCount to
771 // indicate non-indexed drawing.
772 bool checkDraw(GrPrimitiveType type, int startVertex,
773 int startIndex, int vertexCount,
774 int indexCount) const;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000775 // called when setting a new vert/idx source to unref prev vb/ib
776 void releasePreviousVertexSource();
777 void releasePreviousIndexSource();
rmistry@google.comd6176b02012-08-23 18:14:13 +0000778
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000779 enum {
780 kPreallocGeoSrcStateStackCnt = 4,
reed@google.comac10a2d2010-12-22 21:39:39 +0000781 };
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000782 SkSTArray<kPreallocGeoSrcStateStackCnt, GeometrySrcState, true> fGeoSrcStateStack;
783 const GrClipData* fClip;
784 GrDrawState* fDrawState;
785 GrDrawState fDefaultDrawState;
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000786 // The context owns us, not vice-versa, so this ptr is not ref'ed by DrawTarget.
787 GrContext* fContext;
reed@google.comfa35e3d2012-06-26 20:16:17 +0000788
789 typedef GrRefCnt INHERITED;
reed@google.comac10a2d2010-12-22 21:39:39 +0000790};
791
reed@google.comac10a2d2010-12-22 21:39:39 +0000792#endif