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