[Scummvm-git-logs] scummvm master -> 9b6d9b0c27b2b05bf80adfb7a870e2025b509405
sev-
noreply at scummvm.org
Sat Jul 8 19:13:32 UTC 2023
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
9b6d9b0c27 GRAPHICS: Fix WinFont scaling memory leak when scaling fonts.
Commit: 9b6d9b0c27b2b05bf80adfb7a870e2025b509405
https://github.com/scummvm/scummvm/commit/9b6d9b0c27b2b05bf80adfb7a870e2025b509405
Author: Harishankar Kumar (hari01584 at gmail.com)
Date: 2023-07-08T22:13:28+03:00
Commit Message:
GRAPHICS: Fix WinFont scaling memory leak when scaling fonts.
Memory leak happened because the scaled generated fonts were not
being cached or saved anywhere, thus they were not being destructed
and freed. Added logic to cache generated font in _winFontRegistry
itself.
Leaks observed in `trektech-win` of director engine in first few frames itself.
Changed paths:
graphics/fonts/winfont.cpp
graphics/fonts/winfont.h
graphics/macgui/macfontmanager.cpp
diff --git a/graphics/fonts/winfont.cpp b/graphics/fonts/winfont.cpp
index 9427af0717a..4447f954bd5 100644
--- a/graphics/fonts/winfont.cpp
+++ b/graphics/fonts/winfont.cpp
@@ -321,7 +321,7 @@ void WinFont::drawChar(Surface *dst, uint32 chr, int x, int y, uint32 color) con
}
}
-int WinFont::getStyle() {
+int WinFont::getStyle() const {
int style = kFontStyleRegular;
// This has been taken from Wine Source
diff --git a/graphics/fonts/winfont.h b/graphics/fonts/winfont.h
index 9545e6e18e7..9ee87aa1ae1 100644
--- a/graphics/fonts/winfont.h
+++ b/graphics/fonts/winfont.h
@@ -68,7 +68,7 @@ public:
Common::String getName() const { return _name; }
int getCharWidth(uint32 chr) const;
void drawChar(Surface *dst, uint32 chr, int x, int y, uint32 color) const;
- int getStyle();
+ int getStyle() const;
static WinFont *scaleFont(const WinFont *src, int newSize);
private:
diff --git a/graphics/macgui/macfontmanager.cpp b/graphics/macgui/macfontmanager.cpp
index 613e9ddeff7..224080d89ad 100644
--- a/graphics/macgui/macfontmanager.cpp
+++ b/graphics/macgui/macfontmanager.cpp
@@ -526,7 +526,24 @@ const Font *MacFontManager::getFont(MacFont *macFont) {
if (winfont->getFontHeight() != macFont->getSize()) {
debug(5, "MacFontManager::getFont(): For font '%s' windows font '%s' is used of a different size %d", macFont->getName().c_str(), winfont->getName().c_str(), winfont->getFontHeight());
- font = WinFont::scaleFont(winfont, macFont->getSize());
+
+ Common::String fullFontName = Common::String::format("%s-%d-%d", winfont->getName().c_str(), winfont->getStyle(), macFont->getSize());
+
+ if (_winFontRegistry.contains(fullFontName)) {
+ // Check if we have generated this earlier, in that case reuse it.
+ font = _winFontRegistry.getVal(fullFontName);
+ } else {
+ // Generate a scaledFont
+ Graphics::WinFont *scaledWinFont = WinFont::scaleFont(winfont, macFont->getSize());
+ if (scaledWinFont) {
+ debug(5, "MacFontManager::getFont(): Generated scaled winFont %s", fullFontName.c_str());
+
+ // register font generated for reuse
+ _winFontRegistry.setVal(fullFontName, scaledWinFont);
+
+ font = scaledWinFont;
+ }
+ }
}
}
}
More information about the Scummvm-git-logs
mailing list