blob: 41cbe4b8dbdd25a40b83bae98d033d6cdd4b9cf2 [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:
Chris Dalton0a22b1e2020-03-26 11:52:15 -060022 GrTessellationPathRenderer(const GrCaps&);
Chris Dalton0f6bb8a2020-01-15 09:40:54 -070023 StencilSupport onGetStencilSupport(const GrShape& shape) const override {
Chris Daltonb832ce62020-01-06 19:49:37 -070024 // TODO: Single-pass (e.g., convex) paths can have full support.
25 return kStencilOnly_StencilSupport;
26 }
Chris Daltonb832ce62020-01-06 19:49:37 -070027 CanDrawPath onCanDrawPath(const CanDrawPathArgs&) const override;
28 bool onDrawPath(const DrawPathArgs&) override;
29 void onStencilPath(const StencilPathArgs&) override;
Chris Dalton4e998532020-02-10 11:06:42 -070030 void preFlush(GrOnFlushResourceProvider*, const uint32_t* opsTaskIDs,
31 int numOpsTaskIDs) override;
32
33private:
34 SkPath* getAtlasUberPath(SkPathFillType fillType, bool antialias) {
35 int idx = (int)antialias << 1;
36 idx |= (int)fillType & 1;
37 return &fAtlasUberPaths[idx];
38 }
39 // Allocates space in fAtlas if the path is small and simple enough, and if there is room.
40 bool tryAddPathToAtlas(const GrCaps&, const SkMatrix&, const SkPath&, GrAAType,
41 SkIRect* devIBounds, SkIVector* devToAtlasOffset);
42 void renderAtlas(GrOnFlushResourceProvider*);
43
44 GrDynamicAtlas fAtlas;
45 SkPath fAtlasUberPaths[4]; // 2 fillTypes * 2 antialias modes.
Chris Daltonb832ce62020-01-06 19:49:37 -070046};
47
48#endif