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 "include/core/SkPath.h"
12
13class GrGpu;
14class GrPath;
15class GrProgramInfo;
16class GrRenderTarget;
17class GrRenderTargetProxy;
18class GrScissorState;
19class GrStencilSettings;
20class GrStyle;
21struct GrUserStencilSettings;
22struct SkScalerContextEffects;
23class SkDescriptor;
24class SkTypeface;
25
26/**
27 * Abstract class wrapping HW path rendering API.
28 *
29 * The subclasses of this class use the possible HW API to render paths (as opposed to path
30 * rendering implemented in Skia on top of a "3d" HW API).
31 * The subclasses hold the global state needed to render paths, including shadow of the global HW
32 * API state. Similar to GrGpu.
33 *
34 * It is expected that the lifetimes of GrGpuXX and GrXXPathRendering are the same. The call context
35 * interface (eg. * the concrete instance of GrGpu subclass) should be provided to the instance
36 * during construction.
37 */
38class GrPathRendering {
39public:
40 virtual ~GrPathRendering() { }
41
42 enum PathTransformType {
43 kNone_PathTransformType, //!< []
44 kTranslateX_PathTransformType, //!< [kMTransX]
45 kTranslateY_PathTransformType, //!< [kMTransY]
46 kTranslate_PathTransformType, //!< [kMTransX, kMTransY]
47 kAffine_PathTransformType, //!< [kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY]
48
49 kLast_PathTransformType = kAffine_PathTransformType
50 };
51
52 static inline int PathTransformSize(PathTransformType type) {
53 switch (type) {
54 case kNone_PathTransformType:
55 return 0;
56 case kTranslateX_PathTransformType:
57 case kTranslateY_PathTransformType:
58 return 1;
59 case kTranslate_PathTransformType:
60 return 2;
61 case kAffine_PathTransformType:
62 return 6;
63
64 default:
65 SK_ABORT("Unknown path transform type");
66 }
67 }
68
69 // No native support for inverse at this time
70 enum FillType {
71 /** Specifies that "inside" is computed by a non-zero sum of signed
72 edge crossings
73 */
74 kWinding_FillType,
75 /** Specifies that "inside" is computed by an odd number of edge
76 crossings
77 */
78 kEvenOdd_FillType,
79 };
80
81 static const GrUserStencilSettings& GetStencilPassSettings(FillType);
82
83 /**
84 * Creates a new gpu path, based on the specified path and stroke and returns it.
85 *
86 * @param SkPath the geometry.
87 * @param GrStyle the style applied to the path. Styles with non-dash path effects are not
88 * allowed.
89 * @return a new GPU path object.
90 */
91 virtual sk_sp<GrPath> createPath(const SkPath&, const GrStyle&) = 0;
92
93 /** None of these params are optional, pointers used just to avoid making copies. */
94 struct StencilPathArgs {
95 StencilPathArgs(bool useHWAA,
96 GrRenderTargetProxy* proxy,
97 GrSurfaceOrigin origin,
98 const SkMatrix* viewMatrix,
99 const GrScissorState* scissor,
100 const GrStencilSettings* stencil)
101 : fUseHWAA(useHWAA)
102 , fProxy(proxy)
103 , fOrigin(origin)
104 , fViewMatrix(viewMatrix)
105 , fScissor(scissor)
106 , fStencil(stencil) {
107 }
108 bool fUseHWAA;
109 GrRenderTargetProxy* fProxy;
110 GrSurfaceOrigin fOrigin;
111 const SkMatrix* fViewMatrix;
112 const GrScissorState* fScissor;
113 const GrStencilSettings* fStencil;
114 };
115
116 void stencilPath(const StencilPathArgs& args, const GrPath* path);
117
118 void drawPath(GrRenderTarget*,
119 const GrProgramInfo&,
120 const GrStencilSettings& stencilPassSettings, // Cover pass settings in pipeline.
121 const GrPath* path);
122
123protected:
124 GrPathRendering(GrGpu* gpu) : fGpu(gpu) { }
125
126 virtual void onStencilPath(const StencilPathArgs&, const GrPath*) = 0;
127 virtual void onDrawPath(const GrStencilSettings&, const GrPath*) = 0;
128
129 GrGpu* fGpu;
130private:
131 GrPathRendering& operator=(const GrPathRendering&);
132};
133
134#endif
135