Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: skia/sgl/SkBitmapProcState_matrix.h

Issue 113827: Remove the remainder of the skia source code from the Chromium repo.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « skia/sgl/SkBitmapProcState.cpp ('k') | skia/sgl/SkBitmapProcState_matrixProcs.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1
2 #define TRANSLATE_NOFILTER_NAME MAKENAME(_nofilter_translate)
3 #define SCALE_NOFILTER_NAME MAKENAME(_nofilter_scale)
4 #define SCALE_FILTER_NAME MAKENAME(_filter_scale)
5 #define AFFINE_NOFILTER_NAME MAKENAME(_nofilter_affine)
6 #define AFFINE_FILTER_NAME MAKENAME(_filter_affine)
7 #define PERSP_NOFILTER_NAME MAKENAME(_nofilter_persp)
8 #define PERSP_FILTER_NAME MAKENAME(_filter_persp)
9
10 #define PACK_FILTER_X_NAME MAKENAME(_pack_filter_x)
11 #define PACK_FILTER_Y_NAME MAKENAME(_pack_filter_y)
12
13 #ifndef PREAMBLE
14 #define PREAMBLE(state)
15 #define PREAMBLE_PARAM_X
16 #define PREAMBLE_PARAM_Y
17 #define PREAMBLE_ARG_X
18 #define PREAMBLE_ARG_Y
19 #endif
20
21 #ifndef PREAMBLE_TRANS
22 #define PREAMBLE_TRANS(state)
23 #endif
24
25 static void TRANSLATE_NOFILTER_NAME(const SkBitmapProcState& s,
26 uint32_t xy[], int count, int x, int y)
27 {
28 SkASSERT((s.fInvType & ~SkMatrix::kTranslate_Mask) == 0);
29
30 PREAMBLE_TRANS(s);
31
32 x += SkScalarFloor(s.fInvMatrix->getTranslateX());
33 y += SkScalarFloor(s.fInvMatrix->getTranslateY());
34
35 *xy++ = (uint32_t)TILEY_TRANS(y, (s.fBitmap->height() - 1));
36
37 unsigned maxX = s.fBitmap->width() - 1;
38 int i;
39 uint16_t* xx = (uint16_t*)xy;
40 for (i = (count >> 2); i > 0; --i)
41 {
42 *xx++ = (uint16_t)TILEX_TRANS(x, maxX); x++;
43 *xx++ = (uint16_t)TILEX_TRANS(x, maxX); x++;
44 *xx++ = (uint16_t)TILEX_TRANS(x, maxX); x++;
45 *xx++ = (uint16_t)TILEX_TRANS(x, maxX); x++;
46 }
47 for (i = (count & 3); i > 0; --i)
48 {
49 *xx++ = (uint16_t)TILEX_TRANS(x, maxX); x++;
50 }
51 }
52
53 static void SCALE_NOFILTER_NAME(const SkBitmapProcState& s,
54 uint32_t xy[], int count, int x, int y) {
55 SkASSERT((s.fInvType & ~(SkMatrix::kTranslate_Mask |
56 SkMatrix::kScale_Mask)) == 0);
57
58 PREAMBLE(s);
59 // we store y, x, x, x, x, x
60
61 // invert x+half, y+half and convert to fixed
62 SkFixed fx = s.fInvSy * y + s.fInvTyPlusHalf;
63 *xy++ = TILEY_PROCF(fx, (s.fBitmap->height() - 1));
64 // invert X
65 SkFixed dx = s.fInvSx;
66 fx = dx * x + s.fInvTxPlusHalf;
67 unsigned maxX = s.fBitmap->width() - 1;
68
69 #ifdef CHECK_FOR_DECAL
70 // test if we don't need to apply the tile proc
71 if ((unsigned)(fx >> 16) <= maxX &&
72 (unsigned)((fx + dx * (count - 1)) >> 16) <= maxX) {
73 decal_nofilter_scale(xy, fx, dx, count);
74 } else
75 #endif
76 {
77 int i;
78 #if 0
79 uint16_t* xx = (uint16_t*)xy;
80 for (i = (count >> 2); i > 0; --i) {
81 *xx++ = TILEX_PROCF(fx, maxX); fx += dx;
82 *xx++ = TILEX_PROCF(fx, maxX); fx += dx;
83 *xx++ = TILEX_PROCF(fx, maxX); fx += dx;
84 *xx++ = TILEX_PROCF(fx, maxX); fx += dx;
85 }
86 for (i = (count & 3); i > 0; --i) {
87 *xx++ = TILEX_PROCF(fx, maxX); fx += dx;
88 }
89 #else
90 for (i = (count >> 2); i > 0; --i) {
91 unsigned a, b;
92 a = TILEX_PROCF(fx, maxX); fx += dx;
93 b = TILEX_PROCF(fx, maxX); fx += dx;
94 #ifdef SK_CPU_BENDIAN
95 *xy++ = (a << 16) | b;
96 #else
97 *xy++ = (b << 16) | a;
98 #endif
99 a = TILEX_PROCF(fx, maxX); fx += dx;
100 b = TILEX_PROCF(fx, maxX); fx += dx;
101 #ifdef SK_CPU_BENDIAN
102 *xy++ = (a << 16) | b;
103 #else
104 *xy++ = (b << 16) | a;
105 #endif
106 }
107 uint16_t* xx = (uint16_t*)xy;
108 for (i = (count & 3); i > 0; --i) {
109 *xx++ = TILEX_PROCF(fx, maxX); fx += dx;
110 }
111 #endif
112 }
113 }
114
115 // note: we could special-case on a matrix which is skewed in X but not Y.
116 // this would require a more general setup thatn SCALE does, but could use
117 // SCALE's inner loop that only looks at dx
118
119 static void AFFINE_NOFILTER_NAME(const SkBitmapProcState& s,
120 uint32_t xy[], int count, int x, int y) {
121 SkASSERT(s.fInvType & SkMatrix::kAffine_Mask);
122 SkASSERT((s.fInvType & ~(SkMatrix::kTranslate_Mask |
123 SkMatrix::kScale_Mask |
124 SkMatrix::kAffine_Mask)) == 0);
125
126 PREAMBLE(s);
127 SkPoint srcPt;
128 s.fInvProc(*s.fInvMatrix,
129 SkIntToScalar(x) + SK_ScalarHalf,
130 SkIntToScalar(y) + SK_ScalarHalf, &srcPt);
131
132 SkFixed fx = SkScalarToFixed(srcPt.fX);
133 SkFixed fy = SkScalarToFixed(srcPt.fY);
134 SkFixed dx = s.fInvSx;
135 SkFixed dy = s.fInvKy;
136 int maxX = s.fBitmap->width() - 1;
137 int maxY = s.fBitmap->height() - 1;
138
139 for (int i = count; i > 0; --i) {
140 *xy++ = (TILEY_PROCF(fy, maxY) << 16) | TILEX_PROCF(fx, maxX);
141 fx += dx; fy += dy;
142 }
143 }
144
145 static void PERSP_NOFILTER_NAME(const SkBitmapProcState& s,
146 uint32_t* SK_RESTRICT xy,
147 int count, int x, int y) {
148 SkASSERT(s.fInvType & SkMatrix::kPerspective_Mask);
149
150 PREAMBLE(s);
151 int maxX = s.fBitmap->width() - 1;
152 int maxY = s.fBitmap->height() - 1;
153
154 SkPerspIter iter(*s.fInvMatrix,
155 SkIntToScalar(x) + SK_ScalarHalf,
156 SkIntToScalar(y) + SK_ScalarHalf, count);
157
158 while ((count = iter.next()) != 0) {
159 const SkFixed* SK_RESTRICT srcXY = iter.getXY();
160 while (--count >= 0) {
161 *xy++ = (TILEY_PROCF(srcXY[1], maxY) << 16) |
162 TILEX_PROCF(srcXY[0], maxX);
163 srcXY += 2;
164 }
165 }
166 }
167
168 //////////////////////////////////////////////////////////////////////////////
169
170 static inline uint32_t PACK_FILTER_Y_NAME(SkFixed f, unsigned max,
171 SkFixed one PREAMBLE_PARAM_Y) {
172 unsigned i = TILEY_PROCF(f, max);
173 i = (i << 4) | TILEY_LOW_BITS(f, max);
174 return (i << 14) | (TILEY_PROCF((f + one), max));
175 }
176
177 static inline uint32_t PACK_FILTER_X_NAME(SkFixed f, unsigned max,
178 SkFixed one PREAMBLE_PARAM_X) {
179 unsigned i = TILEX_PROCF(f, max);
180 i = (i << 4) | TILEX_LOW_BITS(f, max);
181 return (i << 14) | (TILEX_PROCF((f + one), max));
182 }
183
184 static void SCALE_FILTER_NAME(const SkBitmapProcState& s,
185 uint32_t xy[], int count, int x, int y) {
186 SkASSERT((s.fInvType & ~(SkMatrix::kTranslate_Mask |
187 SkMatrix::kScale_Mask)) == 0);
188 SkASSERT(s.fInvKy == 0);
189
190 PREAMBLE(s);
191 // compute our two Y values up front
192 {
193 unsigned maxY = s.fBitmap->height() - 1;
194 SkFixed fy = s.fInvSy * y + s.fInvTyPlusHalf - (s.fFilterOneY >> 1);
195 *xy++ = PACK_FILTER_Y_NAME(fy, maxY, s.fFilterOneY PREAMBLE_ARG_Y);
196 }
197
198 unsigned maxX = s.fBitmap->width() - 1;
199 SkFixed one = s.fFilterOneX;
200 SkFixed dx = s.fInvSx;
201 SkFixed fx = dx * x + s.fInvTxPlusHalf - (one >> 1);
202
203 #ifdef CHECK_FOR_DECAL
204 // test if we don't need to apply the tile proc
205 if (dx > 0 &&
206 (unsigned)(fx >> 16) <= maxX &&
207 (unsigned)((fx + dx * (count - 1)) >> 16) < maxX) {
208 decal_filter_scale(xy, fx, dx, count);
209 } else
210 #endif
211 {
212 do {
213 *xy++ = PACK_FILTER_X_NAME(fx, maxX, one PREAMBLE_ARG_X);
214 fx += dx;
215 } while (--count != 0);
216 }
217 }
218
219 static void AFFINE_FILTER_NAME(const SkBitmapProcState& s,
220 uint32_t xy[], int count, int x, int y) {
221 SkASSERT(s.fInvType & SkMatrix::kAffine_Mask);
222 SkASSERT((s.fInvType & ~(SkMatrix::kTranslate_Mask |
223 SkMatrix::kScale_Mask |
224 SkMatrix::kAffine_Mask)) == 0);
225
226 PREAMBLE(s);
227 SkPoint srcPt;
228 s.fInvProc(*s.fInvMatrix,
229 SkIntToScalar(x) + SK_ScalarHalf,
230 SkIntToScalar(y) + SK_ScalarHalf, &srcPt);
231
232 SkFixed oneX = s.fFilterOneX;
233 SkFixed oneY = s.fFilterOneY;
234 SkFixed fx = SkScalarToFixed(srcPt.fX) - (oneX >> 1);
235 SkFixed fy = SkScalarToFixed(srcPt.fY) - (oneY >> 1);
236 SkFixed dx = s.fInvSx;
237 SkFixed dy = s.fInvKy;
238 unsigned maxX = s.fBitmap->width() - 1;
239 unsigned maxY = s.fBitmap->height() - 1;
240
241 do {
242 *xy++ = PACK_FILTER_Y_NAME(fy, maxY, oneY PREAMBLE_ARG_Y);
243 fy += dy;
244 *xy++ = PACK_FILTER_X_NAME(fx, maxX, oneX PREAMBLE_ARG_X);
245 fx += dx;
246 } while (--count != 0);
247 }
248
249 static void PERSP_FILTER_NAME(const SkBitmapProcState& s,
250 uint32_t* SK_RESTRICT xy, int count,
251 int x, int y) {
252 SkASSERT(s.fInvType & SkMatrix::kPerspective_Mask);
253
254 PREAMBLE(s);
255 unsigned maxX = s.fBitmap->width() - 1;
256 unsigned maxY = s.fBitmap->height() - 1;
257 SkFixed oneX = s.fFilterOneX;
258 SkFixed oneY = s.fFilterOneY;
259
260 SkPerspIter iter(*s.fInvMatrix,
261 SkIntToScalar(x) + SK_ScalarHalf,
262 SkIntToScalar(y) + SK_ScalarHalf, count);
263
264 while ((count = iter.next()) != 0) {
265 const SkFixed* SK_RESTRICT srcXY = iter.getXY();
266 do {
267 *xy++ = PACK_FILTER_Y_NAME(srcXY[1] - (oneY >> 1), maxY,
268 oneY PREAMBLE_ARG_Y);
269 *xy++ = PACK_FILTER_X_NAME(srcXY[0] - (oneX >> 1), maxX,
270 oneX PREAMBLE_ARG_X);
271 srcXY += 2;
272 } while (--count != 0);
273 }
274 }
275
276 static SkBitmapProcState::MatrixProc MAKENAME(_Procs)[] = {
277 TRANSLATE_NOFILTER_NAME,
278 TRANSLATE_NOFILTER_NAME, // No need to do filtering if the matrix is no
279 // more complex than identity/translate.
280 SCALE_NOFILTER_NAME,
281 SCALE_FILTER_NAME,
282 AFFINE_NOFILTER_NAME,
283 AFFINE_FILTER_NAME,
284 PERSP_NOFILTER_NAME,
285 PERSP_FILTER_NAME
286 };
287
288 #undef MAKENAME
289 #undef TILEX_PROCF
290 #undef TILEY_PROCF
291 #ifdef CHECK_FOR_DECAL
292 #undef CHECK_FOR_DECAL
293 #endif
294
295 #undef TILEX_TRANS
296 #undef TILEY_TRANS
297
298 #undef TRANSLATE_NOFILTER_NAME
299 #undef SCALE_NOFILTER_NAME
300 #undef SCALE_FILTER_NAME
301 #undef AFFINE_NOFILTER_NAME
302 #undef AFFINE_FILTER_NAME
303 #undef PERSP_NOFILTER_NAME
304 #undef PERSP_FILTER_NAME
305
306 #undef PREAMBLE
307 #undef PREAMBLE_PARAM_X
308 #undef PREAMBLE_PARAM_Y
309 #undef PREAMBLE_ARG_X
310 #undef PREAMBLE_ARG_Y
311
312 #undef PREAMBLE_TRANS
313
314 #undef TILEX_LOW_BITS
315 #undef TILEY_LOW_BITS
OLDNEW
« no previous file with comments | « skia/sgl/SkBitmapProcState.cpp ('k') | skia/sgl/SkBitmapProcState_matrixProcs.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698