blob: d11763bff13297eae4ef9b9325a849d2baf0a9d7 [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
joshualitt9853cce2014-11-17 14:22:48 -080034GrPathRenderer* GrPathRendererChain::getPathRenderer(const GrDrawTarget* target,
egdaniel8dd688b2015-01-22 10:16:09 -080035 const GrPipelineBuilder* pipelineBuilder,
joshualitt8059eb92014-12-29 15:10:07 -080036 const SkMatrix& viewMatrix,
joshualitt9853cce2014-11-17 14:22:48 -080037 const SkPath& path,
sugoi@google.com5f74cf82012-12-17 21:16:45 +000038 const SkStrokeRec& stroke,
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
robertphillips@google.come79f3202014-02-11 16:30:21 +000061
bsalomon@google.com30085192011-08-19 15:42:31 +000062 for (int i = 0; i < fChain.count(); ++i) {
egdaniel8dd688b2015-01-22 10:16:09 -080063 if (fChain[i]->canDrawPath(target, pipelineBuilder, viewMatrix, path, stroke, antiAlias)) {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000064 if (GrPathRenderer::kNoSupport_StencilSupport != minStencilSupport) {
egdaniel8dd688b2015-01-22 10:16:09 -080065 GrPathRenderer::StencilSupport support =
66 fChain[i]->getStencilSupport(target, pipelineBuilder, path, stroke);
bsalomon@google.com45a15f52012-12-10 19:10:17 +000067 if (support < minStencilSupport) {
68 continue;
bsalomon49f085d2014-09-05 13:34:00 -070069 } else if (stencilSupport) {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000070 *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() {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000080 SkASSERT(!fInit);
bsalomon@google.com30085192011-08-19 15:42:31 +000081 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}