blob: 1521a9bee545037a3fda4efeeb700aa922cc9b27 [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"
bsalomona73239a2015-04-28 13:35:17 -070012#include "GrBufferAllocPool.h"
bsalomon@google.com26e18b52013-03-29 19:22:36 +000013#include "GrContext.h"
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000014#include "GrDrawTargetCaps.h"
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +000015#include "GrPath.h"
egdaniele36914c2015-02-13 09:00:33 -080016#include "GrPipeline.h"
joshualittb7133be2015-04-08 09:08:31 -070017#include "GrMemoryPool.h"
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000018#include "GrRenderTarget.h"
bsalomon6bc1b5f2015-02-23 09:06:38 -080019#include "GrRenderTargetPriv.h"
bsalomonafbf2d62014-09-30 12:18:44 -070020#include "GrSurfacePriv.h"
bsalomon62c447d2014-08-08 08:08:50 -070021#include "GrTemplates.h"
bsalomon@google.com86afc2a2011-02-16 16:12:19 +000022#include "GrTexture.h"
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000023#include "GrVertexBuffer.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000024
sugoi@google.com5f74cf82012-12-17 21:16:45 +000025#include "SkStrokeRec.h"
sugoi@google.com12b4e272012-12-06 20:13:11 +000026
reed@google.comac10a2d2010-12-22 21:39:39 +000027////////////////////////////////////////////////////////////////////////////////
28
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000029GrDrawTarget::DrawInfo& GrDrawTarget::DrawInfo::operator =(const DrawInfo& di) {
30 fPrimitiveType = di.fPrimitiveType;
31 fStartVertex = di.fStartVertex;
32 fStartIndex = di.fStartIndex;
33 fVertexCount = di.fVertexCount;
34 fIndexCount = di.fIndexCount;
35
36 fInstanceCount = di.fInstanceCount;
37 fVerticesPerInstance = di.fVerticesPerInstance;
38 fIndicesPerInstance = di.fIndicesPerInstance;
39
bsalomon49f085d2014-09-05 13:34:00 -070040 if (di.fDevBounds) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000041 SkASSERT(di.fDevBounds == &di.fDevBoundsStorage);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000042 fDevBoundsStorage = di.fDevBoundsStorage;
43 fDevBounds = &fDevBoundsStorage;
44 } else {
45 fDevBounds = NULL;
46 }
bsalomon@google.com26e18b52013-03-29 19:22:36 +000047
joshualitt7eb8c7b2014-11-18 14:24:27 -080048 this->setVertexBuffer(di.vertexBuffer());
49 this->setIndexBuffer(di.indexBuffer());
50
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000051 return *this;
52}
53
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000054////////////////////////////////////////////////////////////////////////////////
55
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000056#define DEBUG_INVAL_BUFFER 0xdeadcafe
57#define DEBUG_INVAL_START_IDX -1
58
bsalomona73239a2015-04-28 13:35:17 -070059GrDrawTarget::GrDrawTarget(GrContext* context,
60 GrVertexBufferAllocPool* vpool,
61 GrIndexBufferAllocPool* ipool)
joshualitt44701df2015-02-23 14:44:57 -080062 : fContext(context)
bsalomona73239a2015-04-28 13:35:17 -070063 , fCaps(SkRef(context->getGpu()->caps()))
64 , fGpuTraceMarkerCount(0)
65 , fVertexPool(vpool)
66 , fIndexPool(ipool)
67 , fFlushing(false) {
bsalomon49f085d2014-09-05 13:34:00 -070068 SkASSERT(context);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000069}
70
71////////////////////////////////////////////////////////////////////////////////
72
bsalomon50785a32015-02-06 07:02:37 -080073bool GrDrawTarget::setupDstReadIfNecessary(const GrPipelineBuilder& pipelineBuilder,
egdaniele36914c2015-02-13 09:00:33 -080074 const GrProcOptInfo& colorPOI,
75 const GrProcOptInfo& coveragePOI,
joshualitt9853cce2014-11-17 14:22:48 -080076 GrDeviceCoordTexture* dstCopy,
77 const SkRect* drawBounds) {
egdaniele36914c2015-02-13 09:00:33 -080078 if (!pipelineBuilder.willXPNeedDstCopy(*this->caps(), colorPOI, coveragePOI)) {
bsalomon@google.com26e18b52013-03-29 19:22:36 +000079 return true;
80 }
cdalton9954bc32015-04-29 14:17:00 -070081
bsalomon50785a32015-02-06 07:02:37 -080082 GrRenderTarget* rt = pipelineBuilder.getRenderTarget();
cdalton9954bc32015-04-29 14:17:00 -070083
84 if (this->caps()->textureBarrierSupport()) {
85 if (GrTexture* rtTex = rt->asTexture()) {
86 // The render target is a texture, se we can read from it directly in the shader. The XP
87 // will be responsible to detect this situation and request a texture barrier.
88 dstCopy->setTexture(rtTex);
89 dstCopy->setOffset(0, 0);
90 return true;
91 }
92 }
93
94 SkIRect copyRect;
joshualitt44701df2015-02-23 14:44:57 -080095 pipelineBuilder.clip().getConservativeBounds(rt, &copyRect);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +000096
bsalomon49f085d2014-09-05 13:34:00 -070097 if (drawBounds) {
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +000098 SkIRect drawIBounds;
99 drawBounds->roundOut(&drawIBounds);
commit-bot@chromium.orgbb5c4652013-04-01 12:49:31 +0000100 if (!copyRect.intersect(drawIBounds)) {
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000101#ifdef SK_DEBUG
tfarina38406c82014-10-31 07:11:12 -0700102 SkDebugf("Missed an early reject. Bailing on draw from setupDstReadIfNecessary.\n");
commit-bot@chromium.orgbb5c4652013-04-01 12:49:31 +0000103#endif
104 return false;
105 }
106 } else {
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000107#ifdef SK_DEBUG
tfarina38406c82014-10-31 07:11:12 -0700108 //SkDebugf("No dev bounds when dst copy is made.\n");
commit-bot@chromium.orgbb5c4652013-04-01 12:49:31 +0000109#endif
110 }
skia.committer@gmail.com05a2ee02013-04-02 07:01:34 +0000111
commit-bot@chromium.org63150af2013-04-11 22:00:22 +0000112 // MSAA consideration: When there is support for reading MSAA samples in the shader we could
113 // have per-sample dst values by making the copy multisampled.
bsalomonf2703d82014-10-28 14:33:06 -0700114 GrSurfaceDesc desc;
bsalomona73239a2015-04-28 13:35:17 -0700115 if (!this->getGpu()->initCopySurfaceDstDesc(rt, &desc)) {
116 desc.fOrigin = kDefault_GrSurfaceOrigin;
117 desc.fFlags = kRenderTarget_GrSurfaceFlag;
118 desc.fConfig = rt->config();
119 }
120
121
commit-bot@chromium.orgbb5c4652013-04-01 12:49:31 +0000122 desc.fWidth = copyRect.width();
123 desc.fHeight = copyRect.height();
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000124
bsalomond309e7a2015-04-30 14:18:54 -0700125 SkAutoTUnref<GrTexture> copy(fContext->textureProvider()->refScratchTexture(desc,
126 GrTextureProvider::kApprox_ScratchTexMatch));
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000127
bsalomone3059732014-10-14 11:47:22 -0700128 if (!copy) {
tfarina38406c82014-10-31 07:11:12 -0700129 SkDebugf("Failed to create temporary copy of destination texture.\n");
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000130 return false;
131 }
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000132 SkIPoint dstPoint = {0, 0};
bsalomone3059732014-10-14 11:47:22 -0700133 if (this->copySurface(copy, rt, copyRect, dstPoint)) {
134 dstCopy->setTexture(copy);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000135 dstCopy->setOffset(copyRect.fLeft, copyRect.fTop);
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000136 return true;
137 } else {
138 return false;
139 }
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000140}
141
bsalomona73239a2015-04-28 13:35:17 -0700142void GrDrawTarget::reset() {
143 fVertexPool->reset();
144 fIndexPool->reset();
145
146 this->onReset();
147}
148
149void GrDrawTarget::flush() {
150 if (fFlushing) {
151 return;
152 }
153 fFlushing = true;
154
155 this->getGpu()->saveActiveTraceMarkers();
156
157 this->onFlush();
158
159 this->getGpu()->restoreActiveTraceMarkers();
160
161 fFlushing = false;
162 this->reset();
163}
164
joshualitt4d8da812015-01-28 12:53:54 -0800165void GrDrawTarget::drawBatch(GrPipelineBuilder* pipelineBuilder,
166 GrBatch* batch,
167 const SkRect* devBounds) {
168 SkASSERT(pipelineBuilder);
169 // TODO some kind of checkdraw, but not at this level
170
171 // Setup clip
172 GrScissorState scissorState;
bsalomon6be6f7c2015-02-26 13:05:21 -0800173 GrPipelineBuilder::AutoRestoreFragmentProcessors arfp;
joshualitt4d8da812015-01-28 12:53:54 -0800174 GrPipelineBuilder::AutoRestoreStencil ars;
bsalomon6be6f7c2015-02-26 13:05:21 -0800175 if (!this->setupClip(pipelineBuilder, &arfp, &ars, &scissorState, devBounds)) {
joshualitt4d8da812015-01-28 12:53:54 -0800176 return;
177 }
178
egdaniele36914c2015-02-13 09:00:33 -0800179 GrDrawTarget::PipelineInfo pipelineInfo(pipelineBuilder, &scissorState, batch, devBounds, this);
180 if (pipelineInfo.mustSkipDraw()) {
181 return;
182 }
183
184 this->onDrawBatch(batch, pipelineInfo);
joshualitt4d8da812015-01-28 12:53:54 -0800185}
186
joshualitt2c93efe2014-11-06 12:57:13 -0800187static const GrStencilSettings& winding_path_stencil_settings() {
188 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings,
189 kIncClamp_StencilOp,
190 kIncClamp_StencilOp,
191 kAlwaysIfInClip_StencilFunc,
192 0xFFFF, 0xFFFF, 0xFFFF);
193 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings);
194}
195
196static const GrStencilSettings& even_odd_path_stencil_settings() {
197 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings,
198 kInvert_StencilOp,
199 kInvert_StencilOp,
200 kAlwaysIfInClip_StencilFunc,
201 0xFFFF, 0xFFFF, 0xFFFF);
202 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings);
203}
204
205void GrDrawTarget::getPathStencilSettingsForFilltype(GrPathRendering::FillType fill,
egdaniel8dc7c3a2015-04-16 11:22:42 -0700206 const GrStencilAttachment* sb,
joshualitt2c93efe2014-11-06 12:57:13 -0800207 GrStencilSettings* outStencilSettings) {
208
209 switch (fill) {
210 default:
211 SkFAIL("Unexpected path fill.");
212 case GrPathRendering::kWinding_FillType:
213 *outStencilSettings = winding_path_stencil_settings();
214 break;
215 case GrPathRendering::kEvenOdd_FillType:
216 *outStencilSettings = even_odd_path_stencil_settings();
217 break;
218 }
joshualitt9853cce2014-11-17 14:22:48 -0800219 this->clipMaskManager()->adjustPathStencilParams(sb, outStencilSettings);
joshualitt2c93efe2014-11-06 12:57:13 -0800220}
221
egdaniel8dd688b2015-01-22 10:16:09 -0800222void GrDrawTarget::stencilPath(GrPipelineBuilder* pipelineBuilder,
joshualitt56995b52014-12-11 15:44:02 -0800223 const GrPathProcessor* pathProc,
joshualitt9853cce2014-11-17 14:22:48 -0800224 const GrPath* path,
225 GrPathRendering::FillType fill) {
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000226 // TODO: extract portions of checkDraw that are relevant to path stenciling.
bsalomon49f085d2014-09-05 13:34:00 -0700227 SkASSERT(path);
jvanverthe9c0fc62015-04-29 11:18:05 -0700228 SkASSERT(this->caps()->shaderCaps()->pathRenderingSupport());
egdaniel8dd688b2015-01-22 10:16:09 -0800229 SkASSERT(pipelineBuilder);
joshualitt2c93efe2014-11-06 12:57:13 -0800230
231 // Setup clip
bsalomon3e791242014-12-17 13:43:13 -0800232 GrScissorState scissorState;
bsalomon6be6f7c2015-02-26 13:05:21 -0800233 GrPipelineBuilder::AutoRestoreFragmentProcessors arfp;
egdaniel8dd688b2015-01-22 10:16:09 -0800234 GrPipelineBuilder::AutoRestoreStencil ars;
bsalomon6be6f7c2015-02-26 13:05:21 -0800235 if (!this->setupClip(pipelineBuilder, &arfp, &ars, &scissorState, NULL)) {
joshualitt2c93efe2014-11-06 12:57:13 -0800236 return;
237 }
238
239 // set stencil settings for path
240 GrStencilSettings stencilSettings;
bsalomon6bc1b5f2015-02-23 09:06:38 -0800241 GrRenderTarget* rt = pipelineBuilder->getRenderTarget();
egdaniel8dc7c3a2015-04-16 11:22:42 -0700242 GrStencilAttachment* sb = rt->renderTargetPriv().attachStencilAttachment();
bsalomon6bc1b5f2015-02-23 09:06:38 -0800243 this->getPathStencilSettingsForFilltype(fill, sb, &stencilSettings);
joshualitt2c93efe2014-11-06 12:57:13 -0800244
egdaniel8dd688b2015-01-22 10:16:09 -0800245 this->onStencilPath(*pipelineBuilder, pathProc, path, scissorState, stencilSettings);
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000246}
247
egdaniel8dd688b2015-01-22 10:16:09 -0800248void GrDrawTarget::drawPath(GrPipelineBuilder* pipelineBuilder,
joshualitt56995b52014-12-11 15:44:02 -0800249 const GrPathProcessor* pathProc,
joshualitt9853cce2014-11-17 14:22:48 -0800250 const GrPath* path,
251 GrPathRendering::FillType fill) {
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000252 // TODO: extract portions of checkDraw that are relevant to path rendering.
bsalomon49f085d2014-09-05 13:34:00 -0700253 SkASSERT(path);
jvanverthe9c0fc62015-04-29 11:18:05 -0700254 SkASSERT(this->caps()->shaderCaps()->pathRenderingSupport());
egdaniel8dd688b2015-01-22 10:16:09 -0800255 SkASSERT(pipelineBuilder);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000256
joshualitt92e496f2014-10-31 13:56:50 -0700257 SkRect devBounds = path->getBounds();
joshualitt8059eb92014-12-29 15:10:07 -0800258 pathProc->viewMatrix().mapRect(&devBounds);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000259
joshualitt2c93efe2014-11-06 12:57:13 -0800260 // Setup clip
bsalomon3e791242014-12-17 13:43:13 -0800261 GrScissorState scissorState;
bsalomon6be6f7c2015-02-26 13:05:21 -0800262 GrPipelineBuilder::AutoRestoreFragmentProcessors arfp;
egdaniel8dd688b2015-01-22 10:16:09 -0800263 GrPipelineBuilder::AutoRestoreStencil ars;
bsalomon6be6f7c2015-02-26 13:05:21 -0800264 if (!this->setupClip(pipelineBuilder, &arfp, &ars, &scissorState, &devBounds)) {
joshualitt2c93efe2014-11-06 12:57:13 -0800265 return;
266 }
267
268 // set stencil settings for path
269 GrStencilSettings stencilSettings;
bsalomon6bc1b5f2015-02-23 09:06:38 -0800270 GrRenderTarget* rt = pipelineBuilder->getRenderTarget();
egdaniel8dc7c3a2015-04-16 11:22:42 -0700271 GrStencilAttachment* sb = rt->renderTargetPriv().attachStencilAttachment();
bsalomon6bc1b5f2015-02-23 09:06:38 -0800272 this->getPathStencilSettingsForFilltype(fill, sb, &stencilSettings);
joshualitt2c93efe2014-11-06 12:57:13 -0800273
egdaniele36914c2015-02-13 09:00:33 -0800274 GrDrawTarget::PipelineInfo pipelineInfo(pipelineBuilder, &scissorState, pathProc, &devBounds,
275 this);
276 if (pipelineInfo.mustSkipDraw()) {
277 return;
278 }
279
280 this->onDrawPath(pathProc, path, stencilSettings, pipelineInfo);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000281}
282
egdaniel8dd688b2015-01-22 10:16:09 -0800283void GrDrawTarget::drawPaths(GrPipelineBuilder* pipelineBuilder,
joshualitt56995b52014-12-11 15:44:02 -0800284 const GrPathProcessor* pathProc,
joshualitt9853cce2014-11-17 14:22:48 -0800285 const GrPathRange* pathRange,
cdalton55b24af2014-11-25 11:00:56 -0800286 const void* indices,
287 PathIndexType indexType,
288 const float transformValues[],
289 PathTransformType transformType,
joshualitt9853cce2014-11-17 14:22:48 -0800290 int count,
joshualitt92e496f2014-10-31 13:56:50 -0700291 GrPathRendering::FillType fill) {
jvanverthe9c0fc62015-04-29 11:18:05 -0700292 SkASSERT(this->caps()->shaderCaps()->pathRenderingSupport());
bsalomon49f085d2014-09-05 13:34:00 -0700293 SkASSERT(pathRange);
294 SkASSERT(indices);
cdalton55b24af2014-11-25 11:00:56 -0800295 SkASSERT(0 == reinterpret_cast<long>(indices) % GrPathRange::PathIndexSizeInBytes(indexType));
296 SkASSERT(transformValues);
egdaniel8dd688b2015-01-22 10:16:09 -0800297 SkASSERT(pipelineBuilder);
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000298
joshualitt2c93efe2014-11-06 12:57:13 -0800299 // Setup clip
bsalomon3e791242014-12-17 13:43:13 -0800300 GrScissorState scissorState;
bsalomon6be6f7c2015-02-26 13:05:21 -0800301 GrPipelineBuilder::AutoRestoreFragmentProcessors arfp;
egdaniel8dd688b2015-01-22 10:16:09 -0800302 GrPipelineBuilder::AutoRestoreStencil ars;
joshualitt2c93efe2014-11-06 12:57:13 -0800303
bsalomon6be6f7c2015-02-26 13:05:21 -0800304 if (!this->setupClip(pipelineBuilder, &arfp, &ars, &scissorState, NULL)) {
joshualitt2c93efe2014-11-06 12:57:13 -0800305 return;
306 }
307
308 // set stencil settings for path
309 GrStencilSettings stencilSettings;
bsalomon6bc1b5f2015-02-23 09:06:38 -0800310 GrRenderTarget* rt = pipelineBuilder->getRenderTarget();
egdaniel8dc7c3a2015-04-16 11:22:42 -0700311 GrStencilAttachment* sb = rt->renderTargetPriv().attachStencilAttachment();
bsalomon6bc1b5f2015-02-23 09:06:38 -0800312 this->getPathStencilSettingsForFilltype(fill, sb, &stencilSettings);
joshualitt2c93efe2014-11-06 12:57:13 -0800313
bsalomon50785a32015-02-06 07:02:37 -0800314 // Don't compute a bounding box for dst copy texture, we'll opt
cdaltonb85a0aa2014-07-21 15:32:44 -0700315 // instead for it to just copy the entire dst. Realistically this is a moot
316 // point, because any context that supports NV_path_rendering will also
317 // support NV_blend_equation_advanced.
egdaniele36914c2015-02-13 09:00:33 -0800318 GrDrawTarget::PipelineInfo pipelineInfo(pipelineBuilder, &scissorState, pathProc, NULL, this);
319 if (pipelineInfo.mustSkipDraw()) {
320 return;
321 }
322
323 this->onDrawPaths(pathProc, pathRange, indices, indexType, transformValues,
324 transformType, count, stencilSettings, pipelineInfo);
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000325}
326
joshualitt9853cce2014-11-17 14:22:48 -0800327void GrDrawTarget::clear(const SkIRect* rect,
328 GrColor color,
329 bool canIgnoreRect,
bsalomon63b21962014-11-05 07:05:34 -0800330 GrRenderTarget* renderTarget) {
331 if (fCaps->useDrawInsteadOfClear()) {
332 // This works around a driver bug with clear by drawing a rect instead.
333 // The driver will ignore a clear if it is the only thing rendered to a
334 // target before the target is read.
335 SkIRect rtRect = SkIRect::MakeWH(renderTarget->width(), renderTarget->height());
336 if (NULL == rect || canIgnoreRect || rect->contains(rtRect)) {
337 rect = &rtRect;
338 // We first issue a discard() since that may help tilers.
339 this->discard(renderTarget);
340 }
bsalomon63b21962014-11-05 07:05:34 -0800341
egdaniel8dd688b2015-01-22 10:16:09 -0800342 GrPipelineBuilder pipelineBuilder;
343 pipelineBuilder.setRenderTarget(renderTarget);
joshualitt9853cce2014-11-17 14:22:48 -0800344
egdaniel8dd688b2015-01-22 10:16:09 -0800345 this->drawSimpleRect(&pipelineBuilder, color, SkMatrix::I(), *rect);
bsalomon63b21962014-11-05 07:05:34 -0800346 } else {
347 this->onClear(rect, color, canIgnoreRect, renderTarget);
348 }
349}
350
egdaniel3eee3832014-06-18 13:09:11 -0700351typedef GrTraceMarkerSet::Iter TMIter;
352void GrDrawTarget::saveActiveTraceMarkers() {
353 if (this->caps()->gpuTracingSupport()) {
354 SkASSERT(0 == fStoredTraceMarkers.count());
355 fStoredTraceMarkers.addSet(fActiveTraceMarkers);
356 for (TMIter iter = fStoredTraceMarkers.begin(); iter != fStoredTraceMarkers.end(); ++iter) {
357 this->removeGpuTraceMarker(&(*iter));
358 }
359 }
360}
361
362void GrDrawTarget::restoreActiveTraceMarkers() {
363 if (this->caps()->gpuTracingSupport()) {
364 SkASSERT(0 == fActiveTraceMarkers.count());
365 for (TMIter iter = fStoredTraceMarkers.begin(); iter != fStoredTraceMarkers.end(); ++iter) {
366 this->addGpuTraceMarker(&(*iter));
367 }
368 for (TMIter iter = fActiveTraceMarkers.begin(); iter != fActiveTraceMarkers.end(); ++iter) {
369 this->fStoredTraceMarkers.remove(*iter);
370 }
371 }
372}
373
374void GrDrawTarget::addGpuTraceMarker(const GrGpuTraceMarker* marker) {
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000375 if (this->caps()->gpuTracingSupport()) {
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000376 SkASSERT(fGpuTraceMarkerCount >= 0);
377 this->fActiveTraceMarkers.add(*marker);
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000378 ++fGpuTraceMarkerCount;
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000379 }
380}
381
egdaniel3eee3832014-06-18 13:09:11 -0700382void GrDrawTarget::removeGpuTraceMarker(const GrGpuTraceMarker* marker) {
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000383 if (this->caps()->gpuTracingSupport()) {
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000384 SkASSERT(fGpuTraceMarkerCount >= 1);
385 this->fActiveTraceMarkers.remove(*marker);
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000386 --fGpuTraceMarkerCount;
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000387 }
388}
389
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000390////////////////////////////////////////////////////////////////////////////////
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000391
bsalomon@google.com116ad842013-04-09 15:38:19 +0000392namespace {
393// returns true if the read/written rect intersects the src/dst and false if not.
394bool clip_srcrect_and_dstpoint(const GrSurface* dst,
395 const GrSurface* src,
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000396 const SkIRect& srcRect,
bsalomon@google.com116ad842013-04-09 15:38:19 +0000397 const SkIPoint& dstPoint,
398 SkIRect* clippedSrcRect,
399 SkIPoint* clippedDstPoint) {
400 *clippedSrcRect = srcRect;
401 *clippedDstPoint = dstPoint;
skia.committer@gmail.coma9493a32013-04-04 07:01:12 +0000402
bsalomon@google.com116ad842013-04-09 15:38:19 +0000403 // clip the left edge to src and dst bounds, adjusting dstPoint if necessary
404 if (clippedSrcRect->fLeft < 0) {
405 clippedDstPoint->fX -= clippedSrcRect->fLeft;
406 clippedSrcRect->fLeft = 0;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000407 }
bsalomon@google.com116ad842013-04-09 15:38:19 +0000408 if (clippedDstPoint->fX < 0) {
409 clippedSrcRect->fLeft -= clippedDstPoint->fX;
410 clippedDstPoint->fX = 0;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000411 }
412
bsalomon@google.com116ad842013-04-09 15:38:19 +0000413 // clip the top edge to src and dst bounds, adjusting dstPoint if necessary
414 if (clippedSrcRect->fTop < 0) {
415 clippedDstPoint->fY -= clippedSrcRect->fTop;
416 clippedSrcRect->fTop = 0;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000417 }
bsalomon@google.com116ad842013-04-09 15:38:19 +0000418 if (clippedDstPoint->fY < 0) {
419 clippedSrcRect->fTop -= clippedDstPoint->fY;
420 clippedDstPoint->fY = 0;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000421 }
skia.committer@gmail.coma9493a32013-04-04 07:01:12 +0000422
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000423 // clip the right edge to the src and dst bounds.
bsalomon@google.com116ad842013-04-09 15:38:19 +0000424 if (clippedSrcRect->fRight > src->width()) {
425 clippedSrcRect->fRight = src->width();
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000426 }
bsalomon@google.com116ad842013-04-09 15:38:19 +0000427 if (clippedDstPoint->fX + clippedSrcRect->width() > dst->width()) {
428 clippedSrcRect->fRight = clippedSrcRect->fLeft + dst->width() - clippedDstPoint->fX;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000429 }
430
431 // clip the bottom edge to the src and dst bounds.
bsalomon@google.com116ad842013-04-09 15:38:19 +0000432 if (clippedSrcRect->fBottom > src->height()) {
433 clippedSrcRect->fBottom = src->height();
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000434 }
bsalomon@google.com116ad842013-04-09 15:38:19 +0000435 if (clippedDstPoint->fY + clippedSrcRect->height() > dst->height()) {
436 clippedSrcRect->fBottom = clippedSrcRect->fTop + dst->height() - clippedDstPoint->fY;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000437 }
skia.committer@gmail.coma9493a32013-04-04 07:01:12 +0000438
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000439 // The above clipping steps may have inverted the rect if it didn't intersect either the src or
440 // dst bounds.
bsalomon@google.com116ad842013-04-09 15:38:19 +0000441 return !clippedSrcRect->isEmpty();
442}
443}
444
445bool GrDrawTarget::copySurface(GrSurface* dst,
446 GrSurface* src,
447 const SkIRect& srcRect,
448 const SkIPoint& dstPoint) {
bsalomon49f085d2014-09-05 13:34:00 -0700449 SkASSERT(dst);
450 SkASSERT(src);
bsalomon@google.com116ad842013-04-09 15:38:19 +0000451
452 SkIRect clippedSrcRect;
453 SkIPoint clippedDstPoint;
454 // If the rect is outside the src or dst then we've already succeeded.
455 if (!clip_srcrect_and_dstpoint(dst,
456 src,
457 srcRect,
458 dstPoint,
459 &clippedSrcRect,
460 &clippedDstPoint)) {
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000461 return true;
462 }
463
bsalomona73239a2015-04-28 13:35:17 -0700464 if (this->getGpu()->canCopySurface(dst, src, clippedSrcRect, clippedDstPoint)) {
465 this->onCopySurface(dst, src, clippedSrcRect, clippedDstPoint);
bsalomonf90a02b2014-11-26 12:28:00 -0800466 return true;
joshualitta7024152014-11-03 14:16:35 -0800467 }
468
469 GrRenderTarget* rt = dst->asRenderTarget();
470 GrTexture* tex = src->asTexture();
471
bsalomonf90a02b2014-11-26 12:28:00 -0800472 if ((dst == src) || !rt || !tex) {
473 return false;
474 }
475
egdaniel8dd688b2015-01-22 10:16:09 -0800476 GrPipelineBuilder pipelineBuilder;
477 pipelineBuilder.setRenderTarget(rt);
joshualitta7024152014-11-03 14:16:35 -0800478 SkMatrix matrix;
479 matrix.setTranslate(SkIntToScalar(clippedSrcRect.fLeft - clippedDstPoint.fX),
480 SkIntToScalar(clippedSrcRect.fTop - clippedDstPoint.fY));
481 matrix.postIDiv(tex->width(), tex->height());
egdaniel8dd688b2015-01-22 10:16:09 -0800482 pipelineBuilder.addColorTextureProcessor(tex, matrix);
joshualitta7024152014-11-03 14:16:35 -0800483 SkIRect dstRect = SkIRect::MakeXYWH(clippedDstPoint.fX,
484 clippedDstPoint.fY,
485 clippedSrcRect.width(),
486 clippedSrcRect.height());
egdaniel8dd688b2015-01-22 10:16:09 -0800487 this->drawSimpleRect(&pipelineBuilder, GrColor_WHITE, SkMatrix::I(), dstRect);
joshualitta7024152014-11-03 14:16:35 -0800488 return true;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000489}
490
joshualitt9853cce2014-11-17 14:22:48 -0800491bool GrDrawTarget::canCopySurface(const GrSurface* dst,
492 const GrSurface* src,
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000493 const SkIRect& srcRect,
494 const SkIPoint& dstPoint) {
bsalomon49f085d2014-09-05 13:34:00 -0700495 SkASSERT(dst);
496 SkASSERT(src);
bsalomon@google.com116ad842013-04-09 15:38:19 +0000497
498 SkIRect clippedSrcRect;
499 SkIPoint clippedDstPoint;
500 // If the rect is outside the src or dst then we're guaranteed success
501 if (!clip_srcrect_and_dstpoint(dst,
502 src,
503 srcRect,
504 dstPoint,
505 &clippedSrcRect,
506 &clippedDstPoint)) {
507 return true;
508 }
bsalomonf90a02b2014-11-26 12:28:00 -0800509 return ((dst != src) && dst->asRenderTarget() && src->asTexture()) ||
bsalomona73239a2015-04-28 13:35:17 -0700510 this->getGpu()->canCopySurface(dst, src, clippedSrcRect, clippedDstPoint);
bsalomon@google.comeb851172013-04-15 13:51:00 +0000511}
512
egdaniele36914c2015-02-13 09:00:33 -0800513void GrDrawTarget::setupPipeline(const PipelineInfo& pipelineInfo,
514 GrPipeline* pipeline) {
515 SkNEW_PLACEMENT_ARGS(pipeline, GrPipeline, (*pipelineInfo.fPipelineBuilder,
516 pipelineInfo.fColorPOI,
517 pipelineInfo.fCoveragePOI,
518 *this->caps(),
519 *pipelineInfo.fScissor,
520 &pipelineInfo.fDstCopy));
521}
522///////////////////////////////////////////////////////////////////////////////
523
524GrDrawTarget::PipelineInfo::PipelineInfo(GrPipelineBuilder* pipelineBuilder,
525 GrScissorState* scissor,
526 const GrPrimitiveProcessor* primProc,
527 const SkRect* devBounds,
528 GrDrawTarget* target)
529 : fPipelineBuilder(pipelineBuilder)
530 , fScissor(scissor) {
531 fColorPOI = fPipelineBuilder->colorProcInfo(primProc);
532 fCoveragePOI = fPipelineBuilder->coverageProcInfo(primProc);
533 if (!target->setupDstReadIfNecessary(*fPipelineBuilder, fColorPOI, fCoveragePOI,
534 &fDstCopy, devBounds)) {
535 fPipelineBuilder = NULL;
536 }
537}
538
539GrDrawTarget::PipelineInfo::PipelineInfo(GrPipelineBuilder* pipelineBuilder,
540 GrScissorState* scissor,
541 const GrBatch* batch,
542 const SkRect* devBounds,
543 GrDrawTarget* target)
544 : fPipelineBuilder(pipelineBuilder)
545 , fScissor(scissor) {
546 fColorPOI = fPipelineBuilder->colorProcInfo(batch);
547 fCoveragePOI = fPipelineBuilder->coverageProcInfo(batch);
548 if (!target->setupDstReadIfNecessary(*fPipelineBuilder, fColorPOI, fCoveragePOI,
549 &fDstCopy, devBounds)) {
550 fPipelineBuilder = NULL;
551 }
552}
553
bsalomon@google.combcce8922013-03-25 15:38:39 +0000554///////////////////////////////////////////////////////////////////////////////
555
jvanverthe9c0fc62015-04-29 11:18:05 -0700556void GrShaderCaps::reset() {
557 fShaderDerivativeSupport = false;
558 fGeometryShaderSupport = false;
559 fPathRenderingSupport = false;
560 fDstReadInShaderSupport = false;
561 fDualSourceBlendingSupport = false;
562
563 fShaderPrecisionVaries = false;
564}
565
566GrShaderCaps& GrShaderCaps::operator=(const GrShaderCaps& other) {
567 fShaderDerivativeSupport = other.fShaderDerivativeSupport;
568 fGeometryShaderSupport = other.fGeometryShaderSupport;
569 fPathRenderingSupport = other.fPathRenderingSupport;
570 fDstReadInShaderSupport = other.fDstReadInShaderSupport;
571 fDualSourceBlendingSupport = other.fDualSourceBlendingSupport;
572
573 fShaderPrecisionVaries = other.fShaderPrecisionVaries;
574 for (int s = 0; s < kGrShaderTypeCount; ++s) {
575 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
576 fFloatPrecisions[s][p] = other.fFloatPrecisions[s][p];
577 }
578 }
579 return *this;
580}
581
582static const char* shader_type_to_string(GrShaderType type) {
583 switch (type) {
584 case kVertex_GrShaderType:
585 return "vertex";
586 case kGeometry_GrShaderType:
587 return "geometry";
588 case kFragment_GrShaderType:
589 return "fragment";
590 }
591 return "";
592}
593
594static const char* precision_to_string(GrSLPrecision p) {
595 switch (p) {
596 case kLow_GrSLPrecision:
597 return "low";
598 case kMedium_GrSLPrecision:
599 return "medium";
600 case kHigh_GrSLPrecision:
601 return "high";
602 }
603 return "";
604}
605
606SkString GrShaderCaps::dump() const {
607 SkString r;
608 static const char* gNY[] = { "NO", "YES" };
609 r.appendf("Shader Derivative Support : %s\n", gNY[fShaderDerivativeSupport]);
610 r.appendf("Geometry Shader Support : %s\n", gNY[fGeometryShaderSupport]);
611 r.appendf("Path Rendering Support : %s\n", gNY[fPathRenderingSupport]);
612 r.appendf("Dst Read In Shader Support : %s\n", gNY[fDstReadInShaderSupport]);
613 r.appendf("Dual Source Blending Support : %s\n", gNY[fDualSourceBlendingSupport]);
614
615 r.appendf("Shader Float Precisions (varies: %s):\n", gNY[fShaderPrecisionVaries]);
616
617 for (int s = 0; s < kGrShaderTypeCount; ++s) {
618 GrShaderType shaderType = static_cast<GrShaderType>(s);
619 r.appendf("\t%s:\n", shader_type_to_string(shaderType));
620 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
621 if (fFloatPrecisions[s][p].supported()) {
622 GrSLPrecision precision = static_cast<GrSLPrecision>(p);
623 r.appendf("\t\t%s: log_low: %d log_high: %d bits: %d\n",
624 precision_to_string(precision),
625 fFloatPrecisions[s][p].fLogRangeLow,
626 fFloatPrecisions[s][p].fLogRangeHigh,
627 fFloatPrecisions[s][p].fBits);
628 }
629 }
630 }
631
632 return r;
633}
634
635///////////////////////////////////////////////////////////////////////////////
636
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000637void GrDrawTargetCaps::reset() {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000638 fMipMapSupport = false;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000639 fNPOTTextureTileSupport = false;
640 fTwoSidedStencilSupport = false;
641 fStencilWrapOpsSupport = false;
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +0000642 fDiscardRenderTargetSupport = false;
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000643 fReuseScratchTextures = true;
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000644 fGpuTracingSupport = false;
krajcevski786978162014-07-30 11:25:44 -0700645 fCompressedTexSubImageSupport = false;
bsalomond08ea5f2015-02-20 06:58:13 -0800646 fOversizedStencilSupport = false;
cdaltonfd4167d2015-04-21 11:45:56 -0700647 fTextureBarrierSupport = false;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000648
bsalomon63b21962014-11-05 07:05:34 -0800649 fUseDrawInsteadOfClear = false;
650
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000651 fMapBufferFlags = kNone_MapFlags;
652
bsalomon@google.combcce8922013-03-25 15:38:39 +0000653 fMaxRenderTargetSize = 0;
654 fMaxTextureSize = 0;
655 fMaxSampleCount = 0;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000656
657 memset(fConfigRenderSupport, 0, sizeof(fConfigRenderSupport));
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000658 memset(fConfigTextureSupport, 0, sizeof(fConfigTextureSupport));
bsalomon@google.combcce8922013-03-25 15:38:39 +0000659}
660
bsalomon@google.comc26d94f2013-03-25 18:19:00 +0000661GrDrawTargetCaps& GrDrawTargetCaps::operator=(const GrDrawTargetCaps& other) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000662 fMipMapSupport = other.fMipMapSupport;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000663 fNPOTTextureTileSupport = other.fNPOTTextureTileSupport;
664 fTwoSidedStencilSupport = other.fTwoSidedStencilSupport;
665 fStencilWrapOpsSupport = other.fStencilWrapOpsSupport;
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +0000666 fDiscardRenderTargetSupport = other.fDiscardRenderTargetSupport;
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000667 fReuseScratchTextures = other.fReuseScratchTextures;
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000668 fGpuTracingSupport = other.fGpuTracingSupport;
krajcevski786978162014-07-30 11:25:44 -0700669 fCompressedTexSubImageSupport = other.fCompressedTexSubImageSupport;
bsalomond08ea5f2015-02-20 06:58:13 -0800670 fOversizedStencilSupport = other.fOversizedStencilSupport;
cdaltonfd4167d2015-04-21 11:45:56 -0700671 fTextureBarrierSupport = other.fTextureBarrierSupport;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000672
bsalomon63b21962014-11-05 07:05:34 -0800673 fUseDrawInsteadOfClear = other.fUseDrawInsteadOfClear;
674
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000675 fMapBufferFlags = other.fMapBufferFlags;
676
bsalomon@google.combcce8922013-03-25 15:38:39 +0000677 fMaxRenderTargetSize = other.fMaxRenderTargetSize;
678 fMaxTextureSize = other.fMaxTextureSize;
679 fMaxSampleCount = other.fMaxSampleCount;
680
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000681 memcpy(fConfigRenderSupport, other.fConfigRenderSupport, sizeof(fConfigRenderSupport));
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000682 memcpy(fConfigTextureSupport, other.fConfigTextureSupport, sizeof(fConfigTextureSupport));
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000683
bsalomon@google.combcce8922013-03-25 15:38:39 +0000684 return *this;
685}
686
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000687static SkString map_flags_to_string(uint32_t flags) {
688 SkString str;
689 if (GrDrawTargetCaps::kNone_MapFlags == flags) {
690 str = "none";
691 } else {
692 SkASSERT(GrDrawTargetCaps::kCanMap_MapFlag & flags);
693 SkDEBUGCODE(flags &= ~GrDrawTargetCaps::kCanMap_MapFlag);
694 str = "can_map";
695
696 if (GrDrawTargetCaps::kSubset_MapFlag & flags) {
697 str.append(" partial");
698 } else {
699 str.append(" full");
700 }
701 SkDEBUGCODE(flags &= ~GrDrawTargetCaps::kSubset_MapFlag);
702 }
703 SkASSERT(0 == flags); // Make sure we handled all the flags.
704 return str;
705}
706
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000707SkString GrDrawTargetCaps::dump() const {
708 SkString r;
bsalomon@google.com18c9c192011-09-22 21:01:31 +0000709 static const char* gNY[] = {"NO", "YES"};
bsalomon63b21962014-11-05 07:05:34 -0800710 r.appendf("MIP Map Support : %s\n", gNY[fMipMapSupport]);
711 r.appendf("NPOT Texture Tile Support : %s\n", gNY[fNPOTTextureTileSupport]);
712 r.appendf("Two Sided Stencil Support : %s\n", gNY[fTwoSidedStencilSupport]);
713 r.appendf("Stencil Wrap Ops Support : %s\n", gNY[fStencilWrapOpsSupport]);
bsalomon63b21962014-11-05 07:05:34 -0800714 r.appendf("Discard Render Target Support : %s\n", gNY[fDiscardRenderTargetSupport]);
715 r.appendf("Reuse Scratch Textures : %s\n", gNY[fReuseScratchTextures]);
716 r.appendf("Gpu Tracing Support : %s\n", gNY[fGpuTracingSupport]);
717 r.appendf("Compressed Update Support : %s\n", gNY[fCompressedTexSubImageSupport]);
bsalomond08ea5f2015-02-20 06:58:13 -0800718 r.appendf("Oversized Stencil Support : %s\n", gNY[fOversizedStencilSupport]);
cdaltonfd4167d2015-04-21 11:45:56 -0700719 r.appendf("Texture Barrier Support : %s\n", gNY[fTextureBarrierSupport]);
bsalomon63b21962014-11-05 07:05:34 -0800720 r.appendf("Draw Instead of Clear [workaround] : %s\n", gNY[fUseDrawInsteadOfClear]);
721
722 r.appendf("Max Texture Size : %d\n", fMaxTextureSize);
723 r.appendf("Max Render Target Size : %d\n", fMaxRenderTargetSize);
724 r.appendf("Max Sample Count : %d\n", fMaxSampleCount);
725
726 r.appendf("Map Buffer Support : %s\n",
727 map_flags_to_string(fMapBufferFlags).c_str());
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000728
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000729 static const char* kConfigNames[] = {
730 "Unknown", // kUnknown_GrPixelConfig
731 "Alpha8", // kAlpha_8_GrPixelConfig,
732 "Index8", // kIndex_8_GrPixelConfig,
733 "RGB565", // kRGB_565_GrPixelConfig,
734 "RGBA444", // kRGBA_4444_GrPixelConfig,
735 "RGBA8888", // kRGBA_8888_GrPixelConfig,
736 "BGRA8888", // kBGRA_8888_GrPixelConfig,
jvanverthfa1e8a72014-12-22 08:31:49 -0800737 "SRGBA8888",// kSRGBA_8888_GrPixelConfig,
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000738 "ETC1", // kETC1_GrPixelConfig,
739 "LATC", // kLATC_GrPixelConfig,
krajcevski238b4562014-06-30 09:09:22 -0700740 "R11EAC", // kR11_EAC_GrPixelConfig,
krajcevski7ef21622014-07-16 15:21:13 -0700741 "ASTC12x12",// kASTC_12x12_GrPixelConfig,
jvanverth28f9c602014-12-05 13:06:35 -0800742 "RGBAFloat",// kRGBA_float_GrPixelConfig
743 "AlphaHalf",// kAlpha_half_GrPixelConfig
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000744 };
krajcevski7ef21622014-07-16 15:21:13 -0700745 GR_STATIC_ASSERT(0 == kUnknown_GrPixelConfig);
746 GR_STATIC_ASSERT(1 == kAlpha_8_GrPixelConfig);
747 GR_STATIC_ASSERT(2 == kIndex_8_GrPixelConfig);
748 GR_STATIC_ASSERT(3 == kRGB_565_GrPixelConfig);
749 GR_STATIC_ASSERT(4 == kRGBA_4444_GrPixelConfig);
750 GR_STATIC_ASSERT(5 == kRGBA_8888_GrPixelConfig);
751 GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig);
jvanverthfa1e8a72014-12-22 08:31:49 -0800752 GR_STATIC_ASSERT(7 == kSRGBA_8888_GrPixelConfig);
753 GR_STATIC_ASSERT(8 == kETC1_GrPixelConfig);
754 GR_STATIC_ASSERT(9 == kLATC_GrPixelConfig);
755 GR_STATIC_ASSERT(10 == kR11_EAC_GrPixelConfig);
756 GR_STATIC_ASSERT(11 == kASTC_12x12_GrPixelConfig);
757 GR_STATIC_ASSERT(12 == kRGBA_float_GrPixelConfig);
758 GR_STATIC_ASSERT(13 == kAlpha_half_GrPixelConfig);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000759 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kConfigNames) == kGrPixelConfigCnt);
760
commit-bot@chromium.org99017272013-11-08 18:45:27 +0000761 SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][0]);
762 SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][1]);
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000763
764 for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) {
765 r.appendf("%s is renderable: %s, with MSAA: %s\n",
766 kConfigNames[i],
767 gNY[fConfigRenderSupport[i][0]],
768 gNY[fConfigRenderSupport[i][1]]);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000769 }
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000770
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000771 SkASSERT(!fConfigTextureSupport[kUnknown_GrPixelConfig]);
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000772
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000773 for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) {
774 r.appendf("%s is uploadable to a texture: %s\n",
775 kConfigNames[i],
776 gNY[fConfigTextureSupport[i]]);
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000777 }
778
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000779 return r;
bsalomon@google.com18c9c192011-09-22 21:01:31 +0000780}
egdanielbc127a32014-09-19 12:07:43 -0700781
joshualitt2c93efe2014-11-06 12:57:13 -0800782///////////////////////////////////////////////////////////////////////////////////////////////////
783
egdaniel8dd688b2015-01-22 10:16:09 -0800784bool GrClipTarget::setupClip(GrPipelineBuilder* pipelineBuilder,
bsalomon6be6f7c2015-02-26 13:05:21 -0800785 GrPipelineBuilder::AutoRestoreFragmentProcessors* arfp,
egdaniel8dd688b2015-01-22 10:16:09 -0800786 GrPipelineBuilder::AutoRestoreStencil* ars,
joshualitt8059eb92014-12-29 15:10:07 -0800787 GrScissorState* scissorState,
788 const SkRect* devBounds) {
egdaniel8dd688b2015-01-22 10:16:09 -0800789 return fClipMaskManager.setupClipping(pipelineBuilder,
bsalomon6be6f7c2015-02-26 13:05:21 -0800790 arfp,
joshualitt2c93efe2014-11-06 12:57:13 -0800791 ars,
joshualitt9853cce2014-11-17 14:22:48 -0800792 scissorState,
joshualitt9853cce2014-11-17 14:22:48 -0800793 devBounds);
joshualitt2c93efe2014-11-06 12:57:13 -0800794}