blob: 3ae52e98830eabcdb5a7cfaedc1953ff7a7d97c8 [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"
bsalomoncb02b382015-08-12 11:14:50 -070012#include "GrPipeline.h"
kkinnunenccdaa042014-08-20 01:36:23 -070013
Robert Phillips646e4292017-06-13 12:44:56 -040014class GrGpu;
kkinnunenccdaa042014-08-20 01:36:23 -070015class GrPath;
joshualitt92e496f2014-10-31 13:56:50 -070016class GrStencilSettings;
bsalomon6663acf2016-05-10 09:14:17 -070017class GrStyle;
Brian Salomon2bbdcc42017-09-07 12:36:34 -040018struct SkScalerContextEffects;
19class SkDescriptor;
20class SkTypeface;
kkinnunenccdaa042014-08-20 01:36:23 -070021
22/**
23 * Abstract class wrapping HW path rendering API.
24 *
25 * The subclasses of this class use the possible HW API to render paths (as opposed to path
26 * rendering implemented in Skia on top of a "3d" HW API).
27 * The subclasses hold the global state needed to render paths, including shadow of the global HW
28 * API state. Similar to GrGpu.
29 *
30 * It is expected that the lifetimes of GrGpuXX and GrXXPathRendering are the same. The call context
31 * interface (eg. * the concrete instance of GrGpu subclass) should be provided to the instance
32 * during construction.
33 */
34class GrPathRendering {
35public:
36 virtual ~GrPathRendering() { }
37
38 enum PathTransformType {
39 kNone_PathTransformType, //!< []
40 kTranslateX_PathTransformType, //!< [kMTransX]
41 kTranslateY_PathTransformType, //!< [kMTransY]
42 kTranslate_PathTransformType, //!< [kMTransX, kMTransY]
43 kAffine_PathTransformType, //!< [kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY]
44
45 kLast_PathTransformType = kAffine_PathTransformType
46 };
47
48 static inline int PathTransformSize(PathTransformType type) {
49 switch (type) {
50 case kNone_PathTransformType:
51 return 0;
52 case kTranslateX_PathTransformType:
53 case kTranslateY_PathTransformType:
54 return 1;
55 case kTranslate_PathTransformType:
56 return 2;
57 case kAffine_PathTransformType:
58 return 6;
59
60 default:
Ben Wagnerb4aab9a2017-08-16 10:53:04 -040061 SK_ABORT("Unknown path transform type");
kkinnunenccdaa042014-08-20 01:36:23 -070062 return 0;
63 }
64 }
65
cdalton55b24af2014-11-25 11:00:56 -080066 // No native support for inverse at this time
67 enum FillType {
68 /** Specifies that "inside" is computed by a non-zero sum of signed
69 edge crossings
70 */
71 kWinding_FillType,
72 /** Specifies that "inside" is computed by an odd number of edge
73 crossings
74 */
75 kEvenOdd_FillType,
76 };
77
cdalton193d9cf2016-05-12 11:52:02 -070078 static const GrUserStencilSettings& GetStencilPassSettings(FillType);
79
cdalton4e205b12014-09-17 09:41:24 -070080 /**
81 * Creates a new gpu path, based on the specified path and stroke and returns it.
cdalton4e205b12014-09-17 09:41:24 -070082 *
bsalomon6663acf2016-05-10 09:14:17 -070083 * @param SkPath the geometry.
84 * @param GrStyle the style applied to the path. Styles with non-dash path effects are not
85 * allowed.
86 * @return a new GPU path object.
cdalton4e205b12014-09-17 09:41:24 -070087 */
Robert Phillips67d52cf2017-06-05 13:38:13 -040088 virtual sk_sp<GrPath> createPath(const SkPath&, const GrStyle&) = 0;
cdalton4e205b12014-09-17 09:41:24 -070089
kkinnunencabe20c2015-06-01 01:37:26 -070090 /** None of these params are optional, pointers used just to avoid making copies. */
91 struct StencilPathArgs {
92 StencilPathArgs(bool useHWAA,
Robert Phillips7311b402017-07-27 12:01:46 -040093 GrRenderTargetProxy* proxy,
kkinnunencabe20c2015-06-01 01:37:26 -070094 const SkMatrix* viewMatrix,
95 const GrScissorState* scissor,
96 const GrStencilSettings* stencil)
97 : fUseHWAA(useHWAA)
Robert Phillips7311b402017-07-27 12:01:46 -040098 , fProxy(proxy)
kkinnunencabe20c2015-06-01 01:37:26 -070099 , fViewMatrix(viewMatrix)
100 , fScissor(scissor)
101 , fStencil(stencil) {
102 }
Robert Phillips7311b402017-07-27 12:01:46 -0400103 bool fUseHWAA;
104 GrRenderTargetProxy* fProxy;
105 const SkMatrix* fViewMatrix;
106 const GrScissorState* fScissor;
kkinnunencabe20c2015-06-01 01:37:26 -0700107 const GrStencilSettings* fStencil;
108 };
kkinnunenccdaa042014-08-20 01:36:23 -0700109
Robert Phillips646e4292017-06-13 12:44:56 -0400110 void stencilPath(const StencilPathArgs& args, const GrPath* path);
kkinnunencabe20c2015-06-01 01:37:26 -0700111
Brian Salomonff168d92018-06-23 15:17:27 -0400112 void drawPath(const GrPrimitiveProcessor& primProc,
113 const GrPipeline& pipeline,
Brian Salomon49348902018-06-26 09:12:38 -0400114 const GrPipeline::FixedDynamicState&,
Brian Salomonff168d92018-06-23 15:17:27 -0400115 const GrStencilSettings& stencilPassSettings, // Cover pass settings in pipeline.
Robert Phillips646e4292017-06-13 12:44:56 -0400116 const GrPath* path);
stephana1dc17212016-04-25 07:01:22 -0700117
kkinnunencabe20c2015-06-01 01:37:26 -0700118protected:
Robert Phillips646e4292017-06-13 12:44:56 -0400119 GrPathRendering(GrGpu* gpu) : fGpu(gpu) { }
120
kkinnunencabe20c2015-06-01 01:37:26 -0700121 virtual void onStencilPath(const StencilPathArgs&, const GrPath*) = 0;
Brian Salomonff168d92018-06-23 15:17:27 -0400122 virtual void onDrawPath(const GrPrimitiveProcessor&,
123 const GrPipeline&,
Brian Salomon49348902018-06-26 09:12:38 -0400124 const GrPipeline::FixedDynamicState&,
stephana1dc17212016-04-25 07:01:22 -0700125 const GrStencilSettings&,
126 const GrPath*) = 0;
kkinnunencabe20c2015-06-01 01:37:26 -0700127
128 GrGpu* fGpu;
kkinnunenccdaa042014-08-20 01:36:23 -0700129private:
130 GrPathRendering& operator=(const GrPathRendering&);
131};
132
133#endif