blob: 10fa6b202d2da49f9b11b018ffea83d8cd6d05be [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@google.comac10a2d2010-12-22 21:39:39 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * 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.comac10a2d2010-12-22 21:39:39 +00007 */
8
9
epoger@google.comec3ed6a2011-07-28 14:26:00 +000010
reed@google.comac10a2d2010-12-22 21:39:39 +000011#include "GrDrawTarget.h"
bsalomon@google.com26e18b52013-03-29 19:22:36 +000012#include "GrContext.h"
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000013#include "GrDrawTargetCaps.h"
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +000014#include "GrPath.h"
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000015#include "GrRenderTarget.h"
bsalomon@google.com86afc2a2011-02-16 16:12:19 +000016#include "GrTexture.h"
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000017#include "GrVertexBuffer.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000018
sugoi@google.com5f74cf82012-12-17 21:16:45 +000019#include "SkStrokeRec.h"
sugoi@google.com12b4e272012-12-06 20:13:11 +000020
reed@google.comac10a2d2010-12-22 21:39:39 +000021////////////////////////////////////////////////////////////////////////////////
22
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000023GrDrawTarget::DrawInfo& GrDrawTarget::DrawInfo::operator =(const DrawInfo& di) {
24 fPrimitiveType = di.fPrimitiveType;
25 fStartVertex = di.fStartVertex;
26 fStartIndex = di.fStartIndex;
27 fVertexCount = di.fVertexCount;
28 fIndexCount = di.fIndexCount;
29
30 fInstanceCount = di.fInstanceCount;
31 fVerticesPerInstance = di.fVerticesPerInstance;
32 fIndicesPerInstance = di.fIndicesPerInstance;
33
34 if (NULL != di.fDevBounds) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000035 SkASSERT(di.fDevBounds == &di.fDevBoundsStorage);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000036 fDevBoundsStorage = di.fDevBoundsStorage;
37 fDevBounds = &fDevBoundsStorage;
38 } else {
39 fDevBounds = NULL;
40 }
bsalomon@google.com26e18b52013-03-29 19:22:36 +000041
42 fDstCopy = di.fDstCopy;
43
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000044 return *this;
45}
46
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +000047#ifdef SK_DEBUG
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000048bool GrDrawTarget::DrawInfo::isInstanced() const {
49 if (fInstanceCount > 0) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000050 SkASSERT(0 == fIndexCount % fIndicesPerInstance);
51 SkASSERT(0 == fVertexCount % fVerticesPerInstance);
52 SkASSERT(fIndexCount / fIndicesPerInstance == fInstanceCount);
53 SkASSERT(fVertexCount / fVerticesPerInstance == fInstanceCount);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000054 // there is no way to specify a non-zero start index to drawIndexedInstances().
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000055 SkASSERT(0 == fStartIndex);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000056 return true;
57 } else {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000058 SkASSERT(!fVerticesPerInstance);
59 SkASSERT(!fIndicesPerInstance);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000060 return false;
61 }
62}
63#endif
64
65void GrDrawTarget::DrawInfo::adjustInstanceCount(int instanceOffset) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000066 SkASSERT(this->isInstanced());
67 SkASSERT(instanceOffset + fInstanceCount >= 0);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000068 fInstanceCount += instanceOffset;
69 fVertexCount = fVerticesPerInstance * fInstanceCount;
70 fIndexCount = fIndicesPerInstance * fInstanceCount;
71}
72
73void GrDrawTarget::DrawInfo::adjustStartVertex(int vertexOffset) {
74 fStartVertex += vertexOffset;
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000075 SkASSERT(fStartVertex >= 0);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000076}
77
78void GrDrawTarget::DrawInfo::adjustStartIndex(int indexOffset) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000079 SkASSERT(this->isIndexed());
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000080 fStartIndex += indexOffset;
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000081 SkASSERT(fStartIndex >= 0);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000082}
83
84////////////////////////////////////////////////////////////////////////////////
85
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000086#define DEBUG_INVAL_BUFFER 0xdeadcafe
87#define DEBUG_INVAL_START_IDX -1
88
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000089GrDrawTarget::GrDrawTarget(GrContext* context)
90 : fClip(NULL)
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +000091 , fContext(context)
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +000092 , fGpuTraceMarkerCount(0) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000093 SkASSERT(NULL != context);
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000094
bsalomon@google.coma5d056a2012-03-27 15:59:58 +000095 fDrawState = &fDefaultDrawState;
96 // We assume that fDrawState always owns a ref to the object it points at.
97 fDefaultDrawState.ref();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000098 GeometrySrcState& geoSrc = fGeoSrcStateStack.push_back();
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +000099#ifdef SK_DEBUG
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000100 geoSrc.fVertexCount = DEBUG_INVAL_START_IDX;
101 geoSrc.fVertexBuffer = (GrVertexBuffer*)DEBUG_INVAL_BUFFER;
102 geoSrc.fIndexCount = DEBUG_INVAL_START_IDX;
103 geoSrc.fIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER;
reed@google.comac10a2d2010-12-22 21:39:39 +0000104#endif
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000105 geoSrc.fVertexSrc = kNone_GeometrySrcType;
106 geoSrc.fIndexSrc = kNone_GeometrySrcType;
107}
108
109GrDrawTarget::~GrDrawTarget() {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000110 SkASSERT(1 == fGeoSrcStateStack.count());
humper@google.com0e515772013-01-07 19:54:40 +0000111 SkDEBUGCODE(GeometrySrcState& geoSrc = fGeoSrcStateStack.back());
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000112 SkASSERT(kNone_GeometrySrcType == geoSrc.fIndexSrc);
113 SkASSERT(kNone_GeometrySrcType == geoSrc.fVertexSrc);
bsalomon@google.coma5d056a2012-03-27 15:59:58 +0000114 fDrawState->unref();
bsalomon@google.com4a018bb2011-10-28 19:50:21 +0000115}
116
117void GrDrawTarget::releaseGeometry() {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000118 int popCnt = fGeoSrcStateStack.count() - 1;
119 while (popCnt) {
120 this->popGeometrySource();
121 --popCnt;
122 }
bsalomon@google.com4a018bb2011-10-28 19:50:21 +0000123 this->resetVertexSource();
124 this->resetIndexSource();
reed@google.comac10a2d2010-12-22 21:39:39 +0000125}
126
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000127void GrDrawTarget::setClip(const GrClipData* clip) {
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000128 clipWillBeSet(clip);
reed@google.comac10a2d2010-12-22 21:39:39 +0000129 fClip = clip;
130}
131
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000132const GrClipData* GrDrawTarget::getClip() const {
reed@google.comac10a2d2010-12-22 21:39:39 +0000133 return fClip;
134}
135
bsalomon@google.coma5d056a2012-03-27 15:59:58 +0000136void GrDrawTarget::setDrawState(GrDrawState* drawState) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000137 SkASSERT(NULL != fDrawState);
bsalomon@google.coma5d056a2012-03-27 15:59:58 +0000138 if (NULL == drawState) {
139 drawState = &fDefaultDrawState;
140 }
141 if (fDrawState != drawState) {
142 fDrawState->unref();
143 drawState->ref();
144 fDrawState = drawState;
145 }
146}
147
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000148bool GrDrawTarget::reserveVertexSpace(size_t vertexSize,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000149 int vertexCount,
150 void** vertices) {
151 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
152 bool acquired = false;
153 if (vertexCount > 0) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000154 SkASSERT(NULL != vertices);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000155 this->releasePreviousVertexSource();
156 geoSrc.fVertexSrc = kNone_GeometrySrcType;
reed@google.comac10a2d2010-12-22 21:39:39 +0000157
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000158 acquired = this->onReserveVertexSpace(vertexSize,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000159 vertexCount,
160 vertices);
reed@google.comac10a2d2010-12-22 21:39:39 +0000161 }
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000162 if (acquired) {
163 geoSrc.fVertexSrc = kReserved_GeometrySrcType;
164 geoSrc.fVertexCount = vertexCount;
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000165 geoSrc.fVertexSize = vertexSize;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000166 } else if (NULL != vertices) {
167 *vertices = NULL;
168 }
169 return acquired;
170}
171
172bool GrDrawTarget::reserveIndexSpace(int indexCount,
173 void** indices) {
174 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
175 bool acquired = false;
176 if (indexCount > 0) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000177 SkASSERT(NULL != indices);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000178 this->releasePreviousIndexSource();
179 geoSrc.fIndexSrc = kNone_GeometrySrcType;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000180
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000181 acquired = this->onReserveIndexSpace(indexCount, indices);
182 }
183 if (acquired) {
184 geoSrc.fIndexSrc = kReserved_GeometrySrcType;
185 geoSrc.fIndexCount = indexCount;
186 } else if (NULL != indices) {
187 *indices = NULL;
188 }
189 return acquired;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000190
reed@google.comac10a2d2010-12-22 21:39:39 +0000191}
192
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000193bool GrDrawTarget::reserveVertexAndIndexSpace(int vertexCount,
bsalomon@google.come3d70952012-03-13 12:40:53 +0000194 int indexCount,
195 void** vertices,
196 void** indices) {
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000197 size_t vertexSize = this->drawState()->getVertexSize();
198 this->willReserveVertexAndIndexSpace(vertexCount, indexCount);
bsalomon@google.come3d70952012-03-13 12:40:53 +0000199 if (vertexCount) {
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000200 if (!this->reserveVertexSpace(vertexSize, vertexCount, vertices)) {
bsalomon@google.come3d70952012-03-13 12:40:53 +0000201 if (indexCount) {
202 this->resetIndexSource();
203 }
204 return false;
205 }
206 }
207 if (indexCount) {
208 if (!this->reserveIndexSpace(indexCount, indices)) {
209 if (vertexCount) {
210 this->resetVertexSource();
211 }
212 return false;
213 }
214 }
215 return true;
216}
217
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000218bool GrDrawTarget::geometryHints(int32_t* vertexCount,
reed@google.comac10a2d2010-12-22 21:39:39 +0000219 int32_t* indexCount) const {
reed@google.comac10a2d2010-12-22 21:39:39 +0000220 if (NULL != vertexCount) {
221 *vertexCount = -1;
222 }
223 if (NULL != indexCount) {
224 *indexCount = -1;
225 }
226 return false;
227}
228
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000229void GrDrawTarget::releasePreviousVertexSource() {
230 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
231 switch (geoSrc.fVertexSrc) {
232 case kNone_GeometrySrcType:
233 break;
234 case kArray_GeometrySrcType:
235 this->releaseVertexArray();
236 break;
237 case kReserved_GeometrySrcType:
238 this->releaseReservedVertexSpace();
239 break;
240 case kBuffer_GeometrySrcType:
241 geoSrc.fVertexBuffer->unref();
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000242#ifdef SK_DEBUG
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000243 geoSrc.fVertexBuffer = (GrVertexBuffer*)DEBUG_INVAL_BUFFER;
244#endif
245 break;
246 default:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000247 SkFAIL("Unknown Vertex Source Type.");
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000248 break;
249 }
250}
251
252void GrDrawTarget::releasePreviousIndexSource() {
253 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
254 switch (geoSrc.fIndexSrc) {
255 case kNone_GeometrySrcType: // these two don't require
256 break;
257 case kArray_GeometrySrcType:
258 this->releaseIndexArray();
259 break;
260 case kReserved_GeometrySrcType:
261 this->releaseReservedIndexSpace();
262 break;
263 case kBuffer_GeometrySrcType:
264 geoSrc.fIndexBuffer->unref();
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000265#ifdef SK_DEBUG
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000266 geoSrc.fIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER;
267#endif
268 break;
269 default:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000270 SkFAIL("Unknown Index Source Type.");
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000271 break;
272 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000273}
274
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000275void GrDrawTarget::setVertexSourceToArray(const void* vertexArray,
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000276 int vertexCount) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000277 this->releasePreviousVertexSource();
278 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
279 geoSrc.fVertexSrc = kArray_GeometrySrcType;
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000280 geoSrc.fVertexSize = this->drawState()->getVertexSize();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000281 geoSrc.fVertexCount = vertexCount;
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000282 this->onSetVertexSourceToArray(vertexArray, vertexCount);
reed@google.comac10a2d2010-12-22 21:39:39 +0000283}
284
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000285void GrDrawTarget::setIndexSourceToArray(const void* indexArray,
286 int indexCount) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000287 this->releasePreviousIndexSource();
288 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
289 geoSrc.fIndexSrc = kArray_GeometrySrcType;
290 geoSrc.fIndexCount = indexCount;
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000291 this->onSetIndexSourceToArray(indexArray, indexCount);
reed@google.comac10a2d2010-12-22 21:39:39 +0000292}
293
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000294void GrDrawTarget::setVertexSourceToBuffer(const GrVertexBuffer* buffer) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000295 this->releasePreviousVertexSource();
296 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
297 geoSrc.fVertexSrc = kBuffer_GeometrySrcType;
298 geoSrc.fVertexBuffer = buffer;
299 buffer->ref();
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000300 geoSrc.fVertexSize = this->drawState()->getVertexSize();
reed@google.comac10a2d2010-12-22 21:39:39 +0000301}
302
303void GrDrawTarget::setIndexSourceToBuffer(const GrIndexBuffer* buffer) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000304 this->releasePreviousIndexSource();
305 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
306 geoSrc.fIndexSrc = kBuffer_GeometrySrcType;
307 geoSrc.fIndexBuffer = buffer;
308 buffer->ref();
reed@google.comac10a2d2010-12-22 21:39:39 +0000309}
310
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000311void GrDrawTarget::resetVertexSource() {
312 this->releasePreviousVertexSource();
313 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
314 geoSrc.fVertexSrc = kNone_GeometrySrcType;
315}
316
317void GrDrawTarget::resetIndexSource() {
318 this->releasePreviousIndexSource();
319 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
320 geoSrc.fIndexSrc = kNone_GeometrySrcType;
321}
322
323void GrDrawTarget::pushGeometrySource() {
324 this->geometrySourceWillPush();
325 GeometrySrcState& newState = fGeoSrcStateStack.push_back();
326 newState.fIndexSrc = kNone_GeometrySrcType;
327 newState.fVertexSrc = kNone_GeometrySrcType;
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000328#ifdef SK_DEBUG
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000329 newState.fVertexCount = ~0;
330 newState.fVertexBuffer = (GrVertexBuffer*)~0;
331 newState.fIndexCount = ~0;
332 newState.fIndexBuffer = (GrIndexBuffer*)~0;
333#endif
334}
335
336void GrDrawTarget::popGeometrySource() {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000337 // if popping last element then pops are unbalanced with pushes
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000338 SkASSERT(fGeoSrcStateStack.count() > 1);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000339
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000340 this->geometrySourceWillPop(fGeoSrcStateStack.fromBack(1));
341 this->releasePreviousVertexSource();
342 this->releasePreviousIndexSource();
343 fGeoSrcStateStack.pop_back();
344}
345
346////////////////////////////////////////////////////////////////////////////////
347
bsalomon@google.come8262622011-11-07 02:30:51 +0000348bool GrDrawTarget::checkDraw(GrPrimitiveType type, int startVertex,
349 int startIndex, int vertexCount,
350 int indexCount) const {
bsalomon@google.comcddaf342012-07-30 13:09:05 +0000351 const GrDrawState& drawState = this->getDrawState();
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000352#ifdef SK_DEBUG
bsalomon@google.come8262622011-11-07 02:30:51 +0000353 const GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000354 int maxVertex = startVertex + vertexCount;
355 int maxValidVertex;
356 switch (geoSrc.fVertexSrc) {
357 case kNone_GeometrySrcType:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000358 SkFAIL("Attempting to draw without vertex src.");
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000359 case kReserved_GeometrySrcType: // fallthrough
360 case kArray_GeometrySrcType:
361 maxValidVertex = geoSrc.fVertexCount;
362 break;
363 case kBuffer_GeometrySrcType:
commit-bot@chromium.org089a7802014-05-02 21:38:22 +0000364 maxValidVertex = static_cast<int>(geoSrc.fVertexBuffer->gpuMemorySize() / geoSrc.fVertexSize);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000365 break;
366 }
367 if (maxVertex > maxValidVertex) {
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000368 SkFAIL("Drawing outside valid vertex range.");
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000369 }
bsalomon@google.come8262622011-11-07 02:30:51 +0000370 if (indexCount > 0) {
371 int maxIndex = startIndex + indexCount;
372 int maxValidIndex;
373 switch (geoSrc.fIndexSrc) {
374 case kNone_GeometrySrcType:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000375 SkFAIL("Attempting to draw indexed geom without index src.");
bsalomon@google.come8262622011-11-07 02:30:51 +0000376 case kReserved_GeometrySrcType: // fallthrough
377 case kArray_GeometrySrcType:
378 maxValidIndex = geoSrc.fIndexCount;
379 break;
380 case kBuffer_GeometrySrcType:
commit-bot@chromium.org089a7802014-05-02 21:38:22 +0000381 maxValidIndex = static_cast<int>(geoSrc.fIndexBuffer->gpuMemorySize() / sizeof(uint16_t));
bsalomon@google.come8262622011-11-07 02:30:51 +0000382 break;
383 }
384 if (maxIndex > maxValidIndex) {
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000385 SkFAIL("Index reads outside valid index range.");
bsalomon@google.come8262622011-11-07 02:30:51 +0000386 }
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000387 }
bsalomon@google.comb4725b42012-03-30 17:24:17 +0000388
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000389 SkASSERT(NULL != drawState.getRenderTarget());
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000390
391 for (int s = 0; s < drawState.numColorStages(); ++s) {
bsalomonf99f8842014-07-07 11:54:23 -0700392 const GrEffect* effect = drawState.getColorStage(s).getEffect();
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000393 int numTextures = effect->numTextures();
394 for (int t = 0; t < numTextures; ++t) {
395 GrTexture* texture = effect->texture(t);
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000396 SkASSERT(texture->asRenderTarget() != drawState.getRenderTarget());
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000397 }
398 }
399 for (int s = 0; s < drawState.numCoverageStages(); ++s) {
bsalomonf99f8842014-07-07 11:54:23 -0700400 const GrEffect* effect = drawState.getCoverageStage(s).getEffect();
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000401 int numTextures = effect->numTextures();
402 for (int t = 0; t < numTextures; ++t) {
403 GrTexture* texture = effect->texture(t);
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000404 SkASSERT(texture->asRenderTarget() != drawState.getRenderTarget());
bsalomon@google.comb4725b42012-03-30 17:24:17 +0000405 }
406 }
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000407
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000408 SkASSERT(drawState.validateVertexAttribs());
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000409#endif
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000410 if (NULL == drawState.getRenderTarget()) {
bsalomon@google.com0ba52fc2011-11-10 22:16:06 +0000411 return false;
412 }
bsalomon@google.come8262622011-11-07 02:30:51 +0000413 return true;
414}
415
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000416bool GrDrawTarget::setupDstReadIfNecessary(GrDeviceCoordTexture* dstCopy, const SkRect* drawBounds) {
bsalomon@google.comb5158812013-05-13 18:50:25 +0000417 if (this->caps()->dstReadInShaderSupport() || !this->getDrawState().willEffectReadDstColor()) {
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000418 return true;
419 }
420 GrRenderTarget* rt = this->drawState()->getRenderTarget();
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000421 SkIRect copyRect;
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000422 const GrClipData* clip = this->getClip();
423 clip->getConservativeBounds(rt, &copyRect);
424
425 if (NULL != drawBounds) {
426 SkIRect drawIBounds;
427 drawBounds->roundOut(&drawIBounds);
commit-bot@chromium.orgbb5c4652013-04-01 12:49:31 +0000428 if (!copyRect.intersect(drawIBounds)) {
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000429#ifdef SK_DEBUG
commit-bot@chromium.orgbb5c4652013-04-01 12:49:31 +0000430 GrPrintf("Missed an early reject. Bailing on draw from setupDstReadIfNecessary.\n");
431#endif
432 return false;
433 }
434 } else {
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000435#ifdef SK_DEBUG
commit-bot@chromium.orgbb5c4652013-04-01 12:49:31 +0000436 //GrPrintf("No dev bounds when dst copy is made.\n");
437#endif
438 }
skia.committer@gmail.com05a2ee02013-04-02 07:01:34 +0000439
commit-bot@chromium.org63150af2013-04-11 22:00:22 +0000440 // MSAA consideration: When there is support for reading MSAA samples in the shader we could
441 // have per-sample dst values by making the copy multisampled.
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000442 GrTextureDesc desc;
bsalomon@google.comeb851172013-04-15 13:51:00 +0000443 this->initCopySurfaceDstDesc(rt, &desc);
commit-bot@chromium.orgbb5c4652013-04-01 12:49:31 +0000444 desc.fWidth = copyRect.width();
445 desc.fHeight = copyRect.height();
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000446
447 GrAutoScratchTexture ast(fContext, desc, GrContext::kApprox_ScratchTexMatch);
448
449 if (NULL == ast.texture()) {
450 GrPrintf("Failed to create temporary copy of destination texture.\n");
451 return false;
452 }
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000453 SkIPoint dstPoint = {0, 0};
454 if (this->copySurface(ast.texture(), rt, copyRect, dstPoint)) {
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000455 dstCopy->setTexture(ast.texture());
456 dstCopy->setOffset(copyRect.fLeft, copyRect.fTop);
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000457 return true;
458 } else {
459 return false;
460 }
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000461}
462
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000463void GrDrawTarget::drawIndexed(GrPrimitiveType type,
464 int startVertex,
465 int startIndex,
466 int vertexCount,
467 int indexCount,
468 const SkRect* devBounds) {
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000469 if (indexCount > 0 && this->checkDraw(type, startVertex, startIndex, vertexCount, indexCount)) {
470 DrawInfo info;
471 info.fPrimitiveType = type;
472 info.fStartVertex = startVertex;
473 info.fStartIndex = startIndex;
474 info.fVertexCount = vertexCount;
475 info.fIndexCount = indexCount;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000476
477 info.fInstanceCount = 0;
478 info.fVerticesPerInstance = 0;
479 info.fIndicesPerInstance = 0;
480
481 if (NULL != devBounds) {
482 info.setDevBounds(*devBounds);
483 }
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000484 // TODO: We should continue with incorrect blending.
485 if (!this->setupDstReadIfNecessary(&info)) {
486 return;
487 }
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000488 this->onDraw(info);
bsalomon@google.com82145872011-08-23 14:32:40 +0000489 }
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000490}
491
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000492void GrDrawTarget::drawNonIndexed(GrPrimitiveType type,
493 int startVertex,
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000494 int vertexCount,
495 const SkRect* devBounds) {
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000496 if (vertexCount > 0 && this->checkDraw(type, startVertex, -1, vertexCount, -1)) {
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.comd62e88e2013-02-01 14:19:27 +0000503
504 info.fInstanceCount = 0;
505 info.fVerticesPerInstance = 0;
506 info.fIndicesPerInstance = 0;
507
508 if (NULL != devBounds) {
509 info.setDevBounds(*devBounds);
510 }
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000511 // TODO: We should continue with incorrect blending.
512 if (!this->setupDstReadIfNecessary(&info)) {
513 return;
514 }
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000515 this->onDraw(info);
bsalomon@google.com82145872011-08-23 14:32:40 +0000516 }
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000517}
518
commit-bot@chromium.org32184d82013-10-09 15:14:18 +0000519void GrDrawTarget::stencilPath(const GrPath* path, SkPath::FillType fill) {
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000520 // TODO: extract portions of checkDraw that are relevant to path stenciling.
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000521 SkASSERT(NULL != path);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000522 SkASSERT(this->caps()->pathRenderingSupport());
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000523 SkASSERT(!SkPath::IsInverseFillType(fill));
commit-bot@chromium.org32184d82013-10-09 15:14:18 +0000524 this->onStencilPath(path, fill);
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000525}
526
commit-bot@chromium.org32184d82013-10-09 15:14:18 +0000527void GrDrawTarget::drawPath(const GrPath* path, SkPath::FillType fill) {
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000528 // TODO: extract portions of checkDraw that are relevant to path rendering.
529 SkASSERT(NULL != path);
530 SkASSERT(this->caps()->pathRenderingSupport());
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000531 const GrDrawState* drawState = &getDrawState();
532
533 SkRect devBounds;
534 if (SkPath::IsInverseFillType(fill)) {
535 devBounds = SkRect::MakeWH(SkIntToScalar(drawState->getRenderTarget()->width()),
536 SkIntToScalar(drawState->getRenderTarget()->height()));
537 } else {
538 devBounds = path->getBounds();
539 }
540 SkMatrix viewM = drawState->getViewMatrix();
541 viewM.mapRect(&devBounds);
542
543 GrDeviceCoordTexture dstCopy;
544 if (!this->setupDstReadIfNecessary(&dstCopy, &devBounds)) {
545 return;
546 }
547
commit-bot@chromium.org32184d82013-10-09 15:14:18 +0000548 this->onDrawPath(path, fill, dstCopy.texture() ? &dstCopy : NULL);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000549}
550
cdaltonb85a0aa2014-07-21 15:32:44 -0700551void GrDrawTarget::drawPaths(const GrPathRange* pathRange,
552 const uint32_t indices[], int count,
553 const float transforms[], PathTransformType transformsType,
554 SkPath::FillType fill) {
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000555 SkASSERT(this->caps()->pathRenderingSupport());
cdaltonb85a0aa2014-07-21 15:32:44 -0700556 SkASSERT(NULL != pathRange);
557 SkASSERT(NULL != indices);
558 SkASSERT(NULL != transforms);
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000559
cdaltonb85a0aa2014-07-21 15:32:44 -0700560 // Don't compute a bounding box for setupDstReadIfNecessary(), we'll opt
561 // instead for it to just copy the entire dst. Realistically this is a moot
562 // point, because any context that supports NV_path_rendering will also
563 // support NV_blend_equation_advanced.
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000564 GrDeviceCoordTexture dstCopy;
cdaltonb85a0aa2014-07-21 15:32:44 -0700565 if (!this->setupDstReadIfNecessary(&dstCopy, NULL)) {
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000566 return;
567 }
568
cdaltonb85a0aa2014-07-21 15:32:44 -0700569 this->onDrawPaths(pathRange, indices, count, transforms, transformsType, fill,
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000570 dstCopy.texture() ? &dstCopy : NULL);
571}
572
egdaniel3eee3832014-06-18 13:09:11 -0700573typedef GrTraceMarkerSet::Iter TMIter;
574void GrDrawTarget::saveActiveTraceMarkers() {
575 if (this->caps()->gpuTracingSupport()) {
576 SkASSERT(0 == fStoredTraceMarkers.count());
577 fStoredTraceMarkers.addSet(fActiveTraceMarkers);
578 for (TMIter iter = fStoredTraceMarkers.begin(); iter != fStoredTraceMarkers.end(); ++iter) {
579 this->removeGpuTraceMarker(&(*iter));
580 }
581 }
582}
583
584void GrDrawTarget::restoreActiveTraceMarkers() {
585 if (this->caps()->gpuTracingSupport()) {
586 SkASSERT(0 == fActiveTraceMarkers.count());
587 for (TMIter iter = fStoredTraceMarkers.begin(); iter != fStoredTraceMarkers.end(); ++iter) {
588 this->addGpuTraceMarker(&(*iter));
589 }
590 for (TMIter iter = fActiveTraceMarkers.begin(); iter != fActiveTraceMarkers.end(); ++iter) {
591 this->fStoredTraceMarkers.remove(*iter);
592 }
593 }
594}
595
596void GrDrawTarget::addGpuTraceMarker(const GrGpuTraceMarker* marker) {
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000597 if (this->caps()->gpuTracingSupport()) {
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000598 SkASSERT(fGpuTraceMarkerCount >= 0);
599 this->fActiveTraceMarkers.add(*marker);
600 this->didAddGpuTraceMarker();
601 ++fGpuTraceMarkerCount;
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000602 }
603}
604
egdaniel3eee3832014-06-18 13:09:11 -0700605void GrDrawTarget::removeGpuTraceMarker(const GrGpuTraceMarker* marker) {
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000606 if (this->caps()->gpuTracingSupport()) {
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000607 SkASSERT(fGpuTraceMarkerCount >= 1);
608 this->fActiveTraceMarkers.remove(*marker);
609 this->didRemoveGpuTraceMarker();
610 --fGpuTraceMarkerCount;
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000611 }
612}
613
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000614////////////////////////////////////////////////////////////////////////////////
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000615
bsalomon@google.comd46e2422011-09-23 17:40:07 +0000616bool GrDrawTarget::canApplyCoverage() const {
bsalomon@google.com86c1f712011-10-12 14:54:26 +0000617 // we can correctly apply coverage if a) we have dual source blending
egdanielb09bdd62014-07-29 08:52:23 -0700618 // or b) one of our blend optimizations applies.
bsalomon@google.combcce8922013-03-25 15:38:39 +0000619 return this->caps()->dualSourceBlendingSupport() ||
egdanielb09bdd62014-07-29 08:52:23 -0700620 GrDrawState::kNone_BlendOpt != this->getDrawState().getBlendOpts(true);
bsalomon@google.com471d4712011-08-23 15:45:25 +0000621}
622
bsalomon@google.com934c5702012-03-20 21:17:58 +0000623////////////////////////////////////////////////////////////////////////////////
624
625void GrDrawTarget::drawIndexedInstances(GrPrimitiveType type,
626 int instanceCount,
627 int verticesPerInstance,
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000628 int indicesPerInstance,
629 const SkRect* devBounds) {
bsalomon@google.com934c5702012-03-20 21:17:58 +0000630 if (!verticesPerInstance || !indicesPerInstance) {
631 return;
632 }
633
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000634 int maxInstancesPerDraw = this->indexCountInCurrentSource() / indicesPerInstance;
635 if (!maxInstancesPerDraw) {
bsalomon@google.com934c5702012-03-20 21:17:58 +0000636 return;
637 }
638
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000639 DrawInfo info;
640 info.fPrimitiveType = type;
641 info.fStartIndex = 0;
642 info.fStartVertex = 0;
643 info.fIndicesPerInstance = indicesPerInstance;
644 info.fVerticesPerInstance = verticesPerInstance;
645
646 // Set the same bounds for all the draws.
647 if (NULL != devBounds) {
648 info.setDevBounds(*devBounds);
649 }
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000650 // TODO: We should continue with incorrect blending.
651 if (!this->setupDstReadIfNecessary(&info)) {
652 return;
653 }
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000654
bsalomon@google.com934c5702012-03-20 21:17:58 +0000655 while (instanceCount) {
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000656 info.fInstanceCount = SkTMin(instanceCount, maxInstancesPerDraw);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000657 info.fVertexCount = info.fInstanceCount * verticesPerInstance;
658 info.fIndexCount = info.fInstanceCount * indicesPerInstance;
659
660 if (this->checkDraw(type,
661 info.fStartVertex,
662 info.fStartIndex,
663 info.fVertexCount,
664 info.fIndexCount)) {
665 this->onDraw(info);
666 }
667 info.fStartVertex += info.fVertexCount;
668 instanceCount -= info.fInstanceCount;
bsalomon@google.com934c5702012-03-20 21:17:58 +0000669 }
670}
bsalomon@google.com3d0835b2011-12-08 16:12:03 +0000671
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000672////////////////////////////////////////////////////////////////////////////////
673
robertphillips@google.com42903302013-04-20 12:26:07 +0000674namespace {
675
676// position + (optional) texture coord
677extern const GrVertexAttrib gBWRectPosUVAttribs[] = {
678 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding},
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000679 {kVec2f_GrVertexAttribType, sizeof(SkPoint), kLocalCoord_GrVertexAttribBinding}
robertphillips@google.com42903302013-04-20 12:26:07 +0000680};
681
682void set_vertex_attributes(GrDrawState* drawState, bool hasUVs) {
683 if (hasUVs) {
684 drawState->setVertexAttribs<gBWRectPosUVAttribs>(2);
685 } else {
686 drawState->setVertexAttribs<gBWRectPosUVAttribs>(1);
687 }
688}
689
690};
691
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000692void GrDrawTarget::onDrawRect(const SkRect& rect,
bsalomon@google.com0406b9e2013-04-02 21:00:15 +0000693 const SkMatrix* matrix,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000694 const SkRect* localRect,
bsalomon@google.com0406b9e2013-04-02 21:00:15 +0000695 const SkMatrix* localMatrix) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000696
697 GrDrawState::AutoViewMatrixRestore avmr;
698 if (NULL != matrix) {
bsalomon@google.comc7818882013-03-20 19:19:53 +0000699 avmr.set(this->drawState(), *matrix);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000700 }
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000701
robertphillips@google.com42903302013-04-20 12:26:07 +0000702 set_vertex_attributes(this->drawState(), NULL != localRect);
703
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000704 AutoReleaseGeometry geo(this, 4, 0);
bsalomon@google.com6513cd02011-08-05 20:12:30 +0000705 if (!geo.succeeded()) {
706 GrPrintf("Failed to get space for vertices!\n");
707 return;
708 }
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000709
jvanverth@google.com9b855c72013-03-01 18:21:22 +0000710 size_t vsize = this->drawState()->getVertexSize();
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000711 geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, vsize);
bsalomon@google.comc7818882013-03-20 19:19:53 +0000712 if (NULL != localRect) {
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000713 SkPoint* coords = GrTCast<SkPoint*>(GrTCast<intptr_t>(geo.vertices()) +
714 sizeof(SkPoint));
bsalomon@google.comc7818882013-03-20 19:19:53 +0000715 coords->setRectFan(localRect->fLeft, localRect->fTop,
716 localRect->fRight, localRect->fBottom,
717 vsize);
718 if (NULL != localMatrix) {
719 localMatrix->mapPointsWithStride(coords, vsize, 4);
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000720 }
721 }
commit-bot@chromium.org3ae0e6c2014-02-11 18:24:25 +0000722 SkRect bounds;
723 this->getDrawState().getViewMatrix().mapRect(&bounds, rect);
robertphillips@google.com8b129aa2012-10-05 15:37:00 +0000724
commit-bot@chromium.org3ae0e6c2014-02-11 18:24:25 +0000725 this->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4, &bounds);
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000726}
727
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000728void GrDrawTarget::clipWillBeSet(const GrClipData* clipData) {
729}
730
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000731////////////////////////////////////////////////////////////////////////////////
bsalomon@google.com7ac249b2011-06-14 18:46:24 +0000732
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000733GrDrawTarget::AutoStateRestore::AutoStateRestore() {
734 fDrawTarget = NULL;
735}
reed@google.comac10a2d2010-12-22 21:39:39 +0000736
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000737GrDrawTarget::AutoStateRestore::AutoStateRestore(GrDrawTarget* target,
bsalomon@google.com137f1342013-05-29 21:27:53 +0000738 ASRInit init,
739 const SkMatrix* vm) {
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000740 fDrawTarget = NULL;
bsalomon@google.com137f1342013-05-29 21:27:53 +0000741 this->set(target, init, vm);
reed@google.comac10a2d2010-12-22 21:39:39 +0000742}
743
744GrDrawTarget::AutoStateRestore::~AutoStateRestore() {
bsalomon@google.com7d34d2e2011-01-24 17:41:47 +0000745 if (NULL != fDrawTarget) {
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000746 fDrawTarget->setDrawState(fSavedState);
747 fSavedState->unref();
bsalomon@google.com7d34d2e2011-01-24 17:41:47 +0000748 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000749}
bsalomon@google.com7d34d2e2011-01-24 17:41:47 +0000750
bsalomon@google.com137f1342013-05-29 21:27:53 +0000751void GrDrawTarget::AutoStateRestore::set(GrDrawTarget* target, ASRInit init, const SkMatrix* vm) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000752 SkASSERT(NULL == fDrawTarget);
bsalomon@google.com137f1342013-05-29 21:27:53 +0000753 fDrawTarget = target;
754 fSavedState = target->drawState();
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000755 SkASSERT(fSavedState);
bsalomon@google.com137f1342013-05-29 21:27:53 +0000756 fSavedState->ref();
757 if (kReset_ASRInit == init) {
758 if (NULL == vm) {
759 // calls the default cons
760 fTempState.init();
761 } else {
762 SkNEW_IN_TLAZY(&fTempState, GrDrawState, (*vm));
763 }
764 } else {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000765 SkASSERT(kPreserve_ASRInit == init);
bsalomon@google.com137f1342013-05-29 21:27:53 +0000766 if (NULL == vm) {
767 fTempState.set(*fSavedState);
768 } else {
769 SkNEW_IN_TLAZY(&fTempState, GrDrawState, (*fSavedState, *vm));
770 }
771 }
772 target->setDrawState(fTempState.get());
773}
774
775bool GrDrawTarget::AutoStateRestore::setIdentity(GrDrawTarget* target, ASRInit init) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000776 SkASSERT(NULL == fDrawTarget);
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000777 fDrawTarget = target;
778 fSavedState = target->drawState();
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000779 SkASSERT(fSavedState);
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000780 fSavedState->ref();
781 if (kReset_ASRInit == init) {
782 // calls the default cons
783 fTempState.init();
784 } else {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000785 SkASSERT(kPreserve_ASRInit == init);
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000786 // calls the copy cons
787 fTempState.set(*fSavedState);
bsalomon@google.com137f1342013-05-29 21:27:53 +0000788 if (!fTempState.get()->setIdentityViewMatrix()) {
789 // let go of any resources held by the temp
790 fTempState.get()->reset();
791 fDrawTarget = NULL;
792 fSavedState->unref();
793 fSavedState = NULL;
794 return false;
795 }
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000796 }
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000797 target->setDrawState(fTempState.get());
bsalomon@google.com137f1342013-05-29 21:27:53 +0000798 return true;
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000799}
bsalomon@google.com7ac249b2011-06-14 18:46:24 +0000800
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000801////////////////////////////////////////////////////////////////////////////////
bsalomon@google.com7ac249b2011-06-14 18:46:24 +0000802
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000803GrDrawTarget::AutoReleaseGeometry::AutoReleaseGeometry(
804 GrDrawTarget* target,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000805 int vertexCount,
806 int indexCount) {
807 fTarget = NULL;
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000808 this->set(target, vertexCount, indexCount);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000809}
rmistry@google.comd6176b02012-08-23 18:14:13 +0000810
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000811GrDrawTarget::AutoReleaseGeometry::AutoReleaseGeometry() {
812 fTarget = NULL;
813}
814
815GrDrawTarget::AutoReleaseGeometry::~AutoReleaseGeometry() {
816 this->reset();
817}
818
819bool GrDrawTarget::AutoReleaseGeometry::set(GrDrawTarget* target,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000820 int vertexCount,
821 int indexCount) {
822 this->reset();
823 fTarget = target;
824 bool success = true;
825 if (NULL != fTarget) {
826 fTarget = target;
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000827 success = target->reserveVertexAndIndexSpace(vertexCount,
bsalomon@google.come3d70952012-03-13 12:40:53 +0000828 indexCount,
829 &fVertices,
830 &fIndices);
831 if (!success) {
832 fTarget = NULL;
833 this->reset();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000834 }
835 }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000836 SkASSERT(success == (NULL != fTarget));
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000837 return success;
838}
839
840void GrDrawTarget::AutoReleaseGeometry::reset() {
841 if (NULL != fTarget) {
842 if (NULL != fVertices) {
843 fTarget->resetVertexSource();
844 }
845 if (NULL != fIndices) {
846 fTarget->resetIndexSource();
847 }
848 fTarget = NULL;
849 }
bsalomon@google.comcb0c5ab2011-06-29 17:48:17 +0000850 fVertices = NULL;
851 fIndices = NULL;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000852}
853
bsalomon@google.com8d67c072012-12-13 20:38:14 +0000854GrDrawTarget::AutoClipRestore::AutoClipRestore(GrDrawTarget* target, const SkIRect& newClip) {
855 fTarget = target;
856 fClip = fTarget->getClip();
857 fStack.init();
858 fStack.get()->clipDevRect(newClip, SkRegion::kReplace_Op);
859 fReplacementClip.fClipStack = fStack.get();
860 target->setClip(&fReplacementClip);
861}
862
bsalomon@google.com116ad842013-04-09 15:38:19 +0000863namespace {
864// returns true if the read/written rect intersects the src/dst and false if not.
865bool clip_srcrect_and_dstpoint(const GrSurface* dst,
866 const GrSurface* src,
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000867 const SkIRect& srcRect,
bsalomon@google.com116ad842013-04-09 15:38:19 +0000868 const SkIPoint& dstPoint,
869 SkIRect* clippedSrcRect,
870 SkIPoint* clippedDstPoint) {
871 *clippedSrcRect = srcRect;
872 *clippedDstPoint = dstPoint;
skia.committer@gmail.coma9493a32013-04-04 07:01:12 +0000873
bsalomon@google.com116ad842013-04-09 15:38:19 +0000874 // clip the left edge to src and dst bounds, adjusting dstPoint if necessary
875 if (clippedSrcRect->fLeft < 0) {
876 clippedDstPoint->fX -= clippedSrcRect->fLeft;
877 clippedSrcRect->fLeft = 0;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000878 }
bsalomon@google.com116ad842013-04-09 15:38:19 +0000879 if (clippedDstPoint->fX < 0) {
880 clippedSrcRect->fLeft -= clippedDstPoint->fX;
881 clippedDstPoint->fX = 0;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000882 }
883
bsalomon@google.com116ad842013-04-09 15:38:19 +0000884 // clip the top edge to src and dst bounds, adjusting dstPoint if necessary
885 if (clippedSrcRect->fTop < 0) {
886 clippedDstPoint->fY -= clippedSrcRect->fTop;
887 clippedSrcRect->fTop = 0;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000888 }
bsalomon@google.com116ad842013-04-09 15:38:19 +0000889 if (clippedDstPoint->fY < 0) {
890 clippedSrcRect->fTop -= clippedDstPoint->fY;
891 clippedDstPoint->fY = 0;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000892 }
skia.committer@gmail.coma9493a32013-04-04 07:01:12 +0000893
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000894 // clip the right edge to the src and dst bounds.
bsalomon@google.com116ad842013-04-09 15:38:19 +0000895 if (clippedSrcRect->fRight > src->width()) {
896 clippedSrcRect->fRight = src->width();
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000897 }
bsalomon@google.com116ad842013-04-09 15:38:19 +0000898 if (clippedDstPoint->fX + clippedSrcRect->width() > dst->width()) {
899 clippedSrcRect->fRight = clippedSrcRect->fLeft + dst->width() - clippedDstPoint->fX;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000900 }
901
902 // clip the bottom edge to the src and dst bounds.
bsalomon@google.com116ad842013-04-09 15:38:19 +0000903 if (clippedSrcRect->fBottom > src->height()) {
904 clippedSrcRect->fBottom = src->height();
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000905 }
bsalomon@google.com116ad842013-04-09 15:38:19 +0000906 if (clippedDstPoint->fY + clippedSrcRect->height() > dst->height()) {
907 clippedSrcRect->fBottom = clippedSrcRect->fTop + dst->height() - clippedDstPoint->fY;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000908 }
skia.committer@gmail.coma9493a32013-04-04 07:01:12 +0000909
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000910 // The above clipping steps may have inverted the rect if it didn't intersect either the src or
911 // dst bounds.
bsalomon@google.com116ad842013-04-09 15:38:19 +0000912 return !clippedSrcRect->isEmpty();
913}
914}
915
916bool GrDrawTarget::copySurface(GrSurface* dst,
917 GrSurface* src,
918 const SkIRect& srcRect,
919 const SkIPoint& dstPoint) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000920 SkASSERT(NULL != dst);
921 SkASSERT(NULL != src);
bsalomon@google.com116ad842013-04-09 15:38:19 +0000922
923 SkIRect clippedSrcRect;
924 SkIPoint clippedDstPoint;
925 // If the rect is outside the src or dst then we've already succeeded.
926 if (!clip_srcrect_and_dstpoint(dst,
927 src,
928 srcRect,
929 dstPoint,
930 &clippedSrcRect,
931 &clippedDstPoint)) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000932 SkASSERT(this->canCopySurface(dst, src, srcRect, dstPoint));
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000933 return true;
934 }
935
936 bool result = this->onCopySurface(dst, src, clippedSrcRect, clippedDstPoint);
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000937 SkASSERT(result == this->canCopySurface(dst, src, clippedSrcRect, clippedDstPoint));
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000938 return result;
939}
940
941bool GrDrawTarget::canCopySurface(GrSurface* dst,
942 GrSurface* src,
943 const SkIRect& srcRect,
944 const SkIPoint& dstPoint) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000945 SkASSERT(NULL != dst);
946 SkASSERT(NULL != src);
bsalomon@google.com116ad842013-04-09 15:38:19 +0000947
948 SkIRect clippedSrcRect;
949 SkIPoint clippedDstPoint;
950 // If the rect is outside the src or dst then we're guaranteed success
951 if (!clip_srcrect_and_dstpoint(dst,
952 src,
953 srcRect,
954 dstPoint,
955 &clippedSrcRect,
956 &clippedDstPoint)) {
957 return true;
958 }
959 return this->onCanCopySurface(dst, src, clippedSrcRect, clippedDstPoint);
960}
961
962bool GrDrawTarget::onCanCopySurface(GrSurface* dst,
963 GrSurface* src,
964 const SkIRect& srcRect,
965 const SkIPoint& dstPoint) {
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000966 // Check that the read/write rects are contained within the src/dst bounds.
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000967 SkASSERT(!srcRect.isEmpty());
968 SkASSERT(SkIRect::MakeWH(src->width(), src->height()).contains(srcRect));
969 SkASSERT(dstPoint.fX >= 0 && dstPoint.fY >= 0);
970 SkASSERT(dstPoint.fX + srcRect.width() <= dst->width() &&
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000971 dstPoint.fY + srcRect.height() <= dst->height());
972
bsalomon@google.com116ad842013-04-09 15:38:19 +0000973 return !dst->isSameAs(src) && NULL != dst->asRenderTarget() && NULL != src->asTexture();
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000974}
975
976bool GrDrawTarget::onCopySurface(GrSurface* dst,
977 GrSurface* src,
978 const SkIRect& srcRect,
979 const SkIPoint& dstPoint) {
bsalomon@google.com116ad842013-04-09 15:38:19 +0000980 if (!GrDrawTarget::onCanCopySurface(dst, src, srcRect, dstPoint)) {
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000981 return false;
982 }
983
984 GrRenderTarget* rt = dst->asRenderTarget();
985 GrTexture* tex = src->asTexture();
986
987 GrDrawTarget::AutoStateRestore asr(this, kReset_ASRInit);
988 this->drawState()->setRenderTarget(rt);
989 SkMatrix matrix;
990 matrix.setTranslate(SkIntToScalar(srcRect.fLeft - dstPoint.fX),
991 SkIntToScalar(srcRect.fTop - dstPoint.fY));
992 matrix.postIDiv(tex->width(), tex->height());
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000993 this->drawState()->addColorTextureEffect(tex, matrix);
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000994 SkIRect dstRect = SkIRect::MakeXYWH(dstPoint.fX,
995 dstPoint.fY,
996 srcRect.width(),
997 srcRect.height());
998 this->drawSimpleRect(dstRect);
999 return true;
1000}
1001
bsalomon@google.comeb851172013-04-15 13:51:00 +00001002void GrDrawTarget::initCopySurfaceDstDesc(const GrSurface* src, GrTextureDesc* desc) {
1003 // Make the dst of the copy be a render target because the default copySurface draws to the dst.
1004 desc->fOrigin = kDefault_GrSurfaceOrigin;
1005 desc->fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit;
1006 desc->fConfig = src->config();
1007}
1008
bsalomon@google.combcce8922013-03-25 15:38:39 +00001009///////////////////////////////////////////////////////////////////////////////
1010
bsalomon@google.comc26d94f2013-03-25 18:19:00 +00001011void GrDrawTargetCaps::reset() {
commit-bot@chromium.org47442312013-12-19 16:18:01 +00001012 fMipMapSupport = false;
bsalomon@google.combcce8922013-03-25 15:38:39 +00001013 fNPOTTextureTileSupport = false;
1014 fTwoSidedStencilSupport = false;
1015 fStencilWrapOpsSupport = false;
1016 fHWAALineSupport = false;
1017 fShaderDerivativeSupport = false;
1018 fGeometryShaderSupport = false;
skia.committer@gmail.come60ed082013-03-26 07:01:04 +00001019 fDualSourceBlendingSupport = false;
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +00001020 fPathRenderingSupport = false;
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +00001021 fDstReadInShaderSupport = false;
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +00001022 fDiscardRenderTargetSupport = false;
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +00001023 fReuseScratchTextures = true;
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +00001024 fGpuTracingSupport = false;
krajcevski78697812014-07-30 11:25:44 -07001025 fCompressedTexSubImageSupport = false;
bsalomon@google.combcce8922013-03-25 15:38:39 +00001026
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001027 fMapBufferFlags = kNone_MapFlags;
1028
bsalomon@google.combcce8922013-03-25 15:38:39 +00001029 fMaxRenderTargetSize = 0;
1030 fMaxTextureSize = 0;
1031 fMaxSampleCount = 0;
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001032
1033 memset(fConfigRenderSupport, 0, sizeof(fConfigRenderSupport));
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001034 memset(fConfigTextureSupport, 0, sizeof(fConfigTextureSupport));
bsalomon@google.combcce8922013-03-25 15:38:39 +00001035}
1036
bsalomon@google.comc26d94f2013-03-25 18:19:00 +00001037GrDrawTargetCaps& GrDrawTargetCaps::operator=(const GrDrawTargetCaps& other) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +00001038 fMipMapSupport = other.fMipMapSupport;
bsalomon@google.combcce8922013-03-25 15:38:39 +00001039 fNPOTTextureTileSupport = other.fNPOTTextureTileSupport;
1040 fTwoSidedStencilSupport = other.fTwoSidedStencilSupport;
1041 fStencilWrapOpsSupport = other.fStencilWrapOpsSupport;
1042 fHWAALineSupport = other.fHWAALineSupport;
1043 fShaderDerivativeSupport = other.fShaderDerivativeSupport;
1044 fGeometryShaderSupport = other.fGeometryShaderSupport;
1045 fDualSourceBlendingSupport = other.fDualSourceBlendingSupport;
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +00001046 fPathRenderingSupport = other.fPathRenderingSupport;
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +00001047 fDstReadInShaderSupport = other.fDstReadInShaderSupport;
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +00001048 fDiscardRenderTargetSupport = other.fDiscardRenderTargetSupport;
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +00001049 fReuseScratchTextures = other.fReuseScratchTextures;
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +00001050 fGpuTracingSupport = other.fGpuTracingSupport;
krajcevski78697812014-07-30 11:25:44 -07001051 fCompressedTexSubImageSupport = other.fCompressedTexSubImageSupport;
bsalomon@google.combcce8922013-03-25 15:38:39 +00001052
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001053 fMapBufferFlags = other.fMapBufferFlags;
1054
bsalomon@google.combcce8922013-03-25 15:38:39 +00001055 fMaxRenderTargetSize = other.fMaxRenderTargetSize;
1056 fMaxTextureSize = other.fMaxTextureSize;
1057 fMaxSampleCount = other.fMaxSampleCount;
1058
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001059 memcpy(fConfigRenderSupport, other.fConfigRenderSupport, sizeof(fConfigRenderSupport));
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001060 memcpy(fConfigTextureSupport, other.fConfigTextureSupport, sizeof(fConfigTextureSupport));
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001061
bsalomon@google.combcce8922013-03-25 15:38:39 +00001062 return *this;
1063}
1064
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001065static SkString map_flags_to_string(uint32_t flags) {
1066 SkString str;
1067 if (GrDrawTargetCaps::kNone_MapFlags == flags) {
1068 str = "none";
1069 } else {
1070 SkASSERT(GrDrawTargetCaps::kCanMap_MapFlag & flags);
1071 SkDEBUGCODE(flags &= ~GrDrawTargetCaps::kCanMap_MapFlag);
1072 str = "can_map";
1073
1074 if (GrDrawTargetCaps::kSubset_MapFlag & flags) {
1075 str.append(" partial");
1076 } else {
1077 str.append(" full");
1078 }
1079 SkDEBUGCODE(flags &= ~GrDrawTargetCaps::kSubset_MapFlag);
1080 }
1081 SkASSERT(0 == flags); // Make sure we handled all the flags.
1082 return str;
1083}
1084
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001085SkString GrDrawTargetCaps::dump() const {
1086 SkString r;
bsalomon@google.com18c9c192011-09-22 21:01:31 +00001087 static const char* gNY[] = {"NO", "YES"};
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +00001088 r.appendf("MIP Map Support : %s\n", gNY[fMipMapSupport]);
1089 r.appendf("NPOT Texture Tile Support : %s\n", gNY[fNPOTTextureTileSupport]);
1090 r.appendf("Two Sided Stencil Support : %s\n", gNY[fTwoSidedStencilSupport]);
1091 r.appendf("Stencil Wrap Ops Support : %s\n", gNY[fStencilWrapOpsSupport]);
1092 r.appendf("HW AA Lines Support : %s\n", gNY[fHWAALineSupport]);
1093 r.appendf("Shader Derivative Support : %s\n", gNY[fShaderDerivativeSupport]);
1094 r.appendf("Geometry Shader Support : %s\n", gNY[fGeometryShaderSupport]);
1095 r.appendf("Dual Source Blending Support : %s\n", gNY[fDualSourceBlendingSupport]);
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +00001096 r.appendf("Path Rendering Support : %s\n", gNY[fPathRenderingSupport]);
1097 r.appendf("Dst Read In Shader Support : %s\n", gNY[fDstReadInShaderSupport]);
1098 r.appendf("Discard Render Target Support: %s\n", gNY[fDiscardRenderTargetSupport]);
1099 r.appendf("Reuse Scratch Textures : %s\n", gNY[fReuseScratchTextures]);
1100 r.appendf("Gpu Tracing Support : %s\n", gNY[fGpuTracingSupport]);
krajcevski78697812014-07-30 11:25:44 -07001101 r.appendf("Compressed Update Support : %s\n", gNY[fCompressedTexSubImageSupport]);
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +00001102 r.appendf("Max Texture Size : %d\n", fMaxTextureSize);
1103 r.appendf("Max Render Target Size : %d\n", fMaxRenderTargetSize);
1104 r.appendf("Max Sample Count : %d\n", fMaxSampleCount);
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001105
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001106 r.appendf("Map Buffer Support : %s\n", map_flags_to_string(fMapBufferFlags).c_str());
1107
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001108 static const char* kConfigNames[] = {
1109 "Unknown", // kUnknown_GrPixelConfig
1110 "Alpha8", // kAlpha_8_GrPixelConfig,
1111 "Index8", // kIndex_8_GrPixelConfig,
1112 "RGB565", // kRGB_565_GrPixelConfig,
1113 "RGBA444", // kRGBA_4444_GrPixelConfig,
1114 "RGBA8888", // kRGBA_8888_GrPixelConfig,
1115 "BGRA8888", // kBGRA_8888_GrPixelConfig,
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001116 "ETC1", // kETC1_GrPixelConfig,
1117 "LATC", // kLATC_GrPixelConfig,
krajcevski238b4562014-06-30 09:09:22 -07001118 "R11EAC", // kR11_EAC_GrPixelConfig,
krajcevski7ef21622014-07-16 15:21:13 -07001119 "ASTC12x12",// kASTC_12x12_GrPixelConfig,
joshualittee5da552014-07-16 13:32:56 -07001120 "RGBAFloat", // kRGBA_float_GrPixelConfig
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001121 };
krajcevski7ef21622014-07-16 15:21:13 -07001122 GR_STATIC_ASSERT(0 == kUnknown_GrPixelConfig);
1123 GR_STATIC_ASSERT(1 == kAlpha_8_GrPixelConfig);
1124 GR_STATIC_ASSERT(2 == kIndex_8_GrPixelConfig);
1125 GR_STATIC_ASSERT(3 == kRGB_565_GrPixelConfig);
1126 GR_STATIC_ASSERT(4 == kRGBA_4444_GrPixelConfig);
1127 GR_STATIC_ASSERT(5 == kRGBA_8888_GrPixelConfig);
1128 GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig);
1129 GR_STATIC_ASSERT(7 == kETC1_GrPixelConfig);
1130 GR_STATIC_ASSERT(8 == kLATC_GrPixelConfig);
1131 GR_STATIC_ASSERT(9 == kR11_EAC_GrPixelConfig);
1132 GR_STATIC_ASSERT(10 == kASTC_12x12_GrPixelConfig);
1133 GR_STATIC_ASSERT(11 == kRGBA_float_GrPixelConfig);
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001134 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kConfigNames) == kGrPixelConfigCnt);
1135
commit-bot@chromium.org99017272013-11-08 18:45:27 +00001136 SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][0]);
1137 SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][1]);
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001138
1139 for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) {
1140 r.appendf("%s is renderable: %s, with MSAA: %s\n",
1141 kConfigNames[i],
1142 gNY[fConfigRenderSupport[i][0]],
1143 gNY[fConfigRenderSupport[i][1]]);
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001144 }
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +00001145
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001146 SkASSERT(!fConfigTextureSupport[kUnknown_GrPixelConfig]);
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +00001147
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001148 for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) {
1149 r.appendf("%s is uploadable to a texture: %s\n",
1150 kConfigNames[i],
1151 gNY[fConfigTextureSupport[i]]);
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +00001152 }
1153
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001154 return r;
bsalomon@google.com18c9c192011-09-22 21:01:31 +00001155}