blob: e21d1bc14840949e51669a935e9ed3edf066e07c [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"
joshualitt0cffb172015-09-02 08:42:16 -070027
Robert Phillips69893702019-02-22 11:16:30 -050028GrPathRendererChain::GrPathRendererChain(GrRecordingContext* context, const Options& options) {
Robert Phillips9da87e02019-02-04 13:26:26 -050029 const GrCaps& caps = *context->priv().caps();
csmartdalton008b9d82017-02-22 12:00:42 -070030 if (options.fGpuPathRenderers & GpuPathRenderers::kDashLine) {
31 fChain.push_back(sk_make_sp<GrDashLinePathRenderer>());
32 }
Chris Daltonc83571e2018-11-16 11:10:39 -050033 if (options.fGpuPathRenderers & GpuPathRenderers::kAAConvex) {
34 fChain.push_back(sk_make_sp<GrAAConvexPathRenderer>());
35 }
Chris Daltondb91c6e2017-09-08 16:25:08 -060036 if (options.fGpuPathRenderers & GpuPathRenderers::kCoverageCounting) {
Chris Daltona2b5b642018-06-24 13:08:57 -060037 using AllowCaching = GrCoverageCountingPathRenderer::AllowCaching;
38 if (auto ccpr = GrCoverageCountingPathRenderer::CreateIfSupported(
Chris Dalton351e80c2019-01-06 22:51:00 -070039 caps, AllowCaching(options.fAllowPathMaskCaching),
Robert Phillips9da87e02019-02-04 13:26:26 -050040 context->priv().contextID())) {
Chris Daltonfddb6c02017-11-04 15:22:22 -060041 fCoverageCountingPathRenderer = ccpr.get();
Robert Phillips9da87e02019-02-04 13:26:26 -050042 context->priv().addOnFlushCallbackObject(fCoverageCountingPathRenderer);
Chris Daltondb91c6e2017-09-08 16:25:08 -060043 fChain.push_back(std::move(ccpr));
44 }
45 }
Chris Dalton9acfc6c2018-07-26 12:34:49 -060046 if (options.fGpuPathRenderers & GpuPathRenderers::kAAHairline) {
47 fChain.push_back(sk_make_sp<GrAAHairLinePathRenderer>());
48 }
csmartdalton008b9d82017-02-22 12:00:42 -070049 if (options.fGpuPathRenderers & GpuPathRenderers::kAALinearizing) {
50 fChain.push_back(sk_make_sp<GrAALinearizingConvexPathRenderer>());
51 }
Jim Van Verth83010462017-03-16 08:45:39 -040052 if (options.fGpuPathRenderers & GpuPathRenderers::kSmall) {
Jim Van Verth106b5c42017-09-26 12:45:29 -040053 auto spr = sk_make_sp<GrSmallPathRenderer>();
Robert Phillips9da87e02019-02-04 13:26:26 -050054 context->priv().addOnFlushCallbackObject(spr.get());
Jim Van Verth106b5c42017-09-26 12:45:29 -040055 fChain.push_back(std::move(spr));
bsalomon@google.com30085192011-08-19 15:42:31 +000056 }
Chris Daltonb3c97452019-06-25 20:07:56 -060057 if (options.fGpuPathRenderers & GpuPathRenderers::kStencilAndCover) {
58 auto direct = context->priv().asDirectContext();
59 if (direct) {
60 auto resourceProvider = direct->priv().resourceProvider();
61
62 sk_sp<GrPathRenderer> pr(
63 GrStencilAndCoverPathRenderer::Create(resourceProvider, caps));
64 if (pr) {
65 fChain.push_back(std::move(pr));
66 }
67 }
68 }
Brian Osman8a9de3d2017-03-01 14:59:05 -050069 if (options.fGpuPathRenderers & GpuPathRenderers::kTessellating) {
csmartdalton008b9d82017-02-22 12:00:42 -070070 fChain.push_back(sk_make_sp<GrTessellatingPathRenderer>());
71 }
Brian Osman8b0f2652017-08-29 15:18:34 -040072
73 // We always include the default path renderer (as well as SW), so we can draw any path
74 fChain.push_back(sk_make_sp<GrDefaultPathRenderer>());
bsalomon@google.com30085192011-08-19 15:42:31 +000075}
76
bsalomond6f25bf2016-05-05 09:26:21 -070077GrPathRenderer* GrPathRendererChain::getPathRenderer(
78 const GrPathRenderer::CanDrawPathArgs& args,
79 DrawType drawType,
80 GrPathRenderer::StencilSupport* stencilSupport) {
Brian Salomonb0047b52019-12-05 19:52:25 +000081 GR_STATIC_ASSERT(GrPathRenderer::kNoSupport_StencilSupport <
82 GrPathRenderer::kStencilOnly_StencilSupport);
83 GR_STATIC_ASSERT(GrPathRenderer::kStencilOnly_StencilSupport <
84 GrPathRenderer::kNoRestriction_StencilSupport);
bsalomon@google.com45a15f52012-12-10 19:10:17 +000085 GrPathRenderer::StencilSupport minStencilSupport;
Brian Salomon82125e92016-12-10 09:35:48 -050086 if (DrawType::kStencil == drawType) {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000087 minStencilSupport = GrPathRenderer::kStencilOnly_StencilSupport;
Brian Salomon82125e92016-12-10 09:35:48 -050088 } else if (DrawType::kStencilAndColor == drawType) {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000089 minStencilSupport = GrPathRenderer::kNoRestriction_StencilSupport;
90 } else {
91 minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport;
92 }
bsalomond6f25bf2016-05-05 09:26:21 -070093 if (minStencilSupport != GrPathRenderer::kNoSupport_StencilSupport) {
94 // We don't support (and shouldn't need) stenciling of non-fill paths.
bsalomon8acedde2016-06-24 10:42:16 -070095 if (!args.fShape->style().isSimpleFill()) {
bsalomond6f25bf2016-05-05 09:26:21 -070096 return nullptr;
97 }
98 }
bsalomon@google.com45a15f52012-12-10 19:10:17 +000099
Chris Dalton5ed44232017-09-07 13:22:46 -0600100 GrPathRenderer* bestPathRenderer = nullptr;
101 for (const sk_sp<GrPathRenderer>& pr : fChain) {
102 GrPathRenderer::StencilSupport support = GrPathRenderer::kNoSupport_StencilSupport;
103 if (GrPathRenderer::kNoSupport_StencilSupport != minStencilSupport) {
104 support = pr->getStencilSupport(*args.fShape);
105 if (support < minStencilSupport) {
106 continue;
bsalomon@google.com45a15f52012-12-10 19:10:17 +0000107 }
Chris Dalton5ed44232017-09-07 13:22:46 -0600108 }
109 GrPathRenderer::CanDrawPath canDrawPath = pr->canDrawPath(args);
110 if (GrPathRenderer::CanDrawPath::kNo == canDrawPath) {
111 continue;
112 }
113 if (GrPathRenderer::CanDrawPath::kAsBackup == canDrawPath && bestPathRenderer) {
114 continue;
115 }
116 if (stencilSupport) {
117 *stencilSupport = support;
118 }
119 bestPathRenderer = pr.get();
120 if (GrPathRenderer::CanDrawPath::kYes == canDrawPath) {
121 break;
bsalomon@google.com30085192011-08-19 15:42:31 +0000122 }
123 }
Chris Dalton5ed44232017-09-07 13:22:46 -0600124 return bestPathRenderer;
bsalomon@google.com30085192011-08-19 15:42:31 +0000125}