blob: e8a758d25f3346d4702fcf9febbe2538779a9abd [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
joshualittd5a7db42015-01-27 15:39:06 -08009
joshualittc2893c52015-01-28 06:54:30 -080010
11#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
egdaniel8dd688b2015-01-22 10:16:09 -0800309bool GrDrawTarget::checkDraw(const GrPipelineBuilder& pipelineBuilder,
joshualitt56995b52014-12-11 15:44:02 -0800310 const GrGeometryProcessor* gp,
joshualitt9853cce2014-11-17 14:22:48 -0800311 GrPrimitiveType type,
312 int startVertex,
313 int startIndex,
314 int vertexCount,
bsalomon@google.come8262622011-11-07 02:30:51 +0000315 int indexCount) const {
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000316#ifdef SK_DEBUG
bsalomon@google.come8262622011-11-07 02:30:51 +0000317 const GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000318 int maxVertex = startVertex + vertexCount;
319 int maxValidVertex;
320 switch (geoSrc.fVertexSrc) {
321 case kNone_GeometrySrcType:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000322 SkFAIL("Attempting to draw without vertex src.");
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000323 case kReserved_GeometrySrcType: // fallthrough
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000324 maxValidVertex = geoSrc.fVertexCount;
325 break;
326 case kBuffer_GeometrySrcType:
egdaniel8dd688b2015-01-22 10:16:09 -0800327 maxValidVertex = static_cast<int>(geoSrc.fVertexBuffer->gpuMemorySize() /
328 geoSrc.fVertexSize);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000329 break;
330 }
331 if (maxVertex > maxValidVertex) {
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000332 SkFAIL("Drawing outside valid vertex range.");
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000333 }
bsalomon@google.come8262622011-11-07 02:30:51 +0000334 if (indexCount > 0) {
335 int maxIndex = startIndex + indexCount;
336 int maxValidIndex;
337 switch (geoSrc.fIndexSrc) {
338 case kNone_GeometrySrcType:
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000339 SkFAIL("Attempting to draw indexed geom without index src.");
bsalomon@google.come8262622011-11-07 02:30:51 +0000340 case kReserved_GeometrySrcType: // fallthrough
bsalomon@google.come8262622011-11-07 02:30:51 +0000341 maxValidIndex = geoSrc.fIndexCount;
342 break;
343 case kBuffer_GeometrySrcType:
egdaniel8dd688b2015-01-22 10:16:09 -0800344 maxValidIndex = static_cast<int>(geoSrc.fIndexBuffer->gpuMemorySize() /
345 sizeof(uint16_t));
bsalomon@google.come8262622011-11-07 02:30:51 +0000346 break;
347 }
348 if (maxIndex > maxValidIndex) {
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +0000349 SkFAIL("Index reads outside valid index range.");
bsalomon@google.come8262622011-11-07 02:30:51 +0000350 }
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000351 }
bsalomon@google.comb4725b42012-03-30 17:24:17 +0000352
egdaniel8dd688b2015-01-22 10:16:09 -0800353 SkASSERT(pipelineBuilder.getRenderTarget());
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000354
joshualitt56995b52014-12-11 15:44:02 -0800355 if (gp) {
joshualittb0a8a372014-09-23 09:50:21 -0700356 int numTextures = gp->numTextures();
joshualittbd769d02014-09-04 08:56:46 -0700357 for (int t = 0; t < numTextures; ++t) {
joshualittb0a8a372014-09-23 09:50:21 -0700358 GrTexture* texture = gp->texture(t);
egdaniel8dd688b2015-01-22 10:16:09 -0800359 SkASSERT(texture->asRenderTarget() != pipelineBuilder.getRenderTarget());
joshualittbd769d02014-09-04 08:56:46 -0700360 }
361 }
362
egdaniel8dd688b2015-01-22 10:16:09 -0800363 for (int s = 0; s < pipelineBuilder.numColorStages(); ++s) {
364 const GrProcessor* effect = pipelineBuilder.getColorStage(s).processor();
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000365 int numTextures = effect->numTextures();
366 for (int t = 0; t < numTextures; ++t) {
367 GrTexture* texture = effect->texture(t);
egdaniel8dd688b2015-01-22 10:16:09 -0800368 SkASSERT(texture->asRenderTarget() != pipelineBuilder.getRenderTarget());
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000369 }
370 }
egdaniel8dd688b2015-01-22 10:16:09 -0800371 for (int s = 0; s < pipelineBuilder.numCoverageStages(); ++s) {
372 const GrProcessor* effect = pipelineBuilder.getCoverageStage(s).processor();
bsalomon@google.comeb6879f2013-06-13 19:34:18 +0000373 int numTextures = effect->numTextures();
374 for (int t = 0; t < numTextures; ++t) {
375 GrTexture* texture = effect->texture(t);
egdaniel8dd688b2015-01-22 10:16:09 -0800376 SkASSERT(texture->asRenderTarget() != pipelineBuilder.getRenderTarget());
bsalomon@google.comb4725b42012-03-30 17:24:17 +0000377 }
378 }
commit-bot@chromium.orgff6ea262013-03-12 12:26:08 +0000379
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000380#endif
egdaniel8dd688b2015-01-22 10:16:09 -0800381 if (NULL == pipelineBuilder.getRenderTarget()) {
bsalomon@google.com0ba52fc2011-11-10 22:16:06 +0000382 return false;
383 }
bsalomon@google.come8262622011-11-07 02:30:51 +0000384 return true;
385}
386
egdaniel8dd688b2015-01-22 10:16:09 -0800387bool GrDrawTarget::setupDstReadIfNecessary(GrPipelineBuilder* pipelineBuilder,
joshualitt9853cce2014-11-17 14:22:48 -0800388 GrDeviceCoordTexture* dstCopy,
389 const SkRect* drawBounds) {
egdaniel8dd688b2015-01-22 10:16:09 -0800390 if (this->caps()->dstReadInShaderSupport() || !pipelineBuilder->willEffectReadDstColor()) {
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000391 return true;
392 }
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000393 SkIRect copyRect;
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000394 const GrClipData* clip = this->getClip();
egdaniel8dd688b2015-01-22 10:16:09 -0800395 GrRenderTarget* rt = pipelineBuilder->getRenderTarget();
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000396 clip->getConservativeBounds(rt, &copyRect);
397
bsalomon49f085d2014-09-05 13:34:00 -0700398 if (drawBounds) {
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000399 SkIRect drawIBounds;
400 drawBounds->roundOut(&drawIBounds);
commit-bot@chromium.orgbb5c4652013-04-01 12:49:31 +0000401 if (!copyRect.intersect(drawIBounds)) {
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000402#ifdef SK_DEBUG
tfarina38406c82014-10-31 07:11:12 -0700403 SkDebugf("Missed an early reject. Bailing on draw from setupDstReadIfNecessary.\n");
commit-bot@chromium.orgbb5c4652013-04-01 12:49:31 +0000404#endif
405 return false;
406 }
407 } else {
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000408#ifdef SK_DEBUG
tfarina38406c82014-10-31 07:11:12 -0700409 //SkDebugf("No dev bounds when dst copy is made.\n");
commit-bot@chromium.orgbb5c4652013-04-01 12:49:31 +0000410#endif
411 }
skia.committer@gmail.com05a2ee02013-04-02 07:01:34 +0000412
commit-bot@chromium.org63150af2013-04-11 22:00:22 +0000413 // MSAA consideration: When there is support for reading MSAA samples in the shader we could
414 // have per-sample dst values by making the copy multisampled.
bsalomonf2703d82014-10-28 14:33:06 -0700415 GrSurfaceDesc desc;
bsalomon@google.comeb851172013-04-15 13:51:00 +0000416 this->initCopySurfaceDstDesc(rt, &desc);
commit-bot@chromium.orgbb5c4652013-04-01 12:49:31 +0000417 desc.fWidth = copyRect.width();
418 desc.fHeight = copyRect.height();
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000419
bsalomone3059732014-10-14 11:47:22 -0700420 SkAutoTUnref<GrTexture> copy(
421 fContext->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch));
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000422
bsalomone3059732014-10-14 11:47:22 -0700423 if (!copy) {
tfarina38406c82014-10-31 07:11:12 -0700424 SkDebugf("Failed to create temporary copy of destination texture.\n");
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000425 return false;
426 }
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000427 SkIPoint dstPoint = {0, 0};
bsalomone3059732014-10-14 11:47:22 -0700428 if (this->copySurface(copy, rt, copyRect, dstPoint)) {
429 dstCopy->setTexture(copy);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000430 dstCopy->setOffset(copyRect.fLeft, copyRect.fTop);
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000431 return true;
432 } else {
433 return false;
434 }
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000435}
436
egdaniel8dd688b2015-01-22 10:16:09 -0800437void GrDrawTarget::drawIndexed(GrPipelineBuilder* pipelineBuilder,
joshualitt56995b52014-12-11 15:44:02 -0800438 const GrGeometryProcessor* gp,
joshualitt9853cce2014-11-17 14:22:48 -0800439 GrPrimitiveType type,
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000440 int startVertex,
441 int startIndex,
442 int vertexCount,
443 int indexCount,
444 const SkRect* devBounds) {
egdaniel8dd688b2015-01-22 10:16:09 -0800445 SkASSERT(pipelineBuilder);
joshualitt9853cce2014-11-17 14:22:48 -0800446 if (indexCount > 0 &&
egdaniel8dd688b2015-01-22 10:16:09 -0800447 this->checkDraw(*pipelineBuilder, gp, type, startVertex, startIndex, vertexCount,
448 indexCount)) {
joshualitt9853cce2014-11-17 14:22:48 -0800449
joshualitt2c93efe2014-11-06 12:57:13 -0800450 // Setup clip
bsalomon3e791242014-12-17 13:43:13 -0800451 GrScissorState scissorState;
egdaniel8dd688b2015-01-22 10:16:09 -0800452 GrPipelineBuilder::AutoRestoreEffects are;
453 GrPipelineBuilder::AutoRestoreStencil ars;
454 if (!this->setupClip(pipelineBuilder, &are, &ars, &scissorState, devBounds)) {
joshualitt2c93efe2014-11-06 12:57:13 -0800455 return;
456 }
457
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000458 DrawInfo info;
459 info.fPrimitiveType = type;
460 info.fStartVertex = startVertex;
461 info.fStartIndex = startIndex;
462 info.fVertexCount = vertexCount;
463 info.fIndexCount = indexCount;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000464
465 info.fInstanceCount = 0;
466 info.fVerticesPerInstance = 0;
467 info.fIndicesPerInstance = 0;
468
bsalomon49f085d2014-09-05 13:34:00 -0700469 if (devBounds) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000470 info.setDevBounds(*devBounds);
471 }
joshualitt9176e2c2014-11-20 07:28:52 -0800472
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000473 // TODO: We should continue with incorrect blending.
joshualitt9176e2c2014-11-20 07:28:52 -0800474 GrDeviceCoordTexture dstCopy;
egdaniel8dd688b2015-01-22 10:16:09 -0800475 if (!this->setupDstReadIfNecessary(pipelineBuilder, &dstCopy, devBounds)) {
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000476 return;
477 }
joshualitt2e3b3e32014-12-09 13:31:14 -0800478 this->setDrawBuffers(&info, gp->getVertexStride());
joshualitt7eb8c7b2014-11-18 14:24:27 -0800479
egdaniel8dd688b2015-01-22 10:16:09 -0800480 this->onDraw(*pipelineBuilder, gp, info, scissorState, dstCopy.texture() ? &dstCopy : NULL);
bsalomon@google.com82145872011-08-23 14:32:40 +0000481 }
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000482}
483
egdaniel8dd688b2015-01-22 10:16:09 -0800484void GrDrawTarget::drawNonIndexed(GrPipelineBuilder* pipelineBuilder,
joshualitt56995b52014-12-11 15:44:02 -0800485 const GrGeometryProcessor* gp,
joshualitt9853cce2014-11-17 14:22:48 -0800486 GrPrimitiveType type,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000487 int startVertex,
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000488 int vertexCount,
489 const SkRect* devBounds) {
egdaniel8dd688b2015-01-22 10:16:09 -0800490 SkASSERT(pipelineBuilder);
491 if (vertexCount > 0 && this->checkDraw(*pipelineBuilder, gp, type, startVertex, -1, vertexCount,
492 -1)) {
joshualitt9853cce2014-11-17 14:22:48 -0800493
joshualitt2c93efe2014-11-06 12:57:13 -0800494 // Setup clip
bsalomon3e791242014-12-17 13:43:13 -0800495 GrScissorState scissorState;
egdaniel8dd688b2015-01-22 10:16:09 -0800496 GrPipelineBuilder::AutoRestoreEffects are;
497 GrPipelineBuilder::AutoRestoreStencil ars;
498 if (!this->setupClip(pipelineBuilder, &are, &ars, &scissorState, devBounds)) {
joshualitt2c93efe2014-11-06 12:57:13 -0800499 return;
500 }
501
bsalomon@google.com74749cd2013-01-30 16:12:41 +0000502 DrawInfo info;
503 info.fPrimitiveType = type;
504 info.fStartVertex = startVertex;
505 info.fStartIndex = 0;
506 info.fVertexCount = vertexCount;
507 info.fIndexCount = 0;
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000508
509 info.fInstanceCount = 0;
510 info.fVerticesPerInstance = 0;
511 info.fIndicesPerInstance = 0;
512
bsalomon49f085d2014-09-05 13:34:00 -0700513 if (devBounds) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000514 info.setDevBounds(*devBounds);
515 }
joshualitt2c93efe2014-11-06 12:57:13 -0800516
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000517 // TODO: We should continue with incorrect blending.
joshualitt9176e2c2014-11-20 07:28:52 -0800518 GrDeviceCoordTexture dstCopy;
egdaniel8dd688b2015-01-22 10:16:09 -0800519 if (!this->setupDstReadIfNecessary(pipelineBuilder, &dstCopy, devBounds)) {
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000520 return;
521 }
joshualitt7eb8c7b2014-11-18 14:24:27 -0800522
joshualitt2e3b3e32014-12-09 13:31:14 -0800523 this->setDrawBuffers(&info, gp->getVertexStride());
joshualitt7eb8c7b2014-11-18 14:24:27 -0800524
egdaniel8dd688b2015-01-22 10:16:09 -0800525 this->onDraw(*pipelineBuilder, gp, info, scissorState, dstCopy.texture() ? &dstCopy : NULL);
bsalomon@google.com82145872011-08-23 14:32:40 +0000526 }
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000527}
528
joshualitt2c93efe2014-11-06 12:57:13 -0800529static const GrStencilSettings& winding_path_stencil_settings() {
530 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings,
531 kIncClamp_StencilOp,
532 kIncClamp_StencilOp,
533 kAlwaysIfInClip_StencilFunc,
534 0xFFFF, 0xFFFF, 0xFFFF);
535 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings);
536}
537
538static const GrStencilSettings& even_odd_path_stencil_settings() {
539 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings,
540 kInvert_StencilOp,
541 kInvert_StencilOp,
542 kAlwaysIfInClip_StencilFunc,
543 0xFFFF, 0xFFFF, 0xFFFF);
544 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings);
545}
546
547void GrDrawTarget::getPathStencilSettingsForFilltype(GrPathRendering::FillType fill,
joshualitt9853cce2014-11-17 14:22:48 -0800548 const GrStencilBuffer* sb,
joshualitt2c93efe2014-11-06 12:57:13 -0800549 GrStencilSettings* outStencilSettings) {
550
551 switch (fill) {
552 default:
553 SkFAIL("Unexpected path fill.");
554 case GrPathRendering::kWinding_FillType:
555 *outStencilSettings = winding_path_stencil_settings();
556 break;
557 case GrPathRendering::kEvenOdd_FillType:
558 *outStencilSettings = even_odd_path_stencil_settings();
559 break;
560 }
joshualitt9853cce2014-11-17 14:22:48 -0800561 this->clipMaskManager()->adjustPathStencilParams(sb, outStencilSettings);
joshualitt2c93efe2014-11-06 12:57:13 -0800562}
563
egdaniel8dd688b2015-01-22 10:16:09 -0800564void GrDrawTarget::stencilPath(GrPipelineBuilder* pipelineBuilder,
joshualitt56995b52014-12-11 15:44:02 -0800565 const GrPathProcessor* pathProc,
joshualitt9853cce2014-11-17 14:22:48 -0800566 const GrPath* path,
567 GrPathRendering::FillType fill) {
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000568 // TODO: extract portions of checkDraw that are relevant to path stenciling.
bsalomon49f085d2014-09-05 13:34:00 -0700569 SkASSERT(path);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000570 SkASSERT(this->caps()->pathRenderingSupport());
egdaniel8dd688b2015-01-22 10:16:09 -0800571 SkASSERT(pipelineBuilder);
joshualitt2c93efe2014-11-06 12:57:13 -0800572
573 // Setup clip
bsalomon3e791242014-12-17 13:43:13 -0800574 GrScissorState scissorState;
egdaniel8dd688b2015-01-22 10:16:09 -0800575 GrPipelineBuilder::AutoRestoreEffects are;
576 GrPipelineBuilder::AutoRestoreStencil ars;
577 if (!this->setupClip(pipelineBuilder, &are, &ars, &scissorState, NULL)) {
joshualitt2c93efe2014-11-06 12:57:13 -0800578 return;
579 }
580
581 // set stencil settings for path
582 GrStencilSettings stencilSettings;
joshualitt9853cce2014-11-17 14:22:48 -0800583 this->getPathStencilSettingsForFilltype(fill,
egdaniel8dd688b2015-01-22 10:16:09 -0800584 pipelineBuilder->getRenderTarget()->getStencilBuffer(),
joshualitt9853cce2014-11-17 14:22:48 -0800585 &stencilSettings);
joshualitt2c93efe2014-11-06 12:57:13 -0800586
egdaniel8dd688b2015-01-22 10:16:09 -0800587 this->onStencilPath(*pipelineBuilder, pathProc, path, scissorState, stencilSettings);
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000588}
589
egdaniel8dd688b2015-01-22 10:16:09 -0800590void GrDrawTarget::drawPath(GrPipelineBuilder* pipelineBuilder,
joshualitt56995b52014-12-11 15:44:02 -0800591 const GrPathProcessor* pathProc,
joshualitt9853cce2014-11-17 14:22:48 -0800592 const GrPath* path,
593 GrPathRendering::FillType fill) {
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000594 // TODO: extract portions of checkDraw that are relevant to path rendering.
bsalomon49f085d2014-09-05 13:34:00 -0700595 SkASSERT(path);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000596 SkASSERT(this->caps()->pathRenderingSupport());
egdaniel8dd688b2015-01-22 10:16:09 -0800597 SkASSERT(pipelineBuilder);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000598
joshualitt92e496f2014-10-31 13:56:50 -0700599 SkRect devBounds = path->getBounds();
joshualitt8059eb92014-12-29 15:10:07 -0800600 pathProc->viewMatrix().mapRect(&devBounds);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000601
joshualitt2c93efe2014-11-06 12:57:13 -0800602 // Setup clip
bsalomon3e791242014-12-17 13:43:13 -0800603 GrScissorState scissorState;
egdaniel8dd688b2015-01-22 10:16:09 -0800604 GrPipelineBuilder::AutoRestoreEffects are;
605 GrPipelineBuilder::AutoRestoreStencil ars;
606 if (!this->setupClip(pipelineBuilder, &are, &ars, &scissorState, &devBounds)) {
joshualitt2c93efe2014-11-06 12:57:13 -0800607 return;
608 }
609
610 // set stencil settings for path
611 GrStencilSettings stencilSettings;
joshualitt9853cce2014-11-17 14:22:48 -0800612 this->getPathStencilSettingsForFilltype(fill,
egdaniel8dd688b2015-01-22 10:16:09 -0800613 pipelineBuilder->getRenderTarget()->getStencilBuffer(),
joshualitt9853cce2014-11-17 14:22:48 -0800614 &stencilSettings);
joshualitt2c93efe2014-11-06 12:57:13 -0800615
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000616 GrDeviceCoordTexture dstCopy;
egdaniel8dd688b2015-01-22 10:16:09 -0800617 if (!this->setupDstReadIfNecessary(pipelineBuilder, &dstCopy, &devBounds)) {
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000618 return;
619 }
620
egdaniel8dd688b2015-01-22 10:16:09 -0800621 this->onDrawPath(*pipelineBuilder, pathProc, path, scissorState, stencilSettings,
622 dstCopy.texture() ? &dstCopy : NULL);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000623}
624
egdaniel8dd688b2015-01-22 10:16:09 -0800625void GrDrawTarget::drawPaths(GrPipelineBuilder* pipelineBuilder,
joshualitt56995b52014-12-11 15:44:02 -0800626 const GrPathProcessor* pathProc,
joshualitt9853cce2014-11-17 14:22:48 -0800627 const GrPathRange* pathRange,
cdalton55b24af2014-11-25 11:00:56 -0800628 const void* indices,
629 PathIndexType indexType,
630 const float transformValues[],
631 PathTransformType transformType,
joshualitt9853cce2014-11-17 14:22:48 -0800632 int count,
joshualitt92e496f2014-10-31 13:56:50 -0700633 GrPathRendering::FillType fill) {
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000634 SkASSERT(this->caps()->pathRenderingSupport());
bsalomon49f085d2014-09-05 13:34:00 -0700635 SkASSERT(pathRange);
636 SkASSERT(indices);
cdalton55b24af2014-11-25 11:00:56 -0800637 SkASSERT(0 == reinterpret_cast<long>(indices) % GrPathRange::PathIndexSizeInBytes(indexType));
638 SkASSERT(transformValues);
egdaniel8dd688b2015-01-22 10:16:09 -0800639 SkASSERT(pipelineBuilder);
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000640
joshualitt2c93efe2014-11-06 12:57:13 -0800641 // Setup clip
bsalomon3e791242014-12-17 13:43:13 -0800642 GrScissorState scissorState;
egdaniel8dd688b2015-01-22 10:16:09 -0800643 GrPipelineBuilder::AutoRestoreEffects are;
644 GrPipelineBuilder::AutoRestoreStencil ars;
joshualitt2c93efe2014-11-06 12:57:13 -0800645
egdaniel8dd688b2015-01-22 10:16:09 -0800646 if (!this->setupClip(pipelineBuilder, &are, &ars, &scissorState, NULL)) {
joshualitt2c93efe2014-11-06 12:57:13 -0800647 return;
648 }
649
650 // set stencil settings for path
651 GrStencilSettings stencilSettings;
joshualitt9853cce2014-11-17 14:22:48 -0800652 this->getPathStencilSettingsForFilltype(fill,
egdaniel8dd688b2015-01-22 10:16:09 -0800653 pipelineBuilder->getRenderTarget()->getStencilBuffer(),
joshualitt9853cce2014-11-17 14:22:48 -0800654 &stencilSettings);
joshualitt2c93efe2014-11-06 12:57:13 -0800655
cdaltonb85a0aa2014-07-21 15:32:44 -0700656 // Don't compute a bounding box for setupDstReadIfNecessary(), we'll opt
657 // instead for it to just copy the entire dst. Realistically this is a moot
658 // point, because any context that supports NV_path_rendering will also
659 // support NV_blend_equation_advanced.
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000660 GrDeviceCoordTexture dstCopy;
egdaniel8dd688b2015-01-22 10:16:09 -0800661 if (!this->setupDstReadIfNecessary(pipelineBuilder, &dstCopy, NULL)) {
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000662 return;
663 }
664
egdaniel8dd688b2015-01-22 10:16:09 -0800665 this->onDrawPaths(*pipelineBuilder, pathProc, pathRange, indices, indexType, transformValues,
666 transformType, count, scissorState, stencilSettings,
667 dstCopy.texture() ? &dstCopy : NULL);
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000668}
669
joshualitt9853cce2014-11-17 14:22:48 -0800670void GrDrawTarget::clear(const SkIRect* rect,
671 GrColor color,
672 bool canIgnoreRect,
bsalomon63b21962014-11-05 07:05:34 -0800673 GrRenderTarget* renderTarget) {
674 if (fCaps->useDrawInsteadOfClear()) {
675 // This works around a driver bug with clear by drawing a rect instead.
676 // The driver will ignore a clear if it is the only thing rendered to a
677 // target before the target is read.
678 SkIRect rtRect = SkIRect::MakeWH(renderTarget->width(), renderTarget->height());
679 if (NULL == rect || canIgnoreRect || rect->contains(rtRect)) {
680 rect = &rtRect;
681 // We first issue a discard() since that may help tilers.
682 this->discard(renderTarget);
683 }
bsalomon63b21962014-11-05 07:05:34 -0800684
egdaniel8dd688b2015-01-22 10:16:09 -0800685 GrPipelineBuilder pipelineBuilder;
686 pipelineBuilder.setRenderTarget(renderTarget);
joshualitt9853cce2014-11-17 14:22:48 -0800687
egdaniel8dd688b2015-01-22 10:16:09 -0800688 this->drawSimpleRect(&pipelineBuilder, color, SkMatrix::I(), *rect);
bsalomon63b21962014-11-05 07:05:34 -0800689 } else {
690 this->onClear(rect, color, canIgnoreRect, renderTarget);
691 }
692}
693
egdaniel3eee3832014-06-18 13:09:11 -0700694typedef GrTraceMarkerSet::Iter TMIter;
695void GrDrawTarget::saveActiveTraceMarkers() {
696 if (this->caps()->gpuTracingSupport()) {
697 SkASSERT(0 == fStoredTraceMarkers.count());
698 fStoredTraceMarkers.addSet(fActiveTraceMarkers);
699 for (TMIter iter = fStoredTraceMarkers.begin(); iter != fStoredTraceMarkers.end(); ++iter) {
700 this->removeGpuTraceMarker(&(*iter));
701 }
702 }
703}
704
705void GrDrawTarget::restoreActiveTraceMarkers() {
706 if (this->caps()->gpuTracingSupport()) {
707 SkASSERT(0 == fActiveTraceMarkers.count());
708 for (TMIter iter = fStoredTraceMarkers.begin(); iter != fStoredTraceMarkers.end(); ++iter) {
709 this->addGpuTraceMarker(&(*iter));
710 }
711 for (TMIter iter = fActiveTraceMarkers.begin(); iter != fActiveTraceMarkers.end(); ++iter) {
712 this->fStoredTraceMarkers.remove(*iter);
713 }
714 }
715}
716
717void GrDrawTarget::addGpuTraceMarker(const GrGpuTraceMarker* marker) {
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000718 if (this->caps()->gpuTracingSupport()) {
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000719 SkASSERT(fGpuTraceMarkerCount >= 0);
720 this->fActiveTraceMarkers.add(*marker);
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000721 ++fGpuTraceMarkerCount;
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000722 }
723}
724
egdaniel3eee3832014-06-18 13:09:11 -0700725void GrDrawTarget::removeGpuTraceMarker(const GrGpuTraceMarker* marker) {
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000726 if (this->caps()->gpuTracingSupport()) {
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000727 SkASSERT(fGpuTraceMarkerCount >= 1);
728 this->fActiveTraceMarkers.remove(*marker);
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000729 --fGpuTraceMarkerCount;
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000730 }
731}
732
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000733////////////////////////////////////////////////////////////////////////////////
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000734
egdaniel8dd688b2015-01-22 10:16:09 -0800735void GrDrawTarget::drawIndexedInstances(GrPipelineBuilder* pipelineBuilder,
joshualitt56995b52014-12-11 15:44:02 -0800736 const GrGeometryProcessor* gp,
joshualitt9853cce2014-11-17 14:22:48 -0800737 GrPrimitiveType type,
bsalomon@google.com934c5702012-03-20 21:17:58 +0000738 int instanceCount,
739 int verticesPerInstance,
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000740 int indicesPerInstance,
741 const SkRect* devBounds) {
egdaniel8dd688b2015-01-22 10:16:09 -0800742 SkASSERT(pipelineBuilder);
joshualitt9853cce2014-11-17 14:22:48 -0800743
bsalomon@google.com934c5702012-03-20 21:17:58 +0000744 if (!verticesPerInstance || !indicesPerInstance) {
745 return;
746 }
747
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000748 int maxInstancesPerDraw = this->indexCountInCurrentSource() / indicesPerInstance;
749 if (!maxInstancesPerDraw) {
bsalomon@google.com934c5702012-03-20 21:17:58 +0000750 return;
751 }
752
joshualitt2c93efe2014-11-06 12:57:13 -0800753 // Setup clip
bsalomon3e791242014-12-17 13:43:13 -0800754 GrScissorState scissorState;
egdaniel8dd688b2015-01-22 10:16:09 -0800755 GrPipelineBuilder::AutoRestoreEffects are;
756 GrPipelineBuilder::AutoRestoreStencil ars;
757 if (!this->setupClip(pipelineBuilder, &are, &ars, &scissorState, devBounds)) {
joshualitt2c93efe2014-11-06 12:57:13 -0800758 return;
759 }
760
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000761 DrawInfo info;
762 info.fPrimitiveType = type;
763 info.fStartIndex = 0;
764 info.fStartVertex = 0;
765 info.fIndicesPerInstance = indicesPerInstance;
766 info.fVerticesPerInstance = verticesPerInstance;
767
768 // Set the same bounds for all the draws.
bsalomon49f085d2014-09-05 13:34:00 -0700769 if (devBounds) {
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000770 info.setDevBounds(*devBounds);
771 }
joshualitt9176e2c2014-11-20 07:28:52 -0800772
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000773 // TODO: We should continue with incorrect blending.
joshualitt9176e2c2014-11-20 07:28:52 -0800774 GrDeviceCoordTexture dstCopy;
egdaniel8dd688b2015-01-22 10:16:09 -0800775 if (!this->setupDstReadIfNecessary(pipelineBuilder, &dstCopy, devBounds)) {
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000776 return;
777 }
joshualitt7eb8c7b2014-11-18 14:24:27 -0800778
bsalomon@google.com934c5702012-03-20 21:17:58 +0000779 while (instanceCount) {
commit-bot@chromium.org972f9cd2014-03-28 17:58:28 +0000780 info.fInstanceCount = SkTMin(instanceCount, maxInstancesPerDraw);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000781 info.fVertexCount = info.fInstanceCount * verticesPerInstance;
782 info.fIndexCount = info.fInstanceCount * indicesPerInstance;
783
egdaniel8dd688b2015-01-22 10:16:09 -0800784 if (this->checkDraw(*pipelineBuilder,
joshualitt56995b52014-12-11 15:44:02 -0800785 gp,
joshualitt9853cce2014-11-17 14:22:48 -0800786 type,
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000787 info.fStartVertex,
788 info.fStartIndex,
789 info.fVertexCount,
790 info.fIndexCount)) {
joshualitt2e3b3e32014-12-09 13:31:14 -0800791 this->setDrawBuffers(&info, gp->getVertexStride());
egdaniel8dd688b2015-01-22 10:16:09 -0800792 this->onDraw(*pipelineBuilder, gp, info, scissorState,
793 dstCopy.texture() ? &dstCopy : NULL);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +0000794 }
795 info.fStartVertex += info.fVertexCount;
796 instanceCount -= info.fInstanceCount;
bsalomon@google.com934c5702012-03-20 21:17:58 +0000797 }
798}
bsalomon@google.com3d0835b2011-12-08 16:12:03 +0000799
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000800////////////////////////////////////////////////////////////////////////////////
801
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000802GrDrawTarget::AutoReleaseGeometry::AutoReleaseGeometry(
803 GrDrawTarget* target,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000804 int vertexCount,
joshualitt9853cce2014-11-17 14:22:48 -0800805 size_t vertexStride,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000806 int indexCount) {
807 fTarget = NULL;
joshualitt9853cce2014-11-17 14:22:48 -0800808 this->set(target, vertexCount, vertexStride, indexCount);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000809}
rmistry@google.comd6176b02012-08-23 18:14:13 +0000810
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000811GrDrawTarget::AutoReleaseGeometry::AutoReleaseGeometry() {
812 fTarget = NULL;
813}
814
815GrDrawTarget::AutoReleaseGeometry::~AutoReleaseGeometry() {
816 this->reset();
817}
818
819bool GrDrawTarget::AutoReleaseGeometry::set(GrDrawTarget* target,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000820 int vertexCount,
joshualitt9853cce2014-11-17 14:22:48 -0800821 size_t vertexStride,
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000822 int indexCount) {
823 this->reset();
824 fTarget = target;
825 bool success = true;
bsalomon49f085d2014-09-05 13:34:00 -0700826 if (fTarget) {
jvanverth@google.comb75b0a02013-02-05 20:33:30 +0000827 success = target->reserveVertexAndIndexSpace(vertexCount,
joshualitt9853cce2014-11-17 14:22:48 -0800828 vertexStride,
bsalomon@google.come3d70952012-03-13 12:40:53 +0000829 indexCount,
830 &fVertices,
831 &fIndices);
832 if (!success) {
833 fTarget = NULL;
834 this->reset();
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000835 }
836 }
bsalomon49f085d2014-09-05 13:34:00 -0700837 SkASSERT(success == SkToBool(fTarget));
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000838 return success;
839}
840
841void GrDrawTarget::AutoReleaseGeometry::reset() {
bsalomon49f085d2014-09-05 13:34:00 -0700842 if (fTarget) {
843 if (fVertices) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000844 fTarget->resetVertexSource();
845 }
bsalomon49f085d2014-09-05 13:34:00 -0700846 if (fIndices) {
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000847 fTarget->resetIndexSource();
848 }
849 fTarget = NULL;
850 }
bsalomon@google.comcb0c5ab2011-06-29 17:48:17 +0000851 fVertices = NULL;
852 fIndices = NULL;
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000853}
854
bsalomon@google.com8d67c072012-12-13 20:38:14 +0000855GrDrawTarget::AutoClipRestore::AutoClipRestore(GrDrawTarget* target, const SkIRect& newClip) {
856 fTarget = target;
857 fClip = fTarget->getClip();
858 fStack.init();
859 fStack.get()->clipDevRect(newClip, SkRegion::kReplace_Op);
860 fReplacementClip.fClipStack = fStack.get();
861 target->setClip(&fReplacementClip);
862}
863
bsalomon@google.com116ad842013-04-09 15:38:19 +0000864namespace {
865// returns true if the read/written rect intersects the src/dst and false if not.
866bool clip_srcrect_and_dstpoint(const GrSurface* dst,
867 const GrSurface* src,
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000868 const SkIRect& srcRect,
bsalomon@google.com116ad842013-04-09 15:38:19 +0000869 const SkIPoint& dstPoint,
870 SkIRect* clippedSrcRect,
871 SkIPoint* clippedDstPoint) {
872 *clippedSrcRect = srcRect;
873 *clippedDstPoint = dstPoint;
skia.committer@gmail.coma9493a32013-04-04 07:01:12 +0000874
bsalomon@google.com116ad842013-04-09 15:38:19 +0000875 // clip the left edge to src and dst bounds, adjusting dstPoint if necessary
876 if (clippedSrcRect->fLeft < 0) {
877 clippedDstPoint->fX -= clippedSrcRect->fLeft;
878 clippedSrcRect->fLeft = 0;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000879 }
bsalomon@google.com116ad842013-04-09 15:38:19 +0000880 if (clippedDstPoint->fX < 0) {
881 clippedSrcRect->fLeft -= clippedDstPoint->fX;
882 clippedDstPoint->fX = 0;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000883 }
884
bsalomon@google.com116ad842013-04-09 15:38:19 +0000885 // clip the top edge to src and dst bounds, adjusting dstPoint if necessary
886 if (clippedSrcRect->fTop < 0) {
887 clippedDstPoint->fY -= clippedSrcRect->fTop;
888 clippedSrcRect->fTop = 0;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000889 }
bsalomon@google.com116ad842013-04-09 15:38:19 +0000890 if (clippedDstPoint->fY < 0) {
891 clippedSrcRect->fTop -= clippedDstPoint->fY;
892 clippedDstPoint->fY = 0;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000893 }
skia.committer@gmail.coma9493a32013-04-04 07:01:12 +0000894
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000895 // clip the right edge to the src and dst bounds.
bsalomon@google.com116ad842013-04-09 15:38:19 +0000896 if (clippedSrcRect->fRight > src->width()) {
897 clippedSrcRect->fRight = src->width();
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000898 }
bsalomon@google.com116ad842013-04-09 15:38:19 +0000899 if (clippedDstPoint->fX + clippedSrcRect->width() > dst->width()) {
900 clippedSrcRect->fRight = clippedSrcRect->fLeft + dst->width() - clippedDstPoint->fX;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000901 }
902
903 // clip the bottom edge to the src and dst bounds.
bsalomon@google.com116ad842013-04-09 15:38:19 +0000904 if (clippedSrcRect->fBottom > src->height()) {
905 clippedSrcRect->fBottom = src->height();
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000906 }
bsalomon@google.com116ad842013-04-09 15:38:19 +0000907 if (clippedDstPoint->fY + clippedSrcRect->height() > dst->height()) {
908 clippedSrcRect->fBottom = clippedSrcRect->fTop + dst->height() - clippedDstPoint->fY;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000909 }
skia.committer@gmail.coma9493a32013-04-04 07:01:12 +0000910
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000911 // The above clipping steps may have inverted the rect if it didn't intersect either the src or
912 // dst bounds.
bsalomon@google.com116ad842013-04-09 15:38:19 +0000913 return !clippedSrcRect->isEmpty();
914}
915}
916
917bool GrDrawTarget::copySurface(GrSurface* dst,
918 GrSurface* src,
919 const SkIRect& srcRect,
920 const SkIPoint& dstPoint) {
bsalomon49f085d2014-09-05 13:34:00 -0700921 SkASSERT(dst);
922 SkASSERT(src);
bsalomon@google.com116ad842013-04-09 15:38:19 +0000923
924 SkIRect clippedSrcRect;
925 SkIPoint clippedDstPoint;
926 // If the rect is outside the src or dst then we've already succeeded.
927 if (!clip_srcrect_and_dstpoint(dst,
928 src,
929 srcRect,
930 dstPoint,
931 &clippedSrcRect,
932 &clippedDstPoint)) {
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000933 return true;
934 }
935
bsalomonf90a02b2014-11-26 12:28:00 -0800936 if (this->onCopySurface(dst, src, clippedSrcRect, clippedDstPoint)) {
937 return true;
joshualitta7024152014-11-03 14:16:35 -0800938 }
939
940 GrRenderTarget* rt = dst->asRenderTarget();
941 GrTexture* tex = src->asTexture();
942
bsalomonf90a02b2014-11-26 12:28:00 -0800943 if ((dst == src) || !rt || !tex) {
944 return false;
945 }
946
egdaniel8dd688b2015-01-22 10:16:09 -0800947 GrPipelineBuilder pipelineBuilder;
948 pipelineBuilder.setRenderTarget(rt);
joshualitta7024152014-11-03 14:16:35 -0800949 SkMatrix matrix;
950 matrix.setTranslate(SkIntToScalar(clippedSrcRect.fLeft - clippedDstPoint.fX),
951 SkIntToScalar(clippedSrcRect.fTop - clippedDstPoint.fY));
952 matrix.postIDiv(tex->width(), tex->height());
egdaniel8dd688b2015-01-22 10:16:09 -0800953 pipelineBuilder.addColorTextureProcessor(tex, matrix);
joshualitta7024152014-11-03 14:16:35 -0800954 SkIRect dstRect = SkIRect::MakeXYWH(clippedDstPoint.fX,
955 clippedDstPoint.fY,
956 clippedSrcRect.width(),
957 clippedSrcRect.height());
egdaniel8dd688b2015-01-22 10:16:09 -0800958 this->drawSimpleRect(&pipelineBuilder, GrColor_WHITE, SkMatrix::I(), dstRect);
joshualitta7024152014-11-03 14:16:35 -0800959 return true;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000960}
961
joshualitt9853cce2014-11-17 14:22:48 -0800962bool GrDrawTarget::canCopySurface(const GrSurface* dst,
963 const GrSurface* src,
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000964 const SkIRect& srcRect,
965 const SkIPoint& dstPoint) {
bsalomon49f085d2014-09-05 13:34:00 -0700966 SkASSERT(dst);
967 SkASSERT(src);
bsalomon@google.com116ad842013-04-09 15:38:19 +0000968
969 SkIRect clippedSrcRect;
970 SkIPoint clippedDstPoint;
971 // If the rect is outside the src or dst then we're guaranteed success
972 if (!clip_srcrect_and_dstpoint(dst,
973 src,
974 srcRect,
975 dstPoint,
976 &clippedSrcRect,
977 &clippedDstPoint)) {
978 return true;
979 }
bsalomonf90a02b2014-11-26 12:28:00 -0800980 return this->internalCanCopySurface(dst, src, clippedSrcRect, clippedDstPoint);
981}
bsalomon@google.com116ad842013-04-09 15:38:19 +0000982
bsalomonf90a02b2014-11-26 12:28:00 -0800983bool GrDrawTarget::internalCanCopySurface(const GrSurface* dst,
984 const GrSurface* src,
985 const SkIRect& clippedSrcRect,
986 const SkIPoint& clippedDstPoint) {
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000987 // Check that the read/write rects are contained within the src/dst bounds.
joshualitta7024152014-11-03 14:16:35 -0800988 SkASSERT(!clippedSrcRect.isEmpty());
989 SkASSERT(SkIRect::MakeWH(src->width(), src->height()).contains(clippedSrcRect));
990 SkASSERT(clippedDstPoint.fX >= 0 && clippedDstPoint.fY >= 0);
991 SkASSERT(clippedDstPoint.fX + clippedSrcRect.width() <= dst->width() &&
992 clippedDstPoint.fY + clippedSrcRect.height() <= dst->height());
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000993
bsalomonf90a02b2014-11-26 12:28:00 -0800994 // The base class can do it as a draw or the subclass may be able to handle it.
995 return ((dst != src) && dst->asRenderTarget() && src->asTexture()) ||
996 this->onCanCopySurface(dst, src, clippedSrcRect, clippedDstPoint);
bsalomon@google.comeb851172013-04-15 13:51:00 +0000997}
998
bsalomon@google.combcce8922013-03-25 15:38:39 +0000999///////////////////////////////////////////////////////////////////////////////
1000
bsalomon@google.comc26d94f2013-03-25 18:19:00 +00001001void GrDrawTargetCaps::reset() {
commit-bot@chromium.org47442312013-12-19 16:18:01 +00001002 fMipMapSupport = false;
bsalomon@google.combcce8922013-03-25 15:38:39 +00001003 fNPOTTextureTileSupport = false;
1004 fTwoSidedStencilSupport = false;
1005 fStencilWrapOpsSupport = false;
1006 fHWAALineSupport = false;
1007 fShaderDerivativeSupport = false;
1008 fGeometryShaderSupport = false;
skia.committer@gmail.come60ed082013-03-26 07:01:04 +00001009 fDualSourceBlendingSupport = false;
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +00001010 fPathRenderingSupport = false;
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +00001011 fDstReadInShaderSupport = false;
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +00001012 fDiscardRenderTargetSupport = false;
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +00001013 fReuseScratchTextures = true;
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +00001014 fGpuTracingSupport = false;
krajcevski786978162014-07-30 11:25:44 -07001015 fCompressedTexSubImageSupport = false;
bsalomon@google.combcce8922013-03-25 15:38:39 +00001016
bsalomon63b21962014-11-05 07:05:34 -08001017 fUseDrawInsteadOfClear = false;
1018
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001019 fMapBufferFlags = kNone_MapFlags;
1020
bsalomon@google.combcce8922013-03-25 15:38:39 +00001021 fMaxRenderTargetSize = 0;
1022 fMaxTextureSize = 0;
1023 fMaxSampleCount = 0;
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001024
bsalomon17168df2014-12-09 09:00:49 -08001025 fShaderPrecisionVaries = false;
1026
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001027 memset(fConfigRenderSupport, 0, sizeof(fConfigRenderSupport));
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001028 memset(fConfigTextureSupport, 0, sizeof(fConfigTextureSupport));
bsalomon@google.combcce8922013-03-25 15:38:39 +00001029}
1030
bsalomon@google.comc26d94f2013-03-25 18:19:00 +00001031GrDrawTargetCaps& GrDrawTargetCaps::operator=(const GrDrawTargetCaps& other) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +00001032 fMipMapSupport = other.fMipMapSupport;
bsalomon@google.combcce8922013-03-25 15:38:39 +00001033 fNPOTTextureTileSupport = other.fNPOTTextureTileSupport;
1034 fTwoSidedStencilSupport = other.fTwoSidedStencilSupport;
1035 fStencilWrapOpsSupport = other.fStencilWrapOpsSupport;
1036 fHWAALineSupport = other.fHWAALineSupport;
1037 fShaderDerivativeSupport = other.fShaderDerivativeSupport;
1038 fGeometryShaderSupport = other.fGeometryShaderSupport;
1039 fDualSourceBlendingSupport = other.fDualSourceBlendingSupport;
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +00001040 fPathRenderingSupport = other.fPathRenderingSupport;
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +00001041 fDstReadInShaderSupport = other.fDstReadInShaderSupport;
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +00001042 fDiscardRenderTargetSupport = other.fDiscardRenderTargetSupport;
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +00001043 fReuseScratchTextures = other.fReuseScratchTextures;
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +00001044 fGpuTracingSupport = other.fGpuTracingSupport;
krajcevski786978162014-07-30 11:25:44 -07001045 fCompressedTexSubImageSupport = other.fCompressedTexSubImageSupport;
bsalomon@google.combcce8922013-03-25 15:38:39 +00001046
bsalomon63b21962014-11-05 07:05:34 -08001047 fUseDrawInsteadOfClear = other.fUseDrawInsteadOfClear;
1048
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001049 fMapBufferFlags = other.fMapBufferFlags;
1050
bsalomon@google.combcce8922013-03-25 15:38:39 +00001051 fMaxRenderTargetSize = other.fMaxRenderTargetSize;
1052 fMaxTextureSize = other.fMaxTextureSize;
1053 fMaxSampleCount = other.fMaxSampleCount;
1054
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001055 memcpy(fConfigRenderSupport, other.fConfigRenderSupport, sizeof(fConfigRenderSupport));
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001056 memcpy(fConfigTextureSupport, other.fConfigTextureSupport, sizeof(fConfigTextureSupport));
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001057
bsalomon17168df2014-12-09 09:00:49 -08001058 fShaderPrecisionVaries = other.fShaderPrecisionVaries;
1059 for (int s = 0; s < kGrShaderTypeCount; ++s) {
bsalomonc0bd6482014-12-09 10:04:14 -08001060 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
bsalomon17168df2014-12-09 09:00:49 -08001061 fFloatPrecisions[s][p] = other.fFloatPrecisions[s][p];
1062 }
1063 }
bsalomon@google.combcce8922013-03-25 15:38:39 +00001064 return *this;
1065}
1066
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001067static SkString map_flags_to_string(uint32_t flags) {
1068 SkString str;
1069 if (GrDrawTargetCaps::kNone_MapFlags == flags) {
1070 str = "none";
1071 } else {
1072 SkASSERT(GrDrawTargetCaps::kCanMap_MapFlag & flags);
1073 SkDEBUGCODE(flags &= ~GrDrawTargetCaps::kCanMap_MapFlag);
1074 str = "can_map";
1075
1076 if (GrDrawTargetCaps::kSubset_MapFlag & flags) {
1077 str.append(" partial");
1078 } else {
1079 str.append(" full");
1080 }
1081 SkDEBUGCODE(flags &= ~GrDrawTargetCaps::kSubset_MapFlag);
1082 }
1083 SkASSERT(0 == flags); // Make sure we handled all the flags.
1084 return str;
1085}
1086
bsalomon17168df2014-12-09 09:00:49 -08001087static const char* shader_type_to_string(GrShaderType type) {
1088 switch (type) {
1089 case kVertex_GrShaderType:
1090 return "vertex";
1091 case kGeometry_GrShaderType:
1092 return "geometry";
1093 case kFragment_GrShaderType:
1094 return "fragment";
1095 }
1096 return "";
1097}
1098
bsalomonc0bd6482014-12-09 10:04:14 -08001099static const char* precision_to_string(GrSLPrecision p) {
bsalomon17168df2014-12-09 09:00:49 -08001100 switch (p) {
bsalomonc0bd6482014-12-09 10:04:14 -08001101 case kLow_GrSLPrecision:
bsalomon17168df2014-12-09 09:00:49 -08001102 return "low";
bsalomonc0bd6482014-12-09 10:04:14 -08001103 case kMedium_GrSLPrecision:
bsalomon17168df2014-12-09 09:00:49 -08001104 return "medium";
bsalomonc0bd6482014-12-09 10:04:14 -08001105 case kHigh_GrSLPrecision:
bsalomon17168df2014-12-09 09:00:49 -08001106 return "high";
1107 }
1108 return "";
1109}
1110
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001111SkString GrDrawTargetCaps::dump() const {
1112 SkString r;
bsalomon@google.com18c9c192011-09-22 21:01:31 +00001113 static const char* gNY[] = {"NO", "YES"};
bsalomon63b21962014-11-05 07:05:34 -08001114 r.appendf("MIP Map Support : %s\n", gNY[fMipMapSupport]);
1115 r.appendf("NPOT Texture Tile Support : %s\n", gNY[fNPOTTextureTileSupport]);
1116 r.appendf("Two Sided Stencil Support : %s\n", gNY[fTwoSidedStencilSupport]);
1117 r.appendf("Stencil Wrap Ops Support : %s\n", gNY[fStencilWrapOpsSupport]);
1118 r.appendf("HW AA Lines Support : %s\n", gNY[fHWAALineSupport]);
1119 r.appendf("Shader Derivative Support : %s\n", gNY[fShaderDerivativeSupport]);
1120 r.appendf("Geometry Shader Support : %s\n", gNY[fGeometryShaderSupport]);
1121 r.appendf("Dual Source Blending Support : %s\n", gNY[fDualSourceBlendingSupport]);
1122 r.appendf("Path Rendering Support : %s\n", gNY[fPathRenderingSupport]);
1123 r.appendf("Dst Read In Shader Support : %s\n", gNY[fDstReadInShaderSupport]);
1124 r.appendf("Discard Render Target Support : %s\n", gNY[fDiscardRenderTargetSupport]);
1125 r.appendf("Reuse Scratch Textures : %s\n", gNY[fReuseScratchTextures]);
1126 r.appendf("Gpu Tracing Support : %s\n", gNY[fGpuTracingSupport]);
1127 r.appendf("Compressed Update Support : %s\n", gNY[fCompressedTexSubImageSupport]);
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001128
bsalomon63b21962014-11-05 07:05:34 -08001129 r.appendf("Draw Instead of Clear [workaround] : %s\n", gNY[fUseDrawInsteadOfClear]);
1130
1131 r.appendf("Max Texture Size : %d\n", fMaxTextureSize);
1132 r.appendf("Max Render Target Size : %d\n", fMaxRenderTargetSize);
1133 r.appendf("Max Sample Count : %d\n", fMaxSampleCount);
1134
1135 r.appendf("Map Buffer Support : %s\n",
1136 map_flags_to_string(fMapBufferFlags).c_str());
commit-bot@chromium.org160b4782014-05-05 12:32:37 +00001137
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001138 static const char* kConfigNames[] = {
1139 "Unknown", // kUnknown_GrPixelConfig
1140 "Alpha8", // kAlpha_8_GrPixelConfig,
1141 "Index8", // kIndex_8_GrPixelConfig,
1142 "RGB565", // kRGB_565_GrPixelConfig,
1143 "RGBA444", // kRGBA_4444_GrPixelConfig,
1144 "RGBA8888", // kRGBA_8888_GrPixelConfig,
1145 "BGRA8888", // kBGRA_8888_GrPixelConfig,
jvanverthfa1e8a72014-12-22 08:31:49 -08001146 "SRGBA8888",// kSRGBA_8888_GrPixelConfig,
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001147 "ETC1", // kETC1_GrPixelConfig,
1148 "LATC", // kLATC_GrPixelConfig,
krajcevski238b4562014-06-30 09:09:22 -07001149 "R11EAC", // kR11_EAC_GrPixelConfig,
krajcevski7ef21622014-07-16 15:21:13 -07001150 "ASTC12x12",// kASTC_12x12_GrPixelConfig,
jvanverth28f9c602014-12-05 13:06:35 -08001151 "RGBAFloat",// kRGBA_float_GrPixelConfig
1152 "AlphaHalf",// kAlpha_half_GrPixelConfig
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001153 };
krajcevski7ef21622014-07-16 15:21:13 -07001154 GR_STATIC_ASSERT(0 == kUnknown_GrPixelConfig);
1155 GR_STATIC_ASSERT(1 == kAlpha_8_GrPixelConfig);
1156 GR_STATIC_ASSERT(2 == kIndex_8_GrPixelConfig);
1157 GR_STATIC_ASSERT(3 == kRGB_565_GrPixelConfig);
1158 GR_STATIC_ASSERT(4 == kRGBA_4444_GrPixelConfig);
1159 GR_STATIC_ASSERT(5 == kRGBA_8888_GrPixelConfig);
1160 GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig);
jvanverthfa1e8a72014-12-22 08:31:49 -08001161 GR_STATIC_ASSERT(7 == kSRGBA_8888_GrPixelConfig);
1162 GR_STATIC_ASSERT(8 == kETC1_GrPixelConfig);
1163 GR_STATIC_ASSERT(9 == kLATC_GrPixelConfig);
1164 GR_STATIC_ASSERT(10 == kR11_EAC_GrPixelConfig);
1165 GR_STATIC_ASSERT(11 == kASTC_12x12_GrPixelConfig);
1166 GR_STATIC_ASSERT(12 == kRGBA_float_GrPixelConfig);
1167 GR_STATIC_ASSERT(13 == kAlpha_half_GrPixelConfig);
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001168 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kConfigNames) == kGrPixelConfigCnt);
1169
commit-bot@chromium.org99017272013-11-08 18:45:27 +00001170 SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][0]);
1171 SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][1]);
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001172
1173 for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) {
1174 r.appendf("%s is renderable: %s, with MSAA: %s\n",
1175 kConfigNames[i],
1176 gNY[fConfigRenderSupport[i][0]],
1177 gNY[fConfigRenderSupport[i][1]]);
commit-bot@chromium.org73880512013-10-14 15:33:45 +00001178 }
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +00001179
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001180 SkASSERT(!fConfigTextureSupport[kUnknown_GrPixelConfig]);
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +00001181
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +00001182 for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) {
1183 r.appendf("%s is uploadable to a texture: %s\n",
1184 kConfigNames[i],
1185 gNY[fConfigTextureSupport[i]]);
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +00001186 }
1187
bsalomon17168df2014-12-09 09:00:49 -08001188 r.appendf("Shader Float Precisions (varies: %s):\n", gNY[fShaderPrecisionVaries]);
1189
1190 for (int s = 0; s < kGrShaderTypeCount; ++s) {
1191 GrShaderType shaderType = static_cast<GrShaderType>(s);
1192 r.appendf("\t%s:\n", shader_type_to_string(shaderType));
bsalomonc0bd6482014-12-09 10:04:14 -08001193 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
bsalomon17168df2014-12-09 09:00:49 -08001194 if (fFloatPrecisions[s][p].supported()) {
bsalomonc0bd6482014-12-09 10:04:14 -08001195 GrSLPrecision precision = static_cast<GrSLPrecision>(p);
bsalomon17168df2014-12-09 09:00:49 -08001196 r.appendf("\t\t%s: log_low: %d log_high: %d bits: %d\n",
1197 precision_to_string(precision),
1198 fFloatPrecisions[s][p].fLogRangeLow,
1199 fFloatPrecisions[s][p].fLogRangeHigh,
1200 fFloatPrecisions[s][p].fBits);
1201 }
1202 }
1203 }
1204
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +00001205 return r;
bsalomon@google.com18c9c192011-09-22 21:01:31 +00001206}
egdanielbc127a32014-09-19 12:07:43 -07001207
1208uint32_t GrDrawTargetCaps::CreateUniqueID() {
1209 static int32_t gUniqueID = SK_InvalidUniqueID;
1210 uint32_t id;
1211 do {
1212 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1);
1213 } while (id == SK_InvalidUniqueID);
1214 return id;
1215}
1216
joshualitt2c93efe2014-11-06 12:57:13 -08001217///////////////////////////////////////////////////////////////////////////////////////////////////
1218
egdaniel8dd688b2015-01-22 10:16:09 -08001219bool GrClipTarget::setupClip(GrPipelineBuilder* pipelineBuilder,
1220 GrPipelineBuilder::AutoRestoreEffects* are,
1221 GrPipelineBuilder::AutoRestoreStencil* ars,
joshualitt8059eb92014-12-29 15:10:07 -08001222 GrScissorState* scissorState,
1223 const SkRect* devBounds) {
egdaniel8dd688b2015-01-22 10:16:09 -08001224 return fClipMaskManager.setupClipping(pipelineBuilder,
joshualitt2c93efe2014-11-06 12:57:13 -08001225 are,
1226 ars,
joshualitt9853cce2014-11-17 14:22:48 -08001227 scissorState,
1228 this->getClip(),
1229 devBounds);
joshualitt2c93efe2014-11-06 12:57:13 -08001230}