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 | |
bsalomon | eb1cb5c | 2015-05-22 08:01:09 -0700 | [diff] [blame] | 11 | #include "GrCaps.h" |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 12 | #include "GrGpu.h" |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 13 | #include "GrPath.h" |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 14 | #include "GrPipeline.h" |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 15 | #include "GrMemoryPool.h" |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 16 | #include "GrRenderTarget.h" |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 17 | #include "GrResourceProvider.h" |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 18 | #include "GrRenderTargetPriv.h" |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 19 | #include "GrSurfacePriv.h" |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 20 | #include "GrTexture.h" |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 21 | #include "GrVertexBuffer.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 22 | |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 23 | #include "batches/GrClearBatch.h" |
bsalomon | 872062c | 2015-08-18 12:12:35 -0700 | [diff] [blame] | 24 | #include "batches/GrCopySurfaceBatch.h" |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 25 | #include "batches/GrDiscardBatch.h" |
bsalomon | 16b9913 | 2015-08-13 14:55:50 -0700 | [diff] [blame] | 26 | #include "batches/GrDrawBatch.h" |
bsalomon | add79ef | 2015-08-19 13:26:49 -0700 | [diff] [blame^] | 27 | #include "batches/GrDrawPathBatch.h" |
joshualitt | ecd1a69 | 2015-08-10 10:08:26 -0700 | [diff] [blame] | 28 | #include "batches/GrRectBatchFactory.h" |
bsalomon | a44919e | 2015-08-18 13:28:19 -0700 | [diff] [blame] | 29 | #include "batches/GrStencilPathBatch.h" |
joshualitt | 7441782 | 2015-08-07 11:42:16 -0700 | [diff] [blame] | 30 | |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 31 | #include "SkStrokeRec.h" |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 32 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 33 | //////////////////////////////////////////////////////////////////////////////// |
| 34 | |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 35 | GrDrawTarget::GrDrawTarget(GrGpu* gpu, GrResourceProvider* resourceProvider) |
| 36 | : fGpu(SkRef(gpu)) |
| 37 | , fCaps(SkRef(gpu->caps())) |
| 38 | , fResourceProvider(resourceProvider) |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 39 | , fGpuTraceMarkerCount(0) |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 40 | , fFlushing(false) { |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | GrDrawTarget::~GrDrawTarget() { |
| 44 | fGpu->unref(); |
| 45 | fCaps->unref(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | //////////////////////////////////////////////////////////////////////////////// |
| 49 | |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 50 | bool GrDrawTarget::setupDstReadIfNecessary(const GrPipelineBuilder& pipelineBuilder, |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 51 | const GrProcOptInfo& colorPOI, |
| 52 | const GrProcOptInfo& coveragePOI, |
bsalomon | 6a44c6a | 2015-05-26 09:49:05 -0700 | [diff] [blame] | 53 | GrXferProcessor::DstTexture* dstTexture, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 54 | const SkRect* drawBounds) { |
bsalomon | 6a44c6a | 2015-05-26 09:49:05 -0700 | [diff] [blame] | 55 | if (!pipelineBuilder.willXPNeedDstTexture(*this->caps(), colorPOI, coveragePOI)) { |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 56 | return true; |
| 57 | } |
cdalton | 9954bc3 | 2015-04-29 14:17:00 -0700 | [diff] [blame] | 58 | |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 59 | GrRenderTarget* rt = pipelineBuilder.getRenderTarget(); |
cdalton | 9954bc3 | 2015-04-29 14:17:00 -0700 | [diff] [blame] | 60 | |
| 61 | if (this->caps()->textureBarrierSupport()) { |
| 62 | if (GrTexture* rtTex = rt->asTexture()) { |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 63 | // The render target is a texture, so we can read from it directly in the shader. The XP |
cdalton | 9954bc3 | 2015-04-29 14:17:00 -0700 | [diff] [blame] | 64 | // will be responsible to detect this situation and request a texture barrier. |
bsalomon | 6a44c6a | 2015-05-26 09:49:05 -0700 | [diff] [blame] | 65 | dstTexture->setTexture(rtTex); |
| 66 | dstTexture->setOffset(0, 0); |
cdalton | 9954bc3 | 2015-04-29 14:17:00 -0700 | [diff] [blame] | 67 | return true; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | SkIRect copyRect; |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 72 | pipelineBuilder.clip().getConservativeBounds(rt, ©Rect); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 73 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 74 | if (drawBounds) { |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 75 | SkIRect drawIBounds; |
| 76 | drawBounds->roundOut(&drawIBounds); |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 77 | if (!copyRect.intersect(drawIBounds)) { |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 78 | #ifdef SK_DEBUG |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 79 | GrCapsDebugf(fCaps, "Missed an early reject. " |
| 80 | "Bailing on draw from setupDstReadIfNecessary.\n"); |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 81 | #endif |
| 82 | return false; |
| 83 | } |
| 84 | } else { |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 85 | #ifdef SK_DEBUG |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 86 | //SkDebugf("No dev bounds when dst copy is made.\n"); |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 87 | #endif |
| 88 | } |
skia.committer@gmail.com | 05a2ee0 | 2013-04-02 07:01:34 +0000 | [diff] [blame] | 89 | |
commit-bot@chromium.org | 63150af | 2013-04-11 22:00:22 +0000 | [diff] [blame] | 90 | // MSAA consideration: When there is support for reading MSAA samples in the shader we could |
| 91 | // have per-sample dst values by making the copy multisampled. |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 92 | GrSurfaceDesc desc; |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 93 | if (!this->getGpu()->initCopySurfaceDstDesc(rt, &desc)) { |
| 94 | desc.fOrigin = kDefault_GrSurfaceOrigin; |
| 95 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 96 | desc.fConfig = rt->config(); |
| 97 | } |
| 98 | |
| 99 | |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 100 | desc.fWidth = copyRect.width(); |
| 101 | desc.fHeight = copyRect.height(); |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 102 | |
bsalomon | eae6200 | 2015-07-31 13:59:30 -0700 | [diff] [blame] | 103 | static const uint32_t kFlags = 0; |
| 104 | SkAutoTUnref<GrTexture> copy(fResourceProvider->createApproxTexture(desc, kFlags)); |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 105 | |
bsalomon | e305973 | 2014-10-14 11:47:22 -0700 | [diff] [blame] | 106 | if (!copy) { |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 107 | SkDebugf("Failed to create temporary copy of destination texture.\n"); |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 108 | return false; |
| 109 | } |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 110 | SkIPoint dstPoint = {0, 0}; |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 111 | this->copySurface(copy, rt, copyRect, dstPoint); |
| 112 | dstTexture->setTexture(copy); |
| 113 | dstTexture->setOffset(copyRect.fLeft, copyRect.fTop); |
| 114 | return true; |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 115 | } |
| 116 | |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 117 | void GrDrawTarget::flush() { |
| 118 | if (fFlushing) { |
| 119 | return; |
| 120 | } |
| 121 | fFlushing = true; |
| 122 | |
| 123 | this->getGpu()->saveActiveTraceMarkers(); |
| 124 | |
| 125 | this->onFlush(); |
| 126 | |
| 127 | this->getGpu()->restoreActiveTraceMarkers(); |
| 128 | |
| 129 | fFlushing = false; |
| 130 | this->reset(); |
| 131 | } |
| 132 | |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 133 | void GrDrawTarget::drawBatch(const GrPipelineBuilder& pipelineBuilder, GrDrawBatch* batch) { |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 134 | // Setup clip |
| 135 | GrScissorState scissorState; |
joshualitt | 4421a4c | 2015-07-13 09:36:41 -0700 | [diff] [blame] | 136 | GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps; |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 137 | GrPipelineBuilder::AutoRestoreStencil ars; |
joshualitt | 4421a4c | 2015-07-13 09:36:41 -0700 | [diff] [blame] | 138 | if (!this->setupClip(pipelineBuilder, &arfps, &ars, &scissorState, &batch->bounds())) { |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 139 | return; |
| 140 | } |
| 141 | |
joshualitt | 99c7c07 | 2015-05-01 13:43:30 -0700 | [diff] [blame] | 142 | // Batch bounds are tight, so for dev copies |
| 143 | // TODO move this into setupDstReadIfNecessary when paths are in batch |
| 144 | SkRect bounds = batch->bounds(); |
| 145 | bounds.outset(0.5f, 0.5f); |
| 146 | |
bsalomon | a387a11 | 2015-08-11 14:47:42 -0700 | [diff] [blame] | 147 | GrDrawTarget::PipelineInfo pipelineInfo(&pipelineBuilder, &scissorState, batch, &bounds, |
joshualitt | 99c7c07 | 2015-05-01 13:43:30 -0700 | [diff] [blame] | 148 | this); |
bsalomon | add79ef | 2015-08-19 13:26:49 -0700 | [diff] [blame^] | 149 | |
bsalomon | a387a11 | 2015-08-11 14:47:42 -0700 | [diff] [blame] | 150 | if (!pipelineInfo.valid()) { |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 151 | return; |
| 152 | } |
bsalomon | a387a11 | 2015-08-11 14:47:42 -0700 | [diff] [blame] | 153 | if (!batch->installPipeline(pipelineInfo.pipelineCreateArgs())) { |
| 154 | return; |
| 155 | } |
| 156 | this->onDrawBatch(batch); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 157 | } |
| 158 | |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 159 | static const GrStencilSettings& winding_path_stencil_settings() { |
| 160 | GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, |
| 161 | kIncClamp_StencilOp, |
| 162 | kIncClamp_StencilOp, |
| 163 | kAlwaysIfInClip_StencilFunc, |
| 164 | 0xFFFF, 0xFFFF, 0xFFFF); |
| 165 | return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); |
| 166 | } |
| 167 | |
| 168 | static const GrStencilSettings& even_odd_path_stencil_settings() { |
| 169 | GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, |
| 170 | kInvert_StencilOp, |
| 171 | kInvert_StencilOp, |
| 172 | kAlwaysIfInClip_StencilFunc, |
| 173 | 0xFFFF, 0xFFFF, 0xFFFF); |
| 174 | return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); |
| 175 | } |
| 176 | |
| 177 | void GrDrawTarget::getPathStencilSettingsForFilltype(GrPathRendering::FillType fill, |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 178 | const GrStencilAttachment* sb, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 179 | GrStencilSettings* outStencilSettings) { |
| 180 | |
| 181 | switch (fill) { |
| 182 | default: |
| 183 | SkFAIL("Unexpected path fill."); |
| 184 | case GrPathRendering::kWinding_FillType: |
| 185 | *outStencilSettings = winding_path_stencil_settings(); |
| 186 | break; |
| 187 | case GrPathRendering::kEvenOdd_FillType: |
| 188 | *outStencilSettings = even_odd_path_stencil_settings(); |
| 189 | break; |
| 190 | } |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 191 | this->clipMaskManager()->adjustPathStencilParams(sb, outStencilSettings); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 192 | } |
| 193 | |
joshualitt | 1c73548 | 2015-07-13 08:08:25 -0700 | [diff] [blame] | 194 | void GrDrawTarget::stencilPath(const GrPipelineBuilder& pipelineBuilder, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 195 | const GrPathProcessor* pathProc, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 196 | const GrPath* path, |
| 197 | GrPathRendering::FillType fill) { |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 198 | // TODO: extract portions of checkDraw that are relevant to path stenciling. |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 199 | SkASSERT(path); |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 200 | SkASSERT(this->caps()->shaderCaps()->pathRenderingSupport()); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 201 | |
| 202 | // Setup clip |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 203 | GrScissorState scissorState; |
joshualitt | 4421a4c | 2015-07-13 09:36:41 -0700 | [diff] [blame] | 204 | GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 205 | GrPipelineBuilder::AutoRestoreStencil ars; |
joshualitt | 4421a4c | 2015-07-13 09:36:41 -0700 | [diff] [blame] | 206 | if (!this->setupClip(pipelineBuilder, &arfps, &ars, &scissorState, NULL)) { |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 207 | return; |
| 208 | } |
| 209 | |
| 210 | // set stencil settings for path |
| 211 | GrStencilSettings stencilSettings; |
joshualitt | 1c73548 | 2015-07-13 08:08:25 -0700 | [diff] [blame] | 212 | GrRenderTarget* rt = pipelineBuilder.getRenderTarget(); |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 213 | GrStencilAttachment* sb = rt->renderTargetPriv().attachStencilAttachment(); |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 214 | this->getPathStencilSettingsForFilltype(fill, sb, &stencilSettings); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 215 | |
bsalomon | a44919e | 2015-08-18 13:28:19 -0700 | [diff] [blame] | 216 | GrBatch* batch = GrStencilPathBatch::Create(pathProc->viewMatrix(), |
| 217 | pipelineBuilder.isHWAntialias(), |
| 218 | stencilSettings, scissorState, |
| 219 | pipelineBuilder.getRenderTarget(), |
| 220 | path); |
| 221 | this->onDrawBatch(batch); |
| 222 | batch->unref(); |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 223 | } |
| 224 | |
joshualitt | 1c73548 | 2015-07-13 08:08:25 -0700 | [diff] [blame] | 225 | void GrDrawTarget::drawPath(const GrPipelineBuilder& pipelineBuilder, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 226 | const GrPathProcessor* pathProc, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 227 | const GrPath* path, |
| 228 | GrPathRendering::FillType fill) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 229 | SkASSERT(path); |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 230 | SkASSERT(this->caps()->shaderCaps()->pathRenderingSupport()); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 231 | |
bsalomon | add79ef | 2015-08-19 13:26:49 -0700 | [diff] [blame^] | 232 | GrDrawPathBatch* batch = GrDrawPathBatch::Create(pathProc, path); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 233 | |
bsalomon | add79ef | 2015-08-19 13:26:49 -0700 | [diff] [blame^] | 234 | // This looks like drawBatch() but there is an added wrinkle that stencil settings get inserted |
| 235 | // after setupClip() but before onDrawBatch(). TODO: Figure out a better model for handling |
| 236 | // stencil settings WRT interactions between pipeline(builder), clipmaskmanager, and batches. |
| 237 | |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 238 | GrScissorState scissorState; |
joshualitt | 4421a4c | 2015-07-13 09:36:41 -0700 | [diff] [blame] | 239 | GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 240 | GrPipelineBuilder::AutoRestoreStencil ars; |
bsalomon | add79ef | 2015-08-19 13:26:49 -0700 | [diff] [blame^] | 241 | if (!this->setupClip(pipelineBuilder, &arfps, &ars, &scissorState, &batch->bounds())) { |
| 242 | return; |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 243 | } |
| 244 | |
bsalomon | add79ef | 2015-08-19 13:26:49 -0700 | [diff] [blame^] | 245 | // Ensure the render target has a stencil buffer and get the stencil settings. |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 246 | GrStencilSettings stencilSettings; |
joshualitt | 1c73548 | 2015-07-13 08:08:25 -0700 | [diff] [blame] | 247 | GrRenderTarget* rt = pipelineBuilder.getRenderTarget(); |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 248 | GrStencilAttachment* sb = rt->renderTargetPriv().attachStencilAttachment(); |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 249 | this->getPathStencilSettingsForFilltype(fill, sb, &stencilSettings); |
bsalomon | add79ef | 2015-08-19 13:26:49 -0700 | [diff] [blame^] | 250 | batch->setStencilSettings(stencilSettings); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 251 | |
bsalomon | add79ef | 2015-08-19 13:26:49 -0700 | [diff] [blame^] | 252 | // Don't compute a bounding box for dst copy texture, we'll opt |
| 253 | // instead for it to just copy the entire dst. Realistically this is a moot |
| 254 | // point, because any context that supports NV_path_rendering will also |
| 255 | // support NV_blend_equation_advanced. |
| 256 | GrDrawTarget::PipelineInfo pipelineInfo(&pipelineBuilder, &scissorState, batch, NULL, this); |
| 257 | |
bsalomon | a387a11 | 2015-08-11 14:47:42 -0700 | [diff] [blame] | 258 | if (!pipelineInfo.valid()) { |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 259 | return; |
| 260 | } |
bsalomon | add79ef | 2015-08-19 13:26:49 -0700 | [diff] [blame^] | 261 | if (!batch->installPipeline(pipelineInfo.pipelineCreateArgs())) { |
| 262 | return; |
| 263 | } |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 264 | |
bsalomon | add79ef | 2015-08-19 13:26:49 -0700 | [diff] [blame^] | 265 | this->onDrawBatch(batch); |
| 266 | batch->unref(); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 267 | } |
| 268 | |
joshualitt | 1c73548 | 2015-07-13 08:08:25 -0700 | [diff] [blame] | 269 | void GrDrawTarget::drawPaths(const GrPipelineBuilder& pipelineBuilder, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 270 | const GrPathProcessor* pathProc, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 271 | const GrPathRange* pathRange, |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 272 | const void* indices, |
| 273 | PathIndexType indexType, |
| 274 | const float transformValues[], |
| 275 | PathTransformType transformType, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 276 | int count, |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 277 | GrPathRendering::FillType fill) { |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 278 | SkASSERT(this->caps()->shaderCaps()->pathRenderingSupport()); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 279 | SkASSERT(pathRange); |
| 280 | SkASSERT(indices); |
bsalomon | ebc1c10 | 2015-08-06 17:33:16 -0700 | [diff] [blame] | 281 | SkASSERT(0 == reinterpret_cast<intptr_t>(indices) % |
| 282 | GrPathRange::PathIndexSizeInBytes(indexType)); |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 283 | SkASSERT(transformValues); |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 284 | |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 285 | // Setup clip |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 286 | GrScissorState scissorState; |
joshualitt | 4421a4c | 2015-07-13 09:36:41 -0700 | [diff] [blame] | 287 | GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 288 | GrPipelineBuilder::AutoRestoreStencil ars; |
joshualitt | 4421a4c | 2015-07-13 09:36:41 -0700 | [diff] [blame] | 289 | if (!this->setupClip(pipelineBuilder, &arfps, &ars, &scissorState, NULL)) { |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 290 | return; |
| 291 | } |
| 292 | |
| 293 | // set stencil settings for path |
| 294 | GrStencilSettings stencilSettings; |
joshualitt | 1c73548 | 2015-07-13 08:08:25 -0700 | [diff] [blame] | 295 | GrRenderTarget* rt = pipelineBuilder.getRenderTarget(); |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 296 | GrStencilAttachment* sb = rt->renderTargetPriv().attachStencilAttachment(); |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 297 | this->getPathStencilSettingsForFilltype(fill, sb, &stencilSettings); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 298 | |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 299 | // Don't compute a bounding box for dst copy texture, we'll opt |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 300 | // instead for it to just copy the entire dst. Realistically this is a moot |
| 301 | // point, because any context that supports NV_path_rendering will also |
| 302 | // support NV_blend_equation_advanced. |
bsalomon | a387a11 | 2015-08-11 14:47:42 -0700 | [diff] [blame] | 303 | GrDrawTarget::PipelineInfo pipelineInfo(&pipelineBuilder, &scissorState, pathProc, NULL, this); |
| 304 | if (!pipelineInfo.valid()) { |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 305 | return; |
| 306 | } |
| 307 | |
| 308 | this->onDrawPaths(pathProc, pathRange, indices, indexType, transformValues, |
| 309 | transformType, count, stencilSettings, pipelineInfo); |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 310 | } |
| 311 | |
joshualitt | 1c73548 | 2015-07-13 08:08:25 -0700 | [diff] [blame] | 312 | void GrDrawTarget::drawBWRect(const GrPipelineBuilder& pipelineBuilder, |
| 313 | GrColor color, |
| 314 | const SkMatrix& viewMatrix, |
| 315 | const SkRect& rect, |
| 316 | const SkRect* localRect, |
| 317 | const SkMatrix* localMatrix) { |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 318 | SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateFillBW(color, viewMatrix, rect, |
| 319 | localRect, localMatrix)); |
joshualitt | ad17cfc | 2015-05-05 10:45:57 -0700 | [diff] [blame] | 320 | this->drawBatch(pipelineBuilder, batch); |
| 321 | } |
| 322 | |
joshualitt | 1c73548 | 2015-07-13 08:08:25 -0700 | [diff] [blame] | 323 | void GrDrawTarget::drawAARect(const GrPipelineBuilder& pipelineBuilder, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 324 | GrColor color, |
| 325 | const SkMatrix& viewMatrix, |
| 326 | const SkRect& rect, |
| 327 | const SkRect& devRect) { |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 328 | SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateFillAA(color, viewMatrix, rect, |
| 329 | devRect)); |
joshualitt | 14205b1 | 2015-08-10 11:40:56 -0700 | [diff] [blame] | 330 | this->drawBatch(pipelineBuilder, batch); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 331 | } |
| 332 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 333 | void GrDrawTarget::clear(const SkIRect* rect, |
| 334 | GrColor color, |
| 335 | bool canIgnoreRect, |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 336 | GrRenderTarget* renderTarget) { |
egdaniel | 51c8d40 | 2015-08-06 10:54:13 -0700 | [diff] [blame] | 337 | SkIRect rtRect = SkIRect::MakeWH(renderTarget->width(), renderTarget->height()); |
| 338 | SkIRect clippedRect; |
| 339 | if (!rect || |
| 340 | (canIgnoreRect && this->caps()->fullClearIsFree()) || |
| 341 | rect->contains(rtRect)) { |
| 342 | rect = &rtRect; |
| 343 | } else { |
| 344 | clippedRect = *rect; |
| 345 | if (!clippedRect.intersect(rtRect)) { |
| 346 | return; |
| 347 | } |
| 348 | rect = &clippedRect; |
| 349 | } |
| 350 | |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 351 | if (fCaps->useDrawInsteadOfClear()) { |
| 352 | // This works around a driver bug with clear by drawing a rect instead. |
| 353 | // The driver will ignore a clear if it is the only thing rendered to a |
| 354 | // target before the target is read. |
egdaniel | 51c8d40 | 2015-08-06 10:54:13 -0700 | [diff] [blame] | 355 | if (rect == &rtRect) { |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 356 | this->discard(renderTarget); |
| 357 | } |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 358 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 359 | GrPipelineBuilder pipelineBuilder; |
| 360 | pipelineBuilder.setRenderTarget(renderTarget); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 361 | |
joshualitt | 1c73548 | 2015-07-13 08:08:25 -0700 | [diff] [blame] | 362 | this->drawSimpleRect(pipelineBuilder, color, SkMatrix::I(), *rect); |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 363 | } else { |
| 364 | GrBatch* batch = SkNEW_ARGS(GrClearBatch, (*rect, color, renderTarget)); |
| 365 | this->onDrawBatch(batch); |
| 366 | batch->unref(); |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | void GrDrawTarget::discard(GrRenderTarget* renderTarget) { |
| 371 | if (this->caps()->discardRenderTargetSupport()) { |
| 372 | GrBatch* batch = SkNEW_ARGS(GrDiscardBatch, (renderTarget)); |
| 373 | this->onDrawBatch(batch); |
| 374 | batch->unref(); |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 375 | } |
| 376 | } |
| 377 | |
egdaniel | 3eee383 | 2014-06-18 13:09:11 -0700 | [diff] [blame] | 378 | typedef GrTraceMarkerSet::Iter TMIter; |
| 379 | void GrDrawTarget::saveActiveTraceMarkers() { |
| 380 | if (this->caps()->gpuTracingSupport()) { |
| 381 | SkASSERT(0 == fStoredTraceMarkers.count()); |
| 382 | fStoredTraceMarkers.addSet(fActiveTraceMarkers); |
| 383 | for (TMIter iter = fStoredTraceMarkers.begin(); iter != fStoredTraceMarkers.end(); ++iter) { |
| 384 | this->removeGpuTraceMarker(&(*iter)); |
| 385 | } |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | void GrDrawTarget::restoreActiveTraceMarkers() { |
| 390 | if (this->caps()->gpuTracingSupport()) { |
| 391 | SkASSERT(0 == fActiveTraceMarkers.count()); |
| 392 | for (TMIter iter = fStoredTraceMarkers.begin(); iter != fStoredTraceMarkers.end(); ++iter) { |
| 393 | this->addGpuTraceMarker(&(*iter)); |
| 394 | } |
| 395 | for (TMIter iter = fActiveTraceMarkers.begin(); iter != fActiveTraceMarkers.end(); ++iter) { |
| 396 | this->fStoredTraceMarkers.remove(*iter); |
| 397 | } |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | void GrDrawTarget::addGpuTraceMarker(const GrGpuTraceMarker* marker) { |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 402 | if (this->caps()->gpuTracingSupport()) { |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 403 | SkASSERT(fGpuTraceMarkerCount >= 0); |
| 404 | this->fActiveTraceMarkers.add(*marker); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 405 | ++fGpuTraceMarkerCount; |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 406 | } |
| 407 | } |
| 408 | |
egdaniel | 3eee383 | 2014-06-18 13:09:11 -0700 | [diff] [blame] | 409 | void GrDrawTarget::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 410 | if (this->caps()->gpuTracingSupport()) { |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 411 | SkASSERT(fGpuTraceMarkerCount >= 1); |
| 412 | this->fActiveTraceMarkers.remove(*marker); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 413 | --fGpuTraceMarkerCount; |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 414 | } |
| 415 | } |
| 416 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 417 | //////////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 418 | |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 419 | void GrDrawTarget::copySurface(GrSurface* dst, |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 420 | GrSurface* src, |
| 421 | const SkIRect& srcRect, |
| 422 | const SkIPoint& dstPoint) { |
bsalomon | 872062c | 2015-08-18 12:12:35 -0700 | [diff] [blame] | 423 | GrBatch* batch = GrCopySurfaceBatch::Create(dst, src, srcRect, dstPoint); |
| 424 | if (batch) { |
| 425 | this->onDrawBatch(batch); |
| 426 | batch->unref(); |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 427 | } |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 428 | } |
| 429 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 430 | /////////////////////////////////////////////////////////////////////////////// |
| 431 | |
bsalomon | a387a11 | 2015-08-11 14:47:42 -0700 | [diff] [blame] | 432 | GrDrawTarget::PipelineInfo::PipelineInfo(const GrPipelineBuilder* pipelineBuilder, |
| 433 | const GrScissorState* scissor, |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 434 | const GrPrimitiveProcessor* primProc, |
| 435 | const SkRect* devBounds, |
bsalomon | a387a11 | 2015-08-11 14:47:42 -0700 | [diff] [blame] | 436 | GrDrawTarget* target) { |
| 437 | fArgs.fPipelineBuilder = pipelineBuilder; |
| 438 | fArgs.fCaps = target->caps(); |
| 439 | fArgs.fScissor = scissor; |
| 440 | fArgs.fColorPOI = fArgs.fPipelineBuilder->colorProcInfo(primProc); |
| 441 | fArgs.fCoveragePOI = fArgs.fPipelineBuilder->coverageProcInfo(primProc); |
| 442 | if (!target->setupDstReadIfNecessary(*fArgs.fPipelineBuilder, fArgs.fColorPOI, |
| 443 | fArgs.fCoveragePOI, &fArgs.fDstTexture, devBounds)) { |
| 444 | fArgs.fPipelineBuilder = NULL; |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 445 | } |
| 446 | } |
| 447 | |
bsalomon | a387a11 | 2015-08-11 14:47:42 -0700 | [diff] [blame] | 448 | GrDrawTarget::PipelineInfo::PipelineInfo(const GrPipelineBuilder* pipelineBuilder, |
| 449 | const GrScissorState* scissor, |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 450 | const GrDrawBatch* batch, |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 451 | const SkRect* devBounds, |
bsalomon | a387a11 | 2015-08-11 14:47:42 -0700 | [diff] [blame] | 452 | GrDrawTarget* target) { |
| 453 | fArgs.fPipelineBuilder = pipelineBuilder; |
| 454 | fArgs.fCaps = target->caps(); |
| 455 | fArgs.fScissor = scissor; |
| 456 | fArgs.fColorPOI = fArgs.fPipelineBuilder->colorProcInfo(batch); |
| 457 | fArgs.fCoveragePOI = fArgs.fPipelineBuilder->coverageProcInfo(batch); |
| 458 | if (!target->setupDstReadIfNecessary(*fArgs.fPipelineBuilder, fArgs.fColorPOI, |
| 459 | fArgs.fCoveragePOI, &fArgs.fDstTexture, devBounds)) { |
| 460 | fArgs.fPipelineBuilder = NULL; |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 461 | } |
| 462 | } |
| 463 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 464 | /////////////////////////////////////////////////////////////////////////////// |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 465 | GrClipTarget::GrClipTarget(GrContext* context) |
| 466 | : INHERITED(context->getGpu(), context->resourceProvider()) |
| 467 | , fContext(context) { |
bsalomon | edd77a1 | 2015-05-29 09:45:57 -0700 | [diff] [blame] | 468 | fClipMaskManager.reset(SkNEW_ARGS(GrClipMaskManager, (this))); |
| 469 | } |
| 470 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 471 | |
joshualitt | 1c73548 | 2015-07-13 08:08:25 -0700 | [diff] [blame] | 472 | bool GrClipTarget::setupClip(const GrPipelineBuilder& pipelineBuilder, |
joshualitt | 4421a4c | 2015-07-13 09:36:41 -0700 | [diff] [blame] | 473 | GrPipelineBuilder::AutoRestoreFragmentProcessorState* arfps, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 474 | GrPipelineBuilder::AutoRestoreStencil* ars, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 475 | GrScissorState* scissorState, |
| 476 | const SkRect* devBounds) { |
joshualitt | 1c73548 | 2015-07-13 08:08:25 -0700 | [diff] [blame] | 477 | return fClipMaskManager->setupClipping(pipelineBuilder, |
joshualitt | 4421a4c | 2015-07-13 09:36:41 -0700 | [diff] [blame] | 478 | arfps, |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame] | 479 | ars, |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame] | 480 | scissorState, |
| 481 | devBounds); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 482 | } |
bsalomon | edd77a1 | 2015-05-29 09:45:57 -0700 | [diff] [blame] | 483 | |
| 484 | void GrClipTarget::purgeResources() { |
| 485 | // The clip mask manager can rebuild all its clip masks so just |
| 486 | // get rid of them all. |
| 487 | fClipMaskManager->purgeResources(); |
| 488 | }; |
bsalomon | 5ea0363 | 2015-08-18 10:33:30 -0700 | [diff] [blame] | 489 | |
| 490 | void GrClipTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRenderTarget* rt) { |
| 491 | GrBatch* batch = SkNEW_ARGS(GrClearStencilClipBatch, (rect, insideClip, rt)); |
| 492 | this->onDrawBatch(batch); |
| 493 | batch->unref(); |
| 494 | } |