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

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

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