本文整理汇总了C++中SkRandom类的典型用法代码示例。如果您正苦于以下问题:C++ SkRandom类的具体用法?C++ SkRandom怎么用?C++ SkRandom使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SkRandom类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: onDraw
virtual void onDraw(SkCanvas* canvas) {
SkPaint paint;
this->setupPaint(&paint);
paint.setAntiAlias(true);
SkRandom rand;
for (int i = 0; i < SkBENCHLOOP(3); i++) {
SkRect r = SkRect::MakeWH(rand.nextUScalar1() * 400,
rand.nextUScalar1() * 400);
r.offset(fRadius, fRadius);
if (fRadius > 0) {
SkMorphologyImageFilter* mf = NULL;
switch (fStyle) {
case kDilate_MT:
mf = new SkDilateImageFilter(SkScalarFloorToInt(fRadius),
SkScalarFloorToInt(fRadius));
break;
case kErode_MT:
mf = new SkErodeImageFilter(SkScalarFloorToInt(fRadius),
SkScalarFloorToInt(fRadius));
break;
}
paint.setImageFilter(mf)->unref();
}
canvas->drawOval(r, paint);
}
}
示例3: rand_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);
}
示例4: DEF_TEST
DEF_TEST(SkFloatToHalf_finite_ftz, r) {
#if 0
for (uint64_t bits = 0; bits <= 0xffffffff; bits++) {
#else
SkRandom rand;
for (int i = 0; i < 1000000; i++) {
uint32_t bits = rand.nextU();
#endif
float f;
memcpy(&f, &bits, 4);
uint16_t expected = SkFloatToHalf(f);
if (!is_finite(expected)) {
// _finite_ftz() only works for values that can be represented as a finite half float.
continue;
}
uint16_t alternate = expected;
if (is_denorm(expected)) {
// _finite_ftz() may flush denorms to zero, and happens to keep the sign bit.
alternate = signbit(f) ? 0x8000 : 0x0000;
}
uint16_t actual = SkFloatToHalf_finite_ftz(Sk4f{f})[0];
// _finite_ftz() may truncate instead of rounding, so it may be one too small.
REPORTER_ASSERT(r, actual == expected || actual == expected - 1 ||
actual == alternate || actual == alternate - 1);
}
}
示例5: ComputeChecksumBench
ComputeChecksumBench(void* param, ChecksumType type) : INHERITED(param), fType(type) {
SkRandom rand;
for (int i = 0; i < U32COUNT; ++i) {
fData[i] = rand.nextU();
}
fIsRendering = false;
}
示例6: stream_peek_test
// Asserts that asset == expected and is peekable.
static void stream_peek_test(skiatest::Reporter* rep,
SkStreamAsset* asset,
const SkData* expected) {
if (asset->getLength() != expected->size()) {
ERRORF(rep, "Unexpected length.");
return;
}
SkRandom rand;
uint8_t buffer[4096];
const uint8_t* expect = expected->bytes();
for (size_t i = 0; i < asset->getLength(); ++i) {
uint32_t maxSize =
SkToU32(SkTMin(sizeof(buffer), asset->getLength() - i));
size_t size = rand.nextRangeU(1, maxSize);
SkASSERT(size >= 1);
SkASSERT(size <= sizeof(buffer));
SkASSERT(size + i <= asset->getLength());
if (asset->peek(buffer, size) < size) {
ERRORF(rep, "Peek Failed!");
return;
}
if (0 != memcmp(buffer, &expect[i], size)) {
ERRORF(rep, "Peek returned wrong bytes!");
return;
}
uint8_t value;
REPORTER_ASSERT(rep, 1 == asset->read(&value, 1));
if (value != expect[i]) {
ERRORF(rep, "Read Failed!");
return;
}
}
}
示例7: onDraw
void onDraw(int loops, SkCanvas* canvas) override {
SkPaint paint;
this->setupPaint(&paint);
paint.setAntiAlias(true);
SkRandom rand;
for (int i = 0; i < loops; i++) {
SkRect r = SkRect::MakeWH(rand.nextUScalar1() * 400,
rand.nextUScalar1() * 400);
r.offset(fRadius, fRadius);
if (fRadius > 0) {
sk_sp<SkImageFilter> mf;
switch (fStyle) {
case kDilate_MT:
mf = SkDilateImageFilter::Make(SkScalarFloorToInt(fRadius),
SkScalarFloorToInt(fRadius),
nullptr);
break;
case kErode_MT:
mf = SkErodeImageFilter::Make(SkScalarFloorToInt(fRadius),
SkScalarFloorToInt(fRadius),
nullptr);
break;
}
paint.setImageFilter(std::move(mf));
}
canvas->drawOval(r, paint);
}
}
示例8: 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);
}
}
}
示例9: make_atlas
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();
}
示例10: test_peephole
static void test_peephole(skiatest::Reporter* reporter) {
SkRandom rand;
for (int j = 0; j < 100; j++) {
SkRandom rand2(rand.getSeed()); // remember the seed
SkPicture picture;
SkCanvas* canvas = picture.beginRecording(100, 100);
for (int i = 0; i < 1000; ++i) {
rand_op(canvas, rand);
}
picture.endRecording();
}
{
SkPicture picture;
SkCanvas* canvas = picture.beginRecording(100, 100);
SkRect rect = SkRect::MakeWH(50, 50);
for (int i = 0; i < 100; ++i) {
canvas->save();
}
while (canvas->getSaveCount() > 1) {
canvas->clipRect(rect);
canvas->restore();
}
picture.endRecording();
}
}
示例11: 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");
}
示例12: 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;
}
}
示例13: onDraw
void onDraw(const int loops, SkCanvas*) override {
SkRandom r;
enum {
kMaxObjects = 4 * (1 << 10),
};
A* objects[kMaxObjects];
// We delete if a random [-1, 1] fixed pt is < the thresh. Otherwise,
// we allocate. We start allocate-biased and ping-pong to delete-biased
SkFixed delThresh = -SK_FixedHalf;
const int kSwitchThreshPeriod = loops / (2 * kMaxObjects);
int s = 0;
int count = 0;
for (int i = 0; i < loops; i++, ++s) {
if (kSwitchThreshPeriod == s) {
delThresh = -delThresh;
s = 0;
}
SkFixed del = r.nextSFixed1();
if (count &&
(kMaxObjects == count || del < delThresh)) {
delete objects[count-1];
--count;
} else {
objects[count] = new A;
++count;
}
}
for (int i = 0; i < count; ++i) {
delete objects[i];
}
}
示例14: constFP
const GrFragmentProcessor* SkModeColorFilter::asFragmentProcessor(GrContext*) const {
if (SkXfermode::kDst_Mode == fMode) {
return nullptr;
}
SkAutoTUnref<const GrFragmentProcessor> constFP(
GrConstColorProcessor::Create(SkColorToPremulGrColor(fColor),
GrConstColorProcessor::kIgnore_InputMode));
const GrFragmentProcessor* fp =
GrXfermodeFragmentProcessor::CreateFromSrcProcessor(constFP, fMode);
if (!fp) {
return nullptr;
}
#ifdef SK_DEBUG
// With a solid color input this should always be able to compute the blended color
// (at least for coeff modes)
if (fMode <= SkXfermode::kLastCoeffMode) {
static SkRandom gRand;
GrInvariantOutput io(GrPremulColor(gRand.nextU()), kRGBA_GrColorComponentFlags,
false);
fp->computeInvariantOutput(&io);
SkASSERT(io.validFlags() == kRGBA_GrColorComponentFlags);
}
#endif
return fp;
}
示例15: onDraw
void onDraw(SkCanvas* canvas) override {
SkPath path;
SkRandom rand;
int scale = 300;
for (int i = 0; i < 4; ++i) {
// get the random values deterministically
SkScalar randoms[12];
for (int index = 0; index < (int) SK_ARRAY_COUNT(randoms); ++index) {
randoms[index] = rand.nextUScalar1();
}
path.lineTo(randoms[0] * scale, randoms[1] * scale);
path.quadTo(randoms[2] * scale, randoms[3] * scale,
randoms[4] * scale, randoms[5] * scale);
path.cubicTo(randoms[6] * scale, randoms[7] * scale,
randoms[8] * scale, randoms[9] * scale,
randoms[10] * scale, randoms[11] * scale);
}
path.setFillType(SkPath::kEvenOdd_FillType);
path.offset(SkIntToScalar(20), SkIntToScalar(20));
test_hittest(canvas, path);
canvas->translate(SkIntToScalar(scale), 0);
path.setFillType(SkPath::kWinding_FillType);
test_hittest(canvas, path);
}