From 2aa4b2f3928ccd8393f60db8f7b740c75f4e8a8d Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Fri, 25 May 2018 22:38:49 +0000 Subject: Make CPDF_Page retainable. Small step to reducing the differences between XFA and non-XFA. We still use the RetainPtr pretty much as if it were an unique_ptr, in that we're not yet caching pages and handing out multiple pointers to the same page in the non-XFA case. The one change is in page view cleanup, where we no longer need a boolean and can take (sufficient) page ownership with a RetainPtr. Tidy up some document.h -> page.h -> document.h circular inclusion while we're at it. NOTE: Wait for imminent branch to pass before landing. We'll want this to bake a while. Change-Id: I64a2f12ac3424ece1063d40583995b834117cf34 Reviewed-on: https://pdfium-review.googlesource.com/32790 Reviewed-by: dsinclair Reviewed-by: Lei Zhang Commit-Queue: Tom Sepez --- fpdfsdk/fpdf_view.cpp | 49 +++++++++++++++++++++---------------------------- 1 file changed, 21 insertions(+), 28 deletions(-) (limited to 'fpdfsdk/fpdf_view.cpp') diff --git a/fpdfsdk/fpdf_view.cpp b/fpdfsdk/fpdf_view.cpp index 6c4ad6020e..593a092fd3 100644 --- a/fpdfsdk/fpdf_view.cpp +++ b/fpdfsdk/fpdf_view.cpp @@ -355,9 +355,9 @@ FPDF_EXPORT FPDF_PAGE FPDF_CALLCONV FPDF_LoadPage(FPDF_DOCUMENT document, if (!pDict) return nullptr; - CPDF_Page* pPage = new CPDF_Page(pDoc, pDict, true); + auto pPage = pdfium::MakeRetain(pDoc, pDict, true); pPage->ParseContent(); - return FPDFPageFromUnderlying(pPage); + return FPDFPageFromUnderlying(pPage.Leak()); #endif // PDF_ENABLE_XFA } @@ -723,35 +723,28 @@ FPDF_EXPORT FPDF_RECORDER FPDF_CALLCONV FPDF_RenderPageSkp(FPDF_PAGE page, #endif FPDF_EXPORT void FPDF_CALLCONV FPDF_ClosePage(FPDF_PAGE page) { - UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); if (!page) return; -#ifdef PDF_ENABLE_XFA - // Take it back across the API and throw it away. - RetainPtr().Unleak(pPage); -#else // PDF_ENABLE_XFA + + // Take it back across the API and hold for duration of this function. + RetainPtr pPage; + pPage.Unleak(UnderlyingFromFPDFPage(page)); + +#ifndef PDF_ENABLE_XFA CPDFSDK_PageView* pPageView = static_cast(pPage->GetView()); - if (pPageView) { - // We're already destroying the pageview, so bail early. - if (pPageView->IsBeingDestroyed()) - return; - - if (pPageView->IsLocked()) { - pPageView->TakePageOwnership(); - return; - } + if (!pPageView || pPageView->IsBeingDestroyed()) + return; - bool owned = pPageView->OwnsPage(); - // This will delete the |pPageView| object. We must cleanup the PageView - // first because it will attempt to reset the View on the |pPage| during - // destruction. - pPageView->GetFormFillEnv()->RemovePageView(pPage); - // If the page was owned then the pageview will have deleted the page. - if (owned) - return; + if (pPageView->IsLocked()) { + pPageView->TakePageOwnership(); + return; } - delete pPage; + + // This will delete the |pPageView| object. We must cleanup the PageView + // first because it will attempt to reset the View on the |pPage| during + // destruction. + pPageView->GetFormFillEnv()->RemovePageView(pPage.Get()); #endif // PDF_ENABLE_XFA } @@ -970,9 +963,9 @@ FPDF_EXPORT int FPDF_CALLCONV FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document, if (!pDict) return false; - CPDF_Page page(pDoc, pDict, true); - *width = page.GetPageWidth(); - *height = page.GetPageHeight(); + auto page = pdfium::MakeRetain(pDoc, pDict, true); + *width = page->GetPageWidth(); + *height = page->GetPageHeight(); return true; } -- cgit v1.2.3