blob: 11c3d46ec621cd1c0dea833632bc9bbcc9111433 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/gpu/GrContext.h"
12#include "include/private/GrRecordingContext.h"
13#include "src/gpu/GrCaps.h"
14#include "src/gpu/GrContextPriv.h"
15#include "src/gpu/GrGpu.h"
16#include "src/gpu/GrRecordingContextPriv.h"
17#include "src/gpu/GrShaderCaps.h"
18#include "src/gpu/ccpr/GrCoverageCountingPathRenderer.h"
19#include "src/gpu/ops/GrAAConvexPathRenderer.h"
20#include "src/gpu/ops/GrAAHairLinePathRenderer.h"
21#include "src/gpu/ops/GrAALinearizingConvexPathRenderer.h"
22#include "src/gpu/ops/GrDashLinePathRenderer.h"
23#include "src/gpu/ops/GrDefaultPathRenderer.h"
24#include "src/gpu/ops/GrSmallPathRenderer.h"
25#include "src/gpu/ops/GrStencilAndCoverPathRenderer.h"
Chris Dalton17dc4182020-03-25 16:18:16 -060026#include "src/gpu/ops/GrTriangulatingPathRenderer.h"
Chris Daltonb832ce62020-01-06 19:49:37 -070027#include "src/gpu/tessellate/GrGpuTessellationPathRenderer.h"
joshualitt0cffb172015-09-02 08:42:16 -070028
Robert Phillips69893702019-02-22 11:16:30 -050029GrPathRendererChain::GrPathRendererChain(GrRecordingContext* context, const Options& options) {
Robert Phillips9da87e02019-02-04 13:26:26 -050030 const GrCaps& caps = *context->priv().caps();
csmartdalton008b9d82017-02-22 12:00:42 -070031 if (options.fGpuPathRenderers & GpuPathRenderers::kDashLine) {
32 fChain.push_back(sk_make_sp<GrDashLinePathRenderer>());
33 }
Chris Daltonb832ce62020-01-06 19:49:37 -070034 if (options.fGpuPathRenderers & GpuPathRenderers::kGpuTessellation) {
35 if (caps.shaderCaps()->tessellationSupport()) {
Chris Dalton4e998532020-02-10 11:06:42 -070036 auto gtess = sk_make_sp<GrGpuTessellationPathRenderer>(caps);
37 context->priv().addOnFlushCallbackObject(gtess.get());
38 fChain.push_back(std::move(gtess));
Chris Daltonb832ce62020-01-06 19:49:37 -070039 }
40 }
Chris Daltonc83571e2018-11-16 11:10:39 -050041 if (options.fGpuPathRenderers & GpuPathRenderers::kAAConvex) {
42 fChain.push_back(sk_make_sp<GrAAConvexPathRenderer>());
43 }
Chris Daltondb91c6e2017-09-08 16:25:08 -060044 if (options.fGpuPathRenderers & GpuPathRenderers::kCoverageCounting) {
Chris Daltona2b5b642018-06-24 13:08:57 -060045 using AllowCaching = GrCoverageCountingPathRenderer::AllowCaching;
46 if (auto ccpr = GrCoverageCountingPathRenderer::CreateIfSupported(
Chris Dalton351e80c2019-01-06 22:51:00 -070047 caps, AllowCaching(options.fAllowPathMaskCaching),
Robert Phillips9da87e02019-02-04 13:26:26 -050048 context->priv().contextID())) {
Chris Daltonfddb6c02017-11-04 15:22:22 -060049 fCoverageCountingPathRenderer = ccpr.get();
Robert Phillips9da87e02019-02-04 13:26:26 -050050 context->priv().addOnFlushCallbackObject(fCoverageCountingPathRenderer);
Chris Daltondb91c6e2017-09-08 16:25:08 -060051 fChain.push_back(std::move(ccpr));
52 }
53 }
Chris Dalton9acfc6c2018-07-26 12:34:49 -060054 if (options.fGpuPathRenderers & GpuPathRenderers::kAAHairline) {
55 fChain.push_back(sk_make_sp<GrAAHairLinePathRenderer>());
56 }
csmartdalton008b9d82017-02-22 12:00:42 -070057 if (options.fGpuPathRenderers & GpuPathRenderers::kAALinearizing) {
58 fChain.push_back(sk_make_sp<GrAALinearizingConvexPathRenderer>());
59 }
Jim Van Verth83010462017-03-16 08:45:39 -040060 if (options.fGpuPathRenderers & GpuPathRenderers::kSmall) {
Jim Van Verth106b5c42017-09-26 12:45:29 -040061 auto spr = sk_make_sp<GrSmallPathRenderer>();
Robert Phillips9da87e02019-02-04 13:26:26 -050062 context->priv().addOnFlushCallbackObject(spr.get());
Jim Van Verth106b5c42017-09-26 12:45:29 -040063 fChain.push_back(std::move(spr));
bsalomon@google.com30085192011-08-19 15:42:31 +000064 }
Chris Daltonb3c97452019-06-25 20:07:56 -060065 if (options.fGpuPathRenderers & GpuPathRenderers::kStencilAndCover) {
66 auto direct = context->priv().asDirectContext();
67 if (direct) {
68 auto resourceProvider = direct->priv().resourceProvider();
69
70 sk_sp<GrPathRenderer> pr(
71 GrStencilAndCoverPathRenderer::Create(resourceProvider, caps));
72 if (pr) {
73 fChain.push_back(std::move(pr));
74 }
75 }
76 }
Chris Dalton17dc4182020-03-25 16:18:16 -060077 if (options.fGpuPathRenderers & GpuPathRenderers::kTriangulating) {
78 fChain.push_back(sk_make_sp<GrTriangulatingPathRenderer>());
csmartdalton008b9d82017-02-22 12:00:42 -070079 }
Brian Osman8b0f2652017-08-29 15:18:34 -040080
81 // We always include the default path renderer (as well as SW), so we can draw any path
82 fChain.push_back(sk_make_sp<GrDefaultPathRenderer>());
bsalomon@google.com30085192011-08-19 15:42:31 +000083}
84
bsalomond6f25bf2016-05-05 09:26:21 -070085GrPathRenderer* GrPathRendererChain::getPathRenderer(
86 const GrPathRenderer::CanDrawPathArgs& args,
87 DrawType drawType,
88 GrPathRenderer::StencilSupport* stencilSupport) {
Brian Salomon4dea72a2019-12-18 10:43:10 -050089 static_assert(GrPathRenderer::kNoSupport_StencilSupport <
90 GrPathRenderer::kStencilOnly_StencilSupport);
91 static_assert(GrPathRenderer::kStencilOnly_StencilSupport <
92 GrPathRenderer::kNoRestriction_StencilSupport);
bsalomon@google.com45a15f52012-12-10 19:10:17 +000093 GrPathRenderer::StencilSupport minStencilSupport;
Brian Salomon82125e92016-12-10 09:35:48 -050094 if (DrawType::kStencil == drawType) {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000095 minStencilSupport = GrPathRenderer::kStencilOnly_StencilSupport;
Brian Salomon82125e92016-12-10 09:35:48 -050096 } else if (DrawType::kStencilAndColor == drawType) {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000097 minStencilSupport = GrPathRenderer::kNoRestriction_StencilSupport;
98 } else {
99 minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport;
100 }
bsalomond6f25bf2016-05-05 09:26:21 -0700101 if (minStencilSupport != GrPathRenderer::kNoSupport_StencilSupport) {
102 // We don't support (and shouldn't need) stenciling of non-fill paths.
bsalomon8acedde2016-06-24 10:42:16 -0700103 if (!args.fShape->style().isSimpleFill()) {
bsalomond6f25bf2016-05-05 09:26:21 -0700104 return nullptr;
105 }
106 }
bsalomon@google.com45a15f52012-12-10 19:10:17 +0000107
Chris Dalton5ed44232017-09-07 13:22:46 -0600108 GrPathRenderer* bestPathRenderer = nullptr;
109 for (const sk_sp<GrPathRenderer>& pr : fChain) {
110 GrPathRenderer::StencilSupport support = GrPathRenderer::kNoSupport_StencilSupport;
111 if (GrPathRenderer::kNoSupport_StencilSupport != minStencilSupport) {
112 support = pr->getStencilSupport(*args.fShape);
113 if (support < minStencilSupport) {
114 continue;
bsalomon@google.com45a15f52012-12-10 19:10:17 +0000115 }
Chris Dalton5ed44232017-09-07 13:22:46 -0600116 }
117 GrPathRenderer::CanDrawPath canDrawPath = pr->canDrawPath(args);
118 if (GrPathRenderer::CanDrawPath::kNo == canDrawPath) {
119 continue;
120 }
121 if (GrPathRenderer::CanDrawPath::kAsBackup == canDrawPath && bestPathRenderer) {
122 continue;
123 }
124 if (stencilSupport) {
125 *stencilSupport = support;
126 }
127 bestPathRenderer = pr.get();
128 if (GrPathRenderer::CanDrawPath::kYes == canDrawPath) {
129 break;
bsalomon@google.com30085192011-08-19 15:42:31 +0000130 }
131 }
Chris Dalton5ed44232017-09-07 13:22:46 -0600132 return bestPathRenderer;
bsalomon@google.com30085192011-08-19 15:42:31 +0000133}