static SkIRect random_rect(SkRandom& rand) { SkIRect rect = {0,0,0,0}; while (rect.isEmpty()) { rect.fLeft = rand.nextS() % MAX_SIZE; rect.fRight = rand.nextS() % MAX_SIZE; rect.fTop = rand.nextS() % MAX_SIZE; rect.fBottom = rand.nextS() % MAX_SIZE; rect.sort(); } return rect; }
static SkIRect rand_rect(SkRandom& rand, int n) { int x = rand.nextS() % n; int y = rand.nextS() % n; int w = rand.nextU() % n; int h = rand.nextU() % n; return SkIRect::MakeXYWH(x, y, w, h); }
void onOnceBeforeDraw() override { SkRandom rand; int steps = 20; SkScalar dist = SkIntToScalar(400); SkScalar x = SkIntToScalar(20); SkScalar y = SkIntToScalar(50); fPath.moveTo(x, y); for (int i = 0; i < steps; i++) { x += dist/steps; SkScalar tmpY = y + SkIntToScalar(rand.nextS() % 25); if (i == steps/2) { fPath.moveTo(x, tmpY); } else { fPath.lineTo(x, tmpY); } } { SkRect oval; oval.set(SkIntToScalar(20), SkIntToScalar(30), SkIntToScalar(100), SkIntToScalar(60)); oval.offset(x, 0); fPath.addRoundRect(oval, SkIntToScalar(8), SkIntToScalar(8)); } fClickPt.set(SkIntToScalar(200), SkIntToScalar(200)); this->setBGColor(0xFFDDDDDD); }
PathEffectView() { SkRandom rand; int steps = 20; SkScalar dist = SkIntToScalar(400); SkScalar x = SkIntToScalar(20); SkScalar y = SkIntToScalar(50); fPath.moveTo(x, y); for (int i = 0; i < steps; i++) { x += dist/steps; SkScalar tmpY = y + SkIntToScalar(rand.nextS() % 25); if (i == steps/2) { fPath.moveTo(x, tmpY); } else { fPath.lineTo(x, tmpY); } } { SkRect oval; oval.set(SkIntToScalar(20), SkIntToScalar(30), SkIntToScalar(100), SkIntToScalar(60)); oval.offset(x, 0); fPath.addRoundRect(oval, SkIntToScalar(8), SkIntToScalar(8)); } fClickPt.set(SkIntToScalar(200), SkIntToScalar(200)); }
static void test_search(skiatest::Reporter* reporter) { int i, array[kSEARCH_COUNT]; SkRandom rand; for (i = 0; i < kSEARCH_COUNT; i++) { array[i] = rand.nextS(); } SkTHeapSort<int>(array, kSEARCH_COUNT); // make sure we got sorted properly for (i = 1; i < kSEARCH_COUNT; i++) { REPORTER_ASSERT(reporter, array[i-1] <= array[i]); } // make sure we can find all of our values for (i = 0; i < kSEARCH_COUNT; i++) { int index = SkTSearch<int>(array, kSEARCH_COUNT, array[i], sizeof(int)); REPORTER_ASSERT(reporter, index == i); } // make sure that random values are either found, or the correct // insertion index is returned for (i = 0; i < 10000; i++) { int value = rand.nextS(); int index = SkTSearch<int>(array, kSEARCH_COUNT, value, sizeof(int)); if (index >= 0) { REPORTER_ASSERT(reporter, index < kSEARCH_COUNT && array[index] == value); } else { index = ~index; REPORTER_ASSERT(reporter, index <= kSEARCH_COUNT); if (index < kSEARCH_COUNT) { REPORTER_ASSERT(reporter, value < array[index]); if (index > 0) { REPORTER_ASSERT(reporter, value > array[index - 1]); } } else { // we should append the new value REPORTER_ASSERT(reporter, value > array[kSEARCH_COUNT - 1]); } } } }
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); } // 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); } }
void SkQSort_UnitTest() { #ifdef SK_SUPPORT_UNITTEST int array[100]; SkRandom rand; for (int i = 0; i < 1000; i++) { int j, count = rand.nextRangeU(1, SK_ARRAY_COUNT(array)); for (j = 0; j < count; j++) array[j] = rand.nextS() & 0xFF; SkQSort(array, count, sizeof(int), compare_int); for (j = 1; j < count; j++) SkASSERT(array[j-1] <= array[j]); } #endif }
static SkIRect next_irect(SkRandom& r) { return {r.nextS(), r.nextS(), r.nextS(), r.nextS()}; }
static void rand_array(SkRandom& rand, int array[], int n) { for (int j = 0; j < n; j++) { array[j] = rand.nextS() & 0xFF; } }
static void rand_proc(int array[N]) { SkRandom rand; for (int i = 0; i < N; ++i) { array[i] = rand.nextS(); } }
void SkGraphics::Init() { SkGlobals::Init(); #ifdef BUILD_EMBOSS_TABLE SkEmbossMask_BuildTable(); #endif #ifdef BUILD_RADIALGRADIENT_TABLE SkRadialGradient_BuildTable(); #endif #ifdef SK_DEBUGx int i; static const struct { const char* fTypeName; size_t fSizeOf; } gTypeSize[] = { typesizeline(char), typesizeline(short), typesizeline(int), typesizeline(long), typesizeline(size_t), typesizeline(void*), typesizeline(S8CPU), typesizeline(U8CPU), typesizeline(S16CPU), typesizeline(U16CPU), typesizeline(SkPoint), typesizeline(SkRect), typesizeline(SkMatrix), typesizeline(SkPath), typesizeline(SkGlyph), typesizeline(SkRefCnt), typesizeline(SkPaint), typesizeline(SkCanvas), typesizeline(SkBlitter), typesizeline(SkShader), typesizeline(SkXfermode), typesizeline(SkPathEffect) }; #ifdef SK_CPU_BENDIAN SkDebugf("SkGraphics: big-endian\n"); #else SkDebugf("SkGraphics: little-endian\n"); #endif { char test = 0xFF; int itest = test; // promote to int, see if it sign-extended if (itest < 0) SkDebugf("SkGraphics: char is signed\n"); else SkDebugf("SkGraphics: char is unsigned\n"); } for (i = 0; i < (int)SK_ARRAY_COUNT(gTypeSize); i++) { SkDebugf("SkGraphics: sizeof(%s) = %d\n", gTypeSize[i].fTypeName, gTypeSize[i].fSizeOf); } #endif if (false) // test asm fixmul { int j; SkMSec now = SkTime::GetMSecs(); for (j = 0; j < BIG_LOOP_COUNT; j++) { (void)SkFixedMul_portable(0x8000, 0x150000); } SkMSec now2 = SkTime::GetMSecs(); printf("-------- SkFixedMul_portable = %d\n", now2 - now); for (j = 0; j < BIG_LOOP_COUNT; j++) { (void)SkFixedMul(0x8000, 0x150000); } printf("-------- SkFixedMul = %d\n", SkTime::GetMSecs() - now2); SkRandom rand; for (j = 0; j < 10000; j++) { SkFixed a = rand.nextS() >> 8; SkFixed b = rand.nextS() >> 8; SkFixed c1 = SkFixedMul_portable(a, b); SkFixed c2 = SkFixedMul(a, b); if (SkAbs32(c1 - c2) > 1) printf("------ FixMul disagreement: (%x %x) slow=%x fast=%x\n", a, b, c1, c2); } }