Fix some nits in CFX_ClipRgn. - Rename ClipType enum values to kFoo, and store it in a bool. Then remove DCHECKs that assume there can be any other value. - Initialize `m_Type` in the header. - Use GetScanLine() in IntersectMaskRect() instead of reimplementing it. Change-Id: I55bdc0b6078764ad1f8a353c64c1d5eb1b15bb8d Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/80833 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxge/agg/fx_agg_driver.cpp b/core/fxge/agg/fx_agg_driver.cpp index 02e55d6..7091a44 100644 --- a/core/fxge/agg/fx_agg_driver.cpp +++ b/core/fxge/agg/fx_agg_driver.cpp
@@ -294,7 +294,7 @@ } RetainPtr<CFX_DIBitmap> GetClipMaskFromRegion(const CFX_ClipRgn* r) { - return (r && r->GetType() == CFX_ClipRgn::MaskF) ? r->GetMask() : nullptr; + return (r && r->GetType() == CFX_ClipRgn::kMaskF) ? r->GetMask() : nullptr; } FX_RECT GetClipBoxFromRegion(const RetainPtr<CFX_DIBitmap>& device, @@ -1282,7 +1282,7 @@ if (draw_rect.IsEmpty()) return true; - if (!m_pClipRgn || m_pClipRgn->GetType() == CFX_ClipRgn::RectI) { + if (!m_pClipRgn || m_pClipRgn->GetType() == CFX_ClipRgn::kRectI) { if (m_bRgbByteOrder) { RgbByteOrderCompositeRect(m_pBitmap, draw_rect.left, draw_rect.top, draw_rect.Width(), draw_rect.Height(),
diff --git a/core/fxge/cfx_cliprgn.cpp b/core/fxge/cfx_cliprgn.cpp index f87ce2f..7c53234 100644 --- a/core/fxge/cfx_cliprgn.cpp +++ b/core/fxge/cfx_cliprgn.cpp
@@ -12,32 +12,28 @@ #include "third_party/base/check_op.h" #include "third_party/base/notreached.h" -CFX_ClipRgn::CFX_ClipRgn(int width, int height) - : m_Type(RectI), m_Box(0, 0, width, height) {} +CFX_ClipRgn::CFX_ClipRgn(int width, int height) : m_Box(0, 0, width, height) {} CFX_ClipRgn::CFX_ClipRgn(const CFX_ClipRgn& src) = default; CFX_ClipRgn::~CFX_ClipRgn() = default; void CFX_ClipRgn::IntersectRect(const FX_RECT& rect) { - if (m_Type == RectI) { + if (m_Type == kRectI) { m_Box.Intersect(rect); return; } - if (m_Type == MaskF) { - IntersectMaskRect(rect, m_Box, m_Mask); - return; - } + IntersectMaskRect(rect, m_Box, m_Mask); } void CFX_ClipRgn::IntersectMaskRect(FX_RECT rect, FX_RECT mask_rect, const RetainPtr<CFX_DIBitmap>& pMask) { - m_Type = MaskF; + m_Type = kMaskF; m_Box = rect; m_Box.Intersect(mask_rect); if (m_Box.IsEmpty()) { - m_Type = RectI; + m_Type = kRectI; return; } if (m_Box == mask_rect) { @@ -50,8 +46,7 @@ for (int row = m_Box.top; row < m_Box.bottom; row++) { uint8_t* dest_scan = m_Mask->GetBuffer() + m_Mask->GetPitch() * (row - m_Box.top); - uint8_t* src_scan = - pOldMask->GetBuffer() + pOldMask->GetPitch() * (row - mask_rect.top); + const uint8_t* src_scan = pOldMask->GetScanline(row - mask_rect.top); for (int col = m_Box.left; col < m_Box.right; col++) dest_scan[col - m_Box.left] = src_scan[col - mask_rect.left]; } @@ -63,35 +58,31 @@ DCHECK_EQ(pMask->GetFormat(), FXDIB_Format::k8bppMask); FX_RECT mask_box(left, top, left + pMask->GetWidth(), top + pMask->GetHeight()); - if (m_Type == RectI) { + if (m_Type == kRectI) { IntersectMaskRect(m_Box, mask_box, pMask); return; } - if (m_Type == MaskF) { - FX_RECT new_box = m_Box; - new_box.Intersect(mask_box); - if (new_box.IsEmpty()) { - m_Type = RectI; - m_Mask = nullptr; - m_Box = new_box; - return; - } - auto new_dib = pdfium::MakeRetain<CFX_DIBitmap>(); - new_dib->Create(new_box.Width(), new_box.Height(), FXDIB_Format::k8bppMask); - for (int row = new_box.top; row < new_box.bottom; row++) { - uint8_t* old_scan = - m_Mask->GetBuffer() + (row - m_Box.top) * m_Mask->GetPitch(); - uint8_t* mask_scan = pMask->GetBuffer() + (row - top) * pMask->GetPitch(); - uint8_t* new_scan = - new_dib->GetBuffer() + (row - new_box.top) * new_dib->GetPitch(); - for (int col = new_box.left; col < new_box.right; col++) { - new_scan[col - new_box.left] = - old_scan[col - m_Box.left] * mask_scan[col - left] / 255; - } - } + + FX_RECT new_box = m_Box; + new_box.Intersect(mask_box); + if (new_box.IsEmpty()) { + m_Type = kRectI; + m_Mask = nullptr; m_Box = new_box; - m_Mask = std::move(new_dib); return; } - NOTREACHED(); + auto new_dib = pdfium::MakeRetain<CFX_DIBitmap>(); + new_dib->Create(new_box.Width(), new_box.Height(), FXDIB_Format::k8bppMask); + for (int row = new_box.top; row < new_box.bottom; row++) { + const uint8_t* old_scan = m_Mask->GetScanline(row - m_Box.top); + const uint8_t* mask_scan = pMask->GetScanline(row - top); + uint8_t* new_scan = + new_dib->GetBuffer() + (row - new_box.top) * new_dib->GetPitch(); + for (int col = new_box.left; col < new_box.right; col++) { + new_scan[col - new_box.left] = + old_scan[col - m_Box.left] * mask_scan[col - left] / 255; + } + } + m_Box = new_box; + m_Mask = std::move(new_dib); }
diff --git a/core/fxge/cfx_cliprgn.h b/core/fxge/cfx_cliprgn.h index e1f9e22..5738a88 100644 --- a/core/fxge/cfx_cliprgn.h +++ b/core/fxge/cfx_cliprgn.h
@@ -14,7 +14,7 @@ class CFX_ClipRgn { public: - enum ClipType { RectI, MaskF }; + enum ClipType : bool { kRectI, kMaskF }; CFX_ClipRgn(int device_width, int device_height); CFX_ClipRgn(const CFX_ClipRgn& src); @@ -32,7 +32,7 @@ FX_RECT mask_rect, const RetainPtr<CFX_DIBitmap>& Mask); - ClipType m_Type; + ClipType m_Type = kRectI; FX_RECT m_Box; RetainPtr<CFX_DIBitmap> m_Mask; };
diff --git a/core/fxge/dib/cfx_bitmapcomposer.cpp b/core/fxge/dib/cfx_bitmapcomposer.cpp index d50e4b4..6f9b420 100644 --- a/core/fxge/dib/cfx_bitmapcomposer.cpp +++ b/core/fxge/dib/cfx_bitmapcomposer.cpp
@@ -32,7 +32,7 @@ m_BitmapAlpha = bitmap_alpha; m_MaskColor = mask_color; m_pClipMask = nullptr; - if (pClipRgn && pClipRgn->GetType() != CFX_ClipRgn::RectI) + if (pClipRgn && pClipRgn->GetType() != CFX_ClipRgn::kRectI) m_pClipMask = pClipRgn->GetMask(); m_bVertical = bVertical; m_bFlipX = bFlipX;
diff --git a/core/fxge/dib/cfx_dibitmap.cpp b/core/fxge/dib/cfx_dibitmap.cpp index 92f69c2..199bedd 100644 --- a/core/fxge/dib/cfx_dibitmap.cpp +++ b/core/fxge/dib/cfx_dibitmap.cpp
@@ -775,8 +775,7 @@ RetainPtr<CFX_DIBitmap> pClipMask; FX_RECT clip_box; - if (pClipRgn && pClipRgn->GetType() != CFX_ClipRgn::RectI) { - DCHECK_EQ(pClipRgn->GetType(), CFX_ClipRgn::MaskF); + if (pClipRgn && pClipRgn->GetType() != CFX_ClipRgn::kRectI) { pClipMask = pClipRgn->GetMask(); clip_box = pClipRgn->GetBox(); } @@ -858,8 +857,7 @@ RetainPtr<CFX_DIBitmap> pClipMask; FX_RECT clip_box; - if (pClipRgn && pClipRgn->GetType() != CFX_ClipRgn::RectI) { - DCHECK_EQ(pClipRgn->GetType(), CFX_ClipRgn::MaskF); + if (pClipRgn && pClipRgn->GetType() != CFX_ClipRgn::kRectI) { pClipMask = pClipRgn->GetMask(); clip_box = pClipRgn->GetBox(); }