diff options
Diffstat (limited to 'contrib/SDL-3.2.8/src/video/vita/SDL_vitaframebuffer.c')
| -rw-r--r-- | contrib/SDL-3.2.8/src/video/vita/SDL_vitaframebuffer.c | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/contrib/SDL-3.2.8/src/video/vita/SDL_vitaframebuffer.c b/contrib/SDL-3.2.8/src/video/vita/SDL_vitaframebuffer.c new file mode 100644 index 0000000..b9bfb50 --- /dev/null +++ b/contrib/SDL-3.2.8/src/video/vita/SDL_vitaframebuffer.c | |||
| @@ -0,0 +1,116 @@ | |||
| 1 | /* | ||
| 2 | Simple DirectMedia Layer | ||
| 3 | Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org> | ||
| 4 | |||
| 5 | This software is provided 'as-is', without any express or implied | ||
| 6 | warranty. In no event will the authors be held liable for any damages | ||
| 7 | arising from the use of this software. | ||
| 8 | |||
| 9 | Permission is granted to anyone to use this software for any purpose, | ||
| 10 | including commercial applications, and to alter it and redistribute it | ||
| 11 | freely, subject to the following restrictions: | ||
| 12 | |||
| 13 | 1. The origin of this software must not be misrepresented; you must not | ||
| 14 | claim that you wrote the original software. If you use this software | ||
| 15 | in a product, an acknowledgment in the product documentation would be | ||
| 16 | appreciated but is not required. | ||
| 17 | 2. Altered source versions must be plainly marked as such, and must not be | ||
| 18 | misrepresented as being the original software. | ||
| 19 | 3. This notice may not be removed or altered from any source distribution. | ||
| 20 | */ | ||
| 21 | #include "SDL_internal.h" | ||
| 22 | |||
| 23 | #ifdef SDL_VIDEO_DRIVER_VITA | ||
| 24 | |||
| 25 | #include "SDL_vitavideo.h" | ||
| 26 | |||
| 27 | #include <psp2/kernel/sysmem.h> | ||
| 28 | |||
| 29 | #define SCREEN_W 960 | ||
| 30 | #define SCREEN_H 544 | ||
| 31 | #define ALIGN(x, a) (((x) + ((a)-1)) & ~((a)-1)) | ||
| 32 | #define DISPLAY_PIXEL_FORMAT SCE_DISPLAY_PIXELFORMAT_A8B8G8R8 | ||
| 33 | |||
| 34 | void *vita_gpu_alloc(unsigned int type, unsigned int size, SceUID *uid) | ||
| 35 | { | ||
| 36 | void *mem; | ||
| 37 | |||
| 38 | if (type == SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW) { | ||
| 39 | size = ALIGN(size, 256 * 1024); | ||
| 40 | } else { | ||
| 41 | size = ALIGN(size, 4 * 1024); | ||
| 42 | } | ||
| 43 | |||
| 44 | *uid = sceKernelAllocMemBlock("gpu_mem", type, size, NULL); | ||
| 45 | |||
| 46 | if (*uid < 0) { | ||
| 47 | return NULL; | ||
| 48 | } | ||
| 49 | |||
| 50 | if (sceKernelGetMemBlockBase(*uid, &mem) < 0) { | ||
| 51 | return NULL; | ||
| 52 | } | ||
| 53 | |||
| 54 | return mem; | ||
| 55 | } | ||
| 56 | |||
| 57 | void vita_gpu_free(SceUID uid) | ||
| 58 | { | ||
| 59 | void *mem = NULL; | ||
| 60 | if (sceKernelGetMemBlockBase(uid, &mem) < 0) { | ||
| 61 | return; | ||
| 62 | } | ||
| 63 | sceKernelFreeMemBlock(uid); | ||
| 64 | } | ||
| 65 | |||
| 66 | bool VITA_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch) | ||
| 67 | { | ||
| 68 | SDL_WindowData *data = window->internal; | ||
| 69 | SceDisplayFrameBuf framebuf; | ||
| 70 | |||
| 71 | *format = SDL_PIXELFORMAT_ABGR8888; | ||
| 72 | *pitch = SCREEN_W * 4; | ||
| 73 | |||
| 74 | data->buffer = vita_gpu_alloc( | ||
| 75 | SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW, | ||
| 76 | 4 * SCREEN_W * SCREEN_H, | ||
| 77 | &data->buffer_uid); | ||
| 78 | |||
| 79 | // SDL_memset the buffer to black | ||
| 80 | SDL_memset(data->buffer, 0x0, SCREEN_W * SCREEN_H * 4); | ||
| 81 | |||
| 82 | SDL_memset(&framebuf, 0x00, sizeof(SceDisplayFrameBuf)); | ||
| 83 | framebuf.size = sizeof(SceDisplayFrameBuf); | ||
| 84 | framebuf.base = data->buffer; | ||
| 85 | framebuf.pitch = SCREEN_W; | ||
| 86 | framebuf.pixelformat = DISPLAY_PIXEL_FORMAT; | ||
| 87 | framebuf.width = SCREEN_W; | ||
| 88 | framebuf.height = SCREEN_H; | ||
| 89 | sceDisplaySetFrameBuf(&framebuf, SCE_DISPLAY_SETBUF_NEXTFRAME); | ||
| 90 | |||
| 91 | *pixels = data->buffer; | ||
| 92 | |||
| 93 | return true; | ||
| 94 | } | ||
| 95 | |||
| 96 | bool VITA_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects) | ||
| 97 | { | ||
| 98 | // do nothing | ||
| 99 | return true; | ||
| 100 | } | ||
| 101 | |||
| 102 | void VITA_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window) | ||
| 103 | { | ||
| 104 | SDL_WindowData *data = window->internal; | ||
| 105 | |||
| 106 | if (!data) { | ||
| 107 | // The window wasn't fully initialized | ||
| 108 | return; | ||
| 109 | } | ||
| 110 | |||
| 111 | vita_gpu_free(data->buffer_uid); | ||
| 112 | data->buffer = NULL; | ||
| 113 | return; | ||
| 114 | } | ||
| 115 | |||
| 116 | #endif // SDL_VIDEO_DRIVER_VITA | ||
