Use std::make_unique() in more Windows-only fxge code.
Get rid of 6 uses of the new keyword, especially when the newly
allocated memory is going into std::unique_ptrs anyway.
Change-Id: I8aa03fe76bbb46f41552d5f9ef9d0818f25972ee
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/75271
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Daniel Hosseinian <dhoss@chromium.org>
diff --git a/core/fxge/cfx_windowsrenderdevice.cpp b/core/fxge/cfx_windowsrenderdevice.cpp
index c4cd5e7..88ec4a9 100644
--- a/core/fxge/cfx_windowsrenderdevice.cpp
+++ b/core/fxge/cfx_windowsrenderdevice.cpp
@@ -10,12 +10,12 @@
#include "core/fxcrt/fx_codepage.h"
#include "core/fxge/cfx_folderfontinfo.h"
+#include "core/fxge/renderdevicedriver_iface.h"
#include "core/fxge/systemfontinfo_iface.h"
#include "core/fxge/win32/cgdi_display_driver.h"
#include "core/fxge/win32/cgdi_printer_driver.h"
#include "core/fxge/win32/cps_printer_driver.h"
#include "core/fxge/win32/ctext_only_printer_driver.h"
-#include "third_party/base/ptr_util.h"
#include "third_party/base/stl_util.h"
namespace {
@@ -427,20 +427,7 @@
return true;
}
-} // namespace
-
-WindowsPrintMode g_pdfium_print_mode = WindowsPrintMode::kModeEmf;
-
-CFX_WindowsRenderDevice::CFX_WindowsRenderDevice(
- HDC hDC,
- const EncoderIface* pEncoderIface) {
- SetDeviceDriver(pdfium::WrapUnique(CreateDriver(hDC, pEncoderIface)));
-}
-
-CFX_WindowsRenderDevice::~CFX_WindowsRenderDevice() = default;
-
-// static
-RenderDeviceDriverIface* CFX_WindowsRenderDevice::CreateDriver(
+std::unique_ptr<RenderDeviceDriverIface> CreateDriver(
HDC hDC,
const EncoderIface* pEncoderIface) {
int device_type = ::GetDeviceCaps(hDC, TECHNOLOGY);
@@ -450,15 +437,28 @@
device_type == DT_CHARSTREAM || obj_type == OBJ_ENHMETADC;
if (!use_printer)
- return new CGdiDisplayDriver(hDC);
+ return std::make_unique<CGdiDisplayDriver>(hDC);
if (g_pdfium_print_mode == WindowsPrintMode::kModeEmf ||
g_pdfium_print_mode == WindowsPrintMode::kModeEmfImageMasks) {
- return new CGdiPrinterDriver(hDC);
+ return std::make_unique<CGdiPrinterDriver>(hDC);
}
if (g_pdfium_print_mode == WindowsPrintMode::kModeTextOnly)
- return new CTextOnlyPrinterDriver(hDC);
+ return std::make_unique<CTextOnlyPrinterDriver>(hDC);
- return new CPSPrinterDriver(hDC, g_pdfium_print_mode, false, pEncoderIface);
+ return std::make_unique<CPSPrinterDriver>(hDC, g_pdfium_print_mode, false,
+ pEncoderIface);
}
+
+} // namespace
+
+WindowsPrintMode g_pdfium_print_mode = WindowsPrintMode::kModeEmf;
+
+CFX_WindowsRenderDevice::CFX_WindowsRenderDevice(
+ HDC hDC,
+ const EncoderIface* pEncoderIface) {
+ SetDeviceDriver(CreateDriver(hDC, pEncoderIface));
+}
+
+CFX_WindowsRenderDevice::~CFX_WindowsRenderDevice() = default;
diff --git a/core/fxge/cfx_windowsrenderdevice.h b/core/fxge/cfx_windowsrenderdevice.h
index 96ae1ee..84b34d6 100644
--- a/core/fxge/cfx_windowsrenderdevice.h
+++ b/core/fxge/cfx_windowsrenderdevice.h
@@ -39,11 +39,6 @@
public:
CFX_WindowsRenderDevice(HDC hDC, const EncoderIface* pEncoderIface);
~CFX_WindowsRenderDevice() override;
-
- private:
- static RenderDeviceDriverIface* CreateDriver(
- HDC hDC,
- const EncoderIface* pEncoderIface);
};
#endif // CORE_FXGE_CFX_WINDOWSRENDERDEVICE_H_
diff --git a/core/fxge/win32/cwin32_platform.cpp b/core/fxge/win32/cwin32_platform.cpp
index b896e5a..8c5b182 100644
--- a/core/fxge/win32/cwin32_platform.cpp
+++ b/core/fxge/win32/cwin32_platform.cpp
@@ -442,10 +442,10 @@
std::unique_ptr<SystemFontInfoIface>
CWin32Platform::CreateDefaultSystemFontInfo() {
if (pdfium::base::win::IsUser32AndGdi32Available())
- return std::unique_ptr<SystemFontInfoIface>(new CFX_Win32FontInfo);
+ return std::make_unique<CFX_Win32FontInfo>();
// Select the fallback font information class if GDI is disabled.
- CFX_Win32FallbackFontInfo* pInfoFallback = new CFX_Win32FallbackFontInfo;
+ auto fallback_info = std::make_unique<CFX_Win32FallbackFontInfo>();
// Construct the font path manually, SHGetKnownFolderPath won't work under
// a restrictive sandbox.
CHAR windows_path[MAX_PATH] = {};
@@ -453,9 +453,9 @@
if (path_len > 0 && path_len < MAX_PATH) {
ByteString fonts_path(windows_path);
fonts_path += "\\Fonts";
- pInfoFallback->AddPath(fonts_path);
+ fallback_info->AddPath(fonts_path);
}
- return std::unique_ptr<SystemFontInfoIface>(pInfoFallback);
+ return fallback_info;
}
// static