本文整理汇总了C++中SkRandom::nextBool方法的典型用法代码示例。如果您正苦于以下问题:C++ SkRandom::nextBool方法的具体用法?C++ SkRandom::nextBool怎么用?C++ SkRandom::nextBool使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkRandom
的用法示例。
在下文中一共展示了SkRandom::nextBool方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testTightBoundsLines
static void testTightBoundsLines(PathOpsThreadState* data) {
SkRandom ran;
for (int index = 0; index < 1000; ++index) {
SkPath path;
int contourCount = ran.nextRangeU(1, 10);
for (int cIndex = 0; cIndex < contourCount; ++cIndex) {
int lineCount = ran.nextRangeU(1, 10);
path.moveTo(ran.nextRangeF(-1000, 1000), ran.nextRangeF(-1000, 1000));
for (int lIndex = 0; lIndex < lineCount; ++lIndex) {
path.lineTo(ran.nextRangeF(-1000, 1000), ran.nextRangeF(-1000, 1000));
}
if (ran.nextBool()) {
path.close();
}
}
SkRect classicBounds = path.getBounds();
SkRect tightBounds;
REPORTER_ASSERT(data->fReporter, TightBounds(path, &tightBounds));
REPORTER_ASSERT(data->fReporter, classicBounds == tightBounds);
}
}
示例2: TestTLList
//.........这里部分代码省略.........
case 0:
list1.addToHead(ListElement(id));
break;
case 1:
list1.addToTail(ListElement(id));
break;
case 2: // fallthru to share code that picks random element.
case 3: {
int n = random.nextULessThan(list1.count());
Iter iter = list1.headIter();
// remember the elements before/after the insertion point.
while (n--) {
iter.next();
}
Iter prev(iter);
Iter next(iter);
next.next();
prev.prev();
SkASSERT(NULL != iter.get());
// insert either before or after the iterator, then check that the
// surrounding sequence is correct.
if (2 == insertionMethod) {
SkNEW_INSERT_IN_LLIST_BEFORE(&list1, iter, ListElement, (id));
Iter newItem(iter);
newItem.prev();
REPORTER_ASSERT(reporter, newItem.get()->fID == id);
if (NULL != next.get()) {
REPORTER_ASSERT(reporter, next.prev()->fID == iter.get()->fID);
}
if (NULL != prev.get()) {
REPORTER_ASSERT(reporter, prev.next()->fID == id);
}
} else {
SkNEW_INSERT_IN_LLIST_AFTER(&list1, iter, ListElement, (id));
Iter newItem(iter);
newItem.next();
REPORTER_ASSERT(reporter, newItem.get()->fID == id);
if (NULL != next.get()) {
REPORTER_ASSERT(reporter, next.prev()->fID == id);
}
if (NULL != prev.get()) {
REPORTER_ASSERT(reporter, prev.next()->fID == iter.get()->fID);
}
}
}
}
++count;
} else {
// walk to a random place either forward or backwards and remove.
int n = random.nextULessThan(list1.count());
Iter::IterStart start;
ListElement* (Iter::*incrFunc)();
if (random.nextBool()) {
start = Iter::kHead_IterStart;
incrFunc = &Iter::next;
} else {
start = Iter::kTail_IterStart;
incrFunc = &Iter::prev;
}
// find the element
Iter iter(list1, start);
while (n--) {
REPORTER_ASSERT(reporter, NULL != iter.get());
(iter.*incrFunc)();
}
REPORTER_ASSERT(reporter, NULL != iter.get());
// remember the prev and next elements from the element to be removed
Iter prev = iter;
Iter next = iter;
prev.prev();
next.next();
list1.remove(iter.get());
// make sure the remembered next/prev iters still work
Iter pn = prev; pn.next();
Iter np = next; np.prev();
// pn should match next unless the target node was the head, in which case prev
// walked off the list.
REPORTER_ASSERT(reporter, pn.get() == next.get() || NULL == prev.get());
// Similarly, np should match prev unless next originally walked off the tail.
REPORTER_ASSERT(reporter, np.get() == prev.get() || NULL == next.get());
--count;
}
REPORTER_ASSERT(reporter, count == list1.count());
#if SK_ENABLE_INST_COUNT
SkASSERT(count == ListElement::InstanceCount());
#endif
}
list1.reset();
#if SK_ENABLE_INST_COUNT
SkASSERT(0 == ListElement::InstanceCount());
#endif
}
}
示例3: programUnitTest
bool GrGpuGL::programUnitTest(int maxStages) {
GrTextureDesc dummyDesc;
dummyDesc.fFlags = kRenderTarget_GrTextureFlagBit;
dummyDesc.fConfig = kSkia8888_GrPixelConfig;
dummyDesc.fWidth = 34;
dummyDesc.fHeight = 18;
SkAutoTUnref<GrTexture> dummyTexture1(this->createTexture(dummyDesc, NULL, 0));
dummyDesc.fFlags = kNone_GrTextureFlags;
dummyDesc.fConfig = kAlpha_8_GrPixelConfig;
dummyDesc.fWidth = 16;
dummyDesc.fHeight = 22;
SkAutoTUnref<GrTexture> dummyTexture2(this->createTexture(dummyDesc, NULL, 0));
if (!dummyTexture1 || ! dummyTexture2) {
return false;
}
static const int NUM_TESTS = 512;
SkRandom random;
for (int t = 0; t < NUM_TESTS; ++t) {
#if 0
GrPrintf("\nTest Program %d\n-------------\n", t);
static const int stop = -1;
if (t == stop) {
int breakpointhere = 9;
}
#endif
GrGLProgramDesc pdesc;
int currAttribIndex = 1; // we need to always leave room for position
int currTextureCoordSet = 0;
GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()};
int numStages = random.nextULessThan(maxStages + 1);
int numColorStages = random.nextULessThan(numStages + 1);
int numCoverageStages = numStages - numColorStages;
SkAutoSTMalloc<8, const GrFragmentStage*> stages(numStages);
bool usePathRendering = this->glCaps().pathRenderingSupport() && random.nextBool();
GrGpu::DrawType drawType = usePathRendering ? GrGpu::kDrawPath_DrawType :
GrGpu::kDrawPoints_DrawType;
SkAutoTDelete<GrGeometryStage> geometryProcessor;
bool hasGeometryProcessor = usePathRendering ? false : random.nextBool();
if (hasGeometryProcessor) {
while (true) {
SkAutoTUnref<const GrGeometryProcessor> effect(
GrProcessorTestFactory<GrGeometryProcessor>::CreateStage(&random, this->getContext(), *this->caps(),
dummyTextures));
SkASSERT(effect);
// Only geometryProcessor can use vertex shader
GrGeometryStage* stage = SkNEW_ARGS(GrGeometryStage, (effect.get()));
geometryProcessor.reset(stage);
// we have to set dummy vertex attribs
const GrGeometryProcessor::VertexAttribArray& v = effect->getVertexAttribs();
int numVertexAttribs = v.count();
SkASSERT(GrGeometryProcessor::kMaxVertexAttribs == 2 &&
GrGeometryProcessor::kMaxVertexAttribs >= numVertexAttribs);
size_t runningStride = GrVertexAttribTypeSize(genericVertexAttribs[0].fType);
for (int i = 0; i < numVertexAttribs; i++) {
genericVertexAttribs[i + 1].fOffset = runningStride;
genericVertexAttribs[i + 1].fType =
convert_sltype_to_attribtype(v[i].getType());
runningStride += GrVertexAttribTypeSize(genericVertexAttribs[i + 1].fType);
}
// update the vertex attributes with the ds
GrDrawState* ds = this->drawState();
ds->setVertexAttribs<genericVertexAttribs>(numVertexAttribs + 1, runningStride);
currAttribIndex = numVertexAttribs + 1;
break;
}
}
for (int s = 0; s < numStages;) {
SkAutoTUnref<const GrFragmentProcessor> effect(
GrProcessorTestFactory<GrFragmentProcessor>::CreateStage(
&random,
this->getContext(),
*this->caps(),
dummyTextures));
SkASSERT(effect);
// If adding this effect would exceed the max texture coord set count then generate a
// new random effect.
if (usePathRendering && this->glPathRendering()->texturingMode() ==
GrGLPathRendering::FixedFunction_TexturingMode) {;
int numTransforms = effect->numTransforms();
if (currTextureCoordSet + numTransforms > this->glCaps().maxFixedFunctionTextureCoords()) {
continue;
}
currTextureCoordSet += numTransforms;
}
//.........这里部分代码省略.........
示例4: programUnitTest
bool GrGpuGL::programUnitTest(int maxStages) {
GrTextureDesc dummyDesc;
dummyDesc.fFlags = kRenderTarget_GrTextureFlagBit;
dummyDesc.fConfig = kSkia8888_GrPixelConfig;
dummyDesc.fWidth = 34;
dummyDesc.fHeight = 18;
SkAutoTUnref<GrTexture> dummyTexture1(this->createTexture(dummyDesc, NULL, 0));
dummyDesc.fFlags = kNone_GrTextureFlags;
dummyDesc.fConfig = kAlpha_8_GrPixelConfig;
dummyDesc.fWidth = 16;
dummyDesc.fHeight = 22;
SkAutoTUnref<GrTexture> dummyTexture2(this->createTexture(dummyDesc, NULL, 0));
static const int NUM_TESTS = 512;
SkRandom random;
for (int t = 0; t < NUM_TESTS; ++t) {
#if 0
GrPrintf("\nTest Program %d\n-------------\n", t);
static const int stop = -1;
if (t == stop) {
int breakpointhere = 9;
}
#endif
GrGLProgramDesc pdesc;
int currAttribIndex = 1; // we need to always leave room for position
int currTextureCoordSet = 0;
int attribIndices[2] = { 0, 0 };
GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()};
int numStages = random.nextULessThan(maxStages + 1);
int numColorStages = random.nextULessThan(numStages + 1);
int numCoverageStages = numStages - numColorStages;
SkAutoSTMalloc<8, const GrEffectStage*> stages(numStages);
bool useFixedFunctionTexturing = this->shouldUseFixedFunctionTexturing();
for (int s = 0; s < numStages;) {
SkAutoTUnref<const GrEffectRef> effect(GrEffectTestFactory::CreateStage(
&random,
this->getContext(),
*this->caps(),
dummyTextures));
SkASSERT(effect);
int numAttribs = (*effect)->numVertexAttribs();
// If adding this effect would exceed the max attrib count then generate a
// new random effect.
if (currAttribIndex + numAttribs > GrDrawState::kMaxVertexAttribCnt) {
continue;
}
// If adding this effect would exceed the max texture coord set count then generate a
// new random effect.
if (useFixedFunctionTexturing && !(*effect)->hasVertexCode()) {
int numTransforms = (*effect)->numTransforms();
if (currTextureCoordSet + numTransforms > this->glCaps().maxFixedFunctionTextureCoords()) {
continue;
}
currTextureCoordSet += numTransforms;
}
useFixedFunctionTexturing = useFixedFunctionTexturing && !(*effect)->hasVertexCode();
for (int i = 0; i < numAttribs; ++i) {
attribIndices[i] = currAttribIndex++;
}
GrEffectStage* stage = SkNEW_ARGS(GrEffectStage,
(effect.get(), attribIndices[0], attribIndices[1]));
stages[s] = stage;
++s;
}
const GrTexture* dstTexture = random.nextBool() ? dummyTextures[0] : dummyTextures[1];
pdesc.setRandom(&random,
this,
dummyTextures[0]->asRenderTarget(),
dstTexture,
stages.get(),
numColorStages,
numCoverageStages,
currAttribIndex);
SkAutoTUnref<GrGLProgram> program(GrGLProgram::Create(this,
pdesc,
stages,
stages + numColorStages));
for (int s = 0; s < numStages; ++s) {
SkDELETE(stages[s]);
}
if (NULL == program.get()) {
return false;
}
}
return true;
//.........这里部分代码省略.........
示例5: testTightBoundsQuads
static void testTightBoundsQuads(PathOpsThreadState* data) {
SkRandom ran;
const int bitWidth = 32;
const int bitHeight = 32;
const float pathMin = 1;
const float pathMax = (float) (bitHeight - 2);
SkBitmap& bits = *data->fBitmap;
if (bits.width() == 0) {
bits.allocN32Pixels(bitWidth, bitHeight);
}
SkCanvas canvas(bits);
SkPaint paint;
for (int index = 0; index < 100; ++index) {
SkPath path;
int contourCount = ran.nextRangeU(1, 10);
for (int cIndex = 0; cIndex < contourCount; ++cIndex) {
int lineCount = ran.nextRangeU(1, 10);
path.moveTo(ran.nextRangeF(1, pathMax), ran.nextRangeF(pathMin, pathMax));
for (int lIndex = 0; lIndex < lineCount; ++lIndex) {
if (ran.nextBool()) {
path.lineTo(ran.nextRangeF(pathMin, pathMax), ran.nextRangeF(pathMin, pathMax));
} else {
path.quadTo(ran.nextRangeF(pathMin, pathMax), ran.nextRangeF(pathMin, pathMax),
ran.nextRangeF(pathMin, pathMax), ran.nextRangeF(pathMin, pathMax));
}
}
if (ran.nextBool()) {
path.close();
}
}
SkRect classicBounds = path.getBounds();
SkRect tightBounds;
REPORTER_ASSERT(data->fReporter, TightBounds(path, &tightBounds));
REPORTER_ASSERT(data->fReporter, classicBounds.contains(tightBounds));
canvas.drawColor(SK_ColorWHITE);
canvas.drawPath(path, paint);
SkIRect bitsWritten = {31, 31, 0, 0};
for (int y = 0; y < bitHeight; ++y) {
uint32_t* addr1 = data->fBitmap->getAddr32(0, y);
bool lineWritten = false;
for (int x = 0; x < bitWidth; ++x) {
if (addr1[x] == (uint32_t) -1) {
continue;
}
lineWritten = true;
bitsWritten.fLeft = SkTMin(bitsWritten.fLeft, x);
bitsWritten.fRight = SkTMax(bitsWritten.fRight, x);
}
if (!lineWritten) {
continue;
}
bitsWritten.fTop = SkTMin(bitsWritten.fTop, y);
bitsWritten.fBottom = SkTMax(bitsWritten.fBottom, y);
}
if (!bitsWritten.isEmpty()) {
SkIRect tightOut;
tightBounds.roundOut(&tightOut);
REPORTER_ASSERT(data->fReporter, tightOut.contains(bitsWritten));
}
}
}