Rename SkDevice::ctm() to localToDevice()
This helps differentiate the SkCanvas' total CTM
(canvas transform matrix), from the device-specific transform matrix
that maps draws from local to device space.
Bug: 9545
Change-Id: I67f40d9b1bc92377bf0520fbc9245f1058e179e6
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/249424
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: Mike Reed <reed@google.com>
diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp
index 9bf45a0..285ff54 100644
--- a/src/core/SkBitmapDevice.cpp
+++ b/src/core/SkBitmapDevice.cpp
@@ -91,7 +91,7 @@
// fSrcBounds = devBounds.roundOut();
// The problem being that the promotion of clipR to SkRect was unreliable
//
- fSrcBounds = dev->ctm().mapRect(*bounds).roundOut();
+ fSrcBounds = dev->localToDevice().mapRect(*bounds).roundOut();
if (fSrcBounds.intersect(clipR)) {
// Check again, now that we have computed srcbounds.
fNeedsTiling = fSrcBounds.right() > kMaxDim || fSrcBounds.bottom() > kMaxDim;
@@ -113,7 +113,7 @@
} else {
// don't reference fSrcBounds, as it may not have been set
fDraw.fDst = fRootPixmap;
- fDraw.fMatrix = &dev->ctm();
+ fDraw.fMatrix = &dev->localToDevice();
fDraw.fRC = &dev->fRCStack.rc();
fOrigin.set(0, 0);
@@ -165,7 +165,7 @@
SkASSERT_RELEASE(success);
// now don't use bounds, since fDst has the clipped dimensions.
- fTileMatrix = fDevice->ctm();
+ fTileMatrix = fDevice->localToDevice();
fTileMatrix.postTranslate(SkIntToScalar(-fOrigin.x()), SkIntToScalar(-fOrigin.y()));
fDevice->fRCStack.rc().translate(-fOrigin.x(), -fOrigin.y(), &fTileRC);
fTileRC.op(SkIRect::MakeWH(fDraw.fDst.width(), fDraw.fDst.height()),
@@ -192,7 +192,7 @@
// NoDrawDevice uses us (why?) so we have to catch this case w/ no pixels
fDst.reset(dev->imageInfo(), nullptr, 0);
}
- fMatrix = &dev->ctm();
+ fMatrix = &dev->localToDevice();
fRC = &dev->fRCStack.rc();
fCoverage = dev->accessCoverage();
}
@@ -446,7 +446,7 @@
}
matrix.setRectToRect(tmpSrc, dst, SkMatrix::kFill_ScaleToFit);
- LogDrawScaleFactor(this->ctm(), matrix, paint.getFilterQuality());
+ LogDrawScaleFactor(this->localToDevice(), matrix, paint.getFilterQuality());
const SkRect* dstPtr = &dst;
const SkBitmap* bitmapPtr = &bitmap;
@@ -565,7 +565,8 @@
// todo: can we unify with similar adjustment in SkGpuDevice?
SkTCopyOnFirstWrite<SkPaint> paint(origPaint);
if (paint->getMaskFilter()) {
- paint.writable()->setMaskFilter(paint->getMaskFilter()->makeWithMatrix(this->ctm()));
+ paint.writable()->setMaskFilter(
+ paint->getMaskFilter()->makeWithMatrix(this->localToDevice()));
}
// hack to test coverage
@@ -603,20 +604,20 @@
public:
SkAutoDeviceClipRestore(SkBaseDevice* device, const SkIRect& clip)
: fDevice(device)
- , fPrevCTM(device->ctm()) {
+ , fPrevLocalToDevice(device->localToDevice()) {
fDevice->save();
- fDevice->setCTM(SkMatrix::I());
+ fDevice->setLocalToDevice(SkMatrix::I());
fDevice->clipRect(SkRect::Make(clip), SkClipOp::kIntersect, false);
- fDevice->setCTM(fPrevCTM);
+ fDevice->setLocalToDevice(fPrevLocalToDevice);
}
~SkAutoDeviceClipRestore() {
- fDevice->restore(fPrevCTM);
+ fDevice->restoreLocal(fPrevLocalToDevice);
}
private:
SkBaseDevice* fDevice;
- const SkMatrix fPrevCTM;
+ const SkMatrix fPrevLocalToDevice;
};
} // anonymous ns
@@ -631,7 +632,7 @@
if (SkImageFilter* filter = paint->getImageFilter()) {
SkIPoint offset = SkIPoint::Make(0, 0);
const SkMatrix matrix = SkMatrix::Concat(
- SkMatrix::MakeTrans(SkIntToScalar(-x), SkIntToScalar(-y)), this->ctm());
+ SkMatrix::MakeTrans(SkIntToScalar(-x), SkIntToScalar(-y)), this->localToDevice());
const SkIRect clipBounds = fRCStack.rc().getBounds().makeOffset(-x, -y);
sk_sp<SkImageFilterCache> cache(this->getImageFilterCache());
SkImageFilter_Base::Context ctx(matrix, clipBounds, cache.get(), fBitmap.colorType(),
@@ -649,7 +650,8 @@
}
if (paint->getMaskFilter()) {
- paint.writable()->setMaskFilter(paint->getMaskFilter()->makeWithMatrix(this->ctm()));
+ paint.writable()->setMaskFilter(
+ paint->getMaskFilter()->makeWithMatrix(this->localToDevice()));
}
if (!clipImage) {
@@ -666,7 +668,7 @@
return;
}
- const SkMatrix totalMatrix = SkMatrix::Concat(this->ctm(), clipMatrix);
+ const SkMatrix totalMatrix = SkMatrix::Concat(this->localToDevice(), clipMatrix);
SkRect clipBounds;
totalMatrix.mapRect(&clipBounds, SkRect::Make(clipImage->bounds()));
const SkIRect srcBounds = srcImage->bounds().makeOffset(x, y);
@@ -708,7 +710,7 @@
shaderMatrix = SkMatrix::MakeTrans(x - maskBounds.x(), y - maskBounds.y());
}
- SkAutoDeviceCTMRestore adctmr(this, maskMatrix);
+ SkAutoDeviceTransformRestore adr(this, maskMatrix);
paint.writable()->setShader(srcImage->makeShader(&shaderMatrix));
this->drawImageRect(mask.get(), nullptr,
SkRect::MakeXYWH(maskBounds.x(), maskBounds.y(),
@@ -756,15 +758,15 @@
}
void SkBitmapDevice::onClipRect(const SkRect& rect, SkClipOp op, bool aa) {
- fRCStack.clipRect(this->ctm(), rect, op, aa);
+ fRCStack.clipRect(this->localToDevice(), rect, op, aa);
}
void SkBitmapDevice::onClipRRect(const SkRRect& rrect, SkClipOp op, bool aa) {
- fRCStack.clipRRect(this->ctm(), rrect, op, aa);
+ fRCStack.clipRRect(this->localToDevice(), rrect, op, aa);
}
void SkBitmapDevice::onClipPath(const SkPath& path, SkClipOp op, bool aa) {
- fRCStack.clipPath(this->ctm(), path, op, aa);
+ fRCStack.clipPath(this->localToDevice(), path, op, aa);
}
void SkBitmapDevice::onClipRegion(const SkRegion& rgn, SkClipOp op) {
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index b31ee31..90335e8 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -1028,11 +1028,11 @@
// Manually setting the device's CTM requires accounting for the device's origin.
// TODO (michaelludwig) - This could be simpler if the dst device had its origin configured
- // before filtering the backdrop device, and if SkAutoDeviceCTMRestore had a way to accept
+ // before filtering the backdrop device, and if SkAutoDeviceTransformRestore had a way to accept
// a global CTM instead of a device CTM.
SkMatrix dstCTM = toRoot;
dstCTM.postTranslate(-dstOrigin.x(), -dstOrigin.y());
- SkAutoDeviceCTMRestore acr(dst, dstCTM);
+ SkAutoDeviceTransformRestore adr(dst, dstCTM);
// And because devices don't have a special-image draw function that supports arbitrary
// matrices, we are abusing the asImage() functionality here...
@@ -2434,7 +2434,7 @@
const SkPaint& pnt = draw.paint();
if (special) {
SkPoint pt;
- iter.fDevice->ctm().mapXY(x, y, &pt);
+ iter.fDevice->localToDevice().mapXY(x, y, &pt);
iter.fDevice->drawSpecial(special.get(),
SkScalarRoundToInt(pt.fX),
SkScalarRoundToInt(pt.fY), pnt,
@@ -2512,7 +2512,7 @@
const SkPaint& pnt = draw.paint();
if (special) {
SkPoint pt;
- iter.fDevice->ctm().mapXY(x, y, &pt);
+ iter.fDevice->localToDevice().mapXY(x, y, &pt);
iter.fDevice->drawSpecial(special.get(),
SkScalarRoundToInt(pt.fX),
SkScalarRoundToInt(pt.fY), pnt,
@@ -3003,7 +3003,7 @@
}
const SkMatrix& SkCanvas::LayerIter::matrix() const {
- return fImpl->fDevice->ctm();
+ return fImpl->fDevice->localToDevice();
}
const SkPaint& SkCanvas::LayerIter::paint() const {
diff --git a/src/core/SkClipStackDevice.cpp b/src/core/SkClipStackDevice.cpp
index 72bfd1b..6734756 100644
--- a/src/core/SkClipStackDevice.cpp
+++ b/src/core/SkClipStackDevice.cpp
@@ -28,15 +28,15 @@
}
void SkClipStackDevice::onClipRect(const SkRect& rect, SkClipOp op, bool aa) {
- fClipStack.clipRect(rect, this->ctm(), op, aa);
+ fClipStack.clipRect(rect, this->localToDevice(), op, aa);
}
void SkClipStackDevice::onClipRRect(const SkRRect& rrect, SkClipOp op, bool aa) {
- fClipStack.clipRRect(rrect, this->ctm(), op, aa);
+ fClipStack.clipRRect(rrect, this->localToDevice(), op, aa);
}
void SkClipStackDevice::onClipPath(const SkPath& path, SkClipOp op, bool aa) {
- fClipStack.clipPath(path, this->ctm(), op, aa);
+ fClipStack.clipPath(path, this->localToDevice(), op, aa);
}
void SkClipStackDevice::onClipRegion(const SkRegion& rgn, SkClipOp op) {
diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp
index 094f273..b1d64b7 100644
--- a/src/core/SkDevice.cpp
+++ b/src/core/SkDevice.cpp
@@ -37,19 +37,19 @@
, fSurfaceProps(surfaceProps)
{
fOrigin = {0, 0};
- fCTM.reset();
+ fLocalToDevice.reset();
}
void SkBaseDevice::setOrigin(const SkMatrix& globalCTM, int x, int y) {
fOrigin.set(x, y);
- fCTM = globalCTM;
- fCTM.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y));
+ fLocalToDevice = globalCTM;
+ fLocalToDevice.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y));
}
void SkBaseDevice::setGlobalCTM(const SkMatrix& ctm) {
- fCTM = ctm;
+ fLocalToDevice = ctm;
if (fOrigin.fX | fOrigin.fY) {
- fCTM.postTranslate(-SkIntToScalar(fOrigin.fX), -SkIntToScalar(fOrigin.fY));
+ fLocalToDevice.postTranslate(-SkIntToScalar(fOrigin.fX), -SkIntToScalar(fOrigin.fY));
}
}
@@ -83,12 +83,12 @@
}
void SkBaseDevice::drawRegion(const SkRegion& region, const SkPaint& paint) {
- const SkMatrix& ctm = this->ctm();
- bool isNonTranslate = ctm.getType() & ~(SkMatrix::kTranslate_Mask);
+ const SkMatrix& localToDevice = this->localToDevice();
+ bool isNonTranslate = localToDevice.getType() & ~(SkMatrix::kTranslate_Mask);
bool complexPaint = paint.getStyle() != SkPaint::kFill_Style || paint.getMaskFilter() ||
paint.getPathEffect();
- bool antiAlias = paint.isAntiAlias() && (!is_int(ctm.getTranslateX()) ||
- !is_int(ctm.getTranslateY()));
+ bool antiAlias = paint.isAntiAlias() && (!is_int(localToDevice.getTranslateX()) ||
+ !is_int(localToDevice.getTranslateY()));
if (isNonTranslate || complexPaint || antiAlias) {
SkPath path;
region.getBoundaryPath(&path);
@@ -125,7 +125,7 @@
void SkBaseDevice::drawPatch(const SkPoint cubics[12], const SkColor colors[4],
const SkPoint texCoords[4], SkBlendMode bmode, const SkPaint& paint) {
- SkISize lod = SkPatchUtils::GetLevelOfDetail(cubics, &this->ctm());
+ SkISize lod = SkPatchUtils::GetLevelOfDetail(cubics, &this->localToDevice());
auto vertices = SkPatchUtils::MakeVertices(cubics, colors, texCoords, lod.width(), lod.height(),
this->imageInfo().colorSpace());
if (vertices) {
@@ -270,7 +270,7 @@
SkASSERT(!paint.getPathEffect());
SkPaint entryPaint = paint;
- const SkMatrix baseCTM = this->ctm();
+ const SkMatrix baseLocalToDevice = this->localToDevice();
int clipIndex = 0;
for (int i = 0; i < count; ++i) {
// TODO: Handle per-edge AA. Right now this mirrors the SkiaRenderer component of Chrome
@@ -283,8 +283,8 @@
SkASSERT(images[i].fMatrixIndex < 0 || preViewMatrices);
if (images[i].fMatrixIndex >= 0) {
this->save();
- this->setGlobalCTM(SkMatrix::Concat(
- baseCTM, preViewMatrices[images[i].fMatrixIndex]));
+ this->setLocalToDevice(SkMatrix::Concat(
+ baseLocalToDevice, preViewMatrices[images[i].fMatrixIndex]));
needsRestore = true;
}
@@ -303,7 +303,7 @@
this->drawImageRect(images[i].fImage.get(), &images[i].fSrcRect, images[i].fDstRect,
entryPaint, constraint);
if (needsRestore) {
- this->restore(baseCTM);
+ this->restoreLocal(baseLocalToDevice);
}
}
}
@@ -366,8 +366,8 @@
void SkBaseDevice::drawGlyphRunRSXform(const SkFont& font, const SkGlyphID glyphs[],
const SkRSXform xform[], int count, SkPoint origin,
const SkPaint& paint) {
- const SkMatrix originalCTM = this->ctm();
- if (!originalCTM.isFinite() || !SkScalarIsFinite(font.getSize()) ||
+ const SkMatrix originalLocalToDevice = this->localToDevice();
+ if (!originalLocalToDevice.isFinite() || !SkScalarIsFinite(font.getSize()) ||
!SkScalarIsFinite(font.getScaleX()) ||
!SkScalarIsFinite(font.getSkewX())) {
return;
@@ -387,8 +387,8 @@
glyphID = glyphs[i];
// now "glyphRun" is pointing at the current glyphID
- SkMatrix ctm;
- ctm.setRSXform(xform[i]).postTranslate(origin.fX, origin.fY);
+ SkMatrix glyphToDevice;
+ glyphToDevice.setRSXform(xform[i]).postTranslate(origin.fX, origin.fY);
// We want to rotate each glyph by the rsxform, but we don't want to rotate "space"
// (i.e. the shader that cares about the ctm) so we have to undo our little ctm trick
@@ -397,19 +397,19 @@
auto shader = transformingPaint.getShader();
if (shader) {
SkMatrix inverse;
- if (ctm.invert(&inverse)) {
+ if (glyphToDevice.invert(&inverse)) {
transformingPaint.setShader(shader->makeWithLocalMatrix(inverse));
} else {
transformingPaint.setShader(nullptr); // can't handle this xform
}
}
- ctm.setConcat(originalCTM, ctm);
- this->setCTM(ctm);
+ glyphToDevice.postConcat(originalLocalToDevice);
+ this->setLocalToDevice(glyphToDevice);
this->drawGlyphRunList(SkGlyphRunList{glyphRun, transformingPaint});
}
- this->setCTM(originalCTM);
+ this->setLocalToDevice(originalLocalToDevice);
}
//////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/core/SkDevice.h b/src/core/SkDevice.h
index ce2629f..c03e9eb 100644
--- a/src/core/SkDevice.h
+++ b/src/core/SkDevice.h
@@ -103,6 +103,10 @@
this->onRestore();
this->setGlobalCTM(ctm);
}
+ void restoreLocal(const SkMatrix& localToDevice) {
+ this->onRestore();
+ this->setLocalToDevice(localToDevice);
+ }
void clipRect(const SkRect& rect, SkClipOp op, bool aa) {
this->onClipRect(rect, op, aa);
}
@@ -120,9 +124,9 @@
}
bool clipIsWideOpen() const;
- const SkMatrix& ctm() const { return fCTM; }
- void setCTM(const SkMatrix& ctm) {
- fCTM = ctm;
+ const SkMatrix& localToDevice() const { return fLocalToDevice; }
+ void setLocalToDevice(const SkMatrix& localToDevice) {
+ fLocalToDevice = localToDevice;
}
void setGlobalCTM(const SkMatrix& ctm);
virtual void validateDevBounds(const SkIRect&) {}
@@ -372,7 +376,7 @@
SkIPoint fOrigin;
const SkImageInfo fInfo;
const SkSurfaceProps fSurfaceProps;
- SkMatrix fCTM;
+ SkMatrix fLocalToDevice;
typedef SkRefCnt INHERITED;
};
@@ -432,21 +436,21 @@
typedef SkBaseDevice INHERITED;
};
-class SkAutoDeviceCTMRestore : SkNoncopyable {
+class SkAutoDeviceTransformRestore : SkNoncopyable {
public:
- SkAutoDeviceCTMRestore(SkBaseDevice* device, const SkMatrix& ctm)
+ SkAutoDeviceTransformRestore(SkBaseDevice* device, const SkMatrix& localToDevice)
: fDevice(device)
- , fPrevCTM(device->ctm())
+ , fPrevLocalToDevice(device->localToDevice())
{
- fDevice->setCTM(ctm);
+ fDevice->setLocalToDevice(localToDevice);
}
- ~SkAutoDeviceCTMRestore() {
- fDevice->setCTM(fPrevCTM);
+ ~SkAutoDeviceTransformRestore() {
+ fDevice->setLocalToDevice(fPrevLocalToDevice);
}
private:
SkBaseDevice* fDevice;
- const SkMatrix fPrevCTM;
+ const SkMatrix fPrevLocalToDevice;
};
#endif
diff --git a/src/core/SkRemoteGlyphCache.cpp b/src/core/SkRemoteGlyphCache.cpp
index 021a476..2e0bb3e 100644
--- a/src/core/SkRemoteGlyphCache.cpp
+++ b/src/core/SkRemoteGlyphCache.cpp
@@ -333,7 +333,7 @@
GrTextContext::SanitizeOptions(&options);
fPainter.processGlyphRunList(glyphRunList,
- this->ctm(),
+ this->localToDevice(),
this->surfaceProps(),
fDFTSupport,
options,