[rust png] Devirtualize all methods of `ProgressiveDecoderIface`.

This CL removes all `virtual` methods of `ProgressiveDecoderIface`.
Virtual calls from `ProgressiveDecoder::ReadMoreData` are hoisted into
its callers (e.g. into `BmpReadMoreData`) and made directly, without
relying on virtual dispatch (since `BmpReadMoreData` doesn't need to
consult a virtual dispatch table to know that it needs to call
`BmpDecoder::GetAvailInput` or `BmpDecoder::Input`).

This refactoring is motivated by:

1. Desire to remove the calls to `ReadBlockAtOffset` from
   `PngDetectImageTypeInBuffer` and `PngContinueDecode`.  This relies on
   the new shape of `ReadMoreData` - it needs to be
   `ProgressiveDecoderIface`-agnostic, because PNG decoders also are.
   See also https://pdfium-review.googlesource.com/137291 which
   introduces `ProgressiveDecoder::PngReadMoreData`.
2. Desire to simplify code by removing the overhead and complexity of
   having an extra layer of indirection when calling to decoder methods.

Bug: 444045690
Change-Id: I4a04446895e969fc533f2ac3a1b6a45798685974
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/137290
Commit-Queue: Lei Zhang <thestig@chromium.org>
Auto-Submit: Ɓukasz Anforowicz <lukasza@google.com>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxcodec/BUILD.gn b/core/fxcodec/BUILD.gn
index a484ce6..e1ac45e 100644
--- a/core/fxcodec/BUILD.gn
+++ b/core/fxcodec/BUILD.gn
@@ -95,8 +95,6 @@
       sources += [
         "bmp/bmp_decoder.cpp",
         "bmp/bmp_decoder.h",
-        "bmp/bmp_progressive_decoder.cpp",
-        "bmp/bmp_progressive_decoder.h",
         "bmp/cfx_bmpcontext.cpp",
         "bmp/cfx_bmpcontext.h",
         "bmp/cfx_bmpdecompressor.cpp",
@@ -112,8 +110,6 @@
         "gif/cfx_gifcontext.h",
         "gif/gif_decoder.cpp",
         "gif/gif_decoder.h",
-        "gif/gif_progressive_decoder.cpp",
-        "gif/gif_progressive_decoder.h",
         "gif/lzw_decompressor.cpp",
         "gif/lzw_decompressor.h",
       ]
diff --git a/core/fxcodec/bmp/bmp_decoder.h b/core/fxcodec/bmp/bmp_decoder.h
index 0a619a7..8774bbe 100644
--- a/core/fxcodec/bmp/bmp_decoder.h
+++ b/core/fxcodec/bmp/bmp_decoder.h
@@ -7,10 +7,14 @@
 #ifndef CORE_FXCODEC_BMP_BMP_DECODER_H_
 #define CORE_FXCODEC_BMP_BMP_DECODER_H_
 
+#include <stdint.h>
+
 #include <memory>
 
+#include "core/fxcodec/cfx_codec_memory.h"
 #include "core/fxcodec/progressive_decoder_iface.h"
 #include "core/fxcrt/fx_system.h"
+#include "core/fxcrt/fx_types.h"
 #include "core/fxcrt/retain_ptr.h"
 #include "core/fxcrt/span.h"
 #include "core/fxge/dib/fx_dib.h"
@@ -48,6 +52,7 @@
   static bool Input(ProgressiveDecoderIface::Context* pContext,
                     RetainPtr<CFX_CodecMemory> codec_memory);
 
+  // Only `static` methods.
   BmpDecoder() = delete;
   BmpDecoder(const BmpDecoder&) = delete;
   BmpDecoder& operator=(const BmpDecoder&) = delete;
diff --git a/core/fxcodec/bmp/bmp_progressive_decoder.cpp b/core/fxcodec/bmp/bmp_progressive_decoder.cpp
deleted file mode 100644
index 3c1d43a..0000000
--- a/core/fxcodec/bmp/bmp_progressive_decoder.cpp
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright 2020 The PDFium Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "core/fxcodec/bmp/bmp_progressive_decoder.h"
-
-#include "core/fxcodec/bmp/bmp_decoder.h"
-#include "core/fxcodec/cfx_codec_memory.h"
-#include "core/fxcrt/check.h"
-
-namespace fxcodec {
-
-namespace {
-
-BmpProgressiveDecoder* g_bmp_decoder = nullptr;
-
-}  // namespace
-
-// static
-void BmpProgressiveDecoder::InitializeGlobals() {
-  CHECK(!g_bmp_decoder);
-  g_bmp_decoder = new BmpProgressiveDecoder();
-}
-
-// static
-void BmpProgressiveDecoder::DestroyGlobals() {
-  delete g_bmp_decoder;
-  g_bmp_decoder = nullptr;
-}
-
-// static
-BmpProgressiveDecoder* BmpProgressiveDecoder::GetInstance() {
-  return g_bmp_decoder;
-}
-
-BmpProgressiveDecoder::BmpProgressiveDecoder() = default;
-
-BmpProgressiveDecoder::~BmpProgressiveDecoder() = default;
-
-FX_FILESIZE BmpProgressiveDecoder::GetAvailInput(Context* context) const {
-  return BmpDecoder::GetAvailInput(context);
-}
-
-bool BmpProgressiveDecoder::Input(Context* context,
-                                  RetainPtr<CFX_CodecMemory> codec_memory) {
-  return BmpDecoder::Input(context, codec_memory);
-}
-
-}  // namespace fxcodec
diff --git a/core/fxcodec/bmp/bmp_progressive_decoder.h b/core/fxcodec/bmp/bmp_progressive_decoder.h
deleted file mode 100644
index 865e112..0000000
--- a/core/fxcodec/bmp/bmp_progressive_decoder.h
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright 2020 The PDFium Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef CORE_FXCODEC_BMP_BMP_PROGRESSIVE_DECODER_H_
-#define CORE_FXCODEC_BMP_BMP_PROGRESSIVE_DECODER_H_
-
-#include "core/fxcodec/progressive_decoder_iface.h"
-
-#ifndef PDF_ENABLE_XFA_BMP
-#error "BMP must be enabled"
-#endif
-
-namespace fxcodec {
-
-class BmpProgressiveDecoder final : public ProgressiveDecoderIface {
- public:
-  static void InitializeGlobals();
-  static void DestroyGlobals();
-
-  static BmpProgressiveDecoder* GetInstance();
-
-  // ProgressiveDecoderIface:
-  FX_FILESIZE GetAvailInput(Context* context) const override;
-  bool Input(Context* context,
-             RetainPtr<CFX_CodecMemory> codec_memory) override;
-
- private:
-  BmpProgressiveDecoder();
-  ~BmpProgressiveDecoder() override;
-};
-
-}  // namespace fxcodec
-
-using BmpProgressiveDecoder = fxcodec::BmpProgressiveDecoder;
-
-#endif  // CORE_FXCODEC_BMP_BMP_PROGRESSIVE_DECODER_H_
diff --git a/core/fxcodec/gif/gif_decoder.h b/core/fxcodec/gif/gif_decoder.h
index ef106af..73c1b9f 100644
--- a/core/fxcodec/gif/gif_decoder.h
+++ b/core/fxcodec/gif/gif_decoder.h
@@ -7,12 +7,16 @@
 #ifndef CORE_FXCODEC_GIF_GIF_DECODER_H_
 #define CORE_FXCODEC_GIF_GIF_DECODER_H_
 
+#include <stdint.h>
+
 #include <memory>
 #include <utility>
 
+#include "core/fxcodec/cfx_codec_memory.h"
 #include "core/fxcodec/gif/cfx_gif.h"
 #include "core/fxcodec/progressive_decoder_iface.h"
 #include "core/fxcrt/fx_coordinates.h"
+#include "core/fxcrt/fx_types.h"
 #include "core/fxcrt/span.h"
 
 #ifndef PDF_ENABLE_XFA_GIF
@@ -55,6 +59,7 @@
   static bool Input(ProgressiveDecoderIface::Context* context,
                     RetainPtr<CFX_CodecMemory> codec_memory);
 
+  // Only `static` methods.
   GifDecoder() = delete;
   GifDecoder(const GifDecoder&) = delete;
   GifDecoder& operator=(const GifDecoder&) = delete;
diff --git a/core/fxcodec/gif/gif_progressive_decoder.cpp b/core/fxcodec/gif/gif_progressive_decoder.cpp
deleted file mode 100644
index 46de8d3..0000000
--- a/core/fxcodec/gif/gif_progressive_decoder.cpp
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright 2020 The PDFium Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "core/fxcodec/gif/gif_progressive_decoder.h"
-
-#include "core/fxcodec/cfx_codec_memory.h"
-#include "core/fxcodec/gif/gif_decoder.h"
-#include "core/fxcrt/check.h"
-
-namespace fxcodec {
-
-namespace {
-
-GifProgressiveDecoder* g_gif_decoder = nullptr;
-
-}  // namespace
-
-// static
-void GifProgressiveDecoder::InitializeGlobals() {
-  CHECK(!g_gif_decoder);
-  g_gif_decoder = new GifProgressiveDecoder();
-}
-
-// static
-void GifProgressiveDecoder::DestroyGlobals() {
-  delete g_gif_decoder;
-  g_gif_decoder = nullptr;
-}
-
-// static
-GifProgressiveDecoder* GifProgressiveDecoder::GetInstance() {
-  return g_gif_decoder;
-}
-
-GifProgressiveDecoder::GifProgressiveDecoder() = default;
-
-GifProgressiveDecoder::~GifProgressiveDecoder() = default;
-
-FX_FILESIZE GifProgressiveDecoder::GetAvailInput(Context* context) const {
-  return GifDecoder::GetAvailInput(context);
-}
-
-bool GifProgressiveDecoder::Input(Context* context,
-                                  RetainPtr<CFX_CodecMemory> codec_memory) {
-  return GifDecoder::Input(context, codec_memory);
-}
-
-}  // namespace fxcodec
diff --git a/core/fxcodec/gif/gif_progressive_decoder.h b/core/fxcodec/gif/gif_progressive_decoder.h
deleted file mode 100644
index 52075a6..0000000
--- a/core/fxcodec/gif/gif_progressive_decoder.h
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright 2020 The PDFium Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef CORE_FXCODEC_GIF_GIF_PROGRESSIVE_DECODER_H_
-#define CORE_FXCODEC_GIF_GIF_PROGRESSIVE_DECODER_H_
-
-#include "core/fxcodec/progressive_decoder_iface.h"
-
-#ifndef PDF_ENABLE_XFA_GIF
-#error "GIF must be enabled"
-#endif
-
-namespace fxcodec {
-
-class GifProgressiveDecoder final : public ProgressiveDecoderIface {
- public:
-  static void InitializeGlobals();
-  static void DestroyGlobals();
-
-  static GifProgressiveDecoder* GetInstance();
-
-  // ProgressiveDecoderIface:
-  FX_FILESIZE GetAvailInput(Context* context) const override;
-  bool Input(Context* context,
-             RetainPtr<CFX_CodecMemory> codec_memory) override;
-
- private:
-  GifProgressiveDecoder();
-  ~GifProgressiveDecoder() override;
-};
-
-}  // namespace fxcodec
-
-using GifProgressiveDecoder = fxcodec::GifProgressiveDecoder;
-
-#endif  // CORE_FXCODEC_GIF_GIF_PROGRESSIVE_DECODER_H_
diff --git a/core/fxcodec/jpeg/jpeg_progressive_decoder.cpp b/core/fxcodec/jpeg/jpeg_progressive_decoder.cpp
index 9ca4b67..c192c84 100644
--- a/core/fxcodec/jpeg/jpeg_progressive_decoder.cpp
+++ b/core/fxcodec/jpeg/jpeg_progressive_decoder.cpp
@@ -58,29 +58,6 @@
 
 namespace fxcodec {
 
-namespace {
-
-JpegProgressiveDecoder* g_jpeg_decoder = nullptr;
-
-}  // namespace
-
-// static
-void JpegProgressiveDecoder::InitializeGlobals() {
-  CHECK(!g_jpeg_decoder);
-  g_jpeg_decoder = new JpegProgressiveDecoder();
-}
-
-// static
-void JpegProgressiveDecoder::DestroyGlobals() {
-  delete g_jpeg_decoder;
-  g_jpeg_decoder = nullptr;
-}
-
-// static
-JpegProgressiveDecoder* JpegProgressiveDecoder::GetInstance() {
-  return g_jpeg_decoder;
-}
-
 // static
 std::unique_ptr<ProgressiveDecoderIface::Context>
 JpegProgressiveDecoder::Start() {
@@ -94,11 +71,12 @@
 }
 
 // static
-int JpegProgressiveDecoder::ReadHeader(Context* pContext,
-                                       int* width,
-                                       int* height,
-                                       int* nComps,
-                                       CFX_DIBAttribute* pAttribute) {
+int JpegProgressiveDecoder::ReadHeader(
+    ProgressiveDecoderIface::Context* pContext,
+    int* width,
+    int* height,
+    int* nComps,
+    CFX_DIBAttribute* pAttribute) {
   DCHECK(pAttribute);
 
   auto* ctx = static_cast<CJpegContext*>(pContext);
@@ -120,15 +98,17 @@
 }
 
 // static
-bool JpegProgressiveDecoder::StartScanline(Context* pContext) {
+bool JpegProgressiveDecoder::StartScanline(
+    ProgressiveDecoderIface::Context* pContext) {
   auto* ctx = static_cast<CJpegContext*>(pContext);
   ctx->common_.cinfo.scale_denom = 1;
   return !!jpeg_common_start_decompress(&ctx->common_);
 }
 
 // static
-int JpegProgressiveDecoder::ReadScanline(Context* pContext,
-                                         unsigned char* dest_buf) {
+int JpegProgressiveDecoder::ReadScanline(
+    ProgressiveDecoderIface::Context* pContext,
+    unsigned char* dest_buf) {
   auto* ctx = static_cast<CJpegContext*>(pContext);
   int nlines = jpeg_common_read_scanlines(&ctx->common_, &dest_buf, 1);
   if (nlines == -1) {
@@ -137,12 +117,15 @@
   return nlines == 1 ? kOk : kError;
 }
 
-FX_FILESIZE JpegProgressiveDecoder::GetAvailInput(Context* pContext) const {
+// static
+FX_FILESIZE JpegProgressiveDecoder::GetAvailInput(
+    ProgressiveDecoderIface::Context* pContext) {
   auto* ctx = static_cast<CJpegContext*>(pContext);
   return static_cast<FX_FILESIZE>(ctx->common_.source_mgr.bytes_in_buffer);
 }
 
-bool JpegProgressiveDecoder::Input(Context* pContext,
+// static
+bool JpegProgressiveDecoder::Input(ProgressiveDecoderIface::Context* pContext,
                                    RetainPtr<CFX_CodecMemory> codec_memory) {
   pdfium::span<uint8_t> src_buf = codec_memory->GetUnconsumedSpan();
   auto* ctx = static_cast<CJpegContext*>(pContext);
@@ -160,8 +143,4 @@
   return true;
 }
 
-JpegProgressiveDecoder::JpegProgressiveDecoder() = default;
-
-JpegProgressiveDecoder::~JpegProgressiveDecoder() = default;
-
 }  // namespace fxcodec
diff --git a/core/fxcodec/jpeg/jpeg_progressive_decoder.h b/core/fxcodec/jpeg/jpeg_progressive_decoder.h
index f3e41aa..b50aab3 100644
--- a/core/fxcodec/jpeg/jpeg_progressive_decoder.h
+++ b/core/fxcodec/jpeg/jpeg_progressive_decoder.h
@@ -7,20 +7,21 @@
 #ifndef CORE_FXCODEC_JPEG_JPEG_PROGRESSIVE_DECODER_H_
 #define CORE_FXCODEC_JPEG_JPEG_PROGRESSIVE_DECODER_H_
 
+#include <stdint.h>
+
 #include <memory>
 
+#include "core/fxcodec/cfx_codec_memory.h"
 #include "core/fxcodec/progressive_decoder_iface.h"
+#include "core/fxcrt/fx_types.h"
 
 namespace fxcodec {
 
 class CFX_DIBAttribute;
 
-class JpegProgressiveDecoder final : public ProgressiveDecoderIface {
+class JpegProgressiveDecoder {
  public:
-  static void InitializeGlobals();
-  static void DestroyGlobals();
-  static JpegProgressiveDecoder* GetInstance();
-  static std::unique_ptr<Context> Start();
+  static std::unique_ptr<ProgressiveDecoderIface::Context> Start();
 
   // Result codes for ReadHeader()/ReadScanline():
   static constexpr int kFatal = -1;
@@ -28,23 +29,24 @@
   static constexpr int kError = 1;
   static constexpr int kNeedsMoreInput = 2;
 
-  static int ReadHeader(Context* pContext,
+  static int ReadHeader(ProgressiveDecoderIface::Context* pContext,
                         int* width,
                         int* height,
                         int* nComps,
                         CFX_DIBAttribute* pAttribute);
 
-  static bool StartScanline(Context* pContext);
-  static int ReadScanline(Context* pContext, uint8_t* dest_buf);
+  static bool StartScanline(ProgressiveDecoderIface::Context* pContext);
+  static int ReadScanline(ProgressiveDecoderIface::Context* pContext,
+                          uint8_t* dest_buf);
 
-  // ProgressiveDecoderIface:
-  FX_FILESIZE GetAvailInput(Context* pContext) const override;
-  bool Input(Context* pContext,
-             RetainPtr<CFX_CodecMemory> codec_memory) override;
+  static FX_FILESIZE GetAvailInput(ProgressiveDecoderIface::Context* pContext);
+  static bool Input(ProgressiveDecoderIface::Context* pContext,
+                    RetainPtr<CFX_CodecMemory> codec_memory);
 
- private:
-  JpegProgressiveDecoder();
-  ~JpegProgressiveDecoder() override;
+  // Only `static` methods.
+  JpegProgressiveDecoder() = delete;
+  JpegProgressiveDecoder(const JpegProgressiveDecoder&) = delete;
+  JpegProgressiveDecoder& operator=(const JpegProgressiveDecoder&) = delete;
 };
 
 }  // namespace fxcodec
diff --git a/core/fxcodec/png/libpng_png_decoder.h b/core/fxcodec/png/libpng_png_decoder.h
index a70a205..c1107fe 100644
--- a/core/fxcodec/png/libpng_png_decoder.h
+++ b/core/fxcodec/png/libpng_png_decoder.h
@@ -9,6 +9,7 @@
 
 #include <memory>
 
+#include "core/fxcodec/cfx_codec_memory.h"
 #include "core/fxcodec/progressive_decoder_iface.h"
 #include "core/fxcrt/retain_ptr.h"
 
diff --git a/core/fxcodec/progressive_decoder.cpp b/core/fxcodec/progressive_decoder.cpp
index d551a1f..c06d8f5 100644
--- a/core/fxcodec/progressive_decoder.cpp
+++ b/core/fxcodec/progressive_decoder.cpp
@@ -30,11 +30,11 @@
 #include "core/fxge/dib/fx_dib.h"
 
 #ifdef PDF_ENABLE_XFA_BMP
-#include "core/fxcodec/bmp/bmp_progressive_decoder.h"
+#include "core/fxcodec/bmp/bmp_decoder.h"
 #endif  // PDF_ENABLE_XFA_BMP
 
 #ifdef PDF_ENABLE_XFA_GIF
-#include "core/fxcodec/gif/gif_progressive_decoder.h"
+#include "core/fxcodec/gif/gif_decoder.h"
 #endif  // PDF_ENABLE_XFA_GIF
 
 #ifdef PDF_ENABLE_XFA_PNG
@@ -333,10 +333,22 @@
 }
 
 bool ProgressiveDecoder::BmpReadMoreData(
-    ProgressiveDecoderIface::Context* pContext,
+    ProgressiveDecoderIface::Context* bmp_context,
     FXCODEC_STATUS* err_status) {
-  return ReadMoreData(BmpProgressiveDecoder::GetInstance(), pContext,
-                      err_status);
+  // TODO(lukasza): Can this just use
+  // `codec_memory_->GetUnconsumedSpan().size()`? (IIUC this is what
+  // `GetAvailInput` uses in the end, but I haven't investigated that this is
+  // the same instance of `CFX_CodecMemory`.)
+  FX_SAFE_SIZE_T avail_input = BmpDecoder::GetAvailInput(bmp_context);
+  if (!avail_input.IsValid()) {
+    return false;
+  }
+
+  if (!ReadMoreData(avail_input.ValueOrDie(), err_status)) {
+    return false;
+  }
+
+  return BmpDecoder::Input(bmp_context, codec_memory_);
 }
 
 FXCODEC_STATUS ProgressiveDecoder::BmpStartDecode() {
@@ -374,8 +386,20 @@
 
 #ifdef PDF_ENABLE_XFA_GIF
 bool ProgressiveDecoder::GifReadMoreData(FXCODEC_STATUS* err_status) {
-  return ReadMoreData(GifProgressiveDecoder::GetInstance(), gif_context_.get(),
-                      err_status);
+  // TODO(lukasza): Can this just use
+  // `codec_memory_->GetUnconsumedSpan().size()`? (IIUC this is what
+  // `GetAvailInput` uses in the end, but I haven't investigated that this is
+  // the same instance of `CFX_CodecMemory`.)
+  FX_SAFE_SIZE_T avail_input = GifDecoder::GetAvailInput(gif_context_.get());
+  if (!avail_input.IsValid()) {
+    return false;
+  }
+
+  if (!ReadMoreData(avail_input.ValueOrDie(), err_status)) {
+    return false;
+  }
+
+  return GifDecoder::Input(gif_context_.get(), codec_memory_);
 }
 
 bool ProgressiveDecoder::GifDetectImageTypeInBuffer() {
@@ -447,8 +471,17 @@
 #endif  // PDF_ENABLE_XFA_GIF
 
 bool ProgressiveDecoder::JpegReadMoreData(FXCODEC_STATUS* err_status) {
-  return ReadMoreData(JpegProgressiveDecoder::GetInstance(),
-                      jpeg_context_.get(), err_status);
+  FX_SAFE_SIZE_T avail_input =
+      JpegProgressiveDecoder::GetAvailInput(jpeg_context_.get());
+  if (!avail_input.IsValid()) {
+    return false;
+  }
+
+  if (!ReadMoreData(avail_input.ValueOrDie(), err_status)) {
+    return false;
+  }
+
+  return JpegProgressiveDecoder::Input(jpeg_context_.get(), codec_memory_);
 }
 
 bool ProgressiveDecoder::JpegDetectImageTypeInBuffer(
@@ -458,8 +491,7 @@
     status_ = FXCODEC_STATUS::kError;
     return false;
   }
-  JpegProgressiveDecoder::GetInstance()->Input(jpeg_context_.get(),
-                                               codec_memory_);
+  JpegProgressiveDecoder::Input(jpeg_context_.get(), codec_memory_);
 
   while (1) {
     int read_result = JpegProgressiveDecoder::ReadHeader(
@@ -725,8 +757,7 @@
   return false;
 }
 
-bool ProgressiveDecoder::ReadMoreData(ProgressiveDecoderIface* decoder,
-                                      ProgressiveDecoderIface::Context* context,
+bool ProgressiveDecoder::ReadMoreData(size_t unconsumed_bytes,
                                       FXCODEC_STATUS* err_status) {
   // Check for EOF.
   if (offset_ >= static_cast<uint32_t>(file_->GetSize())) {
@@ -737,13 +768,6 @@
   uint32_t bytes_to_fetch_from_file =
       pdfium::checked_cast<uint32_t>(file_->GetSize() - offset_);
 
-  // Figure out if the codec stopped processing midway through the buffer.
-  size_t unconsumed_bytes;
-  FX_SAFE_SIZE_T avail_input = decoder->GetAvailInput(context);
-  if (!avail_input.AssignIfValid(&unconsumed_bytes)) {
-    return false;
-  }
-
   if (unconsumed_bytes == codec_memory_->GetSize()) {
     // Codec couldn't make any progress against the bytes in the buffer.
     // Increase the buffer size so that there might be enough contiguous
@@ -775,7 +799,7 @@
     return false;
   }
   offset_ += bytes_to_fetch_from_file;
-  return decoder->Input(context, codec_memory_);
+  return true;
 }
 
 FXCODEC_STATUS ProgressiveDecoder::LoadImageInfo(
diff --git a/core/fxcodec/progressive_decoder.h b/core/fxcodec/progressive_decoder.h
index 97ca5d0..7699de3 100644
--- a/core/fxcodec/progressive_decoder.h
+++ b/core/fxcodec/progressive_decoder.h
@@ -124,7 +124,7 @@
   };
 
 #ifdef PDF_ENABLE_XFA_BMP
-  bool BmpReadMoreData(ProgressiveDecoderIface::Context* pBmpContext,
+  bool BmpReadMoreData(ProgressiveDecoderIface::Context* bmp_context,
                        FXCODEC_STATUS* err_status);
   bool BmpDetectImageTypeInBuffer(CFX_DIBAttribute* pAttribute);
   FXCODEC_STATUS BmpStartDecode();
@@ -160,9 +160,17 @@
 
   bool DetectImageType(FXCODEC_IMAGE_TYPE imageType,
                        CFX_DIBAttribute* pAttribute);
-  bool ReadMoreData(ProgressiveDecoderIface* decoder,
-                    ProgressiveDecoderIface::Context* context,
-                    FXCODEC_STATUS* err_status);
+
+  // Reads more data from `file_` into `codec_memory_`.
+  //
+  // Returns `false` and sets `err_status` upon failure.
+  // Returns `true` to indicate success.
+  //
+  // Retains `unconsumed_bytes` at the end of `codec_memory_`.
+  //
+  // Reads start at `offset_` inside the file.  The `offset_` will be update as
+  // needed.
+  bool ReadMoreData(size_t unconsumed_bytes, FXCODEC_STATUS* err_status);
 
   void SetTransMethod();
 
diff --git a/core/fxcodec/progressive_decoder_iface.h b/core/fxcodec/progressive_decoder_iface.h
index a21f234..decd308 100644
--- a/core/fxcodec/progressive_decoder_iface.h
+++ b/core/fxcodec/progressive_decoder_iface.h
@@ -7,32 +7,20 @@
 #ifndef CORE_FXCODEC_PROGRESSIVE_DECODER_IFACE_H_
 #define CORE_FXCODEC_PROGRESSIVE_DECODER_IFACE_H_
 
-#include "core/fxcrt/fx_types.h"
-#include "core/fxcrt/retain_ptr.h"
-
 #ifndef PDF_ENABLE_XFA
 #error "XFA Only"
 #endif
 
-class CFX_CodecMemory;
-
 namespace fxcodec {
 
 class ProgressiveDecoderIface {
  public:
+  // TODO(https://crbug.com/444045690): Hoist the `Context` class to the
+  // top-level / delete empty `ProgressiveDecoderIface`.
   class Context {
    public:
     virtual ~Context() = default;
   };
-
-  virtual ~ProgressiveDecoderIface() = default;
-
-  // Returns the number of unprocessed bytes remaining in the input buffer.
-  virtual FX_FILESIZE GetAvailInput(Context* pContext) const = 0;
-
-  // Provides a new input buffer to the codec. Returns true on success.
-  virtual bool Input(Context* pContext,
-                     RetainPtr<CFX_CodecMemory> codec_memory) = 0;
 };
 
 }  // namespace fxcodec
diff --git a/core/fxcodec/progressive_decoder_unittest.cpp b/core/fxcodec/progressive_decoder_unittest.cpp
index 9bc29cf..9ebbe20 100644
--- a/core/fxcodec/progressive_decoder_unittest.cpp
+++ b/core/fxcodec/progressive_decoder_unittest.cpp
@@ -14,7 +14,6 @@
 
 #include "core/fxcodec/fx_codec.h"
 #include "core/fxcodec/fx_codec_def.h"
-#include "core/fxcodec/jpeg/jpeg_progressive_decoder.h"
 #include "core/fxcrt/cfx_read_only_span_stream.h"
 #include "core/fxcrt/cfx_read_only_vector_stream.h"
 #include "core/fxcrt/data_vector.h"
@@ -25,16 +24,6 @@
 #include "testing/gmock/include/gmock/gmock.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
-#ifdef PDF_ENABLE_XFA_BMP
-#include "core/fxcodec/bmp/bmp_decoder.h"
-#include "core/fxcodec/bmp/bmp_progressive_decoder.h"
-#endif  // PDF_ENABLE_XFA_BMP
-
-#ifdef PDF_ENABLE_XFA_GIF
-#include "core/fxcodec/gif/gif_decoder.h"
-#include "core/fxcodec/gif/gif_progressive_decoder.h"
-#endif  // PDF_ENABLE_XFA_GIF
-
 namespace fxcodec {
 
 namespace {
@@ -58,26 +47,7 @@
   return status;
 }
 
-class ProgressiveDecoderTest : public testing::Test {
-  void SetUp() override {
-#ifdef PDF_ENABLE_XFA_BMP
-    BmpProgressiveDecoder::InitializeGlobals();
-#endif
-#ifdef PDF_ENABLE_XFA_GIF
-    GifProgressiveDecoder::InitializeGlobals();
-#endif
-    JpegProgressiveDecoder::InitializeGlobals();
-  }
-  void TearDown() override {
-    JpegProgressiveDecoder::DestroyGlobals();
-#ifdef PDF_ENABLE_XFA_GIF
-    GifProgressiveDecoder::DestroyGlobals();
-#endif
-#ifdef PDF_ENABLE_XFA_BMP
-    BmpProgressiveDecoder::DestroyGlobals();
-#endif
-  }
-};
+using ProgressiveDecoderTest = testing::Test;
 
 }  // namespace
 
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
index c3806d3..8256efa 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
@@ -15,7 +15,6 @@
 #include "core/fpdfapi/parser/cpdf_dictionary.h"
 #include "core/fpdfapi/parser/cpdf_document.h"
 #include "core/fpdfapi/parser/cpdf_seekablemultistream.h"
-#include "core/fxcodec/jpeg/jpeg_progressive_decoder.h"
 #include "core/fxcrt/autonuller.h"
 #include "core/fxcrt/check.h"
 #include "core/fxcrt/fixed_size_data_vector.h"
@@ -41,14 +40,6 @@
 #include "xfa/fxfa/cxfa_fontmgr.h"
 #include "xfa/fxfa/cxfa_readynodeiterator.h"
 
-#ifdef PDF_ENABLE_XFA_BMP
-#include "core/fxcodec/bmp/bmp_progressive_decoder.h"
-#endif
-
-#ifdef PDF_ENABLE_XFA_GIF
-#include "core/fxcodec/gif/gif_progressive_decoder.h"
-#endif
-
 namespace {
 
 bool IsValidAlertButton(int type) {
@@ -108,23 +99,9 @@
 void CPDFXFA_ModuleInit() {
   CFGAS_GEModule::Create();
   BC_Library_Init();
-#ifdef PDF_ENABLE_XFA_BMP
-  fxcodec::BmpProgressiveDecoder::InitializeGlobals();
-#endif
-#ifdef PDF_ENABLE_XFA_GIF
-  fxcodec::GifProgressiveDecoder::InitializeGlobals();
-#endif
-  fxcodec::JpegProgressiveDecoder::InitializeGlobals();
 }
 
 void CPDFXFA_ModuleDestroy() {
-  fxcodec::JpegProgressiveDecoder::DestroyGlobals();
-#ifdef PDF_ENABLE_XFA_GIF
-  fxcodec::GifProgressiveDecoder::DestroyGlobals();
-#endif
-#ifdef PDF_ENABLE_XFA_BMP
-  fxcodec::BmpProgressiveDecoder::DestroyGlobals();
-#endif
   BC_Library_Destroy();
   CFGAS_GEModule::Destroy();
 }