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" |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 12 | #include "gl/GrGLCaps.h" |
| 13 | #include "glsl/GrGLSLCaps.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 | |
joshualitt | 0cffb17 | 2015-09-02 08:42:16 -0700 | [diff] [blame] | 17 | #include "batches/GrAAConvexPathRenderer.h" |
| 18 | #include "batches/GrAADistanceFieldPathRenderer.h" |
| 19 | #include "batches/GrAAHairLinePathRenderer.h" |
| 20 | #include "batches/GrAALinearizingConvexPathRenderer.h" |
| 21 | #include "batches/GrDashLinePathRenderer.h" |
| 22 | #include "batches/GrDefaultPathRenderer.h" |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 23 | #include "batches/GrMSAAPathRenderer.h" |
| 24 | #include "batches/GrPLSPathRenderer.h" |
joshualitt | 0cffb17 | 2015-09-02 08:42:16 -0700 | [diff] [blame] | 25 | #include "batches/GrStencilAndCoverPathRenderer.h" |
| 26 | #include "batches/GrTessellatingPathRenderer.h" |
| 27 | |
robertphillips | 13391dd | 2015-10-30 05:15:11 -0700 | [diff] [blame] | 28 | GrPathRendererChain::GrPathRendererChain(GrContext* context) { |
| 29 | const GrCaps& caps = *context->caps(); |
| 30 | this->addPathRenderer(new GrDashLinePathRenderer)->unref(); |
| 31 | |
| 32 | if (GrPathRenderer* pr = GrStencilAndCoverPathRenderer::Create(context->resourceProvider(), |
| 33 | caps)) { |
| 34 | this->addPathRenderer(pr)->unref(); |
| 35 | } |
ethannicholas | 6536ae5 | 2016-05-02 12:16:49 -0700 | [diff] [blame] | 36 | if (caps.sampleShadingSupport()) { |
| 37 | this->addPathRenderer(new GrMSAAPathRenderer)->unref(); |
| 38 | } |
robertphillips | 13391dd | 2015-10-30 05:15:11 -0700 | [diff] [blame] | 39 | this->addPathRenderer(new GrTessellatingPathRenderer)->unref(); |
| 40 | this->addPathRenderer(new GrAAHairLinePathRenderer)->unref(); |
| 41 | this->addPathRenderer(new GrAAConvexPathRenderer)->unref(); |
| 42 | this->addPathRenderer(new GrAALinearizingConvexPathRenderer)->unref(); |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 43 | if (caps.shaderCaps()->plsPathRenderingSupport()) { |
| 44 | this->addPathRenderer(new GrPLSPathRenderer)->unref(); |
| 45 | } |
robertphillips | 13391dd | 2015-10-30 05:15:11 -0700 | [diff] [blame] | 46 | this->addPathRenderer(new GrAADistanceFieldPathRenderer)->unref(); |
| 47 | this->addPathRenderer(new GrDefaultPathRenderer(caps.twoSidedStencilSupport(), |
| 48 | caps.stencilWrapOpsSupport()))->unref(); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 49 | } |
bsalomon@google.com | b27a8d5 | 2012-03-02 15:08:16 +0000 | [diff] [blame] | 50 | |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 51 | GrPathRendererChain::~GrPathRendererChain() { |
| 52 | for (int i = 0; i < fChain.count(); ++i) { |
| 53 | fChain[i]->unref(); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | GrPathRenderer* GrPathRendererChain::addPathRenderer(GrPathRenderer* pr) { |
| 58 | fChain.push_back() = pr; |
| 59 | pr->ref(); |
| 60 | return pr; |
| 61 | } |
| 62 | |
bsalomon | d6f25bf | 2016-05-05 09:26:21 -0700 | [diff] [blame] | 63 | GrPathRenderer* GrPathRendererChain::getPathRenderer( |
| 64 | const GrPathRenderer::CanDrawPathArgs& args, |
| 65 | DrawType drawType, |
| 66 | GrPathRenderer::StencilSupport* stencilSupport) { |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 67 | GR_STATIC_ASSERT(GrPathRenderer::kNoSupport_StencilSupport < |
| 68 | GrPathRenderer::kStencilOnly_StencilSupport); |
| 69 | GR_STATIC_ASSERT(GrPathRenderer::kStencilOnly_StencilSupport < |
| 70 | GrPathRenderer::kNoRestriction_StencilSupport); |
| 71 | GrPathRenderer::StencilSupport minStencilSupport; |
| 72 | if (kStencilOnly_DrawType == drawType) { |
| 73 | minStencilSupport = GrPathRenderer::kStencilOnly_StencilSupport; |
| 74 | } else if (kStencilAndColor_DrawType == drawType || |
| 75 | kStencilAndColorAntiAlias_DrawType == drawType) { |
| 76 | minStencilSupport = GrPathRenderer::kNoRestriction_StencilSupport; |
| 77 | } else { |
| 78 | minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport; |
| 79 | } |
bsalomon | d6f25bf | 2016-05-05 09:26:21 -0700 | [diff] [blame] | 80 | if (minStencilSupport != GrPathRenderer::kNoSupport_StencilSupport) { |
| 81 | // We don't support (and shouldn't need) stenciling of non-fill paths. |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 82 | if (!args.fShape->style().isSimpleFill()) { |
bsalomon | d6f25bf | 2016-05-05 09:26:21 -0700 | [diff] [blame] | 83 | return nullptr; |
| 84 | } |
| 85 | } |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 86 | |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 87 | for (int i = 0; i < fChain.count(); ++i) { |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 88 | if (fChain[i]->canDrawPath(args)) { |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 89 | if (GrPathRenderer::kNoSupport_StencilSupport != minStencilSupport) { |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 90 | GrPathRenderer::StencilSupport support = fChain[i]->getStencilSupport(*args.fShape); |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 91 | if (support < minStencilSupport) { |
| 92 | continue; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 93 | } else if (stencilSupport) { |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 94 | *stencilSupport = support; |
| 95 | } |
| 96 | } |
bsalomon@google.com | 289533a | 2011-10-27 12:34:25 +0000 | [diff] [blame] | 97 | return fChain[i]; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 98 | } |
| 99 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 100 | return nullptr; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 101 | } |