blob: ca2a7f02723a2e7f614a654bc0910320dfa5b4d3 [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"
bsalomoneb1cb5c2015-05-22 08:01:09 -070010#include "GrCaps.h"
Brian Salomon94efbf52016-11-29 13:43:05 -050011#include "GrShaderCaps.h"
bsalomon@google.com30085192011-08-19 15:42:31 +000012#include "GrContext.h"
Chris Dalton1a325d22017-07-14 15:17:41 -060013#include "GrContextPriv.h"
bsalomon@google.com30085192011-08-19 15:42:31 +000014#include "GrGpu.h"
Chris Dalton1a325d22017-07-14 15:17:41 -060015#include "ccpr/GrCoverageCountingPathRenderer.h"
Brian Salomon89527432016-12-16 09:52:16 -050016#include "ops/GrAAConvexPathRenderer.h"
Brian Salomon89527432016-12-16 09:52:16 -050017#include "ops/GrAAHairLinePathRenderer.h"
18#include "ops/GrAALinearizingConvexPathRenderer.h"
Jim Van Verth83010462017-03-16 08:45:39 -040019#include "ops/GrSmallPathRenderer.h"
Brian Salomon89527432016-12-16 09:52:16 -050020#include "ops/GrDashLinePathRenderer.h"
21#include "ops/GrDefaultPathRenderer.h"
Brian Salomon89527432016-12-16 09:52:16 -050022#include "ops/GrStencilAndCoverPathRenderer.h"
23#include "ops/GrTessellatingPathRenderer.h"
joshualitt0cffb172015-09-02 08:42:16 -070024
bsalomon6b2552f2016-09-15 13:50:26 -070025GrPathRendererChain::GrPathRendererChain(GrContext* context, const Options& options) {
Robert Phillips9da87e02019-02-04 13:26:26 -050026 const GrCaps& caps = *context->priv().caps();
csmartdalton008b9d82017-02-22 12:00:42 -070027 if (options.fGpuPathRenderers & GpuPathRenderers::kDashLine) {
28 fChain.push_back(sk_make_sp<GrDashLinePathRenderer>());
29 }
30 if (options.fGpuPathRenderers & GpuPathRenderers::kStencilAndCover) {
Robert Phillips6a6de562019-02-15 15:19:15 -050031 auto direct = context->priv().asDirectContext();
32 if (direct) {
33 auto resourceProvider = direct->priv().resourceProvider();
34
35 sk_sp<GrPathRenderer> pr(
36 GrStencilAndCoverPathRenderer::Create(resourceProvider, caps));
37 if (pr) {
38 fChain.push_back(std::move(pr));
39 }
bsalomon39ef7fb2016-09-21 11:16:05 -070040 }
csmartdalton008b9d82017-02-22 12:00:42 -070041 }
Chris Daltonc83571e2018-11-16 11:10:39 -050042 if (options.fGpuPathRenderers & GpuPathRenderers::kAAConvex) {
43 fChain.push_back(sk_make_sp<GrAAConvexPathRenderer>());
44 }
Chris Daltondb91c6e2017-09-08 16:25:08 -060045 if (options.fGpuPathRenderers & GpuPathRenderers::kCoverageCounting) {
Chris Daltona2b5b642018-06-24 13:08:57 -060046 using AllowCaching = GrCoverageCountingPathRenderer::AllowCaching;
47 if (auto ccpr = GrCoverageCountingPathRenderer::CreateIfSupported(
Chris Dalton351e80c2019-01-06 22:51:00 -070048 caps, AllowCaching(options.fAllowPathMaskCaching),
Robert Phillips9da87e02019-02-04 13:26:26 -050049 context->priv().contextID())) {
Chris Daltonfddb6c02017-11-04 15:22:22 -060050 fCoverageCountingPathRenderer = ccpr.get();
Robert Phillips9da87e02019-02-04 13:26:26 -050051 context->priv().addOnFlushCallbackObject(fCoverageCountingPathRenderer);
Chris Daltondb91c6e2017-09-08 16:25:08 -060052 fChain.push_back(std::move(ccpr));
53 }
54 }
Chris Dalton9acfc6c2018-07-26 12:34:49 -060055 if (options.fGpuPathRenderers & GpuPathRenderers::kAAHairline) {
56 fChain.push_back(sk_make_sp<GrAAHairLinePathRenderer>());
57 }
csmartdalton008b9d82017-02-22 12:00:42 -070058 if (options.fGpuPathRenderers & GpuPathRenderers::kAALinearizing) {
59 fChain.push_back(sk_make_sp<GrAALinearizingConvexPathRenderer>());
60 }
Jim Van Verth83010462017-03-16 08:45:39 -040061 if (options.fGpuPathRenderers & GpuPathRenderers::kSmall) {
Jim Van Verth106b5c42017-09-26 12:45:29 -040062 auto spr = sk_make_sp<GrSmallPathRenderer>();
Robert Phillips9da87e02019-02-04 13:26:26 -050063 context->priv().addOnFlushCallbackObject(spr.get());
Jim Van Verth106b5c42017-09-26 12:45:29 -040064 fChain.push_back(std::move(spr));
bsalomon@google.com30085192011-08-19 15:42:31 +000065 }
Brian Osman8a9de3d2017-03-01 14:59:05 -050066 if (options.fGpuPathRenderers & GpuPathRenderers::kTessellating) {
csmartdalton008b9d82017-02-22 12:00:42 -070067 fChain.push_back(sk_make_sp<GrTessellatingPathRenderer>());
68 }
Brian Osman8b0f2652017-08-29 15:18:34 -040069
70 // We always include the default path renderer (as well as SW), so we can draw any path
71 fChain.push_back(sk_make_sp<GrDefaultPathRenderer>());
bsalomon@google.com30085192011-08-19 15:42:31 +000072}
73
bsalomond6f25bf2016-05-05 09:26:21 -070074GrPathRenderer* GrPathRendererChain::getPathRenderer(
75 const GrPathRenderer::CanDrawPathArgs& args,
76 DrawType drawType,
77 GrPathRenderer::StencilSupport* stencilSupport) {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000078 GR_STATIC_ASSERT(GrPathRenderer::kNoSupport_StencilSupport <
79 GrPathRenderer::kStencilOnly_StencilSupport);
80 GR_STATIC_ASSERT(GrPathRenderer::kStencilOnly_StencilSupport <
81 GrPathRenderer::kNoRestriction_StencilSupport);
82 GrPathRenderer::StencilSupport minStencilSupport;
Brian Salomon82125e92016-12-10 09:35:48 -050083 if (DrawType::kStencil == drawType) {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000084 minStencilSupport = GrPathRenderer::kStencilOnly_StencilSupport;
Brian Salomon82125e92016-12-10 09:35:48 -050085 } else if (DrawType::kStencilAndColor == drawType) {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000086 minStencilSupport = GrPathRenderer::kNoRestriction_StencilSupport;
87 } else {
88 minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport;
89 }
bsalomond6f25bf2016-05-05 09:26:21 -070090 if (minStencilSupport != GrPathRenderer::kNoSupport_StencilSupport) {
91 // We don't support (and shouldn't need) stenciling of non-fill paths.
bsalomon8acedde2016-06-24 10:42:16 -070092 if (!args.fShape->style().isSimpleFill()) {
bsalomond6f25bf2016-05-05 09:26:21 -070093 return nullptr;
94 }
95 }
bsalomon@google.com45a15f52012-12-10 19:10:17 +000096
Chris Dalton5ed44232017-09-07 13:22:46 -060097 GrPathRenderer* bestPathRenderer = nullptr;
98 for (const sk_sp<GrPathRenderer>& pr : fChain) {
99 GrPathRenderer::StencilSupport support = GrPathRenderer::kNoSupport_StencilSupport;
100 if (GrPathRenderer::kNoSupport_StencilSupport != minStencilSupport) {
101 support = pr->getStencilSupport(*args.fShape);
102 if (support < minStencilSupport) {
103 continue;
bsalomon@google.com45a15f52012-12-10 19:10:17 +0000104 }
Chris Dalton5ed44232017-09-07 13:22:46 -0600105 }
106 GrPathRenderer::CanDrawPath canDrawPath = pr->canDrawPath(args);
107 if (GrPathRenderer::CanDrawPath::kNo == canDrawPath) {
108 continue;
109 }
110 if (GrPathRenderer::CanDrawPath::kAsBackup == canDrawPath && bestPathRenderer) {
111 continue;
112 }
113 if (stencilSupport) {
114 *stencilSupport = support;
115 }
116 bestPathRenderer = pr.get();
117 if (GrPathRenderer::CanDrawPath::kYes == canDrawPath) {
118 break;
bsalomon@google.com30085192011-08-19 15:42:31 +0000119 }
120 }
Chris Dalton5ed44232017-09-07 13:22:46 -0600121 return bestPathRenderer;
bsalomon@google.com30085192011-08-19 15:42:31 +0000122}