Remove SkClampRange (unused)

Bug: skia:
Change-Id: I57fbdd39079a92e803902524a7950dd5f571639c
Reviewed-on: https://skia-review.googlesource.com/84961
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
Brian Osman 2017-12-14 11:11:55 -05:00 committed by Skia Commit-Bot
parent d096e0d126
commit 19c026e3b8
5 changed files with 0 additions and 351 deletions

View File

@ -64,8 +64,6 @@ skia_effects_sources = [
"$_src/shaders/gradients/Sk4fGradientPriv.h", "$_src/shaders/gradients/Sk4fGradientPriv.h",
"$_src/shaders/gradients/Sk4fLinearGradient.cpp", "$_src/shaders/gradients/Sk4fLinearGradient.cpp",
"$_src/shaders/gradients/Sk4fLinearGradient.h", "$_src/shaders/gradients/Sk4fLinearGradient.h",
"$_src/shaders/gradients/SkClampRange.cpp",
"$_src/shaders/gradients/SkClampRange.h",
"$_src/shaders/gradients/SkGradientBitmapCache.cpp", "$_src/shaders/gradients/SkGradientBitmapCache.cpp",
"$_src/shaders/gradients/SkGradientBitmapCache.h", "$_src/shaders/gradients/SkGradientBitmapCache.h",
"$_src/shaders/gradients/SkGradientShader.cpp", "$_src/shaders/gradients/SkGradientShader.cpp",

View File

@ -26,7 +26,6 @@ tests_sources = [
"$_tests/CanvasStateTest.cpp", "$_tests/CanvasStateTest.cpp",
"$_tests/CanvasTest.cpp", "$_tests/CanvasTest.cpp",
"$_tests/ChecksumTest.cpp", "$_tests/ChecksumTest.cpp",
"$_tests/ClampRangeTest.cpp",
"$_tests/ClearTest.cpp", "$_tests/ClearTest.cpp",
"$_tests/ClipBoundsTest.cpp", "$_tests/ClipBoundsTest.cpp",
"$_tests/ClipCubicTest.cpp", "$_tests/ClipCubicTest.cpp",

View File

@ -1,178 +0,0 @@
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkClampRange.h"
#include "SkMathPriv.h"
static int SkCLZ64(uint64_t value) {
int count = 0;
if (value >> 32) {
value >>= 32;
} else {
count += 32;
}
return count + SkCLZ(SkToU32(value));
}
static bool sk_64_smul_check(int64_t count, int64_t dx, int64_t* result) {
// Do it the slow way until we have some assembly.
if (dx == std::numeric_limits<int64_t>::min()) {
return false; // SkTAbs overflow
}
SkASSERT(count >= 0);
uint64_t ucount = static_cast<uint64_t>(count);
uint64_t udx = static_cast<uint64_t>(SkTAbs(dx));
int zeros = SkCLZ64(ucount) + SkCLZ64(udx);
// this is a conservative check: it may return false when in fact it would not have overflowed.
// Hackers Delight uses 34 as its convervative check, but that is for 32x32 multiplies.
// Since we are looking at 64x64 muls, we add 32 to the check.
if (zeros < (32 + 34)) {
return false;
}
*result = count * dx;
return true;
}
static bool sk_64_sadd_check(int64_t a, int64_t b, int64_t* result) {
if (a > 0) {
if (b > std::numeric_limits<int64_t>::max() - a) {
return false;
}
} else {
if (b < std::numeric_limits<int64_t>::min() - a) {
return false;
}
}
*result = a + b;
return true;
}
/*
* returns [0..count] for the number of steps (<= count) for which x0 <= edge
* given each step is followed by x0 += dx
*/
static int chop(int64_t x0, SkGradFixed edge, int64_t x1, int64_t dx, int count) {
SkASSERT(dx > 0);
SkASSERT(count >= 0);
if (x0 >= edge) {
return 0;
}
if (x1 <= edge) {
return count;
}
int64_t n = (edge - x0 + dx - 1) / dx;
SkASSERT(n >= 0);
SkASSERT(n <= count);
return (int)n;
}
void SkClampRange::initFor1(SkGradFixed fx) {
fCount0 = fCount1 = fCount2 = 0;
if (fx <= 0) {
fCount0 = 1;
} else if (fx < kFracMax_SkGradFixed) {
fCount1 = 1;
fFx1 = fx;
} else {
fCount2 = 1;
}
}
void SkClampRange::init(SkGradFixed fx0, SkGradFixed dx0, int count, int v0, int v1) {
SkASSERT(count > 0);
fV0 = v0;
fV1 = v1;
// special case 1 == count, as it is slightly common for skia
// and avoids us ever calling divide or 64bit multiply
if (1 == count) {
this->initFor1(fx0);
return;
}
int64_t fx = fx0;
int64_t dx = dx0;
// start with ex equal to the last computed value
int64_t count_times_dx, ex;
if (!sk_64_smul_check(count - 1, dx, &count_times_dx) ||
!sk_64_sadd_check(fx, count_times_dx, &ex)) {
// we can't represent the computed end in 32.32, so just draw something (first color)
fCount1 = fCount2 = 0;
fCount0 = count;
return;
}
if ((uint64_t)(fx | ex) <= kFracMax_SkGradFixed) {
fCount0 = fCount2 = 0;
fCount1 = count;
fFx1 = fx0;
return;
}
if (fx <= 0 && ex <= 0) {
fCount1 = fCount2 = 0;
fCount0 = count;
return;
}
if (fx >= kFracMax_SkGradFixed && ex >= kFracMax_SkGradFixed) {
fCount0 = fCount1 = 0;
fCount2 = count;
return;
}
// now make ex be 1 past the last computed value
ex += dx;
bool doSwap = dx < 0;
if (doSwap) {
ex -= dx;
fx -= dx;
SkTSwap(fx, ex);
dx = -dx;
}
fCount0 = chop(fx, 0, ex, dx, count);
SkASSERT(fCount0 >= 0);
SkASSERT(fCount0 <= count);
count -= fCount0;
fx += fCount0 * dx;
SkASSERT(fx >= 0);
SkASSERT(fCount0 == 0 || (fx - dx) < 0);
fCount1 = chop(fx, kFracMax_SkGradFixed, ex, dx, count);
SkASSERT(fCount1 >= 0);
SkASSERT(fCount1 <= count);
count -= fCount1;
fCount2 = count;
#ifdef SK_DEBUG
fx += fCount1 * dx;
SkASSERT(fx <= ex);
if (fCount2 > 0) {
SkASSERT(fx >= kFracMax_SkGradFixed);
if (fCount1 > 0) {
SkASSERT(fx - dx < kFracMax_SkGradFixed);
}
}
#endif
if (doSwap) {
SkTSwap(fCount0, fCount2);
SkTSwap(fV0, fV1);
dx = -dx;
}
if (fCount1 > 0) {
fFx1 = fx0 + fCount0 * dx;
}
}

View File

@ -1,62 +0,0 @@
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkClampRange_DEFINED
#define SkClampRange_DEFINED
#include "SkFixed.h"
#include "SkScalar.h"
#define SkGradFixed SkFixed3232
// We want the largest 32.32 value representable as a float. (float)0x7FFFFFFF
// becomes too big, due to limited mantissa on the float and its rounding rules, so
// we have to manually compute the next smaller value (aka nextafter).
// #define SkGradFixedMaxScalar nextafterf(SkFixed3232ToFloat(SkFixed3232Max), 0)
// #define SkGradFixedMinScalar nextafterf(SkFixed3232ToFloat(SkFixed3232Min), 0)
#define SkGradFixedMaxScalar ( 2147483520.0f)
#define SkGradFixedMinScalar (-2147483520.0f)
#define SkScalarPinToGradFixed(x) SkScalarToFixed3232(SkTPin(x, \
SkGradFixedMinScalar,\
SkGradFixedMaxScalar))
#define SkFixedToGradFixed(x) SkFixedToFixed3232(x)
#define SkGradFixedToFixed(x) (SkFixed)((x) >> 16)
#define kFracMax_SkGradFixed 0xFFFFFFFFLL
/**
* Iteration fixed fx by dx, clamping as you go to [0..kFracMax_SkGradFixed], this class
* computes the (up to) 3 spans there are:
*
* range0: use constant value V0
* range1: iterate as usual fx += dx
* range2: use constant value V1
*/
struct SkClampRange {
int fCount0; // count for fV0
int fCount1; // count for interpolating (fV0...fV1)
int fCount2; // count for fV1
SkGradFixed fFx1; // initial fx value for the fCount1 range.
// only valid if fCount1 > 0
int fV0, fV1;
void init(SkGradFixed fx, SkGradFixed dx, int count, int v0, int v1);
void validate(int count) const {
#ifdef SK_DEBUG
SkASSERT(fCount0 >= 0);
SkASSERT(fCount1 >= 0);
SkASSERT(fCount2 >= 0);
SkASSERT(fCount0 + fCount1 + fCount2 == count);
#endif
}
private:
void initFor1(SkGradFixed fx);
};
#endif

View File

@ -1,108 +0,0 @@
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkRandom.h"
#include "Test.h"
#include "gradients/SkClampRange.h"
static skiatest::Reporter* gReporter;
#define R_ASSERT(cond) if (!(cond)) { \
SkDebugf("%d: %s\n", __LINE__, #cond); \
REPORTER_ASSERT(gReporter, cond); \
}
// Arbitrary sentinel values outside [0, 0xFFFF].
static const int kV0 = -42, kV1 = -53, kRamp = -64;
static void check_value(int64_t bigfx, int expected) {
if (bigfx < 0) {
R_ASSERT(expected == kV0);
} else if (bigfx > kFracMax_SkGradFixed) {
R_ASSERT(expected == kV1);
} else if (bigfx == kFracMax_SkGradFixed) {
// Either one is fine (and we do see both).
R_ASSERT(expected == kV1 || expected == kRamp);
} else {
R_ASSERT(expected == kRamp);
}
}
static void slow_check(const SkClampRange& range,
const SkGradFixed fx, SkGradFixed dx, int count) {
SkASSERT(range.fCount0 + range.fCount1 + range.fCount2 == count);
// If dx is large, fx will overflow if updated naively. So we use more bits.
int64_t bigfx = fx;
for (int i = 0; i < range.fCount0; i++) {
check_value(bigfx, range.fV0);
bigfx += dx;
}
for (int i = 0; i < range.fCount1; i++) {
check_value(bigfx, kRamp);
bigfx += dx;
}
for (int i = 0; i < range.fCount2; i++) {
check_value(bigfx, range.fV1);
bigfx += dx;
}
}
static void test_range(SkFixed fx, SkFixed dx, int count) {
const SkGradFixed gfx = SkFixedToGradFixed(fx);
const SkGradFixed gdx = SkFixedToGradFixed(dx);
SkClampRange range;
range.init(gfx, gdx, count, kV0, kV1);
slow_check(range, gfx, gdx, count);
}
#define ff(x) SkIntToFixed(x)
DEF_TEST(ClampRange, reporter) {
gReporter = reporter;
test_range(0, 0, 20);
test_range(0xFFFF, 0, 20);
test_range(-ff(2), 0, 20);
test_range( ff(2), 0, 20);
test_range(-10, 1, 20);
test_range(10, -1, 20);
test_range(-10, 3, 20);
test_range(10, -3, 20);
test_range(ff(1), ff(16384), 100);
test_range(ff(-1), ff(-16384), 100);
test_range(ff(1)/2, ff(16384), 100);
test_range(ff(1)/2, ff(-16384), 100);
SkRandom rand;
// test non-overflow cases
for (int i = 0; i < 1000000; i++) {
SkFixed fx = rand.nextS() >> 1;
SkFixed sx = rand.nextS() >> 1;
int count = rand.nextU() % 1000 + 1;
SkFixed dx = (sx - fx) / count;
test_range(fx, dx, count);
}
// TODO(reed): skia:2481, fix whatever bug this is, then uncomment
/*
// test overflow cases
for (int i = 0; i < 100000; i++) {
SkFixed fx = rand.nextS();
SkFixed dx = rand.nextS();
int count = rand.nextU() % 1000 + 1;
test_range(fx, dx, count);
}
*/
}