diff options
author | Tom Sepez <tsepez@chromium.org> | 2017-03-28 09:31:32 -0700 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-03-28 16:42:55 +0000 |
commit | f0799fe84df4d86f25d342b03525f3016d674f86 (patch) | |
tree | d6839802a68b7b6ad6fb166179ede779c3560c75 /core/fxge/agg | |
parent | 31b08d4cdaa17d7a03f35e087096a77036af98ec (diff) | |
download | pdfium-f0799fe84df4d86f25d342b03525f3016d674f86.tar.xz |
Revert "Revert "Refcount all CFX_DIBSources (and subclasses) all the time.""
This reverts commit 31b08d4cdaa17d7a03f35e087096a77036af98ec.
Re-landing the patch after fixing skia build issue.
Change-Id: Ie7039890088b803a6ec5ce365d70f57277459b48
Reviewed-on: https://pdfium-review.googlesource.com/3245
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fxge/agg')
-rw-r--r-- | core/fxge/agg/fx_agg_driver.cpp | 135 | ||||
-rw-r--r-- | core/fxge/agg/fx_agg_driver.h | 20 |
2 files changed, 79 insertions, 76 deletions
diff --git a/core/fxge/agg/fx_agg_driver.cpp b/core/fxge/agg/fx_agg_driver.cpp index b435c032bc..ad7d2c4517 100644 --- a/core/fxge/agg/fx_agg_driver.cpp +++ b/core/fxge/agg/fx_agg_driver.cpp @@ -35,7 +35,10 @@ CFX_PointF HardClip(const CFX_PointF& pos) { pdfium::clamp(pos.y, -kMaxPos, kMaxPos)); } -void RgbByteOrderSetPixel(CFX_DIBitmap* pBitmap, int x, int y, uint32_t argb) { +void RgbByteOrderSetPixel(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, + int x, + int y, + uint32_t argb) { if (x < 0 || x >= pBitmap->GetWidth() || y < 0 || y >= pBitmap->GetHeight()) return; @@ -52,7 +55,7 @@ void RgbByteOrderSetPixel(CFX_DIBitmap* pBitmap, int x, int y, uint32_t argb) { pos[2] = (FXARGB_B(argb) * alpha + pos[2] * (255 - alpha)) / 255; } -void RgbByteOrderCompositeRect(CFX_DIBitmap* pBitmap, +void RgbByteOrderCompositeRect(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, int left, int top, int width, @@ -127,12 +130,12 @@ void RgbByteOrderCompositeRect(CFX_DIBitmap* pBitmap, } } -void RgbByteOrderTransferBitmap(CFX_DIBitmap* pBitmap, +void RgbByteOrderTransferBitmap(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, int dest_left, int dest_top, int width, int height, - const CFX_DIBSource* pSrcBitmap, + const CFX_RetainPtr<CFX_DIBSource>& pSrcBitmap, int src_left, int src_top) { if (!pBitmap) @@ -232,7 +235,7 @@ FX_ARGB DefaultCMYK2ARGB(FX_CMYK cmyk, uint8_t alpha) { return ArgbEncode(alpha, r, g, b); } -bool DibSetPixel(CFX_DIBitmap* pDevice, +bool DibSetPixel(const CFX_RetainPtr<CFX_DIBitmap>& pDevice, int x, int y, uint32_t color, @@ -398,8 +401,8 @@ class CFX_Renderer { uint8_t* clip_scan, uint8_t* dest_extra_alpha_scan); - bool Init(CFX_DIBitmap* pDevice, - CFX_DIBitmap* pOriDevice, + bool Init(const CFX_RetainPtr<CFX_DIBitmap>& pDevice, + const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice, const CFX_ClipRgn* pClipRgn, uint32_t color, bool bFullCover, @@ -456,10 +459,10 @@ class CFX_Renderer { uint32_t m_Color; bool m_bFullCover; bool m_bRgbByteOrder; - CFX_DIBitmap* m_pOriDevice; FX_RECT m_ClipBox; - const CFX_DIBitmap* m_pClipMask; - CFX_DIBitmap* m_pDevice; + CFX_RetainPtr<CFX_DIBitmap> m_pOriDevice; + CFX_RetainPtr<CFX_DIBitmap> m_pClipMask; + CFX_RetainPtr<CFX_DIBitmap> m_pDevice; const CFX_ClipRgn* m_pClipRgn; }; @@ -899,8 +902,8 @@ void CFX_Renderer::CompositeSpanCMYK(uint8_t* dest_scan, } } -bool CFX_Renderer::Init(CFX_DIBitmap* pDevice, - CFX_DIBitmap* pOriDevice, +bool CFX_Renderer::Init(const CFX_RetainPtr<CFX_DIBitmap>& pDevice, + const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice, const CFX_ClipRgn* pClipRgn, uint32_t color, bool bFullCover, @@ -921,7 +924,7 @@ bool CFX_Renderer::Init(CFX_DIBitmap* pDevice, } m_pClipMask = nullptr; if (m_pClipRgn && m_pClipRgn->GetType() == CFX_ClipRgn::MaskF) - m_pClipMask = m_pClipRgn->GetMask().GetObject(); + m_pClipMask = m_pClipRgn->GetMask(); m_bFullCover = bFullCover; bool bObjectCMYK = !!FXGETFLAG_COLORTYPE(alpha_flag); bool bDeviceCMYK = pDevice->IsCmykImage(); @@ -1038,7 +1041,7 @@ void CFX_Renderer::render(const Scanline& sl) { uint8_t* dest_scan = m_pDevice->GetBuffer() + m_pDevice->GetPitch() * y; uint8_t* dest_scan_extra_alpha = nullptr; - CFX_DIBitmap* pAlphaMask = m_pDevice->m_pAlphaMask; + CFX_RetainPtr<CFX_DIBitmap> pAlphaMask = m_pDevice->m_pAlphaMask; if (pAlphaMask) { dest_scan_extra_alpha = pAlphaMask->GetBuffer() + pAlphaMask->GetPitch() * y; @@ -1199,10 +1202,11 @@ void CAgg_PathData::BuildPath(const CFX_PathData* pPathData, } } -CFX_AggDeviceDriver::CFX_AggDeviceDriver(CFX_DIBitmap* pBitmap, - bool bRgbByteOrder, - CFX_DIBitmap* pOriDevice, - bool bGroupKnockout) +CFX_AggDeviceDriver::CFX_AggDeviceDriver( + const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, + bool bRgbByteOrder, + const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice, + bool bGroupKnockout) : m_pBitmap(pBitmap), #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ m_pPlatformGraphics(nullptr), @@ -1296,8 +1300,7 @@ void CFX_AggDeviceDriver::SetClipMask(agg::rasterizer_scanline_aa& rasterizer) { FX_RECT path_rect(rasterizer.min_x(), rasterizer.min_y(), rasterizer.max_x() + 1, rasterizer.max_y() + 1); path_rect.Intersect(m_pClipRgn->GetBox()); - CFX_DIBitmapRef mask; - CFX_DIBitmap* pThisLayer = mask.Emplace(); + auto pThisLayer = pdfium::MakeRetain<CFX_DIBitmap>(); pThisLayer->Create(path_rect.Width(), path_rect.Height(), FXDIB_8bppMask); pThisLayer->Clear(0); agg::rendering_buffer raw_buf(pThisLayer->GetBuffer(), pThisLayer->GetWidth(), @@ -1311,7 +1314,7 @@ void CFX_AggDeviceDriver::SetClipMask(agg::rasterizer_scanline_aa& rasterizer) { agg::scanline_u8 scanline; agg::render_scanlines(rasterizer, scanline, final_render, (m_FillFlags & FXFILL_NOPATHSMOOTH) != 0); - m_pClipRgn->IntersectMaskF(path_rect.left, path_rect.top, mask); + m_pClipRgn->IntersectMaskF(path_rect.left, path_rect.top, pThisLayer); } bool CFX_AggDeviceDriver::SetClip_PathFill(const CFX_PathData* pPathData, @@ -1381,7 +1384,7 @@ bool CFX_AggDeviceDriver::RenderRasterizer( bool bGroupKnockout, int alpha_flag, void* pIccTransform) { - CFX_DIBitmap* pt = bGroupKnockout ? m_pOriDevice : nullptr; + CFX_RetainPtr<CFX_DIBitmap> pt = bGroupKnockout ? m_pOriDevice : nullptr; CFX_Renderer render; if (!render.Init(m_pBitmap, pt, m_pClipRgn.get(), color, bFullCover, m_bRgbByteOrder, alpha_flag, pIccTransform)) { @@ -1492,8 +1495,8 @@ bool CFX_AggDeviceDriver::SetPixel(int x, int y, uint32_t color) { if (m_pClipRgn->GetType() != CFX_ClipRgn::MaskF) return true; - const CFX_DIBitmap* pMask = m_pClipRgn->GetMask().GetObject(); - int new_alpha = FXARGB_A(color) * pMask->GetScanline(y)[x] / 255; + int new_alpha = + FXARGB_A(color) * m_pClipRgn->GetMask()->GetScanline(y)[x] / 255; color = (color & 0xffffff) | (new_alpha << 24); if (m_bRgbByteOrder) { RgbByteOrderSetPixel(m_pBitmap, x, y, color); @@ -1530,11 +1533,11 @@ bool CFX_AggDeviceDriver::FillRectWithBlend(const FX_RECT* pRect, } return true; } - m_pBitmap->CompositeMask( - draw_rect.left, draw_rect.top, draw_rect.Width(), draw_rect.Height(), - m_pClipRgn->GetMask().GetObject(), fill_color, - draw_rect.left - clip_rect.left, draw_rect.top - clip_rect.top, - FXDIB_BLEND_NORMAL, nullptr, m_bRgbByteOrder, 0, nullptr); + m_pBitmap->CompositeMask(draw_rect.left, draw_rect.top, draw_rect.Width(), + draw_rect.Height(), m_pClipRgn->GetMask(), + fill_color, draw_rect.left - clip_rect.left, + draw_rect.top - clip_rect.top, FXDIB_BLEND_NORMAL, + nullptr, m_bRgbByteOrder, 0, nullptr); return true; } @@ -1549,13 +1552,15 @@ bool CFX_AggDeviceDriver::GetClipBox(FX_RECT* pRect) { return true; } -bool CFX_AggDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) { +bool CFX_AggDeviceDriver::GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, + int left, + int top) { if (!m_pBitmap || !m_pBitmap->GetBuffer()) return true; FX_RECT rect(left, top, left + pBitmap->GetWidth(), top + pBitmap->GetHeight()); - std::unique_ptr<CFX_DIBitmap> pBack; + CFX_RetainPtr<CFX_DIBitmap> pBack; if (m_pOriDevice) { pBack = m_pOriDevice->Clone(&rect); if (!pBack) @@ -1573,18 +1578,18 @@ bool CFX_AggDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) { top = std::min(top, 0); if (m_bRgbByteOrder) { RgbByteOrderTransferBitmap(pBitmap, 0, 0, rect.Width(), rect.Height(), - pBack.get(), left, top); + pBack, left, top); return true; } - return pBitmap->TransferBitmap(0, 0, rect.Width(), rect.Height(), pBack.get(), - left, top); + return pBitmap->TransferBitmap(0, 0, rect.Width(), rect.Height(), pBack, left, + top); } -CFX_DIBitmap* CFX_AggDeviceDriver::GetBackDrop() { +CFX_RetainPtr<CFX_DIBitmap> CFX_AggDeviceDriver::GetBackDrop() { return m_pOriDevice; } -bool CFX_AggDeviceDriver::SetDIBits(const CFX_DIBSource* pBitmap, +bool CFX_AggDeviceDriver::SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, uint32_t argb, const FX_RECT* pSrcRect, int left, @@ -1604,15 +1609,16 @@ bool CFX_AggDeviceDriver::SetDIBits(const CFX_DIBSource* pBitmap, pSrcRect->top, blend_type, m_pClipRgn.get(), m_bRgbByteOrder, nullptr); } -bool CFX_AggDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource, - uint32_t argb, - int dest_left, - int dest_top, - int dest_width, - int dest_height, - const FX_RECT* pClipRect, - uint32_t flags, - int blend_type) { +bool CFX_AggDeviceDriver::StretchDIBits( + const CFX_RetainPtr<CFX_DIBSource>& pSource, + uint32_t argb, + int dest_left, + int dest_top, + int dest_width, + int dest_height, + const FX_RECT* pClipRect, + uint32_t flags, + int blend_type) { if (!m_pBitmap->GetBuffer()) return true; @@ -1637,13 +1643,14 @@ bool CFX_AggDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource, return true; } -bool CFX_AggDeviceDriver::StartDIBits(const CFX_DIBSource* pSource, - int bitmap_alpha, - uint32_t argb, - const CFX_Matrix* pMatrix, - uint32_t render_flags, - void*& handle, - int blend_type) { +bool CFX_AggDeviceDriver::StartDIBits( + const CFX_RetainPtr<CFX_DIBSource>& pSource, + int bitmap_alpha, + uint32_t argb, + const CFX_Matrix* pMatrix, + uint32_t render_flags, + void*& handle, + int blend_type) { if (!m_pBitmap->GetBuffer()) return true; @@ -1668,13 +1675,13 @@ void CFX_AggDeviceDriver::CancelDIBits(void* pHandle) { } #ifndef _SKIA_SUPPORT_ -CFX_FxgeDevice::CFX_FxgeDevice() { - m_bOwnedBitmap = false; -} +CFX_FxgeDevice::CFX_FxgeDevice() {} + +CFX_FxgeDevice::~CFX_FxgeDevice() {} -bool CFX_FxgeDevice::Attach(CFX_DIBitmap* pBitmap, +bool CFX_FxgeDevice::Attach(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, bool bRgbByteOrder, - CFX_DIBitmap* pOriDevice, + const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice, bool bGroupKnockout) { if (!pBitmap) return false; @@ -1688,21 +1695,15 @@ bool CFX_FxgeDevice::Attach(CFX_DIBitmap* pBitmap, bool CFX_FxgeDevice::Create(int width, int height, FXDIB_Format format, - CFX_DIBitmap* pOriDevice) { - m_bOwnedBitmap = true; - CFX_DIBitmap* pBitmap = new CFX_DIBitmap; - if (!pBitmap->Create(width, height, format)) { - delete pBitmap; + const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice) { + auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>(); + if (!pBitmap->Create(width, height, format)) return false; - } + SetBitmap(pBitmap); SetDeviceDriver(pdfium::MakeUnique<CFX_AggDeviceDriver>(pBitmap, false, pOriDevice, false)); return true; } -CFX_FxgeDevice::~CFX_FxgeDevice() { - if (m_bOwnedBitmap) - delete GetBitmap(); -} #endif diff --git a/core/fxge/agg/fx_agg_driver.h b/core/fxge/agg/fx_agg_driver.h index 7b4c7209e8..723ed6d98a 100644 --- a/core/fxge/agg/fx_agg_driver.h +++ b/core/fxge/agg/fx_agg_driver.h @@ -32,9 +32,9 @@ class CAgg_PathData { class CFX_AggDeviceDriver : public IFX_RenderDeviceDriver { public: - CFX_AggDeviceDriver(CFX_DIBitmap* pBitmap, + CFX_AggDeviceDriver(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, bool bRgbByteOrder, - CFX_DIBitmap* pOriDevice, + const CFX_RetainPtr<CFX_DIBitmap>& pOriDevice, bool bGroupKnockout); ~CFX_AggDeviceDriver() override; @@ -63,15 +63,17 @@ class CFX_AggDeviceDriver : public IFX_RenderDeviceDriver { uint32_t fill_color, int blend_type) override; bool GetClipBox(FX_RECT* pRect) override; - bool GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) override; - CFX_DIBitmap* GetBackDrop() override; - bool SetDIBits(const CFX_DIBSource* pBitmap, + bool GetDIBits(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap, + int left, + int top) override; + CFX_RetainPtr<CFX_DIBitmap> GetBackDrop() override; + bool SetDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, uint32_t color, const FX_RECT* pSrcRect, int left, int top, int blend_type) override; - bool StretchDIBits(const CFX_DIBSource* pBitmap, + bool StretchDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, uint32_t color, int dest_left, int dest_top, @@ -80,7 +82,7 @@ class CFX_AggDeviceDriver : public IFX_RenderDeviceDriver { const FX_RECT* pClipRect, uint32_t flags, int blend_type) override; - bool StartDIBits(const CFX_DIBSource* pBitmap, + bool StartDIBits(const CFX_RetainPtr<CFX_DIBSource>& pBitmap, int bitmap_alpha, uint32_t color, const CFX_Matrix* pMatrix, @@ -109,7 +111,7 @@ class CFX_AggDeviceDriver : public IFX_RenderDeviceDriver { virtual uint8_t* GetBuffer() const; private: - CFX_DIBitmap* m_pBitmap; + CFX_RetainPtr<CFX_DIBitmap> m_pBitmap; std::unique_ptr<CFX_ClipRgn> m_pClipRgn; std::vector<std::unique_ptr<CFX_ClipRgn>> m_StateStack; #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ @@ -117,7 +119,7 @@ class CFX_AggDeviceDriver : public IFX_RenderDeviceDriver { #endif int m_FillFlags; bool m_bRgbByteOrder; - CFX_DIBitmap* m_pOriDevice; + CFX_RetainPtr<CFX_DIBitmap> m_pOriDevice; bool m_bGroupKnockout; }; |