blob: 54f81ea175c7badbafff99d3d1b9db986d51e85b [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef SkPorterDuff_DEFINED
18#define SkPorterDuff_DEFINED
19
20#include "SkColor.h"
reed@android.com845fdac2009-06-23 03:01:32 +000021#include "SkXfermode.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000022
23class SkXfermode;
24
reed@android.coma0f5d152009-06-22 17:38:10 +000025/** DEPRECATED - use SkXfermode::Mode instead
26 */
reed@android.com8a1c16f2008-12-17 15:59:43 +000027class SkPorterDuff {
28public:
29 /** List of predefined xfermodes. In general, the algebra for the modes
30 uses the following symbols:
31 Sa, Sc - source alpha and color
32 Da, Dc - destination alpha and color (before compositing)
33 [a, c] - Resulting (alpha, color) values
34 For these equations, the colors are in premultiplied state.
35 If no xfermode is specified, kSrcOver is assumed.
36 */
37 enum Mode {
38 kClear_Mode, //!< [0, 0]
39 kSrc_Mode, //!< [Sa, Sc]
40 kDst_Mode, //!< [Da, Dc]
41 kSrcOver_Mode, //!< [Sa + Da - Sa*Da, Rc = Sc + (1 - Sa)*Dc]
42 kDstOver_Mode, //!< [Sa + Da - Sa*Da, Rc = Dc + (1 - Da)*Sc]
43 kSrcIn_Mode, //!< [Sa * Da, Sc * Da]
44 kDstIn_Mode, //!< [Sa * Da, Sa * Dc]
45 kSrcOut_Mode, //!< [Sa * (1 - Da), Sc * (1 - Da)]
46 kDstOut_Mode, //!< [Da * (1 - Sa), Dc * (1 - Sa)]
47 kSrcATop_Mode, //!< [Da, Sc * Da + (1 - Sa) * Dc]
48 kDstATop_Mode, //!< [Sa, Sa * Dc + Sc * (1 - Da)]
49 kXor_Mode, //!< [Sa + Da - 2 * Sa * Da, Sc * (1 - Da) + (1 - Sa) * Dc]
50 kDarken_Mode, //!< [Sa + Da - Sa*Da, Sc*(1 - Da) + Dc*(1 - Sa) + min(Sc, Dc)]
51 kLighten_Mode, //!< [Sa + Da - Sa*Da, Sc*(1 - Da) + Dc*(1 - Sa) + max(Sc, Dc)]
52 kMultiply_Mode, //!< [Sa * Da, Sc * Dc]
53 kScreen_Mode, //!< [Sa + Da - Sa * Da, Sc + Dc - Sc * Dc]
reed@android.com543ed932009-04-24 12:43:40 +000054 kAdd_Mode, //!< Saturate(S + D)
djsollen@google.comcd9d69b2011-03-14 20:30:14 +000055#ifdef ANDROID
56 kOverlay_Mode,
57#endif
reed@android.com8a1c16f2008-12-17 15:59:43 +000058
59 kModeCount
60 };
reed@android.com845fdac2009-06-23 03:01:32 +000061
reed@android.com8a1c16f2008-12-17 15:59:43 +000062 /** Return an SkXfermode object for the specified mode.
63 */
64 static SkXfermode* CreateXfermode(Mode mode);
65
66 /** Return a function pointer to a routine that applies the specified
67 porter-duff transfer mode.
68 */
69 static SkXfermodeProc GetXfermodeProc(Mode mode);
70
71 /** Return a function pointer to a routine that applies the specified
72 porter-duff transfer mode and srcColor to a 16bit device color. Note,
73 if the mode+srcColor might return a non-opaque color, then there is not
74 16bit proc, and this will return NULL.
75 */
76 static SkXfermodeProc16 GetXfermodeProc16(Mode mode, SkColor srcColor);
77
78 /** If the specified xfermode advertises itself as one of the porterduff
79 modes (via SkXfermode::Coeff), return true and if not null, set mode
80 to the corresponding porterduff mode. If it is not recognized as a one,
81 return false and ignore the mode parameter.
82 */
83 static bool IsMode(SkXfermode*, Mode* mode);
reed@android.com845fdac2009-06-23 03:01:32 +000084
85 /** Return the corersponding SkXfermode::Mode
86 */
87 static SkXfermode::Mode ToXfermodeMode(Mode);
reed@android.com8a1c16f2008-12-17 15:59:43 +000088};
89
90#endif
91