| 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 | #include "GrDrawTarget.h" |
| 12 | #include "GrGpuVertex.h" |
| bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 13 | #include "GrTexture.h" |
| bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 14 | #include "GrVertexBuffer.h" |
| 15 | #include "GrIndexBuffer.h" |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 16 | |
| junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 17 | namespace { |
| 18 | |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 19 | // recursive helper for creating mask with all the tex coord bits set for |
| 20 | // one stage |
| 21 | template <int N> |
| reed@google.com | 34cec24 | 2011-04-19 15:53:12 +0000 | [diff] [blame] | 22 | int stage_mask_recur(int stage) { |
| bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 23 | return GrDrawTarget::StageTexCoordVertexLayoutBit(stage, N) | |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 24 | stage_mask_recur<N+1>(stage); |
| 25 | } |
| junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 26 | template<> |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 27 | int stage_mask_recur<GrDrawState::kNumStages>(int) { return 0; } |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 28 | |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 29 | // mask of all tex coord indices for one stage |
| junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 30 | int stage_tex_coord_mask(int stage) { |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 31 | return stage_mask_recur<0>(stage); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 32 | } |
| 33 | |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 34 | // mask of all bits relevant to one stage |
| junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 35 | int stage_mask(int stage) { |
| bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 36 | return stage_tex_coord_mask(stage) | |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 37 | GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(stage); |
| 38 | } |
| 39 | |
| 40 | // recursive helper for creating mask of with all bits set relevant to one |
| 41 | // texture coordinate index |
| 42 | template <int N> |
| reed@google.com | 34cec24 | 2011-04-19 15:53:12 +0000 | [diff] [blame] | 43 | int tex_coord_mask_recur(int texCoordIdx) { |
| bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 44 | return GrDrawTarget::StageTexCoordVertexLayoutBit(N, texCoordIdx) | |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 45 | tex_coord_mask_recur<N+1>(texCoordIdx); |
| 46 | } |
| junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 47 | template<> |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 48 | int tex_coord_mask_recur<GrDrawState::kMaxTexCoords>(int) { return 0; } |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 49 | |
| 50 | // mask of all bits relevant to one texture coordinate index |
| junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 51 | int tex_coord_idx_mask(int texCoordIdx) { |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 52 | return tex_coord_mask_recur<0>(texCoordIdx); |
| 53 | } |
| 54 | |
| 55 | bool check_layout(GrVertexLayout layout) { |
| 56 | // can only have 1 or 0 bits set for each stage. |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 57 | for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 58 | int stageBits = layout & stage_mask(s); |
| 59 | if (stageBits && !GrIsPow2(stageBits)) { |
| 60 | return false; |
| 61 | } |
| 62 | } |
| 63 | return true; |
| 64 | } |
| 65 | |
| bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 66 | int num_tex_coords(GrVertexLayout layout) { |
| 67 | int cnt = 0; |
| 68 | // figure out how many tex coordinates are present |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 69 | for (int t = 0; t < GrDrawState::kMaxTexCoords; ++t) { |
| bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 70 | if (tex_coord_idx_mask(t) & layout) { |
| 71 | ++cnt; |
| 72 | } |
| 73 | } |
| 74 | return cnt; |
| 75 | } |
| 76 | |
| junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 77 | } //unnamed namespace |
| 78 | |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 79 | size_t GrDrawTarget::VertexSize(GrVertexLayout vertexLayout) { |
| 80 | GrAssert(check_layout(vertexLayout)); |
| bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 81 | |
| 82 | size_t vecSize = (vertexLayout & kTextFormat_VertexLayoutBit) ? |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 83 | sizeof(GrGpuTextVertex) : |
| 84 | sizeof(GrPoint); |
| 85 | |
| 86 | size_t size = vecSize; // position |
| bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 87 | size += num_tex_coords(vertexLayout) * vecSize; |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 88 | if (vertexLayout & kColor_VertexLayoutBit) { |
| 89 | size += sizeof(GrColor); |
| 90 | } |
| bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 91 | if (vertexLayout & kCoverage_VertexLayoutBit) { |
| 92 | size += sizeof(GrColor); |
| 93 | } |
| bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 94 | if (vertexLayout & kEdge_VertexLayoutBit) { |
| 95 | size += 4 * sizeof(GrScalar); |
| 96 | } |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 97 | return size; |
| 98 | } |
| 99 | |
| bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 100 | //////////////////////////////////////////////////////////////////////////////// |
| 101 | |
| 102 | /** |
| 103 | * Functions for computing offsets of various components from the layout |
| 104 | * bitfield. |
| 105 | * |
| 106 | * Order of vertex components: |
| 107 | * Position |
| 108 | * Tex Coord 0 |
| 109 | * ... |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 110 | * Tex Coord GrDrawState::kMaxTexCoords-1 |
| bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 111 | * Color |
| 112 | * Coverage |
| 113 | */ |
| 114 | |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 115 | int GrDrawTarget::VertexStageCoordOffset(int stage, GrVertexLayout vertexLayout) { |
| 116 | GrAssert(check_layout(vertexLayout)); |
| 117 | if (StagePosAsTexCoordVertexLayoutBit(stage) & vertexLayout) { |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 118 | return 0; |
| 119 | } |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 120 | int tcIdx = VertexTexCoordsForStage(stage, vertexLayout); |
| 121 | if (tcIdx >= 0) { |
| bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 122 | |
| 123 | int vecSize = (vertexLayout & kTextFormat_VertexLayoutBit) ? |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 124 | sizeof(GrGpuTextVertex) : |
| 125 | sizeof(GrPoint); |
| 126 | int offset = vecSize; // position |
| 127 | // figure out how many tex coordinates are present and precede this one. |
| 128 | for (int t = 0; t < tcIdx; ++t) { |
| 129 | if (tex_coord_idx_mask(t) & vertexLayout) { |
| 130 | offset += vecSize; |
| 131 | } |
| 132 | } |
| 133 | return offset; |
| 134 | } |
| 135 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 136 | return -1; |
| 137 | } |
| 138 | |
| 139 | int GrDrawTarget::VertexColorOffset(GrVertexLayout vertexLayout) { |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 140 | GrAssert(check_layout(vertexLayout)); |
| bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 141 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 142 | if (vertexLayout & kColor_VertexLayoutBit) { |
| bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 143 | int vecSize = (vertexLayout & kTextFormat_VertexLayoutBit) ? |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 144 | sizeof(GrGpuTextVertex) : |
| 145 | sizeof(GrPoint); |
| bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 146 | return vecSize * (num_tex_coords(vertexLayout) + 1); //+1 for pos |
| 147 | } |
| 148 | return -1; |
| 149 | } |
| 150 | |
| bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 151 | int GrDrawTarget::VertexCoverageOffset(GrVertexLayout vertexLayout) { |
| 152 | GrAssert(check_layout(vertexLayout)); |
| 153 | |
| 154 | if (vertexLayout & kCoverage_VertexLayoutBit) { |
| 155 | int vecSize = (vertexLayout & kTextFormat_VertexLayoutBit) ? |
| 156 | sizeof(GrGpuTextVertex) : |
| 157 | sizeof(GrPoint); |
| 158 | |
| 159 | int offset = vecSize * (num_tex_coords(vertexLayout) + 1); |
| 160 | if (vertexLayout & kColor_VertexLayoutBit) { |
| 161 | offset += sizeof(GrColor); |
| 162 | } |
| 163 | return offset; |
| 164 | } |
| 165 | return -1; |
| 166 | } |
| 167 | |
| bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 168 | int GrDrawTarget::VertexEdgeOffset(GrVertexLayout vertexLayout) { |
| 169 | GrAssert(check_layout(vertexLayout)); |
| 170 | |
| 171 | // edge pts are after the pos, tex coords, and color |
| 172 | if (vertexLayout & kEdge_VertexLayoutBit) { |
| 173 | int vecSize = (vertexLayout & kTextFormat_VertexLayoutBit) ? |
| 174 | sizeof(GrGpuTextVertex) : |
| 175 | sizeof(GrPoint); |
| 176 | int offset = vecSize * (num_tex_coords(vertexLayout) + 1); //+1 for pos |
| 177 | if (vertexLayout & kColor_VertexLayoutBit) { |
| 178 | offset += sizeof(GrColor); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 179 | } |
| bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 180 | if (vertexLayout & kCoverage_VertexLayoutBit) { |
| 181 | offset += sizeof(GrColor); |
| 182 | } |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 183 | return offset; |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 184 | } |
| 185 | return -1; |
| 186 | } |
| 187 | |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 188 | int GrDrawTarget::VertexSizeAndOffsetsByIdx( |
| 189 | GrVertexLayout vertexLayout, |
| 190 | int texCoordOffsetsByIdx[GrDrawState::kMaxTexCoords], |
| 191 | int* colorOffset, |
| 192 | int* coverageOffset, |
| 193 | int* edgeOffset) { |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 194 | GrAssert(check_layout(vertexLayout)); |
| bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 195 | |
| bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 196 | int vecSize = (vertexLayout & kTextFormat_VertexLayoutBit) ? |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 197 | sizeof(GrGpuTextVertex) : |
| 198 | sizeof(GrPoint); |
| 199 | int size = vecSize; // position |
| bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 200 | |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 201 | for (int t = 0; t < GrDrawState::kMaxTexCoords; ++t) { |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 202 | if (tex_coord_idx_mask(t) & vertexLayout) { |
| bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 203 | if (NULL != texCoordOffsetsByIdx) { |
| 204 | texCoordOffsetsByIdx[t] = size; |
| 205 | } |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 206 | size += vecSize; |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 207 | } else { |
| bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 208 | if (NULL != texCoordOffsetsByIdx) { |
| 209 | texCoordOffsetsByIdx[t] = -1; |
| 210 | } |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 211 | } |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 212 | } |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 213 | if (kColor_VertexLayoutBit & vertexLayout) { |
| bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 214 | if (NULL != colorOffset) { |
| 215 | *colorOffset = size; |
| 216 | } |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 217 | size += sizeof(GrColor); |
| 218 | } else { |
| bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 219 | if (NULL != colorOffset) { |
| 220 | *colorOffset = -1; |
| 221 | } |
| 222 | } |
| 223 | if (kCoverage_VertexLayoutBit & vertexLayout) { |
| 224 | if (NULL != coverageOffset) { |
| 225 | *coverageOffset = size; |
| 226 | } |
| 227 | size += sizeof(GrColor); |
| 228 | } else { |
| 229 | if (NULL != coverageOffset) { |
| 230 | *coverageOffset = -1; |
| 231 | } |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 232 | } |
| bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 233 | if (kEdge_VertexLayoutBit & vertexLayout) { |
| bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 234 | if (NULL != edgeOffset) { |
| 235 | *edgeOffset = size; |
| 236 | } |
| bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 237 | size += 4 * sizeof(GrScalar); |
| 238 | } else { |
| bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 239 | if (NULL != edgeOffset) { |
| 240 | *edgeOffset = -1; |
| 241 | } |
| bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 242 | } |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 243 | return size; |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 244 | } |
| 245 | |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 246 | int GrDrawTarget::VertexSizeAndOffsetsByStage( |
| 247 | GrVertexLayout vertexLayout, |
| 248 | int texCoordOffsetsByStage[GrDrawState::kNumStages], |
| 249 | int* colorOffset, |
| 250 | int* coverageOffset, |
| 251 | int* edgeOffset) { |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 252 | GrAssert(check_layout(vertexLayout)); |
| 253 | |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 254 | int texCoordOffsetsByIdx[GrDrawState::kMaxTexCoords]; |
| bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 255 | int size = VertexSizeAndOffsetsByIdx(vertexLayout, |
| bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 256 | (NULL == texCoordOffsetsByStage) ? |
| 257 | NULL : |
| 258 | texCoordOffsetsByIdx, |
| bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 259 | colorOffset, |
| bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 260 | coverageOffset, |
| bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 261 | edgeOffset); |
| bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 262 | if (NULL != texCoordOffsetsByStage) { |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 263 | for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
| bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 264 | int tcIdx; |
| 265 | if (StagePosAsTexCoordVertexLayoutBit(s) & vertexLayout) { |
| 266 | texCoordOffsetsByStage[s] = 0; |
| 267 | } else if ((tcIdx = VertexTexCoordsForStage(s, vertexLayout)) >= 0) { |
| 268 | texCoordOffsetsByStage[s] = texCoordOffsetsByIdx[tcIdx]; |
| 269 | } else { |
| 270 | texCoordOffsetsByStage[s] = -1; |
| 271 | } |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 272 | } |
| 273 | } |
| bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 274 | return size; |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 275 | } |
| 276 | |
| bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 277 | //////////////////////////////////////////////////////////////////////////////// |
| 278 | |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 279 | bool GrDrawTarget::VertexUsesStage(int stage, GrVertexLayout vertexLayout) { |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 280 | GrAssert(stage < GrDrawState::kNumStages); |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 281 | GrAssert(check_layout(vertexLayout)); |
| 282 | return !!(stage_mask(stage) & vertexLayout); |
| 283 | } |
| 284 | |
| bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 285 | bool GrDrawTarget::VertexUsesTexCoordIdx(int coordIndex, |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 286 | GrVertexLayout vertexLayout) { |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 287 | GrAssert(coordIndex < GrDrawState::kMaxTexCoords); |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 288 | GrAssert(check_layout(vertexLayout)); |
| 289 | return !!(tex_coord_idx_mask(coordIndex) & vertexLayout); |
| 290 | } |
| 291 | |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 292 | int GrDrawTarget::VertexTexCoordsForStage(int stage, |
| 293 | GrVertexLayout vertexLayout) { |
| 294 | GrAssert(stage < GrDrawState::kNumStages); |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 295 | GrAssert(check_layout(vertexLayout)); |
| 296 | int bit = vertexLayout & stage_tex_coord_mask(stage); |
| 297 | if (bit) { |
| 298 | // figure out which set of texture coordates is used |
| 299 | // bits are ordered T0S0, T0S1, T0S2, ..., T1S0, T1S1, ... |
| 300 | // and start at bit 0. |
| 301 | GR_STATIC_ASSERT(sizeof(GrVertexLayout) <= sizeof(uint32_t)); |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 302 | return (32 - Gr_clz(bit) - 1) / GrDrawState::kNumStages; |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 303 | } |
| 304 | return -1; |
| 305 | } |
| 306 | |
| bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 307 | //////////////////////////////////////////////////////////////////////////////// |
| 308 | |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 309 | void GrDrawTarget::VertexLayoutUnitTest() { |
| 310 | // not necessarily exhaustive |
| 311 | static bool run; |
| 312 | if (!run) { |
| 313 | run = true; |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 314 | for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 315 | |
| 316 | GrAssert(!VertexUsesStage(s, 0)); |
| 317 | GrAssert(-1 == VertexStageCoordOffset(s, 0)); |
| 318 | GrVertexLayout stageMask = 0; |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 319 | for (int t = 0; t < GrDrawState::kMaxTexCoords; ++t) { |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 320 | stageMask |= StageTexCoordVertexLayoutBit(s,t); |
| 321 | } |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 322 | GrAssert(1 == GrDrawState::kMaxTexCoords || |
| 323 | !check_layout(stageMask)); |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 324 | GrAssert(stage_tex_coord_mask(s) == stageMask); |
| 325 | stageMask |= StagePosAsTexCoordVertexLayoutBit(s); |
| 326 | GrAssert(stage_mask(s) == stageMask); |
| 327 | GrAssert(!check_layout(stageMask)); |
| 328 | } |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 329 | for (int t = 0; t < GrDrawState::kMaxTexCoords; ++t) { |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 330 | GrVertexLayout tcMask = 0; |
| 331 | GrAssert(!VertexUsesTexCoordIdx(t, 0)); |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 332 | for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 333 | tcMask |= StageTexCoordVertexLayoutBit(s,t); |
| 334 | GrAssert(VertexUsesStage(s, tcMask)); |
| 335 | GrAssert(sizeof(GrPoint) == VertexStageCoordOffset(s, tcMask)); |
| 336 | GrAssert(VertexUsesTexCoordIdx(t, tcMask)); |
| 337 | GrAssert(2*sizeof(GrPoint) == VertexSize(tcMask)); |
| 338 | GrAssert(t == VertexTexCoordsForStage(s, tcMask)); |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 339 | for (int s2 = s + 1; s2 < GrDrawState::kNumStages; ++s2) { |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 340 | GrAssert(-1 == VertexStageCoordOffset(s2, tcMask)); |
| 341 | GrAssert(!VertexUsesStage(s2, tcMask)); |
| 342 | GrAssert(-1 == VertexTexCoordsForStage(s2, tcMask)); |
| bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 343 | |
| bsalomon@google.com | 1962832 | 2011-02-03 21:30:17 +0000 | [diff] [blame] | 344 | #if GR_DEBUG |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 345 | GrVertexLayout posAsTex = tcMask | StagePosAsTexCoordVertexLayoutBit(s2); |
| bsalomon@google.com | 1962832 | 2011-02-03 21:30:17 +0000 | [diff] [blame] | 346 | #endif |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 347 | GrAssert(0 == VertexStageCoordOffset(s2, posAsTex)); |
| 348 | GrAssert(VertexUsesStage(s2, posAsTex)); |
| 349 | GrAssert(2*sizeof(GrPoint) == VertexSize(posAsTex)); |
| 350 | GrAssert(-1 == VertexTexCoordsForStage(s2, posAsTex)); |
| bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 351 | GrAssert(-1 == VertexEdgeOffset(posAsTex)); |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 352 | } |
| bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 353 | GrAssert(-1 == VertexEdgeOffset(tcMask)); |
| 354 | GrAssert(-1 == VertexColorOffset(tcMask)); |
| bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 355 | GrAssert(-1 == VertexCoverageOffset(tcMask)); |
| bsalomon@google.com | 1962832 | 2011-02-03 21:30:17 +0000 | [diff] [blame] | 356 | #if GR_DEBUG |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 357 | GrVertexLayout withColor = tcMask | kColor_VertexLayoutBit; |
| bsalomon@google.com | 1962832 | 2011-02-03 21:30:17 +0000 | [diff] [blame] | 358 | #endif |
| bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 359 | GrAssert(-1 == VertexCoverageOffset(withColor)); |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 360 | GrAssert(2*sizeof(GrPoint) == VertexColorOffset(withColor)); |
| 361 | GrAssert(2*sizeof(GrPoint) + sizeof(GrColor) == VertexSize(withColor)); |
| bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 362 | #if GR_DEBUG |
| 363 | GrVertexLayout withEdge = tcMask | kEdge_VertexLayoutBit; |
| 364 | #endif |
| 365 | GrAssert(-1 == VertexColorOffset(withEdge)); |
| 366 | GrAssert(2*sizeof(GrPoint) == VertexEdgeOffset(withEdge)); |
| 367 | GrAssert(4*sizeof(GrPoint) == VertexSize(withEdge)); |
| 368 | #if GR_DEBUG |
| 369 | GrVertexLayout withColorAndEdge = withColor | kEdge_VertexLayoutBit; |
| 370 | #endif |
| 371 | GrAssert(2*sizeof(GrPoint) == VertexColorOffset(withColorAndEdge)); |
| 372 | GrAssert(2*sizeof(GrPoint) + sizeof(GrColor) == VertexEdgeOffset(withColorAndEdge)); |
| 373 | GrAssert(4*sizeof(GrPoint) + sizeof(GrColor) == VertexSize(withColorAndEdge)); |
| bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 374 | #if GR_DEBUG |
| 375 | GrVertexLayout withCoverage = tcMask | kCoverage_VertexLayoutBit; |
| 376 | #endif |
| 377 | GrAssert(-1 == VertexColorOffset(withCoverage)); |
| 378 | GrAssert(2*sizeof(GrPoint) == VertexCoverageOffset(withCoverage)); |
| 379 | GrAssert(2*sizeof(GrPoint) + sizeof(GrColor) == VertexSize(withCoverage)); |
| 380 | #if GR_DEBUG |
| 381 | GrVertexLayout withCoverageAndColor = tcMask | kCoverage_VertexLayoutBit | |
| 382 | kColor_VertexLayoutBit; |
| 383 | #endif |
| 384 | GrAssert(2*sizeof(GrPoint) == VertexColorOffset(withCoverageAndColor)); |
| 385 | GrAssert(2*sizeof(GrPoint) + sizeof(GrColor) == VertexCoverageOffset(withCoverageAndColor)); |
| 386 | GrAssert(2*sizeof(GrPoint) + 2 * sizeof(GrColor) == VertexSize(withCoverageAndColor)); |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 387 | } |
| 388 | GrAssert(tex_coord_idx_mask(t) == tcMask); |
| 389 | GrAssert(check_layout(tcMask)); |
| bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 390 | |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 391 | int stageOffsets[GrDrawState::kNumStages]; |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 392 | int colorOffset; |
| bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 393 | int edgeOffset; |
| bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 394 | int coverageOffset; |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 395 | int size; |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 396 | size = VertexSizeAndOffsetsByStage(tcMask, |
| 397 | stageOffsets, &colorOffset, |
| bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 398 | &coverageOffset, &edgeOffset); |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 399 | GrAssert(2*sizeof(GrPoint) == size); |
| 400 | GrAssert(-1 == colorOffset); |
| bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 401 | GrAssert(-1 == coverageOffset); |
| bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 402 | GrAssert(-1 == edgeOffset); |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 403 | for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 404 | GrAssert(VertexUsesStage(s, tcMask)); |
| 405 | GrAssert(sizeof(GrPoint) == stageOffsets[s]); |
| 406 | GrAssert(sizeof(GrPoint) == VertexStageCoordOffset(s, tcMask)); |
| 407 | } |
| 408 | } |
| 409 | } |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | //////////////////////////////////////////////////////////////////////////////// |
| 413 | |
| bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 414 | #define DEBUG_INVAL_BUFFER 0xdeadcafe |
| 415 | #define DEBUG_INVAL_START_IDX -1 |
| 416 | |
| bsalomon@google.com | 9266901 | 2011-09-27 19:10:05 +0000 | [diff] [blame] | 417 | GrDrawTarget::GrDrawTarget() { |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 418 | #if GR_DEBUG |
| 419 | VertexLayoutUnitTest(); |
| 420 | #endif |
| bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 421 | GeometrySrcState& geoSrc = fGeoSrcStateStack.push_back(); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 422 | #if GR_DEBUG |
| bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 423 | geoSrc.fVertexCount = DEBUG_INVAL_START_IDX; |
| 424 | geoSrc.fVertexBuffer = (GrVertexBuffer*)DEBUG_INVAL_BUFFER; |
| 425 | geoSrc.fIndexCount = DEBUG_INVAL_START_IDX; |
| 426 | geoSrc.fIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER; |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 427 | #endif |
| bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 428 | geoSrc.fVertexSrc = kNone_GeometrySrcType; |
| 429 | geoSrc.fIndexSrc = kNone_GeometrySrcType; |
| 430 | } |
| 431 | |
| 432 | GrDrawTarget::~GrDrawTarget() { |
| 433 | int popCnt = fGeoSrcStateStack.count() - 1; |
| 434 | while (popCnt) { |
| 435 | this->popGeometrySource(); |
| 436 | --popCnt; |
| 437 | } |
| 438 | this->releasePreviousVertexSource(); |
| 439 | this->releasePreviousIndexSource(); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | void GrDrawTarget::setClip(const GrClip& clip) { |
| bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 443 | clipWillBeSet(clip); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 444 | fClip = clip; |
| 445 | } |
| 446 | |
| 447 | const GrClip& GrDrawTarget::getClip() const { |
| 448 | return fClip; |
| 449 | } |
| 450 | |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 451 | void GrDrawTarget::setTexture(int stage, GrTexture* tex) { |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 452 | GrAssert(stage >= 0 && stage < GrDrawState::kNumStages); |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 453 | fCurrDrawState.fTextures[stage] = tex; |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 454 | } |
| 455 | |
| bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 456 | const GrTexture* GrDrawTarget::getTexture(int stage) const { |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 457 | GrAssert(stage >= 0 && stage < GrDrawState::kNumStages); |
| bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 458 | return fCurrDrawState.fTextures[stage]; |
| 459 | } |
| 460 | |
| 461 | GrTexture* GrDrawTarget::getTexture(int stage) { |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 462 | GrAssert(stage >= 0 && stage < GrDrawState::kNumStages); |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 463 | return fCurrDrawState.fTextures[stage]; |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | void GrDrawTarget::setRenderTarget(GrRenderTarget* target) { |
| 467 | fCurrDrawState.fRenderTarget = target; |
| 468 | } |
| 469 | |
| bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 470 | const GrRenderTarget* GrDrawTarget::getRenderTarget() const { |
| 471 | return fCurrDrawState.fRenderTarget; |
| 472 | } |
| 473 | |
| 474 | GrRenderTarget* GrDrawTarget::getRenderTarget() { |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 475 | return fCurrDrawState.fRenderTarget; |
| 476 | } |
| 477 | |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 478 | void GrDrawTarget::setViewMatrix(const GrMatrix& m) { |
| 479 | fCurrDrawState.fViewMatrix = m; |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 480 | } |
| 481 | |
| bsalomon@google.com | c6cf723 | 2011-02-17 16:43:10 +0000 | [diff] [blame] | 482 | void GrDrawTarget::preConcatViewMatrix(const GrMatrix& matrix) { |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 483 | fCurrDrawState.fViewMatrix.preConcat(matrix); |
| 484 | } |
| 485 | |
| bsalomon@google.com | 06afe7b | 2011-04-26 15:31:40 +0000 | [diff] [blame] | 486 | void GrDrawTarget::postConcatViewMatrix(const GrMatrix& matrix) { |
| 487 | fCurrDrawState.fViewMatrix.postConcat(matrix); |
| 488 | } |
| 489 | |
| bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 490 | const GrMatrix& GrDrawTarget::getViewMatrix() const { |
| 491 | return fCurrDrawState.fViewMatrix; |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | bool GrDrawTarget::getViewInverse(GrMatrix* matrix) const { |
| bsalomon@google.com | 5782d71 | 2011-01-21 21:03:59 +0000 | [diff] [blame] | 495 | // Mike: Can we cache this somewhere? |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 496 | // Brian: Sure, do we use it often? |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 497 | |
| 498 | GrMatrix inverse; |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 499 | if (fCurrDrawState.fViewMatrix.invert(&inverse)) { |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 500 | if (matrix) { |
| 501 | *matrix = inverse; |
| 502 | } |
| 503 | return true; |
| 504 | } |
| 505 | return false; |
| 506 | } |
| 507 | |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 508 | void GrDrawTarget::setSamplerState(int stage, const GrSamplerState& state) { |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 509 | GrAssert(stage >= 0 && stage < GrDrawState::kNumStages); |
| bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 510 | fCurrDrawState.fSamplerStates[stage] = state; |
| 511 | } |
| 512 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 513 | void GrDrawTarget::enableState(uint32_t bits) { |
| 514 | fCurrDrawState.fFlagBits |= bits; |
| 515 | } |
| 516 | |
| 517 | void GrDrawTarget::disableState(uint32_t bits) { |
| 518 | fCurrDrawState.fFlagBits &= ~(bits); |
| 519 | } |
| 520 | |
| bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 521 | void GrDrawTarget::setBlendFunc(GrBlendCoeff srcCoeff, |
| 522 | GrBlendCoeff dstCoeff) { |
| 523 | fCurrDrawState.fSrcBlend = srcCoeff; |
| 524 | fCurrDrawState.fDstBlend = dstCoeff; |
| 525 | #if GR_DEBUG |
| 526 | switch (dstCoeff) { |
| 527 | case kDC_BlendCoeff: |
| 528 | case kIDC_BlendCoeff: |
| 529 | case kDA_BlendCoeff: |
| 530 | case kIDA_BlendCoeff: |
| 531 | GrPrintf("Unexpected dst blend coeff. Won't work correctly with" |
| 532 | "coverage stages.\n"); |
| 533 | break; |
| 534 | default: |
| 535 | break; |
| 536 | } |
| 537 | switch (srcCoeff) { |
| 538 | case kSC_BlendCoeff: |
| 539 | case kISC_BlendCoeff: |
| 540 | case kSA_BlendCoeff: |
| 541 | case kISA_BlendCoeff: |
| 542 | GrPrintf("Unexpected src blend coeff. Won't work correctly with" |
| 543 | "coverage stages.\n"); |
| 544 | break; |
| 545 | default: |
| 546 | break; |
| 547 | } |
| 548 | #endif |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | void GrDrawTarget::setColor(GrColor c) { |
| 552 | fCurrDrawState.fColor = c; |
| 553 | } |
| 554 | |
| Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 555 | void GrDrawTarget::setColorFilter(GrColor c, SkXfermode::Mode mode) { |
| 556 | fCurrDrawState.fColorFilterColor = c; |
| 557 | fCurrDrawState.fColorFilterXfermode = mode; |
| 558 | } |
| 559 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 560 | void GrDrawTarget::setAlpha(uint8_t a) { |
| 561 | this->setColor((a << 24) | (a << 16) | (a << 8) | a); |
| 562 | } |
| 563 | |
| 564 | void GrDrawTarget::saveCurrentDrawState(SavedDrawState* state) const { |
| 565 | state->fState = fCurrDrawState; |
| 566 | } |
| 567 | |
| 568 | void GrDrawTarget::restoreDrawState(const SavedDrawState& state) { |
| 569 | fCurrDrawState = state.fState; |
| 570 | } |
| 571 | |
| 572 | void GrDrawTarget::copyDrawState(const GrDrawTarget& srcTarget) { |
| 573 | fCurrDrawState = srcTarget.fCurrDrawState; |
| 574 | } |
| 575 | |
| bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 576 | bool GrDrawTarget::reserveVertexSpace(GrVertexLayout vertexLayout, |
| 577 | int vertexCount, |
| 578 | void** vertices) { |
| 579 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 580 | bool acquired = false; |
| 581 | if (vertexCount > 0) { |
| 582 | GrAssert(NULL != vertices); |
| 583 | this->releasePreviousVertexSource(); |
| 584 | geoSrc.fVertexSrc = kNone_GeometrySrcType; |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 585 | |
| bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 586 | acquired = this->onReserveVertexSpace(vertexLayout, |
| 587 | vertexCount, |
| 588 | vertices); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 589 | } |
| bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 590 | if (acquired) { |
| 591 | geoSrc.fVertexSrc = kReserved_GeometrySrcType; |
| 592 | geoSrc.fVertexCount = vertexCount; |
| 593 | geoSrc.fVertexLayout = vertexLayout; |
| 594 | } else if (NULL != vertices) { |
| 595 | *vertices = NULL; |
| 596 | } |
| 597 | return acquired; |
| 598 | } |
| 599 | |
| 600 | bool GrDrawTarget::reserveIndexSpace(int indexCount, |
| 601 | void** indices) { |
| 602 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 603 | bool acquired = false; |
| 604 | if (indexCount > 0) { |
| 605 | GrAssert(NULL != indices); |
| 606 | this->releasePreviousIndexSource(); |
| 607 | geoSrc.fIndexSrc = kNone_GeometrySrcType; |
| 608 | |
| 609 | acquired = this->onReserveIndexSpace(indexCount, indices); |
| 610 | } |
| 611 | if (acquired) { |
| 612 | geoSrc.fIndexSrc = kReserved_GeometrySrcType; |
| 613 | geoSrc.fIndexCount = indexCount; |
| 614 | } else if (NULL != indices) { |
| 615 | *indices = NULL; |
| 616 | } |
| 617 | return acquired; |
| 618 | |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | bool GrDrawTarget::geometryHints(GrVertexLayout vertexLayout, |
| 622 | int32_t* vertexCount, |
| 623 | int32_t* indexCount) const { |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 624 | if (NULL != vertexCount) { |
| 625 | *vertexCount = -1; |
| 626 | } |
| 627 | if (NULL != indexCount) { |
| 628 | *indexCount = -1; |
| 629 | } |
| 630 | return false; |
| 631 | } |
| 632 | |
| bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 633 | void GrDrawTarget::releasePreviousVertexSource() { |
| 634 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 635 | switch (geoSrc.fVertexSrc) { |
| 636 | case kNone_GeometrySrcType: |
| 637 | break; |
| 638 | case kArray_GeometrySrcType: |
| 639 | this->releaseVertexArray(); |
| 640 | break; |
| 641 | case kReserved_GeometrySrcType: |
| 642 | this->releaseReservedVertexSpace(); |
| 643 | break; |
| 644 | case kBuffer_GeometrySrcType: |
| 645 | geoSrc.fVertexBuffer->unref(); |
| 646 | #if GR_DEBUG |
| 647 | geoSrc.fVertexBuffer = (GrVertexBuffer*)DEBUG_INVAL_BUFFER; |
| 648 | #endif |
| 649 | break; |
| 650 | default: |
| 651 | GrCrash("Unknown Vertex Source Type."); |
| 652 | break; |
| 653 | } |
| 654 | } |
| 655 | |
| 656 | void GrDrawTarget::releasePreviousIndexSource() { |
| 657 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 658 | switch (geoSrc.fIndexSrc) { |
| 659 | case kNone_GeometrySrcType: // these two don't require |
| 660 | break; |
| 661 | case kArray_GeometrySrcType: |
| 662 | this->releaseIndexArray(); |
| 663 | break; |
| 664 | case kReserved_GeometrySrcType: |
| 665 | this->releaseReservedIndexSpace(); |
| 666 | break; |
| 667 | case kBuffer_GeometrySrcType: |
| 668 | geoSrc.fIndexBuffer->unref(); |
| 669 | #if GR_DEBUG |
| 670 | geoSrc.fIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER; |
| 671 | #endif |
| 672 | break; |
| 673 | default: |
| 674 | GrCrash("Unknown Index Source Type."); |
| 675 | break; |
| 676 | } |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 677 | } |
| 678 | |
| bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 679 | void GrDrawTarget::setVertexSourceToArray(GrVertexLayout vertexLayout, |
| 680 | const void* vertexArray, |
| 681 | int vertexCount) { |
| bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 682 | this->releasePreviousVertexSource(); |
| 683 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 684 | geoSrc.fVertexSrc = kArray_GeometrySrcType; |
| 685 | geoSrc.fVertexLayout = vertexLayout; |
| 686 | geoSrc.fVertexCount = vertexCount; |
| bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 687 | this->onSetVertexSourceToArray(vertexArray, vertexCount); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 688 | } |
| 689 | |
| bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 690 | void GrDrawTarget::setIndexSourceToArray(const void* indexArray, |
| 691 | int indexCount) { |
| bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 692 | this->releasePreviousIndexSource(); |
| 693 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 694 | geoSrc.fIndexSrc = kArray_GeometrySrcType; |
| 695 | geoSrc.fIndexCount = indexCount; |
| bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 696 | this->onSetIndexSourceToArray(indexArray, indexCount); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 697 | } |
| 698 | |
| bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 699 | void GrDrawTarget::setVertexSourceToBuffer(GrVertexLayout vertexLayout, |
| 700 | const GrVertexBuffer* buffer) { |
| bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 701 | this->releasePreviousVertexSource(); |
| 702 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 703 | geoSrc.fVertexSrc = kBuffer_GeometrySrcType; |
| 704 | geoSrc.fVertexBuffer = buffer; |
| 705 | buffer->ref(); |
| 706 | geoSrc.fVertexLayout = vertexLayout; |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | void GrDrawTarget::setIndexSourceToBuffer(const GrIndexBuffer* buffer) { |
| bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 710 | this->releasePreviousIndexSource(); |
| 711 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 712 | geoSrc.fIndexSrc = kBuffer_GeometrySrcType; |
| 713 | geoSrc.fIndexBuffer = buffer; |
| 714 | buffer->ref(); |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 715 | } |
| 716 | |
| bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 717 | void GrDrawTarget::resetVertexSource() { |
| 718 | this->releasePreviousVertexSource(); |
| 719 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 720 | geoSrc.fVertexSrc = kNone_GeometrySrcType; |
| 721 | } |
| 722 | |
| 723 | void GrDrawTarget::resetIndexSource() { |
| 724 | this->releasePreviousIndexSource(); |
| 725 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 726 | geoSrc.fIndexSrc = kNone_GeometrySrcType; |
| 727 | } |
| 728 | |
| 729 | void GrDrawTarget::pushGeometrySource() { |
| 730 | this->geometrySourceWillPush(); |
| 731 | GeometrySrcState& newState = fGeoSrcStateStack.push_back(); |
| 732 | newState.fIndexSrc = kNone_GeometrySrcType; |
| 733 | newState.fVertexSrc = kNone_GeometrySrcType; |
| 734 | #if GR_DEBUG |
| 735 | newState.fVertexCount = ~0; |
| 736 | newState.fVertexBuffer = (GrVertexBuffer*)~0; |
| 737 | newState.fIndexCount = ~0; |
| 738 | newState.fIndexBuffer = (GrIndexBuffer*)~0; |
| 739 | #endif |
| 740 | } |
| 741 | |
| 742 | void GrDrawTarget::popGeometrySource() { |
| 743 | const GeometrySrcState& geoSrc = this->getGeomSrc(); |
| 744 | // if popping last element then pops are unbalanced with pushes |
| 745 | GrAssert(fGeoSrcStateStack.count() > 1); |
| 746 | |
| 747 | this->geometrySourceWillPop(fGeoSrcStateStack.fromBack(1)); |
| 748 | this->releasePreviousVertexSource(); |
| 749 | this->releasePreviousIndexSource(); |
| 750 | fGeoSrcStateStack.pop_back(); |
| 751 | } |
| 752 | |
| 753 | //////////////////////////////////////////////////////////////////////////////// |
| 754 | |
| 755 | void GrDrawTarget::drawIndexed(GrPrimitiveType type, int startVertex, |
| 756 | int startIndex, int vertexCount, |
| 757 | int indexCount) { |
| 758 | #if GR_DEBUG |
| 759 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 760 | int maxVertex = startVertex + vertexCount; |
| 761 | int maxValidVertex; |
| 762 | switch (geoSrc.fVertexSrc) { |
| 763 | case kNone_GeometrySrcType: |
| 764 | GrCrash("Attempting to draw indexed geom without vertex src."); |
| 765 | case kReserved_GeometrySrcType: // fallthrough |
| 766 | case kArray_GeometrySrcType: |
| 767 | maxValidVertex = geoSrc.fVertexCount; |
| 768 | break; |
| 769 | case kBuffer_GeometrySrcType: |
| bsalomon@google.com | cee661a | 2011-07-26 12:32:36 +0000 | [diff] [blame] | 770 | maxValidVertex = geoSrc.fVertexBuffer->sizeInBytes() / |
| bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 771 | VertexSize(geoSrc.fVertexLayout); |
| 772 | break; |
| 773 | } |
| 774 | if (maxVertex > maxValidVertex) { |
| 775 | GrCrash("Indexed drawing outside valid vertex range."); |
| 776 | } |
| 777 | int maxIndex = startIndex + indexCount; |
| 778 | int maxValidIndex; |
| 779 | switch (geoSrc.fIndexSrc) { |
| 780 | case kNone_GeometrySrcType: |
| 781 | GrCrash("Attempting to draw indexed geom without index src."); |
| 782 | case kReserved_GeometrySrcType: // fallthrough |
| 783 | case kArray_GeometrySrcType: |
| 784 | maxValidIndex = geoSrc.fIndexCount; |
| 785 | break; |
| 786 | case kBuffer_GeometrySrcType: |
| bsalomon@google.com | cee661a | 2011-07-26 12:32:36 +0000 | [diff] [blame] | 787 | maxValidIndex = geoSrc.fIndexBuffer->sizeInBytes() / sizeof(uint16_t); |
| bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 788 | break; |
| 789 | } |
| 790 | if (maxIndex > maxValidIndex) { |
| 791 | GrCrash("Indexed drawing outside valid index range."); |
| 792 | } |
| 793 | #endif |
| bsalomon@google.com | 8214587 | 2011-08-23 14:32:40 +0000 | [diff] [blame] | 794 | if (indexCount > 0) { |
| 795 | this->onDrawIndexed(type, startVertex, startIndex, |
| 796 | vertexCount, indexCount); |
| 797 | } |
| bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | |
| 801 | void GrDrawTarget::drawNonIndexed(GrPrimitiveType type, |
| 802 | int startVertex, |
| 803 | int vertexCount) { |
| 804 | #if GR_DEBUG |
| 805 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 806 | int maxVertex = startVertex + vertexCount; |
| 807 | int maxValidVertex; |
| 808 | switch (geoSrc.fVertexSrc) { |
| 809 | case kNone_GeometrySrcType: |
| 810 | GrCrash("Attempting to draw non-indexed geom without vertex src."); |
| 811 | case kReserved_GeometrySrcType: // fallthrough |
| 812 | case kArray_GeometrySrcType: |
| 813 | maxValidVertex = geoSrc.fVertexCount; |
| 814 | break; |
| 815 | case kBuffer_GeometrySrcType: |
| bsalomon@google.com | cee661a | 2011-07-26 12:32:36 +0000 | [diff] [blame] | 816 | maxValidVertex = geoSrc.fVertexBuffer->sizeInBytes() / |
| bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 817 | VertexSize(geoSrc.fVertexLayout); |
| 818 | break; |
| 819 | } |
| 820 | if (maxVertex > maxValidVertex) { |
| 821 | GrCrash("Non-indexed drawing outside valid vertex range."); |
| 822 | } |
| 823 | #endif |
| bsalomon@google.com | 8214587 | 2011-08-23 14:32:40 +0000 | [diff] [blame] | 824 | if (vertexCount > 0) { |
| 825 | this->onDrawNonIndexed(type, startVertex, vertexCount); |
| 826 | } |
| bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | //////////////////////////////////////////////////////////////////////////////// |
| bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 830 | |
| bsalomon@google.com | d46e242 | 2011-09-23 17:40:07 +0000 | [diff] [blame] | 831 | // Some blend modes allow folding a partial coverage value into the color's |
| 832 | // alpha channel, while others will blend incorrectly. |
| bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 833 | bool GrDrawTarget::canTweakAlphaForCoverage() const { |
| bsalomon@google.com | d46e242 | 2011-09-23 17:40:07 +0000 | [diff] [blame] | 834 | /** |
| 835 | * The fractional coverage is f |
| 836 | * The src and dst coeffs are Cs and Cd |
| 837 | * The dst and src colors are S and D |
| 838 | * We want the blend to compute: f*Cs*S + (f*Cd + (1-f))D |
| 839 | * By tweaking the source color's alpha we're replacing S with S'=fS. It's |
| 840 | * obvious that that first term will always be ok. The second term can be |
| 841 | * rearranged as [1-(1-Cd)f]D. By substituing in the various possbilities |
| 842 | * for Cd we find that only 1, ISA, and ISC produce the correct depth |
| 843 | * coeffecient in terms of S' and D. |
| 844 | */ |
| bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 845 | return kOne_BlendCoeff == fCurrDrawState.fDstBlend|| |
| 846 | kISA_BlendCoeff == fCurrDrawState.fDstBlend || |
| 847 | kISC_BlendCoeff == fCurrDrawState.fDstBlend; |
| bsalomon@google.com | d46e242 | 2011-09-23 17:40:07 +0000 | [diff] [blame] | 848 | } |
| 849 | |
| senorblanco@chromium.org | 92e0f22 | 2011-05-12 15:49:15 +0000 | [diff] [blame] | 850 | |
| bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 851 | bool GrDrawTarget::srcAlphaWillBeOne() const { |
| 852 | const GrVertexLayout& layout = this->getGeomSrc().fVertexLayout; |
| bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 853 | |
| bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 854 | // Check if per-vertex or constant color may have partial alpha |
| bsalomon@google.com | 471d471 | 2011-08-23 15:45:25 +0000 | [diff] [blame] | 855 | if ((layout & kColor_VertexLayoutBit) || |
| bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 856 | 0xff != GrColorUnpackA(fCurrDrawState.fColor)) { |
| bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 857 | return false; |
| 858 | } |
| bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 859 | // Check if color filter could introduce an alpha |
| 860 | // (TODO: Consider being more aggressive with regards to detecting 0xff |
| 861 | // final alpha from color filter). |
| 862 | if (SkXfermode::kDst_Mode != fCurrDrawState.fColorFilterXfermode) { |
| bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 863 | return false; |
| 864 | } |
| bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 865 | // Check if a color stage could create a partial alpha |
| 866 | for (int s = 0; s < fCurrDrawState.fFirstCoverageStage; ++s) { |
| 867 | if (StageWillBeUsed(s, layout, fCurrDrawState)) { |
| 868 | GrAssert(NULL != fCurrDrawState.fTextures[s]); |
| 869 | GrPixelConfig config = fCurrDrawState.fTextures[s]->config(); |
| bsalomon@google.com | a47a48d | 2011-04-26 20:22:11 +0000 | [diff] [blame] | 870 | if (!GrPixelConfigIsOpaque(config)) { |
| bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 871 | return false; |
| 872 | } |
| 873 | } |
| 874 | } |
| bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 875 | return true; |
| 876 | } |
| senorblanco@chromium.org | 92e0f22 | 2011-05-12 15:49:15 +0000 | [diff] [blame] | 877 | |
| bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 878 | GrDrawTarget::BlendOptFlags |
| 879 | GrDrawTarget::getBlendOpts(bool forceCoverage, |
| 880 | GrBlendCoeff* srcCoeff, |
| 881 | GrBlendCoeff* dstCoeff) const { |
| 882 | |
| 883 | const GrVertexLayout& layout = this->getGeomSrc().fVertexLayout; |
| 884 | |
| 885 | GrBlendCoeff bogusSrcCoeff, bogusDstCoeff; |
| 886 | if (NULL == srcCoeff) { |
| 887 | srcCoeff = &bogusSrcCoeff; |
| 888 | } |
| 889 | *srcCoeff = fCurrDrawState.fSrcBlend; |
| 890 | |
| 891 | if (NULL == dstCoeff) { |
| 892 | dstCoeff = &bogusDstCoeff; |
| 893 | } |
| 894 | *dstCoeff = fCurrDrawState.fDstBlend; |
| 895 | |
| 896 | // We don't ever expect source coeffecients to reference the source |
| 897 | GrAssert(kSA_BlendCoeff != *srcCoeff && |
| 898 | kISA_BlendCoeff != *srcCoeff && |
| 899 | kSC_BlendCoeff != *srcCoeff && |
| 900 | kISC_BlendCoeff != *srcCoeff); |
| 901 | // same for dst |
| 902 | GrAssert(kDA_BlendCoeff != *dstCoeff && |
| 903 | kIDA_BlendCoeff != *dstCoeff && |
| 904 | kDC_BlendCoeff != *dstCoeff && |
| 905 | kIDC_BlendCoeff != *dstCoeff); |
| 906 | |
| 907 | if (SkToBool(kNoColorWrites_StateBit & fCurrDrawState.fFlagBits)) { |
| 908 | *srcCoeff = kZero_BlendCoeff; |
| 909 | *dstCoeff = kOne_BlendCoeff; |
| 910 | } |
| 911 | |
| 912 | bool srcAIsOne = this->srcAlphaWillBeOne(); |
| 913 | bool dstCoeffIsOne = kOne_BlendCoeff == *dstCoeff || |
| 914 | (kSA_BlendCoeff == *dstCoeff && srcAIsOne); |
| 915 | bool dstCoeffIsZero = kZero_BlendCoeff == *dstCoeff || |
| 916 | (kISA_BlendCoeff == *dstCoeff && srcAIsOne); |
| 917 | |
| 918 | |
| 919 | // When coeffs are (0,1) there is no reason to draw at all, unless |
| 920 | // stenciling is enabled. Having color writes disabled is effectively |
| 921 | // (0,1). |
| 922 | if ((kZero_BlendCoeff == *srcCoeff && dstCoeffIsOne)) { |
| 923 | if (fCurrDrawState.fStencilSettings.doesWrite()) { |
| 924 | if (fCaps.fShaderSupport) { |
| 925 | return kDisableBlend_BlendOptFlag | |
| 926 | kEmitTransBlack_BlendOptFlag; |
| 927 | } else { |
| 928 | return kDisableBlend_BlendOptFlag; |
| 929 | } |
| 930 | } else { |
| 931 | return kSkipDraw_BlendOptFlag; |
| 932 | } |
| 933 | } |
| 934 | |
| 935 | // check for coverage due to edge aa or coverage texture stage |
| 936 | bool hasCoverage = forceCoverage || |
| 937 | fCurrDrawState.fEdgeAANumEdges > 0 || |
| 938 | (layout & kCoverage_VertexLayoutBit) || |
| 939 | (layout & kEdge_VertexLayoutBit); |
| 940 | for (int s = fCurrDrawState.fFirstCoverageStage; |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 941 | !hasCoverage && s < GrDrawState::kNumStages; |
| bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 942 | ++s) { |
| 943 | if (StageWillBeUsed(s, layout, fCurrDrawState)) { |
| 944 | hasCoverage = true; |
| 945 | } |
| 946 | } |
| 947 | |
| 948 | // if we don't have coverage we can check whether the dst |
| 949 | // has to read at all. If not, we'll disable blending. |
| 950 | if (!hasCoverage) { |
| 951 | if (dstCoeffIsZero) { |
| 952 | if (kOne_BlendCoeff == *srcCoeff) { |
| 953 | // if there is no coverage and coeffs are (1,0) then we |
| 954 | // won't need to read the dst at all, it gets replaced by src |
| 955 | return kDisableBlend_BlendOptFlag; |
| 956 | } else if (kZero_BlendCoeff == *srcCoeff && |
| 957 | fCaps.fShaderSupport) { |
| 958 | // if the op is "clear" then we don't need to emit a color |
| 959 | // or blend, just write transparent black into the dst. |
| 960 | *srcCoeff = kOne_BlendCoeff; |
| 961 | *dstCoeff = kZero_BlendCoeff; |
| 962 | return kDisableBlend_BlendOptFlag | |
| 963 | kEmitTransBlack_BlendOptFlag; |
| 964 | } |
| 965 | } |
| 966 | } else { |
| 967 | // check whether coverage can be safely rolled into alpha |
| 968 | // of if we can skip color computation and just emit coverage |
| 969 | if (this->canTweakAlphaForCoverage()) { |
| 970 | return kCoverageAsAlpha_BlendOptFlag; |
| 971 | } |
| 972 | // We haven't implemented support for these optimizations in the |
| 973 | // fixed pipe (which is on its deathbed) |
| 974 | if (fCaps.fShaderSupport) { |
| 975 | if (dstCoeffIsZero) { |
| 976 | if (kZero_BlendCoeff == *srcCoeff) { |
| 977 | // the source color is not included in the blend |
| 978 | // the dst coeff is effectively zero so blend works out to: |
| 979 | // (c)(0)D + (1-c)D = (1-c)D. |
| 980 | *dstCoeff = kISA_BlendCoeff; |
| 981 | return kEmitCoverage_BlendOptFlag; |
| 982 | } else if (srcAIsOne) { |
| 983 | // the dst coeff is effectively zero so blend works out to: |
| 984 | // cS + (c)(0)D + (1-c)D = cS + (1-c)D. |
| 985 | // If Sa is 1 then we can replace Sa with c |
| 986 | // and set dst coeff to 1-Sa. |
| 987 | *dstCoeff = kISA_BlendCoeff; |
| 988 | return kCoverageAsAlpha_BlendOptFlag; |
| 989 | } |
| 990 | } else if (dstCoeffIsOne) { |
| 991 | // the dst coeff is effectively one so blend works out to: |
| 992 | // cS + (c)(1)D + (1-c)D = cS + D. |
| 993 | *dstCoeff = kOne_BlendCoeff; |
| 994 | return kCoverageAsAlpha_BlendOptFlag; |
| 995 | } |
| 996 | } |
| 997 | } |
| 998 | return kNone_BlendOpt; |
| 999 | } |
| 1000 | |
| 1001 | bool GrDrawTarget::willUseHWAALines() const { |
| bsalomon@google.com | 471d471 | 2011-08-23 15:45:25 +0000 | [diff] [blame] | 1002 | // there is a conflict between using smooth lines and our use of |
| 1003 | // premultiplied alpha. Smooth lines tweak the incoming alpha value |
| 1004 | // but not in a premul-alpha way. So we only use them when our alpha |
| bsalomon@google.com | d46e242 | 2011-09-23 17:40:07 +0000 | [diff] [blame] | 1005 | // is 0xff and tweaking the color for partial coverage is OK |
| bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 1006 | if (!fCaps.fHWAALineSupport || |
| bsalomon@google.com | 289533a | 2011-10-27 12:34:25 +0000 | [diff] [blame] | 1007 | !(kHWAntialias_StateBit & fCurrDrawState.fFlagBits)) { |
| bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 1008 | return false; |
| 1009 | } |
| 1010 | BlendOptFlags opts = this->getBlendOpts(); |
| 1011 | return (kDisableBlend_BlendOptFlag & opts) && |
| 1012 | (kCoverageAsAlpha_BlendOptFlag & opts); |
| bsalomon@google.com | d46e242 | 2011-09-23 17:40:07 +0000 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | bool GrDrawTarget::canApplyCoverage() const { |
| bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 1016 | // we can correctly apply coverage if a) we have dual source blending |
| 1017 | // or b) one of our blend optimizations applies. |
| bsalomon@google.com | d46e242 | 2011-09-23 17:40:07 +0000 | [diff] [blame] | 1018 | return this->getCaps().fDualSourceBlendingSupport || |
| bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 1019 | kNone_BlendOpt != this->getBlendOpts(true); |
| bsalomon@google.com | 471d471 | 2011-08-23 15:45:25 +0000 | [diff] [blame] | 1020 | } |
| 1021 | |
| bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 1022 | bool GrDrawTarget::drawWillReadDst() const { |
| 1023 | return SkToBool((kDisableBlend_BlendOptFlag | kSkipDraw_BlendOptFlag) & |
| 1024 | this->getBlendOpts()); |
| bsalomon@google.com | 471d471 | 2011-08-23 15:45:25 +0000 | [diff] [blame] | 1025 | } |
| 1026 | |
| senorblanco@chromium.org | 92e0f22 | 2011-05-12 15:49:15 +0000 | [diff] [blame] | 1027 | /////////////////////////////////////////////////////////////////////////////// |
| bsalomon@google.com | 471d471 | 2011-08-23 15:45:25 +0000 | [diff] [blame] | 1028 | |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 1029 | void GrDrawTarget::setEdgeAAData(const GrDrawState::Edge* edges, int numEdges) { |
| 1030 | GrAssert(numEdges <= GrDrawState::kMaxEdges); |
| 1031 | memcpy(fCurrDrawState.fEdgeAAEdges, edges, |
| 1032 | numEdges * sizeof(GrDrawState::Edge)); |
| senorblanco@chromium.org | ef3913b | 2011-05-19 17:11:07 +0000 | [diff] [blame] | 1033 | fCurrDrawState.fEdgeAANumEdges = numEdges; |
| senorblanco@chromium.org | 92e0f22 | 2011-05-12 15:49:15 +0000 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | |
| bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 1037 | //////////////////////////////////////////////////////////////////////////////// |
| 1038 | |
| bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 1039 | void GrDrawTarget::drawRect(const GrRect& rect, |
| 1040 | const GrMatrix* matrix, |
| bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 1041 | StageBitfield stageEnableBitfield, |
| bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 1042 | const GrRect* srcRects[], |
| 1043 | const GrMatrix* srcMatrices[]) { |
| bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 1044 | GrVertexLayout layout = GetRectVertexLayout(stageEnableBitfield, srcRects); |
| bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 1045 | |
| 1046 | AutoReleaseGeometry geo(this, layout, 4, 0); |
| bsalomon@google.com | 6513cd0 | 2011-08-05 20:12:30 +0000 | [diff] [blame] | 1047 | if (!geo.succeeded()) { |
| 1048 | GrPrintf("Failed to get space for vertices!\n"); |
| 1049 | return; |
| 1050 | } |
| bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 1051 | |
| 1052 | SetRectVertices(rect, matrix, srcRects, |
| 1053 | srcMatrices, layout, geo.vertices()); |
| 1054 | |
| 1055 | drawNonIndexed(kTriangleFan_PrimitiveType, 0, 4); |
| 1056 | } |
| 1057 | |
| bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 1058 | GrVertexLayout GrDrawTarget::GetRectVertexLayout(StageBitfield stageEnableBitfield, |
| bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 1059 | const GrRect* srcRects[]) { |
| 1060 | GrVertexLayout layout = 0; |
| 1061 | |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 1062 | for (int i = 0; i < GrDrawState::kNumStages; ++i) { |
| bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 1063 | int numTC = 0; |
| bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 1064 | if (stageEnableBitfield & (1 << i)) { |
| bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 1065 | if (NULL != srcRects && NULL != srcRects[i]) { |
| 1066 | layout |= StageTexCoordVertexLayoutBit(i, numTC); |
| 1067 | ++numTC; |
| 1068 | } else { |
| 1069 | layout |= StagePosAsTexCoordVertexLayoutBit(i); |
| 1070 | } |
| 1071 | } |
| 1072 | } |
| 1073 | return layout; |
| 1074 | } |
| bsalomon@google.com | dea2f8d | 2011-08-01 15:51:05 +0000 | [diff] [blame] | 1075 | |
| 1076 | void GrDrawTarget::clipWillBeSet(const GrClip& clip) { |
| 1077 | } |
| 1078 | |
| bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 1079 | void GrDrawTarget::SetRectVertices(const GrRect& rect, |
| 1080 | const GrMatrix* matrix, |
| 1081 | const GrRect* srcRects[], |
| 1082 | const GrMatrix* srcMatrices[], |
| 1083 | GrVertexLayout layout, |
| 1084 | void* vertices) { |
| 1085 | #if GR_DEBUG |
| 1086 | // check that the layout and srcRects agree |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 1087 | for (int i = 0; i < GrDrawState::kNumStages; ++i) { |
| bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 1088 | if (VertexTexCoordsForStage(i, layout) >= 0) { |
| 1089 | GR_DEBUGASSERT(NULL != srcRects && NULL != srcRects[i]); |
| 1090 | } else { |
| 1091 | GR_DEBUGASSERT(NULL == srcRects || NULL == srcRects[i]); |
| 1092 | } |
| 1093 | } |
| 1094 | #endif |
| 1095 | |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 1096 | int stageOffsets[GrDrawState::kNumStages]; |
| bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 1097 | int vsize = VertexSizeAndOffsetsByStage(layout, stageOffsets, |
| 1098 | NULL, NULL, NULL); |
| bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 1099 | |
| bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 1100 | GrTCast<GrPoint*>(vertices)->setRectFan(rect.fLeft, rect.fTop, |
| bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 1101 | rect.fRight, rect.fBottom, |
| 1102 | vsize); |
| 1103 | if (NULL != matrix) { |
| 1104 | matrix->mapPointsWithStride(GrTCast<GrPoint*>(vertices), vsize, 4); |
| 1105 | } |
| 1106 | |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 1107 | for (int i = 0; i < GrDrawState::kNumStages; ++i) { |
| bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 1108 | if (stageOffsets[i] > 0) { |
| bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 1109 | GrPoint* coords = GrTCast<GrPoint*>(GrTCast<intptr_t>(vertices) + |
| bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 1110 | stageOffsets[i]); |
| 1111 | coords->setRectFan(srcRects[i]->fLeft, srcRects[i]->fTop, |
| bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 1112 | srcRects[i]->fRight, srcRects[i]->fBottom, |
| bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 1113 | vsize); |
| 1114 | if (NULL != srcMatrices && NULL != srcMatrices[i]) { |
| 1115 | srcMatrices[i]->mapPointsWithStride(coords, vsize, 4); |
| 1116 | } |
| 1117 | } |
| 1118 | } |
| 1119 | } |
| 1120 | |
| bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 1121 | //////////////////////////////////////////////////////////////////////////////// |
| bsalomon@google.com | 7ac249b | 2011-06-14 18:46:24 +0000 | [diff] [blame] | 1122 | |
| bsalomon@google.com | 06afe7b | 2011-04-26 15:31:40 +0000 | [diff] [blame] | 1123 | GrDrawTarget::AutoStateRestore::AutoStateRestore() { |
| 1124 | fDrawTarget = NULL; |
| 1125 | } |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1126 | |
| 1127 | GrDrawTarget::AutoStateRestore::AutoStateRestore(GrDrawTarget* target) { |
| 1128 | fDrawTarget = target; |
| bsalomon@google.com | 7d34d2e | 2011-01-24 17:41:47 +0000 | [diff] [blame] | 1129 | if (NULL != fDrawTarget) { |
| 1130 | fDrawTarget->saveCurrentDrawState(&fDrawState); |
| 1131 | } |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1132 | } |
| 1133 | |
| 1134 | GrDrawTarget::AutoStateRestore::~AutoStateRestore() { |
| bsalomon@google.com | 7d34d2e | 2011-01-24 17:41:47 +0000 | [diff] [blame] | 1135 | if (NULL != fDrawTarget) { |
| 1136 | fDrawTarget->restoreDrawState(fDrawState); |
| 1137 | } |
| reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1138 | } |
| bsalomon@google.com | 7d34d2e | 2011-01-24 17:41:47 +0000 | [diff] [blame] | 1139 | |
| bsalomon@google.com | 06afe7b | 2011-04-26 15:31:40 +0000 | [diff] [blame] | 1140 | void GrDrawTarget::AutoStateRestore::set(GrDrawTarget* target) { |
| 1141 | if (target != fDrawTarget) { |
| 1142 | if (NULL != fDrawTarget) { |
| 1143 | fDrawTarget->restoreDrawState(fDrawState); |
| 1144 | } |
| 1145 | if (NULL != target) { |
| bsalomon@google.com | d19aa27 | 2011-06-22 01:28:17 +0000 | [diff] [blame] | 1146 | target->saveCurrentDrawState(&fDrawState); |
| bsalomon@google.com | 06afe7b | 2011-04-26 15:31:40 +0000 | [diff] [blame] | 1147 | } |
| 1148 | fDrawTarget = target; |
| 1149 | } |
| 1150 | } |
| bsalomon@google.com | 7ac249b | 2011-06-14 18:46:24 +0000 | [diff] [blame] | 1151 | |
| bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 1152 | //////////////////////////////////////////////////////////////////////////////// |
| bsalomon@google.com | 7ac249b | 2011-06-14 18:46:24 +0000 | [diff] [blame] | 1153 | |
| 1154 | GrDrawTarget::AutoDeviceCoordDraw::AutoDeviceCoordDraw(GrDrawTarget* target, |
| 1155 | int stageMask) { |
| 1156 | GrAssert(NULL != target); |
| 1157 | |
| 1158 | fDrawTarget = target; |
| 1159 | fViewMatrix = target->getViewMatrix(); |
| 1160 | fStageMask = stageMask; |
| 1161 | if (fStageMask) { |
| 1162 | GrMatrix invVM; |
| 1163 | if (fViewMatrix.invert(&invVM)) { |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 1164 | for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
| bsalomon@google.com | 7ac249b | 2011-06-14 18:46:24 +0000 | [diff] [blame] | 1165 | if (fStageMask & (1 << s)) { |
| 1166 | fSamplerMatrices[s] = target->getSamplerMatrix(s); |
| 1167 | } |
| 1168 | } |
| 1169 | target->preConcatSamplerMatrices(fStageMask, invVM); |
| 1170 | } else { |
| 1171 | // sad trombone sound |
| 1172 | fStageMask = 0; |
| 1173 | } |
| 1174 | } |
| 1175 | target->setViewMatrix(GrMatrix::I()); |
| 1176 | } |
| 1177 | |
| 1178 | GrDrawTarget::AutoDeviceCoordDraw::~AutoDeviceCoordDraw() { |
| 1179 | fDrawTarget->setViewMatrix(fViewMatrix); |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame^] | 1180 | for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
| bsalomon@google.com | 7ac249b | 2011-06-14 18:46:24 +0000 | [diff] [blame] | 1181 | if (fStageMask & (1 << s)) { |
| 1182 | fDrawTarget->setSamplerMatrix(s, fSamplerMatrices[s]); |
| 1183 | } |
| 1184 | } |
| 1185 | } |
| 1186 | |
| bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 1187 | //////////////////////////////////////////////////////////////////////////////// |
| 1188 | |
| 1189 | GrDrawTarget::AutoReleaseGeometry::AutoReleaseGeometry( |
| 1190 | GrDrawTarget* target, |
| 1191 | GrVertexLayout vertexLayout, |
| 1192 | int vertexCount, |
| 1193 | int indexCount) { |
| 1194 | fTarget = NULL; |
| 1195 | this->set(target, vertexLayout, vertexCount, indexCount); |
| 1196 | } |
| 1197 | |
| 1198 | GrDrawTarget::AutoReleaseGeometry::AutoReleaseGeometry() { |
| 1199 | fTarget = NULL; |
| 1200 | } |
| 1201 | |
| 1202 | GrDrawTarget::AutoReleaseGeometry::~AutoReleaseGeometry() { |
| 1203 | this->reset(); |
| 1204 | } |
| 1205 | |
| 1206 | bool GrDrawTarget::AutoReleaseGeometry::set(GrDrawTarget* target, |
| 1207 | GrVertexLayout vertexLayout, |
| 1208 | int vertexCount, |
| 1209 | int indexCount) { |
| 1210 | this->reset(); |
| 1211 | fTarget = target; |
| 1212 | bool success = true; |
| 1213 | if (NULL != fTarget) { |
| 1214 | fTarget = target; |
| 1215 | if (vertexCount > 0) { |
| 1216 | success = target->reserveVertexSpace(vertexLayout, |
| 1217 | vertexCount, |
| 1218 | &fVertices); |
| 1219 | if (!success) { |
| 1220 | this->reset(); |
| 1221 | } |
| 1222 | } |
| 1223 | if (success && indexCount > 0) { |
| 1224 | success = target->reserveIndexSpace(indexCount, &fIndices); |
| 1225 | if (!success) { |
| 1226 | this->reset(); |
| 1227 | } |
| 1228 | } |
| 1229 | } |
| 1230 | GrAssert(success == (NULL != fTarget)); |
| 1231 | return success; |
| 1232 | } |
| 1233 | |
| 1234 | void GrDrawTarget::AutoReleaseGeometry::reset() { |
| 1235 | if (NULL != fTarget) { |
| 1236 | if (NULL != fVertices) { |
| 1237 | fTarget->resetVertexSource(); |
| 1238 | } |
| 1239 | if (NULL != fIndices) { |
| 1240 | fTarget->resetIndexSource(); |
| 1241 | } |
| 1242 | fTarget = NULL; |
| 1243 | } |
| bsalomon@google.com | cb0c5ab | 2011-06-29 17:48:17 +0000 | [diff] [blame] | 1244 | fVertices = NULL; |
| 1245 | fIndices = NULL; |
| bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 1246 | } |
| 1247 | |
| bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 1248 | void GrDrawTarget::Caps::print() const { |
| 1249 | static const char* gNY[] = {"NO", "YES"}; |
| 1250 | GrPrintf("8 Bit Palette Support : %s\n", gNY[f8BitPaletteSupport]); |
| 1251 | GrPrintf("NPOT Texture Support : %s\n", gNY[fNPOTTextureSupport]); |
| 1252 | GrPrintf("NPOT Texture Tile Support : %s\n", gNY[fNPOTTextureTileSupport]); |
| 1253 | GrPrintf("NPOT Render Target Support : %s\n", gNY[fNPOTRenderTargetSupport]); |
| 1254 | GrPrintf("Two Sided Stencil Support : %s\n", gNY[fTwoSidedStencilSupport]); |
| 1255 | GrPrintf("Stencil Wrap Ops Support : %s\n", gNY[fStencilWrapOpsSupport]); |
| 1256 | GrPrintf("HW AA Lines Support : %s\n", gNY[fHWAALineSupport]); |
| 1257 | GrPrintf("Shader Support : %s\n", gNY[fShaderSupport]); |
| 1258 | GrPrintf("Shader Derivative Support : %s\n", gNY[fShaderDerivativeSupport]); |
| bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 1259 | GrPrintf("Geometry Shader Support : %s\n", gNY[fGeometryShaderSupport]); |
| bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 1260 | GrPrintf("FSAA Support : %s\n", gNY[fFSAASupport]); |
| 1261 | GrPrintf("Dual Source Blending Support: %s\n", gNY[fDualSourceBlendingSupport]); |
| 1262 | GrPrintf("Buffer Lock Support : %s\n", gNY[fBufferLockSupport]); |
| 1263 | GrPrintf("Min Render Target Width : %d\n", fMinRenderTargetWidth); |
| 1264 | GrPrintf("Min Render Target Height : %d\n", fMinRenderTargetHeight); |
| 1265 | GrPrintf("Max Texture Size : %d\n", fMaxTextureSize); |
| 1266 | GrPrintf("Max Render Target Size : %d\n", fMaxRenderTargetSize); |
| 1267 | } |
| 1268 | |