Consolidate decoding frames into SkCodec

Add a new private method to SkCodec that handles Options.fFrameIndex:
- Check to ensure the index is valid
- Call onGetFrameCount to force parsing the stream
- Recursively call getPixels (it should be complete, so no need for
  incremental decoding) to decode the prior frame if necessary
- Zero fill a RestoreBGColor frame

Call the method in getPixels and startIncrementalDecode, and remove
duplicate code from GIF and WEBP.

Remove support for scaling frames beyond the first, which is currently
unused.

Preserve the feature of SkGifCodec that it will only parse to the end
of the first frame if the first frame is asked for. (Also note that
when we continue a partial frame, we won't force parsing the full
stream.) If the client only wants the first frame, parsing the rest
would be unnecessary. But if the client wants the second, we assume
they will want any remaining frames, so we parse the remainder of the
stream. This simplifies the code (so SkCodec does not have to ask its
subclass to parse up to a particular frame).

Update tests that relied on the old behavior:
- Codec_partialAnim now hardcodes the bytes needed. Previously it
  relied on the old behavior that GIF only parsed up to the frame being
  decoded.
- Codec_skipFullParse now only tests the first frame, since that is the
  case where it is important to skip a full parse.

TBR=reed@google.com
No changes to the public API.

Change-Id: Ic2f075452dfeedb4e3e60e6cf4df33ee7bd38495
Reviewed-on: https://skia-review.googlesource.com/19276
Reviewed-by: Leon Scroggins <scroggo@google.com>
Reviewed-by: Matt Sarett <msarett@google.com>
Commit-Queue: Leon Scroggins <scroggo@google.com>
diff --git a/tests/CodecTest.cpp b/tests/CodecTest.cpp
index f839aaa..04c5a08 100644
--- a/tests/CodecTest.cpp
+++ b/tests/CodecTest.cpp
@@ -1254,8 +1254,8 @@
             bm.getPixels(), bm.rowBytes(), &opts, nullptr, nullptr));
 }
 
-// For an animated image, we should only read enough to decode the requested
-// frame if the client never calls getFrameInfo.
+// For an animated GIF, we should only read enough to decode frame 0 if the
+// client never calls getFrameInfo and only decodes frame 0.
 DEF_TEST(Codec_skipFullParse, r) {
     auto path = "test640x479.gif";
     SkStream* stream(GetResourceAsStream(path));
@@ -1282,26 +1282,10 @@
     REPORTER_ASSERT(r, positionAfterFirstFrame > sizePosition
                        && positionAfterFirstFrame < stream->getLength());
 
-    // Again, this should read more of the stream.
-    decode_frame(r, codec.get(), 2);
-    const size_t positionAfterThirdFrame = stream->getPosition();
-    REPORTER_ASSERT(r, positionAfterThirdFrame > positionAfterFirstFrame
-                       && positionAfterThirdFrame < stream->getLength());
-
-    // This does not need to read any more of the stream, since it has already
-    // parsed the second frame.
-    decode_frame(r, codec.get(), 1);
-    REPORTER_ASSERT(r, stream->getPosition() == positionAfterThirdFrame);
-
-    // This should read the rest of the frames.
-    decode_frame(r, codec.get(), 3);
-    const size_t finalPosition = stream->getPosition();
-    REPORTER_ASSERT(r, finalPosition > positionAfterThirdFrame);
-
-    // There may be more data in the stream.
+    // There is more data in the stream.
     auto frameInfo = codec->getFrameInfo();
     REPORTER_ASSERT(r, frameInfo.size() == 4);
-    REPORTER_ASSERT(r, stream->getPosition() >= finalPosition);
+    REPORTER_ASSERT(r, stream->getPosition() > positionAfterFirstFrame);
 }
 
 // Only rewinds up to a limit.