Changeset - r24900:959a621b6aa9
[Not reviewed]
master
0 6 0
Michael Lutz - 3 years ago 2021-01-16 15:43:31
michi@icosahedron.de
Codechange: Make the simple Malloc sprite allocator globally usable.
6 files changed with 13 insertions and 11 deletions:
0 comments (0 inline, 0 general)
src/fontcache.cpp
Show inline comments
 
@@ -274,17 +274,12 @@ void TrueTypeFontCache::SetGlyphPtr(Glyp
 
	DEBUG(freetype, 4, "Set glyph for unicode character 0x%04X, size %u", key, this->fs);
 
	this->glyph_to_sprite[GB(key, 8, 8)][GB(key, 0, 8)].sprite = glyph->sprite;
 
	this->glyph_to_sprite[GB(key, 8, 8)][GB(key, 0, 8)].width = glyph->width;
 
	this->glyph_to_sprite[GB(key, 8, 8)][GB(key, 0, 8)].duplicate = duplicate;
 
}
 

	
 
void *AllocateFont(size_t size)
 
{
 
	return MallocT<byte>(size);
 
}
 

	
 

	
 
/* Check if a glyph should be rendered with anti-aliasing. */
 
static bool GetFontAAState(FontSize size)
 
{
 
	/* AA is only supported for 32 bpp */
 
	if (BlitterFactory::GetCurrentBlitter()->GetScreenDepth() != 32) return false;
 
@@ -352,13 +347,13 @@ const Sprite *TrueTypeFontCache::GetGlyp
 
				0,  // y_offs
 
				ST_FONT,
 
				SCC_PAL,
 
				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;
 
			new_glyph.width  = spr->width + (this->fs != FS_NORMAL);
 
			this->SetGlyphPtr(key, &new_glyph, false);
 
			return new_glyph.sprite;
 
@@ -640,13 +635,13 @@ const Sprite *FreeTypeFontCache::Interna
 
				sprite.data[x + y * sprite.width].a = aa ? slot->bitmap.buffer[x + y * slot->bitmap.pitch] : 0xFF;
 
			}
 
		}
 
	}
 

	
 
	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);
 

	
 
	return new_glyph.sprite;
 
}
src/fontcache_internal.h
Show inline comments
 
@@ -71,9 +71,7 @@ public:
 
	void ClearFontCache() override;
 
	uint GetGlyphWidth(GlyphID key) override;
 
	bool GetDrawGlyphShadow() override;
 
	bool IsBuiltInFont() override { return false; }
 
};
 

	
 
void *AllocateFont(size_t size);
 

	
 
#endif /* FONTCACHE_INTERNAL_H */
src/os/macosx/font_osx.cpp
Show inline comments
 
@@ -330,13 +330,13 @@ const Sprite *CoreTextFontCache::Interna
 
				}
 
			}
 
		}
 
	}
 

	
 
	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);
 

	
 
	return new_glyph.sprite;
 
}
 

	
src/os/windows/font_win32.cpp
Show inline comments
 
@@ -529,13 +529,13 @@ 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);
 

	
 
	return new_glyph.sprite;
 
}
src/spritecache.cpp
Show inline comments
 
@@ -806,12 +806,20 @@ static void *AllocSprite(size_t mem_req)
 
		/* Reached sentinel, but no block found yet. Delete some old entry. */
 
		DeleteEntryFromSpriteCache();
 
	}
 
}
 

	
 
/**
 
 * Sprite allocator simply using malloc.
 
 */
 
void *SimpleSpriteAlloc(size_t size)
 
{
 
	return MallocT<byte>(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.
 
 * @param sprite ID of loaded sprite
 
 * @param requested requested sprite type
 
 * @param sc the currently known sprite cache for the requested sprite
 
 * @return fallback sprite
src/spritecache.h
Show inline comments
 
@@ -23,12 +23,13 @@ struct Sprite {
 
};
 

	
 
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);
 

	
 
SpriteType GetSpriteType(SpriteID sprite);
 
uint GetOriginFileSlot(SpriteID sprite);
 
uint32 GetSpriteLocalID(SpriteID sprite);
0 comments (0 inline, 0 general)