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
|
#if SK_SUPPORT_GPU
|
||||||
#include "include/gpu/GrContext.h"
|
#include "include/gpu/GrContext.h"
|
||||||
#include "src/gpu/GrColorSpaceXform.h"
|
#include "src/gpu/GrColorSpaceXform.h"
|
||||||
#include "src/gpu/GrCoordTransform.h"
|
#include "src/gpu/effects/GrTextureEffect.h"
|
||||||
#include "src/gpu/GrTexture.h"
|
|
||||||
#include "src/gpu/effects/generated/GrMagnifierEffect.h"
|
#include "src/gpu/effects/generated/GrMagnifierEffect.h"
|
||||||
#include "src/gpu/glsl/GrGLSLFragmentProcessor.h"
|
#include "src/gpu/glsl/GrGLSLFragmentProcessor.h"
|
||||||
#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.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());
|
bounds.offset(input->subset().x(), input->subset().y());
|
||||||
SkRect srcRect = fSrcRect.makeOffset((1.f - invXZoom) * input->subset().x(),
|
SkRect srcRect = fSrcRect.makeOffset((1.f - invXZoom) * input->subset().x(),
|
||||||
(1.f - invYZoom) * input->subset().y());
|
(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(inputFP),
|
||||||
auto fp = GrMagnifierEffect::Make(std::move(inputView),
|
|
||||||
bounds,
|
bounds,
|
||||||
srcRect,
|
srcRect,
|
||||||
invXZoom,
|
invXZoom,
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
* found in the LICENSE file.
|
* found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
in uniform sampler2D src;
|
in fragmentProcessor src;
|
||||||
layout(ctype=SkIRect) in int4 bounds;
|
layout(ctype=SkIRect) in int4 bounds;
|
||||||
uniform float4 boundsUniform;
|
uniform float4 boundsUniform;
|
||||||
layout(ctype=SkRect) in float4 srcRect;
|
layout(ctype=SkRect) in float4 srcRect;
|
||||||
@ -16,9 +16,7 @@ in uniform float yInvInset;
|
|||||||
|
|
||||||
uniform half2 offset;
|
uniform half2 offset;
|
||||||
|
|
||||||
@coordTransform(src) {
|
@coordTransform { SkMatrix::I() }
|
||||||
SkMatrix::I()
|
|
||||||
}
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
float2 coord = sk_TransformedCoords2D[0];
|
float2 coord = sk_TransformedCoords2D[0];
|
||||||
@ -42,36 +40,11 @@ void main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@setData(pdman) {
|
@setData(pdman) {
|
||||||
SkScalar invW = 1.0f / src.width();
|
pdman.set2f(offset, srcRect.x(), srcRect.y());
|
||||||
SkScalar invH = 1.0f / src.height();
|
pdman.set4f(boundsUniform, bounds.x(), bounds.y(), 1.f/ bounds.width(), 1.f / bounds.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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@test(d) {
|
@test(d) {
|
||||||
auto [view, ct, at] = d->randomView();
|
|
||||||
const int kMaxWidth = 200;
|
const int kMaxWidth = 200;
|
||||||
const int kMaxHeight = 200;
|
const int kMaxHeight = 200;
|
||||||
const SkScalar kMaxInset = 20.0f;
|
const SkScalar kMaxInset = 20.0f;
|
||||||
@ -82,7 +55,8 @@ void main() {
|
|||||||
SkIRect bounds = SkIRect::MakeWH(SkIntToScalar(kMaxWidth), SkIntToScalar(kMaxHeight));
|
SkIRect bounds = SkIRect::MakeWH(SkIntToScalar(kMaxWidth), SkIntToScalar(kMaxHeight));
|
||||||
SkRect srcRect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height));
|
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,
|
bounds,
|
||||||
srcRect,
|
srcRect,
|
||||||
srcRect.width() / bounds.width(),
|
srcRect.width() / bounds.width(),
|
||||||
|
@ -65,14 +65,11 @@ public:
|
|||||||
args.fUniformHandler->getUniformCStr(boundsUniformVar),
|
args.fUniformHandler->getUniformCStr(boundsUniformVar),
|
||||||
args.fUniformHandler->getUniformCStr(xInvInsetVar),
|
args.fUniformHandler->getUniformCStr(xInvInsetVar),
|
||||||
args.fUniformHandler->getUniformCStr(yInvInsetVar));
|
args.fUniformHandler->getUniformCStr(yInvInsetVar));
|
||||||
fragBuilder->codeAppendf(
|
fragBuilder->codeAppendf("d.y), 1.0);\n}");
|
||||||
"d.y), 1.0);\n}\n%s = sample(%s, mix(coord, zoom_coord, weight)).%s;\n",
|
SkString _sample1112;
|
||||||
args.fOutputColor,
|
SkString _coords1112("mix(coord, zoom_coord, weight)");
|
||||||
fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]),
|
_sample1112 = this->invokeChild(_outer.src_index, args, _coords1112.c_str());
|
||||||
fragBuilder->getProgramBuilder()
|
fragBuilder->codeAppendf("\n%s = %s;\n", args.fOutputColor, _sample1112.c_str());
|
||||||
->samplerSwizzle(args.fTexSamplers[0])
|
|
||||||
.asString()
|
|
||||||
.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -85,9 +82,6 @@ private:
|
|||||||
pdman.set1f(xInvInsetVar, (_outer.xInvInset));
|
pdman.set1f(xInvInsetVar, (_outer.xInvInset));
|
||||||
pdman.set1f(yInvInsetVar, (_outer.yInvInset));
|
pdman.set1f(yInvInsetVar, (_outer.yInvInset));
|
||||||
}
|
}
|
||||||
const GrSurfaceProxyView& srcView = _outer.textureSampler(0).view();
|
|
||||||
GrTexture& src = *srcView.proxy()->peekTexture();
|
|
||||||
(void)src;
|
|
||||||
auto bounds = _outer.bounds;
|
auto bounds = _outer.bounds;
|
||||||
(void)bounds;
|
(void)bounds;
|
||||||
UniformHandle& boundsUniform = boundsUniformVar;
|
UniformHandle& boundsUniform = boundsUniformVar;
|
||||||
@ -105,32 +99,9 @@ private:
|
|||||||
UniformHandle& offset = offsetVar;
|
UniformHandle& offset = offsetVar;
|
||||||
(void)offset;
|
(void)offset;
|
||||||
|
|
||||||
SkScalar invW = 1.0f / src.width();
|
pdman.set2f(offset, srcRect.x(), srcRect.y());
|
||||||
SkScalar invH = 1.0f / src.height();
|
pdman.set4f(
|
||||||
|
boundsUniform, bounds.x(), bounds.y(), 1.f / bounds.width(), 1.f / bounds.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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
UniformHandle boundsUniformVar;
|
UniformHandle boundsUniformVar;
|
||||||
UniformHandle offsetVar;
|
UniformHandle offsetVar;
|
||||||
@ -147,7 +118,6 @@ void GrMagnifierEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
|
|||||||
bool GrMagnifierEffect::onIsEqual(const GrFragmentProcessor& other) const {
|
bool GrMagnifierEffect::onIsEqual(const GrFragmentProcessor& other) const {
|
||||||
const GrMagnifierEffect& that = other.cast<GrMagnifierEffect>();
|
const GrMagnifierEffect& that = other.cast<GrMagnifierEffect>();
|
||||||
(void)that;
|
(void)that;
|
||||||
if (src != that.src) return false;
|
|
||||||
if (bounds != that.bounds) return false;
|
if (bounds != that.bounds) return false;
|
||||||
if (srcRect != that.srcRect) return false;
|
if (srcRect != that.srcRect) return false;
|
||||||
if (xInvZoom != that.xInvZoom) return false;
|
if (xInvZoom != that.xInvZoom) return false;
|
||||||
@ -158,27 +128,22 @@ bool GrMagnifierEffect::onIsEqual(const GrFragmentProcessor& other) const {
|
|||||||
}
|
}
|
||||||
GrMagnifierEffect::GrMagnifierEffect(const GrMagnifierEffect& src)
|
GrMagnifierEffect::GrMagnifierEffect(const GrMagnifierEffect& src)
|
||||||
: INHERITED(kGrMagnifierEffect_ClassID, src.optimizationFlags())
|
: INHERITED(kGrMagnifierEffect_ClassID, src.optimizationFlags())
|
||||||
, srcCoordTransform(src.srcCoordTransform)
|
, fCoordTransform0(src.fCoordTransform0)
|
||||||
, src(src.src)
|
|
||||||
, bounds(src.bounds)
|
, bounds(src.bounds)
|
||||||
, srcRect(src.srcRect)
|
, srcRect(src.srcRect)
|
||||||
, xInvZoom(src.xInvZoom)
|
, xInvZoom(src.xInvZoom)
|
||||||
, yInvZoom(src.yInvZoom)
|
, yInvZoom(src.yInvZoom)
|
||||||
, xInvInset(src.xInvInset)
|
, xInvInset(src.xInvInset)
|
||||||
, yInvInset(src.yInvInset) {
|
, yInvInset(src.yInvInset) {
|
||||||
this->setTextureSamplerCnt(1);
|
{ src_index = this->cloneAndRegisterChildProcessor(src.childProcessor(src.src_index)); }
|
||||||
this->addCoordTransform(&srcCoordTransform);
|
this->addCoordTransform(&fCoordTransform0);
|
||||||
}
|
}
|
||||||
std::unique_ptr<GrFragmentProcessor> GrMagnifierEffect::clone() const {
|
std::unique_ptr<GrFragmentProcessor> GrMagnifierEffect::clone() const {
|
||||||
return std::unique_ptr<GrFragmentProcessor>(new GrMagnifierEffect(*this));
|
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);
|
GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrMagnifierEffect);
|
||||||
#if GR_TEST_UTILS
|
#if GR_TEST_UTILS
|
||||||
std::unique_ptr<GrFragmentProcessor> GrMagnifierEffect::TestCreate(GrProcessorTestData* d) {
|
std::unique_ptr<GrFragmentProcessor> GrMagnifierEffect::TestCreate(GrProcessorTestData* d) {
|
||||||
auto[view, ct, at] = d->randomView();
|
|
||||||
const int kMaxWidth = 200;
|
const int kMaxWidth = 200;
|
||||||
const int kMaxHeight = 200;
|
const int kMaxHeight = 200;
|
||||||
const SkScalar kMaxInset = 20.0f;
|
const SkScalar kMaxInset = 20.0f;
|
||||||
@ -189,7 +154,8 @@ std::unique_ptr<GrFragmentProcessor> GrMagnifierEffect::TestCreate(GrProcessorTe
|
|||||||
SkIRect bounds = SkIRect::MakeWH(SkIntToScalar(kMaxWidth), SkIntToScalar(kMaxHeight));
|
SkIRect bounds = SkIRect::MakeWH(SkIntToScalar(kMaxWidth), SkIntToScalar(kMaxHeight));
|
||||||
SkRect srcRect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height));
|
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,
|
bounds,
|
||||||
srcRect,
|
srcRect,
|
||||||
srcRect.width() / bounds.width(),
|
srcRect.width() / bounds.width(),
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
class GrMagnifierEffect : public GrFragmentProcessor {
|
class GrMagnifierEffect : public GrFragmentProcessor {
|
||||||
public:
|
public:
|
||||||
static std::unique_ptr<GrFragmentProcessor> Make(GrSurfaceProxyView src,
|
static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> src,
|
||||||
SkIRect bounds,
|
SkIRect bounds,
|
||||||
SkRect srcRect,
|
SkRect srcRect,
|
||||||
float xInvZoom,
|
float xInvZoom,
|
||||||
@ -32,8 +32,8 @@ public:
|
|||||||
GrMagnifierEffect(const GrMagnifierEffect& src);
|
GrMagnifierEffect(const GrMagnifierEffect& src);
|
||||||
std::unique_ptr<GrFragmentProcessor> clone() const override;
|
std::unique_ptr<GrFragmentProcessor> clone() const override;
|
||||||
const char* name() const override { return "MagnifierEffect"; }
|
const char* name() const override { return "MagnifierEffect"; }
|
||||||
GrCoordTransform srcCoordTransform;
|
GrCoordTransform fCoordTransform0;
|
||||||
TextureSampler src;
|
int src_index = -1;
|
||||||
SkIRect bounds;
|
SkIRect bounds;
|
||||||
SkRect srcRect;
|
SkRect srcRect;
|
||||||
float xInvZoom;
|
float xInvZoom;
|
||||||
@ -42,7 +42,7 @@ public:
|
|||||||
float yInvInset;
|
float yInvInset;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GrMagnifierEffect(GrSurfaceProxyView src,
|
GrMagnifierEffect(std::unique_ptr<GrFragmentProcessor> src,
|
||||||
SkIRect bounds,
|
SkIRect bounds,
|
||||||
SkRect srcRect,
|
SkRect srcRect,
|
||||||
float xInvZoom,
|
float xInvZoom,
|
||||||
@ -50,21 +50,21 @@ private:
|
|||||||
float xInvInset,
|
float xInvInset,
|
||||||
float yInvInset)
|
float yInvInset)
|
||||||
: INHERITED(kGrMagnifierEffect_ClassID, kNone_OptimizationFlags)
|
: INHERITED(kGrMagnifierEffect_ClassID, kNone_OptimizationFlags)
|
||||||
, srcCoordTransform(SkMatrix::I(), src.proxy(), src.origin())
|
, fCoordTransform0(SkMatrix::I())
|
||||||
, src(std::move(src))
|
|
||||||
, bounds(bounds)
|
, bounds(bounds)
|
||||||
, srcRect(srcRect)
|
, srcRect(srcRect)
|
||||||
, xInvZoom(xInvZoom)
|
, xInvZoom(xInvZoom)
|
||||||
, yInvZoom(yInvZoom)
|
, yInvZoom(yInvZoom)
|
||||||
, xInvInset(xInvInset)
|
, xInvInset(xInvInset)
|
||||||
, yInvInset(yInvInset) {
|
, yInvInset(yInvInset) {
|
||||||
this->setTextureSamplerCnt(1);
|
SkASSERT(src);
|
||||||
this->addCoordTransform(&srcCoordTransform);
|
src->setSampledWithExplicitCoords();
|
||||||
|
src_index = this->registerChildProcessor(std::move(src));
|
||||||
|
this->addCoordTransform(&fCoordTransform0);
|
||||||
}
|
}
|
||||||
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
|
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
|
||||||
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
|
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
|
||||||
bool onIsEqual(const GrFragmentProcessor&) const override;
|
bool onIsEqual(const GrFragmentProcessor&) const override;
|
||||||
const TextureSampler& onTextureSampler(int) const override;
|
|
||||||
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
|
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
|
||||||
typedef GrFragmentProcessor INHERITED;
|
typedef GrFragmentProcessor INHERITED;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user