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" |
| 14 | #include "GrGpu.h" |
| 15 | |
robertphillips@google.com | 4d73ac2 | 2012-06-13 18:54:08 +0000 | [diff] [blame] | 16 | SK_DEFINE_INST_COUNT(GrPathRendererChain) |
| 17 | |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 18 | GrPathRendererChain::GrPathRendererChain(GrContext* context) |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 19 | : fInit(false) |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 20 | , fOwner(context) { |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 21 | } |
bsalomon@google.com | b27a8d5 | 2012-03-02 15:08:16 +0000 | [diff] [blame] | 22 | |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 23 | GrPathRendererChain::~GrPathRendererChain() { |
| 24 | for (int i = 0; i < fChain.count(); ++i) { |
| 25 | fChain[i]->unref(); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | GrPathRenderer* GrPathRendererChain::addPathRenderer(GrPathRenderer* pr) { |
| 30 | fChain.push_back() = pr; |
| 31 | pr->ref(); |
| 32 | return pr; |
| 33 | } |
| 34 | |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 35 | GrPathRenderer* GrPathRendererChain::getPathRenderer(const SkPath& path, |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 36 | const SkStrokeRec& stroke, |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 37 | const GrDrawTarget* target, |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 38 | DrawType drawType, |
| 39 | StencilSupport* stencilSupport) { |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 40 | if (!fInit) { |
| 41 | this->init(); |
| 42 | } |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 43 | bool antiAlias = (kColorAntiAlias_DrawType == drawType || |
| 44 | kStencilAndColorAntiAlias_DrawType == drawType); |
| 45 | |
| 46 | GR_STATIC_ASSERT(GrPathRenderer::kNoSupport_StencilSupport < |
| 47 | GrPathRenderer::kStencilOnly_StencilSupport); |
| 48 | GR_STATIC_ASSERT(GrPathRenderer::kStencilOnly_StencilSupport < |
| 49 | GrPathRenderer::kNoRestriction_StencilSupport); |
| 50 | GrPathRenderer::StencilSupport minStencilSupport; |
| 51 | if (kStencilOnly_DrawType == drawType) { |
| 52 | minStencilSupport = GrPathRenderer::kStencilOnly_StencilSupport; |
| 53 | } else if (kStencilAndColor_DrawType == drawType || |
| 54 | kStencilAndColorAntiAlias_DrawType == drawType) { |
| 55 | minStencilSupport = GrPathRenderer::kNoRestriction_StencilSupport; |
| 56 | } else { |
| 57 | minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport; |
| 58 | } |
| 59 | |
| 60 | |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 61 | for (int i = 0; i < fChain.count(); ++i) { |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 62 | if (fChain[i]->canDrawPath(path, stroke, target, antiAlias)) { |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 63 | if (GrPathRenderer::kNoSupport_StencilSupport != minStencilSupport) { |
| 64 | GrPathRenderer::StencilSupport support = fChain[i]->getStencilSupport(path, |
| 65 | stroke, |
| 66 | target); |
| 67 | if (support < minStencilSupport) { |
| 68 | continue; |
| 69 | } else if (NULL != stencilSupport) { |
| 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() { |
| 80 | GrAssert(!fInit); |
| 81 | GrGpu* gpu = fOwner->getGpu(); |
bsalomon@google.com | f660187 | 2012-08-28 21:11:35 +0000 | [diff] [blame] | 82 | bool twoSided = gpu->getCaps().twoSidedStencilSupport(); |
| 83 | bool wrapOp = gpu->getCaps().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 | } |