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

Side by Side Diff: src/core/SkBitmapProcState_matrixProcs.cpp

Issue 236593006: Revert of use templates instead of macros to build blitters (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 8 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 | « src/core/SkBitmapProcState_matrix.h ('k') | src/core/SkBitmapProcState_matrix_template.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* NEON optimized code (C) COPYRIGHT 2009 Motorola 1 /* NEON optimized code (C) COPYRIGHT 2009 Motorola
2 * 2 *
3 * Use of this source code is governed by a BSD-style license that can be 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file. 4 * found in the LICENSE file.
5 */ 5 */
6 6
7 #include "SkBitmapProcState.h" 7 #include "SkBitmapProcState.h"
8 #include "SkPerspIter.h" 8 #include "SkPerspIter.h"
9 #include "SkShader.h" 9 #include "SkShader.h"
10 #include "SkUtils.h" 10 #include "SkUtils.h"
(...skipping 15 matching lines...) Expand all
26 } else { 26 } else {
27 x = x % n; 27 x = x % n;
28 } 28 }
29 } 29 }
30 return x; 30 return x;
31 } 31 }
32 32
33 void decal_nofilter_scale(uint32_t dst[], SkFixed fx, SkFixed dx, int count); 33 void decal_nofilter_scale(uint32_t dst[], SkFixed fx, SkFixed dx, int count);
34 void decal_filter_scale(uint32_t dst[], SkFixed fx, SkFixed dx, int count); 34 void decal_filter_scale(uint32_t dst[], SkFixed fx, SkFixed dx, int count);
35 35
36 #include "SkBitmapProcState_matrix_template.h"
37
38 ///////////////////////////////////////////////////////////////////////////////
39
40 // Compile neon code paths if needed 36 // Compile neon code paths if needed
41 #if !SK_ARM_NEON_IS_NONE 37 #if !SK_ARM_NEON_IS_NONE
42 38
43 // These are defined in src/opts/SkBitmapProcState_matrixProcs_neon.cpp 39 // These are defined in src/opts/SkBitmapProcState_matrixProcs_neon.cpp
44 extern const SkBitmapProcState::MatrixProc ClampX_ClampY_Procs_neon[]; 40 extern const SkBitmapProcState::MatrixProc ClampX_ClampY_Procs_neon[];
45 extern const SkBitmapProcState::MatrixProc RepeatX_RepeatY_Procs_neon[]; 41 extern const SkBitmapProcState::MatrixProc RepeatX_RepeatY_Procs_neon[];
46 42
47 #endif // !SK_ARM_NEON_IS_NONE 43 #endif // !SK_ARM_NEON_IS_NONE
48 44
49 // Compile non-neon code path if needed 45 // Compile non-neon code path if needed
50 #if !SK_ARM_NEON_IS_ALWAYS 46 #if !SK_ARM_NEON_IS_ALWAYS
51 #define MAKENAME(suffix) ClampX_ClampY ## suffix 47 #define MAKENAME(suffix) ClampX_ClampY ## suffix
52 #define TILEX_PROCF(fx, max) SkClampMax((fx) >> 16, max) 48 #define TILEX_PROCF(fx, max) SkClampMax((fx) >> 16, max)
53 #define TILEY_PROCF(fy, max) SkClampMax((fy) >> 16, max) 49 #define TILEY_PROCF(fy, max) SkClampMax((fy) >> 16, max)
54 #define TILEX_LOW_BITS(fx, max) (((fx) >> 12) & 0xF) 50 #define TILEX_LOW_BITS(fx, max) (((fx) >> 12) & 0xF)
55 #define TILEY_LOW_BITS(fy, max) (((fy) >> 12) & 0xF) 51 #define TILEY_LOW_BITS(fy, max) (((fy) >> 12) & 0xF)
56 #define CHECK_FOR_DECAL 52 #define CHECK_FOR_DECAL
57 #include "SkBitmapProcState_matrix.h" 53 #include "SkBitmapProcState_matrix.h"
58 54
59 struct ClampTileProcs {
60 static unsigned X(const SkBitmapProcState&, SkFixed fx, int max) {
61 return SkClampMax(fx >> 16, max);
62 }
63 static unsigned Y(const SkBitmapProcState&, SkFixed fy, int max) {
64 return SkClampMax(fy >> 16, max);
65 }
66 };
67
68 // Referenced in opts_check_SSE2.cpp
69 void ClampX_ClampY_nofilter_scale(const SkBitmapProcState& s, uint32_t xy[],
70 int count, int x, int y) {
71 return NoFilterProc_Scale<ClampTileProcs, true>(s, xy, count, x, y);
72 }
73 void ClampX_ClampY_nofilter_affine(const SkBitmapProcState& s, uint32_t xy[],
74 int count, int x, int y) {
75 return NoFilterProc_Affine<ClampTileProcs>(s, xy, count, x, y);
76 }
77
78 static SkBitmapProcState::MatrixProc ClampX_ClampY_Procs[] = {
79 // only clamp lives in the right coord space to check for decal
80 ClampX_ClampY_nofilter_scale,
81 ClampX_ClampY_filter_scale,
82 ClampX_ClampY_nofilter_affine,
83 ClampX_ClampY_filter_affine,
84 NoFilterProc_Persp<ClampTileProcs>,
85 ClampX_ClampY_filter_persp
86 };
87
88 #define MAKENAME(suffix) RepeatX_RepeatY ## suffix 55 #define MAKENAME(suffix) RepeatX_RepeatY ## suffix
89 #define TILEX_PROCF(fx, max) SK_USHIFT16(((fx) & 0xFFFF) * ((max) + 1)) 56 #define TILEX_PROCF(fx, max) SK_USHIFT16(((fx) & 0xFFFF) * ((max) + 1))
90 #define TILEY_PROCF(fy, max) SK_USHIFT16(((fy) & 0xFFFF) * ((max) + 1)) 57 #define TILEY_PROCF(fy, max) SK_USHIFT16(((fy) & 0xFFFF) * ((max) + 1))
91 #define TILEX_LOW_BITS(fx, max) ((((fx) & 0xFFFF) * ((max) + 1) >> 12) & 0xF) 58 #define TILEX_LOW_BITS(fx, max) ((((fx) & 0xFFFF) * ((max) + 1) >> 12) & 0xF)
92 #define TILEY_LOW_BITS(fy, max) ((((fy) & 0xFFFF) * ((max) + 1) >> 12) & 0xF) 59 #define TILEY_LOW_BITS(fy, max) ((((fy) & 0xFFFF) * ((max) + 1) >> 12) & 0xF)
93 #include "SkBitmapProcState_matrix.h" 60 #include "SkBitmapProcState_matrix.h"
94 #endif 61 #endif
95 62
96 struct RepeatTileProcs {
97 static unsigned X(const SkBitmapProcState&, SkFixed fx, int max) {
98 return SK_USHIFT16(((fx) & 0xFFFF) * ((max) + 1));
99 }
100 static unsigned Y(const SkBitmapProcState&, SkFixed fy, int max) {
101 return SK_USHIFT16(((fy) & 0xFFFF) * ((max) + 1));
102 }
103 };
104
105 static SkBitmapProcState::MatrixProc RepeatX_RepeatY_Procs[] = {
106 NoFilterProc_Scale<RepeatTileProcs, false>,
107 RepeatX_RepeatY_filter_scale,
108 NoFilterProc_Affine<RepeatTileProcs>,
109 RepeatX_RepeatY_filter_affine,
110 NoFilterProc_Persp<RepeatTileProcs>,
111 RepeatX_RepeatY_filter_persp
112 };
113
114 #define MAKENAME(suffix) GeneralXY ## suffix 63 #define MAKENAME(suffix) GeneralXY ## suffix
115 #define PREAMBLE(state) SkBitmapProcState::FixedTileProc tileProcX = (st ate).fTileProcX; (void) tileProcX; \ 64 #define PREAMBLE(state) SkBitmapProcState::FixedTileProc tileProcX = (st ate).fTileProcX; (void) tileProcX; \
116 SkBitmapProcState::FixedTileProc tileProcY = (st ate).fTileProcY; (void) tileProcY; \ 65 SkBitmapProcState::FixedTileProc tileProcY = (st ate).fTileProcY; (void) tileProcY; \
117 SkBitmapProcState::FixedTileLowBitsProc tileLowB itsProcX = (state).fTileLowBitsProcX; (void) tileLowBitsProcX; \ 66 SkBitmapProcState::FixedTileLowBitsProc tileLowB itsProcX = (state).fTileLowBitsProcX; (void) tileLowBitsProcX; \
118 SkBitmapProcState::FixedTileLowBitsProc tileLowB itsProcY = (state).fTileLowBitsProcY; (void) tileLowBitsProcY 67 SkBitmapProcState::FixedTileLowBitsProc tileLowB itsProcY = (state).fTileLowBitsProcY; (void) tileLowBitsProcY
119 #define PREAMBLE_PARAM_X , SkBitmapProcState::FixedTileProc tileProcX, Sk BitmapProcState::FixedTileLowBitsProc tileLowBitsProcX 68 #define PREAMBLE_PARAM_X , SkBitmapProcState::FixedTileProc tileProcX, Sk BitmapProcState::FixedTileLowBitsProc tileLowBitsProcX
120 #define PREAMBLE_PARAM_Y , SkBitmapProcState::FixedTileProc tileProcY, Sk BitmapProcState::FixedTileLowBitsProc tileLowBitsProcY 69 #define PREAMBLE_PARAM_Y , SkBitmapProcState::FixedTileProc tileProcY, Sk BitmapProcState::FixedTileLowBitsProc tileLowBitsProcY
121 #define PREAMBLE_ARG_X , tileProcX, tileLowBitsProcX 70 #define PREAMBLE_ARG_X , tileProcX, tileLowBitsProcX
122 #define PREAMBLE_ARG_Y , tileProcY, tileLowBitsProcY 71 #define PREAMBLE_ARG_Y , tileProcY, tileLowBitsProcY
123 #define TILEX_PROCF(fx, max) SK_USHIFT16(tileProcX(fx) * ((max) + 1)) 72 #define TILEX_PROCF(fx, max) SK_USHIFT16(tileProcX(fx) * ((max) + 1))
124 #define TILEY_PROCF(fy, max) SK_USHIFT16(tileProcY(fy) * ((max) + 1)) 73 #define TILEY_PROCF(fy, max) SK_USHIFT16(tileProcY(fy) * ((max) + 1))
125 #define TILEX_LOW_BITS(fx, max) tileLowBitsProcX(fx, (max) + 1) 74 #define TILEX_LOW_BITS(fx, max) tileLowBitsProcX(fx, (max) + 1)
126 #define TILEY_LOW_BITS(fy, max) tileLowBitsProcY(fy, (max) + 1) 75 #define TILEY_LOW_BITS(fy, max) tileLowBitsProcY(fy, (max) + 1)
127 #include "SkBitmapProcState_matrix.h" 76 #include "SkBitmapProcState_matrix.h"
128 77
129 struct GeneralTileProcs { 78 static inline U16CPU fixed_clamp(SkFixed x)
130 static unsigned X(const SkBitmapProcState& s, SkFixed fx, int max) { 79 {
131 return SK_USHIFT16(s.fTileProcX(fx) * ((max) + 1));
132 }
133 static unsigned Y(const SkBitmapProcState& s, SkFixed fy, int max) {
134 return SK_USHIFT16(s.fTileProcY(fy) * ((max) + 1));
135 }
136 };
137
138 static SkBitmapProcState::MatrixProc GeneralXY_Procs[] = {
139 NoFilterProc_Scale<GeneralTileProcs, false>,
140 GeneralXY_filter_scale,
141 NoFilterProc_Affine<GeneralTileProcs>,
142 GeneralXY_filter_affine,
143 NoFilterProc_Persp<GeneralTileProcs>,
144 GeneralXY_filter_persp
145 };
146
147 ///////////////////////////////////////////////////////////////////////////////
148
149 static inline U16CPU fixed_clamp(SkFixed x) {
150 if (x < 0) { 80 if (x < 0) {
151 x = 0; 81 x = 0;
152 } 82 }
153 if (x >> 16) { 83 if (x >> 16) {
154 x = 0xFFFF; 84 x = 0xFFFF;
155 } 85 }
156 return x; 86 return x;
157 } 87 }
158 88
159 static inline U16CPU fixed_repeat(SkFixed x) { 89 static inline U16CPU fixed_repeat(SkFixed x)
90 {
160 return x & 0xFFFF; 91 return x & 0xFFFF;
161 } 92 }
162 93
163 // Visual Studio 2010 (MSC_VER=1600) optimizes bit-shift code incorrectly. 94 // Visual Studio 2010 (MSC_VER=1600) optimizes bit-shift code incorrectly.
164 // See http://code.google.com/p/skia/issues/detail?id=472 95 // See http://code.google.com/p/skia/issues/detail?id=472
165 #if defined(_MSC_VER) && (_MSC_VER >= 1600) 96 #if defined(_MSC_VER) && (_MSC_VER >= 1600)
166 #pragma optimize("", off) 97 #pragma optimize("", off)
167 #endif 98 #endif
168 99
169 static inline U16CPU fixed_mirror(SkFixed x) { 100 static inline U16CPU fixed_mirror(SkFixed x)
101 {
170 SkFixed s = x << 15 >> 31; 102 SkFixed s = x << 15 >> 31;
171 // s is FFFFFFFF if we're on an odd interval, or 0 if an even interval 103 // s is FFFFFFFF if we're on an odd interval, or 0 if an even interval
172 return (x ^ s) & 0xFFFF; 104 return (x ^ s) & 0xFFFF;
173 } 105 }
174 106
175 #if defined(_MSC_VER) && (_MSC_VER >= 1600) 107 #if defined(_MSC_VER) && (_MSC_VER >= 1600)
176 #pragma optimize("", on) 108 #pragma optimize("", on)
177 #endif 109 #endif
178 110
179 static SkBitmapProcState::FixedTileProc choose_tile_proc(unsigned m) { 111 static SkBitmapProcState::FixedTileProc choose_tile_proc(unsigned m)
180 if (SkShader::kClamp_TileMode == m) { 112 {
113 if (SkShader::kClamp_TileMode == m)
181 return fixed_clamp; 114 return fixed_clamp;
182 } 115 if (SkShader::kRepeat_TileMode == m)
183 if (SkShader::kRepeat_TileMode == m) {
184 return fixed_repeat; 116 return fixed_repeat;
185 }
186 SkASSERT(SkShader::kMirror_TileMode == m); 117 SkASSERT(SkShader::kMirror_TileMode == m);
187 return fixed_mirror; 118 return fixed_mirror;
188 } 119 }
189 120
190 static inline U16CPU fixed_clamp_lowbits(SkFixed x, int) { 121 static inline U16CPU fixed_clamp_lowbits(SkFixed x, int) {
191 return (x >> 12) & 0xF; 122 return (x >> 12) & 0xF;
192 } 123 }
193 124
194 static inline U16CPU fixed_repeat_or_mirrow_lowbits(SkFixed x, int scale) { 125 static inline U16CPU fixed_repeat_or_mirrow_lowbits(SkFixed x, int scale) {
195 return ((x * scale) >> 12) & 0xF; 126 return ((x * scale) >> 12) & 0xF;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 if (SkShader::kClamp_TileMode == tm) 171 if (SkShader::kClamp_TileMode == tm)
241 return int_clamp; 172 return int_clamp;
242 if (SkShader::kRepeat_TileMode == tm) 173 if (SkShader::kRepeat_TileMode == tm)
243 return int_repeat; 174 return int_repeat;
244 SkASSERT(SkShader::kMirror_TileMode == tm); 175 SkASSERT(SkShader::kMirror_TileMode == tm);
245 return int_mirror; 176 return int_mirror;
246 } 177 }
247 178
248 ////////////////////////////////////////////////////////////////////////////// 179 //////////////////////////////////////////////////////////////////////////////
249 180
250 void decal_nofilter_scale(uint32_t dst[], SkFixed fx, SkFixed dx, int count) { 181 void decal_nofilter_scale(uint32_t dst[], SkFixed fx, SkFixed dx, int count)
182 {
251 int i; 183 int i;
252 184
253 for (i = (count >> 2); i > 0; --i) { 185 for (i = (count >> 2); i > 0; --i)
186 {
254 *dst++ = pack_two_shorts(fx >> 16, (fx + dx) >> 16); 187 *dst++ = pack_two_shorts(fx >> 16, (fx + dx) >> 16);
255 fx += dx+dx; 188 fx += dx+dx;
256 *dst++ = pack_two_shorts(fx >> 16, (fx + dx) >> 16); 189 *dst++ = pack_two_shorts(fx >> 16, (fx + dx) >> 16);
257 fx += dx+dx; 190 fx += dx+dx;
258 } 191 }
259 count &= 3; 192 count &= 3;
260 193
261 uint16_t* xx = (uint16_t*)dst; 194 uint16_t* xx = (uint16_t*)dst;
262 for (i = count; i > 0; --i) { 195 for (i = count; i > 0; --i) {
263 *xx++ = SkToU16(fx >> 16); fx += dx; 196 *xx++ = SkToU16(fx >> 16); fx += dx;
264 } 197 }
265 } 198 }
266 199
267 void decal_filter_scale(uint32_t dst[], SkFixed fx, SkFixed dx, int count) { 200 void decal_filter_scale(uint32_t dst[], SkFixed fx, SkFixed dx, int count)
268 if (count & 1) { 201 {
202
203
204 if (count & 1)
205 {
269 SkASSERT((fx >> (16 + 14)) == 0); 206 SkASSERT((fx >> (16 + 14)) == 0);
270 *dst++ = (fx >> 12 << 14) | ((fx >> 16) + 1); 207 *dst++ = (fx >> 12 << 14) | ((fx >> 16) + 1);
271 fx += dx; 208 fx += dx;
272 } 209 }
273 while ((count -= 2) >= 0) { 210 while ((count -= 2) >= 0)
211 {
274 SkASSERT((fx >> (16 + 14)) == 0); 212 SkASSERT((fx >> (16 + 14)) == 0);
275 *dst++ = (fx >> 12 << 14) | ((fx >> 16) + 1); 213 *dst++ = (fx >> 12 << 14) | ((fx >> 16) + 1);
276 fx += dx; 214 fx += dx;
277 215
278 *dst++ = (fx >> 12 << 14) | ((fx >> 16) + 1); 216 *dst++ = (fx >> 12 << 14) | ((fx >> 16) + 1);
279 fx += dx; 217 fx += dx;
280 } 218 }
281 } 219 }
282 220
283 /////////////////////////////////////////////////////////////////////////////// 221 ///////////////////////////////////////////////////////////////////////////////
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 if (forward) { 405 if (forward) {
468 fill_sequential(xptr, 0, count); 406 fill_sequential(xptr, 0, count);
469 } else { 407 } else {
470 fill_backwards(xptr, width - 1, count); 408 fill_backwards(xptr, width - 1, count);
471 } 409 }
472 } 410 }
473 } 411 }
474 412
475 /////////////////////////////////////////////////////////////////////////////// 413 ///////////////////////////////////////////////////////////////////////////////
476 414
477 SkBitmapProcState::MatrixProc SkBitmapProcState::chooseMatrixProc(bool trivial_m atrix) { 415 SkBitmapProcState::MatrixProc
416 SkBitmapProcState::chooseMatrixProc(bool trivial_matrix) {
478 // test_int_tileprocs(); 417 // test_int_tileprocs();
479 // check for our special case when there is no scale/affine/perspective 418 // check for our special case when there is no scale/affine/perspective
480 if (trivial_matrix) { 419 if (trivial_matrix) {
481 SkASSERT(SkPaint::kNone_FilterLevel == fFilterLevel); 420 SkASSERT(SkPaint::kNone_FilterLevel == fFilterLevel);
482 fIntTileProcY = choose_int_tile_proc(fTileModeY); 421 fIntTileProcY = choose_int_tile_proc(fTileModeY);
483 switch (fTileModeX) { 422 switch (fTileModeX) {
484 case SkShader::kClamp_TileMode: 423 case SkShader::kClamp_TileMode:
485 return clampx_nofilter_trans; 424 return clampx_nofilter_trans;
486 case SkShader::kRepeat_TileMode: 425 case SkShader::kRepeat_TileMode:
487 return repeatx_nofilter_trans; 426 return repeatx_nofilter_trans;
488 case SkShader::kMirror_TileMode: 427 case SkShader::kMirror_TileMode:
489 return mirrorx_nofilter_trans; 428 return mirrorx_nofilter_trans;
490 } 429 }
491 } 430 }
492 431
493 int index = 0; 432 int index = 0;
494 if (fFilterLevel != SkPaint::kNone_FilterLevel) { 433 if (fFilterLevel != SkPaint::kNone_FilterLevel) {
495 index = 1; 434 index = 1;
496 } 435 }
497 if (fInvType & SkMatrix::kPerspective_Mask) { 436 if (fInvType & SkMatrix::kPerspective_Mask) {
498 index += 4; 437 index += 4;
499 } else if (fInvType & SkMatrix::kAffine_Mask) { 438 } else if (fInvType & SkMatrix::kAffine_Mask) {
500 index += 2; 439 index += 2;
501 } 440 }
502 441
503 if (SkShader::kClamp_TileMode == fTileModeX && SkShader::kClamp_TileMode == fTileModeY) { 442 if (SkShader::kClamp_TileMode == fTileModeX &&
443 SkShader::kClamp_TileMode == fTileModeY)
444 {
504 // clamp gets special version of filterOne 445 // clamp gets special version of filterOne
505 fFilterOneX = SK_Fixed1; 446 fFilterOneX = SK_Fixed1;
506 fFilterOneY = SK_Fixed1; 447 fFilterOneY = SK_Fixed1;
507 return SK_ARM_NEON_WRAP(ClampX_ClampY_Procs)[index]; 448 return SK_ARM_NEON_WRAP(ClampX_ClampY_Procs)[index];
508 } 449 }
509 450
510 // all remaining procs use this form for filterOne 451 // all remaining procs use this form for filterOne
511 fFilterOneX = SK_Fixed1 / fBitmap->width(); 452 fFilterOneX = SK_Fixed1 / fBitmap->width();
512 fFilterOneY = SK_Fixed1 / fBitmap->height(); 453 fFilterOneY = SK_Fixed1 / fBitmap->height();
513 454
514 if (SkShader::kRepeat_TileMode == fTileModeX && SkShader::kRepeat_TileMode = = fTileModeY) { 455 if (SkShader::kRepeat_TileMode == fTileModeX &&
456 SkShader::kRepeat_TileMode == fTileModeY)
457 {
515 return SK_ARM_NEON_WRAP(RepeatX_RepeatY_Procs)[index]; 458 return SK_ARM_NEON_WRAP(RepeatX_RepeatY_Procs)[index];
516 } 459 }
517 460
518 fTileProcX = choose_tile_proc(fTileModeX); 461 fTileProcX = choose_tile_proc(fTileModeX);
519 fTileProcY = choose_tile_proc(fTileModeY); 462 fTileProcY = choose_tile_proc(fTileModeY);
520 fTileLowBitsProcX = choose_tile_lowbits_proc(fTileModeX); 463 fTileLowBitsProcX = choose_tile_lowbits_proc(fTileModeX);
521 fTileLowBitsProcY = choose_tile_lowbits_proc(fTileModeY); 464 fTileLowBitsProcY = choose_tile_lowbits_proc(fTileModeY);
522 return GeneralXY_Procs[index]; 465 return GeneralXY_Procs[index];
523 } 466 }
OLDNEW
« no previous file with comments | « src/core/SkBitmapProcState_matrix.h ('k') | src/core/SkBitmapProcState_matrix_template.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698