blob: 2814f999be6e05d34112304b80bb3581c3d17f28 [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
robertphillips@google.com4d73ac22012-06-13 18:54:08 +000016SK_DEFINE_INST_COUNT(GrPathRendererChain)
17
bsalomon@google.com30085192011-08-19 15:42:31 +000018GrPathRendererChain::GrPathRendererChain(GrContext* context, UsageFlags flags)
19 : fInit(false)
tomhudson@google.comfa510412011-08-26 13:19:39 +000020 , fOwner(context)
bsalomon@google.com92669012011-09-27 19:10:05 +000021 , fFlags(flags) {
bsalomon@google.com30085192011-08-19 15:42:31 +000022}
bsalomon@google.comb27a8d52012-03-02 15:08:16 +000023
bsalomon@google.com30085192011-08-19 15:42:31 +000024GrPathRendererChain::~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
bsalomon@google.comc2099d22012-03-02 21:26:50 +000036GrPathRenderer* GrPathRendererChain::getPathRenderer(const SkPath& path,
37 GrPathFill fill,
38 const GrDrawTarget* target,
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.comc2099d22012-03-02 21:26:50 +000044 if (fChain[i]->canDrawPath(path, fill, target, antiAlias)) {
bsalomon@google.com289533a2011-10-27 12:34:25 +000045 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.comf6601872012-08-28 21:11:35 +000054 bool twoSided = gpu->getCaps().twoSidedStencilSupport();
55 bool wrapOp = gpu->getCaps().stencilWrapOpsSupport();
bsalomon@google.com30085192011-08-19 15:42:31 +000056 GrPathRenderer::AddPathRenderers(fOwner, fFlags, this);
tomhudson@google.comc377baf2012-07-09 20:17:56 +000057 this->addPathRenderer(SkNEW_ARGS(GrDefaultPathRenderer,
58 (twoSided, wrapOp)))->unref();
bsalomon@google.com30085192011-08-19 15:42:31 +000059 fInit = true;
60}