| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | #ifdef __APPLE__ |
|---|
| 11 | |
|---|
| 12 | #ifndef DARWIN_UTILS_HEADER_ |
|---|
| 13 | #define DARWIN_UTILS_HEADER_ |
|---|
| 14 | |
|---|
| 15 | #include <osg/DeleteHandler> |
|---|
| 16 | #include <osg/GraphicsContext> |
|---|
| 17 | #include <osgViewer/GraphicsWindow> |
|---|
| 18 | #include <Carbon/Carbon.h> |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | namespace osgDarwin { |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | class MenubarController : public osg::Referenced |
|---|
| 29 | { |
|---|
| 30 | |
|---|
| 31 | public: |
|---|
| 32 | class WindowAdapter : public osg::Referenced { |
|---|
| 33 | |
|---|
| 34 | public: |
|---|
| 35 | WindowAdapter() : osg::Referenced() {} |
|---|
| 36 | |
|---|
| 37 | virtual bool valid() = 0; |
|---|
| 38 | virtual void getWindowBounds(CGRect& rect) = 0; |
|---|
| 39 | virtual osgViewer::GraphicsWindow* getWindow() = 0; |
|---|
| 40 | |
|---|
| 41 | protected: |
|---|
| 42 | virtual ~WindowAdapter() {} |
|---|
| 43 | }; |
|---|
| 44 | |
|---|
| 45 | MenubarController(); |
|---|
| 46 | static MenubarController* instance(); |
|---|
| 47 | |
|---|
| 48 | void attachWindow(WindowAdapter* win); |
|---|
| 49 | void update(); |
|---|
| 50 | void detachWindow(osgViewer::GraphicsWindow* win); |
|---|
| 51 | |
|---|
| 52 | private: |
|---|
| 53 | typedef std::list< osg::ref_ptr< WindowAdapter > > WindowList; |
|---|
| 54 | WindowList _list; |
|---|
| 55 | bool _menubarShown; |
|---|
| 56 | CGRect _availRect; |
|---|
| 57 | CGRect _mainScreenBounds; |
|---|
| 58 | OpenThreads::Mutex _mutex; |
|---|
| 59 | |
|---|
| 60 | }; |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | struct DarwinWindowingSystemInterface : public osg::GraphicsContext::WindowingSystemInterface |
|---|
| 65 | { |
|---|
| 66 | public: |
|---|
| 67 | DarwinWindowingSystemInterface(); |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | ~DarwinWindowingSystemInterface(); |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | CGDirectDisplayID getDisplayID(const osg::GraphicsContext::ScreenIdentifier& si); |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | virtual unsigned int getNumScreens(const osg::GraphicsContext::ScreenIdentifier& si) ; |
|---|
| 77 | |
|---|
| 78 | virtual void getScreenSettings(const osg::GraphicsContext::ScreenIdentifier& si, osg::GraphicsContext::ScreenSettings & resolution); |
|---|
| 79 | |
|---|
| 80 | virtual void enumerateScreenSettings(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, osg::GraphicsContext::ScreenSettingsList & resolutionList); |
|---|
| 81 | |
|---|
| 82 | virtual bool setScreenSettings (const osg::GraphicsContext::ScreenIdentifier & si, const osg::GraphicsContext::ScreenSettings & settings); |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | void getScreenTopLeft(const osg::GraphicsContext::ScreenIdentifier& si, int& x, int& y); |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | unsigned int getScreenContaining(int x, int y, int w, int h); |
|---|
| 91 | |
|---|
| 92 | protected: |
|---|
| 93 | |
|---|
| 94 | virtual void _init(); |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | bool setScreenResolutionImpl(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, unsigned int width, unsigned int height) ; |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | bool setScreenRefreshRateImpl(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, double refreshRate); |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | template<class PixelBufferImplementation, class GraphicsWindowImplementation> |
|---|
| 104 | osg::GraphicsContext* createGraphicsContextImplementation(osg::GraphicsContext::Traits* traits) |
|---|
| 105 | { |
|---|
| 106 | if (traits->pbuffer) |
|---|
| 107 | { |
|---|
| 108 | osg::ref_ptr<PixelBufferImplementation> pbuffer = new PixelBufferImplementation(traits); |
|---|
| 109 | if (pbuffer->valid()) return pbuffer.release(); |
|---|
| 110 | else return 0; |
|---|
| 111 | } |
|---|
| 112 | else |
|---|
| 113 | { |
|---|
| 114 | osg::ref_ptr<GraphicsWindowImplementation> window = new GraphicsWindowImplementation(traits); |
|---|
| 115 | if (window->valid()) return window.release(); |
|---|
| 116 | else return 0; |
|---|
| 117 | } |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | private: |
|---|
| 122 | |
|---|
| 123 | bool _initialized; |
|---|
| 124 | CGDisplayCount _displayCount; |
|---|
| 125 | CGDirectDisplayID* _displayIds; |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | }; |
|---|
| 129 | |
|---|
| 130 | template <class WSI> |
|---|
| 131 | struct RegisterWindowingSystemInterfaceProxy |
|---|
| 132 | { |
|---|
| 133 | RegisterWindowingSystemInterfaceProxy() |
|---|
| 134 | { |
|---|
| 135 | osg::GraphicsContext::setWindowingSystemInterface(new WSI); |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | ~RegisterWindowingSystemInterfaceProxy() |
|---|
| 139 | { |
|---|
| 140 | if (osg::Referenced::getDeleteHandler()) |
|---|
| 141 | { |
|---|
| 142 | osg::Referenced::getDeleteHandler()->setNumFramesToRetainObjects(0); |
|---|
| 143 | osg::Referenced::getDeleteHandler()->flushAll(); |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | osg::GraphicsContext::setWindowingSystemInterface(0); |
|---|
| 147 | } |
|---|
| 148 | }; |
|---|
| 149 | |
|---|
| 150 | |
|---|
| 151 | |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | #endif |
|---|
| 155 | |
|---|
| 156 | #endif // __APPLE__ |
|---|