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 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 8 | #include "GrRenderTargetOpList.h" |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 9 | |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 10 | #include "GrAppliedClip.h" |
joshualitt | 086cee1 | 2016-01-12 06:45:24 -0800 | [diff] [blame] | 11 | #include "GrAuditTrail.h" |
bsalomon | eb1cb5c | 2015-05-22 08:01:09 -0700 | [diff] [blame] | 12 | #include "GrCaps.h" |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 13 | #include "GrRenderTargetContext.h" |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 14 | #include "GrGpu.h" |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 15 | #include "GrGpuCommandBuffer.h" |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 16 | #include "GrPath.h" |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 17 | #include "GrPipeline.h" |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 18 | #include "GrMemoryPool.h" |
robertphillips | 5fa7f30 | 2016-07-21 09:21:04 -0700 | [diff] [blame] | 19 | #include "GrPipelineBuilder.h" |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 20 | #include "GrRenderTarget.h" |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 21 | #include "GrResourceProvider.h" |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 22 | #include "GrRenderTargetPriv.h" |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 23 | #include "GrStencilAttachment.h" |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 24 | #include "GrSurfacePriv.h" |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 25 | #include "GrTexture.h" |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 26 | #include "gl/GrGLRenderTarget.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 27 | |
joshualitt | 086cee1 | 2016-01-12 06:45:24 -0800 | [diff] [blame] | 28 | #include "SkStrokeRec.h" |
| 29 | |
bsalomon | 9f129de | 2016-08-10 16:31:05 -0700 | [diff] [blame] | 30 | #include "batches/GrClearBatch.h" |
robertphillips | 9199a9f | 2016-07-13 07:48:43 -0700 | [diff] [blame] | 31 | #include "batches/GrClearStencilClipBatch.h" |
bsalomon | 872062c | 2015-08-18 12:12:35 -0700 | [diff] [blame] | 32 | #include "batches/GrCopySurfaceBatch.h" |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 33 | #include "batches/GrDiscardBatch.h" |
bsalomon | 16b9913 | 2015-08-13 14:55:50 -0700 | [diff] [blame] | 34 | #include "batches/GrDrawBatch.h" |
bsalomon | add79ef | 2015-08-19 13:26:49 -0700 | [diff] [blame] | 35 | #include "batches/GrDrawPathBatch.h" |
joshualitt | ecd1a69 | 2015-08-10 10:08:26 -0700 | [diff] [blame] | 36 | #include "batches/GrRectBatchFactory.h" |
bsalomon | a44919e | 2015-08-18 13:28:19 -0700 | [diff] [blame] | 37 | #include "batches/GrStencilPathBatch.h" |
joshualitt | 7441782 | 2015-08-07 11:42:16 -0700 | [diff] [blame] | 38 | |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 39 | #include "instanced/InstancedRendering.h" |
| 40 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 41 | using gr_instanced::InstancedRendering; |
| 42 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 43 | //////////////////////////////////////////////////////////////////////////////// |
| 44 | |
bsalomon | 489147c | 2015-12-14 12:13:09 -0800 | [diff] [blame] | 45 | // Experimentally we have found that most batching occurs within the first 10 comparisons. |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 46 | static const int kDefaultMaxBatchLookback = 10; |
| 47 | static const int kDefaultMaxBatchLookahead = 10; |
bsalomon | 489147c | 2015-12-14 12:13:09 -0800 | [diff] [blame] | 48 | |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 49 | GrRenderTargetOpList::GrRenderTargetOpList(GrRenderTargetProxy* rtp, GrGpu* gpu, |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 50 | GrResourceProvider* resourceProvider, |
| 51 | GrAuditTrail* auditTrail, const Options& options) |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 52 | : INHERITED(rtp, auditTrail) |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 53 | , fLastFullClearBatch(nullptr) |
bsalomon | fd8d013 | 2016-08-11 11:25:33 -0700 | [diff] [blame] | 54 | , fGpu(SkRef(gpu)) |
csmartdalton | 7cdda99 | 2016-11-01 07:03:03 -0700 | [diff] [blame] | 55 | , fResourceProvider(resourceProvider) |
| 56 | , fLastClipStackGenID(SK_InvalidUniqueID) { |
csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 57 | // TODO: Stop extracting the context (currently needed by GrClip) |
bsalomon | b3b9aec | 2015-09-10 11:16:35 -0700 | [diff] [blame] | 58 | fContext = fGpu->getContext(); |
robertphillips | 4beb5c1 | 2015-10-20 07:50:00 -0700 | [diff] [blame] | 59 | |
cdalton | 862cff3 | 2016-05-12 15:09:48 -0700 | [diff] [blame] | 60 | fClipBatchToBounds = options.fClipBatchToBounds; |
bsalomon | 489147c | 2015-12-14 12:13:09 -0800 | [diff] [blame] | 61 | fMaxBatchLookback = (options.fMaxBatchLookback < 0) ? kDefaultMaxBatchLookback : |
| 62 | options.fMaxBatchLookback; |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 63 | fMaxBatchLookahead = (options.fMaxBatchLookahead < 0) ? kDefaultMaxBatchLookahead : |
| 64 | options.fMaxBatchLookahead; |
bsalomon | 6dea83f | 2015-12-03 12:58:06 -0800 | [diff] [blame] | 65 | |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 66 | if (GrCaps::InstancedSupport::kNone != this->caps()->instancedSupport()) { |
| 67 | fInstancedRendering.reset(fGpu->createInstancedRendering()); |
| 68 | } |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 71 | GrRenderTargetOpList::~GrRenderTargetOpList() { |
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 | 4beb5c1 | 2015-10-20 07:50:00 -0700 | [diff] [blame] | 77 | #ifdef SK_DEBUG |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 78 | void GrRenderTargetOpList::dump() const { |
| 79 | INHERITED::dump(); |
| 80 | |
bsalomon | 6cc9006 | 2016-07-08 11:31:22 -0700 | [diff] [blame] | 81 | SkDebugf("batches (%d):\n", fRecordedBatches.count()); |
| 82 | for (int i = 0; i < fRecordedBatches.count(); ++i) { |
robertphillips | 4beb5c1 | 2015-10-20 07:50:00 -0700 | [diff] [blame] | 83 | SkDebugf("*******************************\n"); |
bsalomon | 6cc9006 | 2016-07-08 11:31:22 -0700 | [diff] [blame] | 84 | if (!fRecordedBatches[i].fBatch) { |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 85 | SkDebugf("%d: <combined forward>\n", i); |
| 86 | } else { |
bsalomon | 6cc9006 | 2016-07-08 11:31:22 -0700 | [diff] [blame] | 87 | SkDebugf("%d: %s\n", i, fRecordedBatches[i].fBatch->name()); |
| 88 | SkString str = fRecordedBatches[i].fBatch->dumpInfo(); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 89 | SkDebugf("%s\n", str.c_str()); |
bsalomon | 6cc9006 | 2016-07-08 11:31:22 -0700 | [diff] [blame] | 90 | const SkRect& clippedBounds = fRecordedBatches[i].fClippedBounds; |
| 91 | SkDebugf("ClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", |
| 92 | clippedBounds.fLeft, clippedBounds.fTop, clippedBounds.fRight, |
| 93 | clippedBounds.fBottom); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 94 | } |
robertphillips | 4beb5c1 | 2015-10-20 07:50:00 -0700 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | #endif |
| 98 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 99 | bool GrRenderTargetOpList::setupDstReadIfNecessary(const GrPipelineBuilder& pipelineBuilder, |
| 100 | GrRenderTarget* rt, |
| 101 | const GrClip& clip, |
| 102 | const GrPipelineOptimizations& optimizations, |
| 103 | GrXferProcessor::DstTexture* dstTexture, |
| 104 | const SkRect& batchBounds) { |
bsalomon | ad792c1 | 2015-09-10 11:10:50 -0700 | [diff] [blame] | 105 | SkRect bounds = batchBounds; |
| 106 | bounds.outset(0.5f, 0.5f); |
| 107 | |
ethannicholas | de4166a | 2015-11-30 08:57:38 -0800 | [diff] [blame] | 108 | if (!pipelineBuilder.willXPNeedDstTexture(*this->caps(), optimizations)) { |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 109 | return true; |
| 110 | } |
cdalton | 9954bc3 | 2015-04-29 14:17:00 -0700 | [diff] [blame] | 111 | |
cdalton | 9954bc3 | 2015-04-29 14:17:00 -0700 | [diff] [blame] | 112 | if (this->caps()->textureBarrierSupport()) { |
| 113 | if (GrTexture* rtTex = rt->asTexture()) { |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 114 | // 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] | 115 | // will be responsible to detect this situation and request a texture barrier. |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 116 | dstTexture->setTexture(sk_ref_sp(rtTex)); |
bsalomon | 6a44c6a | 2015-05-26 09:49:05 -0700 | [diff] [blame] | 117 | dstTexture->setOffset(0, 0); |
cdalton | 9954bc3 | 2015-04-29 14:17:00 -0700 | [diff] [blame] | 118 | return true; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | SkIRect copyRect; |
cdalton | 862cff3 | 2016-05-12 15:09:48 -0700 | [diff] [blame] | 123 | clip.getConservativeBounds(rt->width(), rt->height(), ©Rect); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 124 | |
bsalomon | ad792c1 | 2015-09-10 11:10:50 -0700 | [diff] [blame] | 125 | SkIRect drawIBounds; |
| 126 | bounds.roundOut(&drawIBounds); |
| 127 | if (!copyRect.intersect(drawIBounds)) { |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 128 | #ifdef SK_DEBUG |
bsalomon | b3b9aec | 2015-09-10 11:16:35 -0700 | [diff] [blame] | 129 | GrCapsDebugf(this->caps(), "Missed an early reject. " |
| 130 | "Bailing on draw from setupDstReadIfNecessary.\n"); |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 131 | #endif |
bsalomon | ad792c1 | 2015-09-10 11:10:50 -0700 | [diff] [blame] | 132 | return false; |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 133 | } |
skia.committer@gmail.com | 05a2ee0 | 2013-04-02 07:01:34 +0000 | [diff] [blame] | 134 | |
commit-bot@chromium.org | 63150af | 2013-04-11 22:00:22 +0000 | [diff] [blame] | 135 | // MSAA consideration: When there is support for reading MSAA samples in the shader we could |
| 136 | // have per-sample dst values by making the copy multisampled. |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 137 | GrSurfaceDesc desc; |
egdaniel | 4bcd62e | 2016-08-31 07:37:31 -0700 | [diff] [blame] | 138 | if (!fGpu->initDescForDstCopy(rt, &desc)) { |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 139 | desc.fOrigin = kDefault_GrSurfaceOrigin; |
| 140 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 141 | desc.fConfig = rt->config(); |
| 142 | } |
| 143 | |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 144 | desc.fWidth = copyRect.width(); |
| 145 | desc.fHeight = copyRect.height(); |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 146 | |
bsalomon | eae6200 | 2015-07-31 13:59:30 -0700 | [diff] [blame] | 147 | static const uint32_t kFlags = 0; |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 148 | sk_sp<GrTexture> copy(fResourceProvider->createApproxTexture(desc, kFlags)); |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 149 | |
bsalomon | e305973 | 2014-10-14 11:47:22 -0700 | [diff] [blame] | 150 | if (!copy) { |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 151 | SkDebugf("Failed to create temporary copy of destination texture.\n"); |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 152 | return false; |
| 153 | } |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 154 | SkIPoint dstPoint = {0, 0}; |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 155 | this->copySurface(copy.get(), rt, copyRect, dstPoint); |
| 156 | dstTexture->setTexture(std::move(copy)); |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 157 | dstTexture->setOffset(copyRect.fLeft, copyRect.fTop); |
| 158 | return true; |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 159 | } |
| 160 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 161 | void GrRenderTargetOpList::prepareBatches(GrBatchFlushState* flushState) { |
| 162 | // Semi-usually the GrOpLists are already closed at this point, but sometimes Ganesh |
| 163 | // needs to flush mid-draw. In that case, the SkGpuDevice's GrOpLists won't be closed |
| 164 | // but need to be flushed anyway. Closing such GrOpLists here will mean new |
| 165 | // GrOpLists will be created to replace them if the SkGpuDevice(s) write to them again. |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 166 | this->makeClosed(); |
| 167 | |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 168 | // Loop over the batches that haven't yet generated their geometry |
bsalomon | 6cc9006 | 2016-07-08 11:31:22 -0700 | [diff] [blame] | 169 | for (int i = 0; i < fRecordedBatches.count(); ++i) { |
| 170 | if (fRecordedBatches[i].fBatch) { |
| 171 | fRecordedBatches[i].fBatch->prepare(flushState); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 172 | } |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 173 | } |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 174 | |
| 175 | if (fInstancedRendering) { |
| 176 | fInstancedRendering->beginFlush(flushState->resourceProvider()); |
| 177 | } |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 178 | } |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 179 | |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame^] | 180 | // TODO: this is where GrOp::renderTarget is used (which is fine since it |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 181 | // is at flush time). However, we need to store the RenderTargetProxy in the |
| 182 | // Batches and instantiate them here. |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 183 | bool GrRenderTargetOpList::drawBatches(GrBatchFlushState* flushState) { |
egdaniel | b4021cf | 2016-07-28 08:53:07 -0700 | [diff] [blame] | 184 | if (0 == fRecordedBatches.count()) { |
bsalomon | dc43898 | 2016-08-31 11:53:49 -0700 | [diff] [blame] | 185 | return false; |
egdaniel | b4021cf | 2016-07-28 08:53:07 -0700 | [diff] [blame] | 186 | } |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 187 | // Draw all the generated geometry. |
bsalomon | 6dea83f | 2015-12-03 12:58:06 -0800 | [diff] [blame] | 188 | SkRandom random; |
Brian Salomon | 3a7492f | 2016-11-30 10:52:10 -0500 | [diff] [blame] | 189 | GrGpuResource::UniqueID currentRTID = GrGpuResource::UniqueID::InvalidID(); |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 190 | std::unique_ptr<GrGpuCommandBuffer> commandBuffer; |
bsalomon | 6cc9006 | 2016-07-08 11:31:22 -0700 | [diff] [blame] | 191 | for (int i = 0; i < fRecordedBatches.count(); ++i) { |
| 192 | if (!fRecordedBatches[i].fBatch) { |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 193 | continue; |
| 194 | } |
Brian Salomon | 3a7492f | 2016-11-30 10:52:10 -0500 | [diff] [blame] | 195 | if (fRecordedBatches[i].fBatch->renderTargetUniqueID() != currentRTID) { |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 196 | if (commandBuffer) { |
| 197 | commandBuffer->end(); |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 198 | commandBuffer->submit(); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 199 | commandBuffer.reset(); |
| 200 | } |
Brian Salomon | 3a7492f | 2016-11-30 10:52:10 -0500 | [diff] [blame] | 201 | currentRTID = fRecordedBatches[i].fBatch->renderTargetUniqueID(); |
| 202 | if (!currentRTID.isInvalid()) { |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 203 | static const GrGpuCommandBuffer::LoadAndStoreInfo kBasicLoadStoreInfo |
| 204 | { GrGpuCommandBuffer::LoadOp::kLoad,GrGpuCommandBuffer::StoreOp::kStore, |
| 205 | GrColor_ILLEGAL }; |
Brian Salomon | c293a29 | 2016-11-30 13:38:32 -0500 | [diff] [blame] | 206 | commandBuffer.reset(fGpu->createCommandBuffer(kBasicLoadStoreInfo, // Color |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 207 | kBasicLoadStoreInfo)); // Stencil |
| 208 | } |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 209 | flushState->setCommandBuffer(commandBuffer.get()); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 210 | } |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 211 | fRecordedBatches[i].fBatch->draw(flushState, fRecordedBatches[i].fClippedBounds); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 212 | } |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 213 | if (commandBuffer) { |
| 214 | commandBuffer->end(); |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 215 | commandBuffer->submit(); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 216 | flushState->setCommandBuffer(nullptr); |
| 217 | } |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 218 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 219 | fGpu->finishOpList(); |
bsalomon | dc43898 | 2016-08-31 11:53:49 -0700 | [diff] [blame] | 220 | return true; |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 221 | } |
| 222 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 223 | void GrRenderTargetOpList::reset() { |
bsalomon | fd8d013 | 2016-08-11 11:25:33 -0700 | [diff] [blame] | 224 | fLastFullClearBatch = nullptr; |
bsalomon | 6cc9006 | 2016-07-08 11:31:22 -0700 | [diff] [blame] | 225 | fRecordedBatches.reset(); |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 226 | if (fInstancedRendering) { |
| 227 | fInstancedRendering->endFlush(); |
| 228 | } |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 229 | } |
| 230 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 231 | void GrRenderTargetOpList::abandonGpuResources() { |
| 232 | if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport()) { |
| 233 | InstancedRendering* ir = this->instancedRendering(); |
| 234 | ir->resetGpuResources(InstancedRendering::ResetType::kAbandon); |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | void GrRenderTargetOpList::freeGpuResources() { |
| 239 | if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport()) { |
| 240 | InstancedRendering* ir = this->instancedRendering(); |
| 241 | ir->resetGpuResources(InstancedRendering::ResetType::kDestroy); |
| 242 | } |
| 243 | } |
| 244 | |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame^] | 245 | static void batch_bounds(SkRect* bounds, const GrOp* batch) { |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 246 | *bounds = batch->bounds(); |
| 247 | if (batch->hasZeroArea()) { |
| 248 | if (batch->hasAABloat()) { |
| 249 | bounds->outset(0.5f, 0.5f); |
| 250 | } else { |
| 251 | // We don't know which way the particular GPU will snap lines or points at integer |
| 252 | // coords. So we ensure that the bounds is large enough for either snap. |
| 253 | SkRect before = *bounds; |
| 254 | bounds->roundOut(bounds); |
| 255 | if (bounds->fLeft == before.fLeft) { |
| 256 | bounds->fLeft -= 1; |
| 257 | } |
| 258 | if (bounds->fTop == before.fTop) { |
| 259 | bounds->fTop -= 1; |
| 260 | } |
| 261 | if (bounds->fRight == before.fRight) { |
| 262 | bounds->fRight += 1; |
| 263 | } |
| 264 | if (bounds->fBottom == before.fBottom) { |
| 265 | bounds->fBottom += 1; |
| 266 | } |
| 267 | } |
| 268 | } |
| 269 | } |
| 270 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 271 | void GrRenderTargetOpList::drawBatch(const GrPipelineBuilder& pipelineBuilder, |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 272 | GrRenderTargetContext* renderTargetContext, |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 273 | const GrClip& clip, |
| 274 | GrDrawBatch* batch) { |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 275 | // Setup clip |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 276 | SkRect bounds; |
| 277 | batch_bounds(&bounds, batch); |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 278 | GrAppliedClip appliedClip(bounds); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 279 | if (!clip.apply(fContext, renderTargetContext, pipelineBuilder.isHWAntialias(), |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 280 | pipelineBuilder.hasUserStencilSettings(), &appliedClip)) { |
cdalton | 862cff3 | 2016-05-12 15:09:48 -0700 | [diff] [blame] | 281 | return; |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 282 | } |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 283 | |
robertphillips | 55fdccc | 2016-06-06 06:16:20 -0700 | [diff] [blame] | 284 | // TODO: this is the only remaining usage of the AutoRestoreFragmentProcessorState - remove it |
cdalton | d472792 | 2015-11-10 12:49:06 -0800 | [diff] [blame] | 285 | GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps; |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 286 | if (appliedClip.clipCoverageFragmentProcessor()) { |
cdalton | d472792 | 2015-11-10 12:49:06 -0800 | [diff] [blame] | 287 | arfps.set(&pipelineBuilder); |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 288 | arfps.addCoverageFragmentProcessor(sk_ref_sp(appliedClip.clipCoverageFragmentProcessor())); |
cdalton | d472792 | 2015-11-10 12:49:06 -0800 | [diff] [blame] | 289 | } |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 290 | |
cdalton | 862cff3 | 2016-05-12 15:09:48 -0700 | [diff] [blame] | 291 | if (pipelineBuilder.hasUserStencilSettings() || appliedClip.hasStencilClip()) { |
Robert Phillips | e60ad62 | 2016-11-17 10:22:48 -0500 | [diff] [blame] | 292 | if (!renderTargetContext->accessRenderTarget()) { |
| 293 | return; |
| 294 | } |
| 295 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 296 | if (!fResourceProvider->attachStencilAttachment( |
| 297 | renderTargetContext->accessRenderTarget())) { |
cdalton | 17bf820 | 2016-05-13 11:27:15 -0700 | [diff] [blame] | 298 | SkDebugf("ERROR creating stencil attachment. Draw skipped.\n"); |
| 299 | return; |
| 300 | } |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 301 | } |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 302 | |
| 303 | GrPipeline::CreateArgs args; |
| 304 | args.fPipelineBuilder = &pipelineBuilder; |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 305 | args.fRenderTargetContext = renderTargetContext; |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 306 | args.fCaps = this->caps(); |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 307 | batch->getPipelineOptimizations(&args.fOpts); |
cdalton | 862cff3 | 2016-05-12 15:09:48 -0700 | [diff] [blame] | 308 | if (args.fOpts.fOverrides.fUsePLSDstRead || fClipBatchToBounds) { |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 309 | GrGLIRect viewport; |
| 310 | viewport.fLeft = 0; |
| 311 | viewport.fBottom = 0; |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 312 | viewport.fWidth = renderTargetContext->width(); |
| 313 | viewport.fHeight = renderTargetContext->height(); |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 314 | SkIRect ibounds; |
| 315 | ibounds.fLeft = SkTPin(SkScalarFloorToInt(batch->bounds().fLeft), viewport.fLeft, |
| 316 | viewport.fWidth); |
| 317 | ibounds.fTop = SkTPin(SkScalarFloorToInt(batch->bounds().fTop), viewport.fBottom, |
| 318 | viewport.fHeight); |
| 319 | ibounds.fRight = SkTPin(SkScalarCeilToInt(batch->bounds().fRight), viewport.fLeft, |
| 320 | viewport.fWidth); |
| 321 | ibounds.fBottom = SkTPin(SkScalarCeilToInt(batch->bounds().fBottom), viewport.fBottom, |
| 322 | viewport.fHeight); |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 323 | if (!appliedClip.addScissor(ibounds)) { |
| 324 | return; |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 325 | } |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 326 | } |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 327 | args.fOpts.fColorPOI.completeCalculations( |
| 328 | sk_sp_address_as_pointer_address(pipelineBuilder.fColorFragmentProcessors.begin()), |
| 329 | pipelineBuilder.numColorFragmentProcessors()); |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 330 | args.fOpts.fCoveragePOI.completeCalculations( |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 331 | sk_sp_address_as_pointer_address(pipelineBuilder.fCoverageFragmentProcessors.begin()), |
| 332 | pipelineBuilder.numCoverageFragmentProcessors()); |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 333 | args.fScissor = &appliedClip.scissorState(); |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 334 | args.fWindowRectsState = &appliedClip.windowRectsState(); |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 335 | args.fHasStencilClip = appliedClip.hasStencilClip(); |
Robert Phillips | e60ad62 | 2016-11-17 10:22:48 -0500 | [diff] [blame] | 336 | if (!renderTargetContext->accessRenderTarget()) { |
| 337 | return; |
| 338 | } |
| 339 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 340 | if (!this->setupDstReadIfNecessary(pipelineBuilder, renderTargetContext->accessRenderTarget(), |
robertphillips | 55fdccc | 2016-06-06 06:16:20 -0700 | [diff] [blame] | 341 | clip, args.fOpts, |
| 342 | &args.fDstTexture, batch->bounds())) { |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 343 | return; |
| 344 | } |
| 345 | |
| 346 | if (!batch->installPipeline(args)) { |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 347 | return; |
| 348 | } |
bsalomon | ad792c1 | 2015-09-10 11:10:50 -0700 | [diff] [blame] | 349 | |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 350 | #ifdef ENABLE_MDB |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 351 | SkASSERT(fSurface); |
| 352 | batch->pipeline()->addDependenciesTo(fSurface); |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 353 | #endif |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 354 | this->recordBatch(batch, appliedClip.clippedDrawBounds()); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 355 | } |
| 356 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 357 | void GrRenderTargetOpList::stencilPath(GrRenderTargetContext* renderTargetContext, |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 358 | const GrClip& clip, |
| 359 | bool useHWAA, |
| 360 | const SkMatrix& viewMatrix, |
| 361 | const GrPath* path) { |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 362 | // TODO: extract portions of checkDraw that are relevant to path stenciling. |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 363 | SkASSERT(path); |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 364 | SkASSERT(this->caps()->shaderCaps()->pathRenderingSupport()); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 365 | |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 366 | // FIXME: Use path bounds instead of this WAR once |
| 367 | // https://bugs.chromium.org/p/skia/issues/detail?id=5640 is resolved. |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 368 | SkRect bounds = SkRect::MakeIWH(renderTargetContext->width(), renderTargetContext->height()); |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 369 | |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 370 | // Setup clip |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 371 | GrAppliedClip appliedClip(bounds); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 372 | if (!clip.apply(fContext, renderTargetContext, useHWAA, true, &appliedClip)) { |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 373 | return; |
| 374 | } |
cdalton | 862cff3 | 2016-05-12 15:09:48 -0700 | [diff] [blame] | 375 | // TODO: respect fClipBatchToBounds if we ever start computing bounds here. |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 376 | |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 377 | // Coverage AA does not make sense when rendering to the stencil buffer. The caller should never |
| 378 | // attempt this in a situation that would require coverage AA. |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 379 | SkASSERT(!appliedClip.clipCoverageFragmentProcessor()); |
bsalomon | 0ba8c24 | 2015-10-07 09:20:28 -0700 | [diff] [blame] | 380 | |
Robert Phillips | e60ad62 | 2016-11-17 10:22:48 -0500 | [diff] [blame] | 381 | if (!renderTargetContext->accessRenderTarget()) { |
| 382 | return; |
| 383 | } |
robertphillips | 55fdccc | 2016-06-06 06:16:20 -0700 | [diff] [blame] | 384 | GrStencilAttachment* stencilAttachment = fResourceProvider->attachStencilAttachment( |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 385 | renderTargetContext->accessRenderTarget()); |
cdalton | 17bf820 | 2016-05-13 11:27:15 -0700 | [diff] [blame] | 386 | if (!stencilAttachment) { |
| 387 | SkDebugf("ERROR creating stencil attachment. Draw skipped.\n"); |
| 388 | return; |
| 389 | } |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 390 | |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame^] | 391 | GrOp* batch = GrStencilPathBatch::Create(viewMatrix, |
| 392 | useHWAA, |
| 393 | path->getFillType(), |
| 394 | appliedClip.hasStencilClip(), |
| 395 | stencilAttachment->bits(), |
| 396 | appliedClip.scissorState(), |
| 397 | renderTargetContext->accessRenderTarget(), |
| 398 | path); |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 399 | this->recordBatch(batch, appliedClip.clippedDrawBounds()); |
bsalomon | a44919e | 2015-08-18 13:28:19 -0700 | [diff] [blame] | 400 | batch->unref(); |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 401 | } |
| 402 | |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame^] | 403 | void GrRenderTargetOpList::addBatch(sk_sp<GrOp> batch) { |
robertphillips | 9199a9f | 2016-07-13 07:48:43 -0700 | [diff] [blame] | 404 | this->recordBatch(batch.get(), batch->bounds()); |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 405 | } |
| 406 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 407 | void GrRenderTargetOpList::fullClear(GrRenderTarget* renderTarget, GrColor color) { |
bsalomon | fd8d013 | 2016-08-11 11:25:33 -0700 | [diff] [blame] | 408 | // Currently this just inserts or updates the last clear batch. However, once in MDB this can |
| 409 | // remove all the previously recorded batches and change the load op to clear with supplied |
| 410 | // color. |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 411 | // TODO: this needs to be updated to use GrSurfaceProxy::UniqueID |
bsalomon | fd8d013 | 2016-08-11 11:25:33 -0700 | [diff] [blame] | 412 | if (fLastFullClearBatch && |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 413 | fLastFullClearBatch->renderTargetUniqueID() == renderTarget->uniqueID()) { |
bsalomon | fd8d013 | 2016-08-11 11:25:33 -0700 | [diff] [blame] | 414 | // As currently implemented, fLastFullClearBatch should be the last batch because we would |
| 415 | // have cleared it when another batch was recorded. |
| 416 | SkASSERT(fRecordedBatches.back().fBatch.get() == fLastFullClearBatch); |
| 417 | fLastFullClearBatch->setColor(color); |
| 418 | return; |
| 419 | } |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 420 | sk_sp<GrClearBatch> batch(GrClearBatch::Make(GrFixedClip::Disabled(), color, renderTarget)); |
bsalomon | fd8d013 | 2016-08-11 11:25:33 -0700 | [diff] [blame] | 421 | if (batch.get() == this->recordBatch(batch.get(), batch->bounds())) { |
| 422 | fLastFullClearBatch = batch.get(); |
| 423 | } |
bsalomon | 9f129de | 2016-08-10 16:31:05 -0700 | [diff] [blame] | 424 | } |
| 425 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 426 | void GrRenderTargetOpList::discard(GrRenderTarget* renderTarget) { |
bsalomon | 9f129de | 2016-08-10 16:31:05 -0700 | [diff] [blame] | 427 | // Currently this just inserts a discard batch. However, once in MDB this can remove all the |
| 428 | // previously recorded batches and change the load op to discard. |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 429 | if (this->caps()->discardRenderTargetSupport()) { |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame^] | 430 | GrOp* batch = new GrDiscardBatch(renderTarget); |
bsalomon | 6cc9006 | 2016-07-08 11:31:22 -0700 | [diff] [blame] | 431 | this->recordBatch(batch, batch->bounds()); |
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 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 438 | bool GrRenderTargetOpList::copySurface(GrSurface* dst, |
| 439 | GrSurface* src, |
| 440 | const SkIRect& srcRect, |
| 441 | const SkIPoint& dstPoint) { |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame^] | 442 | GrOp* 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 | 6cc9006 | 2016-07-08 11:31:22 -0700 | [diff] [blame] | 450 | this->recordBatch(batch, batch->bounds()); |
bsalomon | b8fea97 | 2016-02-16 07:34:17 -0800 | [diff] [blame] | 451 | batch->unref(); |
| 452 | return true; |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 453 | } |
| 454 | |
bsalomon | 6cc9006 | 2016-07-08 11:31:22 -0700 | [diff] [blame] | 455 | static inline bool can_reorder(const SkRect& a, const SkRect& b) { |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 456 | return a.fRight <= b.fLeft || a.fBottom <= b.fTop || |
| 457 | b.fRight <= a.fLeft || b.fBottom <= a.fTop; |
| 458 | } |
| 459 | |
bsalomon | 6cc9006 | 2016-07-08 11:31:22 -0700 | [diff] [blame] | 460 | static void join(SkRect* out, const SkRect& a, const SkRect& b) { |
| 461 | SkASSERT(a.fLeft <= a.fRight && a.fTop <= a.fBottom); |
| 462 | SkASSERT(b.fLeft <= b.fRight && b.fTop <= b.fBottom); |
| 463 | out->fLeft = SkTMin(a.fLeft, b.fLeft); |
| 464 | out->fTop = SkTMin(a.fTop, b.fTop); |
| 465 | out->fRight = SkTMax(a.fRight, b.fRight); |
| 466 | out->fBottom = SkTMax(a.fBottom, b.fBottom); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 467 | } |
| 468 | |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame^] | 469 | GrOp* GrRenderTargetOpList::recordBatch(GrOp* batch, const SkRect& clippedBounds) { |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 470 | // A closed GrOpList should never receive new/more batches |
robertphillips | 6a18665 | 2015-10-20 07:37:58 -0700 | [diff] [blame] | 471 | SkASSERT(!this->isClosed()); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 472 | |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 473 | // Check if there is a Batch Draw we can batch with by linearly searching back until we either |
| 474 | // 1) check every draw |
| 475 | // 2) intersect with something |
| 476 | // 3) find a 'blocker' |
joshualitt | b0666ad | 2016-03-08 10:43:41 -0800 | [diff] [blame] | 477 | GR_AUDIT_TRAIL_ADDBATCH(fAuditTrail, batch); |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame^] | 478 | GrOP_INFO("Re-Recording (%s, B%u)\n" |
| 479 | "\tBounds LRTB (%f, %f, %f, %f)\n", |
| 480 | batch->name(), |
| 481 | batch->uniqueID(), |
| 482 | batch->bounds().fLeft, batch->bounds().fRight, |
| 483 | batch->bounds().fTop, batch->bounds().fBottom); |
| 484 | GrOP_INFO(SkTabString(batch->dumpInfo(), 1).c_str()); |
| 485 | GrOP_INFO("\tClipped Bounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", |
| 486 | clippedBounds.fLeft, clippedBounds.fTop, clippedBounds.fRight, |
| 487 | clippedBounds.fBottom); |
| 488 | GrOP_INFO("\tOutcome:\n"); |
bsalomon | 6cc9006 | 2016-07-08 11:31:22 -0700 | [diff] [blame] | 489 | int maxCandidates = SkTMin(fMaxBatchLookback, fRecordedBatches.count()); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 490 | if (maxCandidates) { |
| 491 | int i = 0; |
| 492 | while (true) { |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame^] | 493 | GrOp* candidate = fRecordedBatches.fromBack(i).fBatch.get(); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 494 | // We cannot continue to search backwards if the render target changes |
| 495 | if (candidate->renderTargetUniqueID() != batch->renderTargetUniqueID()) { |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame^] | 496 | GrOP_INFO("\t\tBreaking because of (%s, B%u) Rendertarget\n", |
| 497 | candidate->name(), candidate->uniqueID()); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 498 | break; |
| 499 | } |
| 500 | if (candidate->combineIfPossible(batch, *this->caps())) { |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame^] | 501 | GrOP_INFO("\t\tCombining with (%s, B%u)\n", candidate->name(), |
| 502 | candidate->uniqueID()); |
joshualitt | b0666ad | 2016-03-08 10:43:41 -0800 | [diff] [blame] | 503 | GR_AUDIT_TRAIL_BATCHING_RESULT_COMBINED(fAuditTrail, candidate, batch); |
bsalomon | 6cc9006 | 2016-07-08 11:31:22 -0700 | [diff] [blame] | 504 | join(&fRecordedBatches.fromBack(i).fClippedBounds, |
| 505 | fRecordedBatches.fromBack(i).fClippedBounds, clippedBounds); |
bsalomon | fd8d013 | 2016-08-11 11:25:33 -0700 | [diff] [blame] | 506 | return candidate; |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 507 | } |
| 508 | // Stop going backwards if we would cause a painter's order violation. |
bsalomon | 6cc9006 | 2016-07-08 11:31:22 -0700 | [diff] [blame] | 509 | const SkRect& candidateBounds = fRecordedBatches.fromBack(i).fClippedBounds; |
| 510 | if (!can_reorder(candidateBounds, clippedBounds)) { |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame^] | 511 | GrOP_INFO("\t\tIntersects with (%s, B%u)\n", candidate->name(), |
| 512 | candidate->uniqueID()); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 513 | break; |
| 514 | } |
| 515 | ++i; |
| 516 | if (i == maxCandidates) { |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame^] | 517 | GrOP_INFO("\t\tReached max lookback or beginning of batch array %d\n", i); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 518 | break; |
| 519 | } |
| 520 | } |
| 521 | } else { |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame^] | 522 | GrOP_INFO("\t\tFirstBatch\n"); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 523 | } |
joshualitt | 18d6b75 | 2016-02-26 08:07:50 -0800 | [diff] [blame] | 524 | GR_AUDIT_TRAIL_BATCHING_RESULT_NEW(fAuditTrail, batch); |
bsalomon | 6cc9006 | 2016-07-08 11:31:22 -0700 | [diff] [blame] | 525 | fRecordedBatches.emplace_back(RecordedBatch{sk_ref_sp(batch), clippedBounds}); |
bsalomon | fd8d013 | 2016-08-11 11:25:33 -0700 | [diff] [blame] | 526 | fLastFullClearBatch = nullptr; |
| 527 | return batch; |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 528 | } |
| 529 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 530 | void GrRenderTargetOpList::forwardCombine() { |
bsalomon | db27fc5 | 2016-08-29 12:43:27 -0700 | [diff] [blame] | 531 | if (fMaxBatchLookahead <= 0) { |
| 532 | return; |
| 533 | } |
bsalomon | 6cc9006 | 2016-07-08 11:31:22 -0700 | [diff] [blame] | 534 | for (int i = 0; i < fRecordedBatches.count() - 2; ++i) { |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame^] | 535 | GrOp* batch = fRecordedBatches[i].fBatch.get(); |
bsalomon | 6cc9006 | 2016-07-08 11:31:22 -0700 | [diff] [blame] | 536 | const SkRect& batchBounds = fRecordedBatches[i].fClippedBounds; |
| 537 | int maxCandidateIdx = SkTMin(i + fMaxBatchLookahead, fRecordedBatches.count() - 1); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 538 | int j = i + 1; |
| 539 | while (true) { |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame^] | 540 | GrOp* candidate = fRecordedBatches[j].fBatch.get(); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 541 | // We cannot continue to search if the render target changes |
| 542 | if (candidate->renderTargetUniqueID() != batch->renderTargetUniqueID()) { |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame^] | 543 | GrOP_INFO("\t\tBreaking because of (%s, B%u) Rendertarget\n", |
| 544 | candidate->name(), candidate->uniqueID()); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 545 | break; |
| 546 | } |
| 547 | if (j == i +1) { |
| 548 | // We assume batch would have combined with candidate when the candidate was added |
| 549 | // via backwards combining in recordBatch. |
| 550 | SkASSERT(!batch->combineIfPossible(candidate, *this->caps())); |
| 551 | } else if (batch->combineIfPossible(candidate, *this->caps())) { |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame^] | 552 | GrOP_INFO("\t\tCombining with (%s, B%u)\n", candidate->name(), |
| 553 | candidate->uniqueID()); |
joshualitt | b0666ad | 2016-03-08 10:43:41 -0800 | [diff] [blame] | 554 | GR_AUDIT_TRAIL_BATCHING_RESULT_COMBINED(fAuditTrail, batch, candidate); |
bsalomon | 6cc9006 | 2016-07-08 11:31:22 -0700 | [diff] [blame] | 555 | fRecordedBatches[j].fBatch = std::move(fRecordedBatches[i].fBatch); |
| 556 | join(&fRecordedBatches[j].fClippedBounds, fRecordedBatches[j].fClippedBounds, |
| 557 | batchBounds); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 558 | break; |
| 559 | } |
| 560 | // Stop going traversing if we would cause a painter's order violation. |
bsalomon | 6cc9006 | 2016-07-08 11:31:22 -0700 | [diff] [blame] | 561 | const SkRect& candidateBounds = fRecordedBatches[j].fClippedBounds; |
| 562 | if (!can_reorder(candidateBounds, batchBounds)) { |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame^] | 563 | GrOP_INFO("\t\tIntersects with (%s, B%u)\n", candidate->name(), |
| 564 | candidate->uniqueID()); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 565 | break; |
| 566 | } |
| 567 | ++j; |
| 568 | if (j > maxCandidateIdx) { |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame^] | 569 | GrOP_INFO("\t\tReached max lookahead or end of batch array %d\n", i); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 570 | break; |
| 571 | } |
| 572 | } |
| 573 | } |
| 574 | } |
| 575 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 576 | /////////////////////////////////////////////////////////////////////////////// |
| 577 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 578 | void GrRenderTargetOpList::clearStencilClip(const GrFixedClip& clip, |
| 579 | bool insideStencilMask, |
| 580 | GrRenderTarget* rt) { |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame^] | 581 | GrOp* batch = new GrClearStencilClipBatch(clip, insideStencilMask, rt); |
bsalomon | 6cc9006 | 2016-07-08 11:31:22 -0700 | [diff] [blame] | 582 | this->recordBatch(batch, batch->bounds()); |
bsalomon | 5ea0363 | 2015-08-18 10:33:30 -0700 | [diff] [blame] | 583 | batch->unref(); |
| 584 | } |