bool DisplayResOSX::SwitchToVideoMode(int width, int height, double refreshrate) { CGDirectDisplayID d = GetOSXDisplay(MythDisplay::GetWindowID()); CFDictionaryRef dispMode = NULL; boolean_t match = 0; // find mode that matches the desired size if (refreshrate) dispMode = CGDisplayBestModeForParametersAndRefreshRate( d, 32, width, height, (CGRefreshRate)((short)refreshrate), &match); if (!match) dispMode = CGDisplayBestModeForParameters(d, 32, width, height, &match); if (!match) dispMode = CGDisplayBestModeForParameters(d, 16, width, height, &match); if (!match) return false; // switch mode and return success CGDisplayCapture(d); CGDisplayConfigRef cfg; CGBeginDisplayConfiguration(&cfg); CGConfigureDisplayFadeEffect(cfg, 0.3f, 0.5f, 0, 0, 0); CGConfigureDisplayMode(cfg, d, dispMode); CGError err = CGCompleteDisplayConfiguration(cfg, kCGConfigureForAppOnly); CGDisplayRelease(d); return (err == kCGErrorSuccess); }
static void gfx_ctx_cgl_destroy(void *data) { gfx_ctx_cgl_data_t *cgl = (gfx_ctx_cgl_data_t*)data; if (cgl->glCtx) { CGLSetCurrentContext(NULL); CGLDestroyContext(cgl->glCtx); } if (cgl->displayID) CGDisplayRelease(cgl->displayID); if (cgl) free(cgl); }
nglVideoMode::~nglVideoMode() { #ifdef __NGL_MACHO__ CGDisplayRelease( (CGDirectDisplayID)mDisplay ) ; #endif }
//void doFadeOperation(int operation, float time, bool sync) // from SMFL void doFadeOperation(int operation, float time, bool sync) { static CGDisplayFadeReservationToken prevToken = kCGDisplayFadeReservationInvalidToken; CGDisplayFadeReservationToken token = prevToken; CGError result = 0, capture = 0; if (operation == FillScreen) { // Get access for the fade operation result = CGAcquireDisplayFadeReservation((int)(3 + time), &token); if (!result) { // Capture display but do not fill the screen with black // so that we can see the fade operation capture = CGDisplayCaptureWithOptions(kCGDirectMainDisplay, kCGCaptureNoFill); if (!capture) { // Do the increasing fade operation CGDisplayFade(token, time, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0.0f, 0.0f, 0.0f, sync); // Now, release the non black-filling capture CGDisplayRelease(kCGDirectMainDisplay); // And capture with filling // so that we don't see the switching in the meantime CGDisplayCaptureWithOptions(kCGDirectMainDisplay, kCGCaptureNoOptions); } prevToken = token; } } else if (operation == CleanScreen) { // Get access for the fade operation if (token == kCGDisplayFadeReservationInvalidToken) result = CGAcquireDisplayFadeReservation((int)(3 + time), &token); if (!result) { if (!capture) { // Release the black-filling capture CGDisplayRelease(kCGDirectMainDisplay); // Capture the display but do not fill with black (still for the fade operation) CGDisplayCaptureWithOptions(kCGDirectMainDisplay, kCGCaptureNoFill); // Do the decreasing fading CGDisplayFade(token, time, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0.0f, 0.0f, 0.0f, sync); // Release the fade operation token CGReleaseDisplayFadeReservation(token); // Invalidate the given token prevToken = kCGDisplayFadeReservationInvalidToken; } // Release the captured display CGDisplayRelease(kCGDirectMainDisplay); } } }