diff options
author | tsepez <tsepez@chromium.org> | 2016-05-25 14:58:09 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-05-25 14:58:09 -0700 |
commit | 1e2c557e0fa0e47c8bafdb31c833ea4f90f5fedd (patch) | |
tree | 86c90cdb10f3c478570934816a56070ed6d51260 /fpdfsdk/fpdfview.cpp | |
parent | edfd3c3d6a56bee2456e96df4b945c095ea3a290 (diff) | |
download | pdfium-1e2c557e0fa0e47c8bafdb31c833ea4f90f5fedd.tar.xz |
Remove CFX_PrivateData from CPDF_Page
CFX_PrivateData served two purposes here:
The first was to hold an opaque pointer to the corresponding
page structure in the next higher layer, of which it knows
no details. Introduce an empty CPDF_Page::View class to
represent this higher class, so as to get type safety while
preserving layering.
The second was to hold an opaque render context, which it
also happened to own. Make this a CFX_Deletable to help
with management.
Also remove an unused inheritance from CFX_PrivateData
in CPDF_Annot.
Review-Url: https://codereview.chromium.org/2008553008
Diffstat (limited to 'fpdfsdk/fpdfview.cpp')
-rw-r--r-- | fpdfsdk/fpdfview.cpp | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp index cdcaba4318..bf7ae0f5c2 100644 --- a/fpdfsdk/fpdfview.cpp +++ b/fpdfsdk/fpdfview.cpp @@ -517,10 +517,6 @@ DLLEXPORT double STDCALL FPDF_GetPageHeight(FPDF_PAGE page) { return pPage ? pPage->GetPageHeight() : 0.0; } -void DropContext(void* data) { - delete (CRenderContext*)data; -} - #if defined(_WIN32) DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, FPDF_PAGE page, @@ -535,7 +531,7 @@ DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, return; CRenderContext* pContext = new CRenderContext; - pPage->SetPrivateData((void*)1, pContext, DropContext); + pPage->SetRenderContext(std::unique_ptr<CFX_Deletable>(pContext)); #if !defined(_WIN32_WCE) CFX_DIBitmap* pBitmap = nullptr; @@ -619,8 +615,7 @@ DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, if (bBackgroundAlphaNeeded || bHasImageMask) delete pBitmap; - delete pContext; - pPage->RemovePrivateData((void*)1); + pPage->SetRenderContext(std::unique_ptr<CFX_Deletable>()); } #endif // defined(_WIN32) @@ -634,24 +629,25 @@ DLLEXPORT void STDCALL FPDF_RenderPageBitmap(FPDF_BITMAP bitmap, int flags) { if (!bitmap) return; + CPDF_Page* pPage = CPDFPageFromFPDFPage(page); if (!pPage) return; + CRenderContext* pContext = new CRenderContext; - pPage->SetPrivateData((void*)1, pContext, DropContext); + pPage->SetRenderContext(std::unique_ptr<CFX_Deletable>(pContext)); pContext->m_pDevice = new CFX_FxgeDevice; - - if (flags & FPDF_REVERSE_BYTE_ORDER) + if (flags & FPDF_REVERSE_BYTE_ORDER) { ((CFX_FxgeDevice*)pContext->m_pDevice) ->Attach((CFX_DIBitmap*)bitmap, 0, TRUE); - else + } else { ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap); + } FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, - rotate, flags, TRUE, NULL); + rotate, flags, TRUE, nullptr); - delete pContext; - pPage->RemovePrivateData((void*)1); + pPage->SetRenderContext(std::unique_ptr<CFX_Deletable>()); } #ifdef _SKIA_SUPPORT_ @@ -661,33 +657,33 @@ DLLEXPORT FPDF_RECORDER STDCALL FPDF_RenderPageSkp(FPDF_PAGE page, CPDF_Page* pPage = CPDFPageFromFPDFPage(page); if (!pPage) return nullptr; - std::unique_ptr<CRenderContext> pContext(new CRenderContext); - pPage->SetPrivateData((void*)1, pContext.get(), DropContext); + + CRenderContext* pContext = new CRenderContext; + pPage->SetRenderContext(std::unique_ptr<CFX_Deletable>(pContext)); CFX_FxgeDevice* skDevice = new CFX_FxgeDevice; FPDF_RECORDER recorder = skDevice->CreateRecorder(size_x, size_y); pContext->m_pDevice = skDevice; - FPDF_RenderPage_Retail(pContext.get(), page, 0, 0, size_x, size_y, 0, 0, TRUE, - NULL); - pPage->RemovePrivateData((void*)1); + nullptr); + pPage->SetRenderContext(std::unique_ptr<CFX_Deletable>()); return recorder; } #endif DLLEXPORT void STDCALL FPDF_ClosePage(FPDF_PAGE page) { + UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); if (!page) return; #ifdef PDF_ENABLE_XFA - CPDFXFA_Page* pPage = (CPDFXFA_Page*)page; pPage->Release(); #else // PDF_ENABLE_XFA CPDFSDK_PageView* pPageView = - (CPDFSDK_PageView*)(((CPDF_Page*)page))->GetPrivateData((void*)page); + static_cast<CPDFSDK_PageView*>(pPage->GetView()); if (pPageView && pPageView->IsLocked()) { pPageView->TakeOverPage(); return; } - delete (CPDF_Page*)page; + delete pPage; #endif // PDF_ENABLE_XFA } |