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 #include "GrXferProcessor.h" |
| 16 #include "effects/GrPorterDuffXferProcessor.h" |
16 | 17 |
17 #include "SkXfermode.h" | 18 #include "SkXfermode.h" |
18 | 19 |
19 /** | 20 /** |
20 * The paint describes how color and coverage are computed at each pixel by GrCo
ntext draw | 21 * The paint describes how color and coverage are computed at each pixel by GrCo
ntext draw |
21 * functions and the how color is blended with the destination pixel. | 22 * functions and the how color is blended with the destination pixel. |
22 * | 23 * |
23 * The paint allows installation of custom color and coverage stages. New types
of stages are | 24 * The paint allows installation of custom color and coverage stages. New types
of stages are |
24 * created by subclassing GrProcessor. | 25 * created by subclassing GrProcessor. |
25 * | 26 * |
(...skipping 18 matching lines...) Expand all Loading... |
44 */ | 45 */ |
45 class GrPaint { | 46 class GrPaint { |
46 public: | 47 public: |
47 GrPaint() { this->reset(); } | 48 GrPaint() { this->reset(); } |
48 | 49 |
49 GrPaint(const GrPaint& paint) { *this = paint; } | 50 GrPaint(const GrPaint& paint) { *this = paint; } |
50 | 51 |
51 ~GrPaint() {} | 52 ~GrPaint() {} |
52 | 53 |
53 /** | 54 /** |
54 * Sets the blending coefficients to use to blend the final primitive color
with the | |
55 * destination color. Defaults to kOne for src and kZero for dst (i.e. src m
ode). | |
56 */ | |
57 void setBlendFunc(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff) { | |
58 fSrcBlendCoeff = srcCoeff; | |
59 fDstBlendCoeff = dstCoeff; | |
60 } | |
61 GrBlendCoeff getSrcBlendCoeff() const { return fSrcBlendCoeff; } | |
62 GrBlendCoeff getDstBlendCoeff() const { return fDstBlendCoeff; } | |
63 | |
64 /** | |
65 * The initial color of the drawn primitive. Defaults to solid white. | 55 * The initial color of the drawn primitive. Defaults to solid white. |
66 */ | 56 */ |
67 void setColor(GrColor color) { fColor = color; } | 57 void setColor(GrColor color) { fColor = color; } |
68 GrColor getColor() const { return fColor; } | 58 GrColor getColor() const { return fColor; } |
69 | 59 |
70 /** | 60 /** |
71 * Should primitives be anti-aliased or not. Defaults to false. | 61 * Should primitives be anti-aliased or not. Defaults to false. |
72 */ | 62 */ |
73 void setAntiAlias(bool aa) { fAntiAlias = aa; } | 63 void setAntiAlias(bool aa) { fAntiAlias = aa; } |
74 bool isAntiAlias() const { return fAntiAlias; } | 64 bool isAntiAlias() const { return fAntiAlias; } |
75 | 65 |
76 /** | 66 /** |
77 * Should dithering be applied. Defaults to false. | 67 * Should dithering be applied. Defaults to false. |
78 */ | 68 */ |
79 void setDither(bool dither) { fDither = dither; } | 69 void setDither(bool dither) { fDither = dither; } |
80 bool isDither() const { return fDither; } | 70 bool isDither() const { return fDither; } |
81 | 71 |
82 const GrXPFactory* setXPFactory(const GrXPFactory* xpFactory) { | 72 const GrXPFactory* setXPFactory(const GrXPFactory* xpFactory) { |
83 fXPFactory.reset(SkRef(xpFactory)); | 73 fXPFactory.reset(SkRef(xpFactory)); |
84 return xpFactory; | 74 return xpFactory; |
85 } | 75 } |
86 | 76 |
| 77 void setPorterDuffXPFactory(SkXfermode::Mode mode) { |
| 78 fXPFactory.reset(GrPorterDuffXPFactory::Create(mode)); |
| 79 } |
| 80 |
| 81 void setPorterDuffXPFactory(GrBlendCoeff src, GrBlendCoeff dst) { |
| 82 fXPFactory.reset(GrPorterDuffXPFactory::Create(src, dst)); |
| 83 } |
| 84 |
87 /** | 85 /** |
88 * Appends an additional color processor to the color computation. | 86 * Appends an additional color processor to the color computation. |
89 */ | 87 */ |
90 const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* fp)
{ | 88 const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* fp)
{ |
91 SkASSERT(fp); | 89 SkASSERT(fp); |
92 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (fp)); | 90 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (fp)); |
93 return fp; | 91 return fp; |
94 } | 92 } |
95 | 93 |
96 /** | 94 /** |
(...skipping 17 matching lines...) Expand all Loading... |
114 int numColorStages() const { return fColorStages.count(); } | 112 int numColorStages() const { return fColorStages.count(); } |
115 int numCoverageStages() const { return fCoverageStages.count(); } | 113 int numCoverageStages() const { return fCoverageStages.count(); } |
116 int numTotalStages() const { return this->numColorStages() + this->numCovera
geStages(); } | 114 int numTotalStages() const { return this->numColorStages() + this->numCovera
geStages(); } |
117 | 115 |
118 const GrXPFactory* getXPFactory() const { return fXPFactory.get(); } | 116 const GrXPFactory* getXPFactory() const { return fXPFactory.get(); } |
119 | 117 |
120 const GrFragmentStage& getColorStage(int s) const { return fColorStages[s];
} | 118 const GrFragmentStage& getColorStage(int s) const { return fColorStages[s];
} |
121 const GrFragmentStage& getCoverageStage(int s) const { return fCoverageStage
s[s]; } | 119 const GrFragmentStage& getCoverageStage(int s) const { return fCoverageStage
s[s]; } |
122 | 120 |
123 GrPaint& operator=(const GrPaint& paint) { | 121 GrPaint& operator=(const GrPaint& paint) { |
124 fSrcBlendCoeff = paint.fSrcBlendCoeff; | |
125 fDstBlendCoeff = paint.fDstBlendCoeff; | |
126 fAntiAlias = paint.fAntiAlias; | 122 fAntiAlias = paint.fAntiAlias; |
127 fDither = paint.fDither; | 123 fDither = paint.fDither; |
128 | 124 |
129 fColor = paint.fColor; | 125 fColor = paint.fColor; |
130 | 126 |
131 fColorStages = paint.fColorStages; | 127 fColorStages = paint.fColorStages; |
132 fCoverageStages = paint.fCoverageStages; | 128 fCoverageStages = paint.fCoverageStages; |
133 | 129 |
134 fXPFactory.reset(SkRef(paint.getXPFactory())); | 130 fXPFactory.reset(SkRef(paint.getXPFactory())); |
135 | 131 |
136 return *this; | 132 return *this; |
137 } | 133 } |
138 | 134 |
139 /** | 135 /** |
140 * Resets the paint to the defaults. | 136 * Resets the paint to the defaults. |
141 */ | 137 */ |
142 void reset() { | 138 void reset() { |
143 this->resetBlend(); | |
144 this->resetOptions(); | 139 this->resetOptions(); |
145 this->resetColor(); | 140 this->resetColor(); |
146 this->resetStages(); | 141 this->resetStages(); |
147 } | 142 } |
148 | 143 |
149 /** | 144 /** |
150 * Determines whether the drawing with this paint is opaque with respect to
both color blending | 145 * Determines whether the drawing with this paint is opaque with respect to
both color blending |
151 * and fractional coverage. It does not consider whether AA has been enabled
on the paint or | 146 * and fractional coverage. It does not consider whether AA has been enabled
on the paint or |
152 * not. Depending upon whether multisampling or coverage-based AA is in use,
AA may make the | 147 * not. Depending upon whether multisampling or coverage-based AA is in use,
AA may make the |
153 * result only apply to the interior of primitives. | 148 * result only apply to the interior of primitives. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 return true; | 199 return true; |
205 } | 200 } |
206 | 201 |
207 friend class GrContext; // To access above two functions | 202 friend class GrContext; // To access above two functions |
208 friend class GrStencilAndCoverTextContext; // To access above two functions | 203 friend class GrStencilAndCoverTextContext; // To access above two functions |
209 | 204 |
210 SkAutoTUnref<const GrXPFactory> fXPFactory; | 205 SkAutoTUnref<const GrXPFactory> fXPFactory; |
211 SkSTArray<4, GrFragmentStage> fColorStages; | 206 SkSTArray<4, GrFragmentStage> fColorStages; |
212 SkSTArray<2, GrFragmentStage> fCoverageStages; | 207 SkSTArray<2, GrFragmentStage> fCoverageStages; |
213 | 208 |
214 GrBlendCoeff fSrcBlendCoeff; | |
215 GrBlendCoeff fDstBlendCoeff; | |
216 bool fAntiAlias; | 209 bool fAntiAlias; |
217 bool fDither; | 210 bool fDither; |
218 | 211 |
219 GrColor fColor; | 212 GrColor fColor; |
220 | 213 |
221 void resetBlend() { | |
222 fSrcBlendCoeff = kOne_GrBlendCoeff; | |
223 fDstBlendCoeff = kZero_GrBlendCoeff; | |
224 } | |
225 | |
226 void resetOptions() { | 214 void resetOptions() { |
227 fAntiAlias = false; | 215 fAntiAlias = false; |
228 fDither = false; | 216 fDither = false; |
229 } | 217 } |
230 | 218 |
231 void resetColor() { | 219 void resetColor() { |
232 fColor = GrColorPackRGBA(0xff, 0xff, 0xff, 0xff); | 220 fColor = GrColorPackRGBA(0xff, 0xff, 0xff, 0xff); |
233 } | 221 } |
234 | 222 |
235 void resetStages(); | 223 void resetStages(); |
236 }; | 224 }; |
237 | 225 |
238 #endif | 226 #endif |
OLD | NEW |