Defer more renderTargetContexts in the GPU image filter paths

GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4767

Change-Id: I4c1f27247ef340a49d1ac96761810e77e6047ca2
Reviewed-on: https://skia-review.googlesource.com/4767
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Robert Phillips 2016-11-14 13:23:15 -05:00 committed by Skia Commit-Bot
parent af49b19582
commit fd01ce05ef
8 changed files with 98 additions and 53 deletions

View File

@ -197,7 +197,8 @@ public:
// Create a new render target context as above but have it backed by a deferred-style
// GrRenderTargetProxy rather than one that is backed by an actual GrRenderTarget
sk_sp<GrRenderTargetContext> makeDeferredRenderTargetContext(SkBackingFit fit,
sk_sp<GrRenderTargetContext> makeDeferredRenderTargetContext(
SkBackingFit fit,
int width, int height,
GrPixelConfig config,
sk_sp<SkColorSpace> colorSpace,
@ -221,6 +222,18 @@ public:
const SkSurfaceProps* surfaceProps = nullptr,
SkBudgeted budgeted = SkBudgeted::kYes);
// Create a new render target context as above but have it backed by a deferred-style
// GrRenderTargetProxy rather than one that is backed by an actual GrRenderTarget
sk_sp<GrRenderTargetContext> makeDeferredRenderTargetContextWithFallback(
SkBackingFit fit,
int width, int height,
GrPixelConfig config,
sk_sp<SkColorSpace> colorSpace,
int sampleCnt = 0,
GrSurfaceOrigin origin = kDefault_GrSurfaceOrigin,
const SkSurfaceProps* surfaceProps = nullptr,
SkBudgeted budgeted = SkBudgeted::kYes);
///////////////////////////////////////////////////////////////////////////
// Misc.

View File

@ -15,6 +15,7 @@
#if SK_SUPPORT_GPU
#include "GrContext.h"
#include "GrTextureProxy.h"
#include "SkGr.h"
#endif
@ -110,8 +111,8 @@ static void get_box3_params(SkScalar s, int *kernelSize, int* kernelSize3, int *
}
sk_sp<SkSpecialImage> SkBlurImageFilterImpl::onFilterImage(SkSpecialImage* source,
const Context& ctx,
SkIPoint* offset) const {
const Context& ctx,
SkIPoint* offset) const {
SkIPoint inputOffset = SkIPoint::Make(0, 0);
sk_sp<SkSpecialImage> input(this->filterInput(0, source, ctx, &inputOffset));
@ -165,9 +166,11 @@ sk_sp<SkSpecialImage> SkBlurImageFilterImpl::onFilterImage(SkSpecialImage* sourc
}
// TODO: Get the colorSpace from the renderTargetContext (once it has one)
return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(dstBounds.width(), dstBounds.height()),
return SkSpecialImage::MakeDeferredFromGpu(
context,
SkIRect::MakeWH(dstBounds.width(), dstBounds.height()),
kNeedNewImageUniqueID_SpecialImage,
renderTargetContext->asTexture(),
sk_ref_sp(renderTargetContext->asDeferredTexture()),
sk_ref_sp(input->getColorSpace()), &source->props());
}
#endif

View File

@ -229,7 +229,7 @@ sk_sp<GrRenderTargetContext> GaussianBlur(GrContext* context,
const int height = dstBounds.height();
const GrPixelConfig config = srcTexture->config();
sk_sp<GrRenderTargetContext> dstRenderTargetContext(context->makeRenderTargetContext(
sk_sp<GrRenderTargetContext> dstRenderTargetContext(context->makeDeferredRenderTargetContext(
fit, width, height, config, colorSpace, 0, kDefault_GrSurfaceOrigin));
if (!dstRenderTargetContext) {
return nullptr;
@ -248,7 +248,7 @@ sk_sp<GrRenderTargetContext> GaussianBlur(GrContext* context,
return dstRenderTargetContext;
}
sk_sp<GrRenderTargetContext> tmpRenderTargetContext(context->makeRenderTargetContext(
sk_sp<GrRenderTargetContext> tmpRenderTargetContext(context->makeDeferredRenderTargetContext(
fit, width, height, config, colorSpace, 0, kDefault_GrSurfaceOrigin));
if (!tmpRenderTargetContext) {
return nullptr;
@ -261,6 +261,8 @@ sk_sp<GrRenderTargetContext> GaussianBlur(GrContext* context,
for (int i = 1; i < scaleFactorX || i < scaleFactorY; i *= 2) {
GrPaint paint;
paint.setGammaCorrect(dstRenderTargetContext->isGammaCorrect());
// TODO: this matrix relies on the final instantiated size of the texture. This
// will have to be deferred for TextureProxys
SkMatrix matrix;
matrix.setIDiv(srcTexture->width(), srcTexture->height());
SkIRect dstRect(srcRect);
@ -350,14 +352,17 @@ sk_sp<GrRenderTargetContext> GaussianBlur(GrContext* context,
clearRect = SkIRect::MakeXYWH(srcRect.fRight, srcRect.fTop, 1, srcRect.height());
srcRenderTargetContext->clear(&clearRect, 0x0, false);
SkMatrix matrix;
matrix.setIDiv(srcRenderTargetContext->width(), srcRenderTargetContext->height());
GrPaint paint;
paint.setGammaCorrect(dstRenderTargetContext->isGammaCorrect());
// FIXME: this should be mitchell, not bilinear.
GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kBilerp_FilterMode);
sk_sp<GrTexture> tex(srcRenderTargetContext->asTexture());
// TODO: this matrix relies on the final instantiated size of the texture. This
// will have to be deferred for TextureProxys
SkMatrix matrix;
matrix.setIDiv(tex->width(), tex->height());
paint.addColorTextureProcessor(tex.get(), nullptr, matrix, params);
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);

View File

@ -20,8 +20,9 @@
#include "SkWriteBuffer.h"
#if SK_SUPPORT_GPU
#include "GrContext.h"
#include "GrRenderTargetContext.h"
#include "GrFixedClip.h"
#include "GrRenderTargetContext.h"
#include "GrTextureProxy.h"
#include "SkGrPriv.h"
#endif
@ -285,7 +286,7 @@ sk_sp<SkSpecialImage> SkImageFilter::DrawWithFP(GrContext* context,
sk_sp<SkColorSpace> colorSpace = sk_ref_sp(outputProperties.colorSpace());
GrPixelConfig config = GrRenderableConfigForColorSpace(colorSpace.get());
sk_sp<GrRenderTargetContext> renderTargetContext(context->makeRenderTargetContext(
sk_sp<GrRenderTargetContext> renderTargetContext(context->makeDeferredRenderTargetContext(
SkBackingFit::kApprox, bounds.width(), bounds.height(), config, std::move(colorSpace)));
if (!renderTargetContext) {
return nullptr;
@ -298,9 +299,10 @@ sk_sp<SkSpecialImage> SkImageFilter::DrawWithFP(GrContext* context,
GrFixedClip clip(dstIRect);
renderTargetContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRect, srcRect);
return SkSpecialImage::MakeFromGpu(dstIRect, kNeedNewImageUniqueID_SpecialImage,
renderTargetContext->asTexture(),
sk_ref_sp(renderTargetContext->getColorSpace()));
return SkSpecialImage::MakeDeferredFromGpu(context, dstIRect,
kNeedNewImageUniqueID_SpecialImage,
sk_ref_sp(renderTargetContext->asDeferredTexture()),
sk_ref_sp(renderTargetContext->getColorSpace()));
}
#endif

View File

@ -16,8 +16,9 @@
#if SK_SUPPORT_GPU
#include "GrAlphaThresholdFragmentProcessor.h"
#include "GrContext.h"
#include "GrRenderTargetContext.h"
#include "GrFixedClip.h"
#include "GrRenderTargetContext.h"
#include "GrTextureProxy.h"
#endif
class SK_API SkAlphaThresholdFilterImpl : public SkImageFilter {
@ -37,7 +38,9 @@ protected:
SkIPoint* offset) const override;
#if SK_SUPPORT_GPU
sk_sp<GrTexture> createMaskTexture(GrContext*, const SkMatrix&, const SkIRect& bounds) const;
sk_sp<GrTextureProxy> createMaskTexture(GrContext*,
const SkMatrix&,
const SkIRect& bounds) const;
#endif
private:
@ -93,29 +96,29 @@ SkAlphaThresholdFilterImpl::SkAlphaThresholdFilterImpl(const SkRegion& region,
}
#if SK_SUPPORT_GPU
sk_sp<GrTexture> SkAlphaThresholdFilterImpl::createMaskTexture(GrContext* context,
const SkMatrix& inMatrix,
const SkIRect& bounds) const {
sk_sp<GrTextureProxy> SkAlphaThresholdFilterImpl::createMaskTexture(GrContext* context,
const SkMatrix& inMatrix,
const SkIRect& bounds) const {
sk_sp<GrRenderTargetContext> renderTargetContext(context->makeRenderTargetContextWithFallback(
sk_sp<GrRenderTargetContext> rtContext(context->makeDeferredRenderTargetContextWithFallback(
SkBackingFit::kApprox, bounds.width(), bounds.height(), kAlpha_8_GrPixelConfig, nullptr));
if (!renderTargetContext) {
if (!rtContext) {
return nullptr;
}
GrPaint grPaint;
grPaint.setPorterDuffXPFactory(SkBlendMode::kSrc);
SkRegion::Iterator iter(fRegion);
renderTargetContext->clear(nullptr, 0x0, true);
rtContext->clear(nullptr, 0x0, true);
GrFixedClip clip(SkIRect::MakeWH(bounds.width(), bounds.height()));
while (!iter.done()) {
SkRect rect = SkRect::Make(iter.rect());
renderTargetContext->drawRect(clip, grPaint, inMatrix, rect);
rtContext->drawRect(clip, grPaint, inMatrix, rect);
iter.next();
}
return renderTargetContext->asTexture();
return sk_ref_sp(rtContext->asDeferredTexture());
}
#endif
@ -158,7 +161,7 @@ sk_sp<SkSpecialImage> SkAlphaThresholdFilterImpl::onFilterImage(SkSpecialImage*
SkMatrix matrix(ctx.ctm());
matrix.postTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.top()));
sk_sp<GrTexture> maskTexture(this->createMaskTexture(context, matrix, bounds));
sk_sp<GrTextureProxy> maskTexture(this->createMaskTexture(context, matrix, bounds));
if (!maskTexture) {
return nullptr;
}
@ -167,12 +170,12 @@ sk_sp<SkSpecialImage> SkAlphaThresholdFilterImpl::onFilterImage(SkSpecialImage*
sk_sp<GrColorSpaceXform> colorSpaceXform = GrColorSpaceXform::Make(input->getColorSpace(),
outProps.colorSpace());
sk_sp<GrFragmentProcessor> fp(GrAlphaThresholdFragmentProcessor::Make(
inputTexture.get(),
std::move(colorSpaceXform),
maskTexture.get(),
fInnerThreshold,
fOuterThreshold,
bounds));
inputTexture.get(),
std::move(colorSpaceXform),
maskTexture->instantiate(context->textureProvider()),
fInnerThreshold,
fOuterThreshold,
bounds));
if (!fp) {
return nullptr;
}

View File

@ -1122,7 +1122,7 @@ static sk_sp<GrTexture> find_or_create_rrect_blur_mask(GrContext* context,
sk_sp<GrTexture> mask(context->textureProvider()->findAndRefTextureByUniqueKey(key));
if (!mask) {
// TODO: this could be approx but the texture coords will need to be updated
sk_sp<GrRenderTargetContext> rtc(context->makeRenderTargetContextWithFallback(
sk_sp<GrRenderTargetContext> rtc(context->makeDeferredRenderTargetContextWithFallback(
SkBackingFit::kExact, size.fWidth, size.fHeight, kAlpha_8_GrPixelConfig, nullptr));
if (!rtc) {
return nullptr;
@ -1139,8 +1139,8 @@ static sk_sp<GrTexture> find_or_create_rrect_blur_mask(GrContext* context,
srcTexture.get(),
nullptr,
SkIRect::MakeWH(
size.fWidth,
size.fHeight),
size.fWidth,
size.fHeight),
nullptr,
xformedSigma, xformedSigma,
SkBackingFit::kExact));

View File

@ -13,6 +13,7 @@
#include "effects/GrSimpleTextureEffect.h"
#include "GrStyle.h"
#include "GrTexture.h"
#include "GrTextureProxy.h"
#include "GrTextureProvider.h"
#include "SkDraw.h"
#include "SkGrPriv.h"
@ -92,25 +93,25 @@ static bool sw_draw_with_mask_filter(GrRenderTargetContext* renderTargetContext,
}
// Create a mask of 'devPath' and place the result in 'mask'.
static sk_sp<GrTexture> create_mask_GPU(GrContext* context,
const SkIRect& maskRect,
const SkPath& devPath,
SkStrokeRec::InitStyle fillOrHairline,
bool doAA,
int sampleCnt) {
static sk_sp<GrTextureProxy> create_mask_GPU(GrContext* context,
const SkIRect& maskRect,
const SkPath& devPath,
SkStrokeRec::InitStyle fillOrHairline,
bool doAA,
int sampleCnt) {
if (!doAA) {
// Don't need MSAA if mask isn't AA
sampleCnt = 0;
}
sk_sp<GrRenderTargetContext> renderTargetContext(context->makeRenderTargetContextWithFallback(
sk_sp<GrRenderTargetContext> rtContext(context->makeDeferredRenderTargetContextWithFallback(
SkBackingFit::kApprox, maskRect.width(), maskRect.height(), kAlpha_8_GrPixelConfig, nullptr,
sampleCnt));
if (!renderTargetContext) {
if (!rtContext) {
return nullptr;
}
renderTargetContext->clear(nullptr, 0x0, true);
rtContext->clear(nullptr, 0x0, true);
GrPaint tempPaint;
tempPaint.setAntiAlias(doAA);
@ -124,8 +125,8 @@ static sk_sp<GrTexture> create_mask_GPU(GrContext* context,
// the origin using tempPaint.
SkMatrix translate;
translate.setTranslate(-SkIntToScalar(maskRect.fLeft), -SkIntToScalar(maskRect.fTop));
renderTargetContext->drawPath(clip, tempPaint, translate, devPath, GrStyle(fillOrHairline));
return renderTargetContext->asTexture();;
rtContext->drawPath(clip, tempPaint, translate, devPath, GrStyle(fillOrHairline));
return sk_ref_sp(rtContext->asDeferredTexture());
}
static void draw_path_with_mask_filter(GrContext* context,
@ -204,16 +205,17 @@ static void draw_path_with_mask_filter(GrContext* context,
return;
}
sk_sp<GrTexture> mask(create_mask_GPU(context,
finalIRect,
*path,
fillOrHairline,
paint->isAntiAlias(),
renderTargetContext->numColorSamples()));
sk_sp<GrTextureProxy> mask(create_mask_GPU(context,
finalIRect,
*path,
fillOrHairline,
paint->isAntiAlias(),
renderTargetContext->numColorSamples()));
if (mask) {
GrTexture* filtered;
if (maskFilter->filterMaskGPU(mask.get(), viewMatrix, finalIRect, &filtered)) {
if (maskFilter->filterMaskGPU(mask->instantiate(context->textureProvider()),
viewMatrix, finalIRect, &filtered)) {
// filterMaskGPU gives us ownership of a ref to the result
sk_sp<GrTexture> atu(filtered);
if (draw_mask(renderTargetContext, clip, viewMatrix, finalIRect, paint, filtered)) {

View File

@ -744,6 +744,23 @@ sk_sp<GrRenderTargetContext> GrContext::makeRenderTargetContextWithFallback(
sampleCnt, origin, surfaceProps, budgeted);
}
sk_sp<GrRenderTargetContext> GrContext::makeDeferredRenderTargetContextWithFallback(
SkBackingFit fit,
int width, int height,
GrPixelConfig config,
sk_sp<SkColorSpace> colorSpace,
int sampleCnt,
GrSurfaceOrigin origin,
const SkSurfaceProps* surfaceProps,
SkBudgeted budgeted) {
if (!this->caps()->isConfigRenderable(config, sampleCnt > 0)) {
config = GrPixelConfigFallback(config);
}
return this->makeDeferredRenderTargetContext(fit, width, height, config, std::move(colorSpace),
sampleCnt, origin, surfaceProps, budgeted);
}
sk_sp<GrRenderTargetContext> GrContext::makeRenderTargetContext(SkBackingFit fit,
int width, int height,
GrPixelConfig config,