blob: 191194eb509904ee623d95888b58e8acf0dcc0d5 [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"
bsalomon62c447d2014-08-08 08:08:50 -070016#include "GrTemplates.h"
bsalomon@google.com86afc2a2011-02-16 16:12:19 +000017#include "GrTexture.h"
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000018#include "GrVertexBuffer.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000019
sugoi@google.com5f74cf82012-12-17 21:16:45 +000020#include "SkStrokeRec.h"
sugoi@google.com12b4e272012-12-06 20:13:11 +000021
reed@google.comac10a2d2010-12-22 21:39:39 +000022////////////////////////////////////////////////////////////////////////////////
23
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000024GrDrawTarget::DrawInfo& GrDrawTarget::DrawInfo::operator =(const DrawInfo& di) {
25 fPrimitiveType = di.fPrimitiveType;
26 fStartVertex = di.fStartVertex;
27 fStartIndex = di.fStartIndex;
28 fVertexCount = di.fVertexCount;
29 fIndexCount = di.fIndexCount;
30
31 fInstanceCount = di.fInstanceCount;
32 fVerticesPerInstance = di.fVerticesPerInstance;
33 fIndicesPerInstance = di.fIndicesPerInstance;
34
35 if (NULL != di.fDevBounds) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000036 SkASSERT(di.fDevBounds == &di.fDevBoundsStorage);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000037 fDevBoundsStorage = di.fDevBoundsStorage;
38 fDevBounds = &fDevBoundsStorage;
39 } else {
40 fDevBounds = NULL;
41 }
bsalomon@google.com26e18b52013-03-29 19:22:36 +000042
43 fDstCopy = di.fDstCopy;
44
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000045 return *this;
46}
47
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +000048#ifdef SK_DEBUG
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000049bool GrDrawTarget::DrawInfo::isInstanced() const {
50 if (fInstanceCount > 0) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000051 SkASSERT(0 == fIndexCount % fIndicesPerInstance);
52 SkASSERT(0 == fVertexCount % fVerticesPerInstance);
53 SkASSERT(fIndexCount / fIndicesPerInstance == fInstanceCount);
54 SkASSERT(fVertexCount / fVerticesPerInstance == fInstanceCount);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000055 // there is no way to specify a non-zero start index to drawIndexedInstances().
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000056 SkASSERT(0 == fStartIndex);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000057 return true;
58 } else {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000059 SkASSERT(!fVerticesPerInstance);
60 SkASSERT(!fIndicesPerInstance);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000061 return false;
62 }
63}
64#endif
65
66void GrDrawTarget::DrawInfo::adjustInstanceCount(int instanceOffset) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000067 SkASSERT(this->isInstanced());
68 SkASSERT(instanceOffset + fInstanceCount >= 0);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000069 fInstanceCount += instanceOffset;
70 fVertexCount = fVerticesPerInstance * fInstanceCount;
71 fIndexCount = fIndicesPerInstance * fInstanceCount;
72}
73
74void GrDrawTarget::DrawInfo::adjustStartVertex(int vertexOffset) {
75 fStartVertex += vertexOffset;
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000076 SkASSERT(fStartVertex >= 0);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000077}
78
79void GrDrawTarget::DrawInfo::adjustStartIndex(int indexOffset) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000080 SkASSERT(this->isIndexed());
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000081 fStartIndex += indexOffset;
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000082 SkASSERT(fStartIndex >= 0);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000083}
84
85////////////////////////////////////////////////////////////////////////////////
86
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000087#define DEBUG_INVAL_BUFFER 0xdeadcafe
88#define DEBUG_INVAL_START_IDX -1
89
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000090GrDrawTarget::GrDrawTarget(GrContext* context)
91 : fClip(NULL)
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +000092 , fContext(context)
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +000093 , fGpuTraceMarkerCount(0) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000094 SkASSERT(NULL != context);
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000095
bsalomon@google.coma5d056a2012-03-27 15:59:58 +000096 fDrawState = &fDefaultDrawState;
97 // We assume that fDrawState always owns a ref to the object it points at.
98 fDefaultDrawState.ref();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000099 GeometrySrcState& geoSrc = fGeoSrcStateStack.push_back();
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000100#ifdef SK_DEBUG
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000101 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.comac10a2d2010-12-22 21:39:39 +0000105#endif
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000106 geoSrc.fVertexSrc = kNone_GeometrySrcType;
107 geoSrc.fIndexSrc = kNone_GeometrySrcType;
108}
109
110GrDrawTarget::~GrDrawTarget() {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000111 SkASSERT(1 == fGeoSrcStateStack.count());
humper@google.com0e515772013-01-07 19:54:40 +0000112 SkDEBUGCODE(GeometrySrcState& geoSrc = fGeoSrcStateStack.back());
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000113 SkASSERT(kNone_GeometrySrcType == geoSrc.fIndexSrc);
114 SkASSERT(kNone_GeometrySrcType == geoSrc.fVertexSrc);
bsalomon@google.coma5d056a2012-03-27 15:59:58 +0000115 fDrawState->unref();
bsalomon@google.com4a018bb2011-10-28 19:50:21 +0000116}
117
118void GrDrawTarget::releaseGeometry() {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000119 int popCnt = fGeoSrcStateStack.count() - 1;
120 while (popCnt) {
121 this->popGeometrySource();
122 --popCnt;
123 }
bsalomon@google.com4a018bb2011-10-28 19:50:21 +0000124 this->resetVertexSource();
125 this->resetIndexSource();
reed@google.comac10a2d2010-12-22 21:39:39 +0000126}
127
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000128void GrDrawTarget::setClip(const GrClipData* clip) {
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000129 clipWillBeSet(clip);
reed@google.comac10a2d2010-12-22 21:39:39 +0000130 fClip = clip;
131}
132
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000133const GrClipData* GrDrawTarget::getClip() const {
reed@google.comac10a2d2010-12-22 21:39:39 +0000134 return fClip;
135}
136
bsalomon@google.coma5d056a2012-03-27 15:59:58 +0000137void GrDrawTarget::setDrawState(GrDrawState* drawState) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000138 SkASSERT(NULL != fDrawState);
bsalomon@google.coma5d056a2012-03-27 15:59:58 +0000139 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.comb75b0a02013-02-05 20:33:30 +0000149bool GrDrawTarget::reserveVertexSpace(size_t vertexSize,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000150 int vertexCount,
151 void** vertices) {
152 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
153 bool acquired = false;
154 if (vertexCount > 0) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000155 SkASSERT(NULL != vertices);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000156 this->releasePreviousVertexSource();
157 geoSrc.fVertexSrc = kNone_GeometrySrcType;
reed@google.comac10a2d2010-12-22 21:39:39 +0000158
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000159 acquired = this->onReserveVertexSpace(vertexSize,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000160 vertexCount,
161 vertices);
reed@google.comac10a2d2010-12-22 21:39:39 +0000162 }
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000163 if (acquired) {
164 geoSrc.fVertexSrc = kReserved_GeometrySrcType;
165 geoSrc.fVertexCount = vertexCount;
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000166 geoSrc.fVertexSize = vertexSize;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000167 } else if (NULL != vertices) {
168 *vertices = NULL;
169 }
170 return acquired;
171}
172
173bool GrDrawTarget::reserveIndexSpace(int indexCount,
174 void** indices) {
175 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
176 bool acquired = false;
177 if (indexCount > 0) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000178 SkASSERT(NULL != indices);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000179 this->releasePreviousIndexSource();
180 geoSrc.fIndexSrc = kNone_GeometrySrcType;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000181
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000182 acquired = this->onReserveIndexSpace(indexCount, indices);
183 }
184 if (acquired) {
185 geoSrc.fIndexSrc = kReserved_GeometrySrcType;
186 geoSrc.fIndexCount = indexCount;
187 } else if (NULL != indices) {
188 *indices = NULL;
189 }
190 return acquired;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000191
reed@google.comac10a2d2010-12-22 21:39:39 +0000192}
193
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000194bool GrDrawTarget::reserveVertexAndIndexSpace(int vertexCount,
bsalomon@google.come3d70952012-03-13 12:40:53 +0000195 int indexCount,
196 void** vertices,
197 void** indices) {
egdaniel7b3d5ee2014-08-28 05:41:14 -0700198 size_t vertexStride = this->drawState()->getVertexStride();
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000199 this->willReserveVertexAndIndexSpace(vertexCount, indexCount);
bsalomon@google.come3d70952012-03-13 12:40:53 +0000200 if (vertexCount) {
egdaniel7b3d5ee2014-08-28 05:41:14 -0700201 if (!this->reserveVertexSpace(vertexStride, vertexCount, vertices)) {
bsalomon@google.come3d70952012-03-13 12:40:53 +0000202 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.comb75b0a02013-02-05 20:33:30 +0000219bool GrDrawTarget::geometryHints(int32_t* vertexCount,
reed@google.comac10a2d2010-12-22 21:39:39 +0000220 int32_t* indexCount) const {
reed@google.comac10a2d2010-12-22 21:39:39 +0000221 if (NULL != vertexCount) {
222 *vertexCount = -1;
223 }
224 if (NULL != indexCount) {
225 *indexCount = -1;
226 }
227 return false;
228}
229
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000230void GrDrawTarget::releasePreviousVertexSource() {
231 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
232 switch (geoSrc.fVertexSrc) {
233 case kNone_GeometrySrcType:
234 break;
235 case kArray_GeometrySrcType:
236 this->releaseVertexArray();
237 break;
238 case kReserved_GeometrySrcType:
239 this->releaseReservedVertexSpace();
240 break;
241 case kBuffer_GeometrySrcType:
242 geoSrc.fVertexBuffer->unref();
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000243#ifdef SK_DEBUG
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000244 geoSrc.fVertexBuffer = (GrVertexBuffer*)DEBUG_INVAL_BUFFER;
245#endif
246 break;
247 default:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000248 SkFAIL("Unknown Vertex Source Type.");
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000249 break;
250 }
251}
252
253void GrDrawTarget::releasePreviousIndexSource() {
254 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
255 switch (geoSrc.fIndexSrc) {
256 case kNone_GeometrySrcType: // these two don't require
257 break;
258 case kArray_GeometrySrcType:
259 this->releaseIndexArray();
260 break;
261 case kReserved_GeometrySrcType:
262 this->releaseReservedIndexSpace();
263 break;
264 case kBuffer_GeometrySrcType:
265 geoSrc.fIndexBuffer->unref();
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000266#ifdef SK_DEBUG
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000267 geoSrc.fIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER;
268#endif
269 break;
270 default:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000271 SkFAIL("Unknown Index Source Type.");
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000272 break;
273 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000274}
275
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000276void GrDrawTarget::setVertexSourceToArray(const void* vertexArray,
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000277 int vertexCount) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000278 this->releasePreviousVertexSource();
279 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
280 geoSrc.fVertexSrc = kArray_GeometrySrcType;
egdaniel7b3d5ee2014-08-28 05:41:14 -0700281 geoSrc.fVertexSize = this->drawState()->getVertexStride();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000282 geoSrc.fVertexCount = vertexCount;
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000283 this->onSetVertexSourceToArray(vertexArray, vertexCount);
reed@google.comac10a2d2010-12-22 21:39:39 +0000284}
285
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000286void GrDrawTarget::setIndexSourceToArray(const void* indexArray,
287 int indexCount) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000288 this->releasePreviousIndexSource();
289 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
290 geoSrc.fIndexSrc = kArray_GeometrySrcType;
291 geoSrc.fIndexCount = indexCount;
bsalomon@google.combcdbbe62011-04-12 15:40:00 +0000292 this->onSetIndexSourceToArray(indexArray, indexCount);
reed@google.comac10a2d2010-12-22 21:39:39 +0000293}
294
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000295void GrDrawTarget::setVertexSourceToBuffer(const GrVertexBuffer* buffer) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000296 this->releasePreviousVertexSource();
297 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
298 geoSrc.fVertexSrc = kBuffer_GeometrySrcType;
299 geoSrc.fVertexBuffer = buffer;
300 buffer->ref();
egdaniel7b3d5ee2014-08-28 05:41:14 -0700301 geoSrc.fVertexSize = this->drawState()->getVertexStride();
reed@google.comac10a2d2010-12-22 21:39:39 +0000302}
303
304void GrDrawTarget::setIndexSourceToBuffer(const GrIndexBuffer* buffer) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000305 this->releasePreviousIndexSource();
306 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
307 geoSrc.fIndexSrc = kBuffer_GeometrySrcType;
308 geoSrc.fIndexBuffer = buffer;
309 buffer->ref();
reed@google.comac10a2d2010-12-22 21:39:39 +0000310}
311
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000312void GrDrawTarget::resetVertexSource() {
313 this->releasePreviousVertexSource();
314 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
315 geoSrc.fVertexSrc = kNone_GeometrySrcType;
316}
317
318void GrDrawTarget::resetIndexSource() {
319 this->releasePreviousIndexSource();
320 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
321 geoSrc.fIndexSrc = kNone_GeometrySrcType;
322}
323
324void GrDrawTarget::pushGeometrySource() {
325 this->geometrySourceWillPush();
326 GeometrySrcState& newState = fGeoSrcStateStack.push_back();
327 newState.fIndexSrc = kNone_GeometrySrcType;
328 newState.fVertexSrc = kNone_GeometrySrcType;
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000329#ifdef SK_DEBUG
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000330 newState.fVertexCount = ~0;
331 newState.fVertexBuffer = (GrVertexBuffer*)~0;
332 newState.fIndexCount = ~0;
333 newState.fIndexBuffer = (GrIndexBuffer*)~0;
334#endif
335}
336
337void GrDrawTarget::popGeometrySource() {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000338 // if popping last element then pops are unbalanced with pushes
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000339 SkASSERT(fGeoSrcStateStack.count() > 1);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000340
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000341 this->geometrySourceWillPop(fGeoSrcStateStack.fromBack(1));
342 this->releasePreviousVertexSource();
343 this->releasePreviousIndexSource();
344 fGeoSrcStateStack.pop_back();
345}
346
347////////////////////////////////////////////////////////////////////////////////
348
bsalomon@google.come8262622011-11-07 02:30:51 +0000349bool GrDrawTarget::checkDraw(GrPrimitiveType type, int startVertex,
350 int startIndex, int vertexCount,
351 int indexCount) const {
bsalomon@google.comcddaf342012-07-30 13:09:05 +0000352 const GrDrawState& drawState = this->getDrawState();
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000353#ifdef SK_DEBUG
bsalomon@google.come8262622011-11-07 02:30:51 +0000354 const GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000355 int maxVertex = startVertex + vertexCount;
356 int maxValidVertex;
357 switch (geoSrc.fVertexSrc) {
358 case kNone_GeometrySrcType:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000359 SkFAIL("Attempting to draw without vertex src.");
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000360 case kReserved_GeometrySrcType: // fallthrough
361 case kArray_GeometrySrcType:
362 maxValidVertex = geoSrc.fVertexCount;
363 break;
364 case kBuffer_GeometrySrcType:
commit-bot@chromium.org089a7802014-05-02 21:38:22 +0000365 maxValidVertex = static_cast<int>(geoSrc.fVertexBuffer->gpuMemorySize() / geoSrc.fVertexSize);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000366 break;
367 }
368 if (maxVertex > maxValidVertex) {
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000369 SkFAIL("Drawing outside valid vertex range.");
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000370 }
bsalomon@google.come8262622011-11-07 02:30:51 +0000371 if (indexCount > 0) {
372 int maxIndex = startIndex + indexCount;
373 int maxValidIndex;
374 switch (geoSrc.fIndexSrc) {
375 case kNone_GeometrySrcType:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000376 SkFAIL("Attempting to draw indexed geom without index src.");
bsalomon@google.come8262622011-11-07 02:30:51 +0000377 case kReserved_GeometrySrcType: // fallthrough
378 case kArray_GeometrySrcType:
379 maxValidIndex = geoSrc.fIndexCount;
380 break;
381 case kBuffer_GeometrySrcType:
commit-bot@chromium.org089a7802014-05-02 21:38:22 +0000382 maxValidIndex = static_cast<int>(geoSrc.fIndexBuffer->gpuMemorySize() / sizeof(uint16_t));
bsalomon@google.come8262622011-11-07 02:30:51 +0000383 break;
384 }
385 if (maxIndex > maxValidIndex) {
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000386 SkFAIL("Index reads outside valid index range.");
bsalomon@google.come8262622011-11-07 02:30:51 +0000387 }
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000388 }
bsalomon@google.comb4725b42012-03-30 17:24:17 +0000389
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000390 SkASSERT(NULL != drawState.getRenderTarget());
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000391
joshualittbd769d02014-09-04 08:56:46 -0700392 if (drawState.hasGeometryProcessor()) {
393 const GrEffect* effect = drawState.getGeometryProcessor()->getEffect();
394 int numTextures = effect->numTextures();
395 for (int t = 0; t < numTextures; ++t) {
396 GrTexture* texture = effect->texture(t);
397 SkASSERT(texture->asRenderTarget() != drawState.getRenderTarget());
398 }
399 }
400
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000401 for (int s = 0; s < drawState.numColorStages(); ++s) {
bsalomonf99f8842014-07-07 11:54:23 -0700402 const GrEffect* effect = drawState.getColorStage(s).getEffect();
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000403 int numTextures = effect->numTextures();
404 for (int t = 0; t < numTextures; ++t) {
405 GrTexture* texture = effect->texture(t);
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000406 SkASSERT(texture->asRenderTarget() != drawState.getRenderTarget());
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000407 }
408 }
409 for (int s = 0; s < drawState.numCoverageStages(); ++s) {
bsalomonf99f8842014-07-07 11:54:23 -0700410 const GrEffect* effect = drawState.getCoverageStage(s).getEffect();
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000411 int numTextures = effect->numTextures();
412 for (int t = 0; t < numTextures; ++t) {
413 GrTexture* texture = effect->texture(t);
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000414 SkASSERT(texture->asRenderTarget() != drawState.getRenderTarget());
bsalomon@google.comb4725b42012-03-30 17:24:17 +0000415 }
416 }
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000417
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000418 SkASSERT(drawState.validateVertexAttribs());
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000419#endif
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000420 if (NULL == drawState.getRenderTarget()) {
bsalomon@google.com0ba52fc2011-11-10 22:16:06 +0000421 return false;
422 }
bsalomon@google.come8262622011-11-07 02:30:51 +0000423 return true;
424}
425
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000426bool GrDrawTarget::setupDstReadIfNecessary(GrDeviceCoordTexture* dstCopy, const SkRect* drawBounds) {
bsalomon@google.comb5158812013-05-13 18:50:25 +0000427 if (this->caps()->dstReadInShaderSupport() || !this->getDrawState().willEffectReadDstColor()) {
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000428 return true;
429 }
430 GrRenderTarget* rt = this->drawState()->getRenderTarget();
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000431 SkIRect copyRect;
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000432 const GrClipData* clip = this->getClip();
433 clip->getConservativeBounds(rt, &copyRect);
434
435 if (NULL != drawBounds) {
436 SkIRect drawIBounds;
437 drawBounds->roundOut(&drawIBounds);
commit-bot@chromium.orgbb5c4652013-04-01 12:49:31 +0000438 if (!copyRect.intersect(drawIBounds)) {
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000439#ifdef SK_DEBUG
commit-bot@chromium.orgbb5c4652013-04-01 12:49:31 +0000440 GrPrintf("Missed an early reject. Bailing on draw from setupDstReadIfNecessary.\n");
441#endif
442 return false;
443 }
444 } else {
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000445#ifdef SK_DEBUG
commit-bot@chromium.orgbb5c4652013-04-01 12:49:31 +0000446 //GrPrintf("No dev bounds when dst copy is made.\n");
447#endif
448 }
skia.committer@gmail.com05a2ee02013-04-02 07:01:34 +0000449
commit-bot@chromium.org63150af2013-04-11 22:00:22 +0000450 // MSAA consideration: When there is support for reading MSAA samples in the shader we could
451 // have per-sample dst values by making the copy multisampled.
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000452 GrTextureDesc desc;
bsalomon@google.comeb851172013-04-15 13:51:00 +0000453 this->initCopySurfaceDstDesc(rt, &desc);
commit-bot@chromium.orgbb5c4652013-04-01 12:49:31 +0000454 desc.fWidth = copyRect.width();
455 desc.fHeight = copyRect.height();
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000456
457 GrAutoScratchTexture ast(fContext, desc, GrContext::kApprox_ScratchTexMatch);
458
459 if (NULL == ast.texture()) {
460 GrPrintf("Failed to create temporary copy of destination texture.\n");
461 return false;
462 }
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000463 SkIPoint dstPoint = {0, 0};
464 if (this->copySurface(ast.texture(), rt, copyRect, dstPoint)) {
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000465 dstCopy->setTexture(ast.texture());
466 dstCopy->setOffset(copyRect.fLeft, copyRect.fTop);
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000467 return true;
468 } else {
469 return false;
470 }
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000471}
472
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000473void GrDrawTarget::drawIndexed(GrPrimitiveType type,
474 int startVertex,
475 int startIndex,
476 int vertexCount,
477 int indexCount,
478 const SkRect* devBounds) {
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000479 if (indexCount > 0 && this->checkDraw(type, startVertex, startIndex, vertexCount, indexCount)) {
480 DrawInfo info;
481 info.fPrimitiveType = type;
482 info.fStartVertex = startVertex;
483 info.fStartIndex = startIndex;
484 info.fVertexCount = vertexCount;
485 info.fIndexCount = indexCount;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000486
487 info.fInstanceCount = 0;
488 info.fVerticesPerInstance = 0;
489 info.fIndicesPerInstance = 0;
490
491 if (NULL != devBounds) {
492 info.setDevBounds(*devBounds);
493 }
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000494 // TODO: We should continue with incorrect blending.
495 if (!this->setupDstReadIfNecessary(&info)) {
496 return;
497 }
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000498 this->onDraw(info);
bsalomon@google.com82145872011-08-23 14:32:40 +0000499 }
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000500}
501
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000502void GrDrawTarget::drawNonIndexed(GrPrimitiveType type,
503 int startVertex,
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000504 int vertexCount,
505 const SkRect* devBounds) {
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000506 if (vertexCount > 0 && this->checkDraw(type, startVertex, -1, vertexCount, -1)) {
507 DrawInfo info;
508 info.fPrimitiveType = type;
509 info.fStartVertex = startVertex;
510 info.fStartIndex = 0;
511 info.fVertexCount = vertexCount;
512 info.fIndexCount = 0;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000513
514 info.fInstanceCount = 0;
515 info.fVerticesPerInstance = 0;
516 info.fIndicesPerInstance = 0;
517
518 if (NULL != devBounds) {
519 info.setDevBounds(*devBounds);
520 }
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000521 // TODO: We should continue with incorrect blending.
522 if (!this->setupDstReadIfNecessary(&info)) {
523 return;
524 }
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000525 this->onDraw(info);
bsalomon@google.com82145872011-08-23 14:32:40 +0000526 }
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000527}
528
commit-bot@chromium.org32184d82013-10-09 15:14:18 +0000529void GrDrawTarget::stencilPath(const GrPath* path, SkPath::FillType fill) {
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000530 // TODO: extract portions of checkDraw that are relevant to path stenciling.
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000531 SkASSERT(NULL != path);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000532 SkASSERT(this->caps()->pathRenderingSupport());
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000533 SkASSERT(!SkPath::IsInverseFillType(fill));
commit-bot@chromium.org32184d82013-10-09 15:14:18 +0000534 this->onStencilPath(path, fill);
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000535}
536
commit-bot@chromium.org32184d82013-10-09 15:14:18 +0000537void GrDrawTarget::drawPath(const GrPath* path, SkPath::FillType fill) {
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000538 // TODO: extract portions of checkDraw that are relevant to path rendering.
539 SkASSERT(NULL != path);
540 SkASSERT(this->caps()->pathRenderingSupport());
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000541 const GrDrawState* drawState = &getDrawState();
542
543 SkRect devBounds;
544 if (SkPath::IsInverseFillType(fill)) {
545 devBounds = SkRect::MakeWH(SkIntToScalar(drawState->getRenderTarget()->width()),
546 SkIntToScalar(drawState->getRenderTarget()->height()));
547 } else {
548 devBounds = path->getBounds();
549 }
550 SkMatrix viewM = drawState->getViewMatrix();
551 viewM.mapRect(&devBounds);
552
553 GrDeviceCoordTexture dstCopy;
554 if (!this->setupDstReadIfNecessary(&dstCopy, &devBounds)) {
555 return;
556 }
557
commit-bot@chromium.org32184d82013-10-09 15:14:18 +0000558 this->onDrawPath(path, fill, dstCopy.texture() ? &dstCopy : NULL);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000559}
560
cdaltonb85a0aa2014-07-21 15:32:44 -0700561void GrDrawTarget::drawPaths(const GrPathRange* pathRange,
562 const uint32_t indices[], int count,
563 const float transforms[], PathTransformType transformsType,
564 SkPath::FillType fill) {
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000565 SkASSERT(this->caps()->pathRenderingSupport());
cdaltonb85a0aa2014-07-21 15:32:44 -0700566 SkASSERT(NULL != pathRange);
567 SkASSERT(NULL != indices);
568 SkASSERT(NULL != transforms);
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000569
cdaltonb85a0aa2014-07-21 15:32:44 -0700570 // Don't compute a bounding box for setupDstReadIfNecessary(), we'll opt
571 // instead for it to just copy the entire dst. Realistically this is a moot
572 // point, because any context that supports NV_path_rendering will also
573 // support NV_blend_equation_advanced.
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000574 GrDeviceCoordTexture dstCopy;
cdaltonb85a0aa2014-07-21 15:32:44 -0700575 if (!this->setupDstReadIfNecessary(&dstCopy, NULL)) {
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000576 return;
577 }
578
cdaltonb85a0aa2014-07-21 15:32:44 -0700579 this->onDrawPaths(pathRange, indices, count, transforms, transformsType, fill,
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000580 dstCopy.texture() ? &dstCopy : NULL);
581}
582
egdaniel3eee3832014-06-18 13:09:11 -0700583typedef GrTraceMarkerSet::Iter TMIter;
584void GrDrawTarget::saveActiveTraceMarkers() {
585 if (this->caps()->gpuTracingSupport()) {
586 SkASSERT(0 == fStoredTraceMarkers.count());
587 fStoredTraceMarkers.addSet(fActiveTraceMarkers);
588 for (TMIter iter = fStoredTraceMarkers.begin(); iter != fStoredTraceMarkers.end(); ++iter) {
589 this->removeGpuTraceMarker(&(*iter));
590 }
591 }
592}
593
594void GrDrawTarget::restoreActiveTraceMarkers() {
595 if (this->caps()->gpuTracingSupport()) {
596 SkASSERT(0 == fActiveTraceMarkers.count());
597 for (TMIter iter = fStoredTraceMarkers.begin(); iter != fStoredTraceMarkers.end(); ++iter) {
598 this->addGpuTraceMarker(&(*iter));
599 }
600 for (TMIter iter = fActiveTraceMarkers.begin(); iter != fActiveTraceMarkers.end(); ++iter) {
601 this->fStoredTraceMarkers.remove(*iter);
602 }
603 }
604}
605
606void GrDrawTarget::addGpuTraceMarker(const GrGpuTraceMarker* marker) {
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000607 if (this->caps()->gpuTracingSupport()) {
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000608 SkASSERT(fGpuTraceMarkerCount >= 0);
609 this->fActiveTraceMarkers.add(*marker);
610 this->didAddGpuTraceMarker();
611 ++fGpuTraceMarkerCount;
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000612 }
613}
614
egdaniel3eee3832014-06-18 13:09:11 -0700615void GrDrawTarget::removeGpuTraceMarker(const GrGpuTraceMarker* marker) {
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000616 if (this->caps()->gpuTracingSupport()) {
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000617 SkASSERT(fGpuTraceMarkerCount >= 1);
618 this->fActiveTraceMarkers.remove(*marker);
619 this->didRemoveGpuTraceMarker();
620 --fGpuTraceMarkerCount;
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000621 }
622}
623
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000624////////////////////////////////////////////////////////////////////////////////
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000625
bsalomon@google.com934c5702012-03-20 21:17:58 +0000626void GrDrawTarget::drawIndexedInstances(GrPrimitiveType type,
627 int instanceCount,
628 int verticesPerInstance,
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000629 int indicesPerInstance,
630 const SkRect* devBounds) {
bsalomon@google.com934c5702012-03-20 21:17:58 +0000631 if (!verticesPerInstance || !indicesPerInstance) {
632 return;
633 }
634
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000635 int maxInstancesPerDraw = this->indexCountInCurrentSource() / indicesPerInstance;
636 if (!maxInstancesPerDraw) {
bsalomon@google.com934c5702012-03-20 21:17:58 +0000637 return;
638 }
639
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000640 DrawInfo info;
641 info.fPrimitiveType = type;
642 info.fStartIndex = 0;
643 info.fStartVertex = 0;
644 info.fIndicesPerInstance = indicesPerInstance;
645 info.fVerticesPerInstance = verticesPerInstance;
646
647 // Set the same bounds for all the draws.
648 if (NULL != devBounds) {
649 info.setDevBounds(*devBounds);
650 }
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000651 // TODO: We should continue with incorrect blending.
652 if (!this->setupDstReadIfNecessary(&info)) {
653 return;
654 }
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000655
bsalomon@google.com934c5702012-03-20 21:17:58 +0000656 while (instanceCount) {
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000657 info.fInstanceCount = SkTMin(instanceCount, maxInstancesPerDraw);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000658 info.fVertexCount = info.fInstanceCount * verticesPerInstance;
659 info.fIndexCount = info.fInstanceCount * indicesPerInstance;
660
661 if (this->checkDraw(type,
662 info.fStartVertex,
663 info.fStartIndex,
664 info.fVertexCount,
665 info.fIndexCount)) {
666 this->onDraw(info);
667 }
668 info.fStartVertex += info.fVertexCount;
669 instanceCount -= info.fInstanceCount;
bsalomon@google.com934c5702012-03-20 21:17:58 +0000670 }
671}
bsalomon@google.com3d0835b2011-12-08 16:12:03 +0000672
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000673////////////////////////////////////////////////////////////////////////////////
674
robertphillips@google.com42903302013-04-20 12:26:07 +0000675namespace {
676
677// position + (optional) texture coord
678extern const GrVertexAttrib gBWRectPosUVAttribs[] = {
679 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding},
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000680 {kVec2f_GrVertexAttribType, sizeof(SkPoint), kLocalCoord_GrVertexAttribBinding}
robertphillips@google.com42903302013-04-20 12:26:07 +0000681};
682
683void set_vertex_attributes(GrDrawState* drawState, bool hasUVs) {
684 if (hasUVs) {
egdaniel7b3d5ee2014-08-28 05:41:14 -0700685 drawState->setVertexAttribs<gBWRectPosUVAttribs>(2, 2 * sizeof(SkPoint));
robertphillips@google.com42903302013-04-20 12:26:07 +0000686 } else {
egdaniel7b3d5ee2014-08-28 05:41:14 -0700687 drawState->setVertexAttribs<gBWRectPosUVAttribs>(1, sizeof(SkPoint));
robertphillips@google.com42903302013-04-20 12:26:07 +0000688 }
689}
690
691};
692
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000693void GrDrawTarget::onDrawRect(const SkRect& rect,
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
robertphillips@google.com42903302013-04-20 12:26:07 +0000697 set_vertex_attributes(this->drawState(), NULL != localRect);
698
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000699 AutoReleaseGeometry geo(this, 4, 0);
bsalomon@google.com6513cd02011-08-05 20:12:30 +0000700 if (!geo.succeeded()) {
701 GrPrintf("Failed to get space for vertices!\n");
702 return;
703 }
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000704
egdaniel7b3d5ee2014-08-28 05:41:14 -0700705 size_t vstride = this->drawState()->getVertexStride();
706 geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, vstride);
bsalomon@google.comc7818882013-03-20 19:19:53 +0000707 if (NULL != localRect) {
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000708 SkPoint* coords = GrTCast<SkPoint*>(GrTCast<intptr_t>(geo.vertices()) +
709 sizeof(SkPoint));
bsalomon@google.comc7818882013-03-20 19:19:53 +0000710 coords->setRectFan(localRect->fLeft, localRect->fTop,
711 localRect->fRight, localRect->fBottom,
egdaniel7b3d5ee2014-08-28 05:41:14 -0700712 vstride);
bsalomon@google.comc7818882013-03-20 19:19:53 +0000713 if (NULL != localMatrix) {
egdaniel7b3d5ee2014-08-28 05:41:14 -0700714 localMatrix->mapPointsWithStride(coords, vstride, 4);
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000715 }
716 }
commit-bot@chromium.org3ae0e6c2014-02-11 18:24:25 +0000717 SkRect bounds;
718 this->getDrawState().getViewMatrix().mapRect(&bounds, rect);
robertphillips@google.com8b129aa2012-10-05 15:37:00 +0000719
commit-bot@chromium.org3ae0e6c2014-02-11 18:24:25 +0000720 this->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4, &bounds);
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000721}
722
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000723void GrDrawTarget::clipWillBeSet(const GrClipData* clipData) {
724}
725
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000726////////////////////////////////////////////////////////////////////////////////
bsalomon@google.com7ac249b2011-06-14 18:46:24 +0000727
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000728GrDrawTarget::AutoStateRestore::AutoStateRestore() {
729 fDrawTarget = NULL;
730}
reed@google.comac10a2d2010-12-22 21:39:39 +0000731
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000732GrDrawTarget::AutoStateRestore::AutoStateRestore(GrDrawTarget* target,
bsalomon@google.com137f1342013-05-29 21:27:53 +0000733 ASRInit init,
734 const SkMatrix* vm) {
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000735 fDrawTarget = NULL;
bsalomon@google.com137f1342013-05-29 21:27:53 +0000736 this->set(target, init, vm);
reed@google.comac10a2d2010-12-22 21:39:39 +0000737}
738
739GrDrawTarget::AutoStateRestore::~AutoStateRestore() {
bsalomon@google.com7d34d2e2011-01-24 17:41:47 +0000740 if (NULL != fDrawTarget) {
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000741 fDrawTarget->setDrawState(fSavedState);
742 fSavedState->unref();
bsalomon@google.com7d34d2e2011-01-24 17:41:47 +0000743 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000744}
bsalomon@google.com7d34d2e2011-01-24 17:41:47 +0000745
bsalomon@google.com137f1342013-05-29 21:27:53 +0000746void GrDrawTarget::AutoStateRestore::set(GrDrawTarget* target, ASRInit init, const SkMatrix* vm) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000747 SkASSERT(NULL == fDrawTarget);
bsalomon@google.com137f1342013-05-29 21:27:53 +0000748 fDrawTarget = target;
749 fSavedState = target->drawState();
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000750 SkASSERT(fSavedState);
bsalomon@google.com137f1342013-05-29 21:27:53 +0000751 fSavedState->ref();
752 if (kReset_ASRInit == init) {
753 if (NULL == vm) {
754 // calls the default cons
755 fTempState.init();
756 } else {
757 SkNEW_IN_TLAZY(&fTempState, GrDrawState, (*vm));
758 }
759 } else {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000760 SkASSERT(kPreserve_ASRInit == init);
bsalomon@google.com137f1342013-05-29 21:27:53 +0000761 if (NULL == vm) {
762 fTempState.set(*fSavedState);
763 } else {
764 SkNEW_IN_TLAZY(&fTempState, GrDrawState, (*fSavedState, *vm));
765 }
766 }
767 target->setDrawState(fTempState.get());
768}
769
770bool GrDrawTarget::AutoStateRestore::setIdentity(GrDrawTarget* target, ASRInit init) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000771 SkASSERT(NULL == fDrawTarget);
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000772 fDrawTarget = target;
773 fSavedState = target->drawState();
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000774 SkASSERT(fSavedState);
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000775 fSavedState->ref();
776 if (kReset_ASRInit == init) {
777 // calls the default cons
778 fTempState.init();
779 } else {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000780 SkASSERT(kPreserve_ASRInit == init);
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000781 // calls the copy cons
782 fTempState.set(*fSavedState);
bsalomon@google.com137f1342013-05-29 21:27:53 +0000783 if (!fTempState.get()->setIdentityViewMatrix()) {
784 // let go of any resources held by the temp
785 fTempState.get()->reset();
786 fDrawTarget = NULL;
787 fSavedState->unref();
788 fSavedState = NULL;
789 return false;
790 }
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000791 }
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000792 target->setDrawState(fTempState.get());
bsalomon@google.com137f1342013-05-29 21:27:53 +0000793 return true;
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000794}
bsalomon@google.com7ac249b2011-06-14 18:46:24 +0000795
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000796////////////////////////////////////////////////////////////////////////////////
bsalomon@google.com7ac249b2011-06-14 18:46:24 +0000797
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000798GrDrawTarget::AutoReleaseGeometry::AutoReleaseGeometry(
799 GrDrawTarget* target,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000800 int vertexCount,
801 int indexCount) {
802 fTarget = NULL;
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000803 this->set(target, vertexCount, indexCount);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000804}
rmistry@google.comd6176b02012-08-23 18:14:13 +0000805
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000806GrDrawTarget::AutoReleaseGeometry::AutoReleaseGeometry() {
807 fTarget = NULL;
808}
809
810GrDrawTarget::AutoReleaseGeometry::~AutoReleaseGeometry() {
811 this->reset();
812}
813
814bool GrDrawTarget::AutoReleaseGeometry::set(GrDrawTarget* target,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000815 int vertexCount,
816 int indexCount) {
817 this->reset();
818 fTarget = target;
819 bool success = true;
820 if (NULL != fTarget) {
821 fTarget = target;
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000822 success = target->reserveVertexAndIndexSpace(vertexCount,
bsalomon@google.come3d70952012-03-13 12:40:53 +0000823 indexCount,
824 &fVertices,
825 &fIndices);
826 if (!success) {
827 fTarget = NULL;
828 this->reset();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000829 }
830 }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000831 SkASSERT(success == (NULL != fTarget));
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000832 return success;
833}
834
835void GrDrawTarget::AutoReleaseGeometry::reset() {
836 if (NULL != fTarget) {
837 if (NULL != fVertices) {
838 fTarget->resetVertexSource();
839 }
840 if (NULL != fIndices) {
841 fTarget->resetIndexSource();
842 }
843 fTarget = NULL;
844 }
bsalomon@google.comcb0c5ab2011-06-29 17:48:17 +0000845 fVertices = NULL;
846 fIndices = NULL;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000847}
848
bsalomon@google.com8d67c072012-12-13 20:38:14 +0000849GrDrawTarget::AutoClipRestore::AutoClipRestore(GrDrawTarget* target, const SkIRect& newClip) {
850 fTarget = target;
851 fClip = fTarget->getClip();
852 fStack.init();
853 fStack.get()->clipDevRect(newClip, SkRegion::kReplace_Op);
854 fReplacementClip.fClipStack = fStack.get();
855 target->setClip(&fReplacementClip);
856}
857
bsalomon@google.com116ad842013-04-09 15:38:19 +0000858namespace {
859// returns true if the read/written rect intersects the src/dst and false if not.
860bool clip_srcrect_and_dstpoint(const GrSurface* dst,
861 const GrSurface* src,
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000862 const SkIRect& srcRect,
bsalomon@google.com116ad842013-04-09 15:38:19 +0000863 const SkIPoint& dstPoint,
864 SkIRect* clippedSrcRect,
865 SkIPoint* clippedDstPoint) {
866 *clippedSrcRect = srcRect;
867 *clippedDstPoint = dstPoint;
skia.committer@gmail.coma9493a32013-04-04 07:01:12 +0000868
bsalomon@google.com116ad842013-04-09 15:38:19 +0000869 // clip the left edge to src and dst bounds, adjusting dstPoint if necessary
870 if (clippedSrcRect->fLeft < 0) {
871 clippedDstPoint->fX -= clippedSrcRect->fLeft;
872 clippedSrcRect->fLeft = 0;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000873 }
bsalomon@google.com116ad842013-04-09 15:38:19 +0000874 if (clippedDstPoint->fX < 0) {
875 clippedSrcRect->fLeft -= clippedDstPoint->fX;
876 clippedDstPoint->fX = 0;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000877 }
878
bsalomon@google.com116ad842013-04-09 15:38:19 +0000879 // clip the top edge to src and dst bounds, adjusting dstPoint if necessary
880 if (clippedSrcRect->fTop < 0) {
881 clippedDstPoint->fY -= clippedSrcRect->fTop;
882 clippedSrcRect->fTop = 0;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000883 }
bsalomon@google.com116ad842013-04-09 15:38:19 +0000884 if (clippedDstPoint->fY < 0) {
885 clippedSrcRect->fTop -= clippedDstPoint->fY;
886 clippedDstPoint->fY = 0;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000887 }
skia.committer@gmail.coma9493a32013-04-04 07:01:12 +0000888
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000889 // clip the right edge to the src and dst bounds.
bsalomon@google.com116ad842013-04-09 15:38:19 +0000890 if (clippedSrcRect->fRight > src->width()) {
891 clippedSrcRect->fRight = src->width();
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000892 }
bsalomon@google.com116ad842013-04-09 15:38:19 +0000893 if (clippedDstPoint->fX + clippedSrcRect->width() > dst->width()) {
894 clippedSrcRect->fRight = clippedSrcRect->fLeft + dst->width() - clippedDstPoint->fX;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000895 }
896
897 // clip the bottom edge to the src and dst bounds.
bsalomon@google.com116ad842013-04-09 15:38:19 +0000898 if (clippedSrcRect->fBottom > src->height()) {
899 clippedSrcRect->fBottom = src->height();
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000900 }
bsalomon@google.com116ad842013-04-09 15:38:19 +0000901 if (clippedDstPoint->fY + clippedSrcRect->height() > dst->height()) {
902 clippedSrcRect->fBottom = clippedSrcRect->fTop + dst->height() - clippedDstPoint->fY;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000903 }
skia.committer@gmail.coma9493a32013-04-04 07:01:12 +0000904
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000905 // The above clipping steps may have inverted the rect if it didn't intersect either the src or
906 // dst bounds.
bsalomon@google.com116ad842013-04-09 15:38:19 +0000907 return !clippedSrcRect->isEmpty();
908}
909}
910
911bool GrDrawTarget::copySurface(GrSurface* dst,
912 GrSurface* src,
913 const SkIRect& srcRect,
914 const SkIPoint& dstPoint) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000915 SkASSERT(NULL != dst);
916 SkASSERT(NULL != src);
bsalomon@google.com116ad842013-04-09 15:38:19 +0000917
918 SkIRect clippedSrcRect;
919 SkIPoint clippedDstPoint;
920 // If the rect is outside the src or dst then we've already succeeded.
921 if (!clip_srcrect_and_dstpoint(dst,
922 src,
923 srcRect,
924 dstPoint,
925 &clippedSrcRect,
926 &clippedDstPoint)) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000927 SkASSERT(this->canCopySurface(dst, src, srcRect, dstPoint));
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000928 return true;
929 }
930
931 bool result = this->onCopySurface(dst, src, clippedSrcRect, clippedDstPoint);
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000932 SkASSERT(result == this->canCopySurface(dst, src, clippedSrcRect, clippedDstPoint));
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000933 return result;
934}
935
936bool GrDrawTarget::canCopySurface(GrSurface* dst,
937 GrSurface* src,
938 const SkIRect& srcRect,
939 const SkIPoint& dstPoint) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000940 SkASSERT(NULL != dst);
941 SkASSERT(NULL != src);
bsalomon@google.com116ad842013-04-09 15:38:19 +0000942
943 SkIRect clippedSrcRect;
944 SkIPoint clippedDstPoint;
945 // If the rect is outside the src or dst then we're guaranteed success
946 if (!clip_srcrect_and_dstpoint(dst,
947 src,
948 srcRect,
949 dstPoint,
950 &clippedSrcRect,
951 &clippedDstPoint)) {
952 return true;
953 }
954 return this->onCanCopySurface(dst, src, clippedSrcRect, clippedDstPoint);
955}
956
957bool GrDrawTarget::onCanCopySurface(GrSurface* dst,
958 GrSurface* src,
959 const SkIRect& srcRect,
960 const SkIPoint& dstPoint) {
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000961 // Check that the read/write rects are contained within the src/dst bounds.
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000962 SkASSERT(!srcRect.isEmpty());
963 SkASSERT(SkIRect::MakeWH(src->width(), src->height()).contains(srcRect));
964 SkASSERT(dstPoint.fX >= 0 && dstPoint.fY >= 0);
965 SkASSERT(dstPoint.fX + srcRect.width() <= dst->width() &&
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000966 dstPoint.fY + srcRect.height() <= dst->height());
967
bsalomon@google.com116ad842013-04-09 15:38:19 +0000968 return !dst->isSameAs(src) && NULL != dst->asRenderTarget() && NULL != src->asTexture();
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000969}
970
971bool GrDrawTarget::onCopySurface(GrSurface* dst,
972 GrSurface* src,
973 const SkIRect& srcRect,
974 const SkIPoint& dstPoint) {
bsalomon@google.com116ad842013-04-09 15:38:19 +0000975 if (!GrDrawTarget::onCanCopySurface(dst, src, srcRect, dstPoint)) {
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000976 return false;
977 }
978
979 GrRenderTarget* rt = dst->asRenderTarget();
980 GrTexture* tex = src->asTexture();
981
982 GrDrawTarget::AutoStateRestore asr(this, kReset_ASRInit);
983 this->drawState()->setRenderTarget(rt);
984 SkMatrix matrix;
985 matrix.setTranslate(SkIntToScalar(srcRect.fLeft - dstPoint.fX),
986 SkIntToScalar(srcRect.fTop - dstPoint.fY));
987 matrix.postIDiv(tex->width(), tex->height());
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000988 this->drawState()->addColorTextureEffect(tex, matrix);
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000989 SkIRect dstRect = SkIRect::MakeXYWH(dstPoint.fX,
990 dstPoint.fY,
991 srcRect.width(),
992 srcRect.height());
993 this->drawSimpleRect(dstRect);
994 return true;
995}
996
bsalomon@google.comeb851172013-04-15 13:51:00 +0000997void GrDrawTarget::initCopySurfaceDstDesc(const GrSurface* src, GrTextureDesc* desc) {
998 // Make the dst of the copy be a render target because the default copySurface draws to the dst.
999 desc->fOrigin = kDefault_GrSurfaceOrigin;
1000 desc->fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit;
1001 desc->fConfig = src->config();
1002}
1003
bsalomon@google.combcce8922013-03-25 15:38:39 +00001004///////////////////////////////////////////////////////////////////////////////
1005
bsalomon@google.comc26d94f2013-03-25 18:19:00 +00001006void GrDrawTargetCaps::reset() {
commit-bot@chromium.org47442312013-12-19 16:18:01 +00001007 fMipMapSupport = false;
bsalomon@google.combcce8922013-03-25 15:38:39 +00001008 fNPOTTextureTileSupport = false;
1009 fTwoSidedStencilSupport = false;
1010 fStencilWrapOpsSupport = false;
1011 fHWAALineSupport = false;
1012 fShaderDerivativeSupport = false;
1013 fGeometryShaderSupport = false;
skia.committer@gmail.come60ed082013-03-26 07:01:04 +00001014 fDualSourceBlendingSupport = false;
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +00001015 fPathRenderingSupport = false;
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +00001016 fDstReadInShaderSupport = false;
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +00001017 fDiscardRenderTargetSupport = false;
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +00001018 fReuseScratchTextures = true;
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +00001019 fGpuTracingSupport = false;
krajcevski78697812014-07-30 11:25:44 -07001020 fCompressedTexSubImageSupport = false;
bsalomon@google.combcce8922013-03-25 15:38:39 +00001021
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001022 fMapBufferFlags = kNone_MapFlags;
1023
bsalomon@google.combcce8922013-03-25 15:38:39 +00001024 fMaxRenderTargetSize = 0;
1025 fMaxTextureSize = 0;
1026 fMaxSampleCount = 0;
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001027
1028 memset(fConfigRenderSupport, 0, sizeof(fConfigRenderSupport));
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001029 memset(fConfigTextureSupport, 0, sizeof(fConfigTextureSupport));
bsalomon@google.combcce8922013-03-25 15:38:39 +00001030}
1031
bsalomon@google.comc26d94f2013-03-25 18:19:00 +00001032GrDrawTargetCaps& GrDrawTargetCaps::operator=(const GrDrawTargetCaps& other) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +00001033 fMipMapSupport = other.fMipMapSupport;
bsalomon@google.combcce8922013-03-25 15:38:39 +00001034 fNPOTTextureTileSupport = other.fNPOTTextureTileSupport;
1035 fTwoSidedStencilSupport = other.fTwoSidedStencilSupport;
1036 fStencilWrapOpsSupport = other.fStencilWrapOpsSupport;
1037 fHWAALineSupport = other.fHWAALineSupport;
1038 fShaderDerivativeSupport = other.fShaderDerivativeSupport;
1039 fGeometryShaderSupport = other.fGeometryShaderSupport;
1040 fDualSourceBlendingSupport = other.fDualSourceBlendingSupport;
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +00001041 fPathRenderingSupport = other.fPathRenderingSupport;
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +00001042 fDstReadInShaderSupport = other.fDstReadInShaderSupport;
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +00001043 fDiscardRenderTargetSupport = other.fDiscardRenderTargetSupport;
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +00001044 fReuseScratchTextures = other.fReuseScratchTextures;
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +00001045 fGpuTracingSupport = other.fGpuTracingSupport;
krajcevski78697812014-07-30 11:25:44 -07001046 fCompressedTexSubImageSupport = other.fCompressedTexSubImageSupport;
bsalomon@google.combcce8922013-03-25 15:38:39 +00001047
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001048 fMapBufferFlags = other.fMapBufferFlags;
1049
bsalomon@google.combcce8922013-03-25 15:38:39 +00001050 fMaxRenderTargetSize = other.fMaxRenderTargetSize;
1051 fMaxTextureSize = other.fMaxTextureSize;
1052 fMaxSampleCount = other.fMaxSampleCount;
1053
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001054 memcpy(fConfigRenderSupport, other.fConfigRenderSupport, sizeof(fConfigRenderSupport));
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001055 memcpy(fConfigTextureSupport, other.fConfigTextureSupport, sizeof(fConfigTextureSupport));
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001056
bsalomon@google.combcce8922013-03-25 15:38:39 +00001057 return *this;
1058}
1059
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001060static SkString map_flags_to_string(uint32_t flags) {
1061 SkString str;
1062 if (GrDrawTargetCaps::kNone_MapFlags == flags) {
1063 str = "none";
1064 } else {
1065 SkASSERT(GrDrawTargetCaps::kCanMap_MapFlag & flags);
1066 SkDEBUGCODE(flags &= ~GrDrawTargetCaps::kCanMap_MapFlag);
1067 str = "can_map";
1068
1069 if (GrDrawTargetCaps::kSubset_MapFlag & flags) {
1070 str.append(" partial");
1071 } else {
1072 str.append(" full");
1073 }
1074 SkDEBUGCODE(flags &= ~GrDrawTargetCaps::kSubset_MapFlag);
1075 }
1076 SkASSERT(0 == flags); // Make sure we handled all the flags.
1077 return str;
1078}
1079
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001080SkString GrDrawTargetCaps::dump() const {
1081 SkString r;
bsalomon@google.com18c9c192011-09-22 21:01:31 +00001082 static const char* gNY[] = {"NO", "YES"};
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +00001083 r.appendf("MIP Map Support : %s\n", gNY[fMipMapSupport]);
1084 r.appendf("NPOT Texture Tile Support : %s\n", gNY[fNPOTTextureTileSupport]);
1085 r.appendf("Two Sided Stencil Support : %s\n", gNY[fTwoSidedStencilSupport]);
1086 r.appendf("Stencil Wrap Ops Support : %s\n", gNY[fStencilWrapOpsSupport]);
1087 r.appendf("HW AA Lines Support : %s\n", gNY[fHWAALineSupport]);
1088 r.appendf("Shader Derivative Support : %s\n", gNY[fShaderDerivativeSupport]);
1089 r.appendf("Geometry Shader Support : %s\n", gNY[fGeometryShaderSupport]);
1090 r.appendf("Dual Source Blending Support : %s\n", gNY[fDualSourceBlendingSupport]);
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +00001091 r.appendf("Path Rendering Support : %s\n", gNY[fPathRenderingSupport]);
1092 r.appendf("Dst Read In Shader Support : %s\n", gNY[fDstReadInShaderSupport]);
1093 r.appendf("Discard Render Target Support: %s\n", gNY[fDiscardRenderTargetSupport]);
1094 r.appendf("Reuse Scratch Textures : %s\n", gNY[fReuseScratchTextures]);
1095 r.appendf("Gpu Tracing Support : %s\n", gNY[fGpuTracingSupport]);
krajcevski78697812014-07-30 11:25:44 -07001096 r.appendf("Compressed Update Support : %s\n", gNY[fCompressedTexSubImageSupport]);
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +00001097 r.appendf("Max Texture Size : %d\n", fMaxTextureSize);
1098 r.appendf("Max Render Target Size : %d\n", fMaxRenderTargetSize);
1099 r.appendf("Max Sample Count : %d\n", fMaxSampleCount);
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001100
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001101 r.appendf("Map Buffer Support : %s\n", map_flags_to_string(fMapBufferFlags).c_str());
1102
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001103 static const char* kConfigNames[] = {
1104 "Unknown", // kUnknown_GrPixelConfig
1105 "Alpha8", // kAlpha_8_GrPixelConfig,
1106 "Index8", // kIndex_8_GrPixelConfig,
1107 "RGB565", // kRGB_565_GrPixelConfig,
1108 "RGBA444", // kRGBA_4444_GrPixelConfig,
1109 "RGBA8888", // kRGBA_8888_GrPixelConfig,
1110 "BGRA8888", // kBGRA_8888_GrPixelConfig,
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001111 "ETC1", // kETC1_GrPixelConfig,
1112 "LATC", // kLATC_GrPixelConfig,
krajcevski238b4562014-06-30 09:09:22 -07001113 "R11EAC", // kR11_EAC_GrPixelConfig,
krajcevski7ef21622014-07-16 15:21:13 -07001114 "ASTC12x12",// kASTC_12x12_GrPixelConfig,
joshualittee5da552014-07-16 13:32:56 -07001115 "RGBAFloat", // kRGBA_float_GrPixelConfig
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001116 };
krajcevski7ef21622014-07-16 15:21:13 -07001117 GR_STATIC_ASSERT(0 == kUnknown_GrPixelConfig);
1118 GR_STATIC_ASSERT(1 == kAlpha_8_GrPixelConfig);
1119 GR_STATIC_ASSERT(2 == kIndex_8_GrPixelConfig);
1120 GR_STATIC_ASSERT(3 == kRGB_565_GrPixelConfig);
1121 GR_STATIC_ASSERT(4 == kRGBA_4444_GrPixelConfig);
1122 GR_STATIC_ASSERT(5 == kRGBA_8888_GrPixelConfig);
1123 GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig);
1124 GR_STATIC_ASSERT(7 == kETC1_GrPixelConfig);
1125 GR_STATIC_ASSERT(8 == kLATC_GrPixelConfig);
1126 GR_STATIC_ASSERT(9 == kR11_EAC_GrPixelConfig);
1127 GR_STATIC_ASSERT(10 == kASTC_12x12_GrPixelConfig);
1128 GR_STATIC_ASSERT(11 == kRGBA_float_GrPixelConfig);
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001129 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kConfigNames) == kGrPixelConfigCnt);
1130
commit-bot@chromium.org99017272013-11-08 18:45:27 +00001131 SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][0]);
1132 SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][1]);
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001133
1134 for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) {
1135 r.appendf("%s is renderable: %s, with MSAA: %s\n",
1136 kConfigNames[i],
1137 gNY[fConfigRenderSupport[i][0]],
1138 gNY[fConfigRenderSupport[i][1]]);
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001139 }
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +00001140
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001141 SkASSERT(!fConfigTextureSupport[kUnknown_GrPixelConfig]);
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +00001142
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001143 for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) {
1144 r.appendf("%s is uploadable to a texture: %s\n",
1145 kConfigNames[i],
1146 gNY[fConfigTextureSupport[i]]);
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +00001147 }
1148
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001149 return r;
bsalomon@google.com18c9c192011-09-22 21:01:31 +00001150}