Make GrContext cache the gpu paths

Creating paths for nv_path_rendering is costly. Try to reduce this
cost by caching paths based on the SkPath "hash" (i.e. SkPathRef
generation id) and stroke properties.

Adds the paths to GrContext::fTextureCache instance. Later this should
be renamed and the GrContext API should reflect the nature of the cache
better.

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

Author: kkinnunen@nvidia.com

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

git-svn-id: http://skia.googlecode.com/svn/trunk/include@12083 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/core/SkStrokeRec.h b/core/SkStrokeRec.h
index c5b47c2..1e0ec88 100644
--- a/core/SkStrokeRec.h
+++ b/core/SkStrokeRec.h
@@ -81,6 +81,14 @@
      */
     bool applyToPath(SkPath* dst, const SkPath& src) const;
 
+    bool operator==(const SkStrokeRec& other) const {
+            return fWidth == other.fWidth &&
+                   fMiterLimit == other.fMiterLimit &&
+                   fCap == other.fCap &&
+                   fJoin == other.fJoin &&
+                   fStrokeAndFill == other.fStrokeAndFill;
+    }
+
 private:
     SkScalar        fWidth;
     SkScalar        fMiterLimit;
diff --git a/gpu/GrContext.h b/gpu/GrContext.h
index ba3e53a..f302a44 100644
--- a/gpu/GrContext.h
+++ b/gpu/GrContext.h
@@ -29,6 +29,7 @@
 class GrIndexBufferAllocPool;
 class GrInOrderDrawBuffer;
 class GrOvalRenderer;
+class GrPath;
 class GrPathRenderer;
 class GrResourceEntry;
 class GrResourceCache;
@@ -925,6 +926,7 @@
     // Needed so GrTexture's returnToCache helper function can call
     // addExistingTextureToCache
     friend class GrTexture;
+    friend class GrStencilAndCoverPathRenderer;
 
     // Add an existing texture to the texture cache. This is intended solely
     // for use with textures released from an GrAutoScratchTexture.
@@ -948,6 +950,15 @@
      */
     static bool OverbudgetCB(void* data);
 
+    /** Creates a new gpu path, based on the specified path and stroke and returns it.
+     * The caller owns a ref on the returned path which must be balanced by a call to unref.
+     *
+     * @param skPath the path geometry.
+     * @param stroke the path stroke.
+     * @return a new path or NULL if the operation is not supported by the backend.
+     */
+    GrPath* createPath(const SkPath& skPath, const SkStrokeRec& stroke);
+
     typedef SkRefCnt INHERITED;
 };