Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Unified Diff: tests/ImageFilterTest.cpp

Issue 222723002: Fix matrix adjustment passed to filter processing. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkCanvas.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/ImageFilterTest.cpp
diff --git a/tests/ImageFilterTest.cpp b/tests/ImageFilterTest.cpp
index cfba1fa87df55fcde08f13dbc47f538dd3241159..4c8ddc6657ff0d23f47bdd8cb04eabeef0664daf 100644
--- a/tests/ImageFilterTest.cpp
+++ b/tests/ImageFilterTest.cpp
@@ -19,6 +19,7 @@
#include "SkFlattenableBuffers.h"
#include "SkLightingImageFilter.h"
#include "SkMatrixConvolutionImageFilter.h"
+#include "SkMatrixImageFilter.h"
#include "SkMergeImageFilter.h"
#include "SkMorphologyImageFilter.h"
#include "SkOffsetImageFilter.h"
@@ -363,6 +364,57 @@ static void test_xfermode_cropped_input(SkBaseDevice* device, skiatest::Reporter
REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
}
+DEF_TEST(ImageFilterNestedSaveLayer, reporter) {
+ SkBitmap temp;
+ temp.allocN32Pixels(50, 50);
+ SkBitmapDevice device(temp);
+ SkCanvas canvas(&device);
+ canvas.clear(0x0);
+
+ SkBitmap bitmap;
+ bitmap.allocN32Pixels(10, 10);
+ bitmap.eraseColor(SK_ColorGREEN);
+
+ SkMatrix matrix;
+ matrix.setScale(SkIntToScalar(2), SkIntToScalar(2));
+ matrix.postTranslate(SkIntToScalar(-20), SkIntToScalar(-20));
+ SkAutoTUnref<SkImageFilter> matrixFilter(
+ SkMatrixImageFilter::Create(matrix, SkPaint::kLow_FilterLevel));
+
+ // Test that saveLayer() with a filter nested inside another saveLayer() applies the
+ // correct offset to the filter matrix.
+ SkRect bounds1 = SkRect::MakeXYWH(10, 10, 30, 30);
+ canvas.saveLayer(&bounds1, NULL);
+ SkPaint filterPaint;
+ filterPaint.setImageFilter(matrixFilter);
+ SkRect bounds2 = SkRect::MakeXYWH(20, 20, 10, 10);
+ canvas.saveLayer(&bounds2, &filterPaint);
+ SkPaint greenPaint;
+ greenPaint.setColor(SK_ColorGREEN);
+ canvas.drawRect(bounds2, greenPaint);
+ canvas.restore();
+ canvas.restore();
+ SkPaint strokePaint;
+ strokePaint.setStyle(SkPaint::kStroke_Style);
+ strokePaint.setColor(SK_ColorRED);
+
+ SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1);
+ uint32_t pixel;
+ canvas.readPixels(info, &pixel, 4, 25, 25);
+ REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
+
+ // Test that drawSprite() with a filter nested inside a saveLayer() applies the
+ // correct offset to the filter matrix.
+ canvas.clear(0x0);
+ canvas.readPixels(info, &pixel, 4, 25, 25);
+ canvas.saveLayer(&bounds1, NULL);
+ canvas.drawSprite(bitmap, 20, 20, &filterPaint);
+ canvas.restore();
+
+ canvas.readPixels(info, &pixel, 4, 25, 25);
+ REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
+}
+
DEF_TEST(XfermodeImageFilterCroppedInput, reporter) {
SkBitmap temp;
temp.allocN32Pixels(100, 100);
« no previous file with comments | « src/core/SkCanvas.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698