allow clients to opt into new didTranslate/didScale

Before
    148.97  	canvas_matrix_4x4	8888
    139.96  	canvas_matrix_3x3	8888
    139.81  	canvas_matrix_2x3	8888
    183.13  	canvas_matrix_scale	8888
    153.72  	canvas_matrix_trans	8888

After
    ...
    114.68  	canvas_matrix_scale	8888
    112.96  	canvas_matrix_trans	8888

Change-Id: I79d20ea6ab6aa9609143c7abf4acaa8ca08dd58f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/263818
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2020-01-11 20:01:39 -05:00 committed by Skia Commit-Bot
parent 69ace2a0ad
commit cb6b9e3c35
6 changed files with 34 additions and 5 deletions

View File

@ -2554,15 +2554,18 @@ protected:
virtual bool onDoSaveBehind(const SkRect*) { return true; }
virtual void willRestore() {}
virtual void didRestore() {}
virtual void didConcat44(const SkScalar[]) {} // colMajor
virtual void didConcat(const SkMatrix& ) {}
virtual void didSetMatrix(const SkMatrix& ) {}
#ifdef SK_SUPPORT_LEGACY_CANVAS_MATRIX_VIRTUALS
virtual void didTranslate(SkScalar dx, SkScalar dy) {
// TODO: update all subclasses to override this, so we can remove default impl.
this->didConcat(SkMatrix::MakeTrans(dx, dy));
}
// just pass an array for now, until we decide on the "public" form for the matrix
virtual void didConcat44(const SkScalar[]) {}
// This is not called by SkCanvas yet. Waiting for subclasses to override it first.
#else
virtual void didTranslate(SkScalar, SkScalar) {}
#endif
// Called if SK_SUPPORT_LEGACY_CANVAS_MATRIX_VIRTUALS is not defined
virtual void didScale(SkScalar, SkScalar) {}
// NOTE: If you are adding a new onDraw virtual to SkCanvas, PLEASE add an override to

View File

@ -157,6 +157,7 @@ public:
}
SkM44& preTranslate(SkScalar x, SkScalar y);
SkM44& preScale(SkScalar x, SkScalar y);
SkM44& preConcat(const SkMatrix&);
const SkScalar* asColMajor() const { return fMat; }

View File

@ -1439,9 +1439,24 @@ void SkCanvas::translate(SkScalar dx, SkScalar dy) {
}
void SkCanvas::scale(SkScalar sx, SkScalar sy) {
#ifdef SK_SUPPORT_LEGACY_CANVAS_MATRIX_VIRTUALS
SkMatrix m;
m.setScale(sx, sy);
this->concat(m);
#else
if (sx != 1 || sy != 1) {
this->checkForDeferredSave();
fMCRec->fMatrix.preScale(sx, sy);
// shouldn't need to do this (theoretically), as the state shouldn't have changed,
// but pre-scaling by a non-finite does change it, so we have to recompute.
fIsScaleTranslate = fMCRec->fMatrix.isScaleTranslate();
FOR_EACH_TOP_DEVICE(device->setGlobalCTM(fMCRec->fMatrix));
this->didScale(sx, sy);
}
#endif
}
void SkCanvas::rotate(SkScalar degrees) {

View File

@ -18,6 +18,7 @@ public:
void reset() { fM.setIdentity(); }
void preTranslate(SkScalar x, SkScalar y) { fM.preTranslate(x, y); }
void preScale(SkScalar x, SkScalar y) { fM.preScale(x, y); }
void preConcat(const SkMatrix& m) { fM.preConcat(m); }
void preConcat44(const SkScalar m[]) { fM.setConcat(fM, m); }

View File

@ -97,6 +97,15 @@ SkM44& SkM44::preTranslate(SkScalar x, SkScalar y) {
return *this;
}
SkM44& SkM44::preScale(SkScalar x, SkScalar y) {
sk4f c0 = sk4f::Load(fMat + 0);
sk4f c1 = sk4f::Load(fMat + 4);
(c0 * x).store(fMat + 0);
(c1 * y).store(fMat + 4);
return *this;
}
///////////////////////////////////////////////////////////////////////////////
/** We always perform the calculation in doubles, to avoid prematurely losing

View File

@ -46,7 +46,7 @@ DEF_TEST(RecordDraw_LazySaves, r) {
assert_type<SkRecords::DrawPaint>(r, record, 0);
assert_type<SkRecords::Save> (r, record, 1);
assert_type<SkRecords::Concat> (r, record, 2);
assert_type<SkRecords::Scale> (r, record, 2);
assert_type<SkRecords::Restore> (r, record, 3);
recorder.save();