Skip to content

Commit 8b7245c

Browse files
author
Rye
committed
Further cleanup of SDL windowing backend and isolation of Wayland and X specific code in #if
1 parent a0cf26e commit 8b7245c

File tree

3 files changed

+47
-137
lines changed

3 files changed

+47
-137
lines changed

indra/cmake/UI.cmake

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@ include(Prebuilt)
33
include(FreeType)
44
include(GLIB)
55

6+
include_guard()
67
add_library( ll::uilibraries INTERFACE IMPORTED )
78

89
if (LINUX)
9-
target_compile_definitions(ll::uilibraries INTERFACE LL_X11=1 )
10-
1110
if( USE_CONAN )
1211
return()
1312
endif()
1413

15-
include(FindPkgConfig)
14+
find_package(PkgConfig REQUIRED)
1615
pkg_check_modules(WAYLAND_CLIENT wayland-client)
1716

1817
if( WAYLAND_CLIENT_FOUND )
@@ -22,13 +21,6 @@ if (LINUX)
2221
endif()
2322

2423
target_link_libraries( ll::uilibraries INTERFACE
25-
Xrender
26-
Xcursor
27-
Xfixes
28-
Xext
29-
Xft
30-
Xinerama
31-
X11
3224
ll::fontconfig
3325
ll::freetype
3426
ll::SDL2

indra/llwindow/llwindowsdl.cpp

Lines changed: 43 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -64,41 +64,12 @@ const S32 MAX_NUM_RESOLUTIONS = 200;
6464
// LLWindowSDL
6565
//
6666

67-
#include <X11/Xutil.h>
68-
6967
// TOFU HACK -- (*exactly* the same hack as LLWindowMacOSX for a similar
7068
// set of reasons): Stash a pointer to the LLWindowSDL object here and
7169
// maintain in the constructor and destructor. This assumes that there will
7270
// be only one object of this class at any time. Currently this is true.
7371
static LLWindowSDL *gWindowImplementation = nullptr;
7472

75-
void maybe_lock_display(void)
76-
{
77-
if (gWindowImplementation && gWindowImplementation->Lock_Display)
78-
gWindowImplementation->Lock_Display();
79-
}
80-
81-
void maybe_unlock_display(void)
82-
{
83-
if (gWindowImplementation && gWindowImplementation->Unlock_Display)
84-
gWindowImplementation->Unlock_Display();
85-
}
86-
87-
88-
Window LLWindowSDL::get_SDL_XWindowID(void)
89-
{
90-
if (gWindowImplementation)
91-
return gWindowImplementation->mX11Data.mXWindowID;
92-
return None;
93-
}
94-
95-
Display* LLWindowSDL::get_SDL_Display(void)
96-
{
97-
if (gWindowImplementation)
98-
return gWindowImplementation->mX11Data.mDisplay;
99-
return nullptr;
100-
}
101-
10273
/*
10374
* In wayland a window does not have a state of "minimized" or gets messages that it got minimized [1]
10475
* There's two ways to approach this challenge:
@@ -238,8 +209,7 @@ LLWindowSDL::LLWindowSDL(LLWindowCallbacks* callbacks,
238209
bool enable_vsync, bool use_gl,
239210
bool ignore_pixel_depth, U32 fsaa_samples)
240211
: LLWindow(callbacks, fullscreen, flags),
241-
Lock_Display(nullptr),
242-
Unlock_Display(nullptr), mGamma(1.0f)
212+
mGamma(1.0f)
243213
{
244214
// Initialize the keyboard
245215
gKeyboard = new LLKeyboardSDL();
@@ -377,6 +347,14 @@ bool LLWindowSDL::createContext(int x, int y, int width, int height, int bits, b
377347

378348
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
379349

350+
if(LLRender::sGLCoreProfile)
351+
{
352+
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
353+
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
354+
355+
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
356+
}
357+
380358
U32 context_flags = 0;
381359
if (gDebugGL)
382360
{
@@ -416,36 +394,18 @@ bool LLWindowSDL::createContext(int x, int y, int width, int height, int bits, b
416394
setupFailure("GL Context failed to set current failure", "Error", OSMB_OK);
417395
}
418396

419-
mSurface = SDL_GetWindowSurface(mWindow);
420397
if(mFullscreen)
421398
{
422-
if (mSurface)
423-
{
424-
mFullscreen = true;
425-
mFullscreenWidth = mSurface->w;
426-
mFullscreenHeight = mSurface->h;
427-
mFullscreenBits = mSurface->format->BitsPerPixel;
428-
mFullscreenRefresh = -1;
429-
430-
LL_INFOS() << "Running at " << mFullscreenWidth
431-
<< "x" << mFullscreenHeight
432-
<< "x" << mFullscreenBits
433-
<< " @ " << mFullscreenRefresh
434-
<< LL_ENDL;
435-
}
436-
else
437-
{
438-
LL_WARNS() << "createContext: fullscreen creation failure. SDL: " << SDL_GetError() << LL_ENDL;
439-
440-
mFullscreen = false;
441-
mFullscreenWidth = -1;
442-
mFullscreenHeight = -1;
443-
mFullscreenBits = -1;
444-
mFullscreenRefresh = -1;
399+
mFullscreen = true;
400+
SDL_GetWindowSize(mWindow, &mFullscreenWidth, &mFullscreenHeight);
401+
mFullscreenBits = 32;
402+
mFullscreenRefresh = -1;
445403

446-
std::string error = llformat("Unable to run fullscreen at %d x %d.\nRunning in window.", width, height);
447-
setupFailure( error, "Error", OSMB_OK );
448-
}
404+
LL_INFOS() << "Running at " << mFullscreenWidth
405+
<< "x" << mFullscreenHeight
406+
<< "x" << mFullscreenBits
407+
<< " @ " << mFullscreenRefresh
408+
<< LL_ENDL;
449409
}
450410

451411
SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &redBits);
@@ -499,25 +459,23 @@ bool LLWindowSDL::createContext(int x, int y, int width, int height, int bits, b
499459
/* Save the information for later use */
500460
if (info.subsystem == SDL_SYSWM_X11)
501461
{
502-
mX11Data.mDisplay = info.info.x11.display;
503-
mX11Data.mXWindowID = info.info.x11.window;
504462
mServerProtocol = X11;
505463
LL_INFOS() << "Running under X11" << LL_ENDL;
506464
}
507465
else if (info.subsystem == SDL_SYSWM_WAYLAND)
508466
{
467+
mServerProtocol = Wayland;
468+
509469
#ifdef LL_WAYLAND
470+
mWaylandData.mSurface = info.info.wl.surface;
510471
mWaylandLoaded = loadWaylandClient();
511472
if(!mWaylandLoaded)
512473
{
513474
LL_WARNS() << "Failed to load wayland-client.so or grab required functions" << LL_ENDL;
514475
}
515-
#endif
516-
517-
mWaylandData.mSurface = info.info.wl.surface;
518-
mServerProtocol = Wayland;
519476

520477
setupWaylandFrameCallback();
478+
#endif
521479

522480
// If set (XWayland) remove DISPLAY, this will prompt dullahan to also use Wayland
523481
if( getenv("DISPLAY") )
@@ -537,8 +495,6 @@ bool LLWindowSDL::createContext(int x, int y, int width, int height, int bits, b
537495
}
538496

539497
SDL_StartTextInput();
540-
//make sure multisampling is disabled by default
541-
glDisable(GL_MULTISAMPLE_ARB);
542498

543499
// Don't need to get the current gamma, since there's a call that restores it to the system defaults.
544500
return true;
@@ -620,10 +576,9 @@ void LLWindowSDL::destroyContext()
620576
LL_INFOS() << "shutdownGL begins" << LL_ENDL;
621577
gGLManager.shutdownGL();
622578

623-
mX11Data.mDisplay = nullptr;
624-
mX11Data.mXWindowID = None;
625-
Lock_Display = nullptr;
626-
Unlock_Display = nullptr;
579+
#ifdef LL_WAYLAND
580+
mWaylandData.mSurface = nullptr;
581+
#endif
627582
mServerProtocol = Unknown;
628583

629584
LL_INFOS() << "Destroying SDL cursors" << LL_ENDL;
@@ -651,9 +606,6 @@ void LLWindowSDL::destroyContext()
651606
LL_INFOS() << "SDL Window already destroyed" << LL_ENDL;
652607
}
653608
LL_INFOS() << "destroyContext end" << LL_ENDL;
654-
655-
LL_INFOS() << "SDL_QuitSS/VID begins" << LL_ENDL;
656-
SDL_QuitSubSystem(SDL_INIT_VIDEO); // *FIX: this might be risky...
657609
}
658610

659611
LLWindowSDL::~LLWindowSDL()
@@ -730,8 +682,10 @@ bool LLWindowSDL::getVisible() const
730682

731683
bool LLWindowSDL::getMinimized() const
732684
{
685+
#if LL_WAYLAND
733686
if( isWaylandWindowNotDrawing() )
734687
return true;
688+
#endif
735689

736690
bool result = false;
737691
if (mWindow)
@@ -782,10 +736,9 @@ bool LLWindowSDL::getPosition(LLCoordScreen *position) const
782736

783737
bool LLWindowSDL::getSize(LLCoordScreen *size) const
784738
{
785-
if (mSurface)
739+
if (mWindow)
786740
{
787-
size->mX = mSurface->w;
788-
size->mY = mSurface->h;
741+
SDL_GetWindowSize(mWindow, &size->mX, &size->mY);
789742
return true;
790743
}
791744

@@ -794,10 +747,9 @@ bool LLWindowSDL::getSize(LLCoordScreen *size) const
794747

795748
bool LLWindowSDL::getSize(LLCoordWindow *size) const
796749
{
797-
if (mSurface)
750+
if (mWindow)
798751
{
799-
size->mX = mSurface->w;
800-
size->mY = mSurface->h;
752+
SDL_GetWindowSize(mWindow, &size->mX, &size->mY);
801753
return true;
802754
}
803755

@@ -1001,25 +953,12 @@ void LLWindowSDL::beforeDialog()
1001953
if (mFullscreen && mWindow )
1002954
SDL_SetWindowFullscreen( mWindow, 0 );
1003955
}
1004-
1005-
if (mServerProtocol == X11 && mX11Data.mDisplay)
1006-
{
1007-
// Everything that we/SDL asked for should happen before we
1008-
// potentially hand control over to GTK.
1009-
maybe_lock_display();
1010-
XSync(mX11Data.mDisplay, False);
1011-
maybe_unlock_display();
1012-
}
1013-
1014-
maybe_lock_display();
1015956
}
1016957

1017958
void LLWindowSDL::afterDialog()
1018959
{
1019960
LL_INFOS() << "LLWindowSDL::afterDialog()" << LL_ENDL;
1020961

1021-
maybe_unlock_display();
1022-
1023962
if (mFullscreen && mWindow )
1024963
SDL_SetWindowFullscreen( mWindow, 0 );
1025964
}
@@ -1106,7 +1045,6 @@ LLWindow::LLWindowResolution* LLWindowSDL::getSupportedResolutions(S32 &num_reso
11061045
mSupportedResolutions = new LLWindowResolution[MAX_NUM_RESOLUTIONS];
11071046
mNumSupportedResolutions = 0;
11081047

1109-
// <FS:ND> Use display no from mWindow/mSurface here?
11101048
int max = SDL_GetNumDisplayModes(0);
11111049
max = llclamp( max, 0, MAX_NUM_RESOLUTIONS );
11121050

@@ -1142,8 +1080,13 @@ bool LLWindowSDL::convertCoords(LLCoordGL from, LLCoordWindow *to) const
11421080
if (!to)
11431081
return false;
11441082

1083+
if (!mWindow)
1084+
return false;
1085+
S32 height;
1086+
SDL_GetWindowSize(mWindow, nullptr, &height);
1087+
11451088
to->mX = from.mX;
1146-
to->mY = mSurface->h - from.mY - 1;
1089+
to->mY = height - from.mY - 1;
11471090

11481091
return true;
11491092
}
@@ -1153,8 +1096,13 @@ bool LLWindowSDL::convertCoords(LLCoordWindow from, LLCoordGL* to) const
11531096
if (!to)
11541097
return false;
11551098

1099+
if (!mWindow)
1100+
return false;
1101+
S32 height;
1102+
SDL_GetWindowSize(mWindow, nullptr, &height);
1103+
11561104
to->mX = from.mX;
1157-
to->mY = mSurface->h - from.mY - 1;
1105+
to->mY = height - from.mY - 1;
11581106

11591107
return true;
11601108
}
@@ -1520,7 +1468,6 @@ void LLWindowSDL::gatherInput(bool app_has_focus)
15201468
S32 width = llmax(event.window.data1, (S32)mMinWindowWidth);
15211469
S32 height = llmax(event.window.data2, (S32)mMinWindowHeight);
15221470

1523-
mSurface = SDL_GetWindowSurface(mWindow);
15241471
mCallbacks->handleResize(this, width, height);
15251472
break;
15261473
}

0 commit comments

Comments
 (0)