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 /fpdfsdk/fpdfview.cpp | |
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 'fpdfsdk/fpdfview.cpp')
-rw-r--r-- | fpdfsdk/fpdfview.cpp | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp index d4284a3217..dcfa1c1925 100644 --- a/fpdfsdk/fpdfview.cpp +++ b/fpdfsdk/fpdfview.cpp @@ -709,41 +709,39 @@ DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, CPDF_PageRenderContext* pContext = new CPDF_PageRenderContext; pPage->SetRenderContext(pdfium::WrapUnique(pContext)); - std::unique_ptr<CFX_DIBitmap> pBitmap; + CFX_RetainPtr<CFX_DIBitmap> 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::MakeUnique<CFX_DIBitmap>(); + pBitmap = pdfium::MakeRetain<CFX_DIBitmap>(); 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.get(), false, nullptr, false); + pDevice->Attach(pBitmap, false, nullptr, false); } else { pContext->m_pDevice = pdfium::MakeUnique<CFX_WindowsDevice>(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) { - std::unique_ptr<CFX_DIBitmap> pDst = pdfium::MakeUnique<CFX_DIBitmap>(); + auto pDst = pdfium::MakeRetain<CFX_DIBitmap>(); 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.get(), 0, 0, + pDst->CompositeBitmap(0, 0, size_x, size_y, pBitmap, 0, 0, FXDIB_BLEND_NORMAL, nullptr, false, nullptr); - WinDC.StretchDIBits(pDst.get(), 0, 0, size_x, size_y); + WinDC.StretchDIBits(pDst, 0, 0, size_x, size_y); } else { - WinDC.SetDIBits(pBitmap.get(), 0, 0); + WinDC.SetDIBits(pBitmap, 0, 0); } } - pPage->SetRenderContext(nullptr); } #endif // defined(_WIN32) @@ -765,11 +763,12 @@ 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_DIBitmap* pBitmap = CFXBitmapFromFPDFBitmap(bitmap); - pDevice->Attach(pBitmap, !!(flags & FPDF_REVERSE_BYTE_ORDER), nullptr, false); + CFX_RetainPtr<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); @@ -794,9 +793,11 @@ 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_DIBitmap* pBitmap = CFXBitmapFromFPDFBitmap(bitmap); + + CFX_RetainPtr<CFX_DIBitmap> pBitmap(CFXBitmapFromFPDFBitmap(bitmap)); pDevice->Attach(pBitmap, !!(flags & FPDF_REVERSE_BYTE_ORDER), nullptr, false); CFX_Matrix transform_matrix = pPage->GetPageMatrix(); @@ -940,11 +941,11 @@ DLLEXPORT void STDCALL FPDF_PageToDevice(FPDF_PAGE page, DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_Create(int width, int height, int alpha) { - auto pBitmap = pdfium::MakeUnique<CFX_DIBitmap>(); + auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>(); if (!pBitmap->Create(width, height, alpha ? FXDIB_Argb : FXDIB_Rgb32)) return nullptr; - return pBitmap.release(); + return pBitmap.Leak(); } DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_CreateEx(int width, @@ -969,9 +970,9 @@ DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_CreateEx(int width, default: return nullptr; } - CFX_DIBitmap* pBitmap = new CFX_DIBitmap; + auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>(); pBitmap->Create(width, height, fx_format, (uint8_t*)first_scan, stride); - return pBitmap; + return pBitmap.Leak(); } DLLEXPORT void STDCALL FPDFBitmap_FillRect(FPDF_BITMAP bitmap, @@ -984,7 +985,7 @@ DLLEXPORT void STDCALL FPDFBitmap_FillRect(FPDF_BITMAP bitmap, return; CFX_FxgeDevice device; - CFX_DIBitmap* pBitmap = CFXBitmapFromFPDFBitmap(bitmap); + CFX_RetainPtr<CFX_DIBitmap> pBitmap(CFXBitmapFromFPDFBitmap(bitmap)); device.Attach(pBitmap, false, nullptr, false); if (!pBitmap->HasAlpha()) color |= 0xFF000000; @@ -1009,7 +1010,8 @@ DLLEXPORT int STDCALL FPDFBitmap_GetStride(FPDF_BITMAP bitmap) { } DLLEXPORT void STDCALL FPDFBitmap_Destroy(FPDF_BITMAP bitmap) { - delete CFXBitmapFromFPDFBitmap(bitmap); + CFX_RetainPtr<CFX_DIBitmap> destroyer; + destroyer.Unleak(CFXBitmapFromFPDFBitmap(bitmap)); } void FPDF_RenderPage_Retail(CPDF_PageRenderContext* pContext, |