blob: 7d311aa2ec3b451a47d52e991496e0523805c0bf [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"
tomhudson@google.com93813632011-10-27 20:21:16 +000016#include "GrDrawState.h"
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000017#include "GrMatrix.h"
18#include "GrRefCnt.h"
19#include "GrRenderTarget.h"
20#include "GrSamplerState.h"
bsalomon@google.comd302f142011-03-03 13:54:13 +000021#include "GrStencil.h"
bsalomon@google.comaa5b6732011-07-29 15:13:20 +000022#include "GrTexture.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000023
Scroggo97c88c22011-05-11 14:05:25 +000024#include "SkXfermode.h"
25
reed@google.comac10a2d2010-12-22 21:39:39 +000026class GrTexture;
reed@google.comac10a2d2010-12-22 21:39:39 +000027class GrClipIterator;
28class GrVertexBuffer;
29class GrIndexBuffer;
30
31class GrDrawTarget : public GrRefCnt {
32public:
33 /**
bsalomon@google.com18c9c192011-09-22 21:01:31 +000034 * Represents the draw target capabilities.
35 */
36 struct Caps {
37 Caps() { memset(this, 0, sizeof(Caps)); }
38 Caps(const Caps& c) { *this = c; }
39 Caps& operator= (const Caps& c) {
40 memcpy(this, &c, sizeof(Caps));
41 return *this;
42 }
43 void print() const;
44 bool f8BitPaletteSupport : 1;
45 bool fNPOTTextureSupport : 1;
46 bool fNPOTTextureTileSupport : 1;
47 bool fNPOTRenderTargetSupport : 1;
48 bool fTwoSidedStencilSupport : 1;
49 bool fStencilWrapOpsSupport : 1;
50 bool fHWAALineSupport : 1;
51 bool fShaderSupport : 1;
52 bool fShaderDerivativeSupport : 1;
bsalomon@google.comedfe1aa2011-09-29 14:40:26 +000053 bool fGeometryShaderSupport : 1;
bsalomon@google.com18c9c192011-09-22 21:01:31 +000054 bool fFSAASupport : 1;
55 bool fDualSourceBlendingSupport : 1;
56 bool fBufferLockSupport : 1;
bsalomon@google.coma3108262011-10-10 14:08:47 +000057 bool fSupportPerVertexCoverage : 1;
bsalomon@google.com18c9c192011-09-22 21:01:31 +000058 int fMinRenderTargetWidth;
59 int fMinRenderTargetHeight;
60 int fMaxRenderTargetSize;
61 int fMaxTextureSize;
62 };
63
64 /**
bsalomon@google.comffca4002011-02-22 20:34:01 +000065 * Bitfield used to indicate which stages are in use.
reed@google.comac10a2d2010-12-22 21:39:39 +000066 */
bsalomon@google.comffca4002011-02-22 20:34:01 +000067 typedef int StageBitfield;
tomhudson@google.com93813632011-10-27 20:21:16 +000068 GR_STATIC_ASSERT(sizeof(StageBitfield)*8 >= GrDrawState::kNumStages);
reed@google.comac10a2d2010-12-22 21:39:39 +000069
70 /**
71 * Flags that affect rendering. Controlled using enable/disableState(). All
72 * default to disabled.
73 */
74 enum StateBits {
bsalomon@google.com289533a2011-10-27 12:34:25 +000075 /**
76 * Perform dithering. TODO: Re-evaluate whether we need this bit
77 */
78 kDither_StateBit = 0x01,
79 /**
80 * Perform HW anti-aliasing. This means either HW FSAA, if supported
81 * by the render target, or smooth-line rendering if a line primitive
82 * is drawn and line smoothing is supported by the 3D API.
83 */
84 kHWAntialias_StateBit = 0x02,
85 /**
86 * Draws will respect the clip, otherwise the clip is ignored.
87 */
88 kClip_StateBit = 0x04,
89 /**
90 * Disables writing to the color buffer. Useful when performing stencil
91 * operations.
92 */
93 kNoColorWrites_StateBit = 0x08,
94 /**
95 * Modifies the behavior of edge AA specified by setEdgeAA. If set,
96 * will test edge pairs for convexity when rasterizing. Set this if the
97 * source polygon is non-convex.
98 */
99 kEdgeAAConcave_StateBit = 0x10,
bsalomon@google.comd302f142011-03-03 13:54:13 +0000100 // subclass may use additional bits internally
101 kDummyStateBit,
102 kLastPublicStateBit = kDummyStateBit-1
103 };
104
reed@google.comac10a2d2010-12-22 21:39:39 +0000105 /**
bsalomon@google.comd302f142011-03-03 13:54:13 +0000106 * Sets the stencil settings to use for the next draw.
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +0000107 * Changing the clip has the side-effect of possibly zeroing
108 * out the client settable stencil bits. So multipass algorithms
109 * using stencil should not change the clip between passes.
bsalomon@google.comd302f142011-03-03 13:54:13 +0000110 * @param settings the stencil settings to use.
111 */
112 void setStencil(const GrStencilSettings& settings) {
113 fCurrDrawState.fStencilSettings = settings;
114 }
115
116 /**
117 * Shortcut to disable stencil testing and ops.
118 */
119 void disableStencil() {
120 fCurrDrawState.fStencilSettings.setDisabled();
121 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000122
reed@google.comac10a2d2010-12-22 21:39:39 +0000123public:
124 ///////////////////////////////////////////////////////////////////////////
125
126 GrDrawTarget();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000127 virtual ~GrDrawTarget();
reed@google.comac10a2d2010-12-22 21:39:39 +0000128
129 /**
bsalomon@google.com18c9c192011-09-22 21:01:31 +0000130 * Gets the capabilities of the draw target.
131 */
132 const Caps& getCaps() const { return fCaps; }
133
134 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000135 * Sets the current clip to the region specified by clip. All draws will be
136 * clipped against this clip if kClip_StateBit is enabled.
137 *
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +0000138 * Setting the clip may (or may not) zero out the client's stencil bits.
139 *
reed@google.comac10a2d2010-12-22 21:39:39 +0000140 * @param description of the clipping region
141 */
142 void setClip(const GrClip& clip);
143
144 /**
145 * Gets the current clip.
146 *
147 * @return the clip.
148 */
149 const GrClip& getClip() const;
150
151 /**
152 * Sets the texture used at the next drawing call
153 *
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000154 * @param stage The texture stage for which the texture will be set
155 *
reed@google.comac10a2d2010-12-22 21:39:39 +0000156 * @param texture The texture to set. Can be NULL though there is no advantage
157 * to settings a NULL texture if doing non-textured drawing
158 */
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000159 void setTexture(int stage, GrTexture* texture);
reed@google.comac10a2d2010-12-22 21:39:39 +0000160
161 /**
162 * Retrieves the currently set texture.
163 *
164 * @return The currently set texture. The return value will be NULL if no
165 * texture has been set, NULL was most recently passed to
166 * setTexture, or the last setTexture was destroyed.
167 */
bsalomon@google.com5782d712011-01-21 21:03:59 +0000168 const GrTexture* getTexture(int stage) const;
169 GrTexture* getTexture(int stage);
reed@google.comac10a2d2010-12-22 21:39:39 +0000170
171 /**
172 * Sets the rendertarget used at the next drawing call
173 *
bsalomon@google.com5782d712011-01-21 21:03:59 +0000174 * @param target The render target to set.
reed@google.comac10a2d2010-12-22 21:39:39 +0000175 */
176 void setRenderTarget(GrRenderTarget* target);
177
178 /**
179 * Retrieves the currently set rendertarget.
180 *
181 * @return The currently set render target.
182 */
bsalomon@google.com5782d712011-01-21 21:03:59 +0000183 const GrRenderTarget* getRenderTarget() const;
184 GrRenderTarget* getRenderTarget();
reed@google.comac10a2d2010-12-22 21:39:39 +0000185
186 /**
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000187 * Sets the sampler state for a stage used in subsequent draws.
reed@google.comac10a2d2010-12-22 21:39:39 +0000188 *
bsalomon@google.comd302f142011-03-03 13:54:13 +0000189 * The sampler state determines how texture coordinates are
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000190 * intepretted and used to sample the texture.
reed@google.comac10a2d2010-12-22 21:39:39 +0000191 *
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000192 * @param stage the stage of the sampler to set
reed@google.comac10a2d2010-12-22 21:39:39 +0000193 * @param samplerState Specifies the sampler state.
194 */
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000195 void setSamplerState(int stage, const GrSamplerState& samplerState);
reed@google.comac10a2d2010-12-22 21:39:39 +0000196
197 /**
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000198 * Concats the matrix of a stage's sampler.
reed@google.comac10a2d2010-12-22 21:39:39 +0000199 *
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000200 * @param stage the stage of the sampler to set
201 * @param matrix the matrix to concat
reed@google.comac10a2d2010-12-22 21:39:39 +0000202 */
bsalomon@google.com27847de2011-02-22 20:59:41 +0000203 void preConcatSamplerMatrix(int stage, const GrMatrix& matrix) {
tomhudson@google.com93813632011-10-27 20:21:16 +0000204 GrAssert(stage >= 0 && stage < GrDrawState::kNumStages);
bsalomon@google.com27847de2011-02-22 20:59:41 +0000205 fCurrDrawState.fSamplerStates[stage].preConcatMatrix(matrix);
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000206 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000207
208 /**
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000209 * Shortcut for preConcatSamplerMatrix on all stages in mask with same
bsalomon@google.com26c2d0a2011-05-17 20:15:30 +0000210 * matrix
211 */
212 void preConcatSamplerMatrices(int stageMask, const GrMatrix& matrix) {
tomhudson@google.com93813632011-10-27 20:21:16 +0000213 for (int i = 0; i < GrDrawState::kNumStages; ++i) {
bsalomon@google.com26c2d0a2011-05-17 20:15:30 +0000214 if ((1 << i) & stageMask) {
215 this->preConcatSamplerMatrix(i, matrix);
216 }
217 }
218 }
219
220 /**
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000221 * Shortcut for preConcatSamplerMatrix on all enabled stages in mask with
222 * same matrix
223 *
224 * @param stage the stage of the sampler to set
225 * @param matrix the matrix to concat
226 */
227 void preConcatEnabledSamplerMatrices(const GrMatrix& matrix) {
228 StageBitfield stageMask = this->enabledStages();
229 this->preConcatSamplerMatrices(stageMask, matrix);
230 }
231
232 /**
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000233 * Gets the matrix of a stage's sampler
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000234 *
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000235 * @param stage the stage to of sampler to get
236 * @return the sampler state's matrix
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000237 */
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000238 const GrMatrix& getSamplerMatrix(int stage) const {
239 return fCurrDrawState.fSamplerStates[stage].getMatrix();
240 }
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000241
242 /**
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000243 * Sets the matrix of a stage's sampler
244 *
245 * @param stage the stage of sampler set
246 * @param matrix the matrix to set
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000247 */
djsollen@google.comcd9d69b2011-03-14 20:30:14 +0000248 void setSamplerMatrix(int stage, const GrMatrix& matrix) {
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000249 fCurrDrawState.fSamplerStates[stage].setMatrix(matrix);
250 }
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000251
252 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000253 * Sets the matrix applied to veretx positions.
254 *
255 * In the post-view-matrix space the rectangle [0,w]x[0,h]
256 * fully covers the render target. (w and h are the width and height of the
257 * the rendertarget.)
258 *
259 * @param m the matrix used to transform the vertex positions.
260 */
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000261 void setViewMatrix(const GrMatrix& m);
reed@google.comac10a2d2010-12-22 21:39:39 +0000262
263 /**
264 * Multiplies the current view matrix by a matrix
265 *
266 * After this call V' = V*m where V is the old view matrix,
267 * m is the parameter to this function, and V' is the new view matrix.
268 * (We consider positions to be column vectors so position vector p is
269 * transformed by matrix X as p' = X*p.)
270 *
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000271 * @param m the matrix used to modify the view matrix.
reed@google.comac10a2d2010-12-22 21:39:39 +0000272 */
bsalomon@google.comc6cf7232011-02-17 16:43:10 +0000273 void preConcatViewMatrix(const GrMatrix& m);
reed@google.comac10a2d2010-12-22 21:39:39 +0000274
275 /**
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000276 * Multiplies the current view matrix by a matrix
277 *
278 * After this call V' = m*V where V is the old view matrix,
279 * m is the parameter to this function, and V' is the new view matrix.
280 * (We consider positions to be column vectors so position vector p is
281 * transformed by matrix X as p' = X*p.)
282 *
283 * @param m the matrix used to modify the view matrix.
284 */
285 void postConcatViewMatrix(const GrMatrix& m);
286
287 /**
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000288 * Retrieves the current view matrix
289 * @return the current view matrix.
290 */
291 const GrMatrix& getViewMatrix() const;
292
293 /**
294 * Retrieves the inverse of the current view matrix.
295 *
296 * If the current view matrix is invertible, return true, and if matrix
297 * is non-null, copy the inverse into it. If the current view matrix is
298 * non-invertible, return false and ignore the matrix parameter.
299 *
300 * @param matrix if not null, will receive a copy of the current inverse.
301 */
302 bool getViewInverse(GrMatrix* matrix) const;
303
304 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000305 * Sets color for next draw to a premultiplied-alpha color.
306 *
307 * @param the color to set.
308 */
309 void setColor(GrColor);
310
311 /**
bsalomon@google.coma3108262011-10-10 14:08:47 +0000312 * Gets the currently set color.
313 * @return the current color.
314 */
315 GrColor getColor() const { return fCurrDrawState.fColor; }
316
317 /**
Scroggo97c88c22011-05-11 14:05:25 +0000318 * Add a color filter that can be represented by a color and a mode.
319 */
320 void setColorFilter(GrColor, SkXfermode::Mode);
321
322 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000323 * Sets the color to be used for the next draw to be
324 * (r,g,b,a) = (alpha, alpha, alpha, alpha).
325 *
326 * @param alpha The alpha value to set as the color.
327 */
328 void setAlpha(uint8_t alpha);
329
330 /**
bsalomon@google.comd302f142011-03-03 13:54:13 +0000331 * Controls whether clockwise, counterclockwise, or both faces are drawn.
332 * @param face the face(s) to draw.
reed@google.comac10a2d2010-12-22 21:39:39 +0000333 */
tomhudson@google.com93813632011-10-27 20:21:16 +0000334 void setDrawFace(GrDrawState::DrawFace face) {
335 fCurrDrawState.fDrawFace = face;
336 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000337
338 /**
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000339 * A common pattern is to compute a color with the initial stages and then
340 * modulate that color by a coverage value in later stage(s) (AA, mask-
341 * filters, glyph mask, etc). Color-filters, xfermodes, etc should be
342 * computed based on the pre-coverage-modulated color. The division of
343 * stages between color-computing and coverage-computing is specified by
tomhudson@google.com93813632011-10-27 20:21:16 +0000344 * this method. Initially this is GrDrawState::kNumStages (all stages
345 * are color-computing).
bsalomon@google.comf2d91552011-05-16 20:56:06 +0000346 */
347 void setFirstCoverageStage(int firstCoverageStage) {
348 fCurrDrawState.fFirstCoverageStage = firstCoverageStage;
349 }
350
351 /**
352 * Gets the index of the first coverage-computing stage.
353 */
354 int getFirstCoverageStage() const {
355 return fCurrDrawState.fFirstCoverageStage;
356 }
357
358 /**
bsalomon@google.comd302f142011-03-03 13:54:13 +0000359 * Gets whether the target is drawing clockwise, counterclockwise,
360 * or both faces.
361 * @return the current draw face(s).
reed@google.comac10a2d2010-12-22 21:39:39 +0000362 */
tomhudson@google.com93813632011-10-27 20:21:16 +0000363 GrDrawState::DrawFace getDrawFace() const {
364 return fCurrDrawState.fDrawFace;
365 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000366
367 /**
368 * Enable render state settings.
369 *
370 * @param flags bitfield of StateBits specifing the states to enable
371 */
372 void enableState(uint32_t stateBits);
373
374 /**
375 * Disable render state settings.
376 *
377 * @param flags bitfield of StateBits specifing the states to disable
378 */
379 void disableState(uint32_t stateBits);
380
381 bool isDitherState() const {
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000382 return 0 != (fCurrDrawState.fFlagBits & kDither_StateBit);
383 }
384
bsalomon@google.com289533a2011-10-27 12:34:25 +0000385 bool isHWAntialiasState() const {
386 return 0 != (fCurrDrawState.fFlagBits & kHWAntialias_StateBit);
senorblanco@chromium.org92e0f222011-05-12 15:49:15 +0000387 }
388
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000389 bool isClipState() const {
390 return 0 != (fCurrDrawState.fFlagBits & kClip_StateBit);
reed@google.comac10a2d2010-12-22 21:39:39 +0000391 }
392
bsalomon@google.comd302f142011-03-03 13:54:13 +0000393 bool isColorWriteDisabled() const {
394 return 0 != (fCurrDrawState.fFlagBits & kNoColorWrites_StateBit);
395 }
396
reed@google.comac10a2d2010-12-22 21:39:39 +0000397 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000398 * Sets the blending function coeffecients.
399 *
400 * The blend function will be:
401 * D' = sat(S*srcCoef + D*dstCoef)
402 *
403 * where D is the existing destination color, S is the incoming source
404 * color, and D' is the new destination color that will be written. sat()
405 * is the saturation function.
406 *
407 * @param srcCoef coeffecient applied to the src color.
408 * @param dstCoef coeffecient applied to the dst color.
409 */
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000410 void setBlendFunc(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff);
reed@google.comac10a2d2010-12-22 21:39:39 +0000411
412 /**
bsalomon@google.com080773c2011-03-15 19:09:25 +0000413 * Sets the blending function constant referenced by the following blending
414 * coeffecients:
415 * kConstC_BlendCoeff
416 * kIConstC_BlendCoeff
417 * kConstA_BlendCoeff
418 * kIConstA_BlendCoeff
419 *
420 * @param constant the constant to set
421 */
422 void setBlendConstant(GrColor constant) { fCurrDrawState.fBlendConstant = constant; }
423
424 /**
425 * Retrieves the last value set by setBlendConstant()
426 * @return the blending constant value
427 */
428 GrColor getBlendConstant() const { return fCurrDrawState.fBlendConstant; }
429
430 /**
bsalomon@google.com86c1f712011-10-12 14:54:26 +0000431 * Determines if blending will require a read of a dst given the current
432 * state set on the draw target
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000433 *
bsalomon@google.com86c1f712011-10-12 14:54:26 +0000434 * @return true if the dst surface will be read at each pixel hit by the
435 * a draw operation.
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000436 */
bsalomon@google.com86c1f712011-10-12 14:54:26 +0000437 bool drawWillReadDst() const;
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000438
bsalomon@google.comd46e2422011-09-23 17:40:07 +0000439 /**
440 * Color alpha and coverage are two inputs to the drawing pipeline. For some
441 * blend modes it is safe to fold the coverage into constant or per-vertex
442 * color alpha value. For other blend modes they must be handled separately.
443 * Depending on features available in the underlying 3D API this may or may
444 * not be possible.
445 *
446 * This function looks at the current blend on the draw target and the draw
447 * target's capabilities to determine whether coverage can be handled
448 * correctly.
449 */
450 bool canApplyCoverage() const;
451
452 /**
453 * Determines whether incorporating partial pixel coverage into the constant
454 * color specified by setColor or per-vertex colors will give the right
455 * blending result.
456 */
bsalomon@google.com86c1f712011-10-12 14:54:26 +0000457 bool canTweakAlphaForCoverage() const;
bsalomon@google.comd46e2422011-09-23 17:40:07 +0000458
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000459 /**
460 * Determines the interpretation per-vertex edge data when the
461 * kEdge_VertexLayoutBit is set (see below). When per-vertex edges are not
462 * specified the value of this setting has no effect.
463 */
tomhudson@google.com93813632011-10-27 20:21:16 +0000464 void setVertexEdgeType(GrDrawState::VertexEdgeType type) {
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000465 fCurrDrawState.fVertexEdgeType = type;
466 }
467
senorblanco@chromium.org92e0f222011-05-12 15:49:15 +0000468 /**
bsalomon@google.com471d4712011-08-23 15:45:25 +0000469 * Given the current draw state, vertex layout, and hw support, will HW AA
470 * lines be used (if line primitive type is drawn)? (Note that lines are
471 * always 1 pixel wide)
472 */
tomhudson@google.com93813632011-10-27 20:21:16 +0000473 bool willUseHWAALines() const;
bsalomon@google.com471d4712011-08-23 15:45:25 +0000474
475 /**
senorblanco@chromium.org92e0f222011-05-12 15:49:15 +0000476 * Sets the edge data required for edge antialiasing.
477 *
478 * @param edges 3 * 6 float values, representing the edge
479 * equations in Ax + By + C form
480 */
tomhudson@google.com93813632011-10-27 20:21:16 +0000481 void setEdgeAAData(const GrDrawState::Edge* edges, int numEdges);
senorblanco@chromium.org92e0f222011-05-12 15:49:15 +0000482
bsalomon@google.coma3108262011-10-10 14:08:47 +0000483 /**
484 * Used to save and restore the GrGpu's drawing state
485 */
486 struct SavedDrawState {
487 private:
tomhudson@google.com93813632011-10-27 20:21:16 +0000488 GrDrawState fState;
bsalomon@google.coma3108262011-10-10 14:08:47 +0000489 friend class GrDrawTarget;
490 };
491
492 /**
493 * Saves the current draw state. The state can be restored at a later time
494 * with restoreDrawState.
495 *
496 * See also AutoStateRestore class.
497 *
498 * @param state will hold the state after the function returns.
499 */
500 void saveCurrentDrawState(SavedDrawState* state) const;
501
502 /**
503 * Restores previously saved draw state. The client guarantees that state
504 * was previously passed to saveCurrentDrawState and that the rendertarget
505 * and texture set at save are still valid.
506 *
507 * See also AutoStateRestore class.
508 *
509 * @param state the previously saved state to restore.
510 */
511 void restoreDrawState(const SavedDrawState& state);
512
513 /**
514 * Copies the draw state from another target to this target.
515 *
516 * @param srcTarget draw target used as src of the draw state.
517 */
518 void copyDrawState(const GrDrawTarget& srcTarget);
519
520 /**
521 * The format of vertices is represented as a bitfield of flags.
522 * Flags that indicate the layout of vertex data. Vertices always contain
tomhudson@google.com93813632011-10-27 20:21:16 +0000523 * positions and may also contain up to GrDrawState::kMaxTexCoords sets
524 * of 2D texture * coordinates, per-vertex colors, and per-vertex coverage.
525 * Each stage can
bsalomon@google.coma3108262011-10-10 14:08:47 +0000526 * use any of the texture coordinates as its input texture coordinates or it
527 * may use the positions as texture coordinates.
528 *
529 * If no texture coordinates are specified for a stage then the stage is
530 * disabled.
531 *
532 * Only one type of texture coord can be specified per stage. For
533 * example StageTexCoordVertexLayoutBit(0, 2) and
534 * StagePosAsTexCoordVertexLayoutBit(0) cannot both be specified.
535 *
536 * The order in memory is always (position, texture coord 0, ..., color,
537 * coverage) with any unused fields omitted. Note that this means that if
538 * only texture coordinates 1 is referenced then there is no texture
539 * coordinates 0 and the order would be (position, texture coordinate 1
540 * [, color][, coverage]).
541 */
542
543 /**
544 * Generates a bit indicating that a texture stage uses texture coordinates
545 *
546 * @param stage the stage that will use texture coordinates.
547 * @param texCoordIdx the index of the texture coordinates to use
548 *
549 * @return the bit to add to a GrVertexLayout bitfield.
550 */
551 static int StageTexCoordVertexLayoutBit(int stage, int texCoordIdx) {
tomhudson@google.com93813632011-10-27 20:21:16 +0000552 GrAssert(stage < GrDrawState::kNumStages);
553 GrAssert(texCoordIdx < GrDrawState::kMaxTexCoords);
554 return 1 << (stage + (texCoordIdx * GrDrawState::kNumStages));
bsalomon@google.coma3108262011-10-10 14:08:47 +0000555 }
556
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000557private:
tomhudson@google.com93813632011-10-27 20:21:16 +0000558 static const int TEX_COORD_BIT_CNT = GrDrawState::kNumStages *
559 GrDrawState::kMaxTexCoords;
bsalomon@google.com86c1f712011-10-12 14:54:26 +0000560
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000561public:
562 /**
563 * Generates a bit indicating that a texture stage uses the position
564 * as its texture coordinate.
565 *
bsalomon@google.com5782d712011-01-21 21:03:59 +0000566 * @param stage the stage that will use position as texture
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000567 * coordinates.
568 *
569 * @return the bit to add to a GrVertexLayout bitfield.
570 */
571 static int StagePosAsTexCoordVertexLayoutBit(int stage) {
tomhudson@google.com93813632011-10-27 20:21:16 +0000572 GrAssert(stage < GrDrawState::kNumStages);
bsalomon@google.com5782d712011-01-21 21:03:59 +0000573 return (1 << (TEX_COORD_BIT_CNT + stage));
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000574 }
bsalomon@google.coma3108262011-10-10 14:08:47 +0000575
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000576private:
tomhudson@google.com93813632011-10-27 20:21:16 +0000577 static const int STAGE_BIT_CNT = TEX_COORD_BIT_CNT +
578 GrDrawState::kNumStages;
bsalomon@google.com5782d712011-01-21 21:03:59 +0000579
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000580public:
bsalomon@google.com5782d712011-01-21 21:03:59 +0000581
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000582 /**
583 * Additional Bits that can be specified in GrVertexLayout.
reed@google.comac10a2d2010-12-22 21:39:39 +0000584 */
585 enum VertexLayoutBits {
bsalomon@google.coma3108262011-10-10 14:08:47 +0000586 /* vertices have colors (GrColor) */
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000587 kColor_VertexLayoutBit = 1 << (STAGE_BIT_CNT + 0),
bsalomon@google.come10f6fd2011-10-11 20:15:26 +0000588 /* vertices have coverage (GrColor where all channels should have the
589 * same value)
590 */
bsalomon@google.coma3108262011-10-10 14:08:47 +0000591 kCoverage_VertexLayoutBit = 1 << (STAGE_BIT_CNT + 1),
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000592 /* Use text vertices. (Pos and tex coords may be a different type for
bsalomon@google.come10f6fd2011-10-11 20:15:26 +0000593 * text [GrGpuTextVertex vs GrPoint].)
594 */
bsalomon@google.coma3108262011-10-10 14:08:47 +0000595 kTextFormat_VertexLayoutBit = 1 << (STAGE_BIT_CNT + 2),
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000596
bsalomon@google.come10f6fd2011-10-11 20:15:26 +0000597 /* Each vertex specificies an edge. Distance to the edge is used to
598 * compute a coverage. See setVertexEdgeType().
599 */
bsalomon@google.coma3108262011-10-10 14:08:47 +0000600 kEdge_VertexLayoutBit = 1 << (STAGE_BIT_CNT + 3),
reed@google.comac10a2d2010-12-22 21:39:39 +0000601 // for below assert
bsalomon@google.comd302f142011-03-03 13:54:13 +0000602 kDummyVertexLayoutBit,
603 kHighVertexLayoutBit = kDummyVertexLayoutBit - 1
reed@google.comac10a2d2010-12-22 21:39:39 +0000604 };
bsalomon@google.com8531c1c2011-01-13 19:52:45 +0000605 // make sure we haven't exceeded the number of bits in GrVertexLayout.
bsalomon@google.com4be283f2011-04-19 21:15:09 +0000606 GR_STATIC_ASSERT(kHighVertexLayoutBit < ((uint64_t)1 << 8*sizeof(GrVertexLayout)));
reed@google.comac10a2d2010-12-22 21:39:39 +0000607
608 /**
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000609 * There are three methods for specifying geometry (vertices and optionally
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000610 * indices) to the draw target. When indexed drawing the indices and vertices
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000611 * can use a different method. Once geometry is specified it can be used for
612 * multiple drawIndexed and drawNonIndexed calls.
613 *
614 * Sometimes it is necessary to perform a draw while upstack code has
615 * already specified geometry that it isn't finished with. There are push
616 * pop methods
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000617 *
618 * 1. Provide a cpu array (set*SourceToArray). This is useful when the
619 * caller's client has already provided vertex data in a format
620 * the time compatible with a GrVertexLayout. The array must contain the
621 * data at set*SourceToArray is called. The source stays in effect for
622 * drawIndexed & drawNonIndexed calls until set*SourceToArray is called
623 * again or one of the other two paths is chosen.
624 *
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000625 * 2. Reserve. This is most useful when the caller has data it must
626 * transform before drawing and is not long-lived. The caller requests
627 * that the draw target make room for some amount of vertex and/or index
628 * data. The target provides ptrs to hold the vertex and/or index data.
629 *
630 * The data is writable up until the next drawIndexed, drawNonIndexed,
631 * or pushGeometrySource At this point the data is frozen and the ptrs
632 * are no longer valid.
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000633 *
634 * 3. Vertex and Index Buffers. This is most useful for geometry that will
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000635 * is long-lived. SetVertexSourceToBuffer and SetIndexSourceToBuffer are
636 * used to set the buffer and subsequent drawIndexed and drawNonIndexed
637 * calls use this source until another source is set.
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000638 */
639
640 /**
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000641 * Reserves space for vertices. Draw target will use reserved vertices at
642 * at the next draw.
reed@google.comac10a2d2010-12-22 21:39:39 +0000643 *
644 * If succeeds:
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000645 * if vertexCount > 0, *vertices will be the array
reed@google.comac10a2d2010-12-22 21:39:39 +0000646 * of vertices to be filled by caller. The next draw will read
647 * these vertices.
648 *
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000649 * If a client does not already have a vertex buffer then this is the
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000650 * preferred way to allocate vertex data. It allows the subclass of
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000651 * GrDrawTarget to decide whether to put data in buffers, to group vertex
652 * data that uses the same state (e.g. for deferred rendering), etc.
reed@google.comac10a2d2010-12-22 21:39:39 +0000653 *
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000654 * After the next draw or pushGeometrySource the vertices ptr is no longer
655 * valid and the geometry data cannot be further modified. The contents
656 * that were put in the reserved space can be drawn by multiple draws,
657 * however.
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000658 *
reed@google.comac10a2d2010-12-22 21:39:39 +0000659 * @param vertexLayout the format of vertices (ignored if vertexCount == 0).
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000660 * @param vertexCount the number of vertices to reserve space for. Can be 0.
reed@google.comac10a2d2010-12-22 21:39:39 +0000661 * @param vertices will point to reserved vertex space if vertexCount is
662 * non-zero. Illegal to pass NULL if vertexCount > 0.
reed@google.comac10a2d2010-12-22 21:39:39 +0000663 *
664 * @return true if succeeded in allocating space for the vertices and false
665 * if not.
666 */
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000667 bool reserveVertexSpace(GrVertexLayout vertexLayout,
668 int vertexCount,
669 void** vertices);
670 /**
671 * Reserves space for indices. Draw target will use the reserved indices at
672 * the next indexed draw.
673 *
674 * If succeeds:
675 * if indexCount > 0, *indices will be the array
676 * of indices to be filled by caller. The next draw will read
677 * these indices.
678 *
679 * If a client does not already have a index buffer then this is the
680 * preferred way to allocate index data. It allows the subclass of
681 * GrDrawTarget to decide whether to put data in buffers, to group index
682 * data that uses the same state (e.g. for deferred rendering), etc.
683 *
684 * After the next indexed draw or pushGeometrySource the indices ptr is no
685 * longer valid and the geometry data cannot be further modified. The
686 * contents that were put in the reserved space can be drawn by multiple
687 * draws, however.
688 *
689 * @param indexCount the number of indices to reserve space for. Can be 0.
690 * @param indices will point to reserved index space if indexCount is
691 * non-zero. Illegal to pass NULL if indexCount > 0.
692 */
693
694 bool reserveIndexSpace(int indexCount, void** indices);
reed@google.comac10a2d2010-12-22 21:39:39 +0000695 /**
696 * Provides hints to caller about the number of vertices and indices
697 * that can be allocated cheaply. This can be useful if caller is reserving
698 * space but doesn't know exactly how much geometry is needed.
699 *
700 * Also may hint whether the draw target should be flushed first. This is
701 * useful for deferred targets.
702 *
703 * @param vertexLayout layout of vertices caller would like to reserve
704 * @param vertexCount in: hint about how many vertices the caller would
705 * like to allocate.
706 * out: a hint about the number of vertices that can be
707 * allocated cheaply. Negative means no hint.
708 * Ignored if NULL.
709 * @param indexCount in: hint about how many indices the caller would
710 * like to allocate.
711 * out: a hint about the number of indices that can be
712 * allocated cheaply. Negative means no hint.
713 * Ignored if NULL.
714 *
715 * @return true if target should be flushed based on the input values.
716 */
717 virtual bool geometryHints(GrVertexLayout vertexLayout,
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000718 int* vertexCount,
719 int* indexCount) const;
reed@google.comac10a2d2010-12-22 21:39:39 +0000720
721 /**
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000722 * Sets source of vertex data for the next draw. Array must contain
723 * the vertex data when this is called.
reed@google.comac10a2d2010-12-22 21:39:39 +0000724 *
725 * @param array cpu array containing vertex data.
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000726 * @param size size of the vertex data.
727 * @param vertexCount the number of vertices in the array.
reed@google.comac10a2d2010-12-22 21:39:39 +0000728 */
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000729 void setVertexSourceToArray(GrVertexLayout vertexLayout,
730 const void* vertexArray,
731 int vertexCount);
reed@google.comac10a2d2010-12-22 21:39:39 +0000732
733 /**
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000734 * Sets source of index data for the next indexed draw. Array must contain
735 * the indices when this is called.
reed@google.comac10a2d2010-12-22 21:39:39 +0000736 *
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000737 * @param array cpu array containing index data.
738 * @param indexCount the number of indices in the array.
reed@google.comac10a2d2010-12-22 21:39:39 +0000739 */
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000740 void setIndexSourceToArray(const void* indexArray, int indexCount);
reed@google.comac10a2d2010-12-22 21:39:39 +0000741
742 /**
743 * Sets source of vertex data for the next draw. Data does not have to be
744 * in the buffer until drawIndexed or drawNonIndexed.
745 *
746 * @param buffer vertex buffer containing vertex data. Must be
747 * unlocked before draw call.
748 * @param vertexLayout layout of the vertex data in the buffer.
749 */
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000750 void setVertexSourceToBuffer(GrVertexLayout vertexLayout,
751 const GrVertexBuffer* buffer);
reed@google.comac10a2d2010-12-22 21:39:39 +0000752
753 /**
754 * Sets source of index data for the next indexed draw. Data does not have
755 * to be in the buffer until drawIndexed or drawNonIndexed.
756 *
757 * @param buffer index buffer containing indices. Must be unlocked
758 * before indexed draw call.
759 */
760 void setIndexSourceToBuffer(const GrIndexBuffer* buffer);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000761
762 /**
763 * Resets vertex source. Drawing from reset vertices is illegal. Set vertex
764 * source to reserved, array, or buffer before next draw. May be able to free
765 * up temporary storage allocated by setVertexSourceToArray or
766 * reserveVertexSpace.
767 */
768 void resetVertexSource();
769
770 /**
771 * Resets index source. Indexed Drawing from reset indices is illegal. Set
772 * index source to reserved, array, or buffer before next indexed draw. May
773 * be able to free up temporary storage allocated by setIndexSourceToArray
774 * or reserveIndexSpace.
775 */
776 void resetIndexSource();
reed@google.comac10a2d2010-12-22 21:39:39 +0000777
778 /**
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000779 * Pushes and resets the vertex/index sources. Any reserved vertex / index
780 * data is finalized (i.e. cannot be updated after the matching pop but can
781 * be drawn from). Must be balanced by a pop.
782 */
783 void pushGeometrySource();
784
785 /**
786 * Pops the vertex / index sources from the matching push.
787 */
788 void popGeometrySource();
789
790 /**
reed@google.comac10a2d2010-12-22 21:39:39 +0000791 * Draws indexed geometry using the current state and current vertex / index
792 * sources.
793 *
794 * @param type The type of primitives to draw.
795 * @param startVertex the vertex in the vertex array/buffer corresponding
796 * to index 0
797 * @param startIndex first index to read from index src.
798 * @param vertexCount one greater than the max index.
799 * @param indexCount the number of index elements to read. The index count
800 * is effectively trimmed to the last completely
801 * specified primitive.
802 */
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000803 void drawIndexed(GrPrimitiveType type,
804 int startVertex,
805 int startIndex,
806 int vertexCount,
807 int indexCount);
reed@google.comac10a2d2010-12-22 21:39:39 +0000808
809 /**
810 * Draws non-indexed geometry using the current state and current vertex
811 * sources.
812 *
813 * @param type The type of primitives to draw.
814 * @param startVertex the vertex in the vertex array/buffer corresponding
815 * to index 0
816 * @param vertexCount one greater than the max index.
817 */
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000818 void drawNonIndexed(GrPrimitiveType type,
819 int startVertex,
820 int vertexCount);
reed@google.comac10a2d2010-12-22 21:39:39 +0000821
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000822 /**
823 * Helper function for drawing rects. This does not use the current index
824 * and vertex sources. After returning, the vertex and index sources may
825 * have changed. They should be reestablished before the next drawIndexed
826 * or drawNonIndexed. This cannot be called between reserving and releasing
827 * geometry. The GrDrawTarget subclass may be able to perform additional
bsalomon@google.comd302f142011-03-03 13:54:13 +0000828 * optimizations if drawRect is used rather than drawIndexed or
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000829 * drawNonIndexed.
830 * @param rect the rect to draw
831 * @param matrix optional matrix applied to rect (before viewMatrix)
bsalomon@google.comffca4002011-02-22 20:34:01 +0000832 * @param stageEnableBitfield bitmask indicating which stages are enabled.
833 * Bit i indicates whether stage i is enabled.
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000834 * @param srcRects specifies rects for stages enabled by stageEnableMask.
835 * if stageEnableMask bit i is 1, srcRects is not NULL,
836 * and srcRects[i] is not NULL, then srcRects[i] will be
837 * used as coordinates for stage i. Otherwise, if stage i
838 * is enabled then rect is used as the coordinates.
839 * @param srcMatrices optional matrices applied to srcRects. If
840 * srcRect[i] is non-NULL and srcMatrices[i] is
841 * non-NULL then srcRect[i] will be transformed by
842 * srcMatrix[i]. srcMatrices can be NULL when no
843 * srcMatrices are desired.
844 */
bsalomon@google.comd302f142011-03-03 13:54:13 +0000845 virtual void drawRect(const GrRect& rect,
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000846 const GrMatrix* matrix,
bsalomon@google.comffca4002011-02-22 20:34:01 +0000847 StageBitfield stageEnableBitfield,
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000848 const GrRect* srcRects[],
849 const GrMatrix* srcMatrices[]);
850
851 /**
bsalomon@google.comd302f142011-03-03 13:54:13 +0000852 * Helper for drawRect when the caller doesn't need separate src rects or
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000853 * matrices.
854 */
bsalomon@google.comd302f142011-03-03 13:54:13 +0000855 void drawSimpleRect(const GrRect& rect,
856 const GrMatrix* matrix,
bsalomon@google.comffca4002011-02-22 20:34:01 +0000857 StageBitfield stageEnableBitfield) {
858 drawRect(rect, matrix, stageEnableBitfield, NULL, NULL);
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000859 }
860
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000861 /**
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000862 * Clear the render target. Ignores the clip and all other draw state
863 * (blend mode, stages, etc). Clears the whole thing if rect is NULL,
864 * otherwise just the rect.
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000865 */
bsalomon@google.com6aa25c32011-04-27 19:55:29 +0000866 virtual void clear(const GrIRect* rect, GrColor color) = 0;
bsalomon@google.com0b335c12011-04-25 19:17:44 +0000867
senorblanco@chromium.orgef3913b2011-05-19 17:11:07 +0000868 /**
869 * Returns the maximum number of edges that may be specified in a single
870 * draw call when performing edge antialiasing. This is usually limited
871 * by the number of fragment uniforms which may be uploaded. Must be a
872 * minimum of six, since a triangle's vertices each belong to two boundary
873 * edges which may be distinct.
874 */
875 virtual int getMaxEdges() const { return 6; }
876
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000877 ////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +0000878
879 class AutoStateRestore : ::GrNoncopyable {
880 public:
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000881 AutoStateRestore();
reed@google.comac10a2d2010-12-22 21:39:39 +0000882 AutoStateRestore(GrDrawTarget* target);
883 ~AutoStateRestore();
884
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000885 /**
886 * if this object is already saving state for param target then
887 * this does nothing. Otherise, it restores previously saved state on
888 * previous target (if any) and saves current state on param target.
889 */
890 void set(GrDrawTarget* target);
891
reed@google.comac10a2d2010-12-22 21:39:39 +0000892 private:
893 GrDrawTarget* fDrawTarget;
894 SavedDrawState fDrawState;
895 };
896
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000897 ////////////////////////////////////////////////////////////////////////////
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000898
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000899 class AutoViewMatrixRestore : ::GrNoncopyable {
900 public:
901 AutoViewMatrixRestore() {
902 fDrawTarget = NULL;
903 }
904
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000905 AutoViewMatrixRestore(GrDrawTarget* target)
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000906 : fDrawTarget(target), fMatrix(fDrawTarget->getViewMatrix()) {
907 GrAssert(NULL != target);
908 }
909
910 void set(GrDrawTarget* target) {
911 GrAssert(NULL != target);
912 if (NULL != fDrawTarget) {
913 fDrawTarget->setViewMatrix(fMatrix);
914 }
915 fDrawTarget = target;
916 fMatrix = target->getViewMatrix();
917 }
918
919 ~AutoViewMatrixRestore() {
920 if (NULL != fDrawTarget) {
921 fDrawTarget->setViewMatrix(fMatrix);
922 }
923 }
924
925 private:
926 GrDrawTarget* fDrawTarget;
927 GrMatrix fMatrix;
928 };
929
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000930 ////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +0000931
bsalomon@google.com7ac249b2011-06-14 18:46:24 +0000932 /**
933 * Sets the view matrix to I and preconcats all stage matrices enabled in
934 * mask by the view inverse. Destructor undoes these changes.
935 */
936 class AutoDeviceCoordDraw : ::GrNoncopyable {
937 public:
938 AutoDeviceCoordDraw(GrDrawTarget* target, int stageMask);
939 ~AutoDeviceCoordDraw();
940 private:
941 GrDrawTarget* fDrawTarget;
942 GrMatrix fViewMatrix;
tomhudson@google.com93813632011-10-27 20:21:16 +0000943 GrMatrix fSamplerMatrices[GrDrawState::kNumStages];
bsalomon@google.com7ac249b2011-06-14 18:46:24 +0000944 int fStageMask;
945 };
946
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000947 ////////////////////////////////////////////////////////////////////////////
bsalomon@google.com7ac249b2011-06-14 18:46:24 +0000948
reed@google.comac10a2d2010-12-22 21:39:39 +0000949 class AutoReleaseGeometry : ::GrNoncopyable {
950 public:
951 AutoReleaseGeometry(GrDrawTarget* target,
952 GrVertexLayout vertexLayout,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000953 int vertexCount,
954 int indexCount);
955 AutoReleaseGeometry();
956 ~AutoReleaseGeometry();
bsalomon@google.com5782d712011-01-21 21:03:59 +0000957 bool set(GrDrawTarget* target,
958 GrVertexLayout vertexLayout,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000959 int vertexCount,
960 int indexCount);
bsalomon@google.coma47a48d2011-04-26 20:22:11 +0000961 bool succeeded() const { return NULL != fTarget; }
bsalomon@google.com6513cd02011-08-05 20:12:30 +0000962 void* vertices() const { GrAssert(this->succeeded()); return fVertices; }
963 void* indices() const { GrAssert(this->succeeded()); return fIndices; }
reed@google.comac10a2d2010-12-22 21:39:39 +0000964 GrPoint* positions() const {
bsalomon@google.com6513cd02011-08-05 20:12:30 +0000965 return static_cast<GrPoint*>(this->vertices());
reed@google.comac10a2d2010-12-22 21:39:39 +0000966 }
967
968 private:
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000969 void reset();
970
reed@google.comac10a2d2010-12-22 21:39:39 +0000971 GrDrawTarget* fTarget;
reed@google.comac10a2d2010-12-22 21:39:39 +0000972 void* fVertices;
973 void* fIndices;
974 };
975
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000976 ////////////////////////////////////////////////////////////////////////////
reed@google.comac10a2d2010-12-22 21:39:39 +0000977
978 class AutoClipRestore : ::GrNoncopyable {
979 public:
980 AutoClipRestore(GrDrawTarget* target) {
981 fTarget = target;
982 fClip = fTarget->getClip();
983 }
984
985 ~AutoClipRestore() {
986 fTarget->setClip(fClip);
987 }
988 private:
989 GrDrawTarget* fTarget;
990 GrClip fClip;
991 };
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000992
993 ////////////////////////////////////////////////////////////////////////////
994
995 class AutoGeometryPush : ::GrNoncopyable {
996 public:
997 AutoGeometryPush(GrDrawTarget* target) {
998 GrAssert(NULL != target);
999 fTarget = target;
1000 target->pushGeometrySource();
1001 }
1002 ~AutoGeometryPush() {
1003 fTarget->popGeometrySource();
1004 }
1005 private:
1006 GrDrawTarget* fTarget;
1007 };
reed@google.comac10a2d2010-12-22 21:39:39 +00001008
1009 ////////////////////////////////////////////////////////////////////////////
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001010 // Helpers for picking apart vertex layouts
bsalomon@google.com5782d712011-01-21 21:03:59 +00001011
reed@google.comac10a2d2010-12-22 21:39:39 +00001012 /**
1013 * Helper function to compute the size of a vertex from a vertex layout
1014 * @return size of a single vertex.
1015 */
1016 static size_t VertexSize(GrVertexLayout vertexLayout);
bsalomon@google.com5782d712011-01-21 21:03:59 +00001017
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001018 /**
1019 * Helper function for determining the index of texture coordinates that
1020 * is input for a texture stage. Note that a stage may instead use positions
1021 * as texture coordinates, in which case the result of the function is
1022 * indistinguishable from the case when the stage is disabled.
1023 *
1024 * @param stage the stage to query
1025 * @param vertexLayout layout to query
1026 *
1027 * @return the texture coordinate index or -1 if the stage doesn't use
1028 * separate (non-position) texture coordinates.
1029 */
1030 static int VertexTexCoordsForStage(int stage, GrVertexLayout vertexLayout);
reed@google.comac10a2d2010-12-22 21:39:39 +00001031
1032 /**
1033 * Helper function to compute the offset of texture coordinates in a vertex
1034 * @return offset of texture coordinates in vertex layout or -1 if the
bsalomon@google.com5782d712011-01-21 21:03:59 +00001035 * layout has no texture coordinates. Will be 0 if positions are
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001036 * used as texture coordinates for the stage.
reed@google.comac10a2d2010-12-22 21:39:39 +00001037 */
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001038 static int VertexStageCoordOffset(int stage, GrVertexLayout vertexLayout);
reed@google.comac10a2d2010-12-22 21:39:39 +00001039
1040 /**
1041 * Helper function to compute the offset of the color in a vertex
1042 * @return offset of color in vertex layout or -1 if the
1043 * layout has no color.
1044 */
1045 static int VertexColorOffset(GrVertexLayout vertexLayout);
1046
bsalomon@google.coma3108262011-10-10 14:08:47 +00001047 /**
1048 * Helper function to compute the offset of the coverage in a vertex
1049 * @return offset of coverage in vertex layout or -1 if the
1050 * layout has no coverage.
1051 */
1052 static int VertexCoverageOffset(GrVertexLayout vertexLayout);
1053
bsalomon@google.comaeb21602011-08-30 18:13:44 +00001054 /**
1055 * Helper function to compute the offset of the edge pts in a vertex
1056 * @return offset of edge in vertex layout or -1 if the
1057 * layout has no edge.
1058 */
1059 static int VertexEdgeOffset(GrVertexLayout vertexLayout);
1060
reed@google.comac10a2d2010-12-22 21:39:39 +00001061 /**
bsalomon@google.com5782d712011-01-21 21:03:59 +00001062 * Helper function to determine if vertex layout contains explicit texture
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001063 * coordinates of some index.
1064 *
1065 * @param coordIndex the tex coord index to query
1066 * @param vertexLayout layout to query
1067 *
bsalomon@google.com5782d712011-01-21 21:03:59 +00001068 * @return true if vertex specifies texture coordinates for the index,
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001069 * false otherwise.
reed@google.comac10a2d2010-12-22 21:39:39 +00001070 */
bsalomon@google.com5782d712011-01-21 21:03:59 +00001071 static bool VertexUsesTexCoordIdx(int coordIndex,
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001072 GrVertexLayout vertexLayout);
bsalomon@google.com5782d712011-01-21 21:03:59 +00001073
reed@google.comac10a2d2010-12-22 21:39:39 +00001074 /**
1075 * Helper function to determine if vertex layout contains either explicit or
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001076 * implicit texture coordinates for a stage.
reed@google.comac10a2d2010-12-22 21:39:39 +00001077 *
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001078 * @param stage the stage to query
1079 * @param vertexLayout layout to query
1080 *
bsalomon@google.com5782d712011-01-21 21:03:59 +00001081 * @return true if vertex specifies texture coordinates for the stage,
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001082 * false otherwise.
reed@google.comac10a2d2010-12-22 21:39:39 +00001083 */
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001084 static bool VertexUsesStage(int stage, GrVertexLayout vertexLayout);
reed@google.comac10a2d2010-12-22 21:39:39 +00001085
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001086 /**
bsalomon@google.com5782d712011-01-21 21:03:59 +00001087 * Helper function to compute the size of each vertex and the offsets of
1088 * texture coordinates and color. Determines tex coord offsets by tex coord
1089 * index rather than by stage. (Each stage can be mapped to any t.c. index
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001090 * by StageTexCoordVertexLayoutBit.)
1091 *
1092 * @param vertexLayout the layout to query
1093 * @param texCoordOffsetsByIdx after return it is the offset of each
1094 * tex coord index in the vertex or -1 if
bsalomon@google.coma3108262011-10-10 14:08:47 +00001095 * index isn't used. (optional)
1096 * @param colorOffset after return it is the offset of the
1097 * color field in each vertex, or -1 if
1098 * there aren't per-vertex colors. (optional)
1099 * @param coverageOffset after return it is the offset of the
1100 * coverage field in each vertex, or -1 if
1101 * there aren't per-vertex coeverages.
1102 * (optional)
1103 * @param edgeOffset after return it is the offset of the
1104 * edge eq field in each vertex, or -1 if
1105 * there aren't per-vertex edge equations.
1106 * (optional)
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001107 * @return size of a single vertex
1108 */
1109 static int VertexSizeAndOffsetsByIdx(GrVertexLayout vertexLayout,
tomhudson@google.com93813632011-10-27 20:21:16 +00001110 int texCoordOffsetsByIdx[GrDrawState::kMaxTexCoords],
1111 int *colorOffset,
1112 int *coverageOffset,
1113 int* edgeOffset);
bsalomon@google.com5782d712011-01-21 21:03:59 +00001114
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001115 /**
bsalomon@google.com5782d712011-01-21 21:03:59 +00001116 * Helper function to compute the size of each vertex and the offsets of
1117 * texture coordinates and color. Determines tex coord offsets by stage
1118 * rather than by index. (Each stage can be mapped to any t.c. index
1119 * by StageTexCoordVertexLayoutBit.) If a stage uses positions for
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001120 * tex coords then that stage's offset will be 0 (positions are always at 0).
1121 *
1122 * @param vertexLayout the layout to query
1123 * @param texCoordOffsetsByStage after return it is the offset of each
1124 * tex coord index in the vertex or -1 if
bsalomon@google.coma3108262011-10-10 14:08:47 +00001125 * index isn't used. (optional)
1126 * @param colorOffset after return it is the offset of the
1127 * color field in each vertex, or -1 if
1128 * there aren't per-vertex colors.
1129 * (optional)
1130 * @param coverageOffset after return it is the offset of the
1131 * coverage field in each vertex, or -1 if
1132 * there aren't per-vertex coeverages.
1133 * (optional)
1134 * @param edgeOffset after return it is the offset of the
1135 * edge eq field in each vertex, or -1 if
1136 * there aren't per-vertex edge equations.
1137 * (optional)
bsalomon@google.com8531c1c2011-01-13 19:52:45 +00001138 * @return size of a single vertex
1139 */
1140 static int VertexSizeAndOffsetsByStage(GrVertexLayout vertexLayout,
tomhudson@google.com93813632011-10-27 20:21:16 +00001141 int texCoordOffsetsByStage[GrDrawState::kNumStages],
1142 int* colorOffset,
1143 int* coverageOffset,
1144 int* edgeOffset);
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001145
1146 /**
1147 * Accessing positions, texture coords, or colors, of a vertex within an
1148 * array is a hassle involving casts and simple math. These helpers exist
1149 * to keep GrDrawTarget clients' code a bit nicer looking.
1150 */
1151
1152 /**
1153 * Gets a pointer to a GrPoint of a vertex's position or texture
1154 * coordinate.
1155 * @param vertices the vetex array
1156 * @param vertexIndex the index of the vertex in the array
1157 * @param vertexSize the size of each vertex in the array
1158 * @param offset the offset in bytes of the vertex component.
1159 * Defaults to zero (corresponding to vertex position)
1160 * @return pointer to the vertex component as a GrPoint
1161 */
bsalomon@google.comd302f142011-03-03 13:54:13 +00001162 static GrPoint* GetVertexPoint(void* vertices,
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001163 int vertexIndex,
1164 int vertexSize,
1165 int offset = 0) {
1166 intptr_t start = GrTCast<intptr_t>(vertices);
bsalomon@google.comd302f142011-03-03 13:54:13 +00001167 return GrTCast<GrPoint*>(start + offset +
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001168 vertexIndex * vertexSize);
1169 }
1170 static const GrPoint* GetVertexPoint(const void* vertices,
1171 int vertexIndex,
bsalomon@google.comd302f142011-03-03 13:54:13 +00001172 int vertexSize,
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001173 int offset = 0) {
1174 intptr_t start = GrTCast<intptr_t>(vertices);
bsalomon@google.comd302f142011-03-03 13:54:13 +00001175 return GrTCast<const GrPoint*>(start + offset +
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001176 vertexIndex * vertexSize);
1177 }
1178
1179 /**
1180 * Gets a pointer to a GrColor inside a vertex within a vertex array.
1181 * @param vertices the vetex array
1182 * @param vertexIndex the index of the vertex in the array
1183 * @param vertexSize the size of each vertex in the array
1184 * @param offset the offset in bytes of the vertex color
1185 * @return pointer to the vertex component as a GrColor
1186 */
bsalomon@google.comd302f142011-03-03 13:54:13 +00001187 static GrColor* GetVertexColor(void* vertices,
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001188 int vertexIndex,
1189 int vertexSize,
1190 int offset) {
1191 intptr_t start = GrTCast<intptr_t>(vertices);
bsalomon@google.comd302f142011-03-03 13:54:13 +00001192 return GrTCast<GrColor*>(start + offset +
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001193 vertexIndex * vertexSize);
1194 }
1195 static const GrColor* GetVertexColor(const void* vertices,
1196 int vertexIndex,
bsalomon@google.comd302f142011-03-03 13:54:13 +00001197 int vertexSize,
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001198 int offset) {
1199 const intptr_t start = GrTCast<intptr_t>(vertices);
bsalomon@google.comd302f142011-03-03 13:54:13 +00001200 return GrTCast<const GrColor*>(start + offset +
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001201 vertexIndex * vertexSize);
1202 }
1203
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +00001204 static void VertexLayoutUnitTest();
1205
reed@google.comac10a2d2010-12-22 21:39:39 +00001206protected:
bsalomon@google.com471d4712011-08-23 15:45:25 +00001207
bsalomon@google.com86c1f712011-10-12 14:54:26 +00001208 /**
1209 * Optimizations for blending / coverage to be applied based on the current
1210 * state.
1211 * Subclasses that actually draw (as opposed to those that just buffer for
1212 * playback) must implement the flags that replace the output color.
1213 */
1214 enum BlendOptFlags {
1215 /**
1216 * No optimization
1217 */
1218 kNone_BlendOpt = 0,
1219 /**
1220 * Don't draw at all
1221 */
1222 kSkipDraw_BlendOptFlag = 0x2,
1223 /**
1224 * Emit the src color, disable HW blending (replace dst with src)
1225 */
1226 kDisableBlend_BlendOptFlag = 0x4,
1227 /**
1228 * The coverage value does not have to be computed separately from
1229 * alpha, the the output color can be the modulation of the two.
1230 */
1231 kCoverageAsAlpha_BlendOptFlag = 0x1,
1232 /**
1233 * Instead of emitting a src color, emit coverage in the alpha channel
1234 * and r,g,b are "don't cares".
1235 */
1236 kEmitCoverage_BlendOptFlag = 0x10,
1237 /**
1238 * Emit transparent black instead of the src color, no need to compute
1239 * coverage.
1240 */
1241 kEmitTransBlack_BlendOptFlag = 0x8,
1242 };
1243 GR_DECL_BITFIELD_OPS_FRIENDS(BlendOptFlags);
bsalomon@google.com471d4712011-08-23 15:45:25 +00001244
bsalomon@google.com86c1f712011-10-12 14:54:26 +00001245 // Determines what optimizations can be applied based on the blend.
1246 // The coeffecients may have to be tweaked in order for the optimization
1247 // to work. srcCoeff and dstCoeff are optional params that receive the
1248 // tweaked coeffecients.
1249 // Normally the function looks at the current state to see if coverage
1250 // is enabled. By setting forceCoverage the caller can speculatively
1251 // determine the blend optimizations that would be used if there was
1252 // partial pixel coverage
1253 BlendOptFlags getBlendOpts(bool forceCoverage = false,
1254 GrBlendCoeff* srcCoeff = NULL,
1255 GrBlendCoeff* dstCoeff = NULL) const;
1256
1257 // determine if src alpha is guaranteed to be one for all src pixels
1258 bool srcAlphaWillBeOne() const;
bsalomon@google.com471d4712011-08-23 15:45:25 +00001259
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001260 enum GeometrySrcType {
1261 kNone_GeometrySrcType, //<! src has not been specified
1262 kReserved_GeometrySrcType, //<! src was set using reserve*Space
1263 kArray_GeometrySrcType, //<! src was set using set*SourceToArray
1264 kBuffer_GeometrySrcType //<! src was set using set*SourceToBuffer
1265 };
1266
1267 struct GeometrySrcState {
1268 GeometrySrcType fVertexSrc;
1269 union {
1270 // valid if src type is buffer
1271 const GrVertexBuffer* fVertexBuffer;
1272 // valid if src type is reserved or array
1273 int fVertexCount;
1274 };
1275
1276 GeometrySrcType fIndexSrc;
1277 union {
1278 // valid if src type is buffer
1279 const GrIndexBuffer* fIndexBuffer;
1280 // valid if src type is reserved or array
1281 int fIndexCount;
1282 };
1283
1284 GrVertexLayout fVertexLayout;
1285 };
1286
bsalomon@google.coma47a48d2011-04-26 20:22:11 +00001287 // given a vertex layout and a draw state, will a stage be used?
1288 static bool StageWillBeUsed(int stage, GrVertexLayout layout,
tomhudson@google.com93813632011-10-27 20:21:16 +00001289 const GrDrawState& state) {
bsalomon@google.coma47a48d2011-04-26 20:22:11 +00001290 return NULL != state.fTextures[stage] && VertexUsesStage(stage, layout);
1291 }
1292
1293 bool isStageEnabled(int stage) const {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001294 return StageWillBeUsed(stage, this->getGeomSrc().fVertexLayout,
1295 fCurrDrawState);
bsalomon@google.coma47a48d2011-04-26 20:22:11 +00001296 }
bsalomon@google.com5782d712011-01-21 21:03:59 +00001297
bsalomon@google.comaeb21602011-08-30 18:13:44 +00001298 StageBitfield enabledStages() const {
1299 StageBitfield mask = 0;
tomhudson@google.com93813632011-10-27 20:21:16 +00001300 for (int s = 0; s < GrDrawState::kNumStages; ++s) {
bsalomon@google.comaeb21602011-08-30 18:13:44 +00001301 mask |= this->isStageEnabled(s) ? 1 : 0;
1302 }
1303 return mask;
1304 }
1305
reed@google.comac10a2d2010-12-22 21:39:39 +00001306 // Helpers for GrDrawTarget subclasses that won't have private access to
1307 // SavedDrawState but need to peek at the state values.
tomhudson@google.com93813632011-10-27 20:21:16 +00001308 static GrDrawState& accessSavedDrawState(SavedDrawState& sds)
reed@google.comac10a2d2010-12-22 21:39:39 +00001309 { return sds.fState; }
tomhudson@google.com93813632011-10-27 20:21:16 +00001310 static const GrDrawState& accessSavedDrawState(const SavedDrawState& sds)
reed@google.comac10a2d2010-12-22 21:39:39 +00001311 { return sds.fState; }
1312
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001313 // implemented by subclass to allocate space for reserved geom
1314 virtual bool onReserveVertexSpace(GrVertexLayout vertexLayout,
1315 int vertexCount,
1316 void** vertices) = 0;
1317 virtual bool onReserveIndexSpace(int indexCount, void** indices) = 0;
1318 // implemented by subclass to handle release of reserved geom space
1319 virtual void releaseReservedVertexSpace() = 0;
1320 virtual void releaseReservedIndexSpace() = 0;
1321 // subclass must consume array contents when set
1322 virtual void onSetVertexSourceToArray(const void* vertexArray,
1323 int vertexCount) = 0;
1324 virtual void onSetIndexSourceToArray(const void* indexArray,
1325 int indexCount) = 0;
1326 // subclass is notified that geom source will be set away from an array
1327 virtual void releaseVertexArray() = 0;
1328 virtual void releaseIndexArray() = 0;
1329 // subclass overrides to be notified just before geo src state
1330 // is pushed/popped.
1331 virtual void geometrySourceWillPush() = 0;
1332 virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) = 0;
1333 // subclass called to perform drawing
1334 virtual void onDrawIndexed(GrPrimitiveType type,
1335 int startVertex,
1336 int startIndex,
1337 int vertexCount,
1338 int indexCount) = 0;
1339 virtual void onDrawNonIndexed(GrPrimitiveType type,
1340 int startVertex,
1341 int vertexCount) = 0;
bsalomon@google.comdea2f8d2011-08-01 15:51:05 +00001342 // subclass overrides to be notified when clip is set. Must call
1343 // INHERITED::clipwillBeSet
1344 virtual void clipWillBeSet(const GrClip& clip);
bsalomon@google.com1c13c962011-02-14 16:51:21 +00001345
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001346 // Helpers for drawRect, protected so subclasses that override drawRect
1347 // can use them.
bsalomon@google.comffca4002011-02-22 20:34:01 +00001348 static GrVertexLayout GetRectVertexLayout(StageBitfield stageEnableBitfield,
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001349 const GrRect* srcRects[]);
1350
1351 static void SetRectVertices(const GrRect& rect,
bsalomon@google.comd302f142011-03-03 13:54:13 +00001352 const GrMatrix* matrix,
1353 const GrRect* srcRects[],
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001354 const GrMatrix* srcMatrices[],
bsalomon@google.comd302f142011-03-03 13:54:13 +00001355 GrVertexLayout layout,
bsalomon@google.com86afc2a2011-02-16 16:12:19 +00001356 void* vertices);
1357
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001358 // accessor for derived classes
1359 const GeometrySrcState& getGeomSrc() const {
1360 return fGeoSrcStateStack.back();
1361 }
reed@google.comac10a2d2010-12-22 21:39:39 +00001362
1363 GrClip fClip;
1364
tomhudson@google.com93813632011-10-27 20:21:16 +00001365 GrDrawState fCurrDrawState;
reed@google.comac10a2d2010-12-22 21:39:39 +00001366
bsalomon@google.com18c9c192011-09-22 21:01:31 +00001367 Caps fCaps;
1368
bsalomon@google.com4a018bb2011-10-28 19:50:21 +00001369 // subclasses must call this in their destructors to ensure all vertex
1370 // and index sources have been released (including those held by
1371 // pushGeometrySource())
1372 void releaseGeometry();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001373private:
1374 // called when setting a new vert/idx source to unref prev vb/ib
1375 void releasePreviousVertexSource();
1376 void releasePreviousIndexSource();
1377
1378 enum {
1379 kPreallocGeoSrcStateStackCnt = 4,
reed@google.comac10a2d2010-12-22 21:39:39 +00001380 };
bsalomon@google.com92669012011-09-27 19:10:05 +00001381 SkSTArray<kPreallocGeoSrcStateStackCnt,
1382 GeometrySrcState, true> fGeoSrcStateStack;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +00001383
reed@google.comac10a2d2010-12-22 21:39:39 +00001384};
1385
bsalomon@google.com86c1f712011-10-12 14:54:26 +00001386GR_MAKE_BITFIELD_OPS(GrDrawTarget::BlendOptFlags);
1387
reed@google.comac10a2d2010-12-22 21:39:39 +00001388#endif