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 | |
joshualitt | c2893c5 | 2015-01-28 06:54:30 -0800 | [diff] [blame] | 9 | #include "GrDrawTarget.h" |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame^] | 10 | |
| 11 | #include "GrBatch.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 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 309 | bool GrDrawTarget::checkDraw(const GrPipelineBuilder& pipelineBuilder, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 310 | const GrGeometryProcessor* gp, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 311 | GrPrimitiveType type, |
| 312 | int startVertex, |
| 313 | int startIndex, |
| 314 | int vertexCount, |
bsalomon@google.com | e826262 | 2011-11-07 02:30:51 +0000 | [diff] [blame] | 315 | int indexCount) const { |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 316 | #ifdef SK_DEBUG |
bsalomon@google.com | e826262 | 2011-11-07 02:30:51 +0000 | [diff] [blame] | 317 | const GeometrySrcState& geoSrc = fGeoSrcStateStack.back(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 318 | int maxVertex = startVertex + vertexCount; |
| 319 | int maxValidVertex; |
| 320 | switch (geoSrc.fVertexSrc) { |
| 321 | case kNone_GeometrySrcType: |
commit-bot@chromium.org | 88cb22b | 2014-04-30 14:17:00 +0000 | [diff] [blame] | 322 | SkFAIL("Attempting to draw without vertex src."); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 323 | case kReserved_GeometrySrcType: // fallthrough |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 324 | maxValidVertex = geoSrc.fVertexCount; |
| 325 | break; |
| 326 | case kBuffer_GeometrySrcType: |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 327 | maxValidVertex = static_cast<int>(geoSrc.fVertexBuffer->gpuMemorySize() / |
| 328 | 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: |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 344 | maxValidIndex = static_cast<int>(geoSrc.fIndexBuffer->gpuMemorySize() / |
| 345 | sizeof(uint16_t)); |
bsalomon@google.com | e826262 | 2011-11-07 02:30:51 +0000 | [diff] [blame] | 346 | break; |
| 347 | } |
| 348 | if (maxIndex > maxValidIndex) { |
commit-bot@chromium.org | 88cb22b | 2014-04-30 14:17:00 +0000 | [diff] [blame] | 349 | SkFAIL("Index reads outside valid index range."); |
bsalomon@google.com | e826262 | 2011-11-07 02:30:51 +0000 | [diff] [blame] | 350 | } |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 351 | } |
bsalomon@google.com | b4725b4 | 2012-03-30 17:24:17 +0000 | [diff] [blame] | 352 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 353 | SkASSERT(pipelineBuilder.getRenderTarget()); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 354 | |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 355 | if (gp) { |
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); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 359 | SkASSERT(texture->asRenderTarget() != pipelineBuilder.getRenderTarget()); |
joshualitt | bd769d0 | 2014-09-04 08:56:46 -0700 | [diff] [blame] | 360 | } |
| 361 | } |
| 362 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 363 | for (int s = 0; s < pipelineBuilder.numColorStages(); ++s) { |
| 364 | const GrProcessor* effect = pipelineBuilder.getColorStage(s).processor(); |
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); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 368 | SkASSERT(texture->asRenderTarget() != pipelineBuilder.getRenderTarget()); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 369 | } |
| 370 | } |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 371 | for (int s = 0; s < pipelineBuilder.numCoverageStages(); ++s) { |
| 372 | const GrProcessor* effect = pipelineBuilder.getCoverageStage(s).processor(); |
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); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 376 | SkASSERT(texture->asRenderTarget() != pipelineBuilder.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 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 380 | #endif |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 381 | if (NULL == pipelineBuilder.getRenderTarget()) { |
bsalomon@google.com | 0ba52fc | 2011-11-10 22:16:06 +0000 | [diff] [blame] | 382 | return false; |
| 383 | } |
bsalomon@google.com | e826262 | 2011-11-07 02:30:51 +0000 | [diff] [blame] | 384 | return true; |
| 385 | } |
| 386 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 387 | bool GrDrawTarget::setupDstReadIfNecessary(GrPipelineBuilder* pipelineBuilder, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 388 | GrDeviceCoordTexture* dstCopy, |
| 389 | const SkRect* drawBounds) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 390 | if (this->caps()->dstReadInShaderSupport() || !pipelineBuilder->willEffectReadDstColor()) { |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 391 | return true; |
| 392 | } |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 393 | SkIRect copyRect; |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 394 | const GrClipData* clip = this->getClip(); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 395 | GrRenderTarget* rt = pipelineBuilder->getRenderTarget(); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 396 | clip->getConservativeBounds(rt, ©Rect); |
| 397 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 398 | if (drawBounds) { |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 399 | SkIRect drawIBounds; |
| 400 | drawBounds->roundOut(&drawIBounds); |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 401 | if (!copyRect.intersect(drawIBounds)) { |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 402 | #ifdef SK_DEBUG |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 403 | 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] | 404 | #endif |
| 405 | return false; |
| 406 | } |
| 407 | } else { |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 408 | #ifdef SK_DEBUG |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 409 | //SkDebugf("No dev bounds when dst copy is made.\n"); |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 410 | #endif |
| 411 | } |
skia.committer@gmail.com | 05a2ee0 | 2013-04-02 07:01:34 +0000 | [diff] [blame] | 412 | |
commit-bot@chromium.org | 63150af | 2013-04-11 22:00:22 +0000 | [diff] [blame] | 413 | // MSAA consideration: When there is support for reading MSAA samples in the shader we could |
| 414 | // have per-sample dst values by making the copy multisampled. |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 415 | GrSurfaceDesc desc; |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 416 | this->initCopySurfaceDstDesc(rt, &desc); |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 417 | desc.fWidth = copyRect.width(); |
| 418 | desc.fHeight = copyRect.height(); |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 419 | |
bsalomon | e305973 | 2014-10-14 11:47:22 -0700 | [diff] [blame] | 420 | SkAutoTUnref<GrTexture> copy( |
| 421 | fContext->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch)); |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 422 | |
bsalomon | e305973 | 2014-10-14 11:47:22 -0700 | [diff] [blame] | 423 | if (!copy) { |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 424 | SkDebugf("Failed to create temporary copy of destination texture.\n"); |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 425 | return false; |
| 426 | } |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 427 | SkIPoint dstPoint = {0, 0}; |
bsalomon | e305973 | 2014-10-14 11:47:22 -0700 | [diff] [blame] | 428 | if (this->copySurface(copy, rt, copyRect, dstPoint)) { |
| 429 | dstCopy->setTexture(copy); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 430 | dstCopy->setOffset(copyRect.fLeft, copyRect.fTop); |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 431 | return true; |
| 432 | } else { |
| 433 | return false; |
| 434 | } |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 435 | } |
| 436 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 437 | void GrDrawTarget::drawIndexed(GrPipelineBuilder* pipelineBuilder, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 438 | const GrGeometryProcessor* gp, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 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) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 445 | SkASSERT(pipelineBuilder); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 446 | if (indexCount > 0 && |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 447 | this->checkDraw(*pipelineBuilder, gp, type, startVertex, startIndex, vertexCount, |
| 448 | indexCount)) { |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 449 | |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 450 | // Setup clip |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 451 | GrScissorState scissorState; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 452 | GrPipelineBuilder::AutoRestoreEffects are; |
| 453 | GrPipelineBuilder::AutoRestoreStencil ars; |
| 454 | if (!this->setupClip(pipelineBuilder, &are, &ars, &scissorState, devBounds)) { |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 455 | return; |
| 456 | } |
| 457 | |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 458 | DrawInfo info; |
| 459 | info.fPrimitiveType = type; |
| 460 | info.fStartVertex = startVertex; |
| 461 | info.fStartIndex = startIndex; |
| 462 | info.fVertexCount = vertexCount; |
| 463 | info.fIndexCount = indexCount; |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 464 | |
| 465 | info.fInstanceCount = 0; |
| 466 | info.fVerticesPerInstance = 0; |
| 467 | info.fIndicesPerInstance = 0; |
| 468 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 469 | if (devBounds) { |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 470 | info.setDevBounds(*devBounds); |
| 471 | } |
joshualitt | 9176e2c | 2014-11-20 07:28:52 -0800 | [diff] [blame] | 472 | |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 473 | // TODO: We should continue with incorrect blending. |
joshualitt | 9176e2c | 2014-11-20 07:28:52 -0800 | [diff] [blame] | 474 | GrDeviceCoordTexture dstCopy; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 475 | if (!this->setupDstReadIfNecessary(pipelineBuilder, &dstCopy, devBounds)) { |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 476 | return; |
| 477 | } |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 478 | this->setDrawBuffers(&info, gp->getVertexStride()); |
joshualitt | 7eb8c7b | 2014-11-18 14:24:27 -0800 | [diff] [blame] | 479 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 480 | this->onDraw(*pipelineBuilder, gp, info, scissorState, dstCopy.texture() ? &dstCopy : NULL); |
bsalomon@google.com | 8214587 | 2011-08-23 14:32:40 +0000 | [diff] [blame] | 481 | } |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 482 | } |
| 483 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 484 | void GrDrawTarget::drawNonIndexed(GrPipelineBuilder* pipelineBuilder, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 485 | const GrGeometryProcessor* gp, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 486 | GrPrimitiveType type, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 487 | int startVertex, |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 488 | int vertexCount, |
| 489 | const SkRect* devBounds) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 490 | SkASSERT(pipelineBuilder); |
| 491 | if (vertexCount > 0 && this->checkDraw(*pipelineBuilder, gp, type, startVertex, -1, vertexCount, |
| 492 | -1)) { |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 493 | |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 494 | // Setup clip |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 495 | GrScissorState scissorState; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 496 | GrPipelineBuilder::AutoRestoreEffects are; |
| 497 | GrPipelineBuilder::AutoRestoreStencil ars; |
| 498 | if (!this->setupClip(pipelineBuilder, &are, &ars, &scissorState, devBounds)) { |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 499 | return; |
| 500 | } |
| 501 | |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 502 | DrawInfo info; |
| 503 | info.fPrimitiveType = type; |
| 504 | info.fStartVertex = startVertex; |
| 505 | info.fStartIndex = 0; |
| 506 | info.fVertexCount = vertexCount; |
| 507 | info.fIndexCount = 0; |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 508 | |
| 509 | info.fInstanceCount = 0; |
| 510 | info.fVerticesPerInstance = 0; |
| 511 | info.fIndicesPerInstance = 0; |
| 512 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 513 | if (devBounds) { |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 514 | info.setDevBounds(*devBounds); |
| 515 | } |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 516 | |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 517 | // TODO: We should continue with incorrect blending. |
joshualitt | 9176e2c | 2014-11-20 07:28:52 -0800 | [diff] [blame] | 518 | GrDeviceCoordTexture dstCopy; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 519 | if (!this->setupDstReadIfNecessary(pipelineBuilder, &dstCopy, devBounds)) { |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 520 | return; |
| 521 | } |
joshualitt | 7eb8c7b | 2014-11-18 14:24:27 -0800 | [diff] [blame] | 522 | |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 523 | this->setDrawBuffers(&info, gp->getVertexStride()); |
joshualitt | 7eb8c7b | 2014-11-18 14:24:27 -0800 | [diff] [blame] | 524 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 525 | this->onDraw(*pipelineBuilder, gp, info, scissorState, dstCopy.texture() ? &dstCopy : NULL); |
bsalomon@google.com | 8214587 | 2011-08-23 14:32:40 +0000 | [diff] [blame] | 526 | } |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 527 | } |
| 528 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame^] | 529 | |
| 530 | void GrDrawTarget::drawBatch(GrPipelineBuilder* pipelineBuilder, |
| 531 | GrBatch* batch, |
| 532 | const SkRect* devBounds) { |
| 533 | SkASSERT(pipelineBuilder); |
| 534 | // TODO some kind of checkdraw, but not at this level |
| 535 | |
| 536 | // Setup clip |
| 537 | GrScissorState scissorState; |
| 538 | GrPipelineBuilder::AutoRestoreEffects are; |
| 539 | GrPipelineBuilder::AutoRestoreStencil ars; |
| 540 | if (!this->setupClip(pipelineBuilder, &are, &ars, &scissorState, devBounds)) { |
| 541 | return; |
| 542 | } |
| 543 | |
| 544 | GrDeviceCoordTexture dstCopy; |
| 545 | if (!this->setupDstReadIfNecessary(pipelineBuilder, &dstCopy, devBounds)) { |
| 546 | return; |
| 547 | } |
| 548 | |
| 549 | this->onDrawBatch(batch, *pipelineBuilder, scissorState, dstCopy.texture() ? &dstCopy : NULL); |
| 550 | } |
| 551 | |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 552 | static const GrStencilSettings& winding_path_stencil_settings() { |
| 553 | GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, |
| 554 | kIncClamp_StencilOp, |
| 555 | kIncClamp_StencilOp, |
| 556 | kAlwaysIfInClip_StencilFunc, |
| 557 | 0xFFFF, 0xFFFF, 0xFFFF); |
| 558 | return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); |
| 559 | } |
| 560 | |
| 561 | static const GrStencilSettings& even_odd_path_stencil_settings() { |
| 562 | GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, |
| 563 | kInvert_StencilOp, |
| 564 | kInvert_StencilOp, |
| 565 | kAlwaysIfInClip_StencilFunc, |
| 566 | 0xFFFF, 0xFFFF, 0xFFFF); |
| 567 | return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); |
| 568 | } |
| 569 | |
| 570 | void GrDrawTarget::getPathStencilSettingsForFilltype(GrPathRendering::FillType fill, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 571 | const GrStencilBuffer* sb, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 572 | GrStencilSettings* outStencilSettings) { |
| 573 | |
| 574 | switch (fill) { |
| 575 | default: |
| 576 | SkFAIL("Unexpected path fill."); |
| 577 | case GrPathRendering::kWinding_FillType: |
| 578 | *outStencilSettings = winding_path_stencil_settings(); |
| 579 | break; |
| 580 | case GrPathRendering::kEvenOdd_FillType: |
| 581 | *outStencilSettings = even_odd_path_stencil_settings(); |
| 582 | break; |
| 583 | } |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 584 | this->clipMaskManager()->adjustPathStencilParams(sb, outStencilSettings); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 585 | } |
| 586 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 587 | void GrDrawTarget::stencilPath(GrPipelineBuilder* pipelineBuilder, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 588 | const GrPathProcessor* pathProc, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 589 | const GrPath* path, |
| 590 | GrPathRendering::FillType fill) { |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 591 | // TODO: extract portions of checkDraw that are relevant to path stenciling. |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 592 | SkASSERT(path); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 593 | SkASSERT(this->caps()->pathRenderingSupport()); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 594 | SkASSERT(pipelineBuilder); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 595 | |
| 596 | // Setup clip |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 597 | GrScissorState scissorState; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 598 | GrPipelineBuilder::AutoRestoreEffects are; |
| 599 | GrPipelineBuilder::AutoRestoreStencil ars; |
| 600 | if (!this->setupClip(pipelineBuilder, &are, &ars, &scissorState, NULL)) { |
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, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 607 | pipelineBuilder->getRenderTarget()->getStencilBuffer(), |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 608 | &stencilSettings); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 609 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 610 | this->onStencilPath(*pipelineBuilder, pathProc, path, scissorState, stencilSettings); |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 611 | } |
| 612 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 613 | void GrDrawTarget::drawPath(GrPipelineBuilder* pipelineBuilder, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 614 | const GrPathProcessor* pathProc, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 615 | const GrPath* path, |
| 616 | GrPathRendering::FillType fill) { |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 617 | // TODO: extract portions of checkDraw that are relevant to path rendering. |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 618 | SkASSERT(path); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 619 | SkASSERT(this->caps()->pathRenderingSupport()); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 620 | SkASSERT(pipelineBuilder); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 621 | |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 622 | SkRect devBounds = path->getBounds(); |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 623 | pathProc->viewMatrix().mapRect(&devBounds); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 624 | |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 625 | // Setup clip |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 626 | GrScissorState scissorState; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 627 | GrPipelineBuilder::AutoRestoreEffects are; |
| 628 | GrPipelineBuilder::AutoRestoreStencil ars; |
| 629 | if (!this->setupClip(pipelineBuilder, &are, &ars, &scissorState, &devBounds)) { |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 630 | return; |
| 631 | } |
| 632 | |
| 633 | // set stencil settings for path |
| 634 | GrStencilSettings stencilSettings; |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 635 | this->getPathStencilSettingsForFilltype(fill, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 636 | pipelineBuilder->getRenderTarget()->getStencilBuffer(), |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 637 | &stencilSettings); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 638 | |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 639 | GrDeviceCoordTexture dstCopy; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 640 | if (!this->setupDstReadIfNecessary(pipelineBuilder, &dstCopy, &devBounds)) { |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 641 | return; |
| 642 | } |
| 643 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 644 | this->onDrawPath(*pipelineBuilder, pathProc, path, scissorState, stencilSettings, |
| 645 | dstCopy.texture() ? &dstCopy : NULL); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 646 | } |
| 647 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 648 | void GrDrawTarget::drawPaths(GrPipelineBuilder* pipelineBuilder, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 649 | const GrPathProcessor* pathProc, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 650 | const GrPathRange* pathRange, |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 651 | const void* indices, |
| 652 | PathIndexType indexType, |
| 653 | const float transformValues[], |
| 654 | PathTransformType transformType, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 655 | int count, |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 656 | GrPathRendering::FillType fill) { |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 657 | SkASSERT(this->caps()->pathRenderingSupport()); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 658 | SkASSERT(pathRange); |
| 659 | SkASSERT(indices); |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 660 | SkASSERT(0 == reinterpret_cast<long>(indices) % GrPathRange::PathIndexSizeInBytes(indexType)); |
| 661 | SkASSERT(transformValues); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 662 | SkASSERT(pipelineBuilder); |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 663 | |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 664 | // Setup clip |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 665 | GrScissorState scissorState; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 666 | GrPipelineBuilder::AutoRestoreEffects are; |
| 667 | GrPipelineBuilder::AutoRestoreStencil ars; |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 668 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 669 | if (!this->setupClip(pipelineBuilder, &are, &ars, &scissorState, NULL)) { |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 670 | return; |
| 671 | } |
| 672 | |
| 673 | // set stencil settings for path |
| 674 | GrStencilSettings stencilSettings; |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 675 | this->getPathStencilSettingsForFilltype(fill, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 676 | pipelineBuilder->getRenderTarget()->getStencilBuffer(), |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 677 | &stencilSettings); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 678 | |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 679 | // Don't compute a bounding box for setupDstReadIfNecessary(), we'll opt |
| 680 | // instead for it to just copy the entire dst. Realistically this is a moot |
| 681 | // point, because any context that supports NV_path_rendering will also |
| 682 | // support NV_blend_equation_advanced. |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 683 | GrDeviceCoordTexture dstCopy; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 684 | if (!this->setupDstReadIfNecessary(pipelineBuilder, &dstCopy, NULL)) { |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 685 | return; |
| 686 | } |
| 687 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 688 | this->onDrawPaths(*pipelineBuilder, pathProc, pathRange, indices, indexType, transformValues, |
| 689 | transformType, count, scissorState, stencilSettings, |
| 690 | dstCopy.texture() ? &dstCopy : NULL); |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 691 | } |
| 692 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 693 | void GrDrawTarget::clear(const SkIRect* rect, |
| 694 | GrColor color, |
| 695 | bool canIgnoreRect, |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 696 | GrRenderTarget* renderTarget) { |
| 697 | if (fCaps->useDrawInsteadOfClear()) { |
| 698 | // This works around a driver bug with clear by drawing a rect instead. |
| 699 | // The driver will ignore a clear if it is the only thing rendered to a |
| 700 | // target before the target is read. |
| 701 | SkIRect rtRect = SkIRect::MakeWH(renderTarget->width(), renderTarget->height()); |
| 702 | if (NULL == rect || canIgnoreRect || rect->contains(rtRect)) { |
| 703 | rect = &rtRect; |
| 704 | // We first issue a discard() since that may help tilers. |
| 705 | this->discard(renderTarget); |
| 706 | } |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 707 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 708 | GrPipelineBuilder pipelineBuilder; |
| 709 | pipelineBuilder.setRenderTarget(renderTarget); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 710 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 711 | this->drawSimpleRect(&pipelineBuilder, color, SkMatrix::I(), *rect); |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 712 | } else { |
| 713 | this->onClear(rect, color, canIgnoreRect, renderTarget); |
| 714 | } |
| 715 | } |
| 716 | |
egdaniel | 3eee383 | 2014-06-18 13:09:11 -0700 | [diff] [blame] | 717 | typedef GrTraceMarkerSet::Iter TMIter; |
| 718 | void GrDrawTarget::saveActiveTraceMarkers() { |
| 719 | if (this->caps()->gpuTracingSupport()) { |
| 720 | SkASSERT(0 == fStoredTraceMarkers.count()); |
| 721 | fStoredTraceMarkers.addSet(fActiveTraceMarkers); |
| 722 | for (TMIter iter = fStoredTraceMarkers.begin(); iter != fStoredTraceMarkers.end(); ++iter) { |
| 723 | this->removeGpuTraceMarker(&(*iter)); |
| 724 | } |
| 725 | } |
| 726 | } |
| 727 | |
| 728 | void GrDrawTarget::restoreActiveTraceMarkers() { |
| 729 | if (this->caps()->gpuTracingSupport()) { |
| 730 | SkASSERT(0 == fActiveTraceMarkers.count()); |
| 731 | for (TMIter iter = fStoredTraceMarkers.begin(); iter != fStoredTraceMarkers.end(); ++iter) { |
| 732 | this->addGpuTraceMarker(&(*iter)); |
| 733 | } |
| 734 | for (TMIter iter = fActiveTraceMarkers.begin(); iter != fActiveTraceMarkers.end(); ++iter) { |
| 735 | this->fStoredTraceMarkers.remove(*iter); |
| 736 | } |
| 737 | } |
| 738 | } |
| 739 | |
| 740 | void GrDrawTarget::addGpuTraceMarker(const GrGpuTraceMarker* marker) { |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 741 | if (this->caps()->gpuTracingSupport()) { |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 742 | SkASSERT(fGpuTraceMarkerCount >= 0); |
| 743 | this->fActiveTraceMarkers.add(*marker); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 744 | ++fGpuTraceMarkerCount; |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 745 | } |
| 746 | } |
| 747 | |
egdaniel | 3eee383 | 2014-06-18 13:09:11 -0700 | [diff] [blame] | 748 | void GrDrawTarget::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 749 | if (this->caps()->gpuTracingSupport()) { |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 750 | SkASSERT(fGpuTraceMarkerCount >= 1); |
| 751 | this->fActiveTraceMarkers.remove(*marker); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 752 | --fGpuTraceMarkerCount; |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 753 | } |
| 754 | } |
| 755 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 756 | //////////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 757 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 758 | void GrDrawTarget::drawIndexedInstances(GrPipelineBuilder* pipelineBuilder, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 759 | const GrGeometryProcessor* gp, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 760 | GrPrimitiveType type, |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 761 | int instanceCount, |
| 762 | int verticesPerInstance, |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 763 | int indicesPerInstance, |
| 764 | const SkRect* devBounds) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 765 | SkASSERT(pipelineBuilder); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 766 | |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 767 | if (!verticesPerInstance || !indicesPerInstance) { |
| 768 | return; |
| 769 | } |
| 770 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 771 | int maxInstancesPerDraw = this->indexCountInCurrentSource() / indicesPerInstance; |
| 772 | if (!maxInstancesPerDraw) { |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 773 | return; |
| 774 | } |
| 775 | |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 776 | // Setup clip |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 777 | GrScissorState scissorState; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 778 | GrPipelineBuilder::AutoRestoreEffects are; |
| 779 | GrPipelineBuilder::AutoRestoreStencil ars; |
| 780 | if (!this->setupClip(pipelineBuilder, &are, &ars, &scissorState, devBounds)) { |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 781 | return; |
| 782 | } |
| 783 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 784 | DrawInfo info; |
| 785 | info.fPrimitiveType = type; |
| 786 | info.fStartIndex = 0; |
| 787 | info.fStartVertex = 0; |
| 788 | info.fIndicesPerInstance = indicesPerInstance; |
| 789 | info.fVerticesPerInstance = verticesPerInstance; |
| 790 | |
| 791 | // Set the same bounds for all the draws. |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 792 | if (devBounds) { |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 793 | info.setDevBounds(*devBounds); |
| 794 | } |
joshualitt | 9176e2c | 2014-11-20 07:28:52 -0800 | [diff] [blame] | 795 | |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 796 | // TODO: We should continue with incorrect blending. |
joshualitt | 9176e2c | 2014-11-20 07:28:52 -0800 | [diff] [blame] | 797 | GrDeviceCoordTexture dstCopy; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 798 | if (!this->setupDstReadIfNecessary(pipelineBuilder, &dstCopy, devBounds)) { |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 799 | return; |
| 800 | } |
joshualitt | 7eb8c7b | 2014-11-18 14:24:27 -0800 | [diff] [blame] | 801 | |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 802 | while (instanceCount) { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 803 | info.fInstanceCount = SkTMin(instanceCount, maxInstancesPerDraw); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 804 | info.fVertexCount = info.fInstanceCount * verticesPerInstance; |
| 805 | info.fIndexCount = info.fInstanceCount * indicesPerInstance; |
| 806 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 807 | if (this->checkDraw(*pipelineBuilder, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 808 | gp, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 809 | type, |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 810 | info.fStartVertex, |
| 811 | info.fStartIndex, |
| 812 | info.fVertexCount, |
| 813 | info.fIndexCount)) { |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 814 | this->setDrawBuffers(&info, gp->getVertexStride()); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 815 | this->onDraw(*pipelineBuilder, gp, info, scissorState, |
| 816 | dstCopy.texture() ? &dstCopy : NULL); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 817 | } |
| 818 | info.fStartVertex += info.fVertexCount; |
| 819 | instanceCount -= info.fInstanceCount; |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 820 | } |
| 821 | } |
bsalomon@google.com | 3d0835b | 2011-12-08 16:12:03 +0000 | [diff] [blame] | 822 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 823 | //////////////////////////////////////////////////////////////////////////////// |
| 824 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 825 | GrDrawTarget::AutoReleaseGeometry::AutoReleaseGeometry( |
| 826 | GrDrawTarget* target, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 827 | int vertexCount, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 828 | size_t vertexStride, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 829 | int indexCount) { |
| 830 | fTarget = NULL; |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 831 | this->set(target, vertexCount, vertexStride, indexCount); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 832 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 833 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 834 | GrDrawTarget::AutoReleaseGeometry::AutoReleaseGeometry() { |
| 835 | fTarget = NULL; |
| 836 | } |
| 837 | |
| 838 | GrDrawTarget::AutoReleaseGeometry::~AutoReleaseGeometry() { |
| 839 | this->reset(); |
| 840 | } |
| 841 | |
| 842 | bool GrDrawTarget::AutoReleaseGeometry::set(GrDrawTarget* target, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 843 | int vertexCount, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 844 | size_t vertexStride, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 845 | int indexCount) { |
| 846 | this->reset(); |
| 847 | fTarget = target; |
| 848 | bool success = true; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 849 | if (fTarget) { |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 850 | success = target->reserveVertexAndIndexSpace(vertexCount, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 851 | vertexStride, |
bsalomon@google.com | e3d7095 | 2012-03-13 12:40:53 +0000 | [diff] [blame] | 852 | indexCount, |
| 853 | &fVertices, |
| 854 | &fIndices); |
| 855 | if (!success) { |
| 856 | fTarget = NULL; |
| 857 | this->reset(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 858 | } |
| 859 | } |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 860 | SkASSERT(success == SkToBool(fTarget)); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 861 | return success; |
| 862 | } |
| 863 | |
| 864 | void GrDrawTarget::AutoReleaseGeometry::reset() { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 865 | if (fTarget) { |
| 866 | if (fVertices) { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 867 | fTarget->resetVertexSource(); |
| 868 | } |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 869 | if (fIndices) { |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 870 | fTarget->resetIndexSource(); |
| 871 | } |
| 872 | fTarget = NULL; |
| 873 | } |
bsalomon@google.com | cb0c5ab | 2011-06-29 17:48:17 +0000 | [diff] [blame] | 874 | fVertices = NULL; |
| 875 | fIndices = NULL; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 876 | } |
| 877 | |
bsalomon@google.com | 8d67c07 | 2012-12-13 20:38:14 +0000 | [diff] [blame] | 878 | GrDrawTarget::AutoClipRestore::AutoClipRestore(GrDrawTarget* target, const SkIRect& newClip) { |
| 879 | fTarget = target; |
| 880 | fClip = fTarget->getClip(); |
| 881 | fStack.init(); |
| 882 | fStack.get()->clipDevRect(newClip, SkRegion::kReplace_Op); |
| 883 | fReplacementClip.fClipStack = fStack.get(); |
| 884 | target->setClip(&fReplacementClip); |
| 885 | } |
| 886 | |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 887 | namespace { |
| 888 | // returns true if the read/written rect intersects the src/dst and false if not. |
| 889 | bool clip_srcrect_and_dstpoint(const GrSurface* dst, |
| 890 | const GrSurface* src, |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 891 | const SkIRect& srcRect, |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 892 | const SkIPoint& dstPoint, |
| 893 | SkIRect* clippedSrcRect, |
| 894 | SkIPoint* clippedDstPoint) { |
| 895 | *clippedSrcRect = srcRect; |
| 896 | *clippedDstPoint = dstPoint; |
skia.committer@gmail.com | a9493a3 | 2013-04-04 07:01:12 +0000 | [diff] [blame] | 897 | |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 898 | // clip the left edge to src and dst bounds, adjusting dstPoint if necessary |
| 899 | if (clippedSrcRect->fLeft < 0) { |
| 900 | clippedDstPoint->fX -= clippedSrcRect->fLeft; |
| 901 | clippedSrcRect->fLeft = 0; |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 902 | } |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 903 | if (clippedDstPoint->fX < 0) { |
| 904 | clippedSrcRect->fLeft -= clippedDstPoint->fX; |
| 905 | clippedDstPoint->fX = 0; |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 906 | } |
| 907 | |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 908 | // clip the top edge to src and dst bounds, adjusting dstPoint if necessary |
| 909 | if (clippedSrcRect->fTop < 0) { |
| 910 | clippedDstPoint->fY -= clippedSrcRect->fTop; |
| 911 | clippedSrcRect->fTop = 0; |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 912 | } |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 913 | if (clippedDstPoint->fY < 0) { |
| 914 | clippedSrcRect->fTop -= clippedDstPoint->fY; |
| 915 | clippedDstPoint->fY = 0; |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 916 | } |
skia.committer@gmail.com | a9493a3 | 2013-04-04 07:01:12 +0000 | [diff] [blame] | 917 | |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 918 | // clip the right edge to the src and dst bounds. |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 919 | if (clippedSrcRect->fRight > src->width()) { |
| 920 | clippedSrcRect->fRight = src->width(); |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 921 | } |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 922 | if (clippedDstPoint->fX + clippedSrcRect->width() > dst->width()) { |
| 923 | clippedSrcRect->fRight = clippedSrcRect->fLeft + dst->width() - clippedDstPoint->fX; |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | // clip the bottom edge to the src and dst bounds. |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 927 | if (clippedSrcRect->fBottom > src->height()) { |
| 928 | clippedSrcRect->fBottom = src->height(); |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 929 | } |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 930 | if (clippedDstPoint->fY + clippedSrcRect->height() > dst->height()) { |
| 931 | clippedSrcRect->fBottom = clippedSrcRect->fTop + dst->height() - clippedDstPoint->fY; |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 932 | } |
skia.committer@gmail.com | a9493a3 | 2013-04-04 07:01:12 +0000 | [diff] [blame] | 933 | |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 934 | // The above clipping steps may have inverted the rect if it didn't intersect either the src or |
| 935 | // dst bounds. |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 936 | return !clippedSrcRect->isEmpty(); |
| 937 | } |
| 938 | } |
| 939 | |
| 940 | bool GrDrawTarget::copySurface(GrSurface* dst, |
| 941 | GrSurface* src, |
| 942 | const SkIRect& srcRect, |
| 943 | const SkIPoint& dstPoint) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 944 | SkASSERT(dst); |
| 945 | SkASSERT(src); |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 946 | |
| 947 | SkIRect clippedSrcRect; |
| 948 | SkIPoint clippedDstPoint; |
| 949 | // If the rect is outside the src or dst then we've already succeeded. |
| 950 | if (!clip_srcrect_and_dstpoint(dst, |
| 951 | src, |
| 952 | srcRect, |
| 953 | dstPoint, |
| 954 | &clippedSrcRect, |
| 955 | &clippedDstPoint)) { |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 956 | return true; |
| 957 | } |
| 958 | |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 959 | if (this->onCopySurface(dst, src, clippedSrcRect, clippedDstPoint)) { |
| 960 | return true; |
joshualitt | a702415 | 2014-11-03 14:16:35 -0800 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | GrRenderTarget* rt = dst->asRenderTarget(); |
| 964 | GrTexture* tex = src->asTexture(); |
| 965 | |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 966 | if ((dst == src) || !rt || !tex) { |
| 967 | return false; |
| 968 | } |
| 969 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 970 | GrPipelineBuilder pipelineBuilder; |
| 971 | pipelineBuilder.setRenderTarget(rt); |
joshualitt | a702415 | 2014-11-03 14:16:35 -0800 | [diff] [blame] | 972 | SkMatrix matrix; |
| 973 | matrix.setTranslate(SkIntToScalar(clippedSrcRect.fLeft - clippedDstPoint.fX), |
| 974 | SkIntToScalar(clippedSrcRect.fTop - clippedDstPoint.fY)); |
| 975 | matrix.postIDiv(tex->width(), tex->height()); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 976 | pipelineBuilder.addColorTextureProcessor(tex, matrix); |
joshualitt | a702415 | 2014-11-03 14:16:35 -0800 | [diff] [blame] | 977 | SkIRect dstRect = SkIRect::MakeXYWH(clippedDstPoint.fX, |
| 978 | clippedDstPoint.fY, |
| 979 | clippedSrcRect.width(), |
| 980 | clippedSrcRect.height()); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 981 | this->drawSimpleRect(&pipelineBuilder, GrColor_WHITE, SkMatrix::I(), dstRect); |
joshualitt | a702415 | 2014-11-03 14:16:35 -0800 | [diff] [blame] | 982 | return true; |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 983 | } |
| 984 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 985 | bool GrDrawTarget::canCopySurface(const GrSurface* dst, |
| 986 | const GrSurface* src, |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 987 | const SkIRect& srcRect, |
| 988 | const SkIPoint& dstPoint) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 989 | SkASSERT(dst); |
| 990 | SkASSERT(src); |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 991 | |
| 992 | SkIRect clippedSrcRect; |
| 993 | SkIPoint clippedDstPoint; |
| 994 | // If the rect is outside the src or dst then we're guaranteed success |
| 995 | if (!clip_srcrect_and_dstpoint(dst, |
| 996 | src, |
| 997 | srcRect, |
| 998 | dstPoint, |
| 999 | &clippedSrcRect, |
| 1000 | &clippedDstPoint)) { |
| 1001 | return true; |
| 1002 | } |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 1003 | return this->internalCanCopySurface(dst, src, clippedSrcRect, clippedDstPoint); |
| 1004 | } |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 1005 | |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 1006 | bool GrDrawTarget::internalCanCopySurface(const GrSurface* dst, |
| 1007 | const GrSurface* src, |
| 1008 | const SkIRect& clippedSrcRect, |
| 1009 | const SkIPoint& clippedDstPoint) { |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 1010 | // Check that the read/write rects are contained within the src/dst bounds. |
joshualitt | a702415 | 2014-11-03 14:16:35 -0800 | [diff] [blame] | 1011 | SkASSERT(!clippedSrcRect.isEmpty()); |
| 1012 | SkASSERT(SkIRect::MakeWH(src->width(), src->height()).contains(clippedSrcRect)); |
| 1013 | SkASSERT(clippedDstPoint.fX >= 0 && clippedDstPoint.fY >= 0); |
| 1014 | SkASSERT(clippedDstPoint.fX + clippedSrcRect.width() <= dst->width() && |
| 1015 | clippedDstPoint.fY + clippedSrcRect.height() <= dst->height()); |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 1016 | |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 1017 | // The base class can do it as a draw or the subclass may be able to handle it. |
| 1018 | return ((dst != src) && dst->asRenderTarget() && src->asTexture()) || |
| 1019 | this->onCanCopySurface(dst, src, clippedSrcRect, clippedDstPoint); |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 1020 | } |
| 1021 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 1022 | /////////////////////////////////////////////////////////////////////////////// |
| 1023 | |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 1024 | void GrDrawTargetCaps::reset() { |
commit-bot@chromium.org | 4744231 | 2013-12-19 16:18:01 +0000 | [diff] [blame] | 1025 | fMipMapSupport = false; |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 1026 | fNPOTTextureTileSupport = false; |
| 1027 | fTwoSidedStencilSupport = false; |
| 1028 | fStencilWrapOpsSupport = false; |
| 1029 | fHWAALineSupport = false; |
| 1030 | fShaderDerivativeSupport = false; |
| 1031 | fGeometryShaderSupport = false; |
skia.committer@gmail.com | e60ed08 | 2013-03-26 07:01:04 +0000 | [diff] [blame] | 1032 | fDualSourceBlendingSupport = false; |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 1033 | fPathRenderingSupport = false; |
commit-bot@chromium.org | b835652 | 2013-07-18 22:26:39 +0000 | [diff] [blame] | 1034 | fDstReadInShaderSupport = false; |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 1035 | fDiscardRenderTargetSupport = false; |
commit-bot@chromium.org | b835652 | 2013-07-18 22:26:39 +0000 | [diff] [blame] | 1036 | fReuseScratchTextures = true; |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 1037 | fGpuTracingSupport = false; |
krajcevski | 78697816 | 2014-07-30 11:25:44 -0700 | [diff] [blame] | 1038 | fCompressedTexSubImageSupport = false; |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 1039 | |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 1040 | fUseDrawInsteadOfClear = false; |
| 1041 | |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 1042 | fMapBufferFlags = kNone_MapFlags; |
| 1043 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 1044 | fMaxRenderTargetSize = 0; |
| 1045 | fMaxTextureSize = 0; |
| 1046 | fMaxSampleCount = 0; |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 1047 | |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 1048 | fShaderPrecisionVaries = false; |
| 1049 | |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 1050 | memset(fConfigRenderSupport, 0, sizeof(fConfigRenderSupport)); |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 1051 | memset(fConfigTextureSupport, 0, sizeof(fConfigTextureSupport)); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 1052 | } |
| 1053 | |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 1054 | GrDrawTargetCaps& GrDrawTargetCaps::operator=(const GrDrawTargetCaps& other) { |
commit-bot@chromium.org | 4744231 | 2013-12-19 16:18:01 +0000 | [diff] [blame] | 1055 | fMipMapSupport = other.fMipMapSupport; |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 1056 | fNPOTTextureTileSupport = other.fNPOTTextureTileSupport; |
| 1057 | fTwoSidedStencilSupport = other.fTwoSidedStencilSupport; |
| 1058 | fStencilWrapOpsSupport = other.fStencilWrapOpsSupport; |
| 1059 | fHWAALineSupport = other.fHWAALineSupport; |
| 1060 | fShaderDerivativeSupport = other.fShaderDerivativeSupport; |
| 1061 | fGeometryShaderSupport = other.fGeometryShaderSupport; |
| 1062 | fDualSourceBlendingSupport = other.fDualSourceBlendingSupport; |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 1063 | fPathRenderingSupport = other.fPathRenderingSupport; |
commit-bot@chromium.org | b835652 | 2013-07-18 22:26:39 +0000 | [diff] [blame] | 1064 | fDstReadInShaderSupport = other.fDstReadInShaderSupport; |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 1065 | fDiscardRenderTargetSupport = other.fDiscardRenderTargetSupport; |
commit-bot@chromium.org | b835652 | 2013-07-18 22:26:39 +0000 | [diff] [blame] | 1066 | fReuseScratchTextures = other.fReuseScratchTextures; |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 1067 | fGpuTracingSupport = other.fGpuTracingSupport; |
krajcevski | 78697816 | 2014-07-30 11:25:44 -0700 | [diff] [blame] | 1068 | fCompressedTexSubImageSupport = other.fCompressedTexSubImageSupport; |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 1069 | |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 1070 | fUseDrawInsteadOfClear = other.fUseDrawInsteadOfClear; |
| 1071 | |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 1072 | fMapBufferFlags = other.fMapBufferFlags; |
| 1073 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 1074 | fMaxRenderTargetSize = other.fMaxRenderTargetSize; |
| 1075 | fMaxTextureSize = other.fMaxTextureSize; |
| 1076 | fMaxSampleCount = other.fMaxSampleCount; |
| 1077 | |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 1078 | memcpy(fConfigRenderSupport, other.fConfigRenderSupport, sizeof(fConfigRenderSupport)); |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 1079 | memcpy(fConfigTextureSupport, other.fConfigTextureSupport, sizeof(fConfigTextureSupport)); |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 1080 | |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 1081 | fShaderPrecisionVaries = other.fShaderPrecisionVaries; |
| 1082 | for (int s = 0; s < kGrShaderTypeCount; ++s) { |
bsalomon | c0bd648 | 2014-12-09 10:04:14 -0800 | [diff] [blame] | 1083 | for (int p = 0; p < kGrSLPrecisionCount; ++p) { |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 1084 | fFloatPrecisions[s][p] = other.fFloatPrecisions[s][p]; |
| 1085 | } |
| 1086 | } |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 1087 | return *this; |
| 1088 | } |
| 1089 | |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 1090 | static SkString map_flags_to_string(uint32_t flags) { |
| 1091 | SkString str; |
| 1092 | if (GrDrawTargetCaps::kNone_MapFlags == flags) { |
| 1093 | str = "none"; |
| 1094 | } else { |
| 1095 | SkASSERT(GrDrawTargetCaps::kCanMap_MapFlag & flags); |
| 1096 | SkDEBUGCODE(flags &= ~GrDrawTargetCaps::kCanMap_MapFlag); |
| 1097 | str = "can_map"; |
| 1098 | |
| 1099 | if (GrDrawTargetCaps::kSubset_MapFlag & flags) { |
| 1100 | str.append(" partial"); |
| 1101 | } else { |
| 1102 | str.append(" full"); |
| 1103 | } |
| 1104 | SkDEBUGCODE(flags &= ~GrDrawTargetCaps::kSubset_MapFlag); |
| 1105 | } |
| 1106 | SkASSERT(0 == flags); // Make sure we handled all the flags. |
| 1107 | return str; |
| 1108 | } |
| 1109 | |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 1110 | static const char* shader_type_to_string(GrShaderType type) { |
| 1111 | switch (type) { |
| 1112 | case kVertex_GrShaderType: |
| 1113 | return "vertex"; |
| 1114 | case kGeometry_GrShaderType: |
| 1115 | return "geometry"; |
| 1116 | case kFragment_GrShaderType: |
| 1117 | return "fragment"; |
| 1118 | } |
| 1119 | return ""; |
| 1120 | } |
| 1121 | |
bsalomon | c0bd648 | 2014-12-09 10:04:14 -0800 | [diff] [blame] | 1122 | static const char* precision_to_string(GrSLPrecision p) { |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 1123 | switch (p) { |
bsalomon | c0bd648 | 2014-12-09 10:04:14 -0800 | [diff] [blame] | 1124 | case kLow_GrSLPrecision: |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 1125 | return "low"; |
bsalomon | c0bd648 | 2014-12-09 10:04:14 -0800 | [diff] [blame] | 1126 | case kMedium_GrSLPrecision: |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 1127 | return "medium"; |
bsalomon | c0bd648 | 2014-12-09 10:04:14 -0800 | [diff] [blame] | 1128 | case kHigh_GrSLPrecision: |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 1129 | return "high"; |
| 1130 | } |
| 1131 | return ""; |
| 1132 | } |
| 1133 | |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 1134 | SkString GrDrawTargetCaps::dump() const { |
| 1135 | SkString r; |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 1136 | static const char* gNY[] = {"NO", "YES"}; |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 1137 | r.appendf("MIP Map Support : %s\n", gNY[fMipMapSupport]); |
| 1138 | r.appendf("NPOT Texture Tile Support : %s\n", gNY[fNPOTTextureTileSupport]); |
| 1139 | r.appendf("Two Sided Stencil Support : %s\n", gNY[fTwoSidedStencilSupport]); |
| 1140 | r.appendf("Stencil Wrap Ops Support : %s\n", gNY[fStencilWrapOpsSupport]); |
| 1141 | r.appendf("HW AA Lines Support : %s\n", gNY[fHWAALineSupport]); |
| 1142 | r.appendf("Shader Derivative Support : %s\n", gNY[fShaderDerivativeSupport]); |
| 1143 | r.appendf("Geometry Shader Support : %s\n", gNY[fGeometryShaderSupport]); |
| 1144 | r.appendf("Dual Source Blending Support : %s\n", gNY[fDualSourceBlendingSupport]); |
| 1145 | r.appendf("Path Rendering Support : %s\n", gNY[fPathRenderingSupport]); |
| 1146 | r.appendf("Dst Read In Shader Support : %s\n", gNY[fDstReadInShaderSupport]); |
| 1147 | r.appendf("Discard Render Target Support : %s\n", gNY[fDiscardRenderTargetSupport]); |
| 1148 | r.appendf("Reuse Scratch Textures : %s\n", gNY[fReuseScratchTextures]); |
| 1149 | r.appendf("Gpu Tracing Support : %s\n", gNY[fGpuTracingSupport]); |
| 1150 | r.appendf("Compressed Update Support : %s\n", gNY[fCompressedTexSubImageSupport]); |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 1151 | |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 1152 | r.appendf("Draw Instead of Clear [workaround] : %s\n", gNY[fUseDrawInsteadOfClear]); |
| 1153 | |
| 1154 | r.appendf("Max Texture Size : %d\n", fMaxTextureSize); |
| 1155 | r.appendf("Max Render Target Size : %d\n", fMaxRenderTargetSize); |
| 1156 | r.appendf("Max Sample Count : %d\n", fMaxSampleCount); |
| 1157 | |
| 1158 | r.appendf("Map Buffer Support : %s\n", |
| 1159 | map_flags_to_string(fMapBufferFlags).c_str()); |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 1160 | |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 1161 | static const char* kConfigNames[] = { |
| 1162 | "Unknown", // kUnknown_GrPixelConfig |
| 1163 | "Alpha8", // kAlpha_8_GrPixelConfig, |
| 1164 | "Index8", // kIndex_8_GrPixelConfig, |
| 1165 | "RGB565", // kRGB_565_GrPixelConfig, |
| 1166 | "RGBA444", // kRGBA_4444_GrPixelConfig, |
| 1167 | "RGBA8888", // kRGBA_8888_GrPixelConfig, |
| 1168 | "BGRA8888", // kBGRA_8888_GrPixelConfig, |
jvanverth | fa1e8a7 | 2014-12-22 08:31:49 -0800 | [diff] [blame] | 1169 | "SRGBA8888",// kSRGBA_8888_GrPixelConfig, |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 1170 | "ETC1", // kETC1_GrPixelConfig, |
| 1171 | "LATC", // kLATC_GrPixelConfig, |
krajcevski | 238b456 | 2014-06-30 09:09:22 -0700 | [diff] [blame] | 1172 | "R11EAC", // kR11_EAC_GrPixelConfig, |
krajcevski | 7ef2162 | 2014-07-16 15:21:13 -0700 | [diff] [blame] | 1173 | "ASTC12x12",// kASTC_12x12_GrPixelConfig, |
jvanverth | 28f9c60 | 2014-12-05 13:06:35 -0800 | [diff] [blame] | 1174 | "RGBAFloat",// kRGBA_float_GrPixelConfig |
| 1175 | "AlphaHalf",// kAlpha_half_GrPixelConfig |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 1176 | }; |
krajcevski | 7ef2162 | 2014-07-16 15:21:13 -0700 | [diff] [blame] | 1177 | GR_STATIC_ASSERT(0 == kUnknown_GrPixelConfig); |
| 1178 | GR_STATIC_ASSERT(1 == kAlpha_8_GrPixelConfig); |
| 1179 | GR_STATIC_ASSERT(2 == kIndex_8_GrPixelConfig); |
| 1180 | GR_STATIC_ASSERT(3 == kRGB_565_GrPixelConfig); |
| 1181 | GR_STATIC_ASSERT(4 == kRGBA_4444_GrPixelConfig); |
| 1182 | GR_STATIC_ASSERT(5 == kRGBA_8888_GrPixelConfig); |
| 1183 | GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig); |
jvanverth | fa1e8a7 | 2014-12-22 08:31:49 -0800 | [diff] [blame] | 1184 | GR_STATIC_ASSERT(7 == kSRGBA_8888_GrPixelConfig); |
| 1185 | GR_STATIC_ASSERT(8 == kETC1_GrPixelConfig); |
| 1186 | GR_STATIC_ASSERT(9 == kLATC_GrPixelConfig); |
| 1187 | GR_STATIC_ASSERT(10 == kR11_EAC_GrPixelConfig); |
| 1188 | GR_STATIC_ASSERT(11 == kASTC_12x12_GrPixelConfig); |
| 1189 | GR_STATIC_ASSERT(12 == kRGBA_float_GrPixelConfig); |
| 1190 | GR_STATIC_ASSERT(13 == kAlpha_half_GrPixelConfig); |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 1191 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kConfigNames) == kGrPixelConfigCnt); |
| 1192 | |
commit-bot@chromium.org | 9901727 | 2013-11-08 18:45:27 +0000 | [diff] [blame] | 1193 | SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][0]); |
| 1194 | SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][1]); |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 1195 | |
| 1196 | for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) { |
| 1197 | r.appendf("%s is renderable: %s, with MSAA: %s\n", |
| 1198 | kConfigNames[i], |
| 1199 | gNY[fConfigRenderSupport[i][0]], |
| 1200 | gNY[fConfigRenderSupport[i][1]]); |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 1201 | } |
commit-bot@chromium.org | 42dc813 | 2014-05-27 19:26:59 +0000 | [diff] [blame] | 1202 | |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 1203 | SkASSERT(!fConfigTextureSupport[kUnknown_GrPixelConfig]); |
commit-bot@chromium.org | 42dc813 | 2014-05-27 19:26:59 +0000 | [diff] [blame] | 1204 | |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 1205 | for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) { |
| 1206 | r.appendf("%s is uploadable to a texture: %s\n", |
| 1207 | kConfigNames[i], |
| 1208 | gNY[fConfigTextureSupport[i]]); |
commit-bot@chromium.org | 42dc813 | 2014-05-27 19:26:59 +0000 | [diff] [blame] | 1209 | } |
| 1210 | |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 1211 | r.appendf("Shader Float Precisions (varies: %s):\n", gNY[fShaderPrecisionVaries]); |
| 1212 | |
| 1213 | for (int s = 0; s < kGrShaderTypeCount; ++s) { |
| 1214 | GrShaderType shaderType = static_cast<GrShaderType>(s); |
| 1215 | r.appendf("\t%s:\n", shader_type_to_string(shaderType)); |
bsalomon | c0bd648 | 2014-12-09 10:04:14 -0800 | [diff] [blame] | 1216 | for (int p = 0; p < kGrSLPrecisionCount; ++p) { |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 1217 | if (fFloatPrecisions[s][p].supported()) { |
bsalomon | c0bd648 | 2014-12-09 10:04:14 -0800 | [diff] [blame] | 1218 | GrSLPrecision precision = static_cast<GrSLPrecision>(p); |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 1219 | r.appendf("\t\t%s: log_low: %d log_high: %d bits: %d\n", |
| 1220 | precision_to_string(precision), |
| 1221 | fFloatPrecisions[s][p].fLogRangeLow, |
| 1222 | fFloatPrecisions[s][p].fLogRangeHigh, |
| 1223 | fFloatPrecisions[s][p].fBits); |
| 1224 | } |
| 1225 | } |
| 1226 | } |
| 1227 | |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 1228 | return r; |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 1229 | } |
egdaniel | bc127a3 | 2014-09-19 12:07:43 -0700 | [diff] [blame] | 1230 | |
| 1231 | uint32_t GrDrawTargetCaps::CreateUniqueID() { |
| 1232 | static int32_t gUniqueID = SK_InvalidUniqueID; |
| 1233 | uint32_t id; |
| 1234 | do { |
| 1235 | id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1); |
| 1236 | } while (id == SK_InvalidUniqueID); |
| 1237 | return id; |
| 1238 | } |
| 1239 | |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 1240 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 1241 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 1242 | bool GrClipTarget::setupClip(GrPipelineBuilder* pipelineBuilder, |
| 1243 | GrPipelineBuilder::AutoRestoreEffects* are, |
| 1244 | GrPipelineBuilder::AutoRestoreStencil* ars, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 1245 | GrScissorState* scissorState, |
| 1246 | const SkRect* devBounds) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 1247 | return fClipMaskManager.setupClipping(pipelineBuilder, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 1248 | are, |
| 1249 | ars, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 1250 | scissorState, |
| 1251 | this->getClip(), |
| 1252 | devBounds); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 1253 | } |