Create SkLayerRasterizer w/o destroying Builder.

Add a new method to SkLayerRasterizer::Builder that creates a new
SkLayerRasterizer without destroying the Builder. Necessary to
continue to support Android's API.

Also fix a bug where creating a Builder and never calling
detachRasterizer results in not calling the destructor for any SkPaints
in the Builder.

Add tests.

BUG=b/13729784
R=reed@google.com, dominikg@chromium.org

Author: scroggo@google.com

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

git-svn-id: http://skia.googlecode.com/svn/trunk@14139 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/effects/SkLayerRasterizer.h b/include/effects/SkLayerRasterizer.h
index fdfb179..fc21a7c 100644
--- a/include/effects/SkLayerRasterizer.h
+++ b/include/effects/SkLayerRasterizer.h
@@ -39,10 +39,26 @@
 
         /**
           *  Pass queue of layers on to newly created layer rasterizer and return it. The builder
-          *  cannot be used any more after calling this function.
+          *  *cannot* be used any more after calling this function.
+          *
+          *  The caller is responsible for calling unref() on the returned object.
           */
         SkLayerRasterizer* detachRasterizer();
 
+        /**
+          *  Create and return a new immutable SkLayerRasterizer that contains a shapshot of the
+          *  layers that were added to the Builder, without modifying the Builder. The Builder
+          *  *may* be used after calling this function. It will continue to hold any layers
+          *  previously added, so consecutive calls to this function will return identical objects,
+          *  and objects returned by future calls to this function contain all the layers in
+          *  previously returned objects.
+          *
+          *  Future calls to addLayer will not affect rasterizers previously returned by this call.
+          *
+          *  The caller is responsible for calling unref() on the returned object.
+          */
+        SkLayerRasterizer* snapshotRasterizer() const;
+
     private:
         SkDeque* fLayers;
     };
@@ -86,6 +102,8 @@
 
     static SkDeque* ReadLayers(SkReadBuffer& buffer);
 
+    friend class LayerRasterizerTester;
+
     typedef SkRasterizer INHERITED;
 };