heif: Update to actual frame duration when the frame is decoded

bug: 139815242
test: test some 25fps files, and with local logs, duration should
      show 40ms instead of the default 33ms.

Change-Id: Ibd10bda17634b1337349bfc9f69757f569d35972
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/237205
Commit-Queue: Chong Zhang <chz@google.com>
Commit-Queue: Leon Scroggins <scroggo@google.com>
Auto-Submit: Chong Zhang <chz@google.com>
Reviewed-by: Leon Scroggins <scroggo@google.com>
diff --git a/src/codec/SkHeifCodec.cpp b/src/codec/SkHeifCodec.cpp
index ae452c4..de51f1b 100644
--- a/src/codec/SkHeifCodec.cpp
+++ b/src/codec/SkHeifCodec.cpp
@@ -283,7 +283,6 @@
             Frame* frame = fFrameHolder.appendNewFrame();
             frame->setXYWH(0, 0, frameInfo.mWidth, frameInfo.mHeight);
             frame->setDisposalMethod(SkCodecAnimation::DisposalMethod::kKeep);
-            // TODO: fill in per-frame durations
             // Currently we don't know the duration until the frame is actually
             // decoded (onGetFrameInfo is also called before frame is decoded).
             // For now, fill it base on the value reported for the sequence.
@@ -311,6 +310,11 @@
     return &fFrames[i];
 }
 
+SkHeifCodec::Frame* SkHeifCodec::FrameHolder::editFrameAt(int i) {
+    SkASSERT(i >= 0 && i < this->size());
+    return &fFrames[i];
+}
+
 bool SkHeifCodec::onGetFrameInfo(int i, FrameInfo* frameInfo) const {
     if (i >= fFrameHolder.size()) {
         return false;
@@ -353,6 +357,8 @@
     bool success;
     if (fUseAnimation) {
         success = fHeifDecoder->decodeSequence(options.fFrameIndex, &fFrameInfo);
+        fFrameHolder.editFrameAt(options.fFrameIndex)->setDuration(
+                fFrameInfo.mDurationUs / 1000);
     } else {
         success = fHeifDecoder->decode(&fFrameInfo);
     }