bool nglVideoMode::Enum(nglVideoMode& Mode, uint Index) { #ifdef __NGL_MACHO__ CFArrayRef displayModeArray ; CFDictionaryRef displayMode ; CFNumberRef number ; displayModeArray = CGDisplayAvailableModes( (CGDirectDisplayID)Mode.mDisplay ) ; if ( CFArrayGetCount(displayModeArray) <= Index) { return false; } displayMode = (CFDictionaryRef) CFArrayGetValueAtIndex(displayModeArray, Index) ; /* Get the height and width of this display mode. Print them out. */ number = (CFNumberRef)CFDictionaryGetValue( displayMode, kCGDisplayWidth ) ; CFNumberGetValue( number, kCFNumberLongType, &Mode.mWidth ) ; number = (CFNumberRef)CFDictionaryGetValue( displayMode, kCGDisplayHeight ) ; CFNumberGetValue( number, kCFNumberLongType, &Mode.mHeight ) ; number = (CFNumberRef)CFDictionaryGetValue( displayMode, kCGDisplayRefreshRate ) ; CFNumberGetValue( number, kCFNumberLongType, &Mode.mRate ) ; number = (CFNumberRef)CFDictionaryGetValue( displayMode, kCGDisplayBitsPerPixel ) ; CFNumberGetValue( number, kCFNumberLongType, &Mode.mBPP ) ; return true; #else return false; #endif }
static int Open(void * hwnd) { CGLRendererInfoObj renderer; long numRenderer; CGDirectDisplayID l[32]; CGDisplayCount count; SYS_ASSERT(g_pCGLC == 0); UNUSED(hwnd); CGGetActiveDisplayList (sizeof(l), l, &count); #ifdef _DEBUG // Debug in multiple monitor. Use the secondary monitor for rendering g_cgDisplayID = l[count-1]; #else g_cgDisplayID = CGMainDisplayID (); #endif g_cgPrevDisplayMode = CGDisplayCurrentMode (g_cgDisplayID); g_cgDisplayModeList = CGDisplayAvailableModes (g_cgDisplayID); CGLQueryRendererInfo(CGDisplayIDToOpenGLDisplayMask(g_cgDisplayID), &renderer, &numRenderer); CGLDestroyRendererInfo(renderer); return 0; }
const DisplayResVector& DisplayResOSX::GetVideoModes() const { if (m_video_modes.size()) return m_video_modes; CGDirectDisplayID d = GetOSXDisplay(MythDisplay::GetWindowID()); CFArrayRef displayModes = CGDisplayAvailableModes(d); if (NULL == displayModes) return m_video_modes; DisplayResMap screen_map; for (int i=0; i<CFArrayGetCount(displayModes); ++i) { CFDictionaryRef displayMode = (CFDictionaryRef) CFArrayGetValueAtIndex(displayModes, i); int width = get_int_CF(displayMode, kCGDisplayWidth); int height = get_int_CF(displayMode, kCGDisplayHeight); int refresh = get_int_CF(displayMode, kCGDisplayRefreshRate); uint64_t key = DisplayResScreen::CalcKey(width, height, 0.0); if (screen_map.find(key)==screen_map.end()) screen_map[key] = DisplayResScreen(width, height, 0, 0, -1.0, (double) refresh); else screen_map[key].AddRefreshRate(refresh); } //CFRelease(displayModes); // this release causes a segfault DisplayResMapCIt it = screen_map.begin(); for (; screen_map.end() != it; ++it) m_video_modes.push_back(it->second); return m_video_modes; }
size_t VID_ListModes(vid_mode_t *modes, size_t maxcount) { CGDirectDisplayID mainDisplay = CGMainDisplayID(); CFArrayRef vidmodes = CGDisplayAvailableModes(mainDisplay); CFDictionaryRef thismode; unsigned int n = CFArrayGetCount(vidmodes); unsigned int i; size_t k; k = 0; for(i = 0; i < n; ++i) { thismode = (CFDictionaryRef) CFArrayGetValueAtIndex(vidmodes, i); if(!GetDictionaryBoolean(thismode, kCGDisplayModeIsSafeForHardware)) continue; if(k >= maxcount) break; modes[k].width = GetDictionaryLong(thismode, kCGDisplayWidth); modes[k].height = GetDictionaryLong(thismode, kCGDisplayHeight); modes[k].bpp = GetDictionaryLong(thismode, kCGDisplayBitsPerPixel); modes[k].refreshrate = GetDictionaryLong(thismode, kCGDisplayRefreshRate); modes[k].pixelheight_num = 1; modes[k].pixelheight_denom = 1; // OS X doesn't expose this either ++k; } return k; }
// Search for avaliable resolutions - TODO: Move to Common? wxArrayString GetListOfResolutions() { wxArrayString retlist; #ifdef _WIN32 DWORD iModeNum = 0; DEVMODE dmi; ZeroMemory(&dmi, sizeof(dmi)); dmi.dmSize = sizeof(dmi); std::vector<std::string> resos; while (EnumDisplaySettings(NULL, iModeNum++, &dmi) != 0) { char res[100]; sprintf(res, "%dx%d", dmi.dmPelsWidth, dmi.dmPelsHeight); std::string strRes(res); // Only add unique resolutions if (std::find(resos.begin(), resos.end(), strRes) == resos.end()) { resos.push_back(strRes); retlist.Add(wxString::FromAscii(res)); } ZeroMemory(&dmi, sizeof(dmi)); } #elif defined(HAVE_XRANDR) && HAVE_XRANDR main_frame->m_XRRConfig->AddResolutions(retlist); #elif defined(__APPLE__) CFArrayRef modes = CGDisplayAvailableModes(CGMainDisplayID()); for (CFIndex i = 0; i < CFArrayGetCount(modes); i++) { std::stringstream res; CFDictionaryRef mode; CFNumberRef ref; int w, h, d; mode = (CFDictionaryRef)CFArrayGetValueAtIndex(modes, i); ref = (CFNumberRef)CFDictionaryGetValue(mode, kCGDisplayWidth); CFNumberGetValue(ref, kCFNumberIntType, &w); ref = (CFNumberRef)CFDictionaryGetValue(mode, kCGDisplayHeight); CFNumberGetValue(ref, kCFNumberIntType, &h); ref = (CFNumberRef)CFDictionaryGetValue(mode, kCGDisplayBitsPerPixel); CFNumberGetValue(ref, kCFNumberIntType, &d); if (CFDictionaryContainsKey(mode, kCGDisplayModeIsStretched)) continue; if (d != 32) continue; res << w << "x" << h; retlist.Add(res.str()); } #endif return retlist; }
//////////////////////////////////////////////////////////// /// Get supported video modes //////////////////////////////////////////////////////////// void VideoModeGetDesktopMode(struct VideoMode * Mode) { // Ceylo -- using same implementation as in OSXCarbon // Enumerate all available video modes for primary display adapter CFArrayRef DisplayModes = CGDisplayAvailableModes( kCGDirectMainDisplay ); CFIndex DisplayModeCount = CFArrayGetCount( DisplayModes ); CFDictionaryRef CurrentMode; int Count = 0; for (Count = 0; Count < DisplayModeCount; ++Count) { CurrentMode = (CFDictionaryRef)CFArrayGetValueAtIndex( DisplayModes, Count ); struct VideoMode Mode; CFNumberGetValue((CFNumberRef)CFDictionaryGetValue(CurrentMode, kCGDisplayWidth), kCFNumberIntType, &(Mode.Width)); CFNumberGetValue((CFNumberRef)CFDictionaryGetValue(CurrentMode, kCGDisplayHeight), kCFNumberIntType, &(Mode.Height)); CFNumberGetValue((CFNumberRef)CFDictionaryGetValue(CurrentMode, kCGDisplayBitsPerPixel), kCFNumberIntType, &(Mode.BitsPerPixel)); if (ModeList->Modes == NULL) { ModeList->Modes = (struct VideoMode*)(malloc(sizeof(struct VideoMode))); ModeList->Modes[0] = Mode; } int ModeCounter = 0; // Add it only if it is not already in the array for (ModeCounter = 0; ModeCounter <= Count; ++ModeCounter) { if ( (ModeList->Modes[ModeCounter].Width != Mode.Width) && (ModeList->Modes[ModeCounter].Height != Mode.Height) && (ModeList->Modes[ModeCounter].BitsPerPixel != Mode.BitsPerPixel) ) { if (ModeCounter == Count) { ModeList->Size++; ModeList->Modes = (struct VideoMode *)(realloc(ModeList->Modes, (ModeList->Size+1) * sizeof(struct VideoMode))); ModeList->Modes[ModeList->Size].Width = Mode.Width; ModeList->Modes[ModeList->Size].Height = Mode.Height; ModeList->Modes[ModeList->Size].BitsPerPixel = Mode.BitsPerPixel; } } } } }
void CoreMacOSPlatform::GetAvailableDisplayModes(List<DisplayMode> & availableModes) { CFArrayRef availableModesSystem = CGDisplayAvailableModes(kCGDirectMainDisplay); int32 numberOfAvailableModes = CFArrayGetCount(availableModesSystem); for (int modeIndex = 0; modeIndex < numberOfAvailableModes; ++modeIndex) { // look at each mode in the available list CFDictionaryRef modeSystem = (CFDictionaryRef)CFArrayGetValueAtIndex(availableModesSystem, modeIndex); DisplayMode mode; mode.width = GetModeWidth(modeSystem); mode.height = GetModeHeight(modeSystem); mode.refreshRate = GetModeRefreshRate(modeSystem); mode.bpp = GetModeBitsPerPixel(modeSystem); availableModes.push_back(mode); } // LPDIRECT3D9 direct3D = RenderManager::Instance()->GetD3D(); // availableDisplayModes.clear(); // // D3DFORMAT formats[] = {D3DFMT_R5G6B5, D3DFMT_X8R8G8B8}; // // for (int format = 0; format < sizeof(formats) / sizeof(D3DFORMAT); ++format) // { // for (int32 mode = 0; mode < direct3D->GetAdapterModeCount(D3DADAPTER_DEFAULT, formats[format]); ++mode) // { // D3DDISPLAYMODE displayMode; // HRESULT hr = direct3D->EnumAdapterModes(D3DADAPTER_DEFAULT, formats[format], mode, &displayMode); // if (!FAILED(hr)) // { // DisplayMode mode; // mode.width = displayMode.Width; // mode.height = displayMode.Height; // if (displayMode.Format == D3DFMT_R5G6B5)mode.bpp = 16; // else if (displayMode.Format == D3DFMT_X8R8G8B8) mode.bpp = 32; // else if (displayMode.Format == D3DFMT_R8G8B8) mode.bpp = 24; // mode.refreshRate = displayMode.RefreshRate; // availableDisplayModes.push_back(mode); // // Logger::Debug("[RenderManagerDX9::GetAvailableDisplayModes] mode found: %d x %d x %d", // mode.width, // mode.height, // mode.bpp); // } // } // } }
LLWindow::LLWindowResolution* LLWindowMacOSX::getSupportedResolutions(S32 &num_resolutions) { if (!mSupportedResolutions) { CFArrayRef modes = CGDisplayAvailableModes(mDisplay); if(modes != NULL) { CFIndex index, cnt; mSupportedResolutions = new LLWindowResolution[MAX_NUM_RESOLUTIONS]; mNumSupportedResolutions = 0; // Examine each mode cnt = CFArrayGetCount( modes ); for ( index = 0; (index < cnt) && (mNumSupportedResolutions < MAX_NUM_RESOLUTIONS); index++ ) { // Pull the mode dictionary out of the CFArray CFDictionaryRef mode = (CFDictionaryRef)CFArrayGetValueAtIndex( modes, index ); long width = getDictLong(mode, kCGDisplayWidth); long height = getDictLong(mode, kCGDisplayHeight); long bits = getDictLong(mode, kCGDisplayBitsPerPixel); if(bits == BITS_PER_PIXEL && width >= 800 && height >= 600) { BOOL resolution_exists = FALSE; for(S32 i = 0; i < mNumSupportedResolutions; i++) { if (mSupportedResolutions[i].mWidth == width && mSupportedResolutions[i].mHeight == height) { resolution_exists = TRUE; } } if (!resolution_exists) { mSupportedResolutions[mNumSupportedResolutions].mWidth = width; mSupportedResolutions[mNumSupportedResolutions].mHeight = height; mNumSupportedResolutions++; } } } } } num_resolutions = mNumSupportedResolutions; return mSupportedResolutions; }
QuartzToggler::QuartzToggler() : originalMode(NULL), activeDspys(NULL), widgetScreen(0), isFull(false) { CGDisplayCount dspyCnt = 0; CGGetActiveDisplayList(0, 0, &dspyCnt); activeDspys = new CGDirectDisplayID[dspyCnt]; CGGetActiveDisplayList(dspyCnt, activeDspys, &dspyCnt); infoVector.resize(dspyCnt); fullResIndex.resize(dspyCnt); fullRateIndex.resize(dspyCnt); for (CGDisplayCount i = 0; i < dspyCnt; ++i) { CGDirectDisplayID display = activeDspys[i]; CFDictionaryRef currentMode = CGDisplayCurrentMode(display); CFArrayRef modesArray = CGDisplayAvailableModes(display); CFIndex numModes = CFArrayGetCount(modesArray); CFNumberRef bpp = static_cast<CFNumberRef>(CFDictionaryGetValue(currentMode, kCGDisplayBitsPerPixel)); for (CFIndex j = 0; j < numModes; ++j) { CFDictionaryRef mode = static_cast<CFDictionaryRef>(CFArrayGetValueAtIndex(modesArray, j)); if (CFNumberCompare(bpp, static_cast<CFNumberRef>(CFDictionaryGetValue(mode, kCGDisplayBitsPerPixel)), NULL) == kCFCompareEqualTo) { addMode(mode, infoVector[i], NULL, NULL); } } } originalMode = CGDisplayCurrentMode(activeDspys[widgetScreen]); for (CGDisplayCount i = 0; i < dspyCnt; ++i) { unsigned resIndex = 0; unsigned rateIndex = 0; addMode(CGDisplayCurrentMode(activeDspys[i]), infoVector[i], &resIndex, &rateIndex); fullResIndex[i] = resIndex; fullRateIndex[i] = rateIndex; } }
wxArrayVideoModes wxDisplayImplMacOSX::GetModes(const wxVideoMode& mode) const { wxArrayVideoModes resultModes; CFArrayRef theArray = CGDisplayAvailableModes( m_id ); for (CFIndex i = 0; i < CFArrayGetCount(theArray); ++i) { CFDictionaryRef theValue = (CFDictionaryRef) CFArrayGetValueAtIndex( theArray, i ); wxVideoMode theMode( wxCFDictKeyToInt( theValue, kCGDisplayWidth ), wxCFDictKeyToInt( theValue, kCGDisplayHeight ), wxCFDictKeyToInt( theValue, kCGDisplayBitsPerPixel ), wxCFDictKeyToInt( theValue, kCGDisplayRefreshRate )); if (theMode.Matches( mode )) resultModes.Add( theMode ); } return resultModes; }
static int Open(void * hwnd) { CGDirectDisplayID l[32]; CGDisplayCount count; CGGetActiveDisplayList (sizeof(l), l, &count); SYS_ASSERT(g_pAGLC == 0); SYS_ASSERT(hwnd); static Rect rect; g_pRect = ▭ g_hWnd = (WindowPtr) hwnd; #ifdef _DEBUG // Debug in multiple monitor. Use the secondary monitor for rendering g_cgDisplayID = l[count-1]; #else g_cgDisplayID = CGMainDisplayID (); #endif g_cgPrevDisplayMode = CGDisplayCurrentMode (g_cgDisplayID); g_cgOldDisplayModeRestore = 0; g_cgDisplayModeList = CGDisplayAvailableModes (g_cgDisplayID); return 0; }
bool OpenGLApp::initAPI(){ initialMode = CGDisplayCurrentMode(kCGDirectMainDisplay); dmodes = CGDisplayAvailableModes(kCGDirectMainDisplay); int count = CFArrayGetCount(dmodes); Array <DispRes> modes; int foundMode = -1; for (int i = 0; i < count; i++){ CFDictionaryRef mode = (CFDictionaryRef) CFArrayGetValueAtIndex(dmodes, i); long bitsPerPixel = GetDictionaryLong(mode, kCGDisplayBitsPerPixel); Boolean safeForHardware = GetDictionaryBoolean(mode, kCGDisplayModeIsSafeForHardware); Boolean stretched = GetDictionaryBoolean(mode, kCGDisplayModeIsStretched); if (bitsPerPixel < colorBits || !safeForHardware || stretched) continue; long width = GetDictionaryLong(mode, kCGDisplayWidth); long height = GetDictionaryLong(mode, kCGDisplayHeight); long refreshRate = GetDictionaryLong(mode, kCGDisplayRefreshRate); // printf("Mode: %dx%dx%d @ %d\n", width, height, bitsPerPixel, refreshRate); if (width >= 640 && height >= 480){ modes.add(newRes(width, height, i)); if (width == fullscreenWidth && height == fullscreenHeight){ foundMode = i; } } } resolution->clear(); modes.sort(dComp); char str[64]; for (uint i = 0; i < modes.getCount(); i++){ sprintf(str, "%dx%d", modes[i].w, modes[i].h); int index = resolution->addItemUnique(str); if (modes[i].index == foundMode) resolution->selectItem(index); } if (fullscreen){ if (foundMode < 0 || CGDisplaySwitchToMode(kCGDirectMainDisplay, (CFDictionaryRef) CFArrayGetValueAtIndex(dmodes, foundMode)) != kCGErrorSuccess){ sprintf(str, "Couldn't set fullscreen to %dx%d.", fullscreenWidth, fullscreenHeight); ErrorMsg(str); fullscreen = false; } } Rect rect; if (fullscreen){ rect.left = 0; rect.top = 0; } else { long w = GetDictionaryLong(initialMode, kCGDisplayWidth); long h = GetDictionaryLong(initialMode, kCGDisplayHeight); rect.left = (w - width) / 2; rect.top = (h - height) / 2; } rect.right = rect.left + width; rect.bottom = rect.top + height; WindowAttributes attributes = fullscreen? (kWindowNoTitleBarAttribute | kWindowNoShadowAttribute) : (kWindowStandardDocumentAttributes | kWindowStandardHandlerAttribute); OSStatus error = CreateNewWindow(kDocumentWindowClass, attributes, &rect, &window); if (error != noErr || window == NULL){ ErrorMsg("Couldn't create window"); return false; } GDHandle screen = GetGWorldDevice(GetWindowPort(window)); if (screen == NULL){ ErrorMsg("Couldn't get device"); ReleaseWindow(window); return false; } AGLPixelFormat pixelFormat; while (true){ GLint attributes[] = { fullscreen? AGL_FULLSCREEN : AGL_WINDOW, AGL_RGBA, AGL_DOUBLEBUFFER, AGL_RED_SIZE, 8, AGL_GREEN_SIZE, 8, AGL_BLUE_SIZE, 8, AGL_ALPHA_SIZE, (colorBits > 24)? 8 : 0, AGL_DEPTH_SIZE, depthBits, AGL_STENCIL_SIZE, stencilBits, AGL_SAMPLE_BUFFERS_ARB, (antiAliasSamples > 0), AGL_SAMPLES_ARB, antiAliasSamples, AGL_NONE }; pixelFormat = aglChoosePixelFormat(&screen, 1, attributes); if (pixelFormat != NULL) break; antiAliasSamples -= 2; if (antiAliasSamples < 0){ ErrorMsg("No suitable pixel format"); ReleaseWindow(window); return false; } } glContext = aglCreateContext(pixelFormat, NULL); aglDestroyPixelFormat(pixelFormat); if (glContext == NULL){ ErrorMsg("Couldn't create context"); ReleaseWindow(window); return false; } if (fullscreen){ CGCaptureAllDisplays(); aglSetFullScreen(glContext, 0, 0, 0, 0); } else { if (!aglSetDrawable(glContext, GetWindowPort(window))){ ErrorMsg("Couldn't set drawable"); aglDestroyContext(glContext); ReleaseWindow(window); return false; } } if (!aglSetCurrentContext(glContext)){ ErrorMsg("Couldn't make context current"); aglDestroyContext(glContext); ReleaseWindow(window); return false; } setWindowTitle(getTitle()); ShowWindow(window); initExtensions(); if (antiAliasSamples > 0){ glEnable(GL_MULTISAMPLE_ARB); } if (fullscreen) captureMouse(!configDialog->isVisible()); renderer = new OpenGLRenderer(glContext); renderer->setViewport(width, height); antiAlias->selectItem(antiAliasSamples / 2); linearClamp = renderer->addSamplerState(LINEAR, CLAMP, CLAMP, CLAMP); defaultFont = renderer->addFont("../Textures/Fonts/Future.dds", "../Textures/Fonts/Future.font", linearClamp); blendSrcAlpha = renderer->addBlendState(SRC_ALPHA, ONE_MINUS_SRC_ALPHA); noDepthTest = renderer->addDepthState(false, false); noDepthWrite = renderer->addDepthState(true, false); cullNone = renderer->addRasterizerState(CULL_NONE); cullBack = renderer->addRasterizerState(CULL_BACK); cullFront = renderer->addRasterizerState(CULL_FRONT); return true; }
bool macosxAppendAvailableScreenResolutions(QList<QSize> &resolutions, QSize minSize, QPoint screenPoint) { CGDirectDisplayID display = displayAtPoint(screenPoint); if (display == kCGNullDirectDisplay) { return false; } #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 bool modern = (CGDisplayCopyAllDisplayModes != NULL); // where 'modern' means >= 10.6 #endif CFArrayRef displayModes; #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 if (modern) { displayModes = CGDisplayCopyAllDisplayModes(display, NULL); } else #endif { displayModes = CGDisplayAvailableModes(display); } #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 CFStringRef currentPixelEncoding = NULL; #endif double currentRefreshRate; int curBPP, curBPS, curSPP; #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 if (modern) { CGDisplayModeRef currentDisplayMode = CGDisplayCopyDisplayMode(display); currentRefreshRate = CGDisplayModeGetRefreshRate(currentDisplayMode); currentPixelEncoding = CGDisplayModeCopyPixelEncoding(currentDisplayMode); CFRelease(currentDisplayMode); } else #endif { CFDictionaryRef currentDisplayMode = CGDisplayCurrentMode(display); dictget(currentDisplayMode, Double, kCGDisplayRefreshRate, ¤tRefreshRate); dictget(currentDisplayMode, Int, kCGDisplayBitsPerPixel, &curBPP); dictget(currentDisplayMode, Int, kCGDisplayBitsPerSample, &curBPS); dictget(currentDisplayMode, Int, kCGDisplaySamplesPerPixel, &curSPP); } for (CFIndex j = 0, c = CFArrayGetCount(displayModes); j < c; j++) { int width, height; double refreshRate; bool pixelEncodingsEqual; #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 if (modern) { CGDisplayModeRef displayMode = (CGDisplayModeRef)CFArrayGetValueAtIndex(displayModes, j); width = (int)CGDisplayModeGetWidth(displayMode); height = (int)CGDisplayModeGetHeight(displayMode); refreshRate = CGDisplayModeGetRefreshRate(displayMode); CFStringRef pixelEncoding = CGDisplayModeCopyPixelEncoding(displayMode); pixelEncodingsEqual = (CFStringCompare(pixelEncoding, currentPixelEncoding, 0) == kCFCompareEqualTo); CFRelease(pixelEncoding); } else #endif { CFDictionaryRef displayMode = (CFDictionaryRef)CFArrayGetValueAtIndex(displayModes, j); dictget(displayMode, Int, kCGDisplayWidth, &width); dictget(displayMode, Int, kCGDisplayHeight, &height); dictget(displayMode, Double, kCGDisplayRefreshRate, &refreshRate); int bpp, bps, spp; dictget(displayMode, Int, kCGDisplayBitsPerPixel, &bpp); dictget(displayMode, Int, kCGDisplayBitsPerSample, &bps); dictget(displayMode, Int, kCGDisplaySamplesPerPixel, &spp); pixelEncodingsEqual = (bpp == curBPP && bps == curBPS && spp == curSPP); } QSize res(width, height); if (!resolutions.contains(res) && width >= minSize.width() && height >= minSize.height() && refreshRate == currentRefreshRate && pixelEncodingsEqual) { resolutions += res; } } #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 if (modern) { CFRelease(currentPixelEncoding); CFRelease(displayModes); } #endif return true; }
static Bool QuartzRandREnumerateModes(ScreenPtr pScreen, QuartzModeCallback callback, void *data) { Bool retval = FALSE; QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen); /* Just an 800x600 fallback if we have no attached heads */ if (pQuartzScreen->displayIDs) { CFDictionaryRef curModeRef, modeRef; long curBpp; CFArrayRef modes; QuartzModeInfo modeInfo; int i; CGDirectDisplayID screenId = pQuartzScreen->displayIDs[0]; curModeRef = CGDisplayCurrentMode(screenId); if (!curModeRef) return FALSE; curBpp = getDictLong(curModeRef, kCGDisplayBitsPerPixel); modes = CGDisplayAvailableModes(screenId); if (!modes) return FALSE; for (i = 0; i < CFArrayGetCount(modes); i++) { int cb; modeRef = (CFDictionaryRef)CFArrayGetValueAtIndex(modes, i); /* Skip modes that are not usable on the current display or have a different pixel encoding than the current mode. */ if (((unsigned long)getDictLong(modeRef, kCGDisplayIOFlags) & kDisplayModeUsableFlags) != kDisplayModeUsableFlags) continue; if (getDictLong(modeRef, kCGDisplayBitsPerPixel) != curBpp) continue; QuartzRandRGetModeInfo(modeRef, &modeInfo); modeInfo.ref = (void *)modeRef; cb = callback(pScreen, &modeInfo, data); if (cb == CALLBACK_CONTINUE) retval = TRUE; else if (cb == CALLBACK_SUCCESS) return TRUE; else if (cb == CALLBACK_ERROR) return FALSE; } } switch (callback(pScreen, &pQuartzScreen->rootlessMode, data)) { case CALLBACK_SUCCESS: return TRUE; case CALLBACK_ERROR: return FALSE; case CALLBACK_CONTINUE: retval = TRUE; default: break; } switch (callback(pScreen, &pQuartzScreen->fullscreenMode, data)) { case CALLBACK_SUCCESS: return TRUE; case CALLBACK_ERROR: return FALSE; case CALLBACK_CONTINUE: retval = TRUE; default: break; } return retval; }
//////////////////////////////////////////////////////////// /// Note : /// Starting with 10.6, CGDisplayModeRef and CGDisplayCopyAllDisplayModes /// should be used instead of CFDictionaryRef and CGDisplayAvailableModes. /// //////////////////////////////////////////////////////////// std::vector<VideoMode> VideoModeImpl::getFullscreenModes() { #if MAC_OS_X_VERSION_MAX_ALLOWED < 1060 std::vector<VideoMode> modes; // Retrieve array of dictionaries representing display modes. CFArrayRef displayModes = CGDisplayAvailableModes(CGMainDisplayID()); if (displayModes == NULL) { sf::err() << "Couldn't get VideoMode for main display."; return modes; } // Loop on each mode and convert it into a sf::VideoMode object. CFIndex const modesCount = CFArrayGetCount(displayModes); for (CFIndex i = 0; i < modesCount; i++) { CFDictionaryRef dictionary = (CFDictionaryRef)CFArrayGetValueAtIndex(displayModes, i); VideoMode mode = convertCGModeToSFMode(dictionary); // If not yet listed we add it to our modes array. if (std::find(modes.begin(), modes.end(), mode) == modes.end()) { modes.push_back(mode); } } return modes; #else // MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 std::vector<VideoMode> modes; // Retrieve all modes available for main screen only. CFArrayRef cgmodes = CGDisplayCopyAllDisplayModes(CGMainDisplayID(), NULL); if (cgmodes == NULL) { sf::err() << "Couldn't get VideoMode for main display."; return modes; } // Loop on each mode and convert it into a sf::VideoMode object. CFIndex const modesCount = CFArrayGetCount(cgmodes); for (CFIndex i = 0; i < modesCount; i++) { CGDisplayModeRef cgmode = (CGDisplayModeRef)CFArrayGetValueAtIndex(cgmodes, i); VideoMode mode = convertCGModeToSFMode(cgmode); // If not yet listed we add it to our modes array. if (std::find(modes.begin(), modes.end(), mode) == modes.end()) { modes.push_back(mode); } } // Clean up memory. CFRelease(cgmodes); return modes; #endif }