blob: c32e7891b5fd4e8e1b26017da424a6ed5ce13716 [file] [log] [blame]
kkinnunenccdaa042014-08-20 01:36:23 -07001/*
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"
cdalton855d83f2014-09-18 13:51:53 -070012#include "GrPathRange.h"
bsalomoncb02b382015-08-12 11:14:50 -070013#include "GrPipeline.h"
kkinnunenccdaa042014-08-20 01:36:23 -070014
Robert Phillips646e4292017-06-13 12:44:56 -040015class GrGpu;
kkinnunenccdaa042014-08-20 01:36:23 -070016class GrPath;
joshualitt92e496f2014-10-31 13:56:50 -070017class GrStencilSettings;
bsalomon6663acf2016-05-10 09:14:17 -070018class GrStyle;
Brian Salomon2bbdcc42017-09-07 12:36:34 -040019struct SkScalerContextEffects;
20class SkDescriptor;
21class SkTypeface;
kkinnunenccdaa042014-08-20 01:36:23 -070022
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 */
35class GrPathRendering {
36public:
37 virtual ~GrPathRendering() { }
38
cdalton55b24af2014-11-25 11:00:56 -080039 typedef GrPathRange::PathIndexType PathIndexType;
joshualitt92e496f2014-10-31 13:56:50 -070040
kkinnunenccdaa042014-08-20 01:36:23 -070041 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 Wagnerb4aab9a2017-08-16 10:53:04 -040064 SK_ABORT("Unknown path transform type");
kkinnunenccdaa042014-08-20 01:36:23 -070065 return 0;
66 }
67 }
68
cdalton55b24af2014-11-25 11:00:56 -080069 // 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
cdalton193d9cf2016-05-12 11:52:02 -070081 static const GrUserStencilSettings& GetStencilPassSettings(FillType);
82
cdalton4e205b12014-09-17 09:41:24 -070083 /**
84 * Creates a new gpu path, based on the specified path and stroke and returns it.
cdalton4e205b12014-09-17 09:41:24 -070085 *
bsalomon6663acf2016-05-10 09:14:17 -070086 * @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.
cdalton4e205b12014-09-17 09:41:24 -070090 */
Robert Phillips67d52cf2017-06-05 13:38:13 -040091 virtual sk_sp<GrPath> createPath(const SkPath&, const GrStyle&) = 0;
cdalton4e205b12014-09-17 09:41:24 -070092
93 /**
Robert Phillips67d52cf2017-06-05 13:38:13 -040094 * Creates a range of gpu paths with a common style.
cdalton4e205b12014-09-17 09:41:24 -070095 *
96 * @param PathGenerator class that generates SkPath objects for each path in the range.
bsalomon6663acf2016-05-10 09:14:17 -070097 * @param GrStyle the common style applied to each path in the range. Styles with non-dash
98 * path effects are not allowed.
cdalton4e205b12014-09-17 09:41:24 -070099 * @return a new path range.
100 */
Robert Phillips67d52cf2017-06-05 13:38:13 -0400101 virtual sk_sp<GrPathRange> createPathRange(GrPathRange::PathGenerator*, const GrStyle&) = 0;
cdalton855d83f2014-09-18 13:51:53 -0700102
103 /**
104 * Creates a range of glyph paths, indexed by glyph id. The glyphs will have an
Robert Phillips67d52cf2017-06-05 13:38:13 -0400105 * inverted y-direction in order to match the raw font path data.
cdalton855d83f2014-09-18 13:51:53 -0700106 *
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 *
bsalomon6663acf2016-05-10 09:14:17 -0700123 * @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
cdalton855d83f2014-09-18 13:51:53 -0700126 * outlines.
127 *
128 * @return a new path range populated with glyphs.
129 */
Robert Phillips67d52cf2017-06-05 13:38:13 -0400130 sk_sp<GrPathRange> createGlyphs(const SkTypeface*, const SkScalerContextEffects&,
131 const SkDescriptor*, const GrStyle&);
cdalton4e205b12014-09-17 09:41:24 -0700132
kkinnunencabe20c2015-06-01 01:37:26 -0700133 /** None of these params are optional, pointers used just to avoid making copies. */
134 struct StencilPathArgs {
135 StencilPathArgs(bool useHWAA,
Robert Phillips7311b402017-07-27 12:01:46 -0400136 GrRenderTargetProxy* proxy,
kkinnunencabe20c2015-06-01 01:37:26 -0700137 const SkMatrix* viewMatrix,
138 const GrScissorState* scissor,
139 const GrStencilSettings* stencil)
140 : fUseHWAA(useHWAA)
Robert Phillips7311b402017-07-27 12:01:46 -0400141 , fProxy(proxy)
kkinnunencabe20c2015-06-01 01:37:26 -0700142 , fViewMatrix(viewMatrix)
143 , fScissor(scissor)
144 , fStencil(stencil) {
145 }
Robert Phillips7311b402017-07-27 12:01:46 -0400146 bool fUseHWAA;
147 GrRenderTargetProxy* fProxy;
148 const SkMatrix* fViewMatrix;
149 const GrScissorState* fScissor;
kkinnunencabe20c2015-06-01 01:37:26 -0700150 const GrStencilSettings* fStencil;
151 };
kkinnunenccdaa042014-08-20 01:36:23 -0700152
Robert Phillips646e4292017-06-13 12:44:56 -0400153 void stencilPath(const StencilPathArgs& args, const GrPath* path);
kkinnunencabe20c2015-06-01 01:37:26 -0700154
stephana1dc17212016-04-25 07:01:22 -0700155 void drawPath(const GrPipeline& pipeline,
156 const GrPrimitiveProcessor& primProc,
cdalton193d9cf2016-05-12 11:52:02 -0700157 const GrStencilSettings& stencilPassSettings, // Cover pass settings in pipeline.
Robert Phillips646e4292017-06-13 12:44:56 -0400158 const GrPath* path);
stephana1dc17212016-04-25 07:01:22 -0700159
egdaniel0e1853c2016-03-17 11:35:45 -0700160 void drawPaths(const GrPipeline& pipeline,
161 const GrPrimitiveProcessor& primProc,
cdalton193d9cf2016-05-12 11:52:02 -0700162 const GrStencilSettings& stencilPassSettings, // Cover pass settings in pipeline.
egdaniel0e1853c2016-03-17 11:35:45 -0700163 const GrPathRange* pathRange,
164 const void* indices,
165 PathIndexType indexType,
166 const float transformValues[],
167 PathTransformType transformType,
Robert Phillips646e4292017-06-13 12:44:56 -0400168 int count);
bsalomoncb02b382015-08-12 11:14:50 -0700169
kkinnunencabe20c2015-06-01 01:37:26 -0700170protected:
Robert Phillips646e4292017-06-13 12:44:56 -0400171 GrPathRendering(GrGpu* gpu) : fGpu(gpu) { }
172
kkinnunencabe20c2015-06-01 01:37:26 -0700173 virtual void onStencilPath(const StencilPathArgs&, const GrPath*) = 0;
stephana1dc17212016-04-25 07:01:22 -0700174 virtual void onDrawPath(const GrPipeline&,
175 const GrPrimitiveProcessor&,
176 const GrStencilSettings&,
177 const GrPath*) = 0;
egdaniel0e1853c2016-03-17 11:35:45 -0700178 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;
kkinnunencabe20c2015-06-01 01:37:26 -0700187
188 GrGpu* fGpu;
kkinnunenccdaa042014-08-20 01:36:23 -0700189private:
190 GrPathRendering& operator=(const GrPathRendering&);
191};
192
193#endif