diff options
author | Lei Zhang <thestig@chromium.org> | 2018-10-26 22:52:48 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-10-26 22:52:48 +0000 |
commit | 5883300439287ab46559231ce8aed11e92bbc97c (patch) | |
tree | 2c3499da9df5a2c4e2fb9d13f99bde13b7bebb42 /core/fxge/win32 | |
parent | 9590dee526c514d87dc1f47569d1136ffcf539ad (diff) | |
download | pdfium-5883300439287ab46559231ce8aed11e92bbc97c.tar.xz |
Replace int flags with struct FXDIB_ResampleOptions.
Using bit values in an int may not be reliable, since different parts of
the code can interpret the bits differently. e.g. FXDIB_DOWNSAMPLE and
RENDER_FORCE_DOWNSAMPLE are defined in different places, but can be used
interchangeably because they just happen to have the same value. It
works but is rather fragile.
Instead, use a struct of bools to explicitly define what different bits
mean. Remove FXDIB_DOWNSAMPLE and friends.
Change-Id: I9cf0c8f94d1ed27edf8dba22b0ab0ee67f2722cc
Reviewed-on: https://pdfium-review.googlesource.com/c/44650
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fxge/win32')
-rw-r--r-- | core/fxge/win32/cfx_psrenderer.cpp | 11 | ||||
-rw-r--r-- | core/fxge/win32/cfx_psrenderer.h | 5 | ||||
-rw-r--r-- | core/fxge/win32/fx_win32_device.cpp | 38 | ||||
-rw-r--r-- | core/fxge/win32/fx_win32_gdipext.cpp | 4 | ||||
-rw-r--r-- | core/fxge/win32/fx_win32_print.cpp | 30 | ||||
-rw-r--r-- | core/fxge/win32/win32_int.h | 22 |
6 files changed, 57 insertions, 53 deletions
diff --git a/core/fxge/win32/cfx_psrenderer.cpp b/core/fxge/win32/cfx_psrenderer.cpp index 9f5a7cd139..13c1abacb1 100644 --- a/core/fxge/win32/cfx_psrenderer.cpp +++ b/core/fxge/win32/cfx_psrenderer.cpp @@ -25,6 +25,7 @@ #include "core/fxge/cfx_renderdevice.h" #include "core/fxge/dib/cfx_dibextractor.h" #include "core/fxge/dib/cfx_dibitmap.h" +#include "core/fxge/fx_dib.h" #include "core/fxge/win32/cpsoutput.h" #include "third_party/base/ptr_util.h" @@ -348,7 +349,7 @@ bool CFX_PSRenderer::SetDIBits(const RetainPtr<CFX_DIBBase>& pSource, StartRendering(); CFX_Matrix matrix = CFX_RenderDevice::GetFlipMatrix( pSource->GetWidth(), pSource->GetHeight(), left, top); - return DrawDIBits(pSource, color, matrix, 0); + return DrawDIBits(pSource, color, matrix, FXDIB_ResampleOptions()); } bool CFX_PSRenderer::StretchDIBits(const RetainPtr<CFX_DIBBase>& pSource, @@ -357,17 +358,17 @@ bool CFX_PSRenderer::StretchDIBits(const RetainPtr<CFX_DIBBase>& pSource, int dest_top, int dest_width, int dest_height, - uint32_t flags) { + const FXDIB_ResampleOptions& options) { StartRendering(); CFX_Matrix matrix = CFX_RenderDevice::GetFlipMatrix(dest_width, dest_height, dest_left, dest_top); - return DrawDIBits(pSource, color, matrix, flags); + return DrawDIBits(pSource, color, matrix, options); } bool CFX_PSRenderer::DrawDIBits(const RetainPtr<CFX_DIBBase>& pSource, uint32_t color, const CFX_Matrix& matrix, - uint32_t flags) { + const FXDIB_ResampleOptions& options) { StartRendering(); if ((matrix.a == 0 && matrix.b == 0) || (matrix.c == 0 && matrix.d == 0)) return true; @@ -459,7 +460,7 @@ bool CFX_PSRenderer::DrawDIBits(const RetainPtr<CFX_DIBBase>& pSource, uint8_t* output_buf = nullptr; size_t output_size = 0; const char* filter = nullptr; - if ((m_PSLevel == 2 || flags & FXRENDER_IMAGE_LOSSY) && + if ((m_PSLevel == 2 || options.bLossy) && CCodec_JpegModule::JpegEncode(pConverted, &output_buf, &output_size)) { filter = "/DCTDecode filter "; } diff --git a/core/fxge/win32/cfx_psrenderer.h b/core/fxge/win32/cfx_psrenderer.h index b5107d9ab1..9b1d86b8fc 100644 --- a/core/fxge/win32/cfx_psrenderer.h +++ b/core/fxge/win32/cfx_psrenderer.h @@ -24,6 +24,7 @@ class CFX_Matrix; class CFX_PathData; class CPSFont; class FXTEXT_CHARPOS; +struct FXDIB_ResampleOptions; class CFX_PSRenderer { public: @@ -62,11 +63,11 @@ class CFX_PSRenderer { int dest_top, int dest_width, int dest_height, - uint32_t flags); + const FXDIB_ResampleOptions& options); bool DrawDIBits(const RetainPtr<CFX_DIBBase>& pBitmap, uint32_t color, const CFX_Matrix& matrix, - uint32_t flags); + const FXDIB_ResampleOptions& options); bool DrawText(int nChars, const FXTEXT_CHARPOS* pCharPos, CFX_Font* pFont, diff --git a/core/fxge/win32/fx_win32_device.cpp b/core/fxge/win32/fx_win32_device.cpp index a4452e7faa..4f2abae882 100644 --- a/core/fxge/win32/fx_win32_device.cpp +++ b/core/fxge/win32/fx_win32_device.cpp @@ -812,7 +812,7 @@ bool CGdiDeviceDriver::GDI_StretchDIBits( int dest_top, int dest_width, int dest_height, - uint32_t flags) { + const FXDIB_ResampleOptions& options) { RetainPtr<CFX_DIBitmap> pBitmap = pBitmap1; if (!pBitmap || dest_width == 0 || dest_height == 0) return false; @@ -823,7 +823,7 @@ bool CGdiDeviceDriver::GDI_StretchDIBits( ByteString info = CFX_WindowsDIB::GetBitmapInfo(pBitmap); if ((int64_t)abs(dest_width) * abs(dest_height) < (int64_t)pBitmap1->GetWidth() * pBitmap1->GetHeight() * 4 || - (flags & FXDIB_INTERPOL) || (flags & FXDIB_BICUBIC_INTERPOL)) { + options.bInterpolateBilinear || options.bInterpolateBicubic) { SetStretchBltMode(m_hDC, HALFTONE); } else { SetStretchBltMode(m_hDC, COLORONCOLOR); @@ -832,7 +832,8 @@ bool CGdiDeviceDriver::GDI_StretchDIBits( if (m_DeviceClass == FXDC_PRINTER && ((int64_t)pBitmap->GetWidth() * pBitmap->GetHeight() > (int64_t)abs(dest_width) * abs(dest_height))) { - pToStrechBitmap = pBitmap->StretchTo(dest_width, dest_height, 0, nullptr); + pToStrechBitmap = pBitmap->StretchTo(dest_width, dest_height, + FXDIB_ResampleOptions(), nullptr); } ByteString toStrechBitmapInfo = CFX_WindowsDIB::GetBitmapInfo(pToStrechBitmap); @@ -1209,8 +1210,8 @@ bool CGdiDisplayDriver::SetDIBits(const RetainPtr<CFX_DIBBase>& pSource, FX_RECT clip_rect(left, top, left + src_rect.Width(), top + src_rect.Height()); return StretchDIBits(pSource, color, left - src_rect.left, - top - src_rect.top, width, height, &clip_rect, 0, - BlendMode::kNormal); + top - src_rect.top, width, height, &clip_rect, + FXDIB_ResampleOptions(), BlendMode::kNormal); } int width = src_rect.Width(); int height = src_rect.Height(); @@ -1241,7 +1242,7 @@ bool CGdiDisplayDriver::UseFoxitStretchEngine( int dest_width, int dest_height, const FX_RECT* pClipRect, - int render_flags) { + const FXDIB_ResampleOptions& options) { FX_RECT bitmap_clip = *pClipRect; if (dest_width < 0) dest_left += dest_width; @@ -1251,7 +1252,7 @@ bool CGdiDisplayDriver::UseFoxitStretchEngine( bitmap_clip.Offset(-dest_left, -dest_top); RetainPtr<CFX_DIBitmap> pStretched = - pSource->StretchTo(dest_width, dest_height, render_flags, &bitmap_clip); + pSource->StretchTo(dest_width, dest_height, options, &bitmap_clip); if (!pStretched) return true; @@ -1267,13 +1268,13 @@ bool CGdiDisplayDriver::StretchDIBits(const RetainPtr<CFX_DIBBase>& pSource, int dest_width, int dest_height, const FX_RECT* pClipRect, - uint32_t flags, + const FXDIB_ResampleOptions& options, BlendMode blend_type) { ASSERT(pSource && pClipRect); - if (flags || dest_width > 10000 || dest_width < -10000 || + if (options.HasAnyOptions() || dest_width > 10000 || dest_width < -10000 || dest_height > 10000 || dest_height < -10000) { return UseFoxitStretchEngine(pSource, color, dest_left, dest_top, - dest_width, dest_height, pClipRect, flags); + dest_width, dest_height, pClipRect, options); } if (pSource->IsAlphaMask()) { FX_RECT image_rect; @@ -1285,8 +1286,8 @@ bool CGdiDisplayDriver::StretchDIBits(const RetainPtr<CFX_DIBBase>& pSource, clip_rect.Intersect(*pClipRect); clip_rect.Offset(-image_rect.left, -image_rect.top); int clip_width = clip_rect.Width(), clip_height = clip_rect.Height(); - RetainPtr<CFX_DIBitmap> pStretched( - pSource->StretchTo(dest_width, dest_height, 0, &clip_rect)); + RetainPtr<CFX_DIBitmap> pStretched(pSource->StretchTo( + dest_width, dest_height, FXDIB_ResampleOptions(), &clip_rect)); if (!pStretched) return true; @@ -1312,26 +1313,27 @@ bool CGdiDisplayDriver::StretchDIBits(const RetainPtr<CFX_DIBBase>& pSource, RetainPtr<CFX_DIBitmap> pBitmap = temp.GetBitmap(); if (!pBitmap) return false; - return pPlatform->m_GdiplusExt.StretchDIBits(m_hDC, pBitmap, dest_left, - dest_top, dest_width, - dest_height, pClipRect, 0); + return pPlatform->m_GdiplusExt.StretchDIBits( + m_hDC, pBitmap, dest_left, dest_top, dest_width, dest_height, + pClipRect, FXDIB_ResampleOptions()); } return UseFoxitStretchEngine(pSource, color, dest_left, dest_top, - dest_width, dest_height, pClipRect, 0); + dest_width, dest_height, pClipRect, + FXDIB_ResampleOptions()); } CFX_DIBExtractor temp(pSource); RetainPtr<CFX_DIBitmap> pBitmap = temp.GetBitmap(); if (!pBitmap) return false; return GDI_StretchDIBits(pBitmap, dest_left, dest_top, dest_width, - dest_height, 0); + dest_height, FXDIB_ResampleOptions()); } bool CGdiDisplayDriver::StartDIBits(const RetainPtr<CFX_DIBBase>& pBitmap, int bitmap_alpha, uint32_t color, const CFX_Matrix& matrix, - uint32_t render_flags, + const FXDIB_ResampleOptions& options, std::unique_ptr<CFX_ImageRenderer>* handle, BlendMode blend_type) { return false; diff --git a/core/fxge/win32/fx_win32_gdipext.cpp b/core/fxge/win32/fx_win32_gdipext.cpp index f93ce8f9ad..8e80b50fbc 100644 --- a/core/fxge/win32/fx_win32_gdipext.cpp +++ b/core/fxge/win32/fx_win32_gdipext.cpp @@ -778,12 +778,12 @@ bool CGdiplusExt::StretchDIBits(HDC hDC, int dest_width, int dest_height, const FX_RECT* pClipRect, - int flags) { + const FXDIB_ResampleOptions& options) { Gdiplus::GpGraphics* pGraphics; const CGdiplusExt& GdiplusExt = GetGdiplusExt(); CallFunc(GdipCreateFromHDC)(hDC, &pGraphics); CallFunc(GdipSetPageUnit)(pGraphics, Gdiplus::UnitPixel); - if (flags & FXDIB_NOSMOOTH) { + if (options.bNoSmoothing) { CallFunc(GdipSetInterpolationMode)( pGraphics, Gdiplus::InterpolationModeNearestNeighbor); } else if (pBitmap->GetWidth() > abs(dest_width) / 2 || diff --git a/core/fxge/win32/fx_win32_print.cpp b/core/fxge/win32/fx_win32_print.cpp index 2f99f88e68..f2d3a9c482 100644 --- a/core/fxge/win32/fx_win32_print.cpp +++ b/core/fxge/win32/fx_win32_print.cpp @@ -80,8 +80,8 @@ bool CGdiPrinterDriver::SetDIBits(const RetainPtr<CFX_DIBBase>& pSource, top + src_rect.Height()); return StretchDIBits(pSource, color, left - src_rect.left, top - src_rect.top, pSource->GetWidth(), - pSource->GetHeight(), &clip_rect, 0, - BlendMode::kNormal); + pSource->GetHeight(), &clip_rect, + FXDIB_ResampleOptions(), BlendMode::kNormal); } ASSERT(pSource && !pSource->IsAlphaMask()); ASSERT(blend_type == BlendMode::kNormal); @@ -103,7 +103,7 @@ bool CGdiPrinterDriver::StretchDIBits(const RetainPtr<CFX_DIBBase>& pSource, int dest_width, int dest_height, const FX_RECT* pClipRect, - uint32_t flags, + const FXDIB_ResampleOptions& options, BlendMode blend_type) { if (pSource->IsAlphaMask()) { int alpha = FXARGB_A(color); @@ -148,7 +148,7 @@ bool CGdiPrinterDriver::StretchDIBits(const RetainPtr<CFX_DIBBase>& pSource, dest_top += dest_height; return GDI_StretchDIBits(pFlipped, dest_left, dest_top, abs(dest_width), - abs(dest_height), flags); + abs(dest_height), options); } CFX_DIBExtractor temp(pSource); @@ -156,14 +156,14 @@ bool CGdiPrinterDriver::StretchDIBits(const RetainPtr<CFX_DIBBase>& pSource, if (!pBitmap) return false; return GDI_StretchDIBits(pBitmap, dest_left, dest_top, dest_width, - dest_height, flags); + dest_height, options); } bool CGdiPrinterDriver::StartDIBits(const RetainPtr<CFX_DIBBase>& pSource, int bitmap_alpha, uint32_t color, const CFX_Matrix& matrix, - uint32_t render_flags, + const FXDIB_ResampleOptions& options, std::unique_ptr<CFX_ImageRenderer>* handle, BlendMode blend_type) { if (bitmap_alpha < 255 || pSource->HasAlpha() || @@ -181,7 +181,7 @@ bool CGdiPrinterDriver::StartDIBits(const RetainPtr<CFX_DIBBase>& pSource, bFlipY ? full_rect.bottom : full_rect.top, bFlipX ? -full_rect.Width() : full_rect.Width(), bFlipY ? -full_rect.Height() : full_rect.Height(), - nullptr, 0, blend_type); + nullptr, FXDIB_ResampleOptions(), blend_type); } if (fabs(matrix.a) >= 0.5f || fabs(matrix.d) >= 0.5f) return false; @@ -192,8 +192,8 @@ bool CGdiPrinterDriver::StartDIBits(const RetainPtr<CFX_DIBBase>& pSource, return false; return StretchDIBits(pTransformed, color, full_rect.left, full_rect.top, - full_rect.Width(), full_rect.Height(), nullptr, 0, - blend_type); + full_rect.Width(), full_rect.Height(), nullptr, + FXDIB_ResampleOptions(), blend_type); } bool CGdiPrinterDriver::DrawDeviceText(int nChars, @@ -472,19 +472,19 @@ bool CPSPrinterDriver::StretchDIBits(const RetainPtr<CFX_DIBBase>& pBitmap, int dest_width, int dest_height, const FX_RECT* pClipRect, - uint32_t flags, + const FXDIB_ResampleOptions& options, BlendMode blend_type) { if (blend_type != BlendMode::kNormal) return false; return m_PSRenderer.StretchDIBits(pBitmap, color, dest_left, dest_top, - dest_width, dest_height, flags); + dest_width, dest_height, options); } bool CPSPrinterDriver::StartDIBits(const RetainPtr<CFX_DIBBase>& pBitmap, int bitmap_alpha, uint32_t color, const CFX_Matrix& matrix, - uint32_t render_flags, + const FXDIB_ResampleOptions& options, std::unique_ptr<CFX_ImageRenderer>* handle, BlendMode blend_type) { if (blend_type != BlendMode::kNormal) @@ -494,7 +494,7 @@ bool CPSPrinterDriver::StartDIBits(const RetainPtr<CFX_DIBBase>& pBitmap, return false; *handle = nullptr; - return m_PSRenderer.DrawDIBits(pBitmap, color, matrix, render_flags); + return m_PSRenderer.DrawDIBits(pBitmap, color, matrix, options); } bool CPSPrinterDriver::DrawDeviceText(int nChars, @@ -590,7 +590,7 @@ bool CTextOnlyPrinterDriver::StretchDIBits( int dest_width, int dest_height, const FX_RECT* pClipRect, - uint32_t flags, + const FXDIB_ResampleOptions& options, BlendMode blend_type) { return false; } @@ -600,7 +600,7 @@ bool CTextOnlyPrinterDriver::StartDIBits( int bitmap_alpha, uint32_t color, const CFX_Matrix& matrix, - uint32_t render_flags, + const FXDIB_ResampleOptions& options, std::unique_ptr<CFX_ImageRenderer>* handle, BlendMode blend_type) { return false; diff --git a/core/fxge/win32/win32_int.h b/core/fxge/win32/win32_int.h index db0e3894c5..44c3c8beae 100644 --- a/core/fxge/win32/win32_int.h +++ b/core/fxge/win32/win32_int.h @@ -40,7 +40,7 @@ class CGdiplusExt { int dest_width, int dest_height, const FX_RECT* pClipRect, - int flags); + const FXDIB_ResampleOptions& options); bool DrawPath(HDC hDC, const CFX_PathData* pPathData, const CFX_Matrix* pObject2Device, @@ -106,7 +106,7 @@ class CGdiDeviceDriver : public RenderDeviceDriverIface { int dest_top, int dest_width, int dest_height, - uint32_t flags); + const FXDIB_ResampleOptions& options); bool GDI_StretchBitMask(const RetainPtr<CFX_DIBitmap>& pBitmap, int dest_left, int dest_top, @@ -145,13 +145,13 @@ class CGdiDisplayDriver final : public CGdiDeviceDriver { int dest_width, int dest_height, const FX_RECT* pClipRect, - uint32_t flags, + const FXDIB_ResampleOptions& options, BlendMode blend_type) override; bool StartDIBits(const RetainPtr<CFX_DIBBase>& pBitmap, int bitmap_alpha, uint32_t color, const CFX_Matrix& matrix, - uint32_t render_flags, + const FXDIB_ResampleOptions& options, std::unique_ptr<CFX_ImageRenderer>* handle, BlendMode blend_type) override; bool UseFoxitStretchEngine(const RetainPtr<CFX_DIBBase>& pSource, @@ -161,7 +161,7 @@ class CGdiDisplayDriver final : public CGdiDeviceDriver { int dest_width, int dest_height, const FX_RECT* pClipRect, - int render_flags); + const FXDIB_ResampleOptions& options); }; class CGdiPrinterDriver final : public CGdiDeviceDriver { @@ -184,13 +184,13 @@ class CGdiPrinterDriver final : public CGdiDeviceDriver { int dest_width, int dest_height, const FX_RECT* pClipRect, - uint32_t flags, + const FXDIB_ResampleOptions& options, BlendMode blend_type) override; bool StartDIBits(const RetainPtr<CFX_DIBBase>& pBitmap, int bitmap_alpha, uint32_t color, const CFX_Matrix& matrix, - uint32_t render_flags, + const FXDIB_ResampleOptions& options, std::unique_ptr<CFX_ImageRenderer>* handle, BlendMode blend_type) override; bool DrawDeviceText(int nChars, @@ -243,13 +243,13 @@ class CPSPrinterDriver final : public RenderDeviceDriverIface { int dest_width, int dest_height, const FX_RECT* pClipRect, - uint32_t flags, + const FXDIB_ResampleOptions& options, BlendMode blend_type) override; bool StartDIBits(const RetainPtr<CFX_DIBBase>& pBitmap, int bitmap_alpha, uint32_t color, const CFX_Matrix& matrix, - uint32_t render_flags, + const FXDIB_ResampleOptions& options, std::unique_ptr<CFX_ImageRenderer>* handle, BlendMode blend_type) override; bool DrawDeviceText(int nChars, @@ -306,13 +306,13 @@ class CTextOnlyPrinterDriver final : public RenderDeviceDriverIface { int dest_width, int dest_height, const FX_RECT* pClipRect, - uint32_t flags, + const FXDIB_ResampleOptions& options, BlendMode blend_type) override; bool StartDIBits(const RetainPtr<CFX_DIBBase>& pBitmap, int bitmap_alpha, uint32_t color, const CFX_Matrix& matrix, - uint32_t render_flags, + const FXDIB_ResampleOptions& options, std::unique_ptr<CFX_ImageRenderer>* handle, BlendMode blend_type) override; bool DrawDeviceText(int nChars, |