kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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 | #ifndef GrPathRendering_DEFINED |
| 9 | #define GrPathRendering_DEFINED |
| 10 | |
| 11 | #include "SkPath.h" |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 12 | #include "GrPipeline.h" |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 13 | |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 14 | class GrGpu; |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 15 | class GrPath; |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 16 | class GrStencilSettings; |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 17 | class GrStyle; |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 18 | struct SkScalerContextEffects; |
| 19 | class SkDescriptor; |
| 20 | class SkTypeface; |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 21 | |
| 22 | /** |
| 23 | * Abstract class wrapping HW path rendering API. |
| 24 | * |
| 25 | * The subclasses of this class use the possible HW API to render paths (as opposed to path |
| 26 | * rendering implemented in Skia on top of a "3d" HW API). |
| 27 | * The subclasses hold the global state needed to render paths, including shadow of the global HW |
| 28 | * API state. Similar to GrGpu. |
| 29 | * |
| 30 | * It is expected that the lifetimes of GrGpuXX and GrXXPathRendering are the same. The call context |
| 31 | * interface (eg. * the concrete instance of GrGpu subclass) should be provided to the instance |
| 32 | * during construction. |
| 33 | */ |
| 34 | class GrPathRendering { |
| 35 | public: |
| 36 | virtual ~GrPathRendering() { } |
| 37 | |
| 38 | enum PathTransformType { |
| 39 | kNone_PathTransformType, //!< [] |
| 40 | kTranslateX_PathTransformType, //!< [kMTransX] |
| 41 | kTranslateY_PathTransformType, //!< [kMTransY] |
| 42 | kTranslate_PathTransformType, //!< [kMTransX, kMTransY] |
| 43 | kAffine_PathTransformType, //!< [kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY] |
| 44 | |
| 45 | kLast_PathTransformType = kAffine_PathTransformType |
| 46 | }; |
| 47 | |
| 48 | static inline int PathTransformSize(PathTransformType type) { |
| 49 | switch (type) { |
| 50 | case kNone_PathTransformType: |
| 51 | return 0; |
| 52 | case kTranslateX_PathTransformType: |
| 53 | case kTranslateY_PathTransformType: |
| 54 | return 1; |
| 55 | case kTranslate_PathTransformType: |
| 56 | return 2; |
| 57 | case kAffine_PathTransformType: |
| 58 | return 6; |
| 59 | |
| 60 | default: |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 61 | SK_ABORT("Unknown path transform type"); |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 62 | return 0; |
| 63 | } |
| 64 | } |
| 65 | |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 66 | // No native support for inverse at this time |
| 67 | enum FillType { |
| 68 | /** Specifies that "inside" is computed by a non-zero sum of signed |
| 69 | edge crossings |
| 70 | */ |
| 71 | kWinding_FillType, |
| 72 | /** Specifies that "inside" is computed by an odd number of edge |
| 73 | crossings |
| 74 | */ |
| 75 | kEvenOdd_FillType, |
| 76 | }; |
| 77 | |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 78 | static const GrUserStencilSettings& GetStencilPassSettings(FillType); |
| 79 | |
cdalton | 4e205b1 | 2014-09-17 09:41:24 -0700 | [diff] [blame] | 80 | /** |
| 81 | * Creates a new gpu path, based on the specified path and stroke and returns it. |
cdalton | 4e205b1 | 2014-09-17 09:41:24 -0700 | [diff] [blame] | 82 | * |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 83 | * @param SkPath the geometry. |
| 84 | * @param GrStyle the style applied to the path. Styles with non-dash path effects are not |
| 85 | * allowed. |
| 86 | * @return a new GPU path object. |
cdalton | 4e205b1 | 2014-09-17 09:41:24 -0700 | [diff] [blame] | 87 | */ |
Robert Phillips | 67d52cf | 2017-06-05 13:38:13 -0400 | [diff] [blame] | 88 | virtual sk_sp<GrPath> createPath(const SkPath&, const GrStyle&) = 0; |
cdalton | 4e205b1 | 2014-09-17 09:41:24 -0700 | [diff] [blame] | 89 | |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 90 | /** None of these params are optional, pointers used just to avoid making copies. */ |
| 91 | struct StencilPathArgs { |
| 92 | StencilPathArgs(bool useHWAA, |
Robert Phillips | 7311b40 | 2017-07-27 12:01:46 -0400 | [diff] [blame] | 93 | GrRenderTargetProxy* proxy, |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 94 | const SkMatrix* viewMatrix, |
| 95 | const GrScissorState* scissor, |
| 96 | const GrStencilSettings* stencil) |
| 97 | : fUseHWAA(useHWAA) |
Robert Phillips | 7311b40 | 2017-07-27 12:01:46 -0400 | [diff] [blame] | 98 | , fProxy(proxy) |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 99 | , fViewMatrix(viewMatrix) |
| 100 | , fScissor(scissor) |
| 101 | , fStencil(stencil) { |
| 102 | } |
Robert Phillips | 7311b40 | 2017-07-27 12:01:46 -0400 | [diff] [blame] | 103 | bool fUseHWAA; |
| 104 | GrRenderTargetProxy* fProxy; |
| 105 | const SkMatrix* fViewMatrix; |
| 106 | const GrScissorState* fScissor; |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 107 | const GrStencilSettings* fStencil; |
| 108 | }; |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 109 | |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 110 | void stencilPath(const StencilPathArgs& args, const GrPath* path); |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 111 | |
Robert Phillips | d0fe875 | 2019-01-31 14:13:59 -0500 | [diff] [blame] | 112 | void drawPath(GrRenderTarget*, GrSurfaceOrigin, |
| 113 | const GrPrimitiveProcessor& primProc, |
Brian Salomon | ff168d9 | 2018-06-23 15:17:27 -0400 | [diff] [blame] | 114 | const GrPipeline& pipeline, |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 115 | const GrPipeline::FixedDynamicState&, |
Brian Salomon | ff168d9 | 2018-06-23 15:17:27 -0400 | [diff] [blame] | 116 | const GrStencilSettings& stencilPassSettings, // Cover pass settings in pipeline. |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 117 | const GrPath* path); |
stephana | 1dc1721 | 2016-04-25 07:01:22 -0700 | [diff] [blame] | 118 | |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 119 | protected: |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 120 | GrPathRendering(GrGpu* gpu) : fGpu(gpu) { } |
| 121 | |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 122 | virtual void onStencilPath(const StencilPathArgs&, const GrPath*) = 0; |
Robert Phillips | d0fe875 | 2019-01-31 14:13:59 -0500 | [diff] [blame] | 123 | virtual void onDrawPath(GrRenderTarget*, GrSurfaceOrigin, |
| 124 | const GrPrimitiveProcessor&, |
Brian Salomon | ff168d9 | 2018-06-23 15:17:27 -0400 | [diff] [blame] | 125 | const GrPipeline&, |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 126 | const GrPipeline::FixedDynamicState&, |
stephana | 1dc1721 | 2016-04-25 07:01:22 -0700 | [diff] [blame] | 127 | const GrStencilSettings&, |
| 128 | const GrPath*) = 0; |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 129 | |
| 130 | GrGpu* fGpu; |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 131 | private: |
| 132 | GrPathRendering& operator=(const GrPathRendering&); |
| 133 | }; |
| 134 | |
| 135 | #endif |