updates



git-svn-id: http://skia.googlecode.com/svn/trunk@558 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/samplecode/SamplePicture.cpp b/samplecode/SamplePicture.cpp
index e232a50..6c018b7 100644
--- a/samplecode/SamplePicture.cpp
+++ b/samplecode/SamplePicture.cpp
@@ -14,6 +14,7 @@
 #include "SkUtils.h"
 #include "SkColorPriv.h"
 #include "SkColorFilter.h"
+#include "SkShape.h"
 #include "SkTime.h"
 #include "SkTypeface.h"
 #include "SkXfermode.h"
@@ -21,6 +22,69 @@
 #include "SkStream.h"
 #include "SkXMLParser.h"
 
+class SignalShape : public SkShape {
+public:
+    SignalShape() : fSignal(0) {}
+
+    SkShape* setSignal(int n) {
+        fSignal = n;
+        return this;
+    }
+
+protected:
+    virtual void onDraw(SkCanvas* canvas) {
+        SkDebugf("---- sc %d\n", canvas->getSaveCount() - 1);
+    }
+
+private:
+    int fSignal;
+};
+
+static SkPMColor SignalProc(SkPMColor src, SkPMColor dst) {
+    return dst;
+}
+
+/*  Picture playback will skip blocks of draw calls that follow a clip() call
+    that returns empty, and jump down to the corresponding restore() call.
+
+    This is a great preformance win for drawing very large/tall pictures with
+    a small visible window (think scrolling a long document). These tests make
+    sure that (a) we are performing the culling, and (b) we don't get confused
+    by nested save() calls, nor by calls to restoreToCount().
+ */
+static void test_saveRestoreCulling() {
+    SkPaint signalPaint;
+    SignalShape signalShape;
+
+    SkPicture pic;
+    SkRect r = SkRect::MakeWH(0, 0);
+    int n;
+    SkCanvas* canvas = pic.beginRecording(100, 100);
+    int startN = canvas->getSaveCount();
+    SkDebugf("---- start sc %d\n", startN);
+    canvas->drawShape(signalShape.setSignal(1));
+    canvas->save();
+    canvas->drawShape(signalShape.setSignal(2));
+    n = canvas->save();
+    canvas->drawShape(signalShape.setSignal(3));
+    canvas->save();
+    canvas->clipRect(r);
+    canvas->drawShape(signalShape.setSignal(4));
+    canvas->restoreToCount(n);
+    canvas->drawShape(signalShape.setSignal(5));
+    canvas->restore();
+    canvas->drawShape(signalShape.setSignal(6));
+    SkASSERT(canvas->getSaveCount() == startN);
+
+    SkBitmap bm;
+    bm.setConfig(SkBitmap::kARGB_8888_Config, 100, 100);
+    bm.allocPixels();
+    SkCanvas c(bm);
+    c.drawPicture(pic);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
 #include "SkImageRef_GlobalPool.h"
 
 static SkBitmap load_bitmap() {
@@ -73,6 +137,8 @@
         // unref fPicture in our destructor, and it will in turn take care of
         // the other references to fSubPicture
         fSubPicture->unref();
+
+        test_saveRestoreCulling();
     }
     
     virtual ~PictureView() {