diff options
| author | 3gg <3gg@shellblade.net> | 2025-12-27 12:03:39 -0800 |
|---|---|---|
| committer | 3gg <3gg@shellblade.net> | 2025-12-27 12:03:39 -0800 |
| commit | 5a079a2d114f96d4847d1ee305d5b7c16eeec50e (patch) | |
| tree | 8926ab44f168acf787d8e19608857b3af0f82758 /contrib/SDL-3.2.8/src/video/haiku/SDL_bmodes.cc | |
Initial commit
Diffstat (limited to 'contrib/SDL-3.2.8/src/video/haiku/SDL_bmodes.cc')
| -rw-r--r-- | contrib/SDL-3.2.8/src/video/haiku/SDL_bmodes.cc | 307 |
1 files changed, 307 insertions, 0 deletions
diff --git a/contrib/SDL-3.2.8/src/video/haiku/SDL_bmodes.cc b/contrib/SDL-3.2.8/src/video/haiku/SDL_bmodes.cc new file mode 100644 index 0000000..32c8b6d --- /dev/null +++ b/contrib/SDL-3.2.8/src/video/haiku/SDL_bmodes.cc | |||
| @@ -0,0 +1,307 @@ | |||
| 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_HAIKU | ||
| 24 | |||
| 25 | #include <AppKit.h> | ||
| 26 | #include <InterfaceKit.h> | ||
| 27 | #include "SDL_bmodes.h" | ||
| 28 | #include "SDL_BWin.h" | ||
| 29 | |||
| 30 | #ifdef SDL_VIDEO_OPENGL | ||
| 31 | #include "SDL_bopengl.h" | ||
| 32 | #endif | ||
| 33 | |||
| 34 | #include "../../core/haiku/SDL_BApp.h" | ||
| 35 | |||
| 36 | #ifdef __cplusplus | ||
| 37 | extern "C" { | ||
| 38 | #endif | ||
| 39 | |||
| 40 | |||
| 41 | #define WRAP_BMODE 1 // FIXME: Some debate as to whether this is necessary | ||
| 42 | |||
| 43 | #if WRAP_BMODE | ||
| 44 | /* This wrapper is here so that the internal can be freed without freeing | ||
| 45 | the display_mode structure */ | ||
| 46 | struct SDL_DisplayModeData { | ||
| 47 | display_mode *bmode; | ||
| 48 | }; | ||
| 49 | #endif | ||
| 50 | |||
| 51 | static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) | ||
| 52 | { | ||
| 53 | return (SDL_BWin *)(window->internal); | ||
| 54 | } | ||
| 55 | |||
| 56 | static SDL_INLINE SDL_BLooper *_GetBeLooper() | ||
| 57 | { | ||
| 58 | return SDL_Looper; | ||
| 59 | } | ||
| 60 | |||
| 61 | static SDL_INLINE display_mode * _ExtractBMode(SDL_DisplayMode *mode) | ||
| 62 | { | ||
| 63 | #if WRAP_BMODE | ||
| 64 | return mode->internal->bmode; | ||
| 65 | #else | ||
| 66 | return (display_mode *)mode->internal; | ||
| 67 | #endif | ||
| 68 | } | ||
| 69 | |||
| 70 | // Copied from haiku/trunk/src/preferences/screen/ScreenMode.cpp | ||
| 71 | static void get_refresh_rate(display_mode &mode, int *numerator, int *denominator) | ||
| 72 | { | ||
| 73 | *numerator = (mode.timing.pixel_clock * 1000); | ||
| 74 | *denominator = (mode.timing.h_total * mode.timing.v_total); | ||
| 75 | } | ||
| 76 | |||
| 77 | |||
| 78 | #if 0 | ||
| 79 | /* TODO: | ||
| 80 | * This is a useful debugging tool. Uncomment and insert into code as needed. | ||
| 81 | */ | ||
| 82 | void _SpoutModeData(display_mode *bmode) | ||
| 83 | { | ||
| 84 | printf("BMode:\n"); | ||
| 85 | printf("\tw,h = (%i,%i)\n", bmode->virtual_width, bmode->virtual_height); | ||
| 86 | printf("\th,v = (%i,%i)\n", bmode->h_display_start, | ||
| 87 | bmode->v_display_start); | ||
| 88 | if (bmode->flags) { | ||
| 89 | printf("\tFlags:\n"); | ||
| 90 | if (bmode->flags & B_SCROLL) { | ||
| 91 | printf("\t\tB_SCROLL\n"); | ||
| 92 | } | ||
| 93 | if (bmode->flags & B_8_BIT_DAC) { | ||
| 94 | printf("\t\tB_8_BIT_DAC\n"); | ||
| 95 | } | ||
| 96 | if (bmode->flags & B_HARDWARE_CURSOR) { | ||
| 97 | printf("\t\tB_HARDWARE_CURSOR\n"); | ||
| 98 | } | ||
| 99 | if (bmode->flags & B_PARALLEL_ACCESS) { | ||
| 100 | printf("\t\tB_PARALLEL_ACCESS\n"); | ||
| 101 | } | ||
| 102 | if (bmode->flags & B_DPMS) { | ||
| 103 | printf("\t\tB_DPMS\n"); | ||
| 104 | } | ||
| 105 | if (bmode->flags & B_IO_FB_NA) { | ||
| 106 | printf("\t\tB_IO_FB_NA\n"); | ||
| 107 | } | ||
| 108 | } | ||
| 109 | printf("\tTiming:\n"); | ||
| 110 | printf("\t\tpx clock: %i\n", bmode->timing.pixel_clock); | ||
| 111 | printf("\t\th - display: %i sync start: %i sync end: %i total: %i\n", | ||
| 112 | bmode->timing.h_display, bmode->timing.h_sync_start, | ||
| 113 | bmode->timing.h_sync_end, bmode->timing.h_total); | ||
| 114 | printf("\t\tv - display: %i sync start: %i sync end: %i total: %i\n", | ||
| 115 | bmode->timing.v_display, bmode->timing.v_sync_start, | ||
| 116 | bmode->timing.v_sync_end, bmode->timing.v_total); | ||
| 117 | if (bmode->timing.flags) { | ||
| 118 | printf("\t\tFlags:\n"); | ||
| 119 | if (bmode->timing.flags & B_BLANK_PEDESTAL) { | ||
| 120 | printf("\t\t\tB_BLANK_PEDESTAL\n"); | ||
| 121 | } | ||
| 122 | if (bmode->timing.flags & B_TIMING_INTERLACED) { | ||
| 123 | printf("\t\t\tB_TIMING_INTERLACED\n"); | ||
| 124 | } | ||
| 125 | if (bmode->timing.flags & B_POSITIVE_HSYNC) { | ||
| 126 | printf("\t\t\tB_POSITIVE_HSYNC\n"); | ||
| 127 | } | ||
| 128 | if (bmode->timing.flags & B_POSITIVE_VSYNC) { | ||
| 129 | printf("\t\t\tB_POSITIVE_VSYNC\n"); | ||
| 130 | } | ||
| 131 | if (bmode->timing.flags & B_SYNC_ON_GREEN) { | ||
| 132 | printf("\t\t\tB_SYNC_ON_GREEN\n"); | ||
| 133 | } | ||
| 134 | } | ||
| 135 | } | ||
| 136 | #endif | ||
| 137 | |||
| 138 | |||
| 139 | |||
| 140 | SDL_PixelFormat HAIKU_ColorSpaceToSDLPxFormat(uint32 colorspace) | ||
| 141 | { | ||
| 142 | switch (colorspace) { | ||
| 143 | case B_CMAP8: | ||
| 144 | return SDL_PIXELFORMAT_INDEX8; | ||
| 145 | break; | ||
| 146 | case B_RGB15: | ||
| 147 | case B_RGBA15: | ||
| 148 | case B_RGB15_BIG: | ||
| 149 | case B_RGBA15_BIG: | ||
| 150 | return SDL_PIXELFORMAT_XRGB1555; | ||
| 151 | break; | ||
| 152 | case B_RGB16: | ||
| 153 | case B_RGB16_BIG: | ||
| 154 | return SDL_PIXELFORMAT_RGB565; | ||
| 155 | break; | ||
| 156 | case B_RGB24: | ||
| 157 | case B_RGB24_BIG: | ||
| 158 | return SDL_PIXELFORMAT_BGR24; | ||
| 159 | break; | ||
| 160 | case B_RGB32: | ||
| 161 | case B_RGBA32: | ||
| 162 | case B_RGB32_BIG: | ||
| 163 | case B_RGBA32_BIG: | ||
| 164 | return SDL_PIXELFORMAT_XRGB8888; | ||
| 165 | break; | ||
| 166 | } | ||
| 167 | |||
| 168 | // May never get here, but safer and needed to shut up compiler | ||
| 169 | SDL_SetError("Invalid color space"); | ||
| 170 | return SDL_PIXELFORMAT_UNKNOWN; | ||
| 171 | } | ||
| 172 | |||
| 173 | static void _BDisplayModeToSdlDisplayMode(display_mode *bmode, SDL_DisplayMode *mode) | ||
| 174 | { | ||
| 175 | SDL_zerop(mode); | ||
| 176 | mode->w = bmode->virtual_width; | ||
| 177 | mode->h = bmode->virtual_height; | ||
| 178 | get_refresh_rate(*bmode, &mode->refresh_rate_numerator, &mode->refresh_rate_denominator); | ||
| 179 | |||
| 180 | #if WRAP_BMODE | ||
| 181 | SDL_DisplayModeData *data = (SDL_DisplayModeData*)SDL_calloc(1, sizeof(SDL_DisplayModeData)); | ||
| 182 | data->bmode = bmode; | ||
| 183 | |||
| 184 | mode->internal = data; | ||
| 185 | #else | ||
| 186 | mode->internal = bmode; | ||
| 187 | #endif | ||
| 188 | |||
| 189 | // Set the format | ||
| 190 | mode->format = HAIKU_ColorSpaceToSDLPxFormat(bmode->space); | ||
| 191 | } | ||
| 192 | |||
| 193 | // Later, there may be more than one monitor available | ||
| 194 | static void _AddDisplay(BScreen *screen) | ||
| 195 | { | ||
| 196 | SDL_DisplayMode mode; | ||
| 197 | display_mode bmode; | ||
| 198 | screen->GetMode(&bmode); | ||
| 199 | |||
| 200 | _BDisplayModeToSdlDisplayMode(&bmode, &mode); | ||
| 201 | |||
| 202 | SDL_AddBasicVideoDisplay(&mode); | ||
| 203 | } | ||
| 204 | |||
| 205 | /* | ||
| 206 | * Functions called by SDL | ||
| 207 | */ | ||
| 208 | |||
| 209 | bool HAIKU_InitModes(SDL_VideoDevice *_this) | ||
| 210 | { | ||
| 211 | BScreen screen; | ||
| 212 | |||
| 213 | /* TODO: When Haiku supports multiple display screens, call | ||
| 214 | _AddDisplayScreen() for each of them. */ | ||
| 215 | _AddDisplay(&screen); | ||
| 216 | return true; | ||
| 217 | } | ||
| 218 | |||
| 219 | void HAIKU_QuitModes(SDL_VideoDevice *_this) | ||
| 220 | { | ||
| 221 | return; | ||
| 222 | } | ||
| 223 | |||
| 224 | |||
| 225 | bool HAIKU_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect) | ||
| 226 | { | ||
| 227 | BScreen bscreen; | ||
| 228 | BRect rc = bscreen.Frame(); | ||
| 229 | rect->x = (int)rc.left; | ||
| 230 | rect->y = (int)rc.top; | ||
| 231 | rect->w = (int)rc.Width() + 1; | ||
| 232 | rect->h = (int)rc.Height() + 1; | ||
| 233 | return true; | ||
| 234 | } | ||
| 235 | |||
| 236 | bool HAIKU_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display) | ||
| 237 | { | ||
| 238 | // Get the current screen | ||
| 239 | BScreen bscreen; | ||
| 240 | |||
| 241 | // Iterate through all of the modes | ||
| 242 | SDL_DisplayMode mode; | ||
| 243 | display_mode this_bmode; | ||
| 244 | display_mode *bmodes; | ||
| 245 | uint32 count, i; | ||
| 246 | |||
| 247 | // Get graphics-hardware supported modes | ||
| 248 | bscreen.GetModeList(&bmodes, &count); | ||
| 249 | bscreen.GetMode(&this_bmode); | ||
| 250 | |||
| 251 | for (i = 0; i < count; ++i) { | ||
| 252 | // FIXME: Apparently there are errors with colorspace changes | ||
| 253 | if (bmodes[i].space == this_bmode.space) { | ||
| 254 | _BDisplayModeToSdlDisplayMode(&bmodes[i], &mode); | ||
| 255 | SDL_AddFullscreenDisplayMode(display, &mode); | ||
| 256 | } | ||
| 257 | } | ||
| 258 | free(bmodes); // This should NOT be SDL_free() | ||
| 259 | return true; | ||
| 260 | } | ||
| 261 | |||
| 262 | |||
| 263 | bool HAIKU_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode) | ||
| 264 | { | ||
| 265 | // Get the current screen | ||
| 266 | BScreen bscreen; | ||
| 267 | if (!bscreen.IsValid()) { | ||
| 268 | printf(__FILE__": %d - ERROR: BAD SCREEN\n", __LINE__); | ||
| 269 | } | ||
| 270 | |||
| 271 | // Set the mode using the driver data | ||
| 272 | display_mode *bmode = _ExtractBMode(mode); | ||
| 273 | |||
| 274 | |||
| 275 | // FIXME: Is the first option always going to be the right one? | ||
| 276 | uint32 c = 0, i; | ||
| 277 | display_mode *bmode_list; | ||
| 278 | bscreen.GetModeList(&bmode_list, &c); | ||
| 279 | for (i = 0; i < c; ++i) { | ||
| 280 | if ( bmode_list[i].space == bmode->space && | ||
| 281 | bmode_list[i].virtual_width == bmode->virtual_width && | ||
| 282 | bmode_list[i].virtual_height == bmode->virtual_height ) { | ||
| 283 | bmode = &bmode_list[i]; | ||
| 284 | break; | ||
| 285 | } | ||
| 286 | } | ||
| 287 | |||
| 288 | if (bscreen.SetMode(bmode) != B_OK) { | ||
| 289 | return SDL_SetError("Bad video mode"); | ||
| 290 | } | ||
| 291 | |||
| 292 | free(bmode_list); // This should NOT be SDL_free() | ||
| 293 | |||
| 294 | #ifdef SDL_VIDEO_OPENGL | ||
| 295 | /* FIXME: Is there some way to reboot the OpenGL context? This doesn't | ||
| 296 | help */ | ||
| 297 | // HAIKU_GL_RebootContexts(_this); | ||
| 298 | #endif | ||
| 299 | |||
| 300 | return true; | ||
| 301 | } | ||
| 302 | |||
| 303 | #ifdef __cplusplus | ||
| 304 | } | ||
| 305 | #endif | ||
| 306 | |||
| 307 | #endif // SDL_VIDEO_DRIVER_HAIKU | ||
