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 | |
Robert Phillips | b7bfbc2 | 2020-07-01 12:55:01 -0400 | [diff] [blame] | 11 | #include "include/gpu/GrDirectContext.h" |
| 12 | #include "include/gpu/GrRecordingContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "src/gpu/GrCaps.h" |
Adlai Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 14 | #include "src/gpu/GrDirectContextPriv.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 15 | #include "src/gpu/GrGpu.h" |
| 16 | #include "src/gpu/GrRecordingContextPriv.h" |
| 17 | #include "src/gpu/GrShaderCaps.h" |
Robert Phillips | 5dd3d88 | 2020-08-10 09:29:39 -0400 | [diff] [blame] | 18 | #include "src/gpu/geometry/GrStyledShape.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 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" |
Chris Dalton | 17dc418 | 2020-03-25 16:18:16 -0600 | [diff] [blame] | 25 | #include "src/gpu/ops/GrTriangulatingPathRenderer.h" |
Chris Dalton | 0a22b1e | 2020-03-26 11:52:15 -0600 | [diff] [blame] | 26 | #include "src/gpu/tessellate/GrTessellationPathRenderer.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 | 9acfc6c | 2018-07-26 12:34:49 -0600 | [diff] [blame] | 36 | if (options.fGpuPathRenderers & GpuPathRenderers::kAAHairline) { |
| 37 | fChain.push_back(sk_make_sp<GrAAHairLinePathRenderer>()); |
| 38 | } |
csmartdalton | 008b9d8 | 2017-02-22 12:00:42 -0700 | [diff] [blame] | 39 | if (options.fGpuPathRenderers & GpuPathRenderers::kAALinearizing) { |
| 40 | fChain.push_back(sk_make_sp<GrAALinearizingConvexPathRenderer>()); |
| 41 | } |
Jim Van Verth | 8301046 | 2017-03-16 08:45:39 -0400 | [diff] [blame] | 42 | if (options.fGpuPathRenderers & GpuPathRenderers::kSmall) { |
Robert Phillips | 079455c | 2020-08-11 15:18:46 -0400 | [diff] [blame] | 43 | fChain.push_back(sk_make_sp<GrSmallPathRenderer>()); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 44 | } |
Chris Dalton | 17dc418 | 2020-03-25 16:18:16 -0600 | [diff] [blame] | 45 | if (options.fGpuPathRenderers & GpuPathRenderers::kTriangulating) { |
| 46 | fChain.push_back(sk_make_sp<GrTriangulatingPathRenderer>()); |
csmartdalton | 008b9d8 | 2017-02-22 12:00:42 -0700 | [diff] [blame] | 47 | } |
Chris Dalton | eae5c16 | 2020-12-29 10:18:21 -0700 | [diff] [blame] | 48 | if (options.fGpuPathRenderers & GpuPathRenderers::kTessellation) { |
| 49 | if (GrTessellationPathRenderer::IsSupported(caps)) { |
| 50 | auto tess = sk_make_sp<GrTessellationPathRenderer>(context); |
Chris Dalton | e6ae476 | 2021-02-05 14:56:21 -0700 | [diff] [blame] | 51 | fTessellationPathRenderer = tess.get(); |
Chris Dalton | eae5c16 | 2020-12-29 10:18:21 -0700 | [diff] [blame] | 52 | context->priv().addOnFlushCallbackObject(tess.get()); |
| 53 | fChain.push_back(std::move(tess)); |
| 54 | } |
| 55 | } |
Brian Osman | 8b0f265 | 2017-08-29 15:18:34 -0400 | [diff] [blame] | 56 | |
| 57 | // We always include the default path renderer (as well as SW), so we can draw any path |
| 58 | fChain.push_back(sk_make_sp<GrDefaultPathRenderer>()); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 59 | } |
| 60 | |
bsalomon | d6f25bf | 2016-05-05 09:26:21 -0700 | [diff] [blame] | 61 | GrPathRenderer* GrPathRendererChain::getPathRenderer( |
| 62 | const GrPathRenderer::CanDrawPathArgs& args, |
| 63 | DrawType drawType, |
| 64 | GrPathRenderer::StencilSupport* stencilSupport) { |
Brian Salomon | 4dea72a | 2019-12-18 10:43:10 -0500 | [diff] [blame] | 65 | static_assert(GrPathRenderer::kNoSupport_StencilSupport < |
| 66 | GrPathRenderer::kStencilOnly_StencilSupport); |
| 67 | static_assert(GrPathRenderer::kStencilOnly_StencilSupport < |
| 68 | GrPathRenderer::kNoRestriction_StencilSupport); |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 69 | GrPathRenderer::StencilSupport minStencilSupport; |
Brian Salomon | 82125e9 | 2016-12-10 09:35:48 -0500 | [diff] [blame] | 70 | if (DrawType::kStencil == drawType) { |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 71 | minStencilSupport = GrPathRenderer::kStencilOnly_StencilSupport; |
Brian Salomon | 82125e9 | 2016-12-10 09:35:48 -0500 | [diff] [blame] | 72 | } else if (DrawType::kStencilAndColor == drawType) { |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 73 | minStencilSupport = GrPathRenderer::kNoRestriction_StencilSupport; |
| 74 | } else { |
| 75 | minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport; |
| 76 | } |
bsalomon | d6f25bf | 2016-05-05 09:26:21 -0700 | [diff] [blame] | 77 | if (minStencilSupport != GrPathRenderer::kNoSupport_StencilSupport) { |
| 78 | // We don't support (and shouldn't need) stenciling of non-fill paths. |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 79 | if (!args.fShape->style().isSimpleFill()) { |
bsalomon | d6f25bf | 2016-05-05 09:26:21 -0700 | [diff] [blame] | 80 | return nullptr; |
| 81 | } |
| 82 | } |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 83 | |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 84 | GrPathRenderer* bestPathRenderer = nullptr; |
| 85 | for (const sk_sp<GrPathRenderer>& pr : fChain) { |
| 86 | GrPathRenderer::StencilSupport support = GrPathRenderer::kNoSupport_StencilSupport; |
| 87 | if (GrPathRenderer::kNoSupport_StencilSupport != minStencilSupport) { |
| 88 | support = pr->getStencilSupport(*args.fShape); |
| 89 | if (support < minStencilSupport) { |
| 90 | continue; |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 91 | } |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 92 | } |
| 93 | GrPathRenderer::CanDrawPath canDrawPath = pr->canDrawPath(args); |
| 94 | if (GrPathRenderer::CanDrawPath::kNo == canDrawPath) { |
| 95 | continue; |
| 96 | } |
| 97 | if (GrPathRenderer::CanDrawPath::kAsBackup == canDrawPath && bestPathRenderer) { |
| 98 | continue; |
| 99 | } |
| 100 | if (stencilSupport) { |
| 101 | *stencilSupport = support; |
| 102 | } |
| 103 | bestPathRenderer = pr.get(); |
| 104 | if (GrPathRenderer::CanDrawPath::kYes == canDrawPath) { |
| 105 | break; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 106 | } |
| 107 | } |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 108 | return bestPathRenderer; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 109 | } |