本文整理汇总了C++中GrPipelineBuilder::setClip方法的典型用法代码示例。如果您正苦于以下问题:C++ GrPipelineBuilder::setClip方法的具体用法?C++ GrPipelineBuilder::setClip怎么用?C++ GrPipelineBuilder::setClip使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GrPipelineBuilder
的用法示例。
在下文中一共展示了GrPipelineBuilder::setClip方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ProgramUnitTest
bool GrDrawingManager::ProgramUnitTest(GrContext* context,
GrDrawTarget* drawTarget,
int maxStages) {
GrDrawingManager* drawingManager = context->drawingManager();
// setup dummy textures
GrSurfaceDesc dummyDesc;
dummyDesc.fFlags = kRenderTarget_GrSurfaceFlag;
dummyDesc.fConfig = kSkia8888_GrPixelConfig;
dummyDesc.fWidth = 34;
dummyDesc.fHeight = 18;
SkAutoTUnref<GrTexture> dummyTexture1(
context->textureProvider()->createTexture(dummyDesc, false, nullptr, 0));
dummyDesc.fFlags = kNone_GrSurfaceFlags;
dummyDesc.fConfig = kAlpha_8_GrPixelConfig;
dummyDesc.fWidth = 16;
dummyDesc.fHeight = 22;
SkAutoTUnref<GrTexture> dummyTexture2(
context->textureProvider()->createTexture(dummyDesc, false, nullptr, 0));
if (!dummyTexture1 || ! dummyTexture2) {
SkDebugf("Could not allocate dummy textures");
return false;
}
GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()};
// dummy scissor state
GrScissorState scissor;
// wide open clip
GrClip clip;
SkRandom random;
static const int NUM_TESTS = 2048;
for (int t = 0; t < NUM_TESTS; t++) {
// setup random render target(can fail)
SkAutoTUnref<GrRenderTarget> rt(random_render_target(
context->textureProvider(), &random, context->caps()));
if (!rt.get()) {
SkDebugf("Could not allocate render target");
return false;
}
GrPipelineBuilder pipelineBuilder;
pipelineBuilder.setRenderTarget(rt.get());
pipelineBuilder.setClip(clip);
SkAutoTUnref<GrDrawBatch> batch(GrRandomDrawBatch(&random, context));
SkASSERT(batch);
GrProcessorTestData ptd(&random, context, context->caps(), dummyTextures);
set_random_color_coverage_stages(&pipelineBuilder, &ptd, maxStages);
set_random_xpf(&pipelineBuilder, &ptd);
set_random_state(&pipelineBuilder, &random);
set_random_stencil(&pipelineBuilder, &random);
drawTarget->drawBatch(pipelineBuilder, batch);
}
// Flush everything, test passes if flush is successful(ie, no asserts are hit, no crashes)
drawingManager->flush();
// Validate that GrFPs work correctly without an input.
GrSurfaceDesc rtDesc;
rtDesc.fWidth = kRenderTargetWidth;
rtDesc.fHeight = kRenderTargetHeight;
rtDesc.fFlags = kRenderTarget_GrSurfaceFlag;
rtDesc.fConfig = kRGBA_8888_GrPixelConfig;
SkAutoTUnref<GrRenderTarget> rt(
context->textureProvider()->createTexture(rtDesc, false)->asRenderTarget());
int fpFactoryCnt = GrProcessorTestFactory<GrFragmentProcessor>::Count();
for (int i = 0; i < fpFactoryCnt; ++i) {
// Since FP factories internally randomize, call each 10 times.
for (int j = 0; j < 10; ++j) {
SkAutoTUnref<GrDrawBatch> batch(GrRandomDrawBatch(&random, context));
SkASSERT(batch);
GrProcessorTestData ptd(&random, context, context->caps(), dummyTextures);
GrPipelineBuilder builder;
builder.setXPFactory(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->unref();
builder.setRenderTarget(rt);
builder.setClip(clip);
SkAutoTUnref<const GrFragmentProcessor> fp(
GrProcessorTestFactory<GrFragmentProcessor>::CreateIdx(i, &ptd));
SkAutoTUnref<const GrFragmentProcessor> blockFP(
BlockInputFragmentProcessor::Create(fp));
builder.addColorFragmentProcessor(blockFP);
drawTarget->drawBatch(builder, batch);
drawingManager->flush();
}
}
return true;
}
示例2: createAlphaClipMask
GrTexture* GrClipMaskManager::createAlphaClipMask(int32_t elementsGenID,
GrReducedClip::InitialState initialState,
const GrReducedClip::ElementList& elements,
const SkVector& clipToMaskOffset,
const SkIRect& clipSpaceIBounds) {
GrResourceProvider* resourceProvider = fDrawTarget->cmmAccess().resourceProvider();
GrUniqueKey key;
GetClipMaskKey(elementsGenID, clipSpaceIBounds, &key);
if (GrTexture* texture = resourceProvider->findAndRefTextureByUniqueKey(key)) {
return texture;
}
SkAutoTUnref<GrTexture> texture(this->createCachedMask(
clipSpaceIBounds.width(), clipSpaceIBounds.height(), key, true));
// There's no texture in the cache. Let's try to allocate it then.
if (!texture) {
return nullptr;
}
// Set the matrix so that rendered clip elements are transformed to mask space from clip
// space.
SkMatrix translate;
translate.setTranslate(clipToMaskOffset);
// The texture may be larger than necessary, this rect represents the part of the texture
// we populate with a rasterization of the clip.
SkIRect maskSpaceIBounds = SkIRect::MakeWH(clipSpaceIBounds.width(), clipSpaceIBounds.height());
// The scratch texture that we are drawing into can be substantially larger than the mask. Only
// clear the part that we care about.
fDrawTarget->clear(&maskSpaceIBounds,
GrReducedClip::kAllIn_InitialState == initialState ? 0xffffffff : 0x00000000,
true,
texture->asRenderTarget());
// When we use the stencil in the below loop it is important to have this clip installed.
// The second pass that zeros the stencil buffer renders the rect maskSpaceIBounds so the first
// pass must not set values outside of this bounds or stencil values outside the rect won't be
// cleared.
GrClip clip(maskSpaceIBounds);
SkAutoTUnref<GrTexture> temp;
// walk through each clip element and perform its set op
for (GrReducedClip::ElementList::Iter iter = elements.headIter(); iter.get(); iter.next()) {
const Element* element = iter.get();
SkRegion::Op op = element->getOp();
bool invert = element->isInverseFilled();
if (invert || SkRegion::kIntersect_Op == op || SkRegion::kReverseDifference_Op == op) {
GrPipelineBuilder pipelineBuilder;
pipelineBuilder.setClip(clip);
GrPathRenderer* pr = nullptr;
bool useTemp = !this->canStencilAndDrawElement(&pipelineBuilder, texture, &pr, element);
GrTexture* dst;
// This is the bounds of the clip element in the space of the alpha-mask. The temporary
// mask buffer can be substantially larger than the actually clip stack element. We
// touch the minimum number of pixels necessary and use decal mode to combine it with
// the accumulator.
SkIRect maskSpaceElementIBounds;
if (useTemp) {
if (invert) {
maskSpaceElementIBounds = maskSpaceIBounds;
} else {
SkRect elementBounds = element->getBounds();
elementBounds.offset(clipToMaskOffset);
elementBounds.roundOut(&maskSpaceElementIBounds);
}
if (!temp) {
temp.reset(this->createTempMask(maskSpaceIBounds.fRight,
maskSpaceIBounds.fBottom));
if (!temp) {
texture->resourcePriv().removeUniqueKey();
return nullptr;
}
}
dst = temp;
// clear the temp target and set blend to replace
fDrawTarget->clear(&maskSpaceElementIBounds,
invert ? 0xffffffff : 0x00000000,
true,
dst->asRenderTarget());
set_coverage_drawing_xpf(SkRegion::kReplace_Op, invert, &pipelineBuilder);
} else {
// draw directly into the result with the stencil set to make the pixels affected
// by the clip shape be non-zero.
dst = texture;
GR_STATIC_CONST_SAME_STENCIL(kStencilInElement,
kReplace_StencilOp,
kReplace_StencilOp,
kAlways_StencilFunc,
0xffff,
0xffff,
0xffff);
pipelineBuilder.setStencil(kStencilInElement);
set_coverage_drawing_xpf(op, invert, &pipelineBuilder);
}
//.........这里部分代码省略.........
示例3: createStencilClipMask
////////////////////////////////////////////////////////////////////////////////
// Create a 1-bit clip mask in the stencil buffer. 'devClipBounds' are in device
// (as opposed to canvas) coordinates
bool GrClipMaskManager::createStencilClipMask(GrRenderTarget* rt,
int32_t elementsGenID,
GrReducedClip::InitialState initialState,
const GrReducedClip::ElementList& elements,
const SkIRect& clipSpaceIBounds,
const SkIPoint& clipSpaceToStencilOffset) {
SkASSERT(rt);
GrStencilAttachment* stencilAttachment =
fDrawTarget->cmmAccess().resourceProvider()->attachStencilAttachment(rt);
if (nullptr == stencilAttachment) {
return false;
}
if (stencilAttachment->mustRenderClip(elementsGenID, clipSpaceIBounds, clipSpaceToStencilOffset)) {
stencilAttachment->setLastClip(elementsGenID, clipSpaceIBounds, clipSpaceToStencilOffset);
// Set the matrix so that rendered clip elements are transformed from clip to stencil space.
SkVector translate = {
SkIntToScalar(clipSpaceToStencilOffset.fX),
SkIntToScalar(clipSpaceToStencilOffset.fY)
};
SkMatrix viewMatrix;
viewMatrix.setTranslate(translate);
// We set the current clip to the bounds so that our recursive draws are scissored to them.
SkIRect stencilSpaceIBounds(clipSpaceIBounds);
stencilSpaceIBounds.offset(clipSpaceToStencilOffset);
GrClip clip(stencilSpaceIBounds);
int clipBit = stencilAttachment->bits();
SkASSERT((clipBit <= 16) && "Ganesh only handles 16b or smaller stencil buffers");
clipBit = (1 << (clipBit-1));
fDrawTarget->cmmAccess().clearStencilClip(stencilSpaceIBounds,
GrReducedClip::kAllIn_InitialState == initialState, rt);
// walk through each clip element and perform its set op
// with the existing clip.
for (GrReducedClip::ElementList::Iter iter(elements.headIter()); iter.get(); iter.next()) {
const Element* element = iter.get();
GrPipelineBuilder pipelineBuilder;
pipelineBuilder.setClip(clip);
pipelineBuilder.setRenderTarget(rt);
pipelineBuilder.setDisableColorXPFactory();
// if the target is MSAA then we want MSAA enabled when the clip is soft
if (rt->isStencilBufferMultisampled()) {
pipelineBuilder.setState(GrPipelineBuilder::kHWAntialias_Flag, element->isAA());
}
bool fillInverted = false;
// enabled at bottom of loop
fClipMode = kIgnoreClip_StencilClipMode;
// This will be used to determine whether the clip shape can be rendered into the
// stencil with arbitrary stencil settings.
GrPathRenderer::StencilSupport stencilSupport;
GrStrokeInfo stroke(SkStrokeRec::kFill_InitStyle);
SkRegion::Op op = element->getOp();
GrPathRenderer* pr = nullptr;
SkPath clipPath;
if (Element::kRect_Type == element->getType()) {
stencilSupport = GrPathRenderer::kNoRestriction_StencilSupport;
fillInverted = false;
} else {
element->asPath(&clipPath);
fillInverted = clipPath.isInverseFillType();
if (fillInverted) {
clipPath.toggleInverseFillType();
}
pr = this->getContext()->getPathRenderer(fDrawTarget,
&pipelineBuilder,
viewMatrix,
clipPath,
stroke,
false,
GrPathRendererChain::kStencilOnly_DrawType,
&stencilSupport);
if (nullptr == pr) {
return false;
}
}
int passes;
GrStencilSettings stencilSettings[GrStencilSettings::kMaxStencilClipPasses];
bool canRenderDirectToStencil =
GrPathRenderer::kNoRestriction_StencilSupport == stencilSupport;
bool canDrawDirectToClip; // Given the renderer, the element,
// fill rule, and set operation can
// we render the element directly to
// stencil bit used for clipping.
canDrawDirectToClip = GrStencilSettings::GetClipPasses(op,
//.........这里部分代码省略.........
示例4: programUnitTest
bool GrDrawTarget::programUnitTest(GrContext* context, int maxStages) {
// setup dummy textures
GrSurfaceDesc dummyDesc;
dummyDesc.fFlags = kRenderTarget_GrSurfaceFlag;
dummyDesc.fConfig = kSkia8888_GrPixelConfig;
dummyDesc.fWidth = 34;
dummyDesc.fHeight = 18;
SkAutoTUnref<GrTexture> dummyTexture1(
context->textureProvider()->createTexture(dummyDesc, false, nullptr, 0));
dummyDesc.fFlags = kNone_GrSurfaceFlags;
dummyDesc.fConfig = kAlpha_8_GrPixelConfig;
dummyDesc.fWidth = 16;
dummyDesc.fHeight = 22;
SkAutoTUnref<GrTexture> dummyTexture2(
context->textureProvider()->createTexture(dummyDesc, false, nullptr, 0));
if (!dummyTexture1 || ! dummyTexture2) {
SkDebugf("Could not allocate dummy textures");
return false;
}
GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()};
// dummy scissor state
GrScissorState scissor;
// wide open clip
GrClip clip;
SkRandom random;
static const int NUM_TESTS = 2048;
for (int t = 0; t < NUM_TESTS; t++) {
// setup random render target(can fail)
SkAutoTUnref<GrRenderTarget> rt(random_render_target(
context->textureProvider(), &random, this->caps()));
if (!rt.get()) {
SkDebugf("Could not allocate render target");
return false;
}
GrPipelineBuilder pipelineBuilder;
pipelineBuilder.setRenderTarget(rt.get());
pipelineBuilder.setClip(clip);
SkAutoTUnref<GrDrawBatch> batch(GrRandomDrawBatch(&random, context));
SkASSERT(batch);
GrProcessorDataManager procDataManager;
GrProcessorTestData ptd(&random, context, &procDataManager, fGpu->caps(), dummyTextures);
set_random_color_coverage_stages(&pipelineBuilder, &ptd, maxStages);
set_random_xpf(&pipelineBuilder, &ptd);
set_random_state(&pipelineBuilder, &random);
set_random_stencil(&pipelineBuilder, &random);
this->drawBatch(pipelineBuilder, batch);
}
// Flush everything, test passes if flush is successful(ie, no asserts are hit, no crashes)
this->flush();
return true;
}