blob: 4f5807cf6c980488d1eecf2bd62ba6e3d5b7272f [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05009#include "src/gpu/GrPathRendererChain.h"
Robert Phillips69893702019-02-22 11:16:30 -050010
Robert Phillipsb7bfbc22020-07-01 12:55:01 -040011#include "include/gpu/GrDirectContext.h"
12#include "include/gpu/GrRecordingContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "src/gpu/GrCaps.h"
Adlai Hollera0693042020-10-14 11:23:11 -040014#include "src/gpu/GrDirectContextPriv.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050015#include "src/gpu/GrGpu.h"
16#include "src/gpu/GrRecordingContextPriv.h"
17#include "src/gpu/GrShaderCaps.h"
18#include "src/gpu/ccpr/GrCoverageCountingPathRenderer.h"
Robert Phillips5dd3d882020-08-10 09:29:39 -040019#include "src/gpu/geometry/GrStyledShape.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050020#include "src/gpu/ops/GrAAConvexPathRenderer.h"
21#include "src/gpu/ops/GrAAHairLinePathRenderer.h"
22#include "src/gpu/ops/GrAALinearizingConvexPathRenderer.h"
23#include "src/gpu/ops/GrDashLinePathRenderer.h"
24#include "src/gpu/ops/GrDefaultPathRenderer.h"
25#include "src/gpu/ops/GrSmallPathRenderer.h"
26#include "src/gpu/ops/GrStencilAndCoverPathRenderer.h"
Chris Dalton17dc4182020-03-25 16:18:16 -060027#include "src/gpu/ops/GrTriangulatingPathRenderer.h"
Chris Dalton0a22b1e2020-03-26 11:52:15 -060028#include "src/gpu/tessellate/GrTessellationPathRenderer.h"
joshualitt0cffb172015-09-02 08:42:16 -070029
Robert Phillips69893702019-02-22 11:16:30 -050030GrPathRendererChain::GrPathRendererChain(GrRecordingContext* context, const Options& options) {
Robert Phillips9da87e02019-02-04 13:26:26 -050031 const GrCaps& caps = *context->priv().caps();
csmartdalton008b9d82017-02-22 12:00:42 -070032 if (options.fGpuPathRenderers & GpuPathRenderers::kDashLine) {
33 fChain.push_back(sk_make_sp<GrDashLinePathRenderer>());
34 }
Chris Dalton0a22b1e2020-03-26 11:52:15 -060035 if (options.fGpuPathRenderers & GpuPathRenderers::kTessellation) {
Chris Dalton1413d112020-07-09 11:26:31 -060036 if (GrTessellationPathRenderer::IsSupported(caps)) {
Chris Dalton31634282020-09-17 12:16:54 -060037 auto tess = sk_make_sp<GrTessellationPathRenderer>(context);
Chris Dalton0a22b1e2020-03-26 11:52:15 -060038 context->priv().addOnFlushCallbackObject(tess.get());
39 fChain.push_back(std::move(tess));
Chris Daltonb832ce62020-01-06 19:49:37 -070040 }
41 }
Chris Daltonc83571e2018-11-16 11:10:39 -050042 if (options.fGpuPathRenderers & GpuPathRenderers::kAAConvex) {
43 fChain.push_back(sk_make_sp<GrAAConvexPathRenderer>());
44 }
Chris Daltondb91c6e2017-09-08 16:25:08 -060045 if (options.fGpuPathRenderers & GpuPathRenderers::kCoverageCounting) {
Chris Daltona2b5b642018-06-24 13:08:57 -060046 using AllowCaching = GrCoverageCountingPathRenderer::AllowCaching;
47 if (auto ccpr = GrCoverageCountingPathRenderer::CreateIfSupported(
Chris Dalton351e80c2019-01-06 22:51:00 -070048 caps, AllowCaching(options.fAllowPathMaskCaching),
Robert Phillips9da87e02019-02-04 13:26:26 -050049 context->priv().contextID())) {
Chris Daltonfddb6c02017-11-04 15:22:22 -060050 fCoverageCountingPathRenderer = ccpr.get();
Robert Phillips9da87e02019-02-04 13:26:26 -050051 context->priv().addOnFlushCallbackObject(fCoverageCountingPathRenderer);
Chris Daltondb91c6e2017-09-08 16:25:08 -060052 fChain.push_back(std::move(ccpr));
53 }
54 }
Chris Dalton9acfc6c2018-07-26 12:34:49 -060055 if (options.fGpuPathRenderers & GpuPathRenderers::kAAHairline) {
56 fChain.push_back(sk_make_sp<GrAAHairLinePathRenderer>());
57 }
csmartdalton008b9d82017-02-22 12:00:42 -070058 if (options.fGpuPathRenderers & GpuPathRenderers::kAALinearizing) {
59 fChain.push_back(sk_make_sp<GrAALinearizingConvexPathRenderer>());
60 }
Jim Van Verth83010462017-03-16 08:45:39 -040061 if (options.fGpuPathRenderers & GpuPathRenderers::kSmall) {
Robert Phillips079455c2020-08-11 15:18:46 -040062 fChain.push_back(sk_make_sp<GrSmallPathRenderer>());
bsalomon@google.com30085192011-08-19 15:42:31 +000063 }
Chris Daltonb3c97452019-06-25 20:07:56 -060064 if (options.fGpuPathRenderers & GpuPathRenderers::kStencilAndCover) {
Robert Phillipsf8f45d92020-07-01 11:11:18 -040065 auto direct = context->asDirectContext();
Chris Daltonb3c97452019-06-25 20:07:56 -060066 if (direct) {
67 auto resourceProvider = direct->priv().resourceProvider();
68
69 sk_sp<GrPathRenderer> pr(
70 GrStencilAndCoverPathRenderer::Create(resourceProvider, caps));
71 if (pr) {
72 fChain.push_back(std::move(pr));
73 }
74 }
75 }
Chris Dalton17dc4182020-03-25 16:18:16 -060076 if (options.fGpuPathRenderers & GpuPathRenderers::kTriangulating) {
77 fChain.push_back(sk_make_sp<GrTriangulatingPathRenderer>());
csmartdalton008b9d82017-02-22 12:00:42 -070078 }
Brian Osman8b0f2652017-08-29 15:18:34 -040079
80 // We always include the default path renderer (as well as SW), so we can draw any path
81 fChain.push_back(sk_make_sp<GrDefaultPathRenderer>());
bsalomon@google.com30085192011-08-19 15:42:31 +000082}
83
bsalomond6f25bf2016-05-05 09:26:21 -070084GrPathRenderer* GrPathRendererChain::getPathRenderer(
85 const GrPathRenderer::CanDrawPathArgs& args,
86 DrawType drawType,
87 GrPathRenderer::StencilSupport* stencilSupport) {
Brian Salomon4dea72a2019-12-18 10:43:10 -050088 static_assert(GrPathRenderer::kNoSupport_StencilSupport <
89 GrPathRenderer::kStencilOnly_StencilSupport);
90 static_assert(GrPathRenderer::kStencilOnly_StencilSupport <
91 GrPathRenderer::kNoRestriction_StencilSupport);
bsalomon@google.com45a15f52012-12-10 19:10:17 +000092 GrPathRenderer::StencilSupport minStencilSupport;
Brian Salomon82125e92016-12-10 09:35:48 -050093 if (DrawType::kStencil == drawType) {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000094 minStencilSupport = GrPathRenderer::kStencilOnly_StencilSupport;
Brian Salomon82125e92016-12-10 09:35:48 -050095 } else if (DrawType::kStencilAndColor == drawType) {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000096 minStencilSupport = GrPathRenderer::kNoRestriction_StencilSupport;
97 } else {
98 minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport;
99 }
bsalomond6f25bf2016-05-05 09:26:21 -0700100 if (minStencilSupport != GrPathRenderer::kNoSupport_StencilSupport) {
101 // We don't support (and shouldn't need) stenciling of non-fill paths.
bsalomon8acedde2016-06-24 10:42:16 -0700102 if (!args.fShape->style().isSimpleFill()) {
bsalomond6f25bf2016-05-05 09:26:21 -0700103 return nullptr;
104 }
105 }
bsalomon@google.com45a15f52012-12-10 19:10:17 +0000106
Chris Dalton5ed44232017-09-07 13:22:46 -0600107 GrPathRenderer* bestPathRenderer = nullptr;
108 for (const sk_sp<GrPathRenderer>& pr : fChain) {
109 GrPathRenderer::StencilSupport support = GrPathRenderer::kNoSupport_StencilSupport;
110 if (GrPathRenderer::kNoSupport_StencilSupport != minStencilSupport) {
111 support = pr->getStencilSupport(*args.fShape);
112 if (support < minStencilSupport) {
113 continue;
bsalomon@google.com45a15f52012-12-10 19:10:17 +0000114 }
Chris Dalton5ed44232017-09-07 13:22:46 -0600115 }
116 GrPathRenderer::CanDrawPath canDrawPath = pr->canDrawPath(args);
117 if (GrPathRenderer::CanDrawPath::kNo == canDrawPath) {
118 continue;
119 }
120 if (GrPathRenderer::CanDrawPath::kAsBackup == canDrawPath && bestPathRenderer) {
121 continue;
122 }
123 if (stencilSupport) {
124 *stencilSupport = support;
125 }
126 bestPathRenderer = pr.get();
127 if (GrPathRenderer::CanDrawPath::kYes == canDrawPath) {
128 break;
bsalomon@google.com30085192011-08-19 15:42:31 +0000129 }
130 }
Chris Dalton5ed44232017-09-07 13:22:46 -0600131 return bestPathRenderer;
bsalomon@google.com30085192011-08-19 15:42:31 +0000132}