Keep scaledHeight calculation across oID calls

Prior to this commit, scaledHeight was only computed for the first
onIncrementalDecode call, and if y-sampling was requested, forgotten for
subsequent calls.

Bug: skia:8235
Change-Id: I87e8c2ba1b6a07b589841b0d7fbe9325f6bad76f
Reviewed-on: https://skia-review.googlesource.com/c/191880
Reviewed-by: Leon Scroggins <scroggo@google.com>
Commit-Queue: Leon Scroggins <scroggo@google.com>
diff --git a/src/codec/SkWuffsCodec.cpp b/src/codec/SkWuffsCodec.cpp
index 8384c1c..d9bd7c1 100644
--- a/src/codec/SkWuffsCodec.cpp
+++ b/src/codec/SkWuffsCodec.cpp
@@ -210,6 +210,7 @@
     size_t   fIncrDecRowBytes;
 
     std::unique_ptr<SkSwizzler> fSwizzler;
+    int                         fScaledHeight;
     SkPMColor                   fColorTable[256];
     bool                        fColorTableFilled;
 
@@ -330,6 +331,7 @@
       fIncrDecDst(nullptr),
       fIncrDecRowBytes(0),
       fSwizzler(nullptr),
+      fScaledHeight(0),
       fColorTableFilled(false),
       fNumFullyReceivedFrames(0),
       fFramesComplete(false),
@@ -392,6 +394,7 @@
 
     fSpySampler.reset();
     fSwizzler = nullptr;
+    fScaledHeight = 0;
     fColorTableFilled = false;
 
     const char* status = this->decodeFrameConfig();
@@ -474,15 +477,18 @@
                                      this->options(), &bounds);
         fSwizzler->setSampleX(fSpySampler.sampleX());
         fSwizzler->setSampleY(fSpySampler.sampleY());
-        scaledHeight = get_scaled_dimension(dstInfo().height(), fSpySampler.sampleY());
+        fScaledHeight = get_scaled_dimension(dstInfo().height(), fSpySampler.sampleY());
 
         // If the frame rect does not fill the output, ensure that those pixels are not
         // left uninitialized.
         if (independent && (bounds != this->bounds() || dirty_rect.is_empty())) {
-            auto fillInfo = dstInfo().makeWH(fSwizzler->fillWidth(), scaledHeight);
+            auto fillInfo = dstInfo().makeWH(fSwizzler->fillWidth(), fScaledHeight);
             SkSampler::Fill(fillInfo, fIncrDecDst, fIncrDecRowBytes, options().fZeroInitialized);
         }
     }
+    if (fScaledHeight == 0) {
+        return SkCodec::kInternalError;
+    }
 
     // The semantics of *rowsDecoded is: say you have a 10 pixel high image
     // (both the frame and the image). If you only decoded the first 3 rows,
@@ -499,10 +505,10 @@
     // do anything.
     //
     // Similarly, if the output is scaled, we zero-initialized all
-    // |scaledHeight| rows (the scaled image height), so we inform the caller
+    // |fScaledHeight| rows (the scaled image height), so we inform the caller
     // that it doesn't need to do anything.
     if (rowsDecoded) {
-        *rowsDecoded = scaledHeight;
+        *rowsDecoded = fScaledHeight;
     }
 
     // If the frame's dirty rect is empty, no need to swizzle.
@@ -530,7 +536,7 @@
                     continue;
                 }
                 dstY /= sampleY;
-                if (dstY >= scaledHeight) {
+                if (dstY >= fScaledHeight) {
                     break;
                 }
             }