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 | |
| 9 | #include "GrPathRendererChain.h" |
bsalomon | eb1cb5c | 2015-05-22 08:01:09 -0700 | [diff] [blame] | 10 | #include "GrCaps.h" |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 11 | #include "GrShaderCaps.h" |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 12 | #include "GrContext.h" |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 13 | #include "GrContextPriv.h" |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 14 | #include "GrGpu.h" |
Chris Dalton | 1a325d2 | 2017-07-14 15:17:41 -0600 | [diff] [blame] | 15 | #include "ccpr/GrCoverageCountingPathRenderer.h" |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 16 | #include "ops/GrAAConvexPathRenderer.h" |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 17 | #include "ops/GrAAHairLinePathRenderer.h" |
| 18 | #include "ops/GrAALinearizingConvexPathRenderer.h" |
Jim Van Verth | 8301046 | 2017-03-16 08:45:39 -0400 | [diff] [blame] | 19 | #include "ops/GrSmallPathRenderer.h" |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 20 | #include "ops/GrDashLinePathRenderer.h" |
| 21 | #include "ops/GrDefaultPathRenderer.h" |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 22 | #include "ops/GrStencilAndCoverPathRenderer.h" |
| 23 | #include "ops/GrTessellatingPathRenderer.h" |
joshualitt | 0cffb17 | 2015-09-02 08:42:16 -0700 | [diff] [blame] | 24 | |
bsalomon | 6b2552f | 2016-09-15 13:50:26 -0700 | [diff] [blame] | 25 | GrPathRendererChain::GrPathRendererChain(GrContext* context, const Options& options) { |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 26 | const GrCaps& caps = *context->contextPriv().caps(); |
csmartdalton | 008b9d8 | 2017-02-22 12:00:42 -0700 | [diff] [blame] | 27 | if (options.fGpuPathRenderers & GpuPathRenderers::kDashLine) { |
| 28 | fChain.push_back(sk_make_sp<GrDashLinePathRenderer>()); |
| 29 | } |
| 30 | if (options.fGpuPathRenderers & GpuPathRenderers::kStencilAndCover) { |
| 31 | sk_sp<GrPathRenderer> pr( |
Robert Phillips | 6be756b | 2018-01-16 15:07:54 -0500 | [diff] [blame] | 32 | GrStencilAndCoverPathRenderer::Create(context->contextPriv().resourceProvider(), caps)); |
csmartdalton | 008b9d8 | 2017-02-22 12:00:42 -0700 | [diff] [blame] | 33 | if (pr) { |
| 34 | fChain.push_back(std::move(pr)); |
bsalomon | 39ef7fb | 2016-09-21 11:16:05 -0700 | [diff] [blame] | 35 | } |
csmartdalton | 008b9d8 | 2017-02-22 12:00:42 -0700 | [diff] [blame] | 36 | } |
Chris Dalton | c83571e | 2018-11-16 11:10:39 -0500 | [diff] [blame] | 37 | if (options.fGpuPathRenderers & GpuPathRenderers::kAAConvex) { |
| 38 | fChain.push_back(sk_make_sp<GrAAConvexPathRenderer>()); |
| 39 | } |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 40 | if (options.fGpuPathRenderers & GpuPathRenderers::kCoverageCounting) { |
Chris Dalton | a2b5b64 | 2018-06-24 13:08:57 -0600 | [diff] [blame] | 41 | using AllowCaching = GrCoverageCountingPathRenderer::AllowCaching; |
| 42 | if (auto ccpr = GrCoverageCountingPathRenderer::CreateIfSupported( |
Chris Dalton | 8429c79 | 2018-10-23 15:56:22 -0600 | [diff] [blame] | 43 | caps, AllowCaching(options.fAllowPathMaskCaching))) { |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 44 | fCoverageCountingPathRenderer = ccpr.get(); |
| 45 | context->contextPriv().addOnFlushCallbackObject(fCoverageCountingPathRenderer); |
Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 46 | fChain.push_back(std::move(ccpr)); |
| 47 | } |
| 48 | } |
Chris Dalton | 9acfc6c | 2018-07-26 12:34:49 -0600 | [diff] [blame] | 49 | if (options.fGpuPathRenderers & GpuPathRenderers::kAAHairline) { |
| 50 | fChain.push_back(sk_make_sp<GrAAHairLinePathRenderer>()); |
| 51 | } |
csmartdalton | 008b9d8 | 2017-02-22 12:00:42 -0700 | [diff] [blame] | 52 | if (options.fGpuPathRenderers & GpuPathRenderers::kAALinearizing) { |
| 53 | fChain.push_back(sk_make_sp<GrAALinearizingConvexPathRenderer>()); |
| 54 | } |
Jim Van Verth | 8301046 | 2017-03-16 08:45:39 -0400 | [diff] [blame] | 55 | if (options.fGpuPathRenderers & GpuPathRenderers::kSmall) { |
Jim Van Verth | 106b5c4 | 2017-09-26 12:45:29 -0400 | [diff] [blame] | 56 | auto spr = sk_make_sp<GrSmallPathRenderer>(); |
| 57 | context->contextPriv().addOnFlushCallbackObject(spr.get()); |
| 58 | fChain.push_back(std::move(spr)); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 59 | } |
Brian Osman | 8a9de3d | 2017-03-01 14:59:05 -0500 | [diff] [blame] | 60 | if (options.fGpuPathRenderers & GpuPathRenderers::kTessellating) { |
csmartdalton | 008b9d8 | 2017-02-22 12:00:42 -0700 | [diff] [blame] | 61 | fChain.push_back(sk_make_sp<GrTessellatingPathRenderer>()); |
| 62 | } |
Brian Osman | 8b0f265 | 2017-08-29 15:18:34 -0400 | [diff] [blame] | 63 | |
| 64 | // We always include the default path renderer (as well as SW), so we can draw any path |
| 65 | fChain.push_back(sk_make_sp<GrDefaultPathRenderer>()); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 66 | } |
| 67 | |
bsalomon | d6f25bf | 2016-05-05 09:26:21 -0700 | [diff] [blame] | 68 | GrPathRenderer* GrPathRendererChain::getPathRenderer( |
| 69 | const GrPathRenderer::CanDrawPathArgs& args, |
| 70 | DrawType drawType, |
| 71 | GrPathRenderer::StencilSupport* stencilSupport) { |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 72 | GR_STATIC_ASSERT(GrPathRenderer::kNoSupport_StencilSupport < |
| 73 | GrPathRenderer::kStencilOnly_StencilSupport); |
| 74 | GR_STATIC_ASSERT(GrPathRenderer::kStencilOnly_StencilSupport < |
| 75 | GrPathRenderer::kNoRestriction_StencilSupport); |
| 76 | GrPathRenderer::StencilSupport minStencilSupport; |
Brian Salomon | 82125e9 | 2016-12-10 09:35:48 -0500 | [diff] [blame] | 77 | if (DrawType::kStencil == drawType) { |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 78 | minStencilSupport = GrPathRenderer::kStencilOnly_StencilSupport; |
Brian Salomon | 82125e9 | 2016-12-10 09:35:48 -0500 | [diff] [blame] | 79 | } else if (DrawType::kStencilAndColor == drawType) { |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 80 | minStencilSupport = GrPathRenderer::kNoRestriction_StencilSupport; |
| 81 | } else { |
| 82 | minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport; |
| 83 | } |
bsalomon | d6f25bf | 2016-05-05 09:26:21 -0700 | [diff] [blame] | 84 | if (minStencilSupport != GrPathRenderer::kNoSupport_StencilSupport) { |
| 85 | // We don't support (and shouldn't need) stenciling of non-fill paths. |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 86 | if (!args.fShape->style().isSimpleFill()) { |
bsalomon | d6f25bf | 2016-05-05 09:26:21 -0700 | [diff] [blame] | 87 | return nullptr; |
| 88 | } |
| 89 | } |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 90 | |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 91 | GrPathRenderer* bestPathRenderer = nullptr; |
| 92 | for (const sk_sp<GrPathRenderer>& pr : fChain) { |
| 93 | GrPathRenderer::StencilSupport support = GrPathRenderer::kNoSupport_StencilSupport; |
| 94 | if (GrPathRenderer::kNoSupport_StencilSupport != minStencilSupport) { |
| 95 | support = pr->getStencilSupport(*args.fShape); |
| 96 | if (support < minStencilSupport) { |
| 97 | continue; |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 98 | } |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 99 | } |
| 100 | GrPathRenderer::CanDrawPath canDrawPath = pr->canDrawPath(args); |
| 101 | if (GrPathRenderer::CanDrawPath::kNo == canDrawPath) { |
| 102 | continue; |
| 103 | } |
| 104 | if (GrPathRenderer::CanDrawPath::kAsBackup == canDrawPath && bestPathRenderer) { |
| 105 | continue; |
| 106 | } |
| 107 | if (stencilSupport) { |
| 108 | *stencilSupport = support; |
| 109 | } |
| 110 | bestPathRenderer = pr.get(); |
| 111 | if (GrPathRenderer::CanDrawPath::kYes == canDrawPath) { |
| 112 | break; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 113 | } |
| 114 | } |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 115 | return bestPathRenderer; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 116 | } |