Change random number generator for 'tests' to SkMWCRandom. Also removes some
unused headers and fixes a couple of bugs exposed by changing the random
number generator:
First, the function SkMatrix::getMaxStretch() had an error where it was testing
the square of a number against near-zero. This led to it occasionally taking a
cheaper but imprecise path for computing the eigenvalues of the matrix. It's
been replaced with a check against the square of SK_ScalarNearlyZero.
The second case was a failure in ClipStackTest, where it hit the rare case of
a practically empty clip stack (it has a single Union) and we set a tight
bounds. The bounds rect doesn't get set by GrReducedClip::ReduceClipStack() in
this case, so when it clips the reduced stack it's clipping against garbage,
and the resulting regions don't match. The solution is to initialize the
tightBounds rect.
git-svn-id: http://skia.googlecode.com/svn/trunk@7952 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/tests/AAClipTest.cpp b/tests/AAClipTest.cpp
index 5c1d4e1..4c4ee60 100644
--- a/tests/AAClipTest.cpp
+++ b/tests/AAClipTest.cpp
@@ -87,7 +87,7 @@
canvas.drawColor(SK_ColorBLACK);
}
-static SkIRect rand_rect(SkRandom& rand, int n) {
+static SkIRect rand_rect(SkMWCRandom& rand, int n) {
int x = rand.nextS() % n;
int y = rand.nextS() % n;
int w = rand.nextU() % n;
@@ -95,7 +95,7 @@
return SkIRect::MakeXYWH(x, y, w, h);
}
-static void make_rand_rgn(SkRegion* rgn, SkRandom& rand) {
+static void make_rand_rgn(SkRegion* rgn, SkMWCRandom& rand) {
int count = rand.nextU() % 20;
for (int i = 0; i < count; ++i) {
rgn->op(rand_rect(rand, 100), SkRegion::kXOR_Op);
@@ -128,7 +128,7 @@
// aaclip.setRegion should create idential masks to the region
static void test_rgn(skiatest::Reporter* reporter) {
- SkRandom rand;
+ SkMWCRandom rand;
for (int i = 0; i < 1000; i++) {
SkRegion rgn;
make_rand_rgn(&rgn, rand);
@@ -232,7 +232,7 @@
REPORTER_ASSERT(reporter, mask.fBounds.isEmpty());
}
-static void rand_irect(SkIRect* r, int N, SkRandom& rand) {
+static void rand_irect(SkIRect* r, int N, SkMWCRandom& rand) {
r->setXYWH(0, 0, rand.nextU() % N, rand.nextU() % N);
int dx = rand.nextU() % (2*N);
int dy = rand.nextU() % (2*N);
@@ -241,7 +241,7 @@
}
static void test_irect(skiatest::Reporter* reporter) {
- SkRandom rand;
+ SkMWCRandom rand;
for (int i = 0; i < 10000; i++) {
SkAAClip clip0, clip1;
diff --git a/tests/BlurTest.cpp b/tests/BlurTest.cpp
index c0d16f8..57dc940 100644
--- a/tests/BlurTest.cpp
+++ b/tests/BlurTest.cpp
@@ -10,7 +10,6 @@
#include "SkCanvas.h"
#include "SkMath.h"
#include "SkPaint.h"
-#include "SkRandom.h"
///////////////////////////////////////////////////////////////////////////////
diff --git a/tests/ClampRangeTest.cpp b/tests/ClampRangeTest.cpp
index fa3804e..dc52071 100644
--- a/tests/ClampRangeTest.cpp
+++ b/tests/ClampRangeTest.cpp
@@ -107,7 +107,7 @@
test_range(ff(1)/2, ff(16384), 100);
test_range(ff(1)/2, ff(-16384), 100);
- SkRandom rand;
+ SkMWCRandom rand;
// test non-overflow cases
for (int i = 0; i < 1000000; i++) {
diff --git a/tests/ClipStackTest.cpp b/tests/ClipStackTest.cpp
index 4709d22..4de6673 100644
--- a/tests/ClipStackTest.cpp
+++ b/tests/ClipStackTest.cpp
@@ -820,7 +820,7 @@
add_oval,
};
- SkRandom r;
+ SkMWCRandom r;
for (int i = 0; i < kNumTests; ++i) {
// Randomly generate a clip stack.
@@ -864,7 +864,7 @@
ElementList reducedClips;
GrReducedClip::InitialState initial;
- SkIRect tBounds;
+ SkIRect tBounds(inflatedIBounds);
SkIRect* tightBounds = r.nextBool() ? &tBounds : NULL;
GrReducedClip::ReduceClipStack(stack,
inflatedIBounds,
diff --git a/tests/ColorFilterTest.cpp b/tests/ColorFilterTest.cpp
index 4016f21..0225649 100644
--- a/tests/ColorFilterTest.cpp
+++ b/tests/ColorFilterTest.cpp
@@ -35,7 +35,7 @@
#define ILLEGAL_MODE ((SkXfermode::Mode)-1)
static void test_asColorMode(skiatest::Reporter* reporter) {
- SkRandom rand;
+ SkMWCRandom rand;
for (int mode = 0; mode <= SkXfermode::kLastMode; mode++) {
SkColor color = rand.nextU();
diff --git a/tests/ColorTest.cpp b/tests/ColorTest.cpp
index a720ff4..c6e5485 100644
--- a/tests/ColorTest.cpp
+++ b/tests/ColorTest.cpp
@@ -146,7 +146,7 @@
*/
/*
static void test_interp(skiatest::Reporter* reporter) {
- SkRandom r;
+ SkMWCRandom r;
U8CPU a0 = 0;
U8CPU a255 = 255;
@@ -163,7 +163,7 @@
*/
static inline void test_fast_interp(skiatest::Reporter* reporter) {
- SkRandom r;
+ SkMWCRandom r;
U8CPU a0 = 0;
U8CPU a255 = 255;
diff --git a/tests/DrawBitmapRectTest.cpp b/tests/DrawBitmapRectTest.cpp
index ce33fcf..1917004 100644
--- a/tests/DrawBitmapRectTest.cpp
+++ b/tests/DrawBitmapRectTest.cpp
@@ -12,7 +12,7 @@
#include "SkRandom.h"
#include "SkMatrixUtils.h"
-static void rand_matrix(SkMatrix* mat, SkRandom& rand, unsigned mask) {
+static void rand_matrix(SkMatrix* mat, SkMWCRandom& rand, unsigned mask) {
mat->setIdentity();
if (mask & SkMatrix::kTranslate_Mask) {
mat->postTranslate(rand.nextSScalar1(), rand.nextSScalar1());
@@ -29,7 +29,7 @@
}
}
-static void rand_size(SkISize* size, SkRandom& rand) {
+static void rand_size(SkISize* size, SkMWCRandom& rand) {
size->set(rand.nextU() & 0xFFFF, rand.nextU() & 0xFFFF);
}
@@ -43,7 +43,7 @@
SkMatrix mat;
SkISize size;
- SkRandom rand;
+ SkMWCRandom rand;
// assert: translate-only no-filter can always be treated as sprite
for (int i = 0; i < 1000; ++i) {
diff --git a/tests/GrMemoryPoolTest.cpp b/tests/GrMemoryPoolTest.cpp
index 8660ea2..73f26a9 100644
--- a/tests/GrMemoryPoolTest.cpp
+++ b/tests/GrMemoryPoolTest.cpp
@@ -47,7 +47,7 @@
SK_DECLARE_INST_COUNT_ROOT(A);
- static A* Create(SkRandom* r);
+ static A* Create(SkMWCRandom* r);
static void SetAllocator(size_t preallocSize, size_t minAllocSize) {
#if SK_ENABLE_INST_COUNT
@@ -160,7 +160,7 @@
typedef A INHERITED;
};
-A* A::Create(SkRandom* r) {
+A* A::Create(SkMWCRandom* r) {
switch (r->nextRangeU(0, 4)) {
case 0:
return new A;
@@ -201,7 +201,7 @@
// number of iterations
static const int kCheckPeriod = 500;
- SkRandom r;
+ SkMWCRandom r;
for (size_t s = 0; s < SK_ARRAY_COUNT(gSizes); ++s) {
A::SetAllocator(gSizes[s][0], gSizes[s][1]);
for (size_t c = 0; c < SK_ARRAY_COUNT(gCreateFraction); ++c) {
diff --git a/tests/InfRectTest.cpp b/tests/InfRectTest.cpp
index 4d957dc..95ef4be 100644
--- a/tests/InfRectTest.cpp
+++ b/tests/InfRectTest.cpp
@@ -35,7 +35,7 @@
gData[index].fRect.centerY() == gData[index].fCenter.y());
}
- SkRandom rand;
+ SkMWCRandom rand;
for (int i = 0; i < 10000; ++i) {
SkIRect r;
diff --git a/tests/LListTest.cpp b/tests/LListTest.cpp
index ab36ef5..7c03ab5 100644
--- a/tests/LListTest.cpp
+++ b/tests/LListTest.cpp
@@ -124,7 +124,7 @@
static void TestTLList(skiatest::Reporter* reporter) {
typedef SkTLList<ListElement> ElList;
typedef ElList::Iter Iter;
- SkRandom random;
+ SkMWCRandom random;
for (int i = 1; i <= 16; i *= 2) {
diff --git a/tests/MathTest.cpp b/tests/MathTest.cpp
index 7fc53a9..105a3e4 100644
--- a/tests/MathTest.cpp
+++ b/tests/MathTest.cpp
@@ -173,7 +173,7 @@
REPORTER_ASSERT(reporter, len > 0.999f && len < 1.001f);
}
-static float nextFloat(SkRandom& rand) {
+static float nextFloat(SkMWCRandom& rand) {
SkFloatIntUnion data;
data.fSignBitInt = rand.nextU();
return data.fFloat;
@@ -247,7 +247,7 @@
}
static void unittest_fastfloat(skiatest::Reporter* reporter) {
- SkRandom rand;
+ SkMWCRandom rand;
size_t i;
static const float gFloats[] = {
@@ -368,7 +368,7 @@
REPORTER_ASSERT(reporter, sk_float_copysign(x, y) == expected);
}
- SkRandom rand;
+ SkMWCRandom rand;
for (int j = 0; j < 1000; j++) {
int ix = rand.nextS();
REPORTER_ASSERT(reporter, SkCopySign32(ix, ix) == ix);
@@ -387,7 +387,7 @@
static void TestMath(skiatest::Reporter* reporter) {
int i;
int32_t x;
- SkRandom rand;
+ SkMWCRandom rand;
// these should assert
#if 0
diff --git a/tests/MatrixTest.cpp b/tests/MatrixTest.cpp
index 56292dc..022e401 100644
--- a/tests/MatrixTest.cpp
+++ b/tests/MatrixTest.cpp
@@ -168,7 +168,7 @@
bool invertable = mats[i].invert(&mats[i + SK_ARRAY_COUNT(baseMats)]);
REPORTER_ASSERT(reporter, invertable);
}
- SkRandom rand;
+ SkMWCRandom rand;
for (int m = 0; m < 1000; ++m) {
SkMatrix mat;
mat.reset();
diff --git a/tests/PackBitsTest.cpp b/tests/PackBitsTest.cpp
index f7d4b8e..59c8a8c 100644
--- a/tests/PackBitsTest.cpp
+++ b/tests/PackBitsTest.cpp
@@ -14,7 +14,7 @@
static const uint16_t gTest3[] = { 0, 0, 0, 0, 0, 0, 1, 2, 3, 3, 3, 0, 0, 1 };
#include "SkRandom.h"
-static SkRandom gRand;
+static SkMWCRandom gRand;
static void rand_fill(uint16_t buffer[], int count) {
for (int i = 0; i < count; i++)
buffer[i] = (uint16_t)gRand.nextU();
diff --git a/tests/PathTest.cpp b/tests/PathTest.cpp
index a52e540..d8da95b 100644
--- a/tests/PathTest.cpp
+++ b/tests/PathTest.cpp
@@ -290,7 +290,7 @@
// Note: PathBench::ArbRoundRectBench performs almost exactly
// the same test (but with drawing)
static void test_arb_round_rect_is_convex(skiatest::Reporter* reporter) {
- SkRandom rand;
+ SkMWCRandom rand;
SkRect r;
for (int i = 0; i < 5000; ++i) {
@@ -317,7 +317,7 @@
// Note: PathBench::ArbRoundRectBench performs almost exactly
// the same test (but with drawing)
static void test_arb_zero_rad_round_rect_is_rect(skiatest::Reporter* reporter) {
- SkRandom rand;
+ SkMWCRandom rand;
SkRect r;
for (int i = 0; i < 5000; ++i) {
@@ -452,7 +452,7 @@
static void test_addPoly(skiatest::Reporter* reporter) {
SkPoint pts[32];
- SkRandom rand;
+ SkMWCRandom rand;
for (size_t i = 0; i < SK_ARRAY_COUNT(pts); ++i) {
pts[i].fX = rand.nextSScalar1();
@@ -1862,7 +1862,7 @@
}
// Max of 10 segments, max 3 points per segment
- SkRandom rand(9876543);
+ SkMWCRandom rand(9876543);
SkPoint expectedPts[31]; // May have leading moveTo
SkPath::Verb expectedVerbs[22]; // May have leading moveTo
SkPath::Verb nextVerb;
diff --git a/tests/PictureTest.cpp b/tests/PictureTest.cpp
index 0a562cf..6adfd5a 100644
--- a/tests/PictureTest.cpp
+++ b/tests/PictureTest.cpp
@@ -73,7 +73,7 @@
return pic;
}
-static void rand_rect(SkRect* rect, SkRandom& rand, SkScalar W, SkScalar H) {
+static void rand_rect(SkRect* rect, SkMWCRandom& rand, SkScalar W, SkScalar H) {
rect->fLeft = rand.nextRangeScalar(-W, 2*W);
rect->fTop = rand.nextRangeScalar(-H, 2*H);
rect->fRight = rect->fLeft + rand.nextRangeScalar(0, W);
@@ -176,7 +176,7 @@
drawbitmap_proc, drawbitmaprect_proc, drawshader_proc
};
- SkRandom rand;
+ SkMWCRandom rand;
for (size_t k = 0; k < SK_ARRAY_COUNT(procs); ++k) {
SkAutoTUnref<SkPicture> pic(record_bitmaps(bm, pos, N, procs[k]));
@@ -259,7 +259,7 @@
}
#endif
-static void rand_op(SkCanvas* canvas, SkRandom& rand) {
+static void rand_op(SkCanvas* canvas, SkMWCRandom& rand) {
SkPaint paint;
SkRect rect = SkRect::MakeWH(50, 50);
@@ -280,10 +280,10 @@
}
static void test_peephole() {
- SkRandom rand;
+ SkMWCRandom rand;
for (int j = 0; j < 100; j++) {
- SkRandom rand2(rand.getSeed()); // remember the seed
+ SkMWCRandom rand2(rand); // remember the seed
SkPicture picture;
SkCanvas* canvas = picture.beginRecording(100, 100);
@@ -292,6 +292,8 @@
rand_op(canvas, rand);
}
picture.endRecording();
+
+ rand = rand2;
}
{
diff --git a/tests/RTreeTest.cpp b/tests/RTreeTest.cpp
index 6962c89..6296c4e 100644
--- a/tests/RTreeTest.cpp
+++ b/tests/RTreeTest.cpp
@@ -23,7 +23,7 @@
void* data;
};
-static SkIRect random_rect(SkRandom& rand) {
+static SkIRect random_rect(SkMWCRandom& rand) {
SkIRect rect = {0,0,0,0};
while (rect.isEmpty()) {
rect.fLeft = rand.nextS() % 1000;
@@ -35,7 +35,7 @@
return rect;
}
-static void random_data_rects(SkRandom& rand, DataRect out[], int n) {
+static void random_data_rects(SkMWCRandom& rand, DataRect out[], int n) {
for (int i = 0; i < n; ++i) {
out[i].rect = random_rect(rand);
out[i].data = reinterpret_cast<void*>(i);
@@ -68,7 +68,7 @@
return found == expected;
}
-static void runQueries(skiatest::Reporter* reporter, SkRandom& rand, DataRect rects[],
+static void runQueries(skiatest::Reporter* reporter, SkMWCRandom& rand, DataRect rects[],
SkRTree& tree) {
for (size_t i = 0; i < NUM_QUERIES; ++i) {
SkTDArray<void*> hits;
@@ -80,7 +80,7 @@
static void TestRTree(skiatest::Reporter* reporter) {
DataRect rects[NUM_RECTS];
- SkRandom rand;
+ SkMWCRandom rand;
SkRTree* rtree = SkRTree::Create(MIN_CHILDREN, MAX_CHILDREN);
SkAutoUnref au(rtree);
REPORTER_ASSERT(reporter, NULL != rtree);
diff --git a/tests/RegionTest.cpp b/tests/RegionTest.cpp
index 5d3946e..1c06d7e 100644
--- a/tests/RegionTest.cpp
+++ b/tests/RegionTest.cpp
@@ -98,7 +98,7 @@
H = 256
};
-static SkIRect randRect(SkRandom& rand) {
+static SkIRect randRect(SkMWCRandom& rand) {
int x = rand.nextU() % W;
int y = rand.nextU() % H;
int w = rand.nextU() % W;
@@ -106,7 +106,7 @@
return SkIRect::MakeXYWH(x, y, w >> 1, h >> 1);
}
-static void randRgn(SkRandom& rand, SkRegion* rgn, int n) {
+static void randRgn(SkMWCRandom& rand, SkRegion* rgn, int n) {
rgn->setEmpty();
for (int i = 0; i < n; ++i) {
rgn->op(randRect(rand), SkRegion::kUnion_Op);
@@ -183,7 +183,7 @@
static void test_proc(skiatest::Reporter* reporter,
void (*proc)(skiatest::Reporter*,
const SkRegion& a, const SkRegion&)) {
- SkRandom rand;
+ SkMWCRandom rand;
for (int i = 0; i < 10000; ++i) {
SkRegion outer;
randRgn(rand, &outer, 8);
@@ -193,7 +193,7 @@
}
}
-static void rand_rect(SkIRect* rect, SkRandom& rand) {
+static void rand_rect(SkIRect* rect, SkMWCRandom& rand) {
int bits = 6;
int shift = 32 - bits;
rect->set(rand.nextU() >> shift, rand.nextU() >> shift,
@@ -237,7 +237,7 @@
};
REPORTER_ASSERT(reporter, test_rects(rects, SK_ARRAY_COUNT(rects)));
- SkRandom rand;
+ SkMWCRandom rand;
for (int i = 0; i < 1000; i++) {
SkRegion rgn0, rgn1;
diff --git a/tests/Sk64Test.cpp b/tests/Sk64Test.cpp
index 50b7ec7..e956cbb 100644
--- a/tests/Sk64Test.cpp
+++ b/tests/Sk64Test.cpp
@@ -75,7 +75,7 @@
// Now test add/sub
- SkRandom rand;
+ SkMWCRandom rand;
int i;
for (i = 0; i < 1000; i++)
diff --git a/tests/SortTest.cpp b/tests/SortTest.cpp
index 28c6e68..6bfb300 100644
--- a/tests/SortTest.cpp
+++ b/tests/SortTest.cpp
@@ -15,7 +15,7 @@
}
}
-static void rand_array(SkRandom& rand, int array[], int n) {
+static void rand_array(SkMWCRandom& rand, int array[], int n) {
for (int j = 0; j < n; j++) {
array[j] = rand.nextS() & 0xFF;
}
@@ -40,7 +40,7 @@
/** The random numbers are copied into this array, sorted by an SkSort,
then this array is compared against the reference sort. */
int workingArray[SK_ARRAY_COUNT(randomArray)];
- SkRandom rand;
+ SkMWCRandom rand;
for (int i = 0; i < 10000; i++) {
int count = rand.nextRangeU(1, SK_ARRAY_COUNT(randomArray));
diff --git a/tests/StreamTest.cpp b/tests/StreamTest.cpp
index 3174511..2b86e7b 100644
--- a/tests/StreamTest.cpp
+++ b/tests/StreamTest.cpp
@@ -17,7 +17,7 @@
#define MAX_SIZE (256 * 1024)
-static void random_fill(SkRandom& rand, void* buffer, size_t size) {
+static void random_fill(SkMWCRandom& rand, void* buffer, size_t size) {
char* p = (char*)buffer;
char* stop = p + size;
while (p < stop) {
@@ -26,7 +26,7 @@
}
static void test_buffer(skiatest::Reporter* reporter) {
- SkRandom rand;
+ SkMWCRandom rand;
SkAutoMalloc am(MAX_SIZE * 2);
char* storage = (char*)am.get();
char* storage2 = storage + MAX_SIZE;
@@ -62,7 +62,7 @@
static const char s[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
char copy[sizeof(s)];
- SkRandom rand;
+ SkMWCRandom rand;
for (int i = 0; i < 65; i++) {
char* copyPtr = copy;
diff --git a/tests/UtilsTest.cpp b/tests/UtilsTest.cpp
index 7f27f7e..bdabb57 100644
--- a/tests/UtilsTest.cpp
+++ b/tests/UtilsTest.cpp
@@ -54,7 +54,7 @@
static void test_search(skiatest::Reporter* reporter) {
int i, array[kSEARCH_COUNT];
- SkRandom rand;
+ SkMWCRandom rand;
for (i = 0; i < kSEARCH_COUNT; i++) {
array[i] = rand.nextS();
diff --git a/tests/Writer32Test.cpp b/tests/Writer32Test.cpp
index 33777a1..498be9c 100644
--- a/tests/Writer32Test.cpp
+++ b/tests/Writer32Test.cpp
@@ -134,7 +134,7 @@
SkAutoMalloc originalData(dataSize);
{
- SkRandom rand(0);
+ SkMWCRandom rand(0);
uint32_t* ptr = static_cast<uint32_t*>(originalData.get());
uint32_t* stop = ptr + (dataSize>>2);
while (ptr < stop) {