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
This commit is contained in:
jvanverth@google.com 2013-03-04 13:56:38 +00:00
Родитель bb963e2585
Коммит c490f801b0
27 изменённых файлов: 56 добавлений и 57 удалений

Просмотреть файл

@ -291,7 +291,7 @@ void SkFloat::UnitTest()
d.setAdd(c, b);
SkDebugf("SkFloat: %d + %d = %d\n", c.getInt(), b.getInt(), d.getInt());
SkRandom rand;
SkMWCRandom rand;
int i;
for (i = 0; i < 1000; i++)

Просмотреть файл

@ -19,7 +19,6 @@
#include "SkPath.h"
#include "SkPathEffect.h"
#include "SkPixelRef.h"
#include "SkRandom.h"
#include "SkRefCnt.h"
#include "SkRTConf.h"
#include "SkScalerContext.h"

Просмотреть файл

@ -1808,7 +1808,7 @@ SkScalar SkMatrix::getMaxStretch() const {
SkScalar largerRoot;
SkScalar bSqd = SkScalarMul(b,b);
// if upper left 2x2 is orthogonal save some math
if (bSqd <= SK_ScalarNearlyZero) {
if (bSqd <= SK_ScalarNearlyZero*SK_ScalarNearlyZero) {
largerRoot = SkMaxScalar(a, c);
} else {
SkScalar aminusc = a - c;

Просмотреть файл

@ -950,7 +950,7 @@ void GrRedBlackTree<T,C>::UnitTest() {
GrRedBlackTree<int> tree;
typedef GrRedBlackTree<int>::Iter iter;
SkRandom r;
SkMWCRandom r;
int count[100] = {0};
// add 10K ints

Просмотреть файл

@ -12,7 +12,6 @@
#include "SkMatrix.h"
class GrTexture;
class SkRandom;
/**
* This is a helper to implement a texture matrix in a GrGLEffect.

Просмотреть файл

@ -87,7 +87,7 @@ static void copyToMask(const SkRegion& rgn, SkMask* mask) {
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 @@ static SkIRect rand_rect(SkRandom& rand, int n) {
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 @@ static void setRgnToPath(SkRegion* rgn, const SkPath& path) {
// 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 @@ static void test_empty(skiatest::Reporter* reporter) {
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 rand_irect(SkIRect* r, int N, SkRandom& rand) {
}
static void test_irect(skiatest::Reporter* reporter) {
SkRandom rand;
SkMWCRandom rand;
for (int i = 0; i < 10000; i++) {
SkAAClip clip0, clip1;

Просмотреть файл

@ -10,7 +10,6 @@
#include "SkCanvas.h"
#include "SkMath.h"
#include "SkPaint.h"
#include "SkRandom.h"
///////////////////////////////////////////////////////////////////////////////

Просмотреть файл

@ -107,7 +107,7 @@ void TestClampRange(skiatest::Reporter* reporter) {
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++) {

Просмотреть файл

@ -820,7 +820,7 @@ static void test_reduced_clip_stack(skiatest::Reporter* reporter) {
add_oval,
};
SkRandom r;
SkMWCRandom r;
for (int i = 0; i < kNumTests; ++i) {
// Randomly generate a clip stack.
@ -864,7 +864,7 @@ static void test_reduced_clip_stack(skiatest::Reporter* reporter) {
ElementList reducedClips;
GrReducedClip::InitialState initial;
SkIRect tBounds;
SkIRect tBounds(inflatedIBounds);
SkIRect* tightBounds = r.nextBool() ? &tBounds : NULL;
GrReducedClip::ReduceClipStack(stack,
inflatedIBounds,

Просмотреть файл

@ -35,7 +35,7 @@ template <typename T> T* reincarnate(T* obj) {
#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();

Просмотреть файл

@ -146,7 +146,7 @@ static inline void test_premul(skiatest::Reporter* reporter) {
*/
/*
static void test_interp(skiatest::Reporter* reporter) {
SkRandom r;
SkMWCRandom r;
U8CPU a0 = 0;
U8CPU a255 = 255;
@ -163,7 +163,7 @@ static void test_interp(skiatest::Reporter* reporter) {
*/
static inline void test_fast_interp(skiatest::Reporter* reporter) {
SkRandom r;
SkMWCRandom r;
U8CPU a0 = 0;
U8CPU a255 = 255;

Просмотреть файл

@ -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_matrix(SkMatrix* mat, SkRandom& rand, unsigned mask) {
}
}
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 @@ static void test_treatAsSprite(skiatest::Reporter* reporter) {
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) {

Просмотреть файл

@ -47,7 +47,7 @@ public:
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 @@ private:
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 @@ static void test_memory_pool(skiatest::Reporter* reporter) {
// 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) {

Просмотреть файл

@ -35,7 +35,7 @@ static void test_center(skiatest::Reporter* reporter) {
gData[index].fRect.centerY() == gData[index].fCenter.y());
}
SkRandom rand;
SkMWCRandom rand;
for (int i = 0; i < 10000; ++i) {
SkIRect r;

Просмотреть файл

@ -124,7 +124,7 @@ static void TestTInternalLList(skiatest::Reporter* reporter) {
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) {

Просмотреть файл

@ -173,7 +173,7 @@ static void check_length(skiatest::Reporter* reporter,
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 test_int2float(skiatest::Reporter* reporter, int ival) {
}
static void unittest_fastfloat(skiatest::Reporter* reporter) {
SkRandom rand;
SkMWCRandom rand;
size_t i;
static const float gFloats[] = {
@ -368,7 +368,7 @@ static void test_copysign(skiatest::Reporter* reporter) {
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 test_copysign(skiatest::Reporter* reporter) {
static void TestMath(skiatest::Reporter* reporter) {
int i;
int32_t x;
SkRandom rand;
SkMWCRandom rand;
// these should assert
#if 0

Просмотреть файл

@ -168,7 +168,7 @@ static void test_matrix_max_stretch(skiatest::Reporter* reporter) {
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();

Просмотреть файл

@ -14,7 +14,7 @@ static const uint16_t gTest2[] = { 0, 0, 0, 1, 2, 3, 3, 3 };
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();

Просмотреть файл

@ -290,7 +290,7 @@ static void make_arb_round_rect(SkPath* path, const SkRect& r,
// 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 @@ static void test_arb_round_rect_is_convex(skiatest::Reporter* reporter) {
// 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 @@ DONE:
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 @@ static void test_raw_iter(skiatest::Reporter* reporter) {
}
// 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;

Просмотреть файл

@ -73,7 +73,7 @@ static SkPicture* record_bitmaps(const SkBitmap bm[], const SkPoint pos[],
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 @@ static void test_gatherpixelrefs(skiatest::Reporter* reporter) {
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 @@ static void test_serializing_empty_picture() {
}
#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 rand_op(SkCanvas* canvas, SkRandom& rand) {
}
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 @@ static void test_peephole() {
rand_op(canvas, rand);
}
picture.endRecording();
rand = rand2;
}
{

Просмотреть файл

@ -23,7 +23,7 @@ struct DataRect {
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 @@ static SkIRect random_rect(SkRandom& rand) {
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 @@ static bool verify_query(SkIRect query, DataRect rects[],
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 runQueries(skiatest::Reporter* reporter, SkRandom& rand, DataRect re
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);

Просмотреть файл

@ -98,7 +98,7 @@ enum {
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 @@ static SkIRect randRect(SkRandom& rand) {
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 intersects_proc(skiatest::Reporter* reporter,
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 test_proc(skiatest::Reporter* reporter,
}
}
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 @@ static void TestRegion(skiatest::Reporter* reporter) {
};
REPORTER_ASSERT(reporter, test_rects(rects, SK_ARRAY_COUNT(rects)));
SkRandom rand;
SkMWCRandom rand;
for (int i = 0; i < 1000; i++) {
SkRegion rgn0, rgn1;

Просмотреть файл

@ -75,7 +75,7 @@ static void TestSk64(skiatest::Reporter* reporter) {
// Now test add/sub
SkRandom rand;
SkMWCRandom rand;
int i;
for (i = 0; i < 1000; i++)

Просмотреть файл

@ -15,7 +15,7 @@ extern "C" {
}
}
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 @@ static void TestSort(skiatest::Reporter* reporter) {
/** 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));

Просмотреть файл

@ -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 random_fill(SkRandom& rand, void* buffer, size_t size) {
}
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 void TestRStream(skiatest::Reporter* reporter) {
static const char s[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
char copy[sizeof(s)];
SkRandom rand;
SkMWCRandom rand;
for (int i = 0; i < 65; i++) {
char* copyPtr = copy;

Просмотреть файл

@ -54,7 +54,7 @@ static void test_autounref(skiatest::Reporter* reporter) {
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();

Просмотреть файл

@ -134,7 +134,7 @@ static void testWritePad(skiatest::Reporter* reporter, SkWriter32* writer) {
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) {