blob: 63195c641488808812114ea5a8ffe8212ba2dda8 [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
robertphillips68737822015-10-29 12:12:21 -070042GrPathRenderer* GrPathRendererChain::getPathRenderer(const GrPathRenderer::CanDrawPathArgs& args,
bsalomon@google.com45a15f52012-12-10 19:10:17 +000043 DrawType drawType,
robertphillips68737822015-10-29 12:12:21 -070044 GrPathRenderer::StencilSupport* stencilSupport) {
bsalomon@google.com30085192011-08-19 15:42:31 +000045 if (!fInit) {
46 this->init();
47 }
bsalomon@google.com45a15f52012-12-10 19:10:17 +000048
49 GR_STATIC_ASSERT(GrPathRenderer::kNoSupport_StencilSupport <
50 GrPathRenderer::kStencilOnly_StencilSupport);
51 GR_STATIC_ASSERT(GrPathRenderer::kStencilOnly_StencilSupport <
52 GrPathRenderer::kNoRestriction_StencilSupport);
53 GrPathRenderer::StencilSupport minStencilSupport;
54 if (kStencilOnly_DrawType == drawType) {
55 minStencilSupport = GrPathRenderer::kStencilOnly_StencilSupport;
56 } else if (kStencilAndColor_DrawType == drawType ||
57 kStencilAndColorAntiAlias_DrawType == drawType) {
58 minStencilSupport = GrPathRenderer::kNoRestriction_StencilSupport;
59 } else {
60 minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport;
61 }
62
robertphillips@google.come79f3202014-02-11 16:30:21 +000063
bsalomon@google.com30085192011-08-19 15:42:31 +000064 for (int i = 0; i < fChain.count(); ++i) {
bsalomon0aff2fa2015-07-31 06:48:27 -070065 if (fChain[i]->canDrawPath(args)) {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000066 if (GrPathRenderer::kNoSupport_StencilSupport != minStencilSupport) {
egdaniel8dd688b2015-01-22 10:16:09 -080067 GrPathRenderer::StencilSupport support =
robertphillips68737822015-10-29 12:12:21 -070068 fChain[i]->getStencilSupport(*args.fPath, *args.fStroke);
bsalomon@google.com45a15f52012-12-10 19:10:17 +000069 if (support < minStencilSupport) {
70 continue;
bsalomon49f085d2014-09-05 13:34:00 -070071 } else if (stencilSupport) {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000072 *stencilSupport = support;
73 }
74 }
bsalomon@google.com289533a2011-10-27 12:34:25 +000075 return fChain[i];
bsalomon@google.com30085192011-08-19 15:42:31 +000076 }
77 }
halcanary96fcdcc2015-08-27 07:41:13 -070078 return nullptr;
bsalomon@google.com30085192011-08-19 15:42:31 +000079}
80
81void GrPathRendererChain::init() {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000082 SkASSERT(!fInit);
joshualitt0cffb172015-09-02 08:42:16 -070083 const GrCaps& caps = *fOwner->caps();
84 this->addPathRenderer(new GrDashLinePathRenderer)->unref();
85
86 if (GrPathRenderer* pr = GrStencilAndCoverPathRenderer::Create(fOwner->resourceProvider(),
87 caps)) {
88 this->addPathRenderer(pr)->unref();
89 }
90 this->addPathRenderer(new GrTessellatingPathRenderer)->unref();
91 this->addPathRenderer(new GrAAHairLinePathRenderer)->unref();
92 this->addPathRenderer(new GrAAConvexPathRenderer)->unref();
93 this->addPathRenderer(new GrAALinearizingConvexPathRenderer)->unref();
94 this->addPathRenderer(new GrAADistanceFieldPathRenderer)->unref();
95 this->addPathRenderer(new GrDefaultPathRenderer(caps.twoSidedStencilSupport(),
96 caps.stencilWrapOpsSupport()))->unref();
bsalomon@google.com30085192011-08-19 15:42:31 +000097 fInit = true;
98}