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 | |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 25 | GrPathRendererChain::GrPathRendererChain(GrContext* context) |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 26 | : fInit(false) |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 27 | , fOwner(context) { |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 28 | } |
bsalomon@google.com | b27a8d5 | 2012-03-02 15:08:16 +0000 | [diff] [blame] | 29 | |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 30 | GrPathRendererChain::~GrPathRendererChain() { |
| 31 | for (int i = 0; i < fChain.count(); ++i) { |
| 32 | fChain[i]->unref(); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | GrPathRenderer* GrPathRendererChain::addPathRenderer(GrPathRenderer* pr) { |
| 37 | fChain.push_back() = pr; |
| 38 | pr->ref(); |
| 39 | return pr; |
| 40 | } |
| 41 | |
robertphillips | b83bec5 | 2015-10-23 09:38:03 -0700 | [diff] [blame] | 42 | GrPathRenderer* GrPathRendererChain::getPathRenderer(const GrShaderCaps* shaderCaps, |
robertphillips | 24cdec1 | 2015-10-26 14:12:25 -0700 | [diff] [blame^] | 43 | const GrPipelineBuilder* pipelineBuilder, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 44 | const SkMatrix& viewMatrix, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 45 | const SkPath& path, |
kkinnunen | 1899651 | 2015-04-26 23:18:49 -0700 | [diff] [blame] | 46 | const GrStrokeInfo& stroke, |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 47 | DrawType drawType, |
| 48 | StencilSupport* stencilSupport) { |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 49 | if (!fInit) { |
| 50 | this->init(); |
| 51 | } |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 52 | bool antiAlias = (kColorAntiAlias_DrawType == drawType || |
| 53 | kStencilAndColorAntiAlias_DrawType == drawType); |
| 54 | |
| 55 | GR_STATIC_ASSERT(GrPathRenderer::kNoSupport_StencilSupport < |
| 56 | GrPathRenderer::kStencilOnly_StencilSupport); |
| 57 | GR_STATIC_ASSERT(GrPathRenderer::kStencilOnly_StencilSupport < |
| 58 | GrPathRenderer::kNoRestriction_StencilSupport); |
| 59 | GrPathRenderer::StencilSupport minStencilSupport; |
| 60 | if (kStencilOnly_DrawType == drawType) { |
| 61 | minStencilSupport = GrPathRenderer::kStencilOnly_StencilSupport; |
| 62 | } else if (kStencilAndColor_DrawType == drawType || |
| 63 | kStencilAndColorAntiAlias_DrawType == drawType) { |
| 64 | minStencilSupport = GrPathRenderer::kNoRestriction_StencilSupport; |
| 65 | } else { |
| 66 | minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport; |
| 67 | } |
| 68 | |
robertphillips@google.com | e79f320 | 2014-02-11 16:30:21 +0000 | [diff] [blame] | 69 | |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 70 | for (int i = 0; i < fChain.count(); ++i) { |
robertphillips | 24cdec1 | 2015-10-26 14:12:25 -0700 | [diff] [blame^] | 71 | GrPathRenderer::CanDrawPathArgs args; |
| 72 | args.fShaderCaps = shaderCaps; |
| 73 | args.fPipelineBuilder = pipelineBuilder; |
| 74 | args.fViewMatrix = &viewMatrix; |
| 75 | args.fPath = &path; |
| 76 | args.fStroke = &stroke; |
| 77 | args.fAntiAlias = antiAlias; |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 78 | if (fChain[i]->canDrawPath(args)) { |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 79 | if (GrPathRenderer::kNoSupport_StencilSupport != minStencilSupport) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 80 | GrPathRenderer::StencilSupport support = |
robertphillips | e7d4b2f | 2015-08-13 07:57:10 -0700 | [diff] [blame] | 81 | fChain[i]->getStencilSupport(path, stroke); |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 82 | if (support < minStencilSupport) { |
| 83 | continue; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 84 | } else if (stencilSupport) { |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 85 | *stencilSupport = support; |
| 86 | } |
| 87 | } |
bsalomon@google.com | 289533a | 2011-10-27 12:34:25 +0000 | [diff] [blame] | 88 | return fChain[i]; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 89 | } |
| 90 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 91 | return nullptr; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | void GrPathRendererChain::init() { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 95 | SkASSERT(!fInit); |
joshualitt | 0cffb17 | 2015-09-02 08:42:16 -0700 | [diff] [blame] | 96 | const GrCaps& caps = *fOwner->caps(); |
| 97 | this->addPathRenderer(new GrDashLinePathRenderer)->unref(); |
| 98 | |
| 99 | if (GrPathRenderer* pr = GrStencilAndCoverPathRenderer::Create(fOwner->resourceProvider(), |
| 100 | caps)) { |
| 101 | this->addPathRenderer(pr)->unref(); |
| 102 | } |
| 103 | this->addPathRenderer(new GrTessellatingPathRenderer)->unref(); |
| 104 | this->addPathRenderer(new GrAAHairLinePathRenderer)->unref(); |
| 105 | this->addPathRenderer(new GrAAConvexPathRenderer)->unref(); |
| 106 | this->addPathRenderer(new GrAALinearizingConvexPathRenderer)->unref(); |
| 107 | this->addPathRenderer(new GrAADistanceFieldPathRenderer)->unref(); |
| 108 | this->addPathRenderer(new GrDefaultPathRenderer(caps.twoSidedStencilSupport(), |
| 109 | caps.stencilWrapOpsSupport()))->unref(); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 110 | fInit = true; |
| 111 | } |