blob: 7a064e8c9c8039e975e8ede2489430730cb9ab3a [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
35GrPathRenderer* GrPathRendererChain::getPathRenderer(const GrDrawTarget* target,
36 const GrPath& path,
37 GrPathFill fill) {
38 if (!fInit) {
39 this->init();
40 }
41 bool preferAA = target->isAntialiasState() &&
42 !target->getRenderTarget()->isMultisampled();
43 GrPathRenderer* nonAAPR = NULL;
44 for (int i = 0; i < fChain.count(); ++i) {
bsalomon@google.comaeb21602011-08-30 18:13:44 +000045 if (fChain[i]->canDrawPath(target, path, fill)) {
bsalomon@google.com30085192011-08-19 15:42:31 +000046 if (!preferAA || fChain[i]->supportsAA(target, path, fill)) {
47 return fChain[i];
48 } else {
49 nonAAPR = fChain[i];
50 }
51 }
52 }
53 return nonAAPR;
54}
55
56void GrPathRendererChain::init() {
57 GrAssert(!fInit);
58 GrGpu* gpu = fOwner->getGpu();
bsalomon@google.com18c9c192011-09-22 21:01:31 +000059 bool twoSided = gpu->getCaps().fTwoSidedStencilSupport;
60 bool wrapOp = gpu->getCaps().fStencilWrapOpsSupport;
bsalomon@google.com30085192011-08-19 15:42:31 +000061 GrPathRenderer::AddPathRenderers(fOwner, fFlags, this);
bsalomon@google.coma8a6a322011-09-23 14:19:58 +000062 this->addPathRenderer(new GrDefaultPathRenderer(twoSided, wrapOp))->unref();
bsalomon@google.com30085192011-08-19 15:42:31 +000063 fInit = true;
64}