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