blob: 00ee90d9400bd88bde1dfd73e437dee0718ea064 [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 {
Brian Salomon3de0aee2017-01-29 09:34:17 -050065 kPremulGrColorUniform_Type,
66 kPremulGrColorAttribute_Type,
67 kUnpremulSkColorAttribute_Type,
joshualitte9d60952015-07-27 12:13:14 -070068 };
Brian Salomon3de0aee2017-01-29 09:34:17 -050069 explicit Color(GrColor color) : fType(kPremulGrColorUniform_Type), fColor(color) {}
joshualitte9d60952015-07-27 12:13:14 -070070 Color(Type type) : fType(type), fColor(GrColor_ILLEGAL) {
Brian Salomon3de0aee2017-01-29 09:34:17 -050071 SkASSERT(type != kPremulGrColorUniform_Type);
joshualitte9d60952015-07-27 12:13:14 -070072 }
73
74 Type fType;
75 GrColor fColor;
76 };
77
78 struct Coverage {
79 enum Type {
joshualitte9d60952015-07-27 12:13:14 -070080 kSolid_Type,
81 kUniform_Type,
82 kAttribute_Type,
83 };
Brian Salomon8c852be2017-01-04 10:44:42 -050084 explicit Coverage(uint8_t coverage) : fType(kUniform_Type), fCoverage(coverage) {}
joshualitte9d60952015-07-27 12:13:14 -070085 Coverage(Type type) : fType(type), fCoverage(0xff) {
86 SkASSERT(type != kUniform_Type);
87 }
88
89 Type fType;
90 uint8_t fCoverage;
91 };
92
93 struct LocalCoords {
94 enum Type {
joshualitt0d986d82015-07-28 10:01:18 -070095 kUnused_Type,
joshualitte9d60952015-07-27 12:13:14 -070096 kUsePosition_Type,
97 kHasExplicit_Type,
joshualittb2aa7cb2015-08-05 11:05:22 -070098 kHasTransformed_Type,
joshualitte9d60952015-07-27 12:13:14 -070099 };
halcanary96fcdcc2015-08-27 07:41:13 -0700100 LocalCoords(Type type) : fType(type), fMatrix(nullptr) {}
joshualitt0d986d82015-07-28 10:01:18 -0700101 LocalCoords(Type type, const SkMatrix* matrix) : fType(type), fMatrix(matrix) {
102 SkASSERT(kUnused_Type != type);
103 }
halcanary96fcdcc2015-08-27 07:41:13 -0700104 bool hasLocalMatrix() const { return nullptr != fMatrix; }
joshualitt0d986d82015-07-28 10:01:18 -0700105
106 Type fType;
107 const SkMatrix* fMatrix;
joshualitte9d60952015-07-27 12:13:14 -0700108 };
109
bungeman06ca8ec2016-06-09 08:01:03 -0700110 sk_sp<GrGeometryProcessor> Make(const Color&,
111 const Coverage&,
112 const LocalCoords&,
113 const SkMatrix& viewMatrix);
joshualitte9d60952015-07-27 12:13:14 -0700114
joshualitt5478d422014-11-14 16:00:38 -0800115 /*
joshualitt0d986d82015-07-28 10:01:18 -0700116 * Use this factory to create a GrGeometryProcessor that expects a device space vertex position
117 * attribute. The view matrix must still be provided to compute correctly transformed
118 * coordinates for GrFragmentProcessors. It may fail if the view matrix is not invertible.
joshualitt5478d422014-11-14 16:00:38 -0800119 */
bungeman06ca8ec2016-06-09 08:01:03 -0700120 sk_sp<GrGeometryProcessor> MakeForDeviceSpace(const Color&,
121 const Coverage&,
122 const LocalCoords&,
123 const SkMatrix& viewMatrix);
joshualitt4973d9d2014-11-08 09:24:25 -0800124};
125
126#endif