Make SkFixedRound/Ceil/FloorToFixed as inline func

The macros that we were using will return unsigned int32 instead of
signed int32 because of the last 0xFFFF0000 mask. That may bring
problems if we right shift that result.

Special thanks to mtklein@google.com for helping me find out this issue.

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2433233003

Review-Url: https://chromiumcodereview.appspot.com/2433233003
This commit is contained in:
liyuqian 2016-10-20 11:23:09 -07:00 committed by Commit bot
parent c0d550143e
commit 3f490cc642
2 changed files with 15 additions and 3 deletions

View File

@ -69,9 +69,15 @@ typedef int32_t SkFixed;
#define SkFixedCeilToInt(x) (((x) + SK_Fixed1 - 1) >> 16)
#define SkFixedFloorToInt(x) ((x) >> 16)
#define SkFixedRoundToFixed(x) (((x) + SK_FixedHalf) & 0xFFFF0000)
#define SkFixedCeilToFixed(x) (((x) + SK_Fixed1 - 1) & 0xFFFF0000)
#define SkFixedFloorToFixed(x) ((x) & 0xFFFF0000)
static inline SkFixed SkFixedRoundToFixed(SkFixed x) {
return (x + SK_FixedHalf) & 0xFFFF0000;
}
static inline SkFixed SkFixedCeilToFixed(SkFixed x) {
return (x + SK_Fixed1 - 1) & 0xFFFF0000;
}
static inline SkFixed SkFixedFloorToFixed(SkFixed x) {
return x & 0xFFFF0000;
}
#define SkFixedAbs(x) SkAbs32(x)
#define SkFixedAve(a, b) (((a) + (b)) >> 1)

View File

@ -534,6 +534,12 @@ DEF_TEST(Math, reporter) {
REPORTER_ASSERT(reporter, result == 3);
}
{
REPORTER_ASSERT(reporter, (SkFixedRoundToFixed(-SK_Fixed1 * 10) >> 1) == -SK_Fixed1 * 5);
REPORTER_ASSERT(reporter, (SkFixedFloorToFixed(-SK_Fixed1 * 10) >> 1) == -SK_Fixed1 * 5);
REPORTER_ASSERT(reporter, (SkFixedCeilToFixed(-SK_Fixed1 * 10) >> 1) == -SK_Fixed1 * 5);
}
unittest_fastfloat(reporter);
unittest_isfinite(reporter);
unittest_half(reporter);