Changeset 11207 for OpenSceneGraph/trunk/src/osgViewer/DarwinUtils.mm
- Timestamp:
- 03/13/10 12:28:00 (3 years ago)
- Files:
-
- 1 modified
-
OpenSceneGraph/trunk/src/osgViewer/DarwinUtils.mm (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgViewer/DarwinUtils.mm
r10622 r11207 222 222 /** ctor, get a list of all attached displays */ 223 223 DarwinWindowingSystemInterface::DarwinWindowingSystemInterface() : 224 _initialized(false), 224 225 _displayCount(0), 225 226 _displayIds(NULL) 226 227 { 228 } 229 230 /** dtor */ 231 DarwinWindowingSystemInterface::~DarwinWindowingSystemInterface() 232 { 233 if (osg::Referenced::getDeleteHandler()) 234 { 235 osg::Referenced::getDeleteHandler()->setNumFramesToRetainObjects(0); 236 osg::Referenced::getDeleteHandler()->flushAll(); 237 } 238 239 if (_displayIds) delete[] _displayIds; 240 _displayIds = NULL; 241 } 242 243 void DarwinWindowingSystemInterface::_init() 244 { 245 if (_initialized) return; 246 227 247 ProcessSerialNumber sn = { 0, kCurrentProcess }; 228 248 TransformProcessType(&sn,kProcessTransformToForegroundApplication); 229 249 SetFrontProcess(&sn); 230 250 231 251 if( CGGetActiveDisplayList( 0, NULL, &_displayCount ) != CGDisplayNoErr ) 252 { 232 253 osg::notify(osg::WARN) << "DarwinWindowingSystemInterface: could not get # of screens" << std::endl; 233 254 _displayCount = 0; 255 256 _initialized = true; 257 return; 258 } 259 234 260 _displayIds = new CGDirectDisplayID[_displayCount]; 261 235 262 if( CGGetActiveDisplayList( _displayCount, _displayIds, &_displayCount ) != CGDisplayNoErr ) 263 { 236 264 osg::notify(osg::WARN) << "DarwinWindowingSystemInterface: CGGetActiveDisplayList failed" << std::endl; 237 238 } 239 240 /** dtor */ 241 DarwinWindowingSystemInterface::~DarwinWindowingSystemInterface() 242 { 243 if (osg::Referenced::getDeleteHandler()) 244 { 245 osg::Referenced::getDeleteHandler()->setNumFramesToRetainObjects(0); 246 osg::Referenced::getDeleteHandler()->flushAll(); 247 } 248 249 if (_displayIds) delete[] _displayIds; 250 _displayIds = NULL; 265 } 266 267 _initialized = true; 251 268 } 252 269 253 270 /** @return a CGDirectDisplayID for a ScreenIdentifier */ 254 CGDirectDisplayID DarwinWindowingSystemInterface::getDisplayID(const osg::GraphicsContext::ScreenIdentifier& si) { 271 CGDirectDisplayID DarwinWindowingSystemInterface::getDisplayID(const osg::GraphicsContext::ScreenIdentifier& si) 272 { 273 _init(); 274 275 if (_displayCount==0) 276 { 277 osg::notify(osg::WARN) << "DarwinWindowingSystemInterface::getDisplayID(..) no valid screens available returning 0 instead." << std::endl; 278 return 0; 279 } 280 255 281 if (si.screenNum < static_cast<int>(_displayCount)) 282 { 256 283 return _displayIds[si.screenNum]; 257 else { 258 osg::notify(osg::WARN) << "GraphicsWindowCarbon :: invalid screen # " << si.screenNum << ", returning main-screen instead" << std::endl; 284 } 285 else 286 { 287 osg::notify(osg::WARN) << "DarwinWindowingSystemInterface::getDisplayID(..) invalid screen # " << si.screenNum << ", returning main-screen instead." << std::endl; 259 288 return _displayIds[0]; 260 289 } … … 264 293 unsigned int DarwinWindowingSystemInterface::getNumScreens(const osg::GraphicsContext::ScreenIdentifier& si) 265 294 { 295 _init(); 296 266 297 return _displayCount; 267 298 } … … 269 300 void DarwinWindowingSystemInterface::getScreenSettings(const osg::GraphicsContext::ScreenIdentifier& si, osg::GraphicsContext::ScreenSettings & resolution) 270 301 { 302 _init(); 303 304 if (_displayCount==0) 305 { 306 resolution.width = 0; 307 resolution.height = 0; 308 resolution.colorDepth = 0; 309 resolution.refreshRate = 0; 310 return; 311 } 312 271 313 CGDirectDisplayID id = getDisplayID(si); 272 314 resolution.width = CGDisplayPixelsWide(id); … … 278 320 279 321 280 void DarwinWindowingSystemInterface::enumerateScreenSettings(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, osg::GraphicsContext::ScreenSettingsList & resolutionList) { 281 // Warning! This method has not been tested. 282 resolutionList.clear(); 283 284 CGDirectDisplayID displayid = getDisplayID(screenIdentifier); 285 CFArrayRef availableModes = CGDisplayAvailableModes(displayid); 286 unsigned int numberOfAvailableModes = CFArrayGetCount(availableModes); 287 for (unsigned int i=0; i<numberOfAvailableModes; ++i) { 288 // look at each mode in the available list 289 CFDictionaryRef mode = (CFDictionaryRef)CFArrayGetValueAtIndex(availableModes, i); 290 osg::GraphicsContext::ScreenSettings tmpSR; 291 292 long width = getDictLong(mode, kCGDisplayWidth); 293 tmpSR.width = width<=0 ? 0 : width; 294 long height = getDictLong(mode, kCGDisplayHeight); 295 tmpSR.height = height<=0 ? 0 : height; 296 long rate = getDictLong(mode, kCGDisplayRefreshRate); 297 tmpSR.refreshRate = rate<=0 ? 0 : rate; 298 long depth = getDictLong(mode, kCGDisplayBitsPerPixel); 299 tmpSR.colorDepth = depth<=0 ? 0 : depth; 300 301 resolutionList.push_back(tmpSR); 302 } 303 } 322 void DarwinWindowingSystemInterface::enumerateScreenSettings(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, osg::GraphicsContext::ScreenSettingsList & resolutionList) 323 { 324 _init(); 325 326 // Warning! This method has not been tested. 327 resolutionList.clear(); 328 329 if (_displayCount==0) 330 { 331 return; 332 } 333 334 CGDirectDisplayID displayid = getDisplayID(screenIdentifier); 335 CFArrayRef availableModes = CGDisplayAvailableModes(displayid); 336 unsigned int numberOfAvailableModes = CFArrayGetCount(availableModes); 337 for (unsigned int i=0; i<numberOfAvailableModes; ++i) { 338 // look at each mode in the available list 339 CFDictionaryRef mode = (CFDictionaryRef)CFArrayGetValueAtIndex(availableModes, i); 340 osg::GraphicsContext::ScreenSettings tmpSR; 341 342 long width = getDictLong(mode, kCGDisplayWidth); 343 tmpSR.width = width<=0 ? 0 : width; 344 long height = getDictLong(mode, kCGDisplayHeight); 345 tmpSR.height = height<=0 ? 0 : height; 346 long rate = getDictLong(mode, kCGDisplayRefreshRate); 347 tmpSR.refreshRate = rate<=0 ? 0 : rate; 348 long depth = getDictLong(mode, kCGDisplayBitsPerPixel); 349 tmpSR.colorDepth = depth<=0 ? 0 : depth; 350 351 resolutionList.push_back(tmpSR); 352 } 353 } 304 354 305 355 /** return the top left coord of a specific screen in global screen space */ 306 void DarwinWindowingSystemInterface::getScreenTopLeft(const osg::GraphicsContext::ScreenIdentifier& si, int& x, int& y) { 356 void DarwinWindowingSystemInterface::getScreenTopLeft(const osg::GraphicsContext::ScreenIdentifier& si, int& x, int& y) 357 { 358 _init(); 359 360 if (_displayCount==0) 361 { 362 x = 0; 363 y = 0; 364 return; 365 } 366 307 367 CGRect bounds = CGDisplayBounds( getDisplayID(si) ); 308 368 x = static_cast<int>(bounds.origin.x); … … 317 377 bool result = setScreenResolutionImpl(si, settings.width, settings.height); 318 378 if (result) 379 { 319 380 setScreenRefreshRateImpl(si, settings.refreshRate); 320 381 } 382 321 383 return result; 322 384 } … … 327 389 bool DarwinWindowingSystemInterface::setScreenResolutionImpl(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, unsigned int width, unsigned int height) 328 390 { 391 _init(); 392 393 if (_displayCount==0) 394 { 395 return false; 396 } 397 329 398 CGDirectDisplayID displayid = getDisplayID(screenIdentifier); 330 399 … … 345 414 346 415 /** implementation of setScreenRefreshRate */ 347 bool DarwinWindowingSystemInterface::setScreenRefreshRateImpl(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, double refreshRate) { 348 416 bool DarwinWindowingSystemInterface::setScreenRefreshRateImpl(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, double refreshRate) 417 { 418 _init(); 419 420 if (_displayCount==0) 421 { 422 return false; 423 } 424 349 425 boolean_t success(false); 350 426 unsigned width, height; … … 372 448 unsigned int DarwinWindowingSystemInterface::getScreenContaining(int x, int y, int w, int h) 373 449 { 450 _init(); 451 452 if (_displayCount==0) 453 { 454 return 0; 455 } 456 374 457 CGRect rect = CGRectMake(x,y,w,h); 375 458 for(unsigned int i = 0; i < _displayCount; ++i) { … … 383 466 } 384 467 385 386 387 388 389 390 } 468 }
