本文整理汇总了C++中GrContext::makeDrawContext方法的典型用法代码示例。如果您正苦于以下问题:C++ GrContext::makeDrawContext方法的具体用法?C++ GrContext::makeDrawContext怎么用?C++ GrContext::makeDrawContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GrContext
的用法示例。
在下文中一共展示了GrContext::makeDrawContext方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MakeFromGpu
sk_sp<SkSpecialImage> SkXfermodeImageFilter::filterImageGPU(SkSpecialImage* source,
sk_sp<SkSpecialImage> background,
const SkIPoint& backgroundOffset,
sk_sp<SkSpecialImage> foreground,
const SkIPoint& foregroundOffset,
const SkIRect& bounds) const {
SkASSERT(source->isTextureBacked());
GrContext* context = source->getContext();
sk_sp<GrTexture> backgroundTex, foregroundTex;
if (background) {
backgroundTex = background->asTextureRef(context);
}
if (foreground) {
foregroundTex = foreground->asTextureRef(context);
}
GrPaint paint;
// SRGBTODO: AllowSRGBInputs?
sk_sp<GrFragmentProcessor> bgFP;
if (backgroundTex) {
SkMatrix backgroundMatrix;
backgroundMatrix.setIDiv(backgroundTex->width(), backgroundTex->height());
backgroundMatrix.preTranslate(SkIntToScalar(-backgroundOffset.fX),
SkIntToScalar(-backgroundOffset.fY));
bgFP = GrTextureDomainEffect::Make(
backgroundTex.get(), nullptr, backgroundMatrix,
GrTextureDomain::MakeTexelDomain(backgroundTex.get(),
background->subset()),
GrTextureDomain::kDecal_Mode,
GrTextureParams::kNone_FilterMode);
} else {
bgFP = GrConstColorProcessor::Make(GrColor_TRANSPARENT_BLACK,
GrConstColorProcessor::kIgnore_InputMode);
}
if (foregroundTex) {
SkMatrix foregroundMatrix;
foregroundMatrix.setIDiv(foregroundTex->width(), foregroundTex->height());
foregroundMatrix.preTranslate(SkIntToScalar(-foregroundOffset.fX),
SkIntToScalar(-foregroundOffset.fY));
sk_sp<GrFragmentProcessor> foregroundFP;
foregroundFP = GrTextureDomainEffect::Make(
foregroundTex.get(), nullptr, foregroundMatrix,
GrTextureDomain::MakeTexelDomain(foregroundTex.get(),
foreground->subset()),
GrTextureDomain::kDecal_Mode,
GrTextureParams::kNone_FilterMode);
paint.addColorFragmentProcessor(std::move(foregroundFP));
// A null fMode is interpreted to mean kSrcOver_Mode (to match raster).
SkAutoTUnref<SkXfermode> mode(SkSafeRef(fMode.get()));
if (!mode) {
// It would be awesome to use SkXfermode::Create here but it knows better
// than us and won't return a kSrcOver_Mode SkXfermode. That means we
// have to get one the hard way.
struct ProcCoeff rec;
rec.fProc = SkXfermode::GetProc(SkXfermode::kSrcOver_Mode);
SkXfermode::ModeAsCoeff(SkXfermode::kSrcOver_Mode, &rec.fSC, &rec.fDC);
mode.reset(new SkProcCoeffXfermode(rec, SkXfermode::kSrcOver_Mode));
}
sk_sp<GrFragmentProcessor> xferFP(
mode->makeFragmentProcessorForImageFilter(std::move(bgFP)));
// A null 'xferFP' here means kSrc_Mode was used in which case we can just proceed
if (xferFP) {
paint.addColorFragmentProcessor(std::move(xferFP));
}
} else {
paint.addColorFragmentProcessor(std::move(bgFP));
}
paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode);
sk_sp<GrDrawContext> drawContext(context->makeDrawContext(SkBackingFit::kApprox,
bounds.width(), bounds.height(),
kSkia8888_GrPixelConfig,
sk_ref_sp(source->getColorSpace())));
if (!drawContext) {
return nullptr;
}
SkMatrix matrix;
matrix.setTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.top()));
drawContext->drawRect(GrNoClip(), paint, matrix, SkRect::Make(bounds));
return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(bounds.width(), bounds.height()),
kNeedNewImageUniqueID_SpecialImage,
drawContext->asTexture(),
sk_ref_sp(drawContext->getColorSpace()));
}