blob: c5f549211d4c2e5679f798b374b9a0e6482c8878 [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2006 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00003 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00004 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00006 */
7
8#ifndef SkPorterDuff_DEFINED
9#define SkPorterDuff_DEFINED
10
11#include "SkColor.h"
reed@android.com845fdac2009-06-23 03:01:32 +000012#include "SkXfermode.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000013
14class SkXfermode;
15
reed@android.coma0f5d152009-06-22 17:38:10 +000016/** DEPRECATED - use SkXfermode::Mode instead
17 */
tfarina@chromium.org6806fe82012-10-12 14:41:39 +000018class SK_API SkPorterDuff {
reed@android.com8a1c16f2008-12-17 15:59:43 +000019public:
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)]
reed@google.com8d3cd7a2013-01-30 21:36:11 +000043 kModulate_Mode, //!< [Sa * Da, Sc * Dc] multiplies all components
reed@android.com8a1c16f2008-12-17 15:59:43 +000044 kScreen_Mode, //!< [Sa + Da - Sa * Da, Sc + Dc - Sc * Dc]
reed@android.com543ed932009-04-24 12:43:40 +000045 kAdd_Mode, //!< Saturate(S + D)
djsollen@google.com56c69772011-11-08 19:00:26 +000046#ifdef SK_BUILD_FOR_ANDROID
djsollen@google.comcd9d69b2011-03-14 20:30:14 +000047 kOverlay_Mode,
48#endif
reed@android.com8a1c16f2008-12-17 15:59:43 +000049
50 kModeCount
51 };
reed@android.com845fdac2009-06-23 03:01:32 +000052
reed@android.com8a1c16f2008-12-17 15:59:43 +000053 /** Return an SkXfermode object for the specified mode.
54 */
55 static SkXfermode* CreateXfermode(Mode mode);
rmistry@google.comfbfcd562012-08-23 18:09:54 +000056
reed@android.com8a1c16f2008-12-17 15:59:43 +000057 /** Return a function pointer to a routine that applies the specified
58 porter-duff transfer mode.
59 */
60 static SkXfermodeProc GetXfermodeProc(Mode mode);
rmistry@google.comfbfcd562012-08-23 18:09:54 +000061
reed@android.com8a1c16f2008-12-17 15:59:43 +000062 /** 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);
rmistry@google.comfbfcd562012-08-23 18:09:54 +000068
reed@android.com8a1c16f2008-12-17 15:59:43 +000069 /** 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);
reed@android.com845fdac2009-06-23 03:01:32 +000075
76 /** Return the corersponding SkXfermode::Mode
77 */
78 static SkXfermode::Mode ToXfermodeMode(Mode);
reed@android.com8a1c16f2008-12-17 15:59:43 +000079};
80
81#endif