diff options
author | Tom Sepez <tsepez@chromium.org> | 2017-03-28 09:31:32 -0700 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-03-28 16:42:55 +0000 |
commit | f0799fe84df4d86f25d342b03525f3016d674f86 (patch) | |
tree | d6839802a68b7b6ad6fb166179ede779c3560c75 /xfa | |
parent | 31b08d4cdaa17d7a03f35e087096a77036af98ec (diff) | |
download | pdfium-f0799fe84df4d86f25d342b03525f3016d674f86.tar.xz |
Revert "Revert "Refcount all CFX_DIBSources (and subclasses) all the time.""
This reverts commit 31b08d4cdaa17d7a03f35e087096a77036af98ec.
Re-landing the patch after fixing skia build issue.
Change-Id: Ie7039890088b803a6ec5ce365d70f57277459b48
Reviewed-on: https://pdfium-review.googlesource.com/3245
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa')
46 files changed, 267 insertions, 261 deletions
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; |