[WIP] Add Context to SkDrawLooper.

SkDrawLooper carries some state during draws. This CL extracts this state into
a separate class Context, which is then passed by the users of SkDrawLooper
into the appropriate methods.
This is a step towards making SkDrawLooper immutable.

BUG=skia:2141
R=scroggo@google.com, reed@google.com, sugoi@google.com

Author: dominikg@chromium.org

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

git-svn-id: http://skia.googlecode.com/svn/trunk@13760 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/effects/SkLayerDrawLooper.h b/include/effects/SkLayerDrawLooper.h
index 241b3b2..7a13b7a 100644
--- a/include/effects/SkLayerDrawLooper.h
+++ b/include/effects/SkLayerDrawLooper.h
@@ -94,9 +94,9 @@
     /// Similar to addLayer, but adds a layer to the top.
     SkPaint* addLayerOnTop(const LayerInfo&);
 
-    // overrides from SkDrawLooper
-    virtual void init(SkCanvas*);
-    virtual bool next(SkCanvas*, SkPaint* paint);
+    virtual SkDrawLooper::Context* createContext(SkCanvas*, void* storage) const SK_OVERRIDE;
+
+    virtual size_t contextSize() const SK_OVERRIDE { return sizeof(LayerDrawLooperContext); }
 
     SK_DEVELOPER_TO_STRING()
 
@@ -118,9 +118,18 @@
     int     fCount;
 
     // state-machine during the init/next cycle
-    Rec* fCurrRec;
+    class LayerDrawLooperContext : public SkDrawLooper::Context {
+    public:
+        explicit LayerDrawLooperContext(const SkLayerDrawLooper* looper);
 
-    static void ApplyInfo(SkPaint* dst, const SkPaint& src, const LayerInfo&);
+    protected:
+        virtual bool next(SkCanvas*, SkPaint* paint) SK_OVERRIDE;
+
+    private:
+        Rec* fCurrRec;
+
+        static void ApplyInfo(SkPaint* dst, const SkPaint& src, const LayerInfo&);
+    };
 
     class MyRegistrar : public SkFlattenable::Registrar {
     public: