/* NEON optimized code (C) COPYRIGHT 2009 Motorola
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkBitmapProcState.h"
#include "SkPerspIter.h"
#include "SkShader.h"
#include "SkUtils.h"
#include "SkUtilsArm.h"
#include "SkBitmapProcState_utils.h"
/* returns 0...(n-1) given any x (positive or negative).
As an example, if n (which is always positive) is 5...
x: -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8
returns: 2 3 4 0 1 2 3 4 0 1 2 3 4 0 1 2 3
*/
static inline int sk_int_mod(int x, int n) {
SkASSERT(n > 0);
if ((unsigned)x >= (unsigned)n) {
if (x < 0) {
x = n + ~(~x % n);
} else {
x = x % n;
}
}
return x;
}
void decal_nofilter_scale(uint32_t dst[], SkFixed fx, SkFixed dx, int count);
void decal_filter_scale(uint32_t dst[], SkFixed fx, SkFixed dx, int count);
#include "SkBitmapProcState_matrix_template.h"
///////////////////////////////////////////////////////////////////////////////
// Compile neon code paths if needed
#if !SK_ARM_NEON_IS_NONE
// These are defined in src/opts/SkBitmapProcState_matrixProcs_neon.cpp
extern const SkBitmapProcState::MatrixProc ClampX_ClampY_Procs_neon[];
extern const SkBitmapProcState::MatrixProc RepeatX_RepeatY_Procs_neon[];
#endif // !SK_ARM_NEON_IS_NONE
// Compile non-neon code path if needed
#if !SK_ARM_NEON_IS_ALWAYS
#define MAKENAME(suffix) ClampX_ClampY ## suffix
#define TILEX_PROCF(fx, max) SkClampMax((fx) >> 16, max)
#define TILEY_PROCF(fy, max) SkClampMax((fy) >> 16, max)
#define TILEX_LOW_BITS(fx, max) (((fx) >> 12) & 0xF)
#define TILEY_LOW_BITS(fy, max) (((fy) >> 12) & 0xF)
#define CHECK_FOR_DECAL
#include "SkBitmapProcState_matrix.h"
struct ClampTileProcs {
static unsigned X(const SkBitmapProcState&, SkFixed fx, int max) {
return SkClampMax(fx >> 16, max);
}
static unsigned Y(const SkBitmapProcState&, SkFixed fy, int max) {
return SkClampMax(fy >> 16, max);
}
};
// Referenced in opts_check_x86.cpp
void ClampX_ClampY_nofilter_scale(const SkBitmapProcState& s, uint32_t xy[],
int count, int x, int y) {
return NoFilterProc_Scale<ClampTileProcs, true>(s, xy, count, x, y);
}
void ClampX_ClampY_nofilter_affine(const SkBitmapProcState& s, uint32_t xy[],
int count, int x, int y) {
return NoFilterProc_Affine<ClampTileProcs>(s, xy, count, x, y);
}
static SkBitmapProcState::MatrixProc ClampX_ClampY_Procs[] = {
// only clamp lives in the right coord space to check for decal
ClampX_ClampY_nofilter_scale,
ClampX_ClampY_filter_scale,
ClampX_ClampY_nofilter_affine,
ClampX_ClampY_filter_affine,
NoFilterProc_Persp<ClampTileProcs>,
ClampX_ClampY_filter_persp
};
#define MAKENAME(suffix) RepeatX_RepeatY ## suffix
#define TILEX_PROCF(fx, max) SK_USHIFT16(((fx) & 0xFFFF) * ((max) + 1))
#define TILEY_PROCF(fy, max) SK_USHIFT16(((fy) & 0xFFFF) * ((max) + 1))
#define TILEX_LOW_BITS(fx, max) ((((fx) & 0xFFFF) * ((max) + 1) >> 12) & 0xF)
#define TILEY_LOW_BITS(fy, max) ((((fy) & 0xFFFF) * ((max) + 1) >> 12) & 0xF)
#include "SkBitmapProcState_matrix.h"
struct RepeatTileProcs {
static unsigned X(const SkBitmapProcState&, SkFixed fx, int max) {
return SK_USHIFT16(((fx) & 0xFFFF) * ((max) + 1));
}
static unsigned Y(const SkBitmapProcState&, SkFixed fy, int max) {
return SK_USHIFT16(((fy) & 0xFFFF) * ((max) + 1));
}
};
static SkBitmapProcState::MatrixProc RepeatX_RepeatY_Procs[] = {
NoFilterProc_Scale<RepeatTileProcs, false>,
RepeatX_RepeatY_filter_scale,
NoFilterProc_Affine<RepeatTileProcs>,
RepeatX_RepeatY_filter_affine,
NoFilterProc_Persp<RepeatTileProcs>,
RepeatX_RepeatY_filter_persp
};
#endif
#define MAKENAME(suffix) GeneralXY ## suffix
#define PREAMBLE(state) SkBitmapProcState::FixedTileProc tileProcX = (state).fTileProcX; (void) tileProcX; \
SkBitmapProcState::FixedTileProc tileProcY = (state).fTileProcY; (void) tileProcY; \
SkBitmapProcState::FixedTileLowBitsProc tileLowBitsProcX = (state).fTileLowBitsProcX; (void) tileLowBitsProcX; \
SkBitmapProcState::FixedTileLowBitsProc tileLowBitsProcY = (state).fTileLowBitsProcY; (void) tileLowBitsProcY
#define PREAMBLE_PARAM_X , SkBitmapProcState::FixedTileProc tileProcX, SkBitmapProcState::FixedTileLowBitsProc tileLowBitsProcX
#define PREAMBLE_PARAM_Y , SkBitmapProcState::FixedTileProc tileProcY, SkBitmapProcState::FixedTileLowBitsProc tileLowBitsProcY
#define PREAMBLE_ARG_X , tileProcX, tileLowBitsProcX
#define PREAMBLE_ARG_Y , tileProcY, tileLowBitsProcY
#define TILEX_PROCF(fx, max) SK_USHIFT16(tileProcX(fx) * ((max) + 1))
#define TILEY_PROCF(fy, max) SK_USHIFT16(tileProcY(fy) * ((max) + 1))
#define TILEX_LOW_BITS(fx, max) tileLowBitsProcX(fx, (max) + 1)
#define TILEY_LOW_BITS(fy, max) tileLowBitsProcY(fy, (max) + 1)
#include "SkBitmapProcState_matrix.h"
struct GeneralTileProcs {
static unsigned X(const SkBitmapProcState& s, SkFixed fx, int max) {
return SK_USHIFT16(s.fTileProcX(fx) * ((max) + 1));
}
static unsigned Y(const SkBitmapProcState& s, SkFixed fy, int max) {
return SK_USHIFT16(s.fTileProcY(fy) * ((max) + 1));
}
};
static SkBitmapProcState::MatrixProc GeneralXY_Procs[] = {
NoFilterProc_Scale<GeneralTileProcs, false>,
GeneralXY_filter_scale,
NoFilterProc_Affine<GeneralTileProcs>,
GeneralXY_filter_affine,
NoFilterProc_Persp<GeneralTileProcs>,
GeneralXY_filter_persp
};
///////////////////////////////////////////////////////////////////////////////
static inline U16CPU fixed_clamp(SkFixed x) {
if (x < 0) {
x = 0;
}
if (x >> 16) {
x = 0xFFFF;
}
return x;
}
static inline U16CPU fixed_repeat(SkFixed x) {
return x & 0xFFFF;
}
// Visual Studio 2010 (MSC_VER=1600) optimizes bit-shift code incorrectly.
// See http://code.google.com/p/skia/issues/detail?id=472
#if defined(_MSC_VER) && (_MSC_VER >= 1600)
#pragma optimize("", off)
#endif
static inline U16CPU fixed_mirror(SkFixed x) {
SkFixed s = x << 15 >> 31;
// s is FFFFFFFF if we're on an odd interval, or 0 if an even interval
return (x ^ s) & 0xFFFF;
}
#if defined(_MSC_VER) && (_MSC_VER >= 1600)
#pragma optimize("", on)
#endif
static SkBitmapProcState::FixedTileProc choose_tile_proc(unsigned m) {
if (SkShader::kClamp_TileMode == m) {
return fixed_clamp;
}
if (SkShader::kRepeat_TileMode == m) {
return fixed_repeat;
}
SkASSERT(SkShader::kMirror_TileMode == m);
return fixed_mirror;
}
static inline U16CPU fixed_clamp_lowbits(SkFixed x, int) {
return (x >> 12) & 0xF;
}
static inline U16CPU fixed_repeat_or_mirrow_lowbits(SkFixed x, int scale) {
return ((x * scale) >> 12) & 0xF;
}
static SkBitmapProcState::FixedTileLowBitsProc choose_tile_lowbits_proc(unsigned m) {
if (SkShader::kClamp_TileMode == m) {
return fixed_clamp_lowbits;
} else {
SkASSERT(SkShader::kMirror_TileMode == m ||
SkShader::kRepeat_TileMode == m);
// mirror and repeat have the same behavior for the low bits.
return fixed_repeat_or_mirrow_lowbits;
}
}
static inline U16CPU int_clamp(int x, int n) {
if (x >= n) {
x = n - 1;
}
if (x < 0) {
x = 0;
}
return x;
}
static inline U16CPU int_repeat(int x, int n) {
return sk_int_mod(x, n);
}
static inline U16CPU int_mirror(int x, int n) {
x = sk_int_mod(x, 2 * n);
if (x >= n) {
x = n + ~(x - n);
}
return x;
}
#if 0
static void test_int_tileprocs() {
for (int i = -8; i <= 8; i++) {
SkDebugf(" int_mirror(%2d, 3) = %d\n", i, int_mirror(i, 3));
}
}
#endif
static SkBitmapProcState