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( |
| 37 | GrStencilAndCoverPathRenderer::Create(context->resourceProvider(), caps)); |
| 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 | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 57 | context->contextPriv().addOnFlushCallbackObject(ccpr.get()); |
| 58 | fChain.push_back(std::move(ccpr)); |
| 59 | } |
| 60 | } |
csmartdalton | 008b9d8 | 2017-02-22 12:00:42 -0700 | [diff] [blame] | 61 | if (options.fGpuPathRenderers & GpuPathRenderers::kAAConvex) { |
| 62 | fChain.push_back(sk_make_sp<GrAAConvexPathRenderer>()); |
| 63 | } |
| 64 | if (options.fGpuPathRenderers & GpuPathRenderers::kAALinearizing) { |
| 65 | fChain.push_back(sk_make_sp<GrAALinearizingConvexPathRenderer>()); |
| 66 | } |
Jim Van Verth | 8301046 | 2017-03-16 08:45:39 -0400 | [diff] [blame] | 67 | if (options.fGpuPathRenderers & GpuPathRenderers::kSmall) { |
Jim Van Verth | 106b5c4 | 2017-09-26 12:45:29 -0400 | [diff] [blame] | 68 | auto spr = sk_make_sp<GrSmallPathRenderer>(); |
| 69 | context->contextPriv().addOnFlushCallbackObject(spr.get()); |
| 70 | fChain.push_back(std::move(spr)); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 71 | } |
Brian Osman | 8a9de3d | 2017-03-01 14:59:05 -0500 | [diff] [blame] | 72 | if (options.fGpuPathRenderers & GpuPathRenderers::kTessellating) { |
csmartdalton | 008b9d8 | 2017-02-22 12:00:42 -0700 | [diff] [blame] | 73 | fChain.push_back(sk_make_sp<GrTessellatingPathRenderer>()); |
| 74 | } |
Brian Osman | 8b0f265 | 2017-08-29 15:18:34 -0400 | [diff] [blame] | 75 | |
| 76 | // We always include the default path renderer (as well as SW), so we can draw any path |
| 77 | fChain.push_back(sk_make_sp<GrDefaultPathRenderer>()); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 78 | } |
| 79 | |
bsalomon | d6f25bf | 2016-05-05 09:26:21 -0700 | [diff] [blame] | 80 | GrPathRenderer* GrPathRendererChain::getPathRenderer( |
| 81 | const GrPathRenderer::CanDrawPathArgs& args, |
| 82 | DrawType drawType, |
| 83 | GrPathRenderer::StencilSupport* stencilSupport) { |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 84 | GR_STATIC_ASSERT(GrPathRenderer::kNoSupport_StencilSupport < |
| 85 | GrPathRenderer::kStencilOnly_StencilSupport); |
| 86 | GR_STATIC_ASSERT(GrPathRenderer::kStencilOnly_StencilSupport < |
| 87 | GrPathRenderer::kNoRestriction_StencilSupport); |
| 88 | GrPathRenderer::StencilSupport minStencilSupport; |
Brian Salomon | 82125e9 | 2016-12-10 09:35:48 -0500 | [diff] [blame] | 89 | if (DrawType::kStencil == drawType) { |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 90 | minStencilSupport = GrPathRenderer::kStencilOnly_StencilSupport; |
Brian Salomon | 82125e9 | 2016-12-10 09:35:48 -0500 | [diff] [blame] | 91 | } else if (DrawType::kStencilAndColor == drawType) { |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 92 | minStencilSupport = GrPathRenderer::kNoRestriction_StencilSupport; |
| 93 | } else { |
| 94 | minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport; |
| 95 | } |
bsalomon | d6f25bf | 2016-05-05 09:26:21 -0700 | [diff] [blame] | 96 | if (minStencilSupport != GrPathRenderer::kNoSupport_StencilSupport) { |
| 97 | // We don't support (and shouldn't need) stenciling of non-fill paths. |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 98 | if (!args.fShape->style().isSimpleFill()) { |
bsalomon | d6f25bf | 2016-05-05 09:26:21 -0700 | [diff] [blame] | 99 | return nullptr; |
| 100 | } |
| 101 | } |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 102 | |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 103 | GrPathRenderer* bestPathRenderer = nullptr; |
| 104 | for (const sk_sp<GrPathRenderer>& pr : fChain) { |
| 105 | GrPathRenderer::StencilSupport support = GrPathRenderer::kNoSupport_StencilSupport; |
| 106 | if (GrPathRenderer::kNoSupport_StencilSupport != minStencilSupport) { |
| 107 | support = pr->getStencilSupport(*args.fShape); |
| 108 | if (support < minStencilSupport) { |
| 109 | continue; |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 110 | } |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 111 | } |
| 112 | GrPathRenderer::CanDrawPath canDrawPath = pr->canDrawPath(args); |
| 113 | if (GrPathRenderer::CanDrawPath::kNo == canDrawPath) { |
| 114 | continue; |
| 115 | } |
| 116 | if (GrPathRenderer::CanDrawPath::kAsBackup == canDrawPath && bestPathRenderer) { |
| 117 | continue; |
| 118 | } |
| 119 | if (stencilSupport) { |
| 120 | *stencilSupport = support; |
| 121 | } |
| 122 | bestPathRenderer = pr.get(); |
| 123 | if (GrPathRenderer::CanDrawPath::kYes == canDrawPath) { |
| 124 | break; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 125 | } |
| 126 | } |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 127 | return bestPathRenderer; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 128 | } |