aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/SkBlurImageFilter.cpp11
-rw-r--r--src/core/SkGpuBlurUtils.cpp24
-rw-r--r--src/core/SkImageFilter.cpp12
-rw-r--r--src/effects/SkAlphaThresholdFilter.cpp44
-rw-r--r--src/effects/SkBlurMaskFilter.cpp12
-rw-r--r--src/gpu/GrBlurUtils.cpp44
-rw-r--r--src/gpu/GrContext.cpp17
7 files changed, 108 insertions, 56 deletions
diff --git a/src/core/SkBlurImageFilter.cpp b/src/core/SkBlurImageFilter.cpp
index 7590fdcc57..7d51a364d5 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));
@@ -167,9 +168,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 84cc8d8d14..f210178cef 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);
@@ -292,6 +294,9 @@ sk_sp<GrRenderTargetContext> GaussianBlur(GrContext* context,
srcRenderTargetContext = dstRenderTargetContext;
srcRect = dstRect;
srcTexture = srcRenderTargetContext->asTexture();
+ if (!srcTexture) {
+ return nullptr;
+ }
dstRenderTargetContext.swap(tmpRenderTargetContext);
localSrcBounds = srcRect;
}
@@ -314,6 +319,9 @@ sk_sp<GrRenderTargetContext> GaussianBlur(GrContext* context,
srcBounds, srcOffset);
srcRenderTargetContext = dstRenderTargetContext;
srcTexture = srcRenderTargetContext->asTexture();
+ if (!srcTexture) {
+ return nullptr;
+ }
srcRect.offsetTo(0, 0);
dstRenderTargetContext.swap(tmpRenderTargetContext);
localSrcBounds = srcRect;
@@ -350,14 +358,20 @@ 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.
GrSamplerParams params(SkShader::kClamp_TileMode, GrSamplerParams::kBilerp_FilterMode);
sk_sp<GrTexture> tex(srcRenderTargetContext->asTexture());
+ if (!tex) {
+ return nullptr;
+ }
+
+ // 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..43751e1199 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,21 +161,26 @@ 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));
- if (!maskTexture) {
+ sk_sp<GrTextureProxy> maskProxy(this->createMaskTexture(context, matrix, bounds));
+ if (!maskProxy) {
return nullptr;
}
const OutputProperties& outProps = ctx.outputProperties();
sk_sp<GrColorSpaceXform> colorSpaceXform = GrColorSpaceXform::Make(input->getColorSpace(),
outProps.colorSpace());
+
+ GrTexture* maskTex = maskProxy->instantiate(context->textureProvider());
+ if (!maskTex) {
+ return nullptr;
+ }
sk_sp<GrFragmentProcessor> fp(GrAlphaThresholdFragmentProcessor::Make(
- inputTexture.get(),
- std::move(colorSpaceXform),
- maskTexture.get(),
- fInnerThreshold,
- fOuterThreshold,
- bounds));
+ inputTexture.get(),
+ std::move(colorSpaceXform),
+ maskTex,
+ fInnerThreshold,
+ fOuterThreshold,
+ bounds));
if (!fp) {
return nullptr;
}
diff --git a/src/effects/SkBlurMaskFilter.cpp b/src/effects/SkBlurMaskFilter.cpp
index 92911bc9ee..237c5630e2 100644
--- a/src/effects/SkBlurMaskFilter.cpp
+++ b/src/effects/SkBlurMaskFilter.cpp
@@ -1121,7 +1121,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;
@@ -1141,8 +1141,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));
@@ -1151,7 +1151,9 @@ static sk_sp<GrTexture> find_or_create_rrect_blur_mask(GrContext* context,
}
mask = rtc2->asTexture();
- SkASSERT(mask);
+ if (!mask) {
+ return nullptr;
+ }
context->textureProvider()->assignUniqueKeyToTexture(key, mask.get());
}
@@ -1539,7 +1541,7 @@ bool SkBlurMaskFilterImpl::filterMaskGPU(GrTexture* src,
}
*result = renderTargetContext->asTexture().release();
- return true;
+ return SkToBool(*result);
}
#endif // SK_SUPPORT_GPU
diff --git a/src/gpu/GrBlurUtils.cpp b/src/gpu/GrBlurUtils.cpp
index 58d12af178..97fa623e2f 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,21 @@ 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()));
- if (mask) {
+ sk_sp<GrTextureProxy> maskProxy(create_mask_GPU(context,
+ finalIRect,
+ *path,
+ fillOrHairline,
+ paint->isAntiAlias(),
+ renderTargetContext->numColorSamples()));
+ if (maskProxy) {
GrTexture* filtered;
- if (maskFilter->filterMaskGPU(mask.get(), viewMatrix, finalIRect, &filtered)) {
+ GrTexture* mask = maskProxy->instantiate(context->textureProvider());
+ if (!mask) {
+ return;
+ }
+
+ if (maskFilter->filterMaskGPU(mask, 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 4994ae04c3..1a5ee20721 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -748,6 +748,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,