Commit 7e3873ec authored by Etienne Bergeron's avatar Etienne Bergeron Committed by Commit Bot

Add detection of high usage of HFONT in PlatformFontWin

This CL is adding code to detect when GDI Handles (HFONT)
are going to high because too many gfx::Font exists.

There is a plan to fix the incorrect uses of gfx::Font
and these dump will help tracking the source of these leaks.

Bug: 972689
Change-Id: I326938c3751766e01b3c318b5397ef8f4d4f9ae9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1648398Reviewed-by: default avatarEtienne Bergeron <etienneb@chromium.org>
Reviewed-by: default avatarAlexei Svitkine <asvitkine@chromium.org>
Reviewed-by: default avatarRobert Liao <robliao@chromium.org>
Commit-Queue: Etienne Bergeron <etienneb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#668462}
parent 93e33fa4
......@@ -17,6 +17,7 @@
#include "base/containers/flat_map.h"
#include "base/debug/alias.h"
#include "base/debug/dump_without_crashing.h"
#include "base/feature_list.h"
#include "base/logging.h"
#include "base/no_destructor.h"
......@@ -44,6 +45,19 @@
namespace {
// Tracking of HFontRef allocations (see: http://crbug/972689). The following
// code is temporary. It will be used to track and fix incorrect usage of
// GDI handles.
// Amount of HFontRef objects currently allocated.
int g_hfontref_total = 0;
// Max amount of HFontRef object before reporting a crash.
constexpr int kMaxHFontRefObjects = 1024;
// Whether a report already got sent.
bool g_hfontref_dump_already_sent = false;
// Enable the use of PlatformFontSkia instead of PlatformFontWin.
const base::Feature kPlatformFontSkiaOnWindows{
"PlatformFontSkiaOnWindows", base::FEATURE_DISABLED_BY_DEFAULT};
......@@ -580,6 +594,18 @@ PlatformFontWin::HFontRef::HFontRef(HFONT hfont,
requested_font_size_(font_size) {
DLOG_ASSERT(hfont);
// We are seeing cases in the field where the amount of HFontRef is above
// 10k objects. Each object keeps an HFONT alive, counting towards out 10K GDI
// handle limit. This code will help track the source of these issues
// (see crbug.com/972689) (todo: etienneb: remove this code when the
// experiment is done).
++g_hfontref_total;
if (g_hfontref_total > kMaxHFontRefObjects &&
!g_hfontref_dump_already_sent) {
g_hfontref_dump_already_sent = true;
base::debug::DumpWithoutCrashing();
}
LOGFONT font_info;
GetObject(hfont_, sizeof(LOGFONT), &font_info);
font_name_ = base::UTF16ToUTF8(base::string16(font_info.lfFaceName));
......@@ -623,6 +649,7 @@ int PlatformFontWin::HFontRef::GetAverageCharWidthInDialogUnits(
}
PlatformFontWin::HFontRef::~HFontRef() {
--g_hfontref_total;
DeleteObject(hfont_);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment