epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * 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.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
joshualitt | c2893c5 | 2015-01-28 06:54:30 -0800 | [diff] [blame] | 9 | #include "GrDrawTarget.h" |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 10 | |
| 11 | #include "GrBatch.h" |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 12 | #include "GrBufferAllocPool.h" |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 13 | #include "GrContext.h" |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 14 | #include "GrDrawTargetCaps.h" |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 15 | #include "GrPath.h" |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 16 | #include "GrPipeline.h" |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 17 | #include "GrMemoryPool.h" |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 18 | #include "GrRenderTarget.h" |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 19 | #include "GrRenderTargetPriv.h" |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 20 | #include "GrSurfacePriv.h" |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 21 | #include "GrTemplates.h" |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 22 | #include "GrTexture.h" |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 23 | #include "GrVertexBuffer.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 24 | |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 25 | #include "SkStrokeRec.h" |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 26 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 27 | //////////////////////////////////////////////////////////////////////////////// |
| 28 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 29 | GrDrawTarget::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 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 40 | if (di.fDevBounds) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 41 | SkASSERT(di.fDevBounds == &di.fDevBoundsStorage); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 42 | fDevBoundsStorage = di.fDevBoundsStorage; |
| 43 | fDevBounds = &fDevBoundsStorage; |
| 44 | } else { |
| 45 | fDevBounds = NULL; |
| 46 | } |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 47 | |
joshualitt | 7eb8c7b | 2014-11-18 14:24:27 -0800 | [diff] [blame] | 48 | this->setVertexBuffer(di.vertexBuffer()); |
| 49 | this->setIndexBuffer(di.indexBuffer()); |
| 50 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 51 | return *this; |
| 52 | } |
| 53 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 54 | //////////////////////////////////////////////////////////////////////////////// |
| 55 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 56 | #define DEBUG_INVAL_BUFFER 0xdeadcafe |
| 57 | #define DEBUG_INVAL_START_IDX -1 |
| 58 | |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 59 | GrDrawTarget::GrDrawTarget(GrContext* context, |
| 60 | GrVertexBufferAllocPool* vpool, |
| 61 | GrIndexBufferAllocPool* ipool) |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 62 | : fContext(context) |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 63 | , fCaps(SkRef(context->getGpu()->caps())) |
| 64 | , fGpuTraceMarkerCount(0) |
| 65 | , fVertexPool(vpool) |
| 66 | , fIndexPool(ipool) |
| 67 | , fFlushing(false) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 68 | SkASSERT(context); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | //////////////////////////////////////////////////////////////////////////////// |
| 72 | |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 73 | bool GrDrawTarget::setupDstReadIfNecessary(const GrPipelineBuilder& pipelineBuilder, |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 74 | const GrProcOptInfo& colorPOI, |
| 75 | const GrProcOptInfo& coveragePOI, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 76 | GrDeviceCoordTexture* dstCopy, |
| 77 | const SkRect* drawBounds) { |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 78 | if (!pipelineBuilder.willXPNeedDstCopy(*this->caps(), colorPOI, coveragePOI)) { |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 79 | return true; |
| 80 | } |
cdalton | 9954bc3 | 2015-04-29 14:17:00 -0700 | [diff] [blame] | 81 | |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 82 | GrRenderTarget* rt = pipelineBuilder.getRenderTarget(); |
cdalton | 9954bc3 | 2015-04-29 14:17:00 -0700 | [diff] [blame] | 83 | |
| 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; |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 95 | pipelineBuilder.clip().getConservativeBounds(rt, ©Rect); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 96 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 97 | if (drawBounds) { |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 98 | SkIRect drawIBounds; |
| 99 | drawBounds->roundOut(&drawIBounds); |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 100 | if (!copyRect.intersect(drawIBounds)) { |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 101 | #ifdef SK_DEBUG |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 102 | SkDebugf("Missed an early reject. Bailing on draw from setupDstReadIfNecessary.\n"); |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 103 | #endif |
| 104 | return false; |
| 105 | } |
| 106 | } else { |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 107 | #ifdef SK_DEBUG |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 108 | //SkDebugf("No dev bounds when dst copy is made.\n"); |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 109 | #endif |
| 110 | } |
skia.committer@gmail.com | 05a2ee0 | 2013-04-02 07:01:34 +0000 | [diff] [blame] | 111 | |
commit-bot@chromium.org | 63150af | 2013-04-11 22:00:22 +0000 | [diff] [blame] | 112 | // 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. |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 114 | GrSurfaceDesc desc; |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 115 | 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.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 122 | desc.fWidth = copyRect.width(); |
| 123 | desc.fHeight = copyRect.height(); |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 124 | |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame^] | 125 | SkAutoTUnref<GrTexture> copy(fContext->textureProvider()->refScratchTexture(desc, |
| 126 | GrTextureProvider::kApprox_ScratchTexMatch)); |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 127 | |
bsalomon | e305973 | 2014-10-14 11:47:22 -0700 | [diff] [blame] | 128 | if (!copy) { |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 129 | SkDebugf("Failed to create temporary copy of destination texture.\n"); |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 130 | return false; |
| 131 | } |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 132 | SkIPoint dstPoint = {0, 0}; |
bsalomon | e305973 | 2014-10-14 11:47:22 -0700 | [diff] [blame] | 133 | if (this->copySurface(copy, rt, copyRect, dstPoint)) { |
| 134 | dstCopy->setTexture(copy); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 135 | dstCopy->setOffset(copyRect.fLeft, copyRect.fTop); |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 136 | return true; |
| 137 | } else { |
| 138 | return false; |
| 139 | } |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 140 | } |
| 141 | |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 142 | void GrDrawTarget::reset() { |
| 143 | fVertexPool->reset(); |
| 144 | fIndexPool->reset(); |
| 145 | |
| 146 | this->onReset(); |
| 147 | } |
| 148 | |
| 149 | void 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 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 165 | void 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; |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 173 | GrPipelineBuilder::AutoRestoreFragmentProcessors arfp; |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 174 | GrPipelineBuilder::AutoRestoreStencil ars; |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 175 | if (!this->setupClip(pipelineBuilder, &arfp, &ars, &scissorState, devBounds)) { |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 176 | return; |
| 177 | } |
| 178 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 179 | GrDrawTarget::PipelineInfo pipelineInfo(pipelineBuilder, &scissorState, batch, devBounds, this); |
| 180 | if (pipelineInfo.mustSkipDraw()) { |
| 181 | return; |
| 182 | } |
| 183 | |
| 184 | this->onDrawBatch(batch, pipelineInfo); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 185 | } |
| 186 | |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 187 | static 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 | |
| 196 | static 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 | |
| 205 | void GrDrawTarget::getPathStencilSettingsForFilltype(GrPathRendering::FillType fill, |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 206 | const GrStencilAttachment* sb, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 207 | 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 | } |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 219 | this->clipMaskManager()->adjustPathStencilParams(sb, outStencilSettings); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 220 | } |
| 221 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 222 | void GrDrawTarget::stencilPath(GrPipelineBuilder* pipelineBuilder, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 223 | const GrPathProcessor* pathProc, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 224 | const GrPath* path, |
| 225 | GrPathRendering::FillType fill) { |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 226 | // TODO: extract portions of checkDraw that are relevant to path stenciling. |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 227 | SkASSERT(path); |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 228 | SkASSERT(this->caps()->shaderCaps()->pathRenderingSupport()); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 229 | SkASSERT(pipelineBuilder); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 230 | |
| 231 | // Setup clip |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 232 | GrScissorState scissorState; |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 233 | GrPipelineBuilder::AutoRestoreFragmentProcessors arfp; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 234 | GrPipelineBuilder::AutoRestoreStencil ars; |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 235 | if (!this->setupClip(pipelineBuilder, &arfp, &ars, &scissorState, NULL)) { |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 236 | return; |
| 237 | } |
| 238 | |
| 239 | // set stencil settings for path |
| 240 | GrStencilSettings stencilSettings; |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 241 | GrRenderTarget* rt = pipelineBuilder->getRenderTarget(); |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 242 | GrStencilAttachment* sb = rt->renderTargetPriv().attachStencilAttachment(); |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 243 | this->getPathStencilSettingsForFilltype(fill, sb, &stencilSettings); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 244 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 245 | this->onStencilPath(*pipelineBuilder, pathProc, path, scissorState, stencilSettings); |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 246 | } |
| 247 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 248 | void GrDrawTarget::drawPath(GrPipelineBuilder* pipelineBuilder, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 249 | const GrPathProcessor* pathProc, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 250 | const GrPath* path, |
| 251 | GrPathRendering::FillType fill) { |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 252 | // TODO: extract portions of checkDraw that are relevant to path rendering. |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 253 | SkASSERT(path); |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 254 | SkASSERT(this->caps()->shaderCaps()->pathRenderingSupport()); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 255 | SkASSERT(pipelineBuilder); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 256 | |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 257 | SkRect devBounds = path->getBounds(); |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 258 | pathProc->viewMatrix().mapRect(&devBounds); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 259 | |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 260 | // Setup clip |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 261 | GrScissorState scissorState; |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 262 | GrPipelineBuilder::AutoRestoreFragmentProcessors arfp; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 263 | GrPipelineBuilder::AutoRestoreStencil ars; |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 264 | if (!this->setupClip(pipelineBuilder, &arfp, &ars, &scissorState, &devBounds)) { |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 265 | return; |
| 266 | } |
| 267 | |
| 268 | // set stencil settings for path |
| 269 | GrStencilSettings stencilSettings; |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 270 | GrRenderTarget* rt = pipelineBuilder->getRenderTarget(); |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 271 | GrStencilAttachment* sb = rt->renderTargetPriv().attachStencilAttachment(); |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 272 | this->getPathStencilSettingsForFilltype(fill, sb, &stencilSettings); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 273 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 274 | 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.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 281 | } |
| 282 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 283 | void GrDrawTarget::drawPaths(GrPipelineBuilder* pipelineBuilder, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 284 | const GrPathProcessor* pathProc, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 285 | const GrPathRange* pathRange, |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 286 | const void* indices, |
| 287 | PathIndexType indexType, |
| 288 | const float transformValues[], |
| 289 | PathTransformType transformType, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 290 | int count, |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 291 | GrPathRendering::FillType fill) { |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 292 | SkASSERT(this->caps()->shaderCaps()->pathRenderingSupport()); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 293 | SkASSERT(pathRange); |
| 294 | SkASSERT(indices); |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 295 | SkASSERT(0 == reinterpret_cast<long>(indices) % GrPathRange::PathIndexSizeInBytes(indexType)); |
| 296 | SkASSERT(transformValues); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 297 | SkASSERT(pipelineBuilder); |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 298 | |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 299 | // Setup clip |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 300 | GrScissorState scissorState; |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 301 | GrPipelineBuilder::AutoRestoreFragmentProcessors arfp; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 302 | GrPipelineBuilder::AutoRestoreStencil ars; |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 303 | |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 304 | if (!this->setupClip(pipelineBuilder, &arfp, &ars, &scissorState, NULL)) { |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 305 | return; |
| 306 | } |
| 307 | |
| 308 | // set stencil settings for path |
| 309 | GrStencilSettings stencilSettings; |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 310 | GrRenderTarget* rt = pipelineBuilder->getRenderTarget(); |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 311 | GrStencilAttachment* sb = rt->renderTargetPriv().attachStencilAttachment(); |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 312 | this->getPathStencilSettingsForFilltype(fill, sb, &stencilSettings); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 313 | |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 314 | // Don't compute a bounding box for dst copy texture, we'll opt |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 315 | // 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. |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 318 | 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.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 325 | } |
| 326 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 327 | void GrDrawTarget::clear(const SkIRect* rect, |
| 328 | GrColor color, |
| 329 | bool canIgnoreRect, |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 330 | 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 | } |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 341 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 342 | GrPipelineBuilder pipelineBuilder; |
| 343 | pipelineBuilder.setRenderTarget(renderTarget); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 344 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 345 | this->drawSimpleRect(&pipelineBuilder, color, SkMatrix::I(), *rect); |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 346 | } else { |
| 347 | this->onClear(rect, color, canIgnoreRect, renderTarget); |
| 348 | } |
| 349 | } |
| 350 | |
egdaniel | 3eee383 | 2014-06-18 13:09:11 -0700 | [diff] [blame] | 351 | typedef GrTraceMarkerSet::Iter TMIter; |
| 352 | void 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 | |
| 362 | void 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 | |
| 374 | void GrDrawTarget::addGpuTraceMarker(const GrGpuTraceMarker* marker) { |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 375 | if (this->caps()->gpuTracingSupport()) { |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 376 | SkASSERT(fGpuTraceMarkerCount >= 0); |
| 377 | this->fActiveTraceMarkers.add(*marker); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 378 | ++fGpuTraceMarkerCount; |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 379 | } |
| 380 | } |
| 381 | |
egdaniel | 3eee383 | 2014-06-18 13:09:11 -0700 | [diff] [blame] | 382 | void GrDrawTarget::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 383 | if (this->caps()->gpuTracingSupport()) { |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 384 | SkASSERT(fGpuTraceMarkerCount >= 1); |
| 385 | this->fActiveTraceMarkers.remove(*marker); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 386 | --fGpuTraceMarkerCount; |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 387 | } |
| 388 | } |
| 389 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 390 | //////////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 391 | |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 392 | namespace { |
| 393 | // returns true if the read/written rect intersects the src/dst and false if not. |
| 394 | bool clip_srcrect_and_dstpoint(const GrSurface* dst, |
| 395 | const GrSurface* src, |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 396 | const SkIRect& srcRect, |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 397 | const SkIPoint& dstPoint, |
| 398 | SkIRect* clippedSrcRect, |
| 399 | SkIPoint* clippedDstPoint) { |
| 400 | *clippedSrcRect = srcRect; |
| 401 | *clippedDstPoint = dstPoint; |
skia.committer@gmail.com | a9493a3 | 2013-04-04 07:01:12 +0000 | [diff] [blame] | 402 | |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 403 | // 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.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 407 | } |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 408 | if (clippedDstPoint->fX < 0) { |
| 409 | clippedSrcRect->fLeft -= clippedDstPoint->fX; |
| 410 | clippedDstPoint->fX = 0; |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 411 | } |
| 412 | |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 413 | // 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.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 417 | } |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 418 | if (clippedDstPoint->fY < 0) { |
| 419 | clippedSrcRect->fTop -= clippedDstPoint->fY; |
| 420 | clippedDstPoint->fY = 0; |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 421 | } |
skia.committer@gmail.com | a9493a3 | 2013-04-04 07:01:12 +0000 | [diff] [blame] | 422 | |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 423 | // clip the right edge to the src and dst bounds. |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 424 | if (clippedSrcRect->fRight > src->width()) { |
| 425 | clippedSrcRect->fRight = src->width(); |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 426 | } |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 427 | if (clippedDstPoint->fX + clippedSrcRect->width() > dst->width()) { |
| 428 | clippedSrcRect->fRight = clippedSrcRect->fLeft + dst->width() - clippedDstPoint->fX; |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | // clip the bottom edge to the src and dst bounds. |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 432 | if (clippedSrcRect->fBottom > src->height()) { |
| 433 | clippedSrcRect->fBottom = src->height(); |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 434 | } |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 435 | if (clippedDstPoint->fY + clippedSrcRect->height() > dst->height()) { |
| 436 | clippedSrcRect->fBottom = clippedSrcRect->fTop + dst->height() - clippedDstPoint->fY; |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 437 | } |
skia.committer@gmail.com | a9493a3 | 2013-04-04 07:01:12 +0000 | [diff] [blame] | 438 | |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 439 | // The above clipping steps may have inverted the rect if it didn't intersect either the src or |
| 440 | // dst bounds. |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 441 | return !clippedSrcRect->isEmpty(); |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | bool GrDrawTarget::copySurface(GrSurface* dst, |
| 446 | GrSurface* src, |
| 447 | const SkIRect& srcRect, |
| 448 | const SkIPoint& dstPoint) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 449 | SkASSERT(dst); |
| 450 | SkASSERT(src); |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 451 | |
| 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.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 461 | return true; |
| 462 | } |
| 463 | |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 464 | if (this->getGpu()->canCopySurface(dst, src, clippedSrcRect, clippedDstPoint)) { |
| 465 | this->onCopySurface(dst, src, clippedSrcRect, clippedDstPoint); |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 466 | return true; |
joshualitt | a702415 | 2014-11-03 14:16:35 -0800 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | GrRenderTarget* rt = dst->asRenderTarget(); |
| 470 | GrTexture* tex = src->asTexture(); |
| 471 | |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 472 | if ((dst == src) || !rt || !tex) { |
| 473 | return false; |
| 474 | } |
| 475 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 476 | GrPipelineBuilder pipelineBuilder; |
| 477 | pipelineBuilder.setRenderTarget(rt); |
joshualitt | a702415 | 2014-11-03 14:16:35 -0800 | [diff] [blame] | 478 | SkMatrix matrix; |
| 479 | matrix.setTranslate(SkIntToScalar(clippedSrcRect.fLeft - clippedDstPoint.fX), |
| 480 | SkIntToScalar(clippedSrcRect.fTop - clippedDstPoint.fY)); |
| 481 | matrix.postIDiv(tex->width(), tex->height()); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 482 | pipelineBuilder.addColorTextureProcessor(tex, matrix); |
joshualitt | a702415 | 2014-11-03 14:16:35 -0800 | [diff] [blame] | 483 | SkIRect dstRect = SkIRect::MakeXYWH(clippedDstPoint.fX, |
| 484 | clippedDstPoint.fY, |
| 485 | clippedSrcRect.width(), |
| 486 | clippedSrcRect.height()); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 487 | this->drawSimpleRect(&pipelineBuilder, GrColor_WHITE, SkMatrix::I(), dstRect); |
joshualitt | a702415 | 2014-11-03 14:16:35 -0800 | [diff] [blame] | 488 | return true; |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 489 | } |
| 490 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 491 | bool GrDrawTarget::canCopySurface(const GrSurface* dst, |
| 492 | const GrSurface* src, |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 493 | const SkIRect& srcRect, |
| 494 | const SkIPoint& dstPoint) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 495 | SkASSERT(dst); |
| 496 | SkASSERT(src); |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 497 | |
| 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 | } |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 509 | return ((dst != src) && dst->asRenderTarget() && src->asTexture()) || |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 510 | this->getGpu()->canCopySurface(dst, src, clippedSrcRect, clippedDstPoint); |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 511 | } |
| 512 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 513 | void 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 | |
| 524 | GrDrawTarget::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 | |
| 539 | GrDrawTarget::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.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 554 | /////////////////////////////////////////////////////////////////////////////// |
| 555 | |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 556 | void GrShaderCaps::reset() { |
| 557 | fShaderDerivativeSupport = false; |
| 558 | fGeometryShaderSupport = false; |
| 559 | fPathRenderingSupport = false; |
| 560 | fDstReadInShaderSupport = false; |
| 561 | fDualSourceBlendingSupport = false; |
| 562 | |
| 563 | fShaderPrecisionVaries = false; |
| 564 | } |
| 565 | |
| 566 | GrShaderCaps& 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 | |
| 582 | static 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 | |
| 594 | static 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 | |
| 606 | SkString 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.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 637 | void GrDrawTargetCaps::reset() { |
commit-bot@chromium.org | 4744231 | 2013-12-19 16:18:01 +0000 | [diff] [blame] | 638 | fMipMapSupport = false; |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 639 | fNPOTTextureTileSupport = false; |
| 640 | fTwoSidedStencilSupport = false; |
| 641 | fStencilWrapOpsSupport = false; |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 642 | fDiscardRenderTargetSupport = false; |
commit-bot@chromium.org | b835652 | 2013-07-18 22:26:39 +0000 | [diff] [blame] | 643 | fReuseScratchTextures = true; |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 644 | fGpuTracingSupport = false; |
krajcevski | 78697816 | 2014-07-30 11:25:44 -0700 | [diff] [blame] | 645 | fCompressedTexSubImageSupport = false; |
bsalomon | d08ea5f | 2015-02-20 06:58:13 -0800 | [diff] [blame] | 646 | fOversizedStencilSupport = false; |
cdalton | fd4167d | 2015-04-21 11:45:56 -0700 | [diff] [blame] | 647 | fTextureBarrierSupport = false; |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 648 | |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 649 | fUseDrawInsteadOfClear = false; |
| 650 | |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 651 | fMapBufferFlags = kNone_MapFlags; |
| 652 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 653 | fMaxRenderTargetSize = 0; |
| 654 | fMaxTextureSize = 0; |
| 655 | fMaxSampleCount = 0; |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 656 | |
| 657 | memset(fConfigRenderSupport, 0, sizeof(fConfigRenderSupport)); |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 658 | memset(fConfigTextureSupport, 0, sizeof(fConfigTextureSupport)); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 659 | } |
| 660 | |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 661 | GrDrawTargetCaps& GrDrawTargetCaps::operator=(const GrDrawTargetCaps& other) { |
commit-bot@chromium.org | 4744231 | 2013-12-19 16:18:01 +0000 | [diff] [blame] | 662 | fMipMapSupport = other.fMipMapSupport; |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 663 | fNPOTTextureTileSupport = other.fNPOTTextureTileSupport; |
| 664 | fTwoSidedStencilSupport = other.fTwoSidedStencilSupport; |
| 665 | fStencilWrapOpsSupport = other.fStencilWrapOpsSupport; |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 666 | fDiscardRenderTargetSupport = other.fDiscardRenderTargetSupport; |
commit-bot@chromium.org | b835652 | 2013-07-18 22:26:39 +0000 | [diff] [blame] | 667 | fReuseScratchTextures = other.fReuseScratchTextures; |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 668 | fGpuTracingSupport = other.fGpuTracingSupport; |
krajcevski | 78697816 | 2014-07-30 11:25:44 -0700 | [diff] [blame] | 669 | fCompressedTexSubImageSupport = other.fCompressedTexSubImageSupport; |
bsalomon | d08ea5f | 2015-02-20 06:58:13 -0800 | [diff] [blame] | 670 | fOversizedStencilSupport = other.fOversizedStencilSupport; |
cdalton | fd4167d | 2015-04-21 11:45:56 -0700 | [diff] [blame] | 671 | fTextureBarrierSupport = other.fTextureBarrierSupport; |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 672 | |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 673 | fUseDrawInsteadOfClear = other.fUseDrawInsteadOfClear; |
| 674 | |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 675 | fMapBufferFlags = other.fMapBufferFlags; |
| 676 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 677 | fMaxRenderTargetSize = other.fMaxRenderTargetSize; |
| 678 | fMaxTextureSize = other.fMaxTextureSize; |
| 679 | fMaxSampleCount = other.fMaxSampleCount; |
| 680 | |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 681 | memcpy(fConfigRenderSupport, other.fConfigRenderSupport, sizeof(fConfigRenderSupport)); |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 682 | memcpy(fConfigTextureSupport, other.fConfigTextureSupport, sizeof(fConfigTextureSupport)); |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 683 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 684 | return *this; |
| 685 | } |
| 686 | |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 687 | static 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.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 707 | SkString GrDrawTargetCaps::dump() const { |
| 708 | SkString r; |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 709 | static const char* gNY[] = {"NO", "YES"}; |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 710 | 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]); |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 714 | 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]); |
bsalomon | d08ea5f | 2015-02-20 06:58:13 -0800 | [diff] [blame] | 718 | r.appendf("Oversized Stencil Support : %s\n", gNY[fOversizedStencilSupport]); |
cdalton | fd4167d | 2015-04-21 11:45:56 -0700 | [diff] [blame] | 719 | r.appendf("Texture Barrier Support : %s\n", gNY[fTextureBarrierSupport]); |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 720 | 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.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 728 | |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 729 | 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, |
jvanverth | fa1e8a7 | 2014-12-22 08:31:49 -0800 | [diff] [blame] | 737 | "SRGBA8888",// kSRGBA_8888_GrPixelConfig, |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 738 | "ETC1", // kETC1_GrPixelConfig, |
| 739 | "LATC", // kLATC_GrPixelConfig, |
krajcevski | 238b456 | 2014-06-30 09:09:22 -0700 | [diff] [blame] | 740 | "R11EAC", // kR11_EAC_GrPixelConfig, |
krajcevski | 7ef2162 | 2014-07-16 15:21:13 -0700 | [diff] [blame] | 741 | "ASTC12x12",// kASTC_12x12_GrPixelConfig, |
jvanverth | 28f9c60 | 2014-12-05 13:06:35 -0800 | [diff] [blame] | 742 | "RGBAFloat",// kRGBA_float_GrPixelConfig |
| 743 | "AlphaHalf",// kAlpha_half_GrPixelConfig |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 744 | }; |
krajcevski | 7ef2162 | 2014-07-16 15:21:13 -0700 | [diff] [blame] | 745 | 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); |
jvanverth | fa1e8a7 | 2014-12-22 08:31:49 -0800 | [diff] [blame] | 752 | 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.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 759 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kConfigNames) == kGrPixelConfigCnt); |
| 760 | |
commit-bot@chromium.org | 9901727 | 2013-11-08 18:45:27 +0000 | [diff] [blame] | 761 | SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][0]); |
| 762 | SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][1]); |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 763 | |
| 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.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 769 | } |
commit-bot@chromium.org | 42dc813 | 2014-05-27 19:26:59 +0000 | [diff] [blame] | 770 | |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 771 | SkASSERT(!fConfigTextureSupport[kUnknown_GrPixelConfig]); |
commit-bot@chromium.org | 42dc813 | 2014-05-27 19:26:59 +0000 | [diff] [blame] | 772 | |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 773 | 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.org | 42dc813 | 2014-05-27 19:26:59 +0000 | [diff] [blame] | 777 | } |
| 778 | |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 779 | return r; |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 780 | } |
egdaniel | bc127a3 | 2014-09-19 12:07:43 -0700 | [diff] [blame] | 781 | |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 782 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 783 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 784 | bool GrClipTarget::setupClip(GrPipelineBuilder* pipelineBuilder, |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 785 | GrPipelineBuilder::AutoRestoreFragmentProcessors* arfp, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 786 | GrPipelineBuilder::AutoRestoreStencil* ars, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 787 | GrScissorState* scissorState, |
| 788 | const SkRect* devBounds) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 789 | return fClipMaskManager.setupClipping(pipelineBuilder, |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 790 | arfp, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 791 | ars, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 792 | scissorState, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 793 | devBounds); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 794 | } |