src/gui/painting/qpainter.cpp
branchRCL_3
changeset 5 d3bac044e0f0
parent 4 3b1da2848fc7
child 8 3f74d0d4af4c
--- a/src/gui/painting/qpainter.cpp	Fri Feb 19 23:40:16 2010 +0200
+++ b/src/gui/painting/qpainter.cpp	Fri Mar 12 15:46:37 2010 +0200
@@ -7382,10 +7382,15 @@
 typedef QList<QPaintDeviceRedirection> QPaintDeviceRedirectionList;
 Q_GLOBAL_STATIC(QPaintDeviceRedirectionList, globalRedirections)
 Q_GLOBAL_STATIC(QMutex, globalRedirectionsMutex)
+Q_GLOBAL_STATIC(QAtomicInt, globalRedirectionAtomic)
 
 /*!
     \threadsafe
 
+    \obsolete
+
+    Please use QWidget::render() instead.
+
     Redirects all paint commands for the given paint \a device, to the
     \a replacement device. The optional point \a offset defines an
     offset within the source device.
@@ -7395,9 +7400,10 @@
     device's painter (if any) before redirecting. Call
     restoreRedirected() to restore the previous redirection.
 
-    In general, you'll probably find that calling
-    QPixmap::grabWidget() or QPixmap::grabWindow() is an easier
-    solution.
+    \warning Making use of redirections in the QPainter API implies
+    that QPainter::begin() and QPaintDevice destructors need to hold
+    a mutex for a short period. This can impact performance. Use of
+    QWidget::render is strongly encouraged.
 
     \sa redirected(), restoreRedirected()
 */
@@ -7429,14 +7435,24 @@
     Q_ASSERT(redirections != 0);
     *redirections += QPaintDeviceRedirection(device, rdev ? rdev : replacement, offset + roffset,
                                              hadInternalWidgetRedirection ? redirections->size() - 1 : -1);
+    globalRedirectionAtomic()->ref();
 }
 
 /*!
     \threadsafe
 
+    \obsolete
+
+    Using QWidget::render() obsoletes the use of this function.
+
     Restores the previous redirection for the given \a device after a
     call to setRedirected().
 
+    \warning Making use of redirections in the QPainter API implies
+    that QPainter::begin() and QPaintDevice destructors need to hold
+    a mutex for a short period. This can impact performance. Use of
+    QWidget::render is strongly encouraged.
+
     \sa redirected()
  */
 void QPainter::restoreRedirected(const QPaintDevice *device)
@@ -7447,6 +7463,7 @@
     Q_ASSERT(redirections != 0);
     for (int i = redirections->size()-1; i >= 0; --i) {
         if (redirections->at(i) == device) {
+            globalRedirectionAtomic()->deref();
             const int internalWidgetRedirectionIndex = redirections->at(i).internalWidgetRedirectionIndex;
             redirections->removeAt(i);
             // Restore the internal widget redirection, i.e. remove it from the global
@@ -7468,9 +7485,18 @@
 /*!
     \threadsafe
 
+    \obsolete
+
+    Using QWidget::render() obsoletes the use of this function.
+
     Returns the replacement for given \a device. The optional out
     parameter \a offset returns the offset within the replaced device.
 
+    \warning Making use of redirections in the QPainter API implies
+    that QPainter::begin() and QPaintDevice destructors need to hold
+    a mutex for a short period. This can impact performance. Use of
+    QWidget::render is strongly encouraged.
+
     \sa setRedirected(), restoreRedirected()
 */
 QPaintDevice *QPainter::redirected(const QPaintDevice *device, QPoint *offset)
@@ -7483,6 +7509,9 @@
             return widgetPrivate->redirected(offset);
     }
 
+    if (*globalRedirectionAtomic() == 0)
+        return 0;
+
     QMutexLocker locker(globalRedirectionsMutex());
     QPaintDeviceRedirectionList *redirections = globalRedirections();
     Q_ASSERT(redirections != 0);
@@ -7500,6 +7529,9 @@
 
 void qt_painter_removePaintDevice(QPaintDevice *dev)
 {
+    if (*globalRedirectionAtomic() == 0)
+        return;
+
     QMutex *mutex = 0;
     QT_TRY {
         mutex = globalRedirectionsMutex();