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