Avoid heap allocation in SkPictureStateTree constructor

This makes empty state trees cheaper. ~1% improvement on rasterize_and_record_micro.key_silk_cases on Android.

BUG=1772
R=tomhudson@chromium.org, tomhudson@google.com

Author: skyostil@chromium.org

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

git-svn-id: http://skia.googlecode.com/svn/trunk@12616 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/core/SkPictureStateTree.cpp b/src/core/SkPictureStateTree.cpp
index 5f4ed934..2f3b943 100644
--- a/src/core/SkPictureStateTree.cpp
+++ b/src/core/SkPictureStateTree.cpp
@@ -11,19 +11,16 @@
 
 SkPictureStateTree::SkPictureStateTree()
     : fAlloc(2048)
-    , fRoot(NULL)
     , fLastRestoredNode(NULL)
     , fStateStack(sizeof(Draw), 16) {
-    SkMatrix* identity = static_cast<SkMatrix*>(fAlloc.allocThrow(sizeof(SkMatrix)));
-    identity->reset();
-    fRoot = static_cast<Node*>(fAlloc.allocThrow(sizeof(Node)));
-    fRoot->fParent = NULL;
-    fRoot->fMatrix = identity;
-    fRoot->fFlags = Node::kSave_Flag;
-    fRoot->fOffset = 0;
-    fRoot->fLevel = 0;
-    fCurrentState.fNode = fRoot;
-    fCurrentState.fMatrix = identity;
+    fRootMatrix.reset();
+    fRoot.fParent = NULL;
+    fRoot.fMatrix = &fRootMatrix;
+    fRoot.fFlags = Node::kSave_Flag;
+    fRoot.fOffset = 0;
+    fRoot.fLevel = 0;
+    fCurrentState.fNode = &fRoot;
+    fCurrentState.fMatrix = &fRootMatrix;
     *static_cast<Draw*>(fStateStack.push_back()) = fCurrentState;
 }
 
@@ -78,7 +75,7 @@
 
 SkPictureStateTree::Iterator SkPictureStateTree::getIterator(const SkTDArray<void*>& draws,
                                                              SkCanvas* canvas) {
-    return Iterator(draws, canvas, fRoot);
+    return Iterator(draws, canvas, &fRoot);
 }
 
 void SkPictureStateTree::appendNode(uint32_t offset) {
diff --git a/src/core/SkPictureStateTree.h b/src/core/SkPictureStateTree.h
index 9d8bcf8..8752958 100644
--- a/src/core/SkPictureStateTree.h
+++ b/src/core/SkPictureStateTree.h
@@ -115,7 +115,6 @@
     void appendNode(uint32_t offset);
 
     SkChunkAlloc fAlloc;
-    Node* fRoot;
     // Needed by saveCollapsed() because nodes do not currently store
     // references to their children.  If they did, we could just retrieve the
     // last added child.
@@ -140,6 +139,9 @@
         };
     };
 
+    Node fRoot;
+    SkMatrix fRootMatrix;
+
     typedef SkRefCnt INHERITED;
 };