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