reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2010 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
joshualitt | c2893c5 | 2015-01-28 06:54:30 -0800 | [diff] [blame] | 8 | #include "GrDrawTarget.h" |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 9 | |
joshualitt | 086cee1 | 2016-01-12 06:45:24 -0800 | [diff] [blame] | 10 | #include "GrAuditTrail.h" |
bsalomon | eb1cb5c | 2015-05-22 08:01:09 -0700 | [diff] [blame] | 11 | #include "GrCaps.h" |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 12 | #include "GrDrawContext.h" |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 13 | #include "GrGpu.h" |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame^] | 14 | #include "GrGpuCommandBuffer.h" |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 15 | #include "GrPath.h" |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 16 | #include "GrPipeline.h" |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 17 | #include "GrMemoryPool.h" |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 18 | #include "GrRenderTarget.h" |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 19 | #include "GrResourceProvider.h" |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 20 | #include "GrRenderTargetPriv.h" |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 21 | #include "GrStencilAttachment.h" |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 22 | #include "GrSurfacePriv.h" |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 23 | #include "GrTexture.h" |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 24 | #include "gl/GrGLRenderTarget.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 25 | |
joshualitt | 086cee1 | 2016-01-12 06:45:24 -0800 | [diff] [blame] | 26 | #include "SkStrokeRec.h" |
| 27 | |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 28 | #include "batches/GrClearBatch.h" |
bsalomon | 872062c | 2015-08-18 12:12:35 -0700 | [diff] [blame] | 29 | #include "batches/GrCopySurfaceBatch.h" |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 30 | #include "batches/GrDiscardBatch.h" |
bsalomon | 16b9913 | 2015-08-13 14:55:50 -0700 | [diff] [blame] | 31 | #include "batches/GrDrawBatch.h" |
bsalomon | add79ef | 2015-08-19 13:26:49 -0700 | [diff] [blame] | 32 | #include "batches/GrDrawPathBatch.h" |
joshualitt | ecd1a69 | 2015-08-10 10:08:26 -0700 | [diff] [blame] | 33 | #include "batches/GrRectBatchFactory.h" |
bsalomon | a44919e | 2015-08-18 13:28:19 -0700 | [diff] [blame] | 34 | #include "batches/GrStencilPathBatch.h" |
joshualitt | 7441782 | 2015-08-07 11:42:16 -0700 | [diff] [blame] | 35 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 36 | //////////////////////////////////////////////////////////////////////////////// |
| 37 | |
bsalomon | 489147c | 2015-12-14 12:13:09 -0800 | [diff] [blame] | 38 | // Experimentally we have found that most batching occurs within the first 10 comparisons. |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 39 | static const int kDefaultMaxBatchLookback = 10; |
| 40 | static const int kDefaultMaxBatchLookahead = 10; |
bsalomon | 489147c | 2015-12-14 12:13:09 -0800 | [diff] [blame] | 41 | |
bsalomon | 69cfe95 | 2015-11-30 13:27:47 -0800 | [diff] [blame] | 42 | GrDrawTarget::GrDrawTarget(GrRenderTarget* rt, GrGpu* gpu, GrResourceProvider* resourceProvider, |
joshualitt | 086cee1 | 2016-01-12 06:45:24 -0800 | [diff] [blame] | 43 | GrAuditTrail* auditTrail, const Options& options) |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 44 | : fGpu(SkRef(gpu)) |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 45 | , fResourceProvider(resourceProvider) |
joshualitt | 086cee1 | 2016-01-12 06:45:24 -0800 | [diff] [blame] | 46 | , fAuditTrail(auditTrail) |
bsalomon | 648c696 | 2015-10-23 09:06:59 -0700 | [diff] [blame] | 47 | , fFlags(0) |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 48 | , fRenderTarget(rt) { |
bsalomon | b3b9aec | 2015-09-10 11:16:35 -0700 | [diff] [blame] | 49 | // TODO: Stop extracting the context (currently needed by GrClipMaskManager) |
| 50 | fContext = fGpu->getContext(); |
robertphillips | 4beb5c1 | 2015-10-20 07:50:00 -0700 | [diff] [blame] | 51 | |
cdalton | 862cff3 | 2016-05-12 15:09:48 -0700 | [diff] [blame] | 52 | fClipBatchToBounds = options.fClipBatchToBounds; |
bsalomon | 6dea83f | 2015-12-03 12:58:06 -0800 | [diff] [blame] | 53 | fDrawBatchBounds = options.fDrawBatchBounds; |
bsalomon | 489147c | 2015-12-14 12:13:09 -0800 | [diff] [blame] | 54 | fMaxBatchLookback = (options.fMaxBatchLookback < 0) ? kDefaultMaxBatchLookback : |
| 55 | options.fMaxBatchLookback; |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 56 | fMaxBatchLookahead = (options.fMaxBatchLookahead < 0) ? kDefaultMaxBatchLookahead : |
| 57 | options.fMaxBatchLookahead; |
bsalomon | 6dea83f | 2015-12-03 12:58:06 -0800 | [diff] [blame] | 58 | |
robertphillips | 0dfa62c | 2015-11-16 06:23:31 -0800 | [diff] [blame] | 59 | rt->setLastDrawTarget(this); |
| 60 | |
robertphillips | 4beb5c1 | 2015-10-20 07:50:00 -0700 | [diff] [blame] | 61 | #ifdef SK_DEBUG |
| 62 | static int debugID = 0; |
| 63 | fDebugID = debugID++; |
| 64 | #endif |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | GrDrawTarget::~GrDrawTarget() { |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 68 | if (fRenderTarget && this == fRenderTarget->getLastDrawTarget()) { |
| 69 | fRenderTarget->setLastDrawTarget(nullptr); |
| 70 | } |
| 71 | |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 72 | fGpu->unref(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | //////////////////////////////////////////////////////////////////////////////// |
| 76 | |
robertphillips | 6a18665 | 2015-10-20 07:37:58 -0700 | [diff] [blame] | 77 | // Add a GrDrawTarget-based dependency |
| 78 | void GrDrawTarget::addDependency(GrDrawTarget* dependedOn) { |
| 79 | SkASSERT(!dependedOn->dependsOn(this)); // loops are bad |
| 80 | |
| 81 | if (this->dependsOn(dependedOn)) { |
| 82 | return; // don't add duplicate dependencies |
| 83 | } |
| 84 | |
| 85 | *fDependencies.push() = dependedOn; |
| 86 | } |
| 87 | |
| 88 | // Convert from a GrSurface-based dependency to a GrDrawTarget one |
| 89 | void GrDrawTarget::addDependency(GrSurface* dependedOn) { |
| 90 | if (dependedOn->asRenderTarget() && dependedOn->asRenderTarget()->getLastDrawTarget()) { |
| 91 | // If it is still receiving dependencies, this DT shouldn't be closed |
| 92 | SkASSERT(!this->isClosed()); |
| 93 | |
| 94 | GrDrawTarget* dt = dependedOn->asRenderTarget()->getLastDrawTarget(); |
| 95 | if (dt == this) { |
| 96 | // self-read - presumably for dst reads |
| 97 | } else { |
| 98 | this->addDependency(dt); |
| 99 | |
| 100 | // Can't make it closed in the self-read case |
| 101 | dt->makeClosed(); |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | |
robertphillips | 4beb5c1 | 2015-10-20 07:50:00 -0700 | [diff] [blame] | 106 | #ifdef SK_DEBUG |
| 107 | void GrDrawTarget::dump() const { |
| 108 | SkDebugf("--------------------------------------------------------------\n"); |
robertphillips | e004bfc | 2015-11-16 09:06:59 -0800 | [diff] [blame] | 109 | SkDebugf("node: %d -> RT: %d\n", fDebugID, fRenderTarget ? fRenderTarget->getUniqueID() : -1); |
robertphillips | 4beb5c1 | 2015-10-20 07:50:00 -0700 | [diff] [blame] | 110 | SkDebugf("relies On (%d): ", fDependencies.count()); |
| 111 | for (int i = 0; i < fDependencies.count(); ++i) { |
| 112 | SkDebugf("%d, ", fDependencies[i]->fDebugID); |
| 113 | } |
| 114 | SkDebugf("\n"); |
| 115 | SkDebugf("batches (%d):\n", fBatches.count()); |
| 116 | for (int i = 0; i < fBatches.count(); ++i) { |
| 117 | #if 0 |
| 118 | SkDebugf("*******************************\n"); |
| 119 | #endif |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 120 | if (fBatches[i]) { |
| 121 | SkDebugf("%d: <combined forward>\n", i); |
| 122 | } else { |
| 123 | SkDebugf("%d: %s\n", i, fBatches[i]->name()); |
robertphillips | 4beb5c1 | 2015-10-20 07:50:00 -0700 | [diff] [blame] | 124 | #if 0 |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 125 | SkString str = fBatches[i]->dumpInfo(); |
| 126 | SkDebugf("%s\n", str.c_str()); |
robertphillips | 4beb5c1 | 2015-10-20 07:50:00 -0700 | [diff] [blame] | 127 | #endif |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 128 | } |
robertphillips | 4beb5c1 | 2015-10-20 07:50:00 -0700 | [diff] [blame] | 129 | } |
| 130 | } |
| 131 | #endif |
| 132 | |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 133 | bool GrDrawTarget::setupDstReadIfNecessary(const GrPipelineBuilder& pipelineBuilder, |
robertphillips | 55fdccc | 2016-06-06 06:16:20 -0700 | [diff] [blame] | 134 | GrRenderTarget* rt, |
cdalton | 862cff3 | 2016-05-12 15:09:48 -0700 | [diff] [blame] | 135 | const GrClip& clip, |
ethannicholas | de4166a | 2015-11-30 08:57:38 -0800 | [diff] [blame] | 136 | const GrPipelineOptimizations& optimizations, |
bsalomon | 6a44c6a | 2015-05-26 09:49:05 -0700 | [diff] [blame] | 137 | GrXferProcessor::DstTexture* dstTexture, |
bsalomon | ad792c1 | 2015-09-10 11:10:50 -0700 | [diff] [blame] | 138 | const SkRect& batchBounds) { |
| 139 | SkRect bounds = batchBounds; |
| 140 | bounds.outset(0.5f, 0.5f); |
| 141 | |
ethannicholas | de4166a | 2015-11-30 08:57:38 -0800 | [diff] [blame] | 142 | if (!pipelineBuilder.willXPNeedDstTexture(*this->caps(), optimizations)) { |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 143 | return true; |
| 144 | } |
cdalton | 9954bc3 | 2015-04-29 14:17:00 -0700 | [diff] [blame] | 145 | |
cdalton | 9954bc3 | 2015-04-29 14:17:00 -0700 | [diff] [blame] | 146 | if (this->caps()->textureBarrierSupport()) { |
| 147 | if (GrTexture* rtTex = rt->asTexture()) { |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 148 | // 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] | 149 | // will be responsible to detect this situation and request a texture barrier. |
bsalomon | 6a44c6a | 2015-05-26 09:49:05 -0700 | [diff] [blame] | 150 | dstTexture->setTexture(rtTex); |
| 151 | dstTexture->setOffset(0, 0); |
cdalton | 9954bc3 | 2015-04-29 14:17:00 -0700 | [diff] [blame] | 152 | return true; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | SkIRect copyRect; |
cdalton | 862cff3 | 2016-05-12 15:09:48 -0700 | [diff] [blame] | 157 | clip.getConservativeBounds(rt->width(), rt->height(), ©Rect); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 158 | |
bsalomon | ad792c1 | 2015-09-10 11:10:50 -0700 | [diff] [blame] | 159 | SkIRect drawIBounds; |
| 160 | bounds.roundOut(&drawIBounds); |
| 161 | if (!copyRect.intersect(drawIBounds)) { |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 162 | #ifdef SK_DEBUG |
bsalomon | b3b9aec | 2015-09-10 11:16:35 -0700 | [diff] [blame] | 163 | GrCapsDebugf(this->caps(), "Missed an early reject. " |
| 164 | "Bailing on draw from setupDstReadIfNecessary.\n"); |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 165 | #endif |
bsalomon | ad792c1 | 2015-09-10 11:10:50 -0700 | [diff] [blame] | 166 | return false; |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 167 | } |
skia.committer@gmail.com | 05a2ee0 | 2013-04-02 07:01:34 +0000 | [diff] [blame] | 168 | |
commit-bot@chromium.org | 63150af | 2013-04-11 22:00:22 +0000 | [diff] [blame] | 169 | // MSAA consideration: When there is support for reading MSAA samples in the shader we could |
| 170 | // have per-sample dst values by making the copy multisampled. |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 171 | GrSurfaceDesc desc; |
bsalomon | b3b9aec | 2015-09-10 11:16:35 -0700 | [diff] [blame] | 172 | if (!fGpu->initCopySurfaceDstDesc(rt, &desc)) { |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 173 | desc.fOrigin = kDefault_GrSurfaceOrigin; |
| 174 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 175 | desc.fConfig = rt->config(); |
| 176 | } |
| 177 | |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 178 | desc.fWidth = copyRect.width(); |
| 179 | desc.fHeight = copyRect.height(); |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 180 | |
bsalomon | eae6200 | 2015-07-31 13:59:30 -0700 | [diff] [blame] | 181 | static const uint32_t kFlags = 0; |
| 182 | SkAutoTUnref<GrTexture> copy(fResourceProvider->createApproxTexture(desc, kFlags)); |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 183 | |
bsalomon | e305973 | 2014-10-14 11:47:22 -0700 | [diff] [blame] | 184 | if (!copy) { |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 185 | SkDebugf("Failed to create temporary copy of destination texture.\n"); |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 186 | return false; |
| 187 | } |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 188 | SkIPoint dstPoint = {0, 0}; |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 189 | this->copySurface(copy, rt, copyRect, dstPoint); |
| 190 | dstTexture->setTexture(copy); |
| 191 | dstTexture->setOffset(copyRect.fLeft, copyRect.fTop); |
| 192 | return true; |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 193 | } |
| 194 | |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 195 | void GrDrawTarget::prepareBatches(GrBatchFlushState* flushState) { |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 196 | // Semi-usually the drawTargets are already closed at this point, but sometimes Ganesh |
| 197 | // needs to flush mid-draw. In that case, the SkGpuDevice's drawTargets won't be closed |
| 198 | // but need to be flushed anyway. Closing such drawTargets here will mean new |
| 199 | // drawTargets will be created to replace them if the SkGpuDevice(s) write to them again. |
| 200 | this->makeClosed(); |
| 201 | |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 202 | // Loop over the batches that haven't yet generated their geometry |
robertphillips | 1f0e350 | 2015-11-10 10:19:50 -0800 | [diff] [blame] | 203 | for (int i = 0; i < fBatches.count(); ++i) { |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 204 | if (fBatches[i]) { |
| 205 | fBatches[i]->prepare(flushState); |
| 206 | } |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 207 | } |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 208 | } |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 209 | |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 210 | void GrDrawTarget::drawBatches(GrBatchFlushState* flushState) { |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 211 | // Draw all the generated geometry. |
bsalomon | 6dea83f | 2015-12-03 12:58:06 -0800 | [diff] [blame] | 212 | SkRandom random; |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame^] | 213 | GrRenderTarget* currentRT = nullptr; |
| 214 | SkAutoTDelete<GrGpuCommandBuffer> commandBuffer; |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 215 | for (int i = 0; i < fBatches.count(); ++i) { |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 216 | if (!fBatches[i]) { |
| 217 | continue; |
| 218 | } |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame^] | 219 | if (fBatches[i]->renderTarget() != currentRT) { |
| 220 | if (commandBuffer) { |
| 221 | commandBuffer->end(); |
| 222 | // For now just use size of whole render target, but this should be updated to |
| 223 | // only be the actual bounds of the various draws. |
| 224 | SkIRect bounds = SkIRect::MakeWH(currentRT->width(), currentRT->height()); |
| 225 | commandBuffer->submit(bounds); |
| 226 | commandBuffer.reset(); |
| 227 | } |
| 228 | currentRT = fBatches[i]->renderTarget(); |
| 229 | if (currentRT) { |
| 230 | static const GrGpuCommandBuffer::LoadAndStoreInfo kBasicLoadStoreInfo |
| 231 | { GrGpuCommandBuffer::LoadOp::kLoad,GrGpuCommandBuffer::StoreOp::kStore, |
| 232 | GrColor_ILLEGAL }; |
| 233 | commandBuffer.reset(fGpu->createCommandBuffer(currentRT, |
| 234 | kBasicLoadStoreInfo, // Color |
| 235 | kBasicLoadStoreInfo)); // Stencil |
| 236 | } |
| 237 | flushState->setCommandBuffer(commandBuffer); |
| 238 | } |
bsalomon | 6dea83f | 2015-12-03 12:58:06 -0800 | [diff] [blame] | 239 | if (fDrawBatchBounds) { |
| 240 | const SkRect& bounds = fBatches[i]->bounds(); |
| 241 | SkIRect ibounds; |
| 242 | bounds.roundOut(&ibounds); |
| 243 | // In multi-draw buffer all the batches use the same render target and we won't need to |
| 244 | // get the batchs bounds. |
| 245 | if (GrRenderTarget* rt = fBatches[i]->renderTarget()) { |
| 246 | fGpu->drawDebugWireRect(rt, ibounds, 0xFF000000 | random.nextU()); |
| 247 | } |
| 248 | } |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 249 | fBatches[i]->draw(flushState); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 250 | } |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame^] | 251 | if (commandBuffer) { |
| 252 | commandBuffer->end(); |
| 253 | // For now just use size of whole render target, but this should be updated to |
| 254 | // only be the actual bounds of the various draws. |
| 255 | SkIRect bounds = SkIRect::MakeWH(currentRT->width(), currentRT->height()); |
| 256 | commandBuffer->submit(bounds); |
| 257 | flushState->setCommandBuffer(nullptr); |
| 258 | } |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 259 | |
jvanverth | d2d2eb9 | 2016-02-17 14:04:46 -0800 | [diff] [blame] | 260 | fGpu->finishDrawTarget(); |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 261 | } |
| 262 | |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 263 | void GrDrawTarget::reset() { |
| 264 | fBatches.reset(); |
| 265 | } |
| 266 | |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 267 | void GrDrawTarget::drawBatch(const GrPipelineBuilder& pipelineBuilder, |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 268 | GrDrawContext* drawContext, |
cdalton | 862cff3 | 2016-05-12 15:09:48 -0700 | [diff] [blame] | 269 | const GrClip& clip, |
| 270 | GrDrawBatch* batch) { |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 271 | // Setup clip |
cdalton | 862cff3 | 2016-05-12 15:09:48 -0700 | [diff] [blame] | 272 | GrAppliedClip appliedClip; |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 273 | if (!clip.apply(fContext, pipelineBuilder, drawContext, &batch->bounds(), &appliedClip)) { |
cdalton | 862cff3 | 2016-05-12 15:09:48 -0700 | [diff] [blame] | 274 | return; |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 275 | } |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 276 | |
robertphillips | 55fdccc | 2016-06-06 06:16:20 -0700 | [diff] [blame] | 277 | // TODO: this is the only remaining usage of the AutoRestoreFragmentProcessorState - remove it |
cdalton | d472792 | 2015-11-10 12:49:06 -0800 | [diff] [blame] | 278 | GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps; |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 279 | if (appliedClip.getClipCoverageFragmentProcessor()) { |
cdalton | d472792 | 2015-11-10 12:49:06 -0800 | [diff] [blame] | 280 | arfps.set(&pipelineBuilder); |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 281 | arfps.addCoverageFragmentProcessor(sk_ref_sp(appliedClip.getClipCoverageFragmentProcessor())); |
cdalton | d472792 | 2015-11-10 12:49:06 -0800 | [diff] [blame] | 282 | } |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 283 | |
bsalomon | ad792c1 | 2015-09-10 11:10:50 -0700 | [diff] [blame] | 284 | GrPipeline::CreateArgs args; |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 285 | args.fPipelineBuilder = &pipelineBuilder; |
robertphillips | 55fdccc | 2016-06-06 06:16:20 -0700 | [diff] [blame] | 286 | args.fDrawContext = drawContext; |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 287 | args.fCaps = this->caps(); |
cdalton | 862cff3 | 2016-05-12 15:09:48 -0700 | [diff] [blame] | 288 | args.fScissor = &appliedClip.scissorState(); |
| 289 | args.fHasStencilClip = appliedClip.hasStencilClip(); |
| 290 | if (pipelineBuilder.hasUserStencilSettings() || appliedClip.hasStencilClip()) { |
robertphillips | 55fdccc | 2016-06-06 06:16:20 -0700 | [diff] [blame] | 291 | if (!fResourceProvider->attachStencilAttachment(drawContext->accessRenderTarget())) { |
cdalton | 17bf820 | 2016-05-13 11:27:15 -0700 | [diff] [blame] | 292 | SkDebugf("ERROR creating stencil attachment. Draw skipped.\n"); |
| 293 | return; |
| 294 | } |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 295 | } |
| 296 | batch->getPipelineOptimizations(&args.fOpts); |
| 297 | GrScissorState finalScissor; |
cdalton | 862cff3 | 2016-05-12 15:09:48 -0700 | [diff] [blame] | 298 | if (args.fOpts.fOverrides.fUsePLSDstRead || fClipBatchToBounds) { |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 299 | GrGLIRect viewport; |
| 300 | viewport.fLeft = 0; |
| 301 | viewport.fBottom = 0; |
robertphillips | 55fdccc | 2016-06-06 06:16:20 -0700 | [diff] [blame] | 302 | viewport.fWidth = drawContext->width(); |
| 303 | viewport.fHeight = drawContext->height(); |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 304 | SkIRect ibounds; |
| 305 | ibounds.fLeft = SkTPin(SkScalarFloorToInt(batch->bounds().fLeft), viewport.fLeft, |
| 306 | viewport.fWidth); |
| 307 | ibounds.fTop = SkTPin(SkScalarFloorToInt(batch->bounds().fTop), viewport.fBottom, |
| 308 | viewport.fHeight); |
| 309 | ibounds.fRight = SkTPin(SkScalarCeilToInt(batch->bounds().fRight), viewport.fLeft, |
| 310 | viewport.fWidth); |
| 311 | ibounds.fBottom = SkTPin(SkScalarCeilToInt(batch->bounds().fBottom), viewport.fBottom, |
| 312 | viewport.fHeight); |
cdalton | 862cff3 | 2016-05-12 15:09:48 -0700 | [diff] [blame] | 313 | if (appliedClip.scissorState().enabled()) { |
| 314 | const SkIRect& scissorRect = appliedClip.scissorState().rect(); |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 315 | if (!ibounds.intersect(scissorRect)) { |
cdalton | 862cff3 | 2016-05-12 15:09:48 -0700 | [diff] [blame] | 316 | return; |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 317 | } |
| 318 | } |
| 319 | finalScissor.set(ibounds); |
| 320 | args.fScissor = &finalScissor; |
| 321 | } |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 322 | args.fOpts.fColorPOI.completeCalculations( |
| 323 | sk_sp_address_as_pointer_address(pipelineBuilder.fColorFragmentProcessors.begin()), |
| 324 | pipelineBuilder.numColorFragmentProcessors()); |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 325 | args.fOpts.fCoveragePOI.completeCalculations( |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 326 | sk_sp_address_as_pointer_address(pipelineBuilder.fCoverageFragmentProcessors.begin()), |
| 327 | pipelineBuilder.numCoverageFragmentProcessors()); |
robertphillips | 55fdccc | 2016-06-06 06:16:20 -0700 | [diff] [blame] | 328 | if (!this->setupDstReadIfNecessary(pipelineBuilder, drawContext->accessRenderTarget(), |
| 329 | clip, args.fOpts, |
| 330 | &args.fDstTexture, batch->bounds())) { |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 331 | return; |
| 332 | } |
| 333 | |
| 334 | if (!batch->installPipeline(args)) { |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 335 | return; |
| 336 | } |
bsalomon | ad792c1 | 2015-09-10 11:10:50 -0700 | [diff] [blame] | 337 | |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 338 | #ifdef ENABLE_MDB |
| 339 | SkASSERT(fRenderTarget); |
| 340 | batch->pipeline()->addDependenciesTo(fRenderTarget); |
| 341 | #endif |
| 342 | |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 343 | this->recordBatch(batch); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 344 | } |
| 345 | |
joshualitt | 1c73548 | 2015-07-13 08:08:25 -0700 | [diff] [blame] | 346 | void GrDrawTarget::stencilPath(const GrPipelineBuilder& pipelineBuilder, |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 347 | GrDrawContext* drawContext, |
cdalton | 862cff3 | 2016-05-12 15:09:48 -0700 | [diff] [blame] | 348 | const GrClip& clip, |
joshualitt | f238469 | 2015-09-10 11:00:51 -0700 | [diff] [blame] | 349 | const SkMatrix& viewMatrix, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 350 | const GrPath* path, |
| 351 | GrPathRendering::FillType fill) { |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 352 | // TODO: extract portions of checkDraw that are relevant to path stenciling. |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 353 | SkASSERT(path); |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 354 | SkASSERT(this->caps()->shaderCaps()->pathRenderingSupport()); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 355 | |
| 356 | // Setup clip |
cdalton | 862cff3 | 2016-05-12 15:09:48 -0700 | [diff] [blame] | 357 | GrAppliedClip appliedClip; |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 358 | if (!clip.apply(fContext, pipelineBuilder, drawContext, nullptr, &appliedClip)) { |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 359 | return; |
| 360 | } |
cdalton | 862cff3 | 2016-05-12 15:09:48 -0700 | [diff] [blame] | 361 | // TODO: respect fClipBatchToBounds if we ever start computing bounds here. |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 362 | |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 363 | // Coverage AA does not make sense when rendering to the stencil buffer. The caller should never |
| 364 | // attempt this in a situation that would require coverage AA. |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 365 | SkASSERT(!appliedClip.getClipCoverageFragmentProcessor()); |
bsalomon | 0ba8c24 | 2015-10-07 09:20:28 -0700 | [diff] [blame] | 366 | |
robertphillips | 55fdccc | 2016-06-06 06:16:20 -0700 | [diff] [blame] | 367 | GrStencilAttachment* stencilAttachment = fResourceProvider->attachStencilAttachment( |
| 368 | drawContext->accessRenderTarget()); |
cdalton | 17bf820 | 2016-05-13 11:27:15 -0700 | [diff] [blame] | 369 | if (!stencilAttachment) { |
| 370 | SkDebugf("ERROR creating stencil attachment. Draw skipped.\n"); |
| 371 | return; |
| 372 | } |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 373 | |
joshualitt | f238469 | 2015-09-10 11:00:51 -0700 | [diff] [blame] | 374 | GrBatch* batch = GrStencilPathBatch::Create(viewMatrix, |
bsalomon | a44919e | 2015-08-18 13:28:19 -0700 | [diff] [blame] | 375 | pipelineBuilder.isHWAntialias(), |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 376 | fill, |
cdalton | 862cff3 | 2016-05-12 15:09:48 -0700 | [diff] [blame] | 377 | appliedClip.hasStencilClip(), |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 378 | stencilAttachment->bits(), |
cdalton | 862cff3 | 2016-05-12 15:09:48 -0700 | [diff] [blame] | 379 | appliedClip.scissorState(), |
robertphillips | 55fdccc | 2016-06-06 06:16:20 -0700 | [diff] [blame] | 380 | drawContext->accessRenderTarget(), |
bsalomon | a44919e | 2015-08-18 13:28:19 -0700 | [diff] [blame] | 381 | path); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 382 | this->recordBatch(batch); |
bsalomon | a44919e | 2015-08-18 13:28:19 -0700 | [diff] [blame] | 383 | batch->unref(); |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 384 | } |
| 385 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 386 | void GrDrawTarget::clear(const SkIRect* rect, |
| 387 | GrColor color, |
| 388 | bool canIgnoreRect, |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 389 | GrDrawContext* drawContext) { |
| 390 | SkIRect rtRect = SkIRect::MakeWH(drawContext->width(), drawContext->height()); |
egdaniel | 51c8d40 | 2015-08-06 10:54:13 -0700 | [diff] [blame] | 391 | SkIRect clippedRect; |
| 392 | if (!rect || |
| 393 | (canIgnoreRect && this->caps()->fullClearIsFree()) || |
| 394 | rect->contains(rtRect)) { |
| 395 | rect = &rtRect; |
| 396 | } else { |
| 397 | clippedRect = *rect; |
| 398 | if (!clippedRect.intersect(rtRect)) { |
| 399 | return; |
| 400 | } |
| 401 | rect = &clippedRect; |
| 402 | } |
| 403 | |
bsalomon | b3b9aec | 2015-09-10 11:16:35 -0700 | [diff] [blame] | 404 | if (this->caps()->useDrawInsteadOfClear()) { |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 405 | // This works around a driver bug with clear by drawing a rect instead. |
| 406 | // The driver will ignore a clear if it is the only thing rendered to a |
| 407 | // target before the target is read. |
egdaniel | 51c8d40 | 2015-08-06 10:54:13 -0700 | [diff] [blame] | 408 | if (rect == &rtRect) { |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 409 | drawContext->discard(); |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 410 | } |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 411 | |
robertphillips | 55fdccc | 2016-06-06 06:16:20 -0700 | [diff] [blame] | 412 | // TODO: flip this into real draw! |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 413 | GrPipelineBuilder pipelineBuilder; |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 414 | pipelineBuilder.setXPFactory(GrPorterDuffXPFactory::Make(SkXfermode::kSrc_Mode)); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 415 | |
joshualitt | a8b8499 | 2016-01-13 13:35:35 -0800 | [diff] [blame] | 416 | SkRect scalarRect = SkRect::Make(*rect); |
| 417 | SkAutoTUnref<GrDrawBatch> batch( |
| 418 | GrRectBatchFactory::CreateNonAAFill(color, SkMatrix::I(), scalarRect, |
| 419 | nullptr, nullptr)); |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 420 | this->drawBatch(pipelineBuilder, drawContext, GrNoClip(), batch); |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 421 | } else { |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 422 | GrBatch* batch = new GrClearBatch(*rect, color, drawContext->accessRenderTarget()); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 423 | this->recordBatch(batch); |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 424 | batch->unref(); |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | void GrDrawTarget::discard(GrRenderTarget* renderTarget) { |
| 429 | if (this->caps()->discardRenderTargetSupport()) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 430 | GrBatch* batch = new GrDiscardBatch(renderTarget); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 431 | this->recordBatch(batch); |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 432 | batch->unref(); |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 433 | } |
| 434 | } |
| 435 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 436 | //////////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 437 | |
bsalomon | b8fea97 | 2016-02-16 07:34:17 -0800 | [diff] [blame] | 438 | bool GrDrawTarget::copySurface(GrSurface* dst, |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 439 | GrSurface* src, |
| 440 | const SkIRect& srcRect, |
| 441 | const SkIPoint& dstPoint) { |
bsalomon | 872062c | 2015-08-18 12:12:35 -0700 | [diff] [blame] | 442 | GrBatch* batch = GrCopySurfaceBatch::Create(dst, src, srcRect, dstPoint); |
bsalomon | b8fea97 | 2016-02-16 07:34:17 -0800 | [diff] [blame] | 443 | if (!batch) { |
| 444 | return false; |
| 445 | } |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 446 | #ifdef ENABLE_MDB |
bsalomon | b8fea97 | 2016-02-16 07:34:17 -0800 | [diff] [blame] | 447 | this->addDependency(src); |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 448 | #endif |
| 449 | |
bsalomon | b8fea97 | 2016-02-16 07:34:17 -0800 | [diff] [blame] | 450 | this->recordBatch(batch); |
| 451 | batch->unref(); |
| 452 | return true; |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 453 | } |
| 454 | |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 455 | template <class Left, class Right> static bool intersect(const Left& a, const Right& b) { |
| 456 | SkASSERT(a.fLeft <= a.fRight && a.fTop <= a.fBottom && |
| 457 | b.fLeft <= b.fRight && b.fTop <= b.fBottom); |
| 458 | return a.fLeft < b.fRight && b.fLeft < a.fRight && a.fTop < b.fBottom && b.fTop < a.fBottom; |
| 459 | } |
| 460 | |
| 461 | void GrDrawTarget::recordBatch(GrBatch* batch) { |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 462 | // A closed drawTarget should never receive new/more batches |
robertphillips | 6a18665 | 2015-10-20 07:37:58 -0700 | [diff] [blame] | 463 | SkASSERT(!this->isClosed()); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 464 | |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 465 | // Check if there is a Batch Draw we can batch with by linearly searching back until we either |
| 466 | // 1) check every draw |
| 467 | // 2) intersect with something |
| 468 | // 3) find a 'blocker' |
joshualitt | b0666ad | 2016-03-08 10:43:41 -0800 | [diff] [blame] | 469 | GR_AUDIT_TRAIL_ADDBATCH(fAuditTrail, batch); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 470 | GrBATCH_INFO("Re-Recording (%s, B%u)\n" |
joshualitt | e2bcec3 | 2015-09-30 06:22:22 -0700 | [diff] [blame] | 471 | "\tBounds LRTB (%f, %f, %f, %f)\n", |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 472 | batch->name(), |
| 473 | batch->uniqueID(), |
| 474 | batch->bounds().fLeft, batch->bounds().fRight, |
| 475 | batch->bounds().fTop, batch->bounds().fBottom); |
| 476 | GrBATCH_INFO(SkTabString(batch->dumpInfo(), 1).c_str()); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 477 | GrBATCH_INFO("\tOutcome:\n"); |
bsalomon | 489147c | 2015-12-14 12:13:09 -0800 | [diff] [blame] | 478 | int maxCandidates = SkTMin(fMaxBatchLookback, fBatches.count()); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 479 | if (maxCandidates) { |
| 480 | int i = 0; |
| 481 | while (true) { |
| 482 | GrBatch* candidate = fBatches.fromBack(i); |
| 483 | // We cannot continue to search backwards if the render target changes |
| 484 | if (candidate->renderTargetUniqueID() != batch->renderTargetUniqueID()) { |
| 485 | GrBATCH_INFO("\t\tBreaking because of (%s, B%u) Rendertarget\n", |
| 486 | candidate->name(), candidate->uniqueID()); |
| 487 | break; |
| 488 | } |
| 489 | if (candidate->combineIfPossible(batch, *this->caps())) { |
| 490 | GrBATCH_INFO("\t\tCombining with (%s, B%u)\n", candidate->name(), |
| 491 | candidate->uniqueID()); |
joshualitt | b0666ad | 2016-03-08 10:43:41 -0800 | [diff] [blame] | 492 | GR_AUDIT_TRAIL_BATCHING_RESULT_COMBINED(fAuditTrail, candidate, batch); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 493 | return; |
| 494 | } |
| 495 | // Stop going backwards if we would cause a painter's order violation. |
bsalomon | db4758c | 2015-11-23 11:14:20 -0800 | [diff] [blame] | 496 | // TODO: The bounds used here do not fully consider the clip. It may be advantageous |
| 497 | // to clip each batch's bounds to the clip. |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 498 | if (intersect(candidate->bounds(), batch->bounds())) { |
| 499 | GrBATCH_INFO("\t\tIntersects with (%s, B%u)\n", candidate->name(), |
| 500 | candidate->uniqueID()); |
| 501 | break; |
| 502 | } |
| 503 | ++i; |
| 504 | if (i == maxCandidates) { |
| 505 | GrBATCH_INFO("\t\tReached max lookback or beginning of batch array %d\n", i); |
| 506 | break; |
| 507 | } |
| 508 | } |
| 509 | } else { |
| 510 | GrBATCH_INFO("\t\tFirstBatch\n"); |
| 511 | } |
joshualitt | 18d6b75 | 2016-02-26 08:07:50 -0800 | [diff] [blame] | 512 | GR_AUDIT_TRAIL_BATCHING_RESULT_NEW(fAuditTrail, batch); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 513 | fBatches.push_back().reset(SkRef(batch)); |
| 514 | } |
| 515 | |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 516 | void GrDrawTarget::forwardCombine() { |
| 517 | for (int i = 0; i < fBatches.count() - 2; ++i) { |
| 518 | GrBatch* batch = fBatches[i]; |
| 519 | int maxCandidateIdx = SkTMin(i + fMaxBatchLookahead, fBatches.count() - 1); |
| 520 | int j = i + 1; |
| 521 | while (true) { |
| 522 | GrBatch* candidate = fBatches[j]; |
| 523 | // We cannot continue to search if the render target changes |
| 524 | if (candidate->renderTargetUniqueID() != batch->renderTargetUniqueID()) { |
| 525 | GrBATCH_INFO("\t\tBreaking because of (%s, B%u) Rendertarget\n", |
| 526 | candidate->name(), candidate->uniqueID()); |
| 527 | break; |
| 528 | } |
| 529 | if (j == i +1) { |
| 530 | // We assume batch would have combined with candidate when the candidate was added |
| 531 | // via backwards combining in recordBatch. |
| 532 | SkASSERT(!batch->combineIfPossible(candidate, *this->caps())); |
| 533 | } else if (batch->combineIfPossible(candidate, *this->caps())) { |
| 534 | GrBATCH_INFO("\t\tCombining with (%s, B%u)\n", candidate->name(), |
| 535 | candidate->uniqueID()); |
joshualitt | b0666ad | 2016-03-08 10:43:41 -0800 | [diff] [blame] | 536 | GR_AUDIT_TRAIL_BATCHING_RESULT_COMBINED(fAuditTrail, batch, candidate); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 537 | fBatches[j].reset(SkRef(batch)); |
| 538 | fBatches[i].reset(nullptr); |
| 539 | break; |
| 540 | } |
| 541 | // Stop going traversing if we would cause a painter's order violation. |
| 542 | // TODO: The bounds used here do not fully consider the clip. It may be advantageous |
| 543 | // to clip each batch's bounds to the clip. |
| 544 | if (intersect(candidate->bounds(), batch->bounds())) { |
| 545 | GrBATCH_INFO("\t\tIntersects with (%s, B%u)\n", candidate->name(), |
| 546 | candidate->uniqueID()); |
| 547 | break; |
| 548 | } |
| 549 | ++j; |
| 550 | if (j > maxCandidateIdx) { |
| 551 | GrBATCH_INFO("\t\tReached max lookahead or end of batch array %d\n", i); |
| 552 | break; |
| 553 | } |
| 554 | } |
| 555 | } |
| 556 | } |
| 557 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 558 | /////////////////////////////////////////////////////////////////////////////// |
| 559 | |
bsalomon | b3b9aec | 2015-09-10 11:16:35 -0700 | [diff] [blame] | 560 | void GrDrawTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRenderTarget* rt) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 561 | GrBatch* batch = new GrClearStencilClipBatch(rect, insideClip, rt); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 562 | this->recordBatch(batch); |
bsalomon | 5ea0363 | 2015-08-18 10:33:30 -0700 | [diff] [blame] | 563 | batch->unref(); |
| 564 | } |