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