From 31b08d4cdaa17d7a03f35e087096a77036af98ec Mon Sep 17 00:00:00 2001 From: dsinclair Date: Tue, 28 Mar 2017 15:47:47 +0000 Subject: 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' ../../third_party/pdfium/core/fxge/skia/fx_skia_device.cpp:1861:42: error: no member named 'get' in 'CFX_RetainPtr' ../../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' 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 > Commit-Queue: dsinclair > 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 Commit-Queue: dsinclair --- core/fxge/skia/fx_skia_device.cpp | 151 ++++++++++++++--------------- core/fxge/skia/fx_skia_device.h | 30 +++--- core/fxge/skia/fx_skia_device_unittest.cpp | 2 +- 3 files changed, 90 insertions(+), 93 deletions(-) (limited to 'core/fxge/skia') 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& pBitmap, +void RgbByteOrderTransferBitmap(CFX_DIBitmap* pBitmap, int dest_left, int dest_top, int width, int height, - const CFX_RetainPtr& 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& bitmap, - const CFX_RetainPtr& 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& pSource, +bool Upsample(const CFX_DIBSource* pSource, std::unique_ptr& dst8Storage, std::unique_ptr& dst32Storage, SkColorTable** ctPtr, @@ -1197,11 +1197,10 @@ void CFX_SkiaDeviceDriver::PaintStroke(SkPaint* spaint, spaint->setStrokeJoin(join); } -CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver( - const CFX_RetainPtr& pBitmap, - bool bRgbByteOrder, - const CFX_RetainPtr& 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_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(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& 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& pBitmap, m_pBitmap->UnPreMultiply(); FX_RECT rect(left, top, left + pBitmap->GetWidth(), top + pBitmap->GetHeight()); - CFX_RetainPtr pBack; + std::unique_ptr pBack; if (m_pOriDevice) { pBack = m_pOriDevice->Clone(&rect); if (!pBack) @@ -1864,17 +1863,16 @@ bool CFX_SkiaDeviceDriver::GetDIBits(const CFX_RetainPtr& pBitmap, #endif // _SKIA_SUPPORT_PATHS_ } -CFX_RetainPtr CFX_SkiaDeviceDriver::GetBackDrop() { +CFX_DIBitmap* CFX_SkiaDeviceDriver::GetBackDrop() { return m_pOriDevice; } -bool CFX_SkiaDeviceDriver::SetDIBits( - const CFX_RetainPtr& 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& 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& 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& 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& pSource, - const CFX_RetainPtr& 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& pBitmap, - const CFX_RetainPtr& 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& pBitmap, +bool CFX_FxgeDevice::Attach(CFX_DIBitmap* pBitmap, bool bRgbByteOrder, - const CFX_RetainPtr& 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& pOriDevice) { - auto pBitmap = pdfium::MakeRetain(); + 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& pBitmap, - const CFX_RetainPtr& 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(GetDeviceDriver()); if (skDriver) @@ -2285,10 +2284,10 @@ class CFX_Renderer { uint32_t m_Color; bool m_bFullCover; bool m_bRgbByteOrder; - const CFX_RetainPtr& m_pOriDevice; + CFX_DIBitmap* m_pOriDevice; FX_RECT m_ClipBox; - const CFX_RetainPtr& m_pClipMask; - const CFX_RetainPtr& 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 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& pDevice, - const CFX_RetainPtr& 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& pBitmap, + CFX_SkiaDeviceDriver(CFX_DIBitmap* pBitmap, bool bRgbByteOrder, - const CFX_RetainPtr& 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& pBitmap, - int left, - int top) override; + bool GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) override; - CFX_RetainPtr GetBackDrop() override; + CFX_DIBitmap* GetBackDrop() override; - bool SetDIBits(const CFX_RetainPtr& 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& pBitmap, - const CFX_RetainPtr& 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& 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& 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& pBitmap, - const CFX_RetainPtr& 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& 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 m_pBitmap; - CFX_RetainPtr m_pOriDevice; + CFX_DIBitmap* m_pBitmap; + CFX_DIBitmap* m_pOriDevice; SkCanvas* m_pCanvas; SkPictureRecorder* const m_pRecorder; std::unique_ptr m_pCache; diff --git a/core/fxge/skia/fx_skia_device_unittest.cpp b/core/fxge/skia/fx_skia_device_unittest.cpp index 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 pBitmap(CFXBitmapFromFPDFBitmap(bitmap)); + CFX_DIBitmap* pBitmap = CFXBitmapFromFPDFBitmap(bitmap); geDevice.Attach(pBitmap, false, nullptr, false); CFX_SkiaDeviceDriver* driver = static_cast(geDevice.GetDeviceDriver()); -- cgit v1.2.3