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" |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 14 | #include "GrPath.h" |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 15 | #include "GrRenderTarget.h" |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 16 | #include "GrTemplates.h" |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 17 | #include "GrTexture.h" |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 18 | #include "GrVertexBuffer.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 19 | |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 20 | #include "SkStrokeRec.h" |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 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 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 35 | if (di.fDevBounds) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 36 | SkASSERT(di.fDevBounds == &di.fDevBoundsStorage); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 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 | |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 48 | #ifdef SK_DEBUG |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 49 | bool GrDrawTarget::DrawInfo::isInstanced() const { |
| 50 | if (fInstanceCount > 0) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 51 | SkASSERT(0 == fIndexCount % fIndicesPerInstance); |
| 52 | SkASSERT(0 == fVertexCount % fVerticesPerInstance); |
| 53 | SkASSERT(fIndexCount / fIndicesPerInstance == fInstanceCount); |
| 54 | SkASSERT(fVertexCount / fVerticesPerInstance == fInstanceCount); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 55 | // there is no way to specify a non-zero start index to drawIndexedInstances(). |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 56 | SkASSERT(0 == fStartIndex); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 57 | return true; |
| 58 | } else { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 59 | SkASSERT(!fVerticesPerInstance); |
| 60 | SkASSERT(!fIndicesPerInstance); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 61 | return false; |
| 62 | } |
| 63 | } |
| 64 | #endif |
| 65 | |
| 66 | void GrDrawTarget::DrawInfo::adjustInstanceCount(int instanceOffset) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 67 | SkASSERT(this->isInstanced()); |
| 68 | SkASSERT(instanceOffset + fInstanceCount >= 0); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 69 | fInstanceCount += instanceOffset; |
| 70 | fVertexCount = fVerticesPerInstance * fInstanceCount; |
| 71 | fIndexCount = fIndicesPerInstance * fInstanceCount; |
| 72 | } |
| 73 | |
| 74 | void GrDrawTarget::DrawInfo::adjustStartVertex(int vertexOffset) { |
| 75 | fStartVertex += vertexOffset; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 76 | SkASSERT(fStartVertex >= 0); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | void GrDrawTarget::DrawInfo::adjustStartIndex(int indexOffset) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 80 | SkASSERT(this->isIndexed()); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 81 | fStartIndex += indexOffset; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 82 | SkASSERT(fStartIndex >= 0); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 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) |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 92 | , fContext(context) |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 93 | , fGpuTraceMarkerCount(0) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 94 | SkASSERT(context); |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 95 | |
bsalomon@google.com | a5d056a | 2012-03-27 15:59:58 +0000 | [diff] [blame] | 96 | fDrawState = &fDefaultDrawState; |
| 97 | // We assume that fDrawState always owns a ref to the object it points at. |
| 98 | fDefaultDrawState.ref(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 99 | GeometrySrcState& geoSrc = fGeoSrcStateStack.push_back(); |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 100 | #ifdef SK_DEBUG |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 101 | geoSrc.fVertexCount = DEBUG_INVAL_START_IDX; |
| 102 | geoSrc.fVertexBuffer = (GrVertexBuffer*)DEBUG_INVAL_BUFFER; |
| 103 | geoSrc.fIndexCount = DEBUG_INVAL_START_IDX; |
| 104 | geoSrc.fIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 105 | #endif |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 106 | geoSrc.fVertexSrc = kNone_GeometrySrcType; |
| 107 | geoSrc.fIndexSrc = kNone_GeometrySrcType; |
| 108 | } |
| 109 | |
| 110 | GrDrawTarget::~GrDrawTarget() { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 111 | SkASSERT(1 == fGeoSrcStateStack.count()); |
humper@google.com | 0e51577 | 2013-01-07 19:54:40 +0000 | [diff] [blame] | 112 | SkDEBUGCODE(GeometrySrcState& geoSrc = fGeoSrcStateStack.back()); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 113 | SkASSERT(kNone_GeometrySrcType == geoSrc.fIndexSrc); |
| 114 | SkASSERT(kNone_GeometrySrcType == geoSrc.fVertexSrc); |
bsalomon@google.com | a5d056a | 2012-03-27 15:59:58 +0000 | [diff] [blame] | 115 | fDrawState->unref(); |
bsalomon@google.com | 4a018bb | 2011-10-28 19:50:21 +0000 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | void GrDrawTarget::releaseGeometry() { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 119 | int popCnt = fGeoSrcStateStack.count() - 1; |
| 120 | while (popCnt) { |
| 121 | this->popGeometrySource(); |
| 122 | --popCnt; |
| 123 | } |
bsalomon@google.com | 4a018bb | 2011-10-28 19:50:21 +0000 | [diff] [blame] | 124 | this->resetVertexSource(); |
| 125 | this->resetIndexSource(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 126 | } |
| 127 | |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 128 | void GrDrawTarget::setClip(const GrClipData* clip) { |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 129 | clipWillBeSet(clip); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 130 | fClip = clip; |
| 131 | } |
| 132 | |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 133 | const GrClipData* GrDrawTarget::getClip() const { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 134 | return fClip; |
| 135 | } |
| 136 | |
bsalomon@google.com | a5d056a | 2012-03-27 15:59:58 +0000 | [diff] [blame] | 137 | void GrDrawTarget::setDrawState(GrDrawState* drawState) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 138 | SkASSERT(fDrawState); |
bsalomon@google.com | a5d056a | 2012-03-27 15:59:58 +0000 | [diff] [blame] | 139 | if (NULL == drawState) { |
| 140 | drawState = &fDefaultDrawState; |
| 141 | } |
| 142 | if (fDrawState != drawState) { |
| 143 | fDrawState->unref(); |
| 144 | drawState->ref(); |
| 145 | fDrawState = drawState; |
| 146 | } |
| 147 | } |
| 148 | |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 149 | bool GrDrawTarget::reserveVertexSpace(size_t vertexSize, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 150 | int vertexCount, |
| 151 | void** vertices) { |
| 152 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 153 | bool acquired = false; |
| 154 | if (vertexCount > 0) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 155 | SkASSERT(vertices); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 156 | this->releasePreviousVertexSource(); |
| 157 | geoSrc.fVertexSrc = kNone_GeometrySrcType; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 158 | |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 159 | acquired = this->onReserveVertexSpace(vertexSize, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 160 | vertexCount, |
| 161 | vertices); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 162 | } |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 163 | if (acquired) { |
| 164 | geoSrc.fVertexSrc = kReserved_GeometrySrcType; |
| 165 | geoSrc.fVertexCount = vertexCount; |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 166 | geoSrc.fVertexSize = vertexSize; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 167 | } else if (vertices) { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 168 | *vertices = NULL; |
| 169 | } |
| 170 | return acquired; |
| 171 | } |
| 172 | |
| 173 | bool GrDrawTarget::reserveIndexSpace(int indexCount, |
| 174 | void** indices) { |
| 175 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 176 | bool acquired = false; |
| 177 | if (indexCount > 0) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 178 | SkASSERT(indices); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 179 | this->releasePreviousIndexSource(); |
| 180 | geoSrc.fIndexSrc = kNone_GeometrySrcType; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 181 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 182 | acquired = this->onReserveIndexSpace(indexCount, indices); |
| 183 | } |
| 184 | if (acquired) { |
| 185 | geoSrc.fIndexSrc = kReserved_GeometrySrcType; |
| 186 | geoSrc.fIndexCount = indexCount; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 187 | } else if (indices) { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 188 | *indices = NULL; |
| 189 | } |
| 190 | return acquired; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 191 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 192 | } |
| 193 | |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 194 | bool GrDrawTarget::reserveVertexAndIndexSpace(int vertexCount, |
bsalomon@google.com | e3d7095 | 2012-03-13 12:40:53 +0000 | [diff] [blame] | 195 | int indexCount, |
| 196 | void** vertices, |
| 197 | void** indices) { |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame] | 198 | size_t vertexStride = this->drawState()->getVertexStride(); |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 199 | this->willReserveVertexAndIndexSpace(vertexCount, indexCount); |
bsalomon@google.com | e3d7095 | 2012-03-13 12:40:53 +0000 | [diff] [blame] | 200 | if (vertexCount) { |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame] | 201 | if (!this->reserveVertexSpace(vertexStride, vertexCount, vertices)) { |
bsalomon@google.com | e3d7095 | 2012-03-13 12:40:53 +0000 | [diff] [blame] | 202 | if (indexCount) { |
| 203 | this->resetIndexSource(); |
| 204 | } |
| 205 | return false; |
| 206 | } |
| 207 | } |
| 208 | if (indexCount) { |
| 209 | if (!this->reserveIndexSpace(indexCount, indices)) { |
| 210 | if (vertexCount) { |
| 211 | this->resetVertexSource(); |
| 212 | } |
| 213 | return false; |
| 214 | } |
| 215 | } |
| 216 | return true; |
| 217 | } |
| 218 | |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 219 | bool GrDrawTarget::geometryHints(int32_t* vertexCount, |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 220 | int32_t* indexCount) const { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 221 | if (vertexCount) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 222 | *vertexCount = -1; |
| 223 | } |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 224 | if (indexCount) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 225 | *indexCount = -1; |
| 226 | } |
| 227 | return false; |
| 228 | } |
| 229 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 230 | void GrDrawTarget::releasePreviousVertexSource() { |
| 231 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 232 | switch (geoSrc.fVertexSrc) { |
| 233 | case kNone_GeometrySrcType: |
| 234 | break; |
| 235 | case kArray_GeometrySrcType: |
| 236 | this->releaseVertexArray(); |
| 237 | break; |
| 238 | case kReserved_GeometrySrcType: |
| 239 | this->releaseReservedVertexSpace(); |
| 240 | break; |
| 241 | case kBuffer_GeometrySrcType: |
| 242 | geoSrc.fVertexBuffer->unref(); |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 243 | #ifdef SK_DEBUG |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 244 | geoSrc.fVertexBuffer = (GrVertexBuffer*)DEBUG_INVAL_BUFFER; |
| 245 | #endif |
| 246 | break; |
| 247 | default: |
commit-bot@chromium.org | 88cb22b | 2014-04-30 14:17:00 +0000 | [diff] [blame] | 248 | SkFAIL("Unknown Vertex Source Type."); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 249 | break; |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | void GrDrawTarget::releasePreviousIndexSource() { |
| 254 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 255 | switch (geoSrc.fIndexSrc) { |
| 256 | case kNone_GeometrySrcType: // these two don't require |
| 257 | break; |
| 258 | case kArray_GeometrySrcType: |
| 259 | this->releaseIndexArray(); |
| 260 | break; |
| 261 | case kReserved_GeometrySrcType: |
| 262 | this->releaseReservedIndexSpace(); |
| 263 | break; |
| 264 | case kBuffer_GeometrySrcType: |
| 265 | geoSrc.fIndexBuffer->unref(); |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 266 | #ifdef SK_DEBUG |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 267 | geoSrc.fIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER; |
| 268 | #endif |
| 269 | break; |
| 270 | default: |
commit-bot@chromium.org | 88cb22b | 2014-04-30 14:17:00 +0000 | [diff] [blame] | 271 | SkFAIL("Unknown Index Source Type."); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 272 | break; |
| 273 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 274 | } |
| 275 | |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 276 | void GrDrawTarget::setVertexSourceToArray(const void* vertexArray, |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 277 | int vertexCount) { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 278 | this->releasePreviousVertexSource(); |
| 279 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 280 | geoSrc.fVertexSrc = kArray_GeometrySrcType; |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame] | 281 | geoSrc.fVertexSize = this->drawState()->getVertexStride(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 282 | geoSrc.fVertexCount = vertexCount; |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 283 | this->onSetVertexSourceToArray(vertexArray, vertexCount); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 284 | } |
| 285 | |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 286 | void GrDrawTarget::setIndexSourceToArray(const void* indexArray, |
| 287 | int indexCount) { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 288 | this->releasePreviousIndexSource(); |
| 289 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 290 | geoSrc.fIndexSrc = kArray_GeometrySrcType; |
| 291 | geoSrc.fIndexCount = indexCount; |
bsalomon@google.com | bcdbbe6 | 2011-04-12 15:40:00 +0000 | [diff] [blame] | 292 | this->onSetIndexSourceToArray(indexArray, indexCount); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 293 | } |
| 294 | |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 295 | void GrDrawTarget::setVertexSourceToBuffer(const GrVertexBuffer* buffer) { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 296 | this->releasePreviousVertexSource(); |
| 297 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 298 | geoSrc.fVertexSrc = kBuffer_GeometrySrcType; |
| 299 | geoSrc.fVertexBuffer = buffer; |
| 300 | buffer->ref(); |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame] | 301 | geoSrc.fVertexSize = this->drawState()->getVertexStride(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | void GrDrawTarget::setIndexSourceToBuffer(const GrIndexBuffer* buffer) { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 305 | this->releasePreviousIndexSource(); |
| 306 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 307 | geoSrc.fIndexSrc = kBuffer_GeometrySrcType; |
| 308 | geoSrc.fIndexBuffer = buffer; |
| 309 | buffer->ref(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 310 | } |
| 311 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 312 | void GrDrawTarget::resetVertexSource() { |
| 313 | this->releasePreviousVertexSource(); |
| 314 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 315 | geoSrc.fVertexSrc = kNone_GeometrySrcType; |
| 316 | } |
| 317 | |
| 318 | void GrDrawTarget::resetIndexSource() { |
| 319 | this->releasePreviousIndexSource(); |
| 320 | GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
| 321 | geoSrc.fIndexSrc = kNone_GeometrySrcType; |
| 322 | } |
| 323 | |
| 324 | void GrDrawTarget::pushGeometrySource() { |
| 325 | this->geometrySourceWillPush(); |
| 326 | GeometrySrcState& newState = fGeoSrcStateStack.push_back(); |
| 327 | newState.fIndexSrc = kNone_GeometrySrcType; |
| 328 | newState.fVertexSrc = kNone_GeometrySrcType; |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 329 | #ifdef SK_DEBUG |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 330 | newState.fVertexCount = ~0; |
| 331 | newState.fVertexBuffer = (GrVertexBuffer*)~0; |
| 332 | newState.fIndexCount = ~0; |
| 333 | newState.fIndexBuffer = (GrIndexBuffer*)~0; |
| 334 | #endif |
| 335 | } |
| 336 | |
| 337 | void GrDrawTarget::popGeometrySource() { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 338 | // if popping last element then pops are unbalanced with pushes |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 339 | SkASSERT(fGeoSrcStateStack.count() > 1); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 340 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 341 | this->geometrySourceWillPop(fGeoSrcStateStack.fromBack(1)); |
| 342 | this->releasePreviousVertexSource(); |
| 343 | this->releasePreviousIndexSource(); |
| 344 | fGeoSrcStateStack.pop_back(); |
| 345 | } |
| 346 | |
| 347 | //////////////////////////////////////////////////////////////////////////////// |
| 348 | |
bsalomon@google.com | e826262 | 2011-11-07 02:30:51 +0000 | [diff] [blame] | 349 | bool GrDrawTarget::checkDraw(GrPrimitiveType type, int startVertex, |
| 350 | int startIndex, int vertexCount, |
| 351 | int indexCount) const { |
bsalomon@google.com | cddaf34 | 2012-07-30 13:09:05 +0000 | [diff] [blame] | 352 | const GrDrawState& drawState = this->getDrawState(); |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 353 | #ifdef SK_DEBUG |
bsalomon@google.com | e826262 | 2011-11-07 02:30:51 +0000 | [diff] [blame] | 354 | const GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 355 | int maxVertex = startVertex + vertexCount; |
| 356 | int maxValidVertex; |
| 357 | switch (geoSrc.fVertexSrc) { |
| 358 | case kNone_GeometrySrcType: |
commit-bot@chromium.org | 88cb22b | 2014-04-30 14:17:00 +0000 | [diff] [blame] | 359 | SkFAIL("Attempting to draw without vertex src."); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 360 | case kReserved_GeometrySrcType: // fallthrough |
| 361 | case kArray_GeometrySrcType: |
| 362 | maxValidVertex = geoSrc.fVertexCount; |
| 363 | break; |
| 364 | case kBuffer_GeometrySrcType: |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 365 | maxValidVertex = static_cast<int>(geoSrc.fVertexBuffer->gpuMemorySize() / geoSrc.fVertexSize); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 366 | break; |
| 367 | } |
| 368 | if (maxVertex > maxValidVertex) { |
commit-bot@chromium.org | 88cb22b | 2014-04-30 14:17:00 +0000 | [diff] [blame] | 369 | SkFAIL("Drawing outside valid vertex range."); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 370 | } |
bsalomon@google.com | e826262 | 2011-11-07 02:30:51 +0000 | [diff] [blame] | 371 | if (indexCount > 0) { |
| 372 | int maxIndex = startIndex + indexCount; |
| 373 | int maxValidIndex; |
| 374 | switch (geoSrc.fIndexSrc) { |
| 375 | case kNone_GeometrySrcType: |
commit-bot@chromium.org | 88cb22b | 2014-04-30 14:17:00 +0000 | [diff] [blame] | 376 | SkFAIL("Attempting to draw indexed geom without index src."); |
bsalomon@google.com | e826262 | 2011-11-07 02:30:51 +0000 | [diff] [blame] | 377 | case kReserved_GeometrySrcType: // fallthrough |
| 378 | case kArray_GeometrySrcType: |
| 379 | maxValidIndex = geoSrc.fIndexCount; |
| 380 | break; |
| 381 | case kBuffer_GeometrySrcType: |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 382 | maxValidIndex = static_cast<int>(geoSrc.fIndexBuffer->gpuMemorySize() / sizeof(uint16_t)); |
bsalomon@google.com | e826262 | 2011-11-07 02:30:51 +0000 | [diff] [blame] | 383 | break; |
| 384 | } |
| 385 | if (maxIndex > maxValidIndex) { |
commit-bot@chromium.org | 88cb22b | 2014-04-30 14:17:00 +0000 | [diff] [blame] | 386 | SkFAIL("Index reads outside valid index range."); |
bsalomon@google.com | e826262 | 2011-11-07 02:30:51 +0000 | [diff] [blame] | 387 | } |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 388 | } |
bsalomon@google.com | b4725b4 | 2012-03-30 17:24:17 +0000 | [diff] [blame] | 389 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 390 | SkASSERT(drawState.getRenderTarget()); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 391 | |
joshualitt | bd769d0 | 2014-09-04 08:56:46 -0700 | [diff] [blame] | 392 | if (drawState.hasGeometryProcessor()) { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 393 | const GrGeometryProcessor* gp = drawState.getGeometryProcessor()->getGeometryProcessor(); |
| 394 | int numTextures = gp->numTextures(); |
joshualitt | bd769d0 | 2014-09-04 08:56:46 -0700 | [diff] [blame] | 395 | for (int t = 0; t < numTextures; ++t) { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 396 | GrTexture* texture = gp->texture(t); |
joshualitt | bd769d0 | 2014-09-04 08:56:46 -0700 | [diff] [blame] | 397 | SkASSERT(texture->asRenderTarget() != drawState.getRenderTarget()); |
| 398 | } |
| 399 | } |
| 400 | |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 401 | for (int s = 0; s < drawState.numColorStages(); ++s) { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 402 | const GrProcessor* effect = drawState.getColorStage(s).getProcessor(); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 403 | int numTextures = effect->numTextures(); |
| 404 | for (int t = 0; t < numTextures; ++t) { |
| 405 | GrTexture* texture = effect->texture(t); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 406 | SkASSERT(texture->asRenderTarget() != drawState.getRenderTarget()); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 407 | } |
| 408 | } |
| 409 | for (int s = 0; s < drawState.numCoverageStages(); ++s) { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 410 | const GrProcessor* effect = drawState.getCoverageStage(s).getProcessor(); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 411 | int numTextures = effect->numTextures(); |
| 412 | for (int t = 0; t < numTextures; ++t) { |
| 413 | GrTexture* texture = effect->texture(t); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 414 | SkASSERT(texture->asRenderTarget() != drawState.getRenderTarget()); |
bsalomon@google.com | b4725b4 | 2012-03-30 17:24:17 +0000 | [diff] [blame] | 415 | } |
| 416 | } |
commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 417 | |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 418 | SkASSERT(drawState.validateVertexAttribs()); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 419 | #endif |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 420 | if (NULL == drawState.getRenderTarget()) { |
bsalomon@google.com | 0ba52fc | 2011-11-10 22:16:06 +0000 | [diff] [blame] | 421 | return false; |
| 422 | } |
bsalomon@google.com | e826262 | 2011-11-07 02:30:51 +0000 | [diff] [blame] | 423 | return true; |
| 424 | } |
| 425 | |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 426 | bool GrDrawTarget::setupDstReadIfNecessary(GrDeviceCoordTexture* dstCopy, const SkRect* drawBounds) { |
bsalomon@google.com | b515881 | 2013-05-13 18:50:25 +0000 | [diff] [blame] | 427 | if (this->caps()->dstReadInShaderSupport() || !this->getDrawState().willEffectReadDstColor()) { |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 428 | return true; |
| 429 | } |
| 430 | GrRenderTarget* rt = this->drawState()->getRenderTarget(); |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 431 | SkIRect copyRect; |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 432 | const GrClipData* clip = this->getClip(); |
| 433 | clip->getConservativeBounds(rt, ©Rect); |
| 434 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 435 | if (drawBounds) { |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 436 | SkIRect drawIBounds; |
| 437 | drawBounds->roundOut(&drawIBounds); |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 438 | if (!copyRect.intersect(drawIBounds)) { |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 439 | #ifdef SK_DEBUG |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 440 | GrPrintf("Missed an early reject. Bailing on draw from setupDstReadIfNecessary.\n"); |
| 441 | #endif |
| 442 | return false; |
| 443 | } |
| 444 | } else { |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 445 | #ifdef SK_DEBUG |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 446 | //GrPrintf("No dev bounds when dst copy is made.\n"); |
| 447 | #endif |
| 448 | } |
skia.committer@gmail.com | 05a2ee0 | 2013-04-02 07:01:34 +0000 | [diff] [blame] | 449 | |
commit-bot@chromium.org | 63150af | 2013-04-11 22:00:22 +0000 | [diff] [blame] | 450 | // MSAA consideration: When there is support for reading MSAA samples in the shader we could |
| 451 | // have per-sample dst values by making the copy multisampled. |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 452 | GrTextureDesc desc; |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 453 | this->initCopySurfaceDstDesc(rt, &desc); |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 454 | desc.fWidth = copyRect.width(); |
| 455 | desc.fHeight = copyRect.height(); |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 456 | |
| 457 | GrAutoScratchTexture ast(fContext, desc, GrContext::kApprox_ScratchTexMatch); |
| 458 | |
| 459 | if (NULL == ast.texture()) { |
| 460 | GrPrintf("Failed to create temporary copy of destination texture.\n"); |
| 461 | return false; |
| 462 | } |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 463 | SkIPoint dstPoint = {0, 0}; |
| 464 | if (this->copySurface(ast.texture(), rt, copyRect, dstPoint)) { |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 465 | dstCopy->setTexture(ast.texture()); |
| 466 | dstCopy->setOffset(copyRect.fLeft, copyRect.fTop); |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 467 | return true; |
| 468 | } else { |
| 469 | return false; |
| 470 | } |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 471 | } |
| 472 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 473 | void GrDrawTarget::drawIndexed(GrPrimitiveType type, |
| 474 | int startVertex, |
| 475 | int startIndex, |
| 476 | int vertexCount, |
| 477 | int indexCount, |
| 478 | const SkRect* devBounds) { |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 479 | if (indexCount > 0 && this->checkDraw(type, startVertex, startIndex, vertexCount, indexCount)) { |
| 480 | DrawInfo info; |
| 481 | info.fPrimitiveType = type; |
| 482 | info.fStartVertex = startVertex; |
| 483 | info.fStartIndex = startIndex; |
| 484 | info.fVertexCount = vertexCount; |
| 485 | info.fIndexCount = indexCount; |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 486 | |
| 487 | info.fInstanceCount = 0; |
| 488 | info.fVerticesPerInstance = 0; |
| 489 | info.fIndicesPerInstance = 0; |
| 490 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 491 | if (devBounds) { |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 492 | info.setDevBounds(*devBounds); |
| 493 | } |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 494 | // TODO: We should continue with incorrect blending. |
| 495 | if (!this->setupDstReadIfNecessary(&info)) { |
| 496 | return; |
| 497 | } |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 498 | this->onDraw(info); |
bsalomon@google.com | 8214587 | 2011-08-23 14:32:40 +0000 | [diff] [blame] | 499 | } |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 500 | } |
| 501 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 502 | void GrDrawTarget::drawNonIndexed(GrPrimitiveType type, |
| 503 | int startVertex, |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 504 | int vertexCount, |
| 505 | const SkRect* devBounds) { |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 506 | if (vertexCount > 0 && this->checkDraw(type, startVertex, -1, vertexCount, -1)) { |
| 507 | DrawInfo info; |
| 508 | info.fPrimitiveType = type; |
| 509 | info.fStartVertex = startVertex; |
| 510 | info.fStartIndex = 0; |
| 511 | info.fVertexCount = vertexCount; |
| 512 | info.fIndexCount = 0; |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 513 | |
| 514 | info.fInstanceCount = 0; |
| 515 | info.fVerticesPerInstance = 0; |
| 516 | info.fIndicesPerInstance = 0; |
| 517 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 518 | if (devBounds) { |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 519 | info.setDevBounds(*devBounds); |
| 520 | } |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 521 | // TODO: We should continue with incorrect blending. |
| 522 | if (!this->setupDstReadIfNecessary(&info)) { |
| 523 | return; |
| 524 | } |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 525 | this->onDraw(info); |
bsalomon@google.com | 8214587 | 2011-08-23 14:32:40 +0000 | [diff] [blame] | 526 | } |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 527 | } |
| 528 | |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 529 | void GrDrawTarget::stencilPath(const GrPath* path, SkPath::FillType fill) { |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 530 | // TODO: extract portions of checkDraw that are relevant to path stenciling. |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 531 | SkASSERT(path); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 532 | SkASSERT(this->caps()->pathRenderingSupport()); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 533 | SkASSERT(!SkPath::IsInverseFillType(fill)); |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 534 | this->onStencilPath(path, fill); |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 535 | } |
| 536 | |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 537 | void GrDrawTarget::drawPath(const GrPath* path, SkPath::FillType fill) { |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 538 | // TODO: extract portions of checkDraw that are relevant to path rendering. |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 539 | SkASSERT(path); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 540 | SkASSERT(this->caps()->pathRenderingSupport()); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 541 | const GrDrawState* drawState = &getDrawState(); |
| 542 | |
| 543 | SkRect devBounds; |
| 544 | if (SkPath::IsInverseFillType(fill)) { |
| 545 | devBounds = SkRect::MakeWH(SkIntToScalar(drawState->getRenderTarget()->width()), |
| 546 | SkIntToScalar(drawState->getRenderTarget()->height())); |
| 547 | } else { |
| 548 | devBounds = path->getBounds(); |
| 549 | } |
| 550 | SkMatrix viewM = drawState->getViewMatrix(); |
| 551 | viewM.mapRect(&devBounds); |
| 552 | |
| 553 | GrDeviceCoordTexture dstCopy; |
| 554 | if (!this->setupDstReadIfNecessary(&dstCopy, &devBounds)) { |
| 555 | return; |
| 556 | } |
| 557 | |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 558 | this->onDrawPath(path, fill, dstCopy.texture() ? &dstCopy : NULL); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 559 | } |
| 560 | |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 561 | void GrDrawTarget::drawPaths(const GrPathRange* pathRange, |
| 562 | const uint32_t indices[], int count, |
| 563 | const float transforms[], PathTransformType transformsType, |
| 564 | SkPath::FillType fill) { |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 565 | SkASSERT(this->caps()->pathRenderingSupport()); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 566 | SkASSERT(pathRange); |
| 567 | SkASSERT(indices); |
| 568 | SkASSERT(transforms); |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 569 | |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 570 | // Don't compute a bounding box for setupDstReadIfNecessary(), we'll opt |
| 571 | // instead for it to just copy the entire dst. Realistically this is a moot |
| 572 | // point, because any context that supports NV_path_rendering will also |
| 573 | // support NV_blend_equation_advanced. |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 574 | GrDeviceCoordTexture dstCopy; |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 575 | if (!this->setupDstReadIfNecessary(&dstCopy, NULL)) { |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 576 | return; |
| 577 | } |
| 578 | |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 579 | this->onDrawPaths(pathRange, indices, count, transforms, transformsType, fill, |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 580 | dstCopy.texture() ? &dstCopy : NULL); |
| 581 | } |
| 582 | |
egdaniel | 3eee383 | 2014-06-18 13:09:11 -0700 | [diff] [blame] | 583 | typedef GrTraceMarkerSet::Iter TMIter; |
| 584 | void GrDrawTarget::saveActiveTraceMarkers() { |
| 585 | if (this->caps()->gpuTracingSupport()) { |
| 586 | SkASSERT(0 == fStoredTraceMarkers.count()); |
| 587 | fStoredTraceMarkers.addSet(fActiveTraceMarkers); |
| 588 | for (TMIter iter = fStoredTraceMarkers.begin(); iter != fStoredTraceMarkers.end(); ++iter) { |
| 589 | this->removeGpuTraceMarker(&(*iter)); |
| 590 | } |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | void GrDrawTarget::restoreActiveTraceMarkers() { |
| 595 | if (this->caps()->gpuTracingSupport()) { |
| 596 | SkASSERT(0 == fActiveTraceMarkers.count()); |
| 597 | for (TMIter iter = fStoredTraceMarkers.begin(); iter != fStoredTraceMarkers.end(); ++iter) { |
| 598 | this->addGpuTraceMarker(&(*iter)); |
| 599 | } |
| 600 | for (TMIter iter = fActiveTraceMarkers.begin(); iter != fActiveTraceMarkers.end(); ++iter) { |
| 601 | this->fStoredTraceMarkers.remove(*iter); |
| 602 | } |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | void GrDrawTarget::addGpuTraceMarker(const GrGpuTraceMarker* marker) { |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 607 | if (this->caps()->gpuTracingSupport()) { |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 608 | SkASSERT(fGpuTraceMarkerCount >= 0); |
| 609 | this->fActiveTraceMarkers.add(*marker); |
| 610 | this->didAddGpuTraceMarker(); |
| 611 | ++fGpuTraceMarkerCount; |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 612 | } |
| 613 | } |
| 614 | |
egdaniel | 3eee383 | 2014-06-18 13:09:11 -0700 | [diff] [blame] | 615 | void GrDrawTarget::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 616 | if (this->caps()->gpuTracingSupport()) { |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 617 | SkASSERT(fGpuTraceMarkerCount >= 1); |
| 618 | this->fActiveTraceMarkers.remove(*marker); |
| 619 | this->didRemoveGpuTraceMarker(); |
| 620 | --fGpuTraceMarkerCount; |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 621 | } |
| 622 | } |
| 623 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 624 | //////////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 625 | |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 626 | void GrDrawTarget::drawIndexedInstances(GrPrimitiveType type, |
| 627 | int instanceCount, |
| 628 | int verticesPerInstance, |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 629 | int indicesPerInstance, |
| 630 | const SkRect* devBounds) { |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 631 | if (!verticesPerInstance || !indicesPerInstance) { |
| 632 | return; |
| 633 | } |
| 634 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 635 | int maxInstancesPerDraw = this->indexCountInCurrentSource() / indicesPerInstance; |
| 636 | if (!maxInstancesPerDraw) { |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 637 | return; |
| 638 | } |
| 639 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 640 | DrawInfo info; |
| 641 | info.fPrimitiveType = type; |
| 642 | info.fStartIndex = 0; |
| 643 | info.fStartVertex = 0; |
| 644 | info.fIndicesPerInstance = indicesPerInstance; |
| 645 | info.fVerticesPerInstance = verticesPerInstance; |
| 646 | |
| 647 | // Set the same bounds for all the draws. |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 648 | if (devBounds) { |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 649 | info.setDevBounds(*devBounds); |
| 650 | } |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 651 | // TODO: We should continue with incorrect blending. |
| 652 | if (!this->setupDstReadIfNecessary(&info)) { |
| 653 | return; |
| 654 | } |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 655 | |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 656 | while (instanceCount) { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 657 | info.fInstanceCount = SkTMin(instanceCount, maxInstancesPerDraw); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 658 | info.fVertexCount = info.fInstanceCount * verticesPerInstance; |
| 659 | info.fIndexCount = info.fInstanceCount * indicesPerInstance; |
| 660 | |
| 661 | if (this->checkDraw(type, |
| 662 | info.fStartVertex, |
| 663 | info.fStartIndex, |
| 664 | info.fVertexCount, |
| 665 | info.fIndexCount)) { |
| 666 | this->onDraw(info); |
| 667 | } |
| 668 | info.fStartVertex += info.fVertexCount; |
| 669 | instanceCount -= info.fInstanceCount; |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 670 | } |
| 671 | } |
bsalomon@google.com | 3d0835b | 2011-12-08 16:12:03 +0000 | [diff] [blame] | 672 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 673 | //////////////////////////////////////////////////////////////////////////////// |
| 674 | |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 675 | namespace { |
| 676 | |
| 677 | // position + (optional) texture coord |
| 678 | extern const GrVertexAttrib gBWRectPosUVAttribs[] = { |
| 679 | {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}, |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 680 | {kVec2f_GrVertexAttribType, sizeof(SkPoint), kLocalCoord_GrVertexAttribBinding} |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 681 | }; |
| 682 | |
| 683 | void set_vertex_attributes(GrDrawState* drawState, bool hasUVs) { |
| 684 | if (hasUVs) { |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame] | 685 | drawState->setVertexAttribs<gBWRectPosUVAttribs>(2, 2 * sizeof(SkPoint)); |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 686 | } else { |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame] | 687 | drawState->setVertexAttribs<gBWRectPosUVAttribs>(1, sizeof(SkPoint)); |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 688 | } |
| 689 | } |
| 690 | |
| 691 | }; |
| 692 | |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 693 | void GrDrawTarget::onDrawRect(const SkRect& rect, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 694 | const SkRect* localRect, |
bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 695 | const SkMatrix* localMatrix) { |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 696 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 697 | set_vertex_attributes(this->drawState(), SkToBool(localRect)); |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 698 | |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 699 | AutoReleaseGeometry geo(this, 4, 0); |
bsalomon@google.com | 6513cd0 | 2011-08-05 20:12:30 +0000 | [diff] [blame] | 700 | if (!geo.succeeded()) { |
| 701 | GrPrintf("Failed to get space for vertices!\n"); |
| 702 | return; |
| 703 | } |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 704 | |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame] | 705 | size_t vstride = this->drawState()->getVertexStride(); |
| 706 | geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, vstride); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 707 | if (localRect) { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 708 | SkPoint* coords = GrTCast<SkPoint*>(GrTCast<intptr_t>(geo.vertices()) + |
| 709 | sizeof(SkPoint)); |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 710 | coords->setRectFan(localRect->fLeft, localRect->fTop, |
| 711 | localRect->fRight, localRect->fBottom, |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame] | 712 | vstride); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 713 | if (localMatrix) { |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame] | 714 | localMatrix->mapPointsWithStride(coords, vstride, 4); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 715 | } |
| 716 | } |
commit-bot@chromium.org | 3ae0e6c | 2014-02-11 18:24:25 +0000 | [diff] [blame] | 717 | SkRect bounds; |
| 718 | this->getDrawState().getViewMatrix().mapRect(&bounds, rect); |
robertphillips@google.com | 8b129aa | 2012-10-05 15:37:00 +0000 | [diff] [blame] | 719 | |
commit-bot@chromium.org | 3ae0e6c | 2014-02-11 18:24:25 +0000 | [diff] [blame] | 720 | this->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4, &bounds); |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 721 | } |
| 722 | |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 723 | void GrDrawTarget::clipWillBeSet(const GrClipData* clipData) { |
| 724 | } |
| 725 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 726 | //////////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 7ac249b | 2011-06-14 18:46:24 +0000 | [diff] [blame] | 727 | |
bsalomon@google.com | 06afe7b | 2011-04-26 15:31:40 +0000 | [diff] [blame] | 728 | GrDrawTarget::AutoStateRestore::AutoStateRestore() { |
| 729 | fDrawTarget = NULL; |
| 730 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 731 | |
bsalomon@google.com | 873ea0c | 2012-03-30 15:55:32 +0000 | [diff] [blame] | 732 | GrDrawTarget::AutoStateRestore::AutoStateRestore(GrDrawTarget* target, |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 733 | ASRInit init, |
| 734 | const SkMatrix* vm) { |
bsalomon@google.com | 873ea0c | 2012-03-30 15:55:32 +0000 | [diff] [blame] | 735 | fDrawTarget = NULL; |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 736 | this->set(target, init, vm); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | GrDrawTarget::AutoStateRestore::~AutoStateRestore() { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 740 | if (fDrawTarget) { |
bsalomon@google.com | 873ea0c | 2012-03-30 15:55:32 +0000 | [diff] [blame] | 741 | fDrawTarget->setDrawState(fSavedState); |
| 742 | fSavedState->unref(); |
bsalomon@google.com | 7d34d2e | 2011-01-24 17:41:47 +0000 | [diff] [blame] | 743 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 744 | } |
bsalomon@google.com | 7d34d2e | 2011-01-24 17:41:47 +0000 | [diff] [blame] | 745 | |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 746 | void GrDrawTarget::AutoStateRestore::set(GrDrawTarget* target, ASRInit init, const SkMatrix* vm) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 747 | SkASSERT(NULL == fDrawTarget); |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 748 | fDrawTarget = target; |
| 749 | fSavedState = target->drawState(); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 750 | SkASSERT(fSavedState); |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 751 | fSavedState->ref(); |
| 752 | if (kReset_ASRInit == init) { |
| 753 | if (NULL == vm) { |
| 754 | // calls the default cons |
| 755 | fTempState.init(); |
| 756 | } else { |
| 757 | SkNEW_IN_TLAZY(&fTempState, GrDrawState, (*vm)); |
| 758 | } |
| 759 | } else { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 760 | SkASSERT(kPreserve_ASRInit == init); |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 761 | if (NULL == vm) { |
| 762 | fTempState.set(*fSavedState); |
| 763 | } else { |
| 764 | SkNEW_IN_TLAZY(&fTempState, GrDrawState, (*fSavedState, *vm)); |
| 765 | } |
| 766 | } |
| 767 | target->setDrawState(fTempState.get()); |
| 768 | } |
| 769 | |
| 770 | bool GrDrawTarget::AutoStateRestore::setIdentity(GrDrawTarget* target, ASRInit init) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 771 | SkASSERT(NULL == fDrawTarget); |
bsalomon@google.com | 873ea0c | 2012-03-30 15:55:32 +0000 | [diff] [blame] | 772 | fDrawTarget = target; |
| 773 | fSavedState = target->drawState(); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 774 | SkASSERT(fSavedState); |
bsalomon@google.com | 873ea0c | 2012-03-30 15:55:32 +0000 | [diff] [blame] | 775 | fSavedState->ref(); |
| 776 | if (kReset_ASRInit == init) { |
| 777 | // calls the default cons |
| 778 | fTempState.init(); |
| 779 | } else { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 780 | SkASSERT(kPreserve_ASRInit == init); |
bsalomon@google.com | 873ea0c | 2012-03-30 15:55:32 +0000 | [diff] [blame] | 781 | // calls the copy cons |
| 782 | fTempState.set(*fSavedState); |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 783 | if (!fTempState.get()->setIdentityViewMatrix()) { |
| 784 | // let go of any resources held by the temp |
| 785 | fTempState.get()->reset(); |
| 786 | fDrawTarget = NULL; |
| 787 | fSavedState->unref(); |
| 788 | fSavedState = NULL; |
| 789 | return false; |
| 790 | } |
bsalomon@google.com | 06afe7b | 2011-04-26 15:31:40 +0000 | [diff] [blame] | 791 | } |
bsalomon@google.com | 873ea0c | 2012-03-30 15:55:32 +0000 | [diff] [blame] | 792 | target->setDrawState(fTempState.get()); |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 793 | return true; |
bsalomon@google.com | 06afe7b | 2011-04-26 15:31:40 +0000 | [diff] [blame] | 794 | } |
bsalomon@google.com | 7ac249b | 2011-06-14 18:46:24 +0000 | [diff] [blame] | 795 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 796 | //////////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 7ac249b | 2011-06-14 18:46:24 +0000 | [diff] [blame] | 797 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 798 | GrDrawTarget::AutoReleaseGeometry::AutoReleaseGeometry( |
| 799 | GrDrawTarget* target, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 800 | int vertexCount, |
| 801 | int indexCount) { |
| 802 | fTarget = NULL; |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 803 | this->set(target, vertexCount, indexCount); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 804 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 805 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 806 | GrDrawTarget::AutoReleaseGeometry::AutoReleaseGeometry() { |
| 807 | fTarget = NULL; |
| 808 | } |
| 809 | |
| 810 | GrDrawTarget::AutoReleaseGeometry::~AutoReleaseGeometry() { |
| 811 | this->reset(); |
| 812 | } |
| 813 | |
| 814 | bool GrDrawTarget::AutoReleaseGeometry::set(GrDrawTarget* target, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 815 | int vertexCount, |
| 816 | int indexCount) { |
| 817 | this->reset(); |
| 818 | fTarget = target; |
| 819 | bool success = true; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 820 | if (fTarget) { |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 821 | success = target->reserveVertexAndIndexSpace(vertexCount, |
bsalomon@google.com | e3d7095 | 2012-03-13 12:40:53 +0000 | [diff] [blame] | 822 | indexCount, |
| 823 | &fVertices, |
| 824 | &fIndices); |
| 825 | if (!success) { |
| 826 | fTarget = NULL; |
| 827 | this->reset(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 828 | } |
| 829 | } |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 830 | SkASSERT(success == SkToBool(fTarget)); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 831 | return success; |
| 832 | } |
| 833 | |
| 834 | void GrDrawTarget::AutoReleaseGeometry::reset() { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 835 | if (fTarget) { |
| 836 | if (fVertices) { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 837 | fTarget->resetVertexSource(); |
| 838 | } |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 839 | if (fIndices) { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 840 | fTarget->resetIndexSource(); |
| 841 | } |
| 842 | fTarget = NULL; |
| 843 | } |
bsalomon@google.com | cb0c5ab | 2011-06-29 17:48:17 +0000 | [diff] [blame] | 844 | fVertices = NULL; |
| 845 | fIndices = NULL; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 846 | } |
| 847 | |
bsalomon@google.com | 8d67c07 | 2012-12-13 20:38:14 +0000 | [diff] [blame] | 848 | GrDrawTarget::AutoClipRestore::AutoClipRestore(GrDrawTarget* target, const SkIRect& newClip) { |
| 849 | fTarget = target; |
| 850 | fClip = fTarget->getClip(); |
| 851 | fStack.init(); |
| 852 | fStack.get()->clipDevRect(newClip, SkRegion::kReplace_Op); |
| 853 | fReplacementClip.fClipStack = fStack.get(); |
| 854 | target->setClip(&fReplacementClip); |
| 855 | } |
| 856 | |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 857 | namespace { |
| 858 | // returns true if the read/written rect intersects the src/dst and false if not. |
| 859 | bool clip_srcrect_and_dstpoint(const GrSurface* dst, |
| 860 | const GrSurface* src, |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 861 | const SkIRect& srcRect, |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 862 | const SkIPoint& dstPoint, |
| 863 | SkIRect* clippedSrcRect, |
| 864 | SkIPoint* clippedDstPoint) { |
| 865 | *clippedSrcRect = srcRect; |
| 866 | *clippedDstPoint = dstPoint; |
skia.committer@gmail.com | a9493a3 | 2013-04-04 07:01:12 +0000 | [diff] [blame] | 867 | |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 868 | // clip the left edge to src and dst bounds, adjusting dstPoint if necessary |
| 869 | if (clippedSrcRect->fLeft < 0) { |
| 870 | clippedDstPoint->fX -= clippedSrcRect->fLeft; |
| 871 | clippedSrcRect->fLeft = 0; |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 872 | } |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 873 | if (clippedDstPoint->fX < 0) { |
| 874 | clippedSrcRect->fLeft -= clippedDstPoint->fX; |
| 875 | clippedDstPoint->fX = 0; |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 876 | } |
| 877 | |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 878 | // clip the top edge to src and dst bounds, adjusting dstPoint if necessary |
| 879 | if (clippedSrcRect->fTop < 0) { |
| 880 | clippedDstPoint->fY -= clippedSrcRect->fTop; |
| 881 | clippedSrcRect->fTop = 0; |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 882 | } |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 883 | if (clippedDstPoint->fY < 0) { |
| 884 | clippedSrcRect->fTop -= clippedDstPoint->fY; |
| 885 | clippedDstPoint->fY = 0; |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 886 | } |
skia.committer@gmail.com | a9493a3 | 2013-04-04 07:01:12 +0000 | [diff] [blame] | 887 | |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 888 | // clip the right edge to the src and dst bounds. |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 889 | if (clippedSrcRect->fRight > src->width()) { |
| 890 | clippedSrcRect->fRight = src->width(); |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 891 | } |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 892 | if (clippedDstPoint->fX + clippedSrcRect->width() > dst->width()) { |
| 893 | clippedSrcRect->fRight = clippedSrcRect->fLeft + dst->width() - clippedDstPoint->fX; |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | // clip the bottom edge to the src and dst bounds. |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 897 | if (clippedSrcRect->fBottom > src->height()) { |
| 898 | clippedSrcRect->fBottom = src->height(); |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 899 | } |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 900 | if (clippedDstPoint->fY + clippedSrcRect->height() > dst->height()) { |
| 901 | clippedSrcRect->fBottom = clippedSrcRect->fTop + dst->height() - clippedDstPoint->fY; |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 902 | } |
skia.committer@gmail.com | a9493a3 | 2013-04-04 07:01:12 +0000 | [diff] [blame] | 903 | |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 904 | // The above clipping steps may have inverted the rect if it didn't intersect either the src or |
| 905 | // dst bounds. |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 906 | return !clippedSrcRect->isEmpty(); |
| 907 | } |
| 908 | } |
| 909 | |
| 910 | bool GrDrawTarget::copySurface(GrSurface* dst, |
| 911 | GrSurface* src, |
| 912 | const SkIRect& srcRect, |
| 913 | const SkIPoint& dstPoint) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 914 | SkASSERT(dst); |
| 915 | SkASSERT(src); |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 916 | |
| 917 | SkIRect clippedSrcRect; |
| 918 | SkIPoint clippedDstPoint; |
| 919 | // If the rect is outside the src or dst then we've already succeeded. |
| 920 | if (!clip_srcrect_and_dstpoint(dst, |
| 921 | src, |
| 922 | srcRect, |
| 923 | dstPoint, |
| 924 | &clippedSrcRect, |
| 925 | &clippedDstPoint)) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 926 | SkASSERT(this->canCopySurface(dst, src, srcRect, dstPoint)); |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 927 | return true; |
| 928 | } |
| 929 | |
| 930 | bool result = this->onCopySurface(dst, src, clippedSrcRect, clippedDstPoint); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 931 | SkASSERT(result == this->canCopySurface(dst, src, clippedSrcRect, clippedDstPoint)); |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 932 | return result; |
| 933 | } |
| 934 | |
| 935 | bool GrDrawTarget::canCopySurface(GrSurface* dst, |
| 936 | GrSurface* src, |
| 937 | const SkIRect& srcRect, |
| 938 | const SkIPoint& dstPoint) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 939 | SkASSERT(dst); |
| 940 | SkASSERT(src); |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 941 | |
| 942 | SkIRect clippedSrcRect; |
| 943 | SkIPoint clippedDstPoint; |
| 944 | // If the rect is outside the src or dst then we're guaranteed success |
| 945 | if (!clip_srcrect_and_dstpoint(dst, |
| 946 | src, |
| 947 | srcRect, |
| 948 | dstPoint, |
| 949 | &clippedSrcRect, |
| 950 | &clippedDstPoint)) { |
| 951 | return true; |
| 952 | } |
| 953 | return this->onCanCopySurface(dst, src, clippedSrcRect, clippedDstPoint); |
| 954 | } |
| 955 | |
| 956 | bool GrDrawTarget::onCanCopySurface(GrSurface* dst, |
| 957 | GrSurface* src, |
| 958 | const SkIRect& srcRect, |
| 959 | const SkIPoint& dstPoint) { |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 960 | // Check that the read/write rects are contained within the src/dst bounds. |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 961 | SkASSERT(!srcRect.isEmpty()); |
| 962 | SkASSERT(SkIRect::MakeWH(src->width(), src->height()).contains(srcRect)); |
| 963 | SkASSERT(dstPoint.fX >= 0 && dstPoint.fY >= 0); |
| 964 | SkASSERT(dstPoint.fX + srcRect.width() <= dst->width() && |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 965 | dstPoint.fY + srcRect.height() <= dst->height()); |
| 966 | |
robertphillips | b06e5a2 | 2014-09-30 06:58:20 -0700 | [diff] [blame^] | 967 | return !dst->isSameAs(src) && dst->asRenderTarget() && src->asTexture(); |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | bool GrDrawTarget::onCopySurface(GrSurface* dst, |
| 971 | GrSurface* src, |
| 972 | const SkIRect& srcRect, |
| 973 | const SkIPoint& dstPoint) { |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 974 | if (!GrDrawTarget::onCanCopySurface(dst, src, srcRect, dstPoint)) { |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 975 | return false; |
| 976 | } |
| 977 | |
| 978 | GrRenderTarget* rt = dst->asRenderTarget(); |
| 979 | GrTexture* tex = src->asTexture(); |
| 980 | |
| 981 | GrDrawTarget::AutoStateRestore asr(this, kReset_ASRInit); |
| 982 | this->drawState()->setRenderTarget(rt); |
| 983 | SkMatrix matrix; |
| 984 | matrix.setTranslate(SkIntToScalar(srcRect.fLeft - dstPoint.fX), |
| 985 | SkIntToScalar(srcRect.fTop - dstPoint.fY)); |
| 986 | matrix.postIDiv(tex->width(), tex->height()); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 987 | this->drawState()->addColorTextureProcessor(tex, matrix); |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 988 | SkIRect dstRect = SkIRect::MakeXYWH(dstPoint.fX, |
| 989 | dstPoint.fY, |
| 990 | srcRect.width(), |
| 991 | srcRect.height()); |
| 992 | this->drawSimpleRect(dstRect); |
| 993 | return true; |
| 994 | } |
| 995 | |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 996 | void GrDrawTarget::initCopySurfaceDstDesc(const GrSurface* src, GrTextureDesc* desc) { |
| 997 | // Make the dst of the copy be a render target because the default copySurface draws to the dst. |
| 998 | desc->fOrigin = kDefault_GrSurfaceOrigin; |
| 999 | desc->fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; |
| 1000 | desc->fConfig = src->config(); |
| 1001 | } |
| 1002 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 1003 | /////////////////////////////////////////////////////////////////////////////// |
| 1004 | |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 1005 | void GrDrawTargetCaps::reset() { |
commit-bot@chromium.org | 4744231 | 2013-12-19 16:18:01 +0000 | [diff] [blame] | 1006 | fMipMapSupport = false; |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 1007 | fNPOTTextureTileSupport = false; |
| 1008 | fTwoSidedStencilSupport = false; |
| 1009 | fStencilWrapOpsSupport = false; |
| 1010 | fHWAALineSupport = false; |
| 1011 | fShaderDerivativeSupport = false; |
| 1012 | fGeometryShaderSupport = false; |
skia.committer@gmail.com | e60ed08 | 2013-03-26 07:01:04 +0000 | [diff] [blame] | 1013 | fDualSourceBlendingSupport = false; |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 1014 | fPathRenderingSupport = false; |
commit-bot@chromium.org | b835652 | 2013-07-18 22:26:39 +0000 | [diff] [blame] | 1015 | fDstReadInShaderSupport = false; |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 1016 | fDiscardRenderTargetSupport = false; |
commit-bot@chromium.org | b835652 | 2013-07-18 22:26:39 +0000 | [diff] [blame] | 1017 | fReuseScratchTextures = true; |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 1018 | fGpuTracingSupport = false; |
krajcevski | 78697816 | 2014-07-30 11:25:44 -0700 | [diff] [blame] | 1019 | fCompressedTexSubImageSupport = false; |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 1020 | |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 1021 | fMapBufferFlags = kNone_MapFlags; |
| 1022 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 1023 | fMaxRenderTargetSize = 0; |
| 1024 | fMaxTextureSize = 0; |
| 1025 | fMaxSampleCount = 0; |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 1026 | |
| 1027 | memset(fConfigRenderSupport, 0, sizeof(fConfigRenderSupport)); |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 1028 | memset(fConfigTextureSupport, 0, sizeof(fConfigTextureSupport)); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 1029 | } |
| 1030 | |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 1031 | GrDrawTargetCaps& GrDrawTargetCaps::operator=(const GrDrawTargetCaps& other) { |
commit-bot@chromium.org | 4744231 | 2013-12-19 16:18:01 +0000 | [diff] [blame] | 1032 | fMipMapSupport = other.fMipMapSupport; |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 1033 | fNPOTTextureTileSupport = other.fNPOTTextureTileSupport; |
| 1034 | fTwoSidedStencilSupport = other.fTwoSidedStencilSupport; |
| 1035 | fStencilWrapOpsSupport = other.fStencilWrapOpsSupport; |
| 1036 | fHWAALineSupport = other.fHWAALineSupport; |
| 1037 | fShaderDerivativeSupport = other.fShaderDerivativeSupport; |
| 1038 | fGeometryShaderSupport = other.fGeometryShaderSupport; |
| 1039 | fDualSourceBlendingSupport = other.fDualSourceBlendingSupport; |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 1040 | fPathRenderingSupport = other.fPathRenderingSupport; |
commit-bot@chromium.org | b835652 | 2013-07-18 22:26:39 +0000 | [diff] [blame] | 1041 | fDstReadInShaderSupport = other.fDstReadInShaderSupport; |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 1042 | fDiscardRenderTargetSupport = other.fDiscardRenderTargetSupport; |
commit-bot@chromium.org | b835652 | 2013-07-18 22:26:39 +0000 | [diff] [blame] | 1043 | fReuseScratchTextures = other.fReuseScratchTextures; |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 1044 | fGpuTracingSupport = other.fGpuTracingSupport; |
krajcevski | 78697816 | 2014-07-30 11:25:44 -0700 | [diff] [blame] | 1045 | fCompressedTexSubImageSupport = other.fCompressedTexSubImageSupport; |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 1046 | |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 1047 | fMapBufferFlags = other.fMapBufferFlags; |
| 1048 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 1049 | fMaxRenderTargetSize = other.fMaxRenderTargetSize; |
| 1050 | fMaxTextureSize = other.fMaxTextureSize; |
| 1051 | fMaxSampleCount = other.fMaxSampleCount; |
| 1052 | |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 1053 | memcpy(fConfigRenderSupport, other.fConfigRenderSupport, sizeof(fConfigRenderSupport)); |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 1054 | memcpy(fConfigTextureSupport, other.fConfigTextureSupport, sizeof(fConfigTextureSupport)); |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 1055 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 1056 | return *this; |
| 1057 | } |
| 1058 | |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 1059 | static SkString map_flags_to_string(uint32_t flags) { |
| 1060 | SkString str; |
| 1061 | if (GrDrawTargetCaps::kNone_MapFlags == flags) { |
| 1062 | str = "none"; |
| 1063 | } else { |
| 1064 | SkASSERT(GrDrawTargetCaps::kCanMap_MapFlag & flags); |
| 1065 | SkDEBUGCODE(flags &= ~GrDrawTargetCaps::kCanMap_MapFlag); |
| 1066 | str = "can_map"; |
| 1067 | |
| 1068 | if (GrDrawTargetCaps::kSubset_MapFlag & flags) { |
| 1069 | str.append(" partial"); |
| 1070 | } else { |
| 1071 | str.append(" full"); |
| 1072 | } |
| 1073 | SkDEBUGCODE(flags &= ~GrDrawTargetCaps::kSubset_MapFlag); |
| 1074 | } |
| 1075 | SkASSERT(0 == flags); // Make sure we handled all the flags. |
| 1076 | return str; |
| 1077 | } |
| 1078 | |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 1079 | SkString GrDrawTargetCaps::dump() const { |
| 1080 | SkString r; |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 1081 | static const char* gNY[] = {"NO", "YES"}; |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 1082 | r.appendf("MIP Map Support : %s\n", gNY[fMipMapSupport]); |
| 1083 | r.appendf("NPOT Texture Tile Support : %s\n", gNY[fNPOTTextureTileSupport]); |
| 1084 | r.appendf("Two Sided Stencil Support : %s\n", gNY[fTwoSidedStencilSupport]); |
| 1085 | r.appendf("Stencil Wrap Ops Support : %s\n", gNY[fStencilWrapOpsSupport]); |
| 1086 | r.appendf("HW AA Lines Support : %s\n", gNY[fHWAALineSupport]); |
| 1087 | r.appendf("Shader Derivative Support : %s\n", gNY[fShaderDerivativeSupport]); |
| 1088 | r.appendf("Geometry Shader Support : %s\n", gNY[fGeometryShaderSupport]); |
| 1089 | r.appendf("Dual Source Blending Support : %s\n", gNY[fDualSourceBlendingSupport]); |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 1090 | r.appendf("Path Rendering Support : %s\n", gNY[fPathRenderingSupport]); |
| 1091 | r.appendf("Dst Read In Shader Support : %s\n", gNY[fDstReadInShaderSupport]); |
| 1092 | r.appendf("Discard Render Target Support: %s\n", gNY[fDiscardRenderTargetSupport]); |
| 1093 | r.appendf("Reuse Scratch Textures : %s\n", gNY[fReuseScratchTextures]); |
| 1094 | r.appendf("Gpu Tracing Support : %s\n", gNY[fGpuTracingSupport]); |
krajcevski | 78697816 | 2014-07-30 11:25:44 -0700 | [diff] [blame] | 1095 | r.appendf("Compressed Update Support : %s\n", gNY[fCompressedTexSubImageSupport]); |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 1096 | r.appendf("Max Texture Size : %d\n", fMaxTextureSize); |
| 1097 | r.appendf("Max Render Target Size : %d\n", fMaxRenderTargetSize); |
| 1098 | r.appendf("Max Sample Count : %d\n", fMaxSampleCount); |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 1099 | |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 1100 | r.appendf("Map Buffer Support : %s\n", map_flags_to_string(fMapBufferFlags).c_str()); |
| 1101 | |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 1102 | static const char* kConfigNames[] = { |
| 1103 | "Unknown", // kUnknown_GrPixelConfig |
| 1104 | "Alpha8", // kAlpha_8_GrPixelConfig, |
| 1105 | "Index8", // kIndex_8_GrPixelConfig, |
| 1106 | "RGB565", // kRGB_565_GrPixelConfig, |
| 1107 | "RGBA444", // kRGBA_4444_GrPixelConfig, |
| 1108 | "RGBA8888", // kRGBA_8888_GrPixelConfig, |
| 1109 | "BGRA8888", // kBGRA_8888_GrPixelConfig, |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 1110 | "ETC1", // kETC1_GrPixelConfig, |
| 1111 | "LATC", // kLATC_GrPixelConfig, |
krajcevski | 238b456 | 2014-06-30 09:09:22 -0700 | [diff] [blame] | 1112 | "R11EAC", // kR11_EAC_GrPixelConfig, |
krajcevski | 7ef2162 | 2014-07-16 15:21:13 -0700 | [diff] [blame] | 1113 | "ASTC12x12",// kASTC_12x12_GrPixelConfig, |
joshualitt | ee5da55 | 2014-07-16 13:32:56 -0700 | [diff] [blame] | 1114 | "RGBAFloat", // kRGBA_float_GrPixelConfig |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 1115 | }; |
krajcevski | 7ef2162 | 2014-07-16 15:21:13 -0700 | [diff] [blame] | 1116 | GR_STATIC_ASSERT(0 == kUnknown_GrPixelConfig); |
| 1117 | GR_STATIC_ASSERT(1 == kAlpha_8_GrPixelConfig); |
| 1118 | GR_STATIC_ASSERT(2 == kIndex_8_GrPixelConfig); |
| 1119 | GR_STATIC_ASSERT(3 == kRGB_565_GrPixelConfig); |
| 1120 | GR_STATIC_ASSERT(4 == kRGBA_4444_GrPixelConfig); |
| 1121 | GR_STATIC_ASSERT(5 == kRGBA_8888_GrPixelConfig); |
| 1122 | GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig); |
| 1123 | GR_STATIC_ASSERT(7 == kETC1_GrPixelConfig); |
| 1124 | GR_STATIC_ASSERT(8 == kLATC_GrPixelConfig); |
| 1125 | GR_STATIC_ASSERT(9 == kR11_EAC_GrPixelConfig); |
| 1126 | GR_STATIC_ASSERT(10 == kASTC_12x12_GrPixelConfig); |
| 1127 | GR_STATIC_ASSERT(11 == kRGBA_float_GrPixelConfig); |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 1128 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kConfigNames) == kGrPixelConfigCnt); |
| 1129 | |
commit-bot@chromium.org | 9901727 | 2013-11-08 18:45:27 +0000 | [diff] [blame] | 1130 | SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][0]); |
| 1131 | SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][1]); |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 1132 | |
| 1133 | for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) { |
| 1134 | r.appendf("%s is renderable: %s, with MSAA: %s\n", |
| 1135 | kConfigNames[i], |
| 1136 | gNY[fConfigRenderSupport[i][0]], |
| 1137 | gNY[fConfigRenderSupport[i][1]]); |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 1138 | } |
commit-bot@chromium.org | 42dc813 | 2014-05-27 19:26:59 +0000 | [diff] [blame] | 1139 | |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 1140 | SkASSERT(!fConfigTextureSupport[kUnknown_GrPixelConfig]); |
commit-bot@chromium.org | 42dc813 | 2014-05-27 19:26:59 +0000 | [diff] [blame] | 1141 | |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 1142 | for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) { |
| 1143 | r.appendf("%s is uploadable to a texture: %s\n", |
| 1144 | kConfigNames[i], |
| 1145 | gNY[fConfigTextureSupport[i]]); |
commit-bot@chromium.org | 42dc813 | 2014-05-27 19:26:59 +0000 | [diff] [blame] | 1146 | } |
| 1147 | |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 1148 | return r; |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 1149 | } |
egdaniel | bc127a3 | 2014-09-19 12:07:43 -0700 | [diff] [blame] | 1150 | |
| 1151 | uint32_t GrDrawTargetCaps::CreateUniqueID() { |
| 1152 | static int32_t gUniqueID = SK_InvalidUniqueID; |
| 1153 | uint32_t id; |
| 1154 | do { |
| 1155 | id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); |
| 1156 | } while (id == SK_InvalidUniqueID); |
| 1157 | return id; |
| 1158 | } |
| 1159 | |