all repos — mgba @ 9088d8e6ef7eaa35bdd21268b3d8b86513156d42

mGBA Game Boy Advance Emulator

PSP2: Add fit-to-height screen mode
Jeffrey Pfau jeffrey@endrift.com
Wed, 10 Aug 2016 23:42:31 -0700
commit

9088d8e6ef7eaa35bdd21268b3d8b86513156d42

parent

1402d3177ee902fc562e21936fc45bfab71f8bc3

3 files changed, 60 insertions(+), 17 deletions(-)

jump to
M CHANGESCHANGES

@@ -48,6 +48,7 @@ - 3DS: Attempt to use Core 2 for threads

- GUI: Screenshot dimensions are now passed through - GUI: Add back logging - PSP2: Add rumble for PS TV + - PSP2: Add fit-to-height screen mode 0.4.1: (2016-07-11) Bugfixes:
M src/platform/psp2/main.csrc/platform/psp2/main.c

@@ -116,6 +116,7 @@ .validStates = (const char*[]) {

"With Background", "Without Background", "Stretched", + "Fit Aspect Ratio", }, .nStates = 3 }
M src/platform/psp2/psp2-context.csrc/platform/psp2/psp2-context.c

@@ -38,6 +38,7 @@ static enum ScreenMode {

SM_BACKDROP, SM_PLAIN, SM_FULL, + SM_ASPECT, SM_MAX } screenMode;

@@ -280,21 +281,72 @@ vita2d_free_texture(tex);

vita2d_free_texture(screenshot); } -void mPSP2Draw(struct mGUIRunner* runner, bool faded) { - unsigned width, height; - runner->core->desiredVideoDimensions(runner->core, &width, &height); + +void _drawTex(vita2d_texture* t, unsigned width, unsigned height, bool faded) { + unsigned w = width; + unsigned h = height; + // Get greatest common divisor + while (w != 0) { + int temp = h % w; + h = w; + w = temp; + } + int gcd = h; + int aspectw = width / gcd; + int aspecth = height / gcd; + float scalex; + float scaley; + switch (screenMode) { case SM_BACKDROP: default: vita2d_draw_texture_tint(backdrop, 0, 0, (faded ? 0 : 0xC0000000) | 0x3FFFFFFF); // Fall through case SM_PLAIN: - vita2d_draw_texture_tint_part_scale(tex, (960.0f - width * 3.0f) / 2.0f, (544.0f - height * 3.0f) / 2.0f, 0, 0, width, height, 3.0f, 3.0f, (faded ? 0 : 0xC0000000) | 0x3FFFFFFF); + w = 960 / width; + h = 544 / height; + if (w * height > 544) { + scalex = h; + w = width * h; + h = height * h; + } else { + scalex = w; + w = width * w; + h = height * w; + } + scaley = scalex; + break; + case SM_ASPECT: + w = 960 / aspectw; + h = 544 / aspecth; + if (w * aspecth > 544) { + w = aspectw * h; + h = aspecth * h; + } else { + w = aspectw * w; + h = aspecth * w; + } + scalex = w / (float) width; + scaley = scalex; break; case SM_FULL: - vita2d_draw_texture_tint_scale(tex, 0, 0, 960.0f / width, 544.0f / height, (faded ? 0 : 0xC0000000) | 0x3FFFFFFF); + w = 960; + h = 544; + scalex = 960.0f / width; + scaley = 544.0f / height; break; } + vita2d_draw_texture_tint_part_scale(t, + (960.0f - w) / 2.0f, (544.0f - h) / 2.0f, + 0, 0, width, height, + scalex, scaley, + (faded ? 0 : 0xC0000000) | 0x3FFFFFFF); +} + +void mPSP2Draw(struct mGUIRunner* runner, bool faded) { + unsigned width, height; + runner->core->desiredVideoDimensions(runner->core, &width, &height); + _drawTex(tex, width, height, faded); } void mPSP2DrawScreenshot(struct mGUIRunner* runner, const uint32_t* pixels, unsigned width, unsigned height, bool faded) {

@@ -304,18 +356,7 @@ int y;

for (y = 0; y < height; ++y) { memcpy(&texpixels[256 * y], &pixels[width * y], width * 4); } - switch (screenMode) { - case SM_BACKDROP: - default: - vita2d_draw_texture_tint(backdrop, 0, 0, (faded ? 0 : 0xC0000000) | 0x3FFFFFFF); - // Fall through - case SM_PLAIN: - vita2d_draw_texture_tint_part_scale(screenshot, (960.0f - width * 3.0f) / 2.0f, (544.0f - height * 3.0f) / 2.0f, 0, 0, width, height, 3.0f, 3.0f, (faded ? 0 : 0xC0000000) | 0x3FFFFFFF); - break; - case SM_FULL: - vita2d_draw_texture_tint_scale(screenshot, 0, 0, 960.0f / width, 544.0f / height, (faded ? 0 : 0xC0000000) | 0x3FFFFFFF); - break; - } + _drawTex(screenshot, width, height, faded); } void mPSP2IncrementScreenMode(struct mGUIRunner* runner) {