Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Unified Diff: fpdfsdk/fpdfview.cpp

Issue 2369323004: Simplify FPDF_RenderPage(). (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fpdfsdk/fpdfview.cpp
diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp
index c5b13f850d42e343342c1de9ae495de1af523122..c33086d603c19bfd0dc0079e8162390101ac4431 100644
--- a/fpdfsdk/fpdfview.cpp
+++ b/fpdfsdk/fpdfview.cpp
@@ -576,9 +576,9 @@ DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc,
pPage->SetRenderContext(WrapUnique(pContext));
CFX_DIBitmap* pBitmap = nullptr;
Tom Sepez 2016/09/27 21:25:32 Can this be an unique_ptr? It looks like it only
Lei Zhang 2016/09/27 21:49:46 Done.
- FX_BOOL bBackgroundAlphaNeeded = pPage->BackgroundAlphaNeeded();
- FX_BOOL bHasImageMask = pPage->HasImageMask();
- if (bBackgroundAlphaNeeded || bHasImageMask) {
+ const bool bNewBitmap =
+ pPage->BackgroundAlphaNeeded() || pPage->HasImageMask();
+ if (bNewBitmap) {
pBitmap = new CFX_DIBitmap;
pBitmap->Create(size_x, size_y, FXDIB_Argb);
pBitmap->Clear(0x00ffffff);
@@ -592,26 +592,23 @@ DLLEXPORT void STDCALL FPDF_RenderPage(HDC 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) {
+ ASSERT(pBitmap);
+
+ 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, 0, 0,
+ FXDIB_BLEND_NORMAL, nullptr, FALSE, nullptr);
+ WinDC.StretchDIBits(pDst.get(), 0, 0, size_x, size_y);
+ } else {
+ WinDC.SetDIBits(pBitmap, 0, 0);
}
- }
- if (bBackgroundAlphaNeeded || bHasImageMask)
delete pBitmap;
+ }
pPage->SetRenderContext(std::unique_ptr<CPDF_PageRenderContext>());
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698