本文整理汇总了C++中SkMatrix::setIDiv方法的典型用法代码示例。如果您正苦于以下问题:C++ SkMatrix::setIDiv方法的具体用法?C++ SkMatrix::setIDiv怎么用?C++ SkMatrix::setIDiv使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkMatrix
的用法示例。
在下文中一共展示了SkMatrix::setIDiv方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DrawToTargetWithPathMask
void GrSWMaskHelper::DrawToTargetWithPathMask(GrTexture* texture,
GrDrawTarget* target,
const SkIRect& rect) {
GrDrawState* drawState = target->drawState();
GrDrawState::AutoViewMatrixRestore avmr;
if (!avmr.setIdentity(drawState)) {
return;
}
GrDrawState::AutoRestoreEffects are(drawState);
SkRect dstRect = SkRect::MakeLTRB(SK_Scalar1 * rect.fLeft,
SK_Scalar1 * rect.fTop,
SK_Scalar1 * rect.fRight,
SK_Scalar1 * rect.fBottom);
// We want to use device coords to compute the texture coordinates. We set our matrix to be
// equal to the view matrix followed by a translation so that the top-left of the device bounds
// maps to 0,0, and then a scaling matrix to normalized coords. We apply this matrix to the
// vertex positions rather than local coords.
SkMatrix maskMatrix;
maskMatrix.setIDiv(texture->width(), texture->height());
maskMatrix.preTranslate(SkIntToScalar(-rect.fLeft), SkIntToScalar(-rect.fTop));
maskMatrix.preConcat(drawState->getViewMatrix());
drawState->addCoverageEffect(
GrSimpleTextureEffect::Create(texture,
maskMatrix,
GrTextureParams::kNone_FilterMode,
kPosition_GrCoordSet))->unref();
target->drawSimpleRect(dstRect);
}
示例2: mergeMask
void GrClipMaskManager::mergeMask(GrPipelineBuilder* pipelineBuilder,
GrTexture* dstMask,
GrTexture* srcMask,
SkRegion::Op op,
const SkIRect& dstBound,
const SkIRect& srcBound) {
pipelineBuilder->setRenderTarget(dstMask->asRenderTarget());
// We want to invert the coverage here
set_coverage_drawing_xpf(op, false, pipelineBuilder);
SkMatrix sampleM;
sampleM.setIDiv(srcMask->width(), srcMask->height());
pipelineBuilder->addCoverageFragmentProcessor(
GrTextureDomainEffect::Create(srcMask,
sampleM,
GrTextureDomain::MakeTexelDomain(srcMask, srcBound),
GrTextureDomain::kDecal_Mode,
GrTextureParams::kNone_FilterMode))->unref();
// The color passed in here does not matter since the coverageSetOpXP won't read it.
fDrawTarget->drawNonAARect(*pipelineBuilder,
GrColor_WHITE,
SkMatrix::I(),
SkRect::Make(dstBound));
}
示例3: mergeMask
void GrClipMaskManager::mergeMask(GrTexture* dstMask,
GrTexture* srcMask,
SkRegion::Op op,
const SkIRect& dstBound,
const SkIRect& srcBound) {
GrDrawState::AutoViewMatrixRestore avmr;
GrDrawState* drawState = fGpu->drawState();
SkAssertResult(avmr.setIdentity(drawState));
GrDrawState::AutoRestoreEffects are(drawState);
drawState->setRenderTarget(dstMask->asRenderTarget());
setup_boolean_blendcoeffs(drawState, op);
SkMatrix sampleM;
sampleM.setIDiv(srcMask->width(), srcMask->height());
drawState->addColorEffect(
GrTextureDomainEffect::Create(srcMask,
sampleM,
GrTextureDomain::MakeTexelDomain(srcMask, srcBound),
GrTextureDomain::kDecal_Mode,
GrTextureParams::kNone_FilterMode))->unref();
fGpu->drawSimpleRect(SkRect::Make(dstBound), NULL);
}
示例4: mergeMask
void GrClipMaskManager::mergeMask(GrTexture* dstMask,
GrTexture* srcMask,
SkRegion::Op op,
const GrIRect& dstBound,
const GrIRect& srcBound) {
GrDrawState* drawState = fGpu->drawState();
SkMatrix oldMatrix = drawState->getViewMatrix();
drawState->viewMatrix()->reset();
drawState->setRenderTarget(dstMask->asRenderTarget());
setup_boolean_blendcoeffs(drawState, op);
SkMatrix sampleM;
sampleM.setIDiv(srcMask->width(), srcMask->height());
drawState->setEffect(0,
GrTextureDomainEffect::Create(srcMask,
sampleM,
GrTextureDomainEffect::MakeTexelDomain(srcMask, srcBound),
GrTextureDomainEffect::kDecal_WrapMode,
false))->unref();
fGpu->drawSimpleRect(SkRect::MakeFromIRect(dstBound), NULL);
drawState->disableStage(0);
drawState->setViewMatrix(oldMatrix);
}
示例5: SkIntToScalar
BOOL
_DC::ExtTextOut(int x, int y, UINT options, LPCRECTDef lprect, const char* pszText, const int * lpDx){
if( !context_ || !pszText)
return FALSE;
// Invalid rect area.
if( lprect && (lprect->right <= 0 || lprect->bottom <= 0) )
return FALSE;
BOOL bRet = FALSE;
if (_canvas) {
_skPaintText.setTextEncoding(SkPaint::TextEncoding::kUTF8_TextEncoding);
_canvas->save();
SkMatrix m;
m.setIDiv(1.0f, -1.0f);
_canvas->setMatrix(m);
int bytesLen = _tcslen(pszText)*sizeof(char);
SkScalar textSize = _skPaintText.getTextSize();
int height = _canvas->imageInfo().fHeight;
_canvas->drawText(pszText, bytesLen, SkIntToScalar(x), -1.0f * SkIntToScalar(height - y) + textSize, _skPaintText);
_canvas->restore();
bRet = TRUE;
}
else {
wchar_t wszTemp[256];
int nLen = StringHelper::UTF8ToUnicode(pszText, wszTemp, 255);
bRet = (TRUE == ::ExtTextOutW(context_, x, y, options, lprect, wszTemp, nLen, NULL));
}
return bRet;
}
示例6: DrawToTargetWithPathMask
void GrSWMaskHelper::DrawToTargetWithPathMask(GrTexture* texture,
GrDrawTarget* target,
GrPipelineBuilder* pipelineBuilder,
GrColor color,
const SkMatrix& viewMatrix,
const SkIRect& rect) {
SkMatrix invert;
if (!viewMatrix.invert(&invert)) {
return;
}
GrPipelineBuilder::AutoRestoreFragmentProcessors arfp(pipelineBuilder);
SkRect dstRect = SkRect::MakeLTRB(SK_Scalar1 * rect.fLeft,
SK_Scalar1 * rect.fTop,
SK_Scalar1 * rect.fRight,
SK_Scalar1 * rect.fBottom);
// We use device coords to compute the texture coordinates. We take the device coords and apply
// a translation so that the top-left of the device bounds maps to 0,0, and then a scaling
// matrix to normalized coords.
SkMatrix maskMatrix;
maskMatrix.setIDiv(texture->width(), texture->height());
maskMatrix.preTranslate(SkIntToScalar(-rect.fLeft), SkIntToScalar(-rect.fTop));
pipelineBuilder->addCoverageProcessor(
GrSimpleTextureEffect::Create(texture,
maskMatrix,
GrTextureParams::kNone_FilterMode,
kDevice_GrCoordSet))->unref();
target->drawRect(pipelineBuilder, color, SkMatrix::I(), dstRect, NULL, &invert);
}
示例7: asFragmentProcessor
const GrFragmentProcessor* SkImageShader::asFragmentProcessor(GrContext* context,
const SkMatrix& viewM,
const SkMatrix* localMatrix,
SkFilterQuality filterQuality,
GrProcessorDataManager* mgr) const {
SkMatrix matrix;
matrix.setIDiv(fImage->width(), fImage->height());
SkMatrix lmInverse;
if (!this->getLocalMatrix().invert(&lmInverse)) {
return nullptr;
}
if (localMatrix) {
SkMatrix inv;
if (!localMatrix->invert(&inv)) {
return nullptr;
}
lmInverse.postConcat(inv);
}
matrix.preConcat(lmInverse);
SkShader::TileMode tm[] = { fTileModeX, fTileModeY };
// Must set wrap and filter on the sampler before requesting a texture. In two places below
// we check the matrix scale factors to determine how to interpret the filter quality setting.
// This completely ignores the complexity of the drawVertices case where explicit local coords
// are provided by the caller.
bool doBicubic;
GrTextureParams::FilterMode textureFilterMode =
GrSkFilterQualityToGrFilterMode(filterQuality, viewM, this->getLocalMatrix(), &doBicubic);
GrTextureParams params(tm, textureFilterMode);
SkImageUsageType usageType;
if (kClamp_TileMode == fTileModeX && kClamp_TileMode == fTileModeY) {
usageType = kUntiled_SkImageUsageType;
} else if (GrTextureParams::kNone_FilterMode == textureFilterMode) {
usageType = kTiled_Unfiltered_SkImageUsageType;
} else {
usageType = kTiled_Filtered_SkImageUsageType;
}
SkAutoTUnref<GrTexture> texture(as_IB(fImage)->asTextureRef(context, usageType));
if (!texture) {
return nullptr;
}
SkAutoTUnref<GrFragmentProcessor> inner;
if (doBicubic) {
inner.reset(GrBicubicEffect::Create(mgr, texture, matrix, tm));
} else {
inner.reset(GrSimpleTextureEffect::Create(mgr, texture, matrix, params));
}
if (GrPixelConfigIsAlphaOnly(texture->config())) {
return SkRef(inner.get());
}
return GrFragmentProcessor::MulOuputByInputAlpha(inner);
}
示例8: asFragmentProcessor
bool SkBitmapProcShader::asFragmentProcessor(GrContext* context, const SkPaint& paint,
const SkMatrix& viewM,
const SkMatrix* localMatrix, GrColor* paintColor,
GrProcessorDataManager* procDataManager,
GrFragmentProcessor** fp) const {
SkMatrix matrix;
matrix.setIDiv(fRawBitmap.width(), fRawBitmap.height());
SkMatrix lmInverse;
if (!this->getLocalMatrix().invert(&lmInverse)) {
return false;
}
if (localMatrix) {
SkMatrix inv;
if (!localMatrix->invert(&inv)) {
return false;
}
lmInverse.postConcat(inv);
}
matrix.preConcat(lmInverse);
SkShader::TileMode tm[] = {
(TileMode)fTileModeX,
(TileMode)fTileModeY,
};
// Must set wrap and filter on the sampler before requesting a texture. In two places below
// we check the matrix scale factors to determine how to interpret the filter quality setting.
// This completely ignores the complexity of the drawVertices case where explicit local coords
// are provided by the caller.
bool doBicubic;
GrTextureParams::FilterMode textureFilterMode =
GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), viewM, this->getLocalMatrix(),
&doBicubic);
GrTextureParams params(tm, textureFilterMode);
SkAutoTUnref<GrTexture> texture(GrRefCachedBitmapTexture(context, fRawBitmap, ¶ms));
if (!texture) {
SkErrorInternals::SetError( kInternalError_SkError,
"Couldn't convert bitmap to texture.");
return false;
}
*paintColor = (kAlpha_8_SkColorType == fRawBitmap.colorType()) ?
SkColor2GrColor(paint.getColor()) :
SkColor2GrColorJustAlpha(paint.getColor());
if (doBicubic) {
*fp = GrBicubicEffect::Create(procDataManager, texture, matrix, tm);
} else {
*fp = GrSimpleTextureEffect::Create(procDataManager, texture, matrix, params);
}
return true;
}
示例9: Create
////////////////////////////////////////////////////////////////////////////////
// set up the draw state to enable the aa clipping mask. Besides setting up the
// stage matrix this also alters the vertex layout
static const GrFragmentProcessor* create_fp_for_mask(GrTexture* result, const SkIRect &devBound) {
SkMatrix mat;
// We use device coords to compute the texture coordinates. We set our matrix to be a
// translation to the devBound, and then a scaling matrix to normalized coords.
mat.setIDiv(result->width(), result->height());
mat.preTranslate(SkIntToScalar(-devBound.fLeft),
SkIntToScalar(-devBound.fTop));
SkIRect domainTexels = SkIRect::MakeWH(devBound.width(), devBound.height());
return GrTextureDomainEffect::Create(result,
mat,
GrTextureDomain::MakeTexelDomain(result, domainTexels),
GrTextureDomain::kDecal_Mode,
GrTextureParams::kNone_FilterMode,
kDevice_GrCoordSet);
}
示例10: params
sk_sp<GrFragmentProcessor> SkImageShader::asFragmentProcessor(const AsFPArgs& args) const {
SkMatrix matrix;
matrix.setIDiv(fImage->width(), fImage->height());
SkMatrix lmInverse;
if (!this->getLocalMatrix().invert(&lmInverse)) {
return nullptr;
}
if (args.fLocalMatrix) {
SkMatrix inv;
if (!args.fLocalMatrix->invert(&inv)) {
return nullptr;
}
lmInverse.postConcat(inv);
}
matrix.preConcat(lmInverse);
SkShader::TileMode tm[] = { fTileModeX, fTileModeY };
// Must set wrap and filter on the sampler before requesting a texture. In two places below
// we check the matrix scale factors to determine how to interpret the filter quality setting.
// This completely ignores the complexity of the drawVertices case where explicit local coords
// are provided by the caller.
bool doBicubic;
GrTextureParams::FilterMode textureFilterMode =
GrSkFilterQualityToGrFilterMode(args.fFilterQuality, *args.fViewMatrix, this->getLocalMatrix(),
&doBicubic);
GrTextureParams params(tm, textureFilterMode);
SkAutoTUnref<GrTexture> texture(as_IB(fImage)->asTextureRef(args.fContext, params,
args.fGammaTreatment));
if (!texture) {
return nullptr;
}
sk_sp<GrFragmentProcessor> inner;
if (doBicubic) {
inner = GrBicubicEffect::Make(texture, nullptr, matrix, tm);
} else {
inner = GrSimpleTextureEffect::Make(texture, nullptr, matrix, params);
}
if (GrPixelConfigIsAlphaOnly(texture->config())) {
return inner;
}
return sk_sp<GrFragmentProcessor>(GrFragmentProcessor::MulOutputByInputAlpha(std::move(inner)));
}
示例11: DrawToTargetWithPathMask
void GrSWMaskHelper::DrawToTargetWithPathMask(GrTexture* texture,
GrDrawContext* drawContext,
const GrPaint* paint,
const GrUserStencilSettings* userStencilSettings,
const GrClip& clip,
GrColor color,
const SkMatrix& viewMatrix,
const SkIRect& rect) {
SkMatrix invert;
if (!viewMatrix.invert(&invert)) {
return;
}
SkRect dstRect = SkRect::MakeLTRB(SK_Scalar1 * rect.fLeft,
SK_Scalar1 * rect.fTop,
SK_Scalar1 * rect.fRight,
SK_Scalar1 * rect.fBottom);
// We use device coords to compute the texture coordinates. We take the device coords and apply
// a translation so that the top-left of the device bounds maps to 0,0, and then a scaling
// matrix to normalized coords.
SkMatrix maskMatrix;
maskMatrix.setIDiv(texture->width(), texture->height());
maskMatrix.preTranslate(SkIntToScalar(-rect.fLeft), SkIntToScalar(-rect.fTop));
GrPipelineBuilder pipelineBuilder(*paint, drawContext->isUnifiedMultisampled());
pipelineBuilder.setRenderTarget(drawContext->accessRenderTarget());
pipelineBuilder.setUserStencil(userStencilSettings);
pipelineBuilder.addCoverageFragmentProcessor(
GrSimpleTextureEffect::Create(texture,
maskMatrix,
GrTextureParams::kNone_FilterMode,
kDevice_GrCoordSet))->unref();
SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateNonAAFill(color, SkMatrix::I(),
dstRect, nullptr, &invert));
drawContext->drawBatch(pipelineBuilder, clip, batch);
}
示例12: GaussianBlur
GrTexture* GaussianBlur(GrContext* context,
GrTexture* srcTexture,
bool canClobberSrc,
const SkRect& rect,
bool cropToRect,
float sigmaX,
float sigmaY) {
SkASSERT(NULL != context);
GrContext::AutoRenderTarget art(context);
GrContext::AutoMatrix am;
am.setIdentity(context);
SkIRect clearRect;
int scaleFactorX, radiusX;
int scaleFactorY, radiusY;
sigmaX = adjust_sigma(sigmaX, &scaleFactorX, &radiusX);
sigmaY = adjust_sigma(sigmaY, &scaleFactorY, &radiusY);
SkRect srcRect(rect);
scale_rect(&srcRect, 1.0f / scaleFactorX, 1.0f / scaleFactorY);
srcRect.roundOut();
scale_rect(&srcRect, static_cast<float>(scaleFactorX),
static_cast<float>(scaleFactorY));
GrContext::AutoClip acs(context, SkRect::MakeWH(srcRect.width(), srcRect.height()));
SkASSERT(kBGRA_8888_GrPixelConfig == srcTexture->config() ||
kRGBA_8888_GrPixelConfig == srcTexture->config() ||
kAlpha_8_GrPixelConfig == srcTexture->config());
GrTextureDesc desc;
desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit;
desc.fWidth = SkScalarFloorToInt(srcRect.width());
desc.fHeight = SkScalarFloorToInt(srcRect.height());
desc.fConfig = srcTexture->config();
GrAutoScratchTexture temp1, temp2;
GrTexture* dstTexture = temp1.set(context, desc);
GrTexture* tempTexture = canClobberSrc ? srcTexture : temp2.set(context, desc);
if (NULL == dstTexture || NULL == tempTexture) {
return NULL;
}
for (int i = 1; i < scaleFactorX || i < scaleFactorY; i *= 2) {
GrPaint paint;
SkMatrix matrix;
matrix.setIDiv(srcTexture->width(), srcTexture->height());
context->setRenderTarget(dstTexture->asRenderTarget());
SkRect dstRect(srcRect);
if (cropToRect && i == 1) {
dstRect.offset(-dstRect.fLeft, -dstRect.fTop);
SkRect domain;
matrix.mapRect(&domain, rect);
domain.inset(i < scaleFactorX ? SK_ScalarHalf / srcTexture->width() : 0.0f,
i < scaleFactorY ? SK_ScalarHalf / srcTexture->height() : 0.0f);
SkAutoTUnref<GrEffectRef> effect(GrTextureDomainEffect::Create(
srcTexture,
matrix,
domain,
GrTextureDomainEffect::kDecal_WrapMode,
GrTextureParams::kBilerp_FilterMode));
paint.addColorEffect(effect);
} else {
GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kBilerp_FilterMode);
paint.addColorTextureEffect(srcTexture, matrix, params);
}
scale_rect(&dstRect, i < scaleFactorX ? 0.5f : 1.0f,
i < scaleFactorY ? 0.5f : 1.0f);
context->drawRectToRect(paint, dstRect, srcRect);
srcRect = dstRect;
srcTexture = dstTexture;
SkTSwap(dstTexture, tempTexture);
}
SkIRect srcIRect;
srcRect.roundOut(&srcIRect);
if (sigmaX > 0.0f) {
if (scaleFactorX > 1) {
// Clear out a radius to the right of the srcRect to prevent the
// X convolution from reading garbage.
clearRect = SkIRect::MakeXYWH(srcIRect.fRight, srcIRect.fTop,
radiusX, srcIRect.height());
context->clear(&clearRect, 0x0, false);
}
context->setRenderTarget(dstTexture->asRenderTarget());
SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height());
convolve_gaussian(context, srcRect, dstRect, srcTexture,
Gr1DKernelEffect::kX_Direction, radiusX, sigmaX, cropToRect);
srcTexture = dstTexture;
srcRect = dstRect;
SkTSwap(dstTexture, tempTexture);
}
if (sigmaY > 0.0f) {
if (scaleFactorY > 1 || sigmaX > 0.0f) {
// Clear out a radius below the srcRect to prevent the Y
// convolution from reading garbage.
//.........这里部分代码省略.........
示例13: GaussianBlur
GrTexture* GaussianBlur(GrContext* context,
GrTexture* srcTexture,
bool canClobberSrc,
const SkRect& dstBounds,
const SkRect* srcBounds,
float sigmaX,
float sigmaY,
GrTextureProvider::SizeConstraint constraint) {
SkASSERT(context);
SkIRect clearRect;
int scaleFactorX, radiusX;
int scaleFactorY, radiusY;
int maxTextureSize = context->caps()->maxTextureSize();
sigmaX = adjust_sigma(sigmaX, maxTextureSize, &scaleFactorX, &radiusX);
sigmaY = adjust_sigma(sigmaY, maxTextureSize, &scaleFactorY, &radiusY);
SkPoint srcOffset = SkPoint::Make(-dstBounds.x(), -dstBounds.y());
SkRect localDstBounds = SkRect::MakeWH(dstBounds.width(), dstBounds.height());
SkRect localSrcBounds;
SkRect srcRect;
if (srcBounds) {
srcRect = localSrcBounds = *srcBounds;
srcRect.offset(srcOffset);
srcBounds = &localSrcBounds;
} else {
srcRect = localDstBounds;
}
scale_rect(&srcRect, 1.0f / scaleFactorX, 1.0f / scaleFactorY);
srcRect.roundOut(&srcRect);
scale_rect(&srcRect, static_cast<float>(scaleFactorX),
static_cast<float>(scaleFactorY));
// setup new clip
GrClip clip(localDstBounds);
SkASSERT(kBGRA_8888_GrPixelConfig == srcTexture->config() ||
kRGBA_8888_GrPixelConfig == srcTexture->config() ||
kAlpha_8_GrPixelConfig == srcTexture->config());
GrSurfaceDesc desc;
desc.fFlags = kRenderTarget_GrSurfaceFlag;
desc.fWidth = SkScalarFloorToInt(dstBounds.width());
desc.fHeight = SkScalarFloorToInt(dstBounds.height());
desc.fConfig = srcTexture->config();
GrTexture* dstTexture;
GrTexture* tempTexture;
SkAutoTUnref<GrTexture> temp1, temp2;
temp1.reset(context->textureProvider()->createTexture(desc, constraint));
dstTexture = temp1.get();
if (canClobberSrc) {
tempTexture = srcTexture;
} else {
temp2.reset(context->textureProvider()->createTexture(desc, constraint));
tempTexture = temp2.get();
}
if (nullptr == dstTexture || nullptr == tempTexture) {
return nullptr;
}
SkAutoTUnref<GrDrawContext> srcDrawContext;
for (int i = 1; i < scaleFactorX || i < scaleFactorY; i *= 2) {
GrPaint paint;
SkMatrix matrix;
matrix.setIDiv(srcTexture->width(), srcTexture->height());
SkRect dstRect(srcRect);
if (srcBounds && i == 1) {
SkRect domain;
matrix.mapRect(&domain, *srcBounds);
domain.inset((i < scaleFactorX) ? SK_ScalarHalf / srcTexture->width() : 0.0f,
(i < scaleFactorY) ? SK_ScalarHalf / srcTexture->height() : 0.0f);
SkAutoTUnref<const GrFragmentProcessor> fp(GrTextureDomainEffect::Create(
srcTexture,
matrix,
domain,
GrTextureDomain::kDecal_Mode,
GrTextureParams::kBilerp_FilterMode));
paint.addColorFragmentProcessor(fp);
srcRect.offset(-srcOffset);
srcOffset.set(0, 0);
} else {
GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kBilerp_FilterMode);
paint.addColorTextureProcessor(srcTexture, matrix, params);
}
paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode);
scale_rect(&dstRect, i < scaleFactorX ? 0.5f : 1.0f,
i < scaleFactorY ? 0.5f : 1.0f);
SkAutoTUnref<GrDrawContext> dstDrawContext(
context->drawContext(dstTexture->asRenderTarget()));
if (!dstDrawContext) {
return nullptr;
}
dstDrawContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRect, srcRect);
srcDrawContext.swap(dstDrawContext);
//.........这里部分代码省略.........
示例14: GaussianBlur
GrTexture* GaussianBlur(GrContext* context,
GrTexture* srcTexture,
bool canClobberSrc,
const SkRect& rect,
bool cropToRect,
float sigmaX,
float sigmaY) {
SkASSERT(context);
SkIRect clearRect;
int scaleFactorX, radiusX;
int scaleFactorY, radiusY;
int maxTextureSize = context->caps()->maxTextureSize();
sigmaX = adjust_sigma(sigmaX, maxTextureSize, &scaleFactorX, &radiusX);
sigmaY = adjust_sigma(sigmaY, maxTextureSize, &scaleFactorY, &radiusY);
SkRect srcRect(rect);
scale_rect(&srcRect, 1.0f / scaleFactorX, 1.0f / scaleFactorY);
srcRect.roundOut(&srcRect);
scale_rect(&srcRect, static_cast<float>(scaleFactorX),
static_cast<float>(scaleFactorY));
// setup new clip
GrClip clip(SkRect::MakeWH(srcRect.width(), srcRect.height()));
SkASSERT(kBGRA_8888_GrPixelConfig == srcTexture->config() ||
kRGBA_8888_GrPixelConfig == srcTexture->config() ||
kAlpha_8_GrPixelConfig == srcTexture->config());
GrSurfaceDesc desc;
desc.fFlags = kRenderTarget_GrSurfaceFlag;
desc.fWidth = SkScalarFloorToInt(srcRect.width());
desc.fHeight = SkScalarFloorToInt(srcRect.height());
desc.fConfig = srcTexture->config();
GrTexture* dstTexture;
GrTexture* tempTexture;
SkAutoTUnref<GrTexture> temp1, temp2;
temp1.reset(context->textureProvider()->refScratchTexture(
desc, GrTextureProvider::kApprox_ScratchTexMatch));
dstTexture = temp1.get();
if (canClobberSrc) {
tempTexture = srcTexture;
} else {
temp2.reset(context->textureProvider()->refScratchTexture(
desc, GrTextureProvider::kApprox_ScratchTexMatch));
tempTexture = temp2.get();
}
if (NULL == dstTexture || NULL == tempTexture) {
return NULL;
}
GrDrawContext* drawContext = context->drawContext();
if (!drawContext) {
return NULL;
}
for (int i = 1; i < scaleFactorX || i < scaleFactorY; i *= 2) {
GrPaint paint;
SkMatrix matrix;
matrix.setIDiv(srcTexture->width(), srcTexture->height());
SkRect dstRect(srcRect);
if (cropToRect && i == 1) {
dstRect.offset(-dstRect.fLeft, -dstRect.fTop);
SkRect domain;
matrix.mapRect(&domain, rect);
domain.inset(i < scaleFactorX ? SK_ScalarHalf / srcTexture->width() : 0.0f,
i < scaleFactorY ? SK_ScalarHalf / srcTexture->height() : 0.0f);
SkAutoTUnref<GrFragmentProcessor> fp( GrTextureDomainEffect::Create(
paint.getProcessorDataManager(),
srcTexture,
matrix,
domain,
GrTextureDomain::kDecal_Mode,
GrTextureParams::kBilerp_FilterMode));
paint.addColorProcessor(fp);
} else {
GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kBilerp_FilterMode);
paint.addColorTextureProcessor(srcTexture, matrix, params);
}
scale_rect(&dstRect, i < scaleFactorX ? 0.5f : 1.0f,
i < scaleFactorY ? 0.5f : 1.0f);
drawContext->drawNonAARectToRect(dstTexture->asRenderTarget(), clip, paint, SkMatrix::I(),
dstRect, srcRect);
srcRect = dstRect;
srcTexture = dstTexture;
SkTSwap(dstTexture, tempTexture);
}
const SkIRect srcIRect = srcRect.roundOut();
// For really small blurs(Certainly no wider than 5x5 on desktop gpus) it is faster to just
// launch a single non separable kernel vs two launches
if (sigmaX > 0.0f && sigmaY > 0 &&
(2 * radiusX + 1) * (2 * radiusY + 1) <= MAX_KERNEL_SIZE) {
// We shouldn't be scaling because this is a small size blur
SkASSERT((scaleFactorX == scaleFactorY) == 1);
SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height());
//.........这里部分代码省略.........
示例15: filterImageGPUDeprecated
bool SkXfermodeImageFilter::filterImageGPUDeprecated(Proxy* proxy,
const SkBitmap& src,
const Context& ctx,
SkBitmap* result,
SkIPoint* offset) const {
GrContext* context = nullptr;
SkBitmap background = src;
SkIPoint backgroundOffset = SkIPoint::Make(0, 0);
if (!this->filterInputGPUDeprecated(0, proxy, src, ctx, &background, &backgroundOffset)) {
background.reset();
}
GrTexture* backgroundTex = background.getTexture();
if (backgroundTex) {
context = backgroundTex->getContext();
}
SkBitmap foreground = src;
SkIPoint foregroundOffset = SkIPoint::Make(0, 0);
if (!this->filterInputGPUDeprecated(1, proxy, src, ctx, &foreground, &foregroundOffset)) {
foreground.reset();
}
GrTexture* foregroundTex = foreground.getTexture();
if (foregroundTex) {
context = foregroundTex->getContext();
}
if (!context) {
return false;
}
SkIRect bounds = background.bounds().makeOffset(backgroundOffset.x(), backgroundOffset.y());
bounds.join(foreground.bounds().makeOffset(foregroundOffset.x(), foregroundOffset.y()));
if (bounds.isEmpty()) {
return false;
}
GrSurfaceDesc desc;
desc.fFlags = kRenderTarget_GrSurfaceFlag;
desc.fWidth = bounds.width();
desc.fHeight = bounds.height();
desc.fConfig = kSkia8888_GrPixelConfig;
SkAutoTUnref<GrTexture> dst(context->textureProvider()->createApproxTexture(desc));
if (!dst) {
return false;
}
GrPaint paint;
SkAutoTUnref<const GrFragmentProcessor> bgFP;
if (backgroundTex) {
SkMatrix backgroundMatrix;
backgroundMatrix.setIDiv(backgroundTex->width(), backgroundTex->height());
backgroundMatrix.preTranslate(SkIntToScalar(-backgroundOffset.fX),
SkIntToScalar(-backgroundOffset.fY));
bgFP.reset(GrTextureDomainEffect::Create(
backgroundTex, backgroundMatrix,
GrTextureDomain::MakeTexelDomain(backgroundTex, background.bounds()),
GrTextureDomain::kDecal_Mode,
GrTextureParams::kNone_FilterMode));
} else {
bgFP.reset(GrConstColorProcessor::Create(GrColor_TRANSPARENT_BLACK,
GrConstColorProcessor::kIgnore_InputMode));
}
if (foregroundTex) {
SkMatrix foregroundMatrix;
foregroundMatrix.setIDiv(foregroundTex->width(), foregroundTex->height());
foregroundMatrix.preTranslate(SkIntToScalar(-foregroundOffset.fX),
SkIntToScalar(-foregroundOffset.fY));
SkAutoTUnref<const GrFragmentProcessor> foregroundFP;
foregroundFP.reset(GrTextureDomainEffect::Create(
foregroundTex, foregroundMatrix,
GrTextureDomain::MakeTexelDomain(foregroundTex, foreground.bounds()),
GrTextureDomain::kDecal_Mode,
GrTextureParams::kNone_FilterMode));
paint.addColorFragmentProcessor(foregroundFP.get());
// 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));
}
SkAutoTUnref<const GrFragmentProcessor> xferFP(mode->getFragmentProcessorForImageFilter(bgFP));
// A null 'xferFP' here means kSrc_Mode was used in which case we can just proceed
if (xferFP) {
paint.addColorFragmentProcessor(xferFP);
}
} else {
//.........这里部分代码省略.........