diff options
author | mal@chromium.org <mal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-15 07:00:54 +0000 |
---|---|---|
committer | mal@chromium.org <mal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-15 07:00:54 +0000 |
commit | ed16129adbdd6d8c1613863e2498e4a804035db1 (patch) | |
tree | 224239f78954cff931c064cfa0b6c4a71c19c8ca /skia | |
parent | 91305c89fa92f52453190b5007377a1df03140df (diff) | |
download | chromium_src-ed16129adbdd6d8c1613863e2498e4a804035db1.zip chromium_src-ed16129adbdd6d8c1613863e2498e4a804035db1.tar.gz chromium_src-ed16129adbdd6d8c1613863e2498e4a804035db1.tar.bz2 |
Fix Facebook sidebar.
Relanding http://codereview.chromium.org/20386 (r9836), this time
with re-baselined layout tests. The change affects the pixel diffs for
any test with a tiled css background image.
BUG = 5564
TBR= brettw
TEST= layout tests, conveniently re-baselined to pass with this change :)
Review URL: http://codereview.chromium.org/20388
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9839 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia')
-rw-r--r-- | skia/sgl/SkBitmapProcState.cpp | 5 | ||||
-rw-r--r-- | skia/sgl/SkBitmapProcState.h | 5 | ||||
-rw-r--r-- | skia/sgl/SkBitmapProcState_matrix.h | 42 | ||||
-rw-r--r-- | skia/sgl/SkBitmapProcState_matrixProcs.cpp | 72 |
4 files changed, 110 insertions, 14 deletions
diff --git a/skia/sgl/SkBitmapProcState.cpp b/skia/sgl/SkBitmapProcState.cpp index 428921d..eb87e7b 100644 --- a/skia/sgl/SkBitmapProcState.cpp +++ b/skia/sgl/SkBitmapProcState.cpp @@ -296,8 +296,9 @@ bool SkBitmapProcState::chooseProcs(const SkMatrix& inv, const SkPaint& paint) { } const SkMatrix* m; - if (SkShader::kClamp_TileMode == fTileModeX && - SkShader::kClamp_TileMode == fTileModeY) { + if (inv.getType() <= SkMatrix::kTranslate_Mask || + (SkShader::kClamp_TileMode == fTileModeX && + SkShader::kClamp_TileMode == fTileModeY)) { m = &inv; } else { fUnitInvMatrix = inv; diff --git a/skia/sgl/SkBitmapProcState.h b/skia/sgl/SkBitmapProcState.h index 1366d3b..fabc0e5 100644 --- a/skia/sgl/SkBitmapProcState.h +++ b/skia/sgl/SkBitmapProcState.h @@ -39,7 +39,8 @@ struct SkBitmapProcState { int count, uint16_t colors[]); - typedef U16CPU (*FixedTileProc)(SkFixed); // returns 0..0xFFFF + typedef SkFixed (*FixedTileProc)(SkFixed, int); + typedef int (*IntTileProc)(int, int); MatrixProc fMatrixProc; // chooseProcs SampleProc32 fSampleProc32; // chooseProcs @@ -48,6 +49,8 @@ struct SkBitmapProcState { SkMatrix fUnitInvMatrix; // chooseProcs FixedTileProc fTileProcX; // chooseProcs FixedTileProc fTileProcY; // chooseProcs + IntTileProc iTileProcX; // chooseProcs + IntTileProc iTileProcY; // chooseProcs SkFixed fFilterOneX; SkFixed fFilterOneY; diff --git a/skia/sgl/SkBitmapProcState_matrix.h b/skia/sgl/SkBitmapProcState_matrix.h index 1212a41..80d3e97 100644 --- a/skia/sgl/SkBitmapProcState_matrix.h +++ b/skia/sgl/SkBitmapProcState_matrix.h @@ -1,4 +1,5 @@ +#define TRANSLATE_NOFILTER_NAME MAKENAME(_nofilter_translate) #define SCALE_NOFILTER_NAME MAKENAME(_nofilter_scale) #define SCALE_FILTER_NAME MAKENAME(_filter_scale) #define AFFINE_NOFILTER_NAME MAKENAME(_nofilter_affine) @@ -17,6 +18,38 @@ #define PREAMBLE_ARG_Y #endif +#ifndef PREAMBLE_TRANS + #define PREAMBLE_TRANS(state) +#endif + +static void TRANSLATE_NOFILTER_NAME(const SkBitmapProcState& s, + uint32_t xy[], int count, int x, int y) +{ + SkASSERT((s.fInvType & ~SkMatrix::kTranslate_Mask) == 0); + + PREAMBLE_TRANS(s); + + x += SkScalarFloor(s.fInvMatrix->getTranslateX()); + y += SkScalarFloor(s.fInvMatrix->getTranslateY()); + + *xy++ = (uint32_t)TILEY_TRANS(y, (s.fBitmap->height() - 1)); + + unsigned maxX = s.fBitmap->width() - 1; + int i; + uint16_t* xx = (uint16_t*)xy; + for (i = (count >> 2); i > 0; --i) + { + *xx++ = (uint16_t)TILEX_TRANS(x, maxX); x++; + *xx++ = (uint16_t)TILEX_TRANS(x, maxX); x++; + *xx++ = (uint16_t)TILEX_TRANS(x, maxX); x++; + *xx++ = (uint16_t)TILEX_TRANS(x, maxX); x++; + } + for (i = (count & 3); i > 0; --i) + { + *xx++ = (uint16_t)TILEX_TRANS(x, maxX); x++; + } +} + static void SCALE_NOFILTER_NAME(const SkBitmapProcState& s, uint32_t xy[], int count, int x, int y) { SkASSERT((s.fInvType & ~(SkMatrix::kTranslate_Mask | @@ -241,6 +274,9 @@ static void PERSP_FILTER_NAME(const SkBitmapProcState& s, } static SkBitmapProcState::MatrixProc MAKENAME(_Procs)[] = { + TRANSLATE_NOFILTER_NAME, + TRANSLATE_NOFILTER_NAME, // No need to do filtering if the matrix is no + // more complex than identity/translate. SCALE_NOFILTER_NAME, SCALE_FILTER_NAME, AFFINE_NOFILTER_NAME, @@ -256,6 +292,10 @@ static SkBitmapProcState::MatrixProc MAKENAME(_Procs)[] = { #undef CHECK_FOR_DECAL #endif +#undef TILEX_TRANS +#undef TILEY_TRANS + +#undef TRANSLATE_NOFILTER_NAME #undef SCALE_NOFILTER_NAME #undef SCALE_FILTER_NAME #undef AFFINE_NOFILTER_NAME @@ -269,5 +309,7 @@ static SkBitmapProcState::MatrixProc MAKENAME(_Procs)[] = { #undef PREAMBLE_ARG_X #undef PREAMBLE_ARG_Y +#undef PREAMBLE_TRANS + #undef TILEX_LOW_BITS #undef TILEY_LOW_BITS diff --git a/skia/sgl/SkBitmapProcState_matrixProcs.cpp b/skia/sgl/SkBitmapProcState_matrixProcs.cpp index beb21c8..a16c8b3 100644 --- a/skia/sgl/SkBitmapProcState_matrixProcs.cpp +++ b/skia/sgl/SkBitmapProcState_matrixProcs.cpp @@ -28,6 +28,8 @@ void decal_filter_scale(uint32_t dst[], SkFixed fx, SkFixed dx, int count); #define TILEX_LOW_BITS(fx, max) (((fx) >> 12) & 0xF) #define TILEY_LOW_BITS(fy, max) (((fy) >> 12) & 0xF) #define CHECK_FOR_DECAL +#define TILEX_TRANS(x, max) SkClampMax(x, max) +#define TILEY_TRANS(y, max) SkClampMax(y, max) #include "SkBitmapProcState_matrix.h" #define MAKENAME(suffix) RepeatX_RepeatY ## suffix @@ -35,6 +37,8 @@ void decal_filter_scale(uint32_t dst[], SkFixed fx, SkFixed dx, int count); #define TILEY_PROCF(fy, max) (((fy) & 0xFFFF) * ((max) + 1) >> 16) #define TILEX_LOW_BITS(fx, max) ((((fx) & 0xFFFF) * ((max) + 1) >> 12) & 0xF) #define TILEY_LOW_BITS(fy, max) ((((fy) & 0xFFFF) * ((max) + 1) >> 12) & 0xF) +#define TILEX_TRANS(x, max) ((x) % ((max) + 1)) +#define TILEY_TRANS(y, max) ((y) % ((max) + 1)) #include "SkBitmapProcState_matrix.h" #define MAKENAME(suffix) GeneralXY ## suffix @@ -44,13 +48,19 @@ void decal_filter_scale(uint32_t dst[], SkFixed fx, SkFixed dx, int count); #define PREAMBLE_PARAM_Y , SkBitmapProcState::FixedTileProc tileProcY #define PREAMBLE_ARG_X , tileProcX #define PREAMBLE_ARG_Y , tileProcY -#define TILEX_PROCF(fx, max) (tileProcX(fx) * ((max) + 1) >> 16) -#define TILEY_PROCF(fy, max) (tileProcY(fy) * ((max) + 1) >> 16) -#define TILEX_LOW_BITS(fx, max) ((tileProcX(fx) * ((max) + 1) >> 12) & 0xF) -#define TILEY_LOW_BITS(fy, max) ((tileProcY(fy) * ((max) + 1) >> 12) & 0xF) +#define TILEX_PROCF(fx, max) (tileProcX(fx, max) >> 16) +#define TILEY_PROCF(fy, max) (tileProcY(fy, max) >> 16) +#define TILEX_LOW_BITS(fx, max) ((tileProcX(fx, max) >> 14) & 0x3) +#define TILEY_LOW_BITS(fy, max) ((tileProcY(fy, max) >> 14) & 0x3) +#define PREAMBLE_TRANS(state) SkBitmapProcState::IntTileProc tileProcX = (state).iTileProcX; \ + SkBitmapProcState::IntTileProc tileProcY = (state).iTileProcY +#define TILEX_TRANS(x, max) tileProcX(x, max) +#define TILEY_TRANS(y, max) tileProcY(y, max) #include "SkBitmapProcState_matrix.h" -static inline U16CPU fixed_clamp(SkFixed x) + + +static inline SkFixed fixed_clamp(SkFixed x, int max) { #ifdef SK_CPU_HAS_CONDITIONAL_INSTR if (x >> 16) @@ -66,19 +76,20 @@ static inline U16CPU fixed_clamp(SkFixed x) x = 0xFFFF; } #endif - return x; + return x * (max + 1); } -static inline U16CPU fixed_repeat(SkFixed x) +static inline SkFixed fixed_repeat(SkFixed x, int max) { - return x & 0xFFFF; + return (x & 0xFFFF) * (max + 1); } -static inline U16CPU fixed_mirror(SkFixed x) +static inline SkFixed fixed_mirror(SkFixed x, int max) { 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; + x = ((x ^ s) & 0xFFFF) * (max + 1); + return s ? (x ^ 0xFFFF) : x; } static SkBitmapProcState::FixedTileProc choose_tile_proc(unsigned m) @@ -91,14 +102,51 @@ static SkBitmapProcState::FixedTileProc choose_tile_proc(unsigned m) return fixed_mirror; } +static inline int int_clamp(int x, int max) +{ + SkASSERT(max >= 0); + + return SkClampMax(x, max); +} + +static inline int int_repeat(int x, int max) +{ + SkASSERT(max >= 0); + + return x % (max + 1); +} + +static inline int int_mirror(int x, int max) +{ + SkASSERT(max >= 0); + + int dx = x % (max + 1); + if (dx < 0) + dx = -dx - 1; + + return (x / (max + 1) % 2) ? max - dx : dx; +} + +static SkBitmapProcState::IntTileProc choose_int_tile_proc(unsigned m) +{ + if (SkShader::kClamp_TileMode == m) + return int_clamp; + if (SkShader::kRepeat_TileMode == m) + return int_repeat; + SkASSERT(SkShader::kMirror_TileMode == m); + return int_mirror; +} + SkBitmapProcState::MatrixProc SkBitmapProcState::chooseMatrixProc() { int index = 0; if (fDoFilter) index = 1; if (fInvType & SkMatrix::kPerspective_Mask) - index |= 4; + index |= 6; else if (fInvType & SkMatrix::kAffine_Mask) + index |= 4; + else if (fInvType & SkMatrix::kScale_Mask) index |= 2; if (SkShader::kClamp_TileMode == fTileModeX && @@ -123,6 +171,8 @@ SkBitmapProcState::MatrixProc SkBitmapProcState::chooseMatrixProc() // only general needs these procs fTileProcX = choose_tile_proc(fTileModeX); fTileProcY = choose_tile_proc(fTileModeY); + iTileProcX = choose_int_tile_proc(fTileModeX); + iTileProcY = choose_int_tile_proc(fTileModeY); return GeneralXY_Procs[index]; } |