reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame^] | 1 | /* |
| 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 SkXfermode_DEFINED |
| 18 | #define SkXfermode_DEFINED |
| 19 | |
| 20 | #include "SkFlattenable.h" |
| 21 | #include "SkColor.h" |
| 22 | |
| 23 | /** \class SkXfermode |
| 24 | |
| 25 | SkXfermode is the base class for objects that are called to implement custom |
| 26 | "transfer-modes" in the drawing pipeline. The static function Create(Modes) |
| 27 | can be called to return an instance of any of the predefined subclasses as |
| 28 | specified in the Modes enum. When an SkXfermode is assigned to an SkPaint, |
| 29 | then objects drawn with that paint have the xfermode applied. |
| 30 | */ |
| 31 | class SkXfermode : public SkFlattenable { |
| 32 | public: |
| 33 | SkXfermode() {} |
| 34 | |
| 35 | virtual void xfer32(SkPMColor dst[], const SkPMColor src[], int count, |
| 36 | const SkAlpha aa[]); |
| 37 | virtual void xfer16(uint16_t dst[], const SkPMColor src[], int count, |
| 38 | const SkAlpha aa[]); |
| 39 | virtual void xfer4444(uint16_t dst[], const SkPMColor src[], int count, |
| 40 | const SkAlpha aa[]); |
| 41 | virtual void xferA8(SkAlpha dst[], const SkPMColor src[], int count, |
| 42 | const SkAlpha aa[]); |
| 43 | |
| 44 | enum Coeff { |
| 45 | kZero_Coeff, |
| 46 | kOne_Coeff, |
| 47 | kSC_Coeff, |
| 48 | kISC_Coeff, |
| 49 | kDC_Coeff, |
| 50 | kIDC_Coeff, |
| 51 | kSA_Coeff, |
| 52 | kISA_Coeff, |
| 53 | kDA_Coeff, |
| 54 | kIDA_Coeff, |
| 55 | |
| 56 | kCoeffCount |
| 57 | }; |
| 58 | virtual bool asCoeff(Coeff* src, Coeff* dst); |
| 59 | |
| 60 | protected: |
| 61 | SkXfermode(SkFlattenableReadBuffer& rb) : SkFlattenable(rb) {} |
| 62 | |
| 63 | /** The default implementation of xfer32/xfer16/xferA8 in turn call this |
| 64 | method, 1 color at a time (upscaled to a SkPMColor). The default |
| 65 | implmentation of this method just returns dst. If performance is |
| 66 | important, your subclass should override xfer32/xfer16/xferA8 directly. |
| 67 | |
| 68 | This method will not be called directly by the client, so it need not |
| 69 | be implemented if your subclass has overridden xfer32/xfer16/xferA8 |
| 70 | */ |
| 71 | virtual SkPMColor xferColor(SkPMColor src, SkPMColor dst); |
| 72 | |
| 73 | private: |
| 74 | typedef SkFlattenable INHERITED; |
| 75 | }; |
| 76 | |
| 77 | /////////////////////////////////////////////////////////////////////////////// |
| 78 | |
| 79 | /** \class SkProcXfermode |
| 80 | |
| 81 | SkProcXfermode is a xfermode that applies the specified proc to its colors. |
| 82 | This class is not exported to java. |
| 83 | */ |
| 84 | class SkProcXfermode : public SkXfermode { |
| 85 | public: |
| 86 | SkProcXfermode(SkXfermodeProc proc) : fProc(proc) {} |
| 87 | |
| 88 | // overrides from SkXfermode |
| 89 | virtual void xfer32(SkPMColor dst[], const SkPMColor src[], int count, |
| 90 | const SkAlpha aa[]); |
| 91 | virtual void xfer16(uint16_t dst[], const SkPMColor src[], int count, |
| 92 | const SkAlpha aa[]); |
| 93 | virtual void xfer4444(uint16_t dst[], const SkPMColor src[], int count, |
| 94 | const SkAlpha aa[]); |
| 95 | virtual void xferA8(SkAlpha dst[], const SkPMColor src[], int count, |
| 96 | const SkAlpha aa[]); |
| 97 | |
| 98 | // overrides from SkFlattenable |
| 99 | virtual Factory getFactory() { return CreateProc; } |
| 100 | virtual void flatten(SkFlattenableWriteBuffer&); |
| 101 | |
| 102 | protected: |
| 103 | SkProcXfermode(SkFlattenableReadBuffer&); |
| 104 | |
| 105 | private: |
| 106 | SkXfermodeProc fProc; |
| 107 | |
| 108 | static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) { |
| 109 | return SkNEW_ARGS(SkProcXfermode, (buffer)); } |
| 110 | |
| 111 | typedef SkXfermode INHERITED; |
| 112 | }; |
| 113 | |
| 114 | #endif |
| 115 | |