blob: 2640e71da60d903d1ae6c3b8482d8bd39dd27beb [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
joshualittc2893c52015-01-28 06:54:30 -08009#include "GrDrawTarget.h"
joshualitt4d8da812015-01-28 12:53:54 -080010
11#include "GrBatch.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"
egdaniele36914c2015-02-13 09:00:33 -080015#include "GrPipeline.h"
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000016#include "GrRenderTarget.h"
bsalomon6bc1b5f2015-02-23 09:06:38 -080017#include "GrRenderTargetPriv.h"
bsalomonafbf2d62014-09-30 12:18:44 -070018#include "GrSurfacePriv.h"
bsalomon62c447d2014-08-08 08:08:50 -070019#include "GrTemplates.h"
bsalomon@google.com86afc2a2011-02-16 16:12:19 +000020#include "GrTexture.h"
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000021#include "GrVertexBuffer.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000022
sugoi@google.com5f74cf82012-12-17 21:16:45 +000023#include "SkStrokeRec.h"
sugoi@google.com12b4e272012-12-06 20:13:11 +000024
reed@google.comac10a2d2010-12-22 21:39:39 +000025////////////////////////////////////////////////////////////////////////////////
26
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000027GrDrawTarget::DrawInfo& GrDrawTarget::DrawInfo::operator =(const DrawInfo& di) {
28 fPrimitiveType = di.fPrimitiveType;
29 fStartVertex = di.fStartVertex;
30 fStartIndex = di.fStartIndex;
31 fVertexCount = di.fVertexCount;
32 fIndexCount = di.fIndexCount;
33
34 fInstanceCount = di.fInstanceCount;
35 fVerticesPerInstance = di.fVerticesPerInstance;
36 fIndicesPerInstance = di.fIndicesPerInstance;
37
bsalomon49f085d2014-09-05 13:34:00 -070038 if (di.fDevBounds) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000039 SkASSERT(di.fDevBounds == &di.fDevBoundsStorage);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000040 fDevBoundsStorage = di.fDevBoundsStorage;
41 fDevBounds = &fDevBoundsStorage;
42 } else {
43 fDevBounds = NULL;
44 }
bsalomon@google.com26e18b52013-03-29 19:22:36 +000045
joshualitt7eb8c7b2014-11-18 14:24:27 -080046 this->setVertexBuffer(di.vertexBuffer());
47 this->setIndexBuffer(di.indexBuffer());
48
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000049 return *this;
50}
51
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +000052#ifdef SK_DEBUG
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000053bool GrDrawTarget::DrawInfo::isInstanced() const {
54 if (fInstanceCount > 0) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000055 SkASSERT(0 == fIndexCount % fIndicesPerInstance);
56 SkASSERT(0 == fVertexCount % fVerticesPerInstance);
57 SkASSERT(fIndexCount / fIndicesPerInstance == fInstanceCount);
58 SkASSERT(fVertexCount / fVerticesPerInstance == fInstanceCount);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000059 // there is no way to specify a non-zero start index to drawIndexedInstances().
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000060 SkASSERT(0 == fStartIndex);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000061 return true;
62 } else {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000063 SkASSERT(!fVerticesPerInstance);
64 SkASSERT(!fIndicesPerInstance);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000065 return false;
66 }
67}
68#endif
69
70void GrDrawTarget::DrawInfo::adjustInstanceCount(int instanceOffset) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000071 SkASSERT(this->isInstanced());
72 SkASSERT(instanceOffset + fInstanceCount >= 0);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000073 fInstanceCount += instanceOffset;
74 fVertexCount = fVerticesPerInstance * fInstanceCount;
75 fIndexCount = fIndicesPerInstance * fInstanceCount;
76}
77
78void GrDrawTarget::DrawInfo::adjustStartVertex(int vertexOffset) {
79 fStartVertex += vertexOffset;
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000080 SkASSERT(fStartVertex >= 0);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000081}
82
83void GrDrawTarget::DrawInfo::adjustStartIndex(int indexOffset) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000084 SkASSERT(this->isIndexed());
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000085 fStartIndex += indexOffset;
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000086 SkASSERT(fStartIndex >= 0);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000087}
88
89////////////////////////////////////////////////////////////////////////////////
90
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000091#define DEBUG_INVAL_BUFFER 0xdeadcafe
92#define DEBUG_INVAL_START_IDX -1
93
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000094GrDrawTarget::GrDrawTarget(GrContext* context)
joshualitt44701df2015-02-23 14:44:57 -080095 : fContext(context)
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +000096 , fGpuTraceMarkerCount(0) {
bsalomon49f085d2014-09-05 13:34:00 -070097 SkASSERT(context);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000098 GeometrySrcState& geoSrc = fGeoSrcStateStack.push_back();
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +000099#ifdef SK_DEBUG
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000100 geoSrc.fVertexCount = DEBUG_INVAL_START_IDX;
101 geoSrc.fVertexBuffer = (GrVertexBuffer*)DEBUG_INVAL_BUFFER;
102 geoSrc.fIndexCount = DEBUG_INVAL_START_IDX;
103 geoSrc.fIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER;
reed@google.comac10a2d2010-12-22 21:39:39 +0000104#endif
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000105 geoSrc.fVertexSrc = kNone_GeometrySrcType;
106 geoSrc.fIndexSrc = kNone_GeometrySrcType;
107}
108
109GrDrawTarget::~GrDrawTarget() {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000110 SkASSERT(1 == fGeoSrcStateStack.count());
humper@google.com0e515772013-01-07 19:54:40 +0000111 SkDEBUGCODE(GeometrySrcState& geoSrc = fGeoSrcStateStack.back());
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000112 SkASSERT(kNone_GeometrySrcType == geoSrc.fIndexSrc);
113 SkASSERT(kNone_GeometrySrcType == geoSrc.fVertexSrc);
bsalomon@google.com4a018bb2011-10-28 19:50:21 +0000114}
115
116void GrDrawTarget::releaseGeometry() {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000117 int popCnt = fGeoSrcStateStack.count() - 1;
118 while (popCnt) {
119 this->popGeometrySource();
120 --popCnt;
121 }
bsalomon@google.com4a018bb2011-10-28 19:50:21 +0000122 this->resetVertexSource();
123 this->resetIndexSource();
reed@google.comac10a2d2010-12-22 21:39:39 +0000124}
125
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000126bool GrDrawTarget::reserveVertexSpace(size_t vertexSize,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000127 int vertexCount,
128 void** vertices) {
129 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
130 bool acquired = false;
131 if (vertexCount > 0) {
bsalomon49f085d2014-09-05 13:34:00 -0700132 SkASSERT(vertices);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000133 this->releasePreviousVertexSource();
134 geoSrc.fVertexSrc = kNone_GeometrySrcType;
reed@google.comac10a2d2010-12-22 21:39:39 +0000135
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000136 acquired = this->onReserveVertexSpace(vertexSize,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000137 vertexCount,
138 vertices);
reed@google.comac10a2d2010-12-22 21:39:39 +0000139 }
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000140 if (acquired) {
141 geoSrc.fVertexSrc = kReserved_GeometrySrcType;
142 geoSrc.fVertexCount = vertexCount;
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000143 geoSrc.fVertexSize = vertexSize;
bsalomon49f085d2014-09-05 13:34:00 -0700144 } else if (vertices) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000145 *vertices = NULL;
146 }
147 return acquired;
148}
149
150bool GrDrawTarget::reserveIndexSpace(int indexCount,
151 void** indices) {
152 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
153 bool acquired = false;
154 if (indexCount > 0) {
bsalomon49f085d2014-09-05 13:34:00 -0700155 SkASSERT(indices);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000156 this->releasePreviousIndexSource();
157 geoSrc.fIndexSrc = kNone_GeometrySrcType;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000158
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000159 acquired = this->onReserveIndexSpace(indexCount, indices);
160 }
161 if (acquired) {
162 geoSrc.fIndexSrc = kReserved_GeometrySrcType;
163 geoSrc.fIndexCount = indexCount;
bsalomon49f085d2014-09-05 13:34:00 -0700164 } else if (indices) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000165 *indices = NULL;
166 }
167 return acquired;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000168
reed@google.comac10a2d2010-12-22 21:39:39 +0000169}
170
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000171bool GrDrawTarget::reserveVertexAndIndexSpace(int vertexCount,
joshualitt9853cce2014-11-17 14:22:48 -0800172 size_t vertexStride,
bsalomon@google.come3d70952012-03-13 12:40:53 +0000173 int indexCount,
174 void** vertices,
175 void** indices) {
joshualitt9853cce2014-11-17 14:22:48 -0800176 this->willReserveVertexAndIndexSpace(vertexCount, vertexStride, indexCount);
bsalomon@google.come3d70952012-03-13 12:40:53 +0000177 if (vertexCount) {
egdaniel7b3d5ee2014-08-28 05:41:14 -0700178 if (!this->reserveVertexSpace(vertexStride, vertexCount, vertices)) {
bsalomon@google.come3d70952012-03-13 12:40:53 +0000179 if (indexCount) {
180 this->resetIndexSource();
181 }
182 return false;
183 }
184 }
185 if (indexCount) {
186 if (!this->reserveIndexSpace(indexCount, indices)) {
187 if (vertexCount) {
188 this->resetVertexSource();
189 }
190 return false;
191 }
192 }
193 return true;
194}
195
joshualitt9853cce2014-11-17 14:22:48 -0800196bool GrDrawTarget::geometryHints(size_t vertexStride,
197 int32_t* vertexCount,
reed@google.comac10a2d2010-12-22 21:39:39 +0000198 int32_t* indexCount) const {
bsalomon49f085d2014-09-05 13:34:00 -0700199 if (vertexCount) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000200 *vertexCount = -1;
201 }
bsalomon49f085d2014-09-05 13:34:00 -0700202 if (indexCount) {
reed@google.comac10a2d2010-12-22 21:39:39 +0000203 *indexCount = -1;
204 }
205 return false;
206}
207
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000208void GrDrawTarget::releasePreviousVertexSource() {
209 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
210 switch (geoSrc.fVertexSrc) {
211 case kNone_GeometrySrcType:
212 break;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000213 case kReserved_GeometrySrcType:
214 this->releaseReservedVertexSpace();
215 break;
216 case kBuffer_GeometrySrcType:
217 geoSrc.fVertexBuffer->unref();
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000218#ifdef SK_DEBUG
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000219 geoSrc.fVertexBuffer = (GrVertexBuffer*)DEBUG_INVAL_BUFFER;
220#endif
221 break;
222 default:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000223 SkFAIL("Unknown Vertex Source Type.");
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000224 break;
225 }
226}
227
228void GrDrawTarget::releasePreviousIndexSource() {
229 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
230 switch (geoSrc.fIndexSrc) {
231 case kNone_GeometrySrcType: // these two don't require
232 break;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000233 case kReserved_GeometrySrcType:
234 this->releaseReservedIndexSpace();
235 break;
236 case kBuffer_GeometrySrcType:
237 geoSrc.fIndexBuffer->unref();
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000238#ifdef SK_DEBUG
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000239 geoSrc.fIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER;
240#endif
241 break;
242 default:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000243 SkFAIL("Unknown Index Source Type.");
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000244 break;
245 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000246}
247
joshualitt9853cce2014-11-17 14:22:48 -0800248void GrDrawTarget::setVertexSourceToBuffer(const GrVertexBuffer* buffer, size_t vertexStride) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000249 this->releasePreviousVertexSource();
250 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
251 geoSrc.fVertexSrc = kBuffer_GeometrySrcType;
252 geoSrc.fVertexBuffer = buffer;
253 buffer->ref();
joshualitt9853cce2014-11-17 14:22:48 -0800254 geoSrc.fVertexSize = vertexStride;
reed@google.comac10a2d2010-12-22 21:39:39 +0000255}
256
257void GrDrawTarget::setIndexSourceToBuffer(const GrIndexBuffer* buffer) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000258 this->releasePreviousIndexSource();
259 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
260 geoSrc.fIndexSrc = kBuffer_GeometrySrcType;
261 geoSrc.fIndexBuffer = buffer;
262 buffer->ref();
reed@google.comac10a2d2010-12-22 21:39:39 +0000263}
264
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000265void GrDrawTarget::resetVertexSource() {
266 this->releasePreviousVertexSource();
267 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
268 geoSrc.fVertexSrc = kNone_GeometrySrcType;
269}
270
271void GrDrawTarget::resetIndexSource() {
272 this->releasePreviousIndexSource();
273 GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
274 geoSrc.fIndexSrc = kNone_GeometrySrcType;
275}
276
277void GrDrawTarget::pushGeometrySource() {
278 this->geometrySourceWillPush();
279 GeometrySrcState& newState = fGeoSrcStateStack.push_back();
280 newState.fIndexSrc = kNone_GeometrySrcType;
281 newState.fVertexSrc = kNone_GeometrySrcType;
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000282#ifdef SK_DEBUG
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000283 newState.fVertexCount = ~0;
284 newState.fVertexBuffer = (GrVertexBuffer*)~0;
285 newState.fIndexCount = ~0;
286 newState.fIndexBuffer = (GrIndexBuffer*)~0;
287#endif
288}
289
290void GrDrawTarget::popGeometrySource() {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000291 // if popping last element then pops are unbalanced with pushes
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000292 SkASSERT(fGeoSrcStateStack.count() > 1);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000293
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000294 this->geometrySourceWillPop(fGeoSrcStateStack.fromBack(1));
295 this->releasePreviousVertexSource();
296 this->releasePreviousIndexSource();
297 fGeoSrcStateStack.pop_back();
298}
299
300////////////////////////////////////////////////////////////////////////////////
301
egdaniel8dd688b2015-01-22 10:16:09 -0800302bool GrDrawTarget::checkDraw(const GrPipelineBuilder& pipelineBuilder,
joshualitt56995b52014-12-11 15:44:02 -0800303 const GrGeometryProcessor* gp,
joshualitt9853cce2014-11-17 14:22:48 -0800304 GrPrimitiveType type,
305 int startVertex,
306 int startIndex,
307 int vertexCount,
bsalomon@google.come8262622011-11-07 02:30:51 +0000308 int indexCount) const {
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000309#ifdef SK_DEBUG
bsalomon@google.come8262622011-11-07 02:30:51 +0000310 const GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000311 int maxVertex = startVertex + vertexCount;
312 int maxValidVertex;
313 switch (geoSrc.fVertexSrc) {
314 case kNone_GeometrySrcType:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000315 SkFAIL("Attempting to draw without vertex src.");
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000316 case kReserved_GeometrySrcType: // fallthrough
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000317 maxValidVertex = geoSrc.fVertexCount;
318 break;
319 case kBuffer_GeometrySrcType:
egdaniel8dd688b2015-01-22 10:16:09 -0800320 maxValidVertex = static_cast<int>(geoSrc.fVertexBuffer->gpuMemorySize() /
321 geoSrc.fVertexSize);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000322 break;
323 }
324 if (maxVertex > maxValidVertex) {
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000325 SkFAIL("Drawing outside valid vertex range.");
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000326 }
bsalomon@google.come8262622011-11-07 02:30:51 +0000327 if (indexCount > 0) {
328 int maxIndex = startIndex + indexCount;
329 int maxValidIndex;
330 switch (geoSrc.fIndexSrc) {
331 case kNone_GeometrySrcType:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000332 SkFAIL("Attempting to draw indexed geom without index src.");
bsalomon@google.come8262622011-11-07 02:30:51 +0000333 case kReserved_GeometrySrcType: // fallthrough
bsalomon@google.come8262622011-11-07 02:30:51 +0000334 maxValidIndex = geoSrc.fIndexCount;
335 break;
336 case kBuffer_GeometrySrcType:
egdaniel8dd688b2015-01-22 10:16:09 -0800337 maxValidIndex = static_cast<int>(geoSrc.fIndexBuffer->gpuMemorySize() /
338 sizeof(uint16_t));
bsalomon@google.come8262622011-11-07 02:30:51 +0000339 break;
340 }
341 if (maxIndex > maxValidIndex) {
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000342 SkFAIL("Index reads outside valid index range.");
bsalomon@google.come8262622011-11-07 02:30:51 +0000343 }
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000344 }
bsalomon@google.comb4725b42012-03-30 17:24:17 +0000345
egdaniel8dd688b2015-01-22 10:16:09 -0800346 SkASSERT(pipelineBuilder.getRenderTarget());
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000347
joshualitt56995b52014-12-11 15:44:02 -0800348 if (gp) {
joshualittb0a8a372014-09-23 09:50:21 -0700349 int numTextures = gp->numTextures();
joshualittbd769d02014-09-04 08:56:46 -0700350 for (int t = 0; t < numTextures; ++t) {
joshualittb0a8a372014-09-23 09:50:21 -0700351 GrTexture* texture = gp->texture(t);
egdaniel8dd688b2015-01-22 10:16:09 -0800352 SkASSERT(texture->asRenderTarget() != pipelineBuilder.getRenderTarget());
joshualittbd769d02014-09-04 08:56:46 -0700353 }
354 }
355
bsalomon6be6f7c2015-02-26 13:05:21 -0800356 for (int s = 0; s < pipelineBuilder.numColorFragmentStages(); ++s) {
357 const GrProcessor* effect = pipelineBuilder.getColorFragmentStage(s).processor();
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000358 int numTextures = effect->numTextures();
359 for (int t = 0; t < numTextures; ++t) {
360 GrTexture* texture = effect->texture(t);
egdaniel8dd688b2015-01-22 10:16:09 -0800361 SkASSERT(texture->asRenderTarget() != pipelineBuilder.getRenderTarget());
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000362 }
363 }
bsalomon6be6f7c2015-02-26 13:05:21 -0800364 for (int s = 0; s < pipelineBuilder.numCoverageFragmentStages(); ++s) {
365 const GrProcessor* effect = pipelineBuilder.getCoverageFragmentStage(s).processor();
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000366 int numTextures = effect->numTextures();
367 for (int t = 0; t < numTextures; ++t) {
368 GrTexture* texture = effect->texture(t);
egdaniel8dd688b2015-01-22 10:16:09 -0800369 SkASSERT(texture->asRenderTarget() != pipelineBuilder.getRenderTarget());
bsalomon@google.comb4725b42012-03-30 17:24:17 +0000370 }
371 }
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000372
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000373#endif
egdaniel8dd688b2015-01-22 10:16:09 -0800374 if (NULL == pipelineBuilder.getRenderTarget()) {
bsalomon@google.com0ba52fc2011-11-10 22:16:06 +0000375 return false;
376 }
bsalomon@google.come8262622011-11-07 02:30:51 +0000377 return true;
378}
379
bsalomon50785a32015-02-06 07:02:37 -0800380bool GrDrawTarget::setupDstReadIfNecessary(const GrPipelineBuilder& pipelineBuilder,
egdaniele36914c2015-02-13 09:00:33 -0800381 const GrProcOptInfo& colorPOI,
382 const GrProcOptInfo& coveragePOI,
joshualitt9853cce2014-11-17 14:22:48 -0800383 GrDeviceCoordTexture* dstCopy,
384 const SkRect* drawBounds) {
egdaniele36914c2015-02-13 09:00:33 -0800385 if (!pipelineBuilder.willXPNeedDstCopy(*this->caps(), colorPOI, coveragePOI)) {
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000386 return true;
387 }
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000388 SkIRect copyRect;
bsalomon50785a32015-02-06 07:02:37 -0800389 GrRenderTarget* rt = pipelineBuilder.getRenderTarget();
joshualitt44701df2015-02-23 14:44:57 -0800390 pipelineBuilder.clip().getConservativeBounds(rt, &copyRect);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000391
bsalomon49f085d2014-09-05 13:34:00 -0700392 if (drawBounds) {
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000393 SkIRect drawIBounds;
394 drawBounds->roundOut(&drawIBounds);
commit-bot@chromium.orgbb5c4652013-04-01 12:49:31 +0000395 if (!copyRect.intersect(drawIBounds)) {
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000396#ifdef SK_DEBUG
tfarina38406c82014-10-31 07:11:12 -0700397 SkDebugf("Missed an early reject. Bailing on draw from setupDstReadIfNecessary.\n");
commit-bot@chromium.orgbb5c4652013-04-01 12:49:31 +0000398#endif
399 return false;
400 }
401 } else {
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000402#ifdef SK_DEBUG
tfarina38406c82014-10-31 07:11:12 -0700403 //SkDebugf("No dev bounds when dst copy is made.\n");
commit-bot@chromium.orgbb5c4652013-04-01 12:49:31 +0000404#endif
405 }
skia.committer@gmail.com05a2ee02013-04-02 07:01:34 +0000406
commit-bot@chromium.org63150af2013-04-11 22:00:22 +0000407 // MSAA consideration: When there is support for reading MSAA samples in the shader we could
408 // have per-sample dst values by making the copy multisampled.
bsalomonf2703d82014-10-28 14:33:06 -0700409 GrSurfaceDesc desc;
bsalomon@google.comeb851172013-04-15 13:51:00 +0000410 this->initCopySurfaceDstDesc(rt, &desc);
commit-bot@chromium.orgbb5c4652013-04-01 12:49:31 +0000411 desc.fWidth = copyRect.width();
412 desc.fHeight = copyRect.height();
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000413
bsalomone3059732014-10-14 11:47:22 -0700414 SkAutoTUnref<GrTexture> copy(
415 fContext->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch));
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000416
bsalomone3059732014-10-14 11:47:22 -0700417 if (!copy) {
tfarina38406c82014-10-31 07:11:12 -0700418 SkDebugf("Failed to create temporary copy of destination texture.\n");
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000419 return false;
420 }
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000421 SkIPoint dstPoint = {0, 0};
bsalomone3059732014-10-14 11:47:22 -0700422 if (this->copySurface(copy, rt, copyRect, dstPoint)) {
423 dstCopy->setTexture(copy);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000424 dstCopy->setOffset(copyRect.fLeft, copyRect.fTop);
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000425 return true;
426 } else {
427 return false;
428 }
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000429}
430
egdaniel8dd688b2015-01-22 10:16:09 -0800431void GrDrawTarget::drawIndexed(GrPipelineBuilder* pipelineBuilder,
joshualitt56995b52014-12-11 15:44:02 -0800432 const GrGeometryProcessor* gp,
joshualitt9853cce2014-11-17 14:22:48 -0800433 GrPrimitiveType type,
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000434 int startVertex,
435 int startIndex,
436 int vertexCount,
437 int indexCount,
438 const SkRect* devBounds) {
egdaniel8dd688b2015-01-22 10:16:09 -0800439 SkASSERT(pipelineBuilder);
joshualitt9853cce2014-11-17 14:22:48 -0800440 if (indexCount > 0 &&
egdaniel8dd688b2015-01-22 10:16:09 -0800441 this->checkDraw(*pipelineBuilder, gp, type, startVertex, startIndex, vertexCount,
442 indexCount)) {
joshualitt9853cce2014-11-17 14:22:48 -0800443
joshualitt2c93efe2014-11-06 12:57:13 -0800444 // Setup clip
bsalomon3e791242014-12-17 13:43:13 -0800445 GrScissorState scissorState;
bsalomon6be6f7c2015-02-26 13:05:21 -0800446 GrPipelineBuilder::AutoRestoreFragmentProcessors arfp;
egdaniel8dd688b2015-01-22 10:16:09 -0800447 GrPipelineBuilder::AutoRestoreStencil ars;
bsalomon6be6f7c2015-02-26 13:05:21 -0800448 if (!this->setupClip(pipelineBuilder, &arfp, &ars, &scissorState, devBounds)) {
joshualitt2c93efe2014-11-06 12:57:13 -0800449 return;
450 }
451
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000452 DrawInfo info;
453 info.fPrimitiveType = type;
454 info.fStartVertex = startVertex;
455 info.fStartIndex = startIndex;
456 info.fVertexCount = vertexCount;
457 info.fIndexCount = indexCount;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000458
459 info.fInstanceCount = 0;
460 info.fVerticesPerInstance = 0;
461 info.fIndicesPerInstance = 0;
462
bsalomon49f085d2014-09-05 13:34:00 -0700463 if (devBounds) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000464 info.setDevBounds(*devBounds);
465 }
joshualitt9176e2c2014-11-20 07:28:52 -0800466
egdaniele36914c2015-02-13 09:00:33 -0800467 GrDrawTarget::PipelineInfo pipelineInfo(pipelineBuilder, &scissorState, gp, devBounds,
468 this);
469 if (pipelineInfo.mustSkipDraw()) {
470 return;
471 }
472
joshualitt2e3b3e32014-12-09 13:31:14 -0800473 this->setDrawBuffers(&info, gp->getVertexStride());
joshualitt7eb8c7b2014-11-18 14:24:27 -0800474
egdaniele36914c2015-02-13 09:00:33 -0800475 this->onDraw(gp, info, pipelineInfo);
bsalomon@google.com82145872011-08-23 14:32:40 +0000476 }
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000477}
478
egdaniel8dd688b2015-01-22 10:16:09 -0800479void GrDrawTarget::drawNonIndexed(GrPipelineBuilder* pipelineBuilder,
joshualitt56995b52014-12-11 15:44:02 -0800480 const GrGeometryProcessor* gp,
joshualitt9853cce2014-11-17 14:22:48 -0800481 GrPrimitiveType type,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000482 int startVertex,
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000483 int vertexCount,
484 const SkRect* devBounds) {
egdaniel8dd688b2015-01-22 10:16:09 -0800485 SkASSERT(pipelineBuilder);
486 if (vertexCount > 0 && this->checkDraw(*pipelineBuilder, gp, type, startVertex, -1, vertexCount,
487 -1)) {
joshualitt9853cce2014-11-17 14:22:48 -0800488
joshualitt2c93efe2014-11-06 12:57:13 -0800489 // Setup clip
bsalomon3e791242014-12-17 13:43:13 -0800490 GrScissorState scissorState;
bsalomon6be6f7c2015-02-26 13:05:21 -0800491 GrPipelineBuilder::AutoRestoreFragmentProcessors arfp;
egdaniel8dd688b2015-01-22 10:16:09 -0800492 GrPipelineBuilder::AutoRestoreStencil ars;
bsalomon6be6f7c2015-02-26 13:05:21 -0800493 if (!this->setupClip(pipelineBuilder, &arfp, &ars, &scissorState, devBounds)) {
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
egdaniele36914c2015-02-13 09:00:33 -0800512 GrDrawTarget::PipelineInfo pipelineInfo(pipelineBuilder, &scissorState, gp, devBounds,
513 this);
514 if (pipelineInfo.mustSkipDraw()) {
515 return;
516 }
517
joshualitt2e3b3e32014-12-09 13:31:14 -0800518 this->setDrawBuffers(&info, gp->getVertexStride());
joshualitt7eb8c7b2014-11-18 14:24:27 -0800519
egdaniele36914c2015-02-13 09:00:33 -0800520 this->onDraw(gp, info, pipelineInfo);
bsalomon@google.com82145872011-08-23 14:32:40 +0000521 }
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000522}
523
joshualitt4d8da812015-01-28 12:53:54 -0800524
525void GrDrawTarget::drawBatch(GrPipelineBuilder* pipelineBuilder,
526 GrBatch* batch,
527 const SkRect* devBounds) {
528 SkASSERT(pipelineBuilder);
529 // TODO some kind of checkdraw, but not at this level
530
531 // Setup clip
532 GrScissorState scissorState;
bsalomon6be6f7c2015-02-26 13:05:21 -0800533 GrPipelineBuilder::AutoRestoreFragmentProcessors arfp;
joshualitt4d8da812015-01-28 12:53:54 -0800534 GrPipelineBuilder::AutoRestoreStencil ars;
bsalomon6be6f7c2015-02-26 13:05:21 -0800535 if (!this->setupClip(pipelineBuilder, &arfp, &ars, &scissorState, devBounds)) {
joshualitt4d8da812015-01-28 12:53:54 -0800536 return;
537 }
538
egdaniele36914c2015-02-13 09:00:33 -0800539 GrDrawTarget::PipelineInfo pipelineInfo(pipelineBuilder, &scissorState, batch, devBounds, this);
540 if (pipelineInfo.mustSkipDraw()) {
541 return;
542 }
543
544 this->onDrawBatch(batch, pipelineInfo);
joshualitt4d8da812015-01-28 12:53:54 -0800545}
546
joshualitt2c93efe2014-11-06 12:57:13 -0800547static const GrStencilSettings& winding_path_stencil_settings() {
548 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings,
549 kIncClamp_StencilOp,
550 kIncClamp_StencilOp,
551 kAlwaysIfInClip_StencilFunc,
552 0xFFFF, 0xFFFF, 0xFFFF);
553 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings);
554}
555
556static const GrStencilSettings& even_odd_path_stencil_settings() {
557 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings,
558 kInvert_StencilOp,
559 kInvert_StencilOp,
560 kAlwaysIfInClip_StencilFunc,
561 0xFFFF, 0xFFFF, 0xFFFF);
562 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings);
563}
564
565void GrDrawTarget::getPathStencilSettingsForFilltype(GrPathRendering::FillType fill,
joshualitt9853cce2014-11-17 14:22:48 -0800566 const GrStencilBuffer* sb,
joshualitt2c93efe2014-11-06 12:57:13 -0800567 GrStencilSettings* outStencilSettings) {
568
569 switch (fill) {
570 default:
571 SkFAIL("Unexpected path fill.");
572 case GrPathRendering::kWinding_FillType:
573 *outStencilSettings = winding_path_stencil_settings();
574 break;
575 case GrPathRendering::kEvenOdd_FillType:
576 *outStencilSettings = even_odd_path_stencil_settings();
577 break;
578 }
joshualitt9853cce2014-11-17 14:22:48 -0800579 this->clipMaskManager()->adjustPathStencilParams(sb, outStencilSettings);
joshualitt2c93efe2014-11-06 12:57:13 -0800580}
581
egdaniel8dd688b2015-01-22 10:16:09 -0800582void GrDrawTarget::stencilPath(GrPipelineBuilder* pipelineBuilder,
joshualitt56995b52014-12-11 15:44:02 -0800583 const GrPathProcessor* pathProc,
joshualitt9853cce2014-11-17 14:22:48 -0800584 const GrPath* path,
585 GrPathRendering::FillType fill) {
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000586 // TODO: extract portions of checkDraw that are relevant to path stenciling.
bsalomon49f085d2014-09-05 13:34:00 -0700587 SkASSERT(path);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000588 SkASSERT(this->caps()->pathRenderingSupport());
egdaniel8dd688b2015-01-22 10:16:09 -0800589 SkASSERT(pipelineBuilder);
joshualitt2c93efe2014-11-06 12:57:13 -0800590
591 // Setup clip
bsalomon3e791242014-12-17 13:43:13 -0800592 GrScissorState scissorState;
bsalomon6be6f7c2015-02-26 13:05:21 -0800593 GrPipelineBuilder::AutoRestoreFragmentProcessors arfp;
egdaniel8dd688b2015-01-22 10:16:09 -0800594 GrPipelineBuilder::AutoRestoreStencil ars;
bsalomon6be6f7c2015-02-26 13:05:21 -0800595 if (!this->setupClip(pipelineBuilder, &arfp, &ars, &scissorState, NULL)) {
joshualitt2c93efe2014-11-06 12:57:13 -0800596 return;
597 }
598
599 // set stencil settings for path
600 GrStencilSettings stencilSettings;
bsalomon6bc1b5f2015-02-23 09:06:38 -0800601 GrRenderTarget* rt = pipelineBuilder->getRenderTarget();
602 GrStencilBuffer* sb = rt->renderTargetPriv().attachStencilBuffer();
603 this->getPathStencilSettingsForFilltype(fill, sb, &stencilSettings);
joshualitt2c93efe2014-11-06 12:57:13 -0800604
egdaniel8dd688b2015-01-22 10:16:09 -0800605 this->onStencilPath(*pipelineBuilder, pathProc, path, scissorState, stencilSettings);
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000606}
607
egdaniel8dd688b2015-01-22 10:16:09 -0800608void GrDrawTarget::drawPath(GrPipelineBuilder* pipelineBuilder,
joshualitt56995b52014-12-11 15:44:02 -0800609 const GrPathProcessor* pathProc,
joshualitt9853cce2014-11-17 14:22:48 -0800610 const GrPath* path,
611 GrPathRendering::FillType fill) {
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000612 // TODO: extract portions of checkDraw that are relevant to path rendering.
bsalomon49f085d2014-09-05 13:34:00 -0700613 SkASSERT(path);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000614 SkASSERT(this->caps()->pathRenderingSupport());
egdaniel8dd688b2015-01-22 10:16:09 -0800615 SkASSERT(pipelineBuilder);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000616
joshualitt92e496f2014-10-31 13:56:50 -0700617 SkRect devBounds = path->getBounds();
joshualitt8059eb92014-12-29 15:10:07 -0800618 pathProc->viewMatrix().mapRect(&devBounds);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000619
joshualitt2c93efe2014-11-06 12:57:13 -0800620 // Setup clip
bsalomon3e791242014-12-17 13:43:13 -0800621 GrScissorState scissorState;
bsalomon6be6f7c2015-02-26 13:05:21 -0800622 GrPipelineBuilder::AutoRestoreFragmentProcessors arfp;
egdaniel8dd688b2015-01-22 10:16:09 -0800623 GrPipelineBuilder::AutoRestoreStencil ars;
bsalomon6be6f7c2015-02-26 13:05:21 -0800624 if (!this->setupClip(pipelineBuilder, &arfp, &ars, &scissorState, &devBounds)) {
joshualitt2c93efe2014-11-06 12:57:13 -0800625 return;
626 }
627
628 // set stencil settings for path
629 GrStencilSettings stencilSettings;
bsalomon6bc1b5f2015-02-23 09:06:38 -0800630 GrRenderTarget* rt = pipelineBuilder->getRenderTarget();
631 GrStencilBuffer* sb = rt->renderTargetPriv().attachStencilBuffer();
632 this->getPathStencilSettingsForFilltype(fill, sb, &stencilSettings);
joshualitt2c93efe2014-11-06 12:57:13 -0800633
egdaniele36914c2015-02-13 09:00:33 -0800634 GrDrawTarget::PipelineInfo pipelineInfo(pipelineBuilder, &scissorState, pathProc, &devBounds,
635 this);
636 if (pipelineInfo.mustSkipDraw()) {
637 return;
638 }
639
640 this->onDrawPath(pathProc, path, stencilSettings, pipelineInfo);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000641}
642
egdaniel8dd688b2015-01-22 10:16:09 -0800643void GrDrawTarget::drawPaths(GrPipelineBuilder* pipelineBuilder,
joshualitt56995b52014-12-11 15:44:02 -0800644 const GrPathProcessor* pathProc,
joshualitt9853cce2014-11-17 14:22:48 -0800645 const GrPathRange* pathRange,
cdalton55b24af2014-11-25 11:00:56 -0800646 const void* indices,
647 PathIndexType indexType,
648 const float transformValues[],
649 PathTransformType transformType,
joshualitt9853cce2014-11-17 14:22:48 -0800650 int count,
joshualitt92e496f2014-10-31 13:56:50 -0700651 GrPathRendering::FillType fill) {
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000652 SkASSERT(this->caps()->pathRenderingSupport());
bsalomon49f085d2014-09-05 13:34:00 -0700653 SkASSERT(pathRange);
654 SkASSERT(indices);
cdalton55b24af2014-11-25 11:00:56 -0800655 SkASSERT(0 == reinterpret_cast<long>(indices) % GrPathRange::PathIndexSizeInBytes(indexType));
656 SkASSERT(transformValues);
egdaniel8dd688b2015-01-22 10:16:09 -0800657 SkASSERT(pipelineBuilder);
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000658
joshualitt2c93efe2014-11-06 12:57:13 -0800659 // Setup clip
bsalomon3e791242014-12-17 13:43:13 -0800660 GrScissorState scissorState;
bsalomon6be6f7c2015-02-26 13:05:21 -0800661 GrPipelineBuilder::AutoRestoreFragmentProcessors arfp;
egdaniel8dd688b2015-01-22 10:16:09 -0800662 GrPipelineBuilder::AutoRestoreStencil ars;
joshualitt2c93efe2014-11-06 12:57:13 -0800663
bsalomon6be6f7c2015-02-26 13:05:21 -0800664 if (!this->setupClip(pipelineBuilder, &arfp, &ars, &scissorState, NULL)) {
joshualitt2c93efe2014-11-06 12:57:13 -0800665 return;
666 }
667
668 // set stencil settings for path
669 GrStencilSettings stencilSettings;
bsalomon6bc1b5f2015-02-23 09:06:38 -0800670 GrRenderTarget* rt = pipelineBuilder->getRenderTarget();
671 GrStencilBuffer* sb = rt->renderTargetPriv().attachStencilBuffer();
672 this->getPathStencilSettingsForFilltype(fill, sb, &stencilSettings);
joshualitt2c93efe2014-11-06 12:57:13 -0800673
bsalomon50785a32015-02-06 07:02:37 -0800674 // Don't compute a bounding box for dst copy texture, we'll opt
cdaltonb85a0aa2014-07-21 15:32:44 -0700675 // instead for it to just copy the entire dst. Realistically this is a moot
676 // point, because any context that supports NV_path_rendering will also
677 // support NV_blend_equation_advanced.
egdaniele36914c2015-02-13 09:00:33 -0800678 GrDrawTarget::PipelineInfo pipelineInfo(pipelineBuilder, &scissorState, pathProc, NULL, this);
679 if (pipelineInfo.mustSkipDraw()) {
680 return;
681 }
682
683 this->onDrawPaths(pathProc, pathRange, indices, indexType, transformValues,
684 transformType, count, stencilSettings, pipelineInfo);
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000685}
686
joshualitt9853cce2014-11-17 14:22:48 -0800687void GrDrawTarget::clear(const SkIRect* rect,
688 GrColor color,
689 bool canIgnoreRect,
bsalomon63b21962014-11-05 07:05:34 -0800690 GrRenderTarget* renderTarget) {
691 if (fCaps->useDrawInsteadOfClear()) {
692 // This works around a driver bug with clear by drawing a rect instead.
693 // The driver will ignore a clear if it is the only thing rendered to a
694 // target before the target is read.
695 SkIRect rtRect = SkIRect::MakeWH(renderTarget->width(), renderTarget->height());
696 if (NULL == rect || canIgnoreRect || rect->contains(rtRect)) {
697 rect = &rtRect;
698 // We first issue a discard() since that may help tilers.
699 this->discard(renderTarget);
700 }
bsalomon63b21962014-11-05 07:05:34 -0800701
egdaniel8dd688b2015-01-22 10:16:09 -0800702 GrPipelineBuilder pipelineBuilder;
703 pipelineBuilder.setRenderTarget(renderTarget);
joshualitt9853cce2014-11-17 14:22:48 -0800704
egdaniel8dd688b2015-01-22 10:16:09 -0800705 this->drawSimpleRect(&pipelineBuilder, color, SkMatrix::I(), *rect);
bsalomon63b21962014-11-05 07:05:34 -0800706 } else {
707 this->onClear(rect, color, canIgnoreRect, renderTarget);
708 }
709}
710
egdaniel3eee3832014-06-18 13:09:11 -0700711typedef GrTraceMarkerSet::Iter TMIter;
712void GrDrawTarget::saveActiveTraceMarkers() {
713 if (this->caps()->gpuTracingSupport()) {
714 SkASSERT(0 == fStoredTraceMarkers.count());
715 fStoredTraceMarkers.addSet(fActiveTraceMarkers);
716 for (TMIter iter = fStoredTraceMarkers.begin(); iter != fStoredTraceMarkers.end(); ++iter) {
717 this->removeGpuTraceMarker(&(*iter));
718 }
719 }
720}
721
722void GrDrawTarget::restoreActiveTraceMarkers() {
723 if (this->caps()->gpuTracingSupport()) {
724 SkASSERT(0 == fActiveTraceMarkers.count());
725 for (TMIter iter = fStoredTraceMarkers.begin(); iter != fStoredTraceMarkers.end(); ++iter) {
726 this->addGpuTraceMarker(&(*iter));
727 }
728 for (TMIter iter = fActiveTraceMarkers.begin(); iter != fActiveTraceMarkers.end(); ++iter) {
729 this->fStoredTraceMarkers.remove(*iter);
730 }
731 }
732}
733
734void GrDrawTarget::addGpuTraceMarker(const GrGpuTraceMarker* marker) {
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000735 if (this->caps()->gpuTracingSupport()) {
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000736 SkASSERT(fGpuTraceMarkerCount >= 0);
737 this->fActiveTraceMarkers.add(*marker);
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000738 ++fGpuTraceMarkerCount;
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000739 }
740}
741
egdaniel3eee3832014-06-18 13:09:11 -0700742void GrDrawTarget::removeGpuTraceMarker(const GrGpuTraceMarker* marker) {
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000743 if (this->caps()->gpuTracingSupport()) {
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000744 SkASSERT(fGpuTraceMarkerCount >= 1);
745 this->fActiveTraceMarkers.remove(*marker);
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000746 --fGpuTraceMarkerCount;
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000747 }
748}
749
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000750////////////////////////////////////////////////////////////////////////////////
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000751
egdaniel8dd688b2015-01-22 10:16:09 -0800752void GrDrawTarget::drawIndexedInstances(GrPipelineBuilder* pipelineBuilder,
joshualitt56995b52014-12-11 15:44:02 -0800753 const GrGeometryProcessor* gp,
joshualitt9853cce2014-11-17 14:22:48 -0800754 GrPrimitiveType type,
bsalomon@google.com934c5702012-03-20 21:17:58 +0000755 int instanceCount,
756 int verticesPerInstance,
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000757 int indicesPerInstance,
758 const SkRect* devBounds) {
egdaniel8dd688b2015-01-22 10:16:09 -0800759 SkASSERT(pipelineBuilder);
joshualitt9853cce2014-11-17 14:22:48 -0800760
bsalomon@google.com934c5702012-03-20 21:17:58 +0000761 if (!verticesPerInstance || !indicesPerInstance) {
762 return;
763 }
764
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000765 int maxInstancesPerDraw = this->indexCountInCurrentSource() / indicesPerInstance;
766 if (!maxInstancesPerDraw) {
bsalomon@google.com934c5702012-03-20 21:17:58 +0000767 return;
768 }
769
joshualitt2c93efe2014-11-06 12:57:13 -0800770 // Setup clip
bsalomon3e791242014-12-17 13:43:13 -0800771 GrScissorState scissorState;
bsalomon6be6f7c2015-02-26 13:05:21 -0800772 GrPipelineBuilder::AutoRestoreFragmentProcessors arfp;
egdaniel8dd688b2015-01-22 10:16:09 -0800773 GrPipelineBuilder::AutoRestoreStencil ars;
bsalomon6be6f7c2015-02-26 13:05:21 -0800774 if (!this->setupClip(pipelineBuilder, &arfp, &ars, &scissorState, devBounds)) {
joshualitt2c93efe2014-11-06 12:57:13 -0800775 return;
776 }
777
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000778 DrawInfo info;
779 info.fPrimitiveType = type;
780 info.fStartIndex = 0;
781 info.fStartVertex = 0;
782 info.fIndicesPerInstance = indicesPerInstance;
783 info.fVerticesPerInstance = verticesPerInstance;
784
785 // Set the same bounds for all the draws.
bsalomon49f085d2014-09-05 13:34:00 -0700786 if (devBounds) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000787 info.setDevBounds(*devBounds);
788 }
joshualitt9176e2c2014-11-20 07:28:52 -0800789
bsalomon@google.com934c5702012-03-20 21:17:58 +0000790 while (instanceCount) {
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000791 info.fInstanceCount = SkTMin(instanceCount, maxInstancesPerDraw);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000792 info.fVertexCount = info.fInstanceCount * verticesPerInstance;
793 info.fIndexCount = info.fInstanceCount * indicesPerInstance;
794
egdaniel8dd688b2015-01-22 10:16:09 -0800795 if (this->checkDraw(*pipelineBuilder,
joshualitt56995b52014-12-11 15:44:02 -0800796 gp,
joshualitt9853cce2014-11-17 14:22:48 -0800797 type,
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000798 info.fStartVertex,
799 info.fStartIndex,
800 info.fVertexCount,
801 info.fIndexCount)) {
egdaniele36914c2015-02-13 09:00:33 -0800802
803 GrDrawTarget::PipelineInfo pipelineInfo(pipelineBuilder, &scissorState, gp, devBounds,
804 this);
805 if (pipelineInfo.mustSkipDraw()) {
806 return;
807 }
808
joshualitt2e3b3e32014-12-09 13:31:14 -0800809 this->setDrawBuffers(&info, gp->getVertexStride());
egdaniele36914c2015-02-13 09:00:33 -0800810 this->onDraw(gp, info, pipelineInfo);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000811 }
812 info.fStartVertex += info.fVertexCount;
813 instanceCount -= info.fInstanceCount;
bsalomon@google.com934c5702012-03-20 21:17:58 +0000814 }
815}
bsalomon@google.com3d0835b2011-12-08 16:12:03 +0000816
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000817////////////////////////////////////////////////////////////////////////////////
818
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000819GrDrawTarget::AutoReleaseGeometry::AutoReleaseGeometry(
820 GrDrawTarget* target,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000821 int vertexCount,
joshualitt9853cce2014-11-17 14:22:48 -0800822 size_t vertexStride,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000823 int indexCount) {
824 fTarget = NULL;
joshualitt9853cce2014-11-17 14:22:48 -0800825 this->set(target, vertexCount, vertexStride, indexCount);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000826}
rmistry@google.comd6176b02012-08-23 18:14:13 +0000827
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000828GrDrawTarget::AutoReleaseGeometry::AutoReleaseGeometry() {
829 fTarget = NULL;
830}
831
832GrDrawTarget::AutoReleaseGeometry::~AutoReleaseGeometry() {
833 this->reset();
834}
835
836bool GrDrawTarget::AutoReleaseGeometry::set(GrDrawTarget* target,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000837 int vertexCount,
joshualitt9853cce2014-11-17 14:22:48 -0800838 size_t vertexStride,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000839 int indexCount) {
840 this->reset();
841 fTarget = target;
842 bool success = true;
bsalomon49f085d2014-09-05 13:34:00 -0700843 if (fTarget) {
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000844 success = target->reserveVertexAndIndexSpace(vertexCount,
joshualitt9853cce2014-11-17 14:22:48 -0800845 vertexStride,
bsalomon@google.come3d70952012-03-13 12:40:53 +0000846 indexCount,
847 &fVertices,
848 &fIndices);
849 if (!success) {
850 fTarget = NULL;
851 this->reset();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000852 }
853 }
bsalomon49f085d2014-09-05 13:34:00 -0700854 SkASSERT(success == SkToBool(fTarget));
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000855 return success;
856}
857
858void GrDrawTarget::AutoReleaseGeometry::reset() {
bsalomon49f085d2014-09-05 13:34:00 -0700859 if (fTarget) {
860 if (fVertices) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000861 fTarget->resetVertexSource();
862 }
bsalomon49f085d2014-09-05 13:34:00 -0700863 if (fIndices) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000864 fTarget->resetIndexSource();
865 }
866 fTarget = NULL;
867 }
bsalomon@google.comcb0c5ab2011-06-29 17:48:17 +0000868 fVertices = NULL;
869 fIndices = NULL;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000870}
871
bsalomon@google.com116ad842013-04-09 15:38:19 +0000872namespace {
873// returns true if the read/written rect intersects the src/dst and false if not.
874bool clip_srcrect_and_dstpoint(const GrSurface* dst,
875 const GrSurface* src,
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000876 const SkIRect& srcRect,
bsalomon@google.com116ad842013-04-09 15:38:19 +0000877 const SkIPoint& dstPoint,
878 SkIRect* clippedSrcRect,
879 SkIPoint* clippedDstPoint) {
880 *clippedSrcRect = srcRect;
881 *clippedDstPoint = dstPoint;
skia.committer@gmail.coma9493a32013-04-04 07:01:12 +0000882
bsalomon@google.com116ad842013-04-09 15:38:19 +0000883 // clip the left edge to src and dst bounds, adjusting dstPoint if necessary
884 if (clippedSrcRect->fLeft < 0) {
885 clippedDstPoint->fX -= clippedSrcRect->fLeft;
886 clippedSrcRect->fLeft = 0;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000887 }
bsalomon@google.com116ad842013-04-09 15:38:19 +0000888 if (clippedDstPoint->fX < 0) {
889 clippedSrcRect->fLeft -= clippedDstPoint->fX;
890 clippedDstPoint->fX = 0;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000891 }
892
bsalomon@google.com116ad842013-04-09 15:38:19 +0000893 // clip the top edge to src and dst bounds, adjusting dstPoint if necessary
894 if (clippedSrcRect->fTop < 0) {
895 clippedDstPoint->fY -= clippedSrcRect->fTop;
896 clippedSrcRect->fTop = 0;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000897 }
bsalomon@google.com116ad842013-04-09 15:38:19 +0000898 if (clippedDstPoint->fY < 0) {
899 clippedSrcRect->fTop -= clippedDstPoint->fY;
900 clippedDstPoint->fY = 0;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000901 }
skia.committer@gmail.coma9493a32013-04-04 07:01:12 +0000902
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000903 // clip the right edge to the src and dst bounds.
bsalomon@google.com116ad842013-04-09 15:38:19 +0000904 if (clippedSrcRect->fRight > src->width()) {
905 clippedSrcRect->fRight = src->width();
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000906 }
bsalomon@google.com116ad842013-04-09 15:38:19 +0000907 if (clippedDstPoint->fX + clippedSrcRect->width() > dst->width()) {
908 clippedSrcRect->fRight = clippedSrcRect->fLeft + dst->width() - clippedDstPoint->fX;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000909 }
910
911 // clip the bottom edge to the src and dst bounds.
bsalomon@google.com116ad842013-04-09 15:38:19 +0000912 if (clippedSrcRect->fBottom > src->height()) {
913 clippedSrcRect->fBottom = src->height();
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000914 }
bsalomon@google.com116ad842013-04-09 15:38:19 +0000915 if (clippedDstPoint->fY + clippedSrcRect->height() > dst->height()) {
916 clippedSrcRect->fBottom = clippedSrcRect->fTop + dst->height() - clippedDstPoint->fY;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000917 }
skia.committer@gmail.coma9493a32013-04-04 07:01:12 +0000918
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000919 // The above clipping steps may have inverted the rect if it didn't intersect either the src or
920 // dst bounds.
bsalomon@google.com116ad842013-04-09 15:38:19 +0000921 return !clippedSrcRect->isEmpty();
922}
923}
924
925bool GrDrawTarget::copySurface(GrSurface* dst,
926 GrSurface* src,
927 const SkIRect& srcRect,
928 const SkIPoint& dstPoint) {
bsalomon49f085d2014-09-05 13:34:00 -0700929 SkASSERT(dst);
930 SkASSERT(src);
bsalomon@google.com116ad842013-04-09 15:38:19 +0000931
932 SkIRect clippedSrcRect;
933 SkIPoint clippedDstPoint;
934 // If the rect is outside the src or dst then we've already succeeded.
935 if (!clip_srcrect_and_dstpoint(dst,
936 src,
937 srcRect,
938 dstPoint,
939 &clippedSrcRect,
940 &clippedDstPoint)) {
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000941 return true;
942 }
943
bsalomonf90a02b2014-11-26 12:28:00 -0800944 if (this->onCopySurface(dst, src, clippedSrcRect, clippedDstPoint)) {
945 return true;
joshualitta7024152014-11-03 14:16:35 -0800946 }
947
948 GrRenderTarget* rt = dst->asRenderTarget();
949 GrTexture* tex = src->asTexture();
950
bsalomonf90a02b2014-11-26 12:28:00 -0800951 if ((dst == src) || !rt || !tex) {
952 return false;
953 }
954
egdaniel8dd688b2015-01-22 10:16:09 -0800955 GrPipelineBuilder pipelineBuilder;
956 pipelineBuilder.setRenderTarget(rt);
joshualitta7024152014-11-03 14:16:35 -0800957 SkMatrix matrix;
958 matrix.setTranslate(SkIntToScalar(clippedSrcRect.fLeft - clippedDstPoint.fX),
959 SkIntToScalar(clippedSrcRect.fTop - clippedDstPoint.fY));
960 matrix.postIDiv(tex->width(), tex->height());
egdaniel8dd688b2015-01-22 10:16:09 -0800961 pipelineBuilder.addColorTextureProcessor(tex, matrix);
joshualitta7024152014-11-03 14:16:35 -0800962 SkIRect dstRect = SkIRect::MakeXYWH(clippedDstPoint.fX,
963 clippedDstPoint.fY,
964 clippedSrcRect.width(),
965 clippedSrcRect.height());
egdaniel8dd688b2015-01-22 10:16:09 -0800966 this->drawSimpleRect(&pipelineBuilder, GrColor_WHITE, SkMatrix::I(), dstRect);
joshualitta7024152014-11-03 14:16:35 -0800967 return true;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000968}
969
joshualitt9853cce2014-11-17 14:22:48 -0800970bool GrDrawTarget::canCopySurface(const GrSurface* dst,
971 const GrSurface* src,
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000972 const SkIRect& srcRect,
973 const SkIPoint& dstPoint) {
bsalomon49f085d2014-09-05 13:34:00 -0700974 SkASSERT(dst);
975 SkASSERT(src);
bsalomon@google.com116ad842013-04-09 15:38:19 +0000976
977 SkIRect clippedSrcRect;
978 SkIPoint clippedDstPoint;
979 // If the rect is outside the src or dst then we're guaranteed success
980 if (!clip_srcrect_and_dstpoint(dst,
981 src,
982 srcRect,
983 dstPoint,
984 &clippedSrcRect,
985 &clippedDstPoint)) {
986 return true;
987 }
bsalomonf90a02b2014-11-26 12:28:00 -0800988 return this->internalCanCopySurface(dst, src, clippedSrcRect, clippedDstPoint);
989}
bsalomon@google.com116ad842013-04-09 15:38:19 +0000990
bsalomonf90a02b2014-11-26 12:28:00 -0800991bool GrDrawTarget::internalCanCopySurface(const GrSurface* dst,
992 const GrSurface* src,
993 const SkIRect& clippedSrcRect,
994 const SkIPoint& clippedDstPoint) {
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000995 // Check that the read/write rects are contained within the src/dst bounds.
joshualitta7024152014-11-03 14:16:35 -0800996 SkASSERT(!clippedSrcRect.isEmpty());
997 SkASSERT(SkIRect::MakeWH(src->width(), src->height()).contains(clippedSrcRect));
998 SkASSERT(clippedDstPoint.fX >= 0 && clippedDstPoint.fY >= 0);
999 SkASSERT(clippedDstPoint.fX + clippedSrcRect.width() <= dst->width() &&
1000 clippedDstPoint.fY + clippedSrcRect.height() <= dst->height());
bsalomon@google.come4617bf2013-04-03 14:56:40 +00001001
bsalomonf90a02b2014-11-26 12:28:00 -08001002 // The base class can do it as a draw or the subclass may be able to handle it.
1003 return ((dst != src) && dst->asRenderTarget() && src->asTexture()) ||
1004 this->onCanCopySurface(dst, src, clippedSrcRect, clippedDstPoint);
bsalomon@google.comeb851172013-04-15 13:51:00 +00001005}
1006
egdaniele36914c2015-02-13 09:00:33 -08001007void GrDrawTarget::setupPipeline(const PipelineInfo& pipelineInfo,
1008 GrPipeline* pipeline) {
1009 SkNEW_PLACEMENT_ARGS(pipeline, GrPipeline, (*pipelineInfo.fPipelineBuilder,
1010 pipelineInfo.fColorPOI,
1011 pipelineInfo.fCoveragePOI,
1012 *this->caps(),
1013 *pipelineInfo.fScissor,
1014 &pipelineInfo.fDstCopy));
1015}
1016///////////////////////////////////////////////////////////////////////////////
1017
1018GrDrawTarget::PipelineInfo::PipelineInfo(GrPipelineBuilder* pipelineBuilder,
1019 GrScissorState* scissor,
1020 const GrPrimitiveProcessor* primProc,
1021 const SkRect* devBounds,
1022 GrDrawTarget* target)
1023 : fPipelineBuilder(pipelineBuilder)
1024 , fScissor(scissor) {
1025 fColorPOI = fPipelineBuilder->colorProcInfo(primProc);
1026 fCoveragePOI = fPipelineBuilder->coverageProcInfo(primProc);
1027 if (!target->setupDstReadIfNecessary(*fPipelineBuilder, fColorPOI, fCoveragePOI,
1028 &fDstCopy, devBounds)) {
1029 fPipelineBuilder = NULL;
1030 }
1031}
1032
1033GrDrawTarget::PipelineInfo::PipelineInfo(GrPipelineBuilder* pipelineBuilder,
1034 GrScissorState* scissor,
1035 const GrBatch* batch,
1036 const SkRect* devBounds,
1037 GrDrawTarget* target)
1038 : fPipelineBuilder(pipelineBuilder)
1039 , fScissor(scissor) {
1040 fColorPOI = fPipelineBuilder->colorProcInfo(batch);
1041 fCoveragePOI = fPipelineBuilder->coverageProcInfo(batch);
1042 if (!target->setupDstReadIfNecessary(*fPipelineBuilder, fColorPOI, fCoveragePOI,
1043 &fDstCopy, devBounds)) {
1044 fPipelineBuilder = NULL;
1045 }
1046}
1047
bsalomon@google.combcce8922013-03-25 15:38:39 +00001048///////////////////////////////////////////////////////////////////////////////
1049
bsalomon@google.comc26d94f2013-03-25 18:19:00 +00001050void GrDrawTargetCaps::reset() {
commit-bot@chromium.org47442312013-12-19 16:18:01 +00001051 fMipMapSupport = false;
bsalomon@google.combcce8922013-03-25 15:38:39 +00001052 fNPOTTextureTileSupport = false;
1053 fTwoSidedStencilSupport = false;
1054 fStencilWrapOpsSupport = false;
1055 fHWAALineSupport = false;
1056 fShaderDerivativeSupport = false;
1057 fGeometryShaderSupport = false;
skia.committer@gmail.come60ed082013-03-26 07:01:04 +00001058 fDualSourceBlendingSupport = false;
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +00001059 fPathRenderingSupport = false;
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +00001060 fDstReadInShaderSupport = false;
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +00001061 fDiscardRenderTargetSupport = false;
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +00001062 fReuseScratchTextures = true;
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +00001063 fGpuTracingSupport = false;
krajcevski786978162014-07-30 11:25:44 -07001064 fCompressedTexSubImageSupport = false;
bsalomond08ea5f2015-02-20 06:58:13 -08001065 fOversizedStencilSupport = false;
bsalomon@google.combcce8922013-03-25 15:38:39 +00001066
bsalomon63b21962014-11-05 07:05:34 -08001067 fUseDrawInsteadOfClear = false;
1068
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001069 fMapBufferFlags = kNone_MapFlags;
1070
bsalomon@google.combcce8922013-03-25 15:38:39 +00001071 fMaxRenderTargetSize = 0;
1072 fMaxTextureSize = 0;
1073 fMaxSampleCount = 0;
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001074
bsalomon17168df2014-12-09 09:00:49 -08001075 fShaderPrecisionVaries = false;
1076
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001077 memset(fConfigRenderSupport, 0, sizeof(fConfigRenderSupport));
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001078 memset(fConfigTextureSupport, 0, sizeof(fConfigTextureSupport));
bsalomon@google.combcce8922013-03-25 15:38:39 +00001079}
1080
bsalomon@google.comc26d94f2013-03-25 18:19:00 +00001081GrDrawTargetCaps& GrDrawTargetCaps::operator=(const GrDrawTargetCaps& other) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +00001082 fMipMapSupport = other.fMipMapSupport;
bsalomon@google.combcce8922013-03-25 15:38:39 +00001083 fNPOTTextureTileSupport = other.fNPOTTextureTileSupport;
1084 fTwoSidedStencilSupport = other.fTwoSidedStencilSupport;
1085 fStencilWrapOpsSupport = other.fStencilWrapOpsSupport;
1086 fHWAALineSupport = other.fHWAALineSupport;
1087 fShaderDerivativeSupport = other.fShaderDerivativeSupport;
1088 fGeometryShaderSupport = other.fGeometryShaderSupport;
1089 fDualSourceBlendingSupport = other.fDualSourceBlendingSupport;
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +00001090 fPathRenderingSupport = other.fPathRenderingSupport;
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +00001091 fDstReadInShaderSupport = other.fDstReadInShaderSupport;
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +00001092 fDiscardRenderTargetSupport = other.fDiscardRenderTargetSupport;
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +00001093 fReuseScratchTextures = other.fReuseScratchTextures;
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +00001094 fGpuTracingSupport = other.fGpuTracingSupport;
krajcevski786978162014-07-30 11:25:44 -07001095 fCompressedTexSubImageSupport = other.fCompressedTexSubImageSupport;
bsalomond08ea5f2015-02-20 06:58:13 -08001096 fOversizedStencilSupport = other.fOversizedStencilSupport;
bsalomon@google.combcce8922013-03-25 15:38:39 +00001097
bsalomon63b21962014-11-05 07:05:34 -08001098 fUseDrawInsteadOfClear = other.fUseDrawInsteadOfClear;
1099
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001100 fMapBufferFlags = other.fMapBufferFlags;
1101
bsalomon@google.combcce8922013-03-25 15:38:39 +00001102 fMaxRenderTargetSize = other.fMaxRenderTargetSize;
1103 fMaxTextureSize = other.fMaxTextureSize;
1104 fMaxSampleCount = other.fMaxSampleCount;
1105
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001106 memcpy(fConfigRenderSupport, other.fConfigRenderSupport, sizeof(fConfigRenderSupport));
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001107 memcpy(fConfigTextureSupport, other.fConfigTextureSupport, sizeof(fConfigTextureSupport));
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001108
bsalomon17168df2014-12-09 09:00:49 -08001109 fShaderPrecisionVaries = other.fShaderPrecisionVaries;
1110 for (int s = 0; s < kGrShaderTypeCount; ++s) {
bsalomonc0bd6482014-12-09 10:04:14 -08001111 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
bsalomon17168df2014-12-09 09:00:49 -08001112 fFloatPrecisions[s][p] = other.fFloatPrecisions[s][p];
1113 }
1114 }
bsalomon@google.combcce8922013-03-25 15:38:39 +00001115 return *this;
1116}
1117
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001118static SkString map_flags_to_string(uint32_t flags) {
1119 SkString str;
1120 if (GrDrawTargetCaps::kNone_MapFlags == flags) {
1121 str = "none";
1122 } else {
1123 SkASSERT(GrDrawTargetCaps::kCanMap_MapFlag & flags);
1124 SkDEBUGCODE(flags &= ~GrDrawTargetCaps::kCanMap_MapFlag);
1125 str = "can_map";
1126
1127 if (GrDrawTargetCaps::kSubset_MapFlag & flags) {
1128 str.append(" partial");
1129 } else {
1130 str.append(" full");
1131 }
1132 SkDEBUGCODE(flags &= ~GrDrawTargetCaps::kSubset_MapFlag);
1133 }
1134 SkASSERT(0 == flags); // Make sure we handled all the flags.
1135 return str;
1136}
1137
bsalomon17168df2014-12-09 09:00:49 -08001138static const char* shader_type_to_string(GrShaderType type) {
1139 switch (type) {
1140 case kVertex_GrShaderType:
1141 return "vertex";
1142 case kGeometry_GrShaderType:
1143 return "geometry";
1144 case kFragment_GrShaderType:
1145 return "fragment";
1146 }
1147 return "";
1148}
1149
bsalomonc0bd6482014-12-09 10:04:14 -08001150static const char* precision_to_string(GrSLPrecision p) {
bsalomon17168df2014-12-09 09:00:49 -08001151 switch (p) {
bsalomonc0bd6482014-12-09 10:04:14 -08001152 case kLow_GrSLPrecision:
bsalomon17168df2014-12-09 09:00:49 -08001153 return "low";
bsalomonc0bd6482014-12-09 10:04:14 -08001154 case kMedium_GrSLPrecision:
bsalomon17168df2014-12-09 09:00:49 -08001155 return "medium";
bsalomonc0bd6482014-12-09 10:04:14 -08001156 case kHigh_GrSLPrecision:
bsalomon17168df2014-12-09 09:00:49 -08001157 return "high";
1158 }
1159 return "";
1160}
1161
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001162SkString GrDrawTargetCaps::dump() const {
1163 SkString r;
bsalomon@google.com18c9c192011-09-22 21:01:31 +00001164 static const char* gNY[] = {"NO", "YES"};
bsalomon63b21962014-11-05 07:05:34 -08001165 r.appendf("MIP Map Support : %s\n", gNY[fMipMapSupport]);
1166 r.appendf("NPOT Texture Tile Support : %s\n", gNY[fNPOTTextureTileSupport]);
1167 r.appendf("Two Sided Stencil Support : %s\n", gNY[fTwoSidedStencilSupport]);
1168 r.appendf("Stencil Wrap Ops Support : %s\n", gNY[fStencilWrapOpsSupport]);
1169 r.appendf("HW AA Lines Support : %s\n", gNY[fHWAALineSupport]);
1170 r.appendf("Shader Derivative Support : %s\n", gNY[fShaderDerivativeSupport]);
1171 r.appendf("Geometry Shader Support : %s\n", gNY[fGeometryShaderSupport]);
1172 r.appendf("Dual Source Blending Support : %s\n", gNY[fDualSourceBlendingSupport]);
1173 r.appendf("Path Rendering Support : %s\n", gNY[fPathRenderingSupport]);
1174 r.appendf("Dst Read In Shader Support : %s\n", gNY[fDstReadInShaderSupport]);
1175 r.appendf("Discard Render Target Support : %s\n", gNY[fDiscardRenderTargetSupport]);
1176 r.appendf("Reuse Scratch Textures : %s\n", gNY[fReuseScratchTextures]);
1177 r.appendf("Gpu Tracing Support : %s\n", gNY[fGpuTracingSupport]);
1178 r.appendf("Compressed Update Support : %s\n", gNY[fCompressedTexSubImageSupport]);
bsalomond08ea5f2015-02-20 06:58:13 -08001179 r.appendf("Oversized Stencil Support : %s\n", gNY[fOversizedStencilSupport]);
bsalomon63b21962014-11-05 07:05:34 -08001180 r.appendf("Draw Instead of Clear [workaround] : %s\n", gNY[fUseDrawInsteadOfClear]);
1181
1182 r.appendf("Max Texture Size : %d\n", fMaxTextureSize);
1183 r.appendf("Max Render Target Size : %d\n", fMaxRenderTargetSize);
1184 r.appendf("Max Sample Count : %d\n", fMaxSampleCount);
1185
1186 r.appendf("Map Buffer Support : %s\n",
1187 map_flags_to_string(fMapBufferFlags).c_str());
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001188
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001189 static const char* kConfigNames[] = {
1190 "Unknown", // kUnknown_GrPixelConfig
1191 "Alpha8", // kAlpha_8_GrPixelConfig,
1192 "Index8", // kIndex_8_GrPixelConfig,
1193 "RGB565", // kRGB_565_GrPixelConfig,
1194 "RGBA444", // kRGBA_4444_GrPixelConfig,
1195 "RGBA8888", // kRGBA_8888_GrPixelConfig,
1196 "BGRA8888", // kBGRA_8888_GrPixelConfig,
jvanverthfa1e8a72014-12-22 08:31:49 -08001197 "SRGBA8888",// kSRGBA_8888_GrPixelConfig,
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001198 "ETC1", // kETC1_GrPixelConfig,
1199 "LATC", // kLATC_GrPixelConfig,
krajcevski238b4562014-06-30 09:09:22 -07001200 "R11EAC", // kR11_EAC_GrPixelConfig,
krajcevski7ef21622014-07-16 15:21:13 -07001201 "ASTC12x12",// kASTC_12x12_GrPixelConfig,
jvanverth28f9c602014-12-05 13:06:35 -08001202 "RGBAFloat",// kRGBA_float_GrPixelConfig
1203 "AlphaHalf",// kAlpha_half_GrPixelConfig
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001204 };
krajcevski7ef21622014-07-16 15:21:13 -07001205 GR_STATIC_ASSERT(0 == kUnknown_GrPixelConfig);
1206 GR_STATIC_ASSERT(1 == kAlpha_8_GrPixelConfig);
1207 GR_STATIC_ASSERT(2 == kIndex_8_GrPixelConfig);
1208 GR_STATIC_ASSERT(3 == kRGB_565_GrPixelConfig);
1209 GR_STATIC_ASSERT(4 == kRGBA_4444_GrPixelConfig);
1210 GR_STATIC_ASSERT(5 == kRGBA_8888_GrPixelConfig);
1211 GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig);
jvanverthfa1e8a72014-12-22 08:31:49 -08001212 GR_STATIC_ASSERT(7 == kSRGBA_8888_GrPixelConfig);
1213 GR_STATIC_ASSERT(8 == kETC1_GrPixelConfig);
1214 GR_STATIC_ASSERT(9 == kLATC_GrPixelConfig);
1215 GR_STATIC_ASSERT(10 == kR11_EAC_GrPixelConfig);
1216 GR_STATIC_ASSERT(11 == kASTC_12x12_GrPixelConfig);
1217 GR_STATIC_ASSERT(12 == kRGBA_float_GrPixelConfig);
1218 GR_STATIC_ASSERT(13 == kAlpha_half_GrPixelConfig);
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001219 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kConfigNames) == kGrPixelConfigCnt);
1220
commit-bot@chromium.org99017272013-11-08 18:45:27 +00001221 SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][0]);
1222 SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][1]);
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001223
1224 for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) {
1225 r.appendf("%s is renderable: %s, with MSAA: %s\n",
1226 kConfigNames[i],
1227 gNY[fConfigRenderSupport[i][0]],
1228 gNY[fConfigRenderSupport[i][1]]);
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001229 }
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +00001230
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001231 SkASSERT(!fConfigTextureSupport[kUnknown_GrPixelConfig]);
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +00001232
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001233 for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) {
1234 r.appendf("%s is uploadable to a texture: %s\n",
1235 kConfigNames[i],
1236 gNY[fConfigTextureSupport[i]]);
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +00001237 }
1238
bsalomon17168df2014-12-09 09:00:49 -08001239 r.appendf("Shader Float Precisions (varies: %s):\n", gNY[fShaderPrecisionVaries]);
1240
1241 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1242 GrShaderType shaderType = static_cast<GrShaderType>(s);
1243 r.appendf("\t%s:\n", shader_type_to_string(shaderType));
bsalomonc0bd6482014-12-09 10:04:14 -08001244 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
bsalomon17168df2014-12-09 09:00:49 -08001245 if (fFloatPrecisions[s][p].supported()) {
bsalomonc0bd6482014-12-09 10:04:14 -08001246 GrSLPrecision precision = static_cast<GrSLPrecision>(p);
bsalomon17168df2014-12-09 09:00:49 -08001247 r.appendf("\t\t%s: log_low: %d log_high: %d bits: %d\n",
1248 precision_to_string(precision),
1249 fFloatPrecisions[s][p].fLogRangeLow,
1250 fFloatPrecisions[s][p].fLogRangeHigh,
1251 fFloatPrecisions[s][p].fBits);
1252 }
1253 }
1254 }
1255
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001256 return r;
bsalomon@google.com18c9c192011-09-22 21:01:31 +00001257}
egdanielbc127a32014-09-19 12:07:43 -07001258
1259uint32_t GrDrawTargetCaps::CreateUniqueID() {
1260 static int32_t gUniqueID = SK_InvalidUniqueID;
1261 uint32_t id;
1262 do {
1263 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1);
1264 } while (id == SK_InvalidUniqueID);
1265 return id;
1266}
1267
joshualitt2c93efe2014-11-06 12:57:13 -08001268///////////////////////////////////////////////////////////////////////////////////////////////////
1269
egdaniel8dd688b2015-01-22 10:16:09 -08001270bool GrClipTarget::setupClip(GrPipelineBuilder* pipelineBuilder,
bsalomon6be6f7c2015-02-26 13:05:21 -08001271 GrPipelineBuilder::AutoRestoreFragmentProcessors* arfp,
egdaniel8dd688b2015-01-22 10:16:09 -08001272 GrPipelineBuilder::AutoRestoreStencil* ars,
joshualitt8059eb92014-12-29 15:10:07 -08001273 GrScissorState* scissorState,
1274 const SkRect* devBounds) {
egdaniel8dd688b2015-01-22 10:16:09 -08001275 return fClipMaskManager.setupClipping(pipelineBuilder,
bsalomon6be6f7c2015-02-26 13:05:21 -08001276 arfp,
joshualitt2c93efe2014-11-06 12:57:13 -08001277 ars,
joshualitt9853cce2014-11-17 14:22:48 -08001278 scissorState,
joshualitt9853cce2014-11-17 14:22:48 -08001279 devBounds);
joshualitt2c93efe2014-11-06 12:57:13 -08001280}