blob: cac0475bbf774fc5737d5105b7565c6ab145c104 [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
bsalomon@google.com45a15f52012-12-10 19:10:17 +000017GrPathRendererChain::GrPathRendererChain(GrContext* context)
bsalomon@google.com30085192011-08-19 15:42:31 +000018 : fInit(false)
bsalomon@google.com45a15f52012-12-10 19:10:17 +000019 , fOwner(context) {
bsalomon@google.com30085192011-08-19 15:42:31 +000020}
bsalomon@google.comb27a8d52012-03-02 15:08:16 +000021
bsalomon@google.com30085192011-08-19 15:42:31 +000022GrPathRendererChain::~GrPathRendererChain() {
23 for (int i = 0; i < fChain.count(); ++i) {
24 fChain[i]->unref();
25 }
26}
27
28GrPathRenderer* GrPathRendererChain::addPathRenderer(GrPathRenderer* pr) {
29 fChain.push_back() = pr;
30 pr->ref();
31 return pr;
32}
33
bsalomon@google.comc2099d22012-03-02 21:26:50 +000034GrPathRenderer* GrPathRendererChain::getPathRenderer(const SkPath& path,
sugoi@google.com5f74cf82012-12-17 21:16:45 +000035 const SkStrokeRec& stroke,
bsalomon@google.comc2099d22012-03-02 21:26:50 +000036 const GrDrawTarget* target,
bsalomon@google.com45a15f52012-12-10 19:10:17 +000037 DrawType drawType,
38 StencilSupport* stencilSupport) {
bsalomon@google.com30085192011-08-19 15:42:31 +000039 if (!fInit) {
40 this->init();
41 }
bsalomon@google.com45a15f52012-12-10 19:10:17 +000042 bool antiAlias = (kColorAntiAlias_DrawType == drawType ||
43 kStencilAndColorAntiAlias_DrawType == drawType);
44
45 GR_STATIC_ASSERT(GrPathRenderer::kNoSupport_StencilSupport <
46 GrPathRenderer::kStencilOnly_StencilSupport);
47 GR_STATIC_ASSERT(GrPathRenderer::kStencilOnly_StencilSupport <
48 GrPathRenderer::kNoRestriction_StencilSupport);
49 GrPathRenderer::StencilSupport minStencilSupport;
50 if (kStencilOnly_DrawType == drawType) {
51 minStencilSupport = GrPathRenderer::kStencilOnly_StencilSupport;
52 } else if (kStencilAndColor_DrawType == drawType ||
53 kStencilAndColorAntiAlias_DrawType == drawType) {
54 minStencilSupport = GrPathRenderer::kNoRestriction_StencilSupport;
55 } else {
56 minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport;
57 }
58
59
bsalomon@google.com30085192011-08-19 15:42:31 +000060 for (int i = 0; i < fChain.count(); ++i) {
sugoi@google.com12b4e272012-12-06 20:13:11 +000061 if (fChain[i]->canDrawPath(path, stroke, target, antiAlias)) {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000062 if (GrPathRenderer::kNoSupport_StencilSupport != minStencilSupport) {
63 GrPathRenderer::StencilSupport support = fChain[i]->getStencilSupport(path,
64 stroke,
65 target);
66 if (support < minStencilSupport) {
67 continue;
68 } else if (NULL != stencilSupport) {
69 *stencilSupport = support;
70 }
71 }
bsalomon@google.com289533a2011-10-27 12:34:25 +000072 return fChain[i];
bsalomon@google.com30085192011-08-19 15:42:31 +000073 }
74 }
bsalomon@google.com289533a2011-10-27 12:34:25 +000075 return NULL;
bsalomon@google.com30085192011-08-19 15:42:31 +000076}
77
78void GrPathRendererChain::init() {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000079 SkASSERT(!fInit);
bsalomon@google.com30085192011-08-19 15:42:31 +000080 GrGpu* gpu = fOwner->getGpu();
bsalomon@google.combcce8922013-03-25 15:38:39 +000081 bool twoSided = gpu->caps()->twoSidedStencilSupport();
82 bool wrapOp = gpu->caps()->stencilWrapOpsSupport();
bsalomon@google.com45a15f52012-12-10 19:10:17 +000083 GrPathRenderer::AddPathRenderers(fOwner, this);
tomhudson@google.comc377baf2012-07-09 20:17:56 +000084 this->addPathRenderer(SkNEW_ARGS(GrDefaultPathRenderer,
85 (twoSided, wrapOp)))->unref();
bsalomon@google.com30085192011-08-19 15:42:31 +000086 fInit = true;
87}