blob: 2f395e666de203251b955954f5f638a74c6c890a [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
joshualitt7eb8c7b2014-11-18 14:24:27 -080044 this->setVertexBuffer(di.vertexBuffer());
45 this->setIndexBuffer(di.indexBuffer());
46
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000047 return *this;
48}
49
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +000050#ifdef SK_DEBUG
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000051bool GrDrawTarget::DrawInfo::isInstanced() const {
52 if (fInstanceCount > 0) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000053 SkASSERT(0 == fIndexCount % fIndicesPerInstance);
54 SkASSERT(0 == fVertexCount % fVerticesPerInstance);
55 SkASSERT(fIndexCount / fIndicesPerInstance == fInstanceCount);
56 SkASSERT(fVertexCount / fVerticesPerInstance == fInstanceCount);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000057 // there is no way to specify a non-zero start index to drawIndexedInstances().
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000058 SkASSERT(0 == fStartIndex);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000059 return true;
60 } else {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000061 SkASSERT(!fVerticesPerInstance);
62 SkASSERT(!fIndicesPerInstance);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000063 return false;
64 }
65}
66#endif
67
68void GrDrawTarget::DrawInfo::adjustInstanceCount(int instanceOffset) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000069 SkASSERT(this->isInstanced());
70 SkASSERT(instanceOffset + fInstanceCount >= 0);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000071 fInstanceCount += instanceOffset;
72 fVertexCount = fVerticesPerInstance * fInstanceCount;
73 fIndexCount = fIndicesPerInstance * fInstanceCount;
74}
75
76void GrDrawTarget::DrawInfo::adjustStartVertex(int vertexOffset) {
77 fStartVertex += vertexOffset;
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000078 SkASSERT(fStartVertex >= 0);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000079}
80
81void GrDrawTarget::DrawInfo::adjustStartIndex(int indexOffset) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000082 SkASSERT(this->isIndexed());
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000083 fStartIndex += indexOffset;
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000084 SkASSERT(fStartIndex >= 0);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000085}
86
87////////////////////////////////////////////////////////////////////////////////
88
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000089#define DEBUG_INVAL_BUFFER 0xdeadcafe
90#define DEBUG_INVAL_START_IDX -1
91
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000092GrDrawTarget::GrDrawTarget(GrContext* context)
93 : fClip(NULL)
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +000094 , fContext(context)
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +000095 , fGpuTraceMarkerCount(0) {
bsalomon49f085d2014-09-05 13:34:00 -070096 SkASSERT(context);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000097 GeometrySrcState& geoSrc = fGeoSrcStateStack.push_back();
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +000098#ifdef SK_DEBUG
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000099 geoSrc.fVertexCount = DEBUG_INVAL_START_IDX;
100 geoSrc.fVertexBuffer = (GrVertexBuffer*)DEBUG_INVAL_BUFFER;
101 geoSrc.fIndexCount = DEBUG_INVAL_START_IDX;
102 geoSrc.fIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER;
reed@google.comac10a2d2010-12-22 21:39:39 +0000103#endif
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000104 geoSrc.fVertexSrc = kNone_GeometrySrcType;
105 geoSrc.fIndexSrc = kNone_GeometrySrcType;
106}
107
108GrDrawTarget::~GrDrawTarget() {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000109 SkASSERT(1 == fGeoSrcStateStack.count());
humper@google.com0e515772013-01-07 19:54:40 +0000110 SkDEBUGCODE(GeometrySrcState& geoSrc = fGeoSrcStateStack.back());
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000111 SkASSERT(kNone_GeometrySrcType == geoSrc.fIndexSrc);
112 SkASSERT(kNone_GeometrySrcType == geoSrc.fVertexSrc);
bsalomon@google.com4a018bb2011-10-28 19:50:21 +0000113}
114
115void GrDrawTarget::releaseGeometry() {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000116 int popCnt = fGeoSrcStateStack.count() - 1;
117 while (popCnt) {
118 this->popGeometrySource();
119 --popCnt;
120 }
bsalomon@google.com4a018bb2011-10-28 19:50:21 +0000121 this->resetVertexSource();
122 this->resetIndexSource();
reed@google.comac10a2d2010-12-22 21:39:39 +0000123}
124
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000125void GrDrawTarget::setClip(const GrClipData* clip) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000126 fClip = clip;
127}
128
robertphillips@google.combeb1af72012-07-26 18:52:16 +0000129const GrClipData* GrDrawTarget::getClip() const {
reed@google.comac10a2d2010-12-22 21:39:39 +0000130 return fClip;
131}
132
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000133bool GrDrawTarget::reserveVertexSpace(size_t vertexSize,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000134 int vertexCount,
135 void** vertices) {
136 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
137 bool acquired = false;
138 if (vertexCount > 0) {
bsalomon49f085d2014-09-05 13:34:00 -0700139 SkASSERT(vertices);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000140 this->releasePreviousVertexSource();
141 geoSrc.fVertexSrc = kNone_GeometrySrcType;
reed@google.comac10a2d2010-12-22 21:39:39 +0000142
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000143 acquired = this->onReserveVertexSpace(vertexSize,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000144 vertexCount,
145 vertices);
reed@google.comac10a2d2010-12-22 21:39:39 +0000146 }
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000147 if (acquired) {
148 geoSrc.fVertexSrc = kReserved_GeometrySrcType;
149 geoSrc.fVertexCount = vertexCount;
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000150 geoSrc.fVertexSize = vertexSize;
bsalomon49f085d2014-09-05 13:34:00 -0700151 } else if (vertices) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000152 *vertices = NULL;
153 }
154 return acquired;
155}
156
157bool GrDrawTarget::reserveIndexSpace(int indexCount,
158 void** indices) {
159 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
160 bool acquired = false;
161 if (indexCount > 0) {
bsalomon49f085d2014-09-05 13:34:00 -0700162 SkASSERT(indices);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000163 this->releasePreviousIndexSource();
164 geoSrc.fIndexSrc = kNone_GeometrySrcType;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000165
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000166 acquired = this->onReserveIndexSpace(indexCount, indices);
167 }
168 if (acquired) {
169 geoSrc.fIndexSrc = kReserved_GeometrySrcType;
170 geoSrc.fIndexCount = indexCount;
bsalomon49f085d2014-09-05 13:34:00 -0700171 } else if (indices) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000172 *indices = NULL;
173 }
174 return acquired;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000175
reed@google.comac10a2d2010-12-22 21:39:39 +0000176}
177
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000178bool GrDrawTarget::reserveVertexAndIndexSpace(int vertexCount,
joshualitt9853cce2014-11-17 14:22:48 -0800179 size_t vertexStride,
bsalomon@google.come3d70952012-03-13 12:40:53 +0000180 int indexCount,
181 void** vertices,
182 void** indices) {
joshualitt9853cce2014-11-17 14:22:48 -0800183 this->willReserveVertexAndIndexSpace(vertexCount, vertexStride, indexCount);
bsalomon@google.come3d70952012-03-13 12:40:53 +0000184 if (vertexCount) {
egdaniel7b3d5ee2014-08-28 05:41:14 -0700185 if (!this->reserveVertexSpace(vertexStride, vertexCount, vertices)) {
bsalomon@google.come3d70952012-03-13 12:40:53 +0000186 if (indexCount) {
187 this->resetIndexSource();
188 }
189 return false;
190 }
191 }
192 if (indexCount) {
193 if (!this->reserveIndexSpace(indexCount, indices)) {
194 if (vertexCount) {
195 this->resetVertexSource();
196 }
197 return false;
198 }
199 }
200 return true;
201}
202
joshualitt9853cce2014-11-17 14:22:48 -0800203bool GrDrawTarget::geometryHints(size_t vertexStride,
204 int32_t* vertexCount,
reed@google.comac10a2d2010-12-22 21:39:39 +0000205 int32_t* indexCount) const {
bsalomon49f085d2014-09-05 13:34:00 -0700206 if (vertexCount) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000207 *vertexCount = -1;
208 }
bsalomon49f085d2014-09-05 13:34:00 -0700209 if (indexCount) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000210 *indexCount = -1;
211 }
212 return false;
213}
214
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000215void GrDrawTarget::releasePreviousVertexSource() {
216 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
217 switch (geoSrc.fVertexSrc) {
218 case kNone_GeometrySrcType:
219 break;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000220 case kReserved_GeometrySrcType:
221 this->releaseReservedVertexSpace();
222 break;
223 case kBuffer_GeometrySrcType:
224 geoSrc.fVertexBuffer->unref();
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000225#ifdef SK_DEBUG
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000226 geoSrc.fVertexBuffer = (GrVertexBuffer*)DEBUG_INVAL_BUFFER;
227#endif
228 break;
229 default:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000230 SkFAIL("Unknown Vertex Source Type.");
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000231 break;
232 }
233}
234
235void GrDrawTarget::releasePreviousIndexSource() {
236 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
237 switch (geoSrc.fIndexSrc) {
238 case kNone_GeometrySrcType: // these two don't require
239 break;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000240 case kReserved_GeometrySrcType:
241 this->releaseReservedIndexSpace();
242 break;
243 case kBuffer_GeometrySrcType:
244 geoSrc.fIndexBuffer->unref();
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000245#ifdef SK_DEBUG
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000246 geoSrc.fIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER;
247#endif
248 break;
249 default:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000250 SkFAIL("Unknown Index Source Type.");
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000251 break;
252 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000253}
254
joshualitt9853cce2014-11-17 14:22:48 -0800255void GrDrawTarget::setVertexSourceToBuffer(const GrVertexBuffer* buffer, size_t vertexStride) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000256 this->releasePreviousVertexSource();
257 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
258 geoSrc.fVertexSrc = kBuffer_GeometrySrcType;
259 geoSrc.fVertexBuffer = buffer;
260 buffer->ref();
joshualitt9853cce2014-11-17 14:22:48 -0800261 geoSrc.fVertexSize = vertexStride;
reed@google.comac10a2d2010-12-22 21:39:39 +0000262}
263
264void GrDrawTarget::setIndexSourceToBuffer(const GrIndexBuffer* buffer) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000265 this->releasePreviousIndexSource();
266 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
267 geoSrc.fIndexSrc = kBuffer_GeometrySrcType;
268 geoSrc.fIndexBuffer = buffer;
269 buffer->ref();
reed@google.comac10a2d2010-12-22 21:39:39 +0000270}
271
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000272void GrDrawTarget::resetVertexSource() {
273 this->releasePreviousVertexSource();
274 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
275 geoSrc.fVertexSrc = kNone_GeometrySrcType;
276}
277
278void GrDrawTarget::resetIndexSource() {
279 this->releasePreviousIndexSource();
280 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
281 geoSrc.fIndexSrc = kNone_GeometrySrcType;
282}
283
284void GrDrawTarget::pushGeometrySource() {
285 this->geometrySourceWillPush();
286 GeometrySrcState& newState = fGeoSrcStateStack.push_back();
287 newState.fIndexSrc = kNone_GeometrySrcType;
288 newState.fVertexSrc = kNone_GeometrySrcType;
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000289#ifdef SK_DEBUG
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000290 newState.fVertexCount = ~0;
291 newState.fVertexBuffer = (GrVertexBuffer*)~0;
292 newState.fIndexCount = ~0;
293 newState.fIndexBuffer = (GrIndexBuffer*)~0;
294#endif
295}
296
297void GrDrawTarget::popGeometrySource() {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000298 // if popping last element then pops are unbalanced with pushes
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000299 SkASSERT(fGeoSrcStateStack.count() > 1);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000300
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000301 this->geometrySourceWillPop(fGeoSrcStateStack.fromBack(1));
302 this->releasePreviousVertexSource();
303 this->releasePreviousIndexSource();
304 fGeoSrcStateStack.pop_back();
305}
306
307////////////////////////////////////////////////////////////////////////////////
308
joshualitt9853cce2014-11-17 14:22:48 -0800309bool GrDrawTarget::checkDraw(const GrDrawState& drawState,
310 GrPrimitiveType type,
311 int startVertex,
312 int startIndex,
313 int vertexCount,
bsalomon@google.come8262622011-11-07 02:30:51 +0000314 int indexCount) const {
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000315#ifdef SK_DEBUG
bsalomon@google.come8262622011-11-07 02:30:51 +0000316 const GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000317 int maxVertex = startVertex + vertexCount;
318 int maxValidVertex;
319 switch (geoSrc.fVertexSrc) {
320 case kNone_GeometrySrcType:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000321 SkFAIL("Attempting to draw without vertex src.");
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000322 case kReserved_GeometrySrcType: // fallthrough
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000323 maxValidVertex = geoSrc.fVertexCount;
324 break;
325 case kBuffer_GeometrySrcType:
commit-bot@chromium.org089a7802014-05-02 21:38:22 +0000326 maxValidVertex = static_cast<int>(geoSrc.fVertexBuffer->gpuMemorySize() / geoSrc.fVertexSize);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000327 break;
328 }
329 if (maxVertex > maxValidVertex) {
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000330 SkFAIL("Drawing outside valid vertex range.");
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000331 }
bsalomon@google.come8262622011-11-07 02:30:51 +0000332 if (indexCount > 0) {
333 int maxIndex = startIndex + indexCount;
334 int maxValidIndex;
335 switch (geoSrc.fIndexSrc) {
336 case kNone_GeometrySrcType:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000337 SkFAIL("Attempting to draw indexed geom without index src.");
bsalomon@google.come8262622011-11-07 02:30:51 +0000338 case kReserved_GeometrySrcType: // fallthrough
bsalomon@google.come8262622011-11-07 02:30:51 +0000339 maxValidIndex = geoSrc.fIndexCount;
340 break;
341 case kBuffer_GeometrySrcType:
commit-bot@chromium.org089a7802014-05-02 21:38:22 +0000342 maxValidIndex = static_cast<int>(geoSrc.fIndexBuffer->gpuMemorySize() / sizeof(uint16_t));
bsalomon@google.come8262622011-11-07 02:30:51 +0000343 break;
344 }
345 if (maxIndex > maxValidIndex) {
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000346 SkFAIL("Index reads outside valid index range.");
bsalomon@google.come8262622011-11-07 02:30:51 +0000347 }
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000348 }
bsalomon@google.comb4725b42012-03-30 17:24:17 +0000349
bsalomon49f085d2014-09-05 13:34:00 -0700350 SkASSERT(drawState.getRenderTarget());
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000351
joshualittbd769d02014-09-04 08:56:46 -0700352 if (drawState.hasGeometryProcessor()) {
joshualitta5305a12014-10-10 17:47:00 -0700353 const GrGeometryProcessor* gp = drawState.getGeometryProcessor();
joshualittb0a8a372014-09-23 09:50:21 -0700354 int numTextures = gp->numTextures();
joshualittbd769d02014-09-04 08:56:46 -0700355 for (int t = 0; t < numTextures; ++t) {
joshualittb0a8a372014-09-23 09:50:21 -0700356 GrTexture* texture = gp->texture(t);
joshualittbd769d02014-09-04 08:56:46 -0700357 SkASSERT(texture->asRenderTarget() != drawState.getRenderTarget());
358 }
359 }
360
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000361 for (int s = 0; s < drawState.numColorStages(); ++s) {
joshualittb0a8a372014-09-23 09:50:21 -0700362 const GrProcessor* effect = drawState.getColorStage(s).getProcessor();
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000363 int numTextures = effect->numTextures();
364 for (int t = 0; t < numTextures; ++t) {
365 GrTexture* texture = effect->texture(t);
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000366 SkASSERT(texture->asRenderTarget() != drawState.getRenderTarget());
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000367 }
368 }
369 for (int s = 0; s < drawState.numCoverageStages(); ++s) {
joshualittb0a8a372014-09-23 09:50:21 -0700370 const GrProcessor* effect = drawState.getCoverageStage(s).getProcessor();
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000371 int numTextures = effect->numTextures();
372 for (int t = 0; t < numTextures; ++t) {
373 GrTexture* texture = effect->texture(t);
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000374 SkASSERT(texture->asRenderTarget() != drawState.getRenderTarget());
bsalomon@google.comb4725b42012-03-30 17:24:17 +0000375 }
376 }
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000377
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000378 SkASSERT(drawState.validateVertexAttribs());
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000379#endif
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000380 if (NULL == drawState.getRenderTarget()) {
bsalomon@google.com0ba52fc2011-11-10 22:16:06 +0000381 return false;
382 }
bsalomon@google.come8262622011-11-07 02:30:51 +0000383 return true;
384}
385
joshualitt9853cce2014-11-17 14:22:48 -0800386bool GrDrawTarget::setupDstReadIfNecessary(GrDrawState* ds,
387 GrDeviceCoordTexture* dstCopy,
388 const SkRect* drawBounds) {
389 if (this->caps()->dstReadInShaderSupport() || !ds->willEffectReadDstColor()) {
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000390 return true;
391 }
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000392 SkIRect copyRect;
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000393 const GrClipData* clip = this->getClip();
joshualitt9853cce2014-11-17 14:22:48 -0800394 GrRenderTarget* rt = ds->getRenderTarget();
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000395 clip->getConservativeBounds(rt, &copyRect);
396
bsalomon49f085d2014-09-05 13:34:00 -0700397 if (drawBounds) {
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000398 SkIRect drawIBounds;
399 drawBounds->roundOut(&drawIBounds);
commit-bot@chromium.orgbb5c4652013-04-01 12:49:31 +0000400 if (!copyRect.intersect(drawIBounds)) {
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000401#ifdef SK_DEBUG
tfarina38406c82014-10-31 07:11:12 -0700402 SkDebugf("Missed an early reject. Bailing on draw from setupDstReadIfNecessary.\n");
commit-bot@chromium.orgbb5c4652013-04-01 12:49:31 +0000403#endif
404 return false;
405 }
406 } else {
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000407#ifdef SK_DEBUG
tfarina38406c82014-10-31 07:11:12 -0700408 //SkDebugf("No dev bounds when dst copy is made.\n");
commit-bot@chromium.orgbb5c4652013-04-01 12:49:31 +0000409#endif
410 }
skia.committer@gmail.com05a2ee02013-04-02 07:01:34 +0000411
commit-bot@chromium.org63150af2013-04-11 22:00:22 +0000412 // MSAA consideration: When there is support for reading MSAA samples in the shader we could
413 // have per-sample dst values by making the copy multisampled.
bsalomonf2703d82014-10-28 14:33:06 -0700414 GrSurfaceDesc desc;
bsalomon@google.comeb851172013-04-15 13:51:00 +0000415 this->initCopySurfaceDstDesc(rt, &desc);
commit-bot@chromium.orgbb5c4652013-04-01 12:49:31 +0000416 desc.fWidth = copyRect.width();
417 desc.fHeight = copyRect.height();
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000418
bsalomone3059732014-10-14 11:47:22 -0700419 SkAutoTUnref<GrTexture> copy(
420 fContext->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch));
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000421
bsalomone3059732014-10-14 11:47:22 -0700422 if (!copy) {
tfarina38406c82014-10-31 07:11:12 -0700423 SkDebugf("Failed to create temporary copy of destination texture.\n");
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000424 return false;
425 }
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000426 SkIPoint dstPoint = {0, 0};
bsalomone3059732014-10-14 11:47:22 -0700427 if (this->copySurface(copy, rt, copyRect, dstPoint)) {
428 dstCopy->setTexture(copy);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000429 dstCopy->setOffset(copyRect.fLeft, copyRect.fTop);
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000430 return true;
431 } else {
432 return false;
433 }
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000434}
435
joshualitt9853cce2014-11-17 14:22:48 -0800436void GrDrawTarget::drawIndexed(GrDrawState* ds,
437 GrPrimitiveType type,
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000438 int startVertex,
439 int startIndex,
440 int vertexCount,
441 int indexCount,
442 const SkRect* devBounds) {
joshualitt9853cce2014-11-17 14:22:48 -0800443 SkASSERT(ds);
444 if (indexCount > 0 &&
445 this->checkDraw(*ds, type, startVertex, startIndex, vertexCount, indexCount)) {
446
joshualitt2c93efe2014-11-06 12:57:13 -0800447 // Setup clip
448 GrClipMaskManager::ScissorState scissorState;
449 GrDrawState::AutoRestoreEffects are;
450 GrDrawState::AutoRestoreStencil ars;
joshualitt9853cce2014-11-17 14:22:48 -0800451 if (!this->setupClip(devBounds, &are, &ars, ds, &scissorState)) {
joshualitt2c93efe2014-11-06 12:57:13 -0800452 return;
453 }
454
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000455 DrawInfo info;
456 info.fPrimitiveType = type;
457 info.fStartVertex = startVertex;
458 info.fStartIndex = startIndex;
459 info.fVertexCount = vertexCount;
460 info.fIndexCount = indexCount;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000461
462 info.fInstanceCount = 0;
463 info.fVerticesPerInstance = 0;
464 info.fIndicesPerInstance = 0;
465
bsalomon49f085d2014-09-05 13:34:00 -0700466 if (devBounds) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000467 info.setDevBounds(*devBounds);
468 }
joshualitt9176e2c2014-11-20 07:28:52 -0800469
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000470 // TODO: We should continue with incorrect blending.
joshualitt9176e2c2014-11-20 07:28:52 -0800471 GrDeviceCoordTexture dstCopy;
472 if (!this->setupDstReadIfNecessary(ds, &dstCopy, devBounds)) {
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000473 return;
474 }
joshualitt7eb8c7b2014-11-18 14:24:27 -0800475 this->setDrawBuffers(&info);
476
joshualitt9176e2c2014-11-20 07:28:52 -0800477 this->onDraw(*ds, info, scissorState, dstCopy.texture() ? &dstCopy : NULL);
bsalomon@google.com82145872011-08-23 14:32:40 +0000478 }
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000479}
480
joshualitt9853cce2014-11-17 14:22:48 -0800481void GrDrawTarget::drawNonIndexed(GrDrawState* ds,
482 GrPrimitiveType type,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000483 int startVertex,
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000484 int vertexCount,
485 const SkRect* devBounds) {
joshualitt9853cce2014-11-17 14:22:48 -0800486 SkASSERT(ds);
487 if (vertexCount > 0 && this->checkDraw(*ds, type, startVertex, -1, vertexCount, -1)) {
488
joshualitt2c93efe2014-11-06 12:57:13 -0800489 // Setup clip
490 GrClipMaskManager::ScissorState scissorState;
491 GrDrawState::AutoRestoreEffects are;
492 GrDrawState::AutoRestoreStencil ars;
joshualitt9853cce2014-11-17 14:22:48 -0800493 if (!this->setupClip(devBounds, &are, &ars, ds, &scissorState)) {
joshualitt2c93efe2014-11-06 12:57:13 -0800494 return;
495 }
496
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000497 DrawInfo info;
498 info.fPrimitiveType = type;
499 info.fStartVertex = startVertex;
500 info.fStartIndex = 0;
501 info.fVertexCount = vertexCount;
502 info.fIndexCount = 0;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000503
504 info.fInstanceCount = 0;
505 info.fVerticesPerInstance = 0;
506 info.fIndicesPerInstance = 0;
507
bsalomon49f085d2014-09-05 13:34:00 -0700508 if (devBounds) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000509 info.setDevBounds(*devBounds);
510 }
joshualitt2c93efe2014-11-06 12:57:13 -0800511
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000512 // TODO: We should continue with incorrect blending.
joshualitt9176e2c2014-11-20 07:28:52 -0800513 GrDeviceCoordTexture dstCopy;
514 if (!this->setupDstReadIfNecessary(ds, &dstCopy, devBounds)) {
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000515 return;
516 }
joshualitt7eb8c7b2014-11-18 14:24:27 -0800517
518 this->setDrawBuffers(&info);
519
joshualitt9176e2c2014-11-20 07:28:52 -0800520 this->onDraw(*ds, info, scissorState, dstCopy.texture() ? &dstCopy : NULL);
bsalomon@google.com82145872011-08-23 14:32:40 +0000521 }
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000522}
523
joshualitt2c93efe2014-11-06 12:57:13 -0800524static const GrStencilSettings& winding_path_stencil_settings() {
525 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings,
526 kIncClamp_StencilOp,
527 kIncClamp_StencilOp,
528 kAlwaysIfInClip_StencilFunc,
529 0xFFFF, 0xFFFF, 0xFFFF);
530 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings);
531}
532
533static const GrStencilSettings& even_odd_path_stencil_settings() {
534 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings,
535 kInvert_StencilOp,
536 kInvert_StencilOp,
537 kAlwaysIfInClip_StencilFunc,
538 0xFFFF, 0xFFFF, 0xFFFF);
539 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings);
540}
541
542void GrDrawTarget::getPathStencilSettingsForFilltype(GrPathRendering::FillType fill,
joshualitt9853cce2014-11-17 14:22:48 -0800543 const GrStencilBuffer* sb,
joshualitt2c93efe2014-11-06 12:57:13 -0800544 GrStencilSettings* outStencilSettings) {
545
546 switch (fill) {
547 default:
548 SkFAIL("Unexpected path fill.");
549 case GrPathRendering::kWinding_FillType:
550 *outStencilSettings = winding_path_stencil_settings();
551 break;
552 case GrPathRendering::kEvenOdd_FillType:
553 *outStencilSettings = even_odd_path_stencil_settings();
554 break;
555 }
joshualitt9853cce2014-11-17 14:22:48 -0800556 this->clipMaskManager()->adjustPathStencilParams(sb, outStencilSettings);
joshualitt2c93efe2014-11-06 12:57:13 -0800557}
558
joshualitt9853cce2014-11-17 14:22:48 -0800559void GrDrawTarget::stencilPath(GrDrawState* ds,
560 const GrPath* path,
561 GrPathRendering::FillType fill) {
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000562 // TODO: extract portions of checkDraw that are relevant to path stenciling.
bsalomon49f085d2014-09-05 13:34:00 -0700563 SkASSERT(path);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000564 SkASSERT(this->caps()->pathRenderingSupport());
joshualitt9853cce2014-11-17 14:22:48 -0800565 SkASSERT(ds);
joshualitt2c93efe2014-11-06 12:57:13 -0800566
567 // Setup clip
568 GrClipMaskManager::ScissorState scissorState;
569 GrDrawState::AutoRestoreEffects are;
570 GrDrawState::AutoRestoreStencil ars;
joshualitt9853cce2014-11-17 14:22:48 -0800571 if (!this->setupClip(NULL, &are, &ars, ds, &scissorState)) {
joshualitt2c93efe2014-11-06 12:57:13 -0800572 return;
573 }
574
575 // set stencil settings for path
576 GrStencilSettings stencilSettings;
joshualitt9853cce2014-11-17 14:22:48 -0800577 this->getPathStencilSettingsForFilltype(fill,
578 ds->getRenderTarget()->getStencilBuffer(),
579 &stencilSettings);
joshualitt2c93efe2014-11-06 12:57:13 -0800580
joshualitt9853cce2014-11-17 14:22:48 -0800581 this->onStencilPath(*ds, path, scissorState, stencilSettings);
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000582}
583
joshualitt9853cce2014-11-17 14:22:48 -0800584void GrDrawTarget::drawPath(GrDrawState* ds,
585 const GrPath* path,
586 GrPathRendering::FillType fill) {
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000587 // TODO: extract portions of checkDraw that are relevant to path rendering.
bsalomon49f085d2014-09-05 13:34:00 -0700588 SkASSERT(path);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000589 SkASSERT(this->caps()->pathRenderingSupport());
joshualitt9853cce2014-11-17 14:22:48 -0800590 SkASSERT(ds);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000591
joshualitt92e496f2014-10-31 13:56:50 -0700592 SkRect devBounds = path->getBounds();
joshualitt9853cce2014-11-17 14:22:48 -0800593 SkMatrix viewM = ds->getViewMatrix();
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000594 viewM.mapRect(&devBounds);
595
joshualitt2c93efe2014-11-06 12:57:13 -0800596 // Setup clip
597 GrClipMaskManager::ScissorState scissorState;
598 GrDrawState::AutoRestoreEffects are;
599 GrDrawState::AutoRestoreStencil ars;
joshualitt9853cce2014-11-17 14:22:48 -0800600 if (!this->setupClip(&devBounds, &are, &ars, ds, &scissorState)) {
joshualitt2c93efe2014-11-06 12:57:13 -0800601 return;
602 }
603
604 // set stencil settings for path
605 GrStencilSettings stencilSettings;
joshualitt9853cce2014-11-17 14:22:48 -0800606 this->getPathStencilSettingsForFilltype(fill,
607 ds->getRenderTarget()->getStencilBuffer(),
608 &stencilSettings);
joshualitt2c93efe2014-11-06 12:57:13 -0800609
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000610 GrDeviceCoordTexture dstCopy;
joshualitt9853cce2014-11-17 14:22:48 -0800611 if (!this->setupDstReadIfNecessary(ds, &dstCopy, &devBounds)) {
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000612 return;
613 }
614
joshualitt9853cce2014-11-17 14:22:48 -0800615 this->onDrawPath(*ds, path, scissorState, stencilSettings, dstCopy.texture() ? &dstCopy : NULL);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000616}
617
joshualitt9853cce2014-11-17 14:22:48 -0800618void GrDrawTarget::drawPaths(GrDrawState* ds,
619 const GrPathRange* pathRange,
620 const uint32_t indices[],
621 int count,
622 const float transforms[],
623 PathTransformType transformsType,
joshualitt92e496f2014-10-31 13:56:50 -0700624 GrPathRendering::FillType fill) {
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000625 SkASSERT(this->caps()->pathRenderingSupport());
bsalomon49f085d2014-09-05 13:34:00 -0700626 SkASSERT(pathRange);
627 SkASSERT(indices);
628 SkASSERT(transforms);
joshualitt9853cce2014-11-17 14:22:48 -0800629 SkASSERT(ds);
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000630
joshualitt2c93efe2014-11-06 12:57:13 -0800631 // Setup clip
632 GrClipMaskManager::ScissorState scissorState;
633 GrDrawState::AutoRestoreEffects are;
634 GrDrawState::AutoRestoreStencil ars;
635
joshualitt9853cce2014-11-17 14:22:48 -0800636 if (!this->setupClip(NULL, &are, &ars, ds, &scissorState)) {
joshualitt2c93efe2014-11-06 12:57:13 -0800637 return;
638 }
639
640 // set stencil settings for path
641 GrStencilSettings stencilSettings;
joshualitt9853cce2014-11-17 14:22:48 -0800642 this->getPathStencilSettingsForFilltype(fill,
643 ds->getRenderTarget()->getStencilBuffer(),
644 &stencilSettings);
joshualitt2c93efe2014-11-06 12:57:13 -0800645
cdaltonb85a0aa2014-07-21 15:32:44 -0700646 // Don't compute a bounding box for setupDstReadIfNecessary(), we'll opt
647 // instead for it to just copy the entire dst. Realistically this is a moot
648 // point, because any context that supports NV_path_rendering will also
649 // support NV_blend_equation_advanced.
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000650 GrDeviceCoordTexture dstCopy;
joshualitt9853cce2014-11-17 14:22:48 -0800651 if (!this->setupDstReadIfNecessary(ds, &dstCopy, NULL)) {
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000652 return;
653 }
654
joshualitt9853cce2014-11-17 14:22:48 -0800655 this->onDrawPaths(*ds, pathRange, indices, count, transforms, transformsType, scissorState,
joshualitt2c93efe2014-11-06 12:57:13 -0800656 stencilSettings, dstCopy.texture() ? &dstCopy : NULL);
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000657}
658
joshualitt9853cce2014-11-17 14:22:48 -0800659void GrDrawTarget::clear(const SkIRect* rect,
660 GrColor color,
661 bool canIgnoreRect,
bsalomon63b21962014-11-05 07:05:34 -0800662 GrRenderTarget* renderTarget) {
663 if (fCaps->useDrawInsteadOfClear()) {
664 // This works around a driver bug with clear by drawing a rect instead.
665 // The driver will ignore a clear if it is the only thing rendered to a
666 // target before the target is read.
667 SkIRect rtRect = SkIRect::MakeWH(renderTarget->width(), renderTarget->height());
668 if (NULL == rect || canIgnoreRect || rect->contains(rtRect)) {
669 rect = &rtRect;
670 // We first issue a discard() since that may help tilers.
671 this->discard(renderTarget);
672 }
bsalomon63b21962014-11-05 07:05:34 -0800673
joshualitt9853cce2014-11-17 14:22:48 -0800674 GrDrawState drawState;
bsalomon63b21962014-11-05 07:05:34 -0800675
joshualitt9853cce2014-11-17 14:22:48 -0800676 drawState.setColor(color);
677 drawState.setRenderTarget(renderTarget);
678
679 this->drawSimpleRect(&drawState, *rect);
bsalomon63b21962014-11-05 07:05:34 -0800680 } else {
681 this->onClear(rect, color, canIgnoreRect, renderTarget);
682 }
683}
684
egdaniel3eee3832014-06-18 13:09:11 -0700685typedef GrTraceMarkerSet::Iter TMIter;
686void GrDrawTarget::saveActiveTraceMarkers() {
687 if (this->caps()->gpuTracingSupport()) {
688 SkASSERT(0 == fStoredTraceMarkers.count());
689 fStoredTraceMarkers.addSet(fActiveTraceMarkers);
690 for (TMIter iter = fStoredTraceMarkers.begin(); iter != fStoredTraceMarkers.end(); ++iter) {
691 this->removeGpuTraceMarker(&(*iter));
692 }
693 }
694}
695
696void GrDrawTarget::restoreActiveTraceMarkers() {
697 if (this->caps()->gpuTracingSupport()) {
698 SkASSERT(0 == fActiveTraceMarkers.count());
699 for (TMIter iter = fStoredTraceMarkers.begin(); iter != fStoredTraceMarkers.end(); ++iter) {
700 this->addGpuTraceMarker(&(*iter));
701 }
702 for (TMIter iter = fActiveTraceMarkers.begin(); iter != fActiveTraceMarkers.end(); ++iter) {
703 this->fStoredTraceMarkers.remove(*iter);
704 }
705 }
706}
707
708void GrDrawTarget::addGpuTraceMarker(const GrGpuTraceMarker* marker) {
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000709 if (this->caps()->gpuTracingSupport()) {
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000710 SkASSERT(fGpuTraceMarkerCount >= 0);
711 this->fActiveTraceMarkers.add(*marker);
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000712 ++fGpuTraceMarkerCount;
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000713 }
714}
715
egdaniel3eee3832014-06-18 13:09:11 -0700716void GrDrawTarget::removeGpuTraceMarker(const GrGpuTraceMarker* marker) {
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000717 if (this->caps()->gpuTracingSupport()) {
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000718 SkASSERT(fGpuTraceMarkerCount >= 1);
719 this->fActiveTraceMarkers.remove(*marker);
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000720 --fGpuTraceMarkerCount;
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000721 }
722}
723
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000724////////////////////////////////////////////////////////////////////////////////
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000725
joshualitt9853cce2014-11-17 14:22:48 -0800726void GrDrawTarget::drawIndexedInstances(GrDrawState* ds,
727 GrPrimitiveType type,
bsalomon@google.com934c5702012-03-20 21:17:58 +0000728 int instanceCount,
729 int verticesPerInstance,
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000730 int indicesPerInstance,
731 const SkRect* devBounds) {
joshualitt9853cce2014-11-17 14:22:48 -0800732 SkASSERT(ds);
733
bsalomon@google.com934c5702012-03-20 21:17:58 +0000734 if (!verticesPerInstance || !indicesPerInstance) {
735 return;
736 }
737
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000738 int maxInstancesPerDraw = this->indexCountInCurrentSource() / indicesPerInstance;
739 if (!maxInstancesPerDraw) {
bsalomon@google.com934c5702012-03-20 21:17:58 +0000740 return;
741 }
742
joshualitt2c93efe2014-11-06 12:57:13 -0800743 // Setup clip
744 GrClipMaskManager::ScissorState scissorState;
745 GrDrawState::AutoRestoreEffects are;
746 GrDrawState::AutoRestoreStencil ars;
joshualitt9853cce2014-11-17 14:22:48 -0800747 if (!this->setupClip(devBounds, &are, &ars, ds, &scissorState)) {
joshualitt2c93efe2014-11-06 12:57:13 -0800748 return;
749 }
750
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000751 DrawInfo info;
752 info.fPrimitiveType = type;
753 info.fStartIndex = 0;
754 info.fStartVertex = 0;
755 info.fIndicesPerInstance = indicesPerInstance;
756 info.fVerticesPerInstance = verticesPerInstance;
757
758 // Set the same bounds for all the draws.
bsalomon49f085d2014-09-05 13:34:00 -0700759 if (devBounds) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000760 info.setDevBounds(*devBounds);
761 }
joshualitt9176e2c2014-11-20 07:28:52 -0800762
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000763 // TODO: We should continue with incorrect blending.
joshualitt9176e2c2014-11-20 07:28:52 -0800764 GrDeviceCoordTexture dstCopy;
765 if (!this->setupDstReadIfNecessary(ds, &dstCopy, devBounds)) {
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000766 return;
767 }
joshualitt7eb8c7b2014-11-18 14:24:27 -0800768
bsalomon@google.com934c5702012-03-20 21:17:58 +0000769 while (instanceCount) {
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000770 info.fInstanceCount = SkTMin(instanceCount, maxInstancesPerDraw);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000771 info.fVertexCount = info.fInstanceCount * verticesPerInstance;
772 info.fIndexCount = info.fInstanceCount * indicesPerInstance;
773
joshualitt7eb8c7b2014-11-18 14:24:27 -0800774 this->setDrawBuffers(&info);
775
joshualitt9853cce2014-11-17 14:22:48 -0800776 if (this->checkDraw(*ds,
777 type,
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000778 info.fStartVertex,
779 info.fStartIndex,
780 info.fVertexCount,
781 info.fIndexCount)) {
joshualitt9176e2c2014-11-20 07:28:52 -0800782 this->onDraw(*ds, info, scissorState, dstCopy.texture() ? &dstCopy : NULL);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000783 }
784 info.fStartVertex += info.fVertexCount;
785 instanceCount -= info.fInstanceCount;
bsalomon@google.com934c5702012-03-20 21:17:58 +0000786 }
787}
bsalomon@google.com3d0835b2011-12-08 16:12:03 +0000788
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000789////////////////////////////////////////////////////////////////////////////////
790
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,
joshualitt9853cce2014-11-17 14:22:48 -0800794 size_t vertexStride,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000795 int indexCount) {
796 fTarget = NULL;
joshualitt9853cce2014-11-17 14:22:48 -0800797 this->set(target, vertexCount, vertexStride, indexCount);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000798}
rmistry@google.comd6176b02012-08-23 18:14:13 +0000799
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000800GrDrawTarget::AutoReleaseGeometry::AutoReleaseGeometry() {
801 fTarget = NULL;
802}
803
804GrDrawTarget::AutoReleaseGeometry::~AutoReleaseGeometry() {
805 this->reset();
806}
807
808bool GrDrawTarget::AutoReleaseGeometry::set(GrDrawTarget* target,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000809 int vertexCount,
joshualitt9853cce2014-11-17 14:22:48 -0800810 size_t vertexStride,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000811 int indexCount) {
812 this->reset();
813 fTarget = target;
814 bool success = true;
bsalomon49f085d2014-09-05 13:34:00 -0700815 if (fTarget) {
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000816 success = target->reserveVertexAndIndexSpace(vertexCount,
joshualitt9853cce2014-11-17 14:22:48 -0800817 vertexStride,
bsalomon@google.come3d70952012-03-13 12:40:53 +0000818 indexCount,
819 &fVertices,
820 &fIndices);
821 if (!success) {
822 fTarget = NULL;
823 this->reset();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000824 }
825 }
bsalomon49f085d2014-09-05 13:34:00 -0700826 SkASSERT(success == SkToBool(fTarget));
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000827 return success;
828}
829
830void GrDrawTarget::AutoReleaseGeometry::reset() {
bsalomon49f085d2014-09-05 13:34:00 -0700831 if (fTarget) {
832 if (fVertices) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000833 fTarget->resetVertexSource();
834 }
bsalomon49f085d2014-09-05 13:34:00 -0700835 if (fIndices) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000836 fTarget->resetIndexSource();
837 }
838 fTarget = NULL;
839 }
bsalomon@google.comcb0c5ab2011-06-29 17:48:17 +0000840 fVertices = NULL;
841 fIndices = NULL;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000842}
843
bsalomon@google.com8d67c072012-12-13 20:38:14 +0000844GrDrawTarget::AutoClipRestore::AutoClipRestore(GrDrawTarget* target, const SkIRect& newClip) {
845 fTarget = target;
846 fClip = fTarget->getClip();
847 fStack.init();
848 fStack.get()->clipDevRect(newClip, SkRegion::kReplace_Op);
849 fReplacementClip.fClipStack = fStack.get();
850 target->setClip(&fReplacementClip);
851}
852
bsalomon@google.com116ad842013-04-09 15:38:19 +0000853namespace {
854// returns true if the read/written rect intersects the src/dst and false if not.
855bool clip_srcrect_and_dstpoint(const GrSurface* dst,
856 const GrSurface* src,
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000857 const SkIRect& srcRect,
bsalomon@google.com116ad842013-04-09 15:38:19 +0000858 const SkIPoint& dstPoint,
859 SkIRect* clippedSrcRect,
860 SkIPoint* clippedDstPoint) {
861 *clippedSrcRect = srcRect;
862 *clippedDstPoint = dstPoint;
skia.committer@gmail.coma9493a32013-04-04 07:01:12 +0000863
bsalomon@google.com116ad842013-04-09 15:38:19 +0000864 // clip the left edge to src and dst bounds, adjusting dstPoint if necessary
865 if (clippedSrcRect->fLeft < 0) {
866 clippedDstPoint->fX -= clippedSrcRect->fLeft;
867 clippedSrcRect->fLeft = 0;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000868 }
bsalomon@google.com116ad842013-04-09 15:38:19 +0000869 if (clippedDstPoint->fX < 0) {
870 clippedSrcRect->fLeft -= clippedDstPoint->fX;
871 clippedDstPoint->fX = 0;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000872 }
873
bsalomon@google.com116ad842013-04-09 15:38:19 +0000874 // clip the top edge to src and dst bounds, adjusting dstPoint if necessary
875 if (clippedSrcRect->fTop < 0) {
876 clippedDstPoint->fY -= clippedSrcRect->fTop;
877 clippedSrcRect->fTop = 0;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000878 }
bsalomon@google.com116ad842013-04-09 15:38:19 +0000879 if (clippedDstPoint->fY < 0) {
880 clippedSrcRect->fTop -= clippedDstPoint->fY;
881 clippedDstPoint->fY = 0;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000882 }
skia.committer@gmail.coma9493a32013-04-04 07:01:12 +0000883
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000884 // clip the right edge to the src and dst bounds.
bsalomon@google.com116ad842013-04-09 15:38:19 +0000885 if (clippedSrcRect->fRight > src->width()) {
886 clippedSrcRect->fRight = src->width();
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000887 }
bsalomon@google.com116ad842013-04-09 15:38:19 +0000888 if (clippedDstPoint->fX + clippedSrcRect->width() > dst->width()) {
889 clippedSrcRect->fRight = clippedSrcRect->fLeft + dst->width() - clippedDstPoint->fX;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000890 }
891
892 // clip the bottom edge to the src and dst bounds.
bsalomon@google.com116ad842013-04-09 15:38:19 +0000893 if (clippedSrcRect->fBottom > src->height()) {
894 clippedSrcRect->fBottom = src->height();
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000895 }
bsalomon@google.com116ad842013-04-09 15:38:19 +0000896 if (clippedDstPoint->fY + clippedSrcRect->height() > dst->height()) {
897 clippedSrcRect->fBottom = clippedSrcRect->fTop + dst->height() - clippedDstPoint->fY;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000898 }
skia.committer@gmail.coma9493a32013-04-04 07:01:12 +0000899
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000900 // The above clipping steps may have inverted the rect if it didn't intersect either the src or
901 // dst bounds.
bsalomon@google.com116ad842013-04-09 15:38:19 +0000902 return !clippedSrcRect->isEmpty();
903}
904}
905
906bool GrDrawTarget::copySurface(GrSurface* dst,
907 GrSurface* src,
908 const SkIRect& srcRect,
909 const SkIPoint& dstPoint) {
bsalomon49f085d2014-09-05 13:34:00 -0700910 SkASSERT(dst);
911 SkASSERT(src);
bsalomon@google.com116ad842013-04-09 15:38:19 +0000912
913 SkIRect clippedSrcRect;
914 SkIPoint clippedDstPoint;
915 // If the rect is outside the src or dst then we've already succeeded.
916 if (!clip_srcrect_and_dstpoint(dst,
917 src,
918 srcRect,
919 dstPoint,
920 &clippedSrcRect,
921 &clippedDstPoint)) {
joshualitta7024152014-11-03 14:16:35 -0800922 SkASSERT(GrDrawTarget::canCopySurface(dst, src, srcRect, dstPoint));
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000923 return true;
924 }
925
joshualitta7024152014-11-03 14:16:35 -0800926 if (!GrDrawTarget::canCopySurface(dst, src, clippedSrcRect, clippedDstPoint)) {
927 return false;
928 }
929
930 GrRenderTarget* rt = dst->asRenderTarget();
931 GrTexture* tex = src->asTexture();
932
joshualitt9853cce2014-11-17 14:22:48 -0800933 GrDrawState drawState;
934 drawState.setRenderTarget(rt);
joshualitta7024152014-11-03 14:16:35 -0800935 SkMatrix matrix;
936 matrix.setTranslate(SkIntToScalar(clippedSrcRect.fLeft - clippedDstPoint.fX),
937 SkIntToScalar(clippedSrcRect.fTop - clippedDstPoint.fY));
938 matrix.postIDiv(tex->width(), tex->height());
joshualitt9853cce2014-11-17 14:22:48 -0800939 drawState.addColorTextureProcessor(tex, matrix);
joshualitta7024152014-11-03 14:16:35 -0800940 SkIRect dstRect = SkIRect::MakeXYWH(clippedDstPoint.fX,
941 clippedDstPoint.fY,
942 clippedSrcRect.width(),
943 clippedSrcRect.height());
joshualitt9853cce2014-11-17 14:22:48 -0800944 this->drawSimpleRect(&drawState, dstRect);
joshualitta7024152014-11-03 14:16:35 -0800945 return true;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000946}
947
joshualitt9853cce2014-11-17 14:22:48 -0800948bool GrDrawTarget::canCopySurface(const GrSurface* dst,
949 const GrSurface* src,
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000950 const SkIRect& srcRect,
951 const SkIPoint& dstPoint) {
bsalomon49f085d2014-09-05 13:34:00 -0700952 SkASSERT(dst);
953 SkASSERT(src);
bsalomon@google.com116ad842013-04-09 15:38:19 +0000954
955 SkIRect clippedSrcRect;
956 SkIPoint clippedDstPoint;
957 // If the rect is outside the src or dst then we're guaranteed success
958 if (!clip_srcrect_and_dstpoint(dst,
959 src,
960 srcRect,
961 dstPoint,
962 &clippedSrcRect,
963 &clippedDstPoint)) {
964 return true;
965 }
bsalomon@google.com116ad842013-04-09 15:38:19 +0000966
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000967 // Check that the read/write rects are contained within the src/dst bounds.
joshualitta7024152014-11-03 14:16:35 -0800968 SkASSERT(!clippedSrcRect.isEmpty());
969 SkASSERT(SkIRect::MakeWH(src->width(), src->height()).contains(clippedSrcRect));
970 SkASSERT(clippedDstPoint.fX >= 0 && clippedDstPoint.fY >= 0);
971 SkASSERT(clippedDstPoint.fX + clippedSrcRect.width() <= dst->width() &&
972 clippedDstPoint.fY + clippedSrcRect.height() <= dst->height());
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000973
bsalomonafbf2d62014-09-30 12:18:44 -0700974 return !dst->surfacePriv().isSameAs(src) && dst->asRenderTarget() && src->asTexture();
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000975}
976
bsalomonf2703d82014-10-28 14:33:06 -0700977void GrDrawTarget::initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc) {
bsalomon@google.comeb851172013-04-15 13:51:00 +0000978 // Make the dst of the copy be a render target because the default copySurface draws to the dst.
979 desc->fOrigin = kDefault_GrSurfaceOrigin;
bsalomonf2703d82014-10-28 14:33:06 -0700980 desc->fFlags = kRenderTarget_GrSurfaceFlag | kNoStencil_GrSurfaceFlag;
bsalomon@google.comeb851172013-04-15 13:51:00 +0000981 desc->fConfig = src->config();
982}
983
bsalomon@google.combcce8922013-03-25 15:38:39 +0000984///////////////////////////////////////////////////////////////////////////////
985
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000986void GrDrawTargetCaps::reset() {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000987 fMipMapSupport = false;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000988 fNPOTTextureTileSupport = false;
989 fTwoSidedStencilSupport = false;
990 fStencilWrapOpsSupport = false;
991 fHWAALineSupport = false;
992 fShaderDerivativeSupport = false;
993 fGeometryShaderSupport = false;
skia.committer@gmail.come60ed082013-03-26 07:01:04 +0000994 fDualSourceBlendingSupport = false;
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000995 fPathRenderingSupport = false;
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000996 fDstReadInShaderSupport = false;
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +0000997 fDiscardRenderTargetSupport = false;
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000998 fReuseScratchTextures = true;
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000999 fGpuTracingSupport = false;
krajcevski786978162014-07-30 11:25:44 -07001000 fCompressedTexSubImageSupport = false;
bsalomon@google.combcce8922013-03-25 15:38:39 +00001001
bsalomon63b21962014-11-05 07:05:34 -08001002 fUseDrawInsteadOfClear = false;
1003
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001004 fMapBufferFlags = kNone_MapFlags;
1005
bsalomon@google.combcce8922013-03-25 15:38:39 +00001006 fMaxRenderTargetSize = 0;
1007 fMaxTextureSize = 0;
1008 fMaxSampleCount = 0;
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001009
1010 memset(fConfigRenderSupport, 0, sizeof(fConfigRenderSupport));
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001011 memset(fConfigTextureSupport, 0, sizeof(fConfigTextureSupport));
bsalomon@google.combcce8922013-03-25 15:38:39 +00001012}
1013
bsalomon@google.comc26d94f2013-03-25 18:19:00 +00001014GrDrawTargetCaps& GrDrawTargetCaps::operator=(const GrDrawTargetCaps& other) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +00001015 fMipMapSupport = other.fMipMapSupport;
bsalomon@google.combcce8922013-03-25 15:38:39 +00001016 fNPOTTextureTileSupport = other.fNPOTTextureTileSupport;
1017 fTwoSidedStencilSupport = other.fTwoSidedStencilSupport;
1018 fStencilWrapOpsSupport = other.fStencilWrapOpsSupport;
1019 fHWAALineSupport = other.fHWAALineSupport;
1020 fShaderDerivativeSupport = other.fShaderDerivativeSupport;
1021 fGeometryShaderSupport = other.fGeometryShaderSupport;
1022 fDualSourceBlendingSupport = other.fDualSourceBlendingSupport;
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +00001023 fPathRenderingSupport = other.fPathRenderingSupport;
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +00001024 fDstReadInShaderSupport = other.fDstReadInShaderSupport;
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +00001025 fDiscardRenderTargetSupport = other.fDiscardRenderTargetSupport;
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +00001026 fReuseScratchTextures = other.fReuseScratchTextures;
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +00001027 fGpuTracingSupport = other.fGpuTracingSupport;
krajcevski786978162014-07-30 11:25:44 -07001028 fCompressedTexSubImageSupport = other.fCompressedTexSubImageSupport;
bsalomon@google.combcce8922013-03-25 15:38:39 +00001029
bsalomon63b21962014-11-05 07:05:34 -08001030 fUseDrawInsteadOfClear = other.fUseDrawInsteadOfClear;
1031
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001032 fMapBufferFlags = other.fMapBufferFlags;
1033
bsalomon@google.combcce8922013-03-25 15:38:39 +00001034 fMaxRenderTargetSize = other.fMaxRenderTargetSize;
1035 fMaxTextureSize = other.fMaxTextureSize;
1036 fMaxSampleCount = other.fMaxSampleCount;
1037
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001038 memcpy(fConfigRenderSupport, other.fConfigRenderSupport, sizeof(fConfigRenderSupport));
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001039 memcpy(fConfigTextureSupport, other.fConfigTextureSupport, sizeof(fConfigTextureSupport));
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001040
bsalomon@google.combcce8922013-03-25 15:38:39 +00001041 return *this;
1042}
1043
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001044static SkString map_flags_to_string(uint32_t flags) {
1045 SkString str;
1046 if (GrDrawTargetCaps::kNone_MapFlags == flags) {
1047 str = "none";
1048 } else {
1049 SkASSERT(GrDrawTargetCaps::kCanMap_MapFlag & flags);
1050 SkDEBUGCODE(flags &= ~GrDrawTargetCaps::kCanMap_MapFlag);
1051 str = "can_map";
1052
1053 if (GrDrawTargetCaps::kSubset_MapFlag & flags) {
1054 str.append(" partial");
1055 } else {
1056 str.append(" full");
1057 }
1058 SkDEBUGCODE(flags &= ~GrDrawTargetCaps::kSubset_MapFlag);
1059 }
1060 SkASSERT(0 == flags); // Make sure we handled all the flags.
1061 return str;
1062}
1063
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001064SkString GrDrawTargetCaps::dump() const {
1065 SkString r;
bsalomon@google.com18c9c192011-09-22 21:01:31 +00001066 static const char* gNY[] = {"NO", "YES"};
bsalomon63b21962014-11-05 07:05:34 -08001067 r.appendf("MIP Map Support : %s\n", gNY[fMipMapSupport]);
1068 r.appendf("NPOT Texture Tile Support : %s\n", gNY[fNPOTTextureTileSupport]);
1069 r.appendf("Two Sided Stencil Support : %s\n", gNY[fTwoSidedStencilSupport]);
1070 r.appendf("Stencil Wrap Ops Support : %s\n", gNY[fStencilWrapOpsSupport]);
1071 r.appendf("HW AA Lines Support : %s\n", gNY[fHWAALineSupport]);
1072 r.appendf("Shader Derivative Support : %s\n", gNY[fShaderDerivativeSupport]);
1073 r.appendf("Geometry Shader Support : %s\n", gNY[fGeometryShaderSupport]);
1074 r.appendf("Dual Source Blending Support : %s\n", gNY[fDualSourceBlendingSupport]);
1075 r.appendf("Path Rendering Support : %s\n", gNY[fPathRenderingSupport]);
1076 r.appendf("Dst Read In Shader Support : %s\n", gNY[fDstReadInShaderSupport]);
1077 r.appendf("Discard Render Target Support : %s\n", gNY[fDiscardRenderTargetSupport]);
1078 r.appendf("Reuse Scratch Textures : %s\n", gNY[fReuseScratchTextures]);
1079 r.appendf("Gpu Tracing Support : %s\n", gNY[fGpuTracingSupport]);
1080 r.appendf("Compressed Update Support : %s\n", gNY[fCompressedTexSubImageSupport]);
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001081
bsalomon63b21962014-11-05 07:05:34 -08001082 r.appendf("Draw Instead of Clear [workaround] : %s\n", gNY[fUseDrawInsteadOfClear]);
1083
1084 r.appendf("Max Texture Size : %d\n", fMaxTextureSize);
1085 r.appendf("Max Render Target Size : %d\n", fMaxRenderTargetSize);
1086 r.appendf("Max Sample Count : %d\n", fMaxSampleCount);
1087
1088 r.appendf("Map Buffer Support : %s\n",
1089 map_flags_to_string(fMapBufferFlags).c_str());
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001090
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001091 static const char* kConfigNames[] = {
1092 "Unknown", // kUnknown_GrPixelConfig
1093 "Alpha8", // kAlpha_8_GrPixelConfig,
1094 "Index8", // kIndex_8_GrPixelConfig,
1095 "RGB565", // kRGB_565_GrPixelConfig,
1096 "RGBA444", // kRGBA_4444_GrPixelConfig,
1097 "RGBA8888", // kRGBA_8888_GrPixelConfig,
1098 "BGRA8888", // kBGRA_8888_GrPixelConfig,
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001099 "ETC1", // kETC1_GrPixelConfig,
1100 "LATC", // kLATC_GrPixelConfig,
krajcevski238b4562014-06-30 09:09:22 -07001101 "R11EAC", // kR11_EAC_GrPixelConfig,
krajcevski7ef21622014-07-16 15:21:13 -07001102 "ASTC12x12",// kASTC_12x12_GrPixelConfig,
joshualittee5da552014-07-16 13:32:56 -07001103 "RGBAFloat", // kRGBA_float_GrPixelConfig
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001104 };
krajcevski7ef21622014-07-16 15:21:13 -07001105 GR_STATIC_ASSERT(0 == kUnknown_GrPixelConfig);
1106 GR_STATIC_ASSERT(1 == kAlpha_8_GrPixelConfig);
1107 GR_STATIC_ASSERT(2 == kIndex_8_GrPixelConfig);
1108 GR_STATIC_ASSERT(3 == kRGB_565_GrPixelConfig);
1109 GR_STATIC_ASSERT(4 == kRGBA_4444_GrPixelConfig);
1110 GR_STATIC_ASSERT(5 == kRGBA_8888_GrPixelConfig);
1111 GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig);
1112 GR_STATIC_ASSERT(7 == kETC1_GrPixelConfig);
1113 GR_STATIC_ASSERT(8 == kLATC_GrPixelConfig);
1114 GR_STATIC_ASSERT(9 == kR11_EAC_GrPixelConfig);
1115 GR_STATIC_ASSERT(10 == kASTC_12x12_GrPixelConfig);
1116 GR_STATIC_ASSERT(11 == kRGBA_float_GrPixelConfig);
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001117 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kConfigNames) == kGrPixelConfigCnt);
1118
commit-bot@chromium.org99017272013-11-08 18:45:27 +00001119 SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][0]);
1120 SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][1]);
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001121
1122 for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) {
1123 r.appendf("%s is renderable: %s, with MSAA: %s\n",
1124 kConfigNames[i],
1125 gNY[fConfigRenderSupport[i][0]],
1126 gNY[fConfigRenderSupport[i][1]]);
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001127 }
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +00001128
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001129 SkASSERT(!fConfigTextureSupport[kUnknown_GrPixelConfig]);
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +00001130
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001131 for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) {
1132 r.appendf("%s is uploadable to a texture: %s\n",
1133 kConfigNames[i],
1134 gNY[fConfigTextureSupport[i]]);
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +00001135 }
1136
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001137 return r;
bsalomon@google.com18c9c192011-09-22 21:01:31 +00001138}
egdanielbc127a32014-09-19 12:07:43 -07001139
1140uint32_t GrDrawTargetCaps::CreateUniqueID() {
1141 static int32_t gUniqueID = SK_InvalidUniqueID;
1142 uint32_t id;
1143 do {
1144 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1);
1145 } while (id == SK_InvalidUniqueID);
1146 return id;
1147}
1148
joshualitt2c93efe2014-11-06 12:57:13 -08001149///////////////////////////////////////////////////////////////////////////////////////////////////
1150
1151bool GrClipTarget::setupClip(const SkRect* devBounds,
1152 GrDrawState::AutoRestoreEffects* are,
1153 GrDrawState::AutoRestoreStencil* ars,
joshualitt9853cce2014-11-17 14:22:48 -08001154 GrDrawState* ds,
joshualitt2c93efe2014-11-06 12:57:13 -08001155 GrClipMaskManager::ScissorState* scissorState) {
joshualitt9853cce2014-11-17 14:22:48 -08001156 return fClipMaskManager.setupClipping(ds,
joshualitt2c93efe2014-11-06 12:57:13 -08001157 are,
1158 ars,
joshualitt9853cce2014-11-17 14:22:48 -08001159 scissorState,
1160 this->getClip(),
1161 devBounds);
joshualitt2c93efe2014-11-06 12:57:13 -08001162}