blob: 965b1b6176ca6b468cc1ab5fd8b5a7409b65e3e9 [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.com18c9c192011-09-22 21:01:31 +000048 int fMaxRenderTargetSize;
49 int fMaxTextureSize;
50 };
51
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000052 class DrawInfo;
53
bsalomon@google.comf6601872012-08-28 21:11:35 +000054public:
55 SK_DECLARE_INST_COUNT(GrDrawTarget)
56
57 /**
58 * Represents the draw target capabilities.
59 */
60 class Caps {
61 public:
62 Caps() { memset(this, 0, sizeof(Caps)); }
63 Caps(const Caps& c) { *this = c; }
64 Caps& operator= (const Caps& c) {
65 memcpy(this, &c, sizeof(Caps));
66 return *this;
67 }
68 void print() const;
69
70 bool eightBitPaletteSupport() const { return fInternals.f8BitPaletteSupport; }
71 bool npotTextureTileSupport() const { return fInternals.fNPOTTextureTileSupport; }
72 bool twoSidedStencilSupport() const { return fInternals.fTwoSidedStencilSupport; }
73 bool stencilWrapOpsSupport() const { return fInternals.fStencilWrapOpsSupport; }
74 bool hwAALineSupport() const { return fInternals.fHWAALineSupport; }
75 bool shaderDerivativeSupport() const { return fInternals.fShaderDerivativeSupport; }
76 bool geometryShaderSupport() const { return fInternals.fGeometryShaderSupport; }
77 bool fsaaSupport() const { return fInternals.fFSAASupport; }
78 bool dualSourceBlendingSupport() const { return fInternals.fDualSourceBlendingSupport; }
79 bool bufferLockSupport() const { return fInternals.fBufferLockSupport; }
80 bool pathStencilingSupport() const { return fInternals.fPathStencilingSupport; }
81
82 int maxRenderTargetSize() const { return fInternals.fMaxRenderTargetSize; }
83 int maxTextureSize() const { return fInternals.fMaxTextureSize; }
84 private:
85 CapsInternals fInternals;
bsalomon@google.com0d82fe52012-08-28 21:39:15 +000086 friend class GrDrawTarget; // to set values of fInternals
bsalomon@google.comf6601872012-08-28 21:11:35 +000087 };
88
reed@google.comac10a2d2010-12-22 21:39:39 +000089 ///////////////////////////////////////////////////////////////////////////
90
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000091 // The context may not be fully constructed and should not be used during GrDrawTarget
92 // construction.
93 GrDrawTarget(GrContext* context);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000094 virtual ~GrDrawTarget();
reed@google.comac10a2d2010-12-22 21:39:39 +000095
96 /**
bsalomon@google.com18c9c192011-09-22 21:01:31 +000097 * Gets the capabilities of the draw target.
98 */
99 const Caps& getCaps() const { return fCaps; }
100
101 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000102 * Sets the current clip to the region specified by clip. All draws will be
103 * clipped against this clip if kClip_StateBit is enabled.
104 *
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +0000105 * Setting the clip may (or may not) zero out the client's stencil bits.
106 *
reed@google.comac10a2d2010-12-22 21:39:39 +0000107 * @param description of the clipping region
108 */
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000109 void setClip(const GrClipData* clip);
reed@google.comac10a2d2010-12-22 21:39:39 +0000110
111 /**
112 * Gets the current clip.
113 *
114 * @return the clip.
115 */
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000116 const GrClipData* getClip() const;
reed@google.comac10a2d2010-12-22 21:39:39 +0000117
bsalomon@google.coma5d056a2012-03-27 15:59:58 +0000118 /**
119 * Sets the draw state object for the draw target. Note that this does not
120 * make a copy. The GrDrawTarget will take a reference to passed object.
121 * Passing NULL will cause the GrDrawTarget to use its own internal draw
122 * state object rather than an externally provided one.
123 */
124 void setDrawState(GrDrawState* drawState);
125
126 /**
127 * Read-only access to the GrDrawTarget's current draw state.
128 */
129 const GrDrawState& getDrawState() const { return *fDrawState; }
130
131 /**
132 * Read-write access to the GrDrawTarget's current draw state. Note that
133 * this doesn't ref.
134 */
135 GrDrawState* drawState() { return fDrawState; }
bsalomon@google.com3d0835b2011-12-08 16:12:03 +0000136
bsalomon@google.com3d0835b2011-12-08 16:12:03 +0000137 /**
bsalomon@google.comd46e2422011-09-23 17:40:07 +0000138 * Color alpha and coverage are two inputs to the drawing pipeline. For some
139 * blend modes it is safe to fold the coverage into constant or per-vertex
140 * color alpha value. For other blend modes they must be handled separately.
141 * Depending on features available in the underlying 3D API this may or may
142 * not be possible.
143 *
bsalomon@google.come79c8152012-03-29 19:07:12 +0000144 * This function considers the current draw state and the draw target's
145 * capabilities to determine whether coverage can be handled correctly. The
146 * following assumptions are made:
147 * 1. The caller intends to somehow specify coverage. This can be
148 * specified either by enabling a coverage stage on the GrDrawState or
149 * via the vertex layout.
bsalomon@google.com2b446732013-02-12 16:47:41 +0000150 * 2. Other than enabling coverage stages or enabling coverage in the
151 * layout, the current configuration of the target's GrDrawState is as
152 * it will be at draw time.
bsalomon@google.comd46e2422011-09-23 17:40:07 +0000153 */
154 bool canApplyCoverage() const;
155
156 /**
bsalomon@google.com2b446732013-02-12 16:47:41 +0000157 * Given the current draw state and hw support, will HW AA lines be used (if
158 * a line primitive type is drawn)?
bsalomon@google.com471d4712011-08-23 15:45:25 +0000159 */
tomhudson@google.com93813632011-10-27 20:21:16 +0000160 bool willUseHWAALines() const;
bsalomon@google.com471d4712011-08-23 15:45:25 +0000161
bsalomon@google.com3d0835b2011-12-08 16:12:03 +0000162 /**
bsalomon@google.come3d70952012-03-13 12:40:53 +0000163 * There are three types of "sources" of geometry (vertices and indices) for
164 * draw calls made on the target. When performing an indexed draw, the
165 * indices and vertices can use different source types. Once a source is
bsalomon@google.com934c5702012-03-20 21:17:58 +0000166 * specified it can be used for multiple draws. However, the time at which
167 * the geometry data is no longer editable depends on the source type.
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000168 *
169 * Sometimes it is necessary to perform a draw while upstack code has
bsalomon@google.come3d70952012-03-13 12:40:53 +0000170 * already specified geometry that it isn't finished with. So there are push
171 * and pop methods. This allows the client to push the sources, draw
172 * something using alternate sources, and then pop to restore the original
173 * sources.
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000174 *
bsalomon@google.come3d70952012-03-13 12:40:53 +0000175 * Aside from pushes and pops, a source remains valid until another source
176 * is set or resetVertexSource / resetIndexSource is called. Drawing from
177 * a reset source is an error.
178 *
179 * The three types of sources are:
180 *
181 * 1. A cpu array (set*SourceToArray). This is useful when the caller
182 * already provided vertex data in a format compatible with a
183 * GrVertexLayout. The data in the array is consumed at the time that
184 * set*SourceToArray is called and subsequent edits to the array will not
185 * be reflected in draws.
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000186 *
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000187 * 2. Reserve. This is most useful when the caller has data it must
188 * transform before drawing and is not long-lived. The caller requests
189 * that the draw target make room for some amount of vertex and/or index
190 * data. The target provides ptrs to hold the vertex and/or index data.
191 *
rmistry@google.comd6176b02012-08-23 18:14:13 +0000192 * The data is writable up until the next drawIndexed, drawNonIndexed,
bsalomon@google.com934c5702012-03-20 21:17:58 +0000193 * drawIndexedInstances, or pushGeometrySource. At this point the data is
194 * frozen and the ptrs are no longer valid.
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000195 *
bsalomon@google.come3d70952012-03-13 12:40:53 +0000196 * Where the space is allocated and how it is uploaded to the GPU is
197 * subclass-dependent.
198 *
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000199 * 3. Vertex and Index Buffers. This is most useful for geometry that will
bsalomon@google.come3d70952012-03-13 12:40:53 +0000200 * is long-lived. When the data in the buffer is consumed depends on the
rmistry@google.comd6176b02012-08-23 18:14:13 +0000201 * GrDrawTarget subclass. For deferred subclasses the caller has to
bsalomon@google.come3d70952012-03-13 12:40:53 +0000202 * guarantee that the data is still available in the buffers at playback.
203 * (TODO: Make this more automatic as we have done for read/write pixels)
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000204 *
205 * The size of each vertex is determined by querying the current GrDrawState.
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000206 */
207
208 /**
bsalomon@google.come3d70952012-03-13 12:40:53 +0000209 * Reserves space for vertices and/or indices. Zero can be specifed as
210 * either the vertex or index count if the caller desires to only reserve
rmistry@google.comd6176b02012-08-23 18:14:13 +0000211 * space for only indices or only vertices. If zero is specifed for
bsalomon@google.come3d70952012-03-13 12:40:53 +0000212 * vertexCount then the vertex source will be unmodified and likewise for
213 * indexCount.
reed@google.comac10a2d2010-12-22 21:39:39 +0000214 *
bsalomon@google.come3d70952012-03-13 12:40:53 +0000215 * If the function returns true then the reserve suceeded and the vertices
216 * and indices pointers will point to the space created.
reed@google.comac10a2d2010-12-22 21:39:39 +0000217 *
bsalomon@google.come3d70952012-03-13 12:40:53 +0000218 * If the target cannot make space for the request then this function will
219 * return false. If vertexCount was non-zero then upon failure the vertex
220 * source is reset and likewise for indexCount.
reed@google.comac10a2d2010-12-22 21:39:39 +0000221 *
bsalomon@google.come3d70952012-03-13 12:40:53 +0000222 * The pointers to the space allocated for vertices and indices remain valid
bsalomon@google.com934c5702012-03-20 21:17:58 +0000223 * until a drawIndexed, drawNonIndexed, drawIndexedInstances, or push/
224 * popGeomtrySource is called. At that point logically a snapshot of the
225 * data is made and the pointers are invalid.
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000226 *
bsalomon@google.come3d70952012-03-13 12:40:53 +0000227 * @param vertexCount the number of vertices to reserve space for. Can be
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000228 * 0. Vertex size is queried from the current GrDrawState.
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000229 * @param indexCount the number of indices to reserve space for. Can be 0.
bsalomon@google.come3d70952012-03-13 12:40:53 +0000230 * @param vertices will point to reserved vertex space if vertexCount is
rmistry@google.comd6176b02012-08-23 18:14:13 +0000231 * non-zero. Illegal to pass NULL if vertexCount > 0.
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000232 * @param indices will point to reserved index space if indexCount is
233 * non-zero. Illegal to pass NULL if indexCount > 0.
234 */
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000235 bool reserveVertexAndIndexSpace(int vertexCount,
bsalomon@google.com97805382012-03-13 14:32:07 +0000236 int indexCount,
237 void** vertices,
238 void** indices);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000239
reed@google.comac10a2d2010-12-22 21:39:39 +0000240 /**
241 * Provides hints to caller about the number of vertices and indices
242 * that can be allocated cheaply. This can be useful if caller is reserving
243 * space but doesn't know exactly how much geometry is needed.
244 *
245 * Also may hint whether the draw target should be flushed first. This is
246 * useful for deferred targets.
247 *
reed@google.comac10a2d2010-12-22 21:39:39 +0000248 * @param vertexCount in: hint about how many vertices the caller would
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000249 * like to allocate. Vertex size is queried from the
250 * current GrDrawState.
reed@google.comac10a2d2010-12-22 21:39:39 +0000251 * out: a hint about the number of vertices that can be
252 * allocated cheaply. Negative means no hint.
253 * Ignored if NULL.
254 * @param indexCount in: hint about how many indices the caller would
255 * like to allocate.
256 * out: a hint about the number of indices that can be
257 * allocated cheaply. Negative means no hint.
258 * Ignored if NULL.
259 *
260 * @return true if target should be flushed based on the input values.
261 */
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000262 virtual bool geometryHints(int* vertexCount,
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000263 int* indexCount) const;
reed@google.comac10a2d2010-12-22 21:39:39 +0000264
265 /**
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000266 * Sets source of vertex data for the next draw. Array must contain
267 * the vertex data when this is called.
reed@google.comac10a2d2010-12-22 21:39:39 +0000268 *
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000269 * @param vertexArray cpu array containing vertex data.
skia.committer@gmail.comae683922013-02-06 07:01:54 +0000270 * @param vertexCount the number of vertices in the array. Vertex size is
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000271 * queried from the current GrDrawState.
reed@google.comac10a2d2010-12-22 21:39:39 +0000272 */
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000273 void setVertexSourceToArray(const void* vertexArray, int vertexCount);
reed@google.comac10a2d2010-12-22 21:39:39 +0000274
275 /**
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000276 * Sets source of index data for the next indexed draw. Array must contain
277 * the indices when this is called.
reed@google.comac10a2d2010-12-22 21:39:39 +0000278 *
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000279 * @param indexArray cpu array containing index data.
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000280 * @param indexCount the number of indices in the array.
reed@google.comac10a2d2010-12-22 21:39:39 +0000281 */
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000282 void setIndexSourceToArray(const void* indexArray, int indexCount);
reed@google.comac10a2d2010-12-22 21:39:39 +0000283
284 /**
285 * Sets source of vertex data for the next draw. Data does not have to be
bsalomon@google.com934c5702012-03-20 21:17:58 +0000286 * in the buffer until drawIndexed, drawNonIndexed, or drawIndexedInstances.
reed@google.comac10a2d2010-12-22 21:39:39 +0000287 *
288 * @param buffer vertex buffer containing vertex data. Must be
skia.committer@gmail.comae683922013-02-06 07:01:54 +0000289 * unlocked before draw call. Vertex size is queried
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000290 * from current GrDrawState.
reed@google.comac10a2d2010-12-22 21:39:39 +0000291 */
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000292 void setVertexSourceToBuffer(const GrVertexBuffer* buffer);
reed@google.comac10a2d2010-12-22 21:39:39 +0000293
294 /**
295 * Sets source of index data for the next indexed draw. Data does not have
bsalomon@google.com934c5702012-03-20 21:17:58 +0000296 * to be in the buffer until drawIndexed.
reed@google.comac10a2d2010-12-22 21:39:39 +0000297 *
298 * @param buffer index buffer containing indices. Must be unlocked
299 * before indexed draw call.
300 */
301 void setIndexSourceToBuffer(const GrIndexBuffer* buffer);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000302
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000303 /**
304 * Resets vertex source. Drawing from reset vertices is illegal. Set vertex
305 * source to reserved, array, or buffer before next draw. May be able to free
306 * up temporary storage allocated by setVertexSourceToArray or
307 * reserveVertexSpace.
308 */
309 void resetVertexSource();
rmistry@google.comd6176b02012-08-23 18:14:13 +0000310
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000311 /**
312 * Resets index source. Indexed Drawing from reset indices is illegal. Set
313 * index source to reserved, array, or buffer before next indexed draw. May
314 * be able to free up temporary storage allocated by setIndexSourceToArray
315 * or reserveIndexSpace.
316 */
bsalomon@google.com97805382012-03-13 14:32:07 +0000317 void resetIndexSource();
rmistry@google.comd6176b02012-08-23 18:14:13 +0000318
bsalomon@google.com97805382012-03-13 14:32:07 +0000319 /**
320 * Query to find out if the vertex or index source is reserved.
321 */
322 bool hasReservedVerticesOrIndices() const {
bsalomon@google.com73d98aa2012-03-13 14:41:19 +0000323 return kReserved_GeometrySrcType == this->getGeomSrc().fVertexSrc ||
bsalomon@google.com97805382012-03-13 14:32:07 +0000324 kReserved_GeometrySrcType == this->getGeomSrc().fIndexSrc;
325 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000326
327 /**
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000328 * Pushes and resets the vertex/index sources. Any reserved vertex / index
329 * data is finalized (i.e. cannot be updated after the matching pop but can
330 * be drawn from). Must be balanced by a pop.
331 */
332 void pushGeometrySource();
333
334 /**
335 * Pops the vertex / index sources from the matching push.
336 */
337 void popGeometrySource();
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000338
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000339 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000340 * Draws indexed geometry using the current state and current vertex / index
341 * sources.
342 *
343 * @param type The type of primitives to draw.
344 * @param startVertex the vertex in the vertex array/buffer corresponding
345 * to index 0
346 * @param startIndex first index to read from index src.
347 * @param vertexCount one greater than the max index.
348 * @param indexCount the number of index elements to read. The index count
349 * is effectively trimmed to the last completely
350 * specified primitive.
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000351 * @param devBounds optional bounds hint. This is a promise from the caller,
352 * not a request for clipping.
reed@google.comac10a2d2010-12-22 21:39:39 +0000353 */
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000354 void drawIndexed(GrPrimitiveType type,
355 int startVertex,
356 int startIndex,
357 int vertexCount,
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000358 int indexCount,
359 const SkRect* devBounds = NULL);
reed@google.comac10a2d2010-12-22 21:39:39 +0000360
361 /**
362 * Draws non-indexed geometry using the current state and current vertex
363 * sources.
364 *
365 * @param type The type of primitives to draw.
366 * @param startVertex the vertex in the vertex array/buffer corresponding
367 * to index 0
368 * @param vertexCount one greater than the max index.
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000369 * @param devBounds optional bounds hint. This is a promise from the caller,
370 * not a request for clipping.
reed@google.comac10a2d2010-12-22 21:39:39 +0000371 */
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000372 void drawNonIndexed(GrPrimitiveType type,
373 int startVertex,
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000374 int vertexCount,
375 const SkRect* devBounds = NULL);
reed@google.comac10a2d2010-12-22 21:39:39 +0000376
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000377 /**
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000378 * Draws path into the stencil buffer. The fill must be either even/odd or
379 * winding (not inverse or hairline). It will respect the HW antialias flag
380 * on the draw state (if possible in the 3D API).
381 */
sugoi@google.com5f74cf82012-12-17 21:16:45 +0000382 void stencilPath(const GrPath*, const SkStrokeRec& stroke, SkPath::FillType fill);
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000383
384 /**
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000385 * Helper function for drawing rects. This does not use the current index
386 * and vertex sources. After returning, the vertex and index sources may
387 * have changed. They should be reestablished before the next drawIndexed
388 * or drawNonIndexed. This cannot be called between reserving and releasing
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000389 * geometry.
skia.committer@gmail.com044679e2013-02-15 07:16:57 +0000390 *
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000391 * A subclass may override this to perform more optimal rect rendering. Its
392 * draws should be funneled through one of the public GrDrawTarget draw methods
393 * (e.g. drawNonIndexed, drawIndexedInstances, ...). The base class draws a two
394 * triangle fan using drawNonIndexed from reserved vertex space.
skia.committer@gmail.com044679e2013-02-15 07:16:57 +0000395 *
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000396 * @param rect the rect to draw
397 * @param matrix optional matrix applied to rect (before viewMatrix)
jvanverth@google.com39768252013-02-14 15:25:44 +0000398 * @param srcRects specifies rect for explicit texture coordinates.
399 * if srcRect is non-NULL then that rect will be used
400 * as the coordinates for the given stage.
401 * @param srcMatrix optional matrix applied to srcRect. If
skia.committer@gmail.com044679e2013-02-15 07:16:57 +0000402 * srcRect is non-NULL and srcMatrix is non-NULL
403 * then srcRect will be transformed by srcMatrix.
jvanverth@google.com39768252013-02-14 15:25:44 +0000404 * srcMatrix can be NULL when no srcMatrix is desired.
skia.committer@gmail.com044679e2013-02-15 07:16:57 +0000405 * @param stage the stage to be given explicit texture coordinates.
jvanverth@google.com39768252013-02-14 15:25:44 +0000406 * Ignored if srcRect is NULL.
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000407 */
bsalomon@google.comd302f142011-03-03 13:54:13 +0000408 virtual void drawRect(const GrRect& rect,
bsalomon@google.comb9086a02012-11-01 18:02:54 +0000409 const SkMatrix* matrix,
jvanverth@google.com39768252013-02-14 15:25:44 +0000410 const GrRect* srcRect,
411 const SkMatrix* srcMatrix,
412 int stage);
413
bsalomon@google.comcf939ae2012-12-13 19:59:23 +0000414 /**
415 * Helper for drawRect when the caller doesn't need separate src rects or
416 * matrices.
417 */
418 void drawSimpleRect(const GrRect& rect, const SkMatrix* matrix = NULL) {
jvanverth@google.com39768252013-02-14 15:25:44 +0000419 drawRect(rect, matrix, NULL, NULL, 0);
bsalomon@google.comcf939ae2012-12-13 19:59:23 +0000420 }
421 void drawSimpleRect(const GrIRect& irect, const SkMatrix* matrix = NULL) {
422 SkRect rect = SkRect::MakeFromIRect(irect);
jvanverth@google.com39768252013-02-14 15:25:44 +0000423 this->drawRect(rect, matrix, NULL, NULL, 0);
bsalomon@google.comcf939ae2012-12-13 19:59:23 +0000424 }
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000425
426 /**
bsalomon@google.com934c5702012-03-20 21:17:58 +0000427 * This call is used to draw multiple instances of some geometry with a
428 * given number of vertices (V) and indices (I) per-instance. The indices in
429 * the index source must have the form i[k+I] == i[k] + V. Also, all indices
430 * i[kI] ... i[(k+1)I-1] must be elements of the range kV ... (k+1)V-1. As a
431 * concrete example, the following index buffer for drawing a series of
432 * quads each as two triangles each satisfies these conditions with V=4 and
433 * I=6:
434 * (0,1,2,0,2,3, 4,5,6,4,6,7, 8,9,10,8,10,11, ...)
435 *
436 * The call assumes that the pattern of indices fills the entire index
437 * source. The size of the index buffer limits the number of instances that
438 * can be drawn by the GPU in a single draw. However, the caller may specify
439 * any (positive) number for instanceCount and if necessary multiple GPU
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000440 * draws will be issued. Moreover, when drawIndexedInstances is called
bsalomon@google.com934c5702012-03-20 21:17:58 +0000441 * multiple times it may be possible for GrDrawTarget to group them into a
442 * single GPU draw.
443 *
444 * @param type the type of primitives to draw
445 * @param instanceCount the number of instances to draw. Each instance
446 * consists of verticesPerInstance vertices indexed by
447 * indicesPerInstance indices drawn as the primitive
448 * type specified by type.
449 * @param verticesPerInstance The number of vertices in each instance (V
450 * in the above description).
451 * @param indicesPerInstance The number of indices in each instance (I
452 * in the above description).
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000453 * @param devBounds optional bounds hint. This is a promise from the caller,
454 * not a request for clipping.
bsalomon@google.com934c5702012-03-20 21:17:58 +0000455 */
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000456 void drawIndexedInstances(GrPrimitiveType type,
457 int instanceCount,
458 int verticesPerInstance,
459 int indicesPerInstance,
460 const SkRect* devBounds = NULL);
bsalomon@google.com934c5702012-03-20 21:17:58 +0000461
462 /**
rmistry@google.comd6176b02012-08-23 18:14:13 +0000463 * Clear the current render target if one isn't passed in. Ignores the
464 * clip and all other draw state (blend mode, stages, etc). Clears the
robertphillips@google.comc82a8b72012-06-21 20:15:48 +0000465 * whole thing if rect is NULL, otherwise just the rect.
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000466 */
rmistry@google.comd6176b02012-08-23 18:14:13 +0000467 virtual void clear(const GrIRect* rect,
robertphillips@google.comc82a8b72012-06-21 20:15:48 +0000468 GrColor color,
469 GrRenderTarget* renderTarget = NULL) = 0;
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000470
robertphillips@google.comff175842012-05-14 19:31:39 +0000471 /**
472 * Release any resources that are cached but not currently in use. This
473 * is intended to give an application some recourse when resources are low.
474 */
475 virtual void purgeResources() {};
476
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000477 /**
478 * For subclass internal use to invoke a call to onDraw(). See DrawInfo below.
479 */
480 void executeDraw(const DrawInfo& info) { this->onDraw(info); }
481
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000482 ////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +0000483
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000484 /**
485 * See AutoStateRestore below.
486 */
487 enum ASRInit {
488 kPreserve_ASRInit,
489 kReset_ASRInit
490 };
491
492 /**
493 * Saves off the current state and restores it in the destructor. It will
494 * install a new GrDrawState object on the target (setDrawState) and restore
495 * the previous one in the destructor. The caller should call drawState() to
496 * get the new draw state after the ASR is installed.
497 *
498 * GrDrawState* state = target->drawState();
499 * AutoStateRestore asr(target, GrDrawTarget::kReset_ASRInit).
500 * state->setRenderTarget(rt); // state refers to the GrDrawState set on
501 * // target before asr was initialized.
502 * // Therefore, rt is set on the GrDrawState
503 * // that will be restored after asr's
504 * // destructor rather than target's current
rmistry@google.comd6176b02012-08-23 18:14:13 +0000505 * // GrDrawState.
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000506 */
reed@google.comac10a2d2010-12-22 21:39:39 +0000507 class AutoStateRestore : ::GrNoncopyable {
508 public:
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000509 /**
510 * Default ASR will have no effect unless set() is subsequently called.
511 */
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000512 AutoStateRestore();
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000513
514 /**
515 * Saves the state on target. The state will be restored when the ASR
516 * is destroyed. If this constructor is used do not call set().
517 *
518 * @param init Should the newly installed GrDrawState be a copy of the
519 * previous state or a default-initialized GrDrawState.
520 */
521 AutoStateRestore(GrDrawTarget* target, ASRInit init);
522
reed@google.comac10a2d2010-12-22 21:39:39 +0000523 ~AutoStateRestore();
524
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000525 /**
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000526 * Saves the state on target. The state will be restored when the ASR
527 * is destroyed. This should only be called once per ASR object and only
528 * when the default constructor was used. For nested saves use multiple
529 * ASR objects.
530 *
531 * @param init Should the newly installed GrDrawState be a copy of the
532 * previous state or a default-initialized GrDrawState.
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000533 */
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000534 void set(GrDrawTarget* target, ASRInit init);
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000535
reed@google.comac10a2d2010-12-22 21:39:39 +0000536 private:
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000537 GrDrawTarget* fDrawTarget;
538 SkTLazy<GrDrawState> fTempState;
539 GrDrawState* fSavedState;
reed@google.comac10a2d2010-12-22 21:39:39 +0000540 };
541
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000542 ////////////////////////////////////////////////////////////////////////////
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000543
reed@google.comac10a2d2010-12-22 21:39:39 +0000544 class AutoReleaseGeometry : ::GrNoncopyable {
545 public:
546 AutoReleaseGeometry(GrDrawTarget* target,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000547 int vertexCount,
548 int indexCount);
549 AutoReleaseGeometry();
550 ~AutoReleaseGeometry();
bsalomon@google.com5782d712011-01-21 21:03:59 +0000551 bool set(GrDrawTarget* target,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000552 int vertexCount,
553 int indexCount);
bsalomon@google.coma47a48d2011-04-26 20:22:11 +0000554 bool succeeded() const { return NULL != fTarget; }
bsalomon@google.com6513cd02011-08-05 20:12:30 +0000555 void* vertices() const { GrAssert(this->succeeded()); return fVertices; }
556 void* indices() const { GrAssert(this->succeeded()); return fIndices; }
reed@google.comac10a2d2010-12-22 21:39:39 +0000557 GrPoint* positions() const {
bsalomon@google.com6513cd02011-08-05 20:12:30 +0000558 return static_cast<GrPoint*>(this->vertices());
reed@google.comac10a2d2010-12-22 21:39:39 +0000559 }
560
561 private:
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000562 void reset();
rmistry@google.comd6176b02012-08-23 18:14:13 +0000563
reed@google.comac10a2d2010-12-22 21:39:39 +0000564 GrDrawTarget* fTarget;
reed@google.comac10a2d2010-12-22 21:39:39 +0000565 void* fVertices;
566 void* fIndices;
567 };
568
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000569 ////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +0000570
571 class AutoClipRestore : ::GrNoncopyable {
572 public:
573 AutoClipRestore(GrDrawTarget* target) {
574 fTarget = target;
575 fClip = fTarget->getClip();
576 }
577
bsalomon@google.com8d67c072012-12-13 20:38:14 +0000578 AutoClipRestore(GrDrawTarget* target, const SkIRect& newClip);
579
reed@google.comac10a2d2010-12-22 21:39:39 +0000580 ~AutoClipRestore() {
581 fTarget->setClip(fClip);
582 }
583 private:
bsalomon@google.com8d67c072012-12-13 20:38:14 +0000584 GrDrawTarget* fTarget;
585 const GrClipData* fClip;
586 SkTLazy<SkClipStack> fStack;
587 GrClipData fReplacementClip;
reed@google.comac10a2d2010-12-22 21:39:39 +0000588 };
rmistry@google.comd6176b02012-08-23 18:14:13 +0000589
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000590 ////////////////////////////////////////////////////////////////////////////
rmistry@google.comd6176b02012-08-23 18:14:13 +0000591
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000592 class AutoGeometryAndStatePush : ::GrNoncopyable {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000593 public:
skia.committer@gmail.comae683922013-02-06 07:01:54 +0000594 AutoGeometryAndStatePush(GrDrawTarget* target, ASRInit init)
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000595 : fState(target, init) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000596 GrAssert(NULL != target);
597 fTarget = target;
598 target->pushGeometrySource();
599 }
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000600 ~AutoGeometryAndStatePush() {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000601 fTarget->popGeometrySource();
602 }
603 private:
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000604 GrDrawTarget* fTarget;
605 AutoStateRestore fState;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000606 };
reed@google.comac10a2d2010-12-22 21:39:39 +0000607
reed@google.comac10a2d2010-12-22 21:39:39 +0000608protected:
bsalomon@google.com471d4712011-08-23 15:45:25 +0000609
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000610 enum GeometrySrcType {
611 kNone_GeometrySrcType, //<! src has not been specified
612 kReserved_GeometrySrcType, //<! src was set using reserve*Space
613 kArray_GeometrySrcType, //<! src was set using set*SourceToArray
614 kBuffer_GeometrySrcType //<! src was set using set*SourceToBuffer
615 };
rmistry@google.comd6176b02012-08-23 18:14:13 +0000616
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000617 struct GeometrySrcState {
618 GeometrySrcType fVertexSrc;
619 union {
620 // valid if src type is buffer
621 const GrVertexBuffer* fVertexBuffer;
622 // valid if src type is reserved or array
623 int fVertexCount;
624 };
rmistry@google.comd6176b02012-08-23 18:14:13 +0000625
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000626 GeometrySrcType fIndexSrc;
627 union {
628 // valid if src type is buffer
629 const GrIndexBuffer* fIndexBuffer;
630 // valid if src type is reserved or array
631 int fIndexCount;
632 };
rmistry@google.comd6176b02012-08-23 18:14:13 +0000633
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000634 size_t fVertexSize;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000635 };
bsalomon@google.com934c5702012-03-20 21:17:58 +0000636
637 int indexCountInCurrentSource() const {
638 const GeometrySrcState& src = this->getGeomSrc();
639 switch (src.fIndexSrc) {
640 case kNone_GeometrySrcType:
641 return 0;
642 case kReserved_GeometrySrcType:
643 case kArray_GeometrySrcType:
644 return src.fIndexCount;
645 case kBuffer_GeometrySrcType:
646 return src.fIndexBuffer->sizeInBytes() / sizeof(uint16_t);
647 default:
648 GrCrash("Unexpected Index Source.");
649 return 0;
650 }
651 }
bsalomon@google.coma47a48d2011-04-26 20:22:11 +0000652
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000653 GrContext* getContext() { return fContext; }
654 const GrContext* getContext() const { return fContext; }
655
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000656 // allows derived class to set the caps
657 CapsInternals* capsInternals() { return &fCaps.fInternals; }
658
659 // A subclass may override this function if it wishes to be notified when the clip is changed.
660 // The override should call INHERITED::clipWillBeSet().
661 virtual void clipWillBeSet(const GrClipData* clipData);
662
663 // subclasses must call this in their destructors to ensure all vertex
664 // and index sources have been released (including those held by
665 // pushGeometrySource())
666 void releaseGeometry();
667
668 // accessors for derived classes
669 const GeometrySrcState& getGeomSrc() const { return fGeoSrcStateStack.back(); }
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000670 // it is preferable to call this rather than getGeomSrc()->fVertexSize because of the assert.
671 size_t getVertexSize() const {
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000672 // the vertex layout is only valid if a vertex source has been specified.
673 GrAssert(this->getGeomSrc().fVertexSrc != kNone_GeometrySrcType);
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000674 return this->getGeomSrc().fVertexSize;
bsalomon@google.coma47a48d2011-04-26 20:22:11 +0000675 }
bsalomon@google.com5782d712011-01-21 21:03:59 +0000676
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000677 Caps fCaps;
678
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000679 /**
680 * Used to communicate draws to subclass's onDraw function.
681 */
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000682 class DrawInfo {
683 public:
684 DrawInfo(const DrawInfo& di) { (*this) = di; }
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000685 DrawInfo& operator =(const DrawInfo& di);
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000686
687 GrPrimitiveType primitiveType() const { return fPrimitiveType; }
688 int startVertex() const { return fStartVertex; }
689 int startIndex() const { return fStartIndex; }
690 int vertexCount() const { return fVertexCount; }
691 int indexCount() const { return fIndexCount; }
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000692 int verticesPerInstance() const { return fVerticesPerInstance; }
693 int indicesPerInstance() const { return fIndicesPerInstance; }
694 int instanceCount() const { return fInstanceCount; }
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000695
696 bool isIndexed() const { return fIndexCount > 0; }
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000697#if GR_DEBUG
698 bool isInstanced() const; // this version is longer because of asserts
699#else
700 bool isInstanced() const { return fInstanceCount > 0; }
701#endif
702
703 // adds or remove instances
704 void adjustInstanceCount(int instanceOffset);
705 // shifts the start vertex
706 void adjustStartVertex(int vertexOffset);
707 // shifts the start index
708 void adjustStartIndex(int indexOffset);
709
710 void setDevBounds(const SkRect& bounds) {
711 fDevBoundsStorage = bounds;
712 fDevBounds = &fDevBoundsStorage;
713 }
714 const SkRect* getDevBounds() const { return fDevBounds; }
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000715
716 private:
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000717 DrawInfo() { fDevBounds = NULL; }
718
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000719 friend class GrDrawTarget;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000720
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000721 GrPrimitiveType fPrimitiveType;
722
723 int fStartVertex;
724 int fStartIndex;
725 int fVertexCount;
726 int fIndexCount;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000727
728 int fInstanceCount;
729 int fVerticesPerInstance;
730 int fIndicesPerInstance;
731
732 SkRect fDevBoundsStorage;
733 SkRect* fDevBounds;
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000734 };
735
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000736private:
737 // A subclass can optionally overload this function to be notified before
738 // vertex and index space is reserved.
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000739 virtual void willReserveVertexAndIndexSpace(int vertexCount, int indexCount) {}
bsalomon@google.com97805382012-03-13 14:32:07 +0000740
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000741 // implemented by subclass to allocate space for reserved geom
jvanverth@google.coma6338982013-01-31 21:34:25 +0000742 virtual bool onReserveVertexSpace(size_t vertexSize, int vertexCount, void** vertices) = 0;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000743 virtual bool onReserveIndexSpace(int indexCount, void** indices) = 0;
744 // implemented by subclass to handle release of reserved geom space
745 virtual void releaseReservedVertexSpace() = 0;
746 virtual void releaseReservedIndexSpace() = 0;
747 // subclass must consume array contents when set
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000748 virtual void onSetVertexSourceToArray(const void* vertexArray, int vertexCount) = 0;
749 virtual void onSetIndexSourceToArray(const void* indexArray, int indexCount) = 0;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000750 // subclass is notified that geom source will be set away from an array
751 virtual void releaseVertexArray() = 0;
752 virtual void releaseIndexArray() = 0;
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000753 // subclass overrides to be notified just before geo src state is pushed/popped.
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000754 virtual void geometrySourceWillPush() = 0;
755 virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) = 0;
756 // subclass called to perform drawing
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000757 virtual void onDraw(const DrawInfo&) = 0;
sugoi@google.com5f74cf82012-12-17 21:16:45 +0000758 virtual void onStencilPath(const GrPath*, const SkStrokeRec& stroke, SkPath::FillType fill) = 0;
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000759
bsalomon@google.come3d70952012-03-13 12:40:53 +0000760 // helpers for reserving vertex and index space.
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000761 bool reserveVertexSpace(size_t vertexSize,
bsalomon@google.come3d70952012-03-13 12:40:53 +0000762 int vertexCount,
763 void** vertices);
764 bool reserveIndexSpace(int indexCount, void** indices);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000765
bsalomon@google.come8262622011-11-07 02:30:51 +0000766 // called by drawIndexed and drawNonIndexed. Use a negative indexCount to
767 // indicate non-indexed drawing.
768 bool checkDraw(GrPrimitiveType type, int startVertex,
769 int startIndex, int vertexCount,
770 int indexCount) const;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000771 // called when setting a new vert/idx source to unref prev vb/ib
772 void releasePreviousVertexSource();
773 void releasePreviousIndexSource();
rmistry@google.comd6176b02012-08-23 18:14:13 +0000774
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000775 enum {
776 kPreallocGeoSrcStateStackCnt = 4,
reed@google.comac10a2d2010-12-22 21:39:39 +0000777 };
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000778 SkSTArray<kPreallocGeoSrcStateStackCnt, GeometrySrcState, true> fGeoSrcStateStack;
779 const GrClipData* fClip;
780 GrDrawState* fDrawState;
781 GrDrawState fDefaultDrawState;
bsalomon@google.com6e4e6502013-02-25 20:12:45 +0000782 // The context owns us, not vice-versa, so this ptr is not ref'ed by DrawTarget.
783 GrContext* fContext;
reed@google.comfa35e3d2012-06-26 20:16:17 +0000784
785 typedef GrRefCnt INHERITED;
reed@google.comac10a2d2010-12-22 21:39:39 +0000786};
787
reed@google.comac10a2d2010-12-22 21:39:39 +0000788#endif