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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
/*
* Copyright 2007 The Android Open Source Project
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkBitmapProcState_DEFINED
#define SkBitmapProcState_DEFINED
#include "SkBitmap.h"
#include "SkBitmapFilter.h"
#include "SkMatrix.h"
#include "SkPaint.h"
#include "SkScaledImageCache.h"
#define FractionalInt_IS_64BIT
#ifdef FractionalInt_IS_64BIT
typedef SkFixed48 SkFractionalInt;
#define SkScalarToFractionalInt(x) SkScalarToFixed48(x)
#define SkFractionalIntToFixed(x) SkFixed48ToFixed(x)
#define SkFixedToFractionalInt(x) SkFixedToFixed48(x)
#define SkFractionalIntToInt(x) SkFixed48ToInt(x)
#else
typedef SkFixed SkFractionalInt;
#define SkScalarToFractionalInt(x) SkScalarToFixed(x)
#define SkFractionalIntToFixed(x) (x)
#define SkFixedToFractionalInt(x) (x)
#define SkFractionalIntToInt(x) ((x) >> 16)
#endif
class SkPaint;
struct SkConvolutionProcs;
struct SkBitmapProcState {
SkBitmapProcState(): fScaledCacheID(NULL), fBitmapFilter(NULL) {}
~SkBitmapProcState();
typedef void (*ShaderProc32)(const SkBitmapProcState&, int x, int y,
SkPMColor[], int count);
typedef void (*ShaderProc16)(const SkBitmapProcState&, int x, int y,
uint16_t[], int count);
typedef void (*MatrixProc)(const SkBitmapProcState&,
uint32_t bitmapXY[],
int count,
int x, int y);
typedef void (*SampleProc32)(const SkBitmapProcState&,
const uint32_t[],
int count,
SkPMColor colors[]);
typedef void (*SampleProc16)(const SkBitmapProcState&,
const uint32_t[],
int count,
uint16_t colors[]);
typedef U16CPU (*FixedTileProc)(SkFixed); // returns 0..0xFFFF
typedef U16CPU (*FixedTileLowBitsProc)(SkFixed, int); // returns 0..0xF
typedef U16CPU (*IntTileProc)(int value, int count); // returns 0..count-1
const SkBitmap* fBitmap; // chooseProcs - orig or scaled
SkMatrix fInvMatrix; // chooseProcs
SkMatrix::MapXYProc fInvProc; // chooseProcs
SkFractionalInt fInvSxFractionalInt;
SkFractionalInt fInvKyFractionalInt;
FixedTileProc fTileProcX; // chooseProcs
FixedTileProc fTileProcY; // chooseProcs
FixedTileLowBitsProc fTileLowBitsProcX; // chooseProcs
FixedTileLowBitsProc fTileLowBitsProcY; // chooseProcs
IntTileProc fIntTileProcY; // chooseProcs
SkFixed fFilterOneX;
SkFixed fFilterOneY;
SkPMColor fPaintPMColor; // chooseProcs - A8 config
SkFixed fInvSx; // chooseProcs
SkFixed fInvKy; // chooseProcs
uint16_t fAlphaScale; // chooseProcs
uint8_t fInvType; // chooseProcs
uint8_t fTileModeX; // CONSTRUCTOR
uint8_t fTileModeY; // CONSTRUCTOR
uint8_t fFilterLevel; // chooseProcs
/** The shader will let us know when we can release some of our resources
* like scaled bitmaps.
*/
void endContext();
/** Platforms implement this, and can optionally overwrite only the
following fields:
fShaderProc32
fShaderProc16
fMatrixProc
fSampleProc32
fSampleProc32
They will already have valid function pointers, so a platform that does
not have an accelerated version can just leave that field as is. A valid
implementation can do nothing (see SkBitmapProcState_opts_none.cpp)
*/
void platformProcs();
/** Platforms can also optionally overwrite the convolution functions
if we have SIMD versions of them.
*/
void platformConvolutionProcs(SkConvolutionProcs*);
/** Given the byte size of the index buffer to be passed to the matrix proc,
return the maximum number of resulting pixels that can be computed
(i.e. the number of SkPMColor values to be written by the sample proc).
This routine takes into account that filtering and scale-vs-affine
affect the amount of buffer space needed.
Only valid to call after chooseProcs (setContext) has been called. It is
safe to call this inside the shader's shadeSpan() method.
*/
int maxCountForBufferSize(size_t bufferSize) const;
// If a shader proc is present, then the corresponding matrix/sample procs
// are ignored
ShaderProc32 getShaderProc32() const { return fShaderProc32; }
ShaderProc16 getShaderProc16() const { return fShaderProc16; }
SkBitmapFilter* getBitmapFilter() const { return fBitmapFilter; }
#ifdef SK_DEBUG
MatrixProc getMatrixProc() const;
#else
MatrixProc getMatrixProc() const { return fMatrixProc; }
#endif
SampleProc32 getSampleProc32() const { return fSampleProc32; }
SampleProc16 getSampleProc16() const { return fSampleProc16; }
private:
friend class SkBitmapProcShader;
ShaderProc32 fShaderProc32; // chooseProcs
ShaderProc16 fShaderProc16; // chooseProcs
// These are used if the shaderproc is NULL
MatrixProc fMatrixProc; // chooseProcs
SampleProc32 fSampleProc32; // chooseProcs
SampleProc16 fSampleProc16; // chooseProcs
SkBitmap fOrigBitmap; // CONSTRUCTOR
SkBitmap fScaledBitmap; // chooseProcs
SkScaledImageCache::ID* fScaledCacheID;
MatrixProc chooseMatrixProc(bool trivial_matrix);
bool chooseProcs(const SkMatrix& inv, const SkPaint&);
ShaderProc32 chooseShaderProc32();
// returns false if we did not try to scale the image. In that case, we
// will need to "lock" its pixels some other way.
bool possiblyScaleImage();
// returns false if we failed to "lock" the pixels at all. Typically this
// means we have to abort the shader.
bool lockBaseBitmap();
SkBitmapFilter* fBitmapFilter;
// If supported, sets fShaderProc32 and fShaderProc16 and returns true,
// otherwise returns false.
bool setBitmapFilterProcs();
// Return false if we failed to setup for fast translate (e.g. overflow)
bool setupForTranslate();
#ifdef SK_DEBUG
static void DebugMatrixProc(const SkBitmapProcState&,
uint32_t[], int count, int x, int y);
#endif
};
/* Macros for packing and unpacking pairs of 16bit values in a 32bit uint.
Used to allow access to a stream of uint16_t either one at a time, or
2 at a time by unpacking a uint32_t
*/
#ifdef SK_CPU_BENDIAN
#define PACK_TWO_SHORTS(pri, sec) ((pri) << 16 | (sec))
#define UNPACK_PRIMARY_SHORT(packed) ((uint32_t)(packed) >> 16)
#define UNPACK_SECONDARY_SHORT(packed) ((packed) & 0xFFFF)
#else
#define PACK_TWO_SHORTS(pri, sec) ((pri) | ((sec) << 16))
#define UNPACK_PRIMARY_SHORT(packed) ((packed) & 0xFFFF)
#define UNPACK_SECONDARY_SHORT(packed) ((uint32_t)(packed) >> 16)
#endif
#ifdef SK_DEBUG
static inline uint32_t pack_two_shorts(U16CPU pri, U16CPU sec) {
SkASSERT((uint16_t)pri == pri);
SkASSERT((uint16_t)sec == sec);
return PACK_TWO_SHORTS(pri, sec);
}
#else
#define pack_two_shorts(pri, sec) PACK_TWO_SHORTS(pri, sec)
#endif
// These functions are generated via macros, but are exposed here so that
// platformProcs may test for them by name.
void S32_opaque_D32_filter_DX(const SkBitmapProcState& s, const uint32_t xy[],
int count, SkPMColor colors[]);
void S32_alpha_D32_filter_DX(const SkBitmapProcState& s, const uint32_t xy[],
int count, SkPMColor colors[]);
void S32_opaque_D32_filter_DXDY(const SkBitmapProcState& s,
const uint32_t xy[], int count, SkPMColor colors[]);
void S32_alpha_D32_filter_DXDY(const SkBitmapProcState& s,
const uint32_t xy[], int count, SkPMColor colors[]);
void ClampX_ClampY_filter_scale(const SkBitmapProcState& s, uint32_t xy[],
int count, int x, int y);
void ClampX_ClampY_nofilter_scale(const SkBitmapProcState& s, uint32_t xy[],
int count, int x, int y);
void ClampX_ClampY_filter_affine(const SkBitmapProcState& s,
uint32_t xy[], int count, int x, int y);
void ClampX_ClampY_nofilter_affine(const SkBitmapProcState& s,
uint32_t xy[], int count, int x, int y);
void S32_D16_filter_DX(const SkBitmapProcState& s,
const uint32_t* xy, int count, uint16_t* colors);
void highQualityFilter32(const SkBitmapProcState &s, int x, int y,
SkPMColor *SK_RESTRICT colors, int count);
void highQualityFilter16(const SkBitmapProcState &s, int x, int y,
uint16_t *SK_RESTRICT colors, int count);
#endif
|