本文整理汇总了C++中SkRandom::nextU方法的典型用法代码示例。如果您正苦于以下问题:C++ SkRandom::nextU方法的具体用法?C++ SkRandom::nextU怎么用?C++ SkRandom::nextU使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkRandom
的用法示例。
在下文中一共展示了SkRandom::nextU方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: randrect
SkIRect randrect(SkRandom& rand) {
int x = rand.nextU() % W;
int y = rand.nextU() % H;
int w = rand.nextU() % W;
int h = rand.nextU() % H;
return SkIRect::MakeXYWH(x, y, w >> 1, h >> 1);
}
示例2: test_buffer
static void test_buffer(skiatest::Reporter* reporter) {
SkRandom rand;
SkAutoMalloc am(MAX_SIZE * 2);
char* storage = (char*)am.get();
char* storage2 = storage + MAX_SIZE;
random_fill(rand, storage, MAX_SIZE);
for (int sizeTimes = 0; sizeTimes < 100; sizeTimes++) {
int size = rand.nextU() % MAX_SIZE;
if (size == 0) {
size = MAX_SIZE;
}
for (int times = 0; times < 100; times++) {
int bufferSize = 1 + (rand.nextU() & 0xFFFF);
SkMemoryStream mstream(storage, size);
SkBufferStream bstream(&mstream, bufferSize);
int bytesRead = 0;
while (bytesRead < size) {
int s = 17 + (rand.nextU() & 0xFFFF);
int ss = bstream.read(storage2, s);
REPORTER_ASSERT(reporter, ss > 0 && ss <= s);
REPORTER_ASSERT(reporter, bytesRead + ss <= size);
REPORTER_ASSERT(reporter,
memcmp(storage + bytesRead, storage2, ss) == 0);
bytesRead += ss;
}
REPORTER_ASSERT(reporter, bytesRead == size);
}
}
}
示例3: rand_irect
static void rand_irect(SkIRect* r, int N, SkRandom& rand) {
r->setXYWH(0, 0, rand.nextU() % N, rand.nextU() % N);
int dx = rand.nextU() % (2*N);
int dy = rand.nextU() % (2*N);
// use int dx,dy to make the subtract be signed
r->offset(N - dx, N - dy);
}
示例4: ASSERT
DEF_TEST(Checksum, r) {
// Algorithms to test. They're currently all uint32_t(const uint32_t*, size_t).
typedef uint32_t(*algorithmProc)(const uint32_t*, size_t);
const algorithmProc kAlgorithms[] = { &SkChecksum::Compute, &murmur_noseed };
// Put 128 random bytes into two identical buffers. Any multiple of 4 will do.
const size_t kBytes = SkAlign4(128);
SkRandom rand;
uint32_t data[kBytes/4], tweaked[kBytes/4];
for (size_t i = 0; i < SK_ARRAY_COUNT(tweaked); ++i) {
data[i] = tweaked[i] = rand.nextU();
}
// Test each algorithm.
for (size_t i = 0; i < SK_ARRAY_COUNT(kAlgorithms); ++i) {
const algorithmProc algorithm = kAlgorithms[i];
// Hash of nullptr is always 0.
ASSERT(algorithm(nullptr, 0) == 0);
const uint32_t hash = algorithm(data, kBytes);
// Should be deterministic.
ASSERT(hash == algorithm(data, kBytes));
// Changing any single element should change the hash.
for (size_t j = 0; j < SK_ARRAY_COUNT(tweaked); ++j) {
const uint32_t saved = tweaked[j];
tweaked[j] = rand.nextU();
const uint32_t tweakedHash = algorithm(tweaked, kBytes);
ASSERT(tweakedHash != hash);
ASSERT(tweakedHash == algorithm(tweaked, kBytes));
tweaked[j] = saved;
}
}
}
示例5: show_stroke
static void show_stroke(SkCanvas* canvas, bool doAA, SkScalar strokeWidth, int n) {
SkRandom rand;
SkPaint paint;
paint.setAntiAlias(doAA);
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(strokeWidth);
for (int i = 0; i < n; ++i) {
SkRect r;
SkPath p;
r.setXYWH(rand.nextSScalar1() * W, rand.nextSScalar1() * H,
rand.nextUScalar1() * W, rand.nextUScalar1() * H);
paint.setColor(rand.nextU());
canvas->drawRect(r, paint);
r.setXYWH(rand.nextSScalar1() * W, rand.nextSScalar1() * H,
rand.nextUScalar1() * W, rand.nextUScalar1() * H);
paint.setColor(rand.nextU());
p.addOval(r);
canvas->drawPath(p, paint);
const SkScalar minx = -SkIntToScalar(W)/4;
const SkScalar maxx = 5*SkIntToScalar(W)/4;
const SkScalar miny = -SkIntToScalar(H)/4;
const SkScalar maxy = 5*SkIntToScalar(H)/4;
paint.setColor(rand.nextU());
canvas->drawLine(randRange(rand, minx, maxx), randRange(rand, miny, maxy),
randRange(rand, minx, maxx), randRange(rand, miny, maxy),
paint);
}
}
示例6: memcmp
DEF_TEST(Paint_cmap, reporter) {
// need to implement charsToGlyphs on other backends (e.g. linux, win)
// before we can run this tests everywhere
return;
static const int NGLYPHS = 64;
SkUnichar src[NGLYPHS];
SkUnichar dst[NGLYPHS]; // used for utf8, utf16, utf32 storage
static const struct {
size_t (*fSeedTextProc)(const SkUnichar[], void* dst, int count);
SkPaint::TextEncoding fEncoding;
} gRec[] = {
{ uni_to_utf8, SkPaint::kUTF8_TextEncoding },
{ uni_to_utf16, SkPaint::kUTF16_TextEncoding },
{ uni_to_utf32, SkPaint::kUTF32_TextEncoding },
};
SkRandom rand;
SkPaint paint;
paint.setTypeface(SkTypeface::RefDefault())->unref();
SkTypeface* face = paint.getTypeface();
for (int i = 0; i < 1000; ++i) {
// generate some random text
for (int j = 0; j < NGLYPHS; ++j) {
src[j] = ' ' + j;
}
// inject some random chars, to sometimes abort early
src[rand.nextU() & 63] = rand.nextU() & 0xFFF;
for (size_t k = 0; k < SK_ARRAY_COUNT(gRec); ++k) {
paint.setTextEncoding(gRec[k].fEncoding);
size_t len = gRec[k].fSeedTextProc(src, dst, NGLYPHS);
uint16_t glyphs0[NGLYPHS], glyphs1[NGLYPHS];
bool contains = paint.containsText(dst, len);
int nglyphs = paint.textToGlyphs(dst, len, glyphs0);
int first = face->charsToGlyphs(dst, paint2encoding(paint), glyphs1, NGLYPHS);
int index = find_first_zero(glyphs1, NGLYPHS);
REPORTER_ASSERT(reporter, NGLYPHS == nglyphs);
REPORTER_ASSERT(reporter, index == first);
REPORTER_ASSERT(reporter, 0 == memcmp(glyphs0, glyphs1, NGLYPHS * sizeof(uint16_t)));
if (contains) {
REPORTER_ASSERT(reporter, NGLYPHS == first);
} else {
REPORTER_ASSERT(reporter, NGLYPHS > first);
}
}
}
}
示例7: memcmp
static void test_pack8(skiatest::Reporter* reporter) {
static const struct {
const uint8_t* fSrc;
int fCount;
} gTests[] = {
{ gTest80, SK_ARRAY_COUNT(gTest80) },
{ gTest81, SK_ARRAY_COUNT(gTest81) },
{ gTest82, SK_ARRAY_COUNT(gTest82) },
{ gTest83, SK_ARRAY_COUNT(gTest83) },
{ gTest84, SK_ARRAY_COUNT(gTest84) }
};
for (size_t i = 4; i < SK_ARRAY_COUNT(gTests); i++) {
uint8_t dst[100];
size_t maxSize = SkPackBits::ComputeMaxSize8(gTests[i].fCount);
size_t dstSize = SkPackBits::Pack8(gTests[i].fSrc,
gTests[i].fCount, dst);
REPORTER_ASSERT(reporter, dstSize <= maxSize);
uint8_t src[100];
int srcCount = SkPackBits::Unpack8(dst, dstSize, src);
bool match = gTests[i].fCount == srcCount &&
memcmp(gTests[i].fSrc, src,
gTests[i].fCount * sizeof(uint8_t)) == 0;
REPORTER_ASSERT(reporter, match);
}
for (size_t size = 1; size <= 512; size += 1) {
for (int n = 100; n; n--) {
uint8_t src[600], src2[600];
uint8_t dst[600];
rand_fill(src, size);
size_t dstSize = SkPackBits::Pack8(src, size, dst);
size_t maxSize = SkPackBits::ComputeMaxSize8(size);
REPORTER_ASSERT(reporter, maxSize >= dstSize);
size_t srcCount = SkPackBits::Unpack8(dst, dstSize, src2);
REPORTER_ASSERT(reporter, size == srcCount);
bool match = memcmp(src, src2, size * sizeof(uint8_t)) == 0;
REPORTER_ASSERT(reporter, match);
for (int j = 0; j < 100; j++) {
size_t skip = gRand.nextU() % size;
size_t write = gRand.nextU() % size;
if (skip + write > size) {
write = size - skip;
}
SkPackBits::Unpack8(src, skip, write, dst);
bool match = memcmp(src, src2 + skip, write) == 0;
REPORTER_ASSERT(reporter, match);
}
}
}
}
示例8: onDraw
void onDraw(SkCanvas* canvas) override {
// Draw a giant AA circle as the background.
SkISize size = this->getISize();
SkScalar giantRadius = SkTMin(SkIntToScalar(size.fWidth),
SkIntToScalar(size.fHeight)) / 2.f;
SkPoint giantCenter = SkPoint::Make(SkIntToScalar(size.fWidth/2),
SkIntToScalar(size.fHeight/2));
SkPaint giantPaint;
giantPaint.setAntiAlias(true);
giantPaint.setColor(0x80808080);
canvas->drawCircle(giantCenter.fX, giantCenter.fY, giantRadius, giantPaint);
SkRandom rand;
canvas->translate(20 * SK_Scalar1, 20 * SK_Scalar1);
int i;
for (i = 0; i < fPaints.count(); ++i) {
canvas->save();
// position the path, and make it at off-integer coords.
canvas->translate(SK_Scalar1 * 200 * (i % 5) + SK_Scalar1 / 4,
SK_Scalar1 * 200 * (i / 5) + 3 * SK_Scalar1 / 4);
SkColor color = rand.nextU();
color |= 0xff000000;
fPaints[i].setColor(color);
canvas->drawCircle(SkIntToScalar(40), SkIntToScalar(40),
SkIntToScalar(20),
fPaints[i]);
canvas->restore();
}
for (int j = 0; j < fMatrices.count(); ++j, ++i) {
canvas->save();
canvas->translate(SK_Scalar1 * 200 * (i % 5) + SK_Scalar1 / 4,
SK_Scalar1 * 200 * (i / 5) + 3 * SK_Scalar1 / 4);
canvas->concat(fMatrices[j]);
SkPaint paint;
paint.setAntiAlias(true);
SkColor color = rand.nextU();
color |= 0xff000000;
paint.setColor(color);
canvas->drawCircle(SkIntToScalar(40), SkIntToScalar(40),
SkIntToScalar(20),
paint);
canvas->restore();
}
}
示例9: onDraw
void onDraw(const int loops, SkCanvas* canvas) override {
const char* text = "Hamburgefons";
size_t len = strlen(text);
SkISize size = canvas->getDeviceSize();
SkRandom random;
for (int i = 0; i < loops; ++i) {
SkPaint paint;
paint.setXfermode(fXfermode.get());
paint.setColor(random.nextU());
if (fAA) {
// Draw text to exercise AA code paths.
paint.setAntiAlias(true);
paint.setTextSize(random.nextRangeScalar(12, 96));
SkScalar x = random.nextRangeScalar(0, (SkScalar)size.fWidth),
y = random.nextRangeScalar(0, (SkScalar)size.fHeight);
for (int j = 0; j < 1000; ++j) {
canvas->drawText(text, len, x, y, paint);
}
} else {
// Draw rects to exercise non-AA code paths.
SkScalar w = random.nextRangeScalar(50, 100);
SkScalar h = random.nextRangeScalar(50, 100);
SkRect rect = SkRect::MakeXYWH(
random.nextUScalar1() * (size.fWidth - w),
random.nextUScalar1() * (size.fHeight - h),
w,
h
);
for (int j = 0; j < 1000; ++j) {
canvas->drawRect(rect, paint);
}
}
}
}
示例10: surface
static sk_sp<SkImage> make_atlas(int atlasSize, int cellSize) {
SkImageInfo info = SkImageInfo::MakeN32Premul(atlasSize, atlasSize);
auto surface(SkSurface::MakeRaster(info));
SkCanvas* canvas = surface->getCanvas();
SkPaint paint;
SkRandom rand;
const SkScalar half = cellSize * SK_ScalarHalf;
const char* s = "[email protected]#$%^&*=+<>?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
SkFont font(nullptr, 28);
int i = 0;
for (int y = 0; y < atlasSize; y += cellSize) {
for (int x = 0; x < atlasSize; x += cellSize) {
paint.setColor(rand.nextU());
paint.setAlpha(0xFF);
int index = i % strlen(s);
SkTextUtils::Draw(canvas, &s[index], 1, SkTextEncoding::kUTF8,
x + half, y + half + half/2, font, paint,
SkTextUtils::kCenter_Align);
i += 1;
}
}
return surface->makeImageSnapshot();
}
示例11: random_fill
static void random_fill(SkRandom& rand, void* buffer, size_t size) {
char* p = (char*)buffer;
char* stop = p + size;
while (p < stop) {
*p++ = (char)(rand.nextU() >> 8);
}
}
示例12: VertBench
VertBench() {
const SkScalar dx = SkIntToScalar(W) / COL;
const SkScalar dy = SkIntToScalar(H) / COL;
SkPoint* pts = fPts;
uint16_t* idx = fIdx;
SkScalar yy = 0;
for (int y = 0; y <= ROW; y++) {
SkScalar xx = 0;
for (int x = 0; x <= COL; ++x) {
pts->set(xx, yy);
pts += 1;
xx += dx;
if (x < COL && y < ROW) {
load_2_tris(idx, x, y, COL + 1);
for (int i = 0; i < 6; i++) {
SkASSERT(idx[i] < PTS);
}
idx += 6;
}
}
yy += dy;
}
SkASSERT(PTS == pts - fPts);
SkASSERT(IDX == idx - fIdx);
SkRandom rand;
for (int i = 0; i < PTS; ++i) {
fColors[i] = rand.nextU() | (0xFF << 24);
}
fName.set("verts");
}
示例13: call_draw
static void call_draw(SkCanvas* canvas)
{
SkPaint paint;
uint16_t text[32];
SkRandom rand;
paint.setAntiAlias(true);
paint.setTextEncoding(SkPaint::kUTF16_TextEncoding);
for (int j = 0; j < SK_ARRAY_COUNT(text); j++)
text[j] = (uint16_t)((rand.nextU() & 0xFF) + 32);
SkScalar x = SkIntToScalar(10);
SkScalar y = SkIntToScalar(20);
canvas->drawColor(SK_ColorWHITE);
for (int i = 9; i < 36; i++)
{
SkPaint::FontMetrics m;
paint.setTextSize(SkIntToScalar(i));
paint.getFontMetrics(&m);
canvas->drawText(text, sizeof(text), x, y, paint);
y += m.fDescent - m.fAscent;
}
}
示例14: HTDrawable
HTDrawable(SkRandom& rand) {
fR = SkRect::MakeXYWH(rand.nextRangeF(0, 640), rand.nextRangeF(0, 480),
rand.nextRangeF(20, 200), rand.nextRangeF(20, 200));
fColor = rand_opaque_color(rand.nextU());
fInterp = nullptr;
fTime = 0;
}
示例15: aur
DEF_TEST(ColorFilter, reporter) {
SkRandom rand;
for (int mode = 0; mode <= SkXfermode::kLastMode; mode++) {
SkColor color = rand.nextU();
// ensure we always get a filter, by avoiding the possibility of a
// special case that would return NULL (if color's alpha is 0 or 0xFF)
color = SkColorSetA(color, 0x7F);
SkColorFilter* cf = SkColorFilter::CreateModeFilter(color,
(SkXfermode::Mode)mode);
// allow for no filter if we're in Dst mode (its a no op)
if (SkXfermode::kDst_Mode == mode && NULL == cf) {
continue;
}
SkAutoUnref aur(cf);
REPORTER_ASSERT(reporter, cf);
SkColor c = ~color;
SkXfermode::Mode m = ILLEGAL_MODE;
SkColor expectedColor = color;
SkXfermode::Mode expectedMode = (SkXfermode::Mode)mode;
// SkDebugf("--- mc [%d %x] ", mode, color);
REPORTER_ASSERT(reporter, cf->asColorMode(&c, &m));
// handle special-case folding by the factory
if (SkXfermode::kClear_Mode == mode) {
if (c != expectedColor) {
expectedColor = 0;
}
if (m != expectedMode) {
expectedMode = SkXfermode::kSrc_Mode;
}
}
// SkDebugf("--- got [%d %x] expected [%d %x]\n", m, c, expectedMode, expectedColor);
REPORTER_ASSERT(reporter, c == expectedColor);
REPORTER_ASSERT(reporter, m == expectedMode);
{
SkColorFilter* cf2 = reincarnate_colorfilter(cf);
SkAutoUnref aur2(cf2);
REPORTER_ASSERT(reporter, cf2);
SkColor c2 = ~color;
SkXfermode::Mode m2 = ILLEGAL_MODE;
REPORTER_ASSERT(reporter, cf2->asColorMode(&c2, &m2));
REPORTER_ASSERT(reporter, c2 == expectedColor);
REPORTER_ASSERT(reporter, m2 == expectedMode);
}
}
test_composecolorfilter_limit(reporter);
}