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