From 0004f29bf6ee3c6060a272c79f14993e92e053c7 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Mon, 27 Mar 2017 13:51:46 -0700 Subject: Refcount all CFX_DIBSources (and subclasses) all the time. There are currently several ownership models for these objects, including ad-hoc logic for sharing and deletion, and the now-redundant CFX_DIBitmapRef externally-counted handle to the DIBs. Replace them all with the internal refcount scheme. Change-Id: I2db399dfc19219eda384f94cc989353b78ce2872 Reviewed-on: https://pdfium-review.googlesource.com/3166 Reviewed-by: dsinclair Commit-Queue: dsinclair --- core/fxge/agg/fx_agg_driver.cpp | 135 ++++++++++----------- core/fxge/agg/fx_agg_driver.h | 20 ++-- core/fxge/apple/apple_int.h | 2 +- core/fxge/apple/fx_apple_platform.cpp | 2 +- core/fxge/apple/fx_quartz_device.cpp | 2 +- core/fxge/cfx_fxgedevice.h | 13 +- core/fxge/cfx_renderdevice.h | 53 +++++---- core/fxge/dib/dib_int.h | 4 +- core/fxge/dib/fx_dib_composite.cpp | 42 +++---- core/fxge/dib/fx_dib_convert.cpp | 122 +++++++++---------- core/fxge/dib/fx_dib_engine.cpp | 15 +-- core/fxge/dib/fx_dib_engine_unittest.cpp | 8 +- core/fxge/dib/fx_dib_main.cpp | 170 ++++++++++++--------------- core/fxge/dib/fx_dib_transform.cpp | 38 +++--- core/fxge/fx_dib.h | 146 +++++++++++------------ core/fxge/fx_font.h | 10 +- core/fxge/ge/cfx_cliprgn.cpp | 43 ++++--- core/fxge/ge/cfx_cliprgn.h | 12 +- core/fxge/ge/cfx_facecache.cpp | 6 +- core/fxge/ge/cfx_renderdevice.cpp | 183 +++++++++++++++-------------- core/fxge/ge/fx_ge_text.cpp | 4 +- core/fxge/ifx_renderdevicedriver.cpp | 24 ++-- core/fxge/ifx_renderdevicedriver.h | 17 +-- core/fxge/skia/fx_skia_device.cpp | 151 ++++++++++++------------ core/fxge/skia/fx_skia_device.h | 30 ++--- core/fxge/skia/fx_skia_device_unittest.cpp | 2 +- core/fxge/win32/cfx_psrenderer.cpp | 21 ++-- core/fxge/win32/cfx_psrenderer.h | 6 +- core/fxge/win32/cfx_windowsdib.h | 24 ++-- core/fxge/win32/dwrite_int.h | 3 +- core/fxge/win32/fx_win32_device.cpp | 165 +++++++++++++------------- core/fxge/win32/fx_win32_dib.cpp | 52 ++++---- core/fxge/win32/fx_win32_dwrite.cpp | 27 +++-- core/fxge/win32/fx_win32_gdipext.cpp | 41 ++++--- core/fxge/win32/fx_win32_print.cpp | 69 +++++------ core/fxge/win32/win32_int.h | 39 +++--- 36 files changed, 873 insertions(+), 828 deletions(-) (limited to 'core/fxge') 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& 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& 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& pBitmap, int dest_left, int dest_top, int width, int height, - const CFX_DIBSource* pSrcBitmap, + const CFX_RetainPtr& 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& 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& pDevice, + const CFX_RetainPtr& 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 m_pOriDevice; + CFX_RetainPtr m_pClipMask; + CFX_RetainPtr 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& pDevice, + const CFX_RetainPtr& 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 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& pBitmap, + bool bRgbByteOrder, + const CFX_RetainPtr& 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(); 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 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& 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 pBack; + CFX_RetainPtr 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_AggDeviceDriver::GetBackDrop() { return m_pOriDevice; } -bool CFX_AggDeviceDriver::SetDIBits(const CFX_DIBSource* pBitmap, +bool CFX_AggDeviceDriver::SetDIBits(const CFX_RetainPtr& 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& 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& 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& pBitmap, bool bRgbByteOrder, - CFX_DIBitmap* pOriDevice, + const CFX_RetainPtr& 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& pOriDevice) { + auto pBitmap = pdfium::MakeRetain(); + if (!pBitmap->Create(width, height, format)) return false; - } + SetBitmap(pBitmap); SetDeviceDriver(pdfium::MakeUnique(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& pBitmap, bool bRgbByteOrder, - CFX_DIBitmap* pOriDevice, + const CFX_RetainPtr& 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& pBitmap, + int left, + int top) override; + CFX_RetainPtr GetBackDrop() override; + bool SetDIBits(const CFX_RetainPtr& 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& 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& 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 m_pBitmap; std::unique_ptr m_pClipRgn; std::vector> 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 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& 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 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& 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& pBitmap, bool bRgbByteOrder, - CFX_DIBitmap* pOriDevice, + const CFX_RetainPtr& pOriDevice, bool bGroupKnockout); bool Create(int width, int height, FXDIB_Format format, - CFX_DIBitmap* pOriDevice); + const CFX_RetainPtr& 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& pBitmap, + const CFX_RetainPtr& 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 GetBitmap() const { return m_pBitmap; } + void SetBitmap(const CFX_RetainPtr& pBitmap) { + m_pBitmap = pBitmap; + } + bool CreateCompatibleBitmap(const CFX_RetainPtr& 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 GetBackDrop(); + bool GetDIBits(const CFX_RetainPtr& pBitmap, int left, int top); + bool SetDIBits(const CFX_RetainPtr& pBitmap, + int left, + int top) { return SetDIBitsWithBlend(pBitmap, left, top, FXDIB_BLEND_NORMAL); } - bool SetDIBitsWithBlend(const CFX_DIBSource* pBitmap, + bool SetDIBitsWithBlend(const CFX_RetainPtr& pBitmap, int left, int top, int blend_type); - bool StretchDIBits(const CFX_DIBSource* pBitmap, + bool StretchDIBits(const CFX_RetainPtr& 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& pBitmap, + int left, + int top, + int dest_width, + int dest_height, + uint32_t flags, + int blend_type); + bool SetBitMask(const CFX_RetainPtr& pBitmap, int left, int top, uint32_t color); - bool StretchBitMask(const CFX_DIBSource* pBitmap, + bool StretchBitMask(const CFX_RetainPtr& 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& 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& 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& 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& pBitmap, + const CFX_RetainPtr& 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 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& 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 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& 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 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 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& 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 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& 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& 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& 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& 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& 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& 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& 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& 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& 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& 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& 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& 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& 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& 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& 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& 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& 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& 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& 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& pSrcBitmap, int src_left, int src_top, std::unique_ptr* p_pal) { @@ -783,16 +787,16 @@ bool ConvertBuffer(FXDIB_Format dest_format, } } -std::unique_ptr CFX_DIBSource::CloneConvert( - FXDIB_Format dest_format) const { +CFX_RetainPtr CFX_DIBSource::CloneConvert( + FXDIB_Format dest_format) { if (dest_format == GetFormat()) return Clone(nullptr); - std::unique_ptr pClone = pdfium::MakeUnique(); + auto pClone = pdfium::MakeRetain(); if (!pClone->Create(m_Width, m_Height, dest_format)) return nullptr; - CFX_MaybeOwned pSrcAlpha; + CFX_RetainPtr pSrcAlpha; if (HasAlpha()) { if (GetFormat() == FXDIB_Argb) pSrcAlpha = CloneAlphaMask(); @@ -805,19 +809,19 @@ std::unique_ptr 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 holder(this); std::unique_ptr 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 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 holder(this); std::unique_ptr 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& 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& 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("Height", 12500); std::unique_ptr stream = pdfium::MakeUnique(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(); + 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& 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&& 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_DIBSource::Clone(const FX_RECT* pClip) const { +CFX_RetainPtr 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(); + auto pNewBitmap = pdfium::MakeRetain(); 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(); 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& 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& 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_DIBSource::CloneAlphaMask( +CFX_RetainPtr 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_DIBSource::CloneAlphaMask( if (rect.IsEmpty()) return nullptr; } - auto pMask = pdfium::MakeUnique(); + auto pMask = pdfium::MakeRetain(); if (!pMask->Create(rect.Width(), rect.Height(), FXDIB_8bppMask)) return nullptr; @@ -630,7 +622,7 @@ std::unique_ptr CFX_DIBSource::CloneAlphaMask( return pMask; } -bool CFX_DIBSource::SetAlphaMask(const CFX_DIBSource* pAlphaMask, +bool CFX_DIBSource::SetAlphaMask(const CFX_RetainPtr& 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& pSrcBitmap, FXDIB_Channel srcChannel) { if (!m_pBuffer) return false; - CFX_MaybeOwned pSrcClone(pSrcBitmap); + CFX_RetainPtr 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 pAlphaMask(pSrcClone->m_pAlphaMask); + CFX_RetainPtr 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 pSrcMatched = + CFX_RetainPtr pSrcMatched = pSrcClone->StretchTo(m_Width, m_Height); if (!pSrcMatched) return false; pSrcClone = std::move(pSrcMatched); } - CFX_DIBitmap* pDst = this; + CFX_RetainPtr 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& 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 pSrcClone( - static_cast(pSrcBitmap)); + CFX_RetainPtr pSrcClone = pSrcBitmap.As(); 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(m_pPalette.get()[i] >> 16); @@ -897,11 +889,10 @@ bool CFX_DIBitmap::GetGrayData(void* pIccTransform) { int b = static_cast(m_pPalette.get()[i]); gray[i] = static_cast(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(); + 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(m_pPalette.get()[i] >> 16); @@ -928,11 +918,10 @@ bool CFX_DIBitmap::GetGrayData(void* pIccTransform) { int b = static_cast(m_pPalette.get()[i]); gray[i] = static_cast(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(); + 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(); + 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(); + 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_DIBSource::FlipImage(bool bXFlip, - bool bYFlip) const { - auto pFlipped = pdfium::MakeUnique(); +CFX_RetainPtr CFX_DIBSource::FlipImage(bool bXFlip, + bool bYFlip) const { + auto pFlipped = pdfium::MakeRetain(); if (!pFlipped->Create(m_Width, m_Height, GetFormat())) return nullptr; @@ -1414,12 +1398,12 @@ std::unique_ptr CFX_DIBSource::FlipImage(bool bXFlip, return pFlipped; } -CFX_DIBExtractor::CFX_DIBExtractor(const CFX_DIBSource* pSrc) { +CFX_DIBExtractor::CFX_DIBExtractor(const CFX_RetainPtr& pSrc) { if (pSrc->GetBuffer()) { - m_pBitmap = pdfium::MakeUnique(); + m_pBitmap = pdfium::MakeRetain(); 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& 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& pDevice, const CFX_ClipRgn* pClipRgn, - const CFX_DIBSource* pSource, + const CFX_RetainPtr& 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 pBitmap(m_pTransformer->DetachBitmap()); + CFX_RetainPtr 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_BitmapStorer::Detach() { +CFX_RetainPtr CFX_BitmapStorer::Detach() { return std::move(m_pBitmap); } -void CFX_BitmapStorer::Replace(std::unique_ptr pBitmap) { +void CFX_BitmapStorer::Replace(CFX_RetainPtr&& 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(); - if (!m_pBitmap->Create(width, height, src_format)) { - m_pBitmap.reset(); + auto pBitmap = pdfium::MakeRetain(); + 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& 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_DIBSource::SwapXY( +CFX_RetainPtr CFX_DIBSource::SwapXY( bool bXFlip, bool bYFlip, const FX_RECT* pDestClip) const { @@ -189,7 +189,7 @@ std::unique_ptr CFX_DIBSource::SwapXY( if (dest_clip.IsEmpty()) return nullptr; - auto pTransBitmap = pdfium::MakeUnique(); + auto pTransBitmap = pdfium::MakeRetain(); 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_DIBSource::TransformTo( +CFX_RetainPtr 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 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_DIBSource::TransformTo( return transformer.DetachBitmap(); } -std::unique_ptr CFX_DIBSource::StretchTo( - int dest_width, - int dest_height, - uint32_t flags, - const FX_RECT* pClip) const { +CFX_RetainPtr CFX_DIBSource::StretchTo(int dest_width, + int dest_height, + uint32_t flags, + const FX_RECT* pClip) { + CFX_RetainPtr 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_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_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& 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 pTransformed(new CFX_DIBitmap); + auto pTransformed = pdfium::MakeRetain(); 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_ImageTransformer::DetachBitmap() { +CFX_RetainPtr 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 #include -#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& pSrcBitmap, int src_left, int src_top, std::unique_ptr* 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 Clone(const FX_RECT* pClip = nullptr) const; - std::unique_ptr CloneConvert(FXDIB_Format format) const; - std::unique_ptr StretchTo(int dest_width, - int dest_height, + CFX_RetainPtr Clone(const FX_RECT* pClip = nullptr) const; + CFX_RetainPtr CloneConvert(FXDIB_Format format); + CFX_RetainPtr StretchTo(int dest_width, + int dest_height, + uint32_t flags = 0, + const FX_RECT* pClip = nullptr); + CFX_RetainPtr TransformTo(const CFX_Matrix* pMatrix, + int& left, + int& top, uint32_t flags = 0, - const FX_RECT* pClip = nullptr) const; - std::unique_ptr TransformTo( - const CFX_Matrix* pMatrix, - int& left, - int& top, - uint32_t flags = 0, - const FX_RECT* pClip = nullptr) const; - std::unique_ptr SwapXY(bool bXFlip, - bool bYFlip, - const FX_RECT* pClip = nullptr) const; - std::unique_ptr FlipImage(bool bXFlip, bool bYFlip) const; + const FX_RECT* pClip = nullptr); + CFX_RetainPtr SwapXY(bool bXFlip, + bool bYFlip, + const FX_RECT* pClip = nullptr) const; + CFX_RetainPtr FlipImage(bool bXFlip, bool bYFlip) const; - std::unique_ptr CloneAlphaMask( + CFX_RetainPtr CloneAlphaMask( const FX_RECT* pClip = nullptr) const; // Copies into internally-owned mask. - bool SetAlphaMask(const CFX_DIBSource* pAlphaMask, + bool SetAlphaMask(const CFX_RetainPtr& 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 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 + friend CFX_RetainPtr 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& 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&& 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& 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& pAlphaMask); bool TransferBitmap(int dest_left, int dest_top, int width, int height, - const CFX_DIBSource* pSrcBitmap, + const CFX_RetainPtr& 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& 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& 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& 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& pSrc); ~CFX_DIBExtractor(); - CFX_DIBitmap* GetBitmap() { return m_pBitmap.get(); } + CFX_RetainPtr GetBitmap() { return m_pBitmap; } private: - std::unique_ptr m_pBitmap; + CFX_RetainPtr m_pBitmap; }; -typedef CFX_SharedCopyOnWrite CFX_DIBitmapRef; - class CFX_FilteredDIB : public CFX_DIBSource { public: - CFX_FilteredDIB(); - ~CFX_FilteredDIB() override; + template + friend CFX_RetainPtr 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* 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& 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 m_pSrc; mutable std::vector 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& 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 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 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 Detach(); - void Replace(std::unique_ptr pBitmap); + CFX_RetainPtr GetBitmap() { return m_pBitmap; } + CFX_RetainPtr Detach(); + void Replace(CFX_RetainPtr&& pBitmap); private: - std::unique_ptr m_pBitmap; + CFX_RetainPtr m_pBitmap; }; class CFX_ImageStretcher { public: CFX_ImageStretcher(IFX_ScanlineComposer* pDest, - const CFX_DIBSource* pSource, + const CFX_RetainPtr& 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 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 m_pSource; std::unique_ptr m_pStretchEngine; std::unique_ptr m_pScanline; std::unique_ptr m_pMaskScanline; @@ -632,7 +634,7 @@ class CFX_ImageStretcher { class CFX_ImageTransformer { public: - CFX_ImageTransformer(const CFX_DIBSource* pSrc, + CFX_ImageTransformer(const CFX_RetainPtr& 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 DetachBitmap(); + CFX_RetainPtr DetachBitmap(); private: - const CFX_DIBSource* const m_pSrc; + const CFX_RetainPtr 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& pDevice, const CFX_ClipRgn* pClipRgn, - const CFX_DIBSource* pSource, + const CFX_RetainPtr& 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 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 m_pBitmap; }; +inline CFX_GlyphBitmap::CFX_GlyphBitmap() + : m_pBitmap(pdfium::MakeRetain()) {} + +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 + 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& 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(); + 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& 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(); 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 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& 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& Mask); ClipType m_Type; FX_RECT m_Box; - CFX_DIBitmapRef m_Mask; + CFX_RetainPtr 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& bitmap, + const CFX_RetainPtr& 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& 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(); + auto Backdrop = pdfium::MakeRetain(); + 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(); + 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& 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_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& 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(); + 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& 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& 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& 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& 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& 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& pBitmap, + const CFX_RetainPtr& 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(); + 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 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(); 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 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& 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& 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& pBitmap, + int left, + int top) { return false; } -CFX_DIBitmap* IFX_RenderDeviceDriver::GetBackDrop() { - return nullptr; +CFX_RetainPtr IFX_RenderDeviceDriver::GetBackDrop() { + return CFX_RetainPtr(); } 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& pBitmap, + const CFX_RetainPtr& 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& pBitmap, + int left, + int top); + virtual CFX_RetainPtr GetBackDrop(); + virtual bool SetDIBits(const CFX_RetainPtr& 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& 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& 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& pBitmap, + const CFX_RetainPtr& 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& pBitmap, int dest_left, int dest_top, int width, int height, - const CFX_DIBSource* pSrcBitmap, + const CFX_RetainPtr& 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& bitmap, + const CFX_RetainPtr& 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& pSource, std::unique_ptr& dst8Storage, std::unique_ptr& 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& pBitmap, + bool bRgbByteOrder, + const CFX_RetainPtr& 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(); 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(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& 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 pBack; + CFX_RetainPtr 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_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& 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& 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& 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& 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& pSource, + const CFX_RetainPtr& 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& pBitmap, + const CFX_RetainPtr& 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& pBitmap, bool bRgbByteOrder, - CFX_DIBitmap* pOriDevice, + const CFX_RetainPtr& 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& pOriDevice) { + auto pBitmap = pdfium::MakeRetain(); 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& pBitmap, + const CFX_RetainPtr& pMask, + int left, + int top, + int bitmap_alpha, + int blend_type) { CFX_SkiaDeviceDriver* skDriver = static_cast(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& m_pOriDevice; FX_RECT m_ClipBox; - const CFX_DIBitmap* m_pClipMask; - CFX_DIBitmap* m_pDevice; + const CFX_RetainPtr& m_pClipMask; + const CFX_RetainPtr& 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 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& pDevice, + const CFX_RetainPtr& 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& pBitmap, bool bRgbByteOrder, - CFX_DIBitmap* pOriDevice, + const CFX_RetainPtr& 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& pBitmap, + int left, + int top) override; - CFX_DIBitmap* GetBackDrop() override; + CFX_RetainPtr GetBackDrop() override; - bool SetDIBits(const CFX_DIBSource* pBitmap, + bool SetDIBits(const CFX_RetainPtr& 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& pBitmap, + const CFX_RetainPtr& 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& 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& 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& pBitmap, + const CFX_RetainPtr& 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& 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 m_pBitmap; + CFX_RetainPtr m_pOriDevice; SkCanvas* m_pCanvas; SkPictureRecorder* const m_pRecorder; std::unique_ptr 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 pBitmap(CFXBitmapFromFPDFBitmap(bitmap)); geDevice.Attach(pBitmap, false, nullptr, false); CFX_SkiaDeviceDriver* driver = static_cast(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& 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& 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& 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 pConverted(source_extractor.GetBitmap()); - if (!pConverted.Get()) + CFX_RetainPtr 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& pBitmap, uint32_t color, int dest_left, int dest_top); - bool StretchDIBits(const CFX_DIBSource* pBitmap, + bool StretchDIBits(const CFX_RetainPtr& 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& 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 #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 + friend CFX_RetainPtr 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& pBitmap); + static HBITMAP GetDDBitmap(const CFX_RetainPtr& pBitmap, + HDC hDC); + + static CFX_RetainPtr LoadFromBuf(BITMAPINFO* pbmi, void* pData); + static CFX_RetainPtr LoadFromFile(const wchar_t* filename); + static CFX_RetainPtr LoadFromFile(const char* filename); + static CFX_RetainPtr 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& 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& pBitmap1, + const FX_RECT* pSrcRect, + int left, + int top) { if (m_DeviceClass == FXDC_PRINTER) { - std::unique_ptr pBitmap = pBitmap1->FlipImage(false, true); + CFX_RetainPtr 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 pBitmap(pBitmap1); + CFX_RetainPtr 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& pBitmap1, + int dest_left, + int dest_top, + int dest_width, + int dest_height, + uint32_t flags) { + CFX_RetainPtr 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 pToStrechBitmap(pBitmap); + CFX_RetainPtr 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& pBitmap1, + int dest_left, + int dest_top, + int dest_width, + int dest_height, + uint32_t bitmap_color, + uint32_t flags) { + CFX_RetainPtr 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& 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(); + 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& 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(); + 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(); + 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 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& 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 pStretched( - pSource->StretchTo(dest_width, dest_height, render_flags, &bitmap_clip)); + CFX_RetainPtr 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& 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 pStretched( + CFX_RetainPtr 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(); + 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 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 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& 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& 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 _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(); 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_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& 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_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(); 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_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_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(); 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& pBitmap, IDWriteBitmapRenderTarget* bitmapRenderTarget, IDWriteRenderingParams* renderingParams); ~CDwGdiTextRenderer(); @@ -118,7 +118,7 @@ class CDwGdiTextRenderer { const COLORREF& textColor); private: - CFX_DIBitmap* pBitmap_; + CFX_RetainPtr 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& 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& 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(); + 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 StretchMonoToGray( +static CFX_RetainPtr StretchMonoToGray( int dest_width, int dest_height, - const CFX_DIBitmap* pSource, + const CFX_RetainPtr& pSource, FX_RECT* pClipRect) { bool bFlipX = dest_width < 0; if (bFlipX) @@ -477,7 +477,7 @@ static std::unique_ptr StretchMonoToGray( int result_width = pClipRect->Width(); int result_height = pClipRect->Height(); int result_pitch = (result_width + 3) / 4 * 4; - auto pStretched = pdfium::MakeUnique(); + auto pStretched = pdfium::MakeRetain(); if (!pStretched->Create(result_width, result_height, FXDIB_8bppRgb)) return nullptr; @@ -518,7 +518,7 @@ static std::unique_ptr StretchMonoToGray( static void OutputImageMask(GpGraphics* pGraphics, BOOL bMonoDevice, - const CFX_DIBitmap* pBitmap, + const CFX_RetainPtr& 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 pStretched; + CFX_RetainPtr 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& 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 pCloned = pBitmap->Clone(pSrcRect); + CFX_RetainPtr 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& 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& 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& 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 _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi, + LPVOID pData, + bool bAlpha); + +CFX_RetainPtr 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 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& 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 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& 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 pFlipped = + CFX_RetainPtr 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 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 pFlipped = + CFX_RetainPtr 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 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& 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 pTransformed = + CFX_RetainPtr 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& 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& 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& 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& 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& 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& 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 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& pBitmap, const FX_RECT* pSrcRect, int left, int top); - bool GDI_StretchDIBits(CFX_DIBitmap* pBitmap, + bool GDI_StretchDIBits(const CFX_RetainPtr& 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& 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& pBitmap, + int left, + int top) override; + bool SetDIBits(const CFX_RetainPtr& 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& 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& 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& 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& 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& 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& 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& 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& 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& pBitmap, int bitmap_alpha, uint32_t color, const CFX_Matrix* pMatrix, -- cgit v1.2.3