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" |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 19 | #include "GrSamplerState.h" |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 20 | #include "GrStencil.h" |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 21 | #include "GrTexture.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 22 | |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 23 | #include "SkXfermode.h" |
bsalomon@google.com | 46f7afb | 2012-01-18 19:51:55 +0000 | [diff] [blame^] | 24 | #include "SkTLazy.h" |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 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; |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 45 | bool fNPOTTextureTileSupport : 1; |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 46 | bool fTwoSidedStencilSupport : 1; |
| 47 | bool fStencilWrapOpsSupport : 1; |
| 48 | bool fHWAALineSupport : 1; |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 49 | bool fShaderDerivativeSupport : 1; |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 50 | bool fGeometryShaderSupport : 1; |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 51 | bool fFSAASupport : 1; |
| 52 | bool fDualSourceBlendingSupport : 1; |
| 53 | bool fBufferLockSupport : 1; |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 54 | int fMaxRenderTargetSize; |
| 55 | int fMaxTextureSize; |
| 56 | }; |
| 57 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 58 | // for convenience |
bsalomon@google.com | 39ee0ff | 2011-12-06 15:32:52 +0000 | [diff] [blame] | 59 | typedef GrDrawState::StageMask StageMask; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 60 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 61 | /////////////////////////////////////////////////////////////////////////// |
| 62 | |
| 63 | GrDrawTarget(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 64 | virtual ~GrDrawTarget(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 65 | |
| 66 | /** |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 67 | * Gets the capabilities of the draw target. |
| 68 | */ |
| 69 | const Caps& getCaps() const { return fCaps; } |
| 70 | |
| 71 | /** |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 72 | * Sets the current clip to the region specified by clip. All draws will be |
| 73 | * clipped against this clip if kClip_StateBit is enabled. |
| 74 | * |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 75 | * Setting the clip may (or may not) zero out the client's stencil bits. |
| 76 | * |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 77 | * @param description of the clipping region |
| 78 | */ |
| 79 | void setClip(const GrClip& clip); |
| 80 | |
| 81 | /** |
| 82 | * Gets the current clip. |
| 83 | * |
| 84 | * @return the clip. |
| 85 | */ |
| 86 | const GrClip& getClip() const; |
| 87 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 88 | const GrDrawState& getDrawState() const { return fCurrDrawState; } |
| 89 | GrDrawState* drawState() { return &fCurrDrawState; } |
bsalomon@google.com | 3d0835b | 2011-12-08 16:12:03 +0000 | [diff] [blame] | 90 | |
bsalomon@google.com | 3d0835b | 2011-12-08 16:12:03 +0000 | [diff] [blame] | 91 | /** |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 92 | * Shortcut for drawState()->preConcatSamplerMatrices() on all enabled |
| 93 | * stages |
bsalomon@google.com | 3d0835b | 2011-12-08 16:12:03 +0000 | [diff] [blame] | 94 | * |
bsalomon@google.com | 3d0835b | 2011-12-08 16:12:03 +0000 | [diff] [blame] | 95 | * @param matrix the matrix to concat |
| 96 | */ |
| 97 | void preConcatEnabledSamplerMatrices(const GrMatrix& matrix) { |
| 98 | StageMask stageMask = this->enabledStages(); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 99 | this->drawState()->preConcatSamplerMatrices(stageMask, matrix); |
bsalomon@google.com | 3d0835b | 2011-12-08 16:12:03 +0000 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | /** |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 103 | * Determines if blending will require a read of a dst given the current |
| 104 | * state set on the draw target |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 105 | * |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 106 | * @return true if the dst surface will be read at each pixel hit by the |
| 107 | * a draw operation. |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 108 | */ |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 109 | bool drawWillReadDst() const; |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 110 | |
bsalomon@google.com | d46e242 | 2011-09-23 17:40:07 +0000 | [diff] [blame] | 111 | /** |
| 112 | * Color alpha and coverage are two inputs to the drawing pipeline. For some |
| 113 | * blend modes it is safe to fold the coverage into constant or per-vertex |
| 114 | * color alpha value. For other blend modes they must be handled separately. |
| 115 | * Depending on features available in the underlying 3D API this may or may |
| 116 | * not be possible. |
| 117 | * |
| 118 | * This function looks at the current blend on the draw target and the draw |
| 119 | * target's capabilities to determine whether coverage can be handled |
| 120 | * correctly. |
| 121 | */ |
| 122 | bool canApplyCoverage() const; |
| 123 | |
| 124 | /** |
| 125 | * Determines whether incorporating partial pixel coverage into the constant |
| 126 | * color specified by setColor or per-vertex colors will give the right |
| 127 | * blending result. |
| 128 | */ |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 129 | bool canTweakAlphaForCoverage() const; |
bsalomon@google.com | d46e242 | 2011-09-23 17:40:07 +0000 | [diff] [blame] | 130 | |
senorblanco@chromium.org | 92e0f22 | 2011-05-12 15:49:15 +0000 | [diff] [blame] | 131 | /** |
bsalomon@google.com | 471d471 | 2011-08-23 15:45:25 +0000 | [diff] [blame] | 132 | * Given the current draw state, vertex layout, and hw support, will HW AA |
| 133 | * lines be used (if line primitive type is drawn)? (Note that lines are |
| 134 | * always 1 pixel wide) |
| 135 | */ |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 136 | bool willUseHWAALines() const; |
bsalomon@google.com | 471d471 | 2011-08-23 15:45:25 +0000 | [diff] [blame] | 137 | |
bsalomon@google.com | 3d0835b | 2011-12-08 16:12:03 +0000 | [diff] [blame] | 138 | /** |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 139 | * Used to save and restore the GrGpu's drawing state |
| 140 | */ |
| 141 | struct SavedDrawState { |
| 142 | private: |
bsalomon@google.com | 46f7afb | 2012-01-18 19:51:55 +0000 | [diff] [blame^] | 143 | SkTLazy<GrDrawState> fState; |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 144 | friend class GrDrawTarget; |
| 145 | }; |
| 146 | |
| 147 | /** |
| 148 | * Saves the current draw state. The state can be restored at a later time |
| 149 | * with restoreDrawState. |
| 150 | * |
| 151 | * See also AutoStateRestore class. |
| 152 | * |
| 153 | * @param state will hold the state after the function returns. |
| 154 | */ |
| 155 | void saveCurrentDrawState(SavedDrawState* state) const; |
| 156 | |
| 157 | /** |
| 158 | * Restores previously saved draw state. The client guarantees that state |
| 159 | * was previously passed to saveCurrentDrawState and that the rendertarget |
| 160 | * and texture set at save are still valid. |
| 161 | * |
| 162 | * See also AutoStateRestore class. |
| 163 | * |
| 164 | * @param state the previously saved state to restore. |
| 165 | */ |
| 166 | void restoreDrawState(const SavedDrawState& state); |
| 167 | |
| 168 | /** |
| 169 | * Copies the draw state from another target to this target. |
| 170 | * |
| 171 | * @param srcTarget draw target used as src of the draw state. |
| 172 | */ |
| 173 | void copyDrawState(const GrDrawTarget& srcTarget); |
| 174 | |
| 175 | /** |
| 176 | * The format of vertices is represented as a bitfield of flags. |
| 177 | * Flags that indicate the layout of vertex data. Vertices always contain |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 178 | * positions and may also contain up to GrDrawState::kMaxTexCoords sets |
| 179 | * of 2D texture * coordinates, per-vertex colors, and per-vertex coverage. |
| 180 | * Each stage can |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 181 | * use any of the texture coordinates as its input texture coordinates or it |
| 182 | * may use the positions as texture coordinates. |
| 183 | * |
| 184 | * If no texture coordinates are specified for a stage then the stage is |
| 185 | * disabled. |
| 186 | * |
| 187 | * Only one type of texture coord can be specified per stage. For |
| 188 | * example StageTexCoordVertexLayoutBit(0, 2) and |
| 189 | * StagePosAsTexCoordVertexLayoutBit(0) cannot both be specified. |
| 190 | * |
| 191 | * The order in memory is always (position, texture coord 0, ..., color, |
| 192 | * coverage) with any unused fields omitted. Note that this means that if |
| 193 | * only texture coordinates 1 is referenced then there is no texture |
| 194 | * coordinates 0 and the order would be (position, texture coordinate 1 |
| 195 | * [, color][, coverage]). |
| 196 | */ |
| 197 | |
| 198 | /** |
| 199 | * Generates a bit indicating that a texture stage uses texture coordinates |
| 200 | * |
| 201 | * @param stage the stage that will use texture coordinates. |
| 202 | * @param texCoordIdx the index of the texture coordinates to use |
| 203 | * |
| 204 | * @return the bit to add to a GrVertexLayout bitfield. |
| 205 | */ |
| 206 | static int StageTexCoordVertexLayoutBit(int stage, int texCoordIdx) { |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 207 | GrAssert(stage < GrDrawState::kNumStages); |
| 208 | GrAssert(texCoordIdx < GrDrawState::kMaxTexCoords); |
| 209 | return 1 << (stage + (texCoordIdx * GrDrawState::kNumStages)); |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 210 | } |
| 211 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 212 | private: |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 213 | static const int TEX_COORD_BIT_CNT = GrDrawState::kNumStages * |
| 214 | GrDrawState::kMaxTexCoords; |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 215 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 216 | public: |
| 217 | /** |
| 218 | * Generates a bit indicating that a texture stage uses the position |
| 219 | * as its texture coordinate. |
| 220 | * |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 221 | * @param stage the stage that will use position as texture |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 222 | * coordinates. |
| 223 | * |
| 224 | * @return the bit to add to a GrVertexLayout bitfield. |
| 225 | */ |
| 226 | static int StagePosAsTexCoordVertexLayoutBit(int stage) { |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 227 | GrAssert(stage < GrDrawState::kNumStages); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 228 | return (1 << (TEX_COORD_BIT_CNT + stage)); |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 229 | } |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 230 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 231 | private: |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 232 | static const int STAGE_BIT_CNT = TEX_COORD_BIT_CNT + |
| 233 | GrDrawState::kNumStages; |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 234 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 235 | public: |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 236 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 237 | /** |
| 238 | * Additional Bits that can be specified in GrVertexLayout. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 239 | */ |
| 240 | enum VertexLayoutBits { |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 241 | /* vertices have colors (GrColor) */ |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 242 | kColor_VertexLayoutBit = 1 << (STAGE_BIT_CNT + 0), |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 243 | /* vertices have coverage (GrColor) |
bsalomon@google.com | e10f6fd | 2011-10-11 20:15:26 +0000 | [diff] [blame] | 244 | */ |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 245 | kCoverage_VertexLayoutBit = 1 << (STAGE_BIT_CNT + 1), |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 246 | /* 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] | 247 | * text [GrGpuTextVertex vs GrPoint].) |
| 248 | */ |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 249 | kTextFormat_VertexLayoutBit = 1 << (STAGE_BIT_CNT + 2), |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 250 | |
bsalomon@google.com | e10f6fd | 2011-10-11 20:15:26 +0000 | [diff] [blame] | 251 | /* Each vertex specificies an edge. Distance to the edge is used to |
bsalomon@google.com | cff5608 | 2012-01-11 15:33:20 +0000 | [diff] [blame] | 252 | * compute a coverage. See GrDrawState::setVertexEdgeType(). |
bsalomon@google.com | e10f6fd | 2011-10-11 20:15:26 +0000 | [diff] [blame] | 253 | */ |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 254 | kEdge_VertexLayoutBit = 1 << (STAGE_BIT_CNT + 3), |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 255 | // for below assert |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 256 | kDummyVertexLayoutBit, |
| 257 | kHighVertexLayoutBit = kDummyVertexLayoutBit - 1 |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 258 | }; |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 259 | // 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] | 260 | GR_STATIC_ASSERT(kHighVertexLayoutBit < ((uint64_t)1 << 8*sizeof(GrVertexLayout))); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 261 | |
| 262 | /** |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 263 | * There are three methods for specifying geometry (vertices and optionally |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 264 | * 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] | 265 | * can use a different method. Once geometry is specified it can be used for |
| 266 | * multiple drawIndexed and drawNonIndexed calls. |
| 267 | * |
| 268 | * Sometimes it is necessary to perform a draw while upstack code has |
| 269 | * already specified geometry that it isn't finished with. There are push |
| 270 | * pop methods |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 271 | * |
| 272 | * 1. Provide a cpu array (set*SourceToArray). This is useful when the |
| 273 | * caller's client has already provided vertex data in a format |
| 274 | * the time compatible with a GrVertexLayout. The array must contain the |
| 275 | * data at set*SourceToArray is called. The source stays in effect for |
| 276 | * drawIndexed & drawNonIndexed calls until set*SourceToArray is called |
| 277 | * again or one of the other two paths is chosen. |
| 278 | * |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 279 | * 2. Reserve. This is most useful when the caller has data it must |
| 280 | * transform before drawing and is not long-lived. The caller requests |
| 281 | * that the draw target make room for some amount of vertex and/or index |
| 282 | * data. The target provides ptrs to hold the vertex and/or index data. |
| 283 | * |
| 284 | * The data is writable up until the next drawIndexed, drawNonIndexed, |
| 285 | * or pushGeometrySource At this point the data is frozen and the ptrs |
| 286 | * are no longer valid. |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 287 | * |
| 288 | * 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] | 289 | * is long-lived. SetVertexSourceToBuffer and SetIndexSourceToBuffer are |
| 290 | * used to set the buffer and subsequent drawIndexed and drawNonIndexed |
| 291 | * calls use this source until another source is set. |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 292 | */ |
| 293 | |
| 294 | /** |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 295 | * Reserves space for vertices. Draw target will use reserved vertices at |
| 296 | * at the next draw. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 297 | * |
| 298 | * If succeeds: |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 299 | * if vertexCount > 0, *vertices will be the array |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 300 | * of vertices to be filled by caller. The next draw will read |
| 301 | * these vertices. |
| 302 | * |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 303 | * 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] | 304 | * preferred way to allocate vertex data. It allows the subclass of |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 305 | * GrDrawTarget to decide whether to put data in buffers, to group vertex |
| 306 | * 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] | 307 | * |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 308 | * After the next draw or pushGeometrySource the vertices ptr is no longer |
| 309 | * valid and the geometry data cannot be further modified. The contents |
| 310 | * that were put in the reserved space can be drawn by multiple draws, |
| 311 | * however. |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 312 | * |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 313 | * @param vertexLayout the format of vertices (ignored if vertexCount == 0). |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 314 | * @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] | 315 | * @param vertices will point to reserved vertex space if vertexCount is |
| 316 | * non-zero. Illegal to pass NULL if vertexCount > 0. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 317 | * |
| 318 | * @return true if succeeded in allocating space for the vertices and false |
| 319 | * if not. |
| 320 | */ |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 321 | bool reserveVertexSpace(GrVertexLayout vertexLayout, |
| 322 | int vertexCount, |
| 323 | void** vertices); |
| 324 | /** |
| 325 | * Reserves space for indices. Draw target will use the reserved indices at |
| 326 | * the next indexed draw. |
| 327 | * |
| 328 | * If succeeds: |
| 329 | * if indexCount > 0, *indices will be the array |
| 330 | * of indices to be filled by caller. The next draw will read |
| 331 | * these indices. |
| 332 | * |
| 333 | * If a client does not already have a index buffer then this is the |
| 334 | * preferred way to allocate index data. It allows the subclass of |
| 335 | * GrDrawTarget to decide whether to put data in buffers, to group index |
| 336 | * data that uses the same state (e.g. for deferred rendering), etc. |
| 337 | * |
| 338 | * After the next indexed draw or pushGeometrySource the indices ptr is no |
| 339 | * longer valid and the geometry data cannot be further modified. The |
| 340 | * contents that were put in the reserved space can be drawn by multiple |
| 341 | * draws, however. |
| 342 | * |
| 343 | * @param indexCount the number of indices to reserve space for. Can be 0. |
| 344 | * @param indices will point to reserved index space if indexCount is |
| 345 | * non-zero. Illegal to pass NULL if indexCount > 0. |
| 346 | */ |
| 347 | |
| 348 | bool reserveIndexSpace(int indexCount, void** indices); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 349 | /** |
| 350 | * Provides hints to caller about the number of vertices and indices |
| 351 | * that can be allocated cheaply. This can be useful if caller is reserving |
| 352 | * space but doesn't know exactly how much geometry is needed. |
| 353 | * |
| 354 | * Also may hint whether the draw target should be flushed first. This is |
| 355 | * useful for deferred targets. |
| 356 | * |
| 357 | * @param vertexLayout layout of vertices caller would like to reserve |
| 358 | * @param vertexCount in: hint about how many vertices the caller would |
| 359 | * like to allocate. |
| 360 | * out: a hint about the number of vertices that can be |
| 361 | * allocated cheaply. Negative means no hint. |
| 362 | * Ignored if NULL. |
| 363 | * @param indexCount in: hint about how many indices the caller would |
| 364 | * like to allocate. |
| 365 | * out: a hint about the number of indices that can be |
| 366 | * allocated cheaply. Negative means no hint. |
| 367 | * Ignored if NULL. |
| 368 | * |
| 369 | * @return true if target should be flushed based on the input values. |
| 370 | */ |
| 371 | virtual bool geometryHints(GrVertexLayout vertexLayout, |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 372 | int* vertexCount, |
| 373 | int* indexCount) const; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 374 | |
| 375 | /** |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 376 | * Sets source of vertex data for the next draw. Array must contain |
| 377 | * the vertex data when this is called. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 378 | * |
| 379 | * @param array cpu array containing vertex data. |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 380 | * @param size size of the vertex data. |
| 381 | * @param vertexCount the number of vertices in the array. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 382 | */ |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 383 | void setVertexSourceToArray(GrVertexLayout vertexLayout, |
| 384 | const void* vertexArray, |
| 385 | int vertexCount); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 386 | |
| 387 | /** |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 388 | * Sets source of index data for the next indexed draw. Array must contain |
| 389 | * the indices when this is called. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 390 | * |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 391 | * @param array cpu array containing index data. |
| 392 | * @param indexCount the number of indices in the array. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 393 | */ |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 394 | void setIndexSourceToArray(const void* indexArray, int indexCount); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 395 | |
| 396 | /** |
| 397 | * Sets source of vertex data for the next draw. Data does not have to be |
| 398 | * in the buffer until drawIndexed or drawNonIndexed. |
| 399 | * |
| 400 | * @param buffer vertex buffer containing vertex data. Must be |
| 401 | * unlocked before draw call. |
| 402 | * @param vertexLayout layout of the vertex data in the buffer. |
| 403 | */ |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 404 | void setVertexSourceToBuffer(GrVertexLayout vertexLayout, |
| 405 | const GrVertexBuffer* buffer); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 406 | |
| 407 | /** |
| 408 | * Sets source of index data for the next indexed draw. Data does not have |
| 409 | * to be in the buffer until drawIndexed or drawNonIndexed. |
| 410 | * |
| 411 | * @param buffer index buffer containing indices. Must be unlocked |
| 412 | * before indexed draw call. |
| 413 | */ |
| 414 | void setIndexSourceToBuffer(const GrIndexBuffer* buffer); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 415 | |
| 416 | /** |
| 417 | * Resets vertex source. Drawing from reset vertices is illegal. Set vertex |
| 418 | * source to reserved, array, or buffer before next draw. May be able to free |
| 419 | * up temporary storage allocated by setVertexSourceToArray or |
| 420 | * reserveVertexSpace. |
| 421 | */ |
| 422 | void resetVertexSource(); |
| 423 | |
| 424 | /** |
| 425 | * Resets index source. Indexed Drawing from reset indices is illegal. Set |
| 426 | * index source to reserved, array, or buffer before next indexed draw. May |
| 427 | * be able to free up temporary storage allocated by setIndexSourceToArray |
| 428 | * or reserveIndexSpace. |
| 429 | */ |
| 430 | void resetIndexSource(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 431 | |
| 432 | /** |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 433 | * Pushes and resets the vertex/index sources. Any reserved vertex / index |
| 434 | * data is finalized (i.e. cannot be updated after the matching pop but can |
| 435 | * be drawn from). Must be balanced by a pop. |
| 436 | */ |
| 437 | void pushGeometrySource(); |
| 438 | |
| 439 | /** |
| 440 | * Pops the vertex / index sources from the matching push. |
| 441 | */ |
| 442 | void popGeometrySource(); |
| 443 | |
| 444 | /** |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 445 | * Draws indexed geometry using the current state and current vertex / index |
| 446 | * sources. |
| 447 | * |
| 448 | * @param type The type of primitives to draw. |
| 449 | * @param startVertex the vertex in the vertex array/buffer corresponding |
| 450 | * to index 0 |
| 451 | * @param startIndex first index to read from index src. |
| 452 | * @param vertexCount one greater than the max index. |
| 453 | * @param indexCount the number of index elements to read. The index count |
| 454 | * is effectively trimmed to the last completely |
| 455 | * specified primitive. |
| 456 | */ |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 457 | void drawIndexed(GrPrimitiveType type, |
| 458 | int startVertex, |
| 459 | int startIndex, |
| 460 | int vertexCount, |
| 461 | int indexCount); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 462 | |
| 463 | /** |
| 464 | * Draws non-indexed geometry using the current state and current vertex |
| 465 | * sources. |
| 466 | * |
| 467 | * @param type The type of primitives to draw. |
| 468 | * @param startVertex the vertex in the vertex array/buffer corresponding |
| 469 | * to index 0 |
| 470 | * @param vertexCount one greater than the max index. |
| 471 | */ |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 472 | void drawNonIndexed(GrPrimitiveType type, |
| 473 | int startVertex, |
| 474 | int vertexCount); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 475 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 476 | /** |
| 477 | * Helper function for drawing rects. This does not use the current index |
| 478 | * and vertex sources. After returning, the vertex and index sources may |
| 479 | * have changed. They should be reestablished before the next drawIndexed |
| 480 | * or drawNonIndexed. This cannot be called between reserving and releasing |
| 481 | * geometry. The GrDrawTarget subclass may be able to perform additional |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 482 | * optimizations if drawRect is used rather than drawIndexed or |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 483 | * drawNonIndexed. |
| 484 | * @param rect the rect to draw |
| 485 | * @param matrix optional matrix applied to rect (before viewMatrix) |
bsalomon@google.com | 39ee0ff | 2011-12-06 15:32:52 +0000 | [diff] [blame] | 486 | * @param stageMask bitmask indicating which stages are enabled. |
| 487 | * Bit i indicates whether stage i is enabled. |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 488 | * @param srcRects specifies rects for stages enabled by stageEnableMask. |
| 489 | * if stageEnableMask bit i is 1, srcRects is not NULL, |
| 490 | * and srcRects[i] is not NULL, then srcRects[i] will be |
| 491 | * used as coordinates for stage i. Otherwise, if stage i |
| 492 | * is enabled then rect is used as the coordinates. |
| 493 | * @param srcMatrices optional matrices applied to srcRects. If |
| 494 | * srcRect[i] is non-NULL and srcMatrices[i] is |
| 495 | * non-NULL then srcRect[i] will be transformed by |
| 496 | * srcMatrix[i]. srcMatrices can be NULL when no |
| 497 | * srcMatrices are desired. |
| 498 | */ |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 499 | virtual void drawRect(const GrRect& rect, |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 500 | const GrMatrix* matrix, |
bsalomon@google.com | 39ee0ff | 2011-12-06 15:32:52 +0000 | [diff] [blame] | 501 | StageMask stageMask, |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 502 | const GrRect* srcRects[], |
| 503 | const GrMatrix* srcMatrices[]); |
| 504 | |
| 505 | /** |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 506 | * 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] | 507 | * matrices. |
| 508 | */ |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 509 | void drawSimpleRect(const GrRect& rect, |
| 510 | const GrMatrix* matrix, |
bsalomon@google.com | 39ee0ff | 2011-12-06 15:32:52 +0000 | [diff] [blame] | 511 | StageMask stageEnableBitfield) { |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 512 | drawRect(rect, matrix, stageEnableBitfield, NULL, NULL); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 513 | } |
| 514 | |
bsalomon@google.com | 0b335c1 | 2011-04-25 19:17:44 +0000 | [diff] [blame] | 515 | /** |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 516 | * Clear the render target. Ignores the clip and all other draw state |
| 517 | * (blend mode, stages, etc). Clears the whole thing if rect is NULL, |
| 518 | * otherwise just the rect. |
bsalomon@google.com | 0b335c1 | 2011-04-25 19:17:44 +0000 | [diff] [blame] | 519 | */ |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 520 | virtual void clear(const GrIRect* rect, GrColor color) = 0; |
bsalomon@google.com | 0b335c1 | 2011-04-25 19:17:44 +0000 | [diff] [blame] | 521 | |
senorblanco@chromium.org | ef3913b | 2011-05-19 17:11:07 +0000 | [diff] [blame] | 522 | /** |
| 523 | * Returns the maximum number of edges that may be specified in a single |
| 524 | * draw call when performing edge antialiasing. This is usually limited |
| 525 | * by the number of fragment uniforms which may be uploaded. Must be a |
| 526 | * minimum of six, since a triangle's vertices each belong to two boundary |
| 527 | * edges which may be distinct. |
| 528 | */ |
| 529 | virtual int getMaxEdges() const { return 6; } |
| 530 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 531 | //////////////////////////////////////////////////////////////////////////// |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 532 | |
| 533 | class AutoStateRestore : ::GrNoncopyable { |
| 534 | public: |
bsalomon@google.com | 06afe7b | 2011-04-26 15:31:40 +0000 | [diff] [blame] | 535 | AutoStateRestore(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 536 | AutoStateRestore(GrDrawTarget* target); |
| 537 | ~AutoStateRestore(); |
| 538 | |
bsalomon@google.com | 06afe7b | 2011-04-26 15:31:40 +0000 | [diff] [blame] | 539 | /** |
| 540 | * if this object is already saving state for param target then |
| 541 | * this does nothing. Otherise, it restores previously saved state on |
| 542 | * previous target (if any) and saves current state on param target. |
| 543 | */ |
| 544 | void set(GrDrawTarget* target); |
| 545 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 546 | private: |
| 547 | GrDrawTarget* fDrawTarget; |
| 548 | SavedDrawState fDrawState; |
| 549 | }; |
| 550 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 551 | //////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 552 | |
bsalomon@google.com | 7ac249b | 2011-06-14 18:46:24 +0000 | [diff] [blame] | 553 | /** |
| 554 | * Sets the view matrix to I and preconcats all stage matrices enabled in |
| 555 | * mask by the view inverse. Destructor undoes these changes. |
| 556 | */ |
| 557 | class AutoDeviceCoordDraw : ::GrNoncopyable { |
| 558 | public: |
bsalomon@google.com | 3d0835b | 2011-12-08 16:12:03 +0000 | [diff] [blame] | 559 | AutoDeviceCoordDraw(GrDrawTarget* target, StageMask stageMask); |
bsalomon@google.com | 7ac249b | 2011-06-14 18:46:24 +0000 | [diff] [blame] | 560 | ~AutoDeviceCoordDraw(); |
| 561 | private: |
bsalomon@google.com | 3d0835b | 2011-12-08 16:12:03 +0000 | [diff] [blame] | 562 | GrDrawTarget* fDrawTarget; |
| 563 | GrMatrix fViewMatrix; |
| 564 | GrMatrix fSamplerMatrices[GrDrawState::kNumStages]; |
| 565 | int fStageMask; |
bsalomon@google.com | 7ac249b | 2011-06-14 18:46:24 +0000 | [diff] [blame] | 566 | }; |
| 567 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 568 | //////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 7ac249b | 2011-06-14 18:46:24 +0000 | [diff] [blame] | 569 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 570 | class AutoReleaseGeometry : ::GrNoncopyable { |
| 571 | public: |
| 572 | AutoReleaseGeometry(GrDrawTarget* target, |
| 573 | GrVertexLayout vertexLayout, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 574 | int vertexCount, |
| 575 | int indexCount); |
| 576 | AutoReleaseGeometry(); |
| 577 | ~AutoReleaseGeometry(); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 578 | bool set(GrDrawTarget* target, |
| 579 | GrVertexLayout vertexLayout, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 580 | int vertexCount, |
| 581 | int indexCount); |
bsalomon@google.com | a47a48d | 2011-04-26 20:22:11 +0000 | [diff] [blame] | 582 | bool succeeded() const { return NULL != fTarget; } |
bsalomon@google.com | 6513cd0 | 2011-08-05 20:12:30 +0000 | [diff] [blame] | 583 | void* vertices() const { GrAssert(this->succeeded()); return fVertices; } |
| 584 | void* indices() const { GrAssert(this->succeeded()); return fIndices; } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 585 | GrPoint* positions() const { |
bsalomon@google.com | 6513cd0 | 2011-08-05 20:12:30 +0000 | [diff] [blame] | 586 | return static_cast<GrPoint*>(this->vertices()); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | private: |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 590 | void reset(); |
| 591 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 592 | GrDrawTarget* fTarget; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 593 | void* fVertices; |
| 594 | void* fIndices; |
| 595 | }; |
| 596 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 597 | //////////////////////////////////////////////////////////////////////////// |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 598 | |
| 599 | class AutoClipRestore : ::GrNoncopyable { |
| 600 | public: |
| 601 | AutoClipRestore(GrDrawTarget* target) { |
| 602 | fTarget = target; |
| 603 | fClip = fTarget->getClip(); |
| 604 | } |
| 605 | |
| 606 | ~AutoClipRestore() { |
| 607 | fTarget->setClip(fClip); |
| 608 | } |
| 609 | private: |
| 610 | GrDrawTarget* fTarget; |
| 611 | GrClip fClip; |
| 612 | }; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 613 | |
| 614 | //////////////////////////////////////////////////////////////////////////// |
| 615 | |
| 616 | class AutoGeometryPush : ::GrNoncopyable { |
| 617 | public: |
| 618 | AutoGeometryPush(GrDrawTarget* target) { |
| 619 | GrAssert(NULL != target); |
| 620 | fTarget = target; |
| 621 | target->pushGeometrySource(); |
| 622 | } |
| 623 | ~AutoGeometryPush() { |
| 624 | fTarget->popGeometrySource(); |
| 625 | } |
| 626 | private: |
| 627 | GrDrawTarget* fTarget; |
| 628 | }; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 629 | |
| 630 | //////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 631 | // Helpers for picking apart vertex layouts |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 632 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 633 | /** |
| 634 | * Helper function to compute the size of a vertex from a vertex layout |
| 635 | * @return size of a single vertex. |
| 636 | */ |
| 637 | static size_t VertexSize(GrVertexLayout vertexLayout); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 638 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 639 | /** |
| 640 | * Helper function for determining the index of texture coordinates that |
| 641 | * is input for a texture stage. Note that a stage may instead use positions |
| 642 | * as texture coordinates, in which case the result of the function is |
| 643 | * indistinguishable from the case when the stage is disabled. |
| 644 | * |
| 645 | * @param stage the stage to query |
| 646 | * @param vertexLayout layout to query |
| 647 | * |
| 648 | * @return the texture coordinate index or -1 if the stage doesn't use |
| 649 | * separate (non-position) texture coordinates. |
| 650 | */ |
| 651 | static int VertexTexCoordsForStage(int stage, GrVertexLayout vertexLayout); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 652 | |
| 653 | /** |
| 654 | * Helper function to compute the offset of texture coordinates in a vertex |
| 655 | * @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] | 656 | * layout has no texture coordinates. Will be 0 if positions are |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 657 | * used as texture coordinates for the stage. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 658 | */ |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 659 | static int VertexStageCoordOffset(int stage, GrVertexLayout vertexLayout); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 660 | |
| 661 | /** |
| 662 | * Helper function to compute the offset of the color in a vertex |
| 663 | * @return offset of color in vertex layout or -1 if the |
| 664 | * layout has no color. |
| 665 | */ |
| 666 | static int VertexColorOffset(GrVertexLayout vertexLayout); |
| 667 | |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 668 | /** |
| 669 | * Helper function to compute the offset of the coverage in a vertex |
| 670 | * @return offset of coverage in vertex layout or -1 if the |
| 671 | * layout has no coverage. |
| 672 | */ |
| 673 | static int VertexCoverageOffset(GrVertexLayout vertexLayout); |
| 674 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 675 | /** |
| 676 | * Helper function to compute the offset of the edge pts in a vertex |
| 677 | * @return offset of edge in vertex layout or -1 if the |
| 678 | * layout has no edge. |
| 679 | */ |
| 680 | static int VertexEdgeOffset(GrVertexLayout vertexLayout); |
| 681 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 682 | /** |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 683 | * Helper function to determine if vertex layout contains explicit texture |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 684 | * coordinates of some index. |
| 685 | * |
| 686 | * @param coordIndex the tex coord index to query |
| 687 | * @param vertexLayout layout to query |
| 688 | * |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 689 | * @return true if vertex specifies texture coordinates for the index, |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 690 | * false otherwise. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 691 | */ |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 692 | static bool VertexUsesTexCoordIdx(int coordIndex, |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 693 | GrVertexLayout vertexLayout); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 694 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 695 | /** |
| 696 | * Helper function to determine if vertex layout contains either explicit or |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 697 | * implicit texture coordinates for a stage. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 698 | * |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 699 | * @param stage the stage to query |
| 700 | * @param vertexLayout layout to query |
| 701 | * |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 702 | * @return true if vertex specifies texture coordinates for the stage, |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 703 | * false otherwise. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 704 | */ |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 705 | static bool VertexUsesStage(int stage, GrVertexLayout vertexLayout); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 706 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 707 | /** |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 708 | * Helper function to compute the size of each vertex and the offsets of |
| 709 | * texture coordinates and color. Determines tex coord offsets by tex coord |
| 710 | * 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] | 711 | * by StageTexCoordVertexLayoutBit.) |
| 712 | * |
| 713 | * @param vertexLayout the layout to query |
| 714 | * @param texCoordOffsetsByIdx after return it is the offset of each |
| 715 | * tex coord index in the vertex or -1 if |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 716 | * index isn't used. (optional) |
| 717 | * @param colorOffset after return it is the offset of the |
| 718 | * color field in each vertex, or -1 if |
| 719 | * there aren't per-vertex colors. (optional) |
| 720 | * @param coverageOffset after return it is the offset of the |
| 721 | * coverage field in each vertex, or -1 if |
| 722 | * there aren't per-vertex coeverages. |
| 723 | * (optional) |
| 724 | * @param edgeOffset after return it is the offset of the |
| 725 | * edge eq field in each vertex, or -1 if |
| 726 | * there aren't per-vertex edge equations. |
| 727 | * (optional) |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 728 | * @return size of a single vertex |
| 729 | */ |
| 730 | static int VertexSizeAndOffsetsByIdx(GrVertexLayout vertexLayout, |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 731 | int texCoordOffsetsByIdx[GrDrawState::kMaxTexCoords], |
| 732 | int *colorOffset, |
| 733 | int *coverageOffset, |
| 734 | int* edgeOffset); |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 735 | |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 736 | /** |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 737 | * Helper function to compute the size of each vertex and the offsets of |
| 738 | * texture coordinates and color. Determines tex coord offsets by stage |
| 739 | * rather than by index. (Each stage can be mapped to any t.c. index |
| 740 | * by StageTexCoordVertexLayoutBit.) If a stage uses positions for |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 741 | * tex coords then that stage's offset will be 0 (positions are always at 0). |
| 742 | * |
| 743 | * @param vertexLayout the layout to query |
| 744 | * @param texCoordOffsetsByStage after return it is the offset of each |
| 745 | * tex coord index in the vertex or -1 if |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 746 | * index isn't used. (optional) |
| 747 | * @param colorOffset after return it is the offset of the |
| 748 | * color field in each vertex, or -1 if |
| 749 | * there aren't per-vertex colors. |
| 750 | * (optional) |
| 751 | * @param coverageOffset after return it is the offset of the |
| 752 | * coverage field in each vertex, or -1 if |
| 753 | * there aren't per-vertex coeverages. |
| 754 | * (optional) |
| 755 | * @param edgeOffset after return it is the offset of the |
| 756 | * edge eq field in each vertex, or -1 if |
| 757 | * there aren't per-vertex edge equations. |
| 758 | * (optional) |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 759 | * @return size of a single vertex |
| 760 | */ |
| 761 | static int VertexSizeAndOffsetsByStage(GrVertexLayout vertexLayout, |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 762 | int texCoordOffsetsByStage[GrDrawState::kNumStages], |
| 763 | int* colorOffset, |
| 764 | int* coverageOffset, |
| 765 | int* edgeOffset); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 766 | |
| 767 | /** |
| 768 | * Accessing positions, texture coords, or colors, of a vertex within an |
| 769 | * array is a hassle involving casts and simple math. These helpers exist |
| 770 | * to keep GrDrawTarget clients' code a bit nicer looking. |
| 771 | */ |
| 772 | |
| 773 | /** |
| 774 | * Gets a pointer to a GrPoint of a vertex's position or texture |
| 775 | * coordinate. |
| 776 | * @param vertices the vetex array |
| 777 | * @param vertexIndex the index of the vertex in the array |
| 778 | * @param vertexSize the size of each vertex in the array |
| 779 | * @param offset the offset in bytes of the vertex component. |
| 780 | * Defaults to zero (corresponding to vertex position) |
| 781 | * @return pointer to the vertex component as a GrPoint |
| 782 | */ |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 783 | static GrPoint* GetVertexPoint(void* vertices, |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 784 | int vertexIndex, |
| 785 | int vertexSize, |
| 786 | int offset = 0) { |
| 787 | intptr_t start = GrTCast<intptr_t>(vertices); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 788 | return GrTCast<GrPoint*>(start + offset + |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 789 | vertexIndex * vertexSize); |
| 790 | } |
| 791 | static const GrPoint* GetVertexPoint(const void* vertices, |
| 792 | int vertexIndex, |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 793 | int vertexSize, |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 794 | int offset = 0) { |
| 795 | intptr_t start = GrTCast<intptr_t>(vertices); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 796 | return GrTCast<const GrPoint*>(start + offset + |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 797 | vertexIndex * vertexSize); |
| 798 | } |
| 799 | |
| 800 | /** |
| 801 | * Gets a pointer to a GrColor inside a vertex within a vertex array. |
| 802 | * @param vertices the vetex array |
| 803 | * @param vertexIndex the index of the vertex in the array |
| 804 | * @param vertexSize the size of each vertex in the array |
| 805 | * @param offset the offset in bytes of the vertex color |
| 806 | * @return pointer to the vertex component as a GrColor |
| 807 | */ |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 808 | static GrColor* GetVertexColor(void* vertices, |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 809 | int vertexIndex, |
| 810 | int vertexSize, |
| 811 | int offset) { |
| 812 | intptr_t start = GrTCast<intptr_t>(vertices); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 813 | return GrTCast<GrColor*>(start + offset + |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 814 | vertexIndex * vertexSize); |
| 815 | } |
| 816 | static const GrColor* GetVertexColor(const void* vertices, |
| 817 | int vertexIndex, |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 818 | int vertexSize, |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 819 | int offset) { |
| 820 | const intptr_t start = GrTCast<intptr_t>(vertices); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 821 | return GrTCast<const GrColor*>(start + offset + |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 822 | vertexIndex * vertexSize); |
| 823 | } |
| 824 | |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 825 | static void VertexLayoutUnitTest(); |
| 826 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 827 | protected: |
bsalomon@google.com | 471d471 | 2011-08-23 15:45:25 +0000 | [diff] [blame] | 828 | |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 829 | /** |
| 830 | * Optimizations for blending / coverage to be applied based on the current |
| 831 | * state. |
| 832 | * Subclasses that actually draw (as opposed to those that just buffer for |
| 833 | * playback) must implement the flags that replace the output color. |
| 834 | */ |
| 835 | enum BlendOptFlags { |
| 836 | /** |
| 837 | * No optimization |
| 838 | */ |
| 839 | kNone_BlendOpt = 0, |
| 840 | /** |
| 841 | * Don't draw at all |
| 842 | */ |
| 843 | kSkipDraw_BlendOptFlag = 0x2, |
| 844 | /** |
| 845 | * Emit the src color, disable HW blending (replace dst with src) |
| 846 | */ |
| 847 | kDisableBlend_BlendOptFlag = 0x4, |
| 848 | /** |
| 849 | * The coverage value does not have to be computed separately from |
| 850 | * alpha, the the output color can be the modulation of the two. |
| 851 | */ |
| 852 | kCoverageAsAlpha_BlendOptFlag = 0x1, |
| 853 | /** |
| 854 | * Instead of emitting a src color, emit coverage in the alpha channel |
| 855 | * and r,g,b are "don't cares". |
| 856 | */ |
| 857 | kEmitCoverage_BlendOptFlag = 0x10, |
| 858 | /** |
| 859 | * Emit transparent black instead of the src color, no need to compute |
| 860 | * coverage. |
| 861 | */ |
| 862 | kEmitTransBlack_BlendOptFlag = 0x8, |
| 863 | }; |
| 864 | GR_DECL_BITFIELD_OPS_FRIENDS(BlendOptFlags); |
bsalomon@google.com | 471d471 | 2011-08-23 15:45:25 +0000 | [diff] [blame] | 865 | |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 866 | // Determines what optimizations can be applied based on the blend. |
| 867 | // The coeffecients may have to be tweaked in order for the optimization |
| 868 | // to work. srcCoeff and dstCoeff are optional params that receive the |
| 869 | // tweaked coeffecients. |
| 870 | // Normally the function looks at the current state to see if coverage |
| 871 | // is enabled. By setting forceCoverage the caller can speculatively |
| 872 | // determine the blend optimizations that would be used if there was |
| 873 | // partial pixel coverage |
| 874 | BlendOptFlags getBlendOpts(bool forceCoverage = false, |
| 875 | GrBlendCoeff* srcCoeff = NULL, |
| 876 | GrBlendCoeff* dstCoeff = NULL) const; |
| 877 | |
| 878 | // determine if src alpha is guaranteed to be one for all src pixels |
| 879 | bool srcAlphaWillBeOne() const; |
bsalomon@google.com | 471d471 | 2011-08-23 15:45:25 +0000 | [diff] [blame] | 880 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 881 | enum GeometrySrcType { |
| 882 | kNone_GeometrySrcType, //<! src has not been specified |
| 883 | kReserved_GeometrySrcType, //<! src was set using reserve*Space |
| 884 | kArray_GeometrySrcType, //<! src was set using set*SourceToArray |
| 885 | kBuffer_GeometrySrcType //<! src was set using set*SourceToBuffer |
| 886 | }; |
| 887 | |
| 888 | struct GeometrySrcState { |
| 889 | GeometrySrcType fVertexSrc; |
| 890 | union { |
| 891 | // valid if src type is buffer |
| 892 | const GrVertexBuffer* fVertexBuffer; |
| 893 | // valid if src type is reserved or array |
| 894 | int fVertexCount; |
| 895 | }; |
| 896 | |
| 897 | GeometrySrcType fIndexSrc; |
| 898 | union { |
| 899 | // valid if src type is buffer |
| 900 | const GrIndexBuffer* fIndexBuffer; |
| 901 | // valid if src type is reserved or array |
| 902 | int fIndexCount; |
| 903 | }; |
| 904 | |
| 905 | GrVertexLayout fVertexLayout; |
| 906 | }; |
| 907 | |
bsalomon@google.com | a47a48d | 2011-04-26 20:22:11 +0000 | [diff] [blame] | 908 | // given a vertex layout and a draw state, will a stage be used? |
| 909 | static bool StageWillBeUsed(int stage, GrVertexLayout layout, |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 910 | const GrDrawState& state) { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 911 | return NULL != state.getTexture(stage) && |
| 912 | VertexUsesStage(stage, layout); |
bsalomon@google.com | a47a48d | 2011-04-26 20:22:11 +0000 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | bool isStageEnabled(int stage) const { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 916 | return StageWillBeUsed(stage, this->getGeomSrc().fVertexLayout, |
| 917 | fCurrDrawState); |
bsalomon@google.com | a47a48d | 2011-04-26 20:22:11 +0000 | [diff] [blame] | 918 | } |
bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 919 | |
bsalomon@google.com | 39ee0ff | 2011-12-06 15:32:52 +0000 | [diff] [blame] | 920 | StageMask enabledStages() const { |
| 921 | StageMask mask = 0; |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 922 | for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 923 | mask |= this->isStageEnabled(s) ? 1 : 0; |
| 924 | } |
| 925 | return mask; |
| 926 | } |
| 927 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 928 | // Helpers for GrDrawTarget subclasses that won't have private access to |
| 929 | // SavedDrawState but need to peek at the state values. |
bsalomon@google.com | 46f7afb | 2012-01-18 19:51:55 +0000 | [diff] [blame^] | 930 | static GrDrawState& accessSavedDrawState(SavedDrawState& sds) { |
| 931 | return *sds.fState.get(); |
| 932 | } |
| 933 | static const GrDrawState& accessSavedDrawState(const SavedDrawState& sds){ |
| 934 | return *sds.fState.get(); |
| 935 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 936 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 937 | // implemented by subclass to allocate space for reserved geom |
| 938 | virtual bool onReserveVertexSpace(GrVertexLayout vertexLayout, |
| 939 | int vertexCount, |
| 940 | void** vertices) = 0; |
| 941 | virtual bool onReserveIndexSpace(int indexCount, void** indices) = 0; |
| 942 | // implemented by subclass to handle release of reserved geom space |
| 943 | virtual void releaseReservedVertexSpace() = 0; |
| 944 | virtual void releaseReservedIndexSpace() = 0; |
| 945 | // subclass must consume array contents when set |
| 946 | virtual void onSetVertexSourceToArray(const void* vertexArray, |
| 947 | int vertexCount) = 0; |
| 948 | virtual void onSetIndexSourceToArray(const void* indexArray, |
| 949 | int indexCount) = 0; |
| 950 | // subclass is notified that geom source will be set away from an array |
| 951 | virtual void releaseVertexArray() = 0; |
| 952 | virtual void releaseIndexArray() = 0; |
| 953 | // subclass overrides to be notified just before geo src state |
| 954 | // is pushed/popped. |
| 955 | virtual void geometrySourceWillPush() = 0; |
| 956 | virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) = 0; |
| 957 | // subclass called to perform drawing |
| 958 | virtual void onDrawIndexed(GrPrimitiveType type, |
| 959 | int startVertex, |
| 960 | int startIndex, |
| 961 | int vertexCount, |
| 962 | int indexCount) = 0; |
| 963 | virtual void onDrawNonIndexed(GrPrimitiveType type, |
| 964 | int startVertex, |
| 965 | int vertexCount) = 0; |
bsalomon@google.com | dea2f8d | 2011-08-01 15:51:05 +0000 | [diff] [blame] | 966 | // subclass overrides to be notified when clip is set. Must call |
| 967 | // INHERITED::clipwillBeSet |
| 968 | virtual void clipWillBeSet(const GrClip& clip); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 969 | |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 970 | // Helpers for drawRect, protected so subclasses that override drawRect |
| 971 | // can use them. |
bsalomon@google.com | 3d0835b | 2011-12-08 16:12:03 +0000 | [diff] [blame] | 972 | static GrVertexLayout GetRectVertexLayout(StageMask stageEnableBitfield, |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 973 | const GrRect* srcRects[]); |
| 974 | |
| 975 | static void SetRectVertices(const GrRect& rect, |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 976 | const GrMatrix* matrix, |
| 977 | const GrRect* srcRects[], |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 978 | const GrMatrix* srcMatrices[], |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 979 | GrVertexLayout layout, |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 980 | void* vertices); |
| 981 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 982 | // accessor for derived classes |
| 983 | const GeometrySrcState& getGeomSrc() const { |
| 984 | return fGeoSrcStateStack.back(); |
| 985 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 986 | |
| 987 | GrClip fClip; |
| 988 | |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 989 | GrDrawState fCurrDrawState; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 990 | |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 991 | Caps fCaps; |
| 992 | |
bsalomon@google.com | 4a018bb | 2011-10-28 19:50:21 +0000 | [diff] [blame] | 993 | // subclasses must call this in their destructors to ensure all vertex |
| 994 | // and index sources have been released (including those held by |
| 995 | // pushGeometrySource()) |
| 996 | void releaseGeometry(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 997 | private: |
bsalomon@google.com | e826262 | 2011-11-07 02:30:51 +0000 | [diff] [blame] | 998 | // called by drawIndexed and drawNonIndexed. Use a negative indexCount to |
| 999 | // indicate non-indexed drawing. |
| 1000 | bool checkDraw(GrPrimitiveType type, int startVertex, |
| 1001 | int startIndex, int vertexCount, |
| 1002 | int indexCount) const; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 1003 | // called when setting a new vert/idx source to unref prev vb/ib |
| 1004 | void releasePreviousVertexSource(); |
| 1005 | void releasePreviousIndexSource(); |
| 1006 | |
| 1007 | enum { |
| 1008 | kPreallocGeoSrcStateStackCnt = 4, |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1009 | }; |
bsalomon@google.com | 9266901 | 2011-09-27 19:10:05 +0000 | [diff] [blame] | 1010 | SkSTArray<kPreallocGeoSrcStateStackCnt, |
| 1011 | GeometrySrcState, true> fGeoSrcStateStack; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 1012 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1013 | }; |
| 1014 | |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 1015 | GR_MAKE_BITFIELD_OPS(GrDrawTarget::BlendOptFlags); |
| 1016 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1017 | #endif |