blob: 23bcb451c69c7b6483d2009975a14ce12b6338b5 [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
15 * view matrix and wire through color, coverage, UV coords if requested. Right now this is only
16 * used in the creation of optimized draw states because adding default GPs to the drawstate can
17 * interfere with batching due to updating the drawstate.
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;
27 GrColor fCoverage;
28 };
29
30 struct PositionColorAttr {
31 SkPoint fPosition;
32 SkColor fColor;
33 };
34
35 struct PositionColorCoverageAttr {
36 SkPoint fPosition;
37 SkColor fColor;
38 GrColor fCoverage;
39 };
40
41 struct PositionLocalCoordAttr {
42 SkPoint fPosition;
43 SkPoint fLocalCoord;
44 };
45
46 struct PositionLocalCoordCoverageAttr {
47 SkPoint fPosition;
48 SkPoint fLocalCoord;
49 GrColor fCoverage;
50 };
51
52 struct PositionColorLocalCoordAttr {
53 SkPoint fPosition;
54 GrColor fColor;
55 SkPoint fLocalCoord;
56 };
57
58 struct PositionColorLocalCoordCoverage {
59 SkPoint fPosition;
60 GrColor fColor;
61 SkPoint fLocalCoord;
62 GrColor fCoverage;
63 };
64
joshualitte9d60952015-07-27 12:13:14 -070065 struct Color {
66 enum Type {
67 kNone_Type,
68 kUniform_Type,
69 kAttribute_Type,
70 };
71 Color(GrColor color) : fType(kUniform_Type), fColor(color) {}
72 Color(Type type) : fType(type), fColor(GrColor_ILLEGAL) {
73 SkASSERT(type != kUniform_Type);
74
75 // TODO This is temporary
76 if (kAttribute_Type == type) {
77 fColor = GrColor_WHITE;
78 }
79 }
80
81 Type fType;
82 GrColor fColor;
83 };
84
85 struct Coverage {
86 enum Type {
87 kNone_Type,
88 kSolid_Type,
89 kUniform_Type,
90 kAttribute_Type,
91 };
92 Coverage(uint8_t coverage) : fType(kUniform_Type), fCoverage(coverage) {}
93 Coverage(Type type) : fType(type), fCoverage(0xff) {
94 SkASSERT(type != kUniform_Type);
95 }
96
97 Type fType;
98 uint8_t fCoverage;
99 };
100
101 struct LocalCoords {
102 enum Type {
joshualitt0d986d82015-07-28 10:01:18 -0700103 kUnused_Type,
joshualitte9d60952015-07-27 12:13:14 -0700104 kUsePosition_Type,
105 kHasExplicit_Type,
joshualittb2aa7cb2015-08-05 11:05:22 -0700106 kHasTransformed_Type,
joshualitte9d60952015-07-27 12:13:14 -0700107 };
halcanary96fcdcc2015-08-27 07:41:13 -0700108 LocalCoords(Type type) : fType(type), fMatrix(nullptr) {}
joshualitt0d986d82015-07-28 10:01:18 -0700109 LocalCoords(Type type, const SkMatrix* matrix) : fType(type), fMatrix(matrix) {
110 SkASSERT(kUnused_Type != type);
111 }
halcanary96fcdcc2015-08-27 07:41:13 -0700112 bool hasLocalMatrix() const { return nullptr != fMatrix; }
joshualitt0d986d82015-07-28 10:01:18 -0700113
114 Type fType;
115 const SkMatrix* fMatrix;
joshualitte9d60952015-07-27 12:13:14 -0700116 };
117
joshualitt7a0d6972015-07-28 10:20:08 -0700118 const GrGeometryProcessor* Create(const Color&,
119 const Coverage&,
120 const LocalCoords&,
joshualittdf0c5572015-08-03 11:35:28 -0700121 const SkMatrix& viewMatrix);
joshualitte9d60952015-07-27 12:13:14 -0700122
joshualitt5478d422014-11-14 16:00:38 -0800123 /*
joshualitt0d986d82015-07-28 10:01:18 -0700124 * Use this factory to create a GrGeometryProcessor that expects a device space vertex position
125 * attribute. The view matrix must still be provided to compute correctly transformed
126 * coordinates for GrFragmentProcessors. It may fail if the view matrix is not invertible.
joshualitt5478d422014-11-14 16:00:38 -0800127 */
joshualitt7a0d6972015-07-28 10:20:08 -0700128 const GrGeometryProcessor* CreateForDeviceSpace(const Color&,
129 const Coverage&,
130 const LocalCoords&,
131 const SkMatrix& viewMatrix);
joshualitt0d986d82015-07-28 10:01:18 -0700132
joshualitt7a0d6972015-07-28 10:20:08 -0700133 inline size_t DefaultVertexStride() { return sizeof(PositionAttr); }
joshualitt4973d9d2014-11-08 09:24:25 -0800134};
135
136#endif