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); this->append(SkRasterPipeline::matrix_scale_translate, scaleTrans);
} else { } else {
float* storage = alloc->makeArrayDefault<float>(9); 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 // note: asAffine and the 2x3 stage really only need 6 entries
this->append(SkRasterPipeline::matrix_2x3, storage); this->append(SkRasterPipeline::matrix_2x3, storage);
} else { } else {
matrix.get9(storage);
this->append(SkRasterPipeline::matrix_perspective, 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]); g = mad(g,m[1], m[3]);
} }
STAGE(matrix_2x3, const float* m) { STAGE(matrix_2x3, const float* m) {
auto R = mad(r,m[0], mad(g,m[2], m[4])), auto R = mad(r,m[0], mad(g,m[1], m[2])),
G = mad(r,m[1], mad(g,m[3], m[5])); G = mad(r,m[3], mad(g,m[4], m[5]));
r = R; r = R;
g = G; g = G;
} }
@ -3265,8 +3265,8 @@ STAGE_GG(matrix_scale_translate, const float* m) {
y = mad(y,m[1], m[3]); y = mad(y,m[1], m[3]);
} }
STAGE_GG(matrix_2x3, const float* m) { STAGE_GG(matrix_2x3, const float* m) {
auto X = mad(x,m[0], mad(y,m[2], m[4])), auto X = mad(x,m[0], mad(y,m[1], m[2])),
Y = mad(x,m[1], mad(y,m[3], m[5])); Y = mad(x,m[3], mad(y,m[4], m[5]));
x = X; x = X;
y = Y; y = Y;
} }

View File

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