OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2010 Google Inc. | 3 * Copyright 2010 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 | 10 |
11 #ifndef GrEffectStage_DEFINED | 11 #ifndef GrEffectStage_DEFINED |
12 #define GrEffectStage_DEFINED | 12 #define GrEffectStage_DEFINED |
13 | 13 |
14 #include "GrBackendEffectFactory.h" | 14 #include "GrBackendEffectFactory.h" |
15 #include "GrEffect.h" | 15 #include "GrEffect.h" |
16 #include "SkMatrix.h" | 16 #include "SkMatrix.h" |
17 #include "GrTypes.h" | 17 #include "GrTypes.h" |
18 | 18 |
19 #include "SkShader.h" | 19 #include "SkShader.h" |
20 | 20 |
21 class GrEffectStage { | 21 class GrEffectStage { |
22 public: | 22 public: |
23 explicit GrEffectStage(const GrEffectRef* effectRef, int attrIndex0 = -1, in
t attrIndex1 = -1) | 23 explicit GrEffectStage(const GrEffect* effect, int attrIndex0 = -1, int attr
Index1 = -1) |
24 : fEffectRef(SkRef(effectRef)) { | 24 : fEffect(SkRef(effect)) { |
25 fCoordChangeMatrixSet = false; | 25 fCoordChangeMatrixSet = false; |
26 fVertexAttribIndices[0] = attrIndex0; | 26 fVertexAttribIndices[0] = attrIndex0; |
27 fVertexAttribIndices[1] = attrIndex1; | 27 fVertexAttribIndices[1] = attrIndex1; |
28 } | 28 } |
29 | 29 |
30 GrEffectStage(const GrEffectStage& other) { | 30 GrEffectStage(const GrEffectStage& other) { |
31 *this = other; | 31 *this = other; |
32 } | 32 } |
33 | 33 |
34 GrEffectStage& operator= (const GrEffectStage& other) { | 34 GrEffectStage& operator= (const GrEffectStage& other) { |
35 fCoordChangeMatrixSet = other.fCoordChangeMatrixSet; | 35 fCoordChangeMatrixSet = other.fCoordChangeMatrixSet; |
36 if (other.fCoordChangeMatrixSet) { | 36 if (other.fCoordChangeMatrixSet) { |
37 fCoordChangeMatrix = other.fCoordChangeMatrix; | 37 fCoordChangeMatrix = other.fCoordChangeMatrix; |
38 } | 38 } |
39 fEffectRef.reset(SkRef(other.fEffectRef.get())); | 39 fEffect.reset(SkRef(other.fEffect.get())); |
40 memcpy(fVertexAttribIndices, other.fVertexAttribIndices, sizeof(fVertexA
ttribIndices)); | 40 memcpy(fVertexAttribIndices, other.fVertexAttribIndices, sizeof(fVertexA
ttribIndices)); |
41 return *this; | 41 return *this; |
42 } | 42 } |
43 | 43 |
44 bool operator== (const GrEffectStage& other) const { | 44 bool operator== (const GrEffectStage& other) const { |
45 SkASSERT(NULL != fEffectRef.get()); | 45 SkASSERT(NULL != fEffect.get()); |
46 SkASSERT(NULL != other.fEffectRef.get()); | 46 SkASSERT(NULL != other.fEffect.get()); |
47 | 47 |
48 if (!this->getEffect()->isEqual(*other.getEffect())) { | 48 if (!this->getEffect()->isEqual(*other.getEffect())) { |
49 return false; | 49 return false; |
50 } | 50 } |
51 | 51 |
52 if (fCoordChangeMatrixSet != other.fCoordChangeMatrixSet) { | 52 if (fCoordChangeMatrixSet != other.fCoordChangeMatrixSet) { |
53 return false; | 53 return false; |
54 } | 54 } |
55 | 55 |
56 if (!fCoordChangeMatrixSet) { | 56 if (!fCoordChangeMatrixSet) { |
(...skipping 17 matching lines...) Expand all Loading... |
74 } else { | 74 } else { |
75 fCoordChangeMatrixSet = true; | 75 fCoordChangeMatrixSet = true; |
76 fCoordChangeMatrix = matrix; | 76 fCoordChangeMatrix = matrix; |
77 } | 77 } |
78 } | 78 } |
79 | 79 |
80 class SavedCoordChange { | 80 class SavedCoordChange { |
81 private: | 81 private: |
82 bool fCoordChangeMatrixSet; | 82 bool fCoordChangeMatrixSet; |
83 SkMatrix fCoordChangeMatrix; | 83 SkMatrix fCoordChangeMatrix; |
84 SkDEBUGCODE(mutable SkAutoTUnref<const GrEffectRef> fEffectRef;) | 84 SkDEBUGCODE(mutable SkAutoTUnref<const GrEffect> fEffect;) |
85 | 85 |
86 friend class GrEffectStage; | 86 friend class GrEffectStage; |
87 }; | 87 }; |
88 | 88 |
89 /** | 89 /** |
90 * This gets the current coordinate system change. It is the accumulation of | 90 * This gets the current coordinate system change. It is the accumulation of |
91 * localCoordChange calls since the effect was installed. It is used when th
en caller | 91 * localCoordChange calls since the effect was installed. It is used when th
en caller |
92 * wants to temporarily change the source geometry coord system, draw someth
ing, and then | 92 * wants to temporarily change the source geometry coord system, draw someth
ing, and then |
93 * restore the previous coord system (e.g. temporarily draw in device coords
). | 93 * restore the previous coord system (e.g. temporarily draw in device coords
). |
94 */ | 94 */ |
95 void saveCoordChange(SavedCoordChange* savedCoordChange) const { | 95 void saveCoordChange(SavedCoordChange* savedCoordChange) const { |
96 savedCoordChange->fCoordChangeMatrixSet = fCoordChangeMatrixSet; | 96 savedCoordChange->fCoordChangeMatrixSet = fCoordChangeMatrixSet; |
97 if (fCoordChangeMatrixSet) { | 97 if (fCoordChangeMatrixSet) { |
98 savedCoordChange->fCoordChangeMatrix = fCoordChangeMatrix; | 98 savedCoordChange->fCoordChangeMatrix = fCoordChangeMatrix; |
99 } | 99 } |
100 SkASSERT(NULL == savedCoordChange->fEffectRef.get()); | 100 SkASSERT(NULL == savedCoordChange->fEffect.get()); |
101 SkDEBUGCODE(SkRef(fEffectRef.get());) | 101 SkDEBUGCODE(SkRef(fEffect.get());) |
102 SkDEBUGCODE(savedCoordChange->fEffectRef.reset(fEffectRef.get());) | 102 SkDEBUGCODE(savedCoordChange->fEffect.reset(fEffect.get());) |
103 } | 103 } |
104 | 104 |
105 /** | 105 /** |
106 * This balances the saveCoordChange call. | 106 * This balances the saveCoordChange call. |
107 */ | 107 */ |
108 void restoreCoordChange(const SavedCoordChange& savedCoordChange) { | 108 void restoreCoordChange(const SavedCoordChange& savedCoordChange) { |
109 fCoordChangeMatrixSet = savedCoordChange.fCoordChangeMatrixSet; | 109 fCoordChangeMatrixSet = savedCoordChange.fCoordChangeMatrixSet; |
110 if (fCoordChangeMatrixSet) { | 110 if (fCoordChangeMatrixSet) { |
111 fCoordChangeMatrix = savedCoordChange.fCoordChangeMatrix; | 111 fCoordChangeMatrix = savedCoordChange.fCoordChangeMatrix; |
112 } | 112 } |
113 SkASSERT(savedCoordChange.fEffectRef.get() == fEffectRef); | 113 SkASSERT(savedCoordChange.fEffect.get() == fEffect); |
114 SkDEBUGCODE(savedCoordChange.fEffectRef.reset(NULL);) | 114 SkDEBUGCODE(savedCoordChange.fEffect.reset(NULL);) |
115 } | 115 } |
116 | 116 |
117 /** | 117 /** |
118 * Gets the matrix representing all changes of coordinate system since the G
rEffect was | 118 * Gets the matrix representing all changes of coordinate system since the G
rEffect was |
119 * installed in the stage. | 119 * installed in the stage. |
120 */ | 120 */ |
121 const SkMatrix& getCoordChangeMatrix() const { | 121 const SkMatrix& getCoordChangeMatrix() const { |
122 if (fCoordChangeMatrixSet) { | 122 if (fCoordChangeMatrixSet) { |
123 return fCoordChangeMatrix; | 123 return fCoordChangeMatrix; |
124 } else { | 124 } else { |
125 return SkMatrix::I(); | 125 return SkMatrix::I(); |
126 } | 126 } |
127 } | 127 } |
128 | 128 |
129 const GrEffect* getEffect() const { return fEffectRef.get()->get(); } | 129 const GrEffect* getEffect() const { return fEffect.get(); } |
130 | 130 |
131 const int* getVertexAttribIndices() const { return fVertexAttribIndices; } | 131 const int* getVertexAttribIndices() const { return fVertexAttribIndices; } |
132 int getVertexAttribIndexCount() const { return fEffectRef->get()->numVertexA
ttribs(); } | 132 int getVertexAttribIndexCount() const { return fEffect->numVertexAttribs();
} |
133 | 133 |
134 private: | 134 private: |
135 bool fCoordChangeMatrixSet; | 135 bool fCoordChangeMatrixSet; |
136 SkMatrix fCoordChangeMatrix; | 136 SkMatrix fCoordChangeMatrix; |
137 SkAutoTUnref<const GrEffectRef> fEffectRef; | 137 SkAutoTUnref<const GrEffect> fEffect; |
138 int fVertexAttribIndices[2]; | 138 int fVertexAttribIndices[2]; |
139 }; | 139 }; |
140 | 140 |
141 #endif | 141 #endif |
OLD | NEW |