blob: a45437bfb95e857c194579cafe506df280c55f24 [file] [log] [blame]
bsalomon@google.com30085192011-08-19 15:42:31 +00001
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
16GrPathRendererChain::GrPathRendererChain(GrContext* context, UsageFlags flags)
17 : fInit(false)
tomhudson@google.comfa510412011-08-26 13:19:39 +000018 , fOwner(context)
bsalomon@google.com92669012011-09-27 19:10:05 +000019 , fFlags(flags) {
bsalomon@google.com30085192011-08-19 15:42:31 +000020 fInit = false;
21}
22
23GrPathRendererChain::~GrPathRendererChain() {
24 for (int i = 0; i < fChain.count(); ++i) {
25 fChain[i]->unref();
26 }
27}
28
29GrPathRenderer* GrPathRendererChain::addPathRenderer(GrPathRenderer* pr) {
30 fChain.push_back() = pr;
31 pr->ref();
32 return pr;
33}
34
bsalomon@google.com289533a2011-10-27 12:34:25 +000035GrPathRenderer* GrPathRendererChain::getPathRenderer(
36 const GrDrawTarget::Caps& targetCaps,
37 const GrPath& path,
38 GrPathFill fill,
39 bool antiAlias) {
bsalomon@google.com30085192011-08-19 15:42:31 +000040 if (!fInit) {
41 this->init();
42 }
bsalomon@google.com30085192011-08-19 15:42:31 +000043 for (int i = 0; i < fChain.count(); ++i) {
bsalomon@google.com289533a2011-10-27 12:34:25 +000044 if (fChain[i]->canDrawPath(targetCaps, path, fill, antiAlias)) {
45 return fChain[i];
bsalomon@google.com30085192011-08-19 15:42:31 +000046 }
47 }
bsalomon@google.com289533a2011-10-27 12:34:25 +000048 return NULL;
bsalomon@google.com30085192011-08-19 15:42:31 +000049}
50
51void GrPathRendererChain::init() {
52 GrAssert(!fInit);
53 GrGpu* gpu = fOwner->getGpu();
bsalomon@google.com18c9c192011-09-22 21:01:31 +000054 bool twoSided = gpu->getCaps().fTwoSidedStencilSupport;
55 bool wrapOp = gpu->getCaps().fStencilWrapOpsSupport;
bsalomon@google.com30085192011-08-19 15:42:31 +000056 GrPathRenderer::AddPathRenderers(fOwner, fFlags, this);
bsalomon@google.coma8a6a322011-09-23 14:19:58 +000057 this->addPathRenderer(new GrDefaultPathRenderer(twoSided, wrapOp))->unref();
bsalomon@google.com30085192011-08-19 15:42:31 +000058 fInit = true;
59}