change old picture serialization to really handle images

BUG=skia:3965

Review URL: https://codereview.chromium.org/1199473002
diff --git a/src/core/SkPictureRecord.cpp b/src/core/SkPictureRecord.cpp
index c85af90..018da0b 100644
--- a/src/core/SkPictureRecord.cpp
+++ b/src/core/SkPictureRecord.cpp
@@ -96,6 +96,8 @@
         1,  // DRAW_PATCH - right after op code
         1,  // DRAW_PICTURE_MATRIX_PAINT - right after op code
         1,  // DRAW_TEXT_BLOB- right after op code
+        1,  // DRAW_IMAGE - right after op code
+        1,  // DRAW_IMAGE_RECT - right after op code
     };
 
     SK_COMPILE_ASSERT(sizeof(gPaintOffsets) == LAST_DRAWTYPE_ENUM + 1,
@@ -566,18 +568,34 @@
 
 void SkPictureRecord::onDrawImage(const SkImage* image, SkScalar x, SkScalar y,
                                   const SkPaint* paint) {
-    SkBitmap bm;
-    if (as_IB(image)->getROPixels(&bm)) {
-        this->SkPictureRecord::onDrawBitmap(bm, x, y, paint);
-    }
+    // op + paint_index + image_index + x + y
+    size_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar);
+    size_t initialOffset = this->addDraw(DRAW_IMAGE, &size);
+    SkASSERT(initialOffset+get_paint_offset(DRAW_IMAGE, size) == fWriter.bytesWritten());
+    this->addPaintPtr(paint);
+    this->addImage(image);
+    this->addScalar(x);
+    this->addScalar(y);
+    this->validate(initialOffset, size);
 }
 
 void SkPictureRecord::onDrawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
                                       const SkPaint* paint) {
-    SkBitmap bm;
-    if (as_IB(image)->getROPixels(&bm)) {
-        this->SkPictureRecord::onDrawBitmapRect(bm, src, dst, paint, kNone_DrawBitmapRectFlag);
+    // id + paint_index + bitmap_index + bool_for_src
+    size_t size = 4 * kUInt32Size;
+    if (src) {
+        size += sizeof(*src);   // + rect
     }
+    size += sizeof(dst);        // + rect
+    
+    size_t initialOffset = this->addDraw(DRAW_IMAGE_RECT, &size);
+    SkASSERT(initialOffset+get_paint_offset(DRAW_IMAGE_RECT, size)
+             == fWriter.bytesWritten());
+    this->addPaintPtr(paint);
+    this->addImage(image);
+    this->addRectPtr(src);  // may be null
+    this->addRect(dst);
+    this->validate(initialOffset, size);
 }
 
 void SkPictureRecord::onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
@@ -892,6 +910,16 @@
     this->addInt(fBitmaps.count()-1);  // Remember, 0-based.
 }
 
+void SkPictureRecord::addImage(const SkImage* image) {
+    int index = fImageRefs.find(image);
+    if (index >= 0) {
+        this->addInt(index);
+    } else {
+        *fImageRefs.append() = SkRef(image);
+        this->addInt(fImageRefs.count()-1);
+    }
+}
+
 void SkPictureRecord::addMatrix(const SkMatrix& matrix) {
     fWriter.writeMatrix(matrix);
 }