本文整理汇总了C++中GrTexture::asRenderTarget方法的典型用法代码示例。如果您正苦于以下问题:C++ GrTexture::asRenderTarget方法的具体用法?C++ GrTexture::asRenderTarget怎么用?C++ GrTexture::asRenderTarget使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GrTexture
的用法示例。
在下文中一共展示了GrTexture::asRenderTarget方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: basic_clear_test
void basic_clear_test(skiatest::Reporter* reporter, GrContext* context, GrPixelConfig config) {
GrVkGpu* gpu = static_cast<GrVkGpu*>(context->getGpu());
gpu->discard(NULL);
SkAutoTMalloc<GrColor> buffer(25);
GrSurfaceDesc surfDesc;
surfDesc.fFlags = kRenderTarget_GrSurfaceFlag;
surfDesc.fOrigin = kTopLeft_GrSurfaceOrigin;
surfDesc.fWidth = 5;
surfDesc.fHeight = 5;
surfDesc.fConfig = config;
surfDesc.fSampleCnt = 0;
GrTexture* tex = gpu->createTexture(surfDesc, false, nullptr, 0);
SkASSERT(tex);
SkASSERT(tex->asRenderTarget());
SkIRect rect = SkIRect::MakeWH(5, 5);
gpu->clear(rect, GrColor_TRANSPARENT_BLACK, tex->asRenderTarget());
gpu->readPixels(tex, 0, 0, 5, 5, config, (void*)buffer.get(), 0);
REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(buffer.get(),
GrColor_TRANSPARENT_BLACK,
config,
5,
5));
gpu->clear(rect, GrColor_WHITE, tex->asRenderTarget());
gpu->readPixels(tex, 0, 0, 5, 5, config, (void*)buffer.get(), 0);
REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(buffer.get(),
GrColor_WHITE,
config,
5,
5));
GrColor myColor = GrColorPackRGBA(0xFF, 0x7F, 0x40, 0x20);
gpu->clear(rect, myColor, tex->asRenderTarget());
gpu->readPixels(tex, 0, 0, 5, 5, config, (void*)buffer.get(), 0);
REPORTER_ASSERT(reporter, does_full_buffer_contain_correct_color(buffer.get(),
myColor,
config,
5,
5));
}
示例2: random_render_target
static GrRenderTarget* random_render_target(GrTextureProvider* textureProvider, SkRandom* random,
const GrCaps* caps) {
// setup render target
GrTextureParams params;
GrSurfaceDesc texDesc;
texDesc.fWidth = kRenderTargetWidth;
texDesc.fHeight = kRenderTargetHeight;
texDesc.fFlags = kRenderTarget_GrSurfaceFlag;
texDesc.fConfig = kRGBA_8888_GrPixelConfig;
texDesc.fOrigin = random->nextBool() == true ? kTopLeft_GrSurfaceOrigin :
kBottomLeft_GrSurfaceOrigin;
texDesc.fSampleCnt = random->nextBool() == true ? SkTMin(4, caps->maxSampleCount()) : 0;
GrUniqueKey key;
static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
GrUniqueKey::Builder builder(&key, kDomain, 2);
builder[0] = texDesc.fOrigin;
builder[1] = texDesc.fSampleCnt;
builder.finish();
GrTexture* texture = textureProvider->findAndRefTextureByUniqueKey(key);
if (!texture) {
texture = textureProvider->createTexture(texDesc, true);
if (texture) {
textureProvider->assignUniqueKeyToTexture(key, texture);
}
}
return texture ? texture->asRenderTarget() : nullptr;
}
示例3: createTexture
GrTexture* GrGpu::createTexture(const GrTextureDesc& desc,
const void* srcData, size_t rowBytes) {
this->handleDirtyContext();
GrTexture* tex = this->onCreateTexture(desc, srcData, rowBytes);
if (NULL != tex &&
(kRenderTarget_GrTextureFlagBit & desc.fFlags) &&
!(kNoStencil_GrTextureFlagBit & desc.fFlags)) {
GrAssert(NULL != tex->asRenderTarget());
// TODO: defer this and attach dynamically
if (!this->attachStencilBufferToRenderTarget(tex->asRenderTarget())) {
tex->unref();
return NULL;
}
}
return tex;
}
示例4: create_mask_GPU
// Create a mask of 'devPath' and place the result in 'mask'.
static GrTexture* create_mask_GPU(GrContext* context,
const SkRect& maskRect,
const SkPath& devPath,
const GrStrokeInfo& strokeInfo,
bool doAA,
int sampleCnt) {
GrSurfaceDesc desc;
desc.fFlags = kRenderTarget_GrSurfaceFlag;
desc.fWidth = SkScalarCeilToInt(maskRect.width());
desc.fHeight = SkScalarCeilToInt(maskRect.height());
desc.fSampleCnt = doAA ? sampleCnt : 0;
// We actually only need A8, but it often isn't supported as a
// render target so default to RGBA_8888
desc.fConfig = kRGBA_8888_GrPixelConfig;
if (context->caps()->isConfigRenderable(kAlpha_8_GrPixelConfig, desc.fSampleCnt > 0)) {
desc.fConfig = kAlpha_8_GrPixelConfig;
}
GrTexture* mask = context->textureProvider()->createApproxTexture(desc);
if (nullptr == mask) {
return nullptr;
}
SkRect clipRect = SkRect::MakeWH(maskRect.width(), maskRect.height());
GrDrawContext* drawContext = context->drawContext();
if (!drawContext) {
return nullptr;
}
drawContext->clear(mask->asRenderTarget(), nullptr, 0x0, true);
GrPaint tempPaint;
tempPaint.setAntiAlias(doAA);
tempPaint.setCoverageSetOpXPFactory(SkRegion::kReplace_Op);
// setup new clip
GrClip clip(clipRect);
// Draw the mask into maskTexture with the path's top-left at the origin using tempPaint.
SkMatrix translate;
translate.setTranslate(-maskRect.fLeft, -maskRect.fTop);
drawContext->drawPath(mask->asRenderTarget(), clip, tempPaint, translate, devPath, strokeInfo);
return mask;
}
示例5: checkDraw
bool GrDrawTarget::checkDraw(GrPrimitiveType type, int startVertex,
int startIndex, int vertexCount,
int indexCount) const {
const GrDrawState& drawState = this->getDrawState();
#if GR_DEBUG
const GeometrySrcState& geoSrc = fGeoSrcStateStack.back();
int maxVertex = startVertex + vertexCount;
int maxValidVertex;
switch (geoSrc.fVertexSrc) {
case kNone_GeometrySrcType:
GrCrash("Attempting to draw without vertex src.");
case kReserved_GeometrySrcType: // fallthrough
case kArray_GeometrySrcType:
maxValidVertex = geoSrc.fVertexCount;
break;
case kBuffer_GeometrySrcType:
maxValidVertex = geoSrc.fVertexBuffer->sizeInBytes() / VertexSize(geoSrc.fVertexLayout);
break;
}
if (maxVertex > maxValidVertex) {
GrCrash("Drawing outside valid vertex range.");
}
if (indexCount > 0) {
int maxIndex = startIndex + indexCount;
int maxValidIndex;
switch (geoSrc.fIndexSrc) {
case kNone_GeometrySrcType:
GrCrash("Attempting to draw indexed geom without index src.");
case kReserved_GeometrySrcType: // fallthrough
case kArray_GeometrySrcType:
maxValidIndex = geoSrc.fIndexCount;
break;
case kBuffer_GeometrySrcType:
maxValidIndex = geoSrc.fIndexBuffer->sizeInBytes() / sizeof(uint16_t);
break;
}
if (maxIndex > maxValidIndex) {
GrCrash("Index reads outside valid index range.");
}
}
GrAssert(NULL != drawState.getRenderTarget());
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
if (drawState.isStageEnabled(s)) {
const GrEffect* effect = drawState.getStage(s).getEffect();
int numTextures = effect->numTextures();
for (int t = 0; t < numTextures; ++t) {
GrTexture* texture = effect->texture(t);
GrAssert(texture->asRenderTarget() != drawState.getRenderTarget());
}
}
}
#endif
if (NULL == drawState.getRenderTarget()) {
return false;
}
return true;
}
示例6: copyToTexturePixelRef
static SkGrPixelRef* copyToTexturePixelRef(GrTexture* texture, const SkIRect* subset) {
if (NULL == texture) {
return NULL;
}
GrContext* context = texture->getContext();
if (NULL == context) {
return NULL;
}
GrTextureDesc desc;
SkIPoint pointStorage;
SkIPoint* topLeft;
if (subset != NULL) {
SkASSERT(SkIRect::MakeWH(texture->width(), texture->height()).contains(*subset));
// Create a new texture that is the size of subset.
desc.fWidth = subset->width();
desc.fHeight = subset->height();
pointStorage.set(subset->x(), subset->y());
topLeft = &pointStorage;
} else {
desc.fWidth = texture->width();
desc.fHeight = texture->height();
topLeft = NULL;
}
desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit;
desc.fConfig = texture->config();
SkImageInfo info;
if (!GrPixelConfig2ColorType(desc.fConfig, &info.fColorType)) {
return NULL;
}
info.fWidth = desc.fWidth;
info.fHeight = desc.fHeight;
info.fAlphaType = kPremul_SkAlphaType;
GrTexture* dst = context->createUncachedTexture(desc, NULL, 0);
if (NULL == dst) {
return NULL;
}
context->copyTexture(texture, dst->asRenderTarget(), topLeft);
// TODO: figure out if this is responsible for Chrome canvas errors
#if 0
// The render texture we have created (to perform the copy) isn't fully
// functional (since it doesn't have a stencil buffer). Release it here
// so the caller doesn't try to render to it.
// TODO: we can undo this release when dynamic stencil buffer attach/
// detach has been implemented
dst->releaseRenderTarget();
#endif
SkGrPixelRef* pixelRef = SkNEW_ARGS(SkGrPixelRef, (info, dst));
SkSafeUnref(dst);
return pixelRef;
}
示例7: create_mask_GPU
// Create a mask of 'devPath' and place the result in 'mask'.
static GrTexture* create_mask_GPU(GrContext* context,
SkRect* maskRect,
const SkPath& devPath,
const GrStrokeInfo& strokeInfo,
bool doAA,
int sampleCnt) {
// This mask will ultimately be drawn as a non-AA rect (see draw_mask).
// Non-AA rects have a bad habit of snapping arbitrarily. Integerize here
// so the mask draws in a reproducible manner.
*maskRect = SkRect::Make(maskRect->roundOut());
GrSurfaceDesc desc;
desc.fFlags = kRenderTarget_GrSurfaceFlag;
desc.fWidth = SkScalarCeilToInt(maskRect->width());
desc.fHeight = SkScalarCeilToInt(maskRect->height());
desc.fSampleCnt = doAA ? sampleCnt : 0;
// We actually only need A8, but it often isn't supported as a
// render target so default to RGBA_8888
desc.fConfig = kRGBA_8888_GrPixelConfig;
if (context->caps()->isConfigRenderable(kAlpha_8_GrPixelConfig, desc.fSampleCnt > 0)) {
desc.fConfig = kAlpha_8_GrPixelConfig;
}
GrTexture* mask = context->textureProvider()->createApproxTexture(desc);
if (nullptr == mask) {
return nullptr;
}
SkRect clipRect = SkRect::MakeWH(maskRect->width(), maskRect->height());
SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(mask->asRenderTarget()));
if (!drawContext) {
return nullptr;
}
drawContext->clear(nullptr, 0x0, true);
GrPaint tempPaint;
tempPaint.setAntiAlias(doAA);
tempPaint.setCoverageSetOpXPFactory(SkRegion::kReplace_Op);
// setup new clip
GrClip clip(clipRect);
// Draw the mask into maskTexture with the path's integerized top-left at
// the origin using tempPaint.
SkMatrix translate;
translate.setTranslate(-maskRect->fLeft, -maskRect->fTop);
drawContext->drawPath(clip, tempPaint, translate, devPath, strokeInfo);
return mask;
}
示例8: createPlatformTexture
GrTexture* GrGpu::createPlatformTexture(const GrPlatformTextureDesc& desc) {
this->handleDirtyContext();
GrTexture* tex = this->onCreatePlatformTexture(desc);
// TODO: defer this and attach dynamically
GrRenderTarget* tgt = tex->asRenderTarget();
if (NULL != tgt &&
!this->attachStencilBufferToRenderTarget(tgt)) {
tex->unref();
return NULL;
} else {
return tex;
}
}
示例9: createTexture
GrTexture* GrGpu::createTexture(const GrTextureDesc& desc,
const void* srcData, size_t rowBytes) {
if (!this->caps()->isConfigTexturable(desc.fConfig)) {
return NULL;
}
if ((desc.fFlags & kRenderTarget_GrTextureFlagBit) &&
!this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
return NULL;
}
GrTexture *tex = NULL;
if (GrPixelConfigIsCompressed(desc.fConfig)) {
// We shouldn't be rendering into this
SkASSERT((desc.fFlags & kRenderTarget_GrTextureFlagBit) == 0);
if (!this->caps()->npotTextureTileSupport() &&
(!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight))) {
return NULL;
}
this->handleDirtyContext();
tex = this->onCreateCompressedTexture(desc, srcData);
} else {
this->handleDirtyContext();
tex = this->onCreateTexture(desc, srcData, rowBytes);
if (tex &&
(kRenderTarget_GrTextureFlagBit & desc.fFlags) &&
!(kNoStencil_GrTextureFlagBit & desc.fFlags)) {
SkASSERT(tex->asRenderTarget());
// TODO: defer this and attach dynamically
if (!this->attachStencilBufferToRenderTarget(tex->asRenderTarget())) {
tex->unref();
return NULL;
}
}
}
return tex;
}
示例10: wrapBackendTexture
GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc, GrWrapOwnership ownership) {
this->handleDirtyContext();
GrTexture* tex = this->onWrapBackendTexture(desc, ownership);
if (NULL == tex) {
return NULL;
}
// TODO: defer this and attach dynamically
GrRenderTarget* tgt = tex->asRenderTarget();
if (tgt && !this->attachStencilAttachmentToRenderTarget(tgt)) {
tex->unref();
return NULL;
} else {
return tex;
}
}
示例11: createTexture
GrTexture* GrGpu::createTexture(const GrTextureDesc& desc,
const void* srcData, size_t rowBytes) {
if (kUnknown_GrPixelConfig == desc.fConfig) {
return NULL;
}
if ((desc.fFlags & kRenderTarget_GrTextureFlagBit) &&
!this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
return NULL;
}
this->handleDirtyContext();
GrTexture* tex = this->onCreateTexture(desc, srcData, rowBytes);
if (NULL != tex &&
(kRenderTarget_GrTextureFlagBit & desc.fFlags) &&
!(kNoStencil_GrTextureFlagBit & desc.fFlags)) {
SkASSERT(NULL != tex->asRenderTarget());
// TODO: defer this and attach dynamically
if (!this->attachStencilBufferToRenderTarget(tex->asRenderTarget())) {
tex->unref();
return NULL;
}
}
return tex;
}
示例12: copy_to_new_texture_pixelref
static SkGrPixelRef* copy_to_new_texture_pixelref(GrTexture* texture, SkColorType dstCT,
SkColorProfileType dstPT, const SkIRect* subset) {
if (NULL == texture || kUnknown_SkColorType == dstCT) {
return NULL;
}
GrContext* context = texture->getContext();
if (NULL == context) {
return NULL;
}
GrSurfaceDesc desc;
SkIRect srcRect;
if (!subset) {
desc.fWidth = texture->width();
desc.fHeight = texture->height();
srcRect = SkIRect::MakeWH(texture->width(), texture->height());
} else {
SkASSERT(SkIRect::MakeWH(texture->width(), texture->height()).contains(*subset));
// Create a new texture that is the size of subset.
desc.fWidth = subset->width();
desc.fHeight = subset->height();
srcRect = *subset;
}
desc.fFlags = kRenderTarget_GrSurfaceFlag;
desc.fConfig = SkImageInfo2GrPixelConfig(dstCT, kPremul_SkAlphaType, dstPT);
GrTexture* dst = context->createTexture(desc, false, NULL, 0);
if (NULL == dst) {
return NULL;
}
// Blink is relying on the above copy being sent to GL immediately in the case when the source
// is a WebGL canvas backing store. We could have a TODO to remove this flush flag, but we have
// a larger TODO to remove SkGrPixelRef entirely.
context->copySurface(dst->asRenderTarget(), texture, srcRect, SkIPoint::Make(0,0),
GrContext::kFlushWrites_PixelOp);
SkImageInfo info = SkImageInfo::Make(desc.fWidth, desc.fHeight, dstCT, kPremul_SkAlphaType,
dstPT);
SkGrPixelRef* pixelRef = SkNEW_ARGS(SkGrPixelRef, (info, dst));
SkSafeUnref(dst);
return pixelRef;
}
示例13: wrapBackendTexture
GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc, GrWrapOwnership ownership) {
this->handleDirtyContext();
if (!this->caps()->isConfigTexturable(desc.fConfig)) {
return nullptr;
}
if ((desc.fFlags & kRenderTarget_GrBackendTextureFlag) &&
!this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
return nullptr;
}
GrTexture* tex = this->onWrapBackendTexture(desc, ownership);
if (nullptr == tex) {
return nullptr;
}
// TODO: defer this and attach dynamically
GrRenderTarget* tgt = tex->asRenderTarget();
if (tgt && !fContext->resourceProvider()->attachStencilAttachment(tgt)) {
tex->unref();
return nullptr;
} else {
return tex;
}
}
示例14: createAlphaClipMask
////////////////////////////////////////////////////////////////////////////////
// Create a 8-bit clip mask in alpha
GrTexture* GrClipMaskManager::createAlphaClipMask(int32_t clipStackGenID,
InitialState initialState,
const ElementList& elements,
const SkIRect& clipSpaceIBounds) {
GrAssert(kNone_ClipMaskType == fCurrClipMaskType);
GrTexture* result;
if (this->getMaskTexture(clipStackGenID, clipSpaceIBounds, &result)) {
fCurrClipMaskType = kAlpha_ClipMaskType;
return result;
}
if (NULL == result) {
fAACache.reset();
return NULL;
}
GrDrawTarget::AutoGeometryAndStatePush agasp(fGpu, GrDrawTarget::kReset_ASRInit);
GrDrawState* drawState = fGpu->drawState();
// The top-left of the mask corresponds to the top-left corner of the bounds.
SkVector clipToMaskOffset = {
SkIntToScalar(-clipSpaceIBounds.fLeft),
SkIntToScalar(-clipSpaceIBounds.fTop)
};
// 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());
// We're drawing a coverage mask and want coverage to be run through the blend function.
drawState->enableState(GrDrawState::kCoverageDrawing_StateBit);
// Set the matrix so that rendered clip elements are transformed to mask space from clip space.
drawState->viewMatrix()->setTranslate(clipToMaskOffset);
// The scratch texture that we are drawing into can be substantially larger than the mask. Only
// clear the part that we care about.
fGpu->clear(&maskSpaceIBounds,
kAllIn_InitialState == initialState ? 0xffffffff : 0x00000000,
result->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.
GrDrawTarget::AutoClipRestore acr(fGpu, maskSpaceIBounds);
drawState->enableState(GrDrawState::kClip_StateBit);
GrAutoScratchTexture temp;
// walk through each clip element and perform its set op
for (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) {
GrPathRenderer* pr = NULL;
bool useTemp = !this->canStencilAndDrawElement(result, element, &pr);
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.
GrIRect maskSpaceElementIBounds;
if (useTemp) {
if (invert) {
maskSpaceElementIBounds = maskSpaceIBounds;
} else {
GrRect elementBounds = element->getBounds();
elementBounds.offset(clipToMaskOffset);
elementBounds.roundOut(&maskSpaceElementIBounds);
}
this->getTemp(maskSpaceIBounds.fRight, maskSpaceIBounds.fBottom, &temp);
if (NULL == temp.texture()) {
fAACache.reset();
return NULL;
}
dst = temp.texture();
// clear the temp target and set blend to replace
fGpu->clear(&maskSpaceElementIBounds,
invert ? 0xffffffff : 0x00000000,
dst->asRenderTarget());
setup_boolean_blendcoeffs(drawState, SkRegion::kReplace_Op);
} else {
// draw directly into the result with the stencil set to make the pixels affected
// by the clip shape be non-zero.
dst = result;
GR_STATIC_CONST_SAME_STENCIL(kStencilInElement,
kReplace_StencilOp,
kReplace_StencilOp,
kAlways_StencilFunc,
0xffff,
0xffff,
0xffff);
drawState->setStencil(kStencilInElement);
//.........这里部分代码省略.........
示例15: 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());
//.........这里部分代码省略.........