Skip to content

Commit

Permalink
move unspecialized routines out of SkOpts
Browse files Browse the repository at this point in the history
No src/opts/SkOpts_foo.cpp ever replaces these function pointers with
a specialized version, so there's no value to the indirection.

I kind of want to rewrite most of this, but I've not done that here.
It's all just the same code moved around.

Change-Id: Iecb81a64aff3e9ed18c1a3c6d2eb1a6e94e966de
Reviewed-on: https://skia-review.googlesource.com/c/165400
Auto-Submit: Mike Klein <[email protected]>
Reviewed-by: Mike Klein <[email protected]>
Commit-Queue: Mike Klein <[email protected]>
  • Loading branch information
Mike Klein authored and Skia Commit-Bot committed Oct 26, 2018
1 parent 8677607 commit d99bd00
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 178 deletions.
1 change: 0 additions & 1 deletion gn/core.gni
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,6 @@ skia_core_sources = [
"$_src/opts/SkBlitMask_opts.h",
"$_src/opts/SkBlitRow_opts.h",
"$_src/opts/SkChecksum_opts.h",
"$_src/opts/SkMorphologyImageFilter_opts.h",
"$_src/opts/SkNx_neon.h",
"$_src/opts/SkNx_sse.h",
"$_src/opts/SkRasterPipeline_opts.h",
Expand Down
15 changes: 13 additions & 2 deletions src/core/SkBlitRow_D32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
* found in the LICENSE file.
*/

#include "SkBlitRow.h"
#include "Sk4px.h"
#include "SkBlitMask.h"
#include "SkBlitRow.h"
#include "SkColorData.h"
#include "SkOpts.h"
#include "SkUtils.h"
Expand Down Expand Up @@ -115,5 +116,15 @@ void SkBlitRow::Color32(SkPMColor dst[], const SkPMColor src[], int count, SkPMC
case 0: memmove(dst, src, count * sizeof(SkPMColor)); return;
case 255: sk_memset32(dst, color, count); return;
}
return SkOpts::blit_row_color32(dst, src, count, color);

unsigned invA = 255 - SkGetPackedA32(color);
invA += invA >> 7;
SkASSERT(invA < 256); // We've should have already handled alpha == 0 externally.

Sk16h colorHighAndRound = Sk4px::DupPMColor(color).widenHi() + Sk16h(128);
Sk16b invA_16x(invA);

Sk4px::MapSrc(count, dst, src, [&](const Sk4px& src4) -> Sk4px {
return (src4 * invA_16x).addNarrowHi(colorHighAndRound);
});
}
7 changes: 0 additions & 7 deletions src/core/SkOpts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#include "SkBlitMask_opts.h"
#include "SkBlitRow_opts.h"
#include "SkChecksum_opts.h"
#include "SkMorphologyImageFilter_opts.h"
#include "SkRasterPipeline_opts.h"
#include "SkSwizzler_opts.h"
#include "SkUtils_opts.h"
Expand All @@ -53,14 +52,8 @@ namespace SkOpts {
#define DEFINE_DEFAULT(name) decltype(name) name = SK_OPTS_NS::name
DEFINE_DEFAULT(create_xfermode);

DEFINE_DEFAULT(dilate_x);
DEFINE_DEFAULT(dilate_y);
DEFINE_DEFAULT( erode_x);
DEFINE_DEFAULT( erode_y);

DEFINE_DEFAULT(blit_mask_d32_a8);

DEFINE_DEFAULT(blit_row_color32);
DEFINE_DEFAULT(blit_row_s32a_opaque);

DEFINE_DEFAULT(RGBA_to_BGRA);
Expand Down
4 changes: 0 additions & 4 deletions src/core/SkOpts.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ namespace SkOpts {
// May return nullptr if we haven't specialized the given Mode.
extern SkXfermode* (*create_xfermode)(SkBlendMode);

typedef void (*Morph)(const SkPMColor*, SkPMColor*, int, int, int, int, int);
extern Morph dilate_x, dilate_y, erode_x, erode_y;

extern void (*blit_mask_d32_a8)(SkPMColor*, size_t, const SkAlpha*, size_t, SkColor, int, int);
extern void (*blit_row_color32)(SkPMColor*, const SkPMColor*, int, SkPMColor);
extern void (*blit_row_s32a_opaque)(SkPMColor*, const SkPMColor*, int, U8CPU);

// Swizzle input into some sort of 8888 pixel, {premul,unpremul} x {rgba,bgra}.
Expand Down
126 changes: 121 additions & 5 deletions src/effects/imagefilters/SkMorphologyImageFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "SkColorData.h"
#include "SkColorSpaceXformer.h"
#include "SkImageFilterPriv.h"
#include "SkOpts.h"
#include "SkReadBuffer.h"
#include "SkRect.h"
#include "SkSpecialImage.h"
Expand Down Expand Up @@ -518,6 +517,123 @@ static sk_sp<SkSpecialImage> apply_morphology(
}
#endif

namespace {
enum MorphType { kDilate, kErode };
enum class MorphDirection { kX, kY };

#if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2
template<MorphType type, MorphDirection direction>
static void morph(const SkPMColor* src, SkPMColor* dst,
int radius, int width, int height, int srcStride, int dstStride) {
const int srcStrideX = direction == MorphDirection::kX ? 1 : srcStride;
const int dstStrideX = direction == MorphDirection::kX ? 1 : dstStride;
const int srcStrideY = direction == MorphDirection::kX ? srcStride : 1;
const int dstStrideY = direction == MorphDirection::kX ? dstStride : 1;
radius = SkMin32(radius, width - 1);
const SkPMColor* upperSrc = src + radius * srcStrideX;
for (int x = 0; x < width; ++x) {
const SkPMColor* lp = src;
const SkPMColor* up = upperSrc;
SkPMColor* dptr = dst;
for (int y = 0; y < height; ++y) {
__m128i extreme = (type == kDilate) ? _mm_setzero_si128()
: _mm_set1_epi32(0xFFFFFFFF);
for (const SkPMColor* p = lp; p <= up; p += srcStrideX) {
__m128i src_pixel = _mm_cvtsi32_si128(*p);
extreme = (type == kDilate) ? _mm_max_epu8(src_pixel, extreme)
: _mm_min_epu8(src_pixel, extreme);
}
*dptr = _mm_cvtsi128_si32(extreme);
dptr += dstStrideY;
lp += srcStrideY;
up += srcStrideY;
}
if (x >= radius) { src += srcStrideX; }
if (x + radius < width - 1) { upperSrc += srcStrideX; }
dst += dstStrideX;
}
}

#elif defined(SK_ARM_HAS_NEON)
template<MorphType type, MorphDirection direction>
static void morph(const SkPMColor* src, SkPMColor* dst,
int radius, int width, int height, int srcStride, int dstStride) {
const int srcStrideX = direction == MorphDirection::kX ? 1 : srcStride;
const int dstStrideX = direction == MorphDirection::kX ? 1 : dstStride;
const int srcStrideY = direction == MorphDirection::kX ? srcStride : 1;
const int dstStrideY = direction == MorphDirection::kX ? dstStride : 1;
radius = SkMin32(radius, width - 1);
const SkPMColor* upperSrc = src + radius * srcStrideX;
for (int x = 0; x < width; ++x) {
const SkPMColor* lp = src;
const SkPMColor* up = upperSrc;
SkPMColor* dptr = dst;
for (int y = 0; y < height; ++y) {
uint8x8_t extreme = vdup_n_u8(type == kDilate ? 0 : 255);
for (const SkPMColor* p = lp; p <= up; p += srcStrideX) {
uint8x8_t src_pixel = vreinterpret_u8_u32(vdup_n_u32(*p));
extreme = (type == kDilate) ? vmax_u8(src_pixel, extreme)
: vmin_u8(src_pixel, extreme);
}
*dptr = vget_lane_u32(vreinterpret_u32_u8(extreme), 0);
dptr += dstStrideY;
lp += srcStrideY;
up += srcStrideY;
}
if (x >= radius) src += srcStrideX;
if (x + radius < width - 1) upperSrc += srcStrideX;
dst += dstStrideX;
}
}

#else
template<MorphType type, MorphDirection direction>
static void morph(const SkPMColor* src, SkPMColor* dst,
int radius, int width, int height, int srcStride, int dstStride) {
const int srcStrideX = direction == MorphDirection::kX ? 1 : srcStride;
const int dstStrideX = direction == MorphDirection::kX ? 1 : dstStride;
const int srcStrideY = direction == MorphDirection::kX ? srcStride : 1;
const int dstStrideY = direction == MorphDirection::kX ? dstStride : 1;
radius = SkMin32(radius, width - 1);
const SkPMColor* upperSrc = src + radius * srcStrideX;
for (int x = 0; x < width; ++x) {
const SkPMColor* lp = src;
const SkPMColor* up = upperSrc;
SkPMColor* dptr = dst;
for (int y = 0; y < height; ++y) {
// If we're maxing (dilate), start from 0; if minning (erode), start from 255.
const int start = (type == kDilate) ? 0 : 255;
int B = start, G = start, R = start, A = start;
for (const SkPMColor* p = lp; p <= up; p += srcStrideX) {
int b = SkGetPackedB32(*p),
g = SkGetPackedG32(*p),
r = SkGetPackedR32(*p),
a = SkGetPackedA32(*p);
if (type == kDilate) {
B = SkTMax(b, B);
G = SkTMax(g, G);
R = SkTMax(r, R);
A = SkTMax(a, A);
} else {
B = SkTMin(b, B);
G = SkTMin(g, G);
R = SkTMin(r, R);
A = SkTMin(a, A);
}
}
*dptr = SkPackARGB32(A, R, G, B);
dptr += dstStrideY;
lp += srcStrideY;
up += srcStrideY;
}
if (x >= radius) { src += srcStrideX; }
if (x + radius < width - 1) { upperSrc += srcStrideX; }
dst += dstStrideX;
}
}
#endif
} // namespace

sk_sp<SkSpecialImage> SkMorphologyImageFilter::onFilterImage(SkSpecialImage* source,
const Context& ctx,
SkIPoint* offset) const {
Expand Down Expand Up @@ -596,11 +712,11 @@ sk_sp<SkSpecialImage> SkMorphologyImageFilter::onFilterImage(SkSpecialImage* sou
SkMorphologyImageFilter::Proc procX, procY;

if (kDilate_Op == this->op()) {
procX = SkOpts::dilate_x;
procY = SkOpts::dilate_y;
procX = &morph<kDilate, MorphDirection::kX>;
procY = &morph<kDilate, MorphDirection::kY>;
} else {
procX = SkOpts::erode_x;
procY = SkOpts::erode_y;
procX = &morph<kErode, MorphDirection::kX>;
procY = &morph<kErode, MorphDirection::kY>;
}

if (width > 0 && height > 0) {
Expand Down
20 changes: 0 additions & 20 deletions src/opts/SkBlitRow_opts.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#ifndef SkBlitRow_opts_DEFINED
#define SkBlitRow_opts_DEFINED

#include "Sk4px.h"
#include "SkColorData.h"
#include "SkMSAN.h"

Expand All @@ -19,25 +18,6 @@

namespace SK_OPTS_NS {

// Color32 uses the blend_256_round_alt algorithm from tests/BlendTest.cpp.
// It's not quite perfect, but it's never wrong in the interesting edge cases,
// and it's quite a bit faster than blend_perfect.
//
// blend_256_round_alt is our currently blessed algorithm. Please use it or an analogous one.
static inline
void blit_row_color32(SkPMColor* dst, const SkPMColor* src, int count, SkPMColor color) {
unsigned invA = 255 - SkGetPackedA32(color);
invA += invA >> 7;
SkASSERT(invA < 256); // We've should have already handled alpha == 0 externally.

Sk16h colorHighAndRound = Sk4px::DupPMColor(color).widenHi() + Sk16h(128);
Sk16b invA_16x(invA);

Sk4px::MapSrc(count, dst, src, [&](const Sk4px& src4) -> Sk4px {
return (src4 * invA_16x).addNarrowHi(colorHighAndRound);
});
}

#if defined(SK_ARM_HAS_NEON)

// Return a uint8x8_t value, r, computed as r[i] = SkMulDiv255Round(x[i], y[i]), where r[i], x[i],
Expand Down
139 changes: 0 additions & 139 deletions src/opts/SkMorphologyImageFilter_opts.h

This file was deleted.

0 comments on commit d99bd00

Please sign in to comment.