Graduate matrix map-point procs out of SkOpts.
These are implemented generically with Sk4s and don't benefit from anything fancier than vanilla SSE/NEON. This means there's no need to hide this code away in another file or behind a function pointer... it's readable and we have compile-time support for all the instructions it needs. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1872193002 CQ_EXTRA_TRYBOTS=client.skia:Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Release-SKNX_NO_SIMD-Trybot Review URL: https://codereview.chromium.org/1872193002
This commit is contained in:
parent
149b47fec7
commit
567118fbe6
@ -5,13 +5,12 @@
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "SkMatrix.h"
|
||||
#include "SkFloatBits.h"
|
||||
#include "SkMatrix.h"
|
||||
#include "SkNx.h"
|
||||
#include "SkPaint.h"
|
||||
#include "SkRSXform.h"
|
||||
#include "SkString.h"
|
||||
#include "SkNx.h"
|
||||
#include "SkOpts.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
static void normalize_perspective(SkScalar mat[9]) {
|
||||
@ -917,11 +916,62 @@ void SkMatrix::Identity_pts(const SkMatrix& m, SkPoint dst[], const SkPoint src[
|
||||
}
|
||||
|
||||
void SkMatrix::Trans_pts(const SkMatrix& m, SkPoint dst[], const SkPoint src[], int count) {
|
||||
return SkOpts::matrix_translate(m,dst,src,count);
|
||||
SkASSERT(m.getType() <= SkMatrix::kTranslate_Mask);
|
||||
if (count > 0) {
|
||||
SkScalar tx = m.getTranslateX();
|
||||
SkScalar ty = m.getTranslateY();
|
||||
if (count & 1) {
|
||||
dst->fX = src->fX + tx;
|
||||
dst->fY = src->fY + ty;
|
||||
src += 1;
|
||||
dst += 1;
|
||||
}
|
||||
Sk4s trans4(tx, ty, tx, ty);
|
||||
count >>= 1;
|
||||
if (count & 1) {
|
||||
(Sk4s::Load(src) + trans4).store(dst);
|
||||
src += 2;
|
||||
dst += 2;
|
||||
}
|
||||
count >>= 1;
|
||||
for (int i = 0; i < count; ++i) {
|
||||
(Sk4s::Load(src+0) + trans4).store(dst+0);
|
||||
(Sk4s::Load(src+2) + trans4).store(dst+2);
|
||||
src += 4;
|
||||
dst += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SkMatrix::Scale_pts(const SkMatrix& m, SkPoint dst[], const SkPoint src[], int count) {
|
||||
return SkOpts::matrix_scale_translate(m,dst,src,count);
|
||||
SkASSERT(m.getType() <= (SkMatrix::kScale_Mask | SkMatrix::kTranslate_Mask));
|
||||
if (count > 0) {
|
||||
SkScalar tx = m.getTranslateX();
|
||||
SkScalar ty = m.getTranslateY();
|
||||
SkScalar sx = m.getScaleX();
|
||||
SkScalar sy = m.getScaleY();
|
||||
if (count & 1) {
|
||||
dst->fX = src->fX * sx + tx;
|
||||
dst->fY = src->fY * sy + ty;
|
||||
src += 1;
|
||||
dst += 1;
|
||||
}
|
||||
Sk4s trans4(tx, ty, tx, ty);
|
||||
Sk4s scale4(sx, sy, sx, sy);
|
||||
count >>= 1;
|
||||
if (count & 1) {
|
||||
(Sk4s::Load(src) * scale4 + trans4).store(dst);
|
||||
src += 2;
|
||||
dst += 2;
|
||||
}
|
||||
count >>= 1;
|
||||
for (int i = 0; i < count; ++i) {
|
||||
(Sk4s::Load(src+0) * scale4 + trans4).store(dst+0);
|
||||
(Sk4s::Load(src+2) * scale4 + trans4).store(dst+2);
|
||||
src += 4;
|
||||
dst += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SkMatrix::Persp_pts(const SkMatrix& m, SkPoint dst[],
|
||||
@ -953,7 +1003,32 @@ void SkMatrix::Persp_pts(const SkMatrix& m, SkPoint dst[],
|
||||
}
|
||||
|
||||
void SkMatrix::Affine_vpts(const SkMatrix& m, SkPoint dst[], const SkPoint src[], int count) {
|
||||
return SkOpts::matrix_affine(m,dst,src,count);
|
||||
SkASSERT(m.getType() != SkMatrix::kPerspective_Mask);
|
||||
if (count > 0) {
|
||||
SkScalar tx = m.getTranslateX();
|
||||
SkScalar ty = m.getTranslateY();
|
||||
SkScalar sx = m.getScaleX();
|
||||
SkScalar sy = m.getScaleY();
|
||||
SkScalar kx = m.getSkewX();
|
||||
SkScalar ky = m.getSkewY();
|
||||
if (count & 1) {
|
||||
dst->set(src->fX * sx + src->fY * kx + tx,
|
||||
src->fX * ky + src->fY * sy + ty);
|
||||
src += 1;
|
||||
dst += 1;
|
||||
}
|
||||
Sk4s trans4(tx, ty, tx, ty);
|
||||
Sk4s scale4(sx, sy, sx, sy);
|
||||
Sk4s skew4(kx, ky, kx, ky); // applied to swizzle of src4
|
||||
count >>= 1;
|
||||
for (int i = 0; i < count; ++i) {
|
||||
Sk4s src4 = Sk4s::Load(src);
|
||||
Sk4s swz4 = SkNx_shuffle<1,0,3,2>(src4); // y0 x0, y1 x1
|
||||
(src4 * scale4 + swz4 * skew4 + trans4).store(dst);
|
||||
src += 2;
|
||||
dst += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const SkMatrix::MapPtsProc SkMatrix::gMapPtsProcs[] = {
|
||||
|
@ -15,7 +15,6 @@
|
||||
#include "SkBlitRow_opts.h"
|
||||
#include "SkBlurImageFilter_opts.h"
|
||||
#include "SkColorCubeFilter_opts.h"
|
||||
#include "SkMatrix_opts.h"
|
||||
#include "SkMorphologyImageFilter_opts.h"
|
||||
#include "SkSwizzler_opts.h"
|
||||
#include "SkTextureCompressor_opts.h"
|
||||
@ -60,10 +59,6 @@ namespace SkOpts {
|
||||
decltype(blit_row_color32) blit_row_color32 = sk_default::blit_row_color32;
|
||||
decltype(blit_row_s32a_opaque) blit_row_s32a_opaque = sk_default::blit_row_s32a_opaque;
|
||||
|
||||
decltype(matrix_translate) matrix_translate = sk_default::matrix_translate;
|
||||
decltype(matrix_scale_translate) matrix_scale_translate = sk_default::matrix_scale_translate;
|
||||
decltype(matrix_affine) matrix_affine = sk_default::matrix_affine;
|
||||
|
||||
decltype(RGBA_to_BGRA) RGBA_to_BGRA = sk_default::RGBA_to_BGRA;
|
||||
decltype(RGBA_to_rgbA) RGBA_to_rgbA = sk_default::RGBA_to_rgbA;
|
||||
decltype(RGBA_to_bgrA) RGBA_to_bgrA = sk_default::RGBA_to_bgrA;
|
||||
|
@ -8,7 +8,6 @@
|
||||
#ifndef SkOpts_DEFINED
|
||||
#define SkOpts_DEFINED
|
||||
|
||||
#include "SkMatrix.h"
|
||||
#include "SkTextureCompressor.h"
|
||||
#include "SkTypes.h"
|
||||
#include "SkXfermode.h"
|
||||
@ -50,8 +49,6 @@ namespace SkOpts {
|
||||
int,
|
||||
const SkColor*);
|
||||
|
||||
extern SkMatrix::MapPtsProc matrix_translate, matrix_scale_translate, matrix_affine;
|
||||
|
||||
// Swizzle input into some sort of 8888 pixel, {premul,unpremul} x {rgba,bgra}.
|
||||
typedef void (*Swizzle_8888)(uint32_t*, const void*, int);
|
||||
extern Swizzle_8888 RGBA_to_BGRA, // i.e. just swap RB
|
||||
|
@ -1,106 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef SkMatrix_opts_DEFINED
|
||||
#define SkMatrix_opts_DEFINED
|
||||
|
||||
#include "SkMatrix.h"
|
||||
#include "SkNx.h"
|
||||
|
||||
namespace SK_OPTS_NS {
|
||||
|
||||
static void matrix_translate(const SkMatrix& m, SkPoint* dst, const SkPoint* src, int count) {
|
||||
SkASSERT(m.getType() <= SkMatrix::kTranslate_Mask);
|
||||
if (count > 0) {
|
||||
SkScalar tx = m.getTranslateX();
|
||||
SkScalar ty = m.getTranslateY();
|
||||
if (count & 1) {
|
||||
dst->fX = src->fX + tx;
|
||||
dst->fY = src->fY + ty;
|
||||
src += 1;
|
||||
dst += 1;
|
||||
}
|
||||
Sk4s trans4(tx, ty, tx, ty);
|
||||
count >>= 1;
|
||||
if (count & 1) {
|
||||
(Sk4s::Load(src) + trans4).store(dst);
|
||||
src += 2;
|
||||
dst += 2;
|
||||
}
|
||||
count >>= 1;
|
||||
for (int i = 0; i < count; ++i) {
|
||||
(Sk4s::Load(src+0) + trans4).store(dst+0);
|
||||
(Sk4s::Load(src+2) + trans4).store(dst+2);
|
||||
src += 4;
|
||||
dst += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void matrix_scale_translate(const SkMatrix& m, SkPoint* dst, const SkPoint* src, int count) {
|
||||
SkASSERT(m.getType() <= (SkMatrix::kScale_Mask | SkMatrix::kTranslate_Mask));
|
||||
if (count > 0) {
|
||||
SkScalar tx = m.getTranslateX();
|
||||
SkScalar ty = m.getTranslateY();
|
||||
SkScalar sx = m.getScaleX();
|
||||
SkScalar sy = m.getScaleY();
|
||||
if (count & 1) {
|
||||
dst->fX = src->fX * sx + tx;
|
||||
dst->fY = src->fY * sy + ty;
|
||||
src += 1;
|
||||
dst += 1;
|
||||
}
|
||||
Sk4s trans4(tx, ty, tx, ty);
|
||||
Sk4s scale4(sx, sy, sx, sy);
|
||||
count >>= 1;
|
||||
if (count & 1) {
|
||||
(Sk4s::Load(src) * scale4 + trans4).store(dst);
|
||||
src += 2;
|
||||
dst += 2;
|
||||
}
|
||||
count >>= 1;
|
||||
for (int i = 0; i < count; ++i) {
|
||||
(Sk4s::Load(src+0) * scale4 + trans4).store(dst+0);
|
||||
(Sk4s::Load(src+2) * scale4 + trans4).store(dst+2);
|
||||
src += 4;
|
||||
dst += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void matrix_affine(const SkMatrix& m, SkPoint* dst, const SkPoint* src, int count) {
|
||||
SkASSERT(m.getType() != SkMatrix::kPerspective_Mask);
|
||||
if (count > 0) {
|
||||
SkScalar tx = m.getTranslateX();
|
||||
SkScalar ty = m.getTranslateY();
|
||||
SkScalar sx = m.getScaleX();
|
||||
SkScalar sy = m.getScaleY();
|
||||
SkScalar kx = m.getSkewX();
|
||||
SkScalar ky = m.getSkewY();
|
||||
if (count & 1) {
|
||||
dst->set(src->fX * sx + src->fY * kx + tx,
|
||||
src->fX * ky + src->fY * sy + ty);
|
||||
src += 1;
|
||||
dst += 1;
|
||||
}
|
||||
Sk4s trans4(tx, ty, tx, ty);
|
||||
Sk4s scale4(sx, sy, sx, sy);
|
||||
Sk4s skew4(kx, ky, kx, ky); // applied to swizzle of src4
|
||||
count >>= 1;
|
||||
for (int i = 0; i < count; ++i) {
|
||||
Sk4s src4 = Sk4s::Load(src);
|
||||
Sk4s swz4 = SkNx_shuffle<1,0,3,2>(src4); // y0 x0, y1 x1
|
||||
(src4 * scale4 + swz4 * skew4 + trans4).store(dst);
|
||||
src += 2;
|
||||
dst += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace SK_OPTS_NS
|
||||
|
||||
#endif//SkMatrix_opts_DEFINED
|
@ -12,7 +12,6 @@
|
||||
#include "SkBlitRow_opts.h"
|
||||
#include "SkBlurImageFilter_opts.h"
|
||||
#include "SkColorCubeFilter_opts.h"
|
||||
#include "SkMatrix_opts.h"
|
||||
#include "SkMorphologyImageFilter_opts.h"
|
||||
#include "SkSwizzler_opts.h"
|
||||
#include "SkTextureCompressor_opts.h"
|
||||
@ -41,10 +40,6 @@ namespace SkOpts {
|
||||
|
||||
color_cube_filter_span = sk_neon::color_cube_filter_span;
|
||||
|
||||
matrix_translate = sk_neon::matrix_translate;
|
||||
matrix_scale_translate = sk_neon::matrix_scale_translate;
|
||||
matrix_affine = sk_neon::matrix_affine;
|
||||
|
||||
RGBA_to_BGRA = sk_neon::RGBA_to_BGRA;
|
||||
RGBA_to_rgbA = sk_neon::RGBA_to_rgbA;
|
||||
RGBA_to_bgrA = sk_neon::RGBA_to_bgrA;
|
||||
|
Loading…
Reference in New Issue
Block a user