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