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" |
cdalton | 855d83f | 2014-09-18 13:51:53 -0700 | [diff] [blame] | 12 | #include "GrPathRange.h" |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 13 | #include "GrPipeline.h" |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 14 | |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 15 | class GrGpu; |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 16 | class GrPath; |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 17 | class GrStencilSettings; |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 18 | class GrStyle; |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 19 | struct SkScalerContextEffects; |
| 20 | class SkDescriptor; |
| 21 | class SkTypeface; |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 22 | |
| 23 | /** |
| 24 | * Abstract class wrapping HW path rendering API. |
| 25 | * |
| 26 | * The subclasses of this class use the possible HW API to render paths (as opposed to path |
| 27 | * rendering implemented in Skia on top of a "3d" HW API). |
| 28 | * The subclasses hold the global state needed to render paths, including shadow of the global HW |
| 29 | * API state. Similar to GrGpu. |
| 30 | * |
| 31 | * It is expected that the lifetimes of GrGpuXX and GrXXPathRendering are the same. The call context |
| 32 | * interface (eg. * the concrete instance of GrGpu subclass) should be provided to the instance |
| 33 | * during construction. |
| 34 | */ |
| 35 | class GrPathRendering { |
| 36 | public: |
| 37 | virtual ~GrPathRendering() { } |
| 38 | |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 39 | typedef GrPathRange::PathIndexType PathIndexType; |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 40 | |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 41 | enum PathTransformType { |
| 42 | kNone_PathTransformType, //!< [] |
| 43 | kTranslateX_PathTransformType, //!< [kMTransX] |
| 44 | kTranslateY_PathTransformType, //!< [kMTransY] |
| 45 | kTranslate_PathTransformType, //!< [kMTransX, kMTransY] |
| 46 | kAffine_PathTransformType, //!< [kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY] |
| 47 | |
| 48 | kLast_PathTransformType = kAffine_PathTransformType |
| 49 | }; |
| 50 | |
| 51 | static inline int PathTransformSize(PathTransformType type) { |
| 52 | switch (type) { |
| 53 | case kNone_PathTransformType: |
| 54 | return 0; |
| 55 | case kTranslateX_PathTransformType: |
| 56 | case kTranslateY_PathTransformType: |
| 57 | return 1; |
| 58 | case kTranslate_PathTransformType: |
| 59 | return 2; |
| 60 | case kAffine_PathTransformType: |
| 61 | return 6; |
| 62 | |
| 63 | default: |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 64 | SK_ABORT("Unknown path transform type"); |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 65 | return 0; |
| 66 | } |
| 67 | } |
| 68 | |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 69 | // No native support for inverse at this time |
| 70 | enum FillType { |
| 71 | /** Specifies that "inside" is computed by a non-zero sum of signed |
| 72 | edge crossings |
| 73 | */ |
| 74 | kWinding_FillType, |
| 75 | /** Specifies that "inside" is computed by an odd number of edge |
| 76 | crossings |
| 77 | */ |
| 78 | kEvenOdd_FillType, |
| 79 | }; |
| 80 | |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 81 | static const GrUserStencilSettings& GetStencilPassSettings(FillType); |
| 82 | |
cdalton | 4e205b1 | 2014-09-17 09:41:24 -0700 | [diff] [blame] | 83 | /** |
| 84 | * 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] | 85 | * |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 86 | * @param SkPath the geometry. |
| 87 | * @param GrStyle the style applied to the path. Styles with non-dash path effects are not |
| 88 | * allowed. |
| 89 | * @return a new GPU path object. |
cdalton | 4e205b1 | 2014-09-17 09:41:24 -0700 | [diff] [blame] | 90 | */ |
Robert Phillips | 67d52cf | 2017-06-05 13:38:13 -0400 | [diff] [blame] | 91 | virtual sk_sp<GrPath> createPath(const SkPath&, const GrStyle&) = 0; |
cdalton | 4e205b1 | 2014-09-17 09:41:24 -0700 | [diff] [blame] | 92 | |
| 93 | /** |
Robert Phillips | 67d52cf | 2017-06-05 13:38:13 -0400 | [diff] [blame] | 94 | * Creates a range of gpu paths with a common style. |
cdalton | 4e205b1 | 2014-09-17 09:41:24 -0700 | [diff] [blame] | 95 | * |
| 96 | * @param PathGenerator class that generates SkPath objects for each path in the range. |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 97 | * @param GrStyle the common style applied to each path in the range. Styles with non-dash |
| 98 | * path effects are not allowed. |
cdalton | 4e205b1 | 2014-09-17 09:41:24 -0700 | [diff] [blame] | 99 | * @return a new path range. |
| 100 | */ |
Robert Phillips | 67d52cf | 2017-06-05 13:38:13 -0400 | [diff] [blame] | 101 | virtual sk_sp<GrPathRange> createPathRange(GrPathRange::PathGenerator*, const GrStyle&) = 0; |
cdalton | 855d83f | 2014-09-18 13:51:53 -0700 | [diff] [blame] | 102 | |
| 103 | /** |
| 104 | * Creates a range of glyph paths, indexed by glyph id. The glyphs will have an |
Robert Phillips | 67d52cf | 2017-06-05 13:38:13 -0400 | [diff] [blame] | 105 | * inverted y-direction in order to match the raw font path data. |
cdalton | 855d83f | 2014-09-18 13:51:53 -0700 | [diff] [blame] | 106 | * |
| 107 | * @param SkTypeface Typeface that defines the glyphs. |
| 108 | * If null, the default typeface will be used. |
| 109 | * |
| 110 | * @param SkDescriptor Additional font configuration that specifies the font's size, |
| 111 | * stroke, and other flags. This will generally come from an |
| 112 | * SkGlyphCache. |
| 113 | * |
| 114 | * It is recommended to leave this value null when possible, in |
| 115 | * which case the glyphs will be loaded directly from the font's |
| 116 | * raw path data and sized at SkPaint::kCanonicalTextSizeForPaths. |
| 117 | * This will result in less memory usage and more efficient paths. |
| 118 | * |
| 119 | * If non-null, the glyph paths will match the font descriptor, |
| 120 | * including with the stroke information baked directly into |
| 121 | * the outlines. |
| 122 | * |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame] | 123 | * @param GrStyle Common style that the GPU will apply to every path. Note that |
| 124 | * if the glyph outlines contain baked-in styles from the font |
| 125 | * descriptor, the GPU style will be applied on top of those |
cdalton | 855d83f | 2014-09-18 13:51:53 -0700 | [diff] [blame] | 126 | * outlines. |
| 127 | * |
| 128 | * @return a new path range populated with glyphs. |
| 129 | */ |
Robert Phillips | 67d52cf | 2017-06-05 13:38:13 -0400 | [diff] [blame] | 130 | sk_sp<GrPathRange> createGlyphs(const SkTypeface*, const SkScalerContextEffects&, |
| 131 | const SkDescriptor*, const GrStyle&); |
cdalton | 4e205b1 | 2014-09-17 09:41:24 -0700 | [diff] [blame] | 132 | |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 133 | /** None of these params are optional, pointers used just to avoid making copies. */ |
| 134 | struct StencilPathArgs { |
| 135 | StencilPathArgs(bool useHWAA, |
Robert Phillips | 7311b40 | 2017-07-27 12:01:46 -0400 | [diff] [blame] | 136 | GrRenderTargetProxy* proxy, |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 137 | const SkMatrix* viewMatrix, |
| 138 | const GrScissorState* scissor, |
| 139 | const GrStencilSettings* stencil) |
| 140 | : fUseHWAA(useHWAA) |
Robert Phillips | 7311b40 | 2017-07-27 12:01:46 -0400 | [diff] [blame] | 141 | , fProxy(proxy) |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 142 | , fViewMatrix(viewMatrix) |
| 143 | , fScissor(scissor) |
| 144 | , fStencil(stencil) { |
| 145 | } |
Robert Phillips | 7311b40 | 2017-07-27 12:01:46 -0400 | [diff] [blame] | 146 | bool fUseHWAA; |
| 147 | GrRenderTargetProxy* fProxy; |
| 148 | const SkMatrix* fViewMatrix; |
| 149 | const GrScissorState* fScissor; |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 150 | const GrStencilSettings* fStencil; |
| 151 | }; |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 152 | |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 153 | void stencilPath(const StencilPathArgs& args, const GrPath* path); |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 154 | |
stephana | 1dc1721 | 2016-04-25 07:01:22 -0700 | [diff] [blame] | 155 | void drawPath(const GrPipeline& pipeline, |
| 156 | const GrPrimitiveProcessor& primProc, |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 157 | const GrStencilSettings& stencilPassSettings, // Cover pass settings in pipeline. |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 158 | const GrPath* path); |
stephana | 1dc1721 | 2016-04-25 07:01:22 -0700 | [diff] [blame] | 159 | |
egdaniel | 0e1853c | 2016-03-17 11:35:45 -0700 | [diff] [blame] | 160 | void drawPaths(const GrPipeline& pipeline, |
| 161 | const GrPrimitiveProcessor& primProc, |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 162 | const GrStencilSettings& stencilPassSettings, // Cover pass settings in pipeline. |
egdaniel | 0e1853c | 2016-03-17 11:35:45 -0700 | [diff] [blame] | 163 | const GrPathRange* pathRange, |
| 164 | const void* indices, |
| 165 | PathIndexType indexType, |
| 166 | const float transformValues[], |
| 167 | PathTransformType transformType, |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 168 | int count); |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 169 | |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 170 | protected: |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 171 | GrPathRendering(GrGpu* gpu) : fGpu(gpu) { } |
| 172 | |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 173 | virtual void onStencilPath(const StencilPathArgs&, const GrPath*) = 0; |
stephana | 1dc1721 | 2016-04-25 07:01:22 -0700 | [diff] [blame] | 174 | virtual void onDrawPath(const GrPipeline&, |
| 175 | const GrPrimitiveProcessor&, |
| 176 | const GrStencilSettings&, |
| 177 | const GrPath*) = 0; |
egdaniel | 0e1853c | 2016-03-17 11:35:45 -0700 | [diff] [blame] | 178 | virtual void onDrawPaths(const GrPipeline&, |
| 179 | const GrPrimitiveProcessor&, |
| 180 | const GrStencilSettings&, |
| 181 | const GrPathRange*, |
| 182 | const void* indices, |
| 183 | PathIndexType, |
| 184 | const float transformValues[], |
| 185 | PathTransformType, |
| 186 | int count) = 0; |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 187 | |
| 188 | GrGpu* fGpu; |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 189 | private: |
| 190 | GrPathRendering& operator=(const GrPathRendering&); |
| 191 | }; |
| 192 | |
| 193 | #endif |