int main(int argc, char * argv[])
{
    IOReturn            err;
    CGDirectDisplayID   dspy = CGMainDisplayID();
    io_service_t        framebuffer;
    CGRect              bounds;
    vm_address_t        buffer;
    vm_size_t           size, rowBytes;

    framebuffer = CGDisplayIOServicePort(dspy);
    assert (framebuffer != MACH_PORT_NULL);
    dspy = CGMainDisplayID();
    bounds = CGDisplayBounds(dspy);
    rowBytes = CGDisplayBytesPerRow(dspy);

    err = IOAccelReadFramebuffer(framebuffer, bounds.size.width, bounds.size.height, rowBytes,
                                 &buffer, &size);
    if (kIOReturnSuccess == err)
    {
        fprintf(stderr, "writing 0x%x bytes from 0x%x\n", size, buffer);
        write(STDOUT_FILENO, (const void *) buffer, size);
        vm_deallocate(mach_task_self(), buffer, size);
    }
    return (0);
}
Beispiel #2
0
int main ( int argc, const char * argv[])
{
    CGDirectDisplayID displays[ MAX_DISPLAYS ];
    CGDisplayCount    displayCount = 0;
    
    CGDisplayErr err =
    CGGetOnlineDisplayList( MAX_DISPLAYS, displays, &displayCount );
    
    if ( err == kCGErrorSuccess ) {
        int i;
        
        for ( i = 0; i < displayCount; i++ ) {
            io_service_t service = CGDisplayIOServicePort( displays[ i ]);
            
            if ( service )
                IOServiceRequestProbe( service, kIOFBUserRequestProbe );
        }
    } else {
        fprintf( stderr, "CGGetOnlineDisplayList returned error code %d\n",
                 ( int )err );
        return ( int )err;
    }

    
    return EXIT_SUCCESS;
}
Beispiel #3
0
int
main(int argc, char **argv)
{
    int  i;
    long angle = 0;
   
    io_service_t      service;
    CGDisplayErr      dErr;
    CGDirectDisplayID targetDisplay = 0;
    IOOptionBits      options;
   
    while ((i = getopt(argc, argv, "d:limr:")) != -1) {
        switch (i) {
        case 'd':
            targetDisplay = (CGDirectDisplayID)strtol(optarg, NULL, 16);
            if (targetDisplay == 0)
                targetDisplay = CGMainDisplayID();
            break;
        case 'l':
            listDisplays();
            break;
        case 'i':
            infoDisplays();
            break;
        case 'm':
            setMainDisplay(targetDisplay);
            break;
        case 'r':
            angle = strtol(optarg, NULL, 10);
            break;
        default:
            break;
        }
    }
   
    if (targetDisplay == 0)
        usage();
   
    options = angle2options(angle);
   
    // Get the I/O Kit service port of the target display
    // Since the port is owned by the graphics system, we should not destroy it
    service = CGDisplayIOServicePort(targetDisplay);
   
    // We will get an error if the target display doesn't support the
    // kIOFBSetTransform option for IOServiceRequestProbe()
    dErr = IOServiceRequestProbe(service, options);
    if (dErr != kCGErrorSuccess) {
        fprintf(stderr, "IOServiceRequestProbe: error %d\n", dErr);
        exit(1);
    }
   
    exit(0);
}
void setDisplayBrightness(float brightness)
{
  CGDisplayErr      dErr;
  io_service_t      service;
  CGDirectDisplayID targetDisplay;
  CFStringRef key = CFSTR(kIODisplayBrightnessKey);

  targetDisplay = CGMainDisplayID();
  service = CGDisplayIOServicePort(targetDisplay);

  dErr = IODisplaySetFloatParameter(service, kNilOptions, key, brightness);

}
Beispiel #5
0
float ArchHooks_MacOSX::GetDisplayAspectRatio()
{
	io_connect_t displayPort = CGDisplayIOServicePort( CGMainDisplayID() );
	CFDictionaryRef dict = IODisplayCreateInfoDictionary( displayPort, 0 );
	int width = GetIntValue( CFDictionaryGetValue(dict, CFSTR(kDisplayHorizontalImageSize)) );
	int height = GetIntValue( CFDictionaryGetValue(dict, CFSTR(kDisplayVerticalImageSize)) );

	CFRelease( dict );

	if( width && height )
		return float(width)/height;
	return 4/3.f;
}	
float getDisplayBrightness(void)
{
  CGDisplayErr      dErr;
  io_service_t      service;
  CGDirectDisplayID targetDisplay;

  CFStringRef key = CFSTR(kIODisplayBrightnessKey);
  float brightness = HUGE_VALF;

  targetDisplay = CGMainDisplayID();
  service = CGDisplayIOServicePort(targetDisplay);

  dErr = IODisplayGetFloatParameter(service, kNilOptions, key, &brightness);

  return brightness;
}
void gdip_get_display_dpi_carbon (float *h_dpi, float *v_dpi) {
	if (getenv ("MONO_MWF_MAC_DETECT_DPI") != NULL) {
		CFDictionaryRef mode_dict = CGDisplayCurrentMode (kCGDirectMainDisplay);
		io_connect_t display_port = CGDisplayIOServicePort (kCGDirectMainDisplay);
		CFDictionaryRef display_dict = IOCreateDisplayInfoDictionary (display_port, 0);
		const float mmpi = 25.4;
		float h_size = (float) gdip_get_int_from_dict_for_key (display_dict, CFSTR (kDisplayHorizontalImageSize)) / mmpi;
		float v_size = (float) gdip_get_int_from_dict_for_key (display_dict, CFSTR (kDisplayVerticalImageSize)) / mmpi;

		*h_dpi = (float) gdip_get_int_from_dict_for_key (mode_dict, kCGDisplayWidth) / h_size; 
		*v_dpi = (float) gdip_get_int_from_dict_for_key (mode_dict, kCGDisplayHeight) / v_size; 

		CFRelease (display_dict);
	} else {
		*h_dpi = *v_dpi = 96.0f;
	}
}
int main( int argc, char * argv[] )
{
    kern_return_t kr;
    io_service_t  framebuffer, interface;
    IOOptionBits  bus;
    IOItemCount   busCount;

    framebuffer = CGDisplayIOServicePort(CGMainDisplayID());

    {
        io_string_t path;
        kr = IORegistryEntryGetPath(framebuffer, kIOServicePlane, path);
        assert( KERN_SUCCESS == kr );
        printf("\nUsing device: %s\n", path);

        kr = IOFBGetI2CInterfaceCount( framebuffer, &busCount );
        assert( kIOReturnSuccess == kr );
    
        for( bus = 0; bus < busCount; bus++ )
        {
            IOI2CConnectRef  connect;
    
            kr = IOFBCopyI2CInterfaceForBus(framebuffer, bus, &interface);
            if( kIOReturnSuccess != kr)
                continue;
    
            kr = IOI2CInterfaceOpen( interface, kNilOptions, &connect );
    
            IOObjectRelease(interface);
            assert( kIOReturnSuccess == kr );
            if( kIOReturnSuccess != kr)
                continue;
    
            printf("\nEDID using bus %ld:\n", bus);
            EDIDTest( connect );
    
            printf("\niTV using bus %ld:\n", bus);
            iTVTest( connect );
    
            IOI2CInterfaceClose( connect, kNilOptions );
        }
    }

    exit(0);
    return(0);
}
Beispiel #9
0
int main(int argc, char **argv)
{
    CGDirectDisplayID targetDisplayId = CGMainDisplayID();
    io_service_t service = CGDisplayIOServicePort(targetDisplayId);
    CFStringRef key = CFSTR(kIODisplayBrightnessKey);
    int blinktime = strtof(argv[1], NULL);
    int count = 0;
    while(count <= blinktime)
    {
        IODisplaySetIntegerParameter(service, kNilOptions, key, 0);
        sleep(1);
        IODisplaySetIntegerParameter(service, kNilOptions, key, 1000);
        sleep(1);
        count++;
    }
    printf("appleblink ended \n");
    return 0;
}
PsychError SCREENReadNormalizedGammaTable(void)
{
    int		i, screenNumber, numEntries, reallutsize, physicalDisplay, outputId;
    float 	*redTable, *greenTable, *blueTable;
    double	*gammaTable;	

    //all subfunctions should have these two lines
    PsychPushHelp(useString, synopsisString, seeAlsoString);
    if(PsychIsGiveHelp()){PsychGiveHelp();return(PsychError_none);};

    PsychErrorExit(PsychCapNumOutputArgs(3));
    PsychErrorExit(PsychCapNumInputArgs(2));

    // Get optional physicalDisplay argument - It defaults to zero:
    physicalDisplay = -1;
    PsychCopyInIntegerArg(2, FALSE, &physicalDisplay);

    // Read in the screen number:
    // On OS/X we also accept screen indices for physical displays (as opposed to active dispays).
    // This only makes a difference in mirror-mode, where there is only 1 active display, but that
    // corresponds to two physical displays which can have different gamma setting requirements:
    if ((PSYCH_SYSTEM == PSYCH_OSX) && (physicalDisplay > 0)) {
        PsychCopyInIntegerArg(1, TRUE, &screenNumber);
	if (screenNumber < 1) PsychErrorExitMsg(PsychError_user, "A 'screenNumber' that is smaller than one provided, although 'physicalDisplay' flag set. This is not allowed!");

	// Invert screenNumber as a sign its a physical display, not an active display:
	screenNumber = -1 * screenNumber;
    }
    else {
        PsychCopyInScreenNumberArg(1, TRUE, &screenNumber);
    }

    if ((PSYCH_SYSTEM == PSYCH_LINUX) && (physicalDisplay > -1)) {
	// Affect one specific display output for given screen:
	outputId = physicalDisplay;
    }
    else {
	// Other OS'es, and Linux with default setting: Affect all outputs
	// for a screen.
	outputId = -1;
    }

    // Retrieve gamma table:
    PsychReadNormalizedGammaTable(screenNumber, outputId, &numEntries, &redTable, &greenTable, &blueTable);
	
    // Copy it out to runtime:
    PsychAllocOutDoubleMatArg(1, FALSE, numEntries, 3, 0, &gammaTable);

    for(i=0;i<numEntries;i++){
        gammaTable[PsychIndexElementFrom3DArray(numEntries, 3, 0, i, 0, 0)]=(double)redTable[i];
        gammaTable[PsychIndexElementFrom3DArray(numEntries, 3, 0, i, 1, 0)]=(double)greenTable[i];
        gammaTable[PsychIndexElementFrom3DArray(numEntries, 3, 0, i, 2, 0)]=(double)blueTable[i];
    }

    // Copy out optional DAC resolution value:
    PsychCopyOutDoubleArg(2, FALSE, (double) PsychGetDacBitsFromDisplay(screenNumber));
	
    // We default to the assumption that the real size of the hardware LUT is identical to
    // the size of the returned LUT:
    reallutsize = numEntries;
	
    #if PSYCH_SYSTEM == PSYCH_OSX
		// On OS-X we query the real LUT size from the OS and return that value:
		CGDirectDisplayID	displayID;
		CFMutableDictionaryRef properties;
		CFNumberRef cfGammaLength;
		SInt32 lutslotcount;
		io_service_t displayService;
		kern_return_t kr;
		CFMutableArrayRef framebufferTimings0 = 0;
		CFDataRef framebufferTimings1 = 0;
		IODetailedTimingInformationV2 *framebufferTiming = NULL;
		
		// Retrieve display handle for screen:
		PsychGetCGDisplayIDFromScreenNumber(&displayID, screenNumber);
		
		if (PsychPrefStateGet_Verbosity()>5) printf("PTB-DEBUG: Screen %i has framebuffer address %p.\n", screenNumber, CGDisplayBaseAddress(displayID));

		// Retrieve low-level IOKit service port for this display:
		displayService = CGDisplayIOServicePort(displayID);
				
		// Obtain the properties from that service
		kr = IORegistryEntryCreateCFProperties(displayService, &properties, NULL, 0);
		if((kr == kIOReturnSuccess) && ((cfGammaLength = (CFNumberRef) CFDictionaryGetValue(properties, CFSTR(kIOFBGammaCountKey)))!=NULL))
		{
			CFNumberGetValue(cfGammaLength, kCFNumberSInt32Type, &lutslotcount);
			CFRelease(properties);
			reallutsize = (int) lutslotcount;
		}
		else {
			// Failed!
			if (PsychPrefStateGet_Verbosity()>1) printf("PTB-WARNING: Failed to query real size of video LUT for screen %i! Will return safe default of %i slots.\n", screenNumber, reallutsize);
		}	

		if (PsychPrefStateGet_Verbosity()>9) {			
			CFDictionaryRef currentMode;
			CFNumberRef n;
			int modeId;
			currentMode = CGDisplayCurrentMode(displayID);
			n=CFDictionaryGetValue(currentMode, kCGDisplayMode);
			CFNumberGetValue(n, kCFNumberIntType, &modeId);
			printf("Current mode has id %i\n\n", modeId);
			kr = IORegistryEntryCreateCFProperties(displayService, &properties, NULL, 0);
			if((kr == kIOReturnSuccess) && ((framebufferTimings0 = (CFMutableArrayRef) CFDictionaryGetValue(properties, CFSTR(kIOFBDetailedTimingsKey) ) )!=NULL))
			{
				for (i=0; i<CFArrayGetCount(framebufferTimings0); i++) {
					if ((framebufferTimings1 = CFArrayGetValueAtIndex(framebufferTimings0, i)) != NULL) {
						if ((framebufferTiming = (IODetailedTimingInformationV2*) CFDataGetBytePtr(framebufferTimings1)) != NULL) {
							printf("[%i] : VActive =  %li, VBL = %li, VSYNC = %li, VSYNCWIDTH = %li , VBORDERBOT = %li, VTOTAL = %li \n", i, framebufferTiming->verticalActive, framebufferTiming->verticalBlanking, framebufferTiming->verticalSyncOffset, framebufferTiming->verticalSyncPulseWidth, framebufferTiming->verticalBorderBottom, framebufferTiming->verticalActive + framebufferTiming->verticalBlanking);
						}
					}
				}

				CFRelease(properties);
			}
			else {
				// Failed!
				if (PsychPrefStateGet_Verbosity()>1) printf("PTB-WARNING: Failed to query STUFF for screen %i --> %p!\n", screenNumber, properties);
			}	
		}
		


    #endif
	
    // Copy out optional real LUT size (number of slots):
    PsychCopyOutDoubleArg(3, FALSE, (double) reallutsize);

    return(PsychError_none);
}
int main(int argc, char * argv[])
{
    io_service_t        service;
    CGError             err;
    int                 i;
    CGDisplayCount      max;
    CGDirectDisplayID   displayIDs[8];
    uint32_t            mask;
    IOOptionBits        options;
    CFNumberRef         num;
    SInt32              value;

    err = CGGetOnlineDisplayList(8, displayIDs, &max);
    if(err != kCGErrorSuccess)
        exit(1);
    if(max > 8)
        max = 8;

    if( argc < 2)
        options = kIOFBUserRequestProbe;
    else
        options = strtol( argv[1], 0, 0 );

    if (strstr(argv[0], "rotate"))
    {
        switch (options)
        {
            case 90:
              options = kIOFBSetTransform | (kIOScaleRotate90 << 16);
              break;
            case 180:
              options = kIOFBSetTransform | (kIOScaleRotate180 << 16);
              break;
            case 270:
              options = kIOFBSetTransform | (kIOScaleRotate270 << 16);
              break;
            case 0:
            default:
              options = kIOFBSetTransform | (kIOScaleRotate0 << 16);
              break;
        }
    }

    if( argc < 3)
        mask = 0xffffffff;
    else
        mask = strtol( argv[2], 0, 0 );

    for(i = 0; i < max; i++ )
    {
        if (!(mask & (1 << i)))
            continue;

        service = CGDisplayIOServicePort(displayIDs[i]);


        num = (CFNumberRef) IORegistryEntryCreateCFProperty( service, 
                                                                CFSTR(kIOFBTransformKey),
                                                                kCFAllocatorDefault, kNilOptions);
        if (num)
          CFNumberGetValue( num, kCFNumberSInt32Type, (SInt32 *) &value );
        else
          value = 0;

        value &= kIOScaleRotateFlags;

        printf("Display %p: current transform: ", displayIDs[i]);

        switch (value)
        {
            case kIOScaleRotate90:
              printf("90\n");
              break;

            case kIOScaleRotate180:
              printf("180\n");
              break;

            case kIOScaleRotate270:
              printf("270\n");
              break;

            case kIOScaleRotate0:
            default:
              printf("0\n");
              break;
        }


        num = (CFNumberRef) IORegistryEntryCreateCFProperty( service, 
                                                                CFSTR(kIOFBProbeOptionsKey),
                                                                kCFAllocatorDefault, kNilOptions);
        if (num)
          CFNumberGetValue( num, kCFNumberSInt32Type, (SInt32 *) &value );
        else
          value = 0;
        printf("Display %p: does %ssupport kIOFBSetTransform\n", displayIDs[i], value & kIOFBSetTransform ? "" : "not ");

        if (value & kIOFBSetTransform)
        {
          err = IOServiceRequestProbe(service, options );
          printf("Display %p: IOServiceRequestProbe(%d)\n", displayIDs[i], err);
        }
    }
    
    exit(0);
    return(0);
}