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