Implemented experimental precaching of the system font
files during starting the app_server. Should in theory reduce disk seeks when booting from CD. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31788 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
a0f0618739
commit
ab7a6c0999
@ -27,8 +27,6 @@
|
||||
|
||||
#include <new>
|
||||
|
||||
using std::nothrow;
|
||||
|
||||
//#define TRACE_FONT_MANAGER
|
||||
#ifdef TRACE_FONT_MANAGER
|
||||
# define FTRACE(x) printf x
|
||||
@ -115,6 +113,12 @@ FontManager::FontManager()
|
||||
_LoadRecentFontMappings();
|
||||
|
||||
fInitStatus = _SetDefaultFonts();
|
||||
|
||||
if (fInitStatus == B_OK) {
|
||||
// Precache the plain and bold fonts
|
||||
_PrecacheFontFile(fDefaultPlainFont);
|
||||
_PrecacheFontFile(fDefaultBoldFont);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -332,6 +336,8 @@ FontManager::_LoadRecentFontMappings()
|
||||
veraFontPath.SetTo(ttfontsPath.Path());
|
||||
veraFontPath.Append("DejaVuSansMono.ttf");
|
||||
_AddDefaultMapping("DejaVu Sans Mono", "Book", veraFontPath.Path());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -482,6 +488,37 @@ FontManager::_SetDefaultFonts()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
FontManager::_PrecacheFontFile(const ServerFont* font)
|
||||
{
|
||||
if (font == NULL)
|
||||
return;
|
||||
|
||||
size_t bufferSize = 32768;
|
||||
uint8* buffer = new (std::nothrow) uint8[bufferSize];
|
||||
if (buffer == NULL) {
|
||||
// We don't care. Pre-caching doesn't make sense anyways when there
|
||||
// is not enough RAM...
|
||||
return;
|
||||
}
|
||||
|
||||
BFile file(font->Path(), B_READ_ONLY);
|
||||
if (file.InitCheck() != B_OK) {
|
||||
delete[] buffer;
|
||||
return;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
// We just want the file in the kernel file cache...
|
||||
ssize_t read = file.Read(buffer, bufferSize);
|
||||
if (read < bufferSize)
|
||||
break;
|
||||
}
|
||||
|
||||
delete[] buffer;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
FontManager::_AddSystemPaths()
|
||||
{
|
||||
@ -570,7 +607,7 @@ FontManager::_AddFont(font_directory& directory, BEntry& entry)
|
||||
if (!family->AddStyle(style)) {
|
||||
delete style;
|
||||
delete family;
|
||||
return B_NO_MEMORY;
|
||||
return B_NO_MEMORY;
|
||||
}
|
||||
|
||||
directory.styles.AddItem(style);
|
||||
|
@ -88,6 +88,7 @@ private:
|
||||
const char* fallbackStyle,
|
||||
uint16 fallbackFace);
|
||||
status_t _SetDefaultFonts();
|
||||
void _PrecacheFontFile(const ServerFont* font);
|
||||
void _AddSystemPaths();
|
||||
font_directory* _FindDirectory(node_ref& nodeRef);
|
||||
void _RemoveDirectory(font_directory* directory);
|
||||
|
Loading…
x
Reference in New Issue
Block a user