blob: d9717d51cb345464ffcc34c9c9c30f1e245577ad [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"
ethannicholas22793252016-01-30 09:59:10 -080013#include "gl/GrGLCaps.h"
14#include "glsl/GrGLSLCaps.h"
bsalomon@google.com30085192011-08-19 15:42:31 +000015#include "GrContext.h"
bsalomon@google.com30085192011-08-19 15:42:31 +000016#include "GrGpu.h"
17
joshualitt0cffb172015-09-02 08:42:16 -070018#include "batches/GrAAConvexPathRenderer.h"
19#include "batches/GrAADistanceFieldPathRenderer.h"
20#include "batches/GrAAHairLinePathRenderer.h"
21#include "batches/GrAALinearizingConvexPathRenderer.h"
22#include "batches/GrDashLinePathRenderer.h"
23#include "batches/GrDefaultPathRenderer.h"
24#include "batches/GrStencilAndCoverPathRenderer.h"
25#include "batches/GrTessellatingPathRenderer.h"
ethannicholas22793252016-01-30 09:59:10 -080026#include "batches/GrPLSPathRenderer.h"
joshualitt0cffb172015-09-02 08:42:16 -070027
robertphillips13391dd2015-10-30 05:15:11 -070028GrPathRendererChain::GrPathRendererChain(GrContext* context) {
29 const GrCaps& caps = *context->caps();
30 this->addPathRenderer(new GrDashLinePathRenderer)->unref();
31
32 if (GrPathRenderer* pr = GrStencilAndCoverPathRenderer::Create(context->resourceProvider(),
33 caps)) {
34 this->addPathRenderer(pr)->unref();
35 }
36 this->addPathRenderer(new GrTessellatingPathRenderer)->unref();
37 this->addPathRenderer(new GrAAHairLinePathRenderer)->unref();
38 this->addPathRenderer(new GrAAConvexPathRenderer)->unref();
39 this->addPathRenderer(new GrAALinearizingConvexPathRenderer)->unref();
ethannicholas22793252016-01-30 09:59:10 -080040 if (caps.shaderCaps()->plsPathRenderingSupport()) {
41 this->addPathRenderer(new GrPLSPathRenderer)->unref();
42 }
robertphillips13391dd2015-10-30 05:15:11 -070043 this->addPathRenderer(new GrAADistanceFieldPathRenderer)->unref();
44 this->addPathRenderer(new GrDefaultPathRenderer(caps.twoSidedStencilSupport(),
45 caps.stencilWrapOpsSupport()))->unref();
bsalomon@google.com30085192011-08-19 15:42:31 +000046}
bsalomon@google.comb27a8d52012-03-02 15:08:16 +000047
bsalomon@google.com30085192011-08-19 15:42:31 +000048GrPathRendererChain::~GrPathRendererChain() {
49 for (int i = 0; i < fChain.count(); ++i) {
50 fChain[i]->unref();
51 }
52}
53
54GrPathRenderer* GrPathRendererChain::addPathRenderer(GrPathRenderer* pr) {
55 fChain.push_back() = pr;
56 pr->ref();
57 return pr;
58}
59
robertphillips68737822015-10-29 12:12:21 -070060GrPathRenderer* GrPathRendererChain::getPathRenderer(const GrPathRenderer::CanDrawPathArgs& args,
bsalomon@google.com45a15f52012-12-10 19:10:17 +000061 DrawType drawType,
robertphillips68737822015-10-29 12:12:21 -070062 GrPathRenderer::StencilSupport* stencilSupport) {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000063 GR_STATIC_ASSERT(GrPathRenderer::kNoSupport_StencilSupport <
64 GrPathRenderer::kStencilOnly_StencilSupport);
65 GR_STATIC_ASSERT(GrPathRenderer::kStencilOnly_StencilSupport <
66 GrPathRenderer::kNoRestriction_StencilSupport);
67 GrPathRenderer::StencilSupport minStencilSupport;
68 if (kStencilOnly_DrawType == drawType) {
69 minStencilSupport = GrPathRenderer::kStencilOnly_StencilSupport;
70 } else if (kStencilAndColor_DrawType == drawType ||
71 kStencilAndColorAntiAlias_DrawType == drawType) {
72 minStencilSupport = GrPathRenderer::kNoRestriction_StencilSupport;
73 } else {
74 minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport;
75 }
76
bsalomon@google.com30085192011-08-19 15:42:31 +000077 for (int i = 0; i < fChain.count(); ++i) {
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 =
robertphillips68737822015-10-29 12:12:21 -070081 fChain[i]->getStencilSupport(*args.fPath, *args.fStroke);
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}