Avoid re-rendering stencil clip for every draw with reducable clip stack

Fixes the cases where clip stack reduction would cause clip to be
re-rendered to stencil for each draw call. This causes unneeded
slowdown.

Stencil cache would not be used because the clip stack generation id communicated
by the clip stack element list would be invalid. This happended due to

 a) clip stack reduction creating new elements in the element list.

 b) purging logic removing the generation id, but reduction logic
    selecting already purged element, and thus the generation id, as
    the representative state of the clip.

Cases of a) where reduction would flatten the stack to a single new
element were fixed by assigning the generation id of the top-most
element of the clip stack as the generation id of the new
element. This is not strictly minimal, but enables more caching than
using invalid id.

Cases of a) where reduction would substitute a stack element with a
new element the generation id of the substituted element is used.

The b) part was fixed by removing the purging logic. It was not
exactly correct, as the previously purged states were actually
used. The purging was not used for anything.

Changes SkClipStack API to highlight that invalid generation id is
never returned by SkClipStack. Empty stacks are wide open. Changes the
clients to reflect this.

Fixes a crash when not passing anti-alias out parameter to
GrReducedClip::ReduceClipStack. The crash is not exercised in the
current code.

Committed: http://code.google.com/p/skia/source/detail?r=12084

R=bsalomon@google.com, robertphillips@google.com

Author: kkinnunen@nvidia.com

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

git-svn-id: http://skia.googlecode.com/svn/trunk@12127 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/core/SkClipStack.h b/include/core/SkClipStack.h
index 145552d..0d6cfb2 100644
--- a/include/core/SkClipStack.h
+++ b/include/core/SkClipStack.h
@@ -109,7 +109,7 @@
             stack not to the element itself. That is the same clip path in different stacks will
             have a different ID since the elements produce different clip result in the context of
             their stacks. */
-        int32_t getGenID() const { return fGenID; }
+        int32_t getGenID() const { SkASSERT(kInvalidGenID != fGenID); return fGenID; }
 
         /**
          * Gets the bounds of the clip element, either the rect or path bounds. (Whether the shape
@@ -316,25 +316,12 @@
     bool isWideOpen() const;
 
     /**
-     * Add a callback function that will be called whenever a clip state
-     * is no longer viable. This will occur whenever restore
-     * is called or when a clipDevRect or clipDevPath call updates the
-     * clip within an existing save/restore state. Each clip state is
-     * represented by a unique generation ID.
-     */
-    typedef void (*PFPurgeClipCB)(int genID, void* data);
-    void addPurgeClipCallback(PFPurgeClipCB callback, void* data) const;
-
-    /**
-     * Remove a callback added earlier via addPurgeClipCallback
-     */
-    void removePurgeClipCallback(PFPurgeClipCB callback, void* data) const;
-
-    /**
      * The generation ID has three reserved values to indicate special
      * (potentially ignorable) cases
      */
-    static const int32_t kInvalidGenID = 0;
+    static const int32_t kInvalidGenID = 0;     //!< Invalid id that is never returned by
+                                                //!< SkClipStack. Useful when caching clips
+                                                //!< based on GenID.
     static const int32_t kEmptyGenID = 1;       // no pixels writeable
     static const int32_t kWideOpenGenID = 2;    // all pixels writeable
 
@@ -440,29 +427,12 @@
     // invalid ID.
     static int32_t     gGenID;
 
-    struct ClipCallbackData {
-        PFPurgeClipCB   fCallback;
-        void*           fData;
-
-        friend bool operator==(const ClipCallbackData& a,
-                               const ClipCallbackData& b) {
-            return a.fCallback == b.fCallback && a.fData == b.fData;
-        }
-    };
-
-    mutable SkTDArray<ClipCallbackData> fCallbackData;
-
     /**
      * Restore the stack back to the specified save count.
      */
     void restoreTo(int saveCount);
 
     /**
-     * Invoke all the purge callbacks passing in element's generation ID.
-     */
-    void purgeClip(Element* element);
-
-    /**
      * Return the next unique generation ID.
      */
     static int32_t GetNextGenID();