| 1 | --- src/gui/painting/qpaintengine_mac.cpp.orig |
| 2 | +++ src/gui/painting/qpaintengine_mac.cpp |
| 3 | @@ -289,7 +289,7 @@ static CGMutablePathRef qt_mac_compose_path(const QPainterPath &p, float off=0) |
| 4 | } |
| 5 | |
| 6 | CGColorSpaceRef QCoreGraphicsPaintEngine::m_genericColorSpace = 0; |
| 7 | -QHash<QWidget*, CGColorSpaceRef> QCoreGraphicsPaintEngine::m_displayColorSpaceHash; // window -> color space |
| 8 | +QHash<CGDirectDisplayID, CGColorSpaceRef> QCoreGraphicsPaintEngine::m_displayColorSpaceHash; |
| 9 | bool QCoreGraphicsPaintEngine::m_postRoutineRegistered = false; |
| 10 | |
| 11 | CGColorSpaceRef QCoreGraphicsPaintEngine::macGenericColorSpace() |
| 12 | @@ -318,48 +318,31 @@ CGColorSpaceRef QCoreGraphicsPaintEngine::macGenericColorSpace() |
| 13 | |
| 14 | CGColorSpaceRef QCoreGraphicsPaintEngine::macDisplayColorSpace(const QWidget *widget) |
| 15 | { |
| 16 | - // The color space depends on which screen the widget's window is on. |
| 17 | - // widget == 0 is a spacial case where we use the main display. |
| 18 | - QWidget *window = widget ? widget->window() : 0; |
| 19 | + CGColorSpaceRef colorSpace; |
| 20 | |
| 21 | - // Check for cached color space and return if found. |
| 22 | - if (m_displayColorSpaceHash.contains(window)) |
| 23 | - return m_displayColorSpaceHash.value(window); |
| 24 | - |
| 25 | - // Find which display the window is on. |
| 26 | CGDirectDisplayID displayID; |
| 27 | - if (window == 0) { |
| 28 | + if (widget == 0) { |
| 29 | displayID = CGMainDisplayID(); |
| 30 | } else { |
| 31 | - const QRect &qrect = window->geometry(); |
| 32 | + const QRect &qrect = widget->window()->geometry(); |
| 33 | CGRect rect = CGRectMake(qrect.x(), qrect.y(), qrect.width(), qrect.height()); |
| 34 | CGDisplayCount throwAway; |
| 35 | CGDisplayErr dErr = CGGetDisplaysWithRect(rect, 1, &displayID, &throwAway); |
| 36 | if (dErr != kCGErrorSuccess) |
| 37 | - displayID = CGMainDisplayID(); |
| 38 | - } |
| 39 | - |
| 40 | - // Get the color space from the display profile. |
| 41 | - CGColorSpaceRef colorSpace = 0; |
| 42 | - CMProfileRef displayProfile = 0; |
| 43 | - CMError err = CMGetProfileByAVID((CMDisplayIDType)displayID, &displayProfile); |
| 44 | - if (err == noErr) { |
| 45 | - colorSpace = CGColorSpaceCreateWithPlatformColorSpace(displayProfile); |
| 46 | - CMCloseProfile(displayProfile); |
| 47 | + return macDisplayColorSpace(0); // fall back on main display |
| 48 | } |
| 49 | + if ((colorSpace = m_displayColorSpaceHash.value(displayID))) |
| 50 | + return colorSpace; |
| 51 | |
| 52 | - // Fallback: use generic DeviceRGB |
| 53 | + colorSpace = CGDisplayCopyColorSpace(displayID); |
| 54 | if (colorSpace == 0) |
| 55 | colorSpace = CGColorSpaceCreateDeviceRGB(); |
| 56 | |
| 57 | - // Install cleanup routines |
| 58 | + m_displayColorSpaceHash.insert(displayID, colorSpace); |
| 59 | if (!m_postRoutineRegistered) { |
| 60 | m_postRoutineRegistered = true; |
| 61 | qAddPostRoutine(QCoreGraphicsPaintEngine::cleanUpMacColorSpaces); |
| 62 | } |
| 63 | - |
| 64 | - // Cache and return. |
| 65 | - m_displayColorSpaceHash.insert(window, colorSpace); |
| 66 | return colorSpace; |
| 67 | } |
| 68 | |
| 69 | @@ -369,7 +352,7 @@ void QCoreGraphicsPaintEngine::cleanUpMacColorSpaces() |
| 70 | CFRelease(m_genericColorSpace); |
| 71 | m_genericColorSpace = 0; |
| 72 | } |
| 73 | - QHash<QWidget*, CGColorSpaceRef>::const_iterator it = m_displayColorSpaceHash.constBegin(); |
| 74 | + QHash<CGDirectDisplayID, CGColorSpaceRef>::const_iterator it = m_displayColorSpaceHash.constBegin(); |
| 75 | while (it != m_displayColorSpaceHash.constEnd()) { |
| 76 | if (it.value()) |
| 77 | CFRelease(it.value()); |
| 78 | @@ -1069,7 +1052,16 @@ void QCoreGraphicsPaintEngine::cleanup() |
| 79 | |
| 80 | void QCoreGraphicsPaintEngine::clearColorSpace(QWidget* w) |
| 81 | { |
| 82 | - m_displayColorSpaceHash.remove(w); |
| 83 | + CGDirectDisplayID displayID = CGMainDisplayID(); |
| 84 | + if (w != 0) { |
| 85 | + const QRect &qrect = w->window()->geometry(); |
| 86 | + CGRect rect = CGRectMake(qrect.x(), qrect.y(), qrect.width(), qrect.height()); |
| 87 | + CGDisplayCount throwAway; |
| 88 | + CGDisplayErr dErr = CGGetDisplaysWithRect(rect, 1, &displayID, &throwAway); |
| 89 | + if (dErr != kCGErrorSuccess) |
| 90 | + displayID = CGMainDisplayID(); |
| 91 | + } |
| 92 | + m_displayColorSpaceHash.remove(displayID); |
| 93 | } |
| 94 | |
| 95 | CGContextRef |
| 96 | --- src/gui/painting/qpaintengine_mac_p.h.orig |
| 97 | +++ src/gui/painting/qpaintengine_mac_p.h |
| 98 | @@ -135,7 +135,7 @@ protected: |
| 99 | private: |
| 100 | static bool m_postRoutineRegistered; |
| 101 | static CGColorSpaceRef m_genericColorSpace; |
| 102 | - static QHash<QWidget*, CGColorSpaceRef> m_displayColorSpaceHash; // window -> color space |
| 103 | + static QHash<CGDirectDisplayID, CGColorSpaceRef> m_displayColorSpaceHash; |
| 104 | static void cleanUpMacColorSpaces(); |
| 105 | Q_DISABLE_COPY(QCoreGraphicsPaintEngine) |
| 106 | }; |