blob: 238c154489bdca6d44f879e2cd7650b1a45fcc47 [file] [log] [blame]
joshualitt4973d9d2014-11-08 09:24:25 -08001/*
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 GrDefaultGeoProcFactory_DEFINED
9#define GrDefaultGeoProcFactory_DEFINED
10
11#include "GrGeometryProcessor.h"
12
joshualitt4973d9d2014-11-08 09:24:25 -080013/*
14 * A factory for creating default Geometry Processors which simply multiply position by the uniform
Brian Salomon09d994e2016-12-21 11:14:46 -050015 * view matrix and wire through color, coverage, UV coords if requested.
joshualitt4973d9d2014-11-08 09:24:25 -080016 */
joshualitt7a0d6972015-07-28 10:20:08 -070017namespace GrDefaultGeoProcFactory {
joshualitt4973d9d2014-11-08 09:24:25 -080018 // Structs for adding vertex attributes
19 struct PositionAttr {
20 SkPoint fPosition;
21 };
22
23 struct PositionCoverageAttr {
24 SkPoint fPosition;
senorblancof57372d2016-08-31 10:36:19 -070025 float fCoverage;
joshualitt4973d9d2014-11-08 09:24:25 -080026 };
27
28 struct PositionColorAttr {
29 SkPoint fPosition;
30 SkColor fColor;
31 };
32
33 struct PositionColorCoverageAttr {
34 SkPoint fPosition;
35 SkColor fColor;
senorblancof57372d2016-08-31 10:36:19 -070036 float fCoverage;
joshualitt4973d9d2014-11-08 09:24:25 -080037 };
38
39 struct PositionLocalCoordAttr {
40 SkPoint fPosition;
41 SkPoint fLocalCoord;
42 };
43
44 struct PositionLocalCoordCoverageAttr {
45 SkPoint fPosition;
46 SkPoint fLocalCoord;
senorblancof57372d2016-08-31 10:36:19 -070047 float fCoverage;
joshualitt4973d9d2014-11-08 09:24:25 -080048 };
49
50 struct PositionColorLocalCoordAttr {
51 SkPoint fPosition;
52 GrColor fColor;
53 SkPoint fLocalCoord;
54 };
55
56 struct PositionColorLocalCoordCoverage {
57 SkPoint fPosition;
58 GrColor fColor;
59 SkPoint fLocalCoord;
senorblancof57372d2016-08-31 10:36:19 -070060 float fCoverage;
joshualitt4973d9d2014-11-08 09:24:25 -080061 };
62
joshualitte9d60952015-07-27 12:13:14 -070063 struct Color {
64 enum Type {
65 kNone_Type,
66 kUniform_Type,
67 kAttribute_Type,
68 };
Brian Salomon8c852be2017-01-04 10:44:42 -050069 explicit Color(GrColor color) : fType(kUniform_Type), fColor(color) {}
joshualitte9d60952015-07-27 12:13:14 -070070 Color(Type type) : fType(type), fColor(GrColor_ILLEGAL) {
71 SkASSERT(type != kUniform_Type);
72
73 // TODO This is temporary
74 if (kAttribute_Type == type) {
75 fColor = GrColor_WHITE;
76 }
77 }
78
79 Type fType;
80 GrColor fColor;
81 };
82
83 struct Coverage {
84 enum Type {
joshualitte9d60952015-07-27 12:13:14 -070085 kSolid_Type,
86 kUniform_Type,
87 kAttribute_Type,
88 };
Brian Salomon8c852be2017-01-04 10:44:42 -050089 explicit Coverage(uint8_t coverage) : fType(kUniform_Type), fCoverage(coverage) {}
joshualitte9d60952015-07-27 12:13:14 -070090 Coverage(Type type) : fType(type), fCoverage(0xff) {
91 SkASSERT(type != kUniform_Type);
92 }
93
94 Type fType;
95 uint8_t fCoverage;
96 };
97
98 struct LocalCoords {
99 enum Type {
joshualitt0d986d82015-07-28 10:01:18 -0700100 kUnused_Type,
joshualitte9d60952015-07-27 12:13:14 -0700101 kUsePosition_Type,
102 kHasExplicit_Type,
joshualittb2aa7cb2015-08-05 11:05:22 -0700103 kHasTransformed_Type,
joshualitte9d60952015-07-27 12:13:14 -0700104 };
halcanary96fcdcc2015-08-27 07:41:13 -0700105 LocalCoords(Type type) : fType(type), fMatrix(nullptr) {}
joshualitt0d986d82015-07-28 10:01:18 -0700106 LocalCoords(Type type, const SkMatrix* matrix) : fType(type), fMatrix(matrix) {
107 SkASSERT(kUnused_Type != type);
108 }
halcanary96fcdcc2015-08-27 07:41:13 -0700109 bool hasLocalMatrix() const { return nullptr != fMatrix; }
joshualitt0d986d82015-07-28 10:01:18 -0700110
111 Type fType;
112 const SkMatrix* fMatrix;
joshualitte9d60952015-07-27 12:13:14 -0700113 };
114
bungeman06ca8ec2016-06-09 08:01:03 -0700115 sk_sp<GrGeometryProcessor> Make(const Color&,
116 const Coverage&,
117 const LocalCoords&,
118 const SkMatrix& viewMatrix);
joshualitte9d60952015-07-27 12:13:14 -0700119
joshualitt5478d422014-11-14 16:00:38 -0800120 /*
joshualitt0d986d82015-07-28 10:01:18 -0700121 * Use this factory to create a GrGeometryProcessor that expects a device space vertex position
122 * attribute. The view matrix must still be provided to compute correctly transformed
123 * coordinates for GrFragmentProcessors. It may fail if the view matrix is not invertible.
joshualitt5478d422014-11-14 16:00:38 -0800124 */
bungeman06ca8ec2016-06-09 08:01:03 -0700125 sk_sp<GrGeometryProcessor> MakeForDeviceSpace(const Color&,
126 const Coverage&,
127 const LocalCoords&,
128 const SkMatrix& viewMatrix);
joshualitt4973d9d2014-11-08 09:24:25 -0800129};
130
131#endif