summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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, 1543 insertions, 1478 deletions
diff --git a/core/fpdfapi/font/cpdf_type3char.cpp b/core/fpdfapi/font/cpdf_type3char.cpp
index 5eb12c1752..4f116a1afb 100644
--- a/core/fpdfapi/font/cpdf_type3char.cpp
+++ b/core/fpdfapi/font/cpdf_type3char.cpp
@@ -29,7 +29,7 @@ bool CPDF_Type3Char::LoadBitmap(CPDF_RenderContext* pContext) {
return false;
m_ImageMatrix = pPageObj->AsImage()->matrix();
- std::unique_ptr<CFX_DIBSource> pSource =
+ CFX_RetainPtr<CFX_DIBSource> pSource =
pPageObj->AsImage()->GetImage()->LoadDIBSource();
if (pSource)
m_pBitmap = pSource->Clone();
diff --git a/core/fpdfapi/font/cpdf_type3char.h b/core/fpdfapi/font/cpdf_type3char.h
index 549f49e3da..3215802e0c 100644
--- a/core/fpdfapi/font/cpdf_type3char.h
+++ b/core/fpdfapi/font/cpdf_type3char.h
@@ -25,7 +25,7 @@ class CPDF_Type3Char {
bool LoadBitmap(CPDF_RenderContext* pContext);
std::unique_ptr<CPDF_Form> m_pForm;
- std::unique_ptr<CFX_DIBitmap> m_pBitmap;
+ CFX_RetainPtr<CFX_DIBitmap> m_pBitmap;
bool m_bColored;
int m_Width;
CFX_Matrix m_ImageMatrix;
diff --git a/core/fpdfapi/page/cpdf_generalstate.h b/core/fpdfapi/page/cpdf_generalstate.h
index ddc33ac800..1c5ddee4e0 100644
--- a/core/fpdfapi/page/cpdf_generalstate.h
+++ b/core/fpdfapi/page/cpdf_generalstate.h
@@ -7,6 +7,7 @@
#ifndef CORE_FPDFAPI_PAGE_CPDF_GENERALSTATE_H_
#define CORE_FPDFAPI_PAGE_CPDF_GENERALSTATE_H_
+#include "core/fxcrt/cfx_shared_copy_on_write.h"
#include "core/fxcrt/fx_basic.h"
#include "core/fxcrt/fx_coordinates.h"
#include "core/fxge/fx_dib.h"
diff --git a/core/fpdfapi/page/cpdf_image.cpp b/core/fpdfapi/page/cpdf_image.cpp
index 3de0511771..4fc1c344ef 100644
--- a/core/fpdfapi/page/cpdf_image.cpp
+++ b/core/fpdfapi/page/cpdf_image.cpp
@@ -157,7 +157,7 @@ void CPDF_Image::SetJpegImageInline(
m_pStream->InitStream(&(data[0]), size, std::move(pDict));
}
-void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap) {
+void CPDF_Image::SetImage(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap) {
int32_t BitmapWidth = pBitmap->GetWidth();
int32_t BitmapHeight = pBitmap->GetHeight();
if (BitmapWidth < 1 || BitmapHeight < 1)
@@ -248,7 +248,7 @@ void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap) {
bCopyWithoutAlpha = false;
}
- std::unique_ptr<CFX_DIBitmap> pMaskBitmap;
+ CFX_RetainPtr<CFX_DIBitmap> pMaskBitmap;
if (pBitmap->HasAlpha())
pMaskBitmap = pBitmap->CloneAlphaMask();
@@ -320,28 +320,25 @@ void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap) {
FX_Free(dest_buf);
}
-void CPDF_Image::ResetCache(CPDF_Page* pPage, const CFX_DIBitmap* pBitmap) {
+void CPDF_Image::ResetCache(CPDF_Page* pPage,
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap) {
pPage->GetRenderCache()->ResetBitmap(m_pStream.Get(), pBitmap);
}
-std::unique_ptr<CFX_DIBSource> CPDF_Image::LoadDIBSource() const {
- auto source = pdfium::MakeUnique<CPDF_DIBSource>();
+CFX_RetainPtr<CFX_DIBSource> CPDF_Image::LoadDIBSource() const {
+ auto source = pdfium::MakeRetain<CPDF_DIBSource>();
if (!source->Load(m_pDocument, m_pStream.Get()))
return nullptr;
- return std::move(source);
+ return source;
}
-CFX_DIBSource* CPDF_Image::DetachBitmap() {
- CFX_DIBSource* pBitmap = m_pDIBSource;
- m_pDIBSource = nullptr;
- return pBitmap;
+CFX_RetainPtr<CFX_DIBSource> CPDF_Image::DetachBitmap() {
+ return std::move(m_pDIBSource);
}
-CFX_DIBSource* CPDF_Image::DetachMask() {
- CFX_DIBSource* pBitmap = m_pMask;
- m_pMask = nullptr;
- return pBitmap;
+CFX_RetainPtr<CFX_DIBSource> CPDF_Image::DetachMask() {
+ return std::move(m_pMask);
}
bool CPDF_Image::StartLoadDIBSource(CPDF_Dictionary* pFormResource,
@@ -349,35 +346,33 @@ bool CPDF_Image::StartLoadDIBSource(CPDF_Dictionary* pFormResource,
bool bStdCS,
uint32_t GroupFamily,
bool bLoadMask) {
- auto source = pdfium::MakeUnique<CPDF_DIBSource>();
+ auto source = pdfium::MakeRetain<CPDF_DIBSource>();
int ret = source->StartLoadDIBSource(m_pDocument, m_pStream.Get(), true,
pFormResource, pPageResource, bStdCS,
GroupFamily, bLoadMask);
- if (ret == 2) {
- m_pDIBSource = source.release();
- return true;
- }
if (!ret) {
- m_pDIBSource = nullptr;
+ m_pDIBSource.Reset();
return false;
}
+ m_pDIBSource = source;
+ if (ret == 2)
+ return true;
+
m_pMask = source->DetachMask();
m_MatteColor = source->GetMatteColor();
- m_pDIBSource = source.release();
return false;
}
bool CPDF_Image::Continue(IFX_Pause* pPause) {
- CPDF_DIBSource* pSource = static_cast<CPDF_DIBSource*>(m_pDIBSource);
+ CFX_RetainPtr<CPDF_DIBSource> pSource = m_pDIBSource.As<CPDF_DIBSource>();
int ret = pSource->ContinueLoadDIBSource(pPause);
- if (ret == 2) {
- return true;
- }
if (!ret) {
- delete m_pDIBSource;
- m_pDIBSource = nullptr;
+ m_pDIBSource.Reset();
return false;
}
+ if (ret == 2)
+ return true;
+
m_pMask = pSource->DetachMask();
m_MatteColor = pSource->GetMatteColor();
return false;
diff --git a/core/fpdfapi/page/cpdf_image.h b/core/fpdfapi/page/cpdf_image.h
index 1909498102..5b737e67b9 100644
--- a/core/fpdfapi/page/cpdf_image.h
+++ b/core/fpdfapi/page/cpdf_image.h
@@ -44,25 +44,25 @@ class CPDF_Image {
bool IsMask() const { return m_bIsMask; }
bool IsInterpol() const { return m_bInterpolate; }
- std::unique_ptr<CFX_DIBSource> LoadDIBSource() const;
+ CFX_RetainPtr<CFX_DIBSource> LoadDIBSource() const;
- void SetImage(const CFX_DIBitmap* pDIBitmap);
+ void SetImage(const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap);
void SetJpegImage(const CFX_RetainPtr<IFX_SeekableReadStream>& pFile);
void SetJpegImageInline(const CFX_RetainPtr<IFX_SeekableReadStream>& pFile);
- void ResetCache(CPDF_Page* pPage, const CFX_DIBitmap* pDIBitmap);
-
+ void ResetCache(CPDF_Page* pPage,
+ const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap);
bool StartLoadDIBSource(CPDF_Dictionary* pFormResource,
CPDF_Dictionary* pPageResource,
bool bStdCS = false,
uint32_t GroupFamily = 0,
bool bLoadMask = false);
bool Continue(IFX_Pause* pPause);
- CFX_DIBSource* DetachBitmap();
- CFX_DIBSource* DetachMask();
+ CFX_RetainPtr<CFX_DIBSource> DetachBitmap();
+ CFX_RetainPtr<CFX_DIBSource> DetachMask();
- CFX_DIBSource* m_pDIBSource = nullptr;
- CFX_DIBSource* m_pMask = nullptr;
+ CFX_RetainPtr<CFX_DIBSource> m_pDIBSource;
+ CFX_RetainPtr<CFX_DIBSource> m_pMask;
uint32_t m_MatteColor = 0;
private:
diff --git a/core/fpdfapi/render/cpdf_devicebuffer.cpp b/core/fpdfapi/render/cpdf_devicebuffer.cpp
index b8c174d97e..67641676ae 100644
--- a/core/fpdfapi/render/cpdf_devicebuffer.cpp
+++ b/core/fpdfapi/render/cpdf_devicebuffer.cpp
@@ -50,7 +50,7 @@ bool CPDF_DeviceBuffer::Initialize(CPDF_RenderContext* pContext,
m_Matrix.TransformRect(rect);
FX_RECT bitmap_rect = rect.GetOuterRect();
- m_pBitmap = pdfium::MakeUnique<CFX_DIBitmap>();
+ m_pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
m_pBitmap->Create(bitmap_rect.Width(), bitmap_rect.Height(), FXDIB_Argb);
return true;
}
@@ -58,19 +58,19 @@ bool CPDF_DeviceBuffer::Initialize(CPDF_RenderContext* pContext,
void CPDF_DeviceBuffer::OutputToDevice() {
if (m_pDevice->GetDeviceCaps(FXDC_RENDER_CAPS) & FXRC_GET_BITS) {
if (m_Matrix.a == 1.0f && m_Matrix.d == 1.0f) {
- m_pDevice->SetDIBits(m_pBitmap.get(), m_Rect.left, m_Rect.top);
+ m_pDevice->SetDIBits(m_pBitmap, m_Rect.left, m_Rect.top);
} else {
- m_pDevice->StretchDIBits(m_pBitmap.get(), m_Rect.left, m_Rect.top,
+ m_pDevice->StretchDIBits(m_pBitmap, m_Rect.left, m_Rect.top,
m_Rect.Width(), m_Rect.Height());
}
return;
}
- CFX_DIBitmap buffer;
- m_pDevice->CreateCompatibleBitmap(&buffer, m_pBitmap->GetWidth(),
+ auto pBuffer = pdfium::MakeRetain<CFX_DIBitmap>();
+ m_pDevice->CreateCompatibleBitmap(pBuffer, m_pBitmap->GetWidth(),
m_pBitmap->GetHeight());
- m_pContext->GetBackground(&buffer, m_pObject, nullptr, &m_Matrix);
- buffer.CompositeBitmap(0, 0, buffer.GetWidth(), buffer.GetHeight(),
- m_pBitmap.get(), 0, 0);
- m_pDevice->StretchDIBits(&buffer, m_Rect.left, m_Rect.top, m_Rect.Width(),
+ m_pContext->GetBackground(pBuffer, m_pObject, nullptr, &m_Matrix);
+ pBuffer->CompositeBitmap(0, 0, pBuffer->GetWidth(), pBuffer->GetHeight(),
+ m_pBitmap, 0, 0);
+ m_pDevice->StretchDIBits(pBuffer, m_Rect.left, m_Rect.top, m_Rect.Width(),
m_Rect.Height());
}
diff --git a/core/fpdfapi/render/cpdf_devicebuffer.h b/core/fpdfapi/render/cpdf_devicebuffer.h
index e5bbf1fcdf..61cdc9776b 100644
--- a/core/fpdfapi/render/cpdf_devicebuffer.h
+++ b/core/fpdfapi/render/cpdf_devicebuffer.h
@@ -26,7 +26,7 @@ class CPDF_DeviceBuffer {
const CPDF_PageObject* pObj,
int max_dpi);
void OutputToDevice();
- CFX_DIBitmap* GetBitmap() const { return m_pBitmap.get(); }
+ CFX_RetainPtr<CFX_DIBitmap> GetBitmap() const { return m_pBitmap; }
const CFX_Matrix* GetMatrix() const { return &m_Matrix; }
private:
@@ -34,7 +34,7 @@ class CPDF_DeviceBuffer {
CPDF_RenderContext* m_pContext;
FX_RECT m_Rect;
const CPDF_PageObject* m_pObject;
- std::unique_ptr<CFX_DIBitmap> m_pBitmap;
+ CFX_RetainPtr<CFX_DIBitmap> m_pBitmap;
CFX_Matrix m_Matrix;
};
diff --git a/core/fpdfapi/render/cpdf_dibsource.cpp b/core/fpdfapi/render/cpdf_dibsource.cpp
index 899a783c47..f3703dd23a 100644
--- a/core/fpdfapi/render/cpdf_dibsource.cpp
+++ b/core/fpdfapi/render/cpdf_dibsource.cpp
@@ -8,6 +8,7 @@
#include <algorithm>
#include <memory>
+#include <utility>
#include <vector>
#include "core/fpdfapi/cpdf_modulemgr.h"
@@ -126,12 +127,11 @@ CPDF_DIBSource::CPDF_DIBSource()
CPDF_DIBSource::~CPDF_DIBSource() {
FX_Free(m_pMaskedLine);
FX_Free(m_pLineBuf);
- m_pCachedBitmap.reset();
+ m_pCachedBitmap.Reset(); // TODO(tsepez): determine if required early here.
FX_Free(m_pCompData);
CPDF_ColorSpace* pCS = m_pColorSpace;
- if (pCS && m_pDocument) {
+ if (pCS && m_pDocument)
m_pDocument->GetPageData()->ReleaseColorSpace(pCS->GetArray());
- }
}
bool CPDF_DIBSource::Load(CPDF_Document* pDoc, const CPDF_Stream* pStream) {
@@ -332,7 +332,7 @@ int CPDF_DIBSource::ContinueLoadDIBSource(IFX_Pause* pPause) {
m_pStreamAcc.get(), m_pGlobalStream.get(),
m_pCachedBitmap->GetBuffer(), m_pCachedBitmap->GetPitch(), pPause);
if (ret < 0) {
- m_pCachedBitmap.reset();
+ m_pCachedBitmap.Reset();
m_pGlobalStream.reset();
m_pJbig2Context.reset();
return 0;
@@ -355,7 +355,7 @@ int CPDF_DIBSource::ContinueLoadDIBSource(IFX_Pause* pPause) {
}
ret = pJbig2Module->ContinueDecode(m_pJbig2Context.get(), pPause);
if (ret < 0) {
- m_pCachedBitmap.reset();
+ m_pCachedBitmap.Reset();
m_pGlobalStream.reset();
m_pJbig2Context.reset();
return 0;
@@ -507,10 +507,10 @@ int CPDF_DIBSource::CreateDecoder() {
return m_pCachedBitmap ? 1 : 0;
}
if (decoder == "JBIG2Decode") {
- m_pCachedBitmap = pdfium::MakeUnique<CFX_DIBitmap>();
+ m_pCachedBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
if (!m_pCachedBitmap->Create(
m_Width, m_Height, m_bImageMask ? FXDIB_1bppMask : FXDIB_1bppRgb)) {
- m_pCachedBitmap.reset();
+ m_pCachedBitmap.Reset();
return 0;
}
m_Status = 1;
@@ -656,9 +656,9 @@ void CPDF_DIBSource::LoadJpxBitmap() {
format = FXDIB_Rgb;
}
- m_pCachedBitmap = pdfium::MakeUnique<CFX_DIBitmap>();
+ m_pCachedBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
if (!m_pCachedBitmap->Create(width, height, format)) {
- m_pCachedBitmap.reset();
+ m_pCachedBitmap.Reset();
return;
}
m_pCachedBitmap->Clear(0xFFFFFFFF);
@@ -671,7 +671,7 @@ void CPDF_DIBSource::LoadJpxBitmap() {
}
if (!pJpxModule->Decode(context->decoder(), m_pCachedBitmap->GetBuffer(),
m_pCachedBitmap->GetPitch(), output_offsets)) {
- m_pCachedBitmap.reset();
+ m_pCachedBitmap.Reset();
return;
}
if (m_pColorSpace && m_pColorSpace->GetFamily() == PDFCS_INDEXED &&
@@ -713,32 +713,29 @@ int CPDF_DIBSource::StratLoadMask() {
}
int CPDF_DIBSource::ContinueLoadMaskDIB(IFX_Pause* pPause) {
- if (!m_pMask) {
+ if (!m_pMask)
return 1;
- }
+
int ret = m_pMask->ContinueLoadDIBSource(pPause);
- if (ret == 2) {
+ if (ret == 2)
return ret;
- }
- if (m_pColorSpace && m_bStdCS) {
+
+ if (m_pColorSpace && m_bStdCS)
m_pColorSpace->EnableStdConversion(false);
- }
+
if (!ret) {
- delete m_pMask;
- m_pMask = nullptr;
+ m_pMask.Reset();
return ret;
}
return 1;
}
-CPDF_DIBSource* CPDF_DIBSource::DetachMask() {
- CPDF_DIBSource* pDIBSource = m_pMask;
- m_pMask = nullptr;
- return pDIBSource;
+CFX_RetainPtr<CPDF_DIBSource> CPDF_DIBSource::DetachMask() {
+ return std::move(m_pMask);
}
int CPDF_DIBSource::StartLoadMaskDIB() {
- m_pMask = new CPDF_DIBSource;
+ m_pMask = pdfium::MakeRetain<CPDF_DIBSource>();
int ret = m_pMask->StartLoadDIBSource(m_pDocument, m_pMaskStream, false,
nullptr, nullptr, true);
if (ret == 2) {
@@ -747,8 +744,7 @@ int CPDF_DIBSource::StartLoadMaskDIB() {
return 2;
}
if (!ret) {
- delete m_pMask;
- m_pMask = nullptr;
+ m_pMask.Reset();
return 1;
}
return 1;
diff --git a/core/fpdfapi/render/cpdf_dibsource.h b/core/fpdfapi/render/cpdf_dibsource.h
index b0f8dedaf7..c77aac1776 100644
--- a/core/fpdfapi/render/cpdf_dibsource.h
+++ b/core/fpdfapi/render/cpdf_dibsource.h
@@ -39,7 +39,9 @@ typedef struct {
class CPDF_DIBSource : public CFX_DIBSource {
public:
- CPDF_DIBSource();
+ template <typename T, typename... Args>
+ friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args);
+
~CPDF_DIBSource() override;
bool Load(CPDF_Document* pDoc, const CPDF_Stream* pStream);
@@ -71,9 +73,11 @@ class CPDF_DIBSource : public CFX_DIBSource {
int StartLoadMaskDIB();
int ContinueLoadMaskDIB(IFX_Pause* pPause);
int ContinueToLoadMask();
- CPDF_DIBSource* DetachMask();
+ CFX_RetainPtr<CPDF_DIBSource> DetachMask();
private:
+ CPDF_DIBSource();
+
bool LoadColorInfo(const CPDF_Dictionary* pFormResources,
const CPDF_Dictionary* pPageResources);
DIB_COMP_DATA* GetDecodeAndMaskArray(bool* bDefaultDecode, bool* bColorKey);
@@ -133,9 +137,9 @@ class CPDF_DIBSource : public CFX_DIBSource {
DIB_COMP_DATA* m_pCompData;
uint8_t* m_pLineBuf;
uint8_t* m_pMaskedLine;
- std::unique_ptr<CFX_DIBitmap> m_pCachedBitmap;
+ CFX_RetainPtr<CFX_DIBitmap> m_pCachedBitmap;
+ CFX_RetainPtr<CPDF_DIBSource> m_pMask;
std::unique_ptr<CCodec_ScanlineDecoder> m_pDecoder;
- CPDF_DIBSource* m_pMask;
std::unique_ptr<CPDF_StreamAcc> m_pGlobalStream;
std::unique_ptr<CCodec_Jbig2Context> m_pJbig2Context;
CPDF_Stream* m_pMaskStream;
diff --git a/core/fpdfapi/render/cpdf_dibtransferfunc.h b/core/fpdfapi/render/cpdf_dibtransferfunc.h
index d290c00d8a..d57ec0ff89 100644
--- a/core/fpdfapi/render/cpdf_dibtransferfunc.h
+++ b/core/fpdfapi/render/cpdf_dibtransferfunc.h
@@ -15,7 +15,9 @@ class CPDF_TransferFunc;
class CPDF_DIBTransferFunc : public CFX_FilteredDIB {
public:
- explicit CPDF_DIBTransferFunc(const CPDF_TransferFunc* pTransferFunc);
+ template <typename T, typename... Args>
+ friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args);
+
~CPDF_DIBTransferFunc() override;
// CFX_FilteredDIB
@@ -29,6 +31,8 @@ class CPDF_DIBTransferFunc : public CFX_FilteredDIB {
int Bpp) const override;
private:
+ explicit CPDF_DIBTransferFunc(const CPDF_TransferFunc* pTransferFunc);
+
const uint8_t* m_RampR;
const uint8_t* m_RampG;
const uint8_t* m_RampB;
diff --git a/core/fpdfapi/render/cpdf_imagecacheentry.cpp b/core/fpdfapi/render/cpdf_imagecacheentry.cpp
index 82b6117f86..751b3eb4b4 100644
--- a/core/fpdfapi/render/cpdf_imagecacheentry.cpp
+++ b/core/fpdfapi/render/cpdf_imagecacheentry.cpp
@@ -31,30 +31,27 @@ CPDF_ImageCacheEntry::CPDF_ImageCacheEntry(CPDF_Document* pDoc,
CPDF_ImageCacheEntry::~CPDF_ImageCacheEntry() {}
-void CPDF_ImageCacheEntry::Reset(const CFX_DIBitmap* pBitmap) {
- m_pCachedBitmap.reset();
+void CPDF_ImageCacheEntry::Reset(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap) {
+ m_pCachedBitmap.Reset();
if (pBitmap)
m_pCachedBitmap = pBitmap->Clone();
CalcSize();
}
-static uint32_t FPDF_ImageCache_EstimateImageSize(const CFX_DIBSource* pDIB) {
+static uint32_t FPDF_ImageCache_EstimateImageSize(
+ const CFX_RetainPtr<CFX_DIBSource>& pDIB) {
return pDIB && pDIB->GetBuffer()
? (uint32_t)pDIB->GetHeight() * pDIB->GetPitch() +
(uint32_t)pDIB->GetPaletteSize() * 4
: 0;
}
-CFX_DIBSource* CPDF_ImageCacheEntry::DetachBitmap() {
- CFX_DIBSource* pDIBSource = m_pCurBitmap;
- m_pCurBitmap = nullptr;
- return pDIBSource;
+CFX_RetainPtr<CFX_DIBSource> CPDF_ImageCacheEntry::DetachBitmap() {
+ return std::move(m_pCurBitmap);
}
-CFX_DIBSource* CPDF_ImageCacheEntry::DetachMask() {
- CFX_DIBSource* pDIBSource = m_pCurMask;
- m_pCurMask = nullptr;
- return pDIBSource;
+CFX_RetainPtr<CFX_DIBSource> CPDF_ImageCacheEntry::DetachMask() {
+ return std::move(m_pCurMask);
}
int CPDF_ImageCacheEntry::StartGetCachedBitmap(CPDF_Dictionary* pFormResources,
@@ -66,25 +63,23 @@ int CPDF_ImageCacheEntry::StartGetCachedBitmap(CPDF_Dictionary* pFormResources,
int32_t downsampleWidth,
int32_t downsampleHeight) {
if (m_pCachedBitmap) {
- m_pCurBitmap = m_pCachedBitmap.get();
- m_pCurMask = m_pCachedMask.get();
+ m_pCurBitmap = m_pCachedBitmap;
+ m_pCurMask = m_pCachedMask;
return 1;
}
if (!pRenderStatus)
return 0;
m_pRenderStatus = pRenderStatus;
- m_pCurBitmap = new CPDF_DIBSource;
- int ret =
- ((CPDF_DIBSource*)m_pCurBitmap)
- ->StartLoadDIBSource(m_pDocument, m_pStream, true, pFormResources,
- pPageResources, bStdCS, GroupFamily, bLoadMask);
+ m_pCurBitmap = pdfium::MakeRetain<CPDF_DIBSource>();
+ int ret = m_pCurBitmap.As<CPDF_DIBSource>()->StartLoadDIBSource(
+ m_pDocument, m_pStream, true, pFormResources, pPageResources, bStdCS,
+ GroupFamily, bLoadMask);
if (ret == 2)
return ret;
if (!ret) {
- delete m_pCurBitmap;
- m_pCurBitmap = nullptr;
+ m_pCurBitmap.Reset();
return 0;
}
ContinueGetCachedBitmap();
@@ -92,44 +87,41 @@ int CPDF_ImageCacheEntry::StartGetCachedBitmap(CPDF_Dictionary* pFormResources,
}
void CPDF_ImageCacheEntry::ContinueGetCachedBitmap() {
- m_MatteColor = ((CPDF_DIBSource*)m_pCurBitmap)->GetMatteColor();
- m_pCurMask = ((CPDF_DIBSource*)m_pCurBitmap)->DetachMask();
+ m_MatteColor = m_pCurBitmap.As<CPDF_DIBSource>()->GetMatteColor();
+ m_pCurMask = m_pCurBitmap.As<CPDF_DIBSource>()->DetachMask();
CPDF_RenderContext* pContext = m_pRenderStatus->GetContext();
CPDF_PageRenderCache* pPageRenderCache = pContext->GetPageCache();
m_dwTimeCount = pPageRenderCache->GetTimeCount();
if (m_pCurBitmap->GetPitch() * m_pCurBitmap->GetHeight() <
FPDF_HUGE_IMAGE_SIZE) {
m_pCachedBitmap = m_pCurBitmap->Clone();
- delete m_pCurBitmap;
- m_pCurBitmap = nullptr;
+ m_pCurBitmap.Reset();
} else {
- m_pCachedBitmap = pdfium::WrapUnique<CFX_DIBSource>(m_pCurBitmap);
+ m_pCachedBitmap = m_pCurBitmap;
}
if (m_pCurMask) {
m_pCachedMask = m_pCurMask->Clone();
- delete m_pCurMask;
- m_pCurMask = nullptr;
+ m_pCurMask.Reset();
}
- m_pCurBitmap = m_pCachedBitmap.get();
- m_pCurMask = m_pCachedMask.get();
+ m_pCurBitmap = m_pCachedBitmap;
+ m_pCurMask = m_pCachedMask;
CalcSize();
}
int CPDF_ImageCacheEntry::Continue(IFX_Pause* pPause) {
- int ret = ((CPDF_DIBSource*)m_pCurBitmap)->ContinueLoadDIBSource(pPause);
- if (ret == 2)
- return ret;
-
+ int ret = m_pCurBitmap.As<CPDF_DIBSource>()->ContinueLoadDIBSource(pPause);
if (!ret) {
- delete m_pCurBitmap;
- m_pCurBitmap = nullptr;
+ m_pCurBitmap.Reset();
return 0;
}
+ if (ret == 2)
+ return ret;
+
ContinueGetCachedBitmap();
return 0;
}
void CPDF_ImageCacheEntry::CalcSize() {
- m_dwCacheSize = FPDF_ImageCache_EstimateImageSize(m_pCachedBitmap.get()) +
- FPDF_ImageCache_EstimateImageSize(m_pCachedMask.get());
+ m_dwCacheSize = FPDF_ImageCache_EstimateImageSize(m_pCachedBitmap) +
+ FPDF_ImageCache_EstimateImageSize(m_pCachedMask);
}
diff --git a/core/fpdfapi/render/cpdf_imagecacheentry.h b/core/fpdfapi/render/cpdf_imagecacheentry.h
index d11fe94c29..b17d3fdda2 100644
--- a/core/fpdfapi/render/cpdf_imagecacheentry.h
+++ b/core/fpdfapi/render/cpdf_imagecacheentry.h
@@ -9,6 +9,7 @@
#include <memory>
+#include "core/fxcrt/cfx_retain_ptr.h"
#include "core/fxcrt/fx_system.h"
class CFX_DIBitmap;
@@ -24,7 +25,7 @@ class CPDF_ImageCacheEntry {
CPDF_ImageCacheEntry(CPDF_Document* pDoc, CPDF_Stream* pStream);
~CPDF_ImageCacheEntry();
- void Reset(const CFX_DIBitmap* pBitmap);
+ void Reset(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap);
uint32_t EstimateSize() const { return m_dwCacheSize; }
uint32_t GetTimeCount() const { return m_dwTimeCount; }
CPDF_Stream* GetStream() const { return m_pStream; }
@@ -38,8 +39,8 @@ class CPDF_ImageCacheEntry {
int32_t downsampleWidth,
int32_t downsampleHeight);
int Continue(IFX_Pause* pPause);
- CFX_DIBSource* DetachBitmap();
- CFX_DIBSource* DetachMask();
+ CFX_RetainPtr<CFX_DIBSource> DetachBitmap();
+ CFX_RetainPtr<CFX_DIBSource> DetachMask();
int m_dwTimeCount;
uint32_t m_MatteColor;
@@ -51,10 +52,10 @@ class CPDF_ImageCacheEntry {
CPDF_RenderStatus* m_pRenderStatus;
CPDF_Document* m_pDocument;
CPDF_Stream* m_pStream;
- CFX_DIBSource* m_pCurBitmap;
- CFX_DIBSource* m_pCurMask;
- std::unique_ptr<CFX_DIBSource> m_pCachedBitmap;
- std::unique_ptr<CFX_DIBSource> m_pCachedMask;
+ CFX_RetainPtr<CFX_DIBSource> m_pCurBitmap;
+ CFX_RetainPtr<CFX_DIBSource> m_pCurMask;
+ CFX_RetainPtr<CFX_DIBSource> m_pCachedBitmap;
+ CFX_RetainPtr<CFX_DIBSource> m_pCachedMask;
uint32_t m_dwCacheSize;
};
diff --git a/core/fpdfapi/render/cpdf_imageloader.cpp b/core/fpdfapi/render/cpdf_imageloader.cpp
index 18213ea695..856e340325 100644
--- a/core/fpdfapi/render/cpdf_imageloader.cpp
+++ b/core/fpdfapi/render/cpdf_imageloader.cpp
@@ -15,21 +15,14 @@
#include "core/fxcrt/fx_basic.h"
CPDF_ImageLoader::CPDF_ImageLoader()
- : m_pBitmap(nullptr),
- m_pMask(nullptr),
- m_MatteColor(0),
+ : m_MatteColor(0),
m_bCached(false),
m_nDownsampleWidth(0),
m_nDownsampleHeight(0),
m_pCache(nullptr),
m_pImage(nullptr) {}
-CPDF_ImageLoader::~CPDF_ImageLoader() {
- if (!m_bCached) {
- delete m_pBitmap;
- delete m_pMask;
- }
-}
+CPDF_ImageLoader::~CPDF_ImageLoader() {}
bool CPDF_ImageLoader::Start(const CPDF_ImageObject* pImage,
CPDF_PageRenderCache* pCache,
diff --git a/core/fpdfapi/render/cpdf_imageloader.h b/core/fpdfapi/render/cpdf_imageloader.h
index a270c45bbf..c7161c3486 100644
--- a/core/fpdfapi/render/cpdf_imageloader.h
+++ b/core/fpdfapi/render/cpdf_imageloader.h
@@ -31,8 +31,8 @@ class CPDF_ImageLoader {
int32_t nDownsampleHeight);
bool Continue(IFX_Pause* pPause);
- CFX_DIBSource* m_pBitmap;
- CFX_DIBSource* m_pMask;
+ CFX_RetainPtr<CFX_DIBSource> m_pBitmap;
+ CFX_RetainPtr<CFX_DIBSource> m_pMask;
uint32_t m_MatteColor;
bool m_bCached;
diff --git a/core/fpdfapi/render/cpdf_imagerenderer.cpp b/core/fpdfapi/render/cpdf_imagerenderer.cpp
index d3778452a3..08f9165f8a 100644
--- a/core/fpdfapi/render/cpdf_imagerenderer.cpp
+++ b/core/fpdfapi/render/cpdf_imagerenderer.cpp
@@ -95,9 +95,9 @@ bool CPDF_ImageRenderer::StartRenderDIBSource() {
!m_pImageObject->m_GeneralState.GetTransferFunc()->m_bIdentity) {
m_pDIBSource = m_Loader.m_pBitmap =
m_pImageObject->m_GeneralState.GetTransferFunc()->TranslateImage(
- m_Loader.m_pBitmap, !m_Loader.m_bCached);
+ m_Loader.m_pBitmap);
if (m_Loader.m_bCached && m_Loader.m_pMask)
- m_Loader.m_pMask = m_Loader.m_pMask->Clone().release();
+ m_Loader.m_pMask = m_Loader.m_pMask->Clone();
m_Loader.m_bCached = false;
}
}
@@ -116,7 +116,7 @@ bool CPDF_ImageRenderer::StartRenderDIBSource() {
m_pClone = m_pDIBSource->Clone();
m_pClone->ConvertColorScale(m_pRenderStatus->m_Options.m_BackColor,
m_pRenderStatus->m_Options.m_ForeColor);
- m_pDIBSource = m_pClone.get();
+ m_pDIBSource = m_pClone;
}
m_Flags = 0;
if (m_pRenderStatus->m_Options.m_Flags & RENDER_FORCE_DOWNSAMPLE)
@@ -209,7 +209,7 @@ bool CPDF_ImageRenderer::Start(CPDF_RenderStatus* pStatus,
}
bool CPDF_ImageRenderer::Start(CPDF_RenderStatus* pStatus,
- const CFX_DIBSource* pDIBSource,
+ const CFX_RetainPtr<CFX_DIBSource>& pDIBSource,
FX_ARGB bitmap_argb,
int bitmap_alpha,
const CFX_Matrix* pImage2Device,
@@ -244,11 +244,12 @@ CFX_Matrix CPDF_ImageRenderer::GetDrawMatrix(const FX_RECT& rect) const {
return new_matrix;
}
-void CPDF_ImageRenderer::CalculateDrawImage(CFX_FxgeDevice* pBitmapDevice1,
- CFX_FxgeDevice* pBitmapDevice2,
- const CFX_DIBSource* pDIBSource,
- CFX_Matrix* pNewMatrix,
- const FX_RECT& rect) const {
+void CPDF_ImageRenderer::CalculateDrawImage(
+ CFX_FxgeDevice* pBitmapDevice1,
+ CFX_FxgeDevice* pBitmapDevice2,
+ const CFX_RetainPtr<CFX_DIBSource>& pDIBSource,
+ CFX_Matrix* pNewMatrix,
+ const FX_RECT& rect) const {
CPDF_RenderStatus bitmap_render;
bitmap_render.Initialize(m_pRenderStatus->m_pContext, pBitmapDevice2, nullptr,
nullptr, nullptr, nullptr, nullptr, 0,
@@ -403,7 +404,7 @@ bool CPDF_ImageRenderer::StartDIBSource() {
}
}
#ifdef _SKIA_SUPPORT_
- CFX_DIBitmap* premultiplied = m_pDIBSource->Clone().release();
+ CFX_RetainPtr<CFX_DIBitmap> premultiplied = m_pDIBSource->Clone();
if (m_pDIBSource->HasAlpha())
CFX_SkiaDeviceDriver::PreMultiply(premultiplied);
if (m_pRenderStatus->m_pDevice->StartDIBitsWithBlend(
@@ -480,10 +481,10 @@ bool CPDF_ImageRenderer::StartDIBSource() {
FX_RECT dest_clip(
dest_rect.left - image_rect.left, dest_rect.top - image_rect.top,
dest_rect.right - image_rect.left, dest_rect.bottom - image_rect.top);
- std::unique_ptr<CFX_DIBitmap> pStretched(
- m_pDIBSource->StretchTo(dest_width, dest_height, m_Flags, &dest_clip));
+ CFX_RetainPtr<CFX_DIBitmap> pStretched =
+ m_pDIBSource->StretchTo(dest_width, dest_height, m_Flags, &dest_clip);
if (pStretched) {
- m_pRenderStatus->CompositeDIBitmap(pStretched.get(), dest_rect.left,
+ m_pRenderStatus->CompositeDIBitmap(pStretched, dest_rect.left,
dest_rect.top, m_FillArgb, m_BitmapAlpha,
m_BlendType, false);
}
@@ -501,9 +502,9 @@ bool CPDF_ImageRenderer::StartBitmapAlpha() {
FXFILL_WINDING);
return false;
}
- CFX_MaybeOwned<CFX_DIBSource> pAlphaMask;
+ CFX_RetainPtr<CFX_DIBSource> pAlphaMask;
if (m_pDIBSource->IsAlphaMask())
- pAlphaMask = const_cast<CFX_DIBSource*>(m_pDIBSource);
+ pAlphaMask = m_pDIBSource;
else
pAlphaMask = m_pDIBSource->CloneAlphaMask();
@@ -511,13 +512,13 @@ bool CPDF_ImageRenderer::StartBitmapAlpha() {
FXSYS_fabs(m_ImageMatrix.c) >= 0.5f) {
int left;
int top;
- std::unique_ptr<CFX_DIBitmap> pTransformed =
+ CFX_RetainPtr<CFX_DIBitmap> pTransformed =
pAlphaMask->TransformTo(&m_ImageMatrix, left, top);
if (!pTransformed)
return true;
m_pRenderStatus->m_pDevice->SetBitMask(
- pTransformed.get(), left, top,
+ pTransformed, left, top,
ArgbEncode(0xff, m_BitmapAlpha, m_BitmapAlpha, m_BitmapAlpha));
return false;
}
@@ -530,7 +531,7 @@ bool CPDF_ImageRenderer::StartBitmapAlpha() {
int left = dest_width > 0 ? image_rect.left : image_rect.right;
int top = dest_height > 0 ? image_rect.top : image_rect.bottom;
m_pRenderStatus->m_pDevice->StretchBitMask(
- pAlphaMask.Get(), left, top, dest_width, dest_height,
+ pAlphaMask, left, top, dest_width, dest_height,
ArgbEncode(0xff, m_BitmapAlpha, m_BitmapAlpha, m_BitmapAlpha));
return false;
}
@@ -540,7 +541,7 @@ bool CPDF_ImageRenderer::Continue(IFX_Pause* pPause) {
if (m_pTransformer->Continue(pPause))
return true;
- std::unique_ptr<CFX_DIBitmap> pBitmap(m_pTransformer->DetachBitmap());
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap = m_pTransformer->DetachBitmap();
if (!pBitmap)
return false;
@@ -548,14 +549,14 @@ bool CPDF_ImageRenderer::Continue(IFX_Pause* pPause) {
if (m_BitmapAlpha != 255)
m_FillArgb = FXARGB_MUL_ALPHA(m_FillArgb, m_BitmapAlpha);
m_Result = m_pRenderStatus->m_pDevice->SetBitMask(
- pBitmap.get(), m_pTransformer->result().left,
- m_pTransformer->result().top, m_FillArgb);
+ pBitmap, m_pTransformer->result().left, m_pTransformer->result().top,
+ m_FillArgb);
} else {
if (m_BitmapAlpha != 255)
pBitmap->MultiplyAlpha(m_BitmapAlpha);
m_Result = m_pRenderStatus->m_pDevice->SetDIBitsWithBlend(
- pBitmap.get(), m_pTransformer->result().left,
- m_pTransformer->result().top, m_BlendType);
+ pBitmap, m_pTransformer->result().left, m_pTransformer->result().top,
+ m_BlendType);
}
return false;
}
diff --git a/core/fpdfapi/render/cpdf_imagerenderer.h b/core/fpdfapi/render/cpdf_imagerenderer.h
index d358716e9f..542325449f 100644
--- a/core/fpdfapi/render/cpdf_imagerenderer.h
+++ b/core/fpdfapi/render/cpdf_imagerenderer.h
@@ -30,7 +30,7 @@ class CPDF_ImageRenderer {
int blendType);
bool Start(CPDF_RenderStatus* pStatus,
- const CFX_DIBSource* pDIBSource,
+ const CFX_RetainPtr<CFX_DIBSource>& pDIBSource,
FX_ARGB bitmap_argb,
int bitmap_alpha,
const CFX_Matrix* pImage2Device,
@@ -53,7 +53,7 @@ class CPDF_ImageRenderer {
CFX_Matrix GetDrawMatrix(const FX_RECT& rect) const;
void CalculateDrawImage(CFX_FxgeDevice* bitmap_device1,
CFX_FxgeDevice* bitmap_device2,
- const CFX_DIBSource* pDIBSource,
+ const CFX_RetainPtr<CFX_DIBSource>& pDIBSource,
CFX_Matrix* pNewMatrix,
const FX_RECT& rect) const;
@@ -63,8 +63,8 @@ class CPDF_ImageRenderer {
const CFX_Matrix* m_pObj2Device;
CFX_Matrix m_ImageMatrix;
CPDF_ImageLoader m_Loader;
- const CFX_DIBSource* m_pDIBSource;
- std::unique_ptr<CFX_DIBitmap> m_pClone;
+ CFX_RetainPtr<CFX_DIBSource> m_pDIBSource;
+ CFX_RetainPtr<CFX_DIBitmap> m_pClone;
int m_BitmapAlpha;
bool m_bPatternColor;
CPDF_Pattern* m_pPattern;
diff --git a/core/fpdfapi/render/cpdf_pagerendercache.cpp b/core/fpdfapi/render/cpdf_pagerendercache.cpp
index faa9732f9b..6e6250b1c0 100644
--- a/core/fpdfapi/render/cpdf_pagerendercache.cpp
+++ b/core/fpdfapi/render/cpdf_pagerendercache.cpp
@@ -124,8 +124,9 @@ bool CPDF_PageRenderCache::Continue(IFX_Pause* pPause) {
return false;
}
-void CPDF_PageRenderCache::ResetBitmap(CPDF_Stream* pStream,
- const CFX_DIBitmap* pBitmap) {
+void CPDF_PageRenderCache::ResetBitmap(
+ CPDF_Stream* pStream,
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap) {
CPDF_ImageCacheEntry* pEntry;
const auto it = m_ImageCache.find(pStream);
if (it == m_ImageCache.end()) {
diff --git a/core/fpdfapi/render/cpdf_pagerendercache.h b/core/fpdfapi/render/cpdf_pagerendercache.h
index 6c9ed76911..affd55bbfe 100644
--- a/core/fpdfapi/render/cpdf_pagerendercache.h
+++ b/core/fpdfapi/render/cpdf_pagerendercache.h
@@ -9,6 +9,7 @@
#include <map>
+#include "core/fxcrt/cfx_retain_ptr.h"
#include "core/fxcrt/fx_system.h"
class CPDF_Stream;
@@ -27,7 +28,8 @@ class CPDF_PageRenderCache {
void CacheOptimization(int32_t dwLimitCacheSize);
uint32_t GetTimeCount() const { return m_nTimeCount; }
- void ResetBitmap(CPDF_Stream* pStream, const CFX_DIBitmap* pBitmap);
+ void ResetBitmap(CPDF_Stream* pStream,
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap);
CPDF_Page* GetPage() const { return m_pPage; }
CPDF_ImageCacheEntry* GetCurImageCacheEntry() const {
return m_pCurImageCacheEntry;
diff --git a/core/fpdfapi/render/cpdf_rendercontext.cpp b/core/fpdfapi/render/cpdf_rendercontext.cpp
index d74f729858..07af2cc172 100644
--- a/core/fpdfapi/render/cpdf_rendercontext.cpp
+++ b/core/fpdfapi/render/cpdf_rendercontext.cpp
@@ -30,10 +30,11 @@ CPDF_RenderContext::CPDF_RenderContext(CPDF_Document* pDoc,
CPDF_RenderContext::~CPDF_RenderContext() {}
-void CPDF_RenderContext::GetBackground(CFX_DIBitmap* pBuffer,
- const CPDF_PageObject* pObj,
- const CPDF_RenderOptions* pOptions,
- CFX_Matrix* pFinalMatrix) {
+void CPDF_RenderContext::GetBackground(
+ const CFX_RetainPtr<CFX_DIBitmap>& pBuffer,
+ const CPDF_PageObject* pObj,
+ const CPDF_RenderOptions* pOptions,
+ CFX_Matrix* pFinalMatrix) {
CFX_FxgeDevice device;
device.Attach(pBuffer, false, nullptr, false);
diff --git a/core/fpdfapi/render/cpdf_rendercontext.h b/core/fpdfapi/render/cpdf_rendercontext.h
index a9fd2db78b..0cce1ae77e 100644
--- a/core/fpdfapi/render/cpdf_rendercontext.h
+++ b/core/fpdfapi/render/cpdf_rendercontext.h
@@ -47,7 +47,7 @@ class CPDF_RenderContext {
const CPDF_RenderOptions* pOptions,
const CFX_Matrix* pFinalMatrix);
- void GetBackground(CFX_DIBitmap* pBuffer,
+ void GetBackground(const CFX_RetainPtr<CFX_DIBitmap>& pBuffer,
const CPDF_PageObject* pObj,
const CPDF_RenderOptions* pOptions,
CFX_Matrix* pFinalMatrix);
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp
index 17576fc1f3..5320422b41 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.cpp
+++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -97,7 +97,7 @@ uint32_t CountOutputs(
return total;
}
-void DrawAxialShading(CFX_DIBitmap* pBitmap,
+void DrawAxialShading(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
CFX_Matrix* pObject2Bitmap,
CPDF_Dictionary* pDict,
const std::vector<std::unique_ptr<CPDF_Function>>& funcs,
@@ -183,7 +183,7 @@ void DrawAxialShading(CFX_DIBitmap* pBitmap,
}
}
-void DrawRadialShading(CFX_DIBitmap* pBitmap,
+void DrawRadialShading(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
CFX_Matrix* pObject2Bitmap,
CPDF_Dictionary* pDict,
const std::vector<std::unique_ptr<CPDF_Function>>& funcs,
@@ -316,7 +316,7 @@ void DrawRadialShading(CFX_DIBitmap* pBitmap,
}
}
-void DrawFuncShading(CFX_DIBitmap* pBitmap,
+void DrawFuncShading(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
CFX_Matrix* pObject2Bitmap,
CPDF_Dictionary* pDict,
const std::vector<std::unique_ptr<CPDF_Function>>& funcs,
@@ -391,7 +391,7 @@ bool GetScanlineIntersect(int y,
return true;
}
-void DrawGouraud(CFX_DIBitmap* pBitmap,
+void DrawGouraud(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
int alpha,
CPDF_MeshVertex triangle[3]) {
float min_y = triangle[0].position.y;
@@ -473,7 +473,7 @@ void DrawGouraud(CFX_DIBitmap* pBitmap,
}
void DrawFreeGouraudShading(
- CFX_DIBitmap* pBitmap,
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
CFX_Matrix* pObject2Bitmap,
CPDF_Stream* pShadingStream,
const std::vector<std::unique_ptr<CPDF_Function>>& funcs,
@@ -514,7 +514,7 @@ void DrawFreeGouraudShading(
}
void DrawLatticeGouraudShading(
- CFX_DIBitmap* pBitmap,
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
CFX_Matrix* pObject2Bitmap,
CPDF_Stream* pShadingStream,
const std::vector<std::unique_ptr<CPDF_Function>>& funcs,
@@ -808,7 +808,7 @@ struct CPDF_PatchDrawer {
void DrawCoonPatchMeshes(
ShadingType type,
- CFX_DIBitmap* pBitmap,
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
CFX_Matrix* pObject2Bitmap,
CPDF_Stream* pShadingStream,
const std::vector<std::unique_ptr<CPDF_Function>>& funcs,
@@ -892,21 +892,20 @@ void DrawCoonPatchMeshes(
}
}
-std::unique_ptr<CFX_DIBitmap> DrawPatternBitmap(
- CPDF_Document* pDoc,
- CPDF_PageRenderCache* pCache,
- CPDF_TilingPattern* pPattern,
- const CFX_Matrix* pObject2Device,
- int width,
- int height,
- int flags) {
- std::unique_ptr<CFX_DIBitmap> pBitmap(new CFX_DIBitmap);
+CFX_RetainPtr<CFX_DIBitmap> DrawPatternBitmap(CPDF_Document* pDoc,
+ CPDF_PageRenderCache* pCache,
+ CPDF_TilingPattern* pPattern,
+ const CFX_Matrix* pObject2Device,
+ int width,
+ int height,
+ int flags) {
+ auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
if (!pBitmap->Create(width, height,
pPattern->colored() ? FXDIB_Argb : FXDIB_8bppMask)) {
return nullptr;
}
CFX_FxgeDevice bitmap_device;
- bitmap_device.Attach(pBitmap.get(), false, nullptr, false);
+ bitmap_device.Attach(pBitmap, false, nullptr, false);
pBitmap->Clear(0);
CFX_FloatRect cell_bbox = pPattern->bbox();
pPattern->pattern_to_form()->TransformRect(cell_bbox);
@@ -1531,38 +1530,41 @@ bool CPDF_RenderStatus::ProcessTransparency(CPDF_PageObject* pPageObj,
}
FX_RECT rect = pPageObj->GetBBox(pObj2Device);
rect.Intersect(m_pDevice->GetClipBox());
- if (rect.IsEmpty()) {
+ if (rect.IsEmpty())
return true;
- }
+
CFX_Matrix deviceCTM = m_pDevice->GetCTM();
float scaleX = FXSYS_fabs(deviceCTM.a);
float scaleY = FXSYS_fabs(deviceCTM.d);
int width = FXSYS_round((float)rect.Width() * scaleX);
int height = FXSYS_round((float)rect.Height() * scaleY);
CFX_FxgeDevice bitmap_device;
- std::unique_ptr<CFX_DIBitmap> oriDevice;
+ CFX_RetainPtr<CFX_DIBitmap> oriDevice;
if (!isolated && (m_pDevice->GetRenderCaps() & FXRC_GET_BITS)) {
- oriDevice = pdfium::MakeUnique<CFX_DIBitmap>();
- if (!m_pDevice->CreateCompatibleBitmap(oriDevice.get(), width, height))
+ oriDevice = pdfium::MakeRetain<CFX_DIBitmap>();
+ if (!m_pDevice->CreateCompatibleBitmap(oriDevice, width, height))
return true;
- m_pDevice->GetDIBits(oriDevice.get(), rect.left, rect.top);
+ m_pDevice->GetDIBits(oriDevice, rect.left, rect.top);
}
- if (!bitmap_device.Create(width, height, FXDIB_Argb, oriDevice.get()))
+ if (!bitmap_device.Create(width, height, FXDIB_Argb, oriDevice))
return true;
- CFX_DIBitmap* bitmap = bitmap_device.GetBitmap();
+
+ CFX_RetainPtr<CFX_DIBitmap> bitmap = bitmap_device.GetBitmap();
bitmap->Clear(0);
+
CFX_Matrix new_matrix = *pObj2Device;
new_matrix.Translate(-rect.left, -rect.top);
new_matrix.Scale(scaleX, scaleY);
- std::unique_ptr<CFX_DIBitmap> pTextMask;
+
+ CFX_RetainPtr<CFX_DIBitmap> pTextMask;
if (bTextClip) {
- pTextMask = pdfium::MakeUnique<CFX_DIBitmap>();
+ pTextMask = pdfium::MakeRetain<CFX_DIBitmap>();
if (!pTextMask->Create(width, height, FXDIB_8bppMask))
return true;
pTextMask->Clear(0);
CFX_FxgeDevice text_device;
- text_device.Attach(pTextMask.get(), false, nullptr, false);
+ text_device.Attach(pTextMask, false, nullptr, false);
for (uint32_t i = 0; i < pPageObj->m_ClipPath.GetTextCount(); i++) {
CPDF_TextObject* textobj = pPageObj->m_ClipPath.GetText(i);
if (!textobj)
@@ -1589,14 +1591,14 @@ bool CPDF_RenderStatus::ProcessTransparency(CPDF_PageObject* pPageObj,
if (pSMaskDict) {
CFX_Matrix smask_matrix = *pPageObj->m_GeneralState.GetSMaskMatrix();
smask_matrix.Concat(*pObj2Device);
- std::unique_ptr<CFX_DIBSource> pSMaskSource =
+ CFX_RetainPtr<CFX_DIBSource> pSMaskSource =
LoadSMask(pSMaskDict, &rect, &smask_matrix);
if (pSMaskSource)
- bitmap->MultiplyAlpha(pSMaskSource.get());
+ bitmap->MultiplyAlpha(pSMaskSource);
}
if (pTextMask) {
- bitmap->MultiplyAlpha(pTextMask.get());
- pTextMask.reset();
+ bitmap->MultiplyAlpha(pTextMask);
+ pTextMask.Reset();
}
int32_t blitAlpha = 255;
if (Transparency & PDFTRANS_GROUP && group_alpha != 1.0f) {
@@ -1618,7 +1620,7 @@ bool CPDF_RenderStatus::ProcessTransparency(CPDF_PageObject* pPageObj,
return true;
}
-std::unique_ptr<CFX_DIBitmap> CPDF_RenderStatus::GetBackdrop(
+CFX_RetainPtr<CFX_DIBitmap> CPDF_RenderStatus::GetBackdrop(
const CPDF_PageObject* pObj,
const FX_RECT& rect,
int& left,
@@ -1633,11 +1635,11 @@ std::unique_ptr<CFX_DIBitmap> CPDF_RenderStatus::GetBackdrop(
float scaleY = FXSYS_fabs(deviceCTM.d);
int width = FXSYS_round(bbox.Width() * scaleX);
int height = FXSYS_round(bbox.Height() * scaleY);
- auto pBackdrop = pdfium::MakeUnique<CFX_DIBitmap>();
+ auto pBackdrop = pdfium::MakeRetain<CFX_DIBitmap>();
if (bBackAlphaRequired && !m_bDropObjects)
pBackdrop->Create(width, height, FXDIB_Argb);
else
- m_pDevice->CreateCompatibleBitmap(pBackdrop.get(), width, height);
+ m_pDevice->CreateCompatibleBitmap(pBackdrop, width, height);
if (!pBackdrop->GetBuffer())
return nullptr;
@@ -1649,16 +1651,16 @@ std::unique_ptr<CFX_DIBitmap> CPDF_RenderStatus::GetBackdrop(
bNeedDraw = !(m_pDevice->GetRenderCaps() & FXRC_GET_BITS);
if (!bNeedDraw) {
- m_pDevice->GetDIBits(pBackdrop.get(), left, top);
+ m_pDevice->GetDIBits(pBackdrop, left, top);
return pBackdrop;
}
-
CFX_Matrix FinalMatrix = m_DeviceMatrix;
FinalMatrix.Translate(-left, -top);
FinalMatrix.Scale(scaleX, scaleY);
pBackdrop->Clear(pBackdrop->HasAlpha() ? 0 : 0xffffffff);
+
CFX_FxgeDevice device;
- device.Attach(pBackdrop.get(), false, nullptr, false);
+ device.Attach(pBackdrop, false, nullptr, false);
m_pContext->Render(&device, pObj, &m_Options, &FinalMatrix);
return pBackdrop;
}
@@ -1848,7 +1850,7 @@ bool CPDF_RenderStatus::ProcessType3Text(CPDF_TextObject* textobj,
if (!glyph.m_pGlyph)
continue;
- m_pDevice->SetBitMask(&glyph.m_pGlyph->m_Bitmap,
+ m_pDevice->SetBitMask(glyph.m_pGlyph->m_pBitmap,
glyph.m_Origin.x + glyph.m_pGlyph->m_Left,
glyph.m_Origin.y - glyph.m_pGlyph->m_Top,
fill_argb);
@@ -1910,7 +1912,7 @@ bool CPDF_RenderStatus::ProcessType3Text(CPDF_TextObject* textobj,
CFX_Point origin(FXSYS_round(matrix.e), FXSYS_round(matrix.f));
if (glyphs.empty()) {
- m_pDevice->SetBitMask(&pBitmap->m_Bitmap, origin.x + pBitmap->m_Left,
+ m_pDevice->SetBitMask(pBitmap->m_pBitmap, origin.x + pBitmap->m_Left,
origin.y - pBitmap->m_Top, fill_argb);
} else {
glyphs[iChar].m_pGlyph = pBitmap;
@@ -1920,7 +1922,7 @@ bool CPDF_RenderStatus::ProcessType3Text(CPDF_TextObject* textobj,
CFX_Matrix image_matrix = pType3Char->m_ImageMatrix;
image_matrix.Concat(matrix);
CPDF_ImageRenderer renderer;
- if (renderer.Start(this, pType3Char->m_pBitmap.get(), fill_argb, 255,
+ if (renderer.Start(this, pType3Char->m_pBitmap, fill_argb, 255,
&image_matrix, 0, false, FXDIB_BLEND_NORMAL)) {
renderer.Continue(nullptr);
}
@@ -1934,12 +1936,12 @@ bool CPDF_RenderStatus::ProcessType3Text(CPDF_TextObject* textobj,
return true;
FX_RECT rect = FXGE_GetGlyphsBBox(glyphs, 0, sa, sd);
- CFX_DIBitmap bitmap;
- if (!bitmap.Create(static_cast<int>(rect.Width() * sa),
- static_cast<int>(rect.Height() * sd), FXDIB_8bppMask)) {
+ auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ if (!pBitmap->Create(static_cast<int>(rect.Width() * sa),
+ static_cast<int>(rect.Height() * sd), FXDIB_8bppMask)) {
return true;
}
- bitmap.Clear(0);
+ pBitmap->Clear(0);
for (const FXTEXT_GLYPHPOS& glyph : glyphs) {
if (!glyph.m_pGlyph)
continue;
@@ -1958,13 +1960,13 @@ bool CPDF_RenderStatus::ProcessType3Text(CPDF_TextObject* textobj,
if (!top.IsValid())
continue;
- bitmap.CompositeMask(left.ValueOrDie(), top.ValueOrDie(),
- glyph.m_pGlyph->m_Bitmap.GetWidth(),
- glyph.m_pGlyph->m_Bitmap.GetHeight(),
- &glyph.m_pGlyph->m_Bitmap, fill_argb, 0, 0,
- FXDIB_BLEND_NORMAL, nullptr, false, 0, nullptr);
+ pBitmap->CompositeMask(left.ValueOrDie(), top.ValueOrDie(),
+ glyph.m_pGlyph->m_pBitmap->GetWidth(),
+ glyph.m_pGlyph->m_pBitmap->GetHeight(),
+ glyph.m_pGlyph->m_pBitmap, fill_argb, 0, 0,
+ FXDIB_BLEND_NORMAL, nullptr, false, 0, nullptr);
}
- m_pDevice->SetBitMask(&bitmap, rect.left, rect.top, fill_argb);
+ m_pDevice->SetBitMask(pBitmap, rect.left, rect.top, fill_argb);
return true;
}
@@ -2067,7 +2069,7 @@ void CPDF_RenderStatus::DrawShading(CPDF_ShadingPattern* pPattern,
buffer.Initialize(m_pContext, m_pDevice, &clip_rect, m_pCurObj, 150);
CFX_Matrix FinalMatrix = *pMatrix;
FinalMatrix.Concat(*buffer.GetMatrix());
- CFX_DIBitmap* pBitmap = buffer.GetBitmap();
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap = buffer.GetBitmap();
if (!pBitmap->GetBuffer())
return;
@@ -2285,9 +2287,9 @@ void CPDF_RenderStatus::DrawTilingPattern(CPDF_TilingPattern* pPattern,
}
float left_offset = cell_bbox.left - mtPattern2Device.e;
float top_offset = cell_bbox.bottom - mtPattern2Device.f;
- std::unique_ptr<CFX_DIBitmap> pPatternBitmap;
+ CFX_RetainPtr<CFX_DIBitmap> pPatternBitmap;
if (width * height < 16) {
- std::unique_ptr<CFX_DIBitmap> pEnlargedBitmap =
+ CFX_RetainPtr<CFX_DIBitmap> pEnlargedBitmap =
DrawPatternBitmap(m_pContext->GetDocument(), m_pContext->GetPageCache(),
pPattern, pObj2Device, 8, 8, m_Options.m_Flags);
pPatternBitmap = pEnlargedBitmap->StretchTo(width, height);
@@ -2307,11 +2309,11 @@ void CPDF_RenderStatus::DrawTilingPattern(CPDF_TilingPattern* pPattern,
FX_ARGB fill_argb = GetFillArgb(pPageObj);
int clip_width = clip_box.right - clip_box.left;
int clip_height = clip_box.bottom - clip_box.top;
- CFX_DIBitmap screen;
- if (!screen.Create(clip_width, clip_height, FXDIB_Argb)) {
+ auto pScreen = pdfium::MakeRetain<CFX_DIBitmap>();
+ if (!pScreen->Create(clip_width, clip_height, FXDIB_Argb))
return;
- }
- screen.Clear(0);
+
+ pScreen->Clear(0);
uint32_t* src_buf = (uint32_t*)pPatternBitmap->GetBuffer();
for (int col = min_col; col <= max_col; col++) {
for (int row = min_row; row <= max_row; row++) {
@@ -2342,7 +2344,7 @@ void CPDF_RenderStatus::DrawTilingPattern(CPDF_TilingPattern* pPattern,
continue;
}
uint32_t* dest_buf =
- (uint32_t*)(screen.GetBuffer() + screen.GetPitch() * start_y +
+ (uint32_t*)(pScreen->GetBuffer() + pScreen->GetPitch() * start_y +
start_x * 4);
if (pPattern->colored())
*dest_buf = *src_buf;
@@ -2350,16 +2352,16 @@ void CPDF_RenderStatus::DrawTilingPattern(CPDF_TilingPattern* pPattern,
*dest_buf = (*(uint8_t*)src_buf << 24) | (fill_argb & 0xffffff);
} else {
if (pPattern->colored()) {
- screen.CompositeBitmap(start_x, start_y, width, height,
- pPatternBitmap.get(), 0, 0);
+ pScreen->CompositeBitmap(start_x, start_y, width, height,
+ pPatternBitmap, 0, 0);
} else {
- screen.CompositeMask(start_x, start_y, width, height,
- pPatternBitmap.get(), fill_argb, 0, 0);
+ pScreen->CompositeMask(start_x, start_y, width, height,
+ pPatternBitmap, fill_argb, 0, 0);
}
}
}
}
- CompositeDIBitmap(&screen, clip_box.left, clip_box.top, 0, 255,
+ CompositeDIBitmap(pScreen, clip_box.left, clip_box.top, 0, 255,
FXDIB_BLEND_NORMAL, false);
m_pDevice->RestoreState(false);
}
@@ -2406,16 +2408,17 @@ bool CPDF_RenderStatus::ProcessImage(CPDF_ImageObject* pImageObj,
return render.GetResult();
}
-void CPDF_RenderStatus::CompositeDIBitmap(CFX_DIBitmap* pDIBitmap,
- int left,
- int top,
- FX_ARGB mask_argb,
- int bitmap_alpha,
- int blend_mode,
- int Transparency) {
- if (!pDIBitmap) {
+void CPDF_RenderStatus::CompositeDIBitmap(
+ const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap,
+ int left,
+ int top,
+ FX_ARGB mask_argb,
+ int bitmap_alpha,
+ int blend_mode,
+ int Transparency) {
+ if (!pDIBitmap)
return;
- }
+
if (blend_mode == FXDIB_BLEND_NORMAL) {
if (!pDIBitmap->IsAlphaMask()) {
if (bitmap_alpha < 255) {
@@ -2463,10 +2466,10 @@ void CPDF_RenderStatus::CompositeDIBitmap(CFX_DIBitmap* pDIBitmap,
FX_RECT rect(left, top, left + pDIBitmap->GetWidth(),
top + pDIBitmap->GetHeight());
rect.Intersect(m_pDevice->GetClipBox());
- CFX_MaybeOwned<CFX_DIBitmap> pClone;
+ CFX_RetainPtr<CFX_DIBitmap> pClone;
if (m_pDevice->GetBackDrop() && m_pDevice->GetBitmap()) {
pClone = m_pDevice->GetBackDrop()->Clone(&rect);
- CFX_DIBitmap* pForeBitmap = m_pDevice->GetBitmap();
+ CFX_RetainPtr<CFX_DIBitmap> pForeBitmap = m_pDevice->GetBitmap();
pClone->CompositeBitmap(0, 0, pClone->GetWidth(), pClone->GetHeight(),
pForeBitmap, rect.left, rect.top);
left = left >= 0 ? 0 : left;
@@ -2481,7 +2484,7 @@ void CPDF_RenderStatus::CompositeDIBitmap(CFX_DIBitmap* pDIBitmap,
pClone = pDIBitmap;
}
if (m_pDevice->GetBackDrop()) {
- m_pDevice->SetDIBits(pClone.Get(), rect.left, rect.top);
+ m_pDevice->SetDIBits(pClone, rect.left, rect.top);
} else {
if (pDIBitmap->IsAlphaMask())
return;
@@ -2494,7 +2497,7 @@ void CPDF_RenderStatus::CompositeDIBitmap(CFX_DIBitmap* pDIBitmap,
int back_left, back_top;
FX_RECT rect(left, top, left + pDIBitmap->GetWidth(),
top + pDIBitmap->GetHeight());
- std::unique_ptr<CFX_DIBitmap> pBackdrop =
+ CFX_RetainPtr<CFX_DIBitmap> pBackdrop =
GetBackdrop(m_pCurObj, rect, back_left, back_top,
blend_mode > FXDIB_BLEND_NORMAL && bIsolated);
if (!pBackdrop)
@@ -2510,17 +2513,17 @@ void CPDF_RenderStatus::CompositeDIBitmap(CFX_DIBitmap* pDIBitmap,
pDIBitmap, mask_argb, 0, 0, blend_mode);
}
- auto pBackdrop1 = pdfium::MakeUnique<CFX_DIBitmap>();
+ auto pBackdrop1 = pdfium::MakeRetain<CFX_DIBitmap>();
pBackdrop1->Create(pBackdrop->GetWidth(), pBackdrop->GetHeight(),
FXDIB_Rgb32);
pBackdrop1->Clear((uint32_t)-1);
pBackdrop1->CompositeBitmap(0, 0, pBackdrop->GetWidth(),
- pBackdrop->GetHeight(), pBackdrop.get(), 0, 0);
+ pBackdrop->GetHeight(), pBackdrop, 0, 0);
pBackdrop = std::move(pBackdrop1);
- m_pDevice->SetDIBits(pBackdrop.get(), back_left, back_top);
+ m_pDevice->SetDIBits(pBackdrop, back_left, back_top);
}
-std::unique_ptr<CFX_DIBitmap> CPDF_RenderStatus::LoadSMask(
+CFX_RetainPtr<CFX_DIBitmap> CPDF_RenderStatus::LoadSMask(
CPDF_Dictionary* pSMaskDict,
FX_RECT* pClipRect,
const CFX_Matrix* pMatrix) {
@@ -2613,7 +2616,7 @@ std::unique_ptr<CFX_DIBitmap> CPDF_RenderStatus::LoadSMask(
nullptr, 0, color_space_family, bLuminosity);
status.RenderObjectList(&form, &matrix);
- auto pMask = pdfium::MakeUnique<CFX_DIBitmap>();
+ auto pMask = pdfium::MakeRetain<CFX_DIBitmap>();
if (!pMask->Create(width, height, FXDIB_8bppMask))
return nullptr;
diff --git a/core/fpdfapi/render/cpdf_renderstatus.h b/core/fpdfapi/render/cpdf_renderstatus.h
index 6ae255271b..e3dcd73e6d 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.h
+++ b/core/fpdfapi/render/cpdf_renderstatus.h
@@ -105,7 +105,7 @@ class CPDF_RenderStatus {
const CFX_Matrix* pObj2Device,
bool bStroke);
bool ProcessImage(CPDF_ImageObject* pImageObj, const CFX_Matrix* pObj2Device);
- void CompositeDIBitmap(CFX_DIBitmap* pDIBitmap,
+ void CompositeDIBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap,
int left,
int top,
FX_ARGB mask_argb,
@@ -133,14 +133,14 @@ class CPDF_RenderStatus {
bool bStroke);
bool ProcessForm(const CPDF_FormObject* pFormObj,
const CFX_Matrix* pObj2Device);
- std::unique_ptr<CFX_DIBitmap> GetBackdrop(const CPDF_PageObject* pObj,
- const FX_RECT& rect,
- int& left,
- int& top,
- bool bBackAlphaRequired);
- std::unique_ptr<CFX_DIBitmap> LoadSMask(CPDF_Dictionary* pSMaskDict,
- FX_RECT* pClipRect,
- const CFX_Matrix* pMatrix);
+ CFX_RetainPtr<CFX_DIBitmap> GetBackdrop(const CPDF_PageObject* pObj,
+ const FX_RECT& rect,
+ int& left,
+ int& top,
+ bool bBackAlphaRequired);
+ CFX_RetainPtr<CFX_DIBitmap> LoadSMask(CPDF_Dictionary* pSMaskDict,
+ FX_RECT* pClipRect,
+ const CFX_Matrix* pMatrix);
static CPDF_Type3Cache* GetCachedType3(CPDF_Type3Font* pFont);
static CPDF_GraphicStates* CloneObjStates(const CPDF_GraphicStates* pPathObj,
bool bStroke);
diff --git a/core/fpdfapi/render/cpdf_transferfunc.cpp b/core/fpdfapi/render/cpdf_transferfunc.cpp
index be4836d20a..ed1f27dfad 100644
--- a/core/fpdfapi/render/cpdf_transferfunc.cpp
+++ b/core/fpdfapi/render/cpdf_transferfunc.cpp
@@ -17,9 +17,9 @@ FX_COLORREF CPDF_TransferFunc::TranslateColor(FX_COLORREF rgb) const {
m_Samples[512 + FXSYS_GetBValue(rgb)]);
}
-CFX_DIBSource* CPDF_TransferFunc::TranslateImage(const CFX_DIBSource* pSrc,
- bool bAutoDropSrc) {
- CPDF_DIBTransferFunc* pDest = new CPDF_DIBTransferFunc(this);
- pDest->LoadSrc(pSrc, bAutoDropSrc);
+CFX_RetainPtr<CFX_DIBSource> CPDF_TransferFunc::TranslateImage(
+ const CFX_RetainPtr<CFX_DIBSource>& pSrc) {
+ auto pDest = pdfium::MakeRetain<CPDF_DIBTransferFunc>(this);
+ pDest->LoadSrc(pSrc);
return pDest;
}
diff --git a/core/fpdfapi/render/cpdf_transferfunc.h b/core/fpdfapi/render/cpdf_transferfunc.h
index 829b274d9b..05219d49db 100644
--- a/core/fpdfapi/render/cpdf_transferfunc.h
+++ b/core/fpdfapi/render/cpdf_transferfunc.h
@@ -16,7 +16,8 @@ class CPDF_TransferFunc {
explicit CPDF_TransferFunc(CPDF_Document* pDoc);
FX_COLORREF TranslateColor(FX_COLORREF src) const;
- CFX_DIBSource* TranslateImage(const CFX_DIBSource* pSrc, bool bAutoDropSrc);
+ CFX_RetainPtr<CFX_DIBSource> TranslateImage(
+ const CFX_RetainPtr<CFX_DIBSource>& pSrc);
CPDF_Document* const m_pPDFDoc;
bool m_bIdentity;
diff --git a/core/fpdfapi/render/cpdf_type3cache.cpp b/core/fpdfapi/render/cpdf_type3cache.cpp
index 7d0cb18172..1ba9f66203 100644
--- a/core/fpdfapi/render/cpdf_type3cache.cpp
+++ b/core/fpdfapi/render/cpdf_type3cache.cpp
@@ -8,6 +8,7 @@
#include <map>
#include <memory>
+#include <utility>
#include "core/fpdfapi/font/cpdf_type3char.h"
#include "core/fpdfapi/font/cpdf_type3font.h"
@@ -51,7 +52,8 @@ bool IsScanLine8bpp(uint8_t* pBuf, int width) {
return false;
}
-int DetectFirstLastScan(const CFX_DIBitmap* pBitmap, bool bFirst) {
+int DetectFirstLastScan(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ bool bFirst) {
int height = pBitmap->GetHeight();
int pitch = pBitmap->GetPitch();
int width = pBitmap->GetWidth();
@@ -121,12 +123,12 @@ CFX_GlyphBitmap* CPDF_Type3Cache::RenderGlyph(CPDF_Type3Glyphs* pSize,
if (!pChar || !pChar->m_pBitmap)
return nullptr;
- CFX_DIBitmap* pBitmap = pChar->m_pBitmap.get();
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap = pChar->m_pBitmap;
CFX_Matrix image_matrix = pChar->m_ImageMatrix;
CFX_Matrix text_matrix(pMatrix->a, pMatrix->b, pMatrix->c, pMatrix->d, 0, 0);
image_matrix.Concat(text_matrix);
- std::unique_ptr<CFX_DIBitmap> pResBitmap;
+ CFX_RetainPtr<CFX_DIBitmap> pResBitmap;
int left = 0;
int top = 0;
if (FXSYS_fabs(image_matrix.b) < FXSYS_fabs(image_matrix.a) / 100 &&
@@ -166,6 +168,6 @@ CFX_GlyphBitmap* CPDF_Type3Cache::RenderGlyph(CPDF_Type3Glyphs* pSize,
CFX_GlyphBitmap* pGlyph = new CFX_GlyphBitmap;
pGlyph->m_Left = left;
pGlyph->m_Top = -top;
- pGlyph->m_Bitmap.TakeOver(pResBitmap.get());
+ pGlyph->m_pBitmap->TakeOver(std::move(pResBitmap));
return pGlyph;
}
diff --git a/core/fxcodec/codec/ccodec_jpegmodule.h b/core/fxcodec/codec/ccodec_jpegmodule.h
index bad6fa6a94..7782b5fad1 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_DIBSource* pSource,
+ static bool JpegEncode(const CFX_RetainPtr<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 61703dde29..cd96ee76a0 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(CFX_DIBitmap* pDIBitmap,
+ FXCODEC_STATUS StartDecode(const CFX_RetainPtr<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_DIBitmap* m_pDeviceBitmap;
+ CFX_RetainPtr<CFX_DIBitmap> m_pDeviceBitmap;
bool m_bInterpol;
CFXCODEC_WeightTable m_WeightHorz;
CFXCODEC_VertTable m_WeightVert;
@@ -201,29 +201,35 @@ class CCodec_ProgressiveDecoder : public ICodec_BmpModule::Delegate,
FXCODEC_STATUS& err_status);
bool GifReadMoreData(ICodec_GifModule* pGifModule,
FXCODEC_STATUS& err_status);
- 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);
+ 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);
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(CFX_DIBitmap* pDeviceBitmap,
+ void ReSampleScanline(const CFX_RetainPtr<CFX_DIBitmap>& pDeviceBitmap,
int32_t des_line,
uint8_t* src_scan,
FXCodec_Format src_format);
- void Resample(CFX_DIBitmap* pDeviceBitmap,
+ void Resample(const CFX_RetainPtr<CFX_DIBitmap>& pDeviceBitmap,
int32_t src_line,
uint8_t* src_scan,
FXCodec_Format src_format);
- void ResampleVert(CFX_DIBitmap* pDeviceBitmap, double scale_y, int des_row);
+ void ResampleVert(const CFX_RetainPtr<CFX_DIBitmap>& pDeviceBitmap,
+ double scale_y,
+ int des_row);
bool JpegReadMoreData(CCodec_JpegModule* pJpegModule,
FXCODEC_STATUS& err_status);
- void ResampleVertBT(CFX_DIBitmap* pDeviceBitmap, double scale_y, int des_row);
+ void ResampleVertBT(const CFX_RetainPtr<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 3807ec75aa..0a0b56ce94 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(CFX_DIBitmap* pDIBitmap);
+ bool Decode(const CFX_RetainPtr<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_DIBitmap* pDIBitmap) const;
- void SetPalette(CFX_DIBitmap* pDIBitmap, uint16_t bps);
- bool Decode1bppRGB(CFX_DIBitmap* pDIBitmap,
+ 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,
int32_t height,
int32_t width,
uint16_t bps,
uint16_t spp);
- bool Decode8bppRGB(CFX_DIBitmap* pDIBitmap,
+ bool Decode8bppRGB(const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap,
int32_t height,
int32_t width,
uint16_t bps,
uint16_t spp);
- bool Decode24bppRGB(CFX_DIBitmap* pDIBitmap,
+ bool Decode24bppRGB(const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap,
int32_t height,
int32_t width,
uint16_t bps,
@@ -287,7 +287,8 @@ bool CCodec_TiffContext::LoadFrameInfo(int32_t frame,
return true;
}
-bool CCodec_TiffContext::IsSupport(const CFX_DIBitmap* pDIBitmap) const {
+bool CCodec_TiffContext::IsSupport(
+ const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap) const {
if (TIFFIsTiled(m_tif_ctx))
return false;
@@ -317,7 +318,9 @@ bool CCodec_TiffContext::IsSupport(const CFX_DIBitmap* pDIBitmap) const {
return planarconfig != PLANARCONFIG_SEPARATE;
}
-void CCodec_TiffContext::SetPalette(CFX_DIBitmap* pDIBitmap, uint16_t bps) {
+void CCodec_TiffContext::SetPalette(
+ const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap,
+ uint16_t bps) {
uint16_t* red_orig = nullptr;
uint16_t* green_orig = nullptr;
uint16_t* blue_orig = nullptr;
@@ -340,11 +343,12 @@ void CCodec_TiffContext::SetPalette(CFX_DIBitmap* pDIBitmap, uint16_t bps) {
}
}
-bool CCodec_TiffContext::Decode1bppRGB(CFX_DIBitmap* pDIBitmap,
- int32_t height,
- int32_t width,
- uint16_t bps,
- uint16_t spp) {
+bool CCodec_TiffContext::Decode1bppRGB(
+ const CFX_RetainPtr<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;
@@ -368,11 +372,12 @@ bool CCodec_TiffContext::Decode1bppRGB(CFX_DIBitmap* pDIBitmap,
return true;
}
-bool CCodec_TiffContext::Decode8bppRGB(CFX_DIBitmap* pDIBitmap,
- int32_t height,
- int32_t width,
- uint16_t bps,
- uint16_t spp) {
+bool CCodec_TiffContext::Decode8bppRGB(
+ const CFX_RetainPtr<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;
@@ -404,11 +409,12 @@ bool CCodec_TiffContext::Decode8bppRGB(CFX_DIBitmap* pDIBitmap,
return true;
}
-bool CCodec_TiffContext::Decode24bppRGB(CFX_DIBitmap* pDIBitmap,
- int32_t height,
- int32_t width,
- uint16_t bps,
- uint16_t spp) {
+bool CCodec_TiffContext::Decode24bppRGB(
+ const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap,
+ int32_t height,
+ int32_t width,
+ uint16_t bps,
+ uint16_t spp) {
if (pDIBitmap->GetBPP() != 24 || !IsSupport(pDIBitmap))
return false;
@@ -432,7 +438,7 @@ bool CCodec_TiffContext::Decode24bppRGB(CFX_DIBitmap* pDIBitmap,
return true;
}
-bool CCodec_TiffContext::Decode(CFX_DIBitmap* pDIBitmap) {
+bool CCodec_TiffContext::Decode(const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap) {
uint32_t img_wid = pDIBitmap->GetWidth();
uint32_t img_hei = pDIBitmap->GetHeight();
uint32_t width = 0;
@@ -493,7 +499,7 @@ bool CCodec_TiffModule::LoadFrameInfo(CCodec_TiffContext* ctx,
}
bool CCodec_TiffModule::Decode(CCodec_TiffContext* ctx,
- class CFX_DIBitmap* pDIBitmap) {
+ const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap) {
return ctx->Decode(pDIBitmap);
}
diff --git a/core/fxcodec/codec/ccodec_tiffmodule.h b/core/fxcodec/codec/ccodec_tiffmodule.h
index a8820f4aac..8878ad504e 100644
--- a/core/fxcodec/codec/ccodec_tiffmodule.h
+++ b/core/fxcodec/codec/ccodec_tiffmodule.h
@@ -24,7 +24,8 @@ class CCodec_TiffModule : public ICodec_TiffModule {
int32_t* comps,
int32_t* bpc,
CFX_DIBAttribute* pAttribute) override;
- bool Decode(CCodec_TiffContext* ctx, class CFX_DIBitmap* pDIBitmap) override;
+ bool Decode(CCodec_TiffContext* ctx,
+ const CFX_RetainPtr<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 c797605575..0431560529 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_DIBSource* pSource,
+bool CCodec_JpegModule::JpegEncode(const CFX_RetainPtr<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 af7f24e4fe..bd890f89ff 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_DIBitmap* pDIBitmap = m_pDeviceBitmap;
+ CFX_RetainPtr<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(
- CFX_DIBitmap* pDeviceBitmap,
+ const CFX_RetainPtr<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_DIBitmap* pDIBitmap = m_pDeviceBitmap;
+ CFX_RetainPtr<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_DIBitmap* pDevice = m_pDeviceBitmap;
+ CFX_RetainPtr<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_DIBitmap* pDIBitmap = m_pDeviceBitmap;
+ CFX_RetainPtr<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(
- CFX_DIBitmap* pDeviceBitmap,
+ const CFX_RetainPtr<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_DIBitmap* pDIBitmap = m_pDeviceBitmap;
+ CFX_RetainPtr<CFX_DIBitmap> pDIBitmap = m_pDeviceBitmap;
ASSERT(pDIBitmap);
FXSYS_memcpy(m_pDecodeBuf, row_buf, m_ScanlineSize);
int src_top = m_clipBox.top;
@@ -923,9 +923,10 @@ void CCodec_ProgressiveDecoder::BmpReadScanline(int32_t row_num,
ResampleVertBT(pDIBitmap, scale_y, des_row);
}
-void CCodec_ProgressiveDecoder::ResampleVertBT(CFX_DIBitmap* pDeviceBitmap,
- double scale_y,
- int des_row) {
+void CCodec_ProgressiveDecoder::ResampleVertBT(
+ const CFX_RetainPtr<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;
@@ -1440,10 +1441,11 @@ void CCodec_ProgressiveDecoder::GetTransMethod(FXDIB_Format des_format,
}
}
-void CCodec_ProgressiveDecoder::ReSampleScanline(CFX_DIBitmap* pDeviceBitmap,
- int des_line,
- uint8_t* src_scan,
- FXCodec_Format src_format) {
+void CCodec_ProgressiveDecoder::ReSampleScanline(
+ const CFX_RetainPtr<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 =
@@ -1642,9 +1644,10 @@ void CCodec_ProgressiveDecoder::ReSampleScanline(CFX_DIBitmap* pDeviceBitmap,
}
}
-void CCodec_ProgressiveDecoder::ResampleVert(CFX_DIBitmap* pDeviceBitmap,
- double scale_y,
- int des_row) {
+void CCodec_ProgressiveDecoder::ResampleVert(
+ const CFX_RetainPtr<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) {
@@ -1757,10 +1760,11 @@ void CCodec_ProgressiveDecoder::ResampleVert(CFX_DIBitmap* pDeviceBitmap,
}
}
-void CCodec_ProgressiveDecoder::Resample(CFX_DIBitmap* pDeviceBitmap,
- int32_t src_line,
- uint8_t* src_scan,
- FXCodec_Format src_format) {
+void CCodec_ProgressiveDecoder::Resample(
+ const CFX_RetainPtr<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();
@@ -1831,13 +1835,14 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::GetFrames(int32_t& frames,
}
}
-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) {
+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) {
if (m_status != FXCODEC_STATUS_DECODE_READY)
return FXCODEC_STATUS_ERROR;
@@ -2215,10 +2220,9 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode(IFX_Pause* pPause) {
return m_status;
}
- CFX_DIBitmap* pDIBitmap = new CFX_DIBitmap;
+ auto pDIBitmap = pdfium::MakeRetain<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;
@@ -2226,45 +2230,41 @@ 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_DIBitmap* pClipBitmap =
+ CFX_RetainPtr<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).release();
- if (pDIBitmap != pClipBitmap) {
- delete pDIBitmap;
- }
+ : pDIBitmap->Clone(&m_clipBox);
if (!pClipBitmap) {
m_pDeviceBitmap = nullptr;
m_pFile = nullptr;
m_status = FXCODEC_STATUS_ERR_MEMORY;
return m_status;
}
- CFX_DIBitmap* pFormatBitmap = nullptr;
+ CFX_RetainPtr<CFX_DIBitmap> pFormatBitmap;
switch (m_pDeviceBitmap->GetFormat()) {
case FXDIB_8bppRgb:
- pFormatBitmap = new CFX_DIBitmap;
+ pFormatBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
pFormatBitmap->Create(pClipBitmap->GetWidth(),
pClipBitmap->GetHeight(), FXDIB_8bppRgb);
break;
case FXDIB_8bppMask:
- pFormatBitmap = new CFX_DIBitmap;
+ pFormatBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
pFormatBitmap->Create(pClipBitmap->GetWidth(),
pClipBitmap->GetHeight(), FXDIB_8bppMask);
break;
case FXDIB_Rgb:
- pFormatBitmap = new CFX_DIBitmap;
+ pFormatBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
pFormatBitmap->Create(pClipBitmap->GetWidth(),
pClipBitmap->GetHeight(), FXDIB_Rgb);
break;
case FXDIB_Rgb32:
- pFormatBitmap = new CFX_DIBitmap;
+ pFormatBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
pFormatBitmap->Create(pClipBitmap->GetWidth(),
pClipBitmap->GetHeight(), FXDIB_Rgb32);
break;
@@ -2312,18 +2312,14 @@ 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;
}
- std::unique_ptr<CFX_DIBitmap> pStrechBitmap = pFormatBitmap->StretchTo(
+ CFX_RetainPtr<CFX_DIBitmap> pStrechBitmap = pFormatBitmap->StretchTo(
m_sizeX, m_sizeY, m_bInterpol ? FXDIB_INTERPOL : FXDIB_DOWNSAMPLE);
- delete pFormatBitmap;
pFormatBitmap = nullptr;
if (!pStrechBitmap) {
m_pDeviceBitmap = nullptr;
@@ -2332,7 +2328,7 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode(IFX_Pause* pPause) {
return m_status;
}
m_pDeviceBitmap->TransferBitmap(m_startX, m_startY, m_sizeX, m_sizeY,
- pStrechBitmap.get(), 0, 0);
+ pStrechBitmap, 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 540d82ff63..49abd1865f 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,
- class CFX_DIBitmap* pDIBitmap) = 0;
+ const CFX_RetainPtr<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 b435c032bc..ad7d2c4517 100644
--- a/core/fxge/agg/fx_agg_driver.cpp
+++ b/core/fxge/agg/fx_agg_driver.cpp
@@ -35,7 +35,10 @@ CFX_PointF HardClip(const CFX_PointF& pos) {
pdfium::clamp(pos.y, -kMaxPos, kMaxPos));
}
-void RgbByteOrderSetPixel(CFX_DIBitmap* pBitmap, int x, int y, uint32_t argb) {
+void RgbByteOrderSetPixel(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ int x,
+ int y,
+ uint32_t argb) {
if (x < 0 || x >= pBitmap->GetWidth() || y < 0 || y >= pBitmap->GetHeight())
return;
@@ -52,7 +55,7 @@ void RgbByteOrderSetPixel(CFX_DIBitmap* pBitmap, int x, int y, uint32_t argb) {
pos[2] = (FXARGB_B(argb) * alpha + pos[2] * (255 - alpha)) / 255;
}
-void RgbByteOrderCompositeRect(CFX_DIBitmap* pBitmap,
+void RgbByteOrderCompositeRect(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
int left,
int top,
int width,
@@ -127,12 +130,12 @@ void RgbByteOrderCompositeRect(CFX_DIBitmap* pBitmap,
}
}
-void RgbByteOrderTransferBitmap(CFX_DIBitmap* pBitmap,
+void RgbByteOrderTransferBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
int dest_left,
int dest_top,
int width,
int height,
- const CFX_DIBSource* pSrcBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
int src_left,
int src_top) {
if (!pBitmap)
@@ -232,7 +235,7 @@ FX_ARGB DefaultCMYK2ARGB(FX_CMYK cmyk, uint8_t alpha) {
return ArgbEncode(alpha, r, g, b);
}
-bool DibSetPixel(CFX_DIBitmap* pDevice,
+bool DibSetPixel(const CFX_RetainPtr<CFX_DIBitmap>& pDevice,
int x,
int y,
uint32_t color,
@@ -398,8 +401,8 @@ class CFX_Renderer {
uint8_t* clip_scan,
uint8_t* dest_extra_alpha_scan);
- bool Init(CFX_DIBitmap* pDevice,
- CFX_DIBitmap* pOriDevice,
+ bool Init(const CFX_RetainPtr<CFX_DIBitmap>& pDevice,
+ const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice,
const CFX_ClipRgn* pClipRgn,
uint32_t color,
bool bFullCover,
@@ -456,10 +459,10 @@ class CFX_Renderer {
uint32_t m_Color;
bool m_bFullCover;
bool m_bRgbByteOrder;
- CFX_DIBitmap* m_pOriDevice;
FX_RECT m_ClipBox;
- const CFX_DIBitmap* m_pClipMask;
- CFX_DIBitmap* m_pDevice;
+ CFX_RetainPtr<CFX_DIBitmap> m_pOriDevice;
+ CFX_RetainPtr<CFX_DIBitmap> m_pClipMask;
+ CFX_RetainPtr<CFX_DIBitmap> m_pDevice;
const CFX_ClipRgn* m_pClipRgn;
};
@@ -899,8 +902,8 @@ void CFX_Renderer::CompositeSpanCMYK(uint8_t* dest_scan,
}
}
-bool CFX_Renderer::Init(CFX_DIBitmap* pDevice,
- CFX_DIBitmap* pOriDevice,
+bool CFX_Renderer::Init(const CFX_RetainPtr<CFX_DIBitmap>& pDevice,
+ const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice,
const CFX_ClipRgn* pClipRgn,
uint32_t color,
bool bFullCover,
@@ -921,7 +924,7 @@ bool CFX_Renderer::Init(CFX_DIBitmap* pDevice,
}
m_pClipMask = nullptr;
if (m_pClipRgn && m_pClipRgn->GetType() == CFX_ClipRgn::MaskF)
- m_pClipMask = m_pClipRgn->GetMask().GetObject();
+ m_pClipMask = m_pClipRgn->GetMask();
m_bFullCover = bFullCover;
bool bObjectCMYK = !!FXGETFLAG_COLORTYPE(alpha_flag);
bool bDeviceCMYK = pDevice->IsCmykImage();
@@ -1038,7 +1041,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_DIBitmap* pAlphaMask = m_pDevice->m_pAlphaMask;
+ CFX_RetainPtr<CFX_DIBitmap> pAlphaMask = m_pDevice->m_pAlphaMask;
if (pAlphaMask) {
dest_scan_extra_alpha =
pAlphaMask->GetBuffer() + pAlphaMask->GetPitch() * y;
@@ -1199,10 +1202,11 @@ void CAgg_PathData::BuildPath(const CFX_PathData* pPathData,
}
}
-CFX_AggDeviceDriver::CFX_AggDeviceDriver(CFX_DIBitmap* pBitmap,
- bool bRgbByteOrder,
- CFX_DIBitmap* pOriDevice,
- bool bGroupKnockout)
+CFX_AggDeviceDriver::CFX_AggDeviceDriver(
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ bool bRgbByteOrder,
+ const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice,
+ bool bGroupKnockout)
: m_pBitmap(pBitmap),
#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
m_pPlatformGraphics(nullptr),
@@ -1296,8 +1300,7 @@ 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());
- CFX_DIBitmapRef mask;
- CFX_DIBitmap* pThisLayer = mask.Emplace();
+ auto pThisLayer = pdfium::MakeRetain<CFX_DIBitmap>();
pThisLayer->Create(path_rect.Width(), path_rect.Height(), FXDIB_8bppMask);
pThisLayer->Clear(0);
agg::rendering_buffer raw_buf(pThisLayer->GetBuffer(), pThisLayer->GetWidth(),
@@ -1311,7 +1314,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, mask);
+ m_pClipRgn->IntersectMaskF(path_rect.left, path_rect.top, pThisLayer);
}
bool CFX_AggDeviceDriver::SetClip_PathFill(const CFX_PathData* pPathData,
@@ -1381,7 +1384,7 @@ bool CFX_AggDeviceDriver::RenderRasterizer(
bool bGroupKnockout,
int alpha_flag,
void* pIccTransform) {
- CFX_DIBitmap* pt = bGroupKnockout ? m_pOriDevice : nullptr;
+ CFX_RetainPtr<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)) {
@@ -1492,8 +1495,8 @@ bool CFX_AggDeviceDriver::SetPixel(int x, int y, uint32_t color) {
if (m_pClipRgn->GetType() != CFX_ClipRgn::MaskF)
return true;
- const CFX_DIBitmap* pMask = m_pClipRgn->GetMask().GetObject();
- int new_alpha = FXARGB_A(color) * pMask->GetScanline(y)[x] / 255;
+ int new_alpha =
+ FXARGB_A(color) * m_pClipRgn->GetMask()->GetScanline(y)[x] / 255;
color = (color & 0xffffff) | (new_alpha << 24);
if (m_bRgbByteOrder) {
RgbByteOrderSetPixel(m_pBitmap, x, y, color);
@@ -1530,11 +1533,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().GetObject(), 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(),
+ fill_color, draw_rect.left - clip_rect.left,
+ draw_rect.top - clip_rect.top, FXDIB_BLEND_NORMAL,
+ nullptr, m_bRgbByteOrder, 0, nullptr);
return true;
}
@@ -1549,13 +1552,15 @@ bool CFX_AggDeviceDriver::GetClipBox(FX_RECT* pRect) {
return true;
}
-bool CFX_AggDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) {
+bool CFX_AggDeviceDriver::GetDIBits(const CFX_RetainPtr<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());
- std::unique_ptr<CFX_DIBitmap> pBack;
+ CFX_RetainPtr<CFX_DIBitmap> pBack;
if (m_pOriDevice) {
pBack = m_pOriDevice->Clone(&rect);
if (!pBack)
@@ -1573,18 +1578,18 @@ bool CFX_AggDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) {
top = std::min(top, 0);
if (m_bRgbByteOrder) {
RgbByteOrderTransferBitmap(pBitmap, 0, 0, rect.Width(), rect.Height(),
- pBack.get(), left, top);
+ pBack, left, top);
return true;
}
- return pBitmap->TransferBitmap(0, 0, rect.Width(), rect.Height(), pBack.get(),
- left, top);
+ return pBitmap->TransferBitmap(0, 0, rect.Width(), rect.Height(), pBack, left,
+ top);
}
-CFX_DIBitmap* CFX_AggDeviceDriver::GetBackDrop() {
+CFX_RetainPtr<CFX_DIBitmap> CFX_AggDeviceDriver::GetBackDrop() {
return m_pOriDevice;
}
-bool CFX_AggDeviceDriver::SetDIBits(const CFX_DIBSource* pBitmap,
+bool CFX_AggDeviceDriver::SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
uint32_t argb,
const FX_RECT* pSrcRect,
int left,
@@ -1604,15 +1609,16 @@ bool CFX_AggDeviceDriver::SetDIBits(const CFX_DIBSource* pBitmap,
pSrcRect->top, blend_type, m_pClipRgn.get(), m_bRgbByteOrder, nullptr);
}
-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) {
+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) {
if (!m_pBitmap->GetBuffer())
return true;
@@ -1637,13 +1643,14 @@ bool CFX_AggDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource,
return true;
}
-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) {
+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) {
if (!m_pBitmap->GetBuffer())
return true;
@@ -1668,13 +1675,13 @@ void CFX_AggDeviceDriver::CancelDIBits(void* pHandle) {
}
#ifndef _SKIA_SUPPORT_
-CFX_FxgeDevice::CFX_FxgeDevice() {
- m_bOwnedBitmap = false;
-}
+CFX_FxgeDevice::CFX_FxgeDevice() {}
+
+CFX_FxgeDevice::~CFX_FxgeDevice() {}
-bool CFX_FxgeDevice::Attach(CFX_DIBitmap* pBitmap,
+bool CFX_FxgeDevice::Attach(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
bool bRgbByteOrder,
- CFX_DIBitmap* pOriDevice,
+ const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice,
bool bGroupKnockout) {
if (!pBitmap)
return false;
@@ -1688,21 +1695,15 @@ bool CFX_FxgeDevice::Attach(CFX_DIBitmap* pBitmap,
bool CFX_FxgeDevice::Create(int width,
int height,
FXDIB_Format format,
- CFX_DIBitmap* pOriDevice) {
- m_bOwnedBitmap = true;
- CFX_DIBitmap* pBitmap = new CFX_DIBitmap;
- if (!pBitmap->Create(width, height, format)) {
- delete pBitmap;
+ const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice) {
+ auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ if (!pBitmap->Create(width, height, format))
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 7b4c7209e8..723ed6d98a 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(CFX_DIBitmap* pBitmap,
+ CFX_AggDeviceDriver(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
bool bRgbByteOrder,
- CFX_DIBitmap* pOriDevice,
+ const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice,
bool bGroupKnockout);
~CFX_AggDeviceDriver() override;
@@ -63,15 +63,17 @@ class CFX_AggDeviceDriver : public IFX_RenderDeviceDriver {
uint32_t fill_color,
int blend_type) override;
bool GetClipBox(FX_RECT* pRect) override;
- bool GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) override;
- CFX_DIBitmap* GetBackDrop() override;
- bool SetDIBits(const CFX_DIBSource* pBitmap,
+ 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,
uint32_t color,
const FX_RECT* pSrcRect,
int left,
int top,
int blend_type) override;
- bool StretchDIBits(const CFX_DIBSource* pBitmap,
+ bool StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
uint32_t color,
int dest_left,
int dest_top,
@@ -80,7 +82,7 @@ class CFX_AggDeviceDriver : public IFX_RenderDeviceDriver {
const FX_RECT* pClipRect,
uint32_t flags,
int blend_type) override;
- bool StartDIBits(const CFX_DIBSource* pBitmap,
+ bool StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
int bitmap_alpha,
uint32_t color,
const CFX_Matrix* pMatrix,
@@ -109,7 +111,7 @@ class CFX_AggDeviceDriver : public IFX_RenderDeviceDriver {
virtual uint8_t* GetBuffer() const;
private:
- CFX_DIBitmap* m_pBitmap;
+ CFX_RetainPtr<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_
@@ -117,7 +119,7 @@ class CFX_AggDeviceDriver : public IFX_RenderDeviceDriver {
#endif
int m_FillFlags;
bool m_bRgbByteOrder;
- CFX_DIBitmap* m_pOriDevice;
+ CFX_RetainPtr<CFX_DIBitmap> m_pOriDevice;
bool m_bGroupKnockout;
};
diff --git a/core/fxge/apple/apple_int.h b/core/fxge/apple/apple_int.h
index 2a4029bd38..f1b9fcf2e8 100644
--- a/core/fxge/apple/apple_int.h
+++ b/core/fxge/apple/apple_int.h
@@ -19,7 +19,7 @@
class CQuartz2D {
public:
- void* createGraphics(CFX_DIBitmap* bitmap);
+ void* createGraphics(const CFX_RetainPtr<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 20e86ed483..3f7916f07d 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());
- const CFX_DIBitmap* pClipMask = m_pClipRgn->GetMask().GetObject();
+ CFX_RetainPtr<CFX_DIBitmap> pClipMask = m_pClipRgn->GetMask();
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 dbb121065d..ded8036047 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(CFX_DIBitmap* pBitmap) {
+void* CQuartz2D::createGraphics(const CFX_RetainPtr<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 8358e43666..4e8a7f4f55 100644
--- a/core/fxge/cfx_fxgedevice.h
+++ b/core/fxge/cfx_fxgedevice.h
@@ -17,30 +17,27 @@ class CFX_FxgeDevice : public CFX_RenderDevice {
CFX_FxgeDevice();
~CFX_FxgeDevice() override;
- bool Attach(CFX_DIBitmap* pBitmap,
+ bool Attach(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
bool bRgbByteOrder,
- CFX_DIBitmap* pOriDevice,
+ const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice,
bool bGroupKnockout);
bool Create(int width,
int height,
FXDIB_Format format,
- CFX_DIBitmap* pOriDevice);
+ const CFX_RetainPtr<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_DIBSource* pBitmap,
- const CFX_DIBSource* pMask,
+ bool SetBitsWithMask(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ const CFX_RetainPtr<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 41f8e4c690..d56c2ecb9a 100644
--- a/core/fxge/cfx_renderdevice.h
+++ b/core/fxge/cfx_renderdevice.h
@@ -100,9 +100,13 @@ class CFX_RenderDevice {
int GetRenderCaps() const { return m_RenderCaps; }
int GetDeviceCaps(int id) const;
CFX_Matrix GetCTM() 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;
+ 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;
const FX_RECT& GetClipBox() const { return m_ClipBox; }
bool SetClip_PathFill(const CFX_PathData* pPathData,
const CFX_Matrix* pObject2Device,
@@ -140,16 +144,18 @@ class CFX_RenderDevice {
int fill_mode,
int blend_type);
- bool GetDIBits(CFX_DIBitmap* pBitmap, int left, int top);
- CFX_DIBitmap* GetBackDrop();
- bool SetDIBits(const CFX_DIBSource* pBitmap, int left, int top) {
+ 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) {
return SetDIBitsWithBlend(pBitmap, left, top, FXDIB_BLEND_NORMAL);
}
- bool SetDIBitsWithBlend(const CFX_DIBSource* pBitmap,
+ bool SetDIBitsWithBlend(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
int left,
int top,
int blend_type);
- bool StretchDIBits(const CFX_DIBSource* pBitmap,
+ bool StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
int left,
int top,
int dest_width,
@@ -157,31 +163,32 @@ class CFX_RenderDevice {
return StretchDIBitsWithFlagsAndBlend(pBitmap, left, top, dest_width,
dest_height, 0, FXDIB_BLEND_NORMAL);
}
- 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,
+ 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,
int left,
int top,
uint32_t color);
- bool StretchBitMask(const CFX_DIBSource* pBitmap,
+ bool StretchBitMask(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
int left,
int top,
int dest_width,
int dest_height,
uint32_t color);
- bool StretchBitMaskWithFlags(const CFX_DIBSource* pBitmap,
+ bool StretchBitMaskWithFlags(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
int left,
int top,
int dest_width,
int dest_height,
uint32_t color,
uint32_t flags);
- bool StartDIBits(const CFX_DIBSource* pBitmap,
+ bool StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
int bitmap_alpha,
uint32_t color,
const CFX_Matrix* pMatrix,
@@ -190,7 +197,7 @@ class CFX_RenderDevice {
return StartDIBitsWithBlend(pBitmap, bitmap_alpha, color, pMatrix, flags,
handle, FXDIB_BLEND_NORMAL);
}
- bool StartDIBitsWithBlend(const CFX_DIBSource* pBitmap,
+ bool StartDIBitsWithBlend(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
int bitmap_alpha,
uint32_t color,
const CFX_Matrix* pMatrix,
@@ -221,8 +228,8 @@ class CFX_RenderDevice {
#ifdef _SKIA_SUPPORT_
virtual void DebugVerifyBitmapIsPreMultiplied() const;
- virtual bool SetBitsWithMask(const CFX_DIBSource* pBitmap,
- const CFX_DIBSource* pMask,
+ virtual bool SetBitsWithMask(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pMask,
int left,
int top,
int bitmap_alpha,
@@ -243,7 +250,7 @@ class CFX_RenderDevice {
int fill_mode,
int blend_type);
- CFX_DIBitmap* m_pBitmap;
+ CFX_RetainPtr<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 000003a9c6..a898a479a2 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_DIBSource* pSrcBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
int flags);
~CStretchEngine();
@@ -91,7 +91,7 @@ class CStretchEngine {
uint8_t* m_pDestScanline;
uint8_t* m_pDestMaskScanline;
FX_RECT m_SrcClip;
- const CFX_DIBSource* m_pSource;
+ CFX_RetainPtr<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 435a1ad9b6..fb00cb855b 100644
--- a/core/fxge/dib/fx_dib_composite.cpp
+++ b/core/fxge/dib/fx_dib_composite.cpp
@@ -3914,17 +3914,18 @@ void CFX_ScanlineCompositor::CompositeBitMaskLine(uint8_t* dest_scan,
}
}
-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) {
+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) {
if (!m_pBuffer) {
return false;
}
@@ -3938,11 +3939,11 @@ bool CFX_DIBitmap::CompositeBitmap(int dest_left,
if (width == 0 || height == 0) {
return true;
}
- const CFX_DIBitmap* pClipMask = nullptr;
+ CFX_RetainPtr<CFX_DIBitmap> pClipMask;
FX_RECT clip_box;
if (pClipRgn && pClipRgn->GetType() != CFX_ClipRgn::RectI) {
ASSERT(pClipRgn->GetType() == CFX_ClipRgn::MaskF);
- pClipMask = pClipRgn->GetMask().GetObject();
+ pClipMask = pClipRgn->GetMask();
clip_box = pClipRgn->GetBox();
}
CFX_ScanlineCompositor compositor;
@@ -3954,7 +3955,7 @@ bool CFX_DIBitmap::CompositeBitmap(int dest_left,
int dest_Bpp = m_bpp / 8;
int src_Bpp = pSrcBitmap->GetBPP() / 8;
bool bRgb = src_Bpp > 1 && !pSrcBitmap->IsCmykImage();
- CFX_DIBitmap* pSrcAlphaMask = pSrcBitmap->m_pAlphaMask;
+ CFX_RetainPtr<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;
@@ -3990,7 +3991,7 @@ bool CFX_DIBitmap::CompositeMask(int dest_left,
int dest_top,
int width,
int height,
- const CFX_DIBSource* pMask,
+ const CFX_RetainPtr<CFX_DIBSource>& pMask,
uint32_t color,
int src_left,
int src_top,
@@ -4017,11 +4018,11 @@ bool CFX_DIBitmap::CompositeMask(int dest_left,
if (src_alpha == 0) {
return true;
}
- const CFX_DIBitmap* pClipMask = nullptr;
+ CFX_RetainPtr<CFX_DIBitmap> pClipMask;
FX_RECT clip_box;
if (pClipRgn && pClipRgn->GetType() != CFX_ClipRgn::RectI) {
ASSERT(pClipRgn->GetType() == CFX_ClipRgn::MaskF);
- pClipMask = pClipRgn->GetMask().GetObject();
+ pClipMask = pClipRgn->GetMask();
clip_box = pClipRgn->GetBox();
}
int src_bpp = pMask->GetBPP();
@@ -4282,7 +4283,7 @@ CFX_BitmapComposer::~CFX_BitmapComposer() {
FX_Free(m_pAddClipScan);
}
-void CFX_BitmapComposer::Compose(CFX_DIBitmap* pDest,
+void CFX_BitmapComposer::Compose(const CFX_RetainPtr<CFX_DIBitmap>& pDest,
const CFX_ClipRgn* pClipRgn,
int bitmap_alpha,
uint32_t mask_color,
@@ -4303,9 +4304,8 @@ void CFX_BitmapComposer::Compose(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().GetObject();
- }
+ if (pClipRgn && pClipRgn->GetType() != CFX_ClipRgn::RectI)
+ m_pClipMask = pClipRgn->GetMask();
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 aad3f343e2..624e1437e9 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_DIBSource* pBitmap);
+ bool BuildPalette(const CFX_RetainPtr<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_DIBSource* pBitmap) {
+bool CFX_Palette::BuildPalette(const CFX_RetainPtr<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_DIBSource* pSrcBitmap,
+ const CFX_RetainPtr<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_DIBSource* pSrcBitmap,
+ const CFX_RetainPtr<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_DIBSource* pSrcBitmap,
+ const CFX_RetainPtr<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_DIBSource* pSrcBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
int src_left,
int src_top) {
uint32_t* src_plt = pSrcBitmap->GetPalette();
@@ -263,13 +263,14 @@ 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_DIBSource* pSrcBitmap,
- int src_left,
- int src_top) {
+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) {
int Bpp = pSrcBitmap->GetBPP() / 8;
if (pSrcBitmap->IsCmykImage()) {
for (int row = 0; row < height; row++) {
@@ -304,7 +305,7 @@ void ConvertBuffer_IndexCopy(uint8_t* dest_buf,
int dest_pitch,
int width,
int height,
- const CFX_DIBSource* pSrcBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
int src_left,
int src_top) {
if (pSrcBitmap->GetBPP() == 1) {
@@ -333,7 +334,7 @@ bool ConvertBuffer_Plt2PltRgb8(uint8_t* dest_buf,
int dest_pitch,
int width,
int height,
- const CFX_DIBSource* pSrcBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
int src_left,
int src_top,
uint32_t* dst_plt) {
@@ -361,7 +362,7 @@ bool ConvertBuffer_Rgb2PltRgb8(uint8_t* dest_buf,
int dest_pitch,
int width,
int height,
- const CFX_DIBSource* pSrcBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
int src_left,
int src_top,
uint32_t* dst_plt) {
@@ -424,7 +425,7 @@ bool ConvertBuffer_1bppMask2Rgb(FXDIB_Format dst_format,
int dest_pitch,
int width,
int height,
- const CFX_DIBSource* pSrcBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
int src_left,
int src_top) {
int comps = (dst_format & 0xff) / 8;
@@ -455,7 +456,7 @@ bool ConvertBuffer_8bppMask2Rgb(FXDIB_Format dst_format,
int dest_pitch,
int width,
int height,
- const CFX_DIBSource* pSrcBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
int src_left,
int src_top) {
int comps = (dst_format & 0xff) / 8;
@@ -479,7 +480,7 @@ bool ConvertBuffer_1bppPlt2Rgb(FXDIB_Format dst_format,
int dest_pitch,
int width,
int height,
- const CFX_DIBSource* pSrcBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
int src_left,
int src_top) {
int comps = (dst_format & 0xff) / 8;
@@ -531,7 +532,7 @@ bool ConvertBuffer_8bppPlt2Rgb(FXDIB_Format dst_format,
int dest_pitch,
int width,
int height,
- const CFX_DIBSource* pSrcBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
int src_left,
int src_top) {
int comps = (dst_format & 0xff) / 8;
@@ -572,13 +573,14 @@ 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_DIBSource* pSrcBitmap,
- int src_left,
- int src_top) {
+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) {
for (int row = 0; row < height; row++) {
uint8_t* dest_scan = dest_buf + row * dest_pitch;
const uint8_t* src_scan =
@@ -588,13 +590,14 @@ bool ConvertBuffer_24bppRgb2Rgb24(uint8_t* dest_buf,
return true;
}
-bool ConvertBuffer_32bppRgb2Rgb24(uint8_t* dest_buf,
- int dest_pitch,
- int width,
- int height,
- const 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_RetainPtr<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 =
@@ -613,7 +616,7 @@ bool ConvertBuffer_Rgb2Rgb32(uint8_t* dest_buf,
int dest_pitch,
int width,
int height,
- const CFX_DIBSource* pSrcBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
int src_left,
int src_top) {
int comps = pSrcBitmap->GetBPP() / 8;
@@ -632,13 +635,14 @@ 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_DIBSource* pSrcBitmap,
- int src_left,
- int src_top) {
+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) {
for (int row = 0; row < height; row++) {
uint8_t* dest_scan = dest_buf + row * dest_pitch;
const uint8_t* src_scan =
@@ -658,7 +662,7 @@ bool ConvertBuffer(FXDIB_Format dest_format,
int dest_pitch,
int width,
int height,
- const CFX_DIBSource* pSrcBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
int src_left,
int src_top,
std::unique_ptr<uint32_t, FxFreeDeleter>* p_pal) {
@@ -783,16 +787,16 @@ bool ConvertBuffer(FXDIB_Format dest_format,
}
}
-std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::CloneConvert(
- FXDIB_Format dest_format) const {
+CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::CloneConvert(
+ FXDIB_Format dest_format) {
if (dest_format == GetFormat())
return Clone(nullptr);
- std::unique_ptr<CFX_DIBitmap> pClone = pdfium::MakeUnique<CFX_DIBitmap>();
+ auto pClone = pdfium::MakeRetain<CFX_DIBitmap>();
if (!pClone->Create(m_Width, m_Height, dest_format))
return nullptr;
- CFX_MaybeOwned<CFX_DIBitmap> pSrcAlpha;
+ CFX_RetainPtr<CFX_DIBitmap> pSrcAlpha;
if (HasAlpha()) {
if (GetFormat() == FXDIB_Argb)
pSrcAlpha = CloneAlphaMask();
@@ -805,19 +809,19 @@ std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::CloneConvert(
bool ret = true;
if (dest_format & 0x0200) {
if (dest_format == FXDIB_Argb) {
- ret = pSrcAlpha
- ? pClone->LoadChannel(FXDIB_Alpha, pSrcAlpha.Get(), FXDIB_Alpha)
- : pClone->LoadChannel(FXDIB_Alpha, 0xff);
+ ret = pSrcAlpha ? pClone->LoadChannel(FXDIB_Alpha, pSrcAlpha, FXDIB_Alpha)
+ : pClone->LoadChannel(FXDIB_Alpha, 0xff);
} else {
- ret = pClone->SetAlphaMask(pSrcAlpha.Get());
+ ret = pClone->SetAlphaMask(pSrcAlpha);
}
}
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, this, 0, 0, &pal_8bpp)) {
+ m_Width, m_Height, holder, 0, 0, &pal_8bpp)) {
return nullptr;
}
if (pal_8bpp)
@@ -853,7 +857,7 @@ bool CFX_DIBitmap::ConvertFormat(FXDIB_Format dest_format) {
if (!dest_buf) {
return false;
}
- CFX_DIBitmap* pAlphaMask = nullptr;
+ CFX_RetainPtr<CFX_DIBitmap> pAlphaMask;
if (dest_format == FXDIB_Argb) {
FXSYS_memset(dest_buf, 0xff, dest_pitch * m_Height + 4);
if (m_pAlphaMask) {
@@ -868,7 +872,7 @@ bool CFX_DIBitmap::ConvertFormat(FXDIB_Format dest_format) {
}
} else if (dest_format & 0x0200) {
if (src_format == FXDIB_Argb) {
- pAlphaMask = CloneAlphaMask().release();
+ pAlphaMask = CloneAlphaMask();
if (!pAlphaMask) {
FX_Free(dest_buf);
return false;
@@ -879,25 +883,21 @@ bool CFX_DIBitmap::ConvertFormat(FXDIB_Format dest_format) {
FX_Free(dest_buf);
return false;
}
- pAlphaMask = m_pAlphaMask;
- m_pAlphaMask = nullptr;
+ pAlphaMask = std::move(m_pAlphaMask);
} 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,
- this, 0, 0, &pal_8bpp);
+ holder, 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 5975a5e975..7aa710b795 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_DIBSource* pSrcBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
int flags) {
m_State = 0;
m_DestFormat = dest_format;
@@ -852,12 +852,13 @@ void CStretchEngine::StretchVert() {
}
}
-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)
+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)
: 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 705d761ca8..86df82442f 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));
- CPDF_DIBSource dib_source;
- dib_source.Load(nullptr, stream.get());
- CStretchEngine engine(nullptr, FXDIB_8bppRgb, 500, 500, clip_rect,
- &dib_source, 0);
+ 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);
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 96cae9d4e7..8a97d342b5 100644
--- a/core/fxge/dib/fx_dib_main.cpp
+++ b/core/fxge/dib/fx_dib_main.cpp
@@ -44,16 +44,9 @@ uint32_t ArgbEncode(int a, FX_COLORREF rgb) {
}
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;
-}
+ : m_Width(0), m_Height(0), m_bpp(0), m_AlphaFlag(0), m_Pitch(0) {}
+
+CFX_DIBSource::~CFX_DIBSource() {}
uint8_t* CFX_DIBSource::GetBuffer() const {
return nullptr;
@@ -127,7 +120,7 @@ bool CFX_DIBitmap::Create(int width,
return true;
}
-bool CFX_DIBitmap::Copy(const CFX_DIBSource* pSrc) {
+bool CFX_DIBitmap::Copy(const CFX_RetainPtr<CFX_DIBSource>& pSrc) {
if (m_pBuffer)
return false;
@@ -157,11 +150,10 @@ const uint8_t* CFX_DIBitmap::GetScanline(int line) const {
return m_pBuffer ? m_pBuffer + line * m_Pitch : nullptr;
}
-void CFX_DIBitmap::TakeOver(CFX_DIBitmap* pSrcBitmap) {
+void CFX_DIBitmap::TakeOver(CFX_RetainPtr<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;
@@ -175,14 +167,14 @@ void CFX_DIBitmap::TakeOver(CFX_DIBitmap* pSrcBitmap) {
m_Pitch = pSrcBitmap->m_Pitch;
}
-std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::Clone(const FX_RECT* pClip) const {
+CFX_RetainPtr<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::MakeUnique<CFX_DIBitmap>();
+ auto pNewBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
if (!pNewBitmap->Create(rect.Width(), rect.Height(), GetFormat()))
return nullptr;
@@ -240,12 +232,11 @@ void CFX_DIBSource::BuildPalette() {
}
bool CFX_DIBSource::BuildAlphaMask() {
- if (m_pAlphaMask) {
+ if (m_pAlphaMask)
return true;
- }
- m_pAlphaMask = new CFX_DIBitmap;
+
+ m_pAlphaMask = pdfium::MakeRetain<CFX_DIBitmap>();
if (!m_pAlphaMask->Create(m_Width, m_Height, FXDIB_8bppMask)) {
- delete m_pAlphaMask;
m_pAlphaMask = nullptr;
return false;
}
@@ -401,13 +392,14 @@ 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_DIBSource* pSrcBitmap,
- int src_left,
- int src_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) {
if (!m_pBuffer)
return false;
@@ -466,7 +458,7 @@ bool CFX_DIBitmap::TransferMask(int dest_left,
int dest_top,
int width,
int height,
- const CFX_DIBSource* pMask,
+ const CFX_RetainPtr<CFX_DIBSource>& pMask,
uint32_t color,
int src_left,
int src_top,
@@ -605,7 +597,7 @@ void CFX_DIBSource::GetPalette(uint32_t* pal, int alpha) const {
}
}
-std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::CloneAlphaMask(
+CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::CloneAlphaMask(
const FX_RECT* pClip) const {
ASSERT(GetFormat() == FXDIB_Argb);
FX_RECT rect(0, 0, m_Width, m_Height);
@@ -614,7 +606,7 @@ std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::CloneAlphaMask(
if (rect.IsEmpty())
return nullptr;
}
- auto pMask = pdfium::MakeUnique<CFX_DIBitmap>();
+ auto pMask = pdfium::MakeRetain<CFX_DIBitmap>();
if (!pMask->Create(rect.Width(), rect.Height(), FXDIB_8bppMask))
return nullptr;
@@ -630,7 +622,7 @@ std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::CloneAlphaMask(
return pMask;
}
-bool CFX_DIBSource::SetAlphaMask(const CFX_DIBSource* pAlphaMask,
+bool CFX_DIBSource::SetAlphaMask(const CFX_RetainPtr<CFX_DIBSource>& pAlphaMask,
const FX_RECT* pClip) {
if (!HasAlpha() || GetFormat() == FXDIB_Argb)
return false;
@@ -660,12 +652,12 @@ bool CFX_DIBSource::SetAlphaMask(const CFX_DIBSource* pAlphaMask,
const int g_ChannelOffset[] = {0, 2, 1, 0, 0, 1, 2, 3, 3};
bool CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel,
- CFX_DIBSource* pSrcBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
FXDIB_Channel srcChannel) {
if (!m_pBuffer)
return false;
- CFX_MaybeOwned<CFX_DIBSource> pSrcClone(pSrcBitmap);
+ CFX_RetainPtr<CFX_DIBSource> pSrcClone = pSrcBitmap;
int srcOffset;
if (srcChannel == FXDIB_Alpha) {
if (!pSrcBitmap->HasAlpha() && !pSrcBitmap->IsAlphaMask())
@@ -725,7 +717,7 @@ bool CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel,
destOffset = g_ChannelOffset[destChannel];
}
if (srcChannel == FXDIB_Alpha && pSrcClone->m_pAlphaMask) {
- CFX_MaybeOwned<CFX_DIBSource> pAlphaMask(pSrcClone->m_pAlphaMask);
+ CFX_RetainPtr<CFX_DIBSource> pAlphaMask = pSrcClone->m_pAlphaMask;
if (pSrcClone->GetWidth() != m_Width ||
pSrcClone->GetHeight() != m_Height) {
if (pAlphaMask) {
@@ -738,14 +730,14 @@ bool CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel,
srcOffset = 0;
} else if (pSrcClone->GetWidth() != m_Width ||
pSrcClone->GetHeight() != m_Height) {
- std::unique_ptr<CFX_DIBitmap> pSrcMatched =
+ CFX_RetainPtr<CFX_DIBitmap> pSrcMatched =
pSrcClone->StretchTo(m_Width, m_Height);
if (!pSrcMatched)
return false;
pSrcClone = std::move(pSrcMatched);
}
- CFX_DIBitmap* pDst = this;
+ CFX_RetainPtr<CFX_DIBitmap> pDst(this);
if (destChannel == FXDIB_Alpha && m_pAlphaMask) {
pDst = m_pAlphaMask;
destOffset = 0;
@@ -823,7 +815,8 @@ bool CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel, int value) {
return true;
}
-bool CFX_DIBitmap::MultiplyAlpha(CFX_DIBSource* pSrcBitmap) {
+bool CFX_DIBitmap::MultiplyAlpha(
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap) {
if (!m_pBuffer)
return false;
@@ -834,8 +827,7 @@ bool CFX_DIBitmap::MultiplyAlpha(CFX_DIBSource* pSrcBitmap) {
if (!IsAlphaMask() && !HasAlpha())
return LoadChannel(FXDIB_Alpha, pSrcBitmap, FXDIB_Alpha);
- CFX_MaybeOwned<CFX_DIBitmap> pSrcClone(
- static_cast<CFX_DIBitmap*>(pSrcBitmap));
+ CFX_RetainPtr<CFX_DIBitmap> pSrcClone = pSrcBitmap.As<CFX_DIBitmap>();
if (pSrcBitmap->GetWidth() != m_Width ||
pSrcBitmap->GetHeight() != m_Height) {
pSrcClone = pSrcBitmap->StretchTo(m_Width, m_Height);
@@ -875,7 +867,7 @@ bool CFX_DIBitmap::MultiplyAlpha(CFX_DIBSource* pSrcBitmap) {
}
}
} else {
- m_pAlphaMask->MultiplyAlpha(pSrcClone.Get());
+ m_pAlphaMask->MultiplyAlpha(pSrcClone);
}
}
return true;
@@ -887,9 +879,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);
@@ -897,11 +889,10 @@ 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));
}
- CFX_DIBitmap* pMask = new CFX_DIBitmap;
- if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) {
- delete pMask;
+ auto pMask = pdfium::MakeRetain<CFX_DIBitmap>();
+ if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask))
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;
@@ -913,14 +904,13 @@ bool CFX_DIBitmap::GetGrayData(void* pIccTransform) {
dest_pos++;
}
}
- TakeOver(pMask);
- delete pMask;
+ TakeOver(std::move(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);
@@ -928,11 +918,10 @@ 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));
}
- CFX_DIBitmap* pMask = new CFX_DIBitmap;
- if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) {
- delete pMask;
+ auto pMask = pdfium::MakeRetain<CFX_DIBitmap>();
+ if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask))
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;
@@ -940,16 +929,14 @@ bool CFX_DIBitmap::GetGrayData(void* pIccTransform) {
*dest_pos++ = gray[*src_pos++];
}
}
- TakeOver(pMask);
- delete pMask;
+ TakeOver(std::move(pMask));
break;
}
case FXDIB_Rgb: {
- CFX_DIBitmap* pMask = new CFX_DIBitmap;
- if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) {
- delete pMask;
+ auto pMask = pdfium::MakeRetain<CFX_DIBitmap>();
+ if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask))
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();
@@ -958,16 +945,14 @@ bool CFX_DIBitmap::GetGrayData(void* pIccTransform) {
src_pos += 3;
}
}
- TakeOver(pMask);
- delete pMask;
+ TakeOver(std::move(pMask));
break;
}
case FXDIB_Rgb32: {
- CFX_DIBitmap* pMask = new CFX_DIBitmap;
- if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) {
- delete pMask;
+ auto pMask = pdfium::MakeRetain<CFX_DIBitmap>();
+ if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask))
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();
@@ -976,8 +961,7 @@ bool CFX_DIBitmap::GetGrayData(void* pIccTransform) {
src_pos += 4;
}
}
- TakeOver(pMask);
- delete pMask;
+ TakeOver(std::move(pMask));
break;
}
default:
@@ -1342,9 +1326,9 @@ bool CFX_DIBitmap::ConvertColorScale(uint32_t forecolor, uint32_t backcolor) {
return true;
}
-std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::FlipImage(bool bXFlip,
- bool bYFlip) const {
- auto pFlipped = pdfium::MakeUnique<CFX_DIBitmap>();
+CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::FlipImage(bool bXFlip,
+ bool bYFlip) const {
+ auto pFlipped = pdfium::MakeRetain<CFX_DIBitmap>();
if (!pFlipped->Create(m_Width, m_Height, GetFormat()))
return nullptr;
@@ -1414,12 +1398,12 @@ std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::FlipImage(bool bXFlip,
return pFlipped;
}
-CFX_DIBExtractor::CFX_DIBExtractor(const CFX_DIBSource* pSrc) {
+CFX_DIBExtractor::CFX_DIBExtractor(const CFX_RetainPtr<CFX_DIBSource>& pSrc) {
if (pSrc->GetBuffer()) {
- m_pBitmap = pdfium::MakeUnique<CFX_DIBitmap>();
+ m_pBitmap = pdfium::MakeRetain<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());
@@ -1431,17 +1415,12 @@ CFX_DIBExtractor::CFX_DIBExtractor(const CFX_DIBSource* pSrc) {
CFX_DIBExtractor::~CFX_DIBExtractor() {}
-CFX_FilteredDIB::CFX_FilteredDIB() : m_pSrc(nullptr) {}
+CFX_FilteredDIB::CFX_FilteredDIB() {}
-CFX_FilteredDIB::~CFX_FilteredDIB() {
- if (m_bAutoDropSrc) {
- delete m_pSrc;
- }
-}
+CFX_FilteredDIB::~CFX_FilteredDIB() {}
-void CFX_FilteredDIB::LoadSrc(const CFX_DIBSource* pSrc, bool bAutoDropSrc) {
+void CFX_FilteredDIB::LoadSrc(const CFX_RetainPtr<CFX_DIBSource>& pSrc) {
m_pSrc = pSrc;
- m_bAutoDropSrc = bAutoDropSrc;
m_Width = pSrc->GetWidth();
m_Height = pSrc->GetHeight();
FXDIB_Format format = GetDestFormat();
@@ -1478,9 +1457,9 @@ CFX_ImageRenderer::CFX_ImageRenderer() {
CFX_ImageRenderer::~CFX_ImageRenderer() {}
-bool CFX_ImageRenderer::Start(CFX_DIBitmap* pDevice,
+bool CFX_ImageRenderer::Start(const CFX_RetainPtr<CFX_DIBitmap>& pDevice,
const CFX_ClipRgn* pClipRgn,
- const CFX_DIBSource* pSource,
+ const CFX_RetainPtr<CFX_DIBSource>& pSource,
int bitmap_alpha,
uint32_t mask_color,
const CFX_Matrix* pMatrix,
@@ -1569,7 +1548,7 @@ bool CFX_ImageRenderer::Continue(IFX_Pause* pPause) {
if (m_pTransformer->Continue(pPause))
return true;
- std::unique_ptr<CFX_DIBitmap> pBitmap(m_pTransformer->DetachBitmap());
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap = m_pTransformer->DetachBitmap();
if (!pBitmap || !pBitmap->GetBuffer())
return false;
@@ -1585,16 +1564,16 @@ bool CFX_ImageRenderer::Continue(IFX_Pause* pPause) {
}
m_pDevice->CompositeMask(
m_pTransformer->result().left, m_pTransformer->result().top,
- pBitmap->GetWidth(), pBitmap->GetHeight(), pBitmap.get(), m_MaskColor,
- 0, 0, m_BlendType, m_pClipRgn, m_bRgbByteOrder, m_AlphaFlag,
+ pBitmap->GetWidth(), pBitmap->GetHeight(), pBitmap, 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.get(), 0, 0,
- m_BlendType, m_pClipRgn, m_bRgbByteOrder, m_pIccTransform);
+ pBitmap->GetWidth(), pBitmap->GetHeight(), pBitmap, 0, 0, m_BlendType,
+ m_pClipRgn, m_bRgbByteOrder, m_pIccTransform);
}
return false;
}
@@ -1607,11 +1586,11 @@ CFX_BitmapStorer::CFX_BitmapStorer() {
CFX_BitmapStorer::~CFX_BitmapStorer() {
}
-std::unique_ptr<CFX_DIBitmap> CFX_BitmapStorer::Detach() {
+CFX_RetainPtr<CFX_DIBitmap> CFX_BitmapStorer::Detach() {
return std::move(m_pBitmap);
}
-void CFX_BitmapStorer::Replace(std::unique_ptr<CFX_DIBitmap> pBitmap) {
+void CFX_BitmapStorer::Replace(CFX_RetainPtr<CFX_DIBitmap>&& pBitmap) {
m_pBitmap = std::move(pBitmap);
}
@@ -1636,12 +1615,13 @@ bool CFX_BitmapStorer::SetInfo(int width,
int height,
FXDIB_Format src_format,
uint32_t* pSrcPalette) {
- m_pBitmap = pdfium::MakeUnique<CFX_DIBitmap>();
- if (!m_pBitmap->Create(width, height, src_format)) {
- m_pBitmap.reset();
+ auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ if (!pBitmap->Create(width, height, src_format))
return false;
- }
+
if (pSrcPalette)
- m_pBitmap->SetPalette(pSrcPalette);
+ pBitmap->SetPalette(pSrcPalette);
+
+ m_pBitmap = std::move(pBitmap);
return true;
}
diff --git a/core/fxge/dib/fx_dib_transform.cpp b/core/fxge/dib/fx_dib_transform.cpp
index 4a1c3ee050..3d8ddf8783 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_DIBSource* pDrc) {
+FXDIB_Format GetTransformedFormat(const CFX_RetainPtr<CFX_DIBSource>& pDrc) {
FXDIB_Format format = pDrc->GetFormat();
if (pDrc->IsAlphaMask()) {
format = FXDIB_8bppMask;
@@ -179,7 +179,7 @@ class CFX_BilinearMatrix : public CPDF_FixedMatrix {
}
};
-std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::SwapXY(
+CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::SwapXY(
bool bXFlip,
bool bYFlip,
const FX_RECT* pDestClip) const {
@@ -189,7 +189,7 @@ std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::SwapXY(
if (dest_clip.IsEmpty())
return nullptr;
- auto pTransBitmap = pdfium::MakeUnique<CFX_DIBitmap>();
+ auto pTransBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
int result_height = dest_clip.Height();
int result_width = dest_clip.Width();
if (!pTransBitmap->Create(result_width, result_height, GetFormat()))
@@ -303,13 +303,14 @@ FX_RECT FXDIB_SwapClipBox(FX_RECT& clip,
return rect;
}
-std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::TransformTo(
+CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::TransformTo(
const CFX_Matrix* pDestMatrix,
int& result_left,
int& result_top,
uint32_t flags,
- const FX_RECT* pDestClip) const {
- CFX_ImageTransformer transformer(this, pDestMatrix, flags, pDestClip);
+ const FX_RECT* pDestClip) {
+ CFX_RetainPtr<CFX_DIBSource> holder(this);
+ CFX_ImageTransformer transformer(holder, pDestMatrix, flags, pDestClip);
transformer.Start();
transformer.Continue(nullptr);
result_left = transformer.result().left;
@@ -317,11 +318,11 @@ std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::TransformTo(
return transformer.DetachBitmap();
}
-std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::StretchTo(
- int dest_width,
- int dest_height,
- uint32_t flags,
- const FX_RECT* pClip) const {
+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);
FX_RECT clip_rect(0, 0, FXSYS_abs(dest_width), FXSYS_abs(dest_height));
if (pClip)
clip_rect.Intersect(*pClip);
@@ -333,7 +334,7 @@ std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::StretchTo(
return Clone(&clip_rect);
CFX_BitmapStorer storer;
- CFX_ImageStretcher stretcher(&storer, this, dest_width, dest_height,
+ CFX_ImageStretcher stretcher(&storer, holder, dest_width, dest_height,
clip_rect, flags);
if (stretcher.Start())
stretcher.Continue(nullptr);
@@ -341,10 +342,11 @@ std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::StretchTo(
return storer.Detach();
}
-CFX_ImageTransformer::CFX_ImageTransformer(const CFX_DIBSource* pSrc,
- const CFX_Matrix* pMatrix,
- int flags,
- const FX_RECT* pClip)
+CFX_ImageTransformer::CFX_ImageTransformer(
+ const CFX_RetainPtr<CFX_DIBSource>& pSrc,
+ const CFX_Matrix* pMatrix,
+ int flags,
+ const FX_RECT* pClip)
: m_pSrc(pSrc),
m_pMatrix(pMatrix),
m_pClip(pClip),
@@ -444,7 +446,7 @@ bool CFX_ImageTransformer::Continue(IFX_Pause* pPause) {
stretch_buf_mask = m_Storer.GetBitmap()->m_pAlphaMask->GetBuffer();
int stretch_pitch = m_Storer.GetBitmap()->GetPitch();
- std::unique_ptr<CFX_DIBitmap> pTransformed(new CFX_DIBitmap);
+ auto pTransformed = pdfium::MakeRetain<CFX_DIBitmap>();
FXDIB_Format transformF = GetTransformedFormat(m_Stretcher->source());
if (!pTransformed->Create(m_result.Width(), m_result.Height(), transformF))
return false;
@@ -958,6 +960,6 @@ bool CFX_ImageTransformer::Continue(IFX_Pause* pPause) {
return false;
}
-std::unique_ptr<CFX_DIBitmap> CFX_ImageTransformer::DetachBitmap() {
+CFX_RetainPtr<CFX_DIBitmap> CFX_ImageTransformer::DetachBitmap() {
return m_Storer.Detach();
}
diff --git a/core/fxge/fx_dib.h b/core/fxge/fx_dib.h
index 14be05fafe..2208276fa7 100644
--- a/core/fxge/fx_dib.h
+++ b/core/fxge/fx_dib.h
@@ -10,9 +10,10 @@
#include <memory>
#include <vector>
-#include "core/fxcrt/cfx_shared_copy_on_write.h"
+#include "core/fxcrt/cfx_retain_ptr.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,
@@ -163,14 +164,14 @@ bool ConvertBuffer(FXDIB_Format dest_format,
int dest_pitch,
int width,
int height,
- const CFX_DIBSource* pSrcBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
int src_left,
int src_top,
std::unique_ptr<uint32_t, FxFreeDeleter>* pal);
-class CFX_DIBSource {
+class CFX_DIBSource : public CFX_Retainable {
public:
- virtual ~CFX_DIBSource();
+ ~CFX_DIBSource() override;
virtual uint8_t* GetBuffer() const;
virtual const uint8_t* GetScanline(int line) const = 0;
@@ -216,31 +217,29 @@ class CFX_DIBSource {
// Copies into internally-owned palette.
void SetPalette(const uint32_t* pSrcPal);
- 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,
+ 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,
uint32_t flags = 0,
- 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;
+ 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;
- std::unique_ptr<CFX_DIBitmap> CloneAlphaMask(
+ CFX_RetainPtr<CFX_DIBitmap> CloneAlphaMask(
const FX_RECT* pClip = nullptr) const;
// Copies into internally-owned mask.
- bool SetAlphaMask(const CFX_DIBSource* pAlphaMask,
+ bool SetAlphaMask(const CFX_RetainPtr<CFX_DIBSource>& pAlphaMask,
const FX_RECT* pClip = nullptr);
-
void GetOverlapRect(int& dest_left,
int& dest_top,
int& width,
@@ -255,7 +254,7 @@ class CFX_DIBSource {
void DebugVerifyBitmapIsPreMultiplied(void* buffer = nullptr) const;
#endif
- CFX_DIBitmap* m_pAlphaMask;
+ CFX_RetainPtr<CFX_DIBitmap> m_pAlphaMask;
protected:
CFX_DIBSource();
@@ -276,8 +275,9 @@ class CFX_DIBSource {
class CFX_DIBitmap : public CFX_DIBSource {
public:
- CFX_DIBitmap();
- explicit CFX_DIBitmap(const CFX_DIBitmap& src);
+ template <typename T, typename... Args>
+ friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args);
+
~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_DIBSource* pSrc);
+ bool Copy(const CFX_RetainPtr<CFX_DIBSource>& pSrc);
// CFX_DIBSource
uint8_t* GetBuffer() const override;
@@ -299,31 +299,26 @@ class CFX_DIBitmap : public CFX_DIBSource {
int clip_left,
int clip_width) const override;
- void TakeOver(CFX_DIBitmap* pSrcBitmap);
-
+ void TakeOver(CFX_RetainPtr<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,
- CFX_DIBSource* pSrcBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
FXDIB_Channel srcChannel);
-
bool LoadChannel(FXDIB_Channel destChannel, int value);
bool MultiplyAlpha(int alpha);
-
- bool MultiplyAlpha(CFX_DIBSource* pAlphaMask);
+ bool MultiplyAlpha(const CFX_RetainPtr<CFX_DIBSource>& pAlphaMask);
bool TransferBitmap(int dest_left,
int dest_top,
int width,
int height,
- const CFX_DIBSource* pSrcBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
int src_left,
int src_top);
@@ -331,7 +326,7 @@ class CFX_DIBitmap : public CFX_DIBSource {
int dest_top,
int width,
int height,
- const CFX_DIBSource* pSrcBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap,
int src_left,
int src_top,
int blend_type = FXDIB_BLEND_NORMAL,
@@ -343,7 +338,7 @@ class CFX_DIBitmap : public CFX_DIBSource {
int dest_top,
int width,
int height,
- const CFX_DIBSource* pMask,
+ const CFX_RetainPtr<CFX_DIBSource>& pMask,
uint32_t color,
int src_left,
int src_top,
@@ -354,7 +349,7 @@ class CFX_DIBitmap : public CFX_DIBSource {
int dest_top,
int width,
int height,
- const CFX_DIBSource* pMask,
+ const CFX_RetainPtr<CFX_DIBSource>& pMask,
uint32_t color,
int src_left,
int src_top,
@@ -382,6 +377,8 @@ 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_
@@ -397,37 +394,36 @@ class CFX_DIBitmap : public CFX_DIBSource {
class CFX_DIBExtractor {
public:
- explicit CFX_DIBExtractor(const CFX_DIBSource* pSrc);
+ explicit CFX_DIBExtractor(const CFX_RetainPtr<CFX_DIBSource>& pSrc);
~CFX_DIBExtractor();
- CFX_DIBitmap* GetBitmap() { return m_pBitmap.get(); }
+ CFX_RetainPtr<CFX_DIBitmap> GetBitmap() { return m_pBitmap; }
private:
- std::unique_ptr<CFX_DIBitmap> m_pBitmap;
+ CFX_RetainPtr<CFX_DIBitmap> m_pBitmap;
};
-typedef CFX_SharedCopyOnWrite<CFX_DIBitmap> CFX_DIBitmapRef;
-
class CFX_FilteredDIB : public CFX_DIBSource {
public:
- CFX_FilteredDIB();
- ~CFX_FilteredDIB() override;
+ template <typename T, typename... Args>
+ friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args);
- void LoadSrc(const CFX_DIBSource* pSrc, bool bAutoDropSrc = false);
+ ~CFX_FilteredDIB() override;
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,
@@ -438,8 +434,7 @@ class CFX_FilteredDIB : public CFX_DIBSource {
int clip_left,
int clip_width) const override;
- const CFX_DIBSource* m_pSrc;
- bool m_bAutoDropSrc;
+ CFX_RetainPtr<CFX_DIBSource> m_pSrc;
mutable std::vector<uint8_t> m_Scanline;
};
@@ -520,7 +515,7 @@ class CFX_BitmapComposer : public IFX_ScanlineComposer {
CFX_BitmapComposer();
~CFX_BitmapComposer() override;
- void Compose(CFX_DIBitmap* pDest,
+ void Compose(const CFX_RetainPtr<CFX_DIBitmap>& pDest,
const CFX_ClipRgn* pClipRgn,
int bitmap_alpha,
uint32_t mask_color,
@@ -550,21 +545,28 @@ class CFX_BitmapComposer : public IFX_ScanlineComposer {
const uint8_t* clip_scan,
const uint8_t* src_extra_alpha = nullptr,
uint8_t* dst_extra_alpha = nullptr);
- CFX_DIBitmap* m_pBitmap;
+ void ComposeScanlineV(int line,
+ const uint8_t* scanline,
+ const uint8_t* scan_extra_alpha = nullptr);
+
+ CFX_RetainPtr<CFX_DIBitmap> m_pBitmap;
const CFX_ClipRgn* m_pClipRgn;
FXDIB_Format m_SrcFormat;
- int m_DestLeft, m_DestTop, m_DestWidth, m_DestHeight, m_BitmapAlpha;
+ int m_DestLeft;
+ int m_DestTop;
+ int m_DestWidth;
+ int m_DestHeight;
+ int m_BitmapAlpha;
uint32_t m_MaskColor;
- const CFX_DIBitmap* m_pClipMask;
+ CFX_RetainPtr<CFX_DIBitmap> m_pClipMask;
CFX_ScanlineCompositor m_Compositor;
- bool m_bVertical, m_bFlipX, m_bFlipY;
+ bool m_bVertical;
+ bool m_bFlipX;
+ bool 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;
@@ -585,18 +587,18 @@ class CFX_BitmapStorer : public IFX_ScanlineComposer {
FXDIB_Format src_format,
uint32_t* pSrcPalette) override;
- CFX_DIBitmap* GetBitmap() { return m_pBitmap.get(); }
- std::unique_ptr<CFX_DIBitmap> Detach();
- void Replace(std::unique_ptr<CFX_DIBitmap> pBitmap);
+ CFX_RetainPtr<CFX_DIBitmap> GetBitmap() { return m_pBitmap; }
+ CFX_RetainPtr<CFX_DIBitmap> Detach();
+ void Replace(CFX_RetainPtr<CFX_DIBitmap>&& pBitmap);
private:
- std::unique_ptr<CFX_DIBitmap> m_pBitmap;
+ CFX_RetainPtr<CFX_DIBitmap> m_pBitmap;
};
class CFX_ImageStretcher {
public:
CFX_ImageStretcher(IFX_ScanlineComposer* pDest,
- const CFX_DIBSource* pSource,
+ const CFX_RetainPtr<CFX_DIBSource>& pSource,
int dest_width,
int dest_height,
const FX_RECT& bitmap_rect,
@@ -606,7 +608,7 @@ class CFX_ImageStretcher {
bool Start();
bool Continue(IFX_Pause* pPause);
- const CFX_DIBSource* source() { return m_pSource; }
+ CFX_RetainPtr<CFX_DIBSource> source() { return m_pSource; }
private:
bool StartQuickStretch();
@@ -615,7 +617,7 @@ class CFX_ImageStretcher {
bool ContinueStretch(IFX_Pause* pPause);
IFX_ScanlineComposer* const m_pDest;
- const CFX_DIBSource* const m_pSource;
+ CFX_RetainPtr<CFX_DIBSource> m_pSource;
std::unique_ptr<CStretchEngine> m_pStretchEngine;
std::unique_ptr<uint8_t, FxFreeDeleter> m_pScanline;
std::unique_ptr<uint8_t, FxFreeDeleter> m_pMaskScanline;
@@ -632,7 +634,7 @@ class CFX_ImageStretcher {
class CFX_ImageTransformer {
public:
- CFX_ImageTransformer(const CFX_DIBSource* pSrc,
+ CFX_ImageTransformer(const CFX_RetainPtr<CFX_DIBSource>& pSrc,
const CFX_Matrix* pMatrix,
int flags,
const FX_RECT* pClip);
@@ -642,10 +644,10 @@ class CFX_ImageTransformer {
bool Continue(IFX_Pause* pPause);
const FX_RECT& result() const { return m_result; }
- std::unique_ptr<CFX_DIBitmap> DetachBitmap();
+ CFX_RetainPtr<CFX_DIBitmap> DetachBitmap();
private:
- const CFX_DIBSource* const m_pSrc;
+ const CFX_RetainPtr<CFX_DIBSource> m_pSrc;
const CFX_Matrix* const m_pMatrix;
const FX_RECT* const m_pClip;
FX_RECT m_StretchClip;
@@ -662,9 +664,9 @@ class CFX_ImageRenderer {
CFX_ImageRenderer();
~CFX_ImageRenderer();
- bool Start(CFX_DIBitmap* pDevice,
+ bool Start(const CFX_RetainPtr<CFX_DIBitmap>& pDevice,
const CFX_ClipRgn* pClipRgn,
- const CFX_DIBSource* pSource,
+ const CFX_RetainPtr<CFX_DIBSource>& pSource,
int bitmap_alpha,
uint32_t mask_color,
const CFX_Matrix* pMatrix,
@@ -677,7 +679,7 @@ class CFX_ImageRenderer {
bool Continue(IFX_Pause* pPause);
protected:
- CFX_DIBitmap* m_pDevice;
+ CFX_RetainPtr<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 79957ef506..880b6751e8 100644
--- a/core/fxge/fx_font.h
+++ b/core/fxge/fx_font.h
@@ -222,11 +222,19 @@ class CFX_FontFaceInfo {
class CFX_GlyphBitmap {
public:
+ CFX_GlyphBitmap();
+ ~CFX_GlyphBitmap();
+
int m_Top;
int m_Left;
- CFX_DIBitmap m_Bitmap;
+ CFX_RetainPtr<CFX_DIBitmap> m_pBitmap;
};
+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 ea3eb51f18..5193ce2944 100644
--- a/core/fxge/ge/cfx_cliprgn.cpp
+++ b/core/fxge/ge/cfx_cliprgn.cpp
@@ -6,6 +6,8 @@
#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) {}
@@ -20,7 +22,7 @@ CFX_ClipRgn::~CFX_ClipRgn() {}
void CFX_ClipRgn::Reset(const FX_RECT& rect) {
m_Type = RectI;
m_Box = rect;
- m_Mask.SetNull();
+ m_Mask = nullptr;
}
void CFX_ClipRgn::IntersectRect(const FX_RECT& rect) {
@@ -36,8 +38,7 @@ void CFX_ClipRgn::IntersectRect(const FX_RECT& rect) {
void CFX_ClipRgn::IntersectMaskRect(FX_RECT rect,
FX_RECT mask_rect,
- CFX_DIBitmapRef Mask) {
- const CFX_DIBitmap* mask_dib = Mask.GetObject();
+ const CFX_RetainPtr<CFX_DIBitmap>& pMask) {
m_Type = MaskF;
m_Box = rect;
m_Box.Intersect(mask_rect);
@@ -46,28 +47,29 @@ void CFX_ClipRgn::IntersectMaskRect(FX_RECT rect,
return;
}
if (m_Box == mask_rect) {
- m_Mask = Mask;
+ m_Mask = pMask;
return;
}
- CFX_DIBitmap* new_dib = m_Mask.Emplace();
- new_dib->Create(m_Box.Width(), m_Box.Height(), FXDIB_8bppMask);
+ m_Mask = pdfium::MakeRetain<CFX_DIBitmap>();
+ m_Mask->Create(m_Box.Width(), m_Box.Height(), FXDIB_8bppMask);
for (int row = m_Box.top; row < m_Box.bottom; row++) {
uint8_t* dest_scan =
- new_dib->GetBuffer() + new_dib->GetPitch() * (row - m_Box.top);
+ m_Mask->GetBuffer() + m_Mask->GetPitch() * (row - m_Box.top);
uint8_t* src_scan =
- mask_dib->GetBuffer() + mask_dib->GetPitch() * (row - mask_rect.top);
+ pMask->GetBuffer() + pMask->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, 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());
+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());
if (m_Type == RectI) {
- IntersectMaskRect(m_Box, mask_box, Mask);
+ IntersectMaskRect(m_Box, mask_box, pMask);
return;
}
if (m_Type == MaskF) {
@@ -75,19 +77,16 @@ void CFX_ClipRgn::IntersectMaskF(int left, int top, CFX_DIBitmapRef Mask) {
new_box.Intersect(mask_box);
if (new_box.IsEmpty()) {
m_Type = RectI;
- m_Mask.SetNull();
+ m_Mask = nullptr;
m_Box = new_box;
return;
}
- CFX_DIBitmapRef new_mask;
- CFX_DIBitmap* new_dib = new_mask.Emplace();
+ auto new_dib = pdfium::MakeRetain<CFX_DIBitmap>();
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 =
- old_dib->GetBuffer() + (row - m_Box.top) * old_dib->GetPitch();
- uint8_t* mask_scan =
- mask_dib->GetBuffer() + (row - top) * mask_dib->GetPitch();
+ m_Mask->GetBuffer() + (row - m_Box.top) * m_Mask->GetPitch();
+ uint8_t* mask_scan = pMask->GetBuffer() + (row - top) * pMask->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++) {
@@ -96,7 +95,7 @@ void CFX_ClipRgn::IntersectMaskF(int left, int top, CFX_DIBitmapRef Mask) {
}
}
m_Box = new_box;
- m_Mask = new_mask;
+ m_Mask = std::move(new_dib);
return;
}
ASSERT(false);
diff --git a/core/fxge/ge/cfx_cliprgn.h b/core/fxge/ge/cfx_cliprgn.h
index f3fd5856b6..ae12347288 100644
--- a/core/fxge/ge/cfx_cliprgn.h
+++ b/core/fxge/ge/cfx_cliprgn.h
@@ -19,18 +19,22 @@ class CFX_ClipRgn {
ClipType GetType() const { return m_Type; }
const FX_RECT& GetBox() const { return m_Box; }
- CFX_DIBitmapRef GetMask() const { return m_Mask; }
+ CFX_RetainPtr<CFX_DIBitmap> GetMask() const { return m_Mask; }
void Reset(const FX_RECT& rect);
void IntersectRect(const FX_RECT& rect);
- void IntersectMaskF(int left, int top, CFX_DIBitmapRef Mask);
+ void IntersectMaskF(int left,
+ int top,
+ const CFX_RetainPtr<CFX_DIBitmap>& Mask);
private:
- void IntersectMaskRect(FX_RECT rect, FX_RECT mask_box, CFX_DIBitmapRef Mask);
+ void IntersectMaskRect(FX_RECT rect,
+ FX_RECT mask_box,
+ const CFX_RetainPtr<CFX_DIBitmap>& Mask);
ClipType m_Type;
FX_RECT m_Box;
- CFX_DIBitmapRef m_Mask;
+ CFX_RetainPtr<CFX_DIBitmap> 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 3cdff44f8b..4c44660426 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_Bitmap.Create(
+ pGlyphBitmap->m_pBitmap->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_Bitmap.GetPitch();
+ int dest_pitch = pGlyphBitmap->m_pBitmap->GetPitch();
int src_pitch = FXFT_Get_Bitmap_Pitch(FXFT_Get_Glyph_Bitmap(m_Face));
- uint8_t* pDestBuf = pGlyphBitmap->m_Bitmap.GetBuffer();
+ uint8_t* pDestBuf = pGlyphBitmap->m_pBitmap->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 fab318373a..782dbf3e2f 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(CFX_DIBitmap* bitmap,
- const CFX_DIBitmap* pGlyph,
+void DrawNormalTextHelper(const CFX_RetainPtr<CFX_DIBitmap>& bitmap,
+ const CFX_RetainPtr<CFX_DIBitmap>& pGlyph,
int nrows,
int left,
int top,
@@ -416,9 +416,10 @@ CFX_Matrix CFX_RenderDevice::GetCTM() const {
return m_pDeviceDriver->GetCTM();
}
-bool CFX_RenderDevice::CreateCompatibleBitmap(CFX_DIBitmap* pDIB,
- int width,
- int height) const {
+bool CFX_RenderDevice::CreateCompatibleBitmap(
+ const CFX_RetainPtr<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
@@ -610,21 +611,23 @@ 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();
- CFX_DIBitmap bitmap, Backdrop;
- if (!CreateCompatibleBitmap(&bitmap, FXSYS_round(rect.Width() * fScaleX),
+ auto bitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ auto Backdrop = pdfium::MakeRetain<CFX_DIBitmap>();
+ 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;
@@ -640,7 +643,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);
}
@@ -661,19 +664,19 @@ bool CFX_RenderDevice::FillRectWithBlend(const FX_RECT* pRect,
if (!(m_RenderCaps & FXRC_GET_BITS))
return false;
- CFX_DIBitmap bitmap;
- if (!CreateCompatibleBitmap(&bitmap, pRect->Width(), pRect->Height()))
+ auto bitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ 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;
}
@@ -697,20 +700,23 @@ bool CFX_RenderDevice::DrawCosmeticLine(float x1,
fill_mode, blend_type);
}
-bool CFX_RenderDevice::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) {
+bool CFX_RenderDevice::GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ int left,
+ int top) {
if (!(m_RenderCaps & FXRC_GET_BITS))
return false;
return m_pDeviceDriver->GetDIBits(pBitmap, left, top);
}
-CFX_DIBitmap* CFX_RenderDevice::GetBackDrop() {
+CFX_RetainPtr<CFX_DIBitmap> CFX_RenderDevice::GetBackDrop() {
return m_pDeviceDriver->GetBackDrop();
}
-bool CFX_RenderDevice::SetDIBitsWithBlend(const CFX_DIBSource* pBitmap,
- int left,
- int top,
- int blend_mode) {
+bool CFX_RenderDevice::SetDIBitsWithBlend(
+ const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ int left,
+ int top,
+ int blend_mode) {
ASSERT(!pBitmap->IsAlphaMask());
CFX_Matrix ctm = GetCTM();
float fScaleX = FXSYS_fabs(ctm.a);
@@ -721,6 +727,7 @@ bool CFX_RenderDevice::SetDIBitsWithBlend(const CFX_DIBSource* pBitmap,
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());
@@ -732,25 +739,26 @@ bool CFX_RenderDevice::SetDIBitsWithBlend(const CFX_DIBSource* pBitmap,
(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);
- CFX_DIBitmap background;
- if (!background.Create(
+ auto background = pdfium::MakeRetain<CFX_DIBitmap>();
+ 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,
@@ -758,7 +766,7 @@ bool CFX_RenderDevice::SetDIBitsWithBlend(const CFX_DIBSource* pBitmap,
}
bool CFX_RenderDevice::StretchDIBitsWithFlagsAndBlend(
- const CFX_DIBSource* pBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
int left,
int top,
int dest_width,
@@ -775,7 +783,7 @@ bool CFX_RenderDevice::StretchDIBitsWithFlagsAndBlend(
blend_mode);
}
-bool CFX_RenderDevice::SetBitMask(const CFX_DIBSource* pBitmap,
+bool CFX_RenderDevice::SetBitMask(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
int left,
int top,
uint32_t argb) {
@@ -784,23 +792,25 @@ bool CFX_RenderDevice::SetBitMask(const CFX_DIBSource* pBitmap,
FXDIB_BLEND_NORMAL);
}
-bool CFX_RenderDevice::StretchBitMask(const CFX_DIBSource* pBitmap,
- int left,
- int top,
- int dest_width,
- int dest_height,
- uint32_t color) {
+bool CFX_RenderDevice::StretchBitMask(
+ const CFX_RetainPtr<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_DIBSource* pBitmap,
- int left,
- int top,
- int dest_width,
- int dest_height,
- uint32_t argb,
- uint32_t flags) {
+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) {
FX_RECT dest_rect(left, top, left + dest_width, top + dest_height);
FX_RECT clip_box = m_ClipBox;
clip_box.Intersect(dest_rect);
@@ -809,13 +819,14 @@ bool CFX_RenderDevice::StretchBitMaskWithFlags(const CFX_DIBSource* pBitmap,
FXDIB_BLEND_NORMAL);
}
-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) {
+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) {
return m_pDeviceDriver->StartDIBits(pBitmap, bitmap_alpha, argb, pMatrix,
flags, handle, blend_mode);
}
@@ -833,12 +844,13 @@ void CFX_RenderDevice::DebugVerifyBitmapIsPreMultiplied() const {
SkASSERT(0);
}
-bool CFX_RenderDevice::SetBitsWithMask(const CFX_DIBSource* pBitmap,
- const CFX_DIBSource* pMask,
- int left,
- int top,
- int bitmap_alpha,
- int blend_type) {
+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) {
return m_pDeviceDriver->SetBitsWithMask(pBitmap, pMask, left, top,
bitmap_alpha, blend_type);
}
@@ -964,42 +976,43 @@ 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) {
- CFX_DIBitmap bitmap;
- if (!bitmap.Create(pixel_width, pixel_height, FXDIB_1bppMask))
+ auto bitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ 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;
- const CFX_DIBitmap* pGlyph = &glyph.m_pGlyph->m_Bitmap;
- bitmap.TransferBitmap(
+ CFX_RetainPtr<CFX_DIBitmap> pGlyph = glyph.m_pGlyph->m_pBitmap;
+ 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);
}
- CFX_DIBitmap bitmap;
+ auto bitmap = pdfium::MakeRetain<CFX_DIBitmap>();
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;
@@ -1025,14 +1038,14 @@ bool CFX_RenderDevice::DrawNormalText(int nChars,
if (!top.IsValid())
return false;
- const CFX_DIBitmap* pGlyph = &glyph.m_pGlyph->m_Bitmap;
+ CFX_RetainPtr<CFX_DIBitmap> pGlyph = glyph.m_pGlyph->m_pBitmap;
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;
@@ -1052,14 +1065,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 f3dea9178d..b451b543fc 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_Bitmap.GetWidth();
+ FX_SAFE_INT32 char_width = pGlyph->m_pBitmap->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_Bitmap.GetHeight();
+ FX_SAFE_INT32 char_height = pGlyph->m_pBitmap->GetHeight();
char_height /= retinaScaleY;
if (!char_height.IsValid())
continue;
diff --git a/core/fxge/ifx_renderdevicedriver.cpp b/core/fxge/ifx_renderdevicedriver.cpp
index 44ce833d99..35cd4e221d 100644
--- a/core/fxge/ifx_renderdevicedriver.cpp
+++ b/core/fxge/ifx_renderdevicedriver.cpp
@@ -48,14 +48,15 @@ bool IFX_RenderDeviceDriver::DrawCosmeticLine(float x1,
return false;
}
-bool IFX_RenderDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap,
- int left,
- int top) {
+bool IFX_RenderDeviceDriver::GetDIBits(
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ int left,
+ int top) {
return false;
}
-CFX_DIBitmap* IFX_RenderDeviceDriver::GetBackDrop() {
- return nullptr;
+CFX_RetainPtr<CFX_DIBitmap> IFX_RenderDeviceDriver::GetBackDrop() {
+ return CFX_RetainPtr<CFX_DIBitmap>();
}
bool IFX_RenderDeviceDriver::ContinueDIBits(void* handle, IFX_Pause* pPause) {
@@ -91,12 +92,13 @@ bool IFX_RenderDeviceDriver::DrawShading(const CPDF_ShadingPattern* pPattern,
return false;
}
-bool IFX_RenderDeviceDriver::SetBitsWithMask(const CFX_DIBSource* pBitmap,
- const CFX_DIBSource* pMask,
- int left,
- int top,
- int bitmap_alpha,
- int blend_type) {
+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) {
return false;
}
diff --git a/core/fxge/ifx_renderdevicedriver.h b/core/fxge/ifx_renderdevicedriver.h
index 3dd4730f9b..87e38fa5f0 100644
--- a/core/fxge/ifx_renderdevicedriver.h
+++ b/core/fxge/ifx_renderdevicedriver.h
@@ -7,6 +7,7 @@
#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;
@@ -57,15 +58,17 @@ class IFX_RenderDeviceDriver {
int blend_type);
virtual bool GetClipBox(FX_RECT* pRect) = 0;
- virtual bool GetDIBits(CFX_DIBitmap* pBitmap, int left, int top);
- virtual CFX_DIBitmap* GetBackDrop();
- virtual bool SetDIBits(const CFX_DIBSource* pBitmap,
+ 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,
uint32_t color,
const FX_RECT* pSrcRect,
int dest_left,
int dest_top,
int blend_type) = 0;
- virtual bool StretchDIBits(const CFX_DIBSource* pBitmap,
+ virtual bool StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
uint32_t color,
int dest_left,
int dest_top,
@@ -74,7 +77,7 @@ class IFX_RenderDeviceDriver {
const FX_RECT* pClipRect,
uint32_t flags,
int blend_type) = 0;
- virtual bool StartDIBits(const CFX_DIBSource* pBitmap,
+ virtual bool StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
int bitmap_alpha,
uint32_t color,
const CFX_Matrix* pMatrix,
@@ -97,8 +100,8 @@ class IFX_RenderDeviceDriver {
const FX_RECT& clip_rect,
int alpha,
bool bAlphaMode);
- virtual bool SetBitsWithMask(const CFX_DIBSource* pBitmap,
- const CFX_DIBSource* pMask,
+ virtual bool SetBitsWithMask(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ const CFX_RetainPtr<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 a9cf7e67c7..d3ea86b92e 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(CFX_DIBitmap* pBitmap,
+void RgbByteOrderTransferBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
int dest_left,
int dest_top,
int width,
int height,
- const CFX_DIBSource* pSrcBitmap,
+ const CFX_RetainPtr<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_DIBitmap* bitmap,
- const CFX_DIBitmap* device) {
+static void DebugValidate(const CFX_RetainPtr<CFX_DIBitmap>& bitmap,
+ const CFX_RetainPtr<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_DIBSource* pSource,
+bool Upsample(const CFX_RetainPtr<CFX_DIBSource>& pSource,
std::unique_ptr<uint8_t, FxFreeDeleter>& dst8Storage,
std::unique_ptr<uint32_t, FxFreeDeleter>& dst32Storage,
SkColorTable** ctPtr,
@@ -1197,10 +1197,11 @@ void CFX_SkiaDeviceDriver::PaintStroke(SkPaint* spaint,
spaint->setStrokeJoin(join);
}
-CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(CFX_DIBitmap* pBitmap,
- bool bRgbByteOrder,
- CFX_DIBitmap* pOriDevice,
- bool bGroupKnockout)
+CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ bool bRgbByteOrder,
+ const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice,
+ bool bGroupKnockout)
: m_pBitmap(pBitmap),
m_pOriDevice(pOriDevice),
m_pRecorder(nullptr),
@@ -1394,8 +1395,7 @@ 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());
- CFX_DIBitmapRef mask;
- CFX_DIBitmap* pThisLayer = mask.Emplace();
+ auto pThisLayer = pdfium::MakeRetain<CFX_DIBitmap>();
pThisLayer->Create(path_rect.Width(), path_rect.Height(), FXDIB_8bppMask);
pThisLayer->Clear(0);
@@ -1405,15 +1405,14 @@ void CFX_SkiaDeviceDriver::SetClipMask(const FX_RECT& clipBox,
SkBitmap bitmap;
bitmap.installPixels(imageInfo, pThisLayer->GetBuffer(),
pThisLayer->GetPitch(), nullptr, nullptr, nullptr);
- SkCanvas* canvas = new SkCanvas(bitmap);
+ auto canvas = pdfium::MakeUnique<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, mask);
- delete canvas;
+ m_pClipRgn->IntersectMaskF(path_rect.left, path_rect.top, pThisLayer);
}
#endif // _SKIA_SUPPORT_PATHS_
@@ -1798,7 +1797,9 @@ bool CFX_SkiaDeviceDriver::GetClipBox(FX_RECT* pRect) {
return true;
}
-bool CFX_SkiaDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) {
+bool CFX_SkiaDeviceDriver::GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ int left,
+ int top) {
if (!m_pBitmap)
return true;
uint8_t* srcBuffer = m_pBitmap->GetBuffer();
@@ -1835,7 +1836,7 @@ bool CFX_SkiaDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) {
m_pBitmap->UnPreMultiply();
FX_RECT rect(left, top, left + pBitmap->GetWidth(),
top + pBitmap->GetHeight());
- std::unique_ptr<CFX_DIBitmap> pBack;
+ CFX_RetainPtr<CFX_DIBitmap> pBack;
if (m_pOriDevice) {
pBack = m_pOriDevice->Clone(&rect);
if (!pBack)
@@ -1863,16 +1864,17 @@ bool CFX_SkiaDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) {
#endif // _SKIA_SUPPORT_PATHS_
}
-CFX_DIBitmap* CFX_SkiaDeviceDriver::GetBackDrop() {
+CFX_RetainPtr<CFX_DIBitmap> CFX_SkiaDeviceDriver::GetBackDrop() {
return m_pOriDevice;
}
-bool CFX_SkiaDeviceDriver::SetDIBits(const CFX_DIBSource* pBitmap,
- uint32_t argb,
- const FX_RECT* pSrcRect,
- int left,
- int top,
- int blend_type) {
+bool CFX_SkiaDeviceDriver::SetDIBits(
+ const CFX_RetainPtr<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;
@@ -1897,15 +1899,16 @@ bool CFX_SkiaDeviceDriver::SetDIBits(const CFX_DIBSource* pBitmap,
#endif // _SKIA_SUPPORT_PATHS_
}
-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) {
+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) {
#ifdef _SKIA_SUPPORT_
m_pCache->FlushForDraw();
if (!m_pBitmap->GetBuffer())
@@ -1948,13 +1951,14 @@ bool CFX_SkiaDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource,
#endif // _SKIA_SUPPORT_PATHS_
}
-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) {
+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) {
#ifdef _SKIA_SUPPORT_
m_pCache->FlushForDraw();
DebugValidate(m_pBitmap, m_pOriDevice);
@@ -2035,7 +2039,8 @@ bool CFX_SkiaDeviceDriver::ContinueDIBits(void* handle, IFX_Pause* pPause) {
}
#if defined _SKIA_SUPPORT_
-void CFX_SkiaDeviceDriver::PreMultiply(CFX_DIBitmap* pDIBitmap) {
+void CFX_SkiaDeviceDriver::PreMultiply(
+ const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap) {
pDIBitmap->PreMultiply();
}
#endif // _SKIA_SUPPORT_
@@ -2091,11 +2096,12 @@ void CFX_DIBitmap::UnPreMultiply() {
#endif // _SKIA_SUPPORT_PATHS_
#ifdef _SKIA_SUPPORT_
-bool CFX_SkiaDeviceDriver::DrawBitsWithMask(const CFX_DIBSource* pSource,
- const CFX_DIBSource* pMask,
- int bitmap_alpha,
- const CFX_Matrix* pMatrix,
- int blend_type) {
+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) {
DebugValidate(m_pBitmap, m_pOriDevice);
SkColorTable* srcCt = nullptr;
SkColorTable* maskCt = nullptr;
@@ -2135,12 +2141,13 @@ bool CFX_SkiaDeviceDriver::DrawBitsWithMask(const CFX_DIBSource* pSource,
return true;
}
-bool CFX_SkiaDeviceDriver::SetBitsWithMask(const CFX_DIBSource* pBitmap,
- const CFX_DIBSource* pMask,
- int dest_left,
- int dest_top,
- int bitmap_alpha,
- int blend_type) {
+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) {
if (!m_pBitmap || !m_pBitmap->GetBuffer())
return true;
CFX_Matrix m(pBitmap->GetWidth(), 0, 0, -pBitmap->GetHeight(), dest_left,
@@ -2167,9 +2174,7 @@ void CFX_SkiaDeviceDriver::DebugVerifyBitmapIsPreMultiplied() const {
}
#endif // _SKIA_SUPPORT_
-CFX_FxgeDevice::CFX_FxgeDevice() {
- m_bOwnedBitmap = false;
-}
+CFX_FxgeDevice::CFX_FxgeDevice() {}
#ifdef _SKIA_SUPPORT_
void CFX_FxgeDevice::Clear(uint32_t color) {
@@ -2185,9 +2190,9 @@ SkPictureRecorder* CFX_FxgeDevice::CreateRecorder(int size_x, int size_y) {
}
#endif // _SKIA_SUPPORT_
-bool CFX_FxgeDevice::Attach(CFX_DIBitmap* pBitmap,
+bool CFX_FxgeDevice::Attach(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
bool bRgbByteOrder,
- CFX_DIBitmap* pOriDevice,
+ const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice,
bool bGroupKnockout) {
if (!pBitmap)
return false;
@@ -2209,11 +2214,9 @@ bool CFX_FxgeDevice::AttachRecorder(SkPictureRecorder* recorder) {
bool CFX_FxgeDevice::Create(int width,
int height,
FXDIB_Format format,
- CFX_DIBitmap* pOriDevice) {
- m_bOwnedBitmap = true;
- CFX_DIBitmap* pBitmap = new CFX_DIBitmap;
+ const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice) {
+ auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
if (!pBitmap->Create(width, height, format)) {
- delete pBitmap;
return false;
}
SetBitmap(pBitmap);
@@ -2224,9 +2227,6 @@ 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,12 +2239,13 @@ void CFX_FxgeDevice::DebugVerifyBitmapIsPreMultiplied() const {
#endif // SK_DEBUG
}
-bool CFX_FxgeDevice::SetBitsWithMask(const CFX_DIBSource* pBitmap,
- const CFX_DIBSource* pMask,
- int left,
- int top,
- int bitmap_alpha,
- int blend_type) {
+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) {
CFX_SkiaDeviceDriver* skDriver =
static_cast<CFX_SkiaDeviceDriver*>(GetDeviceDriver());
if (skDriver)
@@ -2284,10 +2285,10 @@ class CFX_Renderer {
uint32_t m_Color;
bool m_bFullCover;
bool m_bRgbByteOrder;
- CFX_DIBitmap* m_pOriDevice;
+ const CFX_RetainPtr<CFX_DIBitmap>& m_pOriDevice;
FX_RECT m_ClipBox;
- const CFX_DIBitmap* m_pClipMask;
- CFX_DIBitmap* m_pDevice;
+ const CFX_RetainPtr<CFX_DIBitmap>& m_pClipMask;
+ const CFX_RetainPtr<CFX_DIBitmap>& m_pDevice;
const CFX_ClipRgn* m_pClipRgn;
void (CFX_Renderer::*composite_span)(uint8_t*,
int,
@@ -2926,7 +2927,7 @@ class CFX_Renderer {
}
uint8_t* dest_scan = m_pDevice->GetBuffer() + m_pDevice->GetPitch() * y;
uint8_t* dest_scan_extra_alpha = nullptr;
- CFX_DIBitmap* pAlphaMask = m_pDevice->m_pAlphaMask;
+ CFX_RetainPtr<CFX_DIBitmap> pAlphaMask = m_pDevice->m_pAlphaMask;
if (pAlphaMask) {
dest_scan_extra_alpha =
pAlphaMask->GetBuffer() + pAlphaMask->GetPitch() * y;
@@ -2975,8 +2976,8 @@ class CFX_Renderer {
}
}
- bool Init(CFX_DIBitmap* pDevice,
- CFX_DIBitmap* pOriDevice,
+ bool Init(const CFX_RetainPtr<CFX_DIBitmap>& pDevice,
+ const CFX_RetainPtr<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 494e6e1c44..9b5e4b06fa 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(CFX_DIBitmap* pBitmap,
+ CFX_SkiaDeviceDriver(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
bool bRgbByteOrder,
- CFX_DIBitmap* pOriDevice,
+ const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice,
bool bGroupKnockout);
#ifdef _SKIA_SUPPORT_
explicit CFX_SkiaDeviceDriver(SkPictureRecorder* recorder);
@@ -79,19 +79,21 @@ class CFX_SkiaDeviceDriver : public IFX_RenderDeviceDriver {
bool GetClipBox(FX_RECT* pRect) override;
/** Load device buffer into a DIB */
- bool GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) override;
+ bool GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ int left,
+ int top) override;
- CFX_DIBitmap* GetBackDrop() override;
+ CFX_RetainPtr<CFX_DIBitmap> GetBackDrop() override;
- bool SetDIBits(const CFX_DIBSource* pBitmap,
+ bool SetDIBits(const CFX_RetainPtr<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_DIBSource* pBitmap,
- const CFX_DIBSource* pMask,
+ bool SetBitsWithMask(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pMask,
int dest_left,
int dest_top,
int bitmap_alpha,
@@ -102,7 +104,7 @@ class CFX_SkiaDeviceDriver : public IFX_RenderDeviceDriver {
void SetClipMask(const FX_RECT& clipBox, const SkPath& skClipPath);
#endif
- bool StretchDIBits(const CFX_DIBSource* pBitmap,
+ bool StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
uint32_t color,
int dest_left,
int dest_top,
@@ -112,7 +114,7 @@ class CFX_SkiaDeviceDriver : public IFX_RenderDeviceDriver {
uint32_t flags,
int blend_type) override;
- bool StartDIBits(const CFX_DIBSource* pBitmap,
+ bool StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
int bitmap_alpha,
uint32_t color,
const CFX_Matrix* pMatrix,
@@ -124,8 +126,8 @@ class CFX_SkiaDeviceDriver : public IFX_RenderDeviceDriver {
void CancelDIBits(void* handle) override;
- bool DrawBitsWithMask(const CFX_DIBSource* pBitmap,
- const CFX_DIBSource* pMask,
+ bool DrawBitsWithMask(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
+ const CFX_RetainPtr<CFX_DIBSource>& pMask,
int bitmap_alpha,
const CFX_Matrix* pMatrix,
int blend_type);
@@ -152,7 +154,7 @@ class CFX_SkiaDeviceDriver : public IFX_RenderDeviceDriver {
void Flush() override;
SkPictureRecorder* GetRecorder() const { return m_pRecorder; }
void PreMultiply() { m_pBitmap->PreMultiply(); }
- static void PreMultiply(CFX_DIBitmap* pDIBitmap);
+ static void PreMultiply(const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap);
SkCanvas* SkiaCanvas() { return m_pCanvas; }
void DebugVerifyBitmapIsPreMultiplied() const;
void Dump() const;
@@ -160,8 +162,8 @@ class CFX_SkiaDeviceDriver : public IFX_RenderDeviceDriver {
private:
friend class SkiaState;
- CFX_DIBitmap* m_pBitmap;
- CFX_DIBitmap* m_pOriDevice;
+ CFX_RetainPtr<CFX_DIBitmap> m_pBitmap;
+ CFX_RetainPtr<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 d612840b4c..a47a50c836 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_DIBitmap* pBitmap = CFXBitmapFromFPDFBitmap(bitmap);
+ CFX_RetainPtr<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 391af83630..5350c383b4 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_DIBSource* pSource,
+bool CFX_PSRenderer::SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource,
uint32_t color,
int left,
int top) {
@@ -349,7 +349,7 @@ bool CFX_PSRenderer::SetDIBits(const CFX_DIBSource* pSource,
return DrawDIBits(pSource, color, &matrix, 0);
}
-bool CFX_PSRenderer::StretchDIBits(const CFX_DIBSource* pSource,
+bool CFX_PSRenderer::StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource,
uint32_t color,
int dest_left,
int dest_top,
@@ -362,7 +362,7 @@ bool CFX_PSRenderer::StretchDIBits(const CFX_DIBSource* pSource,
return DrawDIBits(pSource, color, &matrix, flags);
}
-bool CFX_PSRenderer::DrawDIBits(const CFX_DIBSource* pSource,
+bool CFX_PSRenderer::DrawDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource,
uint32_t color,
const CFX_Matrix* pMatrix,
uint32_t flags) {
@@ -419,25 +419,25 @@ bool CFX_PSRenderer::DrawDIBits(const CFX_DIBSource* pSource,
output_buf.release();
} else {
CFX_DIBExtractor source_extractor(pSource);
- CFX_MaybeOwned<CFX_DIBSource> pConverted(source_extractor.GetBitmap());
- if (!pConverted.Get())
+ CFX_RetainPtr<CFX_DIBSource> pConverted = source_extractor.GetBitmap();
+ if (!pConverted)
return false;
switch (pSource->GetFormat()) {
case FXDIB_1bppRgb:
case FXDIB_Rgb32:
- pConverted = pConverted->CloneConvert(FXDIB_Rgb).release();
+ pConverted = pConverted->CloneConvert(FXDIB_Rgb);
break;
case FXDIB_8bppRgb:
if (pSource->GetPalette()) {
- pConverted = pConverted->CloneConvert(FXDIB_Rgb).release();
+ pConverted = pConverted->CloneConvert(FXDIB_Rgb);
}
break;
case FXDIB_1bppCmyk:
- pConverted = pConverted->CloneConvert(FXDIB_Cmyk).release();
+ pConverted = pConverted->CloneConvert(FXDIB_Cmyk);
break;
case FXDIB_8bppCmyk:
if (pSource->GetPalette()) {
- pConverted = pConverted->CloneConvert(FXDIB_Cmyk).release();
+ pConverted = pConverted->CloneConvert(FXDIB_Cmyk);
}
break;
default:
@@ -452,8 +452,7 @@ bool CFX_PSRenderer::DrawDIBits(const CFX_DIBSource* pSource,
FX_STRSIZE output_size = 0;
const char* filter = nullptr;
if ((m_PSLevel == 2 || flags & FXRENDER_IMAGE_LOSSY) &&
- CCodec_JpegModule::JpegEncode(pConverted.Get(), &output_buf,
- &output_size)) {
+ CCodec_JpegModule::JpegEncode(pConverted, &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 133d7b9d72..5768d0770f 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_DIBSource* pBitmap,
+ bool SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
uint32_t color,
int dest_left,
int dest_top);
- bool StretchDIBits(const CFX_DIBSource* pBitmap,
+ bool StretchDIBits(const CFX_RetainPtr<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_DIBSource* pBitmap,
+ bool DrawDIBits(const CFX_RetainPtr<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 0bfab3fee1..e59e9d60a4 100644
--- a/core/fxge/win32/cfx_windowsdib.h
+++ b/core/fxge/win32/cfx_windowsdib.h
@@ -10,6 +10,9 @@
#ifndef _WINDOWS_
#include <windows.h>
#endif
+
+#include "core/fxge/fx_dib.h"
+
#define WINDIB_OPEN_MEMORY 0x1
#define WINDIB_OPEN_PATHNAME 0x2
@@ -25,15 +28,20 @@ typedef struct WINDIB_Open_Args_ {
class CFX_WindowsDIB : public CFX_DIBitmap {
public:
- CFX_WindowsDIB(HDC hDC, int width, int height);
+ template <typename T, typename... Args>
+ friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args);
+
~CFX_WindowsDIB() override;
- 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);
+ 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);
HDC GetDC() const { return m_hMemDC; }
HBITMAP GetWindowsBitmap() const { return m_hBitmap; }
@@ -42,6 +50,8 @@ 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 105c34998c..8e8908a7a1 100644
--- a/core/fxge/win32/dwrite_int.h
+++ b/core/fxge/win32/dwrite_int.h
@@ -39,7 +39,8 @@ class CDWriteExt {
void* DwCreateFontFaceFromStream(uint8_t* pData,
uint32_t size,
int simulation_style);
- bool DwCreateRenderingTarget(CFX_DIBitmap* pSrc, void** renderTarget);
+ bool DwCreateRenderingTarget(const CFX_RetainPtr<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 b2ee4549ea..140a5b07d5 100644
--- a/core/fxge/win32/fx_win32_device.cpp
+++ b/core/fxge/win32/fx_win32_device.cpp
@@ -782,12 +782,13 @@ void CGdiDeviceDriver::RestoreState(bool bKeepSaved) {
SaveDC(m_hDC);
}
-bool CGdiDeviceDriver::GDI_SetDIBits(CFX_DIBitmap* pBitmap1,
- const FX_RECT* pSrcRect,
- int left,
- int top) {
+bool CGdiDeviceDriver::GDI_SetDIBits(
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap1,
+ const FX_RECT* pSrcRect,
+ int left,
+ int top) {
if (m_DeviceClass == FXDC_PRINTER) {
- std::unique_ptr<CFX_DIBitmap> pBitmap = pBitmap1->FlipImage(false, true);
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap = pBitmap1->FlipImage(false, true);
if (!pBitmap)
return false;
@@ -796,7 +797,7 @@ bool CGdiDeviceDriver::GDI_SetDIBits(CFX_DIBitmap* pBitmap1,
int width = pSrcRect->Width(), height = pSrcRect->Height();
LPBYTE pBuffer = pBitmap->GetBuffer();
- CFX_ByteString info = CFX_WindowsDIB::GetBitmapInfo(pBitmap.get());
+ CFX_ByteString info = CFX_WindowsDIB::GetBitmapInfo(pBitmap);
((BITMAPINFOHEADER*)info.c_str())->biHeight *= -1;
FX_RECT dst_rect(0, 0, width, height);
dst_rect.Intersect(0, 0, pBitmap->GetWidth(), pBitmap->GetHeight());
@@ -806,15 +807,15 @@ bool CGdiDeviceDriver::GDI_SetDIBits(CFX_DIBitmap* pBitmap1,
dst_height, pBuffer, (BITMAPINFO*)info.c_str(),
DIB_RGB_COLORS, SRCCOPY);
} else {
- CFX_MaybeOwned<CFX_DIBitmap> pBitmap(pBitmap1);
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap = pBitmap1;
if (pBitmap->IsCmykImage()) {
- pBitmap = pBitmap->CloneConvert(FXDIB_Rgb).release();
+ pBitmap = pBitmap->CloneConvert(FXDIB_Rgb);
if (!pBitmap)
return false;
}
int width = pSrcRect->Width(), height = pSrcRect->Height();
LPBYTE pBuffer = pBitmap->GetBuffer();
- CFX_ByteString info = CFX_WindowsDIB::GetBitmapInfo(pBitmap.Get());
+ CFX_ByteString info = CFX_WindowsDIB::GetBitmapInfo(pBitmap);
::SetDIBitsToDevice(m_hDC, left, top, width, height, pSrcRect->left,
pBitmap->GetHeight() - pSrcRect->bottom, 0,
pBitmap->GetHeight(), pBuffer,
@@ -823,13 +824,14 @@ bool CGdiDeviceDriver::GDI_SetDIBits(CFX_DIBitmap* pBitmap1,
return true;
}
-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;
+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;
if (!pBitmap || dest_width == 0 || dest_height == 0)
return false;
@@ -844,14 +846,14 @@ bool CGdiDeviceDriver::GDI_StretchDIBits(CFX_DIBitmap* pBitmap1,
} else {
SetStretchBltMode(m_hDC, COLORONCOLOR);
}
- CFX_MaybeOwned<CFX_DIBitmap> pToStrechBitmap(pBitmap);
+ CFX_RetainPtr<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.Get());
+ CFX_WindowsDIB::GetBitmapInfo(pToStrechBitmap);
::StretchDIBits(m_hDC, dest_left, dest_top, dest_width, dest_height, 0, 0,
pToStrechBitmap->GetWidth(), pToStrechBitmap->GetHeight(),
pToStrechBitmap->GetBuffer(),
@@ -860,14 +862,15 @@ bool CGdiDeviceDriver::GDI_StretchDIBits(CFX_DIBitmap* pBitmap1,
return true;
}
-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;
+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;
if (!pBitmap || dest_width == 0 || dest_height == 0)
return false;
@@ -1165,7 +1168,9 @@ CGdiDisplayDriver::CGdiDisplayDriver(HDC hDC)
CGdiDisplayDriver::~CGdiDisplayDriver() {}
-bool CGdiDisplayDriver::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) {
+bool CGdiDisplayDriver::GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ int left,
+ int top) {
bool ret = false;
int width = pBitmap->GetWidth();
int height = pBitmap->GetHeight();
@@ -1185,12 +1190,12 @@ bool CGdiDisplayDriver::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) {
ret = ::GetDIBits(hDCMemory, hbmp, 0, height, pBitmap->GetBuffer(), &bmi,
DIB_RGB_COLORS) == height;
} else {
- CFX_DIBitmap bitmap;
- if (bitmap.Create(width, height, FXDIB_Rgb)) {
+ auto bitmap = pdfium::MakeRetain<CFX_DIBitmap>();
+ 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;
}
@@ -1203,7 +1208,7 @@ bool CGdiDisplayDriver::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) {
return ret;
}
-bool CGdiDisplayDriver::SetDIBits(const CFX_DIBSource* pSource,
+bool CGdiDisplayDriver::SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource,
uint32_t color,
const FX_RECT* pSrcRect,
int left,
@@ -1214,17 +1219,16 @@ bool CGdiDisplayDriver::SetDIBits(const CFX_DIBSource* pSource,
int width = pSource->GetWidth(), height = pSource->GetHeight();
int alpha = FXARGB_A(color);
if (pSource->GetBPP() != 1 || alpha != 255) {
- 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)) {
+ 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)) {
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());
@@ -1234,32 +1238,33 @@ bool CGdiDisplayDriver::SetDIBits(const CFX_DIBSource* pSource,
}
int width = pSrcRect->Width(), height = pSrcRect->Height();
if (pSource->HasAlpha()) {
- 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)) {
+ 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)) {
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_DIBitmap* pBitmap = temp.GetBitmap();
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap = temp.GetBitmap();
if (!pBitmap)
return false;
return GDI_SetDIBits(pBitmap, pSrcRect, left, top);
}
-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) {
+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) {
FX_RECT bitmap_clip = *pClipRect;
if (dest_width < 0)
dest_left += dest_width;
@@ -1268,25 +1273,26 @@ bool CGdiDisplayDriver::UseFoxitStretchEngine(const CFX_DIBSource* pSource,
dest_top += dest_height;
bitmap_clip.Offset(-dest_left, -dest_top);
- std::unique_ptr<CFX_DIBitmap> pStretched(
- pSource->StretchTo(dest_width, dest_height, render_flags, &bitmap_clip));
+ CFX_RetainPtr<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.get(), color, &src_rect, pClipRect->left,
+ return SetDIBits(pStretched, color, &src_rect, pClipRect->left,
pClipRect->top, FXDIB_BLEND_NORMAL);
}
-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) {
+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) {
ASSERT(pSource && pClipRect);
if (flags || dest_width > 10000 || dest_width < -10000 ||
dest_height > 10000 || dest_height < -10000) {
@@ -1303,24 +1309,23 @@ bool CGdiDisplayDriver::StretchDIBits(const CFX_DIBSource* pSource,
clip_rect.Intersect(*pClipRect);
clip_rect.Offset(-image_rect.left, -image_rect.top);
int clip_width = clip_rect.Width(), clip_height = clip_rect.Height();
- std::unique_ptr<CFX_DIBitmap> pStretched(
+ CFX_RetainPtr<CFX_DIBitmap> pStretched(
pSource->StretchTo(dest_width, dest_height, flags, &clip_rect));
if (!pStretched)
return true;
- CFX_DIBitmap background;
- if (!background.Create(clip_width, clip_height, FXDIB_Rgb32) ||
- !GetDIBits(&background, image_rect.left + clip_rect.left,
+ auto background = pdfium::MakeRetain<CFX_DIBitmap>();
+ 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.get(), color, 0, 0,
- FXDIB_BLEND_NORMAL, nullptr, false, 0, nullptr)) {
+ !background->CompositeMask(0, 0, clip_width, clip_height, pStretched,
+ 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()) {
@@ -1328,7 +1333,7 @@ bool CGdiDisplayDriver::StretchDIBits(const CFX_DIBSource* pSource,
(CWin32Platform*)CFX_GEModule::Get()->GetPlatformData();
if (pPlatform->m_GdiplusExt.IsAvailable() && !pSource->IsCmykImage()) {
CFX_DIBExtractor temp(pSource);
- CFX_DIBitmap* pBitmap = temp.GetBitmap();
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap = temp.GetBitmap();
if (!pBitmap)
return false;
return pPlatform->m_GdiplusExt.StretchDIBits(
@@ -1339,14 +1344,14 @@ bool CGdiDisplayDriver::StretchDIBits(const CFX_DIBSource* pSource,
dest_width, dest_height, pClipRect, flags);
}
CFX_DIBExtractor temp(pSource);
- CFX_DIBitmap* pBitmap = temp.GetBitmap();
+ CFX_RetainPtr<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_DIBSource* pBitmap,
+bool CGdiDisplayDriver::StartDIBits(const CFX_RetainPtr<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 9b85b57317..9815457bbd 100644
--- a/core/fxge/win32/fx_win32_dib.cpp
+++ b/core/fxge/win32/fx_win32_dib.cpp
@@ -11,7 +11,8 @@
#include "core/fxge/win32/cfx_windowsdib.h"
#include "core/fxge/win32/win32_int.h"
-CFX_ByteString CFX_WindowsDIB::GetBitmapInfo(const CFX_DIBitmap* pBitmap) {
+CFX_ByteString CFX_WindowsDIB::GetBitmapInfo(
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap) {
CFX_ByteString result;
int len = sizeof(BITMAPINFOHEADER);
if (pBitmap->GetBPP() == 1 || pBitmap->GetBPP() == 8) {
@@ -51,9 +52,9 @@ CFX_ByteString CFX_WindowsDIB::GetBitmapInfo(const CFX_DIBitmap* pBitmap) {
return result;
}
-CFX_DIBitmap* _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi,
- LPVOID pData,
- bool bAlpha) {
+CFX_RetainPtr<CFX_DIBitmap> _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi,
+ LPVOID pData,
+ bool bAlpha) {
int width = pbmi->bmiHeader.biWidth;
int height = pbmi->bmiHeader.biHeight;
BOOL bBottomUp = true;
@@ -62,15 +63,13 @@ CFX_DIBitmap* _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi,
bBottomUp = false;
}
int pitch = (width * pbmi->bmiHeader.biBitCount + 31) / 32 * 4;
- CFX_DIBitmap* pBitmap = new CFX_DIBitmap;
+ auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
FXDIB_Format format = bAlpha
? (FXDIB_Format)(pbmi->bmiHeader.biBitCount + 0x200)
: (FXDIB_Format)pbmi->bmiHeader.biBitCount;
- bool ret = pBitmap->Create(width, height, format);
- if (!ret) {
- delete pBitmap;
+ if (!pBitmap->Create(width, height, format))
return nullptr;
- }
+
FXSYS_memcpy(pBitmap->GetBuffer(), pData, pitch * height);
if (bBottomUp) {
uint8_t* temp_buf = FX_Alloc(uint8_t, pitch);
@@ -98,11 +97,13 @@ CFX_DIBitmap* _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi,
return pBitmap;
}
-CFX_DIBitmap* CFX_WindowsDIB::LoadFromBuf(BITMAPINFO* pbmi, LPVOID pData) {
+CFX_RetainPtr<CFX_DIBitmap> CFX_WindowsDIB::LoadFromBuf(BITMAPINFO* pbmi,
+ LPVOID pData) {
return _FX_WindowsDIB_LoadFromBuf(pbmi, pData, false);
}
-HBITMAP CFX_WindowsDIB::GetDDBitmap(const CFX_DIBitmap* pBitmap, HDC hDC) {
+HBITMAP CFX_WindowsDIB::GetDDBitmap(const CFX_RetainPtr<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(),
@@ -116,7 +117,8 @@ void GetBitmapSize(HBITMAP hBitmap, int& w, int& h) {
h = bmp.bmHeight;
}
-CFX_DIBitmap* CFX_WindowsDIB::LoadFromFile(const wchar_t* filename) {
+CFX_RetainPtr<CFX_DIBitmap> CFX_WindowsDIB::LoadFromFile(
+ const wchar_t* filename) {
CWin32Platform* pPlatform =
(CWin32Platform*)CFX_GEModule::Get()->GetPlatformData();
if (pPlatform->m_GdiplusExt.IsAvailable()) {
@@ -131,30 +133,29 @@ CFX_DIBitmap* CFX_WindowsDIB::LoadFromFile(const wchar_t* filename) {
return nullptr;
}
HDC hDC = CreateCompatibleDC(nullptr);
- int width, height;
+ int width;
+ int height;
GetBitmapSize(hBitmap, width, height);
- CFX_DIBitmap* pDIBitmap = new CFX_DIBitmap;
+ auto pDIBitmap = pdfium::MakeRetain<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_DIBitmap* CFX_WindowsDIB::LoadFromFile(const char* filename) {
+CFX_RetainPtr<CFX_DIBitmap> CFX_WindowsDIB::LoadFromFile(const char* filename) {
return LoadFromFile(CFX_WideString::FromLocal(filename).c_str());
}
-CFX_DIBitmap* CFX_WindowsDIB::LoadDIBitmap(WINDIB_Open_Args_ args) {
+CFX_RetainPtr<CFX_DIBitmap> CFX_WindowsDIB::LoadDIBitmap(
+ WINDIB_Open_Args_ args) {
CWin32Platform* pPlatform =
(CWin32Platform*)CFX_GEModule::Get()->GetPlatformData();
if (pPlatform->m_GdiplusExt.IsAvailable()) {
@@ -171,20 +172,17 @@ CFX_DIBitmap* CFX_WindowsDIB::LoadDIBitmap(WINDIB_Open_Args_ args) {
HDC hDC = CreateCompatibleDC(nullptr);
int width, height;
GetBitmapSize(hBitmap, width, height);
- CFX_DIBitmap* pDIBitmap = new CFX_DIBitmap;
+ auto pDIBitmap = pdfium::MakeRetain<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 e088e832bc..91fb465af4 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(CFX_DIBitmap* pBitmap,
+ CDwGdiTextRenderer(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
IDWriteBitmapRenderTarget* bitmapRenderTarget,
IDWriteRenderingParams* renderingParams);
~CDwGdiTextRenderer();
@@ -118,7 +118,7 @@ class CDwGdiTextRenderer {
const COLORREF& textColor);
private:
- CFX_DIBitmap* pBitmap_;
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap_;
IDWriteBitmapRenderTarget* pRenderTarget_;
IDWriteRenderingParams* pRenderingParams_;
};
@@ -180,8 +180,9 @@ failed:
return nullptr;
}
-bool CDWriteExt::DwCreateRenderingTarget(CFX_DIBitmap* pBitmap,
- void** renderTarget) {
+bool CDWriteExt::DwCreateRenderingTarget(
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ void** renderTarget) {
if (pBitmap->GetFormat() > FXDIB_Argb) {
return false;
}
@@ -395,7 +396,7 @@ HRESULT CDwFontContext::Initialize() {
}
CDwGdiTextRenderer::CDwGdiTextRenderer(
- CFX_DIBitmap* pBitmap,
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
IDWriteBitmapRenderTarget* bitmapRenderTarget,
IDWriteRenderingParams* renderingParams)
: pBitmap_(pBitmap),
@@ -426,13 +427,13 @@ STDMETHODIMP CDwGdiTextRenderer::DrawGlyphRun(
HBITMAP hBitmap = (HBITMAP)::GetCurrentObject(hDC, OBJ_BITMAP);
BITMAP bitmap;
GetObject(hBitmap, sizeof bitmap, &bitmap);
- 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);
+ 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);
hr = pRenderTarget_->DrawGlyphRun(baselineOriginX, baselineOriginY,
measuringMode, glyphRun, pRenderingParams_,
textColor);
@@ -440,7 +441,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 8a7f55e0cb..41f9ba55ad 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 std::unique_ptr<CFX_DIBitmap> StretchMonoToGray(
+static CFX_RetainPtr<CFX_DIBitmap> StretchMonoToGray(
int dest_width,
int dest_height,
- const CFX_DIBitmap* pSource,
+ const CFX_RetainPtr<CFX_DIBitmap>& pSource,
FX_RECT* pClipRect) {
bool bFlipX = dest_width < 0;
if (bFlipX)
@@ -477,7 +477,7 @@ static std::unique_ptr<CFX_DIBitmap> StretchMonoToGray(
int result_width = pClipRect->Width();
int result_height = pClipRect->Height();
int result_pitch = (result_width + 3) / 4 * 4;
- auto pStretched = pdfium::MakeUnique<CFX_DIBitmap>();
+ auto pStretched = pdfium::MakeRetain<CFX_DIBitmap>();
if (!pStretched->Create(result_width, result_height, FXDIB_8bppRgb))
return nullptr;
@@ -518,7 +518,7 @@ static std::unique_ptr<CFX_DIBitmap> StretchMonoToGray(
static void OutputImageMask(GpGraphics* pGraphics,
BOOL bMonoDevice,
- const CFX_DIBitmap* pBitmap,
+ const CFX_RetainPtr<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);
- std::unique_ptr<CFX_DIBitmap> pStretched;
+ CFX_RetainPtr<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_DIBitmap* pBitmap,
+ const CFX_RetainPtr<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);
- std::unique_ptr<CFX_DIBitmap> pCloned = pBitmap->Clone(pSrcRect);
+ CFX_RetainPtr<CFX_DIBitmap> pCloned = pBitmap->Clone(pSrcRect);
if (!pCloned)
return;
- OutputImage(pGraphics, pCloned.get(), &new_rect, dest_left, dest_top,
- dest_width, dest_height);
+ OutputImage(pGraphics, pCloned, &new_rect, dest_left, dest_top, dest_width,
+ dest_height);
return;
}
int src_pitch = pBitmap->GetPitch();
@@ -730,7 +730,8 @@ void CGdiplusExt::DeleteMemFont(LPVOID pCollection) {
((CWin32Platform*)CFX_GEModule::Get()->GetPlatformData())->m_GdiplusExt;
CallFunc(GdipDeletePrivateFontCollection)((GpFontCollection**)&pCollection);
}
-bool CGdiplusExt::GdipCreateBitmap(CFX_DIBitmap* pBitmap, void** bitmap) {
+bool CGdiplusExt::GdipCreateBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ void** bitmap) {
CGdiplusExt& GdiplusExt =
((CWin32Platform*)CFX_GEModule::Get()->GetPlatformData())->m_GdiplusExt;
PixelFormat format;
@@ -912,7 +913,7 @@ void CGdiplusExt::GdipDeleteGraphics(void* graphics) {
}
bool CGdiplusExt::StretchBitMask(HDC hDC,
BOOL bMonoDevice,
- const CFX_DIBitmap* pBitmap,
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
int dest_left,
int dest_top,
int dest_width,
@@ -938,7 +939,7 @@ bool CGdiplusExt::StretchBitMask(HDC hDC,
return true;
}
bool CGdiplusExt::StretchDIBits(HDC hDC,
- const CFX_DIBitmap* pBitmap,
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
int dest_left,
int dest_top,
int dest_width,
@@ -1492,14 +1493,16 @@ static void FreeDIBitmap(PREVIEW3_DIBITMAP* pInfo) {
FX_Free(pInfo);
}
-CFX_DIBitmap* _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi,
- LPVOID pData,
- bool bAlpha);
-CFX_DIBitmap* CGdiplusExt::LoadDIBitmap(WINDIB_Open_Args_ args) {
+// 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) {
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;
@@ -1512,7 +1515,7 @@ CFX_DIBitmap* CGdiplusExt::LoadDIBitmap(WINDIB_Open_Args_ args) {
dest_pitch);
}
}
- CFX_DIBitmap* pDIBitmap = _FX_WindowsDIB_LoadFromBuf(
+ CFX_RetainPtr<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 061896f09b..6d96243655 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_DIBSource* pSource,
+bool CGdiPrinterDriver::SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource,
uint32_t color,
const FX_RECT* pSrcRect,
int left,
@@ -87,29 +87,30 @@ bool CGdiPrinterDriver::SetDIBits(const CFX_DIBSource* pSource,
return false;
CFX_DIBExtractor temp(pSource);
- CFX_DIBitmap* pBitmap = temp.GetBitmap();
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap = temp.GetBitmap();
if (!pBitmap)
return false;
return GDI_SetDIBits(pBitmap, pSrcRect, left, top);
}
-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) {
+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) {
if (pSource->IsAlphaMask()) {
int alpha = FXARGB_A(color);
if (pSource->GetBPP() != 1 || alpha != 255)
return false;
if (dest_width < 0 || dest_height < 0) {
- std::unique_ptr<CFX_DIBitmap> pFlipped =
+ CFX_RetainPtr<CFX_DIBitmap> pFlipped =
pSource->FlipImage(dest_width < 0, dest_height < 0);
if (!pFlipped)
return false;
@@ -119,13 +120,12 @@ bool CGdiPrinterDriver::StretchDIBits(const CFX_DIBSource* pSource,
if (dest_height < 0)
dest_top += dest_height;
- return GDI_StretchBitMask(pFlipped.get(), dest_left, dest_top,
- abs(dest_width), abs(dest_height), color,
- flags);
+ return GDI_StretchBitMask(pFlipped, dest_left, dest_top, abs(dest_width),
+ abs(dest_height), color, flags);
}
CFX_DIBExtractor temp(pSource);
- CFX_DIBitmap* pBitmap = temp.GetBitmap();
+ CFX_RetainPtr<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(const CFX_DIBSource* pSource,
return false;
if (dest_width < 0 || dest_height < 0) {
- std::unique_ptr<CFX_DIBitmap> pFlipped =
+ CFX_RetainPtr<CFX_DIBitmap> pFlipped =
pSource->FlipImage(dest_width < 0, dest_height < 0);
if (!pFlipped)
return false;
@@ -146,19 +146,19 @@ bool CGdiPrinterDriver::StretchDIBits(const CFX_DIBSource* pSource,
if (dest_height < 0)
dest_top += dest_height;
- return GDI_StretchDIBits(pFlipped.get(), dest_left, dest_top,
- abs(dest_width), abs(dest_height), flags);
+ return GDI_StretchDIBits(pFlipped, dest_left, dest_top, abs(dest_width),
+ abs(dest_height), flags);
}
CFX_DIBExtractor temp(pSource);
- CFX_DIBitmap* pBitmap = temp.GetBitmap();
+ CFX_RetainPtr<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_DIBSource* pSource,
+bool CGdiPrinterDriver::StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource,
int bitmap_alpha,
uint32_t color,
const CFX_Matrix* pMatrix,
@@ -185,12 +185,12 @@ bool CGdiPrinterDriver::StartDIBits(const CFX_DIBSource* pSource,
if (FXSYS_fabs(pMatrix->a) >= 0.5f || FXSYS_fabs(pMatrix->d) >= 0.5f)
return false;
- std::unique_ptr<CFX_DIBitmap> pTransformed =
+ CFX_RetainPtr<CFX_DIBitmap> pTransformed =
pSource->SwapXY(pMatrix->c > 0, pMatrix->b < 0);
if (!pTransformed)
return false;
- return StretchDIBits(pTransformed.get(), color, full_rect.left, full_rect.top,
+ return StretchDIBits(pTransformed, 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_DIBSource* pBitmap,
+bool CPSPrinterDriver::SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
uint32_t color,
const FX_RECT* pSrcRect,
int left,
@@ -447,22 +447,23 @@ bool CPSPrinterDriver::SetDIBits(const CFX_DIBSource* pBitmap,
return m_PSRenderer.SetDIBits(pBitmap, color, left, top);
}
-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) {
+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) {
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_DIBSource* pBitmap,
+bool CPSPrinterDriver::StartDIBits(const CFX_RetainPtr<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 54ea3716e1..35521d0096 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_DIBitmap* pBitmap,
+ const CFX_RetainPtr<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_DIBitmap* pBitmap,
+ const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
int dest_left,
int dest_top,
int dest_width,
@@ -96,7 +96,8 @@ class CGdiplusExt {
float font_size,
int fontstyle);
void GdipDeleteFont(void* pFont);
- bool GdipCreateBitmap(CFX_DIBitmap* pBitmap, void** bitmap);
+ bool GdipCreateBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ void** bitmap);
void GdipDisposeImage(void* bitmap);
void GdipGetFontSize(void* pFont, float* size);
void* GdiAddFontMemResourceEx(void* pFontdata,
@@ -104,7 +105,7 @@ class CGdiplusExt {
void* pdv,
uint32_t* num_face);
bool GdiRemoveFontMemResourceEx(void* handle);
- CFX_DIBitmap* LoadDIBitmap(WINDIB_Open_Args_ args);
+ CFX_RetainPtr<CFX_DIBitmap> LoadDIBitmap(WINDIB_Open_Args_ args);
FARPROC m_Functions[100];
FuncType_GdiAddFontMemResourceEx m_pGdiAddFontMemResourceEx;
@@ -158,17 +159,17 @@ class CGdiDeviceDriver : public IFX_RenderDeviceDriver {
void DrawLine(float x1, float y1, float x2, float y2);
- bool GDI_SetDIBits(CFX_DIBitmap* pBitmap,
+ bool GDI_SetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
const FX_RECT* pSrcRect,
int left,
int top);
- bool GDI_StretchDIBits(CFX_DIBitmap* pBitmap,
+ bool GDI_StretchDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
int dest_left,
int dest_top,
int dest_width,
int dest_height,
uint32_t flags);
- bool GDI_StretchBitMask(CFX_DIBitmap* pBitmap,
+ bool GDI_StretchBitMask(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
int dest_left,
int dest_top,
int dest_width,
@@ -191,14 +192,16 @@ class CGdiDisplayDriver : public CGdiDeviceDriver {
~CGdiDisplayDriver() override;
protected:
- bool GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) override;
- bool SetDIBits(const CFX_DIBSource* pBitmap,
+ bool GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap,
+ int left,
+ int top) override;
+ bool SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
uint32_t color,
const FX_RECT* pSrcRect,
int left,
int top,
int blend_type) override;
- bool StretchDIBits(const CFX_DIBSource* pBitmap,
+ bool StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
uint32_t color,
int dest_left,
int dest_top,
@@ -207,14 +210,14 @@ class CGdiDisplayDriver : public CGdiDeviceDriver {
const FX_RECT* pClipRect,
uint32_t flags,
int blend_type) override;
- bool StartDIBits(const CFX_DIBSource* pBitmap,
+ bool StartDIBits(const CFX_RetainPtr<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_DIBSource* pSource,
+ bool UseFoxitStretchEngine(const CFX_RetainPtr<CFX_DIBSource>& pSource,
uint32_t color,
int dest_left,
int dest_top,
@@ -231,13 +234,13 @@ class CGdiPrinterDriver : public CGdiDeviceDriver {
protected:
int GetDeviceCaps(int caps_id) const override;
- bool SetDIBits(const CFX_DIBSource* pBitmap,
+ bool SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
uint32_t color,
const FX_RECT* pSrcRect,
int left,
int top,
int blend_type) override;
- bool StretchDIBits(const CFX_DIBSource* pBitmap,
+ bool StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
uint32_t color,
int dest_left,
int dest_top,
@@ -246,7 +249,7 @@ class CGdiPrinterDriver : public CGdiDeviceDriver {
const FX_RECT* pClipRect,
uint32_t flags,
int blend_type) override;
- bool StartDIBits(const CFX_DIBSource* pBitmap,
+ bool StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
int bitmap_alpha,
uint32_t color,
const CFX_Matrix* pMatrix,
@@ -290,13 +293,13 @@ class CPSPrinterDriver : public IFX_RenderDeviceDriver {
int fill_mode,
int blend_type) override;
bool GetClipBox(FX_RECT* pRect) override;
- bool SetDIBits(const CFX_DIBSource* pBitmap,
+ bool SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
uint32_t color,
const FX_RECT* pSrcRect,
int left,
int top,
int blend_type) override;
- bool StretchDIBits(const CFX_DIBSource* pBitmap,
+ bool StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap,
uint32_t color,
int dest_left,
int dest_top,
@@ -305,7 +308,7 @@ class CPSPrinterDriver : public IFX_RenderDeviceDriver {
const FX_RECT* pClipRect,
uint32_t flags,
int blend_type) override;
- bool StartDIBits(const CFX_DIBSource* pBitmap,
+ bool StartDIBits(const CFX_RetainPtr<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 cc09d07638..927bcddd09 100644
--- a/fpdfsdk/fpdf_progressive.cpp
+++ b/fpdfsdk/fpdf_progressive.cpp
@@ -6,6 +6,8 @@
#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"
@@ -44,11 +46,14 @@ DLLEXPORT int STDCALL FPDF_RenderPageBitmap_Start(FPDF_BITMAP bitmap,
if (!pPage)
return FPDF_RENDER_FAILED;
- 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);
+ 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);
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 69151d1999..ca78088793 100644
--- a/fpdfsdk/fpdfeditimg.cpp
+++ b/fpdfsdk/fpdfeditimg.cpp
@@ -105,7 +105,8 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetBitmap(FPDF_PAGE* pages,
if (pPage)
pImgObj->GetImage()->ResetCache(pPage, nullptr);
}
- pImgObj->GetImage()->SetImage(reinterpret_cast<CFX_DIBitmap*>(bitmap));
+ CFX_RetainPtr<CFX_DIBitmap> holder(CFXBitmapFromFPDFBitmap(bitmap));
+ pImgObj->GetImage()->SetImage(holder);
pImgObj->CalcBoundingBox();
return true;
}
diff --git a/fpdfsdk/fpdfformfill.cpp b/fpdfsdk/fpdfformfill.cpp
index c2bbeff7e3..6e31e1f045 100644
--- a/fpdfsdk/fpdfformfill.cpp
+++ b/fpdfsdk/fpdfformfill.cpp
@@ -109,11 +109,12 @@ 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);
- std::unique_ptr<CFX_FxgeDevice> pDevice(new CFX_FxgeDevice);
+ auto pDevice = pdfium::MakeUnique<CFX_FxgeDevice>();
#ifdef _SKIA_SUPPORT_
pDevice->AttachRecorder(static_cast<SkPictureRecorder*>(recorder));
#endif
- pDevice->Attach(CFXBitmapFromFPDFBitmap(bitmap), false, nullptr, false);
+ CFX_RetainPtr<CFX_DIBitmap> holder(CFXBitmapFromFPDFBitmap(bitmap));
+ pDevice->Attach(holder, false, nullptr, false);
pDevice->SaveState();
pDevice->SetClip_Rect(clip);
@@ -147,7 +148,7 @@ void FFLCommon(FPDF_FORMHANDLE hHandle,
pDevice->RestoreState(false);
#ifdef _SKIA_SUPPORT_PATHS_
pDevice->Flush();
- CFXBitmapFromFPDFBitmap(bitmap)->UnPreMultiply();
+ holder->UnPreMultiply();
#endif
}
diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp
index d4284a3217..dcfa1c1925 100644
--- a/fpdfsdk/fpdfview.cpp
+++ b/fpdfsdk/fpdfview.cpp
@@ -709,41 +709,39 @@ DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc,
CPDF_PageRenderContext* pContext = new CPDF_PageRenderContext;
pPage->SetRenderContext(pdfium::WrapUnique(pContext));
- std::unique_ptr<CFX_DIBitmap> pBitmap;
+ CFX_RetainPtr<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::MakeUnique<CFX_DIBitmap>();
+ pBitmap = pdfium::MakeRetain<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.get(), false, nullptr, false);
+ pDevice->Attach(pBitmap, 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) {
- std::unique_ptr<CFX_DIBitmap> pDst = pdfium::MakeUnique<CFX_DIBitmap>();
+ auto pDst = pdfium::MakeRetain<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.get(), 0, 0,
+ pDst->CompositeBitmap(0, 0, size_x, size_y, pBitmap, 0, 0,
FXDIB_BLEND_NORMAL, nullptr, false, nullptr);
- WinDC.StretchDIBits(pDst.get(), 0, 0, size_x, size_y);
+ WinDC.StretchDIBits(pDst, 0, 0, size_x, size_y);
} else {
- WinDC.SetDIBits(pBitmap.get(), 0, 0);
+ WinDC.SetDIBits(pBitmap, 0, 0);
}
}
-
pPage->SetRenderContext(nullptr);
}
#endif // defined(_WIN32)
@@ -765,11 +763,12 @@ 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_DIBitmap* pBitmap = CFXBitmapFromFPDFBitmap(bitmap);
- pDevice->Attach(pBitmap, !!(flags & FPDF_REVERSE_BYTE_ORDER), nullptr, false);
+ CFX_RetainPtr<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);
@@ -794,9 +793,11 @@ 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_DIBitmap* pBitmap = CFXBitmapFromFPDFBitmap(bitmap);
+
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap(CFXBitmapFromFPDFBitmap(bitmap));
pDevice->Attach(pBitmap, !!(flags & FPDF_REVERSE_BYTE_ORDER), nullptr, false);
CFX_Matrix transform_matrix = pPage->GetPageMatrix();
@@ -940,11 +941,11 @@ DLLEXPORT void STDCALL FPDF_PageToDevice(FPDF_PAGE page,
DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_Create(int width,
int height,
int alpha) {
- auto pBitmap = pdfium::MakeUnique<CFX_DIBitmap>();
+ auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
if (!pBitmap->Create(width, height, alpha ? FXDIB_Argb : FXDIB_Rgb32))
return nullptr;
- return pBitmap.release();
+ return pBitmap.Leak();
}
DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_CreateEx(int width,
@@ -969,9 +970,9 @@ DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_CreateEx(int width,
default:
return nullptr;
}
- CFX_DIBitmap* pBitmap = new CFX_DIBitmap;
+ auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
pBitmap->Create(width, height, fx_format, (uint8_t*)first_scan, stride);
- return pBitmap;
+ return pBitmap.Leak();
}
DLLEXPORT void STDCALL FPDFBitmap_FillRect(FPDF_BITMAP bitmap,
@@ -984,7 +985,7 @@ DLLEXPORT void STDCALL FPDFBitmap_FillRect(FPDF_BITMAP bitmap,
return;
CFX_FxgeDevice device;
- CFX_DIBitmap* pBitmap = CFXBitmapFromFPDFBitmap(bitmap);
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap(CFXBitmapFromFPDFBitmap(bitmap));
device.Attach(pBitmap, false, nullptr, false);
if (!pBitmap->HasAlpha())
color |= 0xFF000000;
@@ -1009,7 +1010,8 @@ DLLEXPORT int STDCALL FPDFBitmap_GetStride(FPDF_BITMAP bitmap) {
}
DLLEXPORT void STDCALL FPDFBitmap_Destroy(FPDF_BITMAP bitmap) {
- delete CFXBitmapFromFPDFBitmap(bitmap);
+ CFX_RetainPtr<CFX_DIBitmap> destroyer;
+ destroyer.Unleak(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 1db39751db..162a0bf772 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;
- std::unique_ptr<CFX_DIBitmap> bitmap(new CFX_DIBitmap);
+ auto bitmap = pdfium::MakeRetain<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 bea7ba2dbe..92ba210be3 100644
--- a/testing/libfuzzer/pdf_jpx_fuzzer.cc
+++ b/testing/libfuzzer/pdf_jpx_fuzzer.cc
@@ -37,8 +37,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
width = (width * components + 2) / 3;
format = FXDIB_Rgb;
}
-
- std::unique_ptr<CFX_DIBitmap> bitmap(new CFX_DIBitmap);
+ auto bitmap = pdfium::MakeRetain<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 9a8b23e368..85cedec9a1 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;
- std::unique_ptr<CFX_DIBitmap> bitmap(new CFX_DIBitmap);
+ auto bitmap = pdfium::MakeRetain<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.get(), 0, 0, bitmap->GetWidth(),
+ status = decoder->StartDecode(bitmap, 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 3c6ca9b37e..8af769aae5 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(CFX_DIBSource* pDib,
+bool CFDE_RenderDevice::DrawImage(const CFX_RetainPtr<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 976e1bde6f..a3a1eaf111 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(CFX_DIBSource* pDib,
+ bool DrawImage(const CFX_RetainPtr<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 7f6eddd9ce..c06a12fedf 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(CFX_DIBitmap* pDIB) {
+void CFDE_TextOut::SetDIBitmap(const CFX_RetainPtr<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 6883a5701f..e48e25567e 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(CFX_DIBitmap* pDIB);
+ void SetDIBitmap(const CFX_RetainPtr<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 3f20488830..f23f26e229 100644
--- a/xfa/fwl/cfwl_themebackground.h
+++ b/xfa/fwl/cfwl_themebackground.h
@@ -16,12 +16,17 @@ class CFX_Path;
class CFWL_ThemeBackground : public CFWL_ThemePart {
public:
- CFWL_ThemeBackground()
- : m_pGraphics(nullptr), m_pImage(nullptr), m_pPath(nullptr) {}
+ CFWL_ThemeBackground();
+ ~CFWL_ThemeBackground();
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 328352c6c1..9c9427aaa5 100644
--- a/xfa/fxbarcode/BC_TwoDimWriter.cpp
+++ b/xfa/fxbarcode/BC_TwoDimWriter.cpp
@@ -57,8 +57,9 @@ int32_t CBC_TwoDimWriter::GetErrorCorrectionLevel() const {
return m_iCorrectLevel;
}
-void CBC_TwoDimWriter::RenderBitmapResult(CFX_DIBitmap*& pOutBitmap,
- int32_t& e) {
+void CBC_TwoDimWriter::RenderBitmapResult(
+ CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
+ int32_t& e) {
if (m_bFixedSize) {
pOutBitmap = CreateDIBitmap(m_Width, m_Height);
} else {
@@ -82,12 +83,8 @@ void CBC_TwoDimWriter::RenderBitmapResult(CFX_DIBitmap*& pOutBitmap,
}
}
}
- if (!m_bFixedSize) {
- std::unique_ptr<CFX_DIBitmap> pStretchBitmap =
- pOutBitmap->StretchTo(m_Width, m_Height);
- delete pOutBitmap;
- pOutBitmap = pStretchBitmap.release();
- }
+ if (!m_bFixedSize)
+ pOutBitmap = pOutBitmap->StretchTo(m_Width, m_Height);
}
void CBC_TwoDimWriter::RenderResult(uint8_t* code,
diff --git a/xfa/fxbarcode/BC_TwoDimWriter.h b/xfa/fxbarcode/BC_TwoDimWriter.h
index ad4658b008..c6e0495aec 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_DIBitmap*& pOutBitmap, int32_t& e);
+ virtual void RenderBitmapResult(CFX_RetainPtr<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 73163522cb..69f34148f4 100644
--- a/xfa/fxbarcode/BC_Writer.cpp
+++ b/xfa/fxbarcode/BC_Writer.cpp
@@ -49,8 +49,10 @@ void CBC_Writer::SetBackgroundColor(FX_ARGB backgroundColor) {
void CBC_Writer::SetBarcodeColor(FX_ARGB foregroundColor) {
m_barColor = foregroundColor;
}
-CFX_DIBitmap* CBC_Writer::CreateDIBitmap(int32_t width, int32_t height) {
- CFX_DIBitmap* pDIBitmap = new CFX_DIBitmap;
+
+CFX_RetainPtr<CFX_DIBitmap> CBC_Writer::CreateDIBitmap(int32_t width,
+ int32_t height) {
+ auto pDIBitmap = pdfium::MakeRetain<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 90ea06a397..8dd03ead58 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_DIBitmap* CreateDIBitmap(int32_t width, int32_t height);
+ CFX_RetainPtr<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 53e351d5a2..c49fe95948 100644
--- a/xfa/fxbarcode/cbc_codabar.cpp
+++ b/xfa/fxbarcode/cbc_codabar.cpp
@@ -93,7 +93,8 @@ bool CBC_Codabar::RenderDevice(CFX_RenderDevice* device,
return true;
}
-bool CBC_Codabar::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) {
+bool CBC_Codabar::RenderBitmap(CFX_RetainPtr<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 43f1a010c0..f00c295f44 100644
--- a/xfa/fxbarcode/cbc_codabar.h
+++ b/xfa/fxbarcode/cbc_codabar.h
@@ -24,7 +24,8 @@ class CBC_Codabar : public CBC_OneCode {
bool RenderDevice(CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t& e) override;
- bool RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) override;
+ bool RenderBitmap(CFX_RetainPtr<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 35bd136fd0..ea0bc56fce 100644
--- a/xfa/fxbarcode/cbc_code128.cpp
+++ b/xfa/fxbarcode/cbc_code128.cpp
@@ -78,12 +78,11 @@ bool CBC_Code128::RenderDevice(CFX_RenderDevice* device,
return true;
}
-bool CBC_Code128::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) {
+bool CBC_Code128::RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
+ int32_t& e) {
static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
->RenderBitmapResult(pOutBitmap, m_renderContents.AsStringC(), e);
- if (e != BCExceptionNO)
- return false;
- return true;
+ return e == BCExceptionNO;
}
BC_TYPE CBC_Code128::GetType() {
diff --git a/xfa/fxbarcode/cbc_code128.h b/xfa/fxbarcode/cbc_code128.h
index 0dd9c84f68..d8505760a6 100644
--- a/xfa/fxbarcode/cbc_code128.h
+++ b/xfa/fxbarcode/cbc_code128.h
@@ -24,7 +24,8 @@ class CBC_Code128 : public CBC_OneCode {
bool RenderDevice(CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t& e) override;
- bool RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) override;
+ bool RenderBitmap(CFX_RetainPtr<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 af45ad4063..e3cfccbd90 100644
--- a/xfa/fxbarcode/cbc_code39.cpp
+++ b/xfa/fxbarcode/cbc_code39.cpp
@@ -70,15 +70,14 @@ bool CBC_Code39::RenderDevice(CFX_RenderDevice* device,
return true;
}
-bool CBC_Code39::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) {
+bool CBC_Code39::RenderBitmap(CFX_RetainPtr<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);
- if (e != BCExceptionNO)
- return false;
- return true;
+ return e == BCExceptionNO;
}
BC_TYPE CBC_Code39::GetType() {
diff --git a/xfa/fxbarcode/cbc_code39.h b/xfa/fxbarcode/cbc_code39.h
index 7f5c627c6c..0320211631 100644
--- a/xfa/fxbarcode/cbc_code39.h
+++ b/xfa/fxbarcode/cbc_code39.h
@@ -24,7 +24,8 @@ class CBC_Code39 : public CBC_OneCode {
bool RenderDevice(CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t& e) override;
- bool RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) override;
+ bool RenderBitmap(CFX_RetainPtr<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 c28c08b7e7..37a65d2cf6 100644
--- a/xfa/fxbarcode/cbc_codebase.h
+++ b/xfa/fxbarcode/cbc_codebase.h
@@ -30,7 +30,8 @@ class CBC_CodeBase {
virtual bool RenderDevice(CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t& e) = 0;
- virtual bool RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) = 0;
+ virtual bool RenderBitmap(CFX_RetainPtr<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 6122368e84..ebfa8b9901 100644
--- a/xfa/fxbarcode/cbc_datamatrix.cpp
+++ b/xfa/fxbarcode/cbc_datamatrix.cpp
@@ -53,12 +53,11 @@ bool CBC_DataMatrix::RenderDevice(CFX_RenderDevice* device,
return true;
}
-bool CBC_DataMatrix::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) {
+bool CBC_DataMatrix::RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
+ int32_t& e) {
static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get())
->RenderBitmapResult(pOutBitmap, e);
- if (e != BCExceptionNO)
- return false;
- return true;
+ return e == BCExceptionNO;
}
BC_TYPE CBC_DataMatrix::GetType() {
diff --git a/xfa/fxbarcode/cbc_datamatrix.h b/xfa/fxbarcode/cbc_datamatrix.h
index 661b48d744..ebca372f3f 100644
--- a/xfa/fxbarcode/cbc_datamatrix.h
+++ b/xfa/fxbarcode/cbc_datamatrix.h
@@ -24,7 +24,8 @@ class CBC_DataMatrix : public CBC_CodeBase {
bool RenderDevice(CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t& e) override;
- bool RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) override;
+ bool RenderBitmap(CFX_RetainPtr<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 abd5f198a3..afe52db9dd 100644
--- a/xfa/fxbarcode/cbc_ean13.cpp
+++ b/xfa/fxbarcode/cbc_ean13.cpp
@@ -83,12 +83,11 @@ bool CBC_EAN13::RenderDevice(CFX_RenderDevice* device,
return true;
}
-bool CBC_EAN13::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) {
+bool CBC_EAN13::RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
+ int32_t& e) {
static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
->RenderBitmapResult(pOutBitmap, m_renderContents.AsStringC(), e);
- if (e != BCExceptionNO)
- return false;
- return true;
+ return e == BCExceptionNO;
}
BC_TYPE CBC_EAN13::GetType() {
diff --git a/xfa/fxbarcode/cbc_ean13.h b/xfa/fxbarcode/cbc_ean13.h
index f0e7940a04..5f23855ead 100644
--- a/xfa/fxbarcode/cbc_ean13.h
+++ b/xfa/fxbarcode/cbc_ean13.h
@@ -24,7 +24,8 @@ class CBC_EAN13 : public CBC_OneCode {
bool RenderDevice(CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t& e) override;
- bool RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) override;
+ bool RenderBitmap(CFX_RetainPtr<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 bfb458521e..408b43a608 100644
--- a/xfa/fxbarcode/cbc_ean8.cpp
+++ b/xfa/fxbarcode/cbc_ean8.cpp
@@ -82,12 +82,11 @@ bool CBC_EAN8::RenderDevice(CFX_RenderDevice* device,
return true;
}
-bool CBC_EAN8::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) {
+bool CBC_EAN8::RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
+ int32_t& e) {
static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
->RenderBitmapResult(pOutBitmap, m_renderContents.AsStringC(), e);
- if (e != BCExceptionNO)
- return false;
- return true;
+ return e == BCExceptionNO;
}
BC_TYPE CBC_EAN8::GetType() {
diff --git a/xfa/fxbarcode/cbc_ean8.h b/xfa/fxbarcode/cbc_ean8.h
index 6a475cb795..478a67405c 100644
--- a/xfa/fxbarcode/cbc_ean8.h
+++ b/xfa/fxbarcode/cbc_ean8.h
@@ -24,7 +24,8 @@ class CBC_EAN8 : public CBC_OneCode {
bool RenderDevice(CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t& e) override;
- bool RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) override;
+ bool RenderBitmap(CFX_RetainPtr<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 1c5547d445..a5e210757a 100644
--- a/xfa/fxbarcode/cbc_pdf417i.cpp
+++ b/xfa/fxbarcode/cbc_pdf417i.cpp
@@ -63,12 +63,11 @@ bool CBC_PDF417I::RenderDevice(CFX_RenderDevice* device,
return true;
}
-bool CBC_PDF417I::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) {
+bool CBC_PDF417I::RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
+ int32_t& e) {
static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get())
->RenderBitmapResult(pOutBitmap, e);
- if (e != BCExceptionNO)
- return false;
- return true;
+ return e == BCExceptionNO;
}
BC_TYPE CBC_PDF417I::GetType() {
diff --git a/xfa/fxbarcode/cbc_pdf417i.h b/xfa/fxbarcode/cbc_pdf417i.h
index 70ea929820..c26dceeebd 100644
--- a/xfa/fxbarcode/cbc_pdf417i.h
+++ b/xfa/fxbarcode/cbc_pdf417i.h
@@ -24,7 +24,8 @@ class CBC_PDF417I : public CBC_CodeBase {
bool RenderDevice(CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t& e) override;
- bool RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) override;
+ bool RenderBitmap(CFX_RetainPtr<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 26b74ca400..e046857b6b 100644
--- a/xfa/fxbarcode/cbc_qrcode.cpp
+++ b/xfa/fxbarcode/cbc_qrcode.cpp
@@ -69,12 +69,11 @@ bool CBC_QRCode::RenderDevice(CFX_RenderDevice* device,
return true;
}
-bool CBC_QRCode::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) {
+bool CBC_QRCode::RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
+ int32_t& e) {
static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get())
->RenderBitmapResult(pOutBitmap, e);
- if (e != BCExceptionNO)
- return false;
- return true;
+ return e == BCExceptionNO;
}
BC_TYPE CBC_QRCode::GetType() {
diff --git a/xfa/fxbarcode/cbc_qrcode.h b/xfa/fxbarcode/cbc_qrcode.h
index ac2d93d915..05f3f6c415 100644
--- a/xfa/fxbarcode/cbc_qrcode.h
+++ b/xfa/fxbarcode/cbc_qrcode.h
@@ -24,7 +24,8 @@ class CBC_QRCode : public CBC_CodeBase {
bool RenderDevice(CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t& e) override;
- bool RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) override;
+ bool RenderBitmap(CFX_RetainPtr<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 87f58093ae..915a6aead5 100644
--- a/xfa/fxbarcode/cbc_upca.cpp
+++ b/xfa/fxbarcode/cbc_upca.cpp
@@ -86,12 +86,11 @@ bool CBC_UPCA::RenderDevice(CFX_RenderDevice* device,
return true;
}
-bool CBC_UPCA::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) {
+bool CBC_UPCA::RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
+ int32_t& e) {
static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
->RenderBitmapResult(pOutBitmap, m_renderContents.AsStringC(), e);
- if (e != BCExceptionNO)
- return false;
- return true;
+ return e == BCExceptionNO;
}
BC_TYPE CBC_UPCA::GetType() {
diff --git a/xfa/fxbarcode/cbc_upca.h b/xfa/fxbarcode/cbc_upca.h
index bf90b922b5..4015a3143d 100644
--- a/xfa/fxbarcode/cbc_upca.h
+++ b/xfa/fxbarcode/cbc_upca.h
@@ -24,7 +24,8 @@ class CBC_UPCA : public CBC_OneCode {
bool RenderDevice(CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t& e) override;
- bool RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) override;
+ bool RenderBitmap(CFX_RetainPtr<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 02ae58dc84..16eba2df10 100644
--- a/xfa/fxbarcode/oned/BC_OneDimWriter.cpp
+++ b/xfa/fxbarcode/oned/BC_OneDimWriter.cpp
@@ -224,13 +224,14 @@ void CBC_OneDimWriter::ShowDeviceChars(CFX_RenderDevice* device,
m_fontColor, FXTEXT_CLEARTYPE);
}
-void CBC_OneDimWriter::ShowBitmapChars(CFX_DIBitmap* pOutBitmap,
- const CFX_ByteString str,
- float geWidth,
- FXTEXT_CHARPOS* pCharPos,
- float locX,
- float locY,
- int32_t barWidth) {
+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) {
int32_t iFontSize = (int32_t)fabs(m_fFontSize);
int32_t iTextHeight = iFontSize + 1;
CFX_FxgeDevice ge;
@@ -248,7 +249,7 @@ void CBC_OneDimWriter::ShowBitmapChars(CFX_DIBitmap* pOutBitmap,
}
void CBC_OneDimWriter::ShowChars(const CFX_WideStringC& contents,
- CFX_DIBitmap* pOutBitmap,
+ const CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t barWidth,
@@ -316,9 +317,10 @@ void CBC_OneDimWriter::ShowChars(const CFX_WideStringC& contents,
FX_Free(pCharPos);
}
-void CBC_OneDimWriter::RenderBitmapResult(CFX_DIBitmap*& pOutBitmap,
- const CFX_WideStringC& contents,
- int32_t& e) {
+void CBC_OneDimWriter::RenderBitmapResult(
+ CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
+ const CFX_WideStringC& contents,
+ int32_t& e) {
if (!m_output)
if (e != BCExceptionNO)
return;
@@ -337,20 +339,17 @@ void CBC_OneDimWriter::RenderBitmapResult(CFX_DIBitmap*& pOutBitmap,
}
}
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;
}
- std::unique_ptr<CFX_DIBitmap> pStretchBitmap =
- pOutBitmap->StretchTo(m_Width, m_Height);
- delete pOutBitmap;
- pOutBitmap = pStretchBitmap.release();
+ pOutBitmap = pOutBitmap->StretchTo(m_Width, m_Height);
}
void CBC_OneDimWriter::RenderDeviceResult(CFX_RenderDevice* device,
diff --git a/xfa/fxbarcode/oned/BC_OneDimWriter.h b/xfa/fxbarcode/oned/BC_OneDimWriter.h
index b2447cffb7..4892889ddb 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_DIBitmap*& pOutBitmap,
+ virtual void RenderBitmapResult(CFX_RetainPtr<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,
- CFX_DIBitmap* pOutBitmap,
+ const CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
CFX_RenderDevice* device,
const CFX_Matrix* matrix,
int32_t barWidth,
int32_t multiple,
int32_t& e);
- virtual void ShowBitmapChars(CFX_DIBitmap* pOutBitmap,
+ virtual void ShowBitmapChars(const CFX_RetainPtr<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 555b58643d..dcea777089 100644
--- a/xfa/fxbarcode/oned/BC_OnedEAN13Writer.cpp
+++ b/xfa/fxbarcode/oned/BC_OnedEAN13Writer.cpp
@@ -167,13 +167,14 @@ uint8_t* CBC_OnedEAN13Writer::Encode(const CFX_ByteString& contents,
return result;
}
-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) {
+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) {
if (!device && !pOutBitmap) {
e = BCExceptionIllegalArgument;
return;
@@ -278,7 +279,6 @@ void CBC_OnedEAN13Writer::ShowChars(const CFX_WideStringC& contents,
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 5775f89046..8336259568 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,
- CFX_DIBitmap* pOutBitmap,
+ const CFX_RetainPtr<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 5f571c2a30..a7fa30c811 100644
--- a/xfa/fxbarcode/oned/BC_OnedEAN8Writer.cpp
+++ b/xfa/fxbarcode/oned/BC_OnedEAN8Writer.cpp
@@ -165,13 +165,14 @@ uint8_t* CBC_OnedEAN8Writer::Encode(const CFX_ByteString& contents,
return result;
}
-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) {
+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) {
if (!device && !pOutBitmap) {
e = BCExceptionIllegalArgument;
return;
@@ -217,7 +218,6 @@ void CBC_OnedEAN8Writer::ShowChars(const CFX_WideStringC& contents,
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,7 +237,6 @@ void CBC_OnedEAN8Writer::ShowChars(const CFX_WideStringC& contents,
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 844fc33afa..b9921babc3 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,
- CFX_DIBitmap* pOutBitmap,
+ const CFX_RetainPtr<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 cefae97d8d..540e852d5d 100644
--- a/xfa/fxbarcode/oned/BC_OnedUPCAWriter.cpp
+++ b/xfa/fxbarcode/oned/BC_OnedUPCAWriter.cpp
@@ -117,13 +117,14 @@ uint8_t* CBC_OnedUPCAWriter::Encode(const CFX_ByteString& contents,
return nullptr;
}
-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) {
+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) {
if (!device && !pOutBitmap) {
e = BCExceptionIllegalArgument;
return;
@@ -235,7 +236,6 @@ void CBC_OnedUPCAWriter::ShowChars(const CFX_WideStringC& contents,
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,7 +255,6 @@ void CBC_OnedUPCAWriter::ShowChars(const CFX_WideStringC& contents,
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 6b786ce3b8..6c0929a051 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,
- CFX_DIBitmap* pOutBitmap,
+ const CFX_RetainPtr<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 81188c14d1..23ed88616d 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_DIBitmap* pDIBitmap = GetDataAcc()->GetImageImage();
+ CFX_RetainPtr<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 b776579152..624ef3f442 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_DIBitmap* pDIBitmap = m_pDataAcc->GetImageEditImage();
+ CFX_RetainPtr<CFX_DIBitmap> pDIBitmap = m_pDataAcc->GetImageEditImage();
if (!pDIBitmap)
return;
diff --git a/xfa/fxfa/cxfa_ffdoc.cpp b/xfa/fxfa/cxfa_ffdoc.cpp
index fdeacf7f0f..e14500a725 100644
--- a/xfa/fxfa/cxfa_ffdoc.cpp
+++ b/xfa/fxfa/cxfa_ffdoc.cpp
@@ -332,10 +332,6 @@ 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;
@@ -345,9 +341,10 @@ CPDF_Document* CXFA_FFDoc::GetPDFDoc() {
return m_pPDFDoc;
}
-CFX_DIBitmap* CXFA_FFDoc::GetPDFNamedImage(const CFX_WideStringC& wsName,
- int32_t& iImageXDpi,
- int32_t& iImageYDpi) {
+CFX_RetainPtr<CFX_DIBitmap> CXFA_FFDoc::GetPDFNamedImage(
+ const CFX_WideStringC& wsName,
+ int32_t& iImageXDpi,
+ int32_t& iImageYDpi) {
if (!m_pPDFDoc)
return nullptr;
@@ -356,7 +353,7 @@ CFX_DIBitmap* CXFA_FFDoc::GetPDFNamedImage(const CFX_WideStringC& wsName,
if (it != m_HashToDibDpiMap.end()) {
iImageXDpi = it->second.iImageXDpi;
iImageYDpi = it->second.iImageYDpi;
- return static_cast<CFX_DIBitmap*>(it->second.pDibSource);
+ return it->second.pDibSource.As<CFX_DIBitmap>();
}
CPDF_Dictionary* pRoot = m_pPDFDoc->GetRoot();
@@ -396,7 +393,7 @@ CFX_DIBitmap* CXFA_FFDoc::GetPDFNamedImage(const CFX_WideStringC& wsName,
IFX_MemoryStream::Create((uint8_t*)streamAcc.GetData(),
streamAcc.GetSize());
- CFX_DIBitmap* pDibSource = XFA_LoadImageFromBuffer(
+ CFX_RetainPtr<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 1d46387a5e..80dafba029 100644
--- a/xfa/fxfa/cxfa_ffdoc.h
+++ b/xfa/fxfa/cxfa_ffdoc.h
@@ -20,11 +20,30 @@ class CXFA_FFNotify;
class CXFA_FFDocView;
struct FX_IMAGEDIB_AND_DPI {
- CFX_DIBSource* pDibSource;
+ 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;
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);
@@ -48,9 +67,9 @@ class CXFA_FFDoc {
CXFA_FFDocView* GetDocView(CXFA_LayoutProcessor* pLayout);
CXFA_FFDocView* GetDocView();
CPDF_Document* GetPDFDoc();
- CFX_DIBitmap* GetPDFNamedImage(const CFX_WideStringC& wsName,
- int32_t& iImageXDpi,
- int32_t& iImageYDpi);
+ CFX_RetainPtr<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 504ce70ad9..2e9c9a6ac8 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,
- CFX_DIBSource* pDIBSource,
+ const CFX_RetainPtr<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(CFX_DIBitmap* pDIBitmap,
+ void CompositeDIBitmap(const CFX_RetainPtr<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_DIBSource* m_pDIBSource;
- std::unique_ptr<CFX_DIBitmap> m_pCloneConvert;
+ CFX_RetainPtr<CFX_DIBSource> m_pDIBSource;
+ CFX_RetainPtr<CFX_DIBitmap> m_pCloneConvert;
int m_BitmapAlpha;
FX_ARGB m_FillArgb;
uint32_t m_Flags;
@@ -594,7 +594,6 @@ 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),
@@ -609,7 +608,7 @@ CXFA_ImageRenderer::~CXFA_ImageRenderer() {
}
bool CXFA_ImageRenderer::Start(CFX_RenderDevice* pDevice,
- CFX_DIBSource* pDIBSource,
+ const CFX_RetainPtr<CFX_DIBSource>& pDIBSource,
FX_ARGB bitmap_argb,
int bitmap_alpha,
const CFX_Matrix* pImage2Device,
@@ -645,7 +644,7 @@ bool CXFA_ImageRenderer::StartDIBSource() {
m_Result = false;
return false;
}
- CFX_DIBSource* pDib = m_pDIBSource;
+ CFX_RetainPtr<CFX_DIBSource> pDib = m_pDIBSource;
if (m_pDIBSource->HasAlpha() &&
!(m_pDevice->GetRenderCaps() & FXRC_ALPHA_IMAGE) &&
!(m_pDevice->GetRenderCaps() & FXRC_GET_BITS)) {
@@ -654,13 +653,13 @@ bool CXFA_ImageRenderer::StartDIBSource() {
m_Result = false;
return false;
}
- pDib = m_pCloneConvert.get();
+ pDib = m_pCloneConvert;
}
FX_RECT clip_box = m_pDevice->GetClipBox();
clip_box.Intersect(image_rect);
m_Status = 2;
- m_pTransformer.reset(
- new CFX_ImageTransformer(pDib, &m_ImageMatrix, m_Flags, &clip_box));
+ m_pTransformer = pdfium::MakeUnique<CFX_ImageTransformer>(
+ pDib, &m_ImageMatrix, m_Flags, &clip_box);
m_pTransformer->Start();
return true;
}
@@ -700,11 +699,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);
- std::unique_ptr<CFX_DIBitmap> pStretched(
- m_pDIBSource->StretchTo(dest_width, dest_height, m_Flags, &dest_clip));
+ CFX_RetainPtr<CFX_DIBitmap> pStretched =
+ m_pDIBSource->StretchTo(dest_width, dest_height, m_Flags, &dest_clip);
if (pStretched) {
- CompositeDIBitmap(pStretched.get(), dest_rect.left, dest_rect.top,
- m_FillArgb, m_BitmapAlpha, m_BlendType, false);
+ CompositeDIBitmap(pStretched, dest_rect.left, dest_rect.top, m_FillArgb,
+ m_BitmapAlpha, m_BlendType, false);
}
return false;
}
@@ -714,7 +713,7 @@ bool CXFA_ImageRenderer::Continue(IFX_Pause* pPause) {
if (m_pTransformer->Continue(pPause))
return true;
- std::unique_ptr<CFX_DIBitmap> pBitmap(m_pTransformer->DetachBitmap());
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap = m_pTransformer->DetachBitmap();
if (!pBitmap)
return false;
@@ -722,14 +721,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.get(), m_pTransformer->result().left,
+ m_pDevice->SetBitMask(pBitmap, 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.get(), m_pTransformer->result().left,
- m_pTransformer->result().top, m_BlendType);
+ pBitmap, m_pTransformer->result().left, m_pTransformer->result().top,
+ m_BlendType);
}
return false;
}
@@ -739,13 +738,14 @@ bool CXFA_ImageRenderer::Continue(IFX_Pause* pPause) {
return false;
}
-void CXFA_ImageRenderer::CompositeDIBitmap(CFX_DIBitmap* pDIBitmap,
- int left,
- int top,
- FX_ARGB mask_argb,
- int bitmap_alpha,
- int blend_mode,
- int Transparency) {
+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) {
if (!pDIBitmap) {
return;
}
@@ -785,10 +785,10 @@ void CXFA_ImageRenderer::CompositeDIBitmap(CFX_DIBitmap* pDIBitmap,
FX_RECT rect(left, top, left + pDIBitmap->GetWidth(),
top + pDIBitmap->GetHeight());
rect.Intersect(m_pDevice->GetClipBox());
- CFX_MaybeOwned<CFX_DIBitmap> pClone;
+ CFX_RetainPtr<CFX_DIBitmap> pClone;
if (m_pDevice->GetBackDrop() && m_pDevice->GetBitmap()) {
pClone = m_pDevice->GetBackDrop()->Clone(&rect);
- CFX_DIBitmap* pForeBitmap = m_pDevice->GetBitmap();
+ CFX_RetainPtr<CFX_DIBitmap> pForeBitmap = m_pDevice->GetBitmap();
pClone->CompositeBitmap(0, 0, pClone->GetWidth(), pClone->GetHeight(),
pForeBitmap, rect.left, rect.top);
left = left >= 0 ? 0 : left;
@@ -803,7 +803,7 @@ void CXFA_ImageRenderer::CompositeDIBitmap(CFX_DIBitmap* pDIBitmap,
pClone = pDIBitmap;
}
if (m_pDevice->GetBackDrop()) {
- m_pDevice->SetDIBits(pClone.Get(), rect.left, rect.top);
+ m_pDevice->SetDIBits(pClone, rect.left, rect.top);
} else {
if (pDIBitmap->IsAlphaMask())
return;
@@ -817,14 +817,14 @@ void CXFA_ImageRenderer::CompositeDIBitmap(CFX_DIBitmap* pDIBitmap,
(m_pDevice->GetRenderCaps() & FXRC_ALPHA_IMAGE)) {
return;
}
- std::unique_ptr<CFX_DIBitmap> pCloneConvert =
+ CFX_RetainPtr<CFX_DIBitmap> pCloneConvert =
pDIBitmap->CloneConvert(FXDIB_Rgb);
if (!pCloneConvert)
return;
CXFA_ImageRenderer imageRender;
- if (!imageRender.Start(m_pDevice, pCloneConvert.get(), m_FillArgb,
- m_BitmapAlpha, &m_ImageMatrix, m_Flags)) {
+ if (!imageRender.Start(m_pDevice, pCloneConvert, m_FillArgb, m_BitmapAlpha,
+ &m_ImageMatrix, m_Flags)) {
return;
}
while (imageRender.Continue(nullptr))
@@ -834,7 +834,7 @@ void CXFA_ImageRenderer::CompositeDIBitmap(CFX_DIBitmap* pDIBitmap,
void XFA_DrawImage(CFX_Graphics* pGS,
const CFX_RectF& rtImage,
CFX_Matrix* pMatrix,
- CFX_DIBitmap* pDIBitmap,
+ const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap,
int32_t iAspect,
int32_t iImageXDpi,
int32_t iImageYDpi,
@@ -1034,18 +1034,19 @@ FXCODEC_IMAGE_TYPE XFA_GetImageType(const CFX_WideString& wsType) {
return FXCODEC_IMAGE_TIF;
return FXCODEC_IMAGE_UNKNOWN;
}
-CFX_DIBitmap* XFA_LoadImageData(CXFA_FFDoc* pDoc,
- CXFA_Image* pImage,
- bool& bNameImage,
- int32_t& iImageXDpi,
- int32_t& iImageYDpi) {
+
+CFX_RetainPtr<CFX_DIBitmap> XFA_LoadImageData(CXFA_FFDoc* pDoc,
+ CXFA_Image* pImage,
+ bool& bNameImage,
+ int32_t& iImageXDpi,
+ int32_t& iImageYDpi) {
CFX_WideString wsHref;
- pImage->GetHref(wsHref);
CFX_WideString wsImage;
+ pImage->GetHref(wsHref);
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);
@@ -1071,7 +1072,7 @@ CFX_DIBitmap* XFA_LoadImageData(CXFA_FFDoc* pDoc,
} else {
CFX_WideString wsURL = wsHref;
if (wsURL.Left(7) != L"http://" && wsURL.Left(6) != L"ftp://") {
- CFX_DIBitmap* pBitmap =
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap =
pDoc->GetPDFNamedImage(wsURL.AsStringC(), iImageXDpi, iImageYDpi);
if (pBitmap) {
bNameImage = true;
@@ -1085,7 +1086,7 @@ CFX_DIBitmap* XFA_LoadImageData(CXFA_FFDoc* pDoc,
return nullptr;
}
bNameImage = false;
- CFX_DIBitmap* pBitmap =
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap =
XFA_LoadImageFromBuffer(pImageFileRead, type, iImageXDpi, iImageYDpi);
FX_Free(pImageBuffer);
return pBitmap;
@@ -1111,7 +1112,7 @@ static FXDIB_Format XFA_GetDIBFormat(FXCODEC_IMAGE_TYPE type,
return dibFormat;
}
-CFX_DIBitmap* XFA_LoadImageFromBuffer(
+CFX_RetainPtr<CFX_DIBitmap> XFA_LoadImageFromBuffer(
const CFX_RetainPtr<IFX_SeekableReadStream>& pImageFileRead,
FXCODEC_IMAGE_TYPE type,
int32_t& iImageXDpi,
@@ -1125,7 +1126,7 @@ CFX_DIBitmap* XFA_LoadImageFromBuffer(
return nullptr;
CFX_DIBAttribute dibAttr;
- CFX_DIBitmap* pBitmap = nullptr;
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap;
std::unique_ptr<CCodec_ProgressiveDecoder> pProgressiveDecoder =
pCodecMgr->CreateProgressiveDecoder();
pProgressiveDecoder->LoadImageInfo(pImageFileRead, type, &dibAttr, false);
@@ -1149,7 +1150,7 @@ CFX_DIBitmap* XFA_LoadImageFromBuffer(
int32_t iComponents = pProgressiveDecoder->GetNumComponents();
int32_t iBpc = pProgressiveDecoder->GetBPC();
FXDIB_Format dibFormat = XFA_GetDIBFormat(type, iComponents, iBpc);
- pBitmap = new CFX_DIBitmap();
+ pBitmap = pdfium::MakeRetain<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 02a7b21b15..8c83c4cf4c 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,
- CFX_DIBitmap* pDIBitmap,
+ const CFX_RetainPtr<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_DIBitmap* XFA_LoadImageData(CXFA_FFDoc* pDoc,
- CXFA_Image* pImage,
- bool& bNameImage,
- int32_t& iImageXDpi,
- int32_t& iImageYDpi);
+CFX_RetainPtr<CFX_DIBitmap> XFA_LoadImageData(CXFA_FFDoc* pDoc,
+ CXFA_Image* pImage,
+ bool& bNameImage,
+ int32_t& iImageXDpi,
+ int32_t& iImageYDpi);
-CFX_DIBitmap* XFA_LoadImageFromBuffer(
+CFX_RetainPtr<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 4c8e37291a..6e76119115 100644
--- a/xfa/fxfa/cxfa_widgetacc.cpp
+++ b/xfa/fxfa/cxfa_widgetacc.cpp
@@ -67,15 +67,9 @@ class CXFA_TextLayoutData : public CXFA_WidgetLayoutData {
class CXFA_ImageLayoutData : public CXFA_WidgetLayoutData {
public:
CXFA_ImageLayoutData()
- : m_pDIBitmap(nullptr),
- m_bNamedImage(false),
- m_iImageXDpi(0),
- m_iImageYDpi(0) {}
+ : m_bNamedImage(false), m_iImageXDpi(0), m_iImageYDpi(0) {}
- ~CXFA_ImageLayoutData() override {
- if (m_pDIBitmap && !m_bNamedImage)
- delete m_pDIBitmap;
- }
+ ~CXFA_ImageLayoutData() override {}
bool LoadImageData(CXFA_WidgetAcc* pAcc) {
if (m_pDIBitmap)
@@ -95,7 +89,7 @@ class CXFA_ImageLayoutData : public CXFA_WidgetLayoutData {
return !!m_pDIBitmap;
}
- CFX_DIBitmap* m_pDIBitmap;
+ CFX_RetainPtr<CFX_DIBitmap> m_pDIBitmap;
bool m_bNamedImage;
int32_t m_iImageXDpi;
int32_t m_iImageYDpi;
@@ -132,15 +126,9 @@ class CXFA_TextEditData : public CXFA_FieldLayoutData {
class CXFA_ImageEditData : public CXFA_FieldLayoutData {
public:
CXFA_ImageEditData()
- : m_pDIBitmap(nullptr),
- m_bNamedImage(false),
- m_iImageXDpi(0),
- m_iImageYDpi(0) {}
+ : m_bNamedImage(false), m_iImageXDpi(0), m_iImageYDpi(0) {}
- ~CXFA_ImageEditData() override {
- if (m_pDIBitmap && !m_bNamedImage)
- delete m_pDIBitmap;
- }
+ ~CXFA_ImageEditData() override {}
bool LoadImageData(CXFA_WidgetAcc* pAcc) {
if (m_pDIBitmap)
@@ -157,7 +145,7 @@ class CXFA_ImageEditData : public CXFA_FieldLayoutData {
return !!m_pDIBitmap;
}
- CFX_DIBitmap* m_pDIBitmap;
+ CFX_RetainPtr<CFX_DIBitmap> m_pDIBitmap;
bool m_bNamedImage;
int32_t m_iImageXDpi;
int32_t m_iImageYDpi;
@@ -929,7 +917,8 @@ bool CXFA_WidgetAcc::CalculateImageAutoSize(CFX_SizeF& size) {
LoadImageImage();
size.clear();
- if (CFX_DIBitmap* pBitmap = GetImageImage()) {
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap = GetImageImage();
+ if (pBitmap) {
int32_t iImageXDpi = 0;
int32_t iImageYDpi = 0;
GetImageDpi(iImageXDpi, iImageYDpi);
@@ -958,7 +947,8 @@ bool CXFA_WidgetAcc::CalculateImageEditAutoSize(CFX_SizeF& size) {
LoadImageEditImage();
size.clear();
- if (CFX_DIBitmap* pBitmap = GetImageEditImage()) {
+ CFX_RetainPtr<CFX_DIBitmap> pBitmap = GetImageEditImage();
+ if (pBitmap) {
int32_t iImageXDpi = 0;
int32_t iImageYDpi = 0;
GetImageEditDpi(iImageXDpi, iImageYDpi);
@@ -1467,42 +1457,34 @@ CXFA_TextLayout* CXFA_WidgetAcc::GetTextLayout() {
: nullptr;
}
-CFX_DIBitmap* CXFA_WidgetAcc::GetImageImage() {
+CFX_RetainPtr<CFX_DIBitmap> CXFA_WidgetAcc::GetImageImage() {
return m_pLayoutData
? static_cast<CXFA_ImageLayoutData*>(m_pLayoutData.get())
->m_pDIBitmap
: nullptr;
}
-CFX_DIBitmap* CXFA_WidgetAcc::GetImageEditImage() {
+CFX_RetainPtr<CFX_DIBitmap> CXFA_WidgetAcc::GetImageEditImage() {
return m_pLayoutData
? static_cast<CXFA_ImageEditData*>(m_pLayoutData.get())
->m_pDIBitmap
: nullptr;
}
-void CXFA_WidgetAcc::SetImageImage(CFX_DIBitmap* newImage) {
+void CXFA_WidgetAcc::SetImageImage(
+ const CFX_RetainPtr<CFX_DIBitmap>& newImage) {
CXFA_ImageLayoutData* pData =
static_cast<CXFA_ImageLayoutData*>(m_pLayoutData.get());
- if (pData->m_pDIBitmap == newImage)
- return;
-
- if (pData->m_pDIBitmap && !pData->m_bNamedImage)
- delete pData->m_pDIBitmap;
-
- pData->m_pDIBitmap = newImage;
+ if (pData->m_pDIBitmap != newImage)
+ pData->m_pDIBitmap = newImage;
}
-void CXFA_WidgetAcc::SetImageEditImage(CFX_DIBitmap* newImage) {
+void CXFA_WidgetAcc::SetImageEditImage(
+ const CFX_RetainPtr<CFX_DIBitmap>& newImage) {
CXFA_ImageEditData* pData =
static_cast<CXFA_ImageEditData*>(m_pLayoutData.get());
- if (pData->m_pDIBitmap == newImage)
- return;
-
- if (pData->m_pDIBitmap && !pData->m_bNamedImage)
- delete pData->m_pDIBitmap;
-
- pData->m_pDIBitmap = newImage;
+ if (pData->m_pDIBitmap != newImage)
+ pData->m_pDIBitmap = newImage;
}
CXFA_WidgetLayoutData* CXFA_WidgetAcc::GetWidgetLayoutData() {
diff --git a/xfa/fxfa/cxfa_widgetacc.h b/xfa/fxfa/cxfa_widgetacc.h
index 8a7a7eb73d..c08aa1d587 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_DIBitmap* GetImageImage();
- CFX_DIBitmap* GetImageEditImage();
- void SetImageImage(CFX_DIBitmap* newImage);
- void SetImageEditImage(CFX_DIBitmap* newImage);
+ 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);
void UpdateUIDisplay(CXFA_FFWidget* pExcept = nullptr);
CXFA_Node* GetDatasets();
diff --git a/xfa/fxgraphics/cfx_graphics.cpp b/xfa/fxgraphics/cfx_graphics.cpp
index 48d8f6f80f..3cfe2d0192 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(CFX_DIBSource* source,
+void CFX_Graphics::StretchImage(const CFX_RetainPtr<CFX_DIBSource>& source,
const CFX_RectF& rect,
CFX_Matrix* matrix) {
if (!source)
@@ -318,48 +318,49 @@ void CFX_Graphics::RenderDeviceFillPath(CFX_Path* path,
}
}
-void CFX_Graphics::RenderDeviceStretchImage(CFX_DIBSource* source,
- const CFX_RectF& rect,
- CFX_Matrix* matrix) {
+void CFX_Graphics::RenderDeviceStretchImage(
+ const CFX_RetainPtr<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);
}
- std::unique_ptr<CFX_DIBitmap> bmp1 =
+ CFX_RetainPtr<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;
- std::unique_ptr<CFX_DIBitmap> bmp2 = bmp1->FlipImage(false, true);
- std::unique_ptr<CFX_DIBitmap> bmp3 = bmp2->TransformTo(&m2, left, top);
+ CFX_RetainPtr<CFX_DIBitmap> bmp2 = bmp1->FlipImage(false, true);
+ CFX_RetainPtr<CFX_DIBitmap> bmp3 = bmp2->TransformTo(&m2, left, top);
CFX_RectF r = GetClipRect();
- CFX_DIBitmap* bitmap = m_renderDevice->GetBitmap();
+ CFX_RetainPtr<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.get(), FXSYS_round(r.left - left),
- FXSYS_round(r.top - top));
+ FXSYS_round(r.Width()), FXSYS_round(r.Height()), bmp3,
+ 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_DIBitmap* bitmap = m_renderDevice->GetBitmap();
+ CFX_RetainPtr<CFX_DIBitmap> bitmap = m_renderDevice->GetBitmap();
int32_t width = bitmap->GetWidth();
int32_t height = bitmap->GetHeight();
- CFX_DIBitmap bmp;
- bmp.Create(width, height, FXDIB_Argb);
- m_renderDevice->GetDIBits(&bmp, 0, 0);
+ auto bmp = pdfium::MakeRetain<CFX_DIBitmap>();
+ 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)];
- CFX_DIBitmap mask;
- mask.Create(data.width, data.height, FXDIB_1bppMask);
- FXSYS_memcpy(mask.GetBuffer(), data.maskBits, mask.GetPitch() * data.height);
+ 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_FloatRect rectf = path->GetPathData()->GetBoundingBox();
if (matrix)
matrix->TransformRect(rectf);
@@ -367,35 +368,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_DIBitmap* bitmap = m_renderDevice->GetBitmap();
+ CFX_RetainPtr<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;
- CFX_DIBitmap bmp;
- bmp.Create(width, height, FXDIB_Argb);
- m_renderDevice->GetDIBits(&bmp, 0, 0);
- int32_t pitch = bmp.GetPitch();
+ auto bmp = pdfium::MakeRetain<CFX_DIBitmap>();
+ 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: {
@@ -403,7 +404,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);
@@ -434,7 +435,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);
@@ -496,13 +497,14 @@ 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(CFX_DIBSource* source,
- CFX_Matrix* matrix) {
+void CFX_Graphics::SetDIBitsWithMatrix(
+ const CFX_RetainPtr<CFX_DIBSource>& source,
+ CFX_Matrix* matrix) {
if (matrix->IsIdentity()) {
m_renderDevice->SetDIBits(source, 0, 0);
} else {
@@ -511,9 +513,9 @@ void CFX_Graphics::SetDIBitsWithMatrix(CFX_DIBSource* source,
m.Concat(*matrix);
int32_t left;
int32_t 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);
+ 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);
}
}
diff --git a/xfa/fxgraphics/cfx_graphics.h b/xfa/fxgraphics/cfx_graphics.h
index c360813401..264ec94d53 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(CFX_DIBSource* source,
+ void StretchImage(const CFX_RetainPtr<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(CFX_DIBSource* source,
+ void RenderDeviceStretchImage(const CFX_RetainPtr<CFX_DIBSource>& source,
const CFX_RectF& rect,
CFX_Matrix* matrix);
@@ -101,7 +101,8 @@ class CFX_Graphics {
FX_FillMode fillMode,
CFX_Matrix* matrix);
- void SetDIBitsWithMatrix(CFX_DIBSource* source, CFX_Matrix* matrix);
+ void SetDIBitsWithMatrix(const CFX_RetainPtr<CFX_DIBSource>& source,
+ CFX_Matrix* matrix);
CFX_RenderDevice* m_renderDevice;
std::vector<std::unique_ptr<TInfo>> m_infoStack;