blob: 3c4bd8ea4616e93ff1f809810b15839b0806106f [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
Brian Salomon0c26a9d2017-07-06 10:09:38 -040011#include "GrColorSpaceXform.h"
joshualitt4973d9d2014-11-08 09:24:25 -080012#include "GrGeometryProcessor.h"
Ruiqi Maob609e6d2018-07-17 10:19:38 -040013#include "GrShaderCaps.h"
joshualitt4973d9d2014-11-08 09:24:25 -080014
joshualitt4973d9d2014-11-08 09:24:25 -080015/*
16 * A factory for creating default Geometry Processors which simply multiply position by the uniform
Brian Salomon09d994e2016-12-21 11:14:46 -050017 * view matrix and wire through color, coverage, UV coords if requested.
joshualitt4973d9d2014-11-08 09:24:25 -080018 */
joshualitt7a0d6972015-07-28 10:20:08 -070019namespace GrDefaultGeoProcFactory {
joshualitt4973d9d2014-11-08 09:24:25 -080020 // Structs for adding vertex attributes
21 struct PositionAttr {
22 SkPoint fPosition;
23 };
24
25 struct PositionCoverageAttr {
26 SkPoint fPosition;
senorblancof57372d2016-08-31 10:36:19 -070027 float fCoverage;
joshualitt4973d9d2014-11-08 09:24:25 -080028 };
29
30 struct PositionColorAttr {
31 SkPoint fPosition;
32 SkColor fColor;
33 };
34
35 struct PositionColorCoverageAttr {
36 SkPoint fPosition;
37 SkColor fColor;
senorblancof57372d2016-08-31 10:36:19 -070038 float fCoverage;
joshualitt4973d9d2014-11-08 09:24:25 -080039 };
40
41 struct PositionLocalCoordAttr {
42 SkPoint fPosition;
43 SkPoint fLocalCoord;
44 };
45
46 struct PositionLocalCoordCoverageAttr {
47 SkPoint fPosition;
48 SkPoint fLocalCoord;
senorblancof57372d2016-08-31 10:36:19 -070049 float fCoverage;
joshualitt4973d9d2014-11-08 09:24:25 -080050 };
51
52 struct PositionColorLocalCoordAttr {
53 SkPoint fPosition;
54 GrColor fColor;
55 SkPoint fLocalCoord;
56 };
57
Ruiqi Mao4ec72f72018-07-10 17:21:07 -040058 struct PositionColorLocalCoordCoverageAttr {
joshualitt4973d9d2014-11-08 09:24:25 -080059 SkPoint fPosition;
60 GrColor fColor;
61 SkPoint fLocalCoord;
senorblancof57372d2016-08-31 10:36:19 -070062 float fCoverage;
joshualitt4973d9d2014-11-08 09:24:25 -080063 };
64
joshualitte9d60952015-07-27 12:13:14 -070065 struct Color {
66 enum Type {
Brian Salomon3de0aee2017-01-29 09:34:17 -050067 kPremulGrColorUniform_Type,
68 kPremulGrColorAttribute_Type,
69 kUnpremulSkColorAttribute_Type,
joshualitte9d60952015-07-27 12:13:14 -070070 };
Brian Osmanfa6d8652017-05-31 09:37:27 -040071 explicit Color(GrColor color)
72 : fType(kPremulGrColorUniform_Type)
73 , fColor(color)
Brian Osmanfa6d8652017-05-31 09:37:27 -040074 , fColorSpaceXform(nullptr) {}
75 Color(Type type)
76 : fType(type)
77 , fColor(GrColor_ILLEGAL)
Brian Osmanfa6d8652017-05-31 09:37:27 -040078 , fColorSpaceXform(nullptr) {
Brian Salomon3de0aee2017-01-29 09:34:17 -050079 SkASSERT(type != kPremulGrColorUniform_Type);
joshualitte9d60952015-07-27 12:13:14 -070080 }
81
82 Type fType;
83 GrColor fColor;
Brian Osmanfa6d8652017-05-31 09:37:27 -040084
Brian Osman08a50e02018-06-15 15:06:48 -040085 // This only applies to SkColor. Any GrColors are assumed to have been color converted
Brian Osmanfa6d8652017-05-31 09:37:27 -040086 // during paint conversion.
Brian Osmanfa6d8652017-05-31 09:37:27 -040087 sk_sp<GrColorSpaceXform> fColorSpaceXform;
joshualitte9d60952015-07-27 12:13:14 -070088 };
89
90 struct Coverage {
91 enum Type {
joshualitte9d60952015-07-27 12:13:14 -070092 kSolid_Type,
93 kUniform_Type,
94 kAttribute_Type,
95 };
Brian Salomon8c852be2017-01-04 10:44:42 -050096 explicit Coverage(uint8_t coverage) : fType(kUniform_Type), fCoverage(coverage) {}
joshualitte9d60952015-07-27 12:13:14 -070097 Coverage(Type type) : fType(type), fCoverage(0xff) {
98 SkASSERT(type != kUniform_Type);
99 }
100
101 Type fType;
102 uint8_t fCoverage;
103 };
104
105 struct LocalCoords {
106 enum Type {
joshualitt0d986d82015-07-28 10:01:18 -0700107 kUnused_Type,
joshualitte9d60952015-07-27 12:13:14 -0700108 kUsePosition_Type,
109 kHasExplicit_Type,
joshualittb2aa7cb2015-08-05 11:05:22 -0700110 kHasTransformed_Type,
joshualitte9d60952015-07-27 12:13:14 -0700111 };
halcanary96fcdcc2015-08-27 07:41:13 -0700112 LocalCoords(Type type) : fType(type), fMatrix(nullptr) {}
joshualitt0d986d82015-07-28 10:01:18 -0700113 LocalCoords(Type type, const SkMatrix* matrix) : fType(type), fMatrix(matrix) {
114 SkASSERT(kUnused_Type != type);
115 }
halcanary96fcdcc2015-08-27 07:41:13 -0700116 bool hasLocalMatrix() const { return nullptr != fMatrix; }
joshualitt0d986d82015-07-28 10:01:18 -0700117
118 Type fType;
119 const SkMatrix* fMatrix;
joshualitte9d60952015-07-27 12:13:14 -0700120 };
121
Ruiqi Mao4ec72f72018-07-10 17:21:07 -0400122 struct Bones {
123 Bones(const float bones[], int boneCount)
124 : fBones(bones)
125 , fBoneCount(boneCount) {}
126
127 const float* fBones;
128 int fBoneCount;
129 };
130
Ruiqi Maob609e6d2018-07-17 10:19:38 -0400131 sk_sp<GrGeometryProcessor> Make(const GrShaderCaps*,
132 const Color&,
bungeman06ca8ec2016-06-09 08:01:03 -0700133 const Coverage&,
134 const LocalCoords&,
135 const SkMatrix& viewMatrix);
joshualitte9d60952015-07-27 12:13:14 -0700136
joshualitt5478d422014-11-14 16:00:38 -0800137 /*
joshualitt0d986d82015-07-28 10:01:18 -0700138 * Use this factory to create a GrGeometryProcessor that expects a device space vertex position
139 * attribute. The view matrix must still be provided to compute correctly transformed
140 * coordinates for GrFragmentProcessors. It may fail if the view matrix is not invertible.
joshualitt5478d422014-11-14 16:00:38 -0800141 */
Ruiqi Maob609e6d2018-07-17 10:19:38 -0400142 sk_sp<GrGeometryProcessor> MakeForDeviceSpace(const GrShaderCaps*,
143 const Color&,
bungeman06ca8ec2016-06-09 08:01:03 -0700144 const Coverage&,
145 const LocalCoords&,
146 const SkMatrix& viewMatrix);
Ruiqi Mao4ec72f72018-07-10 17:21:07 -0400147
148 /*
149 * Use this factory to create a GrGeometryProcessor that supports skeletal animation through
150 * deformation of vertices using matrices that are passed in. This should only be called from
151 * GrDrawVerticesOp.
152 */
Ruiqi Maob609e6d2018-07-17 10:19:38 -0400153 sk_sp<GrGeometryProcessor> MakeWithBones(const GrShaderCaps*,
154 const Color&,
Ruiqi Mao4ec72f72018-07-10 17:21:07 -0400155 const Coverage&,
156 const LocalCoords&,
157 const Bones&,
158 const SkMatrix& viewMatrix);
joshualitt4973d9d2014-11-08 09:24:25 -0800159};
160
161#endif