blob: 81d0b2baf485bafcce1325836b7efbbb157ffec8 [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.comd46e2422011-09-23 17:40:07 +0000598 /**
599 * Color alpha and coverage are two inputs to the drawing pipeline. For some
600 * blend modes it is safe to fold the coverage into constant or per-vertex
601 * color alpha value. For other blend modes they must be handled separately.
602 * Depending on features available in the underlying 3D API this may or may
603 * not be possible.
604 *
605 * This function looks at the current blend on the draw target and the draw
606 * target's capabilities to determine whether coverage can be handled
607 * correctly.
608 */
609 bool canApplyCoverage() const;
610
611 /**
612 * Determines whether incorporating partial pixel coverage into the constant
613 * color specified by setColor or per-vertex colors will give the right
614 * blending result.
615 */
616 bool canTweakAlphaForCoverage() const {
617 return CanTweakAlphaForCoverage(fCurrDrawState.fDstBlend);
618 }
619
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000620 /**
621 * Determines the interpretation per-vertex edge data when the
622 * kEdge_VertexLayoutBit is set (see below). When per-vertex edges are not
623 * specified the value of this setting has no effect.
624 */
625 void setVertexEdgeType(VertexEdgeType type) {
626 fCurrDrawState.fVertexEdgeType = type;
627 }
628
senorblanco@chromium.org92e0f222011-05-12 15:49:15 +0000629 /**
bsalomon@google.com471d4712011-08-23 15:45:25 +0000630 * Given the current draw state, vertex layout, and hw support, will HW AA
631 * lines be used (if line primitive type is drawn)? (Note that lines are
632 * always 1 pixel wide)
633 */
634 virtual bool willUseHWAALines() const = 0;
635
636 /**
senorblanco@chromium.org92e0f222011-05-12 15:49:15 +0000637 * Sets the edge data required for edge antialiasing.
638 *
639 * @param edges 3 * 6 float values, representing the edge
640 * equations in Ax + By + C form
641 */
senorblanco@chromium.orgef3913b2011-05-19 17:11:07 +0000642 void setEdgeAAData(const Edge* edges, int numEdges);
senorblanco@chromium.org92e0f222011-05-12 15:49:15 +0000643
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000644private:
645 static const int TEX_COORD_BIT_CNT = kNumStages*kMaxTexCoords;
646public:
647 /**
648 * Generates a bit indicating that a texture stage uses the position
649 * as its texture coordinate.
650 *
bsalomon@google.com5782d712011-01-21 21:03:59 +0000651 * @param stage the stage that will use position as texture
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000652 * coordinates.
653 *
654 * @return the bit to add to a GrVertexLayout bitfield.
655 */
656 static int StagePosAsTexCoordVertexLayoutBit(int stage) {
657 GrAssert(stage < kNumStages);
bsalomon@google.com5782d712011-01-21 21:03:59 +0000658 return (1 << (TEX_COORD_BIT_CNT + stage));
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000659 }
660private:
661 static const int STAGE_BIT_CNT = TEX_COORD_BIT_CNT + kNumStages;
bsalomon@google.com5782d712011-01-21 21:03:59 +0000662
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000663public:
bsalomon@google.com5782d712011-01-21 21:03:59 +0000664
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000665 /**
666 * Additional Bits that can be specified in GrVertexLayout.
reed@google.comac10a2d2010-12-22 21:39:39 +0000667 */
668 enum VertexLayoutBits {
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000669 /* vertices have colors */
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000670 kColor_VertexLayoutBit = 1 << (STAGE_BIT_CNT + 0),
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000671
672 /* Use text vertices. (Pos and tex coords may be a different type for
673 text [GrGpuTextVertex vs GrPoint].) */
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000674 kTextFormat_VertexLayoutBit = 1 << (STAGE_BIT_CNT + 1),
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000675
676 kEdge_VertexLayoutBit = 1 << (STAGE_BIT_CNT + 2),
reed@google.comac10a2d2010-12-22 21:39:39 +0000677 // for below assert
bsalomon@google.comd302f142011-03-03 13:54:13 +0000678 kDummyVertexLayoutBit,
679 kHighVertexLayoutBit = kDummyVertexLayoutBit - 1
reed@google.comac10a2d2010-12-22 21:39:39 +0000680 };
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000681 // make sure we haven't exceeded the number of bits in GrVertexLayout.
bsalomon@google.com4be283f2011-04-19 21:15:09 +0000682 GR_STATIC_ASSERT(kHighVertexLayoutBit < ((uint64_t)1 << 8*sizeof(GrVertexLayout)));
reed@google.comac10a2d2010-12-22 21:39:39 +0000683
684 /**
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000685 * There are three methods for specifying geometry (vertices and optionally
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000686 * indices) to the draw target. When indexed drawing the indices and vertices
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000687 * can use a different method. Once geometry is specified it can be used for
688 * multiple drawIndexed and drawNonIndexed calls.
689 *
690 * Sometimes it is necessary to perform a draw while upstack code has
691 * already specified geometry that it isn't finished with. There are push
692 * pop methods
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000693 *
694 * 1. Provide a cpu array (set*SourceToArray). This is useful when the
695 * caller's client has already provided vertex data in a format
696 * the time compatible with a GrVertexLayout. The array must contain the
697 * data at set*SourceToArray is called. The source stays in effect for
698 * drawIndexed & drawNonIndexed calls until set*SourceToArray is called
699 * again or one of the other two paths is chosen.
700 *
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000701 * 2. Reserve. This is most useful when the caller has data it must
702 * transform before drawing and is not long-lived. The caller requests
703 * that the draw target make room for some amount of vertex and/or index
704 * data. The target provides ptrs to hold the vertex and/or index data.
705 *
706 * The data is writable up until the next drawIndexed, drawNonIndexed,
707 * or pushGeometrySource At this point the data is frozen and the ptrs
708 * are no longer valid.
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000709 *
710 * 3. Vertex and Index Buffers. This is most useful for geometry that will
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000711 * is long-lived. SetVertexSourceToBuffer and SetIndexSourceToBuffer are
712 * used to set the buffer and subsequent drawIndexed and drawNonIndexed
713 * calls use this source until another source is set.
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000714 */
715
716 /**
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000717 * Reserves space for vertices. Draw target will use reserved vertices at
718 * at the next draw.
reed@google.comac10a2d2010-12-22 21:39:39 +0000719 *
720 * If succeeds:
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000721 * if vertexCount > 0, *vertices will be the array
reed@google.comac10a2d2010-12-22 21:39:39 +0000722 * of vertices to be filled by caller. The next draw will read
723 * these vertices.
724 *
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000725 * If a client does not already have a vertex buffer then this is the
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000726 * preferred way to allocate vertex data. It allows the subclass of
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000727 * GrDrawTarget to decide whether to put data in buffers, to group vertex
728 * data that uses the same state (e.g. for deferred rendering), etc.
reed@google.comac10a2d2010-12-22 21:39:39 +0000729 *
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000730 * After the next draw or pushGeometrySource the vertices ptr is no longer
731 * valid and the geometry data cannot be further modified. The contents
732 * that were put in the reserved space can be drawn by multiple draws,
733 * however.
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000734 *
reed@google.comac10a2d2010-12-22 21:39:39 +0000735 * @param vertexLayout the format of vertices (ignored if vertexCount == 0).
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000736 * @param vertexCount the number of vertices to reserve space for. Can be 0.
reed@google.comac10a2d2010-12-22 21:39:39 +0000737 * @param vertices will point to reserved vertex space if vertexCount is
738 * non-zero. Illegal to pass NULL if vertexCount > 0.
reed@google.comac10a2d2010-12-22 21:39:39 +0000739 *
740 * @return true if succeeded in allocating space for the vertices and false
741 * if not.
742 */
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000743 bool reserveVertexSpace(GrVertexLayout vertexLayout,
744 int vertexCount,
745 void** vertices);
746 /**
747 * Reserves space for indices. Draw target will use the reserved indices at
748 * the next indexed draw.
749 *
750 * If succeeds:
751 * if indexCount > 0, *indices will be the array
752 * of indices to be filled by caller. The next draw will read
753 * these indices.
754 *
755 * If a client does not already have a index buffer then this is the
756 * preferred way to allocate index data. It allows the subclass of
757 * GrDrawTarget to decide whether to put data in buffers, to group index
758 * data that uses the same state (e.g. for deferred rendering), etc.
759 *
760 * After the next indexed draw or pushGeometrySource the indices ptr is no
761 * longer valid and the geometry data cannot be further modified. The
762 * contents that were put in the reserved space can be drawn by multiple
763 * draws, however.
764 *
765 * @param indexCount the number of indices to reserve space for. Can be 0.
766 * @param indices will point to reserved index space if indexCount is
767 * non-zero. Illegal to pass NULL if indexCount > 0.
768 */
769
770 bool reserveIndexSpace(int indexCount, void** indices);
reed@google.comac10a2d2010-12-22 21:39:39 +0000771 /**
772 * Provides hints to caller about the number of vertices and indices
773 * that can be allocated cheaply. This can be useful if caller is reserving
774 * space but doesn't know exactly how much geometry is needed.
775 *
776 * Also may hint whether the draw target should be flushed first. This is
777 * useful for deferred targets.
778 *
779 * @param vertexLayout layout of vertices caller would like to reserve
780 * @param vertexCount in: hint about how many vertices the caller would
781 * like to allocate.
782 * out: a hint about the number of vertices that can be
783 * allocated cheaply. Negative means no hint.
784 * Ignored if NULL.
785 * @param indexCount in: hint about how many indices the caller would
786 * like to allocate.
787 * out: a hint about the number of indices that can be
788 * allocated cheaply. Negative means no hint.
789 * Ignored if NULL.
790 *
791 * @return true if target should be flushed based on the input values.
792 */
793 virtual bool geometryHints(GrVertexLayout vertexLayout,
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000794 int* vertexCount,
795 int* indexCount) const;
reed@google.comac10a2d2010-12-22 21:39:39 +0000796
797 /**
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000798 * Sets source of vertex data for the next draw. Array must contain
799 * the vertex data when this is called.
reed@google.comac10a2d2010-12-22 21:39:39 +0000800 *
801 * @param array cpu array containing vertex data.
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000802 * @param size size of the vertex data.
803 * @param vertexCount the number of vertices in the array.
reed@google.comac10a2d2010-12-22 21:39:39 +0000804 */
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000805 void setVertexSourceToArray(GrVertexLayout vertexLayout,
806 const void* vertexArray,
807 int vertexCount);
reed@google.comac10a2d2010-12-22 21:39:39 +0000808
809 /**
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000810 * Sets source of index data for the next indexed draw. Array must contain
811 * the indices when this is called.
reed@google.comac10a2d2010-12-22 21:39:39 +0000812 *
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000813 * @param array cpu array containing index data.
814 * @param indexCount the number of indices in the array.
reed@google.comac10a2d2010-12-22 21:39:39 +0000815 */
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000816 void setIndexSourceToArray(const void* indexArray, int indexCount);
reed@google.comac10a2d2010-12-22 21:39:39 +0000817
818 /**
819 * Sets source of vertex data for the next draw. Data does not have to be
820 * in the buffer until drawIndexed or drawNonIndexed.
821 *
822 * @param buffer vertex buffer containing vertex data. Must be
823 * unlocked before draw call.
824 * @param vertexLayout layout of the vertex data in the buffer.
825 */
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000826 void setVertexSourceToBuffer(GrVertexLayout vertexLayout,
827 const GrVertexBuffer* buffer);
reed@google.comac10a2d2010-12-22 21:39:39 +0000828
829 /**
830 * Sets source of index data for the next indexed draw. Data does not have
831 * to be in the buffer until drawIndexed or drawNonIndexed.
832 *
833 * @param buffer index buffer containing indices. Must be unlocked
834 * before indexed draw call.
835 */
836 void setIndexSourceToBuffer(const GrIndexBuffer* buffer);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000837
838 /**
839 * Resets vertex source. Drawing from reset vertices is illegal. Set vertex
840 * source to reserved, array, or buffer before next draw. May be able to free
841 * up temporary storage allocated by setVertexSourceToArray or
842 * reserveVertexSpace.
843 */
844 void resetVertexSource();
845
846 /**
847 * Resets index source. Indexed Drawing from reset indices is illegal. Set
848 * index source to reserved, array, or buffer before next indexed draw. May
849 * be able to free up temporary storage allocated by setIndexSourceToArray
850 * or reserveIndexSpace.
851 */
852 void resetIndexSource();
reed@google.comac10a2d2010-12-22 21:39:39 +0000853
854 /**
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000855 * Pushes and resets the vertex/index sources. Any reserved vertex / index
856 * data is finalized (i.e. cannot be updated after the matching pop but can
857 * be drawn from). Must be balanced by a pop.
858 */
859 void pushGeometrySource();
860
861 /**
862 * Pops the vertex / index sources from the matching push.
863 */
864 void popGeometrySource();
865
866 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000867 * Draws indexed geometry using the current state and current vertex / index
868 * sources.
869 *
870 * @param type The type of primitives to draw.
871 * @param startVertex the vertex in the vertex array/buffer corresponding
872 * to index 0
873 * @param startIndex first index to read from index src.
874 * @param vertexCount one greater than the max index.
875 * @param indexCount the number of index elements to read. The index count
876 * is effectively trimmed to the last completely
877 * specified primitive.
878 */
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000879 void drawIndexed(GrPrimitiveType type,
880 int startVertex,
881 int startIndex,
882 int vertexCount,
883 int indexCount);
reed@google.comac10a2d2010-12-22 21:39:39 +0000884
885 /**
886 * Draws non-indexed geometry using the current state and current vertex
887 * sources.
888 *
889 * @param type The type of primitives to draw.
890 * @param startVertex the vertex in the vertex array/buffer corresponding
891 * to index 0
892 * @param vertexCount one greater than the max index.
893 */
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000894 void drawNonIndexed(GrPrimitiveType type,
895 int startVertex,
896 int vertexCount);
reed@google.comac10a2d2010-12-22 21:39:39 +0000897
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000898 /**
899 * Helper function for drawing rects. This does not use the current index
900 * and vertex sources. After returning, the vertex and index sources may
901 * have changed. They should be reestablished before the next drawIndexed
902 * or drawNonIndexed. This cannot be called between reserving and releasing
903 * geometry. The GrDrawTarget subclass may be able to perform additional
bsalomon@google.comd302f142011-03-03 13:54:13 +0000904 * optimizations if drawRect is used rather than drawIndexed or
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000905 * drawNonIndexed.
906 * @param rect the rect to draw
907 * @param matrix optional matrix applied to rect (before viewMatrix)
bsalomon@google.comffca4002011-02-22 20:34:01 +0000908 * @param stageEnableBitfield bitmask indicating which stages are enabled.
909 * Bit i indicates whether stage i is enabled.
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000910 * @param srcRects specifies rects for stages enabled by stageEnableMask.
911 * if stageEnableMask bit i is 1, srcRects is not NULL,
912 * and srcRects[i] is not NULL, then srcRects[i] will be
913 * used as coordinates for stage i. Otherwise, if stage i
914 * is enabled then rect is used as the coordinates.
915 * @param srcMatrices optional matrices applied to srcRects. If
916 * srcRect[i] is non-NULL and srcMatrices[i] is
917 * non-NULL then srcRect[i] will be transformed by
918 * srcMatrix[i]. srcMatrices can be NULL when no
919 * srcMatrices are desired.
920 */
bsalomon@google.comd302f142011-03-03 13:54:13 +0000921 virtual void drawRect(const GrRect& rect,
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000922 const GrMatrix* matrix,
bsalomon@google.comffca4002011-02-22 20:34:01 +0000923 StageBitfield stageEnableBitfield,
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000924 const GrRect* srcRects[],
925 const GrMatrix* srcMatrices[]);
926
927 /**
bsalomon@google.comd302f142011-03-03 13:54:13 +0000928 * Helper for drawRect when the caller doesn't need separate src rects or
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000929 * matrices.
930 */
bsalomon@google.comd302f142011-03-03 13:54:13 +0000931 void drawSimpleRect(const GrRect& rect,
932 const GrMatrix* matrix,
bsalomon@google.comffca4002011-02-22 20:34:01 +0000933 StageBitfield stageEnableBitfield) {
934 drawRect(rect, matrix, stageEnableBitfield, NULL, NULL);
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000935 }
936
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000937 /**
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000938 * Clear the render target. Ignores the clip and all other draw state
939 * (blend mode, stages, etc). Clears the whole thing if rect is NULL,
940 * otherwise just the rect.
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000941 */
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000942 virtual void clear(const GrIRect* rect, GrColor color) = 0;
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000943
senorblanco@chromium.orgef3913b2011-05-19 17:11:07 +0000944 /**
945 * Returns the maximum number of edges that may be specified in a single
946 * draw call when performing edge antialiasing. This is usually limited
947 * by the number of fragment uniforms which may be uploaded. Must be a
948 * minimum of six, since a triangle's vertices each belong to two boundary
949 * edges which may be distinct.
950 */
951 virtual int getMaxEdges() const { return 6; }
952
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000953 ////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +0000954
955 class AutoStateRestore : ::GrNoncopyable {
956 public:
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000957 AutoStateRestore();
reed@google.comac10a2d2010-12-22 21:39:39 +0000958 AutoStateRestore(GrDrawTarget* target);
959 ~AutoStateRestore();
960
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000961 /**
962 * if this object is already saving state for param target then
963 * this does nothing. Otherise, it restores previously saved state on
964 * previous target (if any) and saves current state on param target.
965 */
966 void set(GrDrawTarget* target);
967
reed@google.comac10a2d2010-12-22 21:39:39 +0000968 private:
969 GrDrawTarget* fDrawTarget;
970 SavedDrawState fDrawState;
971 };
972
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000973 ////////////////////////////////////////////////////////////////////////////
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000974
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000975 class AutoViewMatrixRestore : ::GrNoncopyable {
976 public:
977 AutoViewMatrixRestore() {
978 fDrawTarget = NULL;
979 }
980
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000981 AutoViewMatrixRestore(GrDrawTarget* target)
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000982 : fDrawTarget(target), fMatrix(fDrawTarget->getViewMatrix()) {
983 GrAssert(NULL != target);
984 }
985
986 void set(GrDrawTarget* target) {
987 GrAssert(NULL != target);
988 if (NULL != fDrawTarget) {
989 fDrawTarget->setViewMatrix(fMatrix);
990 }
991 fDrawTarget = target;
992 fMatrix = target->getViewMatrix();
993 }
994
995 ~AutoViewMatrixRestore() {
996 if (NULL != fDrawTarget) {
997 fDrawTarget->setViewMatrix(fMatrix);
998 }
999 }
1000
1001 private:
1002 GrDrawTarget* fDrawTarget;
1003 GrMatrix fMatrix;
1004 };
1005
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001006 ////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +00001007
bsalomon@google.com7ac249b2011-06-14 18:46:24 +00001008 /**
1009 * Sets the view matrix to I and preconcats all stage matrices enabled in
1010 * mask by the view inverse. Destructor undoes these changes.
1011 */
1012 class AutoDeviceCoordDraw : ::GrNoncopyable {
1013 public:
1014 AutoDeviceCoordDraw(GrDrawTarget* target, int stageMask);
1015 ~AutoDeviceCoordDraw();
1016 private:
1017 GrDrawTarget* fDrawTarget;
1018 GrMatrix fViewMatrix;
1019 GrMatrix fSamplerMatrices[kNumStages];
1020 int fStageMask;
1021 };
1022
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001023 ////////////////////////////////////////////////////////////////////////////
bsalomon@google.com7ac249b2011-06-14 18:46:24 +00001024
reed@google.comac10a2d2010-12-22 21:39:39 +00001025 class AutoReleaseGeometry : ::GrNoncopyable {
1026 public:
1027 AutoReleaseGeometry(GrDrawTarget* target,
1028 GrVertexLayout vertexLayout,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001029 int vertexCount,
1030 int indexCount);
1031 AutoReleaseGeometry();
1032 ~AutoReleaseGeometry();
bsalomon@google.com5782d712011-01-21 21:03:59 +00001033 bool set(GrDrawTarget* target,
1034 GrVertexLayout vertexLayout,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001035 int vertexCount,
1036 int indexCount);
bsalomon@google.coma47a48d2011-04-26 20:22:11 +00001037 bool succeeded() const { return NULL != fTarget; }
bsalomon@google.com6513cd02011-08-05 20:12:30 +00001038 void* vertices() const { GrAssert(this->succeeded()); return fVertices; }
1039 void* indices() const { GrAssert(this->succeeded()); return fIndices; }
reed@google.comac10a2d2010-12-22 21:39:39 +00001040 GrPoint* positions() const {
bsalomon@google.com6513cd02011-08-05 20:12:30 +00001041 return static_cast<GrPoint*>(this->vertices());
reed@google.comac10a2d2010-12-22 21:39:39 +00001042 }
1043
1044 private:
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001045 void reset();
1046
reed@google.comac10a2d2010-12-22 21:39:39 +00001047 GrDrawTarget* fTarget;
reed@google.comac10a2d2010-12-22 21:39:39 +00001048 void* fVertices;
1049 void* fIndices;
1050 };
1051
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001052 ////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +00001053
1054 class AutoClipRestore : ::GrNoncopyable {
1055 public:
1056 AutoClipRestore(GrDrawTarget* target) {
1057 fTarget = target;
1058 fClip = fTarget->getClip();
1059 }
1060
1061 ~AutoClipRestore() {
1062 fTarget->setClip(fClip);
1063 }
1064 private:
1065 GrDrawTarget* fTarget;
1066 GrClip fClip;
1067 };
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001068
1069 ////////////////////////////////////////////////////////////////////////////
1070
1071 class AutoGeometryPush : ::GrNoncopyable {
1072 public:
1073 AutoGeometryPush(GrDrawTarget* target) {
1074 GrAssert(NULL != target);
1075 fTarget = target;
1076 target->pushGeometrySource();
1077 }
1078 ~AutoGeometryPush() {
1079 fTarget->popGeometrySource();
1080 }
1081 private:
1082 GrDrawTarget* fTarget;
1083 };
reed@google.comac10a2d2010-12-22 21:39:39 +00001084
1085 ////////////////////////////////////////////////////////////////////////////
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001086 // Helpers for picking apart vertex layouts
bsalomon@google.com5782d712011-01-21 21:03:59 +00001087
reed@google.comac10a2d2010-12-22 21:39:39 +00001088 /**
1089 * Helper function to compute the size of a vertex from a vertex layout
1090 * @return size of a single vertex.
1091 */
1092 static size_t VertexSize(GrVertexLayout vertexLayout);
bsalomon@google.com5782d712011-01-21 21:03:59 +00001093
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001094 /**
1095 * Helper function for determining the index of texture coordinates that
1096 * is input for a texture stage. Note that a stage may instead use positions
1097 * as texture coordinates, in which case the result of the function is
1098 * indistinguishable from the case when the stage is disabled.
1099 *
1100 * @param stage the stage to query
1101 * @param vertexLayout layout to query
1102 *
1103 * @return the texture coordinate index or -1 if the stage doesn't use
1104 * separate (non-position) texture coordinates.
1105 */
1106 static int VertexTexCoordsForStage(int stage, GrVertexLayout vertexLayout);
reed@google.comac10a2d2010-12-22 21:39:39 +00001107
1108 /**
1109 * Helper function to compute the offset of texture coordinates in a vertex
1110 * @return offset of texture coordinates in vertex layout or -1 if the
bsalomon@google.com5782d712011-01-21 21:03:59 +00001111 * layout has no texture coordinates. Will be 0 if positions are
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001112 * used as texture coordinates for the stage.
reed@google.comac10a2d2010-12-22 21:39:39 +00001113 */
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001114 static int VertexStageCoordOffset(int stage, GrVertexLayout vertexLayout);
reed@google.comac10a2d2010-12-22 21:39:39 +00001115
1116 /**
1117 * Helper function to compute the offset of the color in a vertex
1118 * @return offset of color in vertex layout or -1 if the
1119 * layout has no color.
1120 */
1121 static int VertexColorOffset(GrVertexLayout vertexLayout);
1122
bsalomon@google.comaeb21602011-08-30 18:13:44 +00001123 /**
1124 * Helper function to compute the offset of the edge pts in a vertex
1125 * @return offset of edge in vertex layout or -1 if the
1126 * layout has no edge.
1127 */
1128 static int VertexEdgeOffset(GrVertexLayout vertexLayout);
1129
reed@google.comac10a2d2010-12-22 21:39:39 +00001130 /**
bsalomon@google.com5782d712011-01-21 21:03:59 +00001131 * Helper function to determine if vertex layout contains explicit texture
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001132 * coordinates of some index.
1133 *
1134 * @param coordIndex the tex coord index to query
1135 * @param vertexLayout layout to query
1136 *
bsalomon@google.com5782d712011-01-21 21:03:59 +00001137 * @return true if vertex specifies texture coordinates for the index,
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001138 * false otherwise.
reed@google.comac10a2d2010-12-22 21:39:39 +00001139 */
bsalomon@google.com5782d712011-01-21 21:03:59 +00001140 static bool VertexUsesTexCoordIdx(int coordIndex,
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001141 GrVertexLayout vertexLayout);
bsalomon@google.com5782d712011-01-21 21:03:59 +00001142
reed@google.comac10a2d2010-12-22 21:39:39 +00001143 /**
1144 * Helper function to determine if vertex layout contains either explicit or
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001145 * implicit texture coordinates for a stage.
reed@google.comac10a2d2010-12-22 21:39:39 +00001146 *
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001147 * @param stage the stage to query
1148 * @param vertexLayout layout to query
1149 *
bsalomon@google.com5782d712011-01-21 21:03:59 +00001150 * @return true if vertex specifies texture coordinates for the stage,
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001151 * false otherwise.
reed@google.comac10a2d2010-12-22 21:39:39 +00001152 */
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001153 static bool VertexUsesStage(int stage, GrVertexLayout vertexLayout);
reed@google.comac10a2d2010-12-22 21:39:39 +00001154
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001155 /**
bsalomon@google.com5782d712011-01-21 21:03:59 +00001156 * Helper function to compute the size of each vertex and the offsets of
1157 * texture coordinates and color. Determines tex coord offsets by tex coord
1158 * index rather than by stage. (Each stage can be mapped to any t.c. index
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001159 * by StageTexCoordVertexLayoutBit.)
1160 *
1161 * @param vertexLayout the layout to query
1162 * @param texCoordOffsetsByIdx after return it is the offset of each
1163 * tex coord index in the vertex or -1 if
1164 * index isn't used.
1165 * @return size of a single vertex
1166 */
1167 static int VertexSizeAndOffsetsByIdx(GrVertexLayout vertexLayout,
1168 int texCoordOffsetsByIdx[kMaxTexCoords],
bsalomon@google.comaeb21602011-08-30 18:13:44 +00001169 int *colorOffset,
1170 int* edgeOffset);
bsalomon@google.com5782d712011-01-21 21:03:59 +00001171
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001172 /**
bsalomon@google.com5782d712011-01-21 21:03:59 +00001173 * Helper function to compute the size of each vertex and the offsets of
1174 * texture coordinates and color. Determines tex coord offsets by stage
1175 * rather than by index. (Each stage can be mapped to any t.c. index
1176 * by StageTexCoordVertexLayoutBit.) If a stage uses positions for
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001177 * tex coords then that stage's offset will be 0 (positions are always at 0).
1178 *
1179 * @param vertexLayout the layout to query
1180 * @param texCoordOffsetsByStage after return it is the offset of each
1181 * tex coord index in the vertex or -1 if
1182 * index isn't used.
1183 * @return size of a single vertex
1184 */
1185 static int VertexSizeAndOffsetsByStage(GrVertexLayout vertexLayout,
1186 int texCoordOffsetsByStage[kNumStages],
bsalomon@google.comaeb21602011-08-30 18:13:44 +00001187 int *colorOffset,
1188 int* edgeOffset);
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001189
1190 /**
1191 * Accessing positions, texture coords, or colors, of a vertex within an
1192 * array is a hassle involving casts and simple math. These helpers exist
1193 * to keep GrDrawTarget clients' code a bit nicer looking.
1194 */
1195
1196 /**
1197 * Gets a pointer to a GrPoint of a vertex's position or texture
1198 * coordinate.
1199 * @param vertices the vetex array
1200 * @param vertexIndex the index of the vertex in the array
1201 * @param vertexSize the size of each vertex in the array
1202 * @param offset the offset in bytes of the vertex component.
1203 * Defaults to zero (corresponding to vertex position)
1204 * @return pointer to the vertex component as a GrPoint
1205 */
bsalomon@google.comd302f142011-03-03 13:54:13 +00001206 static GrPoint* GetVertexPoint(void* vertices,
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001207 int vertexIndex,
1208 int vertexSize,
1209 int offset = 0) {
1210 intptr_t start = GrTCast<intptr_t>(vertices);
bsalomon@google.comd302f142011-03-03 13:54:13 +00001211 return GrTCast<GrPoint*>(start + offset +
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001212 vertexIndex * vertexSize);
1213 }
1214 static const GrPoint* GetVertexPoint(const void* vertices,
1215 int vertexIndex,
bsalomon@google.comd302f142011-03-03 13:54:13 +00001216 int vertexSize,
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001217 int offset = 0) {
1218 intptr_t start = GrTCast<intptr_t>(vertices);
bsalomon@google.comd302f142011-03-03 13:54:13 +00001219 return GrTCast<const GrPoint*>(start + offset +
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001220 vertexIndex * vertexSize);
1221 }
1222
1223 /**
1224 * Gets a pointer to a GrColor inside a vertex within a vertex array.
1225 * @param vertices the vetex array
1226 * @param vertexIndex the index of the vertex in the array
1227 * @param vertexSize the size of each vertex in the array
1228 * @param offset the offset in bytes of the vertex color
1229 * @return pointer to the vertex component as a GrColor
1230 */
bsalomon@google.comd302f142011-03-03 13:54:13 +00001231 static GrColor* GetVertexColor(void* vertices,
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001232 int vertexIndex,
1233 int vertexSize,
1234 int offset) {
1235 intptr_t start = GrTCast<intptr_t>(vertices);
bsalomon@google.comd302f142011-03-03 13:54:13 +00001236 return GrTCast<GrColor*>(start + offset +
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001237 vertexIndex * vertexSize);
1238 }
1239 static const GrColor* GetVertexColor(const void* vertices,
1240 int vertexIndex,
bsalomon@google.comd302f142011-03-03 13:54:13 +00001241 int vertexSize,
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001242 int offset) {
1243 const intptr_t start = GrTCast<intptr_t>(vertices);
bsalomon@google.comd302f142011-03-03 13:54:13 +00001244 return GrTCast<const GrColor*>(start + offset +
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001245 vertexIndex * vertexSize);
1246 }
1247
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +00001248 static void VertexLayoutUnitTest();
1249
reed@google.comac10a2d2010-12-22 21:39:39 +00001250protected:
bsalomon@google.com471d4712011-08-23 15:45:25 +00001251
bsalomon@google.comd46e2422011-09-23 17:40:07 +00001252 // Determines whether it is correct to apply partial pixel coverage
1253 // by multiplying the src color by the fractional coverage.
1254 static bool CanTweakAlphaForCoverage(GrBlendCoeff dstCoeff);
1255
bsalomon@google.com471d4712011-08-23 15:45:25 +00001256 // determines whether HW blending can be disabled or not
1257 static bool CanDisableBlend(GrVertexLayout layout, const DrState& state);
1258
1259 // determines whether HW AA lines can be used or not
1260 static bool CanUseHWAALines(GrVertexLayout layout, const DrState& state);
1261
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001262 enum GeometrySrcType {
1263 kNone_GeometrySrcType, //<! src has not been specified
1264 kReserved_GeometrySrcType, //<! src was set using reserve*Space
1265 kArray_GeometrySrcType, //<! src was set using set*SourceToArray
1266 kBuffer_GeometrySrcType //<! src was set using set*SourceToBuffer
1267 };
1268
1269 struct GeometrySrcState {
1270 GeometrySrcType fVertexSrc;
1271 union {
1272 // valid if src type is buffer
1273 const GrVertexBuffer* fVertexBuffer;
1274 // valid if src type is reserved or array
1275 int fVertexCount;
1276 };
1277
1278 GeometrySrcType fIndexSrc;
1279 union {
1280 // valid if src type is buffer
1281 const GrIndexBuffer* fIndexBuffer;
1282 // valid if src type is reserved or array
1283 int fIndexCount;
1284 };
1285
1286 GrVertexLayout fVertexLayout;
1287 };
1288
bsalomon@google.coma47a48d2011-04-26 20:22:11 +00001289 // given a vertex layout and a draw state, will a stage be used?
1290 static bool StageWillBeUsed(int stage, GrVertexLayout layout,
bsalomon@google.comaeb21602011-08-30 18:13:44 +00001291 const DrState& state) {
bsalomon@google.coma47a48d2011-04-26 20:22:11 +00001292 return NULL != state.fTextures[stage] && VertexUsesStage(stage, layout);
1293 }
1294
1295 bool isStageEnabled(int stage) const {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001296 return StageWillBeUsed(stage, this->getGeomSrc().fVertexLayout,
1297 fCurrDrawState);
bsalomon@google.coma47a48d2011-04-26 20:22:11 +00001298 }
bsalomon@google.com5782d712011-01-21 21:03:59 +00001299
bsalomon@google.comaeb21602011-08-30 18:13:44 +00001300 StageBitfield enabledStages() const {
1301 StageBitfield mask = 0;
1302 for (int s = 0; s < kNumStages; ++s) {
1303 mask |= this->isStageEnabled(s) ? 1 : 0;
1304 }
1305 return mask;
1306 }
1307
reed@google.comac10a2d2010-12-22 21:39:39 +00001308 // Helpers for GrDrawTarget subclasses that won't have private access to
1309 // SavedDrawState but need to peek at the state values.
reed@google.com8195f672011-01-12 18:14:28 +00001310 static DrState& accessSavedDrawState(SavedDrawState& sds)
reed@google.comac10a2d2010-12-22 21:39:39 +00001311 { return sds.fState; }
reed@google.com8195f672011-01-12 18:14:28 +00001312 static const DrState& accessSavedDrawState(const SavedDrawState& sds)
reed@google.comac10a2d2010-12-22 21:39:39 +00001313 { return sds.fState; }
1314
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001315 // implemented by subclass to allocate space for reserved geom
1316 virtual bool onReserveVertexSpace(GrVertexLayout vertexLayout,
1317 int vertexCount,
1318 void** vertices) = 0;
1319 virtual bool onReserveIndexSpace(int indexCount, void** indices) = 0;
1320 // implemented by subclass to handle release of reserved geom space
1321 virtual void releaseReservedVertexSpace() = 0;
1322 virtual void releaseReservedIndexSpace() = 0;
1323 // subclass must consume array contents when set
1324 virtual void onSetVertexSourceToArray(const void* vertexArray,
1325 int vertexCount) = 0;
1326 virtual void onSetIndexSourceToArray(const void* indexArray,
1327 int indexCount) = 0;
1328 // subclass is notified that geom source will be set away from an array
1329 virtual void releaseVertexArray() = 0;
1330 virtual void releaseIndexArray() = 0;
1331 // subclass overrides to be notified just before geo src state
1332 // is pushed/popped.
1333 virtual void geometrySourceWillPush() = 0;
1334 virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) = 0;
1335 // subclass called to perform drawing
1336 virtual void onDrawIndexed(GrPrimitiveType type,
1337 int startVertex,
1338 int startIndex,
1339 int vertexCount,
1340 int indexCount) = 0;
1341 virtual void onDrawNonIndexed(GrPrimitiveType type,
1342 int startVertex,
1343 int vertexCount) = 0;
bsalomon@google.comdea2f8d2011-08-01 15:51:05 +00001344 // subclass overrides to be notified when clip is set. Must call
1345 // INHERITED::clipwillBeSet
1346 virtual void clipWillBeSet(const GrClip& clip);
bsalomon@google.com1c13c962011-02-14 16:51:21 +00001347
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001348 // Helpers for drawRect, protected so subclasses that override drawRect
1349 // can use them.
bsalomon@google.comffca4002011-02-22 20:34:01 +00001350 static GrVertexLayout GetRectVertexLayout(StageBitfield stageEnableBitfield,
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001351 const GrRect* srcRects[]);
1352
1353 static void SetRectVertices(const GrRect& rect,
bsalomon@google.comd302f142011-03-03 13:54:13 +00001354 const GrMatrix* matrix,
1355 const GrRect* srcRects[],
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001356 const GrMatrix* srcMatrices[],
bsalomon@google.comd302f142011-03-03 13:54:13 +00001357 GrVertexLayout layout,
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001358 void* vertices);
1359
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001360 // accessor for derived classes
1361 const GeometrySrcState& getGeomSrc() const {
1362 return fGeoSrcStateStack.back();
1363 }
reed@google.comac10a2d2010-12-22 21:39:39 +00001364
1365 GrClip fClip;
1366
reed@google.com8195f672011-01-12 18:14:28 +00001367 DrState fCurrDrawState;
reed@google.comac10a2d2010-12-22 21:39:39 +00001368
bsalomon@google.com18c9c192011-09-22 21:01:31 +00001369 Caps fCaps;
1370
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001371private:
1372 // called when setting a new vert/idx source to unref prev vb/ib
1373 void releasePreviousVertexSource();
1374 void releasePreviousIndexSource();
1375
1376 enum {
1377 kPreallocGeoSrcStateStackCnt = 4,
reed@google.comac10a2d2010-12-22 21:39:39 +00001378 };
bsalomon@google.com92669012011-09-27 19:10:05 +00001379 SkSTArray<kPreallocGeoSrcStateStackCnt,
1380 GeometrySrcState, true> fGeoSrcStateStack;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001381
reed@google.comac10a2d2010-12-22 21:39:39 +00001382};
1383
1384#endif