summaryrefslogtreecommitdiff
path: root/indra/llwindow/llwindowsdl.cpp
diff options
context:
space:
mode:
authorJonathan "Geenz" Goodman <geenz@lindenlab.com>2025-11-04 07:58:01 -0500
committerGitHub <noreply@github.com>2025-11-04 07:58:01 -0500
commit92c08effbc68233f2b1025215ad5422497d43c68 (patch)
tree35cf80b6f631d707410ca4f413ced113551af10e /indra/llwindow/llwindowsdl.cpp
parent02f8d44c9c9cf7c1996d509c527a13f143b120c0 (diff)
parentaf600606e67ea90e634827a6356caabc2ef37ccc (diff)
Merge pull request #4915 from RyeMutt/rye/linux64-2
Linux64 Part 2
Diffstat (limited to 'indra/llwindow/llwindowsdl.cpp')
-rw-r--r--indra/llwindow/llwindowsdl.cpp146
1 files changed, 125 insertions, 21 deletions
diff --git a/indra/llwindow/llwindowsdl.cpp b/indra/llwindow/llwindowsdl.cpp
index 57110f8634..3fc0257a7f 100644
--- a/indra/llwindow/llwindowsdl.cpp
+++ b/indra/llwindow/llwindowsdl.cpp
@@ -40,11 +40,11 @@
#include "llpreeditor.h"
#include "llsdl.h"
+#if LL_LINUX
#ifdef LL_GLIB
#include <glib.h>
#endif
-#if LL_LINUX
extern "C" {
# include "fontconfig/fontconfig.h"
}
@@ -55,6 +55,13 @@ extern "C" {
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
+
+#if LL_X11
+LLWindowSDL::X11_DATA LLWindowSDL::sX11Data = {};
+#endif
+#if LL_WAYLAND
+LLWindowSDL::WAYLAND_DATA LLWindowSDL::sWaylandData = {};
+#endif
#endif // LL_LINUX
#if LL_DARWIN
@@ -224,31 +231,28 @@ bool LLWindowSDL::createContext(int x, int y, int width, int height, int bits, b
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, stencilBits);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+ SDL_GLContextFlag context_flags{};
if(LLRender::sGLCoreProfile)
{
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
#if LL_DARWIN
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
+ context_flags |= SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG;
#endif
-
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
}
- SDL_GLContextFlag context_flags{};
if (gDebugGL)
{
context_flags |= SDL_GL_CONTEXT_DEBUG_FLAG;
}
-#if LL_DARWIN
- context_flags |= SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG;
-#endif
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, context_flags);
SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);
if(mFullscreen)
{
- tryFindFullscreenSize( width, height );
+ tryFindFullscreenSize(width, height);
}
SDL_PropertiesID props = SDL_CreateProperties();
@@ -268,6 +272,7 @@ bool LLWindowSDL::createContext(int x, int y, int width, int height, int bits, b
{
LL_WARNS() << "Window creation failure. SDL: " << SDL_GetError() << LL_ENDL;
setupFailure("Window creation error", "Error", OSMB_OK);
+ SDL_DestroyProperties(props);
return false;
}
SDL_DestroyProperties(props); // Free properties once window is created
@@ -322,6 +327,52 @@ bool LLWindowSDL::createContext(int x, int y, int width, int height, int bits, b
mRefreshRate = DEFAULT_REFRESH_RATE;
}
+ /* Grab the window manager specific information */
+#if LL_LINUX
+ if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "x11") == 0)
+ {
+ LL_INFOS() << "Running under X11" << LL_ENDL;
+ mServerProtocol = X11;
+
+ gGLManager.mIsX11 = true;
+
+#if LL_X11
+ sX11Data.xdisplay = (Display *)SDL_GetPointerProperty(SDL_GetWindowProperties(mWindow), SDL_PROP_WINDOW_X11_DISPLAY_POINTER, nullptr);
+ sX11Data.xwindow = (Window)SDL_GetNumberProperty(SDL_GetWindowProperties(mWindow), SDL_PROP_WINDOW_X11_WINDOW_NUMBER, 0);
+ sX11Data.xscreen = (int)SDL_GetNumberProperty(SDL_GetWindowProperties(mWindow), SDL_PROP_WINDOW_X11_SCREEN_NUMBER, -1);
+ if (sX11Data.xdisplay && sX11Data.xwindow)
+ {
+
+ }
+#endif
+
+ gGLManager.initGLX();
+ }
+ else if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "wayland") == 0)
+ {
+ LL_INFOS() << "Running under Wayland" << LL_ENDL;
+ mServerProtocol = Wayland;
+
+ gGLManager.mIsWayland = true;
+
+#if LL_WAYLAND
+ sWaylandData.display = (struct wl_display *)SDL_GetPointerProperty(SDL_GetWindowProperties(mWindow), SDL_PROP_WINDOW_WAYLAND_DISPLAY_POINTER, nullptr);
+ sWaylandData.surface = (struct wl_surface *)SDL_GetPointerProperty(SDL_GetWindowProperties(mWindow), SDL_PROP_WINDOW_WAYLAND_SURFACE_POINTER, nullptr);
+ if (sWaylandData.display && sWaylandData.surface)
+ {
+ }
+#endif
+
+ gGLManager.initEGL();
+
+ // If set (XWayland) remove DISPLAY, this will prompt dullahan to also use Wayland
+ if(getenv("DISPLAY"))
+ {
+ unsetenv("DISPLAY");
+ }
+ }
+#endif
+
SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &redBits);
SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &greenBits);
SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &blueBits);
@@ -378,29 +429,65 @@ bool LLWindowSDL::createContext(int x, int y, int width, int height, int bits, b
void* LLWindowSDL::createSharedContext()
{
- SDL_GLContext pContext = SDL_GL_CreateContext(mWindow);
- if (pContext)
+ SDL_PropertiesID props = SDL_CreateProperties();
+ SDL_SetStringProperty(props, SDL_PROP_WINDOW_CREATE_TITLE_STRING, "Second Life OSR Utility");
+ SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_WIDTH_NUMBER, 1);
+ SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_HEIGHT_NUMBER, 1);
+ SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_RESIZABLE_BOOLEAN, false);
+ SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_OPENGL_BOOLEAN, true);
+ SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_HIDDEN_BOOLEAN, true);
+ SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_FOCUSABLE_BOOLEAN, false);
+ SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_UTILITY_BOOLEAN, true);
+ SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_HIGH_PIXEL_DENSITY_BOOLEAN, gHiDPISupport);
+
+ auto osr_window = SDL_CreateWindowWithProperties(props);
+ if (osr_window == nullptr)
+ {
+ SDL_DestroyProperties(props);
+ return nullptr;
+ }
+ SDL_DestroyProperties(props); // Free properties once window is created
+ SDL_GLContext pContext = SDL_GL_CreateContext(osr_window);
+
+ // Hack to ensure main window context is bound
+ SDL_GL_MakeCurrent(mWindow, mContext);
+
+ if (!pContext)
+ {
+ LL_WARNS() << "Creating shared OpenGL context failed!" << LL_ENDL;
+ SDL_DestroyWindow(osr_window);
+ return nullptr;
+ }
+
{
- // HACK to ensure windows GL context is set correctly when threaded - Rye
- SDL_GL_MakeCurrent(mWindow, pContext);
- SDL_GL_MakeCurrent(mWindow, mContext);
- LL_DEBUGS() << "Creating shared OpenGL context successful!" << LL_ENDL;
- return (void*)pContext;
+ LLMutexLock osr_lock(&mOSRMutex);
+ mOSRContexts.emplace(pContext, osr_window);
}
- LL_WARNS() << "Creating shared OpenGL context failed!" << LL_ENDL;
- return nullptr;
+ LL_DEBUGS() << "Creating shared OpenGL context successful!" << LL_ENDL;
+ return (void*)pContext;
}
void LLWindowSDL::makeContextCurrent(void* contextPtr)
{
- SDL_GL_MakeCurrent(mWindow, (SDL_GLContext)contextPtr);
+ LLMutexLock osr_lock(&mOSRMutex);
+ auto it = mOSRContexts.find((SDL_GLContext)contextPtr);
+ if(it != mOSRContexts.end())
+ {
+ SDL_GL_MakeCurrent((SDL_Window*)it->second, (SDL_GLContext)it->first);
+ }
LL_PROFILER_GPU_CONTEXT;
}
void LLWindowSDL::destroySharedContext(void* contextPtr)
{
- SDL_GL_DestroyContext((SDL_GLContext)contextPtr);
+ LLMutexLock osr_lock(&mOSRMutex);
+ auto it = mOSRContexts.find((SDL_GLContext)contextPtr);
+ if(it != mOSRContexts.end())
+ {
+ SDL_GL_DestroyContext((SDL_GLContext)it->first);
+ mDeadOSRWindows.push_back((SDL_Window*)it->second);
+ }
}
void LLWindowSDL::toggleVSync(bool enable_vsync)
@@ -449,6 +536,15 @@ void LLWindowSDL::destroyContext()
{
LL_INFOS() << "destroyContext begins" << LL_ENDL;
+ {
+ LLMutexLock osr_lock(&mOSRMutex);
+ for(SDL_Window* pWindow : mDeadOSRWindows)
+ {
+ SDL_DestroyWindow(pWindow);
+ }
+ mDeadOSRWindows.clear();
+ }
+
// Stop unicode input
SDL_StopTextInput(mWindow);
@@ -1114,6 +1210,14 @@ U32 LLWindowSDL::SDLCheckGrabbyKeys(U32 keysym, bool gain)
// virtual
void LLWindowSDL::processMiscNativeEvents()
{
+ {
+ LLMutexLock osr_lock(&mOSRMutex);
+ for(SDL_Window* pWindow : mDeadOSRWindows)
+ {
+ SDL_DestroyWindow(pWindow);
+ }
+ mDeadOSRWindows.clear();
+ }
}
void LLWindowSDL::gatherInput()