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