blob: 00f0b81d8563ff354eaad7fab026a3a2ded0fc66 [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.comc2099d22012-03-02 21:26:50 +000034GrPathRenderer* GrPathRendererChain::getPathRenderer(const SkPath& path,
35 GrPathFill fill,
36 const GrDrawTarget* target,
37 bool antiAlias) {
bsalomon@google.com30085192011-08-19 15:42:31 +000038 if (!fInit) {
39 this->init();
40 }
bsalomon@google.com30085192011-08-19 15:42:31 +000041 for (int i = 0; i < fChain.count(); ++i) {
bsalomon@google.comc2099d22012-03-02 21:26:50 +000042 if (fChain[i]->canDrawPath(path, fill, target, antiAlias)) {
bsalomon@google.com289533a2011-10-27 12:34:25 +000043 return fChain[i];
bsalomon@google.com30085192011-08-19 15:42:31 +000044 }
45 }
bsalomon@google.com289533a2011-10-27 12:34:25 +000046 return NULL;
bsalomon@google.com30085192011-08-19 15:42:31 +000047}
48
49void GrPathRendererChain::init() {
50 GrAssert(!fInit);
51 GrGpu* gpu = fOwner->getGpu();
bsalomon@google.com18c9c192011-09-22 21:01:31 +000052 bool twoSided = gpu->getCaps().fTwoSidedStencilSupport;
53 bool wrapOp = gpu->getCaps().fStencilWrapOpsSupport;
bsalomon@google.com30085192011-08-19 15:42:31 +000054 GrPathRenderer::AddPathRenderers(fOwner, fFlags, this);
bsalomon@google.coma8a6a322011-09-23 14:19:58 +000055 this->addPathRenderer(new GrDefaultPathRenderer(twoSided, wrapOp))->unref();
bsalomon@google.com30085192011-08-19 15:42:31 +000056 fInit = true;
57}