From 4f504f8a2e70b72f6a7a3f52b9ccdaf5d22f1fe6 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 30 Mar 2024 11:52:25 +1100 Subject: [PATCH] PSP: Add screenshot support --- src/AudioBackend.c | 8 ++++---- src/Graphics_PSP.c | 19 ++++++++++++++++++- src/Graphics_PSVita.c | 18 ++++-------------- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/AudioBackend.c b/src/AudioBackend.c index c0e61d7a6..016e388ab 100644 --- a/src/AudioBackend.c +++ b/src/AudioBackend.c @@ -1133,6 +1133,7 @@ void Audio_FreeChunks(void** chunks, int numChunks) { #include #include #include +#include struct AudioBuffer { int available; @@ -1220,7 +1221,7 @@ void Audio_SetVolume(struct AudioContext* ctx, int volume) { cc_result Audio_QueueChunk(struct AudioContext* ctx, void* chunk, cc_uint32 dataSize) { // Audio buffers must be aligned and padded to a multiple of 32 bytes - if (((uintptr_t)chunk & 0x20) != 0) { + if (((uintptr_t)chunk & 0x1F) != 0) { Platform_Log1("Audio_QueueData: tried to queue buffer with non-aligned audio buffer 0x%x\n", &chunk); } @@ -1273,9 +1274,8 @@ cc_bool Audio_DescribeError(cc_result res, cc_string* dst) { } cc_result Audio_AllocChunks(cc_uint32 size, void** chunks, int numChunks) { - size = (size + 0x1F) & ~0x1F; // round up to nearest multiple of 0x20 - cc_uint32 alignedSize = ((size*numChunks) + 0x1F) & ~0x1F; // round up to nearest multiple of 0x20 - void* dst = aligned_alloc(0x20, alignedSize); + size = (size + 0x1F) & ~0x1F; // round up to nearest multiple of 0x20 + void* dst = memalign(0x20, size); if (!dst) return ERR_OUT_OF_MEMORY; for (int i = 0; i < numChunks; i++) { diff --git a/src/Graphics_PSP.c b/src/Graphics_PSP.c index 308c0884b..324e6cb34 100644 --- a/src/Graphics_PSP.c +++ b/src/Graphics_PSP.c @@ -233,8 +233,25 @@ void Gfx_CalcPerspectiveMatrix(struct Matrix* matrix, float fov, float aspect, f /*########################################################################################################################* *-----------------------------------------------------------Misc----------------------------------------------------------* *#########################################################################################################################*/ +static BitmapCol* PSP_GetRow(struct Bitmap* bmp, int y, void* ctx) { + cc_uint8* fb = (cc_uint8*)ctx; + return (BitmapCol*)(fb + y * BUFFER_WIDTH * 4); +} + cc_result Gfx_TakeScreenshot(struct Stream* output) { - return ERR_NOT_SUPPORTED; + int fbWidth, fbFormat; + void* fb; + + int res = sceDisplayGetFrameBuf(&fb, &fbWidth, &fbFormat, PSP_DISPLAY_SETBUF_NEXTFRAME); + if (res < 0) return res; + if (!fb) return ERR_NOT_SUPPORTED; + + struct Bitmap bmp; + bmp.scan0 = NULL; + bmp.width = SCREEN_WIDTH; + bmp.height = SCREEN_HEIGHT; + + return Png_Encode(&bmp, output, PSP_GetRow, false, fb); } void Gfx_GetApiInfo(cc_string* info) { diff --git a/src/Graphics_PSVita.c b/src/Graphics_PSVita.c index 2ef543520..fbfc41d9d 100644 --- a/src/Graphics_PSVita.c +++ b/src/Graphics_PSVita.c @@ -563,8 +563,9 @@ void Gfx_Create(void) { if (!Gfx.Created) InitGPU(); in_scene = false; - Gfx.MaxTexWidth = 512; - Gfx.MaxTexHeight = 512; + Gfx.MaxTexWidth = 1024; + Gfx.MaxTexHeight = 1024; + Gfx.MaxTexSize = 512 * 512; Gfx.Created = true; gfx_vsync = true; @@ -624,15 +625,11 @@ static void GPUTexture_Unref(GfxResourceID* resource) { struct GPUTexture* tex = (struct GPUTexture*)(*resource); if (!tex) return; *resource = NULL; - - cc_uintptr addr = tex; - Platform_Log1("TEX UNREF %h", &addr); + LinkedList_Append(tex, del_textures_head, del_textures_tail); } static void GPUTexture_Free(struct GPUTexture* tex) { - cc_uintptr addr = tex; - Platform_Log1("TEX DELETE %h", &addr); FreeGPUMemory(tex->uid); Mem_Free(tex); } @@ -838,9 +835,6 @@ struct GPUBuffer* GPUBuffer_Alloc(int size) { buffer->data = AllocGPUMemory(size, SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE, SCE_GXM_MEMORY_ATTRIB_READ, &buffer->uid); - - cc_uintptr addr = buffer->data; - Platform_Log2("VB ALLOC %h = %i bytes", &addr, &size); return buffer; } @@ -851,14 +845,10 @@ static void GPUBuffer_Unref(GfxResourceID* resource) { if (!buf) return; *resource = NULL; - cc_uintptr addr = buf; - Platform_Log1("VB UNREF %h", &addr); LinkedList_Append(buf, del_buffers_head, del_buffers_tail); } static void GPUBuffer_Free(struct GPUBuffer* buf) { - cc_uintptr addr = buf; - Platform_Log1("VB DELETE %h", &addr); FreeGPUMemory(buf->uid); Mem_Free(buf); }