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 20 /** 21 * Abstract class wrapping HW path rendering API. 22 * 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. 27 * 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. 31 */ 32 class GrPathRendering { 33 public: 34 virtual ~GrPathRendering() { } 35 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] 42 43 kLast_PathTransformType = kAffine_PathTransformType 44 }; 45 46 static inline int PathTransformSize(PathTransformType type) { 47 switch (type) { 48 case kNone_PathTransformType: 49 return 0; 50 case kTranslateX_PathTransformType: 51 case kTranslateY_PathTransformType: 52 return 1; 53 case kTranslate_PathTransformType: 54 return 2; 55 case kAffine_PathTransformType: 56 return 6; 57 58 default: 59 SkFAIL("Unknown path transform type"); 60 return 0; 61 } 62 } 63 64 /** 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. 67 * 68 * @param skPath the path geometry. 69 * @param stroke the path stroke. 70 * @return a new path. 71 */ 72 virtual GrPath* createPath(const SkPath&, const SkStrokeRec&) = 0; 73 74 /** 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. 77 * 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. 81 */ 82 virtual GrPathRange* createPathRange(GrPathRange::PathGenerator*, const SkStrokeRec&) = 0; 83 84 /** 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. 88 * 89 * @param SkTypeface Typeface that defines the glyphs. 90 * If null, the default typeface will be used. 91 * 92 * @param SkDescriptor Additional font configuration that specifies the font's size, 93 * stroke, and other flags. This will generally come from an 94 * SkGlyphCache. 95 * 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. 100 * 101 * If non-null, the glyph paths will match the font descriptor, 102 * including with the stroke information baked directly into 103 * the outlines. 104 * 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 108 * outlines. 109 * 110 * @return a new path range populated with glyphs. 111 */ 112 virtual GrPathRange* createGlyphs(const SkTypeface*, const SkDescriptor*, const SkStrokeRec&) = 0; 113 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; 118 protected: 119 GrPathRendering() { } 120 121 private: 122 GrPathRendering& operator=(const GrPathRendering&); 123 }; 124 125 #endif 126