Added osg::GraphicsContext::WindowingSystemInterfaces singleton for managing multiple WIndowinSystemInterface
implementations being registered at the same time. One usage case for this functionality to support usage of Wayland and X11 in the same version of the osgViewer. As part of the new functionality there is now a osg::GraphicsContext::Traits::windowingSystemPreferrence string that default to empty, but if defined will ensure that a specific WindowingSystemInterface is utilized when you do a generic call like osg::createGraphicsContext(). Also implemented is standard proxy object for registering the new contexts and removing them automatically, and declaration of standard graphicswindow_name() C entry point to help with static build linking.
This commit is contained in:
@@ -34,42 +34,95 @@
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <stdio.h>
|
||||
|
||||
using namespace osg;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// WindowSystemInterfaces
|
||||
//
|
||||
GraphicsContext::WindowingSystemInterfaces::WindowingSystemInterfaces()
|
||||
{
|
||||
}
|
||||
|
||||
GraphicsContext::WindowingSystemInterfaces::~WindowingSystemInterfaces()
|
||||
{
|
||||
}
|
||||
|
||||
void GraphicsContext::WindowingSystemInterfaces::addWindowingSystemInterface(GraphicsContext::WindowingSystemInterface* wsi)
|
||||
{
|
||||
if (std::find(_interfaces.begin(), _interfaces.end(), wsi)==_interfaces.end())
|
||||
{
|
||||
OSG_NOTICE<<"GraphicsContext::WindowingSystemInterfaces::addWindowingSystemInterface("<<wsi<<") Name="<<wsi->getName()<<std::endl;
|
||||
_interfaces.push_back(wsi);
|
||||
}
|
||||
}
|
||||
|
||||
void GraphicsContext::WindowingSystemInterfaces::removeWindowingSystemInterface(GraphicsContext::WindowingSystemInterface* wsi)
|
||||
{
|
||||
printf("GraphicsContext::WindowingSystemInterfaces::removeWindowingSystemInterface()\n");
|
||||
Interfaces::iterator itr = std::find(_interfaces.begin(), _interfaces.end(), wsi);
|
||||
if (itr!=_interfaces.end())
|
||||
{
|
||||
printf(" succeded GraphicsContext::WindowingSystemInterfaces::removeWindowingSystemInterface()\n");
|
||||
_interfaces.erase(itr);
|
||||
}
|
||||
}
|
||||
|
||||
GraphicsContext::WindowingSystemInterface* GraphicsContext::WindowingSystemInterfaces::getWindowingSystemInterface(const std::string& name)
|
||||
{
|
||||
if (_interfaces.empty())
|
||||
{
|
||||
OSG_WARN<<"Warning: GraphicsContext::WindowingSystemInterfaces::getWindowingSystemInterface() failed, no interfaces available."<<std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!name.empty())
|
||||
{
|
||||
for(Interfaces::iterator itr = _interfaces.begin();
|
||||
itr != _interfaces.end();
|
||||
++itr)
|
||||
{
|
||||
if ((*itr)->getName()==name)
|
||||
{
|
||||
return itr->get();
|
||||
}
|
||||
|
||||
OSG_NOTICE<<" tried interface "<<typeid(*itr).name()<<", name= "<<(*itr)->getName()<<std::endl;
|
||||
}
|
||||
|
||||
OSG_WARN<<"Warning: GraphicsContext::WindowingSystemInterfaces::getWindowingSystemInterface() failed, no interfaces matches name : "<<name<<std::endl;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// no preference provided so just take the first available interface
|
||||
return _interfaces.front().get();
|
||||
}
|
||||
}
|
||||
|
||||
// Use a static reference pointer to hold the window system interface.
|
||||
// Wrap this within a function, in order to control the order in which
|
||||
// the static pointer's constructor is executed.
|
||||
|
||||
static ref_ptr<GraphicsContext::WindowingSystemInterface> &windowingSystemInterfaceRef()
|
||||
osg::ref_ptr<GraphicsContext::WindowingSystemInterfaces>& GraphicsContext::getWindowingSystemInterfaces()
|
||||
{
|
||||
static ref_ptr<GraphicsContext::WindowingSystemInterface> s_WindowingSystemInterface;
|
||||
static ref_ptr<GraphicsContext::WindowingSystemInterfaces> s_WindowingSystemInterface = new GraphicsContext::WindowingSystemInterfaces;
|
||||
return s_WindowingSystemInterface;
|
||||
}
|
||||
|
||||
OSG_INIT_SINGLETON_PROXY(ProxyInitWindowingSystemInterfaces, GraphicsContext::getWindowingSystemInterfaces())
|
||||
|
||||
|
||||
// GraphicsContext static method implementations
|
||||
|
||||
void GraphicsContext::setWindowingSystemInterface(WindowingSystemInterface* callback)
|
||||
GraphicsContext::WindowingSystemInterface* GraphicsContext::getWindowingSystemInterface(const std::string& name)
|
||||
{
|
||||
ref_ptr<GraphicsContext::WindowingSystemInterface> &wsref = windowingSystemInterfaceRef();
|
||||
wsref = callback;
|
||||
OSG_INFO<<"GraphicsContext::setWindowingSystemInterface() "<<wsref.get()<<"\t"<<&wsref<<std::endl;
|
||||
}
|
||||
|
||||
GraphicsContext::WindowingSystemInterface* GraphicsContext::getWindowingSystemInterface()
|
||||
{
|
||||
ref_ptr<GraphicsContext::WindowingSystemInterface> &wsref = windowingSystemInterfaceRef();
|
||||
OSG_INFO<<"GraphicsContext::getWindowingSystemInterface() "<<wsref.get()<<"\t"<<&wsref<<std::endl;
|
||||
return wsref.get();
|
||||
return GraphicsContext::getWindowingSystemInterfaces()->getWindowingSystemInterface(name);
|
||||
}
|
||||
|
||||
GraphicsContext* GraphicsContext::createGraphicsContext(Traits* traits)
|
||||
{
|
||||
ref_ptr<GraphicsContext::WindowingSystemInterface> &wsref = windowingSystemInterfaceRef();
|
||||
ref_ptr<GraphicsContext::WindowingSystemInterface> wsref = getWindowingSystemInterface(traits ? traits->windowingSystemPreference : "") ;
|
||||
if ( wsref.valid())
|
||||
{
|
||||
// catch any undefined values.
|
||||
|
||||
@@ -125,7 +125,7 @@ public:
|
||||
osg::observer_ptr< osgViewer::ViewerBase > _viewer;
|
||||
|
||||
virtual ~HeartBeat();
|
||||
|
||||
|
||||
void init( osgViewer::ViewerBase *viewer );
|
||||
void stopTimer();
|
||||
void timerEvent( QTimerEvent *event );
|
||||
@@ -869,7 +869,6 @@ void GraphicsWindowQt::requestWarpPointer( float x, float y )
|
||||
QCursor::setPos( _widget->mapToGlobal(QPoint((int)x,(int)y)) );
|
||||
}
|
||||
|
||||
|
||||
class QtWindowingSystem : public osg::GraphicsContext::WindowingSystemInterface
|
||||
{
|
||||
public:
|
||||
@@ -945,6 +944,9 @@ private:
|
||||
QtWindowingSystem& operator=( const QtWindowingSystem& );
|
||||
};
|
||||
|
||||
#if 1
|
||||
REGISTER_WINDOWINGSYSTEMINTERFACE(Qt, QtWindowingSystem)
|
||||
#else
|
||||
|
||||
// declare C entry point for static compilation.
|
||||
extern "C" void OSGQT_EXPORT graphicswindow_Qt(void)
|
||||
@@ -957,7 +959,7 @@ void osgQt::initQtWindowingSystem()
|
||||
{
|
||||
graphicswindow_Qt();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
void osgQt::setViewer( osgViewer::ViewerBase *viewer )
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
||||
|
||||
#ifndef DARWIN_UTILS_HEADER_
|
||||
#define DARWIN_UTILS_HEADER_
|
||||
|
||||
@@ -31,37 +31,37 @@ namespace osgDarwin {
|
||||
|
||||
|
||||
/** the MenubarController class checks all open windows if they intersect with the menubar / dock and hide the menubar/dock if necessary */
|
||||
class MenubarController : public osg::Referenced
|
||||
class MenubarController : public osg::Referenced
|
||||
{
|
||||
|
||||
public:
|
||||
class WindowAdapter : public osg::Referenced {
|
||||
|
||||
|
||||
public:
|
||||
WindowAdapter() : osg::Referenced() {}
|
||||
|
||||
|
||||
virtual bool valid() = 0;
|
||||
virtual void getWindowBounds(CGRect& rect) = 0;
|
||||
virtual osgViewer::GraphicsWindow* getWindow() = 0;
|
||||
|
||||
|
||||
protected:
|
||||
virtual ~WindowAdapter() {}
|
||||
};
|
||||
|
||||
MenubarController();
|
||||
|
||||
|
||||
MenubarController();
|
||||
|
||||
static MenubarController* instance();
|
||||
|
||||
|
||||
void attachWindow(WindowAdapter* win);
|
||||
void update();
|
||||
void detachWindow(osgViewer::GraphicsWindow* win);
|
||||
|
||||
|
||||
void setDisplaySettings(osg::DisplaySettings* display_settings);
|
||||
|
||||
|
||||
protected:
|
||||
~MenubarController();
|
||||
|
||||
private:
|
||||
|
||||
private:
|
||||
typedef std::list< osg::ref_ptr< WindowAdapter > > WindowList;
|
||||
WindowList _list;
|
||||
bool _menubarShown;
|
||||
@@ -69,7 +69,7 @@ class MenubarController : public osg::Referenced
|
||||
CGRect _mainScreenBounds;
|
||||
OpenThreads::Mutex _mutex;
|
||||
MenubarToggler* _toggler;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -91,25 +91,25 @@ struct DarwinWindowingSystemInterface : public osg::GraphicsContext::WindowingSy
|
||||
virtual void getScreenSettings(const osg::GraphicsContext::ScreenIdentifier& si, osg::GraphicsContext::ScreenSettings & resolution);
|
||||
|
||||
virtual void enumerateScreenSettings(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, osg::GraphicsContext::ScreenSettingsList & resolutionList);
|
||||
|
||||
|
||||
virtual bool setScreenSettings (const osg::GraphicsContext::ScreenIdentifier & si, const osg::GraphicsContext::ScreenSettings & settings);
|
||||
|
||||
/** return the top left coord of a specific screen in global screen space */
|
||||
void getScreenTopLeft(const osg::GraphicsContext::ScreenIdentifier& si, int& x, int& y);
|
||||
|
||||
|
||||
|
||||
|
||||
/** returns screen-ndx containing rect x,y,w,h */
|
||||
unsigned int getScreenContaining(int x, int y, int w, int h);
|
||||
|
||||
|
||||
virtual void setDisplaySettings(osg::DisplaySettings* display_settings) {
|
||||
MenubarController::instance()->setDisplaySettings(display_settings);
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
virtual void _init();
|
||||
|
||||
|
||||
template<class PixelBufferImplementation, class GraphicsWindowImplementation>
|
||||
osg::GraphicsContext* createGraphicsContextImplementation(osg::GraphicsContext::Traits* traits)
|
||||
{
|
||||
@@ -136,6 +136,7 @@ struct DarwinWindowingSystemInterface : public osg::GraphicsContext::WindowingSy
|
||||
|
||||
};
|
||||
|
||||
#if 0
|
||||
template <class WSI>
|
||||
struct RegisterWindowingSystemInterfaceProxy
|
||||
{
|
||||
@@ -155,7 +156,7 @@ struct RegisterWindowingSystemInterfaceProxy
|
||||
osg::GraphicsContext::setWindowingSystemInterface(0);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1100,15 +1100,19 @@ public:
|
||||
|
||||
}
|
||||
|
||||
#if 1
|
||||
REGISTER_WINDOWINGSYSTEMINTERFACE(Carbon, osgViewer::CarbonWindowingSystemInterface)
|
||||
#else
|
||||
|
||||
#ifdef USE_DARWIN_CARBON_IMPLEMENTATION
|
||||
RegisterWindowingSystemInterfaceProxy<CarbonWindowingSystemInterface> createWindowingSystemInterfaceProxy;
|
||||
#endif
|
||||
|
||||
|
||||
// declare C entry point for static compilation.
|
||||
extern "C" void graphicswindow_Carbon(void)
|
||||
{
|
||||
osg::GraphicsContext::setWindowingSystemInterface(new osgViewer::CarbonWindowingSystemInterface());
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1829,6 +1829,9 @@ private:
|
||||
|
||||
}
|
||||
|
||||
#if 1
|
||||
REGISTER_WINDOWINGSYSTEMINTERFACE(Cocoa, osgViewer::CocoaWindowingSystemInterface)
|
||||
#else
|
||||
#ifdef USE_DARWIN_COCOA_IMPLEMENTATION
|
||||
RegisterWindowingSystemInterfaceProxy<osgViewer::CocoaWindowingSystemInterface> createWindowingSystemInterfaceProxy;
|
||||
#endif
|
||||
@@ -1838,3 +1841,4 @@ extern "C" void graphicswindow_Cocoa(void)
|
||||
{
|
||||
osg::GraphicsContext::setWindowingSystemInterface(new osgViewer::CocoaWindowingSystemInterface());
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1226,7 +1226,9 @@ public:
|
||||
|
||||
}//end namspace
|
||||
|
||||
|
||||
#if 1
|
||||
REGISTER_WINDOWINGSYSTEMINTERFACE(IOS, osgViewer::ConcreteIOSWindowingSystemInterface)
|
||||
#else
|
||||
RegisterWindowingSystemInterfaceProxy<osgViewer::ConcreteIOSWindowingSystemInterface> createWindowingSystemInterfaceProxy;
|
||||
|
||||
|
||||
@@ -1235,3 +1237,4 @@ extern "C" void graphicswindow_IOS(void)
|
||||
{
|
||||
osg::GraphicsContext::setWindowingSystemInterface(new osgViewer::ConcreteIOSWindowingSystemInterface());
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -317,14 +317,16 @@ class Win32WindowingSystem : public osg::GraphicsContext::WindowingSystemInterfa
|
||||
static std::string osgGraphicsWindowWithCursorClass; //!< Name of Win32 window class (with cursor) used by OSG graphics window instances
|
||||
static std::string osgGraphicsWindowWithoutCursorClass; //!< Name of Win32 window class (without cursor) used by OSG graphics window instances
|
||||
|
||||
Win32WindowingSystem();
|
||||
~Win32WindowingSystem();
|
||||
Win32WindowingSystem()
|
||||
{
|
||||
getInterface() = this;
|
||||
}
|
||||
|
||||
// Access the Win32 windowing system through this singleton class.
|
||||
static Win32WindowingSystem* getInterface()
|
||||
static osg::ref_ptr<Win32WindowingSystem>& getInterface()
|
||||
{
|
||||
static Win32WindowingSystem* win32Interface = new Win32WindowingSystem;
|
||||
return win32Interface;
|
||||
static osg::ref_ptr<Win32WindowingSystem> s_win32Interface;
|
||||
return s_win32Interface;
|
||||
}
|
||||
|
||||
// Return the number of screens present in the system
|
||||
@@ -368,6 +370,8 @@ class Win32WindowingSystem : public osg::GraphicsContext::WindowingSystemInterfa
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~Win32WindowingSystem() {}
|
||||
|
||||
// Display devices present in the system
|
||||
typedef std::vector<DISPLAY_DEVICE> DisplayDevices;
|
||||
|
||||
@@ -2273,7 +2277,7 @@ void GraphicsWindowWin32::setCursorImpl( MouseCursor mouseCursor )
|
||||
|
||||
_currentCursor = newCursor;
|
||||
_traits->useCursor = (_currentCursor != NULL) && (_mouseCursor != NoCursor);
|
||||
|
||||
|
||||
PostMessage(_hwnd, WM_SETCURSOR, 0, 0);
|
||||
}
|
||||
}
|
||||
@@ -2894,7 +2898,7 @@ LRESULT GraphicsWindowWin32::handleNativeWindowingEvent( HWND hwnd, UINT uMsg, W
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Class responsible for registering the Win32 Windowing System interface
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if 0
|
||||
struct RegisterWindowingSystemInterfaceProxy
|
||||
{
|
||||
RegisterWindowingSystemInterfaceProxy()
|
||||
@@ -2915,16 +2919,19 @@ struct RegisterWindowingSystemInterfaceProxy
|
||||
};
|
||||
|
||||
static RegisterWindowingSystemInterfaceProxy createWindowingSystemInterfaceProxy;
|
||||
#endif
|
||||
|
||||
} // namespace OsgViewer
|
||||
|
||||
|
||||
#if 1
|
||||
REGISTER_WINDOWINGSYSTEMINTERFACE(Win32, Win32WindowingSystem)
|
||||
#else
|
||||
// declare C entry point for static compilation.
|
||||
extern "C" void OSGVIEWER_EXPORT graphicswindow_Win32(void)
|
||||
{
|
||||
osg::GraphicsContext::setWindowingSystemInterface(osgViewer::Win32WindowingSystem::getInterface());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void GraphicsWindowWin32::raiseWindow()
|
||||
{
|
||||
|
||||
@@ -2144,6 +2144,12 @@ public:
|
||||
|
||||
};
|
||||
|
||||
#if 1
|
||||
|
||||
REGISTER_WINDOWINGSYSTEMINTERFACE(X11, X11WindowingSystemInterface)
|
||||
|
||||
|
||||
#else
|
||||
struct RegisterWindowingSystemInterfaceProxy
|
||||
{
|
||||
RegisterWindowingSystemInterfaceProxy()
|
||||
@@ -2166,7 +2172,6 @@ struct RegisterWindowingSystemInterfaceProxy
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
RegisterWindowingSystemInterfaceProxy createWindowingSystemInterfaceProxy;
|
||||
|
||||
// declare C entry point for static compilation.
|
||||
@@ -2174,6 +2179,7 @@ extern "C" void graphicswindow_X11(void)
|
||||
{
|
||||
osg::GraphicsContext::setWindowingSystemInterface(new X11WindowingSystemInterface);
|
||||
}
|
||||
#endif
|
||||
|
||||
void GraphicsWindowX11::raiseWindow()
|
||||
{
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
||||
#ifndef IOS_UTILS_HEADER_
|
||||
#define IOS_UTILS_HEADER_
|
||||
|
||||
@@ -45,7 +45,7 @@ public:
|
||||
virtual void getScreenSettings(const osg::GraphicsContext::ScreenIdentifier& si, osg::GraphicsContext::ScreenSettings & resolution);
|
||||
|
||||
virtual void enumerateScreenSettings(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, osg::GraphicsContext::ScreenSettingsList & resolutionList);
|
||||
|
||||
|
||||
virtual bool setScreenSettings (const osg::GraphicsContext::ScreenIdentifier & si, const osg::GraphicsContext::ScreenSettings & settings);
|
||||
|
||||
/** returns screen-ndx containing rect x,y,w,h, NOT_TESTED@tom */
|
||||
@@ -57,12 +57,12 @@ public:
|
||||
//return the UIScreen object asscoiated with the passed ScreenIdentifier
|
||||
//returns nil if si isn't found
|
||||
UIScreen* getUIScreen(const osg::GraphicsContext::ScreenIdentifier& si);
|
||||
|
||||
|
||||
//
|
||||
//Get the contents scale factor of the screen, this is the scale factor required
|
||||
//to convert points to pixels on this screen
|
||||
bool getScreenContentScaleFactor(const osg::GraphicsContext::ScreenIdentifier& si, float& scaleFactor);
|
||||
|
||||
|
||||
//
|
||||
//Get the screens size in points, docs state a point is roughly 1/160th of an inch
|
||||
bool getScreenSizeInPoints(const osg::GraphicsContext::ScreenIdentifier& si, osg::Vec2& pointSize);
|
||||
@@ -80,11 +80,12 @@ protected:
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#if 0
|
||||
template <class WSI>
|
||||
struct RegisterWindowingSystemInterfaceProxy
|
||||
{
|
||||
@@ -104,7 +105,7 @@ struct RegisterWindowingSystemInterfaceProxy
|
||||
osg::GraphicsContext::setWindowingSystemInterface(0);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user