aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/effects
diff options
context:
space:
mode:
authorGravatar Robert Phillips <robertphillips@google.com>2017-02-19 12:27:01 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-02-20 19:21:53 +0000
commit8e1c4e672553ecae2745168514240705f3516773 (patch)
treee6a30fef483a4701d7e4203129805880d79f4242 /src/effects
parenta3091099fa19da32e60433c0da835e9de3dd8ee9 (diff)
Remove asTextureRef from SkSpecialImage & update effects accordingly (take 2)
This CL also renames SkSpecialImage::asTextureProxy to asTextureProxyRef This is a reland of: https://skia-review.googlesource.com/c/7995/ (Remove asTextureRef from SkSpecialImage & update effects accordingly) It should be good to land since https://skia-review.googlesource.com/c/8701/ (Replace SkSpecialImage::makeTightSubset with asImage (take 2)) fixes the Chrome-side issue Change-Id: I3d88b2b3d23fd69f3fb914a69dacca96cbc038a4 Reviewed-on: https://skia-review.googlesource.com/8450 Commit-Queue: Robert Phillips <robertphillips@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src/effects')
-rw-r--r--src/effects/GrAlphaThresholdFragmentProcessor.cpp42
-rw-r--r--src/effects/GrAlphaThresholdFragmentProcessor.h33
-rw-r--r--src/effects/SkAlphaThresholdFilter.cpp7
-rw-r--r--src/effects/SkArithmeticImageFilter.cpp14
-rw-r--r--src/effects/SkDisplacementMapEffect.cpp64
-rw-r--r--src/effects/SkImageSource.cpp1
-rw-r--r--src/effects/SkLightingImageFilter.cpp139
-rw-r--r--src/effects/SkMagnifierImageFilter.cpp195
-rw-r--r--src/effects/SkMatrixConvolutionImageFilter.cpp7
-rw-r--r--src/effects/SkMorphologyImageFilter.cpp2
-rw-r--r--src/effects/SkXfermodeImageFilter.cpp24
11 files changed, 348 insertions, 180 deletions
diff --git a/src/effects/GrAlphaThresholdFragmentProcessor.cpp b/src/effects/GrAlphaThresholdFragmentProcessor.cpp
index 3d0defb3ab..d6e71b7aee 100644
--- a/src/effects/GrAlphaThresholdFragmentProcessor.cpp
+++ b/src/effects/GrAlphaThresholdFragmentProcessor.cpp
@@ -9,6 +9,7 @@
#if SK_SUPPORT_GPU
+#include "GrContext.h"
#include "SkRefCnt.h"
#include "glsl/GrGLSLColorSpaceXformHelper.h"
#include "glsl/GrGLSLFragmentProcessor.h"
@@ -16,20 +17,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 |
@@ -64,6 +51,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 fe97c7d96c..2dd18e807a 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 af834aafb5..7f9dc7f594 100644
--- a/src/effects/SkArithmeticImageFilter.cpp
+++ b/src/effects/SkArithmeticImageFilter.cpp
@@ -337,26 +337,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 {
@@ -364,7 +364,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 =
@@ -372,7 +372,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 6dde5dd88e..d123eb5582 100644
--- a/src/effects/SkDisplacementMapEffect.cpp
+++ b/src/effects/SkDisplacementMapEffect.cpp
@@ -225,6 +225,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 {
@@ -253,6 +266,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;
@@ -324,9 +345,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;
}
@@ -337,12 +358,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);
@@ -508,6 +530,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 e3f0f3a695..3ed017ee61 100644
--- a/src/effects/SkLightingImageFilter.cpp
+++ b/src/effects/SkLightingImageFilter.cpp
@@ -361,15 +361,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,
@@ -381,8 +381,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,
@@ -392,7 +393,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);
@@ -410,8 +412,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(),
@@ -439,23 +441,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(
@@ -489,8 +491,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
@@ -525,8 +527,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
@@ -541,7 +543,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;
@@ -567,7 +570,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,
@@ -575,8 +579,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"; }
@@ -590,7 +594,7 @@ private:
bool onIsEqual(const GrFragmentProcessor&) const override;
- GrDiffuseLightingEffect(GrTexture* texture,
+ GrDiffuseLightingEffect(GrContext*, sk_sp<GrTextureProxy>,
const SkImageFilterLight* light,
SkScalar surfaceScale,
const SkMatrix& matrix,
@@ -599,13 +603,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,
@@ -614,7 +620,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));
}
@@ -630,7 +637,7 @@ private:
bool onIsEqual(const GrFragmentProcessor&) const override;
- GrSpecularLightingEffect(GrTexture* texture,
+ GrSpecularLightingEffect(GrContext*, sk_sp<GrTextureProxy>,
const SkImageFilterLight* light,
SkScalar surfaceScale,
const SkMatrix& matrix,
@@ -640,9 +647,10 @@ private:
const SkIRect* srcBounds);
GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
- typedef GrLightingEffect INHERITED;
SkScalar fKS;
SkScalar fShininess;
+
+ typedef GrLightingEffect INHERITED;
};
///////////////////////////////////////////////////////////////////////////////
@@ -1332,12 +1340,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 = this->surfaceScale() * 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
@@ -1497,12 +1507,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 = this->surfaceScale() * 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
@@ -1675,29 +1687,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 coverage-as-alpha 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();
}
@@ -1714,14 +1727,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>();
}
@@ -1743,9 +1758,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));
@@ -1753,13 +1768,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
@@ -1929,7 +1945,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,
@@ -1937,7 +1954,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>();
@@ -1963,9 +1980,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();
@@ -1975,11 +1992,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 5a2f40443a..8307e31593 100644
--- a/src/effects/SkMagnifierImageFilter.cpp
+++ b/src/effects/SkMagnifierImageFilter.cpp
@@ -17,6 +17,7 @@
////////////////////////////////////////////////////////////////////////////////
#if SK_SUPPORT_GPU
#include "GrContext.h"
+#include "effects/GrProxyMove.h"
#include "effects/GrSingleTextureEffect.h"
#include "glsl/GrGLSLColorSpaceXformHelper.h"
#include "glsl/GrGLSLFragmentProcessor.h"
@@ -24,20 +25,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));
}
@@ -46,10 +82,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; }
@@ -62,9 +96,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,
@@ -72,8 +105,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)
@@ -89,9 +144,8 @@ private:
GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
- SkRect fBounds;
- float fXOffset;
- float fYOffset;
+ SkIRect fBounds;
+ SkRect fSrcRect;
float fXInvZoom;
float fYInvZoom;
float fXInvInset;
@@ -184,11 +238,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());
}
@@ -209,27 +290,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;
}
@@ -240,8 +322,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 &&
@@ -252,23 +333,6 @@ bool GrMagnifierEffect::onIsEqual(const GrFragmentProcessor& sBase) 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,
@@ -276,7 +340,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) {
@@ -319,35 +383,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 440ed5e256..f1df9b51ab 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 bf92b4f3fd..9ac69d384f 100644
--- a/src/effects/SkMorphologyImageFilter.cpp
+++ b/src/effects/SkMorphologyImageFilter.cpp
@@ -477,7 +477,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);