blob: dc09d43c1e3ad6a813fcc6ad14ddca1806cce181 [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)
epoger@google.com17b78942011-08-26 14:40:38 +000019 , fFlags(flags)
bsalomon@google.com30085192011-08-19 15:42:31 +000020 , fChain(fStorage.get(), kPreAllocCount) {
21 fInit = false;
22}
23
24GrPathRendererChain::~GrPathRendererChain() {
25 for (int i = 0; i < fChain.count(); ++i) {
26 fChain[i]->unref();
27 }
28}
29
30GrPathRenderer* GrPathRendererChain::addPathRenderer(GrPathRenderer* pr) {
31 fChain.push_back() = pr;
32 pr->ref();
33 return pr;
34}
35
36GrPathRenderer* GrPathRendererChain::getPathRenderer(const GrDrawTarget* target,
37 const GrPath& path,
38 GrPathFill fill) {
39 if (!fInit) {
40 this->init();
41 }
42 bool preferAA = target->isAntialiasState() &&
43 !target->getRenderTarget()->isMultisampled();
44 GrPathRenderer* nonAAPR = NULL;
45 for (int i = 0; i < fChain.count(); ++i) {
bsalomon@google.comaeb21602011-08-30 18:13:44 +000046 if (fChain[i]->canDrawPath(target, path, fill)) {
bsalomon@google.com30085192011-08-19 15:42:31 +000047 if (!preferAA || fChain[i]->supportsAA(target, path, fill)) {
48 return fChain[i];
49 } else {
50 nonAAPR = fChain[i];
51 }
52 }
53 }
54 return nonAAPR;
55}
56
57void GrPathRendererChain::init() {
58 GrAssert(!fInit);
59 GrGpu* gpu = fOwner->getGpu();
60 this->addPathRenderer(
61 new GrDefaultPathRenderer(gpu->supportsTwoSidedStencil(),
62 gpu->supportsStencilWrapOps()))->unref();
63 GrPathRenderer::AddPathRenderers(fOwner, fFlags, this);
64 fInit = true;
65}