1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-14 13:30:48 +03:00

0032308: Configuration - make Xlib dependency optional

MACOSX_USE_GLX has been renamed to HAVE_XLIB and now configurable on Linux target.

Xw_Window.hxx now export class on non-Linux platforms.
OpenGl_Window now creates an off-screen EGL surface also in case of
window-less desktop setup (e.g. with disabled Xlib on Linux).

Draw_Window - code has been cleaned up.
Class definition has been unified across platforms when possible.
Unusued constructors have been removed.
Internal header files (MainWindow.h, init.h, etc.) have been renamed to .pxx
to avoid their unexpected distribution in "inc".
This commit is contained in:
kgv
2021-04-16 16:12:16 +03:00
committed by bugmaster
parent e8e157df45
commit b69e576af0
48 changed files with 2288 additions and 3044 deletions

View File

@@ -16,6 +16,12 @@
#include <Aspect_DisplayConnectionDefinitionError.hxx>
#include <OSD_Environment.hxx>
#if defined(HAVE_XLIB)
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#endif
IMPLEMENT_STANDARD_RTTIEXT(Aspect_DisplayConnection,Standard_Transient)
// =======================================================================
@@ -24,7 +30,7 @@ IMPLEMENT_STANDARD_RTTIEXT(Aspect_DisplayConnection,Standard_Transient)
// =======================================================================
Aspect_DisplayConnection::Aspect_DisplayConnection()
{
#if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && !defined(__ANDROID__) && !defined(__QNX__) && !defined(__EMSCRIPTEN__)
#if defined(HAVE_XLIB)
myDisplay = NULL;
myDefVisualInfo = NULL;
myDefFBConfig = NULL;
@@ -41,7 +47,7 @@ Aspect_DisplayConnection::Aspect_DisplayConnection()
// =======================================================================
Aspect_DisplayConnection::~Aspect_DisplayConnection()
{
#if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && !defined(__ANDROID__) && !defined(__QNX__) && !defined(__EMSCRIPTEN__)
#if defined(HAVE_XLIB)
if (myDefVisualInfo != NULL)
{
XFree (myDefVisualInfo);
@@ -49,12 +55,11 @@ Aspect_DisplayConnection::~Aspect_DisplayConnection()
if (myDisplay != NULL
&& myIsOwnDisplay)
{
XCloseDisplay (myDisplay);
XCloseDisplay ((Display* )myDisplay);
}
#endif
}
#if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && !defined(__ANDROID__) && !defined(__QNX__) && !defined(__EMSCRIPTEN__)
// =======================================================================
// function : Aspect_DisplayConnection
// purpose :
@@ -73,7 +78,7 @@ Aspect_DisplayConnection::Aspect_DisplayConnection (const TCollection_AsciiStrin
// function : Aspect_DisplayConnection
// purpose :
// =======================================================================
Aspect_DisplayConnection::Aspect_DisplayConnection (Display* theDisplay)
Aspect_DisplayConnection::Aspect_DisplayConnection (Aspect_XDisplay* theDisplay)
: myDisplay (NULL),
myDefVisualInfo (NULL),
myDefFBConfig (NULL),
@@ -86,12 +91,14 @@ Aspect_DisplayConnection::Aspect_DisplayConnection (Display* theDisplay)
// function : SetDefaultVisualInfo
// purpose :
// =======================================================================
void Aspect_DisplayConnection::SetDefaultVisualInfo (XVisualInfo* theVisual,
void Aspect_DisplayConnection::SetDefaultVisualInfo (Aspect_XVisualInfo* theVisual,
Aspect_FBConfig theFBConfig)
{
if (myDefVisualInfo != NULL)
{
#if defined(HAVE_XLIB)
XFree (myDefVisualInfo);
#endif
}
myDefVisualInfo = theVisual;
myDefFBConfig = theFBConfig;
@@ -101,17 +108,18 @@ void Aspect_DisplayConnection::SetDefaultVisualInfo (XVisualInfo* theVisual,
// function : Init
// purpose :
// =======================================================================
void Aspect_DisplayConnection::Init (Display* theDisplay)
void Aspect_DisplayConnection::Init (Aspect_XDisplay* theDisplay)
{
#if defined(HAVE_XLIB)
if (myDisplay != NULL
&& myIsOwnDisplay)
{
XCloseDisplay (myDisplay);
XCloseDisplay ((Display* )myDisplay);
}
myIsOwnDisplay = false;
myAtoms.Clear();
myDisplay = theDisplay != NULL ? theDisplay : XOpenDisplay (myDisplayName.ToCString());
myDisplay = theDisplay != NULL ? theDisplay : (Aspect_XDisplay* )XOpenDisplay (myDisplayName.ToCString());
if (myDisplay == NULL)
{
TCollection_AsciiString aMessage;
@@ -122,18 +130,10 @@ void Aspect_DisplayConnection::Init (Display* theDisplay)
else
{
myIsOwnDisplay = theDisplay == NULL;
myAtoms.Bind (Aspect_XA_DELETE_WINDOW, XInternAtom(myDisplay, "WM_DELETE_WINDOW", False));
myAtoms.Bind (Aspect_XA_DELETE_WINDOW, (uint64_t )XInternAtom((Display* )myDisplay, "WM_DELETE_WINDOW", False));
}
}
// =======================================================================
// function : GetAtom
// purpose :
// =======================================================================
Atom Aspect_DisplayConnection::GetAtom (const Aspect_XAtom theAtom) const
{
Atom anAtom = myAtoms.Find(theAtom);
return anAtom;
}
#else
myDisplay = theDisplay;
myIsOwnDisplay = theDisplay == NULL;
#endif
}

View File

@@ -16,51 +16,52 @@
#include <Standard_Transient.hxx>
#include <Aspect_XAtom.hxx>
#include <Aspect_FBConfig.hxx>
#include <TCollection_AsciiString.hxx>
#include <NCollection_DataMap.hxx>
#if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && !defined(__ANDROID__) && !defined(__QNX__) && !defined(__EMSCRIPTEN__)
#include <InterfaceGraphic.hxx>
#include <Aspect_FBConfig.hxx>
#endif
struct Aspect_XDisplay;
struct Aspect_XVisualInfo;
//! This class creates and provides connection with X server.
//! Raises exception if can not connect to X server.
//! On Windows and Mac OS X (in case when Cocoa used) platforms this class do nothing.
//! WARRNING: Do not close display connection manualy!
//! On Windows and Mac OS X (in case when Cocoa used) platforms this class does nothing.
//! WARRNING: Do not close display connection manually!
class Aspect_DisplayConnection : public Standard_Transient
{
DEFINE_STANDARD_RTTIEXT(Aspect_DisplayConnection, Standard_Transient)
public:
//! Default constructor. Creates connection with display name taken from "DISPLAY" environment variable
Standard_EXPORT Aspect_DisplayConnection();
//! Destructor. Close opened connection.
Standard_EXPORT ~Aspect_DisplayConnection();
Standard_EXPORT virtual ~Aspect_DisplayConnection();
#if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && !defined(__ANDROID__) && !defined(__QNX__) && !defined(__EMSCRIPTEN__)
//! Constructor. Creates connection with display specified in theDisplayName.
//! Display name should be in format "hostname:number" or "hostname:number.screen_number", where:
//! hostname - Specifies the name of the host machine on which the display is physically attached.
//! number - Specifies the number of the display server on that host machine.
//! screen_number - Specifies the screen to be used on that server. Optional variable.
Aspect_DisplayConnection (const TCollection_AsciiString& theDisplayName);
Standard_EXPORT Aspect_DisplayConnection (const TCollection_AsciiString& theDisplayName);
//! Constructor wrapping existing Display instance.
//! WARNING! it is a responsibility of application to keep this pointer
//! valid while Aspect_DisplayConnection is alive and to close Display when it is no more needed.
Aspect_DisplayConnection (Display* theDisplay);
Standard_EXPORT Aspect_DisplayConnection (Aspect_XDisplay* theDisplay);
//! @return pointer to Display structure that serves as the connection to the X server.
Display* GetDisplay() { return myDisplay; }
Aspect_XDisplay* GetDisplayAspect() { return myDisplay; }
//! @return TRUE if X Display has been allocated by this class
Standard_Boolean IsOwnDisplay() const { return myIsOwnDisplay; }
//! @return identifier(atom) for custom named property associated with windows that use current connection to X server.
Atom GetAtom (const Aspect_XAtom theAtom) const;
uint64_t GetAtom (const Aspect_XAtom theAtom) const
{
return myAtoms.Find (theAtom);
}
//! @return display name for this connection.
const TCollection_AsciiString& GetDisplayName() { return myDisplayName; }
@@ -71,27 +72,60 @@ public:
//! to keep this pointer valid while Aspect_DisplayConnection is alive
//! and to close Display when it is no more needed.
//! @param theDisplay external pointer to allocated Display, or NULL if new connection should be created
void Init (Display* theDisplay);
Standard_EXPORT void Init (Aspect_XDisplay* theDisplay);
//! Return default window visual or NULL when undefined.
XVisualInfo* GetDefaultVisualInfo() const { return myDefVisualInfo; }
Aspect_XVisualInfo* GetDefaultVisualInfo() const { return myDefVisualInfo; }
//! @return native Window FB config (GLXFBConfig on Xlib)
Aspect_FBConfig GetDefaultFBConfig() const { return myDefFBConfig; }
//! Set default window visual; the visual will be deallocated using XFree().
Standard_EXPORT void SetDefaultVisualInfo (XVisualInfo* theVisual,
Standard_EXPORT void SetDefaultVisualInfo (Aspect_XVisualInfo* theVisual,
Aspect_FBConfig theFBConfig);
#ifdef X_PROTOCOL
//! Constructor wrapping existing Display instance.
//! WARNING! it is a responsibility of application to keep this pointer
//! valid while Aspect_DisplayConnection is alive and to close Display when it is no more needed.
Aspect_DisplayConnection (Display* theDisplay)
: Aspect_DisplayConnection ((Aspect_XDisplay* )theDisplay) {}
//! @return pointer to Display structure that serves as the connection to the X server.
Display* GetDisplay() { return (Display* )myDisplay; }
//! Return default window visual or NULL when undefined.
XVisualInfo* GetDefaultVisualInfoX() const { return (XVisualInfo* )myDefVisualInfo; }
//! Set default window visual; the visual will be deallocated using XFree().
void SetDefaultVisualInfo (XVisualInfo* theVisual,
Aspect_FBConfig theFBConfig)
{
SetDefaultVisualInfo ((Aspect_XVisualInfo* )theVisual, theFBConfig);
}
//! @return identifier(atom) for custom named property associated with windows that use current connection to X server.
Atom GetAtomX (const Aspect_XAtom theAtom) const
{
return (Atom )GetAtom (theAtom);
}
//! Open connection with display specified in myDisplayName class field
//! or takes theDisplay parameter when it is not NULL.
void Init (Display* theDisplay)
{
Init ((Aspect_XDisplay* )theDisplay);
}
#endif
private:
Display* myDisplay;
XVisualInfo* myDefVisualInfo;
Aspect_XDisplay* myDisplay;
Aspect_XVisualInfo* myDefVisualInfo;
Aspect_FBConfig myDefFBConfig;
NCollection_DataMap<Aspect_XAtom, Atom> myAtoms;
NCollection_DataMap<Aspect_XAtom, uint64_t> myAtoms;
TCollection_AsciiString myDisplayName;
Standard_Boolean myIsOwnDisplay;
#endif
private:
@@ -99,10 +133,6 @@ private:
Aspect_DisplayConnection (const Aspect_DisplayConnection& );
Aspect_DisplayConnection& operator= (const Aspect_DisplayConnection& );
public:
DEFINE_STANDARD_RTTIEXT(Aspect_DisplayConnection,Standard_Transient) // Type definition
};
DEFINE_STANDARD_HANDLE (Aspect_DisplayConnection, Standard_Transient)

View File

@@ -14,11 +14,7 @@
#ifndef _Aspect_FBConfig_HeaderFile
#define _Aspect_FBConfig_HeaderFile
#if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && !defined(__ANDROID__) && !defined(__QNX__) && !defined(__EMSCRIPTEN__)
typedef struct __GLXFBConfigRec* GLXFBConfig;
typedef GLXFBConfig Aspect_FBConfig; // GLXFBConfig* under UNIX
#else
typedef void* Aspect_FBConfig; // unused on other systems
#endif
typedef struct __GLXFBConfigRec* GLXFBConfig;
typedef GLXFBConfig Aspect_FBConfig;
#endif // _Aspect_FBConfig_HeaderFile

View File

@@ -22,7 +22,7 @@
#ifndef _Aspect_RenderingContext_HeaderFile
#define _Aspect_RenderingContext_HeaderFile
#if defined(__APPLE__) && !defined(MACOSX_USE_GLX)
#if defined(__APPLE__) && !defined(HAVE_XLIB)
#import <TargetConditionals.h>
#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
#ifdef __OBJC__

View File

@@ -14,7 +14,7 @@
#ifndef __Aspect_WNTXWD_HXX
# define __Aspect_WNTXWD_HXX
#if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && !defined(__ANDROID__) && !defined(__QNX__) && !defined(__EMSCRIPTEN__)
#if !defined(_WIN32) && (!defined(__APPLE__) || defined(HAVE_XLIB)) && !defined(__ANDROID__) && !defined(__QNX__) && !defined(__EMSCRIPTEN__)
# include <X11/XWDFile.h>
# else