Fast path translate() in SkCanvas and SkLiteDL.
This adds didTranslate() so that SkLiteDL (and other canvas recorders) can record the translate rather than the full concat. It also adds a case to SkMatrix::preTranslate() to fast path translate x translate -> translate (i.e. +=). BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2255283002 Review-Url: https://codereview.chromium.org/2255283002
This commit is contained in:
parent
abe795e4db
commit
5fa47f4fd1
@ -1352,6 +1352,9 @@ protected:
|
||||
virtual void didRestore() {}
|
||||
virtual void didConcat(const SkMatrix&) {}
|
||||
virtual void didSetMatrix(const SkMatrix&) {}
|
||||
virtual void didTranslate(SkScalar dx, SkScalar dy) {
|
||||
this->didConcat(SkMatrix::MakeTrans(dx, dy));
|
||||
}
|
||||
|
||||
#ifdef SK_EXPERIMENTAL_SHADOWING
|
||||
virtual void didTranslateZ(SkScalar) {}
|
||||
|
@ -1444,9 +1444,14 @@ void SkCanvas::internalDrawDevice(SkBaseDevice* srcDev, int x, int y, const SkPa
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void SkCanvas::translate(SkScalar dx, SkScalar dy) {
|
||||
SkMatrix m;
|
||||
m.setTranslate(dx, dy);
|
||||
this->concat(m);
|
||||
this->checkForDeferredSave();
|
||||
fDeviceCMDirty = true;
|
||||
fMCRec->fMatrix.preTranslate(dx,dy);
|
||||
|
||||
// Translate shouldn't affect the is-scale-translateness of the matrix.
|
||||
SkASSERT(fIsScaleTranslate == fMCRec->fMatrix.isScaleTranslate());
|
||||
|
||||
this->didTranslate(dx,dy);
|
||||
}
|
||||
|
||||
void SkCanvas::scale(SkScalar sx, SkScalar sy) {
|
||||
|
@ -52,7 +52,7 @@ static void make_threadsafe(SkPath* path, SkMatrix* matrix) {
|
||||
namespace {
|
||||
#define TYPES(M) \
|
||||
M(Save) M(Restore) M(SaveLayer) \
|
||||
M(Concat) M(SetMatrix) M(TranslateZ) \
|
||||
M(Concat) M(SetMatrix) M(Translate) M(TranslateZ) \
|
||||
M(ClipPath) M(ClipRect) M(ClipRRect) M(ClipRegion) \
|
||||
M(DrawPaint) M(DrawPath) M(DrawRect) M(DrawOval) M(DrawRRect) M(DrawDRRect) \
|
||||
M(DrawAnnotation) M(DrawDrawable) M(DrawPicture) M(DrawShadowedPicture) \
|
||||
@ -115,6 +115,14 @@ namespace {
|
||||
}
|
||||
void makeThreadsafe() { make_threadsafe(nullptr, &matrix); }
|
||||
};
|
||||
struct Translate final : Op {
|
||||
static const auto kType = Type::Translate;
|
||||
Translate(SkScalar dx, SkScalar dy) : dx(dx), dy(dy) {}
|
||||
SkScalar dx,dy;
|
||||
void draw(SkCanvas* c, const SkMatrix&) {
|
||||
c->translate(dx, dy);
|
||||
}
|
||||
};
|
||||
struct TranslateZ final : Op {
|
||||
static const auto kType = Type::TranslateZ;
|
||||
TranslateZ(SkScalar dz) : dz(dz) {}
|
||||
@ -539,8 +547,9 @@ void SkLiteDL::saveLayer(const SkRect* bounds, const SkPaint* paint,
|
||||
this->push<SaveLayer>(0, bounds, paint, backdrop, flags);
|
||||
}
|
||||
|
||||
void SkLiteDL:: concat(const SkMatrix& matrix) { this->push <Concat>(0, matrix); }
|
||||
void SkLiteDL::setMatrix(const SkMatrix& matrix) { this->push<SetMatrix>(0, matrix); }
|
||||
void SkLiteDL:: concat(const SkMatrix& matrix) { this->push <Concat>(0, matrix); }
|
||||
void SkLiteDL::setMatrix(const SkMatrix& matrix) { this->push<SetMatrix>(0, matrix); }
|
||||
void SkLiteDL::translate(SkScalar dx, SkScalar dy) { this->push<Translate>(0, dx, dy); }
|
||||
void SkLiteDL::translateZ(SkScalar dz) { this->push<TranslateZ>(0, dz); }
|
||||
|
||||
void SkLiteDL::clipPath(const SkPath& path, SkRegion::Op op, bool aa) {
|
||||
|
@ -29,6 +29,7 @@ public:
|
||||
|
||||
void concat (const SkMatrix&);
|
||||
void setMatrix (const SkMatrix&);
|
||||
void translate(SkScalar, SkScalar);
|
||||
void translateZ(SkScalar);
|
||||
|
||||
void clipPath (const SkPath&, SkRegion::Op, bool aa);
|
||||
|
@ -29,8 +29,9 @@ SkCanvas::SaveLayerStrategy SkLiteRecorder::getSaveLayerStrategy(const SaveLayer
|
||||
}
|
||||
void SkLiteRecorder::willRestore() { fDL->restore(); }
|
||||
|
||||
void SkLiteRecorder::didConcat (const SkMatrix& matrix) { fDL-> concat(matrix); }
|
||||
void SkLiteRecorder::didSetMatrix(const SkMatrix& matrix) { fDL->setMatrix(matrix); }
|
||||
void SkLiteRecorder::didConcat (const SkMatrix& matrix) { fDL-> concat(matrix); }
|
||||
void SkLiteRecorder::didSetMatrix(const SkMatrix& matrix) { fDL->setMatrix(matrix); }
|
||||
void SkLiteRecorder::didTranslate(SkScalar dx, SkScalar dy) { fDL->translate(dx, dy); }
|
||||
|
||||
void SkLiteRecorder::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle style) {
|
||||
fDL->clipRect(rect, op, style==kSoft_ClipEdgeStyle);
|
||||
|
@ -25,6 +25,7 @@ public:
|
||||
|
||||
void didConcat(const SkMatrix&) override;
|
||||
void didSetMatrix(const SkMatrix&) override;
|
||||
void didTranslate(SkScalar, SkScalar) override;
|
||||
|
||||
void onClipRect (const SkRect&, SkRegion::Op, ClipEdgeStyle) override;
|
||||
void onClipRRect (const SkRRect&, SkRegion::Op, ClipEdgeStyle) override;
|
||||
|
@ -290,7 +290,12 @@ void SkMatrix::preTranslate(SkScalar dx, SkScalar dy) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->hasPerspective()) {
|
||||
if (fTypeMask <= kTranslate_Mask) {
|
||||
fMat[kMTransX] += dx;
|
||||
fMat[kMTransY] += dy;
|
||||
this->setTypeMask((fMat[kMTransX] != 0 || fMat[kMTransY] != 0) ? kTranslate_Mask
|
||||
: kIdentity_Mask);
|
||||
} else if (this->hasPerspective()) {
|
||||
SkMatrix m;
|
||||
m.setTranslate(dx, dy);
|
||||
this->preConcat(m);
|
||||
@ -1100,7 +1105,7 @@ void SkMatrix::mapVectors(SkPoint dst[], const SkPoint src[], int count) const {
|
||||
void SkMatrix::mapRectScaleTranslate(SkRect* dst, const SkRect& src) const {
|
||||
SkASSERT(dst);
|
||||
SkASSERT(this->isScaleTranslate());
|
||||
|
||||
|
||||
SkScalar sx = fMat[kMScaleX];
|
||||
SkScalar sy = fMat[kMScaleY];
|
||||
SkScalar tx = fMat[kMTransX];
|
||||
|
Loading…
Reference in New Issue
Block a user