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" |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 12 | #include "GrGpu.h" |
cdalton | 855d83f | 2014-09-18 13:51:53 -0700 | [diff] [blame] | 13 | #include "GrPathRange.h" |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 14 | #include "GrPipeline.h" |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 15 | |
cdalton | 855d83f | 2014-09-18 13:51:53 -0700 | [diff] [blame] | 16 | class SkDescriptor; |
| 17 | class SkTypeface; |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 18 | class GrPath; |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 19 | class GrStencilSettings; |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame^] | 20 | class GrStyle; |
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 | |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 38 | typedef GrPathRange::PathIndexType PathIndexType; |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 39 | |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 40 | enum PathTransformType { |
| 41 | kNone_PathTransformType, //!< [] |
| 42 | kTranslateX_PathTransformType, //!< [kMTransX] |
| 43 | kTranslateY_PathTransformType, //!< [kMTransY] |
| 44 | kTranslate_PathTransformType, //!< [kMTransX, kMTransY] |
| 45 | kAffine_PathTransformType, //!< [kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY] |
| 46 | |
| 47 | kLast_PathTransformType = kAffine_PathTransformType |
| 48 | }; |
| 49 | |
| 50 | static inline int PathTransformSize(PathTransformType type) { |
| 51 | switch (type) { |
| 52 | case kNone_PathTransformType: |
| 53 | return 0; |
| 54 | case kTranslateX_PathTransformType: |
| 55 | case kTranslateY_PathTransformType: |
| 56 | return 1; |
| 57 | case kTranslate_PathTransformType: |
| 58 | return 2; |
| 59 | case kAffine_PathTransformType: |
| 60 | return 6; |
| 61 | |
| 62 | default: |
| 63 | SkFAIL("Unknown path transform type"); |
| 64 | return 0; |
| 65 | } |
| 66 | } |
| 67 | |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 68 | // No native support for inverse at this time |
| 69 | enum FillType { |
| 70 | /** Specifies that "inside" is computed by a non-zero sum of signed |
| 71 | edge crossings |
| 72 | */ |
| 73 | kWinding_FillType, |
| 74 | /** Specifies that "inside" is computed by an odd number of edge |
| 75 | crossings |
| 76 | */ |
| 77 | kEvenOdd_FillType, |
| 78 | }; |
| 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. |
| 82 | * The caller owns a ref on the returned path which must be balanced by a call to unref. |
| 83 | * |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame^] | 84 | * @param SkPath the geometry. |
| 85 | * @param GrStyle the style applied to the path. Styles with non-dash path effects are not |
| 86 | * allowed. |
| 87 | * @return a new GPU path object. |
cdalton | 4e205b1 | 2014-09-17 09:41:24 -0700 | [diff] [blame] | 88 | */ |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame^] | 89 | virtual GrPath* createPath(const SkPath&, const GrStyle&) = 0; |
cdalton | 4e205b1 | 2014-09-17 09:41:24 -0700 | [diff] [blame] | 90 | |
| 91 | /** |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame^] | 92 | * Creates a range of gpu paths with a common style. The caller owns a ref on the |
cdalton | 4e205b1 | 2014-09-17 09:41:24 -0700 | [diff] [blame] | 93 | * returned path range which must be balanced by a call to unref. |
| 94 | * |
| 95 | * @param PathGenerator class that generates SkPath objects for each path in the range. |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame^] | 96 | * @param GrStyle the common style applied to each path in the range. Styles with non-dash |
| 97 | * path effects are not allowed. |
cdalton | 4e205b1 | 2014-09-17 09:41:24 -0700 | [diff] [blame] | 98 | * @return a new path range. |
| 99 | */ |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame^] | 100 | virtual GrPathRange* createPathRange(GrPathRange::PathGenerator*, const GrStyle&) = 0; |
cdalton | 855d83f | 2014-09-18 13:51:53 -0700 | [diff] [blame] | 101 | |
| 102 | /** |
| 103 | * Creates a range of glyph paths, indexed by glyph id. The glyphs will have an |
| 104 | * inverted y-direction in order to match the raw font path data. The caller owns |
| 105 | * a ref on the returned path range which must be balanced by a call to unref. |
| 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 | */ |
reed | a9322c2 | 2016-04-12 06:47:05 -0700 | [diff] [blame] | 130 | GrPathRange* createGlyphs(const SkTypeface*, const SkScalerContextEffects&, |
bsalomon | 6663acf | 2016-05-10 09:14:17 -0700 | [diff] [blame^] | 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, |
| 136 | GrRenderTarget* renderTarget, |
| 137 | const SkMatrix* viewMatrix, |
| 138 | const GrScissorState* scissor, |
| 139 | const GrStencilSettings* stencil) |
| 140 | : fUseHWAA(useHWAA) |
| 141 | , fRenderTarget(renderTarget) |
| 142 | , fViewMatrix(viewMatrix) |
| 143 | , fScissor(scissor) |
| 144 | , fStencil(stencil) { |
| 145 | } |
| 146 | bool fUseHWAA; |
| 147 | GrRenderTarget* fRenderTarget; |
| 148 | const SkMatrix* fViewMatrix; |
| 149 | const GrScissorState* fScissor; |
| 150 | const GrStencilSettings* fStencil; |
| 151 | }; |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 152 | |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 153 | void stencilPath(const StencilPathArgs& args, const GrPath* path) { |
| 154 | fGpu->handleDirtyContext(); |
| 155 | this->onStencilPath(args, path); |
| 156 | } |
| 157 | |
stephana | 1dc1721 | 2016-04-25 07:01:22 -0700 | [diff] [blame] | 158 | void drawPath(const GrPipeline& pipeline, |
| 159 | const GrPrimitiveProcessor& primProc, |
| 160 | const GrStencilSettings& stencil, |
| 161 | const GrPath* path) { |
| 162 | fGpu->handleDirtyContext(); |
| 163 | if (GrXferBarrierType barrierType = pipeline.xferBarrierType(*fGpu->caps())) { |
| 164 | fGpu->xferBarrier(pipeline.getRenderTarget(), barrierType); |
| 165 | } |
| 166 | this->onDrawPath(pipeline, primProc, stencil, path); |
| 167 | } |
| 168 | |
egdaniel | 0e1853c | 2016-03-17 11:35:45 -0700 | [diff] [blame] | 169 | void drawPaths(const GrPipeline& pipeline, |
| 170 | const GrPrimitiveProcessor& primProc, |
| 171 | const GrStencilSettings& stencil, |
| 172 | const GrPathRange* pathRange, |
| 173 | const void* indices, |
| 174 | PathIndexType indexType, |
| 175 | const float transformValues[], |
| 176 | PathTransformType transformType, |
| 177 | int count) { |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 178 | fGpu->handleDirtyContext(); |
egdaniel | 0e1853c | 2016-03-17 11:35:45 -0700 | [diff] [blame] | 179 | if (GrXferBarrierType barrierType = pipeline.xferBarrierType(*fGpu->caps())) { |
| 180 | fGpu->xferBarrier(pipeline.getRenderTarget(), barrierType); |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 181 | } |
cdalton | d120105 | 2015-10-05 15:56:34 -0700 | [diff] [blame] | 182 | #ifdef SK_DEBUG |
| 183 | pathRange->assertPathsLoaded(indices, indexType, count); |
| 184 | #endif |
egdaniel | 0e1853c | 2016-03-17 11:35:45 -0700 | [diff] [blame] | 185 | this->onDrawPaths(pipeline, primProc, stencil, pathRange, indices, indexType, |
| 186 | transformValues, transformType, count); |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 187 | } |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 188 | |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 189 | protected: |
| 190 | GrPathRendering(GrGpu* gpu) |
| 191 | : fGpu(gpu) { |
| 192 | } |
| 193 | virtual void onStencilPath(const StencilPathArgs&, const GrPath*) = 0; |
stephana | 1dc1721 | 2016-04-25 07:01:22 -0700 | [diff] [blame] | 194 | virtual void onDrawPath(const GrPipeline&, |
| 195 | const GrPrimitiveProcessor&, |
| 196 | const GrStencilSettings&, |
| 197 | const GrPath*) = 0; |
egdaniel | 0e1853c | 2016-03-17 11:35:45 -0700 | [diff] [blame] | 198 | virtual void onDrawPaths(const GrPipeline&, |
| 199 | const GrPrimitiveProcessor&, |
| 200 | const GrStencilSettings&, |
| 201 | const GrPathRange*, |
| 202 | const void* indices, |
| 203 | PathIndexType, |
| 204 | const float transformValues[], |
| 205 | PathTransformType, |
| 206 | int count) = 0; |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 207 | |
| 208 | GrGpu* fGpu; |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 209 | private: |
| 210 | GrPathRendering& operator=(const GrPathRendering&); |
| 211 | }; |
| 212 | |
| 213 | #endif |