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