blob: 3bb744afab3c8a85f9e9432b48f295b4b72d1277 [file] [log] [blame]
bsalomon@google.com30085192011-08-19 15:42:31 +00001/*
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
bsalomoneb1cb5c2015-05-22 08:01:09 -070011#include "GrCaps.h"
Brian Salomon94efbf52016-11-29 13:43:05 -050012#include "GrShaderCaps.h"
ethannicholas22793252016-01-30 09:59:10 -080013#include "gl/GrGLCaps.h"
bsalomon@google.com30085192011-08-19 15:42:31 +000014#include "GrContext.h"
Chris Dalton1a325d22017-07-14 15:17:41 -060015#include "GrContextPriv.h"
bsalomon@google.com30085192011-08-19 15:42:31 +000016#include "GrGpu.h"
17
Chris Dalton1a325d22017-07-14 15:17:41 -060018#include "ccpr/GrCoverageCountingPathRenderer.h"
19
Brian Salomon89527432016-12-16 09:52:16 -050020#include "ops/GrAAConvexPathRenderer.h"
Brian Salomon89527432016-12-16 09:52:16 -050021#include "ops/GrAAHairLinePathRenderer.h"
22#include "ops/GrAALinearizingConvexPathRenderer.h"
Jim Van Verth83010462017-03-16 08:45:39 -040023#include "ops/GrSmallPathRenderer.h"
Brian Salomon89527432016-12-16 09:52:16 -050024#include "ops/GrDashLinePathRenderer.h"
25#include "ops/GrDefaultPathRenderer.h"
26#include "ops/GrMSAAPathRenderer.h"
Brian Salomon89527432016-12-16 09:52:16 -050027#include "ops/GrStencilAndCoverPathRenderer.h"
28#include "ops/GrTessellatingPathRenderer.h"
joshualitt0cffb172015-09-02 08:42:16 -070029
bsalomon6b2552f2016-09-15 13:50:26 -070030GrPathRendererChain::GrPathRendererChain(GrContext* context, const Options& options) {
csmartdalton008b9d82017-02-22 12:00:42 -070031 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));
bsalomon39ef7fb2016-09-21 11:16:05 -070040 }
csmartdalton008b9d82017-02-22 12:00:42 -070041 }
42#ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK
43 if (options.fGpuPathRenderers & GpuPathRenderers::kMSAA) {
Stephan White021f9272017-01-03 21:06:16 +000044 if (caps.sampleShadingSupport()) {
csmartdalton008b9d82017-02-22 12:00:42 -070045 fChain.push_back(sk_make_sp<GrMSAAPathRenderer>());
Stephan White021f9272017-01-03 21:06:16 +000046 }
csmartdalton008b9d82017-02-22 12:00:42 -070047 }
48#endif
Brian Osmanc0e66272017-08-30 14:41:12 -040049
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 Daltondb91c6e2017-09-08 16:25:08 -060053 if (options.fGpuPathRenderers & GpuPathRenderers::kCoverageCounting) {
Chris Daltona2ac30d2017-10-17 10:40:01 -060054 bool drawCachablePaths = !options.fAllowPathMaskCaching;
55 if (auto ccpr = GrCoverageCountingPathRenderer::CreateIfSupported(*context->caps(),
56 drawCachablePaths)) {
Chris Daltondb91c6e2017-09-08 16:25:08 -060057 context->contextPriv().addOnFlushCallbackObject(ccpr.get());
58 fChain.push_back(std::move(ccpr));
59 }
60 }
csmartdalton008b9d82017-02-22 12:00:42 -070061 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 Verth83010462017-03-16 08:45:39 -040067 if (options.fGpuPathRenderers & GpuPathRenderers::kSmall) {
Jim Van Verth106b5c42017-09-26 12:45:29 -040068 auto spr = sk_make_sp<GrSmallPathRenderer>();
69 context->contextPriv().addOnFlushCallbackObject(spr.get());
70 fChain.push_back(std::move(spr));
bsalomon@google.com30085192011-08-19 15:42:31 +000071 }
Brian Osman8a9de3d2017-03-01 14:59:05 -050072 if (options.fGpuPathRenderers & GpuPathRenderers::kTessellating) {
csmartdalton008b9d82017-02-22 12:00:42 -070073 fChain.push_back(sk_make_sp<GrTessellatingPathRenderer>());
74 }
Brian Osman8b0f2652017-08-29 15:18:34 -040075
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.com30085192011-08-19 15:42:31 +000078}
79
bsalomond6f25bf2016-05-05 09:26:21 -070080GrPathRenderer* GrPathRendererChain::getPathRenderer(
81 const GrPathRenderer::CanDrawPathArgs& args,
82 DrawType drawType,
83 GrPathRenderer::StencilSupport* stencilSupport) {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000084 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 Salomon82125e92016-12-10 09:35:48 -050089 if (DrawType::kStencil == drawType) {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000090 minStencilSupport = GrPathRenderer::kStencilOnly_StencilSupport;
Brian Salomon82125e92016-12-10 09:35:48 -050091 } else if (DrawType::kStencilAndColor == drawType) {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000092 minStencilSupport = GrPathRenderer::kNoRestriction_StencilSupport;
93 } else {
94 minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport;
95 }
bsalomond6f25bf2016-05-05 09:26:21 -070096 if (minStencilSupport != GrPathRenderer::kNoSupport_StencilSupport) {
97 // We don't support (and shouldn't need) stenciling of non-fill paths.
bsalomon8acedde2016-06-24 10:42:16 -070098 if (!args.fShape->style().isSimpleFill()) {
bsalomond6f25bf2016-05-05 09:26:21 -070099 return nullptr;
100 }
101 }
bsalomon@google.com45a15f52012-12-10 19:10:17 +0000102
Chris Dalton5ed44232017-09-07 13:22:46 -0600103 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.com45a15f52012-12-10 19:10:17 +0000110 }
Chris Dalton5ed44232017-09-07 13:22:46 -0600111 }
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.com30085192011-08-19 15:42:31 +0000125 }
126 }
Chris Dalton5ed44232017-09-07 13:22:46 -0600127 return bestPathRenderer;
bsalomon@google.com30085192011-08-19 15:42:31 +0000128}