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