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