From e86799835214fe98463a470892245d8071421672 Mon Sep 17 00:00:00 2001 From: Curle Date: Fri, 18 Jun 2021 22:15:39 +0100 Subject: [PATCH] More drawing optimizations. --- src/system/memory/physmem.c | 6 +++--- src/video/draw.c | 35 ++++++++++++++--------------------- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/src/system/memory/physmem.c b/src/system/memory/physmem.c index dce876a..b03e917 100644 --- a/src/system/memory/physmem.c +++ b/src/system/memory/physmem.c @@ -221,11 +221,11 @@ void ListMemoryMap() { } void AddRangeToPhysMem(directptr_t Base, size_t Size) { - if(Base + Size < (void*)(LOWER_REGION)) { + if((size_t) Base + Size < (size_t) (LOWER_REGION)) { SerialPrintf("[ Mem] New range in lower memory: 0x%p, size 0x%x\r\n", Base, Size); AddRangeToBuddy(&LowBuddy, Base, Size); } else { - if(Base < (void*)(LOWER_REGION)) { + if((size_t) Base < (size_t) LOWER_REGION) { size_t difference = (size_t) LOWER_REGION - (size_t) Base; SerialPrintf("[ Mem] Base is 0x%p bytes away from the threshold, allocating 0x%p-0x%p to lower memory..\r\n", difference, Base, Base + difference); AddRangeToBuddy(&LowBuddy, Base, difference); @@ -237,7 +237,7 @@ void AddRangeToPhysMem(directptr_t Base, size_t Size) { HighBuddy.Base = Base; } - SerialPrintf("[ Mem] New range in higher memory: 0x%p, size 0x%x\r\n", Base, Size); + SerialPrintf("[ Mem] New range in higher memory: 0x%p, size 0x%x\r\n", (size_t) Base, Size); AddRangeToBuddy(&HighBuddy, Base, Size); } diff --git a/src/video/draw.c b/src/video/draw.c index 3b65c6b..46efdae 100644 --- a/src/video/draw.c +++ b/src/video/draw.c @@ -29,8 +29,8 @@ void InitPrint() { PrintInfo.charScale = 1; - PrintInfo.charPosX = 1; - PrintInfo.charPosY = 1; + PrintInfo.charPosX = 0; + PrintInfo.charPosY = 0; PrintInfo.horizontalOffset = 1; PrintInfo.scrlMode = 0; @@ -38,7 +38,7 @@ void InitPrint() { PrintInfo.screenWidth = bootldr.fb_width; PrintInfo.screenHeight = bootldr.fb_height; - PrintInfo.charsPerRow = bootldr.fb_width / (PrintInfo.charScale * PrintInfo.charWidth) - 4; + PrintInfo.charsPerRow = bootldr.fb_width / (PrintInfo.charScale * PrintInfo.charWidth); PrintInfo.rowsPerScrn = bootldr.fb_height / (PrintInfo.charScale * PrintInfo.charHeight); SerialPrintf("[Print] A single character is %ux%u pixels.\r\n", PrintInfo.charScale * PrintInfo.charWidth, PrintInfo.charScale * PrintInfo.charHeight); SerialPrintf("[Print] The screen is %ux%u, meaning you can fit %ux%u characters on screen.\r\n", bootldr.fb_width, bootldr.fb_height, PrintInfo.charsPerRow, PrintInfo.rowsPerScrn); @@ -92,8 +92,8 @@ static void DrawChar(const char character, size_t x, size_t y) { *(uint32_t* )(&fb + offset * 4) //use it to set the correct pixel on the screen = PrintInfo.charFGColor; // In the set foreground color } else { // otherwise, - *(uint32_t*)(&fb + offset *4) - = PrintInfo.charBGColor; // set the background color. + *(uint32_t* )(&fb + offset * 4) + = PrintInfo.charBGColor; // set the background color. } } } @@ -101,23 +101,14 @@ static void DrawChar(const char character, size_t x, size_t y) { } } -void DrawPixel(size_t x, size_t y) { - if(x > bootldr.fb_scanline) { - DrawPixel(x - bootldr.fb_scanline, y + (PrintInfo.charHeight * PrintInfo.charScale)); - } else if(y > bootldr.fb_height) { - DrawPixel(x, y - bootldr.fb_height); - } else { - *((uint32_t*) (&fb + (y * bootldr.fb_width + x) * 4)) = PrintInfo.charFGColor; - } +inline void DrawPixel(size_t x, size_t y) { + *((uint32_t*) (&fb + (y * bootldr.fb_width + x) * 4)) = PrintInfo.charFGColor; } void FillScreen(uint32_t color) { uint32_t currentColor = GetForegroundColor(); - SetForegroundColor(color); - for(size_t y = 0; y < bootldr.fb_height; y++) { - for(size_t x = 0; x < bootldr.fb_width; x++) { - DrawPixel(x, y); - } + for(uint32_t pixel = 0; pixel < bootldr.fb_width * bootldr.fb_height; pixel++) { + ((uint32_t*)fb)[pixel] = color; } SetForegroundColor(currentColor); } @@ -128,9 +119,10 @@ static void ProgressCursorS(size_t Steps) { size_t Rows = Steps / PrintInfo.charsPerRow; if(PrintInfo.charPosY + Rows > PrintInfo.rowsPerScrn) { size_t RowsLeft = PrintInfo.rowsPerScrn - PrintInfo.charPosY; - ProgressCursorS((Rows - RowsLeft) * PrintInfo.charsPerRow); + ProgressCursorS(RowsLeft + 1); + NewLine(); } else { - PrintInfo.charPosY++; + PrintInfo.charPosY += Rows; } } else { PrintInfo.charPosX += Steps; @@ -138,7 +130,8 @@ static void ProgressCursorS(size_t Steps) { } static void Newline() { - ProgressCursorS(PrintInfo.charsPerRow); + // One row down, unless it goes off the screen, in which case start from the top. + PrintInfo.charPosY = PrintInfo.charPosY + 1 > PrintInfo.rowsPerScrn ? 0 : PrintInfo.charPosY + 1; } static void ProgressCursor() {