All child GrFragmentProcs' transforms and textures will be stored in the root GrFragmentProc in preorder

Changed childProcessor(i) to return const referencd

Fixed rootProc/parentProc offset issues; renamed a few things.

added nonempty check to gatherTransforms to avoid segfault

removed recursive append_gr_coord_transforms() from GrGLProgramBuilder

BUILDS! Changed num*includeProc() calls to num() calls

added gatherCoordTransforms(). added coordTransforms() for root proc only

Modified GrFragmentProcessor to append child proc transforms and textures to root proc's arrays.

BUG=skia:4182

Review URL: https://codereview.chromium.org/1275853005
diff --git a/include/gpu/GrFragmentProcessor.h b/include/gpu/GrFragmentProcessor.h
index 2dc7980..bbc2f2b 100644
--- a/include/gpu/GrFragmentProcessor.h
+++ b/include/gpu/GrFragmentProcessor.h
@@ -9,6 +9,7 @@
 #define GrFragmentProcessor_DEFINED
 
 #include "GrProcessor.h"
+#include "GrStagedProcessor.h"
 
 class GrCoordTransform;
 class GrGLSLCaps;
@@ -38,20 +39,12 @@
     void getGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const {
         this->onGetGLProcessorKey(caps, b);
         for (int i = 0; i < fChildProcessors.count(); ++i) {
-            fChildProcessors[i]->getGLProcessorKey(caps, b);
+            fChildProcessors[i].processor()->getGLProcessorKey(caps, b);
         }
     }
 
     int numTransforms() const { return fCoordTransforms.count(); }
 
-    int numTransformsIncludeChildProcs() const {
-        int numTransforms = fCoordTransforms.count();
-        for (int i = 0; i < fChildProcessors.count(); ++i) {
-            numTransforms += fChildProcessors[i]->numTransformsIncludeChildProcs();
-        }
-        return numTransforms;
-    }
-
     /** Returns the coordinate transformation at index. index must be valid according to
         numTransforms(). */
     const GrCoordTransform& coordTransform(int index) const { return *fCoordTransforms[index]; }
@@ -60,29 +53,16 @@
         return fCoordTransforms;
     }
 
-    /** Gather the coord transforms into an array. We use preorder traversal */
     void gatherCoordTransforms(SkTArray<const GrCoordTransform*, true>* outTransforms) const {
-        SkASSERT(outTransforms);
-        outTransforms->push_back_n(fCoordTransforms.count(), fCoordTransforms.begin());
-        for (int i = 0; i < fChildProcessors.count(); ++i) {
-            fChildProcessors[i]->gatherCoordTransforms(outTransforms);
+        if (!fCoordTransforms.empty()) {
+            outTransforms->push_back_n(fCoordTransforms.count(), fCoordTransforms.begin());
         }
     }
 
     int numChildProcessors() const { return fChildProcessors.count(); }
 
-    GrFragmentProcessor* childProcessor(int index) const { return fChildProcessors[index]; }
-
-    const SkTArray<GrFragmentProcessor*, false>& childProcessors() const {
-        return fChildProcessors;
-    }
-
-    int numTexturesIncludeChildProcs() const {
-        int numTextures = this->numTextures();
-        for (int i = 0; i < fChildProcessors.count(); ++i) {
-            numTextures += fChildProcessors[i]->numTexturesIncludeChildProcs();
-        }
-        return numTextures;
+    const GrFragmentProcessor& childProcessor(int index) const {
+        return *fChildProcessors[index].processor();
     }
 
     /** Do any of the coordtransforms for this processor require local coords? */
@@ -140,13 +120,14 @@
     void addCoordTransform(const GrCoordTransform*);
 
     /**
-     * FragmentProcessor subclasses call this to register any child FragmentProcessors they have.
+     * FragmentProcessor subclasses call this from their constructor to register any child
+     * FragmentProcessors they have.
      * This is for processors whose shader code will be composed of nested processors whose output
      * colors will be combined somehow to produce its output color.  Registering these child
-     * processors will allow the ProgramBuilder to automatically add their transformed coords and
-     * texture accesses and mangle their uniform and output color names and
+     * processors will allow the ProgramBuilder to automatically handle their transformed coords and
+     * texture accesses and mangle their uniform and output color names.
      */
-    void registerChildProcessor(GrFragmentProcessor* child);
+    int registerChildProcessor(const GrFragmentProcessor* child);
 
     /**
      * Subclass implements this to support getConstantColorComponents(...).
@@ -168,9 +149,16 @@
 
     bool hasSameTransforms(const GrFragmentProcessor&) const;
 
-    SkSTArray<4, const GrCoordTransform*, true>  fCoordTransforms;
     bool                                         fUsesLocalCoords;
-    SkTArray<GrFragmentProcessor*, false>        fChildProcessors;
+
+    /**
+     * This stores the transforms of this proc, followed by all the transforms of this proc's
+     * children. In other words, each proc stores all the transforms of its subtree.
+     * The same goes for fTextureAccesses with textures.
+     */
+    SkSTArray<4, const GrCoordTransform*, true>  fCoordTransforms;
+
+    SkTArray<GrFragmentStage, false>             fChildProcessors;
 
     typedef GrProcessor INHERITED;
 };