SkImage_Raster's pixels are always immutable.

To make this work, we tag their pixelrefs as temporarily immutable, allowing
ourselves to restore the pixels to mutability only when the image drops away.

This should allow us to wobble back and forth between writing to the Surface
and reading from the Image without a COW, with the Surface seeing mutable
pixels and the Image seeing immutable pixels.

The big idea is, Image doesn't need forever-immutable pixels, it just needs
pixels that are immutable as long as it's alive.

BUG=skia:

patch from issue 804523002 at patchset 40001 (http://crrev.com/804523002#ps40001)

Review URL: https://codereview.chromium.org/1254383006
diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp
index 41198c0..bde4c34 100644
--- a/src/image/SkImage_Raster.cpp
+++ b/src/image/SkImage_Raster.cpp
@@ -87,10 +87,13 @@
         if (lockPixels) {
             fBitmap.lockPixels();
         }
+        SkASSERT(fBitmap.isImmutable());
     }
 
 private:
-    SkImage_Raster() : INHERITED(0, 0, NULL) {}
+    SkImage_Raster() : INHERITED(0, 0, NULL) {
+        fBitmap.setImmutable();
+    }
 
     SkBitmap    fBitmap;
 
@@ -123,6 +126,7 @@
     fBitmap.setInfo(info, rowBytes);
     fBitmap.setPixelRef(pr, pixelRefOrigin);
     fBitmap.lockPixels();
+    SkASSERT(fBitmap.isImmutable());
 }
 
 SkImage_Raster::~SkImage_Raster() {}
@@ -232,8 +236,8 @@
     return SkNEW_ARGS(SkImage_Raster, (info, pr, pixelRefOrigin, rowBytes, props));
 }
 
-SkImage* SkNewImageFromRasterBitmap(const SkBitmap& bm, bool forceSharePixelRef,
-                                    const SkSurfaceProps* props, SharedPixelRefMode mode) {
+SkImage* SkNewImageFromRasterBitmap(const SkBitmap& bm, const SkSurfaceProps* props,
+                                    SharedPixelRefMode mode, ForceCopyMode forceCopy) {
     SkASSERT(NULL == bm.getTexture());
 
     if (!SkImage_Raster::ValidArgs(bm.info(), bm.rowBytes(), NULL, NULL)) {
@@ -241,9 +245,7 @@
     }
 
     SkImage* image = NULL;
-    if (forceSharePixelRef || bm.isImmutable()) {
-        image = SkNEW_ARGS(SkImage_Raster, (bm, props, kLocked_SharedPixelRefMode == mode));
-    } else {
+    if (kYes_ForceCopyMode == forceCopy || !bm.isImmutable()) {
         SkBitmap tmp(bm);
         tmp.lockPixels();
         if (tmp.getPixels()) {
@@ -255,6 +257,8 @@
         if (image && props) {
             as_IB(image)->initWithProps(*props);
         }
+    } else {
+        image = SkNEW_ARGS(SkImage_Raster, (bm, props, kLocked_SharedPixelRefMode == mode));
     }
     return image;
 }