• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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"
12 #include "GrPathRange.h"
13 
14 class SkStrokeRec;
15 class SkDescriptor;
16 class SkTypeface;
17 class GrPath;
18 class GrGpu;
19 class GrStencilSettings;
20 
21 /**
22  * Abstract class wrapping HW path rendering API.
23  *
24  * The subclasses of this class use the possible HW API to render paths (as opposed to path
25  * rendering implemented in Skia on top of a "3d" HW API).
26  * The subclasses hold the global state needed to render paths, including shadow of the global HW
27  * API state. Similar to GrGpu.
28  *
29  * It is expected that the lifetimes of GrGpuXX and GrXXPathRendering are the same. The call context
30  * interface (eg.  * the concrete instance of GrGpu subclass) should be provided to the instance
31  * during construction.
32  */
33 class GrPathRendering {
34 public:
~GrPathRendering()35     virtual ~GrPathRendering() { }
36 
37     typedef GrPathRange::PathIndexType PathIndexType;
38 
39     enum PathTransformType {
40         kNone_PathTransformType,        //!< []
41         kTranslateX_PathTransformType,  //!< [kMTransX]
42         kTranslateY_PathTransformType,  //!< [kMTransY]
43         kTranslate_PathTransformType,   //!< [kMTransX, kMTransY]
44         kAffine_PathTransformType,      //!< [kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY]
45 
46         kLast_PathTransformType = kAffine_PathTransformType
47     };
48 
PathTransformSize(PathTransformType type)49     static inline int PathTransformSize(PathTransformType type) {
50         switch (type) {
51             case kNone_PathTransformType:
52                 return 0;
53             case kTranslateX_PathTransformType:
54             case kTranslateY_PathTransformType:
55                 return 1;
56             case kTranslate_PathTransformType:
57                 return 2;
58             case kAffine_PathTransformType:
59                 return 6;
60 
61             default:
62                 SkFAIL("Unknown path transform type");
63                 return 0;
64         }
65     }
66 
67     // No native support for inverse at this time
68     enum FillType {
69         /** Specifies that "inside" is computed by a non-zero sum of signed
70             edge crossings
71         */
72         kWinding_FillType,
73         /** Specifies that "inside" is computed by an odd number of edge
74             crossings
75         */
76         kEvenOdd_FillType,
77     };
78 
79     /**
80      * Creates a new gpu path, based on the specified path and stroke and returns it.
81      * The caller owns a ref on the returned path which must be balanced by a call to unref.
82      *
83      * @param skPath the path geometry.
84      * @param stroke the path stroke.
85      * @return a new path.
86      */
87     virtual GrPath* createPath(const SkPath&, const SkStrokeRec&) = 0;
88 
89     /**
90      * Creates a range of gpu paths with a common stroke. The caller owns a ref on the
91      * returned path range which must be balanced by a call to unref.
92      *
93      * @param PathGenerator class that generates SkPath objects for each path in the range.
94      * @param SkStrokeRec   the common stroke applied to each path in the range.
95      * @return a new path range.
96      */
97     virtual GrPathRange* createPathRange(GrPathRange::PathGenerator*, const SkStrokeRec&) = 0;
98 
99     /**
100      * Creates a range of glyph paths, indexed by glyph id. The glyphs will have an
101      * inverted y-direction in order to match the raw font path data. The caller owns
102      * a ref on the returned path range which must be balanced by a call to unref.
103      *
104      * @param SkTypeface   Typeface that defines the glyphs.
105      *                     If null, the default typeface will be used.
106      *
107      * @param SkDescriptor Additional font configuration that specifies the font's size,
108      *                     stroke, and other flags. This will generally come from an
109      *                     SkGlyphCache.
110      *
111      *                     It is recommended to leave this value null when possible, in
112      *                     which case the glyphs will be loaded directly from the font's
113      *                     raw path data and sized at SkPaint::kCanonicalTextSizeForPaths.
114      *                     This will result in less memory usage and more efficient paths.
115      *
116      *                     If non-null, the glyph paths will match the font descriptor,
117      *                     including with the stroke information baked directly into
118      *                     the outlines.
119      *
120      * @param SkStrokeRec  Common stroke that the GPU will apply to every path. Note that
121      *                     if the glyph outlines contain baked-in strokes from the font
122      *                     descriptor, the GPU stroke will be applied on top of those
123      *                     outlines.
124      *
125      * @return a new path range populated with glyphs.
126      */
127     virtual GrPathRange* createGlyphs(const SkTypeface*, const SkDescriptor*, const SkStrokeRec&) = 0;
128 
129     virtual void stencilPath(const GrPath*, const GrStencilSettings&) = 0;
130     virtual void drawPath(const GrPath*, const GrStencilSettings&) = 0;
131     virtual void drawPaths(const GrPathRange*, const void* indices, PathIndexType,
132                            const float transformValues[], PathTransformType, int count,
133                            const GrStencilSettings&) = 0;
134 protected:
GrPathRendering()135     GrPathRendering() { }
136 
137 private:
138     GrPathRendering& operator=(const GrPathRendering&);
139 };
140 
141 #endif
142