1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
/*
* Copyright (C) 2006 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SkXfermode_DEFINED
#define SkXfermode_DEFINED
#include "SkFlattenable.h"
#include "SkColor.h"
/** \class SkXfermode
SkXfermode is the base class for objects that are called to implement custom
"transfer-modes" in the drawing pipeline. The static function Create(Modes)
can be called to return an instance of any of the predefined subclasses as
specified in the Modes enum. When an SkXfermode is assigned to an SkPaint,
then objects drawn with that paint have the xfermode applied.
*/
class SkXfermode : public SkFlattenable {
public:
SkXfermode() {}
virtual void xfer32(SkPMColor dst[], const SkPMColor src[], int count,
const SkAlpha aa[]);
virtual void xfer16(uint16_t dst[], const SkPMColor src[], int count,
const SkAlpha aa[]);
virtual void xfer4444(uint16_t dst[], const SkPMColor src[], int count,
const SkAlpha aa[]);
virtual void xferA8(SkAlpha dst[], const SkPMColor src[], int count,
const SkAlpha aa[]);
/** Enum of possible coefficients to describe some xfermodes
*/
enum Coeff {
kZero_Coeff, /** 0 */
kOne_Coeff, /** 1 */
kSC_Coeff, /** src color */
kISC_Coeff, /** inverse src color (i.e. 1 - sc) */
kDC_Coeff, /** dst color */
kIDC_Coeff, /** inverse dst color (i.e. 1 - dc) */
kSA_Coeff, /** src alpha */
kISA_Coeff, /** inverse src alpha (i.e. 1 - sa) */
kDA_Coeff, /** dst alpha */
kIDA_Coeff, /** inverse dst alpha (i.e. 1 - da) */
kCoeffCount
};
/** If the xfermode can be expressed as an equation using the coefficients
in Coeff, then asCoeff() returns true, and sets (if not null) src and
dst accordingly.
result = src_coeff * src_color + dst_coeff * dst_color;
As examples, here are some of the porterduff coefficients
MODE SRC_COEFF DST_COEFF
clear zero zero
src one zero
dst zero one
srcover one isa
dstover ida one
*/
virtual bool asCoeff(Coeff* src, Coeff* dst);
protected:
SkXfermode(SkFlattenableReadBuffer& rb) : SkFlattenable(rb) {}
/** The default implementation of xfer32/xfer16/xferA8 in turn call this
method, 1 color at a time (upscaled to a SkPMColor). The default
implmentation of this method just returns dst. If performance is
important, your subclass should override xfer32/xfer16/xferA8 directly.
This method will not be called directly by the client, so it need not
be implemented if your subclass has overridden xfer32/xfer16/xferA8
*/
virtual SkPMColor xferColor(SkPMColor src, SkPMColor dst);
private:
typedef SkFlattenable INHERITED;
};
///////////////////////////////////////////////////////////////////////////////
/** \class SkProcXfermode
SkProcXfermode is a xfermode that applies the specified proc to its colors.
This class is not exported to java.
*/
class SkProcXfermode : public SkXfermode {
public:
SkProcXfermode(SkXfermodeProc proc) : fProc(proc) {}
// overrides from SkXfermode
virtual void xfer32(SkPMColor dst[], const SkPMColor src[], int count,
const SkAlpha aa[]);
virtual void xfer16(uint16_t dst[], const SkPMColor src[], int count,
const SkAlpha aa[]);
virtual void xfer4444(uint16_t dst[], const SkPMColor src[], int count,
const SkAlpha aa[]);
virtual void xferA8(SkAlpha dst[], const SkPMColor src[], int count,
const SkAlpha aa[]);
// overrides from SkFlattenable
virtual Factory getFactory() { return CreateProc; }
virtual void flatten(SkFlattenableWriteBuffer&);
protected:
SkProcXfermode(SkFlattenableReadBuffer&);
private:
SkXfermodeProc fProc;
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SkProcXfermode, (buffer)); }
typedef SkXfermode INHERITED;
};
#endif
|