From Stephan Hunber, "I found some time and ported osgDB::FileUtils and DarwinUtils across new apis to fix the warnings about deprecated api-usage.
* osgDB::FileUtils uses now the Cocoa-API to determine the paths of the application-support-folder * DarwinUtils uses now modern functions of the quartz-api to get and set screen-resolutions. Removed some of the osg-deprecated stuff. "
This commit is contained in:
@@ -109,13 +109,6 @@ struct DarwinWindowingSystemInterface : public osg::GraphicsContext::WindowingSy
|
||||
protected:
|
||||
|
||||
virtual void _init();
|
||||
|
||||
/** implementation of setScreenResolution */
|
||||
bool setScreenResolutionImpl(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, unsigned int width, unsigned int height) ;
|
||||
|
||||
/** implementation of setScreenRefreshRate */
|
||||
bool setScreenRefreshRateImpl(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, double refreshRate);
|
||||
|
||||
|
||||
template<class PixelBufferImplementation, class GraphicsWindowImplementation>
|
||||
osg::GraphicsContext* createGraphicsContextImplementation(osg::GraphicsContext::Traits* traits)
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <osg/DeleteHandler>
|
||||
#include "DarwinUtils.h"
|
||||
#include <Cocoa/Cocoa.h>
|
||||
#include <limits>
|
||||
|
||||
@interface MenubarToggler : NSObject {
|
||||
|
||||
@@ -104,21 +105,9 @@
|
||||
|
||||
namespace osgDarwin {
|
||||
|
||||
//
|
||||
// Lion replacement for CGDisplayBitsPerPixel(CGDirectDisplayID displayId)
|
||||
//
|
||||
size_t displayBitsPerPixel( CGDirectDisplayID displayId )
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
|
||||
size_t displayBitsPerPixelForMode(CGDisplayModeRef mode)
|
||||
{
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
|
||||
return CGDisplayBitsPerPixel(displayId);
|
||||
#else
|
||||
CGDisplayModeRef mode = CGDisplayCopyDisplayMode(displayId);
|
||||
if (!mode)
|
||||
{
|
||||
OSG_WARN << "CGDisplayCopyDisplayMode returned NULL" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
CFStringRef pixEnc = CGDisplayModeCopyPixelEncoding(mode);
|
||||
if (!pixEnc)
|
||||
{
|
||||
@@ -144,14 +133,88 @@ size_t displayBitsPerPixel( CGDirectDisplayID displayId )
|
||||
{
|
||||
OSG_WARN << "Unable to match pixel encoding '" << CFStringGetCStringPtr(pixEnc, kCFStringEncodingUTF8) << "'" << std::endl;
|
||||
}
|
||||
|
||||
CGDisplayModeRelease(mode);
|
||||
CFRelease(pixEnc);
|
||||
|
||||
return depth;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
size_t displayBitsPerPixel( CGDirectDisplayID displayId )
|
||||
{
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
|
||||
return CGDisplayBitsPerPixel(displayId);
|
||||
#else
|
||||
CGDisplayModeRef mode = CGDisplayCopyDisplayMode(displayId);
|
||||
if (!mode)
|
||||
{
|
||||
OSG_WARN << "CGDisplayCopyDisplayMode returned NULL" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int depth = displayBitsPerPixelForMode(mode);
|
||||
CGDisplayModeRelease(mode);
|
||||
|
||||
return depth;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static bool findBestDisplayModeFor(const CGDirectDisplayID& displayid, int desired_width, int desired_height, unsigned int desired_color_depth, double desired_refresh_rate) {
|
||||
|
||||
CFArrayRef availableModes = CGDisplayCopyAllDisplayModes(displayid, NULL);
|
||||
unsigned int numberOfAvailableModes = CFArrayGetCount(availableModes);
|
||||
|
||||
CGDisplayModeRef best_match(NULL);
|
||||
|
||||
int best_dx = std::numeric_limits<int>::max();
|
||||
int best_dy = std::numeric_limits<int>::max();
|
||||
|
||||
|
||||
for (unsigned int i=0; i<numberOfAvailableModes; ++i)
|
||||
{
|
||||
CGDisplayModeRef mode = (CGDisplayModeRef)CFArrayGetValueAtIndex(availableModes, i);
|
||||
osg::GraphicsContext::ScreenSettings tmpSR;
|
||||
|
||||
int w = CGDisplayModeGetWidth(mode);
|
||||
int h = CGDisplayModeGetHeight(mode);
|
||||
unsigned int color_depth = displayBitsPerPixelForMode(mode);
|
||||
|
||||
double rate = CGDisplayModeGetRefreshRate(mode);
|
||||
|
||||
int dx(w - desired_width);
|
||||
int dy(h - desired_height);
|
||||
|
||||
if ((dx > 0) && (dx <= best_dx) && (dy > 0) && (dy <= best_dy) && (color_depth >= desired_color_depth) && (rate >= desired_refresh_rate)) {
|
||||
best_match = mode;
|
||||
best_dx = dx;
|
||||
best_dy = dy;
|
||||
}
|
||||
}
|
||||
bool result = false;
|
||||
if(best_match)
|
||||
{
|
||||
result = CGDisplaySetDisplayMode(displayid, best_match, NULL) != kCGErrorSuccess;
|
||||
}
|
||||
else if (desired_refresh_rate > 0)
|
||||
{
|
||||
// try again with a lower refresh-rate
|
||||
result = findBestDisplayModeFor(displayid, desired_width, desired_height, desired_color_depth, 0);
|
||||
}
|
||||
else if (desired_color_depth > 0)
|
||||
{
|
||||
// try again with a lower color_depth
|
||||
result = findBestDisplayModeFor(displayid, desired_width, desired_height, 0, 0);
|
||||
}
|
||||
|
||||
CFRelease(availableModes);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static inline CGRect toCGRect(NSRect nsRect)
|
||||
{
|
||||
CGRect cgRect;
|
||||
@@ -418,12 +481,25 @@ void DarwinWindowingSystemInterface::getScreenSettings(const osg::GraphicsContex
|
||||
resolution.refreshRate = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
CGDirectDisplayID id = getDisplayID(si);
|
||||
resolution.width = CGDisplayPixelsWide(id);
|
||||
resolution.height = CGDisplayPixelsHigh(id);
|
||||
resolution.colorDepth = displayBitsPerPixel(id);
|
||||
resolution.refreshRate = getDictDouble (CGDisplayCurrentMode(id), kCGDisplayRefreshRate); // Not tested
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
|
||||
|
||||
CGDisplayModeRef display_mode_ref = CGDisplayCopyDisplayMode(id);
|
||||
resolution.width = CGDisplayModeGetWidth(display_mode_ref);
|
||||
resolution.height = CGDisplayModeGetHeight(display_mode_ref);
|
||||
resolution.colorDepth = displayBitsPerPixelForMode(display_mode_ref);
|
||||
resolution.refreshRate = CGDisplayModeGetRefreshRate(display_mode_ref);
|
||||
|
||||
CGDisplayModeRelease(display_mode_ref);
|
||||
|
||||
#else
|
||||
resolution.width = CGDisplayPixelsWide(id);
|
||||
resolution.height = CGDisplayPixelsHigh(id);
|
||||
resolution.colorDepth = displayBitsPerPixel(id);
|
||||
|
||||
resolution.refreshRate = getDictDouble (CGDisplayCurrentMode(id), kCGDisplayRefreshRate); // Not tested
|
||||
#endif
|
||||
if (resolution.refreshRate<0) resolution.refreshRate = 0;
|
||||
}
|
||||
|
||||
@@ -441,6 +517,27 @@ void DarwinWindowingSystemInterface::enumerateScreenSettings(const osg::Graphics
|
||||
}
|
||||
|
||||
CGDirectDisplayID displayid = getDisplayID(screenIdentifier);
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
|
||||
|
||||
CFArrayRef availableModes = CGDisplayCopyAllDisplayModes(displayid, NULL);
|
||||
unsigned int numberOfAvailableModes = CFArrayGetCount(availableModes);
|
||||
for (unsigned int i=0; i<numberOfAvailableModes; ++i)
|
||||
{
|
||||
CGDisplayModeRef mode = (CGDisplayModeRef)CFArrayGetValueAtIndex(availableModes, i);
|
||||
osg::GraphicsContext::ScreenSettings tmpSR;
|
||||
|
||||
tmpSR.width = CGDisplayModeGetWidth(mode);
|
||||
tmpSR.height = CGDisplayModeGetHeight(mode);
|
||||
tmpSR.colorDepth = displayBitsPerPixelForMode(mode);
|
||||
tmpSR.refreshRate = CGDisplayModeGetRefreshRate(mode);
|
||||
|
||||
resolutionList.push_back(tmpSR);
|
||||
}
|
||||
|
||||
CFRelease(availableModes);
|
||||
|
||||
#else
|
||||
|
||||
CFArrayRef availableModes = CGDisplayAvailableModes(displayid);
|
||||
unsigned int numberOfAvailableModes = CFArrayGetCount(availableModes);
|
||||
for (unsigned int i=0; i<numberOfAvailableModes; ++i) {
|
||||
@@ -459,6 +556,7 @@ void DarwinWindowingSystemInterface::enumerateScreenSettings(const osg::Graphics
|
||||
|
||||
resolutionList.push_back(tmpSR);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/** return the top left coord of a specific screen in global screen space */
|
||||
@@ -483,76 +581,32 @@ void DarwinWindowingSystemInterface::getScreenTopLeft(const osg::GraphicsContext
|
||||
|
||||
bool DarwinWindowingSystemInterface::setScreenSettings(const osg::GraphicsContext::ScreenIdentifier &si, const osg::GraphicsContext::ScreenSettings & settings)
|
||||
{
|
||||
bool result = setScreenResolutionImpl(si, settings.width, settings.height);
|
||||
if (result)
|
||||
{
|
||||
setScreenRefreshRateImpl(si, settings.refreshRate);
|
||||
}
|
||||
CGDirectDisplayID displayid = getDisplayID(si);
|
||||
|
||||
return result;
|
||||
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060)
|
||||
|
||||
return findBestDisplayModeFor(displayid, settings.width, settings.height, settings.colorDepth, settings.refreshRate);
|
||||
|
||||
#else
|
||||
// add next line and on following line replace hard coded depth and refresh rate
|
||||
CGRefreshRate refresh = getDictDouble (CGDisplayCurrentMode(displayid), kCGDisplayRefreshRate);
|
||||
CFDictionaryRef display_mode_values =
|
||||
CGDisplayBestModeForParametersAndRefreshRate(
|
||||
displayid,
|
||||
settings.colorDepth,
|
||||
settings.width, settings.height,
|
||||
settings.refreshRate,
|
||||
NULL);
|
||||
|
||||
|
||||
return CGDisplaySwitchToMode(displayid, display_mode_values) != kCGErrorSuccess;
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** implementation of setScreenResolution */
|
||||
bool DarwinWindowingSystemInterface::setScreenResolutionImpl(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, unsigned int width, unsigned int height)
|
||||
{
|
||||
_init();
|
||||
|
||||
if (_displayCount==0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
CGDirectDisplayID displayid = getDisplayID(screenIdentifier);
|
||||
|
||||
// add next line and on following line replace hard coded depth and refresh rate
|
||||
CGRefreshRate refresh = getDictDouble (CGDisplayCurrentMode(displayid), kCGDisplayRefreshRate);
|
||||
CFDictionaryRef display_mode_values =
|
||||
CGDisplayBestModeForParametersAndRefreshRate(
|
||||
displayid,
|
||||
displayBitsPerPixel(displayid),
|
||||
width, height,
|
||||
refresh,
|
||||
NULL);
|
||||
|
||||
|
||||
CGDisplaySwitchToMode(displayid, display_mode_values);
|
||||
return true;
|
||||
}
|
||||
|
||||
/** implementation of setScreenRefreshRate */
|
||||
bool DarwinWindowingSystemInterface::setScreenRefreshRateImpl(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, double refreshRate)
|
||||
{
|
||||
_init();
|
||||
|
||||
if (_displayCount==0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean_t success(false);
|
||||
unsigned width, height;
|
||||
getScreenResolution(screenIdentifier, width, height);
|
||||
|
||||
CGDirectDisplayID displayid = getDisplayID(screenIdentifier);
|
||||
|
||||
// add next line and on following line replace hard coded depth and refresh rate
|
||||
CFDictionaryRef display_mode_values =
|
||||
CGDisplayBestModeForParametersAndRefreshRate(
|
||||
displayid,
|
||||
displayBitsPerPixel(displayid),
|
||||
width, height,
|
||||
refreshRate,
|
||||
&success);
|
||||
|
||||
|
||||
if (success)
|
||||
CGDisplaySwitchToMode(displayid, display_mode_values);
|
||||
|
||||
return (success != 0);
|
||||
}
|
||||
|
||||
|
||||
unsigned int DarwinWindowingSystemInterface::getScreenContaining(int x, int y, int w, int h)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user