summaryrefslogtreecommitdiff
path: root/contrib/SDL-3.2.8/src/video/riscos/SDL_riscosframebuffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/SDL-3.2.8/src/video/riscos/SDL_riscosframebuffer.c')
-rw-r--r--contrib/SDL-3.2.8/src/video/riscos/SDL_riscosframebuffer.c127
1 files changed, 127 insertions, 0 deletions
diff --git a/contrib/SDL-3.2.8/src/video/riscos/SDL_riscosframebuffer.c b/contrib/SDL-3.2.8/src/video/riscos/SDL_riscosframebuffer.c
new file mode 100644
index 0000000..a13cab8
--- /dev/null
+++ b/contrib/SDL-3.2.8/src/video/riscos/SDL_riscosframebuffer.c
@@ -0,0 +1,127 @@
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_RISCOS
24
25#include "../SDL_sysvideo.h"
26#include "SDL_riscosframebuffer_c.h"
27#include "SDL_riscosvideo.h"
28#include "SDL_riscoswindow.h"
29
30#include <kernel.h>
31#include <swis.h>
32
33bool RISCOS_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch)
34{
35 SDL_WindowData *internal = window->internal;
36 const char *sprite_name = "display";
37 unsigned int sprite_mode;
38 _kernel_oserror *error;
39 _kernel_swi_regs regs;
40 const SDL_DisplayMode *mode;
41 int size;
42 int w, h;
43
44 SDL_GetWindowSizeInPixels(window, &w, &h);
45
46 // Free the old framebuffer surface
47 RISCOS_DestroyWindowFramebuffer(_this, window);
48
49 // Create a new one
50 mode = SDL_GetCurrentDisplayMode(SDL_GetDisplayForWindow(window));
51 if ((SDL_ISPIXELFORMAT_PACKED(mode->format) || SDL_ISPIXELFORMAT_ARRAY(mode->format))) {
52 *format = mode->format;
53 sprite_mode = (unsigned int)mode->internal;
54 } else {
55 *format = SDL_PIXELFORMAT_XBGR8888;
56 sprite_mode = (1 | (90 << 1) | (90 << 14) | (6 << 27));
57 }
58
59 // Calculate pitch
60 *pitch = (((w * SDL_BYTESPERPIXEL(*format)) + 3) & ~3);
61
62 // Allocate the sprite area
63 size = sizeof(sprite_area) + sizeof(sprite_header) + ((*pitch) * h);
64 internal->fb_area = SDL_malloc(size);
65 if (!internal->fb_area) {
66 return false;
67 }
68
69 internal->fb_area->size = size;
70 internal->fb_area->count = 0;
71 internal->fb_area->start = 16;
72 internal->fb_area->end = 16;
73
74 // Create the actual image
75 regs.r[0] = 256 + 15;
76 regs.r[1] = (int)internal->fb_area;
77 regs.r[2] = (int)sprite_name;
78 regs.r[3] = 0;
79 regs.r[4] = w;
80 regs.r[5] = h;
81 regs.r[6] = sprite_mode;
82 error = _kernel_swi(OS_SpriteOp, &regs, &regs);
83 if (error) {
84 SDL_free(internal->fb_area);
85 return SDL_SetError("Unable to create sprite: %s (%i)", error->errmess, error->errnum);
86 }
87
88 internal->fb_sprite = (sprite_header *)(((Uint8 *)internal->fb_area) + internal->fb_area->start);
89 *pixels = ((Uint8 *)internal->fb_sprite) + internal->fb_sprite->image_offset;
90
91 return true;
92}
93
94bool RISCOS_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects)
95{
96 SDL_WindowData *internal = window->internal;
97 _kernel_swi_regs regs;
98 _kernel_oserror *error;
99
100 regs.r[0] = 512 + 52;
101 regs.r[1] = (int)internal->fb_area;
102 regs.r[2] = (int)internal->fb_sprite;
103 regs.r[3] = 0; // window->x << 1;
104 regs.r[4] = 0; // window->y << 1;
105 regs.r[5] = 0x50;
106 regs.r[6] = 0;
107 regs.r[7] = 0;
108 error = _kernel_swi(OS_SpriteOp, &regs, &regs);
109 if (error) {
110 return SDL_SetError("OS_SpriteOp 52 failed: %s (%i)", error->errmess, error->errnum);
111 }
112
113 return true;
114}
115
116void RISCOS_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window)
117{
118 SDL_WindowData *internal = window->internal;
119
120 if (internal->fb_area) {
121 SDL_free(internal->fb_area);
122 internal->fb_area = NULL;
123 }
124 internal->fb_sprite = NULL;
125}
126
127#endif // SDL_VIDEO_DRIVER_RISCOS