summaryrefslogtreecommitdiff
path: root/core/fxcodec/codec
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-10-09 19:44:11 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-10-09 19:44:11 +0000
commit3e838a75ae5c0bb0e524f745df69e54a021fc5ec (patch)
tree92d389fbba456469c14e75d7723493dc85603b81 /core/fxcodec/codec
parent78606af0550f34a41d262e0a01381f48b7dfe197 (diff)
downloadpdfium-3e838a75ae5c0bb0e524f745df69e54a021fc5ec.tar.xz
Pass CFX_CodecMemory in place of spans to codecs.
Next step towards making CFX_CodecMemory own the memory it is ref-counting. Change-Id: I5922d80d13032c3ea028447c47d34a10234109a3 Reviewed-on: https://pdfium-review.googlesource.com/c/43630 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fxcodec/codec')
-rw-r--r--core/fxcodec/codec/ccodec_bmpmodule.cpp7
-rw-r--r--core/fxcodec/codec/ccodec_bmpmodule.h2
-rw-r--r--core/fxcodec/codec/ccodec_gifmodule.cpp5
-rw-r--r--core/fxcodec/codec/ccodec_gifmodule.h2
-rw-r--r--core/fxcodec/codec/ccodec_jpegmodule.cpp3
-rw-r--r--core/fxcodec/codec/ccodec_jpegmodule.h2
-rw-r--r--core/fxcodec/codec/ccodec_pngmodule.cpp3
-rw-r--r--core/fxcodec/codec/ccodec_pngmodule.h2
-rw-r--r--core/fxcodec/codec/ccodec_progressivedecoder.cpp40
-rw-r--r--core/fxcodec/codec/ccodec_tiffmodule.cpp2
-rw-r--r--core/fxcodec/codec/ccodec_tiffmodule.h2
-rw-r--r--core/fxcodec/codec/cfx_codec_memory.h1
-rw-r--r--core/fxcodec/codec/codec_module_iface.h3
13 files changed, 51 insertions, 23 deletions
diff --git a/core/fxcodec/codec/ccodec_bmpmodule.cpp b/core/fxcodec/codec/ccodec_bmpmodule.cpp
index 9884662bd3..37a0b2cb29 100644
--- a/core/fxcodec/codec/ccodec_bmpmodule.cpp
+++ b/core/fxcodec/codec/ccodec_bmpmodule.cpp
@@ -6,6 +6,8 @@
#include "core/fxcodec/codec/ccodec_bmpmodule.h"
+#include <utility>
+
#include "core/fxcodec/bmp/cfx_bmpcontext.h"
#include "core/fxcodec/codec/codec_int.h"
#include "core/fxcodec/fx_codec.h"
@@ -68,8 +70,9 @@ FX_FILESIZE CCodec_BmpModule::GetAvailInput(Context* pContext) const {
}
bool CCodec_BmpModule::Input(Context* pContext,
- pdfium::span<uint8_t> src_buf,
+ RetainPtr<CFX_CodecMemory> codec_memory,
CFX_DIBAttribute*) {
- static_cast<CFX_BmpContext*>(pContext)->m_Bmp.SetInputBuffer(src_buf);
+ auto* ctx = static_cast<CFX_BmpContext*>(pContext);
+ ctx->m_Bmp.SetInputBuffer(std::move(codec_memory));
return true;
}
diff --git a/core/fxcodec/codec/ccodec_bmpmodule.h b/core/fxcodec/codec/ccodec_bmpmodule.h
index d5b6a75494..f8a82727bc 100644
--- a/core/fxcodec/codec/ccodec_bmpmodule.h
+++ b/core/fxcodec/codec/ccodec_bmpmodule.h
@@ -32,7 +32,7 @@ class CCodec_BmpModule final : public CodecModuleIface {
// CodecModuleIface:
FX_FILESIZE GetAvailInput(Context* pContext) const override;
bool Input(Context* pContext,
- pdfium::span<uint8_t> src_buf,
+ RetainPtr<CFX_CodecMemory> codec_memory,
CFX_DIBAttribute* pAttribute) override;
std::unique_ptr<Context> Start(Delegate* pDelegate);
diff --git a/core/fxcodec/codec/ccodec_gifmodule.cpp b/core/fxcodec/codec/ccodec_gifmodule.cpp
index 289993c903..4162171827 100644
--- a/core/fxcodec/codec/ccodec_gifmodule.cpp
+++ b/core/fxcodec/codec/ccodec_gifmodule.cpp
@@ -71,8 +71,9 @@ FX_FILESIZE CCodec_GifModule::GetAvailInput(Context* pContext) const {
}
bool CCodec_GifModule::Input(Context* pContext,
- pdfium::span<uint8_t> src_buf,
+ RetainPtr<CFX_CodecMemory> codec_memory,
CFX_DIBAttribute*) {
- static_cast<CFX_GifContext*>(pContext)->SetInputBuffer(src_buf);
+ auto* ctx = static_cast<CFX_GifContext*>(pContext);
+ ctx->SetInputBuffer(std::move(codec_memory));
return true;
}
diff --git a/core/fxcodec/codec/ccodec_gifmodule.h b/core/fxcodec/codec/ccodec_gifmodule.h
index 665208ba1a..0e85998dc3 100644
--- a/core/fxcodec/codec/ccodec_gifmodule.h
+++ b/core/fxcodec/codec/ccodec_gifmodule.h
@@ -41,7 +41,7 @@ class CCodec_GifModule final : public CodecModuleIface {
// CodecModuleIface:
FX_FILESIZE GetAvailInput(Context* context) const override;
bool Input(Context* context,
- pdfium::span<uint8_t> src_buf,
+ RetainPtr<CFX_CodecMemory> codec_memory,
CFX_DIBAttribute* pAttribute) override;
std::unique_ptr<Context> Start(Delegate* pDelegate);
diff --git a/core/fxcodec/codec/ccodec_jpegmodule.cpp b/core/fxcodec/codec/ccodec_jpegmodule.cpp
index 7c15aa35a0..4a6059ad18 100644
--- a/core/fxcodec/codec/ccodec_jpegmodule.cpp
+++ b/core/fxcodec/codec/ccodec_jpegmodule.cpp
@@ -413,8 +413,9 @@ std::unique_ptr<CodecModuleIface::Context> CCodec_JpegModule::Start() {
}
bool CCodec_JpegModule::Input(Context* pContext,
- pdfium::span<uint8_t> src_buf,
+ RetainPtr<CFX_CodecMemory> codec_memory,
CFX_DIBAttribute*) {
+ pdfium::span<uint8_t> src_buf = codec_memory->GetSpan();
auto* ctx = static_cast<CJpegContext*>(pContext);
if (ctx->m_SkipSize) {
if (ctx->m_SkipSize > src_buf.size()) {
diff --git a/core/fxcodec/codec/ccodec_jpegmodule.h b/core/fxcodec/codec/ccodec_jpegmodule.h
index 45b1d1b6d1..258038f9cd 100644
--- a/core/fxcodec/codec/ccodec_jpegmodule.h
+++ b/core/fxcodec/codec/ccodec_jpegmodule.h
@@ -31,7 +31,7 @@ class CCodec_JpegModule final : public CodecModuleIface {
// CodecModuleIface:
FX_FILESIZE GetAvailInput(Context* pContext) const override;
bool Input(Context* pContext,
- pdfium::span<uint8_t> src_buf,
+ RetainPtr<CFX_CodecMemory> codec_memory,
CFX_DIBAttribute* pAttribute) override;
jmp_buf* GetJumpMark(Context* pContext);
diff --git a/core/fxcodec/codec/ccodec_pngmodule.cpp b/core/fxcodec/codec/ccodec_pngmodule.cpp
index 593c215db4..31de538087 100644
--- a/core/fxcodec/codec/ccodec_pngmodule.cpp
+++ b/core/fxcodec/codec/ccodec_pngmodule.cpp
@@ -210,7 +210,7 @@ FX_FILESIZE CCodec_PngModule::GetAvailInput(Context* pContext) const {
}
bool CCodec_PngModule::Input(Context* pContext,
- pdfium::span<uint8_t> src_buf,
+ RetainPtr<CFX_CodecMemory> codec_memory,
CFX_DIBAttribute* pAttribute) {
auto* ctx = static_cast<CPngContext*>(pContext);
if (setjmp(png_jmpbuf(ctx->m_pPng))) {
@@ -220,6 +220,7 @@ bool CCodec_PngModule::Input(Context* pContext,
}
return false;
}
+ pdfium::span<uint8_t> src_buf = codec_memory->GetSpan();
png_process_data(ctx->m_pPng, ctx->m_pInfo, src_buf.data(), src_buf.size());
return true;
}
diff --git a/core/fxcodec/codec/ccodec_pngmodule.h b/core/fxcodec/codec/ccodec_pngmodule.h
index e97a221dfc..9754cb3bbd 100644
--- a/core/fxcodec/codec/ccodec_pngmodule.h
+++ b/core/fxcodec/codec/ccodec_pngmodule.h
@@ -35,7 +35,7 @@ class CCodec_PngModule final : public CodecModuleIface {
// CodecModuleIface:
FX_FILESIZE GetAvailInput(Context* pContext) const override;
bool Input(Context* pContext,
- pdfium::span<uint8_t> src_buf,
+ RetainPtr<CFX_CodecMemory> codec_memory,
CFX_DIBAttribute* pAttribute) override;
std::unique_ptr<Context> Start(Delegate* pDelegate);
diff --git a/core/fxcodec/codec/ccodec_progressivedecoder.cpp b/core/fxcodec/codec/ccodec_progressivedecoder.cpp
index 0e6014595e..07665c1d4a 100644
--- a/core/fxcodec/codec/ccodec_progressivedecoder.cpp
+++ b/core/fxcodec/codec/ccodec_progressivedecoder.cpp
@@ -718,7 +718,10 @@ bool CCodec_ProgressiveDecoder::BmpDetectImageTypeInBuffer(
std::unique_ptr<CodecModuleIface::Context> pBmpContext =
pBmpModule->Start(this);
- pBmpModule->Input(pBmpContext.get(), {m_pSrcBuf.get(), m_SrcSize}, nullptr);
+ pBmpModule->Input(pBmpContext.get(),
+ pdfium::MakeRetain<CFX_CodecMemory>(
+ pdfium::make_span(m_pSrcBuf.get(), m_SrcSize)),
+ nullptr);
std::vector<uint32_t> palette;
int32_t readResult = pBmpModule->ReadHeader(
@@ -863,7 +866,10 @@ bool CCodec_ProgressiveDecoder::GifDetectImageTypeInBuffer(
return false;
}
m_pGifContext = pGifModule->Start(this);
- pGifModule->Input(m_pGifContext.get(), {m_pSrcBuf.get(), m_SrcSize}, nullptr);
+ pGifModule->Input(m_pGifContext.get(),
+ pdfium::MakeRetain<CFX_CodecMemory>(
+ pdfium::make_span(m_pSrcBuf.get(), m_SrcSize)),
+ nullptr);
m_SrcComponents = 1;
CFX_GifDecodeStatus readResult = pGifModule->ReadHeader(
m_pGifContext.get(), &m_SrcWidth, &m_SrcHeight, &m_GifPltNumber,
@@ -1046,7 +1052,9 @@ bool CCodec_ProgressiveDecoder::JpegDetectImageTypeInBuffer(
m_status = FXCODEC_STATUS_ERR_MEMORY;
return false;
}
- pJpegModule->Input(m_pJpegContext.get(), {m_pSrcBuf.get(), m_SrcSize},
+ pJpegModule->Input(m_pJpegContext.get(),
+ pdfium::MakeRetain<CFX_CodecMemory>(
+ pdfium::make_span(m_pSrcBuf.get(), m_SrcSize)),
nullptr);
// Setting jump marker before calling ReadHeader, since a longjmp to
// the marker indicates a fatal error.
@@ -1256,8 +1264,11 @@ bool CCodec_ProgressiveDecoder::PngDetectImageTypeInBuffer(
m_status = FXCODEC_STATUS_ERR_MEMORY;
return false;
}
- bool bResult = pPngModule->Input(m_pPngContext.get(),
- {m_pSrcBuf.get(), m_SrcSize}, pAttribute);
+ bool bResult =
+ pPngModule->Input(m_pPngContext.get(),
+ pdfium::MakeRetain<CFX_CodecMemory>(
+ pdfium::make_span(m_pSrcBuf.get(), m_SrcSize)),
+ pAttribute);
while (bResult) {
uint32_t remain_size = static_cast<uint32_t>(m_pFile->GetSize()) - m_offSet;
uint32_t input_size =
@@ -1277,8 +1288,11 @@ bool CCodec_ProgressiveDecoder::PngDetectImageTypeInBuffer(
return false;
}
m_offSet += input_size;
- bResult = pPngModule->Input(m_pPngContext.get(),
- {m_pSrcBuf.get(), input_size}, pAttribute);
+ bResult =
+ pPngModule->Input(m_pPngContext.get(),
+ pdfium::MakeRetain<CFX_CodecMemory>(
+ pdfium::make_span(m_pSrcBuf.get(), input_size)),
+ pAttribute);
}
m_pPngContext.reset();
if (m_SrcPassNumber == 0) {
@@ -1365,8 +1379,11 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::PngContinueDecode() {
return m_status;
}
m_offSet += input_size;
- bResult = pPngModule->Input(m_pPngContext.get(),
- {m_pSrcBuf.get(), input_size}, nullptr);
+ bResult =
+ pPngModule->Input(m_pPngContext.get(),
+ pdfium::MakeRetain<CFX_CodecMemory>(
+ pdfium::make_span(m_pSrcBuf.get(), input_size)),
+ nullptr);
if (!bResult) {
m_pDeviceBitmap = nullptr;
m_pFile = nullptr;
@@ -1633,7 +1650,10 @@ bool CCodec_ProgressiveDecoder::ReadMoreData(
return false;
}
m_offSet += dwBytesToFetchFromFile;
- return pModule->Input(pContext, {m_pSrcBuf.get(), m_SrcSize}, nullptr);
+ return pModule->Input(pContext,
+ pdfium::MakeRetain<CFX_CodecMemory>(
+ pdfium::make_span(m_pSrcBuf.get(), m_SrcSize)),
+ nullptr);
}
FXCODEC_STATUS CCodec_ProgressiveDecoder::LoadImageInfo(
diff --git a/core/fxcodec/codec/ccodec_tiffmodule.cpp b/core/fxcodec/codec/ccodec_tiffmodule.cpp
index d2c6c26dc0..15b80676b5 100644
--- a/core/fxcodec/codec/ccodec_tiffmodule.cpp
+++ b/core/fxcodec/codec/ccodec_tiffmodule.cpp
@@ -502,7 +502,7 @@ FX_FILESIZE CCodec_TiffModule::GetAvailInput(Context* pContext) const {
}
bool CCodec_TiffModule::Input(Context* pContext,
- pdfium::span<uint8_t> src_buf,
+ RetainPtr<CFX_CodecMemory> codec_memory,
CFX_DIBAttribute*) {
NOTREACHED();
return false;
diff --git a/core/fxcodec/codec/ccodec_tiffmodule.h b/core/fxcodec/codec/ccodec_tiffmodule.h
index 15d2a9f6d2..eee24de410 100644
--- a/core/fxcodec/codec/ccodec_tiffmodule.h
+++ b/core/fxcodec/codec/ccodec_tiffmodule.h
@@ -25,7 +25,7 @@ class CCodec_TiffModule final : public CodecModuleIface {
// CodecModuleIface:
FX_FILESIZE GetAvailInput(Context* pContext) const override;
bool Input(Context* pContext,
- pdfium::span<uint8_t> src_buf,
+ RetainPtr<CFX_CodecMemory> codec_memory,
CFX_DIBAttribute* pAttribute) override;
bool LoadFrameInfo(Context* ctx,
diff --git a/core/fxcodec/codec/cfx_codec_memory.h b/core/fxcodec/codec/cfx_codec_memory.h
index 2907e892d2..0d11d41de8 100644
--- a/core/fxcodec/codec/cfx_codec_memory.h
+++ b/core/fxcodec/codec/cfx_codec_memory.h
@@ -13,6 +13,7 @@ class CFX_CodecMemory final : public Retainable {
template <typename T, typename... Args>
friend RetainPtr<T> pdfium::MakeRetain(Args&&... args);
+ pdfium::span<uint8_t> GetSpan() { return buffer_; }
uint8_t* GetBuffer() { return buffer_.data(); }
size_t GetSize() const { return buffer_.size(); }
size_t GetPosition() const { return pos_; }
diff --git a/core/fxcodec/codec/codec_module_iface.h b/core/fxcodec/codec/codec_module_iface.h
index e7faa892b2..52cb564d9a 100644
--- a/core/fxcodec/codec/codec_module_iface.h
+++ b/core/fxcodec/codec/codec_module_iface.h
@@ -7,6 +7,7 @@
#ifndef CORE_FXCODEC_CODEC_CODEC_MODULE_IFACE_H_
#define CORE_FXCODEC_CODEC_CODEC_MODULE_IFACE_H_
+#include "core/fxcodec/codec/cfx_codec_memory.h"
#include "core/fxcrt/fx_system.h"
#include "third_party/base/span.h"
@@ -28,7 +29,7 @@ class CodecModuleIface {
// setting details about the image extracted from the buffer into |pAttribute|
// (if provided and the codec is capable providing that information).
virtual bool Input(Context* pContext,
- pdfium::span<uint8_t> src_buf,
+ RetainPtr<CFX_CodecMemory> codec_memory,
CFX_DIBAttribute* pAttribute) = 0;
};