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 | } |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 81 | SkIRect copyRect; |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 82 | GrRenderTarget* rt = pipelineBuilder.getRenderTarget(); |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 83 | pipelineBuilder.clip().getConservativeBounds(rt, ©Rect); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 84 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 85 | if (drawBounds) { |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 86 | SkIRect drawIBounds; |
| 87 | drawBounds->roundOut(&drawIBounds); |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 88 | if (!copyRect.intersect(drawIBounds)) { |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 89 | #ifdef SK_DEBUG |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 90 | 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] | 91 | #endif |
| 92 | return false; |
| 93 | } |
| 94 | } else { |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 95 | #ifdef SK_DEBUG |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 96 | //SkDebugf("No dev bounds when dst copy is made.\n"); |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 97 | #endif |
| 98 | } |
skia.committer@gmail.com | 05a2ee0 | 2013-04-02 07:01:34 +0000 | [diff] [blame] | 99 | |
commit-bot@chromium.org | 63150af | 2013-04-11 22:00:22 +0000 | [diff] [blame] | 100 | // MSAA consideration: When there is support for reading MSAA samples in the shader we could |
| 101 | // have per-sample dst values by making the copy multisampled. |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 102 | GrSurfaceDesc desc; |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame^] | 103 | if (!this->getGpu()->initCopySurfaceDstDesc(rt, &desc)) { |
| 104 | desc.fOrigin = kDefault_GrSurfaceOrigin; |
| 105 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 106 | desc.fConfig = rt->config(); |
| 107 | } |
| 108 | |
| 109 | |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 110 | desc.fWidth = copyRect.width(); |
| 111 | desc.fHeight = copyRect.height(); |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 112 | |
bsalomon | e305973 | 2014-10-14 11:47:22 -0700 | [diff] [blame] | 113 | SkAutoTUnref<GrTexture> copy( |
| 114 | fContext->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch)); |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 115 | |
bsalomon | e305973 | 2014-10-14 11:47:22 -0700 | [diff] [blame] | 116 | if (!copy) { |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 117 | SkDebugf("Failed to create temporary copy of destination texture.\n"); |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 118 | return false; |
| 119 | } |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 120 | SkIPoint dstPoint = {0, 0}; |
bsalomon | e305973 | 2014-10-14 11:47:22 -0700 | [diff] [blame] | 121 | if (this->copySurface(copy, rt, copyRect, dstPoint)) { |
| 122 | dstCopy->setTexture(copy); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 123 | dstCopy->setOffset(copyRect.fLeft, copyRect.fTop); |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 124 | return true; |
| 125 | } else { |
| 126 | return false; |
| 127 | } |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 128 | } |
| 129 | |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame^] | 130 | void GrDrawTarget::reset() { |
| 131 | fVertexPool->reset(); |
| 132 | fIndexPool->reset(); |
| 133 | |
| 134 | this->onReset(); |
| 135 | } |
| 136 | |
| 137 | void GrDrawTarget::flush() { |
| 138 | if (fFlushing) { |
| 139 | return; |
| 140 | } |
| 141 | fFlushing = true; |
| 142 | |
| 143 | this->getGpu()->saveActiveTraceMarkers(); |
| 144 | |
| 145 | this->onFlush(); |
| 146 | |
| 147 | this->getGpu()->restoreActiveTraceMarkers(); |
| 148 | |
| 149 | fFlushing = false; |
| 150 | this->reset(); |
| 151 | } |
| 152 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 153 | void GrDrawTarget::drawBatch(GrPipelineBuilder* pipelineBuilder, |
| 154 | GrBatch* batch, |
| 155 | const SkRect* devBounds) { |
| 156 | SkASSERT(pipelineBuilder); |
| 157 | // TODO some kind of checkdraw, but not at this level |
| 158 | |
| 159 | // Setup clip |
| 160 | GrScissorState scissorState; |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 161 | GrPipelineBuilder::AutoRestoreFragmentProcessors arfp; |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 162 | GrPipelineBuilder::AutoRestoreStencil ars; |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 163 | if (!this->setupClip(pipelineBuilder, &arfp, &ars, &scissorState, devBounds)) { |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 164 | return; |
| 165 | } |
| 166 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 167 | GrDrawTarget::PipelineInfo pipelineInfo(pipelineBuilder, &scissorState, batch, devBounds, this); |
| 168 | if (pipelineInfo.mustSkipDraw()) { |
| 169 | return; |
| 170 | } |
| 171 | |
| 172 | this->onDrawBatch(batch, pipelineInfo); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 173 | } |
| 174 | |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 175 | static const GrStencilSettings& winding_path_stencil_settings() { |
| 176 | GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, |
| 177 | kIncClamp_StencilOp, |
| 178 | kIncClamp_StencilOp, |
| 179 | kAlwaysIfInClip_StencilFunc, |
| 180 | 0xFFFF, 0xFFFF, 0xFFFF); |
| 181 | return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); |
| 182 | } |
| 183 | |
| 184 | static const GrStencilSettings& even_odd_path_stencil_settings() { |
| 185 | GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, |
| 186 | kInvert_StencilOp, |
| 187 | kInvert_StencilOp, |
| 188 | kAlwaysIfInClip_StencilFunc, |
| 189 | 0xFFFF, 0xFFFF, 0xFFFF); |
| 190 | return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); |
| 191 | } |
| 192 | |
| 193 | void GrDrawTarget::getPathStencilSettingsForFilltype(GrPathRendering::FillType fill, |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 194 | const GrStencilAttachment* sb, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 195 | GrStencilSettings* outStencilSettings) { |
| 196 | |
| 197 | switch (fill) { |
| 198 | default: |
| 199 | SkFAIL("Unexpected path fill."); |
| 200 | case GrPathRendering::kWinding_FillType: |
| 201 | *outStencilSettings = winding_path_stencil_settings(); |
| 202 | break; |
| 203 | case GrPathRendering::kEvenOdd_FillType: |
| 204 | *outStencilSettings = even_odd_path_stencil_settings(); |
| 205 | break; |
| 206 | } |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 207 | this->clipMaskManager()->adjustPathStencilParams(sb, outStencilSettings); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 208 | } |
| 209 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 210 | void GrDrawTarget::stencilPath(GrPipelineBuilder* pipelineBuilder, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 211 | const GrPathProcessor* pathProc, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 212 | const GrPath* path, |
| 213 | GrPathRendering::FillType fill) { |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 214 | // TODO: extract portions of checkDraw that are relevant to path stenciling. |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 215 | SkASSERT(path); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 216 | SkASSERT(this->caps()->pathRenderingSupport()); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 217 | SkASSERT(pipelineBuilder); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 218 | |
| 219 | // Setup clip |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 220 | GrScissorState scissorState; |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 221 | GrPipelineBuilder::AutoRestoreFragmentProcessors arfp; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 222 | GrPipelineBuilder::AutoRestoreStencil ars; |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 223 | if (!this->setupClip(pipelineBuilder, &arfp, &ars, &scissorState, NULL)) { |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 224 | return; |
| 225 | } |
| 226 | |
| 227 | // set stencil settings for path |
| 228 | GrStencilSettings stencilSettings; |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 229 | GrRenderTarget* rt = pipelineBuilder->getRenderTarget(); |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 230 | GrStencilAttachment* sb = rt->renderTargetPriv().attachStencilAttachment(); |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 231 | this->getPathStencilSettingsForFilltype(fill, sb, &stencilSettings); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 232 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 233 | this->onStencilPath(*pipelineBuilder, pathProc, path, scissorState, stencilSettings); |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 234 | } |
| 235 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 236 | void GrDrawTarget::drawPath(GrPipelineBuilder* pipelineBuilder, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 237 | const GrPathProcessor* pathProc, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 238 | const GrPath* path, |
| 239 | GrPathRendering::FillType fill) { |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 240 | // TODO: extract portions of checkDraw that are relevant to path rendering. |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 241 | SkASSERT(path); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 242 | SkASSERT(this->caps()->pathRenderingSupport()); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 243 | SkASSERT(pipelineBuilder); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 244 | |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 245 | SkRect devBounds = path->getBounds(); |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 246 | pathProc->viewMatrix().mapRect(&devBounds); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 247 | |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 248 | // Setup clip |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 249 | GrScissorState scissorState; |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 250 | GrPipelineBuilder::AutoRestoreFragmentProcessors arfp; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 251 | GrPipelineBuilder::AutoRestoreStencil ars; |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 252 | if (!this->setupClip(pipelineBuilder, &arfp, &ars, &scissorState, &devBounds)) { |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 253 | return; |
| 254 | } |
| 255 | |
| 256 | // set stencil settings for path |
| 257 | GrStencilSettings stencilSettings; |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 258 | GrRenderTarget* rt = pipelineBuilder->getRenderTarget(); |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 259 | GrStencilAttachment* sb = rt->renderTargetPriv().attachStencilAttachment(); |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 260 | this->getPathStencilSettingsForFilltype(fill, sb, &stencilSettings); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 261 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 262 | GrDrawTarget::PipelineInfo pipelineInfo(pipelineBuilder, &scissorState, pathProc, &devBounds, |
| 263 | this); |
| 264 | if (pipelineInfo.mustSkipDraw()) { |
| 265 | return; |
| 266 | } |
| 267 | |
| 268 | this->onDrawPath(pathProc, path, stencilSettings, pipelineInfo); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 269 | } |
| 270 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 271 | void GrDrawTarget::drawPaths(GrPipelineBuilder* pipelineBuilder, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 272 | const GrPathProcessor* pathProc, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 273 | const GrPathRange* pathRange, |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 274 | const void* indices, |
| 275 | PathIndexType indexType, |
| 276 | const float transformValues[], |
| 277 | PathTransformType transformType, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 278 | int count, |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 279 | GrPathRendering::FillType fill) { |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 280 | SkASSERT(this->caps()->pathRenderingSupport()); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 281 | SkASSERT(pathRange); |
| 282 | SkASSERT(indices); |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 283 | SkASSERT(0 == reinterpret_cast<long>(indices) % GrPathRange::PathIndexSizeInBytes(indexType)); |
| 284 | SkASSERT(transformValues); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 285 | SkASSERT(pipelineBuilder); |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 286 | |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 287 | // Setup clip |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 288 | GrScissorState scissorState; |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 289 | GrPipelineBuilder::AutoRestoreFragmentProcessors arfp; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 290 | GrPipelineBuilder::AutoRestoreStencil ars; |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 291 | |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 292 | if (!this->setupClip(pipelineBuilder, &arfp, &ars, &scissorState, NULL)) { |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 293 | return; |
| 294 | } |
| 295 | |
| 296 | // set stencil settings for path |
| 297 | GrStencilSettings stencilSettings; |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 298 | GrRenderTarget* rt = pipelineBuilder->getRenderTarget(); |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 299 | GrStencilAttachment* sb = rt->renderTargetPriv().attachStencilAttachment(); |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 300 | this->getPathStencilSettingsForFilltype(fill, sb, &stencilSettings); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 301 | |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 302 | // Don't compute a bounding box for dst copy texture, we'll opt |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 303 | // instead for it to just copy the entire dst. Realistically this is a moot |
| 304 | // point, because any context that supports NV_path_rendering will also |
| 305 | // support NV_blend_equation_advanced. |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 306 | GrDrawTarget::PipelineInfo pipelineInfo(pipelineBuilder, &scissorState, pathProc, NULL, this); |
| 307 | if (pipelineInfo.mustSkipDraw()) { |
| 308 | return; |
| 309 | } |
| 310 | |
| 311 | this->onDrawPaths(pathProc, pathRange, indices, indexType, transformValues, |
| 312 | transformType, count, stencilSettings, pipelineInfo); |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 313 | } |
| 314 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 315 | void GrDrawTarget::clear(const SkIRect* rect, |
| 316 | GrColor color, |
| 317 | bool canIgnoreRect, |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 318 | GrRenderTarget* renderTarget) { |
| 319 | if (fCaps->useDrawInsteadOfClear()) { |
| 320 | // This works around a driver bug with clear by drawing a rect instead. |
| 321 | // The driver will ignore a clear if it is the only thing rendered to a |
| 322 | // target before the target is read. |
| 323 | SkIRect rtRect = SkIRect::MakeWH(renderTarget->width(), renderTarget->height()); |
| 324 | if (NULL == rect || canIgnoreRect || rect->contains(rtRect)) { |
| 325 | rect = &rtRect; |
| 326 | // We first issue a discard() since that may help tilers. |
| 327 | this->discard(renderTarget); |
| 328 | } |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 329 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 330 | GrPipelineBuilder pipelineBuilder; |
| 331 | pipelineBuilder.setRenderTarget(renderTarget); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 332 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 333 | this->drawSimpleRect(&pipelineBuilder, color, SkMatrix::I(), *rect); |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 334 | } else { |
| 335 | this->onClear(rect, color, canIgnoreRect, renderTarget); |
| 336 | } |
| 337 | } |
| 338 | |
egdaniel | 3eee383 | 2014-06-18 13:09:11 -0700 | [diff] [blame] | 339 | typedef GrTraceMarkerSet::Iter TMIter; |
| 340 | void GrDrawTarget::saveActiveTraceMarkers() { |
| 341 | if (this->caps()->gpuTracingSupport()) { |
| 342 | SkASSERT(0 == fStoredTraceMarkers.count()); |
| 343 | fStoredTraceMarkers.addSet(fActiveTraceMarkers); |
| 344 | for (TMIter iter = fStoredTraceMarkers.begin(); iter != fStoredTraceMarkers.end(); ++iter) { |
| 345 | this->removeGpuTraceMarker(&(*iter)); |
| 346 | } |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | void GrDrawTarget::restoreActiveTraceMarkers() { |
| 351 | if (this->caps()->gpuTracingSupport()) { |
| 352 | SkASSERT(0 == fActiveTraceMarkers.count()); |
| 353 | for (TMIter iter = fStoredTraceMarkers.begin(); iter != fStoredTraceMarkers.end(); ++iter) { |
| 354 | this->addGpuTraceMarker(&(*iter)); |
| 355 | } |
| 356 | for (TMIter iter = fActiveTraceMarkers.begin(); iter != fActiveTraceMarkers.end(); ++iter) { |
| 357 | this->fStoredTraceMarkers.remove(*iter); |
| 358 | } |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | void GrDrawTarget::addGpuTraceMarker(const GrGpuTraceMarker* marker) { |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 363 | if (this->caps()->gpuTracingSupport()) { |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 364 | SkASSERT(fGpuTraceMarkerCount >= 0); |
| 365 | this->fActiveTraceMarkers.add(*marker); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 366 | ++fGpuTraceMarkerCount; |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 367 | } |
| 368 | } |
| 369 | |
egdaniel | 3eee383 | 2014-06-18 13:09:11 -0700 | [diff] [blame] | 370 | void GrDrawTarget::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 371 | if (this->caps()->gpuTracingSupport()) { |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 372 | SkASSERT(fGpuTraceMarkerCount >= 1); |
| 373 | this->fActiveTraceMarkers.remove(*marker); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 374 | --fGpuTraceMarkerCount; |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 375 | } |
| 376 | } |
| 377 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 378 | //////////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 379 | |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 380 | namespace { |
| 381 | // returns true if the read/written rect intersects the src/dst and false if not. |
| 382 | bool clip_srcrect_and_dstpoint(const GrSurface* dst, |
| 383 | const GrSurface* src, |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 384 | const SkIRect& srcRect, |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 385 | const SkIPoint& dstPoint, |
| 386 | SkIRect* clippedSrcRect, |
| 387 | SkIPoint* clippedDstPoint) { |
| 388 | *clippedSrcRect = srcRect; |
| 389 | *clippedDstPoint = dstPoint; |
skia.committer@gmail.com | a9493a3 | 2013-04-04 07:01:12 +0000 | [diff] [blame] | 390 | |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 391 | // clip the left edge to src and dst bounds, adjusting dstPoint if necessary |
| 392 | if (clippedSrcRect->fLeft < 0) { |
| 393 | clippedDstPoint->fX -= clippedSrcRect->fLeft; |
| 394 | clippedSrcRect->fLeft = 0; |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 395 | } |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 396 | if (clippedDstPoint->fX < 0) { |
| 397 | clippedSrcRect->fLeft -= clippedDstPoint->fX; |
| 398 | clippedDstPoint->fX = 0; |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 399 | } |
| 400 | |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 401 | // clip the top edge to src and dst bounds, adjusting dstPoint if necessary |
| 402 | if (clippedSrcRect->fTop < 0) { |
| 403 | clippedDstPoint->fY -= clippedSrcRect->fTop; |
| 404 | clippedSrcRect->fTop = 0; |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 405 | } |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 406 | if (clippedDstPoint->fY < 0) { |
| 407 | clippedSrcRect->fTop -= clippedDstPoint->fY; |
| 408 | clippedDstPoint->fY = 0; |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 409 | } |
skia.committer@gmail.com | a9493a3 | 2013-04-04 07:01:12 +0000 | [diff] [blame] | 410 | |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 411 | // clip the right edge to the src and dst bounds. |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 412 | if (clippedSrcRect->fRight > src->width()) { |
| 413 | clippedSrcRect->fRight = src->width(); |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 414 | } |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 415 | if (clippedDstPoint->fX + clippedSrcRect->width() > dst->width()) { |
| 416 | clippedSrcRect->fRight = clippedSrcRect->fLeft + dst->width() - clippedDstPoint->fX; |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | // clip the bottom edge to the src and dst bounds. |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 420 | if (clippedSrcRect->fBottom > src->height()) { |
| 421 | clippedSrcRect->fBottom = src->height(); |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 422 | } |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 423 | if (clippedDstPoint->fY + clippedSrcRect->height() > dst->height()) { |
| 424 | clippedSrcRect->fBottom = clippedSrcRect->fTop + dst->height() - clippedDstPoint->fY; |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 425 | } |
skia.committer@gmail.com | a9493a3 | 2013-04-04 07:01:12 +0000 | [diff] [blame] | 426 | |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 427 | // The above clipping steps may have inverted the rect if it didn't intersect either the src or |
| 428 | // dst bounds. |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 429 | return !clippedSrcRect->isEmpty(); |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | bool GrDrawTarget::copySurface(GrSurface* dst, |
| 434 | GrSurface* src, |
| 435 | const SkIRect& srcRect, |
| 436 | const SkIPoint& dstPoint) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 437 | SkASSERT(dst); |
| 438 | SkASSERT(src); |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 439 | |
| 440 | SkIRect clippedSrcRect; |
| 441 | SkIPoint clippedDstPoint; |
| 442 | // If the rect is outside the src or dst then we've already succeeded. |
| 443 | if (!clip_srcrect_and_dstpoint(dst, |
| 444 | src, |
| 445 | srcRect, |
| 446 | dstPoint, |
| 447 | &clippedSrcRect, |
| 448 | &clippedDstPoint)) { |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 449 | return true; |
| 450 | } |
| 451 | |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame^] | 452 | if (this->getGpu()->canCopySurface(dst, src, clippedSrcRect, clippedDstPoint)) { |
| 453 | this->onCopySurface(dst, src, clippedSrcRect, clippedDstPoint); |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 454 | return true; |
joshualitt | a702415 | 2014-11-03 14:16:35 -0800 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | GrRenderTarget* rt = dst->asRenderTarget(); |
| 458 | GrTexture* tex = src->asTexture(); |
| 459 | |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 460 | if ((dst == src) || !rt || !tex) { |
| 461 | return false; |
| 462 | } |
| 463 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 464 | GrPipelineBuilder pipelineBuilder; |
| 465 | pipelineBuilder.setRenderTarget(rt); |
joshualitt | a702415 | 2014-11-03 14:16:35 -0800 | [diff] [blame] | 466 | SkMatrix matrix; |
| 467 | matrix.setTranslate(SkIntToScalar(clippedSrcRect.fLeft - clippedDstPoint.fX), |
| 468 | SkIntToScalar(clippedSrcRect.fTop - clippedDstPoint.fY)); |
| 469 | matrix.postIDiv(tex->width(), tex->height()); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 470 | pipelineBuilder.addColorTextureProcessor(tex, matrix); |
joshualitt | a702415 | 2014-11-03 14:16:35 -0800 | [diff] [blame] | 471 | SkIRect dstRect = SkIRect::MakeXYWH(clippedDstPoint.fX, |
| 472 | clippedDstPoint.fY, |
| 473 | clippedSrcRect.width(), |
| 474 | clippedSrcRect.height()); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 475 | this->drawSimpleRect(&pipelineBuilder, GrColor_WHITE, SkMatrix::I(), dstRect); |
joshualitt | a702415 | 2014-11-03 14:16:35 -0800 | [diff] [blame] | 476 | return true; |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 477 | } |
| 478 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 479 | bool GrDrawTarget::canCopySurface(const GrSurface* dst, |
| 480 | const GrSurface* src, |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 481 | const SkIRect& srcRect, |
| 482 | const SkIPoint& dstPoint) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 483 | SkASSERT(dst); |
| 484 | SkASSERT(src); |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 485 | |
| 486 | SkIRect clippedSrcRect; |
| 487 | SkIPoint clippedDstPoint; |
| 488 | // If the rect is outside the src or dst then we're guaranteed success |
| 489 | if (!clip_srcrect_and_dstpoint(dst, |
| 490 | src, |
| 491 | srcRect, |
| 492 | dstPoint, |
| 493 | &clippedSrcRect, |
| 494 | &clippedDstPoint)) { |
| 495 | return true; |
| 496 | } |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 497 | return ((dst != src) && dst->asRenderTarget() && src->asTexture()) || |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame^] | 498 | this->getGpu()->canCopySurface(dst, src, clippedSrcRect, clippedDstPoint); |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 499 | } |
| 500 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 501 | void GrDrawTarget::setupPipeline(const PipelineInfo& pipelineInfo, |
| 502 | GrPipeline* pipeline) { |
| 503 | SkNEW_PLACEMENT_ARGS(pipeline, GrPipeline, (*pipelineInfo.fPipelineBuilder, |
| 504 | pipelineInfo.fColorPOI, |
| 505 | pipelineInfo.fCoveragePOI, |
| 506 | *this->caps(), |
| 507 | *pipelineInfo.fScissor, |
| 508 | &pipelineInfo.fDstCopy)); |
| 509 | } |
| 510 | /////////////////////////////////////////////////////////////////////////////// |
| 511 | |
| 512 | GrDrawTarget::PipelineInfo::PipelineInfo(GrPipelineBuilder* pipelineBuilder, |
| 513 | GrScissorState* scissor, |
| 514 | const GrPrimitiveProcessor* primProc, |
| 515 | const SkRect* devBounds, |
| 516 | GrDrawTarget* target) |
| 517 | : fPipelineBuilder(pipelineBuilder) |
| 518 | , fScissor(scissor) { |
| 519 | fColorPOI = fPipelineBuilder->colorProcInfo(primProc); |
| 520 | fCoveragePOI = fPipelineBuilder->coverageProcInfo(primProc); |
| 521 | if (!target->setupDstReadIfNecessary(*fPipelineBuilder, fColorPOI, fCoveragePOI, |
| 522 | &fDstCopy, devBounds)) { |
| 523 | fPipelineBuilder = NULL; |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | GrDrawTarget::PipelineInfo::PipelineInfo(GrPipelineBuilder* pipelineBuilder, |
| 528 | GrScissorState* scissor, |
| 529 | const GrBatch* batch, |
| 530 | const SkRect* devBounds, |
| 531 | GrDrawTarget* target) |
| 532 | : fPipelineBuilder(pipelineBuilder) |
| 533 | , fScissor(scissor) { |
| 534 | fColorPOI = fPipelineBuilder->colorProcInfo(batch); |
| 535 | fCoveragePOI = fPipelineBuilder->coverageProcInfo(batch); |
| 536 | if (!target->setupDstReadIfNecessary(*fPipelineBuilder, fColorPOI, fCoveragePOI, |
| 537 | &fDstCopy, devBounds)) { |
| 538 | fPipelineBuilder = NULL; |
| 539 | } |
| 540 | } |
| 541 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 542 | /////////////////////////////////////////////////////////////////////////////// |
| 543 | |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 544 | void GrDrawTargetCaps::reset() { |
commit-bot@chromium.org | 4744231 | 2013-12-19 16:18:01 +0000 | [diff] [blame] | 545 | fMipMapSupport = false; |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 546 | fNPOTTextureTileSupport = false; |
| 547 | fTwoSidedStencilSupport = false; |
| 548 | fStencilWrapOpsSupport = false; |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 549 | fShaderDerivativeSupport = false; |
| 550 | fGeometryShaderSupport = false; |
skia.committer@gmail.com | e60ed08 | 2013-03-26 07:01:04 +0000 | [diff] [blame] | 551 | fDualSourceBlendingSupport = false; |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 552 | fPathRenderingSupport = false; |
commit-bot@chromium.org | b835652 | 2013-07-18 22:26:39 +0000 | [diff] [blame] | 553 | fDstReadInShaderSupport = false; |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 554 | fDiscardRenderTargetSupport = false; |
commit-bot@chromium.org | b835652 | 2013-07-18 22:26:39 +0000 | [diff] [blame] | 555 | fReuseScratchTextures = true; |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 556 | fGpuTracingSupport = false; |
krajcevski | 78697816 | 2014-07-30 11:25:44 -0700 | [diff] [blame] | 557 | fCompressedTexSubImageSupport = false; |
bsalomon | d08ea5f | 2015-02-20 06:58:13 -0800 | [diff] [blame] | 558 | fOversizedStencilSupport = false; |
cdalton | fd4167d | 2015-04-21 11:45:56 -0700 | [diff] [blame] | 559 | fTextureBarrierSupport = false; |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 560 | |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 561 | fUseDrawInsteadOfClear = false; |
| 562 | |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 563 | fMapBufferFlags = kNone_MapFlags; |
| 564 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 565 | fMaxRenderTargetSize = 0; |
| 566 | fMaxTextureSize = 0; |
| 567 | fMaxSampleCount = 0; |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 568 | |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 569 | fShaderPrecisionVaries = false; |
| 570 | |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 571 | memset(fConfigRenderSupport, 0, sizeof(fConfigRenderSupport)); |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 572 | memset(fConfigTextureSupport, 0, sizeof(fConfigTextureSupport)); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 573 | } |
| 574 | |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 575 | GrDrawTargetCaps& GrDrawTargetCaps::operator=(const GrDrawTargetCaps& other) { |
commit-bot@chromium.org | 4744231 | 2013-12-19 16:18:01 +0000 | [diff] [blame] | 576 | fMipMapSupport = other.fMipMapSupport; |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 577 | fNPOTTextureTileSupport = other.fNPOTTextureTileSupport; |
| 578 | fTwoSidedStencilSupport = other.fTwoSidedStencilSupport; |
| 579 | fStencilWrapOpsSupport = other.fStencilWrapOpsSupport; |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 580 | fShaderDerivativeSupport = other.fShaderDerivativeSupport; |
| 581 | fGeometryShaderSupport = other.fGeometryShaderSupport; |
| 582 | fDualSourceBlendingSupport = other.fDualSourceBlendingSupport; |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 583 | fPathRenderingSupport = other.fPathRenderingSupport; |
commit-bot@chromium.org | b835652 | 2013-07-18 22:26:39 +0000 | [diff] [blame] | 584 | fDstReadInShaderSupport = other.fDstReadInShaderSupport; |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 585 | fDiscardRenderTargetSupport = other.fDiscardRenderTargetSupport; |
commit-bot@chromium.org | b835652 | 2013-07-18 22:26:39 +0000 | [diff] [blame] | 586 | fReuseScratchTextures = other.fReuseScratchTextures; |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 587 | fGpuTracingSupport = other.fGpuTracingSupport; |
krajcevski | 78697816 | 2014-07-30 11:25:44 -0700 | [diff] [blame] | 588 | fCompressedTexSubImageSupport = other.fCompressedTexSubImageSupport; |
bsalomon | d08ea5f | 2015-02-20 06:58:13 -0800 | [diff] [blame] | 589 | fOversizedStencilSupport = other.fOversizedStencilSupport; |
cdalton | fd4167d | 2015-04-21 11:45:56 -0700 | [diff] [blame] | 590 | fTextureBarrierSupport = other.fTextureBarrierSupport; |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 591 | |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 592 | fUseDrawInsteadOfClear = other.fUseDrawInsteadOfClear; |
| 593 | |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 594 | fMapBufferFlags = other.fMapBufferFlags; |
| 595 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 596 | fMaxRenderTargetSize = other.fMaxRenderTargetSize; |
| 597 | fMaxTextureSize = other.fMaxTextureSize; |
| 598 | fMaxSampleCount = other.fMaxSampleCount; |
| 599 | |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 600 | memcpy(fConfigRenderSupport, other.fConfigRenderSupport, sizeof(fConfigRenderSupport)); |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 601 | memcpy(fConfigTextureSupport, other.fConfigTextureSupport, sizeof(fConfigTextureSupport)); |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 602 | |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 603 | fShaderPrecisionVaries = other.fShaderPrecisionVaries; |
| 604 | for (int s = 0; s < kGrShaderTypeCount; ++s) { |
bsalomon | c0bd648 | 2014-12-09 10:04:14 -0800 | [diff] [blame] | 605 | for (int p = 0; p < kGrSLPrecisionCount; ++p) { |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 606 | fFloatPrecisions[s][p] = other.fFloatPrecisions[s][p]; |
| 607 | } |
| 608 | } |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 609 | return *this; |
| 610 | } |
| 611 | |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 612 | static SkString map_flags_to_string(uint32_t flags) { |
| 613 | SkString str; |
| 614 | if (GrDrawTargetCaps::kNone_MapFlags == flags) { |
| 615 | str = "none"; |
| 616 | } else { |
| 617 | SkASSERT(GrDrawTargetCaps::kCanMap_MapFlag & flags); |
| 618 | SkDEBUGCODE(flags &= ~GrDrawTargetCaps::kCanMap_MapFlag); |
| 619 | str = "can_map"; |
| 620 | |
| 621 | if (GrDrawTargetCaps::kSubset_MapFlag & flags) { |
| 622 | str.append(" partial"); |
| 623 | } else { |
| 624 | str.append(" full"); |
| 625 | } |
| 626 | SkDEBUGCODE(flags &= ~GrDrawTargetCaps::kSubset_MapFlag); |
| 627 | } |
| 628 | SkASSERT(0 == flags); // Make sure we handled all the flags. |
| 629 | return str; |
| 630 | } |
| 631 | |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 632 | static const char* shader_type_to_string(GrShaderType type) { |
| 633 | switch (type) { |
| 634 | case kVertex_GrShaderType: |
| 635 | return "vertex"; |
| 636 | case kGeometry_GrShaderType: |
| 637 | return "geometry"; |
| 638 | case kFragment_GrShaderType: |
| 639 | return "fragment"; |
| 640 | } |
| 641 | return ""; |
| 642 | } |
| 643 | |
bsalomon | c0bd648 | 2014-12-09 10:04:14 -0800 | [diff] [blame] | 644 | static const char* precision_to_string(GrSLPrecision p) { |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 645 | switch (p) { |
bsalomon | c0bd648 | 2014-12-09 10:04:14 -0800 | [diff] [blame] | 646 | case kLow_GrSLPrecision: |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 647 | return "low"; |
bsalomon | c0bd648 | 2014-12-09 10:04:14 -0800 | [diff] [blame] | 648 | case kMedium_GrSLPrecision: |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 649 | return "medium"; |
bsalomon | c0bd648 | 2014-12-09 10:04:14 -0800 | [diff] [blame] | 650 | case kHigh_GrSLPrecision: |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 651 | return "high"; |
| 652 | } |
| 653 | return ""; |
| 654 | } |
| 655 | |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 656 | SkString GrDrawTargetCaps::dump() const { |
| 657 | SkString r; |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 658 | static const char* gNY[] = {"NO", "YES"}; |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 659 | r.appendf("MIP Map Support : %s\n", gNY[fMipMapSupport]); |
| 660 | r.appendf("NPOT Texture Tile Support : %s\n", gNY[fNPOTTextureTileSupport]); |
| 661 | r.appendf("Two Sided Stencil Support : %s\n", gNY[fTwoSidedStencilSupport]); |
| 662 | r.appendf("Stencil Wrap Ops Support : %s\n", gNY[fStencilWrapOpsSupport]); |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 663 | r.appendf("Shader Derivative Support : %s\n", gNY[fShaderDerivativeSupport]); |
| 664 | r.appendf("Geometry Shader Support : %s\n", gNY[fGeometryShaderSupport]); |
| 665 | r.appendf("Dual Source Blending Support : %s\n", gNY[fDualSourceBlendingSupport]); |
| 666 | r.appendf("Path Rendering Support : %s\n", gNY[fPathRenderingSupport]); |
| 667 | r.appendf("Dst Read In Shader Support : %s\n", gNY[fDstReadInShaderSupport]); |
| 668 | r.appendf("Discard Render Target Support : %s\n", gNY[fDiscardRenderTargetSupport]); |
| 669 | r.appendf("Reuse Scratch Textures : %s\n", gNY[fReuseScratchTextures]); |
| 670 | r.appendf("Gpu Tracing Support : %s\n", gNY[fGpuTracingSupport]); |
| 671 | r.appendf("Compressed Update Support : %s\n", gNY[fCompressedTexSubImageSupport]); |
bsalomon | d08ea5f | 2015-02-20 06:58:13 -0800 | [diff] [blame] | 672 | r.appendf("Oversized Stencil Support : %s\n", gNY[fOversizedStencilSupport]); |
cdalton | fd4167d | 2015-04-21 11:45:56 -0700 | [diff] [blame] | 673 | r.appendf("Texture Barrier Support : %s\n", gNY[fTextureBarrierSupport]); |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 674 | r.appendf("Draw Instead of Clear [workaround] : %s\n", gNY[fUseDrawInsteadOfClear]); |
| 675 | |
| 676 | r.appendf("Max Texture Size : %d\n", fMaxTextureSize); |
| 677 | r.appendf("Max Render Target Size : %d\n", fMaxRenderTargetSize); |
| 678 | r.appendf("Max Sample Count : %d\n", fMaxSampleCount); |
| 679 | |
| 680 | r.appendf("Map Buffer Support : %s\n", |
| 681 | map_flags_to_string(fMapBufferFlags).c_str()); |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 682 | |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 683 | static const char* kConfigNames[] = { |
| 684 | "Unknown", // kUnknown_GrPixelConfig |
| 685 | "Alpha8", // kAlpha_8_GrPixelConfig, |
| 686 | "Index8", // kIndex_8_GrPixelConfig, |
| 687 | "RGB565", // kRGB_565_GrPixelConfig, |
| 688 | "RGBA444", // kRGBA_4444_GrPixelConfig, |
| 689 | "RGBA8888", // kRGBA_8888_GrPixelConfig, |
| 690 | "BGRA8888", // kBGRA_8888_GrPixelConfig, |
jvanverth | fa1e8a7 | 2014-12-22 08:31:49 -0800 | [diff] [blame] | 691 | "SRGBA8888",// kSRGBA_8888_GrPixelConfig, |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 692 | "ETC1", // kETC1_GrPixelConfig, |
| 693 | "LATC", // kLATC_GrPixelConfig, |
krajcevski | 238b456 | 2014-06-30 09:09:22 -0700 | [diff] [blame] | 694 | "R11EAC", // kR11_EAC_GrPixelConfig, |
krajcevski | 7ef2162 | 2014-07-16 15:21:13 -0700 | [diff] [blame] | 695 | "ASTC12x12",// kASTC_12x12_GrPixelConfig, |
jvanverth | 28f9c60 | 2014-12-05 13:06:35 -0800 | [diff] [blame] | 696 | "RGBAFloat",// kRGBA_float_GrPixelConfig |
| 697 | "AlphaHalf",// kAlpha_half_GrPixelConfig |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 698 | }; |
krajcevski | 7ef2162 | 2014-07-16 15:21:13 -0700 | [diff] [blame] | 699 | GR_STATIC_ASSERT(0 == kUnknown_GrPixelConfig); |
| 700 | GR_STATIC_ASSERT(1 == kAlpha_8_GrPixelConfig); |
| 701 | GR_STATIC_ASSERT(2 == kIndex_8_GrPixelConfig); |
| 702 | GR_STATIC_ASSERT(3 == kRGB_565_GrPixelConfig); |
| 703 | GR_STATIC_ASSERT(4 == kRGBA_4444_GrPixelConfig); |
| 704 | GR_STATIC_ASSERT(5 == kRGBA_8888_GrPixelConfig); |
| 705 | GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig); |
jvanverth | fa1e8a7 | 2014-12-22 08:31:49 -0800 | [diff] [blame] | 706 | GR_STATIC_ASSERT(7 == kSRGBA_8888_GrPixelConfig); |
| 707 | GR_STATIC_ASSERT(8 == kETC1_GrPixelConfig); |
| 708 | GR_STATIC_ASSERT(9 == kLATC_GrPixelConfig); |
| 709 | GR_STATIC_ASSERT(10 == kR11_EAC_GrPixelConfig); |
| 710 | GR_STATIC_ASSERT(11 == kASTC_12x12_GrPixelConfig); |
| 711 | GR_STATIC_ASSERT(12 == kRGBA_float_GrPixelConfig); |
| 712 | GR_STATIC_ASSERT(13 == kAlpha_half_GrPixelConfig); |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 713 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kConfigNames) == kGrPixelConfigCnt); |
| 714 | |
commit-bot@chromium.org | 9901727 | 2013-11-08 18:45:27 +0000 | [diff] [blame] | 715 | SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][0]); |
| 716 | SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][1]); |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 717 | |
| 718 | for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) { |
| 719 | r.appendf("%s is renderable: %s, with MSAA: %s\n", |
| 720 | kConfigNames[i], |
| 721 | gNY[fConfigRenderSupport[i][0]], |
| 722 | gNY[fConfigRenderSupport[i][1]]); |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 723 | } |
commit-bot@chromium.org | 42dc813 | 2014-05-27 19:26:59 +0000 | [diff] [blame] | 724 | |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 725 | SkASSERT(!fConfigTextureSupport[kUnknown_GrPixelConfig]); |
commit-bot@chromium.org | 42dc813 | 2014-05-27 19:26:59 +0000 | [diff] [blame] | 726 | |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 727 | for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) { |
| 728 | r.appendf("%s is uploadable to a texture: %s\n", |
| 729 | kConfigNames[i], |
| 730 | gNY[fConfigTextureSupport[i]]); |
commit-bot@chromium.org | 42dc813 | 2014-05-27 19:26:59 +0000 | [diff] [blame] | 731 | } |
| 732 | |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 733 | r.appendf("Shader Float Precisions (varies: %s):\n", gNY[fShaderPrecisionVaries]); |
| 734 | |
| 735 | for (int s = 0; s < kGrShaderTypeCount; ++s) { |
| 736 | GrShaderType shaderType = static_cast<GrShaderType>(s); |
| 737 | r.appendf("\t%s:\n", shader_type_to_string(shaderType)); |
bsalomon | c0bd648 | 2014-12-09 10:04:14 -0800 | [diff] [blame] | 738 | for (int p = 0; p < kGrSLPrecisionCount; ++p) { |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 739 | if (fFloatPrecisions[s][p].supported()) { |
bsalomon | c0bd648 | 2014-12-09 10:04:14 -0800 | [diff] [blame] | 740 | GrSLPrecision precision = static_cast<GrSLPrecision>(p); |
bsalomon | 17168df | 2014-12-09 09:00:49 -0800 | [diff] [blame] | 741 | r.appendf("\t\t%s: log_low: %d log_high: %d bits: %d\n", |
| 742 | precision_to_string(precision), |
| 743 | fFloatPrecisions[s][p].fLogRangeLow, |
| 744 | fFloatPrecisions[s][p].fLogRangeHigh, |
| 745 | fFloatPrecisions[s][p].fBits); |
| 746 | } |
| 747 | } |
| 748 | } |
| 749 | |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 750 | return r; |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 751 | } |
egdaniel | bc127a3 | 2014-09-19 12:07:43 -0700 | [diff] [blame] | 752 | |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 753 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 754 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 755 | bool GrClipTarget::setupClip(GrPipelineBuilder* pipelineBuilder, |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 756 | GrPipelineBuilder::AutoRestoreFragmentProcessors* arfp, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 757 | GrPipelineBuilder::AutoRestoreStencil* ars, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 758 | GrScissorState* scissorState, |
| 759 | const SkRect* devBounds) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 760 | return fClipMaskManager.setupClipping(pipelineBuilder, |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 761 | arfp, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 762 | ars, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 763 | scissorState, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 764 | devBounds); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 765 | } |