Skip to content

Commit

Permalink
Fix nanosvg leaks.
Browse files Browse the repository at this point in the history
Move global variable textfaces in XTheme.
Move global variable fontsDB in XTheme.
Remove XTheme member SVGParser. SVGParser is deleted just after use.
Remove XTheme members ImageSVG and ImageSVGnight. All images are
rasterized at load, so no need to keep that.
Remove XIcon setFilled because XIcon knows if it's filled or not by
checking Image & ImageNight
  • Loading branch information
jief committed Nov 8, 2023
1 parent 8de61a2 commit 42cece9
Show file tree
Hide file tree
Showing 21 changed files with 478 additions and 535 deletions.
4 changes: 4 additions & 0 deletions Include/Library/MemLogLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
// Mem log sizes
//
#define MEM_LOG_INITIAL_SIZE (128 * 1024)
#ifdef JIEF_DEBUG
#define MEM_LOG_MAX_SIZE (10 * 1024 * 1024)
#else
#define MEM_LOG_MAX_SIZE (2 * 1024 * 1024)
#endif
#define MEM_LOG_MAX_LINE_SIZE 1024


Expand Down
1 change: 1 addition & 0 deletions Library/MemLogLibDefault/MemLogLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ static void transmitS8Printf(const char* buf, unsigned int nbchar, void* context
// but not too big (if something gets out of controll)
if (mMemLog->BufferSize + MEM_LOG_INITIAL_SIZE > MEM_LOG_MAX_SIZE) {
// Out of resources!
// Jief : Silent fail. TODO : At least put "Out of resource" at the end of the log
return;
}
Offset = mMemLog->Cursor - mMemLog->Buffer;
Expand Down
8 changes: 2 additions & 6 deletions rEFIt_UEFI/Platform/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,10 @@ const SETTINGS_DATA::SmbiosClass::SlotDeviceClass SETTINGS_DATA::SmbiosClass::Sl
CUSTOM_LOADER_ENTRY::CUSTOM_LOADER_ENTRY(const CUSTOM_LOADER_ENTRY_SETTINGS& _settings) : settings(_settings)
{
if ( settings.ImageData.notEmpty() ) {
if ( !EFI_ERROR(Image.Image.FromPNG(settings.ImageData.data(), settings.ImageData.size())) ) {
Image.setFilled();
}
Image.Image.FromPNG(settings.ImageData.data(), settings.ImageData.size());
}
if ( settings.DriveImageData.notEmpty() ) {
if ( !EFI_ERROR(DriveImage.Image.FromPNG(settings.DriveImageData.data(), settings.DriveImageData.size())) ) {
DriveImage.setFilled();
}
DriveImage.Image.FromPNG(settings.DriveImageData.data(), settings.DriveImageData.size());
}

if ( settings.CustomLogoTypeSettings == CUSTOM_BOOT_USER && settings.CustomLogoAsXString8.notEmpty() ) {
Expand Down
12 changes: 3 additions & 9 deletions rEFIt_UEFI/Platform/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -473,16 +473,12 @@ class CUSTOM_LEGACY_ENTRY
if ( settings.ImagePath.notEmpty() ) {
Image.LoadXImage(&ThemeDir, settings.ImagePath);
}else if ( settings.ImageData.notEmpty() ) {
if ( !EFI_ERROR(Image.Image.FromPNG(settings.ImageData.data(), settings.ImageData.size())) ) {
Image.setFilled();
}
Image.Image.FromPNG(settings.ImageData.data(), settings.ImageData.size());
}
if ( settings.DriveImagePath.notEmpty() ) {
DriveImage.LoadXImage(&ThemeDir, settings.DriveImagePath);
}else if ( settings.DriveImageData.notEmpty() ) {
if ( !EFI_ERROR(DriveImage.Image.FromPNG(settings.DriveImageData.data(), settings.DriveImageData.size())) ) {
DriveImage.setFilled();
}
DriveImage.Image.FromPNG(settings.DriveImageData.data(), settings.DriveImageData.size());
}
}

Expand Down Expand Up @@ -560,9 +556,7 @@ class CUSTOM_TOOL_ENTRY
if ( settings.ImagePath.notEmpty() ) {
Image.LoadXImage(&ThemeDir, settings.ImagePath);
} else if ( settings.ImageData.notEmpty() ) {
if ( !EFI_ERROR(Image.Image.FromPNG(settings.ImageData.data(), settings.ImageData.size())) ) {
Image.setFilled();
}
Image.Image.FromPNG(settings.ImageData.data(), settings.ImageData.size());
}
}
UINT8 getFlags() const {
Expand Down
4 changes: 0 additions & 4 deletions rEFIt_UEFI/entry_scan/loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,6 @@ if ( Entry->APFSTargetUUID.Data1 == 0x99999999 ) {
if (gSettings.GUI.CustomIcons && FileExists(Volume->RootDir, L"\\.VolumeIcon.icns")){
Entry->Image.Image.LoadIcns(Volume->RootDir, L"\\.VolumeIcon.icns", 128);
if (!Entry->Image.Image.isEmpty()) {
Entry->Image.setFilled();
DBG("%susing VolumeIcon.icns image from Volume\n", indent);
}
} else if (Image) {
Expand All @@ -1205,9 +1204,6 @@ if ( Entry->APFSTargetUUID.Data1 == 0x99999999 ) {
Entry->BadgeImage.Image = XImage(Entry->Image.Image, 0);
DBG("%sShow badge as OSImage.\n", indent);
}
if (!Entry->BadgeImage.Image.isEmpty()) {
Entry->BadgeImage.setFilled();
}
}
Entry->BootBgColor = BootBgColor;
Entry->KernelAndKextPatches = Patches == NULL ? gSettings.KernelAndKextPatches : *Patches;
Expand Down
13 changes: 6 additions & 7 deletions rEFIt_UEFI/gui/REFIT_MAINMENU_SCREEN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ void REFIT_MAINMENU_SCREEN::DrawMainMenuEntry(REFIT_ABSTRACT_MENU_ENTRY *Entry,
}
if (MainIcon.Image.isEmpty()) {
MainIcon.Image.DummyImage(MainSize);
MainIcon.setFilled();
}
}

Expand Down Expand Up @@ -349,8 +348,8 @@ void REFIT_MAINMENU_SCREEN::MainMenuStyle(IN UINTN Function, IN CONST CHAR16 *Pa
// INTN i = 0;
INTN MessageHeight = 0;
// clovy
if (ThemeX->TypeSVG && textFace[1].valid) {
MessageHeight = (INTN)(textFace[1].size * RowHeightFromTextHeight * ThemeX->Scale);
if (ThemeX->TypeSVG && ThemeX->getTextFace(1).valid) {
MessageHeight = (INTN)(ThemeX->getTextFace(1).size * RowHeightFromTextHeight * ThemeX->Scale);
} else {
MessageHeight = (INTN)(ThemeX->TextHeight * RowHeightFromTextHeight * ThemeX->Scale);
}
Expand Down Expand Up @@ -574,8 +573,8 @@ void REFIT_MAINMENU_SCREEN::MainMenuVerticalStyle(IN UINTN Function, IN CONST CH
INTN VisibleHeight = (UGAHeight - EntriesPosY - (int)(LAYOUT_Y_EDGE * ThemeX->Scale) + EntriesGap) / (EntriesHeight + EntriesGap);
EntriesPosX = UGAWidth - EntriesWidth - (int)((BAR_WIDTH + LAYOUT_X_EDGE) * ThemeX->Scale);
INTN MessageHeight = 20;
if (ThemeX->TypeSVG && textFace[1].valid) {
MessageHeight = (INTN)(textFace[1].size * RowHeightFromTextHeight * ThemeX->Scale);
if (ThemeX->TypeSVG && ThemeX->getTextFace(1).valid) {
MessageHeight = (INTN)(ThemeX->getTextFace(1).size * RowHeightFromTextHeight * ThemeX->Scale);
} else {
MessageHeight = (INTN)(ThemeX->TextHeight * RowHeightFromTextHeight * ThemeX->Scale);
}
Expand Down Expand Up @@ -684,8 +683,8 @@ void REFIT_MAINMENU_SCREEN::MainMenuVerticalStyle(IN UINTN Function, IN CONST CH

case MENU_FUNCTION_PAINT_TIMEOUT:
INTN MessageHeight = 20;
if (ThemeX->TypeSVG && textFace[1].valid) {
MessageHeight = (INTN)(textFace[1].size * RowHeightFromTextHeight * ThemeX->Scale);
if (ThemeX->TypeSVG && ThemeX->getTextFace(1).valid) {
MessageHeight = (INTN)(ThemeX->getTextFace(1).size * RowHeightFromTextHeight * ThemeX->Scale);
} else {
MessageHeight = (INTN)(ThemeX->TextHeight * RowHeightFromTextHeight * ThemeX->Scale);
}
Expand Down
26 changes: 13 additions & 13 deletions rEFIt_UEFI/gui/REFIT_MENU_SCREEN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,22 +705,22 @@ UINTN REFIT_MENU_SCREEN::RunGenericMenu(IN OUT INTN *DefaultEntryIndex, OUT REFI
TextStyle = 2;
}
if (ThemeX->TypeSVG) {
if (!textFace[TextStyle].valid) {
if (textFace[0].valid) {
if (!ThemeX->getTextFace(TextStyle).valid) {
if (ThemeX->getTextFace(0).valid) {
TextStyle = 0;
} else if (textFace[2].valid) {
} else if (ThemeX->getTextFace(2).valid) {
TextStyle = 2;
} else if (textFace[1].valid) {
} else if (ThemeX->getTextFace(1).valid) {
TextStyle = 1;
} else {
DBG("no valid text style\n");
textFace[TextStyle].size = ThemeX->TextHeight - 4;
// ThemeX->getTextFace(TextStyle).size = ThemeX->TextHeight - 4;
}
}
if (textFace[TextStyle].valid) {
// TextHeight = (int)((textFace[TextStyle].size + 4) * GlobalConfig.Scale);
if (ThemeX->getTextFace(TextStyle).valid) {
// TextHeight = (int)((ThemeX->getTextFace(TextStyle].size + 4) * GlobalConfig.Scale);
//clovy - row height / text size factor
ThemeX->TextHeight = (int)((textFace[TextStyle].size * RowHeightFromTextHeight) * ThemeX->Scale);
ThemeX->TextHeight = (int)((ThemeX->getTextFace(TextStyle).size * RowHeightFromTextHeight) * ThemeX->Scale);
}
}

Expand Down Expand Up @@ -1314,8 +1314,8 @@ INTN REFIT_MENU_SCREEN::DrawTextXY(IN const XStringW& Text, IN INTN XPos, IN INT
}
//TODO assume using embedded font for BootScreen
//messages must be TextXYStyle = 1 if it is provided by theme
if (!textFace[1].valid) {
if (textFace[2].valid) {
if (!ThemeX->getTextFace(1).valid) {
if (ThemeX->getTextFace(2).valid) {
TextXYStyle = 2;
} else {
TextXYStyle = 0;
Expand All @@ -1336,11 +1336,11 @@ INTN REFIT_MENU_SCREEN::DrawTextXY(IN const XStringW& Text, IN INTN XPos, IN INT

if (!isBootScreen && ThemeX->TypeSVG) {
TextWidth += ThemeX->TextHeight * 2; //give more place for buffer
if (!textFace[TextXYStyle].valid) {
if (!ThemeX->getTextFace(TextXYStyle).valid) {
DBG("no vaid text face for message!\n");
Height = ThemeX->TextHeight;
} else {
Height = (int)(textFace[TextXYStyle].size * RowHeightFromTextHeight * ThemeX->Scale);
Height = (int)(ThemeX->getTextFace(TextXYStyle).size * RowHeightFromTextHeight * ThemeX->Scale);
}
} else {
Height = ThemeX->TextHeight;
Expand Down Expand Up @@ -1442,7 +1442,7 @@ void REFIT_MENU_SCREEN::DrawMenuText(IN const XStringW& Text, IN INTN SelectedWi
if (ThemeX->TypeSVG) {
//clovy - text vertically centred on Height
ThemeX->RenderText(Text, &TextBufferX, 0,
(INTN)((ThemeX->TextHeight - (textFace[TextStyle].size * ThemeX->Scale)) / 2),
(INTN)((ThemeX->TextHeight - (ThemeX->getTextFace(TextStyle).size * ThemeX->Scale)) / 2),
Cursor, TextStyle);
} else {
ThemeX->RenderText(Text, &TextBufferX, TEXT_XMARGIN, TEXT_YMARGIN, Cursor, TextStyle);
Expand Down
Loading

0 comments on commit 42cece9

Please sign in to comment.