michael@0: /* michael@0: * Copyright 2006 The Android Open Source Project michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #ifndef SkPorterDuff_DEFINED michael@0: #define SkPorterDuff_DEFINED michael@0: michael@0: #include "SkColor.h" michael@0: #include "SkXfermode.h" michael@0: michael@0: class SkXfermode; michael@0: michael@0: class SK_API SkPorterDuff { michael@0: public: michael@0: /** List of predefined xfermodes. In general, the algebra for the modes michael@0: uses the following symbols: michael@0: Sa, Sc - source alpha and color michael@0: Da, Dc - destination alpha and color (before compositing) michael@0: [a, c] - Resulting (alpha, color) values michael@0: For these equations, the colors are in premultiplied state. michael@0: If no xfermode is specified, kSrcOver is assumed. michael@0: */ michael@0: enum Mode { michael@0: kClear_Mode, //!< [0, 0] michael@0: kSrc_Mode, //!< [Sa, Sc] michael@0: kDst_Mode, //!< [Da, Dc] michael@0: kSrcOver_Mode, //!< [Sa + Da - Sa*Da, Rc = Sc + (1 - Sa)*Dc] michael@0: kDstOver_Mode, //!< [Sa + Da - Sa*Da, Rc = Dc + (1 - Da)*Sc] michael@0: kSrcIn_Mode, //!< [Sa * Da, Sc * Da] michael@0: kDstIn_Mode, //!< [Sa * Da, Sa * Dc] michael@0: kSrcOut_Mode, //!< [Sa * (1 - Da), Sc * (1 - Da)] michael@0: kDstOut_Mode, //!< [Da * (1 - Sa), Dc * (1 - Sa)] michael@0: kSrcATop_Mode, //!< [Da, Sc * Da + (1 - Sa) * Dc] michael@0: kDstATop_Mode, //!< [Sa, Sa * Dc + Sc * (1 - Da)] michael@0: kXor_Mode, //!< [Sa + Da - 2 * Sa * Da, Sc * (1 - Da) + (1 - Sa) * Dc] michael@0: kDarken_Mode, //!< [Sa + Da - Sa*Da, Sc*(1 - Da) + Dc*(1 - Sa) + min(Sc, Dc)] michael@0: kLighten_Mode, //!< [Sa + Da - Sa*Da, Sc*(1 - Da) + Dc*(1 - Sa) + max(Sc, Dc)] michael@0: kModulate_Mode, //!< [Sa * Da, Sc * Dc] multiplies all components michael@0: kScreen_Mode, //!< [Sa + Da - Sa * Da, Sc + Dc - Sc * Dc] michael@0: kAdd_Mode, //!< Saturate(S + D) michael@0: #ifdef SK_BUILD_FOR_ANDROID michael@0: kOverlay_Mode, michael@0: #endif michael@0: michael@0: kModeCount michael@0: }; michael@0: michael@0: /** Return an SkXfermode object for the specified mode. michael@0: */ michael@0: static SkXfermode* CreateXfermode(Mode mode); michael@0: michael@0: /** Return a function pointer to a routine that applies the specified michael@0: porter-duff transfer mode. michael@0: */ michael@0: static SkXfermodeProc GetXfermodeProc(Mode mode); michael@0: michael@0: /** Return a function pointer to a routine that applies the specified michael@0: porter-duff transfer mode and srcColor to a 16bit device color. Note, michael@0: if the mode+srcColor might return a non-opaque color, then there is not michael@0: 16bit proc, and this will return NULL. michael@0: */ michael@0: static SkXfermodeProc16 GetXfermodeProc16(Mode mode, SkColor srcColor); michael@0: michael@0: /** If the specified xfermode advertises itself as one of the porterduff michael@0: modes (via SkXfermode::Coeff), return true and if not null, set mode michael@0: to the corresponding porterduff mode. If it is not recognized as a one, michael@0: return false and ignore the mode parameter. michael@0: */ michael@0: static bool IsMode(SkXfermode*, Mode* mode); michael@0: michael@0: /** Return the corersponding SkXfermode::Mode michael@0: */ michael@0: static SkXfermode::Mode ToXfermodeMode(Mode); michael@0: } SK_ATTR_DEPRECATED("use SkXfermode::Mode"); michael@0: michael@0: #endif