blob: 70fa61c27e6fe1fac25c4fee3453f240e2699af6 [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"
12
13class SkStrokeRec;
14class GrPath;
15class GrPathRange;
16class GrGpu;
17
18/**
19 * Abstract class wrapping HW path rendering API.
20 *
21 * The subclasses of this class use the possible HW API to render paths (as opposed to path
22 * rendering implemented in Skia on top of a "3d" HW API).
23 * The subclasses hold the global state needed to render paths, including shadow of the global HW
24 * API state. Similar to GrGpu.
25 *
26 * It is expected that the lifetimes of GrGpuXX and GrXXPathRendering are the same. The call context
27 * interface (eg. * the concrete instance of GrGpu subclass) should be provided to the instance
28 * during construction.
29 */
30class GrPathRendering {
31public:
32 virtual ~GrPathRendering() { }
33
34 enum PathTransformType {
35 kNone_PathTransformType, //!< []
36 kTranslateX_PathTransformType, //!< [kMTransX]
37 kTranslateY_PathTransformType, //!< [kMTransY]
38 kTranslate_PathTransformType, //!< [kMTransX, kMTransY]
39 kAffine_PathTransformType, //!< [kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY]
40
41 kLast_PathTransformType = kAffine_PathTransformType
42 };
43
44 static inline int PathTransformSize(PathTransformType type) {
45 switch (type) {
46 case kNone_PathTransformType:
47 return 0;
48 case kTranslateX_PathTransformType:
49 case kTranslateY_PathTransformType:
50 return 1;
51 case kTranslate_PathTransformType:
52 return 2;
53 case kAffine_PathTransformType:
54 return 6;
55
56 default:
57 SkFAIL("Unknown path transform type");
58 return 0;
59 }
60 }
61
cdalton4e205b12014-09-17 09:41:24 -070062 /**
63 * Creates a new gpu path, based on the specified path and stroke and returns it.
64 * The caller owns a ref on the returned path which must be balanced by a call to unref.
65 *
66 * @param skPath the path geometry.
67 * @param stroke the path stroke.
68 * @return a new path.
69 */
kkinnunenccdaa042014-08-20 01:36:23 -070070 virtual GrPath* createPath(const SkPath&, const SkStrokeRec&) = 0;
cdalton4e205b12014-09-17 09:41:24 -070071
72 /**
73 * Creates a range of gpu paths with a common stroke. The caller owns a ref on the
74 * returned path range which must be balanced by a call to unref.
75 *
76 * @param PathGenerator class that generates SkPath objects for each path in the range.
77 * @param SkStrokeRec the common stroke applied to each path in the range.
78 * @return a new path range.
79 */
kkinnunenccdaa042014-08-20 01:36:23 -070080 virtual GrPathRange* createPathRange(size_t size, const SkStrokeRec&) = 0;
cdalton4e205b12014-09-17 09:41:24 -070081
kkinnunenccdaa042014-08-20 01:36:23 -070082 virtual void stencilPath(const GrPath*, SkPath::FillType) = 0;
83 virtual void drawPath(const GrPath*, SkPath::FillType) = 0;
84 virtual void drawPaths(const GrPathRange*, const uint32_t indices[], int count,
85 const float transforms[], PathTransformType, SkPath::FillType) = 0;
86protected:
87 GrPathRendering() { }
88
89private:
90 GrPathRendering& operator=(const GrPathRendering&);
91};
92
93#endif