bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 1 | /* |
| 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 Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 9 | #include "src/gpu/GrPathRendererChain.h" |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #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" |
joshualitt | 0cffb17 | 2015-09-02 08:42:16 -0700 | [diff] [blame] | 27 | |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 28 | GrPathRendererChain::GrPathRendererChain(GrRecordingContext* context, const Options& options) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 29 | const GrCaps& caps = *context->priv().caps(); |
csmartdalton | 008b9d8 | 2017-02-22 12:00:42 -0700 | [diff] [blame] | 30 | if (options.fGpuPathRenderers & GpuPathRenderers::kDashLine) { |
| 31 | fChain.push_back(sk_make_sp<GrDashLinePathRenderer>()); |
| 32 | } |
Chris Dalton | c83571e | 2018-11-16 11:10:39 -0500 | [diff] [blame] | 33 | if (options.fGpuPathRenderers & GpuPathRenderers::kAAConvex) { |
| 34 | fChain.push_back(sk_make_sp<GrAAConvexPathRenderer>()); |
| 35 | } |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 36 | if (options.fGpuPathRenderers & GpuPathRenderers::kCoverageCounting) { |
Chris Dalton | a2b5b64 | 2018-06-24 13:08:57 -0600 | [diff] [blame] | 37 | using AllowCaching = GrCoverageCountingPathRenderer::AllowCaching; |
| 38 | if (auto ccpr = GrCoverageCountingPathRenderer::CreateIfSupported( |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 39 | caps, AllowCaching(options.fAllowPathMaskCaching), |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 40 | context->priv().contextID())) { |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 41 | fCoverageCountingPathRenderer = ccpr.get(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 42 | context->priv().addOnFlushCallbackObject(fCoverageCountingPathRenderer); |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 43 | fChain.push_back(std::move(ccpr)); |
| 44 | } |
| 45 | } |
Chris Dalton | 9acfc6c | 2018-07-26 12:34:49 -0600 | [diff] [blame] | 46 | if (options.fGpuPathRenderers & GpuPathRenderers::kAAHairline) { |
| 47 | fChain.push_back(sk_make_sp<GrAAHairLinePathRenderer>()); |
| 48 | } |
csmartdalton | 008b9d8 | 2017-02-22 12:00:42 -0700 | [diff] [blame] | 49 | if (options.fGpuPathRenderers & GpuPathRenderers::kAALinearizing) { |
| 50 | fChain.push_back(sk_make_sp<GrAALinearizingConvexPathRenderer>()); |
| 51 | } |
Jim Van Verth | 8301046 | 2017-03-16 08:45:39 -0400 | [diff] [blame] | 52 | if (options.fGpuPathRenderers & GpuPathRenderers::kSmall) { |
Jim Van Verth | 106b5c4 | 2017-09-26 12:45:29 -0400 | [diff] [blame] | 53 | auto spr = sk_make_sp<GrSmallPathRenderer>(); |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 54 | context->priv().addOnFlushCallbackObject(spr.get()); |
Jim Van Verth | 106b5c4 | 2017-09-26 12:45:29 -0400 | [diff] [blame] | 55 | fChain.push_back(std::move(spr)); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 56 | } |
Chris Dalton | b3c9745 | 2019-06-25 20:07:56 -0600 | [diff] [blame] | 57 | 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 Osman | 8a9de3d | 2017-03-01 14:59:05 -0500 | [diff] [blame] | 69 | if (options.fGpuPathRenderers & GpuPathRenderers::kTessellating) { |
csmartdalton | 008b9d8 | 2017-02-22 12:00:42 -0700 | [diff] [blame] | 70 | fChain.push_back(sk_make_sp<GrTessellatingPathRenderer>()); |
| 71 | } |
Brian Osman | 8b0f265 | 2017-08-29 15:18:34 -0400 | [diff] [blame] | 72 | |
| 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.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 75 | } |
| 76 | |
bsalomon | d6f25bf | 2016-05-05 09:26:21 -0700 | [diff] [blame] | 77 | GrPathRenderer* GrPathRendererChain::getPathRenderer( |
| 78 | const GrPathRenderer::CanDrawPathArgs& args, |
| 79 | DrawType drawType, |
| 80 | GrPathRenderer::StencilSupport* stencilSupport) { |
Brian Salomon | b0047b5 | 2019-12-05 19:52:25 +0000 | [diff] [blame] | 81 | GR_STATIC_ASSERT(GrPathRenderer::kNoSupport_StencilSupport < |
| 82 | GrPathRenderer::kStencilOnly_StencilSupport); |
| 83 | GR_STATIC_ASSERT(GrPathRenderer::kStencilOnly_StencilSupport < |
| 84 | GrPathRenderer::kNoRestriction_StencilSupport); |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 85 | GrPathRenderer::StencilSupport minStencilSupport; |
Brian Salomon | 82125e9 | 2016-12-10 09:35:48 -0500 | [diff] [blame] | 86 | if (DrawType::kStencil == drawType) { |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 87 | minStencilSupport = GrPathRenderer::kStencilOnly_StencilSupport; |
Brian Salomon | 82125e9 | 2016-12-10 09:35:48 -0500 | [diff] [blame] | 88 | } else if (DrawType::kStencilAndColor == drawType) { |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 89 | minStencilSupport = GrPathRenderer::kNoRestriction_StencilSupport; |
| 90 | } else { |
| 91 | minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport; |
| 92 | } |
bsalomon | d6f25bf | 2016-05-05 09:26:21 -0700 | [diff] [blame] | 93 | if (minStencilSupport != GrPathRenderer::kNoSupport_StencilSupport) { |
| 94 | // We don't support (and shouldn't need) stenciling of non-fill paths. |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 95 | if (!args.fShape->style().isSimpleFill()) { |
bsalomon | d6f25bf | 2016-05-05 09:26:21 -0700 | [diff] [blame] | 96 | return nullptr; |
| 97 | } |
| 98 | } |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 99 | |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 100 | 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.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 107 | } |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 108 | } |
| 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.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 122 | } |
| 123 | } |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 124 | return bestPathRenderer; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 125 | } |