reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
| 2 | Copyright 2010 Google Inc. |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | |
| 18 | #ifndef GrDrawTarget_DEFINED |
| 19 | #define GrDrawTarget_DEFINED |
| 20 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 21 | #include "GrMatrix.h" |
| 22 | #include "GrColor.h" |
| 23 | #include "GrRefCnt.h" |
| 24 | #include "GrSamplerState.h" |
| 25 | #include "GrClip.h" |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame^] | 26 | #include "GrTexture.h" |
| 27 | #include "GrStencil.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 28 | |
| 29 | class GrTexture; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 30 | class GrClipIterator; |
| 31 | class GrVertexBuffer; |
| 32 | class GrIndexBuffer; |
| 33 | |
| 34 | class GrDrawTarget : public GrRefCnt { |
| 35 | public: |
| 36 | /** |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 37 | * Number of texture stages. Each stage takes as input a color and |
| 38 | * 2D texture coordinates. The color input to the first enabled stage is the |
| 39 | * per-vertex color or the constant color (setColor/setAlpha) if there are |
| 40 | * no per-vertex colors. For subsequent stages the input color is the output |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 41 | * color from the previous enabled stage. The output color of each stage is |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 42 | * the input color modulated with the result of a texture lookup. Texture |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 43 | * lookups are specified by a texture a sampler (setSamplerState). Texture |
| 44 | * coordinates for each stage come from the vertices based on a |
| 45 | * GrVertexLayout bitfield. The output fragment color is the output color of |
| 46 | * the last enabled stage. The presence or absence of texture coordinates |
| 47 | * for each stage in the vertex layout indicates whether a stage is enabled |
| 48 | * or not. |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 49 | */ |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 50 | enum { |
bsalomon@google.com | 7d34d2e | 2011-01-24 17:41:47 +0000 | [diff] [blame] | 51 | kNumStages = 2, |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 52 | kMaxTexCoords = kNumStages |
| 53 | }; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 54 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 55 | /** |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 56 | * Bitfield used to indicate which stages are in use. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 57 | */ |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 58 | typedef int StageBitfield; |
| 59 | GR_STATIC_ASSERT(sizeof(StageBitfield)*8 >= kNumStages); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 60 | |
| 61 | /** |
| 62 | * Flags that affect rendering. Controlled using enable/disableState(). All |
| 63 | * default to disabled. |
| 64 | */ |
| 65 | enum StateBits { |
| 66 | kDither_StateBit = 0x1,//<! Perform color dithering |
| 67 | kAntialias_StateBit = 0x2,//<! Perform anti-aliasing. The render- |
| 68 | // target must support some form of AA |
| 69 | // (msaa, coverage sampling, etc). For |
| 70 | // GrGpu-created rendertarget/textures |
| 71 | // this is controlled by parameters |
| 72 | // passed to createTexture. |
| 73 | kClip_StateBit = 0x4,//<! Controls whether drawing is clipped |
| 74 | // against the region specified by |
| 75 | // setClip. |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame^] | 76 | kNoColorWrites_StateBit = 0x8,//<! If set it disables writing colors. |
| 77 | // Useful while performing stencil ops. |
| 78 | |
| 79 | // subclass may use additional bits internally |
| 80 | kDummyStateBit, |
| 81 | kLastPublicStateBit = kDummyStateBit-1 |
| 82 | }; |
| 83 | |
| 84 | enum DrawFace { |
| 85 | kBoth_DrawFace, |
| 86 | kCCW_DrawFace, |
| 87 | kCW_DrawFace, |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | /** |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame^] | 91 | * The DrawTarget may reserve some of the high bits of the stencil. The draw |
| 92 | * target will automatically trim reference and mask values so that the |
| 93 | * client doesn't overwrite these bits. |
| 94 | * The number of bits available is relative to the currently set render |
| 95 | *target. |
| 96 | * @return the number of bits usable by the draw target client. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 97 | */ |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame^] | 98 | int getUsableStencilBits() const { |
| 99 | int bits = fCurrDrawState.fRenderTarget->stencilBits(); |
| 100 | if (bits) { |
| 101 | return bits - 1; |
| 102 | } else { |
| 103 | return 0; |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Sets the stencil settings to use for the next draw. |
| 109 | * @param settings the stencil settings to use. |
| 110 | */ |
| 111 | void setStencil(const GrStencilSettings& settings) { |
| 112 | fCurrDrawState.fStencilSettings = settings; |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Shortcut to disable stencil testing and ops. |
| 117 | */ |
| 118 | void disableStencil() { |
| 119 | fCurrDrawState.fStencilSettings.setDisabled(); |
| 120 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 121 | |
| 122 | protected: |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 123 | |
reed@google.com | 8195f67 | 2011-01-12 18:14:28 +0000 | [diff] [blame] | 124 | struct DrState { |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame^] | 125 | DrState() { |
| 126 | // make sure any pad is zero for memcmp |
| 127 | // all DrState members should default to something |
| 128 | // valid by the memset |
| 129 | memset(this, 0, sizeof(DrState)); |
| 130 | GrAssert((intptr_t)(void*)NULL == 0LL); |
| 131 | GrAssert(fStencilSettings.isDisabled()); |
| 132 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 133 | uint32_t fFlagBits; |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 134 | GrBlendCoeff fSrcBlend; |
| 135 | GrBlendCoeff fDstBlend; |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 136 | GrTexture* fTextures[kNumStages]; |
| 137 | GrSamplerState fSamplerStates[kNumStages]; |
| 138 | GrRenderTarget* fRenderTarget; |
| 139 | GrColor fColor; |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame^] | 140 | DrawFace fDrawFace; |
| 141 | |
| 142 | GrStencilSettings fStencilSettings; |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 143 | GrMatrix fViewMatrix; |
reed@google.com | 8195f67 | 2011-01-12 18:14:28 +0000 | [diff] [blame] | 144 | bool operator ==(const DrState& s) const { |
| 145 | return 0 == memcmp(this, &s, sizeof(DrState)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 146 | } |
reed@google.com | 8195f67 | 2011-01-12 18:14:28 +0000 | [diff] [blame] | 147 | bool operator !=(const DrState& s) const { return !(*this == s); } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 148 | }; |
| 149 | |
| 150 | public: |
| 151 | /////////////////////////////////////////////////////////////////////////// |
| 152 | |
| 153 | GrDrawTarget(); |
| 154 | |
| 155 | /** |
| 156 | * Sets the current clip to the region specified by clip. All draws will be |
| 157 | * clipped against this clip if kClip_StateBit is enabled. |
| 158 | * |
| 159 | * @param description of the clipping region |
| 160 | */ |
| 161 | void setClip(const GrClip& clip); |
| 162 | |
| 163 | /** |
| 164 | * Gets the current clip. |
| 165 | * |
| 166 | * @return the clip. |
| 167 | */ |
| 168 | const GrClip& getClip() const; |
| 169 | |
| 170 | /** |
| 171 | * Sets the texture used at the next drawing call |
| 172 | * |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 173 | * @param stage The texture stage for which the texture will be set |
| 174 | * |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 175 | * @param texture The texture to set. Can be NULL though there is no advantage |
| 176 | * to settings a NULL texture if doing non-textured drawing |
| 177 | */ |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 178 | void setTexture(int stage, GrTexture* texture); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 179 | |
| 180 | /** |
| 181 | * Retrieves the currently set texture. |
| 182 | * |
| 183 | * @return The currently set texture. The return value will be NULL if no |
| 184 | * texture has been set, NULL was most recently passed to |
| 185 | * setTexture, or the last setTexture was destroyed. |
| 186 | */ |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 187 | const GrTexture* getTexture(int stage) const; |
| 188 | GrTexture* getTexture(int stage); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 189 | |
| 190 | /** |
| 191 | * Sets the rendertarget used at the next drawing call |
| 192 | * |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 193 | * @param target The render target to set. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 194 | */ |
| 195 | void setRenderTarget(GrRenderTarget* target); |
| 196 | |
| 197 | /** |
| 198 | * Retrieves the currently set rendertarget. |
| 199 | * |
| 200 | * @return The currently set render target. |
| 201 | */ |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 202 | const GrRenderTarget* getRenderTarget() const; |
| 203 | GrRenderTarget* getRenderTarget(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 204 | |
| 205 | /** |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 206 | * Sets the sampler state for a stage used in subsequent draws. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 207 | * |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame^] | 208 | * The sampler state determines how texture coordinates are |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 209 | * intepretted and used to sample the texture. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 210 | * |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 211 | * @param stage the stage of the sampler to set |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 212 | * @param samplerState Specifies the sampler state. |
| 213 | */ |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 214 | void setSamplerState(int stage, const GrSamplerState& samplerState); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 215 | |
| 216 | /** |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 217 | * Concats the matrix of a stage's sampler. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 218 | * |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 219 | * @param stage the stage of the sampler to set |
| 220 | * @param matrix the matrix to concat |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 221 | */ |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 222 | void preConcatSamplerMatrix(int stage, const GrMatrix& matrix) { |
| 223 | GrAssert(stage >= 0 && stage < kNumStages); |
| 224 | fCurrDrawState.fSamplerStates[stage].preConcatMatrix(matrix); |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 225 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 226 | |
| 227 | /** |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 228 | * Gets the matrix of a stage's sampler |
bsalomon@google.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 229 | * |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 230 | * @param stage the stage to of sampler to get |
| 231 | * @return the sampler state's matrix |
bsalomon@google.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 232 | */ |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 233 | const GrMatrix& getSamplerMatrix(int stage) const { |
| 234 | return fCurrDrawState.fSamplerStates[stage].getMatrix(); |
| 235 | } |
bsalomon@google.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 236 | |
| 237 | /** |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 238 | * Sets the matrix of a stage's sampler |
| 239 | * |
| 240 | * @param stage the stage of sampler set |
| 241 | * @param matrix the matrix to set |
bsalomon@google.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 242 | */ |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 243 | const void setSamplerMatrix(int stage, const GrMatrix& matrix) { |
| 244 | fCurrDrawState.fSamplerStates[stage].setMatrix(matrix); |
| 245 | } |
bsalomon@google.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 246 | |
| 247 | /** |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 248 | * Sets the matrix applied to veretx positions. |
| 249 | * |
| 250 | * In the post-view-matrix space the rectangle [0,w]x[0,h] |
| 251 | * fully covers the render target. (w and h are the width and height of the |
| 252 | * the rendertarget.) |
| 253 | * |
| 254 | * @param m the matrix used to transform the vertex positions. |
| 255 | */ |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 256 | void setViewMatrix(const GrMatrix& m); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 257 | |
| 258 | /** |
| 259 | * Multiplies the current view matrix by a matrix |
| 260 | * |
| 261 | * After this call V' = V*m where V is the old view matrix, |
| 262 | * m is the parameter to this function, and V' is the new view matrix. |
| 263 | * (We consider positions to be column vectors so position vector p is |
| 264 | * transformed by matrix X as p' = X*p.) |
| 265 | * |
bsalomon@google.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 266 | * @param m the matrix used to modify the view matrix. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 267 | */ |
bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 268 | void preConcatViewMatrix(const GrMatrix& m); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 269 | |
| 270 | /** |
bsalomon@google.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 271 | * Retrieves the current view matrix |
| 272 | * @return the current view matrix. |
| 273 | */ |
| 274 | const GrMatrix& getViewMatrix() const; |
| 275 | |
| 276 | /** |
| 277 | * Retrieves the inverse of the current view matrix. |
| 278 | * |
| 279 | * If the current view matrix is invertible, return true, and if matrix |
| 280 | * is non-null, copy the inverse into it. If the current view matrix is |
| 281 | * non-invertible, return false and ignore the matrix parameter. |
| 282 | * |
| 283 | * @param matrix if not null, will receive a copy of the current inverse. |
| 284 | */ |
| 285 | bool getViewInverse(GrMatrix* matrix) const; |
| 286 | |
| 287 | /** |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 288 | * Sets color for next draw to a premultiplied-alpha color. |
| 289 | * |
| 290 | * @param the color to set. |
| 291 | */ |
| 292 | void setColor(GrColor); |
| 293 | |
| 294 | /** |
| 295 | * Sets the color to be used for the next draw to be |
| 296 | * (r,g,b,a) = (alpha, alpha, alpha, alpha). |
| 297 | * |
| 298 | * @param alpha The alpha value to set as the color. |
| 299 | */ |
| 300 | void setAlpha(uint8_t alpha); |
| 301 | |
| 302 | /** |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame^] | 303 | * Controls whether clockwise, counterclockwise, or both faces are drawn. |
| 304 | * @param face the face(s) to draw. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 305 | */ |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame^] | 306 | void setDrawFace(DrawFace face) { fCurrDrawState.fDrawFace = face; } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 307 | |
| 308 | /** |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame^] | 309 | * Gets whether the target is drawing clockwise, counterclockwise, |
| 310 | * or both faces. |
| 311 | * @return the current draw face(s). |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 312 | */ |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame^] | 313 | DrawFace getDrawFace() const { return fCurrDrawState.fDrawFace; } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 314 | |
| 315 | /** |
| 316 | * Enable render state settings. |
| 317 | * |
| 318 | * @param flags bitfield of StateBits specifing the states to enable |
| 319 | */ |
| 320 | void enableState(uint32_t stateBits); |
| 321 | |
| 322 | /** |
| 323 | * Disable render state settings. |
| 324 | * |
| 325 | * @param flags bitfield of StateBits specifing the states to disable |
| 326 | */ |
| 327 | void disableState(uint32_t stateBits); |
| 328 | |
| 329 | bool isDitherState() const { |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 330 | return 0 != (fCurrDrawState.fFlagBits & kDither_StateBit); |
| 331 | } |
| 332 | |
| 333 | bool isClipState() const { |
| 334 | return 0 != (fCurrDrawState.fFlagBits & kClip_StateBit); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 335 | } |
| 336 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame^] | 337 | bool isColorWriteDisabled() const { |
| 338 | return 0 != (fCurrDrawState.fFlagBits & kNoColorWrites_StateBit); |
| 339 | } |
| 340 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 341 | /** |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 342 | * Sets the blending function coeffecients. |
| 343 | * |
| 344 | * The blend function will be: |
| 345 | * D' = sat(S*srcCoef + D*dstCoef) |
| 346 | * |
| 347 | * where D is the existing destination color, S is the incoming source |
| 348 | * color, and D' is the new destination color that will be written. sat() |
| 349 | * is the saturation function. |
| 350 | * |
| 351 | * @param srcCoef coeffecient applied to the src color. |
| 352 | * @param dstCoef coeffecient applied to the dst color. |
| 353 | */ |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 354 | void setBlendFunc(GrBlendCoeff srcCoef, GrBlendCoeff dstCoef); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 355 | |
| 356 | /** |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 357 | * Used to save and restore the GrGpu's drawing state |
| 358 | */ |
| 359 | struct SavedDrawState { |
| 360 | private: |
reed@google.com | 8195f67 | 2011-01-12 18:14:28 +0000 | [diff] [blame] | 361 | DrState fState; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 362 | friend class GrDrawTarget; |
| 363 | }; |
| 364 | |
| 365 | /** |
| 366 | * Saves the current draw state. The state can be restored at a later time |
| 367 | * with restoreDrawState. |
| 368 | * |
| 369 | * See also AutoStateRestore class. |
| 370 | * |
| 371 | * @param state will hold the state after the function returns. |
| 372 | */ |
| 373 | void saveCurrentDrawState(SavedDrawState* state) const; |
| 374 | |
| 375 | /** |
| 376 | * Restores previously saved draw state. The client guarantees that state |
| 377 | * was previously passed to saveCurrentDrawState and that the rendertarget |
| 378 | * and texture set at save are still valid. |
| 379 | * |
| 380 | * See also AutoStateRestore class. |
| 381 | * |
| 382 | * @param state the previously saved state to restore. |
| 383 | */ |
| 384 | void restoreDrawState(const SavedDrawState& state); |
| 385 | |
| 386 | /** |
| 387 | * Copies the draw state from another target to this target. |
| 388 | * |
| 389 | * @param srcTarget draw target used as src of the draw state. |
| 390 | */ |
| 391 | void copyDrawState(const GrDrawTarget& srcTarget); |
| 392 | |
| 393 | /** |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 394 | * The format of vertices is represented as a bitfield of flags. |
| 395 | * Flags that indicate the layout of vertex data. Vertices always contain |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 396 | * positions and may also contain up to kMaxTexCoords sets of 2D texture |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 397 | * coordinates and per-vertex colors. Each stage can use any of the texture |
| 398 | * coordinates as its input texture coordinates or it may use the positions. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 399 | * |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 400 | * If no texture coordinates are specified for a stage then the stage is |
| 401 | * disabled. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 402 | * |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 403 | * Only one type of texture coord can be specified per stage. For |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 404 | * example StageTexCoordVertexLayoutBit(0, 2) and |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 405 | * StagePosAsTexCoordVertexLayoutBit(0) cannot both be specified. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 406 | * |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 407 | * The order in memory is always (position, texture coord 0, ..., color) |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 408 | * with any unused fields omitted. Note that this means that if only texture |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 409 | * coordinates 1 is referenced then there is no texture coordinates 0 and |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 410 | * the order would be (position, texture coordinate 1[, color]). |
| 411 | */ |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 412 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 413 | /** |
| 414 | * Generates a bit indicating that a texture stage uses texture coordinates |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 415 | * |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 416 | * @param stage the stage that will use texture coordinates. |
| 417 | * @param texCoordIdx the index of the texture coordinates to use |
| 418 | * |
| 419 | * @return the bit to add to a GrVertexLayout bitfield. |
| 420 | */ |
| 421 | static int StageTexCoordVertexLayoutBit(int stage, int texCoordIdx) { |
| 422 | GrAssert(stage < kNumStages); |
| 423 | GrAssert(texCoordIdx < kMaxTexCoords); |
| 424 | return 1 << (stage + (texCoordIdx * kNumStages)); |
| 425 | } |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 426 | |
| 427 | /** |
| 428 | * Determines if blend is effectively disabled. |
| 429 | * |
| 430 | * @return true if blend can be disabled without changing the rendering |
| 431 | * result given the current state including the vertex layout specified |
| 432 | * with the vertex source. |
| 433 | */ |
| 434 | bool canDisableBlend() const; |
| 435 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 436 | private: |
| 437 | static const int TEX_COORD_BIT_CNT = kNumStages*kMaxTexCoords; |
| 438 | public: |
| 439 | /** |
| 440 | * Generates a bit indicating that a texture stage uses the position |
| 441 | * as its texture coordinate. |
| 442 | * |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 443 | * @param stage the stage that will use position as texture |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 444 | * coordinates. |
| 445 | * |
| 446 | * @return the bit to add to a GrVertexLayout bitfield. |
| 447 | */ |
| 448 | static int StagePosAsTexCoordVertexLayoutBit(int stage) { |
| 449 | GrAssert(stage < kNumStages); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 450 | return (1 << (TEX_COORD_BIT_CNT + stage)); |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 451 | } |
| 452 | private: |
| 453 | static const int STAGE_BIT_CNT = TEX_COORD_BIT_CNT + kNumStages; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 454 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 455 | public: |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 456 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 457 | /** |
| 458 | * Additional Bits that can be specified in GrVertexLayout. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 459 | */ |
| 460 | enum VertexLayoutBits { |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 461 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 462 | kColor_VertexLayoutBit = 1 << (STAGE_BIT_CNT + 0), |
| 463 | //<! vertices have colors |
| 464 | kTextFormat_VertexLayoutBit = 1 << (STAGE_BIT_CNT + 1), |
| 465 | //<! use text vertices. (Pos |
| 466 | // and tex coords may be |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 467 | // a different type for |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 468 | // text [GrGpuTextVertex vs |
| 469 | // GrPoint].) |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 470 | // for below assert |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame^] | 471 | kDummyVertexLayoutBit, |
| 472 | kHighVertexLayoutBit = kDummyVertexLayoutBit - 1 |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 473 | }; |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 474 | // make sure we haven't exceeded the number of bits in GrVertexLayout. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 475 | GR_STATIC_ASSERT(kHighVertexLayoutBit < (1 << 8*sizeof(GrVertexLayout))); |
| 476 | |
| 477 | /** |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 478 | * There are three paths for specifying geometry (vertices and optionally |
| 479 | * indices) to the draw target. When indexed drawing the indices and vertices |
| 480 | * can be each use a different path. |
| 481 | * |
| 482 | * 1. Provide a cpu array (set*SourceToArray). This is useful when the |
| 483 | * caller's client has already provided vertex data in a format |
| 484 | * the time compatible with a GrVertexLayout. The array must contain the |
| 485 | * data at set*SourceToArray is called. The source stays in effect for |
| 486 | * drawIndexed & drawNonIndexed calls until set*SourceToArray is called |
| 487 | * again or one of the other two paths is chosen. |
| 488 | * |
| 489 | * 2. Reserve and Lock. This is most useful when the caller has data it must |
| 490 | * transform before drawing and will not likely render it again. The |
| 491 | * caller requests that the draw target make room for some amount of |
| 492 | * vertex and/or index data. The target provides ptrs to hold the data |
| 493 | * data. The caller can write the data into the pts up until the first |
| 494 | * drawIndexed or drawNonIndexed call. At this point the data is frozen |
| 495 | * and the ptrs are no longer guaranteed to be valid. All subsequent |
| 496 | * drawIndexed & drawNonIndexed calls will use this data until |
| 497 | * releaseReserved geometry is called. This must be called before another |
| 498 | * source is set. |
| 499 | * |
| 500 | * 3. Vertex and Index Buffers. This is most useful for geometry that will |
| 501 | * be rendered multiple times. SetVertexSourceToBuffer & |
| 502 | * SetIndexSourceToBuffer are used to set the buffer and subsequent |
| 503 | * drawIndexed and drawNonIndexed calls use this source until another |
| 504 | * source is set. |
| 505 | */ |
| 506 | |
| 507 | /** |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 508 | * Reserves space for vertices and/or indices. Draw target will use |
| 509 | * reserved vertices / indices at next draw. |
| 510 | * |
| 511 | * If succeeds: |
| 512 | * if vertexCount is nonzero, *vertices will be the array |
| 513 | * of vertices to be filled by caller. The next draw will read |
| 514 | * these vertices. |
| 515 | * |
| 516 | * if indecCount is nonzero, *indices will be the array of indices |
| 517 | * to be filled by caller. The next indexed draw will read from |
| 518 | * these indices. |
| 519 | * |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 520 | * If a client does not already have a vertex buffer then this is the |
| 521 | * preferred way to allocate vertex/index array. It allows the subclass of |
| 522 | * GrDrawTarget to decide whether to put data in buffers, to group vertex |
| 523 | * 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] | 524 | * |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 525 | * Following the first draw after reserveAndLockGeometry the ptrs returned |
| 526 | * by releaseReservedGeometry are no longer valid and the geometry data |
| 527 | * cannot be further modified. The contents that were put in the reserved |
| 528 | * space can be drawn by multiple draws, however. |
| 529 | * |
| 530 | * reserveAndLockGeometry must be matched with a releaseReservedGeometry |
| 531 | * call after all draws that reference the reserved geometry data have |
| 532 | * been called. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 533 | * |
| 534 | * AutoGeometryRelease can be used to automatically call the release. |
| 535 | * |
| 536 | * @param vertexCount the number of vertices to reserve space for. Can be 0. |
| 537 | * @param indexCount the number of indices to reserve space for. Can be 0. |
| 538 | * @param vertexLayout the format of vertices (ignored if vertexCount == 0). |
| 539 | * @param vertices will point to reserved vertex space if vertexCount is |
| 540 | * non-zero. Illegal to pass NULL if vertexCount > 0. |
| 541 | * @param indices will point to reserved index space if indexCount is |
| 542 | * non-zero. Illegal to pass NULL if indexCount > 0. |
| 543 | * |
| 544 | * @return true if succeeded in allocating space for the vertices and false |
| 545 | * if not. |
| 546 | */ |
| 547 | bool reserveAndLockGeometry(GrVertexLayout vertexLayout, |
| 548 | uint32_t vertexCount, |
| 549 | uint32_t indexCount, |
| 550 | void** vertices, |
| 551 | void** indices); |
| 552 | /** |
| 553 | * Provides hints to caller about the number of vertices and indices |
| 554 | * that can be allocated cheaply. This can be useful if caller is reserving |
| 555 | * space but doesn't know exactly how much geometry is needed. |
| 556 | * |
| 557 | * Also may hint whether the draw target should be flushed first. This is |
| 558 | * useful for deferred targets. |
| 559 | * |
| 560 | * @param vertexLayout layout of vertices caller would like to reserve |
| 561 | * @param vertexCount in: hint about how many vertices the caller would |
| 562 | * like to allocate. |
| 563 | * out: a hint about the number of vertices that can be |
| 564 | * allocated cheaply. Negative means no hint. |
| 565 | * Ignored if NULL. |
| 566 | * @param indexCount in: hint about how many indices the caller would |
| 567 | * like to allocate. |
| 568 | * out: a hint about the number of indices that can be |
| 569 | * allocated cheaply. Negative means no hint. |
| 570 | * Ignored if NULL. |
| 571 | * |
| 572 | * @return true if target should be flushed based on the input values. |
| 573 | */ |
| 574 | virtual bool geometryHints(GrVertexLayout vertexLayout, |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 575 | int* vertexCount, |
| 576 | int* indexCount) const; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 577 | |
| 578 | /** |
| 579 | * Releases reserved vertex/index data from reserveAndLockGeometry(). |
| 580 | */ |
| 581 | void releaseReservedGeometry(); |
| 582 | |
| 583 | /** |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 584 | * Sets source of vertex data for the next draw. Array must contain |
| 585 | * the vertex data when this is called. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 586 | * |
| 587 | * @param array cpu array containing vertex data. |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 588 | * @param size size of the vertex data. |
| 589 | * @param vertexCount the number of vertices in the array. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 590 | */ |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 591 | void setVertexSourceToArray(GrVertexLayout vertexLayout, |
| 592 | const void* vertexArray, |
| 593 | int vertexCount); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 594 | |
| 595 | /** |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 596 | * Sets source of index data for the next indexed draw. Array must contain |
| 597 | * the indices when this is called. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 598 | * |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 599 | * @param array cpu array containing index data. |
| 600 | * @param indexCount the number of indices in the array. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 601 | */ |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 602 | void setIndexSourceToArray(const void* indexArray, int indexCount); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 603 | |
| 604 | /** |
| 605 | * Sets source of vertex data for the next draw. Data does not have to be |
| 606 | * in the buffer until drawIndexed or drawNonIndexed. |
| 607 | * |
| 608 | * @param buffer vertex buffer containing vertex data. Must be |
| 609 | * unlocked before draw call. |
| 610 | * @param vertexLayout layout of the vertex data in the buffer. |
| 611 | */ |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 612 | void setVertexSourceToBuffer(GrVertexLayout vertexLayout, |
| 613 | const GrVertexBuffer* buffer); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 614 | |
| 615 | /** |
| 616 | * Sets source of index data for the next indexed draw. Data does not have |
| 617 | * to be in the buffer until drawIndexed or drawNonIndexed. |
| 618 | * |
| 619 | * @param buffer index buffer containing indices. Must be unlocked |
| 620 | * before indexed draw call. |
| 621 | */ |
| 622 | void setIndexSourceToBuffer(const GrIndexBuffer* buffer); |
| 623 | |
| 624 | /** |
| 625 | * Draws indexed geometry using the current state and current vertex / index |
| 626 | * sources. |
| 627 | * |
| 628 | * @param type The type of primitives to draw. |
| 629 | * @param startVertex the vertex in the vertex array/buffer corresponding |
| 630 | * to index 0 |
| 631 | * @param startIndex first index to read from index src. |
| 632 | * @param vertexCount one greater than the max index. |
| 633 | * @param indexCount the number of index elements to read. The index count |
| 634 | * is effectively trimmed to the last completely |
| 635 | * specified primitive. |
| 636 | */ |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 637 | virtual void drawIndexed(GrPrimitiveType type, |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 638 | int startVertex, |
| 639 | int startIndex, |
| 640 | int vertexCount, |
| 641 | int indexCount) = 0; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 642 | |
| 643 | /** |
| 644 | * Draws non-indexed geometry using the current state and current vertex |
| 645 | * sources. |
| 646 | * |
| 647 | * @param type The type of primitives to draw. |
| 648 | * @param startVertex the vertex in the vertex array/buffer corresponding |
| 649 | * to index 0 |
| 650 | * @param vertexCount one greater than the max index. |
| 651 | */ |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 652 | virtual void drawNonIndexed(GrPrimitiveType type, |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 653 | int startVertex, |
| 654 | int vertexCount) = 0; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 655 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 656 | /** |
| 657 | * Helper function for drawing rects. This does not use the current index |
| 658 | * and vertex sources. After returning, the vertex and index sources may |
| 659 | * have changed. They should be reestablished before the next drawIndexed |
| 660 | * or drawNonIndexed. This cannot be called between reserving and releasing |
| 661 | * geometry. The GrDrawTarget subclass may be able to perform additional |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame^] | 662 | * optimizations if drawRect is used rather than drawIndexed or |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 663 | * drawNonIndexed. |
| 664 | * @param rect the rect to draw |
| 665 | * @param matrix optional matrix applied to rect (before viewMatrix) |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 666 | * @param stageEnableBitfield bitmask indicating which stages are enabled. |
| 667 | * Bit i indicates whether stage i is enabled. |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 668 | * @param srcRects specifies rects for stages enabled by stageEnableMask. |
| 669 | * if stageEnableMask bit i is 1, srcRects is not NULL, |
| 670 | * and srcRects[i] is not NULL, then srcRects[i] will be |
| 671 | * used as coordinates for stage i. Otherwise, if stage i |
| 672 | * is enabled then rect is used as the coordinates. |
| 673 | * @param srcMatrices optional matrices applied to srcRects. If |
| 674 | * srcRect[i] is non-NULL and srcMatrices[i] is |
| 675 | * non-NULL then srcRect[i] will be transformed by |
| 676 | * srcMatrix[i]. srcMatrices can be NULL when no |
| 677 | * srcMatrices are desired. |
| 678 | */ |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame^] | 679 | virtual void drawRect(const GrRect& rect, |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 680 | const GrMatrix* matrix, |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 681 | StageBitfield stageEnableBitfield, |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 682 | const GrRect* srcRects[], |
| 683 | const GrMatrix* srcMatrices[]); |
| 684 | |
| 685 | /** |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame^] | 686 | * 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] | 687 | * matrices. |
| 688 | */ |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame^] | 689 | void drawSimpleRect(const GrRect& rect, |
| 690 | const GrMatrix* matrix, |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 691 | StageBitfield stageEnableBitfield) { |
| 692 | drawRect(rect, matrix, stageEnableBitfield, NULL, NULL); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 693 | } |
| 694 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 695 | /////////////////////////////////////////////////////////////////////////// |
| 696 | |
| 697 | class AutoStateRestore : ::GrNoncopyable { |
| 698 | public: |
| 699 | AutoStateRestore(GrDrawTarget* target); |
| 700 | ~AutoStateRestore(); |
| 701 | |
| 702 | private: |
| 703 | GrDrawTarget* fDrawTarget; |
| 704 | SavedDrawState fDrawState; |
| 705 | }; |
| 706 | |
| 707 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 708 | |
bsalomon@google.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 709 | class AutoViewMatrixRestore : ::GrNoncopyable { |
| 710 | public: |
| 711 | AutoViewMatrixRestore() { |
| 712 | fDrawTarget = NULL; |
| 713 | } |
| 714 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 715 | AutoViewMatrixRestore(GrDrawTarget* target) |
bsalomon@google.com | 6f7fbc9 | 2011-02-01 19:12:40 +0000 | [diff] [blame] | 716 | : fDrawTarget(target), fMatrix(fDrawTarget->getViewMatrix()) { |
| 717 | GrAssert(NULL != target); |
| 718 | } |
| 719 | |
| 720 | void set(GrDrawTarget* target) { |
| 721 | GrAssert(NULL != target); |
| 722 | if (NULL != fDrawTarget) { |
| 723 | fDrawTarget->setViewMatrix(fMatrix); |
| 724 | } |
| 725 | fDrawTarget = target; |
| 726 | fMatrix = target->getViewMatrix(); |
| 727 | } |
| 728 | |
| 729 | ~AutoViewMatrixRestore() { |
| 730 | if (NULL != fDrawTarget) { |
| 731 | fDrawTarget->setViewMatrix(fMatrix); |
| 732 | } |
| 733 | } |
| 734 | |
| 735 | private: |
| 736 | GrDrawTarget* fDrawTarget; |
| 737 | GrMatrix fMatrix; |
| 738 | }; |
| 739 | |
| 740 | /////////////////////////////////////////////////////////////////////////// |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 741 | |
| 742 | class AutoReleaseGeometry : ::GrNoncopyable { |
| 743 | public: |
| 744 | AutoReleaseGeometry(GrDrawTarget* target, |
| 745 | GrVertexLayout vertexLayout, |
| 746 | uint32_t vertexCount, |
| 747 | uint32_t indexCount) { |
| 748 | fTarget = target; |
| 749 | fSuccess = fTarget->reserveAndLockGeometry(vertexLayout, |
| 750 | vertexCount, |
| 751 | indexCount, |
| 752 | &fVertices, |
| 753 | &fIndices); |
| 754 | } |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 755 | |
| 756 | AutoReleaseGeometry() { |
| 757 | fSuccess = false; |
| 758 | } |
| 759 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 760 | ~AutoReleaseGeometry() { |
| 761 | if (fSuccess) { |
| 762 | fTarget->releaseReservedGeometry(); |
| 763 | } |
| 764 | } |
| 765 | |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 766 | bool set(GrDrawTarget* target, |
| 767 | GrVertexLayout vertexLayout, |
| 768 | uint32_t vertexCount, |
| 769 | uint32_t indexCount) { |
| 770 | if (fSuccess) { |
| 771 | fTarget->releaseReservedGeometry(); |
| 772 | } |
| 773 | fTarget = target; |
| 774 | fSuccess = fTarget->reserveAndLockGeometry(vertexLayout, |
| 775 | vertexCount, |
| 776 | indexCount, |
| 777 | &fVertices, |
| 778 | &fIndices); |
| 779 | return fSuccess; |
| 780 | } |
| 781 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 782 | bool succeeded() const { return fSuccess; } |
| 783 | void* vertices() const { return fVertices; } |
| 784 | void* indices() const { return fIndices; } |
| 785 | |
| 786 | GrPoint* positions() const { |
| 787 | return static_cast<GrPoint*>(fVertices); |
| 788 | } |
| 789 | |
| 790 | private: |
| 791 | GrDrawTarget* fTarget; |
| 792 | bool fSuccess; |
| 793 | void* fVertices; |
| 794 | void* fIndices; |
| 795 | }; |
| 796 | |
| 797 | /////////////////////////////////////////////////////////////////////////// |
| 798 | |
| 799 | class AutoClipRestore : ::GrNoncopyable { |
| 800 | public: |
| 801 | AutoClipRestore(GrDrawTarget* target) { |
| 802 | fTarget = target; |
| 803 | fClip = fTarget->getClip(); |
| 804 | } |
| 805 | |
| 806 | ~AutoClipRestore() { |
| 807 | fTarget->setClip(fClip); |
| 808 | } |
| 809 | private: |
| 810 | GrDrawTarget* fTarget; |
| 811 | GrClip fClip; |
| 812 | }; |
| 813 | |
| 814 | //////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 815 | // Helpers for picking apart vertex layouts |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 816 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 817 | /** |
| 818 | * Helper function to compute the size of a vertex from a vertex layout |
| 819 | * @return size of a single vertex. |
| 820 | */ |
| 821 | static size_t VertexSize(GrVertexLayout vertexLayout); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 822 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 823 | /** |
| 824 | * Helper function for determining the index of texture coordinates that |
| 825 | * is input for a texture stage. Note that a stage may instead use positions |
| 826 | * as texture coordinates, in which case the result of the function is |
| 827 | * indistinguishable from the case when the stage is disabled. |
| 828 | * |
| 829 | * @param stage the stage to query |
| 830 | * @param vertexLayout layout to query |
| 831 | * |
| 832 | * @return the texture coordinate index or -1 if the stage doesn't use |
| 833 | * separate (non-position) texture coordinates. |
| 834 | */ |
| 835 | static int VertexTexCoordsForStage(int stage, GrVertexLayout vertexLayout); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 836 | |
| 837 | /** |
| 838 | * Helper function to compute the offset of texture coordinates in a vertex |
| 839 | * @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] | 840 | * layout has no texture coordinates. Will be 0 if positions are |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 841 | * used as texture coordinates for the stage. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 842 | */ |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 843 | static int VertexStageCoordOffset(int stage, GrVertexLayout vertexLayout); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 844 | |
| 845 | /** |
| 846 | * Helper function to compute the offset of the color in a vertex |
| 847 | * @return offset of color in vertex layout or -1 if the |
| 848 | * layout has no color. |
| 849 | */ |
| 850 | static int VertexColorOffset(GrVertexLayout vertexLayout); |
| 851 | |
| 852 | /** |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 853 | * Helper function to determine if vertex layout contains explicit texture |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 854 | * coordinates of some index. |
| 855 | * |
| 856 | * @param coordIndex the tex coord index to query |
| 857 | * @param vertexLayout layout to query |
| 858 | * |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 859 | * @return true if vertex specifies texture coordinates for the index, |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 860 | * false otherwise. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 861 | */ |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 862 | static bool VertexUsesTexCoordIdx(int coordIndex, |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 863 | GrVertexLayout vertexLayout); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 864 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 865 | /** |
| 866 | * Helper function to determine if vertex layout contains either explicit or |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 867 | * implicit texture coordinates for a stage. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 868 | * |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 869 | * @param stage the stage to query |
| 870 | * @param vertexLayout layout to query |
| 871 | * |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 872 | * @return true if vertex specifies texture coordinates for the stage, |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 873 | * false otherwise. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 874 | */ |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 875 | static bool VertexUsesStage(int stage, GrVertexLayout vertexLayout); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 876 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 877 | /** |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 878 | * Helper function to compute the size of each vertex and the offsets of |
| 879 | * texture coordinates and color. Determines tex coord offsets by tex coord |
| 880 | * 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] | 881 | * by StageTexCoordVertexLayoutBit.) |
| 882 | * |
| 883 | * @param vertexLayout the layout to query |
| 884 | * @param texCoordOffsetsByIdx after return it is the offset of each |
| 885 | * tex coord index in the vertex or -1 if |
| 886 | * index isn't used. |
| 887 | * @return size of a single vertex |
| 888 | */ |
| 889 | static int VertexSizeAndOffsetsByIdx(GrVertexLayout vertexLayout, |
| 890 | int texCoordOffsetsByIdx[kMaxTexCoords], |
| 891 | int *colorOffset); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 892 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 893 | /** |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 894 | * Helper function to compute the size of each vertex and the offsets of |
| 895 | * texture coordinates and color. Determines tex coord offsets by stage |
| 896 | * rather than by index. (Each stage can be mapped to any t.c. index |
| 897 | * by StageTexCoordVertexLayoutBit.) If a stage uses positions for |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 898 | * tex coords then that stage's offset will be 0 (positions are always at 0). |
| 899 | * |
| 900 | * @param vertexLayout the layout to query |
| 901 | * @param texCoordOffsetsByStage after return it is the offset of each |
| 902 | * tex coord index in the vertex or -1 if |
| 903 | * index isn't used. |
| 904 | * @return size of a single vertex |
| 905 | */ |
| 906 | static int VertexSizeAndOffsetsByStage(GrVertexLayout vertexLayout, |
| 907 | int texCoordOffsetsByStage[kNumStages], |
| 908 | int *colorOffset); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 909 | |
| 910 | /** |
| 911 | * Accessing positions, texture coords, or colors, of a vertex within an |
| 912 | * array is a hassle involving casts and simple math. These helpers exist |
| 913 | * to keep GrDrawTarget clients' code a bit nicer looking. |
| 914 | */ |
| 915 | |
| 916 | /** |
| 917 | * Gets a pointer to a GrPoint of a vertex's position or texture |
| 918 | * coordinate. |
| 919 | * @param vertices the vetex array |
| 920 | * @param vertexIndex the index of the vertex in the array |
| 921 | * @param vertexSize the size of each vertex in the array |
| 922 | * @param offset the offset in bytes of the vertex component. |
| 923 | * Defaults to zero (corresponding to vertex position) |
| 924 | * @return pointer to the vertex component as a GrPoint |
| 925 | */ |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame^] | 926 | static GrPoint* GetVertexPoint(void* vertices, |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 927 | int vertexIndex, |
| 928 | int vertexSize, |
| 929 | int offset = 0) { |
| 930 | intptr_t start = GrTCast<intptr_t>(vertices); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame^] | 931 | return GrTCast<GrPoint*>(start + offset + |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 932 | vertexIndex * vertexSize); |
| 933 | } |
| 934 | static const GrPoint* GetVertexPoint(const void* vertices, |
| 935 | int vertexIndex, |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame^] | 936 | int vertexSize, |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 937 | int offset = 0) { |
| 938 | intptr_t start = GrTCast<intptr_t>(vertices); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame^] | 939 | return GrTCast<const GrPoint*>(start + offset + |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 940 | vertexIndex * vertexSize); |
| 941 | } |
| 942 | |
| 943 | /** |
| 944 | * Gets a pointer to a GrColor inside a vertex within a vertex array. |
| 945 | * @param vertices the vetex array |
| 946 | * @param vertexIndex the index of the vertex in the array |
| 947 | * @param vertexSize the size of each vertex in the array |
| 948 | * @param offset the offset in bytes of the vertex color |
| 949 | * @return pointer to the vertex component as a GrColor |
| 950 | */ |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame^] | 951 | static GrColor* GetVertexColor(void* vertices, |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 952 | int vertexIndex, |
| 953 | int vertexSize, |
| 954 | int offset) { |
| 955 | intptr_t start = GrTCast<intptr_t>(vertices); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame^] | 956 | return GrTCast<GrColor*>(start + offset + |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 957 | vertexIndex * vertexSize); |
| 958 | } |
| 959 | static const GrColor* GetVertexColor(const void* vertices, |
| 960 | int vertexIndex, |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame^] | 961 | int vertexSize, |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 962 | int offset) { |
| 963 | const intptr_t start = GrTCast<intptr_t>(vertices); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame^] | 964 | return GrTCast<const GrColor*>(start + offset + |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 965 | vertexIndex * vertexSize); |
| 966 | } |
| 967 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 968 | protected: |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 969 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 970 | // Helpers for GrDrawTarget subclasses that won't have private access to |
| 971 | // SavedDrawState but need to peek at the state values. |
reed@google.com | 8195f67 | 2011-01-12 18:14:28 +0000 | [diff] [blame] | 972 | static DrState& accessSavedDrawState(SavedDrawState& sds) |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 973 | { return sds.fState; } |
reed@google.com | 8195f67 | 2011-01-12 18:14:28 +0000 | [diff] [blame] | 974 | static const DrState& accessSavedDrawState(const SavedDrawState& sds) |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 975 | { return sds.fState; } |
| 976 | |
| 977 | // implemented by subclass |
| 978 | virtual bool acquireGeometryHelper(GrVertexLayout vertexLayout, |
| 979 | void** vertices, |
| 980 | void** indices) = 0; |
| 981 | |
| 982 | virtual void releaseGeometryHelper() = 0; |
| 983 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 984 | // subclass overrides to be notified when clip is set. |
| 985 | virtual void clipWillBeSet(const GrClip& clip) = 0; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 986 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 987 | virtual void setVertexSourceToArrayHelper(const void* vertexArray, |
| 988 | int vertexCount) = 0; |
| 989 | |
| 990 | virtual void setIndexSourceToArrayHelper(const void* indexArray, |
| 991 | int indexCount) = 0; |
| 992 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 993 | // Helpers for drawRect, protected so subclasses that override drawRect |
| 994 | // can use them. |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 995 | static GrVertexLayout GetRectVertexLayout(StageBitfield stageEnableBitfield, |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 996 | const GrRect* srcRects[]); |
| 997 | |
| 998 | static void SetRectVertices(const GrRect& rect, |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame^] | 999 | const GrMatrix* matrix, |
| 1000 | const GrRect* srcRects[], |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 1001 | const GrMatrix* srcMatrices[], |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame^] | 1002 | GrVertexLayout layout, |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 1003 | void* vertices); |
| 1004 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1005 | enum GeometrySrcType { |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 1006 | kReserved_GeometrySrcType, // src was set using reserveAndLockGeometry |
| 1007 | kArray_GeometrySrcType, // src was set using set*SourceToArray |
| 1008 | kBuffer_GeometrySrcType // src was set using set*SourceToBuffer |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1009 | }; |
| 1010 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame^] | 1011 | struct ReservedGeometry { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1012 | bool fLocked; |
| 1013 | uint32_t fVertexCount; |
| 1014 | uint32_t fIndexCount; |
| 1015 | } fReservedGeometry; |
| 1016 | |
| 1017 | struct GeometrySrc { |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 1018 | GeometrySrcType fVertexSrc; |
| 1019 | const GrVertexBuffer* fVertexBuffer; // valid if src type is buffer |
| 1020 | GeometrySrcType fIndexSrc; |
| 1021 | const GrIndexBuffer* fIndexBuffer; // valid if src type is buffer |
| 1022 | GrVertexLayout fVertexLayout; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1023 | } fGeometrySrc; |
| 1024 | |
| 1025 | GrClip fClip; |
| 1026 | |
reed@google.com | 8195f67 | 2011-01-12 18:14:28 +0000 | [diff] [blame] | 1027 | DrState fCurrDrawState; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1028 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 1029 | // Not meant for external use. Only setVertexSourceToBuffer and |
| 1030 | // setIndexSourceToBuffer will work since GrDrawTarget subclasses don't |
| 1031 | // support nested reserveAndLockGeometry (and cpu arrays internally use the |
| 1032 | // same path). |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1033 | class AutoGeometrySrcRestore { |
| 1034 | public: |
| 1035 | AutoGeometrySrcRestore(GrDrawTarget* target) { |
| 1036 | fTarget = target; |
| 1037 | fGeometrySrc = fTarget->fGeometrySrc; |
| 1038 | } |
| 1039 | ~AutoGeometrySrcRestore() { |
| 1040 | fTarget->fGeometrySrc = fGeometrySrc; |
| 1041 | } |
| 1042 | private: |
| 1043 | GrDrawTarget *fTarget; |
| 1044 | GeometrySrc fGeometrySrc; |
| 1045 | |
| 1046 | AutoGeometrySrcRestore(); |
| 1047 | AutoGeometrySrcRestore(const AutoGeometrySrcRestore&); |
| 1048 | AutoGeometrySrcRestore& operator =(AutoGeometrySrcRestore&); |
| 1049 | }; |
| 1050 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 1051 | private: |
| 1052 | void VertexLayoutUnitTest(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1053 | }; |
| 1054 | |
| 1055 | #endif |