1 | /* |
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 "src/gpu/GrGeometryProcessor.h" |
12 | |
13 | /* |
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. |
16 | */ |
17 | namespace GrDefaultGeoProcFactory { |
18 | struct Color { |
19 | enum Type { |
20 | kPremulGrColorUniform_Type, |
21 | kPremulGrColorAttribute_Type, |
22 | kPremulWideColorAttribute_Type, |
23 | }; |
24 | explicit Color(const SkPMColor4f& color) |
25 | : fType(kPremulGrColorUniform_Type) |
26 | , fColor(color) {} |
27 | Color(Type type) |
28 | : fType(type) |
29 | , fColor(SK_PMColor4fILLEGAL) { |
30 | SkASSERT(type != kPremulGrColorUniform_Type); |
31 | } |
32 | |
33 | Type fType; |
34 | SkPMColor4f fColor; |
35 | }; |
36 | |
37 | struct Coverage { |
38 | enum Type { |
39 | kSolid_Type, |
40 | kUniform_Type, |
41 | kAttribute_Type, |
42 | kAttributeTweakAlpha_Type, |
43 | }; |
44 | explicit Coverage(uint8_t coverage) : fType(kUniform_Type), fCoverage(coverage) {} |
45 | Coverage(Type type) : fType(type), fCoverage(0xff) { |
46 | SkASSERT(type != kUniform_Type); |
47 | } |
48 | |
49 | Type fType; |
50 | uint8_t fCoverage; |
51 | }; |
52 | |
53 | struct LocalCoords { |
54 | enum Type { |
55 | kUnused_Type, |
56 | kUsePosition_Type, |
57 | kHasExplicit_Type, |
58 | }; |
59 | LocalCoords(Type type) : fType(type), fMatrix(nullptr) {} |
60 | LocalCoords(Type type, const SkMatrix* matrix) : fType(type), fMatrix(matrix) { |
61 | SkASSERT(kUnused_Type != type); |
62 | } |
63 | bool hasLocalMatrix() const { return nullptr != fMatrix; } |
64 | |
65 | Type fType; |
66 | const SkMatrix* fMatrix; |
67 | }; |
68 | |
69 | GrGeometryProcessor* Make(SkArenaAlloc*, |
70 | const Color&, |
71 | const Coverage&, |
72 | const LocalCoords&, |
73 | const SkMatrix& viewMatrix); |
74 | |
75 | /* |
76 | * Use this factory to create a GrGeometryProcessor that expects a device space vertex position |
77 | * attribute. The view matrix must still be provided to compute correctly transformed |
78 | * coordinates for GrFragmentProcessors. It may fail if the view matrix is not invertible. |
79 | */ |
80 | GrGeometryProcessor* MakeForDeviceSpace(SkArenaAlloc*, |
81 | const Color&, |
82 | const Coverage&, |
83 | const LocalCoords&, |
84 | const SkMatrix& viewMatrix); |
85 | }; |
86 | |
87 | #endif |
88 | |