bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | |
| 9 | #include "GrPathRendererChain.h" |
| 10 | |
bsalomon | eb1cb5c | 2015-05-22 08:01:09 -0700 | [diff] [blame] | 11 | #include "GrCaps.h" |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 12 | #include "GrShaderCaps.h" |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 13 | #include "gl/GrGLCaps.h" |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 14 | #include "GrContext.h" |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 15 | #include "GrGpu.h" |
| 16 | |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 17 | #include "ops/GrAAConvexPathRenderer.h" |
| 18 | #include "ops/GrAADistanceFieldPathRenderer.h" |
| 19 | #include "ops/GrAAHairLinePathRenderer.h" |
| 20 | #include "ops/GrAALinearizingConvexPathRenderer.h" |
| 21 | #include "ops/GrDashLinePathRenderer.h" |
| 22 | #include "ops/GrDefaultPathRenderer.h" |
| 23 | #include "ops/GrMSAAPathRenderer.h" |
| 24 | #include "ops/GrPLSPathRenderer.h" |
| 25 | #include "ops/GrStencilAndCoverPathRenderer.h" |
| 26 | #include "ops/GrTessellatingPathRenderer.h" |
joshualitt | 0cffb17 | 2015-09-02 08:42:16 -0700 | [diff] [blame] | 27 | |
bsalomon | 6b2552f | 2016-09-15 13:50:26 -0700 | [diff] [blame] | 28 | GrPathRendererChain::GrPathRendererChain(GrContext* context, const Options& options) { |
bsalomon | 39ef7fb | 2016-09-21 11:16:05 -0700 | [diff] [blame] | 29 | if (!options.fDisableAllPathRenderers) { |
| 30 | const GrCaps& caps = *context->caps(); |
| 31 | this->addPathRenderer(new GrDashLinePathRenderer)->unref(); |
robertphillips | 13391dd | 2015-10-30 05:15:11 -0700 | [diff] [blame] | 32 | |
bsalomon | 39ef7fb | 2016-09-21 11:16:05 -0700 | [diff] [blame] | 33 | if (GrPathRenderer* pr = GrStencilAndCoverPathRenderer::Create(context->resourceProvider(), |
| 34 | caps)) { |
| 35 | this->addPathRenderer(pr)->unref(); |
| 36 | } |
| 37 | #ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK |
Stephan White | 021f927 | 2017-01-03 21:06:16 +0000 | [diff] [blame^] | 38 | if (caps.sampleShadingSupport()) { |
| 39 | this->addPathRenderer(new GrMSAAPathRenderer)->unref(); |
| 40 | } |
bsalomon | 39ef7fb | 2016-09-21 11:16:05 -0700 | [diff] [blame] | 41 | #endif |
| 42 | this->addPathRenderer(new GrAAHairLinePathRenderer)->unref(); |
| 43 | this->addPathRenderer(new GrAAConvexPathRenderer)->unref(); |
| 44 | this->addPathRenderer(new GrAALinearizingConvexPathRenderer)->unref(); |
| 45 | if (caps.shaderCaps()->plsPathRenderingSupport()) { |
| 46 | this->addPathRenderer(new GrPLSPathRenderer)->unref(); |
| 47 | } |
Stephan White | 021f927 | 2017-01-03 21:06:16 +0000 | [diff] [blame^] | 48 | if (!options.fDisableDistanceFieldRenderer) { |
| 49 | this->addPathRenderer(new GrAADistanceFieldPathRenderer)->unref(); |
| 50 | } |
bsalomon | 39ef7fb | 2016-09-21 11:16:05 -0700 | [diff] [blame] | 51 | this->addPathRenderer(new GrTessellatingPathRenderer)->unref(); |
| 52 | this->addPathRenderer(new GrDefaultPathRenderer(caps.twoSidedStencilSupport(), |
| 53 | caps.stencilWrapOpsSupport()))->unref(); |
robertphillips | 13391dd | 2015-10-30 05:15:11 -0700 | [diff] [blame] | 54 | } |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 55 | } |
bsalomon@google.com | b27a8d5 | 2012-03-02 15:08:16 +0000 | [diff] [blame] | 56 | |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 57 | GrPathRendererChain::~GrPathRendererChain() { |
| 58 | for (int i = 0; i < fChain.count(); ++i) { |
| 59 | fChain[i]->unref(); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | GrPathRenderer* GrPathRendererChain::addPathRenderer(GrPathRenderer* pr) { |
| 64 | fChain.push_back() = pr; |
| 65 | pr->ref(); |
| 66 | return pr; |
| 67 | } |
| 68 | |
bsalomon | d6f25bf | 2016-05-05 09:26:21 -0700 | [diff] [blame] | 69 | GrPathRenderer* GrPathRendererChain::getPathRenderer( |
| 70 | const GrPathRenderer::CanDrawPathArgs& args, |
| 71 | DrawType drawType, |
| 72 | GrPathRenderer::StencilSupport* stencilSupport) { |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 73 | GR_STATIC_ASSERT(GrPathRenderer::kNoSupport_StencilSupport < |
| 74 | GrPathRenderer::kStencilOnly_StencilSupport); |
| 75 | GR_STATIC_ASSERT(GrPathRenderer::kStencilOnly_StencilSupport < |
| 76 | GrPathRenderer::kNoRestriction_StencilSupport); |
| 77 | GrPathRenderer::StencilSupport minStencilSupport; |
Brian Salomon | 82125e9 | 2016-12-10 09:35:48 -0500 | [diff] [blame] | 78 | if (DrawType::kStencil == drawType) { |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 79 | minStencilSupport = GrPathRenderer::kStencilOnly_StencilSupport; |
Brian Salomon | 82125e9 | 2016-12-10 09:35:48 -0500 | [diff] [blame] | 80 | } else if (DrawType::kStencilAndColor == drawType) { |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 81 | minStencilSupport = GrPathRenderer::kNoRestriction_StencilSupport; |
| 82 | } else { |
| 83 | minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport; |
| 84 | } |
bsalomon | d6f25bf | 2016-05-05 09:26:21 -0700 | [diff] [blame] | 85 | if (minStencilSupport != GrPathRenderer::kNoSupport_StencilSupport) { |
| 86 | // We don't support (and shouldn't need) stenciling of non-fill paths. |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 87 | if (!args.fShape->style().isSimpleFill()) { |
bsalomon | d6f25bf | 2016-05-05 09:26:21 -0700 | [diff] [blame] | 88 | return nullptr; |
| 89 | } |
| 90 | } |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 91 | |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 92 | for (int i = 0; i < fChain.count(); ++i) { |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 93 | if (fChain[i]->canDrawPath(args)) { |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 94 | if (GrPathRenderer::kNoSupport_StencilSupport != minStencilSupport) { |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 95 | GrPathRenderer::StencilSupport support = fChain[i]->getStencilSupport(*args.fShape); |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 96 | if (support < minStencilSupport) { |
| 97 | continue; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 98 | } else if (stencilSupport) { |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 99 | *stencilSupport = support; |
| 100 | } |
| 101 | } |
bsalomon@google.com | 289533a | 2011-10-27 12:34:25 +0000 | [diff] [blame] | 102 | return fChain[i]; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 103 | } |
| 104 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 105 | return nullptr; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 106 | } |