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" |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 12 | #include "GrRenderTarget.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" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 15 | |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 16 | #include "SkStrokeRec.h" |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 17 | |
reed@google.com | fa35e3d | 2012-06-26 20:16:17 +0000 | [diff] [blame] | 18 | SK_DEFINE_INST_COUNT(GrDrawTarget) |
| 19 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 20 | //////////////////////////////////////////////////////////////////////////////// |
| 21 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 22 | GrDrawTarget::DrawInfo& GrDrawTarget::DrawInfo::operator =(const DrawInfo& di) { |
| 23 | fPrimitiveType = di.fPrimitiveType; |
| 24 | fStartVertex = di.fStartVertex; |
| 25 | fStartIndex = di.fStartIndex; |
| 26 | fVertexCount = di.fVertexCount; |
| 27 | fIndexCount = di.fIndexCount; |
| 28 | |
| 29 | fInstanceCount = di.fInstanceCount; |
| 30 | fVerticesPerInstance = di.fVerticesPerInstance; |
| 31 | fIndicesPerInstance = di.fIndicesPerInstance; |
| 32 | |
| 33 | if (NULL != di.fDevBounds) { |
| 34 | GrAssert(di.fDevBounds == &di.fDevBoundsStorage); |
| 35 | fDevBoundsStorage = di.fDevBoundsStorage; |
| 36 | fDevBounds = &fDevBoundsStorage; |
| 37 | } else { |
| 38 | fDevBounds = NULL; |
| 39 | } |
| 40 | return *this; |
| 41 | } |
| 42 | |
| 43 | #if GR_DEBUG |
| 44 | bool GrDrawTarget::DrawInfo::isInstanced() const { |
| 45 | if (fInstanceCount > 0) { |
| 46 | GrAssert(0 == fIndexCount % fIndicesPerInstance); |
| 47 | GrAssert(0 == fVertexCount % fVerticesPerInstance); |
| 48 | GrAssert(fIndexCount / fIndicesPerInstance == fInstanceCount); |
| 49 | GrAssert(fVertexCount / fVerticesPerInstance == fInstanceCount); |
| 50 | // there is no way to specify a non-zero start index to drawIndexedInstances(). |
| 51 | GrAssert(0 == fStartIndex); |
| 52 | return true; |
| 53 | } else { |
| 54 | GrAssert(!fVerticesPerInstance); |
| 55 | GrAssert(!fIndicesPerInstance); |
| 56 | return false; |
| 57 | } |
| 58 | } |
| 59 | #endif |
| 60 | |
| 61 | void GrDrawTarget::DrawInfo::adjustInstanceCount(int instanceOffset) { |
| 62 | GrAssert(this->isInstanced()); |
| 63 | GrAssert(instanceOffset + fInstanceCount >= 0); |
| 64 | fInstanceCount += instanceOffset; |
| 65 | fVertexCount = fVerticesPerInstance * fInstanceCount; |
| 66 | fIndexCount = fIndicesPerInstance * fInstanceCount; |
| 67 | } |
| 68 | |
| 69 | void GrDrawTarget::DrawInfo::adjustStartVertex(int vertexOffset) { |
| 70 | fStartVertex += vertexOffset; |
| 71 | GrAssert(fStartVertex >= 0); |
| 72 | } |
| 73 | |
| 74 | void GrDrawTarget::DrawInfo::adjustStartIndex(int indexOffset) { |
| 75 | GrAssert(this->isIndexed()); |
| 76 | fStartIndex += indexOffset; |
| 77 | GrAssert(fStartIndex >= 0); |
| 78 | } |
| 79 | |
| 80 | //////////////////////////////////////////////////////////////////////////////// |
| 81 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 82 | #define DEBUG_INVAL_BUFFER 0xdeadcafe |
| 83 | #define DEBUG_INVAL_START_IDX -1 |
| 84 | |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 85 | GrDrawTarget::GrDrawTarget() : fClip(NULL) { |
bsalomon@google.com | a5d056a | 2012-03-27 15:59:58 +0000 | [diff] [blame] | 86 | fDrawState = &fDefaultDrawState; |
| 87 | // We assume that fDrawState always owns a ref to the object it points at. |
| 88 | fDefaultDrawState.ref(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 89 | GeometrySrcState& geoSrc = fGeoSrcStateStack.push_back(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 90 | #if GR_DEBUG |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 91 | geoSrc.fVertexCount = DEBUG_INVAL_START_IDX; |
| 92 | geoSrc.fVertexBuffer = (GrVertexBuffer*)DEBUG_INVAL_BUFFER; |
| 93 | geoSrc.fIndexCount = DEBUG_INVAL_START_IDX; |
| 94 | geoSrc.fIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 95 | #endif |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 96 | geoSrc.fVertexSrc = kNone_GeometrySrcType; |
| 97 | geoSrc.fIndexSrc = kNone_GeometrySrcType; |
| 98 | } |
| 99 | |
| 100 | GrDrawTarget::~GrDrawTarget() { |
bsalomon@google.com | 4a018bb | 2011-10-28 19:50:21 +0000 | [diff] [blame] | 101 | GrAssert(1 == fGeoSrcStateStack.count()); |
humper@google.com | 0e51577 | 2013-01-07 19:54:40 +0000 | [diff] [blame] | 102 | SkDEBUGCODE(GeometrySrcState& geoSrc = fGeoSrcStateStack.back()); |
bsalomon@google.com | 4a018bb | 2011-10-28 19:50:21 +0000 | [diff] [blame] | 103 | GrAssert(kNone_GeometrySrcType == geoSrc.fIndexSrc); |
| 104 | GrAssert(kNone_GeometrySrcType == geoSrc.fVertexSrc); |
bsalomon@google.com | a5d056a | 2012-03-27 15:59:58 +0000 | [diff] [blame] | 105 | fDrawState->unref(); |
bsalomon@google.com | 4a018bb | 2011-10-28 19:50:21 +0000 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | void GrDrawTarget::releaseGeometry() { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 109 | int popCnt = fGeoSrcStateStack.count() - 1; |
| 110 | while (popCnt) { |
| 111 | this->popGeometrySource(); |
| 112 | --popCnt; |
| 113 | } |
bsalomon@google.com | 4a018bb | 2011-10-28 19:50:21 +0000 | [diff] [blame] | 114 | this->resetVertexSource(); |
| 115 | this->resetIndexSource(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 116 | } |
| 117 | |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 118 | void GrDrawTarget::setClip(const GrClipData* clip) { |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 119 | clipWillBeSet(clip); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 120 | fClip = clip; |
| 121 | } |
| 122 | |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 123 | const GrClipData* GrDrawTarget::getClip() const { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 124 | return fClip; |
| 125 | } |
| 126 | |
bsalomon@google.com | a5d056a | 2012-03-27 15:59:58 +0000 | [diff] [blame] | 127 | void GrDrawTarget::setDrawState(GrDrawState* drawState) { |
| 128 | GrAssert(NULL != fDrawState); |
| 129 | if (NULL == drawState) { |
| 130 | drawState = &fDefaultDrawState; |
| 131 | } |
| 132 | if (fDrawState != drawState) { |
| 133 | fDrawState->unref(); |
| 134 | drawState->ref(); |
| 135 | fDrawState = drawState; |
| 136 | } |
| 137 | } |
| 138 | |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 139 | bool GrDrawTarget::reserveVertexSpace(size_t vertexSize, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 140 | int vertexCount, |
| 141 | void** vertices) { |
| 142 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 143 | bool acquired = false; |
| 144 | if (vertexCount > 0) { |
| 145 | GrAssert(NULL != vertices); |
| 146 | this->releasePreviousVertexSource(); |
| 147 | geoSrc.fVertexSrc = kNone_GeometrySrcType; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 148 | |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 149 | acquired = this->onReserveVertexSpace(vertexSize, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 150 | vertexCount, |
| 151 | vertices); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 152 | } |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 153 | if (acquired) { |
| 154 | geoSrc.fVertexSrc = kReserved_GeometrySrcType; |
| 155 | geoSrc.fVertexCount = vertexCount; |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 156 | geoSrc.fVertexSize = vertexSize; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 157 | } else if (NULL != vertices) { |
| 158 | *vertices = NULL; |
| 159 | } |
| 160 | return acquired; |
| 161 | } |
| 162 | |
| 163 | bool GrDrawTarget::reserveIndexSpace(int indexCount, |
| 164 | void** indices) { |
| 165 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 166 | bool acquired = false; |
| 167 | if (indexCount > 0) { |
| 168 | GrAssert(NULL != indices); |
| 169 | this->releasePreviousIndexSource(); |
| 170 | geoSrc.fIndexSrc = kNone_GeometrySrcType; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 171 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 172 | acquired = this->onReserveIndexSpace(indexCount, indices); |
| 173 | } |
| 174 | if (acquired) { |
| 175 | geoSrc.fIndexSrc = kReserved_GeometrySrcType; |
| 176 | geoSrc.fIndexCount = indexCount; |
| 177 | } else if (NULL != indices) { |
| 178 | *indices = NULL; |
| 179 | } |
| 180 | return acquired; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 181 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 182 | } |
| 183 | |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 184 | bool GrDrawTarget::reserveVertexAndIndexSpace(int vertexCount, |
bsalomon@google.com | e3d7095 | 2012-03-13 12:40:53 +0000 | [diff] [blame] | 185 | int indexCount, |
| 186 | void** vertices, |
| 187 | void** indices) { |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 188 | size_t vertexSize = this->drawState()->getVertexSize(); |
| 189 | this->willReserveVertexAndIndexSpace(vertexCount, indexCount); |
bsalomon@google.com | e3d7095 | 2012-03-13 12:40:53 +0000 | [diff] [blame] | 190 | if (vertexCount) { |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 191 | if (!this->reserveVertexSpace(vertexSize, vertexCount, vertices)) { |
bsalomon@google.com | e3d7095 | 2012-03-13 12:40:53 +0000 | [diff] [blame] | 192 | if (indexCount) { |
| 193 | this->resetIndexSource(); |
| 194 | } |
| 195 | return false; |
| 196 | } |
| 197 | } |
| 198 | if (indexCount) { |
| 199 | if (!this->reserveIndexSpace(indexCount, indices)) { |
| 200 | if (vertexCount) { |
| 201 | this->resetVertexSource(); |
| 202 | } |
| 203 | return false; |
| 204 | } |
| 205 | } |
| 206 | return true; |
| 207 | } |
| 208 | |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 209 | bool GrDrawTarget::geometryHints(int32_t* vertexCount, |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 210 | int32_t* indexCount) const { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 211 | if (NULL != vertexCount) { |
| 212 | *vertexCount = -1; |
| 213 | } |
| 214 | if (NULL != indexCount) { |
| 215 | *indexCount = -1; |
| 216 | } |
| 217 | return false; |
| 218 | } |
| 219 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 220 | void GrDrawTarget::releasePreviousVertexSource() { |
| 221 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 222 | switch (geoSrc.fVertexSrc) { |
| 223 | case kNone_GeometrySrcType: |
| 224 | break; |
| 225 | case kArray_GeometrySrcType: |
| 226 | this->releaseVertexArray(); |
| 227 | break; |
| 228 | case kReserved_GeometrySrcType: |
| 229 | this->releaseReservedVertexSpace(); |
| 230 | break; |
| 231 | case kBuffer_GeometrySrcType: |
| 232 | geoSrc.fVertexBuffer->unref(); |
| 233 | #if GR_DEBUG |
| 234 | geoSrc.fVertexBuffer = (GrVertexBuffer*)DEBUG_INVAL_BUFFER; |
| 235 | #endif |
| 236 | break; |
| 237 | default: |
| 238 | GrCrash("Unknown Vertex Source Type."); |
| 239 | break; |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | void GrDrawTarget::releasePreviousIndexSource() { |
| 244 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 245 | switch (geoSrc.fIndexSrc) { |
| 246 | case kNone_GeometrySrcType: // these two don't require |
| 247 | break; |
| 248 | case kArray_GeometrySrcType: |
| 249 | this->releaseIndexArray(); |
| 250 | break; |
| 251 | case kReserved_GeometrySrcType: |
| 252 | this->releaseReservedIndexSpace(); |
| 253 | break; |
| 254 | case kBuffer_GeometrySrcType: |
| 255 | geoSrc.fIndexBuffer->unref(); |
| 256 | #if GR_DEBUG |
| 257 | geoSrc.fIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER; |
| 258 | #endif |
| 259 | break; |
| 260 | default: |
| 261 | GrCrash("Unknown Index Source Type."); |
| 262 | break; |
| 263 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 264 | } |
| 265 | |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 266 | void GrDrawTarget::setVertexSourceToArray(const void* vertexArray, |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 267 | int vertexCount) { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 268 | this->releasePreviousVertexSource(); |
| 269 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 270 | geoSrc.fVertexSrc = kArray_GeometrySrcType; |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 271 | geoSrc.fVertexSize = this->drawState()->getVertexSize(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 272 | geoSrc.fVertexCount = vertexCount; |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 273 | this->onSetVertexSourceToArray(vertexArray, vertexCount); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 274 | } |
| 275 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 276 | void GrDrawTarget::setIndexSourceToArray(const void* indexArray, |
| 277 | int indexCount) { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 278 | this->releasePreviousIndexSource(); |
| 279 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 280 | geoSrc.fIndexSrc = kArray_GeometrySrcType; |
| 281 | geoSrc.fIndexCount = indexCount; |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 282 | this->onSetIndexSourceToArray(indexArray, indexCount); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 283 | } |
| 284 | |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 285 | void GrDrawTarget::setVertexSourceToBuffer(const GrVertexBuffer* buffer) { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 286 | this->releasePreviousVertexSource(); |
| 287 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 288 | geoSrc.fVertexSrc = kBuffer_GeometrySrcType; |
| 289 | geoSrc.fVertexBuffer = buffer; |
| 290 | buffer->ref(); |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 291 | geoSrc.fVertexSize = this->drawState()->getVertexSize(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | void GrDrawTarget::setIndexSourceToBuffer(const GrIndexBuffer* buffer) { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 295 | this->releasePreviousIndexSource(); |
| 296 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 297 | geoSrc.fIndexSrc = kBuffer_GeometrySrcType; |
| 298 | geoSrc.fIndexBuffer = buffer; |
| 299 | buffer->ref(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 300 | } |
| 301 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 302 | void GrDrawTarget::resetVertexSource() { |
| 303 | this->releasePreviousVertexSource(); |
| 304 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 305 | geoSrc.fVertexSrc = kNone_GeometrySrcType; |
| 306 | } |
| 307 | |
| 308 | void GrDrawTarget::resetIndexSource() { |
| 309 | this->releasePreviousIndexSource(); |
| 310 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 311 | geoSrc.fIndexSrc = kNone_GeometrySrcType; |
| 312 | } |
| 313 | |
| 314 | void GrDrawTarget::pushGeometrySource() { |
| 315 | this->geometrySourceWillPush(); |
| 316 | GeometrySrcState& newState = fGeoSrcStateStack.push_back(); |
| 317 | newState.fIndexSrc = kNone_GeometrySrcType; |
| 318 | newState.fVertexSrc = kNone_GeometrySrcType; |
| 319 | #if GR_DEBUG |
| 320 | newState.fVertexCount = ~0; |
| 321 | newState.fVertexBuffer = (GrVertexBuffer*)~0; |
| 322 | newState.fIndexCount = ~0; |
| 323 | newState.fIndexBuffer = (GrIndexBuffer*)~0; |
| 324 | #endif |
| 325 | } |
| 326 | |
| 327 | void GrDrawTarget::popGeometrySource() { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 328 | // if popping last element then pops are unbalanced with pushes |
| 329 | GrAssert(fGeoSrcStateStack.count() > 1); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 330 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 331 | this->geometrySourceWillPop(fGeoSrcStateStack.fromBack(1)); |
| 332 | this->releasePreviousVertexSource(); |
| 333 | this->releasePreviousIndexSource(); |
| 334 | fGeoSrcStateStack.pop_back(); |
| 335 | } |
| 336 | |
| 337 | //////////////////////////////////////////////////////////////////////////////// |
| 338 | |
bsalomon@google.com | e826262 | 2011-11-07 02:30:51 +0000 | [diff] [blame] | 339 | bool GrDrawTarget::checkDraw(GrPrimitiveType type, int startVertex, |
| 340 | int startIndex, int vertexCount, |
| 341 | int indexCount) const { |
bsalomon@google.com | cddaf34 | 2012-07-30 13:09:05 +0000 | [diff] [blame] | 342 | const GrDrawState& drawState = this->getDrawState(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 343 | #if GR_DEBUG |
bsalomon@google.com | e826262 | 2011-11-07 02:30:51 +0000 | [diff] [blame] | 344 | const GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 345 | int maxVertex = startVertex + vertexCount; |
| 346 | int maxValidVertex; |
| 347 | switch (geoSrc.fVertexSrc) { |
| 348 | case kNone_GeometrySrcType: |
bsalomon@google.com | e826262 | 2011-11-07 02:30:51 +0000 | [diff] [blame] | 349 | GrCrash("Attempting to draw without vertex src."); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 350 | case kReserved_GeometrySrcType: // fallthrough |
| 351 | case kArray_GeometrySrcType: |
| 352 | maxValidVertex = geoSrc.fVertexCount; |
| 353 | break; |
| 354 | case kBuffer_GeometrySrcType: |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 355 | maxValidVertex = geoSrc.fVertexBuffer->sizeInBytes() / geoSrc.fVertexSize; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 356 | break; |
| 357 | } |
| 358 | if (maxVertex > maxValidVertex) { |
bsalomon@google.com | e826262 | 2011-11-07 02:30:51 +0000 | [diff] [blame] | 359 | GrCrash("Drawing outside valid vertex range."); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 360 | } |
bsalomon@google.com | e826262 | 2011-11-07 02:30:51 +0000 | [diff] [blame] | 361 | if (indexCount > 0) { |
| 362 | int maxIndex = startIndex + indexCount; |
| 363 | int maxValidIndex; |
| 364 | switch (geoSrc.fIndexSrc) { |
| 365 | case kNone_GeometrySrcType: |
| 366 | GrCrash("Attempting to draw indexed geom without index src."); |
| 367 | case kReserved_GeometrySrcType: // fallthrough |
| 368 | case kArray_GeometrySrcType: |
| 369 | maxValidIndex = geoSrc.fIndexCount; |
| 370 | break; |
| 371 | case kBuffer_GeometrySrcType: |
| 372 | maxValidIndex = geoSrc.fIndexBuffer->sizeInBytes() / sizeof(uint16_t); |
| 373 | break; |
| 374 | } |
| 375 | if (maxIndex > maxValidIndex) { |
| 376 | GrCrash("Index reads outside valid index range."); |
| 377 | } |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 378 | } |
bsalomon@google.com | b4725b4 | 2012-03-30 17:24:17 +0000 | [diff] [blame] | 379 | |
bsalomon@google.com | cddaf34 | 2012-07-30 13:09:05 +0000 | [diff] [blame] | 380 | GrAssert(NULL != drawState.getRenderTarget()); |
| 381 | for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
| 382 | if (drawState.isStageEnabled(s)) { |
bsalomon@google.com | 6340a41 | 2013-01-22 19:55:59 +0000 | [diff] [blame] | 383 | const GrEffectRef& effect = *drawState.getStage(s).getEffect(); |
bsalomon@google.com | 021fc73 | 2012-10-25 12:47:42 +0000 | [diff] [blame] | 384 | int numTextures = effect->numTextures(); |
bsalomon@google.com | cddaf34 | 2012-07-30 13:09:05 +0000 | [diff] [blame] | 385 | for (int t = 0; t < numTextures; ++t) { |
bsalomon@google.com | 021fc73 | 2012-10-25 12:47:42 +0000 | [diff] [blame] | 386 | GrTexture* texture = effect->texture(t); |
bsalomon@google.com | cddaf34 | 2012-07-30 13:09:05 +0000 | [diff] [blame] | 387 | GrAssert(texture->asRenderTarget() != drawState.getRenderTarget()); |
| 388 | } |
bsalomon@google.com | b4725b4 | 2012-03-30 17:24:17 +0000 | [diff] [blame] | 389 | } |
| 390 | } |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 391 | #endif |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 392 | if (NULL == drawState.getRenderTarget()) { |
bsalomon@google.com | 0ba52fc | 2011-11-10 22:16:06 +0000 | [diff] [blame] | 393 | return false; |
| 394 | } |
bsalomon@google.com | e826262 | 2011-11-07 02:30:51 +0000 | [diff] [blame] | 395 | return true; |
| 396 | } |
| 397 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 398 | void GrDrawTarget::drawIndexed(GrPrimitiveType type, |
| 399 | int startVertex, |
| 400 | int startIndex, |
| 401 | int vertexCount, |
| 402 | int indexCount, |
| 403 | const SkRect* devBounds) { |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 404 | if (indexCount > 0 && this->checkDraw(type, startVertex, startIndex, vertexCount, indexCount)) { |
| 405 | DrawInfo info; |
| 406 | info.fPrimitiveType = type; |
| 407 | info.fStartVertex = startVertex; |
| 408 | info.fStartIndex = startIndex; |
| 409 | info.fVertexCount = vertexCount; |
| 410 | info.fIndexCount = indexCount; |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 411 | |
| 412 | info.fInstanceCount = 0; |
| 413 | info.fVerticesPerInstance = 0; |
| 414 | info.fIndicesPerInstance = 0; |
| 415 | |
| 416 | if (NULL != devBounds) { |
| 417 | info.setDevBounds(*devBounds); |
| 418 | } |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 419 | this->onDraw(info); |
bsalomon@google.com | 8214587 | 2011-08-23 14:32:40 +0000 | [diff] [blame] | 420 | } |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 421 | } |
| 422 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 423 | void GrDrawTarget::drawNonIndexed(GrPrimitiveType type, |
| 424 | int startVertex, |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 425 | int vertexCount, |
| 426 | const SkRect* devBounds) { |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 427 | if (vertexCount > 0 && this->checkDraw(type, startVertex, -1, vertexCount, -1)) { |
| 428 | DrawInfo info; |
| 429 | info.fPrimitiveType = type; |
| 430 | info.fStartVertex = startVertex; |
| 431 | info.fStartIndex = 0; |
| 432 | info.fVertexCount = vertexCount; |
| 433 | info.fIndexCount = 0; |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 434 | |
| 435 | info.fInstanceCount = 0; |
| 436 | info.fVerticesPerInstance = 0; |
| 437 | info.fIndicesPerInstance = 0; |
| 438 | |
| 439 | if (NULL != devBounds) { |
| 440 | info.setDevBounds(*devBounds); |
| 441 | } |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 442 | this->onDraw(info); |
bsalomon@google.com | 8214587 | 2011-08-23 14:32:40 +0000 | [diff] [blame] | 443 | } |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 444 | } |
| 445 | |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 446 | void GrDrawTarget::stencilPath(const GrPath* path, const SkStrokeRec& stroke, SkPath::FillType fill) { |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 447 | // TODO: extract portions of checkDraw that are relevant to path stenciling. |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 448 | GrAssert(NULL != path); |
bsalomon@google.com | f660187 | 2012-08-28 21:11:35 +0000 | [diff] [blame] | 449 | GrAssert(fCaps.pathStencilingSupport()); |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 450 | GrAssert(!stroke.isHairlineStyle()); |
| 451 | GrAssert(!SkPath::IsInverseFillType(fill)); |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 452 | this->onStencilPath(path, stroke, fill); |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 453 | } |
| 454 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 455 | //////////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 456 | |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 457 | bool GrDrawTarget::willUseHWAALines() const { |
bsalomon@google.com | 2b44673 | 2013-02-12 16:47:41 +0000 | [diff] [blame] | 458 | // There is a conflict between using smooth lines and our use of premultiplied alpha. Smooth |
| 459 | // lines tweak the incoming alpha value but not in a premul-alpha way. So we only use them when |
| 460 | // our alpha is 0xff and tweaking the color for partial coverage is OK |
bsalomon@google.com | f660187 | 2012-08-28 21:11:35 +0000 | [diff] [blame] | 461 | if (!fCaps.hwAALineSupport() || |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 462 | !this->getDrawState().isHWAntialiasState()) { |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 463 | return false; |
| 464 | } |
bsalomon@google.com | 2b44673 | 2013-02-12 16:47:41 +0000 | [diff] [blame] | 465 | GrDrawState::BlendOptFlags opts = this->getDrawState().getBlendOpts(); |
| 466 | return (GrDrawState::kDisableBlend_BlendOptFlag & opts) && |
| 467 | (GrDrawState::kCoverageAsAlpha_BlendOptFlag & opts); |
bsalomon@google.com | d46e242 | 2011-09-23 17:40:07 +0000 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | bool GrDrawTarget::canApplyCoverage() const { |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 471 | // we can correctly apply coverage if a) we have dual source blending |
| 472 | // or b) one of our blend optimizations applies. |
bsalomon@google.com | f660187 | 2012-08-28 21:11:35 +0000 | [diff] [blame] | 473 | return this->getCaps().dualSourceBlendingSupport() || |
bsalomon@google.com | 2b44673 | 2013-02-12 16:47:41 +0000 | [diff] [blame] | 474 | GrDrawState::kNone_BlendOpt != this->getDrawState().getBlendOpts(true); |
bsalomon@google.com | 471d471 | 2011-08-23 15:45:25 +0000 | [diff] [blame] | 475 | } |
| 476 | |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 477 | //////////////////////////////////////////////////////////////////////////////// |
| 478 | |
| 479 | void GrDrawTarget::drawIndexedInstances(GrPrimitiveType type, |
| 480 | int instanceCount, |
| 481 | int verticesPerInstance, |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 482 | int indicesPerInstance, |
| 483 | const SkRect* devBounds) { |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 484 | if (!verticesPerInstance || !indicesPerInstance) { |
| 485 | return; |
| 486 | } |
| 487 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 488 | int maxInstancesPerDraw = this->indexCountInCurrentSource() / indicesPerInstance; |
| 489 | if (!maxInstancesPerDraw) { |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 490 | return; |
| 491 | } |
| 492 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 493 | DrawInfo info; |
| 494 | info.fPrimitiveType = type; |
| 495 | info.fStartIndex = 0; |
| 496 | info.fStartVertex = 0; |
| 497 | info.fIndicesPerInstance = indicesPerInstance; |
| 498 | info.fVerticesPerInstance = verticesPerInstance; |
| 499 | |
| 500 | // Set the same bounds for all the draws. |
| 501 | if (NULL != devBounds) { |
| 502 | info.setDevBounds(*devBounds); |
| 503 | } |
| 504 | |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 505 | while (instanceCount) { |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 506 | info.fInstanceCount = GrMin(instanceCount, maxInstancesPerDraw); |
| 507 | info.fVertexCount = info.fInstanceCount * verticesPerInstance; |
| 508 | info.fIndexCount = info.fInstanceCount * indicesPerInstance; |
| 509 | |
| 510 | if (this->checkDraw(type, |
| 511 | info.fStartVertex, |
| 512 | info.fStartIndex, |
| 513 | info.fVertexCount, |
| 514 | info.fIndexCount)) { |
| 515 | this->onDraw(info); |
| 516 | } |
| 517 | info.fStartVertex += info.fVertexCount; |
| 518 | instanceCount -= info.fInstanceCount; |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 519 | } |
| 520 | } |
bsalomon@google.com | 3d0835b | 2011-12-08 16:12:03 +0000 | [diff] [blame] | 521 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 522 | //////////////////////////////////////////////////////////////////////////////// |
| 523 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 524 | void GrDrawTarget::drawRect(const GrRect& rect, |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 525 | const SkMatrix* matrix, |
jvanverth@google.com | 3976825 | 2013-02-14 15:25:44 +0000 | [diff] [blame^] | 526 | const GrRect* srcRect, |
| 527 | const SkMatrix* srcMatrix, |
| 528 | int stage) { |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 529 | GrVertexLayout layout = 0; |
| 530 | uint32_t explicitCoordMask = 0; |
| 531 | |
jvanverth@google.com | 3976825 | 2013-02-14 15:25:44 +0000 | [diff] [blame^] | 532 | if (NULL != srcRect) { |
| 533 | layout |= GrDrawState::StageTexCoordVertexLayoutBit(stage); |
| 534 | explicitCoordMask = (1 << stage); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | GrDrawState::AutoViewMatrixRestore avmr; |
| 538 | if (NULL != matrix) { |
| 539 | avmr.set(this->drawState(), *matrix, explicitCoordMask); |
| 540 | } |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 541 | |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 542 | this->drawState()->setVertexLayout(layout); |
| 543 | AutoReleaseGeometry geo(this, 4, 0); |
bsalomon@google.com | 6513cd0 | 2011-08-05 20:12:30 +0000 | [diff] [blame] | 544 | if (!geo.succeeded()) { |
| 545 | GrPrintf("Failed to get space for vertices!\n"); |
| 546 | return; |
| 547 | } |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 548 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 549 | int stageOffsets[GrDrawState::kNumStages]; |
| 550 | int vsize = GrDrawState::VertexSizeAndOffsetsByStage(layout, stageOffsets, NULL, NULL, NULL); |
| 551 | geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, vsize); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 552 | |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 553 | for (int i = 0; i < GrDrawState::kNumStages; ++i) { |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 554 | if (explicitCoordMask & (1 << i)) { |
reed@google.com | 009dfe2 | 2013-02-01 15:05:18 +0000 | [diff] [blame] | 555 | GrAssert(0 != stageOffsets[i]); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 556 | GrPoint* coords = GrTCast<GrPoint*>(GrTCast<intptr_t>(geo.vertices()) + |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 557 | stageOffsets[i]); |
jvanverth@google.com | 3976825 | 2013-02-14 15:25:44 +0000 | [diff] [blame^] | 558 | coords->setRectFan(srcRect->fLeft, srcRect->fTop, |
| 559 | srcRect->fRight, srcRect->fBottom, |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 560 | vsize); |
jvanverth@google.com | 3976825 | 2013-02-14 15:25:44 +0000 | [diff] [blame^] | 561 | if (NULL != srcMatrix) { |
| 562 | srcMatrix->mapPointsWithStride(coords, vsize, 4); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 563 | } |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 564 | } else { |
reed@google.com | 009dfe2 | 2013-02-01 15:05:18 +0000 | [diff] [blame] | 565 | GrAssert(0 == stageOffsets[i]); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 566 | } |
| 567 | } |
robertphillips@google.com | 8b129aa | 2012-10-05 15:37:00 +0000 | [diff] [blame] | 568 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 569 | this->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 570 | } |
| 571 | |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 572 | void GrDrawTarget::clipWillBeSet(const GrClipData* clipData) { |
| 573 | } |
| 574 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 575 | //////////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 7ac249b | 2011-06-14 18:46:24 +0000 | [diff] [blame] | 576 | |
bsalomon@google.com | 06afe7b | 2011-04-26 15:31:40 +0000 | [diff] [blame] | 577 | GrDrawTarget::AutoStateRestore::AutoStateRestore() { |
| 578 | fDrawTarget = NULL; |
| 579 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 580 | |
bsalomon@google.com | 873ea0c | 2012-03-30 15:55:32 +0000 | [diff] [blame] | 581 | GrDrawTarget::AutoStateRestore::AutoStateRestore(GrDrawTarget* target, |
| 582 | ASRInit init) { |
| 583 | fDrawTarget = NULL; |
| 584 | this->set(target, init); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | GrDrawTarget::AutoStateRestore::~AutoStateRestore() { |
bsalomon@google.com | 7d34d2e | 2011-01-24 17:41:47 +0000 | [diff] [blame] | 588 | if (NULL != fDrawTarget) { |
bsalomon@google.com | 873ea0c | 2012-03-30 15:55:32 +0000 | [diff] [blame] | 589 | fDrawTarget->setDrawState(fSavedState); |
| 590 | fSavedState->unref(); |
bsalomon@google.com | 7d34d2e | 2011-01-24 17:41:47 +0000 | [diff] [blame] | 591 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 592 | } |
bsalomon@google.com | 7d34d2e | 2011-01-24 17:41:47 +0000 | [diff] [blame] | 593 | |
bsalomon@google.com | 873ea0c | 2012-03-30 15:55:32 +0000 | [diff] [blame] | 594 | void GrDrawTarget::AutoStateRestore::set(GrDrawTarget* target, ASRInit init) { |
| 595 | GrAssert(NULL == fDrawTarget); |
| 596 | fDrawTarget = target; |
| 597 | fSavedState = target->drawState(); |
| 598 | GrAssert(fSavedState); |
| 599 | fSavedState->ref(); |
| 600 | if (kReset_ASRInit == init) { |
| 601 | // calls the default cons |
| 602 | fTempState.init(); |
| 603 | } else { |
| 604 | GrAssert(kPreserve_ASRInit == init); |
| 605 | // calls the copy cons |
| 606 | fTempState.set(*fSavedState); |
bsalomon@google.com | 06afe7b | 2011-04-26 15:31:40 +0000 | [diff] [blame] | 607 | } |
bsalomon@google.com | 873ea0c | 2012-03-30 15:55:32 +0000 | [diff] [blame] | 608 | target->setDrawState(fTempState.get()); |
bsalomon@google.com | 06afe7b | 2011-04-26 15:31:40 +0000 | [diff] [blame] | 609 | } |
bsalomon@google.com | 7ac249b | 2011-06-14 18:46:24 +0000 | [diff] [blame] | 610 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 611 | //////////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 7ac249b | 2011-06-14 18:46:24 +0000 | [diff] [blame] | 612 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 613 | GrDrawTarget::AutoReleaseGeometry::AutoReleaseGeometry( |
| 614 | GrDrawTarget* target, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 615 | int vertexCount, |
| 616 | int indexCount) { |
| 617 | fTarget = NULL; |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 618 | this->set(target, vertexCount, indexCount); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 619 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 620 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 621 | GrDrawTarget::AutoReleaseGeometry::AutoReleaseGeometry() { |
| 622 | fTarget = NULL; |
| 623 | } |
| 624 | |
| 625 | GrDrawTarget::AutoReleaseGeometry::~AutoReleaseGeometry() { |
| 626 | this->reset(); |
| 627 | } |
| 628 | |
| 629 | bool GrDrawTarget::AutoReleaseGeometry::set(GrDrawTarget* target, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 630 | int vertexCount, |
| 631 | int indexCount) { |
| 632 | this->reset(); |
| 633 | fTarget = target; |
| 634 | bool success = true; |
| 635 | if (NULL != fTarget) { |
| 636 | fTarget = target; |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 637 | success = target->reserveVertexAndIndexSpace(vertexCount, |
bsalomon@google.com | e3d7095 | 2012-03-13 12:40:53 +0000 | [diff] [blame] | 638 | indexCount, |
| 639 | &fVertices, |
| 640 | &fIndices); |
| 641 | if (!success) { |
| 642 | fTarget = NULL; |
| 643 | this->reset(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 644 | } |
| 645 | } |
| 646 | GrAssert(success == (NULL != fTarget)); |
| 647 | return success; |
| 648 | } |
| 649 | |
| 650 | void GrDrawTarget::AutoReleaseGeometry::reset() { |
| 651 | if (NULL != fTarget) { |
| 652 | if (NULL != fVertices) { |
| 653 | fTarget->resetVertexSource(); |
| 654 | } |
| 655 | if (NULL != fIndices) { |
| 656 | fTarget->resetIndexSource(); |
| 657 | } |
| 658 | fTarget = NULL; |
| 659 | } |
bsalomon@google.com | cb0c5ab | 2011-06-29 17:48:17 +0000 | [diff] [blame] | 660 | fVertices = NULL; |
| 661 | fIndices = NULL; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 662 | } |
| 663 | |
bsalomon@google.com | 8d67c07 | 2012-12-13 20:38:14 +0000 | [diff] [blame] | 664 | GrDrawTarget::AutoClipRestore::AutoClipRestore(GrDrawTarget* target, const SkIRect& newClip) { |
| 665 | fTarget = target; |
| 666 | fClip = fTarget->getClip(); |
| 667 | fStack.init(); |
| 668 | fStack.get()->clipDevRect(newClip, SkRegion::kReplace_Op); |
| 669 | fReplacementClip.fClipStack = fStack.get(); |
| 670 | target->setClip(&fReplacementClip); |
| 671 | } |
| 672 | |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 673 | void GrDrawTarget::Caps::print() const { |
| 674 | static const char* gNY[] = {"NO", "YES"}; |
bsalomon@google.com | f660187 | 2012-08-28 21:11:35 +0000 | [diff] [blame] | 675 | GrPrintf("8 Bit Palette Support : %s\n", gNY[fInternals.f8BitPaletteSupport]); |
| 676 | GrPrintf("NPOT Texture Tile Support : %s\n", gNY[fInternals.fNPOTTextureTileSupport]); |
| 677 | GrPrintf("Two Sided Stencil Support : %s\n", gNY[fInternals.fTwoSidedStencilSupport]); |
| 678 | GrPrintf("Stencil Wrap Ops Support : %s\n", gNY[fInternals.fStencilWrapOpsSupport]); |
| 679 | GrPrintf("HW AA Lines Support : %s\n", gNY[fInternals.fHWAALineSupport]); |
| 680 | GrPrintf("Shader Derivative Support : %s\n", gNY[fInternals.fShaderDerivativeSupport]); |
| 681 | GrPrintf("Geometry Shader Support : %s\n", gNY[fInternals.fGeometryShaderSupport]); |
| 682 | GrPrintf("FSAA Support : %s\n", gNY[fInternals.fFSAASupport]); |
| 683 | GrPrintf("Dual Source Blending Support: %s\n", gNY[fInternals.fDualSourceBlendingSupport]); |
| 684 | GrPrintf("Buffer Lock Support : %s\n", gNY[fInternals.fBufferLockSupport]); |
| 685 | GrPrintf("Path Stenciling Support : %s\n", gNY[fInternals.fPathStencilingSupport]); |
| 686 | GrPrintf("Max Texture Size : %d\n", fInternals.fMaxTextureSize); |
| 687 | GrPrintf("Max Render Target Size : %d\n", fInternals.fMaxRenderTargetSize); |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 688 | } |