change matrix_2x3 to row-major

Change-Id: Id25b3875f54f359bac90b6d3a7695287fc108b64
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/456467
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Herb Derby <herb@google.com>
This commit is contained in:
Herb Derby 2021-10-06 11:00:39 -04:00 committed by SkCQ
parent 47da0ac577
commit e023608611
4 changed files with 26 additions and 30 deletions

View File

@ -157,11 +157,11 @@ void SkRasterPipeline::append_matrix(SkArenaAlloc* alloc, const SkMatrix& matrix
this->append(SkRasterPipeline::matrix_scale_translate, scaleTrans);
} else {
float* storage = alloc->makeArrayDefault<float>(9);
if (matrix.asAffine(storage)) {
matrix.get9(storage);
if (!matrix.hasPerspective()) {
// note: asAffine and the 2x3 stage really only need 6 entries
this->append(SkRasterPipeline::matrix_2x3, storage);
} else {
matrix.get9(storage);
this->append(SkRasterPipeline::matrix_perspective, storage);
}
}

View File

@ -2373,8 +2373,8 @@ STAGE(matrix_scale_translate, const float* m) {
g = mad(g,m[1], m[3]);
}
STAGE(matrix_2x3, const float* m) {
auto R = mad(r,m[0], mad(g,m[2], m[4])),
G = mad(r,m[1], mad(g,m[3], m[5]));
auto R = mad(r,m[0], mad(g,m[1], m[2])),
G = mad(r,m[3], mad(g,m[4], m[5]));
r = R;
g = G;
}
@ -3265,8 +3265,8 @@ STAGE_GG(matrix_scale_translate, const float* m) {
y = mad(y,m[1], m[3]);
}
STAGE_GG(matrix_2x3, const float* m) {
auto X = mad(x,m[0], mad(y,m[2], m[4])),
Y = mad(x,m[1], mad(y,m[3], m[5]));
auto X = mad(x,m[0], mad(y,m[1], m[2])),
Y = mad(x,m[3], mad(y,m[4], m[5]));
x = X;
y = Y;
}

View File

@ -354,7 +354,8 @@ public:
SkRasterPipeline_DecalTileCtx* fDecal;
#endif
void append_matrix_stage(SkRasterPipeline* p) {
void append_matrix_stage(const SkMatrix& matrix, SkRasterPipeline* p) {
matrix.get9(fMatrixStorage);
if (fUsePersp) {
p->append(SkRasterPipeline::matrix_perspective, fMatrixStorage);
} else {
@ -363,24 +364,15 @@ public:
}
bool update(const SkMatrix& ctm) override {
SkMatrix matrix;
// TODO: We may have lost the original local matrix?
if (fShader->computeTotalInverse(ctm, nullptr, &matrix)) {
if (fUsePersp) {
matrix.get9(fMatrixStorage);
} else {
// if we get here, matrix should be affine. If it isn't, then defensively we
// won't draw (by returning false), but we should work to never let this
// happen (i.e. better preflight by the caller to know ahead of time that we
// may encounter perspective, either in the CTM, or in the localM).
//
// See https://bugs.chromium.org/p/skia/issues/detail?id=10004
//
if (!matrix.asAffine(fMatrixStorage)) {
SkASSERT(false);
return false;
}
}
if (SkMatrix matrix; fShader->computeTotalInverse(ctm, nullptr, &matrix)) {
#if defined(SK_DEBUG)
SkMatrix old;
old.set9(fMatrixStorage);
SkASSERT(old.hasPerspective() == matrix.hasPerspective());
#endif
matrix.get9(fMatrixStorage);
return true;
}
return false;
@ -453,7 +445,7 @@ bool SkImageShader::doStages(const SkStageRec& rec, SkImageStageUpdater* updater
p->append(SkRasterPipeline::seed_shader);
if (updater) {
updater->append_matrix_stage(p);
updater->append_matrix_stage(matrix, p);
} else {
if (!sampling.useCubic) {
// TODO: can tweak_sampling sometimes for cubic too when B=0

View File

@ -47,11 +47,15 @@ skvm::Coord SkTransformShader::applyMatrix(
}
bool SkTransformShader::update(const SkMatrix& ctm) const {
SkMatrix matrix;
if (this->computeTotalInverse(ctm, nullptr, &matrix)) {
for (int i = 0; i < 9; ++i) {
fMatrixStorage[i] = matrix[i];
}
if (SkMatrix matrix; this->computeTotalInverse(ctm, nullptr, &matrix)) {
#if defined(SK_DEBUG)
SkMatrix old;
old.set9(fMatrixStorage);
SkASSERT(old.hasPerspective() == matrix.hasPerspective());
#endif
matrix.get9(fMatrixStorage);
return true;
}
return false;