1/* 2 * Copyright (c) 2008 Apple Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23/* 24cc -o /tmp/iodt graphics.subproj/IODisplayTest.c -framework CoreGraphics -Wall -undefined warning -g 25*/ 26 27#include <CoreFoundation/CoreFoundation.h> 28#include <CoreGraphics/CoreGraphicsPrivate.h> 29#include <IOKit/graphics/IOGraphicsLib.h> 30#include <stdlib.h> 31 32#include "IODisplayInterface.h" 33 34void KeyArrayCallback(const void *key, const void *value, void *context) 35{ 36 CFArrayAppendValue(context, key); 37} 38 39int main(int argc, char * argv[]) 40{ 41 io_service_t service; 42 CFDictionaryRef dict; 43 CFDictionaryRef names; 44 CFArrayRef langKeys; 45 CFArrayRef orderLangKeys; 46 CFNumberRef num; 47 CGSError err; 48 SInt32 numValue; 49 int i; 50 CGSDisplayNumber max; 51 CGSDisplayID displayIDs[8]; 52 CGSInitialize(); 53 54 err = CGSGetDisplayList(8, displayIDs, &max); 55 if(err != kCGSErrorSuccess) 56 exit(1); 57 if(max > 8) 58 max = 8; 59 60 for(i = 0; i < max; i++ ) { 61 err = CGSServiceForDisplayNumber(displayIDs[i], &service); 62 if(err != kCGSErrorSuccess) 63 continue; 64 65 dict = IODisplayCreateInfoDictionary(service, kNilOptions ); 66 if( dict) { 67 printf("Display %d\n", i); 68 69 num = CFDictionaryGetValue(dict, CFSTR(kDisplayVendorID)); 70 if(num) { 71 CFNumberGetValue(num, kCFNumberSInt32Type, &numValue); 72 printf("vendorID %ld\n", numValue); 73 } 74 num = CFDictionaryGetValue(dict, CFSTR(kDisplayProductID)); 75 if(num) { 76 CFNumberGetValue(num, kCFNumberSInt32Type, &numValue); 77 printf("productID %ld\n", numValue); 78 } 79 80 names = CFDictionaryGetValue(dict, CFSTR(kDisplayProductName)); 81 langKeys = CFArrayCreateMutable(kCFAllocatorDefault, 0, 82 &kCFTypeArrayCallBacks); 83 CFDictionaryApplyFunction(names, KeyArrayCallback, (void *) langKeys); 84 orderLangKeys = CFBundleCopyPreferredLocalizationsFromArray(langKeys); 85 CFRelease(langKeys); 86 if(orderLangKeys && CFArrayGetCount(orderLangKeys)) { 87 char cName[256]; 88 CFStringRef langKey; 89 CFStringRef localName; 90 91 langKey = CFArrayGetValueAtIndex(orderLangKeys, 0); 92 localName = CFDictionaryGetValue(names, langKey); 93 CFStringGetCString(localName, cName, sizeof(cName), 94 CFStringGetSystemEncoding()); 95 printf("local name \"%s\"\n", cName); 96 } 97 CFRelease(orderLangKeys); 98 99 printf("\nAll info:\n"); 100 CFShow(dict); 101 102 CFRelease(dict); 103 } 104 105 // -- 106 { 107 IOCFPlugInInterface ** interface; 108 IODisplayCreateInterface( service, kNilOptions, 109 kIODisplayControlInterfaceID, &interface ); 110 } 111 { 112 CFMutableDictionaryRef dict; 113 CFNumberRef num; 114 SInt32 value; 115 116 dict = CFDictionaryCreateMutable( kCFAllocatorDefault, 0, 117 &kCFTypeDictionaryKeyCallBacks, 118 &kCFTypeDictionaryValueCallBacks ); 119 120 for( value = 0; value < 0x60; value++) { 121 num = CFNumberCreate( kCFAllocatorDefault, kCFNumberSInt32Type, &value ); 122 CFDictionarySetValue( dict, CFSTR("contrast"), num ); 123 CFRelease(num); 124 err = IODisplaySetParameters( service, kNilOptions, dict ); 125 } 126 CFRelease(dict); 127 } 128 // -- 129 } 130 131 exit(0); 132 return(0); 133} 134 135