Fix an assert statement in SkPngCodec

allRowsCallback was asserting that
    rowNum - fFirstRow == fLinesDecoded

But it was expecting fFirstRow to be 0 (logically, it is, since we are
decoding all rows), and it never set it (because it doesn't really need
to, except for this assert). This is only a problem if we reuse an
SkPngCodec after previously scaling with it. Add a test that triggers
the assert, and fix it.
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2401133002

Review-Url: https://codereview.chromium.org/2401133002
diff --git a/tests/CodecTest.cpp b/tests/CodecTest.cpp
index 3248241..a8f8781 100644
--- a/tests/CodecTest.cpp
+++ b/tests/CodecTest.cpp
@@ -1302,3 +1302,33 @@
         }
     }
 }
+
+// This test verifies that we fixed an assert statement that fired when reusing a png codec
+// after scaling.
+DEF_TEST(Codec_reusePng, r) {
+    std::unique_ptr<SkStream> stream(GetResourceAsStream("plane.png"));
+    if (!stream) {
+        return;
+    }
+
+    std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::NewFromStream(stream.release()));
+    if (!codec) {
+        ERRORF(r, "Failed to create codec\n");
+        return;
+    }
+
+    SkAndroidCodec::AndroidOptions opts;
+    opts.fSampleSize = 5;
+    auto size = codec->getSampledDimensions(opts.fSampleSize);
+    auto info = codec->getInfo().makeWH(size.fWidth, size.fHeight).makeColorType(kN32_SkColorType);
+    SkBitmap bm;
+    bm.allocPixels(info);
+    auto result = codec->getAndroidPixels(info, bm.getPixels(), bm.rowBytes(), &opts);
+    REPORTER_ASSERT(r, result == SkCodec::kSuccess);
+
+    info = codec->getInfo().makeColorType(kN32_SkColorType);
+    bm.allocPixels(info);
+    opts.fSampleSize = 1;
+    result = codec->getAndroidPixels(info, bm.getPixels(), bm.rowBytes(), &opts);
+    REPORTER_ASSERT(r, result == SkCodec::kSuccess);
+}