OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
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 SkXfermode_DEFINED | 10 #ifndef SkXfermode_DEFINED |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 * returns true and sets (if not null) mode accordingly. Otherwise it | 119 * returns true and sets (if not null) mode accordingly. Otherwise it |
120 * returns false and ignores the mode parameter. | 120 * returns false and ignores the mode parameter. |
121 */ | 121 */ |
122 virtual bool asMode(Mode* mode) const; | 122 virtual bool asMode(Mode* mode) const; |
123 | 123 |
124 /** | 124 /** |
125 * The same as calling xfermode->asMode(mode), except that this also checks | 125 * The same as calling xfermode->asMode(mode), except that this also checks |
126 * if the xfermode is NULL, and if so, treats it as kSrcOver_Mode. | 126 * if the xfermode is NULL, and if so, treats it as kSrcOver_Mode. |
127 */ | 127 */ |
128 static bool AsMode(const SkXfermode*, Mode* mode); | 128 static bool AsMode(const SkXfermode*, Mode* mode); |
| 129 static bool AsMode(const sk_sp<SkXfermode>& xfer, Mode* mode) { |
| 130 return AsMode(xfer.get(), mode); |
| 131 } |
129 | 132 |
130 /** | 133 /** |
131 * Returns true if the xfermode claims to be the specified Mode. This works | 134 * Returns true if the xfermode claims to be the specified Mode. This works |
132 * correctly even if the xfermode is NULL (which equates to kSrcOver.) Thus | 135 * correctly even if the xfermode is NULL (which equates to kSrcOver.) Thus |
133 * you can say this without checking for a null... | 136 * you can say this without checking for a null... |
134 * | 137 * |
135 * If (SkXfermode::IsMode(paint.getXfermode(), | 138 * If (SkXfermode::IsMode(paint.getXfermode(), |
136 * SkXfermode::kDstOver_Mode)) { | 139 * SkXfermode::kDstOver_Mode)) { |
137 * ... | 140 * ... |
138 * } | 141 * } |
139 */ | 142 */ |
140 static bool IsMode(const SkXfermode* xfer, Mode mode); | 143 static bool IsMode(const SkXfermode* xfer, Mode mode); |
| 144 static bool IsMode(const sk_sp<SkXfermode>& xfer, Mode mode) { |
| 145 return IsMode(xfer.get(), mode); |
| 146 } |
141 | 147 |
142 /** Return an SkXfermode object for the specified mode. | 148 /** Return an SkXfermode object for the specified mode. |
143 */ | 149 */ |
144 static SkXfermode* Create(Mode mode); | 150 static sk_sp<SkXfermode> Make(Mode); |
| 151 #ifdef SK_SUPPORT_LEGACY_XFERMODE_PTR |
| 152 static SkXfermode* Create(Mode mode) { |
| 153 return Make(mode).release(); |
| 154 } |
| 155 SK_ATTR_DEPRECATED("use AsMode(...)") |
| 156 static bool IsMode(const SkXfermode* xfer, Mode* mode) { |
| 157 return AsMode(xfer, mode); |
| 158 } |
| 159 #endif |
145 | 160 |
146 /** Return a function pointer to a routine that applies the specified | 161 /** Return a function pointer to a routine that applies the specified |
147 porter-duff transfer mode. | 162 porter-duff transfer mode. |
148 */ | 163 */ |
149 static SkXfermodeProc GetProc(Mode mode); | 164 static SkXfermodeProc GetProc(Mode mode); |
150 static SkXfermodeProc4f GetProc4f(Mode); | 165 static SkXfermodeProc4f GetProc4f(Mode); |
151 | 166 |
152 virtual SkXfermodeProc4f getProc4f() const; | 167 virtual SkXfermodeProc4f getProc4f() const; |
153 | 168 |
154 /** | 169 /** |
155 * If the specified mode can be represented by a pair of Coeff, then return | 170 * If the specified mode can be represented by a pair of Coeff, then return |
156 * true and set (if not NULL) the corresponding coeffs. If the mode is | 171 * true and set (if not NULL) the corresponding coeffs. If the mode is |
157 * not representable as a pair of Coeffs, return false and ignore the | 172 * not representable as a pair of Coeffs, return false and ignore the |
158 * src and dst parameters. | 173 * src and dst parameters. |
159 */ | 174 */ |
160 static bool ModeAsCoeff(Mode mode, Coeff* src, Coeff* dst); | 175 static bool ModeAsCoeff(Mode mode, Coeff* src, Coeff* dst); |
161 | 176 |
162 SK_ATTR_DEPRECATED("use AsMode(...)") | |
163 static bool IsMode(const SkXfermode* xfer, Mode* mode) { | |
164 return AsMode(xfer, mode); | |
165 } | |
166 | |
167 /** | 177 /** |
168 * Returns whether or not the xfer mode can support treating coverage as alp
ha | 178 * Returns whether or not the xfer mode can support treating coverage as alp
ha |
169 */ | 179 */ |
170 virtual bool supportsCoverageAsAlpha() const; | 180 virtual bool supportsCoverageAsAlpha() const; |
171 | 181 |
172 /** | 182 /** |
173 * The same as calling xfermode->supportsCoverageAsAlpha(), except that thi
s also checks if | 183 * The same as calling xfermode->supportsCoverageAsAlpha(), except that thi
s also checks if |
174 * the xfermode is NULL, and if so, treats it as kSrcOver_Mode. | 184 * the xfermode is NULL, and if so, treats it as kSrcOver_Mode. |
175 */ | 185 */ |
176 static bool SupportsCoverageAsAlpha(const SkXfermode* xfer); | 186 static bool SupportsCoverageAsAlpha(const SkXfermode* xfer); |
| 187 static bool SupportsCoverageAsAlpha(const sk_sp<SkXfermode>& xfer) { |
| 188 return SupportsCoverageAsAlpha(xfer.get()); |
| 189 } |
177 | 190 |
178 enum SrcColorOpacity { | 191 enum SrcColorOpacity { |
179 // The src color is known to be opaque (alpha == 255) | 192 // The src color is known to be opaque (alpha == 255) |
180 kOpaque_SrcColorOpacity = 0, | 193 kOpaque_SrcColorOpacity = 0, |
181 // The src color is known to be fully transparent (color == 0) | 194 // The src color is known to be fully transparent (color == 0) |
182 kTransparentBlack_SrcColorOpacity = 1, | 195 kTransparentBlack_SrcColorOpacity = 1, |
183 // The src alpha is known to be fully transparent (alpha == 0) | 196 // The src alpha is known to be fully transparent (alpha == 0) |
184 kTransparentAlpha_SrcColorOpacity = 2, | 197 kTransparentAlpha_SrcColorOpacity = 2, |
185 // The src color opacity is unknown | 198 // The src color opacity is unknown |
186 kUnknown_SrcColorOpacity = 3 | 199 kUnknown_SrcColorOpacity = 3 |
187 }; | 200 }; |
188 | 201 |
189 /** | 202 /** |
190 * Returns whether or not the result of the draw with the xfer mode will be
opaque or not. The | 203 * Returns whether or not the result of the draw with the xfer mode will be
opaque or not. The |
191 * input to this call is an enum describing known information about the opac
ity of the src color | 204 * input to this call is an enum describing known information about the opac
ity of the src color |
192 * that will be given to the xfer mode. | 205 * that will be given to the xfer mode. |
193 */ | 206 */ |
194 virtual bool isOpaque(SrcColorOpacity opacityType) const; | 207 virtual bool isOpaque(SrcColorOpacity opacityType) const; |
195 | 208 |
196 /** | 209 /** |
197 * The same as calling xfermode->isOpaque(...), except that this also check
s if | 210 * The same as calling xfermode->isOpaque(...), except that this also check
s if |
198 * the xfermode is NULL, and if so, treats it as kSrcOver_Mode. | 211 * the xfermode is NULL, and if so, treats it as kSrcOver_Mode. |
199 */ | 212 */ |
200 static bool IsOpaque(const SkXfermode* xfer, SrcColorOpacity opacityType); | 213 static bool IsOpaque(const SkXfermode* xfer, SrcColorOpacity opacityType); |
| 214 static bool IsOpaque(const sk_sp<SkXfermode>& xfer, SrcColorOpacity opacityT
ype) { |
| 215 return IsOpaque(xfer.get(), opacityType); |
| 216 } |
201 | 217 |
202 #if SK_SUPPORT_GPU | 218 #if SK_SUPPORT_GPU |
203 /** Used by the SkXfermodeImageFilter to blend two colors via a GrFragmentPr
ocessor. | 219 /** Used by the SkXfermodeImageFilter to blend two colors via a GrFragmentPr
ocessor. |
204 The input to the returned FP is the src color. The dst color is | 220 The input to the returned FP is the src color. The dst color is |
205 provided by the dst param which becomes a child FP of the returned FP. | 221 provided by the dst param which becomes a child FP of the returned FP. |
206 It is legal for the function to return a null output. This indicates tha
t | 222 It is legal for the function to return a null output. This indicates tha
t |
207 the output of the blend is simply the src color. | 223 the output of the blend is simply the src color. |
208 */ | 224 */ |
209 virtual const GrFragmentProcessor* getFragmentProcessorForImageFilter( | 225 virtual const GrFragmentProcessor* getFragmentProcessorForImageFilter( |
210 const GrFragmentProc
essor* dst) const; | 226 const GrFragmentProc
essor* dst) const; |
(...skipping 10 matching lines...) Expand all Loading... |
221 SK_DEFINE_FLATTENABLE_TYPE(SkXfermode) | 237 SK_DEFINE_FLATTENABLE_TYPE(SkXfermode) |
222 | 238 |
223 enum D32Flags { | 239 enum D32Flags { |
224 kSrcIsOpaque_D32Flag = 1 << 0, | 240 kSrcIsOpaque_D32Flag = 1 << 0, |
225 kSrcIsSingle_D32Flag = 1 << 1, | 241 kSrcIsSingle_D32Flag = 1 << 1, |
226 kDstIsSRGB_D32Flag = 1 << 2, | 242 kDstIsSRGB_D32Flag = 1 << 2, |
227 }; | 243 }; |
228 typedef void (*D32Proc)(const SkXfermode*, uint32_t dst[], const SkPM4f src[
], | 244 typedef void (*D32Proc)(const SkXfermode*, uint32_t dst[], const SkPM4f src[
], |
229 int count, const SkAlpha coverage[]); | 245 int count, const SkAlpha coverage[]); |
230 static D32Proc GetD32Proc(SkXfermode*, uint32_t flags); | 246 static D32Proc GetD32Proc(SkXfermode*, uint32_t flags); |
| 247 static D32Proc GetD32Proc(const sk_sp<SkXfermode>& xfer, uint32_t flags) { |
| 248 return GetD32Proc(xfer.get(), flags); |
| 249 } |
231 | 250 |
232 enum D64Flags { | 251 enum D64Flags { |
233 kSrcIsOpaque_D64Flag = 1 << 0, | 252 kSrcIsOpaque_D64Flag = 1 << 0, |
234 kSrcIsSingle_D64Flag = 1 << 1, | 253 kSrcIsSingle_D64Flag = 1 << 1, |
235 kDstIsFloat16_D64Flag = 1 << 2, // else U16 bit components | 254 kDstIsFloat16_D64Flag = 1 << 2, // else U16 bit components |
236 }; | 255 }; |
237 typedef void (*D64Proc)(const SkXfermode*, uint64_t dst[], const SkPM4f src[
], int count, | 256 typedef void (*D64Proc)(const SkXfermode*, uint64_t dst[], const SkPM4f src[
], int count, |
238 const SkAlpha coverage[]); | 257 const SkAlpha coverage[]); |
239 static D64Proc GetD64Proc(SkXfermode*, uint32_t flags); | 258 static D64Proc GetD64Proc(SkXfermode*, uint32_t flags); |
| 259 static D64Proc GetD64Proc(const sk_sp<SkXfermode>& xfer, uint32_t flags) { |
| 260 return GetD64Proc(xfer.get(), flags); |
| 261 } |
240 | 262 |
241 enum LCDFlags { | 263 enum LCDFlags { |
242 kSrcIsOpaque_LCDFlag = 1 << 0, // else src(s) may have alpha < 1 | 264 kSrcIsOpaque_LCDFlag = 1 << 0, // else src(s) may have alpha < 1 |
243 kSrcIsSingle_LCDFlag = 1 << 1, // else src[count] | 265 kSrcIsSingle_LCDFlag = 1 << 1, // else src[count] |
244 kDstIsLinearInt_LCDFlag = 1 << 2, // else srgb/half-float | 266 kDstIsLinearInt_LCDFlag = 1 << 2, // else srgb/half-float |
245 }; | 267 }; |
246 typedef void (*LCD32Proc)(uint32_t* dst, const SkPM4f* src, int count, const
uint16_t lcd[]); | 268 typedef void (*LCD32Proc)(uint32_t* dst, const SkPM4f* src, int count, const
uint16_t lcd[]); |
247 typedef void (*LCD64Proc)(uint64_t* dst, const SkPM4f* src, int count, const
uint16_t lcd[]); | 269 typedef void (*LCD64Proc)(uint64_t* dst, const SkPM4f* src, int count, const
uint16_t lcd[]); |
248 static LCD32Proc GetLCD32Proc(uint32_t flags); | 270 static LCD32Proc GetLCD32Proc(uint32_t flags); |
249 static LCD64Proc GetLCD64Proc(uint32_t) { return nullptr; } | 271 static LCD64Proc GetLCD64Proc(uint32_t) { return nullptr; } |
(...skipping 15 matching lines...) Expand all Loading... |
265 | 287 |
266 private: | 288 private: |
267 enum { | 289 enum { |
268 kModeCount = kLastMode + 1 | 290 kModeCount = kLastMode + 1 |
269 }; | 291 }; |
270 | 292 |
271 typedef SkFlattenable INHERITED; | 293 typedef SkFlattenable INHERITED; |
272 }; | 294 }; |
273 | 295 |
274 #endif | 296 #endif |
OLD | NEW |