clean up SkBitmapProcState a bit

- remove dead code
  - fold some headers back into SkBitmapProcState.cpp
  - misc cleanup

Change-Id: I8706efec086ac9ab5795f59de4a60c8d1bb75a7b
Reviewed-on: https://skia-review.googlesource.com/c/171589
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Mike Klein <mtklein@google.com>
This commit is contained in:
Mike Klein 2018-11-19 10:25:04 -05:00 committed by Skia Commit-Bot
parent 5bf91dd14d
commit f2a7a20b32
6 changed files with 83 additions and 266 deletions

View File

@ -35,9 +35,6 @@ skia_core_sources = [
"$_src/core/SkBitmapProcState_matrix.h",
"$_src/core/SkBitmapProcState_matrix_template.h",
"$_src/core/SkBitmapProcState_matrixProcs.cpp",
"$_src/core/SkBitmapProcState_procs.h",
"$_src/core/SkBitmapProcState_sample.h",
"$_src/core/SkBitmapProcState_shaderproc.h",
"$_src/core/SkBitmapProcState_utils.h",
"$_src/core/SkBitmapProvider.cpp",
"$_src/core/SkBitmapProvider.h",

View File

@ -9,19 +9,14 @@
#include "SkBitmapController.h"
#include "SkBitmapProcState.h"
#include "SkColorData.h"
#include "SkImageEncoder.h"
#include "SkMacros.h"
#include "SkMipMap.h"
#include "SkOpts.h"
#include "SkPaint.h"
#include "SkShader.h" // for tilemodes
#include "SkUtilsArm.h"
#include "SkMipMap.h"
#include "SkImageEncoder.h"
#include "SkResourceCache.h"
#if defined(SK_ARM_HAS_NEON)
// These are defined in src/opts/SkBitmapProcState_arm_neon.cpp
extern const SkBitmapProcState::SampleProc32 gSkBitmapProcStateSample32_neon[];
#endif
#include "SkShader.h" // for tilemodes
#include "SkUtils.h"
// One-stop-shop shader for,
// - nearest-neighbor sampling (_nofilter_),
@ -30,7 +25,7 @@ extern const SkBitmapProcState::SampleProc32 gSkBitmapProcStateSample32_neon[];
// - and no extra alpha applied (_opaque_),
// - sampling from 8888 (_S32_) and drawing to 8888 (_S32_).
static void Clamp_S32_opaque_D32_nofilter_DX_shaderproc(const void* sIn, int x, int y,
SkPMColor* SK_RESTRICT dst, int count) {
SkPMColor* dst, int count) {
const SkBitmapProcState& s = *static_cast<const SkBitmapProcState*>(sIn);
SkASSERT((s.fInvType & ~(SkMatrix::kTranslate_Mask |
SkMatrix::kScale_Mask)) == 0);
@ -46,7 +41,7 @@ static void Clamp_S32_opaque_D32_nofilter_DX_shaderproc(const void* sIn, int x,
fx = mapper.fractionalIntX();
}
const SkPMColor* SK_RESTRICT src = s.fPixmap.addr32(0, dstY);
const SkPMColor* src = s.fPixmap.addr32(0, dstY);
const SkFractionalInt dx = s.fInvSxFractionalInt;
// Check if we're safely inside [0...maxX] so no need to clamp each computed index.
@ -80,8 +75,49 @@ static void Clamp_S32_opaque_D32_nofilter_DX_shaderproc(const void* sIn, int x,
}
}
#define NAME_WRAP(x) x
#include "SkBitmapProcState_procs.h"
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.fInvType <= (SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask));
SkASSERT(kNone_SkFilterQuality == s.fFilterQuality);
SkASSERT(4 == s.fPixmap.info().bytesPerPixel());
SkASSERT(s.fAlphaScale <= 256);
// xy is a 32-bit y-coordinate, followed by 16-bit x-coordinates.
unsigned y = *xy++;
SkASSERT(y < (unsigned)s.fPixmap.height());
auto row = (const SkPMColor*)( (const char*)s.fPixmap.addr() + y * s.fPixmap.rowBytes() );
if (1 == s.fPixmap.width()) {
sk_memset32(colors, SkAlphaMulQ(row[0], s.fAlphaScale), count);
return;
}
// Step 4 xs == 2 uint32_t at a time.
while (count >= 4) {
uint32_t x01 = *xy++,
x23 = *xy++;
SkPMColor p0 = row[UNPACK_PRIMARY_SHORT (x01)];
SkPMColor p1 = row[UNPACK_SECONDARY_SHORT(x01)];
SkPMColor p2 = row[UNPACK_PRIMARY_SHORT (x23)];
SkPMColor p3 = row[UNPACK_SECONDARY_SHORT(x23)];
*colors++ = SkAlphaMulQ(p0, s.fAlphaScale);
*colors++ = SkAlphaMulQ(p1, s.fAlphaScale);
*colors++ = SkAlphaMulQ(p2, s.fAlphaScale);
*colors++ = SkAlphaMulQ(p3, s.fAlphaScale);
count -= 4;
}
// Step 1 x == 1 uint16_t at a time.
auto x = (const uint16_t*)xy;
while (count --> 0) {
*colors++ = SkAlphaMulQ(row[*x++], s.fAlphaScale);
}
}
SkBitmapProcInfo::SkBitmapProcInfo(const SkBitmapProvider& provider,
SkShader::TileMode tmx, SkShader::TileMode tmy)
@ -93,7 +129,6 @@ SkBitmapProcInfo::SkBitmapProcInfo(const SkBitmapProvider& provider,
SkBitmapProcInfo::~SkBitmapProcInfo() {}
///////////////////////////////////////////////////////////////////////////////
// true iff the matrix has a scale and no more than an optional translate.
static bool matrix_only_scale_translate(const SkMatrix& m) {
@ -207,71 +242,50 @@ bool SkBitmapProcInfo::init(const SkMatrix& inv, const SkPaint& paint) {
* and may be removed.
*/
bool SkBitmapProcState::chooseProcs() {
SkASSERT(fInvType <= (SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask));
SkASSERT(fPixmap.colorType() == kN32_SkColorType);
SkASSERT(fPixmap.alphaType() == kPremul_SkAlphaType ||
fPixmap.alphaType() == kOpaque_SkAlphaType);
SkASSERT(fTileModeX == fTileModeY);
SkASSERT(fTileModeX != SkShader::kDecal_TileMode);
SkASSERT(fFilterQuality < kHigh_SkFilterQuality);
fInvProc = SkMatrixPriv::GetMapXYProc(fInvMatrix);
fInvSx = SkScalarToFixed(fInvMatrix.getScaleX());
fInvSx = SkScalarToFixed (fInvMatrix.getScaleX());
fInvSxFractionalInt = SkScalarToFractionalInt(fInvMatrix.getScaleX());
fInvKy = SkScalarToFixed(fInvMatrix.getSkewY());
fInvKy = SkScalarToFixed (fInvMatrix.getSkewY());
fInvKyFractionalInt = SkScalarToFractionalInt(fInvMatrix.getSkewY());
fAlphaScale = SkAlpha255To256(SkColorGetA(fPaintColor));
fShaderProc32 = nullptr;
fSampleProc32 = nullptr;
const bool trivialMatrix = (fInvMatrix.getType() & ~SkMatrix::kTranslate_Mask) == 0;
const bool clampClamp = SkShader::kClamp_TileMode == fTileModeX &&
SkShader::kClamp_TileMode == fTileModeY;
return this->chooseScanlineProcs(trivialMatrix, clampClamp);
}
bool SkBitmapProcState::chooseScanlineProcs(bool trivialMatrix, bool clampClamp) {
SkASSERT(fPixmap.colorType() == kN32_SkColorType);
SkASSERT(fInvType <= (SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask));
fMatrixProc = this->chooseMatrixProc(trivialMatrix);
// TODO(dominikg): SkASSERT(fMatrixProc) instead? chooseMatrixProc never returns nullptr.
if (nullptr == fMatrixProc) {
return false;
}
const SkAlphaType at = fPixmap.alphaType();
if (kPremul_SkAlphaType != at && kOpaque_SkAlphaType != at) {
return false;
}
// No need to do this if we're doing HQ sampling; if filter quality is
// still set to HQ by the time we get here, then we must have installed
// the shader procs above and can skip all this.
if (fFilterQuality < kHigh_SkFilterQuality) {
if (fFilterQuality > kNone_SkFilterQuality) {
fSampleProc32 = SkOpts::S32_alpha_D32_filter_DX;
} else {
fSampleProc32 = S32_alpha_D32_nofilter_DX;
}
// our special-case shaderprocs
// TODO: move this one into chooseShaderProc32() or pull all that in here.
if (fAlphaScale == 256
&& fFilterQuality == kNone_SkFilterQuality
&& clampClamp) {
fShaderProc32 = Clamp_S32_opaque_D32_nofilter_DX_shaderproc;
} else {
fShaderProc32 = this->chooseShaderProc32();
}
}
// see if our platform has any accelerated overrides
bool translate_only = (fInvMatrix.getType() & ~SkMatrix::kTranslate_Mask) == 0;
fMatrixProc = this->chooseMatrixProc(translate_only);
SkASSERT(fMatrixProc);
// Look for platform specializations (only fMatrixProc anymore).
this->platformProcs();
if (fFilterQuality > kNone_SkFilterQuality) {
fSampleProc32 = SkOpts::S32_alpha_D32_filter_DX;
} else {
fSampleProc32 = S32_alpha_D32_nofilter_DX;
}
// our special-case shaderprocs
// TODO: move this one into chooseShaderProc32() or pull all that in here.
if (fAlphaScale == 256
&& fFilterQuality == kNone_SkFilterQuality
&& SkShader::kClamp_TileMode == fTileModeX) {
fShaderProc32 = Clamp_S32_opaque_D32_nofilter_DX_shaderproc;
} else {
fShaderProc32 = this->chooseShaderProc32();
}
return true;
}
static void Clamp_S32_D32_nofilter_trans_shaderproc(const void* sIn,
int x, int y,
SkPMColor* SK_RESTRICT colors,
SkPMColor* colors,
int count) {
const SkBitmapProcState& s = *static_cast<const SkBitmapProcState*>(sIn);
SkASSERT(((s.fInvType & ~SkMatrix::kTranslate_Mask)) == 0);
@ -334,7 +348,7 @@ static inline int sk_int_mirror(int x, int n) {
static void Repeat_S32_D32_nofilter_trans_shaderproc(const void* sIn,
int x, int y,
SkPMColor* SK_RESTRICT colors,
SkPMColor* colors,
int count) {
const SkBitmapProcState& s = *static_cast<const SkBitmapProcState*>(sIn);
SkASSERT(((s.fInvType & ~SkMatrix::kTranslate_Mask)) == 0);
@ -388,7 +402,7 @@ static inline void filter_32_alpha(unsigned t,
static void S32_D32_constX_shaderproc(const void* sIn,
int x, int y,
SkPMColor* SK_RESTRICT colors,
SkPMColor* colors,
int count) {
const SkBitmapProcState& s = *static_cast<const SkBitmapProcState*>(sIn);
SkASSERT((s.fInvType & ~(SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask)) == 0);
@ -492,7 +506,7 @@ static void S32_D32_constX_shaderproc(const void* sIn,
}
static void DoNothing_shaderproc(const void*, int x, int y,
SkPMColor* SK_RESTRICT colors, int count) {
SkPMColor* colors, int count) {
// if we get called, the matrix is too tricky, so we just draw nothing
sk_memset32(colors, 0, count);
}
@ -565,8 +579,6 @@ SkBitmapProcState::ShaderProc32 SkBitmapProcState::chooseShaderProc32() {
return nullptr;
}
///////////////////////////////////////////////////////////////////////////////
#ifdef SK_DEBUG
static void check_scale_nofilter(uint32_t bitmapXY[], int count,
@ -621,7 +633,6 @@ SkBitmapProcState::MatrixProc SkBitmapProcState::getMatrixProc() const {
#endif
///////////////////////////////////////////////////////////////////////////////
/*
The storage requirements for the different matrix procs are as follows,
where each X or Y is 2 bytes, and N is the number of pixels/elements:
@ -652,5 +663,3 @@ int SkBitmapProcState::maxCountForBufferSize(size_t bufferSize) const {
return size;
}
///////////////////////

View File

@ -135,7 +135,6 @@ private:
MatrixProc chooseMatrixProc(bool trivial_matrix);
bool chooseProcs(); // caller must have called init() first (on our base-class)
bool chooseScanlineProcs(bool trivialMatrix, bool clampClamp);
ShaderProc32 chooseShaderProc32();
// Return false if we failed to setup for fast translate (e.g. overflow)

View File

@ -1,24 +0,0 @@
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
// Define NAME_WRAP(x) before including this header to perform name-wrapping
// E.g. for ARM NEON, defined it as 'x ## _neon' to ensure all important
// identifiers have a _neon suffix.
#ifndef NAME_WRAP
#error "Please define NAME_WRAP() before including this file"
#endif
#define MAKENAME(suffix) NAME_WRAP(S32_alpha_D32 ## suffix)
#define SRCTYPE SkPMColor
#define CHECKSTATE(state) SkASSERT(4 == state.fPixmap.info().bytesPerPixel()); \
SkASSERT(state.fAlphaScale <= 256)
#define PREAMBLE(state) unsigned alphaScale = state.fAlphaScale
#define RETURNDST(src) SkAlphaMulQ(src, alphaScale)
#define SRC_TO_FILTER(src) src
#include "SkBitmapProcState_sample.h"
#undef NAME_WRAP

View File

@ -1,81 +0,0 @@
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkUtils.h"
// declare functions externally to suppress warnings.
void MAKENAME(_nofilter_DX)(const SkBitmapProcState& s,
const uint32_t* SK_RESTRICT xy,
int count, SkPMColor* SK_RESTRICT colors);
void MAKENAME(_nofilter_DX)(const SkBitmapProcState& s,
const uint32_t* SK_RESTRICT xy,
int count, SkPMColor* SK_RESTRICT colors) {
SkASSERT(count > 0 && colors != nullptr);
SkASSERT(s.fInvType <= (SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask));
SkASSERT(kNone_SkFilterQuality == s.fFilterQuality);
SkDEBUGCODE(CHECKSTATE(s);)
#ifdef PREAMBLE
PREAMBLE(s);
#endif
const SRCTYPE* SK_RESTRICT srcAddr = (const SRCTYPE*)s.fPixmap.addr();
// buffer is y32, x16, x16, x16, x16, x16
// bump srcAddr to the proper row, since we're told Y never changes
SkASSERT((unsigned)xy[0] < (unsigned)s.fPixmap.height());
srcAddr = (const SRCTYPE*)((const char*)srcAddr +
xy[0] * s.fPixmap.rowBytes());
xy += 1;
SRCTYPE src;
if (1 == s.fPixmap.width()) {
src = srcAddr[0];
SkPMColor dstValue = RETURNDST(src);
sk_memset32(colors, dstValue, count);
} else {
int i;
for (i = (count >> 2); i > 0; --i) {
uint32_t xx0 = *xy++;
uint32_t xx1 = *xy++;
SRCTYPE x0 = srcAddr[UNPACK_PRIMARY_SHORT(xx0)];
SRCTYPE x1 = srcAddr[UNPACK_SECONDARY_SHORT(xx0)];
SRCTYPE x2 = srcAddr[UNPACK_PRIMARY_SHORT(xx1)];
SRCTYPE x3 = srcAddr[UNPACK_SECONDARY_SHORT(xx1)];
*colors++ = RETURNDST(x0);
*colors++ = RETURNDST(x1);
*colors++ = RETURNDST(x2);
*colors++ = RETURNDST(x3);
}
const uint16_t* SK_RESTRICT xx = (const uint16_t*)(xy);
for (i = (count & 3); i > 0; --i) {
SkASSERT(*xx < (unsigned)s.fPixmap.width());
src = srcAddr[*xx++]; *colors++ = RETURNDST(src);
}
}
}
///////////////////////////////////////////////////////////////////////////////
#undef MAKENAME
#undef SRCTYPE
#undef CHECKSTATE
#undef RETURNDST
#undef SRC_TO_FILTER
#undef FILTER_TO_DST
#ifdef PREAMBLE
#undef PREAMBLE
#endif
#undef FILTER_PROC_TYPE
#undef GET_FILTER_TABLE
#undef GET_FILTER_ROW
#undef GET_FILTER_ROW_PROC
#undef GET_FILTER_PROC

View File

@ -1,83 +0,0 @@
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkMathPriv.h"
#define SCALE_FILTER_NAME MAKENAME(_filter_DX_shaderproc)
// Can't be static in the general case because some of these implementations
// will be defined and referenced in different object files.
void SCALE_FILTER_NAME(const void* sIn, int x, int y, SkPMColor* SK_RESTRICT colors, int count);
void SCALE_FILTER_NAME(const void* sIn, int x, int y, SkPMColor* SK_RESTRICT colors, int count) {
const SkBitmapProcState& s = *static_cast<const SkBitmapProcState*>(sIn);
SkASSERT((s.fInvType & ~(SkMatrix::kTranslate_Mask |
SkMatrix::kScale_Mask)) == 0);
SkASSERT(s.fInvKy == 0);
SkASSERT(count > 0 && colors != nullptr);
SkASSERT(s.fFilterQuality != kNone_SkFilterQuality);
SkDEBUGCODE(CHECKSTATE(s);)
const unsigned maxX = s.fPixmap.width() - 1;
const SkFixed oneX = s.fFilterOneX;
const SkFixed dx = s.fInvSx;
SkFixed fx;
const SRCTYPE* SK_RESTRICT row0;
const SRCTYPE* SK_RESTRICT row1;
unsigned subY;
{
const SkBitmapProcStateAutoMapper mapper(s, x, y);
SkFixed fy = mapper.fixedY();
const unsigned maxY = s.fPixmap.height() - 1;
// compute our two Y values up front
subY = EXTRACT_LOW_BITS(fy, maxY);
int y0 = TILEY_PROCF(fy, maxY);
int y1 = TILEY_PROCF((fy + s.fFilterOneY), maxY);
const char* SK_RESTRICT srcAddr = (const char*)s.fPixmap.addr();
size_t rb = s.fPixmap.rowBytes();
row0 = (const SRCTYPE*)(srcAddr + y0 * rb);
row1 = (const SRCTYPE*)(srcAddr + y1 * rb);
// now initialize fx
fx = mapper.fixedX();
}
#ifdef PREAMBLE
PREAMBLE(s);
#endif
do {
unsigned subX = EXTRACT_LOW_BITS(fx, maxX);
unsigned x0 = TILEX_PROCF(fx, maxX);
unsigned x1 = TILEX_PROCF((fx + oneX), maxX);
FILTER_PROC(subX, subY,
SRC_TO_FILTER(row0[x0]),
SRC_TO_FILTER(row0[x1]),
SRC_TO_FILTER(row1[x0]),
SRC_TO_FILTER(row1[x1]),
colors);
colors += 1;
fx += dx;
} while (--count != 0);
}
///////////////////////////////////////////////////////////////////////////////
#undef TILEX_PROCF
#undef TILEY_PROCF
#undef EXTRACT_LOW_BITS
#undef MAKENAME
#undef SRCTYPE
#undef CHECKSTATE
#undef SRC_TO_FILTER
#undef FILTER_TO_DST
#undef PREAMBLE
#undef SCALE_FILTER_NAME