summaryrefslogtreecommitdiff
path: root/core/fpdfapi/render
diff options
context:
space:
mode:
authordsinclair <dsinclair@chromium.org>2017-03-28 15:47:47 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-03-28 15:48:01 +0000
commit31b08d4cdaa17d7a03f35e087096a77036af98ec (patch)
tree40234b81f2972c857a33a86cb4b59868e56bb86b /core/fpdfapi/render
parenta3e9bf66c3483db926602aa62b0bd1ff8d1357a1 (diff)
downloadpdfium-31b08d4cdaa17d7a03f35e087096a77036af98ec.tar.xz
Revert "Refcount all CFX_DIBSources (and subclasses) all the time."
This reverts commit 0004f29bf6ee3c6060a272c79f14993e92e053c7. Reason for revert: Breaks build with skia_paths enabled (which will break the chrome roll). ../../third_party/pdfium/core/fxge/skia/fx_skia_device.cpp:1858:38: error: no member named 'get' in 'CFX_RetainPtr<CFX_DIBitmap>' ../../third_party/pdfium/core/fxge/skia/fx_skia_device.cpp:1861:42: error: no member named 'get' in 'CFX_RetainPtr<CFX_DIBitmap>' ../../third_party/pdfium/core/fxge/skia/fx_skia_device.cpp:2987:15: error: no viable overloaded '=' ../../third_party/pdfium/core/fxge/skia/fx_skia_device.cpp:2991:18: error: no viable overloaded '=' ../../third_party/pdfium/core/fxge/skia/fx_skia_device.cpp:2999:17: error: no viable overloaded '=' ../../third_party/pdfium/core/fxge/skia/fx_skia_device.cpp:3001:43: error: no member named 'GetObject' in 'CFX_RetainPtr<CFX_DIBitmap>' Original change's description: > 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> > TBR=thestig@chromium.org,tsepez@chromium.org,dsinclair@chromium.org,pdfium-reviews@googlegroups.com NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true Change-Id: I678b1fbc5e666cf7a19372ebaff3270fb115ba5e Reviewed-on: https://pdfium-review.googlesource.com/3243 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fpdfapi/render')
-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
20 files changed, 231 insertions, 232 deletions
diff --git a/core/fpdfapi/render/cpdf_devicebuffer.cpp b/core/fpdfapi/render/cpdf_devicebuffer.cpp
index 67641676ae..b8c174d97e 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::MakeRetain<CFX_DIBitmap>();
+ m_pBitmap = pdfium::MakeUnique<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, m_Rect.left, m_Rect.top);
+ m_pDevice->SetDIBits(m_pBitmap.get(), m_Rect.left, m_Rect.top);
} else {
- m_pDevice->StretchDIBits(m_pBitmap, m_Rect.left, m_Rect.top,
+ m_pDevice->StretchDIBits(m_pBitmap.get(), m_Rect.left, m_Rect.top,
m_Rect.Width(), m_Rect.Height());
}
return;
}
- auto pBuffer = pdfium::MakeRetain<CFX_DIBitmap>();
- m_pDevice->CreateCompatibleBitmap(pBuffer, m_pBitmap->GetWidth(),
+ CFX_DIBitmap buffer;
+ m_pDevice->CreateCompatibleBitmap(&buffer, m_pBitmap->GetWidth(),
m_pBitmap->GetHeight());
- 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_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_Rect.Height());
}
diff --git a/core/fpdfapi/render/cpdf_devicebuffer.h b/core/fpdfapi/render/cpdf_devicebuffer.h
index 61cdc9776b..e5bbf1fcdf 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_RetainPtr<CFX_DIBitmap> GetBitmap() const { return m_pBitmap; }
+ CFX_DIBitmap* GetBitmap() const { return m_pBitmap.get(); }
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;
- CFX_RetainPtr<CFX_DIBitmap> m_pBitmap;
+ std::unique_ptr<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 f3703dd23a..899a783c47 100644
--- a/core/fpdfapi/render/cpdf_dibsource.cpp
+++ b/core/fpdfapi/render/cpdf_dibsource.cpp
@@ -8,7 +8,6 @@
#include <algorithm>
#include <memory>
-#include <utility>
#include <vector>
#include "core/fpdfapi/cpdf_modulemgr.h"
@@ -127,11 +126,12 @@ CPDF_DIBSource::CPDF_DIBSource()
CPDF_DIBSource::~CPDF_DIBSource() {
FX_Free(m_pMaskedLine);
FX_Free(m_pLineBuf);
- m_pCachedBitmap.Reset(); // TODO(tsepez): determine if required early here.
+ m_pCachedBitmap.reset();
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::MakeRetain<CFX_DIBitmap>();
+ m_pCachedBitmap = pdfium::MakeUnique<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::MakeRetain<CFX_DIBitmap>();
+ m_pCachedBitmap = pdfium::MakeUnique<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,29 +713,32 @@ 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) {
- m_pMask.Reset();
+ delete m_pMask;
+ m_pMask = nullptr;
return ret;
}
return 1;
}
-CFX_RetainPtr<CPDF_DIBSource> CPDF_DIBSource::DetachMask() {
- return std::move(m_pMask);
+CPDF_DIBSource* CPDF_DIBSource::DetachMask() {
+ CPDF_DIBSource* pDIBSource = m_pMask;
+ m_pMask = nullptr;
+ return pDIBSource;
}
int CPDF_DIBSource::StartLoadMaskDIB() {
- m_pMask = pdfium::MakeRetain<CPDF_DIBSource>();
+ m_pMask = new CPDF_DIBSource;
int ret = m_pMask->StartLoadDIBSource(m_pDocument, m_pMaskStream, false,
nullptr, nullptr, true);
if (ret == 2) {
@@ -744,7 +747,8 @@ int CPDF_DIBSource::StartLoadMaskDIB() {
return 2;
}
if (!ret) {
- m_pMask.Reset();
+ delete m_pMask;
+ m_pMask = nullptr;
return 1;
}
return 1;
diff --git a/core/fpdfapi/render/cpdf_dibsource.h b/core/fpdfapi/render/cpdf_dibsource.h
index c77aac1776..b0f8dedaf7 100644
--- a/core/fpdfapi/render/cpdf_dibsource.h
+++ b/core/fpdfapi/render/cpdf_dibsource.h
@@ -39,9 +39,7 @@ typedef struct {
class CPDF_DIBSource : public CFX_DIBSource {
public:
- template <typename T, typename... Args>
- friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args);
-
+ CPDF_DIBSource();
~CPDF_DIBSource() override;
bool Load(CPDF_Document* pDoc, const CPDF_Stream* pStream);
@@ -73,11 +71,9 @@ class CPDF_DIBSource : public CFX_DIBSource {
int StartLoadMaskDIB();
int ContinueLoadMaskDIB(IFX_Pause* pPause);
int ContinueToLoadMask();
- CFX_RetainPtr<CPDF_DIBSource> DetachMask();
+ CPDF_DIBSource* DetachMask();
private:
- CPDF_DIBSource();
-
bool LoadColorInfo(const CPDF_Dictionary* pFormResources,
const CPDF_Dictionary* pPageResources);
DIB_COMP_DATA* GetDecodeAndMaskArray(bool* bDefaultDecode, bool* bColorKey);
@@ -137,9 +133,9 @@ class CPDF_DIBSource : public CFX_DIBSource {
DIB_COMP_DATA* m_pCompData;
uint8_t* m_pLineBuf;
uint8_t* m_pMaskedLine;
- CFX_RetainPtr<CFX_DIBitmap> m_pCachedBitmap;
- CFX_RetainPtr<CPDF_DIBSource> m_pMask;
+ std::unique_ptr<CFX_DIBitmap> m_pCachedBitmap;
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 d57ec0ff89..d290c00d8a 100644
--- a/core/fpdfapi/render/cpdf_dibtransferfunc.h
+++ b/core/fpdfapi/render/cpdf_dibtransferfunc.h
@@ -15,9 +15,7 @@ class CPDF_TransferFunc;
class CPDF_DIBTransferFunc : public CFX_FilteredDIB {
public:
- template <typename T, typename... Args>
- friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args);
-
+ explicit CPDF_DIBTransferFunc(const CPDF_TransferFunc* pTransferFunc);
~CPDF_DIBTransferFunc() override;
// CFX_FilteredDIB
@@ -31,8 +29,6 @@ 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 751b3eb4b4..82b6117f86 100644
--- a/core/fpdfapi/render/cpdf_imagecacheentry.cpp
+++ b/core/fpdfapi/render/cpdf_imagecacheentry.cpp
@@ -31,27 +31,30 @@ CPDF_ImageCacheEntry::CPDF_ImageCacheEntry(CPDF_Document* pDoc,
CPDF_ImageCacheEntry::~CPDF_ImageCacheEntry() {}
-void CPDF_ImageCacheEntry::Reset(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap) {
- m_pCachedBitmap.Reset();
+void CPDF_ImageCacheEntry::Reset(const CFX_DIBitmap* pBitmap) {
+ m_pCachedBitmap.reset();
if (pBitmap)
m_pCachedBitmap = pBitmap->Clone();
CalcSize();
}
-static uint32_t FPDF_ImageCache_EstimateImageSize(
- const CFX_RetainPtr<CFX_DIBSource>& pDIB) {
+static uint32_t FPDF_ImageCache_EstimateImageSize(const CFX_DIBSource* pDIB) {
return pDIB && pDIB->GetBuffer()
? (uint32_t)pDIB->GetHeight() * pDIB->GetPitch() +
(uint32_t)pDIB->GetPaletteSize() * 4
: 0;
}
-CFX_RetainPtr<CFX_DIBSource> CPDF_ImageCacheEntry::DetachBitmap() {
- return std::move(m_pCurBitmap);
+CFX_DIBSource* CPDF_ImageCacheEntry::DetachBitmap() {
+ CFX_DIBSource* pDIBSource = m_pCurBitmap;
+ m_pCurBitmap = nullptr;
+ return pDIBSource;
}
-CFX_RetainPtr<CFX_DIBSource> CPDF_ImageCacheEntry::DetachMask() {
- return std::move(m_pCurMask);
+CFX_DIBSource* CPDF_ImageCacheEntry::DetachMask() {
+ CFX_DIBSource* pDIBSource = m_pCurMask;
+ m_pCurMask = nullptr;
+ return pDIBSource;
}
int CPDF_ImageCacheEntry::StartGetCachedBitmap(CPDF_Dictionary* pFormResources,
@@ -63,23 +66,25 @@ int CPDF_ImageCacheEntry::StartGetCachedBitmap(CPDF_Dictionary* pFormResources,
int32_t downsampleWidth,
int32_t downsampleHeight) {
if (m_pCachedBitmap) {
- m_pCurBitmap = m_pCachedBitmap;
- m_pCurMask = m_pCachedMask;
+ m_pCurBitmap = m_pCachedBitmap.get();
+ m_pCurMask = m_pCachedMask.get();
return 1;
}
if (!pRenderStatus)
return 0;
m_pRenderStatus = pRenderStatus;
- m_pCurBitmap = pdfium::MakeRetain<CPDF_DIBSource>();
- int ret = m_pCurBitmap.As<CPDF_DIBSource>()->StartLoadDIBSource(
- m_pDocument, m_pStream, true, pFormResources, pPageResources, bStdCS,
- GroupFamily, bLoadMask);
+ m_pCurBitmap = new CPDF_DIBSource;
+ int ret =
+ ((CPDF_DIBSource*)m_pCurBitmap)
+ ->StartLoadDIBSource(m_pDocument, m_pStream, true, pFormResources,
+ pPageResources, bStdCS, GroupFamily, bLoadMask);
if (ret == 2)
return ret;
if (!ret) {
- m_pCurBitmap.Reset();
+ delete m_pCurBitmap;
+ m_pCurBitmap = nullptr;
return 0;
}
ContinueGetCachedBitmap();
@@ -87,41 +92,44 @@ int CPDF_ImageCacheEntry::StartGetCachedBitmap(CPDF_Dictionary* pFormResources,
}
void CPDF_ImageCacheEntry::ContinueGetCachedBitmap() {
- m_MatteColor = m_pCurBitmap.As<CPDF_DIBSource>()->GetMatteColor();
- m_pCurMask = m_pCurBitmap.As<CPDF_DIBSource>()->DetachMask();
+ m_MatteColor = ((CPDF_DIBSource*)m_pCurBitmap)->GetMatteColor();
+ m_pCurMask = ((CPDF_DIBSource*)m_pCurBitmap)->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();
- m_pCurBitmap.Reset();
+ delete m_pCurBitmap;
+ m_pCurBitmap = nullptr;
} else {
- m_pCachedBitmap = m_pCurBitmap;
+ m_pCachedBitmap = pdfium::WrapUnique<CFX_DIBSource>(m_pCurBitmap);
}
if (m_pCurMask) {
m_pCachedMask = m_pCurMask->Clone();
- m_pCurMask.Reset();
+ delete m_pCurMask;
+ m_pCurMask = nullptr;
}
- m_pCurBitmap = m_pCachedBitmap;
- m_pCurMask = m_pCachedMask;
+ m_pCurBitmap = m_pCachedBitmap.get();
+ m_pCurMask = m_pCachedMask.get();
CalcSize();
}
int CPDF_ImageCacheEntry::Continue(IFX_Pause* pPause) {
- int ret = m_pCurBitmap.As<CPDF_DIBSource>()->ContinueLoadDIBSource(pPause);
- if (!ret) {
- m_pCurBitmap.Reset();
- return 0;
- }
+ int ret = ((CPDF_DIBSource*)m_pCurBitmap)->ContinueLoadDIBSource(pPause);
if (ret == 2)
return ret;
+ if (!ret) {
+ delete m_pCurBitmap;
+ m_pCurBitmap = nullptr;
+ return 0;
+ }
ContinueGetCachedBitmap();
return 0;
}
void CPDF_ImageCacheEntry::CalcSize() {
- m_dwCacheSize = FPDF_ImageCache_EstimateImageSize(m_pCachedBitmap) +
- FPDF_ImageCache_EstimateImageSize(m_pCachedMask);
+ m_dwCacheSize = FPDF_ImageCache_EstimateImageSize(m_pCachedBitmap.get()) +
+ FPDF_ImageCache_EstimateImageSize(m_pCachedMask.get());
}
diff --git a/core/fpdfapi/render/cpdf_imagecacheentry.h b/core/fpdfapi/render/cpdf_imagecacheentry.h
index b17d3fdda2..d11fe94c29 100644
--- a/core/fpdfapi/render/cpdf_imagecacheentry.h
+++ b/core/fpdfapi/render/cpdf_imagecacheentry.h
@@ -9,7 +9,6 @@
#include <memory>
-#include "core/fxcrt/cfx_retain_ptr.h"
#include "core/fxcrt/fx_system.h"
class CFX_DIBitmap;
@@ -25,7 +24,7 @@ class CPDF_ImageCacheEntry {
CPDF_ImageCacheEntry(CPDF_Document* pDoc, CPDF_Stream* pStream);
~CPDF_ImageCacheEntry();
- void Reset(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap);
+ void Reset(const CFX_DIBitmap* pBitmap);
uint32_t EstimateSize() const { return m_dwCacheSize; }
uint32_t GetTimeCount() const { return m_dwTimeCount; }
CPDF_Stream* GetStream() const { return m_pStream; }
@@ -39,8 +38,8 @@ class CPDF_ImageCacheEntry {
int32_t downsampleWidth,
int32_t downsampleHeight);
int Continue(IFX_Pause* pPause);
- CFX_RetainPtr<CFX_DIBSource> DetachBitmap();
- CFX_RetainPtr<CFX_DIBSource> DetachMask();
+ CFX_DIBSource* DetachBitmap();
+ CFX_DIBSource* DetachMask();
int m_dwTimeCount;
uint32_t m_MatteColor;
@@ -52,10 +51,10 @@ class CPDF_ImageCacheEntry {
CPDF_RenderStatus* m_pRenderStatus;
CPDF_Document* m_pDocument;
CPDF_Stream* m_pStream;
- CFX_RetainPtr<CFX_DIBSource> m_pCurBitmap;
- CFX_RetainPtr<CFX_DIBSource> m_pCurMask;
- CFX_RetainPtr<CFX_DIBSource> m_pCachedBitmap;
- CFX_RetainPtr<CFX_DIBSource> m_pCachedMask;
+ CFX_DIBSource* m_pCurBitmap;
+ CFX_DIBSource* m_pCurMask;
+ std::unique_ptr<CFX_DIBSource> m_pCachedBitmap;
+ std::unique_ptr<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 856e340325..18213ea695 100644
--- a/core/fpdfapi/render/cpdf_imageloader.cpp
+++ b/core/fpdfapi/render/cpdf_imageloader.cpp
@@ -15,14 +15,21 @@
#include "core/fxcrt/fx_basic.h"
CPDF_ImageLoader::CPDF_ImageLoader()
- : m_MatteColor(0),
+ : m_pBitmap(nullptr),
+ m_pMask(nullptr),
+ m_MatteColor(0),
m_bCached(false),
m_nDownsampleWidth(0),
m_nDownsampleHeight(0),
m_pCache(nullptr),
m_pImage(nullptr) {}
-CPDF_ImageLoader::~CPDF_ImageLoader() {}
+CPDF_ImageLoader::~CPDF_ImageLoader() {
+ if (!m_bCached) {
+ delete m_pBitmap;
+ delete m_pMask;
+ }
+}
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 c7161c3486..a270c45bbf 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_RetainPtr<CFX_DIBSource> m_pBitmap;
- CFX_RetainPtr<CFX_DIBSource> m_pMask;
+ CFX_DIBSource* m_pBitmap;
+ 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 08f9165f8a..d3778452a3 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_pBitmap, !m_Loader.m_bCached);
if (m_Loader.m_bCached && m_Loader.m_pMask)
- m_Loader.m_pMask = m_Loader.m_pMask->Clone();
+ m_Loader.m_pMask = m_Loader.m_pMask->Clone().release();
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;
+ m_pDIBSource = m_pClone.get();
}
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_RetainPtr<CFX_DIBSource>& pDIBSource,
+ const CFX_DIBSource* pDIBSource,
FX_ARGB bitmap_argb,
int bitmap_alpha,
const CFX_Matrix* pImage2Device,
@@ -244,12 +244,11 @@ 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_RetainPtr<CFX_DIBSource>& pDIBSource,
- CFX_Matrix* pNewMatrix,
- const FX_RECT& rect) const {
+void CPDF_ImageRenderer::CalculateDrawImage(CFX_FxgeDevice* pBitmapDevice1,
+ CFX_FxgeDevice* pBitmapDevice2,
+ const 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,
@@ -404,7 +403,7 @@ bool CPDF_ImageRenderer::StartDIBSource() {
}
}
#ifdef _SKIA_SUPPORT_
- CFX_RetainPtr<CFX_DIBitmap> premultiplied = m_pDIBSource->Clone();
+ CFX_DIBitmap* premultiplied = m_pDIBSource->Clone().release();
if (m_pDIBSource->HasAlpha())
CFX_SkiaDeviceDriver::PreMultiply(premultiplied);
if (m_pRenderStatus->m_pDevice->StartDIBitsWithBlend(
@@ -481,10 +480,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);
- CFX_RetainPtr<CFX_DIBitmap> pStretched =
- m_pDIBSource->StretchTo(dest_width, dest_height, m_Flags, &dest_clip);
+ std::unique_ptr<CFX_DIBitmap> pStretched(
+ m_pDIBSource->StretchTo(dest_width, dest_height, m_Flags, &dest_clip));
if (pStretched) {
- m_pRenderStatus->CompositeDIBitmap(pStretched, dest_rect.left,
+ m_pRenderStatus->CompositeDIBitmap(pStretched.get(), dest_rect.left,
dest_rect.top, m_FillArgb, m_BitmapAlpha,
m_BlendType, false);
}
@@ -502,9 +501,9 @@ bool CPDF_ImageRenderer::StartBitmapAlpha() {
FXFILL_WINDING);
return false;
}
- CFX_RetainPtr<CFX_DIBSource> pAlphaMask;
+ CFX_MaybeOwned<CFX_DIBSource> pAlphaMask;
if (m_pDIBSource->IsAlphaMask())
- pAlphaMask = m_pDIBSource;
+ pAlphaMask = const_cast<CFX_DIBSource*>(m_pDIBSource);
else
pAlphaMask = m_pDIBSource->CloneAlphaMask();
@@ -512,13 +511,13 @@ bool CPDF_ImageRenderer::StartBitmapAlpha() {
FXSYS_fabs(m_ImageMatrix.c) >= 0.5f) {
int left;
int top;
- CFX_RetainPtr<CFX_DIBitmap> pTransformed =
+ std::unique_ptr<CFX_DIBitmap> pTransformed =
pAlphaMask->TransformTo(&m_ImageMatrix, left, top);
if (!pTransformed)
return true;
m_pRenderStatus->m_pDevice->SetBitMask(
- pTransformed, left, top,
+ pTransformed.get(), left, top,
ArgbEncode(0xff, m_BitmapAlpha, m_BitmapAlpha, m_BitmapAlpha));
return false;
}
@@ -531,7 +530,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, left, top, dest_width, dest_height,
+ pAlphaMask.Get(), left, top, dest_width, dest_height,
ArgbEncode(0xff, m_BitmapAlpha, m_BitmapAlpha, m_BitmapAlpha));
return false;
}
@@ -541,7 +540,7 @@ bool CPDF_ImageRenderer::Continue(IFX_Pause* pPause) {
if (m_pTransformer->Continue(pPause))
return true;
- CFX_RetainPtr<CFX_DIBitmap> pBitmap = m_pTransformer->DetachBitmap();
+ std::unique_ptr<CFX_DIBitmap> pBitmap(m_pTransformer->DetachBitmap());
if (!pBitmap)
return false;
@@ -549,14 +548,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, m_pTransformer->result().left, m_pTransformer->result().top,
- m_FillArgb);
+ pBitmap.get(), 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, m_pTransformer->result().left, m_pTransformer->result().top,
- m_BlendType);
+ pBitmap.get(), 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 542325449f..d358716e9f 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_RetainPtr<CFX_DIBSource>& pDIBSource,
+ const 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_RetainPtr<CFX_DIBSource>& pDIBSource,
+ const 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;
- CFX_RetainPtr<CFX_DIBSource> m_pDIBSource;
- CFX_RetainPtr<CFX_DIBitmap> m_pClone;
+ const CFX_DIBSource* m_pDIBSource;
+ std::unique_ptr<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 6e6250b1c0..faa9732f9b 100644
--- a/core/fpdfapi/render/cpdf_pagerendercache.cpp
+++ b/core/fpdfapi/render/cpdf_pagerendercache.cpp
@@ -124,9 +124,8 @@ bool CPDF_PageRenderCache::Continue(IFX_Pause* pPause) {
return false;
}
-void CPDF_PageRenderCache::ResetBitmap(
- CPDF_Stream* pStream,
- const CFX_RetainPtr<CFX_DIBitmap>& pBitmap) {
+void CPDF_PageRenderCache::ResetBitmap(CPDF_Stream* pStream,
+ const 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 affd55bbfe..6c9ed76911 100644
--- a/core/fpdfapi/render/cpdf_pagerendercache.h
+++ b/core/fpdfapi/render/cpdf_pagerendercache.h
@@ -9,7 +9,6 @@
#include <map>
-#include "core/fxcrt/cfx_retain_ptr.h"
#include "core/fxcrt/fx_system.h"
class CPDF_Stream;
@@ -28,8 +27,7 @@ class CPDF_PageRenderCache {
void CacheOptimization(int32_t dwLimitCacheSize);
uint32_t GetTimeCount() const { return m_nTimeCount; }
- void ResetBitmap(CPDF_Stream* pStream,
- const CFX_RetainPtr<CFX_DIBitmap>& pBitmap);
+ void ResetBitmap(CPDF_Stream* pStream, const 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 07af2cc172..d74f729858 100644
--- a/core/fpdfapi/render/cpdf_rendercontext.cpp
+++ b/core/fpdfapi/render/cpdf_rendercontext.cpp
@@ -30,11 +30,10 @@ CPDF_RenderContext::CPDF_RenderContext(CPDF_Document* pDoc,
CPDF_RenderContext::~CPDF_RenderContext() {}
-void CPDF_RenderContext::GetBackground(
- const CFX_RetainPtr<CFX_DIBitmap>& pBuffer,
- const CPDF_PageObject* pObj,
- const CPDF_RenderOptions* pOptions,
- CFX_Matrix* pFinalMatrix) {
+void CPDF_RenderContext::GetBackground(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 0cce1ae77e..a9fd2db78b 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(const CFX_RetainPtr<CFX_DIBitmap>& pBuffer,
+ void GetBackground(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 5320422b41..17576fc1f3 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(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+void DrawAxialShading(CFX_DIBitmap* pBitmap,
CFX_Matrix* pObject2Bitmap,
CPDF_Dictionary* pDict,
const std::vector<std::unique_ptr<CPDF_Function>>& funcs,
@@ -183,7 +183,7 @@ void DrawAxialShading(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
}
}
-void DrawRadialShading(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+void DrawRadialShading(CFX_DIBitmap* pBitmap,
CFX_Matrix* pObject2Bitmap,
CPDF_Dictionary* pDict,
const std::vector<std::unique_ptr<CPDF_Function>>& funcs,
@@ -316,7 +316,7 @@ void DrawRadialShading(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
}
}
-void DrawFuncShading(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+void DrawFuncShading(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(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+void DrawGouraud(CFX_DIBitmap* pBitmap,
int alpha,
CPDF_MeshVertex triangle[3]) {
float min_y = triangle[0].position.y;
@@ -473,7 +473,7 @@ void DrawGouraud(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
}
void DrawFreeGouraudShading(
- const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ 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(
- const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ 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,
- const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ CFX_DIBitmap* pBitmap,
CFX_Matrix* pObject2Bitmap,
CPDF_Stream* pShadingStream,
const std::vector<std::unique_ptr<CPDF_Function>>& funcs,
@@ -892,20 +892,21 @@ void DrawCoonPatchMeshes(
}
}
-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>();
+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);
if (!pBitmap->Create(width, height,
pPattern->colored() ? FXDIB_Argb : FXDIB_8bppMask)) {
return nullptr;
}
CFX_FxgeDevice bitmap_device;
- bitmap_device.Attach(pBitmap, false, nullptr, false);
+ bitmap_device.Attach(pBitmap.get(), false, nullptr, false);
pBitmap->Clear(0);
CFX_FloatRect cell_bbox = pPattern->bbox();
pPattern->pattern_to_form()->TransformRect(cell_bbox);
@@ -1530,41 +1531,38 @@ 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;
- CFX_RetainPtr<CFX_DIBitmap> oriDevice;
+ std::unique_ptr<CFX_DIBitmap> oriDevice;
if (!isolated && (m_pDevice->GetRenderCaps() & FXRC_GET_BITS)) {
- oriDevice = pdfium::MakeRetain<CFX_DIBitmap>();
- if (!m_pDevice->CreateCompatibleBitmap(oriDevice, width, height))
+ oriDevice = pdfium::MakeUnique<CFX_DIBitmap>();
+ if (!m_pDevice->CreateCompatibleBitmap(oriDevice.get(), width, height))
return true;
- m_pDevice->GetDIBits(oriDevice, rect.left, rect.top);
+ m_pDevice->GetDIBits(oriDevice.get(), rect.left, rect.top);
}
- if (!bitmap_device.Create(width, height, FXDIB_Argb, oriDevice))
+ if (!bitmap_device.Create(width, height, FXDIB_Argb, oriDevice.get()))
return true;
-
- CFX_RetainPtr<CFX_DIBitmap> bitmap = bitmap_device.GetBitmap();
+ 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);
-
- CFX_RetainPtr<CFX_DIBitmap> pTextMask;
+ std::unique_ptr<CFX_DIBitmap> pTextMask;
if (bTextClip) {
- pTextMask = pdfium::MakeRetain<CFX_DIBitmap>();
+ pTextMask = pdfium::MakeUnique<CFX_DIBitmap>();
if (!pTextMask->Create(width, height, FXDIB_8bppMask))
return true;
pTextMask->Clear(0);
CFX_FxgeDevice text_device;
- text_device.Attach(pTextMask, false, nullptr, false);
+ text_device.Attach(pTextMask.get(), false, nullptr, false);
for (uint32_t i = 0; i < pPageObj->m_ClipPath.GetTextCount(); i++) {
CPDF_TextObject* textobj = pPageObj->m_ClipPath.GetText(i);
if (!textobj)
@@ -1591,14 +1589,14 @@ bool CPDF_RenderStatus::ProcessTransparency(CPDF_PageObject* pPageObj,
if (pSMaskDict) {
CFX_Matrix smask_matrix = *pPageObj->m_GeneralState.GetSMaskMatrix();
smask_matrix.Concat(*pObj2Device);
- CFX_RetainPtr<CFX_DIBSource> pSMaskSource =
+ std::unique_ptr<CFX_DIBSource> pSMaskSource =
LoadSMask(pSMaskDict, &rect, &smask_matrix);
if (pSMaskSource)
- bitmap->MultiplyAlpha(pSMaskSource);
+ bitmap->MultiplyAlpha(pSMaskSource.get());
}
if (pTextMask) {
- bitmap->MultiplyAlpha(pTextMask);
- pTextMask.Reset();
+ bitmap->MultiplyAlpha(pTextMask.get());
+ pTextMask.reset();
}
int32_t blitAlpha = 255;
if (Transparency & PDFTRANS_GROUP && group_alpha != 1.0f) {
@@ -1620,7 +1618,7 @@ bool CPDF_RenderStatus::ProcessTransparency(CPDF_PageObject* pPageObj,
return true;
}
-CFX_RetainPtr<CFX_DIBitmap> CPDF_RenderStatus::GetBackdrop(
+std::unique_ptr<CFX_DIBitmap> CPDF_RenderStatus::GetBackdrop(
const CPDF_PageObject* pObj,
const FX_RECT& rect,
int& left,
@@ -1635,11 +1633,11 @@ CFX_RetainPtr<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::MakeRetain<CFX_DIBitmap>();
+ auto pBackdrop = pdfium::MakeUnique<CFX_DIBitmap>();
if (bBackAlphaRequired && !m_bDropObjects)
pBackdrop->Create(width, height, FXDIB_Argb);
else
- m_pDevice->CreateCompatibleBitmap(pBackdrop, width, height);
+ m_pDevice->CreateCompatibleBitmap(pBackdrop.get(), width, height);
if (!pBackdrop->GetBuffer())
return nullptr;
@@ -1651,16 +1649,16 @@ CFX_RetainPtr<CFX_DIBitmap> CPDF_RenderStatus::GetBackdrop(
bNeedDraw = !(m_pDevice->GetRenderCaps() & FXRC_GET_BITS);
if (!bNeedDraw) {
- m_pDevice->GetDIBits(pBackdrop, left, top);
+ m_pDevice->GetDIBits(pBackdrop.get(), 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, false, nullptr, false);
+ device.Attach(pBackdrop.get(), false, nullptr, false);
m_pContext->Render(&device, pObj, &m_Options, &FinalMatrix);
return pBackdrop;
}
@@ -1850,7 +1848,7 @@ bool CPDF_RenderStatus::ProcessType3Text(CPDF_TextObject* textobj,
if (!glyph.m_pGlyph)
continue;
- m_pDevice->SetBitMask(glyph.m_pGlyph->m_pBitmap,
+ m_pDevice->SetBitMask(&glyph.m_pGlyph->m_Bitmap,
glyph.m_Origin.x + glyph.m_pGlyph->m_Left,
glyph.m_Origin.y - glyph.m_pGlyph->m_Top,
fill_argb);
@@ -1912,7 +1910,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_pBitmap, origin.x + pBitmap->m_Left,
+ m_pDevice->SetBitMask(&pBitmap->m_Bitmap, origin.x + pBitmap->m_Left,
origin.y - pBitmap->m_Top, fill_argb);
} else {
glyphs[iChar].m_pGlyph = pBitmap;
@@ -1922,7 +1920,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, fill_argb, 255,
+ if (renderer.Start(this, pType3Char->m_pBitmap.get(), fill_argb, 255,
&image_matrix, 0, false, FXDIB_BLEND_NORMAL)) {
renderer.Continue(nullptr);
}
@@ -1936,12 +1934,12 @@ bool CPDF_RenderStatus::ProcessType3Text(CPDF_TextObject* textobj,
return true;
FX_RECT rect = FXGE_GetGlyphsBBox(glyphs, 0, sa, sd);
- auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
- if (!pBitmap->Create(static_cast<int>(rect.Width() * sa),
- static_cast<int>(rect.Height() * sd), FXDIB_8bppMask)) {
+ CFX_DIBitmap bitmap;
+ if (!bitmap.Create(static_cast<int>(rect.Width() * sa),
+ static_cast<int>(rect.Height() * sd), FXDIB_8bppMask)) {
return true;
}
- pBitmap->Clear(0);
+ bitmap.Clear(0);
for (const FXTEXT_GLYPHPOS& glyph : glyphs) {
if (!glyph.m_pGlyph)
continue;
@@ -1960,13 +1958,13 @@ bool CPDF_RenderStatus::ProcessType3Text(CPDF_TextObject* textobj,
if (!top.IsValid())
continue;
- 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);
+ 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);
}
- m_pDevice->SetBitMask(pBitmap, rect.left, rect.top, fill_argb);
+ m_pDevice->SetBitMask(&bitmap, rect.left, rect.top, fill_argb);
return true;
}
@@ -2069,7 +2067,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_RetainPtr<CFX_DIBitmap> pBitmap = buffer.GetBitmap();
+ CFX_DIBitmap* pBitmap = buffer.GetBitmap();
if (!pBitmap->GetBuffer())
return;
@@ -2287,9 +2285,9 @@ void CPDF_RenderStatus::DrawTilingPattern(CPDF_TilingPattern* pPattern,
}
float left_offset = cell_bbox.left - mtPattern2Device.e;
float top_offset = cell_bbox.bottom - mtPattern2Device.f;
- CFX_RetainPtr<CFX_DIBitmap> pPatternBitmap;
+ std::unique_ptr<CFX_DIBitmap> pPatternBitmap;
if (width * height < 16) {
- CFX_RetainPtr<CFX_DIBitmap> pEnlargedBitmap =
+ std::unique_ptr<CFX_DIBitmap> pEnlargedBitmap =
DrawPatternBitmap(m_pContext->GetDocument(), m_pContext->GetPageCache(),
pPattern, pObj2Device, 8, 8, m_Options.m_Flags);
pPatternBitmap = pEnlargedBitmap->StretchTo(width, height);
@@ -2309,11 +2307,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;
- auto pScreen = pdfium::MakeRetain<CFX_DIBitmap>();
- if (!pScreen->Create(clip_width, clip_height, FXDIB_Argb))
+ CFX_DIBitmap screen;
+ if (!screen.Create(clip_width, clip_height, FXDIB_Argb)) {
return;
-
- pScreen->Clear(0);
+ }
+ screen.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++) {
@@ -2344,7 +2342,7 @@ void CPDF_RenderStatus::DrawTilingPattern(CPDF_TilingPattern* pPattern,
continue;
}
uint32_t* dest_buf =
- (uint32_t*)(pScreen->GetBuffer() + pScreen->GetPitch() * start_y +
+ (uint32_t*)(screen.GetBuffer() + screen.GetPitch() * start_y +
start_x * 4);
if (pPattern->colored())
*dest_buf = *src_buf;
@@ -2352,16 +2350,16 @@ void CPDF_RenderStatus::DrawTilingPattern(CPDF_TilingPattern* pPattern,
*dest_buf = (*(uint8_t*)src_buf << 24) | (fill_argb & 0xffffff);
} else {
if (pPattern->colored()) {
- pScreen->CompositeBitmap(start_x, start_y, width, height,
- pPatternBitmap, 0, 0);
+ screen.CompositeBitmap(start_x, start_y, width, height,
+ pPatternBitmap.get(), 0, 0);
} else {
- pScreen->CompositeMask(start_x, start_y, width, height,
- pPatternBitmap, fill_argb, 0, 0);
+ screen.CompositeMask(start_x, start_y, width, height,
+ pPatternBitmap.get(), fill_argb, 0, 0);
}
}
}
}
- CompositeDIBitmap(pScreen, clip_box.left, clip_box.top, 0, 255,
+ CompositeDIBitmap(&screen, clip_box.left, clip_box.top, 0, 255,
FXDIB_BLEND_NORMAL, false);
m_pDevice->RestoreState(false);
}
@@ -2408,17 +2406,16 @@ bool CPDF_RenderStatus::ProcessImage(CPDF_ImageObject* pImageObj,
return render.GetResult();
}
-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)
+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) {
return;
-
+ }
if (blend_mode == FXDIB_BLEND_NORMAL) {
if (!pDIBitmap->IsAlphaMask()) {
if (bitmap_alpha < 255) {
@@ -2466,10 +2463,10 @@ void CPDF_RenderStatus::CompositeDIBitmap(
FX_RECT rect(left, top, left + pDIBitmap->GetWidth(),
top + pDIBitmap->GetHeight());
rect.Intersect(m_pDevice->GetClipBox());
- CFX_RetainPtr<CFX_DIBitmap> pClone;
+ CFX_MaybeOwned<CFX_DIBitmap> pClone;
if (m_pDevice->GetBackDrop() && m_pDevice->GetBitmap()) {
pClone = m_pDevice->GetBackDrop()->Clone(&rect);
- CFX_RetainPtr<CFX_DIBitmap> pForeBitmap = m_pDevice->GetBitmap();
+ CFX_DIBitmap* pForeBitmap = m_pDevice->GetBitmap();
pClone->CompositeBitmap(0, 0, pClone->GetWidth(), pClone->GetHeight(),
pForeBitmap, rect.left, rect.top);
left = left >= 0 ? 0 : left;
@@ -2484,7 +2481,7 @@ void CPDF_RenderStatus::CompositeDIBitmap(
pClone = pDIBitmap;
}
if (m_pDevice->GetBackDrop()) {
- m_pDevice->SetDIBits(pClone, rect.left, rect.top);
+ m_pDevice->SetDIBits(pClone.Get(), rect.left, rect.top);
} else {
if (pDIBitmap->IsAlphaMask())
return;
@@ -2497,7 +2494,7 @@ void CPDF_RenderStatus::CompositeDIBitmap(
int back_left, back_top;
FX_RECT rect(left, top, left + pDIBitmap->GetWidth(),
top + pDIBitmap->GetHeight());
- CFX_RetainPtr<CFX_DIBitmap> pBackdrop =
+ std::unique_ptr<CFX_DIBitmap> pBackdrop =
GetBackdrop(m_pCurObj, rect, back_left, back_top,
blend_mode > FXDIB_BLEND_NORMAL && bIsolated);
if (!pBackdrop)
@@ -2513,17 +2510,17 @@ void CPDF_RenderStatus::CompositeDIBitmap(
pDIBitmap, mask_argb, 0, 0, blend_mode);
}
- auto pBackdrop1 = pdfium::MakeRetain<CFX_DIBitmap>();
+ auto pBackdrop1 = pdfium::MakeUnique<CFX_DIBitmap>();
pBackdrop1->Create(pBackdrop->GetWidth(), pBackdrop->GetHeight(),
FXDIB_Rgb32);
pBackdrop1->Clear((uint32_t)-1);
pBackdrop1->CompositeBitmap(0, 0, pBackdrop->GetWidth(),
- pBackdrop->GetHeight(), pBackdrop, 0, 0);
+ pBackdrop->GetHeight(), pBackdrop.get(), 0, 0);
pBackdrop = std::move(pBackdrop1);
- m_pDevice->SetDIBits(pBackdrop, back_left, back_top);
+ m_pDevice->SetDIBits(pBackdrop.get(), back_left, back_top);
}
-CFX_RetainPtr<CFX_DIBitmap> CPDF_RenderStatus::LoadSMask(
+std::unique_ptr<CFX_DIBitmap> CPDF_RenderStatus::LoadSMask(
CPDF_Dictionary* pSMaskDict,
FX_RECT* pClipRect,
const CFX_Matrix* pMatrix) {
@@ -2616,7 +2613,7 @@ CFX_RetainPtr<CFX_DIBitmap> CPDF_RenderStatus::LoadSMask(
nullptr, 0, color_space_family, bLuminosity);
status.RenderObjectList(&form, &matrix);
- auto pMask = pdfium::MakeRetain<CFX_DIBitmap>();
+ auto pMask = pdfium::MakeUnique<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 e3dcd73e6d..6ae255271b 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(const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap,
+ void CompositeDIBitmap(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);
- 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);
+ 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);
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 ed1f27dfad..be4836d20a 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_RetainPtr<CFX_DIBSource> CPDF_TransferFunc::TranslateImage(
- const CFX_RetainPtr<CFX_DIBSource>& pSrc) {
- auto pDest = pdfium::MakeRetain<CPDF_DIBTransferFunc>(this);
- pDest->LoadSrc(pSrc);
+CFX_DIBSource* CPDF_TransferFunc::TranslateImage(const CFX_DIBSource* pSrc,
+ bool bAutoDropSrc) {
+ CPDF_DIBTransferFunc* pDest = new CPDF_DIBTransferFunc(this);
+ pDest->LoadSrc(pSrc, bAutoDropSrc);
return pDest;
}
diff --git a/core/fpdfapi/render/cpdf_transferfunc.h b/core/fpdfapi/render/cpdf_transferfunc.h
index 05219d49db..829b274d9b 100644
--- a/core/fpdfapi/render/cpdf_transferfunc.h
+++ b/core/fpdfapi/render/cpdf_transferfunc.h
@@ -16,8 +16,7 @@ class CPDF_TransferFunc {
explicit CPDF_TransferFunc(CPDF_Document* pDoc);
FX_COLORREF TranslateColor(FX_COLORREF src) const;
- CFX_RetainPtr<CFX_DIBSource> TranslateImage(
- const CFX_RetainPtr<CFX_DIBSource>& pSrc);
+ CFX_DIBSource* TranslateImage(const CFX_DIBSource* pSrc, bool bAutoDropSrc);
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 1ba9f66203..7d0cb18172 100644
--- a/core/fpdfapi/render/cpdf_type3cache.cpp
+++ b/core/fpdfapi/render/cpdf_type3cache.cpp
@@ -8,7 +8,6 @@
#include <map>
#include <memory>
-#include <utility>
#include "core/fpdfapi/font/cpdf_type3char.h"
#include "core/fpdfapi/font/cpdf_type3font.h"
@@ -52,8 +51,7 @@ bool IsScanLine8bpp(uint8_t* pBuf, int width) {
return false;
}
-int DetectFirstLastScan(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
- bool bFirst) {
+int DetectFirstLastScan(const CFX_DIBitmap* pBitmap, bool bFirst) {
int height = pBitmap->GetHeight();
int pitch = pBitmap->GetPitch();
int width = pBitmap->GetWidth();
@@ -123,12 +121,12 @@ CFX_GlyphBitmap* CPDF_Type3Cache::RenderGlyph(CPDF_Type3Glyphs* pSize,
if (!pChar || !pChar->m_pBitmap)
return nullptr;
- CFX_RetainPtr<CFX_DIBitmap> pBitmap = pChar->m_pBitmap;
+ CFX_DIBitmap* pBitmap = pChar->m_pBitmap.get();
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);
- CFX_RetainPtr<CFX_DIBitmap> pResBitmap;
+ std::unique_ptr<CFX_DIBitmap> pResBitmap;
int left = 0;
int top = 0;
if (FXSYS_fabs(image_matrix.b) < FXSYS_fabs(image_matrix.a) / 100 &&
@@ -168,6 +166,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_pBitmap->TakeOver(std::move(pResBitmap));
+ pGlyph->m_Bitmap.TakeOver(pResBitmap.get());
return pGlyph;
}