OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2013 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 GrGLGeometryProcessor_DEFINED | |
9 #define GrGLGeometryProcessor_DEFINED | |
10 | |
11 #include "GrGLPrimitiveProcessor.h" | |
12 | |
13 class GrGLSLGPBuilder; | |
14 | |
15 /** | |
16 * If a GL effect needs a GrGLFullShaderBuilder* object to emit vertex code, the
n it must inherit | |
17 * from this class. Since paths don't have vertices, this class is only meant to
be used internally | |
18 * by skia, for special cases. | |
19 */ | |
20 class GrGLGeometryProcessor : public GrGLPrimitiveProcessor { | |
21 public: | |
22 /* Any general emit code goes in the base class emitCode. Subclasses overri
de onEmitCode */ | |
23 void emitCode(EmitArgs&) override; | |
24 | |
25 // By default we use the identity matrix | |
26 void setTransformData(const GrPrimitiveProcessor&, | |
27 const GrGLSLProgramDataManager& pdman, | |
28 int index, | |
29 const SkTArray<const GrCoordTransform*, true>& transfo
rms) override { | |
30 this->setTransformDataMatrix(SkMatrix::I(), pdman, index, transforms); | |
31 } | |
32 | |
33 // A helper which subclasses can use if needed | |
34 template <class GeometryProcessor> | |
35 void setTransformDataHelper(const GrPrimitiveProcessor& primProc, | |
36 const GrGLSLProgramDataManager& pdman, | |
37 int index, | |
38 const SkTArray<const GrCoordTransform*, true>& t
ransforms) { | |
39 const GeometryProcessor& gp = primProc.cast<GeometryProcessor>(); | |
40 this->setTransformDataMatrix(gp.localMatrix(), pdman, index, transforms)
; | |
41 } | |
42 | |
43 protected: | |
44 // Emit a uniform matrix for each coord transform. | |
45 void emitTransforms(GrGLSLGPBuilder* gp, | |
46 const GrShaderVar& posVar, | |
47 const char* localCoords, | |
48 const TransformsIn& tin, | |
49 TransformsOut* tout) { | |
50 this->emitTransforms(gp, posVar, localCoords, SkMatrix::I(), tin, tout); | |
51 } | |
52 | |
53 // Emit pre-transformed coords as a vertex attribute per coord-transform. | |
54 void emitTransforms(GrGLSLGPBuilder*, | |
55 const GrShaderVar& posVar, | |
56 const char* localCoords, | |
57 const SkMatrix& localMatrix, | |
58 const TransformsIn&, | |
59 TransformsOut*); | |
60 | |
61 // caller has emitted transforms via attributes | |
62 void emitTransforms(GrGLSLGPBuilder*, | |
63 const char* localCoords, | |
64 const TransformsIn& tin, | |
65 TransformsOut* tout); | |
66 | |
67 struct GrGPArgs { | |
68 // The variable used by a GP to store its position. It can be | |
69 // either a vec2 or a vec3 depending on the presence of perspective. | |
70 GrShaderVar fPositionVar; | |
71 }; | |
72 | |
73 // Create the correct type of position variable given the CTM | |
74 void setupPosition(GrGLSLGPBuilder*, GrGPArgs*, const char* posName); | |
75 void setupPosition(GrGLSLGPBuilder*, GrGPArgs*, const char* posName, const S
kMatrix& mat, | |
76 UniformHandle* viewMatrixUniform); | |
77 | |
78 static uint32_t ComputePosKey(const SkMatrix& mat) { | |
79 if (mat.isIdentity()) { | |
80 return 0x0; | |
81 } else if (!mat.hasPerspective()) { | |
82 return 0x01; | |
83 } else { | |
84 return 0x02; | |
85 } | |
86 } | |
87 | |
88 private: | |
89 void setTransformDataMatrix(const SkMatrix& localMatrix, | |
90 const GrGLSLProgramDataManager& pdman, | |
91 int index, | |
92 const SkTArray<const GrCoordTransform*, true>& t
ransforms) { | |
93 SkSTArray<2, Transform, true>& procTransforms = fInstalledTransforms[ind
ex]; | |
94 int numTransforms = transforms.count(); | |
95 for (int t = 0; t < numTransforms; ++t) { | |
96 SkASSERT(procTransforms[t].fHandle.isValid()); | |
97 const SkMatrix& transform = GetTransformMatrix(localMatrix, *transfo
rms[t]); | |
98 if (!procTransforms[t].fCurrentValue.cheapEqualTo(transform)) { | |
99 pdman.setSkMatrix(procTransforms[t].fHandle.toIndex(), transform
); | |
100 procTransforms[t].fCurrentValue = transform; | |
101 } | |
102 } | |
103 } | |
104 | |
105 virtual void onEmitCode(EmitArgs&, GrGPArgs*) = 0; | |
106 | |
107 typedef GrGLPrimitiveProcessor INHERITED; | |
108 }; | |
109 | |
110 #endif | |
OLD | NEW |