Implemented {vi/gfx}GetDisplayResolution. Moved gfxGetFramebufferDisplayOffset into the .h as static inline. Added more comments to gfx.h.

This commit is contained in:
yellows8 2017-11-21 01:12:21 -05:00
parent 33c5181237
commit e3d0c849ad
4 changed files with 69 additions and 19 deletions

View File

@ -2,10 +2,35 @@
void gfxInitDefault(void); void gfxInitDefault(void);
void gfxExit(void); void gfxExit(void);
/// Note that "framebuffer" here is technically windowbuffer.
void gfxWaitForVsync(); void gfxWaitForVsync();
void gfxSwapBuffers(); void gfxSwapBuffers();
u8* gfxGetFramebuffer(u32* width, u32* height); u8* gfxGetFramebuffer(u32* width, u32* height);
void gfxSetDoubleBuffering(bool doubleBuffering); void gfxSetDoubleBuffering(bool doubleBuffering);
void gfxFlushBuffers(void); void gfxFlushBuffers(void);
u32 gfxGetFramebufferDisplayOffset(u32 x, u32 y); //Do not use this for getting the framebuffer width/height, use gfxGetFramebuffer for getting that.
Result gfxGetDisplayResolution(u64 *width, u64 *height);
/// Use this to get the pixel-offset in the framebuffer. Returned value is in pixels, not bytes.
/// This implements tegra blocklinear, with hard-coded constants etc.
static inline u32 gfxGetFramebufferDisplayOffset(u32 x, u32 y) {
u32 width=0, height=0;
u32 tilepos, tmp_pos;
gfxGetFramebuffer(&width, &height);
if (x >= width) x = width-1;
if (y >= height) y = height-1;
y = height-1-y;
tilepos = ((y & 127) / 16) + (x/16*8) + ((y/16/8)*(width/16*8));
tilepos = tilepos*16*16 * 4;
tmp_pos = ((y%16)/8)*512 + ((x%16)/8)*256 + ((y%8)/2)*64 + ((x%8)/4)*32 + (y%2)*16 + (x%4)*4;//This line is a modified version of code from the Tegra X1 datasheet.
return (tilepos + tmp_pos) / 4;
}

View File

@ -44,4 +44,5 @@ Result viCloseLayer(viLayer *layer);
/// See viScalingMode. /// See viScalingMode.
Result viSetLayerScalingMode(viLayer *layer, u32 ScalingMode); Result viSetLayerScalingMode(viLayer *layer, u32 ScalingMode);
Result viGetDisplayResolution(viDisplay *display, u64 *width, u64 *height);
Result viGetDisplayVsyncEvent(viDisplay *display, Handle *handle_out); Result viGetDisplayVsyncEvent(viDisplay *display, Handle *handle_out);

View File

@ -257,23 +257,7 @@ void gfxFlushBuffers(void) {
armDCacheFlush(&g_gfxFramebuf[g_gfxCurrentBuffer*g_nvgfx_singleframebuf_size], g_nvgfx_singleframebuf_size); armDCacheFlush(&g_gfxFramebuf[g_gfxCurrentBuffer*g_nvgfx_singleframebuf_size], g_nvgfx_singleframebuf_size);
} }
//This implements tegra blocklinear, with hard-coded constants etc. Result gfxGetDisplayResolution(u64 *width, u64 *height) {
u32 gfxGetFramebufferDisplayOffset(u32 x, u32 y) { return viGetDisplayResolution(&g_gfxDisplay, width, height);
u32 width=0, height=0;
u32 tilepos, tmp_pos;
gfxGetFramebuffer(&width, &height);
if (x >= width) x = width-1;
if (y >= height) y = height-1;
y = height-1-y;
tilepos = ((y & 127) / 16) + (x/16*8) + ((y/16/8)*(width/16*8));
tilepos = tilepos*16*16 * 4;
tmp_pos = ((y%16)/8)*512 + ((x%16)/8)*256 + ((y%8)/2)*64 + ((x%8)/4)*32 + (y%2)*16 + (x%4)*4;//This line is a modified version of code from the Tegra X1 datasheet.
return (tilepos + tmp_pos) / 4;
} }

View File

@ -440,6 +440,46 @@ Result viSetLayerScalingMode(viLayer *layer, u32 ScalingMode) {
return rc; return rc;
} }
Result viGetDisplayResolution(viDisplay *display, u64 *width, u64 *height) {
IpcCommand c;
ipcInitialize(&c);
struct {
u64 magic;
u64 cmd_id;
u64 DisplayId;
} *raw;
raw = ipcPrepareHeader(&c, sizeof(*raw));
raw->magic = SFCI_MAGIC;
raw->cmd_id = 1102;
raw->DisplayId = display->DisplayId;
Result rc = ipcDispatch(g_viIApplicationDisplayService);
if (R_SUCCEEDED(rc)) {
IpcCommandResponse r;
ipcParseResponse(&r);
struct {
u64 magic;
u64 result;
u64 width;
u64 height;
} *resp = r.Raw;
rc = resp->result;
if (R_SUCCEEDED(rc)) {
if (width) *width = resp->width;
if (height) *height = resp->height;
}
}
return rc;
}
Result viGetDisplayVsyncEvent(viDisplay *display, Handle *handle_out) { Result viGetDisplayVsyncEvent(viDisplay *display, Handle *handle_out) {
IpcCommand c; IpcCommand c;
ipcInitialize(&c); ipcInitialize(&c);