blob: 66f27589dde304b645ffbb4f1d0e128d3117c3f0 [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"
13
joshualitt4973d9d2014-11-08 09:24:25 -080014/*
15 * A factory for creating default Geometry Processors which simply multiply position by the uniform
Brian Salomon09d994e2016-12-21 11:14:46 -050016 * view matrix and wire through color, coverage, UV coords if requested.
joshualitt4973d9d2014-11-08 09:24:25 -080017 */
joshualitt7a0d6972015-07-28 10:20:08 -070018namespace GrDefaultGeoProcFactory {
joshualitt4973d9d2014-11-08 09:24:25 -080019 // Structs for adding vertex attributes
20 struct PositionAttr {
21 SkPoint fPosition;
22 };
23
24 struct PositionCoverageAttr {
25 SkPoint fPosition;
senorblancof57372d2016-08-31 10:36:19 -070026 float fCoverage;
joshualitt4973d9d2014-11-08 09:24:25 -080027 };
28
29 struct PositionColorAttr {
30 SkPoint fPosition;
31 SkColor fColor;
32 };
33
34 struct PositionColorCoverageAttr {
35 SkPoint fPosition;
36 SkColor fColor;
senorblancof57372d2016-08-31 10:36:19 -070037 float fCoverage;
joshualitt4973d9d2014-11-08 09:24:25 -080038 };
39
40 struct PositionLocalCoordAttr {
41 SkPoint fPosition;
42 SkPoint fLocalCoord;
43 };
44
45 struct PositionLocalCoordCoverageAttr {
46 SkPoint fPosition;
47 SkPoint fLocalCoord;
senorblancof57372d2016-08-31 10:36:19 -070048 float fCoverage;
joshualitt4973d9d2014-11-08 09:24:25 -080049 };
50
51 struct PositionColorLocalCoordAttr {
52 SkPoint fPosition;
53 GrColor fColor;
54 SkPoint fLocalCoord;
55 };
56
57 struct PositionColorLocalCoordCoverage {
58 SkPoint fPosition;
59 GrColor fColor;
60 SkPoint fLocalCoord;
senorblancof57372d2016-08-31 10:36:19 -070061 float fCoverage;
joshualitt4973d9d2014-11-08 09:24:25 -080062 };
63
joshualitte9d60952015-07-27 12:13:14 -070064 struct Color {
65 enum Type {
Brian Salomon3de0aee2017-01-29 09:34:17 -050066 kPremulGrColorUniform_Type,
67 kPremulGrColorAttribute_Type,
68 kUnpremulSkColorAttribute_Type,
joshualitte9d60952015-07-27 12:13:14 -070069 };
Brian Osmanfa6d8652017-05-31 09:37:27 -040070 explicit Color(GrColor color)
71 : fType(kPremulGrColorUniform_Type)
72 , fColor(color)
73 , fLinearize(false)
74 , fColorSpaceXform(nullptr) {}
75 Color(Type type)
76 : fType(type)
77 , fColor(GrColor_ILLEGAL)
78 , fLinearize(false)
79 , fColorSpaceXform(nullptr) {
Brian Salomon3de0aee2017-01-29 09:34:17 -050080 SkASSERT(type != kPremulGrColorUniform_Type);
joshualitte9d60952015-07-27 12:13:14 -070081 }
82
83 Type fType;
84 GrColor fColor;
Brian Osmanfa6d8652017-05-31 09:37:27 -040085
86 // These options only apply to SkColor. Any GrColors are assumed to have been color managed
87 // during paint conversion.
88 bool fLinearize;
89 sk_sp<GrColorSpaceXform> fColorSpaceXform;
joshualitte9d60952015-07-27 12:13:14 -070090 };
91
92 struct Coverage {
93 enum Type {
joshualitte9d60952015-07-27 12:13:14 -070094 kSolid_Type,
95 kUniform_Type,
96 kAttribute_Type,
97 };
Brian Salomon8c852be2017-01-04 10:44:42 -050098 explicit Coverage(uint8_t coverage) : fType(kUniform_Type), fCoverage(coverage) {}
joshualitte9d60952015-07-27 12:13:14 -070099 Coverage(Type type) : fType(type), fCoverage(0xff) {
100 SkASSERT(type != kUniform_Type);
101 }
102
103 Type fType;
104 uint8_t fCoverage;
105 };
106
107 struct LocalCoords {
108 enum Type {
joshualitt0d986d82015-07-28 10:01:18 -0700109 kUnused_Type,
joshualitte9d60952015-07-27 12:13:14 -0700110 kUsePosition_Type,
111 kHasExplicit_Type,
joshualittb2aa7cb2015-08-05 11:05:22 -0700112 kHasTransformed_Type,
joshualitte9d60952015-07-27 12:13:14 -0700113 };
halcanary96fcdcc2015-08-27 07:41:13 -0700114 LocalCoords(Type type) : fType(type), fMatrix(nullptr) {}
joshualitt0d986d82015-07-28 10:01:18 -0700115 LocalCoords(Type type, const SkMatrix* matrix) : fType(type), fMatrix(matrix) {
116 SkASSERT(kUnused_Type != type);
117 }
halcanary96fcdcc2015-08-27 07:41:13 -0700118 bool hasLocalMatrix() const { return nullptr != fMatrix; }
joshualitt0d986d82015-07-28 10:01:18 -0700119
120 Type fType;
121 const SkMatrix* fMatrix;
joshualitte9d60952015-07-27 12:13:14 -0700122 };
123
bungeman06ca8ec2016-06-09 08:01:03 -0700124 sk_sp<GrGeometryProcessor> Make(const Color&,
125 const Coverage&,
126 const LocalCoords&,
127 const SkMatrix& viewMatrix);
joshualitte9d60952015-07-27 12:13:14 -0700128
joshualitt5478d422014-11-14 16:00:38 -0800129 /*
joshualitt0d986d82015-07-28 10:01:18 -0700130 * Use this factory to create a GrGeometryProcessor that expects a device space vertex position
131 * attribute. The view matrix must still be provided to compute correctly transformed
132 * coordinates for GrFragmentProcessors. It may fail if the view matrix is not invertible.
joshualitt5478d422014-11-14 16:00:38 -0800133 */
bungeman06ca8ec2016-06-09 08:01:03 -0700134 sk_sp<GrGeometryProcessor> MakeForDeviceSpace(const Color&,
135 const Coverage&,
136 const LocalCoords&,
137 const SkMatrix& viewMatrix);
joshualitt4973d9d2014-11-08 09:24:25 -0800138};
139
140#endif