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 | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 12 | #include "GrDrawTargetCaps.h" |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 13 | #include "GrRenderTarget.h" |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 14 | #include "GrTexture.h" |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 15 | #include "GrVertexBuffer.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 16 | |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 17 | #include "SkStrokeRec.h" |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 18 | |
reed@google.com | fa35e3d | 2012-06-26 20:16:17 +0000 | [diff] [blame] | 19 | SK_DEFINE_INST_COUNT(GrDrawTarget) |
| 20 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 21 | //////////////////////////////////////////////////////////////////////////////// |
| 22 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 23 | GrDrawTarget::DrawInfo& GrDrawTarget::DrawInfo::operator =(const DrawInfo& di) { |
| 24 | fPrimitiveType = di.fPrimitiveType; |
| 25 | fStartVertex = di.fStartVertex; |
| 26 | fStartIndex = di.fStartIndex; |
| 27 | fVertexCount = di.fVertexCount; |
| 28 | fIndexCount = di.fIndexCount; |
| 29 | |
| 30 | fInstanceCount = di.fInstanceCount; |
| 31 | fVerticesPerInstance = di.fVerticesPerInstance; |
| 32 | fIndicesPerInstance = di.fIndicesPerInstance; |
| 33 | |
| 34 | if (NULL != di.fDevBounds) { |
| 35 | GrAssert(di.fDevBounds == &di.fDevBoundsStorage); |
| 36 | fDevBoundsStorage = di.fDevBoundsStorage; |
| 37 | fDevBounds = &fDevBoundsStorage; |
| 38 | } else { |
| 39 | fDevBounds = NULL; |
| 40 | } |
| 41 | return *this; |
| 42 | } |
| 43 | |
| 44 | #if GR_DEBUG |
| 45 | bool GrDrawTarget::DrawInfo::isInstanced() const { |
| 46 | if (fInstanceCount > 0) { |
| 47 | GrAssert(0 == fIndexCount % fIndicesPerInstance); |
| 48 | GrAssert(0 == fVertexCount % fVerticesPerInstance); |
| 49 | GrAssert(fIndexCount / fIndicesPerInstance == fInstanceCount); |
| 50 | GrAssert(fVertexCount / fVerticesPerInstance == fInstanceCount); |
| 51 | // there is no way to specify a non-zero start index to drawIndexedInstances(). |
| 52 | GrAssert(0 == fStartIndex); |
| 53 | return true; |
| 54 | } else { |
| 55 | GrAssert(!fVerticesPerInstance); |
| 56 | GrAssert(!fIndicesPerInstance); |
| 57 | return false; |
| 58 | } |
| 59 | } |
| 60 | #endif |
| 61 | |
| 62 | void GrDrawTarget::DrawInfo::adjustInstanceCount(int instanceOffset) { |
| 63 | GrAssert(this->isInstanced()); |
| 64 | GrAssert(instanceOffset + fInstanceCount >= 0); |
| 65 | fInstanceCount += instanceOffset; |
| 66 | fVertexCount = fVerticesPerInstance * fInstanceCount; |
| 67 | fIndexCount = fIndicesPerInstance * fInstanceCount; |
| 68 | } |
| 69 | |
| 70 | void GrDrawTarget::DrawInfo::adjustStartVertex(int vertexOffset) { |
| 71 | fStartVertex += vertexOffset; |
| 72 | GrAssert(fStartVertex >= 0); |
| 73 | } |
| 74 | |
| 75 | void GrDrawTarget::DrawInfo::adjustStartIndex(int indexOffset) { |
| 76 | GrAssert(this->isIndexed()); |
| 77 | fStartIndex += indexOffset; |
| 78 | GrAssert(fStartIndex >= 0); |
| 79 | } |
| 80 | |
| 81 | //////////////////////////////////////////////////////////////////////////////// |
| 82 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 83 | #define DEBUG_INVAL_BUFFER 0xdeadcafe |
| 84 | #define DEBUG_INVAL_START_IDX -1 |
| 85 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 86 | GrDrawTarget::GrDrawTarget(GrContext* context) |
| 87 | : fClip(NULL) |
| 88 | , fContext(context) { |
| 89 | GrAssert(NULL != context); |
| 90 | |
bsalomon@google.com | a5d056a | 2012-03-27 15:59:58 +0000 | [diff] [blame] | 91 | fDrawState = &fDefaultDrawState; |
| 92 | // We assume that fDrawState always owns a ref to the object it points at. |
| 93 | fDefaultDrawState.ref(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 94 | GeometrySrcState& geoSrc = fGeoSrcStateStack.push_back(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 95 | #if GR_DEBUG |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 96 | geoSrc.fVertexCount = DEBUG_INVAL_START_IDX; |
| 97 | geoSrc.fVertexBuffer = (GrVertexBuffer*)DEBUG_INVAL_BUFFER; |
| 98 | geoSrc.fIndexCount = DEBUG_INVAL_START_IDX; |
| 99 | geoSrc.fIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 100 | #endif |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 101 | geoSrc.fVertexSrc = kNone_GeometrySrcType; |
| 102 | geoSrc.fIndexSrc = kNone_GeometrySrcType; |
| 103 | } |
| 104 | |
| 105 | GrDrawTarget::~GrDrawTarget() { |
bsalomon@google.com | 4a018bb | 2011-10-28 19:50:21 +0000 | [diff] [blame] | 106 | GrAssert(1 == fGeoSrcStateStack.count()); |
humper@google.com | 0e51577 | 2013-01-07 19:54:40 +0000 | [diff] [blame] | 107 | SkDEBUGCODE(GeometrySrcState& geoSrc = fGeoSrcStateStack.back()); |
bsalomon@google.com | 4a018bb | 2011-10-28 19:50:21 +0000 | [diff] [blame] | 108 | GrAssert(kNone_GeometrySrcType == geoSrc.fIndexSrc); |
| 109 | GrAssert(kNone_GeometrySrcType == geoSrc.fVertexSrc); |
bsalomon@google.com | a5d056a | 2012-03-27 15:59:58 +0000 | [diff] [blame] | 110 | fDrawState->unref(); |
bsalomon@google.com | 4a018bb | 2011-10-28 19:50:21 +0000 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | void GrDrawTarget::releaseGeometry() { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 114 | int popCnt = fGeoSrcStateStack.count() - 1; |
| 115 | while (popCnt) { |
| 116 | this->popGeometrySource(); |
| 117 | --popCnt; |
| 118 | } |
bsalomon@google.com | 4a018bb | 2011-10-28 19:50:21 +0000 | [diff] [blame] | 119 | this->resetVertexSource(); |
| 120 | this->resetIndexSource(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 121 | } |
| 122 | |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 123 | void GrDrawTarget::setClip(const GrClipData* clip) { |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 124 | clipWillBeSet(clip); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 125 | fClip = clip; |
| 126 | } |
| 127 | |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 128 | const GrClipData* GrDrawTarget::getClip() const { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 129 | return fClip; |
| 130 | } |
| 131 | |
bsalomon@google.com | a5d056a | 2012-03-27 15:59:58 +0000 | [diff] [blame] | 132 | void GrDrawTarget::setDrawState(GrDrawState* drawState) { |
| 133 | GrAssert(NULL != fDrawState); |
| 134 | if (NULL == drawState) { |
| 135 | drawState = &fDefaultDrawState; |
| 136 | } |
| 137 | if (fDrawState != drawState) { |
| 138 | fDrawState->unref(); |
| 139 | drawState->ref(); |
| 140 | fDrawState = drawState; |
| 141 | } |
| 142 | } |
| 143 | |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 144 | bool GrDrawTarget::reserveVertexSpace(size_t vertexSize, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 145 | int vertexCount, |
| 146 | void** vertices) { |
| 147 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 148 | bool acquired = false; |
| 149 | if (vertexCount > 0) { |
| 150 | GrAssert(NULL != vertices); |
| 151 | this->releasePreviousVertexSource(); |
| 152 | geoSrc.fVertexSrc = kNone_GeometrySrcType; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 153 | |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 154 | acquired = this->onReserveVertexSpace(vertexSize, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 155 | vertexCount, |
| 156 | vertices); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 157 | } |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 158 | if (acquired) { |
| 159 | geoSrc.fVertexSrc = kReserved_GeometrySrcType; |
| 160 | geoSrc.fVertexCount = vertexCount; |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 161 | geoSrc.fVertexSize = vertexSize; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 162 | } else if (NULL != vertices) { |
| 163 | *vertices = NULL; |
| 164 | } |
| 165 | return acquired; |
| 166 | } |
| 167 | |
| 168 | bool GrDrawTarget::reserveIndexSpace(int indexCount, |
| 169 | void** indices) { |
| 170 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 171 | bool acquired = false; |
| 172 | if (indexCount > 0) { |
| 173 | GrAssert(NULL != indices); |
| 174 | this->releasePreviousIndexSource(); |
| 175 | geoSrc.fIndexSrc = kNone_GeometrySrcType; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 176 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 177 | acquired = this->onReserveIndexSpace(indexCount, indices); |
| 178 | } |
| 179 | if (acquired) { |
| 180 | geoSrc.fIndexSrc = kReserved_GeometrySrcType; |
| 181 | geoSrc.fIndexCount = indexCount; |
| 182 | } else if (NULL != indices) { |
| 183 | *indices = NULL; |
| 184 | } |
| 185 | return acquired; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 186 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 187 | } |
| 188 | |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 189 | bool GrDrawTarget::reserveVertexAndIndexSpace(int vertexCount, |
bsalomon@google.com | e3d7095 | 2012-03-13 12:40:53 +0000 | [diff] [blame] | 190 | int indexCount, |
| 191 | void** vertices, |
| 192 | void** indices) { |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 193 | size_t vertexSize = this->drawState()->getVertexSize(); |
| 194 | this->willReserveVertexAndIndexSpace(vertexCount, indexCount); |
bsalomon@google.com | e3d7095 | 2012-03-13 12:40:53 +0000 | [diff] [blame] | 195 | if (vertexCount) { |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 196 | if (!this->reserveVertexSpace(vertexSize, vertexCount, vertices)) { |
bsalomon@google.com | e3d7095 | 2012-03-13 12:40:53 +0000 | [diff] [blame] | 197 | if (indexCount) { |
| 198 | this->resetIndexSource(); |
| 199 | } |
| 200 | return false; |
| 201 | } |
| 202 | } |
| 203 | if (indexCount) { |
| 204 | if (!this->reserveIndexSpace(indexCount, indices)) { |
| 205 | if (vertexCount) { |
| 206 | this->resetVertexSource(); |
| 207 | } |
| 208 | return false; |
| 209 | } |
| 210 | } |
| 211 | return true; |
| 212 | } |
| 213 | |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 214 | bool GrDrawTarget::geometryHints(int32_t* vertexCount, |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 215 | int32_t* indexCount) const { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 216 | if (NULL != vertexCount) { |
| 217 | *vertexCount = -1; |
| 218 | } |
| 219 | if (NULL != indexCount) { |
| 220 | *indexCount = -1; |
| 221 | } |
| 222 | return false; |
| 223 | } |
| 224 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 225 | void GrDrawTarget::releasePreviousVertexSource() { |
| 226 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 227 | switch (geoSrc.fVertexSrc) { |
| 228 | case kNone_GeometrySrcType: |
| 229 | break; |
| 230 | case kArray_GeometrySrcType: |
| 231 | this->releaseVertexArray(); |
| 232 | break; |
| 233 | case kReserved_GeometrySrcType: |
| 234 | this->releaseReservedVertexSpace(); |
| 235 | break; |
| 236 | case kBuffer_GeometrySrcType: |
| 237 | geoSrc.fVertexBuffer->unref(); |
| 238 | #if GR_DEBUG |
| 239 | geoSrc.fVertexBuffer = (GrVertexBuffer*)DEBUG_INVAL_BUFFER; |
| 240 | #endif |
| 241 | break; |
| 242 | default: |
| 243 | GrCrash("Unknown Vertex Source Type."); |
| 244 | break; |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | void GrDrawTarget::releasePreviousIndexSource() { |
| 249 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 250 | switch (geoSrc.fIndexSrc) { |
| 251 | case kNone_GeometrySrcType: // these two don't require |
| 252 | break; |
| 253 | case kArray_GeometrySrcType: |
| 254 | this->releaseIndexArray(); |
| 255 | break; |
| 256 | case kReserved_GeometrySrcType: |
| 257 | this->releaseReservedIndexSpace(); |
| 258 | break; |
| 259 | case kBuffer_GeometrySrcType: |
| 260 | geoSrc.fIndexBuffer->unref(); |
| 261 | #if GR_DEBUG |
| 262 | geoSrc.fIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER; |
| 263 | #endif |
| 264 | break; |
| 265 | default: |
| 266 | GrCrash("Unknown Index Source Type."); |
| 267 | break; |
| 268 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 269 | } |
| 270 | |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 271 | void GrDrawTarget::setVertexSourceToArray(const void* vertexArray, |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 272 | int vertexCount) { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 273 | this->releasePreviousVertexSource(); |
| 274 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 275 | geoSrc.fVertexSrc = kArray_GeometrySrcType; |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 276 | geoSrc.fVertexSize = this->drawState()->getVertexSize(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 277 | geoSrc.fVertexCount = vertexCount; |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 278 | this->onSetVertexSourceToArray(vertexArray, vertexCount); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 279 | } |
| 280 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 281 | void GrDrawTarget::setIndexSourceToArray(const void* indexArray, |
| 282 | int indexCount) { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 283 | this->releasePreviousIndexSource(); |
| 284 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 285 | geoSrc.fIndexSrc = kArray_GeometrySrcType; |
| 286 | geoSrc.fIndexCount = indexCount; |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 287 | this->onSetIndexSourceToArray(indexArray, indexCount); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 288 | } |
| 289 | |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 290 | void GrDrawTarget::setVertexSourceToBuffer(const GrVertexBuffer* buffer) { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 291 | this->releasePreviousVertexSource(); |
| 292 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 293 | geoSrc.fVertexSrc = kBuffer_GeometrySrcType; |
| 294 | geoSrc.fVertexBuffer = buffer; |
| 295 | buffer->ref(); |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 296 | geoSrc.fVertexSize = this->drawState()->getVertexSize(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | void GrDrawTarget::setIndexSourceToBuffer(const GrIndexBuffer* buffer) { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 300 | this->releasePreviousIndexSource(); |
| 301 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 302 | geoSrc.fIndexSrc = kBuffer_GeometrySrcType; |
| 303 | geoSrc.fIndexBuffer = buffer; |
| 304 | buffer->ref(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 305 | } |
| 306 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 307 | void GrDrawTarget::resetVertexSource() { |
| 308 | this->releasePreviousVertexSource(); |
| 309 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 310 | geoSrc.fVertexSrc = kNone_GeometrySrcType; |
| 311 | } |
| 312 | |
| 313 | void GrDrawTarget::resetIndexSource() { |
| 314 | this->releasePreviousIndexSource(); |
| 315 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 316 | geoSrc.fIndexSrc = kNone_GeometrySrcType; |
| 317 | } |
| 318 | |
| 319 | void GrDrawTarget::pushGeometrySource() { |
| 320 | this->geometrySourceWillPush(); |
| 321 | GeometrySrcState& newState = fGeoSrcStateStack.push_back(); |
| 322 | newState.fIndexSrc = kNone_GeometrySrcType; |
| 323 | newState.fVertexSrc = kNone_GeometrySrcType; |
| 324 | #if GR_DEBUG |
| 325 | newState.fVertexCount = ~0; |
| 326 | newState.fVertexBuffer = (GrVertexBuffer*)~0; |
| 327 | newState.fIndexCount = ~0; |
| 328 | newState.fIndexBuffer = (GrIndexBuffer*)~0; |
| 329 | #endif |
| 330 | } |
| 331 | |
| 332 | void GrDrawTarget::popGeometrySource() { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 333 | // if popping last element then pops are unbalanced with pushes |
| 334 | GrAssert(fGeoSrcStateStack.count() > 1); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 335 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 336 | this->geometrySourceWillPop(fGeoSrcStateStack.fromBack(1)); |
| 337 | this->releasePreviousVertexSource(); |
| 338 | this->releasePreviousIndexSource(); |
| 339 | fGeoSrcStateStack.pop_back(); |
| 340 | } |
| 341 | |
| 342 | //////////////////////////////////////////////////////////////////////////////// |
| 343 | |
bsalomon@google.com | e826262 | 2011-11-07 02:30:51 +0000 | [diff] [blame] | 344 | bool GrDrawTarget::checkDraw(GrPrimitiveType type, int startVertex, |
| 345 | int startIndex, int vertexCount, |
| 346 | int indexCount) const { |
bsalomon@google.com | cddaf34 | 2012-07-30 13:09:05 +0000 | [diff] [blame] | 347 | const GrDrawState& drawState = this->getDrawState(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 348 | #if GR_DEBUG |
bsalomon@google.com | e826262 | 2011-11-07 02:30:51 +0000 | [diff] [blame] | 349 | const GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 350 | int maxVertex = startVertex + vertexCount; |
| 351 | int maxValidVertex; |
| 352 | switch (geoSrc.fVertexSrc) { |
| 353 | case kNone_GeometrySrcType: |
bsalomon@google.com | e826262 | 2011-11-07 02:30:51 +0000 | [diff] [blame] | 354 | GrCrash("Attempting to draw without vertex src."); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 355 | case kReserved_GeometrySrcType: // fallthrough |
| 356 | case kArray_GeometrySrcType: |
| 357 | maxValidVertex = geoSrc.fVertexCount; |
| 358 | break; |
| 359 | case kBuffer_GeometrySrcType: |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 360 | maxValidVertex = geoSrc.fVertexBuffer->sizeInBytes() / geoSrc.fVertexSize; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 361 | break; |
| 362 | } |
| 363 | if (maxVertex > maxValidVertex) { |
bsalomon@google.com | e826262 | 2011-11-07 02:30:51 +0000 | [diff] [blame] | 364 | GrCrash("Drawing outside valid vertex range."); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 365 | } |
bsalomon@google.com | e826262 | 2011-11-07 02:30:51 +0000 | [diff] [blame] | 366 | if (indexCount > 0) { |
| 367 | int maxIndex = startIndex + indexCount; |
| 368 | int maxValidIndex; |
| 369 | switch (geoSrc.fIndexSrc) { |
| 370 | case kNone_GeometrySrcType: |
| 371 | GrCrash("Attempting to draw indexed geom without index src."); |
| 372 | case kReserved_GeometrySrcType: // fallthrough |
| 373 | case kArray_GeometrySrcType: |
| 374 | maxValidIndex = geoSrc.fIndexCount; |
| 375 | break; |
| 376 | case kBuffer_GeometrySrcType: |
| 377 | maxValidIndex = geoSrc.fIndexBuffer->sizeInBytes() / sizeof(uint16_t); |
| 378 | break; |
| 379 | } |
| 380 | if (maxIndex > maxValidIndex) { |
| 381 | GrCrash("Index reads outside valid index range."); |
| 382 | } |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 383 | } |
bsalomon@google.com | b4725b4 | 2012-03-30 17:24:17 +0000 | [diff] [blame] | 384 | |
bsalomon@google.com | cddaf34 | 2012-07-30 13:09:05 +0000 | [diff] [blame] | 385 | GrAssert(NULL != drawState.getRenderTarget()); |
| 386 | for (int s = 0; s < GrDrawState::kNumStages; ++s) { |
| 387 | if (drawState.isStageEnabled(s)) { |
bsalomon@google.com | 6340a41 | 2013-01-22 19:55:59 +0000 | [diff] [blame] | 388 | const GrEffectRef& effect = *drawState.getStage(s).getEffect(); |
bsalomon@google.com | 021fc73 | 2012-10-25 12:47:42 +0000 | [diff] [blame] | 389 | int numTextures = effect->numTextures(); |
bsalomon@google.com | cddaf34 | 2012-07-30 13:09:05 +0000 | [diff] [blame] | 390 | for (int t = 0; t < numTextures; ++t) { |
bsalomon@google.com | 021fc73 | 2012-10-25 12:47:42 +0000 | [diff] [blame] | 391 | GrTexture* texture = effect->texture(t); |
bsalomon@google.com | cddaf34 | 2012-07-30 13:09:05 +0000 | [diff] [blame] | 392 | GrAssert(texture->asRenderTarget() != drawState.getRenderTarget()); |
| 393 | } |
bsalomon@google.com | b4725b4 | 2012-03-30 17:24:17 +0000 | [diff] [blame] | 394 | } |
| 395 | } |
commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 396 | |
| 397 | GrAssert(drawState.validateVertexAttribs()); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 398 | #endif |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 399 | if (NULL == drawState.getRenderTarget()) { |
bsalomon@google.com | 0ba52fc | 2011-11-10 22:16:06 +0000 | [diff] [blame] | 400 | return false; |
| 401 | } |
bsalomon@google.com | e826262 | 2011-11-07 02:30:51 +0000 | [diff] [blame] | 402 | return true; |
| 403 | } |
| 404 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 405 | void GrDrawTarget::drawIndexed(GrPrimitiveType type, |
| 406 | int startVertex, |
| 407 | int startIndex, |
| 408 | int vertexCount, |
| 409 | int indexCount, |
| 410 | const SkRect* devBounds) { |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 411 | if (indexCount > 0 && this->checkDraw(type, startVertex, startIndex, vertexCount, indexCount)) { |
| 412 | DrawInfo info; |
| 413 | info.fPrimitiveType = type; |
| 414 | info.fStartVertex = startVertex; |
| 415 | info.fStartIndex = startIndex; |
| 416 | info.fVertexCount = vertexCount; |
| 417 | info.fIndexCount = indexCount; |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 418 | |
| 419 | info.fInstanceCount = 0; |
| 420 | info.fVerticesPerInstance = 0; |
| 421 | info.fIndicesPerInstance = 0; |
| 422 | |
| 423 | if (NULL != devBounds) { |
| 424 | info.setDevBounds(*devBounds); |
| 425 | } |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 426 | this->onDraw(info); |
bsalomon@google.com | 8214587 | 2011-08-23 14:32:40 +0000 | [diff] [blame] | 427 | } |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 428 | } |
| 429 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 430 | void GrDrawTarget::drawNonIndexed(GrPrimitiveType type, |
| 431 | int startVertex, |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 432 | int vertexCount, |
| 433 | const SkRect* devBounds) { |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 434 | if (vertexCount > 0 && this->checkDraw(type, startVertex, -1, vertexCount, -1)) { |
| 435 | DrawInfo info; |
| 436 | info.fPrimitiveType = type; |
| 437 | info.fStartVertex = startVertex; |
| 438 | info.fStartIndex = 0; |
| 439 | info.fVertexCount = vertexCount; |
| 440 | info.fIndexCount = 0; |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 441 | |
| 442 | info.fInstanceCount = 0; |
| 443 | info.fVerticesPerInstance = 0; |
| 444 | info.fIndicesPerInstance = 0; |
| 445 | |
| 446 | if (NULL != devBounds) { |
| 447 | info.setDevBounds(*devBounds); |
| 448 | } |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 449 | this->onDraw(info); |
bsalomon@google.com | 8214587 | 2011-08-23 14:32:40 +0000 | [diff] [blame] | 450 | } |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 451 | } |
| 452 | |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 453 | 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] | 454 | // TODO: extract portions of checkDraw that are relevant to path stenciling. |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 455 | GrAssert(NULL != path); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 456 | GrAssert(this->caps()->pathStencilingSupport()); |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 457 | GrAssert(!stroke.isHairlineStyle()); |
| 458 | GrAssert(!SkPath::IsInverseFillType(fill)); |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 459 | this->onStencilPath(path, stroke, fill); |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 460 | } |
| 461 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 462 | //////////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 463 | |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 464 | bool GrDrawTarget::willUseHWAALines() const { |
bsalomon@google.com | 2b44673 | 2013-02-12 16:47:41 +0000 | [diff] [blame] | 465 | // There is a conflict between using smooth lines and our use of premultiplied alpha. Smooth |
| 466 | // lines tweak the incoming alpha value but not in a premul-alpha way. So we only use them when |
| 467 | // our alpha is 0xff and tweaking the color for partial coverage is OK |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 468 | if (!this->caps()->hwAALineSupport() || |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 469 | !this->getDrawState().isHWAntialiasState()) { |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 470 | return false; |
| 471 | } |
bsalomon@google.com | 2b44673 | 2013-02-12 16:47:41 +0000 | [diff] [blame] | 472 | GrDrawState::BlendOptFlags opts = this->getDrawState().getBlendOpts(); |
| 473 | return (GrDrawState::kDisableBlend_BlendOptFlag & opts) && |
| 474 | (GrDrawState::kCoverageAsAlpha_BlendOptFlag & opts); |
bsalomon@google.com | d46e242 | 2011-09-23 17:40:07 +0000 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | bool GrDrawTarget::canApplyCoverage() const { |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 478 | // we can correctly apply coverage if a) we have dual source blending |
| 479 | // or b) one of our blend optimizations applies. |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 480 | return this->caps()->dualSourceBlendingSupport() || |
bsalomon@google.com | 2b44673 | 2013-02-12 16:47:41 +0000 | [diff] [blame] | 481 | GrDrawState::kNone_BlendOpt != this->getDrawState().getBlendOpts(true); |
bsalomon@google.com | 471d471 | 2011-08-23 15:45:25 +0000 | [diff] [blame] | 482 | } |
| 483 | |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 484 | //////////////////////////////////////////////////////////////////////////////// |
| 485 | |
| 486 | void GrDrawTarget::drawIndexedInstances(GrPrimitiveType type, |
| 487 | int instanceCount, |
| 488 | int verticesPerInstance, |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 489 | int indicesPerInstance, |
| 490 | const SkRect* devBounds) { |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 491 | if (!verticesPerInstance || !indicesPerInstance) { |
| 492 | return; |
| 493 | } |
| 494 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 495 | int maxInstancesPerDraw = this->indexCountInCurrentSource() / indicesPerInstance; |
| 496 | if (!maxInstancesPerDraw) { |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 497 | return; |
| 498 | } |
| 499 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 500 | DrawInfo info; |
| 501 | info.fPrimitiveType = type; |
| 502 | info.fStartIndex = 0; |
| 503 | info.fStartVertex = 0; |
| 504 | info.fIndicesPerInstance = indicesPerInstance; |
| 505 | info.fVerticesPerInstance = verticesPerInstance; |
| 506 | |
| 507 | // Set the same bounds for all the draws. |
| 508 | if (NULL != devBounds) { |
| 509 | info.setDevBounds(*devBounds); |
| 510 | } |
| 511 | |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 512 | while (instanceCount) { |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 513 | info.fInstanceCount = GrMin(instanceCount, maxInstancesPerDraw); |
| 514 | info.fVertexCount = info.fInstanceCount * verticesPerInstance; |
| 515 | info.fIndexCount = info.fInstanceCount * indicesPerInstance; |
| 516 | |
| 517 | if (this->checkDraw(type, |
| 518 | info.fStartVertex, |
| 519 | info.fStartIndex, |
| 520 | info.fVertexCount, |
| 521 | info.fIndexCount)) { |
| 522 | this->onDraw(info); |
| 523 | } |
| 524 | info.fStartVertex += info.fVertexCount; |
| 525 | instanceCount -= info.fInstanceCount; |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 526 | } |
| 527 | } |
bsalomon@google.com | 3d0835b | 2011-12-08 16:12:03 +0000 | [diff] [blame] | 528 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 529 | //////////////////////////////////////////////////////////////////////////////// |
| 530 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 531 | void GrDrawTarget::drawRect(const GrRect& rect, |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 532 | const SkMatrix* matrix, |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 533 | const GrRect* localRect, |
| 534 | const SkMatrix* localMatrix) { |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 535 | GrAttribBindings bindings = 0; |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 536 | // position + (optional) texture coord |
| 537 | static const GrVertexAttrib kAttribs[] = { |
jvanverth@google.com | 3b0d631 | 2013-03-01 20:30:01 +0000 | [diff] [blame] | 538 | {kVec2f_GrVertexAttribType, 0}, |
| 539 | {kVec2f_GrVertexAttribType, sizeof(GrPoint)} |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 540 | }; |
| 541 | int attribCount = 1; |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 542 | |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 543 | if (NULL != localRect) { |
| 544 | bindings |= GrDrawState::kLocalCoords_AttribBindingsBit; |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 545 | attribCount = 2; |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 546 | this->drawState()->setAttribIndex(GrDrawState::kLocalCoords_AttribIndex, 1); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | GrDrawState::AutoViewMatrixRestore avmr; |
| 550 | if (NULL != matrix) { |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 551 | avmr.set(this->drawState(), *matrix); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 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); |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 565 | if (NULL != localRect) { |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 566 | GrAssert(attribCount == 2); |
| 567 | GrPoint* coords = GrTCast<GrPoint*>(GrTCast<intptr_t>(geo.vertices()) + |
| 568 | kAttribs[1].fOffset); |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 569 | coords->setRectFan(localRect->fLeft, localRect->fTop, |
| 570 | localRect->fRight, localRect->fBottom, |
| 571 | vsize); |
| 572 | if (NULL != localMatrix) { |
| 573 | localMatrix->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 | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 681 | /////////////////////////////////////////////////////////////////////////////// |
| 682 | |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 683 | SK_DEFINE_INST_COUNT(GrDrawTargetCaps) |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 684 | |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 685 | void GrDrawTargetCaps::reset() { |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 686 | f8BitPaletteSupport = false; |
| 687 | fNPOTTextureTileSupport = false; |
| 688 | fTwoSidedStencilSupport = false; |
| 689 | fStencilWrapOpsSupport = false; |
| 690 | fHWAALineSupport = false; |
| 691 | fShaderDerivativeSupport = false; |
| 692 | fGeometryShaderSupport = false; |
skia.committer@gmail.com | e60ed08 | 2013-03-26 07:01:04 +0000 | [diff] [blame^] | 693 | fDualSourceBlendingSupport = false; |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 694 | fBufferLockSupport = false; |
| 695 | fPathStencilingSupport = false; |
| 696 | |
| 697 | fMaxRenderTargetSize = 0; |
| 698 | fMaxTextureSize = 0; |
| 699 | fMaxSampleCount = 0; |
| 700 | } |
| 701 | |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 702 | GrDrawTargetCaps& GrDrawTargetCaps::operator=(const GrDrawTargetCaps& other) { |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 703 | f8BitPaletteSupport = other.f8BitPaletteSupport; |
| 704 | fNPOTTextureTileSupport = other.fNPOTTextureTileSupport; |
| 705 | fTwoSidedStencilSupport = other.fTwoSidedStencilSupport; |
| 706 | fStencilWrapOpsSupport = other.fStencilWrapOpsSupport; |
| 707 | fHWAALineSupport = other.fHWAALineSupport; |
| 708 | fShaderDerivativeSupport = other.fShaderDerivativeSupport; |
| 709 | fGeometryShaderSupport = other.fGeometryShaderSupport; |
| 710 | fDualSourceBlendingSupport = other.fDualSourceBlendingSupport; |
| 711 | fBufferLockSupport = other.fBufferLockSupport; |
| 712 | fPathStencilingSupport = other.fPathStencilingSupport; |
| 713 | |
| 714 | fMaxRenderTargetSize = other.fMaxRenderTargetSize; |
| 715 | fMaxTextureSize = other.fMaxTextureSize; |
| 716 | fMaxSampleCount = other.fMaxSampleCount; |
| 717 | |
| 718 | return *this; |
| 719 | } |
| 720 | |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 721 | void GrDrawTargetCaps::print() const { |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 722 | static const char* gNY[] = {"NO", "YES"}; |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 723 | GrPrintf("8 Bit Palette Support : %s\n", gNY[f8BitPaletteSupport]); |
| 724 | GrPrintf("NPOT Texture Tile Support : %s\n", gNY[fNPOTTextureTileSupport]); |
| 725 | GrPrintf("Two Sided Stencil Support : %s\n", gNY[fTwoSidedStencilSupport]); |
| 726 | GrPrintf("Stencil Wrap Ops Support : %s\n", gNY[fStencilWrapOpsSupport]); |
| 727 | GrPrintf("HW AA Lines Support : %s\n", gNY[fHWAALineSupport]); |
| 728 | GrPrintf("Shader Derivative Support : %s\n", gNY[fShaderDerivativeSupport]); |
| 729 | GrPrintf("Geometry Shader Support : %s\n", gNY[fGeometryShaderSupport]); |
| 730 | GrPrintf("Dual Source Blending Support: %s\n", gNY[fDualSourceBlendingSupport]); |
| 731 | GrPrintf("Buffer Lock Support : %s\n", gNY[fBufferLockSupport]); |
| 732 | GrPrintf("Path Stenciling Support : %s\n", gNY[fPathStencilingSupport]); |
| 733 | GrPrintf("Max Texture Size : %d\n", fMaxTextureSize); |
| 734 | GrPrintf("Max Render Target Size : %d\n", fMaxRenderTargetSize); |
| 735 | GrPrintf("Max Sample Count : %d\n", fMaxSampleCount); |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 736 | } |