Atlas - SDL_qnxmodes.c

Home / ext / SDL / src / video / qnx Lines: 1 | Size: 6890 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* 2 Simple DirectMedia Layer 3 Copyright (C) 2026 BlackBerry Limited 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 22#include "SDL_internal.h" 23#include "../SDL_sysvideo.h" 24#include "../../events/SDL_keyboard_c.h" 25#include "../../events/SDL_mouse_c.h" 26#include "../../events/SDL_windowevents_c.h" 27#include "SDL_qnx.h" 28 29#include <errno.h> 30 31// All indices not already assigned will be zero'd to SDL_PIXELFORMAT_UNKNOWN. 32static const SDL_PixelFormat _format_map[] = { 33 [SCREEN_FORMAT_RGBA4444] = SDL_PIXELFORMAT_RGBA4444, 34 [SCREEN_FORMAT_RGBA5551] = SDL_PIXELFORMAT_RGBA5551, 35 [SCREEN_FORMAT_RGB565] = SDL_PIXELFORMAT_RGB565, 36 [SCREEN_FORMAT_RGBA8888] = SDL_PIXELFORMAT_RGBA8888, 37 [SCREEN_FORMAT_RGBX8888] = SDL_PIXELFORMAT_RGBX8888, 38 [SCREEN_FORMAT_NV12] = SDL_PIXELFORMAT_NV12, 39 [SCREEN_FORMAT_YV12] = SDL_PIXELFORMAT_YV12, 40 [SCREEN_FORMAT_UYVY] = SDL_PIXELFORMAT_UYVY, 41 [SCREEN_FORMAT_YUY2] = SDL_PIXELFORMAT_YUY2, 42 [SCREEN_FORMAT_YVYU] = SDL_PIXELFORMAT_YVYU, 43 [SCREEN_FORMAT_P010] = SDL_PIXELFORMAT_P010, 44 [SCREEN_FORMAT_BGRA8888] = SDL_PIXELFORMAT_BGRA8888, 45 [SCREEN_FORMAT_BGRX8888] = SDL_PIXELFORMAT_BGRX8888, 46}; 47 48SDL_PixelFormat screenToPixelFormat(int screen_format) 49{ 50 if ((screen_format < 0) || (screen_format >= SDL_arraysize(_format_map))) { 51 return SDL_PIXELFORMAT_UNKNOWN; 52 } 53 54 return _format_map[screen_format]; 55} 56 57bool getDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display) 58{ 59 SDL_DisplayData *display_data = display->internal; 60 SDL_DisplayMode display_mode; 61 SDL_DisplayModeData *display_mode_data; 62 63 int index; 64 int display_mode_count; 65 66 screen_display_t screen_display; 67 screen_display_mode_t *screen_display_modes; 68 int screen_format; 69 int screen_refresh_rate; 70 71 if (display_data == NULL) { 72 return false; 73 } 74 screen_display = display_data->screen_display; 75 76 /* create SDL display imodes based on display mode info from the display */ 77 if (screen_get_display_property_iv(screen_display, SCREEN_PROPERTY_MODE_COUNT, &display_mode_count) < 0) { 78 return false; 79 } 80 81 screen_display_modes = SDL_calloc(display_mode_count, sizeof(screen_display_mode_t)); 82 if (screen_display_modes == NULL) { 83 return false; 84 } 85 86 if(screen_get_display_modes(screen_display, display_mode_count, screen_display_modes) < 0) { 87 SDL_free(screen_display_modes); 88 return false; 89 } 90 91 for (index = 0; index < display_mode_count; index++) { 92 display_mode_data = (SDL_DisplayModeData *)SDL_calloc(1, sizeof(SDL_DisplayModeData)); 93 if (display_mode_data == NULL) { 94 // Not much we can do about the objs we've already created at this point. 95 SDL_free(screen_display_modes); 96 return false; 97 } 98 99 SDL_zero(display_mode); 100 display_mode.w = screen_display_modes[index].width; 101 display_mode.h = screen_display_modes[index].height; 102 display_mode.pixel_density = 1.0; 103 display_mode.internal = display_mode_data; 104 105 if (screen_display_modes[index].flags & SCREEN_DISPLAY_MODE_REFRESH_VALID) { 106 screen_refresh_rate = screen_display_modes[index].refresh; 107 } else { 108 // Fallback 109 screen_refresh_rate = 60; 110 } 111 if (screen_display_modes[index].flags & SCREEN_DISPLAY_MODE_FORMAT_VALID) { 112 screen_format = screen_display_modes[index].format; 113 } else { 114 // Fallback 115 screen_format = SCREEN_FORMAT_RGBX8888; 116 } 117 display_mode.refresh_rate = screen_refresh_rate; 118 display_mode.format = screenToPixelFormat(screen_format); 119 display_mode_data->screen_format = screen_format; 120 display_mode_data->screen_display_mode = screen_display_modes[index]; 121 122 // This op can fail if the mode already exists. 123 SDL_AddFullscreenDisplayMode(display, &display_mode); 124 } 125 126 SDL_free(screen_display_modes); 127 128 return true; 129} 130 131#if 0 132// FIXME: This seems to invalidate the screen_display_t, causing issues with the 133// (get|set)_display_property_*() apis. For now, mode switching is emulated 134// instead. 135bool setDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode) 136{ 137 SDL_DisplayData *display_data = display->internal; 138 SDL_DisplayModeData *display_mode_data = mode->internal; 139 140 if ((display_data == NULL) || (display_mode_data == NULL)) { 141 return false; 142 } 143 144 // TODO: May need to call glInitConfig and screen_create_window_buffers. 145 if (screen_set_display_property_iv(display_data->screen_display, 146 SCREEN_PROPERTY_MODE, (int *)&display_mode_data->screen_display_mode.index) < 0) { 147 return false; 148 } 149 150 return true; 151} 152 153bool getDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect) 154{ 155 SDL_DisplayData *data = display->internal; 156 int size[2] = { 0, 0 }; 157 158 if (data == NULL) { 159 return false; 160 } 161 162 if (screen_get_display_property_iv(data->screen_display, SCREEN_PROPERTY_SIZE, size) < 0) { 163 return false; 164 } 165 166 rect->x = 0; 167 rect->y = 0; 168 rect->w = size[0]; 169 rect->h = size[1]; 170 return true; 171} 172#else 173bool getDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect) 174{ 175 if (display->current_mode == NULL) { 176 return false; 177 } 178 179 rect->x = 0; 180 rect->y = 0; 181 182 // When an emulated, exclusive fullscreen window has focus, treat the mode dimensions as the display bounds. 183 if (display->fullscreen_window && 184 display->fullscreen_window->fullscreen_exclusive && 185 display->fullscreen_window->current_fullscreen_mode.w != 0 && 186 display->fullscreen_window->current_fullscreen_mode.h != 0) { 187 rect->w = display->fullscreen_window->current_fullscreen_mode.w; 188 rect->h = display->fullscreen_window->current_fullscreen_mode.h; 189 } else { 190 rect->w = display->current_mode->w; 191 rect->h = display->current_mode->h; 192 } 193 return true; 194} 195#endif 196
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.