blob: e408762d0aea0b147efc92506a1d21e100aec017 [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
bsalomoneb1cb5c2015-05-22 08:01:09 -070012#include "GrCaps.h"
bsalomon@google.com30085192011-08-19 15:42:31 +000013#include "GrContext.h"
14#include "GrDefaultPathRenderer.h"
15#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,
kkinnunen18996512015-04-26 23:18:49 -070038 const GrStrokeInfo& 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) {
bsalomon0aff2fa2015-07-31 06:48:27 -070063 GrPathRenderer::CanDrawPathArgs args;
robertphillipse7d4b2f2015-08-13 07:57:10 -070064 args.fShaderCaps = target->caps()->shaderCaps();
bsalomon0aff2fa2015-07-31 06:48:27 -070065 args.fPipelineBuilder = pipelineBuilder;
66 args.fViewMatrix = &viewMatrix;
67 args.fPath = &path;
68 args.fStroke = &stroke;
69 args.fAntiAlias = antiAlias;
70 if (fChain[i]->canDrawPath(args)) {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000071 if (GrPathRenderer::kNoSupport_StencilSupport != minStencilSupport) {
egdaniel8dd688b2015-01-22 10:16:09 -080072 GrPathRenderer::StencilSupport support =
robertphillipse7d4b2f2015-08-13 07:57:10 -070073 fChain[i]->getStencilSupport(path, stroke);
bsalomon@google.com45a15f52012-12-10 19:10:17 +000074 if (support < minStencilSupport) {
75 continue;
bsalomon49f085d2014-09-05 13:34:00 -070076 } else if (stencilSupport) {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000077 *stencilSupport = support;
78 }
79 }
bsalomon@google.com289533a2011-10-27 12:34:25 +000080 return fChain[i];
bsalomon@google.com30085192011-08-19 15:42:31 +000081 }
82 }
halcanary96fcdcc2015-08-27 07:41:13 -070083 return nullptr;
bsalomon@google.com30085192011-08-19 15:42:31 +000084}
85
86void GrPathRendererChain::init() {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000087 SkASSERT(!fInit);
bsalomon76228632015-05-29 08:02:10 -070088 const GrCaps* caps = fOwner->caps();
89 bool twoSided = caps->twoSidedStencilSupport();
90 bool wrapOp = caps->stencilWrapOpsSupport();
bsalomon@google.com45a15f52012-12-10 19:10:17 +000091 GrPathRenderer::AddPathRenderers(fOwner, this);
halcanary385fe4d2015-08-26 13:07:48 -070092 this->addPathRenderer(new GrDefaultPathRenderer(twoSided, wrapOp))->unref();
bsalomon@google.com30085192011-08-19 15:42:31 +000093 fInit = true;
94}