blob: a57ff81c0af523934691ad84da517cd4c75a15c5 [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
reed@google.comac10a2d2010-12-22 21:39:39 +000014#include "GrClip.h"
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000015#include "GrColor.h"
16#include "GrMatrix.h"
17#include "GrRefCnt.h"
18#include "GrRenderTarget.h"
19#include "GrSamplerState.h"
bsalomon@google.comd302f142011-03-03 13:54:13 +000020#include "GrStencil.h"
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000021#include "GrTexture.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000022
Scroggo97c88c22011-05-11 14:05:25 +000023#include "SkXfermode.h"
24
reed@google.comac10a2d2010-12-22 21:39:39 +000025class GrTexture;
reed@google.comac10a2d2010-12-22 21:39:39 +000026class GrClipIterator;
27class GrVertexBuffer;
28class GrIndexBuffer;
29
30class GrDrawTarget : public GrRefCnt {
31public:
32 /**
bsalomon@google.com18c9c192011-09-22 21:01:31 +000033 * Represents the draw target capabilities.
34 */
35 struct Caps {
36 Caps() { memset(this, 0, sizeof(Caps)); }
37 Caps(const Caps& c) { *this = c; }
38 Caps& operator= (const Caps& c) {
39 memcpy(this, &c, sizeof(Caps));
40 return *this;
41 }
42 void print() const;
43 bool f8BitPaletteSupport : 1;
44 bool fNPOTTextureSupport : 1;
45 bool fNPOTTextureTileSupport : 1;
46 bool fNPOTRenderTargetSupport : 1;
47 bool fTwoSidedStencilSupport : 1;
48 bool fStencilWrapOpsSupport : 1;
49 bool fHWAALineSupport : 1;
50 bool fShaderSupport : 1;
51 bool fShaderDerivativeSupport : 1;
52 bool fFSAASupport : 1;
53 bool fDualSourceBlendingSupport : 1;
54 bool fBufferLockSupport : 1;
55 int fMinRenderTargetWidth;
56 int fMinRenderTargetHeight;
57 int fMaxRenderTargetSize;
58 int fMaxTextureSize;
59 };
60
61 /**
bsalomon@google.com5782d712011-01-21 21:03:59 +000062 * Number of texture stages. Each stage takes as input a color and
63 * 2D texture coordinates. The color input to the first enabled stage is the
64 * per-vertex color or the constant color (setColor/setAlpha) if there are
65 * no per-vertex colors. For subsequent stages the input color is the output
bsalomon@google.com8531c1c2011-01-13 19:52:45 +000066 * color from the previous enabled stage. The output color of each stage is
bsalomon@google.com5782d712011-01-21 21:03:59 +000067 * the input color modulated with the result of a texture lookup. Texture
bsalomon@google.comc6cf7232011-02-17 16:43:10 +000068 * lookups are specified by a texture a sampler (setSamplerState). Texture
69 * coordinates for each stage come from the vertices based on a
70 * GrVertexLayout bitfield. The output fragment color is the output color of
71 * the last enabled stage. The presence or absence of texture coordinates
72 * for each stage in the vertex layout indicates whether a stage is enabled
73 * or not.
bsalomon@google.com8531c1c2011-01-13 19:52:45 +000074 */
bsalomon@google.com8531c1c2011-01-13 19:52:45 +000075 enum {
bsalomon@google.com26c2d0a2011-05-17 20:15:30 +000076 kNumStages = 3,
bsalomon@google.com8531c1c2011-01-13 19:52:45 +000077 kMaxTexCoords = kNumStages
78 };
bsalomon@google.com5782d712011-01-21 21:03:59 +000079
senorblanco@chromium.orgef3913b2011-05-19 17:11:07 +000080 /**
81 * The absolute maximum number of edges that may be specified for
82 * a single draw call when performing edge antialiasing. This is used for
83 * the size of several static buffers, so implementations of getMaxEdges()
84 * (below) should clamp to this value.
85 */
86 enum {
87 kMaxEdges = 32
88 };
89
bsalomon@google.comaeb21602011-08-30 18:13:44 +000090 /**
91 * When specifying edges as vertex data this enum specifies what type of
92 * edges are in use. The edges are always 4 GrScalars in memory, even when
93 * the edge type requires fewer than 4.
94 */
95 enum VertexEdgeType {
96 /* 1-pixel wide line
97 2D implicit line eq (a*x + b*y +c = 0). 4th component unused */
98 kHairLine_EdgeType,
99 /* 1-pixel wide quadratic
100 u^2-v canonical coords (only 2 components used) */
101 kHairQuad_EdgeType
102 };
103
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000104 /**
bsalomon@google.comffca4002011-02-22 20:34:01 +0000105 * Bitfield used to indicate which stages are in use.
reed@google.comac10a2d2010-12-22 21:39:39 +0000106 */
bsalomon@google.comffca4002011-02-22 20:34:01 +0000107 typedef int StageBitfield;
108 GR_STATIC_ASSERT(sizeof(StageBitfield)*8 >= kNumStages);
reed@google.comac10a2d2010-12-22 21:39:39 +0000109
110 /**
111 * Flags that affect rendering. Controlled using enable/disableState(). All
112 * default to disabled.
113 */
114 enum StateBits {
senorblanco@chromium.org92e0f222011-05-12 15:49:15 +0000115 kDither_StateBit = 0x01, //<! Perform color dithering
116 kAntialias_StateBit = 0x02, //<! Perform anti-aliasing. The render-
reed@google.comac10a2d2010-12-22 21:39:39 +0000117 // target must support some form of AA
118 // (msaa, coverage sampling, etc). For
119 // GrGpu-created rendertarget/textures
120 // this is controlled by parameters
121 // passed to createTexture.
senorblanco@chromium.org92e0f222011-05-12 15:49:15 +0000122 kClip_StateBit = 0x04, //<! Controls whether drawing is clipped
reed@google.comac10a2d2010-12-22 21:39:39 +0000123 // against the region specified by
124 // setClip.
senorblanco@chromium.org92e0f222011-05-12 15:49:15 +0000125 kNoColorWrites_StateBit = 0x08, //<! If set it disables writing colors.
126 // Useful while performing stencil
127 // ops.
senorblanco@chromium.org129b8e32011-06-15 17:52:09 +0000128 kEdgeAAConcave_StateBit = 0x10,//<! If set, edge AA will test edge
129 // pairs for convexity while
130 // rasterizing. Set this if the
131 // source polygon is non-convex.
bsalomon@google.comd302f142011-03-03 13:54:13 +0000132
133 // subclass may use additional bits internally
134 kDummyStateBit,
135 kLastPublicStateBit = kDummyStateBit-1
136 };
137
138 enum DrawFace {
139 kBoth_DrawFace,
140 kCCW_DrawFace,
141 kCW_DrawFace,
reed@google.comac10a2d2010-12-22 21:39:39 +0000142 };
143
144 /**
bsalomon@google.comd302f142011-03-03 13:54:13 +0000145 * Sets the stencil settings to use for the next draw.
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +0000146 * Changing the clip has the side-effect of possibly zeroing
147 * out the client settable stencil bits. So multipass algorithms
148 * using stencil should not change the clip between passes.
bsalomon@google.comd302f142011-03-03 13:54:13 +0000149 * @param settings the stencil settings to use.
150 */
151 void setStencil(const GrStencilSettings& settings) {
152 fCurrDrawState.fStencilSettings = settings;
153 }
154
155 /**
156 * Shortcut to disable stencil testing and ops.
157 */
158 void disableStencil() {
159 fCurrDrawState.fStencilSettings.setDisabled();
160 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000161
senorblanco@chromium.orgef3913b2011-05-19 17:11:07 +0000162 class Edge {
163 public:
164 Edge() {}
165 Edge(float x, float y, float z) : fX(x), fY(y), fZ(z) {}
166 GrPoint intersect(const Edge& other) {
167 return GrPoint::Make(
168 (fY * other.fZ - other.fY * fZ) /
169 (fX * other.fY - other.fX * fY),
170 (fX * other.fZ - other.fX * fZ) /
171 (other.fX * fY - fX * other.fY));
172 }
173 float fX, fY, fZ;
174 };
175
reed@google.comac10a2d2010-12-22 21:39:39 +0000176protected:
reed@google.comac10a2d2010-12-22 21:39:39 +0000177
reed@google.com8195f672011-01-12 18:14:28 +0000178 struct DrState {
bsalomon@google.comd302f142011-03-03 13:54:13 +0000179 DrState() {
180 // make sure any pad is zero for memcmp
181 // all DrState members should default to something
182 // valid by the memset
183 memset(this, 0, sizeof(DrState));
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000184
185 // memset exceptions
Scroggo97c88c22011-05-11 14:05:25 +0000186 fColorFilterXfermode = SkXfermode::kDstIn_Mode;
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000187 fFirstCoverageStage = kNumStages;
188
189 // pedantic assertion that our ptrs will
190 // be NULL (0 ptr is mem addr 0)
bsalomon@google.comd302f142011-03-03 13:54:13 +0000191 GrAssert((intptr_t)(void*)NULL == 0LL);
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000192
193 // default stencil setting should be disabled
bsalomon@google.comd302f142011-03-03 13:54:13 +0000194 GrAssert(fStencilSettings.isDisabled());
bsalomon@google.com26c2d0a2011-05-17 20:15:30 +0000195 fFirstCoverageStage = kNumStages;
bsalomon@google.comd302f142011-03-03 13:54:13 +0000196 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000197 uint32_t fFlagBits;
bsalomon@google.comffca4002011-02-22 20:34:01 +0000198 GrBlendCoeff fSrcBlend;
199 GrBlendCoeff fDstBlend;
bsalomon@google.com080773c2011-03-15 19:09:25 +0000200 GrColor fBlendConstant;
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000201 GrTexture* fTextures[kNumStages];
202 GrSamplerState fSamplerStates[kNumStages];
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000203 int fFirstCoverageStage;
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000204 GrRenderTarget* fRenderTarget;
205 GrColor fColor;
bsalomon@google.comd302f142011-03-03 13:54:13 +0000206 DrawFace fDrawFace;
Scroggo97c88c22011-05-11 14:05:25 +0000207 GrColor fColorFilterColor;
208 SkXfermode::Mode fColorFilterXfermode;
bsalomon@google.comd302f142011-03-03 13:54:13 +0000209
210 GrStencilSettings fStencilSettings;
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000211 GrMatrix fViewMatrix;
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000212 VertexEdgeType fVertexEdgeType;
senorblanco@chromium.orgef3913b2011-05-19 17:11:07 +0000213 Edge fEdgeAAEdges[kMaxEdges];
214 int fEdgeAANumEdges;
reed@google.com8195f672011-01-12 18:14:28 +0000215 bool operator ==(const DrState& s) const {
216 return 0 == memcmp(this, &s, sizeof(DrState));
reed@google.comac10a2d2010-12-22 21:39:39 +0000217 }
reed@google.com8195f672011-01-12 18:14:28 +0000218 bool operator !=(const DrState& s) const { return !(*this == s); }
reed@google.comac10a2d2010-12-22 21:39:39 +0000219 };
220
221public:
222 ///////////////////////////////////////////////////////////////////////////
223
224 GrDrawTarget();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000225 virtual ~GrDrawTarget();
reed@google.comac10a2d2010-12-22 21:39:39 +0000226
227 /**
bsalomon@google.com18c9c192011-09-22 21:01:31 +0000228 * Gets the capabilities of the draw target.
229 */
230 const Caps& getCaps() const { return fCaps; }
231
232 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000233 * Sets the current clip to the region specified by clip. All draws will be
234 * clipped against this clip if kClip_StateBit is enabled.
235 *
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +0000236 * Setting the clip may (or may not) zero out the client's stencil bits.
237 *
reed@google.comac10a2d2010-12-22 21:39:39 +0000238 * @param description of the clipping region
239 */
240 void setClip(const GrClip& clip);
241
242 /**
243 * Gets the current clip.
244 *
245 * @return the clip.
246 */
247 const GrClip& getClip() const;
248
249 /**
250 * Sets the texture used at the next drawing call
251 *
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000252 * @param stage The texture stage for which the texture will be set
253 *
reed@google.comac10a2d2010-12-22 21:39:39 +0000254 * @param texture The texture to set. Can be NULL though there is no advantage
255 * to settings a NULL texture if doing non-textured drawing
256 */
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000257 void setTexture(int stage, GrTexture* texture);
reed@google.comac10a2d2010-12-22 21:39:39 +0000258
259 /**
260 * Retrieves the currently set texture.
261 *
262 * @return The currently set texture. The return value will be NULL if no
263 * texture has been set, NULL was most recently passed to
264 * setTexture, or the last setTexture was destroyed.
265 */
bsalomon@google.com5782d712011-01-21 21:03:59 +0000266 const GrTexture* getTexture(int stage) const;
267 GrTexture* getTexture(int stage);
reed@google.comac10a2d2010-12-22 21:39:39 +0000268
269 /**
270 * Sets the rendertarget used at the next drawing call
271 *
bsalomon@google.com5782d712011-01-21 21:03:59 +0000272 * @param target The render target to set.
reed@google.comac10a2d2010-12-22 21:39:39 +0000273 */
274 void setRenderTarget(GrRenderTarget* target);
275
276 /**
277 * Retrieves the currently set rendertarget.
278 *
279 * @return The currently set render target.
280 */
bsalomon@google.com5782d712011-01-21 21:03:59 +0000281 const GrRenderTarget* getRenderTarget() const;
282 GrRenderTarget* getRenderTarget();
reed@google.comac10a2d2010-12-22 21:39:39 +0000283
284 /**
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000285 * Sets the sampler state for a stage used in subsequent draws.
reed@google.comac10a2d2010-12-22 21:39:39 +0000286 *
bsalomon@google.comd302f142011-03-03 13:54:13 +0000287 * The sampler state determines how texture coordinates are
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000288 * intepretted and used to sample the texture.
reed@google.comac10a2d2010-12-22 21:39:39 +0000289 *
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000290 * @param stage the stage of the sampler to set
reed@google.comac10a2d2010-12-22 21:39:39 +0000291 * @param samplerState Specifies the sampler state.
292 */
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000293 void setSamplerState(int stage, const GrSamplerState& samplerState);
reed@google.comac10a2d2010-12-22 21:39:39 +0000294
295 /**
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000296 * Concats the matrix of a stage's sampler.
reed@google.comac10a2d2010-12-22 21:39:39 +0000297 *
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000298 * @param stage the stage of the sampler to set
299 * @param matrix the matrix to concat
reed@google.comac10a2d2010-12-22 21:39:39 +0000300 */
bsalomon@google.com27847de2011-02-22 20:59:41 +0000301 void preConcatSamplerMatrix(int stage, const GrMatrix& matrix) {
302 GrAssert(stage >= 0 && stage < kNumStages);
303 fCurrDrawState.fSamplerStates[stage].preConcatMatrix(matrix);
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000304 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000305
306 /**
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000307 * Shortcut for preConcatSamplerMatrix on all stages in mask with same
bsalomon@google.com26c2d0a2011-05-17 20:15:30 +0000308 * matrix
309 */
310 void preConcatSamplerMatrices(int stageMask, const GrMatrix& matrix) {
311 for (int i = 0; i < kNumStages; ++i) {
312 if ((1 << i) & stageMask) {
313 this->preConcatSamplerMatrix(i, matrix);
314 }
315 }
316 }
317
318 /**
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000319 * Shortcut for preConcatSamplerMatrix on all enabled stages in mask with
320 * same matrix
321 *
322 * @param stage the stage of the sampler to set
323 * @param matrix the matrix to concat
324 */
325 void preConcatEnabledSamplerMatrices(const GrMatrix& matrix) {
326 StageBitfield stageMask = this->enabledStages();
327 this->preConcatSamplerMatrices(stageMask, matrix);
328 }
329
330 /**
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000331 * Gets the matrix of a stage's sampler
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000332 *
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000333 * @param stage the stage to of sampler to get
334 * @return the sampler state's matrix
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000335 */
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000336 const GrMatrix& getSamplerMatrix(int stage) const {
337 return fCurrDrawState.fSamplerStates[stage].getMatrix();
338 }
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000339
340 /**
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000341 * Sets the matrix of a stage's sampler
342 *
343 * @param stage the stage of sampler set
344 * @param matrix the matrix to set
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000345 */
djsollen@google.comcd9d69b2011-03-14 20:30:14 +0000346 void setSamplerMatrix(int stage, const GrMatrix& matrix) {
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000347 fCurrDrawState.fSamplerStates[stage].setMatrix(matrix);
348 }
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000349
350 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000351 * Sets the matrix applied to veretx positions.
352 *
353 * In the post-view-matrix space the rectangle [0,w]x[0,h]
354 * fully covers the render target. (w and h are the width and height of the
355 * the rendertarget.)
356 *
357 * @param m the matrix used to transform the vertex positions.
358 */
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000359 void setViewMatrix(const GrMatrix& m);
reed@google.comac10a2d2010-12-22 21:39:39 +0000360
361 /**
362 * Multiplies the current view matrix by a matrix
363 *
364 * After this call V' = V*m where V is the old view matrix,
365 * m is the parameter to this function, and V' is the new view matrix.
366 * (We consider positions to be column vectors so position vector p is
367 * transformed by matrix X as p' = X*p.)
368 *
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000369 * @param m the matrix used to modify the view matrix.
reed@google.comac10a2d2010-12-22 21:39:39 +0000370 */
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000371 void preConcatViewMatrix(const GrMatrix& m);
reed@google.comac10a2d2010-12-22 21:39:39 +0000372
373 /**
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000374 * Multiplies the current view matrix by a matrix
375 *
376 * After this call V' = m*V where V is the old view matrix,
377 * m is the parameter to this function, and V' is the new view matrix.
378 * (We consider positions to be column vectors so position vector p is
379 * transformed by matrix X as p' = X*p.)
380 *
381 * @param m the matrix used to modify the view matrix.
382 */
383 void postConcatViewMatrix(const GrMatrix& m);
384
385 /**
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000386 * Retrieves the current view matrix
387 * @return the current view matrix.
388 */
389 const GrMatrix& getViewMatrix() const;
390
391 /**
392 * Retrieves the inverse of the current view matrix.
393 *
394 * If the current view matrix is invertible, return true, and if matrix
395 * is non-null, copy the inverse into it. If the current view matrix is
396 * non-invertible, return false and ignore the matrix parameter.
397 *
398 * @param matrix if not null, will receive a copy of the current inverse.
399 */
400 bool getViewInverse(GrMatrix* matrix) const;
401
402 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000403 * Sets color for next draw to a premultiplied-alpha color.
404 *
405 * @param the color to set.
406 */
407 void setColor(GrColor);
408
409 /**
Scroggo97c88c22011-05-11 14:05:25 +0000410 * Add a color filter that can be represented by a color and a mode.
411 */
412 void setColorFilter(GrColor, SkXfermode::Mode);
413
414 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000415 * Sets the color to be used for the next draw to be
416 * (r,g,b,a) = (alpha, alpha, alpha, alpha).
417 *
418 * @param alpha The alpha value to set as the color.
419 */
420 void setAlpha(uint8_t alpha);
421
422 /**
bsalomon@google.comd302f142011-03-03 13:54:13 +0000423 * Controls whether clockwise, counterclockwise, or both faces are drawn.
424 * @param face the face(s) to draw.
reed@google.comac10a2d2010-12-22 21:39:39 +0000425 */
bsalomon@google.comd302f142011-03-03 13:54:13 +0000426 void setDrawFace(DrawFace face) { fCurrDrawState.fDrawFace = face; }
reed@google.comac10a2d2010-12-22 21:39:39 +0000427
428 /**
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000429 * A common pattern is to compute a color with the initial stages and then
430 * modulate that color by a coverage value in later stage(s) (AA, mask-
431 * filters, glyph mask, etc). Color-filters, xfermodes, etc should be
432 * computed based on the pre-coverage-modulated color. The division of
433 * stages between color-computing and coverage-computing is specified by
434 * this method. Initially this is kNumStages (all stages are color-
435 * computing).
436 */
437 void setFirstCoverageStage(int firstCoverageStage) {
438 fCurrDrawState.fFirstCoverageStage = firstCoverageStage;
439 }
440
441 /**
442 * Gets the index of the first coverage-computing stage.
443 */
444 int getFirstCoverageStage() const {
445 return fCurrDrawState.fFirstCoverageStage;
446 }
447
448 /**
bsalomon@google.comd302f142011-03-03 13:54:13 +0000449 * Gets whether the target is drawing clockwise, counterclockwise,
450 * or both faces.
451 * @return the current draw face(s).
reed@google.comac10a2d2010-12-22 21:39:39 +0000452 */
bsalomon@google.comd302f142011-03-03 13:54:13 +0000453 DrawFace getDrawFace() const { return fCurrDrawState.fDrawFace; }
reed@google.comac10a2d2010-12-22 21:39:39 +0000454
455 /**
456 * Enable render state settings.
457 *
458 * @param flags bitfield of StateBits specifing the states to enable
459 */
460 void enableState(uint32_t stateBits);
461
462 /**
463 * Disable render state settings.
464 *
465 * @param flags bitfield of StateBits specifing the states to disable
466 */
467 void disableState(uint32_t stateBits);
468
469 bool isDitherState() const {
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000470 return 0 != (fCurrDrawState.fFlagBits & kDither_StateBit);
471 }
472
senorblanco@chromium.org92e0f222011-05-12 15:49:15 +0000473 bool isAntialiasState() const {
474 return 0 != (fCurrDrawState.fFlagBits & kAntialias_StateBit);
475 }
476
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000477 bool isClipState() const {
478 return 0 != (fCurrDrawState.fFlagBits & kClip_StateBit);
reed@google.comac10a2d2010-12-22 21:39:39 +0000479 }
480
bsalomon@google.comd302f142011-03-03 13:54:13 +0000481 bool isColorWriteDisabled() const {
482 return 0 != (fCurrDrawState.fFlagBits & kNoColorWrites_StateBit);
483 }
484
reed@google.comac10a2d2010-12-22 21:39:39 +0000485 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000486 * Sets the blending function coeffecients.
487 *
488 * The blend function will be:
489 * D' = sat(S*srcCoef + D*dstCoef)
490 *
491 * where D is the existing destination color, S is the incoming source
492 * color, and D' is the new destination color that will be written. sat()
493 * is the saturation function.
494 *
495 * @param srcCoef coeffecient applied to the src color.
496 * @param dstCoef coeffecient applied to the dst color.
497 */
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000498 void setBlendFunc(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff);
reed@google.comac10a2d2010-12-22 21:39:39 +0000499
500 /**
bsalomon@google.com080773c2011-03-15 19:09:25 +0000501 * Sets the blending function constant referenced by the following blending
502 * coeffecients:
503 * kConstC_BlendCoeff
504 * kIConstC_BlendCoeff
505 * kConstA_BlendCoeff
506 * kIConstA_BlendCoeff
507 *
508 * @param constant the constant to set
509 */
510 void setBlendConstant(GrColor constant) { fCurrDrawState.fBlendConstant = constant; }
511
512 /**
513 * Retrieves the last value set by setBlendConstant()
514 * @return the blending constant value
515 */
516 GrColor getBlendConstant() const { return fCurrDrawState.fBlendConstant; }
517
518 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000519 * Used to save and restore the GrGpu's drawing state
520 */
521 struct SavedDrawState {
522 private:
reed@google.com8195f672011-01-12 18:14:28 +0000523 DrState fState;
reed@google.comac10a2d2010-12-22 21:39:39 +0000524 friend class GrDrawTarget;
525 };
526
527 /**
528 * Saves the current draw state. The state can be restored at a later time
529 * with restoreDrawState.
530 *
531 * See also AutoStateRestore class.
532 *
533 * @param state will hold the state after the function returns.
534 */
535 void saveCurrentDrawState(SavedDrawState* state) const;
536
537 /**
538 * Restores previously saved draw state. The client guarantees that state
539 * was previously passed to saveCurrentDrawState and that the rendertarget
540 * and texture set at save are still valid.
541 *
542 * See also AutoStateRestore class.
543 *
544 * @param state the previously saved state to restore.
545 */
546 void restoreDrawState(const SavedDrawState& state);
547
548 /**
549 * Copies the draw state from another target to this target.
550 *
551 * @param srcTarget draw target used as src of the draw state.
552 */
553 void copyDrawState(const GrDrawTarget& srcTarget);
554
555 /**
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000556 * The format of vertices is represented as a bitfield of flags.
557 * Flags that indicate the layout of vertex data. Vertices always contain
bsalomon@google.com5782d712011-01-21 21:03:59 +0000558 * positions and may also contain up to kMaxTexCoords sets of 2D texture
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000559 * coordinates and per-vertex colors. Each stage can use any of the texture
560 * coordinates as its input texture coordinates or it may use the positions.
reed@google.comac10a2d2010-12-22 21:39:39 +0000561 *
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000562 * If no texture coordinates are specified for a stage then the stage is
563 * disabled.
reed@google.comac10a2d2010-12-22 21:39:39 +0000564 *
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000565 * Only one type of texture coord can be specified per stage. For
bsalomon@google.com5782d712011-01-21 21:03:59 +0000566 * example StageTexCoordVertexLayoutBit(0, 2) and
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000567 * StagePosAsTexCoordVertexLayoutBit(0) cannot both be specified.
reed@google.comac10a2d2010-12-22 21:39:39 +0000568 *
bsalomon@google.com5782d712011-01-21 21:03:59 +0000569 * The order in memory is always (position, texture coord 0, ..., color)
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000570 * with any unused fields omitted. Note that this means that if only texture
bsalomon@google.com5782d712011-01-21 21:03:59 +0000571 * coordinates 1 is referenced then there is no texture coordinates 0 and
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000572 * the order would be (position, texture coordinate 1[, color]).
573 */
bsalomon@google.com5782d712011-01-21 21:03:59 +0000574
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000575 /**
576 * Generates a bit indicating that a texture stage uses texture coordinates
bsalomon@google.com5782d712011-01-21 21:03:59 +0000577 *
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000578 * @param stage the stage that will use texture coordinates.
579 * @param texCoordIdx the index of the texture coordinates to use
580 *
581 * @return the bit to add to a GrVertexLayout bitfield.
582 */
583 static int StageTexCoordVertexLayoutBit(int stage, int texCoordIdx) {
584 GrAssert(stage < kNumStages);
585 GrAssert(texCoordIdx < kMaxTexCoords);
586 return 1 << (stage + (texCoordIdx * kNumStages));
587 }
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000588
589 /**
590 * Determines if blend is effectively disabled.
591 *
592 * @return true if blend can be disabled without changing the rendering
593 * result given the current state including the vertex layout specified
594 * with the vertex source.
595 */
596 bool canDisableBlend() const;
597
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000598 /**
599 * Determines the interpretation per-vertex edge data when the
600 * kEdge_VertexLayoutBit is set (see below). When per-vertex edges are not
601 * specified the value of this setting has no effect.
602 */
603 void setVertexEdgeType(VertexEdgeType type) {
604 fCurrDrawState.fVertexEdgeType = type;
605 }
606
senorblanco@chromium.org92e0f222011-05-12 15:49:15 +0000607 /**
bsalomon@google.com471d4712011-08-23 15:45:25 +0000608 * Given the current draw state, vertex layout, and hw support, will HW AA
609 * lines be used (if line primitive type is drawn)? (Note that lines are
610 * always 1 pixel wide)
611 */
612 virtual bool willUseHWAALines() const = 0;
613
614 /**
senorblanco@chromium.org92e0f222011-05-12 15:49:15 +0000615 * Sets the edge data required for edge antialiasing.
616 *
617 * @param edges 3 * 6 float values, representing the edge
618 * equations in Ax + By + C form
619 */
senorblanco@chromium.orgef3913b2011-05-19 17:11:07 +0000620 void setEdgeAAData(const Edge* edges, int numEdges);
senorblanco@chromium.org92e0f222011-05-12 15:49:15 +0000621
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000622private:
623 static const int TEX_COORD_BIT_CNT = kNumStages*kMaxTexCoords;
624public:
625 /**
626 * Generates a bit indicating that a texture stage uses the position
627 * as its texture coordinate.
628 *
bsalomon@google.com5782d712011-01-21 21:03:59 +0000629 * @param stage the stage that will use position as texture
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000630 * coordinates.
631 *
632 * @return the bit to add to a GrVertexLayout bitfield.
633 */
634 static int StagePosAsTexCoordVertexLayoutBit(int stage) {
635 GrAssert(stage < kNumStages);
bsalomon@google.com5782d712011-01-21 21:03:59 +0000636 return (1 << (TEX_COORD_BIT_CNT + stage));
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000637 }
638private:
639 static const int STAGE_BIT_CNT = TEX_COORD_BIT_CNT + kNumStages;
bsalomon@google.com5782d712011-01-21 21:03:59 +0000640
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000641public:
bsalomon@google.com5782d712011-01-21 21:03:59 +0000642
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000643 /**
644 * Additional Bits that can be specified in GrVertexLayout.
reed@google.comac10a2d2010-12-22 21:39:39 +0000645 */
646 enum VertexLayoutBits {
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000647 /* vertices have colors */
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000648 kColor_VertexLayoutBit = 1 << (STAGE_BIT_CNT + 0),
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000649
650 /* Use text vertices. (Pos and tex coords may be a different type for
651 text [GrGpuTextVertex vs GrPoint].) */
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000652 kTextFormat_VertexLayoutBit = 1 << (STAGE_BIT_CNT + 1),
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000653
654 kEdge_VertexLayoutBit = 1 << (STAGE_BIT_CNT + 2),
reed@google.comac10a2d2010-12-22 21:39:39 +0000655 // for below assert
bsalomon@google.comd302f142011-03-03 13:54:13 +0000656 kDummyVertexLayoutBit,
657 kHighVertexLayoutBit = kDummyVertexLayoutBit - 1
reed@google.comac10a2d2010-12-22 21:39:39 +0000658 };
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000659 // make sure we haven't exceeded the number of bits in GrVertexLayout.
bsalomon@google.com4be283f2011-04-19 21:15:09 +0000660 GR_STATIC_ASSERT(kHighVertexLayoutBit < ((uint64_t)1 << 8*sizeof(GrVertexLayout)));
reed@google.comac10a2d2010-12-22 21:39:39 +0000661
662 /**
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000663 * There are three methods for specifying geometry (vertices and optionally
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000664 * indices) to the draw target. When indexed drawing the indices and vertices
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000665 * can use a different method. Once geometry is specified it can be used for
666 * multiple drawIndexed and drawNonIndexed calls.
667 *
668 * Sometimes it is necessary to perform a draw while upstack code has
669 * already specified geometry that it isn't finished with. There are push
670 * pop methods
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000671 *
672 * 1. Provide a cpu array (set*SourceToArray). This is useful when the
673 * caller's client has already provided vertex data in a format
674 * the time compatible with a GrVertexLayout. The array must contain the
675 * data at set*SourceToArray is called. The source stays in effect for
676 * drawIndexed & drawNonIndexed calls until set*SourceToArray is called
677 * again or one of the other two paths is chosen.
678 *
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000679 * 2. Reserve. This is most useful when the caller has data it must
680 * transform before drawing and is not long-lived. The caller requests
681 * that the draw target make room for some amount of vertex and/or index
682 * data. The target provides ptrs to hold the vertex and/or index data.
683 *
684 * The data is writable up until the next drawIndexed, drawNonIndexed,
685 * or pushGeometrySource At this point the data is frozen and the ptrs
686 * are no longer valid.
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000687 *
688 * 3. Vertex and Index Buffers. This is most useful for geometry that will
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000689 * is long-lived. SetVertexSourceToBuffer and SetIndexSourceToBuffer are
690 * used to set the buffer and subsequent drawIndexed and drawNonIndexed
691 * calls use this source until another source is set.
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000692 */
693
694 /**
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000695 * Reserves space for vertices. Draw target will use reserved vertices at
696 * at the next draw.
reed@google.comac10a2d2010-12-22 21:39:39 +0000697 *
698 * If succeeds:
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000699 * if vertexCount > 0, *vertices will be the array
reed@google.comac10a2d2010-12-22 21:39:39 +0000700 * of vertices to be filled by caller. The next draw will read
701 * these vertices.
702 *
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000703 * If a client does not already have a vertex buffer then this is the
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000704 * preferred way to allocate vertex data. It allows the subclass of
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000705 * GrDrawTarget to decide whether to put data in buffers, to group vertex
706 * data that uses the same state (e.g. for deferred rendering), etc.
reed@google.comac10a2d2010-12-22 21:39:39 +0000707 *
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000708 * After the next draw or pushGeometrySource the vertices ptr is no longer
709 * valid and the geometry data cannot be further modified. The contents
710 * that were put in the reserved space can be drawn by multiple draws,
711 * however.
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000712 *
reed@google.comac10a2d2010-12-22 21:39:39 +0000713 * @param vertexLayout the format of vertices (ignored if vertexCount == 0).
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000714 * @param vertexCount the number of vertices to reserve space for. Can be 0.
reed@google.comac10a2d2010-12-22 21:39:39 +0000715 * @param vertices will point to reserved vertex space if vertexCount is
716 * non-zero. Illegal to pass NULL if vertexCount > 0.
reed@google.comac10a2d2010-12-22 21:39:39 +0000717 *
718 * @return true if succeeded in allocating space for the vertices and false
719 * if not.
720 */
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000721 bool reserveVertexSpace(GrVertexLayout vertexLayout,
722 int vertexCount,
723 void** vertices);
724 /**
725 * Reserves space for indices. Draw target will use the reserved indices at
726 * the next indexed draw.
727 *
728 * If succeeds:
729 * if indexCount > 0, *indices will be the array
730 * of indices to be filled by caller. The next draw will read
731 * these indices.
732 *
733 * If a client does not already have a index buffer then this is the
734 * preferred way to allocate index data. It allows the subclass of
735 * GrDrawTarget to decide whether to put data in buffers, to group index
736 * data that uses the same state (e.g. for deferred rendering), etc.
737 *
738 * After the next indexed draw or pushGeometrySource the indices ptr is no
739 * longer valid and the geometry data cannot be further modified. The
740 * contents that were put in the reserved space can be drawn by multiple
741 * draws, however.
742 *
743 * @param indexCount the number of indices to reserve space for. Can be 0.
744 * @param indices will point to reserved index space if indexCount is
745 * non-zero. Illegal to pass NULL if indexCount > 0.
746 */
747
748 bool reserveIndexSpace(int indexCount, void** indices);
reed@google.comac10a2d2010-12-22 21:39:39 +0000749 /**
750 * Provides hints to caller about the number of vertices and indices
751 * that can be allocated cheaply. This can be useful if caller is reserving
752 * space but doesn't know exactly how much geometry is needed.
753 *
754 * Also may hint whether the draw target should be flushed first. This is
755 * useful for deferred targets.
756 *
757 * @param vertexLayout layout of vertices caller would like to reserve
758 * @param vertexCount in: hint about how many vertices the caller would
759 * like to allocate.
760 * out: a hint about the number of vertices that can be
761 * allocated cheaply. Negative means no hint.
762 * Ignored if NULL.
763 * @param indexCount in: hint about how many indices the caller would
764 * like to allocate.
765 * out: a hint about the number of indices that can be
766 * allocated cheaply. Negative means no hint.
767 * Ignored if NULL.
768 *
769 * @return true if target should be flushed based on the input values.
770 */
771 virtual bool geometryHints(GrVertexLayout vertexLayout,
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000772 int* vertexCount,
773 int* indexCount) const;
reed@google.comac10a2d2010-12-22 21:39:39 +0000774
775 /**
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000776 * Sets source of vertex data for the next draw. Array must contain
777 * the vertex data when this is called.
reed@google.comac10a2d2010-12-22 21:39:39 +0000778 *
779 * @param array cpu array containing vertex data.
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000780 * @param size size of the vertex data.
781 * @param vertexCount the number of vertices in the array.
reed@google.comac10a2d2010-12-22 21:39:39 +0000782 */
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000783 void setVertexSourceToArray(GrVertexLayout vertexLayout,
784 const void* vertexArray,
785 int vertexCount);
reed@google.comac10a2d2010-12-22 21:39:39 +0000786
787 /**
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000788 * Sets source of index data for the next indexed draw. Array must contain
789 * the indices when this is called.
reed@google.comac10a2d2010-12-22 21:39:39 +0000790 *
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000791 * @param array cpu array containing index data.
792 * @param indexCount the number of indices in the array.
reed@google.comac10a2d2010-12-22 21:39:39 +0000793 */
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000794 void setIndexSourceToArray(const void* indexArray, int indexCount);
reed@google.comac10a2d2010-12-22 21:39:39 +0000795
796 /**
797 * Sets source of vertex data for the next draw. Data does not have to be
798 * in the buffer until drawIndexed or drawNonIndexed.
799 *
800 * @param buffer vertex buffer containing vertex data. Must be
801 * unlocked before draw call.
802 * @param vertexLayout layout of the vertex data in the buffer.
803 */
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000804 void setVertexSourceToBuffer(GrVertexLayout vertexLayout,
805 const GrVertexBuffer* buffer);
reed@google.comac10a2d2010-12-22 21:39:39 +0000806
807 /**
808 * Sets source of index data for the next indexed draw. Data does not have
809 * to be in the buffer until drawIndexed or drawNonIndexed.
810 *
811 * @param buffer index buffer containing indices. Must be unlocked
812 * before indexed draw call.
813 */
814 void setIndexSourceToBuffer(const GrIndexBuffer* buffer);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000815
816 /**
817 * Resets vertex source. Drawing from reset vertices is illegal. Set vertex
818 * source to reserved, array, or buffer before next draw. May be able to free
819 * up temporary storage allocated by setVertexSourceToArray or
820 * reserveVertexSpace.
821 */
822 void resetVertexSource();
823
824 /**
825 * Resets index source. Indexed Drawing from reset indices is illegal. Set
826 * index source to reserved, array, or buffer before next indexed draw. May
827 * be able to free up temporary storage allocated by setIndexSourceToArray
828 * or reserveIndexSpace.
829 */
830 void resetIndexSource();
reed@google.comac10a2d2010-12-22 21:39:39 +0000831
832 /**
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000833 * Pushes and resets the vertex/index sources. Any reserved vertex / index
834 * data is finalized (i.e. cannot be updated after the matching pop but can
835 * be drawn from). Must be balanced by a pop.
836 */
837 void pushGeometrySource();
838
839 /**
840 * Pops the vertex / index sources from the matching push.
841 */
842 void popGeometrySource();
843
844 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000845 * Draws indexed geometry using the current state and current vertex / index
846 * sources.
847 *
848 * @param type The type of primitives to draw.
849 * @param startVertex the vertex in the vertex array/buffer corresponding
850 * to index 0
851 * @param startIndex first index to read from index src.
852 * @param vertexCount one greater than the max index.
853 * @param indexCount the number of index elements to read. The index count
854 * is effectively trimmed to the last completely
855 * specified primitive.
856 */
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000857 void drawIndexed(GrPrimitiveType type,
858 int startVertex,
859 int startIndex,
860 int vertexCount,
861 int indexCount);
reed@google.comac10a2d2010-12-22 21:39:39 +0000862
863 /**
864 * Draws non-indexed geometry using the current state and current vertex
865 * sources.
866 *
867 * @param type The type of primitives to draw.
868 * @param startVertex the vertex in the vertex array/buffer corresponding
869 * to index 0
870 * @param vertexCount one greater than the max index.
871 */
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000872 void drawNonIndexed(GrPrimitiveType type,
873 int startVertex,
874 int vertexCount);
reed@google.comac10a2d2010-12-22 21:39:39 +0000875
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000876 /**
877 * Helper function for drawing rects. This does not use the current index
878 * and vertex sources. After returning, the vertex and index sources may
879 * have changed. They should be reestablished before the next drawIndexed
880 * or drawNonIndexed. This cannot be called between reserving and releasing
881 * geometry. The GrDrawTarget subclass may be able to perform additional
bsalomon@google.comd302f142011-03-03 13:54:13 +0000882 * optimizations if drawRect is used rather than drawIndexed or
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000883 * drawNonIndexed.
884 * @param rect the rect to draw
885 * @param matrix optional matrix applied to rect (before viewMatrix)
bsalomon@google.comffca4002011-02-22 20:34:01 +0000886 * @param stageEnableBitfield bitmask indicating which stages are enabled.
887 * Bit i indicates whether stage i is enabled.
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000888 * @param srcRects specifies rects for stages enabled by stageEnableMask.
889 * if stageEnableMask bit i is 1, srcRects is not NULL,
890 * and srcRects[i] is not NULL, then srcRects[i] will be
891 * used as coordinates for stage i. Otherwise, if stage i
892 * is enabled then rect is used as the coordinates.
893 * @param srcMatrices optional matrices applied to srcRects. If
894 * srcRect[i] is non-NULL and srcMatrices[i] is
895 * non-NULL then srcRect[i] will be transformed by
896 * srcMatrix[i]. srcMatrices can be NULL when no
897 * srcMatrices are desired.
898 */
bsalomon@google.comd302f142011-03-03 13:54:13 +0000899 virtual void drawRect(const GrRect& rect,
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000900 const GrMatrix* matrix,
bsalomon@google.comffca4002011-02-22 20:34:01 +0000901 StageBitfield stageEnableBitfield,
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000902 const GrRect* srcRects[],
903 const GrMatrix* srcMatrices[]);
904
905 /**
bsalomon@google.comd302f142011-03-03 13:54:13 +0000906 * Helper for drawRect when the caller doesn't need separate src rects or
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000907 * matrices.
908 */
bsalomon@google.comd302f142011-03-03 13:54:13 +0000909 void drawSimpleRect(const GrRect& rect,
910 const GrMatrix* matrix,
bsalomon@google.comffca4002011-02-22 20:34:01 +0000911 StageBitfield stageEnableBitfield) {
912 drawRect(rect, matrix, stageEnableBitfield, NULL, NULL);
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000913 }
914
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000915 /**
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000916 * Clear the render target. Ignores the clip and all other draw state
917 * (blend mode, stages, etc). Clears the whole thing if rect is NULL,
918 * otherwise just the rect.
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000919 */
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000920 virtual void clear(const GrIRect* rect, GrColor color) = 0;
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000921
senorblanco@chromium.orgef3913b2011-05-19 17:11:07 +0000922 /**
923 * Returns the maximum number of edges that may be specified in a single
924 * draw call when performing edge antialiasing. This is usually limited
925 * by the number of fragment uniforms which may be uploaded. Must be a
926 * minimum of six, since a triangle's vertices each belong to two boundary
927 * edges which may be distinct.
928 */
929 virtual int getMaxEdges() const { return 6; }
930
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000931 ////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +0000932
933 class AutoStateRestore : ::GrNoncopyable {
934 public:
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000935 AutoStateRestore();
reed@google.comac10a2d2010-12-22 21:39:39 +0000936 AutoStateRestore(GrDrawTarget* target);
937 ~AutoStateRestore();
938
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000939 /**
940 * if this object is already saving state for param target then
941 * this does nothing. Otherise, it restores previously saved state on
942 * previous target (if any) and saves current state on param target.
943 */
944 void set(GrDrawTarget* target);
945
reed@google.comac10a2d2010-12-22 21:39:39 +0000946 private:
947 GrDrawTarget* fDrawTarget;
948 SavedDrawState fDrawState;
949 };
950
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000951 ////////////////////////////////////////////////////////////////////////////
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000952
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000953 class AutoViewMatrixRestore : ::GrNoncopyable {
954 public:
955 AutoViewMatrixRestore() {
956 fDrawTarget = NULL;
957 }
958
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000959 AutoViewMatrixRestore(GrDrawTarget* target)
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000960 : fDrawTarget(target), fMatrix(fDrawTarget->getViewMatrix()) {
961 GrAssert(NULL != target);
962 }
963
964 void set(GrDrawTarget* target) {
965 GrAssert(NULL != target);
966 if (NULL != fDrawTarget) {
967 fDrawTarget->setViewMatrix(fMatrix);
968 }
969 fDrawTarget = target;
970 fMatrix = target->getViewMatrix();
971 }
972
973 ~AutoViewMatrixRestore() {
974 if (NULL != fDrawTarget) {
975 fDrawTarget->setViewMatrix(fMatrix);
976 }
977 }
978
979 private:
980 GrDrawTarget* fDrawTarget;
981 GrMatrix fMatrix;
982 };
983
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000984 ////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +0000985
bsalomon@google.com7ac249b2011-06-14 18:46:24 +0000986 /**
987 * Sets the view matrix to I and preconcats all stage matrices enabled in
988 * mask by the view inverse. Destructor undoes these changes.
989 */
990 class AutoDeviceCoordDraw : ::GrNoncopyable {
991 public:
992 AutoDeviceCoordDraw(GrDrawTarget* target, int stageMask);
993 ~AutoDeviceCoordDraw();
994 private:
995 GrDrawTarget* fDrawTarget;
996 GrMatrix fViewMatrix;
997 GrMatrix fSamplerMatrices[kNumStages];
998 int fStageMask;
999 };
1000
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001001 ////////////////////////////////////////////////////////////////////////////
bsalomon@google.com7ac249b2011-06-14 18:46:24 +00001002
reed@google.comac10a2d2010-12-22 21:39:39 +00001003 class AutoReleaseGeometry : ::GrNoncopyable {
1004 public:
1005 AutoReleaseGeometry(GrDrawTarget* target,
1006 GrVertexLayout vertexLayout,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001007 int vertexCount,
1008 int indexCount);
1009 AutoReleaseGeometry();
1010 ~AutoReleaseGeometry();
bsalomon@google.com5782d712011-01-21 21:03:59 +00001011 bool set(GrDrawTarget* target,
1012 GrVertexLayout vertexLayout,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001013 int vertexCount,
1014 int indexCount);
bsalomon@google.coma47a48d2011-04-26 20:22:11 +00001015 bool succeeded() const { return NULL != fTarget; }
bsalomon@google.com6513cd02011-08-05 20:12:30 +00001016 void* vertices() const { GrAssert(this->succeeded()); return fVertices; }
1017 void* indices() const { GrAssert(this->succeeded()); return fIndices; }
reed@google.comac10a2d2010-12-22 21:39:39 +00001018 GrPoint* positions() const {
bsalomon@google.com6513cd02011-08-05 20:12:30 +00001019 return static_cast<GrPoint*>(this->vertices());
reed@google.comac10a2d2010-12-22 21:39:39 +00001020 }
1021
1022 private:
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001023 void reset();
1024
reed@google.comac10a2d2010-12-22 21:39:39 +00001025 GrDrawTarget* fTarget;
reed@google.comac10a2d2010-12-22 21:39:39 +00001026 void* fVertices;
1027 void* fIndices;
1028 };
1029
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001030 ////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +00001031
1032 class AutoClipRestore : ::GrNoncopyable {
1033 public:
1034 AutoClipRestore(GrDrawTarget* target) {
1035 fTarget = target;
1036 fClip = fTarget->getClip();
1037 }
1038
1039 ~AutoClipRestore() {
1040 fTarget->setClip(fClip);
1041 }
1042 private:
1043 GrDrawTarget* fTarget;
1044 GrClip fClip;
1045 };
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001046
1047 ////////////////////////////////////////////////////////////////////////////
1048
1049 class AutoGeometryPush : ::GrNoncopyable {
1050 public:
1051 AutoGeometryPush(GrDrawTarget* target) {
1052 GrAssert(NULL != target);
1053 fTarget = target;
1054 target->pushGeometrySource();
1055 }
1056 ~AutoGeometryPush() {
1057 fTarget->popGeometrySource();
1058 }
1059 private:
1060 GrDrawTarget* fTarget;
1061 };
reed@google.comac10a2d2010-12-22 21:39:39 +00001062
1063 ////////////////////////////////////////////////////////////////////////////
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001064 // Helpers for picking apart vertex layouts
bsalomon@google.com5782d712011-01-21 21:03:59 +00001065
reed@google.comac10a2d2010-12-22 21:39:39 +00001066 /**
1067 * Helper function to compute the size of a vertex from a vertex layout
1068 * @return size of a single vertex.
1069 */
1070 static size_t VertexSize(GrVertexLayout vertexLayout);
bsalomon@google.com5782d712011-01-21 21:03:59 +00001071
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001072 /**
1073 * Helper function for determining the index of texture coordinates that
1074 * is input for a texture stage. Note that a stage may instead use positions
1075 * as texture coordinates, in which case the result of the function is
1076 * indistinguishable from the case when the stage is disabled.
1077 *
1078 * @param stage the stage to query
1079 * @param vertexLayout layout to query
1080 *
1081 * @return the texture coordinate index or -1 if the stage doesn't use
1082 * separate (non-position) texture coordinates.
1083 */
1084 static int VertexTexCoordsForStage(int stage, GrVertexLayout vertexLayout);
reed@google.comac10a2d2010-12-22 21:39:39 +00001085
1086 /**
1087 * Helper function to compute the offset of texture coordinates in a vertex
1088 * @return offset of texture coordinates in vertex layout or -1 if the
bsalomon@google.com5782d712011-01-21 21:03:59 +00001089 * layout has no texture coordinates. Will be 0 if positions are
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001090 * used as texture coordinates for the stage.
reed@google.comac10a2d2010-12-22 21:39:39 +00001091 */
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001092 static int VertexStageCoordOffset(int stage, GrVertexLayout vertexLayout);
reed@google.comac10a2d2010-12-22 21:39:39 +00001093
1094 /**
1095 * Helper function to compute the offset of the color in a vertex
1096 * @return offset of color in vertex layout or -1 if the
1097 * layout has no color.
1098 */
1099 static int VertexColorOffset(GrVertexLayout vertexLayout);
1100
bsalomon@google.comaeb21602011-08-30 18:13:44 +00001101 /**
1102 * Helper function to compute the offset of the edge pts in a vertex
1103 * @return offset of edge in vertex layout or -1 if the
1104 * layout has no edge.
1105 */
1106 static int VertexEdgeOffset(GrVertexLayout vertexLayout);
1107
reed@google.comac10a2d2010-12-22 21:39:39 +00001108 /**
bsalomon@google.com5782d712011-01-21 21:03:59 +00001109 * Helper function to determine if vertex layout contains explicit texture
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001110 * coordinates of some index.
1111 *
1112 * @param coordIndex the tex coord index to query
1113 * @param vertexLayout layout to query
1114 *
bsalomon@google.com5782d712011-01-21 21:03:59 +00001115 * @return true if vertex specifies texture coordinates for the index,
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001116 * false otherwise.
reed@google.comac10a2d2010-12-22 21:39:39 +00001117 */
bsalomon@google.com5782d712011-01-21 21:03:59 +00001118 static bool VertexUsesTexCoordIdx(int coordIndex,
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001119 GrVertexLayout vertexLayout);
bsalomon@google.com5782d712011-01-21 21:03:59 +00001120
reed@google.comac10a2d2010-12-22 21:39:39 +00001121 /**
1122 * Helper function to determine if vertex layout contains either explicit or
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001123 * implicit texture coordinates for a stage.
reed@google.comac10a2d2010-12-22 21:39:39 +00001124 *
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001125 * @param stage the stage to query
1126 * @param vertexLayout layout to query
1127 *
bsalomon@google.com5782d712011-01-21 21:03:59 +00001128 * @return true if vertex specifies texture coordinates for the stage,
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001129 * false otherwise.
reed@google.comac10a2d2010-12-22 21:39:39 +00001130 */
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001131 static bool VertexUsesStage(int stage, GrVertexLayout vertexLayout);
reed@google.comac10a2d2010-12-22 21:39:39 +00001132
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001133 /**
bsalomon@google.com5782d712011-01-21 21:03:59 +00001134 * Helper function to compute the size of each vertex and the offsets of
1135 * texture coordinates and color. Determines tex coord offsets by tex coord
1136 * index rather than by stage. (Each stage can be mapped to any t.c. index
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001137 * by StageTexCoordVertexLayoutBit.)
1138 *
1139 * @param vertexLayout the layout to query
1140 * @param texCoordOffsetsByIdx after return it is the offset of each
1141 * tex coord index in the vertex or -1 if
1142 * index isn't used.
1143 * @return size of a single vertex
1144 */
1145 static int VertexSizeAndOffsetsByIdx(GrVertexLayout vertexLayout,
1146 int texCoordOffsetsByIdx[kMaxTexCoords],
bsalomon@google.comaeb21602011-08-30 18:13:44 +00001147 int *colorOffset,
1148 int* edgeOffset);
bsalomon@google.com5782d712011-01-21 21:03:59 +00001149
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001150 /**
bsalomon@google.com5782d712011-01-21 21:03:59 +00001151 * Helper function to compute the size of each vertex and the offsets of
1152 * texture coordinates and color. Determines tex coord offsets by stage
1153 * rather than by index. (Each stage can be mapped to any t.c. index
1154 * by StageTexCoordVertexLayoutBit.) If a stage uses positions for
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001155 * tex coords then that stage's offset will be 0 (positions are always at 0).
1156 *
1157 * @param vertexLayout the layout to query
1158 * @param texCoordOffsetsByStage after return it is the offset of each
1159 * tex coord index in the vertex or -1 if
1160 * index isn't used.
1161 * @return size of a single vertex
1162 */
1163 static int VertexSizeAndOffsetsByStage(GrVertexLayout vertexLayout,
1164 int texCoordOffsetsByStage[kNumStages],
bsalomon@google.comaeb21602011-08-30 18:13:44 +00001165 int *colorOffset,
1166 int* edgeOffset);
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001167
1168 /**
1169 * Accessing positions, texture coords, or colors, of a vertex within an
1170 * array is a hassle involving casts and simple math. These helpers exist
1171 * to keep GrDrawTarget clients' code a bit nicer looking.
1172 */
1173
1174 /**
1175 * Gets a pointer to a GrPoint of a vertex's position or texture
1176 * coordinate.
1177 * @param vertices the vetex array
1178 * @param vertexIndex the index of the vertex in the array
1179 * @param vertexSize the size of each vertex in the array
1180 * @param offset the offset in bytes of the vertex component.
1181 * Defaults to zero (corresponding to vertex position)
1182 * @return pointer to the vertex component as a GrPoint
1183 */
bsalomon@google.comd302f142011-03-03 13:54:13 +00001184 static GrPoint* GetVertexPoint(void* vertices,
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001185 int vertexIndex,
1186 int vertexSize,
1187 int offset = 0) {
1188 intptr_t start = GrTCast<intptr_t>(vertices);
bsalomon@google.comd302f142011-03-03 13:54:13 +00001189 return GrTCast<GrPoint*>(start + offset +
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001190 vertexIndex * vertexSize);
1191 }
1192 static const GrPoint* GetVertexPoint(const void* vertices,
1193 int vertexIndex,
bsalomon@google.comd302f142011-03-03 13:54:13 +00001194 int vertexSize,
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001195 int offset = 0) {
1196 intptr_t start = GrTCast<intptr_t>(vertices);
bsalomon@google.comd302f142011-03-03 13:54:13 +00001197 return GrTCast<const GrPoint*>(start + offset +
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001198 vertexIndex * vertexSize);
1199 }
1200
1201 /**
1202 * Gets a pointer to a GrColor inside a vertex within a vertex array.
1203 * @param vertices the vetex array
1204 * @param vertexIndex the index of the vertex in the array
1205 * @param vertexSize the size of each vertex in the array
1206 * @param offset the offset in bytes of the vertex color
1207 * @return pointer to the vertex component as a GrColor
1208 */
bsalomon@google.comd302f142011-03-03 13:54:13 +00001209 static GrColor* GetVertexColor(void* vertices,
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001210 int vertexIndex,
1211 int vertexSize,
1212 int offset) {
1213 intptr_t start = GrTCast<intptr_t>(vertices);
bsalomon@google.comd302f142011-03-03 13:54:13 +00001214 return GrTCast<GrColor*>(start + offset +
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001215 vertexIndex * vertexSize);
1216 }
1217 static const GrColor* GetVertexColor(const void* vertices,
1218 int vertexIndex,
bsalomon@google.comd302f142011-03-03 13:54:13 +00001219 int vertexSize,
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001220 int offset) {
1221 const intptr_t start = GrTCast<intptr_t>(vertices);
bsalomon@google.comd302f142011-03-03 13:54:13 +00001222 return GrTCast<const GrColor*>(start + offset +
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001223 vertexIndex * vertexSize);
1224 }
1225
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +00001226 static void VertexLayoutUnitTest();
1227
reed@google.comac10a2d2010-12-22 21:39:39 +00001228protected:
bsalomon@google.com471d4712011-08-23 15:45:25 +00001229
1230 // determines whether HW blending can be disabled or not
1231 static bool CanDisableBlend(GrVertexLayout layout, const DrState& state);
1232
1233 // determines whether HW AA lines can be used or not
1234 static bool CanUseHWAALines(GrVertexLayout layout, const DrState& state);
1235
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001236 enum GeometrySrcType {
1237 kNone_GeometrySrcType, //<! src has not been specified
1238 kReserved_GeometrySrcType, //<! src was set using reserve*Space
1239 kArray_GeometrySrcType, //<! src was set using set*SourceToArray
1240 kBuffer_GeometrySrcType //<! src was set using set*SourceToBuffer
1241 };
1242
1243 struct GeometrySrcState {
1244 GeometrySrcType fVertexSrc;
1245 union {
1246 // valid if src type is buffer
1247 const GrVertexBuffer* fVertexBuffer;
1248 // valid if src type is reserved or array
1249 int fVertexCount;
1250 };
1251
1252 GeometrySrcType fIndexSrc;
1253 union {
1254 // valid if src type is buffer
1255 const GrIndexBuffer* fIndexBuffer;
1256 // valid if src type is reserved or array
1257 int fIndexCount;
1258 };
1259
1260 GrVertexLayout fVertexLayout;
1261 };
1262
bsalomon@google.coma47a48d2011-04-26 20:22:11 +00001263 // given a vertex layout and a draw state, will a stage be used?
1264 static bool StageWillBeUsed(int stage, GrVertexLayout layout,
bsalomon@google.comaeb21602011-08-30 18:13:44 +00001265 const DrState& state) {
bsalomon@google.coma47a48d2011-04-26 20:22:11 +00001266 return NULL != state.fTextures[stage] && VertexUsesStage(stage, layout);
1267 }
1268
1269 bool isStageEnabled(int stage) const {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001270 return StageWillBeUsed(stage, this->getGeomSrc().fVertexLayout,
1271 fCurrDrawState);
bsalomon@google.coma47a48d2011-04-26 20:22:11 +00001272 }
bsalomon@google.com5782d712011-01-21 21:03:59 +00001273
bsalomon@google.comaeb21602011-08-30 18:13:44 +00001274 StageBitfield enabledStages() const {
1275 StageBitfield mask = 0;
1276 for (int s = 0; s < kNumStages; ++s) {
1277 mask |= this->isStageEnabled(s) ? 1 : 0;
1278 }
1279 return mask;
1280 }
1281
reed@google.comac10a2d2010-12-22 21:39:39 +00001282 // Helpers for GrDrawTarget subclasses that won't have private access to
1283 // SavedDrawState but need to peek at the state values.
reed@google.com8195f672011-01-12 18:14:28 +00001284 static DrState& accessSavedDrawState(SavedDrawState& sds)
reed@google.comac10a2d2010-12-22 21:39:39 +00001285 { return sds.fState; }
reed@google.com8195f672011-01-12 18:14:28 +00001286 static const DrState& accessSavedDrawState(const SavedDrawState& sds)
reed@google.comac10a2d2010-12-22 21:39:39 +00001287 { return sds.fState; }
1288
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001289 // implemented by subclass to allocate space for reserved geom
1290 virtual bool onReserveVertexSpace(GrVertexLayout vertexLayout,
1291 int vertexCount,
1292 void** vertices) = 0;
1293 virtual bool onReserveIndexSpace(int indexCount, void** indices) = 0;
1294 // implemented by subclass to handle release of reserved geom space
1295 virtual void releaseReservedVertexSpace() = 0;
1296 virtual void releaseReservedIndexSpace() = 0;
1297 // subclass must consume array contents when set
1298 virtual void onSetVertexSourceToArray(const void* vertexArray,
1299 int vertexCount) = 0;
1300 virtual void onSetIndexSourceToArray(const void* indexArray,
1301 int indexCount) = 0;
1302 // subclass is notified that geom source will be set away from an array
1303 virtual void releaseVertexArray() = 0;
1304 virtual void releaseIndexArray() = 0;
1305 // subclass overrides to be notified just before geo src state
1306 // is pushed/popped.
1307 virtual void geometrySourceWillPush() = 0;
1308 virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) = 0;
1309 // subclass called to perform drawing
1310 virtual void onDrawIndexed(GrPrimitiveType type,
1311 int startVertex,
1312 int startIndex,
1313 int vertexCount,
1314 int indexCount) = 0;
1315 virtual void onDrawNonIndexed(GrPrimitiveType type,
1316 int startVertex,
1317 int vertexCount) = 0;
bsalomon@google.comdea2f8d2011-08-01 15:51:05 +00001318 // subclass overrides to be notified when clip is set. Must call
1319 // INHERITED::clipwillBeSet
1320 virtual void clipWillBeSet(const GrClip& clip);
bsalomon@google.com1c13c962011-02-14 16:51:21 +00001321
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001322 // Helpers for drawRect, protected so subclasses that override drawRect
1323 // can use them.
bsalomon@google.comffca4002011-02-22 20:34:01 +00001324 static GrVertexLayout GetRectVertexLayout(StageBitfield stageEnableBitfield,
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001325 const GrRect* srcRects[]);
1326
1327 static void SetRectVertices(const GrRect& rect,
bsalomon@google.comd302f142011-03-03 13:54:13 +00001328 const GrMatrix* matrix,
1329 const GrRect* srcRects[],
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001330 const GrMatrix* srcMatrices[],
bsalomon@google.comd302f142011-03-03 13:54:13 +00001331 GrVertexLayout layout,
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001332 void* vertices);
1333
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001334 // accessor for derived classes
1335 const GeometrySrcState& getGeomSrc() const {
1336 return fGeoSrcStateStack.back();
1337 }
reed@google.comac10a2d2010-12-22 21:39:39 +00001338
1339 GrClip fClip;
1340
reed@google.com8195f672011-01-12 18:14:28 +00001341 DrState fCurrDrawState;
reed@google.comac10a2d2010-12-22 21:39:39 +00001342
bsalomon@google.com18c9c192011-09-22 21:01:31 +00001343 Caps fCaps;
1344
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001345private:
1346 // called when setting a new vert/idx source to unref prev vb/ib
1347 void releasePreviousVertexSource();
1348 void releasePreviousIndexSource();
1349
1350 enum {
1351 kPreallocGeoSrcStateStackCnt = 4,
reed@google.comac10a2d2010-12-22 21:39:39 +00001352 };
bsalomon@google.com49313f62011-09-14 13:54:05 +00001353 SkAlignedSTStorage<kPreallocGeoSrcStateStackCnt,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001354 GeometrySrcState>
1355 fGeoSrcStateStackStorage;
bsalomon@google.com49313f62011-09-14 13:54:05 +00001356 SkTArray<GeometrySrcState, true> fGeoSrcStateStack;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001357
reed@google.comac10a2d2010-12-22 21:39:39 +00001358};
1359
1360#endif