Calculate rough approximations for nvpr path sizes

Calculates a rough approximation of the actual value for gpuMemorySize
in GrGLPath and GrGLPathRange, instead of assuming every path is the
same fixed size.

BUG=skia:
R=bsalomon@google.com, markkilgard@gmail.com

Author: cdalton@nvidia.com

Review URL: https://codereview.chromium.org/442603002
diff --git a/src/gpu/gl/GrGLPath.cpp b/src/gpu/gl/GrGLPath.cpp
index 6f158cd..e80259e 100644
--- a/src/gpu/gl/GrGLPath.cpp
+++ b/src/gpu/gl/GrGLPath.cpp
@@ -81,10 +81,10 @@
 
 static const bool kIsWrapped = false; // The constructor creates the GL path object.
 
-void GrGLPath::InitPathObject(GrGpuGL* gpu,
-                              GrGLuint pathID,
-                              const SkPath& skPath,
-                              const SkStrokeRec& stroke) {
+size_t GrGLPath::InitPathObject(GrGpuGL* gpu,
+                                GrGLuint pathID,
+                                const SkPath& skPath,
+                                const SkStrokeRec& stroke) {
     GrGLPathRendering* pr = gpu->pathRendering();
     SkSTArray<16, GrGLubyte, true> pathCommands;
     SkSTArray<16, SkPoint, true> pathPoints;
@@ -117,6 +117,13 @@
         pr->pathParameteri(pathID, GR_GL_PATH_INITIAL_END_CAP, cap);
         pr->pathParameteri(pathID, GR_GL_PATH_TERMINAL_END_CAP, cap);
     }
+
+    size_t approximateSize = 5 * (verbCnt + pointCnt);
+    if (SkStrokeRec::kStrokeAndFill_Style == stroke.getStyle()) {
+        // It will take approxoimately twice the memory if it has both fill *and* stroke.
+        approximateSize *= 2;
+    }
+    return approximateSize;
 }
 
 GrGLPath::GrGLPath(GrGpuGL* gpu, const SkPath& path, const SkStrokeRec& stroke)
@@ -124,7 +131,7 @@
       fPathID(gpu->pathRendering()->genPaths(1)) {
     SkASSERT(!path.isEmpty());
 
-    InitPathObject(gpu, fPathID, fSkPath, stroke);
+    fGpuMemorySize = InitPathObject(gpu, fPathID, fSkPath, stroke);
 
     if (stroke.needToApply()) {
         // FIXME: try to account for stroking, without rasterizing the stroke.
diff --git a/src/gpu/gl/GrGLPath.h b/src/gpu/gl/GrGLPath.h
index 935a2e2..7ce93c6 100644
--- a/src/gpu/gl/GrGLPath.h
+++ b/src/gpu/gl/GrGLPath.h
@@ -22,17 +22,20 @@
 
 class GrGLPath : public GrPath {
 public:
-    static void InitPathObject(GrGpuGL*,
-                               GrGLuint pathID,
-                               const SkPath&,
-                               const SkStrokeRec&);
+    /**
+     * Initialize a GL path object with a given path and stroke.
+     *
+     * @return the approximate GPU memory size of the path object in bytes.
+     */
+    static size_t InitPathObject(GrGpuGL*,
+                                 GrGLuint pathID,
+                                 const SkPath&,
+                                 const SkStrokeRec&);
 
     GrGLPath(GrGpuGL* gpu, const SkPath& path, const SkStrokeRec& stroke);
     virtual ~GrGLPath();
     GrGLuint pathID() const { return fPathID; }
-    // TODO: Figure out how to get an approximate size of the path in Gpu
-    // memory.
-    virtual size_t gpuMemorySize() const SK_OVERRIDE { return 100; }
+    virtual size_t gpuMemorySize() const SK_OVERRIDE { return fGpuMemorySize; }
 
 protected:
     virtual void onRelease() SK_OVERRIDE;
@@ -40,6 +43,7 @@
 
 private:
     GrGLuint fPathID;
+    size_t fGpuMemorySize;
 
     typedef GrPath INHERITED;
 };
diff --git a/src/gpu/gl/GrGLPathRange.cpp b/src/gpu/gl/GrGLPathRange.cpp
index 5e89cb5..9e2b2e7 100644
--- a/src/gpu/gl/GrGLPathRange.cpp
+++ b/src/gpu/gl/GrGLPathRange.cpp
@@ -14,7 +14,7 @@
 GrGLPathRange::GrGLPathRange(GrGpuGL* gpu, size_t size, const SkStrokeRec& stroke)
     : INHERITED(gpu, size, stroke),
       fBasePathID(gpu->pathRendering()->genPaths(fSize)),
-      fNumDefinedPaths(0) {
+      fGpuMemorySize(0) {
 }
 
 GrGLPathRange::~GrGLPathRange() {
@@ -30,8 +30,7 @@
     // Make sure the path at this index hasn't been initted already.
     SkASSERT(GR_GL_FALSE == gpu->pathRendering()->isPath(fBasePathID + index));
 
-    GrGLPath::InitPathObject(gpu, fBasePathID + index, skPath, fStroke);
-    ++fNumDefinedPaths;
+    fGpuMemorySize += GrGLPath::InitPathObject(gpu, fBasePathID + index, skPath, fStroke);
     this->didChangeGpuMemorySize();
 }
 
diff --git a/src/gpu/gl/GrGLPathRange.h b/src/gpu/gl/GrGLPathRange.h
index 927310d..8e2df76 100644
--- a/src/gpu/gl/GrGLPathRange.h
+++ b/src/gpu/gl/GrGLPathRange.h
@@ -26,13 +26,8 @@
     virtual ~GrGLPathRange();
 
     GrGLuint basePathID() const { return fBasePathID; }
-
     virtual void initAt(size_t index, const SkPath&);
-
-    // TODO: Use a better approximation for the individual path sizes.
-    virtual size_t gpuMemorySize() const SK_OVERRIDE {
-        return 100 * fNumDefinedPaths;
-    }
+    virtual size_t gpuMemorySize() const SK_OVERRIDE { return fGpuMemorySize; }
 
 protected:
     virtual void onRelease() SK_OVERRIDE;
@@ -40,7 +35,7 @@
 
 private:
     GrGLuint fBasePathID;
-    size_t fNumDefinedPaths;
+    size_t fGpuMemorySize;
 
     typedef GrPathRange INHERITED;
 };