Cocoa: Send obscure events on OcclusionStateHidden

This disables animations for windows that are
completely obscured by other windows.

On examples/quick/animation, obscured CPU usage goes
from 10% to 1%. There has been reports of 100% CPU
usage with Qt before this patch.

Change-Id: Iefea43ed8c1cfaa2df13f1f5a4e4450146ade522
Reviewed-by: Laszlo Agocs <laszlo.agocs@digia.com>
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@theqtcompany.com>
This commit is contained in:
Morten Johan Sørvig 2014-10-23 16:02:31 +02:00 committed by Laszlo Agocs
parent 14e51127cf
commit 6c38a82aa8

View File

@ -420,12 +420,17 @@ static NSString *_q_NSWindowDidChangeOcclusionStateNotification = nil;
#pragma clang diagnostic ignored "-Wobjc-method-access"
enum { NSWindowOcclusionStateVisible = 1UL << 1 };
#endif
// Older versions managed in -[QNSView viewDidMoveToWindow].
// Support QWidgetAction in NSMenu. Mavericks only sends this notification.
// Ideally we should support this in Qt as well, in order to disable animations
// when the window is occluded.
if ((NSUInteger)[self.window occlusionState] & NSWindowOcclusionStateVisible)
if ((NSUInteger)[self.window occlusionState] & NSWindowOcclusionStateVisible) {
m_platformWindow->exposeWindow();
} else {
// Send Obscure events on window occlusion to stop animations. Several
// unit tests expect paint and/or expose events for windows that are
// sometimes (unpredictably) occlouded: Don't send Obscure events when
// running under QTestLib.
static bool onTestLib = qt_mac_resolveOption(false, "QT_QTESTLIB_RUNNING");
if (!onTestLib)
m_platformWindow->obscureWindow();
}
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_9
#pragma clang diagnostic pop
#endif