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 | |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 30 | #include "ops/GrClearOp.h" |
| 31 | #include "ops/GrClearStencilClipOp.h" |
| 32 | #include "ops/GrCopySurfaceOp.h" |
| 33 | #include "ops/GrDiscardOp.h" |
| 34 | #include "ops/GrDrawOp.h" |
| 35 | #include "ops/GrDrawPathOp.h" |
| 36 | #include "ops/GrRectOpFactory.h" |
| 37 | #include "ops/GrStencilPathOp.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 | |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 45 | // Experimentally we have found that most combining occurs within the first 10 comparisons. |
| 46 | static const int kDefaultMaxOpLookback = 10; |
| 47 | static const int kDefaultMaxOpLookahead = 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) |
bsalomon | fd8d013 | 2016-08-11 11:25:33 -0700 | [diff] [blame] | 53 | , fGpu(SkRef(gpu)) |
csmartdalton | 7cdda99 | 2016-11-01 07:03:03 -0700 | [diff] [blame] | 54 | , fResourceProvider(resourceProvider) |
| 55 | , fLastClipStackGenID(SK_InvalidUniqueID) { |
csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 56 | // TODO: Stop extracting the context (currently needed by GrClip) |
bsalomon | b3b9aec | 2015-09-10 11:16:35 -0700 | [diff] [blame] | 57 | fContext = fGpu->getContext(); |
robertphillips | 4beb5c1 | 2015-10-20 07:50:00 -0700 | [diff] [blame] | 58 | |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 59 | fClipOpToBounds = options.fClipDrawOpsToBounds; |
| 60 | fMaxOpLookback = (options.fMaxOpCombineLookback < 0) ? kDefaultMaxOpLookback |
| 61 | : options.fMaxOpCombineLookback; |
| 62 | fMaxOpLookahead = (options.fMaxOpCombineLookahead < 0) ? kDefaultMaxOpLookahead |
| 63 | : options.fMaxOpCombineLookahead; |
bsalomon | 6dea83f | 2015-12-03 12:58:06 -0800 | [diff] [blame] | 64 | |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 65 | if (GrCaps::InstancedSupport::kNone != this->caps()->instancedSupport()) { |
| 66 | fInstancedRendering.reset(fGpu->createInstancedRendering()); |
| 67 | } |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 70 | GrRenderTargetOpList::~GrRenderTargetOpList() { |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 71 | fGpu->unref(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | //////////////////////////////////////////////////////////////////////////////// |
| 75 | |
robertphillips | 4beb5c1 | 2015-10-20 07:50:00 -0700 | [diff] [blame] | 76 | #ifdef SK_DEBUG |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 77 | void GrRenderTargetOpList::dump() const { |
| 78 | INHERITED::dump(); |
| 79 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 80 | SkDebugf("ops (%d):\n", fRecordedOps.count()); |
| 81 | for (int i = 0; i < fRecordedOps.count(); ++i) { |
robertphillips | 4beb5c1 | 2015-10-20 07:50:00 -0700 | [diff] [blame] | 82 | SkDebugf("*******************************\n"); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 83 | if (!fRecordedOps[i].fOp) { |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 84 | SkDebugf("%d: <combined forward>\n", i); |
| 85 | } else { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 86 | SkDebugf("%d: %s\n", i, fRecordedOps[i].fOp->name()); |
| 87 | SkString str = fRecordedOps[i].fOp->dumpInfo(); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 88 | SkDebugf("%s\n", str.c_str()); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 89 | const SkRect& clippedBounds = fRecordedOps[i].fClippedBounds; |
bsalomon | 6cc9006 | 2016-07-08 11:31:22 -0700 | [diff] [blame] | 90 | SkDebugf("ClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", |
| 91 | clippedBounds.fLeft, clippedBounds.fTop, clippedBounds.fRight, |
| 92 | clippedBounds.fBottom); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 93 | } |
robertphillips | 4beb5c1 | 2015-10-20 07:50:00 -0700 | [diff] [blame] | 94 | } |
| 95 | } |
| 96 | #endif |
| 97 | |
Brian Salomon | 5b7b49f | 2016-12-07 14:31:00 -0500 | [diff] [blame] | 98 | void GrRenderTargetOpList::setupDstTexture(GrRenderTarget* rt, |
| 99 | const GrClip& clip, |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 100 | const SkRect& opBounds, |
Brian Salomon | 5b7b49f | 2016-12-07 14:31:00 -0500 | [diff] [blame] | 101 | GrXferProcessor::DstTexture* dstTexture) { |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 102 | SkRect bounds = opBounds; |
bsalomon | ad792c1 | 2015-09-10 11:10:50 -0700 | [diff] [blame] | 103 | bounds.outset(0.5f, 0.5f); |
| 104 | |
cdalton | 9954bc3 | 2015-04-29 14:17:00 -0700 | [diff] [blame] | 105 | if (this->caps()->textureBarrierSupport()) { |
| 106 | if (GrTexture* rtTex = rt->asTexture()) { |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 107 | // 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] | 108 | // will be responsible to detect this situation and request a texture barrier. |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 109 | dstTexture->setTexture(sk_ref_sp(rtTex)); |
bsalomon | 6a44c6a | 2015-05-26 09:49:05 -0700 | [diff] [blame] | 110 | dstTexture->setOffset(0, 0); |
Brian Salomon | 5b7b49f | 2016-12-07 14:31:00 -0500 | [diff] [blame] | 111 | return; |
cdalton | 9954bc3 | 2015-04-29 14:17:00 -0700 | [diff] [blame] | 112 | } |
| 113 | } |
| 114 | |
| 115 | SkIRect copyRect; |
cdalton | 862cff3 | 2016-05-12 15:09:48 -0700 | [diff] [blame] | 116 | clip.getConservativeBounds(rt->width(), rt->height(), ©Rect); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 117 | |
bsalomon | ad792c1 | 2015-09-10 11:10:50 -0700 | [diff] [blame] | 118 | SkIRect drawIBounds; |
| 119 | bounds.roundOut(&drawIBounds); |
| 120 | if (!copyRect.intersect(drawIBounds)) { |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 121 | #ifdef SK_DEBUG |
bsalomon | b3b9aec | 2015-09-10 11:16:35 -0700 | [diff] [blame] | 122 | GrCapsDebugf(this->caps(), "Missed an early reject. " |
Brian Salomon | 5b7b49f | 2016-12-07 14:31:00 -0500 | [diff] [blame] | 123 | "Bailing on draw from setupDstTexture.\n"); |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 124 | #endif |
Brian Salomon | 5b7b49f | 2016-12-07 14:31:00 -0500 | [diff] [blame] | 125 | return; |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 126 | } |
skia.committer@gmail.com | 05a2ee0 | 2013-04-02 07:01:34 +0000 | [diff] [blame] | 127 | |
commit-bot@chromium.org | 63150af | 2013-04-11 22:00:22 +0000 | [diff] [blame] | 128 | // MSAA consideration: When there is support for reading MSAA samples in the shader we could |
| 129 | // have per-sample dst values by making the copy multisampled. |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 130 | GrSurfaceDesc desc; |
egdaniel | 4bcd62e | 2016-08-31 07:37:31 -0700 | [diff] [blame] | 131 | if (!fGpu->initDescForDstCopy(rt, &desc)) { |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 132 | desc.fOrigin = kDefault_GrSurfaceOrigin; |
| 133 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 134 | desc.fConfig = rt->config(); |
| 135 | } |
| 136 | |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 137 | desc.fWidth = copyRect.width(); |
| 138 | desc.fHeight = copyRect.height(); |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 139 | |
bsalomon | eae6200 | 2015-07-31 13:59:30 -0700 | [diff] [blame] | 140 | static const uint32_t kFlags = 0; |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 141 | sk_sp<GrTexture> copy(fResourceProvider->createApproxTexture(desc, kFlags)); |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 142 | |
bsalomon | e305973 | 2014-10-14 11:47:22 -0700 | [diff] [blame] | 143 | if (!copy) { |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 144 | SkDebugf("Failed to create temporary copy of destination texture.\n"); |
Brian Salomon | 5b7b49f | 2016-12-07 14:31:00 -0500 | [diff] [blame] | 145 | return; |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 146 | } |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 147 | SkIPoint dstPoint = {0, 0}; |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 148 | this->copySurface(copy.get(), rt, copyRect, dstPoint); |
| 149 | dstTexture->setTexture(std::move(copy)); |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 150 | dstTexture->setOffset(copyRect.fLeft, copyRect.fTop); |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 151 | } |
| 152 | |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 153 | void GrRenderTargetOpList::prepareOps(GrOpFlushState* flushState) { |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 154 | // Semi-usually the GrOpLists are already closed at this point, but sometimes Ganesh |
| 155 | // needs to flush mid-draw. In that case, the SkGpuDevice's GrOpLists won't be closed |
| 156 | // but need to be flushed anyway. Closing such GrOpLists here will mean new |
| 157 | // 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] | 158 | this->makeClosed(); |
| 159 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 160 | // Loop over the ops that haven't yet been prepared. |
| 161 | for (int i = 0; i < fRecordedOps.count(); ++i) { |
| 162 | if (fRecordedOps[i].fOp) { |
| 163 | fRecordedOps[i].fOp->prepare(flushState); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 164 | } |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 165 | } |
csmartdalton | a7f2964 | 2016-07-07 08:49:11 -0700 | [diff] [blame] | 166 | |
| 167 | if (fInstancedRendering) { |
| 168 | fInstancedRendering->beginFlush(flushState->resourceProvider()); |
| 169 | } |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 170 | } |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 171 | |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 172 | // 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] | 173 | // 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] | 174 | // Ops and instantiate them here. |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 175 | bool GrRenderTargetOpList::executeOps(GrOpFlushState* flushState) { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 176 | if (0 == fRecordedOps.count()) { |
bsalomon | dc43898 | 2016-08-31 11:53:49 -0700 | [diff] [blame] | 177 | return false; |
egdaniel | b4021cf | 2016-07-28 08:53:07 -0700 | [diff] [blame] | 178 | } |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 179 | // Draw all the generated geometry. |
bsalomon | 6dea83f | 2015-12-03 12:58:06 -0800 | [diff] [blame] | 180 | SkRandom random; |
Brian Salomon | 3a7492f | 2016-11-30 10:52:10 -0500 | [diff] [blame] | 181 | GrGpuResource::UniqueID currentRTID = GrGpuResource::UniqueID::InvalidID(); |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 182 | std::unique_ptr<GrGpuCommandBuffer> commandBuffer; |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 183 | for (int i = 0; i < fRecordedOps.count(); ++i) { |
| 184 | if (!fRecordedOps[i].fOp) { |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 185 | continue; |
| 186 | } |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 187 | if (fRecordedOps[i].fRenderTargetID != currentRTID) { |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 188 | if (commandBuffer) { |
| 189 | commandBuffer->end(); |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 190 | commandBuffer->submit(); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 191 | commandBuffer.reset(); |
| 192 | } |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 193 | currentRTID = fRecordedOps[i].fRenderTargetID; |
Brian Salomon | 3a7492f | 2016-11-30 10:52:10 -0500 | [diff] [blame] | 194 | if (!currentRTID.isInvalid()) { |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 195 | static const GrGpuCommandBuffer::LoadAndStoreInfo kBasicLoadStoreInfo |
| 196 | { GrGpuCommandBuffer::LoadOp::kLoad,GrGpuCommandBuffer::StoreOp::kStore, |
| 197 | GrColor_ILLEGAL }; |
Brian Salomon | c293a29 | 2016-11-30 13:38:32 -0500 | [diff] [blame] | 198 | commandBuffer.reset(fGpu->createCommandBuffer(kBasicLoadStoreInfo, // Color |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 199 | kBasicLoadStoreInfo)); // Stencil |
| 200 | } |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 201 | flushState->setCommandBuffer(commandBuffer.get()); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 202 | } |
Brian Salomon | bde4285 | 2016-12-21 11:37:49 -0500 | [diff] [blame] | 203 | fRecordedOps[i].fOp->execute(flushState, fRecordedOps[i].fClippedBounds); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 204 | } |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 205 | if (commandBuffer) { |
| 206 | commandBuffer->end(); |
Greg Daniel | 36a77ee | 2016-10-18 10:33:25 -0400 | [diff] [blame] | 207 | commandBuffer->submit(); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 208 | flushState->setCommandBuffer(nullptr); |
| 209 | } |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 210 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 211 | fGpu->finishOpList(); |
bsalomon | dc43898 | 2016-08-31 11:53:49 -0700 | [diff] [blame] | 212 | return true; |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 213 | } |
| 214 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 215 | void GrRenderTargetOpList::reset() { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 216 | fLastFullClearOp = nullptr; |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 217 | fLastFullClearRenderTargetID.makeInvalid(); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 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 | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 238 | static void op_bounds(SkRect* bounds, const GrOp* op) { |
| 239 | *bounds = op->bounds(); |
| 240 | if (op->hasZeroArea()) { |
| 241 | if (op->hasAABloat()) { |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 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 | 92ce594 | 2017-01-18 11:01:10 -0500 | [diff] [blame] | 267 | std::unique_ptr<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 | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 270 | op_bounds(&bounds, op.get()); |
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 | |
cdalton | 862cff3 | 2016-05-12 15:09:48 -0700 | [diff] [blame] | 277 | if (pipelineBuilder.hasUserStencilSettings() || appliedClip.hasStencilClip()) { |
Robert Phillips | e60ad62 | 2016-11-17 10:22:48 -0500 | [diff] [blame] | 278 | if (!renderTargetContext->accessRenderTarget()) { |
| 279 | return; |
| 280 | } |
| 281 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 282 | if (!fResourceProvider->attachStencilAttachment( |
| 283 | renderTargetContext->accessRenderTarget())) { |
cdalton | 17bf820 | 2016-05-13 11:27:15 -0700 | [diff] [blame] | 284 | SkDebugf("ERROR creating stencil attachment. Draw skipped.\n"); |
| 285 | return; |
| 286 | } |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 287 | } |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 288 | |
| 289 | GrPipeline::CreateArgs args; |
| 290 | args.fPipelineBuilder = &pipelineBuilder; |
Brian Salomon | 652ecb5 | 2017-01-17 12:39:53 -0500 | [diff] [blame] | 291 | args.fAppliedClip = &appliedClip; |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 292 | args.fRenderTargetContext = renderTargetContext; |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 293 | args.fCaps = this->caps(); |
Brian Salomon | 92aee3d | 2016-12-21 09:20:25 -0500 | [diff] [blame] | 294 | op->initPipelineAnalysis(&args.fAnalysis); |
| 295 | if (args.fAnalysis.fUsesPLSDstRead || fClipOpToBounds) { |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 296 | GrGLIRect viewport; |
| 297 | viewport.fLeft = 0; |
| 298 | viewport.fBottom = 0; |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 299 | viewport.fWidth = renderTargetContext->width(); |
| 300 | viewport.fHeight = renderTargetContext->height(); |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 301 | SkIRect ibounds; |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 302 | ibounds.fLeft = SkTPin(SkScalarFloorToInt(op->bounds().fLeft), viewport.fLeft, |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 303 | viewport.fWidth); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 304 | ibounds.fTop = SkTPin(SkScalarFloorToInt(op->bounds().fTop), viewport.fBottom, |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 305 | viewport.fHeight); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 306 | ibounds.fRight = SkTPin(SkScalarCeilToInt(op->bounds().fRight), viewport.fLeft, |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 307 | viewport.fWidth); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 308 | ibounds.fBottom = SkTPin(SkScalarCeilToInt(op->bounds().fBottom), viewport.fBottom, |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 309 | viewport.fHeight); |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 310 | if (!appliedClip.addScissor(ibounds)) { |
| 311 | return; |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 312 | } |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 313 | } |
Brian Salomon | 92ce594 | 2017-01-18 11:01:10 -0500 | [diff] [blame] | 314 | pipelineBuilder.analyzeFragmentProcessors(&args.fAnalysis); |
Brian Salomon | 652ecb5 | 2017-01-17 12:39:53 -0500 | [diff] [blame] | 315 | if (const GrFragmentProcessor* clipFP = appliedClip.clipCoverageFragmentProcessor()) { |
Brian Salomon | 0831f1b | 2017-01-18 11:08:41 -0500 | [diff] [blame^] | 316 | args.fAnalysis.fCoveragePOI.analyzeProcessors(&clipFP, 1); |
Brian Salomon | 652ecb5 | 2017-01-17 12:39:53 -0500 | [diff] [blame] | 317 | } |
| 318 | |
Robert Phillips | e60ad62 | 2016-11-17 10:22:48 -0500 | [diff] [blame] | 319 | if (!renderTargetContext->accessRenderTarget()) { |
| 320 | return; |
| 321 | } |
| 322 | |
Brian Salomon | 92aee3d | 2016-12-21 09:20:25 -0500 | [diff] [blame] | 323 | if (pipelineBuilder.willXPNeedDstTexture(*this->caps(), args.fAnalysis)) { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 324 | this->setupDstTexture(renderTargetContext->accessRenderTarget(), clip, op->bounds(), |
Brian Salomon | 5b7b49f | 2016-12-07 14:31:00 -0500 | [diff] [blame] | 325 | &args.fDstTexture); |
| 326 | if (!args.fDstTexture.texture()) { |
| 327 | return; |
| 328 | } |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 331 | if (!op->installPipeline(args)) { |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 332 | return; |
| 333 | } |
bsalomon | ad792c1 | 2015-09-10 11:10:50 -0700 | [diff] [blame] | 334 | |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 335 | #ifdef ENABLE_MDB |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 336 | SkASSERT(fSurface); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 337 | op->pipeline()->addDependenciesTo(fSurface); |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 338 | #endif |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 339 | this->recordOp(std::move(op), renderTargetContext, appliedClip.clippedDrawBounds()); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 340 | } |
| 341 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 342 | void GrRenderTargetOpList::stencilPath(GrRenderTargetContext* renderTargetContext, |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 343 | const GrClip& clip, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 344 | GrAAType aaType, |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 345 | const SkMatrix& viewMatrix, |
| 346 | const GrPath* path) { |
Brian Salomon | 0abc8b4 | 2016-12-13 10:22:54 -0500 | [diff] [blame] | 347 | bool useHWAA = GrAATypeIsHW(aaType); |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 348 | // TODO: extract portions of checkDraw that are relevant to path stenciling. |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 349 | SkASSERT(path); |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 350 | SkASSERT(this->caps()->shaderCaps()->pathRenderingSupport()); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 351 | |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 352 | // FIXME: Use path bounds instead of this WAR once |
| 353 | // https://bugs.chromium.org/p/skia/issues/detail?id=5640 is resolved. |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 354 | SkRect bounds = SkRect::MakeIWH(renderTargetContext->width(), renderTargetContext->height()); |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 355 | |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 356 | // Setup clip |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 357 | GrAppliedClip appliedClip(bounds); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 358 | if (!clip.apply(fContext, renderTargetContext, useHWAA, true, &appliedClip)) { |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 359 | return; |
| 360 | } |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 361 | // TODO: respect fClipOpToBounds if we ever start computing bounds here. |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 362 | |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 363 | // Coverage AA does not make sense when rendering to the stencil buffer. The caller should never |
| 364 | // attempt this in a situation that would require coverage AA. |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 365 | SkASSERT(!appliedClip.clipCoverageFragmentProcessor()); |
bsalomon | 0ba8c24 | 2015-10-07 09:20:28 -0700 | [diff] [blame] | 366 | |
Robert Phillips | e60ad62 | 2016-11-17 10:22:48 -0500 | [diff] [blame] | 367 | if (!renderTargetContext->accessRenderTarget()) { |
| 368 | return; |
| 369 | } |
robertphillips | 55fdccc | 2016-06-06 06:16:20 -0700 | [diff] [blame] | 370 | GrStencilAttachment* stencilAttachment = fResourceProvider->attachStencilAttachment( |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 371 | renderTargetContext->accessRenderTarget()); |
cdalton | 17bf820 | 2016-05-13 11:27:15 -0700 | [diff] [blame] | 372 | if (!stencilAttachment) { |
| 373 | SkDebugf("ERROR creating stencil attachment. Draw skipped.\n"); |
| 374 | return; |
| 375 | } |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 376 | |
Brian Salomon | f833478 | 2017-01-03 09:42:58 -0500 | [diff] [blame] | 377 | std::unique_ptr<GrOp> op = GrStencilPathOp::Make(viewMatrix, |
| 378 | useHWAA, |
| 379 | path->getFillType(), |
| 380 | appliedClip.hasStencilClip(), |
| 381 | stencilAttachment->bits(), |
| 382 | appliedClip.scissorState(), |
| 383 | renderTargetContext->accessRenderTarget(), |
| 384 | path); |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 385 | this->recordOp(std::move(op), renderTargetContext, appliedClip.clippedDrawBounds()); |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 386 | } |
| 387 | |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 388 | void GrRenderTargetOpList::fullClear(GrRenderTargetContext* renderTargetContext, GrColor color) { |
| 389 | GrRenderTarget* renderTarget = renderTargetContext->accessRenderTarget(); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 390 | // Currently this just inserts or updates the last clear op. However, once in MDB this can |
| 391 | // 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] | 392 | // color. |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 393 | // TODO: this needs to be updated to use GrSurfaceProxy::UniqueID |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 394 | if (fLastFullClearRenderTargetID == renderTarget->uniqueID()) { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 395 | // As currently implemented, fLastFullClearOp should be the last op because we would |
| 396 | // have cleared it when another op was recorded. |
| 397 | SkASSERT(fRecordedOps.back().fOp.get() == fLastFullClearOp); |
| 398 | fLastFullClearOp->setColor(color); |
bsalomon | fd8d013 | 2016-08-11 11:25:33 -0700 | [diff] [blame] | 399 | return; |
| 400 | } |
Brian Salomon | f833478 | 2017-01-03 09:42:58 -0500 | [diff] [blame] | 401 | std::unique_ptr<GrClearOp> op(GrClearOp::Make(GrFixedClip::Disabled(), color, renderTarget)); |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 402 | if (GrOp* clearOp = this->recordOp(std::move(op), renderTargetContext)) { |
Brian Salomon | 2790c52 | 2016-12-09 16:32:23 -0500 | [diff] [blame] | 403 | // This is either the clear op we just created or another one that it combined with. |
Brian Salomon | 7dae46a | 2016-12-14 16:21:37 -0500 | [diff] [blame] | 404 | fLastFullClearOp = static_cast<GrClearOp*>(clearOp); |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 405 | fLastFullClearRenderTargetID = renderTarget->uniqueID(); |
bsalomon | fd8d013 | 2016-08-11 11:25:33 -0700 | [diff] [blame] | 406 | } |
bsalomon | 9f129de | 2016-08-10 16:31:05 -0700 | [diff] [blame] | 407 | } |
| 408 | |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 409 | void GrRenderTargetOpList::discard(GrRenderTargetContext* renderTargetContext) { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 410 | // Currently this just inserts a discard op. However, once in MDB this can remove all the |
| 411 | // previously recorded ops and change the load op to discard. |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 412 | if (this->caps()->discardRenderTargetSupport()) { |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 413 | this->recordOp(GrDiscardOp::Make(renderTargetContext->accessRenderTarget()), |
| 414 | renderTargetContext); |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 415 | } |
| 416 | } |
| 417 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 418 | //////////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 419 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 420 | bool GrRenderTargetOpList::copySurface(GrSurface* dst, |
| 421 | GrSurface* src, |
| 422 | const SkIRect& srcRect, |
| 423 | const SkIPoint& dstPoint) { |
Brian Salomon | f833478 | 2017-01-03 09:42:58 -0500 | [diff] [blame] | 424 | std::unique_ptr<GrOp> op = GrCopySurfaceOp::Make(dst, src, srcRect, dstPoint); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 425 | if (!op) { |
bsalomon | b8fea97 | 2016-02-16 07:34:17 -0800 | [diff] [blame] | 426 | return false; |
| 427 | } |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 428 | #ifdef ENABLE_MDB |
bsalomon | b8fea97 | 2016-02-16 07:34:17 -0800 | [diff] [blame] | 429 | this->addDependency(src); |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 430 | #endif |
| 431 | |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 432 | // Copy surface doesn't work through a GrGpuCommandBuffer. By passing nullptr for the context we |
| 433 | // force this to occur between command buffers and execute directly on GrGpu. This workaround |
| 434 | // goes away with MDB. |
| 435 | this->recordOp(std::move(op), nullptr); |
bsalomon | b8fea97 | 2016-02-16 07:34:17 -0800 | [diff] [blame] | 436 | return true; |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 437 | } |
| 438 | |
bsalomon | 6cc9006 | 2016-07-08 11:31:22 -0700 | [diff] [blame] | 439 | static inline bool can_reorder(const SkRect& a, const SkRect& b) { |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 440 | return a.fRight <= b.fLeft || a.fBottom <= b.fTop || |
| 441 | b.fRight <= a.fLeft || b.fBottom <= a.fTop; |
| 442 | } |
| 443 | |
bsalomon | 6cc9006 | 2016-07-08 11:31:22 -0700 | [diff] [blame] | 444 | static void join(SkRect* out, const SkRect& a, const SkRect& b) { |
| 445 | SkASSERT(a.fLeft <= a.fRight && a.fTop <= a.fBottom); |
| 446 | SkASSERT(b.fLeft <= b.fRight && b.fTop <= b.fBottom); |
| 447 | out->fLeft = SkTMin(a.fLeft, b.fLeft); |
| 448 | out->fTop = SkTMin(a.fTop, b.fTop); |
| 449 | out->fRight = SkTMax(a.fRight, b.fRight); |
| 450 | out->fBottom = SkTMax(a.fBottom, b.fBottom); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 451 | } |
| 452 | |
Brian Salomon | f833478 | 2017-01-03 09:42:58 -0500 | [diff] [blame] | 453 | GrOp* GrRenderTargetOpList::recordOp(std::unique_ptr<GrOp> op, |
| 454 | GrRenderTargetContext* renderTargetContext, |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 455 | const SkRect& clippedBounds) { |
| 456 | // TODO: Should be proxy ID. |
| 457 | GrGpuResource::UniqueID renderTargetID = |
| 458 | renderTargetContext ? renderTargetContext->accessRenderTarget()->uniqueID() |
| 459 | : GrGpuResource::UniqueID::InvalidID(); |
| 460 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 461 | // A closed GrOpList should never receive new/more ops |
robertphillips | 6a18665 | 2015-10-20 07:37:58 -0700 | [diff] [blame] | 462 | SkASSERT(!this->isClosed()); |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 463 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 464 | // Check if there is an op we can combine with by linearly searching back until we either |
| 465 | // 1) check every op |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 466 | // 2) intersect with something |
| 467 | // 3) find a 'blocker' |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 468 | GR_AUDIT_TRAIL_ADD_OP(fAuditTrail, op.get(), renderTargetID); |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 469 | GrOP_INFO("Re-Recording (%s, B%u)\n" |
| 470 | "\tBounds LRTB (%f, %f, %f, %f)\n", |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 471 | op->name(), |
| 472 | op->uniqueID(), |
| 473 | op->bounds().fLeft, op->bounds().fRight, |
| 474 | op->bounds().fTop, op->bounds().fBottom); |
| 475 | GrOP_INFO(SkTabString(op->dumpInfo(), 1).c_str()); |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 476 | GrOP_INFO("\tClipped Bounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", |
| 477 | clippedBounds.fLeft, clippedBounds.fTop, clippedBounds.fRight, |
| 478 | clippedBounds.fBottom); |
| 479 | GrOP_INFO("\tOutcome:\n"); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 480 | int maxCandidates = SkTMin(fMaxOpLookback, fRecordedOps.count()); |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 481 | // If we don't have a valid destination render target ID then we cannot reorder. |
| 482 | if (maxCandidates && !renderTargetID.isInvalid()) { |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 483 | int i = 0; |
| 484 | while (true) { |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 485 | const RecordedOp& candidate = fRecordedOps.fromBack(i); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 486 | // We cannot continue to search backwards if the render target changes |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 487 | if (candidate.fRenderTargetID != renderTargetID) { |
| 488 | GrOP_INFO("\t\tBreaking because of (%s, B%u) Rendertarget\n", candidate.fOp->name(), |
| 489 | candidate.fOp->uniqueID()); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 490 | break; |
| 491 | } |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 492 | if (candidate.fOp->combineIfPossible(op.get(), *this->caps())) { |
| 493 | GrOP_INFO("\t\tCombining with (%s, B%u)\n", candidate.fOp->name(), |
| 494 | candidate.fOp->uniqueID()); |
| 495 | GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(fAuditTrail, candidate.fOp.get(), op.get()); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 496 | join(&fRecordedOps.fromBack(i).fClippedBounds, |
| 497 | fRecordedOps.fromBack(i).fClippedBounds, clippedBounds); |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 498 | return candidate.fOp.get(); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 499 | } |
| 500 | // Stop going backwards if we would cause a painter's order violation. |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 501 | const SkRect& candidateBounds = fRecordedOps.fromBack(i).fClippedBounds; |
bsalomon | 6cc9006 | 2016-07-08 11:31:22 -0700 | [diff] [blame] | 502 | if (!can_reorder(candidateBounds, clippedBounds)) { |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 503 | GrOP_INFO("\t\tIntersects with (%s, B%u)\n", candidate.fOp->name(), |
| 504 | candidate.fOp->uniqueID()); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 505 | break; |
| 506 | } |
| 507 | ++i; |
| 508 | if (i == maxCandidates) { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 509 | 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] | 510 | break; |
| 511 | } |
| 512 | } |
| 513 | } else { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 514 | GrOP_INFO("\t\tFirstOp\n"); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 515 | } |
Brian Salomon | 42ad83a | 2016-12-20 16:14:45 -0500 | [diff] [blame] | 516 | GR_AUDIT_TRAIL_OP_RESULT_NEW(fAuditTrail, op); |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 517 | fRecordedOps.emplace_back(RecordedOp{std::move(op), clippedBounds, renderTargetID}); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 518 | fLastFullClearOp = nullptr; |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 519 | fLastFullClearRenderTargetID.makeInvalid(); |
Brian Salomon | 2790c52 | 2016-12-09 16:32:23 -0500 | [diff] [blame] | 520 | return fRecordedOps.back().fOp.get(); |
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(); |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 529 | GrGpuResource::UniqueID renderTargetID = fRecordedOps[i].fRenderTargetID; |
| 530 | // If we don't have a valid destination render target ID then we cannot reorder. |
| 531 | if (renderTargetID.isInvalid()) { |
| 532 | continue; |
| 533 | } |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 534 | const SkRect& opBounds = fRecordedOps[i].fClippedBounds; |
| 535 | int maxCandidateIdx = SkTMin(i + fMaxOpLookahead, fRecordedOps.count() - 1); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 536 | int j = i + 1; |
| 537 | while (true) { |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 538 | const RecordedOp& candidate = fRecordedOps[j]; |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 539 | // We cannot continue to search if the render target changes |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 540 | if (candidate.fRenderTargetID != renderTargetID) { |
| 541 | GrOP_INFO("\t\tBreaking because of (%s, B%u) Rendertarget\n", candidate.fOp->name(), |
| 542 | candidate.fOp->uniqueID()); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 543 | break; |
| 544 | } |
| 545 | if (j == i +1) { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 546 | // We assume op would have combined with candidate when the candidate was added |
| 547 | // via backwards combining in recordOp. |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 548 | SkASSERT(!op->combineIfPossible(candidate.fOp.get(), *this->caps())); |
| 549 | } else if (op->combineIfPossible(candidate.fOp.get(), *this->caps())) { |
| 550 | GrOP_INFO("\t\tCombining with (%s, B%u)\n", candidate.fOp->name(), |
| 551 | candidate.fOp->uniqueID()); |
| 552 | GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(fAuditTrail, op, candidate.fOp.get()); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 553 | fRecordedOps[j].fOp = std::move(fRecordedOps[i].fOp); |
| 554 | join(&fRecordedOps[j].fClippedBounds, fRecordedOps[j].fClippedBounds, opBounds); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 555 | break; |
| 556 | } |
| 557 | // Stop going traversing if we would cause a painter's order violation. |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 558 | const SkRect& candidateBounds = fRecordedOps[j].fClippedBounds; |
| 559 | if (!can_reorder(candidateBounds, opBounds)) { |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 560 | GrOP_INFO("\t\tIntersects with (%s, B%u)\n", candidate.fOp->name(), |
| 561 | candidate.fOp->uniqueID()); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 562 | break; |
| 563 | } |
| 564 | ++j; |
| 565 | if (j > maxCandidateIdx) { |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 566 | GrOP_INFO("\t\tReached max lookahead or end of op array %d\n", i); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 567 | break; |
| 568 | } |
| 569 | } |
| 570 | } |
| 571 | } |
| 572 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 573 | /////////////////////////////////////////////////////////////////////////////// |
| 574 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 575 | void GrRenderTargetOpList::clearStencilClip(const GrFixedClip& clip, |
| 576 | bool insideStencilMask, |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 577 | GrRenderTargetContext* renderTargetContext) { |
| 578 | this->recordOp(GrClearStencilClipOp::Make(clip, insideStencilMask, |
| 579 | renderTargetContext->accessRenderTarget()), |
| 580 | renderTargetContext); |
bsalomon | 5ea0363 | 2015-08-18 10:33:30 -0700 | [diff] [blame] | 581 | } |