simplify SkSamplingOptions field names

SkSamplingOptions has no methods, so there's no need
to use an fPrefix to distinguish its fields from locals.
They'll always be accessed by foo.filter, bar->mipmap, etc.

Change-Id: Ia27ebea26d03eba60036616508731c4d2020462c
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/340356
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Mike Reed <reed@google.com>
This commit is contained in:
Mike Klein 2020-12-02 15:45:29 -06:00 committed by Skia Commit-Bot
parent dcc8960bc2
commit bb1933e0d6
4 changed files with 57 additions and 57 deletions

View File

@ -43,10 +43,10 @@ struct SkCubicResampler {
};
struct SK_API SkSamplingOptions {
const bool fUseCubic = false;
const SkCubicResampler fCubic = {0, 0};
const SkFilterMode fFilter = SkFilterMode::kNearest;
const SkMipmapMode fMipmap = SkMipmapMode::kNone;
const bool useCubic = false;
const SkCubicResampler cubic = {0, 0};
const SkFilterMode filter = SkFilterMode::kNearest;
const SkMipmapMode mipmap = SkMipmapMode::kNone;
SkSamplingOptions() = default;
SkSamplingOptions(const SkSamplingOptions&) = default;
@ -57,13 +57,13 @@ struct SK_API SkSamplingOptions {
}
SkSamplingOptions(SkFilterMode fm, SkMipmapMode mm)
: fUseCubic(false)
, fFilter(fm)
, fMipmap(mm) {}
: useCubic(false)
, filter(fm)
, mipmap(mm) {}
explicit SkSamplingOptions(const SkCubicResampler& cubic)
: fUseCubic(true)
, fCubic(cubic) {}
explicit SkSamplingOptions(const SkCubicResampler& c)
: useCubic(true)
, cubic(c) {}
explicit SkSamplingOptions(SkFilterQuality);
};

View File

@ -43,13 +43,13 @@ SkBitmapController::State* SkBitmapController::RequestBitmap(const SkImage_Base*
* (in this case, we have the inverse, so it succeeds if fInvMatrix is upscaling)
*/
bool SkBitmapController::State::extractMipLevel(const SkImage_Base* image) {
SkASSERT(!fSampling.fUseCubic);
if (fSampling.fMipmap != SkMipmapMode::kNearest) {
SkASSERT(!fSampling.useCubic);
if (fSampling.mipmap != SkMipmapMode::kNearest) {
return false;
}
// We will extract the right level here, so mark fSampling to know that has already happened.
fSampling = SkSamplingOptions(fSampling.fFilter, SkMipmapMode::kNone);
fSampling = SkSamplingOptions(fSampling.filter, SkMipmapMode::kNone);
SkSize invScaleSize;
if (!fInvMatrix.decomposeScale(&invScaleSize, nullptr)) {
@ -88,13 +88,13 @@ SkBitmapController::State::State(const SkImage_Base* image,
: fInvMatrix(inv)
, fSampling(sampling)
{
if (fSampling.fUseCubic &&
if (fSampling.useCubic &&
SkMatrixPriv::AdjustHighQualityFilterLevel(fInvMatrix, true) != kHigh_SkFilterQuality)
{
fSampling = SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kNearest);
}
if (!fSampling.fUseCubic && this->extractMipLevel(image)) {
if (!fSampling.useCubic && this->extractMipLevel(image)) {
SkASSERT(fResultBitmap.getPixels());
} else {
(void)image->getROPixels(nullptr, &fResultBitmap);

View File

@ -201,9 +201,9 @@ bool SkBitmapProcState::init(const SkMatrix& inv, SkColor paintColor,
fPixmap = fBMState->pixmap();
fInvMatrix = fBMState->invMatrix();
fPaintColor = paintColor;
SkASSERT(!fBMState->sampling().fUseCubic);
SkASSERT(fBMState->sampling().fMipmap == SkMipmapMode::kNone);
fBilerp = fBMState->sampling().fFilter == SkFilterMode::kLinear;
SkASSERT(!fBMState->sampling().useCubic);
SkASSERT(fBMState->sampling().mipmap == SkMipmapMode::kNone);
fBilerp = fBMState->sampling().filter == SkFilterMode::kLinear;
SkASSERT(fPixmap.addr());
bool integral_translate_only = just_trans_integral(fInvMatrix);

View File

@ -85,7 +85,7 @@ enum class LegacyFilterEnum {
kInheritFromPaint,
// this signals we should use the new SkFilterOptions
kUseFilterOptions,
// use fCubic and ignore FilterOptions
// use cubic and ignore FilterOptions
kUseCubicResampler,
kLast = kUseCubicResampler,
@ -145,13 +145,13 @@ sk_sp<SkFlattenable> SkImageShader::PreSamplingCreate(SkReadBuffer& buffer) {
}
static void write_sampling(SkWriteBuffer& buffer, SkSamplingOptions sampling) {
buffer.writeBool(sampling.fUseCubic);
if (sampling.fUseCubic) {
buffer.writeScalar(sampling.fCubic.B);
buffer.writeScalar(sampling.fCubic.C);
buffer.writeBool(sampling.useCubic);
if (sampling.useCubic) {
buffer.writeScalar(sampling.cubic.B);
buffer.writeScalar(sampling.cubic.C);
} else {
buffer.writeUInt((unsigned)sampling.fFilter);
buffer.writeUInt((unsigned)sampling.fMipmap);
buffer.writeUInt((unsigned)sampling.filter);
buffer.writeUInt((unsigned)sampling.mipmap);
}
}
@ -226,19 +226,19 @@ static bool is_default_cubic_resampler(SkCubicResampler cubic) {
static bool sampling_to_quality(SkSamplingOptions sampling, SkFilterQuality* quality) {
int q = -1; // not a legal quality enum
if (sampling.fUseCubic) {
if (is_default_cubic_resampler(sampling.fCubic)) {
if (sampling.useCubic) {
if (is_default_cubic_resampler(sampling.cubic)) {
q = kHigh_SkFilterQuality;
}
} else {
switch (sampling.fMipmap) {
switch (sampling.mipmap) {
case SkMipmapMode::kNone:
q = sampling.fFilter == SkFilterMode::kLinear ?
q = sampling.filter == SkFilterMode::kLinear ?
kLow_SkFilterQuality :
kNone_SkFilterQuality;
break;
case SkMipmapMode::kNearest:
if (sampling.fFilter == SkFilterMode::kLinear) {
if (sampling.filter == SkFilterMode::kLinear) {
q = kMedium_SkFilterQuality;
}
break;
@ -362,8 +362,8 @@ sk_sp<SkShader> SkImageShader::Make(sk_sp<SkImage> image,
auto is_unit = [](float x) {
return x >= 0 && x <= 1;
};
if (options && options->fUseCubic) {
if (!is_unit(options->fCubic.B) || !is_unit(options->fCubic.C)) {
if (options && options->useCubic) {
if (!is_unit(options->cubic.B) || !is_unit(options->cubic.C)) {
return nullptr;
}
}
@ -450,15 +450,15 @@ std::unique_ptr<GrFragmentProcessor> SkImageShader::asFragmentProcessor(
SkCubicResampler kernel = GrBicubicEffect::gMitchell;
if (fUseSamplingOptions) {
bicubic = fSampling.fUseCubic;
bicubic = fSampling.useCubic;
if (bicubic) {
kernel = fSampling.fCubic;
kernel = fSampling.cubic;
} else {
switch (fSampling.fFilter) {
switch (fSampling.filter) {
case SkFilterMode::kNearest: fm = GrSamplerState::Filter::kNearest; break;
case SkFilterMode::kLinear : fm = GrSamplerState::Filter::kLinear ; break;
}
switch (fSampling.fMipmap) {
switch (fSampling.mipmap) {
case SkMipmapMode::kNone : mm = GrSamplerState::MipmapMode::kNone ; break;
case SkMipmapMode::kNearest: mm = GrSamplerState::MipmapMode::kNearest; break;
case SkMipmapMode::kLinear : mm = GrSamplerState::MipmapMode::kLinear ; break;
@ -577,7 +577,7 @@ public:
};
static SkSamplingOptions tweak_filter_and_inv_matrix(SkSamplingOptions sampling, SkMatrix* matrix) {
SkFilterMode filter = sampling.fFilter;
SkFilterMode filter = sampling.filter;
// When the matrix is just an integer translate, bilerp == nearest neighbor.
if (filter == SkFilterMode::kLinear &&
@ -599,7 +599,7 @@ static SkSamplingOptions tweak_filter_and_inv_matrix(SkSamplingOptions sampling,
}
}
return SkSamplingOptions(filter, sampling.fMipmap);
return SkSamplingOptions(filter, sampling.mipmap);
}
bool SkImageShader::doStages(const SkStageRec& rec, SkImageStageUpdater* updater) const {
@ -607,16 +607,16 @@ bool SkImageShader::doStages(const SkStageRec& rec, SkImageStageUpdater* updater
: SkSamplingOptions(rec.fPaint.getFilterQuality());
// We only support certain sampling options in stages so far
if (sampling.fUseCubic) {
if (!is_default_cubic_resampler(sampling.fCubic)) {
if (sampling.useCubic) {
if (!is_default_cubic_resampler(sampling.cubic)) {
return false;
}
} else if (sampling.fMipmap == SkMipmapMode::kLinear) {
} else if (sampling.mipmap == SkMipmapMode::kLinear) {
return false;
}
if (updater && (sampling.fMipmap != SkMipmapMode::kNone)) {
if (updater && (sampling.mipmap != SkMipmapMode::kNone)) {
// TODO: medium: recall RequestBitmap and update width/height accordingly
return false;
}
@ -645,7 +645,7 @@ bool SkImageShader::doStages(const SkStageRec& rec, SkImageStageUpdater* updater
if (updater) {
updater->append_matrix_stage(p);
} else {
if (!sampling.fUseCubic) {
if (!sampling.useCubic) {
sampling = tweak_filter_and_inv_matrix(sampling, &matrix);
}
p->append_matrix(alloc, matrix);
@ -758,7 +758,7 @@ bool SkImageShader::doStages(const SkStageRec& rec, SkImageStageUpdater* updater
}
// Bicubic filtering naturally produces out of range values on both sides of [0,1].
if (sampling.fUseCubic) {
if (sampling.useCubic) {
p->append(SkRasterPipeline::clamp_0);
p->append(at == kUnpremul_SkAlphaType || fClampAsIfUnpremul
? SkRasterPipeline::clamp_1
@ -777,7 +777,7 @@ bool SkImageShader::doStages(const SkStageRec& rec, SkImageStageUpdater* updater
auto ct = info.colorType();
if (true
&& (ct == kRGBA_8888_SkColorType || ct == kBGRA_8888_SkColorType)
&& !sampling.fUseCubic && sampling.fFilter == SkFilterMode::kLinear
&& !sampling.useCubic && sampling.filter == SkFilterMode::kLinear
&& fTileModeX == SkTileMode::kClamp && fTileModeY == SkTileMode::kClamp) {
p->append(SkRasterPipeline::bilerp_clamp_8888, gather);
@ -788,7 +788,7 @@ bool SkImageShader::doStages(const SkStageRec& rec, SkImageStageUpdater* updater
}
if (true
&& (ct == kRGBA_8888_SkColorType || ct == kBGRA_8888_SkColorType) // TODO: all formats
&& !sampling.fUseCubic && sampling.fFilter == SkFilterMode::kLinear
&& !sampling.useCubic && sampling.filter == SkFilterMode::kLinear
&& fTileModeX != SkTileMode::kDecal // TODO decal too?
&& fTileModeY != SkTileMode::kDecal) {
@ -804,7 +804,7 @@ bool SkImageShader::doStages(const SkStageRec& rec, SkImageStageUpdater* updater
}
if (true
&& (ct == kRGBA_8888_SkColorType || ct == kBGRA_8888_SkColorType)
&& sampling.fUseCubic
&& sampling.useCubic
&& fTileModeX == SkTileMode::kClamp && fTileModeY == SkTileMode::kClamp) {
p->append(SkRasterPipeline::bicubic_clamp_8888, gather);
@ -815,7 +815,7 @@ bool SkImageShader::doStages(const SkStageRec& rec, SkImageStageUpdater* updater
}
if (true
&& (ct == kRGBA_8888_SkColorType || ct == kBGRA_8888_SkColorType) // TODO: all formats
&& sampling.fUseCubic
&& sampling.useCubic
&& fTileModeX != SkTileMode::kDecal // TODO decal too?
&& fTileModeY != SkTileMode::kDecal) {
@ -840,7 +840,7 @@ bool SkImageShader::doStages(const SkStageRec& rec, SkImageStageUpdater* updater
p->append(SkRasterPipeline::accumulate, sampler);
};
if (sampling.fUseCubic) {
if (sampling.useCubic) {
p->append(SkRasterPipeline::save_xy, sampler);
sample(SkRasterPipeline::bicubic_n3x, SkRasterPipeline::bicubic_n3y);
@ -864,7 +864,7 @@ bool SkImageShader::doStages(const SkStageRec& rec, SkImageStageUpdater* updater
sample(SkRasterPipeline::bicubic_p3x, SkRasterPipeline::bicubic_p3y);
p->append(SkRasterPipeline::move_dst_src);
} else if (sampling.fFilter == SkFilterMode::kLinear) {
} else if (sampling.filter == SkFilterMode::kLinear) {
p->append(SkRasterPipeline::save_xy, sampler);
sample(SkRasterPipeline::bilinear_nx, SkRasterPipeline::bilinear_ny);
@ -913,14 +913,14 @@ skvm::Color SkImageShader::onProgram(skvm::Builder* p,
};
auto sampling = fUseSamplingOptions ? fSampling : SkSamplingOptions(paintQuality);
if (sampling.fUseCubic) {
if (sampling.useCubic) {
auto* access = alloc->make<SkMipmapAccessor>(as_IB(fImage.get()), baseInv,
SkMipmapMode::kNone);
upper = &access->level();
upperInv = post_scale(upper->dimensions(), baseInv);
} else {
auto* access = alloc->make<SkMipmapAccessor>(as_IB(fImage.get()), baseInv,
sampling.fMipmap);
sampling.mipmap);
upper = &access->level();
upperInv = post_scale(upper->dimensions(), baseInv);
lowerWeight = access->lowerWeight();
@ -1056,7 +1056,7 @@ skvm::Color SkImageShader::onProgram(skvm::Builder* p,
auto sample_level = [&](const SkPixmap& pm, const SkMatrix& inv, skvm::Coord local) {
const Uniforms u = setup_uniforms(pm);
if (sampling.fUseCubic) {
if (sampling.useCubic) {
// All bicubic samples have the same fractional offset (fx,fy) from the center.
// They're either the 16 corners of a 3x3 grid/ surrounding (x,y) at (0.5,0.5) off-center.
skvm::F32 fx = fract(local.x + 0.5f),
@ -1064,7 +1064,7 @@ skvm::Color SkImageShader::onProgram(skvm::Builder* p,
skvm::F32 wx[4],
wy[4];
SkM44 weights = CubicResamplerMatrix(sampling.fCubic.B, sampling.fCubic.C);
SkM44 weights = CubicResamplerMatrix(sampling.cubic.B, sampling.cubic.C);
auto dot = [](const skvm::F32 a[], const skvm::F32 b[]) {
return a[0]*b[0] + a[1]*b[1] + a[2]*b[2] + a[3]*b[3];
@ -1101,7 +1101,7 @@ skvm::Color SkImageShader::onProgram(skvm::Builder* p,
}
}
return c;
} else if (sampling.fFilter == SkFilterMode::kLinear) {
} else if (sampling.filter == SkFilterMode::kLinear) {
// Our four sample points are the corners of a logical 1x1 pixel
// box surrounding (x,y) at (0.5,0.5) off-center.
skvm::F32 left = local.x - 0.5f,
@ -1116,7 +1116,7 @@ skvm::Color SkImageShader::onProgram(skvm::Builder* p,
return lerp(lerp(sample_texel(u, left,top ), sample_texel(u, right,top ), fx),
lerp(sample_texel(u, left,bottom), sample_texel(u, right,bottom), fx), fy);
} else {
SkASSERT(sampling.fFilter == SkFilterMode::kNearest);
SkASSERT(sampling.filter == SkFilterMode::kNearest);
return sample_texel(u, local.x,local.y);
}
};
@ -1151,7 +1151,7 @@ skvm::Color SkImageShader::onProgram(skvm::Builder* p,
at = kUnpremul_SkAlphaType;
}
if (sampling.fUseCubic) {
if (sampling.useCubic) {
// Bicubic filtering naturally produces out of range values on both sides of [0,1].
c.a = clamp01(c.a);