summaryrefslogtreecommitdiff
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
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>
-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
-rw-r--r--core/fxcodec/codec/ccodec_jpegmodule.h2
-rw-r--r--core/fxcodec/codec/ccodec_progressivedecoder.h32
-rw-r--r--core/fxcodec/codec/ccodec_tiffmodule.cpp56
-rw-r--r--core/fxcodec/codec/ccodec_tiffmodule.h3
-rw-r--r--core/fxcodec/codec/fx_codec_jpeg.cpp2
-rw-r--r--core/fxcodec/codec/fx_codec_progress.cpp90
-rw-r--r--core/fxcodec/codec/icodec_tiffmodule.h2
-rw-r--r--core/fxge/agg/fx_agg_driver.cpp135
-rw-r--r--core/fxge/agg/fx_agg_driver.h20
-rw-r--r--core/fxge/apple/apple_int.h2
-rw-r--r--core/fxge/apple/fx_apple_platform.cpp2
-rw-r--r--core/fxge/apple/fx_quartz_device.cpp2
-rw-r--r--core/fxge/cfx_fxgedevice.h13
-rw-r--r--core/fxge/cfx_renderdevice.h53
-rw-r--r--core/fxge/dib/dib_int.h4
-rw-r--r--core/fxge/dib/fx_dib_composite.cpp42
-rw-r--r--core/fxge/dib/fx_dib_convert.cpp122
-rw-r--r--core/fxge/dib/fx_dib_engine.cpp15
-rw-r--r--core/fxge/dib/fx_dib_engine_unittest.cpp8
-rw-r--r--core/fxge/dib/fx_dib_main.cpp170
-rw-r--r--core/fxge/dib/fx_dib_transform.cpp38
-rw-r--r--core/fxge/fx_dib.h146
-rw-r--r--core/fxge/fx_font.h10
-rw-r--r--core/fxge/ge/cfx_cliprgn.cpp43
-rw-r--r--core/fxge/ge/cfx_cliprgn.h12
-rw-r--r--core/fxge/ge/cfx_facecache.cpp6
-rw-r--r--core/fxge/ge/cfx_renderdevice.cpp183
-rw-r--r--core/fxge/ge/fx_ge_text.cpp4
-rw-r--r--core/fxge/ifx_renderdevicedriver.cpp24
-rw-r--r--core/fxge/ifx_renderdevicedriver.h17
-rw-r--r--core/fxge/skia/fx_skia_device.cpp151
-rw-r--r--core/fxge/skia/fx_skia_device.h30
-rw-r--r--core/fxge/skia/fx_skia_device_unittest.cpp2
-rw-r--r--core/fxge/win32/cfx_psrenderer.cpp21
-rw-r--r--core/fxge/win32/cfx_psrenderer.h6
-rw-r--r--core/fxge/win32/cfx_windowsdib.h24
-rw-r--r--core/fxge/win32/dwrite_int.h3
-rw-r--r--core/fxge/win32/fx_win32_device.cpp165
-rw-r--r--core/fxge/win32/fx_win32_dib.cpp52
-rw-r--r--core/fxge/win32/fx_win32_dwrite.cpp27
-rw-r--r--core/fxge/win32/fx_win32_gdipext.cpp41
-rw-r--r--core/fxge/win32/fx_win32_print.cpp69
-rw-r--r--core/fxge/win32/win32_int.h39
-rw-r--r--fpdfsdk/fpdf_progressive.cpp15
-rw-r--r--fpdfsdk/fpdfeditimg.cpp3
-rw-r--r--fpdfsdk/fpdfformfill.cpp7
-rw-r--r--fpdfsdk/fpdfview.cpp38
-rw-r--r--testing/libfuzzer/pdf_codec_jbig2_fuzzer.cc2
-rw-r--r--testing/libfuzzer/pdf_jpx_fuzzer.cc3
-rw-r--r--testing/libfuzzer/xfa_codec_fuzzer.h4
-rw-r--r--xfa/fde/fde_gedevice.cpp2
-rw-r--r--xfa/fde/fde_gedevice.h2
-rw-r--r--xfa/fde/tto/fde_textout.cpp2
-rw-r--r--xfa/fde/tto/fde_textout.h2
-rw-r--r--xfa/fwl/cfwl_themebackground.h11
-rw-r--r--xfa/fxbarcode/BC_TwoDimWriter.cpp13
-rw-r--r--xfa/fxbarcode/BC_TwoDimWriter.h4
-rw-r--r--xfa/fxbarcode/BC_Writer.cpp6
-rw-r--r--xfa/fxbarcode/BC_Writer.h2
-rw-r--r--xfa/fxbarcode/cbc_codabar.cpp3
-rw-r--r--xfa/fxbarcode/cbc_codabar.h3
-rw-r--r--xfa/fxbarcode/cbc_code128.cpp7
-rw-r--r--xfa/fxbarcode/cbc_code128.h3
-rw-r--r--xfa/fxbarcode/cbc_code39.cpp7
-rw-r--r--xfa/fxbarcode/cbc_code39.h3
-rw-r--r--xfa/fxbarcode/cbc_codebase.h3
-rw-r--r--xfa/fxbarcode/cbc_datamatrix.cpp7
-rw-r--r--xfa/fxbarcode/cbc_datamatrix.h3
-rw-r--r--xfa/fxbarcode/cbc_ean13.cpp7
-rw-r--r--xfa/fxbarcode/cbc_ean13.h3
-rw-r--r--xfa/fxbarcode/cbc_ean8.cpp7
-rw-r--r--xfa/fxbarcode/cbc_ean8.h3
-rw-r--r--xfa/fxbarcode/cbc_pdf417i.cpp7
-rw-r--r--xfa/fxbarcode/cbc_pdf417i.h3
-rw-r--r--xfa/fxbarcode/cbc_qrcode.cpp7
-rw-r--r--xfa/fxbarcode/cbc_qrcode.h3
-rw-r--r--xfa/fxbarcode/cbc_upca.cpp7
-rw-r--r--xfa/fxbarcode/cbc_upca.h3
-rw-r--r--xfa/fxbarcode/oned/BC_OneDimWriter.cpp35
-rw-r--r--xfa/fxbarcode/oned/BC_OneDimWriter.h6
-rw-r--r--xfa/fxbarcode/oned/BC_OnedEAN13Writer.cpp16
-rw-r--r--xfa/fxbarcode/oned/BC_OnedEAN13Writer.h2
-rw-r--r--xfa/fxbarcode/oned/BC_OnedEAN8Writer.cpp17
-rw-r--r--xfa/fxbarcode/oned/BC_OnedEAN8Writer.h2
-rw-r--r--xfa/fxbarcode/oned/BC_OnedUPCAWriter.cpp17
-rw-r--r--xfa/fxbarcode/oned/BC_OnedUPCAWriter.h2
-rw-r--r--xfa/fxfa/app/xfa_ffimage.cpp2
-rw-r--r--xfa/fxfa/app/xfa_ffimageedit.cpp2
-rw-r--r--xfa/fxfa/cxfa_ffdoc.cpp15
-rw-r--r--xfa/fxfa/cxfa_ffdoc.h27
-rw-r--r--xfa/fxfa/cxfa_ffwidget.cpp91
-rw-r--r--xfa/fxfa/cxfa_ffwidget.h14
-rw-r--r--xfa/fxfa/cxfa_widgetacc.cpp58
-rw-r--r--xfa/fxfa/cxfa_widgetacc.h8
-rw-r--r--xfa/fxgraphics/cfx_graphics.cpp74
-rw-r--r--xfa/fxgraphics/cfx_graphics.h7
121 files changed, 1478 insertions, 1543 deletions
diff --git a/core/fpdfapi/font/cpdf_type3char.cpp b/core/fpdfapi/font/cpdf_type3char.cpp
index 4f116a1afb..5eb12c1752 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();
- CFX_RetainPtr<CFX_DIBSource> pSource =
+ std::unique_ptr<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 3215802e0c..549f49e3da 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;
- CFX_RetainPtr<CFX_DIBitmap> m_pBitmap;
+ std::unique_ptr<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 1c5ddee4e0..ddc33ac800 100644
--- a/core/fpdfapi/page/cpdf_generalstate.h
+++ b/core/fpdfapi/page/cpdf_generalstate.h
@@ -7,7 +7,6 @@
#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 4fc1c344ef..3de0511771 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_RetainPtr<CFX_DIBitmap>& pBitmap) {
+void CPDF_Image::SetImage(const 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_RetainPtr<CFX_DIBitmap>& pBitmap) {
bCopyWithoutAlpha = false;
}
- CFX_RetainPtr<CFX_DIBitmap> pMaskBitmap;
+ std::unique_ptr<CFX_DIBitmap> pMaskBitmap;
if (pBitmap->HasAlpha())
pMaskBitmap = pBitmap->CloneAlphaMask();
@@ -320,25 +320,28 @@ void CPDF_Image::SetImage(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap) {
FX_Free(dest_buf);
}
-void CPDF_Image::ResetCache(CPDF_Page* pPage,
- const CFX_RetainPtr<CFX_DIBitmap>& pBitmap) {
+void CPDF_Image::ResetCache(CPDF_Page* pPage, const CFX_DIBitmap* pBitmap) {
pPage->GetRenderCache()->ResetBitmap(m_pStream.Get(), pBitmap);
}
-CFX_RetainPtr<CFX_DIBSource> CPDF_Image::LoadDIBSource() const {
- auto source = pdfium::MakeRetain<CPDF_DIBSource>();
+std::unique_ptr<CFX_DIBSource> CPDF_Image::LoadDIBSource() const {
+ auto source = pdfium::MakeUnique<CPDF_DIBSource>();
if (!source->Load(m_pDocument, m_pStream.Get()))
return nullptr;
- return source;
+ return std::move(source);
}
-CFX_RetainPtr<CFX_DIBSource> CPDF_Image::DetachBitmap() {
- return std::move(m_pDIBSource);
+CFX_DIBSource* CPDF_Image::DetachBitmap() {
+ CFX_DIBSource* pBitmap = m_pDIBSource;
+ m_pDIBSource = nullptr;
+ return pBitmap;
}
-CFX_RetainPtr<CFX_DIBSource> CPDF_Image::DetachMask() {
- return std::move(m_pMask);
+CFX_DIBSource* CPDF_Image::DetachMask() {
+ CFX_DIBSource* pBitmap = m_pMask;
+ m_pMask = nullptr;
+ return pBitmap;
}
bool CPDF_Image::StartLoadDIBSource(CPDF_Dictionary* pFormResource,
@@ -346,33 +349,35 @@ bool CPDF_Image::StartLoadDIBSource(CPDF_Dictionary* pFormResource,
bool bStdCS,
uint32_t GroupFamily,
bool bLoadMask) {
- auto source = pdfium::MakeRetain<CPDF_DIBSource>();
+ auto source = pdfium::MakeUnique<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.Reset();
+ m_pDIBSource = nullptr;
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) {
- CFX_RetainPtr<CPDF_DIBSource> pSource = m_pDIBSource.As<CPDF_DIBSource>();
+ CPDF_DIBSource* pSource = static_cast<CPDF_DIBSource*>(m_pDIBSource);
int ret = pSource->ContinueLoadDIBSource(pPause);
+ if (ret == 2) {
+ return true;
+ }
if (!ret) {
- m_pDIBSource.Reset();
+ delete m_pDIBSource;
+ m_pDIBSource = nullptr;
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 5b737e67b9..1909498102 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; }
- CFX_RetainPtr<CFX_DIBSource> LoadDIBSource() const;
+ std::unique_ptr<CFX_DIBSource> LoadDIBSource() const;
- void SetImage(const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap);
+ void SetImage(const 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_RetainPtr<CFX_DIBitmap>& pDIBitmap);
+ void ResetCache(CPDF_Page* pPage, const 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_RetainPtr<CFX_DIBSource> DetachBitmap();
- CFX_RetainPtr<CFX_DIBSource> DetachMask();
+ CFX_DIBSource* DetachBitmap();
+ CFX_DIBSource* DetachMask();
- CFX_RetainPtr<CFX_DIBSource> m_pDIBSource;
- CFX_RetainPtr<CFX_DIBSource> m_pMask;
+ CFX_DIBSource* m_pDIBSource = nullptr;
+ CFX_DIBSource* m_pMask = nullptr;
uint32_t m_MatteColor = 0;
private:
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;
}
diff --git a/core/fxcodec/codec/ccodec_jpegmodule.h b/core/fxcodec/codec/ccodec_jpegmodule.h
index 7782b5fad1..bad6fa6a94 100644
--- a/core/fxcodec/codec/ccodec_jpegmodule.h
+++ b/core/fxcodec/codec/ccodec_jpegmodule.h
@@ -60,7 +60,7 @@ class CCodec_JpegModule {
uint32_t GetAvailInput(FXJPEG_Context* pContext, uint8_t** avail_buf_ptr);
#if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_DESKTOP_
- static bool JpegEncode(const CFX_RetainPtr<CFX_DIBSource>& pSource,
+ static bool JpegEncode(const CFX_DIBSource* pSource,
uint8_t** dest_buf,
FX_STRSIZE* dest_size);
#endif
diff --git a/core/fxcodec/codec/ccodec_progressivedecoder.h b/core/fxcodec/codec/ccodec_progressivedecoder.h
index cd96ee76a0..61703dde29 100644
--- a/core/fxcodec/codec/ccodec_progressivedecoder.h
+++ b/core/fxcodec/codec/ccodec_progressivedecoder.h
@@ -58,7 +58,7 @@ class CCodec_ProgressiveDecoder : public ICodec_BmpModule::Delegate,
void SetClipBox(FX_RECT* clip);
FXCODEC_STATUS GetFrames(int32_t& frames, IFX_Pause* pPause = nullptr);
- FXCODEC_STATUS StartDecode(const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap,
+ FXCODEC_STATUS StartDecode(CFX_DIBitmap* pDIBitmap,
int start_x,
int start_y,
int size_x,
@@ -138,7 +138,7 @@ class CCodec_ProgressiveDecoder : public ICodec_BmpModule::Delegate,
uint32_t m_SrcSize;
uint8_t* m_pDecodeBuf;
int m_ScanlineSize;
- CFX_RetainPtr<CFX_DIBitmap> m_pDeviceBitmap;
+ CFX_DIBitmap* m_pDeviceBitmap;
bool m_bInterpol;
CFXCODEC_WeightTable m_WeightHorz;
CFXCODEC_VertTable m_WeightVert;
@@ -201,35 +201,29 @@ class CCodec_ProgressiveDecoder : public ICodec_BmpModule::Delegate,
FXCODEC_STATUS& err_status);
bool GifReadMoreData(ICodec_GifModule* pGifModule,
FXCODEC_STATUS& err_status);
- void GifDoubleLineResampleVert(
- const CFX_RetainPtr<CFX_DIBitmap>& pDeviceBitmap,
- double scale_y,
- int des_row);
- void PngOneOneMapResampleHorz(
- const CFX_RetainPtr<CFX_DIBitmap>& pDeviceBitmap,
- int32_t des_line,
- uint8_t* src_scan,
- FXCodec_Format src_format);
+ void GifDoubleLineResampleVert(CFX_DIBitmap* pDeviceBitmap,
+ double scale_y,
+ int des_row);
+ void PngOneOneMapResampleHorz(CFX_DIBitmap* pDeviceBitmap,
+ int32_t des_line,
+ uint8_t* src_scan,
+ FXCodec_Format src_format);
bool DetectImageType(FXCODEC_IMAGE_TYPE imageType,
CFX_DIBAttribute* pAttribute);
void GetDownScale(int& down_scale);
void GetTransMethod(FXDIB_Format des_format, FXCodec_Format src_format);
- void ReSampleScanline(const CFX_RetainPtr<CFX_DIBitmap>& pDeviceBitmap,
+ void ReSampleScanline(CFX_DIBitmap* pDeviceBitmap,
int32_t des_line,
uint8_t* src_scan,
FXCodec_Format src_format);
- void Resample(const CFX_RetainPtr<CFX_DIBitmap>& pDeviceBitmap,
+ void Resample(CFX_DIBitmap* pDeviceBitmap,
int32_t src_line,
uint8_t* src_scan,
FXCodec_Format src_format);
- void ResampleVert(const CFX_RetainPtr<CFX_DIBitmap>& pDeviceBitmap,
- double scale_y,
- int des_row);
+ void ResampleVert(CFX_DIBitmap* pDeviceBitmap, double scale_y, int des_row);
bool JpegReadMoreData(CCodec_JpegModule* pJpegModule,
FXCODEC_STATUS& err_status);
- void ResampleVertBT(const CFX_RetainPtr<CFX_DIBitmap>& pDeviceBitmap,
- double scale_y,
- int des_row);
+ void ResampleVertBT(CFX_DIBitmap* pDeviceBitmap, double scale_y, int des_row);
};
#endif // CORE_FXCODEC_CODEC_CCODEC_PROGRESSIVEDECODER_H_
diff --git a/core/fxcodec/codec/ccodec_tiffmodule.cpp b/core/fxcodec/codec/ccodec_tiffmodule.cpp
index 0a0b56ce94..3807ec75aa 100644
--- a/core/fxcodec/codec/ccodec_tiffmodule.cpp
+++ b/core/fxcodec/codec/ccodec_tiffmodule.cpp
@@ -31,26 +31,26 @@ class CCodec_TiffContext {
int32_t* comps,
int32_t* bpc,
CFX_DIBAttribute* pAttribute);
- bool Decode(const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap);
+ bool Decode(CFX_DIBitmap* pDIBitmap);
CFX_RetainPtr<IFX_SeekableReadStream> io_in() const { return m_io_in; }
uint32_t offset() const { return m_offset; }
void set_offset(uint32_t offset) { m_offset = offset; }
private:
- bool IsSupport(const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap) const;
- void SetPalette(const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap, uint16_t bps);
- bool Decode1bppRGB(const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap,
+ bool IsSupport(const CFX_DIBitmap* pDIBitmap) const;
+ void SetPalette(CFX_DIBitmap* pDIBitmap, uint16_t bps);
+ bool Decode1bppRGB(CFX_DIBitmap* pDIBitmap,
int32_t height,
int32_t width,
uint16_t bps,
uint16_t spp);
- bool Decode8bppRGB(const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap,
+ bool Decode8bppRGB(CFX_DIBitmap* pDIBitmap,
int32_t height,
int32_t width,
uint16_t bps,
uint16_t spp);
- bool Decode24bppRGB(const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap,
+ bool Decode24bppRGB(CFX_DIBitmap* pDIBitmap,
int32_t height,
int32_t width,
uint16_t bps,
@@ -287,8 +287,7 @@ bool CCodec_TiffContext::LoadFrameInfo(int32_t frame,
return true;
}
-bool CCodec_TiffContext::IsSupport(
- const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap) const {
+bool CCodec_TiffContext::IsSupport(const CFX_DIBitmap* pDIBitmap) const {
if (TIFFIsTiled(m_tif_ctx))
return false;
@@ -318,9 +317,7 @@ bool CCodec_TiffContext::IsSupport(
return planarconfig != PLANARCONFIG_SEPARATE;
}
-void CCodec_TiffContext::SetPalette(
- const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap,
- uint16_t bps) {
+void CCodec_TiffContext::SetPalette(CFX_DIBitmap* pDIBitmap, uint16_t bps) {
uint16_t* red_orig = nullptr;
uint16_t* green_orig = nullptr;
uint16_t* blue_orig = nullptr;
@@ -343,12 +340,11 @@ void CCodec_TiffContext::SetPalette(
}
}
-bool CCodec_TiffContext::Decode1bppRGB(
- const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap,
- int32_t height,
- int32_t width,
- uint16_t bps,
- uint16_t spp) {
+bool CCodec_TiffContext::Decode1bppRGB(CFX_DIBitmap* pDIBitmap,
+ int32_t height,
+ int32_t width,
+ uint16_t bps,
+ uint16_t spp) {
if (pDIBitmap->GetBPP() != 1 || spp != 1 || bps != 1 ||
!IsSupport(pDIBitmap)) {
return false;
@@ -372,12 +368,11 @@ bool CCodec_TiffContext::Decode1bppRGB(
return true;
}
-bool CCodec_TiffContext::Decode8bppRGB(
- const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap,
- int32_t height,
- int32_t width,
- uint16_t bps,
- uint16_t spp) {
+bool CCodec_TiffContext::Decode8bppRGB(CFX_DIBitmap* pDIBitmap,
+ int32_t height,
+ int32_t width,
+ uint16_t bps,
+ uint16_t spp) {
if (pDIBitmap->GetBPP() != 8 || spp != 1 || (bps != 4 && bps != 8) ||
!IsSupport(pDIBitmap)) {
return false;
@@ -409,12 +404,11 @@ bool CCodec_TiffContext::Decode8bppRGB(
return true;
}
-bool CCodec_TiffContext::Decode24bppRGB(
- const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap,
- int32_t height,
- int32_t width,
- uint16_t bps,
- uint16_t spp) {
+bool CCodec_TiffContext::Decode24bppRGB(CFX_DIBitmap* pDIBitmap,
+ int32_t height,
+ int32_t width,
+ uint16_t bps,
+ uint16_t spp) {
if (pDIBitmap->GetBPP() != 24 || !IsSupport(pDIBitmap))
return false;
@@ -438,7 +432,7 @@ bool CCodec_TiffContext::Decode24bppRGB(
return true;
}
-bool CCodec_TiffContext::Decode(const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap) {
+bool CCodec_TiffContext::Decode(CFX_DIBitmap* pDIBitmap) {
uint32_t img_wid = pDIBitmap->GetWidth();
uint32_t img_hei = pDIBitmap->GetHeight();
uint32_t width = 0;
@@ -499,7 +493,7 @@ bool CCodec_TiffModule::LoadFrameInfo(CCodec_TiffContext* ctx,
}
bool CCodec_TiffModule::Decode(CCodec_TiffContext* ctx,
- const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap) {
+ class CFX_DIBitmap* pDIBitmap) {
return ctx->Decode(pDIBitmap);
}
diff --git a/core/fxcodec/codec/ccodec_tiffmodule.h b/core/fxcodec/codec/ccodec_tiffmodule.h
index 8878ad504e..a8820f4aac 100644
--- a/core/fxcodec/codec/ccodec_tiffmodule.h
+++ b/core/fxcodec/codec/ccodec_tiffmodule.h
@@ -24,8 +24,7 @@ class CCodec_TiffModule : public ICodec_TiffModule {
int32_t* comps,
int32_t* bpc,
CFX_DIBAttribute* pAttribute) override;
- bool Decode(CCodec_TiffContext* ctx,
- const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap) override;
+ bool Decode(CCodec_TiffContext* ctx, class CFX_DIBitmap* pDIBitmap) override;
void DestroyDecoder(CCodec_TiffContext* ctx) override;
};
diff --git a/core/fxcodec/codec/fx_codec_jpeg.cpp b/core/fxcodec/codec/fx_codec_jpeg.cpp
index 0431560529..c797605575 100644
--- a/core/fxcodec/codec/fx_codec_jpeg.cpp
+++ b/core/fxcodec/codec/fx_codec_jpeg.cpp
@@ -484,7 +484,7 @@ uint32_t CCodec_JpegModule::GetAvailInput(FXJPEG_Context* ctx,
#if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_DESKTOP_
#define JPEG_BLOCK_SIZE 1048576
-bool CCodec_JpegModule::JpegEncode(const CFX_RetainPtr<CFX_DIBSource>& pSource,
+bool CCodec_JpegModule::JpegEncode(const CFX_DIBSource* pSource,
uint8_t** dest_buf,
FX_STRSIZE* dest_size) {
struct jpeg_error_mgr jerr;
diff --git a/core/fxcodec/codec/fx_codec_progress.cpp b/core/fxcodec/codec/fx_codec_progress.cpp
index bd890f89ff..af7f24e4fe 100644
--- a/core/fxcodec/codec/fx_codec_progress.cpp
+++ b/core/fxcodec/codec/fx_codec_progress.cpp
@@ -404,7 +404,7 @@ bool CCodec_ProgressiveDecoder::PngReadHeader(int width,
}
bool CCodec_ProgressiveDecoder::PngAskScanlineBuf(int line, uint8_t*& src_buf) {
- CFX_RetainPtr<CFX_DIBitmap> pDIBitmap = m_pDeviceBitmap;
+ CFX_DIBitmap* pDIBitmap = m_pDeviceBitmap;
if (!pDIBitmap) {
ASSERT(false);
return false;
@@ -473,7 +473,7 @@ bool CCodec_ProgressiveDecoder::PngAskScanlineBuf(int line, uint8_t*& src_buf) {
}
void CCodec_ProgressiveDecoder::PngOneOneMapResampleHorz(
- const CFX_RetainPtr<CFX_DIBitmap>& pDeviceBitmap,
+ CFX_DIBitmap* pDeviceBitmap,
int32_t des_line,
uint8_t* src_scan,
FXCodec_Format src_format) {
@@ -546,7 +546,7 @@ void CCodec_ProgressiveDecoder::PngOneOneMapResampleHorz(
void CCodec_ProgressiveDecoder::PngFillScanlineBufCompleted(int pass,
int line) {
- CFX_RetainPtr<CFX_DIBitmap> pDIBitmap = m_pDeviceBitmap;
+ CFX_DIBitmap* pDIBitmap = m_pDeviceBitmap;
ASSERT(pDIBitmap);
int src_top = m_clipBox.top;
int src_bottom = m_clipBox.bottom;
@@ -658,7 +658,7 @@ bool CCodec_ProgressiveDecoder::GifInputRecordPositionBuf(
m_GifFrameRect = img_rc;
m_SrcPassNumber = interlace ? 4 : 1;
int32_t pal_index = m_GifBgIndex;
- CFX_RetainPtr<CFX_DIBitmap> pDevice = m_pDeviceBitmap;
+ CFX_DIBitmap* pDevice = m_pDeviceBitmap;
if (trans_index >= pal_num)
trans_index = -1;
if (trans_index != -1) {
@@ -708,7 +708,7 @@ bool CCodec_ProgressiveDecoder::GifInputRecordPositionBuf(
void CCodec_ProgressiveDecoder::GifReadScanline(int32_t row_num,
uint8_t* row_buf) {
- CFX_RetainPtr<CFX_DIBitmap> pDIBitmap = m_pDeviceBitmap;
+ CFX_DIBitmap* pDIBitmap = m_pDeviceBitmap;
ASSERT(pDIBitmap);
int32_t img_width = m_GifFrameRect.Width();
if (!pDIBitmap->HasAlpha()) {
@@ -770,7 +770,7 @@ void CCodec_ProgressiveDecoder::GifReadScanline(int32_t row_num,
}
void CCodec_ProgressiveDecoder::GifDoubleLineResampleVert(
- const CFX_RetainPtr<CFX_DIBitmap>& pDeviceBitmap,
+ CFX_DIBitmap* pDeviceBitmap,
double scale_y,
int des_row) {
int des_Bpp = pDeviceBitmap->GetBPP() >> 3;
@@ -895,7 +895,7 @@ bool CCodec_ProgressiveDecoder::BmpInputImagePositionBuf(uint32_t rcd_pos) {
void CCodec_ProgressiveDecoder::BmpReadScanline(int32_t row_num,
uint8_t* row_buf) {
- CFX_RetainPtr<CFX_DIBitmap> pDIBitmap = m_pDeviceBitmap;
+ CFX_DIBitmap* pDIBitmap = m_pDeviceBitmap;
ASSERT(pDIBitmap);
FXSYS_memcpy(m_pDecodeBuf, row_buf, m_ScanlineSize);
int src_top = m_clipBox.top;
@@ -923,10 +923,9 @@ void CCodec_ProgressiveDecoder::BmpReadScanline(int32_t row_num,
ResampleVertBT(pDIBitmap, scale_y, des_row);
}
-void CCodec_ProgressiveDecoder::ResampleVertBT(
- const CFX_RetainPtr<CFX_DIBitmap>& pDeviceBitmap,
- double scale_y,
- int des_row) {
+void CCodec_ProgressiveDecoder::ResampleVertBT(CFX_DIBitmap* pDeviceBitmap,
+ double scale_y,
+ int des_row) {
int des_Bpp = pDeviceBitmap->GetBPP() >> 3;
uint32_t des_ScanOffet = m_startX * des_Bpp;
int des_top = m_startY;
@@ -1441,11 +1440,10 @@ void CCodec_ProgressiveDecoder::GetTransMethod(FXDIB_Format des_format,
}
}
-void CCodec_ProgressiveDecoder::ReSampleScanline(
- const CFX_RetainPtr<CFX_DIBitmap>& pDeviceBitmap,
- int des_line,
- uint8_t* src_scan,
- FXCodec_Format src_format) {
+void CCodec_ProgressiveDecoder::ReSampleScanline(CFX_DIBitmap* pDeviceBitmap,
+ int des_line,
+ uint8_t* src_scan,
+ FXCodec_Format src_format) {
int src_left = m_clipBox.left;
int des_left = m_startX;
uint8_t* des_scan =
@@ -1644,10 +1642,9 @@ void CCodec_ProgressiveDecoder::ReSampleScanline(
}
}
-void CCodec_ProgressiveDecoder::ResampleVert(
- const CFX_RetainPtr<CFX_DIBitmap>& pDeviceBitmap,
- double scale_y,
- int des_row) {
+void CCodec_ProgressiveDecoder::ResampleVert(CFX_DIBitmap* pDeviceBitmap,
+ double scale_y,
+ int des_row) {
int des_Bpp = pDeviceBitmap->GetBPP() >> 3;
uint32_t des_ScanOffet = m_startX * des_Bpp;
if (m_bInterpol) {
@@ -1760,11 +1757,10 @@ void CCodec_ProgressiveDecoder::ResampleVert(
}
}
-void CCodec_ProgressiveDecoder::Resample(
- const CFX_RetainPtr<CFX_DIBitmap>& pDeviceBitmap,
- int32_t src_line,
- uint8_t* src_scan,
- FXCodec_Format src_format) {
+void CCodec_ProgressiveDecoder::Resample(CFX_DIBitmap* pDeviceBitmap,
+ int32_t src_line,
+ uint8_t* src_scan,
+ FXCodec_Format src_format) {
int src_top = m_clipBox.top;
int des_top = m_startY;
int src_hei = m_clipBox.Height();
@@ -1835,14 +1831,13 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::GetFrames(int32_t& frames,
}
}
-FXCODEC_STATUS CCodec_ProgressiveDecoder::StartDecode(
- const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap,
- int start_x,
- int start_y,
- int size_x,
- int size_y,
- int32_t frames,
- bool bInterpol) {
+FXCODEC_STATUS CCodec_ProgressiveDecoder::StartDecode(CFX_DIBitmap* pDIBitmap,
+ int start_x,
+ int start_y,
+ int size_x,
+ int size_y,
+ int32_t frames,
+ bool bInterpol) {
if (m_status != FXCODEC_STATUS_DECODE_READY)
return FXCODEC_STATUS_ERROR;
@@ -2220,9 +2215,10 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode(IFX_Pause* pPause) {
return m_status;
}
- auto pDIBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ CFX_DIBitmap* pDIBitmap = new CFX_DIBitmap;
pDIBitmap->Create(m_SrcWidth, m_SrcHeight, FXDIB_Argb);
if (!pDIBitmap->GetBuffer()) {
+ delete pDIBitmap;
m_pDeviceBitmap = nullptr;
m_pFile = nullptr;
m_status = FXCODEC_STATUS_ERR_MEMORY;
@@ -2230,41 +2226,45 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode(IFX_Pause* pPause) {
}
ret = pTiffModule->Decode(m_pTiffContext, pDIBitmap);
if (!ret) {
+ delete pDIBitmap;
m_pDeviceBitmap = nullptr;
m_pFile = nullptr;
m_status = FXCODEC_STATUS_ERROR;
return m_status;
}
- CFX_RetainPtr<CFX_DIBitmap> pClipBitmap =
+ CFX_DIBitmap* pClipBitmap =
(m_clipBox.left == 0 && m_clipBox.top == 0 &&
m_clipBox.right == m_SrcWidth && m_clipBox.bottom == m_SrcHeight)
? pDIBitmap
- : pDIBitmap->Clone(&m_clipBox);
+ : pDIBitmap->Clone(&m_clipBox).release();
+ if (pDIBitmap != pClipBitmap) {
+ delete pDIBitmap;
+ }
if (!pClipBitmap) {
m_pDeviceBitmap = nullptr;
m_pFile = nullptr;
m_status = FXCODEC_STATUS_ERR_MEMORY;
return m_status;
}
- CFX_RetainPtr<CFX_DIBitmap> pFormatBitmap;
+ CFX_DIBitmap* pFormatBitmap = nullptr;
switch (m_pDeviceBitmap->GetFormat()) {
case FXDIB_8bppRgb:
- pFormatBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ pFormatBitmap = new CFX_DIBitmap;
pFormatBitmap->Create(pClipBitmap->GetWidth(),
pClipBitmap->GetHeight(), FXDIB_8bppRgb);
break;
case FXDIB_8bppMask:
- pFormatBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ pFormatBitmap = new CFX_DIBitmap;
pFormatBitmap->Create(pClipBitmap->GetWidth(),
pClipBitmap->GetHeight(), FXDIB_8bppMask);
break;
case FXDIB_Rgb:
- pFormatBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ pFormatBitmap = new CFX_DIBitmap;
pFormatBitmap->Create(pClipBitmap->GetWidth(),
pClipBitmap->GetHeight(), FXDIB_Rgb);
break;
case FXDIB_Rgb32:
- pFormatBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ pFormatBitmap = new CFX_DIBitmap;
pFormatBitmap->Create(pClipBitmap->GetWidth(),
pClipBitmap->GetHeight(), FXDIB_Rgb32);
break;
@@ -2312,14 +2312,18 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode(IFX_Pause* pPause) {
default:
break;
}
+ if (pClipBitmap != pFormatBitmap) {
+ delete pClipBitmap;
+ }
if (!pFormatBitmap) {
m_pDeviceBitmap = nullptr;
m_pFile = nullptr;
m_status = FXCODEC_STATUS_ERR_MEMORY;
return m_status;
}
- CFX_RetainPtr<CFX_DIBitmap> pStrechBitmap = pFormatBitmap->StretchTo(
+ std::unique_ptr<CFX_DIBitmap> pStrechBitmap = pFormatBitmap->StretchTo(
m_sizeX, m_sizeY, m_bInterpol ? FXDIB_INTERPOL : FXDIB_DOWNSAMPLE);
+ delete pFormatBitmap;
pFormatBitmap = nullptr;
if (!pStrechBitmap) {
m_pDeviceBitmap = nullptr;
@@ -2328,7 +2332,7 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode(IFX_Pause* pPause) {
return m_status;
}
m_pDeviceBitmap->TransferBitmap(m_startX, m_startY, m_sizeX, m_sizeY,
- pStrechBitmap, 0, 0);
+ pStrechBitmap.get(), 0, 0);
m_pDeviceBitmap = nullptr;
m_pFile = nullptr;
m_status = FXCODEC_STATUS_DECODE_FINISH;
diff --git a/core/fxcodec/codec/icodec_tiffmodule.h b/core/fxcodec/codec/icodec_tiffmodule.h
index 49abd1865f..540d82ff63 100644
--- a/core/fxcodec/codec/icodec_tiffmodule.h
+++ b/core/fxcodec/codec/icodec_tiffmodule.h
@@ -29,7 +29,7 @@ class ICodec_TiffModule {
int32_t* bpc,
CFX_DIBAttribute* pAttribute) = 0;
virtual bool Decode(CCodec_TiffContext* ctx,
- const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap) = 0;
+ class CFX_DIBitmap* pDIBitmap) = 0;
virtual void DestroyDecoder(CCodec_TiffContext* ctx) = 0;
};
diff --git a/core/fxge/agg/fx_agg_driver.cpp b/core/fxge/agg/fx_agg_driver.cpp
index ad7d2c4517..b435c032bc 100644
--- a/core/fxge/agg/fx_agg_driver.cpp
+++ b/core/fxge/agg/fx_agg_driver.cpp
@@ -35,10 +35,7 @@ CFX_PointF HardClip(const CFX_PointF& pos) {
pdfium::clamp(pos.y, -kMaxPos, kMaxPos));
}
-void RgbByteOrderSetPixel(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
- int x,
- int y,
- uint32_t argb) {
+void RgbByteOrderSetPixel(CFX_DIBitmap* pBitmap, int x, int y, uint32_t argb) {
if (x < 0 || x >= pBitmap->GetWidth() || y < 0 || y >= pBitmap->GetHeight())
return;
@@ -55,7 +52,7 @@ void RgbByteOrderSetPixel(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
pos[2] = (FXARGB_B(argb) * alpha + pos[2] * (255 - alpha)) / 255;
}
-void RgbByteOrderCompositeRect(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+void RgbByteOrderCompositeRect(CFX_DIBitmap* pBitmap,
int left,
int top,
int width,
@@ -130,12 +127,12 @@ void RgbByteOrderCompositeRect(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
}
}
-void RgbByteOrderTransferBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+void RgbByteOrderTransferBitmap(CFX_DIBitmap* pBitmap,
int dest_left,
int dest_top,
int width,
int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ const CFX_DIBSource* pSrcBitmap,
int src_left,
int src_top) {
if (!pBitmap)
@@ -235,7 +232,7 @@ FX_ARGB DefaultCMYK2ARGB(FX_CMYK cmyk, uint8_t alpha) {
return ArgbEncode(alpha, r, g, b);
}
-bool DibSetPixel(const CFX_RetainPtr<CFX_DIBitmap>& pDevice,
+bool DibSetPixel(CFX_DIBitmap* pDevice,
int x,
int y,
uint32_t color,
@@ -401,8 +398,8 @@ class CFX_Renderer {
uint8_t* clip_scan,
uint8_t* dest_extra_alpha_scan);
- bool Init(const CFX_RetainPtr<CFX_DIBitmap>& pDevice,
- const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice,
+ bool Init(CFX_DIBitmap* pDevice,
+ CFX_DIBitmap* pOriDevice,
const CFX_ClipRgn* pClipRgn,
uint32_t color,
bool bFullCover,
@@ -459,10 +456,10 @@ class CFX_Renderer {
uint32_t m_Color;
bool m_bFullCover;
bool m_bRgbByteOrder;
+ CFX_DIBitmap* m_pOriDevice;
FX_RECT m_ClipBox;
- CFX_RetainPtr<CFX_DIBitmap> m_pOriDevice;
- CFX_RetainPtr<CFX_DIBitmap> m_pClipMask;
- CFX_RetainPtr<CFX_DIBitmap> m_pDevice;
+ const CFX_DIBitmap* m_pClipMask;
+ CFX_DIBitmap* m_pDevice;
const CFX_ClipRgn* m_pClipRgn;
};
@@ -902,8 +899,8 @@ void CFX_Renderer::CompositeSpanCMYK(uint8_t* dest_scan,
}
}
-bool CFX_Renderer::Init(const CFX_RetainPtr<CFX_DIBitmap>& pDevice,
- const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice,
+bool CFX_Renderer::Init(CFX_DIBitmap* pDevice,
+ CFX_DIBitmap* pOriDevice,
const CFX_ClipRgn* pClipRgn,
uint32_t color,
bool bFullCover,
@@ -924,7 +921,7 @@ bool CFX_Renderer::Init(const CFX_RetainPtr<CFX_DIBitmap>& pDevice,
}
m_pClipMask = nullptr;
if (m_pClipRgn && m_pClipRgn->GetType() == CFX_ClipRgn::MaskF)
- m_pClipMask = m_pClipRgn->GetMask();
+ m_pClipMask = m_pClipRgn->GetMask().GetObject();
m_bFullCover = bFullCover;
bool bObjectCMYK = !!FXGETFLAG_COLORTYPE(alpha_flag);
bool bDeviceCMYK = pDevice->IsCmykImage();
@@ -1041,7 +1038,7 @@ void CFX_Renderer::render(const Scanline& sl) {
uint8_t* dest_scan = m_pDevice->GetBuffer() + m_pDevice->GetPitch() * y;
uint8_t* dest_scan_extra_alpha = nullptr;
- CFX_RetainPtr<CFX_DIBitmap> pAlphaMask = m_pDevice->m_pAlphaMask;
+ CFX_DIBitmap* pAlphaMask = m_pDevice->m_pAlphaMask;
if (pAlphaMask) {
dest_scan_extra_alpha =
pAlphaMask->GetBuffer() + pAlphaMask->GetPitch() * y;
@@ -1202,11 +1199,10 @@ void CAgg_PathData::BuildPath(const CFX_PathData* pPathData,
}
}
-CFX_AggDeviceDriver::CFX_AggDeviceDriver(
- const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
- bool bRgbByteOrder,
- const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice,
- bool bGroupKnockout)
+CFX_AggDeviceDriver::CFX_AggDeviceDriver(CFX_DIBitmap* pBitmap,
+ bool bRgbByteOrder,
+ CFX_DIBitmap* pOriDevice,
+ bool bGroupKnockout)
: m_pBitmap(pBitmap),
#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
m_pPlatformGraphics(nullptr),
@@ -1300,7 +1296,8 @@ void CFX_AggDeviceDriver::SetClipMask(agg::rasterizer_scanline_aa& rasterizer) {
FX_RECT path_rect(rasterizer.min_x(), rasterizer.min_y(),
rasterizer.max_x() + 1, rasterizer.max_y() + 1);
path_rect.Intersect(m_pClipRgn->GetBox());
- auto pThisLayer = pdfium::MakeRetain<CFX_DIBitmap>();
+ CFX_DIBitmapRef mask;
+ CFX_DIBitmap* pThisLayer = mask.Emplace();
pThisLayer->Create(path_rect.Width(), path_rect.Height(), FXDIB_8bppMask);
pThisLayer->Clear(0);
agg::rendering_buffer raw_buf(pThisLayer->GetBuffer(), pThisLayer->GetWidth(),
@@ -1314,7 +1311,7 @@ void CFX_AggDeviceDriver::SetClipMask(agg::rasterizer_scanline_aa& rasterizer) {
agg::scanline_u8 scanline;
agg::render_scanlines(rasterizer, scanline, final_render,
(m_FillFlags & FXFILL_NOPATHSMOOTH) != 0);
- m_pClipRgn->IntersectMaskF(path_rect.left, path_rect.top, pThisLayer);
+ m_pClipRgn->IntersectMaskF(path_rect.left, path_rect.top, mask);
}
bool CFX_AggDeviceDriver::SetClip_PathFill(const CFX_PathData* pPathData,
@@ -1384,7 +1381,7 @@ bool CFX_AggDeviceDriver::RenderRasterizer(
bool bGroupKnockout,
int alpha_flag,
void* pIccTransform) {
- CFX_RetainPtr<CFX_DIBitmap> pt = bGroupKnockout ? m_pOriDevice : nullptr;
+ CFX_DIBitmap* pt = bGroupKnockout ? m_pOriDevice : nullptr;
CFX_Renderer render;
if (!render.Init(m_pBitmap, pt, m_pClipRgn.get(), color, bFullCover,
m_bRgbByteOrder, alpha_flag, pIccTransform)) {
@@ -1495,8 +1492,8 @@ bool CFX_AggDeviceDriver::SetPixel(int x, int y, uint32_t color) {
if (m_pClipRgn->GetType() != CFX_ClipRgn::MaskF)
return true;
- int new_alpha =
- FXARGB_A(color) * m_pClipRgn->GetMask()->GetScanline(y)[x] / 255;
+ const CFX_DIBitmap* pMask = m_pClipRgn->GetMask().GetObject();
+ int new_alpha = FXARGB_A(color) * pMask->GetScanline(y)[x] / 255;
color = (color & 0xffffff) | (new_alpha << 24);
if (m_bRgbByteOrder) {
RgbByteOrderSetPixel(m_pBitmap, x, y, color);
@@ -1533,11 +1530,11 @@ bool CFX_AggDeviceDriver::FillRectWithBlend(const FX_RECT* pRect,
}
return true;
}
- m_pBitmap->CompositeMask(draw_rect.left, draw_rect.top, draw_rect.Width(),
- draw_rect.Height(), m_pClipRgn->GetMask(),
- fill_color, draw_rect.left - clip_rect.left,
- draw_rect.top - clip_rect.top, FXDIB_BLEND_NORMAL,
- nullptr, m_bRgbByteOrder, 0, nullptr);
+ m_pBitmap->CompositeMask(
+ draw_rect.left, draw_rect.top, draw_rect.Width(), draw_rect.Height(),
+ m_pClipRgn->GetMask().GetObject(), fill_color,
+ draw_rect.left - clip_rect.left, draw_rect.top - clip_rect.top,
+ FXDIB_BLEND_NORMAL, nullptr, m_bRgbByteOrder, 0, nullptr);
return true;
}
@@ -1552,15 +1549,13 @@ bool CFX_AggDeviceDriver::GetClipBox(FX_RECT* pRect) {
return true;
}
-bool CFX_AggDeviceDriver::GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
- int left,
- int top) {
+bool CFX_AggDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) {
if (!m_pBitmap || !m_pBitmap->GetBuffer())
return true;
FX_RECT rect(left, top, left + pBitmap->GetWidth(),
top + pBitmap->GetHeight());
- CFX_RetainPtr<CFX_DIBitmap> pBack;
+ std::unique_ptr<CFX_DIBitmap> pBack;
if (m_pOriDevice) {
pBack = m_pOriDevice->Clone(&rect);
if (!pBack)
@@ -1578,18 +1573,18 @@ bool CFX_AggDeviceDriver::GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
top = std::min(top, 0);
if (m_bRgbByteOrder) {
RgbByteOrderTransferBitmap(pBitmap, 0, 0, rect.Width(), rect.Height(),
- pBack, left, top);
+ pBack.get(), left, top);
return true;
}
- return pBitmap->TransferBitmap(0, 0, rect.Width(), rect.Height(), pBack, left,
- top);
+ return pBitmap->TransferBitmap(0, 0, rect.Width(), rect.Height(), pBack.get(),
+ left, top);
}
-CFX_RetainPtr<CFX_DIBitmap> CFX_AggDeviceDriver::GetBackDrop() {
+CFX_DIBitmap* CFX_AggDeviceDriver::GetBackDrop() {
return m_pOriDevice;
}
-bool CFX_AggDeviceDriver::SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+bool CFX_AggDeviceDriver::SetDIBits(const CFX_DIBSource* pBitmap,
uint32_t argb,
const FX_RECT* pSrcRect,
int left,
@@ -1609,16 +1604,15 @@ bool CFX_AggDeviceDriver::SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
pSrcRect->top, blend_type, m_pClipRgn.get(), m_bRgbByteOrder, nullptr);
}
-bool CFX_AggDeviceDriver::StretchDIBits(
- const CFX_RetainPtr<CFX_DIBSource>& pSource,
- uint32_t argb,
- int dest_left,
- int dest_top,
- int dest_width,
- int dest_height,
- const FX_RECT* pClipRect,
- uint32_t flags,
- int blend_type) {
+bool CFX_AggDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource,
+ uint32_t argb,
+ int dest_left,
+ int dest_top,
+ int dest_width,
+ int dest_height,
+ const FX_RECT* pClipRect,
+ uint32_t flags,
+ int blend_type) {
if (!m_pBitmap->GetBuffer())
return true;
@@ -1643,14 +1637,13 @@ bool CFX_AggDeviceDriver::StretchDIBits(
return true;
}
-bool CFX_AggDeviceDriver::StartDIBits(
- const CFX_RetainPtr<CFX_DIBSource>& pSource,
- int bitmap_alpha,
- uint32_t argb,
- const CFX_Matrix* pMatrix,
- uint32_t render_flags,
- void*& handle,
- int blend_type) {
+bool CFX_AggDeviceDriver::StartDIBits(const CFX_DIBSource* pSource,
+ int bitmap_alpha,
+ uint32_t argb,
+ const CFX_Matrix* pMatrix,
+ uint32_t render_flags,
+ void*& handle,
+ int blend_type) {
if (!m_pBitmap->GetBuffer())
return true;
@@ -1675,13 +1668,13 @@ void CFX_AggDeviceDriver::CancelDIBits(void* pHandle) {
}
#ifndef _SKIA_SUPPORT_
-CFX_FxgeDevice::CFX_FxgeDevice() {}
-
-CFX_FxgeDevice::~CFX_FxgeDevice() {}
+CFX_FxgeDevice::CFX_FxgeDevice() {
+ m_bOwnedBitmap = false;
+}
-bool CFX_FxgeDevice::Attach(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+bool CFX_FxgeDevice::Attach(CFX_DIBitmap* pBitmap,
bool bRgbByteOrder,
- const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice,
+ CFX_DIBitmap* pOriDevice,
bool bGroupKnockout) {
if (!pBitmap)
return false;
@@ -1695,15 +1688,21 @@ bool CFX_FxgeDevice::Attach(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
bool CFX_FxgeDevice::Create(int width,
int height,
FXDIB_Format format,
- const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice) {
- auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
- if (!pBitmap->Create(width, height, format))
+ CFX_DIBitmap* pOriDevice) {
+ m_bOwnedBitmap = true;
+ CFX_DIBitmap* pBitmap = new CFX_DIBitmap;
+ if (!pBitmap->Create(width, height, format)) {
+ delete pBitmap;
return false;
-
+ }
SetBitmap(pBitmap);
SetDeviceDriver(pdfium::MakeUnique<CFX_AggDeviceDriver>(pBitmap, false,
pOriDevice, false));
return true;
}
+CFX_FxgeDevice::~CFX_FxgeDevice() {
+ if (m_bOwnedBitmap)
+ delete GetBitmap();
+}
#endif
diff --git a/core/fxge/agg/fx_agg_driver.h b/core/fxge/agg/fx_agg_driver.h
index 723ed6d98a..7b4c7209e8 100644
--- a/core/fxge/agg/fx_agg_driver.h
+++ b/core/fxge/agg/fx_agg_driver.h
@@ -32,9 +32,9 @@ class CAgg_PathData {
class CFX_AggDeviceDriver : public IFX_RenderDeviceDriver {
public:
- CFX_AggDeviceDriver(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ CFX_AggDeviceDriver(CFX_DIBitmap* pBitmap,
bool bRgbByteOrder,
- const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice,
+ CFX_DIBitmap* pOriDevice,
bool bGroupKnockout);
~CFX_AggDeviceDriver() override;
@@ -63,17 +63,15 @@ class CFX_AggDeviceDriver : public IFX_RenderDeviceDriver {
uint32_t fill_color,
int blend_type) override;
bool GetClipBox(FX_RECT* pRect) override;
- bool GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
- int left,
- int top) override;
- CFX_RetainPtr<CFX_DIBitmap> GetBackDrop() override;
- bool SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ bool GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) override;
+ CFX_DIBitmap* GetBackDrop() override;
+ bool SetDIBits(const CFX_DIBSource* pBitmap,
uint32_t color,
const FX_RECT* pSrcRect,
int left,
int top,
int blend_type) override;
- bool StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ bool StretchDIBits(const CFX_DIBSource* pBitmap,
uint32_t color,
int dest_left,
int dest_top,
@@ -82,7 +80,7 @@ class CFX_AggDeviceDriver : public IFX_RenderDeviceDriver {
const FX_RECT* pClipRect,
uint32_t flags,
int blend_type) override;
- bool StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ bool StartDIBits(const CFX_DIBSource* pBitmap,
int bitmap_alpha,
uint32_t color,
const CFX_Matrix* pMatrix,
@@ -111,7 +109,7 @@ class CFX_AggDeviceDriver : public IFX_RenderDeviceDriver {
virtual uint8_t* GetBuffer() const;
private:
- CFX_RetainPtr<CFX_DIBitmap> m_pBitmap;
+ CFX_DIBitmap* m_pBitmap;
std::unique_ptr<CFX_ClipRgn> m_pClipRgn;
std::vector<std::unique_ptr<CFX_ClipRgn>> m_StateStack;
#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
@@ -119,7 +117,7 @@ class CFX_AggDeviceDriver : public IFX_RenderDeviceDriver {
#endif
int m_FillFlags;
bool m_bRgbByteOrder;
- CFX_RetainPtr<CFX_DIBitmap> m_pOriDevice;
+ CFX_DIBitmap* m_pOriDevice;
bool m_bGroupKnockout;
};
diff --git a/core/fxge/apple/apple_int.h b/core/fxge/apple/apple_int.h
index f1b9fcf2e8..2a4029bd38 100644
--- a/core/fxge/apple/apple_int.h
+++ b/core/fxge/apple/apple_int.h
@@ -19,7 +19,7 @@
class CQuartz2D {
public:
- void* createGraphics(const CFX_RetainPtr<CFX_DIBitmap>& bitmap);
+ void* createGraphics(CFX_DIBitmap* bitmap);
void destroyGraphics(void* graphics);
void* CreateFont(const uint8_t* pFontData, uint32_t dwFontSize);
diff --git a/core/fxge/apple/fx_apple_platform.cpp b/core/fxge/apple/fx_apple_platform.cpp
index 3f7916f07d..20e86ed483 100644
--- a/core/fxge/apple/fx_apple_platform.cpp
+++ b/core/fxge/apple/fx_apple_platform.cpp
@@ -129,7 +129,7 @@ bool CFX_AggDeviceDriver::DrawDeviceText(int nChars,
rect_cg =
CGRectMake(m_pClipRgn->GetBox().left, m_pClipRgn->GetBox().top,
m_pClipRgn->GetBox().Width(), m_pClipRgn->GetBox().Height());
- CFX_RetainPtr<CFX_DIBitmap> pClipMask = m_pClipRgn->GetMask();
+ const CFX_DIBitmap* pClipMask = m_pClipRgn->GetMask().GetObject();
if (pClipMask) {
CGDataProviderRef pClipMaskDataProvider = CGDataProviderCreateWithData(
nullptr, pClipMask->GetBuffer(),
diff --git a/core/fxge/apple/fx_quartz_device.cpp b/core/fxge/apple/fx_quartz_device.cpp
index ded8036047..dbb121065d 100644
--- a/core/fxge/apple/fx_quartz_device.cpp
+++ b/core/fxge/apple/fx_quartz_device.cpp
@@ -25,7 +25,7 @@
#error Expected CGFLOAT_IS_DOUBLE to be defined by CoreGraphics headers
#endif
-void* CQuartz2D::createGraphics(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap) {
+void* CQuartz2D::createGraphics(CFX_DIBitmap* pBitmap) {
if (!pBitmap)
return nullptr;
CGBitmapInfo bmpInfo = kCGBitmapByteOrder32Little;
diff --git a/core/fxge/cfx_fxgedevice.h b/core/fxge/cfx_fxgedevice.h
index 4e8a7f4f55..8358e43666 100644
--- a/core/fxge/cfx_fxgedevice.h
+++ b/core/fxge/cfx_fxgedevice.h
@@ -17,27 +17,30 @@ class CFX_FxgeDevice : public CFX_RenderDevice {
CFX_FxgeDevice();
~CFX_FxgeDevice() override;
- bool Attach(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ bool Attach(CFX_DIBitmap* pBitmap,
bool bRgbByteOrder,
- const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice,
+ CFX_DIBitmap* pOriDevice,
bool bGroupKnockout);
bool Create(int width,
int height,
FXDIB_Format format,
- const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice);
+ CFX_DIBitmap* pOriDevice);
#ifdef _SKIA_SUPPORT_
bool AttachRecorder(SkPictureRecorder* recorder);
void Clear(uint32_t color);
SkPictureRecorder* CreateRecorder(int size_x, int size_y);
void DebugVerifyBitmapIsPreMultiplied() const override;
- bool SetBitsWithMask(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
- const CFX_RetainPtr<CFX_DIBSource>& pMask,
+ bool SetBitsWithMask(const CFX_DIBSource* pBitmap,
+ const CFX_DIBSource* pMask,
int left,
int top,
int bitmap_alpha,
int blend_type) override;
#endif
+
+ private:
+ bool m_bOwnedBitmap;
};
#endif // CORE_FXGE_CFX_FXGEDEVICE_H_
diff --git a/core/fxge/cfx_renderdevice.h b/core/fxge/cfx_renderdevice.h
index d56c2ecb9a..41f8e4c690 100644
--- a/core/fxge/cfx_renderdevice.h
+++ b/core/fxge/cfx_renderdevice.h
@@ -100,13 +100,9 @@ class CFX_RenderDevice {
int GetRenderCaps() const { return m_RenderCaps; }
int GetDeviceCaps(int id) const;
CFX_Matrix GetCTM() const;
- CFX_RetainPtr<CFX_DIBitmap> GetBitmap() const { return m_pBitmap; }
- void SetBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap) {
- m_pBitmap = pBitmap;
- }
- bool CreateCompatibleBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pDIB,
- int width,
- int height) const;
+ CFX_DIBitmap* GetBitmap() const { return m_pBitmap; }
+ void SetBitmap(CFX_DIBitmap* pBitmap) { m_pBitmap = pBitmap; }
+ bool CreateCompatibleBitmap(CFX_DIBitmap* pDIB, int width, int height) const;
const FX_RECT& GetClipBox() const { return m_ClipBox; }
bool SetClip_PathFill(const CFX_PathData* pPathData,
const CFX_Matrix* pObject2Device,
@@ -144,18 +140,16 @@ class CFX_RenderDevice {
int fill_mode,
int blend_type);
- CFX_RetainPtr<CFX_DIBitmap> GetBackDrop();
- bool GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, int left, int top);
- bool SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
- int left,
- int top) {
+ bool GetDIBits(CFX_DIBitmap* pBitmap, int left, int top);
+ CFX_DIBitmap* GetBackDrop();
+ bool SetDIBits(const CFX_DIBSource* pBitmap, int left, int top) {
return SetDIBitsWithBlend(pBitmap, left, top, FXDIB_BLEND_NORMAL);
}
- bool SetDIBitsWithBlend(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ bool SetDIBitsWithBlend(const CFX_DIBSource* pBitmap,
int left,
int top,
int blend_type);
- bool StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ bool StretchDIBits(const CFX_DIBSource* pBitmap,
int left,
int top,
int dest_width,
@@ -163,32 +157,31 @@ class CFX_RenderDevice {
return StretchDIBitsWithFlagsAndBlend(pBitmap, left, top, dest_width,
dest_height, 0, FXDIB_BLEND_NORMAL);
}
- bool StretchDIBitsWithFlagsAndBlend(
- const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
- int left,
- int top,
- int dest_width,
- int dest_height,
- uint32_t flags,
- int blend_type);
- bool SetBitMask(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ bool StretchDIBitsWithFlagsAndBlend(const CFX_DIBSource* pBitmap,
+ int left,
+ int top,
+ int dest_width,
+ int dest_height,
+ uint32_t flags,
+ int blend_type);
+ bool SetBitMask(const CFX_DIBSource* pBitmap,
int left,
int top,
uint32_t color);
- bool StretchBitMask(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ bool StretchBitMask(const CFX_DIBSource* pBitmap,
int left,
int top,
int dest_width,
int dest_height,
uint32_t color);
- bool StretchBitMaskWithFlags(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ bool StretchBitMaskWithFlags(const CFX_DIBSource* pBitmap,
int left,
int top,
int dest_width,
int dest_height,
uint32_t color,
uint32_t flags);
- bool StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ bool StartDIBits(const CFX_DIBSource* pBitmap,
int bitmap_alpha,
uint32_t color,
const CFX_Matrix* pMatrix,
@@ -197,7 +190,7 @@ class CFX_RenderDevice {
return StartDIBitsWithBlend(pBitmap, bitmap_alpha, color, pMatrix, flags,
handle, FXDIB_BLEND_NORMAL);
}
- bool StartDIBitsWithBlend(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ bool StartDIBitsWithBlend(const CFX_DIBSource* pBitmap,
int bitmap_alpha,
uint32_t color,
const CFX_Matrix* pMatrix,
@@ -228,8 +221,8 @@ class CFX_RenderDevice {
#ifdef _SKIA_SUPPORT_
virtual void DebugVerifyBitmapIsPreMultiplied() const;
- virtual bool SetBitsWithMask(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
- const CFX_RetainPtr<CFX_DIBSource>& pMask,
+ virtual bool SetBitsWithMask(const CFX_DIBSource* pBitmap,
+ const CFX_DIBSource* pMask,
int left,
int top,
int bitmap_alpha,
@@ -250,7 +243,7 @@ class CFX_RenderDevice {
int fill_mode,
int blend_type);
- CFX_RetainPtr<CFX_DIBitmap> m_pBitmap;
+ CFX_DIBitmap* m_pBitmap;
int m_Width;
int m_Height;
int m_bpp;
diff --git a/core/fxge/dib/dib_int.h b/core/fxge/dib/dib_int.h
index a898a479a2..000003a9c6 100644
--- a/core/fxge/dib/dib_int.h
+++ b/core/fxge/dib/dib_int.h
@@ -71,7 +71,7 @@ class CStretchEngine {
int dest_width,
int dest_height,
const FX_RECT& clip_rect,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ const CFX_DIBSource* pSrcBitmap,
int flags);
~CStretchEngine();
@@ -91,7 +91,7 @@ class CStretchEngine {
uint8_t* m_pDestScanline;
uint8_t* m_pDestMaskScanline;
FX_RECT m_SrcClip;
- CFX_RetainPtr<CFX_DIBSource> m_pSource;
+ const CFX_DIBSource* m_pSource;
uint32_t* m_pSrcPalette;
int m_SrcWidth;
int m_SrcHeight;
diff --git a/core/fxge/dib/fx_dib_composite.cpp b/core/fxge/dib/fx_dib_composite.cpp
index fb00cb855b..435a1ad9b6 100644
--- a/core/fxge/dib/fx_dib_composite.cpp
+++ b/core/fxge/dib/fx_dib_composite.cpp
@@ -3914,18 +3914,17 @@ void CFX_ScanlineCompositor::CompositeBitMaskLine(uint8_t* dest_scan,
}
}
-bool CFX_DIBitmap::CompositeBitmap(
- int dest_left,
- int dest_top,
- int width,
- int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
- int src_left,
- int src_top,
- int blend_type,
- const CFX_ClipRgn* pClipRgn,
- bool bRgbByteOrder,
- void* pIccTransform) {
+bool CFX_DIBitmap::CompositeBitmap(int dest_left,
+ int dest_top,
+ int width,
+ int height,
+ const CFX_DIBSource* pSrcBitmap,
+ int src_left,
+ int src_top,
+ int blend_type,
+ const CFX_ClipRgn* pClipRgn,
+ bool bRgbByteOrder,
+ void* pIccTransform) {
if (!m_pBuffer) {
return false;
}
@@ -3939,11 +3938,11 @@ bool CFX_DIBitmap::CompositeBitmap(
if (width == 0 || height == 0) {
return true;
}
- CFX_RetainPtr<CFX_DIBitmap> pClipMask;
+ const CFX_DIBitmap* pClipMask = nullptr;
FX_RECT clip_box;
if (pClipRgn && pClipRgn->GetType() != CFX_ClipRgn::RectI) {
ASSERT(pClipRgn->GetType() == CFX_ClipRgn::MaskF);
- pClipMask = pClipRgn->GetMask();
+ pClipMask = pClipRgn->GetMask().GetObject();
clip_box = pClipRgn->GetBox();
}
CFX_ScanlineCompositor compositor;
@@ -3955,7 +3954,7 @@ bool CFX_DIBitmap::CompositeBitmap(
int dest_Bpp = m_bpp / 8;
int src_Bpp = pSrcBitmap->GetBPP() / 8;
bool bRgb = src_Bpp > 1 && !pSrcBitmap->IsCmykImage();
- CFX_RetainPtr<CFX_DIBitmap> pSrcAlphaMask = pSrcBitmap->m_pAlphaMask;
+ CFX_DIBitmap* pSrcAlphaMask = pSrcBitmap->m_pAlphaMask;
for (int row = 0; row < height; row++) {
uint8_t* dest_scan =
m_pBuffer + (dest_top + row) * m_Pitch + dest_left * dest_Bpp;
@@ -3991,7 +3990,7 @@ bool CFX_DIBitmap::CompositeMask(int dest_left,
int dest_top,
int width,
int height,
- const CFX_RetainPtr<CFX_DIBSource>& pMask,
+ const CFX_DIBSource* pMask,
uint32_t color,
int src_left,
int src_top,
@@ -4018,11 +4017,11 @@ bool CFX_DIBitmap::CompositeMask(int dest_left,
if (src_alpha == 0) {
return true;
}
- CFX_RetainPtr<CFX_DIBitmap> pClipMask;
+ const CFX_DIBitmap* pClipMask = nullptr;
FX_RECT clip_box;
if (pClipRgn && pClipRgn->GetType() != CFX_ClipRgn::RectI) {
ASSERT(pClipRgn->GetType() == CFX_ClipRgn::MaskF);
- pClipMask = pClipRgn->GetMask();
+ pClipMask = pClipRgn->GetMask().GetObject();
clip_box = pClipRgn->GetBox();
}
int src_bpp = pMask->GetBPP();
@@ -4283,7 +4282,7 @@ CFX_BitmapComposer::~CFX_BitmapComposer() {
FX_Free(m_pAddClipScan);
}
-void CFX_BitmapComposer::Compose(const CFX_RetainPtr<CFX_DIBitmap>& pDest,
+void CFX_BitmapComposer::Compose(CFX_DIBitmap* pDest,
const CFX_ClipRgn* pClipRgn,
int bitmap_alpha,
uint32_t mask_color,
@@ -4304,8 +4303,9 @@ void CFX_BitmapComposer::Compose(const CFX_RetainPtr<CFX_DIBitmap>& pDest,
m_BitmapAlpha = bitmap_alpha;
m_MaskColor = mask_color;
m_pClipMask = nullptr;
- if (pClipRgn && pClipRgn->GetType() != CFX_ClipRgn::RectI)
- m_pClipMask = pClipRgn->GetMask();
+ if (pClipRgn && pClipRgn->GetType() != CFX_ClipRgn::RectI) {
+ m_pClipMask = pClipRgn->GetMask().GetObject();
+ }
m_bVertical = bVertical;
m_bFlipX = bFlipX;
m_bFlipY = bFlipY;
diff --git a/core/fxge/dib/fx_dib_convert.cpp b/core/fxge/dib/fx_dib_convert.cpp
index 624e1437e9..aad3f343e2 100644
--- a/core/fxge/dib/fx_dib_convert.cpp
+++ b/core/fxge/dib/fx_dib_convert.cpp
@@ -17,7 +17,7 @@ class CFX_Palette {
CFX_Palette();
~CFX_Palette();
- bool BuildPalette(const CFX_RetainPtr<CFX_DIBSource>& pBitmap);
+ bool BuildPalette(const CFX_DIBSource* pBitmap);
uint32_t* GetPalette() const { return m_pPalette; }
uint32_t* GetColorLut() const { return m_cLut; }
uint32_t* GetAmountLut() const { return m_aLut; }
@@ -101,7 +101,7 @@ CFX_Palette::~CFX_Palette() {
m_lut = 0;
}
-bool CFX_Palette::BuildPalette(const CFX_RetainPtr<CFX_DIBSource>& pBitmap) {
+bool CFX_Palette::BuildPalette(const CFX_DIBSource* pBitmap) {
if (!pBitmap) {
return false;
}
@@ -145,7 +145,7 @@ bool ConvertBuffer_1bppMask2Gray(uint8_t* dest_buf,
int dest_pitch,
int width,
int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ const CFX_DIBSource* pSrcBitmap,
int src_left,
int src_top) {
uint8_t set_gray, reset_gray;
@@ -169,7 +169,7 @@ bool ConvertBuffer_8bppMask2Gray(uint8_t* dest_buf,
int dest_pitch,
int width,
int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ const CFX_DIBSource* pSrcBitmap,
int src_left,
int src_top) {
for (int row = 0; row < height; row++) {
@@ -184,7 +184,7 @@ bool ConvertBuffer_1bppPlt2Gray(uint8_t* dest_buf,
int dest_pitch,
int width,
int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ const CFX_DIBSource* pSrcBitmap,
int src_left,
int src_top) {
uint32_t* src_plt = pSrcBitmap->GetPalette();
@@ -231,7 +231,7 @@ bool ConvertBuffer_8bppPlt2Gray(uint8_t* dest_buf,
int dest_pitch,
int width,
int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ const CFX_DIBSource* pSrcBitmap,
int src_left,
int src_top) {
uint32_t* src_plt = pSrcBitmap->GetPalette();
@@ -263,14 +263,13 @@ bool ConvertBuffer_8bppPlt2Gray(uint8_t* dest_buf,
return true;
}
-bool ConvertBuffer_RgbOrCmyk2Gray(
- uint8_t* dest_buf,
- int dest_pitch,
- int width,
- int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
- int src_left,
- int src_top) {
+bool ConvertBuffer_RgbOrCmyk2Gray(uint8_t* dest_buf,
+ int dest_pitch,
+ int width,
+ int height,
+ const CFX_DIBSource* pSrcBitmap,
+ int src_left,
+ int src_top) {
int Bpp = pSrcBitmap->GetBPP() / 8;
if (pSrcBitmap->IsCmykImage()) {
for (int row = 0; row < height; row++) {
@@ -305,7 +304,7 @@ void ConvertBuffer_IndexCopy(uint8_t* dest_buf,
int dest_pitch,
int width,
int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ const CFX_DIBSource* pSrcBitmap,
int src_left,
int src_top) {
if (pSrcBitmap->GetBPP() == 1) {
@@ -334,7 +333,7 @@ bool ConvertBuffer_Plt2PltRgb8(uint8_t* dest_buf,
int dest_pitch,
int width,
int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ const CFX_DIBSource* pSrcBitmap,
int src_left,
int src_top,
uint32_t* dst_plt) {
@@ -362,7 +361,7 @@ bool ConvertBuffer_Rgb2PltRgb8(uint8_t* dest_buf,
int dest_pitch,
int width,
int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ const CFX_DIBSource* pSrcBitmap,
int src_left,
int src_top,
uint32_t* dst_plt) {
@@ -425,7 +424,7 @@ bool ConvertBuffer_1bppMask2Rgb(FXDIB_Format dst_format,
int dest_pitch,
int width,
int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ const CFX_DIBSource* pSrcBitmap,
int src_left,
int src_top) {
int comps = (dst_format & 0xff) / 8;
@@ -456,7 +455,7 @@ bool ConvertBuffer_8bppMask2Rgb(FXDIB_Format dst_format,
int dest_pitch,
int width,
int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ const CFX_DIBSource* pSrcBitmap,
int src_left,
int src_top) {
int comps = (dst_format & 0xff) / 8;
@@ -480,7 +479,7 @@ bool ConvertBuffer_1bppPlt2Rgb(FXDIB_Format dst_format,
int dest_pitch,
int width,
int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ const CFX_DIBSource* pSrcBitmap,
int src_left,
int src_top) {
int comps = (dst_format & 0xff) / 8;
@@ -532,7 +531,7 @@ bool ConvertBuffer_8bppPlt2Rgb(FXDIB_Format dst_format,
int dest_pitch,
int width,
int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ const CFX_DIBSource* pSrcBitmap,
int src_left,
int src_top) {
int comps = (dst_format & 0xff) / 8;
@@ -573,14 +572,13 @@ bool ConvertBuffer_8bppPlt2Rgb(FXDIB_Format dst_format,
return true;
}
-bool ConvertBuffer_24bppRgb2Rgb24(
- uint8_t* dest_buf,
- int dest_pitch,
- int width,
- int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
- int src_left,
- int src_top) {
+bool ConvertBuffer_24bppRgb2Rgb24(uint8_t* dest_buf,
+ int dest_pitch,
+ int width,
+ int height,
+ const CFX_DIBSource* pSrcBitmap,
+ int src_left,
+ int src_top) {
for (int row = 0; row < height; row++) {
uint8_t* dest_scan = dest_buf + row * dest_pitch;
const uint8_t* src_scan =
@@ -590,14 +588,13 @@ bool ConvertBuffer_24bppRgb2Rgb24(
return true;
}
-bool ConvertBuffer_32bppRgb2Rgb24(
- uint8_t* dest_buf,
- int dest_pitch,
- int width,
- int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
- int src_left,
- int src_top) {
+bool ConvertBuffer_32bppRgb2Rgb24(uint8_t* dest_buf,
+ int dest_pitch,
+ int width,
+ int height,
+ const CFX_DIBSource* pSrcBitmap,
+ int src_left,
+ int src_top) {
for (int row = 0; row < height; row++) {
uint8_t* dest_scan = dest_buf + row * dest_pitch;
const uint8_t* src_scan =
@@ -616,7 +613,7 @@ bool ConvertBuffer_Rgb2Rgb32(uint8_t* dest_buf,
int dest_pitch,
int width,
int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ const CFX_DIBSource* pSrcBitmap,
int src_left,
int src_top) {
int comps = pSrcBitmap->GetBPP() / 8;
@@ -635,14 +632,13 @@ bool ConvertBuffer_Rgb2Rgb32(uint8_t* dest_buf,
return true;
}
-bool ConvertBuffer_32bppCmyk2Rgb32(
- uint8_t* dest_buf,
- int dest_pitch,
- int width,
- int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
- int src_left,
- int src_top) {
+bool ConvertBuffer_32bppCmyk2Rgb32(uint8_t* dest_buf,
+ int dest_pitch,
+ int width,
+ int height,
+ const CFX_DIBSource* pSrcBitmap,
+ int src_left,
+ int src_top) {
for (int row = 0; row < height; row++) {
uint8_t* dest_scan = dest_buf + row * dest_pitch;
const uint8_t* src_scan =
@@ -662,7 +658,7 @@ bool ConvertBuffer(FXDIB_Format dest_format,
int dest_pitch,
int width,
int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ const CFX_DIBSource* pSrcBitmap,
int src_left,
int src_top,
std::unique_ptr<uint32_t, FxFreeDeleter>* p_pal) {
@@ -787,16 +783,16 @@ bool ConvertBuffer(FXDIB_Format dest_format,
}
}
-CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::CloneConvert(
- FXDIB_Format dest_format) {
+std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::CloneConvert(
+ FXDIB_Format dest_format) const {
if (dest_format == GetFormat())
return Clone(nullptr);
- auto pClone = pdfium::MakeRetain<CFX_DIBitmap>();
+ std::unique_ptr<CFX_DIBitmap> pClone = pdfium::MakeUnique<CFX_DIBitmap>();
if (!pClone->Create(m_Width, m_Height, dest_format))
return nullptr;
- CFX_RetainPtr<CFX_DIBitmap> pSrcAlpha;
+ CFX_MaybeOwned<CFX_DIBitmap> pSrcAlpha;
if (HasAlpha()) {
if (GetFormat() == FXDIB_Argb)
pSrcAlpha = CloneAlphaMask();
@@ -809,19 +805,19 @@ CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::CloneConvert(
bool ret = true;
if (dest_format & 0x0200) {
if (dest_format == FXDIB_Argb) {
- ret = pSrcAlpha ? pClone->LoadChannel(FXDIB_Alpha, pSrcAlpha, FXDIB_Alpha)
- : pClone->LoadChannel(FXDIB_Alpha, 0xff);
+ ret = pSrcAlpha
+ ? pClone->LoadChannel(FXDIB_Alpha, pSrcAlpha.Get(), FXDIB_Alpha)
+ : pClone->LoadChannel(FXDIB_Alpha, 0xff);
} else {
- ret = pClone->SetAlphaMask(pSrcAlpha);
+ ret = pClone->SetAlphaMask(pSrcAlpha.Get());
}
}
if (!ret)
return nullptr;
- CFX_RetainPtr<CFX_DIBSource> holder(this);
std::unique_ptr<uint32_t, FxFreeDeleter> pal_8bpp;
if (!ConvertBuffer(dest_format, pClone->GetBuffer(), pClone->GetPitch(),
- m_Width, m_Height, holder, 0, 0, &pal_8bpp)) {
+ m_Width, m_Height, this, 0, 0, &pal_8bpp)) {
return nullptr;
}
if (pal_8bpp)
@@ -857,7 +853,7 @@ bool CFX_DIBitmap::ConvertFormat(FXDIB_Format dest_format) {
if (!dest_buf) {
return false;
}
- CFX_RetainPtr<CFX_DIBitmap> pAlphaMask;
+ CFX_DIBitmap* pAlphaMask = nullptr;
if (dest_format == FXDIB_Argb) {
FXSYS_memset(dest_buf, 0xff, dest_pitch * m_Height + 4);
if (m_pAlphaMask) {
@@ -872,7 +868,7 @@ bool CFX_DIBitmap::ConvertFormat(FXDIB_Format dest_format) {
}
} else if (dest_format & 0x0200) {
if (src_format == FXDIB_Argb) {
- pAlphaMask = CloneAlphaMask();
+ pAlphaMask = CloneAlphaMask().release();
if (!pAlphaMask) {
FX_Free(dest_buf);
return false;
@@ -883,21 +879,25 @@ bool CFX_DIBitmap::ConvertFormat(FXDIB_Format dest_format) {
FX_Free(dest_buf);
return false;
}
- pAlphaMask = std::move(m_pAlphaMask);
+ pAlphaMask = m_pAlphaMask;
+ m_pAlphaMask = nullptr;
} else {
pAlphaMask = m_pAlphaMask;
}
}
}
bool ret = false;
- CFX_RetainPtr<CFX_DIBSource> holder(this);
std::unique_ptr<uint32_t, FxFreeDeleter> pal_8bpp;
ret = ConvertBuffer(dest_format, dest_buf, dest_pitch, m_Width, m_Height,
- holder, 0, 0, &pal_8bpp);
+ this, 0, 0, &pal_8bpp);
if (!ret) {
+ if (pAlphaMask != m_pAlphaMask)
+ delete pAlphaMask;
FX_Free(dest_buf);
return false;
}
+ if (m_pAlphaMask && pAlphaMask != m_pAlphaMask)
+ delete m_pAlphaMask;
m_pAlphaMask = pAlphaMask;
m_pPalette = std::move(pal_8bpp);
if (!m_bExtBuf)
diff --git a/core/fxge/dib/fx_dib_engine.cpp b/core/fxge/dib/fx_dib_engine.cpp
index 7aa710b795..5975a5e975 100644
--- a/core/fxge/dib/fx_dib_engine.cpp
+++ b/core/fxge/dib/fx_dib_engine.cpp
@@ -265,7 +265,7 @@ CStretchEngine::CStretchEngine(IFX_ScanlineComposer* pDestBitmap,
int dest_width,
int dest_height,
const FX_RECT& clip_rect,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ const CFX_DIBSource* pSrcBitmap,
int flags) {
m_State = 0;
m_DestFormat = dest_format;
@@ -852,13 +852,12 @@ void CStretchEngine::StretchVert() {
}
}
-CFX_ImageStretcher::CFX_ImageStretcher(
- IFX_ScanlineComposer* pDest,
- const CFX_RetainPtr<CFX_DIBSource>& pSource,
- int dest_width,
- int dest_height,
- const FX_RECT& bitmap_rect,
- uint32_t flags)
+CFX_ImageStretcher::CFX_ImageStretcher(IFX_ScanlineComposer* pDest,
+ const CFX_DIBSource* pSource,
+ int dest_width,
+ int dest_height,
+ const FX_RECT& bitmap_rect,
+ uint32_t flags)
: m_pDest(pDest),
m_pSource(pSource),
m_Flags(flags),
diff --git a/core/fxge/dib/fx_dib_engine_unittest.cpp b/core/fxge/dib/fx_dib_engine_unittest.cpp
index 86df82442f..705d761ca8 100644
--- a/core/fxge/dib/fx_dib_engine_unittest.cpp
+++ b/core/fxge/dib/fx_dib_engine_unittest.cpp
@@ -23,9 +23,9 @@ TEST(CStretchEngine, OverflowInCtor) {
dict_obj->SetNewFor<CPDF_Number>("Height", 12500);
std::unique_ptr<CPDF_Stream> stream =
pdfium::MakeUnique<CPDF_Stream>(nullptr, 0, std::move(dict_obj));
- auto dib_source = pdfium::MakeRetain<CPDF_DIBSource>();
- dib_source->Load(nullptr, stream.get());
- CStretchEngine engine(nullptr, FXDIB_8bppRgb, 500, 500, clip_rect, dib_source,
- 0);
+ CPDF_DIBSource dib_source;
+ dib_source.Load(nullptr, stream.get());
+ CStretchEngine engine(nullptr, FXDIB_8bppRgb, 500, 500, clip_rect,
+ &dib_source, 0);
EXPECT_EQ(FXDIB_INTERPOL, engine.m_Flags);
}
diff --git a/core/fxge/dib/fx_dib_main.cpp b/core/fxge/dib/fx_dib_main.cpp
index 8a97d342b5..96cae9d4e7 100644
--- a/core/fxge/dib/fx_dib_main.cpp
+++ b/core/fxge/dib/fx_dib_main.cpp
@@ -44,9 +44,16 @@ uint32_t ArgbEncode(int a, FX_COLORREF rgb) {
}
CFX_DIBSource::CFX_DIBSource()
- : m_Width(0), m_Height(0), m_bpp(0), m_AlphaFlag(0), m_Pitch(0) {}
-
-CFX_DIBSource::~CFX_DIBSource() {}
+ : m_pAlphaMask(nullptr),
+ m_Width(0),
+ m_Height(0),
+ m_bpp(0),
+ m_AlphaFlag(0),
+ m_Pitch(0) {}
+
+CFX_DIBSource::~CFX_DIBSource() {
+ delete m_pAlphaMask;
+}
uint8_t* CFX_DIBSource::GetBuffer() const {
return nullptr;
@@ -120,7 +127,7 @@ bool CFX_DIBitmap::Create(int width,
return true;
}
-bool CFX_DIBitmap::Copy(const CFX_RetainPtr<CFX_DIBSource>& pSrc) {
+bool CFX_DIBitmap::Copy(const CFX_DIBSource* pSrc) {
if (m_pBuffer)
return false;
@@ -150,10 +157,11 @@ const uint8_t* CFX_DIBitmap::GetScanline(int line) const {
return m_pBuffer ? m_pBuffer + line * m_Pitch : nullptr;
}
-void CFX_DIBitmap::TakeOver(CFX_RetainPtr<CFX_DIBitmap>&& pSrcBitmap) {
+void CFX_DIBitmap::TakeOver(CFX_DIBitmap* pSrcBitmap) {
if (!m_bExtBuf)
FX_Free(m_pBuffer);
+ delete m_pAlphaMask;
m_pBuffer = pSrcBitmap->m_pBuffer;
m_pPalette = std::move(pSrcBitmap->m_pPalette);
m_pAlphaMask = pSrcBitmap->m_pAlphaMask;
@@ -167,14 +175,14 @@ void CFX_DIBitmap::TakeOver(CFX_RetainPtr<CFX_DIBitmap>&& pSrcBitmap) {
m_Pitch = pSrcBitmap->m_Pitch;
}
-CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::Clone(const FX_RECT* pClip) const {
+std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::Clone(const FX_RECT* pClip) const {
FX_RECT rect(0, 0, m_Width, m_Height);
if (pClip) {
rect.Intersect(*pClip);
if (rect.IsEmpty())
return nullptr;
}
- auto pNewBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ auto pNewBitmap = pdfium::MakeUnique<CFX_DIBitmap>();
if (!pNewBitmap->Create(rect.Width(), rect.Height(), GetFormat()))
return nullptr;
@@ -232,11 +240,12 @@ void CFX_DIBSource::BuildPalette() {
}
bool CFX_DIBSource::BuildAlphaMask() {
- if (m_pAlphaMask)
+ if (m_pAlphaMask) {
return true;
-
- m_pAlphaMask = pdfium::MakeRetain<CFX_DIBitmap>();
+ }
+ m_pAlphaMask = new CFX_DIBitmap;
if (!m_pAlphaMask->Create(m_Width, m_Height, FXDIB_8bppMask)) {
+ delete m_pAlphaMask;
m_pAlphaMask = nullptr;
return false;
}
@@ -392,14 +401,13 @@ void CFX_DIBSource::GetOverlapRect(int& dest_left,
height = dest_rect.bottom - dest_rect.top;
}
-bool CFX_DIBitmap::TransferBitmap(
- int dest_left,
- int dest_top,
- int width,
- int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
- int src_left,
- int src_top) {
+bool CFX_DIBitmap::TransferBitmap(int dest_left,
+ int dest_top,
+ int width,
+ int height,
+ const CFX_DIBSource* pSrcBitmap,
+ int src_left,
+ int src_top) {
if (!m_pBuffer)
return false;
@@ -458,7 +466,7 @@ bool CFX_DIBitmap::TransferMask(int dest_left,
int dest_top,
int width,
int height,
- const CFX_RetainPtr<CFX_DIBSource>& pMask,
+ const CFX_DIBSource* pMask,
uint32_t color,
int src_left,
int src_top,
@@ -597,7 +605,7 @@ void CFX_DIBSource::GetPalette(uint32_t* pal, int alpha) const {
}
}
-CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::CloneAlphaMask(
+std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::CloneAlphaMask(
const FX_RECT* pClip) const {
ASSERT(GetFormat() == FXDIB_Argb);
FX_RECT rect(0, 0, m_Width, m_Height);
@@ -606,7 +614,7 @@ CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::CloneAlphaMask(
if (rect.IsEmpty())
return nullptr;
}
- auto pMask = pdfium::MakeRetain<CFX_DIBitmap>();
+ auto pMask = pdfium::MakeUnique<CFX_DIBitmap>();
if (!pMask->Create(rect.Width(), rect.Height(), FXDIB_8bppMask))
return nullptr;
@@ -622,7 +630,7 @@ CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::CloneAlphaMask(
return pMask;
}
-bool CFX_DIBSource::SetAlphaMask(const CFX_RetainPtr<CFX_DIBSource>& pAlphaMask,
+bool CFX_DIBSource::SetAlphaMask(const CFX_DIBSource* pAlphaMask,
const FX_RECT* pClip) {
if (!HasAlpha() || GetFormat() == FXDIB_Argb)
return false;
@@ -652,12 +660,12 @@ bool CFX_DIBSource::SetAlphaMask(const CFX_RetainPtr<CFX_DIBSource>& pAlphaMask,
const int g_ChannelOffset[] = {0, 2, 1, 0, 0, 1, 2, 3, 3};
bool CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ CFX_DIBSource* pSrcBitmap,
FXDIB_Channel srcChannel) {
if (!m_pBuffer)
return false;
- CFX_RetainPtr<CFX_DIBSource> pSrcClone = pSrcBitmap;
+ CFX_MaybeOwned<CFX_DIBSource> pSrcClone(pSrcBitmap);
int srcOffset;
if (srcChannel == FXDIB_Alpha) {
if (!pSrcBitmap->HasAlpha() && !pSrcBitmap->IsAlphaMask())
@@ -717,7 +725,7 @@ bool CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel,
destOffset = g_ChannelOffset[destChannel];
}
if (srcChannel == FXDIB_Alpha && pSrcClone->m_pAlphaMask) {
- CFX_RetainPtr<CFX_DIBSource> pAlphaMask = pSrcClone->m_pAlphaMask;
+ CFX_MaybeOwned<CFX_DIBSource> pAlphaMask(pSrcClone->m_pAlphaMask);
if (pSrcClone->GetWidth() != m_Width ||
pSrcClone->GetHeight() != m_Height) {
if (pAlphaMask) {
@@ -730,14 +738,14 @@ bool CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel,
srcOffset = 0;
} else if (pSrcClone->GetWidth() != m_Width ||
pSrcClone->GetHeight() != m_Height) {
- CFX_RetainPtr<CFX_DIBitmap> pSrcMatched =
+ std::unique_ptr<CFX_DIBitmap> pSrcMatched =
pSrcClone->StretchTo(m_Width, m_Height);
if (!pSrcMatched)
return false;
pSrcClone = std::move(pSrcMatched);
}
- CFX_RetainPtr<CFX_DIBitmap> pDst(this);
+ CFX_DIBitmap* pDst = this;
if (destChannel == FXDIB_Alpha && m_pAlphaMask) {
pDst = m_pAlphaMask;
destOffset = 0;
@@ -815,8 +823,7 @@ bool CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel, int value) {
return true;
}
-bool CFX_DIBitmap::MultiplyAlpha(
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap) {
+bool CFX_DIBitmap::MultiplyAlpha(CFX_DIBSource* pSrcBitmap) {
if (!m_pBuffer)
return false;
@@ -827,7 +834,8 @@ bool CFX_DIBitmap::MultiplyAlpha(
if (!IsAlphaMask() && !HasAlpha())
return LoadChannel(FXDIB_Alpha, pSrcBitmap, FXDIB_Alpha);
- CFX_RetainPtr<CFX_DIBitmap> pSrcClone = pSrcBitmap.As<CFX_DIBitmap>();
+ CFX_MaybeOwned<CFX_DIBitmap> pSrcClone(
+ static_cast<CFX_DIBitmap*>(pSrcBitmap));
if (pSrcBitmap->GetWidth() != m_Width ||
pSrcBitmap->GetHeight() != m_Height) {
pSrcClone = pSrcBitmap->StretchTo(m_Width, m_Height);
@@ -867,7 +875,7 @@ bool CFX_DIBitmap::MultiplyAlpha(
}
}
} else {
- m_pAlphaMask->MultiplyAlpha(pSrcClone);
+ m_pAlphaMask->MultiplyAlpha(pSrcClone.Get());
}
}
return true;
@@ -879,9 +887,9 @@ bool CFX_DIBitmap::GetGrayData(void* pIccTransform) {
}
switch (GetFormat()) {
case FXDIB_1bppRgb: {
- if (!m_pPalette)
+ if (!m_pPalette) {
return false;
-
+ }
uint8_t gray[2];
for (int i = 0; i < 2; i++) {
int r = static_cast<uint8_t>(m_pPalette.get()[i] >> 16);
@@ -889,10 +897,11 @@ bool CFX_DIBitmap::GetGrayData(void* pIccTransform) {
int b = static_cast<uint8_t>(m_pPalette.get()[i]);
gray[i] = static_cast<uint8_t>(FXRGB2GRAY(r, g, b));
}
- auto pMask = pdfium::MakeRetain<CFX_DIBitmap>();
- if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask))
+ CFX_DIBitmap* pMask = new CFX_DIBitmap;
+ if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) {
+ delete pMask;
return false;
-
+ }
FXSYS_memset(pMask->GetBuffer(), gray[0], pMask->GetPitch() * m_Height);
for (int row = 0; row < m_Height; row++) {
uint8_t* src_pos = m_pBuffer + row * m_Pitch;
@@ -904,13 +913,14 @@ bool CFX_DIBitmap::GetGrayData(void* pIccTransform) {
dest_pos++;
}
}
- TakeOver(std::move(pMask));
+ TakeOver(pMask);
+ delete pMask;
break;
}
case FXDIB_8bppRgb: {
- if (!m_pPalette)
+ if (!m_pPalette) {
return false;
-
+ }
uint8_t gray[256];
for (int i = 0; i < 256; i++) {
int r = static_cast<uint8_t>(m_pPalette.get()[i] >> 16);
@@ -918,10 +928,11 @@ bool CFX_DIBitmap::GetGrayData(void* pIccTransform) {
int b = static_cast<uint8_t>(m_pPalette.get()[i]);
gray[i] = static_cast<uint8_t>(FXRGB2GRAY(r, g, b));
}
- auto pMask = pdfium::MakeRetain<CFX_DIBitmap>();
- if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask))
+ CFX_DIBitmap* pMask = new CFX_DIBitmap;
+ if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) {
+ delete pMask;
return false;
-
+ }
for (int row = 0; row < m_Height; row++) {
uint8_t* dest_pos = pMask->GetBuffer() + row * pMask->GetPitch();
uint8_t* src_pos = m_pBuffer + row * m_Pitch;
@@ -929,14 +940,16 @@ bool CFX_DIBitmap::GetGrayData(void* pIccTransform) {
*dest_pos++ = gray[*src_pos++];
}
}
- TakeOver(std::move(pMask));
+ TakeOver(pMask);
+ delete pMask;
break;
}
case FXDIB_Rgb: {
- auto pMask = pdfium::MakeRetain<CFX_DIBitmap>();
- if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask))
+ CFX_DIBitmap* pMask = new CFX_DIBitmap;
+ if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) {
+ delete pMask;
return false;
-
+ }
for (int row = 0; row < m_Height; row++) {
uint8_t* src_pos = m_pBuffer + row * m_Pitch;
uint8_t* dest_pos = pMask->GetBuffer() + row * pMask->GetPitch();
@@ -945,14 +958,16 @@ bool CFX_DIBitmap::GetGrayData(void* pIccTransform) {
src_pos += 3;
}
}
- TakeOver(std::move(pMask));
+ TakeOver(pMask);
+ delete pMask;
break;
}
case FXDIB_Rgb32: {
- auto pMask = pdfium::MakeRetain<CFX_DIBitmap>();
- if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask))
+ CFX_DIBitmap* pMask = new CFX_DIBitmap;
+ if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) {
+ delete pMask;
return false;
-
+ }
for (int row = 0; row < m_Height; row++) {
uint8_t* src_pos = m_pBuffer + row * m_Pitch;
uint8_t* dest_pos = pMask->GetBuffer() + row * pMask->GetPitch();
@@ -961,7 +976,8 @@ bool CFX_DIBitmap::GetGrayData(void* pIccTransform) {
src_pos += 4;
}
}
- TakeOver(std::move(pMask));
+ TakeOver(pMask);
+ delete pMask;
break;
}
default:
@@ -1326,9 +1342,9 @@ bool CFX_DIBitmap::ConvertColorScale(uint32_t forecolor, uint32_t backcolor) {
return true;
}
-CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::FlipImage(bool bXFlip,
- bool bYFlip) const {
- auto pFlipped = pdfium::MakeRetain<CFX_DIBitmap>();
+std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::FlipImage(bool bXFlip,
+ bool bYFlip) const {
+ auto pFlipped = pdfium::MakeUnique<CFX_DIBitmap>();
if (!pFlipped->Create(m_Width, m_Height, GetFormat()))
return nullptr;
@@ -1398,12 +1414,12 @@ CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::FlipImage(bool bXFlip,
return pFlipped;
}
-CFX_DIBExtractor::CFX_DIBExtractor(const CFX_RetainPtr<CFX_DIBSource>& pSrc) {
+CFX_DIBExtractor::CFX_DIBExtractor(const CFX_DIBSource* pSrc) {
if (pSrc->GetBuffer()) {
- m_pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ m_pBitmap = pdfium::MakeUnique<CFX_DIBitmap>();
if (!m_pBitmap->Create(pSrc->GetWidth(), pSrc->GetHeight(),
pSrc->GetFormat(), pSrc->GetBuffer())) {
- m_pBitmap.Reset();
+ m_pBitmap.reset();
return;
}
m_pBitmap->SetPalette(pSrc->GetPalette());
@@ -1415,12 +1431,17 @@ CFX_DIBExtractor::CFX_DIBExtractor(const CFX_RetainPtr<CFX_DIBSource>& pSrc) {
CFX_DIBExtractor::~CFX_DIBExtractor() {}
-CFX_FilteredDIB::CFX_FilteredDIB() {}
+CFX_FilteredDIB::CFX_FilteredDIB() : m_pSrc(nullptr) {}
-CFX_FilteredDIB::~CFX_FilteredDIB() {}
+CFX_FilteredDIB::~CFX_FilteredDIB() {
+ if (m_bAutoDropSrc) {
+ delete m_pSrc;
+ }
+}
-void CFX_FilteredDIB::LoadSrc(const CFX_RetainPtr<CFX_DIBSource>& pSrc) {
+void CFX_FilteredDIB::LoadSrc(const CFX_DIBSource* pSrc, bool bAutoDropSrc) {
m_pSrc = pSrc;
+ m_bAutoDropSrc = bAutoDropSrc;
m_Width = pSrc->GetWidth();
m_Height = pSrc->GetHeight();
FXDIB_Format format = GetDestFormat();
@@ -1457,9 +1478,9 @@ CFX_ImageRenderer::CFX_ImageRenderer() {
CFX_ImageRenderer::~CFX_ImageRenderer() {}
-bool CFX_ImageRenderer::Start(const CFX_RetainPtr<CFX_DIBitmap>& pDevice,
+bool CFX_ImageRenderer::Start(CFX_DIBitmap* pDevice,
const CFX_ClipRgn* pClipRgn,
- const CFX_RetainPtr<CFX_DIBSource>& pSource,
+ const CFX_DIBSource* pSource,
int bitmap_alpha,
uint32_t mask_color,
const CFX_Matrix* pMatrix,
@@ -1548,7 +1569,7 @@ bool CFX_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 || !pBitmap->GetBuffer())
return false;
@@ -1564,16 +1585,16 @@ bool CFX_ImageRenderer::Continue(IFX_Pause* pPause) {
}
m_pDevice->CompositeMask(
m_pTransformer->result().left, m_pTransformer->result().top,
- pBitmap->GetWidth(), pBitmap->GetHeight(), pBitmap, m_MaskColor, 0, 0,
- m_BlendType, m_pClipRgn, m_bRgbByteOrder, m_AlphaFlag,
+ pBitmap->GetWidth(), pBitmap->GetHeight(), pBitmap.get(), m_MaskColor,
+ 0, 0, m_BlendType, m_pClipRgn, m_bRgbByteOrder, m_AlphaFlag,
m_pIccTransform);
} else {
if (m_BitmapAlpha != 255)
pBitmap->MultiplyAlpha(m_BitmapAlpha);
m_pDevice->CompositeBitmap(
m_pTransformer->result().left, m_pTransformer->result().top,
- pBitmap->GetWidth(), pBitmap->GetHeight(), pBitmap, 0, 0, m_BlendType,
- m_pClipRgn, m_bRgbByteOrder, m_pIccTransform);
+ pBitmap->GetWidth(), pBitmap->GetHeight(), pBitmap.get(), 0, 0,
+ m_BlendType, m_pClipRgn, m_bRgbByteOrder, m_pIccTransform);
}
return false;
}
@@ -1586,11 +1607,11 @@ CFX_BitmapStorer::CFX_BitmapStorer() {
CFX_BitmapStorer::~CFX_BitmapStorer() {
}
-CFX_RetainPtr<CFX_DIBitmap> CFX_BitmapStorer::Detach() {
+std::unique_ptr<CFX_DIBitmap> CFX_BitmapStorer::Detach() {
return std::move(m_pBitmap);
}
-void CFX_BitmapStorer::Replace(CFX_RetainPtr<CFX_DIBitmap>&& pBitmap) {
+void CFX_BitmapStorer::Replace(std::unique_ptr<CFX_DIBitmap> pBitmap) {
m_pBitmap = std::move(pBitmap);
}
@@ -1615,13 +1636,12 @@ bool CFX_BitmapStorer::SetInfo(int width,
int height,
FXDIB_Format src_format,
uint32_t* pSrcPalette) {
- auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
- if (!pBitmap->Create(width, height, src_format))
+ m_pBitmap = pdfium::MakeUnique<CFX_DIBitmap>();
+ if (!m_pBitmap->Create(width, height, src_format)) {
+ m_pBitmap.reset();
return false;
-
+ }
if (pSrcPalette)
- pBitmap->SetPalette(pSrcPalette);
-
- m_pBitmap = std::move(pBitmap);
+ m_pBitmap->SetPalette(pSrcPalette);
return true;
}
diff --git a/core/fxge/dib/fx_dib_transform.cpp b/core/fxge/dib/fx_dib_transform.cpp
index 3d8ddf8783..4a1c3ee050 100644
--- a/core/fxge/dib/fx_dib_transform.cpp
+++ b/core/fxge/dib/fx_dib_transform.cpp
@@ -100,7 +100,7 @@ void bicubic_get_pos_weight(int pos_pixel[],
v_w[3] = SDP_Table[512 - res_y];
}
-FXDIB_Format GetTransformedFormat(const CFX_RetainPtr<CFX_DIBSource>& pDrc) {
+FXDIB_Format GetTransformedFormat(const CFX_DIBSource* pDrc) {
FXDIB_Format format = pDrc->GetFormat();
if (pDrc->IsAlphaMask()) {
format = FXDIB_8bppMask;
@@ -179,7 +179,7 @@ class CFX_BilinearMatrix : public CPDF_FixedMatrix {
}
};
-CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::SwapXY(
+std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::SwapXY(
bool bXFlip,
bool bYFlip,
const FX_RECT* pDestClip) const {
@@ -189,7 +189,7 @@ CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::SwapXY(
if (dest_clip.IsEmpty())
return nullptr;
- auto pTransBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ auto pTransBitmap = pdfium::MakeUnique<CFX_DIBitmap>();
int result_height = dest_clip.Height();
int result_width = dest_clip.Width();
if (!pTransBitmap->Create(result_width, result_height, GetFormat()))
@@ -303,14 +303,13 @@ FX_RECT FXDIB_SwapClipBox(FX_RECT& clip,
return rect;
}
-CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::TransformTo(
+std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::TransformTo(
const CFX_Matrix* pDestMatrix,
int& result_left,
int& result_top,
uint32_t flags,
- const FX_RECT* pDestClip) {
- CFX_RetainPtr<CFX_DIBSource> holder(this);
- CFX_ImageTransformer transformer(holder, pDestMatrix, flags, pDestClip);
+ const FX_RECT* pDestClip) const {
+ CFX_ImageTransformer transformer(this, pDestMatrix, flags, pDestClip);
transformer.Start();
transformer.Continue(nullptr);
result_left = transformer.result().left;
@@ -318,11 +317,11 @@ CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::TransformTo(
return transformer.DetachBitmap();
}
-CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::StretchTo(int dest_width,
- int dest_height,
- uint32_t flags,
- const FX_RECT* pClip) {
- CFX_RetainPtr<CFX_DIBSource> holder(this);
+std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::StretchTo(
+ int dest_width,
+ int dest_height,
+ uint32_t flags,
+ const FX_RECT* pClip) const {
FX_RECT clip_rect(0, 0, FXSYS_abs(dest_width), FXSYS_abs(dest_height));
if (pClip)
clip_rect.Intersect(*pClip);
@@ -334,7 +333,7 @@ CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::StretchTo(int dest_width,
return Clone(&clip_rect);
CFX_BitmapStorer storer;
- CFX_ImageStretcher stretcher(&storer, holder, dest_width, dest_height,
+ CFX_ImageStretcher stretcher(&storer, this, dest_width, dest_height,
clip_rect, flags);
if (stretcher.Start())
stretcher.Continue(nullptr);
@@ -342,11 +341,10 @@ CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::StretchTo(int dest_width,
return storer.Detach();
}
-CFX_ImageTransformer::CFX_ImageTransformer(
- const CFX_RetainPtr<CFX_DIBSource>& pSrc,
- const CFX_Matrix* pMatrix,
- int flags,
- const FX_RECT* pClip)
+CFX_ImageTransformer::CFX_ImageTransformer(const CFX_DIBSource* pSrc,
+ const CFX_Matrix* pMatrix,
+ int flags,
+ const FX_RECT* pClip)
: m_pSrc(pSrc),
m_pMatrix(pMatrix),
m_pClip(pClip),
@@ -446,7 +444,7 @@ bool CFX_ImageTransformer::Continue(IFX_Pause* pPause) {
stretch_buf_mask = m_Storer.GetBitmap()->m_pAlphaMask->GetBuffer();
int stretch_pitch = m_Storer.GetBitmap()->GetPitch();
- auto pTransformed = pdfium::MakeRetain<CFX_DIBitmap>();
+ std::unique_ptr<CFX_DIBitmap> pTransformed(new CFX_DIBitmap);
FXDIB_Format transformF = GetTransformedFormat(m_Stretcher->source());
if (!pTransformed->Create(m_result.Width(), m_result.Height(), transformF))
return false;
@@ -960,6 +958,6 @@ bool CFX_ImageTransformer::Continue(IFX_Pause* pPause) {
return false;
}
-CFX_RetainPtr<CFX_DIBitmap> CFX_ImageTransformer::DetachBitmap() {
+std::unique_ptr<CFX_DIBitmap> CFX_ImageTransformer::DetachBitmap() {
return m_Storer.Detach();
}
diff --git a/core/fxge/fx_dib.h b/core/fxge/fx_dib.h
index 2208276fa7..14be05fafe 100644
--- a/core/fxge/fx_dib.h
+++ b/core/fxge/fx_dib.h
@@ -10,10 +10,9 @@
#include <memory>
#include <vector>
-#include "core/fxcrt/cfx_retain_ptr.h"
+#include "core/fxcrt/cfx_shared_copy_on_write.h"
#include "core/fxcrt/fx_basic.h"
#include "core/fxcrt/fx_coordinates.h"
-#include "third_party/base/stl_util.h"
enum FXDIB_Format {
FXDIB_Invalid = 0,
@@ -164,14 +163,14 @@ bool ConvertBuffer(FXDIB_Format dest_format,
int dest_pitch,
int width,
int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ const CFX_DIBSource* pSrcBitmap,
int src_left,
int src_top,
std::unique_ptr<uint32_t, FxFreeDeleter>* pal);
-class CFX_DIBSource : public CFX_Retainable {
+class CFX_DIBSource {
public:
- ~CFX_DIBSource() override;
+ virtual ~CFX_DIBSource();
virtual uint8_t* GetBuffer() const;
virtual const uint8_t* GetScanline(int line) const = 0;
@@ -217,29 +216,31 @@ class CFX_DIBSource : public CFX_Retainable {
// Copies into internally-owned palette.
void SetPalette(const uint32_t* pSrcPal);
- CFX_RetainPtr<CFX_DIBitmap> Clone(const FX_RECT* pClip = nullptr) const;
- CFX_RetainPtr<CFX_DIBitmap> CloneConvert(FXDIB_Format format);
- CFX_RetainPtr<CFX_DIBitmap> StretchTo(int dest_width,
- int dest_height,
- uint32_t flags = 0,
- const FX_RECT* pClip = nullptr);
- CFX_RetainPtr<CFX_DIBitmap> TransformTo(const CFX_Matrix* pMatrix,
- int& left,
- int& top,
+ std::unique_ptr<CFX_DIBitmap> Clone(const FX_RECT* pClip = nullptr) const;
+ std::unique_ptr<CFX_DIBitmap> CloneConvert(FXDIB_Format format) const;
+ std::unique_ptr<CFX_DIBitmap> StretchTo(int dest_width,
+ int dest_height,
uint32_t flags = 0,
- const FX_RECT* pClip = nullptr);
- CFX_RetainPtr<CFX_DIBitmap> SwapXY(bool bXFlip,
- bool bYFlip,
- const FX_RECT* pClip = nullptr) const;
- CFX_RetainPtr<CFX_DIBitmap> FlipImage(bool bXFlip, bool bYFlip) const;
+ const FX_RECT* pClip = nullptr) const;
+ std::unique_ptr<CFX_DIBitmap> TransformTo(
+ const CFX_Matrix* pMatrix,
+ int& left,
+ int& top,
+ uint32_t flags = 0,
+ const FX_RECT* pClip = nullptr) const;
+ std::unique_ptr<CFX_DIBitmap> SwapXY(bool bXFlip,
+ bool bYFlip,
+ const FX_RECT* pClip = nullptr) const;
+ std::unique_ptr<CFX_DIBitmap> FlipImage(bool bXFlip, bool bYFlip) const;
- CFX_RetainPtr<CFX_DIBitmap> CloneAlphaMask(
+ std::unique_ptr<CFX_DIBitmap> CloneAlphaMask(
const FX_RECT* pClip = nullptr) const;
// Copies into internally-owned mask.
- bool SetAlphaMask(const CFX_RetainPtr<CFX_DIBSource>& pAlphaMask,
+ bool SetAlphaMask(const CFX_DIBSource* pAlphaMask,
const FX_RECT* pClip = nullptr);
+
void GetOverlapRect(int& dest_left,
int& dest_top,
int& width,
@@ -254,7 +255,7 @@ class CFX_DIBSource : public CFX_Retainable {
void DebugVerifyBitmapIsPreMultiplied(void* buffer = nullptr) const;
#endif
- CFX_RetainPtr<CFX_DIBitmap> m_pAlphaMask;
+ CFX_DIBitmap* m_pAlphaMask;
protected:
CFX_DIBSource();
@@ -275,9 +276,8 @@ class CFX_DIBSource : public CFX_Retainable {
class CFX_DIBitmap : public CFX_DIBSource {
public:
- template <typename T, typename... Args>
- friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args);
-
+ CFX_DIBitmap();
+ explicit CFX_DIBitmap(const CFX_DIBitmap& src);
~CFX_DIBitmap() override;
bool Create(int width,
@@ -286,7 +286,7 @@ class CFX_DIBitmap : public CFX_DIBSource {
uint8_t* pBuffer = nullptr,
int pitch = 0);
- bool Copy(const CFX_RetainPtr<CFX_DIBSource>& pSrc);
+ bool Copy(const CFX_DIBSource* pSrc);
// CFX_DIBSource
uint8_t* GetBuffer() const override;
@@ -299,26 +299,31 @@ class CFX_DIBitmap : public CFX_DIBSource {
int clip_left,
int clip_width) const override;
- void TakeOver(CFX_RetainPtr<CFX_DIBitmap>&& pSrcBitmap);
+ void TakeOver(CFX_DIBitmap* pSrcBitmap);
+
bool ConvertFormat(FXDIB_Format format);
+
void Clear(uint32_t color);
uint32_t GetPixel(int x, int y) const;
+
void SetPixel(int x, int y, uint32_t color);
bool LoadChannel(FXDIB_Channel destChannel,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ CFX_DIBSource* pSrcBitmap,
FXDIB_Channel srcChannel);
+
bool LoadChannel(FXDIB_Channel destChannel, int value);
bool MultiplyAlpha(int alpha);
- bool MultiplyAlpha(const CFX_RetainPtr<CFX_DIBSource>& pAlphaMask);
+
+ bool MultiplyAlpha(CFX_DIBSource* pAlphaMask);
bool TransferBitmap(int dest_left,
int dest_top,
int width,
int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ const CFX_DIBSource* pSrcBitmap,
int src_left,
int src_top);
@@ -326,7 +331,7 @@ class CFX_DIBitmap : public CFX_DIBSource {
int dest_top,
int width,
int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ const CFX_DIBSource* pSrcBitmap,
int src_left,
int src_top,
int blend_type = FXDIB_BLEND_NORMAL,
@@ -338,7 +343,7 @@ class CFX_DIBitmap : public CFX_DIBSource {
int dest_top,
int width,
int height,
- const CFX_RetainPtr<CFX_DIBSource>& pMask,
+ const CFX_DIBSource* pMask,
uint32_t color,
int src_left,
int src_top,
@@ -349,7 +354,7 @@ class CFX_DIBitmap : public CFX_DIBSource {
int dest_top,
int width,
int height,
- const CFX_RetainPtr<CFX_DIBSource>& pMask,
+ const CFX_DIBSource* pMask,
uint32_t color,
int src_left,
int src_top,
@@ -377,8 +382,6 @@ class CFX_DIBitmap : public CFX_DIBSource {
#endif
protected:
- CFX_DIBitmap();
- CFX_DIBitmap(const CFX_DIBitmap& src);
bool GetGrayData(void* pIccTransform = nullptr);
#if defined _SKIA_SUPPORT_PATHS_
@@ -394,36 +397,37 @@ class CFX_DIBitmap : public CFX_DIBSource {
class CFX_DIBExtractor {
public:
- explicit CFX_DIBExtractor(const CFX_RetainPtr<CFX_DIBSource>& pSrc);
+ explicit CFX_DIBExtractor(const CFX_DIBSource* pSrc);
~CFX_DIBExtractor();
- CFX_RetainPtr<CFX_DIBitmap> GetBitmap() { return m_pBitmap; }
+ CFX_DIBitmap* GetBitmap() { return m_pBitmap.get(); }
private:
- CFX_RetainPtr<CFX_DIBitmap> m_pBitmap;
+ std::unique_ptr<CFX_DIBitmap> m_pBitmap;
};
+typedef CFX_SharedCopyOnWrite<CFX_DIBitmap> CFX_DIBitmapRef;
+
class CFX_FilteredDIB : public CFX_DIBSource {
public:
- template <typename T, typename... Args>
- friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args);
-
+ CFX_FilteredDIB();
~CFX_FilteredDIB() override;
+ void LoadSrc(const CFX_DIBSource* pSrc, bool bAutoDropSrc = false);
+
virtual FXDIB_Format GetDestFormat() = 0;
+
virtual uint32_t* GetDestPalette() = 0;
+
virtual void TranslateScanline(const uint8_t* src_buf,
std::vector<uint8_t>* dest_buf) const = 0;
+
virtual void TranslateDownSamples(uint8_t* dest_buf,
const uint8_t* src_buf,
int pixels,
int Bpp) const = 0;
- void LoadSrc(const CFX_RetainPtr<CFX_DIBSource>& pSrc);
-
protected:
- CFX_FilteredDIB();
-
// CFX_DIBSource
const uint8_t* GetScanline(int line) const override;
void DownSampleScanline(int line,
@@ -434,7 +438,8 @@ class CFX_FilteredDIB : public CFX_DIBSource {
int clip_left,
int clip_width) const override;
- CFX_RetainPtr<CFX_DIBSource> m_pSrc;
+ const CFX_DIBSource* m_pSrc;
+ bool m_bAutoDropSrc;
mutable std::vector<uint8_t> m_Scanline;
};
@@ -515,7 +520,7 @@ class CFX_BitmapComposer : public IFX_ScanlineComposer {
CFX_BitmapComposer();
~CFX_BitmapComposer() override;
- void Compose(const CFX_RetainPtr<CFX_DIBitmap>& pDest,
+ void Compose(CFX_DIBitmap* pDest,
const CFX_ClipRgn* pClipRgn,
int bitmap_alpha,
uint32_t mask_color,
@@ -545,28 +550,21 @@ class CFX_BitmapComposer : public IFX_ScanlineComposer {
const uint8_t* clip_scan,
const uint8_t* src_extra_alpha = nullptr,
uint8_t* dst_extra_alpha = nullptr);
- void ComposeScanlineV(int line,
- const uint8_t* scanline,
- const uint8_t* scan_extra_alpha = nullptr);
-
- CFX_RetainPtr<CFX_DIBitmap> m_pBitmap;
+ CFX_DIBitmap* m_pBitmap;
const CFX_ClipRgn* m_pClipRgn;
FXDIB_Format m_SrcFormat;
- int m_DestLeft;
- int m_DestTop;
- int m_DestWidth;
- int m_DestHeight;
- int m_BitmapAlpha;
+ int m_DestLeft, m_DestTop, m_DestWidth, m_DestHeight, m_BitmapAlpha;
uint32_t m_MaskColor;
- CFX_RetainPtr<CFX_DIBitmap> m_pClipMask;
+ const CFX_DIBitmap* m_pClipMask;
CFX_ScanlineCompositor m_Compositor;
- bool m_bVertical;
- bool m_bFlipX;
- bool m_bFlipY;
+ bool m_bVertical, m_bFlipX, m_bFlipY;
int m_AlphaFlag;
void* m_pIccTransform;
bool m_bRgbByteOrder;
int m_BlendType;
+ void ComposeScanlineV(int line,
+ const uint8_t* scanline,
+ const uint8_t* scan_extra_alpha = nullptr);
uint8_t* m_pScanlineV;
uint8_t* m_pClipScanV;
uint8_t* m_pAddClipScan;
@@ -587,18 +585,18 @@ class CFX_BitmapStorer : public IFX_ScanlineComposer {
FXDIB_Format src_format,
uint32_t* pSrcPalette) override;
- CFX_RetainPtr<CFX_DIBitmap> GetBitmap() { return m_pBitmap; }
- CFX_RetainPtr<CFX_DIBitmap> Detach();
- void Replace(CFX_RetainPtr<CFX_DIBitmap>&& pBitmap);
+ CFX_DIBitmap* GetBitmap() { return m_pBitmap.get(); }
+ std::unique_ptr<CFX_DIBitmap> Detach();
+ void Replace(std::unique_ptr<CFX_DIBitmap> pBitmap);
private:
- CFX_RetainPtr<CFX_DIBitmap> m_pBitmap;
+ std::unique_ptr<CFX_DIBitmap> m_pBitmap;
};
class CFX_ImageStretcher {
public:
CFX_ImageStretcher(IFX_ScanlineComposer* pDest,
- const CFX_RetainPtr<CFX_DIBSource>& pSource,
+ const CFX_DIBSource* pSource,
int dest_width,
int dest_height,
const FX_RECT& bitmap_rect,
@@ -608,7 +606,7 @@ class CFX_ImageStretcher {
bool Start();
bool Continue(IFX_Pause* pPause);
- CFX_RetainPtr<CFX_DIBSource> source() { return m_pSource; }
+ const CFX_DIBSource* source() { return m_pSource; }
private:
bool StartQuickStretch();
@@ -617,7 +615,7 @@ class CFX_ImageStretcher {
bool ContinueStretch(IFX_Pause* pPause);
IFX_ScanlineComposer* const m_pDest;
- CFX_RetainPtr<CFX_DIBSource> m_pSource;
+ const CFX_DIBSource* const m_pSource;
std::unique_ptr<CStretchEngine> m_pStretchEngine;
std::unique_ptr<uint8_t, FxFreeDeleter> m_pScanline;
std::unique_ptr<uint8_t, FxFreeDeleter> m_pMaskScanline;
@@ -634,7 +632,7 @@ class CFX_ImageStretcher {
class CFX_ImageTransformer {
public:
- CFX_ImageTransformer(const CFX_RetainPtr<CFX_DIBSource>& pSrc,
+ CFX_ImageTransformer(const CFX_DIBSource* pSrc,
const CFX_Matrix* pMatrix,
int flags,
const FX_RECT* pClip);
@@ -644,10 +642,10 @@ class CFX_ImageTransformer {
bool Continue(IFX_Pause* pPause);
const FX_RECT& result() const { return m_result; }
- CFX_RetainPtr<CFX_DIBitmap> DetachBitmap();
+ std::unique_ptr<CFX_DIBitmap> DetachBitmap();
private:
- const CFX_RetainPtr<CFX_DIBSource> m_pSrc;
+ const CFX_DIBSource* const m_pSrc;
const CFX_Matrix* const m_pMatrix;
const FX_RECT* const m_pClip;
FX_RECT m_StretchClip;
@@ -664,9 +662,9 @@ class CFX_ImageRenderer {
CFX_ImageRenderer();
~CFX_ImageRenderer();
- bool Start(const CFX_RetainPtr<CFX_DIBitmap>& pDevice,
+ bool Start(CFX_DIBitmap* pDevice,
const CFX_ClipRgn* pClipRgn,
- const CFX_RetainPtr<CFX_DIBSource>& pSource,
+ const CFX_DIBSource* pSource,
int bitmap_alpha,
uint32_t mask_color,
const CFX_Matrix* pMatrix,
@@ -679,7 +677,7 @@ class CFX_ImageRenderer {
bool Continue(IFX_Pause* pPause);
protected:
- CFX_RetainPtr<CFX_DIBitmap> m_pDevice;
+ CFX_DIBitmap* m_pDevice;
const CFX_ClipRgn* m_pClipRgn;
int m_BitmapAlpha;
uint32_t m_MaskColor;
diff --git a/core/fxge/fx_font.h b/core/fxge/fx_font.h
index 880b6751e8..79957ef506 100644
--- a/core/fxge/fx_font.h
+++ b/core/fxge/fx_font.h
@@ -222,19 +222,11 @@ class CFX_FontFaceInfo {
class CFX_GlyphBitmap {
public:
- CFX_GlyphBitmap();
- ~CFX_GlyphBitmap();
-
int m_Top;
int m_Left;
- CFX_RetainPtr<CFX_DIBitmap> m_pBitmap;
+ CFX_DIBitmap m_Bitmap;
};
-inline CFX_GlyphBitmap::CFX_GlyphBitmap()
- : m_pBitmap(pdfium::MakeRetain<CFX_DIBitmap>()) {}
-
-inline CFX_GlyphBitmap::~CFX_GlyphBitmap() {}
-
class FXTEXT_GLYPHPOS {
public:
FXTEXT_GLYPHPOS();
diff --git a/core/fxge/ge/cfx_cliprgn.cpp b/core/fxge/ge/cfx_cliprgn.cpp
index 5193ce2944..ea3eb51f18 100644
--- a/core/fxge/ge/cfx_cliprgn.cpp
+++ b/core/fxge/ge/cfx_cliprgn.cpp
@@ -6,8 +6,6 @@
#include "core/fxge/ge/cfx_cliprgn.h"
-#include <utility>
-
CFX_ClipRgn::CFX_ClipRgn(int width, int height)
: m_Type(RectI), m_Box(0, 0, width, height) {}
@@ -22,7 +20,7 @@ CFX_ClipRgn::~CFX_ClipRgn() {}
void CFX_ClipRgn::Reset(const FX_RECT& rect) {
m_Type = RectI;
m_Box = rect;
- m_Mask = nullptr;
+ m_Mask.SetNull();
}
void CFX_ClipRgn::IntersectRect(const FX_RECT& rect) {
@@ -38,7 +36,8 @@ void CFX_ClipRgn::IntersectRect(const FX_RECT& rect) {
void CFX_ClipRgn::IntersectMaskRect(FX_RECT rect,
FX_RECT mask_rect,
- const CFX_RetainPtr<CFX_DIBitmap>& pMask) {
+ CFX_DIBitmapRef Mask) {
+ const CFX_DIBitmap* mask_dib = Mask.GetObject();
m_Type = MaskF;
m_Box = rect;
m_Box.Intersect(mask_rect);
@@ -47,29 +46,28 @@ void CFX_ClipRgn::IntersectMaskRect(FX_RECT rect,
return;
}
if (m_Box == mask_rect) {
- m_Mask = pMask;
+ m_Mask = Mask;
return;
}
- m_Mask = pdfium::MakeRetain<CFX_DIBitmap>();
- m_Mask->Create(m_Box.Width(), m_Box.Height(), FXDIB_8bppMask);
+ CFX_DIBitmap* new_dib = m_Mask.Emplace();
+ new_dib->Create(m_Box.Width(), m_Box.Height(), FXDIB_8bppMask);
for (int row = m_Box.top; row < m_Box.bottom; row++) {
uint8_t* dest_scan =
- m_Mask->GetBuffer() + m_Mask->GetPitch() * (row - m_Box.top);
+ new_dib->GetBuffer() + new_dib->GetPitch() * (row - m_Box.top);
uint8_t* src_scan =
- pMask->GetBuffer() + pMask->GetPitch() * (row - mask_rect.top);
+ mask_dib->GetBuffer() + mask_dib->GetPitch() * (row - mask_rect.top);
for (int col = m_Box.left; col < m_Box.right; col++)
dest_scan[col - m_Box.left] = src_scan[col - mask_rect.left];
}
}
-void CFX_ClipRgn::IntersectMaskF(int left,
- int top,
- const CFX_RetainPtr<CFX_DIBitmap>& pMask) {
- ASSERT(pMask->GetFormat() == FXDIB_8bppMask);
- FX_RECT mask_box(left, top, left + pMask->GetWidth(),
- top + pMask->GetHeight());
+void CFX_ClipRgn::IntersectMaskF(int left, int top, CFX_DIBitmapRef Mask) {
+ const CFX_DIBitmap* mask_dib = Mask.GetObject();
+ ASSERT(mask_dib->GetFormat() == FXDIB_8bppMask);
+ FX_RECT mask_box(left, top, left + mask_dib->GetWidth(),
+ top + mask_dib->GetHeight());
if (m_Type == RectI) {
- IntersectMaskRect(m_Box, mask_box, pMask);
+ IntersectMaskRect(m_Box, mask_box, Mask);
return;
}
if (m_Type == MaskF) {
@@ -77,16 +75,19 @@ void CFX_ClipRgn::IntersectMaskF(int left,
new_box.Intersect(mask_box);
if (new_box.IsEmpty()) {
m_Type = RectI;
- m_Mask = nullptr;
+ m_Mask.SetNull();
m_Box = new_box;
return;
}
- auto new_dib = pdfium::MakeRetain<CFX_DIBitmap>();
+ CFX_DIBitmapRef new_mask;
+ CFX_DIBitmap* new_dib = new_mask.Emplace();
new_dib->Create(new_box.Width(), new_box.Height(), FXDIB_8bppMask);
+ const CFX_DIBitmap* old_dib = m_Mask.GetObject();
for (int row = new_box.top; row < new_box.bottom; row++) {
uint8_t* old_scan =
- m_Mask->GetBuffer() + (row - m_Box.top) * m_Mask->GetPitch();
- uint8_t* mask_scan = pMask->GetBuffer() + (row - top) * pMask->GetPitch();
+ old_dib->GetBuffer() + (row - m_Box.top) * old_dib->GetPitch();
+ uint8_t* mask_scan =
+ mask_dib->GetBuffer() + (row - top) * mask_dib->GetPitch();
uint8_t* new_scan =
new_dib->GetBuffer() + (row - new_box.top) * new_dib->GetPitch();
for (int col = new_box.left; col < new_box.right; col++) {
@@ -95,7 +96,7 @@ void CFX_ClipRgn::IntersectMaskF(int left,
}
}
m_Box = new_box;
- m_Mask = std::move(new_dib);
+ m_Mask = new_mask;
return;
}
ASSERT(false);
diff --git a/core/fxge/ge/cfx_cliprgn.h b/core/fxge/ge/cfx_cliprgn.h
index ae12347288..f3fd5856b6 100644
--- a/core/fxge/ge/cfx_cliprgn.h
+++ b/core/fxge/ge/cfx_cliprgn.h
@@ -19,22 +19,18 @@ class CFX_ClipRgn {
ClipType GetType() const { return m_Type; }
const FX_RECT& GetBox() const { return m_Box; }
- CFX_RetainPtr<CFX_DIBitmap> GetMask() const { return m_Mask; }
+ CFX_DIBitmapRef GetMask() const { return m_Mask; }
void Reset(const FX_RECT& rect);
void IntersectRect(const FX_RECT& rect);
- void IntersectMaskF(int left,
- int top,
- const CFX_RetainPtr<CFX_DIBitmap>& Mask);
+ void IntersectMaskF(int left, int top, CFX_DIBitmapRef Mask);
private:
- void IntersectMaskRect(FX_RECT rect,
- FX_RECT mask_box,
- const CFX_RetainPtr<CFX_DIBitmap>& Mask);
+ void IntersectMaskRect(FX_RECT rect, FX_RECT mask_box, CFX_DIBitmapRef Mask);
ClipType m_Type;
FX_RECT m_Box;
- CFX_RetainPtr<CFX_DIBitmap> m_Mask;
+ CFX_DIBitmapRef m_Mask;
};
#endif // CORE_FXGE_GE_CFX_CLIPRGN_H_
diff --git a/core/fxge/ge/cfx_facecache.cpp b/core/fxge/ge/cfx_facecache.cpp
index 4c44660426..3cdff44f8b 100644
--- a/core/fxge/ge/cfx_facecache.cpp
+++ b/core/fxge/ge/cfx_facecache.cpp
@@ -182,14 +182,14 @@ CFX_GlyphBitmap* CFX_FaceCache::RenderGlyph(const CFX_Font* pFont,
return nullptr;
int dib_width = bmwidth;
CFX_GlyphBitmap* pGlyphBitmap = new CFX_GlyphBitmap;
- pGlyphBitmap->m_pBitmap->Create(
+ pGlyphBitmap->m_Bitmap.Create(
dib_width, bmheight,
anti_alias == FXFT_RENDER_MODE_MONO ? FXDIB_1bppMask : FXDIB_8bppMask);
pGlyphBitmap->m_Left = FXFT_Get_Glyph_BitmapLeft(m_Face);
pGlyphBitmap->m_Top = FXFT_Get_Glyph_BitmapTop(m_Face);
- int dest_pitch = pGlyphBitmap->m_pBitmap->GetPitch();
+ int dest_pitch = pGlyphBitmap->m_Bitmap.GetPitch();
int src_pitch = FXFT_Get_Bitmap_Pitch(FXFT_Get_Glyph_Bitmap(m_Face));
- uint8_t* pDestBuf = pGlyphBitmap->m_pBitmap->GetBuffer();
+ uint8_t* pDestBuf = pGlyphBitmap->m_Bitmap.GetBuffer();
uint8_t* pSrcBuf =
(uint8_t*)FXFT_Get_Bitmap_Buffer(FXFT_Get_Glyph_Bitmap(m_Face));
if (anti_alias != FXFT_RENDER_MODE_MONO &&
diff --git a/core/fxge/ge/cfx_renderdevice.cpp b/core/fxge/ge/cfx_renderdevice.cpp
index 782dbf3e2f..fab318373a 100644
--- a/core/fxge/ge/cfx_renderdevice.cpp
+++ b/core/fxge/ge/cfx_renderdevice.cpp
@@ -194,8 +194,8 @@ void SetAlpha(uint8_t* alpha) {
void SetAlphaDoNothing(uint8_t* alpha) {}
-void DrawNormalTextHelper(const CFX_RetainPtr<CFX_DIBitmap>& bitmap,
- const CFX_RetainPtr<CFX_DIBitmap>& pGlyph,
+void DrawNormalTextHelper(CFX_DIBitmap* bitmap,
+ const CFX_DIBitmap* pGlyph,
int nrows,
int left,
int top,
@@ -416,10 +416,9 @@ CFX_Matrix CFX_RenderDevice::GetCTM() const {
return m_pDeviceDriver->GetCTM();
}
-bool CFX_RenderDevice::CreateCompatibleBitmap(
- const CFX_RetainPtr<CFX_DIBitmap>& pDIB,
- int width,
- int height) const {
+bool CFX_RenderDevice::CreateCompatibleBitmap(CFX_DIBitmap* pDIB,
+ int width,
+ int height) const {
if (m_RenderCaps & FXRC_CMYK_OUTPUT) {
return pDIB->Create(width, height, m_RenderCaps & FXRC_ALPHA_OUTPUT
? FXDIB_Cmyka
@@ -611,23 +610,21 @@ bool CFX_RenderDevice::DrawFillStrokePath(const CFX_PathData* pPathData,
float fScaleX = FXSYS_fabs(ctm.a);
float fScaleY = FXSYS_fabs(ctm.d);
FX_RECT rect = bbox.GetOuterRect();
- auto bitmap = pdfium::MakeRetain<CFX_DIBitmap>();
- auto Backdrop = pdfium::MakeRetain<CFX_DIBitmap>();
- if (!CreateCompatibleBitmap(bitmap, FXSYS_round(rect.Width() * fScaleX),
+ CFX_DIBitmap bitmap, Backdrop;
+ if (!CreateCompatibleBitmap(&bitmap, FXSYS_round(rect.Width() * fScaleX),
FXSYS_round(rect.Height() * fScaleY))) {
return false;
}
- if (bitmap->HasAlpha()) {
- bitmap->Clear(0);
- Backdrop->Copy(bitmap);
+ if (bitmap.HasAlpha()) {
+ bitmap.Clear(0);
+ Backdrop.Copy(&bitmap);
} else {
- if (!m_pDeviceDriver->GetDIBits(bitmap, rect.left, rect.top))
+ if (!m_pDeviceDriver->GetDIBits(&bitmap, rect.left, rect.top))
return false;
- Backdrop->Copy(bitmap);
+ Backdrop.Copy(&bitmap);
}
CFX_FxgeDevice bitmap_device;
- bitmap_device.Attach(bitmap, false, Backdrop, true);
-
+ bitmap_device.Attach(&bitmap, false, &Backdrop, true);
CFX_Matrix matrix;
if (pObject2Device)
matrix = *pObject2Device;
@@ -643,7 +640,7 @@ bool CFX_RenderDevice::DrawFillStrokePath(const CFX_PathData* pPathData,
#endif
FX_RECT src_rect(0, 0, FXSYS_round(rect.Width() * fScaleX),
FXSYS_round(rect.Height() * fScaleY));
- return m_pDeviceDriver->SetDIBits(bitmap, 0, &src_rect, rect.left, rect.top,
+ return m_pDeviceDriver->SetDIBits(&bitmap, 0, &src_rect, rect.left, rect.top,
FXDIB_BLEND_NORMAL);
}
@@ -664,19 +661,19 @@ bool CFX_RenderDevice::FillRectWithBlend(const FX_RECT* pRect,
if (!(m_RenderCaps & FXRC_GET_BITS))
return false;
- auto bitmap = pdfium::MakeRetain<CFX_DIBitmap>();
- if (!CreateCompatibleBitmap(bitmap, pRect->Width(), pRect->Height()))
+ CFX_DIBitmap bitmap;
+ if (!CreateCompatibleBitmap(&bitmap, pRect->Width(), pRect->Height()))
return false;
- if (!m_pDeviceDriver->GetDIBits(bitmap, pRect->left, pRect->top))
+ if (!m_pDeviceDriver->GetDIBits(&bitmap, pRect->left, pRect->top))
return false;
- if (!bitmap->CompositeRect(0, 0, pRect->Width(), pRect->Height(), fill_color,
- 0, nullptr)) {
+ if (!bitmap.CompositeRect(0, 0, pRect->Width(), pRect->Height(), fill_color,
+ 0, nullptr)) {
return false;
}
FX_RECT src_rect(0, 0, pRect->Width(), pRect->Height());
- m_pDeviceDriver->SetDIBits(bitmap, 0, &src_rect, pRect->left, pRect->top,
+ m_pDeviceDriver->SetDIBits(&bitmap, 0, &src_rect, pRect->left, pRect->top,
FXDIB_BLEND_NORMAL);
return true;
}
@@ -700,23 +697,20 @@ bool CFX_RenderDevice::DrawCosmeticLine(float x1,
fill_mode, blend_type);
}
-bool CFX_RenderDevice::GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
- int left,
- int top) {
+bool CFX_RenderDevice::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) {
if (!(m_RenderCaps & FXRC_GET_BITS))
return false;
return m_pDeviceDriver->GetDIBits(pBitmap, left, top);
}
-CFX_RetainPtr<CFX_DIBitmap> CFX_RenderDevice::GetBackDrop() {
+CFX_DIBitmap* CFX_RenderDevice::GetBackDrop() {
return m_pDeviceDriver->GetBackDrop();
}
-bool CFX_RenderDevice::SetDIBitsWithBlend(
- const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
- int left,
- int top,
- int blend_mode) {
+bool CFX_RenderDevice::SetDIBitsWithBlend(const CFX_DIBSource* pBitmap,
+ int left,
+ int top,
+ int blend_mode) {
ASSERT(!pBitmap->IsAlphaMask());
CFX_Matrix ctm = GetCTM();
float fScaleX = FXSYS_fabs(ctm.a);
@@ -727,7 +721,6 @@ bool CFX_RenderDevice::SetDIBitsWithBlend(
dest_rect.Intersect(m_ClipBox);
if (dest_rect.IsEmpty())
return true;
-
FX_RECT src_rect(dest_rect.left - left, dest_rect.top - top,
dest_rect.left - left + dest_rect.Width(),
dest_rect.top - top + dest_rect.Height());
@@ -739,26 +732,25 @@ bool CFX_RenderDevice::SetDIBitsWithBlend(
(pBitmap->HasAlpha() && !(m_RenderCaps & FXRC_ALPHA_IMAGE))) {
if (!(m_RenderCaps & FXRC_GET_BITS))
return false;
-
int bg_pixel_width = FXSYS_round(dest_rect.Width() * fScaleX);
int bg_pixel_height = FXSYS_round(dest_rect.Height() * fScaleY);
- auto background = pdfium::MakeRetain<CFX_DIBitmap>();
- if (!background->Create(
+ CFX_DIBitmap background;
+ if (!background.Create(
bg_pixel_width, bg_pixel_height,
(m_RenderCaps & FXRC_CMYK_OUTPUT) ? FXDIB_Cmyk : FXDIB_Rgb32)) {
return false;
}
- if (!m_pDeviceDriver->GetDIBits(background, dest_rect.left,
+ if (!m_pDeviceDriver->GetDIBits(&background, dest_rect.left,
dest_rect.top)) {
return false;
}
- if (!background->CompositeBitmap(0, 0, bg_pixel_width, bg_pixel_height,
- pBitmap, src_rect.left, src_rect.top,
- blend_mode, nullptr, false, nullptr)) {
+ if (!background.CompositeBitmap(0, 0, bg_pixel_width, bg_pixel_height,
+ pBitmap, src_rect.left, src_rect.top,
+ blend_mode, nullptr, false, nullptr)) {
return false;
}
FX_RECT rect(0, 0, bg_pixel_width, bg_pixel_height);
- return m_pDeviceDriver->SetDIBits(background, 0, &rect, dest_rect.left,
+ return m_pDeviceDriver->SetDIBits(&background, 0, &rect, dest_rect.left,
dest_rect.top, FXDIB_BLEND_NORMAL);
}
return m_pDeviceDriver->SetDIBits(pBitmap, 0, &src_rect, dest_rect.left,
@@ -766,7 +758,7 @@ bool CFX_RenderDevice::SetDIBitsWithBlend(
}
bool CFX_RenderDevice::StretchDIBitsWithFlagsAndBlend(
- const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ const CFX_DIBSource* pBitmap,
int left,
int top,
int dest_width,
@@ -783,7 +775,7 @@ bool CFX_RenderDevice::StretchDIBitsWithFlagsAndBlend(
blend_mode);
}
-bool CFX_RenderDevice::SetBitMask(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+bool CFX_RenderDevice::SetBitMask(const CFX_DIBSource* pBitmap,
int left,
int top,
uint32_t argb) {
@@ -792,25 +784,23 @@ bool CFX_RenderDevice::SetBitMask(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
FXDIB_BLEND_NORMAL);
}
-bool CFX_RenderDevice::StretchBitMask(
- const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
- int left,
- int top,
- int dest_width,
- int dest_height,
- uint32_t color) {
+bool CFX_RenderDevice::StretchBitMask(const CFX_DIBSource* pBitmap,
+ int left,
+ int top,
+ int dest_width,
+ int dest_height,
+ uint32_t color) {
return StretchBitMaskWithFlags(pBitmap, left, top, dest_width, dest_height,
color, 0);
}
-bool CFX_RenderDevice::StretchBitMaskWithFlags(
- const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
- int left,
- int top,
- int dest_width,
- int dest_height,
- uint32_t argb,
- uint32_t flags) {
+bool CFX_RenderDevice::StretchBitMaskWithFlags(const CFX_DIBSource* pBitmap,
+ int left,
+ int top,
+ int dest_width,
+ int dest_height,
+ uint32_t argb,
+ uint32_t flags) {
FX_RECT dest_rect(left, top, left + dest_width, top + dest_height);
FX_RECT clip_box = m_ClipBox;
clip_box.Intersect(dest_rect);
@@ -819,14 +809,13 @@ bool CFX_RenderDevice::StretchBitMaskWithFlags(
FXDIB_BLEND_NORMAL);
}
-bool CFX_RenderDevice::StartDIBitsWithBlend(
- const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
- int bitmap_alpha,
- uint32_t argb,
- const CFX_Matrix* pMatrix,
- uint32_t flags,
- void*& handle,
- int blend_mode) {
+bool CFX_RenderDevice::StartDIBitsWithBlend(const CFX_DIBSource* pBitmap,
+ int bitmap_alpha,
+ uint32_t argb,
+ const CFX_Matrix* pMatrix,
+ uint32_t flags,
+ void*& handle,
+ int blend_mode) {
return m_pDeviceDriver->StartDIBits(pBitmap, bitmap_alpha, argb, pMatrix,
flags, handle, blend_mode);
}
@@ -844,13 +833,12 @@ void CFX_RenderDevice::DebugVerifyBitmapIsPreMultiplied() const {
SkASSERT(0);
}
-bool CFX_RenderDevice::SetBitsWithMask(
- const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
- const CFX_RetainPtr<CFX_DIBSource>& pMask,
- int left,
- int top,
- int bitmap_alpha,
- int blend_type) {
+bool CFX_RenderDevice::SetBitsWithMask(const CFX_DIBSource* pBitmap,
+ const CFX_DIBSource* pMask,
+ int left,
+ int top,
+ int bitmap_alpha,
+ int blend_type) {
return m_pDeviceDriver->SetBitsWithMask(pBitmap, pMask, left, top,
bitmap_alpha, blend_type);
}
@@ -976,43 +964,42 @@ bool CFX_RenderDevice::DrawNormalText(int nChars,
bmp_rect.Intersect(m_ClipBox);
if (bmp_rect.IsEmpty())
return true;
-
int pixel_width = FXSYS_round(bmp_rect.Width() * scale_x);
int pixel_height = FXSYS_round(bmp_rect.Height() * scale_y);
int pixel_left = FXSYS_round(bmp_rect.left * scale_x);
int pixel_top = FXSYS_round(bmp_rect.top * scale_y);
if (anti_alias == FXFT_RENDER_MODE_MONO) {
- auto bitmap = pdfium::MakeRetain<CFX_DIBitmap>();
- if (!bitmap->Create(pixel_width, pixel_height, FXDIB_1bppMask))
+ CFX_DIBitmap bitmap;
+ if (!bitmap.Create(pixel_width, pixel_height, FXDIB_1bppMask))
return false;
- bitmap->Clear(0);
+ bitmap.Clear(0);
for (const FXTEXT_GLYPHPOS& glyph : glyphs) {
if (!glyph.m_pGlyph)
continue;
- CFX_RetainPtr<CFX_DIBitmap> pGlyph = glyph.m_pGlyph->m_pBitmap;
- bitmap->TransferBitmap(
+ const CFX_DIBitmap* pGlyph = &glyph.m_pGlyph->m_Bitmap;
+ bitmap.TransferBitmap(
glyph.m_Origin.x + glyph.m_pGlyph->m_Left - pixel_left,
glyph.m_Origin.y - glyph.m_pGlyph->m_Top - pixel_top,
pGlyph->GetWidth(), pGlyph->GetHeight(), pGlyph, 0, 0);
}
- return SetBitMask(bitmap, bmp_rect.left, bmp_rect.top, fill_color);
+ return SetBitMask(&bitmap, bmp_rect.left, bmp_rect.top, fill_color);
}
- auto bitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ CFX_DIBitmap bitmap;
if (m_bpp == 8) {
- if (!bitmap->Create(pixel_width, pixel_height, FXDIB_8bppMask))
+ if (!bitmap.Create(pixel_width, pixel_height, FXDIB_8bppMask))
return false;
} else {
- if (!CreateCompatibleBitmap(bitmap, pixel_width, pixel_height))
+ if (!CreateCompatibleBitmap(&bitmap, pixel_width, pixel_height))
return false;
}
- if (!bitmap->HasAlpha() && !bitmap->IsAlphaMask()) {
- bitmap->Clear(0xFFFFFFFF);
- if (!GetDIBits(bitmap, bmp_rect.left, bmp_rect.top))
+ if (!bitmap.HasAlpha() && !bitmap.IsAlphaMask()) {
+ bitmap.Clear(0xFFFFFFFF);
+ if (!GetDIBits(&bitmap, bmp_rect.left, bmp_rect.top))
return false;
} else {
- bitmap->Clear(0);
- if (bitmap->m_pAlphaMask)
- bitmap->m_pAlphaMask->Clear(0);
+ bitmap.Clear(0);
+ if (bitmap.m_pAlphaMask)
+ bitmap.m_pAlphaMask->Clear(0);
}
int dest_width = pixel_width;
int a = 0;
@@ -1038,14 +1025,14 @@ bool CFX_RenderDevice::DrawNormalText(int nChars,
if (!top.IsValid())
return false;
- CFX_RetainPtr<CFX_DIBitmap> pGlyph = glyph.m_pGlyph->m_pBitmap;
+ const CFX_DIBitmap* pGlyph = &glyph.m_pGlyph->m_Bitmap;
int ncols = pGlyph->GetWidth();
int nrows = pGlyph->GetHeight();
if (anti_alias == FXFT_RENDER_MODE_NORMAL) {
- if (!bitmap->CompositeMask(left.ValueOrDie(), top.ValueOrDie(), ncols,
- nrows, pGlyph, fill_color, 0, 0,
- FXDIB_BLEND_NORMAL, nullptr, false, 0,
- nullptr)) {
+ if (!bitmap.CompositeMask(left.ValueOrDie(), top.ValueOrDie(), ncols,
+ nrows, pGlyph, fill_color, 0, 0,
+ FXDIB_BLEND_NORMAL, nullptr, false, 0,
+ nullptr)) {
return false;
}
continue;
@@ -1065,14 +1052,14 @@ bool CFX_RenderDevice::DrawNormalText(int nChars,
if (start_col >= end_col)
continue;
- DrawNormalTextHelper(bitmap, pGlyph, nrows, left.ValueOrDie(),
+ DrawNormalTextHelper(&bitmap, pGlyph, nrows, left.ValueOrDie(),
top.ValueOrDie(), start_col, end_col, bNormal,
bBGRStripe, x_subpixel, a, r, g, b);
}
- if (bitmap->IsAlphaMask())
- SetBitMask(bitmap, bmp_rect.left, bmp_rect.top, fill_color);
+ if (bitmap.IsAlphaMask())
+ SetBitMask(&bitmap, bmp_rect.left, bmp_rect.top, fill_color);
else
- SetDIBits(bitmap, bmp_rect.left, bmp_rect.top);
+ SetDIBits(&bitmap, bmp_rect.left, bmp_rect.top);
return true;
}
diff --git a/core/fxge/ge/fx_ge_text.cpp b/core/fxge/ge/fx_ge_text.cpp
index b451b543fc..f3dea9178d 100644
--- a/core/fxge/ge/fx_ge_text.cpp
+++ b/core/fxge/ge/fx_ge_text.cpp
@@ -59,7 +59,7 @@ FX_RECT FXGE_GetGlyphsBBox(const std::vector<FXTEXT_GLYPHPOS>& glyphs,
if (!char_left.IsValid())
continue;
- FX_SAFE_INT32 char_width = pGlyph->m_pBitmap->GetWidth();
+ FX_SAFE_INT32 char_width = pGlyph->m_Bitmap.GetWidth();
char_width /= retinaScaleX;
if (anti_alias == FXFT_RENDER_MODE_LCD)
char_width /= 3;
@@ -75,7 +75,7 @@ FX_RECT FXGE_GetGlyphsBBox(const std::vector<FXTEXT_GLYPHPOS>& glyphs,
if (!char_top.IsValid())
continue;
- FX_SAFE_INT32 char_height = pGlyph->m_pBitmap->GetHeight();
+ FX_SAFE_INT32 char_height = pGlyph->m_Bitmap.GetHeight();
char_height /= retinaScaleY;
if (!char_height.IsValid())
continue;
diff --git a/core/fxge/ifx_renderdevicedriver.cpp b/core/fxge/ifx_renderdevicedriver.cpp
index 35cd4e221d..44ce833d99 100644
--- a/core/fxge/ifx_renderdevicedriver.cpp
+++ b/core/fxge/ifx_renderdevicedriver.cpp
@@ -48,15 +48,14 @@ bool IFX_RenderDeviceDriver::DrawCosmeticLine(float x1,
return false;
}
-bool IFX_RenderDeviceDriver::GetDIBits(
- const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
- int left,
- int top) {
+bool IFX_RenderDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap,
+ int left,
+ int top) {
return false;
}
-CFX_RetainPtr<CFX_DIBitmap> IFX_RenderDeviceDriver::GetBackDrop() {
- return CFX_RetainPtr<CFX_DIBitmap>();
+CFX_DIBitmap* IFX_RenderDeviceDriver::GetBackDrop() {
+ return nullptr;
}
bool IFX_RenderDeviceDriver::ContinueDIBits(void* handle, IFX_Pause* pPause) {
@@ -92,13 +91,12 @@ bool IFX_RenderDeviceDriver::DrawShading(const CPDF_ShadingPattern* pPattern,
return false;
}
-bool IFX_RenderDeviceDriver::SetBitsWithMask(
- const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
- const CFX_RetainPtr<CFX_DIBSource>& pMask,
- int left,
- int top,
- int bitmap_alpha,
- int blend_type) {
+bool IFX_RenderDeviceDriver::SetBitsWithMask(const CFX_DIBSource* pBitmap,
+ const CFX_DIBSource* pMask,
+ int left,
+ int top,
+ int bitmap_alpha,
+ int blend_type) {
return false;
}
diff --git a/core/fxge/ifx_renderdevicedriver.h b/core/fxge/ifx_renderdevicedriver.h
index 87e38fa5f0..3dd4730f9b 100644
--- a/core/fxge/ifx_renderdevicedriver.h
+++ b/core/fxge/ifx_renderdevicedriver.h
@@ -7,7 +7,6 @@
#ifndef CORE_FXGE_IFX_RENDERDEVICEDRIVER_H_
#define CORE_FXGE_IFX_RENDERDEVICEDRIVER_H_
-#include "core/fxcrt/cfx_retain_ptr.h"
#include "core/fxcrt/fx_system.h"
class CFX_DIBitmap;
@@ -58,17 +57,15 @@ class IFX_RenderDeviceDriver {
int blend_type);
virtual bool GetClipBox(FX_RECT* pRect) = 0;
- virtual bool GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
- int left,
- int top);
- virtual CFX_RetainPtr<CFX_DIBitmap> GetBackDrop();
- virtual bool SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ virtual bool GetDIBits(CFX_DIBitmap* pBitmap, int left, int top);
+ virtual CFX_DIBitmap* GetBackDrop();
+ virtual bool SetDIBits(const CFX_DIBSource* pBitmap,
uint32_t color,
const FX_RECT* pSrcRect,
int dest_left,
int dest_top,
int blend_type) = 0;
- virtual bool StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ virtual bool StretchDIBits(const CFX_DIBSource* pBitmap,
uint32_t color,
int dest_left,
int dest_top,
@@ -77,7 +74,7 @@ class IFX_RenderDeviceDriver {
const FX_RECT* pClipRect,
uint32_t flags,
int blend_type) = 0;
- virtual bool StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ virtual bool StartDIBits(const CFX_DIBSource* pBitmap,
int bitmap_alpha,
uint32_t color,
const CFX_Matrix* pMatrix,
@@ -100,8 +97,8 @@ class IFX_RenderDeviceDriver {
const FX_RECT& clip_rect,
int alpha,
bool bAlphaMode);
- virtual bool SetBitsWithMask(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
- const CFX_RetainPtr<CFX_DIBSource>& pMask,
+ virtual bool SetBitsWithMask(const CFX_DIBSource* pBitmap,
+ const CFX_DIBSource* pMask,
int left,
int top,
int bitmap_alpha,
diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp
index d3ea86b92e..a9cf7e67c7 100644
--- a/core/fxge/skia/fx_skia_device.cpp
+++ b/core/fxge/skia/fx_skia_device.cpp
@@ -48,12 +48,12 @@
namespace {
#ifdef _SKIA_SUPPORT_PATHS_
-void RgbByteOrderTransferBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+void RgbByteOrderTransferBitmap(CFX_DIBitmap* pBitmap,
int dest_left,
int dest_top,
int width,
int height,
- const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
+ const CFX_DIBSource* pSrcBitmap,
int src_left,
int src_top) {
if (!pBitmap)
@@ -247,8 +247,8 @@ void DebugDrawSkiaClipPath(SkCanvas* canvas, const SkPath& path) {}
#endif // DRAW_SKIA_CLIP
#ifdef _SKIA_SUPPORT_
-static void DebugValidate(const CFX_RetainPtr<CFX_DIBitmap>& bitmap,
- const CFX_RetainPtr<CFX_DIBitmap>& device) {
+static void DebugValidate(const CFX_DIBitmap* bitmap,
+ const CFX_DIBitmap* device) {
if (bitmap) {
SkASSERT(bitmap->GetBPP() == 8 || bitmap->GetBPP() == 32);
if (bitmap->GetBPP() == 32) {
@@ -547,7 +547,7 @@ void SetBitmapPaint(bool isAlphaMask,
paint->setAlpha(bitmap_alpha);
}
-bool Upsample(const CFX_RetainPtr<CFX_DIBSource>& pSource,
+bool Upsample(const CFX_DIBSource* pSource,
std::unique_ptr<uint8_t, FxFreeDeleter>& dst8Storage,
std::unique_ptr<uint32_t, FxFreeDeleter>& dst32Storage,
SkColorTable** ctPtr,
@@ -1197,11 +1197,10 @@ void CFX_SkiaDeviceDriver::PaintStroke(SkPaint* spaint,
spaint->setStrokeJoin(join);
}
-CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(
- const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
- bool bRgbByteOrder,
- const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice,
- bool bGroupKnockout)
+CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(CFX_DIBitmap* pBitmap,
+ bool bRgbByteOrder,
+ CFX_DIBitmap* pOriDevice,
+ bool bGroupKnockout)
: m_pBitmap(pBitmap),
m_pOriDevice(pOriDevice),
m_pRecorder(nullptr),
@@ -1395,7 +1394,8 @@ void CFX_SkiaDeviceDriver::SetClipMask(const FX_RECT& clipBox,
FX_RECT path_rect(clipBox.left, clipBox.top, clipBox.right + 1,
clipBox.bottom + 1);
path_rect.Intersect(m_pClipRgn->GetBox());
- auto pThisLayer = pdfium::MakeRetain<CFX_DIBitmap>();
+ CFX_DIBitmapRef mask;
+ CFX_DIBitmap* pThisLayer = mask.Emplace();
pThisLayer->Create(path_rect.Width(), path_rect.Height(), FXDIB_8bppMask);
pThisLayer->Clear(0);
@@ -1405,14 +1405,15 @@ void CFX_SkiaDeviceDriver::SetClipMask(const FX_RECT& clipBox,
SkBitmap bitmap;
bitmap.installPixels(imageInfo, pThisLayer->GetBuffer(),
pThisLayer->GetPitch(), nullptr, nullptr, nullptr);
- auto canvas = pdfium::MakeUnique<SkCanvas>(bitmap);
+ SkCanvas* canvas = new SkCanvas(bitmap);
canvas->translate(
-path_rect.left,
-path_rect.top); // FIXME(caryclark) wrong sign(s)? upside down?
SkPaint paint;
paint.setAntiAlias((m_FillFlags & FXFILL_NOPATHSMOOTH) == 0);
canvas->drawPath(path, paint);
- m_pClipRgn->IntersectMaskF(path_rect.left, path_rect.top, pThisLayer);
+ m_pClipRgn->IntersectMaskF(path_rect.left, path_rect.top, mask);
+ delete canvas;
}
#endif // _SKIA_SUPPORT_PATHS_
@@ -1797,9 +1798,7 @@ bool CFX_SkiaDeviceDriver::GetClipBox(FX_RECT* pRect) {
return true;
}
-bool CFX_SkiaDeviceDriver::GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
- int left,
- int top) {
+bool CFX_SkiaDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) {
if (!m_pBitmap)
return true;
uint8_t* srcBuffer = m_pBitmap->GetBuffer();
@@ -1836,7 +1835,7 @@ bool CFX_SkiaDeviceDriver::GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
m_pBitmap->UnPreMultiply();
FX_RECT rect(left, top, left + pBitmap->GetWidth(),
top + pBitmap->GetHeight());
- CFX_RetainPtr<CFX_DIBitmap> pBack;
+ std::unique_ptr<CFX_DIBitmap> pBack;
if (m_pOriDevice) {
pBack = m_pOriDevice->Clone(&rect);
if (!pBack)
@@ -1864,17 +1863,16 @@ bool CFX_SkiaDeviceDriver::GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
#endif // _SKIA_SUPPORT_PATHS_
}
-CFX_RetainPtr<CFX_DIBitmap> CFX_SkiaDeviceDriver::GetBackDrop() {
+CFX_DIBitmap* CFX_SkiaDeviceDriver::GetBackDrop() {
return m_pOriDevice;
}
-bool CFX_SkiaDeviceDriver::SetDIBits(
- const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
- uint32_t argb,
- const FX_RECT* pSrcRect,
- int left,
- int top,
- int blend_type) {
+bool CFX_SkiaDeviceDriver::SetDIBits(const CFX_DIBSource* pBitmap,
+ uint32_t argb,
+ const FX_RECT* pSrcRect,
+ int left,
+ int top,
+ int blend_type) {
if (!m_pBitmap || !m_pBitmap->GetBuffer())
return true;
@@ -1899,16 +1897,15 @@ bool CFX_SkiaDeviceDriver::SetDIBits(
#endif // _SKIA_SUPPORT_PATHS_
}
-bool CFX_SkiaDeviceDriver::StretchDIBits(
- const CFX_RetainPtr<CFX_DIBSource>& pSource,
- uint32_t argb,
- int dest_left,
- int dest_top,
- int dest_width,
- int dest_height,
- const FX_RECT* pClipRect,
- uint32_t flags,
- int blend_type) {
+bool CFX_SkiaDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource,
+ uint32_t argb,
+ int dest_left,
+ int dest_top,
+ int dest_width,
+ int dest_height,
+ const FX_RECT* pClipRect,
+ uint32_t flags,
+ int blend_type) {
#ifdef _SKIA_SUPPORT_
m_pCache->FlushForDraw();
if (!m_pBitmap->GetBuffer())
@@ -1951,14 +1948,13 @@ bool CFX_SkiaDeviceDriver::StretchDIBits(
#endif // _SKIA_SUPPORT_PATHS_
}
-bool CFX_SkiaDeviceDriver::StartDIBits(
- const CFX_RetainPtr<CFX_DIBSource>& pSource,
- int bitmap_alpha,
- uint32_t argb,
- const CFX_Matrix* pMatrix,
- uint32_t render_flags,
- void*& handle,
- int blend_type) {
+bool CFX_SkiaDeviceDriver::StartDIBits(const CFX_DIBSource* pSource,
+ int bitmap_alpha,
+ uint32_t argb,
+ const CFX_Matrix* pMatrix,
+ uint32_t render_flags,
+ void*& handle,
+ int blend_type) {
#ifdef _SKIA_SUPPORT_
m_pCache->FlushForDraw();
DebugValidate(m_pBitmap, m_pOriDevice);
@@ -2039,8 +2035,7 @@ bool CFX_SkiaDeviceDriver::ContinueDIBits(void* handle, IFX_Pause* pPause) {
}
#if defined _SKIA_SUPPORT_
-void CFX_SkiaDeviceDriver::PreMultiply(
- const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap) {
+void CFX_SkiaDeviceDriver::PreMultiply(CFX_DIBitmap* pDIBitmap) {
pDIBitmap->PreMultiply();
}
#endif // _SKIA_SUPPORT_
@@ -2096,12 +2091,11 @@ void CFX_DIBitmap::UnPreMultiply() {
#endif // _SKIA_SUPPORT_PATHS_
#ifdef _SKIA_SUPPORT_
-bool CFX_SkiaDeviceDriver::DrawBitsWithMask(
- const CFX_RetainPtr<CFX_DIBSource>& pSource,
- const CFX_RetainPtr<CFX_DIBSource>& pMask,
- int bitmap_alpha,
- const CFX_Matrix* pMatrix,
- int blend_type) {
+bool CFX_SkiaDeviceDriver::DrawBitsWithMask(const CFX_DIBSource* pSource,
+ const CFX_DIBSource* pMask,
+ int bitmap_alpha,
+ const CFX_Matrix* pMatrix,
+ int blend_type) {
DebugValidate(m_pBitmap, m_pOriDevice);
SkColorTable* srcCt = nullptr;
SkColorTable* maskCt = nullptr;
@@ -2141,13 +2135,12 @@ bool CFX_SkiaDeviceDriver::DrawBitsWithMask(
return true;
}
-bool CFX_SkiaDeviceDriver::SetBitsWithMask(
- const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
- const CFX_RetainPtr<CFX_DIBSource>& pMask,
- int dest_left,
- int dest_top,
- int bitmap_alpha,
- int blend_type) {
+bool CFX_SkiaDeviceDriver::SetBitsWithMask(const CFX_DIBSource* pBitmap,
+ const CFX_DIBSource* pMask,
+ int dest_left,
+ int dest_top,
+ int bitmap_alpha,
+ int blend_type) {
if (!m_pBitmap || !m_pBitmap->GetBuffer())
return true;
CFX_Matrix m(pBitmap->GetWidth(), 0, 0, -pBitmap->GetHeight(), dest_left,
@@ -2174,7 +2167,9 @@ void CFX_SkiaDeviceDriver::DebugVerifyBitmapIsPreMultiplied() const {
}
#endif // _SKIA_SUPPORT_
-CFX_FxgeDevice::CFX_FxgeDevice() {}
+CFX_FxgeDevice::CFX_FxgeDevice() {
+ m_bOwnedBitmap = false;
+}
#ifdef _SKIA_SUPPORT_
void CFX_FxgeDevice::Clear(uint32_t color) {
@@ -2190,9 +2185,9 @@ SkPictureRecorder* CFX_FxgeDevice::CreateRecorder(int size_x, int size_y) {
}
#endif // _SKIA_SUPPORT_
-bool CFX_FxgeDevice::Attach(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+bool CFX_FxgeDevice::Attach(CFX_DIBitmap* pBitmap,
bool bRgbByteOrder,
- const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice,
+ CFX_DIBitmap* pOriDevice,
bool bGroupKnockout) {
if (!pBitmap)
return false;
@@ -2214,9 +2209,11 @@ bool CFX_FxgeDevice::AttachRecorder(SkPictureRecorder* recorder) {
bool CFX_FxgeDevice::Create(int width,
int height,
FXDIB_Format format,
- const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice) {
- auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ CFX_DIBitmap* pOriDevice) {
+ m_bOwnedBitmap = true;
+ CFX_DIBitmap* pBitmap = new CFX_DIBitmap;
if (!pBitmap->Create(width, height, format)) {
+ delete pBitmap;
return false;
}
SetBitmap(pBitmap);
@@ -2227,6 +2224,9 @@ bool CFX_FxgeDevice::Create(int width,
CFX_FxgeDevice::~CFX_FxgeDevice() {
Flush();
+ // call destructor of CFX_RenderDevice / CFX_SkiaDeviceDriver immediately
+ if (m_bOwnedBitmap && GetBitmap())
+ delete GetBitmap();
}
#ifdef _SKIA_SUPPORT_
@@ -2239,13 +2239,12 @@ void CFX_FxgeDevice::DebugVerifyBitmapIsPreMultiplied() const {
#endif // SK_DEBUG
}
-bool CFX_FxgeDevice::SetBitsWithMask(
- const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
- const CFX_RetainPtr<CFX_DIBSource>& pMask,
- int left,
- int top,
- int bitmap_alpha,
- int blend_type) {
+bool CFX_FxgeDevice::SetBitsWithMask(const CFX_DIBSource* pBitmap,
+ const CFX_DIBSource* pMask,
+ int left,
+ int top,
+ int bitmap_alpha,
+ int blend_type) {
CFX_SkiaDeviceDriver* skDriver =
static_cast<CFX_SkiaDeviceDriver*>(GetDeviceDriver());
if (skDriver)
@@ -2285,10 +2284,10 @@ class CFX_Renderer {
uint32_t m_Color;
bool m_bFullCover;
bool m_bRgbByteOrder;
- const CFX_RetainPtr<CFX_DIBitmap>& m_pOriDevice;
+ CFX_DIBitmap* m_pOriDevice;
FX_RECT m_ClipBox;
- const CFX_RetainPtr<CFX_DIBitmap>& m_pClipMask;
- const CFX_RetainPtr<CFX_DIBitmap>& m_pDevice;
+ const CFX_DIBitmap* m_pClipMask;
+ CFX_DIBitmap* m_pDevice;
const CFX_ClipRgn* m_pClipRgn;
void (CFX_Renderer::*composite_span)(uint8_t*,
int,
@@ -2927,7 +2926,7 @@ class CFX_Renderer {
}
uint8_t* dest_scan = m_pDevice->GetBuffer() + m_pDevice->GetPitch() * y;
uint8_t* dest_scan_extra_alpha = nullptr;
- CFX_RetainPtr<CFX_DIBitmap> pAlphaMask = m_pDevice->m_pAlphaMask;
+ CFX_DIBitmap* pAlphaMask = m_pDevice->m_pAlphaMask;
if (pAlphaMask) {
dest_scan_extra_alpha =
pAlphaMask->GetBuffer() + pAlphaMask->GetPitch() * y;
@@ -2976,8 +2975,8 @@ class CFX_Renderer {
}
}
- bool Init(const CFX_RetainPtr<CFX_DIBitmap>& pDevice,
- const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice,
+ bool Init(CFX_DIBitmap* pDevice,
+ CFX_DIBitmap* pOriDevice,
const CFX_ClipRgn* pClipRgn,
uint32_t color,
bool bFullCover,
diff --git a/core/fxge/skia/fx_skia_device.h b/core/fxge/skia/fx_skia_device.h
index 9b5e4b06fa..494e6e1c44 100644
--- a/core/fxge/skia/fx_skia_device.h
+++ b/core/fxge/skia/fx_skia_device.h
@@ -24,9 +24,9 @@ struct SkIRect;
class CFX_SkiaDeviceDriver : public IFX_RenderDeviceDriver {
public:
- CFX_SkiaDeviceDriver(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ CFX_SkiaDeviceDriver(CFX_DIBitmap* pBitmap,
bool bRgbByteOrder,
- const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice,
+ CFX_DIBitmap* pOriDevice,
bool bGroupKnockout);
#ifdef _SKIA_SUPPORT_
explicit CFX_SkiaDeviceDriver(SkPictureRecorder* recorder);
@@ -79,21 +79,19 @@ class CFX_SkiaDeviceDriver : public IFX_RenderDeviceDriver {
bool GetClipBox(FX_RECT* pRect) override;
/** Load device buffer into a DIB */
- bool GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
- int left,
- int top) override;
+ bool GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) override;
- CFX_RetainPtr<CFX_DIBitmap> GetBackDrop() override;
+ CFX_DIBitmap* GetBackDrop() override;
- bool SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ bool SetDIBits(const CFX_DIBSource* pBitmap,
uint32_t color,
const FX_RECT* pSrcRect,
int dest_left,
int dest_top,
int blend_type) override;
#ifdef _SKIA_SUPPORT_
- bool SetBitsWithMask(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
- const CFX_RetainPtr<CFX_DIBSource>& pMask,
+ bool SetBitsWithMask(const CFX_DIBSource* pBitmap,
+ const CFX_DIBSource* pMask,
int dest_left,
int dest_top,
int bitmap_alpha,
@@ -104,7 +102,7 @@ class CFX_SkiaDeviceDriver : public IFX_RenderDeviceDriver {
void SetClipMask(const FX_RECT& clipBox, const SkPath& skClipPath);
#endif
- bool StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ bool StretchDIBits(const CFX_DIBSource* pBitmap,
uint32_t color,
int dest_left,
int dest_top,
@@ -114,7 +112,7 @@ class CFX_SkiaDeviceDriver : public IFX_RenderDeviceDriver {
uint32_t flags,
int blend_type) override;
- bool StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ bool StartDIBits(const CFX_DIBSource* pBitmap,
int bitmap_alpha,
uint32_t color,
const CFX_Matrix* pMatrix,
@@ -126,8 +124,8 @@ class CFX_SkiaDeviceDriver : public IFX_RenderDeviceDriver {
void CancelDIBits(void* handle) override;
- bool DrawBitsWithMask(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
- const CFX_RetainPtr<CFX_DIBSource>& pMask,
+ bool DrawBitsWithMask(const CFX_DIBSource* pBitmap,
+ const CFX_DIBSource* pMask,
int bitmap_alpha,
const CFX_Matrix* pMatrix,
int blend_type);
@@ -154,7 +152,7 @@ class CFX_SkiaDeviceDriver : public IFX_RenderDeviceDriver {
void Flush() override;
SkPictureRecorder* GetRecorder() const { return m_pRecorder; }
void PreMultiply() { m_pBitmap->PreMultiply(); }
- static void PreMultiply(const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap);
+ static void PreMultiply(CFX_DIBitmap* pDIBitmap);
SkCanvas* SkiaCanvas() { return m_pCanvas; }
void DebugVerifyBitmapIsPreMultiplied() const;
void Dump() const;
@@ -162,8 +160,8 @@ class CFX_SkiaDeviceDriver : public IFX_RenderDeviceDriver {
private:
friend class SkiaState;
- CFX_RetainPtr<CFX_DIBitmap> m_pBitmap;
- CFX_RetainPtr<CFX_DIBitmap> m_pOriDevice;
+ CFX_DIBitmap* m_pBitmap;
+ CFX_DIBitmap* m_pOriDevice;
SkCanvas* m_pCanvas;
SkPictureRecorder* const m_pRecorder;
std::unique_ptr<SkiaState> m_pCache;
diff --git a/core/fxge/skia/fx_skia_device_unittest.cpp b/core/fxge/skia/fx_skia_device_unittest.cpp
index a47a50c836..d612840b4c 100644
--- a/core/fxge/skia/fx_skia_device_unittest.cpp
+++ b/core/fxge/skia/fx_skia_device_unittest.cpp
@@ -125,7 +125,7 @@ void Harness(void (*Test)(CFX_SkiaDeviceDriver*, const State&),
return;
FPDFBitmap_FillRect(bitmap, 0, 0, w, h, 0x00000000);
CFX_FxgeDevice geDevice;
- CFX_RetainPtr<CFX_DIBitmap> pBitmap(CFXBitmapFromFPDFBitmap(bitmap));
+ CFX_DIBitmap* pBitmap = CFXBitmapFromFPDFBitmap(bitmap);
geDevice.Attach(pBitmap, false, nullptr, false);
CFX_SkiaDeviceDriver* driver =
static_cast<CFX_SkiaDeviceDriver*>(geDevice.GetDeviceDriver());
diff --git a/core/fxge/win32/cfx_psrenderer.cpp b/core/fxge/win32/cfx_psrenderer.cpp
index 5350c383b4..391af83630 100644
--- a/core/fxge/win32/cfx_psrenderer.cpp
+++ b/core/fxge/win32/cfx_psrenderer.cpp
@@ -338,7 +338,7 @@ static void PSCompressData(int PSLevel,
}
}
-bool CFX_PSRenderer::SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource,
+bool CFX_PSRenderer::SetDIBits(const CFX_DIBSource* pSource,
uint32_t color,
int left,
int top) {
@@ -349,7 +349,7 @@ bool CFX_PSRenderer::SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource,
return DrawDIBits(pSource, color, &matrix, 0);
}
-bool CFX_PSRenderer::StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource,
+bool CFX_PSRenderer::StretchDIBits(const CFX_DIBSource* pSource,
uint32_t color,
int dest_left,
int dest_top,
@@ -362,7 +362,7 @@ bool CFX_PSRenderer::StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource,
return DrawDIBits(pSource, color, &matrix, flags);
}
-bool CFX_PSRenderer::DrawDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource,
+bool CFX_PSRenderer::DrawDIBits(const CFX_DIBSource* pSource,
uint32_t color,
const CFX_Matrix* pMatrix,
uint32_t flags) {
@@ -419,25 +419,25 @@ bool CFX_PSRenderer::DrawDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource,
output_buf.release();
} else {
CFX_DIBExtractor source_extractor(pSource);
- CFX_RetainPtr<CFX_DIBSource> pConverted = source_extractor.GetBitmap();
- if (!pConverted)
+ CFX_MaybeOwned<CFX_DIBSource> pConverted(source_extractor.GetBitmap());
+ if (!pConverted.Get())
return false;
switch (pSource->GetFormat()) {
case FXDIB_1bppRgb:
case FXDIB_Rgb32:
- pConverted = pConverted->CloneConvert(FXDIB_Rgb);
+ pConverted = pConverted->CloneConvert(FXDIB_Rgb).release();
break;
case FXDIB_8bppRgb:
if (pSource->GetPalette()) {
- pConverted = pConverted->CloneConvert(FXDIB_Rgb);
+ pConverted = pConverted->CloneConvert(FXDIB_Rgb).release();
}
break;
case FXDIB_1bppCmyk:
- pConverted = pConverted->CloneConvert(FXDIB_Cmyk);
+ pConverted = pConverted->CloneConvert(FXDIB_Cmyk).release();
break;
case FXDIB_8bppCmyk:
if (pSource->GetPalette()) {
- pConverted = pConverted->CloneConvert(FXDIB_Cmyk);
+ pConverted = pConverted->CloneConvert(FXDIB_Cmyk).release();
}
break;
default:
@@ -452,7 +452,8 @@ bool CFX_PSRenderer::DrawDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource,
FX_STRSIZE output_size = 0;
const char* filter = nullptr;
if ((m_PSLevel == 2 || flags & FXRENDER_IMAGE_LOSSY) &&
- CCodec_JpegModule::JpegEncode(pConverted, &output_buf, &output_size)) {
+ CCodec_JpegModule::JpegEncode(pConverted.Get(), &output_buf,
+ &output_size)) {
filter = "/DCTDecode filter ";
}
if (!filter) {
diff --git a/core/fxge/win32/cfx_psrenderer.h b/core/fxge/win32/cfx_psrenderer.h
index 5768d0770f..133d7b9d72 100644
--- a/core/fxge/win32/cfx_psrenderer.h
+++ b/core/fxge/win32/cfx_psrenderer.h
@@ -51,18 +51,18 @@ class CFX_PSRenderer {
uint32_t fill_color,
uint32_t stroke_color,
int fill_mode);
- bool SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ bool SetDIBits(const CFX_DIBSource* pBitmap,
uint32_t color,
int dest_left,
int dest_top);
- bool StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ bool StretchDIBits(const CFX_DIBSource* pBitmap,
uint32_t color,
int dest_left,
int dest_top,
int dest_width,
int dest_height,
uint32_t flags);
- bool DrawDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ bool DrawDIBits(const CFX_DIBSource* pBitmap,
uint32_t color,
const CFX_Matrix* pMatrix,
uint32_t flags);
diff --git a/core/fxge/win32/cfx_windowsdib.h b/core/fxge/win32/cfx_windowsdib.h
index e59e9d60a4..0bfab3fee1 100644
--- a/core/fxge/win32/cfx_windowsdib.h
+++ b/core/fxge/win32/cfx_windowsdib.h
@@ -10,9 +10,6 @@
#ifndef _WINDOWS_
#include <windows.h>
#endif
-
-#include "core/fxge/fx_dib.h"
-
#define WINDIB_OPEN_MEMORY 0x1
#define WINDIB_OPEN_PATHNAME 0x2
@@ -28,20 +25,15 @@ typedef struct WINDIB_Open_Args_ {
class CFX_WindowsDIB : public CFX_DIBitmap {
public:
- template <typename T, typename... Args>
- friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args);
-
+ CFX_WindowsDIB(HDC hDC, int width, int height);
~CFX_WindowsDIB() override;
- static CFX_ByteString GetBitmapInfo(
- const CFX_RetainPtr<CFX_DIBitmap>& pBitmap);
- static HBITMAP GetDDBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
- HDC hDC);
-
- static CFX_RetainPtr<CFX_DIBitmap> LoadFromBuf(BITMAPINFO* pbmi, void* pData);
- static CFX_RetainPtr<CFX_DIBitmap> LoadFromFile(const wchar_t* filename);
- static CFX_RetainPtr<CFX_DIBitmap> LoadFromFile(const char* filename);
- static CFX_RetainPtr<CFX_DIBitmap> LoadDIBitmap(WINDIB_Open_Args_ args);
+ static CFX_ByteString GetBitmapInfo(const CFX_DIBitmap* pBitmap);
+ static CFX_DIBitmap* LoadFromBuf(BITMAPINFO* pbmi, void* pData);
+ static HBITMAP GetDDBitmap(const CFX_DIBitmap* pBitmap, HDC hDC);
+ static CFX_DIBitmap* LoadFromFile(const wchar_t* filename);
+ static CFX_DIBitmap* LoadFromFile(const char* filename);
+ static CFX_DIBitmap* LoadDIBitmap(WINDIB_Open_Args_ args);
HDC GetDC() const { return m_hMemDC; }
HBITMAP GetWindowsBitmap() const { return m_hBitmap; }
@@ -50,8 +42,6 @@ class CFX_WindowsDIB : public CFX_DIBitmap {
void SetToDevice(HDC hDC, int left, int top);
protected:
- CFX_WindowsDIB(HDC hDC, int width, int height);
-
HDC m_hMemDC;
HBITMAP m_hBitmap;
HBITMAP m_hOldBitmap;
diff --git a/core/fxge/win32/dwrite_int.h b/core/fxge/win32/dwrite_int.h
index 8e8908a7a1..105c34998c 100644
--- a/core/fxge/win32/dwrite_int.h
+++ b/core/fxge/win32/dwrite_int.h
@@ -39,8 +39,7 @@ class CDWriteExt {
void* DwCreateFontFaceFromStream(uint8_t* pData,
uint32_t size,
int simulation_style);
- bool DwCreateRenderingTarget(const CFX_RetainPtr<CFX_DIBitmap>& pSrc,
- void** renderTarget);
+ bool DwCreateRenderingTarget(CFX_DIBitmap* pSrc, void** renderTarget);
void DwDeleteRenderingTarget(void* renderTarget);
bool DwRendingString(void* renderTarget,
CFX_ClipRgn* pClipRgn,
diff --git a/core/fxge/win32/fx_win32_device.cpp b/core/fxge/win32/fx_win32_device.cpp
index 140a5b07d5..b2ee4549ea 100644
--- a/core/fxge/win32/fx_win32_device.cpp
+++ b/core/fxge/win32/fx_win32_device.cpp
@@ -782,13 +782,12 @@ void CGdiDeviceDriver::RestoreState(bool bKeepSaved) {
SaveDC(m_hDC);
}
-bool CGdiDeviceDriver::GDI_SetDIBits(
- const CFX_RetainPtr<CFX_DIBitmap>& pBitmap1,
- const FX_RECT* pSrcRect,
- int left,
- int top) {
+bool CGdiDeviceDriver::GDI_SetDIBits(CFX_DIBitmap* pBitmap1,
+ const FX_RECT* pSrcRect,
+ int left,
+ int top) {
if (m_DeviceClass == FXDC_PRINTER) {
- CFX_RetainPtr<CFX_DIBitmap> pBitmap = pBitmap1->FlipImage(false, true);
+ std::unique_ptr<CFX_DIBitmap> pBitmap = pBitmap1->FlipImage(false, true);
if (!pBitmap)
return false;
@@ -797,7 +796,7 @@ bool CGdiDeviceDriver::GDI_SetDIBits(
int width = pSrcRect->Width(), height = pSrcRect->Height();
LPBYTE pBuffer = pBitmap->GetBuffer();
- CFX_ByteString info = CFX_WindowsDIB::GetBitmapInfo(pBitmap);
+ CFX_ByteString info = CFX_WindowsDIB::GetBitmapInfo(pBitmap.get());
((BITMAPINFOHEADER*)info.c_str())->biHeight *= -1;
FX_RECT dst_rect(0, 0, width, height);
dst_rect.Intersect(0, 0, pBitmap->GetWidth(), pBitmap->GetHeight());
@@ -807,15 +806,15 @@ bool CGdiDeviceDriver::GDI_SetDIBits(
dst_height, pBuffer, (BITMAPINFO*)info.c_str(),
DIB_RGB_COLORS, SRCCOPY);
} else {
- CFX_RetainPtr<CFX_DIBitmap> pBitmap = pBitmap1;
+ CFX_MaybeOwned<CFX_DIBitmap> pBitmap(pBitmap1);
if (pBitmap->IsCmykImage()) {
- pBitmap = pBitmap->CloneConvert(FXDIB_Rgb);
+ pBitmap = pBitmap->CloneConvert(FXDIB_Rgb).release();
if (!pBitmap)
return false;
}
int width = pSrcRect->Width(), height = pSrcRect->Height();
LPBYTE pBuffer = pBitmap->GetBuffer();
- CFX_ByteString info = CFX_WindowsDIB::GetBitmapInfo(pBitmap);
+ CFX_ByteString info = CFX_WindowsDIB::GetBitmapInfo(pBitmap.Get());
::SetDIBitsToDevice(m_hDC, left, top, width, height, pSrcRect->left,
pBitmap->GetHeight() - pSrcRect->bottom, 0,
pBitmap->GetHeight(), pBuffer,
@@ -824,14 +823,13 @@ bool CGdiDeviceDriver::GDI_SetDIBits(
return true;
}
-bool CGdiDeviceDriver::GDI_StretchDIBits(
- const CFX_RetainPtr<CFX_DIBitmap>& pBitmap1,
- int dest_left,
- int dest_top,
- int dest_width,
- int dest_height,
- uint32_t flags) {
- CFX_RetainPtr<CFX_DIBitmap> pBitmap = pBitmap1;
+bool CGdiDeviceDriver::GDI_StretchDIBits(CFX_DIBitmap* pBitmap1,
+ int dest_left,
+ int dest_top,
+ int dest_width,
+ int dest_height,
+ uint32_t flags) {
+ CFX_DIBitmap* pBitmap = pBitmap1;
if (!pBitmap || dest_width == 0 || dest_height == 0)
return false;
@@ -846,14 +844,14 @@ bool CGdiDeviceDriver::GDI_StretchDIBits(
} else {
SetStretchBltMode(m_hDC, COLORONCOLOR);
}
- CFX_RetainPtr<CFX_DIBitmap> pToStrechBitmap = pBitmap;
+ CFX_MaybeOwned<CFX_DIBitmap> pToStrechBitmap(pBitmap);
if (m_DeviceClass == FXDC_PRINTER &&
((int64_t)pBitmap->GetWidth() * pBitmap->GetHeight() >
(int64_t)abs(dest_width) * abs(dest_height))) {
pToStrechBitmap = pBitmap->StretchTo(dest_width, dest_height);
}
CFX_ByteString toStrechBitmapInfo =
- CFX_WindowsDIB::GetBitmapInfo(pToStrechBitmap);
+ CFX_WindowsDIB::GetBitmapInfo(pToStrechBitmap.Get());
::StretchDIBits(m_hDC, dest_left, dest_top, dest_width, dest_height, 0, 0,
pToStrechBitmap->GetWidth(), pToStrechBitmap->GetHeight(),
pToStrechBitmap->GetBuffer(),
@@ -862,15 +860,14 @@ bool CGdiDeviceDriver::GDI_StretchDIBits(
return true;
}
-bool CGdiDeviceDriver::GDI_StretchBitMask(
- const CFX_RetainPtr<CFX_DIBitmap>& pBitmap1,
- int dest_left,
- int dest_top,
- int dest_width,
- int dest_height,
- uint32_t bitmap_color,
- uint32_t flags) {
- CFX_RetainPtr<CFX_DIBitmap> pBitmap = pBitmap1;
+bool CGdiDeviceDriver::GDI_StretchBitMask(CFX_DIBitmap* pBitmap1,
+ int dest_left,
+ int dest_top,
+ int dest_width,
+ int dest_height,
+ uint32_t bitmap_color,
+ uint32_t flags) {
+ CFX_DIBitmap* pBitmap = pBitmap1;
if (!pBitmap || dest_width == 0 || dest_height == 0)
return false;
@@ -1168,9 +1165,7 @@ CGdiDisplayDriver::CGdiDisplayDriver(HDC hDC)
CGdiDisplayDriver::~CGdiDisplayDriver() {}
-bool CGdiDisplayDriver::GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
- int left,
- int top) {
+bool CGdiDisplayDriver::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) {
bool ret = false;
int width = pBitmap->GetWidth();
int height = pBitmap->GetHeight();
@@ -1190,12 +1185,12 @@ bool CGdiDisplayDriver::GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
ret = ::GetDIBits(hDCMemory, hbmp, 0, height, pBitmap->GetBuffer(), &bmi,
DIB_RGB_COLORS) == height;
} else {
- auto bitmap = pdfium::MakeRetain<CFX_DIBitmap>();
- if (bitmap->Create(width, height, FXDIB_Rgb)) {
+ CFX_DIBitmap bitmap;
+ if (bitmap.Create(width, height, FXDIB_Rgb)) {
bmi.bmiHeader.biBitCount = 24;
- ::GetDIBits(hDCMemory, hbmp, 0, height, bitmap->GetBuffer(), &bmi,
+ ::GetDIBits(hDCMemory, hbmp, 0, height, bitmap.GetBuffer(), &bmi,
DIB_RGB_COLORS);
- ret = pBitmap->TransferBitmap(0, 0, width, height, bitmap, 0, 0);
+ ret = pBitmap->TransferBitmap(0, 0, width, height, &bitmap, 0, 0);
} else {
ret = false;
}
@@ -1208,7 +1203,7 @@ bool CGdiDisplayDriver::GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
return ret;
}
-bool CGdiDisplayDriver::SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource,
+bool CGdiDisplayDriver::SetDIBits(const CFX_DIBSource* pSource,
uint32_t color,
const FX_RECT* pSrcRect,
int left,
@@ -1219,16 +1214,17 @@ bool CGdiDisplayDriver::SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource,
int width = pSource->GetWidth(), height = pSource->GetHeight();
int alpha = FXARGB_A(color);
if (pSource->GetBPP() != 1 || alpha != 255) {
- auto background = pdfium::MakeRetain<CFX_DIBitmap>();
- if (!background->Create(width, height, FXDIB_Rgb32) ||
- !GetDIBits(background, left, top) ||
- !background->CompositeMask(0, 0, width, height, pSource, color, 0, 0,
- FXDIB_BLEND_NORMAL, nullptr, false, 0,
- nullptr)) {
+ CFX_DIBitmap background;
+ if (!background.Create(width, height, FXDIB_Rgb32) ||
+ !GetDIBits(&background, left, top) ||
+ !background.CompositeMask(0, 0, width, height, pSource, color, 0, 0,
+ FXDIB_BLEND_NORMAL, nullptr, false, 0,
+ nullptr)) {
return false;
}
FX_RECT src_rect(0, 0, width, height);
- return SetDIBits(background, 0, &src_rect, left, top, FXDIB_BLEND_NORMAL);
+ return SetDIBits(&background, 0, &src_rect, left, top,
+ FXDIB_BLEND_NORMAL);
}
FX_RECT clip_rect(left, top, left + pSrcRect->Width(),
top + pSrcRect->Height());
@@ -1238,33 +1234,32 @@ bool CGdiDisplayDriver::SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource,
}
int width = pSrcRect->Width(), height = pSrcRect->Height();
if (pSource->HasAlpha()) {
- auto bitmap = pdfium::MakeRetain<CFX_DIBitmap>();
- if (!bitmap->Create(width, height, FXDIB_Rgb) ||
- !GetDIBits(bitmap, left, top) ||
- !bitmap->CompositeBitmap(0, 0, width, height, pSource, pSrcRect->left,
- pSrcRect->top, FXDIB_BLEND_NORMAL, nullptr,
- false, nullptr)) {
+ CFX_DIBitmap bitmap;
+ if (!bitmap.Create(width, height, FXDIB_Rgb) ||
+ !GetDIBits(&bitmap, left, top) ||
+ !bitmap.CompositeBitmap(0, 0, width, height, pSource, pSrcRect->left,
+ pSrcRect->top, FXDIB_BLEND_NORMAL, nullptr,
+ false, nullptr)) {
return false;
}
FX_RECT src_rect(0, 0, width, height);
- return SetDIBits(bitmap, 0, &src_rect, left, top, FXDIB_BLEND_NORMAL);
+ return SetDIBits(&bitmap, 0, &src_rect, left, top, FXDIB_BLEND_NORMAL);
}
CFX_DIBExtractor temp(pSource);
- CFX_RetainPtr<CFX_DIBitmap> pBitmap = temp.GetBitmap();
+ CFX_DIBitmap* pBitmap = temp.GetBitmap();
if (!pBitmap)
return false;
return GDI_SetDIBits(pBitmap, pSrcRect, left, top);
}
-bool CGdiDisplayDriver::UseFoxitStretchEngine(
- const CFX_RetainPtr<CFX_DIBSource>& pSource,
- uint32_t color,
- int dest_left,
- int dest_top,
- int dest_width,
- int dest_height,
- const FX_RECT* pClipRect,
- int render_flags) {
+bool CGdiDisplayDriver::UseFoxitStretchEngine(const CFX_DIBSource* pSource,
+ uint32_t color,
+ int dest_left,
+ int dest_top,
+ int dest_width,
+ int dest_height,
+ const FX_RECT* pClipRect,
+ int render_flags) {
FX_RECT bitmap_clip = *pClipRect;
if (dest_width < 0)
dest_left += dest_width;
@@ -1273,26 +1268,25 @@ bool CGdiDisplayDriver::UseFoxitStretchEngine(
dest_top += dest_height;
bitmap_clip.Offset(-dest_left, -dest_top);
- CFX_RetainPtr<CFX_DIBitmap> pStretched =
- pSource->StretchTo(dest_width, dest_height, render_flags, &bitmap_clip);
+ std::unique_ptr<CFX_DIBitmap> pStretched(
+ pSource->StretchTo(dest_width, dest_height, render_flags, &bitmap_clip));
if (!pStretched)
return true;
FX_RECT src_rect(0, 0, pStretched->GetWidth(), pStretched->GetHeight());
- return SetDIBits(pStretched, color, &src_rect, pClipRect->left,
+ return SetDIBits(pStretched.get(), color, &src_rect, pClipRect->left,
pClipRect->top, FXDIB_BLEND_NORMAL);
}
-bool CGdiDisplayDriver::StretchDIBits(
- const CFX_RetainPtr<CFX_DIBSource>& pSource,
- uint32_t color,
- int dest_left,
- int dest_top,
- int dest_width,
- int dest_height,
- const FX_RECT* pClipRect,
- uint32_t flags,
- int blend_type) {
+bool CGdiDisplayDriver::StretchDIBits(const CFX_DIBSource* pSource,
+ uint32_t color,
+ int dest_left,
+ int dest_top,
+ int dest_width,
+ int dest_height,
+ const FX_RECT* pClipRect,
+ uint32_t flags,
+ int blend_type) {
ASSERT(pSource && pClipRect);
if (flags || dest_width > 10000 || dest_width < -10000 ||
dest_height > 10000 || dest_height < -10000) {
@@ -1309,23 +1303,24 @@ bool CGdiDisplayDriver::StretchDIBits(
clip_rect.Intersect(*pClipRect);
clip_rect.Offset(-image_rect.left, -image_rect.top);
int clip_width = clip_rect.Width(), clip_height = clip_rect.Height();
- CFX_RetainPtr<CFX_DIBitmap> pStretched(
+ std::unique_ptr<CFX_DIBitmap> pStretched(
pSource->StretchTo(dest_width, dest_height, flags, &clip_rect));
if (!pStretched)
return true;
- auto background = pdfium::MakeRetain<CFX_DIBitmap>();
- if (!background->Create(clip_width, clip_height, FXDIB_Rgb32) ||
- !GetDIBits(background, image_rect.left + clip_rect.left,
+ CFX_DIBitmap background;
+ if (!background.Create(clip_width, clip_height, FXDIB_Rgb32) ||
+ !GetDIBits(&background, image_rect.left + clip_rect.left,
image_rect.top + clip_rect.top) ||
- !background->CompositeMask(0, 0, clip_width, clip_height, pStretched,
- color, 0, 0, FXDIB_BLEND_NORMAL, nullptr,
- false, 0, nullptr)) {
+ !background.CompositeMask(
+ 0, 0, clip_width, clip_height, pStretched.get(), color, 0, 0,
+ FXDIB_BLEND_NORMAL, nullptr, false, 0, nullptr)) {
return false;
}
FX_RECT src_rect(0, 0, clip_width, clip_height);
- return SetDIBits(background, 0, &src_rect, image_rect.left + clip_rect.left,
+ return SetDIBits(&background, 0, &src_rect,
+ image_rect.left + clip_rect.left,
image_rect.top + clip_rect.top, FXDIB_BLEND_NORMAL);
}
if (pSource->HasAlpha()) {
@@ -1333,7 +1328,7 @@ bool CGdiDisplayDriver::StretchDIBits(
(CWin32Platform*)CFX_GEModule::Get()->GetPlatformData();
if (pPlatform->m_GdiplusExt.IsAvailable() && !pSource->IsCmykImage()) {
CFX_DIBExtractor temp(pSource);
- CFX_RetainPtr<CFX_DIBitmap> pBitmap = temp.GetBitmap();
+ CFX_DIBitmap* pBitmap = temp.GetBitmap();
if (!pBitmap)
return false;
return pPlatform->m_GdiplusExt.StretchDIBits(
@@ -1344,14 +1339,14 @@ bool CGdiDisplayDriver::StretchDIBits(
dest_width, dest_height, pClipRect, flags);
}
CFX_DIBExtractor temp(pSource);
- CFX_RetainPtr<CFX_DIBitmap> pBitmap = temp.GetBitmap();
+ CFX_DIBitmap* pBitmap = temp.GetBitmap();
if (!pBitmap)
return false;
return GDI_StretchDIBits(pBitmap, dest_left, dest_top, dest_width,
dest_height, flags);
}
-bool CGdiDisplayDriver::StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+bool CGdiDisplayDriver::StartDIBits(const CFX_DIBSource* pBitmap,
int bitmap_alpha,
uint32_t color,
const CFX_Matrix* pMatrix,
diff --git a/core/fxge/win32/fx_win32_dib.cpp b/core/fxge/win32/fx_win32_dib.cpp
index 9815457bbd..9b85b57317 100644
--- a/core/fxge/win32/fx_win32_dib.cpp
+++ b/core/fxge/win32/fx_win32_dib.cpp
@@ -11,8 +11,7 @@
#include "core/fxge/win32/cfx_windowsdib.h"
#include "core/fxge/win32/win32_int.h"
-CFX_ByteString CFX_WindowsDIB::GetBitmapInfo(
- const CFX_RetainPtr<CFX_DIBitmap>& pBitmap) {
+CFX_ByteString CFX_WindowsDIB::GetBitmapInfo(const CFX_DIBitmap* pBitmap) {
CFX_ByteString result;
int len = sizeof(BITMAPINFOHEADER);
if (pBitmap->GetBPP() == 1 || pBitmap->GetBPP() == 8) {
@@ -52,9 +51,9 @@ CFX_ByteString CFX_WindowsDIB::GetBitmapInfo(
return result;
}
-CFX_RetainPtr<CFX_DIBitmap> _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi,
- LPVOID pData,
- bool bAlpha) {
+CFX_DIBitmap* _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi,
+ LPVOID pData,
+ bool bAlpha) {
int width = pbmi->bmiHeader.biWidth;
int height = pbmi->bmiHeader.biHeight;
BOOL bBottomUp = true;
@@ -63,13 +62,15 @@ CFX_RetainPtr<CFX_DIBitmap> _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi,
bBottomUp = false;
}
int pitch = (width * pbmi->bmiHeader.biBitCount + 31) / 32 * 4;
- auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ CFX_DIBitmap* pBitmap = new CFX_DIBitmap;
FXDIB_Format format = bAlpha
? (FXDIB_Format)(pbmi->bmiHeader.biBitCount + 0x200)
: (FXDIB_Format)pbmi->bmiHeader.biBitCount;
- if (!pBitmap->Create(width, height, format))
+ bool ret = pBitmap->Create(width, height, format);
+ if (!ret) {
+ delete pBitmap;
return nullptr;
-
+ }
FXSYS_memcpy(pBitmap->GetBuffer(), pData, pitch * height);
if (bBottomUp) {
uint8_t* temp_buf = FX_Alloc(uint8_t, pitch);
@@ -97,13 +98,11 @@ CFX_RetainPtr<CFX_DIBitmap> _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi,
return pBitmap;
}
-CFX_RetainPtr<CFX_DIBitmap> CFX_WindowsDIB::LoadFromBuf(BITMAPINFO* pbmi,
- LPVOID pData) {
+CFX_DIBitmap* CFX_WindowsDIB::LoadFromBuf(BITMAPINFO* pbmi, LPVOID pData) {
return _FX_WindowsDIB_LoadFromBuf(pbmi, pData, false);
}
-HBITMAP CFX_WindowsDIB::GetDDBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
- HDC hDC) {
+HBITMAP CFX_WindowsDIB::GetDDBitmap(const CFX_DIBitmap* pBitmap, HDC hDC) {
CFX_ByteString info = GetBitmapInfo(pBitmap);
return CreateDIBitmap(hDC, (BITMAPINFOHEADER*)info.c_str(), CBM_INIT,
pBitmap->GetBuffer(), (BITMAPINFO*)info.c_str(),
@@ -117,8 +116,7 @@ void GetBitmapSize(HBITMAP hBitmap, int& w, int& h) {
h = bmp.bmHeight;
}
-CFX_RetainPtr<CFX_DIBitmap> CFX_WindowsDIB::LoadFromFile(
- const wchar_t* filename) {
+CFX_DIBitmap* CFX_WindowsDIB::LoadFromFile(const wchar_t* filename) {
CWin32Platform* pPlatform =
(CWin32Platform*)CFX_GEModule::Get()->GetPlatformData();
if (pPlatform->m_GdiplusExt.IsAvailable()) {
@@ -133,29 +131,30 @@ CFX_RetainPtr<CFX_DIBitmap> CFX_WindowsDIB::LoadFromFile(
return nullptr;
}
HDC hDC = CreateCompatibleDC(nullptr);
- int width;
- int height;
+ int width, height;
GetBitmapSize(hBitmap, width, height);
- auto pDIBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ CFX_DIBitmap* pDIBitmap = new CFX_DIBitmap;
if (!pDIBitmap->Create(width, height, FXDIB_Rgb)) {
+ delete pDIBitmap;
DeleteDC(hDC);
return nullptr;
}
CFX_ByteString info = GetBitmapInfo(pDIBitmap);
int ret = GetDIBits(hDC, hBitmap, 0, height, pDIBitmap->GetBuffer(),
(BITMAPINFO*)info.c_str(), DIB_RGB_COLORS);
+ if (!ret) {
+ delete pDIBitmap;
+ pDIBitmap = nullptr;
+ }
DeleteDC(hDC);
- if (!ret)
- return nullptr;
return pDIBitmap;
}
-CFX_RetainPtr<CFX_DIBitmap> CFX_WindowsDIB::LoadFromFile(const char* filename) {
+CFX_DIBitmap* CFX_WindowsDIB::LoadFromFile(const char* filename) {
return LoadFromFile(CFX_WideString::FromLocal(filename).c_str());
}
-CFX_RetainPtr<CFX_DIBitmap> CFX_WindowsDIB::LoadDIBitmap(
- WINDIB_Open_Args_ args) {
+CFX_DIBitmap* CFX_WindowsDIB::LoadDIBitmap(WINDIB_Open_Args_ args) {
CWin32Platform* pPlatform =
(CWin32Platform*)CFX_GEModule::Get()->GetPlatformData();
if (pPlatform->m_GdiplusExt.IsAvailable()) {
@@ -172,17 +171,20 @@ CFX_RetainPtr<CFX_DIBitmap> CFX_WindowsDIB::LoadDIBitmap(
HDC hDC = CreateCompatibleDC(nullptr);
int width, height;
GetBitmapSize(hBitmap, width, height);
- auto pDIBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ CFX_DIBitmap* pDIBitmap = new CFX_DIBitmap;
if (!pDIBitmap->Create(width, height, FXDIB_Rgb)) {
+ delete pDIBitmap;
DeleteDC(hDC);
return nullptr;
}
CFX_ByteString info = GetBitmapInfo(pDIBitmap);
int ret = GetDIBits(hDC, hBitmap, 0, height, pDIBitmap->GetBuffer(),
(BITMAPINFO*)info.c_str(), DIB_RGB_COLORS);
+ if (!ret) {
+ delete pDIBitmap;
+ pDIBitmap = nullptr;
+ }
DeleteDC(hDC);
- if (!ret)
- return nullptr;
return pDIBitmap;
}
diff --git a/core/fxge/win32/fx_win32_dwrite.cpp b/core/fxge/win32/fx_win32_dwrite.cpp
index 91fb465af4..e088e832bc 100644
--- a/core/fxge/win32/fx_win32_dwrite.cpp
+++ b/core/fxge/win32/fx_win32_dwrite.cpp
@@ -103,7 +103,7 @@ class CDwFontContext {
class CDwGdiTextRenderer {
public:
- CDwGdiTextRenderer(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ CDwGdiTextRenderer(CFX_DIBitmap* pBitmap,
IDWriteBitmapRenderTarget* bitmapRenderTarget,
IDWriteRenderingParams* renderingParams);
~CDwGdiTextRenderer();
@@ -118,7 +118,7 @@ class CDwGdiTextRenderer {
const COLORREF& textColor);
private:
- CFX_RetainPtr<CFX_DIBitmap> pBitmap_;
+ CFX_DIBitmap* pBitmap_;
IDWriteBitmapRenderTarget* pRenderTarget_;
IDWriteRenderingParams* pRenderingParams_;
};
@@ -180,9 +180,8 @@ failed:
return nullptr;
}
-bool CDWriteExt::DwCreateRenderingTarget(
- const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
- void** renderTarget) {
+bool CDWriteExt::DwCreateRenderingTarget(CFX_DIBitmap* pBitmap,
+ void** renderTarget) {
if (pBitmap->GetFormat() > FXDIB_Argb) {
return false;
}
@@ -396,7 +395,7 @@ HRESULT CDwFontContext::Initialize() {
}
CDwGdiTextRenderer::CDwGdiTextRenderer(
- const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ CFX_DIBitmap* pBitmap,
IDWriteBitmapRenderTarget* bitmapRenderTarget,
IDWriteRenderingParams* renderingParams)
: pBitmap_(pBitmap),
@@ -427,13 +426,13 @@ STDMETHODIMP CDwGdiTextRenderer::DrawGlyphRun(
HBITMAP hBitmap = (HBITMAP)::GetCurrentObject(hDC, OBJ_BITMAP);
BITMAP bitmap;
GetObject(hBitmap, sizeof bitmap, &bitmap);
- auto dib = pdfium::MakeRetain<CFX_DIBitmap>();
- dib->Create(bitmap.bmWidth, bitmap.bmHeight,
- bitmap.bmBitsPixel == 24 ? FXDIB_Rgb : FXDIB_Rgb32,
- (uint8_t*)bitmap.bmBits);
- dib->CompositeBitmap(text_bbox.left, text_bbox.top, text_bbox.Width(),
- text_bbox.Height(), pBitmap_, text_bbox.left,
- text_bbox.top, FXDIB_BLEND_NORMAL, nullptr);
+ CFX_DIBitmap dib;
+ dib.Create(bitmap.bmWidth, bitmap.bmHeight,
+ bitmap.bmBitsPixel == 24 ? FXDIB_Rgb : FXDIB_Rgb32,
+ (uint8_t*)bitmap.bmBits);
+ dib.CompositeBitmap(text_bbox.left, text_bbox.top, text_bbox.Width(),
+ text_bbox.Height(), pBitmap_, text_bbox.left,
+ text_bbox.top, FXDIB_BLEND_NORMAL, nullptr);
hr = pRenderTarget_->DrawGlyphRun(baselineOriginX, baselineOriginY,
measuringMode, glyphRun, pRenderingParams_,
textColor);
@@ -441,7 +440,7 @@ STDMETHODIMP CDwGdiTextRenderer::DrawGlyphRun(
return hr;
}
pBitmap_->CompositeBitmap(text_bbox.left, text_bbox.top, text_bbox.Width(),
- text_bbox.Height(), dib, text_bbox.left,
+ text_bbox.Height(), &dib, text_bbox.left,
text_bbox.top, FXDIB_BLEND_NORMAL, pClipRgn);
return hr;
}
diff --git a/core/fxge/win32/fx_win32_gdipext.cpp b/core/fxge/win32/fx_win32_gdipext.cpp
index 41f9ba55ad..8a7f55e0cb 100644
--- a/core/fxge/win32/fx_win32_gdipext.cpp
+++ b/core/fxge/win32/fx_win32_gdipext.cpp
@@ -461,10 +461,10 @@ static GpBrush* _GdipCreateBrush(DWORD argb) {
return solidBrush;
}
-static CFX_RetainPtr<CFX_DIBitmap> StretchMonoToGray(
+static std::unique_ptr<CFX_DIBitmap> StretchMonoToGray(
int dest_width,
int dest_height,
- const CFX_RetainPtr<CFX_DIBitmap>& pSource,
+ const CFX_DIBitmap* pSource,
FX_RECT* pClipRect) {
bool bFlipX = dest_width < 0;
if (bFlipX)
@@ -477,7 +477,7 @@ static CFX_RetainPtr<CFX_DIBitmap> StretchMonoToGray(
int result_width = pClipRect->Width();
int result_height = pClipRect->Height();
int result_pitch = (result_width + 3) / 4 * 4;
- auto pStretched = pdfium::MakeRetain<CFX_DIBitmap>();
+ auto pStretched = pdfium::MakeUnique<CFX_DIBitmap>();
if (!pStretched->Create(result_width, result_height, FXDIB_8bppRgb))
return nullptr;
@@ -518,7 +518,7 @@ static CFX_RetainPtr<CFX_DIBitmap> StretchMonoToGray(
static void OutputImageMask(GpGraphics* pGraphics,
BOOL bMonoDevice,
- const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ const CFX_DIBitmap* pBitmap,
int dest_left,
int dest_top,
int dest_width,
@@ -562,7 +562,7 @@ static void OutputImageMask(GpGraphics* pGraphics,
return;
}
image_clip.Offset(-image_rect.left, -image_rect.top);
- CFX_RetainPtr<CFX_DIBitmap> pStretched;
+ std::unique_ptr<CFX_DIBitmap> pStretched;
if (src_width * src_height > 10000) {
pStretched =
StretchMonoToGray(dest_width, dest_height, pBitmap, &image_clip);
@@ -602,7 +602,7 @@ static void OutputImageMask(GpGraphics* pGraphics,
CallFunc(GdipDisposeImage)(bitmap);
}
static void OutputImage(GpGraphics* pGraphics,
- const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ const CFX_DIBitmap* pBitmap,
const FX_RECT* pSrcRect,
int dest_left,
int dest_top,
@@ -613,11 +613,11 @@ static void OutputImage(GpGraphics* pGraphics,
((CWin32Platform*)CFX_GEModule::Get()->GetPlatformData())->m_GdiplusExt;
if (pBitmap->GetBPP() == 1 && (pSrcRect->left % 8)) {
FX_RECT new_rect(0, 0, src_width, src_height);
- CFX_RetainPtr<CFX_DIBitmap> pCloned = pBitmap->Clone(pSrcRect);
+ std::unique_ptr<CFX_DIBitmap> pCloned = pBitmap->Clone(pSrcRect);
if (!pCloned)
return;
- OutputImage(pGraphics, pCloned, &new_rect, dest_left, dest_top, dest_width,
- dest_height);
+ OutputImage(pGraphics, pCloned.get(), &new_rect, dest_left, dest_top,
+ dest_width, dest_height);
return;
}
int src_pitch = pBitmap->GetPitch();
@@ -730,8 +730,7 @@ void CGdiplusExt::DeleteMemFont(LPVOID pCollection) {
((CWin32Platform*)CFX_GEModule::Get()->GetPlatformData())->m_GdiplusExt;
CallFunc(GdipDeletePrivateFontCollection)((GpFontCollection**)&pCollection);
}
-bool CGdiplusExt::GdipCreateBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
- void** bitmap) {
+bool CGdiplusExt::GdipCreateBitmap(CFX_DIBitmap* pBitmap, void** bitmap) {
CGdiplusExt& GdiplusExt =
((CWin32Platform*)CFX_GEModule::Get()->GetPlatformData())->m_GdiplusExt;
PixelFormat format;
@@ -913,7 +912,7 @@ void CGdiplusExt::GdipDeleteGraphics(void* graphics) {
}
bool CGdiplusExt::StretchBitMask(HDC hDC,
BOOL bMonoDevice,
- const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ const CFX_DIBitmap* pBitmap,
int dest_left,
int dest_top,
int dest_width,
@@ -939,7 +938,7 @@ bool CGdiplusExt::StretchBitMask(HDC hDC,
return true;
}
bool CGdiplusExt::StretchDIBits(HDC hDC,
- const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ const CFX_DIBitmap* pBitmap,
int dest_left,
int dest_top,
int dest_width,
@@ -1493,16 +1492,14 @@ static void FreeDIBitmap(PREVIEW3_DIBITMAP* pInfo) {
FX_Free(pInfo);
}
-// TODO(tsepez): Really? Really? Move to header.
-CFX_RetainPtr<CFX_DIBitmap> _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi,
- LPVOID pData,
- bool bAlpha);
-
-CFX_RetainPtr<CFX_DIBitmap> CGdiplusExt::LoadDIBitmap(WINDIB_Open_Args_ args) {
+CFX_DIBitmap* _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi,
+ LPVOID pData,
+ bool bAlpha);
+CFX_DIBitmap* CGdiplusExt::LoadDIBitmap(WINDIB_Open_Args_ args) {
PREVIEW3_DIBITMAP* pInfo = ::LoadDIBitmap(args);
- if (!pInfo)
+ if (!pInfo) {
return nullptr;
-
+ }
int height = abs(pInfo->pbmi->bmiHeader.biHeight);
int width = pInfo->pbmi->bmiHeader.biWidth;
int dest_pitch = (width * pInfo->pbmi->bmiHeader.biBitCount + 31) / 32 * 4;
@@ -1515,7 +1512,7 @@ CFX_RetainPtr<CFX_DIBitmap> CGdiplusExt::LoadDIBitmap(WINDIB_Open_Args_ args) {
dest_pitch);
}
}
- CFX_RetainPtr<CFX_DIBitmap> pDIBitmap = _FX_WindowsDIB_LoadFromBuf(
+ CFX_DIBitmap* pDIBitmap = _FX_WindowsDIB_LoadFromBuf(
pInfo->pbmi, pData, pInfo->pbmi->bmiHeader.biBitCount == 32);
FX_Free(pData);
FreeDIBitmap(pInfo);
diff --git a/core/fxge/win32/fx_win32_print.cpp b/core/fxge/win32/fx_win32_print.cpp
index 6d96243655..061896f09b 100644
--- a/core/fxge/win32/fx_win32_print.cpp
+++ b/core/fxge/win32/fx_win32_print.cpp
@@ -67,7 +67,7 @@ int CGdiPrinterDriver::GetDeviceCaps(int caps_id) const {
return CGdiDeviceDriver::GetDeviceCaps(caps_id);
}
-bool CGdiPrinterDriver::SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource,
+bool CGdiPrinterDriver::SetDIBits(const CFX_DIBSource* pSource,
uint32_t color,
const FX_RECT* pSrcRect,
int left,
@@ -87,30 +87,29 @@ bool CGdiPrinterDriver::SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource,
return false;
CFX_DIBExtractor temp(pSource);
- CFX_RetainPtr<CFX_DIBitmap> pBitmap = temp.GetBitmap();
+ CFX_DIBitmap* pBitmap = temp.GetBitmap();
if (!pBitmap)
return false;
return GDI_SetDIBits(pBitmap, pSrcRect, left, top);
}
-bool CGdiPrinterDriver::StretchDIBits(
- const CFX_RetainPtr<CFX_DIBSource>& pSource,
- uint32_t color,
- int dest_left,
- int dest_top,
- int dest_width,
- int dest_height,
- const FX_RECT* pClipRect,
- uint32_t flags,
- int blend_type) {
+bool CGdiPrinterDriver::StretchDIBits(const CFX_DIBSource* pSource,
+ uint32_t color,
+ int dest_left,
+ int dest_top,
+ int dest_width,
+ int dest_height,
+ const FX_RECT* pClipRect,
+ uint32_t flags,
+ int blend_type) {
if (pSource->IsAlphaMask()) {
int alpha = FXARGB_A(color);
if (pSource->GetBPP() != 1 || alpha != 255)
return false;
if (dest_width < 0 || dest_height < 0) {
- CFX_RetainPtr<CFX_DIBitmap> pFlipped =
+ std::unique_ptr<CFX_DIBitmap> pFlipped =
pSource->FlipImage(dest_width < 0, dest_height < 0);
if (!pFlipped)
return false;
@@ -120,12 +119,13 @@ bool CGdiPrinterDriver::StretchDIBits(
if (dest_height < 0)
dest_top += dest_height;
- return GDI_StretchBitMask(pFlipped, dest_left, dest_top, abs(dest_width),
- abs(dest_height), color, flags);
+ return GDI_StretchBitMask(pFlipped.get(), dest_left, dest_top,
+ abs(dest_width), abs(dest_height), color,
+ flags);
}
CFX_DIBExtractor temp(pSource);
- CFX_RetainPtr<CFX_DIBitmap> pBitmap = temp.GetBitmap();
+ CFX_DIBitmap* pBitmap = temp.GetBitmap();
if (!pBitmap)
return false;
return GDI_StretchBitMask(pBitmap, dest_left, dest_top, dest_width,
@@ -136,7 +136,7 @@ bool CGdiPrinterDriver::StretchDIBits(
return false;
if (dest_width < 0 || dest_height < 0) {
- CFX_RetainPtr<CFX_DIBitmap> pFlipped =
+ std::unique_ptr<CFX_DIBitmap> pFlipped =
pSource->FlipImage(dest_width < 0, dest_height < 0);
if (!pFlipped)
return false;
@@ -146,19 +146,19 @@ bool CGdiPrinterDriver::StretchDIBits(
if (dest_height < 0)
dest_top += dest_height;
- return GDI_StretchDIBits(pFlipped, dest_left, dest_top, abs(dest_width),
- abs(dest_height), flags);
+ return GDI_StretchDIBits(pFlipped.get(), dest_left, dest_top,
+ abs(dest_width), abs(dest_height), flags);
}
CFX_DIBExtractor temp(pSource);
- CFX_RetainPtr<CFX_DIBitmap> pBitmap = temp.GetBitmap();
+ CFX_DIBitmap* pBitmap = temp.GetBitmap();
if (!pBitmap)
return false;
return GDI_StretchDIBits(pBitmap, dest_left, dest_top, dest_width,
dest_height, flags);
}
-bool CGdiPrinterDriver::StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource,
+bool CGdiPrinterDriver::StartDIBits(const CFX_DIBSource* pSource,
int bitmap_alpha,
uint32_t color,
const CFX_Matrix* pMatrix,
@@ -185,12 +185,12 @@ bool CGdiPrinterDriver::StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource,
if (FXSYS_fabs(pMatrix->a) >= 0.5f || FXSYS_fabs(pMatrix->d) >= 0.5f)
return false;
- CFX_RetainPtr<CFX_DIBitmap> pTransformed =
+ std::unique_ptr<CFX_DIBitmap> pTransformed =
pSource->SwapXY(pMatrix->c > 0, pMatrix->b < 0);
if (!pTransformed)
return false;
- return StretchDIBits(pTransformed, color, full_rect.left, full_rect.top,
+ return StretchDIBits(pTransformed.get(), color, full_rect.left, full_rect.top,
full_rect.Width(), full_rect.Height(), nullptr, 0,
blend_type);
}
@@ -436,7 +436,7 @@ bool CPSPrinterDriver::GetClipBox(FX_RECT* pRect) {
return true;
}
-bool CPSPrinterDriver::SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+bool CPSPrinterDriver::SetDIBits(const CFX_DIBSource* pBitmap,
uint32_t color,
const FX_RECT* pSrcRect,
int left,
@@ -447,23 +447,22 @@ bool CPSPrinterDriver::SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
return m_PSRenderer.SetDIBits(pBitmap, color, left, top);
}
-bool CPSPrinterDriver::StretchDIBits(
- const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
- uint32_t color,
- int dest_left,
- int dest_top,
- int dest_width,
- int dest_height,
- const FX_RECT* pClipRect,
- uint32_t flags,
- int blend_type) {
+bool CPSPrinterDriver::StretchDIBits(const CFX_DIBSource* pBitmap,
+ uint32_t color,
+ int dest_left,
+ int dest_top,
+ int dest_width,
+ int dest_height,
+ const FX_RECT* pClipRect,
+ uint32_t flags,
+ int blend_type) {
if (blend_type != FXDIB_BLEND_NORMAL)
return false;
return m_PSRenderer.StretchDIBits(pBitmap, color, dest_left, dest_top,
dest_width, dest_height, flags);
}
-bool CPSPrinterDriver::StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+bool CPSPrinterDriver::StartDIBits(const CFX_DIBSource* pBitmap,
int bitmap_alpha,
uint32_t color,
const CFX_Matrix* pMatrix,
diff --git a/core/fxge/win32/win32_int.h b/core/fxge/win32/win32_int.h
index 35521d0096..54ea3716e1 100644
--- a/core/fxge/win32/win32_int.h
+++ b/core/fxge/win32/win32_int.h
@@ -34,7 +34,7 @@ class CGdiplusExt {
bool IsAvailable() { return !!m_hModule; }
bool StretchBitMask(HDC hDC,
BOOL bMonoDevice,
- const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ const CFX_DIBitmap* pBitmap,
int dest_left,
int dest_top,
int dest_width,
@@ -43,7 +43,7 @@ class CGdiplusExt {
const FX_RECT* pClipRect,
int flags);
bool StretchDIBits(HDC hDC,
- const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ const CFX_DIBitmap* pBitmap,
int dest_left,
int dest_top,
int dest_width,
@@ -96,8 +96,7 @@ class CGdiplusExt {
float font_size,
int fontstyle);
void GdipDeleteFont(void* pFont);
- bool GdipCreateBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
- void** bitmap);
+ bool GdipCreateBitmap(CFX_DIBitmap* pBitmap, void** bitmap);
void GdipDisposeImage(void* bitmap);
void GdipGetFontSize(void* pFont, float* size);
void* GdiAddFontMemResourceEx(void* pFontdata,
@@ -105,7 +104,7 @@ class CGdiplusExt {
void* pdv,
uint32_t* num_face);
bool GdiRemoveFontMemResourceEx(void* handle);
- CFX_RetainPtr<CFX_DIBitmap> LoadDIBitmap(WINDIB_Open_Args_ args);
+ CFX_DIBitmap* LoadDIBitmap(WINDIB_Open_Args_ args);
FARPROC m_Functions[100];
FuncType_GdiAddFontMemResourceEx m_pGdiAddFontMemResourceEx;
@@ -159,17 +158,17 @@ class CGdiDeviceDriver : public IFX_RenderDeviceDriver {
void DrawLine(float x1, float y1, float x2, float y2);
- bool GDI_SetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ bool GDI_SetDIBits(CFX_DIBitmap* pBitmap,
const FX_RECT* pSrcRect,
int left,
int top);
- bool GDI_StretchDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ bool GDI_StretchDIBits(CFX_DIBitmap* pBitmap,
int dest_left,
int dest_top,
int dest_width,
int dest_height,
uint32_t flags);
- bool GDI_StretchBitMask(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ bool GDI_StretchBitMask(CFX_DIBitmap* pBitmap,
int dest_left,
int dest_top,
int dest_width,
@@ -192,16 +191,14 @@ class CGdiDisplayDriver : public CGdiDeviceDriver {
~CGdiDisplayDriver() override;
protected:
- bool GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
- int left,
- int top) override;
- bool SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ bool GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) override;
+ bool SetDIBits(const CFX_DIBSource* pBitmap,
uint32_t color,
const FX_RECT* pSrcRect,
int left,
int top,
int blend_type) override;
- bool StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ bool StretchDIBits(const CFX_DIBSource* pBitmap,
uint32_t color,
int dest_left,
int dest_top,
@@ -210,14 +207,14 @@ class CGdiDisplayDriver : public CGdiDeviceDriver {
const FX_RECT* pClipRect,
uint32_t flags,
int blend_type) override;
- bool StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ bool StartDIBits(const CFX_DIBSource* pBitmap,
int bitmap_alpha,
uint32_t color,
const CFX_Matrix* pMatrix,
uint32_t render_flags,
void*& handle,
int blend_type) override;
- bool UseFoxitStretchEngine(const CFX_RetainPtr<CFX_DIBSource>& pSource,
+ bool UseFoxitStretchEngine(const CFX_DIBSource* pSource,
uint32_t color,
int dest_left,
int dest_top,
@@ -234,13 +231,13 @@ class CGdiPrinterDriver : public CGdiDeviceDriver {
protected:
int GetDeviceCaps(int caps_id) const override;
- bool SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ bool SetDIBits(const CFX_DIBSource* pBitmap,
uint32_t color,
const FX_RECT* pSrcRect,
int left,
int top,
int blend_type) override;
- bool StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ bool StretchDIBits(const CFX_DIBSource* pBitmap,
uint32_t color,
int dest_left,
int dest_top,
@@ -249,7 +246,7 @@ class CGdiPrinterDriver : public CGdiDeviceDriver {
const FX_RECT* pClipRect,
uint32_t flags,
int blend_type) override;
- bool StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ bool StartDIBits(const CFX_DIBSource* pBitmap,
int bitmap_alpha,
uint32_t color,
const CFX_Matrix* pMatrix,
@@ -293,13 +290,13 @@ class CPSPrinterDriver : public IFX_RenderDeviceDriver {
int fill_mode,
int blend_type) override;
bool GetClipBox(FX_RECT* pRect) override;
- bool SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ bool SetDIBits(const CFX_DIBSource* pBitmap,
uint32_t color,
const FX_RECT* pSrcRect,
int left,
int top,
int blend_type) override;
- bool StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ bool StretchDIBits(const CFX_DIBSource* pBitmap,
uint32_t color,
int dest_left,
int dest_top,
@@ -308,7 +305,7 @@ class CPSPrinterDriver : public IFX_RenderDeviceDriver {
const FX_RECT* pClipRect,
uint32_t flags,
int blend_type) override;
- bool StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ bool StartDIBits(const CFX_DIBSource* pBitmap,
int bitmap_alpha,
uint32_t color,
const CFX_Matrix* pMatrix,
diff --git a/fpdfsdk/fpdf_progressive.cpp b/fpdfsdk/fpdf_progressive.cpp
index 927bcddd09..cc09d07638 100644
--- a/fpdfsdk/fpdf_progressive.cpp
+++ b/fpdfsdk/fpdf_progressive.cpp
@@ -6,8 +6,6 @@
#include "public/fpdf_progressive.h"
-#include <utility>
-
#include "core/fpdfapi/cpdf_pagerendercontext.h"
#include "core/fpdfapi/page/cpdf_page.h"
#include "core/fpdfapi/render/cpdf_progressiverenderer.h"
@@ -46,14 +44,11 @@ DLLEXPORT int STDCALL FPDF_RenderPageBitmap_Start(FPDF_BITMAP bitmap,
if (!pPage)
return FPDF_RENDER_FAILED;
- auto pOwnedContext = pdfium::MakeUnique<CPDF_PageRenderContext>();
- CPDF_PageRenderContext* pContext = pOwnedContext.get();
- pPage->SetRenderContext(std::move(pOwnedContext));
-
- CFX_RetainPtr<CFX_DIBitmap> pBitmap(CFXBitmapFromFPDFBitmap(bitmap));
- auto pOwnedDevice = pdfium::MakeUnique<CFX_FxgeDevice>();
- CFX_FxgeDevice* pDevice = pOwnedDevice.get();
- pContext->m_pDevice = std::move(pOwnedDevice);
+ CPDF_PageRenderContext* pContext = new CPDF_PageRenderContext;
+ pPage->SetRenderContext(pdfium::WrapUnique(pContext));
+ CFX_FxgeDevice* pDevice = new CFX_FxgeDevice;
+ pContext->m_pDevice.reset(pDevice);
+ CFX_DIBitmap* pBitmap = CFXBitmapFromFPDFBitmap(bitmap);
pDevice->Attach(pBitmap, !!(flags & FPDF_REVERSE_BYTE_ORDER), nullptr, false);
IFSDK_PAUSE_Adapter IPauseAdapter(pause);
diff --git a/fpdfsdk/fpdfeditimg.cpp b/fpdfsdk/fpdfeditimg.cpp
index ca78088793..69151d1999 100644
--- a/fpdfsdk/fpdfeditimg.cpp
+++ b/fpdfsdk/fpdfeditimg.cpp
@@ -105,8 +105,7 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetBitmap(FPDF_PAGE* pages,
if (pPage)
pImgObj->GetImage()->ResetCache(pPage, nullptr);
}
- CFX_RetainPtr<CFX_DIBitmap> holder(CFXBitmapFromFPDFBitmap(bitmap));
- pImgObj->GetImage()->SetImage(holder);
+ pImgObj->GetImage()->SetImage(reinterpret_cast<CFX_DIBitmap*>(bitmap));
pImgObj->CalcBoundingBox();
return true;
}
diff --git a/fpdfsdk/fpdfformfill.cpp b/fpdfsdk/fpdfformfill.cpp
index 6e31e1f045..c2bbeff7e3 100644
--- a/fpdfsdk/fpdfformfill.cpp
+++ b/fpdfsdk/fpdfformfill.cpp
@@ -109,12 +109,11 @@ void FFLCommon(FPDF_FORMHANDLE hHandle,
pPage->GetDisplayMatrix(start_x, start_y, size_x, size_y, rotate);
FX_RECT clip(start_x, start_y, start_x + size_x, start_y + size_y);
- auto pDevice = pdfium::MakeUnique<CFX_FxgeDevice>();
+ std::unique_ptr<CFX_FxgeDevice> pDevice(new CFX_FxgeDevice);
#ifdef _SKIA_SUPPORT_
pDevice->AttachRecorder(static_cast<SkPictureRecorder*>(recorder));
#endif
- CFX_RetainPtr<CFX_DIBitmap> holder(CFXBitmapFromFPDFBitmap(bitmap));
- pDevice->Attach(holder, false, nullptr, false);
+ pDevice->Attach(CFXBitmapFromFPDFBitmap(bitmap), false, nullptr, false);
pDevice->SaveState();
pDevice->SetClip_Rect(clip);
@@ -148,7 +147,7 @@ void FFLCommon(FPDF_FORMHANDLE hHandle,
pDevice->RestoreState(false);
#ifdef _SKIA_SUPPORT_PATHS_
pDevice->Flush();
- holder->UnPreMultiply();
+ CFXBitmapFromFPDFBitmap(bitmap)->UnPreMultiply();
#endif
}
diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp
index dcfa1c1925..d4284a3217 100644
--- a/fpdfsdk/fpdfview.cpp
+++ b/fpdfsdk/fpdfview.cpp
@@ -709,39 +709,41 @@ DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc,
CPDF_PageRenderContext* pContext = new CPDF_PageRenderContext;
pPage->SetRenderContext(pdfium::WrapUnique(pContext));
- CFX_RetainPtr<CFX_DIBitmap> pBitmap;
+ std::unique_ptr<CFX_DIBitmap> pBitmap;
// TODO: This results in unnecessary rasterization of some PDFs due to
// HasImageMask() returning true. If any image on the page is a mask, the
// entire page gets rasterized and the spool size gets huge.
const bool bNewBitmap =
pPage->BackgroundAlphaNeeded() || pPage->HasImageMask();
if (bNewBitmap) {
- pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ pBitmap = pdfium::MakeUnique<CFX_DIBitmap>();
pBitmap->Create(size_x, size_y, FXDIB_Argb);
pBitmap->Clear(0x00ffffff);
CFX_FxgeDevice* pDevice = new CFX_FxgeDevice;
pContext->m_pDevice = pdfium::WrapUnique(pDevice);
- pDevice->Attach(pBitmap, false, nullptr, false);
+ pDevice->Attach(pBitmap.get(), false, nullptr, false);
} else {
pContext->m_pDevice = pdfium::MakeUnique<CFX_WindowsDevice>(dc);
}
+
FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y,
rotate, flags, true, nullptr);
if (bNewBitmap) {
CFX_WindowsDevice WinDC(dc);
if (WinDC.GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINTER) {
- auto pDst = pdfium::MakeRetain<CFX_DIBitmap>();
+ std::unique_ptr<CFX_DIBitmap> pDst = pdfium::MakeUnique<CFX_DIBitmap>();
int pitch = pBitmap->GetPitch();
pDst->Create(size_x, size_y, FXDIB_Rgb32);
FXSYS_memset(pDst->GetBuffer(), -1, pitch * size_y);
- pDst->CompositeBitmap(0, 0, size_x, size_y, pBitmap, 0, 0,
+ pDst->CompositeBitmap(0, 0, size_x, size_y, pBitmap.get(), 0, 0,
FXDIB_BLEND_NORMAL, nullptr, false, nullptr);
- WinDC.StretchDIBits(pDst, 0, 0, size_x, size_y);
+ WinDC.StretchDIBits(pDst.get(), 0, 0, size_x, size_y);
} else {
- WinDC.SetDIBits(pBitmap, 0, 0);
+ WinDC.SetDIBits(pBitmap.get(), 0, 0);
}
}
+
pPage->SetRenderContext(nullptr);
}
#endif // defined(_WIN32)
@@ -763,12 +765,11 @@ DLLEXPORT void STDCALL FPDF_RenderPageBitmap(FPDF_BITMAP bitmap,
CPDF_PageRenderContext* pContext = new CPDF_PageRenderContext;
pPage->SetRenderContext(pdfium::WrapUnique(pContext));
-
CFX_FxgeDevice* pDevice = new CFX_FxgeDevice;
pContext->m_pDevice.reset(pDevice);
-
- CFX_RetainPtr<CFX_DIBitmap> pBitmap(CFXBitmapFromFPDFBitmap(bitmap));
+ CFX_DIBitmap* pBitmap = CFXBitmapFromFPDFBitmap(bitmap);
pDevice->Attach(pBitmap, !!(flags & FPDF_REVERSE_BYTE_ORDER), nullptr, false);
+
FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y,
rotate, flags, true, nullptr);
@@ -793,11 +794,9 @@ DLLEXPORT void STDCALL FPDF_RenderPageBitmapWithMatrix(FPDF_BITMAP bitmap,
CPDF_PageRenderContext* pContext = new CPDF_PageRenderContext;
pPage->SetRenderContext(pdfium::WrapUnique(pContext));
-
CFX_FxgeDevice* pDevice = new CFX_FxgeDevice;
pContext->m_pDevice.reset(pDevice);
-
- CFX_RetainPtr<CFX_DIBitmap> pBitmap(CFXBitmapFromFPDFBitmap(bitmap));
+ CFX_DIBitmap* pBitmap = CFXBitmapFromFPDFBitmap(bitmap);
pDevice->Attach(pBitmap, !!(flags & FPDF_REVERSE_BYTE_ORDER), nullptr, false);
CFX_Matrix transform_matrix = pPage->GetPageMatrix();
@@ -941,11 +940,11 @@ DLLEXPORT void STDCALL FPDF_PageToDevice(FPDF_PAGE page,
DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_Create(int width,
int height,
int alpha) {
- auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ auto pBitmap = pdfium::MakeUnique<CFX_DIBitmap>();
if (!pBitmap->Create(width, height, alpha ? FXDIB_Argb : FXDIB_Rgb32))
return nullptr;
- return pBitmap.Leak();
+ return pBitmap.release();
}
DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_CreateEx(int width,
@@ -970,9 +969,9 @@ DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_CreateEx(int width,
default:
return nullptr;
}
- auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ CFX_DIBitmap* pBitmap = new CFX_DIBitmap;
pBitmap->Create(width, height, fx_format, (uint8_t*)first_scan, stride);
- return pBitmap.Leak();
+ return pBitmap;
}
DLLEXPORT void STDCALL FPDFBitmap_FillRect(FPDF_BITMAP bitmap,
@@ -985,7 +984,7 @@ DLLEXPORT void STDCALL FPDFBitmap_FillRect(FPDF_BITMAP bitmap,
return;
CFX_FxgeDevice device;
- CFX_RetainPtr<CFX_DIBitmap> pBitmap(CFXBitmapFromFPDFBitmap(bitmap));
+ CFX_DIBitmap* pBitmap = CFXBitmapFromFPDFBitmap(bitmap);
device.Attach(pBitmap, false, nullptr, false);
if (!pBitmap->HasAlpha())
color |= 0xFF000000;
@@ -1010,8 +1009,7 @@ DLLEXPORT int STDCALL FPDFBitmap_GetStride(FPDF_BITMAP bitmap) {
}
DLLEXPORT void STDCALL FPDFBitmap_Destroy(FPDF_BITMAP bitmap) {
- CFX_RetainPtr<CFX_DIBitmap> destroyer;
- destroyer.Unleak(CFXBitmapFromFPDFBitmap(bitmap));
+ delete CFXBitmapFromFPDFBitmap(bitmap);
}
void FPDF_RenderPage_Retail(CPDF_PageRenderContext* pContext,
diff --git a/testing/libfuzzer/pdf_codec_jbig2_fuzzer.cc b/testing/libfuzzer/pdf_codec_jbig2_fuzzer.cc
index 162a0bf772..1db39751db 100644
--- a/testing/libfuzzer/pdf_codec_jbig2_fuzzer.cc
+++ b/testing/libfuzzer/pdf_codec_jbig2_fuzzer.cc
@@ -25,7 +25,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
size -= kParameterSize;
data += kParameterSize;
- auto bitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ std::unique_ptr<CFX_DIBitmap> bitmap(new CFX_DIBitmap);
if (!bitmap->Create(width, height, FXDIB_1bppRgb))
return 0;
diff --git a/testing/libfuzzer/pdf_jpx_fuzzer.cc b/testing/libfuzzer/pdf_jpx_fuzzer.cc
index 92ba210be3..bea7ba2dbe 100644
--- a/testing/libfuzzer/pdf_jpx_fuzzer.cc
+++ b/testing/libfuzzer/pdf_jpx_fuzzer.cc
@@ -37,7 +37,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
width = (width * components + 2) / 3;
format = FXDIB_Rgb;
}
- auto bitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+
+ std::unique_ptr<CFX_DIBitmap> bitmap(new CFX_DIBitmap);
if (!bitmap->Create(width, height, format))
return 0;
diff --git a/testing/libfuzzer/xfa_codec_fuzzer.h b/testing/libfuzzer/xfa_codec_fuzzer.h
index 85cedec9a1..9a8b23e368 100644
--- a/testing/libfuzzer/xfa_codec_fuzzer.h
+++ b/testing/libfuzzer/xfa_codec_fuzzer.h
@@ -32,7 +32,7 @@ class XFACodecFuzzer {
if (status != FXCODEC_STATUS_FRAME_READY)
return 0;
- auto bitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ std::unique_ptr<CFX_DIBitmap> bitmap(new CFX_DIBitmap);
bitmap->Create(decoder->GetWidth(), decoder->GetHeight(), FXDIB_Argb);
int32_t frames;
@@ -40,7 +40,7 @@ class XFACodecFuzzer {
frames == 0)
return 0;
- status = decoder->StartDecode(bitmap, 0, 0, bitmap->GetWidth(),
+ status = decoder->StartDecode(bitmap.get(), 0, 0, bitmap->GetWidth(),
bitmap->GetHeight());
while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE)
status = decoder->ContinueDecode();
diff --git a/xfa/fde/fde_gedevice.cpp b/xfa/fde/fde_gedevice.cpp
index 8af769aae5..3c6ca9b37e 100644
--- a/xfa/fde/fde_gedevice.cpp
+++ b/xfa/fde/fde_gedevice.cpp
@@ -82,7 +82,7 @@ float CFDE_RenderDevice::GetDpiY() const {
return 96;
}
-bool CFDE_RenderDevice::DrawImage(const CFX_RetainPtr<CFX_DIBSource>& pDib,
+bool CFDE_RenderDevice::DrawImage(CFX_DIBSource* pDib,
const CFX_RectF* pSrcRect,
const CFX_RectF& dstRect,
const CFX_Matrix* pImgMatrix,
diff --git a/xfa/fde/fde_gedevice.h b/xfa/fde/fde_gedevice.h
index a3a1eaf111..976e1bde6f 100644
--- a/xfa/fde/fde_gedevice.h
+++ b/xfa/fde/fde_gedevice.h
@@ -34,7 +34,7 @@ class CFDE_RenderDevice {
float GetDpiX() const;
float GetDpiY() const;
- bool DrawImage(const CFX_RetainPtr<CFX_DIBSource>& pDib,
+ bool DrawImage(CFX_DIBSource* pDib,
const CFX_RectF* pSrcRect,
const CFX_RectF& dstRect,
const CFX_Matrix* pImgMatrix = nullptr,
diff --git a/xfa/fde/tto/fde_textout.cpp b/xfa/fde/tto/fde_textout.cpp
index c06a12fedf..7f6eddd9ce 100644
--- a/xfa/fde/tto/fde_textout.cpp
+++ b/xfa/fde/tto/fde_textout.cpp
@@ -112,7 +112,7 @@ void CFDE_TextOut::SetLineSpace(float fLineSpace) {
m_fLineSpace = fLineSpace;
}
-void CFDE_TextOut::SetDIBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pDIB) {
+void CFDE_TextOut::SetDIBitmap(CFX_DIBitmap* pDIB) {
ASSERT(pDIB);
m_pRenderDevice.reset();
diff --git a/xfa/fde/tto/fde_textout.h b/xfa/fde/tto/fde_textout.h
index e48e25567e..6883a5701f 100644
--- a/xfa/fde/tto/fde_textout.h
+++ b/xfa/fde/tto/fde_textout.h
@@ -87,7 +87,7 @@ class CFDE_TextOut {
void SetParagraphBreakChar(wchar_t wch);
void SetAlignment(int32_t iAlignment);
void SetLineSpace(float fLineSpace);
- void SetDIBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pDIB);
+ void SetDIBitmap(CFX_DIBitmap* pDIB);
void SetRenderDevice(CFX_RenderDevice* pDevice);
void SetClipRect(const CFX_Rect& rtClip);
void SetClipRect(const CFX_RectF& rtClip);
diff --git a/xfa/fwl/cfwl_themebackground.h b/xfa/fwl/cfwl_themebackground.h
index f23f26e229..3f20488830 100644
--- a/xfa/fwl/cfwl_themebackground.h
+++ b/xfa/fwl/cfwl_themebackground.h
@@ -16,17 +16,12 @@ class CFX_Path;
class CFWL_ThemeBackground : public CFWL_ThemePart {
public:
- CFWL_ThemeBackground();
- ~CFWL_ThemeBackground();
+ CFWL_ThemeBackground()
+ : m_pGraphics(nullptr), m_pImage(nullptr), m_pPath(nullptr) {}
CFX_Graphics* m_pGraphics;
+ CFX_DIBitmap* m_pImage;
CFX_Path* m_pPath;
- CFX_RetainPtr<CFX_DIBitmap> m_pImage;
};
-inline CFWL_ThemeBackground::CFWL_ThemeBackground()
- : m_pGraphics(nullptr), m_pPath(nullptr) {}
-
-inline CFWL_ThemeBackground::~CFWL_ThemeBackground() {}
-
#endif // XFA_FWL_CFWL_THEMEBACKGROUND_H_
diff --git a/xfa/fxbarcode/BC_TwoDimWriter.cpp b/xfa/fxbarcode/BC_TwoDimWriter.cpp
index 9c9427aaa5..328352c6c1 100644
--- a/xfa/fxbarcode/BC_TwoDimWriter.cpp
+++ b/xfa/fxbarcode/BC_TwoDimWriter.cpp
@@ -57,9 +57,8 @@ int32_t CBC_TwoDimWriter::GetErrorCorrectionLevel() const {
return m_iCorrectLevel;
}
-void CBC_TwoDimWriter::RenderBitmapResult(
- CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
- int32_t& e) {
+void CBC_TwoDimWriter::RenderBitmapResult(CFX_DIBitmap*& pOutBitmap,
+ int32_t& e) {
if (m_bFixedSize) {
pOutBitmap = CreateDIBitmap(m_Width, m_Height);
} else {
@@ -83,8 +82,12 @@ void CBC_TwoDimWriter::RenderBitmapResult(
}
}
}
- if (!m_bFixedSize)
- pOutBitmap = pOutBitmap->StretchTo(m_Width, m_Height);
+ if (!m_bFixedSize) {
+ std::unique_ptr<CFX_DIBitmap> pStretchBitmap =
+ pOutBitmap->StretchTo(m_Width, m_Height);
+ delete pOutBitmap;
+ pOutBitmap = pStretchBitmap.release();
+ }
}
void CBC_TwoDimWriter::RenderResult(uint8_t* code,
diff --git a/xfa/fxbarcode/BC_TwoDimWriter.h b/xfa/fxbarcode/BC_TwoDimWriter.h
index c6e0495aec..ad4658b008 100644
--- a/xfa/fxbarcode/BC_TwoDimWriter.h
+++ b/xfa/fxbarcode/BC_TwoDimWriter.h
@@ -23,11 +23,11 @@ class CBC_TwoDimWriter : public CBC_Writer {
int32_t codeWidth,
int32_t codeHeight,
int32_t& e);
- virtual void RenderBitmapResult(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
- int32_t& e);
+ virtual void RenderBitmapResult(CFX_DIBitmap*& pOutBitmap, int32_t& e);
virtual void RenderDeviceResult(CFX_RenderDevice* device,
const CFX_Matrix* matrix);
virtual bool SetErrorCorrectionLevel(int32_t level) = 0;
+
int32_t GetErrorCorrectionLevel() const;
protected:
diff --git a/xfa/fxbarcode/BC_Writer.cpp b/xfa/fxbarcode/BC_Writer.cpp
index 69f34148f4..73163522cb 100644
--- a/xfa/fxbarcode/BC_Writer.cpp
+++ b/xfa/fxbarcode/BC_Writer.cpp
@@ -49,10 +49,8 @@ void CBC_Writer::SetBackgroundColor(FX_ARGB backgroundColor) {
void CBC_Writer::SetBarcodeColor(FX_ARGB foregroundColor) {
m_barColor = foregroundColor;
}
-
-CFX_RetainPtr<CFX_DIBitmap> CBC_Writer::CreateDIBitmap(int32_t width,
- int32_t height) {
- auto pDIBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+CFX_DIBitmap* CBC_Writer::CreateDIBitmap(int32_t width, int32_t height) {
+ CFX_DIBitmap* pDIBitmap = new CFX_DIBitmap;
pDIBitmap->Create(width, height, m_colorSpace);
return pDIBitmap;
}
diff --git a/xfa/fxbarcode/BC_Writer.h b/xfa/fxbarcode/BC_Writer.h
index 8dd03ead58..90ea06a397 100644
--- a/xfa/fxbarcode/BC_Writer.h
+++ b/xfa/fxbarcode/BC_Writer.h
@@ -24,7 +24,7 @@ class CBC_Writer {
virtual void SetBarcodeColor(FX_ARGB foregroundColor);
protected:
- CFX_RetainPtr<CFX_DIBitmap> CreateDIBitmap(int32_t width, int32_t height);
+ CFX_DIBitmap* CreateDIBitmap(int32_t width, int32_t height);
int32_t m_CharEncoding;
int32_t m_ModuleHeight;
int32_t m_ModuleWidth;
diff --git a/xfa/fxbarcode/cbc_codabar.cpp b/xfa/fxbarcode/cbc_codabar.cpp
index c49fe95948..53e351d5a2 100644
--- a/xfa/fxbarcode/cbc_codabar.cpp
+++ b/xfa/fxbarcode/cbc_codabar.cpp
@@ -93,8 +93,7 @@ bool CBC_Codabar::RenderDevice(CFX_RenderDevice* device,
return true;
}
-bool CBC_Codabar::RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
- int32_t& e) {
+bool CBC_Codabar::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) {
CFX_WideString renderCon =
static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter.get())
->encodedContents(m_renderContents.AsStringC());
diff --git a/xfa/fxbarcode/cbc_codabar.h b/xfa/fxbarcode/cbc_codabar.h
index f00c295f44..43f1a010c0 100644
--- a/xfa/fxbarcode/cbc_codabar.h
+++ b/xfa/fxbarcode/cbc_codabar.h
@@ -24,8 +24,7 @@ class CBC_Codabar : public CBC_OneCode {
bool RenderDevice(CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t& e) override;
- bool RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
- int32_t& e) override;
+ bool RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) override;
BC_TYPE GetType() override;
bool SetStartChar(char start);
diff --git a/xfa/fxbarcode/cbc_code128.cpp b/xfa/fxbarcode/cbc_code128.cpp
index ea0bc56fce..35bd136fd0 100644
--- a/xfa/fxbarcode/cbc_code128.cpp
+++ b/xfa/fxbarcode/cbc_code128.cpp
@@ -78,11 +78,12 @@ bool CBC_Code128::RenderDevice(CFX_RenderDevice* device,
return true;
}
-bool CBC_Code128::RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
- int32_t& e) {
+bool CBC_Code128::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) {
static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
->RenderBitmapResult(pOutBitmap, m_renderContents.AsStringC(), e);
- return e == BCExceptionNO;
+ if (e != BCExceptionNO)
+ return false;
+ return true;
}
BC_TYPE CBC_Code128::GetType() {
diff --git a/xfa/fxbarcode/cbc_code128.h b/xfa/fxbarcode/cbc_code128.h
index d8505760a6..0dd9c84f68 100644
--- a/xfa/fxbarcode/cbc_code128.h
+++ b/xfa/fxbarcode/cbc_code128.h
@@ -24,8 +24,7 @@ class CBC_Code128 : public CBC_OneCode {
bool RenderDevice(CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t& e) override;
- bool RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
- int32_t& e) override;
+ bool RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) override;
BC_TYPE GetType() override;
bool SetTextLocation(BC_TEXT_LOC loction);
diff --git a/xfa/fxbarcode/cbc_code39.cpp b/xfa/fxbarcode/cbc_code39.cpp
index e3cfccbd90..af45ad4063 100644
--- a/xfa/fxbarcode/cbc_code39.cpp
+++ b/xfa/fxbarcode/cbc_code39.cpp
@@ -70,14 +70,15 @@ bool CBC_Code39::RenderDevice(CFX_RenderDevice* device,
return true;
}
-bool CBC_Code39::RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
- int32_t& e) {
+bool CBC_Code39::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) {
CFX_WideString renderCon =
static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get())
->encodedContents(m_renderContents.AsStringC(), e);
static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
->RenderBitmapResult(pOutBitmap, renderCon.AsStringC(), e);
- return e == BCExceptionNO;
+ if (e != BCExceptionNO)
+ return false;
+ return true;
}
BC_TYPE CBC_Code39::GetType() {
diff --git a/xfa/fxbarcode/cbc_code39.h b/xfa/fxbarcode/cbc_code39.h
index 0320211631..7f5c627c6c 100644
--- a/xfa/fxbarcode/cbc_code39.h
+++ b/xfa/fxbarcode/cbc_code39.h
@@ -24,8 +24,7 @@ class CBC_Code39 : public CBC_OneCode {
bool RenderDevice(CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t& e) override;
- bool RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
- int32_t& e) override;
+ bool RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) override;
BC_TYPE GetType() override;
bool SetTextLocation(BC_TEXT_LOC location);
diff --git a/xfa/fxbarcode/cbc_codebase.h b/xfa/fxbarcode/cbc_codebase.h
index 37a65d2cf6..c28c08b7e7 100644
--- a/xfa/fxbarcode/cbc_codebase.h
+++ b/xfa/fxbarcode/cbc_codebase.h
@@ -30,8 +30,7 @@ class CBC_CodeBase {
virtual bool RenderDevice(CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t& e) = 0;
- virtual bool RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
- int32_t& e) = 0;
+ virtual bool RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) = 0;
bool SetCharEncoding(int32_t encoding);
bool SetModuleHeight(int32_t moduleHeight);
diff --git a/xfa/fxbarcode/cbc_datamatrix.cpp b/xfa/fxbarcode/cbc_datamatrix.cpp
index ebfa8b9901..6122368e84 100644
--- a/xfa/fxbarcode/cbc_datamatrix.cpp
+++ b/xfa/fxbarcode/cbc_datamatrix.cpp
@@ -53,11 +53,12 @@ bool CBC_DataMatrix::RenderDevice(CFX_RenderDevice* device,
return true;
}
-bool CBC_DataMatrix::RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
- int32_t& e) {
+bool CBC_DataMatrix::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) {
static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get())
->RenderBitmapResult(pOutBitmap, e);
- return e == BCExceptionNO;
+ if (e != BCExceptionNO)
+ return false;
+ return true;
}
BC_TYPE CBC_DataMatrix::GetType() {
diff --git a/xfa/fxbarcode/cbc_datamatrix.h b/xfa/fxbarcode/cbc_datamatrix.h
index ebca372f3f..661b48d744 100644
--- a/xfa/fxbarcode/cbc_datamatrix.h
+++ b/xfa/fxbarcode/cbc_datamatrix.h
@@ -24,8 +24,7 @@ class CBC_DataMatrix : public CBC_CodeBase {
bool RenderDevice(CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t& e) override;
- bool RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
- int32_t& e) override;
+ bool RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) override;
BC_TYPE GetType() override;
};
diff --git a/xfa/fxbarcode/cbc_ean13.cpp b/xfa/fxbarcode/cbc_ean13.cpp
index afe52db9dd..abd5f198a3 100644
--- a/xfa/fxbarcode/cbc_ean13.cpp
+++ b/xfa/fxbarcode/cbc_ean13.cpp
@@ -83,11 +83,12 @@ bool CBC_EAN13::RenderDevice(CFX_RenderDevice* device,
return true;
}
-bool CBC_EAN13::RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
- int32_t& e) {
+bool CBC_EAN13::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) {
static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
->RenderBitmapResult(pOutBitmap, m_renderContents.AsStringC(), e);
- return e == BCExceptionNO;
+ if (e != BCExceptionNO)
+ return false;
+ return true;
}
BC_TYPE CBC_EAN13::GetType() {
diff --git a/xfa/fxbarcode/cbc_ean13.h b/xfa/fxbarcode/cbc_ean13.h
index 5f23855ead..f0e7940a04 100644
--- a/xfa/fxbarcode/cbc_ean13.h
+++ b/xfa/fxbarcode/cbc_ean13.h
@@ -24,8 +24,7 @@ class CBC_EAN13 : public CBC_OneCode {
bool RenderDevice(CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t& e) override;
- bool RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
- int32_t& e) override;
+ bool RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) override;
BC_TYPE GetType() override;
private:
diff --git a/xfa/fxbarcode/cbc_ean8.cpp b/xfa/fxbarcode/cbc_ean8.cpp
index 408b43a608..bfb458521e 100644
--- a/xfa/fxbarcode/cbc_ean8.cpp
+++ b/xfa/fxbarcode/cbc_ean8.cpp
@@ -82,11 +82,12 @@ bool CBC_EAN8::RenderDevice(CFX_RenderDevice* device,
return true;
}
-bool CBC_EAN8::RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
- int32_t& e) {
+bool CBC_EAN8::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) {
static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
->RenderBitmapResult(pOutBitmap, m_renderContents.AsStringC(), e);
- return e == BCExceptionNO;
+ if (e != BCExceptionNO)
+ return false;
+ return true;
}
BC_TYPE CBC_EAN8::GetType() {
diff --git a/xfa/fxbarcode/cbc_ean8.h b/xfa/fxbarcode/cbc_ean8.h
index 478a67405c..6a475cb795 100644
--- a/xfa/fxbarcode/cbc_ean8.h
+++ b/xfa/fxbarcode/cbc_ean8.h
@@ -24,8 +24,7 @@ class CBC_EAN8 : public CBC_OneCode {
bool RenderDevice(CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t& e) override;
- bool RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
- int32_t& e) override;
+ bool RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) override;
BC_TYPE GetType() override;
private:
diff --git a/xfa/fxbarcode/cbc_pdf417i.cpp b/xfa/fxbarcode/cbc_pdf417i.cpp
index a5e210757a..1c5547d445 100644
--- a/xfa/fxbarcode/cbc_pdf417i.cpp
+++ b/xfa/fxbarcode/cbc_pdf417i.cpp
@@ -63,11 +63,12 @@ bool CBC_PDF417I::RenderDevice(CFX_RenderDevice* device,
return true;
}
-bool CBC_PDF417I::RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
- int32_t& e) {
+bool CBC_PDF417I::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) {
static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get())
->RenderBitmapResult(pOutBitmap, e);
- return e == BCExceptionNO;
+ if (e != BCExceptionNO)
+ return false;
+ return true;
}
BC_TYPE CBC_PDF417I::GetType() {
diff --git a/xfa/fxbarcode/cbc_pdf417i.h b/xfa/fxbarcode/cbc_pdf417i.h
index c26dceeebd..70ea929820 100644
--- a/xfa/fxbarcode/cbc_pdf417i.h
+++ b/xfa/fxbarcode/cbc_pdf417i.h
@@ -24,8 +24,7 @@ class CBC_PDF417I : public CBC_CodeBase {
bool RenderDevice(CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t& e) override;
- bool RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
- int32_t& e) override;
+ bool RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) override;
BC_TYPE GetType() override;
bool SetErrorCorrectionLevel(int32_t level);
diff --git a/xfa/fxbarcode/cbc_qrcode.cpp b/xfa/fxbarcode/cbc_qrcode.cpp
index e046857b6b..26b74ca400 100644
--- a/xfa/fxbarcode/cbc_qrcode.cpp
+++ b/xfa/fxbarcode/cbc_qrcode.cpp
@@ -69,11 +69,12 @@ bool CBC_QRCode::RenderDevice(CFX_RenderDevice* device,
return true;
}
-bool CBC_QRCode::RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
- int32_t& e) {
+bool CBC_QRCode::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) {
static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get())
->RenderBitmapResult(pOutBitmap, e);
- return e == BCExceptionNO;
+ if (e != BCExceptionNO)
+ return false;
+ return true;
}
BC_TYPE CBC_QRCode::GetType() {
diff --git a/xfa/fxbarcode/cbc_qrcode.h b/xfa/fxbarcode/cbc_qrcode.h
index 05f3f6c415..ac2d93d915 100644
--- a/xfa/fxbarcode/cbc_qrcode.h
+++ b/xfa/fxbarcode/cbc_qrcode.h
@@ -24,8 +24,7 @@ class CBC_QRCode : public CBC_CodeBase {
bool RenderDevice(CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t& e) override;
- bool RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
- int32_t& e) override;
+ bool RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) override;
BC_TYPE GetType() override;
bool SetVersion(int32_t version);
diff --git a/xfa/fxbarcode/cbc_upca.cpp b/xfa/fxbarcode/cbc_upca.cpp
index 915a6aead5..87f58093ae 100644
--- a/xfa/fxbarcode/cbc_upca.cpp
+++ b/xfa/fxbarcode/cbc_upca.cpp
@@ -86,11 +86,12 @@ bool CBC_UPCA::RenderDevice(CFX_RenderDevice* device,
return true;
}
-bool CBC_UPCA::RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
- int32_t& e) {
+bool CBC_UPCA::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) {
static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
->RenderBitmapResult(pOutBitmap, m_renderContents.AsStringC(), e);
- return e == BCExceptionNO;
+ if (e != BCExceptionNO)
+ return false;
+ return true;
}
BC_TYPE CBC_UPCA::GetType() {
diff --git a/xfa/fxbarcode/cbc_upca.h b/xfa/fxbarcode/cbc_upca.h
index 4015a3143d..bf90b922b5 100644
--- a/xfa/fxbarcode/cbc_upca.h
+++ b/xfa/fxbarcode/cbc_upca.h
@@ -24,8 +24,7 @@ class CBC_UPCA : public CBC_OneCode {
bool RenderDevice(CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t& e) override;
- bool RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
- int32_t& e) override;
+ bool RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) override;
BC_TYPE GetType() override;
private:
diff --git a/xfa/fxbarcode/oned/BC_OneDimWriter.cpp b/xfa/fxbarcode/oned/BC_OneDimWriter.cpp
index 16eba2df10..02ae58dc84 100644
--- a/xfa/fxbarcode/oned/BC_OneDimWriter.cpp
+++ b/xfa/fxbarcode/oned/BC_OneDimWriter.cpp
@@ -224,14 +224,13 @@ void CBC_OneDimWriter::ShowDeviceChars(CFX_RenderDevice* device,
m_fontColor, FXTEXT_CLEARTYPE);
}
-void CBC_OneDimWriter::ShowBitmapChars(
- const CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
- const CFX_ByteString str,
- float geWidth,
- FXTEXT_CHARPOS* pCharPos,
- float locX,
- float locY,
- int32_t barWidth) {
+void CBC_OneDimWriter::ShowBitmapChars(CFX_DIBitmap* pOutBitmap,
+ const CFX_ByteString str,
+ float geWidth,
+ FXTEXT_CHARPOS* pCharPos,
+ float locX,
+ float locY,
+ int32_t barWidth) {
int32_t iFontSize = (int32_t)fabs(m_fFontSize);
int32_t iTextHeight = iFontSize + 1;
CFX_FxgeDevice ge;
@@ -249,7 +248,7 @@ void CBC_OneDimWriter::ShowBitmapChars(
}
void CBC_OneDimWriter::ShowChars(const CFX_WideStringC& contents,
- const CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
+ CFX_DIBitmap* pOutBitmap,
CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t barWidth,
@@ -317,10 +316,9 @@ void CBC_OneDimWriter::ShowChars(const CFX_WideStringC& contents,
FX_Free(pCharPos);
}
-void CBC_OneDimWriter::RenderBitmapResult(
- CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
- const CFX_WideStringC& contents,
- int32_t& e) {
+void CBC_OneDimWriter::RenderBitmapResult(CFX_DIBitmap*& pOutBitmap,
+ const CFX_WideStringC& contents,
+ int32_t& e) {
if (!m_output)
if (e != BCExceptionNO)
return;
@@ -339,17 +337,20 @@ void CBC_OneDimWriter::RenderBitmapResult(
}
}
int32_t i = 0;
- for (; i < contents.GetLength(); i++) {
- if (contents.GetAt(i) != ' ')
+ for (; i < contents.GetLength(); i++)
+ if (contents.GetAt(i) != ' ') {
break;
- }
+ }
if (m_locTextLoc != BC_TEXT_LOC_NONE && i < contents.GetLength()) {
ShowChars(contents, pOutBitmap, nullptr, nullptr, m_barWidth, m_multiple,
e);
if (e != BCExceptionNO)
return;
}
- pOutBitmap = pOutBitmap->StretchTo(m_Width, m_Height);
+ std::unique_ptr<CFX_DIBitmap> pStretchBitmap =
+ pOutBitmap->StretchTo(m_Width, m_Height);
+ delete pOutBitmap;
+ pOutBitmap = pStretchBitmap.release();
}
void CBC_OneDimWriter::RenderDeviceResult(CFX_RenderDevice* device,
diff --git a/xfa/fxbarcode/oned/BC_OneDimWriter.h b/xfa/fxbarcode/oned/BC_OneDimWriter.h
index 4892889ddb..b2447cffb7 100644
--- a/xfa/fxbarcode/oned/BC_OneDimWriter.h
+++ b/xfa/fxbarcode/oned/BC_OneDimWriter.h
@@ -42,7 +42,7 @@ class CBC_OneDimWriter : public CBC_Writer {
int32_t codeLength,
bool isDevice,
int32_t& e);
- virtual void RenderBitmapResult(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
+ virtual void RenderBitmapResult(CFX_DIBitmap*& pOutBitmap,
const CFX_WideStringC& contents,
int32_t& e);
virtual void RenderDeviceResult(CFX_RenderDevice* device,
@@ -68,13 +68,13 @@ class CBC_OneDimWriter : public CBC_Writer {
int32_t fontSize,
float& charsLen);
virtual void ShowChars(const CFX_WideStringC& contents,
- const CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
+ CFX_DIBitmap* pOutBitmap,
CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t barWidth,
int32_t multiple,
int32_t& e);
- virtual void ShowBitmapChars(const CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
+ virtual void ShowBitmapChars(CFX_DIBitmap* pOutBitmap,
const CFX_ByteString str,
float geWidth,
FXTEXT_CHARPOS* pCharPos,
diff --git a/xfa/fxbarcode/oned/BC_OnedEAN13Writer.cpp b/xfa/fxbarcode/oned/BC_OnedEAN13Writer.cpp
index dcea777089..555b58643d 100644
--- a/xfa/fxbarcode/oned/BC_OnedEAN13Writer.cpp
+++ b/xfa/fxbarcode/oned/BC_OnedEAN13Writer.cpp
@@ -167,14 +167,13 @@ uint8_t* CBC_OnedEAN13Writer::Encode(const CFX_ByteString& contents,
return result;
}
-void CBC_OnedEAN13Writer::ShowChars(
- const CFX_WideStringC& contents,
- const CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
- CFX_RenderDevice* device,
- const CFX_Matrix* matrix,
- int32_t barWidth,
- int32_t multiple,
- int32_t& e) {
+void CBC_OnedEAN13Writer::ShowChars(const CFX_WideStringC& contents,
+ CFX_DIBitmap* pOutBitmap,
+ CFX_RenderDevice* device,
+ const CFX_Matrix* matrix,
+ int32_t barWidth,
+ int32_t multiple,
+ int32_t& e) {
if (!device && !pOutBitmap) {
e = BCExceptionIllegalArgument;
return;
@@ -279,6 +278,7 @@ void CBC_OnedEAN13Writer::ShowChars(
CalcTextInfo(tempStr, pCharPos, m_pFont, (float)strWidth, iFontSize, blank);
if (pOutBitmap) {
+ delete ge.GetBitmap();
ge.Create(strWidth, iTextHeight, FXDIB_Argb, nullptr);
ge.GetBitmap()->Clear(m_backgroundColor);
ge.DrawNormalText(iLen, pCharPos, m_pFont, static_cast<float>(iFontSize),
diff --git a/xfa/fxbarcode/oned/BC_OnedEAN13Writer.h b/xfa/fxbarcode/oned/BC_OnedEAN13Writer.h
index 8336259568..5775f89046 100644
--- a/xfa/fxbarcode/oned/BC_OnedEAN13Writer.h
+++ b/xfa/fxbarcode/oned/BC_OnedEAN13Writer.h
@@ -46,7 +46,7 @@ class CBC_OnedEAN13Writer : public CBC_OneDimWriter {
protected:
void ShowChars(const CFX_WideStringC& contents,
- const CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
+ CFX_DIBitmap* pOutBitmap,
CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t barWidth,
diff --git a/xfa/fxbarcode/oned/BC_OnedEAN8Writer.cpp b/xfa/fxbarcode/oned/BC_OnedEAN8Writer.cpp
index a7fa30c811..5f571c2a30 100644
--- a/xfa/fxbarcode/oned/BC_OnedEAN8Writer.cpp
+++ b/xfa/fxbarcode/oned/BC_OnedEAN8Writer.cpp
@@ -165,14 +165,13 @@ uint8_t* CBC_OnedEAN8Writer::Encode(const CFX_ByteString& contents,
return result;
}
-void CBC_OnedEAN8Writer::ShowChars(
- const CFX_WideStringC& contents,
- const CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
- CFX_RenderDevice* device,
- const CFX_Matrix* matrix,
- int32_t barWidth,
- int32_t multiple,
- int32_t& e) {
+void CBC_OnedEAN8Writer::ShowChars(const CFX_WideStringC& contents,
+ CFX_DIBitmap* pOutBitmap,
+ CFX_RenderDevice* device,
+ const CFX_Matrix* matrix,
+ int32_t barWidth,
+ int32_t multiple,
+ int32_t& e) {
if (!device && !pOutBitmap) {
e = BCExceptionIllegalArgument;
return;
@@ -218,6 +217,7 @@ void CBC_OnedEAN8Writer::ShowChars(
CFX_Matrix affine_matrix(1.0, 0.0, 0.0, -1.0, 0.0, (float)iFontSize);
CFX_FxgeDevice ge;
if (pOutBitmap) {
+ delete ge.GetBitmap();
ge.Create(strWidth, iTextHeight, FXDIB_Argb, nullptr);
ge.GetBitmap()->Clear(m_backgroundColor);
ge.DrawNormalText(iLen, pCharPos, m_pFont, static_cast<float>(iFontSize),
@@ -237,6 +237,7 @@ void CBC_OnedEAN8Writer::ShowChars(
CalcTextInfo(tempStr, pCharPos + 4, m_pFont, (float)strWidth, iFontSize,
blank);
if (pOutBitmap) {
+ delete ge.GetBitmap();
ge.Create(strWidth, iTextHeight, FXDIB_Argb, nullptr);
ge.GetBitmap()->Clear(m_backgroundColor);
ge.DrawNormalText(iLen, pCharPos + 4, m_pFont,
diff --git a/xfa/fxbarcode/oned/BC_OnedEAN8Writer.h b/xfa/fxbarcode/oned/BC_OnedEAN8Writer.h
index b9921babc3..844fc33afa 100644
--- a/xfa/fxbarcode/oned/BC_OnedEAN8Writer.h
+++ b/xfa/fxbarcode/oned/BC_OnedEAN8Writer.h
@@ -50,7 +50,7 @@ class CBC_OnedEAN8Writer : public CBC_OneDimWriter {
protected:
void ShowChars(const CFX_WideStringC& contents,
- const CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
+ CFX_DIBitmap* pOutBitmap,
CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t barWidth,
diff --git a/xfa/fxbarcode/oned/BC_OnedUPCAWriter.cpp b/xfa/fxbarcode/oned/BC_OnedUPCAWriter.cpp
index 540e852d5d..cefae97d8d 100644
--- a/xfa/fxbarcode/oned/BC_OnedUPCAWriter.cpp
+++ b/xfa/fxbarcode/oned/BC_OnedUPCAWriter.cpp
@@ -117,14 +117,13 @@ uint8_t* CBC_OnedUPCAWriter::Encode(const CFX_ByteString& contents,
return nullptr;
}
-void CBC_OnedUPCAWriter::ShowChars(
- const CFX_WideStringC& contents,
- const CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
- CFX_RenderDevice* device,
- const CFX_Matrix* matrix,
- int32_t barWidth,
- int32_t multiple,
- int32_t& e) {
+void CBC_OnedUPCAWriter::ShowChars(const CFX_WideStringC& contents,
+ CFX_DIBitmap* pOutBitmap,
+ CFX_RenderDevice* device,
+ const CFX_Matrix* matrix,
+ int32_t barWidth,
+ int32_t multiple,
+ int32_t& e) {
if (!device && !pOutBitmap) {
e = BCExceptionIllegalArgument;
return;
@@ -236,6 +235,7 @@ void CBC_OnedUPCAWriter::ShowChars(
CalcTextInfo(tempStr, pCharPos, m_pFont, strWidth, iFontSize, blank);
if (pOutBitmap) {
+ delete ge.GetBitmap();
ge.Create((int)strWidth, iTextHeight, FXDIB_Argb, nullptr);
ge.GetBitmap()->Clear(m_backgroundColor);
ge.DrawNormalText(iLen, pCharPos, m_pFont, static_cast<float>(iFontSize),
@@ -255,6 +255,7 @@ void CBC_OnedUPCAWriter::ShowChars(
iLen = tempStr.GetLength();
CalcTextInfo(tempStr, pCharPos + 11, m_pFont, strWidth, iFontSize, blank);
if (pOutBitmap) {
+ delete ge.GetBitmap();
ge.Create((int)strWidth, iTextHeight, FXDIB_Argb, nullptr);
ge.GetBitmap()->Clear(m_backgroundColor);
ge.DrawNormalText(iLen, pCharPos + 11, m_pFont,
diff --git a/xfa/fxbarcode/oned/BC_OnedUPCAWriter.h b/xfa/fxbarcode/oned/BC_OnedUPCAWriter.h
index 6c0929a051..6b786ce3b8 100644
--- a/xfa/fxbarcode/oned/BC_OnedUPCAWriter.h
+++ b/xfa/fxbarcode/oned/BC_OnedUPCAWriter.h
@@ -52,7 +52,7 @@ class CBC_OnedUPCAWriter : public CBC_OneDimWriter {
protected:
void ShowChars(const CFX_WideStringC& contents,
- const CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
+ CFX_DIBitmap* pOutBitmap,
CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t barWidth,
diff --git a/xfa/fxfa/app/xfa_ffimage.cpp b/xfa/fxfa/app/xfa_ffimage.cpp
index 23ed88616d..81188c14d1 100644
--- a/xfa/fxfa/app/xfa_ffimage.cpp
+++ b/xfa/fxfa/app/xfa_ffimage.cpp
@@ -43,7 +43,7 @@ void CXFA_FFImage::RenderWidget(CFX_Graphics* pGS,
CXFA_FFWidget::RenderWidget(pGS, &mtRotate, dwStatus);
- CFX_RetainPtr<CFX_DIBitmap> pDIBitmap = GetDataAcc()->GetImageImage();
+ CFX_DIBitmap* pDIBitmap = GetDataAcc()->GetImageImage();
if (!pDIBitmap)
return;
diff --git a/xfa/fxfa/app/xfa_ffimageedit.cpp b/xfa/fxfa/app/xfa_ffimageedit.cpp
index 624ef3f442..b776579152 100644
--- a/xfa/fxfa/app/xfa_ffimageedit.cpp
+++ b/xfa/fxfa/app/xfa_ffimageedit.cpp
@@ -60,7 +60,7 @@ void CXFA_FFImageEdit::RenderWidget(CFX_Graphics* pGS,
CXFA_Border borderUI = m_pDataAcc->GetUIBorder();
DrawBorder(pGS, borderUI, m_rtUI, &mtRotate);
RenderCaption(pGS, &mtRotate);
- CFX_RetainPtr<CFX_DIBitmap> pDIBitmap = m_pDataAcc->GetImageEditImage();
+ CFX_DIBitmap* pDIBitmap = m_pDataAcc->GetImageEditImage();
if (!pDIBitmap)
return;
diff --git a/xfa/fxfa/cxfa_ffdoc.cpp b/xfa/fxfa/cxfa_ffdoc.cpp
index e14500a725..fdeacf7f0f 100644
--- a/xfa/fxfa/cxfa_ffdoc.cpp
+++ b/xfa/fxfa/cxfa_ffdoc.cpp
@@ -332,6 +332,10 @@ bool CXFA_FFDoc::CloseDoc() {
m_DocView.reset();
m_pNotify.reset(nullptr);
m_pApp->GetXFAFontMgr()->ReleaseDocFonts(this);
+
+ for (const auto& pair : m_HashToDibDpiMap)
+ delete pair.second.pDibSource;
+
m_HashToDibDpiMap.clear();
m_pApp->ClearEventTargets();
return true;
@@ -341,10 +345,9 @@ CPDF_Document* CXFA_FFDoc::GetPDFDoc() {
return m_pPDFDoc;
}
-CFX_RetainPtr<CFX_DIBitmap> CXFA_FFDoc::GetPDFNamedImage(
- const CFX_WideStringC& wsName,
- int32_t& iImageXDpi,
- int32_t& iImageYDpi) {
+CFX_DIBitmap* CXFA_FFDoc::GetPDFNamedImage(const CFX_WideStringC& wsName,
+ int32_t& iImageXDpi,
+ int32_t& iImageYDpi) {
if (!m_pPDFDoc)
return nullptr;
@@ -353,7 +356,7 @@ CFX_RetainPtr<CFX_DIBitmap> CXFA_FFDoc::GetPDFNamedImage(
if (it != m_HashToDibDpiMap.end()) {
iImageXDpi = it->second.iImageXDpi;
iImageYDpi = it->second.iImageYDpi;
- return it->second.pDibSource.As<CFX_DIBitmap>();
+ return static_cast<CFX_DIBitmap*>(it->second.pDibSource);
}
CPDF_Dictionary* pRoot = m_pPDFDoc->GetRoot();
@@ -393,7 +396,7 @@ CFX_RetainPtr<CFX_DIBitmap> CXFA_FFDoc::GetPDFNamedImage(
IFX_MemoryStream::Create((uint8_t*)streamAcc.GetData(),
streamAcc.GetSize());
- CFX_RetainPtr<CFX_DIBitmap> pDibSource = XFA_LoadImageFromBuffer(
+ CFX_DIBitmap* pDibSource = XFA_LoadImageFromBuffer(
pImageFileRead, FXCODEC_IMAGE_UNKNOWN, iImageXDpi, iImageYDpi);
m_HashToDibDpiMap[dwHash] = {pDibSource, iImageXDpi, iImageYDpi};
return pDibSource;
diff --git a/xfa/fxfa/cxfa_ffdoc.h b/xfa/fxfa/cxfa_ffdoc.h
index 80dafba029..1d46387a5e 100644
--- a/xfa/fxfa/cxfa_ffdoc.h
+++ b/xfa/fxfa/cxfa_ffdoc.h
@@ -20,30 +20,11 @@ class CXFA_FFNotify;
class CXFA_FFDocView;
struct FX_IMAGEDIB_AND_DPI {
- FX_IMAGEDIB_AND_DPI();
- FX_IMAGEDIB_AND_DPI(const FX_IMAGEDIB_AND_DPI& that);
- FX_IMAGEDIB_AND_DPI(const CFX_RetainPtr<CFX_DIBSource>& pDib,
- int32_t xDpi,
- int32_t yDpi);
- ~FX_IMAGEDIB_AND_DPI();
-
- CFX_RetainPtr<CFX_DIBSource> pDibSource;
+ CFX_DIBSource* pDibSource;
int32_t iImageXDpi;
int32_t iImageYDpi;
};
-inline FX_IMAGEDIB_AND_DPI::FX_IMAGEDIB_AND_DPI() = default;
-inline FX_IMAGEDIB_AND_DPI::FX_IMAGEDIB_AND_DPI(
- const FX_IMAGEDIB_AND_DPI& that) = default;
-
-inline FX_IMAGEDIB_AND_DPI::FX_IMAGEDIB_AND_DPI(
- const CFX_RetainPtr<CFX_DIBSource>& pDib,
- int32_t xDpi,
- int32_t yDpi)
- : pDibSource(pDib), iImageXDpi(xDpi), iImageYDpi(yDpi) {}
-
-inline FX_IMAGEDIB_AND_DPI::~FX_IMAGEDIB_AND_DPI() = default;
-
class CXFA_FFDoc {
public:
CXFA_FFDoc(CXFA_FFApp* pApp, IXFA_DocEnvironment* pDocEnvironment);
@@ -67,9 +48,9 @@ class CXFA_FFDoc {
CXFA_FFDocView* GetDocView(CXFA_LayoutProcessor* pLayout);
CXFA_FFDocView* GetDocView();
CPDF_Document* GetPDFDoc();
- CFX_RetainPtr<CFX_DIBitmap> GetPDFNamedImage(const CFX_WideStringC& wsName,
- int32_t& iImageXDpi,
- int32_t& iImageYDpi);
+ CFX_DIBitmap* GetPDFNamedImage(const CFX_WideStringC& wsName,
+ int32_t& iImageXDpi,
+ int32_t& iImageYDpi);
bool SavePackage(XFA_HashCode code,
const CFX_RetainPtr<IFX_SeekableWriteStream>& pFile,
diff --git a/xfa/fxfa/cxfa_ffwidget.cpp b/xfa/fxfa/cxfa_ffwidget.cpp
index 2e9c9a6ac8..504ce70ad9 100644
--- a/xfa/fxfa/cxfa_ffwidget.cpp
+++ b/xfa/fxfa/cxfa_ffwidget.cpp
@@ -558,7 +558,7 @@ class CXFA_ImageRenderer {
~CXFA_ImageRenderer();
bool Start(CFX_RenderDevice* pDevice,
- const CFX_RetainPtr<CFX_DIBSource>& pDIBSource,
+ CFX_DIBSource* pDIBSource,
FX_ARGB bitmap_argb,
int bitmap_alpha,
const CFX_Matrix* pImage2Device,
@@ -568,7 +568,7 @@ class CXFA_ImageRenderer {
protected:
bool StartDIBSource();
- void CompositeDIBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap,
+ void CompositeDIBitmap(CFX_DIBitmap* pDIBitmap,
int left,
int top,
FX_ARGB mask_argb,
@@ -579,8 +579,8 @@ class CXFA_ImageRenderer {
CFX_RenderDevice* m_pDevice;
int m_Status;
CFX_Matrix m_ImageMatrix;
- CFX_RetainPtr<CFX_DIBSource> m_pDIBSource;
- CFX_RetainPtr<CFX_DIBitmap> m_pCloneConvert;
+ CFX_DIBSource* m_pDIBSource;
+ std::unique_ptr<CFX_DIBitmap> m_pCloneConvert;
int m_BitmapAlpha;
FX_ARGB m_FillArgb;
uint32_t m_Flags;
@@ -594,6 +594,7 @@ class CXFA_ImageRenderer {
CXFA_ImageRenderer::CXFA_ImageRenderer()
: m_pDevice(nullptr),
m_Status(0),
+ m_pDIBSource(nullptr),
m_BitmapAlpha(255),
m_FillArgb(0),
m_Flags(0),
@@ -608,7 +609,7 @@ CXFA_ImageRenderer::~CXFA_ImageRenderer() {
}
bool CXFA_ImageRenderer::Start(CFX_RenderDevice* pDevice,
- const CFX_RetainPtr<CFX_DIBSource>& pDIBSource,
+ CFX_DIBSource* pDIBSource,
FX_ARGB bitmap_argb,
int bitmap_alpha,
const CFX_Matrix* pImage2Device,
@@ -644,7 +645,7 @@ bool CXFA_ImageRenderer::StartDIBSource() {
m_Result = false;
return false;
}
- CFX_RetainPtr<CFX_DIBSource> pDib = m_pDIBSource;
+ CFX_DIBSource* pDib = m_pDIBSource;
if (m_pDIBSource->HasAlpha() &&
!(m_pDevice->GetRenderCaps() & FXRC_ALPHA_IMAGE) &&
!(m_pDevice->GetRenderCaps() & FXRC_GET_BITS)) {
@@ -653,13 +654,13 @@ bool CXFA_ImageRenderer::StartDIBSource() {
m_Result = false;
return false;
}
- pDib = m_pCloneConvert;
+ pDib = m_pCloneConvert.get();
}
FX_RECT clip_box = m_pDevice->GetClipBox();
clip_box.Intersect(image_rect);
m_Status = 2;
- m_pTransformer = pdfium::MakeUnique<CFX_ImageTransformer>(
- pDib, &m_ImageMatrix, m_Flags, &clip_box);
+ m_pTransformer.reset(
+ new CFX_ImageTransformer(pDib, &m_ImageMatrix, m_Flags, &clip_box));
m_pTransformer->Start();
return true;
}
@@ -699,11 +700,11 @@ bool CXFA_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) {
- CompositeDIBitmap(pStretched, dest_rect.left, dest_rect.top, m_FillArgb,
- m_BitmapAlpha, m_BlendType, false);
+ CompositeDIBitmap(pStretched.get(), dest_rect.left, dest_rect.top,
+ m_FillArgb, m_BitmapAlpha, m_BlendType, false);
}
return false;
}
@@ -713,7 +714,7 @@ bool CXFA_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;
@@ -721,14 +722,14 @@ bool CXFA_ImageRenderer::Continue(IFX_Pause* pPause) {
if (m_BitmapAlpha != 255)
m_FillArgb = FXARGB_MUL_ALPHA(m_FillArgb, m_BitmapAlpha);
m_Result =
- m_pDevice->SetBitMask(pBitmap, m_pTransformer->result().left,
+ m_pDevice->SetBitMask(pBitmap.get(), m_pTransformer->result().left,
m_pTransformer->result().top, m_FillArgb);
} else {
if (m_BitmapAlpha != 255)
pBitmap->MultiplyAlpha(m_BitmapAlpha);
m_Result = 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;
}
@@ -738,14 +739,13 @@ bool CXFA_ImageRenderer::Continue(IFX_Pause* pPause) {
return false;
}
-void CXFA_ImageRenderer::CompositeDIBitmap(
- const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap,
- int left,
- int top,
- FX_ARGB mask_argb,
- int bitmap_alpha,
- int blend_mode,
- int Transparency) {
+void CXFA_ImageRenderer::CompositeDIBitmap(CFX_DIBitmap* pDIBitmap,
+ int left,
+ int top,
+ FX_ARGB mask_argb,
+ int bitmap_alpha,
+ int blend_mode,
+ int Transparency) {
if (!pDIBitmap) {
return;
}
@@ -785,10 +785,10 @@ void CXFA_ImageRenderer::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;
@@ -803,7 +803,7 @@ void CXFA_ImageRenderer::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;
@@ -817,14 +817,14 @@ void CXFA_ImageRenderer::CompositeDIBitmap(
(m_pDevice->GetRenderCaps() & FXRC_ALPHA_IMAGE)) {
return;
}
- CFX_RetainPtr<CFX_DIBitmap> pCloneConvert =
+ std::unique_ptr<CFX_DIBitmap> pCloneConvert =
pDIBitmap->CloneConvert(FXDIB_Rgb);
if (!pCloneConvert)
return;
CXFA_ImageRenderer imageRender;
- if (!imageRender.Start(m_pDevice, pCloneConvert, m_FillArgb, m_BitmapAlpha,
- &m_ImageMatrix, m_Flags)) {
+ if (!imageRender.Start(m_pDevice, pCloneConvert.get(), m_FillArgb,
+ m_BitmapAlpha, &m_ImageMatrix, m_Flags)) {
return;
}
while (imageRender.Continue(nullptr))
@@ -834,7 +834,7 @@ void CXFA_ImageRenderer::CompositeDIBitmap(
void XFA_DrawImage(CFX_Graphics* pGS,
const CFX_RectF& rtImage,
CFX_Matrix* pMatrix,
- const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap,
+ CFX_DIBitmap* pDIBitmap,
int32_t iAspect,
int32_t iImageXDpi,
int32_t iImageYDpi,
@@ -1034,19 +1034,18 @@ FXCODEC_IMAGE_TYPE XFA_GetImageType(const CFX_WideString& wsType) {
return FXCODEC_IMAGE_TIF;
return FXCODEC_IMAGE_UNKNOWN;
}
-
-CFX_RetainPtr<CFX_DIBitmap> XFA_LoadImageData(CXFA_FFDoc* pDoc,
- CXFA_Image* pImage,
- bool& bNameImage,
- int32_t& iImageXDpi,
- int32_t& iImageYDpi) {
+CFX_DIBitmap* XFA_LoadImageData(CXFA_FFDoc* pDoc,
+ CXFA_Image* pImage,
+ bool& bNameImage,
+ int32_t& iImageXDpi,
+ int32_t& iImageYDpi) {
CFX_WideString wsHref;
- CFX_WideString wsImage;
pImage->GetHref(wsHref);
+ CFX_WideString wsImage;
pImage->GetContent(wsImage);
- if (wsHref.IsEmpty() && wsImage.IsEmpty())
+ if (wsHref.IsEmpty() && wsImage.IsEmpty()) {
return nullptr;
-
+ }
CFX_WideString wsContentType;
pImage->GetContentType(wsContentType);
FXCODEC_IMAGE_TYPE type = XFA_GetImageType(wsContentType);
@@ -1072,7 +1071,7 @@ CFX_RetainPtr<CFX_DIBitmap> XFA_LoadImageData(CXFA_FFDoc* pDoc,
} else {
CFX_WideString wsURL = wsHref;
if (wsURL.Left(7) != L"http://" && wsURL.Left(6) != L"ftp://") {
- CFX_RetainPtr<CFX_DIBitmap> pBitmap =
+ CFX_DIBitmap* pBitmap =
pDoc->GetPDFNamedImage(wsURL.AsStringC(), iImageXDpi, iImageYDpi);
if (pBitmap) {
bNameImage = true;
@@ -1086,7 +1085,7 @@ CFX_RetainPtr<CFX_DIBitmap> XFA_LoadImageData(CXFA_FFDoc* pDoc,
return nullptr;
}
bNameImage = false;
- CFX_RetainPtr<CFX_DIBitmap> pBitmap =
+ CFX_DIBitmap* pBitmap =
XFA_LoadImageFromBuffer(pImageFileRead, type, iImageXDpi, iImageYDpi);
FX_Free(pImageBuffer);
return pBitmap;
@@ -1112,7 +1111,7 @@ static FXDIB_Format XFA_GetDIBFormat(FXCODEC_IMAGE_TYPE type,
return dibFormat;
}
-CFX_RetainPtr<CFX_DIBitmap> XFA_LoadImageFromBuffer(
+CFX_DIBitmap* XFA_LoadImageFromBuffer(
const CFX_RetainPtr<IFX_SeekableReadStream>& pImageFileRead,
FXCODEC_IMAGE_TYPE type,
int32_t& iImageXDpi,
@@ -1126,7 +1125,7 @@ CFX_RetainPtr<CFX_DIBitmap> XFA_LoadImageFromBuffer(
return nullptr;
CFX_DIBAttribute dibAttr;
- CFX_RetainPtr<CFX_DIBitmap> pBitmap;
+ CFX_DIBitmap* pBitmap = nullptr;
std::unique_ptr<CCodec_ProgressiveDecoder> pProgressiveDecoder =
pCodecMgr->CreateProgressiveDecoder();
pProgressiveDecoder->LoadImageInfo(pImageFileRead, type, &dibAttr, false);
@@ -1150,7 +1149,7 @@ CFX_RetainPtr<CFX_DIBitmap> XFA_LoadImageFromBuffer(
int32_t iComponents = pProgressiveDecoder->GetNumComponents();
int32_t iBpc = pProgressiveDecoder->GetBPC();
FXDIB_Format dibFormat = XFA_GetDIBFormat(type, iComponents, iBpc);
- pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ pBitmap = new CFX_DIBitmap();
pBitmap->Create(pProgressiveDecoder->GetWidth(),
pProgressiveDecoder->GetHeight(), dibFormat);
pBitmap->Clear(0xffffffff);
diff --git a/xfa/fxfa/cxfa_ffwidget.h b/xfa/fxfa/cxfa_ffwidget.h
index 8c83c4cf4c..02a7b21b15 100644
--- a/xfa/fxfa/cxfa_ffwidget.h
+++ b/xfa/fxfa/cxfa_ffwidget.h
@@ -41,20 +41,20 @@ CFX_GraphStateData::LineCap XFA_LineCapToFXGE(int32_t iLineCap);
void XFA_DrawImage(CFX_Graphics* pGS,
const CFX_RectF& rtImage,
CFX_Matrix* pMatrix,
- const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap,
+ CFX_DIBitmap* pDIBitmap,
int32_t iAspect,
int32_t iImageXDpi,
int32_t iImageYDpi,
int32_t iHorzAlign = XFA_ATTRIBUTEENUM_Left,
int32_t iVertAlign = XFA_ATTRIBUTEENUM_Top);
-CFX_RetainPtr<CFX_DIBitmap> XFA_LoadImageData(CXFA_FFDoc* pDoc,
- CXFA_Image* pImage,
- bool& bNameImage,
- int32_t& iImageXDpi,
- int32_t& iImageYDpi);
+CFX_DIBitmap* XFA_LoadImageData(CXFA_FFDoc* pDoc,
+ CXFA_Image* pImage,
+ bool& bNameImage,
+ int32_t& iImageXDpi,
+ int32_t& iImageYDpi);
-CFX_RetainPtr<CFX_DIBitmap> XFA_LoadImageFromBuffer(
+CFX_DIBitmap* XFA_LoadImageFromBuffer(
const CFX_RetainPtr<IFX_SeekableReadStream>& pImageFileRead,
FXCODEC_IMAGE_TYPE type,
int32_t& iImageXDpi,
diff --git a/xfa/fxfa/cxfa_widgetacc.cpp b/xfa/fxfa/cxfa_widgetacc.cpp
index 6e76119115..4c8e37291a 100644
--- a/xfa/fxfa/cxfa_widgetacc.cpp
+++ b/xfa/fxfa/cxfa_widgetacc.cpp
@@ -67,9 +67,15 @@ class CXFA_TextLayoutData : public CXFA_WidgetLayoutData {
class CXFA_ImageLayoutData : public CXFA_WidgetLayoutData {
public:
CXFA_ImageLayoutData()
- : m_bNamedImage(false), m_iImageXDpi(0), m_iImageYDpi(0) {}
+ : m_pDIBitmap(nullptr),
+ m_bNamedImage(false),
+ m_iImageXDpi(0),
+ m_iImageYDpi(0) {}
- ~CXFA_ImageLayoutData() override {}
+ ~CXFA_ImageLayoutData() override {
+ if (m_pDIBitmap && !m_bNamedImage)
+ delete m_pDIBitmap;
+ }
bool LoadImageData(CXFA_WidgetAcc* pAcc) {
if (m_pDIBitmap)
@@ -89,7 +95,7 @@ class CXFA_ImageLayoutData : public CXFA_WidgetLayoutData {
return !!m_pDIBitmap;
}
- CFX_RetainPtr<CFX_DIBitmap> m_pDIBitmap;
+ CFX_DIBitmap* m_pDIBitmap;
bool m_bNamedImage;
int32_t m_iImageXDpi;
int32_t m_iImageYDpi;
@@ -126,9 +132,15 @@ class CXFA_TextEditData : public CXFA_FieldLayoutData {
class CXFA_ImageEditData : public CXFA_FieldLayoutData {
public:
CXFA_ImageEditData()
- : m_bNamedImage(false), m_iImageXDpi(0), m_iImageYDpi(0) {}
+ : m_pDIBitmap(nullptr),
+ m_bNamedImage(false),
+ m_iImageXDpi(0),
+ m_iImageYDpi(0) {}
- ~CXFA_ImageEditData() override {}
+ ~CXFA_ImageEditData() override {
+ if (m_pDIBitmap && !m_bNamedImage)
+ delete m_pDIBitmap;
+ }
bool LoadImageData(CXFA_WidgetAcc* pAcc) {
if (m_pDIBitmap)
@@ -145,7 +157,7 @@ class CXFA_ImageEditData : public CXFA_FieldLayoutData {
return !!m_pDIBitmap;
}
- CFX_RetainPtr<CFX_DIBitmap> m_pDIBitmap;
+ CFX_DIBitmap* m_pDIBitmap;
bool m_bNamedImage;
int32_t m_iImageXDpi;
int32_t m_iImageYDpi;
@@ -917,8 +929,7 @@ bool CXFA_WidgetAcc::CalculateImageAutoSize(CFX_SizeF& size) {
LoadImageImage();
size.clear();
- CFX_RetainPtr<CFX_DIBitmap> pBitmap = GetImageImage();
- if (pBitmap) {
+ if (CFX_DIBitmap* pBitmap = GetImageImage()) {
int32_t iImageXDpi = 0;
int32_t iImageYDpi = 0;
GetImageDpi(iImageXDpi, iImageYDpi);
@@ -947,8 +958,7 @@ bool CXFA_WidgetAcc::CalculateImageEditAutoSize(CFX_SizeF& size) {
LoadImageEditImage();
size.clear();
- CFX_RetainPtr<CFX_DIBitmap> pBitmap = GetImageEditImage();
- if (pBitmap) {
+ if (CFX_DIBitmap* pBitmap = GetImageEditImage()) {
int32_t iImageXDpi = 0;
int32_t iImageYDpi = 0;
GetImageEditDpi(iImageXDpi, iImageYDpi);
@@ -1457,34 +1467,42 @@ CXFA_TextLayout* CXFA_WidgetAcc::GetTextLayout() {
: nullptr;
}
-CFX_RetainPtr<CFX_DIBitmap> CXFA_WidgetAcc::GetImageImage() {
+CFX_DIBitmap* CXFA_WidgetAcc::GetImageImage() {
return m_pLayoutData
? static_cast<CXFA_ImageLayoutData*>(m_pLayoutData.get())
->m_pDIBitmap
: nullptr;
}
-CFX_RetainPtr<CFX_DIBitmap> CXFA_WidgetAcc::GetImageEditImage() {
+CFX_DIBitmap* CXFA_WidgetAcc::GetImageEditImage() {
return m_pLayoutData
? static_cast<CXFA_ImageEditData*>(m_pLayoutData.get())
->m_pDIBitmap
: nullptr;
}
-void CXFA_WidgetAcc::SetImageImage(
- const CFX_RetainPtr<CFX_DIBitmap>& newImage) {
+void CXFA_WidgetAcc::SetImageImage(CFX_DIBitmap* newImage) {
CXFA_ImageLayoutData* pData =
static_cast<CXFA_ImageLayoutData*>(m_pLayoutData.get());
- if (pData->m_pDIBitmap != newImage)
- pData->m_pDIBitmap = newImage;
+ if (pData->m_pDIBitmap == newImage)
+ return;
+
+ if (pData->m_pDIBitmap && !pData->m_bNamedImage)
+ delete pData->m_pDIBitmap;
+
+ pData->m_pDIBitmap = newImage;
}
-void CXFA_WidgetAcc::SetImageEditImage(
- const CFX_RetainPtr<CFX_DIBitmap>& newImage) {
+void CXFA_WidgetAcc::SetImageEditImage(CFX_DIBitmap* newImage) {
CXFA_ImageEditData* pData =
static_cast<CXFA_ImageEditData*>(m_pLayoutData.get());
- if (pData->m_pDIBitmap != newImage)
- pData->m_pDIBitmap = newImage;
+ if (pData->m_pDIBitmap == newImage)
+ return;
+
+ if (pData->m_pDIBitmap && !pData->m_bNamedImage)
+ delete pData->m_pDIBitmap;
+
+ pData->m_pDIBitmap = newImage;
}
CXFA_WidgetLayoutData* CXFA_WidgetAcc::GetWidgetLayoutData() {
diff --git a/xfa/fxfa/cxfa_widgetacc.h b/xfa/fxfa/cxfa_widgetacc.h
index c08aa1d587..8a7a7eb73d 100644
--- a/xfa/fxfa/cxfa_widgetacc.h
+++ b/xfa/fxfa/cxfa_widgetacc.h
@@ -69,10 +69,10 @@ class CXFA_WidgetAcc : public CXFA_WidgetData {
void GetImageEditDpi(int32_t& iImageXDpi, int32_t& iImageYDpi);
CXFA_TextLayout* GetCaptionTextLayout();
CXFA_TextLayout* GetTextLayout();
- CFX_RetainPtr<CFX_DIBitmap> GetImageImage();
- CFX_RetainPtr<CFX_DIBitmap> GetImageEditImage();
- void SetImageImage(const CFX_RetainPtr<CFX_DIBitmap>& newImage);
- void SetImageEditImage(const CFX_RetainPtr<CFX_DIBitmap>& newImage);
+ CFX_DIBitmap* GetImageImage();
+ CFX_DIBitmap* GetImageEditImage();
+ void SetImageImage(CFX_DIBitmap* newImage);
+ void SetImageEditImage(CFX_DIBitmap* newImage);
void UpdateUIDisplay(CXFA_FFWidget* pExcept = nullptr);
CXFA_Node* GetDatasets();
diff --git a/xfa/fxgraphics/cfx_graphics.cpp b/xfa/fxgraphics/cfx_graphics.cpp
index 3cfe2d0192..48d8f6f80f 100644
--- a/xfa/fxgraphics/cfx_graphics.cpp
+++ b/xfa/fxgraphics/cfx_graphics.cpp
@@ -198,7 +198,7 @@ void CFX_Graphics::FillPath(CFX_Path* path,
RenderDeviceFillPath(path, fillMode, matrix);
}
-void CFX_Graphics::StretchImage(const CFX_RetainPtr<CFX_DIBSource>& source,
+void CFX_Graphics::StretchImage(CFX_DIBSource* source,
const CFX_RectF& rect,
CFX_Matrix* matrix) {
if (!source)
@@ -318,49 +318,48 @@ void CFX_Graphics::RenderDeviceFillPath(CFX_Path* path,
}
}
-void CFX_Graphics::RenderDeviceStretchImage(
- const CFX_RetainPtr<CFX_DIBSource>& source,
- const CFX_RectF& rect,
- CFX_Matrix* matrix) {
+void CFX_Graphics::RenderDeviceStretchImage(CFX_DIBSource* source,
+ const CFX_RectF& rect,
+ CFX_Matrix* matrix) {
CFX_Matrix m1(m_info.CTM.a, m_info.CTM.b, m_info.CTM.c, m_info.CTM.d,
m_info.CTM.e, m_info.CTM.f);
if (matrix) {
m1.Concat(*matrix);
}
- CFX_RetainPtr<CFX_DIBitmap> bmp1 =
+ std::unique_ptr<CFX_DIBitmap> bmp1 =
source->StretchTo((int32_t)rect.Width(), (int32_t)rect.Height());
CFX_Matrix m2(rect.Width(), 0.0, 0.0, rect.Height(), rect.left, rect.top);
m2.Concat(m1);
int32_t left;
int32_t top;
- CFX_RetainPtr<CFX_DIBitmap> bmp2 = bmp1->FlipImage(false, true);
- CFX_RetainPtr<CFX_DIBitmap> bmp3 = bmp2->TransformTo(&m2, left, top);
+ std::unique_ptr<CFX_DIBitmap> bmp2 = bmp1->FlipImage(false, true);
+ std::unique_ptr<CFX_DIBitmap> bmp3 = bmp2->TransformTo(&m2, left, top);
CFX_RectF r = GetClipRect();
- CFX_RetainPtr<CFX_DIBitmap> bitmap = m_renderDevice->GetBitmap();
+ CFX_DIBitmap* bitmap = m_renderDevice->GetBitmap();
bitmap->CompositeBitmap(FXSYS_round(r.left), FXSYS_round(r.top),
- FXSYS_round(r.Width()), FXSYS_round(r.Height()), bmp3,
- FXSYS_round(r.left - left), FXSYS_round(r.top - top));
+ FXSYS_round(r.Width()), FXSYS_round(r.Height()),
+ bmp3.get(), FXSYS_round(r.left - left),
+ FXSYS_round(r.top - top));
}
void CFX_Graphics::FillPathWithPattern(CFX_Path* path,
FX_FillMode fillMode,
CFX_Matrix* matrix) {
CFX_Pattern* pattern = m_info.fillColor->m_info.pattern;
- CFX_RetainPtr<CFX_DIBitmap> bitmap = m_renderDevice->GetBitmap();
+ CFX_DIBitmap* bitmap = m_renderDevice->GetBitmap();
int32_t width = bitmap->GetWidth();
int32_t height = bitmap->GetHeight();
- auto bmp = pdfium::MakeRetain<CFX_DIBitmap>();
- bmp->Create(width, height, FXDIB_Argb);
- m_renderDevice->GetDIBits(bmp, 0, 0);
+ CFX_DIBitmap bmp;
+ bmp.Create(width, height, FXDIB_Argb);
+ m_renderDevice->GetDIBits(&bmp, 0, 0);
FX_HatchStyle hatchStyle = m_info.fillColor->m_info.pattern->m_hatchStyle;
const FX_HATCHDATA& data = hatchBitmapData[static_cast<int>(hatchStyle)];
- auto mask = pdfium::MakeRetain<CFX_DIBitmap>();
- mask->Create(data.width, data.height, FXDIB_1bppMask);
- FXSYS_memcpy(mask->GetBuffer(), data.maskBits,
- mask->GetPitch() * data.height);
+ CFX_DIBitmap mask;
+ mask.Create(data.width, data.height, FXDIB_1bppMask);
+ FXSYS_memcpy(mask.GetBuffer(), data.maskBits, mask.GetPitch() * data.height);
CFX_FloatRect rectf = path->GetPathData()->GetBoundingBox();
if (matrix)
matrix->TransformRect(rectf);
@@ -368,35 +367,35 @@ void CFX_Graphics::FillPathWithPattern(CFX_Path* path,
FX_RECT rect(FXSYS_round(rectf.left), FXSYS_round(rectf.top),
FXSYS_round(rectf.right), FXSYS_round(rectf.bottom));
CFX_FxgeDevice device;
- device.Attach(bmp, false, nullptr, false);
+ device.Attach(&bmp, false, nullptr, false);
device.FillRect(&rect, m_info.fillColor->m_info.pattern->m_backArgb);
- for (int32_t j = rect.bottom; j < rect.top; j += mask->GetHeight()) {
- for (int32_t i = rect.left; i < rect.right; i += mask->GetWidth()) {
- device.SetBitMask(mask, i, j,
+ for (int32_t j = rect.bottom; j < rect.top; j += mask.GetHeight()) {
+ for (int32_t i = rect.left; i < rect.right; i += mask.GetWidth()) {
+ device.SetBitMask(&mask, i, j,
m_info.fillColor->m_info.pattern->m_foreArgb);
}
}
m_renderDevice->SaveState();
m_renderDevice->SetClip_PathFill(path->GetPathData(), matrix, fillMode);
- SetDIBitsWithMatrix(bmp, &pattern->m_matrix);
+ SetDIBitsWithMatrix(&bmp, &pattern->m_matrix);
m_renderDevice->RestoreState(false);
}
void CFX_Graphics::FillPathWithShading(CFX_Path* path,
FX_FillMode fillMode,
CFX_Matrix* matrix) {
- CFX_RetainPtr<CFX_DIBitmap> bitmap = m_renderDevice->GetBitmap();
+ CFX_DIBitmap* bitmap = m_renderDevice->GetBitmap();
int32_t width = bitmap->GetWidth();
int32_t height = bitmap->GetHeight();
float start_x = m_info.fillColor->m_shading->m_beginPoint.x;
float start_y = m_info.fillColor->m_shading->m_beginPoint.y;
float end_x = m_info.fillColor->m_shading->m_endPoint.x;
float end_y = m_info.fillColor->m_shading->m_endPoint.y;
- auto bmp = pdfium::MakeRetain<CFX_DIBitmap>();
- bmp->Create(width, height, FXDIB_Argb);
- m_renderDevice->GetDIBits(bmp, 0, 0);
- int32_t pitch = bmp->GetPitch();
+ CFX_DIBitmap bmp;
+ bmp.Create(width, height, FXDIB_Argb);
+ m_renderDevice->GetDIBits(&bmp, 0, 0);
+ int32_t pitch = bmp.GetPitch();
bool result = false;
switch (m_info.fillColor->m_shading->m_type) {
case FX_SHADING_Axial: {
@@ -404,7 +403,7 @@ void CFX_Graphics::FillPathWithShading(CFX_Path* path,
float y_span = end_y - start_y;
float axis_len_square = (x_span * x_span) + (y_span * y_span);
for (int32_t row = 0; row < height; row++) {
- uint32_t* dib_buf = (uint32_t*)(bmp->GetBuffer() + row * pitch);
+ uint32_t* dib_buf = (uint32_t*)(bmp.GetBuffer() + row * pitch);
for (int32_t column = 0; column < width; column++) {
float x = (float)(column);
float y = (float)(row);
@@ -435,7 +434,7 @@ void CFX_Graphics::FillPathWithShading(CFX_Path* path,
((start_y - end_y) * (start_y - end_y)) -
((start_r - end_r) * (start_r - end_r));
for (int32_t row = 0; row < height; row++) {
- uint32_t* dib_buf = (uint32_t*)(bmp->GetBuffer() + row * pitch);
+ uint32_t* dib_buf = (uint32_t*)(bmp.GetBuffer() + row * pitch);
for (int32_t column = 0; column < width; column++) {
float x = (float)(column);
float y = (float)(row);
@@ -497,14 +496,13 @@ void CFX_Graphics::FillPathWithShading(CFX_Path* path,
if (result) {
m_renderDevice->SaveState();
m_renderDevice->SetClip_PathFill(path->GetPathData(), matrix, fillMode);
- SetDIBitsWithMatrix(bmp, matrix);
+ SetDIBitsWithMatrix(&bmp, matrix);
m_renderDevice->RestoreState(false);
}
}
-void CFX_Graphics::SetDIBitsWithMatrix(
- const CFX_RetainPtr<CFX_DIBSource>& source,
- CFX_Matrix* matrix) {
+void CFX_Graphics::SetDIBitsWithMatrix(CFX_DIBSource* source,
+ CFX_Matrix* matrix) {
if (matrix->IsIdentity()) {
m_renderDevice->SetDIBits(source, 0, 0);
} else {
@@ -513,9 +511,9 @@ void CFX_Graphics::SetDIBitsWithMatrix(
m.Concat(*matrix);
int32_t left;
int32_t top;
- CFX_RetainPtr<CFX_DIBitmap> bmp1 = source->FlipImage(false, true);
- CFX_RetainPtr<CFX_DIBitmap> bmp2 = bmp1->TransformTo(&m, left, top);
- m_renderDevice->SetDIBits(bmp2, left, top);
+ std::unique_ptr<CFX_DIBitmap> bmp1 = source->FlipImage(false, true);
+ std::unique_ptr<CFX_DIBitmap> bmp2 = bmp1->TransformTo(&m, left, top);
+ m_renderDevice->SetDIBits(bmp2.get(), left, top);
}
}
diff --git a/xfa/fxgraphics/cfx_graphics.h b/xfa/fxgraphics/cfx_graphics.h
index 264ec94d53..c360813401 100644
--- a/xfa/fxgraphics/cfx_graphics.h
+++ b/xfa/fxgraphics/cfx_graphics.h
@@ -64,7 +64,7 @@ class CFX_Graphics {
void FillPath(CFX_Path* path,
FX_FillMode fillMode = FXFILL_WINDING,
CFX_Matrix* matrix = nullptr);
- void StretchImage(const CFX_RetainPtr<CFX_DIBSource>& source,
+ void StretchImage(CFX_DIBSource* source,
const CFX_RectF& rect,
CFX_Matrix* matrix = nullptr);
void ConcatMatrix(const CFX_Matrix* matrix);
@@ -90,7 +90,7 @@ class CFX_Graphics {
void RenderDeviceFillPath(CFX_Path* path,
FX_FillMode fillMode,
CFX_Matrix* matrix);
- void RenderDeviceStretchImage(const CFX_RetainPtr<CFX_DIBSource>& source,
+ void RenderDeviceStretchImage(CFX_DIBSource* source,
const CFX_RectF& rect,
CFX_Matrix* matrix);
@@ -101,8 +101,7 @@ class CFX_Graphics {
FX_FillMode fillMode,
CFX_Matrix* matrix);
- void SetDIBitsWithMatrix(const CFX_RetainPtr<CFX_DIBSource>& source,
- CFX_Matrix* matrix);
+ void SetDIBitsWithMatrix(CFX_DIBSource* source, CFX_Matrix* matrix);
CFX_RenderDevice* m_renderDevice;
std::vector<std::unique_ptr<TInfo>> m_infoStack;