From 1c4723ac66363c1b0dd08f2095869b810bfd16ec Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 12 Nov 2023 21:37:00 -0800 Subject: [PATCH] SDL_CreateWindowFrom() now takes a set of properties that describe the native window and options. --- docs/README-migration.md | 5 ++++ include/SDL3/SDL_hints.h | 41 --------------------------- include/SDL3/SDL_video.h | 34 +++++++++++++++++----- src/dynapi/SDL_dynapi_procs.h | 2 +- src/video/SDL_sysvideo.h | 2 +- src/video/SDL_video.c | 12 +++++--- src/video/cocoa/SDL_cocoawindow.h | 3 +- src/video/cocoa/SDL_cocoawindow.m | 31 ++++++++++++++------ src/video/haiku/SDL_bvideo.cc | 1 - src/video/haiku/SDL_bwindow.cc | 33 --------------------- src/video/haiku/SDL_bwindow.h | 1 - src/video/kmsdrm/SDL_kmsdrmvideo.c | 6 ---- src/video/kmsdrm/SDL_kmsdrmvideo.h | 1 - src/video/psp/SDL_pspvideo.c | 6 ---- src/video/psp/SDL_pspvideo.h | 1 - src/video/raspberry/SDL_rpivideo.c | 6 ---- src/video/raspberry/SDL_rpivideo.h | 1 - src/video/vita/SDL_vitavideo.c | 6 ---- src/video/vita/SDL_vitavideo.h | 1 - src/video/windows/SDL_windowsopengl.c | 15 ---------- src/video/windows/SDL_windowsopengl.h | 1 - src/video/windows/SDL_windowswindow.c | 35 +++++++++++------------ src/video/windows/SDL_windowswindow.h | 2 +- src/video/x11/SDL_x11window.c | 7 +++-- src/video/x11/SDL_x11window.h | 2 +- test/testautomation_hints.c | 2 -- test/testnative.c | 6 +++- 27 files changed, 94 insertions(+), 169 deletions(-) diff --git a/docs/README-migration.md b/docs/README-migration.md index 6e64bf1260..d0eda28d59 100644 --- a/docs/README-migration.md +++ b/docs/README-migration.md @@ -559,7 +559,10 @@ The following hints have been removed: * SDL_HINT_IME_SUPPORT_EXTENDED_TEXT - the normal text editing event has extended text * SDL_HINT_MOUSE_RELATIVE_SCALING - mouse coordinates are no longer automatically scaled by the SDL renderer * SDL_HINT_RENDER_LOGICAL_SIZE_MODE - the logical size mode is explicitly set with SDL_SetRenderLogicalPresentation() +* SDL_HINT_VIDEO_FOREIGN_WINDOW_OPENGL - replaced with the "opengl" property in SDL_CreateWindowFrom() +* SDL_HINT_VIDEO_FOREIGN_WINDOW_VULKAN - replaced with the "vulkan" property in SDL_CreateWindowFrom() * SDL_HINT_VIDEO_HIGHDPI_DISABLED - high DPI support is always enabled +* SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT - replaced with the "win32.pixel_format_hwnd" in SDL_CreateWindowFrom() * SDL_HINT_VIDEO_X11_FORCE_EGL - use SDL_HINT_VIDEO_FORCE_EGL instead * SDL_HINT_VIDEO_X11_XINERAMA - Xinerama no longer supported by the X11 backend * SDL_HINT_VIDEO_X11_XVIDMODE - Xvidmode no longer supported by the X11 backend @@ -1260,6 +1263,8 @@ Rather than iterating over displays using display index, there is a new function SDL_CreateWindow() has been simplified and no longer takes a window position. You can use SDL_CreateWindowWithPosition() if you need to set the window position when creating it. +SDL_CreateWindowFrom() now takes a set of properties that describe the native window and options. + The SDL_WINDOWPOS_UNDEFINED_DISPLAY() and SDL_WINDOWPOS_CENTERED_DISPLAY() macros take a display ID instead of display index. The display ID 0 has a special meaning in this case, and is used to indicate the primary display. The SDL_WINDOW_SHOWN flag has been removed. Windows are shown by default and can be created hidden by using the SDL_WINDOW_HIDDEN flag. diff --git a/include/SDL3/SDL_hints.h b/include/SDL3/SDL_hints.h index 91d7f0670c..bac7e50866 100644 --- a/include/SDL3/SDL_hints.h +++ b/include/SDL3/SDL_hints.h @@ -1801,47 +1801,6 @@ extern "C" { */ #define SDL_HINT_VIDEO_WAYLAND_EMULATE_MOUSE_WARP "SDL_VIDEO_WAYLAND_EMULATE_MOUSE_WARP" -/** -* A variable that is the address of another SDL_Window* (as a hex string formatted with "%p"). -* -* If this hint is set before SDL_CreateWindowFrom() and the SDL_Window* it is set to has -* SDL_WINDOW_OPENGL set (and running on WGL only, currently), then two things will occur on the newly -* created SDL_Window: -* -* 1. Its pixel format will be set to the same pixel format as this SDL_Window. This is -* needed for example when sharing an OpenGL context across multiple windows. -* -* 2. The flag SDL_WINDOW_OPENGL will be set on the new window so it can be used for -* OpenGL rendering. -* -* This variable can be set to the following values: -* The address (as a string "%p") of the SDL_Window* that new windows created with SDL_CreateWindowFrom() should -* share a pixel format with. -*/ -#define SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT "SDL_VIDEO_WINDOW_SHARE_PIXEL_FORMAT" - -/** - * When calling SDL_CreateWindowFrom(), make the window compatible with OpenGL. - * - * This variable can be set to the following values: - * "0" - Don't add any graphics flags to the SDL_WindowFlags - * "1" - Add SDL_WINDOW_OPENGL to the SDL_WindowFlags - * - * By default SDL will not make the foreign window compatible with OpenGL. - */ -#define SDL_HINT_VIDEO_FOREIGN_WINDOW_OPENGL "SDL_VIDEO_FOREIGN_WINDOW_OPENGL" - -/** - * When calling SDL_CreateWindowFrom(), make the window compatible with Vulkan. - * - * This variable can be set to the following values: - * "0" - Don't add any graphics flags to the SDL_WindowFlags - * "1" - Add SDL_WINDOW_VULKAN to the SDL_WindowFlags - * - * By default SDL will not make the foreign window compatible with Vulkan. - */ -#define SDL_HINT_VIDEO_FOREIGN_WINDOW_VULKAN "SDL_VIDEO_FOREIGN_WINDOW_VULKAN" - /** * A variable specifying which shader compiler to preload when using the Chrome ANGLE binaries * diff --git a/include/SDL3/SDL_video.h b/include/SDL3/SDL_video.h index e8db562df8..262409f9e7 100644 --- a/include/SDL3/SDL_video.h +++ b/include/SDL3/SDL_video.h @@ -868,14 +868,34 @@ extern DECLSPEC SDL_Window *SDLCALL SDL_CreateWindowWithPosition(const char *tit extern DECLSPEC SDL_Window *SDLCALL SDL_CreatePopupWindow(SDL_Window *parent, int offset_x, int offset_y, int w, int h, Uint32 flags); /** - * Create an SDL window from an existing native window. + * Create an SDL window from properties representing an existing native window. * - * In some cases (e.g. OpenGL) and on some platforms (e.g. Microsoft Windows) - * the hint `SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT` needs to be configured - * before using SDL_CreateWindowFrom(). + * These are the supported properties: * - * \param data a pointer to driver-dependent window creation data, typically - * your native window cast to a void* + * On macOS: + * ``` + * "cocoa.window" (pointer) - the (__unsafe_unretained) NSWindow associated with the window + * "cocoa.view" (pointer) - optional, the (__unsafe_unretained) NSView associated with the window, defaults to [window contentView] + * ``` + * + * On Windows: + * ``` + * "win32.hwnd" (pointer) - the HWND associated with the window + * "win32.pixel_format_hwnd" (pointer) - optional, another window to share pixel format with, useful for OpenGL windows + * ``` + * + * On X11: + * ``` + * "x11.window" (number) - the X11 Window associated with the window + * ``` + * + * On all platforms: + * ``` + * "opengl" (boolean) - optional, true if the window will be used with OpenGL rendering + * "vulkan" (boolean) - optional, true if the window will be used with Vulkan rendering + * ``` + * + * \param props a set of properties describing the native window and options * \returns the window that was created or NULL on failure; call * SDL_GetError() for more information. * @@ -884,7 +904,7 @@ extern DECLSPEC SDL_Window *SDLCALL SDL_CreatePopupWindow(SDL_Window *parent, in * \sa SDL_CreateWindow * \sa SDL_DestroyWindow */ -extern DECLSPEC SDL_Window *SDLCALL SDL_CreateWindowFrom(const void *data); +extern DECLSPEC SDL_Window *SDLCALL SDL_CreateWindowFrom(SDL_PropertiesID props); /** * Get the numeric ID of a window. diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h index 90be91d078..309249d97f 100644 --- a/src/dynapi/SDL_dynapi_procs.h +++ b/src/dynapi/SDL_dynapi_procs.h @@ -157,7 +157,7 @@ SDL_DYNAPI_PROC(SDL_Texture*,SDL_CreateTexture,(SDL_Renderer *a, Uint32 b, int c SDL_DYNAPI_PROC(SDL_Texture*,SDL_CreateTextureFromSurface,(SDL_Renderer *a, SDL_Surface *b),(a,b),return) SDL_DYNAPI_PROC(SDL_Window*,SDL_CreateWindow,(const char *a, int b, int c, Uint32 d),(a,b,c,d),return) SDL_DYNAPI_PROC(int,SDL_CreateWindowAndRenderer,(int a, int b, Uint32 c, SDL_Window **d, SDL_Renderer **e),(a,b,c,d,e),return) -SDL_DYNAPI_PROC(SDL_Window*,SDL_CreateWindowFrom,(const void *a),(a),return) +SDL_DYNAPI_PROC(SDL_Window*,SDL_CreateWindowFrom,(SDL_PropertiesID a),(a),return) SDL_DYNAPI_PROC(SDL_Window*,SDL_CreateWindowWithPosition,(const char *a, int b, int c, int d, int e, Uint32 f),(a,b,c,d,e,f),return) SDL_DYNAPI_PROC(SDL_bool,SDL_CursorVisible,(void),(),return) SDL_DYNAPI_PROC(void,SDL_DelEventWatch,(SDL_EventFilter a, void *b),(a,b),) diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h index fe3e5fd52a..cc9597f663 100644 --- a/src/video/SDL_sysvideo.h +++ b/src/video/SDL_sysvideo.h @@ -223,7 +223,7 @@ struct SDL_VideoDevice * Window functions */ int (*CreateSDLWindow)(SDL_VideoDevice *_this, SDL_Window *window); - int (*CreateSDLWindowFrom)(SDL_VideoDevice *_this, SDL_Window *window, const void *data); + int (*CreateSDLWindowFrom)(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props); void (*SetWindowTitle)(SDL_VideoDevice *_this, SDL_Window *window); int (*SetWindowIcon)(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *icon); int (*SetWindowPosition)(SDL_VideoDevice *_this, SDL_Window *window); diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 16010b810e..712b21e095 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -2092,11 +2092,15 @@ SDL_Window *SDL_CreatePopupWindow(SDL_Window *parent, int offset_x, int offset_y return SDL_CreateWindowInternal(NULL, offset_x, offset_y, w, h, parent, flags); } -SDL_Window *SDL_CreateWindowFrom(const void *data) +SDL_Window *SDL_CreateWindowFrom(SDL_PropertiesID props) { SDL_Window *window; Uint32 flags = SDL_WINDOW_FOREIGN; + if (!props) { + SDL_InvalidParamError("props"); + return NULL; + } if (!_this) { SDL_UninitializedVideo(); return NULL; @@ -2106,7 +2110,7 @@ SDL_Window *SDL_CreateWindowFrom(const void *data) return NULL; } - if (SDL_GetHintBoolean(SDL_HINT_VIDEO_FOREIGN_WINDOW_OPENGL, SDL_FALSE)) { + if (SDL_GetBooleanProperty(props, "opengl", SDL_FALSE)) { if (!_this->GL_CreateContext) { SDL_ContextNotSupported("OpenGL"); return NULL; @@ -2117,7 +2121,7 @@ SDL_Window *SDL_CreateWindowFrom(const void *data) flags |= SDL_WINDOW_OPENGL; } - if (SDL_GetHintBoolean(SDL_HINT_VIDEO_FOREIGN_WINDOW_VULKAN, SDL_FALSE)) { + if (SDL_GetBooleanProperty(props, "vulkan", SDL_FALSE)) { if (!_this->Vulkan_CreateSurface) { SDL_ContextNotSupported("Vulkan"); return NULL; @@ -2149,7 +2153,7 @@ SDL_Window *SDL_CreateWindowFrom(const void *data) } _this->windows = window; - if (_this->CreateSDLWindowFrom(_this, window, data) < 0) { + if (_this->CreateSDLWindowFrom(_this, window, props) < 0) { SDL_DestroyWindow(window); return NULL; } diff --git a/src/video/cocoa/SDL_cocoawindow.h b/src/video/cocoa/SDL_cocoawindow.h index 8e4158cf67..e03adb3504 100644 --- a/src/video/cocoa/SDL_cocoawindow.h +++ b/src/video/cocoa/SDL_cocoawindow.h @@ -142,8 +142,7 @@ typedef enum @end extern int Cocoa_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window); -extern int Cocoa_CreateWindowFrom(SDL_VideoDevice *_this, SDL_Window *window, - const void *data); +extern int Cocoa_CreateWindowFrom(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props); extern void Cocoa_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window); extern int Cocoa_SetWindowIcon(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *icon); extern int Cocoa_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window); diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m index afbfb4352d..ee99090591 100644 --- a/src/video/cocoa/SDL_cocoawindow.m +++ b/src/video/cocoa/SDL_cocoawindow.m @@ -2007,22 +2007,35 @@ int Cocoa_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window) } } -int Cocoa_CreateWindowFrom(SDL_VideoDevice *_this, SDL_Window *window, const void *data) +int Cocoa_CreateWindowFrom(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props) { @autoreleasepool { - NSView *nsview = nil; + const void *data = SDL_GetProperty(props, "data", NULL); NSWindow *nswindow = nil; + NSView *nsview = nil; NSString *title; BOOL highdpi; - if ([(__bridge id)data isKindOfClass:[NSWindow class]]) { - nswindow = (__bridge NSWindow *)data; - nsview = [nswindow contentView]; - } else if ([(__bridge id)data isKindOfClass:[NSView class]]) { - nsview = (__bridge NSView *)data; - nswindow = [nsview window]; + if (data) { + if ([(__bridge id)data isKindOfClass:[NSWindow class]]) { + nswindow = (__bridge NSWindow *)data; + } else if ([(__bridge id)data isKindOfClass:[NSView class]]) { + nsview = (__bridge NSView *)data; + } else { + SDL_assert(false); + } } else { - SDL_assert(false); + nswindow = (__bridge NSWindow *)SDL_GetProperty(props, "cocoa.window", NULL); + nsview = (__bridge NSView *)SDL_GetProperty(props, "cocoa.view", NULL); + } + if (nswindow && !nsview) { + nsview = [nswindow contentView]; + } + if (nsview && !nswindow) { + nswindow = [nsview window]; + } + if (!nswindow) { + return SDL_SetError("Couldn't find property cocoa.window"); } /* Query the title from the existing window */ diff --git a/src/video/haiku/SDL_bvideo.cc b/src/video/haiku/SDL_bvideo.cc index b97ee5a01c..21d1b864cb 100644 --- a/src/video/haiku/SDL_bvideo.cc +++ b/src/video/haiku/SDL_bvideo.cc @@ -75,7 +75,6 @@ static SDL_VideoDevice * HAIKU_CreateDevice(void) device->PumpEvents = HAIKU_PumpEvents; device->CreateSDLWindow = HAIKU_CreateWindow; - device->CreateSDLWindowFrom = HAIKU_CreateWindowFrom; device->SetWindowTitle = HAIKU_SetWindowTitle; device->SetWindowPosition = HAIKU_SetWindowPosition; device->SetWindowSize = HAIKU_SetWindowSize; diff --git a/src/video/haiku/SDL_bwindow.cc b/src/video/haiku/SDL_bwindow.cc index bb99a0fb99..15c1d32fa2 100644 --- a/src/video/haiku/SDL_bwindow.cc +++ b/src/video/haiku/SDL_bwindow.cc @@ -86,39 +86,6 @@ int HAIKU_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window) { return 0; } -int HAIKU_CreateWindowFrom(SDL_VideoDevice *_this, SDL_Window * window, const void *data) { - - SDL_BWin *otherBWin = (SDL_BWin*)data; - if (!otherBWin->LockLooper()) { - return -1; - } - - /* Create the new window and initialize its members */ - window->x = (int)otherBWin->Frame().left; - window->y = (int)otherBWin->Frame().top; - window->w = (int)otherBWin->Frame().Width(); - window->h = (int)otherBWin->Frame().Height(); - - /* Set SDL flags */ - if (!(otherBWin->Flags() & B_NOT_RESIZABLE)) { - window->flags |= SDL_WINDOW_RESIZABLE; - } - - /* If we are out of memory, return the error code */ - if (_InitWindow(_this, window) < 0) { - return -1; - } - - /* TODO: Add any other SDL-supported window attributes here */ - _ToBeWin(window)->SetTitle(otherBWin->Title()); - - /* Start window loop and unlock the other window */ - _ToBeWin(window)->Show(); - - otherBWin->UnlockLooper(); - return 0; -} - void HAIKU_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window * window) { BMessage msg(BWIN_SET_TITLE); msg.AddString("window-title", window->title); diff --git a/src/video/haiku/SDL_bwindow.h b/src/video/haiku/SDL_bwindow.h index 400fa9467a..b49ab92764 100644 --- a/src/video/haiku/SDL_bwindow.h +++ b/src/video/haiku/SDL_bwindow.h @@ -25,7 +25,6 @@ #include "../SDL_sysvideo.h" extern int HAIKU_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window); -extern int HAIKU_CreateWindowFrom(SDL_VideoDevice *_this, SDL_Window *window, const void *data); extern void HAIKU_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window); extern int HAIKU_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window); extern void HAIKU_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window); diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.c b/src/video/kmsdrm/SDL_kmsdrmvideo.c index ca283c1fe8..07598ab26c 100644 --- a/src/video/kmsdrm/SDL_kmsdrmvideo.c +++ b/src/video/kmsdrm/SDL_kmsdrmvideo.c @@ -281,7 +281,6 @@ static SDL_VideoDevice *KMSDRM_CreateDevice(void) device->GetDisplayModes = KMSDRM_GetDisplayModes; device->SetDisplayMode = KMSDRM_SetDisplayMode; device->CreateSDLWindow = KMSDRM_CreateWindow; - device->CreateSDLWindowFrom = KMSDRM_CreateWindowFrom; device->SetWindowTitle = KMSDRM_SetWindowTitle; device->SetWindowPosition = KMSDRM_SetWindowPosition; device->SetWindowSize = KMSDRM_SetWindowSize; @@ -1584,11 +1583,6 @@ int KMSDRM_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window) return ret; } -int KMSDRM_CreateWindowFrom(SDL_VideoDevice *_this, SDL_Window *window, const void *data) -{ - return -1; -} - void KMSDRM_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window) { } diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.h b/src/video/kmsdrm/SDL_kmsdrmvideo.h index d488fc84ae..9807cf4b39 100644 --- a/src/video/kmsdrm/SDL_kmsdrmvideo.h +++ b/src/video/kmsdrm/SDL_kmsdrmvideo.h @@ -122,7 +122,6 @@ void KMSDRM_VideoQuit(SDL_VideoDevice *_this); int KMSDRM_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display); int KMSDRM_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode); int KMSDRM_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window); -int KMSDRM_CreateWindowFrom(SDL_VideoDevice *_this, SDL_Window *window, const void *data); void KMSDRM_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window); int KMSDRM_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window); void KMSDRM_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window); diff --git a/src/video/psp/SDL_pspvideo.c b/src/video/psp/SDL_pspvideo.c index 637d9c1385..5a2091e3b8 100644 --- a/src/video/psp/SDL_pspvideo.c +++ b/src/video/psp/SDL_pspvideo.c @@ -89,7 +89,6 @@ static SDL_VideoDevice *PSP_Create() device->GetDisplayModes = PSP_GetDisplayModes; device->SetDisplayMode = PSP_SetDisplayMode; device->CreateSDLWindow = PSP_CreateWindow; - device->CreateSDLWindowFrom = PSP_CreateWindowFrom; device->SetWindowTitle = PSP_SetWindowTitle; device->SetWindowPosition = PSP_SetWindowPosition; device->SetWindowSize = PSP_SetWindowSize; @@ -205,11 +204,6 @@ int PSP_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window) return 0; } -int PSP_CreateWindowFrom(SDL_VideoDevice *_this, SDL_Window *window, const void *data) -{ - return SDL_Unsupported(); -} - void PSP_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window) { } diff --git a/src/video/psp/SDL_pspvideo.h b/src/video/psp/SDL_pspvideo.h index 429ad98d63..6a680d9eb5 100644 --- a/src/video/psp/SDL_pspvideo.h +++ b/src/video/psp/SDL_pspvideo.h @@ -50,7 +50,6 @@ void PSP_VideoQuit(SDL_VideoDevice *_this); int PSP_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display); int PSP_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode); int PSP_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window); -int PSP_CreateWindowFrom(SDL_VideoDevice *_this, SDL_Window *window, const void *data); void PSP_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window); int PSP_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window); void PSP_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window); diff --git a/src/video/raspberry/SDL_rpivideo.c b/src/video/raspberry/SDL_rpivideo.c index e48bc1e68f..e167265346 100644 --- a/src/video/raspberry/SDL_rpivideo.c +++ b/src/video/raspberry/SDL_rpivideo.c @@ -101,7 +101,6 @@ static SDL_VideoDevice *RPI_Create() device->VideoInit = RPI_VideoInit; device->VideoQuit = RPI_VideoQuit; device->CreateSDLWindow = RPI_CreateWindow; - device->CreateSDLWindowFrom = RPI_CreateWindowFrom; device->SetWindowTitle = RPI_SetWindowTitle; device->SetWindowPosition = RPI_SetWindowPosition; device->SetWindowSize = RPI_SetWindowSize; @@ -339,11 +338,6 @@ void RPI_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window) } } -int RPI_CreateWindowFrom(SDL_VideoDevice *_this, SDL_Window *window, const void *data) -{ - return -1; -} - void RPI_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window) { } diff --git a/src/video/raspberry/SDL_rpivideo.h b/src/video/raspberry/SDL_rpivideo.h index b620d5d130..f1d72b7ce0 100644 --- a/src/video/raspberry/SDL_rpivideo.h +++ b/src/video/raspberry/SDL_rpivideo.h @@ -64,7 +64,6 @@ void RPI_VideoQuit(SDL_VideoDevice *_this); int RPI_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display); int RPI_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode); int RPI_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window); -int RPI_CreateWindowFrom(SDL_VideoDevice *_this, SDL_Window *window, const void *data); void RPI_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window); int RPI_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window); void RPI_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window); diff --git a/src/video/vita/SDL_vitavideo.c b/src/video/vita/SDL_vitavideo.c index f3fd1f94bc..884c95fe33 100644 --- a/src/video/vita/SDL_vitavideo.c +++ b/src/video/vita/SDL_vitavideo.c @@ -105,7 +105,6 @@ static SDL_VideoDevice *VITA_Create() device->VideoInit = VITA_VideoInit; device->VideoQuit = VITA_VideoQuit; device->CreateSDLWindow = VITA_CreateWindow; - device->CreateSDLWindowFrom = VITA_CreateWindowFrom; device->SetWindowTitle = VITA_SetWindowTitle; device->SetWindowPosition = VITA_SetWindowPosition; device->SetWindowSize = VITA_SetWindowSize; @@ -293,11 +292,6 @@ int VITA_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window) return 0; } -int VITA_CreateWindowFrom(SDL_VideoDevice *_this, SDL_Window *window, const void *data) -{ - return -1; -} - void VITA_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window) { } diff --git a/src/video/vita/SDL_vitavideo.h b/src/video/vita/SDL_vitavideo.h index aa4be1ba9e..a4cf79dafb 100644 --- a/src/video/vita/SDL_vitavideo.h +++ b/src/video/vita/SDL_vitavideo.h @@ -63,7 +63,6 @@ void VITA_VideoQuit(SDL_VideoDevice *_this); int VITA_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display); int VITA_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode); int VITA_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window); -int VITA_CreateWindowFrom(SDL_VideoDevice *_this, SDL_Window *window, const void *data); void VITA_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window); int VITA_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window); void VITA_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window); diff --git a/src/video/windows/SDL_windowsopengl.c b/src/video/windows/SDL_windowsopengl.c index 41103805e4..3b6c879e4e 100644 --- a/src/video/windows/SDL_windowsopengl.c +++ b/src/video/windows/SDL_windowsopengl.c @@ -893,21 +893,6 @@ int WIN_GL_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context) return 0; } -SDL_bool WIN_GL_SetPixelFormatFrom(SDL_VideoDevice *_this, SDL_Window *fromWindow, SDL_Window *toWindow) -{ - HDC hfromdc = fromWindow->driverdata->hdc; - HDC htodc = toWindow->driverdata->hdc; - - /* get the pixel format of the fromWindow */ - int pixel_format = GetPixelFormat(hfromdc); - PIXELFORMATDESCRIPTOR pfd; - SDL_memset(&pfd, 0, sizeof(pfd)); - DescribePixelFormat(hfromdc, pixel_format, sizeof(pfd), &pfd); - - /* set the pixel format of the toWindow */ - return SetPixelFormat(htodc, pixel_format, &pfd); -} - #endif /* SDL_VIDEO_OPENGL_WGL */ #endif /* SDL_VIDEO_DRIVER_WINDOWS */ diff --git a/src/video/windows/SDL_windowsopengl.h b/src/video/windows/SDL_windowsopengl.h index dc1d140de3..4597d8ee3a 100644 --- a/src/video/windows/SDL_windowsopengl.h +++ b/src/video/windows/SDL_windowsopengl.h @@ -115,7 +115,6 @@ extern int WIN_GL_GetSwapInterval(SDL_VideoDevice *_this, int *interval); extern int WIN_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); extern int WIN_GL_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context); extern void WIN_GL_InitExtensions(SDL_VideoDevice *_this); -extern SDL_bool WIN_GL_SetPixelFormatFrom(SDL_VideoDevice *_this, SDL_Window *fromWindow, SDL_Window *toWindow); #ifndef WGL_ARB_pixel_format #define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000 diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c index ebcabd24ea..66b5701498 100644 --- a/src/video/windows/SDL_windowswindow.c +++ b/src/video/windows/SDL_windowswindow.c @@ -644,16 +644,20 @@ int WIN_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window) return 0; } -int WIN_CreateWindowFrom(SDL_VideoDevice *_this, SDL_Window *window, const void *data) +int WIN_CreateWindowFrom(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props) { #if defined(__XBOXONE__) || defined(__XBOXSERIES__) return -1; #else - HWND hwnd = (HWND)data; + HWND hwnd = (HWND)SDL_GetProperty(props, "win32.hwnd", SDL_GetProperty(props, "data", NULL)); LPTSTR title; int titleLen; SDL_bool isstack; + if (!hwnd) { + return SDL_SetError("Couldn't find property win32.hwnd"); + } + /* Query the title from the existing window */ titleLen = GetWindowTextLength(hwnd); title = SDL_small_alloc(TCHAR, titleLen + 1, &isstack); @@ -675,23 +679,18 @@ int WIN_CreateWindowFrom(SDL_VideoDevice *_this, SDL_Window *window, const void #ifdef SDL_VIDEO_OPENGL_WGL { - const char *hint = SDL_GetHint(SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT); - if (hint) { - /* This hint is a pointer (in string form) of the address of - the window to share a pixel format with - */ - SDL_Window *otherWindow = NULL; - (void)SDL_sscanf(hint, "%p", (void **)&otherWindow); + HWND share_hwnd = (HWND)SDL_GetProperty(props, "win32.pixel_format_hwnd", NULL); + if (share_hwnd) { + HDC hdc = GetDC(share_hwnd); + int pixel_format = GetPixelFormat(hdc); + PIXELFORMATDESCRIPTOR pfd; - /* Do some error checking on the pointer */ - if (otherWindow && otherWindow->magic == &_this->window_magic) { - /* If the otherWindow has SDL_WINDOW_OPENGL set, set it for the new window as well */ - if (otherWindow->flags & SDL_WINDOW_OPENGL) { - window->flags |= SDL_WINDOW_OPENGL; - if (!WIN_GL_SetPixelFormatFrom(_this, otherWindow, window)) { - return -1; - } - } + SDL_zero(pfd); + DescribePixelFormat(hdc, pixel_format, sizeof(pfd), &pfd); + ReleaseDC(share_hwnd, hdc); + + if (!SetPixelFormat(window->driverdata->hdc, pixel_format, &pfd)) { + return WIN_SetError("SetPixelFormat()"); } } else if (window->flags & SDL_WINDOW_OPENGL) { /* Try to set up the pixel format, if it hasn't been set by the application */ diff --git a/src/video/windows/SDL_windowswindow.h b/src/video/windows/SDL_windowswindow.h index 5b2c0260c0..a3e0c84561 100644 --- a/src/video/windows/SDL_windowswindow.h +++ b/src/video/windows/SDL_windowswindow.h @@ -76,7 +76,7 @@ struct SDL_WindowData }; extern int WIN_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window); -extern int WIN_CreateWindowFrom(SDL_VideoDevice *_this, SDL_Window *window, const void *data); +extern int WIN_CreateWindowFrom(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props); extern void WIN_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window); extern int WIN_SetWindowIcon(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *icon); extern int WIN_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window); diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c index 0997fc7532..f8c7d5d8ba 100644 --- a/src/video/x11/SDL_x11window.c +++ b/src/video/x11/SDL_x11window.c @@ -777,9 +777,12 @@ int X11_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window) return 0; } -int X11_CreateWindowFrom(SDL_VideoDevice *_this, SDL_Window *window, const void *data) +int X11_CreateWindowFrom(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props) { - Window w = (Window)data; + Window w = (Window)SDL_GetNumberProperty(props, "x11.window", (Window)SDL_GetProperty(props, "data", NULL)); + if (!w) { + return SDL_SetError("Couldn't find property x11.window"); + } window->title = X11_GetWindowTitle(_this, w); diff --git a/src/video/x11/SDL_x11window.h b/src/video/x11/SDL_x11window.h index 03b8b8cdee..65afecc30d 100644 --- a/src/video/x11/SDL_x11window.h +++ b/src/video/x11/SDL_x11window.h @@ -85,7 +85,7 @@ extern void X11_SetNetWMState(SDL_VideoDevice *_this, Window xwindow, Uint32 fla extern Uint32 X11_GetNetWMState(SDL_VideoDevice *_this, SDL_Window *window, Window xwindow); extern int X11_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window); -extern int X11_CreateWindowFrom(SDL_VideoDevice *_this, SDL_Window *window, const void *data); +extern int X11_CreateWindowFrom(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props); extern char *X11_GetWindowTitle(SDL_VideoDevice *_this, Window xwindow); extern void X11_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window); extern int X11_SetWindowIcon(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *icon); diff --git a/test/testautomation_hints.c b/test/testautomation_hints.c index 0a5ec42583..0e22b70747 100644 --- a/test/testautomation_hints.c +++ b/test/testautomation_hints.c @@ -24,7 +24,6 @@ static const char *HintsEnum[] = { SDL_HINT_VIDEO_ALLOW_SCREENSAVER, SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES, SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, - SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT, SDL_HINT_VIDEO_WIN_D3DCOMPILER, SDL_HINT_VIDEO_X11_XRANDR, SDL_HINT_XINPUT_ENABLED, @@ -47,7 +46,6 @@ static const char *HintsVerbose[] = { "SDL_VIDEO_ALLOW_SCREENSAVER", "SDL_VIDEO_MAC_FULLSCREEN_SPACES", "SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS", - "SDL_VIDEO_WINDOW_SHARE_PIXEL_FORMAT", "SDL_VIDEO_WIN_D3DCOMPILER", "SDL_VIDEO_X11_XRANDR", "SDL_XINPUT_ENABLED" diff --git a/test/testnative.c b/test/testnative.c index cc5b1b071a..212a6f7a18 100644 --- a/test/testnative.c +++ b/test/testnative.c @@ -100,6 +100,7 @@ int main(int argc, char *argv[]) { int i, done; const char *driver; + SDL_PropertiesID props; SDL_Window *window; SDL_Renderer *renderer; SDL_Texture *sprite; @@ -146,7 +147,10 @@ int main(int argc, char *argv[]) SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create native window\n"); quit(3); } - window = SDL_CreateWindowFrom(native_window); + props = SDL_CreateProperties(); + SDL_SetProperty(props, "data", native_window); + window = SDL_CreateWindowFrom(props); + SDL_DestroyProperties(props); if (!window) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create SDL window: %s\n", SDL_GetError()); quit(4);