Skip to content

Commit

Permalink
nanosvg memory allocation tracer.
Browse files Browse the repository at this point in the history
  • Loading branch information
jief committed Nov 6, 2023
1 parent 45795cc commit a107644
Show file tree
Hide file tree
Showing 5 changed files with 241 additions and 82 deletions.
26 changes: 23 additions & 3 deletions rEFIt_UEFI/libeg/VectorGraphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,35 @@ EFI_STATUS XTheme::ParseSVGXIcon(INTN Id, const XString8& IconNameX, OUT XImage*
return EFI_SUCCESS;
}

EFI_STATUS XTheme::ParseSVGXTheme(CONST CHAR8* buffer)
EFI_STATUS XTheme::ParseSVGXTheme(UINT8* buffer, UINTN Size)
{
EFI_STATUS Status;

Icons.setEmpty();

#if 1 && defined(NANOSVG_MEMORY_ALLOCATION_TRACE)
if ( nsvg__nbDanglingPtr() > 0 ) {
DBG("There is already dangling ptr. nano svg memory leak test not done\n");
}else{
char* buffer2 = (char*)malloc(Size);
memcpy(buffer2, buffer, Size);
nvsg__memoryallocation_verbose = false;
SVGParser = nsvgParse(buffer2, 72, 1.f); //the buffer will be modified, it is how nanosvg works // Jief : NEVER cast const to not const. Just change the parameter to not const !!! Nothing better to deceive.
// nsvg__deleteParser(SVGParser);
if ( nsvg__nbDanglingPtr() > 0 ) {
nsvg__outputDanglingPtr();
nvsg__memoryallocation_verbose = true; // there leaks. Activate verbose
}else{
nvsg__memoryallocation_verbose = false; // be sure that nvsg__memoryallocation_verbose is false, as it seems there is no memory leaks
}
}
#else
(void)Size;
#endif

// --- Parse theme.svg --- low case
NSVGparser *mainParser = nsvgParse((CHAR8*)buffer, 72, 1.f); //the buffer will be modified, it is how nanosvg works
SVGParser = (void *)mainParser; //store the pointer for future use
SVGParser = mainParser; //store the pointer for future use
NSVGimage *SVGimage = mainParser->image;
if (!SVGimage) {
// DBG("Theme not parsed!\n");
Expand Down Expand Up @@ -465,7 +485,7 @@ INTN renderSVGtext(XImage* TextBufferXY_ptr, INTN posX, INTN posY, INTN textType
if (!p) {
return 0;
}
NSVGtext* text = (NSVGtext*)AllocateZeroPool(sizeof(NSVGtext));
NSVGtext* text = (NSVGtext*)nsvg__alloczero(sizeof(NSVGtext), "renderSVGtext"_XS8); // use nsvg__alloczero method so it won't panic when it's freed.
if (!text) {
return 0;
}
Expand Down
8 changes: 4 additions & 4 deletions rEFIt_UEFI/libeg/XTheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ TagDict* XTheme::LoadTheme(const XStringW& TestTheme)
{
EFI_STATUS Status = EFI_UNSUPPORTED;
TagDict* ThemeDict = NULL;
CHAR8 *ThemePtr = NULL;
UINT8 *ThemePtr = NULL;
UINTN Size = 0;

if (TestTheme.isEmpty()) {
Expand All @@ -358,9 +358,9 @@ TagDict* XTheme::LoadTheme(const XStringW& TestTheme)
}

if (!EFI_ERROR(Status)) {
Status = egLoadFile(ThemeDir, CONFIG_THEME_SVG, (UINT8**)&ThemePtr, &Size);
Status = egLoadFile(ThemeDir, CONFIG_THEME_SVG, &ThemePtr, &Size);
if (!EFI_ERROR(Status) && (ThemePtr != NULL) && (Size != 0)) {
Status = ParseSVGXTheme(ThemePtr);
Status = ParseSVGXTheme(ThemePtr, Size);
if (EFI_ERROR(Status)) {
ThemeDict = NULL;
} else {
Expand All @@ -374,7 +374,7 @@ TagDict* XTheme::LoadTheme(const XStringW& TestTheme)
} else {
Status = egLoadFile(ThemeDir, CONFIG_THEME_FILENAME, (UINT8**)&ThemePtr, &Size);
if (!EFI_ERROR(Status) && (ThemePtr != NULL) && (Size != 0)) {
Status = ParseXML(ThemePtr, &ThemeDict, 0);
Status = ParseXML((CHAR8*)ThemePtr, &ThemeDict, 0);
if (EFI_ERROR(Status)) {
ThemeDict = NULL;
}
Expand Down
5 changes: 3 additions & 2 deletions rEFIt_UEFI/libeg/XTheme.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#if !defined(__XTHEME_H__)
#define __XTHEME_H__

#include "nanosvg.h"
#include "../cpp_foundation/XObjArray.h"
#include "../cpp_foundation/XString.h"
#include "../Settings/Self.h"
Expand Down Expand Up @@ -145,7 +146,7 @@ class XTheme

XCinema Cinema;

void *SVGParser;
NSVGparser* SVGParser;

void Init();
XTheme(); //default constructor
Expand Down Expand Up @@ -184,7 +185,7 @@ class XTheme
void FillByDir();
EFI_STATUS GetThemeTagSettings(const TagDict* DictPointer);
void parseTheme(void* p, char** dict); //in nano project
EFI_STATUS ParseSVGXTheme(const CHAR8* buffer); // in VectorTheme
EFI_STATUS ParseSVGXTheme(UINT8* buffer, UINTN Size); // in VectorTheme
EFI_STATUS ParseSVGXIcon(INTN Id, const XString8& IconNameX, XImage* Image, void **SVGIcon);
TagDict* LoadTheme(const XStringW& TestTheme); //return TagStruct* why?
EFI_STATUS LoadSvgFrame(INTN i, OUT XImage* XFrame); // for animation
Expand Down
Loading

0 comments on commit a107644

Please sign in to comment.