blob: bf2db40ecd030b31cdaaae20fa509aeafda296ab [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
13class GrDrawState;
14
15/*
16 * A factory for creating default Geometry Processors which simply multiply position by the uniform
17 * view matrix and wire through color, coverage, UV coords if requested. Right now this is only
18 * used in the creation of optimized draw states because adding default GPs to the drawstate can
19 * interfere with batching due to updating the drawstate.
joshualitt4973d9d2014-11-08 09:24:25 -080020 */
joshualitt7a0d6972015-07-28 10:20:08 -070021namespace GrDefaultGeoProcFactory {
joshualitt4973d9d2014-11-08 09:24:25 -080022 // Structs for adding vertex attributes
23 struct PositionAttr {
24 SkPoint fPosition;
25 };
26
27 struct PositionCoverageAttr {
28 SkPoint fPosition;
29 GrColor fCoverage;
30 };
31
32 struct PositionColorAttr {
33 SkPoint fPosition;
34 SkColor fColor;
35 };
36
37 struct PositionColorCoverageAttr {
38 SkPoint fPosition;
39 SkColor fColor;
40 GrColor fCoverage;
41 };
42
43 struct PositionLocalCoordAttr {
44 SkPoint fPosition;
45 SkPoint fLocalCoord;
46 };
47
48 struct PositionLocalCoordCoverageAttr {
49 SkPoint fPosition;
50 SkPoint fLocalCoord;
51 GrColor fCoverage;
52 };
53
54 struct PositionColorLocalCoordAttr {
55 SkPoint fPosition;
56 GrColor fColor;
57 SkPoint fLocalCoord;
58 };
59
60 struct PositionColorLocalCoordCoverage {
61 SkPoint fPosition;
62 GrColor fColor;
63 SkPoint fLocalCoord;
64 GrColor fCoverage;
65 };
66
joshualitte9d60952015-07-27 12:13:14 -070067 struct Color {
68 enum Type {
69 kNone_Type,
70 kUniform_Type,
71 kAttribute_Type,
72 };
73 Color(GrColor color) : fType(kUniform_Type), fColor(color) {}
74 Color(Type type) : fType(type), fColor(GrColor_ILLEGAL) {
75 SkASSERT(type != kUniform_Type);
76
77 // TODO This is temporary
78 if (kAttribute_Type == type) {
79 fColor = GrColor_WHITE;
80 }
81 }
82
83 Type fType;
84 GrColor fColor;
85 };
86
87 struct Coverage {
88 enum Type {
89 kNone_Type,
90 kSolid_Type,
91 kUniform_Type,
92 kAttribute_Type,
93 };
94 Coverage(uint8_t coverage) : fType(kUniform_Type), fCoverage(coverage) {}
95 Coverage(Type type) : fType(type), fCoverage(0xff) {
96 SkASSERT(type != kUniform_Type);
97 }
98
99 Type fType;
100 uint8_t fCoverage;
101 };
102
103 struct LocalCoords {
104 enum Type {
joshualitt0d986d82015-07-28 10:01:18 -0700105 kUnused_Type,
joshualitte9d60952015-07-27 12:13:14 -0700106 kUsePosition_Type,
107 kHasExplicit_Type,
joshualittb2aa7cb2015-08-05 11:05:22 -0700108 kHasTransformed_Type,
joshualitte9d60952015-07-27 12:13:14 -0700109 };
halcanary96fcdcc2015-08-27 07:41:13 -0700110 LocalCoords(Type type) : fType(type), fMatrix(nullptr) {}
joshualitt0d986d82015-07-28 10:01:18 -0700111 LocalCoords(Type type, const SkMatrix* matrix) : fType(type), fMatrix(matrix) {
112 SkASSERT(kUnused_Type != type);
113 }
halcanary96fcdcc2015-08-27 07:41:13 -0700114 bool hasLocalMatrix() const { return nullptr != fMatrix; }
joshualitt0d986d82015-07-28 10:01:18 -0700115
116 Type fType;
117 const SkMatrix* fMatrix;
joshualitte9d60952015-07-27 12:13:14 -0700118 };
119
joshualitt7a0d6972015-07-28 10:20:08 -0700120 const GrGeometryProcessor* Create(const Color&,
121 const Coverage&,
122 const LocalCoords&,
joshualittdf0c5572015-08-03 11:35:28 -0700123 const SkMatrix& viewMatrix);
joshualitte9d60952015-07-27 12:13:14 -0700124
joshualitt5478d422014-11-14 16:00:38 -0800125 /*
joshualitt0d986d82015-07-28 10:01:18 -0700126 * Use this factory to create a GrGeometryProcessor that expects a device space vertex position
127 * attribute. The view matrix must still be provided to compute correctly transformed
128 * coordinates for GrFragmentProcessors. It may fail if the view matrix is not invertible.
joshualitt5478d422014-11-14 16:00:38 -0800129 */
joshualitt7a0d6972015-07-28 10:20:08 -0700130 const GrGeometryProcessor* CreateForDeviceSpace(const Color&,
131 const Coverage&,
132 const LocalCoords&,
133 const SkMatrix& viewMatrix);
joshualitt0d986d82015-07-28 10:01:18 -0700134
joshualitt7a0d6972015-07-28 10:20:08 -0700135 inline size_t DefaultVertexStride() { return sizeof(PositionAttr); }
joshualitt4973d9d2014-11-08 09:24:25 -0800136};
137
138#endif