• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "src/gpu/GrPathRendererChain.h"
10 
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"
27 
GrPathRendererChain(GrRecordingContext * context,const Options & options)28 GrPathRendererChain::GrPathRendererChain(GrRecordingContext* context, const Options& options) {
29     const GrCaps& caps = *context->priv().caps();
30     if (options.fGpuPathRenderers & GpuPathRenderers::kDashLine) {
31         fChain.push_back(sk_make_sp<GrDashLinePathRenderer>());
32     }
33     if (options.fGpuPathRenderers & GpuPathRenderers::kAAConvex) {
34         fChain.push_back(sk_make_sp<GrAAConvexPathRenderer>());
35     }
36     if (options.fGpuPathRenderers & GpuPathRenderers::kCoverageCounting) {
37         using AllowCaching = GrCoverageCountingPathRenderer::AllowCaching;
38         if (auto ccpr = GrCoverageCountingPathRenderer::CreateIfSupported(
39                                 caps, AllowCaching(options.fAllowPathMaskCaching),
40                                 context->priv().contextID())) {
41             fCoverageCountingPathRenderer = ccpr.get();
42             context->priv().addOnFlushCallbackObject(fCoverageCountingPathRenderer);
43             fChain.push_back(std::move(ccpr));
44         }
45     }
46     if (options.fGpuPathRenderers & GpuPathRenderers::kAAHairline) {
47         fChain.push_back(sk_make_sp<GrAAHairLinePathRenderer>());
48     }
49     if (options.fGpuPathRenderers & GpuPathRenderers::kAALinearizing) {
50         fChain.push_back(sk_make_sp<GrAALinearizingConvexPathRenderer>());
51     }
52     if (options.fGpuPathRenderers & GpuPathRenderers::kSmall) {
53         auto spr = sk_make_sp<GrSmallPathRenderer>();
54         context->priv().addOnFlushCallbackObject(spr.get());
55         fChain.push_back(std::move(spr));
56     }
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     }
69     if (options.fGpuPathRenderers & GpuPathRenderers::kTessellating) {
70         fChain.push_back(sk_make_sp<GrTessellatingPathRenderer>());
71     }
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>());
75 }
76 
getPathRenderer(const GrPathRenderer::CanDrawPathArgs & args,DrawType drawType,GrPathRenderer::StencilSupport * stencilSupport)77 GrPathRenderer* GrPathRendererChain::getPathRenderer(
78         const GrPathRenderer::CanDrawPathArgs& args,
79         DrawType drawType,
80         GrPathRenderer::StencilSupport* stencilSupport) {
81     GR_STATIC_ASSERT(GrPathRenderer::kNoSupport_StencilSupport <
82                      GrPathRenderer::kStencilOnly_StencilSupport);
83     GR_STATIC_ASSERT(GrPathRenderer::kStencilOnly_StencilSupport <
84                      GrPathRenderer::kNoRestriction_StencilSupport);
85     GrPathRenderer::StencilSupport minStencilSupport;
86     if (DrawType::kStencil == drawType) {
87         minStencilSupport = GrPathRenderer::kStencilOnly_StencilSupport;
88     } else if (DrawType::kStencilAndColor == drawType) {
89         minStencilSupport = GrPathRenderer::kNoRestriction_StencilSupport;
90     } else {
91         minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport;
92     }
93     if (minStencilSupport != GrPathRenderer::kNoSupport_StencilSupport) {
94         // We don't support (and shouldn't need) stenciling of non-fill paths.
95         if (!args.fShape->style().isSimpleFill()) {
96             return nullptr;
97         }
98     }
99 
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;
107             }
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;
122         }
123     }
124     return bestPathRenderer;
125 }
126