From 9da5a5a198e5dc9148f7f30a6089377590eee55b Mon Sep 17 00:00:00 2001 From: msarett Date: Fri, 19 Aug 2016 08:38:36 -0700 Subject: [PATCH] Fix bug, always keep fIsScaleTranslate in correct state BUG:639179 GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2263513003 Review-Url: https://codereview.chromium.org/2263513003 --- src/core/SkCanvas.cpp | 2 +- tests/QuickRejectTest.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index 6fbc4fe7..e5ad3b8 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -1488,12 +1488,12 @@ void SkCanvas::concat(const SkMatrix& matrix) { void SkCanvas::internalSetMatrix(const SkMatrix& matrix) { fDeviceCMDirty = true; fMCRec->fMatrix = matrix; + fIsScaleTranslate = matrix.isScaleTranslate(); } void SkCanvas::setMatrix(const SkMatrix& matrix) { this->checkForDeferredSave(); this->internalSetMatrix(matrix); - fIsScaleTranslate = matrix.isScaleTranslate(); this->didSetMatrix(matrix); } diff --git a/tests/QuickRejectTest.cpp b/tests/QuickRejectTest.cpp index b39484b..8f6556b 100644 --- a/tests/QuickRejectTest.cpp +++ b/tests/QuickRejectTest.cpp @@ -7,6 +7,7 @@ #include "SkCanvas.h" #include "SkDrawLooper.h" +#include "SkLightingImageFilter.h" #include "SkTypes.h" #include "Test.h" @@ -145,3 +146,26 @@ DEF_TEST(QuickReject, reporter) { test_layers(reporter); test_quick_reject(reporter); } + +// Regression test to make sure that we keep fIsScaleTranslate up to date on the canvas. +// It is possible to set a new matrix on the canvas without calling setMatrix(). This tests +// that code path. +DEF_TEST(QuickReject_MatrixState, reporter) { + SkCanvas canvas(100, 100); + + SkMatrix matrix; + matrix.setRotate(45.0f); + canvas.setMatrix(matrix); + + SkPaint paint; + sk_sp filter = SkLightingImageFilter::MakeDistantLitDiffuse( + SkPoint3::Make(1.0f, 1.0f, 1.0f), 0xFF0000FF, 2.0f, 0.5f, nullptr); + REPORTER_ASSERT(reporter, filter); + paint.setImageFilter(filter); + SkCanvas::SaveLayerRec rec; + rec.fPaint = &paint; + canvas.saveLayer(rec); + + // quickReject() will assert if the matrix is out of sync. + canvas.quickReject(SkRect::MakeWH(100.0f, 100.0f)); +} -- 2.7.4