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 --- fpdfsdk/fpdf_progressive.cpp | 15 +++++---------- fpdfsdk/fpdfeditimg.cpp | 3 +-- fpdfsdk/fpdfformfill.cpp | 7 +++---- fpdfsdk/fpdfview.cpp | 38 ++++++++++++++++++-------------------- 4 files changed, 27 insertions(+), 36 deletions(-) (limited to 'fpdfsdk') diff --git a/fpdfsdk/fpdf_progressive.cpp b/fpdfsdk/fpdf_progressive.cpp index 927bcddd09..cc09d07638 100644 --- a/fpdfsdk/fpdf_progressive.cpp +++ b/fpdfsdk/fpdf_progressive.cpp @@ -6,8 +6,6 @@ #include "public/fpdf_progressive.h" -#include - #include "core/fpdfapi/cpdf_pagerendercontext.h" #include "core/fpdfapi/page/cpdf_page.h" #include "core/fpdfapi/render/cpdf_progressiverenderer.h" @@ -46,14 +44,11 @@ DLLEXPORT int STDCALL FPDF_RenderPageBitmap_Start(FPDF_BITMAP bitmap, if (!pPage) return FPDF_RENDER_FAILED; - auto pOwnedContext = pdfium::MakeUnique(); - CPDF_PageRenderContext* pContext = pOwnedContext.get(); - pPage->SetRenderContext(std::move(pOwnedContext)); - - CFX_RetainPtr pBitmap(CFXBitmapFromFPDFBitmap(bitmap)); - auto pOwnedDevice = pdfium::MakeUnique(); - CFX_FxgeDevice* pDevice = pOwnedDevice.get(); - pContext->m_pDevice = std::move(pOwnedDevice); + CPDF_PageRenderContext* pContext = new CPDF_PageRenderContext; + pPage->SetRenderContext(pdfium::WrapUnique(pContext)); + CFX_FxgeDevice* pDevice = new CFX_FxgeDevice; + pContext->m_pDevice.reset(pDevice); + CFX_DIBitmap* pBitmap = CFXBitmapFromFPDFBitmap(bitmap); pDevice->Attach(pBitmap, !!(flags & FPDF_REVERSE_BYTE_ORDER), nullptr, false); IFSDK_PAUSE_Adapter IPauseAdapter(pause); diff --git a/fpdfsdk/fpdfeditimg.cpp b/fpdfsdk/fpdfeditimg.cpp index ca78088793..69151d1999 100644 --- a/fpdfsdk/fpdfeditimg.cpp +++ b/fpdfsdk/fpdfeditimg.cpp @@ -105,8 +105,7 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetBitmap(FPDF_PAGE* pages, if (pPage) pImgObj->GetImage()->ResetCache(pPage, nullptr); } - CFX_RetainPtr holder(CFXBitmapFromFPDFBitmap(bitmap)); - pImgObj->GetImage()->SetImage(holder); + pImgObj->GetImage()->SetImage(reinterpret_cast(bitmap)); pImgObj->CalcBoundingBox(); return true; } diff --git a/fpdfsdk/fpdfformfill.cpp b/fpdfsdk/fpdfformfill.cpp index 6e31e1f045..c2bbeff7e3 100644 --- a/fpdfsdk/fpdfformfill.cpp +++ b/fpdfsdk/fpdfformfill.cpp @@ -109,12 +109,11 @@ void FFLCommon(FPDF_FORMHANDLE hHandle, pPage->GetDisplayMatrix(start_x, start_y, size_x, size_y, rotate); FX_RECT clip(start_x, start_y, start_x + size_x, start_y + size_y); - auto pDevice = pdfium::MakeUnique(); + std::unique_ptr pDevice(new CFX_FxgeDevice); #ifdef _SKIA_SUPPORT_ pDevice->AttachRecorder(static_cast(recorder)); #endif - CFX_RetainPtr holder(CFXBitmapFromFPDFBitmap(bitmap)); - pDevice->Attach(holder, false, nullptr, false); + pDevice->Attach(CFXBitmapFromFPDFBitmap(bitmap), false, nullptr, false); pDevice->SaveState(); pDevice->SetClip_Rect(clip); @@ -148,7 +147,7 @@ void FFLCommon(FPDF_FORMHANDLE hHandle, pDevice->RestoreState(false); #ifdef _SKIA_SUPPORT_PATHS_ pDevice->Flush(); - holder->UnPreMultiply(); + CFXBitmapFromFPDFBitmap(bitmap)->UnPreMultiply(); #endif } diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp index dcfa1c1925..d4284a3217 100644 --- a/fpdfsdk/fpdfview.cpp +++ b/fpdfsdk/fpdfview.cpp @@ -709,39 +709,41 @@ DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, CPDF_PageRenderContext* pContext = new CPDF_PageRenderContext; pPage->SetRenderContext(pdfium::WrapUnique(pContext)); - CFX_RetainPtr pBitmap; + std::unique_ptr pBitmap; // TODO: This results in unnecessary rasterization of some PDFs due to // HasImageMask() returning true. If any image on the page is a mask, the // entire page gets rasterized and the spool size gets huge. const bool bNewBitmap = pPage->BackgroundAlphaNeeded() || pPage->HasImageMask(); if (bNewBitmap) { - pBitmap = pdfium::MakeRetain(); + pBitmap = pdfium::MakeUnique(); pBitmap->Create(size_x, size_y, FXDIB_Argb); pBitmap->Clear(0x00ffffff); CFX_FxgeDevice* pDevice = new CFX_FxgeDevice; pContext->m_pDevice = pdfium::WrapUnique(pDevice); - pDevice->Attach(pBitmap, false, nullptr, false); + pDevice->Attach(pBitmap.get(), false, nullptr, false); } else { pContext->m_pDevice = pdfium::MakeUnique(dc); } + FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, rotate, flags, true, nullptr); if (bNewBitmap) { CFX_WindowsDevice WinDC(dc); if (WinDC.GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINTER) { - auto pDst = pdfium::MakeRetain(); + std::unique_ptr pDst = pdfium::MakeUnique(); int pitch = pBitmap->GetPitch(); pDst->Create(size_x, size_y, FXDIB_Rgb32); FXSYS_memset(pDst->GetBuffer(), -1, pitch * size_y); - pDst->CompositeBitmap(0, 0, size_x, size_y, pBitmap, 0, 0, + pDst->CompositeBitmap(0, 0, size_x, size_y, pBitmap.get(), 0, 0, FXDIB_BLEND_NORMAL, nullptr, false, nullptr); - WinDC.StretchDIBits(pDst, 0, 0, size_x, size_y); + WinDC.StretchDIBits(pDst.get(), 0, 0, size_x, size_y); } else { - WinDC.SetDIBits(pBitmap, 0, 0); + WinDC.SetDIBits(pBitmap.get(), 0, 0); } } + pPage->SetRenderContext(nullptr); } #endif // defined(_WIN32) @@ -763,12 +765,11 @@ DLLEXPORT void STDCALL FPDF_RenderPageBitmap(FPDF_BITMAP bitmap, CPDF_PageRenderContext* pContext = new CPDF_PageRenderContext; pPage->SetRenderContext(pdfium::WrapUnique(pContext)); - CFX_FxgeDevice* pDevice = new CFX_FxgeDevice; pContext->m_pDevice.reset(pDevice); - - CFX_RetainPtr pBitmap(CFXBitmapFromFPDFBitmap(bitmap)); + CFX_DIBitmap* pBitmap = CFXBitmapFromFPDFBitmap(bitmap); pDevice->Attach(pBitmap, !!(flags & FPDF_REVERSE_BYTE_ORDER), nullptr, false); + FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, rotate, flags, true, nullptr); @@ -793,11 +794,9 @@ DLLEXPORT void STDCALL FPDF_RenderPageBitmapWithMatrix(FPDF_BITMAP bitmap, CPDF_PageRenderContext* pContext = new CPDF_PageRenderContext; pPage->SetRenderContext(pdfium::WrapUnique(pContext)); - CFX_FxgeDevice* pDevice = new CFX_FxgeDevice; pContext->m_pDevice.reset(pDevice); - - CFX_RetainPtr pBitmap(CFXBitmapFromFPDFBitmap(bitmap)); + CFX_DIBitmap* pBitmap = CFXBitmapFromFPDFBitmap(bitmap); pDevice->Attach(pBitmap, !!(flags & FPDF_REVERSE_BYTE_ORDER), nullptr, false); CFX_Matrix transform_matrix = pPage->GetPageMatrix(); @@ -941,11 +940,11 @@ DLLEXPORT void STDCALL FPDF_PageToDevice(FPDF_PAGE page, DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_Create(int width, int height, int alpha) { - auto pBitmap = pdfium::MakeRetain(); + auto pBitmap = pdfium::MakeUnique(); if (!pBitmap->Create(width, height, alpha ? FXDIB_Argb : FXDIB_Rgb32)) return nullptr; - return pBitmap.Leak(); + return pBitmap.release(); } DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_CreateEx(int width, @@ -970,9 +969,9 @@ DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_CreateEx(int width, default: return nullptr; } - auto pBitmap = pdfium::MakeRetain(); + CFX_DIBitmap* pBitmap = new CFX_DIBitmap; pBitmap->Create(width, height, fx_format, (uint8_t*)first_scan, stride); - return pBitmap.Leak(); + return pBitmap; } DLLEXPORT void STDCALL FPDFBitmap_FillRect(FPDF_BITMAP bitmap, @@ -985,7 +984,7 @@ DLLEXPORT void STDCALL FPDFBitmap_FillRect(FPDF_BITMAP bitmap, return; CFX_FxgeDevice device; - CFX_RetainPtr pBitmap(CFXBitmapFromFPDFBitmap(bitmap)); + CFX_DIBitmap* pBitmap = CFXBitmapFromFPDFBitmap(bitmap); device.Attach(pBitmap, false, nullptr, false); if (!pBitmap->HasAlpha()) color |= 0xFF000000; @@ -1010,8 +1009,7 @@ DLLEXPORT int STDCALL FPDFBitmap_GetStride(FPDF_BITMAP bitmap) { } DLLEXPORT void STDCALL FPDFBitmap_Destroy(FPDF_BITMAP bitmap) { - CFX_RetainPtr destroyer; - destroyer.Unleak(CFXBitmapFromFPDFBitmap(bitmap)); + delete CFXBitmapFromFPDFBitmap(bitmap); } void FPDF_RenderPage_Retail(CPDF_PageRenderContext* pContext, -- cgit v1.2.3