From 5595f6ef0e87ff14e7995c055fc7728a54980e86 Mon Sep 17 00:00:00 2001 From: Mike Klein Date: Wed, 5 Sep 2018 10:51:00 -0400 Subject: [PATCH] clean up S16CPU S16CPU is used only inside Skia, and only sparsely. - SkRandom::nextS16() and nextU16() were used rarely enough that it makes things simpler to get rid of them. - SkAlphaBlend255() was unused outside tests. - SkIntToFDot6() looks like it really wants to take an int. Change-Id: I3ca773beb6c04c691947d4602f27c819b660554d Reviewed-on: https://skia-review.googlesource.com/151700 Reviewed-by: Brian Osman --- include/core/SkTypes.h | 5 ----- include/utils/SkRandom.h | 8 -------- src/core/SkColorData.h | 15 --------------- src/core/SkFDot6.h | 2 +- tests/MathTest.cpp | 27 ++------------------------- tests/SkNxTest.cpp | 4 ++-- 6 files changed, 5 insertions(+), 56 deletions(-) diff --git a/include/core/SkTypes.h b/include/core/SkTypes.h index 95ee208ed6..697afc84d7 100644 --- a/include/core/SkTypes.h +++ b/include/core/SkTypes.h @@ -80,11 +80,6 @@ SK_API extern void sk_abort_no_print(void); */ typedef unsigned U8CPU; -/** Fast type for signed 16 bits. Use for parameter passing and local variables, - not for storage -*/ -typedef int S16CPU; - /** Fast type for unsigned 16 bits. Use for parameter passing and local variables, not for storage */ diff --git a/include/utils/SkRandom.h b/include/utils/SkRandom.h index aec9940262..390c0830ce 100644 --- a/include/utils/SkRandom.h +++ b/include/utils/SkRandom.h @@ -45,14 +45,6 @@ public: */ int32_t nextS() { return (int32_t)this->nextU(); } - /** Return the next pseudo random number as an unsigned 16bit value. - */ - U16CPU nextU16() { return this->nextU() >> 16; } - - /** Return the next pseudo random number as a signed 16bit value. - */ - S16CPU nextS16() { return this->nextS() >> 16; } - /** * Returns value [0...1) as an IEEE float */ diff --git a/src/core/SkColorData.h b/src/core/SkColorData.h index 3e61c18ae3..db1eb66b63 100644 --- a/src/core/SkColorData.h +++ b/src/core/SkColorData.h @@ -189,21 +189,6 @@ static inline int SkAlphaBlend(int src, int dst, int scale256) { return dst + SkAlphaMul(src - dst, scale256); } -/** - * Returns (src * alpha + dst * (255 - alpha)) / 255 - * - * This is more accurate than SkAlphaBlend, but slightly slower - */ -static inline int SkAlphaBlend255(S16CPU src, S16CPU dst, U8CPU alpha) { - SkASSERT((int16_t)src == src); - SkASSERT((int16_t)dst == dst); - SkASSERT((uint8_t)alpha == alpha); - - int prod = (src - dst) * alpha + 128; - prod = (prod + (prod >> 8)) >> 8; - return dst + prod; -} - #define SkR16Assert(r) SkASSERT((unsigned)(r) <= SK_R16_MASK) #define SkG16Assert(g) SkASSERT((unsigned)(g) <= SK_G16_MASK) #define SkB16Assert(b) SkASSERT((unsigned)(b) <= SK_B16_MASK) diff --git a/src/core/SkFDot6.h b/src/core/SkFDot6.h index 57e7d6a924..692e99882b 100644 --- a/src/core/SkFDot6.h +++ b/src/core/SkFDot6.h @@ -41,7 +41,7 @@ inline SkFDot6 SkScalarRoundToFDot6(SkScalar x, int shift = 0) #define SK_FDot6Half (32) #ifdef SK_DEBUG - inline SkFDot6 SkIntToFDot6(S16CPU x) { + inline SkFDot6 SkIntToFDot6(int x) { SkASSERT(SkToS16(x) == x); return x << 6; } diff --git a/tests/MathTest.cpp b/tests/MathTest.cpp index 857440c9f9..f4693262f9 100644 --- a/tests/MathTest.cpp +++ b/tests/MathTest.cpp @@ -198,27 +198,6 @@ static void test_blend31() { SkDebugf("---- failed %d death %d\n", failed, death); } -static void test_blend(skiatest::Reporter* reporter) { - for (int src = 0; src <= 255; src++) { - for (int dst = 0; dst <= 255; dst++) { - for (int a = 0; a <= 255; a++) { - int r0 = SkAlphaBlend255(src, dst, a); - float f1 = float_blend(src, dst, a / 255.f); - int r1 = SkScalarRoundToInt(f1); - - if (r0 != r1) { - float diff = sk_float_abs(f1 - r1); - diff = sk_float_abs(diff - 0.5f); - if (diff > (1 / 255.f)) { - ERRORF(reporter, "src:%d dst:%d a:%d " - "result:%d float:%g\n", src, dst, a, r0, f1); - } - } - } - } - } -} - static void check_length(skiatest::Reporter* reporter, const SkPoint& p, SkScalar targetLen) { float x = SkScalarToFloat(p.fX); @@ -462,8 +441,8 @@ DEF_TEST(Math, reporter) { } for (i = 0; i < 1000; i++) { - int value = rand.nextS16(); - int max = rand.nextU16(); + int value = rand.nextS() >> 16; + int max = rand.nextU() >> 16; int clamp = SkClampMax(value, max); int clamp2 = value < 0 ? 0 : (value > max ? max : value); @@ -527,8 +506,6 @@ DEF_TEST(Math, reporter) { REPORTER_ASSERT(reporter, result == (int32_t)check); } - test_blend(reporter); - if (false) test_floor(reporter); // disable for now diff --git a/tests/SkNxTest.cpp b/tests/SkNxTest.cpp index a454043936..7afedfed9c 100644 --- a/tests/SkNxTest.cpp +++ b/tests/SkNxTest.cpp @@ -324,8 +324,8 @@ DEF_TEST(SkNx_u16_float, r) { SkRandom rand; for (int i = 0; i < 10000; ++i) { const uint16_t s16[4] { - (uint16_t)rand.nextU16(), (uint16_t)rand.nextU16(), - (uint16_t)rand.nextU16(), (uint16_t)rand.nextU16(), + (uint16_t)(rand.nextU() >> 16), (uint16_t)(rand.nextU() >> 16), + (uint16_t)(rand.nextU() >> 16), (uint16_t)(rand.nextU() >> 16), }; auto u4_0 = Sk4h::Load(s16); auto f4 = SkNx_cast(u4_0);