deprecate getTotalMatrix
Change-Id: Iec7d67f4ec3fdf4d5280f3de3d6146a69a60c646
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/339995
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
diff --git a/bench/BulkRectBench.cpp b/bench/BulkRectBench.cpp
index 2509d61..a5b10db 100644
--- a/bench/BulkRectBench.cpp
+++ b/bench/BulkRectBench.cpp
@@ -145,7 +145,7 @@
paint.setAntiAlias(true);
GrRenderTargetContext* rtc = canvas->internal_private_accessTopLayerRenderTargetContext();
- SkMatrix view = canvas->getTotalMatrix();
+ SkMatrix view = canvas->getLocalToDeviceAs3x3();
SkSimpleMatrixProvider matrixProvider(view);
GrPaint grPaint;
SkPaintToGrPaint(context, rtc->colorInfo(), paint, matrixProvider, &grPaint);
diff --git a/bench/SKPBench.cpp b/bench/SKPBench.cpp
index 7b18e6b..16cf11e 100644
--- a/bench/SKPBench.cpp
+++ b/bench/SKPBench.cpp
@@ -74,7 +74,7 @@
clip.offset(-SkIntToScalar(tileRect.fLeft), -SkIntToScalar(tileRect.fTop));
fSurfaces.back()->getCanvas()->clipRect(clip);
- fSurfaces.back()->getCanvas()->setMatrix(canvas->getTotalMatrix());
+ fSurfaces.back()->getCanvas()->setMatrix(canvas->getLocalToDevice());
fSurfaces.back()->getCanvas()->scale(fScale, fScale);
}
}
diff --git a/docs/examples/Canvas_empty_constructor.cpp b/docs/examples/Canvas_empty_constructor.cpp
index 79ea09b..3bc90ab 100644
--- a/docs/examples/Canvas_empty_constructor.cpp
+++ b/docs/examples/Canvas_empty_constructor.cpp
@@ -4,8 +4,8 @@
// HASH=4a00e6589e862fde5be532f4b6e316ce
REG_FIDDLE(Canvas_empty_constructor, 256, 256, true, 0) {
static void check_for_rotated_ctm(const SkCanvas* canvas) {
- const SkMatrix& matrix = canvas->getTotalMatrix();
- SkDebugf("rect stays rect is %s\n", matrix.rectStaysRect() ? "true" : "false");
+ const SkM44 matrix = canvas->getLocalToDevice();
+ SkDebugf("ctm is identity = \n", matrix == SkM44() ? "true" : "false");
}
void draw(SkCanvas* canvas) {
diff --git a/gm/dftext.cpp b/gm/dftext.cpp
index 1f2c568..07c3720 100644
--- a/gm/dftext.cpp
+++ b/gm/dftext.cpp
@@ -68,7 +68,7 @@
auto surface(SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info, 0, &props));
SkCanvas* canvas = surface ? surface->getCanvas() : inputCanvas;
// init our new canvas with the old canvas's matrix
- canvas->setMatrix(inputCanvas->getTotalMatrix());
+ canvas->setMatrix(inputCanvas->getLocalToDeviceAs3x3());
// apply global scale to test glyph positioning
canvas->scale(1.05f, 1.05f);
canvas->clear(0xffffffff);
diff --git a/gm/dftext_blob_persp.cpp b/gm/dftext_blob_persp.cpp
index f401a1b..637f5d5 100644
--- a/gm/dftext_blob_persp.cpp
+++ b/gm/dftext_blob_persp.cpp
@@ -73,7 +73,7 @@
auto surface = SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info, 0, &props);
SkCanvas* canvas = surface ? surface->getCanvas() : inputCanvas;
// init our new canvas with the old canvas's matrix
- canvas->setMatrix(inputCanvas->getTotalMatrix());
+ canvas->setMatrix(inputCanvas->getLocalToDeviceAs3x3());
SkScalar x = 0, y = 0;
SkScalar maxH = 0;
for (auto twm : {TranslateWithMatrix::kNo, TranslateWithMatrix::kYes}) {
diff --git a/gm/glyph_pos.cpp b/gm/glyph_pos.cpp
index 10ab213..6f86ed7 100644
--- a/gm/glyph_pos.cpp
+++ b/gm/glyph_pos.cpp
@@ -99,7 +99,7 @@
// This demonstrates that we can not measure the text if
// there's a device transform. The canvas total matrix will
// end up being a device transform.
- bool drawRef = !(canvas->getTotalMatrix().getType() &
+ bool drawRef = !(canvas->getLocalToDeviceAs3x3().getType() &
~(SkMatrix::kIdentity_Mask | SkMatrix::kTranslate_Mask));
SkRect bounds;
diff --git a/gm/resizeimagefilter.cpp b/gm/resizeimagefilter.cpp
index 482e3ae..6abbb62 100644
--- a/gm/resizeimagefilter.cpp
+++ b/gm/resizeimagefilter.cpp
@@ -42,7 +42,7 @@
SkFilterQuality filterQuality,
sk_sp<SkImageFilter> input) {
SkRect dstRect;
- canvas->getTotalMatrix().mapRect(&dstRect, rect);
+ canvas->getLocalToDeviceAs3x3().mapRect(&dstRect, rect);
canvas->save();
SkScalar deviceScaleX = deviceSize.width() / dstRect.width();
SkScalar deviceScaleY = deviceSize.height() / dstRect.height();
diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h
index d40c73e..004c400 100644
--- a/include/core/SkCanvas.h
+++ b/include/core/SkCanvas.h
@@ -32,6 +32,9 @@
#include <memory>
#include <vector>
+// Working on allow this to be undefined
+#define SK_SUPPORT_LEGACY_GETTOTALMATRIX
+
class GrRecordingContext;
class GrRenderTargetContext;
class SkBaseDevice;
@@ -2433,6 +2436,14 @@
*/
SkM44 getLocalToDevice() const;
+ /**
+ * Throws away the 3rd row and column in the matrix, so be warned.
+ */
+ SkMatrix getLocalToDeviceAs3x3() const {
+ return this->getLocalToDevice().asM33();
+ }
+
+#ifdef SK_SUPPORT_LEGACY_GETTOTALMATRIX
/** DEPRECATED
* Legacy version of getLocalToDevice(), which strips away any Z information, and
* just returns a 3x3 version.
@@ -2443,6 +2454,7 @@
* example: https://fiddle.skia.org/c/@Clip
*/
SkMatrix getTotalMatrix() const;
+#endif
///////////////////////////////////////////////////////////////////////////
diff --git a/samplecode/PerlinPatch.cpp b/samplecode/PerlinPatch.cpp
index d659914..b46799c 100644
--- a/samplecode/PerlinPatch.cpp
+++ b/samplecode/PerlinPatch.cpp
@@ -126,7 +126,7 @@
}
void onDrawContent(SkCanvas* canvas) override {
- if (!canvas->getTotalMatrix().invert(&fInvMatrix)) {
+ if (!canvas->getLocalToDeviceAs3x3().invert(&fInvMatrix)) {
return;
}
diff --git a/samplecode/SampleFilterBounds.cpp b/samplecode/SampleFilterBounds.cpp
index def4be4..95dfc74 100644
--- a/samplecode/SampleFilterBounds.cpp
+++ b/samplecode/SampleFilterBounds.cpp
@@ -175,7 +175,7 @@
void onDrawContent(SkCanvas* canvas) override {
// The local content, e.g. what would be submitted to drawRect or the bounds to saveLayer
const SkRect localContentRect = SkRect::MakeLTRB(100.f, 20.f, 180.f, 140.f);
- SkMatrix ctm = canvas->getTotalMatrix();
+ SkMatrix ctm = canvas->getLocalToDeviceAs3x3();
// Base rendering of a filter
SkPaint blurPaint;
diff --git a/src/core/SkBigPicture.cpp b/src/core/SkBigPicture.cpp
index b6e9707..1c07b44 100644
--- a/src/core/SkBigPicture.cpp
+++ b/src/core/SkBigPicture.cpp
@@ -42,7 +42,7 @@
void SkBigPicture::partialPlayback(SkCanvas* canvas,
int start,
int stop,
- const SkMatrix& initialCTM) const {
+ const SkM44& initialCTM) const {
SkASSERT(canvas);
SkRecordPartialDraw(*fRecord,
canvas,
diff --git a/src/core/SkBigPicture.h b/src/core/SkBigPicture.h
index 11191e8..eac2e90 100644
--- a/src/core/SkBigPicture.h
+++ b/src/core/SkBigPicture.h
@@ -8,6 +8,7 @@
#ifndef SkBigPicture_DEFINED
#define SkBigPicture_DEFINED
+#include "include/core/SkM44.h"
#include "include/core/SkPicture.h"
#include "include/core/SkRect.h"
#include "include/private/SkNoncopyable.h"
@@ -52,7 +53,7 @@
void partialPlayback(SkCanvas*,
int start,
int stop,
- const SkMatrix& initialCTM) const;
+ const SkM44& initialCTM) const;
// Used by GrRecordReplaceDraw
const SkBBoxHierarchy* bbh() const { return fBBH.get(); }
const SkRecord* record() const { return fRecord.get(); }
diff --git a/src/core/SkDrawLooper.cpp b/src/core/SkDrawLooper.cpp
index 9de4d43..85a6529 100644
--- a/src/core/SkDrawLooper.cpp
+++ b/src/core/SkDrawLooper.cpp
@@ -22,9 +22,7 @@
void SkDrawLooper::Context::Info::applyToCanvas(SkCanvas* canvas) const {
if (fApplyPostCTM) {
- SkMatrix ctm = canvas->getTotalMatrix();
- ctm.postTranslate(fTranslate.fX, fTranslate.fY);
- canvas->setMatrix(ctm);
+ canvas->setMatrix(canvas->getLocalToDevice().postTranslate(fTranslate.fX, fTranslate.fY));
} else {
canvas->translate(fTranslate.fX, fTranslate.fY);
}
@@ -95,9 +93,8 @@
}
canvas->save();
if (info.fApplyPostCTM) {
- SkMatrix ctm = canvas->getTotalMatrix();
- ctm.postTranslate(info.fTranslate.fX, info.fTranslate.fY);
- canvas->setMatrix(ctm);
+ canvas->setMatrix(canvas->getLocalToDevice().postTranslate(info.fTranslate.fX,
+ info.fTranslate.fY));
} else {
canvas->translate(info.fTranslate.fX, info.fTranslate.fY);
}
diff --git a/src/core/SkRecordDraw.cpp b/src/core/SkRecordDraw.cpp
index 953a954..4b8a9c0 100644
--- a/src/core/SkRecordDraw.cpp
+++ b/src/core/SkRecordDraw.cpp
@@ -59,7 +59,7 @@
void SkRecordPartialDraw(const SkRecord& record, SkCanvas* canvas,
SkPicture const* const drawablePicts[], int drawableCount,
int start, int stop,
- const SkMatrix& initialCTM) {
+ const SkM44& initialCTM) {
SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/);
stop = std::min(stop, record.count());
@@ -92,8 +92,8 @@
}
DRAW(MarkCTM, markCTM(r.name.c_str()));
-DRAW(SetMatrix, setMatrix(SkMatrix::Concat(fInitialCTM, r.matrix)));
-DRAW(SetM44, setMatrix(SkM44(fInitialCTM) * r.matrix));
+DRAW(SetMatrix, setMatrix(fInitialCTM.asM33() * r.matrix));
+DRAW(SetM44, setMatrix(fInitialCTM * r.matrix));
DRAW(Concat44, concat(r.matrix));
DRAW(Concat, concat(r.matrix));
DRAW(Translate, translate(r.dx, r.dy));
diff --git a/src/core/SkRecordDraw.h b/src/core/SkRecordDraw.h
index 34132a3..ca060ea 100644
--- a/src/core/SkRecordDraw.h
+++ b/src/core/SkRecordDraw.h
@@ -39,7 +39,7 @@
// the initialCTM parameter must set to just the replay matrix.
void SkRecordPartialDraw(const SkRecord&, SkCanvas*,
SkPicture const* const drawablePicts[], int drawableCount,
- int start, int stop, const SkMatrix& initialCTM);
+ int start, int stop, const SkM44& initialCTM);
namespace SkRecords {
@@ -48,8 +48,8 @@
public:
explicit Draw(SkCanvas* canvas, SkPicture const* const drawablePicts[],
SkDrawable* const drawables[], int drawableCount,
- const SkMatrix* initialCTM = nullptr)
- : fInitialCTM(initialCTM ? *initialCTM : canvas->getTotalMatrix())
+ const SkM44* initialCTM = nullptr)
+ : fInitialCTM(initialCTM ? *initialCTM : canvas->getLocalToDevice())
, fCanvas(canvas)
, fDrawablePicts(drawablePicts)
, fDrawables(drawables)
@@ -71,7 +71,7 @@
// No base case, so we'll be compile-time checked that we implement all possibilities.
template <typename T> void draw(const T&);
- const SkMatrix fInitialCTM;
+ const SkM44 fInitialCTM;
SkCanvas* fCanvas;
SkPicture const* const* fDrawablePicts;
SkDrawable* const* fDrawables;
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 6f16597..7ede206 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -1011,7 +1011,7 @@
void SkGpuDevice::drawDrawable(SkDrawable* drawable, const SkMatrix* matrix, SkCanvas* canvas) {
GrBackendApi api = this->recordingContext()->backend();
if (GrBackendApi::kVulkan == api) {
- const SkMatrix& ctm = canvas->getTotalMatrix();
+ const SkMatrix& ctm = canvas->getLocalToDeviceAs3x3();
const SkMatrix& combinedMatrix = matrix ? SkMatrix::Concat(ctm, *matrix) : ctm;
std::unique_ptr<SkDrawable::GpuDrawHandler> gpuDraw =
drawable->snapGpuDrawHandler(api, combinedMatrix, canvas->getDeviceClipBounds(),
diff --git a/src/utils/SkPaintFilterCanvas.cpp b/src/utils/SkPaintFilterCanvas.cpp
index f04222c..2004105 100644
--- a/src/utils/SkPaintFilterCanvas.cpp
+++ b/src/utils/SkPaintFilterCanvas.cpp
@@ -37,7 +37,7 @@
// Transfer matrix & clip state before adding the target canvas.
this->clipRect(SkRect::Make(canvas->getDeviceClipBounds()));
- this->setMatrix(canvas->getTotalMatrix());
+ this->setMatrix(canvas->getLocalToDevice());
this->addCanvas(canvas);
}
diff --git a/tests/RecordDrawTest.cpp b/tests/RecordDrawTest.cpp
index 3da1363..593257a 100644
--- a/tests/RecordDrawTest.cpp
+++ b/tests/RecordDrawTest.cpp
@@ -184,7 +184,7 @@
SkRecord rerecord;
SkRecorder canvas(&rerecord, kWidth, kHeight);
- SkRecordPartialDraw(record, &canvas, nullptr, 0, 1, 2, SkMatrix::I()); // replay just drawRect of r2
+ SkRecordPartialDraw(record, &canvas, nullptr, 0, 1, 2, SkM44()); // replay just drawRect of r2
REPORTER_ASSERT(r, 1 == count_instances_of_type<SkRecords::DrawRect>(rerecord));
int index = find_first_instances_of_type<SkRecords::DrawRect>(rerecord);
diff --git a/tools/debugger/DebugCanvas.cpp b/tools/debugger/DebugCanvas.cpp
index 693be01..f4cc125 100644
--- a/tools/debugger/DebugCanvas.cpp
+++ b/tools/debugger/DebugCanvas.cpp
@@ -177,7 +177,7 @@
finalCanvas->restore();
}
- fMatrix = finalCanvas->getTotalMatrix();
+ fMatrix = finalCanvas->getLocalToDevice();
fClip = finalCanvas->getDeviceClipBounds();
if (fShowOrigin) {
const SkPaint originXPaint = SkPaint({1.0, 0, 0, 1.0});
diff --git a/tools/debugger/DebugCanvas.h b/tools/debugger/DebugCanvas.h
index 1c3d015..12b14f5 100644
--- a/tools/debugger/DebugCanvas.h
+++ b/tools/debugger/DebugCanvas.h
@@ -89,7 +89,7 @@
/**
Returns the most recently calculated transformation matrix
*/
- const SkMatrix& getCurrentMatrix() { return fMatrix; }
+ const SkM44& getCurrentMatrix() { return fMatrix; }
/**
Returns the most recently calculated clip
@@ -219,7 +219,7 @@
private:
SkTDArray<DrawCommand*> fCommandVector;
- SkMatrix fMatrix;
+ SkM44 fMatrix;
SkIRect fClip;
bool fOverdrawViz = false;
diff --git a/tools/skiaserve/Request.cpp b/tools/skiaserve/Request.cpp
index 06cfd2d..bc336ab 100644
--- a/tools/skiaserve/Request.cpp
+++ b/tools/skiaserve/Request.cpp
@@ -260,12 +260,12 @@
SkDynamicMemoryWStream stream;
SkJSONWriter writer(&stream, SkJSONWriter::Mode::kFast);
- SkMatrix vm = fDebugCanvas->getCurrentMatrix();
+ SkM44 vm = fDebugCanvas->getCurrentMatrix();
SkIRect clip = fDebugCanvas->getCurrentClip();
writer.beginObject(); // root
writer.appendName("ViewMatrix");
- DrawCommand::MakeJsonMatrix(writer, vm);
+ DrawCommand::MakeJsonMatrix44(writer, vm);
writer.appendName("ClipRect");
DrawCommand::MakeJsonIRect(writer, clip);
writer.endObject(); // root