blob: bf8ea29eb701678c0e83ccac202c69bd27a656a3 [file] [log] [blame]
Chris Daltonb832ce62020-01-06 19:49:37 -07001/*
2 * Copyright 2019 Google LLC.
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
Chris Dalton0a22b1e2020-03-26 11:52:15 -06008#ifndef GrTessellationPathRenderer_DEFINED
9#define GrTessellationPathRenderer_DEFINED
Chris Daltonb832ce62020-01-06 19:49:37 -070010
Chris Dalton4e998532020-02-10 11:06:42 -070011#include "src/gpu/GrDynamicAtlas.h"
12#include "src/gpu/GrOnFlushResourceProvider.h"
Chris Daltonb832ce62020-01-06 19:49:37 -070013#include "src/gpu/GrPathRenderer.h"
Chris Dalton4e998532020-02-10 11:06:42 -070014#include <map>
Chris Daltonb832ce62020-01-06 19:49:37 -070015
Chris Dalton0a22b1e2020-03-26 11:52:15 -060016// This is the tie-in point for path rendering via GrTessellatePathOp. This path renderer draws
17// paths using a hybrid Red Book "stencil, then cover" method. Curves get linearized by GPU
18// tessellation shaders. This path renderer doesn't apply analytic AA, so it requires a render
19// target that supports either MSAA or mixed samples if AA is desired.
20class GrTessellationPathRenderer : public GrPathRenderer, public GrOnFlushCallbackObject {
Chris Dalton4e998532020-02-10 11:06:42 -070021public:
Robert Phillipsa6286052020-04-13 10:55:08 -040022 const char* name() const final { return "Tess"; }
23
Chris Dalton0a22b1e2020-03-26 11:52:15 -060024 GrTessellationPathRenderer(const GrCaps&);
Michael Ludwig2686d692020-04-17 20:21:37 +000025 StencilSupport onGetStencilSupport(const GrStyledShape& shape) const override {
Chris Daltonb832ce62020-01-06 19:49:37 -070026 // TODO: Single-pass (e.g., convex) paths can have full support.
27 return kStencilOnly_StencilSupport;
28 }
Chris Daltonb832ce62020-01-06 19:49:37 -070029 CanDrawPath onCanDrawPath(const CanDrawPathArgs&) const override;
30 bool onDrawPath(const DrawPathArgs&) override;
31 void onStencilPath(const StencilPathArgs&) override;
Chris Dalton4e998532020-02-10 11:06:42 -070032 void preFlush(GrOnFlushResourceProvider*, const uint32_t* opsTaskIDs,
33 int numOpsTaskIDs) override;
34
35private:
36 SkPath* getAtlasUberPath(SkPathFillType fillType, bool antialias) {
37 int idx = (int)antialias << 1;
38 idx |= (int)fillType & 1;
39 return &fAtlasUberPaths[idx];
40 }
41 // Allocates space in fAtlas if the path is small and simple enough, and if there is room.
42 bool tryAddPathToAtlas(const GrCaps&, const SkMatrix&, const SkPath&, GrAAType,
43 SkIRect* devIBounds, SkIVector* devToAtlasOffset);
44 void renderAtlas(GrOnFlushResourceProvider*);
45
46 GrDynamicAtlas fAtlas;
47 SkPath fAtlasUberPaths[4]; // 2 fillTypes * 2 antialias modes.
Chris Daltonb832ce62020-01-06 19:49:37 -070048};
49
50#endif