aboutsummaryrefslogtreecommitdiffhomepage
path: root/gpu/src/GrPathRendererChain.cpp
blob: dc09d43c1e3ad6a813fcc6ad14ddca1806cce181 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

/*
 * Copyright 2011 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */


#include "GrPathRendererChain.h"

#include "GrContext.h"
#include "GrDefaultPathRenderer.h"
#include "GrGpu.h"

GrPathRendererChain::GrPathRendererChain(GrContext* context, UsageFlags flags)
    : fInit(false)
    , fOwner(context)
    , fFlags(flags)
    , fChain(fStorage.get(), kPreAllocCount) {
    fInit = false;
}
    
GrPathRendererChain::~GrPathRendererChain() {
    for (int i = 0; i < fChain.count(); ++i) {
        fChain[i]->unref();
    }
}

GrPathRenderer* GrPathRendererChain::addPathRenderer(GrPathRenderer* pr) {
    fChain.push_back() = pr;
    pr->ref();
    return pr;
}

GrPathRenderer* GrPathRendererChain::getPathRenderer(const GrDrawTarget* target,
                                                     const GrPath& path,
                                                     GrPathFill fill) {
    if (!fInit) {
        this->init();
    }
    bool preferAA = target->isAntialiasState() && 
                    !target->getRenderTarget()->isMultisampled();
    GrPathRenderer* nonAAPR = NULL;
    for (int i = 0; i < fChain.count(); ++i) {
        if (fChain[i]->canDrawPath(target, path, fill)) {
            if (!preferAA || fChain[i]->supportsAA(target, path, fill)) {
                return fChain[i];
            } else {
                nonAAPR = fChain[i];
            }
        }
    }
    return nonAAPR;
}

void GrPathRendererChain::init() {
    GrAssert(!fInit);
    GrGpu* gpu = fOwner->getGpu();
    this->addPathRenderer(
                    new GrDefaultPathRenderer(gpu->supportsTwoSidedStencil(),
                    gpu->supportsStencilWrapOps()))->unref();
    GrPathRenderer::AddPathRenderers(fOwner, fFlags, this);
    fInit = true;
}