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