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 <brianosman@google.com>
This commit is contained in:
Mike Klein 2018-09-05 10:51:00 -04:00
parent bbe8ff9a17
commit 5595f6ef0e
6 changed files with 5 additions and 56 deletions

View File

@ -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
*/

View File

@ -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
*/

View File

@ -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)

View File

@ -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;
}

View File

@ -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

View File

@ -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<float>(u4_0);