mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-24 05:42:40 +02:00
console_sw: Use Framebuffer object instead of old gfx api. Moved RGBA8/_MAXALPHA to framebuffer.h.
This commit is contained in:
parent
f37518d848
commit
1b18a3b056
@ -8,6 +8,12 @@
|
|||||||
#include "../nvidia/map.h"
|
#include "../nvidia/map.h"
|
||||||
#include "native_window.h"
|
#include "native_window.h"
|
||||||
|
|
||||||
|
/// Converts red, green, blue, and alpha components to packed RGBA8 (i.e. \ref PIXEL_FORMAT_RGBA_8888).
|
||||||
|
#define RGBA8(r,g,b,a) (((r)&0xff)|(((g)&0xff)<<8)|(((b)&0xff)<<16)|(((a)&0xff)<<24))
|
||||||
|
|
||||||
|
/// Same as \ref RGBA8 except with alpha=0xff.
|
||||||
|
#define RGBA8_MAXALPHA(r,g,b) RGBA8(r,g,b,0xff)
|
||||||
|
|
||||||
/// Framebuffer structure.
|
/// Framebuffer structure.
|
||||||
typedef struct Framebuffer {
|
typedef struct Framebuffer {
|
||||||
NWindow *win;
|
NWindow *win;
|
||||||
|
@ -9,12 +9,6 @@
|
|||||||
#include "../types.h"
|
#include "../types.h"
|
||||||
#include "../nvidia/fence.h"
|
#include "../nvidia/fence.h"
|
||||||
|
|
||||||
/// Converts red, green, blue, and alpha components to packed RGBA8.
|
|
||||||
#define RGBA8(r,g,b,a) (((r)&0xff)|(((g)&0xff)<<8)|(((b)&0xff)<<16)|(((a)&0xff)<<24))
|
|
||||||
|
|
||||||
/// Same as \ref RGBA8 except with alpha=0xff.
|
|
||||||
#define RGBA8_MAXALPHA(r,g,b) RGBA8(r,g,b,0xff)
|
|
||||||
|
|
||||||
/// GfxMode set by \ref gfxSetMode. The default is GfxMode_LinearDouble. Note that the text-console (see console.h) sets this to GfxMode_TiledDouble.
|
/// GfxMode set by \ref gfxSetMode. The default is GfxMode_LinearDouble. Note that the text-console (see console.h) sets this to GfxMode_TiledDouble.
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
|
@ -519,7 +519,7 @@ PrintConsole* consoleInit(PrintConsole* console) {
|
|||||||
console->renderer = getDefaultConsoleRenderer();
|
console->renderer = getDefaultConsoleRenderer();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (console->renderer->init(console)) {
|
if (!console->consoleInitialised && console->renderer->init(console)) {
|
||||||
console->consoleInitialised = true;
|
console->consoleInitialised = true;
|
||||||
consoleCls('2');
|
consoleCls('2');
|
||||||
return console;
|
return console;
|
||||||
|
@ -3,7 +3,8 @@
|
|||||||
#include <sys/iosupport.h>
|
#include <sys/iosupport.h>
|
||||||
#include "result.h"
|
#include "result.h"
|
||||||
#include "runtime/devices/console.h"
|
#include "runtime/devices/console.h"
|
||||||
#include "display/gfx.h"
|
#include "display/native_window.h"
|
||||||
|
#include "display/framebuffer.h"
|
||||||
|
|
||||||
//set up the palette for color printing
|
//set up the palette for color printing
|
||||||
static const u32 colorTable[] = {
|
static const u32 colorTable[] = {
|
||||||
@ -38,8 +39,10 @@ static const u32 colorTable[] = {
|
|||||||
struct ConsoleSwRenderer
|
struct ConsoleSwRenderer
|
||||||
{
|
{
|
||||||
ConsoleRenderer base;
|
ConsoleRenderer base;
|
||||||
|
Framebuffer fb; ///< Framebuffer object
|
||||||
u32 *frameBuffer; ///< Framebuffer address
|
u32 *frameBuffer; ///< Framebuffer address
|
||||||
u32 *frameBuffer2; ///< Framebuffer address
|
u32 frameBufferStride; ///< Framebuffer stride (in pixels)
|
||||||
|
bool initialized;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct ConsoleSwRenderer* ConsoleSwRenderer(PrintConsole* con)
|
static struct ConsoleSwRenderer* ConsoleSwRenderer(PrintConsole* con)
|
||||||
@ -56,34 +59,54 @@ static bool ConsoleSwRenderer_init(PrintConsole* con)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (R_FAILED(gfxInitDefault())) {
|
if (sw->initialized) {
|
||||||
// Graphics failed to initialize
|
// We're already initialized
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
NWindow* win = nwindowGetDefault();
|
||||||
|
u32 width = con->font.tileWidth * con->consoleWidth;
|
||||||
|
u32 height = con->font.tileHeight * con->consoleHeight;
|
||||||
|
|
||||||
|
if (R_FAILED(nwindowSetDimensions(win, width, height))) {
|
||||||
|
// Failed to set dimensions
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 width, height;
|
if (R_FAILED(framebufferCreate(&sw->fb, win, width, height, PIXEL_FORMAT_RGBA_8888, 2))) {
|
||||||
gfxGetFramebufferResolution(&width, &height);
|
// Failed to create framebuffer
|
||||||
if (con->consoleWidth > (width/16) || con->consoleHeight > (height/16)) {
|
|
||||||
// Unsupported console size
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
gfxSetMode(GfxMode_TiledDouble);
|
if (R_FAILED(framebufferMakeLinear(&sw->fb))) {
|
||||||
sw->frameBuffer = (u32*)gfxGetFramebuffer(NULL, NULL);
|
// Failed to make framebuffer linear
|
||||||
gfxSwapBuffers();
|
framebufferClose(&sw->fb);
|
||||||
sw->frameBuffer2 = (u32*)gfxGetFramebuffer(NULL, NULL);
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
sw->frameBuffer = NULL;
|
||||||
|
sw->frameBufferStride = 0;
|
||||||
|
sw->initialized = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ConsoleSwRenderer_deinit(PrintConsole* con)
|
static u32* _getFrameBuffer(struct ConsoleSwRenderer* sw, u32* out_stride)
|
||||||
{
|
{
|
||||||
gfxExit();
|
if (!sw->frameBuffer) {
|
||||||
|
sw->frameBuffer = (u32*)framebufferBegin(&sw->fb, &sw->frameBufferStride);
|
||||||
|
sw->frameBufferStride /= sizeof(u32);
|
||||||
|
}
|
||||||
|
if (out_stride)
|
||||||
|
*out_stride = sw->frameBufferStride;
|
||||||
|
return sw->frameBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ConsoleSwRenderer_drawChar(PrintConsole* con, int x, int y, int c)
|
static void ConsoleSwRenderer_drawChar(PrintConsole* con, int x, int y, int c)
|
||||||
{
|
{
|
||||||
struct ConsoleSwRenderer* sw = ConsoleSwRenderer(con);
|
struct ConsoleSwRenderer* sw = ConsoleSwRenderer(con);
|
||||||
|
u32 stride;
|
||||||
|
u32* frameBuffer = _getFrameBuffer(sw, &stride);
|
||||||
const u16 *fontdata = (const u16*)con->font.gfx + (16 * c);
|
const u16 *fontdata = (const u16*)con->font.gfx + (16 * c);
|
||||||
|
|
||||||
int writingColor = con->fg;
|
int writingColor = con->fg;
|
||||||
@ -124,16 +147,12 @@ static void ConsoleSwRenderer_drawChar(PrintConsole* con, int x, int y, int c)
|
|||||||
|
|
||||||
for (i=0;i<16;i++) {
|
for (i=0;i<16;i++) {
|
||||||
for (j=0;j<8;j++) {
|
for (j=0;j<8;j++) {
|
||||||
uint32_t screenOffset = gfxGetFramebufferDisplayOffset(x + i, y + j);
|
uint32_t screenOffset = (x + i) + stride*(y + j);
|
||||||
screen = &sw->frameBuffer[screenOffset];
|
screen = &frameBuffer[screenOffset];
|
||||||
if (bvaltop >> (16*j) & mask) { *screen = fg; }else{ *screen = bg; }
|
|
||||||
screen = &sw->frameBuffer2[screenOffset];
|
|
||||||
if (bvaltop >> (16*j) & mask) { *screen = fg; }else{ *screen = bg; }
|
if (bvaltop >> (16*j) & mask) { *screen = fg; }else{ *screen = bg; }
|
||||||
|
|
||||||
screenOffset = gfxGetFramebufferDisplayOffset(x + i, y + j + 8);
|
screenOffset = (x + i) + stride*(y + j + 8);
|
||||||
screen = &sw->frameBuffer[screenOffset];
|
screen = &frameBuffer[screenOffset];
|
||||||
if (bvalbtm >> (16*j) & mask) { *screen = fg; }else{ *screen = bg; }
|
|
||||||
screen = &sw->frameBuffer2[screenOffset];
|
|
||||||
if (bvalbtm >> (16*j) & mask) { *screen = fg; }else{ *screen = bg; }
|
if (bvalbtm >> (16*j) & mask) { *screen = fg; }else{ *screen = bg; }
|
||||||
}
|
}
|
||||||
mask >>= 1;
|
mask >>= 1;
|
||||||
@ -143,6 +162,8 @@ static void ConsoleSwRenderer_drawChar(PrintConsole* con, int x, int y, int c)
|
|||||||
static void ConsoleSwRenderer_scrollWindow(PrintConsole* con)
|
static void ConsoleSwRenderer_scrollWindow(PrintConsole* con)
|
||||||
{
|
{
|
||||||
struct ConsoleSwRenderer* sw = ConsoleSwRenderer(con);
|
struct ConsoleSwRenderer* sw = ConsoleSwRenderer(con);
|
||||||
|
u32 stride;
|
||||||
|
u32* frameBuffer = _getFrameBuffer(sw, &stride);
|
||||||
int i,j;
|
int i,j;
|
||||||
u32 x, y;
|
u32 x, y;
|
||||||
|
|
||||||
@ -153,11 +174,8 @@ static void ConsoleSwRenderer_scrollWindow(PrintConsole* con)
|
|||||||
u32 *from;
|
u32 *from;
|
||||||
u32 *to;
|
u32 *to;
|
||||||
for (j=0;j<(con->windowHeight-1)*16;j++) {
|
for (j=0;j<(con->windowHeight-1)*16;j++) {
|
||||||
to = &sw->frameBuffer[gfxGetFramebufferDisplayOffset(x + i, y + j)];
|
to = &frameBuffer[(x + i) + stride*(y + j)];
|
||||||
from = &sw->frameBuffer[gfxGetFramebufferDisplayOffset(x + i, y + 16 + j)];
|
from = &frameBuffer[(x + i) + stride*(y + 16 + j)];
|
||||||
*to = *from;
|
|
||||||
to = &sw->frameBuffer2[gfxGetFramebufferDisplayOffset(x + i, y + j)];
|
|
||||||
from = &sw->frameBuffer2[gfxGetFramebufferDisplayOffset(x + i, y + 16 + j)];
|
|
||||||
*to = *from;
|
*to = *from;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -165,8 +183,26 @@ static void ConsoleSwRenderer_scrollWindow(PrintConsole* con)
|
|||||||
|
|
||||||
static void ConsoleSwRenderer_flushAndSwap(PrintConsole* con)
|
static void ConsoleSwRenderer_flushAndSwap(PrintConsole* con)
|
||||||
{
|
{
|
||||||
gfxFlushBuffers();
|
struct ConsoleSwRenderer* sw = ConsoleSwRenderer(con);
|
||||||
gfxSwapBuffers();
|
_getFrameBuffer(sw, NULL); // Make sure we dequeued
|
||||||
|
|
||||||
|
framebufferEnd(&sw->fb);
|
||||||
|
sw->frameBuffer = NULL;
|
||||||
|
sw->frameBufferStride = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void ConsoleSwRenderer_deinit(PrintConsole* con)
|
||||||
|
{
|
||||||
|
struct ConsoleSwRenderer* sw = ConsoleSwRenderer(con);
|
||||||
|
|
||||||
|
if (sw->initialized) {
|
||||||
|
if (sw->frameBuffer)
|
||||||
|
ConsoleSwRenderer_flushAndSwap(con);
|
||||||
|
|
||||||
|
framebufferClose(&sw->fb);
|
||||||
|
sw->initialized = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct ConsoleSwRenderer s_consoleSwRenderer =
|
static struct ConsoleSwRenderer s_consoleSwRenderer =
|
||||||
@ -177,9 +213,7 @@ static struct ConsoleSwRenderer s_consoleSwRenderer =
|
|||||||
ConsoleSwRenderer_drawChar,
|
ConsoleSwRenderer_drawChar,
|
||||||
ConsoleSwRenderer_scrollWindow,
|
ConsoleSwRenderer_scrollWindow,
|
||||||
ConsoleSwRenderer_flushAndSwap,
|
ConsoleSwRenderer_flushAndSwap,
|
||||||
}, //base
|
}
|
||||||
NULL, //frameBuffer
|
|
||||||
NULL, //frameBuffer2
|
|
||||||
};
|
};
|
||||||
|
|
||||||
__attribute__((weak)) ConsoleRenderer* getDefaultConsoleRenderer(void)
|
__attribute__((weak)) ConsoleRenderer* getDefaultConsoleRenderer(void)
|
||||||
|
Loading…
Reference in New Issue
Block a user