From 5e01f1a55c0e0c9e04ec64f9da0efea77dcc6a4b Mon Sep 17 00:00:00 2001 From: Jeff Muizelaar Date: Sat, 3 Oct 2009 14:33:55 -0400 Subject: [PATCH] Bug 514932. Fix color profile retrieval on OS X 10.6. r=joshmoz CMGetDeviceProfile(cmDisplayDeviceClass, cmDefaultDeviceID, cmDefaultProfileID, &device); returns cmDeviceNotRegistered on 10.6 so we need to use a different method to get the profile. --- gfx/thebes/src/gfxPlatformMac.cpp | 51 +++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/gfx/thebes/src/gfxPlatformMac.cpp b/gfx/thebes/src/gfxPlatformMac.cpp index e4fb76c670d..43cc101d5e6 100644 --- a/gfx/thebes/src/gfxPlatformMac.cpp +++ b/gfx/thebes/src/gfxPlatformMac.cpp @@ -401,20 +401,49 @@ gfxPlatformMac::ReadAntiAliasingThreshold() qcms_profile * gfxPlatformMac::GetPlatformCMSOutputProfile() { - CMProfileLocation device; - CMError err = CMGetDeviceProfile(cmDisplayDeviceClass, - cmDefaultDeviceID, - cmDefaultProfileID, - &device); + qcms_profile *profile = nsnull; + CMProfileRef cmProfile; + CMProfileLocation *location; + UInt32 locationSize; + + /* There a number of different ways that we could try to get a color + profile to use. On 10.5 all of these methods seem to give the same + results. On 10.6, the results are different and the following method, + using CGMainDisplayID() seems to best match what we are looking for. + Currently, both Google Chrome and Qt4 use a similar method. + + CMTypes.h describes CMDisplayIDType: + "Data type for ColorSync DisplayID reference + On 8 & 9 this is a AVIDType + On X this is a CGSDisplayID" + + CGMainDisplayID gives us a CGDirectDisplayID which presumeably + corresponds directly to a CGSDisplayID */ + CGDirectDisplayID displayID = CGMainDisplayID(); + + CMError err = CMGetProfileByAVID(static_cast(displayID), &cmProfile); if (err != noErr) return nsnull; - qcms_profile *profile = nsnull; - switch (device.locType) { + // get the size of location + err = NCMGetProfileLocation(cmProfile, NULL, &locationSize); + if (err != noErr) + return nsnull; + + // allocate enough room for location + location = static_cast(malloc(locationSize)); + if (!location) + goto fail_close; + + err = NCMGetProfileLocation(cmProfile, location, &locationSize); + if (err != noErr) + goto fail_location; + + switch (location->locType) { #ifndef __LP64__ case cmFileBasedProfile: { FSRef fsRef; - if (!FSpMakeFSRef(&device.u.fileLoc.spec, &fsRef)) { + if (!FSpMakeFSRef(&location->u.fileLoc.spec, &fsRef)) { char path[512]; if (!FSRefMakePath(&fsRef, reinterpret_cast(path), sizeof(path))) { profile = qcms_profile_from_path(path); @@ -429,7 +458,7 @@ gfxPlatformMac::GetPlatformCMSOutputProfile() } #endif case cmPathBasedProfile: - profile = qcms_profile_from_path(device.u.pathLoc.path); + profile = qcms_profile_from_path(location->u.pathLoc.path); #ifdef DEBUG_tor if (profile) fprintf(stderr, @@ -444,6 +473,10 @@ gfxPlatformMac::GetPlatformCMSOutputProfile() break; } +fail_location: + free(location); +fail_close: + CMCloseProfile(cmProfile); return profile; }