diff options
author | Tor Arne Vestbø <tor.arne.vestbo@nokia.com> | 2010-09-02 15:18:31 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@nokia.com> | 2010-09-02 16:47:30 +0200 |
commit | 71a3b1a0d3ee6429832bdbf0da026cdc3f74080f (patch) | |
tree | d2254318ed1c4870238f2ae6b62edc19ba733319 /src/gui/kernel/qcocoasharedwindowmethods_mac_p.h | |
parent | 03b7a3cffba609df56b4ccadacae6b6f985e96e9 (diff) | |
download | qt4-tools-71a3b1a0d3ee6429832bdbf0da026cdc3f74080f.tar.gz |
Ensure that OpenGL contexts are attached to an NSView before first paint
Attaching an OpenGL context to an NSView too soon will result in an
error "invalid drawable" printed on the console. We used to guard
against this by checking the visible property of the NSWindow, but this
turned out to be too late, as we had already recived an initial paint
event by then as part of showing the window. The visual result was a
single frame of gray painted before the user's paint event code took
effect.
We solve this by hooking into setInitialFirstResponder on the NSWindow,
which is called as part of making the window visible for the first time.
At this point it's safe to attach the GL context to the NSView, so we
iterate all the GLWidget children of the top level window and make sure
the context is attached by sending a MacGLWindowChange event.
The check in qt_mac_update_child_gl_widgets() for a top level window
had to be removed for this approach to work, but should be okey as
we're only iterating the children.
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@nokia.com>
Reviewed-by: Trond Kjernåsen <trond.kjernasen@nokia.com>
Diffstat (limited to 'src/gui/kernel/qcocoasharedwindowmethods_mac_p.h')
-rw-r--r-- | src/gui/kernel/qcocoasharedwindowmethods_mac_p.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/gui/kernel/qcocoasharedwindowmethods_mac_p.h b/src/gui/kernel/qcocoasharedwindowmethods_mac_p.h index 679514946c..16f5bd6266 100644 --- a/src/gui/kernel/qcocoasharedwindowmethods_mac_p.h +++ b/src/gui/kernel/qcocoasharedwindowmethods_mac_p.h @@ -58,6 +58,8 @@ QT_BEGIN_NAMESPACE extern Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum); // qcocoaview.mm extern QPointer<QWidget> qt_button_down; //qapplication_mac.cpp extern const QStringList& qEnabledDraggedTypes(); // qmime_mac.cpp +extern void qt_event_request_window_change(QWidget *); // qapplication_mac.mm +extern void qt_mac_send_posted_gl_updates(QWidget *widget); // qapplication_mac.mm Q_GLOBAL_STATIC(QPointer<QWidget>, currentDragTarget); @@ -227,6 +229,17 @@ QT_END_NAMESPACE [self release]; } +- (void)setInitialFirstResponder:(NSView *)view +{ + // This method is called the first time the window is placed on screen and + // is the earliest point in time we can connect OpenGL contexts to NSViews. + QWidget *qwidget = [[QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) sharedDelegate] qt_qwidgetForWindow:self]; + qt_event_request_window_change(qwidget); + qt_mac_send_posted_gl_updates(qwidget); + + [super setInitialFirstResponder:view]; +} + - (BOOL)makeFirstResponder:(NSResponder *)responder { // For some reason Cocoa wants to flip the first responder |