aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar senorblanco <senorblanco@chromium.org>2014-07-11 09:56:03 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-07-11 09:56:03 -0700
commit6ca0b6a46cbe9bef3e2b9b9db813ec864efd62de (patch)
tree777045a1ad412b4a0e6856b152a499f7782bc3ae /tests
parentc855ca0c9408d2a218655a138fab9cc18a2b3940 (diff)
Fix for saveLayer() with filters vs. the BBox Hierarchy.
When building acceleration structures for SkPicture, we must transform the primitive's bounds not only by its own SkPaint, but by the paints of any saveLayer()s currently active above it. We do this by pushing the SkPaint onto a stack on saveLayer(), and popping them on restore(). We also push a NULL paint in save(), so that the pushes and pops are balanced. BUG=skia:2734 R=mtklein@google.com, reed@google.com Author: senorblanco@chromium.org Review URL: https://codereview.chromium.org/380373003
Diffstat (limited to 'tests')
-rw-r--r--tests/ImageFilterTest.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/ImageFilterTest.cpp b/tests/ImageFilterTest.cpp
index 32822087ba..7da4a911ef 100644
--- a/tests/ImageFilterTest.cpp
+++ b/tests/ImageFilterTest.cpp
@@ -409,6 +409,70 @@ DEF_TEST(ImageFilterDrawTiled, reporter) {
}
}
+static void drawBlurredRect(SkCanvas* canvas) {
+ SkAutoTUnref<SkImageFilter> filter(SkBlurImageFilter::Create(SkIntToScalar(8), 0));
+ SkPaint filterPaint;
+ filterPaint.setColor(SK_ColorWHITE);
+ filterPaint.setImageFilter(filter);
+ canvas->saveLayer(NULL, &filterPaint);
+ SkPaint whitePaint;
+ whitePaint.setColor(SK_ColorWHITE);
+ canvas->drawRect(SkRect::Make(SkIRect::MakeWH(4, 4)), whitePaint);
+ canvas->restore();
+}
+
+static void drawPictureClipped(SkCanvas* canvas, const SkRect& clipRect, const SkPicture* picture) {
+ canvas->save();
+ canvas->clipRect(clipRect);
+ canvas->drawPicture(picture);
+ canvas->restore();
+}
+
+DEF_TEST(ImageFilterDrawTiledBlurRTree, reporter) {
+ // Check that the blur filter when recorded with RTree acceleration,
+ // and drawn tiled (with subsequent clip rects) exactly
+ // matches the same filter drawn with without RTree acceleration.
+ // This tests that the "bleed" from the blur into the otherwise-blank
+ // tiles is correctly rendered.
+ // Tests pass by not asserting.
+
+ int width = 16, height = 8;
+ SkBitmap result1, result2;
+ result1.allocN32Pixels(width, height);
+ result2.allocN32Pixels(width, height);
+ SkCanvas canvas1(result1);
+ SkCanvas canvas2(result2);
+ int tileSize = 8;
+
+ canvas1.clear(0);
+ canvas2.clear(0);
+
+ SkRTreeFactory factory;
+
+ SkPictureRecorder recorder1, recorder2;
+ // The only difference between these two pictures is that one has RTree aceleration.
+ SkCanvas* recordingCanvas1 = recorder1.beginRecording(width, height, NULL, 0);
+ SkCanvas* recordingCanvas2 = recorder2.beginRecording(width, height, &factory, 0);
+ drawBlurredRect(recordingCanvas1);
+ drawBlurredRect(recordingCanvas2);
+ SkAutoTUnref<SkPicture> picture1(recorder1.endRecording());
+ SkAutoTUnref<SkPicture> picture2(recorder2.endRecording());
+ for (int y = 0; y < height; y += tileSize) {
+ for (int x = 0; x < width; x += tileSize) {
+ SkRect tileRect = SkRect::Make(SkIRect::MakeXYWH(x, y, tileSize, tileSize));
+ drawPictureClipped(&canvas1, tileRect, picture1);
+ drawPictureClipped(&canvas2, tileRect, picture2);
+ }
+ }
+ for (int y = 0; y < height; y++) {
+ int diffs = memcmp(result1.getAddr32(0, y), result2.getAddr32(0, y), result1.rowBytes());
+ REPORTER_ASSERT(reporter, !diffs);
+ if (diffs) {
+ break;
+ }
+ }
+}
+
DEF_TEST(ImageFilterMatrixConvolution, reporter) {
// Check that a 1x3 filter does not cause a spurious assert.
SkScalar kernel[3] = {