aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/PictureTest.cpp
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-10-02 17:42:15 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-10-02 17:42:15 +0000
commit21b519d56f9838c2e6e7abe704d3313e03f6f754 (patch)
tree7f0b15fdd823871ff621c564a0a22b10a6f95cfe /tests/PictureTest.cpp
parenta3301b6d1527d7a8c59760c219db741b8c8915a3 (diff)
catch empty stack in restorefixup called by clipRect
write stress-test for save/clip/restore peephole optimization git-svn-id: http://skia.googlecode.com/svn/trunk@5774 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests/PictureTest.cpp')
-rw-r--r--tests/PictureTest.cpp57
1 files changed, 56 insertions, 1 deletions
diff --git a/tests/PictureTest.cpp b/tests/PictureTest.cpp
index 34d7832034..dfad68fb69 100644
--- a/tests/PictureTest.cpp
+++ b/tests/PictureTest.cpp
@@ -5,7 +5,10 @@
* found in the LICENSE file.
*/
#include "Test.h"
+#include "SkCanvas.h"
+#include "SkPaint.h"
#include "SkPicture.h"
+#include "SkRandom.h"
#include "SkStream.h"
#ifdef SK_DEBUG
@@ -31,12 +34,64 @@ static void test_serializing_empty_picture() {
}
#endif
+static void rand_op(SkCanvas* canvas, SkRandom& rand) {
+ SkPaint paint;
+ SkRect rect = SkRect::MakeWH(50, 50);
+
+ SkScalar unit = rand.nextUScalar1();
+ if (unit <= 0.3) {
+// SkDebugf("save\n");
+ canvas->save();
+ } else if (unit <= 0.6) {
+// SkDebugf("restore\n");
+ canvas->restore();
+ } else if (unit <= 0.9) {
+// SkDebugf("clip\n");
+ canvas->clipRect(rect);
+ } else {
+// SkDebugf("draw\n");
+ canvas->drawPaint(paint);
+ }
+}
+
+static void test_peephole(skiatest::Reporter* reporter) {
+ SkRandom rand;
+
+ for (int j = 0; j < 100; j++) {
+ SkRandom rand2(rand.getSeed()); // remember the seed
+
+ SkPicture picture;
+ SkCanvas* canvas = picture.beginRecording(100, 100);
+
+ for (int i = 0; i < 1000; ++i) {
+ rand_op(canvas, rand);
+ }
+ picture.endRecording();
+ }
+
+ {
+ SkPicture picture;
+ SkCanvas* canvas = picture.beginRecording(100, 100);
+ SkRect rect = SkRect::MakeWH(50, 50);
+
+ for (int i = 0; i < 100; ++i) {
+ canvas->save();
+ }
+ while (canvas->getSaveCount() > 1) {
+ canvas->clipRect(rect);
+ canvas->restore();
+ }
+ picture.endRecording();
+ }
+}
+
static void TestPicture(skiatest::Reporter* reporter) {
#ifdef SK_DEBUG
test_deleting_empty_playback();
test_serializing_empty_picture();
#endif
+ test_peephole(reporter);
}
#include "TestClassDef.h"
-DEFINE_TESTCLASS("Picture", PictureTestClass, TestPicture)
+DEFINE_TESTCLASS("Pictures", PictureTestClass, TestPicture)