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 | } |
cdalton | d472792 | 2015-11-10 12:49:06 -0800 | [diff] [blame^] | 222 | GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps; |
| 223 | if (clip.clipCoverageFragmentProcessor()) { |
| 224 | arfps.set(&pipelineBuilder); |
| 225 | arfps.addCoverageFragmentProcessor(clip.clipCoverageFragmentProcessor()); |
| 226 | } |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 227 | |
bsalomon | ad792c1 | 2015-09-10 11:10:50 -0700 | [diff] [blame] | 228 | GrPipeline::CreateArgs args; |
cdalton | d472792 | 2015-11-10 12:49:06 -0800 | [diff] [blame^] | 229 | if (!this->installPipelineInDrawBatch(&pipelineBuilder, &clip.scissorState(), batch)) { |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 230 | return; |
| 231 | } |
bsalomon | ad792c1 | 2015-09-10 11:10:50 -0700 | [diff] [blame] | 232 | |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 233 | #ifdef ENABLE_MDB |
| 234 | SkASSERT(fRenderTarget); |
| 235 | batch->pipeline()->addDependenciesTo(fRenderTarget); |
| 236 | #endif |
| 237 | |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 238 | this->recordBatch(batch); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 239 | } |
| 240 | |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 241 | static const GrStencilSettings& winding_path_stencil_settings() { |
| 242 | GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, |
| 243 | kIncClamp_StencilOp, |
| 244 | kIncClamp_StencilOp, |
| 245 | kAlwaysIfInClip_StencilFunc, |
| 246 | 0xFFFF, 0xFFFF, 0xFFFF); |
| 247 | return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); |
| 248 | } |
| 249 | |
| 250 | static const GrStencilSettings& even_odd_path_stencil_settings() { |
| 251 | GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, |
| 252 | kInvert_StencilOp, |
| 253 | kInvert_StencilOp, |
| 254 | kAlwaysIfInClip_StencilFunc, |
| 255 | 0xFFFF, 0xFFFF, 0xFFFF); |
| 256 | return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); |
| 257 | } |
| 258 | |
| 259 | void GrDrawTarget::getPathStencilSettingsForFilltype(GrPathRendering::FillType fill, |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 260 | const GrStencilAttachment* sb, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 261 | GrStencilSettings* outStencilSettings) { |
| 262 | |
| 263 | switch (fill) { |
| 264 | default: |
| 265 | SkFAIL("Unexpected path fill."); |
| 266 | case GrPathRendering::kWinding_FillType: |
| 267 | *outStencilSettings = winding_path_stencil_settings(); |
| 268 | break; |
| 269 | case GrPathRendering::kEvenOdd_FillType: |
| 270 | *outStencilSettings = even_odd_path_stencil_settings(); |
| 271 | break; |
| 272 | } |
bsalomon | b3b9aec | 2015-09-10 11:16:35 -0700 | [diff] [blame] | 273 | fClipMaskManager->adjustPathStencilParams(sb, outStencilSettings); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 274 | } |
| 275 | |
joshualitt | 1c73548 | 2015-07-13 08:08:25 -0700 | [diff] [blame] | 276 | void GrDrawTarget::stencilPath(const GrPipelineBuilder& pipelineBuilder, |
joshualitt | f238469 | 2015-09-10 11:00:51 -0700 | [diff] [blame] | 277 | const SkMatrix& viewMatrix, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 278 | const GrPath* path, |
| 279 | GrPathRendering::FillType fill) { |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 280 | // TODO: extract portions of checkDraw that are relevant to path stenciling. |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 281 | SkASSERT(path); |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 282 | SkASSERT(this->caps()->shaderCaps()->pathRenderingSupport()); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 283 | |
| 284 | // Setup clip |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 285 | GrPipelineBuilder::AutoRestoreStencil ars; |
bsalomon | 0ba8c24 | 2015-10-07 09:20:28 -0700 | [diff] [blame] | 286 | GrAppliedClip clip; |
bsalomon | e91f7b5 | 2015-10-27 06:42:50 -0700 | [diff] [blame] | 287 | if (!fClipMaskManager->setupClipping(pipelineBuilder, &ars, nullptr, &clip)) { |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 288 | return; |
| 289 | } |
| 290 | |
bsalomon | 0ba8c24 | 2015-10-07 09:20:28 -0700 | [diff] [blame] | 291 | GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps; |
| 292 | if (clip.clipCoverageFragmentProcessor()) { |
| 293 | arfps.set(&pipelineBuilder); |
| 294 | arfps.addCoverageFragmentProcessor(clip.clipCoverageFragmentProcessor()); |
| 295 | } |
| 296 | |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 297 | // set stencil settings for path |
| 298 | GrStencilSettings stencilSettings; |
joshualitt | 1c73548 | 2015-07-13 08:08:25 -0700 | [diff] [blame] | 299 | GrRenderTarget* rt = pipelineBuilder.getRenderTarget(); |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 300 | GrStencilAttachment* sb = fResourceProvider->attachStencilAttachment(rt); |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 301 | this->getPathStencilSettingsForFilltype(fill, sb, &stencilSettings); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 302 | |
joshualitt | f238469 | 2015-09-10 11:00:51 -0700 | [diff] [blame] | 303 | GrBatch* batch = GrStencilPathBatch::Create(viewMatrix, |
bsalomon | a44919e | 2015-08-18 13:28:19 -0700 | [diff] [blame] | 304 | pipelineBuilder.isHWAntialias(), |
bsalomon | e91f7b5 | 2015-10-27 06:42:50 -0700 | [diff] [blame] | 305 | stencilSettings, clip.scissorState(), |
bsalomon | a44919e | 2015-08-18 13:28:19 -0700 | [diff] [blame] | 306 | pipelineBuilder.getRenderTarget(), |
| 307 | path); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 308 | this->recordBatch(batch); |
bsalomon | a44919e | 2015-08-18 13:28:19 -0700 | [diff] [blame] | 309 | batch->unref(); |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 310 | } |
| 311 | |
joshualitt | 1c73548 | 2015-07-13 08:08:25 -0700 | [diff] [blame] | 312 | void GrDrawTarget::drawPath(const GrPipelineBuilder& pipelineBuilder, |
joshualitt | f238469 | 2015-09-10 11:00:51 -0700 | [diff] [blame] | 313 | const SkMatrix& viewMatrix, |
| 314 | GrColor color, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 315 | const GrPath* path, |
| 316 | GrPathRendering::FillType fill) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 317 | SkASSERT(path); |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 318 | SkASSERT(this->caps()->shaderCaps()->pathRenderingSupport()); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 319 | |
joshualitt | f238469 | 2015-09-10 11:00:51 -0700 | [diff] [blame] | 320 | GrDrawPathBatchBase* batch = GrDrawPathBatch::Create(viewMatrix, color, path); |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 321 | this->drawPathBatch(pipelineBuilder, batch, fill); |
| 322 | batch->unref(); |
| 323 | } |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 324 | |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 325 | void GrDrawTarget::drawPathsFromRange(const GrPipelineBuilder& pipelineBuilder, |
joshualitt | f238469 | 2015-09-10 11:00:51 -0700 | [diff] [blame] | 326 | const SkMatrix& viewMatrix, |
| 327 | const SkMatrix& localMatrix, |
| 328 | GrColor color, |
cdalton | 8585dd2 | 2015-10-08 08:04:09 -0700 | [diff] [blame] | 329 | GrPathRange* range, |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 330 | GrPathRangeDraw* draw, |
| 331 | GrPathRendering::FillType fill) { |
cdalton | 8585dd2 | 2015-10-08 08:04:09 -0700 | [diff] [blame] | 332 | GrDrawPathBatchBase* batch = GrDrawPathRangeBatch::Create(viewMatrix, localMatrix, color, |
| 333 | range, draw); |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 334 | this->drawPathBatch(pipelineBuilder, batch, fill); |
| 335 | batch->unref(); |
| 336 | } |
| 337 | |
| 338 | void GrDrawTarget::drawPathBatch(const GrPipelineBuilder& pipelineBuilder, |
| 339 | GrDrawPathBatchBase* batch, |
| 340 | GrPathRendering::FillType fill) { |
bsalomon | add79ef | 2015-08-19 13:26:49 -0700 | [diff] [blame] | 341 | // 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] | 342 | // after setting up clipping but before onDrawBatch(). TODO: Figure out a better model for |
| 343 | // handling stencil settings WRT interactions between pipeline(builder), clipmaskmanager, and |
| 344 | // batches. |
bsalomon | add79ef | 2015-08-19 13:26:49 -0700 | [diff] [blame] | 345 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 346 | GrPipelineBuilder::AutoRestoreStencil ars; |
bsalomon | 0ba8c24 | 2015-10-07 09:20:28 -0700 | [diff] [blame] | 347 | GrAppliedClip clip; |
bsalomon | e91f7b5 | 2015-10-27 06:42:50 -0700 | [diff] [blame] | 348 | if (!fClipMaskManager->setupClipping(pipelineBuilder, &ars, &batch->bounds(), &clip)) { |
bsalomon | add79ef | 2015-08-19 13:26:49 -0700 | [diff] [blame] | 349 | return; |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 350 | } |
| 351 | |
cdalton | d472792 | 2015-11-10 12:49:06 -0800 | [diff] [blame^] | 352 | GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps; |
| 353 | if (clip.clipCoverageFragmentProcessor()) { |
| 354 | arfps.set(&pipelineBuilder); |
| 355 | arfps.addCoverageFragmentProcessor(clip.clipCoverageFragmentProcessor()); |
| 356 | } |
| 357 | |
bsalomon | add79ef | 2015-08-19 13:26:49 -0700 | [diff] [blame] | 358 | // Ensure the render target has a stencil buffer and get the stencil settings. |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 359 | GrStencilSettings stencilSettings; |
joshualitt | 1c73548 | 2015-07-13 08:08:25 -0700 | [diff] [blame] | 360 | GrRenderTarget* rt = pipelineBuilder.getRenderTarget(); |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 361 | GrStencilAttachment* sb = fResourceProvider->attachStencilAttachment(rt); |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 362 | this->getPathStencilSettingsForFilltype(fill, sb, &stencilSettings); |
bsalomon | add79ef | 2015-08-19 13:26:49 -0700 | [diff] [blame] | 363 | batch->setStencilSettings(stencilSettings); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 364 | |
bsalomon | ad792c1 | 2015-09-10 11:10:50 -0700 | [diff] [blame] | 365 | GrPipeline::CreateArgs args; |
cdalton | d472792 | 2015-11-10 12:49:06 -0800 | [diff] [blame^] | 366 | if (!this->installPipelineInDrawBatch(&pipelineBuilder, &clip.scissorState(), batch)) { |
bsalomon | add79ef | 2015-08-19 13:26:49 -0700 | [diff] [blame] | 367 | return; |
| 368 | } |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 369 | |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 370 | this->recordBatch(batch); |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 371 | } |
| 372 | |
joshualitt | d2b23e0 | 2015-08-21 10:53:34 -0700 | [diff] [blame] | 373 | void GrDrawTarget::drawNonAARect(const GrPipelineBuilder& pipelineBuilder, |
joshualitt | 1c73548 | 2015-07-13 08:08:25 -0700 | [diff] [blame] | 374 | GrColor color, |
| 375 | const SkMatrix& viewMatrix, |
joshualitt | b6b513b | 2015-08-21 10:25:18 -0700 | [diff] [blame] | 376 | const SkRect& rect) { |
joshualitt | d2b23e0 | 2015-08-21 10:53:34 -0700 | [diff] [blame] | 377 | SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateNonAAFill(color, viewMatrix, rect, |
| 378 | nullptr, nullptr)); |
joshualitt | ad17cfc | 2015-05-05 10:45:57 -0700 | [diff] [blame] | 379 | this->drawBatch(pipelineBuilder, batch); |
| 380 | } |
| 381 | |
joshualitt | d2b23e0 | 2015-08-21 10:53:34 -0700 | [diff] [blame] | 382 | void GrDrawTarget::drawNonAARect(const GrPipelineBuilder& pipelineBuilder, |
joshualitt | b6b513b | 2015-08-21 10:25:18 -0700 | [diff] [blame] | 383 | GrColor color, |
| 384 | const SkMatrix& viewMatrix, |
| 385 | const SkRect& rect, |
| 386 | const SkMatrix& localMatrix) { |
joshualitt | d2b23e0 | 2015-08-21 10:53:34 -0700 | [diff] [blame] | 387 | SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateNonAAFill(color, viewMatrix, rect, |
| 388 | nullptr, &localMatrix)); |
joshualitt | b6b513b | 2015-08-21 10:25:18 -0700 | [diff] [blame] | 389 | this->drawBatch(pipelineBuilder, batch); |
| 390 | } |
| 391 | |
joshualitt | d2b23e0 | 2015-08-21 10:53:34 -0700 | [diff] [blame] | 392 | void GrDrawTarget::drawNonAARect(const GrPipelineBuilder& pipelineBuilder, |
joshualitt | b6b513b | 2015-08-21 10:25:18 -0700 | [diff] [blame] | 393 | GrColor color, |
| 394 | const SkMatrix& viewMatrix, |
| 395 | const SkRect& rect, |
| 396 | const SkRect& localRect) { |
joshualitt | d2b23e0 | 2015-08-21 10:53:34 -0700 | [diff] [blame] | 397 | SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateNonAAFill(color, viewMatrix, rect, |
| 398 | &localRect, nullptr)); |
joshualitt | b6b513b | 2015-08-21 10:25:18 -0700 | [diff] [blame] | 399 | this->drawBatch(pipelineBuilder, batch); |
| 400 | } |
| 401 | |
| 402 | |
joshualitt | 1c73548 | 2015-07-13 08:08:25 -0700 | [diff] [blame] | 403 | void GrDrawTarget::drawAARect(const GrPipelineBuilder& pipelineBuilder, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 404 | GrColor color, |
| 405 | const SkMatrix& viewMatrix, |
| 406 | const SkRect& rect, |
| 407 | const SkRect& devRect) { |
joshualitt | d2b23e0 | 2015-08-21 10:53:34 -0700 | [diff] [blame] | 408 | SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateAAFill(color, viewMatrix, rect, |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 409 | devRect)); |
joshualitt | 14205b1 | 2015-08-10 11:40:56 -0700 | [diff] [blame] | 410 | this->drawBatch(pipelineBuilder, batch); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 411 | } |
| 412 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 413 | void GrDrawTarget::clear(const SkIRect* rect, |
| 414 | GrColor color, |
| 415 | bool canIgnoreRect, |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 416 | GrRenderTarget* renderTarget) { |
egdaniel | 51c8d40 | 2015-08-06 10:54:13 -0700 | [diff] [blame] | 417 | SkIRect rtRect = SkIRect::MakeWH(renderTarget->width(), renderTarget->height()); |
| 418 | SkIRect clippedRect; |
| 419 | if (!rect || |
| 420 | (canIgnoreRect && this->caps()->fullClearIsFree()) || |
| 421 | rect->contains(rtRect)) { |
| 422 | rect = &rtRect; |
| 423 | } else { |
| 424 | clippedRect = *rect; |
| 425 | if (!clippedRect.intersect(rtRect)) { |
| 426 | return; |
| 427 | } |
| 428 | rect = &clippedRect; |
| 429 | } |
| 430 | |
bsalomon | b3b9aec | 2015-09-10 11:16:35 -0700 | [diff] [blame] | 431 | if (this->caps()->useDrawInsteadOfClear()) { |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 432 | // This works around a driver bug with clear by drawing a rect instead. |
| 433 | // The driver will ignore a clear if it is the only thing rendered to a |
| 434 | // target before the target is read. |
egdaniel | 51c8d40 | 2015-08-06 10:54:13 -0700 | [diff] [blame] | 435 | if (rect == &rtRect) { |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 436 | this->discard(renderTarget); |
| 437 | } |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 438 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 439 | GrPipelineBuilder pipelineBuilder; |
| 440 | pipelineBuilder.setRenderTarget(renderTarget); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 441 | |
joshualitt | d2b23e0 | 2015-08-21 10:53:34 -0700 | [diff] [blame] | 442 | this->drawNonAARect(pipelineBuilder, color, SkMatrix::I(), *rect); |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 443 | } else { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 444 | GrBatch* batch = new GrClearBatch(*rect, color, renderTarget); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 445 | this->recordBatch(batch); |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 446 | batch->unref(); |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | void GrDrawTarget::discard(GrRenderTarget* renderTarget) { |
| 451 | if (this->caps()->discardRenderTargetSupport()) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 452 | GrBatch* batch = new GrDiscardBatch(renderTarget); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 453 | this->recordBatch(batch); |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 454 | batch->unref(); |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 455 | } |
| 456 | } |
| 457 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 458 | //////////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 459 | |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 460 | void GrDrawTarget::copySurface(GrSurface* dst, |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 461 | GrSurface* src, |
| 462 | const SkIRect& srcRect, |
| 463 | const SkIPoint& dstPoint) { |
bsalomon | 872062c | 2015-08-18 12:12:35 -0700 | [diff] [blame] | 464 | GrBatch* batch = GrCopySurfaceBatch::Create(dst, src, srcRect, dstPoint); |
| 465 | if (batch) { |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 466 | #ifdef ENABLE_MDB |
| 467 | this->addDependency(src); |
| 468 | #endif |
| 469 | |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 470 | this->recordBatch(batch); |
bsalomon | 872062c | 2015-08-18 12:12:35 -0700 | [diff] [blame] | 471 | batch->unref(); |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 472 | } |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 473 | } |
| 474 | |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 475 | template <class Left, class Right> static bool intersect(const Left& a, const Right& b) { |
| 476 | SkASSERT(a.fLeft <= a.fRight && a.fTop <= a.fBottom && |
| 477 | b.fLeft <= b.fRight && b.fTop <= b.fBottom); |
| 478 | return a.fLeft < b.fRight && b.fLeft < a.fRight && a.fTop < b.fBottom && b.fTop < a.fBottom; |
| 479 | } |
| 480 | |
| 481 | void GrDrawTarget::recordBatch(GrBatch* batch) { |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 482 | // A closed drawTarget should never receive new/more batches |
robertphillips | 6a18665 | 2015-10-20 07:37:58 -0700 | [diff] [blame] | 483 | SkASSERT(!this->isClosed()); |
bsalomon | 648c696 | 2015-10-23 09:06:59 -0700 | [diff] [blame] | 484 | // Should never have batches queued up when in immediate mode. |
| 485 | SkASSERT(!fOptions.fImmediateMode || !fBatches.count()); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 486 | |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 487 | // Check if there is a Batch Draw we can batch with by linearly searching back until we either |
| 488 | // 1) check every draw |
| 489 | // 2) intersect with something |
| 490 | // 3) find a 'blocker' |
| 491 | // Experimentally we have found that most batching occurs within the first 10 comparisons. |
| 492 | static const int kMaxLookback = 10; |
| 493 | |
| 494 | GrBATCH_INFO("Re-Recording (%s, B%u)\n" |
joshualitt | e2bcec3 | 2015-09-30 06:22:22 -0700 | [diff] [blame] | 495 | "\tBounds LRTB (%f, %f, %f, %f)\n", |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 496 | batch->name(), |
| 497 | batch->uniqueID(), |
| 498 | batch->bounds().fLeft, batch->bounds().fRight, |
| 499 | batch->bounds().fTop, batch->bounds().fBottom); |
| 500 | GrBATCH_INFO(SkTabString(batch->dumpInfo(), 1).c_str()); |
| 501 | GrBATCH_INFO("\tOutcome:\n"); |
| 502 | int maxCandidates = SkTMin(kMaxLookback, fBatches.count()); |
| 503 | if (maxCandidates) { |
| 504 | int i = 0; |
| 505 | while (true) { |
| 506 | GrBatch* candidate = fBatches.fromBack(i); |
| 507 | // We cannot continue to search backwards if the render target changes |
| 508 | if (candidate->renderTargetUniqueID() != batch->renderTargetUniqueID()) { |
| 509 | GrBATCH_INFO("\t\tBreaking because of (%s, B%u) Rendertarget\n", |
| 510 | candidate->name(), candidate->uniqueID()); |
| 511 | break; |
| 512 | } |
| 513 | if (candidate->combineIfPossible(batch, *this->caps())) { |
| 514 | GrBATCH_INFO("\t\tCombining with (%s, B%u)\n", candidate->name(), |
| 515 | candidate->uniqueID()); |
| 516 | return; |
| 517 | } |
| 518 | // Stop going backwards if we would cause a painter's order violation. |
| 519 | if (intersect(candidate->bounds(), batch->bounds())) { |
| 520 | GrBATCH_INFO("\t\tIntersects with (%s, B%u)\n", candidate->name(), |
| 521 | candidate->uniqueID()); |
| 522 | break; |
| 523 | } |
| 524 | ++i; |
| 525 | if (i == maxCandidates) { |
| 526 | GrBATCH_INFO("\t\tReached max lookback or beginning of batch array %d\n", i); |
| 527 | break; |
| 528 | } |
| 529 | } |
| 530 | } else { |
| 531 | GrBATCH_INFO("\t\tFirstBatch\n"); |
| 532 | } |
| 533 | fBatches.push_back().reset(SkRef(batch)); |
bsalomon | 648c696 | 2015-10-23 09:06:59 -0700 | [diff] [blame] | 534 | if (fOptions.fImmediateMode) { |
| 535 | this->flush(); |
| 536 | } |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 537 | } |
| 538 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 539 | /////////////////////////////////////////////////////////////////////////////// |
| 540 | |
bsalomon | ad792c1 | 2015-09-10 11:10:50 -0700 | [diff] [blame] | 541 | bool GrDrawTarget::installPipelineInDrawBatch(const GrPipelineBuilder* pipelineBuilder, |
cdalton | d472792 | 2015-11-10 12:49:06 -0800 | [diff] [blame^] | 542 | const GrScissorState* scissor, |
| 543 | GrDrawBatch* batch) { |
bsalomon | ad792c1 | 2015-09-10 11:10:50 -0700 | [diff] [blame] | 544 | GrPipeline::CreateArgs args; |
| 545 | args.fPipelineBuilder = pipelineBuilder; |
| 546 | args.fCaps = this->caps(); |
cdalton | d472792 | 2015-11-10 12:49:06 -0800 | [diff] [blame^] | 547 | args.fScissor = scissor; |
bsalomon | ad792c1 | 2015-09-10 11:10:50 -0700 | [diff] [blame] | 548 | args.fColorPOI = pipelineBuilder->colorProcInfo(batch); |
| 549 | args.fCoveragePOI = pipelineBuilder->coverageProcInfo(batch); |
| 550 | if (!this->setupDstReadIfNecessary(*pipelineBuilder, args.fColorPOI, |
| 551 | args.fCoveragePOI, &args.fDstTexture, |
| 552 | batch->bounds())) { |
| 553 | return false; |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 554 | } |
bsalomon | ad792c1 | 2015-09-10 11:10:50 -0700 | [diff] [blame] | 555 | |
| 556 | if (!batch->installPipeline(args)) { |
| 557 | return false; |
| 558 | } |
| 559 | |
| 560 | return true; |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 561 | } |
| 562 | |
bsalomon | b3b9aec | 2015-09-10 11:16:35 -0700 | [diff] [blame] | 563 | void GrDrawTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRenderTarget* rt) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 564 | GrBatch* batch = new GrClearStencilClipBatch(rect, insideClip, rt); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 565 | this->recordBatch(batch); |
bsalomon | 5ea0363 | 2015-08-18 10:33:30 -0700 | [diff] [blame] | 566 | batch->unref(); |
| 567 | } |