1 /*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2018 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 #if 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
RISCOS_CreateWindowFramebuffer(_THIS,SDL_Window * window,Uint32 * format,void ** pixels,int * pitch)33 int RISCOS_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch)
34 {
35 SDL_WindowData *driverdata = (SDL_WindowData *) window->driverdata;
36 const char *sprite_name = "display";
37 unsigned int sprite_mode;
38 _kernel_oserror *error;
39 _kernel_swi_regs regs;
40 SDL_DisplayMode mode;
41 int size;
42
43 /* Free the old framebuffer surface */
44 RISCOS_DestroyWindowFramebuffer(_this, window);
45
46 /* Create a new one */
47 SDL_GetCurrentDisplayMode(SDL_GetWindowDisplayIndex(window), &mode);
48 if ((SDL_ISPIXELFORMAT_PACKED(mode.format) || SDL_ISPIXELFORMAT_ARRAY(mode.format))) {
49 *format = mode.format;
50 sprite_mode = (unsigned int)mode.driverdata;
51 } else {
52 *format = SDL_PIXELFORMAT_BGR888;
53 sprite_mode = (1 | (90 << 1) | (90 << 14) | (6 << 27));
54 }
55
56 /* Calculate pitch */
57 *pitch = (((window->w * SDL_BYTESPERPIXEL(*format)) + 3) & ~3);
58
59 /* Allocate the sprite area */
60 size = sizeof(sprite_area) + sizeof(sprite_header) + ((*pitch) * window->h);
61 driverdata->fb_area = SDL_malloc(size);
62 if (!driverdata->fb_area) {
63 return SDL_OutOfMemory();
64 }
65
66 driverdata->fb_area->size = size;
67 driverdata->fb_area->count = 0;
68 driverdata->fb_area->start = 16;
69 driverdata->fb_area->end = 16;
70
71 /* Create the actual image */
72 regs.r[0] = 256+15;
73 regs.r[1] = (int)driverdata->fb_area;
74 regs.r[2] = (int)sprite_name;
75 regs.r[3] = 0;
76 regs.r[4] = window->w;
77 regs.r[5] = window->h;
78 regs.r[6] = sprite_mode;
79 error = _kernel_swi(OS_SpriteOp, ®s, ®s);
80 if (error != NULL) {
81 SDL_free(driverdata->fb_area);
82 return SDL_SetError("Unable to create sprite: %s (%i)", error->errmess, error->errnum);
83 }
84
85 driverdata->fb_sprite = (sprite_header *)(((Uint8 *)driverdata->fb_area) + driverdata->fb_area->start);
86 *pixels = ((Uint8 *)driverdata->fb_sprite) + driverdata->fb_sprite->image_offset;
87
88 return 0;
89 }
90
RISCOS_UpdateWindowFramebuffer(_THIS,SDL_Window * window,const SDL_Rect * rects,int numrects)91 int RISCOS_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects)
92 {
93 SDL_WindowData *driverdata = (SDL_WindowData *) window->driverdata;
94 _kernel_swi_regs regs;
95 _kernel_oserror *error;
96
97 regs.r[0] = 512+52;
98 regs.r[1] = (int)driverdata->fb_area;
99 regs.r[2] = (int)driverdata->fb_sprite;
100 regs.r[3] = 0; /* window->x << 1; */
101 regs.r[4] = 0; /* window->y << 1; */
102 regs.r[5] = 0x50;
103 regs.r[6] = 0;
104 regs.r[7] = 0;
105 error = _kernel_swi(OS_SpriteOp, ®s, ®s);
106 if (error != NULL) {
107 return SDL_SetError("OS_SpriteOp 52 failed: %s (%i)", error->errmess, error->errnum);
108 }
109
110 return 0;
111 }
112
RISCOS_DestroyWindowFramebuffer(_THIS,SDL_Window * window)113 void RISCOS_DestroyWindowFramebuffer(_THIS, SDL_Window * window)
114 {
115 SDL_WindowData *driverdata = (SDL_WindowData *) window->driverdata;
116
117 if (driverdata->fb_area) {
118 SDL_free(driverdata->fb_area);
119 driverdata->fb_area = NULL;
120 }
121 driverdata->fb_sprite = NULL;
122 }
123
124 #endif /* SDL_VIDEO_DRIVER_RISCOS */
125
126 /* vi: set ts=4 sw=4 expandtab: */
127