epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * 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.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 10 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 11 | #ifndef GrDrawTarget_DEFINED |
| 12 | #define GrDrawTarget_DEFINED |
| 13 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 14 | #include "GrClip.h" |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 15 | #include "GrColor.h" |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 16 | #include "GrDrawState.h" |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 17 | #include "GrMatrix.h" |
| 18 | #include "GrRefCnt.h" |
| 19 | #include "GrRenderTarget.h" |
| 20 | #include "GrSamplerState.h" |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 21 | #include "GrStencil.h" |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 22 | #include "GrTexture.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 23 | |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 24 | #include "SkXfermode.h" |
| 25 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 26 | class GrTexture; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 27 | class GrClipIterator; |
| 28 | class GrVertexBuffer; |
| 29 | class GrIndexBuffer; |
| 30 | |
| 31 | class GrDrawTarget : public GrRefCnt { |
| 32 | public: |
| 33 | /** |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 34 | * 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.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 53 | bool fGeometryShaderSupport : 1; |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 54 | bool fFSAASupport : 1; |
| 55 | bool fDualSourceBlendingSupport : 1; |
| 56 | bool fBufferLockSupport : 1; |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 57 | bool fSupportPerVertexCoverage : 1; |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 58 | int fMinRenderTargetWidth; |
| 59 | int fMinRenderTargetHeight; |
| 60 | int fMaxRenderTargetSize; |
| 61 | int fMaxTextureSize; |
| 62 | }; |
| 63 | |
| 64 | /** |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 65 | * Bitfield used to indicate which stages are in use. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 66 | */ |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 67 | typedef int StageBitfield; |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 68 | GR_STATIC_ASSERT(sizeof(StageBitfield)*8 >= GrDrawState::kNumStages); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 69 | |
| 70 | /** |
| 71 | * Flags that affect rendering. Controlled using enable/disableState(). All |
| 72 | * default to disabled. |
| 73 | */ |
| 74 | enum StateBits { |
bsalomon@google.com | 289533a | 2011-10-27 12:34:25 +0000 | [diff] [blame] | 75 | /** |
| 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.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 100 | // subclass may use additional bits internally |
| 101 | kDummyStateBit, |
| 102 | kLastPublicStateBit = kDummyStateBit-1 |
| 103 | }; |
| 104 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 105 | /** |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 106 | * Sets the stencil settings to use for the next draw. |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 107 | * 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.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 110 | * @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.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 122 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 123 | public: |
| 124 | /////////////////////////////////////////////////////////////////////////// |
| 125 | |
| 126 | GrDrawTarget(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 127 | virtual ~GrDrawTarget(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 128 | |
| 129 | /** |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 130 | * Gets the capabilities of the draw target. |
| 131 | */ |
| 132 | const Caps& getCaps() const { return fCaps; } |
| 133 | |
| 134 | /** |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 135 | * 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.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 138 | * Setting the clip may (or may not) zero out the client's stencil bits. |
| 139 | * |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 140 | * @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.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 154 | * @param stage The texture stage for which the texture will be set |
| 155 | * |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 156 | * @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.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 159 | void setTexture(int stage, GrTexture* texture); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 160 | |
| 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.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 168 | const GrTexture* getTexture(int stage) const; |
| 169 | GrTexture* getTexture(int stage); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 170 | |
| 171 | /** |
| 172 | * Sets the rendertarget used at the next drawing call |
| 173 | * |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 174 | * @param target The render target to set. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 175 | */ |
| 176 | void setRenderTarget(GrRenderTarget* target); |
| 177 | |
| 178 | /** |
| 179 | * Retrieves the currently set rendertarget. |
| 180 | * |
| 181 | * @return The currently set render target. |
| 182 | */ |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 183 | const GrRenderTarget* getRenderTarget() const; |
| 184 | GrRenderTarget* getRenderTarget(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 185 | |
| 186 | /** |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 187 | * Sets the sampler state for a stage used in subsequent draws. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 188 | * |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 189 | * The sampler state determines how texture coordinates are |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 190 | * intepretted and used to sample the texture. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 191 | * |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 192 | * @param stage the stage of the sampler to set |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 193 | * @param samplerState Specifies the sampler state. |
| 194 | */ |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 195 | void setSamplerState(int stage, const GrSamplerState& samplerState); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 196 | |
| 197 | /** |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 198 | * Concats the matrix of a stage's sampler. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 199 | * |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 200 | * @param stage the stage of the sampler to set |
| 201 | * @param matrix the matrix to concat |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 202 | */ |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 203 | void preConcatSamplerMatrix(int stage, const GrMatrix& matrix) { |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 204 | GrAssert(stage >= 0 && stage < GrDrawState::kNumStages); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 205 | fCurrDrawState.fSamplerStates[stage].preConcatMatrix(matrix); |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 206 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 207 | |
| 208 | /** |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 209 | * Shortcut for preConcatSamplerMatrix on all stages in mask with same |
bsalomon@google.com | 26c2d0a | 2011-05-17 20:15:30 +0000 | [diff] [blame] | 210 | * matrix |
| 211 | */ |
| 212 | void preConcatSamplerMatrices(int stageMask, const GrMatrix& matrix) { |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 213 | for (int i = 0; i < GrDrawState::kNumStages; ++i) { |
bsalomon@google.com | 26c2d0a | 2011-05-17 20:15:30 +0000 | [diff] [blame] | 214 | if ((1 << i) & stageMask) { |
| 215 | this->preConcatSamplerMatrix(i, matrix); |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | /** |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 221 | * 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.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 233 | * Gets the matrix of a stage's sampler |
bsalomon@google.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 234 | * |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 235 | * @param stage the stage to of sampler to get |
| 236 | * @return the sampler state's matrix |
bsalomon@google.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 237 | */ |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 238 | const GrMatrix& getSamplerMatrix(int stage) const { |
| 239 | return fCurrDrawState.fSamplerStates[stage].getMatrix(); |
| 240 | } |
bsalomon@google.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 241 | |
| 242 | /** |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 243 | * 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.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 247 | */ |
djsollen@google.com | cd9d69b | 2011-03-14 20:30:14 +0000 | [diff] [blame] | 248 | void setSamplerMatrix(int stage, const GrMatrix& matrix) { |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 249 | fCurrDrawState.fSamplerStates[stage].setMatrix(matrix); |
| 250 | } |
bsalomon@google.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 251 | |
| 252 | /** |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 253 | * 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.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 261 | void setViewMatrix(const GrMatrix& m); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 262 | |
| 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.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 271 | * @param m the matrix used to modify the view matrix. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 272 | */ |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 273 | void preConcatViewMatrix(const GrMatrix& m); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 274 | |
| 275 | /** |
bsalomon@google.com | 06afe7b | 2011-04-26 15:31:40 +0000 | [diff] [blame] | 276 | * 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.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 288 | * 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.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 305 | * 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.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 312 | * Gets the currently set color. |
| 313 | * @return the current color. |
| 314 | */ |
| 315 | GrColor getColor() const { return fCurrDrawState.fColor; } |
| 316 | |
| 317 | /** |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 318 | * 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.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 323 | * 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.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 331 | * Controls whether clockwise, counterclockwise, or both faces are drawn. |
| 332 | * @param face the face(s) to draw. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 333 | */ |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 334 | void setDrawFace(GrDrawState::DrawFace face) { |
| 335 | fCurrDrawState.fDrawFace = face; |
| 336 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 337 | |
| 338 | /** |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 339 | * 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.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 344 | * this method. Initially this is GrDrawState::kNumStages (all stages |
| 345 | * are color-computing). |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 346 | */ |
| 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.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 359 | * Gets whether the target is drawing clockwise, counterclockwise, |
| 360 | * or both faces. |
| 361 | * @return the current draw face(s). |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 362 | */ |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 363 | GrDrawState::DrawFace getDrawFace() const { |
| 364 | return fCurrDrawState.fDrawFace; |
| 365 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 366 | |
| 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.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 382 | return 0 != (fCurrDrawState.fFlagBits & kDither_StateBit); |
| 383 | } |
| 384 | |
bsalomon@google.com | 289533a | 2011-10-27 12:34:25 +0000 | [diff] [blame] | 385 | bool isHWAntialiasState() const { |
| 386 | return 0 != (fCurrDrawState.fFlagBits & kHWAntialias_StateBit); |
senorblanco@chromium.org | 92e0f22 | 2011-05-12 15:49:15 +0000 | [diff] [blame] | 387 | } |
| 388 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 389 | bool isClipState() const { |
| 390 | return 0 != (fCurrDrawState.fFlagBits & kClip_StateBit); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 391 | } |
| 392 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 393 | bool isColorWriteDisabled() const { |
| 394 | return 0 != (fCurrDrawState.fFlagBits & kNoColorWrites_StateBit); |
| 395 | } |
| 396 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 397 | /** |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 398 | * 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.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 410 | void setBlendFunc(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 411 | |
| 412 | /** |
bsalomon@google.com | 080773c | 2011-03-15 19:09:25 +0000 | [diff] [blame] | 413 | * 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.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 431 | * Determines if blending will require a read of a dst given the current |
| 432 | * state set on the draw target |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 433 | * |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 434 | * @return true if the dst surface will be read at each pixel hit by the |
| 435 | * a draw operation. |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 436 | */ |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 437 | bool drawWillReadDst() const; |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 438 | |
bsalomon@google.com | d46e242 | 2011-09-23 17:40:07 +0000 | [diff] [blame] | 439 | /** |
| 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.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 457 | bool canTweakAlphaForCoverage() const; |
bsalomon@google.com | d46e242 | 2011-09-23 17:40:07 +0000 | [diff] [blame] | 458 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 459 | /** |
| 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.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 464 | void setVertexEdgeType(GrDrawState::VertexEdgeType type) { |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 465 | fCurrDrawState.fVertexEdgeType = type; |
| 466 | } |
| 467 | |
senorblanco@chromium.org | 92e0f22 | 2011-05-12 15:49:15 +0000 | [diff] [blame] | 468 | /** |
bsalomon@google.com | 471d471 | 2011-08-23 15:45:25 +0000 | [diff] [blame] | 469 | * 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.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 473 | bool willUseHWAALines() const; |
bsalomon@google.com | 471d471 | 2011-08-23 15:45:25 +0000 | [diff] [blame] | 474 | |
| 475 | /** |
senorblanco@chromium.org | 92e0f22 | 2011-05-12 15:49:15 +0000 | [diff] [blame] | 476 | * 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.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 481 | void setEdgeAAData(const GrDrawState::Edge* edges, int numEdges); |
senorblanco@chromium.org | 92e0f22 | 2011-05-12 15:49:15 +0000 | [diff] [blame] | 482 | |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 483 | /** |
| 484 | * Used to save and restore the GrGpu's drawing state |
| 485 | */ |
| 486 | struct SavedDrawState { |
| 487 | private: |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 488 | GrDrawState fState; |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 489 | 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.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 523 | * 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.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 526 | * 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.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 552 | GrAssert(stage < GrDrawState::kNumStages); |
| 553 | GrAssert(texCoordIdx < GrDrawState::kMaxTexCoords); |
| 554 | return 1 << (stage + (texCoordIdx * GrDrawState::kNumStages)); |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 555 | } |
| 556 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 557 | private: |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 558 | static const int TEX_COORD_BIT_CNT = GrDrawState::kNumStages * |
| 559 | GrDrawState::kMaxTexCoords; |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 560 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 561 | public: |
| 562 | /** |
| 563 | * Generates a bit indicating that a texture stage uses the position |
| 564 | * as its texture coordinate. |
| 565 | * |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 566 | * @param stage the stage that will use position as texture |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 567 | * coordinates. |
| 568 | * |
| 569 | * @return the bit to add to a GrVertexLayout bitfield. |
| 570 | */ |
| 571 | static int StagePosAsTexCoordVertexLayoutBit(int stage) { |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 572 | GrAssert(stage < GrDrawState::kNumStages); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 573 | return (1 << (TEX_COORD_BIT_CNT + stage)); |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 574 | } |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 575 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 576 | private: |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 577 | static const int STAGE_BIT_CNT = TEX_COORD_BIT_CNT + |
| 578 | GrDrawState::kNumStages; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 579 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 580 | public: |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 581 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 582 | /** |
| 583 | * Additional Bits that can be specified in GrVertexLayout. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 584 | */ |
| 585 | enum VertexLayoutBits { |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 586 | /* vertices have colors (GrColor) */ |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 587 | kColor_VertexLayoutBit = 1 << (STAGE_BIT_CNT + 0), |
bsalomon@google.com | e10f6fd | 2011-10-11 20:15:26 +0000 | [diff] [blame] | 588 | /* vertices have coverage (GrColor where all channels should have the |
| 589 | * same value) |
| 590 | */ |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 591 | kCoverage_VertexLayoutBit = 1 << (STAGE_BIT_CNT + 1), |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 592 | /* Use text vertices. (Pos and tex coords may be a different type for |
bsalomon@google.com | e10f6fd | 2011-10-11 20:15:26 +0000 | [diff] [blame] | 593 | * text [GrGpuTextVertex vs GrPoint].) |
| 594 | */ |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 595 | kTextFormat_VertexLayoutBit = 1 << (STAGE_BIT_CNT + 2), |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 596 | |
bsalomon@google.com | e10f6fd | 2011-10-11 20:15:26 +0000 | [diff] [blame] | 597 | /* Each vertex specificies an edge. Distance to the edge is used to |
| 598 | * compute a coverage. See setVertexEdgeType(). |
| 599 | */ |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 600 | kEdge_VertexLayoutBit = 1 << (STAGE_BIT_CNT + 3), |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 601 | // for below assert |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 602 | kDummyVertexLayoutBit, |
| 603 | kHighVertexLayoutBit = kDummyVertexLayoutBit - 1 |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 604 | }; |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 605 | // make sure we haven't exceeded the number of bits in GrVertexLayout. |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 606 | GR_STATIC_ASSERT(kHighVertexLayoutBit < ((uint64_t)1 << 8*sizeof(GrVertexLayout))); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 607 | |
| 608 | /** |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 609 | * There are three methods for specifying geometry (vertices and optionally |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 610 | * indices) to the draw target. When indexed drawing the indices and vertices |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 611 | * 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.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 617 | * |
| 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.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 625 | * 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.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 633 | * |
| 634 | * 3. Vertex and Index Buffers. This is most useful for geometry that will |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 635 | * 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.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 638 | */ |
| 639 | |
| 640 | /** |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 641 | * Reserves space for vertices. Draw target will use reserved vertices at |
| 642 | * at the next draw. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 643 | * |
| 644 | * If succeeds: |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 645 | * if vertexCount > 0, *vertices will be the array |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 646 | * of vertices to be filled by caller. The next draw will read |
| 647 | * these vertices. |
| 648 | * |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 649 | * If a client does not already have a vertex buffer then this is the |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 650 | * preferred way to allocate vertex data. It allows the subclass of |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 651 | * 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.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 653 | * |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 654 | * 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.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 658 | * |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 659 | * @param vertexLayout the format of vertices (ignored if vertexCount == 0). |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 660 | * @param vertexCount the number of vertices to reserve space for. Can be 0. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 661 | * @param vertices will point to reserved vertex space if vertexCount is |
| 662 | * non-zero. Illegal to pass NULL if vertexCount > 0. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 663 | * |
| 664 | * @return true if succeeded in allocating space for the vertices and false |
| 665 | * if not. |
| 666 | */ |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 667 | 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.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 695 | /** |
| 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.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 718 | int* vertexCount, |
| 719 | int* indexCount) const; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 720 | |
| 721 | /** |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 722 | * Sets source of vertex data for the next draw. Array must contain |
| 723 | * the vertex data when this is called. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 724 | * |
| 725 | * @param array cpu array containing vertex data. |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 726 | * @param size size of the vertex data. |
| 727 | * @param vertexCount the number of vertices in the array. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 728 | */ |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 729 | void setVertexSourceToArray(GrVertexLayout vertexLayout, |
| 730 | const void* vertexArray, |
| 731 | int vertexCount); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 732 | |
| 733 | /** |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 734 | * Sets source of index data for the next indexed draw. Array must contain |
| 735 | * the indices when this is called. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 736 | * |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 737 | * @param array cpu array containing index data. |
| 738 | * @param indexCount the number of indices in the array. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 739 | */ |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 740 | void setIndexSourceToArray(const void* indexArray, int indexCount); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 741 | |
| 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.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 750 | void setVertexSourceToBuffer(GrVertexLayout vertexLayout, |
| 751 | const GrVertexBuffer* buffer); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 752 | |
| 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.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 761 | |
| 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.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 777 | |
| 778 | /** |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 779 | * 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.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 791 | * 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.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 803 | void drawIndexed(GrPrimitiveType type, |
| 804 | int startVertex, |
| 805 | int startIndex, |
| 806 | int vertexCount, |
| 807 | int indexCount); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 808 | |
| 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.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 818 | void drawNonIndexed(GrPrimitiveType type, |
| 819 | int startVertex, |
| 820 | int vertexCount); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 821 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 822 | /** |
| 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.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 828 | * optimizations if drawRect is used rather than drawIndexed or |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 829 | * drawNonIndexed. |
| 830 | * @param rect the rect to draw |
| 831 | * @param matrix optional matrix applied to rect (before viewMatrix) |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 832 | * @param stageEnableBitfield bitmask indicating which stages are enabled. |
| 833 | * Bit i indicates whether stage i is enabled. |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 834 | * @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.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 845 | virtual void drawRect(const GrRect& rect, |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 846 | const GrMatrix* matrix, |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 847 | StageBitfield stageEnableBitfield, |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 848 | const GrRect* srcRects[], |
| 849 | const GrMatrix* srcMatrices[]); |
| 850 | |
| 851 | /** |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 852 | * Helper for drawRect when the caller doesn't need separate src rects or |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 853 | * matrices. |
| 854 | */ |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 855 | void drawSimpleRect(const GrRect& rect, |
| 856 | const GrMatrix* matrix, |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 857 | StageBitfield stageEnableBitfield) { |
| 858 | drawRect(rect, matrix, stageEnableBitfield, NULL, NULL); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 859 | } |
| 860 | |
bsalomon@google.com | 0b335c1 | 2011-04-25 19:17:44 +0000 | [diff] [blame] | 861 | /** |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 862 | * 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.com | 0b335c1 | 2011-04-25 19:17:44 +0000 | [diff] [blame] | 865 | */ |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 866 | virtual void clear(const GrIRect* rect, GrColor color) = 0; |
bsalomon@google.com | 0b335c1 | 2011-04-25 19:17:44 +0000 | [diff] [blame] | 867 | |
senorblanco@chromium.org | ef3913b | 2011-05-19 17:11:07 +0000 | [diff] [blame] | 868 | /** |
| 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.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 877 | //////////////////////////////////////////////////////////////////////////// |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 878 | |
| 879 | class AutoStateRestore : ::GrNoncopyable { |
| 880 | public: |
bsalomon@google.com | 06afe7b | 2011-04-26 15:31:40 +0000 | [diff] [blame] | 881 | AutoStateRestore(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 882 | AutoStateRestore(GrDrawTarget* target); |
| 883 | ~AutoStateRestore(); |
| 884 | |
bsalomon@google.com | 06afe7b | 2011-04-26 15:31:40 +0000 | [diff] [blame] | 885 | /** |
| 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.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 892 | private: |
| 893 | GrDrawTarget* fDrawTarget; |
| 894 | SavedDrawState fDrawState; |
| 895 | }; |
| 896 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 897 | //////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 898 | |
bsalomon@google.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 899 | class AutoViewMatrixRestore : ::GrNoncopyable { |
| 900 | public: |
| 901 | AutoViewMatrixRestore() { |
| 902 | fDrawTarget = NULL; |
| 903 | } |
| 904 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 905 | AutoViewMatrixRestore(GrDrawTarget* target) |
bsalomon@google.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 906 | : 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.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 930 | //////////////////////////////////////////////////////////////////////////// |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 931 | |
bsalomon@google.com | 7ac249b | 2011-06-14 18:46:24 +0000 | [diff] [blame] | 932 | /** |
| 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.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 943 | GrMatrix fSamplerMatrices[GrDrawState::kNumStages]; |
bsalomon@google.com | 7ac249b | 2011-06-14 18:46:24 +0000 | [diff] [blame] | 944 | int fStageMask; |
| 945 | }; |
| 946 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 947 | //////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 7ac249b | 2011-06-14 18:46:24 +0000 | [diff] [blame] | 948 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 949 | class AutoReleaseGeometry : ::GrNoncopyable { |
| 950 | public: |
| 951 | AutoReleaseGeometry(GrDrawTarget* target, |
| 952 | GrVertexLayout vertexLayout, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 953 | int vertexCount, |
| 954 | int indexCount); |
| 955 | AutoReleaseGeometry(); |
| 956 | ~AutoReleaseGeometry(); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 957 | bool set(GrDrawTarget* target, |
| 958 | GrVertexLayout vertexLayout, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 959 | int vertexCount, |
| 960 | int indexCount); |
bsalomon@google.com | a47a48d | 2011-04-26 20:22:11 +0000 | [diff] [blame] | 961 | bool succeeded() const { return NULL != fTarget; } |
bsalomon@google.com | 6513cd0 | 2011-08-05 20:12:30 +0000 | [diff] [blame] | 962 | void* vertices() const { GrAssert(this->succeeded()); return fVertices; } |
| 963 | void* indices() const { GrAssert(this->succeeded()); return fIndices; } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 964 | GrPoint* positions() const { |
bsalomon@google.com | 6513cd0 | 2011-08-05 20:12:30 +0000 | [diff] [blame] | 965 | return static_cast<GrPoint*>(this->vertices()); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | private: |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 969 | void reset(); |
| 970 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 971 | GrDrawTarget* fTarget; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 972 | void* fVertices; |
| 973 | void* fIndices; |
| 974 | }; |
| 975 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 976 | //////////////////////////////////////////////////////////////////////////// |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 977 | |
| 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.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 992 | |
| 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.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1008 | |
| 1009 | //////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 1010 | // Helpers for picking apart vertex layouts |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 1011 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1012 | /** |
| 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.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 1017 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 1018 | /** |
| 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.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1031 | |
| 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.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 1035 | * layout has no texture coordinates. Will be 0 if positions are |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 1036 | * used as texture coordinates for the stage. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1037 | */ |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 1038 | static int VertexStageCoordOffset(int stage, GrVertexLayout vertexLayout); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1039 | |
| 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.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 1047 | /** |
| 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.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 1054 | /** |
| 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.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1061 | /** |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 1062 | * Helper function to determine if vertex layout contains explicit texture |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 1063 | * coordinates of some index. |
| 1064 | * |
| 1065 | * @param coordIndex the tex coord index to query |
| 1066 | * @param vertexLayout layout to query |
| 1067 | * |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 1068 | * @return true if vertex specifies texture coordinates for the index, |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 1069 | * false otherwise. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1070 | */ |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 1071 | static bool VertexUsesTexCoordIdx(int coordIndex, |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 1072 | GrVertexLayout vertexLayout); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 1073 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1074 | /** |
| 1075 | * Helper function to determine if vertex layout contains either explicit or |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 1076 | * implicit texture coordinates for a stage. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1077 | * |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 1078 | * @param stage the stage to query |
| 1079 | * @param vertexLayout layout to query |
| 1080 | * |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 1081 | * @return true if vertex specifies texture coordinates for the stage, |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 1082 | * false otherwise. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1083 | */ |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 1084 | static bool VertexUsesStage(int stage, GrVertexLayout vertexLayout); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1085 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 1086 | /** |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 1087 | * 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.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 1090 | * 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.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 1095 | * 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.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 1107 | * @return size of a single vertex |
| 1108 | */ |
| 1109 | static int VertexSizeAndOffsetsByIdx(GrVertexLayout vertexLayout, |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 1110 | int texCoordOffsetsByIdx[GrDrawState::kMaxTexCoords], |
| 1111 | int *colorOffset, |
| 1112 | int *coverageOffset, |
| 1113 | int* edgeOffset); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 1114 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 1115 | /** |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 1116 | * 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.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 1120 | * 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.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 1125 | * 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.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 1138 | * @return size of a single vertex |
| 1139 | */ |
| 1140 | static int VertexSizeAndOffsetsByStage(GrVertexLayout vertexLayout, |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 1141 | int texCoordOffsetsByStage[GrDrawState::kNumStages], |
| 1142 | int* colorOffset, |
| 1143 | int* coverageOffset, |
| 1144 | int* edgeOffset); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 1145 | |
| 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.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1162 | static GrPoint* GetVertexPoint(void* vertices, |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 1163 | int vertexIndex, |
| 1164 | int vertexSize, |
| 1165 | int offset = 0) { |
| 1166 | intptr_t start = GrTCast<intptr_t>(vertices); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1167 | return GrTCast<GrPoint*>(start + offset + |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 1168 | vertexIndex * vertexSize); |
| 1169 | } |
| 1170 | static const GrPoint* GetVertexPoint(const void* vertices, |
| 1171 | int vertexIndex, |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1172 | int vertexSize, |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 1173 | int offset = 0) { |
| 1174 | intptr_t start = GrTCast<intptr_t>(vertices); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1175 | return GrTCast<const GrPoint*>(start + offset + |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 1176 | 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.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1187 | static GrColor* GetVertexColor(void* vertices, |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 1188 | int vertexIndex, |
| 1189 | int vertexSize, |
| 1190 | int offset) { |
| 1191 | intptr_t start = GrTCast<intptr_t>(vertices); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1192 | return GrTCast<GrColor*>(start + offset + |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 1193 | vertexIndex * vertexSize); |
| 1194 | } |
| 1195 | static const GrColor* GetVertexColor(const void* vertices, |
| 1196 | int vertexIndex, |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1197 | int vertexSize, |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 1198 | int offset) { |
| 1199 | const intptr_t start = GrTCast<intptr_t>(vertices); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1200 | return GrTCast<const GrColor*>(start + offset + |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 1201 | vertexIndex * vertexSize); |
| 1202 | } |
| 1203 | |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 1204 | static void VertexLayoutUnitTest(); |
| 1205 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1206 | protected: |
bsalomon@google.com | 471d471 | 2011-08-23 15:45:25 +0000 | [diff] [blame] | 1207 | |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 1208 | /** |
| 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.com | 471d471 | 2011-08-23 15:45:25 +0000 | [diff] [blame] | 1244 | |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 1245 | // 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.com | 471d471 | 2011-08-23 15:45:25 +0000 | [diff] [blame] | 1259 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 1260 | 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.com | a47a48d | 2011-04-26 20:22:11 +0000 | [diff] [blame] | 1287 | // given a vertex layout and a draw state, will a stage be used? |
| 1288 | static bool StageWillBeUsed(int stage, GrVertexLayout layout, |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 1289 | const GrDrawState& state) { |
bsalomon@google.com | a47a48d | 2011-04-26 20:22:11 +0000 | [diff] [blame] | 1290 | return NULL != state.fTextures[stage] && VertexUsesStage(stage, layout); |
| 1291 | } |
| 1292 | |
| 1293 | bool isStageEnabled(int stage) const { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 1294 | return StageWillBeUsed(stage, this->getGeomSrc().fVertexLayout, |
| 1295 | fCurrDrawState); |
bsalomon@google.com | a47a48d | 2011-04-26 20:22:11 +0000 | [diff] [blame] | 1296 | } |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 1297 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 1298 | StageBitfield enabledStages() const { |
| 1299 | StageBitfield mask = 0; |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 1300 | for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 1301 | mask |= this->isStageEnabled(s) ? 1 : 0; |
| 1302 | } |
| 1303 | return mask; |
| 1304 | } |
| 1305 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1306 | // Helpers for GrDrawTarget subclasses that won't have private access to |
| 1307 | // SavedDrawState but need to peek at the state values. |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 1308 | static GrDrawState& accessSavedDrawState(SavedDrawState& sds) |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1309 | { return sds.fState; } |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 1310 | static const GrDrawState& accessSavedDrawState(const SavedDrawState& sds) |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1311 | { return sds.fState; } |
| 1312 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 1313 | // 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.com | dea2f8d | 2011-08-01 15:51:05 +0000 | [diff] [blame] | 1342 | // subclass overrides to be notified when clip is set. Must call |
| 1343 | // INHERITED::clipwillBeSet |
| 1344 | virtual void clipWillBeSet(const GrClip& clip); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 1345 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 1346 | // Helpers for drawRect, protected so subclasses that override drawRect |
| 1347 | // can use them. |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 1348 | static GrVertexLayout GetRectVertexLayout(StageBitfield stageEnableBitfield, |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 1349 | const GrRect* srcRects[]); |
| 1350 | |
| 1351 | static void SetRectVertices(const GrRect& rect, |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1352 | const GrMatrix* matrix, |
| 1353 | const GrRect* srcRects[], |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 1354 | const GrMatrix* srcMatrices[], |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1355 | GrVertexLayout layout, |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 1356 | void* vertices); |
| 1357 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 1358 | // accessor for derived classes |
| 1359 | const GeometrySrcState& getGeomSrc() const { |
| 1360 | return fGeoSrcStateStack.back(); |
| 1361 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1362 | |
| 1363 | GrClip fClip; |
| 1364 | |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 1365 | GrDrawState fCurrDrawState; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1366 | |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 1367 | Caps fCaps; |
| 1368 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 1369 | private: |
| 1370 | // called when setting a new vert/idx source to unref prev vb/ib |
| 1371 | void releasePreviousVertexSource(); |
| 1372 | void releasePreviousIndexSource(); |
| 1373 | |
| 1374 | enum { |
| 1375 | kPreallocGeoSrcStateStackCnt = 4, |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1376 | }; |
bsalomon@google.com | 9266901 | 2011-09-27 19:10:05 +0000 | [diff] [blame] | 1377 | SkSTArray<kPreallocGeoSrcStateStackCnt, |
| 1378 | GeometrySrcState, true> fGeoSrcStateStack; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 1379 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1380 | }; |
| 1381 | |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 1382 | GR_MAKE_BITFIELD_OPS(GrDrawTarget::BlendOptFlags); |
| 1383 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1384 | #endif |