• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 class SkXfermode;
15 
16 /** DEPRECATED - use SkXfermode::Mode instead
17  */
18 class SK_API SkPorterDuff {
19 public:
20     /** List of predefined xfermodes. In general, the algebra for the modes
21         uses the following symbols:
22         Sa, Sc  - source alpha and color
23         Da, Dc - destination alpha and color (before compositing)
24         [a, c] - Resulting (alpha, color) values
25         For these equations, the colors are in premultiplied state.
26         If no xfermode is specified, kSrcOver is assumed.
27     */
28     enum Mode {
29         kClear_Mode,    //!< [0, 0]
30         kSrc_Mode,      //!< [Sa, Sc]
31         kDst_Mode,      //!< [Da, Dc]
32         kSrcOver_Mode,  //!< [Sa + Da - Sa*Da, Rc = Sc + (1 - Sa)*Dc]
33         kDstOver_Mode,  //!< [Sa + Da - Sa*Da, Rc = Dc + (1 - Da)*Sc]
34         kSrcIn_Mode,    //!< [Sa * Da, Sc * Da]
35         kDstIn_Mode,    //!< [Sa * Da, Sa * Dc]
36         kSrcOut_Mode,   //!< [Sa * (1 - Da), Sc * (1 - Da)]
37         kDstOut_Mode,   //!< [Da * (1 - Sa), Dc * (1 - Sa)]
38         kSrcATop_Mode,  //!< [Da, Sc * Da + (1 - Sa) * Dc]
39         kDstATop_Mode,  //!< [Sa, Sa * Dc + Sc * (1 - Da)]
40         kXor_Mode,      //!< [Sa + Da - 2 * Sa * Da, Sc * (1 - Da) + (1 - Sa) * Dc]
41         kDarken_Mode,   //!< [Sa + Da - Sa*Da, Sc*(1 - Da) + Dc*(1 - Sa) + min(Sc, Dc)]
42         kLighten_Mode,  //!< [Sa + Da - Sa*Da, Sc*(1 - Da) + Dc*(1 - Sa) + max(Sc, Dc)]
43         kModulate_Mode, //!< [Sa * Da, Sc * Dc] multiplies all components
44         kScreen_Mode,   //!< [Sa + Da - Sa * Da, Sc + Dc - Sc * Dc]
45         kAdd_Mode,      //!< Saturate(S + D)
46 #ifdef SK_BUILD_FOR_ANDROID
47         kOverlay_Mode,
48 #endif
49 
50         kModeCount
51     };
52 
53     /** Return an SkXfermode object for the specified mode.
54     */
55     static SkXfermode* CreateXfermode(Mode mode);
56 
57     /** Return a function pointer to a routine that applies the specified
58         porter-duff transfer mode.
59     */
60     static SkXfermodeProc GetXfermodeProc(Mode mode);
61 
62     /** Return a function pointer to a routine that applies the specified
63         porter-duff transfer mode and srcColor to a 16bit device color. Note,
64         if the mode+srcColor might return a non-opaque color, then there is not
65         16bit proc, and this will return NULL.
66     */
67     static SkXfermodeProc16 GetXfermodeProc16(Mode mode, SkColor srcColor);
68 
69     /** If the specified xfermode advertises itself as one of the porterduff
70         modes (via SkXfermode::Coeff), return true and if not null, set mode
71         to the corresponding porterduff mode. If it is not recognized as a one,
72         return false and ignore the mode parameter.
73     */
74     static bool IsMode(SkXfermode*, Mode* mode);
75 
76     /** Return the corersponding SkXfermode::Mode
77      */
78     static SkXfermode::Mode ToXfermodeMode(Mode);
79 };
80 
81 #endif
82