blob: ad7f3db3c3899ba68b15ca92c3ca00b4393eea28 [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}
bsalomon@google.comb27a8d52012-03-02 15:08:16 +000021
bsalomon@google.com30085192011-08-19 15:42:31 +000022GrPathRendererChain::~GrPathRendererChain() {
23 for (int i = 0; i < fChain.count(); ++i) {
24 fChain[i]->unref();
25 }
26}
27
28GrPathRenderer* GrPathRendererChain::addPathRenderer(GrPathRenderer* pr) {
29 fChain.push_back() = pr;
30 pr->ref();
31 return pr;
32}
33
bsalomon@google.com289533a2011-10-27 12:34:25 +000034GrPathRenderer* GrPathRendererChain::getPathRenderer(
35 const GrDrawTarget::Caps& targetCaps,
36 const GrPath& path,
37 GrPathFill fill,
38 bool antiAlias) {
bsalomon@google.com30085192011-08-19 15:42:31 +000039 if (!fInit) {
40 this->init();
41 }
bsalomon@google.com30085192011-08-19 15:42:31 +000042 for (int i = 0; i < fChain.count(); ++i) {
bsalomon@google.com289533a2011-10-27 12:34:25 +000043 if (fChain[i]->canDrawPath(targetCaps, path, fill, antiAlias)) {
44 return fChain[i];
bsalomon@google.com30085192011-08-19 15:42:31 +000045 }
46 }
bsalomon@google.com289533a2011-10-27 12:34:25 +000047 return NULL;
bsalomon@google.com30085192011-08-19 15:42:31 +000048}
49
50void GrPathRendererChain::init() {
51 GrAssert(!fInit);
52 GrGpu* gpu = fOwner->getGpu();
bsalomon@google.com18c9c192011-09-22 21:01:31 +000053 bool twoSided = gpu->getCaps().fTwoSidedStencilSupport;
54 bool wrapOp = gpu->getCaps().fStencilWrapOpsSupport;
bsalomon@google.com30085192011-08-19 15:42:31 +000055 GrPathRenderer::AddPathRenderers(fOwner, fFlags, this);
bsalomon@google.coma8a6a322011-09-23 14:19:58 +000056 this->addPathRenderer(new GrDefaultPathRenderer(twoSided, wrapOp))->unref();
bsalomon@google.com30085192011-08-19 15:42:31 +000057 fInit = true;
58}