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 | |
| 12 | #include "GrContext.h" |
| 13 | #include "GrDefaultPathRenderer.h" |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 14 | #include "GrDrawTargetCaps.h" |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 15 | #include "GrGpu.h" |
| 16 | |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 17 | GrPathRendererChain::GrPathRendererChain(GrContext* context) |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 18 | : fInit(false) |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 19 | , fOwner(context) { |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 20 | } |
bsalomon@google.com | b27a8d5 | 2012-03-02 15:08:16 +0000 | [diff] [blame] | 21 | |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 22 | GrPathRendererChain::~GrPathRendererChain() { |
| 23 | for (int i = 0; i < fChain.count(); ++i) { |
| 24 | fChain[i]->unref(); |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | GrPathRenderer* GrPathRendererChain::addPathRenderer(GrPathRenderer* pr) { |
| 29 | fChain.push_back() = pr; |
| 30 | pr->ref(); |
| 31 | return pr; |
| 32 | } |
| 33 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 34 | GrPathRenderer* GrPathRendererChain::getPathRenderer(const GrDrawTarget* target, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 35 | const GrPipelineBuilder* pipelineBuilder, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 36 | const SkMatrix& viewMatrix, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 37 | const SkPath& path, |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 38 | const SkStrokeRec& stroke, |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 39 | DrawType drawType, |
| 40 | StencilSupport* stencilSupport) { |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 41 | if (!fInit) { |
| 42 | this->init(); |
| 43 | } |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 44 | bool antiAlias = (kColorAntiAlias_DrawType == drawType || |
| 45 | kStencilAndColorAntiAlias_DrawType == drawType); |
| 46 | |
| 47 | GR_STATIC_ASSERT(GrPathRenderer::kNoSupport_StencilSupport < |
| 48 | GrPathRenderer::kStencilOnly_StencilSupport); |
| 49 | GR_STATIC_ASSERT(GrPathRenderer::kStencilOnly_StencilSupport < |
| 50 | GrPathRenderer::kNoRestriction_StencilSupport); |
| 51 | GrPathRenderer::StencilSupport minStencilSupport; |
| 52 | if (kStencilOnly_DrawType == drawType) { |
| 53 | minStencilSupport = GrPathRenderer::kStencilOnly_StencilSupport; |
| 54 | } else if (kStencilAndColor_DrawType == drawType || |
| 55 | kStencilAndColorAntiAlias_DrawType == drawType) { |
| 56 | minStencilSupport = GrPathRenderer::kNoRestriction_StencilSupport; |
| 57 | } else { |
| 58 | minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport; |
| 59 | } |
| 60 | |
robertphillips@google.com | e79f320 | 2014-02-11 16:30:21 +0000 | [diff] [blame] | 61 | |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 62 | for (int i = 0; i < fChain.count(); ++i) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 63 | if (fChain[i]->canDrawPath(target, pipelineBuilder, viewMatrix, path, stroke, antiAlias)) { |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 64 | if (GrPathRenderer::kNoSupport_StencilSupport != minStencilSupport) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 65 | GrPathRenderer::StencilSupport support = |
| 66 | fChain[i]->getStencilSupport(target, pipelineBuilder, path, stroke); |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 67 | if (support < minStencilSupport) { |
| 68 | continue; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 69 | } else if (stencilSupport) { |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 70 | *stencilSupport = support; |
| 71 | } |
| 72 | } |
bsalomon@google.com | 289533a | 2011-10-27 12:34:25 +0000 | [diff] [blame] | 73 | return fChain[i]; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 74 | } |
| 75 | } |
bsalomon@google.com | 289533a | 2011-10-27 12:34:25 +0000 | [diff] [blame] | 76 | return NULL; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | void GrPathRendererChain::init() { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 80 | SkASSERT(!fInit); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 81 | GrGpu* gpu = fOwner->getGpu(); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 82 | bool twoSided = gpu->caps()->twoSidedStencilSupport(); |
| 83 | bool wrapOp = gpu->caps()->stencilWrapOpsSupport(); |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 84 | GrPathRenderer::AddPathRenderers(fOwner, this); |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 85 | this->addPathRenderer(SkNEW_ARGS(GrDefaultPathRenderer, |
| 86 | (twoSided, wrapOp)))->unref(); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 87 | fInit = true; |
| 88 | } |