blob: 3e2cfc6c9aefb345bff2442ebd7b2d11d412ba3a [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"
kkinnunenccdaa042014-08-20 01:36:23 -070013
14class SkStrokeRec;
cdalton855d83f2014-09-18 13:51:53 -070015class SkDescriptor;
16class SkTypeface;
kkinnunenccdaa042014-08-20 01:36:23 -070017class GrPath;
kkinnunenccdaa042014-08-20 01:36:23 -070018class GrGpu;
joshualitt92e496f2014-10-31 13:56:50 -070019class GrStencilSettings;
kkinnunenccdaa042014-08-20 01:36:23 -070020
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 */
33class GrPathRendering {
34public:
35 virtual ~GrPathRendering() { }
36
cdalton55b24af2014-11-25 11:00:56 -080037 typedef GrPathRange::PathIndexType PathIndexType;
joshualitt92e496f2014-10-31 13:56:50 -070038
kkinnunenccdaa042014-08-20 01:36:23 -070039 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
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
cdalton55b24af2014-11-25 11:00:56 -080067 // 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
cdalton4e205b12014-09-17 09:41:24 -070079 /**
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 */
kkinnunenccdaa042014-08-20 01:36:23 -070087 virtual GrPath* createPath(const SkPath&, const SkStrokeRec&) = 0;
cdalton4e205b12014-09-17 09:41:24 -070088
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 */
cdalton855d83f2014-09-18 13:51:53 -070097 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;
cdalton4e205b12014-09-17 09:41:24 -0700128
joshualitt92e496f2014-10-31 13:56:50 -0700129 virtual void stencilPath(const GrPath*, const GrStencilSettings&) = 0;
130 virtual void drawPath(const GrPath*, const GrStencilSettings&) = 0;
cdalton55b24af2014-11-25 11:00:56 -0800131 virtual void drawPaths(const GrPathRange*, const void* indices, PathIndexType,
132 const float transformValues[], PathTransformType, int count,
joshualitt92e496f2014-10-31 13:56:50 -0700133 const GrStencilSettings&) = 0;
kkinnunenccdaa042014-08-20 01:36:23 -0700134protected:
135 GrPathRendering() { }
136
137private:
138 GrPathRendering& operator=(const GrPathRendering&);
139};
140
141#endif