Change FillRectWithBlend methods to take FX_RECT by const-ref.
They currently take const FX_RECT*, but the pointer is never nullptr.
Also add a comment to explain why FX_RECT is the way it is. It has the
same layout as a win32 RECT.
Change-Id: Icf0e4c3eb25fe03317590a736578e053b9dccf7a
Reviewed-on: https://pdfium-review.googlesource.com/30051
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
diff --git a/core/fxcrt/fx_coordinates.h b/core/fxcrt/fx_coordinates.h
index 2e8c1ab..a458fa8 100644
--- a/core/fxcrt/fx_coordinates.h
+++ b/core/fxcrt/fx_coordinates.h
@@ -178,6 +178,7 @@
// TODO(tsepez): Consolidate all these different rectangle classes.
// LTRB rectangles (y-axis runs downwards).
+// Struct layout is compatible with win32 RECT.
struct FX_RECT {
FX_RECT() : left(0), top(0), right(0), bottom(0) {}
FX_RECT(int l, int t, int r, int b) : left(l), top(t), right(r), bottom(b) {}
diff --git a/core/fxge/agg/fx_agg_driver.cpp b/core/fxge/agg/fx_agg_driver.cpp
index 9d8d8fa..ab6ee49 100644
--- a/core/fxge/agg/fx_agg_driver.cpp
+++ b/core/fxge/agg/fx_agg_driver.cpp
@@ -1407,7 +1407,7 @@
return DibSetPixel(m_pBitmap, x, y, color);
}
-bool CFX_AggDeviceDriver::FillRectWithBlend(const FX_RECT* pRect,
+bool CFX_AggDeviceDriver::FillRectWithBlend(const FX_RECT& rect,
uint32_t fill_color,
int blend_type) {
if (blend_type != FXDIB_BLEND_NORMAL)
@@ -1419,8 +1419,7 @@
FX_RECT clip_rect;
GetClipBox(&clip_rect);
FX_RECT draw_rect = clip_rect;
- if (pRect)
- draw_rect.Intersect(*pRect);
+ draw_rect.Intersect(rect);
if (draw_rect.IsEmpty())
return true;
diff --git a/core/fxge/agg/fx_agg_driver.h b/core/fxge/agg/fx_agg_driver.h
index adea810..4e94a00 100644
--- a/core/fxge/agg/fx_agg_driver.h
+++ b/core/fxge/agg/fx_agg_driver.h
@@ -59,7 +59,7 @@
int fill_mode,
int blend_type) override;
bool SetPixel(int x, int y, uint32_t color) override;
- bool FillRectWithBlend(const FX_RECT* pRect,
+ bool FillRectWithBlend(const FX_RECT& rect,
uint32_t fill_color,
int blend_type) override;
bool GetClipBox(FX_RECT* pRect) override;
diff --git a/core/fxge/cfx_renderdevice.cpp b/core/fxge/cfx_renderdevice.cpp
index 2fd48d2..a479517 100644
--- a/core/fxge/cfx_renderdevice.cpp
+++ b/core/fxge/cfx_renderdevice.cpp
@@ -564,7 +564,7 @@
--rect_i.bottom;
}
}
- if (FillRectWithBlend(&rect_i, fill_color, blend_type))
+ if (FillRectWithBlend(rect_i, fill_color, blend_type))
return true;
}
}
@@ -664,28 +664,28 @@
FXDIB_BLEND_NORMAL);
}
-bool CFX_RenderDevice::FillRectWithBlend(const FX_RECT* pRect,
+bool CFX_RenderDevice::FillRectWithBlend(const FX_RECT& rect,
uint32_t fill_color,
int blend_type) {
- if (m_pDeviceDriver->FillRectWithBlend(pRect, fill_color, blend_type))
+ if (m_pDeviceDriver->FillRectWithBlend(rect, fill_color, blend_type))
return true;
if (!(m_RenderCaps & FXRC_GET_BITS))
return false;
auto bitmap = pdfium::MakeRetain<CFX_DIBitmap>();
- if (!CreateCompatibleBitmap(bitmap, pRect->Width(), pRect->Height()))
+ if (!CreateCompatibleBitmap(bitmap, rect.Width(), rect.Height()))
return false;
- if (!m_pDeviceDriver->GetDIBits(bitmap, pRect->left, pRect->top))
+ if (!m_pDeviceDriver->GetDIBits(bitmap, rect.left, rect.top))
return false;
- if (!bitmap->CompositeRect(0, 0, pRect->Width(), pRect->Height(), fill_color,
+ if (!bitmap->CompositeRect(0, 0, rect.Width(), rect.Height(), fill_color,
0)) {
return false;
}
- FX_RECT src_rect(0, 0, pRect->Width(), pRect->Height());
- m_pDeviceDriver->SetDIBits(bitmap, 0, &src_rect, pRect->left, pRect->top,
+ FX_RECT src_rect(0, 0, rect.Width(), rect.Height());
+ m_pDeviceDriver->SetDIBits(bitmap, 0, &src_rect, rect.left, rect.top,
FXDIB_BLEND_NORMAL);
return true;
}
diff --git a/core/fxge/cfx_renderdevice.h b/core/fxge/cfx_renderdevice.h
index 124e5e9..6c91d55 100644
--- a/core/fxge/cfx_renderdevice.h
+++ b/core/fxge/cfx_renderdevice.h
@@ -145,7 +145,7 @@
int fill_mode,
int blend_type);
bool FillRect(const FX_RECT* pRect, uint32_t color) {
- return FillRectWithBlend(pRect, color, FXDIB_BLEND_NORMAL);
+ return FillRectWithBlend(*pRect, color, FXDIB_BLEND_NORMAL);
}
RetainPtr<CFX_DIBitmap> GetBackDrop();
@@ -290,7 +290,7 @@
uint32_t color,
int fill_mode,
int blend_type);
- bool FillRectWithBlend(const FX_RECT* pRect, uint32_t color, int blend_type);
+ bool FillRectWithBlend(const FX_RECT& rect, uint32_t color, int blend_type);
RetainPtr<CFX_DIBitmap> m_pBitmap;
int m_Width;
diff --git a/core/fxge/renderdevicedriver_iface.cpp b/core/fxge/renderdevicedriver_iface.cpp
index b4d7fb0..7023e02 100644
--- a/core/fxge/renderdevicedriver_iface.cpp
+++ b/core/fxge/renderdevicedriver_iface.cpp
@@ -29,7 +29,7 @@
return false;
}
-bool RenderDeviceDriverIface::FillRectWithBlend(const FX_RECT* pRect,
+bool RenderDeviceDriverIface::FillRectWithBlend(const FX_RECT& rect,
uint32_t fill_color,
int blend_type) {
return false;
diff --git a/core/fxge/renderdevicedriver_iface.h b/core/fxge/renderdevicedriver_iface.h
index 2d255f6..a0c148d 100644
--- a/core/fxge/renderdevicedriver_iface.h
+++ b/core/fxge/renderdevicedriver_iface.h
@@ -50,7 +50,7 @@
int fill_mode,
int blend_type) = 0;
virtual bool SetPixel(int x, int y, uint32_t color);
- virtual bool FillRectWithBlend(const FX_RECT* pRect,
+ virtual bool FillRectWithBlend(const FX_RECT& rect,
uint32_t fill_color,
int blend_type);
virtual bool DrawCosmeticLine(const CFX_PointF& ptMoveTo,
diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp
index 190ad9e..598dc48 100644
--- a/core/fxge/skia/fx_skia_device.cpp
+++ b/core/fxge/skia/fx_skia_device.cpp
@@ -1960,7 +1960,7 @@
return false;
}
-bool CFX_SkiaDeviceDriver::FillRectWithBlend(const FX_RECT* pRect,
+bool CFX_SkiaDeviceDriver::FillRectWithBlend(const FX_RECT& rect,
uint32_t fill_color,
int blend_type) {
m_pCache->FlushForDraw();
@@ -1968,11 +1968,10 @@
spaint.setAntiAlias(true);
spaint.setColor(fill_color);
spaint.setBlendMode(GetSkiaBlendMode(blend_type));
- SkRect rect =
- SkRect::MakeLTRB(pRect->left, SkTMin(pRect->top, pRect->bottom),
- pRect->right, SkTMax(pRect->bottom, pRect->top));
- DebugShowSkiaDrawRect(this, m_pCanvas, spaint, rect);
- m_pCanvas->drawRect(rect, spaint);
+ SkRect srect = SkRect::MakeLTRB(rect.left, SkTMin(rect.top, rect.bottom),
+ rect.right, SkTMax(rect.bottom, rect.top));
+ DebugShowSkiaDrawRect(this, m_pCanvas, spaint, srect);
+ m_pCanvas->drawRect(srect, spaint);
return true;
}
diff --git a/core/fxge/skia/fx_skia_device.h b/core/fxge/skia/fx_skia_device.h
index e545f9c..8fdd4fd 100644
--- a/core/fxge/skia/fx_skia_device.h
+++ b/core/fxge/skia/fx_skia_device.h
@@ -64,7 +64,7 @@
int fill_mode,
int blend_type) override;
- bool FillRectWithBlend(const FX_RECT* pRect,
+ bool FillRectWithBlend(const FX_RECT& rect,
uint32_t fill_color,
int blend_type) override;
diff --git a/core/fxge/win32/fx_win32_device.cpp b/core/fxge/win32/fx_win32_device.cpp
index b857dde..337f964 100644
--- a/core/fxge/win32/fx_win32_device.cpp
+++ b/core/fxge/win32/fx_win32_device.cpp
@@ -1061,7 +1061,7 @@
return true;
}
-bool CGdiDeviceDriver::FillRectWithBlend(const FX_RECT* pRect,
+bool CGdiDeviceDriver::FillRectWithBlend(const FX_RECT& rect,
uint32_t fill_color,
int blend_type) {
if (blend_type != FXDIB_BLEND_NORMAL)
@@ -1077,7 +1077,8 @@
return false;
HBRUSH hBrush = CreateSolidBrush(colorref);
- ::FillRect(m_hDC, (RECT*)pRect, hBrush);
+ const RECT* pRect = reinterpret_cast<const RECT*>(&rect);
+ ::FillRect(m_hDC, pRect, hBrush);
DeleteObject(hBrush);
return true;
}
diff --git a/core/fxge/win32/win32_int.h b/core/fxge/win32/win32_int.h
index 34d307c..b248522 100644
--- a/core/fxge/win32/win32_int.h
+++ b/core/fxge/win32/win32_int.h
@@ -151,7 +151,7 @@
uint32_t stroke_color,
int fill_mode,
int blend_type) override;
- bool FillRectWithBlend(const FX_RECT* pRect,
+ bool FillRectWithBlend(const FX_RECT& rect,
uint32_t fill_color,
int blend_type) override;
bool DrawCosmeticLine(const CFX_PointF& ptMoveTo,