diff options
author | thestig <thestig@chromium.org> | 2016-09-27 15:06:01 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-09-27 15:06:01 -0700 |
commit | 84144e88da8d2bbd03ba9f8608d5603a18b4d480 (patch) | |
tree | a9d5643832ed332982761e04f4a6cb48bd8dfde2 | |
parent | f8074cefb2f8d947fa83d151bcbe080b485d6e6b (diff) | |
download | pdfium-chromium/2874.tar.xz |
Simplify FPDF_RenderPage().chromium/2874
Review-Url: https://codereview.chromium.org/2369323004
-rw-r--r-- | fpdfsdk/fpdfview.cpp | 46 |
1 files changed, 20 insertions, 26 deletions
diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp index c5b13f850d..62cafa0781 100644 --- a/fpdfsdk/fpdfview.cpp +++ b/fpdfsdk/fpdfview.cpp @@ -575,43 +575,37 @@ DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, CPDF_PageRenderContext* pContext = new CPDF_PageRenderContext; pPage->SetRenderContext(WrapUnique(pContext)); - CFX_DIBitmap* pBitmap = nullptr; - FX_BOOL bBackgroundAlphaNeeded = pPage->BackgroundAlphaNeeded(); - FX_BOOL bHasImageMask = pPage->HasImageMask(); - if (bBackgroundAlphaNeeded || bHasImageMask) { - pBitmap = new CFX_DIBitmap; + std::unique_ptr<CFX_DIBitmap> pBitmap; + const bool bNewBitmap = + pPage->BackgroundAlphaNeeded() || pPage->HasImageMask(); + if (bNewBitmap) { + pBitmap = WrapUnique(new CFX_DIBitmap); pBitmap->Create(size_x, size_y, FXDIB_Argb); pBitmap->Clear(0x00ffffff); CFX_FxgeDevice* pDevice = new CFX_FxgeDevice; - pContext->m_pDevice.reset(pDevice); - pDevice->Attach(pBitmap, false, nullptr, false); + pContext->m_pDevice = WrapUnique(pDevice); + pDevice->Attach(pBitmap.get(), false, nullptr, false); } else { - pContext->m_pDevice.reset(new CFX_WindowsDevice(dc)); + pContext->m_pDevice = WrapUnique(new CFX_WindowsDevice(dc)); } FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, rotate, flags, TRUE, nullptr); - if (bBackgroundAlphaNeeded || bHasImageMask) { - if (pBitmap) { - CFX_WindowsDevice WinDC(dc); - - if (WinDC.GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINTER) { - CFX_DIBitmap* pDst = new 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, 0, 0, - FXDIB_BLEND_NORMAL, nullptr, FALSE, nullptr); - WinDC.StretchDIBits(pDst, 0, 0, size_x, size_y); - delete pDst; - } else { - WinDC.SetDIBits(pBitmap, 0, 0); - } + if (bNewBitmap) { + CFX_WindowsDevice WinDC(dc); + if (WinDC.GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINTER) { + std::unique_ptr<CFX_DIBitmap> pDst = WrapUnique(new 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, + FXDIB_BLEND_NORMAL, nullptr, FALSE, nullptr); + WinDC.StretchDIBits(pDst.get(), 0, 0, size_x, size_y); + } else { + WinDC.SetDIBits(pBitmap.get(), 0, 0); } } - if (bBackgroundAlphaNeeded || bHasImageMask) - delete pBitmap; pPage->SetRenderContext(std::unique_ptr<CPDF_PageRenderContext>()); } |