Builder class for SkLayerDrawLooper.

SkLayerDrawLooper provides methods like addLayer() to build up a linked list
of layers. Working towards making this class immutable, this patch introduces
the SkLayerDrawLooperBuilder class which is used to accumulate all the layers
first. Once all layers are in place, it creates a new SkLayerDrawLooper object
and hands over the list of layers to that object.

For now we keep the addLayer methods in SkLayerDrawLooper so we don't break
Chrome and Blink when this is landed. Once we've updated all users, we can
remove the methods.

BUG=skia:2141
R=reed@google.com, scroggo@google.com, mtklein@google.com, reed@chromium.org

Author: dominikg@chromium.org

Review URL: https://codereview.chromium.org/133813005

git-svn-id: http://skia.googlecode.com/svn/trunk@13448 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/effects/SkLayerDrawLooper.h b/include/effects/SkLayerDrawLooper.h
index 6955192..e1fae57 100644
--- a/include/effects/SkLayerDrawLooper.h
+++ b/include/effects/SkLayerDrawLooper.h
@@ -107,10 +107,12 @@
     virtual bool next(SkCanvas*, SkPaint* paint);
 
     SK_DEVELOPER_TO_STRING()
-    SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLayerDrawLooper)
+
+    /// Implements Flattenable.
+    virtual Factory getFactory() const SK_OVERRIDE { return CreateProc; }
+    static SkFlattenable* CreateProc(SkReadBuffer& buffer);
 
 protected:
-    SkLayerDrawLooper(SkReadBuffer&);
     virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
 
 private:
@@ -134,6 +136,44 @@
     };
 
     typedef SkDrawLooper INHERITED;
+
+public:
+    class SK_API Builder {
+    public:
+        Builder();
+        ~Builder();
+
+        /**
+         *  Call for each layer you want to add (from top to bottom).
+         *  This returns a paint you can modify, but that ptr is only valid until
+         *  the next call made to addLayer().
+         */
+        SkPaint* addLayer(const LayerInfo&);
+
+        /**
+         *  This layer will draw with the original paint, at the specified offset
+         */
+        void addLayer(SkScalar dx, SkScalar dy);
+
+        /**
+         *  This layer will with the original paint and no offset.
+         */
+        void addLayer() { this->addLayer(0, 0); }
+
+        /// Similar to addLayer, but adds a layer to the top.
+        SkPaint* addLayerOnTop(const LayerInfo&);
+
+        /**
+          * Pass list of layers on to newly built looper and return it. This will
+          * also reset the builder, so it can be used to build another looper.
+          */
+        SkLayerDrawLooper* detachLooper();
+
+    private:
+        Rec* fRecs;
+        Rec* fTopRec;
+        int  fCount;
+    };
 };
 
 #endif