michael@0: michael@0: /* michael@0: * Copyright 2011 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #include "GrPathRendererChain.h" michael@0: michael@0: #include "GrContext.h" michael@0: #include "GrDefaultPathRenderer.h" michael@0: #include "GrDrawTargetCaps.h" michael@0: #include "GrGpu.h" michael@0: michael@0: GrPathRendererChain::GrPathRendererChain(GrContext* context) michael@0: : fInit(false) michael@0: , fOwner(context) { michael@0: } michael@0: michael@0: GrPathRendererChain::~GrPathRendererChain() { michael@0: for (int i = 0; i < fChain.count(); ++i) { michael@0: fChain[i]->unref(); michael@0: } michael@0: } michael@0: michael@0: GrPathRenderer* GrPathRendererChain::addPathRenderer(GrPathRenderer* pr) { michael@0: fChain.push_back() = pr; michael@0: pr->ref(); michael@0: return pr; michael@0: } michael@0: michael@0: GrPathRenderer* GrPathRendererChain::getPathRenderer(const SkPath& path, michael@0: const SkStrokeRec& stroke, michael@0: const GrDrawTarget* target, michael@0: DrawType drawType, michael@0: StencilSupport* stencilSupport) { michael@0: if (!fInit) { michael@0: this->init(); michael@0: } michael@0: bool antiAlias = (kColorAntiAlias_DrawType == drawType || michael@0: kStencilAndColorAntiAlias_DrawType == drawType); michael@0: michael@0: GR_STATIC_ASSERT(GrPathRenderer::kNoSupport_StencilSupport < michael@0: GrPathRenderer::kStencilOnly_StencilSupport); michael@0: GR_STATIC_ASSERT(GrPathRenderer::kStencilOnly_StencilSupport < michael@0: GrPathRenderer::kNoRestriction_StencilSupport); michael@0: GrPathRenderer::StencilSupport minStencilSupport; michael@0: if (kStencilOnly_DrawType == drawType) { michael@0: minStencilSupport = GrPathRenderer::kStencilOnly_StencilSupport; michael@0: } else if (kStencilAndColor_DrawType == drawType || michael@0: kStencilAndColorAntiAlias_DrawType == drawType) { michael@0: minStencilSupport = GrPathRenderer::kNoRestriction_StencilSupport; michael@0: } else { michael@0: minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport; michael@0: } michael@0: michael@0: michael@0: for (int i = 0; i < fChain.count(); ++i) { michael@0: if (fChain[i]->canDrawPath(path, stroke, target, antiAlias)) { michael@0: if (GrPathRenderer::kNoSupport_StencilSupport != minStencilSupport) { michael@0: GrPathRenderer::StencilSupport support = fChain[i]->getStencilSupport(path, michael@0: stroke, michael@0: target); michael@0: if (support < minStencilSupport) { michael@0: continue; michael@0: } else if (NULL != stencilSupport) { michael@0: *stencilSupport = support; michael@0: } michael@0: } michael@0: return fChain[i]; michael@0: } michael@0: } michael@0: return NULL; michael@0: } michael@0: michael@0: void GrPathRendererChain::init() { michael@0: SkASSERT(!fInit); michael@0: GrGpu* gpu = fOwner->getGpu(); michael@0: bool twoSided = gpu->caps()->twoSidedStencilSupport(); michael@0: bool wrapOp = gpu->caps()->stencilWrapOpsSupport(); michael@0: GrPathRenderer::AddPathRenderers(fOwner, this); michael@0: this->addPathRenderer(SkNEW_ARGS(GrDefaultPathRenderer, michael@0: (twoSided, wrapOp)))->unref(); michael@0: fInit = true; michael@0: }