GrMagnifierEffect uses child for src
Bug: skia:10139 Change-Id: I07b95233c7a7892be8b70e7b640c71ce438545f1 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/296803 Reviewed-by: Michael Ludwig <michaelludwig@google.com> Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
parent
4c47d0ddea
commit
f5cd604cb9
@ -19,8 +19,7 @@
|
||||
#if SK_SUPPORT_GPU
|
||||
#include "include/gpu/GrContext.h"
|
||||
#include "src/gpu/GrColorSpaceXform.h"
|
||||
#include "src/gpu/GrCoordTransform.h"
|
||||
#include "src/gpu/GrTexture.h"
|
||||
#include "src/gpu/effects/GrTextureEffect.h"
|
||||
#include "src/gpu/effects/generated/GrMagnifierEffect.h"
|
||||
#include "src/gpu/glsl/GrGLSLFragmentProcessor.h"
|
||||
#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
|
||||
@ -136,9 +135,9 @@ sk_sp<SkSpecialImage> SkMagnifierImageFilterImpl::onFilterImage(const Context& c
|
||||
bounds.offset(input->subset().x(), input->subset().y());
|
||||
SkRect srcRect = fSrcRect.makeOffset((1.f - invXZoom) * input->subset().x(),
|
||||
(1.f - invYZoom) * input->subset().y());
|
||||
auto inputFP = GrTextureEffect::Make(std::move(inputView), kPremul_SkAlphaType);
|
||||
|
||||
// TODO: Update generated fp file Make functions to take views instead of proxies
|
||||
auto fp = GrMagnifierEffect::Make(std::move(inputView),
|
||||
auto fp = GrMagnifierEffect::Make(std::move(inputFP),
|
||||
bounds,
|
||||
srcRect,
|
||||
invXZoom,
|
||||
|
@ -5,7 +5,7 @@
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
in uniform sampler2D src;
|
||||
in fragmentProcessor src;
|
||||
layout(ctype=SkIRect) in int4 bounds;
|
||||
uniform float4 boundsUniform;
|
||||
layout(ctype=SkRect) in float4 srcRect;
|
||||
@ -16,9 +16,7 @@ in uniform float yInvInset;
|
||||
|
||||
uniform half2 offset;
|
||||
|
||||
@coordTransform(src) {
|
||||
SkMatrix::I()
|
||||
}
|
||||
@coordTransform { SkMatrix::I() }
|
||||
|
||||
void main() {
|
||||
float2 coord = sk_TransformedCoords2D[0];
|
||||
@ -42,36 +40,11 @@ void main() {
|
||||
}
|
||||
|
||||
@setData(pdman) {
|
||||
SkScalar invW = 1.0f / src.width();
|
||||
SkScalar invH = 1.0f / src.height();
|
||||
|
||||
{
|
||||
SkScalar y = srcRect.y() * invH;
|
||||
if (srcView.origin() != kTopLeft_GrSurfaceOrigin) {
|
||||
y = 1.0f - (srcRect.height() / bounds.height()) - y;
|
||||
}
|
||||
|
||||
pdman.set2f(offset, srcRect.x() * invW, y);
|
||||
}
|
||||
|
||||
{
|
||||
SkScalar y = bounds.y() * invH;
|
||||
SkScalar hSign = 1.f;
|
||||
if (srcView.origin() != kTopLeft_GrSurfaceOrigin) {
|
||||
y = 1.0f - bounds.y() * invH;
|
||||
hSign = -1.f;
|
||||
}
|
||||
|
||||
pdman.set4f(boundsUniform,
|
||||
bounds.x() * invW,
|
||||
y,
|
||||
SkIntToScalar(src.width()) / bounds.width(),
|
||||
hSign * SkIntToScalar(src.height()) / bounds.height());
|
||||
}
|
||||
pdman.set2f(offset, srcRect.x(), srcRect.y());
|
||||
pdman.set4f(boundsUniform, bounds.x(), bounds.y(), 1.f/ bounds.width(), 1.f / bounds.height());
|
||||
}
|
||||
|
||||
@test(d) {
|
||||
auto [view, ct, at] = d->randomView();
|
||||
const int kMaxWidth = 200;
|
||||
const int kMaxHeight = 200;
|
||||
const SkScalar kMaxInset = 20.0f;
|
||||
@ -82,7 +55,8 @@ void main() {
|
||||
SkIRect bounds = SkIRect::MakeWH(SkIntToScalar(kMaxWidth), SkIntToScalar(kMaxHeight));
|
||||
SkRect srcRect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height));
|
||||
|
||||
auto effect = GrMagnifierEffect::Make(std::move(view),
|
||||
auto src = GrProcessorUnitTest::MakeChildFP(d);
|
||||
auto effect = GrMagnifierEffect::Make(std::move(src),
|
||||
bounds,
|
||||
srcRect,
|
||||
srcRect.width() / bounds.width(),
|
||||
|
@ -65,14 +65,11 @@ public:
|
||||
args.fUniformHandler->getUniformCStr(boundsUniformVar),
|
||||
args.fUniformHandler->getUniformCStr(xInvInsetVar),
|
||||
args.fUniformHandler->getUniformCStr(yInvInsetVar));
|
||||
fragBuilder->codeAppendf(
|
||||
"d.y), 1.0);\n}\n%s = sample(%s, mix(coord, zoom_coord, weight)).%s;\n",
|
||||
args.fOutputColor,
|
||||
fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]),
|
||||
fragBuilder->getProgramBuilder()
|
||||
->samplerSwizzle(args.fTexSamplers[0])
|
||||
.asString()
|
||||
.c_str());
|
||||
fragBuilder->codeAppendf("d.y), 1.0);\n}");
|
||||
SkString _sample1112;
|
||||
SkString _coords1112("mix(coord, zoom_coord, weight)");
|
||||
_sample1112 = this->invokeChild(_outer.src_index, args, _coords1112.c_str());
|
||||
fragBuilder->codeAppendf("\n%s = %s;\n", args.fOutputColor, _sample1112.c_str());
|
||||
}
|
||||
|
||||
private:
|
||||
@ -85,9 +82,6 @@ private:
|
||||
pdman.set1f(xInvInsetVar, (_outer.xInvInset));
|
||||
pdman.set1f(yInvInsetVar, (_outer.yInvInset));
|
||||
}
|
||||
const GrSurfaceProxyView& srcView = _outer.textureSampler(0).view();
|
||||
GrTexture& src = *srcView.proxy()->peekTexture();
|
||||
(void)src;
|
||||
auto bounds = _outer.bounds;
|
||||
(void)bounds;
|
||||
UniformHandle& boundsUniform = boundsUniformVar;
|
||||
@ -105,32 +99,9 @@ private:
|
||||
UniformHandle& offset = offsetVar;
|
||||
(void)offset;
|
||||
|
||||
SkScalar invW = 1.0f / src.width();
|
||||
SkScalar invH = 1.0f / src.height();
|
||||
|
||||
{
|
||||
SkScalar y = srcRect.y() * invH;
|
||||
if (srcView.origin() != kTopLeft_GrSurfaceOrigin) {
|
||||
y = 1.0f - (srcRect.height() / bounds.height()) - y;
|
||||
}
|
||||
|
||||
pdman.set2f(offset, srcRect.x() * invW, y);
|
||||
}
|
||||
|
||||
{
|
||||
SkScalar y = bounds.y() * invH;
|
||||
SkScalar hSign = 1.f;
|
||||
if (srcView.origin() != kTopLeft_GrSurfaceOrigin) {
|
||||
y = 1.0f - bounds.y() * invH;
|
||||
hSign = -1.f;
|
||||
}
|
||||
|
||||
pdman.set4f(boundsUniform,
|
||||
bounds.x() * invW,
|
||||
y,
|
||||
SkIntToScalar(src.width()) / bounds.width(),
|
||||
hSign * SkIntToScalar(src.height()) / bounds.height());
|
||||
}
|
||||
pdman.set2f(offset, srcRect.x(), srcRect.y());
|
||||
pdman.set4f(
|
||||
boundsUniform, bounds.x(), bounds.y(), 1.f / bounds.width(), 1.f / bounds.height());
|
||||
}
|
||||
UniformHandle boundsUniformVar;
|
||||
UniformHandle offsetVar;
|
||||
@ -147,7 +118,6 @@ void GrMagnifierEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
|
||||
bool GrMagnifierEffect::onIsEqual(const GrFragmentProcessor& other) const {
|
||||
const GrMagnifierEffect& that = other.cast<GrMagnifierEffect>();
|
||||
(void)that;
|
||||
if (src != that.src) return false;
|
||||
if (bounds != that.bounds) return false;
|
||||
if (srcRect != that.srcRect) return false;
|
||||
if (xInvZoom != that.xInvZoom) return false;
|
||||
@ -158,27 +128,22 @@ bool GrMagnifierEffect::onIsEqual(const GrFragmentProcessor& other) const {
|
||||
}
|
||||
GrMagnifierEffect::GrMagnifierEffect(const GrMagnifierEffect& src)
|
||||
: INHERITED(kGrMagnifierEffect_ClassID, src.optimizationFlags())
|
||||
, srcCoordTransform(src.srcCoordTransform)
|
||||
, src(src.src)
|
||||
, fCoordTransform0(src.fCoordTransform0)
|
||||
, bounds(src.bounds)
|
||||
, srcRect(src.srcRect)
|
||||
, xInvZoom(src.xInvZoom)
|
||||
, yInvZoom(src.yInvZoom)
|
||||
, xInvInset(src.xInvInset)
|
||||
, yInvInset(src.yInvInset) {
|
||||
this->setTextureSamplerCnt(1);
|
||||
this->addCoordTransform(&srcCoordTransform);
|
||||
{ src_index = this->cloneAndRegisterChildProcessor(src.childProcessor(src.src_index)); }
|
||||
this->addCoordTransform(&fCoordTransform0);
|
||||
}
|
||||
std::unique_ptr<GrFragmentProcessor> GrMagnifierEffect::clone() const {
|
||||
return std::unique_ptr<GrFragmentProcessor>(new GrMagnifierEffect(*this));
|
||||
}
|
||||
const GrFragmentProcessor::TextureSampler& GrMagnifierEffect::onTextureSampler(int index) const {
|
||||
return IthTextureSampler(index, src);
|
||||
}
|
||||
GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrMagnifierEffect);
|
||||
#if GR_TEST_UTILS
|
||||
std::unique_ptr<GrFragmentProcessor> GrMagnifierEffect::TestCreate(GrProcessorTestData* d) {
|
||||
auto[view, ct, at] = d->randomView();
|
||||
const int kMaxWidth = 200;
|
||||
const int kMaxHeight = 200;
|
||||
const SkScalar kMaxInset = 20.0f;
|
||||
@ -189,7 +154,8 @@ std::unique_ptr<GrFragmentProcessor> GrMagnifierEffect::TestCreate(GrProcessorTe
|
||||
SkIRect bounds = SkIRect::MakeWH(SkIntToScalar(kMaxWidth), SkIntToScalar(kMaxHeight));
|
||||
SkRect srcRect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height));
|
||||
|
||||
auto effect = GrMagnifierEffect::Make(std::move(view),
|
||||
auto src = GrProcessorUnitTest::MakeChildFP(d);
|
||||
auto effect = GrMagnifierEffect::Make(std::move(src),
|
||||
bounds,
|
||||
srcRect,
|
||||
srcRect.width() / bounds.width(),
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
class GrMagnifierEffect : public GrFragmentProcessor {
|
||||
public:
|
||||
static std::unique_ptr<GrFragmentProcessor> Make(GrSurfaceProxyView src,
|
||||
static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> src,
|
||||
SkIRect bounds,
|
||||
SkRect srcRect,
|
||||
float xInvZoom,
|
||||
@ -32,8 +32,8 @@ public:
|
||||
GrMagnifierEffect(const GrMagnifierEffect& src);
|
||||
std::unique_ptr<GrFragmentProcessor> clone() const override;
|
||||
const char* name() const override { return "MagnifierEffect"; }
|
||||
GrCoordTransform srcCoordTransform;
|
||||
TextureSampler src;
|
||||
GrCoordTransform fCoordTransform0;
|
||||
int src_index = -1;
|
||||
SkIRect bounds;
|
||||
SkRect srcRect;
|
||||
float xInvZoom;
|
||||
@ -42,7 +42,7 @@ public:
|
||||
float yInvInset;
|
||||
|
||||
private:
|
||||
GrMagnifierEffect(GrSurfaceProxyView src,
|
||||
GrMagnifierEffect(std::unique_ptr<GrFragmentProcessor> src,
|
||||
SkIRect bounds,
|
||||
SkRect srcRect,
|
||||
float xInvZoom,
|
||||
@ -50,21 +50,21 @@ private:
|
||||
float xInvInset,
|
||||
float yInvInset)
|
||||
: INHERITED(kGrMagnifierEffect_ClassID, kNone_OptimizationFlags)
|
||||
, srcCoordTransform(SkMatrix::I(), src.proxy(), src.origin())
|
||||
, src(std::move(src))
|
||||
, fCoordTransform0(SkMatrix::I())
|
||||
, bounds(bounds)
|
||||
, srcRect(srcRect)
|
||||
, xInvZoom(xInvZoom)
|
||||
, yInvZoom(yInvZoom)
|
||||
, xInvInset(xInvInset)
|
||||
, yInvInset(yInvInset) {
|
||||
this->setTextureSamplerCnt(1);
|
||||
this->addCoordTransform(&srcCoordTransform);
|
||||
SkASSERT(src);
|
||||
src->setSampledWithExplicitCoords();
|
||||
src_index = this->registerChildProcessor(std::move(src));
|
||||
this->addCoordTransform(&fCoordTransform0);
|
||||
}
|
||||
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
|
||||
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
|
||||
bool onIsEqual(const GrFragmentProcessor&) const override;
|
||||
const TextureSampler& onTextureSampler(int) const override;
|
||||
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
|
||||
typedef GrFragmentProcessor INHERITED;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user