gfx/skia/trunk/src/gpu/GrPathRendererChain.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/gpu/GrPathRendererChain.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,87 @@
     1.4 +
     1.5 +/*
     1.6 + * Copyright 2011 Google Inc.
     1.7 + *
     1.8 + * Use of this source code is governed by a BSD-style license that can be
     1.9 + * found in the LICENSE file.
    1.10 + */
    1.11 +
    1.12 +
    1.13 +#include "GrPathRendererChain.h"
    1.14 +
    1.15 +#include "GrContext.h"
    1.16 +#include "GrDefaultPathRenderer.h"
    1.17 +#include "GrDrawTargetCaps.h"
    1.18 +#include "GrGpu.h"
    1.19 +
    1.20 +GrPathRendererChain::GrPathRendererChain(GrContext* context)
    1.21 +    : fInit(false)
    1.22 +    , fOwner(context) {
    1.23 +}
    1.24 +
    1.25 +GrPathRendererChain::~GrPathRendererChain() {
    1.26 +    for (int i = 0; i < fChain.count(); ++i) {
    1.27 +        fChain[i]->unref();
    1.28 +    }
    1.29 +}
    1.30 +
    1.31 +GrPathRenderer* GrPathRendererChain::addPathRenderer(GrPathRenderer* pr) {
    1.32 +    fChain.push_back() = pr;
    1.33 +    pr->ref();
    1.34 +    return pr;
    1.35 +}
    1.36 +
    1.37 +GrPathRenderer* GrPathRendererChain::getPathRenderer(const SkPath& path,
    1.38 +                                                     const SkStrokeRec& stroke,
    1.39 +                                                     const GrDrawTarget* target,
    1.40 +                                                     DrawType drawType,
    1.41 +                                                     StencilSupport* stencilSupport) {
    1.42 +    if (!fInit) {
    1.43 +        this->init();
    1.44 +    }
    1.45 +    bool antiAlias = (kColorAntiAlias_DrawType == drawType ||
    1.46 +                      kStencilAndColorAntiAlias_DrawType == drawType);
    1.47 +
    1.48 +    GR_STATIC_ASSERT(GrPathRenderer::kNoSupport_StencilSupport <
    1.49 +                     GrPathRenderer::kStencilOnly_StencilSupport);
    1.50 +    GR_STATIC_ASSERT(GrPathRenderer::kStencilOnly_StencilSupport <
    1.51 +                     GrPathRenderer::kNoRestriction_StencilSupport);
    1.52 +    GrPathRenderer::StencilSupport minStencilSupport;
    1.53 +    if (kStencilOnly_DrawType == drawType) {
    1.54 +        minStencilSupport = GrPathRenderer::kStencilOnly_StencilSupport;
    1.55 +    } else if (kStencilAndColor_DrawType == drawType ||
    1.56 +               kStencilAndColorAntiAlias_DrawType == drawType) {
    1.57 +        minStencilSupport = GrPathRenderer::kNoRestriction_StencilSupport;
    1.58 +    } else {
    1.59 +        minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport;
    1.60 +    }
    1.61 +
    1.62 +
    1.63 +    for (int i = 0; i < fChain.count(); ++i) {
    1.64 +        if (fChain[i]->canDrawPath(path, stroke, target, antiAlias)) {
    1.65 +            if (GrPathRenderer::kNoSupport_StencilSupport != minStencilSupport) {
    1.66 +                GrPathRenderer::StencilSupport support = fChain[i]->getStencilSupport(path,
    1.67 +                                                                                      stroke,
    1.68 +                                                                                      target);
    1.69 +                if (support < minStencilSupport) {
    1.70 +                    continue;
    1.71 +                } else if (NULL != stencilSupport) {
    1.72 +                    *stencilSupport = support;
    1.73 +                }
    1.74 +            }
    1.75 +            return fChain[i];
    1.76 +        }
    1.77 +    }
    1.78 +    return NULL;
    1.79 +}
    1.80 +
    1.81 +void GrPathRendererChain::init() {
    1.82 +    SkASSERT(!fInit);
    1.83 +    GrGpu* gpu = fOwner->getGpu();
    1.84 +    bool twoSided = gpu->caps()->twoSidedStencilSupport();
    1.85 +    bool wrapOp = gpu->caps()->stencilWrapOpsSupport();
    1.86 +    GrPathRenderer::AddPathRenderers(fOwner, this);
    1.87 +    this->addPathRenderer(SkNEW_ARGS(GrDefaultPathRenderer,
    1.88 +                                     (twoSided, wrapOp)))->unref();
    1.89 +    fInit = true;
    1.90 +}

mercurial