SDL_CreateWindowFrom() now takes a set of properties that describe the native window and options.

main
Sam Lantinga 2023-11-12 21:37:00 -08:00
parent 6afae6681b
commit 1c4723ac66
27 changed files with 94 additions and 169 deletions

View File

@ -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.

View File

@ -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
*

View File

@ -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.

View File

@ -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),)

View File

@ -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);

View File

@ -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;
}

View File

@ -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);

View File

@ -2007,23 +2007,36 @@ 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 (data) {
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];
} else {
SDL_assert(false);
}
} else {
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 */
title = [nswindow title];

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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)
{
}

View File

@ -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);

View File

@ -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)
{
}

View File

@ -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);

View File

@ -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)
{
}

View File

@ -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);

View File

@ -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)
{
}

View File

@ -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);

View File

@ -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 */

View File

@ -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

View File

@ -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 */

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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"

View File

@ -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);