diff options
author | Robert Phillips <robertphillips@google.com> | 2017-02-07 11:59:16 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-02-07 21:41:00 +0000 |
commit | e88cf6b7aa5deaeaa9dab18ada7d9d11e1e4be12 (patch) | |
tree | 9b3eef7407120c74dd9e9a7a38579d57ff52fe39 /src | |
parent | 0766e9b55e307eb1db9c683a12b8333833d65247 (diff) |
Remove asTextureRef from SkSpecialImage & update effects accordingly
This CL also renames SkSpecialImage::asTextureProxy to asTextureProxyRef
Change-Id: I5ed8e475bb9688453b825ae4500ed0e8d324b5ac
Reviewed-on: https://skia-review.googlesource.com/7995
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkBlurImageFilter.cpp | 2 | ||||
-rw-r--r-- | src/core/SkSpecialImage.cpp | 33 | ||||
-rw-r--r-- | src/core/SkSpecialImage.h | 9 | ||||
-rw-r--r-- | src/effects/GrAlphaThresholdFragmentProcessor.cpp | 42 | ||||
-rw-r--r-- | src/effects/GrAlphaThresholdFragmentProcessor.h | 33 | ||||
-rw-r--r-- | src/effects/SkAlphaThresholdFilter.cpp | 7 | ||||
-rw-r--r-- | src/effects/SkArithmeticImageFilter.cpp | 14 | ||||
-rw-r--r-- | src/effects/SkDisplacementMapEffect.cpp | 64 | ||||
-rw-r--r-- | src/effects/SkImageSource.cpp | 1 | ||||
-rw-r--r-- | src/effects/SkLightingImageFilter.cpp | 139 | ||||
-rw-r--r-- | src/effects/SkMagnifierImageFilter.cpp | 195 | ||||
-rw-r--r-- | src/effects/SkMatrixConvolutionImageFilter.cpp | 7 | ||||
-rw-r--r-- | src/effects/SkMorphologyImageFilter.cpp | 2 | ||||
-rw-r--r-- | src/effects/SkXfermodeImageFilter.cpp | 24 | ||||
-rw-r--r-- | src/gpu/SkGpuDevice.cpp | 14 | ||||
-rw-r--r-- | src/image/SkImage.cpp | 12 |
16 files changed, 371 insertions, 227 deletions
diff --git a/src/core/SkBlurImageFilter.cpp b/src/core/SkBlurImageFilter.cpp index 71b5cdc82e..462edb545a 100644 --- a/src/core/SkBlurImageFilter.cpp +++ b/src/core/SkBlurImageFilter.cpp @@ -141,7 +141,7 @@ sk_sp<SkSpecialImage> SkBlurImageFilterImpl::onFilterImage(SkSpecialImage* sourc // xform during the filter itself. input = ImageToColorSpace(input.get(), ctx.outputProperties()); - sk_sp<GrTextureProxy> inputTexture(input->asTextureProxy(context)); + sk_sp<GrTextureProxy> inputTexture(input->asTextureProxyRef(context)); if (!inputTexture) { return nullptr; } diff --git a/src/core/SkSpecialImage.cpp b/src/core/SkSpecialImage.cpp index 0ec5459127..b1791c99c2 100644 --- a/src/core/SkSpecialImage.cpp +++ b/src/core/SkSpecialImage.cpp @@ -50,8 +50,7 @@ public: virtual SkColorSpace* onGetColorSpace() const = 0; #if SK_SUPPORT_GPU - virtual sk_sp<GrTexture> onAsTextureRef(GrContext* context) const = 0; - virtual sk_sp<GrTextureProxy> onAsTextureProxy(GrContext* context) const = 0; + virtual sk_sp<GrTextureProxy> onAsTextureProxyRef(GrContext* context) const = 0; #endif virtual sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const = 0; @@ -139,12 +138,8 @@ SkColorSpace* SkSpecialImage::getColorSpace() const { } #if SK_SUPPORT_GPU -sk_sp<GrTexture> SkSpecialImage::asTextureRef(GrContext* context) const { - return as_SIB(this)->onAsTextureRef(context); -} - -sk_sp<GrTextureProxy> SkSpecialImage::asTextureProxy(GrContext* context) const { - return as_SIB(this)->onAsTextureProxy(context); +sk_sp<GrTextureProxy> SkSpecialImage::asTextureProxyRef(GrContext* context) const { + return as_SIB(this)->onAsTextureProxyRef(context); } #endif @@ -242,16 +237,7 @@ public: } #if SK_SUPPORT_GPU - sk_sp<GrTexture> onAsTextureRef(GrContext* context) const override { - if (context) { - return sk_ref_sp(GrRefCachedBitmapTexture(context, fBitmap, - GrSamplerParams::ClampNoFilter(), nullptr)); - } - - return nullptr; - } - - sk_sp<GrTextureProxy> onAsTextureProxy(GrContext* context) const override { + sk_sp<GrTextureProxy> onAsTextureProxyRef(GrContext* context) const override { if (context) { sk_sp<GrTexture> tex(sk_ref_sp(GrRefCachedBitmapTexture( context, fBitmap, GrSamplerParams::ClampNoFilter(), nullptr))); @@ -428,16 +414,7 @@ public: GrContext* onGetContext() const override { return fContext; } - // This entry point should go away in favor of asTextureProxy - sk_sp<GrTexture> onAsTextureRef(GrContext* context) const override { - GrSurface* surf = fSurfaceProxy->instantiate(context->textureProvider()); - if (!surf) { - return nullptr; - } - return sk_ref_sp(surf->asTexture()); - } - - sk_sp<GrTextureProxy> onAsTextureProxy(GrContext*) const override { + sk_sp<GrTextureProxy> onAsTextureProxyRef(GrContext*) const override { return sk_ref_sp(fSurfaceProxy->asTextureProxy()); } diff --git a/src/core/SkSpecialImage.h b/src/core/SkSpecialImage.h index bf168f02af..8ccff0e056 100644 --- a/src/core/SkSpecialImage.h +++ b/src/core/SkSpecialImage.h @@ -136,15 +136,10 @@ public: #if SK_SUPPORT_GPU /** - * Regardless of the underlying backing store, return the contents as a GrTexture. + * Regardless of the underlying backing store, return the contents as a GrTextureProxy. * The active portion of the texture can be retrieved via 'subset'. */ - sk_sp<GrTexture> asTextureRef(GrContext*) const; - - /** - * The same as above but return the contents as a GrTextureProxy. - */ - sk_sp<GrTextureProxy> asTextureProxy(GrContext*) const; + sk_sp<GrTextureProxy> asTextureProxyRef(GrContext*) const; #endif // TODO: hide this whe the imagefilter all have a consistent draw path (see skbug.com/5063) diff --git a/src/effects/GrAlphaThresholdFragmentProcessor.cpp b/src/effects/GrAlphaThresholdFragmentProcessor.cpp index a18fb9c1e9..b83ed779c9 100644 --- a/src/effects/GrAlphaThresholdFragmentProcessor.cpp +++ b/src/effects/GrAlphaThresholdFragmentProcessor.cpp @@ -9,6 +9,7 @@ #if SK_SUPPORT_GPU +#include "GrContext.h" #include "GrInvariantOutput.h" #include "SkRefCnt.h" @@ -18,20 +19,6 @@ #include "glsl/GrGLSLUniformHandler.h" #include "../private/GrGLSL.h" -sk_sp<GrFragmentProcessor> GrAlphaThresholdFragmentProcessor::Make( - GrTexture* texture, - sk_sp<GrColorSpaceXform> colorSpaceXform, - GrTexture* maskTexture, - float innerThreshold, - float outerThreshold, - const SkIRect& bounds) { - return sk_sp<GrFragmentProcessor>(new GrAlphaThresholdFragmentProcessor( - texture, std::move(colorSpaceXform), - maskTexture, - innerThreshold, outerThreshold, - bounds)); -} - inline GrFragmentProcessor::OptimizationFlags GrAlphaThresholdFragmentProcessor::OptFlags(float outerThreshold) { if (outerThreshold >= 1.f) { return kPreservesOpaqueInput_OptimizationFlag | kModulatesInput_OptimizationFlag; @@ -65,6 +52,33 @@ GrAlphaThresholdFragmentProcessor::GrAlphaThresholdFragmentProcessor( this->addTextureSampler(&fMaskTextureSampler); } +GrAlphaThresholdFragmentProcessor::GrAlphaThresholdFragmentProcessor( + GrContext* context, + sk_sp<GrTextureProxy> proxy, + sk_sp<GrColorSpaceXform> colorSpaceXform, + GrTexture* maskTexture, + float innerThreshold, + float outerThreshold, + const SkIRect& bounds) + : INHERITED(OptFlags(outerThreshold)) + , fInnerThreshold(innerThreshold) + , fOuterThreshold(outerThreshold) + , fImageCoordTransform(context, SkMatrix::I(), proxy.get(), + GrSamplerParams::kNone_FilterMode) + , fImageTextureSampler(context->textureProvider(), std::move(proxy)) + , fColorSpaceXform(std::move(colorSpaceXform)) + , fMaskCoordTransform( + SkMatrix::MakeTrans(SkIntToScalar(-bounds.x()), SkIntToScalar(-bounds.y())), + maskTexture, + GrSamplerParams::kNone_FilterMode) + , fMaskTextureSampler(maskTexture) { + this->initClassID<GrAlphaThresholdFragmentProcessor>(); + this->addCoordTransform(&fImageCoordTransform); + this->addTextureSampler(&fImageTextureSampler); + this->addCoordTransform(&fMaskCoordTransform); + this->addTextureSampler(&fMaskTextureSampler); +} + bool GrAlphaThresholdFragmentProcessor::onIsEqual(const GrFragmentProcessor& sBase) const { const GrAlphaThresholdFragmentProcessor& s = sBase.cast<GrAlphaThresholdFragmentProcessor>(); return (this->fInnerThreshold == s.fInnerThreshold && diff --git a/src/effects/GrAlphaThresholdFragmentProcessor.h b/src/effects/GrAlphaThresholdFragmentProcessor.h index f2c14c64bc..bb5aba7ae1 100644 --- a/src/effects/GrAlphaThresholdFragmentProcessor.h +++ b/src/effects/GrAlphaThresholdFragmentProcessor.h @@ -25,7 +25,30 @@ public: GrTexture* maskTexture, float innerThreshold, float outerThreshold, - const SkIRect& bounds); + const SkIRect& bounds) { + return sk_sp<GrFragmentProcessor>(new GrAlphaThresholdFragmentProcessor( + texture, + std::move(colorSpaceXform), + maskTexture, + innerThreshold, outerThreshold, + bounds)); + } + + static sk_sp<GrFragmentProcessor> Make(GrContext* context, + sk_sp<GrTextureProxy> proxy, + sk_sp<GrColorSpaceXform> colorSpaceXform, + GrTexture* maskTexture, + float innerThreshold, + float outerThreshold, + const SkIRect& bounds) { + return sk_sp<GrFragmentProcessor>(new GrAlphaThresholdFragmentProcessor( + context, + std::move(proxy), + std::move(colorSpaceXform), + maskTexture, + innerThreshold, outerThreshold, + bounds)); + } const char* name() const override { return "Alpha Threshold"; } @@ -44,6 +67,14 @@ private: float outerThreshold, const SkIRect& bounds); + GrAlphaThresholdFragmentProcessor(GrContext*, + sk_sp<GrTextureProxy> proxy, + sk_sp<GrColorSpaceXform> colorSpaceXform, + GrTexture* maskTexture, + float innerThreshold, + float outerThreshold, + const SkIRect& bounds); + GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; diff --git a/src/effects/SkAlphaThresholdFilter.cpp b/src/effects/SkAlphaThresholdFilter.cpp index 0e38cccd65..bd38fb4ada 100644 --- a/src/effects/SkAlphaThresholdFilter.cpp +++ b/src/effects/SkAlphaThresholdFilter.cpp @@ -150,8 +150,8 @@ sk_sp<SkSpecialImage> SkAlphaThresholdFilterImpl::onFilterImage(SkSpecialImage* if (source->isTextureBacked()) { GrContext* context = source->getContext(); - sk_sp<GrTexture> inputTexture(input->asTextureRef(context)); - SkASSERT(inputTexture); + sk_sp<GrTextureProxy> inputProxy(input->asTextureProxyRef(context)); + SkASSERT(inputProxy); offset->fX = bounds.left(); offset->fY = bounds.top(); @@ -175,7 +175,8 @@ sk_sp<SkSpecialImage> SkAlphaThresholdFilterImpl::onFilterImage(SkSpecialImage* return nullptr; } sk_sp<GrFragmentProcessor> fp(GrAlphaThresholdFragmentProcessor::Make( - inputTexture.get(), + context, + std::move(inputProxy), std::move(colorSpaceXform), maskTex, fInnerThreshold, diff --git a/src/effects/SkArithmeticImageFilter.cpp b/src/effects/SkArithmeticImageFilter.cpp index 40560690ee..566b27f049 100644 --- a/src/effects/SkArithmeticImageFilter.cpp +++ b/src/effects/SkArithmeticImageFilter.cpp @@ -342,26 +342,26 @@ sk_sp<SkSpecialImage> ArithmeticImageFilterImpl::filterImageGPU( GrContext* context = source->getContext(); - sk_sp<GrTexture> backgroundTex, foregroundTex; + sk_sp<GrTextureProxy> backgroundProxy, foregroundProxy; if (background) { - backgroundTex = background->asTextureRef(context); + backgroundProxy = background->asTextureProxyRef(context); } if (foreground) { - foregroundTex = foreground->asTextureRef(context); + foregroundProxy = foreground->asTextureProxyRef(context); } GrPaint paint; sk_sp<GrFragmentProcessor> bgFP; - if (backgroundTex) { + if (backgroundProxy) { SkMatrix backgroundMatrix = SkMatrix::MakeTrans(-SkIntToScalar(backgroundOffset.fX), -SkIntToScalar(backgroundOffset.fY)); sk_sp<GrColorSpaceXform> bgXform = GrColorSpaceXform::Make(background->getColorSpace(), outputProperties.colorSpace()); bgFP = GrTextureDomainEffect::Make( - backgroundTex.get(), std::move(bgXform), backgroundMatrix, + context, std::move(backgroundProxy), std::move(bgXform), backgroundMatrix, GrTextureDomain::MakeTexelDomain(background->subset()), GrTextureDomain::kDecal_Mode, GrSamplerParams::kNone_FilterMode); } else { @@ -369,7 +369,7 @@ sk_sp<SkSpecialImage> ArithmeticImageFilterImpl::filterImageGPU( GrConstColorProcessor::kIgnore_InputMode); } - if (foregroundTex) { + if (foregroundProxy) { SkMatrix foregroundMatrix = SkMatrix::MakeTrans(-SkIntToScalar(foregroundOffset.fX), -SkIntToScalar(foregroundOffset.fY)); sk_sp<GrColorSpaceXform> fgXform = @@ -377,7 +377,7 @@ sk_sp<SkSpecialImage> ArithmeticImageFilterImpl::filterImageGPU( sk_sp<GrFragmentProcessor> foregroundFP; foregroundFP = GrTextureDomainEffect::Make( - foregroundTex.get(), std::move(fgXform), foregroundMatrix, + context, std::move(foregroundProxy), std::move(fgXform), foregroundMatrix, GrTextureDomain::MakeTexelDomain(foreground->subset()), GrTextureDomain::kDecal_Mode, GrSamplerParams::kNone_FilterMode); diff --git a/src/effects/SkDisplacementMapEffect.cpp b/src/effects/SkDisplacementMapEffect.cpp index 67fb761ed4..726be6b780 100644 --- a/src/effects/SkDisplacementMapEffect.cpp +++ b/src/effects/SkDisplacementMapEffect.cpp @@ -229,6 +229,19 @@ public: colorDimensions)); } + static sk_sp<GrFragmentProcessor> Make(GrContext* context, + SkDisplacementMapEffect::ChannelSelectorType xChannelSelector, + SkDisplacementMapEffect::ChannelSelectorType yChannelSelector, SkVector scale, + sk_sp<GrTextureProxy> displacement, const SkMatrix& offsetMatrix, + sk_sp<GrTextureProxy> color, + sk_sp<GrColorSpaceXform> colorSpaceXform, const SkISize& colorDimensions) { + return sk_sp<GrFragmentProcessor>( + new GrDisplacementMapEffect(context, xChannelSelector, yChannelSelector, scale, + std::move(displacement), + offsetMatrix, std::move(color), std::move(colorSpaceXform), + colorDimensions)); + } + virtual ~GrDisplacementMapEffect(); SkDisplacementMapEffect::ChannelSelectorType xChannelSelector() const { @@ -259,6 +272,14 @@ private: GrTexture* color, sk_sp<GrColorSpaceXform> colorSpaceXform, const SkISize& colorDimensions); + GrDisplacementMapEffect(GrContext*, + SkDisplacementMapEffect::ChannelSelectorType xChannelSelector, + SkDisplacementMapEffect::ChannelSelectorType yChannelSelector, + const SkVector& scale, + sk_sp<GrTextureProxy> displacement, const SkMatrix& offsetMatrix, + sk_sp<GrTextureProxy> color, sk_sp<GrColorSpaceXform> colorSpaceXform, + const SkISize& colorDimensions); + GR_DECLARE_FRAGMENT_PROCESSOR_TEST; GrCoordTransform fDisplacementTransform; @@ -330,9 +351,9 @@ sk_sp<SkSpecialImage> SkDisplacementMapEffect::onFilterImage(SkSpecialImage* sou if (source->isTextureBacked()) { GrContext* context = source->getContext(); - sk_sp<GrTexture> colorTexture(color->asTextureRef(context)); - sk_sp<GrTexture> displTexture(displ->asTextureRef(context)); - if (!colorTexture || !displTexture) { + sk_sp<GrTextureProxy> colorProxy(color->asTextureProxyRef(context)); + sk_sp<GrTextureProxy> displProxy(displ->asTextureProxyRef(context)); + if (!colorProxy || !displProxy) { return nullptr; } @@ -343,12 +364,13 @@ sk_sp<SkSpecialImage> SkDisplacementMapEffect::onFilterImage(SkSpecialImage* sou colorSpace); GrPaint paint; paint.addColorFragmentProcessor( - GrDisplacementMapEffect::Make(fXChannelSelector, + GrDisplacementMapEffect::Make(context, + fXChannelSelector, fYChannelSelector, scale, - displTexture.get(), + std::move(displProxy), offsetMatrix, - colorTexture.get(), + std::move(colorProxy), std::move(colorSpaceXform), SkISize::Make(color->width(), color->height()))); paint.setPorterDuffXPFactory(SkBlendMode::kSrc); @@ -514,6 +536,36 @@ GrDisplacementMapEffect::GrDisplacementMapEffect( this->addTextureSampler(&fColorSampler); } +GrDisplacementMapEffect::GrDisplacementMapEffect( + GrContext* context, + SkDisplacementMapEffect::ChannelSelectorType xChannelSelector, + SkDisplacementMapEffect::ChannelSelectorType yChannelSelector, + const SkVector& scale, + sk_sp<GrTextureProxy> displacement, + const SkMatrix& offsetMatrix, + sk_sp<GrTextureProxy> color, + sk_sp<GrColorSpaceXform> colorSpaceXform, + const SkISize& colorDimensions) + : INHERITED(GrPixelConfigIsOpaque(color->config()) ? kPreservesOpaqueInput_OptimizationFlag + : kNone_OptimizationFlags) + , fDisplacementTransform(context, offsetMatrix, displacement.get(), + GrSamplerParams::kNone_FilterMode) + , fDisplacementSampler(context->textureProvider(), displacement) + , fColorTransform(context, color.get(), GrSamplerParams::kNone_FilterMode) + , fDomain(color.get(), GrTextureDomain::MakeTexelDomain(SkIRect::MakeSize(colorDimensions)), + GrTextureDomain::kDecal_Mode) + , fColorSampler(context->textureProvider(), color) + , fColorSpaceXform(std::move(colorSpaceXform)) + , fXChannelSelector(xChannelSelector) + , fYChannelSelector(yChannelSelector) + , fScale(scale) { + this->initClassID<GrDisplacementMapEffect>(); + this->addCoordTransform(&fDisplacementTransform); + this->addTextureSampler(&fDisplacementSampler); + this->addCoordTransform(&fColorTransform); + this->addTextureSampler(&fColorSampler); +} + GrDisplacementMapEffect::~GrDisplacementMapEffect() { } diff --git a/src/effects/SkImageSource.cpp b/src/effects/SkImageSource.cpp index 5769e677a1..9c32cf8775 100644 --- a/src/effects/SkImageSource.cpp +++ b/src/effects/SkImageSource.cpp @@ -93,6 +93,7 @@ sk_sp<SkSpecialImage> SkImageSource::onFilterImage(SkSpecialImage* source, const // The dest is just an un-scaled integer translation of the entire image; return it offset->fX = iLeft; offset->fY = iTop; + return SkSpecialImage::MakeFromImage(SkIRect::MakeWH(fImage->width(), fImage->height()), fImage, ctx.outputProperties().colorSpace(), &source->props()); diff --git a/src/effects/SkLightingImageFilter.cpp b/src/effects/SkLightingImageFilter.cpp index 92057f0802..fefb2ff077 100644 --- a/src/effects/SkLightingImageFilter.cpp +++ b/src/effects/SkLightingImageFilter.cpp @@ -365,15 +365,15 @@ protected: const SkIRect& bounds, const SkMatrix& matrix, const OutputProperties& outputProperties) const; - virtual sk_sp<GrFragmentProcessor> makeFragmentProcessor(GrTexture*, + virtual sk_sp<GrFragmentProcessor> makeFragmentProcessor(GrContext*, sk_sp<GrTextureProxy>, const SkMatrix&, const SkIRect* srcBounds, BoundaryMode boundaryMode) const = 0; #endif private: #if SK_SUPPORT_GPU - void drawRect(GrRenderTargetContext* renderTargetContext, - GrTexture* src, + void drawRect(GrContext*, GrRenderTargetContext*, + sk_sp<GrTextureProxy> srcProxy, const SkMatrix& matrix, const GrClip& clip, const SkRect& dstRect, @@ -385,8 +385,9 @@ private: }; #if SK_SUPPORT_GPU -void SkLightingImageFilterInternal::drawRect(GrRenderTargetContext* renderTargetContext, - GrTexture* src, +void SkLightingImageFilterInternal::drawRect(GrContext* context, + GrRenderTargetContext* renderTargetContext, + sk_sp<GrTextureProxy> srcProxy, const SkMatrix& matrix, const GrClip& clip, const SkRect& dstRect, @@ -396,7 +397,8 @@ void SkLightingImageFilterInternal::drawRect(GrRenderTargetContext* renderTarget SkRect srcRect = dstRect.makeOffset(SkIntToScalar(bounds.x()), SkIntToScalar(bounds.y())); GrPaint paint; paint.setGammaCorrect(renderTargetContext->isGammaCorrect()); - sk_sp<GrFragmentProcessor> fp(this->makeFragmentProcessor(src, matrix, srcBounds, + sk_sp<GrFragmentProcessor> fp(this->makeFragmentProcessor(context, std::move(srcProxy), + matrix, srcBounds, boundaryMode)); paint.addColorFragmentProcessor(std::move(fp)); paint.setPorterDuffXPFactory(SkBlendMode::kSrc); @@ -414,8 +416,8 @@ sk_sp<SkSpecialImage> SkLightingImageFilterInternal::filterImageGPU( GrContext* context = source->getContext(); - sk_sp<GrTexture> inputTexture(input->asTextureRef(context)); - SkASSERT(inputTexture); + sk_sp<GrTextureProxy> inputProxy(input->asTextureProxyRef(context)); + SkASSERT(inputProxy); sk_sp<GrRenderTargetContext> renderTargetContext(context->makeDeferredRenderTargetContext( SkBackingFit::kApprox, offsetBounds.width(), offsetBounds.height(), @@ -443,23 +445,23 @@ sk_sp<SkSpecialImage> SkLightingImageFilterInternal::filterImageGPU( SkRect bottomRight = SkRect::MakeXYWH(dstRect.width() - 1, dstRect.height() - 1, 1, 1); const SkIRect* pSrcBounds = inputBounds.contains(offsetBounds) ? nullptr : &inputBounds; - this->drawRect(renderTargetContext.get(), inputTexture.get(), matrix, clip, topLeft, + this->drawRect(context, renderTargetContext.get(), inputProxy, matrix, clip, topLeft, kTopLeft_BoundaryMode, pSrcBounds, offsetBounds); - this->drawRect(renderTargetContext.get(), inputTexture.get(), matrix, clip, top, + this->drawRect(context, renderTargetContext.get(), inputProxy, matrix, clip, top, kTop_BoundaryMode, pSrcBounds, offsetBounds); - this->drawRect(renderTargetContext.get(), inputTexture.get(), matrix, clip, topRight, + this->drawRect(context, renderTargetContext.get(), inputProxy, matrix, clip, topRight, kTopRight_BoundaryMode, pSrcBounds, offsetBounds); - this->drawRect(renderTargetContext.get(), inputTexture.get(), matrix, clip, left, + this->drawRect(context, renderTargetContext.get(), inputProxy, matrix, clip, left, kLeft_BoundaryMode, pSrcBounds, offsetBounds); - this->drawRect(renderTargetContext.get(), inputTexture.get(), matrix, clip, interior, + this->drawRect(context, renderTargetContext.get(), inputProxy, matrix, clip, interior, kInterior_BoundaryMode, pSrcBounds, offsetBounds); - this->drawRect(renderTargetContext.get(), inputTexture.get(), matrix, clip, right, + this->drawRect(context, renderTargetContext.get(), inputProxy, matrix, clip, right, kRight_BoundaryMode, pSrcBounds, offsetBounds); - this->drawRect(renderTargetContext.get(), inputTexture.get(), matrix, clip, bottomLeft, + this->drawRect(context, renderTargetContext.get(), inputProxy, matrix, clip, bottomLeft, kBottomLeft_BoundaryMode, pSrcBounds, offsetBounds); - this->drawRect(renderTargetContext.get(), inputTexture.get(), matrix, clip, bottom, + this->drawRect(context, renderTargetContext.get(), inputProxy, matrix, clip, bottom, kBottom_BoundaryMode, pSrcBounds, offsetBounds); - this->drawRect(renderTargetContext.get(), inputTexture.get(), matrix, clip, bottomRight, + this->drawRect(context, renderTargetContext.get(), inputProxy, matrix, clip, bottomRight, kBottomRight_BoundaryMode, pSrcBounds, offsetBounds); return SkSpecialImage::MakeDeferredFromGpu( @@ -493,8 +495,8 @@ protected: SkIPoint* offset) const override; #if SK_SUPPORT_GPU - sk_sp<GrFragmentProcessor> makeFragmentProcessor(GrTexture*, const SkMatrix&, - const SkIRect* bounds, + sk_sp<GrFragmentProcessor> makeFragmentProcessor(GrContext*, sk_sp<GrTextureProxy>, + const SkMatrix&, const SkIRect* bounds, BoundaryMode) const override; #endif @@ -529,8 +531,8 @@ protected: SkIPoint* offset) const override; #if SK_SUPPORT_GPU - sk_sp<GrFragmentProcessor> makeFragmentProcessor(GrTexture*, const SkMatrix&, - const SkIRect* bounds, + sk_sp<GrFragmentProcessor> makeFragmentProcessor(GrContext*, sk_sp<GrTextureProxy>, + const SkMatrix&, const SkIRect* bounds, BoundaryMode) const override; #endif @@ -545,7 +547,8 @@ private: class GrLightingEffect : public GrSingleTextureEffect { public: - GrLightingEffect(GrTexture* texture, const SkImageFilterLight* light, SkScalar surfaceScale, + GrLightingEffect(GrContext*, sk_sp<GrTextureProxy>, + const SkImageFilterLight* light, SkScalar surfaceScale, const SkMatrix& matrix, BoundaryMode boundaryMode, const SkIRect* srcBounds); ~GrLightingEffect() override; @@ -575,7 +578,8 @@ private: class GrDiffuseLightingEffect : public GrLightingEffect { public: - static sk_sp<GrFragmentProcessor> Make(GrTexture* texture, + static sk_sp<GrFragmentProcessor> Make(GrContext* context, + sk_sp<GrTextureProxy> proxy, const SkImageFilterLight* light, SkScalar surfaceScale, const SkMatrix& matrix, @@ -583,8 +587,8 @@ public: BoundaryMode boundaryMode, const SkIRect* srcBounds) { return sk_sp<GrFragmentProcessor>( - new GrDiffuseLightingEffect(texture, light, surfaceScale, matrix, kd, boundaryMode, - srcBounds)); + new GrDiffuseLightingEffect(context, std::move(proxy), light, + surfaceScale, matrix, kd, boundaryMode, srcBounds)); } const char* name() const override { return "DiffuseLighting"; } @@ -598,7 +602,7 @@ private: bool onIsEqual(const GrFragmentProcessor&) const override; - GrDiffuseLightingEffect(GrTexture* texture, + GrDiffuseLightingEffect(GrContext*, sk_sp<GrTextureProxy>, const SkImageFilterLight* light, SkScalar surfaceScale, const SkMatrix& matrix, @@ -607,13 +611,15 @@ private: const SkIRect* srcBounds); GR_DECLARE_FRAGMENT_PROCESSOR_TEST; - typedef GrLightingEffect INHERITED; SkScalar fKD; + + typedef GrLightingEffect INHERITED; }; class GrSpecularLightingEffect : public GrLightingEffect { public: - static sk_sp<GrFragmentProcessor> Make(GrTexture* texture, + static sk_sp<GrFragmentProcessor> Make(GrContext* context, + sk_sp<GrTextureProxy> proxy, const SkImageFilterLight* light, SkScalar surfaceScale, const SkMatrix& matrix, @@ -622,7 +628,8 @@ public: BoundaryMode boundaryMode, const SkIRect* srcBounds) { return sk_sp<GrFragmentProcessor>( - new GrSpecularLightingEffect(texture, light, surfaceScale, matrix, ks, shininess, + new GrSpecularLightingEffect(context, std::move(proxy), + light, surfaceScale, matrix, ks, shininess, boundaryMode, srcBounds)); } @@ -638,7 +645,7 @@ private: bool onIsEqual(const GrFragmentProcessor&) const override; - GrSpecularLightingEffect(GrTexture* texture, + GrSpecularLightingEffect(GrContext*, sk_sp<GrTextureProxy>, const SkImageFilterLight* light, SkScalar surfaceScale, const SkMatrix& matrix, @@ -648,9 +655,10 @@ private: const SkIRect* srcBounds); GR_DECLARE_FRAGMENT_PROCESSOR_TEST; - typedef GrLightingEffect INHERITED; SkScalar fKS; SkScalar fShininess; + + typedef GrLightingEffect INHERITED; }; /////////////////////////////////////////////////////////////////////////////// @@ -1348,12 +1356,14 @@ void SkDiffuseLightingImageFilter::toString(SkString* str) const { #if SK_SUPPORT_GPU sk_sp<GrFragmentProcessor> SkDiffuseLightingImageFilter::makeFragmentProcessor( - GrTexture* texture, + GrContext* context, + sk_sp<GrTextureProxy> proxy, const SkMatrix& matrix, const SkIRect* srcBounds, BoundaryMode boundaryMode) const { SkScalar scale = SkScalarMul(this->surfaceScale(), SkIntToScalar(255)); - return GrDiffuseLightingEffect::Make(texture, this->light(), scale, matrix, this->kd(), + return GrDiffuseLightingEffect::Make(context, std::move(proxy), + this->light(), scale, matrix, this->kd(), boundaryMode, srcBounds); } #endif @@ -1513,12 +1523,14 @@ void SkSpecularLightingImageFilter::toString(SkString* str) const { #if SK_SUPPORT_GPU sk_sp<GrFragmentProcessor> SkSpecularLightingImageFilter::makeFragmentProcessor( - GrTexture* texture, + GrContext* context, + sk_sp<GrTextureProxy> proxy, const SkMatrix& matrix, const SkIRect* srcBounds, BoundaryMode boundaryMode) const { SkScalar scale = SkScalarMul(this->surfaceScale(), SkIntToScalar(255)); - return GrSpecularLightingEffect::Make(texture, this->light(), scale, matrix, this->ks(), + return GrSpecularLightingEffect::Make(context, std::move(proxy), this->light(), + scale, matrix, this->ks(), this->shininess(), boundaryMode, srcBounds); } #endif @@ -1691,29 +1703,30 @@ private: /////////////////////////////////////////////////////////////////////////////// -static GrTextureDomain create_domain(GrTexture* texture, const SkIRect* srcBounds, +static GrTextureDomain create_domain(GrTextureProxy* proxy, const SkIRect* srcBounds, GrTextureDomain::Mode mode) { if (srcBounds) { SkRect texelDomain = GrTextureDomain::MakeTexelDomainForMode(*srcBounds, mode); - return GrTextureDomain(texture, texelDomain, mode); + return GrTextureDomain(proxy, texelDomain, mode); } else { return GrTextureDomain::IgnoredDomain(); } } -GrLightingEffect::GrLightingEffect(GrTexture* texture, +GrLightingEffect::GrLightingEffect(GrContext* context, + sk_sp<GrTextureProxy> proxy, const SkImageFilterLight* light, SkScalar surfaceScale, const SkMatrix& matrix, BoundaryMode boundaryMode, const SkIRect* srcBounds) // Perhaps this could advertise the opaque or modulating optimizations? - : INHERITED(texture, nullptr, SkMatrix::I(), kNone_OptimizationFlags) + : INHERITED(context, kNone_OptimizationFlags, proxy, nullptr, SkMatrix::I()) , fLight(light) , fSurfaceScale(surfaceScale) , fFilterMatrix(matrix) , fBoundaryMode(boundaryMode) - , fDomain(create_domain(texture, srcBounds, GrTextureDomain::kDecal_Mode)) { + , fDomain(create_domain(proxy.get(), srcBounds, GrTextureDomain::kDecal_Mode)) { fLight->ref(); if (light->requiresFragmentPosition()) { this->setWillReadFragmentPosition(); @@ -1733,14 +1746,16 @@ bool GrLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const { /////////////////////////////////////////////////////////////////////////////// -GrDiffuseLightingEffect::GrDiffuseLightingEffect(GrTexture* texture, +GrDiffuseLightingEffect::GrDiffuseLightingEffect(GrContext* context, + sk_sp<GrTextureProxy> proxy, const SkImageFilterLight* light, SkScalar surfaceScale, const SkMatrix& matrix, SkScalar kd, BoundaryMode boundaryMode, const SkIRect* srcBounds) - : INHERITED(texture, light, surfaceScale, matrix, boundaryMode, srcBounds), fKD(kd) { + : INHERITED(context, std::move(proxy), light, surfaceScale, matrix, + boundaryMode, srcBounds), fKD(kd) { this->initClassID<GrDiffuseLightingEffect>(); } @@ -1762,9 +1777,9 @@ GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDiffuseLightingEffect); #if GR_TEST_UTILS sk_sp<GrFragmentProcessor> GrDiffuseLightingEffect::TestCreate(GrProcessorTestData* d) { - int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : - GrProcessorUnitTest::kAlphaTextureIdx; - GrTexture* tex = d->fTextures[texIdx]; + int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx + : GrProcessorUnitTest::kAlphaTextureIdx; + sk_sp<GrTextureProxy> proxy = d->textureProxy(texIdx); SkScalar surfaceScale = d->fRandom->nextSScalar1(); SkScalar kd = d->fRandom->nextUScalar1(); sk_sp<SkImageFilterLight> light(create_random_light(d->fRandom)); @@ -1772,13 +1787,14 @@ sk_sp<GrFragmentProcessor> GrDiffuseLightingEffect::TestCreate(GrProcessorTestDa for (int i = 0; i < 9; i++) { matrix[i] = d->fRandom->nextUScalar1(); } - SkIRect srcBounds = SkIRect::MakeXYWH(d->fRandom->nextRangeU(0, tex->width()), - d->fRandom->nextRangeU(0, tex->height()), - d->fRandom->nextRangeU(0, tex->width()), - d->fRandom->nextRangeU(0, tex->height())); + SkIRect srcBounds = SkIRect::MakeXYWH(d->fRandom->nextRangeU(0, proxy->width()), + d->fRandom->nextRangeU(0, proxy->height()), + d->fRandom->nextRangeU(0, proxy->width()), + d->fRandom->nextRangeU(0, proxy->height())); BoundaryMode mode = static_cast<BoundaryMode>(d->fRandom->nextU() % kBoundaryModeCount); - return GrDiffuseLightingEffect::Make(tex, light.get(), surfaceScale, matrix, kd, mode, - &srcBounds); + return GrDiffuseLightingEffect::Make(d->context(), + std::move(proxy), light.get(), surfaceScale, + matrix, kd, mode, &srcBounds); } #endif @@ -1948,7 +1964,8 @@ void GrGLDiffuseLightingEffect::onSetData(const GrGLSLProgramDataManager& pdman, /////////////////////////////////////////////////////////////////////////////// -GrSpecularLightingEffect::GrSpecularLightingEffect(GrTexture* texture, +GrSpecularLightingEffect::GrSpecularLightingEffect(GrContext* context, + sk_sp<GrTextureProxy> proxy, const SkImageFilterLight* light, SkScalar surfaceScale, const SkMatrix& matrix, @@ -1956,7 +1973,7 @@ GrSpecularLightingEffect::GrSpecularLightingEffect(GrTexture* texture, SkScalar shininess, BoundaryMode boundaryMode, const SkIRect* srcBounds) - : INHERITED(texture, light, surfaceScale, matrix, boundaryMode, srcBounds) + : INHERITED(context, std::move(proxy), light, surfaceScale, matrix, boundaryMode, srcBounds) , fKS(ks) , fShininess(shininess) { this->initClassID<GrSpecularLightingEffect>(); @@ -1982,9 +1999,9 @@ GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSpecularLightingEffect); #if GR_TEST_UTILS sk_sp<GrFragmentProcessor> GrSpecularLightingEffect::TestCreate(GrProcessorTestData* d) { - int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : - GrProcessorUnitTest::kAlphaTextureIdx; - GrTexture* tex = d->fTextures[texIdx]; + int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx + : GrProcessorUnitTest::kAlphaTextureIdx; + sk_sp<GrTextureProxy> proxy = d->textureProxy(texIdx); SkScalar surfaceScale = d->fRandom->nextSScalar1(); SkScalar ks = d->fRandom->nextUScalar1(); SkScalar shininess = d->fRandom->nextUScalar1(); @@ -1994,11 +2011,11 @@ sk_sp<GrFragmentProcessor> GrSpecularLightingEffect::TestCreate(GrProcessorTestD matrix[i] = d->fRandom->nextUScalar1(); } BoundaryMode mode = static_cast<BoundaryMode>(d->fRandom->nextU() % kBoundaryModeCount); - SkIRect srcBounds = SkIRect::MakeXYWH(d->fRandom->nextRangeU(0, tex->width()), - d->fRandom->nextRangeU(0, tex->height()), - d->fRandom->nextRangeU(0, tex->width()), - d->fRandom->nextRangeU(0, tex->height())); - return GrSpecularLightingEffect::Make(d->fTextures[GrProcessorUnitTest::kAlphaTextureIdx], + SkIRect srcBounds = SkIRect::MakeXYWH(d->fRandom->nextRangeU(0, proxy->width()), + d->fRandom->nextRangeU(0, proxy->height()), + d->fRandom->nextRangeU(0, proxy->width()), + d->fRandom->nextRangeU(0, proxy->height())); + return GrSpecularLightingEffect::Make(d->context(), std::move(proxy), light.get(), surfaceScale, matrix, ks, shininess, mode, &srcBounds); } diff --git a/src/effects/SkMagnifierImageFilter.cpp b/src/effects/SkMagnifierImageFilter.cpp index 93a67104f4..540ed309bc 100644 --- a/src/effects/SkMagnifierImageFilter.cpp +++ b/src/effects/SkMagnifierImageFilter.cpp @@ -18,6 +18,7 @@ #if SK_SUPPORT_GPU #include "GrContext.h" #include "GrInvariantOutput.h" +#include "effects/GrProxyMove.h" #include "effects/GrSingleTextureEffect.h" #include "glsl/GrGLSLColorSpaceXformHelper.h" #include "glsl/GrGLSLFragmentProcessor.h" @@ -25,20 +26,55 @@ #include "glsl/GrGLSLProgramDataManager.h" #include "glsl/GrGLSLUniformHandler.h" #include "../private/GrGLSL.h" +#endif + +sk_sp<SkImageFilter> SkMagnifierImageFilter::Make(const SkRect& srcRect, SkScalar inset, + sk_sp<SkImageFilter> input, + const CropRect* cropRect) { + if (!SkScalarIsFinite(inset) || !SkIsValidRect(srcRect)) { + return nullptr; + } + if (inset < 0) { + return nullptr; + } + // Negative numbers in src rect are not supported + if (srcRect.fLeft < 0 || srcRect.fTop < 0) { + return nullptr; + } + return sk_sp<SkImageFilter>(new SkMagnifierImageFilter(srcRect, inset, + std::move(input), + cropRect)); +} +#if SK_SUPPORT_GPU class GrMagnifierEffect : public GrSingleTextureEffect { public: static sk_sp<GrFragmentProcessor> Make(GrTexture* texture, sk_sp<GrColorSpaceXform> colorSpaceXform, - const SkRect& bounds, - float xOffset, - float yOffset, + const SkIRect& bounds, + const SkRect& srcRect, float xInvZoom, float yInvZoom, float xInvInset, float yInvInset) { return sk_sp<GrFragmentProcessor>(new GrMagnifierEffect(texture, std::move(colorSpaceXform), - bounds, xOffset, yOffset, + bounds, srcRect, + xInvZoom, yInvZoom, + xInvInset, yInvInset)); + } + static sk_sp<GrFragmentProcessor> Make(GrContext* context, + sk_sp<GrTextureProxy> proxy, + sk_sp<GrColorSpaceXform> colorSpaceXform, + const SkIRect& bounds, + const SkRect& srcRect, + float xInvZoom, + float yInvZoom, + float xInvInset, + float yInvInset) { + return sk_sp<GrFragmentProcessor>(new GrMagnifierEffect(context, + std::move(proxy), + std::move(colorSpaceXform), + bounds, srcRect, xInvZoom, yInvZoom, xInvInset, yInvInset)); } @@ -47,10 +83,8 @@ public: const char* name() const override { return "Magnifier"; } - const SkRect& bounds() const { return fBounds; } // Bounds of source image. - // Offset to apply to zoomed pixels, (srcRect position / texture size). - float xOffset() const { return fXOffset; } - float yOffset() const { return fYOffset; } + const SkIRect& bounds() const { return fBounds; } // Bounds of source image. + const SkRect& srcRect() const { return fSrcRect; } // Scale to apply to zoomed pixels (srcRect size / bounds size). float xInvZoom() const { return fXInvZoom; } @@ -63,9 +97,8 @@ public: private: GrMagnifierEffect(GrTexture* texture, sk_sp<GrColorSpaceXform> colorSpaceXform, - const SkRect& bounds, - float xOffset, - float yOffset, + const SkIRect& bounds, + const SkRect& srcRect, float xInvZoom, float yInvZoom, float xInvInset, @@ -73,8 +106,30 @@ private: : INHERITED(texture, std::move(colorSpaceXform), SkMatrix::I(), ModulationFlags(texture->config())) , fBounds(bounds) - , fXOffset(xOffset) - , fYOffset(yOffset) + , fSrcRect(srcRect) + , fXInvZoom(xInvZoom) + , fYInvZoom(yInvZoom) + , fXInvInset(xInvInset) + , fYInvInset(yInvInset) { + this->initClassID<GrMagnifierEffect>(); + } + + GrMagnifierEffect(GrContext* context, + sk_sp<GrTextureProxy> proxy, + sk_sp<GrColorSpaceXform> colorSpaceXform, + const SkIRect& bounds, + const SkRect& srcRect, + float xInvZoom, + float yInvZoom, + float xInvInset, + float yInvInset) + : INHERITED{context, + ModulationFlags(proxy->config()), + GR_PROXY_MOVE(proxy), + std::move(colorSpaceXform), + SkMatrix::I()} // TODO: no GrSamplerParams::kBilerp_FilterMode? + , fBounds(bounds) + , fSrcRect(srcRect) , fXInvZoom(xInvZoom) , fYInvZoom(yInvZoom) , fXInvInset(xInvInset) @@ -92,9 +147,8 @@ private: GR_DECLARE_FRAGMENT_PROCESSOR_TEST; - SkRect fBounds; - float fXOffset; - float fYOffset; + SkIRect fBounds; + SkRect fSrcRect; float fXInvZoom; float fYInvZoom; float fXInvInset; @@ -187,11 +241,38 @@ void GrGLMagnifierEffect::emitCode(EmitArgs& args) { void GrGLMagnifierEffect::onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& effect) { const GrMagnifierEffect& zoom = effect.cast<GrMagnifierEffect>(); - pdman.set2f(fOffsetVar, zoom.xOffset(), zoom.yOffset()); + + GrTexture* tex = zoom.textureSampler(0).texture(); + SkASSERT(tex); + + SkScalar invW = 1.0f / tex->width(); + SkScalar invH = 1.0f / tex->height(); + + { + SkScalar y = zoom.srcRect().y() * invH; + if (tex->origin() != kTopLeft_GrSurfaceOrigin) { + y = 1.0f - (zoom.srcRect().height() / zoom.bounds().height()) - y; + } + + pdman.set2f(fOffsetVar, zoom.srcRect().x() * invW, y); + } + pdman.set2f(fInvZoomVar, zoom.xInvZoom(), zoom.yInvZoom()); pdman.set2f(fInvInsetVar, zoom.xInvInset(), zoom.yInvInset()); - pdman.set4f(fBoundsVar, zoom.bounds().x(), zoom.bounds().y(), - zoom.bounds().width(), zoom.bounds().height()); + + { + SkScalar y = zoom.bounds().y() * invH; + if (tex->origin() != kTopLeft_GrSurfaceOrigin) { + y = 1.0f - zoom.bounds().height() * invH; + } + + pdman.set4f(fBoundsVar, + zoom.bounds().x() * invW, + y, + SkIntToScalar(tex->width()) / zoom.bounds().width(), + SkIntToScalar(tex->height()) / zoom.bounds().height()); + } + if (SkToBool(zoom.colorSpaceXform())) { pdman.setSkMatrix44(fColorSpaceXformVar, zoom.colorSpaceXform()->srcToDst()); } @@ -212,27 +293,28 @@ GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrMagnifierEffect); #if GR_TEST_UTILS sk_sp<GrFragmentProcessor> GrMagnifierEffect::TestCreate(GrProcessorTestData* d) { - GrTexture* texture = d->fTextures[0]; + sk_sp<GrTextureProxy> proxy = d->textureProxy(0); const int kMaxWidth = 200; const int kMaxHeight = 200; - const int kMaxInset = 20; + const SkScalar kMaxInset = 20.0f; uint32_t width = d->fRandom->nextULessThan(kMaxWidth); uint32_t height = d->fRandom->nextULessThan(kMaxHeight); - uint32_t x = d->fRandom->nextULessThan(kMaxWidth - width); - uint32_t y = d->fRandom->nextULessThan(kMaxHeight - height); - uint32_t inset = d->fRandom->nextULessThan(kMaxInset); - auto colorSpaceXform = GrTest::TestColorXform(d->fRandom); + SkScalar inset = d->fRandom->nextRangeScalar(1.0f, kMaxInset); + sk_sp<GrColorSpaceXform> colorSpaceXform = GrTest::TestColorXform(d->fRandom); + + SkIRect bounds = SkIRect::MakeWH(SkIntToScalar(kMaxWidth), SkIntToScalar(kMaxHeight)); + SkRect srcRect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height)); sk_sp<GrFragmentProcessor> effect(GrMagnifierEffect::Make( - texture, + d->context(), + std::move(proxy), std::move(colorSpaceXform), - SkRect::MakeWH(SkIntToScalar(kMaxWidth), SkIntToScalar(kMaxHeight)), - (float) width / texture->width(), - (float) height / texture->height(), - texture->width() / (float) x, - texture->height() / (float) y, - (float) inset / texture->width(), - (float) inset / texture->height())); + bounds, + srcRect, + srcRect.width() / bounds.width(), + srcRect.height() / bounds.height(), + bounds.width() / inset, + bounds.height() / inset)); SkASSERT(effect); return effect; } @@ -243,8 +325,7 @@ sk_sp<GrFragmentProcessor> GrMagnifierEffect::TestCreate(GrProcessorTestData* d) bool GrMagnifierEffect::onIsEqual(const GrFragmentProcessor& sBase) const { const GrMagnifierEffect& s = sBase.cast<GrMagnifierEffect>(); return (this->fBounds == s.fBounds && - this->fXOffset == s.fXOffset && - this->fYOffset == s.fYOffset && + this->fSrcRect == s.fSrcRect && this->fXInvZoom == s.fXInvZoom && this->fYInvZoom == s.fYInvZoom && this->fXInvInset == s.fXInvInset && @@ -259,23 +340,6 @@ void GrMagnifierEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const //////////////////////////////////////////////////////////////////////////////// -sk_sp<SkImageFilter> SkMagnifierImageFilter::Make(const SkRect& srcRect, SkScalar inset, - sk_sp<SkImageFilter> input, - const CropRect* cropRect) { - - if (!SkScalarIsFinite(inset) || !SkIsValidRect(srcRect)) { - return nullptr; - } - // Negative numbers in src rect are not supported - if (srcRect.fLeft < 0 || srcRect.fTop < 0) { - return nullptr; - } - return sk_sp<SkImageFilter>(new SkMagnifierImageFilter(srcRect, inset, - std::move(input), - cropRect)); -} - - SkMagnifierImageFilter::SkMagnifierImageFilter(const SkRect& srcRect, SkScalar inset, sk_sp<SkImageFilter> input, @@ -283,7 +347,7 @@ SkMagnifierImageFilter::SkMagnifierImageFilter(const SkRect& srcRect, : INHERITED(&input, 1, cropRect) , fSrcRect(srcRect) , fInset(inset) { - SkASSERT(srcRect.x() >= 0 && srcRect.y() >= 0 && inset >= 0); + SkASSERT(srcRect.left() >= 0 && srcRect.top() >= 0 && inset >= 0); } sk_sp<SkFlattenable> SkMagnifierImageFilter::CreateProc(SkReadBuffer& buffer) { @@ -326,35 +390,22 @@ sk_sp<SkSpecialImage> SkMagnifierImageFilter::onFilterImage(SkSpecialImage* sour if (source->isTextureBacked()) { GrContext* context = source->getContext(); - sk_sp<GrTexture> inputTexture(input->asTextureRef(context)); - SkASSERT(inputTexture); + sk_sp<GrTextureProxy> inputProxy(input->asTextureProxyRef(context)); + SkASSERT(inputProxy); offset->fX = bounds.left(); offset->fY = bounds.top(); bounds.offset(-inputOffset); - SkScalar yOffset = inputTexture->origin() == kTopLeft_GrSurfaceOrigin - ? fSrcRect.y() - : inputTexture->height() - - fSrcRect.height() * inputTexture->height() / bounds.height() - fSrcRect.y(); - int boundsY = inputTexture->origin() == kTopLeft_GrSurfaceOrigin - ? bounds.y() - : inputTexture->height() - bounds.height(); - SkRect effectBounds = SkRect::MakeXYWH( - SkIntToScalar(bounds.x()) / inputTexture->width(), - SkIntToScalar(boundsY) / inputTexture->height(), - SkIntToScalar(inputTexture->width()) / bounds.width(), - SkIntToScalar(inputTexture->height()) / bounds.height()); - SkColorSpace* dstColorSpace = ctx.outputProperties().colorSpace(); sk_sp<GrColorSpaceXform> colorSpaceXform = GrColorSpaceXform::Make(input->getColorSpace(), dstColorSpace); sk_sp<GrFragmentProcessor> fp(GrMagnifierEffect::Make( - inputTexture.get(), + context, + std::move(inputProxy), std::move(colorSpaceXform), - effectBounds, - fSrcRect.x() / inputTexture->width(), - yOffset / inputTexture->height(), + bounds, + fSrcRect, invXZoom, invYZoom, bounds.width() * invInset, diff --git a/src/effects/SkMatrixConvolutionImageFilter.cpp b/src/effects/SkMatrixConvolutionImageFilter.cpp index 8d6dbfc2b7..cec1a7d4f4 100644 --- a/src/effects/SkMatrixConvolutionImageFilter.cpp +++ b/src/effects/SkMatrixConvolutionImageFilter.cpp @@ -311,14 +311,15 @@ sk_sp<SkSpecialImage> SkMatrixConvolutionImageFilter::onFilterImage(SkSpecialIma // fall-back, which saves us from having to do the xform during the filter itself. input = ImageToColorSpace(input.get(), ctx.outputProperties()); - sk_sp<GrTexture> inputTexture(input->asTextureRef(context)); - SkASSERT(inputTexture); + sk_sp<GrTextureProxy> inputProxy(input->asTextureProxyRef(context)); + SkASSERT(inputProxy); offset->fX = bounds.left(); offset->fY = bounds.top(); bounds.offset(-inputOffset); - sk_sp<GrFragmentProcessor> fp(GrMatrixConvolutionEffect::Make(inputTexture.get(), + sk_sp<GrFragmentProcessor> fp(GrMatrixConvolutionEffect::Make(context, + std::move(inputProxy), bounds, fKernelSize, fKernel, diff --git a/src/effects/SkMorphologyImageFilter.cpp b/src/effects/SkMorphologyImageFilter.cpp index 2c813e283a..e6a477f36b 100644 --- a/src/effects/SkMorphologyImageFilter.cpp +++ b/src/effects/SkMorphologyImageFilter.cpp @@ -486,7 +486,7 @@ static sk_sp<SkSpecialImage> apply_morphology( GrMorphologyEffect::MorphologyType morphType, SkISize radius, const SkImageFilter::OutputProperties& outputProperties) { - sk_sp<GrTextureProxy> srcTexture(input->asTextureProxy(context)); + sk_sp<GrTextureProxy> srcTexture(input->asTextureProxyRef(context)); SkASSERT(srcTexture); sk_sp<SkColorSpace> colorSpace = sk_ref_sp(outputProperties.colorSpace()); GrPixelConfig config = GrRenderableConfigForColorSpace(colorSpace.get()); diff --git a/src/effects/SkXfermodeImageFilter.cpp b/src/effects/SkXfermodeImageFilter.cpp index 5f44919914..c9e5a8a601 100644 --- a/src/effects/SkXfermodeImageFilter.cpp +++ b/src/effects/SkXfermodeImageFilter.cpp @@ -235,26 +235,26 @@ sk_sp<SkSpecialImage> SkXfermodeImageFilter_Base::filterImageGPU( GrContext* context = source->getContext(); - sk_sp<GrTexture> backgroundTex, foregroundTex; - + sk_sp<GrTextureProxy> backgroundProxy, foregroundProxy; + if (background) { - backgroundTex = background->asTextureRef(context); + backgroundProxy = background->asTextureProxyRef(context); } if (foreground) { - foregroundTex = foreground->asTextureRef(context); + foregroundProxy = foreground->asTextureProxyRef(context); } GrPaint paint; sk_sp<GrFragmentProcessor> bgFP; - if (backgroundTex) { - SkMatrix backgroundMatrix = SkMatrix::MakeTrans(-SkIntToScalar(backgroundOffset.fX), - -SkIntToScalar(backgroundOffset.fY)); + if (backgroundProxy) { + SkMatrix bgMatrix = SkMatrix::MakeTrans(-SkIntToScalar(backgroundOffset.fX), + -SkIntToScalar(backgroundOffset.fY)); sk_sp<GrColorSpaceXform> bgXform = GrColorSpaceXform::Make(background->getColorSpace(), outputProperties.colorSpace()); bgFP = GrTextureDomainEffect::Make( - backgroundTex.get(), std::move(bgXform), backgroundMatrix, + context, std::move(backgroundProxy), std::move(bgXform), bgMatrix, GrTextureDomain::MakeTexelDomain(background->subset()), GrTextureDomain::kDecal_Mode, GrSamplerParams::kNone_FilterMode); @@ -263,15 +263,15 @@ sk_sp<SkSpecialImage> SkXfermodeImageFilter_Base::filterImageGPU( GrConstColorProcessor::kIgnore_InputMode); } - if (foregroundTex) { - SkMatrix foregroundMatrix = SkMatrix::MakeTrans(-SkIntToScalar(foregroundOffset.fX), - -SkIntToScalar(foregroundOffset.fY)); + if (foregroundProxy) { + SkMatrix fgMatrix = SkMatrix::MakeTrans(-SkIntToScalar(foregroundOffset.fX), + -SkIntToScalar(foregroundOffset.fY)); sk_sp<GrColorSpaceXform> fgXform = GrColorSpaceXform::Make(foreground->getColorSpace(), outputProperties.colorSpace()); sk_sp<GrFragmentProcessor> foregroundFP; foregroundFP = GrTextureDomainEffect::Make( - foregroundTex.get(), std::move(fgXform), foregroundMatrix, + context, std::move(foregroundProxy), std::move(fgXform), fgMatrix, GrTextureDomain::MakeTexelDomain(foreground->subset()), GrTextureDomain::kDecal_Mode, GrSamplerParams::kNone_FilterMode); diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index f30057d315..e9d27be0bf 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -1178,25 +1178,29 @@ void SkGpuDevice::drawSpecial(const SkDraw& draw, } SkASSERT(result->isTextureBacked()); - sk_sp<GrTexture> texture = result->asTextureRef(fContext.get()); - if (!texture) { + sk_sp<GrTextureProxy> proxy = result->asTextureProxyRef(fContext.get()); + if (!proxy) { return; } + const GrPixelConfig config = proxy->config(); + SkPaint tmpUnfiltered(paint); tmpUnfiltered.setImageFilter(nullptr); sk_sp<GrColorSpaceXform> colorSpaceXform = GrColorSpaceXform::Make(result->getColorSpace(), fRenderTargetContext->getColorSpace()); - GrPaint grPaint; - sk_sp<GrFragmentProcessor> fp(GrSimpleTextureEffect::Make(texture.get(), + sk_sp<GrFragmentProcessor> fp(GrSimpleTextureEffect::Make(fContext.get(), + std::move(proxy), std::move(colorSpaceXform), SkMatrix::I())); - if (GrPixelConfigIsAlphaOnly(texture->config())) { + if (GrPixelConfigIsAlphaOnly(config)) { fp = GrFragmentProcessor::MakeInputPremulAndMulByOutput(std::move(fp)); } else { fp = GrFragmentProcessor::MulOutputByInputAlpha(std::move(fp)); } + + GrPaint grPaint; if (!SkPaintToGrPaintReplaceShader(this->context(), fRenderTargetContext.get(), tmpUnfiltered, std::move(fp), &grPaint)) { return; diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp index 67c96d7ed2..e798935710 100644 --- a/src/image/SkImage.cpp +++ b/src/image/SkImage.cpp @@ -291,9 +291,7 @@ sk_sp<SkImage> SkImage::makeWithFilter(const SkImageFilter* filter, const SkIRec SkImageFilter::OutputProperties outputProperties(colorSpace); SkImageFilter::Context context(SkMatrix::I(), clipBounds, cache.get(), outputProperties); - sk_sp<SkSpecialImage> result = - filter->filterImage(srcSpecialImage.get(), context, offset); - + sk_sp<SkSpecialImage> result = filter->filterImage(srcSpecialImage.get(), context, offset); if (!result) { return nullptr; } @@ -302,11 +300,13 @@ sk_sp<SkImage> SkImage::makeWithFilter(const SkImageFilter* filter, const SkIRec #if SK_SUPPORT_GPU if (result->isTextureBacked()) { GrContext* context = result->getContext(); - sk_sp<GrTexture> texture = result->asTextureRef(context); - if (!texture) { + sk_sp<GrTextureProxy> proxy = result->asTextureProxyRef(context); + if (!proxy) { return nullptr; } - fullSize = SkIRect::MakeWH(texture->width(), texture->height()); + // MDB TODO: This is okay for now but will need to updated when we have deferred + // SkImage_Gpu objects + fullSize = SkIRect::MakeWH(proxy->width(), proxy->height()); } #endif *outSubset = SkIRect::MakeWH(result->width(), result->height()); |