blob: 08a62a534cf0ff0d9f0ee42bf9d0b52659365c78 [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;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000235 case kReserved_GeometrySrcType:
236 this->releaseReservedVertexSpace();
237 break;
238 case kBuffer_GeometrySrcType:
239 geoSrc.fVertexBuffer->unref();
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000240#ifdef SK_DEBUG
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000241 geoSrc.fVertexBuffer = (GrVertexBuffer*)DEBUG_INVAL_BUFFER;
242#endif
243 break;
244 default:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000245 SkFAIL("Unknown Vertex Source Type.");
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000246 break;
247 }
248}
249
250void GrDrawTarget::releasePreviousIndexSource() {
251 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
252 switch (geoSrc.fIndexSrc) {
253 case kNone_GeometrySrcType: // these two don't require
254 break;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000255 case kReserved_GeometrySrcType:
256 this->releaseReservedIndexSpace();
257 break;
258 case kBuffer_GeometrySrcType:
259 geoSrc.fIndexBuffer->unref();
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000260#ifdef SK_DEBUG
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000261 geoSrc.fIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER;
262#endif
263 break;
264 default:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000265 SkFAIL("Unknown Index Source Type.");
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000266 break;
267 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000268}
269
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000270void GrDrawTarget::setVertexSourceToBuffer(const GrVertexBuffer* buffer) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000271 this->releasePreviousVertexSource();
272 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
273 geoSrc.fVertexSrc = kBuffer_GeometrySrcType;
274 geoSrc.fVertexBuffer = buffer;
275 buffer->ref();
egdaniel7b3d5ee2014-08-28 05:41:14 -0700276 geoSrc.fVertexSize = this->drawState()->getVertexStride();
reed@google.comac10a2d2010-12-22 21:39:39 +0000277}
278
279void GrDrawTarget::setIndexSourceToBuffer(const GrIndexBuffer* buffer) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000280 this->releasePreviousIndexSource();
281 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
282 geoSrc.fIndexSrc = kBuffer_GeometrySrcType;
283 geoSrc.fIndexBuffer = buffer;
284 buffer->ref();
reed@google.comac10a2d2010-12-22 21:39:39 +0000285}
286
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000287void GrDrawTarget::resetVertexSource() {
288 this->releasePreviousVertexSource();
289 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
290 geoSrc.fVertexSrc = kNone_GeometrySrcType;
291}
292
293void GrDrawTarget::resetIndexSource() {
294 this->releasePreviousIndexSource();
295 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
296 geoSrc.fIndexSrc = kNone_GeometrySrcType;
297}
298
299void GrDrawTarget::pushGeometrySource() {
300 this->geometrySourceWillPush();
301 GeometrySrcState& newState = fGeoSrcStateStack.push_back();
302 newState.fIndexSrc = kNone_GeometrySrcType;
303 newState.fVertexSrc = kNone_GeometrySrcType;
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000304#ifdef SK_DEBUG
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000305 newState.fVertexCount = ~0;
306 newState.fVertexBuffer = (GrVertexBuffer*)~0;
307 newState.fIndexCount = ~0;
308 newState.fIndexBuffer = (GrIndexBuffer*)~0;
309#endif
310}
311
312void GrDrawTarget::popGeometrySource() {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000313 // if popping last element then pops are unbalanced with pushes
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000314 SkASSERT(fGeoSrcStateStack.count() > 1);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000315
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000316 this->geometrySourceWillPop(fGeoSrcStateStack.fromBack(1));
317 this->releasePreviousVertexSource();
318 this->releasePreviousIndexSource();
319 fGeoSrcStateStack.pop_back();
320}
321
322////////////////////////////////////////////////////////////////////////////////
323
bsalomon@google.come8262622011-11-07 02:30:51 +0000324bool GrDrawTarget::checkDraw(GrPrimitiveType type, int startVertex,
325 int startIndex, int vertexCount,
326 int indexCount) const {
bsalomon@google.comcddaf342012-07-30 13:09:05 +0000327 const GrDrawState& drawState = this->getDrawState();
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000328#ifdef SK_DEBUG
bsalomon@google.come8262622011-11-07 02:30:51 +0000329 const GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000330 int maxVertex = startVertex + vertexCount;
331 int maxValidVertex;
332 switch (geoSrc.fVertexSrc) {
333 case kNone_GeometrySrcType:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000334 SkFAIL("Attempting to draw without vertex src.");
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000335 case kReserved_GeometrySrcType: // fallthrough
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000336 maxValidVertex = geoSrc.fVertexCount;
337 break;
338 case kBuffer_GeometrySrcType:
commit-bot@chromium.org089a7802014-05-02 21:38:22 +0000339 maxValidVertex = static_cast<int>(geoSrc.fVertexBuffer->gpuMemorySize() / geoSrc.fVertexSize);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000340 break;
341 }
342 if (maxVertex > maxValidVertex) {
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000343 SkFAIL("Drawing outside valid vertex range.");
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000344 }
bsalomon@google.come8262622011-11-07 02:30:51 +0000345 if (indexCount > 0) {
346 int maxIndex = startIndex + indexCount;
347 int maxValidIndex;
348 switch (geoSrc.fIndexSrc) {
349 case kNone_GeometrySrcType:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000350 SkFAIL("Attempting to draw indexed geom without index src.");
bsalomon@google.come8262622011-11-07 02:30:51 +0000351 case kReserved_GeometrySrcType: // fallthrough
bsalomon@google.come8262622011-11-07 02:30:51 +0000352 maxValidIndex = geoSrc.fIndexCount;
353 break;
354 case kBuffer_GeometrySrcType:
commit-bot@chromium.org089a7802014-05-02 21:38:22 +0000355 maxValidIndex = static_cast<int>(geoSrc.fIndexBuffer->gpuMemorySize() / sizeof(uint16_t));
bsalomon@google.come8262622011-11-07 02:30:51 +0000356 break;
357 }
358 if (maxIndex > maxValidIndex) {
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000359 SkFAIL("Index reads outside valid index range.");
bsalomon@google.come8262622011-11-07 02:30:51 +0000360 }
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000361 }
bsalomon@google.comb4725b42012-03-30 17:24:17 +0000362
bsalomon49f085d2014-09-05 13:34:00 -0700363 SkASSERT(drawState.getRenderTarget());
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000364
joshualittbd769d02014-09-04 08:56:46 -0700365 if (drawState.hasGeometryProcessor()) {
joshualitta5305a12014-10-10 17:47:00 -0700366 const GrGeometryProcessor* gp = drawState.getGeometryProcessor();
joshualittb0a8a372014-09-23 09:50:21 -0700367 int numTextures = gp->numTextures();
joshualittbd769d02014-09-04 08:56:46 -0700368 for (int t = 0; t < numTextures; ++t) {
joshualittb0a8a372014-09-23 09:50:21 -0700369 GrTexture* texture = gp->texture(t);
joshualittbd769d02014-09-04 08:56:46 -0700370 SkASSERT(texture->asRenderTarget() != drawState.getRenderTarget());
371 }
372 }
373
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000374 for (int s = 0; s < drawState.numColorStages(); ++s) {
joshualittb0a8a372014-09-23 09:50:21 -0700375 const GrProcessor* effect = drawState.getColorStage(s).getProcessor();
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000376 int numTextures = effect->numTextures();
377 for (int t = 0; t < numTextures; ++t) {
378 GrTexture* texture = effect->texture(t);
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000379 SkASSERT(texture->asRenderTarget() != drawState.getRenderTarget());
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000380 }
381 }
382 for (int s = 0; s < drawState.numCoverageStages(); ++s) {
joshualittb0a8a372014-09-23 09:50:21 -0700383 const GrProcessor* effect = drawState.getCoverageStage(s).getProcessor();
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000384 int numTextures = effect->numTextures();
385 for (int t = 0; t < numTextures; ++t) {
386 GrTexture* texture = effect->texture(t);
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000387 SkASSERT(texture->asRenderTarget() != drawState.getRenderTarget());
bsalomon@google.comb4725b42012-03-30 17:24:17 +0000388 }
389 }
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000390
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000391 SkASSERT(drawState.validateVertexAttribs());
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000392#endif
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000393 if (NULL == drawState.getRenderTarget()) {
bsalomon@google.com0ba52fc2011-11-10 22:16:06 +0000394 return false;
395 }
bsalomon@google.come8262622011-11-07 02:30:51 +0000396 return true;
397}
398
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000399bool GrDrawTarget::setupDstReadIfNecessary(GrDeviceCoordTexture* dstCopy, const SkRect* drawBounds) {
bsalomon@google.comb5158812013-05-13 18:50:25 +0000400 if (this->caps()->dstReadInShaderSupport() || !this->getDrawState().willEffectReadDstColor()) {
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000401 return true;
402 }
403 GrRenderTarget* rt = this->drawState()->getRenderTarget();
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000404 SkIRect copyRect;
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000405 const GrClipData* clip = this->getClip();
406 clip->getConservativeBounds(rt, &copyRect);
407
bsalomon49f085d2014-09-05 13:34:00 -0700408 if (drawBounds) {
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000409 SkIRect drawIBounds;
410 drawBounds->roundOut(&drawIBounds);
commit-bot@chromium.orgbb5c4652013-04-01 12:49:31 +0000411 if (!copyRect.intersect(drawIBounds)) {
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000412#ifdef SK_DEBUG
tfarina38406c82014-10-31 07:11:12 -0700413 SkDebugf("Missed an early reject. Bailing on draw from setupDstReadIfNecessary.\n");
commit-bot@chromium.orgbb5c4652013-04-01 12:49:31 +0000414#endif
415 return false;
416 }
417 } else {
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000418#ifdef SK_DEBUG
tfarina38406c82014-10-31 07:11:12 -0700419 //SkDebugf("No dev bounds when dst copy is made.\n");
commit-bot@chromium.orgbb5c4652013-04-01 12:49:31 +0000420#endif
421 }
skia.committer@gmail.com05a2ee02013-04-02 07:01:34 +0000422
commit-bot@chromium.org63150af2013-04-11 22:00:22 +0000423 // MSAA consideration: When there is support for reading MSAA samples in the shader we could
424 // have per-sample dst values by making the copy multisampled.
bsalomonf2703d82014-10-28 14:33:06 -0700425 GrSurfaceDesc desc;
bsalomon@google.comeb851172013-04-15 13:51:00 +0000426 this->initCopySurfaceDstDesc(rt, &desc);
commit-bot@chromium.orgbb5c4652013-04-01 12:49:31 +0000427 desc.fWidth = copyRect.width();
428 desc.fHeight = copyRect.height();
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000429
bsalomone3059732014-10-14 11:47:22 -0700430 SkAutoTUnref<GrTexture> copy(
431 fContext->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch));
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000432
bsalomone3059732014-10-14 11:47:22 -0700433 if (!copy) {
tfarina38406c82014-10-31 07:11:12 -0700434 SkDebugf("Failed to create temporary copy of destination texture.\n");
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000435 return false;
436 }
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000437 SkIPoint dstPoint = {0, 0};
bsalomone3059732014-10-14 11:47:22 -0700438 if (this->copySurface(copy, rt, copyRect, dstPoint)) {
439 dstCopy->setTexture(copy);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000440 dstCopy->setOffset(copyRect.fLeft, copyRect.fTop);
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000441 return true;
442 } else {
443 return false;
444 }
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000445}
446
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000447void GrDrawTarget::drawIndexed(GrPrimitiveType type,
448 int startVertex,
449 int startIndex,
450 int vertexCount,
451 int indexCount,
452 const SkRect* devBounds) {
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000453 if (indexCount > 0 && this->checkDraw(type, startVertex, startIndex, vertexCount, indexCount)) {
454 DrawInfo info;
455 info.fPrimitiveType = type;
456 info.fStartVertex = startVertex;
457 info.fStartIndex = startIndex;
458 info.fVertexCount = vertexCount;
459 info.fIndexCount = indexCount;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000460
461 info.fInstanceCount = 0;
462 info.fVerticesPerInstance = 0;
463 info.fIndicesPerInstance = 0;
464
bsalomon49f085d2014-09-05 13:34:00 -0700465 if (devBounds) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000466 info.setDevBounds(*devBounds);
467 }
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000468 // TODO: We should continue with incorrect blending.
469 if (!this->setupDstReadIfNecessary(&info)) {
470 return;
471 }
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000472 this->onDraw(info);
bsalomon@google.com82145872011-08-23 14:32:40 +0000473 }
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000474}
475
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000476void GrDrawTarget::drawNonIndexed(GrPrimitiveType type,
477 int startVertex,
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000478 int vertexCount,
479 const SkRect* devBounds) {
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000480 if (vertexCount > 0 && this->checkDraw(type, startVertex, -1, vertexCount, -1)) {
481 DrawInfo info;
482 info.fPrimitiveType = type;
483 info.fStartVertex = startVertex;
484 info.fStartIndex = 0;
485 info.fVertexCount = vertexCount;
486 info.fIndexCount = 0;
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
joshualitt92e496f2014-10-31 13:56:50 -0700503void GrDrawTarget::stencilPath(const GrPath* path, GrPathRendering::FillType fill) {
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000504 // TODO: extract portions of checkDraw that are relevant to path stenciling.
bsalomon49f085d2014-09-05 13:34:00 -0700505 SkASSERT(path);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000506 SkASSERT(this->caps()->pathRenderingSupport());
commit-bot@chromium.org32184d82013-10-09 15:14:18 +0000507 this->onStencilPath(path, fill);
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000508}
509
joshualitt92e496f2014-10-31 13:56:50 -0700510void GrDrawTarget::drawPath(const GrPath* path, GrPathRendering::FillType fill) {
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000511 // TODO: extract portions of checkDraw that are relevant to path rendering.
bsalomon49f085d2014-09-05 13:34:00 -0700512 SkASSERT(path);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000513 SkASSERT(this->caps()->pathRenderingSupport());
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000514
joshualitt92e496f2014-10-31 13:56:50 -0700515 SkRect devBounds = path->getBounds();
516 SkMatrix viewM = this->drawState()->getViewMatrix();
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000517 viewM.mapRect(&devBounds);
518
519 GrDeviceCoordTexture dstCopy;
520 if (!this->setupDstReadIfNecessary(&dstCopy, &devBounds)) {
521 return;
522 }
523
commit-bot@chromium.org32184d82013-10-09 15:14:18 +0000524 this->onDrawPath(path, fill, dstCopy.texture() ? &dstCopy : NULL);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000525}
526
cdaltonb85a0aa2014-07-21 15:32:44 -0700527void GrDrawTarget::drawPaths(const GrPathRange* pathRange,
528 const uint32_t indices[], int count,
529 const float transforms[], PathTransformType transformsType,
joshualitt92e496f2014-10-31 13:56:50 -0700530 GrPathRendering::FillType fill) {
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000531 SkASSERT(this->caps()->pathRenderingSupport());
bsalomon49f085d2014-09-05 13:34:00 -0700532 SkASSERT(pathRange);
533 SkASSERT(indices);
534 SkASSERT(transforms);
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000535
cdaltonb85a0aa2014-07-21 15:32:44 -0700536 // Don't compute a bounding box for setupDstReadIfNecessary(), we'll opt
537 // instead for it to just copy the entire dst. Realistically this is a moot
538 // point, because any context that supports NV_path_rendering will also
539 // support NV_blend_equation_advanced.
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000540 GrDeviceCoordTexture dstCopy;
cdaltonb85a0aa2014-07-21 15:32:44 -0700541 if (!this->setupDstReadIfNecessary(&dstCopy, NULL)) {
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000542 return;
543 }
544
cdaltonb85a0aa2014-07-21 15:32:44 -0700545 this->onDrawPaths(pathRange, indices, count, transforms, transformsType, fill,
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000546 dstCopy.texture() ? &dstCopy : NULL);
547}
548
bsalomon63b21962014-11-05 07:05:34 -0800549void GrDrawTarget::clear(const SkIRect* rect, GrColor color, bool canIgnoreRect,
550 GrRenderTarget* renderTarget) {
551 if (fCaps->useDrawInsteadOfClear()) {
552 // This works around a driver bug with clear by drawing a rect instead.
553 // The driver will ignore a clear if it is the only thing rendered to a
554 // target before the target is read.
555 SkIRect rtRect = SkIRect::MakeWH(renderTarget->width(), renderTarget->height());
556 if (NULL == rect || canIgnoreRect || rect->contains(rtRect)) {
557 rect = &rtRect;
558 // We first issue a discard() since that may help tilers.
559 this->discard(renderTarget);
560 }
561 AutoStateRestore asr(this, kReset_ASRInit, &SkMatrix::I());
562
563 this->drawState()->setColor(color);
564 this->drawState()->disableState(GrDrawState::kClip_StateBit);
565 this->drawState()->disableState(GrDrawState::kHWAntialias_StateBit);
566 this->drawState()->setRenderTarget(renderTarget);
567
568 this->drawSimpleRect(*rect);
569 } else {
570 this->onClear(rect, color, canIgnoreRect, renderTarget);
571 }
572}
573
egdaniel3eee3832014-06-18 13:09:11 -0700574typedef GrTraceMarkerSet::Iter TMIter;
575void GrDrawTarget::saveActiveTraceMarkers() {
576 if (this->caps()->gpuTracingSupport()) {
577 SkASSERT(0 == fStoredTraceMarkers.count());
578 fStoredTraceMarkers.addSet(fActiveTraceMarkers);
579 for (TMIter iter = fStoredTraceMarkers.begin(); iter != fStoredTraceMarkers.end(); ++iter) {
580 this->removeGpuTraceMarker(&(*iter));
581 }
582 }
583}
584
585void GrDrawTarget::restoreActiveTraceMarkers() {
586 if (this->caps()->gpuTracingSupport()) {
587 SkASSERT(0 == fActiveTraceMarkers.count());
588 for (TMIter iter = fStoredTraceMarkers.begin(); iter != fStoredTraceMarkers.end(); ++iter) {
589 this->addGpuTraceMarker(&(*iter));
590 }
591 for (TMIter iter = fActiveTraceMarkers.begin(); iter != fActiveTraceMarkers.end(); ++iter) {
592 this->fStoredTraceMarkers.remove(*iter);
593 }
594 }
595}
596
597void GrDrawTarget::addGpuTraceMarker(const GrGpuTraceMarker* marker) {
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000598 if (this->caps()->gpuTracingSupport()) {
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000599 SkASSERT(fGpuTraceMarkerCount >= 0);
600 this->fActiveTraceMarkers.add(*marker);
601 this->didAddGpuTraceMarker();
602 ++fGpuTraceMarkerCount;
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000603 }
604}
605
egdaniel3eee3832014-06-18 13:09:11 -0700606void GrDrawTarget::removeGpuTraceMarker(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 >= 1);
609 this->fActiveTraceMarkers.remove(*marker);
610 this->didRemoveGpuTraceMarker();
611 --fGpuTraceMarkerCount;
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000612 }
613}
614
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000615////////////////////////////////////////////////////////////////////////////////
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000616
bsalomon@google.com934c5702012-03-20 21:17:58 +0000617void GrDrawTarget::drawIndexedInstances(GrPrimitiveType type,
618 int instanceCount,
619 int verticesPerInstance,
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000620 int indicesPerInstance,
621 const SkRect* devBounds) {
bsalomon@google.com934c5702012-03-20 21:17:58 +0000622 if (!verticesPerInstance || !indicesPerInstance) {
623 return;
624 }
625
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000626 int maxInstancesPerDraw = this->indexCountInCurrentSource() / indicesPerInstance;
627 if (!maxInstancesPerDraw) {
bsalomon@google.com934c5702012-03-20 21:17:58 +0000628 return;
629 }
630
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000631 DrawInfo info;
632 info.fPrimitiveType = type;
633 info.fStartIndex = 0;
634 info.fStartVertex = 0;
635 info.fIndicesPerInstance = indicesPerInstance;
636 info.fVerticesPerInstance = verticesPerInstance;
637
638 // Set the same bounds for all the draws.
bsalomon49f085d2014-09-05 13:34:00 -0700639 if (devBounds) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000640 info.setDevBounds(*devBounds);
641 }
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000642 // TODO: We should continue with incorrect blending.
643 if (!this->setupDstReadIfNecessary(&info)) {
644 return;
645 }
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000646
bsalomon@google.com934c5702012-03-20 21:17:58 +0000647 while (instanceCount) {
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000648 info.fInstanceCount = SkTMin(instanceCount, maxInstancesPerDraw);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000649 info.fVertexCount = info.fInstanceCount * verticesPerInstance;
650 info.fIndexCount = info.fInstanceCount * indicesPerInstance;
651
652 if (this->checkDraw(type,
653 info.fStartVertex,
654 info.fStartIndex,
655 info.fVertexCount,
656 info.fIndexCount)) {
657 this->onDraw(info);
658 }
659 info.fStartVertex += info.fVertexCount;
660 instanceCount -= info.fInstanceCount;
bsalomon@google.com934c5702012-03-20 21:17:58 +0000661 }
662}
bsalomon@google.com3d0835b2011-12-08 16:12:03 +0000663
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000664////////////////////////////////////////////////////////////////////////////////
665
robertphillips@google.com42903302013-04-20 12:26:07 +0000666namespace {
667
668// position + (optional) texture coord
669extern const GrVertexAttrib gBWRectPosUVAttribs[] = {
670 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding},
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000671 {kVec2f_GrVertexAttribType, sizeof(SkPoint), kLocalCoord_GrVertexAttribBinding}
robertphillips@google.com42903302013-04-20 12:26:07 +0000672};
673
674void set_vertex_attributes(GrDrawState* drawState, bool hasUVs) {
675 if (hasUVs) {
egdaniel7b3d5ee2014-08-28 05:41:14 -0700676 drawState->setVertexAttribs<gBWRectPosUVAttribs>(2, 2 * sizeof(SkPoint));
robertphillips@google.com42903302013-04-20 12:26:07 +0000677 } else {
egdaniel7b3d5ee2014-08-28 05:41:14 -0700678 drawState->setVertexAttribs<gBWRectPosUVAttribs>(1, sizeof(SkPoint));
robertphillips@google.com42903302013-04-20 12:26:07 +0000679 }
680}
681
682};
683
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000684void GrDrawTarget::onDrawRect(const SkRect& rect,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000685 const SkRect* localRect,
bsalomon@google.com0406b9e2013-04-02 21:00:15 +0000686 const SkMatrix* localMatrix) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000687
bsalomon49f085d2014-09-05 13:34:00 -0700688 set_vertex_attributes(this->drawState(), SkToBool(localRect));
robertphillips@google.com42903302013-04-20 12:26:07 +0000689
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000690 AutoReleaseGeometry geo(this, 4, 0);
bsalomon@google.com6513cd02011-08-05 20:12:30 +0000691 if (!geo.succeeded()) {
tfarina38406c82014-10-31 07:11:12 -0700692 SkDebugf("Failed to get space for vertices!\n");
bsalomon@google.com6513cd02011-08-05 20:12:30 +0000693 return;
694 }
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000695
egdaniel7b3d5ee2014-08-28 05:41:14 -0700696 size_t vstride = this->drawState()->getVertexStride();
697 geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, vstride);
bsalomon49f085d2014-09-05 13:34:00 -0700698 if (localRect) {
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000699 SkPoint* coords = GrTCast<SkPoint*>(GrTCast<intptr_t>(geo.vertices()) +
700 sizeof(SkPoint));
bsalomon@google.comc7818882013-03-20 19:19:53 +0000701 coords->setRectFan(localRect->fLeft, localRect->fTop,
702 localRect->fRight, localRect->fBottom,
egdaniel7b3d5ee2014-08-28 05:41:14 -0700703 vstride);
bsalomon49f085d2014-09-05 13:34:00 -0700704 if (localMatrix) {
egdaniel7b3d5ee2014-08-28 05:41:14 -0700705 localMatrix->mapPointsWithStride(coords, vstride, 4);
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000706 }
707 }
commit-bot@chromium.org3ae0e6c2014-02-11 18:24:25 +0000708 SkRect bounds;
709 this->getDrawState().getViewMatrix().mapRect(&bounds, rect);
robertphillips@google.com8b129aa2012-10-05 15:37:00 +0000710
commit-bot@chromium.org3ae0e6c2014-02-11 18:24:25 +0000711 this->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4, &bounds);
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000712}
713
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000714void GrDrawTarget::clipWillBeSet(const GrClipData* clipData) {
715}
716
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000717////////////////////////////////////////////////////////////////////////////////
bsalomon@google.com7ac249b2011-06-14 18:46:24 +0000718
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000719GrDrawTarget::AutoStateRestore::AutoStateRestore() {
720 fDrawTarget = NULL;
721}
reed@google.comac10a2d2010-12-22 21:39:39 +0000722
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000723GrDrawTarget::AutoStateRestore::AutoStateRestore(GrDrawTarget* target,
bsalomon@google.com137f1342013-05-29 21:27:53 +0000724 ASRInit init,
725 const SkMatrix* vm) {
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000726 fDrawTarget = NULL;
bsalomon@google.com137f1342013-05-29 21:27:53 +0000727 this->set(target, init, vm);
reed@google.comac10a2d2010-12-22 21:39:39 +0000728}
729
730GrDrawTarget::AutoStateRestore::~AutoStateRestore() {
bsalomon49f085d2014-09-05 13:34:00 -0700731 if (fDrawTarget) {
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000732 fDrawTarget->setDrawState(fSavedState);
733 fSavedState->unref();
bsalomon@google.com7d34d2e2011-01-24 17:41:47 +0000734 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000735}
bsalomon@google.com7d34d2e2011-01-24 17:41:47 +0000736
bsalomon@google.com137f1342013-05-29 21:27:53 +0000737void GrDrawTarget::AutoStateRestore::set(GrDrawTarget* target, ASRInit init, const SkMatrix* vm) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000738 SkASSERT(NULL == fDrawTarget);
bsalomon@google.com137f1342013-05-29 21:27:53 +0000739 fDrawTarget = target;
740 fSavedState = target->drawState();
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000741 SkASSERT(fSavedState);
bsalomon@google.com137f1342013-05-29 21:27:53 +0000742 fSavedState->ref();
743 if (kReset_ASRInit == init) {
744 if (NULL == vm) {
745 // calls the default cons
746 fTempState.init();
747 } else {
748 SkNEW_IN_TLAZY(&fTempState, GrDrawState, (*vm));
749 }
750 } else {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000751 SkASSERT(kPreserve_ASRInit == init);
bsalomon@google.com137f1342013-05-29 21:27:53 +0000752 if (NULL == vm) {
753 fTempState.set(*fSavedState);
754 } else {
755 SkNEW_IN_TLAZY(&fTempState, GrDrawState, (*fSavedState, *vm));
756 }
757 }
758 target->setDrawState(fTempState.get());
759}
760
761bool GrDrawTarget::AutoStateRestore::setIdentity(GrDrawTarget* target, ASRInit init) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000762 SkASSERT(NULL == fDrawTarget);
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000763 fDrawTarget = target;
764 fSavedState = target->drawState();
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000765 SkASSERT(fSavedState);
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000766 fSavedState->ref();
767 if (kReset_ASRInit == init) {
768 // calls the default cons
769 fTempState.init();
770 } else {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000771 SkASSERT(kPreserve_ASRInit == init);
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000772 // calls the copy cons
773 fTempState.set(*fSavedState);
bsalomon@google.com137f1342013-05-29 21:27:53 +0000774 if (!fTempState.get()->setIdentityViewMatrix()) {
775 // let go of any resources held by the temp
776 fTempState.get()->reset();
777 fDrawTarget = NULL;
778 fSavedState->unref();
779 fSavedState = NULL;
780 return false;
781 }
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000782 }
bsalomon@google.com873ea0c2012-03-30 15:55:32 +0000783 target->setDrawState(fTempState.get());
bsalomon@google.com137f1342013-05-29 21:27:53 +0000784 return true;
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000785}
bsalomon@google.com7ac249b2011-06-14 18:46:24 +0000786
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000787////////////////////////////////////////////////////////////////////////////////
bsalomon@google.com7ac249b2011-06-14 18:46:24 +0000788
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000789GrDrawTarget::AutoReleaseGeometry::AutoReleaseGeometry(
790 GrDrawTarget* target,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000791 int vertexCount,
792 int indexCount) {
793 fTarget = NULL;
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000794 this->set(target, vertexCount, indexCount);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000795}
rmistry@google.comd6176b02012-08-23 18:14:13 +0000796
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000797GrDrawTarget::AutoReleaseGeometry::AutoReleaseGeometry() {
798 fTarget = NULL;
799}
800
801GrDrawTarget::AutoReleaseGeometry::~AutoReleaseGeometry() {
802 this->reset();
803}
804
805bool GrDrawTarget::AutoReleaseGeometry::set(GrDrawTarget* target,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000806 int vertexCount,
807 int indexCount) {
808 this->reset();
809 fTarget = target;
810 bool success = true;
bsalomon49f085d2014-09-05 13:34:00 -0700811 if (fTarget) {
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000812 success = target->reserveVertexAndIndexSpace(vertexCount,
bsalomon@google.come3d70952012-03-13 12:40:53 +0000813 indexCount,
814 &fVertices,
815 &fIndices);
816 if (!success) {
817 fTarget = NULL;
818 this->reset();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000819 }
820 }
bsalomon49f085d2014-09-05 13:34:00 -0700821 SkASSERT(success == SkToBool(fTarget));
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000822 return success;
823}
824
825void GrDrawTarget::AutoReleaseGeometry::reset() {
bsalomon49f085d2014-09-05 13:34:00 -0700826 if (fTarget) {
827 if (fVertices) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000828 fTarget->resetVertexSource();
829 }
bsalomon49f085d2014-09-05 13:34:00 -0700830 if (fIndices) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000831 fTarget->resetIndexSource();
832 }
833 fTarget = NULL;
834 }
bsalomon@google.comcb0c5ab2011-06-29 17:48:17 +0000835 fVertices = NULL;
836 fIndices = NULL;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000837}
838
bsalomon@google.com8d67c072012-12-13 20:38:14 +0000839GrDrawTarget::AutoClipRestore::AutoClipRestore(GrDrawTarget* target, const SkIRect& newClip) {
840 fTarget = target;
841 fClip = fTarget->getClip();
842 fStack.init();
843 fStack.get()->clipDevRect(newClip, SkRegion::kReplace_Op);
844 fReplacementClip.fClipStack = fStack.get();
845 target->setClip(&fReplacementClip);
846}
847
bsalomon@google.com116ad842013-04-09 15:38:19 +0000848namespace {
849// returns true if the read/written rect intersects the src/dst and false if not.
850bool clip_srcrect_and_dstpoint(const GrSurface* dst,
851 const GrSurface* src,
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000852 const SkIRect& srcRect,
bsalomon@google.com116ad842013-04-09 15:38:19 +0000853 const SkIPoint& dstPoint,
854 SkIRect* clippedSrcRect,
855 SkIPoint* clippedDstPoint) {
856 *clippedSrcRect = srcRect;
857 *clippedDstPoint = dstPoint;
skia.committer@gmail.coma9493a32013-04-04 07:01:12 +0000858
bsalomon@google.com116ad842013-04-09 15:38:19 +0000859 // clip the left edge to src and dst bounds, adjusting dstPoint if necessary
860 if (clippedSrcRect->fLeft < 0) {
861 clippedDstPoint->fX -= clippedSrcRect->fLeft;
862 clippedSrcRect->fLeft = 0;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000863 }
bsalomon@google.com116ad842013-04-09 15:38:19 +0000864 if (clippedDstPoint->fX < 0) {
865 clippedSrcRect->fLeft -= clippedDstPoint->fX;
866 clippedDstPoint->fX = 0;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000867 }
868
bsalomon@google.com116ad842013-04-09 15:38:19 +0000869 // clip the top edge to src and dst bounds, adjusting dstPoint if necessary
870 if (clippedSrcRect->fTop < 0) {
871 clippedDstPoint->fY -= clippedSrcRect->fTop;
872 clippedSrcRect->fTop = 0;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000873 }
bsalomon@google.com116ad842013-04-09 15:38:19 +0000874 if (clippedDstPoint->fY < 0) {
875 clippedSrcRect->fTop -= clippedDstPoint->fY;
876 clippedDstPoint->fY = 0;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000877 }
skia.committer@gmail.coma9493a32013-04-04 07:01:12 +0000878
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000879 // clip the right edge to the src and dst bounds.
bsalomon@google.com116ad842013-04-09 15:38:19 +0000880 if (clippedSrcRect->fRight > src->width()) {
881 clippedSrcRect->fRight = src->width();
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000882 }
bsalomon@google.com116ad842013-04-09 15:38:19 +0000883 if (clippedDstPoint->fX + clippedSrcRect->width() > dst->width()) {
884 clippedSrcRect->fRight = clippedSrcRect->fLeft + dst->width() - clippedDstPoint->fX;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000885 }
886
887 // clip the bottom edge to the src and dst bounds.
bsalomon@google.com116ad842013-04-09 15:38:19 +0000888 if (clippedSrcRect->fBottom > src->height()) {
889 clippedSrcRect->fBottom = src->height();
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000890 }
bsalomon@google.com116ad842013-04-09 15:38:19 +0000891 if (clippedDstPoint->fY + clippedSrcRect->height() > dst->height()) {
892 clippedSrcRect->fBottom = clippedSrcRect->fTop + dst->height() - clippedDstPoint->fY;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000893 }
skia.committer@gmail.coma9493a32013-04-04 07:01:12 +0000894
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000895 // The above clipping steps may have inverted the rect if it didn't intersect either the src or
896 // dst bounds.
bsalomon@google.com116ad842013-04-09 15:38:19 +0000897 return !clippedSrcRect->isEmpty();
898}
899}
900
901bool GrDrawTarget::copySurface(GrSurface* dst,
902 GrSurface* src,
903 const SkIRect& srcRect,
904 const SkIPoint& dstPoint) {
bsalomon49f085d2014-09-05 13:34:00 -0700905 SkASSERT(dst);
906 SkASSERT(src);
bsalomon@google.com116ad842013-04-09 15:38:19 +0000907
908 SkIRect clippedSrcRect;
909 SkIPoint clippedDstPoint;
910 // If the rect is outside the src or dst then we've already succeeded.
911 if (!clip_srcrect_and_dstpoint(dst,
912 src,
913 srcRect,
914 dstPoint,
915 &clippedSrcRect,
916 &clippedDstPoint)) {
joshualitta7024152014-11-03 14:16:35 -0800917 SkASSERT(GrDrawTarget::canCopySurface(dst, src, srcRect, dstPoint));
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000918 return true;
919 }
920
joshualitta7024152014-11-03 14:16:35 -0800921 if (!GrDrawTarget::canCopySurface(dst, src, clippedSrcRect, clippedDstPoint)) {
922 return false;
923 }
924
925 GrRenderTarget* rt = dst->asRenderTarget();
926 GrTexture* tex = src->asTexture();
927
928 GrDrawTarget::AutoStateRestore asr(this, kReset_ASRInit);
929 this->drawState()->setRenderTarget(rt);
930 SkMatrix matrix;
931 matrix.setTranslate(SkIntToScalar(clippedSrcRect.fLeft - clippedDstPoint.fX),
932 SkIntToScalar(clippedSrcRect.fTop - clippedDstPoint.fY));
933 matrix.postIDiv(tex->width(), tex->height());
934 this->drawState()->addColorTextureProcessor(tex, matrix);
935 SkIRect dstRect = SkIRect::MakeXYWH(clippedDstPoint.fX,
936 clippedDstPoint.fY,
937 clippedSrcRect.width(),
938 clippedSrcRect.height());
939 this->drawSimpleRect(dstRect);
940 return true;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000941}
942
943bool GrDrawTarget::canCopySurface(GrSurface* dst,
944 GrSurface* src,
945 const SkIRect& srcRect,
946 const SkIPoint& dstPoint) {
bsalomon49f085d2014-09-05 13:34:00 -0700947 SkASSERT(dst);
948 SkASSERT(src);
bsalomon@google.com116ad842013-04-09 15:38:19 +0000949
950 SkIRect clippedSrcRect;
951 SkIPoint clippedDstPoint;
952 // If the rect is outside the src or dst then we're guaranteed success
953 if (!clip_srcrect_and_dstpoint(dst,
954 src,
955 srcRect,
956 dstPoint,
957 &clippedSrcRect,
958 &clippedDstPoint)) {
959 return true;
960 }
bsalomon@google.com116ad842013-04-09 15:38:19 +0000961
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000962 // Check that the read/write rects are contained within the src/dst bounds.
joshualitta7024152014-11-03 14:16:35 -0800963 SkASSERT(!clippedSrcRect.isEmpty());
964 SkASSERT(SkIRect::MakeWH(src->width(), src->height()).contains(clippedSrcRect));
965 SkASSERT(clippedDstPoint.fX >= 0 && clippedDstPoint.fY >= 0);
966 SkASSERT(clippedDstPoint.fX + clippedSrcRect.width() <= dst->width() &&
967 clippedDstPoint.fY + clippedSrcRect.height() <= dst->height());
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000968
bsalomonafbf2d62014-09-30 12:18:44 -0700969 return !dst->surfacePriv().isSameAs(src) && dst->asRenderTarget() && src->asTexture();
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000970}
971
bsalomonf2703d82014-10-28 14:33:06 -0700972void GrDrawTarget::initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc) {
bsalomon@google.comeb851172013-04-15 13:51:00 +0000973 // Make the dst of the copy be a render target because the default copySurface draws to the dst.
974 desc->fOrigin = kDefault_GrSurfaceOrigin;
bsalomonf2703d82014-10-28 14:33:06 -0700975 desc->fFlags = kRenderTarget_GrSurfaceFlag | kNoStencil_GrSurfaceFlag;
bsalomon@google.comeb851172013-04-15 13:51:00 +0000976 desc->fConfig = src->config();
977}
978
bsalomon@google.combcce8922013-03-25 15:38:39 +0000979///////////////////////////////////////////////////////////////////////////////
980
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000981void GrDrawTargetCaps::reset() {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000982 fMipMapSupport = false;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000983 fNPOTTextureTileSupport = false;
984 fTwoSidedStencilSupport = false;
985 fStencilWrapOpsSupport = false;
986 fHWAALineSupport = false;
987 fShaderDerivativeSupport = false;
988 fGeometryShaderSupport = false;
skia.committer@gmail.come60ed082013-03-26 07:01:04 +0000989 fDualSourceBlendingSupport = false;
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000990 fPathRenderingSupport = false;
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000991 fDstReadInShaderSupport = false;
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +0000992 fDiscardRenderTargetSupport = false;
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000993 fReuseScratchTextures = true;
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000994 fGpuTracingSupport = false;
krajcevski786978162014-07-30 11:25:44 -0700995 fCompressedTexSubImageSupport = false;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000996
bsalomon63b21962014-11-05 07:05:34 -0800997 fUseDrawInsteadOfClear = false;
998
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000999 fMapBufferFlags = kNone_MapFlags;
1000
bsalomon@google.combcce8922013-03-25 15:38:39 +00001001 fMaxRenderTargetSize = 0;
1002 fMaxTextureSize = 0;
1003 fMaxSampleCount = 0;
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001004
1005 memset(fConfigRenderSupport, 0, sizeof(fConfigRenderSupport));
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001006 memset(fConfigTextureSupport, 0, sizeof(fConfigTextureSupport));
bsalomon@google.combcce8922013-03-25 15:38:39 +00001007}
1008
bsalomon@google.comc26d94f2013-03-25 18:19:00 +00001009GrDrawTargetCaps& GrDrawTargetCaps::operator=(const GrDrawTargetCaps& other) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +00001010 fMipMapSupport = other.fMipMapSupport;
bsalomon@google.combcce8922013-03-25 15:38:39 +00001011 fNPOTTextureTileSupport = other.fNPOTTextureTileSupport;
1012 fTwoSidedStencilSupport = other.fTwoSidedStencilSupport;
1013 fStencilWrapOpsSupport = other.fStencilWrapOpsSupport;
1014 fHWAALineSupport = other.fHWAALineSupport;
1015 fShaderDerivativeSupport = other.fShaderDerivativeSupport;
1016 fGeometryShaderSupport = other.fGeometryShaderSupport;
1017 fDualSourceBlendingSupport = other.fDualSourceBlendingSupport;
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +00001018 fPathRenderingSupport = other.fPathRenderingSupport;
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +00001019 fDstReadInShaderSupport = other.fDstReadInShaderSupport;
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +00001020 fDiscardRenderTargetSupport = other.fDiscardRenderTargetSupport;
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +00001021 fReuseScratchTextures = other.fReuseScratchTextures;
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +00001022 fGpuTracingSupport = other.fGpuTracingSupport;
krajcevski786978162014-07-30 11:25:44 -07001023 fCompressedTexSubImageSupport = other.fCompressedTexSubImageSupport;
bsalomon@google.combcce8922013-03-25 15:38:39 +00001024
bsalomon63b21962014-11-05 07:05:34 -08001025 fUseDrawInsteadOfClear = other.fUseDrawInsteadOfClear;
1026
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001027 fMapBufferFlags = other.fMapBufferFlags;
1028
bsalomon@google.combcce8922013-03-25 15:38:39 +00001029 fMaxRenderTargetSize = other.fMaxRenderTargetSize;
1030 fMaxTextureSize = other.fMaxTextureSize;
1031 fMaxSampleCount = other.fMaxSampleCount;
1032
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001033 memcpy(fConfigRenderSupport, other.fConfigRenderSupport, sizeof(fConfigRenderSupport));
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001034 memcpy(fConfigTextureSupport, other.fConfigTextureSupport, sizeof(fConfigTextureSupport));
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001035
bsalomon@google.combcce8922013-03-25 15:38:39 +00001036 return *this;
1037}
1038
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001039static SkString map_flags_to_string(uint32_t flags) {
1040 SkString str;
1041 if (GrDrawTargetCaps::kNone_MapFlags == flags) {
1042 str = "none";
1043 } else {
1044 SkASSERT(GrDrawTargetCaps::kCanMap_MapFlag & flags);
1045 SkDEBUGCODE(flags &= ~GrDrawTargetCaps::kCanMap_MapFlag);
1046 str = "can_map";
1047
1048 if (GrDrawTargetCaps::kSubset_MapFlag & flags) {
1049 str.append(" partial");
1050 } else {
1051 str.append(" full");
1052 }
1053 SkDEBUGCODE(flags &= ~GrDrawTargetCaps::kSubset_MapFlag);
1054 }
1055 SkASSERT(0 == flags); // Make sure we handled all the flags.
1056 return str;
1057}
1058
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001059SkString GrDrawTargetCaps::dump() const {
1060 SkString r;
bsalomon@google.com18c9c192011-09-22 21:01:31 +00001061 static const char* gNY[] = {"NO", "YES"};
bsalomon63b21962014-11-05 07:05:34 -08001062 r.appendf("MIP Map Support : %s\n", gNY[fMipMapSupport]);
1063 r.appendf("NPOT Texture Tile Support : %s\n", gNY[fNPOTTextureTileSupport]);
1064 r.appendf("Two Sided Stencil Support : %s\n", gNY[fTwoSidedStencilSupport]);
1065 r.appendf("Stencil Wrap Ops Support : %s\n", gNY[fStencilWrapOpsSupport]);
1066 r.appendf("HW AA Lines Support : %s\n", gNY[fHWAALineSupport]);
1067 r.appendf("Shader Derivative Support : %s\n", gNY[fShaderDerivativeSupport]);
1068 r.appendf("Geometry Shader Support : %s\n", gNY[fGeometryShaderSupport]);
1069 r.appendf("Dual Source Blending Support : %s\n", gNY[fDualSourceBlendingSupport]);
1070 r.appendf("Path Rendering Support : %s\n", gNY[fPathRenderingSupport]);
1071 r.appendf("Dst Read In Shader Support : %s\n", gNY[fDstReadInShaderSupport]);
1072 r.appendf("Discard Render Target Support : %s\n", gNY[fDiscardRenderTargetSupport]);
1073 r.appendf("Reuse Scratch Textures : %s\n", gNY[fReuseScratchTextures]);
1074 r.appendf("Gpu Tracing Support : %s\n", gNY[fGpuTracingSupport]);
1075 r.appendf("Compressed Update Support : %s\n", gNY[fCompressedTexSubImageSupport]);
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001076
bsalomon63b21962014-11-05 07:05:34 -08001077 r.appendf("Draw Instead of Clear [workaround] : %s\n", gNY[fUseDrawInsteadOfClear]);
1078
1079 r.appendf("Max Texture Size : %d\n", fMaxTextureSize);
1080 r.appendf("Max Render Target Size : %d\n", fMaxRenderTargetSize);
1081 r.appendf("Max Sample Count : %d\n", fMaxSampleCount);
1082
1083 r.appendf("Map Buffer Support : %s\n",
1084 map_flags_to_string(fMapBufferFlags).c_str());
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001085
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001086 static const char* kConfigNames[] = {
1087 "Unknown", // kUnknown_GrPixelConfig
1088 "Alpha8", // kAlpha_8_GrPixelConfig,
1089 "Index8", // kIndex_8_GrPixelConfig,
1090 "RGB565", // kRGB_565_GrPixelConfig,
1091 "RGBA444", // kRGBA_4444_GrPixelConfig,
1092 "RGBA8888", // kRGBA_8888_GrPixelConfig,
1093 "BGRA8888", // kBGRA_8888_GrPixelConfig,
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001094 "ETC1", // kETC1_GrPixelConfig,
1095 "LATC", // kLATC_GrPixelConfig,
krajcevski238b4562014-06-30 09:09:22 -07001096 "R11EAC", // kR11_EAC_GrPixelConfig,
krajcevski7ef21622014-07-16 15:21:13 -07001097 "ASTC12x12",// kASTC_12x12_GrPixelConfig,
joshualittee5da552014-07-16 13:32:56 -07001098 "RGBAFloat", // kRGBA_float_GrPixelConfig
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001099 };
krajcevski7ef21622014-07-16 15:21:13 -07001100 GR_STATIC_ASSERT(0 == kUnknown_GrPixelConfig);
1101 GR_STATIC_ASSERT(1 == kAlpha_8_GrPixelConfig);
1102 GR_STATIC_ASSERT(2 == kIndex_8_GrPixelConfig);
1103 GR_STATIC_ASSERT(3 == kRGB_565_GrPixelConfig);
1104 GR_STATIC_ASSERT(4 == kRGBA_4444_GrPixelConfig);
1105 GR_STATIC_ASSERT(5 == kRGBA_8888_GrPixelConfig);
1106 GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig);
1107 GR_STATIC_ASSERT(7 == kETC1_GrPixelConfig);
1108 GR_STATIC_ASSERT(8 == kLATC_GrPixelConfig);
1109 GR_STATIC_ASSERT(9 == kR11_EAC_GrPixelConfig);
1110 GR_STATIC_ASSERT(10 == kASTC_12x12_GrPixelConfig);
1111 GR_STATIC_ASSERT(11 == kRGBA_float_GrPixelConfig);
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001112 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kConfigNames) == kGrPixelConfigCnt);
1113
commit-bot@chromium.org99017272013-11-08 18:45:27 +00001114 SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][0]);
1115 SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][1]);
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001116
1117 for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) {
1118 r.appendf("%s is renderable: %s, with MSAA: %s\n",
1119 kConfigNames[i],
1120 gNY[fConfigRenderSupport[i][0]],
1121 gNY[fConfigRenderSupport[i][1]]);
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001122 }
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +00001123
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001124 SkASSERT(!fConfigTextureSupport[kUnknown_GrPixelConfig]);
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +00001125
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001126 for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) {
1127 r.appendf("%s is uploadable to a texture: %s\n",
1128 kConfigNames[i],
1129 gNY[fConfigTextureSupport[i]]);
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +00001130 }
1131
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001132 return r;
bsalomon@google.com18c9c192011-09-22 21:01:31 +00001133}
egdanielbc127a32014-09-19 12:07:43 -07001134
1135uint32_t GrDrawTargetCaps::CreateUniqueID() {
1136 static int32_t gUniqueID = SK_InvalidUniqueID;
1137 uint32_t id;
1138 do {
1139 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1);
1140 } while (id == SK_InvalidUniqueID);
1141 return id;
1142}
1143