blob: d6de12b3f538c8ad73ba74d2a990b56374bd3182 [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"
bsalomon@google.comc26d94f2013-03-25 18:19:00 +000014#include "GrDrawTargetCaps.h"
bsalomon@google.com30085192011-08-19 15:42:31 +000015#include "GrGpu.h"
16
robertphillips@google.com4d73ac22012-06-13 18:54:08 +000017SK_DEFINE_INST_COUNT(GrPathRendererChain)
18
bsalomon@google.com45a15f52012-12-10 19:10:17 +000019GrPathRendererChain::GrPathRendererChain(GrContext* context)
bsalomon@google.com30085192011-08-19 15:42:31 +000020 : fInit(false)
bsalomon@google.com45a15f52012-12-10 19:10:17 +000021 , fOwner(context) {
bsalomon@google.com30085192011-08-19 15:42:31 +000022}
bsalomon@google.comb27a8d52012-03-02 15:08:16 +000023
bsalomon@google.com30085192011-08-19 15:42:31 +000024GrPathRendererChain::~GrPathRendererChain() {
25 for (int i = 0; i < fChain.count(); ++i) {
26 fChain[i]->unref();
27 }
28}
29
30GrPathRenderer* GrPathRendererChain::addPathRenderer(GrPathRenderer* pr) {
31 fChain.push_back() = pr;
32 pr->ref();
33 return pr;
34}
35
bsalomon@google.comc2099d22012-03-02 21:26:50 +000036GrPathRenderer* GrPathRendererChain::getPathRenderer(const SkPath& path,
sugoi@google.com5f74cf82012-12-17 21:16:45 +000037 const SkStrokeRec& stroke,
bsalomon@google.comc2099d22012-03-02 21:26:50 +000038 const GrDrawTarget* target,
bsalomon@google.com45a15f52012-12-10 19:10:17 +000039 DrawType drawType,
40 StencilSupport* stencilSupport) {
bsalomon@google.com30085192011-08-19 15:42:31 +000041 if (!fInit) {
42 this->init();
43 }
bsalomon@google.com45a15f52012-12-10 19:10:17 +000044 bool antiAlias = (kColorAntiAlias_DrawType == drawType ||
45 kStencilAndColorAntiAlias_DrawType == drawType);
46
47 GR_STATIC_ASSERT(GrPathRenderer::kNoSupport_StencilSupport <
48 GrPathRenderer::kStencilOnly_StencilSupport);
49 GR_STATIC_ASSERT(GrPathRenderer::kStencilOnly_StencilSupport <
50 GrPathRenderer::kNoRestriction_StencilSupport);
51 GrPathRenderer::StencilSupport minStencilSupport;
52 if (kStencilOnly_DrawType == drawType) {
53 minStencilSupport = GrPathRenderer::kStencilOnly_StencilSupport;
54 } else if (kStencilAndColor_DrawType == drawType ||
55 kStencilAndColorAntiAlias_DrawType == drawType) {
56 minStencilSupport = GrPathRenderer::kNoRestriction_StencilSupport;
57 } else {
58 minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport;
59 }
60
61
bsalomon@google.com30085192011-08-19 15:42:31 +000062 for (int i = 0; i < fChain.count(); ++i) {
sugoi@google.com12b4e272012-12-06 20:13:11 +000063 if (fChain[i]->canDrawPath(path, stroke, target, antiAlias)) {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000064 if (GrPathRenderer::kNoSupport_StencilSupport != minStencilSupport) {
65 GrPathRenderer::StencilSupport support = fChain[i]->getStencilSupport(path,
66 stroke,
67 target);
68 if (support < minStencilSupport) {
69 continue;
70 } else if (NULL != stencilSupport) {
71 *stencilSupport = support;
72 }
73 }
bsalomon@google.com289533a2011-10-27 12:34:25 +000074 return fChain[i];
bsalomon@google.com30085192011-08-19 15:42:31 +000075 }
76 }
bsalomon@google.com289533a2011-10-27 12:34:25 +000077 return NULL;
bsalomon@google.com30085192011-08-19 15:42:31 +000078}
79
80void GrPathRendererChain::init() {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000081 SkASSERT(!fInit);
bsalomon@google.com30085192011-08-19 15:42:31 +000082 GrGpu* gpu = fOwner->getGpu();
bsalomon@google.combcce8922013-03-25 15:38:39 +000083 bool twoSided = gpu->caps()->twoSidedStencilSupport();
84 bool wrapOp = gpu->caps()->stencilWrapOpsSupport();
bsalomon@google.com45a15f52012-12-10 19:10:17 +000085 GrPathRenderer::AddPathRenderers(fOwner, this);
tomhudson@google.comc377baf2012-07-09 20:17:56 +000086 this->addPathRenderer(SkNEW_ARGS(GrDefaultPathRenderer,
87 (twoSided, wrapOp)))->unref();
bsalomon@google.com30085192011-08-19 15:42:31 +000088 fInit = true;
89}