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