blob: ea259dcab62d24f6a8a0978808052a432bb9de1b [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"
Chris Daltonc3176002021-07-23 15:33:09 -060022#include "src/gpu/ops/GrAtlasPathRenderer.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050023#include "src/gpu/ops/GrDashLinePathRenderer.h"
24#include "src/gpu/ops/GrDefaultPathRenderer.h"
25#include "src/gpu/ops/GrSmallPathRenderer.h"
Chris Dalton17dc4182020-03-25 16:18:16 -060026#include "src/gpu/ops/GrTriangulatingPathRenderer.h"
Chris Dalton0a22b1e2020-03-26 11:52:15 -060027#include "src/gpu/tessellate/GrTessellationPathRenderer.h"
joshualitt0cffb172015-09-02 08:42:16 -070028
Robert Phillips69893702019-02-22 11:16:30 -050029GrPathRendererChain::GrPathRendererChain(GrRecordingContext* context, const Options& options) {
Robert Phillips9da87e02019-02-04 13:26:26 -050030 const GrCaps& caps = *context->priv().caps();
csmartdalton008b9d82017-02-22 12:00:42 -070031 if (options.fGpuPathRenderers & GpuPathRenderers::kDashLine) {
32 fChain.push_back(sk_make_sp<GrDashLinePathRenderer>());
33 }
Chris Daltonc83571e2018-11-16 11:10:39 -050034 if (options.fGpuPathRenderers & GpuPathRenderers::kAAConvex) {
35 fChain.push_back(sk_make_sp<GrAAConvexPathRenderer>());
36 }
Chris Dalton9acfc6c2018-07-26 12:34:49 -060037 if (options.fGpuPathRenderers & GpuPathRenderers::kAAHairline) {
38 fChain.push_back(sk_make_sp<GrAAHairLinePathRenderer>());
39 }
csmartdalton008b9d82017-02-22 12:00:42 -070040 if (options.fGpuPathRenderers & GpuPathRenderers::kAALinearizing) {
41 fChain.push_back(sk_make_sp<GrAALinearizingConvexPathRenderer>());
42 }
Chris Daltonc3176002021-07-23 15:33:09 -060043 if (options.fGpuPathRenderers & GpuPathRenderers::kAtlas) {
44 if (auto atlasPathRenderer = GrAtlasPathRenderer::Make(context)) {
45 fAtlasPathRenderer = atlasPathRenderer.get();
46 context->priv().addOnFlushCallbackObject(atlasPathRenderer.get());
47 fChain.push_back(std::move(atlasPathRenderer));
48 }
49 }
Chris Daltond6659992021-07-28 16:03:32 -060050 if (options.fGpuPathRenderers & GpuPathRenderers::kSmall) {
51 fChain.push_back(sk_make_sp<GrSmallPathRenderer>());
52 }
Chris Daltoncdabdce2021-07-28 01:52:01 -060053 if (options.fGpuPathRenderers & GpuPathRenderers::kTriangulating) {
54 fChain.push_back(sk_make_sp<GrTriangulatingPathRenderer>());
55 }
Chris Daltoneae5c162020-12-29 10:18:21 -070056 if (options.fGpuPathRenderers & GpuPathRenderers::kTessellation) {
57 if (GrTessellationPathRenderer::IsSupported(caps)) {
Chris Daltonc3176002021-07-23 15:33:09 -060058 auto tess = sk_make_sp<GrTessellationPathRenderer>();
Chris Daltone6ae4762021-02-05 14:56:21 -070059 fTessellationPathRenderer = tess.get();
Chris Daltoneae5c162020-12-29 10:18:21 -070060 fChain.push_back(std::move(tess));
61 }
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) {
Brian Salomon4dea72a2019-12-18 10:43:10 -050072 static_assert(GrPathRenderer::kNoSupport_StencilSupport <
73 GrPathRenderer::kStencilOnly_StencilSupport);
74 static_assert(GrPathRenderer::kStencilOnly_StencilSupport <
75 GrPathRenderer::kNoRestriction_StencilSupport);
bsalomon@google.com45a15f52012-12-10 19:10:17 +000076 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}