blob: e13e6c658488c4b2aa3243c98f290765c187a130 [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
robertphillips13391dd2015-10-30 05:15:11 -070025GrPathRendererChain::GrPathRendererChain(GrContext* context) {
26 const GrCaps& caps = *context->caps();
27 this->addPathRenderer(new GrDashLinePathRenderer)->unref();
28
29 if (GrPathRenderer* pr = GrStencilAndCoverPathRenderer::Create(context->resourceProvider(),
30 caps)) {
31 this->addPathRenderer(pr)->unref();
32 }
33 this->addPathRenderer(new GrTessellatingPathRenderer)->unref();
34 this->addPathRenderer(new GrAAHairLinePathRenderer)->unref();
35 this->addPathRenderer(new GrAAConvexPathRenderer)->unref();
36 this->addPathRenderer(new GrAALinearizingConvexPathRenderer)->unref();
37 this->addPathRenderer(new GrAADistanceFieldPathRenderer)->unref();
38 this->addPathRenderer(new GrDefaultPathRenderer(caps.twoSidedStencilSupport(),
39 caps.stencilWrapOpsSupport()))->unref();
bsalomon@google.com30085192011-08-19 15:42:31 +000040}
bsalomon@google.comb27a8d52012-03-02 15:08:16 +000041
bsalomon@google.com30085192011-08-19 15:42:31 +000042GrPathRendererChain::~GrPathRendererChain() {
43 for (int i = 0; i < fChain.count(); ++i) {
44 fChain[i]->unref();
45 }
46}
47
48GrPathRenderer* GrPathRendererChain::addPathRenderer(GrPathRenderer* pr) {
49 fChain.push_back() = pr;
50 pr->ref();
51 return pr;
52}
53
robertphillips68737822015-10-29 12:12:21 -070054GrPathRenderer* GrPathRendererChain::getPathRenderer(const GrPathRenderer::CanDrawPathArgs& args,
bsalomon@google.com45a15f52012-12-10 19:10:17 +000055 DrawType drawType,
robertphillips68737822015-10-29 12:12:21 -070056 GrPathRenderer::StencilSupport* stencilSupport) {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000057 GR_STATIC_ASSERT(GrPathRenderer::kNoSupport_StencilSupport <
58 GrPathRenderer::kStencilOnly_StencilSupport);
59 GR_STATIC_ASSERT(GrPathRenderer::kStencilOnly_StencilSupport <
60 GrPathRenderer::kNoRestriction_StencilSupport);
61 GrPathRenderer::StencilSupport minStencilSupport;
62 if (kStencilOnly_DrawType == drawType) {
63 minStencilSupport = GrPathRenderer::kStencilOnly_StencilSupport;
64 } else if (kStencilAndColor_DrawType == drawType ||
65 kStencilAndColorAntiAlias_DrawType == drawType) {
66 minStencilSupport = GrPathRenderer::kNoRestriction_StencilSupport;
67 } else {
68 minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport;
69 }
70
bsalomon@google.com30085192011-08-19 15:42:31 +000071 for (int i = 0; i < fChain.count(); ++i) {
bsalomon0aff2fa2015-07-31 06:48:27 -070072 if (fChain[i]->canDrawPath(args)) {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000073 if (GrPathRenderer::kNoSupport_StencilSupport != minStencilSupport) {
egdaniel8dd688b2015-01-22 10:16:09 -080074 GrPathRenderer::StencilSupport support =
robertphillips68737822015-10-29 12:12:21 -070075 fChain[i]->getStencilSupport(*args.fPath, *args.fStroke);
bsalomon@google.com45a15f52012-12-10 19:10:17 +000076 if (support < minStencilSupport) {
77 continue;
bsalomon49f085d2014-09-05 13:34:00 -070078 } else if (stencilSupport) {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000079 *stencilSupport = support;
80 }
81 }
bsalomon@google.com289533a2011-10-27 12:34:25 +000082 return fChain[i];
bsalomon@google.com30085192011-08-19 15:42:31 +000083 }
84 }
halcanary96fcdcc2015-08-27 07:41:13 -070085 return nullptr;
bsalomon@google.com30085192011-08-19 15:42:31 +000086}