Revert "Reland "Revert "allow clients to opt into new didTranslate/didScale"""

This reverts commit f66bba6018.

Reason for revert: sheriff thinks it may be the bot, so landing

Original change's description:
> Reland "Revert "allow clients to opt into new didTranslate/didScale""
> 
> This reverts commit d7ce7ac8d1.
> 
> Reason for revert: breaks Test-Debian10-GCC-GCE-CPU-AVX2-x86-Debug-All-Docker
> 
> Original change's description:
> > Revert "Revert "allow clients to opt into new didTranslate/didScale""
> > 
> > This reverts commit 4a46758db8.
> > 
> > Add guard to Flutter
> > 
> > Change-Id: Ief0e5cb36af13c8f00a36a617d0384622012d644
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/263937
> > Reviewed-by: Mike Reed <reed@google.com>
> > Commit-Queue: Mike Reed <reed@google.com>
> 
> TBR=reed@google.com
> 
> Change-Id: I3291c4dfe18d6e751e61f55ed9b22a01f0c8ad72
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/263860
> Reviewed-by: Mike Reed <reed@google.com>
> Commit-Queue: Mike Reed <reed@google.com>

TBR=reed@google.com

Change-Id: I3111a034291c2320e5ff33f8c2072354f836440f
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/263939
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2020-01-13 14:40:56 +00:00 committed by Skia Commit-Bot
parent 70e9301c26
commit 9403c3897f
7 changed files with 35 additions and 5 deletions

View File

@ -13,6 +13,7 @@ flutter_defines = [
"SK_DISABLE_AAA",
# API staging
"SK_SUPPORT_LEGACY_CANVAS_MATRIX_VIRTUALS",
# Flutter doesn't deserialize anything.
"SK_DISABLE_READBUFFER",

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();