From 6776229047c0f5aac540fc9c367e4abbf5302322 Mon Sep 17 00:00:00 2001 From: Michael Lutz Date: Sat, 16 Jan 2021 16:43:31 +0100 Subject: Codechange: Make the simple Malloc sprite allocator globally usable. --- src/fontcache.cpp | 9 ++------- src/fontcache_internal.h | 2 -- src/os/macosx/font_osx.cpp | 2 +- src/os/windows/font_win32.cpp | 2 +- src/spritecache.cpp | 8 ++++++++ src/spritecache.h | 1 + 6 files changed, 13 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/fontcache.cpp b/src/fontcache.cpp index 8ed8708aa..0ae597fa9 100644 --- a/src/fontcache.cpp +++ b/src/fontcache.cpp @@ -277,11 +277,6 @@ void TrueTypeFontCache::SetGlyphPtr(GlyphID key, const GlyphEntry *glyph, bool d this->glyph_to_sprite[GB(key, 8, 8)][GB(key, 0, 8)].duplicate = duplicate; } -void *AllocateFont(size_t size) -{ - return MallocT(size); -} - /* Check if a glyph should be rendered with anti-aliasing. */ static bool GetFontAAState(FontSize size) @@ -355,7 +350,7 @@ const Sprite *TrueTypeFontCache::GetGlyph(GlyphID key) builtin_questionmark_data }; - Sprite *spr = BlitterFactory::GetCurrentBlitter()->Encode(&builtin_questionmark, AllocateFont); + Sprite *spr = BlitterFactory::GetCurrentBlitter()->Encode(&builtin_questionmark, SimpleSpriteAlloc); assert(spr != nullptr); GlyphEntry new_glyph; new_glyph.sprite = spr; @@ -643,7 +638,7 @@ const Sprite *FreeTypeFontCache::InternalGetGlyph(GlyphID key, bool aa) } GlyphEntry new_glyph; - new_glyph.sprite = BlitterFactory::GetCurrentBlitter()->Encode(&sprite, AllocateFont); + new_glyph.sprite = BlitterFactory::GetCurrentBlitter()->Encode(&sprite, SimpleSpriteAlloc); new_glyph.width = slot->advance.x >> 6; this->SetGlyphPtr(key, &new_glyph); diff --git a/src/fontcache_internal.h b/src/fontcache_internal.h index 2f7454733..acae3d71d 100644 --- a/src/fontcache_internal.h +++ b/src/fontcache_internal.h @@ -74,6 +74,4 @@ public: bool IsBuiltInFont() override { return false; } }; -void *AllocateFont(size_t size); - #endif /* FONTCACHE_INTERNAL_H */ diff --git a/src/os/macosx/font_osx.cpp b/src/os/macosx/font_osx.cpp index 04e5db9ab..f5ceed850 100644 --- a/src/os/macosx/font_osx.cpp +++ b/src/os/macosx/font_osx.cpp @@ -333,7 +333,7 @@ const Sprite *CoreTextFontCache::InternalGetGlyph(GlyphID key, bool use_aa) } GlyphEntry new_glyph; - new_glyph.sprite = BlitterFactory::GetCurrentBlitter()->Encode(&sprite, AllocateFont); + new_glyph.sprite = BlitterFactory::GetCurrentBlitter()->Encode(&sprite, SimpleSpriteAlloc); new_glyph.width = (byte)std::round(CTFontGetAdvancesForGlyphs(this->font.get(), kCTFontOrientationDefault, &glyph, nullptr, 1)); this->SetGlyphPtr(key, &new_glyph); diff --git a/src/os/windows/font_win32.cpp b/src/os/windows/font_win32.cpp index a3b60933c..1b4a41ccf 100644 --- a/src/os/windows/font_win32.cpp +++ b/src/os/windows/font_win32.cpp @@ -532,7 +532,7 @@ void Win32FontCache::ClearFontCache() } GlyphEntry new_glyph; - new_glyph.sprite = BlitterFactory::GetCurrentBlitter()->Encode(&sprite, AllocateFont); + new_glyph.sprite = BlitterFactory::GetCurrentBlitter()->Encode(&sprite, SimpleSpriteAlloc); new_glyph.width = gm.gmCellIncX; this->SetGlyphPtr(key, &new_glyph); diff --git a/src/spritecache.cpp b/src/spritecache.cpp index f86be1b97..9e23d7d2a 100644 --- a/src/spritecache.cpp +++ b/src/spritecache.cpp @@ -808,6 +808,14 @@ static void *AllocSprite(size_t mem_req) } } +/** + * Sprite allocator simply using malloc. + */ +void *SimpleSpriteAlloc(size_t size) +{ + return MallocT(size); +} + /** * Handles the case when a sprite of different type is requested than is present in the SpriteCache. * For ST_FONT sprites, it is normal. In other cases, default sprite is loaded instead. diff --git a/src/spritecache.h b/src/spritecache.h index 80e92a8f4..00503c453 100644 --- a/src/spritecache.h +++ b/src/spritecache.h @@ -26,6 +26,7 @@ extern uint _sprite_cache_size; typedef void *AllocatorProc(size_t size); +void *SimpleSpriteAlloc(size_t size); void *GetRawSprite(SpriteID sprite, SpriteType type, AllocatorProc *allocator = nullptr, SpriteEncoder *encoder = nullptr); bool SpriteExists(SpriteID sprite); -- cgit v1.2.3-70-g09d2