OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 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 #ifndef GrPaint_DEFINED | 10 #ifndef GrPaint_DEFINED |
11 #define GrPaint_DEFINED | 11 #define GrPaint_DEFINED |
12 | 12 |
13 #include "GrColor.h" | 13 #include "GrColor.h" |
14 #include "GrFragmentStage.h" | 14 #include "GrFragmentStage.h" |
| 15 #include "GrXferProcessor.h" |
15 | 16 |
16 #include "SkXfermode.h" | 17 #include "SkXfermode.h" |
17 | 18 |
18 /** | 19 /** |
19 * The paint describes how color and coverage are computed at each pixel by GrCo
ntext draw | 20 * The paint describes how color and coverage are computed at each pixel by GrCo
ntext draw |
20 * functions and the how color is blended with the destination pixel. | 21 * functions and the how color is blended with the destination pixel. |
21 * | 22 * |
22 * The paint allows installation of custom color and coverage stages. New types
of stages are | 23 * The paint allows installation of custom color and coverage stages. New types
of stages are |
23 * created by subclassing GrProcessor. | 24 * created by subclassing GrProcessor. |
24 * | 25 * |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 */ | 72 */ |
72 void setAntiAlias(bool aa) { fAntiAlias = aa; } | 73 void setAntiAlias(bool aa) { fAntiAlias = aa; } |
73 bool isAntiAlias() const { return fAntiAlias; } | 74 bool isAntiAlias() const { return fAntiAlias; } |
74 | 75 |
75 /** | 76 /** |
76 * Should dithering be applied. Defaults to false. | 77 * Should dithering be applied. Defaults to false. |
77 */ | 78 */ |
78 void setDither(bool dither) { fDither = dither; } | 79 void setDither(bool dither) { fDither = dither; } |
79 bool isDither() const { return fDither; } | 80 bool isDither() const { return fDither; } |
80 | 81 |
| 82 const GrXPFactory* setXPFactory(const GrXPFactory* xpFactory) { |
| 83 fXPFactory.reset(SkRef(xpFactory)); |
| 84 return xpFactory; |
| 85 } |
| 86 |
81 /** | 87 /** |
82 * Appends an additional color processor to the color computation. | 88 * Appends an additional color processor to the color computation. |
83 */ | 89 */ |
84 const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* fp)
{ | 90 const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* fp)
{ |
85 SkASSERT(fp); | 91 SkASSERT(fp); |
86 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (fp)); | 92 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (fp)); |
87 return fp; | 93 return fp; |
88 } | 94 } |
89 | 95 |
90 /** | 96 /** |
(...skipping 11 matching lines...) Expand all Loading... |
102 */ | 108 */ |
103 void addColorTextureProcessor(GrTexture*, const SkMatrix&); | 109 void addColorTextureProcessor(GrTexture*, const SkMatrix&); |
104 void addCoverageTextureProcessor(GrTexture*, const SkMatrix&); | 110 void addCoverageTextureProcessor(GrTexture*, const SkMatrix&); |
105 void addColorTextureProcessor(GrTexture*, const SkMatrix&, const GrTexturePa
rams&); | 111 void addColorTextureProcessor(GrTexture*, const SkMatrix&, const GrTexturePa
rams&); |
106 void addCoverageTextureProcessor(GrTexture*, const SkMatrix&, const GrTextur
eParams&); | 112 void addCoverageTextureProcessor(GrTexture*, const SkMatrix&, const GrTextur
eParams&); |
107 | 113 |
108 int numColorStages() const { return fColorStages.count(); } | 114 int numColorStages() const { return fColorStages.count(); } |
109 int numCoverageStages() const { return fCoverageStages.count(); } | 115 int numCoverageStages() const { return fCoverageStages.count(); } |
110 int numTotalStages() const { return this->numColorStages() + this->numCovera
geStages(); } | 116 int numTotalStages() const { return this->numColorStages() + this->numCovera
geStages(); } |
111 | 117 |
| 118 const GrXPFactory* getXPFactory() const { return fXPFactory.get(); } |
| 119 |
112 const GrFragmentStage& getColorStage(int s) const { return fColorStages[s];
} | 120 const GrFragmentStage& getColorStage(int s) const { return fColorStages[s];
} |
113 const GrFragmentStage& getCoverageStage(int s) const { return fCoverageStage
s[s]; } | 121 const GrFragmentStage& getCoverageStage(int s) const { return fCoverageStage
s[s]; } |
114 | 122 |
115 GrPaint& operator=(const GrPaint& paint) { | 123 GrPaint& operator=(const GrPaint& paint) { |
116 fSrcBlendCoeff = paint.fSrcBlendCoeff; | 124 fSrcBlendCoeff = paint.fSrcBlendCoeff; |
117 fDstBlendCoeff = paint.fDstBlendCoeff; | 125 fDstBlendCoeff = paint.fDstBlendCoeff; |
118 fAntiAlias = paint.fAntiAlias; | 126 fAntiAlias = paint.fAntiAlias; |
119 fDither = paint.fDither; | 127 fDither = paint.fDither; |
120 | 128 |
121 fColor = paint.fColor; | 129 fColor = paint.fColor; |
122 | 130 |
123 fColorStages = paint.fColorStages; | 131 fColorStages = paint.fColorStages; |
124 fCoverageStages = paint.fCoverageStages; | 132 fCoverageStages = paint.fCoverageStages; |
125 | 133 |
| 134 fXPFactory.reset(SkRef(paint.getXPFactory())); |
| 135 |
126 return *this; | 136 return *this; |
127 } | 137 } |
128 | 138 |
129 /** | 139 /** |
130 * Resets the paint to the defaults. | 140 * Resets the paint to the defaults. |
131 */ | 141 */ |
132 void reset() { | 142 void reset() { |
133 this->resetBlend(); | 143 this->resetBlend(); |
134 this->resetOptions(); | 144 this->resetOptions(); |
135 this->resetColor(); | 145 this->resetColor(); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 computed = true; | 200 computed = true; |
191 } | 201 } |
192 fCoverageStages[i].localCoordChange(oldToNew); | 202 fCoverageStages[i].localCoordChange(oldToNew); |
193 } | 203 } |
194 return true; | 204 return true; |
195 } | 205 } |
196 | 206 |
197 friend class GrContext; // To access above two functions | 207 friend class GrContext; // To access above two functions |
198 friend class GrStencilAndCoverTextContext; // To access above two functions | 208 friend class GrStencilAndCoverTextContext; // To access above two functions |
199 | 209 |
200 SkSTArray<4, GrFragmentStage> fColorStages; | 210 SkAutoTUnref<const GrXPFactory> fXPFactory; |
201 SkSTArray<2, GrFragmentStage> fCoverageStages; | 211 SkSTArray<4, GrFragmentStage> fColorStages; |
| 212 SkSTArray<2, GrFragmentStage> fCoverageStages; |
202 | 213 |
203 GrBlendCoeff fSrcBlendCoeff; | 214 GrBlendCoeff fSrcBlendCoeff; |
204 GrBlendCoeff fDstBlendCoeff; | 215 GrBlendCoeff fDstBlendCoeff; |
205 bool fAntiAlias; | 216 bool fAntiAlias; |
206 bool fDither; | 217 bool fDither; |
207 | 218 |
208 GrColor fColor; | 219 GrColor fColor; |
209 | 220 |
210 void resetBlend() { | 221 void resetBlend() { |
211 fSrcBlendCoeff = kOne_GrBlendCoeff; | 222 fSrcBlendCoeff = kOne_GrBlendCoeff; |
212 fDstBlendCoeff = kZero_GrBlendCoeff; | 223 fDstBlendCoeff = kZero_GrBlendCoeff; |
213 } | 224 } |
214 | 225 |
215 void resetOptions() { | 226 void resetOptions() { |
216 fAntiAlias = false; | 227 fAntiAlias = false; |
217 fDither = false; | 228 fDither = false; |
218 } | 229 } |
219 | 230 |
220 void resetColor() { | 231 void resetColor() { |
221 fColor = GrColorPackRGBA(0xff, 0xff, 0xff, 0xff); | 232 fColor = GrColorPackRGBA(0xff, 0xff, 0xff, 0xff); |
222 } | 233 } |
223 | 234 |
224 void resetStages() { | 235 void resetStages(); |
225 fColorStages.reset(); | |
226 fCoverageStages.reset(); | |
227 } | |
228 }; | 236 }; |
229 | 237 |
230 #endif | 238 #endif |
OLD | NEW |