Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(198)

Side by Side Diff: include/core/SkXfermode.h

Issue 2396953002: Revert[8] "replace SkXfermode obj with SkBlendMode enum in paints" (Closed)
Patch Set: add tmp virtual to unroll legacy arithmodes Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/core/SkPicture.h ('k') | include/effects/SkXfermodeImageFilter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkXfermode_DEFINED 8 #ifndef SkXfermode_DEFINED
9 #define SkXfermode_DEFINED 9 #define SkXfermode_DEFINED
10 10
11 #include "SkBlendMode.h"
12 #include "SkColor.h"
11 #include "SkFlattenable.h" 13 #include "SkFlattenable.h"
12 #include "SkColor.h"
13 14
14 class GrFragmentProcessor; 15 class GrFragmentProcessor;
15 class GrTexture; 16 class GrTexture;
16 class GrXPFactory; 17 class GrXPFactory;
17 class SkRasterPipeline; 18 class SkRasterPipeline;
18 class SkString; 19 class SkString;
19 20
21 struct SkArithmeticParams;
22
20 struct SkPM4f; 23 struct SkPM4f;
21 typedef SkPM4f (*SkXfermodeProc4f)(const SkPM4f& src, const SkPM4f& dst); 24 typedef SkPM4f (*SkXfermodeProc4f)(const SkPM4f& src, const SkPM4f& dst);
22 25
23 /** \class SkXfermode 26 /** \class SkXfermode
24 * 27 *
25 * SkXfermode is the base class for objects that are called to implement custom 28 * SkXfermode is the base class for objects that are called to implement custom
26 * "transfer-modes" in the drawing pipeline. The static function Create(Modes) 29 * "transfer-modes" in the drawing pipeline. The static function Create(Modes)
27 * can be called to return an instance of any of the predefined subclasses as 30 * can be called to return an instance of any of the predefined subclasses as
28 * specified in the Modes enum. When an SkXfermode is assigned to an SkPaint, 31 * specified in the Modes enum. When an SkXfermode is assigned to an SkPaint,
29 * then objects drawn with that paint have the xfermode applied. 32 * then objects drawn with that paint have the xfermode applied.
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 kSaturation_Mode, 108 kSaturation_Mode,
106 kColor_Mode, 109 kColor_Mode,
107 kLuminosity_Mode, 110 kLuminosity_Mode,
108 kLastMode = kLuminosity_Mode 111 kLastMode = kLuminosity_Mode
109 }; 112 };
110 113
111 /** 114 /**
112 * Gets the name of the Mode as a string. 115 * Gets the name of the Mode as a string.
113 */ 116 */
114 static const char* ModeName(Mode); 117 static const char* ModeName(Mode);
118 static const char* ModeName(SkBlendMode mode) {
119 return ModeName(Mode(mode));
120 }
115 121
116 /** 122 /**
117 * If the xfermode is one of the modes in the Mode enum, then asMode() 123 * If the xfermode is one of the modes in the Mode enum, then asMode()
118 * returns true and sets (if not null) mode accordingly. Otherwise it 124 * returns true and sets (if not null) mode accordingly. Otherwise it
119 * returns false and ignores the mode parameter. 125 * returns false and ignores the mode parameter.
120 */ 126 */
121 virtual bool asMode(Mode* mode) const; 127 virtual bool asMode(Mode* mode) const;
122 128
123 /** 129 /**
124 * The same as calling xfermode->asMode(mode), except that this also checks 130 * The same as calling xfermode->asMode(mode), except that this also checks
(...skipping 25 matching lines...) Expand all
150 #ifdef SK_SUPPORT_LEGACY_XFERMODE_PTR 156 #ifdef SK_SUPPORT_LEGACY_XFERMODE_PTR
151 static SkXfermode* Create(Mode mode) { 157 static SkXfermode* Create(Mode mode) {
152 return Make(mode).release(); 158 return Make(mode).release();
153 } 159 }
154 SK_ATTR_DEPRECATED("use AsMode(...)") 160 SK_ATTR_DEPRECATED("use AsMode(...)")
155 static bool IsMode(const SkXfermode* xfer, Mode* mode) { 161 static bool IsMode(const SkXfermode* xfer, Mode* mode) {
156 return AsMode(xfer, mode); 162 return AsMode(xfer, mode);
157 } 163 }
158 #endif 164 #endif
159 165
166 /**
167 * Skia maintains global xfermode objects corresponding to each BlendMode. This returns a
168 * ptr to that global xfermode (or null if the mode is srcover). Thus the c aller may use
169 * the returned ptr, but it should leave its refcnt untouched.
170 */
171 static SkXfermode* Peek(SkBlendMode mode) {
172 sk_sp<SkXfermode> xfer = Make(mode);
173 if (!xfer) {
174 SkASSERT(SkBlendMode::kSrcOver == mode);
175 return nullptr;
176 }
177 SkASSERT(!xfer->unique());
178 return xfer.get();
179 }
180
181 static sk_sp<SkXfermode> Make(SkBlendMode bm) {
182 return Make((Mode)bm);
183 }
184
185 SkBlendMode blend() const {
186 Mode mode;
187 SkAssertResult(this->asMode(&mode));
188 return (SkBlendMode)mode;
189 }
190
160 /** Return a function pointer to a routine that applies the specified 191 /** Return a function pointer to a routine that applies the specified
161 porter-duff transfer mode. 192 porter-duff transfer mode.
162 */ 193 */
163 static SkXfermodeProc GetProc(Mode mode); 194 static SkXfermodeProc GetProc(Mode mode);
164 static SkXfermodeProc4f GetProc4f(Mode); 195 static SkXfermodeProc4f GetProc4f(Mode);
165 196
166 virtual SkXfermodeProc4f getProc4f() const; 197 virtual SkXfermodeProc4f getProc4f() const;
167 198
168 bool appendStages(SkRasterPipeline*) const; 199 bool appendStages(SkRasterPipeline*) const;
169 200
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 virtual bool isOpaque(SrcColorOpacity opacityType) const; 239 virtual bool isOpaque(SrcColorOpacity opacityType) const;
209 240
210 /** 241 /**
211 * The same as calling xfermode->isOpaque(...), except that this also check s if 242 * The same as calling xfermode->isOpaque(...), except that this also check s if
212 * the xfermode is NULL, and if so, treats it as kSrcOver_Mode. 243 * the xfermode is NULL, and if so, treats it as kSrcOver_Mode.
213 */ 244 */
214 static bool IsOpaque(const SkXfermode* xfer, SrcColorOpacity opacityType); 245 static bool IsOpaque(const SkXfermode* xfer, SrcColorOpacity opacityType);
215 static bool IsOpaque(const sk_sp<SkXfermode>& xfer, SrcColorOpacity opacityT ype) { 246 static bool IsOpaque(const sk_sp<SkXfermode>& xfer, SrcColorOpacity opacityT ype) {
216 return IsOpaque(xfer.get(), opacityType); 247 return IsOpaque(xfer.get(), opacityType);
217 } 248 }
249 static bool IsOpaque(SkBlendMode, SrcColorOpacity);
218 250
219 #if SK_SUPPORT_GPU 251 #if SK_SUPPORT_GPU
220 /** Used by the SkXfermodeImageFilter to blend two colors via a GrFragmentPr ocessor. 252 /** Used by the SkXfermodeImageFilter to blend two colors via a GrFragmentPr ocessor.
221 The input to the returned FP is the src color. The dst color is 253 The input to the returned FP is the src color. The dst color is
222 provided by the dst param which becomes a child FP of the returned FP. 254 provided by the dst param which becomes a child FP of the returned FP.
223 It is legal for the function to return a null output. This indicates tha t 255 It is legal for the function to return a null output. This indicates tha t
224 the output of the blend is simply the src color. 256 the output of the blend is simply the src color.
225 */ 257 */
226 virtual sk_sp<GrFragmentProcessor> makeFragmentProcessorForImageFilter( 258 virtual sk_sp<GrFragmentProcessor> makeFragmentProcessorForImageFilter(
227 sk_sp<GrFragmentProc essor> dst) const; 259 sk_sp<GrFragmentProc essor> dst) const;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 enum LCDFlags { 295 enum LCDFlags {
264 kSrcIsOpaque_LCDFlag = 1 << 0, // else src(s) may have alpha < 1 296 kSrcIsOpaque_LCDFlag = 1 << 0, // else src(s) may have alpha < 1
265 kSrcIsSingle_LCDFlag = 1 << 1, // else src[count] 297 kSrcIsSingle_LCDFlag = 1 << 1, // else src[count]
266 kDstIsSRGB_LCDFlag = 1 << 2, // else l32 or f16 298 kDstIsSRGB_LCDFlag = 1 << 2, // else l32 or f16
267 }; 299 };
268 typedef void (*LCD32Proc)(uint32_t* dst, const SkPM4f* src, int count, const uint16_t lcd[]); 300 typedef void (*LCD32Proc)(uint32_t* dst, const SkPM4f* src, int count, const uint16_t lcd[]);
269 typedef void (*LCDF16Proc)(uint64_t* dst, const SkPM4f* src, int count, cons t uint16_t lcd[]); 301 typedef void (*LCDF16Proc)(uint64_t* dst, const SkPM4f* src, int count, cons t uint16_t lcd[]);
270 static LCD32Proc GetLCD32Proc(uint32_t flags); 302 static LCD32Proc GetLCD32Proc(uint32_t flags);
271 static LCDF16Proc GetLCDF16Proc(uint32_t) { return nullptr; } 303 static LCDF16Proc GetLCDF16Proc(uint32_t) { return nullptr; }
272 304
305 virtual bool isArithmetic(SkArithmeticParams*) const { return false; }
306
273 protected: 307 protected:
274 SkXfermode() {} 308 SkXfermode() {}
275 /** The default implementation of xfer32/xfer16/xferA8 in turn call this 309 /** The default implementation of xfer32/xfer16/xferA8 in turn call this
276 method, 1 color at a time (upscaled to a SkPMColor). The default 310 method, 1 color at a time (upscaled to a SkPMColor). The default
277 implementation of this method just returns dst. If performance is 311 implementation of this method just returns dst. If performance is
278 important, your subclass should override xfer32/xfer16/xferA8 directly. 312 important, your subclass should override xfer32/xfer16/xferA8 directly.
279 313
280 This method will not be called directly by the client, so it need not 314 This method will not be called directly by the client, so it need not
281 be implemented if your subclass has overridden xfer32/xfer16/xferA8 315 be implemented if your subclass has overridden xfer32/xfer16/xferA8
282 */ 316 */
283 virtual SkPMColor xferColor(SkPMColor src, SkPMColor dst) const; 317 virtual SkPMColor xferColor(SkPMColor src, SkPMColor dst) const;
284 318
285 virtual D32Proc onGetD32Proc(uint32_t flags) const; 319 virtual D32Proc onGetD32Proc(uint32_t flags) const;
286 virtual F16Proc onGetF16Proc(uint32_t flags) const; 320 virtual F16Proc onGetF16Proc(uint32_t flags) const;
287 virtual bool onAppendStages(SkRasterPipeline*) const; 321 virtual bool onAppendStages(SkRasterPipeline*) const;
288 322
289 private: 323 private:
290 enum { 324 enum {
291 kModeCount = kLastMode + 1 325 kModeCount = kLastMode + 1
292 }; 326 };
293 327
294 typedef SkFlattenable INHERITED; 328 typedef SkFlattenable INHERITED;
295 }; 329 };
296 330
297 #endif 331 #endif
OLDNEW
« no previous file with comments | « include/core/SkPicture.h ('k') | include/effects/SkXfermodeImageFilter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698