blob: 2d5bdb158535c2c069d75292d41a06c8cd67e571 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@android.com8a1c16f2008-12-17 15:59:43 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2006 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00004 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00005 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
reed@android.com8a1c16f2008-12-17 15:59:43 +000010#ifndef SkPorterDuff_DEFINED
11#define SkPorterDuff_DEFINED
12
13#include "SkColor.h"
reed@android.com845fdac2009-06-23 03:01:32 +000014#include "SkXfermode.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000015
16class SkXfermode;
17
reed@android.coma0f5d152009-06-22 17:38:10 +000018/** DEPRECATED - use SkXfermode::Mode instead
19 */
reed@android.com8a1c16f2008-12-17 15:59:43 +000020class SkPorterDuff {
21public:
22 /** List of predefined xfermodes. In general, the algebra for the modes
23 uses the following symbols:
24 Sa, Sc - source alpha and color
25 Da, Dc - destination alpha and color (before compositing)
26 [a, c] - Resulting (alpha, color) values
27 For these equations, the colors are in premultiplied state.
28 If no xfermode is specified, kSrcOver is assumed.
29 */
30 enum Mode {
31 kClear_Mode, //!< [0, 0]
32 kSrc_Mode, //!< [Sa, Sc]
33 kDst_Mode, //!< [Da, Dc]
34 kSrcOver_Mode, //!< [Sa + Da - Sa*Da, Rc = Sc + (1 - Sa)*Dc]
35 kDstOver_Mode, //!< [Sa + Da - Sa*Da, Rc = Dc + (1 - Da)*Sc]
36 kSrcIn_Mode, //!< [Sa * Da, Sc * Da]
37 kDstIn_Mode, //!< [Sa * Da, Sa * Dc]
38 kSrcOut_Mode, //!< [Sa * (1 - Da), Sc * (1 - Da)]
39 kDstOut_Mode, //!< [Da * (1 - Sa), Dc * (1 - Sa)]
40 kSrcATop_Mode, //!< [Da, Sc * Da + (1 - Sa) * Dc]
41 kDstATop_Mode, //!< [Sa, Sa * Dc + Sc * (1 - Da)]
42 kXor_Mode, //!< [Sa + Da - 2 * Sa * Da, Sc * (1 - Da) + (1 - Sa) * Dc]
43 kDarken_Mode, //!< [Sa + Da - Sa*Da, Sc*(1 - Da) + Dc*(1 - Sa) + min(Sc, Dc)]
44 kLighten_Mode, //!< [Sa + Da - Sa*Da, Sc*(1 - Da) + Dc*(1 - Sa) + max(Sc, Dc)]
45 kMultiply_Mode, //!< [Sa * Da, Sc * Dc]
46 kScreen_Mode, //!< [Sa + Da - Sa * Da, Sc + Dc - Sc * Dc]
reed@android.com543ed932009-04-24 12:43:40 +000047 kAdd_Mode, //!< Saturate(S + D)
djsollen@google.comcd9d69b2011-03-14 20:30:14 +000048#ifdef ANDROID
49 kOverlay_Mode,
50#endif
reed@android.com8a1c16f2008-12-17 15:59:43 +000051
52 kModeCount
53 };
reed@android.com845fdac2009-06-23 03:01:32 +000054
reed@android.com8a1c16f2008-12-17 15:59:43 +000055 /** Return an SkXfermode object for the specified mode.
56 */
57 static SkXfermode* CreateXfermode(Mode mode);
58
59 /** Return a function pointer to a routine that applies the specified
60 porter-duff transfer mode.
61 */
62 static SkXfermodeProc GetXfermodeProc(Mode mode);
63
64 /** Return a function pointer to a routine that applies the specified
65 porter-duff transfer mode and srcColor to a 16bit device color. Note,
66 if the mode+srcColor might return a non-opaque color, then there is not
67 16bit proc, and this will return NULL.
68 */
69 static SkXfermodeProc16 GetXfermodeProc16(Mode mode, SkColor srcColor);
70
71 /** If the specified xfermode advertises itself as one of the porterduff
72 modes (via SkXfermode::Coeff), return true and if not null, set mode
73 to the corresponding porterduff mode. If it is not recognized as a one,
74 return false and ignore the mode parameter.
75 */
76 static bool IsMode(SkXfermode*, Mode* mode);
reed@android.com845fdac2009-06-23 03:01:32 +000077
78 /** Return the corersponding SkXfermode::Mode
79 */
80 static SkXfermode::Mode ToXfermodeMode(Mode);
reed@android.com8a1c16f2008-12-17 15:59:43 +000081};
82
83#endif
84