1 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) 18 , fOwner(context) 19 , fFlags(flags) { 20} 21 22GrPathRendererChain::~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 34GrPathRenderer* GrPathRendererChain::getPathRenderer(const SkPath& path, 35 GrPathFill fill, 36 const GrDrawTarget* target, 37 bool antiAlias) { 38 if (!fInit) { 39 this->init(); 40 } 41 for (int i = 0; i < fChain.count(); ++i) { 42 if (fChain[i]->canDrawPath(path, fill, target, antiAlias)) { 43 return fChain[i]; 44 } 45 } 46 return NULL; 47} 48 49void GrPathRendererChain::init() { 50 GrAssert(!fInit); 51 GrGpu* gpu = fOwner->getGpu(); 52 bool twoSided = gpu->getCaps().fTwoSidedStencilSupport; 53 bool wrapOp = gpu->getCaps().fStencilWrapOpsSupport; 54 GrPathRenderer::AddPathRenderers(fOwner, fFlags, this); 55 this->addPathRenderer(new GrDefaultPathRenderer(twoSided, wrapOp))->unref(); 56 fInit = true; 57} 58