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 | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 18 | GrPathRendererChain::GrPathRendererChain(GrContext* context, UsageFlags flags) |
| 19 | : fInit(false) |
tomhudson@google.com | fa51041 | 2011-08-26 13:19:39 +0000 | [diff] [blame] | 20 | , fOwner(context) |
bsalomon@google.com | 9266901 | 2011-09-27 19:10:05 +0000 | [diff] [blame] | 21 | , fFlags(flags) { |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 22 | } |
bsalomon@google.com | b27a8d5 | 2012-03-02 15:08:16 +0000 | [diff] [blame] | 23 | |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 24 | GrPathRendererChain::~GrPathRendererChain() { |
| 25 | for (int i = 0; i < fChain.count(); ++i) { |
| 26 | fChain[i]->unref(); |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | GrPathRenderer* GrPathRendererChain::addPathRenderer(GrPathRenderer* pr) { |
| 31 | fChain.push_back() = pr; |
| 32 | pr->ref(); |
| 33 | return pr; |
| 34 | } |
| 35 | |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 36 | GrPathRenderer* GrPathRendererChain::getPathRenderer(const SkPath& path, |
| 37 | GrPathFill fill, |
| 38 | const GrDrawTarget* target, |
| 39 | bool antiAlias) { |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 40 | if (!fInit) { |
| 41 | this->init(); |
| 42 | } |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 43 | for (int i = 0; i < fChain.count(); ++i) { |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 44 | if (fChain[i]->canDrawPath(path, fill, target, antiAlias)) { |
bsalomon@google.com | 289533a | 2011-10-27 12:34:25 +0000 | [diff] [blame] | 45 | return fChain[i]; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 46 | } |
| 47 | } |
bsalomon@google.com | 289533a | 2011-10-27 12:34:25 +0000 | [diff] [blame] | 48 | return NULL; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | void GrPathRendererChain::init() { |
| 52 | GrAssert(!fInit); |
| 53 | GrGpu* gpu = fOwner->getGpu(); |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 54 | bool twoSided = gpu->getCaps().fTwoSidedStencilSupport; |
| 55 | bool wrapOp = gpu->getCaps().fStencilWrapOpsSupport; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 56 | GrPathRenderer::AddPathRenderers(fOwner, fFlags, this); |
bsalomon@google.com | a8a6a32 | 2011-09-23 14:19:58 +0000 | [diff] [blame] | 57 | this->addPathRenderer(new GrDefaultPathRenderer(twoSided, wrapOp))->unref(); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 58 | fInit = true; |
| 59 | } |