| Chris Dalton | b832ce6 | 2020-01-06 19:49:37 -0700 | [diff] [blame] | 1 | /* | 
 | 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 Dalton | 0a22b1e | 2020-03-26 11:52:15 -0600 | [diff] [blame] | 8 | #ifndef GrTessellationPathRenderer_DEFINED | 
 | 9 | #define GrTessellationPathRenderer_DEFINED | 
| Chris Dalton | b832ce6 | 2020-01-06 19:49:37 -0700 | [diff] [blame] | 10 |  | 
| Chris Dalton | 4e99853 | 2020-02-10 11:06:42 -0700 | [diff] [blame] | 11 | #include "src/gpu/GrDynamicAtlas.h" | 
 | 12 | #include "src/gpu/GrOnFlushResourceProvider.h" | 
| Chris Dalton | b832ce6 | 2020-01-06 19:49:37 -0700 | [diff] [blame] | 13 | #include "src/gpu/GrPathRenderer.h" | 
| Chris Dalton | 4e99853 | 2020-02-10 11:06:42 -0700 | [diff] [blame] | 14 | #include <map> | 
| Chris Dalton | b832ce6 | 2020-01-06 19:49:37 -0700 | [diff] [blame] | 15 |  | 
| Chris Dalton | 0a22b1e | 2020-03-26 11:52:15 -0600 | [diff] [blame] | 16 | // 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. | 
 | 20 | class GrTessellationPathRenderer : public GrPathRenderer, public GrOnFlushCallbackObject { | 
| Chris Dalton | 4e99853 | 2020-02-10 11:06:42 -0700 | [diff] [blame] | 21 | public: | 
| Robert Phillips | a628605 | 2020-04-13 10:55:08 -0400 | [diff] [blame] | 22 |     const char* name() const final { return "Tess"; } | 
 | 23 |  | 
| Chris Dalton | 0a22b1e | 2020-03-26 11:52:15 -0600 | [diff] [blame] | 24 |     GrTessellationPathRenderer(const GrCaps&); | 
| Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 25 |     StencilSupport onGetStencilSupport(const GrStyledShape& shape) const override { | 
| Chris Dalton | b832ce6 | 2020-01-06 19:49:37 -0700 | [diff] [blame] | 26 |         // TODO: Single-pass (e.g., convex) paths can have full support. | 
 | 27 |         return kStencilOnly_StencilSupport; | 
 | 28 |     } | 
| Chris Dalton | b832ce6 | 2020-01-06 19:49:37 -0700 | [diff] [blame] | 29 |     CanDrawPath onCanDrawPath(const CanDrawPathArgs&) const override; | 
 | 30 |     bool onDrawPath(const DrawPathArgs&) override; | 
 | 31 |     void onStencilPath(const StencilPathArgs&) override; | 
| Chris Dalton | 4e99853 | 2020-02-10 11:06:42 -0700 | [diff] [blame] | 32 |     void preFlush(GrOnFlushResourceProvider*, const uint32_t* opsTaskIDs, | 
 | 33 |                   int numOpsTaskIDs) override; | 
 | 34 |  | 
 | 35 | private: | 
 | 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 Dalton | b832ce6 | 2020-01-06 19:49:37 -0700 | [diff] [blame] | 48 | }; | 
 | 49 |  | 
 | 50 | #endif |