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