Revert "Remove asTextureRef from SkSpecialImage & update effects accordingly"
This reverts commit e88cf6b7aa
.
Reason for revert: See if breaking DEPS roll
Original change's description:
> 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>
>
TBR=bsalomon@google.com,robertphillips@google.com,reviews@skia.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
Change-Id: I227cbd5fcaf7e2f86e858331d9ec7ff7a5f203ca
Reviewed-on: https://skia-review.googlesource.com/8184
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
This commit is contained in:
parent
9852dc027f
commit
696b29346e
@ -14,7 +14,7 @@
|
||||
|
||||
class SK_API SkMagnifierImageFilter : public SkImageFilter {
|
||||
public:
|
||||
static sk_sp<SkImageFilter> Make(const SkRect& srcRect, SkScalar inset,
|
||||
static sk_sp<SkImageFilter> Make(const SkRect& src, SkScalar inset,
|
||||
sk_sp<SkImageFilter> input,
|
||||
const CropRect* cropRect = nullptr);
|
||||
|
||||
@ -32,9 +32,8 @@ protected:
|
||||
SkIPoint* offset) const override;
|
||||
|
||||
private:
|
||||
SkRect fSrcRect;
|
||||
SkRect fSrcRect;
|
||||
SkScalar fInset;
|
||||
|
||||
typedef SkImageFilter INHERITED;
|
||||
};
|
||||
|
||||
|
@ -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->asTextureProxyRef(context));
|
||||
sk_sp<GrTextureProxy> inputTexture(input->asTextureProxy(context));
|
||||
if (!inputTexture) {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -50,7 +50,8 @@ public:
|
||||
virtual SkColorSpace* onGetColorSpace() const = 0;
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
virtual sk_sp<GrTextureProxy> onAsTextureProxyRef(GrContext* context) const = 0;
|
||||
virtual sk_sp<GrTexture> onAsTextureRef(GrContext* context) const = 0;
|
||||
virtual sk_sp<GrTextureProxy> onAsTextureProxy(GrContext* context) const = 0;
|
||||
#endif
|
||||
|
||||
virtual sk_sp<SkSpecialImage> onMakeSubset(const SkIRect& subset) const = 0;
|
||||
@ -138,8 +139,12 @@ SkColorSpace* SkSpecialImage::getColorSpace() const {
|
||||
}
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
sk_sp<GrTextureProxy> SkSpecialImage::asTextureProxyRef(GrContext* context) const {
|
||||
return as_SIB(this)->onAsTextureProxyRef(context);
|
||||
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);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -237,7 +242,16 @@ public:
|
||||
}
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
sk_sp<GrTextureProxy> onAsTextureProxyRef(GrContext* context) const override {
|
||||
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 {
|
||||
if (context) {
|
||||
sk_sp<GrTexture> tex(sk_ref_sp(GrRefCachedBitmapTexture(
|
||||
context, fBitmap, GrSamplerParams::ClampNoFilter(), nullptr)));
|
||||
@ -414,7 +428,16 @@ public:
|
||||
|
||||
GrContext* onGetContext() const override { return fContext; }
|
||||
|
||||
sk_sp<GrTextureProxy> onAsTextureProxyRef(GrContext*) const override {
|
||||
// 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 {
|
||||
return sk_ref_sp(fSurfaceProxy->asTextureProxy());
|
||||
}
|
||||
|
||||
|
@ -136,10 +136,15 @@ public:
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
/**
|
||||
* Regardless of the underlying backing store, return the contents as a GrTextureProxy.
|
||||
* Regardless of the underlying backing store, return the contents as a GrTexture.
|
||||
* The active portion of the texture can be retrieved via 'subset'.
|
||||
*/
|
||||
sk_sp<GrTextureProxy> asTextureProxyRef(GrContext*) const;
|
||||
sk_sp<GrTexture> asTextureRef(GrContext*) const;
|
||||
|
||||
/**
|
||||
* The same as above but return the contents as a GrTextureProxy.
|
||||
*/
|
||||
sk_sp<GrTextureProxy> asTextureProxy(GrContext*) const;
|
||||
#endif
|
||||
|
||||
// TODO: hide this whe the imagefilter all have a consistent draw path (see skbug.com/5063)
|
||||
|
@ -9,7 +9,6 @@
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
|
||||
#include "GrContext.h"
|
||||
#include "GrInvariantOutput.h"
|
||||
#include "SkRefCnt.h"
|
||||
|
||||
@ -19,6 +18,20 @@
|
||||
#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;
|
||||
@ -52,33 +65,6 @@ 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 &&
|
||||
|
@ -25,30 +25,7 @@ public:
|
||||
GrTexture* maskTexture,
|
||||
float innerThreshold,
|
||||
float outerThreshold,
|
||||
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 SkIRect& bounds);
|
||||
|
||||
const char* name() const override { return "Alpha Threshold"; }
|
||||
|
||||
@ -67,14 +44,6 @@ 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;
|
||||
|
@ -150,8 +150,8 @@ sk_sp<SkSpecialImage> SkAlphaThresholdFilterImpl::onFilterImage(SkSpecialImage*
|
||||
if (source->isTextureBacked()) {
|
||||
GrContext* context = source->getContext();
|
||||
|
||||
sk_sp<GrTextureProxy> inputProxy(input->asTextureProxyRef(context));
|
||||
SkASSERT(inputProxy);
|
||||
sk_sp<GrTexture> inputTexture(input->asTextureRef(context));
|
||||
SkASSERT(inputTexture);
|
||||
|
||||
offset->fX = bounds.left();
|
||||
offset->fY = bounds.top();
|
||||
@ -175,8 +175,7 @@ sk_sp<SkSpecialImage> SkAlphaThresholdFilterImpl::onFilterImage(SkSpecialImage*
|
||||
return nullptr;
|
||||
}
|
||||
sk_sp<GrFragmentProcessor> fp(GrAlphaThresholdFragmentProcessor::Make(
|
||||
context,
|
||||
std::move(inputProxy),
|
||||
inputTexture.get(),
|
||||
std::move(colorSpaceXform),
|
||||
maskTex,
|
||||
fInnerThreshold,
|
||||
|
@ -342,26 +342,26 @@ sk_sp<SkSpecialImage> ArithmeticImageFilterImpl::filterImageGPU(
|
||||
|
||||
GrContext* context = source->getContext();
|
||||
|
||||
sk_sp<GrTextureProxy> backgroundProxy, foregroundProxy;
|
||||
sk_sp<GrTexture> backgroundTex, foregroundTex;
|
||||
|
||||
if (background) {
|
||||
backgroundProxy = background->asTextureProxyRef(context);
|
||||
backgroundTex = background->asTextureRef(context);
|
||||
}
|
||||
|
||||
if (foreground) {
|
||||
foregroundProxy = foreground->asTextureProxyRef(context);
|
||||
foregroundTex = foreground->asTextureRef(context);
|
||||
}
|
||||
|
||||
GrPaint paint;
|
||||
sk_sp<GrFragmentProcessor> bgFP;
|
||||
|
||||
if (backgroundProxy) {
|
||||
if (backgroundTex) {
|
||||
SkMatrix backgroundMatrix = SkMatrix::MakeTrans(-SkIntToScalar(backgroundOffset.fX),
|
||||
-SkIntToScalar(backgroundOffset.fY));
|
||||
sk_sp<GrColorSpaceXform> bgXform =
|
||||
GrColorSpaceXform::Make(background->getColorSpace(), outputProperties.colorSpace());
|
||||
bgFP = GrTextureDomainEffect::Make(
|
||||
context, std::move(backgroundProxy), std::move(bgXform), backgroundMatrix,
|
||||
backgroundTex.get(), 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 (foregroundProxy) {
|
||||
if (foregroundTex) {
|
||||
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(
|
||||
context, std::move(foregroundProxy), std::move(fgXform), foregroundMatrix,
|
||||
foregroundTex.get(), std::move(fgXform), foregroundMatrix,
|
||||
GrTextureDomain::MakeTexelDomain(foreground->subset()),
|
||||
GrTextureDomain::kDecal_Mode, GrSamplerParams::kNone_FilterMode);
|
||||
|
||||
|
@ -229,19 +229,6 @@ 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 {
|
||||
@ -272,14 +259,6 @@ 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;
|
||||
@ -351,9 +330,9 @@ sk_sp<SkSpecialImage> SkDisplacementMapEffect::onFilterImage(SkSpecialImage* sou
|
||||
if (source->isTextureBacked()) {
|
||||
GrContext* context = source->getContext();
|
||||
|
||||
sk_sp<GrTextureProxy> colorProxy(color->asTextureProxyRef(context));
|
||||
sk_sp<GrTextureProxy> displProxy(displ->asTextureProxyRef(context));
|
||||
if (!colorProxy || !displProxy) {
|
||||
sk_sp<GrTexture> colorTexture(color->asTextureRef(context));
|
||||
sk_sp<GrTexture> displTexture(displ->asTextureRef(context));
|
||||
if (!colorTexture || !displTexture) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -364,13 +343,12 @@ sk_sp<SkSpecialImage> SkDisplacementMapEffect::onFilterImage(SkSpecialImage* sou
|
||||
colorSpace);
|
||||
GrPaint paint;
|
||||
paint.addColorFragmentProcessor(
|
||||
GrDisplacementMapEffect::Make(context,
|
||||
fXChannelSelector,
|
||||
GrDisplacementMapEffect::Make(fXChannelSelector,
|
||||
fYChannelSelector,
|
||||
scale,
|
||||
std::move(displProxy),
|
||||
displTexture.get(),
|
||||
offsetMatrix,
|
||||
std::move(colorProxy),
|
||||
colorTexture.get(),
|
||||
std::move(colorSpaceXform),
|
||||
SkISize::Make(color->width(), color->height())));
|
||||
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
|
||||
@ -536,36 +514,6 @@ 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() {
|
||||
}
|
||||
|
||||
|
@ -93,7 +93,6 @@ 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());
|
||||
|
@ -365,15 +365,15 @@ protected:
|
||||
const SkIRect& bounds,
|
||||
const SkMatrix& matrix,
|
||||
const OutputProperties& outputProperties) const;
|
||||
virtual sk_sp<GrFragmentProcessor> makeFragmentProcessor(GrContext*, sk_sp<GrTextureProxy>,
|
||||
virtual sk_sp<GrFragmentProcessor> makeFragmentProcessor(GrTexture*,
|
||||
const SkMatrix&,
|
||||
const SkIRect* srcBounds,
|
||||
BoundaryMode boundaryMode) const = 0;
|
||||
#endif
|
||||
private:
|
||||
#if SK_SUPPORT_GPU
|
||||
void drawRect(GrContext*, GrRenderTargetContext*,
|
||||
sk_sp<GrTextureProxy> srcProxy,
|
||||
void drawRect(GrRenderTargetContext* renderTargetContext,
|
||||
GrTexture* src,
|
||||
const SkMatrix& matrix,
|
||||
const GrClip& clip,
|
||||
const SkRect& dstRect,
|
||||
@ -385,9 +385,8 @@ private:
|
||||
};
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
void SkLightingImageFilterInternal::drawRect(GrContext* context,
|
||||
GrRenderTargetContext* renderTargetContext,
|
||||
sk_sp<GrTextureProxy> srcProxy,
|
||||
void SkLightingImageFilterInternal::drawRect(GrRenderTargetContext* renderTargetContext,
|
||||
GrTexture* src,
|
||||
const SkMatrix& matrix,
|
||||
const GrClip& clip,
|
||||
const SkRect& dstRect,
|
||||
@ -397,8 +396,7 @@ void SkLightingImageFilterInternal::drawRect(GrContext* context,
|
||||
SkRect srcRect = dstRect.makeOffset(SkIntToScalar(bounds.x()), SkIntToScalar(bounds.y()));
|
||||
GrPaint paint;
|
||||
paint.setGammaCorrect(renderTargetContext->isGammaCorrect());
|
||||
sk_sp<GrFragmentProcessor> fp(this->makeFragmentProcessor(context, std::move(srcProxy),
|
||||
matrix, srcBounds,
|
||||
sk_sp<GrFragmentProcessor> fp(this->makeFragmentProcessor(src, matrix, srcBounds,
|
||||
boundaryMode));
|
||||
paint.addColorFragmentProcessor(std::move(fp));
|
||||
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
|
||||
@ -416,8 +414,8 @@ sk_sp<SkSpecialImage> SkLightingImageFilterInternal::filterImageGPU(
|
||||
|
||||
GrContext* context = source->getContext();
|
||||
|
||||
sk_sp<GrTextureProxy> inputProxy(input->asTextureProxyRef(context));
|
||||
SkASSERT(inputProxy);
|
||||
sk_sp<GrTexture> inputTexture(input->asTextureRef(context));
|
||||
SkASSERT(inputTexture);
|
||||
|
||||
sk_sp<GrRenderTargetContext> renderTargetContext(context->makeDeferredRenderTargetContext(
|
||||
SkBackingFit::kApprox, offsetBounds.width(), offsetBounds.height(),
|
||||
@ -445,23 +443,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(context, renderTargetContext.get(), inputProxy, matrix, clip, topLeft,
|
||||
this->drawRect(renderTargetContext.get(), inputTexture.get(), matrix, clip, topLeft,
|
||||
kTopLeft_BoundaryMode, pSrcBounds, offsetBounds);
|
||||
this->drawRect(context, renderTargetContext.get(), inputProxy, matrix, clip, top,
|
||||
this->drawRect(renderTargetContext.get(), inputTexture.get(), matrix, clip, top,
|
||||
kTop_BoundaryMode, pSrcBounds, offsetBounds);
|
||||
this->drawRect(context, renderTargetContext.get(), inputProxy, matrix, clip, topRight,
|
||||
this->drawRect(renderTargetContext.get(), inputTexture.get(), matrix, clip, topRight,
|
||||
kTopRight_BoundaryMode, pSrcBounds, offsetBounds);
|
||||
this->drawRect(context, renderTargetContext.get(), inputProxy, matrix, clip, left,
|
||||
this->drawRect(renderTargetContext.get(), inputTexture.get(), matrix, clip, left,
|
||||
kLeft_BoundaryMode, pSrcBounds, offsetBounds);
|
||||
this->drawRect(context, renderTargetContext.get(), inputProxy, matrix, clip, interior,
|
||||
this->drawRect(renderTargetContext.get(), inputTexture.get(), matrix, clip, interior,
|
||||
kInterior_BoundaryMode, pSrcBounds, offsetBounds);
|
||||
this->drawRect(context, renderTargetContext.get(), inputProxy, matrix, clip, right,
|
||||
this->drawRect(renderTargetContext.get(), inputTexture.get(), matrix, clip, right,
|
||||
kRight_BoundaryMode, pSrcBounds, offsetBounds);
|
||||
this->drawRect(context, renderTargetContext.get(), inputProxy, matrix, clip, bottomLeft,
|
||||
this->drawRect(renderTargetContext.get(), inputTexture.get(), matrix, clip, bottomLeft,
|
||||
kBottomLeft_BoundaryMode, pSrcBounds, offsetBounds);
|
||||
this->drawRect(context, renderTargetContext.get(), inputProxy, matrix, clip, bottom,
|
||||
this->drawRect(renderTargetContext.get(), inputTexture.get(), matrix, clip, bottom,
|
||||
kBottom_BoundaryMode, pSrcBounds, offsetBounds);
|
||||
this->drawRect(context, renderTargetContext.get(), inputProxy, matrix, clip, bottomRight,
|
||||
this->drawRect(renderTargetContext.get(), inputTexture.get(), matrix, clip, bottomRight,
|
||||
kBottomRight_BoundaryMode, pSrcBounds, offsetBounds);
|
||||
|
||||
return SkSpecialImage::MakeDeferredFromGpu(
|
||||
@ -495,8 +493,8 @@ protected:
|
||||
SkIPoint* offset) const override;
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
sk_sp<GrFragmentProcessor> makeFragmentProcessor(GrContext*, sk_sp<GrTextureProxy>,
|
||||
const SkMatrix&, const SkIRect* bounds,
|
||||
sk_sp<GrFragmentProcessor> makeFragmentProcessor(GrTexture*, const SkMatrix&,
|
||||
const SkIRect* bounds,
|
||||
BoundaryMode) const override;
|
||||
#endif
|
||||
|
||||
@ -531,8 +529,8 @@ protected:
|
||||
SkIPoint* offset) const override;
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
sk_sp<GrFragmentProcessor> makeFragmentProcessor(GrContext*, sk_sp<GrTextureProxy>,
|
||||
const SkMatrix&, const SkIRect* bounds,
|
||||
sk_sp<GrFragmentProcessor> makeFragmentProcessor(GrTexture*, const SkMatrix&,
|
||||
const SkIRect* bounds,
|
||||
BoundaryMode) const override;
|
||||
#endif
|
||||
|
||||
@ -547,8 +545,7 @@ private:
|
||||
|
||||
class GrLightingEffect : public GrSingleTextureEffect {
|
||||
public:
|
||||
GrLightingEffect(GrContext*, sk_sp<GrTextureProxy>,
|
||||
const SkImageFilterLight* light, SkScalar surfaceScale,
|
||||
GrLightingEffect(GrTexture* texture, const SkImageFilterLight* light, SkScalar surfaceScale,
|
||||
const SkMatrix& matrix, BoundaryMode boundaryMode, const SkIRect* srcBounds);
|
||||
~GrLightingEffect() override;
|
||||
|
||||
@ -578,8 +575,7 @@ private:
|
||||
|
||||
class GrDiffuseLightingEffect : public GrLightingEffect {
|
||||
public:
|
||||
static sk_sp<GrFragmentProcessor> Make(GrContext* context,
|
||||
sk_sp<GrTextureProxy> proxy,
|
||||
static sk_sp<GrFragmentProcessor> Make(GrTexture* texture,
|
||||
const SkImageFilterLight* light,
|
||||
SkScalar surfaceScale,
|
||||
const SkMatrix& matrix,
|
||||
@ -587,8 +583,8 @@ public:
|
||||
BoundaryMode boundaryMode,
|
||||
const SkIRect* srcBounds) {
|
||||
return sk_sp<GrFragmentProcessor>(
|
||||
new GrDiffuseLightingEffect(context, std::move(proxy), light,
|
||||
surfaceScale, matrix, kd, boundaryMode, srcBounds));
|
||||
new GrDiffuseLightingEffect(texture, light, surfaceScale, matrix, kd, boundaryMode,
|
||||
srcBounds));
|
||||
}
|
||||
|
||||
const char* name() const override { return "DiffuseLighting"; }
|
||||
@ -602,7 +598,7 @@ private:
|
||||
|
||||
bool onIsEqual(const GrFragmentProcessor&) const override;
|
||||
|
||||
GrDiffuseLightingEffect(GrContext*, sk_sp<GrTextureProxy>,
|
||||
GrDiffuseLightingEffect(GrTexture* texture,
|
||||
const SkImageFilterLight* light,
|
||||
SkScalar surfaceScale,
|
||||
const SkMatrix& matrix,
|
||||
@ -611,15 +607,13 @@ private:
|
||||
const SkIRect* srcBounds);
|
||||
|
||||
GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
|
||||
SkScalar fKD;
|
||||
|
||||
typedef GrLightingEffect INHERITED;
|
||||
SkScalar fKD;
|
||||
};
|
||||
|
||||
class GrSpecularLightingEffect : public GrLightingEffect {
|
||||
public:
|
||||
static sk_sp<GrFragmentProcessor> Make(GrContext* context,
|
||||
sk_sp<GrTextureProxy> proxy,
|
||||
static sk_sp<GrFragmentProcessor> Make(GrTexture* texture,
|
||||
const SkImageFilterLight* light,
|
||||
SkScalar surfaceScale,
|
||||
const SkMatrix& matrix,
|
||||
@ -628,8 +622,7 @@ public:
|
||||
BoundaryMode boundaryMode,
|
||||
const SkIRect* srcBounds) {
|
||||
return sk_sp<GrFragmentProcessor>(
|
||||
new GrSpecularLightingEffect(context, std::move(proxy),
|
||||
light, surfaceScale, matrix, ks, shininess,
|
||||
new GrSpecularLightingEffect(texture, light, surfaceScale, matrix, ks, shininess,
|
||||
boundaryMode, srcBounds));
|
||||
}
|
||||
|
||||
@ -645,7 +638,7 @@ private:
|
||||
|
||||
bool onIsEqual(const GrFragmentProcessor&) const override;
|
||||
|
||||
GrSpecularLightingEffect(GrContext*, sk_sp<GrTextureProxy>,
|
||||
GrSpecularLightingEffect(GrTexture* texture,
|
||||
const SkImageFilterLight* light,
|
||||
SkScalar surfaceScale,
|
||||
const SkMatrix& matrix,
|
||||
@ -655,10 +648,9 @@ private:
|
||||
const SkIRect* srcBounds);
|
||||
|
||||
GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
|
||||
typedef GrLightingEffect INHERITED;
|
||||
SkScalar fKS;
|
||||
SkScalar fShininess;
|
||||
|
||||
typedef GrLightingEffect INHERITED;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -1356,14 +1348,12 @@ void SkDiffuseLightingImageFilter::toString(SkString* str) const {
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
sk_sp<GrFragmentProcessor> SkDiffuseLightingImageFilter::makeFragmentProcessor(
|
||||
GrContext* context,
|
||||
sk_sp<GrTextureProxy> proxy,
|
||||
GrTexture* texture,
|
||||
const SkMatrix& matrix,
|
||||
const SkIRect* srcBounds,
|
||||
BoundaryMode boundaryMode) const {
|
||||
SkScalar scale = SkScalarMul(this->surfaceScale(), SkIntToScalar(255));
|
||||
return GrDiffuseLightingEffect::Make(context, std::move(proxy),
|
||||
this->light(), scale, matrix, this->kd(),
|
||||
return GrDiffuseLightingEffect::Make(texture, this->light(), scale, matrix, this->kd(),
|
||||
boundaryMode, srcBounds);
|
||||
}
|
||||
#endif
|
||||
@ -1523,14 +1513,12 @@ void SkSpecularLightingImageFilter::toString(SkString* str) const {
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
sk_sp<GrFragmentProcessor> SkSpecularLightingImageFilter::makeFragmentProcessor(
|
||||
GrContext* context,
|
||||
sk_sp<GrTextureProxy> proxy,
|
||||
GrTexture* texture,
|
||||
const SkMatrix& matrix,
|
||||
const SkIRect* srcBounds,
|
||||
BoundaryMode boundaryMode) const {
|
||||
SkScalar scale = SkScalarMul(this->surfaceScale(), SkIntToScalar(255));
|
||||
return GrSpecularLightingEffect::Make(context, std::move(proxy), this->light(),
|
||||
scale, matrix, this->ks(),
|
||||
return GrSpecularLightingEffect::Make(texture, this->light(), scale, matrix, this->ks(),
|
||||
this->shininess(), boundaryMode, srcBounds);
|
||||
}
|
||||
#endif
|
||||
@ -1703,30 +1691,29 @@ private:
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static GrTextureDomain create_domain(GrTextureProxy* proxy, const SkIRect* srcBounds,
|
||||
static GrTextureDomain create_domain(GrTexture* texture, const SkIRect* srcBounds,
|
||||
GrTextureDomain::Mode mode) {
|
||||
if (srcBounds) {
|
||||
SkRect texelDomain = GrTextureDomain::MakeTexelDomainForMode(*srcBounds, mode);
|
||||
return GrTextureDomain(proxy, texelDomain, mode);
|
||||
return GrTextureDomain(texture, texelDomain, mode);
|
||||
} else {
|
||||
return GrTextureDomain::IgnoredDomain();
|
||||
}
|
||||
}
|
||||
|
||||
GrLightingEffect::GrLightingEffect(GrContext* context,
|
||||
sk_sp<GrTextureProxy> proxy,
|
||||
GrLightingEffect::GrLightingEffect(GrTexture* texture,
|
||||
const SkImageFilterLight* light,
|
||||
SkScalar surfaceScale,
|
||||
const SkMatrix& matrix,
|
||||
BoundaryMode boundaryMode,
|
||||
const SkIRect* srcBounds)
|
||||
// Perhaps this could advertise the opaque or modulating optimizations?
|
||||
: INHERITED(context, kNone_OptimizationFlags, proxy, nullptr, SkMatrix::I())
|
||||
: INHERITED(texture, nullptr, SkMatrix::I(), kNone_OptimizationFlags)
|
||||
, fLight(light)
|
||||
, fSurfaceScale(surfaceScale)
|
||||
, fFilterMatrix(matrix)
|
||||
, fBoundaryMode(boundaryMode)
|
||||
, fDomain(create_domain(proxy.get(), srcBounds, GrTextureDomain::kDecal_Mode)) {
|
||||
, fDomain(create_domain(texture, srcBounds, GrTextureDomain::kDecal_Mode)) {
|
||||
fLight->ref();
|
||||
if (light->requiresFragmentPosition()) {
|
||||
this->setWillReadFragmentPosition();
|
||||
@ -1746,16 +1733,14 @@ bool GrLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
GrDiffuseLightingEffect::GrDiffuseLightingEffect(GrContext* context,
|
||||
sk_sp<GrTextureProxy> proxy,
|
||||
GrDiffuseLightingEffect::GrDiffuseLightingEffect(GrTexture* texture,
|
||||
const SkImageFilterLight* light,
|
||||
SkScalar surfaceScale,
|
||||
const SkMatrix& matrix,
|
||||
SkScalar kd,
|
||||
BoundaryMode boundaryMode,
|
||||
const SkIRect* srcBounds)
|
||||
: INHERITED(context, std::move(proxy), light, surfaceScale, matrix,
|
||||
boundaryMode, srcBounds), fKD(kd) {
|
||||
: INHERITED(texture, light, surfaceScale, matrix, boundaryMode, srcBounds), fKD(kd) {
|
||||
this->initClassID<GrDiffuseLightingEffect>();
|
||||
}
|
||||
|
||||
@ -1777,9 +1762,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;
|
||||
sk_sp<GrTextureProxy> proxy = d->textureProxy(texIdx);
|
||||
int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx :
|
||||
GrProcessorUnitTest::kAlphaTextureIdx;
|
||||
GrTexture* tex = d->fTextures[texIdx];
|
||||
SkScalar surfaceScale = d->fRandom->nextSScalar1();
|
||||
SkScalar kd = d->fRandom->nextUScalar1();
|
||||
sk_sp<SkImageFilterLight> light(create_random_light(d->fRandom));
|
||||
@ -1787,14 +1772,13 @@ 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, proxy->width()),
|
||||
d->fRandom->nextRangeU(0, proxy->height()),
|
||||
d->fRandom->nextRangeU(0, proxy->width()),
|
||||
d->fRandom->nextRangeU(0, proxy->height()));
|
||||
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()));
|
||||
BoundaryMode mode = static_cast<BoundaryMode>(d->fRandom->nextU() % kBoundaryModeCount);
|
||||
return GrDiffuseLightingEffect::Make(d->context(),
|
||||
std::move(proxy), light.get(), surfaceScale,
|
||||
matrix, kd, mode, &srcBounds);
|
||||
return GrDiffuseLightingEffect::Make(tex, light.get(), surfaceScale, matrix, kd, mode,
|
||||
&srcBounds);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -1964,8 +1948,7 @@ void GrGLDiffuseLightingEffect::onSetData(const GrGLSLProgramDataManager& pdman,
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
GrSpecularLightingEffect::GrSpecularLightingEffect(GrContext* context,
|
||||
sk_sp<GrTextureProxy> proxy,
|
||||
GrSpecularLightingEffect::GrSpecularLightingEffect(GrTexture* texture,
|
||||
const SkImageFilterLight* light,
|
||||
SkScalar surfaceScale,
|
||||
const SkMatrix& matrix,
|
||||
@ -1973,7 +1956,7 @@ GrSpecularLightingEffect::GrSpecularLightingEffect(GrContext* context,
|
||||
SkScalar shininess,
|
||||
BoundaryMode boundaryMode,
|
||||
const SkIRect* srcBounds)
|
||||
: INHERITED(context, std::move(proxy), light, surfaceScale, matrix, boundaryMode, srcBounds)
|
||||
: INHERITED(texture, light, surfaceScale, matrix, boundaryMode, srcBounds)
|
||||
, fKS(ks)
|
||||
, fShininess(shininess) {
|
||||
this->initClassID<GrSpecularLightingEffect>();
|
||||
@ -1999,9 +1982,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;
|
||||
sk_sp<GrTextureProxy> proxy = d->textureProxy(texIdx);
|
||||
int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx :
|
||||
GrProcessorUnitTest::kAlphaTextureIdx;
|
||||
GrTexture* tex = d->fTextures[texIdx];
|
||||
SkScalar surfaceScale = d->fRandom->nextSScalar1();
|
||||
SkScalar ks = d->fRandom->nextUScalar1();
|
||||
SkScalar shininess = d->fRandom->nextUScalar1();
|
||||
@ -2011,11 +1994,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, 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),
|
||||
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],
|
||||
light.get(), surfaceScale, matrix, ks, shininess, mode,
|
||||
&srcBounds);
|
||||
}
|
||||
|
@ -18,7 +18,6 @@
|
||||
#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"
|
||||
@ -26,55 +25,20 @@
|
||||
#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 SkIRect& bounds,
|
||||
const SkRect& srcRect,
|
||||
const SkRect& bounds,
|
||||
float xOffset,
|
||||
float yOffset,
|
||||
float xInvZoom,
|
||||
float yInvZoom,
|
||||
float xInvInset,
|
||||
float yInvInset) {
|
||||
return sk_sp<GrFragmentProcessor>(new GrMagnifierEffect(texture, std::move(colorSpaceXform),
|
||||
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,
|
||||
bounds, xOffset, yOffset,
|
||||
xInvZoom, yInvZoom,
|
||||
xInvInset, yInvInset));
|
||||
}
|
||||
@ -83,8 +47,10 @@ public:
|
||||
|
||||
const char* name() const override { return "Magnifier"; }
|
||||
|
||||
const SkIRect& bounds() const { return fBounds; } // Bounds of source image.
|
||||
const SkRect& srcRect() const { return fSrcRect; }
|
||||
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; }
|
||||
|
||||
// Scale to apply to zoomed pixels (srcRect size / bounds size).
|
||||
float xInvZoom() const { return fXInvZoom; }
|
||||
@ -97,8 +63,9 @@ public:
|
||||
private:
|
||||
GrMagnifierEffect(GrTexture* texture,
|
||||
sk_sp<GrColorSpaceXform> colorSpaceXform,
|
||||
const SkIRect& bounds,
|
||||
const SkRect& srcRect,
|
||||
const SkRect& bounds,
|
||||
float xOffset,
|
||||
float yOffset,
|
||||
float xInvZoom,
|
||||
float yInvZoom,
|
||||
float xInvInset,
|
||||
@ -106,30 +73,8 @@ private:
|
||||
: INHERITED(texture, std::move(colorSpaceXform), SkMatrix::I(),
|
||||
ModulationFlags(texture->config()))
|
||||
, fBounds(bounds)
|
||||
, 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)
|
||||
, fXOffset(xOffset)
|
||||
, fYOffset(yOffset)
|
||||
, fXInvZoom(xInvZoom)
|
||||
, fYInvZoom(yInvZoom)
|
||||
, fXInvInset(xInvInset)
|
||||
@ -147,8 +92,9 @@ private:
|
||||
|
||||
GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
|
||||
|
||||
SkIRect fBounds;
|
||||
SkRect fSrcRect;
|
||||
SkRect fBounds;
|
||||
float fXOffset;
|
||||
float fYOffset;
|
||||
float fXInvZoom;
|
||||
float fYInvZoom;
|
||||
float fXInvInset;
|
||||
@ -241,38 +187,11 @@ void GrGLMagnifierEffect::emitCode(EmitArgs& args) {
|
||||
void GrGLMagnifierEffect::onSetData(const GrGLSLProgramDataManager& pdman,
|
||||
const GrProcessor& effect) {
|
||||
const GrMagnifierEffect& zoom = effect.cast<GrMagnifierEffect>();
|
||||
|
||||
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(fOffsetVar, zoom.xOffset(), zoom.yOffset());
|
||||
pdman.set2f(fInvZoomVar, zoom.xInvZoom(), zoom.yInvZoom());
|
||||
pdman.set2f(fInvInsetVar, zoom.xInvInset(), zoom.yInvInset());
|
||||
|
||||
{
|
||||
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());
|
||||
}
|
||||
|
||||
pdman.set4f(fBoundsVar, zoom.bounds().x(), zoom.bounds().y(),
|
||||
zoom.bounds().width(), zoom.bounds().height());
|
||||
if (SkToBool(zoom.colorSpaceXform())) {
|
||||
pdman.setSkMatrix44(fColorSpaceXformVar, zoom.colorSpaceXform()->srcToDst());
|
||||
}
|
||||
@ -293,28 +212,27 @@ GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrMagnifierEffect);
|
||||
|
||||
#if GR_TEST_UTILS
|
||||
sk_sp<GrFragmentProcessor> GrMagnifierEffect::TestCreate(GrProcessorTestData* d) {
|
||||
sk_sp<GrTextureProxy> proxy = d->textureProxy(0);
|
||||
GrTexture* texture = d->fTextures[0];
|
||||
const int kMaxWidth = 200;
|
||||
const int kMaxHeight = 200;
|
||||
const SkScalar kMaxInset = 20.0f;
|
||||
const int kMaxInset = 20;
|
||||
uint32_t width = d->fRandom->nextULessThan(kMaxWidth);
|
||||
uint32_t height = d->fRandom->nextULessThan(kMaxHeight);
|
||||
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));
|
||||
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);
|
||||
|
||||
sk_sp<GrFragmentProcessor> effect(GrMagnifierEffect::Make(
|
||||
d->context(),
|
||||
std::move(proxy),
|
||||
texture,
|
||||
std::move(colorSpaceXform),
|
||||
bounds,
|
||||
srcRect,
|
||||
srcRect.width() / bounds.width(),
|
||||
srcRect.height() / bounds.height(),
|
||||
bounds.width() / inset,
|
||||
bounds.height() / inset));
|
||||
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()));
|
||||
SkASSERT(effect);
|
||||
return effect;
|
||||
}
|
||||
@ -325,7 +243,8 @@ 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->fSrcRect == s.fSrcRect &&
|
||||
this->fXOffset == s.fXOffset &&
|
||||
this->fYOffset == s.fYOffset &&
|
||||
this->fXInvZoom == s.fXInvZoom &&
|
||||
this->fYInvZoom == s.fYInvZoom &&
|
||||
this->fXInvInset == s.fXInvInset &&
|
||||
@ -340,6 +259,23 @@ 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,
|
||||
@ -347,7 +283,7 @@ SkMagnifierImageFilter::SkMagnifierImageFilter(const SkRect& srcRect,
|
||||
: INHERITED(&input, 1, cropRect)
|
||||
, fSrcRect(srcRect)
|
||||
, fInset(inset) {
|
||||
SkASSERT(srcRect.left() >= 0 && srcRect.top() >= 0 && inset >= 0);
|
||||
SkASSERT(srcRect.x() >= 0 && srcRect.y() >= 0 && inset >= 0);
|
||||
}
|
||||
|
||||
sk_sp<SkFlattenable> SkMagnifierImageFilter::CreateProc(SkReadBuffer& buffer) {
|
||||
@ -390,22 +326,35 @@ sk_sp<SkSpecialImage> SkMagnifierImageFilter::onFilterImage(SkSpecialImage* sour
|
||||
if (source->isTextureBacked()) {
|
||||
GrContext* context = source->getContext();
|
||||
|
||||
sk_sp<GrTextureProxy> inputProxy(input->asTextureProxyRef(context));
|
||||
SkASSERT(inputProxy);
|
||||
sk_sp<GrTexture> inputTexture(input->asTextureRef(context));
|
||||
SkASSERT(inputTexture);
|
||||
|
||||
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(
|
||||
context,
|
||||
std::move(inputProxy),
|
||||
inputTexture.get(),
|
||||
std::move(colorSpaceXform),
|
||||
bounds,
|
||||
fSrcRect,
|
||||
effectBounds,
|
||||
fSrcRect.x() / inputTexture->width(),
|
||||
yOffset / inputTexture->height(),
|
||||
invXZoom,
|
||||
invYZoom,
|
||||
bounds.width() * invInset,
|
||||
|
@ -311,15 +311,14 @@ 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<GrTextureProxy> inputProxy(input->asTextureProxyRef(context));
|
||||
SkASSERT(inputProxy);
|
||||
sk_sp<GrTexture> inputTexture(input->asTextureRef(context));
|
||||
SkASSERT(inputTexture);
|
||||
|
||||
offset->fX = bounds.left();
|
||||
offset->fY = bounds.top();
|
||||
bounds.offset(-inputOffset);
|
||||
|
||||
sk_sp<GrFragmentProcessor> fp(GrMatrixConvolutionEffect::Make(context,
|
||||
std::move(inputProxy),
|
||||
sk_sp<GrFragmentProcessor> fp(GrMatrixConvolutionEffect::Make(inputTexture.get(),
|
||||
bounds,
|
||||
fKernelSize,
|
||||
fKernel,
|
||||
|
@ -486,7 +486,7 @@ static sk_sp<SkSpecialImage> apply_morphology(
|
||||
GrMorphologyEffect::MorphologyType morphType,
|
||||
SkISize radius,
|
||||
const SkImageFilter::OutputProperties& outputProperties) {
|
||||
sk_sp<GrTextureProxy> srcTexture(input->asTextureProxyRef(context));
|
||||
sk_sp<GrTextureProxy> srcTexture(input->asTextureProxy(context));
|
||||
SkASSERT(srcTexture);
|
||||
sk_sp<SkColorSpace> colorSpace = sk_ref_sp(outputProperties.colorSpace());
|
||||
GrPixelConfig config = GrRenderableConfigForColorSpace(colorSpace.get());
|
||||
|
@ -235,26 +235,26 @@ sk_sp<SkSpecialImage> SkXfermodeImageFilter_Base::filterImageGPU(
|
||||
|
||||
GrContext* context = source->getContext();
|
||||
|
||||
sk_sp<GrTextureProxy> backgroundProxy, foregroundProxy;
|
||||
|
||||
sk_sp<GrTexture> backgroundTex, foregroundTex;
|
||||
|
||||
if (background) {
|
||||
backgroundProxy = background->asTextureProxyRef(context);
|
||||
backgroundTex = background->asTextureRef(context);
|
||||
}
|
||||
|
||||
if (foreground) {
|
||||
foregroundProxy = foreground->asTextureProxyRef(context);
|
||||
foregroundTex = foreground->asTextureRef(context);
|
||||
}
|
||||
|
||||
GrPaint paint;
|
||||
sk_sp<GrFragmentProcessor> bgFP;
|
||||
|
||||
if (backgroundProxy) {
|
||||
SkMatrix bgMatrix = SkMatrix::MakeTrans(-SkIntToScalar(backgroundOffset.fX),
|
||||
-SkIntToScalar(backgroundOffset.fY));
|
||||
if (backgroundTex) {
|
||||
SkMatrix backgroundMatrix = SkMatrix::MakeTrans(-SkIntToScalar(backgroundOffset.fX),
|
||||
-SkIntToScalar(backgroundOffset.fY));
|
||||
sk_sp<GrColorSpaceXform> bgXform = GrColorSpaceXform::Make(background->getColorSpace(),
|
||||
outputProperties.colorSpace());
|
||||
bgFP = GrTextureDomainEffect::Make(
|
||||
context, std::move(backgroundProxy), std::move(bgXform), bgMatrix,
|
||||
backgroundTex.get(), std::move(bgXform), backgroundMatrix,
|
||||
GrTextureDomain::MakeTexelDomain(background->subset()),
|
||||
GrTextureDomain::kDecal_Mode,
|
||||
GrSamplerParams::kNone_FilterMode);
|
||||
@ -263,15 +263,15 @@ sk_sp<SkSpecialImage> SkXfermodeImageFilter_Base::filterImageGPU(
|
||||
GrConstColorProcessor::kIgnore_InputMode);
|
||||
}
|
||||
|
||||
if (foregroundProxy) {
|
||||
SkMatrix fgMatrix = SkMatrix::MakeTrans(-SkIntToScalar(foregroundOffset.fX),
|
||||
-SkIntToScalar(foregroundOffset.fY));
|
||||
if (foregroundTex) {
|
||||
SkMatrix foregroundMatrix = 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(
|
||||
context, std::move(foregroundProxy), std::move(fgXform), fgMatrix,
|
||||
foregroundTex.get(), std::move(fgXform), foregroundMatrix,
|
||||
GrTextureDomain::MakeTexelDomain(foreground->subset()),
|
||||
GrTextureDomain::kDecal_Mode,
|
||||
GrSamplerParams::kNone_FilterMode);
|
||||
|
@ -1178,29 +1178,25 @@ void SkGpuDevice::drawSpecial(const SkDraw& draw,
|
||||
}
|
||||
|
||||
SkASSERT(result->isTextureBacked());
|
||||
sk_sp<GrTextureProxy> proxy = result->asTextureProxyRef(fContext.get());
|
||||
if (!proxy) {
|
||||
sk_sp<GrTexture> texture = result->asTextureRef(fContext.get());
|
||||
if (!texture) {
|
||||
return;
|
||||
}
|
||||
|
||||
const GrPixelConfig config = proxy->config();
|
||||
|
||||
SkPaint tmpUnfiltered(paint);
|
||||
tmpUnfiltered.setImageFilter(nullptr);
|
||||
|
||||
sk_sp<GrColorSpaceXform> colorSpaceXform =
|
||||
GrColorSpaceXform::Make(result->getColorSpace(), fRenderTargetContext->getColorSpace());
|
||||
sk_sp<GrFragmentProcessor> fp(GrSimpleTextureEffect::Make(fContext.get(),
|
||||
std::move(proxy),
|
||||
GrPaint grPaint;
|
||||
sk_sp<GrFragmentProcessor> fp(GrSimpleTextureEffect::Make(texture.get(),
|
||||
std::move(colorSpaceXform),
|
||||
SkMatrix::I()));
|
||||
if (GrPixelConfigIsAlphaOnly(config)) {
|
||||
if (GrPixelConfigIsAlphaOnly(texture->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;
|
||||
|
@ -291,7 +291,9 @@ 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;
|
||||
}
|
||||
@ -300,13 +302,11 @@ sk_sp<SkImage> SkImage::makeWithFilter(const SkImageFilter* filter, const SkIRec
|
||||
#if SK_SUPPORT_GPU
|
||||
if (result->isTextureBacked()) {
|
||||
GrContext* context = result->getContext();
|
||||
sk_sp<GrTextureProxy> proxy = result->asTextureProxyRef(context);
|
||||
if (!proxy) {
|
||||
sk_sp<GrTexture> texture = result->asTextureRef(context);
|
||||
if (!texture) {
|
||||
return nullptr;
|
||||
}
|
||||
// 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());
|
||||
fullSize = SkIRect::MakeWH(texture->width(), texture->height());
|
||||
}
|
||||
#endif
|
||||
*outSubset = SkIRect::MakeWH(result->width(), result->height());
|
||||
|
@ -65,10 +65,10 @@ static void test_image(const sk_sp<SkSpecialImage>& img, skiatest::Reporter* rep
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
//--------------
|
||||
// Test asTextureProxyRef - as long as there is a context this should succeed
|
||||
// Test getTextureAsRef - as long as there is a context this should succeed
|
||||
if (context) {
|
||||
sk_sp<GrTextureProxy> proxy(img->asTextureProxyRef(context));
|
||||
REPORTER_ASSERT(reporter, proxy);
|
||||
sk_sp<GrTexture> texture(img->asTextureRef(context));
|
||||
REPORTER_ASSERT(reporter, texture);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user