summaryrefslogtreecommitdiff
path: root/core/fpdfapi
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-03-27 13:51:46 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-03-28 14:14:50 +0000
commit0004f29bf6ee3c6060a272c79f14993e92e053c7 (patch)
treeb82385e4853a157e10148af8d95ebb6bae4fb4c7 /core/fpdfapi
parent369fe1f7f9f3a424ee3cf8f992c3128db27fa479 (diff)
downloadpdfium-0004f29bf6ee3c6060a272c79f14993e92e053c7.tar.xz
Refcount all CFX_DIBSources (and subclasses) all the time.
There are currently several ownership models for these objects, including ad-hoc logic for sharing and deletion, and the now-redundant CFX_DIBitmapRef externally-counted handle to the DIBs. Replace them all with the internal refcount scheme. Change-Id: I2db399dfc19219eda384f94cc989353b78ce2872 Reviewed-on: https://pdfium-review.googlesource.com/3166 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fpdfapi')
-rw-r--r--core/fpdfapi/font/cpdf_type3char.cpp2
-rw-r--r--core/fpdfapi/font/cpdf_type3char.h2
-rw-r--r--core/fpdfapi/page/cpdf_generalstate.h1
-rw-r--r--core/fpdfapi/page/cpdf_image.cpp49
-rw-r--r--core/fpdfapi/page/cpdf_image.h16
-rw-r--r--core/fpdfapi/render/cpdf_devicebuffer.cpp18
-rw-r--r--core/fpdfapi/render/cpdf_devicebuffer.h4
-rw-r--r--core/fpdfapi/render/cpdf_dibsource.cpp46
-rw-r--r--core/fpdfapi/render/cpdf_dibsource.h12
-rw-r--r--core/fpdfapi/render/cpdf_dibtransferfunc.h6
-rw-r--r--core/fpdfapi/render/cpdf_imagecacheentry.cpp66
-rw-r--r--core/fpdfapi/render/cpdf_imagecacheentry.h15
-rw-r--r--core/fpdfapi/render/cpdf_imageloader.cpp11
-rw-r--r--core/fpdfapi/render/cpdf_imageloader.h4
-rw-r--r--core/fpdfapi/render/cpdf_imagerenderer.cpp47
-rw-r--r--core/fpdfapi/render/cpdf_imagerenderer.h8
-rw-r--r--core/fpdfapi/render/cpdf_pagerendercache.cpp5
-rw-r--r--core/fpdfapi/render/cpdf_pagerendercache.h4
-rw-r--r--core/fpdfapi/render/cpdf_rendercontext.cpp9
-rw-r--r--core/fpdfapi/render/cpdf_rendercontext.h2
-rw-r--r--core/fpdfapi/render/cpdf_renderstatus.cpp167
-rw-r--r--core/fpdfapi/render/cpdf_renderstatus.h18
-rw-r--r--core/fpdfapi/render/cpdf_transferfunc.cpp8
-rw-r--r--core/fpdfapi/render/cpdf_transferfunc.h3
-rw-r--r--core/fpdfapi/render/cpdf_type3cache.cpp10
25 files changed, 265 insertions, 268 deletions
diff --git a/core/fpdfapi/font/cpdf_type3char.cpp b/core/fpdfapi/font/cpdf_type3char.cpp
index 5eb12c1752..4f116a1afb 100644
--- a/core/fpdfapi/font/cpdf_type3char.cpp
+++ b/core/fpdfapi/font/cpdf_type3char.cpp
@@ -29,7 +29,7 @@ bool CPDF_Type3Char::LoadBitmap(CPDF_RenderContext* pContext) {
return false;
m_ImageMatrix = pPageObj->AsImage()->matrix();
- std::unique_ptr<CFX_DIBSource> pSource =
+ CFX_RetainPtr<CFX_DIBSource> pSource =
pPageObj->AsImage()->GetImage()->LoadDIBSource();
if (pSource)
m_pBitmap = pSource->Clone();
diff --git a/core/fpdfapi/font/cpdf_type3char.h b/core/fpdfapi/font/cpdf_type3char.h
index 549f49e3da..3215802e0c 100644
--- a/core/fpdfapi/font/cpdf_type3char.h
+++ b/core/fpdfapi/font/cpdf_type3char.h
@@ -25,7 +25,7 @@ class CPDF_Type3Char {
bool LoadBitmap(CPDF_RenderContext* pContext);
std::unique_ptr<CPDF_Form> m_pForm;
- std::unique_ptr<CFX_DIBitmap> m_pBitmap;
+ CFX_RetainPtr<CFX_DIBitmap> m_pBitmap;
bool m_bColored;
int m_Width;
CFX_Matrix m_ImageMatrix;
diff --git a/core/fpdfapi/page/cpdf_generalstate.h b/core/fpdfapi/page/cpdf_generalstate.h
index ddc33ac800..1c5ddee4e0 100644
--- a/core/fpdfapi/page/cpdf_generalstate.h
+++ b/core/fpdfapi/page/cpdf_generalstate.h
@@ -7,6 +7,7 @@
#ifndef CORE_FPDFAPI_PAGE_CPDF_GENERALSTATE_H_
#define CORE_FPDFAPI_PAGE_CPDF_GENERALSTATE_H_
+#include "core/fxcrt/cfx_shared_copy_on_write.h"
#include "core/fxcrt/fx_basic.h"
#include "core/fxcrt/fx_coordinates.h"
#include "core/fxge/fx_dib.h"
diff --git a/core/fpdfapi/page/cpdf_image.cpp b/core/fpdfapi/page/cpdf_image.cpp
index 3de0511771..4fc1c344ef 100644
--- a/core/fpdfapi/page/cpdf_image.cpp
+++ b/core/fpdfapi/page/cpdf_image.cpp
@@ -157,7 +157,7 @@ void CPDF_Image::SetJpegImageInline(
m_pStream->InitStream(&(data[0]), size, std::move(pDict));
}
-void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap) {
+void CPDF_Image::SetImage(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap) {
int32_t BitmapWidth = pBitmap->GetWidth();
int32_t BitmapHeight = pBitmap->GetHeight();
if (BitmapWidth < 1 || BitmapHeight < 1)
@@ -248,7 +248,7 @@ void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap) {
bCopyWithoutAlpha = false;
}
- std::unique_ptr<CFX_DIBitmap> pMaskBitmap;
+ CFX_RetainPtr<CFX_DIBitmap> pMaskBitmap;
if (pBitmap->HasAlpha())
pMaskBitmap = pBitmap->CloneAlphaMask();
@@ -320,28 +320,25 @@ void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap) {
FX_Free(dest_buf);
}
-void CPDF_Image::ResetCache(CPDF_Page* pPage, const CFX_DIBitmap* pBitmap) {
+void CPDF_Image::ResetCache(CPDF_Page* pPage,
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap) {
pPage->GetRenderCache()->ResetBitmap(m_pStream.Get(), pBitmap);
}
-std::unique_ptr<CFX_DIBSource> CPDF_Image::LoadDIBSource() const {
- auto source = pdfium::MakeUnique<CPDF_DIBSource>();
+CFX_RetainPtr<CFX_DIBSource> CPDF_Image::LoadDIBSource() const {
+ auto source = pdfium::MakeRetain<CPDF_DIBSource>();
if (!source->Load(m_pDocument, m_pStream.Get()))
return nullptr;
- return std::move(source);
+ return source;
}
-CFX_DIBSource* CPDF_Image::DetachBitmap() {
- CFX_DIBSource* pBitmap = m_pDIBSource;
- m_pDIBSource = nullptr;
- return pBitmap;
+CFX_RetainPtr<CFX_DIBSource> CPDF_Image::DetachBitmap() {
+ return std::move(m_pDIBSource);
}
-CFX_DIBSource* CPDF_Image::DetachMask() {
- CFX_DIBSource* pBitmap = m_pMask;
- m_pMask = nullptr;
- return pBitmap;
+CFX_RetainPtr<CFX_DIBSource> CPDF_Image::DetachMask() {
+ return std::move(m_pMask);
}
bool CPDF_Image::StartLoadDIBSource(CPDF_Dictionary* pFormResource,
@@ -349,35 +346,33 @@ bool CPDF_Image::StartLoadDIBSource(CPDF_Dictionary* pFormResource,
bool bStdCS,
uint32_t GroupFamily,
bool bLoadMask) {
- auto source = pdfium::MakeUnique<CPDF_DIBSource>();
+ auto source = pdfium::MakeRetain<CPDF_DIBSource>();
int ret = source->StartLoadDIBSource(m_pDocument, m_pStream.Get(), true,
pFormResource, pPageResource, bStdCS,
GroupFamily, bLoadMask);
- if (ret == 2) {
- m_pDIBSource = source.release();
- return true;
- }
if (!ret) {
- m_pDIBSource = nullptr;
+ m_pDIBSource.Reset();
return false;
}
+ m_pDIBSource = source;
+ if (ret == 2)
+ return true;
+
m_pMask = source->DetachMask();
m_MatteColor = source->GetMatteColor();
- m_pDIBSource = source.release();
return false;
}
bool CPDF_Image::Continue(IFX_Pause* pPause) {
- CPDF_DIBSource* pSource = static_cast<CPDF_DIBSource*>(m_pDIBSource);
+ CFX_RetainPtr<CPDF_DIBSource> pSource = m_pDIBSource.As<CPDF_DIBSource>();
int ret = pSource->ContinueLoadDIBSource(pPause);
- if (ret == 2) {
- return true;
- }
if (!ret) {
- delete m_pDIBSource;
- m_pDIBSource = nullptr;
+ m_pDIBSource.Reset();
return false;
}
+ if (ret == 2)
+ return true;
+
m_pMask = pSource->DetachMask();
m_MatteColor = pSource->GetMatteColor();
return false;
diff --git a/core/fpdfapi/page/cpdf_image.h b/core/fpdfapi/page/cpdf_image.h
index 1909498102..5b737e67b9 100644
--- a/core/fpdfapi/page/cpdf_image.h
+++ b/core/fpdfapi/page/cpdf_image.h
@@ -44,25 +44,25 @@ class CPDF_Image {
bool IsMask() const { return m_bIsMask; }
bool IsInterpol() const { return m_bInterpolate; }
- std::unique_ptr<CFX_DIBSource> LoadDIBSource() const;
+ CFX_RetainPtr<CFX_DIBSource> LoadDIBSource() const;
- void SetImage(const CFX_DIBitmap* pDIBitmap);
+ void SetImage(const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap);
void SetJpegImage(const CFX_RetainPtr<IFX_SeekableReadStream>& pFile);
void SetJpegImageInline(const CFX_RetainPtr<IFX_SeekableReadStream>& pFile);
- void ResetCache(CPDF_Page* pPage, const CFX_DIBitmap* pDIBitmap);
-
+ void ResetCache(CPDF_Page* pPage,
+ const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap);
bool StartLoadDIBSource(CPDF_Dictionary* pFormResource,
CPDF_Dictionary* pPageResource,
bool bStdCS = false,
uint32_t GroupFamily = 0,
bool bLoadMask = false);
bool Continue(IFX_Pause* pPause);
- CFX_DIBSource* DetachBitmap();
- CFX_DIBSource* DetachMask();
+ CFX_RetainPtr<CFX_DIBSource> DetachBitmap();
+ CFX_RetainPtr<CFX_DIBSource> DetachMask();
- CFX_DIBSource* m_pDIBSource = nullptr;
- CFX_DIBSource* m_pMask = nullptr;
+ CFX_RetainPtr<CFX_DIBSource> m_pDIBSource;
+ CFX_RetainPtr<CFX_DIBSource> m_pMask;
uint32_t m_MatteColor = 0;
private:
diff --git a/core/fpdfapi/render/cpdf_devicebuffer.cpp b/core/fpdfapi/render/cpdf_devicebuffer.cpp
index b8c174d97e..67641676ae 100644
--- a/core/fpdfapi/render/cpdf_devicebuffer.cpp
+++ b/core/fpdfapi/render/cpdf_devicebuffer.cpp
@@ -50,7 +50,7 @@ bool CPDF_DeviceBuffer::Initialize(CPDF_RenderContext* pContext,
m_Matrix.TransformRect(rect);
FX_RECT bitmap_rect = rect.GetOuterRect();
- m_pBitmap = pdfium::MakeUnique<CFX_DIBitmap>();
+ m_pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
m_pBitmap->Create(bitmap_rect.Width(), bitmap_rect.Height(), FXDIB_Argb);
return true;
}
@@ -58,19 +58,19 @@ bool CPDF_DeviceBuffer::Initialize(CPDF_RenderContext* pContext,
void CPDF_DeviceBuffer::OutputToDevice() {
if (m_pDevice->GetDeviceCaps(FXDC_RENDER_CAPS) & FXRC_GET_BITS) {
if (m_Matrix.a == 1.0f && m_Matrix.d == 1.0f) {
- m_pDevice->SetDIBits(m_pBitmap.get(), m_Rect.left, m_Rect.top);
+ m_pDevice->SetDIBits(m_pBitmap, m_Rect.left, m_Rect.top);
} else {
- m_pDevice->StretchDIBits(m_pBitmap.get(), m_Rect.left, m_Rect.top,
+ m_pDevice->StretchDIBits(m_pBitmap, m_Rect.left, m_Rect.top,
m_Rect.Width(), m_Rect.Height());
}
return;
}
- CFX_DIBitmap buffer;
- m_pDevice->CreateCompatibleBitmap(&buffer, m_pBitmap->GetWidth(),
+ auto pBuffer = pdfium::MakeRetain<CFX_DIBitmap>();
+ m_pDevice->CreateCompatibleBitmap(pBuffer, m_pBitmap->GetWidth(),
m_pBitmap->GetHeight());
- m_pContext->GetBackground(&buffer, m_pObject, nullptr, &m_Matrix);
- buffer.CompositeBitmap(0, 0, buffer.GetWidth(), buffer.GetHeight(),
- m_pBitmap.get(), 0, 0);
- m_pDevice->StretchDIBits(&buffer, m_Rect.left, m_Rect.top, m_Rect.Width(),
+ m_pContext->GetBackground(pBuffer, m_pObject, nullptr, &m_Matrix);
+ pBuffer->CompositeBitmap(0, 0, pBuffer->GetWidth(), pBuffer->GetHeight(),
+ m_pBitmap, 0, 0);
+ m_pDevice->StretchDIBits(pBuffer, m_Rect.left, m_Rect.top, m_Rect.Width(),
m_Rect.Height());
}
diff --git a/core/fpdfapi/render/cpdf_devicebuffer.h b/core/fpdfapi/render/cpdf_devicebuffer.h
index e5bbf1fcdf..61cdc9776b 100644
--- a/core/fpdfapi/render/cpdf_devicebuffer.h
+++ b/core/fpdfapi/render/cpdf_devicebuffer.h
@@ -26,7 +26,7 @@ class CPDF_DeviceBuffer {
const CPDF_PageObject* pObj,
int max_dpi);
void OutputToDevice();
- CFX_DIBitmap* GetBitmap() const { return m_pBitmap.get(); }
+ CFX_RetainPtr<CFX_DIBitmap> GetBitmap() const { return m_pBitmap; }
const CFX_Matrix* GetMatrix() const { return &m_Matrix; }
private:
@@ -34,7 +34,7 @@ class CPDF_DeviceBuffer {
CPDF_RenderContext* m_pContext;
FX_RECT m_Rect;
const CPDF_PageObject* m_pObject;
- std::unique_ptr<CFX_DIBitmap> m_pBitmap;
+ CFX_RetainPtr<CFX_DIBitmap> m_pBitmap;
CFX_Matrix m_Matrix;
};
diff --git a/core/fpdfapi/render/cpdf_dibsource.cpp b/core/fpdfapi/render/cpdf_dibsource.cpp
index 899a783c47..f3703dd23a 100644
--- a/core/fpdfapi/render/cpdf_dibsource.cpp
+++ b/core/fpdfapi/render/cpdf_dibsource.cpp
@@ -8,6 +8,7 @@
#include <algorithm>
#include <memory>
+#include <utility>
#include <vector>
#include "core/fpdfapi/cpdf_modulemgr.h"
@@ -126,12 +127,11 @@ CPDF_DIBSource::CPDF_DIBSource()
CPDF_DIBSource::~CPDF_DIBSource() {
FX_Free(m_pMaskedLine);
FX_Free(m_pLineBuf);
- m_pCachedBitmap.reset();
+ m_pCachedBitmap.Reset(); // TODO(tsepez): determine if required early here.
FX_Free(m_pCompData);
CPDF_ColorSpace* pCS = m_pColorSpace;
- if (pCS && m_pDocument) {
+ if (pCS && m_pDocument)
m_pDocument->GetPageData()->ReleaseColorSpace(pCS->GetArray());
- }
}
bool CPDF_DIBSource::Load(CPDF_Document* pDoc, const CPDF_Stream* pStream) {
@@ -332,7 +332,7 @@ int CPDF_DIBSource::ContinueLoadDIBSource(IFX_Pause* pPause) {
m_pStreamAcc.get(), m_pGlobalStream.get(),
m_pCachedBitmap->GetBuffer(), m_pCachedBitmap->GetPitch(), pPause);
if (ret < 0) {
- m_pCachedBitmap.reset();
+ m_pCachedBitmap.Reset();
m_pGlobalStream.reset();
m_pJbig2Context.reset();
return 0;
@@ -355,7 +355,7 @@ int CPDF_DIBSource::ContinueLoadDIBSource(IFX_Pause* pPause) {
}
ret = pJbig2Module->ContinueDecode(m_pJbig2Context.get(), pPause);
if (ret < 0) {
- m_pCachedBitmap.reset();
+ m_pCachedBitmap.Reset();
m_pGlobalStream.reset();
m_pJbig2Context.reset();
return 0;
@@ -507,10 +507,10 @@ int CPDF_DIBSource::CreateDecoder() {
return m_pCachedBitmap ? 1 : 0;
}
if (decoder == "JBIG2Decode") {
- m_pCachedBitmap = pdfium::MakeUnique<CFX_DIBitmap>();
+ m_pCachedBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
if (!m_pCachedBitmap->Create(
m_Width, m_Height, m_bImageMask ? FXDIB_1bppMask : FXDIB_1bppRgb)) {
- m_pCachedBitmap.reset();
+ m_pCachedBitmap.Reset();
return 0;
}
m_Status = 1;
@@ -656,9 +656,9 @@ void CPDF_DIBSource::LoadJpxBitmap() {
format = FXDIB_Rgb;
}
- m_pCachedBitmap = pdfium::MakeUnique<CFX_DIBitmap>();
+ m_pCachedBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
if (!m_pCachedBitmap->Create(width, height, format)) {
- m_pCachedBitmap.reset();
+ m_pCachedBitmap.Reset();
return;
}
m_pCachedBitmap->Clear(0xFFFFFFFF);
@@ -671,7 +671,7 @@ void CPDF_DIBSource::LoadJpxBitmap() {
}
if (!pJpxModule->Decode(context->decoder(), m_pCachedBitmap->GetBuffer(),
m_pCachedBitmap->GetPitch(), output_offsets)) {
- m_pCachedBitmap.reset();
+ m_pCachedBitmap.Reset();
return;
}
if (m_pColorSpace && m_pColorSpace->GetFamily() == PDFCS_INDEXED &&
@@ -713,32 +713,29 @@ int CPDF_DIBSource::StratLoadMask() {
}
int CPDF_DIBSource::ContinueLoadMaskDIB(IFX_Pause* pPause) {
- if (!m_pMask) {
+ if (!m_pMask)
return 1;
- }
+
int ret = m_pMask->ContinueLoadDIBSource(pPause);
- if (ret == 2) {
+ if (ret == 2)
return ret;
- }
- if (m_pColorSpace && m_bStdCS) {
+
+ if (m_pColorSpace && m_bStdCS)
m_pColorSpace->EnableStdConversion(false);
- }
+
if (!ret) {
- delete m_pMask;
- m_pMask = nullptr;
+ m_pMask.Reset();
return ret;
}
return 1;
}
-CPDF_DIBSource* CPDF_DIBSource::DetachMask() {
- CPDF_DIBSource* pDIBSource = m_pMask;
- m_pMask = nullptr;
- return pDIBSource;
+CFX_RetainPtr<CPDF_DIBSource> CPDF_DIBSource::DetachMask() {
+ return std::move(m_pMask);
}
int CPDF_DIBSource::StartLoadMaskDIB() {
- m_pMask = new CPDF_DIBSource;
+ m_pMask = pdfium::MakeRetain<CPDF_DIBSource>();
int ret = m_pMask->StartLoadDIBSource(m_pDocument, m_pMaskStream, false,
nullptr, nullptr, true);
if (ret == 2) {
@@ -747,8 +744,7 @@ int CPDF_DIBSource::StartLoadMaskDIB() {
return 2;
}
if (!ret) {
- delete m_pMask;
- m_pMask = nullptr;
+ m_pMask.Reset();
return 1;
}
return 1;
diff --git a/core/fpdfapi/render/cpdf_dibsource.h b/core/fpdfapi/render/cpdf_dibsource.h
index b0f8dedaf7..c77aac1776 100644
--- a/core/fpdfapi/render/cpdf_dibsource.h
+++ b/core/fpdfapi/render/cpdf_dibsource.h
@@ -39,7 +39,9 @@ typedef struct {
class CPDF_DIBSource : public CFX_DIBSource {
public:
- CPDF_DIBSource();
+ template <typename T, typename... Args>
+ friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args);
+
~CPDF_DIBSource() override;
bool Load(CPDF_Document* pDoc, const CPDF_Stream* pStream);
@@ -71,9 +73,11 @@ class CPDF_DIBSource : public CFX_DIBSource {
int StartLoadMaskDIB();
int ContinueLoadMaskDIB(IFX_Pause* pPause);
int ContinueToLoadMask();
- CPDF_DIBSource* DetachMask();
+ CFX_RetainPtr<CPDF_DIBSource> DetachMask();
private:
+ CPDF_DIBSource();
+
bool LoadColorInfo(const CPDF_Dictionary* pFormResources,
const CPDF_Dictionary* pPageResources);
DIB_COMP_DATA* GetDecodeAndMaskArray(bool* bDefaultDecode, bool* bColorKey);
@@ -133,9 +137,9 @@ class CPDF_DIBSource : public CFX_DIBSource {
DIB_COMP_DATA* m_pCompData;
uint8_t* m_pLineBuf;
uint8_t* m_pMaskedLine;
- std::unique_ptr<CFX_DIBitmap> m_pCachedBitmap;
+ CFX_RetainPtr<CFX_DIBitmap> m_pCachedBitmap;
+ CFX_RetainPtr<CPDF_DIBSource> m_pMask;
std::unique_ptr<CCodec_ScanlineDecoder> m_pDecoder;
- CPDF_DIBSource* m_pMask;
std::unique_ptr<CPDF_StreamAcc> m_pGlobalStream;
std::unique_ptr<CCodec_Jbig2Context> m_pJbig2Context;
CPDF_Stream* m_pMaskStream;
diff --git a/core/fpdfapi/render/cpdf_dibtransferfunc.h b/core/fpdfapi/render/cpdf_dibtransferfunc.h
index d290c00d8a..d57ec0ff89 100644
--- a/core/fpdfapi/render/cpdf_dibtransferfunc.h
+++ b/core/fpdfapi/render/cpdf_dibtransferfunc.h
@@ -15,7 +15,9 @@ class CPDF_TransferFunc;
class CPDF_DIBTransferFunc : public CFX_FilteredDIB {
public:
- explicit CPDF_DIBTransferFunc(const CPDF_TransferFunc* pTransferFunc);
+ template <typename T, typename... Args>
+ friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args);
+
~CPDF_DIBTransferFunc() override;
// CFX_FilteredDIB
@@ -29,6 +31,8 @@ class CPDF_DIBTransferFunc : public CFX_FilteredDIB {
int Bpp) const override;
private:
+ explicit CPDF_DIBTransferFunc(const CPDF_TransferFunc* pTransferFunc);
+
const uint8_t* m_RampR;
const uint8_t* m_RampG;
const uint8_t* m_RampB;
diff --git a/core/fpdfapi/render/cpdf_imagecacheentry.cpp b/core/fpdfapi/render/cpdf_imagecacheentry.cpp
index 82b6117f86..751b3eb4b4 100644
--- a/core/fpdfapi/render/cpdf_imagecacheentry.cpp
+++ b/core/fpdfapi/render/cpdf_imagecacheentry.cpp
@@ -31,30 +31,27 @@ CPDF_ImageCacheEntry::CPDF_ImageCacheEntry(CPDF_Document* pDoc,
CPDF_ImageCacheEntry::~CPDF_ImageCacheEntry() {}
-void CPDF_ImageCacheEntry::Reset(const CFX_DIBitmap* pBitmap) {
- m_pCachedBitmap.reset();
+void CPDF_ImageCacheEntry::Reset(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap) {
+ m_pCachedBitmap.Reset();
if (pBitmap)
m_pCachedBitmap = pBitmap->Clone();
CalcSize();
}
-static uint32_t FPDF_ImageCache_EstimateImageSize(const CFX_DIBSource* pDIB) {
+static uint32_t FPDF_ImageCache_EstimateImageSize(
+ const CFX_RetainPtr<CFX_DIBSource>& pDIB) {
return pDIB && pDIB->GetBuffer()
? (uint32_t)pDIB->GetHeight() * pDIB->GetPitch() +
(uint32_t)pDIB->GetPaletteSize() * 4
: 0;
}
-CFX_DIBSource* CPDF_ImageCacheEntry::DetachBitmap() {
- CFX_DIBSource* pDIBSource = m_pCurBitmap;
- m_pCurBitmap = nullptr;
- return pDIBSource;
+CFX_RetainPtr<CFX_DIBSource> CPDF_ImageCacheEntry::DetachBitmap() {
+ return std::move(m_pCurBitmap);
}
-CFX_DIBSource* CPDF_ImageCacheEntry::DetachMask() {
- CFX_DIBSource* pDIBSource = m_pCurMask;
- m_pCurMask = nullptr;
- return pDIBSource;
+CFX_RetainPtr<CFX_DIBSource> CPDF_ImageCacheEntry::DetachMask() {
+ return std::move(m_pCurMask);
}
int CPDF_ImageCacheEntry::StartGetCachedBitmap(CPDF_Dictionary* pFormResources,
@@ -66,25 +63,23 @@ int CPDF_ImageCacheEntry::StartGetCachedBitmap(CPDF_Dictionary* pFormResources,
int32_t downsampleWidth,
int32_t downsampleHeight) {
if (m_pCachedBitmap) {
- m_pCurBitmap = m_pCachedBitmap.get();
- m_pCurMask = m_pCachedMask.get();
+ m_pCurBitmap = m_pCachedBitmap;
+ m_pCurMask = m_pCachedMask;
return 1;
}
if (!pRenderStatus)
return 0;
m_pRenderStatus = pRenderStatus;
- m_pCurBitmap = new CPDF_DIBSource;
- int ret =
- ((CPDF_DIBSource*)m_pCurBitmap)
- ->StartLoadDIBSource(m_pDocument, m_pStream, true, pFormResources,
- pPageResources, bStdCS, GroupFamily, bLoadMask);
+ m_pCurBitmap = pdfium::MakeRetain<CPDF_DIBSource>();
+ int ret = m_pCurBitmap.As<CPDF_DIBSource>()->StartLoadDIBSource(
+ m_pDocument, m_pStream, true, pFormResources, pPageResources, bStdCS,
+ GroupFamily, bLoadMask);
if (ret == 2)
return ret;
if (!ret) {
- delete m_pCurBitmap;
- m_pCurBitmap = nullptr;
+ m_pCurBitmap.Reset();
return 0;
}
ContinueGetCachedBitmap();
@@ -92,44 +87,41 @@ int CPDF_ImageCacheEntry::StartGetCachedBitmap(CPDF_Dictionary* pFormResources,
}
void CPDF_ImageCacheEntry::ContinueGetCachedBitmap() {
- m_MatteColor = ((CPDF_DIBSource*)m_pCurBitmap)->GetMatteColor();
- m_pCurMask = ((CPDF_DIBSource*)m_pCurBitmap)->DetachMask();
+ m_MatteColor = m_pCurBitmap.As<CPDF_DIBSource>()->GetMatteColor();
+ m_pCurMask = m_pCurBitmap.As<CPDF_DIBSource>()->DetachMask();
CPDF_RenderContext* pContext = m_pRenderStatus->GetContext();
CPDF_PageRenderCache* pPageRenderCache = pContext->GetPageCache();
m_dwTimeCount = pPageRenderCache->GetTimeCount();
if (m_pCurBitmap->GetPitch() * m_pCurBitmap->GetHeight() <
FPDF_HUGE_IMAGE_SIZE) {
m_pCachedBitmap = m_pCurBitmap->Clone();
- delete m_pCurBitmap;
- m_pCurBitmap = nullptr;
+ m_pCurBitmap.Reset();
} else {
- m_pCachedBitmap = pdfium::WrapUnique<CFX_DIBSource>(m_pCurBitmap);
+ m_pCachedBitmap = m_pCurBitmap;
}
if (m_pCurMask) {
m_pCachedMask = m_pCurMask->Clone();
- delete m_pCurMask;
- m_pCurMask = nullptr;
+ m_pCurMask.Reset();
}
- m_pCurBitmap = m_pCachedBitmap.get();
- m_pCurMask = m_pCachedMask.get();
+ m_pCurBitmap = m_pCachedBitmap;
+ m_pCurMask = m_pCachedMask;
CalcSize();
}
int CPDF_ImageCacheEntry::Continue(IFX_Pause* pPause) {
- int ret = ((CPDF_DIBSource*)m_pCurBitmap)->ContinueLoadDIBSource(pPause);
- if (ret == 2)
- return ret;
-
+ int ret = m_pCurBitmap.As<CPDF_DIBSource>()->ContinueLoadDIBSource(pPause);
if (!ret) {
- delete m_pCurBitmap;
- m_pCurBitmap = nullptr;
+ m_pCurBitmap.Reset();
return 0;
}
+ if (ret == 2)
+ return ret;
+
ContinueGetCachedBitmap();
return 0;
}
void CPDF_ImageCacheEntry::CalcSize() {
- m_dwCacheSize = FPDF_ImageCache_EstimateImageSize(m_pCachedBitmap.get()) +
- FPDF_ImageCache_EstimateImageSize(m_pCachedMask.get());
+ m_dwCacheSize = FPDF_ImageCache_EstimateImageSize(m_pCachedBitmap) +
+ FPDF_ImageCache_EstimateImageSize(m_pCachedMask);
}
diff --git a/core/fpdfapi/render/cpdf_imagecacheentry.h b/core/fpdfapi/render/cpdf_imagecacheentry.h
index d11fe94c29..b17d3fdda2 100644
--- a/core/fpdfapi/render/cpdf_imagecacheentry.h
+++ b/core/fpdfapi/render/cpdf_imagecacheentry.h
@@ -9,6 +9,7 @@
#include <memory>
+#include "core/fxcrt/cfx_retain_ptr.h"
#include "core/fxcrt/fx_system.h"
class CFX_DIBitmap;
@@ -24,7 +25,7 @@ class CPDF_ImageCacheEntry {
CPDF_ImageCacheEntry(CPDF_Document* pDoc, CPDF_Stream* pStream);
~CPDF_ImageCacheEntry();
- void Reset(const CFX_DIBitmap* pBitmap);
+ void Reset(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap);
uint32_t EstimateSize() const { return m_dwCacheSize; }
uint32_t GetTimeCount() const { return m_dwTimeCount; }
CPDF_Stream* GetStream() const { return m_pStream; }
@@ -38,8 +39,8 @@ class CPDF_ImageCacheEntry {
int32_t downsampleWidth,
int32_t downsampleHeight);
int Continue(IFX_Pause* pPause);
- CFX_DIBSource* DetachBitmap();
- CFX_DIBSource* DetachMask();
+ CFX_RetainPtr<CFX_DIBSource> DetachBitmap();
+ CFX_RetainPtr<CFX_DIBSource> DetachMask();
int m_dwTimeCount;
uint32_t m_MatteColor;
@@ -51,10 +52,10 @@ class CPDF_ImageCacheEntry {
CPDF_RenderStatus* m_pRenderStatus;
CPDF_Document* m_pDocument;
CPDF_Stream* m_pStream;
- CFX_DIBSource* m_pCurBitmap;
- CFX_DIBSource* m_pCurMask;
- std::unique_ptr<CFX_DIBSource> m_pCachedBitmap;
- std::unique_ptr<CFX_DIBSource> m_pCachedMask;
+ CFX_RetainPtr<CFX_DIBSource> m_pCurBitmap;
+ CFX_RetainPtr<CFX_DIBSource> m_pCurMask;
+ CFX_RetainPtr<CFX_DIBSource> m_pCachedBitmap;
+ CFX_RetainPtr<CFX_DIBSource> m_pCachedMask;
uint32_t m_dwCacheSize;
};
diff --git a/core/fpdfapi/render/cpdf_imageloader.cpp b/core/fpdfapi/render/cpdf_imageloader.cpp
index 18213ea695..856e340325 100644
--- a/core/fpdfapi/render/cpdf_imageloader.cpp
+++ b/core/fpdfapi/render/cpdf_imageloader.cpp
@@ -15,21 +15,14 @@
#include "core/fxcrt/fx_basic.h"
CPDF_ImageLoader::CPDF_ImageLoader()
- : m_pBitmap(nullptr),
- m_pMask(nullptr),
- m_MatteColor(0),
+ : m_MatteColor(0),
m_bCached(false),
m_nDownsampleWidth(0),
m_nDownsampleHeight(0),
m_pCache(nullptr),
m_pImage(nullptr) {}
-CPDF_ImageLoader::~CPDF_ImageLoader() {
- if (!m_bCached) {
- delete m_pBitmap;
- delete m_pMask;
- }
-}
+CPDF_ImageLoader::~CPDF_ImageLoader() {}
bool CPDF_ImageLoader::Start(const CPDF_ImageObject* pImage,
CPDF_PageRenderCache* pCache,
diff --git a/core/fpdfapi/render/cpdf_imageloader.h b/core/fpdfapi/render/cpdf_imageloader.h
index a270c45bbf..c7161c3486 100644
--- a/core/fpdfapi/render/cpdf_imageloader.h
+++ b/core/fpdfapi/render/cpdf_imageloader.h
@@ -31,8 +31,8 @@ class CPDF_ImageLoader {
int32_t nDownsampleHeight);
bool Continue(IFX_Pause* pPause);
- CFX_DIBSource* m_pBitmap;
- CFX_DIBSource* m_pMask;
+ CFX_RetainPtr<CFX_DIBSource> m_pBitmap;
+ CFX_RetainPtr<CFX_DIBSource> m_pMask;
uint32_t m_MatteColor;
bool m_bCached;
diff --git a/core/fpdfapi/render/cpdf_imagerenderer.cpp b/core/fpdfapi/render/cpdf_imagerenderer.cpp
index d3778452a3..08f9165f8a 100644
--- a/core/fpdfapi/render/cpdf_imagerenderer.cpp
+++ b/core/fpdfapi/render/cpdf_imagerenderer.cpp
@@ -95,9 +95,9 @@ bool CPDF_ImageRenderer::StartRenderDIBSource() {
!m_pImageObject->m_GeneralState.GetTransferFunc()->m_bIdentity) {
m_pDIBSource = m_Loader.m_pBitmap =
m_pImageObject->m_GeneralState.GetTransferFunc()->TranslateImage(
- m_Loader.m_pBitmap, !m_Loader.m_bCached);
+ m_Loader.m_pBitmap);
if (m_Loader.m_bCached && m_Loader.m_pMask)
- m_Loader.m_pMask = m_Loader.m_pMask->Clone().release();
+ m_Loader.m_pMask = m_Loader.m_pMask->Clone();
m_Loader.m_bCached = false;
}
}
@@ -116,7 +116,7 @@ bool CPDF_ImageRenderer::StartRenderDIBSource() {
m_pClone = m_pDIBSource->Clone();
m_pClone->ConvertColorScale(m_pRenderStatus->m_Options.m_BackColor,
m_pRenderStatus->m_Options.m_ForeColor);
- m_pDIBSource = m_pClone.get();
+ m_pDIBSource = m_pClone;
}
m_Flags = 0;
if (m_pRenderStatus->m_Options.m_Flags & RENDER_FORCE_DOWNSAMPLE)
@@ -209,7 +209,7 @@ bool CPDF_ImageRenderer::Start(CPDF_RenderStatus* pStatus,
}
bool CPDF_ImageRenderer::Start(CPDF_RenderStatus* pStatus,
- const CFX_DIBSource* pDIBSource,
+ const CFX_RetainPtr<CFX_DIBSource>& pDIBSource,
FX_ARGB bitmap_argb,
int bitmap_alpha,
const CFX_Matrix* pImage2Device,
@@ -244,11 +244,12 @@ CFX_Matrix CPDF_ImageRenderer::GetDrawMatrix(const FX_RECT& rect) const {
return new_matrix;
}
-void CPDF_ImageRenderer::CalculateDrawImage(CFX_FxgeDevice* pBitmapDevice1,
- CFX_FxgeDevice* pBitmapDevice2,
- const CFX_DIBSource* pDIBSource,
- CFX_Matrix* pNewMatrix,
- const FX_RECT& rect) const {
+void CPDF_ImageRenderer::CalculateDrawImage(
+ CFX_FxgeDevice* pBitmapDevice1,
+ CFX_FxgeDevice* pBitmapDevice2,
+ const CFX_RetainPtr<CFX_DIBSource>& pDIBSource,
+ CFX_Matrix* pNewMatrix,
+ const FX_RECT& rect) const {
CPDF_RenderStatus bitmap_render;
bitmap_render.Initialize(m_pRenderStatus->m_pContext, pBitmapDevice2, nullptr,
nullptr, nullptr, nullptr, nullptr, 0,
@@ -403,7 +404,7 @@ bool CPDF_ImageRenderer::StartDIBSource() {
}
}
#ifdef _SKIA_SUPPORT_
- CFX_DIBitmap* premultiplied = m_pDIBSource->Clone().release();
+ CFX_RetainPtr<CFX_DIBitmap> premultiplied = m_pDIBSource->Clone();
if (m_pDIBSource->HasAlpha())
CFX_SkiaDeviceDriver::PreMultiply(premultiplied);
if (m_pRenderStatus->m_pDevice->StartDIBitsWithBlend(
@@ -480,10 +481,10 @@ bool CPDF_ImageRenderer::StartDIBSource() {
FX_RECT dest_clip(
dest_rect.left - image_rect.left, dest_rect.top - image_rect.top,
dest_rect.right - image_rect.left, dest_rect.bottom - image_rect.top);
- std::unique_ptr<CFX_DIBitmap> pStretched(
- m_pDIBSource->StretchTo(dest_width, dest_height, m_Flags, &dest_clip));
+ CFX_RetainPtr<CFX_DIBitmap> pStretched =
+ m_pDIBSource->StretchTo(dest_width, dest_height, m_Flags, &dest_clip);
if (pStretched) {
- m_pRenderStatus->CompositeDIBitmap(pStretched.get(), dest_rect.left,
+ m_pRenderStatus->CompositeDIBitmap(pStretched, dest_rect.left,
dest_rect.top, m_FillArgb, m_BitmapAlpha,
m_BlendType, false);
}
@@ -501,9 +502,9 @@ bool CPDF_ImageRenderer::StartBitmapAlpha() {
FXFILL_WINDING);
return false;
}
- CFX_MaybeOwned<CFX_DIBSource> pAlphaMask;
+ CFX_RetainPtr<CFX_DIBSource> pAlphaMask;
if (m_pDIBSource->IsAlphaMask())
- pAlphaMask = const_cast<CFX_DIBSource*>(m_pDIBSource);
+ pAlphaMask = m_pDIBSource;
else
pAlphaMask = m_pDIBSource->CloneAlphaMask();
@@ -511,13 +512,13 @@ bool CPDF_ImageRenderer::StartBitmapAlpha() {
FXSYS_fabs(m_ImageMatrix.c) >= 0.5f) {
int left;
int top;
- std::unique_ptr<CFX_DIBitmap> pTransformed =
+ CFX_RetainPtr<CFX_DIBitmap> pTransformed =
pAlphaMask->TransformTo(&m_ImageMatrix, left, top);
if (!pTransformed)
return true;
m_pRenderStatus->m_pDevice->SetBitMask(
- pTransformed.get(), left, top,
+ pTransformed, left, top,
ArgbEncode(0xff, m_BitmapAlpha, m_BitmapAlpha, m_BitmapAlpha));
return false;
}
@@ -530,7 +531,7 @@ bool CPDF_ImageRenderer::StartBitmapAlpha() {
int left = dest_width > 0 ? image_rect.left : image_rect.right;
int top = dest_height > 0 ? image_rect.top : image_rect.bottom;
m_pRenderStatus->m_pDevice->StretchBitMask(
- pAlphaMask.Get(), left, top, dest_width, dest_height,
+ pAlphaMask, left, top, dest_width, dest_height,
ArgbEncode(0xff, m_BitmapAlpha, m_BitmapAlpha, m_BitmapAlpha));
return false;
}
@@ -540,7 +541,7 @@ bool CPDF_ImageRenderer::Continue(IFX_Pause* pPause) {
if (m_pTransformer->Continue(pPause))
return true;
- std::unique_ptr<CFX_DIBitmap> pBitmap(m_pTransformer->DetachBitmap());
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap = m_pTransformer->DetachBitmap();
if (!pBitmap)
return false;
@@ -548,14 +549,14 @@ bool CPDF_ImageRenderer::Continue(IFX_Pause* pPause) {
if (m_BitmapAlpha != 255)
m_FillArgb = FXARGB_MUL_ALPHA(m_FillArgb, m_BitmapAlpha);
m_Result = m_pRenderStatus->m_pDevice->SetBitMask(
- pBitmap.get(), m_pTransformer->result().left,
- m_pTransformer->result().top, m_FillArgb);
+ pBitmap, m_pTransformer->result().left, m_pTransformer->result().top,
+ m_FillArgb);
} else {
if (m_BitmapAlpha != 255)
pBitmap->MultiplyAlpha(m_BitmapAlpha);
m_Result = m_pRenderStatus->m_pDevice->SetDIBitsWithBlend(
- pBitmap.get(), m_pTransformer->result().left,
- m_pTransformer->result().top, m_BlendType);
+ pBitmap, m_pTransformer->result().left, m_pTransformer->result().top,
+ m_BlendType);
}
return false;
}
diff --git a/core/fpdfapi/render/cpdf_imagerenderer.h b/core/fpdfapi/render/cpdf_imagerenderer.h
index d358716e9f..542325449f 100644
--- a/core/fpdfapi/render/cpdf_imagerenderer.h
+++ b/core/fpdfapi/render/cpdf_imagerenderer.h
@@ -30,7 +30,7 @@ class CPDF_ImageRenderer {
int blendType);
bool Start(CPDF_RenderStatus* pStatus,
- const CFX_DIBSource* pDIBSource,
+ const CFX_RetainPtr<CFX_DIBSource>& pDIBSource,
FX_ARGB bitmap_argb,
int bitmap_alpha,
const CFX_Matrix* pImage2Device,
@@ -53,7 +53,7 @@ class CPDF_ImageRenderer {
CFX_Matrix GetDrawMatrix(const FX_RECT& rect) const;
void CalculateDrawImage(CFX_FxgeDevice* bitmap_device1,
CFX_FxgeDevice* bitmap_device2,
- const CFX_DIBSource* pDIBSource,
+ const CFX_RetainPtr<CFX_DIBSource>& pDIBSource,
CFX_Matrix* pNewMatrix,
const FX_RECT& rect) const;
@@ -63,8 +63,8 @@ class CPDF_ImageRenderer {
const CFX_Matrix* m_pObj2Device;
CFX_Matrix m_ImageMatrix;
CPDF_ImageLoader m_Loader;
- const CFX_DIBSource* m_pDIBSource;
- std::unique_ptr<CFX_DIBitmap> m_pClone;
+ CFX_RetainPtr<CFX_DIBSource> m_pDIBSource;
+ CFX_RetainPtr<CFX_DIBitmap> m_pClone;
int m_BitmapAlpha;
bool m_bPatternColor;
CPDF_Pattern* m_pPattern;
diff --git a/core/fpdfapi/render/cpdf_pagerendercache.cpp b/core/fpdfapi/render/cpdf_pagerendercache.cpp
index faa9732f9b..6e6250b1c0 100644
--- a/core/fpdfapi/render/cpdf_pagerendercache.cpp
+++ b/core/fpdfapi/render/cpdf_pagerendercache.cpp
@@ -124,8 +124,9 @@ bool CPDF_PageRenderCache::Continue(IFX_Pause* pPause) {
return false;
}
-void CPDF_PageRenderCache::ResetBitmap(CPDF_Stream* pStream,
- const CFX_DIBitmap* pBitmap) {
+void CPDF_PageRenderCache::ResetBitmap(
+ CPDF_Stream* pStream,
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap) {
CPDF_ImageCacheEntry* pEntry;
const auto it = m_ImageCache.find(pStream);
if (it == m_ImageCache.end()) {
diff --git a/core/fpdfapi/render/cpdf_pagerendercache.h b/core/fpdfapi/render/cpdf_pagerendercache.h
index 6c9ed76911..affd55bbfe 100644
--- a/core/fpdfapi/render/cpdf_pagerendercache.h
+++ b/core/fpdfapi/render/cpdf_pagerendercache.h
@@ -9,6 +9,7 @@
#include <map>
+#include "core/fxcrt/cfx_retain_ptr.h"
#include "core/fxcrt/fx_system.h"
class CPDF_Stream;
@@ -27,7 +28,8 @@ class CPDF_PageRenderCache {
void CacheOptimization(int32_t dwLimitCacheSize);
uint32_t GetTimeCount() const { return m_nTimeCount; }
- void ResetBitmap(CPDF_Stream* pStream, const CFX_DIBitmap* pBitmap);
+ void ResetBitmap(CPDF_Stream* pStream,
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap);
CPDF_Page* GetPage() const { return m_pPage; }
CPDF_ImageCacheEntry* GetCurImageCacheEntry() const {
return m_pCurImageCacheEntry;
diff --git a/core/fpdfapi/render/cpdf_rendercontext.cpp b/core/fpdfapi/render/cpdf_rendercontext.cpp
index d74f729858..07af2cc172 100644
--- a/core/fpdfapi/render/cpdf_rendercontext.cpp
+++ b/core/fpdfapi/render/cpdf_rendercontext.cpp
@@ -30,10 +30,11 @@ CPDF_RenderContext::CPDF_RenderContext(CPDF_Document* pDoc,
CPDF_RenderContext::~CPDF_RenderContext() {}
-void CPDF_RenderContext::GetBackground(CFX_DIBitmap* pBuffer,
- const CPDF_PageObject* pObj,
- const CPDF_RenderOptions* pOptions,
- CFX_Matrix* pFinalMatrix) {
+void CPDF_RenderContext::GetBackground(
+ const CFX_RetainPtr<CFX_DIBitmap>& pBuffer,
+ const CPDF_PageObject* pObj,
+ const CPDF_RenderOptions* pOptions,
+ CFX_Matrix* pFinalMatrix) {
CFX_FxgeDevice device;
device.Attach(pBuffer, false, nullptr, false);
diff --git a/core/fpdfapi/render/cpdf_rendercontext.h b/core/fpdfapi/render/cpdf_rendercontext.h
index a9fd2db78b..0cce1ae77e 100644
--- a/core/fpdfapi/render/cpdf_rendercontext.h
+++ b/core/fpdfapi/render/cpdf_rendercontext.h
@@ -47,7 +47,7 @@ class CPDF_RenderContext {
const CPDF_RenderOptions* pOptions,
const CFX_Matrix* pFinalMatrix);
- void GetBackground(CFX_DIBitmap* pBuffer,
+ void GetBackground(const CFX_RetainPtr<CFX_DIBitmap>& pBuffer,
const CPDF_PageObject* pObj,
const CPDF_RenderOptions* pOptions,
CFX_Matrix* pFinalMatrix);
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp
index 17576fc1f3..5320422b41 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.cpp
+++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -97,7 +97,7 @@ uint32_t CountOutputs(
return total;
}
-void DrawAxialShading(CFX_DIBitmap* pBitmap,
+void DrawAxialShading(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
CFX_Matrix* pObject2Bitmap,
CPDF_Dictionary* pDict,
const std::vector<std::unique_ptr<CPDF_Function>>& funcs,
@@ -183,7 +183,7 @@ void DrawAxialShading(CFX_DIBitmap* pBitmap,
}
}
-void DrawRadialShading(CFX_DIBitmap* pBitmap,
+void DrawRadialShading(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
CFX_Matrix* pObject2Bitmap,
CPDF_Dictionary* pDict,
const std::vector<std::unique_ptr<CPDF_Function>>& funcs,
@@ -316,7 +316,7 @@ void DrawRadialShading(CFX_DIBitmap* pBitmap,
}
}
-void DrawFuncShading(CFX_DIBitmap* pBitmap,
+void DrawFuncShading(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
CFX_Matrix* pObject2Bitmap,
CPDF_Dictionary* pDict,
const std::vector<std::unique_ptr<CPDF_Function>>& funcs,
@@ -391,7 +391,7 @@ bool GetScanlineIntersect(int y,
return true;
}
-void DrawGouraud(CFX_DIBitmap* pBitmap,
+void DrawGouraud(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
int alpha,
CPDF_MeshVertex triangle[3]) {
float min_y = triangle[0].position.y;
@@ -473,7 +473,7 @@ void DrawGouraud(CFX_DIBitmap* pBitmap,
}
void DrawFreeGouraudShading(
- CFX_DIBitmap* pBitmap,
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
CFX_Matrix* pObject2Bitmap,
CPDF_Stream* pShadingStream,
const std::vector<std::unique_ptr<CPDF_Function>>& funcs,
@@ -514,7 +514,7 @@ void DrawFreeGouraudShading(
}
void DrawLatticeGouraudShading(
- CFX_DIBitmap* pBitmap,
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
CFX_Matrix* pObject2Bitmap,
CPDF_Stream* pShadingStream,
const std::vector<std::unique_ptr<CPDF_Function>>& funcs,
@@ -808,7 +808,7 @@ struct CPDF_PatchDrawer {
void DrawCoonPatchMeshes(
ShadingType type,
- CFX_DIBitmap* pBitmap,
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
CFX_Matrix* pObject2Bitmap,
CPDF_Stream* pShadingStream,
const std::vector<std::unique_ptr<CPDF_Function>>& funcs,
@@ -892,21 +892,20 @@ void DrawCoonPatchMeshes(
}
}
-std::unique_ptr<CFX_DIBitmap> DrawPatternBitmap(
- CPDF_Document* pDoc,
- CPDF_PageRenderCache* pCache,
- CPDF_TilingPattern* pPattern,
- const CFX_Matrix* pObject2Device,
- int width,
- int height,
- int flags) {
- std::unique_ptr<CFX_DIBitmap> pBitmap(new CFX_DIBitmap);
+CFX_RetainPtr<CFX_DIBitmap> DrawPatternBitmap(CPDF_Document* pDoc,
+ CPDF_PageRenderCache* pCache,
+ CPDF_TilingPattern* pPattern,
+ const CFX_Matrix* pObject2Device,
+ int width,
+ int height,
+ int flags) {
+ auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
if (!pBitmap->Create(width, height,
pPattern->colored() ? FXDIB_Argb : FXDIB_8bppMask)) {
return nullptr;
}
CFX_FxgeDevice bitmap_device;
- bitmap_device.Attach(pBitmap.get(), false, nullptr, false);
+ bitmap_device.Attach(pBitmap, false, nullptr, false);
pBitmap->Clear(0);
CFX_FloatRect cell_bbox = pPattern->bbox();
pPattern->pattern_to_form()->TransformRect(cell_bbox);
@@ -1531,38 +1530,41 @@ bool CPDF_RenderStatus::ProcessTransparency(CPDF_PageObject* pPageObj,
}
FX_RECT rect = pPageObj->GetBBox(pObj2Device);
rect.Intersect(m_pDevice->GetClipBox());
- if (rect.IsEmpty()) {
+ if (rect.IsEmpty())
return true;
- }
+
CFX_Matrix deviceCTM = m_pDevice->GetCTM();
float scaleX = FXSYS_fabs(deviceCTM.a);
float scaleY = FXSYS_fabs(deviceCTM.d);
int width = FXSYS_round((float)rect.Width() * scaleX);
int height = FXSYS_round((float)rect.Height() * scaleY);
CFX_FxgeDevice bitmap_device;
- std::unique_ptr<CFX_DIBitmap> oriDevice;
+ CFX_RetainPtr<CFX_DIBitmap> oriDevice;
if (!isolated && (m_pDevice->GetRenderCaps() & FXRC_GET_BITS)) {
- oriDevice = pdfium::MakeUnique<CFX_DIBitmap>();
- if (!m_pDevice->CreateCompatibleBitmap(oriDevice.get(), width, height))
+ oriDevice = pdfium::MakeRetain<CFX_DIBitmap>();
+ if (!m_pDevice->CreateCompatibleBitmap(oriDevice, width, height))
return true;
- m_pDevice->GetDIBits(oriDevice.get(), rect.left, rect.top);
+ m_pDevice->GetDIBits(oriDevice, rect.left, rect.top);
}
- if (!bitmap_device.Create(width, height, FXDIB_Argb, oriDevice.get()))
+ if (!bitmap_device.Create(width, height, FXDIB_Argb, oriDevice))
return true;
- CFX_DIBitmap* bitmap = bitmap_device.GetBitmap();
+
+ CFX_RetainPtr<CFX_DIBitmap> bitmap = bitmap_device.GetBitmap();
bitmap->Clear(0);
+
CFX_Matrix new_matrix = *pObj2Device;
new_matrix.Translate(-rect.left, -rect.top);
new_matrix.Scale(scaleX, scaleY);
- std::unique_ptr<CFX_DIBitmap> pTextMask;
+
+ CFX_RetainPtr<CFX_DIBitmap> pTextMask;
if (bTextClip) {
- pTextMask = pdfium::MakeUnique<CFX_DIBitmap>();
+ pTextMask = pdfium::MakeRetain<CFX_DIBitmap>();
if (!pTextMask->Create(width, height, FXDIB_8bppMask))
return true;
pTextMask->Clear(0);
CFX_FxgeDevice text_device;
- text_device.Attach(pTextMask.get(), false, nullptr, false);
+ text_device.Attach(pTextMask, false, nullptr, false);
for (uint32_t i = 0; i < pPageObj->m_ClipPath.GetTextCount(); i++) {
CPDF_TextObject* textobj = pPageObj->m_ClipPath.GetText(i);
if (!textobj)
@@ -1589,14 +1591,14 @@ bool CPDF_RenderStatus::ProcessTransparency(CPDF_PageObject* pPageObj,
if (pSMaskDict) {
CFX_Matrix smask_matrix = *pPageObj->m_GeneralState.GetSMaskMatrix();
smask_matrix.Concat(*pObj2Device);
- std::unique_ptr<CFX_DIBSource> pSMaskSource =
+ CFX_RetainPtr<CFX_DIBSource> pSMaskSource =
LoadSMask(pSMaskDict, &rect, &smask_matrix);
if (pSMaskSource)
- bitmap->MultiplyAlpha(pSMaskSource.get());
+ bitmap->MultiplyAlpha(pSMaskSource);
}
if (pTextMask) {
- bitmap->MultiplyAlpha(pTextMask.get());
- pTextMask.reset();
+ bitmap->MultiplyAlpha(pTextMask);
+ pTextMask.Reset();
}
int32_t blitAlpha = 255;
if (Transparency & PDFTRANS_GROUP && group_alpha != 1.0f) {
@@ -1618,7 +1620,7 @@ bool CPDF_RenderStatus::ProcessTransparency(CPDF_PageObject* pPageObj,
return true;
}
-std::unique_ptr<CFX_DIBitmap> CPDF_RenderStatus::GetBackdrop(
+CFX_RetainPtr<CFX_DIBitmap> CPDF_RenderStatus::GetBackdrop(
const CPDF_PageObject* pObj,
const FX_RECT& rect,
int& left,
@@ -1633,11 +1635,11 @@ std::unique_ptr<CFX_DIBitmap> CPDF_RenderStatus::GetBackdrop(
float scaleY = FXSYS_fabs(deviceCTM.d);
int width = FXSYS_round(bbox.Width() * scaleX);
int height = FXSYS_round(bbox.Height() * scaleY);
- auto pBackdrop = pdfium::MakeUnique<CFX_DIBitmap>();
+ auto pBackdrop = pdfium::MakeRetain<CFX_DIBitmap>();
if (bBackAlphaRequired && !m_bDropObjects)
pBackdrop->Create(width, height, FXDIB_Argb);
else
- m_pDevice->CreateCompatibleBitmap(pBackdrop.get(), width, height);
+ m_pDevice->CreateCompatibleBitmap(pBackdrop, width, height);
if (!pBackdrop->GetBuffer())
return nullptr;
@@ -1649,16 +1651,16 @@ std::unique_ptr<CFX_DIBitmap> CPDF_RenderStatus::GetBackdrop(
bNeedDraw = !(m_pDevice->GetRenderCaps() & FXRC_GET_BITS);
if (!bNeedDraw) {
- m_pDevice->GetDIBits(pBackdrop.get(), left, top);
+ m_pDevice->GetDIBits(pBackdrop, left, top);
return pBackdrop;
}
-
CFX_Matrix FinalMatrix = m_DeviceMatrix;
FinalMatrix.Translate(-left, -top);
FinalMatrix.Scale(scaleX, scaleY);
pBackdrop->Clear(pBackdrop->HasAlpha() ? 0 : 0xffffffff);
+
CFX_FxgeDevice device;
- device.Attach(pBackdrop.get(), false, nullptr, false);
+ device.Attach(pBackdrop, false, nullptr, false);
m_pContext->Render(&device, pObj, &m_Options, &FinalMatrix);
return pBackdrop;
}
@@ -1848,7 +1850,7 @@ bool CPDF_RenderStatus::ProcessType3Text(CPDF_TextObject* textobj,
if (!glyph.m_pGlyph)
continue;
- m_pDevice->SetBitMask(&glyph.m_pGlyph->m_Bitmap,
+ m_pDevice->SetBitMask(glyph.m_pGlyph->m_pBitmap,
glyph.m_Origin.x + glyph.m_pGlyph->m_Left,
glyph.m_Origin.y - glyph.m_pGlyph->m_Top,
fill_argb);
@@ -1910,7 +1912,7 @@ bool CPDF_RenderStatus::ProcessType3Text(CPDF_TextObject* textobj,
CFX_Point origin(FXSYS_round(matrix.e), FXSYS_round(matrix.f));
if (glyphs.empty()) {
- m_pDevice->SetBitMask(&pBitmap->m_Bitmap, origin.x + pBitmap->m_Left,
+ m_pDevice->SetBitMask(pBitmap->m_pBitmap, origin.x + pBitmap->m_Left,
origin.y - pBitmap->m_Top, fill_argb);
} else {
glyphs[iChar].m_pGlyph = pBitmap;
@@ -1920,7 +1922,7 @@ bool CPDF_RenderStatus::ProcessType3Text(CPDF_TextObject* textobj,
CFX_Matrix image_matrix = pType3Char->m_ImageMatrix;
image_matrix.Concat(matrix);
CPDF_ImageRenderer renderer;
- if (renderer.Start(this, pType3Char->m_pBitmap.get(), fill_argb, 255,
+ if (renderer.Start(this, pType3Char->m_pBitmap, fill_argb, 255,
&image_matrix, 0, false, FXDIB_BLEND_NORMAL)) {
renderer.Continue(nullptr);
}
@@ -1934,12 +1936,12 @@ bool CPDF_RenderStatus::ProcessType3Text(CPDF_TextObject* textobj,
return true;
FX_RECT rect = FXGE_GetGlyphsBBox(glyphs, 0, sa, sd);
- CFX_DIBitmap bitmap;
- if (!bitmap.Create(static_cast<int>(rect.Width() * sa),
- static_cast<int>(rect.Height() * sd), FXDIB_8bppMask)) {
+ auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ if (!pBitmap->Create(static_cast<int>(rect.Width() * sa),
+ static_cast<int>(rect.Height() * sd), FXDIB_8bppMask)) {
return true;
}
- bitmap.Clear(0);
+ pBitmap->Clear(0);
for (const FXTEXT_GLYPHPOS& glyph : glyphs) {
if (!glyph.m_pGlyph)
continue;
@@ -1958,13 +1960,13 @@ bool CPDF_RenderStatus::ProcessType3Text(CPDF_TextObject* textobj,
if (!top.IsValid())
continue;
- bitmap.CompositeMask(left.ValueOrDie(), top.ValueOrDie(),
- glyph.m_pGlyph->m_Bitmap.GetWidth(),
- glyph.m_pGlyph->m_Bitmap.GetHeight(),
- &glyph.m_pGlyph->m_Bitmap, fill_argb, 0, 0,
- FXDIB_BLEND_NORMAL, nullptr, false, 0, nullptr);
+ pBitmap->CompositeMask(left.ValueOrDie(), top.ValueOrDie(),
+ glyph.m_pGlyph->m_pBitmap->GetWidth(),
+ glyph.m_pGlyph->m_pBitmap->GetHeight(),
+ glyph.m_pGlyph->m_pBitmap, fill_argb, 0, 0,
+ FXDIB_BLEND_NORMAL, nullptr, false, 0, nullptr);
}
- m_pDevice->SetBitMask(&bitmap, rect.left, rect.top, fill_argb);
+ m_pDevice->SetBitMask(pBitmap, rect.left, rect.top, fill_argb);
return true;
}
@@ -2067,7 +2069,7 @@ void CPDF_RenderStatus::DrawShading(CPDF_ShadingPattern* pPattern,
buffer.Initialize(m_pContext, m_pDevice, &clip_rect, m_pCurObj, 150);
CFX_Matrix FinalMatrix = *pMatrix;
FinalMatrix.Concat(*buffer.GetMatrix());
- CFX_DIBitmap* pBitmap = buffer.GetBitmap();
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap = buffer.GetBitmap();
if (!pBitmap->GetBuffer())
return;
@@ -2285,9 +2287,9 @@ void CPDF_RenderStatus::DrawTilingPattern(CPDF_TilingPattern* pPattern,
}
float left_offset = cell_bbox.left - mtPattern2Device.e;
float top_offset = cell_bbox.bottom - mtPattern2Device.f;
- std::unique_ptr<CFX_DIBitmap> pPatternBitmap;
+ CFX_RetainPtr<CFX_DIBitmap> pPatternBitmap;
if (width * height < 16) {
- std::unique_ptr<CFX_DIBitmap> pEnlargedBitmap =
+ CFX_RetainPtr<CFX_DIBitmap> pEnlargedBitmap =
DrawPatternBitmap(m_pContext->GetDocument(), m_pContext->GetPageCache(),
pPattern, pObj2Device, 8, 8, m_Options.m_Flags);
pPatternBitmap = pEnlargedBitmap->StretchTo(width, height);
@@ -2307,11 +2309,11 @@ void CPDF_RenderStatus::DrawTilingPattern(CPDF_TilingPattern* pPattern,
FX_ARGB fill_argb = GetFillArgb(pPageObj);
int clip_width = clip_box.right - clip_box.left;
int clip_height = clip_box.bottom - clip_box.top;
- CFX_DIBitmap screen;
- if (!screen.Create(clip_width, clip_height, FXDIB_Argb)) {
+ auto pScreen = pdfium::MakeRetain<CFX_DIBitmap>();
+ if (!pScreen->Create(clip_width, clip_height, FXDIB_Argb))
return;
- }
- screen.Clear(0);
+
+ pScreen->Clear(0);
uint32_t* src_buf = (uint32_t*)pPatternBitmap->GetBuffer();
for (int col = min_col; col <= max_col; col++) {
for (int row = min_row; row <= max_row; row++) {
@@ -2342,7 +2344,7 @@ void CPDF_RenderStatus::DrawTilingPattern(CPDF_TilingPattern* pPattern,
continue;
}
uint32_t* dest_buf =
- (uint32_t*)(screen.GetBuffer() + screen.GetPitch() * start_y +
+ (uint32_t*)(pScreen->GetBuffer() + pScreen->GetPitch() * start_y +
start_x * 4);
if (pPattern->colored())
*dest_buf = *src_buf;
@@ -2350,16 +2352,16 @@ void CPDF_RenderStatus::DrawTilingPattern(CPDF_TilingPattern* pPattern,
*dest_buf = (*(uint8_t*)src_buf << 24) | (fill_argb & 0xffffff);
} else {
if (pPattern->colored()) {
- screen.CompositeBitmap(start_x, start_y, width, height,
- pPatternBitmap.get(), 0, 0);
+ pScreen->CompositeBitmap(start_x, start_y, width, height,
+ pPatternBitmap, 0, 0);
} else {
- screen.CompositeMask(start_x, start_y, width, height,
- pPatternBitmap.get(), fill_argb, 0, 0);
+ pScreen->CompositeMask(start_x, start_y, width, height,
+ pPatternBitmap, fill_argb, 0, 0);
}
}
}
}
- CompositeDIBitmap(&screen, clip_box.left, clip_box.top, 0, 255,
+ CompositeDIBitmap(pScreen, clip_box.left, clip_box.top, 0, 255,
FXDIB_BLEND_NORMAL, false);
m_pDevice->RestoreState(false);
}
@@ -2406,16 +2408,17 @@ bool CPDF_RenderStatus::ProcessImage(CPDF_ImageObject* pImageObj,
return render.GetResult();
}
-void CPDF_RenderStatus::CompositeDIBitmap(CFX_DIBitmap* pDIBitmap,
- int left,
- int top,
- FX_ARGB mask_argb,
- int bitmap_alpha,
- int blend_mode,
- int Transparency) {
- if (!pDIBitmap) {
+void CPDF_RenderStatus::CompositeDIBitmap(
+ const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap,
+ int left,
+ int top,
+ FX_ARGB mask_argb,
+ int bitmap_alpha,
+ int blend_mode,
+ int Transparency) {
+ if (!pDIBitmap)
return;
- }
+
if (blend_mode == FXDIB_BLEND_NORMAL) {
if (!pDIBitmap->IsAlphaMask()) {
if (bitmap_alpha < 255) {
@@ -2463,10 +2466,10 @@ void CPDF_RenderStatus::CompositeDIBitmap(CFX_DIBitmap* pDIBitmap,
FX_RECT rect(left, top, left + pDIBitmap->GetWidth(),
top + pDIBitmap->GetHeight());
rect.Intersect(m_pDevice->GetClipBox());
- CFX_MaybeOwned<CFX_DIBitmap> pClone;
+ CFX_RetainPtr<CFX_DIBitmap> pClone;
if (m_pDevice->GetBackDrop() && m_pDevice->GetBitmap()) {
pClone = m_pDevice->GetBackDrop()->Clone(&rect);
- CFX_DIBitmap* pForeBitmap = m_pDevice->GetBitmap();
+ CFX_RetainPtr<CFX_DIBitmap> pForeBitmap = m_pDevice->GetBitmap();
pClone->CompositeBitmap(0, 0, pClone->GetWidth(), pClone->GetHeight(),
pForeBitmap, rect.left, rect.top);
left = left >= 0 ? 0 : left;
@@ -2481,7 +2484,7 @@ void CPDF_RenderStatus::CompositeDIBitmap(CFX_DIBitmap* pDIBitmap,
pClone = pDIBitmap;
}
if (m_pDevice->GetBackDrop()) {
- m_pDevice->SetDIBits(pClone.Get(), rect.left, rect.top);
+ m_pDevice->SetDIBits(pClone, rect.left, rect.top);
} else {
if (pDIBitmap->IsAlphaMask())
return;
@@ -2494,7 +2497,7 @@ void CPDF_RenderStatus::CompositeDIBitmap(CFX_DIBitmap* pDIBitmap,
int back_left, back_top;
FX_RECT rect(left, top, left + pDIBitmap->GetWidth(),
top + pDIBitmap->GetHeight());
- std::unique_ptr<CFX_DIBitmap> pBackdrop =
+ CFX_RetainPtr<CFX_DIBitmap> pBackdrop =
GetBackdrop(m_pCurObj, rect, back_left, back_top,
blend_mode > FXDIB_BLEND_NORMAL && bIsolated);
if (!pBackdrop)
@@ -2510,17 +2513,17 @@ void CPDF_RenderStatus::CompositeDIBitmap(CFX_DIBitmap* pDIBitmap,
pDIBitmap, mask_argb, 0, 0, blend_mode);
}
- auto pBackdrop1 = pdfium::MakeUnique<CFX_DIBitmap>();
+ auto pBackdrop1 = pdfium::MakeRetain<CFX_DIBitmap>();
pBackdrop1->Create(pBackdrop->GetWidth(), pBackdrop->GetHeight(),
FXDIB_Rgb32);
pBackdrop1->Clear((uint32_t)-1);
pBackdrop1->CompositeBitmap(0, 0, pBackdrop->GetWidth(),
- pBackdrop->GetHeight(), pBackdrop.get(), 0, 0);
+ pBackdrop->GetHeight(), pBackdrop, 0, 0);
pBackdrop = std::move(pBackdrop1);
- m_pDevice->SetDIBits(pBackdrop.get(), back_left, back_top);
+ m_pDevice->SetDIBits(pBackdrop, back_left, back_top);
}
-std::unique_ptr<CFX_DIBitmap> CPDF_RenderStatus::LoadSMask(
+CFX_RetainPtr<CFX_DIBitmap> CPDF_RenderStatus::LoadSMask(
CPDF_Dictionary* pSMaskDict,
FX_RECT* pClipRect,
const CFX_Matrix* pMatrix) {
@@ -2613,7 +2616,7 @@ std::unique_ptr<CFX_DIBitmap> CPDF_RenderStatus::LoadSMask(
nullptr, 0, color_space_family, bLuminosity);
status.RenderObjectList(&form, &matrix);
- auto pMask = pdfium::MakeUnique<CFX_DIBitmap>();
+ auto pMask = pdfium::MakeRetain<CFX_DIBitmap>();
if (!pMask->Create(width, height, FXDIB_8bppMask))
return nullptr;
diff --git a/core/fpdfapi/render/cpdf_renderstatus.h b/core/fpdfapi/render/cpdf_renderstatus.h
index 6ae255271b..e3dcd73e6d 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.h
+++ b/core/fpdfapi/render/cpdf_renderstatus.h
@@ -105,7 +105,7 @@ class CPDF_RenderStatus {
const CFX_Matrix* pObj2Device,
bool bStroke);
bool ProcessImage(CPDF_ImageObject* pImageObj, const CFX_Matrix* pObj2Device);
- void CompositeDIBitmap(CFX_DIBitmap* pDIBitmap,
+ void CompositeDIBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap,
int left,
int top,
FX_ARGB mask_argb,
@@ -133,14 +133,14 @@ class CPDF_RenderStatus {
bool bStroke);
bool ProcessForm(const CPDF_FormObject* pFormObj,
const CFX_Matrix* pObj2Device);
- std::unique_ptr<CFX_DIBitmap> GetBackdrop(const CPDF_PageObject* pObj,
- const FX_RECT& rect,
- int& left,
- int& top,
- bool bBackAlphaRequired);
- std::unique_ptr<CFX_DIBitmap> LoadSMask(CPDF_Dictionary* pSMaskDict,
- FX_RECT* pClipRect,
- const CFX_Matrix* pMatrix);
+ CFX_RetainPtr<CFX_DIBitmap> GetBackdrop(const CPDF_PageObject* pObj,
+ const FX_RECT& rect,
+ int& left,
+ int& top,
+ bool bBackAlphaRequired);
+ CFX_RetainPtr<CFX_DIBitmap> LoadSMask(CPDF_Dictionary* pSMaskDict,
+ FX_RECT* pClipRect,
+ const CFX_Matrix* pMatrix);
static CPDF_Type3Cache* GetCachedType3(CPDF_Type3Font* pFont);
static CPDF_GraphicStates* CloneObjStates(const CPDF_GraphicStates* pPathObj,
bool bStroke);
diff --git a/core/fpdfapi/render/cpdf_transferfunc.cpp b/core/fpdfapi/render/cpdf_transferfunc.cpp
index be4836d20a..ed1f27dfad 100644
--- a/core/fpdfapi/render/cpdf_transferfunc.cpp
+++ b/core/fpdfapi/render/cpdf_transferfunc.cpp
@@ -17,9 +17,9 @@ FX_COLORREF CPDF_TransferFunc::TranslateColor(FX_COLORREF rgb) const {
m_Samples[512 + FXSYS_GetBValue(rgb)]);
}
-CFX_DIBSource* CPDF_TransferFunc::TranslateImage(const CFX_DIBSource* pSrc,
- bool bAutoDropSrc) {
- CPDF_DIBTransferFunc* pDest = new CPDF_DIBTransferFunc(this);
- pDest->LoadSrc(pSrc, bAutoDropSrc);
+CFX_RetainPtr<CFX_DIBSource> CPDF_TransferFunc::TranslateImage(
+ const CFX_RetainPtr<CFX_DIBSource>& pSrc) {
+ auto pDest = pdfium::MakeRetain<CPDF_DIBTransferFunc>(this);
+ pDest->LoadSrc(pSrc);
return pDest;
}
diff --git a/core/fpdfapi/render/cpdf_transferfunc.h b/core/fpdfapi/render/cpdf_transferfunc.h
index 829b274d9b..05219d49db 100644
--- a/core/fpdfapi/render/cpdf_transferfunc.h
+++ b/core/fpdfapi/render/cpdf_transferfunc.h
@@ -16,7 +16,8 @@ class CPDF_TransferFunc {
explicit CPDF_TransferFunc(CPDF_Document* pDoc);
FX_COLORREF TranslateColor(FX_COLORREF src) const;
- CFX_DIBSource* TranslateImage(const CFX_DIBSource* pSrc, bool bAutoDropSrc);
+ CFX_RetainPtr<CFX_DIBSource> TranslateImage(
+ const CFX_RetainPtr<CFX_DIBSource>& pSrc);
CPDF_Document* const m_pPDFDoc;
bool m_bIdentity;
diff --git a/core/fpdfapi/render/cpdf_type3cache.cpp b/core/fpdfapi/render/cpdf_type3cache.cpp
index 7d0cb18172..1ba9f66203 100644
--- a/core/fpdfapi/render/cpdf_type3cache.cpp
+++ b/core/fpdfapi/render/cpdf_type3cache.cpp
@@ -8,6 +8,7 @@
#include <map>
#include <memory>
+#include <utility>
#include "core/fpdfapi/font/cpdf_type3char.h"
#include "core/fpdfapi/font/cpdf_type3font.h"
@@ -51,7 +52,8 @@ bool IsScanLine8bpp(uint8_t* pBuf, int width) {
return false;
}
-int DetectFirstLastScan(const CFX_DIBitmap* pBitmap, bool bFirst) {
+int DetectFirstLastScan(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ bool bFirst) {
int height = pBitmap->GetHeight();
int pitch = pBitmap->GetPitch();
int width = pBitmap->GetWidth();
@@ -121,12 +123,12 @@ CFX_GlyphBitmap* CPDF_Type3Cache::RenderGlyph(CPDF_Type3Glyphs* pSize,
if (!pChar || !pChar->m_pBitmap)
return nullptr;
- CFX_DIBitmap* pBitmap = pChar->m_pBitmap.get();
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap = pChar->m_pBitmap;
CFX_Matrix image_matrix = pChar->m_ImageMatrix;
CFX_Matrix text_matrix(pMatrix->a, pMatrix->b, pMatrix->c, pMatrix->d, 0, 0);
image_matrix.Concat(text_matrix);
- std::unique_ptr<CFX_DIBitmap> pResBitmap;
+ CFX_RetainPtr<CFX_DIBitmap> pResBitmap;
int left = 0;
int top = 0;
if (FXSYS_fabs(image_matrix.b) < FXSYS_fabs(image_matrix.a) / 100 &&
@@ -166,6 +168,6 @@ CFX_GlyphBitmap* CPDF_Type3Cache::RenderGlyph(CPDF_Type3Glyphs* pSize,
CFX_GlyphBitmap* pGlyph = new CFX_GlyphBitmap;
pGlyph->m_Left = left;
pGlyph->m_Top = -top;
- pGlyph->m_Bitmap.TakeOver(pResBitmap.get());
+ pGlyph->m_pBitmap->TakeOver(std::move(pResBitmap));
return pGlyph;
}