blob: 35a19e4e243546338dd1725f6aaaceb4691877f6 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@google.comac10a2d2010-12-22 21:39:39 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2010 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
reed@google.comac10a2d2010-12-22 21:39:39 +00007 */
8
joshualittc2893c52015-01-28 06:54:30 -08009#include "GrDrawTarget.h"
joshualitt4d8da812015-01-28 12:53:54 -080010
11#include "GrBatch.h"
bsalomon@google.com26e18b52013-03-29 19:22:36 +000012#include "GrContext.h"
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000013#include "GrDrawTargetCaps.h"
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +000014#include "GrPath.h"
egdaniele36914c2015-02-13 09:00:33 -080015#include "GrPipeline.h"
joshualittb7133be2015-04-08 09:08:31 -070016#include "GrMemoryPool.h"
joshualittad17cfc2015-05-05 10:45:57 -070017#include "GrRectBatch.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.com25fb21f2011-06-21 18:17:25 +000029#define DEBUG_INVAL_BUFFER 0xdeadcafe
30#define DEBUG_INVAL_START_IDX -1
31
robertphillipse40d3972015-05-07 09:51:43 -070032GrDrawTarget::GrDrawTarget(GrContext* context)
joshualitt44701df2015-02-23 14:44:57 -080033 : fContext(context)
bsalomona73239a2015-04-28 13:35:17 -070034 , fCaps(SkRef(context->getGpu()->caps()))
35 , fGpuTraceMarkerCount(0)
bsalomona73239a2015-04-28 13:35:17 -070036 , fFlushing(false) {
bsalomon49f085d2014-09-05 13:34:00 -070037 SkASSERT(context);
bsalomon@google.com25fb21f2011-06-21 18:17:25 +000038}
39
40////////////////////////////////////////////////////////////////////////////////
41
bsalomon50785a32015-02-06 07:02:37 -080042bool GrDrawTarget::setupDstReadIfNecessary(const GrPipelineBuilder& pipelineBuilder,
egdaniele36914c2015-02-13 09:00:33 -080043 const GrProcOptInfo& colorPOI,
44 const GrProcOptInfo& coveragePOI,
joshualitt9853cce2014-11-17 14:22:48 -080045 GrDeviceCoordTexture* dstCopy,
46 const SkRect* drawBounds) {
egdaniele36914c2015-02-13 09:00:33 -080047 if (!pipelineBuilder.willXPNeedDstCopy(*this->caps(), colorPOI, coveragePOI)) {
bsalomon@google.com26e18b52013-03-29 19:22:36 +000048 return true;
49 }
cdalton9954bc32015-04-29 14:17:00 -070050
bsalomon50785a32015-02-06 07:02:37 -080051 GrRenderTarget* rt = pipelineBuilder.getRenderTarget();
cdalton9954bc32015-04-29 14:17:00 -070052
53 if (this->caps()->textureBarrierSupport()) {
54 if (GrTexture* rtTex = rt->asTexture()) {
55 // The render target is a texture, se we can read from it directly in the shader. The XP
56 // will be responsible to detect this situation and request a texture barrier.
57 dstCopy->setTexture(rtTex);
58 dstCopy->setOffset(0, 0);
59 return true;
60 }
61 }
62
63 SkIRect copyRect;
joshualitt44701df2015-02-23 14:44:57 -080064 pipelineBuilder.clip().getConservativeBounds(rt, &copyRect);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +000065
bsalomon49f085d2014-09-05 13:34:00 -070066 if (drawBounds) {
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +000067 SkIRect drawIBounds;
68 drawBounds->roundOut(&drawIBounds);
commit-bot@chromium.orgbb5c4652013-04-01 12:49:31 +000069 if (!copyRect.intersect(drawIBounds)) {
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +000070#ifdef SK_DEBUG
joshualitt7d022d62015-05-12 12:03:50 -070071 GrContextDebugf(fContext, "Missed an early reject. "
72 "Bailing on draw from setupDstReadIfNecessary.\n");
commit-bot@chromium.orgbb5c4652013-04-01 12:49:31 +000073#endif
74 return false;
75 }
76 } else {
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +000077#ifdef SK_DEBUG
tfarina38406c82014-10-31 07:11:12 -070078 //SkDebugf("No dev bounds when dst copy is made.\n");
commit-bot@chromium.orgbb5c4652013-04-01 12:49:31 +000079#endif
80 }
skia.committer@gmail.com05a2ee02013-04-02 07:01:34 +000081
commit-bot@chromium.org63150af2013-04-11 22:00:22 +000082 // MSAA consideration: When there is support for reading MSAA samples in the shader we could
83 // have per-sample dst values by making the copy multisampled.
bsalomonf2703d82014-10-28 14:33:06 -070084 GrSurfaceDesc desc;
bsalomona73239a2015-04-28 13:35:17 -070085 if (!this->getGpu()->initCopySurfaceDstDesc(rt, &desc)) {
86 desc.fOrigin = kDefault_GrSurfaceOrigin;
87 desc.fFlags = kRenderTarget_GrSurfaceFlag;
88 desc.fConfig = rt->config();
89 }
90
91
commit-bot@chromium.orgbb5c4652013-04-01 12:49:31 +000092 desc.fWidth = copyRect.width();
93 desc.fHeight = copyRect.height();
bsalomon@google.com26e18b52013-03-29 19:22:36 +000094
bsalomond309e7a2015-04-30 14:18:54 -070095 SkAutoTUnref<GrTexture> copy(fContext->textureProvider()->refScratchTexture(desc,
96 GrTextureProvider::kApprox_ScratchTexMatch));
bsalomon@google.com26e18b52013-03-29 19:22:36 +000097
bsalomone3059732014-10-14 11:47:22 -070098 if (!copy) {
tfarina38406c82014-10-31 07:11:12 -070099 SkDebugf("Failed to create temporary copy of destination texture.\n");
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000100 return false;
101 }
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000102 SkIPoint dstPoint = {0, 0};
mtklein404b3b22015-05-18 09:29:10 -0700103 if (this->copySurface(copy, rt, copyRect, dstPoint)) {
104 dstCopy->setTexture(copy);
105 dstCopy->setOffset(copyRect.fLeft, copyRect.fTop);
106 return true;
107 } else {
108 return false;
109 }
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000110}
111
bsalomona73239a2015-04-28 13:35:17 -0700112void GrDrawTarget::flush() {
113 if (fFlushing) {
114 return;
115 }
116 fFlushing = true;
117
118 this->getGpu()->saveActiveTraceMarkers();
119
120 this->onFlush();
121
122 this->getGpu()->restoreActiveTraceMarkers();
123
124 fFlushing = false;
125 this->reset();
126}
127
joshualitt4d8da812015-01-28 12:53:54 -0800128void GrDrawTarget::drawBatch(GrPipelineBuilder* pipelineBuilder,
joshualitt99c7c072015-05-01 13:43:30 -0700129 GrBatch* batch) {
joshualitt4d8da812015-01-28 12:53:54 -0800130 SkASSERT(pipelineBuilder);
131 // TODO some kind of checkdraw, but not at this level
132
133 // Setup clip
134 GrScissorState scissorState;
bsalomon6be6f7c2015-02-26 13:05:21 -0800135 GrPipelineBuilder::AutoRestoreFragmentProcessors arfp;
joshualitt4d8da812015-01-28 12:53:54 -0800136 GrPipelineBuilder::AutoRestoreStencil ars;
joshualitt99c7c072015-05-01 13:43:30 -0700137 if (!this->setupClip(pipelineBuilder, &arfp, &ars, &scissorState, &batch->bounds())) {
joshualitt4d8da812015-01-28 12:53:54 -0800138 return;
139 }
140
joshualitt99c7c072015-05-01 13:43:30 -0700141 // Batch bounds are tight, so for dev copies
142 // TODO move this into setupDstReadIfNecessary when paths are in batch
143 SkRect bounds = batch->bounds();
144 bounds.outset(0.5f, 0.5f);
145
146 GrDrawTarget::PipelineInfo pipelineInfo(pipelineBuilder, &scissorState, batch, &bounds,
147 this);
egdaniele36914c2015-02-13 09:00:33 -0800148 if (pipelineInfo.mustSkipDraw()) {
149 return;
150 }
151
152 this->onDrawBatch(batch, pipelineInfo);
joshualitt4d8da812015-01-28 12:53:54 -0800153}
154
joshualitt2c93efe2014-11-06 12:57:13 -0800155static const GrStencilSettings& winding_path_stencil_settings() {
156 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings,
157 kIncClamp_StencilOp,
158 kIncClamp_StencilOp,
159 kAlwaysIfInClip_StencilFunc,
160 0xFFFF, 0xFFFF, 0xFFFF);
161 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings);
162}
163
164static const GrStencilSettings& even_odd_path_stencil_settings() {
165 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings,
166 kInvert_StencilOp,
167 kInvert_StencilOp,
168 kAlwaysIfInClip_StencilFunc,
169 0xFFFF, 0xFFFF, 0xFFFF);
170 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings);
171}
172
173void GrDrawTarget::getPathStencilSettingsForFilltype(GrPathRendering::FillType fill,
egdaniel8dc7c3a2015-04-16 11:22:42 -0700174 const GrStencilAttachment* sb,
joshualitt2c93efe2014-11-06 12:57:13 -0800175 GrStencilSettings* outStencilSettings) {
176
177 switch (fill) {
178 default:
179 SkFAIL("Unexpected path fill.");
180 case GrPathRendering::kWinding_FillType:
181 *outStencilSettings = winding_path_stencil_settings();
182 break;
183 case GrPathRendering::kEvenOdd_FillType:
184 *outStencilSettings = even_odd_path_stencil_settings();
185 break;
186 }
joshualitt9853cce2014-11-17 14:22:48 -0800187 this->clipMaskManager()->adjustPathStencilParams(sb, outStencilSettings);
joshualitt2c93efe2014-11-06 12:57:13 -0800188}
189
egdaniel8dd688b2015-01-22 10:16:09 -0800190void GrDrawTarget::stencilPath(GrPipelineBuilder* pipelineBuilder,
joshualitt56995b52014-12-11 15:44:02 -0800191 const GrPathProcessor* pathProc,
joshualitt9853cce2014-11-17 14:22:48 -0800192 const GrPath* path,
193 GrPathRendering::FillType fill) {
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000194 // TODO: extract portions of checkDraw that are relevant to path stenciling.
bsalomon49f085d2014-09-05 13:34:00 -0700195 SkASSERT(path);
jvanverthe9c0fc62015-04-29 11:18:05 -0700196 SkASSERT(this->caps()->shaderCaps()->pathRenderingSupport());
egdaniel8dd688b2015-01-22 10:16:09 -0800197 SkASSERT(pipelineBuilder);
joshualitt2c93efe2014-11-06 12:57:13 -0800198
199 // Setup clip
bsalomon3e791242014-12-17 13:43:13 -0800200 GrScissorState scissorState;
bsalomon6be6f7c2015-02-26 13:05:21 -0800201 GrPipelineBuilder::AutoRestoreFragmentProcessors arfp;
egdaniel8dd688b2015-01-22 10:16:09 -0800202 GrPipelineBuilder::AutoRestoreStencil ars;
bsalomon6be6f7c2015-02-26 13:05:21 -0800203 if (!this->setupClip(pipelineBuilder, &arfp, &ars, &scissorState, NULL)) {
joshualitt2c93efe2014-11-06 12:57:13 -0800204 return;
205 }
206
207 // set stencil settings for path
208 GrStencilSettings stencilSettings;
bsalomon6bc1b5f2015-02-23 09:06:38 -0800209 GrRenderTarget* rt = pipelineBuilder->getRenderTarget();
egdaniel8dc7c3a2015-04-16 11:22:42 -0700210 GrStencilAttachment* sb = rt->renderTargetPriv().attachStencilAttachment();
bsalomon6bc1b5f2015-02-23 09:06:38 -0800211 this->getPathStencilSettingsForFilltype(fill, sb, &stencilSettings);
joshualitt2c93efe2014-11-06 12:57:13 -0800212
egdaniel8dd688b2015-01-22 10:16:09 -0800213 this->onStencilPath(*pipelineBuilder, pathProc, path, scissorState, stencilSettings);
bsalomon@google.com64aef2b2012-06-11 15:36:13 +0000214}
215
egdaniel8dd688b2015-01-22 10:16:09 -0800216void GrDrawTarget::drawPath(GrPipelineBuilder* pipelineBuilder,
joshualitt56995b52014-12-11 15:44:02 -0800217 const GrPathProcessor* pathProc,
joshualitt9853cce2014-11-17 14:22:48 -0800218 const GrPath* path,
219 GrPathRendering::FillType fill) {
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000220 // TODO: extract portions of checkDraw that are relevant to path rendering.
bsalomon49f085d2014-09-05 13:34:00 -0700221 SkASSERT(path);
jvanverthe9c0fc62015-04-29 11:18:05 -0700222 SkASSERT(this->caps()->shaderCaps()->pathRenderingSupport());
egdaniel8dd688b2015-01-22 10:16:09 -0800223 SkASSERT(pipelineBuilder);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000224
joshualitt92e496f2014-10-31 13:56:50 -0700225 SkRect devBounds = path->getBounds();
joshualitt8059eb92014-12-29 15:10:07 -0800226 pathProc->viewMatrix().mapRect(&devBounds);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000227
joshualitt2c93efe2014-11-06 12:57:13 -0800228 // Setup clip
bsalomon3e791242014-12-17 13:43:13 -0800229 GrScissorState scissorState;
bsalomon6be6f7c2015-02-26 13:05:21 -0800230 GrPipelineBuilder::AutoRestoreFragmentProcessors arfp;
egdaniel8dd688b2015-01-22 10:16:09 -0800231 GrPipelineBuilder::AutoRestoreStencil ars;
bsalomon6be6f7c2015-02-26 13:05:21 -0800232 if (!this->setupClip(pipelineBuilder, &arfp, &ars, &scissorState, &devBounds)) {
joshualitt2c93efe2014-11-06 12:57:13 -0800233 return;
234 }
235
236 // set stencil settings for path
237 GrStencilSettings stencilSettings;
bsalomon6bc1b5f2015-02-23 09:06:38 -0800238 GrRenderTarget* rt = pipelineBuilder->getRenderTarget();
egdaniel8dc7c3a2015-04-16 11:22:42 -0700239 GrStencilAttachment* sb = rt->renderTargetPriv().attachStencilAttachment();
bsalomon6bc1b5f2015-02-23 09:06:38 -0800240 this->getPathStencilSettingsForFilltype(fill, sb, &stencilSettings);
joshualitt2c93efe2014-11-06 12:57:13 -0800241
egdaniele36914c2015-02-13 09:00:33 -0800242 GrDrawTarget::PipelineInfo pipelineInfo(pipelineBuilder, &scissorState, pathProc, &devBounds,
243 this);
244 if (pipelineInfo.mustSkipDraw()) {
245 return;
246 }
247
248 this->onDrawPath(pathProc, path, stencilSettings, pipelineInfo);
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000249}
250
egdaniel8dd688b2015-01-22 10:16:09 -0800251void GrDrawTarget::drawPaths(GrPipelineBuilder* pipelineBuilder,
joshualitt56995b52014-12-11 15:44:02 -0800252 const GrPathProcessor* pathProc,
joshualitt9853cce2014-11-17 14:22:48 -0800253 const GrPathRange* pathRange,
cdalton55b24af2014-11-25 11:00:56 -0800254 const void* indices,
255 PathIndexType indexType,
256 const float transformValues[],
257 PathTransformType transformType,
joshualitt9853cce2014-11-17 14:22:48 -0800258 int count,
joshualitt92e496f2014-10-31 13:56:50 -0700259 GrPathRendering::FillType fill) {
jvanverthe9c0fc62015-04-29 11:18:05 -0700260 SkASSERT(this->caps()->shaderCaps()->pathRenderingSupport());
bsalomon49f085d2014-09-05 13:34:00 -0700261 SkASSERT(pathRange);
262 SkASSERT(indices);
cdalton55b24af2014-11-25 11:00:56 -0800263 SkASSERT(0 == reinterpret_cast<long>(indices) % GrPathRange::PathIndexSizeInBytes(indexType));
264 SkASSERT(transformValues);
egdaniel8dd688b2015-01-22 10:16:09 -0800265 SkASSERT(pipelineBuilder);
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000266
joshualitt2c93efe2014-11-06 12:57:13 -0800267 // Setup clip
bsalomon3e791242014-12-17 13:43:13 -0800268 GrScissorState scissorState;
bsalomon6be6f7c2015-02-26 13:05:21 -0800269 GrPipelineBuilder::AutoRestoreFragmentProcessors arfp;
egdaniel8dd688b2015-01-22 10:16:09 -0800270 GrPipelineBuilder::AutoRestoreStencil ars;
joshualitt2c93efe2014-11-06 12:57:13 -0800271
bsalomon6be6f7c2015-02-26 13:05:21 -0800272 if (!this->setupClip(pipelineBuilder, &arfp, &ars, &scissorState, NULL)) {
joshualitt2c93efe2014-11-06 12:57:13 -0800273 return;
274 }
275
276 // set stencil settings for path
277 GrStencilSettings stencilSettings;
bsalomon6bc1b5f2015-02-23 09:06:38 -0800278 GrRenderTarget* rt = pipelineBuilder->getRenderTarget();
egdaniel8dc7c3a2015-04-16 11:22:42 -0700279 GrStencilAttachment* sb = rt->renderTargetPriv().attachStencilAttachment();
bsalomon6bc1b5f2015-02-23 09:06:38 -0800280 this->getPathStencilSettingsForFilltype(fill, sb, &stencilSettings);
joshualitt2c93efe2014-11-06 12:57:13 -0800281
bsalomon50785a32015-02-06 07:02:37 -0800282 // Don't compute a bounding box for dst copy texture, we'll opt
cdaltonb85a0aa2014-07-21 15:32:44 -0700283 // instead for it to just copy the entire dst. Realistically this is a moot
284 // point, because any context that supports NV_path_rendering will also
285 // support NV_blend_equation_advanced.
egdaniele36914c2015-02-13 09:00:33 -0800286 GrDrawTarget::PipelineInfo pipelineInfo(pipelineBuilder, &scissorState, pathProc, NULL, this);
287 if (pipelineInfo.mustSkipDraw()) {
288 return;
289 }
290
291 this->onDrawPaths(pathProc, pathRange, indices, indexType, transformValues,
292 transformType, count, stencilSettings, pipelineInfo);
commit-bot@chromium.org9b62aa12014-03-25 11:59:40 +0000293}
294
joshualittad17cfc2015-05-05 10:45:57 -0700295void GrDrawTarget::drawRect(GrPipelineBuilder* pipelineBuilder,
296 GrColor color,
297 const SkMatrix& viewMatrix,
298 const SkRect& rect,
299 const SkRect* localRect,
300 const SkMatrix* localMatrix) {
301 SkAutoTUnref<GrBatch> batch(GrRectBatch::Create(color, viewMatrix, rect, localRect,
302 localMatrix));
303 this->drawBatch(pipelineBuilder, batch);
304}
305
joshualitt9853cce2014-11-17 14:22:48 -0800306void GrDrawTarget::clear(const SkIRect* rect,
307 GrColor color,
308 bool canIgnoreRect,
bsalomon63b21962014-11-05 07:05:34 -0800309 GrRenderTarget* renderTarget) {
310 if (fCaps->useDrawInsteadOfClear()) {
311 // This works around a driver bug with clear by drawing a rect instead.
312 // The driver will ignore a clear if it is the only thing rendered to a
313 // target before the target is read.
314 SkIRect rtRect = SkIRect::MakeWH(renderTarget->width(), renderTarget->height());
315 if (NULL == rect || canIgnoreRect || rect->contains(rtRect)) {
316 rect = &rtRect;
317 // We first issue a discard() since that may help tilers.
318 this->discard(renderTarget);
319 }
bsalomon63b21962014-11-05 07:05:34 -0800320
egdaniel8dd688b2015-01-22 10:16:09 -0800321 GrPipelineBuilder pipelineBuilder;
322 pipelineBuilder.setRenderTarget(renderTarget);
joshualitt9853cce2014-11-17 14:22:48 -0800323
egdaniel8dd688b2015-01-22 10:16:09 -0800324 this->drawSimpleRect(&pipelineBuilder, color, SkMatrix::I(), *rect);
bsalomon63b21962014-11-05 07:05:34 -0800325 } else {
326 this->onClear(rect, color, canIgnoreRect, renderTarget);
327 }
328}
329
egdaniel3eee3832014-06-18 13:09:11 -0700330typedef GrTraceMarkerSet::Iter TMIter;
331void GrDrawTarget::saveActiveTraceMarkers() {
332 if (this->caps()->gpuTracingSupport()) {
333 SkASSERT(0 == fStoredTraceMarkers.count());
334 fStoredTraceMarkers.addSet(fActiveTraceMarkers);
335 for (TMIter iter = fStoredTraceMarkers.begin(); iter != fStoredTraceMarkers.end(); ++iter) {
336 this->removeGpuTraceMarker(&(*iter));
337 }
338 }
339}
340
341void GrDrawTarget::restoreActiveTraceMarkers() {
342 if (this->caps()->gpuTracingSupport()) {
343 SkASSERT(0 == fActiveTraceMarkers.count());
344 for (TMIter iter = fStoredTraceMarkers.begin(); iter != fStoredTraceMarkers.end(); ++iter) {
345 this->addGpuTraceMarker(&(*iter));
346 }
347 for (TMIter iter = fActiveTraceMarkers.begin(); iter != fActiveTraceMarkers.end(); ++iter) {
348 this->fStoredTraceMarkers.remove(*iter);
349 }
350 }
351}
352
353void GrDrawTarget::addGpuTraceMarker(const GrGpuTraceMarker* marker) {
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000354 if (this->caps()->gpuTracingSupport()) {
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000355 SkASSERT(fGpuTraceMarkerCount >= 0);
356 this->fActiveTraceMarkers.add(*marker);
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000357 ++fGpuTraceMarkerCount;
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000358 }
359}
360
egdaniel3eee3832014-06-18 13:09:11 -0700361void GrDrawTarget::removeGpuTraceMarker(const GrGpuTraceMarker* marker) {
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000362 if (this->caps()->gpuTracingSupport()) {
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000363 SkASSERT(fGpuTraceMarkerCount >= 1);
364 this->fActiveTraceMarkers.remove(*marker);
commit-bot@chromium.org2a05de02014-03-25 15:17:32 +0000365 --fGpuTraceMarkerCount;
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000366 }
367}
368
bsalomon@google.com25fb21f2011-06-21 18:17:25 +0000369////////////////////////////////////////////////////////////////////////////////
bsalomon@google.com86afc2a2011-02-16 16:12:19 +0000370
bsalomon@google.com116ad842013-04-09 15:38:19 +0000371namespace {
372// returns true if the read/written rect intersects the src/dst and false if not.
373bool clip_srcrect_and_dstpoint(const GrSurface* dst,
374 const GrSurface* src,
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000375 const SkIRect& srcRect,
bsalomon@google.com116ad842013-04-09 15:38:19 +0000376 const SkIPoint& dstPoint,
377 SkIRect* clippedSrcRect,
378 SkIPoint* clippedDstPoint) {
379 *clippedSrcRect = srcRect;
380 *clippedDstPoint = dstPoint;
skia.committer@gmail.coma9493a32013-04-04 07:01:12 +0000381
bsalomon@google.com116ad842013-04-09 15:38:19 +0000382 // clip the left edge to src and dst bounds, adjusting dstPoint if necessary
383 if (clippedSrcRect->fLeft < 0) {
384 clippedDstPoint->fX -= clippedSrcRect->fLeft;
385 clippedSrcRect->fLeft = 0;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000386 }
bsalomon@google.com116ad842013-04-09 15:38:19 +0000387 if (clippedDstPoint->fX < 0) {
388 clippedSrcRect->fLeft -= clippedDstPoint->fX;
389 clippedDstPoint->fX = 0;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000390 }
391
bsalomon@google.com116ad842013-04-09 15:38:19 +0000392 // clip the top edge to src and dst bounds, adjusting dstPoint if necessary
393 if (clippedSrcRect->fTop < 0) {
394 clippedDstPoint->fY -= clippedSrcRect->fTop;
395 clippedSrcRect->fTop = 0;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000396 }
bsalomon@google.com116ad842013-04-09 15:38:19 +0000397 if (clippedDstPoint->fY < 0) {
398 clippedSrcRect->fTop -= clippedDstPoint->fY;
399 clippedDstPoint->fY = 0;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000400 }
skia.committer@gmail.coma9493a32013-04-04 07:01:12 +0000401
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000402 // clip the right edge to the src and dst bounds.
bsalomon@google.com116ad842013-04-09 15:38:19 +0000403 if (clippedSrcRect->fRight > src->width()) {
404 clippedSrcRect->fRight = src->width();
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000405 }
bsalomon@google.com116ad842013-04-09 15:38:19 +0000406 if (clippedDstPoint->fX + clippedSrcRect->width() > dst->width()) {
407 clippedSrcRect->fRight = clippedSrcRect->fLeft + dst->width() - clippedDstPoint->fX;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000408 }
409
410 // clip the bottom edge to the src and dst bounds.
bsalomon@google.com116ad842013-04-09 15:38:19 +0000411 if (clippedSrcRect->fBottom > src->height()) {
412 clippedSrcRect->fBottom = src->height();
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000413 }
bsalomon@google.com116ad842013-04-09 15:38:19 +0000414 if (clippedDstPoint->fY + clippedSrcRect->height() > dst->height()) {
415 clippedSrcRect->fBottom = clippedSrcRect->fTop + dst->height() - clippedDstPoint->fY;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000416 }
skia.committer@gmail.coma9493a32013-04-04 07:01:12 +0000417
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000418 // The above clipping steps may have inverted the rect if it didn't intersect either the src or
419 // dst bounds.
bsalomon@google.com116ad842013-04-09 15:38:19 +0000420 return !clippedSrcRect->isEmpty();
421}
422}
423
mtklein404b3b22015-05-18 09:29:10 -0700424bool GrDrawTarget::copySurface(GrSurface* dst,
bsalomon@google.com116ad842013-04-09 15:38:19 +0000425 GrSurface* src,
426 const SkIRect& srcRect,
427 const SkIPoint& dstPoint) {
bsalomon49f085d2014-09-05 13:34:00 -0700428 SkASSERT(dst);
429 SkASSERT(src);
bsalomon@google.com116ad842013-04-09 15:38:19 +0000430
431 SkIRect clippedSrcRect;
432 SkIPoint clippedDstPoint;
433 // If the rect is outside the src or dst then we've already succeeded.
434 if (!clip_srcrect_and_dstpoint(dst,
435 src,
436 srcRect,
437 dstPoint,
438 &clippedSrcRect,
439 &clippedDstPoint)) {
mtklein404b3b22015-05-18 09:29:10 -0700440 return true;
bsalomon@google.come4617bf2013-04-03 14:56:40 +0000441 }
442
mtklein404b3b22015-05-18 09:29:10 -0700443 if (this->getGpu()->canCopySurface(dst, src, clippedSrcRect, clippedDstPoint)) {
444 this->onCopySurface(dst, src, clippedSrcRect, clippedDstPoint);
445 return true;
446 }
447
448 GrRenderTarget* rt = dst->asRenderTarget();
449 GrTexture* tex = src->asTexture();
450
451 if ((dst == src) || !rt || !tex) {
452 return false;
453 }
454
455 GrPipelineBuilder pipelineBuilder;
456 pipelineBuilder.setRenderTarget(rt);
457 SkMatrix matrix;
458 matrix.setTranslate(SkIntToScalar(clippedSrcRect.fLeft - clippedDstPoint.fX),
459 SkIntToScalar(clippedSrcRect.fTop - clippedDstPoint.fY));
460 matrix.postIDiv(tex->width(), tex->height());
461 pipelineBuilder.addColorTextureProcessor(tex, matrix);
462 SkIRect dstRect = SkIRect::MakeXYWH(clippedDstPoint.fX,
463 clippedDstPoint.fY,
464 clippedSrcRect.width(),
465 clippedSrcRect.height());
466 this->drawSimpleRect(&pipelineBuilder, GrColor_WHITE, SkMatrix::I(), dstRect);
467 return true;
468}
469
470bool GrDrawTarget::canCopySurface(const GrSurface* dst,
471 const GrSurface* src,
472 const SkIRect& srcRect,
473 const SkIPoint& dstPoint) {
474 SkASSERT(dst);
475 SkASSERT(src);
476
477 SkIRect clippedSrcRect;
478 SkIPoint clippedDstPoint;
479 // If the rect is outside the src or dst then we're guaranteed success
480 if (!clip_srcrect_and_dstpoint(dst,
481 src,
482 srcRect,
483 dstPoint,
484 &clippedSrcRect,
485 &clippedDstPoint)) {
486 return true;
487 }
488 return ((dst != src) && dst->asRenderTarget() && src->asTexture()) ||
489 this->getGpu()->canCopySurface(dst, src, clippedSrcRect, clippedDstPoint);
bsalomon@google.comeb851172013-04-15 13:51:00 +0000490}
491
egdaniele36914c2015-02-13 09:00:33 -0800492void GrDrawTarget::setupPipeline(const PipelineInfo& pipelineInfo,
493 GrPipeline* pipeline) {
494 SkNEW_PLACEMENT_ARGS(pipeline, GrPipeline, (*pipelineInfo.fPipelineBuilder,
495 pipelineInfo.fColorPOI,
496 pipelineInfo.fCoveragePOI,
497 *this->caps(),
498 *pipelineInfo.fScissor,
499 &pipelineInfo.fDstCopy));
500}
501///////////////////////////////////////////////////////////////////////////////
502
503GrDrawTarget::PipelineInfo::PipelineInfo(GrPipelineBuilder* pipelineBuilder,
504 GrScissorState* scissor,
505 const GrPrimitiveProcessor* primProc,
506 const SkRect* devBounds,
507 GrDrawTarget* target)
508 : fPipelineBuilder(pipelineBuilder)
509 , fScissor(scissor) {
510 fColorPOI = fPipelineBuilder->colorProcInfo(primProc);
511 fCoveragePOI = fPipelineBuilder->coverageProcInfo(primProc);
512 if (!target->setupDstReadIfNecessary(*fPipelineBuilder, fColorPOI, fCoveragePOI,
513 &fDstCopy, devBounds)) {
514 fPipelineBuilder = NULL;
515 }
516}
517
518GrDrawTarget::PipelineInfo::PipelineInfo(GrPipelineBuilder* pipelineBuilder,
519 GrScissorState* scissor,
520 const GrBatch* batch,
521 const SkRect* devBounds,
522 GrDrawTarget* target)
523 : fPipelineBuilder(pipelineBuilder)
524 , fScissor(scissor) {
525 fColorPOI = fPipelineBuilder->colorProcInfo(batch);
526 fCoveragePOI = fPipelineBuilder->coverageProcInfo(batch);
527 if (!target->setupDstReadIfNecessary(*fPipelineBuilder, fColorPOI, fCoveragePOI,
528 &fDstCopy, devBounds)) {
529 fPipelineBuilder = NULL;
530 }
531}
532
bsalomon@google.combcce8922013-03-25 15:38:39 +0000533///////////////////////////////////////////////////////////////////////////////
534
jvanverthe9c0fc62015-04-29 11:18:05 -0700535void GrShaderCaps::reset() {
536 fShaderDerivativeSupport = false;
537 fGeometryShaderSupport = false;
538 fPathRenderingSupport = false;
539 fDstReadInShaderSupport = false;
540 fDualSourceBlendingSupport = false;
cdalton0edea2c2015-05-21 08:27:44 -0700541 fMixedSamplesSupport = false;
jvanverthe9c0fc62015-04-29 11:18:05 -0700542
543 fShaderPrecisionVaries = false;
544}
545
546GrShaderCaps& GrShaderCaps::operator=(const GrShaderCaps& other) {
547 fShaderDerivativeSupport = other.fShaderDerivativeSupport;
548 fGeometryShaderSupport = other.fGeometryShaderSupport;
549 fPathRenderingSupport = other.fPathRenderingSupport;
550 fDstReadInShaderSupport = other.fDstReadInShaderSupport;
551 fDualSourceBlendingSupport = other.fDualSourceBlendingSupport;
cdalton0edea2c2015-05-21 08:27:44 -0700552 fMixedSamplesSupport = other.fMixedSamplesSupport;
jvanverthe9c0fc62015-04-29 11:18:05 -0700553
554 fShaderPrecisionVaries = other.fShaderPrecisionVaries;
555 for (int s = 0; s < kGrShaderTypeCount; ++s) {
556 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
557 fFloatPrecisions[s][p] = other.fFloatPrecisions[s][p];
558 }
559 }
560 return *this;
561}
562
563static const char* shader_type_to_string(GrShaderType type) {
564 switch (type) {
565 case kVertex_GrShaderType:
566 return "vertex";
567 case kGeometry_GrShaderType:
568 return "geometry";
569 case kFragment_GrShaderType:
570 return "fragment";
571 }
572 return "";
573}
574
575static const char* precision_to_string(GrSLPrecision p) {
576 switch (p) {
577 case kLow_GrSLPrecision:
578 return "low";
579 case kMedium_GrSLPrecision:
580 return "medium";
581 case kHigh_GrSLPrecision:
582 return "high";
583 }
584 return "";
585}
586
587SkString GrShaderCaps::dump() const {
588 SkString r;
589 static const char* gNY[] = { "NO", "YES" };
590 r.appendf("Shader Derivative Support : %s\n", gNY[fShaderDerivativeSupport]);
591 r.appendf("Geometry Shader Support : %s\n", gNY[fGeometryShaderSupport]);
592 r.appendf("Path Rendering Support : %s\n", gNY[fPathRenderingSupport]);
593 r.appendf("Dst Read In Shader Support : %s\n", gNY[fDstReadInShaderSupport]);
594 r.appendf("Dual Source Blending Support : %s\n", gNY[fDualSourceBlendingSupport]);
cdalton0edea2c2015-05-21 08:27:44 -0700595 r.appendf("Mixed Samples Support : %s\n", gNY[fMixedSamplesSupport]);
jvanverthe9c0fc62015-04-29 11:18:05 -0700596
597 r.appendf("Shader Float Precisions (varies: %s):\n", gNY[fShaderPrecisionVaries]);
598
599 for (int s = 0; s < kGrShaderTypeCount; ++s) {
600 GrShaderType shaderType = static_cast<GrShaderType>(s);
601 r.appendf("\t%s:\n", shader_type_to_string(shaderType));
602 for (int p = 0; p < kGrSLPrecisionCount; ++p) {
603 if (fFloatPrecisions[s][p].supported()) {
604 GrSLPrecision precision = static_cast<GrSLPrecision>(p);
605 r.appendf("\t\t%s: log_low: %d log_high: %d bits: %d\n",
606 precision_to_string(precision),
607 fFloatPrecisions[s][p].fLogRangeLow,
608 fFloatPrecisions[s][p].fLogRangeHigh,
609 fFloatPrecisions[s][p].fBits);
610 }
611 }
612 }
613
614 return r;
615}
616
617///////////////////////////////////////////////////////////////////////////////
618
bsalomon4b91f762015-05-19 09:29:46 -0700619void GrCaps::reset() {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000620 fMipMapSupport = false;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000621 fNPOTTextureTileSupport = false;
622 fTwoSidedStencilSupport = false;
623 fStencilWrapOpsSupport = false;
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +0000624 fDiscardRenderTargetSupport = false;
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000625 fReuseScratchTextures = true;
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000626 fGpuTracingSupport = false;
krajcevski786978162014-07-30 11:25:44 -0700627 fCompressedTexSubImageSupport = false;
bsalomond08ea5f2015-02-20 06:58:13 -0800628 fOversizedStencilSupport = false;
cdaltonfd4167d2015-04-21 11:45:56 -0700629 fTextureBarrierSupport = false;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000630
bsalomon63b21962014-11-05 07:05:34 -0800631 fUseDrawInsteadOfClear = false;
632
cdalton8917d622015-05-06 13:40:21 -0700633 fBlendEquationSupport = kBasic_BlendEquationSupport;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000634 fMapBufferFlags = kNone_MapFlags;
635
bsalomon@google.combcce8922013-03-25 15:38:39 +0000636 fMaxRenderTargetSize = 0;
637 fMaxTextureSize = 0;
638 fMaxSampleCount = 0;
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000639
640 memset(fConfigRenderSupport, 0, sizeof(fConfigRenderSupport));
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000641 memset(fConfigTextureSupport, 0, sizeof(fConfigTextureSupport));
bsalomon@google.combcce8922013-03-25 15:38:39 +0000642}
643
bsalomon4b91f762015-05-19 09:29:46 -0700644GrCaps& GrCaps::operator=(const GrCaps& other) {
commit-bot@chromium.org47442312013-12-19 16:18:01 +0000645 fMipMapSupport = other.fMipMapSupport;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000646 fNPOTTextureTileSupport = other.fNPOTTextureTileSupport;
647 fTwoSidedStencilSupport = other.fTwoSidedStencilSupport;
648 fStencilWrapOpsSupport = other.fStencilWrapOpsSupport;
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +0000649 fDiscardRenderTargetSupport = other.fDiscardRenderTargetSupport;
commit-bot@chromium.orgb8356522013-07-18 22:26:39 +0000650 fReuseScratchTextures = other.fReuseScratchTextures;
commit-bot@chromium.orga3baf3b2014-02-21 18:45:30 +0000651 fGpuTracingSupport = other.fGpuTracingSupport;
krajcevski786978162014-07-30 11:25:44 -0700652 fCompressedTexSubImageSupport = other.fCompressedTexSubImageSupport;
bsalomond08ea5f2015-02-20 06:58:13 -0800653 fOversizedStencilSupport = other.fOversizedStencilSupport;
cdaltonfd4167d2015-04-21 11:45:56 -0700654 fTextureBarrierSupport = other.fTextureBarrierSupport;
bsalomon@google.combcce8922013-03-25 15:38:39 +0000655
bsalomon63b21962014-11-05 07:05:34 -0800656 fUseDrawInsteadOfClear = other.fUseDrawInsteadOfClear;
657
cdalton8917d622015-05-06 13:40:21 -0700658 fBlendEquationSupport = other.fBlendEquationSupport;
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000659 fMapBufferFlags = other.fMapBufferFlags;
660
bsalomon@google.combcce8922013-03-25 15:38:39 +0000661 fMaxRenderTargetSize = other.fMaxRenderTargetSize;
662 fMaxTextureSize = other.fMaxTextureSize;
663 fMaxSampleCount = other.fMaxSampleCount;
664
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000665 memcpy(fConfigRenderSupport, other.fConfigRenderSupport, sizeof(fConfigRenderSupport));
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000666 memcpy(fConfigTextureSupport, other.fConfigTextureSupport, sizeof(fConfigTextureSupport));
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000667
bsalomon@google.combcce8922013-03-25 15:38:39 +0000668 return *this;
669}
670
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000671static SkString map_flags_to_string(uint32_t flags) {
672 SkString str;
bsalomon4b91f762015-05-19 09:29:46 -0700673 if (GrCaps::kNone_MapFlags == flags) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000674 str = "none";
675 } else {
bsalomon4b91f762015-05-19 09:29:46 -0700676 SkASSERT(GrCaps::kCanMap_MapFlag & flags);
677 SkDEBUGCODE(flags &= ~GrCaps::kCanMap_MapFlag);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000678 str = "can_map";
679
bsalomon4b91f762015-05-19 09:29:46 -0700680 if (GrCaps::kSubset_MapFlag & flags) {
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000681 str.append(" partial");
682 } else {
683 str.append(" full");
684 }
bsalomon4b91f762015-05-19 09:29:46 -0700685 SkDEBUGCODE(flags &= ~GrCaps::kSubset_MapFlag);
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000686 }
687 SkASSERT(0 == flags); // Make sure we handled all the flags.
688 return str;
689}
690
bsalomon4b91f762015-05-19 09:29:46 -0700691SkString GrCaps::dump() const {
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000692 SkString r;
bsalomon@google.com18c9c192011-09-22 21:01:31 +0000693 static const char* gNY[] = {"NO", "YES"};
bsalomon63b21962014-11-05 07:05:34 -0800694 r.appendf("MIP Map Support : %s\n", gNY[fMipMapSupport]);
695 r.appendf("NPOT Texture Tile Support : %s\n", gNY[fNPOTTextureTileSupport]);
696 r.appendf("Two Sided Stencil Support : %s\n", gNY[fTwoSidedStencilSupport]);
697 r.appendf("Stencil Wrap Ops Support : %s\n", gNY[fStencilWrapOpsSupport]);
bsalomon63b21962014-11-05 07:05:34 -0800698 r.appendf("Discard Render Target Support : %s\n", gNY[fDiscardRenderTargetSupport]);
699 r.appendf("Reuse Scratch Textures : %s\n", gNY[fReuseScratchTextures]);
700 r.appendf("Gpu Tracing Support : %s\n", gNY[fGpuTracingSupport]);
701 r.appendf("Compressed Update Support : %s\n", gNY[fCompressedTexSubImageSupport]);
bsalomond08ea5f2015-02-20 06:58:13 -0800702 r.appendf("Oversized Stencil Support : %s\n", gNY[fOversizedStencilSupport]);
cdaltonfd4167d2015-04-21 11:45:56 -0700703 r.appendf("Texture Barrier Support : %s\n", gNY[fTextureBarrierSupport]);
bsalomon63b21962014-11-05 07:05:34 -0800704 r.appendf("Draw Instead of Clear [workaround] : %s\n", gNY[fUseDrawInsteadOfClear]);
705
706 r.appendf("Max Texture Size : %d\n", fMaxTextureSize);
707 r.appendf("Max Render Target Size : %d\n", fMaxRenderTargetSize);
708 r.appendf("Max Sample Count : %d\n", fMaxSampleCount);
709
cdalton8917d622015-05-06 13:40:21 -0700710 static const char* kBlendEquationSupportNames[] = {
711 "Basic",
712 "Advanced",
713 "Advanced Coherent",
714 };
715 GR_STATIC_ASSERT(0 == kBasic_BlendEquationSupport);
716 GR_STATIC_ASSERT(1 == kAdvanced_BlendEquationSupport);
717 GR_STATIC_ASSERT(2 == kAdvancedCoherent_BlendEquationSupport);
718 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kBlendEquationSupportNames) == kLast_BlendEquationSupport + 1);
719
720 r.appendf("Blend Equation Support : %s\n",
721 kBlendEquationSupportNames[fBlendEquationSupport]);
bsalomon63b21962014-11-05 07:05:34 -0800722 r.appendf("Map Buffer Support : %s\n",
723 map_flags_to_string(fMapBufferFlags).c_str());
commit-bot@chromium.org160b4782014-05-05 12:32:37 +0000724
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000725 static const char* kConfigNames[] = {
726 "Unknown", // kUnknown_GrPixelConfig
727 "Alpha8", // kAlpha_8_GrPixelConfig,
728 "Index8", // kIndex_8_GrPixelConfig,
729 "RGB565", // kRGB_565_GrPixelConfig,
730 "RGBA444", // kRGBA_4444_GrPixelConfig,
731 "RGBA8888", // kRGBA_8888_GrPixelConfig,
732 "BGRA8888", // kBGRA_8888_GrPixelConfig,
jvanverthfa1e8a72014-12-22 08:31:49 -0800733 "SRGBA8888",// kSRGBA_8888_GrPixelConfig,
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000734 "ETC1", // kETC1_GrPixelConfig,
735 "LATC", // kLATC_GrPixelConfig,
krajcevski238b4562014-06-30 09:09:22 -0700736 "R11EAC", // kR11_EAC_GrPixelConfig,
krajcevski7ef21622014-07-16 15:21:13 -0700737 "ASTC12x12",// kASTC_12x12_GrPixelConfig,
jvanverth28f9c602014-12-05 13:06:35 -0800738 "RGBAFloat",// kRGBA_float_GrPixelConfig
739 "AlphaHalf",// kAlpha_half_GrPixelConfig
jvanverthfb5df432015-05-21 08:12:27 -0700740 "RGBAHalf", // kRGBA_half_GrPixelConfig
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000741 };
krajcevski7ef21622014-07-16 15:21:13 -0700742 GR_STATIC_ASSERT(0 == kUnknown_GrPixelConfig);
743 GR_STATIC_ASSERT(1 == kAlpha_8_GrPixelConfig);
744 GR_STATIC_ASSERT(2 == kIndex_8_GrPixelConfig);
745 GR_STATIC_ASSERT(3 == kRGB_565_GrPixelConfig);
746 GR_STATIC_ASSERT(4 == kRGBA_4444_GrPixelConfig);
747 GR_STATIC_ASSERT(5 == kRGBA_8888_GrPixelConfig);
748 GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig);
jvanverthfa1e8a72014-12-22 08:31:49 -0800749 GR_STATIC_ASSERT(7 == kSRGBA_8888_GrPixelConfig);
750 GR_STATIC_ASSERT(8 == kETC1_GrPixelConfig);
751 GR_STATIC_ASSERT(9 == kLATC_GrPixelConfig);
752 GR_STATIC_ASSERT(10 == kR11_EAC_GrPixelConfig);
753 GR_STATIC_ASSERT(11 == kASTC_12x12_GrPixelConfig);
754 GR_STATIC_ASSERT(12 == kRGBA_float_GrPixelConfig);
755 GR_STATIC_ASSERT(13 == kAlpha_half_GrPixelConfig);
jvanverthfb5df432015-05-21 08:12:27 -0700756 GR_STATIC_ASSERT(14 == kRGBA_half_GrPixelConfig);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000757 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kConfigNames) == kGrPixelConfigCnt);
758
commit-bot@chromium.org99017272013-11-08 18:45:27 +0000759 SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][0]);
760 SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][1]);
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000761
762 for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) {
763 r.appendf("%s is renderable: %s, with MSAA: %s\n",
764 kConfigNames[i],
765 gNY[fConfigRenderSupport[i][0]],
766 gNY[fConfigRenderSupport[i][1]]);
commit-bot@chromium.org73880512013-10-14 15:33:45 +0000767 }
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000768
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000769 SkASSERT(!fConfigTextureSupport[kUnknown_GrPixelConfig]);
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000770
commit-bot@chromium.org6e7ddaa2014-05-30 13:55:58 +0000771 for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) {
772 r.appendf("%s is uploadable to a texture: %s\n",
773 kConfigNames[i],
774 gNY[fConfigTextureSupport[i]]);
commit-bot@chromium.org42dc8132014-05-27 19:26:59 +0000775 }
776
commit-bot@chromium.org8b656c62013-11-21 15:23:15 +0000777 return r;
bsalomon@google.com18c9c192011-09-22 21:01:31 +0000778}
egdanielbc127a32014-09-19 12:07:43 -0700779
joshualitt2c93efe2014-11-06 12:57:13 -0800780///////////////////////////////////////////////////////////////////////////////////////////////////
781
egdaniel8dd688b2015-01-22 10:16:09 -0800782bool GrClipTarget::setupClip(GrPipelineBuilder* pipelineBuilder,
bsalomon6be6f7c2015-02-26 13:05:21 -0800783 GrPipelineBuilder::AutoRestoreFragmentProcessors* arfp,
egdaniel8dd688b2015-01-22 10:16:09 -0800784 GrPipelineBuilder::AutoRestoreStencil* ars,
joshualitt8059eb92014-12-29 15:10:07 -0800785 GrScissorState* scissorState,
786 const SkRect* devBounds) {
egdaniel8dd688b2015-01-22 10:16:09 -0800787 return fClipMaskManager.setupClipping(pipelineBuilder,
bsalomon6be6f7c2015-02-26 13:05:21 -0800788 arfp,
joshualitt2c93efe2014-11-06 12:57:13 -0800789 ars,
joshualitt9853cce2014-11-17 14:22:48 -0800790 scissorState,
joshualitt9853cce2014-11-17 14:22:48 -0800791 devBounds);
joshualitt2c93efe2014-11-06 12:57:13 -0800792}