blob: 2f25272e31c356e935bce4e9b9784bcfb061a34f [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"
bsalomonafbf2d62014-09-30 12:18:44 -070016#include "GrSurfacePriv.h"
bsalomon62c447d2014-08-08 08:08:50 -070017#include "GrTemplates.h"
bsalomon@google.com86afc2a2011-02-16 16:12:19 +000018#include "GrTexture.h"
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000019#include "GrVertexBuffer.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000020
sugoi@google.com5f74cf82012-12-17 21:16:45 +000021#include "SkStrokeRec.h"
sugoi@google.com12b4e272012-12-06 20:13:11 +000022
reed@google.comac10a2d2010-12-22 21:39:39 +000023////////////////////////////////////////////////////////////////////////////////
24
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000025GrDrawTarget::DrawInfo& GrDrawTarget::DrawInfo::operator =(const DrawInfo& di) {
26 fPrimitiveType = di.fPrimitiveType;
27 fStartVertex = di.fStartVertex;
28 fStartIndex = di.fStartIndex;
29 fVertexCount = di.fVertexCount;
30 fIndexCount = di.fIndexCount;
31
32 fInstanceCount = di.fInstanceCount;
33 fVerticesPerInstance = di.fVerticesPerInstance;
34 fIndicesPerInstance = di.fIndicesPerInstance;
35
bsalomon49f085d2014-09-05 13:34:00 -070036 if (di.fDevBounds) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000037 SkASSERT(di.fDevBounds == &di.fDevBoundsStorage);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000038 fDevBoundsStorage = di.fDevBoundsStorage;
39 fDevBounds = &fDevBoundsStorage;
40 } else {
41 fDevBounds = NULL;
42 }
bsalomon@google.com26e18b52013-03-29 19:22:36 +000043
44 fDstCopy = di.fDstCopy;
45
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000046 return *this;
47}
48
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +000049#ifdef SK_DEBUG
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000050bool GrDrawTarget::DrawInfo::isInstanced() const {
51 if (fInstanceCount > 0) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000052 SkASSERT(0 == fIndexCount % fIndicesPerInstance);
53 SkASSERT(0 == fVertexCount % fVerticesPerInstance);
54 SkASSERT(fIndexCount / fIndicesPerInstance == fInstanceCount);
55 SkASSERT(fVertexCount / fVerticesPerInstance == fInstanceCount);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000056 // there is no way to specify a non-zero start index to drawIndexedInstances().
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000057 SkASSERT(0 == fStartIndex);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000058 return true;
59 } else {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000060 SkASSERT(!fVerticesPerInstance);
61 SkASSERT(!fIndicesPerInstance);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000062 return false;
63 }
64}
65#endif
66
67void GrDrawTarget::DrawInfo::adjustInstanceCount(int instanceOffset) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000068 SkASSERT(this->isInstanced());
69 SkASSERT(instanceOffset + fInstanceCount >= 0);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000070 fInstanceCount += instanceOffset;
71 fVertexCount = fVerticesPerInstance * fInstanceCount;
72 fIndexCount = fIndicesPerInstance * fInstanceCount;
73}
74
75void GrDrawTarget::DrawInfo::adjustStartVertex(int vertexOffset) {
76 fStartVertex += vertexOffset;
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000077 SkASSERT(fStartVertex >= 0);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000078}
79
80void GrDrawTarget::DrawInfo::adjustStartIndex(int indexOffset) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000081 SkASSERT(this->isIndexed());
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000082 fStartIndex += indexOffset;
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000083 SkASSERT(fStartIndex >= 0);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000084}
85
86////////////////////////////////////////////////////////////////////////////////
87
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000088#define DEBUG_INVAL_BUFFER 0xdeadcafe
89#define DEBUG_INVAL_START_IDX -1
90
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000091GrDrawTarget::GrDrawTarget(GrContext* context)
92 : fClip(NULL)
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +000093 , fContext(context)
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +000094 , fGpuTraceMarkerCount(0) {
bsalomon49f085d2014-09-05 13:34:00 -070095 SkASSERT(context);
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) {
bsalomon49f085d2014-09-05 13:34:00 -0700138 SkASSERT(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) {
bsalomon49f085d2014-09-05 13:34:00 -0700155 SkASSERT(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;
bsalomon49f085d2014-09-05 13:34:00 -0700167 } else if (vertices) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000168 *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) {
bsalomon49f085d2014-09-05 13:34:00 -0700178 SkASSERT(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;
bsalomon49f085d2014-09-05 13:34:00 -0700187 } else if (indices) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000188 *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 {
bsalomon49f085d2014-09-05 13:34:00 -0700221 if (vertexCount) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000222 *vertexCount = -1;
223 }
bsalomon49f085d2014-09-05 13:34:00 -0700224 if (indexCount) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000225 *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
bsalomon49f085d2014-09-05 13:34:00 -0700390 SkASSERT(drawState.getRenderTarget());
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000391
joshualittbd769d02014-09-04 08:56:46 -0700392 if (drawState.hasGeometryProcessor()) {
joshualitta5305a12014-10-10 17:47:00 -0700393 const GrGeometryProcessor* gp = drawState.getGeometryProcessor();
joshualittb0a8a372014-09-23 09:50:21 -0700394 int numTextures = gp->numTextures();
joshualittbd769d02014-09-04 08:56:46 -0700395 for (int t = 0; t < numTextures; ++t) {
joshualittb0a8a372014-09-23 09:50:21 -0700396 GrTexture* texture = gp->texture(t);
joshualittbd769d02014-09-04 08:56:46 -0700397 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) {
joshualittb0a8a372014-09-23 09:50:21 -0700402 const GrProcessor* effect = drawState.getColorStage(s).getProcessor();
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) {
joshualittb0a8a372014-09-23 09:50:21 -0700410 const GrProcessor* effect = drawState.getCoverageStage(s).getProcessor();
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
bsalomon49f085d2014-09-05 13:34:00 -0700435 if (drawBounds) {
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000436 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
tfarina38406c82014-10-31 07:11:12 -0700440 SkDebugf("Missed an early reject. Bailing on draw from setupDstReadIfNecessary.\n");
commit-bot@chromium.orgbb5c4652013-04-01 12:49:31 +0000441#endif
442 return false;
443 }
444 } else {
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000445#ifdef SK_DEBUG
tfarina38406c82014-10-31 07:11:12 -0700446 //SkDebugf("No dev bounds when dst copy is made.\n");
commit-bot@chromium.orgbb5c4652013-04-01 12:49:31 +0000447#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.
bsalomonf2703d82014-10-28 14:33:06 -0700452 GrSurfaceDesc 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
bsalomone3059732014-10-14 11:47:22 -0700457 SkAutoTUnref<GrTexture> copy(
458 fContext->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch));
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000459
bsalomone3059732014-10-14 11:47:22 -0700460 if (!copy) {
tfarina38406c82014-10-31 07:11:12 -0700461 SkDebugf("Failed to create temporary copy of destination texture.\n");
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000462 return false;
463 }
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000464 SkIPoint dstPoint = {0, 0};
bsalomone3059732014-10-14 11:47:22 -0700465 if (this->copySurface(copy, rt, copyRect, dstPoint)) {
466 dstCopy->setTexture(copy);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000467 dstCopy->setOffset(copyRect.fLeft, copyRect.fTop);
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000468 return true;
469 } else {
470 return false;
471 }
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000472}
473
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000474void GrDrawTarget::drawIndexed(GrPrimitiveType type,
475 int startVertex,
476 int startIndex,
477 int vertexCount,
478 int indexCount,
479 const SkRect* devBounds) {
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000480 if (indexCount > 0 && this->checkDraw(type, startVertex, startIndex, vertexCount, indexCount)) {
481 DrawInfo info;
482 info.fPrimitiveType = type;
483 info.fStartVertex = startVertex;
484 info.fStartIndex = startIndex;
485 info.fVertexCount = vertexCount;
486 info.fIndexCount = indexCount;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000487
488 info.fInstanceCount = 0;
489 info.fVerticesPerInstance = 0;
490 info.fIndicesPerInstance = 0;
491
bsalomon49f085d2014-09-05 13:34:00 -0700492 if (devBounds) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000493 info.setDevBounds(*devBounds);
494 }
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000495 // TODO: We should continue with incorrect blending.
496 if (!this->setupDstReadIfNecessary(&info)) {
497 return;
498 }
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000499 this->onDraw(info);
bsalomon@google.com82145872011-08-23 14:32:40 +0000500 }
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000501}
502
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000503void GrDrawTarget::drawNonIndexed(GrPrimitiveType type,
504 int startVertex,
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000505 int vertexCount,
506 const SkRect* devBounds) {
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000507 if (vertexCount > 0 && this->checkDraw(type, startVertex, -1, vertexCount, -1)) {
508 DrawInfo info;
509 info.fPrimitiveType = type;
510 info.fStartVertex = startVertex;
511 info.fStartIndex = 0;
512 info.fVertexCount = vertexCount;
513 info.fIndexCount = 0;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000514
515 info.fInstanceCount = 0;
516 info.fVerticesPerInstance = 0;
517 info.fIndicesPerInstance = 0;
518
bsalomon49f085d2014-09-05 13:34:00 -0700519 if (devBounds) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000520 info.setDevBounds(*devBounds);
521 }
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000522 // TODO: We should continue with incorrect blending.
523 if (!this->setupDstReadIfNecessary(&info)) {
524 return;
525 }
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000526 this->onDraw(info);
bsalomon@google.com82145872011-08-23 14:32:40 +0000527 }
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000528}
529
joshualitt92e496f2014-10-31 13:56:50 -0700530void GrDrawTarget::stencilPath(const GrPath* path, GrPathRendering::FillType fill) {
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000531 // TODO: extract portions of checkDraw that are relevant to path stenciling.
bsalomon49f085d2014-09-05 13:34:00 -0700532 SkASSERT(path);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000533 SkASSERT(this->caps()->pathRenderingSupport());
commit-bot@chromium.org32184d82013-10-09 15:14:18 +0000534 this->onStencilPath(path, fill);
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000535}
536
joshualitt92e496f2014-10-31 13:56:50 -0700537void GrDrawTarget::drawPath(const GrPath* path, GrPathRendering::FillType fill) {
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000538 // TODO: extract portions of checkDraw that are relevant to path rendering.
bsalomon49f085d2014-09-05 13:34:00 -0700539 SkASSERT(path);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000540 SkASSERT(this->caps()->pathRenderingSupport());
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000541
joshualitt92e496f2014-10-31 13:56:50 -0700542 SkRect devBounds = path->getBounds();
543 SkMatrix viewM = this->drawState()->getViewMatrix();
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000544 viewM.mapRect(&devBounds);
545
546 GrDeviceCoordTexture dstCopy;
547 if (!this->setupDstReadIfNecessary(&dstCopy, &devBounds)) {
548 return;
549 }
550
commit-bot@chromium.org32184d82013-10-09 15:14:18 +0000551 this->onDrawPath(path, fill, dstCopy.texture() ? &dstCopy : NULL);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000552}
553
cdaltonb85a0aa2014-07-21 15:32:44 -0700554void GrDrawTarget::drawPaths(const GrPathRange* pathRange,
555 const uint32_t indices[], int count,
556 const float transforms[], PathTransformType transformsType,
joshualitt92e496f2014-10-31 13:56:50 -0700557 GrPathRendering::FillType fill) {
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000558 SkASSERT(this->caps()->pathRenderingSupport());
bsalomon49f085d2014-09-05 13:34:00 -0700559 SkASSERT(pathRange);
560 SkASSERT(indices);
561 SkASSERT(transforms);
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000562
cdaltonb85a0aa2014-07-21 15:32:44 -0700563 // Don't compute a bounding box for setupDstReadIfNecessary(), we'll opt
564 // instead for it to just copy the entire dst. Realistically this is a moot
565 // point, because any context that supports NV_path_rendering will also
566 // support NV_blend_equation_advanced.
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000567 GrDeviceCoordTexture dstCopy;
cdaltonb85a0aa2014-07-21 15:32:44 -0700568 if (!this->setupDstReadIfNecessary(&dstCopy, NULL)) {
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000569 return;
570 }
571
cdaltonb85a0aa2014-07-21 15:32:44 -0700572 this->onDrawPaths(pathRange, indices, count, transforms, transformsType, fill,
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000573 dstCopy.texture() ? &dstCopy : NULL);
574}
575
egdaniel3eee3832014-06-18 13:09:11 -0700576typedef GrTraceMarkerSet::Iter TMIter;
577void GrDrawTarget::saveActiveTraceMarkers() {
578 if (this->caps()->gpuTracingSupport()) {
579 SkASSERT(0 == fStoredTraceMarkers.count());
580 fStoredTraceMarkers.addSet(fActiveTraceMarkers);
581 for (TMIter iter = fStoredTraceMarkers.begin(); iter != fStoredTraceMarkers.end(); ++iter) {
582 this->removeGpuTraceMarker(&(*iter));
583 }
584 }
585}
586
587void GrDrawTarget::restoreActiveTraceMarkers() {
588 if (this->caps()->gpuTracingSupport()) {
589 SkASSERT(0 == fActiveTraceMarkers.count());
590 for (TMIter iter = fStoredTraceMarkers.begin(); iter != fStoredTraceMarkers.end(); ++iter) {
591 this->addGpuTraceMarker(&(*iter));
592 }
593 for (TMIter iter = fActiveTraceMarkers.begin(); iter != fActiveTraceMarkers.end(); ++iter) {
594 this->fStoredTraceMarkers.remove(*iter);
595 }
596 }
597}
598
599void GrDrawTarget::addGpuTraceMarker(const GrGpuTraceMarker* marker) {
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000600 if (this->caps()->gpuTracingSupport()) {
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000601 SkASSERT(fGpuTraceMarkerCount >= 0);
602 this->fActiveTraceMarkers.add(*marker);
603 this->didAddGpuTraceMarker();
604 ++fGpuTraceMarkerCount;
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000605 }
606}
607
egdaniel3eee3832014-06-18 13:09:11 -0700608void GrDrawTarget::removeGpuTraceMarker(const GrGpuTraceMarker* marker) {
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000609 if (this->caps()->gpuTracingSupport()) {
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000610 SkASSERT(fGpuTraceMarkerCount >= 1);
611 this->fActiveTraceMarkers.remove(*marker);
612 this->didRemoveGpuTraceMarker();
613 --fGpuTraceMarkerCount;
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000614 }
615}
616
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000617////////////////////////////////////////////////////////////////////////////////
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000618
bsalomon@google.com934c5702012-03-20 21:17:58 +0000619void GrDrawTarget::drawIndexedInstances(GrPrimitiveType type,
620 int instanceCount,
621 int verticesPerInstance,
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000622 int indicesPerInstance,
623 const SkRect* devBounds) {
bsalomon@google.com934c5702012-03-20 21:17:58 +0000624 if (!verticesPerInstance || !indicesPerInstance) {
625 return;
626 }
627
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000628 int maxInstancesPerDraw = this->indexCountInCurrentSource() / indicesPerInstance;
629 if (!maxInstancesPerDraw) {
bsalomon@google.com934c5702012-03-20 21:17:58 +0000630 return;
631 }
632
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000633 DrawInfo info;
634 info.fPrimitiveType = type;
635 info.fStartIndex = 0;
636 info.fStartVertex = 0;
637 info.fIndicesPerInstance = indicesPerInstance;
638 info.fVerticesPerInstance = verticesPerInstance;
639
640 // Set the same bounds for all the draws.
bsalomon49f085d2014-09-05 13:34:00 -0700641 if (devBounds) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000642 info.setDevBounds(*devBounds);
643 }
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000644 // TODO: We should continue with incorrect blending.
645 if (!this->setupDstReadIfNecessary(&info)) {
646 return;
647 }
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000648
bsalomon@google.com934c5702012-03-20 21:17:58 +0000649 while (instanceCount) {
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000650 info.fInstanceCount = SkTMin(instanceCount, maxInstancesPerDraw);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000651 info.fVertexCount = info.fInstanceCount * verticesPerInstance;
652 info.fIndexCount = info.fInstanceCount * indicesPerInstance;
653
654 if (this->checkDraw(type,
655 info.fStartVertex,
656 info.fStartIndex,
657 info.fVertexCount,
658 info.fIndexCount)) {
659 this->onDraw(info);
660 }
661 info.fStartVertex += info.fVertexCount;
662 instanceCount -= info.fInstanceCount;
bsalomon@google.com934c5702012-03-20 21:17:58 +0000663 }
664}
bsalomon@google.com3d0835b2011-12-08 16:12:03 +0000665
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000666////////////////////////////////////////////////////////////////////////////////
667
robertphillips@google.com42903302013-04-20 12:26:07 +0000668namespace {
669
670// position + (optional) texture coord
671extern const GrVertexAttrib gBWRectPosUVAttribs[] = {
672 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding},
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000673 {kVec2f_GrVertexAttribType, sizeof(SkPoint), kLocalCoord_GrVertexAttribBinding}
robertphillips@google.com42903302013-04-20 12:26:07 +0000674};
675
676void set_vertex_attributes(GrDrawState* drawState, bool hasUVs) {
677 if (hasUVs) {
egdaniel7b3d5ee2014-08-28 05:41:14 -0700678 drawState->setVertexAttribs<gBWRectPosUVAttribs>(2, 2 * sizeof(SkPoint));
robertphillips@google.com42903302013-04-20 12:26:07 +0000679 } else {
egdaniel7b3d5ee2014-08-28 05:41:14 -0700680 drawState->setVertexAttribs<gBWRectPosUVAttribs>(1, sizeof(SkPoint));
robertphillips@google.com42903302013-04-20 12:26:07 +0000681 }
682}
683
684};
685
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000686void GrDrawTarget::onDrawRect(const SkRect& rect,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000687 const SkRect* localRect,
bsalomon@google.com0406b9e2013-04-02 21:00:15 +0000688 const SkMatrix* localMatrix) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000689
bsalomon49f085d2014-09-05 13:34:00 -0700690 set_vertex_attributes(this->drawState(), SkToBool(localRect));
robertphillips@google.com42903302013-04-20 12:26:07 +0000691
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000692 AutoReleaseGeometry geo(this, 4, 0);
bsalomon@google.com6513cd02011-08-05 20:12:30 +0000693 if (!geo.succeeded()) {
tfarina38406c82014-10-31 07:11:12 -0700694 SkDebugf("Failed to get space for vertices!\n");
bsalomon@google.com6513cd02011-08-05 20:12:30 +0000695 return;
696 }
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000697
egdaniel7b3d5ee2014-08-28 05:41:14 -0700698 size_t vstride = this->drawState()->getVertexStride();
699 geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, vstride);
bsalomon49f085d2014-09-05 13:34:00 -0700700 if (localRect) {
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000701 SkPoint* coords = GrTCast<SkPoint*>(GrTCast<intptr_t>(geo.vertices()) +
702 sizeof(SkPoint));
bsalomon@google.comc7818882013-03-20 19:19:53 +0000703 coords->setRectFan(localRect->fLeft, localRect->fTop,
704 localRect->fRight, localRect->fBottom,
egdaniel7b3d5ee2014-08-28 05:41:14 -0700705 vstride);
bsalomon49f085d2014-09-05 13:34:00 -0700706 if (localMatrix) {
egdaniel7b3d5ee2014-08-28 05:41:14 -0700707 localMatrix->mapPointsWithStride(coords, vstride, 4);
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000708 }
709 }
commit-bot@chromium.org3ae0e6c2014-02-11 18:24:25 +0000710 SkRect bounds;
711 this->getDrawState().getViewMatrix().mapRect(&bounds, rect);
robertphillips@google.com8b129aa2012-10-05 15:37:00 +0000712
commit-bot@chromium.org3ae0e6c2014-02-11 18:24:25 +0000713 this->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4, &bounds);
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000714}
715
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000716void GrDrawTarget::clipWillBeSet(const GrClipData* clipData) {
717}
718
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000719////////////////////////////////////////////////////////////////////////////////
bsalomon@google.com7ac249b2011-06-14 18:46:24 +0000720
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000721GrDrawTarget::AutoStateRestore::AutoStateRestore() {
722 fDrawTarget = NULL;
723}
reed@google.comac10a2d2010-12-22 21:39:39 +0000724
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000725GrDrawTarget::AutoStateRestore::AutoStateRestore(GrDrawTarget* target,
bsalomon@google.com137f1342013-05-29 21:27:53 +0000726 ASRInit init,
727 const SkMatrix* vm) {
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000728 fDrawTarget = NULL;
bsalomon@google.com137f1342013-05-29 21:27:53 +0000729 this->set(target, init, vm);
reed@google.comac10a2d2010-12-22 21:39:39 +0000730}
731
732GrDrawTarget::AutoStateRestore::~AutoStateRestore() {
bsalomon49f085d2014-09-05 13:34:00 -0700733 if (fDrawTarget) {
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000734 fDrawTarget->setDrawState(fSavedState);
735 fSavedState->unref();
bsalomon@google.com7d34d2e2011-01-24 17:41:47 +0000736 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000737}
bsalomon@google.com7d34d2e2011-01-24 17:41:47 +0000738
bsalomon@google.com137f1342013-05-29 21:27:53 +0000739void GrDrawTarget::AutoStateRestore::set(GrDrawTarget* target, ASRInit init, const SkMatrix* vm) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000740 SkASSERT(NULL == fDrawTarget);
bsalomon@google.com137f1342013-05-29 21:27:53 +0000741 fDrawTarget = target;
742 fSavedState = target->drawState();
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000743 SkASSERT(fSavedState);
bsalomon@google.com137f1342013-05-29 21:27:53 +0000744 fSavedState->ref();
745 if (kReset_ASRInit == init) {
746 if (NULL == vm) {
747 // calls the default cons
748 fTempState.init();
749 } else {
750 SkNEW_IN_TLAZY(&fTempState, GrDrawState, (*vm));
751 }
752 } else {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000753 SkASSERT(kPreserve_ASRInit == init);
bsalomon@google.com137f1342013-05-29 21:27:53 +0000754 if (NULL == vm) {
755 fTempState.set(*fSavedState);
756 } else {
757 SkNEW_IN_TLAZY(&fTempState, GrDrawState, (*fSavedState, *vm));
758 }
759 }
760 target->setDrawState(fTempState.get());
761}
762
763bool GrDrawTarget::AutoStateRestore::setIdentity(GrDrawTarget* target, ASRInit init) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000764 SkASSERT(NULL == fDrawTarget);
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000765 fDrawTarget = target;
766 fSavedState = target->drawState();
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000767 SkASSERT(fSavedState);
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000768 fSavedState->ref();
769 if (kReset_ASRInit == init) {
770 // calls the default cons
771 fTempState.init();
772 } else {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000773 SkASSERT(kPreserve_ASRInit == init);
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000774 // calls the copy cons
775 fTempState.set(*fSavedState);
bsalomon@google.com137f1342013-05-29 21:27:53 +0000776 if (!fTempState.get()->setIdentityViewMatrix()) {
777 // let go of any resources held by the temp
778 fTempState.get()->reset();
779 fDrawTarget = NULL;
780 fSavedState->unref();
781 fSavedState = NULL;
782 return false;
783 }
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000784 }
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000785 target->setDrawState(fTempState.get());
bsalomon@google.com137f1342013-05-29 21:27:53 +0000786 return true;
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000787}
bsalomon@google.com7ac249b2011-06-14 18:46:24 +0000788
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000789////////////////////////////////////////////////////////////////////////////////
bsalomon@google.com7ac249b2011-06-14 18:46:24 +0000790
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000791GrDrawTarget::AutoReleaseGeometry::AutoReleaseGeometry(
792 GrDrawTarget* target,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000793 int vertexCount,
794 int indexCount) {
795 fTarget = NULL;
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000796 this->set(target, vertexCount, indexCount);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000797}
rmistry@google.comd6176b02012-08-23 18:14:13 +0000798
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000799GrDrawTarget::AutoReleaseGeometry::AutoReleaseGeometry() {
800 fTarget = NULL;
801}
802
803GrDrawTarget::AutoReleaseGeometry::~AutoReleaseGeometry() {
804 this->reset();
805}
806
807bool GrDrawTarget::AutoReleaseGeometry::set(GrDrawTarget* target,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000808 int vertexCount,
809 int indexCount) {
810 this->reset();
811 fTarget = target;
812 bool success = true;
bsalomon49f085d2014-09-05 13:34:00 -0700813 if (fTarget) {
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000814 success = target->reserveVertexAndIndexSpace(vertexCount,
bsalomon@google.come3d70952012-03-13 12:40:53 +0000815 indexCount,
816 &fVertices,
817 &fIndices);
818 if (!success) {
819 fTarget = NULL;
820 this->reset();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000821 }
822 }
bsalomon49f085d2014-09-05 13:34:00 -0700823 SkASSERT(success == SkToBool(fTarget));
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000824 return success;
825}
826
827void GrDrawTarget::AutoReleaseGeometry::reset() {
bsalomon49f085d2014-09-05 13:34:00 -0700828 if (fTarget) {
829 if (fVertices) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000830 fTarget->resetVertexSource();
831 }
bsalomon49f085d2014-09-05 13:34:00 -0700832 if (fIndices) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000833 fTarget->resetIndexSource();
834 }
835 fTarget = NULL;
836 }
bsalomon@google.comcb0c5ab2011-06-29 17:48:17 +0000837 fVertices = NULL;
838 fIndices = NULL;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000839}
840
bsalomon@google.com8d67c072012-12-13 20:38:14 +0000841GrDrawTarget::AutoClipRestore::AutoClipRestore(GrDrawTarget* target, const SkIRect& newClip) {
842 fTarget = target;
843 fClip = fTarget->getClip();
844 fStack.init();
845 fStack.get()->clipDevRect(newClip, SkRegion::kReplace_Op);
846 fReplacementClip.fClipStack = fStack.get();
847 target->setClip(&fReplacementClip);
848}
849
bsalomon@google.com116ad842013-04-09 15:38:19 +0000850namespace {
851// returns true if the read/written rect intersects the src/dst and false if not.
852bool clip_srcrect_and_dstpoint(const GrSurface* dst,
853 const GrSurface* src,
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000854 const SkIRect& srcRect,
bsalomon@google.com116ad842013-04-09 15:38:19 +0000855 const SkIPoint& dstPoint,
856 SkIRect* clippedSrcRect,
857 SkIPoint* clippedDstPoint) {
858 *clippedSrcRect = srcRect;
859 *clippedDstPoint = dstPoint;
skia.committer@gmail.coma9493a32013-04-04 07:01:12 +0000860
bsalomon@google.com116ad842013-04-09 15:38:19 +0000861 // clip the left edge to src and dst bounds, adjusting dstPoint if necessary
862 if (clippedSrcRect->fLeft < 0) {
863 clippedDstPoint->fX -= clippedSrcRect->fLeft;
864 clippedSrcRect->fLeft = 0;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000865 }
bsalomon@google.com116ad842013-04-09 15:38:19 +0000866 if (clippedDstPoint->fX < 0) {
867 clippedSrcRect->fLeft -= clippedDstPoint->fX;
868 clippedDstPoint->fX = 0;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000869 }
870
bsalomon@google.com116ad842013-04-09 15:38:19 +0000871 // clip the top edge to src and dst bounds, adjusting dstPoint if necessary
872 if (clippedSrcRect->fTop < 0) {
873 clippedDstPoint->fY -= clippedSrcRect->fTop;
874 clippedSrcRect->fTop = 0;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000875 }
bsalomon@google.com116ad842013-04-09 15:38:19 +0000876 if (clippedDstPoint->fY < 0) {
877 clippedSrcRect->fTop -= clippedDstPoint->fY;
878 clippedDstPoint->fY = 0;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000879 }
skia.committer@gmail.coma9493a32013-04-04 07:01:12 +0000880
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000881 // clip the right edge to the src and dst bounds.
bsalomon@google.com116ad842013-04-09 15:38:19 +0000882 if (clippedSrcRect->fRight > src->width()) {
883 clippedSrcRect->fRight = src->width();
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000884 }
bsalomon@google.com116ad842013-04-09 15:38:19 +0000885 if (clippedDstPoint->fX + clippedSrcRect->width() > dst->width()) {
886 clippedSrcRect->fRight = clippedSrcRect->fLeft + dst->width() - clippedDstPoint->fX;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000887 }
888
889 // clip the bottom edge to the src and dst bounds.
bsalomon@google.com116ad842013-04-09 15:38:19 +0000890 if (clippedSrcRect->fBottom > src->height()) {
891 clippedSrcRect->fBottom = src->height();
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000892 }
bsalomon@google.com116ad842013-04-09 15:38:19 +0000893 if (clippedDstPoint->fY + clippedSrcRect->height() > dst->height()) {
894 clippedSrcRect->fBottom = clippedSrcRect->fTop + dst->height() - clippedDstPoint->fY;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000895 }
skia.committer@gmail.coma9493a32013-04-04 07:01:12 +0000896
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000897 // The above clipping steps may have inverted the rect if it didn't intersect either the src or
898 // dst bounds.
bsalomon@google.com116ad842013-04-09 15:38:19 +0000899 return !clippedSrcRect->isEmpty();
900}
901}
902
903bool GrDrawTarget::copySurface(GrSurface* dst,
904 GrSurface* src,
905 const SkIRect& srcRect,
906 const SkIPoint& dstPoint) {
bsalomon49f085d2014-09-05 13:34:00 -0700907 SkASSERT(dst);
908 SkASSERT(src);
bsalomon@google.com116ad842013-04-09 15:38:19 +0000909
910 SkIRect clippedSrcRect;
911 SkIPoint clippedDstPoint;
912 // If the rect is outside the src or dst then we've already succeeded.
913 if (!clip_srcrect_and_dstpoint(dst,
914 src,
915 srcRect,
916 dstPoint,
917 &clippedSrcRect,
918 &clippedDstPoint)) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000919 SkASSERT(this->canCopySurface(dst, src, srcRect, dstPoint));
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000920 return true;
921 }
922
923 bool result = this->onCopySurface(dst, src, clippedSrcRect, clippedDstPoint);
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000924 SkASSERT(result == this->canCopySurface(dst, src, clippedSrcRect, clippedDstPoint));
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000925 return result;
926}
927
928bool GrDrawTarget::canCopySurface(GrSurface* dst,
929 GrSurface* src,
930 const SkIRect& srcRect,
931 const SkIPoint& dstPoint) {
bsalomon49f085d2014-09-05 13:34:00 -0700932 SkASSERT(dst);
933 SkASSERT(src);
bsalomon@google.com116ad842013-04-09 15:38:19 +0000934
935 SkIRect clippedSrcRect;
936 SkIPoint clippedDstPoint;
937 // If the rect is outside the src or dst then we're guaranteed success
938 if (!clip_srcrect_and_dstpoint(dst,
939 src,
940 srcRect,
941 dstPoint,
942 &clippedSrcRect,
943 &clippedDstPoint)) {
944 return true;
945 }
946 return this->onCanCopySurface(dst, src, clippedSrcRect, clippedDstPoint);
947}
948
949bool GrDrawTarget::onCanCopySurface(GrSurface* dst,
950 GrSurface* src,
951 const SkIRect& srcRect,
952 const SkIPoint& dstPoint) {
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000953 // Check that the read/write rects are contained within the src/dst bounds.
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000954 SkASSERT(!srcRect.isEmpty());
955 SkASSERT(SkIRect::MakeWH(src->width(), src->height()).contains(srcRect));
956 SkASSERT(dstPoint.fX >= 0 && dstPoint.fY >= 0);
957 SkASSERT(dstPoint.fX + srcRect.width() <= dst->width() &&
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000958 dstPoint.fY + srcRect.height() <= dst->height());
959
bsalomonafbf2d62014-09-30 12:18:44 -0700960 return !dst->surfacePriv().isSameAs(src) && dst->asRenderTarget() && src->asTexture();
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000961}
962
963bool GrDrawTarget::onCopySurface(GrSurface* dst,
964 GrSurface* src,
965 const SkIRect& srcRect,
966 const SkIPoint& dstPoint) {
bsalomon@google.com116ad842013-04-09 15:38:19 +0000967 if (!GrDrawTarget::onCanCopySurface(dst, src, srcRect, dstPoint)) {
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000968 return false;
969 }
970
971 GrRenderTarget* rt = dst->asRenderTarget();
972 GrTexture* tex = src->asTexture();
973
974 GrDrawTarget::AutoStateRestore asr(this, kReset_ASRInit);
975 this->drawState()->setRenderTarget(rt);
976 SkMatrix matrix;
977 matrix.setTranslate(SkIntToScalar(srcRect.fLeft - dstPoint.fX),
978 SkIntToScalar(srcRect.fTop - dstPoint.fY));
979 matrix.postIDiv(tex->width(), tex->height());
joshualittb0a8a372014-09-23 09:50:21 -0700980 this->drawState()->addColorTextureProcessor(tex, matrix);
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000981 SkIRect dstRect = SkIRect::MakeXYWH(dstPoint.fX,
982 dstPoint.fY,
983 srcRect.width(),
984 srcRect.height());
985 this->drawSimpleRect(dstRect);
986 return true;
987}
988
bsalomonf2703d82014-10-28 14:33:06 -0700989void GrDrawTarget::initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc) {
bsalomon@google.comeb851172013-04-15 13:51:00 +0000990 // Make the dst of the copy be a render target because the default copySurface draws to the dst.
991 desc->fOrigin = kDefault_GrSurfaceOrigin;
bsalomonf2703d82014-10-28 14:33:06 -0700992 desc->fFlags = kRenderTarget_GrSurfaceFlag | kNoStencil_GrSurfaceFlag;
bsalomon@google.comeb851172013-04-15 13:51:00 +0000993 desc->fConfig = src->config();
994}
995
bsalomon@google.combcce8922013-03-25 15:38:39 +0000996///////////////////////////////////////////////////////////////////////////////
997
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000998void GrDrawTargetCaps::reset() {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000999 fMipMapSupport = false;
bsalomon@google.combcce8922013-03-25 15:38:39 +00001000 fNPOTTextureTileSupport = false;
1001 fTwoSidedStencilSupport = false;
1002 fStencilWrapOpsSupport = false;
1003 fHWAALineSupport = false;
1004 fShaderDerivativeSupport = false;
1005 fGeometryShaderSupport = false;
skia.committer@gmail.come60ed082013-03-26 07:01:04 +00001006 fDualSourceBlendingSupport = false;
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +00001007 fPathRenderingSupport = false;
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +00001008 fDstReadInShaderSupport = false;
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +00001009 fDiscardRenderTargetSupport = false;
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +00001010 fReuseScratchTextures = true;
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +00001011 fGpuTracingSupport = false;
krajcevski786978162014-07-30 11:25:44 -07001012 fCompressedTexSubImageSupport = false;
bsalomon@google.combcce8922013-03-25 15:38:39 +00001013
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001014 fMapBufferFlags = kNone_MapFlags;
1015
bsalomon@google.combcce8922013-03-25 15:38:39 +00001016 fMaxRenderTargetSize = 0;
1017 fMaxTextureSize = 0;
1018 fMaxSampleCount = 0;
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001019
1020 memset(fConfigRenderSupport, 0, sizeof(fConfigRenderSupport));
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001021 memset(fConfigTextureSupport, 0, sizeof(fConfigTextureSupport));
bsalomon@google.combcce8922013-03-25 15:38:39 +00001022}
1023
bsalomon@google.comc26d94f2013-03-25 18:19:00 +00001024GrDrawTargetCaps& GrDrawTargetCaps::operator=(const GrDrawTargetCaps& other) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +00001025 fMipMapSupport = other.fMipMapSupport;
bsalomon@google.combcce8922013-03-25 15:38:39 +00001026 fNPOTTextureTileSupport = other.fNPOTTextureTileSupport;
1027 fTwoSidedStencilSupport = other.fTwoSidedStencilSupport;
1028 fStencilWrapOpsSupport = other.fStencilWrapOpsSupport;
1029 fHWAALineSupport = other.fHWAALineSupport;
1030 fShaderDerivativeSupport = other.fShaderDerivativeSupport;
1031 fGeometryShaderSupport = other.fGeometryShaderSupport;
1032 fDualSourceBlendingSupport = other.fDualSourceBlendingSupport;
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +00001033 fPathRenderingSupport = other.fPathRenderingSupport;
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +00001034 fDstReadInShaderSupport = other.fDstReadInShaderSupport;
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +00001035 fDiscardRenderTargetSupport = other.fDiscardRenderTargetSupport;
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +00001036 fReuseScratchTextures = other.fReuseScratchTextures;
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +00001037 fGpuTracingSupport = other.fGpuTracingSupport;
krajcevski786978162014-07-30 11:25:44 -07001038 fCompressedTexSubImageSupport = other.fCompressedTexSubImageSupport;
bsalomon@google.combcce8922013-03-25 15:38:39 +00001039
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001040 fMapBufferFlags = other.fMapBufferFlags;
1041
bsalomon@google.combcce8922013-03-25 15:38:39 +00001042 fMaxRenderTargetSize = other.fMaxRenderTargetSize;
1043 fMaxTextureSize = other.fMaxTextureSize;
1044 fMaxSampleCount = other.fMaxSampleCount;
1045
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001046 memcpy(fConfigRenderSupport, other.fConfigRenderSupport, sizeof(fConfigRenderSupport));
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001047 memcpy(fConfigTextureSupport, other.fConfigTextureSupport, sizeof(fConfigTextureSupport));
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001048
bsalomon@google.combcce8922013-03-25 15:38:39 +00001049 return *this;
1050}
1051
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001052static SkString map_flags_to_string(uint32_t flags) {
1053 SkString str;
1054 if (GrDrawTargetCaps::kNone_MapFlags == flags) {
1055 str = "none";
1056 } else {
1057 SkASSERT(GrDrawTargetCaps::kCanMap_MapFlag & flags);
1058 SkDEBUGCODE(flags &= ~GrDrawTargetCaps::kCanMap_MapFlag);
1059 str = "can_map";
1060
1061 if (GrDrawTargetCaps::kSubset_MapFlag & flags) {
1062 str.append(" partial");
1063 } else {
1064 str.append(" full");
1065 }
1066 SkDEBUGCODE(flags &= ~GrDrawTargetCaps::kSubset_MapFlag);
1067 }
1068 SkASSERT(0 == flags); // Make sure we handled all the flags.
1069 return str;
1070}
1071
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001072SkString GrDrawTargetCaps::dump() const {
1073 SkString r;
bsalomon@google.com18c9c192011-09-22 21:01:31 +00001074 static const char* gNY[] = {"NO", "YES"};
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +00001075 r.appendf("MIP Map Support : %s\n", gNY[fMipMapSupport]);
1076 r.appendf("NPOT Texture Tile Support : %s\n", gNY[fNPOTTextureTileSupport]);
1077 r.appendf("Two Sided Stencil Support : %s\n", gNY[fTwoSidedStencilSupport]);
1078 r.appendf("Stencil Wrap Ops Support : %s\n", gNY[fStencilWrapOpsSupport]);
1079 r.appendf("HW AA Lines Support : %s\n", gNY[fHWAALineSupport]);
1080 r.appendf("Shader Derivative Support : %s\n", gNY[fShaderDerivativeSupport]);
1081 r.appendf("Geometry Shader Support : %s\n", gNY[fGeometryShaderSupport]);
1082 r.appendf("Dual Source Blending Support : %s\n", gNY[fDualSourceBlendingSupport]);
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +00001083 r.appendf("Path Rendering Support : %s\n", gNY[fPathRenderingSupport]);
1084 r.appendf("Dst Read In Shader Support : %s\n", gNY[fDstReadInShaderSupport]);
1085 r.appendf("Discard Render Target Support: %s\n", gNY[fDiscardRenderTargetSupport]);
1086 r.appendf("Reuse Scratch Textures : %s\n", gNY[fReuseScratchTextures]);
1087 r.appendf("Gpu Tracing Support : %s\n", gNY[fGpuTracingSupport]);
krajcevski786978162014-07-30 11:25:44 -07001088 r.appendf("Compressed Update Support : %s\n", gNY[fCompressedTexSubImageSupport]);
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +00001089 r.appendf("Max Texture Size : %d\n", fMaxTextureSize);
1090 r.appendf("Max Render Target Size : %d\n", fMaxRenderTargetSize);
1091 r.appendf("Max Sample Count : %d\n", fMaxSampleCount);
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001092
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001093 r.appendf("Map Buffer Support : %s\n", map_flags_to_string(fMapBufferFlags).c_str());
1094
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001095 static const char* kConfigNames[] = {
1096 "Unknown", // kUnknown_GrPixelConfig
1097 "Alpha8", // kAlpha_8_GrPixelConfig,
1098 "Index8", // kIndex_8_GrPixelConfig,
1099 "RGB565", // kRGB_565_GrPixelConfig,
1100 "RGBA444", // kRGBA_4444_GrPixelConfig,
1101 "RGBA8888", // kRGBA_8888_GrPixelConfig,
1102 "BGRA8888", // kBGRA_8888_GrPixelConfig,
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001103 "ETC1", // kETC1_GrPixelConfig,
1104 "LATC", // kLATC_GrPixelConfig,
krajcevski238b4562014-06-30 09:09:22 -07001105 "R11EAC", // kR11_EAC_GrPixelConfig,
krajcevski7ef21622014-07-16 15:21:13 -07001106 "ASTC12x12",// kASTC_12x12_GrPixelConfig,
joshualittee5da552014-07-16 13:32:56 -07001107 "RGBAFloat", // kRGBA_float_GrPixelConfig
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001108 };
krajcevski7ef21622014-07-16 15:21:13 -07001109 GR_STATIC_ASSERT(0 == kUnknown_GrPixelConfig);
1110 GR_STATIC_ASSERT(1 == kAlpha_8_GrPixelConfig);
1111 GR_STATIC_ASSERT(2 == kIndex_8_GrPixelConfig);
1112 GR_STATIC_ASSERT(3 == kRGB_565_GrPixelConfig);
1113 GR_STATIC_ASSERT(4 == kRGBA_4444_GrPixelConfig);
1114 GR_STATIC_ASSERT(5 == kRGBA_8888_GrPixelConfig);
1115 GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig);
1116 GR_STATIC_ASSERT(7 == kETC1_GrPixelConfig);
1117 GR_STATIC_ASSERT(8 == kLATC_GrPixelConfig);
1118 GR_STATIC_ASSERT(9 == kR11_EAC_GrPixelConfig);
1119 GR_STATIC_ASSERT(10 == kASTC_12x12_GrPixelConfig);
1120 GR_STATIC_ASSERT(11 == kRGBA_float_GrPixelConfig);
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001121 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kConfigNames) == kGrPixelConfigCnt);
1122
commit-bot@chromium.org99017272013-11-08 18:45:27 +00001123 SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][0]);
1124 SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][1]);
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001125
1126 for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) {
1127 r.appendf("%s is renderable: %s, with MSAA: %s\n",
1128 kConfigNames[i],
1129 gNY[fConfigRenderSupport[i][0]],
1130 gNY[fConfigRenderSupport[i][1]]);
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001131 }
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +00001132
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001133 SkASSERT(!fConfigTextureSupport[kUnknown_GrPixelConfig]);
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +00001134
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001135 for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) {
1136 r.appendf("%s is uploadable to a texture: %s\n",
1137 kConfigNames[i],
1138 gNY[fConfigTextureSupport[i]]);
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +00001139 }
1140
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001141 return r;
bsalomon@google.com18c9c192011-09-22 21:01:31 +00001142}
egdanielbc127a32014-09-19 12:07:43 -07001143
1144uint32_t GrDrawTargetCaps::CreateUniqueID() {
1145 static int32_t gUniqueID = SK_InvalidUniqueID;
1146 uint32_t id;
1147 do {
1148 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1);
1149 } while (id == SK_InvalidUniqueID);
1150 return id;
1151}
1152