2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef GrPathRendering_DEFINED
9 #define GrPathRendering_DEFINED
12 #include "GrPathRange.h"
21 * Abstract class wrapping HW path rendering API.
23 * The subclasses of this class use the possible HW API to render paths (as opposed to path
24 * rendering implemented in Skia on top of a "3d" HW API).
25 * The subclasses hold the global state needed to render paths, including shadow of the global HW
26 * API state. Similar to GrGpu.
28 * It is expected that the lifetimes of GrGpuXX and GrXXPathRendering are the same. The call context
29 * interface (eg. * the concrete instance of GrGpu subclass) should be provided to the instance
30 * during construction.
32 class GrPathRendering {
34 virtual ~GrPathRendering() { }
36 enum PathTransformType {
37 kNone_PathTransformType, //!< []
38 kTranslateX_PathTransformType, //!< [kMTransX]
39 kTranslateY_PathTransformType, //!< [kMTransY]
40 kTranslate_PathTransformType, //!< [kMTransX, kMTransY]
41 kAffine_PathTransformType, //!< [kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY]
43 kLast_PathTransformType = kAffine_PathTransformType
46 static inline int PathTransformSize(PathTransformType type) {
48 case kNone_PathTransformType:
50 case kTranslateX_PathTransformType:
51 case kTranslateY_PathTransformType:
53 case kTranslate_PathTransformType:
55 case kAffine_PathTransformType:
59 SkFAIL("Unknown path transform type");
65 * Creates a new gpu path, based on the specified path and stroke and returns it.
66 * The caller owns a ref on the returned path which must be balanced by a call to unref.
68 * @param skPath the path geometry.
69 * @param stroke the path stroke.
72 virtual GrPath* createPath(const SkPath&, const SkStrokeRec&) = 0;
75 * Creates a range of gpu paths with a common stroke. The caller owns a ref on the
76 * returned path range which must be balanced by a call to unref.
78 * @param PathGenerator class that generates SkPath objects for each path in the range.
79 * @param SkStrokeRec the common stroke applied to each path in the range.
80 * @return a new path range.
82 virtual GrPathRange* createPathRange(GrPathRange::PathGenerator*, const SkStrokeRec&) = 0;
85 * Creates a range of glyph paths, indexed by glyph id. The glyphs will have an
86 * inverted y-direction in order to match the raw font path data. The caller owns
87 * a ref on the returned path range which must be balanced by a call to unref.
89 * @param SkTypeface Typeface that defines the glyphs.
90 * If null, the default typeface will be used.
92 * @param SkDescriptor Additional font configuration that specifies the font's size,
93 * stroke, and other flags. This will generally come from an
96 * It is recommended to leave this value null when possible, in
97 * which case the glyphs will be loaded directly from the font's
98 * raw path data and sized at SkPaint::kCanonicalTextSizeForPaths.
99 * This will result in less memory usage and more efficient paths.
101 * If non-null, the glyph paths will match the font descriptor,
102 * including with the stroke information baked directly into
105 * @param SkStrokeRec Common stroke that the GPU will apply to every path. Note that
106 * if the glyph outlines contain baked-in strokes from the font
107 * descriptor, the GPU stroke will be applied on top of those
110 * @return a new path range populated with glyphs.
112 virtual GrPathRange* createGlyphs(const SkTypeface*, const SkDescriptor*, const SkStrokeRec&) = 0;
114 virtual void stencilPath(const GrPath*, SkPath::FillType) = 0;
115 virtual void drawPath(const GrPath*, SkPath::FillType) = 0;
116 virtual void drawPaths(const GrPathRange*, const uint32_t indices[], int count,
117 const float transforms[], PathTransformType, SkPath::FillType) = 0;
119 GrPathRendering() { }
122 GrPathRendering& operator=(const GrPathRendering&);