blob: 8f13bf60edf423e2ee2b09dda683267e4b1188bc [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05009#include "src/gpu/GrPathRendererChain.h"
Robert Phillips69893702019-02-22 11:16:30 -050010
Robert Phillipsb7bfbc22020-07-01 12:55:01 -040011#include "include/gpu/GrDirectContext.h"
12#include "include/gpu/GrRecordingContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "src/gpu/GrCaps.h"
Adlai Hollera0693042020-10-14 11:23:11 -040014#include "src/gpu/GrDirectContextPriv.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050015#include "src/gpu/GrGpu.h"
16#include "src/gpu/GrRecordingContextPriv.h"
17#include "src/gpu/GrShaderCaps.h"
Robert Phillips5dd3d882020-08-10 09:29:39 -040018#include "src/gpu/geometry/GrStyledShape.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050019#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 Dalton17dc4182020-03-25 16:18:16 -060025#include "src/gpu/ops/GrTriangulatingPathRenderer.h"
Chris Dalton0a22b1e2020-03-26 11:52:15 -060026#include "src/gpu/tessellate/GrTessellationPathRenderer.h"
joshualitt0cffb172015-09-02 08:42:16 -070027
Robert Phillips69893702019-02-22 11:16:30 -050028GrPathRendererChain::GrPathRendererChain(GrRecordingContext* context, const Options& options) {
Robert Phillips9da87e02019-02-04 13:26:26 -050029 const GrCaps& caps = *context->priv().caps();
csmartdalton008b9d82017-02-22 12:00:42 -070030 if (options.fGpuPathRenderers & GpuPathRenderers::kDashLine) {
31 fChain.push_back(sk_make_sp<GrDashLinePathRenderer>());
32 }
Chris Daltonc83571e2018-11-16 11:10:39 -050033 if (options.fGpuPathRenderers & GpuPathRenderers::kAAConvex) {
34 fChain.push_back(sk_make_sp<GrAAConvexPathRenderer>());
35 }
Chris Dalton9acfc6c2018-07-26 12:34:49 -060036 if (options.fGpuPathRenderers & GpuPathRenderers::kAAHairline) {
37 fChain.push_back(sk_make_sp<GrAAHairLinePathRenderer>());
38 }
csmartdalton008b9d82017-02-22 12:00:42 -070039 if (options.fGpuPathRenderers & GpuPathRenderers::kAALinearizing) {
40 fChain.push_back(sk_make_sp<GrAALinearizingConvexPathRenderer>());
41 }
Jim Van Verth83010462017-03-16 08:45:39 -040042 if (options.fGpuPathRenderers & GpuPathRenderers::kSmall) {
Robert Phillips079455c2020-08-11 15:18:46 -040043 fChain.push_back(sk_make_sp<GrSmallPathRenderer>());
bsalomon@google.com30085192011-08-19 15:42:31 +000044 }
Chris Dalton17dc4182020-03-25 16:18:16 -060045 if (options.fGpuPathRenderers & GpuPathRenderers::kTriangulating) {
46 fChain.push_back(sk_make_sp<GrTriangulatingPathRenderer>());
csmartdalton008b9d82017-02-22 12:00:42 -070047 }
Chris Daltoneae5c162020-12-29 10:18:21 -070048 if (options.fGpuPathRenderers & GpuPathRenderers::kTessellation) {
49 if (GrTessellationPathRenderer::IsSupported(caps)) {
50 auto tess = sk_make_sp<GrTessellationPathRenderer>(context);
Chris Daltone6ae4762021-02-05 14:56:21 -070051 fTessellationPathRenderer = tess.get();
Chris Daltoneae5c162020-12-29 10:18:21 -070052 context->priv().addOnFlushCallbackObject(tess.get());
53 fChain.push_back(std::move(tess));
54 }
55 }
Brian Osman8b0f2652017-08-29 15:18:34 -040056
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.com30085192011-08-19 15:42:31 +000059}
60
bsalomond6f25bf2016-05-05 09:26:21 -070061GrPathRenderer* GrPathRendererChain::getPathRenderer(
62 const GrPathRenderer::CanDrawPathArgs& args,
63 DrawType drawType,
64 GrPathRenderer::StencilSupport* stencilSupport) {
Brian Salomon4dea72a2019-12-18 10:43:10 -050065 static_assert(GrPathRenderer::kNoSupport_StencilSupport <
66 GrPathRenderer::kStencilOnly_StencilSupport);
67 static_assert(GrPathRenderer::kStencilOnly_StencilSupport <
68 GrPathRenderer::kNoRestriction_StencilSupport);
bsalomon@google.com45a15f52012-12-10 19:10:17 +000069 GrPathRenderer::StencilSupport minStencilSupport;
Brian Salomon82125e92016-12-10 09:35:48 -050070 if (DrawType::kStencil == drawType) {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000071 minStencilSupport = GrPathRenderer::kStencilOnly_StencilSupport;
Brian Salomon82125e92016-12-10 09:35:48 -050072 } else if (DrawType::kStencilAndColor == drawType) {
bsalomon@google.com45a15f52012-12-10 19:10:17 +000073 minStencilSupport = GrPathRenderer::kNoRestriction_StencilSupport;
74 } else {
75 minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport;
76 }
bsalomond6f25bf2016-05-05 09:26:21 -070077 if (minStencilSupport != GrPathRenderer::kNoSupport_StencilSupport) {
78 // We don't support (and shouldn't need) stenciling of non-fill paths.
bsalomon8acedde2016-06-24 10:42:16 -070079 if (!args.fShape->style().isSimpleFill()) {
bsalomond6f25bf2016-05-05 09:26:21 -070080 return nullptr;
81 }
82 }
bsalomon@google.com45a15f52012-12-10 19:10:17 +000083
Chris Dalton5ed44232017-09-07 13:22:46 -060084 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.com45a15f52012-12-10 19:10:17 +000091 }
Chris Dalton5ed44232017-09-07 13:22:46 -060092 }
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.com30085192011-08-19 15:42:31 +0000106 }
107 }
Chris Dalton5ed44232017-09-07 13:22:46 -0600108 return bestPathRenderer;
bsalomon@google.com30085192011-08-19 15:42:31 +0000109}