Make WebP decoding independent of stream length.

There's a case in Android, when the SkStream passed to WebP decoder may have
incorrect length (stream->getLength()). This is observed, if the App decodes
an image (size > 80KB) using: 'ParcelFileDescriptor --> BitmapFactory.decodeStream()'.
This CL updates the WebP incremental decoding loop to not rely on stream->getLength().

R=scroggo@google.com, vikasa@google.com

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

git-svn-id: http://skia.googlecode.com/svn/trunk@10651 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/images/SkImageDecoder_libwebp.cpp b/src/images/SkImageDecoder_libwebp.cpp
index b0fa7f7..4b5081b 100644
--- a/src/images/SkImageDecoder_libwebp.cpp
+++ b/src/images/SkImageDecoder_libwebp.cpp
@@ -203,31 +203,27 @@
         return false;
     }
 
-    uint32_t bytesRemaining = contentSize;
-    while (bytesRemaining > 0) {
-        const uint32_t bytesToRead = (bytesRemaining < WEBP_IDECODE_BUFFER_SZ) ?
-                                      bytesRemaining : WEBP_IDECODE_BUFFER_SZ;
+    bool success = true;
+    VP8StatusCode status = VP8_STATUS_SUSPENDED;
+    do {
+        const uint32_t bytesToRead = WEBP_IDECODE_BUFFER_SZ;
         const size_t bytesRead = stream->read(input, bytesToRead);
         if (0 == bytesRead) {
+            success = false;
             break;
         }
 
-        VP8StatusCode status = WebPIAppend(idec, input, bytesRead);
-        if (VP8_STATUS_OK == status || VP8_STATUS_SUSPENDED == status) {
-            bytesRemaining -= bytesRead;
-        } else {
+        status = WebPIAppend(idec, input, bytesRead);
+        if (VP8_STATUS_OK != status && VP8_STATUS_SUSPENDED != status) {
+            success = false;
             break;
         }
-    }
+    } while (VP8_STATUS_OK != status);
     srcStorage.free();
     WebPIDelete(idec);
     WebPFreeDecBuffer(&config->output);
 
-    if (bytesRemaining > 0) {
-        return false;
-    } else {
-        return true;
-    }
+    return success;
 }
 
 static bool webp_get_config_resize(WebPDecoderConfig* config,