diff options
author | dsinclair <dsinclair@chromium.org> | 2017-03-28 15:47:47 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-03-28 15:48:01 +0000 |
commit | 31b08d4cdaa17d7a03f35e087096a77036af98ec (patch) | |
tree | 40234b81f2972c857a33a86cb4b59868e56bb86b /core/fxge | |
parent | a3e9bf66c3483db926602aa62b0bd1ff8d1357a1 (diff) | |
download | pdfium-31b08d4cdaa17d7a03f35e087096a77036af98ec.tar.xz |
Revert "Refcount all CFX_DIBSources (and subclasses) all the time."
This reverts commit 0004f29bf6ee3c6060a272c79f14993e92e053c7.
Reason for revert: Breaks build with skia_paths enabled (which will break the chrome roll).
../../third_party/pdfium/core/fxge/skia/fx_skia_device.cpp:1858:38: error: no member named 'get' in 'CFX_RetainPtr<CFX_DIBitmap>'
../../third_party/pdfium/core/fxge/skia/fx_skia_device.cpp:1861:42: error: no member named 'get' in 'CFX_RetainPtr<CFX_DIBitmap>'
../../third_party/pdfium/core/fxge/skia/fx_skia_device.cpp:2987:15: error: no viable overloaded '='
../../third_party/pdfium/core/fxge/skia/fx_skia_device.cpp:2991:18: error: no viable overloaded '='
../../third_party/pdfium/core/fxge/skia/fx_skia_device.cpp:2999:17: error: no viable overloaded '='
../../third_party/pdfium/core/fxge/skia/fx_skia_device.cpp:3001:43: error: no member named 'GetObject' in 'CFX_RetainPtr<CFX_DIBitmap>'
Original change's description:
> Refcount all CFX_DIBSources (and subclasses) all the time.
>
> There are currently several ownership models for these objects,
> including ad-hoc logic for sharing and deletion, and the
> now-redundant CFX_DIBitmapRef externally-counted handle to the DIBs.
>
> Replace them all with the internal refcount scheme.
>
> Change-Id: I2db399dfc19219eda384f94cc989353b78ce2872
> Reviewed-on: https://pdfium-review.googlesource.com/3166
> Reviewed-by: dsinclair <dsinclair@chromium.org>
> Commit-Queue: dsinclair <dsinclair@chromium.org>
>
TBR=thestig@chromium.org,tsepez@chromium.org,dsinclair@chromium.org,pdfium-reviews@googlegroups.com
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
Change-Id: I678b1fbc5e666cf7a19372ebaff3270fb115ba5e
Reviewed-on: https://pdfium-review.googlesource.com/3243
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fxge')
36 files changed, 828 insertions, 873 deletions
diff --git a/core/fxge/agg/fx_agg_driver.cpp b/core/fxge/agg/fx_agg_driver.cpp index ad7d2c4517..b435c032bc 100644 --- a/core/fxge/agg/fx_agg_driver.cpp +++ b/core/fxge/agg/fx_agg_driver.cpp @@ -35,10 +35,7 @@ CFX_PointF HardClip(const CFX_PointF& pos) { pdfium::clamp(pos.y, -kMaxPos, kMaxPos)); } -void RgbByteOrderSetPixel(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, - int x, - int y, - uint32_t argb) { +void RgbByteOrderSetPixel(CFX_DIBitmap* pBitmap, int x, int y, uint32_t argb) { if (x < 0 || x >= pBitmap->GetWidth() || y < 0 || y >= pBitmap->GetHeight()) return; @@ -55,7 +52,7 @@ void RgbByteOrderSetPixel(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, pos[2] = (FXARGB_B(argb) * alpha + pos[2] * (255 - alpha)) / 255; } -void RgbByteOrderCompositeRect(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, +void RgbByteOrderCompositeRect(CFX_DIBitmap* pBitmap, int left, int top, int width, @@ -130,12 +127,12 @@ void RgbByteOrderCompositeRect(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, } } -void RgbByteOrderTransferBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, +void RgbByteOrderTransferBitmap(CFX_DIBitmap* pBitmap, int dest_left, int dest_top, int width, int height, - const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap, + const CFX_DIBSource* pSrcBitmap, int src_left, int src_top) { if (!pBitmap) @@ -235,7 +232,7 @@ FX_ARGB DefaultCMYK2ARGB(FX_CMYK cmyk, uint8_t alpha) { return ArgbEncode(alpha, r, g, b); } -bool DibSetPixel(const CFX_RetainPtr<CFX_DIBitmap>& pDevice, +bool DibSetPixel(CFX_DIBitmap* pDevice, int x, int y, uint32_t color, @@ -401,8 +398,8 @@ class CFX_Renderer { uint8_t* clip_scan, uint8_t* dest_extra_alpha_scan); - bool Init(const CFX_RetainPtr<CFX_DIBitmap>& pDevice, - const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice, + bool Init(CFX_DIBitmap* pDevice, + CFX_DIBitmap* pOriDevice, const CFX_ClipRgn* pClipRgn, uint32_t color, bool bFullCover, @@ -459,10 +456,10 @@ class CFX_Renderer { uint32_t m_Color; bool m_bFullCover; bool m_bRgbByteOrder; + CFX_DIBitmap* m_pOriDevice; FX_RECT m_ClipBox; - CFX_RetainPtr<CFX_DIBitmap> m_pOriDevice; - CFX_RetainPtr<CFX_DIBitmap> m_pClipMask; - CFX_RetainPtr<CFX_DIBitmap> m_pDevice; + const CFX_DIBitmap* m_pClipMask; + CFX_DIBitmap* m_pDevice; const CFX_ClipRgn* m_pClipRgn; }; @@ -902,8 +899,8 @@ void CFX_Renderer::CompositeSpanCMYK(uint8_t* dest_scan, } } -bool CFX_Renderer::Init(const CFX_RetainPtr<CFX_DIBitmap>& pDevice, - const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice, +bool CFX_Renderer::Init(CFX_DIBitmap* pDevice, + CFX_DIBitmap* pOriDevice, const CFX_ClipRgn* pClipRgn, uint32_t color, bool bFullCover, @@ -924,7 +921,7 @@ bool CFX_Renderer::Init(const CFX_RetainPtr<CFX_DIBitmap>& pDevice, } m_pClipMask = nullptr; if (m_pClipRgn && m_pClipRgn->GetType() == CFX_ClipRgn::MaskF) - m_pClipMask = m_pClipRgn->GetMask(); + m_pClipMask = m_pClipRgn->GetMask().GetObject(); m_bFullCover = bFullCover; bool bObjectCMYK = !!FXGETFLAG_COLORTYPE(alpha_flag); bool bDeviceCMYK = pDevice->IsCmykImage(); @@ -1041,7 +1038,7 @@ void CFX_Renderer::render(const Scanline& sl) { uint8_t* dest_scan = m_pDevice->GetBuffer() + m_pDevice->GetPitch() * y; uint8_t* dest_scan_extra_alpha = nullptr; - CFX_RetainPtr<CFX_DIBitmap> pAlphaMask = m_pDevice->m_pAlphaMask; + CFX_DIBitmap* pAlphaMask = m_pDevice->m_pAlphaMask; if (pAlphaMask) { dest_scan_extra_alpha = pAlphaMask->GetBuffer() + pAlphaMask->GetPitch() * y; @@ -1202,11 +1199,10 @@ void CAgg_PathData::BuildPath(const CFX_PathData* pPathData, } } -CFX_AggDeviceDriver::CFX_AggDeviceDriver( - const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, - bool bRgbByteOrder, - const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice, - bool bGroupKnockout) +CFX_AggDeviceDriver::CFX_AggDeviceDriver(CFX_DIBitmap* pBitmap, + bool bRgbByteOrder, + CFX_DIBitmap* pOriDevice, + bool bGroupKnockout) : m_pBitmap(pBitmap), #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ m_pPlatformGraphics(nullptr), @@ -1300,7 +1296,8 @@ void CFX_AggDeviceDriver::SetClipMask(agg::rasterizer_scanline_aa& rasterizer) { FX_RECT path_rect(rasterizer.min_x(), rasterizer.min_y(), rasterizer.max_x() + 1, rasterizer.max_y() + 1); path_rect.Intersect(m_pClipRgn->GetBox()); - auto pThisLayer = pdfium::MakeRetain<CFX_DIBitmap>(); + CFX_DIBitmapRef mask; + CFX_DIBitmap* pThisLayer = mask.Emplace(); pThisLayer->Create(path_rect.Width(), path_rect.Height(), FXDIB_8bppMask); pThisLayer->Clear(0); agg::rendering_buffer raw_buf(pThisLayer->GetBuffer(), pThisLayer->GetWidth(), @@ -1314,7 +1311,7 @@ void CFX_AggDeviceDriver::SetClipMask(agg::rasterizer_scanline_aa& rasterizer) { agg::scanline_u8 scanline; agg::render_scanlines(rasterizer, scanline, final_render, (m_FillFlags & FXFILL_NOPATHSMOOTH) != 0); - m_pClipRgn->IntersectMaskF(path_rect.left, path_rect.top, pThisLayer); + m_pClipRgn->IntersectMaskF(path_rect.left, path_rect.top, mask); } bool CFX_AggDeviceDriver::SetClip_PathFill(const CFX_PathData* pPathData, @@ -1384,7 +1381,7 @@ bool CFX_AggDeviceDriver::RenderRasterizer( bool bGroupKnockout, int alpha_flag, void* pIccTransform) { - CFX_RetainPtr<CFX_DIBitmap> pt = bGroupKnockout ? m_pOriDevice : nullptr; + CFX_DIBitmap* pt = bGroupKnockout ? m_pOriDevice : nullptr; CFX_Renderer render; if (!render.Init(m_pBitmap, pt, m_pClipRgn.get(), color, bFullCover, m_bRgbByteOrder, alpha_flag, pIccTransform)) { @@ -1495,8 +1492,8 @@ bool CFX_AggDeviceDriver::SetPixel(int x, int y, uint32_t color) { if (m_pClipRgn->GetType() != CFX_ClipRgn::MaskF) return true; - int new_alpha = - FXARGB_A(color) * m_pClipRgn->GetMask()->GetScanline(y)[x] / 255; + const CFX_DIBitmap* pMask = m_pClipRgn->GetMask().GetObject(); + int new_alpha = FXARGB_A(color) * pMask->GetScanline(y)[x] / 255; color = (color & 0xffffff) | (new_alpha << 24); if (m_bRgbByteOrder) { RgbByteOrderSetPixel(m_pBitmap, x, y, color); @@ -1533,11 +1530,11 @@ bool CFX_AggDeviceDriver::FillRectWithBlend(const FX_RECT* pRect, } return true; } - m_pBitmap->CompositeMask(draw_rect.left, draw_rect.top, draw_rect.Width(), - draw_rect.Height(), m_pClipRgn->GetMask(), - fill_color, draw_rect.left - clip_rect.left, - draw_rect.top - clip_rect.top, FXDIB_BLEND_NORMAL, - nullptr, m_bRgbByteOrder, 0, nullptr); + m_pBitmap->CompositeMask( + draw_rect.left, draw_rect.top, draw_rect.Width(), draw_rect.Height(), + m_pClipRgn->GetMask().GetObject(), fill_color, + draw_rect.left - clip_rect.left, draw_rect.top - clip_rect.top, + FXDIB_BLEND_NORMAL, nullptr, m_bRgbByteOrder, 0, nullptr); return true; } @@ -1552,15 +1549,13 @@ bool CFX_AggDeviceDriver::GetClipBox(FX_RECT* pRect) { return true; } -bool CFX_AggDeviceDriver::GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, - int left, - int top) { +bool CFX_AggDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) { if (!m_pBitmap || !m_pBitmap->GetBuffer()) return true; FX_RECT rect(left, top, left + pBitmap->GetWidth(), top + pBitmap->GetHeight()); - CFX_RetainPtr<CFX_DIBitmap> pBack; + std::unique_ptr<CFX_DIBitmap> pBack; if (m_pOriDevice) { pBack = m_pOriDevice->Clone(&rect); if (!pBack) @@ -1578,18 +1573,18 @@ bool CFX_AggDeviceDriver::GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, top = std::min(top, 0); if (m_bRgbByteOrder) { RgbByteOrderTransferBitmap(pBitmap, 0, 0, rect.Width(), rect.Height(), - pBack, left, top); + pBack.get(), left, top); return true; } - return pBitmap->TransferBitmap(0, 0, rect.Width(), rect.Height(), pBack, left, - top); + return pBitmap->TransferBitmap(0, 0, rect.Width(), rect.Height(), pBack.get(), + left, top); } -CFX_RetainPtr<CFX_DIBitmap> CFX_AggDeviceDriver::GetBackDrop() { +CFX_DIBitmap* CFX_AggDeviceDriver::GetBackDrop() { return m_pOriDevice; } -bool CFX_AggDeviceDriver::SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, +bool CFX_AggDeviceDriver::SetDIBits(const CFX_DIBSource* pBitmap, uint32_t argb, const FX_RECT* pSrcRect, int left, @@ -1609,16 +1604,15 @@ bool CFX_AggDeviceDriver::SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, pSrcRect->top, blend_type, m_pClipRgn.get(), m_bRgbByteOrder, nullptr); } -bool CFX_AggDeviceDriver::StretchDIBits( - const CFX_RetainPtr<CFX_DIBSource>& pSource, - uint32_t argb, - int dest_left, - int dest_top, - int dest_width, - int dest_height, - const FX_RECT* pClipRect, - uint32_t flags, - int blend_type) { +bool CFX_AggDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource, + uint32_t argb, + int dest_left, + int dest_top, + int dest_width, + int dest_height, + const FX_RECT* pClipRect, + uint32_t flags, + int blend_type) { if (!m_pBitmap->GetBuffer()) return true; @@ -1643,14 +1637,13 @@ bool CFX_AggDeviceDriver::StretchDIBits( return true; } -bool CFX_AggDeviceDriver::StartDIBits( - const CFX_RetainPtr<CFX_DIBSource>& pSource, - int bitmap_alpha, - uint32_t argb, - const CFX_Matrix* pMatrix, - uint32_t render_flags, - void*& handle, - int blend_type) { +bool CFX_AggDeviceDriver::StartDIBits(const CFX_DIBSource* pSource, + int bitmap_alpha, + uint32_t argb, + const CFX_Matrix* pMatrix, + uint32_t render_flags, + void*& handle, + int blend_type) { if (!m_pBitmap->GetBuffer()) return true; @@ -1675,13 +1668,13 @@ void CFX_AggDeviceDriver::CancelDIBits(void* pHandle) { } #ifndef _SKIA_SUPPORT_ -CFX_FxgeDevice::CFX_FxgeDevice() {} - -CFX_FxgeDevice::~CFX_FxgeDevice() {} +CFX_FxgeDevice::CFX_FxgeDevice() { + m_bOwnedBitmap = false; +} -bool CFX_FxgeDevice::Attach(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, +bool CFX_FxgeDevice::Attach(CFX_DIBitmap* pBitmap, bool bRgbByteOrder, - const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice, + CFX_DIBitmap* pOriDevice, bool bGroupKnockout) { if (!pBitmap) return false; @@ -1695,15 +1688,21 @@ bool CFX_FxgeDevice::Attach(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, bool CFX_FxgeDevice::Create(int width, int height, FXDIB_Format format, - const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice) { - auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>(); - if (!pBitmap->Create(width, height, format)) + CFX_DIBitmap* pOriDevice) { + m_bOwnedBitmap = true; + CFX_DIBitmap* pBitmap = new CFX_DIBitmap; + if (!pBitmap->Create(width, height, format)) { + delete pBitmap; return false; - + } SetBitmap(pBitmap); SetDeviceDriver(pdfium::MakeUnique<CFX_AggDeviceDriver>(pBitmap, false, pOriDevice, false)); return true; } +CFX_FxgeDevice::~CFX_FxgeDevice() { + if (m_bOwnedBitmap) + delete GetBitmap(); +} #endif diff --git a/core/fxge/agg/fx_agg_driver.h b/core/fxge/agg/fx_agg_driver.h index 723ed6d98a..7b4c7209e8 100644 --- a/core/fxge/agg/fx_agg_driver.h +++ b/core/fxge/agg/fx_agg_driver.h @@ -32,9 +32,9 @@ class CAgg_PathData { class CFX_AggDeviceDriver : public IFX_RenderDeviceDriver { public: - CFX_AggDeviceDriver(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, + CFX_AggDeviceDriver(CFX_DIBitmap* pBitmap, bool bRgbByteOrder, - const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice, + CFX_DIBitmap* pOriDevice, bool bGroupKnockout); ~CFX_AggDeviceDriver() override; @@ -63,17 +63,15 @@ class CFX_AggDeviceDriver : public IFX_RenderDeviceDriver { uint32_t fill_color, int blend_type) override; bool GetClipBox(FX_RECT* pRect) override; - bool GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, - int left, - int top) override; - CFX_RetainPtr<CFX_DIBitmap> GetBackDrop() override; - bool SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, + bool GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) override; + CFX_DIBitmap* GetBackDrop() override; + bool SetDIBits(const CFX_DIBSource* pBitmap, uint32_t color, const FX_RECT* pSrcRect, int left, int top, int blend_type) override; - bool StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, + bool StretchDIBits(const CFX_DIBSource* pBitmap, uint32_t color, int dest_left, int dest_top, @@ -82,7 +80,7 @@ class CFX_AggDeviceDriver : public IFX_RenderDeviceDriver { const FX_RECT* pClipRect, uint32_t flags, int blend_type) override; - bool StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, + bool StartDIBits(const CFX_DIBSource* pBitmap, int bitmap_alpha, uint32_t color, const CFX_Matrix* pMatrix, @@ -111,7 +109,7 @@ class CFX_AggDeviceDriver : public IFX_RenderDeviceDriver { virtual uint8_t* GetBuffer() const; private: - CFX_RetainPtr<CFX_DIBitmap> m_pBitmap; + CFX_DIBitmap* m_pBitmap; std::unique_ptr<CFX_ClipRgn> m_pClipRgn; std::vector<std::unique_ptr<CFX_ClipRgn>> m_StateStack; #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ @@ -119,7 +117,7 @@ class CFX_AggDeviceDriver : public IFX_RenderDeviceDriver { #endif int m_FillFlags; bool m_bRgbByteOrder; - CFX_RetainPtr<CFX_DIBitmap> m_pOriDevice; + CFX_DIBitmap* m_pOriDevice; bool m_bGroupKnockout; }; diff --git a/core/fxge/apple/apple_int.h b/core/fxge/apple/apple_int.h index f1b9fcf2e8..2a4029bd38 100644 --- a/core/fxge/apple/apple_int.h +++ b/core/fxge/apple/apple_int.h @@ -19,7 +19,7 @@ class CQuartz2D { public: - void* createGraphics(const CFX_RetainPtr<CFX_DIBitmap>& bitmap); + void* createGraphics(CFX_DIBitmap* bitmap); void destroyGraphics(void* graphics); void* CreateFont(const uint8_t* pFontData, uint32_t dwFontSize); diff --git a/core/fxge/apple/fx_apple_platform.cpp b/core/fxge/apple/fx_apple_platform.cpp index 3f7916f07d..20e86ed483 100644 --- a/core/fxge/apple/fx_apple_platform.cpp +++ b/core/fxge/apple/fx_apple_platform.cpp @@ -129,7 +129,7 @@ bool CFX_AggDeviceDriver::DrawDeviceText(int nChars, rect_cg = CGRectMake(m_pClipRgn->GetBox().left, m_pClipRgn->GetBox().top, m_pClipRgn->GetBox().Width(), m_pClipRgn->GetBox().Height()); - CFX_RetainPtr<CFX_DIBitmap> pClipMask = m_pClipRgn->GetMask(); + const CFX_DIBitmap* pClipMask = m_pClipRgn->GetMask().GetObject(); if (pClipMask) { CGDataProviderRef pClipMaskDataProvider = CGDataProviderCreateWithData( nullptr, pClipMask->GetBuffer(), diff --git a/core/fxge/apple/fx_quartz_device.cpp b/core/fxge/apple/fx_quartz_device.cpp index ded8036047..dbb121065d 100644 --- a/core/fxge/apple/fx_quartz_device.cpp +++ b/core/fxge/apple/fx_quartz_device.cpp @@ -25,7 +25,7 @@ #error Expected CGFLOAT_IS_DOUBLE to be defined by CoreGraphics headers #endif -void* CQuartz2D::createGraphics(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap) { +void* CQuartz2D::createGraphics(CFX_DIBitmap* pBitmap) { if (!pBitmap) return nullptr; CGBitmapInfo bmpInfo = kCGBitmapByteOrder32Little; diff --git a/core/fxge/cfx_fxgedevice.h b/core/fxge/cfx_fxgedevice.h index 4e8a7f4f55..8358e43666 100644 --- a/core/fxge/cfx_fxgedevice.h +++ b/core/fxge/cfx_fxgedevice.h @@ -17,27 +17,30 @@ class CFX_FxgeDevice : public CFX_RenderDevice { CFX_FxgeDevice(); ~CFX_FxgeDevice() override; - bool Attach(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, + bool Attach(CFX_DIBitmap* pBitmap, bool bRgbByteOrder, - const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice, + CFX_DIBitmap* pOriDevice, bool bGroupKnockout); bool Create(int width, int height, FXDIB_Format format, - const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice); + CFX_DIBitmap* pOriDevice); #ifdef _SKIA_SUPPORT_ bool AttachRecorder(SkPictureRecorder* recorder); void Clear(uint32_t color); SkPictureRecorder* CreateRecorder(int size_x, int size_y); void DebugVerifyBitmapIsPreMultiplied() const override; - bool SetBitsWithMask(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, - const CFX_RetainPtr<CFX_DIBSource>& pMask, + bool SetBitsWithMask(const CFX_DIBSource* pBitmap, + const CFX_DIBSource* pMask, int left, int top, int bitmap_alpha, int blend_type) override; #endif + + private: + bool m_bOwnedBitmap; }; #endif // CORE_FXGE_CFX_FXGEDEVICE_H_ diff --git a/core/fxge/cfx_renderdevice.h b/core/fxge/cfx_renderdevice.h index d56c2ecb9a..41f8e4c690 100644 --- a/core/fxge/cfx_renderdevice.h +++ b/core/fxge/cfx_renderdevice.h @@ -100,13 +100,9 @@ class CFX_RenderDevice { int GetRenderCaps() const { return m_RenderCaps; } int GetDeviceCaps(int id) const; CFX_Matrix GetCTM() const; - CFX_RetainPtr<CFX_DIBitmap> GetBitmap() const { return m_pBitmap; } - void SetBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap) { - m_pBitmap = pBitmap; - } - bool CreateCompatibleBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pDIB, - int width, - int height) const; + CFX_DIBitmap* GetBitmap() const { return m_pBitmap; } + void SetBitmap(CFX_DIBitmap* pBitmap) { m_pBitmap = pBitmap; } + bool CreateCompatibleBitmap(CFX_DIBitmap* pDIB, int width, int height) const; const FX_RECT& GetClipBox() const { return m_ClipBox; } bool SetClip_PathFill(const CFX_PathData* pPathData, const CFX_Matrix* pObject2Device, @@ -144,18 +140,16 @@ class CFX_RenderDevice { int fill_mode, int blend_type); - CFX_RetainPtr<CFX_DIBitmap> GetBackDrop(); - bool GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, int left, int top); - bool SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, - int left, - int top) { + bool GetDIBits(CFX_DIBitmap* pBitmap, int left, int top); + CFX_DIBitmap* GetBackDrop(); + bool SetDIBits(const CFX_DIBSource* pBitmap, int left, int top) { return SetDIBitsWithBlend(pBitmap, left, top, FXDIB_BLEND_NORMAL); } - bool SetDIBitsWithBlend(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, + bool SetDIBitsWithBlend(const CFX_DIBSource* pBitmap, int left, int top, int blend_type); - bool StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, + bool StretchDIBits(const CFX_DIBSource* pBitmap, int left, int top, int dest_width, @@ -163,32 +157,31 @@ class CFX_RenderDevice { return StretchDIBitsWithFlagsAndBlend(pBitmap, left, top, dest_width, dest_height, 0, FXDIB_BLEND_NORMAL); } - bool StretchDIBitsWithFlagsAndBlend( - const CFX_RetainPtr<CFX_DIBSource>& pBitmap, - int left, - int top, - int dest_width, - int dest_height, - uint32_t flags, - int blend_type); - bool SetBitMask(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, + bool StretchDIBitsWithFlagsAndBlend(const CFX_DIBSource* pBitmap, + int left, + int top, + int dest_width, + int dest_height, + uint32_t flags, + int blend_type); + bool SetBitMask(const CFX_DIBSource* pBitmap, int left, int top, uint32_t color); - bool StretchBitMask(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, + bool StretchBitMask(const CFX_DIBSource* pBitmap, int left, int top, int dest_width, int dest_height, uint32_t color); - bool StretchBitMaskWithFlags(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, + bool StretchBitMaskWithFlags(const CFX_DIBSource* pBitmap, int left, int top, int dest_width, int dest_height, uint32_t color, uint32_t flags); - bool StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, + bool StartDIBits(const CFX_DIBSource* pBitmap, int bitmap_alpha, uint32_t color, const CFX_Matrix* pMatrix, @@ -197,7 +190,7 @@ class CFX_RenderDevice { return StartDIBitsWithBlend(pBitmap, bitmap_alpha, color, pMatrix, flags, handle, FXDIB_BLEND_NORMAL); } - bool StartDIBitsWithBlend(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, + bool StartDIBitsWithBlend(const CFX_DIBSource* pBitmap, int bitmap_alpha, uint32_t color, const CFX_Matrix* pMatrix, @@ -228,8 +221,8 @@ class CFX_RenderDevice { #ifdef _SKIA_SUPPORT_ virtual void DebugVerifyBitmapIsPreMultiplied() const; - virtual bool SetBitsWithMask(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, - const CFX_RetainPtr<CFX_DIBSource>& pMask, + virtual bool SetBitsWithMask(const CFX_DIBSource* pBitmap, + const CFX_DIBSource* pMask, int left, int top, int bitmap_alpha, @@ -250,7 +243,7 @@ class CFX_RenderDevice { int fill_mode, int blend_type); - CFX_RetainPtr<CFX_DIBitmap> m_pBitmap; + CFX_DIBitmap* m_pBitmap; int m_Width; int m_Height; int m_bpp; diff --git a/core/fxge/dib/dib_int.h b/core/fxge/dib/dib_int.h index a898a479a2..000003a9c6 100644 --- a/core/fxge/dib/dib_int.h +++ b/core/fxge/dib/dib_int.h @@ -71,7 +71,7 @@ class CStretchEngine { int dest_width, int dest_height, const FX_RECT& clip_rect, - const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap, + const CFX_DIBSource* pSrcBitmap, int flags); ~CStretchEngine(); @@ -91,7 +91,7 @@ class CStretchEngine { uint8_t* m_pDestScanline; uint8_t* m_pDestMaskScanline; FX_RECT m_SrcClip; - CFX_RetainPtr<CFX_DIBSource> m_pSource; + const CFX_DIBSource* m_pSource; uint32_t* m_pSrcPalette; int m_SrcWidth; int m_SrcHeight; diff --git a/core/fxge/dib/fx_dib_composite.cpp b/core/fxge/dib/fx_dib_composite.cpp index fb00cb855b..435a1ad9b6 100644 --- a/core/fxge/dib/fx_dib_composite.cpp +++ b/core/fxge/dib/fx_dib_composite.cpp @@ -3914,18 +3914,17 @@ void CFX_ScanlineCompositor::CompositeBitMaskLine(uint8_t* dest_scan, } } -bool CFX_DIBitmap::CompositeBitmap( - int dest_left, - int dest_top, - int width, - int height, - const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap, - int src_left, - int src_top, - int blend_type, - const CFX_ClipRgn* pClipRgn, - bool bRgbByteOrder, - void* pIccTransform) { +bool CFX_DIBitmap::CompositeBitmap(int dest_left, + int dest_top, + int width, + int height, + const CFX_DIBSource* pSrcBitmap, + int src_left, + int src_top, + int blend_type, + const CFX_ClipRgn* pClipRgn, + bool bRgbByteOrder, + void* pIccTransform) { if (!m_pBuffer) { return false; } @@ -3939,11 +3938,11 @@ bool CFX_DIBitmap::CompositeBitmap( if (width == 0 || height == 0) { return true; } - CFX_RetainPtr<CFX_DIBitmap> pClipMask; + const CFX_DIBitmap* pClipMask = nullptr; FX_RECT clip_box; if (pClipRgn && pClipRgn->GetType() != CFX_ClipRgn::RectI) { ASSERT(pClipRgn->GetType() == CFX_ClipRgn::MaskF); - pClipMask = pClipRgn->GetMask(); + pClipMask = pClipRgn->GetMask().GetObject(); clip_box = pClipRgn->GetBox(); } CFX_ScanlineCompositor compositor; @@ -3955,7 +3954,7 @@ bool CFX_DIBitmap::CompositeBitmap( int dest_Bpp = m_bpp / 8; int src_Bpp = pSrcBitmap->GetBPP() / 8; bool bRgb = src_Bpp > 1 && !pSrcBitmap->IsCmykImage(); - CFX_RetainPtr<CFX_DIBitmap> pSrcAlphaMask = pSrcBitmap->m_pAlphaMask; + CFX_DIBitmap* pSrcAlphaMask = pSrcBitmap->m_pAlphaMask; for (int row = 0; row < height; row++) { uint8_t* dest_scan = m_pBuffer + (dest_top + row) * m_Pitch + dest_left * dest_Bpp; @@ -3991,7 +3990,7 @@ bool CFX_DIBitmap::CompositeMask(int dest_left, int dest_top, int width, int height, - const CFX_RetainPtr<CFX_DIBSource>& pMask, + const CFX_DIBSource* pMask, uint32_t color, int src_left, int src_top, @@ -4018,11 +4017,11 @@ bool CFX_DIBitmap::CompositeMask(int dest_left, if (src_alpha == 0) { return true; } - CFX_RetainPtr<CFX_DIBitmap> pClipMask; + const CFX_DIBitmap* pClipMask = nullptr; FX_RECT clip_box; if (pClipRgn && pClipRgn->GetType() != CFX_ClipRgn::RectI) { ASSERT(pClipRgn->GetType() == CFX_ClipRgn::MaskF); - pClipMask = pClipRgn->GetMask(); + pClipMask = pClipRgn->GetMask().GetObject(); clip_box = pClipRgn->GetBox(); } int src_bpp = pMask->GetBPP(); @@ -4283,7 +4282,7 @@ CFX_BitmapComposer::~CFX_BitmapComposer() { FX_Free(m_pAddClipScan); } -void CFX_BitmapComposer::Compose(const CFX_RetainPtr<CFX_DIBitmap>& pDest, +void CFX_BitmapComposer::Compose(CFX_DIBitmap* pDest, const CFX_ClipRgn* pClipRgn, int bitmap_alpha, uint32_t mask_color, @@ -4304,8 +4303,9 @@ void CFX_BitmapComposer::Compose(const CFX_RetainPtr<CFX_DIBitmap>& pDest, m_BitmapAlpha = bitmap_alpha; m_MaskColor = mask_color; m_pClipMask = nullptr; - if (pClipRgn && pClipRgn->GetType() != CFX_ClipRgn::RectI) - m_pClipMask = pClipRgn->GetMask(); + if (pClipRgn && pClipRgn->GetType() != CFX_ClipRgn::RectI) { + m_pClipMask = pClipRgn->GetMask().GetObject(); + } m_bVertical = bVertical; m_bFlipX = bFlipX; m_bFlipY = bFlipY; diff --git a/core/fxge/dib/fx_dib_convert.cpp b/core/fxge/dib/fx_dib_convert.cpp index 624e1437e9..aad3f343e2 100644 --- a/core/fxge/dib/fx_dib_convert.cpp +++ b/core/fxge/dib/fx_dib_convert.cpp @@ -17,7 +17,7 @@ class CFX_Palette { CFX_Palette(); ~CFX_Palette(); - bool BuildPalette(const CFX_RetainPtr<CFX_DIBSource>& pBitmap); + bool BuildPalette(const CFX_DIBSource* pBitmap); uint32_t* GetPalette() const { return m_pPalette; } uint32_t* GetColorLut() const { return m_cLut; } uint32_t* GetAmountLut() const { return m_aLut; } @@ -101,7 +101,7 @@ CFX_Palette::~CFX_Palette() { m_lut = 0; } -bool CFX_Palette::BuildPalette(const CFX_RetainPtr<CFX_DIBSource>& pBitmap) { +bool CFX_Palette::BuildPalette(const CFX_DIBSource* pBitmap) { if (!pBitmap) { return false; } @@ -145,7 +145,7 @@ bool ConvertBuffer_1bppMask2Gray(uint8_t* dest_buf, int dest_pitch, int width, int height, - const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap, + const CFX_DIBSource* pSrcBitmap, int src_left, int src_top) { uint8_t set_gray, reset_gray; @@ -169,7 +169,7 @@ bool ConvertBuffer_8bppMask2Gray(uint8_t* dest_buf, int dest_pitch, int width, int height, - const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap, + const CFX_DIBSource* pSrcBitmap, int src_left, int src_top) { for (int row = 0; row < height; row++) { @@ -184,7 +184,7 @@ bool ConvertBuffer_1bppPlt2Gray(uint8_t* dest_buf, int dest_pitch, int width, int height, - const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap, + const CFX_DIBSource* pSrcBitmap, int src_left, int src_top) { uint32_t* src_plt = pSrcBitmap->GetPalette(); @@ -231,7 +231,7 @@ bool ConvertBuffer_8bppPlt2Gray(uint8_t* dest_buf, int dest_pitch, int width, int height, - const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap, + const CFX_DIBSource* pSrcBitmap, int src_left, int src_top) { uint32_t* src_plt = pSrcBitmap->GetPalette(); @@ -263,14 +263,13 @@ bool ConvertBuffer_8bppPlt2Gray(uint8_t* dest_buf, return true; } -bool ConvertBuffer_RgbOrCmyk2Gray( - uint8_t* dest_buf, - int dest_pitch, - int width, - int height, - const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap, - int src_left, - int src_top) { +bool ConvertBuffer_RgbOrCmyk2Gray(uint8_t* dest_buf, + int dest_pitch, + int width, + int height, + const CFX_DIBSource* pSrcBitmap, + int src_left, + int src_top) { int Bpp = pSrcBitmap->GetBPP() / 8; if (pSrcBitmap->IsCmykImage()) { for (int row = 0; row < height; row++) { @@ -305,7 +304,7 @@ void ConvertBuffer_IndexCopy(uint8_t* dest_buf, int dest_pitch, int width, int height, - const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap, + const CFX_DIBSource* pSrcBitmap, int src_left, int src_top) { if (pSrcBitmap->GetBPP() == 1) { @@ -334,7 +333,7 @@ bool ConvertBuffer_Plt2PltRgb8(uint8_t* dest_buf, int dest_pitch, int width, int height, - const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap, + const CFX_DIBSource* pSrcBitmap, int src_left, int src_top, uint32_t* dst_plt) { @@ -362,7 +361,7 @@ bool ConvertBuffer_Rgb2PltRgb8(uint8_t* dest_buf, int dest_pitch, int width, int height, - const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap, + const CFX_DIBSource* pSrcBitmap, int src_left, int src_top, uint32_t* dst_plt) { @@ -425,7 +424,7 @@ bool ConvertBuffer_1bppMask2Rgb(FXDIB_Format dst_format, int dest_pitch, int width, int height, - const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap, + const CFX_DIBSource* pSrcBitmap, int src_left, int src_top) { int comps = (dst_format & 0xff) / 8; @@ -456,7 +455,7 @@ bool ConvertBuffer_8bppMask2Rgb(FXDIB_Format dst_format, int dest_pitch, int width, int height, - const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap, + const CFX_DIBSource* pSrcBitmap, int src_left, int src_top) { int comps = (dst_format & 0xff) / 8; @@ -480,7 +479,7 @@ bool ConvertBuffer_1bppPlt2Rgb(FXDIB_Format dst_format, int dest_pitch, int width, int height, - const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap, + const CFX_DIBSource* pSrcBitmap, int src_left, int src_top) { int comps = (dst_format & 0xff) / 8; @@ -532,7 +531,7 @@ bool ConvertBuffer_8bppPlt2Rgb(FXDIB_Format dst_format, int dest_pitch, int width, int height, - const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap, + const CFX_DIBSource* pSrcBitmap, int src_left, int src_top) { int comps = (dst_format & 0xff) / 8; @@ -573,14 +572,13 @@ bool ConvertBuffer_8bppPlt2Rgb(FXDIB_Format dst_format, return true; } -bool ConvertBuffer_24bppRgb2Rgb24( - uint8_t* dest_buf, - int dest_pitch, - int width, - int height, - const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap, - int src_left, - int src_top) { +bool ConvertBuffer_24bppRgb2Rgb24(uint8_t* dest_buf, + int dest_pitch, + int width, + int height, + const CFX_DIBSource* pSrcBitmap, + int src_left, + int src_top) { for (int row = 0; row < height; row++) { uint8_t* dest_scan = dest_buf + row * dest_pitch; const uint8_t* src_scan = @@ -590,14 +588,13 @@ bool ConvertBuffer_24bppRgb2Rgb24( return true; } -bool ConvertBuffer_32bppRgb2Rgb24( - uint8_t* dest_buf, - int dest_pitch, - int width, - int height, - const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap, - int src_left, - int src_top) { +bool ConvertBuffer_32bppRgb2Rgb24(uint8_t* dest_buf, + int dest_pitch, + int width, + int height, + const CFX_DIBSource* pSrcBitmap, + int src_left, + int src_top) { for (int row = 0; row < height; row++) { uint8_t* dest_scan = dest_buf + row * dest_pitch; const uint8_t* src_scan = @@ -616,7 +613,7 @@ bool ConvertBuffer_Rgb2Rgb32(uint8_t* dest_buf, int dest_pitch, int width, int height, - const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap, + const CFX_DIBSource* pSrcBitmap, int src_left, int src_top) { int comps = pSrcBitmap->GetBPP() / 8; @@ -635,14 +632,13 @@ bool ConvertBuffer_Rgb2Rgb32(uint8_t* dest_buf, return true; } -bool ConvertBuffer_32bppCmyk2Rgb32( - uint8_t* dest_buf, - int dest_pitch, - int width, - int height, - const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap, - int src_left, - int src_top) { +bool ConvertBuffer_32bppCmyk2Rgb32(uint8_t* dest_buf, + int dest_pitch, + int width, + int height, + const CFX_DIBSource* pSrcBitmap, + int src_left, + int src_top) { for (int row = 0; row < height; row++) { uint8_t* dest_scan = dest_buf + row * dest_pitch; const uint8_t* src_scan = @@ -662,7 +658,7 @@ bool ConvertBuffer(FXDIB_Format dest_format, int dest_pitch, int width, int height, - const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap, + const CFX_DIBSource* pSrcBitmap, int src_left, int src_top, std::unique_ptr<uint32_t, FxFreeDeleter>* p_pal) { @@ -787,16 +783,16 @@ bool ConvertBuffer(FXDIB_Format dest_format, } } -CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::CloneConvert( - FXDIB_Format dest_format) { +std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::CloneConvert( + FXDIB_Format dest_format) const { if (dest_format == GetFormat()) return Clone(nullptr); - auto pClone = pdfium::MakeRetain<CFX_DIBitmap>(); + std::unique_ptr<CFX_DIBitmap> pClone = pdfium::MakeUnique<CFX_DIBitmap>(); if (!pClone->Create(m_Width, m_Height, dest_format)) return nullptr; - CFX_RetainPtr<CFX_DIBitmap> pSrcAlpha; + CFX_MaybeOwned<CFX_DIBitmap> pSrcAlpha; if (HasAlpha()) { if (GetFormat() == FXDIB_Argb) pSrcAlpha = CloneAlphaMask(); @@ -809,19 +805,19 @@ CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::CloneConvert( bool ret = true; if (dest_format & 0x0200) { if (dest_format == FXDIB_Argb) { - ret = pSrcAlpha ? pClone->LoadChannel(FXDIB_Alpha, pSrcAlpha, FXDIB_Alpha) - : pClone->LoadChannel(FXDIB_Alpha, 0xff); + ret = pSrcAlpha + ? pClone->LoadChannel(FXDIB_Alpha, pSrcAlpha.Get(), FXDIB_Alpha) + : pClone->LoadChannel(FXDIB_Alpha, 0xff); } else { - ret = pClone->SetAlphaMask(pSrcAlpha); + ret = pClone->SetAlphaMask(pSrcAlpha.Get()); } } if (!ret) return nullptr; - CFX_RetainPtr<CFX_DIBSource> holder(this); std::unique_ptr<uint32_t, FxFreeDeleter> pal_8bpp; if (!ConvertBuffer(dest_format, pClone->GetBuffer(), pClone->GetPitch(), - m_Width, m_Height, holder, 0, 0, &pal_8bpp)) { + m_Width, m_Height, this, 0, 0, &pal_8bpp)) { return nullptr; } if (pal_8bpp) @@ -857,7 +853,7 @@ bool CFX_DIBitmap::ConvertFormat(FXDIB_Format dest_format) { if (!dest_buf) { return false; } - CFX_RetainPtr<CFX_DIBitmap> pAlphaMask; + CFX_DIBitmap* pAlphaMask = nullptr; if (dest_format == FXDIB_Argb) { FXSYS_memset(dest_buf, 0xff, dest_pitch * m_Height + 4); if (m_pAlphaMask) { @@ -872,7 +868,7 @@ bool CFX_DIBitmap::ConvertFormat(FXDIB_Format dest_format) { } } else if (dest_format & 0x0200) { if (src_format == FXDIB_Argb) { - pAlphaMask = CloneAlphaMask(); + pAlphaMask = CloneAlphaMask().release(); if (!pAlphaMask) { FX_Free(dest_buf); return false; @@ -883,21 +879,25 @@ bool CFX_DIBitmap::ConvertFormat(FXDIB_Format dest_format) { FX_Free(dest_buf); return false; } - pAlphaMask = std::move(m_pAlphaMask); + pAlphaMask = m_pAlphaMask; + m_pAlphaMask = nullptr; } else { pAlphaMask = m_pAlphaMask; } } } bool ret = false; - CFX_RetainPtr<CFX_DIBSource> holder(this); std::unique_ptr<uint32_t, FxFreeDeleter> pal_8bpp; ret = ConvertBuffer(dest_format, dest_buf, dest_pitch, m_Width, m_Height, - holder, 0, 0, &pal_8bpp); + this, 0, 0, &pal_8bpp); if (!ret) { + if (pAlphaMask != m_pAlphaMask) + delete pAlphaMask; FX_Free(dest_buf); return false; } + if (m_pAlphaMask && pAlphaMask != m_pAlphaMask) + delete m_pAlphaMask; m_pAlphaMask = pAlphaMask; m_pPalette = std::move(pal_8bpp); if (!m_bExtBuf) diff --git a/core/fxge/dib/fx_dib_engine.cpp b/core/fxge/dib/fx_dib_engine.cpp index 7aa710b795..5975a5e975 100644 --- a/core/fxge/dib/fx_dib_engine.cpp +++ b/core/fxge/dib/fx_dib_engine.cpp @@ -265,7 +265,7 @@ CStretchEngine::CStretchEngine(IFX_ScanlineComposer* pDestBitmap, int dest_width, int dest_height, const FX_RECT& clip_rect, - const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap, + const CFX_DIBSource* pSrcBitmap, int flags) { m_State = 0; m_DestFormat = dest_format; @@ -852,13 +852,12 @@ void CStretchEngine::StretchVert() { } } -CFX_ImageStretcher::CFX_ImageStretcher( - IFX_ScanlineComposer* pDest, - const CFX_RetainPtr<CFX_DIBSource>& pSource, - int dest_width, - int dest_height, - const FX_RECT& bitmap_rect, - uint32_t flags) +CFX_ImageStretcher::CFX_ImageStretcher(IFX_ScanlineComposer* pDest, + const CFX_DIBSource* pSource, + int dest_width, + int dest_height, + const FX_RECT& bitmap_rect, + uint32_t flags) : m_pDest(pDest), m_pSource(pSource), m_Flags(flags), diff --git a/core/fxge/dib/fx_dib_engine_unittest.cpp b/core/fxge/dib/fx_dib_engine_unittest.cpp index 86df82442f..705d761ca8 100644 --- a/core/fxge/dib/fx_dib_engine_unittest.cpp +++ b/core/fxge/dib/fx_dib_engine_unittest.cpp @@ -23,9 +23,9 @@ TEST(CStretchEngine, OverflowInCtor) { dict_obj->SetNewFor<CPDF_Number>("Height", 12500); std::unique_ptr<CPDF_Stream> stream = pdfium::MakeUnique<CPDF_Stream>(nullptr, 0, std::move(dict_obj)); - auto dib_source = pdfium::MakeRetain<CPDF_DIBSource>(); - dib_source->Load(nullptr, stream.get()); - CStretchEngine engine(nullptr, FXDIB_8bppRgb, 500, 500, clip_rect, dib_source, - 0); + CPDF_DIBSource dib_source; + dib_source.Load(nullptr, stream.get()); + CStretchEngine engine(nullptr, FXDIB_8bppRgb, 500, 500, clip_rect, + &dib_source, 0); EXPECT_EQ(FXDIB_INTERPOL, engine.m_Flags); } diff --git a/core/fxge/dib/fx_dib_main.cpp b/core/fxge/dib/fx_dib_main.cpp index 8a97d342b5..96cae9d4e7 100644 --- a/core/fxge/dib/fx_dib_main.cpp +++ b/core/fxge/dib/fx_dib_main.cpp @@ -44,9 +44,16 @@ uint32_t ArgbEncode(int a, FX_COLORREF rgb) { } CFX_DIBSource::CFX_DIBSource() - : m_Width(0), m_Height(0), m_bpp(0), m_AlphaFlag(0), m_Pitch(0) {} - -CFX_DIBSource::~CFX_DIBSource() {} + : m_pAlphaMask(nullptr), + m_Width(0), + m_Height(0), + m_bpp(0), + m_AlphaFlag(0), + m_Pitch(0) {} + +CFX_DIBSource::~CFX_DIBSource() { + delete m_pAlphaMask; +} uint8_t* CFX_DIBSource::GetBuffer() const { return nullptr; @@ -120,7 +127,7 @@ bool CFX_DIBitmap::Create(int width, return true; } -bool CFX_DIBitmap::Copy(const CFX_RetainPtr<CFX_DIBSource>& pSrc) { +bool CFX_DIBitmap::Copy(const CFX_DIBSource* pSrc) { if (m_pBuffer) return false; @@ -150,10 +157,11 @@ const uint8_t* CFX_DIBitmap::GetScanline(int line) const { return m_pBuffer ? m_pBuffer + line * m_Pitch : nullptr; } -void CFX_DIBitmap::TakeOver(CFX_RetainPtr<CFX_DIBitmap>&& pSrcBitmap) { +void CFX_DIBitmap::TakeOver(CFX_DIBitmap* pSrcBitmap) { if (!m_bExtBuf) FX_Free(m_pBuffer); + delete m_pAlphaMask; m_pBuffer = pSrcBitmap->m_pBuffer; m_pPalette = std::move(pSrcBitmap->m_pPalette); m_pAlphaMask = pSrcBitmap->m_pAlphaMask; @@ -167,14 +175,14 @@ void CFX_DIBitmap::TakeOver(CFX_RetainPtr<CFX_DIBitmap>&& pSrcBitmap) { m_Pitch = pSrcBitmap->m_Pitch; } -CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::Clone(const FX_RECT* pClip) const { +std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::Clone(const FX_RECT* pClip) const { FX_RECT rect(0, 0, m_Width, m_Height); if (pClip) { rect.Intersect(*pClip); if (rect.IsEmpty()) return nullptr; } - auto pNewBitmap = pdfium::MakeRetain<CFX_DIBitmap>(); + auto pNewBitmap = pdfium::MakeUnique<CFX_DIBitmap>(); if (!pNewBitmap->Create(rect.Width(), rect.Height(), GetFormat())) return nullptr; @@ -232,11 +240,12 @@ void CFX_DIBSource::BuildPalette() { } bool CFX_DIBSource::BuildAlphaMask() { - if (m_pAlphaMask) + if (m_pAlphaMask) { return true; - - m_pAlphaMask = pdfium::MakeRetain<CFX_DIBitmap>(); + } + m_pAlphaMask = new CFX_DIBitmap; if (!m_pAlphaMask->Create(m_Width, m_Height, FXDIB_8bppMask)) { + delete m_pAlphaMask; m_pAlphaMask = nullptr; return false; } @@ -392,14 +401,13 @@ void CFX_DIBSource::GetOverlapRect(int& dest_left, height = dest_rect.bottom - dest_rect.top; } -bool CFX_DIBitmap::TransferBitmap( - int dest_left, - int dest_top, - int width, - int height, - const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap, - int src_left, - int src_top) { +bool CFX_DIBitmap::TransferBitmap(int dest_left, + int dest_top, + int width, + int height, + const CFX_DIBSource* pSrcBitmap, + int src_left, + int src_top) { if (!m_pBuffer) return false; @@ -458,7 +466,7 @@ bool CFX_DIBitmap::TransferMask(int dest_left, int dest_top, int width, int height, - const CFX_RetainPtr<CFX_DIBSource>& pMask, + const CFX_DIBSource* pMask, uint32_t color, int src_left, int src_top, @@ -597,7 +605,7 @@ void CFX_DIBSource::GetPalette(uint32_t* pal, int alpha) const { } } -CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::CloneAlphaMask( +std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::CloneAlphaMask( const FX_RECT* pClip) const { ASSERT(GetFormat() == FXDIB_Argb); FX_RECT rect(0, 0, m_Width, m_Height); @@ -606,7 +614,7 @@ CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::CloneAlphaMask( if (rect.IsEmpty()) return nullptr; } - auto pMask = pdfium::MakeRetain<CFX_DIBitmap>(); + auto pMask = pdfium::MakeUnique<CFX_DIBitmap>(); if (!pMask->Create(rect.Width(), rect.Height(), FXDIB_8bppMask)) return nullptr; @@ -622,7 +630,7 @@ CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::CloneAlphaMask( return pMask; } -bool CFX_DIBSource::SetAlphaMask(const CFX_RetainPtr<CFX_DIBSource>& pAlphaMask, +bool CFX_DIBSource::SetAlphaMask(const CFX_DIBSource* pAlphaMask, const FX_RECT* pClip) { if (!HasAlpha() || GetFormat() == FXDIB_Argb) return false; @@ -652,12 +660,12 @@ bool CFX_DIBSource::SetAlphaMask(const CFX_RetainPtr<CFX_DIBSource>& pAlphaMask, const int g_ChannelOffset[] = {0, 2, 1, 0, 0, 1, 2, 3, 3}; bool CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel, - const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap, + CFX_DIBSource* pSrcBitmap, FXDIB_Channel srcChannel) { if (!m_pBuffer) return false; - CFX_RetainPtr<CFX_DIBSource> pSrcClone = pSrcBitmap; + CFX_MaybeOwned<CFX_DIBSource> pSrcClone(pSrcBitmap); int srcOffset; if (srcChannel == FXDIB_Alpha) { if (!pSrcBitmap->HasAlpha() && !pSrcBitmap->IsAlphaMask()) @@ -717,7 +725,7 @@ bool CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel, destOffset = g_ChannelOffset[destChannel]; } if (srcChannel == FXDIB_Alpha && pSrcClone->m_pAlphaMask) { - CFX_RetainPtr<CFX_DIBSource> pAlphaMask = pSrcClone->m_pAlphaMask; + CFX_MaybeOwned<CFX_DIBSource> pAlphaMask(pSrcClone->m_pAlphaMask); if (pSrcClone->GetWidth() != m_Width || pSrcClone->GetHeight() != m_Height) { if (pAlphaMask) { @@ -730,14 +738,14 @@ bool CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel, srcOffset = 0; } else if (pSrcClone->GetWidth() != m_Width || pSrcClone->GetHeight() != m_Height) { - CFX_RetainPtr<CFX_DIBitmap> pSrcMatched = + std::unique_ptr<CFX_DIBitmap> pSrcMatched = pSrcClone->StretchTo(m_Width, m_Height); if (!pSrcMatched) return false; pSrcClone = std::move(pSrcMatched); } - CFX_RetainPtr<CFX_DIBitmap> pDst(this); + CFX_DIBitmap* pDst = this; if (destChannel == FXDIB_Alpha && m_pAlphaMask) { pDst = m_pAlphaMask; destOffset = 0; @@ -815,8 +823,7 @@ bool CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel, int value) { return true; } -bool CFX_DIBitmap::MultiplyAlpha( - const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap) { +bool CFX_DIBitmap::MultiplyAlpha(CFX_DIBSource* pSrcBitmap) { if (!m_pBuffer) return false; @@ -827,7 +834,8 @@ bool CFX_DIBitmap::MultiplyAlpha( if (!IsAlphaMask() && !HasAlpha()) return LoadChannel(FXDIB_Alpha, pSrcBitmap, FXDIB_Alpha); - CFX_RetainPtr<CFX_DIBitmap> pSrcClone = pSrcBitmap.As<CFX_DIBitmap>(); + CFX_MaybeOwned<CFX_DIBitmap> pSrcClone( + static_cast<CFX_DIBitmap*>(pSrcBitmap)); if (pSrcBitmap->GetWidth() != m_Width || pSrcBitmap->GetHeight() != m_Height) { pSrcClone = pSrcBitmap->StretchTo(m_Width, m_Height); @@ -867,7 +875,7 @@ bool CFX_DIBitmap::MultiplyAlpha( } } } else { - m_pAlphaMask->MultiplyAlpha(pSrcClone); + m_pAlphaMask->MultiplyAlpha(pSrcClone.Get()); } } return true; @@ -879,9 +887,9 @@ bool CFX_DIBitmap::GetGrayData(void* pIccTransform) { } switch (GetFormat()) { case FXDIB_1bppRgb: { - if (!m_pPalette) + if (!m_pPalette) { return false; - + } uint8_t gray[2]; for (int i = 0; i < 2; i++) { int r = static_cast<uint8_t>(m_pPalette.get()[i] >> 16); @@ -889,10 +897,11 @@ bool CFX_DIBitmap::GetGrayData(void* pIccTransform) { int b = static_cast<uint8_t>(m_pPalette.get()[i]); gray[i] = static_cast<uint8_t>(FXRGB2GRAY(r, g, b)); } - auto pMask = pdfium::MakeRetain<CFX_DIBitmap>(); - if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) + CFX_DIBitmap* pMask = new CFX_DIBitmap; + if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) { + delete pMask; return false; - + } FXSYS_memset(pMask->GetBuffer(), gray[0], pMask->GetPitch() * m_Height); for (int row = 0; row < m_Height; row++) { uint8_t* src_pos = m_pBuffer + row * m_Pitch; @@ -904,13 +913,14 @@ bool CFX_DIBitmap::GetGrayData(void* pIccTransform) { dest_pos++; } } - TakeOver(std::move(pMask)); + TakeOver(pMask); + delete pMask; break; } case FXDIB_8bppRgb: { - if (!m_pPalette) + if (!m_pPalette) { return false; - + } uint8_t gray[256]; for (int i = 0; i < 256; i++) { int r = static_cast<uint8_t>(m_pPalette.get()[i] >> 16); @@ -918,10 +928,11 @@ bool CFX_DIBitmap::GetGrayData(void* pIccTransform) { int b = static_cast<uint8_t>(m_pPalette.get()[i]); gray[i] = static_cast<uint8_t>(FXRGB2GRAY(r, g, b)); } - auto pMask = pdfium::MakeRetain<CFX_DIBitmap>(); - if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) + CFX_DIBitmap* pMask = new CFX_DIBitmap; + if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) { + delete pMask; return false; - + } for (int row = 0; row < m_Height; row++) { uint8_t* dest_pos = pMask->GetBuffer() + row * pMask->GetPitch(); uint8_t* src_pos = m_pBuffer + row * m_Pitch; @@ -929,14 +940,16 @@ bool CFX_DIBitmap::GetGrayData(void* pIccTransform) { *dest_pos++ = gray[*src_pos++]; } } - TakeOver(std::move(pMask)); + TakeOver(pMask); + delete pMask; break; } case FXDIB_Rgb: { - auto pMask = pdfium::MakeRetain<CFX_DIBitmap>(); - if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) + CFX_DIBitmap* pMask = new CFX_DIBitmap; + if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) { + delete pMask; return false; - + } for (int row = 0; row < m_Height; row++) { uint8_t* src_pos = m_pBuffer + row * m_Pitch; uint8_t* dest_pos = pMask->GetBuffer() + row * pMask->GetPitch(); @@ -945,14 +958,16 @@ bool CFX_DIBitmap::GetGrayData(void* pIccTransform) { src_pos += 3; } } - TakeOver(std::move(pMask)); + TakeOver(pMask); + delete pMask; break; } case FXDIB_Rgb32: { - auto pMask = pdfium::MakeRetain<CFX_DIBitmap>(); - if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) + CFX_DIBitmap* pMask = new CFX_DIBitmap; + if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) { + delete pMask; return false; - + } for (int row = 0; row < m_Height; row++) { uint8_t* src_pos = m_pBuffer + row * m_Pitch; uint8_t* dest_pos = pMask->GetBuffer() + row * pMask->GetPitch(); @@ -961,7 +976,8 @@ bool CFX_DIBitmap::GetGrayData(void* pIccTransform) { src_pos += 4; } } - TakeOver(std::move(pMask)); + TakeOver(pMask); + delete pMask; break; } default: @@ -1326,9 +1342,9 @@ bool CFX_DIBitmap::ConvertColorScale(uint32_t forecolor, uint32_t backcolor) { return true; } -CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::FlipImage(bool bXFlip, - bool bYFlip) const { - auto pFlipped = pdfium::MakeRetain<CFX_DIBitmap>(); +std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::FlipImage(bool bXFlip, + bool bYFlip) const { + auto pFlipped = pdfium::MakeUnique<CFX_DIBitmap>(); if (!pFlipped->Create(m_Width, m_Height, GetFormat())) return nullptr; @@ -1398,12 +1414,12 @@ CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::FlipImage(bool bXFlip, return pFlipped; } -CFX_DIBExtractor::CFX_DIBExtractor(const CFX_RetainPtr<CFX_DIBSource>& pSrc) { +CFX_DIBExtractor::CFX_DIBExtractor(const CFX_DIBSource* pSrc) { if (pSrc->GetBuffer()) { - m_pBitmap = pdfium::MakeRetain<CFX_DIBitmap>(); + m_pBitmap = pdfium::MakeUnique<CFX_DIBitmap>(); if (!m_pBitmap->Create(pSrc->GetWidth(), pSrc->GetHeight(), pSrc->GetFormat(), pSrc->GetBuffer())) { - m_pBitmap.Reset(); + m_pBitmap.reset(); return; } m_pBitmap->SetPalette(pSrc->GetPalette()); @@ -1415,12 +1431,17 @@ CFX_DIBExtractor::CFX_DIBExtractor(const CFX_RetainPtr<CFX_DIBSource>& pSrc) { CFX_DIBExtractor::~CFX_DIBExtractor() {} -CFX_FilteredDIB::CFX_FilteredDIB() {} +CFX_FilteredDIB::CFX_FilteredDIB() : m_pSrc(nullptr) {} -CFX_FilteredDIB::~CFX_FilteredDIB() {} +CFX_FilteredDIB::~CFX_FilteredDIB() { + if (m_bAutoDropSrc) { + delete m_pSrc; + } +} -void CFX_FilteredDIB::LoadSrc(const CFX_RetainPtr<CFX_DIBSource>& pSrc) { +void CFX_FilteredDIB::LoadSrc(const CFX_DIBSource* pSrc, bool bAutoDropSrc) { m_pSrc = pSrc; + m_bAutoDropSrc = bAutoDropSrc; m_Width = pSrc->GetWidth(); m_Height = pSrc->GetHeight(); FXDIB_Format format = GetDestFormat(); @@ -1457,9 +1478,9 @@ CFX_ImageRenderer::CFX_ImageRenderer() { CFX_ImageRenderer::~CFX_ImageRenderer() {} -bool CFX_ImageRenderer::Start(const CFX_RetainPtr<CFX_DIBitmap>& pDevice, +bool CFX_ImageRenderer::Start(CFX_DIBitmap* pDevice, const CFX_ClipRgn* pClipRgn, - const CFX_RetainPtr<CFX_DIBSource>& pSource, + const CFX_DIBSource* pSource, int bitmap_alpha, uint32_t mask_color, const CFX_Matrix* pMatrix, @@ -1548,7 +1569,7 @@ bool CFX_ImageRenderer::Continue(IFX_Pause* pPause) { if (m_pTransformer->Continue(pPause)) return true; - CFX_RetainPtr<CFX_DIBitmap> pBitmap = m_pTransformer->DetachBitmap(); + std::unique_ptr<CFX_DIBitmap> pBitmap(m_pTransformer->DetachBitmap()); if (!pBitmap || !pBitmap->GetBuffer()) return false; @@ -1564,16 +1585,16 @@ bool CFX_ImageRenderer::Continue(IFX_Pause* pPause) { } m_pDevice->CompositeMask( m_pTransformer->result().left, m_pTransformer->result().top, - pBitmap->GetWidth(), pBitmap->GetHeight(), pBitmap, m_MaskColor, 0, 0, - m_BlendType, m_pClipRgn, m_bRgbByteOrder, m_AlphaFlag, + pBitmap->GetWidth(), pBitmap->GetHeight(), pBitmap.get(), m_MaskColor, + 0, 0, m_BlendType, m_pClipRgn, m_bRgbByteOrder, m_AlphaFlag, m_pIccTransform); } else { if (m_BitmapAlpha != 255) pBitmap->MultiplyAlpha(m_BitmapAlpha); m_pDevice->CompositeBitmap( m_pTransformer->result().left, m_pTransformer->result().top, - pBitmap->GetWidth(), pBitmap->GetHeight(), pBitmap, 0, 0, m_BlendType, - m_pClipRgn, m_bRgbByteOrder, m_pIccTransform); + pBitmap->GetWidth(), pBitmap->GetHeight(), pBitmap.get(), 0, 0, + m_BlendType, m_pClipRgn, m_bRgbByteOrder, m_pIccTransform); } return false; } @@ -1586,11 +1607,11 @@ CFX_BitmapStorer::CFX_BitmapStorer() { CFX_BitmapStorer::~CFX_BitmapStorer() { } -CFX_RetainPtr<CFX_DIBitmap> CFX_BitmapStorer::Detach() { +std::unique_ptr<CFX_DIBitmap> CFX_BitmapStorer::Detach() { return std::move(m_pBitmap); } -void CFX_BitmapStorer::Replace(CFX_RetainPtr<CFX_DIBitmap>&& pBitmap) { +void CFX_BitmapStorer::Replace(std::unique_ptr<CFX_DIBitmap> pBitmap) { m_pBitmap = std::move(pBitmap); } @@ -1615,13 +1636,12 @@ bool CFX_BitmapStorer::SetInfo(int width, int height, FXDIB_Format src_format, uint32_t* pSrcPalette) { - auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>(); - if (!pBitmap->Create(width, height, src_format)) + m_pBitmap = pdfium::MakeUnique<CFX_DIBitmap>(); + if (!m_pBitmap->Create(width, height, src_format)) { + m_pBitmap.reset(); return false; - + } if (pSrcPalette) - pBitmap->SetPalette(pSrcPalette); - - m_pBitmap = std::move(pBitmap); + m_pBitmap->SetPalette(pSrcPalette); return true; } diff --git a/core/fxge/dib/fx_dib_transform.cpp b/core/fxge/dib/fx_dib_transform.cpp index 3d8ddf8783..4a1c3ee050 100644 --- a/core/fxge/dib/fx_dib_transform.cpp +++ b/core/fxge/dib/fx_dib_transform.cpp @@ -100,7 +100,7 @@ void bicubic_get_pos_weight(int pos_pixel[], v_w[3] = SDP_Table[512 - res_y]; } -FXDIB_Format GetTransformedFormat(const CFX_RetainPtr<CFX_DIBSource>& pDrc) { +FXDIB_Format GetTransformedFormat(const CFX_DIBSource* pDrc) { FXDIB_Format format = pDrc->GetFormat(); if (pDrc->IsAlphaMask()) { format = FXDIB_8bppMask; @@ -179,7 +179,7 @@ class CFX_BilinearMatrix : public CPDF_FixedMatrix { } }; -CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::SwapXY( +std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::SwapXY( bool bXFlip, bool bYFlip, const FX_RECT* pDestClip) const { @@ -189,7 +189,7 @@ CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::SwapXY( if (dest_clip.IsEmpty()) return nullptr; - auto pTransBitmap = pdfium::MakeRetain<CFX_DIBitmap>(); + auto pTransBitmap = pdfium::MakeUnique<CFX_DIBitmap>(); int result_height = dest_clip.Height(); int result_width = dest_clip.Width(); if (!pTransBitmap->Create(result_width, result_height, GetFormat())) @@ -303,14 +303,13 @@ FX_RECT FXDIB_SwapClipBox(FX_RECT& clip, return rect; } -CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::TransformTo( +std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::TransformTo( const CFX_Matrix* pDestMatrix, int& result_left, int& result_top, uint32_t flags, - const FX_RECT* pDestClip) { - CFX_RetainPtr<CFX_DIBSource> holder(this); - CFX_ImageTransformer transformer(holder, pDestMatrix, flags, pDestClip); + const FX_RECT* pDestClip) const { + CFX_ImageTransformer transformer(this, pDestMatrix, flags, pDestClip); transformer.Start(); transformer.Continue(nullptr); result_left = transformer.result().left; @@ -318,11 +317,11 @@ CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::TransformTo( return transformer.DetachBitmap(); } -CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::StretchTo(int dest_width, - int dest_height, - uint32_t flags, - const FX_RECT* pClip) { - CFX_RetainPtr<CFX_DIBSource> holder(this); +std::unique_ptr<CFX_DIBitmap> CFX_DIBSource::StretchTo( + int dest_width, + int dest_height, + uint32_t flags, + const FX_RECT* pClip) const { FX_RECT clip_rect(0, 0, FXSYS_abs(dest_width), FXSYS_abs(dest_height)); if (pClip) clip_rect.Intersect(*pClip); @@ -334,7 +333,7 @@ CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::StretchTo(int dest_width, return Clone(&clip_rect); CFX_BitmapStorer storer; - CFX_ImageStretcher stretcher(&storer, holder, dest_width, dest_height, + CFX_ImageStretcher stretcher(&storer, this, dest_width, dest_height, clip_rect, flags); if (stretcher.Start()) stretcher.Continue(nullptr); @@ -342,11 +341,10 @@ CFX_RetainPtr<CFX_DIBitmap> CFX_DIBSource::StretchTo(int dest_width, return storer.Detach(); } -CFX_ImageTransformer::CFX_ImageTransformer( - const CFX_RetainPtr<CFX_DIBSource>& pSrc, - const CFX_Matrix* pMatrix, - int flags, - const FX_RECT* pClip) +CFX_ImageTransformer::CFX_ImageTransformer(const CFX_DIBSource* pSrc, + const CFX_Matrix* pMatrix, + int flags, + const FX_RECT* pClip) : m_pSrc(pSrc), m_pMatrix(pMatrix), m_pClip(pClip), @@ -446,7 +444,7 @@ bool CFX_ImageTransformer::Continue(IFX_Pause* pPause) { stretch_buf_mask = m_Storer.GetBitmap()->m_pAlphaMask->GetBuffer(); int stretch_pitch = m_Storer.GetBitmap()->GetPitch(); - auto pTransformed = pdfium::MakeRetain<CFX_DIBitmap>(); + std::unique_ptr<CFX_DIBitmap> pTransformed(new CFX_DIBitmap); FXDIB_Format transformF = GetTransformedFormat(m_Stretcher->source()); if (!pTransformed->Create(m_result.Width(), m_result.Height(), transformF)) return false; @@ -960,6 +958,6 @@ bool CFX_ImageTransformer::Continue(IFX_Pause* pPause) { return false; } -CFX_RetainPtr<CFX_DIBitmap> CFX_ImageTransformer::DetachBitmap() { +std::unique_ptr<CFX_DIBitmap> CFX_ImageTransformer::DetachBitmap() { return m_Storer.Detach(); } diff --git a/core/fxge/fx_dib.h b/core/fxge/fx_dib.h index 2208276fa7..14be05fafe 100644 --- a/core/fxge/fx_dib.h +++ b/core/fxge/fx_dib.h @@ -10,10 +10,9 @@ #include <memory> #include <vector> -#include "core/fxcrt/cfx_retain_ptr.h" +#include "core/fxcrt/cfx_shared_copy_on_write.h" #include "core/fxcrt/fx_basic.h" #include "core/fxcrt/fx_coordinates.h" -#include "third_party/base/stl_util.h" enum FXDIB_Format { FXDIB_Invalid = 0, @@ -164,14 +163,14 @@ bool ConvertBuffer(FXDIB_Format dest_format, int dest_pitch, int width, int height, - const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap, + const CFX_DIBSource* pSrcBitmap, int src_left, int src_top, std::unique_ptr<uint32_t, FxFreeDeleter>* pal); -class CFX_DIBSource : public CFX_Retainable { +class CFX_DIBSource { public: - ~CFX_DIBSource() override; + virtual ~CFX_DIBSource(); virtual uint8_t* GetBuffer() const; virtual const uint8_t* GetScanline(int line) const = 0; @@ -217,29 +216,31 @@ class CFX_DIBSource : public CFX_Retainable { // Copies into internally-owned palette. void SetPalette(const uint32_t* pSrcPal); - CFX_RetainPtr<CFX_DIBitmap> Clone(const FX_RECT* pClip = nullptr) const; - CFX_RetainPtr<CFX_DIBitmap> CloneConvert(FXDIB_Format format); - CFX_RetainPtr<CFX_DIBitmap> StretchTo(int dest_width, - int dest_height, - uint32_t flags = 0, - const FX_RECT* pClip = nullptr); - CFX_RetainPtr<CFX_DIBitmap> TransformTo(const CFX_Matrix* pMatrix, - int& left, - int& top, + std::unique_ptr<CFX_DIBitmap> Clone(const FX_RECT* pClip = nullptr) const; + std::unique_ptr<CFX_DIBitmap> CloneConvert(FXDIB_Format format) const; + std::unique_ptr<CFX_DIBitmap> StretchTo(int dest_width, + int dest_height, uint32_t flags = 0, - const FX_RECT* pClip = nullptr); - CFX_RetainPtr<CFX_DIBitmap> SwapXY(bool bXFlip, - bool bYFlip, - const FX_RECT* pClip = nullptr) const; - CFX_RetainPtr<CFX_DIBitmap> FlipImage(bool bXFlip, bool bYFlip) const; + const FX_RECT* pClip = nullptr) const; + std::unique_ptr<CFX_DIBitmap> TransformTo( + const CFX_Matrix* pMatrix, + int& left, + int& top, + uint32_t flags = 0, + const FX_RECT* pClip = nullptr) const; + std::unique_ptr<CFX_DIBitmap> SwapXY(bool bXFlip, + bool bYFlip, + const FX_RECT* pClip = nullptr) const; + std::unique_ptr<CFX_DIBitmap> FlipImage(bool bXFlip, bool bYFlip) const; - CFX_RetainPtr<CFX_DIBitmap> CloneAlphaMask( + std::unique_ptr<CFX_DIBitmap> CloneAlphaMask( const FX_RECT* pClip = nullptr) const; // Copies into internally-owned mask. - bool SetAlphaMask(const CFX_RetainPtr<CFX_DIBSource>& pAlphaMask, + bool SetAlphaMask(const CFX_DIBSource* pAlphaMask, const FX_RECT* pClip = nullptr); + void GetOverlapRect(int& dest_left, int& dest_top, int& width, @@ -254,7 +255,7 @@ class CFX_DIBSource : public CFX_Retainable { void DebugVerifyBitmapIsPreMultiplied(void* buffer = nullptr) const; #endif - CFX_RetainPtr<CFX_DIBitmap> m_pAlphaMask; + CFX_DIBitmap* m_pAlphaMask; protected: CFX_DIBSource(); @@ -275,9 +276,8 @@ class CFX_DIBSource : public CFX_Retainable { class CFX_DIBitmap : public CFX_DIBSource { public: - template <typename T, typename... Args> - friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args); - + CFX_DIBitmap(); + explicit CFX_DIBitmap(const CFX_DIBitmap& src); ~CFX_DIBitmap() override; bool Create(int width, @@ -286,7 +286,7 @@ class CFX_DIBitmap : public CFX_DIBSource { uint8_t* pBuffer = nullptr, int pitch = 0); - bool Copy(const CFX_RetainPtr<CFX_DIBSource>& pSrc); + bool Copy(const CFX_DIBSource* pSrc); // CFX_DIBSource uint8_t* GetBuffer() const override; @@ -299,26 +299,31 @@ class CFX_DIBitmap : public CFX_DIBSource { int clip_left, int clip_width) const override; - void TakeOver(CFX_RetainPtr<CFX_DIBitmap>&& pSrcBitmap); + void TakeOver(CFX_DIBitmap* pSrcBitmap); + bool ConvertFormat(FXDIB_Format format); + void Clear(uint32_t color); uint32_t GetPixel(int x, int y) const; + void SetPixel(int x, int y, uint32_t color); bool LoadChannel(FXDIB_Channel destChannel, - const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap, + CFX_DIBSource* pSrcBitmap, FXDIB_Channel srcChannel); + bool LoadChannel(FXDIB_Channel destChannel, int value); bool MultiplyAlpha(int alpha); - bool MultiplyAlpha(const CFX_RetainPtr<CFX_DIBSource>& pAlphaMask); + + bool MultiplyAlpha(CFX_DIBSource* pAlphaMask); bool TransferBitmap(int dest_left, int dest_top, int width, int height, - const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap, + const CFX_DIBSource* pSrcBitmap, int src_left, int src_top); @@ -326,7 +331,7 @@ class CFX_DIBitmap : public CFX_DIBSource { int dest_top, int width, int height, - const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap, + const CFX_DIBSource* pSrcBitmap, int src_left, int src_top, int blend_type = FXDIB_BLEND_NORMAL, @@ -338,7 +343,7 @@ class CFX_DIBitmap : public CFX_DIBSource { int dest_top, int width, int height, - const CFX_RetainPtr<CFX_DIBSource>& pMask, + const CFX_DIBSource* pMask, uint32_t color, int src_left, int src_top, @@ -349,7 +354,7 @@ class CFX_DIBitmap : public CFX_DIBSource { int dest_top, int width, int height, - const CFX_RetainPtr<CFX_DIBSource>& pMask, + const CFX_DIBSource* pMask, uint32_t color, int src_left, int src_top, @@ -377,8 +382,6 @@ class CFX_DIBitmap : public CFX_DIBSource { #endif protected: - CFX_DIBitmap(); - CFX_DIBitmap(const CFX_DIBitmap& src); bool GetGrayData(void* pIccTransform = nullptr); #if defined _SKIA_SUPPORT_PATHS_ @@ -394,36 +397,37 @@ class CFX_DIBitmap : public CFX_DIBSource { class CFX_DIBExtractor { public: - explicit CFX_DIBExtractor(const CFX_RetainPtr<CFX_DIBSource>& pSrc); + explicit CFX_DIBExtractor(const CFX_DIBSource* pSrc); ~CFX_DIBExtractor(); - CFX_RetainPtr<CFX_DIBitmap> GetBitmap() { return m_pBitmap; } + CFX_DIBitmap* GetBitmap() { return m_pBitmap.get(); } private: - CFX_RetainPtr<CFX_DIBitmap> m_pBitmap; + std::unique_ptr<CFX_DIBitmap> m_pBitmap; }; +typedef CFX_SharedCopyOnWrite<CFX_DIBitmap> CFX_DIBitmapRef; + class CFX_FilteredDIB : public CFX_DIBSource { public: - template <typename T, typename... Args> - friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args); - + CFX_FilteredDIB(); ~CFX_FilteredDIB() override; + void LoadSrc(const CFX_DIBSource* pSrc, bool bAutoDropSrc = false); + virtual FXDIB_Format GetDestFormat() = 0; + virtual uint32_t* GetDestPalette() = 0; + virtual void TranslateScanline(const uint8_t* src_buf, std::vector<uint8_t>* dest_buf) const = 0; + virtual void TranslateDownSamples(uint8_t* dest_buf, const uint8_t* src_buf, int pixels, int Bpp) const = 0; - void LoadSrc(const CFX_RetainPtr<CFX_DIBSource>& pSrc); - protected: - CFX_FilteredDIB(); - // CFX_DIBSource const uint8_t* GetScanline(int line) const override; void DownSampleScanline(int line, @@ -434,7 +438,8 @@ class CFX_FilteredDIB : public CFX_DIBSource { int clip_left, int clip_width) const override; - CFX_RetainPtr<CFX_DIBSource> m_pSrc; + const CFX_DIBSource* m_pSrc; + bool m_bAutoDropSrc; mutable std::vector<uint8_t> m_Scanline; }; @@ -515,7 +520,7 @@ class CFX_BitmapComposer : public IFX_ScanlineComposer { CFX_BitmapComposer(); ~CFX_BitmapComposer() override; - void Compose(const CFX_RetainPtr<CFX_DIBitmap>& pDest, + void Compose(CFX_DIBitmap* pDest, const CFX_ClipRgn* pClipRgn, int bitmap_alpha, uint32_t mask_color, @@ -545,28 +550,21 @@ class CFX_BitmapComposer : public IFX_ScanlineComposer { const uint8_t* clip_scan, const uint8_t* src_extra_alpha = nullptr, uint8_t* dst_extra_alpha = nullptr); - void ComposeScanlineV(int line, - const uint8_t* scanline, - const uint8_t* scan_extra_alpha = nullptr); - - CFX_RetainPtr<CFX_DIBitmap> m_pBitmap; + CFX_DIBitmap* m_pBitmap; const CFX_ClipRgn* m_pClipRgn; FXDIB_Format m_SrcFormat; - int m_DestLeft; - int m_DestTop; - int m_DestWidth; - int m_DestHeight; - int m_BitmapAlpha; + int m_DestLeft, m_DestTop, m_DestWidth, m_DestHeight, m_BitmapAlpha; uint32_t m_MaskColor; - CFX_RetainPtr<CFX_DIBitmap> m_pClipMask; + const CFX_DIBitmap* m_pClipMask; CFX_ScanlineCompositor m_Compositor; - bool m_bVertical; - bool m_bFlipX; - bool m_bFlipY; + bool m_bVertical, m_bFlipX, m_bFlipY; int m_AlphaFlag; void* m_pIccTransform; bool m_bRgbByteOrder; int m_BlendType; + void ComposeScanlineV(int line, + const uint8_t* scanline, + const uint8_t* scan_extra_alpha = nullptr); uint8_t* m_pScanlineV; uint8_t* m_pClipScanV; uint8_t* m_pAddClipScan; @@ -587,18 +585,18 @@ class CFX_BitmapStorer : public IFX_ScanlineComposer { FXDIB_Format src_format, uint32_t* pSrcPalette) override; - CFX_RetainPtr<CFX_DIBitmap> GetBitmap() { return m_pBitmap; } - CFX_RetainPtr<CFX_DIBitmap> Detach(); - void Replace(CFX_RetainPtr<CFX_DIBitmap>&& pBitmap); + CFX_DIBitmap* GetBitmap() { return m_pBitmap.get(); } + std::unique_ptr<CFX_DIBitmap> Detach(); + void Replace(std::unique_ptr<CFX_DIBitmap> pBitmap); private: - CFX_RetainPtr<CFX_DIBitmap> m_pBitmap; + std::unique_ptr<CFX_DIBitmap> m_pBitmap; }; class CFX_ImageStretcher { public: CFX_ImageStretcher(IFX_ScanlineComposer* pDest, - const CFX_RetainPtr<CFX_DIBSource>& pSource, + const CFX_DIBSource* pSource, int dest_width, int dest_height, const FX_RECT& bitmap_rect, @@ -608,7 +606,7 @@ class CFX_ImageStretcher { bool Start(); bool Continue(IFX_Pause* pPause); - CFX_RetainPtr<CFX_DIBSource> source() { return m_pSource; } + const CFX_DIBSource* source() { return m_pSource; } private: bool StartQuickStretch(); @@ -617,7 +615,7 @@ class CFX_ImageStretcher { bool ContinueStretch(IFX_Pause* pPause); IFX_ScanlineComposer* const m_pDest; - CFX_RetainPtr<CFX_DIBSource> m_pSource; + const CFX_DIBSource* const m_pSource; std::unique_ptr<CStretchEngine> m_pStretchEngine; std::unique_ptr<uint8_t, FxFreeDeleter> m_pScanline; std::unique_ptr<uint8_t, FxFreeDeleter> m_pMaskScanline; @@ -634,7 +632,7 @@ class CFX_ImageStretcher { class CFX_ImageTransformer { public: - CFX_ImageTransformer(const CFX_RetainPtr<CFX_DIBSource>& pSrc, + CFX_ImageTransformer(const CFX_DIBSource* pSrc, const CFX_Matrix* pMatrix, int flags, const FX_RECT* pClip); @@ -644,10 +642,10 @@ class CFX_ImageTransformer { bool Continue(IFX_Pause* pPause); const FX_RECT& result() const { return m_result; } - CFX_RetainPtr<CFX_DIBitmap> DetachBitmap(); + std::unique_ptr<CFX_DIBitmap> DetachBitmap(); private: - const CFX_RetainPtr<CFX_DIBSource> m_pSrc; + const CFX_DIBSource* const m_pSrc; const CFX_Matrix* const m_pMatrix; const FX_RECT* const m_pClip; FX_RECT m_StretchClip; @@ -664,9 +662,9 @@ class CFX_ImageRenderer { CFX_ImageRenderer(); ~CFX_ImageRenderer(); - bool Start(const CFX_RetainPtr<CFX_DIBitmap>& pDevice, + bool Start(CFX_DIBitmap* pDevice, const CFX_ClipRgn* pClipRgn, - const CFX_RetainPtr<CFX_DIBSource>& pSource, + const CFX_DIBSource* pSource, int bitmap_alpha, uint32_t mask_color, const CFX_Matrix* pMatrix, @@ -679,7 +677,7 @@ class CFX_ImageRenderer { bool Continue(IFX_Pause* pPause); protected: - CFX_RetainPtr<CFX_DIBitmap> m_pDevice; + CFX_DIBitmap* m_pDevice; const CFX_ClipRgn* m_pClipRgn; int m_BitmapAlpha; uint32_t m_MaskColor; diff --git a/core/fxge/fx_font.h b/core/fxge/fx_font.h index 880b6751e8..79957ef506 100644 --- a/core/fxge/fx_font.h +++ b/core/fxge/fx_font.h @@ -222,19 +222,11 @@ class CFX_FontFaceInfo { class CFX_GlyphBitmap { public: - CFX_GlyphBitmap(); - ~CFX_GlyphBitmap(); - int m_Top; int m_Left; - CFX_RetainPtr<CFX_DIBitmap> m_pBitmap; + CFX_DIBitmap m_Bitmap; }; -inline CFX_GlyphBitmap::CFX_GlyphBitmap() - : m_pBitmap(pdfium::MakeRetain<CFX_DIBitmap>()) {} - -inline CFX_GlyphBitmap::~CFX_GlyphBitmap() {} - class FXTEXT_GLYPHPOS { public: FXTEXT_GLYPHPOS(); diff --git a/core/fxge/ge/cfx_cliprgn.cpp b/core/fxge/ge/cfx_cliprgn.cpp index 5193ce2944..ea3eb51f18 100644 --- a/core/fxge/ge/cfx_cliprgn.cpp +++ b/core/fxge/ge/cfx_cliprgn.cpp @@ -6,8 +6,6 @@ #include "core/fxge/ge/cfx_cliprgn.h" -#include <utility> - CFX_ClipRgn::CFX_ClipRgn(int width, int height) : m_Type(RectI), m_Box(0, 0, width, height) {} @@ -22,7 +20,7 @@ CFX_ClipRgn::~CFX_ClipRgn() {} void CFX_ClipRgn::Reset(const FX_RECT& rect) { m_Type = RectI; m_Box = rect; - m_Mask = nullptr; + m_Mask.SetNull(); } void CFX_ClipRgn::IntersectRect(const FX_RECT& rect) { @@ -38,7 +36,8 @@ void CFX_ClipRgn::IntersectRect(const FX_RECT& rect) { void CFX_ClipRgn::IntersectMaskRect(FX_RECT rect, FX_RECT mask_rect, - const CFX_RetainPtr<CFX_DIBitmap>& pMask) { + CFX_DIBitmapRef Mask) { + const CFX_DIBitmap* mask_dib = Mask.GetObject(); m_Type = MaskF; m_Box = rect; m_Box.Intersect(mask_rect); @@ -47,29 +46,28 @@ void CFX_ClipRgn::IntersectMaskRect(FX_RECT rect, return; } if (m_Box == mask_rect) { - m_Mask = pMask; + m_Mask = Mask; return; } - m_Mask = pdfium::MakeRetain<CFX_DIBitmap>(); - m_Mask->Create(m_Box.Width(), m_Box.Height(), FXDIB_8bppMask); + CFX_DIBitmap* new_dib = m_Mask.Emplace(); + new_dib->Create(m_Box.Width(), m_Box.Height(), FXDIB_8bppMask); for (int row = m_Box.top; row < m_Box.bottom; row++) { uint8_t* dest_scan = - m_Mask->GetBuffer() + m_Mask->GetPitch() * (row - m_Box.top); + new_dib->GetBuffer() + new_dib->GetPitch() * (row - m_Box.top); uint8_t* src_scan = - pMask->GetBuffer() + pMask->GetPitch() * (row - mask_rect.top); + mask_dib->GetBuffer() + mask_dib->GetPitch() * (row - mask_rect.top); for (int col = m_Box.left; col < m_Box.right; col++) dest_scan[col - m_Box.left] = src_scan[col - mask_rect.left]; } } -void CFX_ClipRgn::IntersectMaskF(int left, - int top, - const CFX_RetainPtr<CFX_DIBitmap>& pMask) { - ASSERT(pMask->GetFormat() == FXDIB_8bppMask); - FX_RECT mask_box(left, top, left + pMask->GetWidth(), - top + pMask->GetHeight()); +void CFX_ClipRgn::IntersectMaskF(int left, int top, CFX_DIBitmapRef Mask) { + const CFX_DIBitmap* mask_dib = Mask.GetObject(); + ASSERT(mask_dib->GetFormat() == FXDIB_8bppMask); + FX_RECT mask_box(left, top, left + mask_dib->GetWidth(), + top + mask_dib->GetHeight()); if (m_Type == RectI) { - IntersectMaskRect(m_Box, mask_box, pMask); + IntersectMaskRect(m_Box, mask_box, Mask); return; } if (m_Type == MaskF) { @@ -77,16 +75,19 @@ void CFX_ClipRgn::IntersectMaskF(int left, new_box.Intersect(mask_box); if (new_box.IsEmpty()) { m_Type = RectI; - m_Mask = nullptr; + m_Mask.SetNull(); m_Box = new_box; return; } - auto new_dib = pdfium::MakeRetain<CFX_DIBitmap>(); + CFX_DIBitmapRef new_mask; + CFX_DIBitmap* new_dib = new_mask.Emplace(); new_dib->Create(new_box.Width(), new_box.Height(), FXDIB_8bppMask); + const CFX_DIBitmap* old_dib = m_Mask.GetObject(); for (int row = new_box.top; row < new_box.bottom; row++) { uint8_t* old_scan = - m_Mask->GetBuffer() + (row - m_Box.top) * m_Mask->GetPitch(); - uint8_t* mask_scan = pMask->GetBuffer() + (row - top) * pMask->GetPitch(); + old_dib->GetBuffer() + (row - m_Box.top) * old_dib->GetPitch(); + uint8_t* mask_scan = + mask_dib->GetBuffer() + (row - top) * mask_dib->GetPitch(); uint8_t* new_scan = new_dib->GetBuffer() + (row - new_box.top) * new_dib->GetPitch(); for (int col = new_box.left; col < new_box.right; col++) { @@ -95,7 +96,7 @@ void CFX_ClipRgn::IntersectMaskF(int left, } } m_Box = new_box; - m_Mask = std::move(new_dib); + m_Mask = new_mask; return; } ASSERT(false); diff --git a/core/fxge/ge/cfx_cliprgn.h b/core/fxge/ge/cfx_cliprgn.h index ae12347288..f3fd5856b6 100644 --- a/core/fxge/ge/cfx_cliprgn.h +++ b/core/fxge/ge/cfx_cliprgn.h @@ -19,22 +19,18 @@ class CFX_ClipRgn { ClipType GetType() const { return m_Type; } const FX_RECT& GetBox() const { return m_Box; } - CFX_RetainPtr<CFX_DIBitmap> GetMask() const { return m_Mask; } + CFX_DIBitmapRef GetMask() const { return m_Mask; } void Reset(const FX_RECT& rect); void IntersectRect(const FX_RECT& rect); - void IntersectMaskF(int left, - int top, - const CFX_RetainPtr<CFX_DIBitmap>& Mask); + void IntersectMaskF(int left, int top, CFX_DIBitmapRef Mask); private: - void IntersectMaskRect(FX_RECT rect, - FX_RECT mask_box, - const CFX_RetainPtr<CFX_DIBitmap>& Mask); + void IntersectMaskRect(FX_RECT rect, FX_RECT mask_box, CFX_DIBitmapRef Mask); ClipType m_Type; FX_RECT m_Box; - CFX_RetainPtr<CFX_DIBitmap> m_Mask; + CFX_DIBitmapRef m_Mask; }; #endif // CORE_FXGE_GE_CFX_CLIPRGN_H_ diff --git a/core/fxge/ge/cfx_facecache.cpp b/core/fxge/ge/cfx_facecache.cpp index 4c44660426..3cdff44f8b 100644 --- a/core/fxge/ge/cfx_facecache.cpp +++ b/core/fxge/ge/cfx_facecache.cpp @@ -182,14 +182,14 @@ CFX_GlyphBitmap* CFX_FaceCache::RenderGlyph(const CFX_Font* pFont, return nullptr; int dib_width = bmwidth; CFX_GlyphBitmap* pGlyphBitmap = new CFX_GlyphBitmap; - pGlyphBitmap->m_pBitmap->Create( + pGlyphBitmap->m_Bitmap.Create( dib_width, bmheight, anti_alias == FXFT_RENDER_MODE_MONO ? FXDIB_1bppMask : FXDIB_8bppMask); pGlyphBitmap->m_Left = FXFT_Get_Glyph_BitmapLeft(m_Face); pGlyphBitmap->m_Top = FXFT_Get_Glyph_BitmapTop(m_Face); - int dest_pitch = pGlyphBitmap->m_pBitmap->GetPitch(); + int dest_pitch = pGlyphBitmap->m_Bitmap.GetPitch(); int src_pitch = FXFT_Get_Bitmap_Pitch(FXFT_Get_Glyph_Bitmap(m_Face)); - uint8_t* pDestBuf = pGlyphBitmap->m_pBitmap->GetBuffer(); + uint8_t* pDestBuf = pGlyphBitmap->m_Bitmap.GetBuffer(); uint8_t* pSrcBuf = (uint8_t*)FXFT_Get_Bitmap_Buffer(FXFT_Get_Glyph_Bitmap(m_Face)); if (anti_alias != FXFT_RENDER_MODE_MONO && diff --git a/core/fxge/ge/cfx_renderdevice.cpp b/core/fxge/ge/cfx_renderdevice.cpp index 782dbf3e2f..fab318373a 100644 --- a/core/fxge/ge/cfx_renderdevice.cpp +++ b/core/fxge/ge/cfx_renderdevice.cpp @@ -194,8 +194,8 @@ void SetAlpha(uint8_t* alpha) { void SetAlphaDoNothing(uint8_t* alpha) {} -void DrawNormalTextHelper(const CFX_RetainPtr<CFX_DIBitmap>& bitmap, - const CFX_RetainPtr<CFX_DIBitmap>& pGlyph, +void DrawNormalTextHelper(CFX_DIBitmap* bitmap, + const CFX_DIBitmap* pGlyph, int nrows, int left, int top, @@ -416,10 +416,9 @@ CFX_Matrix CFX_RenderDevice::GetCTM() const { return m_pDeviceDriver->GetCTM(); } -bool CFX_RenderDevice::CreateCompatibleBitmap( - const CFX_RetainPtr<CFX_DIBitmap>& pDIB, - int width, - int height) const { +bool CFX_RenderDevice::CreateCompatibleBitmap(CFX_DIBitmap* pDIB, + int width, + int height) const { if (m_RenderCaps & FXRC_CMYK_OUTPUT) { return pDIB->Create(width, height, m_RenderCaps & FXRC_ALPHA_OUTPUT ? FXDIB_Cmyka @@ -611,23 +610,21 @@ bool CFX_RenderDevice::DrawFillStrokePath(const CFX_PathData* pPathData, float fScaleX = FXSYS_fabs(ctm.a); float fScaleY = FXSYS_fabs(ctm.d); FX_RECT rect = bbox.GetOuterRect(); - auto bitmap = pdfium::MakeRetain<CFX_DIBitmap>(); - auto Backdrop = pdfium::MakeRetain<CFX_DIBitmap>(); - if (!CreateCompatibleBitmap(bitmap, FXSYS_round(rect.Width() * fScaleX), + CFX_DIBitmap bitmap, Backdrop; + if (!CreateCompatibleBitmap(&bitmap, FXSYS_round(rect.Width() * fScaleX), FXSYS_round(rect.Height() * fScaleY))) { return false; } - if (bitmap->HasAlpha()) { - bitmap->Clear(0); - Backdrop->Copy(bitmap); + if (bitmap.HasAlpha()) { + bitmap.Clear(0); + Backdrop.Copy(&bitmap); } else { - if (!m_pDeviceDriver->GetDIBits(bitmap, rect.left, rect.top)) + if (!m_pDeviceDriver->GetDIBits(&bitmap, rect.left, rect.top)) return false; - Backdrop->Copy(bitmap); + Backdrop.Copy(&bitmap); } CFX_FxgeDevice bitmap_device; - bitmap_device.Attach(bitmap, false, Backdrop, true); - + bitmap_device.Attach(&bitmap, false, &Backdrop, true); CFX_Matrix matrix; if (pObject2Device) matrix = *pObject2Device; @@ -643,7 +640,7 @@ bool CFX_RenderDevice::DrawFillStrokePath(const CFX_PathData* pPathData, #endif FX_RECT src_rect(0, 0, FXSYS_round(rect.Width() * fScaleX), FXSYS_round(rect.Height() * fScaleY)); - return m_pDeviceDriver->SetDIBits(bitmap, 0, &src_rect, rect.left, rect.top, + return m_pDeviceDriver->SetDIBits(&bitmap, 0, &src_rect, rect.left, rect.top, FXDIB_BLEND_NORMAL); } @@ -664,19 +661,19 @@ bool CFX_RenderDevice::FillRectWithBlend(const FX_RECT* pRect, if (!(m_RenderCaps & FXRC_GET_BITS)) return false; - auto bitmap = pdfium::MakeRetain<CFX_DIBitmap>(); - if (!CreateCompatibleBitmap(bitmap, pRect->Width(), pRect->Height())) + CFX_DIBitmap bitmap; + if (!CreateCompatibleBitmap(&bitmap, pRect->Width(), pRect->Height())) return false; - if (!m_pDeviceDriver->GetDIBits(bitmap, pRect->left, pRect->top)) + if (!m_pDeviceDriver->GetDIBits(&bitmap, pRect->left, pRect->top)) return false; - if (!bitmap->CompositeRect(0, 0, pRect->Width(), pRect->Height(), fill_color, - 0, nullptr)) { + if (!bitmap.CompositeRect(0, 0, pRect->Width(), pRect->Height(), fill_color, + 0, nullptr)) { return false; } FX_RECT src_rect(0, 0, pRect->Width(), pRect->Height()); - m_pDeviceDriver->SetDIBits(bitmap, 0, &src_rect, pRect->left, pRect->top, + m_pDeviceDriver->SetDIBits(&bitmap, 0, &src_rect, pRect->left, pRect->top, FXDIB_BLEND_NORMAL); return true; } @@ -700,23 +697,20 @@ bool CFX_RenderDevice::DrawCosmeticLine(float x1, fill_mode, blend_type); } -bool CFX_RenderDevice::GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, - int left, - int top) { +bool CFX_RenderDevice::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) { if (!(m_RenderCaps & FXRC_GET_BITS)) return false; return m_pDeviceDriver->GetDIBits(pBitmap, left, top); } -CFX_RetainPtr<CFX_DIBitmap> CFX_RenderDevice::GetBackDrop() { +CFX_DIBitmap* CFX_RenderDevice::GetBackDrop() { return m_pDeviceDriver->GetBackDrop(); } -bool CFX_RenderDevice::SetDIBitsWithBlend( - const CFX_RetainPtr<CFX_DIBSource>& pBitmap, - int left, - int top, - int blend_mode) { +bool CFX_RenderDevice::SetDIBitsWithBlend(const CFX_DIBSource* pBitmap, + int left, + int top, + int blend_mode) { ASSERT(!pBitmap->IsAlphaMask()); CFX_Matrix ctm = GetCTM(); float fScaleX = FXSYS_fabs(ctm.a); @@ -727,7 +721,6 @@ bool CFX_RenderDevice::SetDIBitsWithBlend( dest_rect.Intersect(m_ClipBox); if (dest_rect.IsEmpty()) return true; - FX_RECT src_rect(dest_rect.left - left, dest_rect.top - top, dest_rect.left - left + dest_rect.Width(), dest_rect.top - top + dest_rect.Height()); @@ -739,26 +732,25 @@ bool CFX_RenderDevice::SetDIBitsWithBlend( (pBitmap->HasAlpha() && !(m_RenderCaps & FXRC_ALPHA_IMAGE))) { if (!(m_RenderCaps & FXRC_GET_BITS)) return false; - int bg_pixel_width = FXSYS_round(dest_rect.Width() * fScaleX); int bg_pixel_height = FXSYS_round(dest_rect.Height() * fScaleY); - auto background = pdfium::MakeRetain<CFX_DIBitmap>(); - if (!background->Create( + CFX_DIBitmap background; + if (!background.Create( bg_pixel_width, bg_pixel_height, (m_RenderCaps & FXRC_CMYK_OUTPUT) ? FXDIB_Cmyk : FXDIB_Rgb32)) { return false; } - if (!m_pDeviceDriver->GetDIBits(background, dest_rect.left, + if (!m_pDeviceDriver->GetDIBits(&background, dest_rect.left, dest_rect.top)) { return false; } - if (!background->CompositeBitmap(0, 0, bg_pixel_width, bg_pixel_height, - pBitmap, src_rect.left, src_rect.top, - blend_mode, nullptr, false, nullptr)) { + if (!background.CompositeBitmap(0, 0, bg_pixel_width, bg_pixel_height, + pBitmap, src_rect.left, src_rect.top, + blend_mode, nullptr, false, nullptr)) { return false; } FX_RECT rect(0, 0, bg_pixel_width, bg_pixel_height); - return m_pDeviceDriver->SetDIBits(background, 0, &rect, dest_rect.left, + return m_pDeviceDriver->SetDIBits(&background, 0, &rect, dest_rect.left, dest_rect.top, FXDIB_BLEND_NORMAL); } return m_pDeviceDriver->SetDIBits(pBitmap, 0, &src_rect, dest_rect.left, @@ -766,7 +758,7 @@ bool CFX_RenderDevice::SetDIBitsWithBlend( } bool CFX_RenderDevice::StretchDIBitsWithFlagsAndBlend( - const CFX_RetainPtr<CFX_DIBSource>& pBitmap, + const CFX_DIBSource* pBitmap, int left, int top, int dest_width, @@ -783,7 +775,7 @@ bool CFX_RenderDevice::StretchDIBitsWithFlagsAndBlend( blend_mode); } -bool CFX_RenderDevice::SetBitMask(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, +bool CFX_RenderDevice::SetBitMask(const CFX_DIBSource* pBitmap, int left, int top, uint32_t argb) { @@ -792,25 +784,23 @@ bool CFX_RenderDevice::SetBitMask(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, FXDIB_BLEND_NORMAL); } -bool CFX_RenderDevice::StretchBitMask( - const CFX_RetainPtr<CFX_DIBSource>& pBitmap, - int left, - int top, - int dest_width, - int dest_height, - uint32_t color) { +bool CFX_RenderDevice::StretchBitMask(const CFX_DIBSource* pBitmap, + int left, + int top, + int dest_width, + int dest_height, + uint32_t color) { return StretchBitMaskWithFlags(pBitmap, left, top, dest_width, dest_height, color, 0); } -bool CFX_RenderDevice::StretchBitMaskWithFlags( - const CFX_RetainPtr<CFX_DIBSource>& pBitmap, - int left, - int top, - int dest_width, - int dest_height, - uint32_t argb, - uint32_t flags) { +bool CFX_RenderDevice::StretchBitMaskWithFlags(const CFX_DIBSource* pBitmap, + int left, + int top, + int dest_width, + int dest_height, + uint32_t argb, + uint32_t flags) { FX_RECT dest_rect(left, top, left + dest_width, top + dest_height); FX_RECT clip_box = m_ClipBox; clip_box.Intersect(dest_rect); @@ -819,14 +809,13 @@ bool CFX_RenderDevice::StretchBitMaskWithFlags( FXDIB_BLEND_NORMAL); } -bool CFX_RenderDevice::StartDIBitsWithBlend( - const CFX_RetainPtr<CFX_DIBSource>& pBitmap, - int bitmap_alpha, - uint32_t argb, - const CFX_Matrix* pMatrix, - uint32_t flags, - void*& handle, - int blend_mode) { +bool CFX_RenderDevice::StartDIBitsWithBlend(const CFX_DIBSource* pBitmap, + int bitmap_alpha, + uint32_t argb, + const CFX_Matrix* pMatrix, + uint32_t flags, + void*& handle, + int blend_mode) { return m_pDeviceDriver->StartDIBits(pBitmap, bitmap_alpha, argb, pMatrix, flags, handle, blend_mode); } @@ -844,13 +833,12 @@ void CFX_RenderDevice::DebugVerifyBitmapIsPreMultiplied() const { SkASSERT(0); } -bool CFX_RenderDevice::SetBitsWithMask( - const CFX_RetainPtr<CFX_DIBSource>& pBitmap, - const CFX_RetainPtr<CFX_DIBSource>& pMask, - int left, - int top, - int bitmap_alpha, - int blend_type) { +bool CFX_RenderDevice::SetBitsWithMask(const CFX_DIBSource* pBitmap, + const CFX_DIBSource* pMask, + int left, + int top, + int bitmap_alpha, + int blend_type) { return m_pDeviceDriver->SetBitsWithMask(pBitmap, pMask, left, top, bitmap_alpha, blend_type); } @@ -976,43 +964,42 @@ bool CFX_RenderDevice::DrawNormalText(int nChars, bmp_rect.Intersect(m_ClipBox); if (bmp_rect.IsEmpty()) return true; - int pixel_width = FXSYS_round(bmp_rect.Width() * scale_x); int pixel_height = FXSYS_round(bmp_rect.Height() * scale_y); int pixel_left = FXSYS_round(bmp_rect.left * scale_x); int pixel_top = FXSYS_round(bmp_rect.top * scale_y); if (anti_alias == FXFT_RENDER_MODE_MONO) { - auto bitmap = pdfium::MakeRetain<CFX_DIBitmap>(); - if (!bitmap->Create(pixel_width, pixel_height, FXDIB_1bppMask)) + CFX_DIBitmap bitmap; + if (!bitmap.Create(pixel_width, pixel_height, FXDIB_1bppMask)) return false; - bitmap->Clear(0); + bitmap.Clear(0); for (const FXTEXT_GLYPHPOS& glyph : glyphs) { if (!glyph.m_pGlyph) continue; - CFX_RetainPtr<CFX_DIBitmap> pGlyph = glyph.m_pGlyph->m_pBitmap; - bitmap->TransferBitmap( + const CFX_DIBitmap* pGlyph = &glyph.m_pGlyph->m_Bitmap; + bitmap.TransferBitmap( glyph.m_Origin.x + glyph.m_pGlyph->m_Left - pixel_left, glyph.m_Origin.y - glyph.m_pGlyph->m_Top - pixel_top, pGlyph->GetWidth(), pGlyph->GetHeight(), pGlyph, 0, 0); } - return SetBitMask(bitmap, bmp_rect.left, bmp_rect.top, fill_color); + return SetBitMask(&bitmap, bmp_rect.left, bmp_rect.top, fill_color); } - auto bitmap = pdfium::MakeRetain<CFX_DIBitmap>(); + CFX_DIBitmap bitmap; if (m_bpp == 8) { - if (!bitmap->Create(pixel_width, pixel_height, FXDIB_8bppMask)) + if (!bitmap.Create(pixel_width, pixel_height, FXDIB_8bppMask)) return false; } else { - if (!CreateCompatibleBitmap(bitmap, pixel_width, pixel_height)) + if (!CreateCompatibleBitmap(&bitmap, pixel_width, pixel_height)) return false; } - if (!bitmap->HasAlpha() && !bitmap->IsAlphaMask()) { - bitmap->Clear(0xFFFFFFFF); - if (!GetDIBits(bitmap, bmp_rect.left, bmp_rect.top)) + if (!bitmap.HasAlpha() && !bitmap.IsAlphaMask()) { + bitmap.Clear(0xFFFFFFFF); + if (!GetDIBits(&bitmap, bmp_rect.left, bmp_rect.top)) return false; } else { - bitmap->Clear(0); - if (bitmap->m_pAlphaMask) - bitmap->m_pAlphaMask->Clear(0); + bitmap.Clear(0); + if (bitmap.m_pAlphaMask) + bitmap.m_pAlphaMask->Clear(0); } int dest_width = pixel_width; int a = 0; @@ -1038,14 +1025,14 @@ bool CFX_RenderDevice::DrawNormalText(int nChars, if (!top.IsValid()) return false; - CFX_RetainPtr<CFX_DIBitmap> pGlyph = glyph.m_pGlyph->m_pBitmap; + const CFX_DIBitmap* pGlyph = &glyph.m_pGlyph->m_Bitmap; int ncols = pGlyph->GetWidth(); int nrows = pGlyph->GetHeight(); if (anti_alias == FXFT_RENDER_MODE_NORMAL) { - if (!bitmap->CompositeMask(left.ValueOrDie(), top.ValueOrDie(), ncols, - nrows, pGlyph, fill_color, 0, 0, - FXDIB_BLEND_NORMAL, nullptr, false, 0, - nullptr)) { + if (!bitmap.CompositeMask(left.ValueOrDie(), top.ValueOrDie(), ncols, + nrows, pGlyph, fill_color, 0, 0, + FXDIB_BLEND_NORMAL, nullptr, false, 0, + nullptr)) { return false; } continue; @@ -1065,14 +1052,14 @@ bool CFX_RenderDevice::DrawNormalText(int nChars, if (start_col >= end_col) continue; - DrawNormalTextHelper(bitmap, pGlyph, nrows, left.ValueOrDie(), + DrawNormalTextHelper(&bitmap, pGlyph, nrows, left.ValueOrDie(), top.ValueOrDie(), start_col, end_col, bNormal, bBGRStripe, x_subpixel, a, r, g, b); } - if (bitmap->IsAlphaMask()) - SetBitMask(bitmap, bmp_rect.left, bmp_rect.top, fill_color); + if (bitmap.IsAlphaMask()) + SetBitMask(&bitmap, bmp_rect.left, bmp_rect.top, fill_color); else - SetDIBits(bitmap, bmp_rect.left, bmp_rect.top); + SetDIBits(&bitmap, bmp_rect.left, bmp_rect.top); return true; } diff --git a/core/fxge/ge/fx_ge_text.cpp b/core/fxge/ge/fx_ge_text.cpp index b451b543fc..f3dea9178d 100644 --- a/core/fxge/ge/fx_ge_text.cpp +++ b/core/fxge/ge/fx_ge_text.cpp @@ -59,7 +59,7 @@ FX_RECT FXGE_GetGlyphsBBox(const std::vector<FXTEXT_GLYPHPOS>& glyphs, if (!char_left.IsValid()) continue; - FX_SAFE_INT32 char_width = pGlyph->m_pBitmap->GetWidth(); + FX_SAFE_INT32 char_width = pGlyph->m_Bitmap.GetWidth(); char_width /= retinaScaleX; if (anti_alias == FXFT_RENDER_MODE_LCD) char_width /= 3; @@ -75,7 +75,7 @@ FX_RECT FXGE_GetGlyphsBBox(const std::vector<FXTEXT_GLYPHPOS>& glyphs, if (!char_top.IsValid()) continue; - FX_SAFE_INT32 char_height = pGlyph->m_pBitmap->GetHeight(); + FX_SAFE_INT32 char_height = pGlyph->m_Bitmap.GetHeight(); char_height /= retinaScaleY; if (!char_height.IsValid()) continue; diff --git a/core/fxge/ifx_renderdevicedriver.cpp b/core/fxge/ifx_renderdevicedriver.cpp index 35cd4e221d..44ce833d99 100644 --- a/core/fxge/ifx_renderdevicedriver.cpp +++ b/core/fxge/ifx_renderdevicedriver.cpp @@ -48,15 +48,14 @@ bool IFX_RenderDeviceDriver::DrawCosmeticLine(float x1, return false; } -bool IFX_RenderDeviceDriver::GetDIBits( - const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, - int left, - int top) { +bool IFX_RenderDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, + int left, + int top) { return false; } -CFX_RetainPtr<CFX_DIBitmap> IFX_RenderDeviceDriver::GetBackDrop() { - return CFX_RetainPtr<CFX_DIBitmap>(); +CFX_DIBitmap* IFX_RenderDeviceDriver::GetBackDrop() { + return nullptr; } bool IFX_RenderDeviceDriver::ContinueDIBits(void* handle, IFX_Pause* pPause) { @@ -92,13 +91,12 @@ bool IFX_RenderDeviceDriver::DrawShading(const CPDF_ShadingPattern* pPattern, return false; } -bool IFX_RenderDeviceDriver::SetBitsWithMask( - const CFX_RetainPtr<CFX_DIBSource>& pBitmap, - const CFX_RetainPtr<CFX_DIBSource>& pMask, - int left, - int top, - int bitmap_alpha, - int blend_type) { +bool IFX_RenderDeviceDriver::SetBitsWithMask(const CFX_DIBSource* pBitmap, + const CFX_DIBSource* pMask, + int left, + int top, + int bitmap_alpha, + int blend_type) { return false; } diff --git a/core/fxge/ifx_renderdevicedriver.h b/core/fxge/ifx_renderdevicedriver.h index 87e38fa5f0..3dd4730f9b 100644 --- a/core/fxge/ifx_renderdevicedriver.h +++ b/core/fxge/ifx_renderdevicedriver.h @@ -7,7 +7,6 @@ #ifndef CORE_FXGE_IFX_RENDERDEVICEDRIVER_H_ #define CORE_FXGE_IFX_RENDERDEVICEDRIVER_H_ -#include "core/fxcrt/cfx_retain_ptr.h" #include "core/fxcrt/fx_system.h" class CFX_DIBitmap; @@ -58,17 +57,15 @@ class IFX_RenderDeviceDriver { int blend_type); virtual bool GetClipBox(FX_RECT* pRect) = 0; - virtual bool GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, - int left, - int top); - virtual CFX_RetainPtr<CFX_DIBitmap> GetBackDrop(); - virtual bool SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, + virtual bool GetDIBits(CFX_DIBitmap* pBitmap, int left, int top); + virtual CFX_DIBitmap* GetBackDrop(); + virtual bool SetDIBits(const CFX_DIBSource* pBitmap, uint32_t color, const FX_RECT* pSrcRect, int dest_left, int dest_top, int blend_type) = 0; - virtual bool StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, + virtual bool StretchDIBits(const CFX_DIBSource* pBitmap, uint32_t color, int dest_left, int dest_top, @@ -77,7 +74,7 @@ class IFX_RenderDeviceDriver { const FX_RECT* pClipRect, uint32_t flags, int blend_type) = 0; - virtual bool StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, + virtual bool StartDIBits(const CFX_DIBSource* pBitmap, int bitmap_alpha, uint32_t color, const CFX_Matrix* pMatrix, @@ -100,8 +97,8 @@ class IFX_RenderDeviceDriver { const FX_RECT& clip_rect, int alpha, bool bAlphaMode); - virtual bool SetBitsWithMask(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, - const CFX_RetainPtr<CFX_DIBSource>& pMask, + virtual bool SetBitsWithMask(const CFX_DIBSource* pBitmap, + const CFX_DIBSource* pMask, int left, int top, int bitmap_alpha, diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp index d3ea86b92e..a9cf7e67c7 100644 --- a/core/fxge/skia/fx_skia_device.cpp +++ b/core/fxge/skia/fx_skia_device.cpp @@ -48,12 +48,12 @@ namespace { #ifdef _SKIA_SUPPORT_PATHS_ -void RgbByteOrderTransferBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, +void RgbByteOrderTransferBitmap(CFX_DIBitmap* pBitmap, int dest_left, int dest_top, int width, int height, - const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap, + const CFX_DIBSource* pSrcBitmap, int src_left, int src_top) { if (!pBitmap) @@ -247,8 +247,8 @@ void DebugDrawSkiaClipPath(SkCanvas* canvas, const SkPath& path) {} #endif // DRAW_SKIA_CLIP #ifdef _SKIA_SUPPORT_ -static void DebugValidate(const CFX_RetainPtr<CFX_DIBitmap>& bitmap, - const CFX_RetainPtr<CFX_DIBitmap>& device) { +static void DebugValidate(const CFX_DIBitmap* bitmap, + const CFX_DIBitmap* device) { if (bitmap) { SkASSERT(bitmap->GetBPP() == 8 || bitmap->GetBPP() == 32); if (bitmap->GetBPP() == 32) { @@ -547,7 +547,7 @@ void SetBitmapPaint(bool isAlphaMask, paint->setAlpha(bitmap_alpha); } -bool Upsample(const CFX_RetainPtr<CFX_DIBSource>& pSource, +bool Upsample(const CFX_DIBSource* pSource, std::unique_ptr<uint8_t, FxFreeDeleter>& dst8Storage, std::unique_ptr<uint32_t, FxFreeDeleter>& dst32Storage, SkColorTable** ctPtr, @@ -1197,11 +1197,10 @@ void CFX_SkiaDeviceDriver::PaintStroke(SkPaint* spaint, spaint->setStrokeJoin(join); } -CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver( - const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, - bool bRgbByteOrder, - const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice, - bool bGroupKnockout) +CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(CFX_DIBitmap* pBitmap, + bool bRgbByteOrder, + CFX_DIBitmap* pOriDevice, + bool bGroupKnockout) : m_pBitmap(pBitmap), m_pOriDevice(pOriDevice), m_pRecorder(nullptr), @@ -1395,7 +1394,8 @@ void CFX_SkiaDeviceDriver::SetClipMask(const FX_RECT& clipBox, FX_RECT path_rect(clipBox.left, clipBox.top, clipBox.right + 1, clipBox.bottom + 1); path_rect.Intersect(m_pClipRgn->GetBox()); - auto pThisLayer = pdfium::MakeRetain<CFX_DIBitmap>(); + CFX_DIBitmapRef mask; + CFX_DIBitmap* pThisLayer = mask.Emplace(); pThisLayer->Create(path_rect.Width(), path_rect.Height(), FXDIB_8bppMask); pThisLayer->Clear(0); @@ -1405,14 +1405,15 @@ void CFX_SkiaDeviceDriver::SetClipMask(const FX_RECT& clipBox, SkBitmap bitmap; bitmap.installPixels(imageInfo, pThisLayer->GetBuffer(), pThisLayer->GetPitch(), nullptr, nullptr, nullptr); - auto canvas = pdfium::MakeUnique<SkCanvas>(bitmap); + SkCanvas* canvas = new SkCanvas(bitmap); canvas->translate( -path_rect.left, -path_rect.top); // FIXME(caryclark) wrong sign(s)? upside down? SkPaint paint; paint.setAntiAlias((m_FillFlags & FXFILL_NOPATHSMOOTH) == 0); canvas->drawPath(path, paint); - m_pClipRgn->IntersectMaskF(path_rect.left, path_rect.top, pThisLayer); + m_pClipRgn->IntersectMaskF(path_rect.left, path_rect.top, mask); + delete canvas; } #endif // _SKIA_SUPPORT_PATHS_ @@ -1797,9 +1798,7 @@ bool CFX_SkiaDeviceDriver::GetClipBox(FX_RECT* pRect) { return true; } -bool CFX_SkiaDeviceDriver::GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, - int left, - int top) { +bool CFX_SkiaDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) { if (!m_pBitmap) return true; uint8_t* srcBuffer = m_pBitmap->GetBuffer(); @@ -1836,7 +1835,7 @@ bool CFX_SkiaDeviceDriver::GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, m_pBitmap->UnPreMultiply(); FX_RECT rect(left, top, left + pBitmap->GetWidth(), top + pBitmap->GetHeight()); - CFX_RetainPtr<CFX_DIBitmap> pBack; + std::unique_ptr<CFX_DIBitmap> pBack; if (m_pOriDevice) { pBack = m_pOriDevice->Clone(&rect); if (!pBack) @@ -1864,17 +1863,16 @@ bool CFX_SkiaDeviceDriver::GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, #endif // _SKIA_SUPPORT_PATHS_ } -CFX_RetainPtr<CFX_DIBitmap> CFX_SkiaDeviceDriver::GetBackDrop() { +CFX_DIBitmap* CFX_SkiaDeviceDriver::GetBackDrop() { return m_pOriDevice; } -bool CFX_SkiaDeviceDriver::SetDIBits( - const CFX_RetainPtr<CFX_DIBSource>& pBitmap, - uint32_t argb, - const FX_RECT* pSrcRect, - int left, - int top, - int blend_type) { +bool CFX_SkiaDeviceDriver::SetDIBits(const CFX_DIBSource* pBitmap, + uint32_t argb, + const FX_RECT* pSrcRect, + int left, + int top, + int blend_type) { if (!m_pBitmap || !m_pBitmap->GetBuffer()) return true; @@ -1899,16 +1897,15 @@ bool CFX_SkiaDeviceDriver::SetDIBits( #endif // _SKIA_SUPPORT_PATHS_ } -bool CFX_SkiaDeviceDriver::StretchDIBits( - const CFX_RetainPtr<CFX_DIBSource>& pSource, - uint32_t argb, - int dest_left, - int dest_top, - int dest_width, - int dest_height, - const FX_RECT* pClipRect, - uint32_t flags, - int blend_type) { +bool CFX_SkiaDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource, + uint32_t argb, + int dest_left, + int dest_top, + int dest_width, + int dest_height, + const FX_RECT* pClipRect, + uint32_t flags, + int blend_type) { #ifdef _SKIA_SUPPORT_ m_pCache->FlushForDraw(); if (!m_pBitmap->GetBuffer()) @@ -1951,14 +1948,13 @@ bool CFX_SkiaDeviceDriver::StretchDIBits( #endif // _SKIA_SUPPORT_PATHS_ } -bool CFX_SkiaDeviceDriver::StartDIBits( - const CFX_RetainPtr<CFX_DIBSource>& pSource, - int bitmap_alpha, - uint32_t argb, - const CFX_Matrix* pMatrix, - uint32_t render_flags, - void*& handle, - int blend_type) { +bool CFX_SkiaDeviceDriver::StartDIBits(const CFX_DIBSource* pSource, + int bitmap_alpha, + uint32_t argb, + const CFX_Matrix* pMatrix, + uint32_t render_flags, + void*& handle, + int blend_type) { #ifdef _SKIA_SUPPORT_ m_pCache->FlushForDraw(); DebugValidate(m_pBitmap, m_pOriDevice); @@ -2039,8 +2035,7 @@ bool CFX_SkiaDeviceDriver::ContinueDIBits(void* handle, IFX_Pause* pPause) { } #if defined _SKIA_SUPPORT_ -void CFX_SkiaDeviceDriver::PreMultiply( - const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap) { +void CFX_SkiaDeviceDriver::PreMultiply(CFX_DIBitmap* pDIBitmap) { pDIBitmap->PreMultiply(); } #endif // _SKIA_SUPPORT_ @@ -2096,12 +2091,11 @@ void CFX_DIBitmap::UnPreMultiply() { #endif // _SKIA_SUPPORT_PATHS_ #ifdef _SKIA_SUPPORT_ -bool CFX_SkiaDeviceDriver::DrawBitsWithMask( - const CFX_RetainPtr<CFX_DIBSource>& pSource, - const CFX_RetainPtr<CFX_DIBSource>& pMask, - int bitmap_alpha, - const CFX_Matrix* pMatrix, - int blend_type) { +bool CFX_SkiaDeviceDriver::DrawBitsWithMask(const CFX_DIBSource* pSource, + const CFX_DIBSource* pMask, + int bitmap_alpha, + const CFX_Matrix* pMatrix, + int blend_type) { DebugValidate(m_pBitmap, m_pOriDevice); SkColorTable* srcCt = nullptr; SkColorTable* maskCt = nullptr; @@ -2141,13 +2135,12 @@ bool CFX_SkiaDeviceDriver::DrawBitsWithMask( return true; } -bool CFX_SkiaDeviceDriver::SetBitsWithMask( - const CFX_RetainPtr<CFX_DIBSource>& pBitmap, - const CFX_RetainPtr<CFX_DIBSource>& pMask, - int dest_left, - int dest_top, - int bitmap_alpha, - int blend_type) { +bool CFX_SkiaDeviceDriver::SetBitsWithMask(const CFX_DIBSource* pBitmap, + const CFX_DIBSource* pMask, + int dest_left, + int dest_top, + int bitmap_alpha, + int blend_type) { if (!m_pBitmap || !m_pBitmap->GetBuffer()) return true; CFX_Matrix m(pBitmap->GetWidth(), 0, 0, -pBitmap->GetHeight(), dest_left, @@ -2174,7 +2167,9 @@ void CFX_SkiaDeviceDriver::DebugVerifyBitmapIsPreMultiplied() const { } #endif // _SKIA_SUPPORT_ -CFX_FxgeDevice::CFX_FxgeDevice() {} +CFX_FxgeDevice::CFX_FxgeDevice() { + m_bOwnedBitmap = false; +} #ifdef _SKIA_SUPPORT_ void CFX_FxgeDevice::Clear(uint32_t color) { @@ -2190,9 +2185,9 @@ SkPictureRecorder* CFX_FxgeDevice::CreateRecorder(int size_x, int size_y) { } #endif // _SKIA_SUPPORT_ -bool CFX_FxgeDevice::Attach(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, +bool CFX_FxgeDevice::Attach(CFX_DIBitmap* pBitmap, bool bRgbByteOrder, - const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice, + CFX_DIBitmap* pOriDevice, bool bGroupKnockout) { if (!pBitmap) return false; @@ -2214,9 +2209,11 @@ bool CFX_FxgeDevice::AttachRecorder(SkPictureRecorder* recorder) { bool CFX_FxgeDevice::Create(int width, int height, FXDIB_Format format, - const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice) { - auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>(); + CFX_DIBitmap* pOriDevice) { + m_bOwnedBitmap = true; + CFX_DIBitmap* pBitmap = new CFX_DIBitmap; if (!pBitmap->Create(width, height, format)) { + delete pBitmap; return false; } SetBitmap(pBitmap); @@ -2227,6 +2224,9 @@ bool CFX_FxgeDevice::Create(int width, CFX_FxgeDevice::~CFX_FxgeDevice() { Flush(); + // call destructor of CFX_RenderDevice / CFX_SkiaDeviceDriver immediately + if (m_bOwnedBitmap && GetBitmap()) + delete GetBitmap(); } #ifdef _SKIA_SUPPORT_ @@ -2239,13 +2239,12 @@ void CFX_FxgeDevice::DebugVerifyBitmapIsPreMultiplied() const { #endif // SK_DEBUG } -bool CFX_FxgeDevice::SetBitsWithMask( - const CFX_RetainPtr<CFX_DIBSource>& pBitmap, - const CFX_RetainPtr<CFX_DIBSource>& pMask, - int left, - int top, - int bitmap_alpha, - int blend_type) { +bool CFX_FxgeDevice::SetBitsWithMask(const CFX_DIBSource* pBitmap, + const CFX_DIBSource* pMask, + int left, + int top, + int bitmap_alpha, + int blend_type) { CFX_SkiaDeviceDriver* skDriver = static_cast<CFX_SkiaDeviceDriver*>(GetDeviceDriver()); if (skDriver) @@ -2285,10 +2284,10 @@ class CFX_Renderer { uint32_t m_Color; bool m_bFullCover; bool m_bRgbByteOrder; - const CFX_RetainPtr<CFX_DIBitmap>& m_pOriDevice; + CFX_DIBitmap* m_pOriDevice; FX_RECT m_ClipBox; - const CFX_RetainPtr<CFX_DIBitmap>& m_pClipMask; - const CFX_RetainPtr<CFX_DIBitmap>& m_pDevice; + const CFX_DIBitmap* m_pClipMask; + CFX_DIBitmap* m_pDevice; const CFX_ClipRgn* m_pClipRgn; void (CFX_Renderer::*composite_span)(uint8_t*, int, @@ -2927,7 +2926,7 @@ class CFX_Renderer { } uint8_t* dest_scan = m_pDevice->GetBuffer() + m_pDevice->GetPitch() * y; uint8_t* dest_scan_extra_alpha = nullptr; - CFX_RetainPtr<CFX_DIBitmap> pAlphaMask = m_pDevice->m_pAlphaMask; + CFX_DIBitmap* pAlphaMask = m_pDevice->m_pAlphaMask; if (pAlphaMask) { dest_scan_extra_alpha = pAlphaMask->GetBuffer() + pAlphaMask->GetPitch() * y; @@ -2976,8 +2975,8 @@ class CFX_Renderer { } } - bool Init(const CFX_RetainPtr<CFX_DIBitmap>& pDevice, - const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice, + bool Init(CFX_DIBitmap* pDevice, + CFX_DIBitmap* pOriDevice, const CFX_ClipRgn* pClipRgn, uint32_t color, bool bFullCover, diff --git a/core/fxge/skia/fx_skia_device.h b/core/fxge/skia/fx_skia_device.h index 9b5e4b06fa..494e6e1c44 100644 --- a/core/fxge/skia/fx_skia_device.h +++ b/core/fxge/skia/fx_skia_device.h @@ -24,9 +24,9 @@ struct SkIRect; class CFX_SkiaDeviceDriver : public IFX_RenderDeviceDriver { public: - CFX_SkiaDeviceDriver(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, + CFX_SkiaDeviceDriver(CFX_DIBitmap* pBitmap, bool bRgbByteOrder, - const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice, + CFX_DIBitmap* pOriDevice, bool bGroupKnockout); #ifdef _SKIA_SUPPORT_ explicit CFX_SkiaDeviceDriver(SkPictureRecorder* recorder); @@ -79,21 +79,19 @@ class CFX_SkiaDeviceDriver : public IFX_RenderDeviceDriver { bool GetClipBox(FX_RECT* pRect) override; /** Load device buffer into a DIB */ - bool GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, - int left, - int top) override; + bool GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) override; - CFX_RetainPtr<CFX_DIBitmap> GetBackDrop() override; + CFX_DIBitmap* GetBackDrop() override; - bool SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, + bool SetDIBits(const CFX_DIBSource* pBitmap, uint32_t color, const FX_RECT* pSrcRect, int dest_left, int dest_top, int blend_type) override; #ifdef _SKIA_SUPPORT_ - bool SetBitsWithMask(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, - const CFX_RetainPtr<CFX_DIBSource>& pMask, + bool SetBitsWithMask(const CFX_DIBSource* pBitmap, + const CFX_DIBSource* pMask, int dest_left, int dest_top, int bitmap_alpha, @@ -104,7 +102,7 @@ class CFX_SkiaDeviceDriver : public IFX_RenderDeviceDriver { void SetClipMask(const FX_RECT& clipBox, const SkPath& skClipPath); #endif - bool StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, + bool StretchDIBits(const CFX_DIBSource* pBitmap, uint32_t color, int dest_left, int dest_top, @@ -114,7 +112,7 @@ class CFX_SkiaDeviceDriver : public IFX_RenderDeviceDriver { uint32_t flags, int blend_type) override; - bool StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, + bool StartDIBits(const CFX_DIBSource* pBitmap, int bitmap_alpha, uint32_t color, const CFX_Matrix* pMatrix, @@ -126,8 +124,8 @@ class CFX_SkiaDeviceDriver : public IFX_RenderDeviceDriver { void CancelDIBits(void* handle) override; - bool DrawBitsWithMask(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, - const CFX_RetainPtr<CFX_DIBSource>& pMask, + bool DrawBitsWithMask(const CFX_DIBSource* pBitmap, + const CFX_DIBSource* pMask, int bitmap_alpha, const CFX_Matrix* pMatrix, int blend_type); @@ -154,7 +152,7 @@ class CFX_SkiaDeviceDriver : public IFX_RenderDeviceDriver { void Flush() override; SkPictureRecorder* GetRecorder() const { return m_pRecorder; } void PreMultiply() { m_pBitmap->PreMultiply(); } - static void PreMultiply(const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap); + static void PreMultiply(CFX_DIBitmap* pDIBitmap); SkCanvas* SkiaCanvas() { return m_pCanvas; } void DebugVerifyBitmapIsPreMultiplied() const; void Dump() const; @@ -162,8 +160,8 @@ class CFX_SkiaDeviceDriver : public IFX_RenderDeviceDriver { private: friend class SkiaState; - CFX_RetainPtr<CFX_DIBitmap> m_pBitmap; - CFX_RetainPtr<CFX_DIBitmap> m_pOriDevice; + CFX_DIBitmap* m_pBitmap; + CFX_DIBitmap* m_pOriDevice; SkCanvas* m_pCanvas; SkPictureRecorder* const m_pRecorder; std::unique_ptr<SkiaState> m_pCache; diff --git a/core/fxge/skia/fx_skia_device_unittest.cpp b/core/fxge/skia/fx_skia_device_unittest.cpp index a47a50c836..d612840b4c 100644 --- a/core/fxge/skia/fx_skia_device_unittest.cpp +++ b/core/fxge/skia/fx_skia_device_unittest.cpp @@ -125,7 +125,7 @@ void Harness(void (*Test)(CFX_SkiaDeviceDriver*, const State&), return; FPDFBitmap_FillRect(bitmap, 0, 0, w, h, 0x00000000); CFX_FxgeDevice geDevice; - CFX_RetainPtr<CFX_DIBitmap> pBitmap(CFXBitmapFromFPDFBitmap(bitmap)); + CFX_DIBitmap* pBitmap = CFXBitmapFromFPDFBitmap(bitmap); geDevice.Attach(pBitmap, false, nullptr, false); CFX_SkiaDeviceDriver* driver = static_cast<CFX_SkiaDeviceDriver*>(geDevice.GetDeviceDriver()); diff --git a/core/fxge/win32/cfx_psrenderer.cpp b/core/fxge/win32/cfx_psrenderer.cpp index 5350c383b4..391af83630 100644 --- a/core/fxge/win32/cfx_psrenderer.cpp +++ b/core/fxge/win32/cfx_psrenderer.cpp @@ -338,7 +338,7 @@ static void PSCompressData(int PSLevel, } } -bool CFX_PSRenderer::SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource, +bool CFX_PSRenderer::SetDIBits(const CFX_DIBSource* pSource, uint32_t color, int left, int top) { @@ -349,7 +349,7 @@ bool CFX_PSRenderer::SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource, return DrawDIBits(pSource, color, &matrix, 0); } -bool CFX_PSRenderer::StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource, +bool CFX_PSRenderer::StretchDIBits(const CFX_DIBSource* pSource, uint32_t color, int dest_left, int dest_top, @@ -362,7 +362,7 @@ bool CFX_PSRenderer::StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource, return DrawDIBits(pSource, color, &matrix, flags); } -bool CFX_PSRenderer::DrawDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource, +bool CFX_PSRenderer::DrawDIBits(const CFX_DIBSource* pSource, uint32_t color, const CFX_Matrix* pMatrix, uint32_t flags) { @@ -419,25 +419,25 @@ bool CFX_PSRenderer::DrawDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource, output_buf.release(); } else { CFX_DIBExtractor source_extractor(pSource); - CFX_RetainPtr<CFX_DIBSource> pConverted = source_extractor.GetBitmap(); - if (!pConverted) + CFX_MaybeOwned<CFX_DIBSource> pConverted(source_extractor.GetBitmap()); + if (!pConverted.Get()) return false; switch (pSource->GetFormat()) { case FXDIB_1bppRgb: case FXDIB_Rgb32: - pConverted = pConverted->CloneConvert(FXDIB_Rgb); + pConverted = pConverted->CloneConvert(FXDIB_Rgb).release(); break; case FXDIB_8bppRgb: if (pSource->GetPalette()) { - pConverted = pConverted->CloneConvert(FXDIB_Rgb); + pConverted = pConverted->CloneConvert(FXDIB_Rgb).release(); } break; case FXDIB_1bppCmyk: - pConverted = pConverted->CloneConvert(FXDIB_Cmyk); + pConverted = pConverted->CloneConvert(FXDIB_Cmyk).release(); break; case FXDIB_8bppCmyk: if (pSource->GetPalette()) { - pConverted = pConverted->CloneConvert(FXDIB_Cmyk); + pConverted = pConverted->CloneConvert(FXDIB_Cmyk).release(); } break; default: @@ -452,7 +452,8 @@ bool CFX_PSRenderer::DrawDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource, FX_STRSIZE output_size = 0; const char* filter = nullptr; if ((m_PSLevel == 2 || flags & FXRENDER_IMAGE_LOSSY) && - CCodec_JpegModule::JpegEncode(pConverted, &output_buf, &output_size)) { + CCodec_JpegModule::JpegEncode(pConverted.Get(), &output_buf, + &output_size)) { filter = "/DCTDecode filter "; } if (!filter) { diff --git a/core/fxge/win32/cfx_psrenderer.h b/core/fxge/win32/cfx_psrenderer.h index 5768d0770f..133d7b9d72 100644 --- a/core/fxge/win32/cfx_psrenderer.h +++ b/core/fxge/win32/cfx_psrenderer.h @@ -51,18 +51,18 @@ class CFX_PSRenderer { uint32_t fill_color, uint32_t stroke_color, int fill_mode); - bool SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, + bool SetDIBits(const CFX_DIBSource* pBitmap, uint32_t color, int dest_left, int dest_top); - bool StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, + bool StretchDIBits(const CFX_DIBSource* pBitmap, uint32_t color, int dest_left, int dest_top, int dest_width, int dest_height, uint32_t flags); - bool DrawDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, + bool DrawDIBits(const CFX_DIBSource* pBitmap, uint32_t color, const CFX_Matrix* pMatrix, uint32_t flags); diff --git a/core/fxge/win32/cfx_windowsdib.h b/core/fxge/win32/cfx_windowsdib.h index e59e9d60a4..0bfab3fee1 100644 --- a/core/fxge/win32/cfx_windowsdib.h +++ b/core/fxge/win32/cfx_windowsdib.h @@ -10,9 +10,6 @@ #ifndef _WINDOWS_ #include <windows.h> #endif - -#include "core/fxge/fx_dib.h" - #define WINDIB_OPEN_MEMORY 0x1 #define WINDIB_OPEN_PATHNAME 0x2 @@ -28,20 +25,15 @@ typedef struct WINDIB_Open_Args_ { class CFX_WindowsDIB : public CFX_DIBitmap { public: - template <typename T, typename... Args> - friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args); - + CFX_WindowsDIB(HDC hDC, int width, int height); ~CFX_WindowsDIB() override; - static CFX_ByteString GetBitmapInfo( - const CFX_RetainPtr<CFX_DIBitmap>& pBitmap); - static HBITMAP GetDDBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, - HDC hDC); - - static CFX_RetainPtr<CFX_DIBitmap> LoadFromBuf(BITMAPINFO* pbmi, void* pData); - static CFX_RetainPtr<CFX_DIBitmap> LoadFromFile(const wchar_t* filename); - static CFX_RetainPtr<CFX_DIBitmap> LoadFromFile(const char* filename); - static CFX_RetainPtr<CFX_DIBitmap> LoadDIBitmap(WINDIB_Open_Args_ args); + static CFX_ByteString GetBitmapInfo(const CFX_DIBitmap* pBitmap); + static CFX_DIBitmap* LoadFromBuf(BITMAPINFO* pbmi, void* pData); + static HBITMAP GetDDBitmap(const CFX_DIBitmap* pBitmap, HDC hDC); + static CFX_DIBitmap* LoadFromFile(const wchar_t* filename); + static CFX_DIBitmap* LoadFromFile(const char* filename); + static CFX_DIBitmap* LoadDIBitmap(WINDIB_Open_Args_ args); HDC GetDC() const { return m_hMemDC; } HBITMAP GetWindowsBitmap() const { return m_hBitmap; } @@ -50,8 +42,6 @@ class CFX_WindowsDIB : public CFX_DIBitmap { void SetToDevice(HDC hDC, int left, int top); protected: - CFX_WindowsDIB(HDC hDC, int width, int height); - HDC m_hMemDC; HBITMAP m_hBitmap; HBITMAP m_hOldBitmap; diff --git a/core/fxge/win32/dwrite_int.h b/core/fxge/win32/dwrite_int.h index 8e8908a7a1..105c34998c 100644 --- a/core/fxge/win32/dwrite_int.h +++ b/core/fxge/win32/dwrite_int.h @@ -39,8 +39,7 @@ class CDWriteExt { void* DwCreateFontFaceFromStream(uint8_t* pData, uint32_t size, int simulation_style); - bool DwCreateRenderingTarget(const CFX_RetainPtr<CFX_DIBitmap>& pSrc, - void** renderTarget); + bool DwCreateRenderingTarget(CFX_DIBitmap* pSrc, void** renderTarget); void DwDeleteRenderingTarget(void* renderTarget); bool DwRendingString(void* renderTarget, CFX_ClipRgn* pClipRgn, diff --git a/core/fxge/win32/fx_win32_device.cpp b/core/fxge/win32/fx_win32_device.cpp index 140a5b07d5..b2ee4549ea 100644 --- a/core/fxge/win32/fx_win32_device.cpp +++ b/core/fxge/win32/fx_win32_device.cpp @@ -782,13 +782,12 @@ void CGdiDeviceDriver::RestoreState(bool bKeepSaved) { SaveDC(m_hDC); } -bool CGdiDeviceDriver::GDI_SetDIBits( - const CFX_RetainPtr<CFX_DIBitmap>& pBitmap1, - const FX_RECT* pSrcRect, - int left, - int top) { +bool CGdiDeviceDriver::GDI_SetDIBits(CFX_DIBitmap* pBitmap1, + const FX_RECT* pSrcRect, + int left, + int top) { if (m_DeviceClass == FXDC_PRINTER) { - CFX_RetainPtr<CFX_DIBitmap> pBitmap = pBitmap1->FlipImage(false, true); + std::unique_ptr<CFX_DIBitmap> pBitmap = pBitmap1->FlipImage(false, true); if (!pBitmap) return false; @@ -797,7 +796,7 @@ bool CGdiDeviceDriver::GDI_SetDIBits( int width = pSrcRect->Width(), height = pSrcRect->Height(); LPBYTE pBuffer = pBitmap->GetBuffer(); - CFX_ByteString info = CFX_WindowsDIB::GetBitmapInfo(pBitmap); + CFX_ByteString info = CFX_WindowsDIB::GetBitmapInfo(pBitmap.get()); ((BITMAPINFOHEADER*)info.c_str())->biHeight *= -1; FX_RECT dst_rect(0, 0, width, height); dst_rect.Intersect(0, 0, pBitmap->GetWidth(), pBitmap->GetHeight()); @@ -807,15 +806,15 @@ bool CGdiDeviceDriver::GDI_SetDIBits( dst_height, pBuffer, (BITMAPINFO*)info.c_str(), DIB_RGB_COLORS, SRCCOPY); } else { - CFX_RetainPtr<CFX_DIBitmap> pBitmap = pBitmap1; + CFX_MaybeOwned<CFX_DIBitmap> pBitmap(pBitmap1); if (pBitmap->IsCmykImage()) { - pBitmap = pBitmap->CloneConvert(FXDIB_Rgb); + pBitmap = pBitmap->CloneConvert(FXDIB_Rgb).release(); if (!pBitmap) return false; } int width = pSrcRect->Width(), height = pSrcRect->Height(); LPBYTE pBuffer = pBitmap->GetBuffer(); - CFX_ByteString info = CFX_WindowsDIB::GetBitmapInfo(pBitmap); + CFX_ByteString info = CFX_WindowsDIB::GetBitmapInfo(pBitmap.Get()); ::SetDIBitsToDevice(m_hDC, left, top, width, height, pSrcRect->left, pBitmap->GetHeight() - pSrcRect->bottom, 0, pBitmap->GetHeight(), pBuffer, @@ -824,14 +823,13 @@ bool CGdiDeviceDriver::GDI_SetDIBits( return true; } -bool CGdiDeviceDriver::GDI_StretchDIBits( - const CFX_RetainPtr<CFX_DIBitmap>& pBitmap1, - int dest_left, - int dest_top, - int dest_width, - int dest_height, - uint32_t flags) { - CFX_RetainPtr<CFX_DIBitmap> pBitmap = pBitmap1; +bool CGdiDeviceDriver::GDI_StretchDIBits(CFX_DIBitmap* pBitmap1, + int dest_left, + int dest_top, + int dest_width, + int dest_height, + uint32_t flags) { + CFX_DIBitmap* pBitmap = pBitmap1; if (!pBitmap || dest_width == 0 || dest_height == 0) return false; @@ -846,14 +844,14 @@ bool CGdiDeviceDriver::GDI_StretchDIBits( } else { SetStretchBltMode(m_hDC, COLORONCOLOR); } - CFX_RetainPtr<CFX_DIBitmap> pToStrechBitmap = pBitmap; + CFX_MaybeOwned<CFX_DIBitmap> pToStrechBitmap(pBitmap); if (m_DeviceClass == FXDC_PRINTER && ((int64_t)pBitmap->GetWidth() * pBitmap->GetHeight() > (int64_t)abs(dest_width) * abs(dest_height))) { pToStrechBitmap = pBitmap->StretchTo(dest_width, dest_height); } CFX_ByteString toStrechBitmapInfo = - CFX_WindowsDIB::GetBitmapInfo(pToStrechBitmap); + CFX_WindowsDIB::GetBitmapInfo(pToStrechBitmap.Get()); ::StretchDIBits(m_hDC, dest_left, dest_top, dest_width, dest_height, 0, 0, pToStrechBitmap->GetWidth(), pToStrechBitmap->GetHeight(), pToStrechBitmap->GetBuffer(), @@ -862,15 +860,14 @@ bool CGdiDeviceDriver::GDI_StretchDIBits( return true; } -bool CGdiDeviceDriver::GDI_StretchBitMask( - const CFX_RetainPtr<CFX_DIBitmap>& pBitmap1, - int dest_left, - int dest_top, - int dest_width, - int dest_height, - uint32_t bitmap_color, - uint32_t flags) { - CFX_RetainPtr<CFX_DIBitmap> pBitmap = pBitmap1; +bool CGdiDeviceDriver::GDI_StretchBitMask(CFX_DIBitmap* pBitmap1, + int dest_left, + int dest_top, + int dest_width, + int dest_height, + uint32_t bitmap_color, + uint32_t flags) { + CFX_DIBitmap* pBitmap = pBitmap1; if (!pBitmap || dest_width == 0 || dest_height == 0) return false; @@ -1168,9 +1165,7 @@ CGdiDisplayDriver::CGdiDisplayDriver(HDC hDC) CGdiDisplayDriver::~CGdiDisplayDriver() {} -bool CGdiDisplayDriver::GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, - int left, - int top) { +bool CGdiDisplayDriver::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) { bool ret = false; int width = pBitmap->GetWidth(); int height = pBitmap->GetHeight(); @@ -1190,12 +1185,12 @@ bool CGdiDisplayDriver::GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, ret = ::GetDIBits(hDCMemory, hbmp, 0, height, pBitmap->GetBuffer(), &bmi, DIB_RGB_COLORS) == height; } else { - auto bitmap = pdfium::MakeRetain<CFX_DIBitmap>(); - if (bitmap->Create(width, height, FXDIB_Rgb)) { + CFX_DIBitmap bitmap; + if (bitmap.Create(width, height, FXDIB_Rgb)) { bmi.bmiHeader.biBitCount = 24; - ::GetDIBits(hDCMemory, hbmp, 0, height, bitmap->GetBuffer(), &bmi, + ::GetDIBits(hDCMemory, hbmp, 0, height, bitmap.GetBuffer(), &bmi, DIB_RGB_COLORS); - ret = pBitmap->TransferBitmap(0, 0, width, height, bitmap, 0, 0); + ret = pBitmap->TransferBitmap(0, 0, width, height, &bitmap, 0, 0); } else { ret = false; } @@ -1208,7 +1203,7 @@ bool CGdiDisplayDriver::GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, return ret; } -bool CGdiDisplayDriver::SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource, +bool CGdiDisplayDriver::SetDIBits(const CFX_DIBSource* pSource, uint32_t color, const FX_RECT* pSrcRect, int left, @@ -1219,16 +1214,17 @@ bool CGdiDisplayDriver::SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource, int width = pSource->GetWidth(), height = pSource->GetHeight(); int alpha = FXARGB_A(color); if (pSource->GetBPP() != 1 || alpha != 255) { - auto background = pdfium::MakeRetain<CFX_DIBitmap>(); - if (!background->Create(width, height, FXDIB_Rgb32) || - !GetDIBits(background, left, top) || - !background->CompositeMask(0, 0, width, height, pSource, color, 0, 0, - FXDIB_BLEND_NORMAL, nullptr, false, 0, - nullptr)) { + CFX_DIBitmap background; + if (!background.Create(width, height, FXDIB_Rgb32) || + !GetDIBits(&background, left, top) || + !background.CompositeMask(0, 0, width, height, pSource, color, 0, 0, + FXDIB_BLEND_NORMAL, nullptr, false, 0, + nullptr)) { return false; } FX_RECT src_rect(0, 0, width, height); - return SetDIBits(background, 0, &src_rect, left, top, FXDIB_BLEND_NORMAL); + return SetDIBits(&background, 0, &src_rect, left, top, + FXDIB_BLEND_NORMAL); } FX_RECT clip_rect(left, top, left + pSrcRect->Width(), top + pSrcRect->Height()); @@ -1238,33 +1234,32 @@ bool CGdiDisplayDriver::SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource, } int width = pSrcRect->Width(), height = pSrcRect->Height(); if (pSource->HasAlpha()) { - auto bitmap = pdfium::MakeRetain<CFX_DIBitmap>(); - if (!bitmap->Create(width, height, FXDIB_Rgb) || - !GetDIBits(bitmap, left, top) || - !bitmap->CompositeBitmap(0, 0, width, height, pSource, pSrcRect->left, - pSrcRect->top, FXDIB_BLEND_NORMAL, nullptr, - false, nullptr)) { + CFX_DIBitmap bitmap; + if (!bitmap.Create(width, height, FXDIB_Rgb) || + !GetDIBits(&bitmap, left, top) || + !bitmap.CompositeBitmap(0, 0, width, height, pSource, pSrcRect->left, + pSrcRect->top, FXDIB_BLEND_NORMAL, nullptr, + false, nullptr)) { return false; } FX_RECT src_rect(0, 0, width, height); - return SetDIBits(bitmap, 0, &src_rect, left, top, FXDIB_BLEND_NORMAL); + return SetDIBits(&bitmap, 0, &src_rect, left, top, FXDIB_BLEND_NORMAL); } CFX_DIBExtractor temp(pSource); - CFX_RetainPtr<CFX_DIBitmap> pBitmap = temp.GetBitmap(); + CFX_DIBitmap* pBitmap = temp.GetBitmap(); if (!pBitmap) return false; return GDI_SetDIBits(pBitmap, pSrcRect, left, top); } -bool CGdiDisplayDriver::UseFoxitStretchEngine( - const CFX_RetainPtr<CFX_DIBSource>& pSource, - uint32_t color, - int dest_left, - int dest_top, - int dest_width, - int dest_height, - const FX_RECT* pClipRect, - int render_flags) { +bool CGdiDisplayDriver::UseFoxitStretchEngine(const CFX_DIBSource* pSource, + uint32_t color, + int dest_left, + int dest_top, + int dest_width, + int dest_height, + const FX_RECT* pClipRect, + int render_flags) { FX_RECT bitmap_clip = *pClipRect; if (dest_width < 0) dest_left += dest_width; @@ -1273,26 +1268,25 @@ bool CGdiDisplayDriver::UseFoxitStretchEngine( dest_top += dest_height; bitmap_clip.Offset(-dest_left, -dest_top); - CFX_RetainPtr<CFX_DIBitmap> pStretched = - pSource->StretchTo(dest_width, dest_height, render_flags, &bitmap_clip); + std::unique_ptr<CFX_DIBitmap> pStretched( + pSource->StretchTo(dest_width, dest_height, render_flags, &bitmap_clip)); if (!pStretched) return true; FX_RECT src_rect(0, 0, pStretched->GetWidth(), pStretched->GetHeight()); - return SetDIBits(pStretched, color, &src_rect, pClipRect->left, + return SetDIBits(pStretched.get(), color, &src_rect, pClipRect->left, pClipRect->top, FXDIB_BLEND_NORMAL); } -bool CGdiDisplayDriver::StretchDIBits( - const CFX_RetainPtr<CFX_DIBSource>& pSource, - uint32_t color, - int dest_left, - int dest_top, - int dest_width, - int dest_height, - const FX_RECT* pClipRect, - uint32_t flags, - int blend_type) { +bool CGdiDisplayDriver::StretchDIBits(const CFX_DIBSource* pSource, + uint32_t color, + int dest_left, + int dest_top, + int dest_width, + int dest_height, + const FX_RECT* pClipRect, + uint32_t flags, + int blend_type) { ASSERT(pSource && pClipRect); if (flags || dest_width > 10000 || dest_width < -10000 || dest_height > 10000 || dest_height < -10000) { @@ -1309,23 +1303,24 @@ bool CGdiDisplayDriver::StretchDIBits( clip_rect.Intersect(*pClipRect); clip_rect.Offset(-image_rect.left, -image_rect.top); int clip_width = clip_rect.Width(), clip_height = clip_rect.Height(); - CFX_RetainPtr<CFX_DIBitmap> pStretched( + std::unique_ptr<CFX_DIBitmap> pStretched( pSource->StretchTo(dest_width, dest_height, flags, &clip_rect)); if (!pStretched) return true; - auto background = pdfium::MakeRetain<CFX_DIBitmap>(); - if (!background->Create(clip_width, clip_height, FXDIB_Rgb32) || - !GetDIBits(background, image_rect.left + clip_rect.left, + CFX_DIBitmap background; + if (!background.Create(clip_width, clip_height, FXDIB_Rgb32) || + !GetDIBits(&background, image_rect.left + clip_rect.left, image_rect.top + clip_rect.top) || - !background->CompositeMask(0, 0, clip_width, clip_height, pStretched, - color, 0, 0, FXDIB_BLEND_NORMAL, nullptr, - false, 0, nullptr)) { + !background.CompositeMask( + 0, 0, clip_width, clip_height, pStretched.get(), color, 0, 0, + FXDIB_BLEND_NORMAL, nullptr, false, 0, nullptr)) { return false; } FX_RECT src_rect(0, 0, clip_width, clip_height); - return SetDIBits(background, 0, &src_rect, image_rect.left + clip_rect.left, + return SetDIBits(&background, 0, &src_rect, + image_rect.left + clip_rect.left, image_rect.top + clip_rect.top, FXDIB_BLEND_NORMAL); } if (pSource->HasAlpha()) { @@ -1333,7 +1328,7 @@ bool CGdiDisplayDriver::StretchDIBits( (CWin32Platform*)CFX_GEModule::Get()->GetPlatformData(); if (pPlatform->m_GdiplusExt.IsAvailable() && !pSource->IsCmykImage()) { CFX_DIBExtractor temp(pSource); - CFX_RetainPtr<CFX_DIBitmap> pBitmap = temp.GetBitmap(); + CFX_DIBitmap* pBitmap = temp.GetBitmap(); if (!pBitmap) return false; return pPlatform->m_GdiplusExt.StretchDIBits( @@ -1344,14 +1339,14 @@ bool CGdiDisplayDriver::StretchDIBits( dest_width, dest_height, pClipRect, flags); } CFX_DIBExtractor temp(pSource); - CFX_RetainPtr<CFX_DIBitmap> pBitmap = temp.GetBitmap(); + CFX_DIBitmap* pBitmap = temp.GetBitmap(); if (!pBitmap) return false; return GDI_StretchDIBits(pBitmap, dest_left, dest_top, dest_width, dest_height, flags); } -bool CGdiDisplayDriver::StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, +bool CGdiDisplayDriver::StartDIBits(const CFX_DIBSource* pBitmap, int bitmap_alpha, uint32_t color, const CFX_Matrix* pMatrix, diff --git a/core/fxge/win32/fx_win32_dib.cpp b/core/fxge/win32/fx_win32_dib.cpp index 9815457bbd..9b85b57317 100644 --- a/core/fxge/win32/fx_win32_dib.cpp +++ b/core/fxge/win32/fx_win32_dib.cpp @@ -11,8 +11,7 @@ #include "core/fxge/win32/cfx_windowsdib.h" #include "core/fxge/win32/win32_int.h" -CFX_ByteString CFX_WindowsDIB::GetBitmapInfo( - const CFX_RetainPtr<CFX_DIBitmap>& pBitmap) { +CFX_ByteString CFX_WindowsDIB::GetBitmapInfo(const CFX_DIBitmap* pBitmap) { CFX_ByteString result; int len = sizeof(BITMAPINFOHEADER); if (pBitmap->GetBPP() == 1 || pBitmap->GetBPP() == 8) { @@ -52,9 +51,9 @@ CFX_ByteString CFX_WindowsDIB::GetBitmapInfo( return result; } -CFX_RetainPtr<CFX_DIBitmap> _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi, - LPVOID pData, - bool bAlpha) { +CFX_DIBitmap* _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi, + LPVOID pData, + bool bAlpha) { int width = pbmi->bmiHeader.biWidth; int height = pbmi->bmiHeader.biHeight; BOOL bBottomUp = true; @@ -63,13 +62,15 @@ CFX_RetainPtr<CFX_DIBitmap> _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi, bBottomUp = false; } int pitch = (width * pbmi->bmiHeader.biBitCount + 31) / 32 * 4; - auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>(); + CFX_DIBitmap* pBitmap = new CFX_DIBitmap; FXDIB_Format format = bAlpha ? (FXDIB_Format)(pbmi->bmiHeader.biBitCount + 0x200) : (FXDIB_Format)pbmi->bmiHeader.biBitCount; - if (!pBitmap->Create(width, height, format)) + bool ret = pBitmap->Create(width, height, format); + if (!ret) { + delete pBitmap; return nullptr; - + } FXSYS_memcpy(pBitmap->GetBuffer(), pData, pitch * height); if (bBottomUp) { uint8_t* temp_buf = FX_Alloc(uint8_t, pitch); @@ -97,13 +98,11 @@ CFX_RetainPtr<CFX_DIBitmap> _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi, return pBitmap; } -CFX_RetainPtr<CFX_DIBitmap> CFX_WindowsDIB::LoadFromBuf(BITMAPINFO* pbmi, - LPVOID pData) { +CFX_DIBitmap* CFX_WindowsDIB::LoadFromBuf(BITMAPINFO* pbmi, LPVOID pData) { return _FX_WindowsDIB_LoadFromBuf(pbmi, pData, false); } -HBITMAP CFX_WindowsDIB::GetDDBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, - HDC hDC) { +HBITMAP CFX_WindowsDIB::GetDDBitmap(const CFX_DIBitmap* pBitmap, HDC hDC) { CFX_ByteString info = GetBitmapInfo(pBitmap); return CreateDIBitmap(hDC, (BITMAPINFOHEADER*)info.c_str(), CBM_INIT, pBitmap->GetBuffer(), (BITMAPINFO*)info.c_str(), @@ -117,8 +116,7 @@ void GetBitmapSize(HBITMAP hBitmap, int& w, int& h) { h = bmp.bmHeight; } -CFX_RetainPtr<CFX_DIBitmap> CFX_WindowsDIB::LoadFromFile( - const wchar_t* filename) { +CFX_DIBitmap* CFX_WindowsDIB::LoadFromFile(const wchar_t* filename) { CWin32Platform* pPlatform = (CWin32Platform*)CFX_GEModule::Get()->GetPlatformData(); if (pPlatform->m_GdiplusExt.IsAvailable()) { @@ -133,29 +131,30 @@ CFX_RetainPtr<CFX_DIBitmap> CFX_WindowsDIB::LoadFromFile( return nullptr; } HDC hDC = CreateCompatibleDC(nullptr); - int width; - int height; + int width, height; GetBitmapSize(hBitmap, width, height); - auto pDIBitmap = pdfium::MakeRetain<CFX_DIBitmap>(); + CFX_DIBitmap* pDIBitmap = new CFX_DIBitmap; if (!pDIBitmap->Create(width, height, FXDIB_Rgb)) { + delete pDIBitmap; DeleteDC(hDC); return nullptr; } CFX_ByteString info = GetBitmapInfo(pDIBitmap); int ret = GetDIBits(hDC, hBitmap, 0, height, pDIBitmap->GetBuffer(), (BITMAPINFO*)info.c_str(), DIB_RGB_COLORS); + if (!ret) { + delete pDIBitmap; + pDIBitmap = nullptr; + } DeleteDC(hDC); - if (!ret) - return nullptr; return pDIBitmap; } -CFX_RetainPtr<CFX_DIBitmap> CFX_WindowsDIB::LoadFromFile(const char* filename) { +CFX_DIBitmap* CFX_WindowsDIB::LoadFromFile(const char* filename) { return LoadFromFile(CFX_WideString::FromLocal(filename).c_str()); } -CFX_RetainPtr<CFX_DIBitmap> CFX_WindowsDIB::LoadDIBitmap( - WINDIB_Open_Args_ args) { +CFX_DIBitmap* CFX_WindowsDIB::LoadDIBitmap(WINDIB_Open_Args_ args) { CWin32Platform* pPlatform = (CWin32Platform*)CFX_GEModule::Get()->GetPlatformData(); if (pPlatform->m_GdiplusExt.IsAvailable()) { @@ -172,17 +171,20 @@ CFX_RetainPtr<CFX_DIBitmap> CFX_WindowsDIB::LoadDIBitmap( HDC hDC = CreateCompatibleDC(nullptr); int width, height; GetBitmapSize(hBitmap, width, height); - auto pDIBitmap = pdfium::MakeRetain<CFX_DIBitmap>(); + CFX_DIBitmap* pDIBitmap = new CFX_DIBitmap; if (!pDIBitmap->Create(width, height, FXDIB_Rgb)) { + delete pDIBitmap; DeleteDC(hDC); return nullptr; } CFX_ByteString info = GetBitmapInfo(pDIBitmap); int ret = GetDIBits(hDC, hBitmap, 0, height, pDIBitmap->GetBuffer(), (BITMAPINFO*)info.c_str(), DIB_RGB_COLORS); + if (!ret) { + delete pDIBitmap; + pDIBitmap = nullptr; + } DeleteDC(hDC); - if (!ret) - return nullptr; return pDIBitmap; } diff --git a/core/fxge/win32/fx_win32_dwrite.cpp b/core/fxge/win32/fx_win32_dwrite.cpp index 91fb465af4..e088e832bc 100644 --- a/core/fxge/win32/fx_win32_dwrite.cpp +++ b/core/fxge/win32/fx_win32_dwrite.cpp @@ -103,7 +103,7 @@ class CDwFontContext { class CDwGdiTextRenderer { public: - CDwGdiTextRenderer(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, + CDwGdiTextRenderer(CFX_DIBitmap* pBitmap, IDWriteBitmapRenderTarget* bitmapRenderTarget, IDWriteRenderingParams* renderingParams); ~CDwGdiTextRenderer(); @@ -118,7 +118,7 @@ class CDwGdiTextRenderer { const COLORREF& textColor); private: - CFX_RetainPtr<CFX_DIBitmap> pBitmap_; + CFX_DIBitmap* pBitmap_; IDWriteBitmapRenderTarget* pRenderTarget_; IDWriteRenderingParams* pRenderingParams_; }; @@ -180,9 +180,8 @@ failed: return nullptr; } -bool CDWriteExt::DwCreateRenderingTarget( - const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, - void** renderTarget) { +bool CDWriteExt::DwCreateRenderingTarget(CFX_DIBitmap* pBitmap, + void** renderTarget) { if (pBitmap->GetFormat() > FXDIB_Argb) { return false; } @@ -396,7 +395,7 @@ HRESULT CDwFontContext::Initialize() { } CDwGdiTextRenderer::CDwGdiTextRenderer( - const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, + CFX_DIBitmap* pBitmap, IDWriteBitmapRenderTarget* bitmapRenderTarget, IDWriteRenderingParams* renderingParams) : pBitmap_(pBitmap), @@ -427,13 +426,13 @@ STDMETHODIMP CDwGdiTextRenderer::DrawGlyphRun( HBITMAP hBitmap = (HBITMAP)::GetCurrentObject(hDC, OBJ_BITMAP); BITMAP bitmap; GetObject(hBitmap, sizeof bitmap, &bitmap); - auto dib = pdfium::MakeRetain<CFX_DIBitmap>(); - dib->Create(bitmap.bmWidth, bitmap.bmHeight, - bitmap.bmBitsPixel == 24 ? FXDIB_Rgb : FXDIB_Rgb32, - (uint8_t*)bitmap.bmBits); - dib->CompositeBitmap(text_bbox.left, text_bbox.top, text_bbox.Width(), - text_bbox.Height(), pBitmap_, text_bbox.left, - text_bbox.top, FXDIB_BLEND_NORMAL, nullptr); + CFX_DIBitmap dib; + dib.Create(bitmap.bmWidth, bitmap.bmHeight, + bitmap.bmBitsPixel == 24 ? FXDIB_Rgb : FXDIB_Rgb32, + (uint8_t*)bitmap.bmBits); + dib.CompositeBitmap(text_bbox.left, text_bbox.top, text_bbox.Width(), + text_bbox.Height(), pBitmap_, text_bbox.left, + text_bbox.top, FXDIB_BLEND_NORMAL, nullptr); hr = pRenderTarget_->DrawGlyphRun(baselineOriginX, baselineOriginY, measuringMode, glyphRun, pRenderingParams_, textColor); @@ -441,7 +440,7 @@ STDMETHODIMP CDwGdiTextRenderer::DrawGlyphRun( return hr; } pBitmap_->CompositeBitmap(text_bbox.left, text_bbox.top, text_bbox.Width(), - text_bbox.Height(), dib, text_bbox.left, + text_bbox.Height(), &dib, text_bbox.left, text_bbox.top, FXDIB_BLEND_NORMAL, pClipRgn); return hr; } diff --git a/core/fxge/win32/fx_win32_gdipext.cpp b/core/fxge/win32/fx_win32_gdipext.cpp index 41f9ba55ad..8a7f55e0cb 100644 --- a/core/fxge/win32/fx_win32_gdipext.cpp +++ b/core/fxge/win32/fx_win32_gdipext.cpp @@ -461,10 +461,10 @@ static GpBrush* _GdipCreateBrush(DWORD argb) { return solidBrush; } -static CFX_RetainPtr<CFX_DIBitmap> StretchMonoToGray( +static std::unique_ptr<CFX_DIBitmap> StretchMonoToGray( int dest_width, int dest_height, - const CFX_RetainPtr<CFX_DIBitmap>& pSource, + const CFX_DIBitmap* pSource, FX_RECT* pClipRect) { bool bFlipX = dest_width < 0; if (bFlipX) @@ -477,7 +477,7 @@ static CFX_RetainPtr<CFX_DIBitmap> StretchMonoToGray( int result_width = pClipRect->Width(); int result_height = pClipRect->Height(); int result_pitch = (result_width + 3) / 4 * 4; - auto pStretched = pdfium::MakeRetain<CFX_DIBitmap>(); + auto pStretched = pdfium::MakeUnique<CFX_DIBitmap>(); if (!pStretched->Create(result_width, result_height, FXDIB_8bppRgb)) return nullptr; @@ -518,7 +518,7 @@ static CFX_RetainPtr<CFX_DIBitmap> StretchMonoToGray( static void OutputImageMask(GpGraphics* pGraphics, BOOL bMonoDevice, - const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, + const CFX_DIBitmap* pBitmap, int dest_left, int dest_top, int dest_width, @@ -562,7 +562,7 @@ static void OutputImageMask(GpGraphics* pGraphics, return; } image_clip.Offset(-image_rect.left, -image_rect.top); - CFX_RetainPtr<CFX_DIBitmap> pStretched; + std::unique_ptr<CFX_DIBitmap> pStretched; if (src_width * src_height > 10000) { pStretched = StretchMonoToGray(dest_width, dest_height, pBitmap, &image_clip); @@ -602,7 +602,7 @@ static void OutputImageMask(GpGraphics* pGraphics, CallFunc(GdipDisposeImage)(bitmap); } static void OutputImage(GpGraphics* pGraphics, - const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, + const CFX_DIBitmap* pBitmap, const FX_RECT* pSrcRect, int dest_left, int dest_top, @@ -613,11 +613,11 @@ static void OutputImage(GpGraphics* pGraphics, ((CWin32Platform*)CFX_GEModule::Get()->GetPlatformData())->m_GdiplusExt; if (pBitmap->GetBPP() == 1 && (pSrcRect->left % 8)) { FX_RECT new_rect(0, 0, src_width, src_height); - CFX_RetainPtr<CFX_DIBitmap> pCloned = pBitmap->Clone(pSrcRect); + std::unique_ptr<CFX_DIBitmap> pCloned = pBitmap->Clone(pSrcRect); if (!pCloned) return; - OutputImage(pGraphics, pCloned, &new_rect, dest_left, dest_top, dest_width, - dest_height); + OutputImage(pGraphics, pCloned.get(), &new_rect, dest_left, dest_top, + dest_width, dest_height); return; } int src_pitch = pBitmap->GetPitch(); @@ -730,8 +730,7 @@ void CGdiplusExt::DeleteMemFont(LPVOID pCollection) { ((CWin32Platform*)CFX_GEModule::Get()->GetPlatformData())->m_GdiplusExt; CallFunc(GdipDeletePrivateFontCollection)((GpFontCollection**)&pCollection); } -bool CGdiplusExt::GdipCreateBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, - void** bitmap) { +bool CGdiplusExt::GdipCreateBitmap(CFX_DIBitmap* pBitmap, void** bitmap) { CGdiplusExt& GdiplusExt = ((CWin32Platform*)CFX_GEModule::Get()->GetPlatformData())->m_GdiplusExt; PixelFormat format; @@ -913,7 +912,7 @@ void CGdiplusExt::GdipDeleteGraphics(void* graphics) { } bool CGdiplusExt::StretchBitMask(HDC hDC, BOOL bMonoDevice, - const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, + const CFX_DIBitmap* pBitmap, int dest_left, int dest_top, int dest_width, @@ -939,7 +938,7 @@ bool CGdiplusExt::StretchBitMask(HDC hDC, return true; } bool CGdiplusExt::StretchDIBits(HDC hDC, - const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, + const CFX_DIBitmap* pBitmap, int dest_left, int dest_top, int dest_width, @@ -1493,16 +1492,14 @@ static void FreeDIBitmap(PREVIEW3_DIBITMAP* pInfo) { FX_Free(pInfo); } -// TODO(tsepez): Really? Really? Move to header. -CFX_RetainPtr<CFX_DIBitmap> _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi, - LPVOID pData, - bool bAlpha); - -CFX_RetainPtr<CFX_DIBitmap> CGdiplusExt::LoadDIBitmap(WINDIB_Open_Args_ args) { +CFX_DIBitmap* _FX_WindowsDIB_LoadFromBuf(BITMAPINFO* pbmi, + LPVOID pData, + bool bAlpha); +CFX_DIBitmap* CGdiplusExt::LoadDIBitmap(WINDIB_Open_Args_ args) { PREVIEW3_DIBITMAP* pInfo = ::LoadDIBitmap(args); - if (!pInfo) + if (!pInfo) { return nullptr; - + } int height = abs(pInfo->pbmi->bmiHeader.biHeight); int width = pInfo->pbmi->bmiHeader.biWidth; int dest_pitch = (width * pInfo->pbmi->bmiHeader.biBitCount + 31) / 32 * 4; @@ -1515,7 +1512,7 @@ CFX_RetainPtr<CFX_DIBitmap> CGdiplusExt::LoadDIBitmap(WINDIB_Open_Args_ args) { dest_pitch); } } - CFX_RetainPtr<CFX_DIBitmap> pDIBitmap = _FX_WindowsDIB_LoadFromBuf( + CFX_DIBitmap* pDIBitmap = _FX_WindowsDIB_LoadFromBuf( pInfo->pbmi, pData, pInfo->pbmi->bmiHeader.biBitCount == 32); FX_Free(pData); FreeDIBitmap(pInfo); diff --git a/core/fxge/win32/fx_win32_print.cpp b/core/fxge/win32/fx_win32_print.cpp index 6d96243655..061896f09b 100644 --- a/core/fxge/win32/fx_win32_print.cpp +++ b/core/fxge/win32/fx_win32_print.cpp @@ -67,7 +67,7 @@ int CGdiPrinterDriver::GetDeviceCaps(int caps_id) const { return CGdiDeviceDriver::GetDeviceCaps(caps_id); } -bool CGdiPrinterDriver::SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource, +bool CGdiPrinterDriver::SetDIBits(const CFX_DIBSource* pSource, uint32_t color, const FX_RECT* pSrcRect, int left, @@ -87,30 +87,29 @@ bool CGdiPrinterDriver::SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource, return false; CFX_DIBExtractor temp(pSource); - CFX_RetainPtr<CFX_DIBitmap> pBitmap = temp.GetBitmap(); + CFX_DIBitmap* pBitmap = temp.GetBitmap(); if (!pBitmap) return false; return GDI_SetDIBits(pBitmap, pSrcRect, left, top); } -bool CGdiPrinterDriver::StretchDIBits( - const CFX_RetainPtr<CFX_DIBSource>& pSource, - uint32_t color, - int dest_left, - int dest_top, - int dest_width, - int dest_height, - const FX_RECT* pClipRect, - uint32_t flags, - int blend_type) { +bool CGdiPrinterDriver::StretchDIBits(const CFX_DIBSource* pSource, + uint32_t color, + int dest_left, + int dest_top, + int dest_width, + int dest_height, + const FX_RECT* pClipRect, + uint32_t flags, + int blend_type) { if (pSource->IsAlphaMask()) { int alpha = FXARGB_A(color); if (pSource->GetBPP() != 1 || alpha != 255) return false; if (dest_width < 0 || dest_height < 0) { - CFX_RetainPtr<CFX_DIBitmap> pFlipped = + std::unique_ptr<CFX_DIBitmap> pFlipped = pSource->FlipImage(dest_width < 0, dest_height < 0); if (!pFlipped) return false; @@ -120,12 +119,13 @@ bool CGdiPrinterDriver::StretchDIBits( if (dest_height < 0) dest_top += dest_height; - return GDI_StretchBitMask(pFlipped, dest_left, dest_top, abs(dest_width), - abs(dest_height), color, flags); + return GDI_StretchBitMask(pFlipped.get(), dest_left, dest_top, + abs(dest_width), abs(dest_height), color, + flags); } CFX_DIBExtractor temp(pSource); - CFX_RetainPtr<CFX_DIBitmap> pBitmap = temp.GetBitmap(); + CFX_DIBitmap* pBitmap = temp.GetBitmap(); if (!pBitmap) return false; return GDI_StretchBitMask(pBitmap, dest_left, dest_top, dest_width, @@ -136,7 +136,7 @@ bool CGdiPrinterDriver::StretchDIBits( return false; if (dest_width < 0 || dest_height < 0) { - CFX_RetainPtr<CFX_DIBitmap> pFlipped = + std::unique_ptr<CFX_DIBitmap> pFlipped = pSource->FlipImage(dest_width < 0, dest_height < 0); if (!pFlipped) return false; @@ -146,19 +146,19 @@ bool CGdiPrinterDriver::StretchDIBits( if (dest_height < 0) dest_top += dest_height; - return GDI_StretchDIBits(pFlipped, dest_left, dest_top, abs(dest_width), - abs(dest_height), flags); + return GDI_StretchDIBits(pFlipped.get(), dest_left, dest_top, + abs(dest_width), abs(dest_height), flags); } CFX_DIBExtractor temp(pSource); - CFX_RetainPtr<CFX_DIBitmap> pBitmap = temp.GetBitmap(); + CFX_DIBitmap* pBitmap = temp.GetBitmap(); if (!pBitmap) return false; return GDI_StretchDIBits(pBitmap, dest_left, dest_top, dest_width, dest_height, flags); } -bool CGdiPrinterDriver::StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource, +bool CGdiPrinterDriver::StartDIBits(const CFX_DIBSource* pSource, int bitmap_alpha, uint32_t color, const CFX_Matrix* pMatrix, @@ -185,12 +185,12 @@ bool CGdiPrinterDriver::StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pSource, if (FXSYS_fabs(pMatrix->a) >= 0.5f || FXSYS_fabs(pMatrix->d) >= 0.5f) return false; - CFX_RetainPtr<CFX_DIBitmap> pTransformed = + std::unique_ptr<CFX_DIBitmap> pTransformed = pSource->SwapXY(pMatrix->c > 0, pMatrix->b < 0); if (!pTransformed) return false; - return StretchDIBits(pTransformed, color, full_rect.left, full_rect.top, + return StretchDIBits(pTransformed.get(), color, full_rect.left, full_rect.top, full_rect.Width(), full_rect.Height(), nullptr, 0, blend_type); } @@ -436,7 +436,7 @@ bool CPSPrinterDriver::GetClipBox(FX_RECT* pRect) { return true; } -bool CPSPrinterDriver::SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, +bool CPSPrinterDriver::SetDIBits(const CFX_DIBSource* pBitmap, uint32_t color, const FX_RECT* pSrcRect, int left, @@ -447,23 +447,22 @@ bool CPSPrinterDriver::SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, return m_PSRenderer.SetDIBits(pBitmap, color, left, top); } -bool CPSPrinterDriver::StretchDIBits( - const CFX_RetainPtr<CFX_DIBSource>& pBitmap, - uint32_t color, - int dest_left, - int dest_top, - int dest_width, - int dest_height, - const FX_RECT* pClipRect, - uint32_t flags, - int blend_type) { +bool CPSPrinterDriver::StretchDIBits(const CFX_DIBSource* pBitmap, + uint32_t color, + int dest_left, + int dest_top, + int dest_width, + int dest_height, + const FX_RECT* pClipRect, + uint32_t flags, + int blend_type) { if (blend_type != FXDIB_BLEND_NORMAL) return false; return m_PSRenderer.StretchDIBits(pBitmap, color, dest_left, dest_top, dest_width, dest_height, flags); } -bool CPSPrinterDriver::StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, +bool CPSPrinterDriver::StartDIBits(const CFX_DIBSource* pBitmap, int bitmap_alpha, uint32_t color, const CFX_Matrix* pMatrix, diff --git a/core/fxge/win32/win32_int.h b/core/fxge/win32/win32_int.h index 35521d0096..54ea3716e1 100644 --- a/core/fxge/win32/win32_int.h +++ b/core/fxge/win32/win32_int.h @@ -34,7 +34,7 @@ class CGdiplusExt { bool IsAvailable() { return !!m_hModule; } bool StretchBitMask(HDC hDC, BOOL bMonoDevice, - const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, + const CFX_DIBitmap* pBitmap, int dest_left, int dest_top, int dest_width, @@ -43,7 +43,7 @@ class CGdiplusExt { const FX_RECT* pClipRect, int flags); bool StretchDIBits(HDC hDC, - const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, + const CFX_DIBitmap* pBitmap, int dest_left, int dest_top, int dest_width, @@ -96,8 +96,7 @@ class CGdiplusExt { float font_size, int fontstyle); void GdipDeleteFont(void* pFont); - bool GdipCreateBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, - void** bitmap); + bool GdipCreateBitmap(CFX_DIBitmap* pBitmap, void** bitmap); void GdipDisposeImage(void* bitmap); void GdipGetFontSize(void* pFont, float* size); void* GdiAddFontMemResourceEx(void* pFontdata, @@ -105,7 +104,7 @@ class CGdiplusExt { void* pdv, uint32_t* num_face); bool GdiRemoveFontMemResourceEx(void* handle); - CFX_RetainPtr<CFX_DIBitmap> LoadDIBitmap(WINDIB_Open_Args_ args); + CFX_DIBitmap* LoadDIBitmap(WINDIB_Open_Args_ args); FARPROC m_Functions[100]; FuncType_GdiAddFontMemResourceEx m_pGdiAddFontMemResourceEx; @@ -159,17 +158,17 @@ class CGdiDeviceDriver : public IFX_RenderDeviceDriver { void DrawLine(float x1, float y1, float x2, float y2); - bool GDI_SetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, + bool GDI_SetDIBits(CFX_DIBitmap* pBitmap, const FX_RECT* pSrcRect, int left, int top); - bool GDI_StretchDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, + bool GDI_StretchDIBits(CFX_DIBitmap* pBitmap, int dest_left, int dest_top, int dest_width, int dest_height, uint32_t flags); - bool GDI_StretchBitMask(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, + bool GDI_StretchBitMask(CFX_DIBitmap* pBitmap, int dest_left, int dest_top, int dest_width, @@ -192,16 +191,14 @@ class CGdiDisplayDriver : public CGdiDeviceDriver { ~CGdiDisplayDriver() override; protected: - bool GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, - int left, - int top) override; - bool SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, + bool GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) override; + bool SetDIBits(const CFX_DIBSource* pBitmap, uint32_t color, const FX_RECT* pSrcRect, int left, int top, int blend_type) override; - bool StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, + bool StretchDIBits(const CFX_DIBSource* pBitmap, uint32_t color, int dest_left, int dest_top, @@ -210,14 +207,14 @@ class CGdiDisplayDriver : public CGdiDeviceDriver { const FX_RECT* pClipRect, uint32_t flags, int blend_type) override; - bool StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, + bool StartDIBits(const CFX_DIBSource* pBitmap, int bitmap_alpha, uint32_t color, const CFX_Matrix* pMatrix, uint32_t render_flags, void*& handle, int blend_type) override; - bool UseFoxitStretchEngine(const CFX_RetainPtr<CFX_DIBSource>& pSource, + bool UseFoxitStretchEngine(const CFX_DIBSource* pSource, uint32_t color, int dest_left, int dest_top, @@ -234,13 +231,13 @@ class CGdiPrinterDriver : public CGdiDeviceDriver { protected: int GetDeviceCaps(int caps_id) const override; - bool SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, + bool SetDIBits(const CFX_DIBSource* pBitmap, uint32_t color, const FX_RECT* pSrcRect, int left, int top, int blend_type) override; - bool StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, + bool StretchDIBits(const CFX_DIBSource* pBitmap, uint32_t color, int dest_left, int dest_top, @@ -249,7 +246,7 @@ class CGdiPrinterDriver : public CGdiDeviceDriver { const FX_RECT* pClipRect, uint32_t flags, int blend_type) override; - bool StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, + bool StartDIBits(const CFX_DIBSource* pBitmap, int bitmap_alpha, uint32_t color, const CFX_Matrix* pMatrix, @@ -293,13 +290,13 @@ class CPSPrinterDriver : public IFX_RenderDeviceDriver { int fill_mode, int blend_type) override; bool GetClipBox(FX_RECT* pRect) override; - bool SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, + bool SetDIBits(const CFX_DIBSource* pBitmap, uint32_t color, const FX_RECT* pSrcRect, int left, int top, int blend_type) override; - bool StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, + bool StretchDIBits(const CFX_DIBSource* pBitmap, uint32_t color, int dest_left, int dest_top, @@ -308,7 +305,7 @@ class CPSPrinterDriver : public IFX_RenderDeviceDriver { const FX_RECT* pClipRect, uint32_t flags, int blend_type) override; - bool StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, + bool StartDIBits(const CFX_DIBSource* pBitmap, int bitmap_alpha, uint32_t color, const CFX_Matrix* pMatrix, |