bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2011 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. |
| 7 | */ |
| 8 | |
| 9 | |
| 10 | #include "GrPathRendererChain.h" |
| 11 | |
bsalomon | eb1cb5c | 2015-05-22 08:01:09 -0700 | [diff] [blame] | 12 | #include "GrCaps.h" |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 13 | #include "GrContext.h" |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 14 | #include "GrGpu.h" |
| 15 | |
joshualitt | 0cffb17 | 2015-09-02 08:42:16 -0700 | [diff] [blame] | 16 | #include "batches/GrAAConvexPathRenderer.h" |
| 17 | #include "batches/GrAADistanceFieldPathRenderer.h" |
| 18 | #include "batches/GrAAHairLinePathRenderer.h" |
| 19 | #include "batches/GrAALinearizingConvexPathRenderer.h" |
| 20 | #include "batches/GrDashLinePathRenderer.h" |
| 21 | #include "batches/GrDefaultPathRenderer.h" |
| 22 | #include "batches/GrStencilAndCoverPathRenderer.h" |
| 23 | #include "batches/GrTessellatingPathRenderer.h" |
| 24 | |
robertphillips | 13391dd | 2015-10-30 05:15:11 -0700 | [diff] [blame] | 25 | GrPathRendererChain::GrPathRendererChain(GrContext* context) { |
| 26 | const GrCaps& caps = *context->caps(); |
| 27 | this->addPathRenderer(new GrDashLinePathRenderer)->unref(); |
| 28 | |
| 29 | if (GrPathRenderer* pr = GrStencilAndCoverPathRenderer::Create(context->resourceProvider(), |
| 30 | caps)) { |
| 31 | this->addPathRenderer(pr)->unref(); |
| 32 | } |
| 33 | this->addPathRenderer(new GrTessellatingPathRenderer)->unref(); |
| 34 | this->addPathRenderer(new GrAAHairLinePathRenderer)->unref(); |
| 35 | this->addPathRenderer(new GrAAConvexPathRenderer)->unref(); |
| 36 | this->addPathRenderer(new GrAALinearizingConvexPathRenderer)->unref(); |
| 37 | this->addPathRenderer(new GrAADistanceFieldPathRenderer)->unref(); |
| 38 | this->addPathRenderer(new GrDefaultPathRenderer(caps.twoSidedStencilSupport(), |
| 39 | caps.stencilWrapOpsSupport()))->unref(); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 40 | } |
bsalomon@google.com | b27a8d5 | 2012-03-02 15:08:16 +0000 | [diff] [blame] | 41 | |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 42 | GrPathRendererChain::~GrPathRendererChain() { |
| 43 | for (int i = 0; i < fChain.count(); ++i) { |
| 44 | fChain[i]->unref(); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | GrPathRenderer* GrPathRendererChain::addPathRenderer(GrPathRenderer* pr) { |
| 49 | fChain.push_back() = pr; |
| 50 | pr->ref(); |
| 51 | return pr; |
| 52 | } |
| 53 | |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 54 | GrPathRenderer* GrPathRendererChain::getPathRenderer(const GrPathRenderer::CanDrawPathArgs& args, |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 55 | DrawType drawType, |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 56 | GrPathRenderer::StencilSupport* stencilSupport) { |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 57 | GR_STATIC_ASSERT(GrPathRenderer::kNoSupport_StencilSupport < |
| 58 | GrPathRenderer::kStencilOnly_StencilSupport); |
| 59 | GR_STATIC_ASSERT(GrPathRenderer::kStencilOnly_StencilSupport < |
| 60 | GrPathRenderer::kNoRestriction_StencilSupport); |
| 61 | GrPathRenderer::StencilSupport minStencilSupport; |
| 62 | if (kStencilOnly_DrawType == drawType) { |
| 63 | minStencilSupport = GrPathRenderer::kStencilOnly_StencilSupport; |
| 64 | } else if (kStencilAndColor_DrawType == drawType || |
| 65 | kStencilAndColorAntiAlias_DrawType == drawType) { |
| 66 | minStencilSupport = GrPathRenderer::kNoRestriction_StencilSupport; |
| 67 | } else { |
| 68 | minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport; |
| 69 | } |
| 70 | |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 71 | for (int i = 0; i < fChain.count(); ++i) { |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 72 | if (fChain[i]->canDrawPath(args)) { |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 73 | if (GrPathRenderer::kNoSupport_StencilSupport != minStencilSupport) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 74 | GrPathRenderer::StencilSupport support = |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 75 | fChain[i]->getStencilSupport(*args.fPath, *args.fStroke); |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 76 | if (support < minStencilSupport) { |
| 77 | continue; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 78 | } else if (stencilSupport) { |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 79 | *stencilSupport = support; |
| 80 | } |
| 81 | } |
bsalomon@google.com | 289533a | 2011-10-27 12:34:25 +0000 | [diff] [blame] | 82 | return fChain[i]; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 83 | } |
| 84 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 85 | return nullptr; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 86 | } |