New API for encoding bitmaps during serialization.

This change gives more flexibility to the implementation of
EncodeBitmap to prefer calling refEncodedData, doing its own
encode, or even doing both and making a decision about which
to use.

The new function signature also allows the implementation to
tell the ordered write buffer whether to store the pixel offset,
in the case where the encoded bitmap represents the larger
bitmap, or to ignore the pixel offset, in the case where the
implementation only encoded the subset that is used.

Requires changes to chromium to use the new function signature.
(https://codereview.chromium.org/15496006/)

SkPicture:
New API for EncodeBitmap.

SkOrderedReadBuffer:
Ifdef'd out addition of reading the offset.

SkOrderedWriteBuffer:
Never call refEncodedData. Allow the user to call that from their
EncodeBitmap function, if desired.
This addresses https://code.google.com/p/skia/issues/detail?id=1239
Add in ifdef'd out code to record the offset.

PictureTest and PictureRenderer:
Implement the new definition of EncodeBitmap. Also update the name
of the function to meet coding style guidelines.

BUG=https://code.google.com/p/skia/issues/detail?id=1239
R=reed@google.com

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

git-svn-id: http://skia.googlecode.com/svn/trunk@9226 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp
index fe4255d..a258087 100644
--- a/src/core/SkBitmap.cpp
+++ b/src/core/SkBitmap.cpp
@@ -837,7 +837,7 @@
  *  Also note that (x, y) may be outside the range of (0 - width(), 0 - height()), so long as it is
  *  within the bounds of the SkPixelRef being used.
  */
-static size_t getSubOffset(const SkBitmap& bm, int x, int y) {
+static size_t get_sub_offset(const SkBitmap& bm, int x, int y) {
     switch (bm.getConfig()) {
         case SkBitmap::kA8_Config:
         case SkBitmap:: kIndex8_Config:
@@ -866,18 +866,18 @@
  *  upper left corner of bm relative to its SkPixelRef.
  *  x and y must be non-NULL.
  */
-static bool getUpperLeftFromOffset(const SkBitmap& bm, int32_t* x, int32_t* y) {
+bool get_upper_left_from_offset(SkBitmap::Config config, size_t offset, size_t rowBytes,
+                                   int32_t* x, int32_t* y) {
     SkASSERT(x != NULL && y != NULL);
-    const size_t offset = bm.pixelRefOffset();
     if (0 == offset) {
         *x = *y = 0;
         return true;
     }
     // Use integer division to find the correct y position.
-    *y = SkToS32(offset / bm.rowBytes());
-    // The remainder will be the x position, after we reverse getSubOffset.
-    *x = SkToS32(offset % bm.rowBytes());
-    switch (bm.getConfig()) {
+    *y = SkToS32(offset / rowBytes);
+    // The remainder will be the x position, after we reverse get_sub_offset.
+    *x = SkToS32(offset % rowBytes);
+    switch (config) {
         case SkBitmap::kA8_Config:
             // Fall through.
         case SkBitmap::kIndex8_Config:
@@ -904,6 +904,10 @@
     return true;
 }
 
+static bool get_upper_left_from_offset(const SkBitmap& bm, int32_t* x, int32_t* y) {
+    return get_upper_left_from_offset(bm.config(), bm.pixelRefOffset(), bm.rowBytes(), x, y);
+}
+
 bool SkBitmap::extractSubset(SkBitmap* result, const SkIRect& subset) const {
     SkDEBUGCODE(this->validate();)
 
@@ -965,7 +969,7 @@
     SkASSERT(static_cast<unsigned>(r.fLeft) < static_cast<unsigned>(this->width()));
     SkASSERT(static_cast<unsigned>(r.fTop) < static_cast<unsigned>(this->height()));
 
-    size_t offset = getSubOffset(*this, r.fLeft, r.fTop);
+    size_t offset = get_sub_offset(*this, r.fLeft, r.fTop);
     if (SUB_OFFSET_FAILURE == offset) {
         return false;   // config not supported
     }
@@ -1032,7 +1036,7 @@
 
     if (fPixelRef) {
         SkIRect subset;
-        if (getUpperLeftFromOffset(*this, &subset.fLeft, &subset.fTop)) {
+        if (get_upper_left_from_offset(*this, &subset.fLeft, &subset.fTop)) {
             subset.fRight = subset.fLeft + fWidth;
             subset.fBottom = subset.fTop + fHeight;
             if (fPixelRef->readPixels(&tmpSrc, &subset)) {
@@ -1144,10 +1148,10 @@
                 // Find the correct offset in the new config. This needs to be done after calling
                 // setConfig so dst's fConfig and fRowBytes have been set properly.
                 int32_t x, y;
-                if (!getUpperLeftFromOffset(*this, &x, &y)) {
+                if (!get_upper_left_from_offset(*this, &x, &y)) {
                     return false;
                 }
-                pixelRefOffset = getSubOffset(*dst, x, y);
+                pixelRefOffset = get_sub_offset(*dst, x, y);
                 if (SUB_OFFSET_FAILURE == pixelRefOffset) {
                     return false;
                 }