blob: 95105ba079bf42176ebfc364886872934d69b7fa [file] [log] [blame]
bsalomon@google.com30085192011-08-19 15:42:31 +00001/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8
9#include "GrPathRendererChain.h"
10
bsalomoneb1cb5c2015-05-22 08:01:09 -070011#include "GrCaps.h"
ethannicholas22793252016-01-30 09:59:10 -080012#include "gl/GrGLCaps.h"
13#include "glsl/GrGLSLCaps.h"
bsalomon@google.com30085192011-08-19 15:42:31 +000014#include "GrContext.h"
bsalomon@google.com30085192011-08-19 15:42:31 +000015#include "GrGpu.h"
16
joshualitt0cffb172015-09-02 08:42:16 -070017#include "batches/GrAAConvexPathRenderer.h"
18#include "batches/GrAADistanceFieldPathRenderer.h"
19#include "batches/GrAAHairLinePathRenderer.h"
20#include "batches/GrAALinearizingConvexPathRenderer.h"
21#include "batches/GrDashLinePathRenderer.h"
22#include "batches/GrDefaultPathRenderer.h"
ethannicholas6536ae52016-05-02 12:16:49 -070023#include "batches/GrMSAAPathRenderer.h"
24#include "batches/GrPLSPathRenderer.h"
joshualitt0cffb172015-09-02 08:42:16 -070025#include "batches/GrStencilAndCoverPathRenderer.h"
26#include "batches/GrTessellatingPathRenderer.h"
27
bsalomon6b2552f2016-09-15 13:50:26 -070028GrPathRendererChain::GrPathRendererChain(GrContext* context, const Options& options) {
bsalomon39ef7fb2016-09-21 11:16:05 -070029 if (!options.fDisableAllPathRenderers) {
30 const GrCaps& caps = *context->caps();
31 this->addPathRenderer(new GrDashLinePathRenderer)->unref();
robertphillips13391dd2015-10-30 05:15:11 -070032
bsalomon39ef7fb2016-09-21 11:16:05 -070033 if (GrPathRenderer* pr = GrStencilAndCoverPathRenderer::Create(context->resourceProvider(),
34 caps)) {
35 this->addPathRenderer(pr)->unref();
36 }
37 #ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK
38 if (caps.sampleShadingSupport()) {
39 this->addPathRenderer(new GrMSAAPathRenderer)->unref();
40 }
41 #endif
42 this->addPathRenderer(new GrAAHairLinePathRenderer)->unref();
43 this->addPathRenderer(new GrAAConvexPathRenderer)->unref();
44 this->addPathRenderer(new GrAALinearizingConvexPathRenderer)->unref();
45 if (caps.shaderCaps()->plsPathRenderingSupport()) {
46 this->addPathRenderer(new GrPLSPathRenderer)->unref();
47 }
48 if (!options.fDisableDistanceFieldRenderer) {
49 this->addPathRenderer(new GrAADistanceFieldPathRenderer)->unref();
50 }
51 this->addPathRenderer(new GrTessellatingPathRenderer)->unref();
52 this->addPathRenderer(new GrDefaultPathRenderer(caps.twoSidedStencilSupport(),
53 caps.stencilWrapOpsSupport()))->unref();
robertphillips13391dd2015-10-30 05:15:11 -070054 }
bsalomon@google.com30085192011-08-19 15:42:31 +000055}
bsalomon@google.comb27a8d52012-03-02 15:08:16 +000056
bsalomon@google.com30085192011-08-19 15:42:31 +000057GrPathRendererChain::~GrPathRendererChain() {
58 for (int i = 0; i < fChain.count(); ++i) {
59 fChain[i]->unref();
60 }
61}
62
63GrPathRenderer* GrPathRendererChain::addPathRenderer(GrPathRenderer* pr) {
64 fChain.push_back() = pr;
65 pr->ref();
66 return pr;
67}
68
bsalomond6f25bf2016-05-05 09:26:21 -070069GrPathRenderer* GrPathRendererChain::getPathRenderer(
70 const GrPathRenderer::CanDrawPathArgs& args,
71 DrawType drawType,
72 GrPathRenderer::StencilSupport* stencilSupport) {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000073 GR_STATIC_ASSERT(GrPathRenderer::kNoSupport_StencilSupport <
74 GrPathRenderer::kStencilOnly_StencilSupport);
75 GR_STATIC_ASSERT(GrPathRenderer::kStencilOnly_StencilSupport <
76 GrPathRenderer::kNoRestriction_StencilSupport);
77 GrPathRenderer::StencilSupport minStencilSupport;
78 if (kStencilOnly_DrawType == drawType) {
79 minStencilSupport = GrPathRenderer::kStencilOnly_StencilSupport;
80 } else if (kStencilAndColor_DrawType == drawType ||
81 kStencilAndColorAntiAlias_DrawType == drawType) {
82 minStencilSupport = GrPathRenderer::kNoRestriction_StencilSupport;
83 } else {
84 minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport;
85 }
bsalomond6f25bf2016-05-05 09:26:21 -070086 if (minStencilSupport != GrPathRenderer::kNoSupport_StencilSupport) {
87 // We don't support (and shouldn't need) stenciling of non-fill paths.
bsalomon8acedde2016-06-24 10:42:16 -070088 if (!args.fShape->style().isSimpleFill()) {
bsalomond6f25bf2016-05-05 09:26:21 -070089 return nullptr;
90 }
91 }
bsalomon@google.com45a15f52012-12-10 19:10:17 +000092
bsalomon@google.com30085192011-08-19 15:42:31 +000093 for (int i = 0; i < fChain.count(); ++i) {
bsalomon0aff2fa2015-07-31 06:48:27 -070094 if (fChain[i]->canDrawPath(args)) {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000095 if (GrPathRenderer::kNoSupport_StencilSupport != minStencilSupport) {
bsalomon8acedde2016-06-24 10:42:16 -070096 GrPathRenderer::StencilSupport support = fChain[i]->getStencilSupport(*args.fShape);
bsalomon@google.com45a15f52012-12-10 19:10:17 +000097 if (support < minStencilSupport) {
98 continue;
bsalomon49f085d2014-09-05 13:34:00 -070099 } else if (stencilSupport) {
bsalomon@google.com45a15f52012-12-10 19:10:17 +0000100 *stencilSupport = support;
101 }
102 }
bsalomon@google.com289533a2011-10-27 12:34:25 +0000103 return fChain[i];
bsalomon@google.com30085192011-08-19 15:42:31 +0000104 }
105 }
halcanary96fcdcc2015-08-27 07:41:13 -0700106 return nullptr;
bsalomon@google.com30085192011-08-19 15:42:31 +0000107}