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 | |
| 11 | #include "GrBatch.h" |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 12 | #include "GrContext.h" |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 13 | #include "GrDrawTargetCaps.h" |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 14 | #include "GrPath.h" |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 15 | #include "GrPipeline.h" |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 16 | #include "GrMemoryPool.h" |
joshualitt | ad17cfc | 2015-05-05 10:45:57 -0700 | [diff] [blame] | 17 | #include "GrRectBatch.h" |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 18 | #include "GrRenderTarget.h" |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 19 | #include "GrRenderTargetPriv.h" |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 20 | #include "GrSurfacePriv.h" |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 21 | #include "GrTemplates.h" |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 22 | #include "GrTexture.h" |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 23 | #include "GrVertexBuffer.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 24 | |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 25 | #include "SkStrokeRec.h" |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 26 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 27 | //////////////////////////////////////////////////////////////////////////////// |
| 28 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 29 | #define DEBUG_INVAL_BUFFER 0xdeadcafe |
| 30 | #define DEBUG_INVAL_START_IDX -1 |
| 31 | |
robertphillips | e40d397 | 2015-05-07 09:51:43 -0700 | [diff] [blame] | 32 | GrDrawTarget::GrDrawTarget(GrContext* context) |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 33 | : fContext(context) |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 34 | , fCaps(SkRef(context->getGpu()->caps())) |
| 35 | , fGpuTraceMarkerCount(0) |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 36 | , fFlushing(false) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 37 | SkASSERT(context); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | //////////////////////////////////////////////////////////////////////////////// |
| 41 | |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 42 | bool GrDrawTarget::setupDstReadIfNecessary(const GrPipelineBuilder& pipelineBuilder, |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 43 | const GrProcOptInfo& colorPOI, |
| 44 | const GrProcOptInfo& coveragePOI, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 45 | GrDeviceCoordTexture* dstCopy, |
| 46 | const SkRect* drawBounds) { |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 47 | if (!pipelineBuilder.willXPNeedDstCopy(*this->caps(), colorPOI, coveragePOI)) { |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 48 | return true; |
| 49 | } |
cdalton | 9954bc3 | 2015-04-29 14:17:00 -0700 | [diff] [blame] | 50 | |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 51 | GrRenderTarget* rt = pipelineBuilder.getRenderTarget(); |
cdalton | 9954bc3 | 2015-04-29 14:17:00 -0700 | [diff] [blame] | 52 | |
| 53 | if (this->caps()->textureBarrierSupport()) { |
| 54 | if (GrTexture* rtTex = rt->asTexture()) { |
| 55 | // The render target is a texture, se we can read from it directly in the shader. The XP |
| 56 | // will be responsible to detect this situation and request a texture barrier. |
| 57 | dstCopy->setTexture(rtTex); |
| 58 | dstCopy->setOffset(0, 0); |
| 59 | return true; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | SkIRect copyRect; |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 64 | pipelineBuilder.clip().getConservativeBounds(rt, ©Rect); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 65 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 66 | if (drawBounds) { |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 67 | SkIRect drawIBounds; |
| 68 | drawBounds->roundOut(&drawIBounds); |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 69 | if (!copyRect.intersect(drawIBounds)) { |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 70 | #ifdef SK_DEBUG |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 71 | GrContextDebugf(fContext, "Missed an early reject. " |
| 72 | "Bailing on draw from setupDstReadIfNecessary.\n"); |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 73 | #endif |
| 74 | return false; |
| 75 | } |
| 76 | } else { |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 77 | #ifdef SK_DEBUG |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 78 | //SkDebugf("No dev bounds when dst copy is made.\n"); |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 79 | #endif |
| 80 | } |
skia.committer@gmail.com | 05a2ee0 | 2013-04-02 07:01:34 +0000 | [diff] [blame] | 81 | |
commit-bot@chromium.org | 63150af | 2013-04-11 22:00:22 +0000 | [diff] [blame] | 82 | // MSAA consideration: When there is support for reading MSAA samples in the shader we could |
| 83 | // have per-sample dst values by making the copy multisampled. |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 84 | GrSurfaceDesc desc; |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 85 | if (!this->getGpu()->initCopySurfaceDstDesc(rt, &desc)) { |
| 86 | desc.fOrigin = kDefault_GrSurfaceOrigin; |
| 87 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 88 | desc.fConfig = rt->config(); |
| 89 | } |
| 90 | |
| 91 | |
commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 92 | desc.fWidth = copyRect.width(); |
| 93 | desc.fHeight = copyRect.height(); |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 94 | |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame] | 95 | SkAutoTUnref<GrTexture> copy(fContext->textureProvider()->refScratchTexture(desc, |
| 96 | GrTextureProvider::kApprox_ScratchTexMatch)); |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 97 | |
bsalomon | e305973 | 2014-10-14 11:47:22 -0700 | [diff] [blame] | 98 | if (!copy) { |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 99 | SkDebugf("Failed to create temporary copy of destination texture.\n"); |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 100 | return false; |
| 101 | } |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 102 | SkIPoint dstPoint = {0, 0}; |
mtklein | 404b3b2 | 2015-05-18 09:29:10 -0700 | [diff] [blame] | 103 | if (this->copySurface(copy, rt, copyRect, dstPoint)) { |
| 104 | dstCopy->setTexture(copy); |
| 105 | dstCopy->setOffset(copyRect.fLeft, copyRect.fTop); |
| 106 | return true; |
| 107 | } else { |
| 108 | return false; |
| 109 | } |
bsalomon@google.com | 26e18b5 | 2013-03-29 19:22:36 +0000 | [diff] [blame] | 110 | } |
| 111 | |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 112 | void GrDrawTarget::flush() { |
| 113 | if (fFlushing) { |
| 114 | return; |
| 115 | } |
| 116 | fFlushing = true; |
| 117 | |
| 118 | this->getGpu()->saveActiveTraceMarkers(); |
| 119 | |
| 120 | this->onFlush(); |
| 121 | |
| 122 | this->getGpu()->restoreActiveTraceMarkers(); |
| 123 | |
| 124 | fFlushing = false; |
| 125 | this->reset(); |
| 126 | } |
| 127 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 128 | void GrDrawTarget::drawBatch(GrPipelineBuilder* pipelineBuilder, |
joshualitt | 99c7c07 | 2015-05-01 13:43:30 -0700 | [diff] [blame] | 129 | GrBatch* batch) { |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 130 | SkASSERT(pipelineBuilder); |
| 131 | // TODO some kind of checkdraw, but not at this level |
| 132 | |
| 133 | // Setup clip |
| 134 | GrScissorState scissorState; |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 135 | GrPipelineBuilder::AutoRestoreFragmentProcessors arfp; |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 136 | GrPipelineBuilder::AutoRestoreStencil ars; |
joshualitt | 99c7c07 | 2015-05-01 13:43:30 -0700 | [diff] [blame] | 137 | if (!this->setupClip(pipelineBuilder, &arfp, &ars, &scissorState, &batch->bounds())) { |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 138 | return; |
| 139 | } |
| 140 | |
joshualitt | 99c7c07 | 2015-05-01 13:43:30 -0700 | [diff] [blame] | 141 | // Batch bounds are tight, so for dev copies |
| 142 | // TODO move this into setupDstReadIfNecessary when paths are in batch |
| 143 | SkRect bounds = batch->bounds(); |
| 144 | bounds.outset(0.5f, 0.5f); |
| 145 | |
| 146 | GrDrawTarget::PipelineInfo pipelineInfo(pipelineBuilder, &scissorState, batch, &bounds, |
| 147 | this); |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 148 | if (pipelineInfo.mustSkipDraw()) { |
| 149 | return; |
| 150 | } |
| 151 | |
| 152 | this->onDrawBatch(batch, pipelineInfo); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 153 | } |
| 154 | |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 155 | static const GrStencilSettings& winding_path_stencil_settings() { |
| 156 | GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, |
| 157 | kIncClamp_StencilOp, |
| 158 | kIncClamp_StencilOp, |
| 159 | kAlwaysIfInClip_StencilFunc, |
| 160 | 0xFFFF, 0xFFFF, 0xFFFF); |
| 161 | return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); |
| 162 | } |
| 163 | |
| 164 | static const GrStencilSettings& even_odd_path_stencil_settings() { |
| 165 | GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, |
| 166 | kInvert_StencilOp, |
| 167 | kInvert_StencilOp, |
| 168 | kAlwaysIfInClip_StencilFunc, |
| 169 | 0xFFFF, 0xFFFF, 0xFFFF); |
| 170 | return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); |
| 171 | } |
| 172 | |
| 173 | void GrDrawTarget::getPathStencilSettingsForFilltype(GrPathRendering::FillType fill, |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 174 | const GrStencilAttachment* sb, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 175 | GrStencilSettings* outStencilSettings) { |
| 176 | |
| 177 | switch (fill) { |
| 178 | default: |
| 179 | SkFAIL("Unexpected path fill."); |
| 180 | case GrPathRendering::kWinding_FillType: |
| 181 | *outStencilSettings = winding_path_stencil_settings(); |
| 182 | break; |
| 183 | case GrPathRendering::kEvenOdd_FillType: |
| 184 | *outStencilSettings = even_odd_path_stencil_settings(); |
| 185 | break; |
| 186 | } |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 187 | this->clipMaskManager()->adjustPathStencilParams(sb, outStencilSettings); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 188 | } |
| 189 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 190 | void GrDrawTarget::stencilPath(GrPipelineBuilder* pipelineBuilder, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 191 | const GrPathProcessor* pathProc, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 192 | const GrPath* path, |
| 193 | GrPathRendering::FillType fill) { |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 194 | // TODO: extract portions of checkDraw that are relevant to path stenciling. |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 195 | SkASSERT(path); |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 196 | SkASSERT(this->caps()->shaderCaps()->pathRenderingSupport()); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 197 | SkASSERT(pipelineBuilder); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 198 | |
| 199 | // Setup clip |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 200 | GrScissorState scissorState; |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 201 | GrPipelineBuilder::AutoRestoreFragmentProcessors arfp; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 202 | GrPipelineBuilder::AutoRestoreStencil ars; |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 203 | if (!this->setupClip(pipelineBuilder, &arfp, &ars, &scissorState, NULL)) { |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 204 | return; |
| 205 | } |
| 206 | |
| 207 | // set stencil settings for path |
| 208 | GrStencilSettings stencilSettings; |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 209 | GrRenderTarget* rt = pipelineBuilder->getRenderTarget(); |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 210 | GrStencilAttachment* sb = rt->renderTargetPriv().attachStencilAttachment(); |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 211 | this->getPathStencilSettingsForFilltype(fill, sb, &stencilSettings); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 212 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 213 | this->onStencilPath(*pipelineBuilder, pathProc, path, scissorState, stencilSettings); |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 214 | } |
| 215 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 216 | void GrDrawTarget::drawPath(GrPipelineBuilder* pipelineBuilder, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 217 | const GrPathProcessor* pathProc, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 218 | const GrPath* path, |
| 219 | GrPathRendering::FillType fill) { |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 220 | // TODO: extract portions of checkDraw that are relevant to path rendering. |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 221 | SkASSERT(path); |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 222 | SkASSERT(this->caps()->shaderCaps()->pathRenderingSupport()); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 223 | SkASSERT(pipelineBuilder); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 224 | |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 225 | SkRect devBounds = path->getBounds(); |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 226 | pathProc->viewMatrix().mapRect(&devBounds); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 227 | |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 228 | // Setup clip |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 229 | GrScissorState scissorState; |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 230 | GrPipelineBuilder::AutoRestoreFragmentProcessors arfp; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 231 | GrPipelineBuilder::AutoRestoreStencil ars; |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 232 | if (!this->setupClip(pipelineBuilder, &arfp, &ars, &scissorState, &devBounds)) { |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 233 | return; |
| 234 | } |
| 235 | |
| 236 | // set stencil settings for path |
| 237 | GrStencilSettings stencilSettings; |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 238 | GrRenderTarget* rt = pipelineBuilder->getRenderTarget(); |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 239 | GrStencilAttachment* sb = rt->renderTargetPriv().attachStencilAttachment(); |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 240 | this->getPathStencilSettingsForFilltype(fill, sb, &stencilSettings); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 241 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 242 | GrDrawTarget::PipelineInfo pipelineInfo(pipelineBuilder, &scissorState, pathProc, &devBounds, |
| 243 | this); |
| 244 | if (pipelineInfo.mustSkipDraw()) { |
| 245 | return; |
| 246 | } |
| 247 | |
| 248 | this->onDrawPath(pathProc, path, stencilSettings, pipelineInfo); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 249 | } |
| 250 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 251 | void GrDrawTarget::drawPaths(GrPipelineBuilder* pipelineBuilder, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 252 | const GrPathProcessor* pathProc, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 253 | const GrPathRange* pathRange, |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 254 | const void* indices, |
| 255 | PathIndexType indexType, |
| 256 | const float transformValues[], |
| 257 | PathTransformType transformType, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 258 | int count, |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 259 | GrPathRendering::FillType fill) { |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 260 | SkASSERT(this->caps()->shaderCaps()->pathRenderingSupport()); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 261 | SkASSERT(pathRange); |
| 262 | SkASSERT(indices); |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 263 | SkASSERT(0 == reinterpret_cast<long>(indices) % GrPathRange::PathIndexSizeInBytes(indexType)); |
| 264 | SkASSERT(transformValues); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 265 | SkASSERT(pipelineBuilder); |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 266 | |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 267 | // Setup clip |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 268 | GrScissorState scissorState; |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 269 | GrPipelineBuilder::AutoRestoreFragmentProcessors arfp; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 270 | GrPipelineBuilder::AutoRestoreStencil ars; |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 271 | |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 272 | if (!this->setupClip(pipelineBuilder, &arfp, &ars, &scissorState, NULL)) { |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 273 | return; |
| 274 | } |
| 275 | |
| 276 | // set stencil settings for path |
| 277 | GrStencilSettings stencilSettings; |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 278 | GrRenderTarget* rt = pipelineBuilder->getRenderTarget(); |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 279 | GrStencilAttachment* sb = rt->renderTargetPriv().attachStencilAttachment(); |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 280 | this->getPathStencilSettingsForFilltype(fill, sb, &stencilSettings); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 281 | |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 282 | // Don't compute a bounding box for dst copy texture, we'll opt |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 283 | // instead for it to just copy the entire dst. Realistically this is a moot |
| 284 | // point, because any context that supports NV_path_rendering will also |
| 285 | // support NV_blend_equation_advanced. |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 286 | GrDrawTarget::PipelineInfo pipelineInfo(pipelineBuilder, &scissorState, pathProc, NULL, this); |
| 287 | if (pipelineInfo.mustSkipDraw()) { |
| 288 | return; |
| 289 | } |
| 290 | |
| 291 | this->onDrawPaths(pathProc, pathRange, indices, indexType, transformValues, |
| 292 | transformType, count, stencilSettings, pipelineInfo); |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 293 | } |
| 294 | |
joshualitt | ad17cfc | 2015-05-05 10:45:57 -0700 | [diff] [blame] | 295 | void GrDrawTarget::drawRect(GrPipelineBuilder* pipelineBuilder, |
| 296 | GrColor color, |
| 297 | const SkMatrix& viewMatrix, |
| 298 | const SkRect& rect, |
| 299 | const SkRect* localRect, |
| 300 | const SkMatrix* localMatrix) { |
| 301 | SkAutoTUnref<GrBatch> batch(GrRectBatch::Create(color, viewMatrix, rect, localRect, |
| 302 | localMatrix)); |
| 303 | this->drawBatch(pipelineBuilder, batch); |
| 304 | } |
| 305 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 306 | void GrDrawTarget::clear(const SkIRect* rect, |
| 307 | GrColor color, |
| 308 | bool canIgnoreRect, |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 309 | GrRenderTarget* renderTarget) { |
| 310 | if (fCaps->useDrawInsteadOfClear()) { |
| 311 | // This works around a driver bug with clear by drawing a rect instead. |
| 312 | // The driver will ignore a clear if it is the only thing rendered to a |
| 313 | // target before the target is read. |
| 314 | SkIRect rtRect = SkIRect::MakeWH(renderTarget->width(), renderTarget->height()); |
| 315 | if (NULL == rect || canIgnoreRect || rect->contains(rtRect)) { |
| 316 | rect = &rtRect; |
| 317 | // We first issue a discard() since that may help tilers. |
| 318 | this->discard(renderTarget); |
| 319 | } |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 320 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 321 | GrPipelineBuilder pipelineBuilder; |
| 322 | pipelineBuilder.setRenderTarget(renderTarget); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 323 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 324 | this->drawSimpleRect(&pipelineBuilder, color, SkMatrix::I(), *rect); |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 325 | } else { |
| 326 | this->onClear(rect, color, canIgnoreRect, renderTarget); |
| 327 | } |
| 328 | } |
| 329 | |
egdaniel | 3eee383 | 2014-06-18 13:09:11 -0700 | [diff] [blame] | 330 | typedef GrTraceMarkerSet::Iter TMIter; |
| 331 | void GrDrawTarget::saveActiveTraceMarkers() { |
| 332 | if (this->caps()->gpuTracingSupport()) { |
| 333 | SkASSERT(0 == fStoredTraceMarkers.count()); |
| 334 | fStoredTraceMarkers.addSet(fActiveTraceMarkers); |
| 335 | for (TMIter iter = fStoredTraceMarkers.begin(); iter != fStoredTraceMarkers.end(); ++iter) { |
| 336 | this->removeGpuTraceMarker(&(*iter)); |
| 337 | } |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | void GrDrawTarget::restoreActiveTraceMarkers() { |
| 342 | if (this->caps()->gpuTracingSupport()) { |
| 343 | SkASSERT(0 == fActiveTraceMarkers.count()); |
| 344 | for (TMIter iter = fStoredTraceMarkers.begin(); iter != fStoredTraceMarkers.end(); ++iter) { |
| 345 | this->addGpuTraceMarker(&(*iter)); |
| 346 | } |
| 347 | for (TMIter iter = fActiveTraceMarkers.begin(); iter != fActiveTraceMarkers.end(); ++iter) { |
| 348 | this->fStoredTraceMarkers.remove(*iter); |
| 349 | } |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | void GrDrawTarget::addGpuTraceMarker(const GrGpuTraceMarker* marker) { |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 354 | if (this->caps()->gpuTracingSupport()) { |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 355 | SkASSERT(fGpuTraceMarkerCount >= 0); |
| 356 | this->fActiveTraceMarkers.add(*marker); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 357 | ++fGpuTraceMarkerCount; |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 358 | } |
| 359 | } |
| 360 | |
egdaniel | 3eee383 | 2014-06-18 13:09:11 -0700 | [diff] [blame] | 361 | void GrDrawTarget::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 362 | if (this->caps()->gpuTracingSupport()) { |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 363 | SkASSERT(fGpuTraceMarkerCount >= 1); |
| 364 | this->fActiveTraceMarkers.remove(*marker); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 365 | --fGpuTraceMarkerCount; |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 366 | } |
| 367 | } |
| 368 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 369 | //////////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 370 | |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 371 | namespace { |
| 372 | // returns true if the read/written rect intersects the src/dst and false if not. |
| 373 | bool clip_srcrect_and_dstpoint(const GrSurface* dst, |
| 374 | const GrSurface* src, |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 375 | const SkIRect& srcRect, |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 376 | const SkIPoint& dstPoint, |
| 377 | SkIRect* clippedSrcRect, |
| 378 | SkIPoint* clippedDstPoint) { |
| 379 | *clippedSrcRect = srcRect; |
| 380 | *clippedDstPoint = dstPoint; |
skia.committer@gmail.com | a9493a3 | 2013-04-04 07:01:12 +0000 | [diff] [blame] | 381 | |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 382 | // clip the left edge to src and dst bounds, adjusting dstPoint if necessary |
| 383 | if (clippedSrcRect->fLeft < 0) { |
| 384 | clippedDstPoint->fX -= clippedSrcRect->fLeft; |
| 385 | clippedSrcRect->fLeft = 0; |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 386 | } |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 387 | if (clippedDstPoint->fX < 0) { |
| 388 | clippedSrcRect->fLeft -= clippedDstPoint->fX; |
| 389 | clippedDstPoint->fX = 0; |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 390 | } |
| 391 | |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 392 | // clip the top edge to src and dst bounds, adjusting dstPoint if necessary |
| 393 | if (clippedSrcRect->fTop < 0) { |
| 394 | clippedDstPoint->fY -= clippedSrcRect->fTop; |
| 395 | clippedSrcRect->fTop = 0; |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 396 | } |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 397 | if (clippedDstPoint->fY < 0) { |
| 398 | clippedSrcRect->fTop -= clippedDstPoint->fY; |
| 399 | clippedDstPoint->fY = 0; |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 400 | } |
skia.committer@gmail.com | a9493a3 | 2013-04-04 07:01:12 +0000 | [diff] [blame] | 401 | |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 402 | // clip the right edge to the src and dst bounds. |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 403 | if (clippedSrcRect->fRight > src->width()) { |
| 404 | clippedSrcRect->fRight = src->width(); |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 405 | } |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 406 | if (clippedDstPoint->fX + clippedSrcRect->width() > dst->width()) { |
| 407 | clippedSrcRect->fRight = clippedSrcRect->fLeft + dst->width() - clippedDstPoint->fX; |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | // clip the bottom edge to the src and dst bounds. |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 411 | if (clippedSrcRect->fBottom > src->height()) { |
| 412 | clippedSrcRect->fBottom = src->height(); |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 413 | } |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 414 | if (clippedDstPoint->fY + clippedSrcRect->height() > dst->height()) { |
| 415 | clippedSrcRect->fBottom = clippedSrcRect->fTop + dst->height() - clippedDstPoint->fY; |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 416 | } |
skia.committer@gmail.com | a9493a3 | 2013-04-04 07:01:12 +0000 | [diff] [blame] | 417 | |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 418 | // The above clipping steps may have inverted the rect if it didn't intersect either the src or |
| 419 | // dst bounds. |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 420 | return !clippedSrcRect->isEmpty(); |
| 421 | } |
| 422 | } |
| 423 | |
mtklein | 404b3b2 | 2015-05-18 09:29:10 -0700 | [diff] [blame] | 424 | bool GrDrawTarget::copySurface(GrSurface* dst, |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 425 | GrSurface* src, |
| 426 | const SkIRect& srcRect, |
| 427 | const SkIPoint& dstPoint) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 428 | SkASSERT(dst); |
| 429 | SkASSERT(src); |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 430 | |
| 431 | SkIRect clippedSrcRect; |
| 432 | SkIPoint clippedDstPoint; |
| 433 | // If the rect is outside the src or dst then we've already succeeded. |
| 434 | if (!clip_srcrect_and_dstpoint(dst, |
| 435 | src, |
| 436 | srcRect, |
| 437 | dstPoint, |
| 438 | &clippedSrcRect, |
| 439 | &clippedDstPoint)) { |
mtklein | 404b3b2 | 2015-05-18 09:29:10 -0700 | [diff] [blame] | 440 | return true; |
bsalomon@google.com | e4617bf | 2013-04-03 14:56:40 +0000 | [diff] [blame] | 441 | } |
| 442 | |
mtklein | 404b3b2 | 2015-05-18 09:29:10 -0700 | [diff] [blame] | 443 | if (this->getGpu()->canCopySurface(dst, src, clippedSrcRect, clippedDstPoint)) { |
| 444 | this->onCopySurface(dst, src, clippedSrcRect, clippedDstPoint); |
| 445 | return true; |
| 446 | } |
| 447 | |
| 448 | GrRenderTarget* rt = dst->asRenderTarget(); |
| 449 | GrTexture* tex = src->asTexture(); |
| 450 | |
| 451 | if ((dst == src) || !rt || !tex) { |
| 452 | return false; |
| 453 | } |
| 454 | |
| 455 | GrPipelineBuilder pipelineBuilder; |
| 456 | pipelineBuilder.setRenderTarget(rt); |
| 457 | SkMatrix matrix; |
| 458 | matrix.setTranslate(SkIntToScalar(clippedSrcRect.fLeft - clippedDstPoint.fX), |
| 459 | SkIntToScalar(clippedSrcRect.fTop - clippedDstPoint.fY)); |
| 460 | matrix.postIDiv(tex->width(), tex->height()); |
| 461 | pipelineBuilder.addColorTextureProcessor(tex, matrix); |
| 462 | SkIRect dstRect = SkIRect::MakeXYWH(clippedDstPoint.fX, |
| 463 | clippedDstPoint.fY, |
| 464 | clippedSrcRect.width(), |
| 465 | clippedSrcRect.height()); |
| 466 | this->drawSimpleRect(&pipelineBuilder, GrColor_WHITE, SkMatrix::I(), dstRect); |
| 467 | return true; |
| 468 | } |
| 469 | |
| 470 | bool GrDrawTarget::canCopySurface(const GrSurface* dst, |
| 471 | const GrSurface* src, |
| 472 | const SkIRect& srcRect, |
| 473 | const SkIPoint& dstPoint) { |
| 474 | SkASSERT(dst); |
| 475 | SkASSERT(src); |
| 476 | |
| 477 | SkIRect clippedSrcRect; |
| 478 | SkIPoint clippedDstPoint; |
| 479 | // If the rect is outside the src or dst then we're guaranteed success |
| 480 | if (!clip_srcrect_and_dstpoint(dst, |
| 481 | src, |
| 482 | srcRect, |
| 483 | dstPoint, |
| 484 | &clippedSrcRect, |
| 485 | &clippedDstPoint)) { |
| 486 | return true; |
| 487 | } |
| 488 | return ((dst != src) && dst->asRenderTarget() && src->asTexture()) || |
| 489 | this->getGpu()->canCopySurface(dst, src, clippedSrcRect, clippedDstPoint); |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 490 | } |
| 491 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 492 | void GrDrawTarget::setupPipeline(const PipelineInfo& pipelineInfo, |
| 493 | GrPipeline* pipeline) { |
| 494 | SkNEW_PLACEMENT_ARGS(pipeline, GrPipeline, (*pipelineInfo.fPipelineBuilder, |
| 495 | pipelineInfo.fColorPOI, |
| 496 | pipelineInfo.fCoveragePOI, |
| 497 | *this->caps(), |
| 498 | *pipelineInfo.fScissor, |
| 499 | &pipelineInfo.fDstCopy)); |
| 500 | } |
| 501 | /////////////////////////////////////////////////////////////////////////////// |
| 502 | |
| 503 | GrDrawTarget::PipelineInfo::PipelineInfo(GrPipelineBuilder* pipelineBuilder, |
| 504 | GrScissorState* scissor, |
| 505 | const GrPrimitiveProcessor* primProc, |
| 506 | const SkRect* devBounds, |
| 507 | GrDrawTarget* target) |
| 508 | : fPipelineBuilder(pipelineBuilder) |
| 509 | , fScissor(scissor) { |
| 510 | fColorPOI = fPipelineBuilder->colorProcInfo(primProc); |
| 511 | fCoveragePOI = fPipelineBuilder->coverageProcInfo(primProc); |
| 512 | if (!target->setupDstReadIfNecessary(*fPipelineBuilder, fColorPOI, fCoveragePOI, |
| 513 | &fDstCopy, devBounds)) { |
| 514 | fPipelineBuilder = NULL; |
| 515 | } |
| 516 | } |
| 517 | |
| 518 | GrDrawTarget::PipelineInfo::PipelineInfo(GrPipelineBuilder* pipelineBuilder, |
| 519 | GrScissorState* scissor, |
| 520 | const GrBatch* batch, |
| 521 | const SkRect* devBounds, |
| 522 | GrDrawTarget* target) |
| 523 | : fPipelineBuilder(pipelineBuilder) |
| 524 | , fScissor(scissor) { |
| 525 | fColorPOI = fPipelineBuilder->colorProcInfo(batch); |
| 526 | fCoveragePOI = fPipelineBuilder->coverageProcInfo(batch); |
| 527 | if (!target->setupDstReadIfNecessary(*fPipelineBuilder, fColorPOI, fCoveragePOI, |
| 528 | &fDstCopy, devBounds)) { |
| 529 | fPipelineBuilder = NULL; |
| 530 | } |
| 531 | } |
| 532 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 533 | /////////////////////////////////////////////////////////////////////////////// |
| 534 | |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 535 | void GrShaderCaps::reset() { |
| 536 | fShaderDerivativeSupport = false; |
| 537 | fGeometryShaderSupport = false; |
| 538 | fPathRenderingSupport = false; |
| 539 | fDstReadInShaderSupport = false; |
| 540 | fDualSourceBlendingSupport = false; |
cdalton | 0edea2c | 2015-05-21 08:27:44 -0700 | [diff] [blame^] | 541 | fMixedSamplesSupport = false; |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 542 | |
| 543 | fShaderPrecisionVaries = false; |
| 544 | } |
| 545 | |
| 546 | GrShaderCaps& GrShaderCaps::operator=(const GrShaderCaps& other) { |
| 547 | fShaderDerivativeSupport = other.fShaderDerivativeSupport; |
| 548 | fGeometryShaderSupport = other.fGeometryShaderSupport; |
| 549 | fPathRenderingSupport = other.fPathRenderingSupport; |
| 550 | fDstReadInShaderSupport = other.fDstReadInShaderSupport; |
| 551 | fDualSourceBlendingSupport = other.fDualSourceBlendingSupport; |
cdalton | 0edea2c | 2015-05-21 08:27:44 -0700 | [diff] [blame^] | 552 | fMixedSamplesSupport = other.fMixedSamplesSupport; |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 553 | |
| 554 | fShaderPrecisionVaries = other.fShaderPrecisionVaries; |
| 555 | for (int s = 0; s < kGrShaderTypeCount; ++s) { |
| 556 | for (int p = 0; p < kGrSLPrecisionCount; ++p) { |
| 557 | fFloatPrecisions[s][p] = other.fFloatPrecisions[s][p]; |
| 558 | } |
| 559 | } |
| 560 | return *this; |
| 561 | } |
| 562 | |
| 563 | static const char* shader_type_to_string(GrShaderType type) { |
| 564 | switch (type) { |
| 565 | case kVertex_GrShaderType: |
| 566 | return "vertex"; |
| 567 | case kGeometry_GrShaderType: |
| 568 | return "geometry"; |
| 569 | case kFragment_GrShaderType: |
| 570 | return "fragment"; |
| 571 | } |
| 572 | return ""; |
| 573 | } |
| 574 | |
| 575 | static const char* precision_to_string(GrSLPrecision p) { |
| 576 | switch (p) { |
| 577 | case kLow_GrSLPrecision: |
| 578 | return "low"; |
| 579 | case kMedium_GrSLPrecision: |
| 580 | return "medium"; |
| 581 | case kHigh_GrSLPrecision: |
| 582 | return "high"; |
| 583 | } |
| 584 | return ""; |
| 585 | } |
| 586 | |
| 587 | SkString GrShaderCaps::dump() const { |
| 588 | SkString r; |
| 589 | static const char* gNY[] = { "NO", "YES" }; |
| 590 | r.appendf("Shader Derivative Support : %s\n", gNY[fShaderDerivativeSupport]); |
| 591 | r.appendf("Geometry Shader Support : %s\n", gNY[fGeometryShaderSupport]); |
| 592 | r.appendf("Path Rendering Support : %s\n", gNY[fPathRenderingSupport]); |
| 593 | r.appendf("Dst Read In Shader Support : %s\n", gNY[fDstReadInShaderSupport]); |
| 594 | r.appendf("Dual Source Blending Support : %s\n", gNY[fDualSourceBlendingSupport]); |
cdalton | 0edea2c | 2015-05-21 08:27:44 -0700 | [diff] [blame^] | 595 | r.appendf("Mixed Samples Support : %s\n", gNY[fMixedSamplesSupport]); |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 596 | |
| 597 | r.appendf("Shader Float Precisions (varies: %s):\n", gNY[fShaderPrecisionVaries]); |
| 598 | |
| 599 | for (int s = 0; s < kGrShaderTypeCount; ++s) { |
| 600 | GrShaderType shaderType = static_cast<GrShaderType>(s); |
| 601 | r.appendf("\t%s:\n", shader_type_to_string(shaderType)); |
| 602 | for (int p = 0; p < kGrSLPrecisionCount; ++p) { |
| 603 | if (fFloatPrecisions[s][p].supported()) { |
| 604 | GrSLPrecision precision = static_cast<GrSLPrecision>(p); |
| 605 | r.appendf("\t\t%s: log_low: %d log_high: %d bits: %d\n", |
| 606 | precision_to_string(precision), |
| 607 | fFloatPrecisions[s][p].fLogRangeLow, |
| 608 | fFloatPrecisions[s][p].fLogRangeHigh, |
| 609 | fFloatPrecisions[s][p].fBits); |
| 610 | } |
| 611 | } |
| 612 | } |
| 613 | |
| 614 | return r; |
| 615 | } |
| 616 | |
| 617 | /////////////////////////////////////////////////////////////////////////////// |
| 618 | |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 619 | void GrCaps::reset() { |
commit-bot@chromium.org | 4744231 | 2013-12-19 16:18:01 +0000 | [diff] [blame] | 620 | fMipMapSupport = false; |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 621 | fNPOTTextureTileSupport = false; |
| 622 | fTwoSidedStencilSupport = false; |
| 623 | fStencilWrapOpsSupport = false; |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 624 | fDiscardRenderTargetSupport = false; |
commit-bot@chromium.org | b835652 | 2013-07-18 22:26:39 +0000 | [diff] [blame] | 625 | fReuseScratchTextures = true; |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 626 | fGpuTracingSupport = false; |
krajcevski | 78697816 | 2014-07-30 11:25:44 -0700 | [diff] [blame] | 627 | fCompressedTexSubImageSupport = false; |
bsalomon | d08ea5f | 2015-02-20 06:58:13 -0800 | [diff] [blame] | 628 | fOversizedStencilSupport = false; |
cdalton | fd4167d | 2015-04-21 11:45:56 -0700 | [diff] [blame] | 629 | fTextureBarrierSupport = false; |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 630 | |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 631 | fUseDrawInsteadOfClear = false; |
| 632 | |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 633 | fBlendEquationSupport = kBasic_BlendEquationSupport; |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 634 | fMapBufferFlags = kNone_MapFlags; |
| 635 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 636 | fMaxRenderTargetSize = 0; |
| 637 | fMaxTextureSize = 0; |
| 638 | fMaxSampleCount = 0; |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 639 | |
| 640 | memset(fConfigRenderSupport, 0, sizeof(fConfigRenderSupport)); |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 641 | memset(fConfigTextureSupport, 0, sizeof(fConfigTextureSupport)); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 642 | } |
| 643 | |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 644 | GrCaps& GrCaps::operator=(const GrCaps& other) { |
commit-bot@chromium.org | 4744231 | 2013-12-19 16:18:01 +0000 | [diff] [blame] | 645 | fMipMapSupport = other.fMipMapSupport; |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 646 | fNPOTTextureTileSupport = other.fNPOTTextureTileSupport; |
| 647 | fTwoSidedStencilSupport = other.fTwoSidedStencilSupport; |
| 648 | fStencilWrapOpsSupport = other.fStencilWrapOpsSupport; |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 649 | fDiscardRenderTargetSupport = other.fDiscardRenderTargetSupport; |
commit-bot@chromium.org | b835652 | 2013-07-18 22:26:39 +0000 | [diff] [blame] | 650 | fReuseScratchTextures = other.fReuseScratchTextures; |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 651 | fGpuTracingSupport = other.fGpuTracingSupport; |
krajcevski | 78697816 | 2014-07-30 11:25:44 -0700 | [diff] [blame] | 652 | fCompressedTexSubImageSupport = other.fCompressedTexSubImageSupport; |
bsalomon | d08ea5f | 2015-02-20 06:58:13 -0800 | [diff] [blame] | 653 | fOversizedStencilSupport = other.fOversizedStencilSupport; |
cdalton | fd4167d | 2015-04-21 11:45:56 -0700 | [diff] [blame] | 654 | fTextureBarrierSupport = other.fTextureBarrierSupport; |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 655 | |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 656 | fUseDrawInsteadOfClear = other.fUseDrawInsteadOfClear; |
| 657 | |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 658 | fBlendEquationSupport = other.fBlendEquationSupport; |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 659 | fMapBufferFlags = other.fMapBufferFlags; |
| 660 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 661 | fMaxRenderTargetSize = other.fMaxRenderTargetSize; |
| 662 | fMaxTextureSize = other.fMaxTextureSize; |
| 663 | fMaxSampleCount = other.fMaxSampleCount; |
| 664 | |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 665 | memcpy(fConfigRenderSupport, other.fConfigRenderSupport, sizeof(fConfigRenderSupport)); |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 666 | memcpy(fConfigTextureSupport, other.fConfigTextureSupport, sizeof(fConfigTextureSupport)); |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 667 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 668 | return *this; |
| 669 | } |
| 670 | |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 671 | static SkString map_flags_to_string(uint32_t flags) { |
| 672 | SkString str; |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 673 | if (GrCaps::kNone_MapFlags == flags) { |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 674 | str = "none"; |
| 675 | } else { |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 676 | SkASSERT(GrCaps::kCanMap_MapFlag & flags); |
| 677 | SkDEBUGCODE(flags &= ~GrCaps::kCanMap_MapFlag); |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 678 | str = "can_map"; |
| 679 | |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 680 | if (GrCaps::kSubset_MapFlag & flags) { |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 681 | str.append(" partial"); |
| 682 | } else { |
| 683 | str.append(" full"); |
| 684 | } |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 685 | SkDEBUGCODE(flags &= ~GrCaps::kSubset_MapFlag); |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 686 | } |
| 687 | SkASSERT(0 == flags); // Make sure we handled all the flags. |
| 688 | return str; |
| 689 | } |
| 690 | |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 691 | SkString GrCaps::dump() const { |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 692 | SkString r; |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 693 | static const char* gNY[] = {"NO", "YES"}; |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 694 | r.appendf("MIP Map Support : %s\n", gNY[fMipMapSupport]); |
| 695 | r.appendf("NPOT Texture Tile Support : %s\n", gNY[fNPOTTextureTileSupport]); |
| 696 | r.appendf("Two Sided Stencil Support : %s\n", gNY[fTwoSidedStencilSupport]); |
| 697 | r.appendf("Stencil Wrap Ops Support : %s\n", gNY[fStencilWrapOpsSupport]); |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 698 | r.appendf("Discard Render Target Support : %s\n", gNY[fDiscardRenderTargetSupport]); |
| 699 | r.appendf("Reuse Scratch Textures : %s\n", gNY[fReuseScratchTextures]); |
| 700 | r.appendf("Gpu Tracing Support : %s\n", gNY[fGpuTracingSupport]); |
| 701 | r.appendf("Compressed Update Support : %s\n", gNY[fCompressedTexSubImageSupport]); |
bsalomon | d08ea5f | 2015-02-20 06:58:13 -0800 | [diff] [blame] | 702 | r.appendf("Oversized Stencil Support : %s\n", gNY[fOversizedStencilSupport]); |
cdalton | fd4167d | 2015-04-21 11:45:56 -0700 | [diff] [blame] | 703 | r.appendf("Texture Barrier Support : %s\n", gNY[fTextureBarrierSupport]); |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 704 | r.appendf("Draw Instead of Clear [workaround] : %s\n", gNY[fUseDrawInsteadOfClear]); |
| 705 | |
| 706 | r.appendf("Max Texture Size : %d\n", fMaxTextureSize); |
| 707 | r.appendf("Max Render Target Size : %d\n", fMaxRenderTargetSize); |
| 708 | r.appendf("Max Sample Count : %d\n", fMaxSampleCount); |
| 709 | |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 710 | static const char* kBlendEquationSupportNames[] = { |
| 711 | "Basic", |
| 712 | "Advanced", |
| 713 | "Advanced Coherent", |
| 714 | }; |
| 715 | GR_STATIC_ASSERT(0 == kBasic_BlendEquationSupport); |
| 716 | GR_STATIC_ASSERT(1 == kAdvanced_BlendEquationSupport); |
| 717 | GR_STATIC_ASSERT(2 == kAdvancedCoherent_BlendEquationSupport); |
| 718 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kBlendEquationSupportNames) == kLast_BlendEquationSupport + 1); |
| 719 | |
| 720 | r.appendf("Blend Equation Support : %s\n", |
| 721 | kBlendEquationSupportNames[fBlendEquationSupport]); |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 722 | r.appendf("Map Buffer Support : %s\n", |
| 723 | map_flags_to_string(fMapBufferFlags).c_str()); |
commit-bot@chromium.org | 160b478 | 2014-05-05 12:32:37 +0000 | [diff] [blame] | 724 | |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 725 | static const char* kConfigNames[] = { |
| 726 | "Unknown", // kUnknown_GrPixelConfig |
| 727 | "Alpha8", // kAlpha_8_GrPixelConfig, |
| 728 | "Index8", // kIndex_8_GrPixelConfig, |
| 729 | "RGB565", // kRGB_565_GrPixelConfig, |
| 730 | "RGBA444", // kRGBA_4444_GrPixelConfig, |
| 731 | "RGBA8888", // kRGBA_8888_GrPixelConfig, |
| 732 | "BGRA8888", // kBGRA_8888_GrPixelConfig, |
jvanverth | fa1e8a7 | 2014-12-22 08:31:49 -0800 | [diff] [blame] | 733 | "SRGBA8888",// kSRGBA_8888_GrPixelConfig, |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 734 | "ETC1", // kETC1_GrPixelConfig, |
| 735 | "LATC", // kLATC_GrPixelConfig, |
krajcevski | 238b456 | 2014-06-30 09:09:22 -0700 | [diff] [blame] | 736 | "R11EAC", // kR11_EAC_GrPixelConfig, |
krajcevski | 7ef2162 | 2014-07-16 15:21:13 -0700 | [diff] [blame] | 737 | "ASTC12x12",// kASTC_12x12_GrPixelConfig, |
jvanverth | 28f9c60 | 2014-12-05 13:06:35 -0800 | [diff] [blame] | 738 | "RGBAFloat",// kRGBA_float_GrPixelConfig |
| 739 | "AlphaHalf",// kAlpha_half_GrPixelConfig |
jvanverth | fb5df43 | 2015-05-21 08:12:27 -0700 | [diff] [blame] | 740 | "RGBAHalf", // kRGBA_half_GrPixelConfig |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 741 | }; |
krajcevski | 7ef2162 | 2014-07-16 15:21:13 -0700 | [diff] [blame] | 742 | GR_STATIC_ASSERT(0 == kUnknown_GrPixelConfig); |
| 743 | GR_STATIC_ASSERT(1 == kAlpha_8_GrPixelConfig); |
| 744 | GR_STATIC_ASSERT(2 == kIndex_8_GrPixelConfig); |
| 745 | GR_STATIC_ASSERT(3 == kRGB_565_GrPixelConfig); |
| 746 | GR_STATIC_ASSERT(4 == kRGBA_4444_GrPixelConfig); |
| 747 | GR_STATIC_ASSERT(5 == kRGBA_8888_GrPixelConfig); |
| 748 | GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig); |
jvanverth | fa1e8a7 | 2014-12-22 08:31:49 -0800 | [diff] [blame] | 749 | GR_STATIC_ASSERT(7 == kSRGBA_8888_GrPixelConfig); |
| 750 | GR_STATIC_ASSERT(8 == kETC1_GrPixelConfig); |
| 751 | GR_STATIC_ASSERT(9 == kLATC_GrPixelConfig); |
| 752 | GR_STATIC_ASSERT(10 == kR11_EAC_GrPixelConfig); |
| 753 | GR_STATIC_ASSERT(11 == kASTC_12x12_GrPixelConfig); |
| 754 | GR_STATIC_ASSERT(12 == kRGBA_float_GrPixelConfig); |
| 755 | GR_STATIC_ASSERT(13 == kAlpha_half_GrPixelConfig); |
jvanverth | fb5df43 | 2015-05-21 08:12:27 -0700 | [diff] [blame] | 756 | GR_STATIC_ASSERT(14 == kRGBA_half_GrPixelConfig); |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 757 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kConfigNames) == kGrPixelConfigCnt); |
| 758 | |
commit-bot@chromium.org | 9901727 | 2013-11-08 18:45:27 +0000 | [diff] [blame] | 759 | SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][0]); |
| 760 | SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][1]); |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 761 | |
| 762 | for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) { |
| 763 | r.appendf("%s is renderable: %s, with MSAA: %s\n", |
| 764 | kConfigNames[i], |
| 765 | gNY[fConfigRenderSupport[i][0]], |
| 766 | gNY[fConfigRenderSupport[i][1]]); |
commit-bot@chromium.org | 7388051 | 2013-10-14 15:33:45 +0000 | [diff] [blame] | 767 | } |
commit-bot@chromium.org | 42dc813 | 2014-05-27 19:26:59 +0000 | [diff] [blame] | 768 | |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 769 | SkASSERT(!fConfigTextureSupport[kUnknown_GrPixelConfig]); |
commit-bot@chromium.org | 42dc813 | 2014-05-27 19:26:59 +0000 | [diff] [blame] | 770 | |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 771 | for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) { |
| 772 | r.appendf("%s is uploadable to a texture: %s\n", |
| 773 | kConfigNames[i], |
| 774 | gNY[fConfigTextureSupport[i]]); |
commit-bot@chromium.org | 42dc813 | 2014-05-27 19:26:59 +0000 | [diff] [blame] | 775 | } |
| 776 | |
commit-bot@chromium.org | 8b656c6 | 2013-11-21 15:23:15 +0000 | [diff] [blame] | 777 | return r; |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 778 | } |
egdaniel | bc127a3 | 2014-09-19 12:07:43 -0700 | [diff] [blame] | 779 | |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 780 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 781 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 782 | bool GrClipTarget::setupClip(GrPipelineBuilder* pipelineBuilder, |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 783 | GrPipelineBuilder::AutoRestoreFragmentProcessors* arfp, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 784 | GrPipelineBuilder::AutoRestoreStencil* ars, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 785 | GrScissorState* scissorState, |
| 786 | const SkRect* devBounds) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 787 | return fClipMaskManager.setupClipping(pipelineBuilder, |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 788 | arfp, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 789 | ars, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 790 | scissorState, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 791 | devBounds); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 792 | } |