blob: 3458841f2401c5b9c44c617479d51905b71f5174 [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.com45a15f52012-12-10 19:10:17 +000018GrPathRendererChain::GrPathRendererChain(GrContext* context)
bsalomon@google.com30085192011-08-19 15:42:31 +000019 : fInit(false)
bsalomon@google.com45a15f52012-12-10 19:10:17 +000020 , fOwner(context) {
bsalomon@google.com30085192011-08-19 15:42:31 +000021}
bsalomon@google.comb27a8d52012-03-02 15:08:16 +000022
bsalomon@google.com30085192011-08-19 15:42:31 +000023GrPathRendererChain::~GrPathRendererChain() {
24 for (int i = 0; i < fChain.count(); ++i) {
25 fChain[i]->unref();
26 }
27}
28
29GrPathRenderer* GrPathRendererChain::addPathRenderer(GrPathRenderer* pr) {
30 fChain.push_back() = pr;
31 pr->ref();
32 return pr;
33}
34
bsalomon@google.comc2099d22012-03-02 21:26:50 +000035GrPathRenderer* GrPathRendererChain::getPathRenderer(const SkPath& path,
sugoi@google.com5f74cf82012-12-17 21:16:45 +000036 const SkStrokeRec& stroke,
bsalomon@google.comc2099d22012-03-02 21:26:50 +000037 const GrDrawTarget* target,
bsalomon@google.com45a15f52012-12-10 19:10:17 +000038 DrawType drawType,
39 StencilSupport* stencilSupport) {
bsalomon@google.com30085192011-08-19 15:42:31 +000040 if (!fInit) {
41 this->init();
42 }
bsalomon@google.com45a15f52012-12-10 19:10:17 +000043 bool antiAlias = (kColorAntiAlias_DrawType == drawType ||
44 kStencilAndColorAntiAlias_DrawType == drawType);
45
46 GR_STATIC_ASSERT(GrPathRenderer::kNoSupport_StencilSupport <
47 GrPathRenderer::kStencilOnly_StencilSupport);
48 GR_STATIC_ASSERT(GrPathRenderer::kStencilOnly_StencilSupport <
49 GrPathRenderer::kNoRestriction_StencilSupport);
50 GrPathRenderer::StencilSupport minStencilSupport;
51 if (kStencilOnly_DrawType == drawType) {
52 minStencilSupport = GrPathRenderer::kStencilOnly_StencilSupport;
53 } else if (kStencilAndColor_DrawType == drawType ||
54 kStencilAndColorAntiAlias_DrawType == drawType) {
55 minStencilSupport = GrPathRenderer::kNoRestriction_StencilSupport;
56 } else {
57 minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport;
58 }
59
60
bsalomon@google.com30085192011-08-19 15:42:31 +000061 for (int i = 0; i < fChain.count(); ++i) {
sugoi@google.com12b4e272012-12-06 20:13:11 +000062 if (fChain[i]->canDrawPath(path, stroke, target, antiAlias)) {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000063 if (GrPathRenderer::kNoSupport_StencilSupport != minStencilSupport) {
64 GrPathRenderer::StencilSupport support = fChain[i]->getStencilSupport(path,
65 stroke,
66 target);
67 if (support < minStencilSupport) {
68 continue;
69 } else if (NULL != stencilSupport) {
70 *stencilSupport = support;
71 }
72 }
bsalomon@google.com289533a2011-10-27 12:34:25 +000073 return fChain[i];
bsalomon@google.com30085192011-08-19 15:42:31 +000074 }
75 }
bsalomon@google.com289533a2011-10-27 12:34:25 +000076 return NULL;
bsalomon@google.com30085192011-08-19 15:42:31 +000077}
78
79void GrPathRendererChain::init() {
80 GrAssert(!fInit);
81 GrGpu* gpu = fOwner->getGpu();
bsalomon@google.combcce8922013-03-25 15:38:39 +000082 bool twoSided = gpu->caps()->twoSidedStencilSupport();
83 bool wrapOp = gpu->caps()->stencilWrapOpsSupport();
bsalomon@google.com45a15f52012-12-10 19:10:17 +000084 GrPathRenderer::AddPathRenderers(fOwner, this);
tomhudson@google.comc377baf2012-07-09 20:17:56 +000085 this->addPathRenderer(SkNEW_ARGS(GrDefaultPathRenderer,
86 (twoSided, wrapOp)))->unref();
bsalomon@google.com30085192011-08-19 15:42:31 +000087 fInit = true;
88}