CoreText: Resolve color scheme (dark mode) via the platform theme
We might be drawing glyphs outside the main thread, which triggers the main thread checker for our access to NSApplication from qt_mac_applicationIsInDarkMode(). Change the CoreText font engine to pull out this information from the theme instead, and teach the theme to only updates its color scheme on the main thread. Change-Id: I02be713d9705c6e0c21107db7f7de039182f601d Reviewed-by: Doris Verria <doris.verria@qt.io> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io> (cherry picked from commit 6cf4c5b98fb0e3f30379d79003ab587aadebbce7) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
c462d33d3d
commit
d514557091
@ -12,6 +12,8 @@
|
||||
#include <QtGui/qpainterpath.h>
|
||||
#include <private/qcoregraphics_p.h>
|
||||
#include <private/qimage_p.h>
|
||||
#include <private/qguiapplication_p.h>
|
||||
#include <qpa/qplatformtheme.h>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
@ -716,10 +718,12 @@ QImage QCoreTextFontEngine::imageForGlyph(glyph_t glyph, const QFixedPoint &subP
|
||||
// draw with white or black fill, and then invert the glyph image in the latter case,
|
||||
// producing an alpha map. This covers the most common use-cases, but longer term we
|
||||
// should propagate the fill color all the way from the paint engine, and include it
|
||||
//in the key for the glyph cache.
|
||||
// in the key for the glyph cache.
|
||||
|
||||
if (!qt_mac_applicationIsInDarkMode())
|
||||
return kCGColorBlack;
|
||||
if (auto *platformTheme = QGuiApplicationPrivate::platformTheme()) {
|
||||
if (platformTheme->colorScheme() != Qt::ColorScheme::Dark)
|
||||
return kCGColorBlack;
|
||||
}
|
||||
}
|
||||
return kCGColorWhite;
|
||||
}();
|
||||
|
@ -54,6 +54,9 @@ private:
|
||||
QMacNotificationObserver m_systemColorObserver;
|
||||
mutable QHash<QPlatformTheme::Palette, QPalette*> m_palettes;
|
||||
QMacKeyValueObserver m_appearanceObserver;
|
||||
|
||||
Qt::ColorScheme m_colorScheme = Qt::ColorScheme::Unknown;
|
||||
void updateColorScheme();
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -224,6 +224,8 @@ QCocoaTheme::QCocoaTheme()
|
||||
NSSystemColorsDidChangeNotification, [this] {
|
||||
handleSystemThemeChange();
|
||||
});
|
||||
|
||||
updateColorScheme();
|
||||
}
|
||||
|
||||
QCocoaTheme::~QCocoaTheme()
|
||||
@ -242,6 +244,9 @@ void QCocoaTheme::reset()
|
||||
void QCocoaTheme::handleSystemThemeChange()
|
||||
{
|
||||
reset();
|
||||
|
||||
updateColorScheme();
|
||||
|
||||
m_systemPalette = qt_mac_createSystemPalette();
|
||||
m_palettes = qt_mac_createRolePalettes();
|
||||
|
||||
@ -475,7 +480,19 @@ QVariant QCocoaTheme::themeHint(ThemeHint hint) const
|
||||
|
||||
Qt::ColorScheme QCocoaTheme::colorScheme() const
|
||||
{
|
||||
return qt_mac_applicationIsInDarkMode() ? Qt::ColorScheme::Dark : Qt::ColorScheme::Light;
|
||||
return m_colorScheme;
|
||||
}
|
||||
|
||||
/*
|
||||
Update the theme's color scheme based on the current appearance.
|
||||
|
||||
We can only reference the appearance on the main thread, but the
|
||||
CoreText font engine needs to know the color scheme, and might be
|
||||
used from secondary threads, so we cache the color scheme.
|
||||
*/
|
||||
void QCocoaTheme::updateColorScheme()
|
||||
{
|
||||
m_colorScheme = qt_mac_applicationIsInDarkMode() ? Qt::ColorScheme::Dark : Qt::ColorScheme::Light;
|
||||
}
|
||||
|
||||
QString QCocoaTheme::standardButtonText(int button) const
|
||||
|
Loading…
x
Reference in New Issue
Block a user