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