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