Simplify bitmapprocstate to just store bool for bilerp

Change-Id: Iffd08ce728b8d17df5b6e41ea789b86ce0da859a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/338321
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2020-11-24 16:04:05 -05:00 committed by Skia Commit-Bot
parent 95ab83f6fe
commit bbaad02ec2
4 changed files with 32 additions and 38 deletions

View File

@ -79,7 +79,7 @@ static void S32_alpha_D32_nofilter_DX(const SkBitmapProcState& s,
const uint32_t* xy, int count, SkPMColor* colors) {
SkASSERT(count > 0 && colors != nullptr);
SkASSERT(s.fInvMatrix.isScaleTranslate());
SkASSERT(kNone_SkFilterQuality == s.fFilterQuality);
SkASSERT(!s.fBilerp);
SkASSERT(4 == s.fPixmap.info().bytesPerPixel());
SkASSERT(s.fAlphaScale <= 256);
@ -122,7 +122,7 @@ static void S32_alpha_D32_nofilter_DX(const SkBitmapProcState& s,
static void S32_alpha_D32_nofilter_DXDY(const SkBitmapProcState& s,
const uint32_t* xy, int count, SkPMColor* colors) {
SkASSERT(count > 0 && colors != nullptr);
SkASSERT(kNone_SkFilterQuality == s.fFilterQuality);
SkASSERT(!s.fBilerp);
SkASSERT(4 == s.fPixmap.info().bytesPerPixel());
SkASSERT(s.fAlphaScale <= 256);
@ -189,7 +189,7 @@ bool SkBitmapProcState::init(const SkMatrix& inv, const SkPaint& paint) {
fPixmap.reset();
fInvMatrix = inv;
fFilterQuality = paint.getFilterQuality();
fBilerp = false;
fBMState = SkBitmapController::RequestBitmap(fImage, inv, paint.getFilterQuality(), &fAlloc);
@ -200,8 +200,8 @@ bool SkBitmapProcState::init(const SkMatrix& inv, const SkPaint& paint) {
fPixmap = fBMState->pixmap();
fInvMatrix = fBMState->invMatrix();
fPaintColor = paint.getColor();
fFilterQuality = fBMState->quality();
SkASSERT(fFilterQuality <= kLow_SkFilterQuality);
SkASSERT(fBMState->quality() <= kLow_SkFilterQuality);
fBilerp = fBMState->quality() == kLow_SkFilterQuality;
SkASSERT(fPixmap.addr());
bool integral_translate_only = just_trans_integral(fInvMatrix);
@ -236,10 +236,9 @@ bool SkBitmapProcState::init(const SkMatrix& inv, const SkPaint& paint) {
integral_translate_only = just_trans_integral(fInvMatrix);
}
if (kLow_SkFilterQuality == fFilterQuality &&
(!valid_for_filtering(fPixmap.width() | fPixmap.height()) ||
integral_translate_only)) {
fFilterQuality = kNone_SkFilterQuality;
if (fBilerp &&
(!valid_for_filtering(fPixmap.width() | fPixmap.height()) || integral_translate_only)) {
fBilerp = false;
}
return true;
@ -263,7 +262,6 @@ bool SkBitmapProcState::chooseProcs() {
fPixmap.alphaType() == kOpaque_SkAlphaType);
SkASSERT(fTileModeX != SkTileMode::kDecal);
SkASSERT(fFilterQuality < kHigh_SkFilterQuality);
fInvProc = SkMatrixPriv::GetMapXYProc(fInvMatrix);
fInvSxFractionalInt = SkScalarToFractionalInt(fInvMatrix.getScaleX());
@ -275,18 +273,17 @@ bool SkBitmapProcState::chooseProcs() {
fMatrixProc = this->chooseMatrixProc(translate_only);
SkASSERT(fMatrixProc);
const bool filter = fFilterQuality > kNone_SkFilterQuality;
if (fInvMatrix.isScaleTranslate()) {
fSampleProc32 = filter ? SkOpts::S32_alpha_D32_filter_DX : S32_alpha_D32_nofilter_DX ;
fSampleProc32 = fBilerp ? SkOpts::S32_alpha_D32_filter_DX : S32_alpha_D32_nofilter_DX ;
} else {
fSampleProc32 = filter ? SkOpts::S32_alpha_D32_filter_DXDY : S32_alpha_D32_nofilter_DXDY;
fSampleProc32 = fBilerp ? SkOpts::S32_alpha_D32_filter_DXDY : S32_alpha_D32_nofilter_DXDY;
}
SkASSERT(fSampleProc32);
// our special-case shaderprocs
// TODO: move this one into chooseShaderProc32() or pull all that in here.
if (fAlphaScale == 256
&& fFilterQuality == kNone_SkFilterQuality
&& !fBilerp
&& SkTileMode::kClamp == fTileModeX
&& SkTileMode::kClamp == fTileModeY
&& fInvMatrix.isScaleTranslate()) {
@ -305,7 +302,7 @@ static void Clamp_S32_D32_nofilter_trans_shaderproc(const void* sIn,
const SkBitmapProcState& s = *static_cast<const SkBitmapProcState*>(sIn);
SkASSERT(s.fInvMatrix.isTranslate());
SkASSERT(count > 0 && colors != nullptr);
SkASSERT(kNone_SkFilterQuality == s.fFilterQuality);
SkASSERT(!s.fBilerp);
const int maxX = s.fPixmap.width() - 1;
const int maxY = s.fPixmap.height() - 1;
@ -367,7 +364,7 @@ static void Repeat_S32_D32_nofilter_trans_shaderproc(const void* sIn,
const SkBitmapProcState& s = *static_cast<const SkBitmapProcState*>(sIn);
SkASSERT(s.fInvMatrix.isTranslate());
SkASSERT(count > 0 && colors != nullptr);
SkASSERT(kNone_SkFilterQuality == s.fFilterQuality);
SkASSERT(!s.fBilerp);
const int stopX = s.fPixmap.width();
const int stopY = s.fPixmap.height();
@ -426,7 +423,7 @@ static void S32_D32_constX_shaderproc(const void* sIn,
int iY1 SK_INIT_TO_AVOID_WARNING;
int iSubY SK_INIT_TO_AVOID_WARNING;
if (kNone_SkFilterQuality != s.fFilterQuality) {
if (s.fBilerp) {
SkBitmapProcState::MatrixProc mproc = s.getMatrixProc();
uint32_t xy[2];
@ -501,7 +498,7 @@ static void S32_D32_constX_shaderproc(const void* sIn,
const SkPMColor* row0 = s.fPixmap.addr32(0, iY0);
SkPMColor color;
if (kNone_SkFilterQuality != s.fFilterQuality) {
if (s.fBilerp) {
const SkPMColor* row1 = s.fPixmap.addr32(0, iY1);
filter_32_alpha(iSubY, *row0, *row1, &color, s.fAlphaScale);
} else {
@ -551,9 +548,7 @@ SkBitmapProcState::ShaderProc32 SkBitmapProcState::chooseShaderProc32() {
}
if (1 == fPixmap.width() && fInvMatrix.isScaleTranslate()) {
if (kNone_SkFilterQuality == fFilterQuality &&
fInvMatrix.isTranslate() &&
!this->setupForTranslate()) {
if (!fBilerp && fInvMatrix.isTranslate() && !this->setupForTranslate()) {
return DoNothing_shaderproc;
}
return S32_D32_constX_shaderproc;
@ -565,7 +560,7 @@ SkBitmapProcState::ShaderProc32 SkBitmapProcState::chooseShaderProc32() {
if (!fInvMatrix.isTranslate()) {
return nullptr;
}
if (kNone_SkFilterQuality != fFilterQuality) {
if (fBilerp) {
return nullptr;
}
@ -653,11 +648,10 @@ void SkBitmapProcState::DebugMatrixProc(const SkBitmapProcState& state,
void (*proc)(uint32_t bitmapXY[], int count, unsigned mx, unsigned my);
const bool filter = state.fFilterQuality > kNone_SkFilterQuality;
if (state.fInvMatrix.isScaleTranslate()) {
proc = filter ? check_scale_filter : check_scale_nofilter;
proc = state.fBilerp ? check_scale_filter : check_scale_nofilter;
} else {
proc = filter ? check_affine_filter : check_affine_nofilter;
proc = state.fBilerp ? check_affine_filter : check_affine_nofilter;
}
proc(bitmapXY, count, state.fPixmap.width(), state.fPixmap.height());
@ -692,7 +686,7 @@ int SkBitmapProcState::maxCountForBufferSize(size_t bufferSize) const {
size >>= 2;
}
if (fFilterQuality != kNone_SkFilterQuality) {
if (fBilerp) {
size >>= 1;
}

View File

@ -53,7 +53,7 @@ struct SkBitmapProcState {
SkColor fPaintColor;
SkTileMode fTileModeX;
SkTileMode fTileModeY;
SkFilterQuality fFilterQuality;
bool fBilerp;
SkMatrixPriv::MapXYProc fInvProc; // chooseProcs
SkFractionalInt fInvSxFractionalInt;
@ -162,16 +162,16 @@ public:
SkIntToScalar(y) + SK_ScalarHalf, &pt);
SkFixed biasX, biasY;
if (s.fFilterQuality == kNone_SkFilterQuality) {
if (s.fBilerp) {
biasX = s.fFilterOneX >> 1;
biasY = s.fFilterOneY >> 1;
} else {
// SkFixed epsilon bias to ensure inverse-mapped bitmap coordinates are rounded
// consistently WRT geometry. Note that we only need the bias for positive scales:
// for negative scales, the rounding is intrinsically correct.
// We scale it to persist SkFractionalInt -> SkFixed conversions.
biasX = (s.fInvMatrix.getScaleX() > 0);
biasY = (s.fInvMatrix.getScaleY() > 0);
} else {
biasX = s.fFilterOneX >> 1;
biasY = s.fFilterOneY >> 1;
}
// punt to unsigned for defined underflow behavior

View File

@ -474,7 +474,7 @@ SkBitmapProcState::MatrixProc SkBitmapProcState::chooseMatrixProc(bool translate
if( fTileModeX == fTileModeY ) {
// Check for our special case translate methods when there is no scale/affine/perspective.
if (translate_only_matrix && kNone_SkFilterQuality == fFilterQuality) {
if (translate_only_matrix && !fBilerp) {
switch (fTileModeX) {
default: SkASSERT(false); [[fallthrough]];
case SkTileMode::kClamp: return clampx_nofilter_trans<int_clamp>;
@ -484,7 +484,7 @@ SkBitmapProcState::MatrixProc SkBitmapProcState::chooseMatrixProc(bool translate
}
// The arrays are all [ nofilter, filter ].
int index = fFilterQuality > kNone_SkFilterQuality ? 1 : 0;
int index = fBilerp ? 1 : 0;
if (!fInvMatrix.isScaleTranslate()) {
index |= 2;
}

View File

@ -42,7 +42,7 @@ static void decode_packed_coordinates_and_weight(U32 packed, Out* v0, Out* v1, O
void S32_alpha_D32_filter_DX(const SkBitmapProcState& s,
const uint32_t* xy, int count, uint32_t* colors) {
SkASSERT(count > 0 && colors != nullptr);
SkASSERT(s.fFilterQuality != kNone_SkFilterQuality);
SkASSERT(s.fBilerp);
SkASSERT(kN32_SkColorType == s.fPixmap.colorType());
SkASSERT(s.fAlphaScale <= 256);
@ -174,7 +174,7 @@ static void decode_packed_coordinates_and_weight(U32 packed, Out* v0, Out* v1, O
void S32_alpha_D32_filter_DX(const SkBitmapProcState& s,
const uint32_t* xy, int count, uint32_t* colors) {
SkASSERT(count > 0 && colors != nullptr);
SkASSERT(s.fFilterQuality != kNone_SkFilterQuality);
SkASSERT(s.fBilerp);
SkASSERT(kN32_SkColorType == s.fPixmap.colorType());
SkASSERT(s.fAlphaScale <= 256);
@ -313,7 +313,7 @@ static void decode_packed_coordinates_and_weight(U32 packed, Out* v0, Out* v1, O
void S32_alpha_D32_filter_DX(const SkBitmapProcState& s,
const uint32_t* xy, int count, uint32_t* colors) {
SkASSERT(count > 0 && colors != nullptr);
SkASSERT(s.fFilterQuality != kNone_SkFilterQuality);
SkASSERT(s.fBilerp);
SkASSERT(kN32_SkColorType == s.fPixmap.colorType());
SkASSERT(s.fAlphaScale <= 256);
@ -475,7 +475,7 @@ static void decode_packed_coordinates_and_weight(U32 packed, Out* v0, Out* v1, O
void S32_alpha_D32_filter_DX(const SkBitmapProcState& s,
const uint32_t* xy, int count, SkPMColor* colors) {
SkASSERT(count > 0 && colors != nullptr);
SkASSERT(s.fFilterQuality != kNone_SkFilterQuality);
SkASSERT(s.fBilerp);
SkASSERT(4 == s.fPixmap.info().bytesPerPixel());
SkASSERT(s.fAlphaScale <= 256);
@ -504,7 +504,7 @@ static void decode_packed_coordinates_and_weight(U32 packed, Out* v0, Out* v1, O
void S32_alpha_D32_filter_DXDY(const SkBitmapProcState& s,
const uint32_t* xy, int count, SkPMColor* colors) {
SkASSERT(count > 0 && colors != nullptr);
SkASSERT(s.fFilterQuality != kNone_SkFilterQuality);
SkASSERT(s.fBilerp);
SkASSERT(4 == s.fPixmap.info().bytesPerPixel());
SkASSERT(s.fAlphaScale <= 256);