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 | |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 35 | GrDrawTarget::GrDrawTarget(GrRenderTarget* rt, GrGpu* gpu, GrResourceProvider* resourceProvider, |
bsalomon | 648c696 | 2015-10-23 09:06:59 -0700 | [diff] [blame] | 36 | const Options& options) |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 37 | : fGpu(SkRef(gpu)) |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 38 | , fResourceProvider(resourceProvider) |
robertphillips | 1f0e350 | 2015-11-10 10:19:50 -0800 | [diff] [blame^] | 39 | , fFlushState(fGpu, fResourceProvider) |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 40 | , fFlushing(false) |
bsalomon | 648c696 | 2015-10-23 09:06:59 -0700 | [diff] [blame] | 41 | , fFlags(0) |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 42 | , fOptions(options) |
| 43 | , fRenderTarget(rt) { |
bsalomon | b3b9aec | 2015-09-10 11:16:35 -0700 | [diff] [blame] | 44 | // TODO: Stop extracting the context (currently needed by GrClipMaskManager) |
| 45 | fContext = fGpu->getContext(); |
Brian Salomon | e66fec2 | 2015-09-10 14:40:20 -0400 | [diff] [blame] | 46 | fClipMaskManager.reset(new GrClipMaskManager(this)); |
robertphillips | 4beb5c1 | 2015-10-20 07:50:00 -0700 | [diff] [blame] | 47 | |
| 48 | #ifdef SK_DEBUG |
| 49 | static int debugID = 0; |
| 50 | fDebugID = debugID++; |
| 51 | #endif |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | GrDrawTarget::~GrDrawTarget() { |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 55 | if (fRenderTarget && this == fRenderTarget->getLastDrawTarget()) { |
| 56 | fRenderTarget->setLastDrawTarget(nullptr); |
| 57 | } |
| 58 | |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 59 | fGpu->unref(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | //////////////////////////////////////////////////////////////////////////////// |
| 63 | |
robertphillips | 6a18665 | 2015-10-20 07:37:58 -0700 | [diff] [blame] | 64 | // Add a GrDrawTarget-based dependency |
| 65 | void GrDrawTarget::addDependency(GrDrawTarget* dependedOn) { |
| 66 | SkASSERT(!dependedOn->dependsOn(this)); // loops are bad |
| 67 | |
| 68 | if (this->dependsOn(dependedOn)) { |
| 69 | return; // don't add duplicate dependencies |
| 70 | } |
| 71 | |
| 72 | *fDependencies.push() = dependedOn; |
| 73 | } |
| 74 | |
| 75 | // Convert from a GrSurface-based dependency to a GrDrawTarget one |
| 76 | void GrDrawTarget::addDependency(GrSurface* dependedOn) { |
| 77 | if (dependedOn->asRenderTarget() && dependedOn->asRenderTarget()->getLastDrawTarget()) { |
| 78 | // If it is still receiving dependencies, this DT shouldn't be closed |
| 79 | SkASSERT(!this->isClosed()); |
| 80 | |
| 81 | GrDrawTarget* dt = dependedOn->asRenderTarget()->getLastDrawTarget(); |
| 82 | if (dt == this) { |
| 83 | // self-read - presumably for dst reads |
| 84 | } else { |
| 85 | this->addDependency(dt); |
| 86 | |
| 87 | // Can't make it closed in the self-read case |
| 88 | dt->makeClosed(); |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | |
robertphillips | 4beb5c1 | 2015-10-20 07:50:00 -0700 | [diff] [blame] | 93 | #ifdef SK_DEBUG |
| 94 | void GrDrawTarget::dump() const { |
| 95 | SkDebugf("--------------------------------------------------------------\n"); |
| 96 | SkDebugf("node: %d\n"); |
| 97 | SkDebugf("relies On (%d): ", fDependencies.count()); |
| 98 | for (int i = 0; i < fDependencies.count(); ++i) { |
| 99 | SkDebugf("%d, ", fDependencies[i]->fDebugID); |
| 100 | } |
| 101 | SkDebugf("\n"); |
| 102 | SkDebugf("batches (%d):\n", fBatches.count()); |
| 103 | for (int i = 0; i < fBatches.count(); ++i) { |
| 104 | #if 0 |
| 105 | SkDebugf("*******************************\n"); |
| 106 | #endif |
| 107 | SkDebugf("%d: %s\n", i, fBatches[i]->name()); |
| 108 | #if 0 |
| 109 | SkString str = fBatches[i]->dumpInfo(); |
| 110 | SkDebugf("%s\n", str.c_str()); |
| 111 | #endif |
| 112 | } |
| 113 | } |
| 114 | #endif |
| 115 | |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 116 | bool GrDrawTarget::setupDstReadIfNecessary(const GrPipelineBuilder& pipelineBuilder, |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 117 | const GrProcOptInfo& colorPOI, |
| 118 | const GrProcOptInfo& coveragePOI, |
bsalomon | 6a44c6a | 2015-05-26 09:49:05 -0700 | [diff] [blame] | 119 | GrXferProcessor::DstTexture* dstTexture, |
bsalomon | ad792c1 | 2015-09-10 11:10:50 -0700 | [diff] [blame] | 120 | const SkRect& batchBounds) { |
| 121 | SkRect bounds = batchBounds; |
| 122 | bounds.outset(0.5f, 0.5f); |
| 123 | |
bsalomon | 6a44c6a | 2015-05-26 09:49:05 -0700 | [diff] [blame] | 124 | if (!pipelineBuilder.willXPNeedDstTexture(*this->caps(), colorPOI, coveragePOI)) { |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 125 | return true; |
| 126 | } |
cdalton | 9954bc3 | 2015-04-29 14:17:00 -0700 | [diff] [blame] | 127 | |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 128 | GrRenderTarget* rt = pipelineBuilder.getRenderTarget(); |
cdalton | 9954bc3 | 2015-04-29 14:17:00 -0700 | [diff] [blame] | 129 | |
| 130 | if (this->caps()->textureBarrierSupport()) { |
| 131 | if (GrTexture* rtTex = rt->asTexture()) { |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 132 | // 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] | 133 | // will be responsible to detect this situation and request a texture barrier. |
bsalomon | 6a44c6a | 2015-05-26 09:49:05 -0700 | [diff] [blame] | 134 | dstTexture->setTexture(rtTex); |
| 135 | dstTexture->setOffset(0, 0); |
cdalton | 9954bc3 | 2015-04-29 14:17:00 -0700 | [diff] [blame] | 136 | return true; |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | SkIRect copyRect; |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 141 | pipelineBuilder.clip().getConservativeBounds(rt, ©Rect); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 142 | |
bsalomon | ad792c1 | 2015-09-10 11:10:50 -0700 | [diff] [blame] | 143 | SkIRect drawIBounds; |
| 144 | bounds.roundOut(&drawIBounds); |
| 145 | if (!copyRect.intersect(drawIBounds)) { |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 146 | #ifdef SK_DEBUG |
bsalomon | b3b9aec | 2015-09-10 11:16:35 -0700 | [diff] [blame] | 147 | GrCapsDebugf(this->caps(), "Missed an early reject. " |
| 148 | "Bailing on draw from setupDstReadIfNecessary.\n"); |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 149 | #endif |
bsalomon | ad792c1 | 2015-09-10 11:10:50 -0700 | [diff] [blame] | 150 | return false; |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 151 | } |
skia.committer@gmail.com | 05a2ee0 | 2013-04-02 07:01:34 +0000 | [diff] [blame] | 152 | |
commit-bot@chromium.org | 63150af | 2013-04-11 22:00:22 +0000 | [diff] [blame] | 153 | // MSAA consideration: When there is support for reading MSAA samples in the shader we could |
| 154 | // have per-sample dst values by making the copy multisampled. |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 155 | GrSurfaceDesc desc; |
bsalomon | b3b9aec | 2015-09-10 11:16:35 -0700 | [diff] [blame] | 156 | if (!fGpu->initCopySurfaceDstDesc(rt, &desc)) { |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 157 | desc.fOrigin = kDefault_GrSurfaceOrigin; |
| 158 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 159 | desc.fConfig = rt->config(); |
| 160 | } |
| 161 | |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 162 | desc.fWidth = copyRect.width(); |
| 163 | desc.fHeight = copyRect.height(); |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 164 | |
bsalomon | eae6200 | 2015-07-31 13:59:30 -0700 | [diff] [blame] | 165 | static const uint32_t kFlags = 0; |
| 166 | SkAutoTUnref<GrTexture> copy(fResourceProvider->createApproxTexture(desc, kFlags)); |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 167 | |
bsalomon | e305973 | 2014-10-14 11:47:22 -0700 | [diff] [blame] | 168 | if (!copy) { |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 169 | SkDebugf("Failed to create temporary copy of destination texture.\n"); |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 170 | return false; |
| 171 | } |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 172 | SkIPoint dstPoint = {0, 0}; |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 173 | this->copySurface(copy, rt, copyRect, dstPoint); |
| 174 | dstTexture->setTexture(copy); |
| 175 | dstTexture->setOffset(copyRect.fLeft, copyRect.fTop); |
| 176 | return true; |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 177 | } |
| 178 | |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 179 | void GrDrawTarget::flush() { |
| 180 | if (fFlushing) { |
| 181 | return; |
| 182 | } |
| 183 | fFlushing = true; |
| 184 | |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 185 | // Semi-usually the drawTargets are already closed at this point, but sometimes Ganesh |
| 186 | // needs to flush mid-draw. In that case, the SkGpuDevice's drawTargets won't be closed |
| 187 | // but need to be flushed anyway. Closing such drawTargets here will mean new |
| 188 | // drawTargets will be created to replace them if the SkGpuDevice(s) write to them again. |
| 189 | this->makeClosed(); |
| 190 | |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 191 | // Loop over the batches that haven't yet generated their geometry |
robertphillips | 1f0e350 | 2015-11-10 10:19:50 -0800 | [diff] [blame^] | 192 | for (int i = 0; i < fBatches.count(); ++i) { |
| 193 | fBatches[i]->prepare(&fFlushState); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | // Upload all data to the GPU |
joshualitt | f6d259b | 2015-10-02 11:27:14 -0700 | [diff] [blame] | 197 | fFlushState.preIssueDraws(); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 198 | |
| 199 | // Draw all the generated geometry. |
| 200 | for (int i = 0; i < fBatches.count(); ++i) { |
joshualitt | f6d259b | 2015-10-02 11:27:14 -0700 | [diff] [blame] | 201 | fBatches[i]->draw(&fFlushState); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 202 | } |
| 203 | |
joshualitt | f6d259b | 2015-10-02 11:27:14 -0700 | [diff] [blame] | 204 | SkASSERT(fFlushState.lastFlushedToken() == fFlushState.currentToken()); |
| 205 | this->reset(); |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 206 | |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 207 | fFlushing = false; |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 208 | } |
| 209 | |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 210 | void GrDrawTarget::reset() { |
| 211 | fBatches.reset(); |
joshualitt | f6d259b | 2015-10-02 11:27:14 -0700 | [diff] [blame] | 212 | fFlushState.reset(); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 213 | } |
| 214 | |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 215 | void GrDrawTarget::drawBatch(const GrPipelineBuilder& pipelineBuilder, GrDrawBatch* batch) { |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 216 | // Setup clip |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 217 | GrPipelineBuilder::AutoRestoreStencil ars; |
bsalomon | 0ba8c24 | 2015-10-07 09:20:28 -0700 | [diff] [blame] | 218 | GrAppliedClip clip; |
bsalomon | e91f7b5 | 2015-10-27 06:42:50 -0700 | [diff] [blame] | 219 | if (!fClipMaskManager->setupClipping(pipelineBuilder, &ars, &batch->bounds(), &clip)) { |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 220 | return; |
| 221 | } |
| 222 | |
bsalomon | ad792c1 | 2015-09-10 11:10:50 -0700 | [diff] [blame] | 223 | GrPipeline::CreateArgs args; |
cdalton | 14184d5 | 2015-11-09 15:12:19 -0800 | [diff] [blame] | 224 | if (!this->installPipelineInDrawBatch(&pipelineBuilder, &clip, batch)) { |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 225 | return; |
| 226 | } |
bsalomon | ad792c1 | 2015-09-10 11:10:50 -0700 | [diff] [blame] | 227 | |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 228 | #ifdef ENABLE_MDB |
| 229 | SkASSERT(fRenderTarget); |
| 230 | batch->pipeline()->addDependenciesTo(fRenderTarget); |
| 231 | #endif |
| 232 | |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 233 | this->recordBatch(batch); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 234 | } |
| 235 | |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 236 | static const GrStencilSettings& winding_path_stencil_settings() { |
| 237 | GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, |
| 238 | kIncClamp_StencilOp, |
| 239 | kIncClamp_StencilOp, |
| 240 | kAlwaysIfInClip_StencilFunc, |
| 241 | 0xFFFF, 0xFFFF, 0xFFFF); |
| 242 | return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); |
| 243 | } |
| 244 | |
| 245 | static const GrStencilSettings& even_odd_path_stencil_settings() { |
| 246 | GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, |
| 247 | kInvert_StencilOp, |
| 248 | kInvert_StencilOp, |
| 249 | kAlwaysIfInClip_StencilFunc, |
| 250 | 0xFFFF, 0xFFFF, 0xFFFF); |
| 251 | return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); |
| 252 | } |
| 253 | |
| 254 | void GrDrawTarget::getPathStencilSettingsForFilltype(GrPathRendering::FillType fill, |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 255 | const GrStencilAttachment* sb, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 256 | GrStencilSettings* outStencilSettings) { |
| 257 | |
| 258 | switch (fill) { |
| 259 | default: |
| 260 | SkFAIL("Unexpected path fill."); |
| 261 | case GrPathRendering::kWinding_FillType: |
| 262 | *outStencilSettings = winding_path_stencil_settings(); |
| 263 | break; |
| 264 | case GrPathRendering::kEvenOdd_FillType: |
| 265 | *outStencilSettings = even_odd_path_stencil_settings(); |
| 266 | break; |
| 267 | } |
bsalomon | b3b9aec | 2015-09-10 11:16:35 -0700 | [diff] [blame] | 268 | fClipMaskManager->adjustPathStencilParams(sb, outStencilSettings); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 269 | } |
| 270 | |
joshualitt | 1c73548 | 2015-07-13 08:08:25 -0700 | [diff] [blame] | 271 | void GrDrawTarget::stencilPath(const GrPipelineBuilder& pipelineBuilder, |
joshualitt | f238469 | 2015-09-10 11:00:51 -0700 | [diff] [blame] | 272 | const SkMatrix& viewMatrix, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 273 | const GrPath* path, |
| 274 | GrPathRendering::FillType fill) { |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 275 | // TODO: extract portions of checkDraw that are relevant to path stenciling. |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 276 | SkASSERT(path); |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 277 | SkASSERT(this->caps()->shaderCaps()->pathRenderingSupport()); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 278 | |
| 279 | // Setup clip |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 280 | GrPipelineBuilder::AutoRestoreStencil ars; |
bsalomon | 0ba8c24 | 2015-10-07 09:20:28 -0700 | [diff] [blame] | 281 | GrAppliedClip clip; |
bsalomon | e91f7b5 | 2015-10-27 06:42:50 -0700 | [diff] [blame] | 282 | if (!fClipMaskManager->setupClipping(pipelineBuilder, &ars, nullptr, &clip)) { |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 283 | return; |
| 284 | } |
| 285 | |
bsalomon | 0ba8c24 | 2015-10-07 09:20:28 -0700 | [diff] [blame] | 286 | GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps; |
| 287 | if (clip.clipCoverageFragmentProcessor()) { |
| 288 | arfps.set(&pipelineBuilder); |
| 289 | arfps.addCoverageFragmentProcessor(clip.clipCoverageFragmentProcessor()); |
| 290 | } |
| 291 | |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 292 | // set stencil settings for path |
| 293 | GrStencilSettings stencilSettings; |
joshualitt | 1c73548 | 2015-07-13 08:08:25 -0700 | [diff] [blame] | 294 | GrRenderTarget* rt = pipelineBuilder.getRenderTarget(); |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 295 | GrStencilAttachment* sb = fResourceProvider->attachStencilAttachment(rt); |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 296 | this->getPathStencilSettingsForFilltype(fill, sb, &stencilSettings); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 297 | |
joshualitt | f238469 | 2015-09-10 11:00:51 -0700 | [diff] [blame] | 298 | GrBatch* batch = GrStencilPathBatch::Create(viewMatrix, |
bsalomon | a44919e | 2015-08-18 13:28:19 -0700 | [diff] [blame] | 299 | pipelineBuilder.isHWAntialias(), |
bsalomon | e91f7b5 | 2015-10-27 06:42:50 -0700 | [diff] [blame] | 300 | stencilSettings, clip.scissorState(), |
bsalomon | a44919e | 2015-08-18 13:28:19 -0700 | [diff] [blame] | 301 | pipelineBuilder.getRenderTarget(), |
| 302 | path); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 303 | this->recordBatch(batch); |
bsalomon | a44919e | 2015-08-18 13:28:19 -0700 | [diff] [blame] | 304 | batch->unref(); |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 305 | } |
| 306 | |
joshualitt | 1c73548 | 2015-07-13 08:08:25 -0700 | [diff] [blame] | 307 | void GrDrawTarget::drawPath(const GrPipelineBuilder& pipelineBuilder, |
joshualitt | f238469 | 2015-09-10 11:00:51 -0700 | [diff] [blame] | 308 | const SkMatrix& viewMatrix, |
| 309 | GrColor color, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 310 | const GrPath* path, |
| 311 | GrPathRendering::FillType fill) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 312 | SkASSERT(path); |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 313 | SkASSERT(this->caps()->shaderCaps()->pathRenderingSupport()); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 314 | |
joshualitt | f238469 | 2015-09-10 11:00:51 -0700 | [diff] [blame] | 315 | GrDrawPathBatchBase* batch = GrDrawPathBatch::Create(viewMatrix, color, path); |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 316 | this->drawPathBatch(pipelineBuilder, batch, fill); |
| 317 | batch->unref(); |
| 318 | } |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 319 | |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 320 | void GrDrawTarget::drawPathsFromRange(const GrPipelineBuilder& pipelineBuilder, |
joshualitt | f238469 | 2015-09-10 11:00:51 -0700 | [diff] [blame] | 321 | const SkMatrix& viewMatrix, |
| 322 | const SkMatrix& localMatrix, |
| 323 | GrColor color, |
cdalton | 8585dd2 | 2015-10-08 08:04:09 -0700 | [diff] [blame] | 324 | GrPathRange* range, |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 325 | GrPathRangeDraw* draw, |
| 326 | GrPathRendering::FillType fill) { |
cdalton | 8585dd2 | 2015-10-08 08:04:09 -0700 | [diff] [blame] | 327 | GrDrawPathBatchBase* batch = GrDrawPathRangeBatch::Create(viewMatrix, localMatrix, color, |
| 328 | range, draw); |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 329 | this->drawPathBatch(pipelineBuilder, batch, fill); |
| 330 | batch->unref(); |
| 331 | } |
| 332 | |
| 333 | void GrDrawTarget::drawPathBatch(const GrPipelineBuilder& pipelineBuilder, |
| 334 | GrDrawPathBatchBase* batch, |
| 335 | GrPathRendering::FillType fill) { |
bsalomon | add79ef | 2015-08-19 13:26:49 -0700 | [diff] [blame] | 336 | // This looks like drawBatch() but there is an added wrinkle that stencil settings get inserted |
bsalomon | b3b9aec | 2015-09-10 11:16:35 -0700 | [diff] [blame] | 337 | // after setting up clipping but before onDrawBatch(). TODO: Figure out a better model for |
| 338 | // handling stencil settings WRT interactions between pipeline(builder), clipmaskmanager, and |
| 339 | // batches. |
bsalomon | add79ef | 2015-08-19 13:26:49 -0700 | [diff] [blame] | 340 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 341 | GrPipelineBuilder::AutoRestoreStencil ars; |
bsalomon | 0ba8c24 | 2015-10-07 09:20:28 -0700 | [diff] [blame] | 342 | GrAppliedClip clip; |
bsalomon | e91f7b5 | 2015-10-27 06:42:50 -0700 | [diff] [blame] | 343 | if (!fClipMaskManager->setupClipping(pipelineBuilder, &ars, &batch->bounds(), &clip)) { |
bsalomon | add79ef | 2015-08-19 13:26:49 -0700 | [diff] [blame] | 344 | return; |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 345 | } |
| 346 | |
bsalomon | add79ef | 2015-08-19 13:26:49 -0700 | [diff] [blame] | 347 | // Ensure the render target has a stencil buffer and get the stencil settings. |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 348 | GrStencilSettings stencilSettings; |
joshualitt | 1c73548 | 2015-07-13 08:08:25 -0700 | [diff] [blame] | 349 | GrRenderTarget* rt = pipelineBuilder.getRenderTarget(); |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 350 | GrStencilAttachment* sb = fResourceProvider->attachStencilAttachment(rt); |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 351 | this->getPathStencilSettingsForFilltype(fill, sb, &stencilSettings); |
bsalomon | add79ef | 2015-08-19 13:26:49 -0700 | [diff] [blame] | 352 | batch->setStencilSettings(stencilSettings); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 353 | |
bsalomon | ad792c1 | 2015-09-10 11:10:50 -0700 | [diff] [blame] | 354 | GrPipeline::CreateArgs args; |
cdalton | 14184d5 | 2015-11-09 15:12:19 -0800 | [diff] [blame] | 355 | if (!this->installPipelineInDrawBatch(&pipelineBuilder, &clip, batch)) { |
bsalomon | add79ef | 2015-08-19 13:26:49 -0700 | [diff] [blame] | 356 | return; |
| 357 | } |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 358 | |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 359 | this->recordBatch(batch); |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 360 | } |
| 361 | |
joshualitt | d2b23e0 | 2015-08-21 10:53:34 -0700 | [diff] [blame] | 362 | void GrDrawTarget::drawNonAARect(const GrPipelineBuilder& pipelineBuilder, |
joshualitt | 1c73548 | 2015-07-13 08:08:25 -0700 | [diff] [blame] | 363 | GrColor color, |
| 364 | const SkMatrix& viewMatrix, |
joshualitt | b6b513b | 2015-08-21 10:25:18 -0700 | [diff] [blame] | 365 | const SkRect& rect) { |
joshualitt | d2b23e0 | 2015-08-21 10:53:34 -0700 | [diff] [blame] | 366 | SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateNonAAFill(color, viewMatrix, rect, |
| 367 | nullptr, nullptr)); |
joshualitt | ad17cfc | 2015-05-05 10:45:57 -0700 | [diff] [blame] | 368 | this->drawBatch(pipelineBuilder, batch); |
| 369 | } |
| 370 | |
joshualitt | d2b23e0 | 2015-08-21 10:53:34 -0700 | [diff] [blame] | 371 | void GrDrawTarget::drawNonAARect(const GrPipelineBuilder& pipelineBuilder, |
joshualitt | b6b513b | 2015-08-21 10:25:18 -0700 | [diff] [blame] | 372 | GrColor color, |
| 373 | const SkMatrix& viewMatrix, |
| 374 | const SkRect& rect, |
| 375 | const SkMatrix& localMatrix) { |
joshualitt | d2b23e0 | 2015-08-21 10:53:34 -0700 | [diff] [blame] | 376 | SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateNonAAFill(color, viewMatrix, rect, |
| 377 | nullptr, &localMatrix)); |
joshualitt | b6b513b | 2015-08-21 10:25:18 -0700 | [diff] [blame] | 378 | this->drawBatch(pipelineBuilder, batch); |
| 379 | } |
| 380 | |
joshualitt | d2b23e0 | 2015-08-21 10:53:34 -0700 | [diff] [blame] | 381 | void GrDrawTarget::drawNonAARect(const GrPipelineBuilder& pipelineBuilder, |
joshualitt | b6b513b | 2015-08-21 10:25:18 -0700 | [diff] [blame] | 382 | GrColor color, |
| 383 | const SkMatrix& viewMatrix, |
| 384 | const SkRect& rect, |
| 385 | const SkRect& localRect) { |
joshualitt | d2b23e0 | 2015-08-21 10:53:34 -0700 | [diff] [blame] | 386 | SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateNonAAFill(color, viewMatrix, rect, |
| 387 | &localRect, nullptr)); |
joshualitt | b6b513b | 2015-08-21 10:25:18 -0700 | [diff] [blame] | 388 | this->drawBatch(pipelineBuilder, batch); |
| 389 | } |
| 390 | |
| 391 | |
joshualitt | 1c73548 | 2015-07-13 08:08:25 -0700 | [diff] [blame] | 392 | void GrDrawTarget::drawAARect(const GrPipelineBuilder& pipelineBuilder, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 393 | GrColor color, |
| 394 | const SkMatrix& viewMatrix, |
| 395 | const SkRect& rect, |
| 396 | const SkRect& devRect) { |
joshualitt | d2b23e0 | 2015-08-21 10:53:34 -0700 | [diff] [blame] | 397 | SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateAAFill(color, viewMatrix, rect, |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 398 | devRect)); |
joshualitt | 14205b1 | 2015-08-10 11:40:56 -0700 | [diff] [blame] | 399 | this->drawBatch(pipelineBuilder, batch); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 400 | } |
| 401 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 402 | void GrDrawTarget::clear(const SkIRect* rect, |
| 403 | GrColor color, |
| 404 | bool canIgnoreRect, |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 405 | GrRenderTarget* renderTarget) { |
egdaniel | 51c8d40 | 2015-08-06 10:54:13 -0700 | [diff] [blame] | 406 | SkIRect rtRect = SkIRect::MakeWH(renderTarget->width(), renderTarget->height()); |
| 407 | SkIRect clippedRect; |
| 408 | if (!rect || |
| 409 | (canIgnoreRect && this->caps()->fullClearIsFree()) || |
| 410 | rect->contains(rtRect)) { |
| 411 | rect = &rtRect; |
| 412 | } else { |
| 413 | clippedRect = *rect; |
| 414 | if (!clippedRect.intersect(rtRect)) { |
| 415 | return; |
| 416 | } |
| 417 | rect = &clippedRect; |
| 418 | } |
| 419 | |
bsalomon | b3b9aec | 2015-09-10 11:16:35 -0700 | [diff] [blame] | 420 | if (this->caps()->useDrawInsteadOfClear()) { |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 421 | // This works around a driver bug with clear by drawing a rect instead. |
| 422 | // The driver will ignore a clear if it is the only thing rendered to a |
| 423 | // target before the target is read. |
egdaniel | 51c8d40 | 2015-08-06 10:54:13 -0700 | [diff] [blame] | 424 | if (rect == &rtRect) { |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 425 | this->discard(renderTarget); |
| 426 | } |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 427 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 428 | GrPipelineBuilder pipelineBuilder; |
| 429 | pipelineBuilder.setRenderTarget(renderTarget); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 430 | |
joshualitt | d2b23e0 | 2015-08-21 10:53:34 -0700 | [diff] [blame] | 431 | this->drawNonAARect(pipelineBuilder, color, SkMatrix::I(), *rect); |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 432 | } else { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 433 | GrBatch* batch = new GrClearBatch(*rect, color, renderTarget); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 434 | this->recordBatch(batch); |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 435 | batch->unref(); |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | void GrDrawTarget::discard(GrRenderTarget* renderTarget) { |
| 440 | if (this->caps()->discardRenderTargetSupport()) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 441 | GrBatch* batch = new GrDiscardBatch(renderTarget); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 442 | this->recordBatch(batch); |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 443 | batch->unref(); |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 444 | } |
| 445 | } |
| 446 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 447 | //////////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 448 | |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 449 | void GrDrawTarget::copySurface(GrSurface* dst, |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 450 | GrSurface* src, |
| 451 | const SkIRect& srcRect, |
| 452 | const SkIPoint& dstPoint) { |
bsalomon | 872062c | 2015-08-18 12:12:35 -0700 | [diff] [blame] | 453 | GrBatch* batch = GrCopySurfaceBatch::Create(dst, src, srcRect, dstPoint); |
| 454 | if (batch) { |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 455 | #ifdef ENABLE_MDB |
| 456 | this->addDependency(src); |
| 457 | #endif |
| 458 | |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 459 | this->recordBatch(batch); |
bsalomon | 872062c | 2015-08-18 12:12:35 -0700 | [diff] [blame] | 460 | batch->unref(); |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 461 | } |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 462 | } |
| 463 | |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 464 | template <class Left, class Right> static bool intersect(const Left& a, const Right& b) { |
| 465 | SkASSERT(a.fLeft <= a.fRight && a.fTop <= a.fBottom && |
| 466 | b.fLeft <= b.fRight && b.fTop <= b.fBottom); |
| 467 | return a.fLeft < b.fRight && b.fLeft < a.fRight && a.fTop < b.fBottom && b.fTop < a.fBottom; |
| 468 | } |
| 469 | |
| 470 | void GrDrawTarget::recordBatch(GrBatch* batch) { |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 471 | // A closed drawTarget should never receive new/more batches |
robertphillips | 6a18665 | 2015-10-20 07:37:58 -0700 | [diff] [blame] | 472 | SkASSERT(!this->isClosed()); |
bsalomon | 648c696 | 2015-10-23 09:06:59 -0700 | [diff] [blame] | 473 | // Should never have batches queued up when in immediate mode. |
| 474 | SkASSERT(!fOptions.fImmediateMode || !fBatches.count()); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 475 | |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 476 | // Check if there is a Batch Draw we can batch with by linearly searching back until we either |
| 477 | // 1) check every draw |
| 478 | // 2) intersect with something |
| 479 | // 3) find a 'blocker' |
| 480 | // Experimentally we have found that most batching occurs within the first 10 comparisons. |
| 481 | static const int kMaxLookback = 10; |
| 482 | |
| 483 | GrBATCH_INFO("Re-Recording (%s, B%u)\n" |
joshualitt | e2bcec3 | 2015-09-30 06:22:22 -0700 | [diff] [blame] | 484 | "\tBounds LRTB (%f, %f, %f, %f)\n", |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 485 | batch->name(), |
| 486 | batch->uniqueID(), |
| 487 | batch->bounds().fLeft, batch->bounds().fRight, |
| 488 | batch->bounds().fTop, batch->bounds().fBottom); |
| 489 | GrBATCH_INFO(SkTabString(batch->dumpInfo(), 1).c_str()); |
| 490 | GrBATCH_INFO("\tOutcome:\n"); |
| 491 | int maxCandidates = SkTMin(kMaxLookback, fBatches.count()); |
| 492 | if (maxCandidates) { |
| 493 | int i = 0; |
| 494 | while (true) { |
| 495 | GrBatch* candidate = fBatches.fromBack(i); |
| 496 | // We cannot continue to search backwards if the render target changes |
| 497 | if (candidate->renderTargetUniqueID() != batch->renderTargetUniqueID()) { |
| 498 | GrBATCH_INFO("\t\tBreaking because of (%s, B%u) Rendertarget\n", |
| 499 | candidate->name(), candidate->uniqueID()); |
| 500 | break; |
| 501 | } |
| 502 | if (candidate->combineIfPossible(batch, *this->caps())) { |
| 503 | GrBATCH_INFO("\t\tCombining with (%s, B%u)\n", candidate->name(), |
| 504 | candidate->uniqueID()); |
| 505 | return; |
| 506 | } |
| 507 | // Stop going backwards if we would cause a painter's order violation. |
| 508 | if (intersect(candidate->bounds(), batch->bounds())) { |
| 509 | GrBATCH_INFO("\t\tIntersects with (%s, B%u)\n", candidate->name(), |
| 510 | candidate->uniqueID()); |
| 511 | break; |
| 512 | } |
| 513 | ++i; |
| 514 | if (i == maxCandidates) { |
| 515 | GrBATCH_INFO("\t\tReached max lookback or beginning of batch array %d\n", i); |
| 516 | break; |
| 517 | } |
| 518 | } |
| 519 | } else { |
| 520 | GrBATCH_INFO("\t\tFirstBatch\n"); |
| 521 | } |
| 522 | fBatches.push_back().reset(SkRef(batch)); |
bsalomon | 648c696 | 2015-10-23 09:06:59 -0700 | [diff] [blame] | 523 | if (fOptions.fImmediateMode) { |
| 524 | this->flush(); |
| 525 | } |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 526 | } |
| 527 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 528 | /////////////////////////////////////////////////////////////////////////////// |
| 529 | |
bsalomon | ad792c1 | 2015-09-10 11:10:50 -0700 | [diff] [blame] | 530 | bool GrDrawTarget::installPipelineInDrawBatch(const GrPipelineBuilder* pipelineBuilder, |
cdalton | 14184d5 | 2015-11-09 15:12:19 -0800 | [diff] [blame] | 531 | const GrAppliedClip* clip, GrDrawBatch* batch) { |
| 532 | GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps; |
| 533 | if (clip->clipCoverageFragmentProcessor()) { |
| 534 | arfps.set(pipelineBuilder); |
| 535 | arfps.addCoverageFragmentProcessor(clip->clipCoverageFragmentProcessor()); |
| 536 | } |
| 537 | |
bsalomon | ad792c1 | 2015-09-10 11:10:50 -0700 | [diff] [blame] | 538 | GrPipeline::CreateArgs args; |
| 539 | args.fPipelineBuilder = pipelineBuilder; |
| 540 | args.fCaps = this->caps(); |
bsalomon | ad792c1 | 2015-09-10 11:10:50 -0700 | [diff] [blame] | 541 | args.fColorPOI = pipelineBuilder->colorProcInfo(batch); |
| 542 | args.fCoveragePOI = pipelineBuilder->coverageProcInfo(batch); |
cdalton | 14184d5 | 2015-11-09 15:12:19 -0800 | [diff] [blame] | 543 | args.fClip = clip; |
bsalomon | ad792c1 | 2015-09-10 11:10:50 -0700 | [diff] [blame] | 544 | if (!this->setupDstReadIfNecessary(*pipelineBuilder, args.fColorPOI, |
| 545 | args.fCoveragePOI, &args.fDstTexture, |
| 546 | batch->bounds())) { |
| 547 | return false; |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 548 | } |
bsalomon | ad792c1 | 2015-09-10 11:10:50 -0700 | [diff] [blame] | 549 | |
| 550 | if (!batch->installPipeline(args)) { |
| 551 | return false; |
| 552 | } |
| 553 | |
| 554 | return true; |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 555 | } |
| 556 | |
bsalomon | b3b9aec | 2015-09-10 11:16:35 -0700 | [diff] [blame] | 557 | void GrDrawTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRenderTarget* rt) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 558 | GrBatch* batch = new GrClearStencilClipBatch(rect, insideClip, rt); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 559 | this->recordBatch(batch); |
bsalomon | 5ea0363 | 2015-08-18 10:33:30 -0700 | [diff] [blame] | 560 | batch->unref(); |
| 561 | } |