aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Robert Phillips <robertphillips@google.com>2016-11-14 13:23:15 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2016-11-15 15:05:37 +0000
commitfd01ce05ef7902c49b0272b3524a389693c72b35 (patch)
treee125464b9dff5c2b81e83c3b0ccde65606986b45 /src
parentaf49b19582f1f7a55e1300647804212252315b8a (diff)
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>
Diffstat (limited to 'src')
-rw-r--r--src/core/SkBlurImageFilter.cpp11
-rw-r--r--src/core/SkGpuBlurUtils.cpp15
-rw-r--r--src/core/SkImageFilter.cpp12
-rw-r--r--src/effects/SkAlphaThresholdFilter.cpp37
-rw-r--r--src/effects/SkBlurMaskFilter.cpp6
-rw-r--r--src/gpu/GrBlurUtils.cpp38
-rw-r--r--src/gpu/GrContext.cpp17
7 files changed, 84 insertions, 52 deletions
diff --git a/src/core/SkBlurImageFilter.cpp b/src/core/SkBlurImageFilter.cpp
index d531b44393..0713055245 100644
--- a/src/core/SkBlurImageFilter.cpp
+++ b/src/core/SkBlurImageFilter.cpp
@@ -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
diff --git a/src/core/SkGpuBlurUtils.cpp b/src/core/SkGpuBlurUtils.cpp
index 8107642783..1236e2bf18 100644
--- a/src/core/SkGpuBlurUtils.cpp
+++ b/src/core/SkGpuBlurUtils.cpp
@@ -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);
diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp
index 09c26d387e..df46a13d3c 100644
--- a/src/core/SkImageFilter.cpp
+++ b/src/core/SkImageFilter.cpp
@@ -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
diff --git a/src/effects/SkAlphaThresholdFilter.cpp b/src/effects/SkAlphaThresholdFilter.cpp
index b1c8b21460..abf924ca06 100644
--- a/src/effects/SkAlphaThresholdFilter.cpp
+++ b/src/effects/SkAlphaThresholdFilter.cpp
@@ -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;
}
diff --git a/src/effects/SkBlurMaskFilter.cpp b/src/effects/SkBlurMaskFilter.cpp
index 0a98fa8c3a..4dcd022be0 100644
--- a/src/effects/SkBlurMaskFilter.cpp
+++ b/src/effects/SkBlurMaskFilter.cpp
@@ -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));
diff --git a/src/gpu/GrBlurUtils.cpp b/src/gpu/GrBlurUtils.cpp
index 58d12af178..d31a7a7fba 100644
--- a/src/gpu/GrBlurUtils.cpp
+++ b/src/gpu/GrBlurUtils.cpp
@@ -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)) {
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 71203d6442..d7c66a0b5d 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -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,