blob: b1eb3202bfdc93e1849cebfff5f76a0c4d99421f [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"
bsalomon@google.com30085192011-08-19 15:42:31 +000014#include "GrGpu.h"
15
joshualitt0cffb172015-09-02 08:42:16 -070016#include "batches/GrAAConvexPathRenderer.h"
17#include "batches/GrAADistanceFieldPathRenderer.h"
18#include "batches/GrAAHairLinePathRenderer.h"
19#include "batches/GrAALinearizingConvexPathRenderer.h"
20#include "batches/GrDashLinePathRenderer.h"
21#include "batches/GrDefaultPathRenderer.h"
22#include "batches/GrStencilAndCoverPathRenderer.h"
23#include "batches/GrTessellatingPathRenderer.h"
24
bsalomon@google.com45a15f52012-12-10 19:10:17 +000025GrPathRendererChain::GrPathRendererChain(GrContext* context)
bsalomon@google.com30085192011-08-19 15:42:31 +000026 : fInit(false)
bsalomon@google.com45a15f52012-12-10 19:10:17 +000027 , fOwner(context) {
bsalomon@google.com30085192011-08-19 15:42:31 +000028}
bsalomon@google.comb27a8d52012-03-02 15:08:16 +000029
bsalomon@google.com30085192011-08-19 15:42:31 +000030GrPathRendererChain::~GrPathRendererChain() {
31 for (int i = 0; i < fChain.count(); ++i) {
32 fChain[i]->unref();
33 }
34}
35
36GrPathRenderer* GrPathRendererChain::addPathRenderer(GrPathRenderer* pr) {
37 fChain.push_back() = pr;
38 pr->ref();
39 return pr;
40}
41
robertphillipsb83bec52015-10-23 09:38:03 -070042GrPathRenderer* GrPathRendererChain::getPathRenderer(const GrShaderCaps* shaderCaps,
robertphillips24cdec12015-10-26 14:12:25 -070043 const GrPipelineBuilder* pipelineBuilder,
joshualitt8059eb92014-12-29 15:10:07 -080044 const SkMatrix& viewMatrix,
joshualitt9853cce2014-11-17 14:22:48 -080045 const SkPath& path,
kkinnunen18996512015-04-26 23:18:49 -070046 const GrStrokeInfo& stroke,
bsalomon@google.com45a15f52012-12-10 19:10:17 +000047 DrawType drawType,
48 StencilSupport* stencilSupport) {
bsalomon@google.com30085192011-08-19 15:42:31 +000049 if (!fInit) {
50 this->init();
51 }
bsalomon@google.com45a15f52012-12-10 19:10:17 +000052 bool antiAlias = (kColorAntiAlias_DrawType == drawType ||
53 kStencilAndColorAntiAlias_DrawType == drawType);
54
55 GR_STATIC_ASSERT(GrPathRenderer::kNoSupport_StencilSupport <
56 GrPathRenderer::kStencilOnly_StencilSupport);
57 GR_STATIC_ASSERT(GrPathRenderer::kStencilOnly_StencilSupport <
58 GrPathRenderer::kNoRestriction_StencilSupport);
59 GrPathRenderer::StencilSupport minStencilSupport;
60 if (kStencilOnly_DrawType == drawType) {
61 minStencilSupport = GrPathRenderer::kStencilOnly_StencilSupport;
62 } else if (kStencilAndColor_DrawType == drawType ||
63 kStencilAndColorAntiAlias_DrawType == drawType) {
64 minStencilSupport = GrPathRenderer::kNoRestriction_StencilSupport;
65 } else {
66 minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport;
67 }
68
robertphillips@google.come79f3202014-02-11 16:30:21 +000069
bsalomon@google.com30085192011-08-19 15:42:31 +000070 for (int i = 0; i < fChain.count(); ++i) {
robertphillips24cdec12015-10-26 14:12:25 -070071 GrPathRenderer::CanDrawPathArgs args;
72 args.fShaderCaps = shaderCaps;
73 args.fPipelineBuilder = pipelineBuilder;
74 args.fViewMatrix = &viewMatrix;
75 args.fPath = &path;
76 args.fStroke = &stroke;
77 args.fAntiAlias = antiAlias;
bsalomon0aff2fa2015-07-31 06:48:27 -070078 if (fChain[i]->canDrawPath(args)) {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000079 if (GrPathRenderer::kNoSupport_StencilSupport != minStencilSupport) {
egdaniel8dd688b2015-01-22 10:16:09 -080080 GrPathRenderer::StencilSupport support =
robertphillipse7d4b2f2015-08-13 07:57:10 -070081 fChain[i]->getStencilSupport(path, stroke);
bsalomon@google.com45a15f52012-12-10 19:10:17 +000082 if (support < minStencilSupport) {
83 continue;
bsalomon49f085d2014-09-05 13:34:00 -070084 } else if (stencilSupport) {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000085 *stencilSupport = support;
86 }
87 }
bsalomon@google.com289533a2011-10-27 12:34:25 +000088 return fChain[i];
bsalomon@google.com30085192011-08-19 15:42:31 +000089 }
90 }
halcanary96fcdcc2015-08-27 07:41:13 -070091 return nullptr;
bsalomon@google.com30085192011-08-19 15:42:31 +000092}
93
94void GrPathRendererChain::init() {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000095 SkASSERT(!fInit);
joshualitt0cffb172015-09-02 08:42:16 -070096 const GrCaps& caps = *fOwner->caps();
97 this->addPathRenderer(new GrDashLinePathRenderer)->unref();
98
99 if (GrPathRenderer* pr = GrStencilAndCoverPathRenderer::Create(fOwner->resourceProvider(),
100 caps)) {
101 this->addPathRenderer(pr)->unref();
102 }
103 this->addPathRenderer(new GrTessellatingPathRenderer)->unref();
104 this->addPathRenderer(new GrAAHairLinePathRenderer)->unref();
105 this->addPathRenderer(new GrAAConvexPathRenderer)->unref();
106 this->addPathRenderer(new GrAALinearizingConvexPathRenderer)->unref();
107 this->addPathRenderer(new GrAADistanceFieldPathRenderer)->unref();
108 this->addPathRenderer(new GrDefaultPathRenderer(caps.twoSidedStencilSupport(),
109 caps.stencilWrapOpsSupport()))->unref();
bsalomon@google.com30085192011-08-19 15:42:31 +0000110 fInit = true;
111}