Revert "GaussianConvolutionFragmentProcessor uses GrTextureEffect."
This reverts commit eb48024f8b
.
Reason for revert: Failing additional layout test on Win10
Original change's description:
> GaussianConvolutionFragmentProcessor uses GrTextureEffect.
>
> Also removes now unused GrShaderVar::appendArrayAccess.
>
> Bug: skia:10139
>
> Change-Id: Ic2583a6822e88510551b1031f3fb130266b3f395
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/283440
> Commit-Queue: Brian Salomon <bsalomon@google.com>
> Reviewed-by: Michael Ludwig <michaelludwig@google.com>
TBR=bsalomon@google.com,michaelludwig@google.com
Change-Id: I7403e97c51ba966e52679b5a048a962795c4271b
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:10139
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/283636
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
parent
e6995c74cd
commit
68626439f3
@ -71,14 +71,19 @@ static float adjust_sigma(float sigma, int maxTextureSize, int *scaleFactor, int
|
||||
return sigma;
|
||||
}
|
||||
|
||||
static GrSamplerState::WrapMode to_wrap_mode(SkTileMode tileMode) {
|
||||
static GrTextureDomain::Mode to_texture_domain_mode(SkTileMode tileMode) {
|
||||
switch (tileMode) {
|
||||
case SkTileMode::kClamp: return GrSamplerState::WrapMode::kClamp;
|
||||
case SkTileMode::kDecal: return GrSamplerState::WrapMode::kClampToBorder;
|
||||
case SkTileMode::kMirror: return GrSamplerState::WrapMode::kMirrorRepeat;
|
||||
case SkTileMode::kRepeat: return GrSamplerState::WrapMode::kRepeat;
|
||||
case SkTileMode::kClamp:
|
||||
return GrTextureDomain::kClamp_Mode;
|
||||
case SkTileMode::kDecal:
|
||||
return GrTextureDomain::kDecal_Mode;
|
||||
case SkTileMode::kMirror:
|
||||
// TODO (michaelludwig) - Support mirror mode, treat as repeat for now
|
||||
case SkTileMode::kRepeat:
|
||||
return GrTextureDomain::kRepeat_Mode;
|
||||
default:
|
||||
SK_ABORT("Unsupported tile mode.");
|
||||
}
|
||||
SkUNREACHABLE;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -96,7 +101,7 @@ static void convolve_gaussian_1d(GrRenderTargetContext* renderTargetContext,
|
||||
SkTileMode mode,
|
||||
int bounds[2]) {
|
||||
GrPaint paint;
|
||||
auto wm = to_wrap_mode(mode);
|
||||
auto domainMode = to_texture_domain_mode(mode);
|
||||
int realBounds[2];
|
||||
if (bounds) {
|
||||
realBounds[0] = bounds[0]; realBounds[1] = bounds[1];
|
||||
@ -106,8 +111,7 @@ static void convolve_gaussian_1d(GrRenderTargetContext* renderTargetContext,
|
||||
realBounds[1] = direction == Direction::kX ? proxy->width() : proxy->height();
|
||||
}
|
||||
std::unique_ptr<GrFragmentProcessor> conv(GrGaussianConvolutionFragmentProcessor::Make(
|
||||
std::move(srcView), srcAlphaType, direction, radius, sigma, wm, realBounds,
|
||||
*renderTargetContext->caps()));
|
||||
std::move(srcView), srcAlphaType, direction, radius, sigma, domainMode, realBounds));
|
||||
paint.addColorFragmentProcessor(std::move(conv));
|
||||
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
|
||||
auto srcRect = SkRect::Make(rtcRect.makeOffset(rtcToSrcOffset));
|
||||
@ -115,20 +119,6 @@ static void convolve_gaussian_1d(GrRenderTargetContext* renderTargetContext,
|
||||
SkRect::Make(rtcRect), srcRect);
|
||||
}
|
||||
|
||||
static GrTextureDomain::Mode to_texture_domain_mode(SkTileMode tileMode) {
|
||||
switch (tileMode) {
|
||||
case SkTileMode::kClamp:
|
||||
return GrTextureDomain::kClamp_Mode;
|
||||
case SkTileMode::kDecal:
|
||||
return GrTextureDomain::kDecal_Mode;
|
||||
case SkTileMode::kMirror:
|
||||
// TODO (michaelludwig) - Support mirror mode, treat as repeat for now
|
||||
case SkTileMode::kRepeat:
|
||||
return GrTextureDomain::kRepeat_Mode;
|
||||
}
|
||||
SkUNREACHABLE;
|
||||
}
|
||||
|
||||
static std::unique_ptr<GrRenderTargetContext> convolve_gaussian_2d(GrRecordingContext* context,
|
||||
GrSurfaceProxyView srcView,
|
||||
GrColorType srcColorType,
|
||||
|
@ -130,6 +130,10 @@ public:
|
||||
/** Write a declaration of this variable to out. */
|
||||
void appendDecl(const GrShaderCaps*, SkString* out) const;
|
||||
|
||||
void appendArrayAccess(const char* indexName, SkString* out) const {
|
||||
out->appendf("%s[%s]", this->getName().c_str(), indexName);
|
||||
}
|
||||
|
||||
private:
|
||||
GrSLType fType;
|
||||
TypeModifier fTypeModifier;
|
||||
|
@ -9,7 +9,6 @@
|
||||
|
||||
#include "src/gpu/GrTexture.h"
|
||||
#include "src/gpu/GrTextureProxy.h"
|
||||
#include "src/gpu/effects/GrTextureEffect.h"
|
||||
#include "src/gpu/glsl/GrGLSLFragmentProcessor.h"
|
||||
#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
|
||||
#include "src/gpu/glsl/GrGLSLProgramDataManager.h"
|
||||
@ -30,7 +29,8 @@ protected:
|
||||
|
||||
private:
|
||||
UniformHandle fKernelUni;
|
||||
UniformHandle fIncrementUni;
|
||||
UniformHandle fImageIncrementUni;
|
||||
UniformHandle fBoundsUni;
|
||||
|
||||
typedef GrGLSLFragmentProcessor INHERITED;
|
||||
};
|
||||
@ -40,54 +40,136 @@ void GrGLConvolutionEffect::emitCode(EmitArgs& args) {
|
||||
args.fFp.cast<GrGaussianConvolutionFragmentProcessor>();
|
||||
|
||||
GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
|
||||
|
||||
const char* inc;
|
||||
fIncrementUni = uniformHandler->addUniform(&ce, kFragment_GrShaderFlag, kHalf2_GrSLType,
|
||||
"Increment", &inc);
|
||||
fImageIncrementUni = uniformHandler->addUniform(&ce, kFragment_GrShaderFlag, kHalf2_GrSLType,
|
||||
"ImageIncrement");
|
||||
if (ce.useBounds()) {
|
||||
fBoundsUni = uniformHandler->addUniform(&ce, kFragment_GrShaderFlag, kHalf2_GrSLType,
|
||||
"Bounds");
|
||||
}
|
||||
|
||||
int width = ce.width();
|
||||
|
||||
int arrayCount = (width + 3) / 4;
|
||||
SkASSERT(4 * arrayCount >= width);
|
||||
|
||||
const char* kernel;
|
||||
fKernelUni = uniformHandler->addUniformArray(&ce, kFragment_GrShaderFlag, kHalf4_GrSLType,
|
||||
"Kernel", arrayCount, &kernel);
|
||||
"Kernel", arrayCount);
|
||||
|
||||
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
|
||||
auto coords2D = fragBuilder->ensureCoords2D(args.fTransformedCoords[0].fVaryingPoint,
|
||||
ce.sampleMatrix());
|
||||
SkString coords2D = fragBuilder->ensureCoords2D(args.fTransformedCoords[0].fVaryingPoint,
|
||||
ce.sampleMatrix());
|
||||
|
||||
fragBuilder->codeAppendf("%s = half4(0, 0, 0, 0);", args.fOutputColor);
|
||||
|
||||
fragBuilder->codeAppendf("float2 coord = %s - %d.0 * %s;", coords2D.c_str(), ce.radius(), inc);
|
||||
const GrShaderVar& kernel = uniformHandler->getUniformVariable(fKernelUni);
|
||||
const char* imgInc = uniformHandler->getUniformCStr(fImageIncrementUni);
|
||||
|
||||
fragBuilder->codeAppendf("float2 coord = %s - %d.0 * %s;", coords2D.c_str(), ce.radius(), imgInc);
|
||||
fragBuilder->codeAppend("float2 coordSampled = half2(0, 0);");
|
||||
|
||||
// Manually unroll loop because some drivers don't; yields 20-30% speedup.
|
||||
static constexpr const char* kVecSuffix[4] = {".x", ".y", ".z", ".w"};
|
||||
const char* kVecSuffix[4] = {".x", ".y", ".z", ".w"};
|
||||
for (int i = 0; i < width; i++) {
|
||||
SkString index;
|
||||
SkString kernelIndex;
|
||||
kernelIndex.printf("%s[%d]", kernel, i/4);
|
||||
index.appendS32(i / 4);
|
||||
kernel.appendArrayAccess(index.c_str(), &kernelIndex);
|
||||
kernelIndex.append(kVecSuffix[i & 0x3]);
|
||||
|
||||
fragBuilder->codeAppend("coordSampled = coord;");
|
||||
auto sample = this->invokeChild(0, args, "coordSampled");
|
||||
fragBuilder->codeAppendf("%s += %s", args.fOutputColor, sample.c_str());
|
||||
fragBuilder->codeAppendf(" * %s;", kernelIndex.c_str());
|
||||
fragBuilder->codeAppendf("coord += %s;", inc);
|
||||
if (ce.useBounds()) {
|
||||
// We used to compute a bool indicating whether we're in bounds or not, cast it to a
|
||||
// float, and then mul weight*texture_sample by the float. However, the Adreno 430 seems
|
||||
// to have a bug that caused corruption.
|
||||
const char* bounds = uniformHandler->getUniformCStr(fBoundsUni);
|
||||
const char* component = ce.direction() == Direction::kY ? "y" : "x";
|
||||
|
||||
switch (ce.mode()) {
|
||||
case GrTextureDomain::kClamp_Mode: {
|
||||
fragBuilder->codeAppendf("coordSampled.%s = clamp(coord.%s, %s.x, %s.y);\n",
|
||||
component, component, bounds, bounds);
|
||||
break;
|
||||
}
|
||||
// Deferring implementing kMirrorRepeat until we use DomainEffects as
|
||||
// child processors. Fallback to Repeat.
|
||||
case GrTextureDomain::kMirrorRepeat_Mode:
|
||||
case GrTextureDomain::kRepeat_Mode: {
|
||||
fragBuilder->codeAppendf("coordSampled.%s = "
|
||||
"mod(coord.%s - %s.x, %s.y - %s.x) + %s.x;\n",
|
||||
component, component, bounds, bounds, bounds, bounds);
|
||||
break;
|
||||
}
|
||||
case GrTextureDomain::kDecal_Mode: {
|
||||
fragBuilder->codeAppendf("if (coord.%s >= %s.x && coord.%s <= %s.y) {",
|
||||
component, bounds, component, bounds);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
SK_ABORT("Unsupported operation.");
|
||||
}
|
||||
}
|
||||
}
|
||||
fragBuilder->codeAppendf("%s += ", args.fOutputColor);
|
||||
fragBuilder->appendTextureLookup(args.fTexSamplers[0], "coordSampled");
|
||||
fragBuilder->codeAppendf(" * %s;\n", kernelIndex.c_str());
|
||||
if (GrTextureDomain::kDecal_Mode == ce.mode()) {
|
||||
fragBuilder->codeAppend("}");
|
||||
}
|
||||
fragBuilder->codeAppendf("coord += %s;\n", imgInc);
|
||||
}
|
||||
fragBuilder->codeAppendf("%s *= %s;", args.fOutputColor, args.fInputColor);
|
||||
fragBuilder->codeAppendf("%s *= %s;\n", args.fOutputColor, args.fInputColor);
|
||||
}
|
||||
|
||||
void GrGLConvolutionEffect::onSetData(const GrGLSLProgramDataManager& pdman,
|
||||
const GrFragmentProcessor& processor) {
|
||||
const auto& conv = processor.cast<GrGaussianConvolutionFragmentProcessor>();
|
||||
const GrGaussianConvolutionFragmentProcessor& conv =
|
||||
processor.cast<GrGaussianConvolutionFragmentProcessor>();
|
||||
const auto& view = conv.textureSampler(0).view();
|
||||
GrSurfaceProxy* proxy = view.proxy();
|
||||
GrTexture& texture = *proxy->peekTexture();
|
||||
|
||||
float increment[2] = {};
|
||||
increment[static_cast<int>(conv.direction())] = 1;
|
||||
pdman.set2fv(fIncrementUni, 1, increment);
|
||||
float imageIncrement[2] = {0};
|
||||
float ySign = view.origin() != kTopLeft_GrSurfaceOrigin ? 1.0f : -1.0f;
|
||||
switch (conv.direction()) {
|
||||
case Direction::kX:
|
||||
imageIncrement[0] = 1.0f / texture.width();
|
||||
break;
|
||||
case Direction::kY:
|
||||
imageIncrement[1] = ySign / texture.height();
|
||||
break;
|
||||
default:
|
||||
SK_ABORT("Unknown filter direction.");
|
||||
}
|
||||
pdman.set2fv(fImageIncrementUni, 1, imageIncrement);
|
||||
if (conv.useBounds()) {
|
||||
float bounds[2] = {0};
|
||||
bounds[0] = conv.bounds()[0];
|
||||
bounds[1] = conv.bounds()[1];
|
||||
if (GrTextureDomain::kClamp_Mode == conv.mode()) {
|
||||
bounds[0] += SK_ScalarHalf;
|
||||
bounds[1] -= SK_ScalarHalf;
|
||||
}
|
||||
if (Direction::kX == conv.direction()) {
|
||||
SkScalar inv = SkScalarInvert(SkIntToScalar(texture.width()));
|
||||
bounds[0] *= inv;
|
||||
bounds[1] *= inv;
|
||||
} else {
|
||||
SkScalar inv = SkScalarInvert(SkIntToScalar(texture.height()));
|
||||
if (view.origin() != kTopLeft_GrSurfaceOrigin) {
|
||||
float tmp = bounds[0];
|
||||
bounds[0] = 1.0f - (inv * bounds[1]);
|
||||
bounds[1] = 1.0f - (inv * tmp);
|
||||
} else {
|
||||
bounds[0] *= inv;
|
||||
bounds[1] *= inv;
|
||||
}
|
||||
}
|
||||
|
||||
SkASSERT(bounds[0] <= bounds[1]);
|
||||
pdman.set2f(fBoundsUni, bounds[0], bounds[1]);
|
||||
}
|
||||
int width = conv.width();
|
||||
|
||||
int arrayCount = (width + 3) / 4;
|
||||
SkASSERT(4 * arrayCount >= width);
|
||||
pdman.set4fv(fKernelUni, arrayCount, conv.kernel());
|
||||
@ -95,8 +177,15 @@ void GrGLConvolutionEffect::onSetData(const GrGLSLProgramDataManager& pdman,
|
||||
|
||||
void GrGLConvolutionEffect::GenKey(const GrProcessor& processor, const GrShaderCaps&,
|
||||
GrProcessorKeyBuilder* b) {
|
||||
const auto& conv = processor.cast<GrGaussianConvolutionFragmentProcessor>();
|
||||
b->add32(conv.radius());
|
||||
const GrGaussianConvolutionFragmentProcessor& conv =
|
||||
processor.cast<GrGaussianConvolutionFragmentProcessor>();
|
||||
uint32_t key = conv.radius();
|
||||
key <<= 3;
|
||||
if (conv.useBounds()) {
|
||||
key |= Direction::kY == conv.direction() ? 0x4 : 0x0;
|
||||
}
|
||||
key |= static_cast<uint32_t>(conv.mode());
|
||||
b->add32(key);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -126,67 +215,79 @@ static void fill_in_1D_gaussian_kernel(float* kernel, int width, float gaussianS
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<GrFragmentProcessor> GrGaussianConvolutionFragmentProcessor::Make(
|
||||
GrGaussianConvolutionFragmentProcessor::GrGaussianConvolutionFragmentProcessor(
|
||||
GrSurfaceProxyView view,
|
||||
SkAlphaType alphaType,
|
||||
Direction dir,
|
||||
int halfWidth,
|
||||
float gaussianSigma,
|
||||
GrSamplerState::WrapMode wm,
|
||||
const int bounds[2],
|
||||
const GrCaps& caps) {
|
||||
std::unique_ptr<GrFragmentProcessor> child;
|
||||
GrSamplerState sampler;
|
||||
switch (dir) {
|
||||
case Direction::kX: sampler.setWrapModeX(wm); break;
|
||||
case Direction::kY: sampler.setWrapModeY(wm); break;
|
||||
}
|
||||
if (bounds) {
|
||||
SkASSERT(bounds[0] < bounds[1]);
|
||||
SkRect subset;
|
||||
switch (dir) {
|
||||
case Direction::kX:
|
||||
subset = SkRect::MakeLTRB(bounds[0], 0, bounds[1], view.height());
|
||||
break;
|
||||
case Direction::kY:
|
||||
subset = SkRect::MakeLTRB(0, bounds[0], view.width(), bounds[1]);
|
||||
break;
|
||||
}
|
||||
child = GrTextureEffect::MakeSubset(std::move(view), alphaType, SkMatrix::I(), sampler,
|
||||
subset, caps);
|
||||
} else {
|
||||
child = GrTextureEffect::Make(std::move(view), alphaType, SkMatrix::I(), sampler, caps);
|
||||
}
|
||||
return std::unique_ptr<GrFragmentProcessor>(new GrGaussianConvolutionFragmentProcessor(
|
||||
std::move(child), dir, halfWidth, gaussianSigma));
|
||||
}
|
||||
|
||||
GrGaussianConvolutionFragmentProcessor::GrGaussianConvolutionFragmentProcessor(
|
||||
std::unique_ptr<GrFragmentProcessor> child,
|
||||
Direction direction,
|
||||
int radius,
|
||||
float gaussianSigma)
|
||||
float gaussianSigma,
|
||||
GrTextureDomain::Mode mode,
|
||||
int bounds[2])
|
||||
: INHERITED(kGrGaussianConvolutionFragmentProcessor_ClassID,
|
||||
ProcessorOptimizationFlags(child.get()))
|
||||
ModulateForSamplerOptFlags(alphaType, mode == GrTextureDomain::kDecal_Mode))
|
||||
, fCoordTransform(view.proxy(), view.origin())
|
||||
, fTextureSampler(std::move(view))
|
||||
, fRadius(radius)
|
||||
, fDirection(direction) {
|
||||
child->setSampledWithExplicitCoords();
|
||||
this->registerChildProcessor(std::move(child));
|
||||
SkASSERT(radius <= kMaxKernelRadius);
|
||||
fill_in_1D_gaussian_kernel(fKernel, this->width(), gaussianSigma, this->radius());
|
||||
, fDirection(direction)
|
||||
, fMode(mode) {
|
||||
this->addCoordTransform(&fCoordTransform);
|
||||
this->setTextureSamplerCnt(1);
|
||||
SkASSERT(radius <= kMaxKernelRadius);
|
||||
|
||||
fill_in_1D_gaussian_kernel(fKernel, this->width(), gaussianSigma, this->radius());
|
||||
// SkGpuBlurUtils is not as aggressive as it once was about avoiding domains. So we check
|
||||
// here if we can omit the domain. TODO: remove this when this effect uses a child to
|
||||
// sample the texture.
|
||||
auto samplerProxy = fTextureSampler.proxy();
|
||||
if (!samplerProxy->isFullyLazy()) {
|
||||
int wh = (fDirection == Direction::kX) ? samplerProxy->backingStoreDimensions().width()
|
||||
: samplerProxy->backingStoreDimensions().height();
|
||||
if (bounds[0] == 0 && bounds[1] == wh) {
|
||||
bool useSampler = false;
|
||||
GrSamplerState::WrapMode samplerMode = GrSamplerState::WrapMode::kClamp;
|
||||
switch (fMode) {
|
||||
case GrTextureDomain::kClamp_Mode:
|
||||
case GrTextureDomain::kIgnore_Mode:
|
||||
useSampler = true;
|
||||
break;
|
||||
case GrTextureDomain::kRepeat_Mode:
|
||||
useSampler = true;
|
||||
samplerMode = GrSamplerState::WrapMode::kRepeat;
|
||||
break;
|
||||
case GrTextureDomain::kMirrorRepeat_Mode:
|
||||
useSampler = true;
|
||||
samplerMode = GrSamplerState::WrapMode::kMirrorRepeat;
|
||||
break;
|
||||
case GrTextureDomain::kDecal_Mode:
|
||||
// Not sure if we support this in HW without having GrCaps here.
|
||||
// Just wait until we replace this with GrTextureEffect.
|
||||
break;
|
||||
}
|
||||
if (useSampler) {
|
||||
fMode = GrTextureDomain::kIgnore_Mode;
|
||||
if (fDirection == Direction::kX) {
|
||||
fTextureSampler.samplerState().setWrapModeX(samplerMode);
|
||||
} else {
|
||||
fTextureSampler.samplerState().setWrapModeY(samplerMode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
memcpy(fBounds, bounds, sizeof(fBounds));
|
||||
}
|
||||
|
||||
GrGaussianConvolutionFragmentProcessor::GrGaussianConvolutionFragmentProcessor(
|
||||
const GrGaussianConvolutionFragmentProcessor& that)
|
||||
: INHERITED(kGrGaussianConvolutionFragmentProcessor_ClassID, that.optimizationFlags())
|
||||
, fCoordTransform(that.fCoordTransform)
|
||||
, fTextureSampler(that.fTextureSampler)
|
||||
, fRadius(that.fRadius)
|
||||
, fDirection(that.fDirection) {
|
||||
auto child = that.childProcessor(0).clone();
|
||||
child->setSampledWithExplicitCoords();
|
||||
this->registerChildProcessor(std::move(child));
|
||||
memcpy(fKernel, that.fKernel, that.width() * sizeof(float));
|
||||
, fDirection(that.fDirection)
|
||||
, fMode(that.fMode) {
|
||||
this->addCoordTransform(&fCoordTransform);
|
||||
this->setTextureSamplerCnt(1);
|
||||
memcpy(fKernel, that.fKernel, that.width() * sizeof(float));
|
||||
memcpy(fBounds, that.fBounds, sizeof(fBounds));
|
||||
}
|
||||
|
||||
void GrGaussianConvolutionFragmentProcessor::onGetGLSLProcessorKey(const GrShaderCaps& caps,
|
||||
@ -199,9 +300,12 @@ GrGLSLFragmentProcessor* GrGaussianConvolutionFragmentProcessor::onCreateGLSLIns
|
||||
}
|
||||
|
||||
bool GrGaussianConvolutionFragmentProcessor::onIsEqual(const GrFragmentProcessor& sBase) const {
|
||||
const auto& that = sBase.cast<GrGaussianConvolutionFragmentProcessor>();
|
||||
return this->radius() == that.radius() && this->direction() == that.direction() &&
|
||||
std::equal(fKernel, fKernel + this->width(), that.fKernel);
|
||||
const GrGaussianConvolutionFragmentProcessor& s =
|
||||
sBase.cast<GrGaussianConvolutionFragmentProcessor>();
|
||||
return (this->radius() == s.radius() && this->direction() == s.direction() &&
|
||||
this->mode() == s.mode() &&
|
||||
0 == memcmp(fBounds, s.fBounds, sizeof(fBounds)) &&
|
||||
0 == memcmp(fKernel, s.fKernel, this->width() * sizeof(float)));
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -213,27 +317,25 @@ std::unique_ptr<GrFragmentProcessor> GrGaussianConvolutionFragmentProcessor::Tes
|
||||
GrProcessorTestData* d) {
|
||||
auto [view, ct, at] = d->randomView();
|
||||
|
||||
Direction dir;
|
||||
int bounds[2];
|
||||
do {
|
||||
if (d->fRandom->nextBool()) {
|
||||
dir = Direction::kX;
|
||||
bounds[0] = d->fRandom->nextRangeU(0, view.width() - 1);
|
||||
bounds[1] = d->fRandom->nextRangeU(0, view.width() - 1);
|
||||
} else {
|
||||
dir = Direction::kY;
|
||||
bounds[0] = d->fRandom->nextRangeU(0, view.height() - 1);
|
||||
bounds[1] = d->fRandom->nextRangeU(0, view.height() - 1);
|
||||
}
|
||||
} while (bounds[0] == bounds[1]);
|
||||
std::sort(bounds, bounds + 2);
|
||||
int modeIdx = d->fRandom->nextRangeU(0, GrTextureDomain::kModeCount-1);
|
||||
|
||||
Direction dir;
|
||||
if (d->fRandom->nextBool()) {
|
||||
dir = Direction::kX;
|
||||
bounds[0] = d->fRandom->nextRangeU(0, view.width()-2);
|
||||
bounds[1] = d->fRandom->nextRangeU(bounds[0]+1, view.width()-1);
|
||||
} else {
|
||||
dir = Direction::kY;
|
||||
bounds[0] = d->fRandom->nextRangeU(0, view.height()-2);
|
||||
bounds[1] = d->fRandom->nextRangeU(bounds[0]+1, view.height()-1);
|
||||
}
|
||||
|
||||
auto wm = static_cast<GrSamplerState::WrapMode>(
|
||||
d->fRandom->nextULessThan(GrSamplerState::kWrapModeCount));
|
||||
int radius = d->fRandom->nextRangeU(1, kMaxKernelRadius);
|
||||
float sigma = radius / 3.f;
|
||||
|
||||
return GrGaussianConvolutionFragmentProcessor::Make(std::move(view), at, dir, radius, sigma, wm,
|
||||
bounds, *d->caps());
|
||||
return GrGaussianConvolutionFragmentProcessor::Make(std::move(view), at, dir, radius, sigma,
|
||||
static_cast<GrTextureDomain::Mode>(modeIdx),
|
||||
bounds);
|
||||
}
|
||||
#endif
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
#include "src/gpu/GrCoordTransform.h"
|
||||
#include "src/gpu/GrFragmentProcessor.h"
|
||||
#include "src/gpu/effects/GrTextureDomain.h"
|
||||
|
||||
/**
|
||||
* A 1D Gaussian convolution effect. The kernel is computed as an array of 2 * half-width weights.
|
||||
@ -20,32 +21,37 @@ class GrGaussianConvolutionFragmentProcessor : public GrFragmentProcessor {
|
||||
public:
|
||||
enum class Direction { kX, kY };
|
||||
|
||||
/**
|
||||
* Convolve with a Gaussian kernel. Bounds limits the coords sampled by the effect along the
|
||||
* axis indicated by Direction. The WrapMode is applied to the bounds interval. If bounds is
|
||||
* nullptr then the full proxy width/height is used.
|
||||
*/
|
||||
/// Convolve with a Gaussian kernel
|
||||
static std::unique_ptr<GrFragmentProcessor> Make(GrSurfaceProxyView view,
|
||||
SkAlphaType alphaType,
|
||||
Direction dir,
|
||||
int halfWidth,
|
||||
float gaussianSigma,
|
||||
GrSamplerState::WrapMode,
|
||||
const int bounds[2],
|
||||
const GrCaps& caps);
|
||||
GrTextureDomain::Mode mode,
|
||||
int* bounds) {
|
||||
return std::unique_ptr<GrFragmentProcessor>(new GrGaussianConvolutionFragmentProcessor(
|
||||
std::move(view), alphaType, dir, halfWidth, gaussianSigma, mode, bounds));
|
||||
}
|
||||
|
||||
const float* kernel() const { return fKernel; }
|
||||
|
||||
const int* bounds() const { return fBounds; }
|
||||
bool useBounds() const { return fMode != GrTextureDomain::kIgnore_Mode; }
|
||||
int radius() const { return fRadius; }
|
||||
int width() const { return 2 * fRadius + 1; }
|
||||
Direction direction() const { return fDirection; }
|
||||
|
||||
GrTextureDomain::Mode mode() const { return fMode; }
|
||||
|
||||
const char* name() const override { return "GaussianConvolution"; }
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
SkString dumpInfo() const override {
|
||||
SkString str;
|
||||
str.appendf("dir: %s radius: %d", Direction::kX == fDirection ? "X" : "Y", fRadius);
|
||||
str.appendf("dir: %s radius: %d bounds: [%d %d]",
|
||||
Direction::kX == fDirection ? "X" : "Y",
|
||||
fRadius,
|
||||
fBounds[0], fBounds[1]);
|
||||
return str;
|
||||
}
|
||||
#endif
|
||||
@ -65,10 +71,10 @@ public:
|
||||
static const int kMaxKernelWidth = 2 * kMaxKernelRadius + 1;
|
||||
|
||||
private:
|
||||
GrGaussianConvolutionFragmentProcessor(std::unique_ptr<GrFragmentProcessor>,
|
||||
Direction,
|
||||
int halfWidth,
|
||||
float gaussianSigma);
|
||||
/// Convolve with a Gaussian kernel
|
||||
GrGaussianConvolutionFragmentProcessor(GrSurfaceProxyView, SkAlphaType alphaType, Direction,
|
||||
int halfWidth, float gaussianSigma,
|
||||
GrTextureDomain::Mode mode, int bounds[2]);
|
||||
|
||||
explicit GrGaussianConvolutionFragmentProcessor(const GrGaussianConvolutionFragmentProcessor&);
|
||||
|
||||
@ -78,16 +84,19 @@ private:
|
||||
|
||||
bool onIsEqual(const GrFragmentProcessor&) const override;
|
||||
|
||||
const TextureSampler& onTextureSampler(int) const override { return fTextureSampler; }
|
||||
|
||||
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
|
||||
|
||||
// We really just want the unaltered local coords, but the only way to get that right now is
|
||||
// an identity coord transform.
|
||||
GrCoordTransform fCoordTransform = {};
|
||||
GrCoordTransform fCoordTransform;
|
||||
TextureSampler fTextureSampler;
|
||||
// TODO: Inline the kernel constants into the generated shader code. This may involve pulling
|
||||
// some of the logic from SkGpuBlurUtils into this class related to radius/sigma calculations.
|
||||
float fKernel[kMaxKernelWidth];
|
||||
int fBounds[2];
|
||||
int fRadius;
|
||||
Direction fDirection;
|
||||
GrTextureDomain::Mode fMode;
|
||||
|
||||
typedef GrFragmentProcessor INHERITED;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user