Rename GrSamplerState::Filter::kBilerp to kLinear

Aligning with SkSamplingMode.

Bug: skia:10344

Change-Id: Ie303c3ca1d664d4c23f779b84c9a661076bd74d4
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/303022
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Brian Salomon 2020-07-15 16:02:01 -04:00 committed by Skia Commit-Bot
parent c0693db3f5
commit a3b02f5278
34 changed files with 139 additions and 135 deletions

View File

@ -50,7 +50,7 @@ protected:
case GrSamplerState::Filter::kNearest:
name.append("_nearest");
break;
case GrSamplerState::Filter::kBilerp:
case GrSamplerState::Filter::kLinear:
name.append("_bilerp");
break;
case GrSamplerState::Filter::kMipMap:
@ -210,8 +210,8 @@ private:
DEF_GM(return new TexelSubset(GrSamplerState::Filter::kNearest, false);)
DEF_GM(return new TexelSubset(GrSamplerState::Filter::kNearest, true);)
DEF_GM(return new TexelSubset(GrSamplerState::Filter::kBilerp , false);)
DEF_GM(return new TexelSubset(GrSamplerState::Filter::kBilerp , true);)
DEF_GM(return new TexelSubset(GrSamplerState::Filter::kLinear , false);)
DEF_GM(return new TexelSubset(GrSamplerState::Filter::kLinear , true);)
// It doesn't make sense to have upscaling MIP map.
DEF_GM(return new TexelSubset(GrSamplerState::Filter::kMipMap, false);)

View File

@ -326,8 +326,8 @@ protected:
}
}
static const GrSamplerState::Filter kFilters[] = {
GrSamplerState::Filter::kNearest, GrSamplerState::Filter::kBilerp };
static const GrSamplerState::Filter kFilters[] = {GrSamplerState::Filter::kNearest,
GrSamplerState::Filter::kLinear};
static const SkRect kColorRect = SkRect::MakeLTRB(2.f, 2.f, 6.f, 6.f);
SkYUVAIndex yuvaIndices[4] = {

View File

@ -266,7 +266,7 @@ static std::unique_ptr<GrRenderTargetContext> reexpand(GrRecordingContext* conte
GrPaint paint;
auto fp = GrTextureEffect::MakeSubset(std::move(srcView), srcAlphaType, SkMatrix::I(),
GrSamplerState::Filter::kBilerp, srcBounds, srcBounds,
GrSamplerState::Filter::kLinear, srcBounds, srcBounds,
*context->priv().caps());
paint.addColorFragmentProcessor(std::move(fp));
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);

View File

@ -305,13 +305,13 @@ static GrSurfaceProxyView decimate(GrRecordingContext* context,
if (i == 1) {
GrSamplerState::WrapMode wrapMode = SkTileModeToWrapMode(mode);
const auto& caps = *context->priv().caps();
GrSamplerState sampler(wrapMode, GrSamplerState::Filter::kBilerp);
GrSamplerState sampler(wrapMode, GrSamplerState::Filter::kLinear);
fp = GrTextureEffect::MakeSubset(std::move(srcView), srcAlphaType, SkMatrix::I(),
sampler, SkRect::Make(*contentRect), caps);
srcRect.offset(-srcOffset);
} else {
fp = GrTextureEffect::Make(std::move(srcView), srcAlphaType, SkMatrix::I(),
GrSamplerState::Filter::kBilerp);
GrSamplerState::Filter::kLinear);
}
paint.addColorFragmentProcessor(std::move(fp));
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
@ -368,7 +368,7 @@ static std::unique_ptr<GrRenderTargetContext> reexpand(GrRecordingContext* conte
GrPaint paint;
const auto& caps = *context->priv().caps();
auto fp = GrTextureEffect::MakeSubset(std::move(srcView), srcAlphaType, SkMatrix::I(),
GrSamplerState::Filter::kBilerp, SkRect::Make(srcBounds),
GrSamplerState::Filter::kLinear, SkRect::Make(srcBounds),
caps);
paint.addColorFragmentProcessor(std::move(fp));
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);

View File

@ -70,10 +70,11 @@ std::unique_ptr<GrFragmentProcessor> GrYUVAImageTextureMaker::createFragmentProc
}
// Check to see if the client has given us pre-mipped textures or we can generate them
// If not, fall back to bilerp. Also fall back to bilerp when a domain is requested
// If not, fall back to linear filtering. Also fall back to linear filtering when a domain is
// requested.
if (samplerState.filter() == GrSamplerState::Filter::kMipMap &&
(subset || !fImage->setupMipmapsForPlanes(this->context()))) {
samplerState.setFilterMode(GrSamplerState::Filter::kBilerp);
samplerState.setFilterMode(GrSamplerState::Filter::kLinear);
}
const auto& caps = *fImage->context()->priv().caps();

View File

@ -63,7 +63,7 @@ uint32_t GrPrimitiveProcessor::computeCoordTransformsKey(const GrFragmentProcess
static inline GrSamplerState::Filter clamp_filter(GrTextureType type,
GrSamplerState::Filter requestedFilter) {
if (GrTextureTypeHasRestrictedSampling(type)) {
return std::min(requestedFilter, GrSamplerState::Filter::kBilerp);
return std::min(requestedFilter, GrSamplerState::Filter::kLinear);
}
return requestedFilter;
}

View File

@ -15,7 +15,7 @@
*/
class GrSamplerState {
public:
enum class Filter : uint8_t { kNearest, kBilerp, kMipMap, kLast = kMipMap };
enum class Filter : uint8_t { kNearest, kLinear, kMipMap, kLast = kMipMap };
enum class WrapMode : uint8_t { kClamp, kRepeat, kMirrorRepeat, kClampToBorder,
kLast = kClampToBorder };

View File

@ -868,7 +868,7 @@ void GrSurfaceContext::asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorS
std::copy_n(baseM + 5, 5, uM + 15);
GrPaint uPaint;
auto uTexFP = GrTextureEffect::Make(srcView, this->colorInfo().alphaType(), texMatrix,
GrSamplerState::Filter::kBilerp);
GrSamplerState::Filter::kLinear);
auto uColFP = GrColorMatrixFragmentProcessor::Make(std::move(uTexFP), uM,
/*unpremulInput=*/false,
/*clampRGBOutput=*/true,
@ -892,7 +892,7 @@ void GrSurfaceContext::asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorS
std::copy_n(baseM + 10, 5, vM + 15);
GrPaint vPaint;
auto vTexFP = GrTextureEffect::Make(std::move(srcView), this->colorInfo().alphaType(),
texMatrix, GrSamplerState::Filter::kBilerp);
texMatrix, GrSamplerState::Filter::kLinear);
auto vColFP = GrColorMatrixFragmentProcessor::Make(std::move(vTexFP), vM,
/*unpremulInput=*/false,
/*clampRGBOutput=*/true,
@ -1129,7 +1129,7 @@ std::unique_ptr<GrRenderTargetContext> GrSurfaceContext::rescale(const GrImageIn
dstRect);
} else {
auto filter = rescaleQuality == kNone_SkFilterQuality ? GrSamplerState::Filter::kNearest
: GrSamplerState::Filter::kBilerp;
: GrSamplerState::Filter::kLinear;
// Minimizing draw with integer coord src and dev rects can always be kFast.
auto constraint = SkCanvas::SrcRectConstraint::kStrict_SrcRectConstraint;
if (nextDims.width() <= srcRect.width() && nextDims.height() <= srcRect.height()) {

View File

@ -68,7 +68,7 @@ GrSurfaceProxyView GrTextureAdjuster::onView(GrMipMapped mipMapped) {
if (!copy) {
// If we were unable to make a copy and we only needed a copy for mips, then we will return
// the source texture here and require that the GPU backend is able to fall back to using
// bilerp if mips are required.
// linear filtering if mips are required.
return fOriginal;
}
SkASSERT(copy.asTextureProxy());

View File

@ -148,7 +148,7 @@ size_t GrTextureProxy::onUninstantiatedGpuMemorySize(const GrCaps& caps) const {
}
GrSamplerState::Filter GrTextureProxy::HighestFilterMode(GrTextureType textureType) {
return GrTextureTypeHasRestrictedSampling(textureType) ? GrSamplerState::Filter::kBilerp
return GrTextureTypeHasRestrictedSampling(textureType) ? GrSamplerState::Filter::kLinear
: GrSamplerState::Filter::kMipMap;
}

View File

@ -812,13 +812,13 @@ void SkGpuDevice::drawImageRect(const SkImage* image, const SkRect* src, const S
paint, constraint);
}
// When drawing nine-patches or n-patches, cap the filter quality at kBilerp.
// When drawing nine-patches or n-patches, cap the filter quality at kLinear.
static GrSamplerState::Filter compute_lattice_filter_mode(const SkPaint& paint) {
if (paint.getFilterQuality() == kNone_SkFilterQuality) {
return GrSamplerState::Filter::kNearest;
}
return GrSamplerState::Filter::kBilerp;
return GrSamplerState::Filter::kLinear;
}
void SkGpuDevice::drawImageNine(const SkImage* image,

View File

@ -35,7 +35,7 @@ static inline bool use_shader(bool textureIsAlphaOnly, const SkPaint& paint) {
}
//////////////////////////////////////////////////////////////////////////////
// Helper functions for dropping src rect subset in bilerp mode.
// Helper functions for dropping src rect subset with GrSamplerState::Filter::kLinear.
static const SkScalar kColorBleedTolerance = 0.001f;
@ -79,10 +79,10 @@ static bool may_color_bleed(const SkRect& srcRect,
return inner != outer;
}
static bool can_ignore_bilerp_subset(const GrTextureProducer& producer,
const SkRect& srcSubset,
const SkMatrix& srcRectToDeviceSpace,
int numSamples) {
static bool can_ignore_linear_filtering_subset(const GrTextureProducer& producer,
const SkRect& srcSubset,
const SkMatrix& srcRectToDeviceSpace,
int numSamples) {
if (srcRectToDeviceSpace.rectStaysRect()) {
// sampling is axis-aligned
SkRect transformedRect;
@ -350,7 +350,7 @@ static void draw_texture(GrRenderTargetContext* rtc, const GrClip* clip, const S
filter = GrSamplerState::Filter::kNearest;
break;
case kLow_SkFilterQuality:
filter = GrSamplerState::Filter::kBilerp;
filter = GrSamplerState::Filter::kLinear;
break;
case kMedium_SkFilterQuality:
case kHigh_SkFilterQuality:
@ -361,9 +361,9 @@ static void draw_texture(GrRenderTargetContext* rtc, const GrClip* clip, const S
// rect would access pixels outside the proxy's content area without the constraint.
if (constraint != SkCanvas::kStrict_SrcRectConstraint && !proxy->isFunctionallyExact()) {
// Conservative estimate of how much a coord could be outset from src rect:
// 1/2 pixel for AA and 1/2 pixel for bilerp
// 1/2 pixel for AA and 1/2 pixel for linear filtering
float buffer = 0.5f * (aa == GrAA::kYes) +
0.5f * (filter == GrSamplerState::Filter::kBilerp);
0.5f * (filter == GrSamplerState::Filter::kLinear);
SkRect safeBounds = proxy->getBoundsRect();
safeBounds.inset(buffer, buffer);
if (!safeBounds.contains(srcRect)) {
@ -444,12 +444,12 @@ static void draw_texture_producer(GrRecordingContext* context,
// This is conservative as a mask filter does not have to expand the bounds rendered.
bool coordsAllInsideSrcRect = aaFlags == GrQuadAAFlags::kNone && !mf;
// Check for optimization to drop the src rect constraint when on bilerp.
if (!doBicubic && fm == GrSamplerState::Filter::kBilerp && restrictToSubset &&
// Check for optimization to drop the src rect constraint when using linear filtering.
if (!doBicubic && fm == GrSamplerState::Filter::kLinear && restrictToSubset &&
coordsAllInsideSrcRect) {
SkMatrix combinedMatrix;
combinedMatrix.setConcat(ctm, srcToDst);
if (can_ignore_bilerp_subset(*producer, src, combinedMatrix, rtc->numSamples())) {
if (can_ignore_linear_filtering_subset(*producer, src, combinedMatrix, rtc->numSamples())) {
restrictToSubset = false;
}
}
@ -780,8 +780,9 @@ void SkGpuDevice::drawEdgeAAImageSet(const SkCanvas::ImageSetEntry set[], int co
return;
}
GrSamplerState::Filter filter = kNone_SkFilterQuality == paint.getFilterQuality() ?
GrSamplerState::Filter::kNearest : GrSamplerState::Filter::kBilerp;
GrSamplerState::Filter filter = kNone_SkFilterQuality == paint.getFilterQuality()
? GrSamplerState::Filter::kNearest
: GrSamplerState::Filter::kLinear;
SkBlendMode mode = paint.getBlendMode();
SkAutoTArray<GrRenderTargetContext::TextureSetEntry> textures(count);

View File

@ -448,7 +448,7 @@ GrSamplerState::Filter GrSkFilterQualityToGrFilterMode(int imageWidth, int image
case kNone_SkFilterQuality:
return GrSamplerState::Filter::kNearest;
case kLow_SkFilterQuality:
return GrSamplerState::Filter::kBilerp;
return GrSamplerState::Filter::kLinear;
case kMedium_SkFilterQuality: {
SkMatrix matrix;
matrix.setConcat(viewM, localM);
@ -465,7 +465,7 @@ GrSamplerState::Filter GrSkFilterQualityToGrFilterMode(int imageWidth, int image
return GrSamplerState::Filter::kMipMap;
} else {
// Don't trigger MIP level generation unnecessarily.
return GrSamplerState::Filter::kBilerp;
return GrSamplerState::Filter::kLinear;
}
}
case kHigh_SkFilterQuality: {

View File

@ -139,7 +139,7 @@ D3D12_CPU_DESCRIPTOR_HANDLE GrD3DResourceProvider::findOrCreateCompatibleSampler
};
static_assert((int)GrSamplerState::Filter::kNearest == 0);
static_assert((int)GrSamplerState::Filter::kBilerp == 1);
static_assert((int)GrSamplerState::Filter::kLinear == 1);
static_assert((int)GrSamplerState::Filter::kMipMap == 2);
D3D12_FILTER filter = d3dFilterModes[static_cast<int>(params.filter())];

View File

@ -72,7 +72,7 @@ static wgpu::FilterMode to_dawn_filter_mode(GrSamplerState::Filter filter) {
switch (filter) {
case GrSamplerState::Filter::kNearest:
return wgpu::FilterMode::Nearest;
case GrSamplerState::Filter::kBilerp:
case GrSamplerState::Filter::kLinear:
case GrSamplerState::Filter::kMipMap:
return wgpu::FilterMode::Linear;
default:

View File

@ -326,7 +326,7 @@ bool GrBicubicEffect::ShouldUseBicubic(const SkMatrix& matrix, GrSamplerState::F
*filterMode = GrSamplerState::Filter::kNearest;
break;
case kLow_SkFilterQuality:
*filterMode = GrSamplerState::Filter::kBilerp;
*filterMode = GrSamplerState::Filter::kLinear;
break;
case kMedium_SkFilterQuality:
*filterMode = GrSamplerState::Filter::kMipMap;

View File

@ -103,7 +103,7 @@ public:
* Determines whether the bicubic effect should be used based on the transformation from the
* local coords to the device. Returns true if the bicubic effect should be used. filterMode
* is set to appropriate filtering mode to use regardless of the return result (e.g. when this
* returns false it may indicate that the best fallback is to use kMipMap, kBilerp, or
* returns false it may indicate that the best fallback is to use kMipMap, kLinear, or
* kNearest).
*/
static bool ShouldUseBicubic(const SkMatrix& localCoordsToDevice,

View File

@ -207,7 +207,7 @@ GrGeometryProcessor* GrBitmapTextGeoProc::TestCreate(GrProcessorTestData* d) {
GrSamplerState::WrapMode wrapModes[2];
GrTest::TestWrapModes(d->fRandom, wrapModes);
GrSamplerState samplerState(wrapModes, d->fRandom->nextBool()
? GrSamplerState::Filter::kBilerp
? GrSamplerState::Filter::kLinear
: GrSamplerState::Filter::kNearest);
GrMaskFormat format;

View File

@ -291,7 +291,7 @@ GrGeometryProcessor* GrDistanceFieldA8TextGeoProc::TestCreate(GrProcessorTestDat
GrSamplerState::WrapMode wrapModes[2];
GrTest::TestWrapModes(d->fRandom, wrapModes);
GrSamplerState samplerState(wrapModes, d->fRandom->nextBool()
? GrSamplerState::Filter::kBilerp
? GrSamplerState::Filter::kLinear
: GrSamplerState::Filter::kNearest);
uint32_t flags = 0;
@ -561,7 +561,7 @@ GrGeometryProcessor* GrDistanceFieldPathGeoProc::TestCreate(GrProcessorTestData*
GrSamplerState::WrapMode wrapModes[2];
GrTest::TestWrapModes(d->fRandom, wrapModes);
GrSamplerState samplerState(wrapModes, d->fRandom->nextBool()
? GrSamplerState::Filter::kBilerp
? GrSamplerState::Filter::kLinear
: GrSamplerState::Filter::kNearest);
uint32_t flags = 0;
@ -884,7 +884,7 @@ GrGeometryProcessor* GrDistanceFieldLCDTextGeoProc::TestCreate(GrProcessorTestDa
GrSamplerState::WrapMode wrapModes[2];
GrTest::TestWrapModes(d->fRandom, wrapModes);
GrSamplerState samplerState(wrapModes, d->fRandom->nextBool()
? GrSamplerState::Filter::kBilerp
? GrSamplerState::Filter::kLinear
: GrSamplerState::Filter::kNearest);
DistanceAdjust wa = { 0.0f, 0.1f, -0.1f };
uint32_t flags = kUseLCD_DistanceFieldEffectFlag;

View File

@ -76,7 +76,7 @@ static std::unique_ptr<GrFragmentProcessor> MakeIntegralFP(GrRecordingContext* c
GrColorType::kAlpha_8);
GrSurfaceProxyView view{std::move(proxy), kTopLeft_GrSurfaceOrigin, swizzle};
return GrTextureEffect::Make(
std::move(view), kPremul_SkAlphaType, m, GrSamplerState::Filter::kBilerp);
std::move(view), kPremul_SkAlphaType, m, GrSamplerState::Filter::kLinear);
}
SkBitmap bitmap;
@ -102,7 +102,7 @@ static std::unique_ptr<GrFragmentProcessor> MakeIntegralFP(GrRecordingContext* c
SkASSERT(view.origin() == kTopLeft_GrSurfaceOrigin);
proxyProvider->assignUniqueKeyToProxy(key, view.asTextureProxy());
return GrTextureEffect::Make(
std::move(view), kPremul_SkAlphaType, m, GrSamplerState::Filter::kBilerp);
std::move(view), kPremul_SkAlphaType, m, GrSamplerState::Filter::kLinear);
}
}
@ -145,7 +145,7 @@ static std::unique_ptr<GrFragmentProcessor> MakeIntegralFP(GrRecordingContext* c
bool isFast = insetRect.isSorted();
return std::unique_ptr<GrFragmentProcessor>(new GrRectBlurEffect(
std::move(inputFP), insetRect, std::move(integral),
isFast, GrSamplerState::Filter::kBilerp));
isFast, GrSamplerState::Filter::kLinear));
}
}

View File

@ -61,7 +61,7 @@ GrRRectShadowGeoProc::GrRRectShadowGeoProc(const GrSurfaceProxyView& lutView)
this->setVertexAttributes(&fInPosition, 3);
SkASSERT(lutView.proxy());
fLUTTextureSampler.reset(GrSamplerState::Filter::kBilerp, lutView.proxy()->backendFormat(),
fLUTTextureSampler.reset(GrSamplerState::Filter::kLinear, lutView.proxy()->backendFormat(),
lutView.swizzle());
this->setTextureSamplerCnt(1);
}

View File

@ -31,7 +31,7 @@ struct GrTextureEffect::Sampling {
const SkRect*,
const float border[4],
const GrCaps&,
SkVector bilerpInset = {0.5f, 0.5f});
SkVector linearFilterInset = {0.5f, 0.5f});
inline bool hasBorderAlpha() const;
};
@ -41,7 +41,7 @@ GrTextureEffect::Sampling::Sampling(const GrSurfaceProxy& proxy,
const SkRect* domain,
const float border[4],
const GrCaps& caps,
SkVector bilerpInset) {
SkVector linearFilterInset) {
struct Span {
float fA = 0.f, fB = 0.f;
@ -65,7 +65,7 @@ GrTextureEffect::Sampling::Sampling(const GrSurfaceProxy& proxy,
auto type = proxy.asTextureProxy()->textureType();
auto filter = sampler.filter();
auto resolve = [&](int size, Mode mode, Span subset, Span domain, float bilerpInset) {
auto resolve = [&](int size, Mode mode, Span subset, Span domain, float linearFilterInset) {
Result1D r;
bool canDoModeInHW = true;
// TODO: Use HW border color when available.
@ -97,7 +97,7 @@ GrTextureEffect::Sampling::Sampling(const GrSurfaceProxy& proxy,
// and GPU-specific snapping at the boundary).
r.fShaderClamp = isubset.makeInset(0.5f);
} else {
r.fShaderClamp = subset.makeInset(bilerpInset);
r.fShaderClamp = subset.makeInset(linearFilterInset);
if (r.fShaderClamp.contains(domain)) {
domainIsSafe = true;
}
@ -121,12 +121,12 @@ GrTextureEffect::Sampling::Sampling(const GrSurfaceProxy& proxy,
Span subsetX{subset.fLeft, subset.fRight};
auto domainX = domain ? Span{domain->fLeft, domain->fRight}
: Span{SK_FloatNegativeInfinity, SK_FloatInfinity};
auto x = resolve(dim.width(), sampler.wrapModeX(), subsetX, domainX, bilerpInset.fX);
auto x = resolve(dim.width(), sampler.wrapModeX(), subsetX, domainX, linearFilterInset.fX);
Span subsetY{subset.fTop, subset.fBottom};
auto domainY = domain ? Span{domain->fTop, domain->fBottom}
: Span{SK_FloatNegativeInfinity, SK_FloatInfinity};
auto y = resolve(dim.height(), sampler.wrapModeY(), subsetY, domainY, bilerpInset.fY);
auto y = resolve(dim.height(), sampler.wrapModeY(), subsetY, domainY, linearFilterInset.fY);
fHWSampler = {x.fHWMode, y.fHWMode, filter};
fShaderModes[0] = x.fShaderMode;
@ -258,7 +258,7 @@ std::unique_ptr<GrFragmentProcessor> GrTextureEffect::MakeSubset(GrSurfaceProxyV
lazyProxyNormalization)));
}
std::unique_ptr<GrFragmentProcessor> GrTextureEffect::MakeBilerpWithInset(
std::unique_ptr<GrFragmentProcessor> GrTextureEffect::MakeCustomLinearFilterInset(
GrSurfaceProxyView view,
SkAlphaType alphaType,
const SkMatrix& matrix,
@ -269,7 +269,7 @@ std::unique_ptr<GrFragmentProcessor> GrTextureEffect::MakeBilerpWithInset(
SkVector inset,
const GrCaps& caps,
const float border[4]) {
GrSamplerState sampler(wx, wy, GrSamplerState::Filter::kBilerp);
GrSamplerState sampler(wx, wy, GrSamplerState::Filter::kLinear);
Sampling sampling(*view.proxy(), sampler, subset, domain, border, caps, inset);
SkMatrix final;
bool lazyProxyNormalization;
@ -290,8 +290,8 @@ GrTextureEffect::ShaderMode GrTextureEffect::GetShaderMode(GrSamplerState::WrapM
switch (filter) {
case GrSamplerState::Filter::kNearest:
return ShaderMode::kRepeatNearest;
case GrSamplerState::Filter::kBilerp:
return ShaderMode::kRepeatBilerp;
case GrSamplerState::Filter::kLinear:
return ShaderMode::kRepeatLinear;
case GrSamplerState::Filter::kMipMap:
return ShaderMode::kRepeatMipMap;
}
@ -371,7 +371,7 @@ void GrTextureEffect::Impl::emitCode(EmitArgs& args) {
case ShaderMode::kNone: return false;
case ShaderMode::kClamp: return false;
case ShaderMode::kRepeatNearest: return true;
case ShaderMode::kRepeatBilerp: return true;
case ShaderMode::kRepeatLinear: return true;
case ShaderMode::kRepeatMipMap: return true;
case ShaderMode::kMirrorRepeat: return true;
case ShaderMode::kClampToBorderNearest: return true;
@ -385,7 +385,7 @@ void GrTextureEffect::Impl::emitCode(EmitArgs& args) {
case ShaderMode::kNone: return false;
case ShaderMode::kClamp: return true;
case ShaderMode::kRepeatNearest: return true;
case ShaderMode::kRepeatBilerp: return true;
case ShaderMode::kRepeatLinear: return true;
case ShaderMode::kRepeatMipMap: return true;
case ShaderMode::kMirrorRepeat: return true;
case ShaderMode::kClampToBorderNearest: return false;
@ -402,7 +402,7 @@ void GrTextureEffect::Impl::emitCode(EmitArgs& args) {
case ShaderMode::kNone: return false;
case ShaderMode::kClamp: return false;
case ShaderMode::kRepeatNearest: return false;
case ShaderMode::kRepeatBilerp: return true;
case ShaderMode::kRepeatLinear: return true;
case ShaderMode::kRepeatMipMap: return true;
case ShaderMode::kMirrorRepeat: return false;
case ShaderMode::kClampToBorderNearest: return true;
@ -468,7 +468,7 @@ void GrTextureEffect::Impl::emitCode(EmitArgs& args) {
fb->codeAppendf("subsetCoord.%s = inCoord.%s;", coordSwizzle, coordSwizzle);
break;
case ShaderMode::kRepeatNearest:
case ShaderMode::kRepeatBilerp:
case ShaderMode::kRepeatLinear:
fb->codeAppendf(
"subsetCoord.%s = mod(inCoord.%s - %s.%s, %s.%s - %s.%s) + "
"%s.%s;",
@ -597,37 +597,37 @@ void GrTextureEffect::Impl::emitCode(EmitArgs& args) {
fb->codeAppendf("half4 textureColor = %s;", read("clampedCoord").c_str());
}
// Strings for extra texture reads used only in kRepeatBilerp
SkString repeatBilerpReadX;
SkString repeatBilerpReadY;
// Strings for extra texture reads used only in kRepeatLinear
SkString repeatLinearReadX;
SkString repeatLinearReadY;
// Calculate the amount the coord moved for clamping. This will be used
// to implement shader-based filtering for kClampToBorder and kRepeat.
if (m[0] == ShaderMode::kRepeatBilerp || m[0] == ShaderMode::kClampToBorderFilter) {
if (m[0] == ShaderMode::kRepeatLinear || m[0] == ShaderMode::kClampToBorderFilter) {
fb->codeAppend("half errX = half(subsetCoord.x - clampedCoord.x);");
if (m[0] == ShaderMode::kRepeatBilerp) {
if (m[0] == ShaderMode::kRepeatLinear) {
fb->codeAppendf("float repeatCoordX = errX > 0 ? %s.x : %s.z;",
clampName, clampName);
repeatBilerpReadX = read("float2(repeatCoordX, clampedCoord.y)");
repeatLinearReadX = read("float2(repeatCoordX, clampedCoord.y)");
}
}
if (m[1] == ShaderMode::kRepeatBilerp || m[1] == ShaderMode::kClampToBorderFilter) {
if (m[1] == ShaderMode::kRepeatLinear || m[1] == ShaderMode::kClampToBorderFilter) {
fb->codeAppend("half errY = half(subsetCoord.y - clampedCoord.y);");
if (m[1] == ShaderMode::kRepeatBilerp) {
if (m[1] == ShaderMode::kRepeatLinear) {
fb->codeAppendf("float repeatCoordY = errY > 0 ? %s.y : %s.w;",
clampName, clampName);
repeatBilerpReadY = read("float2(clampedCoord.x, repeatCoordY)");
repeatLinearReadY = read("float2(clampedCoord.x, repeatCoordY)");
}
}
// Add logic for kRepeatBilerp. Do 1 or 3 more texture reads depending
// Add logic for kRepeatLinear. Do 1 or 3 more texture reads depending
// on whether both modes are kRepeat and whether we're near a single subset edge
// or a corner. Then blend the multiple reads using the err values calculated
// above.
const char* ifStr = "if";
if (m[0] == ShaderMode::kRepeatBilerp && m[1] == ShaderMode::kRepeatBilerp) {
auto repeatBilerpReadXY = read("float2(repeatCoordX, repeatCoordY)");
if (m[0] == ShaderMode::kRepeatLinear && m[1] == ShaderMode::kRepeatLinear) {
auto repeatLinearReadXY = read("float2(repeatCoordX, repeatCoordY)");
fb->codeAppendf(
"if (errX != 0 && errY != 0) {"
" errX = abs(errX);"
@ -635,23 +635,23 @@ void GrTextureEffect::Impl::emitCode(EmitArgs& args) {
" mix(%s, %s, errX),"
" abs(errY));"
"}",
repeatBilerpReadX.c_str(), repeatBilerpReadY.c_str(),
repeatBilerpReadXY.c_str());
repeatLinearReadX.c_str(), repeatLinearReadY.c_str(),
repeatLinearReadXY.c_str());
ifStr = "else if";
}
if (m[0] == ShaderMode::kRepeatBilerp) {
if (m[0] == ShaderMode::kRepeatLinear) {
fb->codeAppendf(
"%s (errX != 0) {"
" textureColor = mix(textureColor, %s, abs(errX));"
"}",
ifStr, repeatBilerpReadX.c_str());
ifStr, repeatLinearReadX.c_str());
}
if (m[1] == ShaderMode::kRepeatBilerp) {
if (m[1] == ShaderMode::kRepeatLinear) {
fb->codeAppendf(
"%s (errY != 0) {"
" textureColor = mix(textureColor, %s, abs(errY));"
"}",
ifStr, repeatBilerpReadY.c_str());
ifStr, repeatLinearReadY.c_str());
}
// Do soft edge shader filtering against border color for kClampToBorderFilter using
@ -810,14 +810,14 @@ std::unique_ptr<GrFragmentProcessor> GrTextureEffect::TestCreate(GrProcessorTest
filter = Filter::kNearest;
break;
case 1:
filter = Filter::kBilerp;
filter = Filter::kLinear;
break;
default:
filter = Filter::kMipMap;
break;
}
} else {
filter = testData->fRandom->nextBool() ? Filter::kBilerp : Filter::kNearest;
filter = testData->fRandom->nextBool() ? Filter::kLinear : Filter::kNearest;
}
GrSamplerState params(wrapModes, filter);

View File

@ -38,11 +38,11 @@ public:
* Makes a texture effect that samples a subset of a texture. The wrap modes of the
* GrSampleState are applied to the subset in the shader rather than using HW samplers.
* The 'subset' parameter specifies the texels in the base level. The shader code will
* avoid allowing bilerp filtering to read outside the texel window. However, if MIP
* avoid allowing linear filtering to read outside the texel window. However, if MIP
* filtering is used and a shader invocation reads from a level other than the base
* then it may read texel values that were computed from in part from base level texels
* outside the window. More specifically, we treat the MIP map case exactly like the
* bilerp case in terms of how the final texture coords are computed.
* linear case in terms of how the final texture coords are computed.
*/
static std::unique_ptr<GrFragmentProcessor> MakeSubset(GrSurfaceProxyView,
SkAlphaType,
@ -68,16 +68,16 @@ public:
const float border[4] = kDefaultBorder);
/**
* Like MakeSubset() but always uses kBilerp filtering. MakeSubset() uses the subset rect
* Like MakeSubset() but always uses kLinear filtering. MakeSubset() uses the subset rect
* dimensions to determine the period of the wrap mode (for repeat and mirror). Once it computes
* the wrapped texture coordinate inside subset rect it further clamps it to a 0.5 inset rect of
* subset. When subset is an integer rectangle this clamping avoids the hw bilerp filtering from
* subset. When subset is an integer rectangle this clamping avoids the hw linear filtering from
* reading texels just outside the subset rect. This factory allows a custom inset clamping
* distance rather than 0.5, allowing those neighboring texels to influence the bilerped sample
* result. If there is a known restriction on the post-matrix texture coords it can be specified
* using domain.
* distance rather than 0.5, allowing those neighboring texels to influence the linear filtering
* sample result. If there is a known restriction on the post-matrix texture coords it can be
* specified using domain.
*/
static std::unique_ptr<GrFragmentProcessor> MakeBilerpWithInset(
static std::unique_ptr<GrFragmentProcessor> MakeCustomLinearFilterInset(
GrSurfaceProxyView,
SkAlphaType,
const SkMatrix&,
@ -127,7 +127,7 @@ private:
kNone, // Using HW mode
kClamp, // Shader based clamp, no filter specialization
kRepeatNearest, // Simple repeat for nearest sampling
kRepeatBilerp, // Filter across the subset boundary for kRepeat mode
kRepeatLinear, // Filter across the subset boundary for kRepeat mode
kRepeatMipMap, // Logic for LOD selection with kRepeat mode.
kMirrorRepeat, // Mirror repeat (doesn't depend on filter))
kClampToBorderNearest, // Logic for hard transition to border color when not filtering.

View File

@ -58,7 +58,7 @@ std::unique_ptr<GrFragmentProcessor> GrYUVtoRGBEffect::Make(GrSurfaceProxyView v
SkTCopyOnFirstWrite<SkMatrix> planeMatrix(&SkMatrix::I());
SkRect planeSubset;
SkRect planeDomain;
bool makeBilerpWithSnap = false;
bool makeLinearWithSnap = false;
float sx = 1.f,
sy = 1.f;
if (dimensions != yDimensions) {
@ -88,13 +88,14 @@ std::unique_ptr<GrFragmentProcessor> GrYUVtoRGBEffect::Make(GrSurfaceProxyView v
domain->fRight * sx,
domain->fBottom * sy};
}
// This promotion of nearest to bilinear for UV planes exists to mimic libjpeg[-turbo]'s
// do_fancy_upsampling option. We will filter the subsampled plane, however we want to
// filter at a fixed point for each logical image pixel to simulate nearest neighbor.
// This promotion of nearest to linear filtering for UV planes exists to mimic
// libjpeg[-turbo]'s do_fancy_upsampling option. We will filter the subsampled plane,
// however we want to filter at a fixed point for each logical image pixel to simulate
// nearest neighbor.
if (samplerState.filter() == GrSamplerState::Filter::kNearest) {
bool snapX = (sx != 1.f),
snapY = (sy != 1.f);
makeBilerpWithSnap = snapX || snapY;
makeLinearWithSnap = snapX || snapY;
snap[0] |= snapX;
snap[1] |= snapY;
if (domain) {
@ -116,21 +117,21 @@ std::unique_ptr<GrFragmentProcessor> GrYUVtoRGBEffect::Make(GrSurfaceProxyView v
}
if (subset) {
SkASSERT(samplerState.filter() != GrSamplerState::Filter::kMipMap);
if (makeBilerpWithSnap) {
if (makeLinearWithSnap) {
// The plane is subsampled and we have an overall subset on the image. We're
// emulating do_fancy_upsampling using bilerp but snapping look ups to the y-plane
// pixel centers. Consider a logical image pixel at the edge of the subset. When
// computing the logical pixel color value we should use a 50/50 blend of two values
// from the subsampled plane. Depending on where the subset edge falls in actual
// subsampled plane, one of those values may come from outside the subset. Hence,
// we use this custom inset factory which applies the wrap mode to planeSubset but
// allows the bilerp sampling to read pixels from the plane that are just outside
// planeSubset.
// emulating do_fancy_upsampling using linear filtering but snapping look ups to the
// y-plane pixel centers. Consider a logical image pixel at the edge of the subset.
// When computing the logical pixel color value we should use a 50/50 blend of two
// values from the subsampled plane. Depending on where the subset edge falls in
// actual subsampled plane, one of those values may come from outside the subset.
// Hence, we use this custom inset factory which applies the wrap mode to
// planeSubset but allows linear filtering to read pixels from the plane that are
// just outside planeSubset.
SkRect* domainRect = domain ? &planeDomain : nullptr;
planeFPs[i] = GrTextureEffect::MakeBilerpWithInset(
planeFPs[i] = GrTextureEffect::MakeCustomLinearFilterInset(
views[i], kUnknown_SkAlphaType, *planeMatrix, samplerState.wrapModeX(),
samplerState.wrapModeY(), planeSubset, domainRect, {sx/2.f, sy/2.f}, caps,
planeBorders[i]);
samplerState.wrapModeY(), planeSubset, domainRect, {sx / 2.f, sy / 2.f},
caps, planeBorders[i]);
} else if (domain) {
planeFPs[i] = GrTextureEffect::MakeSubset(views[i], kUnknown_SkAlphaType,
*planeMatrix, samplerState, planeSubset,
@ -143,8 +144,8 @@ std::unique_ptr<GrFragmentProcessor> GrYUVtoRGBEffect::Make(GrSurfaceProxyView v
}
} else {
GrSamplerState planeSampler = samplerState;
if (makeBilerpWithSnap) {
planeSampler.setFilterMode(GrSamplerState::Filter::kBilerp);
if (makeLinearWithSnap) {
planeSampler.setFilterMode(GrSamplerState::Filter::kLinear);
}
planeFPs[i] = GrTextureEffect::Make(views[i], kUnknown_SkAlphaType, *planeMatrix,
planeSampler, caps, planeBorders[i]);

View File

@ -55,7 +55,7 @@ public:
GrColorType::kAlpha_8);
GrSurfaceProxyView view{std::move(proxy), kTopLeft_GrSurfaceOrigin, swizzle};
return GrTextureEffect::Make(std::move(view), kPremul_SkAlphaType, m,
GrSamplerState::Filter::kBilerp);
GrSamplerState::Filter::kLinear);
}
SkBitmap bitmap;
@ -81,7 +81,7 @@ public:
SkASSERT(view.origin() == kTopLeft_GrSurfaceOrigin);
proxyProvider->assignUniqueKeyToProxy(key, view.asTextureProxy());
return GrTextureEffect::Make(std::move(view), kPremul_SkAlphaType, m,
GrSamplerState::Filter::kBilerp);
GrSamplerState::Filter::kLinear);
}
static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> inputFP,
@ -121,7 +121,7 @@ public:
bool isFast = insetRect.isSorted();
return std::unique_ptr<GrFragmentProcessor>(
new GrRectBlurEffect(std::move(inputFP), insetRect, std::move(integral), isFast,
GrSamplerState::Filter::kBilerp));
GrSamplerState::Filter::kLinear));
}
GrRectBlurEffect(const GrRectBlurEffect& src);
std::unique_ptr<GrFragmentProcessor> clone() const override;

View File

@ -177,7 +177,7 @@ void GrGLGpu::TextureUnitBindings::invalidateAllTargets(bool markUnmodified) {
static GrGLenum filter_to_gl_mag_filter(GrSamplerState::Filter filter) {
switch (filter) {
case GrSamplerState::Filter::kNearest: return GR_GL_NEAREST;
case GrSamplerState::Filter::kBilerp: return GR_GL_LINEAR;
case GrSamplerState::Filter::kLinear: return GR_GL_LINEAR;
case GrSamplerState::Filter::kMipMap: return GR_GL_LINEAR;
}
SK_ABORT("Unknown filter");
@ -186,7 +186,7 @@ static GrGLenum filter_to_gl_mag_filter(GrSamplerState::Filter filter) {
static GrGLenum filter_to_gl_min_filter(GrSamplerState::Filter filter) {
switch (filter) {
case GrSamplerState::Filter::kNearest: return GR_GL_NEAREST;
case GrSamplerState::Filter::kBilerp: return GR_GL_LINEAR;
case GrSamplerState::Filter::kLinear: return GR_GL_LINEAR;
case GrSamplerState::Filter::kMipMap: return GR_GL_LINEAR_MIPMAP_LINEAR;
}
SK_ABORT("Unknown filter");
@ -2589,7 +2589,7 @@ void GrGLGpu::bindTexture(int unitIdx, GrSamplerState samplerState, const GrSwiz
if (samplerState.filter() == GrSamplerState::Filter::kMipMap) {
if (!this->caps()->mipMapSupport() ||
texture->texturePriv().mipMapped() == GrMipMapped::kNo) {
samplerState.setFilterMode(GrSamplerState::Filter::kBilerp);
samplerState.setFilterMode(GrSamplerState::Filter::kLinear);
}
}
@ -3436,7 +3436,7 @@ bool GrGLGpu::onRegenerateMipMapLevels(GrTexture* texture) {
// We'll be changing our base level further below:
this->setTextureUnit(0);
// The mipmap program does not do any swizzling.
this->bindTexture(0, GrSamplerState::Filter::kBilerp, GrSwizzle::RGBA(), glTex);
this->bindTexture(0, GrSamplerState::Filter::kLinear, GrSwizzle::RGBA(), glTex);
// Vertex data:
if (!fMipmapProgramArrayBuffer) {

View File

@ -68,7 +68,7 @@ static std::unique_ptr<GrFragmentProcessor> make_textured_colorizer(const SkPMCo
// TODO: When we start sampling colorizers with explicit coords rather than using sk_InColor
// the GrTextureEffect can simply be the colorizer.
auto m = SkMatrix::Scale(view.width(), 1.f);
auto te = GrTextureEffect::Make(std::move(view), alphaType, m, GrSamplerState::Filter::kBilerp);
auto te = GrTextureEffect::Make(std::move(view), alphaType, m, GrSamplerState::Filter::kLinear);
return GrTextureGradientColorizer::Make(std::move(te));
}

View File

@ -48,7 +48,7 @@ GrMtlSampler* GrMtlSampler::Create(const GrMtlGpu* gpu, GrSamplerState samplerSt
};
static_assert((int)GrSamplerState::Filter::kNearest == 0);
static_assert((int)GrSamplerState::Filter::kBilerp == 1);
static_assert((int)GrSamplerState::Filter::kLinear == 1);
static_assert((int)GrSamplerState::Filter::kMipMap == 2);
auto samplerDesc = [[MTLSamplerDescriptor alloc] init];

View File

@ -176,7 +176,7 @@ void GrAtlasTextOp::onPrepareDraws(Target* target) {
*target->caps().shaderCaps(),
views, numActiveViews);
} else {
auto filter = fNeedsGlyphTransform ? GrSamplerState::Filter::kBilerp
auto filter = fNeedsGlyphTransform ? GrSamplerState::Filter::kLinear
: GrSamplerState::Filter::kNearest;
flushInfo.fGeometryProcessor = GrBitmapTextGeoProc::Make(
target->allocator(), *target->caps().shaderCaps(), this->color(), false, views,
@ -323,13 +323,13 @@ void GrAtlasTextOp::createDrawForGeneratedGlyphs(
if (this->usesDistanceFields()) {
if (this->isLCD()) {
reinterpret_cast<GrDistanceFieldLCDTextGeoProc*>(gp)->addNewViews(
views, numActiveViews, GrSamplerState::Filter::kBilerp);
views, numActiveViews, GrSamplerState::Filter::kLinear);
} else {
reinterpret_cast<GrDistanceFieldA8TextGeoProc*>(gp)->addNewViews(
views, numActiveViews, GrSamplerState::Filter::kBilerp);
views, numActiveViews, GrSamplerState::Filter::kLinear);
}
} else {
auto filter = fNeedsGlyphTransform ? GrSamplerState::Filter::kBilerp
auto filter = fNeedsGlyphTransform ? GrSamplerState::Filter::kLinear
: GrSamplerState::Filter::kNearest;
reinterpret_cast<GrBitmapTextGeoProc*>(gp)->addNewViews(views, numActiveViews, filter);
}
@ -449,7 +449,7 @@ GrGeometryProcessor* GrAtlasTextOp::setupDfProcessor(SkArenaAlloc* arena,
GrDistanceFieldLCDTextGeoProc::DistanceAdjust::Make(
redCorrection, greenCorrection, blueCorrection);
return GrDistanceFieldLCDTextGeoProc::Make(arena, caps, views, numActiveViews,
GrSamplerState::Filter::kBilerp, widthAdjust,
GrSamplerState::Filter::kLinear, widthAdjust,
fDFGPFlags, localMatrix);
} else {
#ifdef SK_GAMMA_APPLY_TO_A8
@ -461,12 +461,12 @@ GrGeometryProcessor* GrAtlasTextOp::setupDfProcessor(SkArenaAlloc* arena,
fUseGammaCorrectDistanceTable);
}
return GrDistanceFieldA8TextGeoProc::Make(arena, caps, views, numActiveViews,
GrSamplerState::Filter::kBilerp, correction,
GrSamplerState::Filter::kLinear, correction,
fDFGPFlags, localMatrix);
#else
return GrDistanceFieldA8TextGeoProc::Make(arena, caps, views, numActiveViews,
GrSamplerState::Filter::kBilerp,
fDFGPFlags, localMatrix);
GrSamplerState::Filter::kLinear, fDFGPFlags,
localMatrix);
#endif
}
}

View File

@ -492,7 +492,7 @@ GR_DRAW_OP_TEST_DEFINE(NonAALatticeOp) {
SkMatrix viewMatrix = GrTest::TestMatrixPreservesRightAngles(random);
auto csxf = GrTest::TestColorXform(random);
GrSamplerState::Filter filter =
random->nextBool() ? GrSamplerState::Filter::kNearest : GrSamplerState::Filter::kBilerp;
random->nextBool() ? GrSamplerState::Filter::kNearest : GrSamplerState::Filter::kLinear;
GrSurfaceProxyView view(
std::move(proxy), origin,

View File

@ -373,7 +373,7 @@ private:
}
flushInfo.fGeometryProcessor = GrDistanceFieldPathGeoProc::Make(
target->allocator(), *target->caps().shaderCaps(), *matrix, fWideColor,
fAtlas->getViews(), fAtlas->numActivePages(), GrSamplerState::Filter::kBilerp,
fAtlas->getViews(), fAtlas->numActivePages(), GrSamplerState::Filter::kLinear,
flags);
} else {
SkMatrix invert;
@ -769,7 +769,7 @@ private:
if (fUsesDistanceField) {
reinterpret_cast<GrDistanceFieldPathGeoProc*>(gp)->addNewViews(
fAtlas->getViews(), fAtlas->numActivePages(),
GrSamplerState::Filter::kBilerp);
GrSamplerState::Filter::kLinear);
} else {
reinterpret_cast<GrBitmapTextGeoProc*>(gp)->addNewViews(
fAtlas->getViews(), fAtlas->numActivePages(),

View File

@ -561,11 +561,12 @@ private:
}
if (netFilter != filter && filter_has_effect(quad.fLocal, quad.fDevice)) {
// The only way netFilter != filter is if bilerp is requested and we haven't yet
// found a quad that requires bilerp (so net is still nearest).
// The only way netFilter != filter is if linear filtering is requested and we
// haven't yet found a quad that requires linear filtering (so net is still
// nearest).
SkASSERT(netFilter == GrSamplerState::Filter::kNearest &&
filter == GrSamplerState::Filter::kBilerp);
netFilter = GrSamplerState::Filter::kBilerp;
filter == GrSamplerState::Filter::kLinear);
netFilter = GrSamplerState::Filter::kLinear;
}
// Update overall bounds of the op as the union of all quads

View File

@ -465,7 +465,7 @@ DEF_GPUTEST(GrManyDependentsMipMappedTest, reporter, /* options */) {
// Draw the dirty mipmap texture into a render target, but don't do mipmap filtering.
rtc1 = draw_mipmap_into_new_render_target(context.get(), proxyProvider, colorType,
alphaType, mipmapView, Filter::kBilerp);
alphaType, mipmapView, Filter::kLinear);
// Mipmaps should have gotten marked dirty during makeClosed() when adding the dependency.
// Since the last draw did not use mips, they will not have been regenerated and should

View File

@ -29,7 +29,7 @@ static void test_basic_draw_as_src(skiatest::Reporter* reporter, GrRecordingCont
auto rtContext = GrRenderTargetContext::Make(
context, colorType, nullptr, SkBackingFit::kExact, rectView.proxy()->dimensions());
for (auto filter : {GrSamplerState::Filter::kNearest,
GrSamplerState::Filter::kBilerp,
GrSamplerState::Filter::kLinear,
GrSamplerState::Filter::kMipMap}) {
rtContext->clear(SkPMColor4f::FromBytes_RGBA(0xDDCCBBAA));
auto fp = GrTextureEffect::Make(rectView, alphaType, SkMatrix::I(), filter);