|
@@ -642,57 +642,51 @@ SDL_DisplayID SDL_AddBasicVideoDisplay(const SDL_DisplayMode *desktop_mode)
|
|
|
|
|
|
SDL_DisplayID SDL_AddVideoDisplay(const SDL_VideoDisplay *display, SDL_bool send_event)
|
|
|
{
|
|
|
- SDL_VideoDisplay *displays, *new_display;
|
|
|
- SDL_DisplayID id = 0;
|
|
|
-
|
|
|
- displays = (SDL_VideoDisplay *)SDL_malloc((_this->num_displays + 1) * sizeof(*displays));
|
|
|
- if (displays) {
|
|
|
- int i;
|
|
|
-
|
|
|
- if (_this->displays) {
|
|
|
- /* The display list may contain self-referential pointers to the desktop mode. */
|
|
|
- SDL_memcpy(displays, _this->displays, _this->num_displays * sizeof(*displays));
|
|
|
- for (i = 0; i < _this->num_displays; ++i) {
|
|
|
- if (displays[i].current_mode == &_this->displays[i].desktop_mode) {
|
|
|
- displays[i].current_mode = &displays[i].desktop_mode;
|
|
|
- }
|
|
|
- }
|
|
|
+ SDL_VideoDisplay **displays, *new_display;
|
|
|
+ SDL_DisplayID id;
|
|
|
+ int i;
|
|
|
|
|
|
- SDL_free(_this->displays);
|
|
|
- }
|
|
|
+ new_display = (SDL_VideoDisplay *)SDL_malloc(sizeof(*new_display));
|
|
|
+ if (!new_display) {
|
|
|
+ SDL_OutOfMemory();
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
|
|
|
- _this->displays = displays;
|
|
|
- id = _this->next_object_id++;
|
|
|
- new_display = &displays[_this->num_displays++];
|
|
|
+ displays = (SDL_VideoDisplay **)SDL_realloc(_this->displays, (_this->num_displays + 1) * sizeof(*displays));
|
|
|
+ if (!displays) {
|
|
|
+ SDL_OutOfMemory();
|
|
|
+ SDL_free(new_display);
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ _this->displays = displays;
|
|
|
+ _this->displays[_this->num_displays++] = new_display;
|
|
|
|
|
|
- SDL_memcpy(new_display, display, sizeof(*new_display));
|
|
|
- new_display->id = id;
|
|
|
- new_display->device = _this;
|
|
|
- if (display->name) {
|
|
|
- new_display->name = SDL_strdup(display->name);
|
|
|
- } else {
|
|
|
- char name[32];
|
|
|
+ id = _this->next_object_id++;
|
|
|
+ SDL_memcpy(new_display, display, sizeof(*new_display));
|
|
|
+ new_display->id = id;
|
|
|
+ new_display->device = _this;
|
|
|
+ if (display->name) {
|
|
|
+ new_display->name = SDL_strdup(display->name);
|
|
|
+ } else {
|
|
|
+ char name[32];
|
|
|
|
|
|
- SDL_itoa(id, name, 10);
|
|
|
- new_display->name = SDL_strdup(name);
|
|
|
- }
|
|
|
- if (new_display->content_scale == 0.0f) {
|
|
|
- new_display->content_scale = 1.0f;
|
|
|
- }
|
|
|
+ SDL_itoa(id, name, 10);
|
|
|
+ new_display->name = SDL_strdup(name);
|
|
|
+ }
|
|
|
+ if (new_display->content_scale == 0.0f) {
|
|
|
+ new_display->content_scale = 1.0f;
|
|
|
+ }
|
|
|
|
|
|
- new_display->desktop_mode.displayID = id;
|
|
|
- new_display->current_mode = &new_display->desktop_mode;
|
|
|
- SDL_FinalizeDisplayMode(&new_display->desktop_mode);
|
|
|
+ new_display->desktop_mode.displayID = id;
|
|
|
+ new_display->current_mode = &new_display->desktop_mode;
|
|
|
+ SDL_FinalizeDisplayMode(&new_display->desktop_mode);
|
|
|
|
|
|
- for (i = 0; i < new_display->num_fullscreen_modes; ++i) {
|
|
|
- new_display->fullscreen_modes[i].displayID = id;
|
|
|
- }
|
|
|
+ for (i = 0; i < new_display->num_fullscreen_modes; ++i) {
|
|
|
+ new_display->fullscreen_modes[i].displayID = id;
|
|
|
+ }
|
|
|
|
|
|
- if (send_event) {
|
|
|
- SDL_SendDisplayEvent(new_display, SDL_EVENT_DISPLAY_CONNECTED, 0);
|
|
|
- }
|
|
|
- } else {
|
|
|
- SDL_OutOfMemory();
|
|
|
+ if (send_event) {
|
|
|
+ SDL_SendDisplayEvent(new_display, SDL_EVENT_DISPLAY_CONNECTED, 0);
|
|
|
}
|
|
|
return id;
|
|
|
}
|
|
@@ -715,7 +709,7 @@ void SDL_DelVideoDisplay(SDL_DisplayID displayID, SDL_bool send_event)
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- display = &_this->displays[display_index];
|
|
|
+ display = _this->displays[display_index];
|
|
|
|
|
|
if (send_event) {
|
|
|
SDL_SendDisplayEvent(display, SDL_EVENT_DISPLAY_DISCONNECTED, 0);
|
|
@@ -727,6 +721,7 @@ void SDL_DelVideoDisplay(SDL_DisplayID displayID, SDL_bool send_event)
|
|
|
display->desktop_mode.driverdata = NULL;
|
|
|
SDL_free(display->driverdata);
|
|
|
display->driverdata = NULL;
|
|
|
+ SDL_free(display);
|
|
|
|
|
|
if (display_index < (_this->num_displays - 1)) {
|
|
|
SDL_memmove(&_this->displays[display_index], &_this->displays[display_index + 1], (_this->num_displays - display_index - 1) * sizeof(_this->displays[display_index]));
|
|
@@ -755,7 +750,7 @@ SDL_DisplayID *SDL_GetDisplays(int *count)
|
|
|
}
|
|
|
|
|
|
for (i = 0; i < _this->num_displays; ++i) {
|
|
|
- displays[i] = _this->displays[i].id;
|
|
|
+ displays[i] = _this->displays[i]->id;
|
|
|
}
|
|
|
displays[i] = 0;
|
|
|
} else {
|
|
@@ -776,7 +771,7 @@ SDL_VideoDisplay *SDL_GetVideoDisplay(SDL_DisplayID displayID)
|
|
|
if (display_index < 0) {
|
|
|
return NULL;
|
|
|
}
|
|
|
- return &_this->displays[display_index];
|
|
|
+ return _this->displays[display_index];
|
|
|
}
|
|
|
|
|
|
SDL_VideoDisplay *SDL_GetVideoDisplayForWindow(SDL_Window *window)
|
|
@@ -790,7 +785,7 @@ SDL_DisplayID SDL_GetPrimaryDisplay(void)
|
|
|
SDL_UninitializedVideo();
|
|
|
return 0;
|
|
|
}
|
|
|
- return _this->displays[0].id;
|
|
|
+ return _this->displays[0]->id;
|
|
|
}
|
|
|
|
|
|
int SDL_GetDisplayIndex(SDL_DisplayID displayID)
|
|
@@ -802,7 +797,7 @@ int SDL_GetDisplayIndex(SDL_DisplayID displayID)
|
|
|
}
|
|
|
|
|
|
for (display_index = 0; display_index < _this->num_displays; ++display_index) {
|
|
|
- if (displayID == _this->displays[display_index].id) {
|
|
|
+ if (displayID == _this->displays[display_index]->id) {
|
|
|
return display_index;
|
|
|
}
|
|
|
}
|
|
@@ -853,7 +848,7 @@ int SDL_GetDisplayBounds(SDL_DisplayID displayID, SDL_Rect *rect)
|
|
|
rect->x = 0;
|
|
|
rect->y = 0;
|
|
|
} else {
|
|
|
- SDL_GetDisplayBounds(_this->displays[SDL_GetDisplayIndex(displayID) - 1].id, rect);
|
|
|
+ SDL_GetDisplayBounds(_this->displays[SDL_GetDisplayIndex(displayID) - 1]->id, rect);
|
|
|
rect->x += rect->w;
|
|
|
}
|
|
|
rect->w = display->current_mode->w;
|
|
@@ -1256,7 +1251,7 @@ static SDL_DisplayID GetDisplayForRect(int x, int y, int w, int h)
|
|
|
|
|
|
if (_this) {
|
|
|
for (i = 0; i < _this->num_displays; ++i) {
|
|
|
- SDL_VideoDisplay *display = &_this->displays[i];
|
|
|
+ SDL_VideoDisplay *display = _this->displays[i];
|
|
|
SDL_Rect display_rect;
|
|
|
SDL_GetDisplayBounds(display->id, &display_rect);
|
|
|
|
|
@@ -1390,14 +1385,14 @@ static void SDL_CheckWindowDisplayChanged(SDL_Window *window)
|
|
|
/* Sanity check our fullscreen windows */
|
|
|
display_index = SDL_GetDisplayIndex(displayID);
|
|
|
for (i = 0; i < _this->num_displays; ++i) {
|
|
|
- SDL_VideoDisplay *display = &_this->displays[i];
|
|
|
+ SDL_VideoDisplay *display = _this->displays[i];
|
|
|
|
|
|
if (display->fullscreen_window == window) {
|
|
|
if (display_index != i) {
|
|
|
if (display_index < 0) {
|
|
|
display_index = i;
|
|
|
} else {
|
|
|
- SDL_VideoDisplay *new_display = &_this->displays[display_index];
|
|
|
+ SDL_VideoDisplay *new_display = _this->displays[display_index];
|
|
|
|
|
|
/* The window was moved to a different display */
|
|
|
if (new_display->fullscreen_window &&
|
|
@@ -1489,7 +1484,7 @@ static int SDL_UpdateFullscreenMode(SDL_Window *window, SDL_bool fullscreen)
|
|
|
}
|
|
|
} else {
|
|
|
for (i = 0; i < _this->num_displays; ++i) {
|
|
|
- display = &_this->displays[i];
|
|
|
+ display = _this->displays[i];
|
|
|
if (display->fullscreen_window == window) {
|
|
|
break;
|
|
|
}
|
|
@@ -1528,7 +1523,7 @@ static int SDL_UpdateFullscreenMode(SDL_Window *window, SDL_bool fullscreen)
|
|
|
}
|
|
|
} else if (fullscreen && window->last_fullscreen_exclusive_display && !window->fullscreen_exclusive) {
|
|
|
for (i = 0; i < _this->num_displays; ++i) {
|
|
|
- SDL_VideoDisplay *last_display = &_this->displays[i];
|
|
|
+ SDL_VideoDisplay *last_display = _this->displays[i];
|
|
|
if (last_display->fullscreen_window == window) {
|
|
|
SDL_SetDisplayModeForDisplay(last_display, NULL);
|
|
|
if (_this->SetWindowFullscreen) {
|
|
@@ -1584,7 +1579,7 @@ static int SDL_UpdateFullscreenMode(SDL_Window *window, SDL_bool fullscreen)
|
|
|
|
|
|
/* Restore the video mode on other displays if needed */
|
|
|
for (i = 0; i < _this->num_displays; ++i) {
|
|
|
- SDL_VideoDisplay *other = &_this->displays[i];
|
|
|
+ SDL_VideoDisplay *other = _this->displays[i];
|
|
|
if (other != display && other->fullscreen_window == window) {
|
|
|
SDL_SetDisplayModeForDisplay(other, NULL);
|
|
|
if (_this->SetWindowFullscreen) {
|
|
@@ -3733,7 +3728,7 @@ void SDL_VideoQuit(void)
|
|
|
_this->VideoQuit(_this);
|
|
|
|
|
|
for (i = _this->num_displays; i--; ) {
|
|
|
- SDL_VideoDisplay *display = &_this->displays[i];
|
|
|
+ SDL_VideoDisplay *display = _this->displays[i];
|
|
|
SDL_DelVideoDisplay(display->id, SDL_FALSE);
|
|
|
}
|
|
|
if (_this->displays) {
|