Skip to content

Commit

Permalink
Move the vast majority of resources into Base/lemon/resources
Browse files Browse the repository at this point in the history
Reduces the memory footprint of the initrd.
  • Loading branch information
fido2020 committed Jun 21, 2021
1 parent 7729045 commit 587dad0
Show file tree
Hide file tree
Showing 46 changed files with 39 additions and 31 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.vscode
!.vscode/c_cpp_properties.json
.cache
*.img
*.wad
Expand All @@ -16,7 +15,6 @@ Kernel/subprojects/*
Applications/build
LibLemon/build
LibLemon/subprojects/*
!LibLemon/subprojects/json.wrap
System/build
Scripts/build-win/mount.cfg
Initrd/*
Expand All @@ -28,4 +26,4 @@ Ports/*
Toolchain/*
!Toolchain/*.sh
!Toolchain/*.patch
InterfaceCompiler/lic
InterfaceCompiler/lic
4 changes: 2 additions & 2 deletions Applications/GUITest/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ int main(){
gridView->SetLayout(Lemon::GUI::LayoutSize::Stretch, Lemon::GUI::LayoutSize::Stretch, Lemon::GUI::WidgetAlignment::WAlignLeft);

surface_t folderIcon;
Lemon::Graphics::LoadImage("/initrd/folder.png", &folderIcon);
Lemon::Graphics::LoadImage("/system/lemon/resources/icons/folder.png", &folderIcon);
surface_t fileIcon;
Lemon::Graphics::LoadImage("/initrd/file.png", &fileIcon);
Lemon::Graphics::LoadImage("/system/lemon/resources/icons/file.png", &fileIcon);

Lemon::GUI::GridItem item1;
item1.name = "Item";
Expand Down
2 changes: 1 addition & 1 deletion Applications/Minesweeper/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ int main(int argc, char** argv){
window->CreateMenuBar();
window->menuBar->items.push_back(gameMenu);

Lemon::Graphics::LoadImage("/initrd/minesweeper.png", &resources);
Lemon::Graphics::LoadImage("/system/lemon/resources/minesweeper.png", &resources);

window->AddWidget(&game);

Expand Down
2 changes: 1 addition & 1 deletion Applications/Shell/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ int main(){
syscall(SYS_GET_VIDEO_MODE, (uintptr_t)&videoInfo,0,0,0,0);
syscall(SYS_UNAME, (uintptr_t)versionString,0,0,0,0);

Lemon::Graphics::LoadImage("/initrd/menubuttons.png", &menuButton);
Lemon::Graphics::LoadImage("/system/lemon/resources/menubuttons.png", &menuButton);

handle_t tempEndpoint = 0;
while(tempEndpoint <= 0){
Expand Down
6 changes: 3 additions & 3 deletions Applications/Shell/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,17 @@ void InitializeMenu(){
menuWindow->OnPaint = OnPaint;
menuWindow->rootContainer.background = {0, 0, 0, 0};

Lemon::Graphics::LoadImage("/initrd/applicationicon.png", &defaultIcon);
Lemon::Graphics::LoadImage("/system/lemon/resources/icons/application.png", &defaultIcon);

categories["Games"] = MenuCategory("Games");
Lemon::Graphics::LoadImage("/initrd/gamesicon.png", &categories["Games"].icon);
Lemon::Graphics::LoadImage("/system/lemon/resources/icons/games.png", &categories["Games"].icon);

categories["Utilities"] = MenuCategory("Utilities");
categories["Other"] = MenuCategory("Other");

{
MenuItem item("Terminal...", "Open a Terminal", "terminal.lef", GetItemID());
Lemon::Graphics::LoadImage("/initrd/terminalicon.png", &item.icon);
Lemon::Graphics::LoadImage("/system/lemon/resources/icons/terminal.png", &item.icon);
items[item.id] = item;
rootItems.push_back(item);
}
Expand Down
2 changes: 1 addition & 1 deletion Applications/SysInfo/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ char versionString[80];
lemon_sysinfo_t sysInfo;

int main(int argc, char** argv){
Lemon::Graphics::LoadImage("/initrd/banner.png", &banner);
Lemon::Graphics::LoadImage("/system/lemon/resources/banner.png", &banner);

bannerW = new Lemon::GUI::Bitmap({{0, 0}, {300, banner.height}}, &banner);

Expand Down
2 changes: 1 addition & 1 deletion Applications/Terminal/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ void PrintChar(char ch){
}

int main(int argc, char** argv){
terminalFont = Lemon::Graphics::LoadFont("/system/lemon/fonts/sourcecodepro.ttf", "termmonospace");
terminalFont = Lemon::Graphics::LoadFont("/system/lemon/resources/fonts/sourcecodepro.ttf", "termmonospace");
if(!terminalFont){
terminalFont = Lemon::Graphics::GetFont("default");
}
Expand Down
2 changes: 1 addition & 1 deletion Applications/TextEdit/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ int main(int argc, char** argv){
window->AddWidget(textBox);
textBox->SetLayout(Lemon::GUI::LayoutSize::Stretch, Lemon::GUI::LayoutSize::Stretch, Lemon::GUI::WidgetAlignment::WAlignLeft);

textBox->font = Lemon::Graphics::LoadFont("/system/lemon/fonts/sourcecodepro.ttf", "monospace", 10);
textBox->font = Lemon::Graphics::LoadFont("/system/lemon/resources/fonts/sourcecodepro.ttf", "monospace", 10);
textBox->multiline = true;
textBox->editable = true;

Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes
22 changes: 15 additions & 7 deletions Kernel/src/Kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ void KernelProcess(){

Network::InitializeConnections();

if(progressBuffer)
Video::DrawBitmapImage(videoMode.width/2 + 24 * 3, videoMode.height/2 + 292/2 + 48, 24, 24, progressBuffer);

if(FsNode* node = fs::ResolvePath("/initrd/modules.cfg")){
char* buffer = new char[node->size + 1];

Expand Down Expand Up @@ -92,6 +89,9 @@ void KernelProcess(){
fs::volumes->add_back(new fs::LinkVolume(initrd, "lib")); // If /system/lib is not present is /initrd
}

if(progressBuffer)
Video::DrawBitmapImage(videoMode.width/2 + 24 * 3, videoMode.height/2 + 292/2 + 48, 24, 24, progressBuffer);

Log::Info("Loading Init Process...");
FsNode* initFsNode = nullptr;
char* argv[] = {"init.lef"};
Expand Down Expand Up @@ -121,6 +121,10 @@ void KernelProcess(){

Scheduler::StartProcess(initProc);

if(progressBuffer){
delete[] progressBuffer;
}

for(;;) {
acquireLock(&Scheduler::destroyedProcessesLock);
for(auto it = Scheduler::destroyedProcesses->begin(); it != Scheduler::destroyedProcesses->end(); it++){
Expand Down Expand Up @@ -200,15 +204,19 @@ extern "C"
if(initrd){
if((splashFile = fs::FindDir(initrd,"splash.bmp"))){
uint32_t size = splashFile->size;
uint8_t* buffer = (uint8_t*)kmalloc(size);
if(fs::Read(splashFile, 0, size, buffer))
uint8_t* buffer = new uint8_t[size];

if(fs::Read(splashFile, 0, size, buffer) > 0)
Video::DrawBitmapImage(videoMode.width/2 - 620/2, videoMode.height/2 - 150/2, 621, 150, buffer);

delete[] buffer;
} else Log::Warning("Could not load splash image");

if((splashFile = fs::FindDir(initrd,"pbar.bmp"))){
uint32_t size = splashFile->size;
progressBuffer = (uint8_t*)kmalloc(size);
if(fs::Read(splashFile, 0, size, progressBuffer)){
progressBuffer = new uint8_t[size];

if(fs::Read(splashFile, 0, size, progressBuffer) > 0){
Video::DrawBitmapImage(videoMode.width/2 - 24*4, videoMode.height/2 + 292/2 + 48, 24, 24, progressBuffer);
Video::DrawBitmapImage(videoMode.width/2 - 24*3, videoMode.height/2 + 292/2 + 48, 24, 24, progressBuffer);
}
Expand Down
4 changes: 2 additions & 2 deletions LibLemon/src/gfx/font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ namespace Lemon::Graphics{

mainFont = new Font;

if(int err = FT_New_Face(library, "/system/lemon/fonts/notosans.ttf", 0, &mainFont->face)){
printf("Freetype Error (%d) loading font /system/lemon/fonts/notosans.ttf\n", err);
if(int err = FT_New_Face(library, "/system/lemon/resources/fonts/notosans.ttf", 0, &mainFont->face)){
printf("Freetype Error (%d) loading font /system/lemon/resources/fonts/notosans.ttf\n", err);
return;
}

Expand Down
14 changes: 7 additions & 7 deletions LibLemon/src/gui/fileview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace Lemon::GUI {

__attribute__((constructor))
void InitializeFVIcons(){
if(FILE* f = fopen("/initrd/disk.png", "rb")){
if(FILE* f = fopen("/system/lemon/resources/icons/disk.png", "rb")){
Graphics::LoadImage(f, &FileView::diskIcon);
fclose(f);
} else {
Expand All @@ -41,7 +41,7 @@ namespace Lemon::GUI {
FileView::diskIcon.width = 0;
}

if(FILE* f = fopen("/initrd/folder.png", "rb")){
if(FILE* f = fopen("/system/lemon/resources/icons/folder.png", "rb")){
Graphics::LoadImage(f, &FileView::folderIcon);
fclose(f);
} else {
Expand All @@ -50,7 +50,7 @@ namespace Lemon::GUI {
FileView::folderIcon.width = 0;
}

if(FILE* f = fopen("/initrd/file.png", "rb")){
if(FILE* f = fopen("/system/lemon/resources/icons/file.png", "rb")){
Graphics::LoadImage(f, &FileView::fileIcon);
fclose(f);
} else {
Expand All @@ -59,7 +59,7 @@ namespace Lemon::GUI {
FileView::fileIcon.width = 0;
}

if(FILE* f = fopen("/initrd/textfile.png", "rb")){
if(FILE* f = fopen("/system/lemon/resources/icons/filetext.png", "rb")){
Graphics::LoadImage(f, &FileView::textFileIcon);
fclose(f);
} else {
Expand All @@ -68,7 +68,7 @@ namespace Lemon::GUI {
FileView::textFileIcon.width = 0;
}

if(FILE* f = fopen("/initrd/jsonfile.png", "rb")){
if(FILE* f = fopen("/system/lemon/resources/icons/filejson.png", "rb")){
Graphics::LoadImage(f, &FileView::jsonFileIcon);
fclose(f);
} else {
Expand All @@ -77,7 +77,7 @@ namespace Lemon::GUI {
FileView::jsonFileIcon.width = 0;
}

if(FILE* f = fopen("/initrd/disksml.png", "rb")){
if(FILE* f = fopen("/system/lemon/resources/icons/disksml.png", "rb")){
Graphics::LoadImage(f, &FileView::diskIconSml);
fclose(f);
} else {
Expand All @@ -86,7 +86,7 @@ namespace Lemon::GUI {
FileView::diskIconSml.width = 0;
}

if(FILE* f = fopen("/initrd/foldersml.png", "rb")){
if(FILE* f = fopen("/system/lemon/resources/icons/foldersml.png", "rb")){
Graphics::LoadImage(f, &FileView::folderIconSml);
fclose(f);
} else {
Expand Down
2 changes: 2 additions & 0 deletions LibLemon/src/gui/widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,8 @@ namespace Lemon::GUI {
void GridView::UpdateFixedBounds(){
Widget::UpdateFixedBounds();

assert(itemSize.x);

itemsPerRow = fixedBounds.width / itemSize.x;

ResetScrollBar();
Expand Down
Binary file added Resources/sourcecodepro.ttf
Binary file not shown.
4 changes: 2 additions & 2 deletions System/LemonWM/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ int main(){

Lemon::Graphics::DrawRect(0, 0, renderSurface.width, renderSurface.height, 255, 0, 128, &fbSurface);

if(int e = Lemon::Graphics::LoadImage("/initrd/winbuttons.png", &wm.compositor.windowButtons)){
if(int e = Lemon::Graphics::LoadImage("/system/lemon/resources/winbuttons.png", &wm.compositor.windowButtons)){
printf("LemonWM: Warning: Error %d loading buttons.\n", e);
}

if(int e = Lemon::Graphics::LoadImage("/initrd/mouse.png", &wm.compositor.mouseCursor)){
if(int e = Lemon::Graphics::LoadImage("/system/lemon/resources/mouse.png", &wm.compositor.mouseCursor)){
printf("LemonWM: Warning: Error %d loading mouse cursor.\n", e);
wm.compositor.mouseCursor.buffer = new uint8_t[4 * 4 * 4];
wm.compositor.mouseCursor.width = wm.compositor.mouseCursor.height = 4;
Expand Down

0 comments on commit 587dad0

Please sign in to comment.