blob: 34d6931b976e9c1763b7b40090e5c542b211d6de [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"
26#include "src/gpu/ops/GrTessellatingPathRenderer.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()) {
36 fChain.push_back(sk_make_sp<GrGpuTessellationPathRenderer>());
37 }
38 }
Chris Daltonc83571e2018-11-16 11:10:39 -050039 if (options.fGpuPathRenderers & GpuPathRenderers::kAAConvex) {
40 fChain.push_back(sk_make_sp<GrAAConvexPathRenderer>());
41 }
Chris Daltondb91c6e2017-09-08 16:25:08 -060042 if (options.fGpuPathRenderers & GpuPathRenderers::kCoverageCounting) {
Chris Daltona2b5b642018-06-24 13:08:57 -060043 using AllowCaching = GrCoverageCountingPathRenderer::AllowCaching;
44 if (auto ccpr = GrCoverageCountingPathRenderer::CreateIfSupported(
Chris Dalton351e80c2019-01-06 22:51:00 -070045 caps, AllowCaching(options.fAllowPathMaskCaching),
Robert Phillips9da87e02019-02-04 13:26:26 -050046 context->priv().contextID())) {
Chris Daltonfddb6c02017-11-04 15:22:22 -060047 fCoverageCountingPathRenderer = ccpr.get();
Robert Phillips9da87e02019-02-04 13:26:26 -050048 context->priv().addOnFlushCallbackObject(fCoverageCountingPathRenderer);
Chris Daltondb91c6e2017-09-08 16:25:08 -060049 fChain.push_back(std::move(ccpr));
50 }
51 }
Chris Dalton9acfc6c2018-07-26 12:34:49 -060052 if (options.fGpuPathRenderers & GpuPathRenderers::kAAHairline) {
53 fChain.push_back(sk_make_sp<GrAAHairLinePathRenderer>());
54 }
csmartdalton008b9d82017-02-22 12:00:42 -070055 if (options.fGpuPathRenderers & GpuPathRenderers::kAALinearizing) {
56 fChain.push_back(sk_make_sp<GrAALinearizingConvexPathRenderer>());
57 }
Jim Van Verth83010462017-03-16 08:45:39 -040058 if (options.fGpuPathRenderers & GpuPathRenderers::kSmall) {
Jim Van Verth106b5c42017-09-26 12:45:29 -040059 auto spr = sk_make_sp<GrSmallPathRenderer>();
Robert Phillips9da87e02019-02-04 13:26:26 -050060 context->priv().addOnFlushCallbackObject(spr.get());
Jim Van Verth106b5c42017-09-26 12:45:29 -040061 fChain.push_back(std::move(spr));
bsalomon@google.com30085192011-08-19 15:42:31 +000062 }
Chris Daltonb3c97452019-06-25 20:07:56 -060063 if (options.fGpuPathRenderers & GpuPathRenderers::kStencilAndCover) {
64 auto direct = context->priv().asDirectContext();
65 if (direct) {
66 auto resourceProvider = direct->priv().resourceProvider();
67
68 sk_sp<GrPathRenderer> pr(
69 GrStencilAndCoverPathRenderer::Create(resourceProvider, caps));
70 if (pr) {
71 fChain.push_back(std::move(pr));
72 }
73 }
74 }
Brian Osman8a9de3d2017-03-01 14:59:05 -050075 if (options.fGpuPathRenderers & GpuPathRenderers::kTessellating) {
csmartdalton008b9d82017-02-22 12:00:42 -070076 fChain.push_back(sk_make_sp<GrTessellatingPathRenderer>());
77 }
Brian Osman8b0f2652017-08-29 15:18:34 -040078
79 // We always include the default path renderer (as well as SW), so we can draw any path
80 fChain.push_back(sk_make_sp<GrDefaultPathRenderer>());
bsalomon@google.com30085192011-08-19 15:42:31 +000081}
82
bsalomond6f25bf2016-05-05 09:26:21 -070083GrPathRenderer* GrPathRendererChain::getPathRenderer(
84 const GrPathRenderer::CanDrawPathArgs& args,
85 DrawType drawType,
86 GrPathRenderer::StencilSupport* stencilSupport) {
Brian Salomon4dea72a2019-12-18 10:43:10 -050087 static_assert(GrPathRenderer::kNoSupport_StencilSupport <
88 GrPathRenderer::kStencilOnly_StencilSupport);
89 static_assert(GrPathRenderer::kStencilOnly_StencilSupport <
90 GrPathRenderer::kNoRestriction_StencilSupport);
bsalomon@google.com45a15f52012-12-10 19:10:17 +000091 GrPathRenderer::StencilSupport minStencilSupport;
Brian Salomon82125e92016-12-10 09:35:48 -050092 if (DrawType::kStencil == drawType) {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000093 minStencilSupport = GrPathRenderer::kStencilOnly_StencilSupport;
Brian Salomon82125e92016-12-10 09:35:48 -050094 } else if (DrawType::kStencilAndColor == drawType) {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000095 minStencilSupport = GrPathRenderer::kNoRestriction_StencilSupport;
96 } else {
97 minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport;
98 }
bsalomond6f25bf2016-05-05 09:26:21 -070099 if (minStencilSupport != GrPathRenderer::kNoSupport_StencilSupport) {
100 // We don't support (and shouldn't need) stenciling of non-fill paths.
bsalomon8acedde2016-06-24 10:42:16 -0700101 if (!args.fShape->style().isSimpleFill()) {
bsalomond6f25bf2016-05-05 09:26:21 -0700102 return nullptr;
103 }
104 }
bsalomon@google.com45a15f52012-12-10 19:10:17 +0000105
Chris Dalton5ed44232017-09-07 13:22:46 -0600106 GrPathRenderer* bestPathRenderer = nullptr;
107 for (const sk_sp<GrPathRenderer>& pr : fChain) {
108 GrPathRenderer::StencilSupport support = GrPathRenderer::kNoSupport_StencilSupport;
109 if (GrPathRenderer::kNoSupport_StencilSupport != minStencilSupport) {
110 support = pr->getStencilSupport(*args.fShape);
111 if (support < minStencilSupport) {
112 continue;
bsalomon@google.com45a15f52012-12-10 19:10:17 +0000113 }
Chris Dalton5ed44232017-09-07 13:22:46 -0600114 }
115 GrPathRenderer::CanDrawPath canDrawPath = pr->canDrawPath(args);
116 if (GrPathRenderer::CanDrawPath::kNo == canDrawPath) {
117 continue;
118 }
119 if (GrPathRenderer::CanDrawPath::kAsBackup == canDrawPath && bestPathRenderer) {
120 continue;
121 }
122 if (stencilSupport) {
123 *stencilSupport = support;
124 }
125 bestPathRenderer = pr.get();
126 if (GrPathRenderer::CanDrawPath::kYes == canDrawPath) {
127 break;
bsalomon@google.com30085192011-08-19 15:42:31 +0000128 }
129 }
Chris Dalton5ed44232017-09-07 13:22:46 -0600130 return bestPathRenderer;
bsalomon@google.com30085192011-08-19 15:42:31 +0000131}