blob: a6ad51302225c14f943787b9b2e17c0a7ac44cdc [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) {
Brian Salomonc7fe0f72018-05-11 10:14:21 -040026 const GrCaps& caps = *context->contextPriv().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) {
31 sk_sp<GrPathRenderer> pr(
Robert Phillips6be756b2018-01-16 15:07:54 -050032 GrStencilAndCoverPathRenderer::Create(context->contextPriv().resourceProvider(), caps));
csmartdalton008b9d82017-02-22 12:00:42 -070033 if (pr) {
34 fChain.push_back(std::move(pr));
bsalomon39ef7fb2016-09-21 11:16:05 -070035 }
csmartdalton008b9d82017-02-22 12:00:42 -070036 }
Chris Daltonc83571e2018-11-16 11:10:39 -050037 if (options.fGpuPathRenderers & GpuPathRenderers::kAAConvex) {
38 fChain.push_back(sk_make_sp<GrAAConvexPathRenderer>());
39 }
Chris Daltondb91c6e2017-09-08 16:25:08 -060040 if (options.fGpuPathRenderers & GpuPathRenderers::kCoverageCounting) {
Chris Daltona2b5b642018-06-24 13:08:57 -060041 using AllowCaching = GrCoverageCountingPathRenderer::AllowCaching;
42 if (auto ccpr = GrCoverageCountingPathRenderer::CreateIfSupported(
Chris Dalton8429c792018-10-23 15:56:22 -060043 caps, AllowCaching(options.fAllowPathMaskCaching))) {
Chris Daltonfddb6c02017-11-04 15:22:22 -060044 fCoverageCountingPathRenderer = ccpr.get();
45 context->contextPriv().addOnFlushCallbackObject(fCoverageCountingPathRenderer);
Chris Daltondb91c6e2017-09-08 16:25:08 -060046 fChain.push_back(std::move(ccpr));
47 }
48 }
Chris Dalton9acfc6c2018-07-26 12:34:49 -060049 if (options.fGpuPathRenderers & GpuPathRenderers::kAAHairline) {
50 fChain.push_back(sk_make_sp<GrAAHairLinePathRenderer>());
51 }
csmartdalton008b9d82017-02-22 12:00:42 -070052 if (options.fGpuPathRenderers & GpuPathRenderers::kAALinearizing) {
53 fChain.push_back(sk_make_sp<GrAALinearizingConvexPathRenderer>());
54 }
Jim Van Verth83010462017-03-16 08:45:39 -040055 if (options.fGpuPathRenderers & GpuPathRenderers::kSmall) {
Jim Van Verth106b5c42017-09-26 12:45:29 -040056 auto spr = sk_make_sp<GrSmallPathRenderer>();
57 context->contextPriv().addOnFlushCallbackObject(spr.get());
58 fChain.push_back(std::move(spr));
bsalomon@google.com30085192011-08-19 15:42:31 +000059 }
Brian Osman8a9de3d2017-03-01 14:59:05 -050060 if (options.fGpuPathRenderers & GpuPathRenderers::kTessellating) {
csmartdalton008b9d82017-02-22 12:00:42 -070061 fChain.push_back(sk_make_sp<GrTessellatingPathRenderer>());
62 }
Brian Osman8b0f2652017-08-29 15:18:34 -040063
64 // We always include the default path renderer (as well as SW), so we can draw any path
65 fChain.push_back(sk_make_sp<GrDefaultPathRenderer>());
bsalomon@google.com30085192011-08-19 15:42:31 +000066}
67
bsalomond6f25bf2016-05-05 09:26:21 -070068GrPathRenderer* GrPathRendererChain::getPathRenderer(
69 const GrPathRenderer::CanDrawPathArgs& args,
70 DrawType drawType,
71 GrPathRenderer::StencilSupport* stencilSupport) {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000072 GR_STATIC_ASSERT(GrPathRenderer::kNoSupport_StencilSupport <
73 GrPathRenderer::kStencilOnly_StencilSupport);
74 GR_STATIC_ASSERT(GrPathRenderer::kStencilOnly_StencilSupport <
75 GrPathRenderer::kNoRestriction_StencilSupport);
76 GrPathRenderer::StencilSupport minStencilSupport;
Brian Salomon82125e92016-12-10 09:35:48 -050077 if (DrawType::kStencil == drawType) {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000078 minStencilSupport = GrPathRenderer::kStencilOnly_StencilSupport;
Brian Salomon82125e92016-12-10 09:35:48 -050079 } else if (DrawType::kStencilAndColor == drawType) {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000080 minStencilSupport = GrPathRenderer::kNoRestriction_StencilSupport;
81 } else {
82 minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport;
83 }
bsalomond6f25bf2016-05-05 09:26:21 -070084 if (minStencilSupport != GrPathRenderer::kNoSupport_StencilSupport) {
85 // We don't support (and shouldn't need) stenciling of non-fill paths.
bsalomon8acedde2016-06-24 10:42:16 -070086 if (!args.fShape->style().isSimpleFill()) {
bsalomond6f25bf2016-05-05 09:26:21 -070087 return nullptr;
88 }
89 }
bsalomon@google.com45a15f52012-12-10 19:10:17 +000090
Chris Dalton5ed44232017-09-07 13:22:46 -060091 GrPathRenderer* bestPathRenderer = nullptr;
92 for (const sk_sp<GrPathRenderer>& pr : fChain) {
93 GrPathRenderer::StencilSupport support = GrPathRenderer::kNoSupport_StencilSupport;
94 if (GrPathRenderer::kNoSupport_StencilSupport != minStencilSupport) {
95 support = pr->getStencilSupport(*args.fShape);
96 if (support < minStencilSupport) {
97 continue;
bsalomon@google.com45a15f52012-12-10 19:10:17 +000098 }
Chris Dalton5ed44232017-09-07 13:22:46 -060099 }
100 GrPathRenderer::CanDrawPath canDrawPath = pr->canDrawPath(args);
101 if (GrPathRenderer::CanDrawPath::kNo == canDrawPath) {
102 continue;
103 }
104 if (GrPathRenderer::CanDrawPath::kAsBackup == canDrawPath && bestPathRenderer) {
105 continue;
106 }
107 if (stencilSupport) {
108 *stencilSupport = support;
109 }
110 bestPathRenderer = pr.get();
111 if (GrPathRenderer::CanDrawPath::kYes == canDrawPath) {
112 break;
bsalomon@google.com30085192011-08-19 15:42:31 +0000113 }
114 }
Chris Dalton5ed44232017-09-07 13:22:46 -0600115 return bestPathRenderer;
bsalomon@google.com30085192011-08-19 15:42:31 +0000116}