Skip to content

Commit

Permalink
eliminate temp buffer variables/simplify initscreen calls
Browse files Browse the repository at this point in the history
  • Loading branch information
w3irDv committed Aug 7, 2024
1 parent 911f381 commit 484ea7f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 39 deletions.
3 changes: 0 additions & 3 deletions include/utils/DrawUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ class DrawUtils {

static void LogConsoleFree();

static void initBuffers(void *tvBuffer, void *drcBuffer);

static void beginDraw();

static void endDraw();
Expand Down Expand Up @@ -92,7 +90,6 @@ class DrawUtils {
static uint8_t *tvBuffer;
static uint8_t *drcBuffer;

static void *sBufferTV, *sBufferDRC;
static uint32_t sBufferSizeTV, sBufferSizeDRC;
static BOOL sConsoleHasForeground;
};
46 changes: 10 additions & 36 deletions src/utils/DrawUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,64 +26,50 @@ bool DrawUtils::isBackBuffer;

uint8_t *DrawUtils::tvBuffer = nullptr;
uint8_t *DrawUtils::drcBuffer = nullptr;
/*
uint32_t DrawUtils::sBufferSizeTV = 0;
uint32_t DrawUtils::sBufferSizeDRC = 0;
*/
uint32_t DrawUtils::sBufferSizeTV = 0, DrawUtils::sBufferSizeDRC = 0;
BOOL DrawUtils::sConsoleHasForeground = TRUE;

static SFT pFont = {};

static Color font_col(0xFFFFFFFF);

void *DrawUtils::sBufferTV = NULL, *DrawUtils::sBufferDRC = NULL;
uint32_t DrawUtils::sBufferSizeTV = 0, DrawUtils::sBufferSizeDRC = 0;
BOOL DrawUtils::sConsoleHasForeground = TRUE;

uint32_t
DrawUtils::initScreen()
{
MEMHeapHandle heap = MEMGetBaseHeapHandle(MEM_BASE_HEAP_MEM1);
MEMRecordStateForFrmHeap(heap, CONSOLE_FRAME_HEAP_TAG);

if (sBufferSizeTV) {
sBufferTV = MEMAllocFromFrmHeapEx(heap, sBufferSizeTV, 4);
DrawUtils::tvBuffer = static_cast<uint8_t *>(MEMAllocFromFrmHeapEx(heap, sBufferSizeTV, 4));
}

if (sBufferSizeDRC) {
sBufferDRC = MEMAllocFromFrmHeapEx(heap, sBufferSizeDRC, 4);
DrawUtils::drcBuffer = static_cast<uint8_t *>(MEMAllocFromFrmHeapEx(heap, sBufferSizeDRC, 4));
}


sConsoleHasForeground = TRUE;

OSScreenSetBufferEx(SCREEN_TV, sBufferTV);
OSScreenSetBufferEx(SCREEN_DRC, sBufferDRC);
DrawUtils::initBuffers(sBufferTV, sBufferDRC);
OSScreenSetBufferEx(SCREEN_TV, DrawUtils::tvBuffer);
OSScreenSetBufferEx(SCREEN_DRC, DrawUtils::drcBuffer);

for (int i = 0; i<2; i++) // both buffers to black
{
DrawUtils::clear(COLOR_BLACK);
DrawUtils::endDraw();
}
DrawUtils::endDraw(); // flip buffers

DrawUtils::setRedraw(true); // force a redraw when reentering

return 0;

}

uint32_t
DrawUtils::deinitScreen()
{

for (int i = 0; i<2; i++) // both buffers to black
{
DrawUtils::clear(COLOR_BLACK);
DrawUtils::endDraw();
}

MEMHeapHandle heap = MEMGetBaseHeapHandle(MEM_BASE_HEAP_MEM1);
MEMFreeByStateToFrmHeap(heap, CONSOLE_FRAME_HEAP_TAG);
sConsoleHasForeground = FALSE;
return 0;

}


Expand Down Expand Up @@ -123,11 +109,6 @@ void DrawUtils::setRedraw(bool value) {
redraw = value;
}

void DrawUtils::initBuffers(void *sBufferTV_, void *sBufferDRC_) {
DrawUtils::tvBuffer = (uint8_t *) sBufferTV_;
DrawUtils::drcBuffer = (uint8_t *) sBufferDRC_;
}

void DrawUtils::beginDraw() {
uint32_t pixel = *(uint32_t *) tvBuffer;

Expand All @@ -144,13 +125,6 @@ void DrawUtils::beginDraw() {
}

void DrawUtils::endDraw() {
// OSScreenFlipBuffersEx already flushes the cache?
// DCFlushRange(tvBuffer, sBufferSizeTV);
// DCFlushRange(drcBuffer, sBufferSizeDRC);

DCFlushRange(sBufferTV, sBufferSizeTV);
DCFlushRange(sBufferDRC, sBufferSizeDRC);

OSScreenFlipBuffersEx(SCREEN_DRC);
OSScreenFlipBuffersEx(SCREEN_TV);
}
Expand Down

0 comments on commit 484ea7f

Please sign in to comment.