blob: a1667e410f12837c7732ceb8f2c8b21d8c976f7d [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;
bsalomon@google.comedfe1aa2011-09-29 14:40:26 +000052 bool fGeometryShaderSupport : 1;
bsalomon@google.com18c9c192011-09-22 21:01:31 +000053 bool fFSAASupport : 1;
54 bool fDualSourceBlendingSupport : 1;
55 bool fBufferLockSupport : 1;
56 int fMinRenderTargetWidth;
57 int fMinRenderTargetHeight;
58 int fMaxRenderTargetSize;
59 int fMaxTextureSize;
60 };
61
62 /**
bsalomon@google.com5782d712011-01-21 21:03:59 +000063 * Number of texture stages. Each stage takes as input a color and
64 * 2D texture coordinates. The color input to the first enabled stage is the
65 * per-vertex color or the constant color (setColor/setAlpha) if there are
66 * no per-vertex colors. For subsequent stages the input color is the output
bsalomon@google.com8531c1c2011-01-13 19:52:45 +000067 * color from the previous enabled stage. The output color of each stage is
bsalomon@google.com5782d712011-01-21 21:03:59 +000068 * the input color modulated with the result of a texture lookup. Texture
bsalomon@google.comc6cf7232011-02-17 16:43:10 +000069 * lookups are specified by a texture a sampler (setSamplerState). Texture
70 * coordinates for each stage come from the vertices based on a
71 * GrVertexLayout bitfield. The output fragment color is the output color of
72 * the last enabled stage. The presence or absence of texture coordinates
73 * for each stage in the vertex layout indicates whether a stage is enabled
74 * or not.
bsalomon@google.com8531c1c2011-01-13 19:52:45 +000075 */
bsalomon@google.com8531c1c2011-01-13 19:52:45 +000076 enum {
bsalomon@google.com26c2d0a2011-05-17 20:15:30 +000077 kNumStages = 3,
bsalomon@google.com8531c1c2011-01-13 19:52:45 +000078 kMaxTexCoords = kNumStages
79 };
bsalomon@google.com5782d712011-01-21 21:03:59 +000080
senorblanco@chromium.orgef3913b2011-05-19 17:11:07 +000081 /**
82 * The absolute maximum number of edges that may be specified for
83 * a single draw call when performing edge antialiasing. This is used for
84 * the size of several static buffers, so implementations of getMaxEdges()
85 * (below) should clamp to this value.
86 */
87 enum {
88 kMaxEdges = 32
89 };
90
bsalomon@google.comaeb21602011-08-30 18:13:44 +000091 /**
92 * When specifying edges as vertex data this enum specifies what type of
93 * edges are in use. The edges are always 4 GrScalars in memory, even when
94 * the edge type requires fewer than 4.
95 */
96 enum VertexEdgeType {
97 /* 1-pixel wide line
98 2D implicit line eq (a*x + b*y +c = 0). 4th component unused */
99 kHairLine_EdgeType,
100 /* 1-pixel wide quadratic
101 u^2-v canonical coords (only 2 components used) */
102 kHairQuad_EdgeType
103 };
104
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000105 /**
bsalomon@google.comffca4002011-02-22 20:34:01 +0000106 * Bitfield used to indicate which stages are in use.
reed@google.comac10a2d2010-12-22 21:39:39 +0000107 */
bsalomon@google.comffca4002011-02-22 20:34:01 +0000108 typedef int StageBitfield;
109 GR_STATIC_ASSERT(sizeof(StageBitfield)*8 >= kNumStages);
reed@google.comac10a2d2010-12-22 21:39:39 +0000110
111 /**
112 * Flags that affect rendering. Controlled using enable/disableState(). All
113 * default to disabled.
114 */
115 enum StateBits {
senorblanco@chromium.org92e0f222011-05-12 15:49:15 +0000116 kDither_StateBit = 0x01, //<! Perform color dithering
117 kAntialias_StateBit = 0x02, //<! Perform anti-aliasing. The render-
reed@google.comac10a2d2010-12-22 21:39:39 +0000118 // target must support some form of AA
119 // (msaa, coverage sampling, etc). For
120 // GrGpu-created rendertarget/textures
121 // this is controlled by parameters
122 // passed to createTexture.
senorblanco@chromium.org92e0f222011-05-12 15:49:15 +0000123 kClip_StateBit = 0x04, //<! Controls whether drawing is clipped
reed@google.comac10a2d2010-12-22 21:39:39 +0000124 // against the region specified by
125 // setClip.
senorblanco@chromium.org92e0f222011-05-12 15:49:15 +0000126 kNoColorWrites_StateBit = 0x08, //<! If set it disables writing colors.
127 // Useful while performing stencil
128 // ops.
senorblanco@chromium.org129b8e32011-06-15 17:52:09 +0000129 kEdgeAAConcave_StateBit = 0x10,//<! If set, edge AA will test edge
130 // pairs for convexity while
131 // rasterizing. Set this if the
132 // source polygon is non-convex.
bsalomon@google.comd302f142011-03-03 13:54:13 +0000133
134 // subclass may use additional bits internally
135 kDummyStateBit,
136 kLastPublicStateBit = kDummyStateBit-1
137 };
138
139 enum DrawFace {
140 kBoth_DrawFace,
141 kCCW_DrawFace,
142 kCW_DrawFace,
reed@google.comac10a2d2010-12-22 21:39:39 +0000143 };
144
145 /**
bsalomon@google.comd302f142011-03-03 13:54:13 +0000146 * Sets the stencil settings to use for the next draw.
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +0000147 * Changing the clip has the side-effect of possibly zeroing
148 * out the client settable stencil bits. So multipass algorithms
149 * using stencil should not change the clip between passes.
bsalomon@google.comd302f142011-03-03 13:54:13 +0000150 * @param settings the stencil settings to use.
151 */
152 void setStencil(const GrStencilSettings& settings) {
153 fCurrDrawState.fStencilSettings = settings;
154 }
155
156 /**
157 * Shortcut to disable stencil testing and ops.
158 */
159 void disableStencil() {
160 fCurrDrawState.fStencilSettings.setDisabled();
161 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000162
senorblanco@chromium.orgef3913b2011-05-19 17:11:07 +0000163 class Edge {
164 public:
165 Edge() {}
166 Edge(float x, float y, float z) : fX(x), fY(y), fZ(z) {}
167 GrPoint intersect(const Edge& other) {
168 return GrPoint::Make(
169 (fY * other.fZ - other.fY * fZ) /
170 (fX * other.fY - other.fX * fY),
171 (fX * other.fZ - other.fX * fZ) /
172 (other.fX * fY - fX * other.fY));
173 }
174 float fX, fY, fZ;
175 };
176
reed@google.comac10a2d2010-12-22 21:39:39 +0000177protected:
reed@google.comac10a2d2010-12-22 21:39:39 +0000178
reed@google.com8195f672011-01-12 18:14:28 +0000179 struct DrState {
bsalomon@google.comd302f142011-03-03 13:54:13 +0000180 DrState() {
181 // make sure any pad is zero for memcmp
182 // all DrState members should default to something
183 // valid by the memset
184 memset(this, 0, sizeof(DrState));
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000185
186 // memset exceptions
Scroggo97c88c22011-05-11 14:05:25 +0000187 fColorFilterXfermode = SkXfermode::kDstIn_Mode;
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000188 fFirstCoverageStage = kNumStages;
189
190 // pedantic assertion that our ptrs will
191 // be NULL (0 ptr is mem addr 0)
bsalomon@google.comd302f142011-03-03 13:54:13 +0000192 GrAssert((intptr_t)(void*)NULL == 0LL);
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000193
194 // default stencil setting should be disabled
bsalomon@google.comd302f142011-03-03 13:54:13 +0000195 GrAssert(fStencilSettings.isDisabled());
bsalomon@google.com26c2d0a2011-05-17 20:15:30 +0000196 fFirstCoverageStage = kNumStages;
bsalomon@google.comd302f142011-03-03 13:54:13 +0000197 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000198 uint32_t fFlagBits;
bsalomon@google.comffca4002011-02-22 20:34:01 +0000199 GrBlendCoeff fSrcBlend;
200 GrBlendCoeff fDstBlend;
bsalomon@google.com080773c2011-03-15 19:09:25 +0000201 GrColor fBlendConstant;
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000202 GrTexture* fTextures[kNumStages];
203 GrSamplerState fSamplerStates[kNumStages];
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000204 int fFirstCoverageStage;
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000205 GrRenderTarget* fRenderTarget;
206 GrColor fColor;
bsalomon@google.comd302f142011-03-03 13:54:13 +0000207 DrawFace fDrawFace;
Scroggo97c88c22011-05-11 14:05:25 +0000208 GrColor fColorFilterColor;
209 SkXfermode::Mode fColorFilterXfermode;
bsalomon@google.comd302f142011-03-03 13:54:13 +0000210
211 GrStencilSettings fStencilSettings;
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000212 GrMatrix fViewMatrix;
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000213 VertexEdgeType fVertexEdgeType;
senorblanco@chromium.orgef3913b2011-05-19 17:11:07 +0000214 Edge fEdgeAAEdges[kMaxEdges];
215 int fEdgeAANumEdges;
reed@google.com8195f672011-01-12 18:14:28 +0000216 bool operator ==(const DrState& s) const {
217 return 0 == memcmp(this, &s, sizeof(DrState));
reed@google.comac10a2d2010-12-22 21:39:39 +0000218 }
reed@google.com8195f672011-01-12 18:14:28 +0000219 bool operator !=(const DrState& s) const { return !(*this == s); }
reed@google.comac10a2d2010-12-22 21:39:39 +0000220 };
221
222public:
223 ///////////////////////////////////////////////////////////////////////////
224
225 GrDrawTarget();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000226 virtual ~GrDrawTarget();
reed@google.comac10a2d2010-12-22 21:39:39 +0000227
228 /**
bsalomon@google.com18c9c192011-09-22 21:01:31 +0000229 * Gets the capabilities of the draw target.
230 */
231 const Caps& getCaps() const { return fCaps; }
232
233 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000234 * Sets the current clip to the region specified by clip. All draws will be
235 * clipped against this clip if kClip_StateBit is enabled.
236 *
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +0000237 * Setting the clip may (or may not) zero out the client's stencil bits.
238 *
reed@google.comac10a2d2010-12-22 21:39:39 +0000239 * @param description of the clipping region
240 */
241 void setClip(const GrClip& clip);
242
243 /**
244 * Gets the current clip.
245 *
246 * @return the clip.
247 */
248 const GrClip& getClip() const;
249
250 /**
251 * Sets the texture used at the next drawing call
252 *
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000253 * @param stage The texture stage for which the texture will be set
254 *
reed@google.comac10a2d2010-12-22 21:39:39 +0000255 * @param texture The texture to set. Can be NULL though there is no advantage
256 * to settings a NULL texture if doing non-textured drawing
257 */
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000258 void setTexture(int stage, GrTexture* texture);
reed@google.comac10a2d2010-12-22 21:39:39 +0000259
260 /**
261 * Retrieves the currently set texture.
262 *
263 * @return The currently set texture. The return value will be NULL if no
264 * texture has been set, NULL was most recently passed to
265 * setTexture, or the last setTexture was destroyed.
266 */
bsalomon@google.com5782d712011-01-21 21:03:59 +0000267 const GrTexture* getTexture(int stage) const;
268 GrTexture* getTexture(int stage);
reed@google.comac10a2d2010-12-22 21:39:39 +0000269
270 /**
271 * Sets the rendertarget used at the next drawing call
272 *
bsalomon@google.com5782d712011-01-21 21:03:59 +0000273 * @param target The render target to set.
reed@google.comac10a2d2010-12-22 21:39:39 +0000274 */
275 void setRenderTarget(GrRenderTarget* target);
276
277 /**
278 * Retrieves the currently set rendertarget.
279 *
280 * @return The currently set render target.
281 */
bsalomon@google.com5782d712011-01-21 21:03:59 +0000282 const GrRenderTarget* getRenderTarget() const;
283 GrRenderTarget* getRenderTarget();
reed@google.comac10a2d2010-12-22 21:39:39 +0000284
285 /**
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000286 * Sets the sampler state for a stage used in subsequent draws.
reed@google.comac10a2d2010-12-22 21:39:39 +0000287 *
bsalomon@google.comd302f142011-03-03 13:54:13 +0000288 * The sampler state determines how texture coordinates are
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000289 * intepretted and used to sample the texture.
reed@google.comac10a2d2010-12-22 21:39:39 +0000290 *
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000291 * @param stage the stage of the sampler to set
reed@google.comac10a2d2010-12-22 21:39:39 +0000292 * @param samplerState Specifies the sampler state.
293 */
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000294 void setSamplerState(int stage, const GrSamplerState& samplerState);
reed@google.comac10a2d2010-12-22 21:39:39 +0000295
296 /**
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000297 * Concats the matrix of a stage's sampler.
reed@google.comac10a2d2010-12-22 21:39:39 +0000298 *
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000299 * @param stage the stage of the sampler to set
300 * @param matrix the matrix to concat
reed@google.comac10a2d2010-12-22 21:39:39 +0000301 */
bsalomon@google.com27847de2011-02-22 20:59:41 +0000302 void preConcatSamplerMatrix(int stage, const GrMatrix& matrix) {
303 GrAssert(stage >= 0 && stage < kNumStages);
304 fCurrDrawState.fSamplerStates[stage].preConcatMatrix(matrix);
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000305 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000306
307 /**
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000308 * Shortcut for preConcatSamplerMatrix on all stages in mask with same
bsalomon@google.com26c2d0a2011-05-17 20:15:30 +0000309 * matrix
310 */
311 void preConcatSamplerMatrices(int stageMask, const GrMatrix& matrix) {
312 for (int i = 0; i < kNumStages; ++i) {
313 if ((1 << i) & stageMask) {
314 this->preConcatSamplerMatrix(i, matrix);
315 }
316 }
317 }
318
319 /**
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000320 * Shortcut for preConcatSamplerMatrix on all enabled stages in mask with
321 * same matrix
322 *
323 * @param stage the stage of the sampler to set
324 * @param matrix the matrix to concat
325 */
326 void preConcatEnabledSamplerMatrices(const GrMatrix& matrix) {
327 StageBitfield stageMask = this->enabledStages();
328 this->preConcatSamplerMatrices(stageMask, matrix);
329 }
330
331 /**
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000332 * Gets the matrix of a stage's sampler
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000333 *
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000334 * @param stage the stage to of sampler to get
335 * @return the sampler state's matrix
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000336 */
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000337 const GrMatrix& getSamplerMatrix(int stage) const {
338 return fCurrDrawState.fSamplerStates[stage].getMatrix();
339 }
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000340
341 /**
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000342 * Sets the matrix of a stage's sampler
343 *
344 * @param stage the stage of sampler set
345 * @param matrix the matrix to set
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000346 */
djsollen@google.comcd9d69b2011-03-14 20:30:14 +0000347 void setSamplerMatrix(int stage, const GrMatrix& matrix) {
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000348 fCurrDrawState.fSamplerStates[stage].setMatrix(matrix);
349 }
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000350
351 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000352 * Sets the matrix applied to veretx positions.
353 *
354 * In the post-view-matrix space the rectangle [0,w]x[0,h]
355 * fully covers the render target. (w and h are the width and height of the
356 * the rendertarget.)
357 *
358 * @param m the matrix used to transform the vertex positions.
359 */
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000360 void setViewMatrix(const GrMatrix& m);
reed@google.comac10a2d2010-12-22 21:39:39 +0000361
362 /**
363 * Multiplies the current view matrix by a matrix
364 *
365 * After this call V' = V*m where V is the old view matrix,
366 * m is the parameter to this function, and V' is the new view matrix.
367 * (We consider positions to be column vectors so position vector p is
368 * transformed by matrix X as p' = X*p.)
369 *
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000370 * @param m the matrix used to modify the view matrix.
reed@google.comac10a2d2010-12-22 21:39:39 +0000371 */
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000372 void preConcatViewMatrix(const GrMatrix& m);
reed@google.comac10a2d2010-12-22 21:39:39 +0000373
374 /**
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000375 * Multiplies the current view matrix by a matrix
376 *
377 * After this call V' = m*V where V is the old view matrix,
378 * m is the parameter to this function, and V' is the new view matrix.
379 * (We consider positions to be column vectors so position vector p is
380 * transformed by matrix X as p' = X*p.)
381 *
382 * @param m the matrix used to modify the view matrix.
383 */
384 void postConcatViewMatrix(const GrMatrix& m);
385
386 /**
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000387 * Retrieves the current view matrix
388 * @return the current view matrix.
389 */
390 const GrMatrix& getViewMatrix() const;
391
392 /**
393 * Retrieves the inverse of the current view matrix.
394 *
395 * If the current view matrix is invertible, return true, and if matrix
396 * is non-null, copy the inverse into it. If the current view matrix is
397 * non-invertible, return false and ignore the matrix parameter.
398 *
399 * @param matrix if not null, will receive a copy of the current inverse.
400 */
401 bool getViewInverse(GrMatrix* matrix) const;
402
403 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000404 * Sets color for next draw to a premultiplied-alpha color.
405 *
406 * @param the color to set.
407 */
408 void setColor(GrColor);
409
410 /**
Scroggo97c88c22011-05-11 14:05:25 +0000411 * Add a color filter that can be represented by a color and a mode.
412 */
413 void setColorFilter(GrColor, SkXfermode::Mode);
414
415 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000416 * Sets the color to be used for the next draw to be
417 * (r,g,b,a) = (alpha, alpha, alpha, alpha).
418 *
419 * @param alpha The alpha value to set as the color.
420 */
421 void setAlpha(uint8_t alpha);
422
423 /**
bsalomon@google.comd302f142011-03-03 13:54:13 +0000424 * Controls whether clockwise, counterclockwise, or both faces are drawn.
425 * @param face the face(s) to draw.
reed@google.comac10a2d2010-12-22 21:39:39 +0000426 */
bsalomon@google.comd302f142011-03-03 13:54:13 +0000427 void setDrawFace(DrawFace face) { fCurrDrawState.fDrawFace = face; }
reed@google.comac10a2d2010-12-22 21:39:39 +0000428
429 /**
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000430 * A common pattern is to compute a color with the initial stages and then
431 * modulate that color by a coverage value in later stage(s) (AA, mask-
432 * filters, glyph mask, etc). Color-filters, xfermodes, etc should be
433 * computed based on the pre-coverage-modulated color. The division of
434 * stages between color-computing and coverage-computing is specified by
435 * this method. Initially this is kNumStages (all stages are color-
436 * computing).
437 */
438 void setFirstCoverageStage(int firstCoverageStage) {
439 fCurrDrawState.fFirstCoverageStage = firstCoverageStage;
440 }
441
442 /**
443 * Gets the index of the first coverage-computing stage.
444 */
445 int getFirstCoverageStage() const {
446 return fCurrDrawState.fFirstCoverageStage;
447 }
448
449 /**
bsalomon@google.comd302f142011-03-03 13:54:13 +0000450 * Gets whether the target is drawing clockwise, counterclockwise,
451 * or both faces.
452 * @return the current draw face(s).
reed@google.comac10a2d2010-12-22 21:39:39 +0000453 */
bsalomon@google.comd302f142011-03-03 13:54:13 +0000454 DrawFace getDrawFace() const { return fCurrDrawState.fDrawFace; }
reed@google.comac10a2d2010-12-22 21:39:39 +0000455
456 /**
457 * Enable render state settings.
458 *
459 * @param flags bitfield of StateBits specifing the states to enable
460 */
461 void enableState(uint32_t stateBits);
462
463 /**
464 * Disable render state settings.
465 *
466 * @param flags bitfield of StateBits specifing the states to disable
467 */
468 void disableState(uint32_t stateBits);
469
470 bool isDitherState() const {
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000471 return 0 != (fCurrDrawState.fFlagBits & kDither_StateBit);
472 }
473
senorblanco@chromium.org92e0f222011-05-12 15:49:15 +0000474 bool isAntialiasState() const {
475 return 0 != (fCurrDrawState.fFlagBits & kAntialias_StateBit);
476 }
477
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000478 bool isClipState() const {
479 return 0 != (fCurrDrawState.fFlagBits & kClip_StateBit);
reed@google.comac10a2d2010-12-22 21:39:39 +0000480 }
481
bsalomon@google.comd302f142011-03-03 13:54:13 +0000482 bool isColorWriteDisabled() const {
483 return 0 != (fCurrDrawState.fFlagBits & kNoColorWrites_StateBit);
484 }
485
reed@google.comac10a2d2010-12-22 21:39:39 +0000486 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000487 * Sets the blending function coeffecients.
488 *
489 * The blend function will be:
490 * D' = sat(S*srcCoef + D*dstCoef)
491 *
492 * where D is the existing destination color, S is the incoming source
493 * color, and D' is the new destination color that will be written. sat()
494 * is the saturation function.
495 *
496 * @param srcCoef coeffecient applied to the src color.
497 * @param dstCoef coeffecient applied to the dst color.
498 */
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000499 void setBlendFunc(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff);
reed@google.comac10a2d2010-12-22 21:39:39 +0000500
501 /**
bsalomon@google.com080773c2011-03-15 19:09:25 +0000502 * Sets the blending function constant referenced by the following blending
503 * coeffecients:
504 * kConstC_BlendCoeff
505 * kIConstC_BlendCoeff
506 * kConstA_BlendCoeff
507 * kIConstA_BlendCoeff
508 *
509 * @param constant the constant to set
510 */
511 void setBlendConstant(GrColor constant) { fCurrDrawState.fBlendConstant = constant; }
512
513 /**
514 * Retrieves the last value set by setBlendConstant()
515 * @return the blending constant value
516 */
517 GrColor getBlendConstant() const { return fCurrDrawState.fBlendConstant; }
518
519 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000520 * Used to save and restore the GrGpu's drawing state
521 */
522 struct SavedDrawState {
523 private:
reed@google.com8195f672011-01-12 18:14:28 +0000524 DrState fState;
reed@google.comac10a2d2010-12-22 21:39:39 +0000525 friend class GrDrawTarget;
526 };
527
528 /**
529 * Saves the current draw state. The state can be restored at a later time
530 * with restoreDrawState.
531 *
532 * See also AutoStateRestore class.
533 *
534 * @param state will hold the state after the function returns.
535 */
536 void saveCurrentDrawState(SavedDrawState* state) const;
537
538 /**
539 * Restores previously saved draw state. The client guarantees that state
540 * was previously passed to saveCurrentDrawState and that the rendertarget
541 * and texture set at save are still valid.
542 *
543 * See also AutoStateRestore class.
544 *
545 * @param state the previously saved state to restore.
546 */
547 void restoreDrawState(const SavedDrawState& state);
548
549 /**
550 * Copies the draw state from another target to this target.
551 *
552 * @param srcTarget draw target used as src of the draw state.
553 */
554 void copyDrawState(const GrDrawTarget& srcTarget);
555
556 /**
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000557 * The format of vertices is represented as a bitfield of flags.
558 * Flags that indicate the layout of vertex data. Vertices always contain
bsalomon@google.com5782d712011-01-21 21:03:59 +0000559 * positions and may also contain up to kMaxTexCoords sets of 2D texture
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000560 * coordinates and per-vertex colors. Each stage can use any of the texture
561 * coordinates as its input texture coordinates or it may use the positions.
reed@google.comac10a2d2010-12-22 21:39:39 +0000562 *
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000563 * If no texture coordinates are specified for a stage then the stage is
564 * disabled.
reed@google.comac10a2d2010-12-22 21:39:39 +0000565 *
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000566 * Only one type of texture coord can be specified per stage. For
bsalomon@google.com5782d712011-01-21 21:03:59 +0000567 * example StageTexCoordVertexLayoutBit(0, 2) and
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000568 * StagePosAsTexCoordVertexLayoutBit(0) cannot both be specified.
reed@google.comac10a2d2010-12-22 21:39:39 +0000569 *
bsalomon@google.com5782d712011-01-21 21:03:59 +0000570 * The order in memory is always (position, texture coord 0, ..., color)
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000571 * with any unused fields omitted. Note that this means that if only texture
bsalomon@google.com5782d712011-01-21 21:03:59 +0000572 * coordinates 1 is referenced then there is no texture coordinates 0 and
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000573 * the order would be (position, texture coordinate 1[, color]).
574 */
bsalomon@google.com5782d712011-01-21 21:03:59 +0000575
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000576 /**
577 * Generates a bit indicating that a texture stage uses texture coordinates
bsalomon@google.com5782d712011-01-21 21:03:59 +0000578 *
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000579 * @param stage the stage that will use texture coordinates.
580 * @param texCoordIdx the index of the texture coordinates to use
581 *
582 * @return the bit to add to a GrVertexLayout bitfield.
583 */
584 static int StageTexCoordVertexLayoutBit(int stage, int texCoordIdx) {
585 GrAssert(stage < kNumStages);
586 GrAssert(texCoordIdx < kMaxTexCoords);
587 return 1 << (stage + (texCoordIdx * kNumStages));
588 }
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000589
590 /**
591 * Determines if blend is effectively disabled.
592 *
593 * @return true if blend can be disabled without changing the rendering
594 * result given the current state including the vertex layout specified
595 * with the vertex source.
596 */
597 bool canDisableBlend() const;
598
bsalomon@google.comd46e2422011-09-23 17:40:07 +0000599 /**
600 * Color alpha and coverage are two inputs to the drawing pipeline. For some
601 * blend modes it is safe to fold the coverage into constant or per-vertex
602 * color alpha value. For other blend modes they must be handled separately.
603 * Depending on features available in the underlying 3D API this may or may
604 * not be possible.
605 *
606 * This function looks at the current blend on the draw target and the draw
607 * target's capabilities to determine whether coverage can be handled
608 * correctly.
609 */
610 bool canApplyCoverage() const;
611
612 /**
613 * Determines whether incorporating partial pixel coverage into the constant
614 * color specified by setColor or per-vertex colors will give the right
615 * blending result.
616 */
617 bool canTweakAlphaForCoverage() const {
618 return CanTweakAlphaForCoverage(fCurrDrawState.fDstBlend);
619 }
620
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000621 /**
622 * Determines the interpretation per-vertex edge data when the
623 * kEdge_VertexLayoutBit is set (see below). When per-vertex edges are not
624 * specified the value of this setting has no effect.
625 */
626 void setVertexEdgeType(VertexEdgeType type) {
627 fCurrDrawState.fVertexEdgeType = type;
628 }
629
senorblanco@chromium.org92e0f222011-05-12 15:49:15 +0000630 /**
bsalomon@google.com471d4712011-08-23 15:45:25 +0000631 * Given the current draw state, vertex layout, and hw support, will HW AA
632 * lines be used (if line primitive type is drawn)? (Note that lines are
633 * always 1 pixel wide)
634 */
635 virtual bool willUseHWAALines() const = 0;
636
637 /**
senorblanco@chromium.org92e0f222011-05-12 15:49:15 +0000638 * Sets the edge data required for edge antialiasing.
639 *
640 * @param edges 3 * 6 float values, representing the edge
641 * equations in Ax + By + C form
642 */
senorblanco@chromium.orgef3913b2011-05-19 17:11:07 +0000643 void setEdgeAAData(const Edge* edges, int numEdges);
senorblanco@chromium.org92e0f222011-05-12 15:49:15 +0000644
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000645private:
646 static const int TEX_COORD_BIT_CNT = kNumStages*kMaxTexCoords;
647public:
648 /**
649 * Generates a bit indicating that a texture stage uses the position
650 * as its texture coordinate.
651 *
bsalomon@google.com5782d712011-01-21 21:03:59 +0000652 * @param stage the stage that will use position as texture
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000653 * coordinates.
654 *
655 * @return the bit to add to a GrVertexLayout bitfield.
656 */
657 static int StagePosAsTexCoordVertexLayoutBit(int stage) {
658 GrAssert(stage < kNumStages);
bsalomon@google.com5782d712011-01-21 21:03:59 +0000659 return (1 << (TEX_COORD_BIT_CNT + stage));
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000660 }
661private:
662 static const int STAGE_BIT_CNT = TEX_COORD_BIT_CNT + kNumStages;
bsalomon@google.com5782d712011-01-21 21:03:59 +0000663
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000664public:
bsalomon@google.com5782d712011-01-21 21:03:59 +0000665
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000666 /**
667 * Additional Bits that can be specified in GrVertexLayout.
reed@google.comac10a2d2010-12-22 21:39:39 +0000668 */
669 enum VertexLayoutBits {
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000670 /* vertices have colors */
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000671 kColor_VertexLayoutBit = 1 << (STAGE_BIT_CNT + 0),
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000672
673 /* Use text vertices. (Pos and tex coords may be a different type for
674 text [GrGpuTextVertex vs GrPoint].) */
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000675 kTextFormat_VertexLayoutBit = 1 << (STAGE_BIT_CNT + 1),
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000676
677 kEdge_VertexLayoutBit = 1 << (STAGE_BIT_CNT + 2),
reed@google.comac10a2d2010-12-22 21:39:39 +0000678 // for below assert
bsalomon@google.comd302f142011-03-03 13:54:13 +0000679 kDummyVertexLayoutBit,
680 kHighVertexLayoutBit = kDummyVertexLayoutBit - 1
reed@google.comac10a2d2010-12-22 21:39:39 +0000681 };
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000682 // make sure we haven't exceeded the number of bits in GrVertexLayout.
bsalomon@google.com4be283f2011-04-19 21:15:09 +0000683 GR_STATIC_ASSERT(kHighVertexLayoutBit < ((uint64_t)1 << 8*sizeof(GrVertexLayout)));
reed@google.comac10a2d2010-12-22 21:39:39 +0000684
685 /**
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000686 * There are three methods for specifying geometry (vertices and optionally
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000687 * indices) to the draw target. When indexed drawing the indices and vertices
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000688 * can use a different method. Once geometry is specified it can be used for
689 * multiple drawIndexed and drawNonIndexed calls.
690 *
691 * Sometimes it is necessary to perform a draw while upstack code has
692 * already specified geometry that it isn't finished with. There are push
693 * pop methods
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000694 *
695 * 1. Provide a cpu array (set*SourceToArray). This is useful when the
696 * caller's client has already provided vertex data in a format
697 * the time compatible with a GrVertexLayout. The array must contain the
698 * data at set*SourceToArray is called. The source stays in effect for
699 * drawIndexed & drawNonIndexed calls until set*SourceToArray is called
700 * again or one of the other two paths is chosen.
701 *
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000702 * 2. Reserve. This is most useful when the caller has data it must
703 * transform before drawing and is not long-lived. The caller requests
704 * that the draw target make room for some amount of vertex and/or index
705 * data. The target provides ptrs to hold the vertex and/or index data.
706 *
707 * The data is writable up until the next drawIndexed, drawNonIndexed,
708 * or pushGeometrySource At this point the data is frozen and the ptrs
709 * are no longer valid.
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000710 *
711 * 3. Vertex and Index Buffers. This is most useful for geometry that will
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000712 * is long-lived. SetVertexSourceToBuffer and SetIndexSourceToBuffer are
713 * used to set the buffer and subsequent drawIndexed and drawNonIndexed
714 * calls use this source until another source is set.
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000715 */
716
717 /**
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000718 * Reserves space for vertices. Draw target will use reserved vertices at
719 * at the next draw.
reed@google.comac10a2d2010-12-22 21:39:39 +0000720 *
721 * If succeeds:
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000722 * if vertexCount > 0, *vertices will be the array
reed@google.comac10a2d2010-12-22 21:39:39 +0000723 * of vertices to be filled by caller. The next draw will read
724 * these vertices.
725 *
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000726 * If a client does not already have a vertex buffer then this is the
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000727 * preferred way to allocate vertex data. It allows the subclass of
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000728 * GrDrawTarget to decide whether to put data in buffers, to group vertex
729 * data that uses the same state (e.g. for deferred rendering), etc.
reed@google.comac10a2d2010-12-22 21:39:39 +0000730 *
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000731 * After the next draw or pushGeometrySource the vertices ptr is no longer
732 * valid and the geometry data cannot be further modified. The contents
733 * that were put in the reserved space can be drawn by multiple draws,
734 * however.
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000735 *
reed@google.comac10a2d2010-12-22 21:39:39 +0000736 * @param vertexLayout the format of vertices (ignored if vertexCount == 0).
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000737 * @param vertexCount the number of vertices to reserve space for. Can be 0.
reed@google.comac10a2d2010-12-22 21:39:39 +0000738 * @param vertices will point to reserved vertex space if vertexCount is
739 * non-zero. Illegal to pass NULL if vertexCount > 0.
reed@google.comac10a2d2010-12-22 21:39:39 +0000740 *
741 * @return true if succeeded in allocating space for the vertices and false
742 * if not.
743 */
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000744 bool reserveVertexSpace(GrVertexLayout vertexLayout,
745 int vertexCount,
746 void** vertices);
747 /**
748 * Reserves space for indices. Draw target will use the reserved indices at
749 * the next indexed draw.
750 *
751 * If succeeds:
752 * if indexCount > 0, *indices will be the array
753 * of indices to be filled by caller. The next draw will read
754 * these indices.
755 *
756 * If a client does not already have a index buffer then this is the
757 * preferred way to allocate index data. It allows the subclass of
758 * GrDrawTarget to decide whether to put data in buffers, to group index
759 * data that uses the same state (e.g. for deferred rendering), etc.
760 *
761 * After the next indexed draw or pushGeometrySource the indices ptr is no
762 * longer valid and the geometry data cannot be further modified. The
763 * contents that were put in the reserved space can be drawn by multiple
764 * draws, however.
765 *
766 * @param indexCount the number of indices to reserve space for. Can be 0.
767 * @param indices will point to reserved index space if indexCount is
768 * non-zero. Illegal to pass NULL if indexCount > 0.
769 */
770
771 bool reserveIndexSpace(int indexCount, void** indices);
reed@google.comac10a2d2010-12-22 21:39:39 +0000772 /**
773 * Provides hints to caller about the number of vertices and indices
774 * that can be allocated cheaply. This can be useful if caller is reserving
775 * space but doesn't know exactly how much geometry is needed.
776 *
777 * Also may hint whether the draw target should be flushed first. This is
778 * useful for deferred targets.
779 *
780 * @param vertexLayout layout of vertices caller would like to reserve
781 * @param vertexCount in: hint about how many vertices the caller would
782 * like to allocate.
783 * out: a hint about the number of vertices that can be
784 * allocated cheaply. Negative means no hint.
785 * Ignored if NULL.
786 * @param indexCount in: hint about how many indices the caller would
787 * like to allocate.
788 * out: a hint about the number of indices that can be
789 * allocated cheaply. Negative means no hint.
790 * Ignored if NULL.
791 *
792 * @return true if target should be flushed based on the input values.
793 */
794 virtual bool geometryHints(GrVertexLayout vertexLayout,
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000795 int* vertexCount,
796 int* indexCount) const;
reed@google.comac10a2d2010-12-22 21:39:39 +0000797
798 /**
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000799 * Sets source of vertex data for the next draw. Array must contain
800 * the vertex data when this is called.
reed@google.comac10a2d2010-12-22 21:39:39 +0000801 *
802 * @param array cpu array containing vertex data.
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000803 * @param size size of the vertex data.
804 * @param vertexCount the number of vertices in the array.
reed@google.comac10a2d2010-12-22 21:39:39 +0000805 */
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000806 void setVertexSourceToArray(GrVertexLayout vertexLayout,
807 const void* vertexArray,
808 int vertexCount);
reed@google.comac10a2d2010-12-22 21:39:39 +0000809
810 /**
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000811 * Sets source of index data for the next indexed draw. Array must contain
812 * the indices when this is called.
reed@google.comac10a2d2010-12-22 21:39:39 +0000813 *
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000814 * @param array cpu array containing index data.
815 * @param indexCount the number of indices in the array.
reed@google.comac10a2d2010-12-22 21:39:39 +0000816 */
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000817 void setIndexSourceToArray(const void* indexArray, int indexCount);
reed@google.comac10a2d2010-12-22 21:39:39 +0000818
819 /**
820 * Sets source of vertex data for the next draw. Data does not have to be
821 * in the buffer until drawIndexed or drawNonIndexed.
822 *
823 * @param buffer vertex buffer containing vertex data. Must be
824 * unlocked before draw call.
825 * @param vertexLayout layout of the vertex data in the buffer.
826 */
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000827 void setVertexSourceToBuffer(GrVertexLayout vertexLayout,
828 const GrVertexBuffer* buffer);
reed@google.comac10a2d2010-12-22 21:39:39 +0000829
830 /**
831 * Sets source of index data for the next indexed draw. Data does not have
832 * to be in the buffer until drawIndexed or drawNonIndexed.
833 *
834 * @param buffer index buffer containing indices. Must be unlocked
835 * before indexed draw call.
836 */
837 void setIndexSourceToBuffer(const GrIndexBuffer* buffer);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000838
839 /**
840 * Resets vertex source. Drawing from reset vertices is illegal. Set vertex
841 * source to reserved, array, or buffer before next draw. May be able to free
842 * up temporary storage allocated by setVertexSourceToArray or
843 * reserveVertexSpace.
844 */
845 void resetVertexSource();
846
847 /**
848 * Resets index source. Indexed Drawing from reset indices is illegal. Set
849 * index source to reserved, array, or buffer before next indexed draw. May
850 * be able to free up temporary storage allocated by setIndexSourceToArray
851 * or reserveIndexSpace.
852 */
853 void resetIndexSource();
reed@google.comac10a2d2010-12-22 21:39:39 +0000854
855 /**
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000856 * Pushes and resets the vertex/index sources. Any reserved vertex / index
857 * data is finalized (i.e. cannot be updated after the matching pop but can
858 * be drawn from). Must be balanced by a pop.
859 */
860 void pushGeometrySource();
861
862 /**
863 * Pops the vertex / index sources from the matching push.
864 */
865 void popGeometrySource();
866
867 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000868 * Draws indexed geometry using the current state and current vertex / index
869 * sources.
870 *
871 * @param type The type of primitives to draw.
872 * @param startVertex the vertex in the vertex array/buffer corresponding
873 * to index 0
874 * @param startIndex first index to read from index src.
875 * @param vertexCount one greater than the max index.
876 * @param indexCount the number of index elements to read. The index count
877 * is effectively trimmed to the last completely
878 * specified primitive.
879 */
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000880 void drawIndexed(GrPrimitiveType type,
881 int startVertex,
882 int startIndex,
883 int vertexCount,
884 int indexCount);
reed@google.comac10a2d2010-12-22 21:39:39 +0000885
886 /**
887 * Draws non-indexed geometry using the current state and current vertex
888 * sources.
889 *
890 * @param type The type of primitives to draw.
891 * @param startVertex the vertex in the vertex array/buffer corresponding
892 * to index 0
893 * @param vertexCount one greater than the max index.
894 */
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000895 void drawNonIndexed(GrPrimitiveType type,
896 int startVertex,
897 int vertexCount);
reed@google.comac10a2d2010-12-22 21:39:39 +0000898
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000899 /**
900 * Helper function for drawing rects. This does not use the current index
901 * and vertex sources. After returning, the vertex and index sources may
902 * have changed. They should be reestablished before the next drawIndexed
903 * or drawNonIndexed. This cannot be called between reserving and releasing
904 * geometry. The GrDrawTarget subclass may be able to perform additional
bsalomon@google.comd302f142011-03-03 13:54:13 +0000905 * optimizations if drawRect is used rather than drawIndexed or
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000906 * drawNonIndexed.
907 * @param rect the rect to draw
908 * @param matrix optional matrix applied to rect (before viewMatrix)
bsalomon@google.comffca4002011-02-22 20:34:01 +0000909 * @param stageEnableBitfield bitmask indicating which stages are enabled.
910 * Bit i indicates whether stage i is enabled.
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000911 * @param srcRects specifies rects for stages enabled by stageEnableMask.
912 * if stageEnableMask bit i is 1, srcRects is not NULL,
913 * and srcRects[i] is not NULL, then srcRects[i] will be
914 * used as coordinates for stage i. Otherwise, if stage i
915 * is enabled then rect is used as the coordinates.
916 * @param srcMatrices optional matrices applied to srcRects. If
917 * srcRect[i] is non-NULL and srcMatrices[i] is
918 * non-NULL then srcRect[i] will be transformed by
919 * srcMatrix[i]. srcMatrices can be NULL when no
920 * srcMatrices are desired.
921 */
bsalomon@google.comd302f142011-03-03 13:54:13 +0000922 virtual void drawRect(const GrRect& rect,
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000923 const GrMatrix* matrix,
bsalomon@google.comffca4002011-02-22 20:34:01 +0000924 StageBitfield stageEnableBitfield,
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000925 const GrRect* srcRects[],
926 const GrMatrix* srcMatrices[]);
927
928 /**
bsalomon@google.comd302f142011-03-03 13:54:13 +0000929 * Helper for drawRect when the caller doesn't need separate src rects or
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000930 * matrices.
931 */
bsalomon@google.comd302f142011-03-03 13:54:13 +0000932 void drawSimpleRect(const GrRect& rect,
933 const GrMatrix* matrix,
bsalomon@google.comffca4002011-02-22 20:34:01 +0000934 StageBitfield stageEnableBitfield) {
935 drawRect(rect, matrix, stageEnableBitfield, NULL, NULL);
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000936 }
937
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000938 /**
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000939 * Clear the render target. Ignores the clip and all other draw state
940 * (blend mode, stages, etc). Clears the whole thing if rect is NULL,
941 * otherwise just the rect.
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000942 */
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000943 virtual void clear(const GrIRect* rect, GrColor color) = 0;
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000944
senorblanco@chromium.orgef3913b2011-05-19 17:11:07 +0000945 /**
946 * Returns the maximum number of edges that may be specified in a single
947 * draw call when performing edge antialiasing. This is usually limited
948 * by the number of fragment uniforms which may be uploaded. Must be a
949 * minimum of six, since a triangle's vertices each belong to two boundary
950 * edges which may be distinct.
951 */
952 virtual int getMaxEdges() const { return 6; }
953
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000954 ////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +0000955
956 class AutoStateRestore : ::GrNoncopyable {
957 public:
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000958 AutoStateRestore();
reed@google.comac10a2d2010-12-22 21:39:39 +0000959 AutoStateRestore(GrDrawTarget* target);
960 ~AutoStateRestore();
961
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000962 /**
963 * if this object is already saving state for param target then
964 * this does nothing. Otherise, it restores previously saved state on
965 * previous target (if any) and saves current state on param target.
966 */
967 void set(GrDrawTarget* target);
968
reed@google.comac10a2d2010-12-22 21:39:39 +0000969 private:
970 GrDrawTarget* fDrawTarget;
971 SavedDrawState fDrawState;
972 };
973
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000974 ////////////////////////////////////////////////////////////////////////////
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000975
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000976 class AutoViewMatrixRestore : ::GrNoncopyable {
977 public:
978 AutoViewMatrixRestore() {
979 fDrawTarget = NULL;
980 }
981
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000982 AutoViewMatrixRestore(GrDrawTarget* target)
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000983 : fDrawTarget(target), fMatrix(fDrawTarget->getViewMatrix()) {
984 GrAssert(NULL != target);
985 }
986
987 void set(GrDrawTarget* target) {
988 GrAssert(NULL != target);
989 if (NULL != fDrawTarget) {
990 fDrawTarget->setViewMatrix(fMatrix);
991 }
992 fDrawTarget = target;
993 fMatrix = target->getViewMatrix();
994 }
995
996 ~AutoViewMatrixRestore() {
997 if (NULL != fDrawTarget) {
998 fDrawTarget->setViewMatrix(fMatrix);
999 }
1000 }
1001
1002 private:
1003 GrDrawTarget* fDrawTarget;
1004 GrMatrix fMatrix;
1005 };
1006
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001007 ////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +00001008
bsalomon@google.com7ac249b2011-06-14 18:46:24 +00001009 /**
1010 * Sets the view matrix to I and preconcats all stage matrices enabled in
1011 * mask by the view inverse. Destructor undoes these changes.
1012 */
1013 class AutoDeviceCoordDraw : ::GrNoncopyable {
1014 public:
1015 AutoDeviceCoordDraw(GrDrawTarget* target, int stageMask);
1016 ~AutoDeviceCoordDraw();
1017 private:
1018 GrDrawTarget* fDrawTarget;
1019 GrMatrix fViewMatrix;
1020 GrMatrix fSamplerMatrices[kNumStages];
1021 int fStageMask;
1022 };
1023
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001024 ////////////////////////////////////////////////////////////////////////////
bsalomon@google.com7ac249b2011-06-14 18:46:24 +00001025
reed@google.comac10a2d2010-12-22 21:39:39 +00001026 class AutoReleaseGeometry : ::GrNoncopyable {
1027 public:
1028 AutoReleaseGeometry(GrDrawTarget* target,
1029 GrVertexLayout vertexLayout,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001030 int vertexCount,
1031 int indexCount);
1032 AutoReleaseGeometry();
1033 ~AutoReleaseGeometry();
bsalomon@google.com5782d712011-01-21 21:03:59 +00001034 bool set(GrDrawTarget* target,
1035 GrVertexLayout vertexLayout,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001036 int vertexCount,
1037 int indexCount);
bsalomon@google.coma47a48d2011-04-26 20:22:11 +00001038 bool succeeded() const { return NULL != fTarget; }
bsalomon@google.com6513cd02011-08-05 20:12:30 +00001039 void* vertices() const { GrAssert(this->succeeded()); return fVertices; }
1040 void* indices() const { GrAssert(this->succeeded()); return fIndices; }
reed@google.comac10a2d2010-12-22 21:39:39 +00001041 GrPoint* positions() const {
bsalomon@google.com6513cd02011-08-05 20:12:30 +00001042 return static_cast<GrPoint*>(this->vertices());
reed@google.comac10a2d2010-12-22 21:39:39 +00001043 }
1044
1045 private:
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001046 void reset();
1047
reed@google.comac10a2d2010-12-22 21:39:39 +00001048 GrDrawTarget* fTarget;
reed@google.comac10a2d2010-12-22 21:39:39 +00001049 void* fVertices;
1050 void* fIndices;
1051 };
1052
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001053 ////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +00001054
1055 class AutoClipRestore : ::GrNoncopyable {
1056 public:
1057 AutoClipRestore(GrDrawTarget* target) {
1058 fTarget = target;
1059 fClip = fTarget->getClip();
1060 }
1061
1062 ~AutoClipRestore() {
1063 fTarget->setClip(fClip);
1064 }
1065 private:
1066 GrDrawTarget* fTarget;
1067 GrClip fClip;
1068 };
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001069
1070 ////////////////////////////////////////////////////////////////////////////
1071
1072 class AutoGeometryPush : ::GrNoncopyable {
1073 public:
1074 AutoGeometryPush(GrDrawTarget* target) {
1075 GrAssert(NULL != target);
1076 fTarget = target;
1077 target->pushGeometrySource();
1078 }
1079 ~AutoGeometryPush() {
1080 fTarget->popGeometrySource();
1081 }
1082 private:
1083 GrDrawTarget* fTarget;
1084 };
reed@google.comac10a2d2010-12-22 21:39:39 +00001085
1086 ////////////////////////////////////////////////////////////////////////////
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001087 // Helpers for picking apart vertex layouts
bsalomon@google.com5782d712011-01-21 21:03:59 +00001088
reed@google.comac10a2d2010-12-22 21:39:39 +00001089 /**
1090 * Helper function to compute the size of a vertex from a vertex layout
1091 * @return size of a single vertex.
1092 */
1093 static size_t VertexSize(GrVertexLayout vertexLayout);
bsalomon@google.com5782d712011-01-21 21:03:59 +00001094
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001095 /**
1096 * Helper function for determining the index of texture coordinates that
1097 * is input for a texture stage. Note that a stage may instead use positions
1098 * as texture coordinates, in which case the result of the function is
1099 * indistinguishable from the case when the stage is disabled.
1100 *
1101 * @param stage the stage to query
1102 * @param vertexLayout layout to query
1103 *
1104 * @return the texture coordinate index or -1 if the stage doesn't use
1105 * separate (non-position) texture coordinates.
1106 */
1107 static int VertexTexCoordsForStage(int stage, GrVertexLayout vertexLayout);
reed@google.comac10a2d2010-12-22 21:39:39 +00001108
1109 /**
1110 * Helper function to compute the offset of texture coordinates in a vertex
1111 * @return offset of texture coordinates in vertex layout or -1 if the
bsalomon@google.com5782d712011-01-21 21:03:59 +00001112 * layout has no texture coordinates. Will be 0 if positions are
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001113 * used as texture coordinates for the stage.
reed@google.comac10a2d2010-12-22 21:39:39 +00001114 */
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001115 static int VertexStageCoordOffset(int stage, GrVertexLayout vertexLayout);
reed@google.comac10a2d2010-12-22 21:39:39 +00001116
1117 /**
1118 * Helper function to compute the offset of the color in a vertex
1119 * @return offset of color in vertex layout or -1 if the
1120 * layout has no color.
1121 */
1122 static int VertexColorOffset(GrVertexLayout vertexLayout);
1123
bsalomon@google.comaeb21602011-08-30 18:13:44 +00001124 /**
1125 * Helper function to compute the offset of the edge pts in a vertex
1126 * @return offset of edge in vertex layout or -1 if the
1127 * layout has no edge.
1128 */
1129 static int VertexEdgeOffset(GrVertexLayout vertexLayout);
1130
reed@google.comac10a2d2010-12-22 21:39:39 +00001131 /**
bsalomon@google.com5782d712011-01-21 21:03:59 +00001132 * Helper function to determine if vertex layout contains explicit texture
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001133 * coordinates of some index.
1134 *
1135 * @param coordIndex the tex coord index to query
1136 * @param vertexLayout layout to query
1137 *
bsalomon@google.com5782d712011-01-21 21:03:59 +00001138 * @return true if vertex specifies texture coordinates for the index,
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001139 * false otherwise.
reed@google.comac10a2d2010-12-22 21:39:39 +00001140 */
bsalomon@google.com5782d712011-01-21 21:03:59 +00001141 static bool VertexUsesTexCoordIdx(int coordIndex,
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001142 GrVertexLayout vertexLayout);
bsalomon@google.com5782d712011-01-21 21:03:59 +00001143
reed@google.comac10a2d2010-12-22 21:39:39 +00001144 /**
1145 * Helper function to determine if vertex layout contains either explicit or
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001146 * implicit texture coordinates for a stage.
reed@google.comac10a2d2010-12-22 21:39:39 +00001147 *
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001148 * @param stage the stage to query
1149 * @param vertexLayout layout to query
1150 *
bsalomon@google.com5782d712011-01-21 21:03:59 +00001151 * @return true if vertex specifies texture coordinates for the stage,
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001152 * false otherwise.
reed@google.comac10a2d2010-12-22 21:39:39 +00001153 */
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001154 static bool VertexUsesStage(int stage, GrVertexLayout vertexLayout);
reed@google.comac10a2d2010-12-22 21:39:39 +00001155
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001156 /**
bsalomon@google.com5782d712011-01-21 21:03:59 +00001157 * Helper function to compute the size of each vertex and the offsets of
1158 * texture coordinates and color. Determines tex coord offsets by tex coord
1159 * index rather than by stage. (Each stage can be mapped to any t.c. index
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001160 * by StageTexCoordVertexLayoutBit.)
1161 *
1162 * @param vertexLayout the layout to query
1163 * @param texCoordOffsetsByIdx after return it is the offset of each
1164 * tex coord index in the vertex or -1 if
1165 * index isn't used.
1166 * @return size of a single vertex
1167 */
1168 static int VertexSizeAndOffsetsByIdx(GrVertexLayout vertexLayout,
1169 int texCoordOffsetsByIdx[kMaxTexCoords],
bsalomon@google.comaeb21602011-08-30 18:13:44 +00001170 int *colorOffset,
1171 int* edgeOffset);
bsalomon@google.com5782d712011-01-21 21:03:59 +00001172
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001173 /**
bsalomon@google.com5782d712011-01-21 21:03:59 +00001174 * Helper function to compute the size of each vertex and the offsets of
1175 * texture coordinates and color. Determines tex coord offsets by stage
1176 * rather than by index. (Each stage can be mapped to any t.c. index
1177 * by StageTexCoordVertexLayoutBit.) If a stage uses positions for
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001178 * tex coords then that stage's offset will be 0 (positions are always at 0).
1179 *
1180 * @param vertexLayout the layout to query
1181 * @param texCoordOffsetsByStage after return it is the offset of each
1182 * tex coord index in the vertex or -1 if
1183 * index isn't used.
1184 * @return size of a single vertex
1185 */
1186 static int VertexSizeAndOffsetsByStage(GrVertexLayout vertexLayout,
1187 int texCoordOffsetsByStage[kNumStages],
bsalomon@google.comaeb21602011-08-30 18:13:44 +00001188 int *colorOffset,
1189 int* edgeOffset);
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001190
1191 /**
1192 * Accessing positions, texture coords, or colors, of a vertex within an
1193 * array is a hassle involving casts and simple math. These helpers exist
1194 * to keep GrDrawTarget clients' code a bit nicer looking.
1195 */
1196
1197 /**
1198 * Gets a pointer to a GrPoint of a vertex's position or texture
1199 * coordinate.
1200 * @param vertices the vetex array
1201 * @param vertexIndex the index of the vertex in the array
1202 * @param vertexSize the size of each vertex in the array
1203 * @param offset the offset in bytes of the vertex component.
1204 * Defaults to zero (corresponding to vertex position)
1205 * @return pointer to the vertex component as a GrPoint
1206 */
bsalomon@google.comd302f142011-03-03 13:54:13 +00001207 static GrPoint* GetVertexPoint(void* vertices,
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001208 int vertexIndex,
1209 int vertexSize,
1210 int offset = 0) {
1211 intptr_t start = GrTCast<intptr_t>(vertices);
bsalomon@google.comd302f142011-03-03 13:54:13 +00001212 return GrTCast<GrPoint*>(start + offset +
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001213 vertexIndex * vertexSize);
1214 }
1215 static const GrPoint* GetVertexPoint(const void* vertices,
1216 int vertexIndex,
bsalomon@google.comd302f142011-03-03 13:54:13 +00001217 int vertexSize,
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001218 int offset = 0) {
1219 intptr_t start = GrTCast<intptr_t>(vertices);
bsalomon@google.comd302f142011-03-03 13:54:13 +00001220 return GrTCast<const GrPoint*>(start + offset +
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001221 vertexIndex * vertexSize);
1222 }
1223
1224 /**
1225 * Gets a pointer to a GrColor inside a vertex within a vertex array.
1226 * @param vertices the vetex array
1227 * @param vertexIndex the index of the vertex in the array
1228 * @param vertexSize the size of each vertex in the array
1229 * @param offset the offset in bytes of the vertex color
1230 * @return pointer to the vertex component as a GrColor
1231 */
bsalomon@google.comd302f142011-03-03 13:54:13 +00001232 static GrColor* GetVertexColor(void* vertices,
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001233 int vertexIndex,
1234 int vertexSize,
1235 int offset) {
1236 intptr_t start = GrTCast<intptr_t>(vertices);
bsalomon@google.comd302f142011-03-03 13:54:13 +00001237 return GrTCast<GrColor*>(start + offset +
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001238 vertexIndex * vertexSize);
1239 }
1240 static const GrColor* GetVertexColor(const void* vertices,
1241 int vertexIndex,
bsalomon@google.comd302f142011-03-03 13:54:13 +00001242 int vertexSize,
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001243 int offset) {
1244 const intptr_t start = GrTCast<intptr_t>(vertices);
bsalomon@google.comd302f142011-03-03 13:54:13 +00001245 return GrTCast<const GrColor*>(start + offset +
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001246 vertexIndex * vertexSize);
1247 }
1248
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +00001249 static void VertexLayoutUnitTest();
1250
reed@google.comac10a2d2010-12-22 21:39:39 +00001251protected:
bsalomon@google.com471d4712011-08-23 15:45:25 +00001252
bsalomon@google.comd46e2422011-09-23 17:40:07 +00001253 // Determines whether it is correct to apply partial pixel coverage
1254 // by multiplying the src color by the fractional coverage.
1255 static bool CanTweakAlphaForCoverage(GrBlendCoeff dstCoeff);
1256
bsalomon@google.com471d4712011-08-23 15:45:25 +00001257 // determines whether HW blending can be disabled or not
1258 static bool CanDisableBlend(GrVertexLayout layout, const DrState& state);
1259
1260 // determines whether HW AA lines can be used or not
1261 static bool CanUseHWAALines(GrVertexLayout layout, const DrState& state);
1262
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001263 enum GeometrySrcType {
1264 kNone_GeometrySrcType, //<! src has not been specified
1265 kReserved_GeometrySrcType, //<! src was set using reserve*Space
1266 kArray_GeometrySrcType, //<! src was set using set*SourceToArray
1267 kBuffer_GeometrySrcType //<! src was set using set*SourceToBuffer
1268 };
1269
1270 struct GeometrySrcState {
1271 GeometrySrcType fVertexSrc;
1272 union {
1273 // valid if src type is buffer
1274 const GrVertexBuffer* fVertexBuffer;
1275 // valid if src type is reserved or array
1276 int fVertexCount;
1277 };
1278
1279 GeometrySrcType fIndexSrc;
1280 union {
1281 // valid if src type is buffer
1282 const GrIndexBuffer* fIndexBuffer;
1283 // valid if src type is reserved or array
1284 int fIndexCount;
1285 };
1286
1287 GrVertexLayout fVertexLayout;
1288 };
1289
bsalomon@google.coma47a48d2011-04-26 20:22:11 +00001290 // given a vertex layout and a draw state, will a stage be used?
1291 static bool StageWillBeUsed(int stage, GrVertexLayout layout,
bsalomon@google.comaeb21602011-08-30 18:13:44 +00001292 const DrState& state) {
bsalomon@google.coma47a48d2011-04-26 20:22:11 +00001293 return NULL != state.fTextures[stage] && VertexUsesStage(stage, layout);
1294 }
1295
1296 bool isStageEnabled(int stage) const {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001297 return StageWillBeUsed(stage, this->getGeomSrc().fVertexLayout,
1298 fCurrDrawState);
bsalomon@google.coma47a48d2011-04-26 20:22:11 +00001299 }
bsalomon@google.com5782d712011-01-21 21:03:59 +00001300
bsalomon@google.comaeb21602011-08-30 18:13:44 +00001301 StageBitfield enabledStages() const {
1302 StageBitfield mask = 0;
1303 for (int s = 0; s < kNumStages; ++s) {
1304 mask |= this->isStageEnabled(s) ? 1 : 0;
1305 }
1306 return mask;
1307 }
1308
reed@google.comac10a2d2010-12-22 21:39:39 +00001309 // Helpers for GrDrawTarget subclasses that won't have private access to
1310 // SavedDrawState but need to peek at the state values.
reed@google.com8195f672011-01-12 18:14:28 +00001311 static DrState& accessSavedDrawState(SavedDrawState& sds)
reed@google.comac10a2d2010-12-22 21:39:39 +00001312 { return sds.fState; }
reed@google.com8195f672011-01-12 18:14:28 +00001313 static const DrState& accessSavedDrawState(const SavedDrawState& sds)
reed@google.comac10a2d2010-12-22 21:39:39 +00001314 { return sds.fState; }
1315
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001316 // implemented by subclass to allocate space for reserved geom
1317 virtual bool onReserveVertexSpace(GrVertexLayout vertexLayout,
1318 int vertexCount,
1319 void** vertices) = 0;
1320 virtual bool onReserveIndexSpace(int indexCount, void** indices) = 0;
1321 // implemented by subclass to handle release of reserved geom space
1322 virtual void releaseReservedVertexSpace() = 0;
1323 virtual void releaseReservedIndexSpace() = 0;
1324 // subclass must consume array contents when set
1325 virtual void onSetVertexSourceToArray(const void* vertexArray,
1326 int vertexCount) = 0;
1327 virtual void onSetIndexSourceToArray(const void* indexArray,
1328 int indexCount) = 0;
1329 // subclass is notified that geom source will be set away from an array
1330 virtual void releaseVertexArray() = 0;
1331 virtual void releaseIndexArray() = 0;
1332 // subclass overrides to be notified just before geo src state
1333 // is pushed/popped.
1334 virtual void geometrySourceWillPush() = 0;
1335 virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) = 0;
1336 // subclass called to perform drawing
1337 virtual void onDrawIndexed(GrPrimitiveType type,
1338 int startVertex,
1339 int startIndex,
1340 int vertexCount,
1341 int indexCount) = 0;
1342 virtual void onDrawNonIndexed(GrPrimitiveType type,
1343 int startVertex,
1344 int vertexCount) = 0;
bsalomon@google.comdea2f8d2011-08-01 15:51:05 +00001345 // subclass overrides to be notified when clip is set. Must call
1346 // INHERITED::clipwillBeSet
1347 virtual void clipWillBeSet(const GrClip& clip);
bsalomon@google.com1c13c962011-02-14 16:51:21 +00001348
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001349 // Helpers for drawRect, protected so subclasses that override drawRect
1350 // can use them.
bsalomon@google.comffca4002011-02-22 20:34:01 +00001351 static GrVertexLayout GetRectVertexLayout(StageBitfield stageEnableBitfield,
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001352 const GrRect* srcRects[]);
1353
1354 static void SetRectVertices(const GrRect& rect,
bsalomon@google.comd302f142011-03-03 13:54:13 +00001355 const GrMatrix* matrix,
1356 const GrRect* srcRects[],
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001357 const GrMatrix* srcMatrices[],
bsalomon@google.comd302f142011-03-03 13:54:13 +00001358 GrVertexLayout layout,
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001359 void* vertices);
1360
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001361 // accessor for derived classes
1362 const GeometrySrcState& getGeomSrc() const {
1363 return fGeoSrcStateStack.back();
1364 }
reed@google.comac10a2d2010-12-22 21:39:39 +00001365
1366 GrClip fClip;
1367
reed@google.com8195f672011-01-12 18:14:28 +00001368 DrState fCurrDrawState;
reed@google.comac10a2d2010-12-22 21:39:39 +00001369
bsalomon@google.com18c9c192011-09-22 21:01:31 +00001370 Caps fCaps;
1371
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001372private:
1373 // called when setting a new vert/idx source to unref prev vb/ib
1374 void releasePreviousVertexSource();
1375 void releasePreviousIndexSource();
1376
1377 enum {
1378 kPreallocGeoSrcStateStackCnt = 4,
reed@google.comac10a2d2010-12-22 21:39:39 +00001379 };
bsalomon@google.com92669012011-09-27 19:10:05 +00001380 SkSTArray<kPreallocGeoSrcStateStackCnt,
1381 GeometrySrcState, true> fGeoSrcStateStack;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001382
reed@google.comac10a2d2010-12-22 21:39:39 +00001383};
1384
1385#endif