OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2006 The Android Open Source Project | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #ifndef SkPorterDuff_DEFINED | |
9 #define SkPorterDuff_DEFINED | |
10 | |
11 #include "SkColor.h" | |
12 #include "SkXfermode.h" | |
13 | |
14 //#define SK_SUPPORT_LEGACY_PORTER_DUFF | |
15 | |
16 // Temporary guard until we can remove the dependencies in android. Then we | |
17 // plan to remove this entirely. | |
18 #ifdef SK_SUPPORT_LEGACY_PORTER_DUFF | |
19 | |
20 class SkXfermode; | |
21 | |
22 class SK_API SkPorterDuff { | |
23 public: | |
24 /** List of predefined xfermodes. In general, the algebra for the modes | |
25 uses the following symbols: | |
26 Sa, Sc - source alpha and color | |
27 Da, Dc - destination alpha and color (before compositing) | |
28 [a, c] - Resulting (alpha, color) values | |
29 For these equations, the colors are in premultiplied state. | |
30 If no xfermode is specified, kSrcOver is assumed. | |
31 */ | |
32 enum Mode { | |
33 kClear_Mode, //!< [0, 0] | |
34 kSrc_Mode, //!< [Sa, Sc] | |
35 kDst_Mode, //!< [Da, Dc] | |
36 kSrcOver_Mode, //!< [Sa + Da - Sa*Da, Rc = Sc + (1 - Sa)*Dc] | |
37 kDstOver_Mode, //!< [Sa + Da - Sa*Da, Rc = Dc + (1 - Da)*Sc] | |
38 kSrcIn_Mode, //!< [Sa * Da, Sc * Da] | |
39 kDstIn_Mode, //!< [Sa * Da, Sa * Dc] | |
40 kSrcOut_Mode, //!< [Sa * (1 - Da), Sc * (1 - Da)] | |
41 kDstOut_Mode, //!< [Da * (1 - Sa), Dc * (1 - Sa)] | |
42 kSrcATop_Mode, //!< [Da, Sc * Da + (1 - Sa) * Dc] | |
43 kDstATop_Mode, //!< [Sa, Sa * Dc + Sc * (1 - Da)] | |
44 kXor_Mode, //!< [Sa + Da - 2 * Sa * Da, Sc * (1 - Da) + (1 - Sa) *
Dc] | |
45 kDarken_Mode, //!< [Sa + Da - Sa*Da, Sc*(1 - Da) + Dc*(1 - Sa) + min(S
c, Dc)] | |
46 kLighten_Mode, //!< [Sa + Da - Sa*Da, Sc*(1 - Da) + Dc*(1 - Sa) + max(S
c, Dc)] | |
47 kModulate_Mode, //!< [Sa * Da, Sc * Dc] multiplies all components | |
48 kScreen_Mode, //!< [Sa + Da - Sa * Da, Sc + Dc - Sc * Dc] | |
49 kAdd_Mode, //!< Saturate(S + D) | |
50 #ifdef SK_BUILD_FOR_ANDROID | |
51 kOverlay_Mode, | |
52 #endif | |
53 | |
54 kModeCount | |
55 }; | |
56 | |
57 /** Return an SkXfermode object for the specified mode. | |
58 */ | |
59 static SkXfermode* CreateXfermode(Mode mode); | |
60 | |
61 /** Return a function pointer to a routine that applies the specified | |
62 porter-duff transfer mode. | |
63 */ | |
64 static SkXfermodeProc GetXfermodeProc(Mode mode); | |
65 | |
66 /** Return a function pointer to a routine that applies the specified | |
67 porter-duff transfer mode and srcColor to a 16bit device color. Note, | |
68 if the mode+srcColor might return a non-opaque color, then there is not | |
69 16bit proc, and this will return NULL. | |
70 */ | |
71 static SkXfermodeProc16 GetXfermodeProc16(Mode mode, SkColor srcColor); | |
72 | |
73 /** If the specified xfermode advertises itself as one of the porterduff | |
74 modes (via SkXfermode::Coeff), return true and if not null, set mode | |
75 to the corresponding porterduff mode. If it is not recognized as a one, | |
76 return false and ignore the mode parameter. | |
77 */ | |
78 static bool IsMode(SkXfermode*, Mode* mode); | |
79 | |
80 /** Return the corersponding SkXfermode::Mode | |
81 */ | |
82 static SkXfermode::Mode ToXfermodeMode(Mode); | |
83 } SK_ATTR_DEPRECATED("use SkXfermode::Mode"); | |
84 | |
85 #endif | |
86 | |
87 #endif | |
OLD | NEW |