From 2c920eb87b24af1f5aa07476a0ce4bb035a923b0 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Tue, 25 Jun 2019 16:19:20 +0000 Subject: [PATCH] remove obsolete QPainter redirection support Signed-off-by: Ivailo Monev --- src/gui/kernel/qwidget.cpp | 2 - src/gui/painting/qpaintdevice.cpp | 3 - src/gui/painting/qpainter.cpp | 179 ------------------------------ src/gui/painting/qpainter.h | 5 - 4 files changed, 189 deletions(-) diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 4fd658207..24fb0a302 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -4926,8 +4926,6 @@ void QWidgetPrivate::render(QPaintDevice *target, const QPoint &targetOffset, if (target->devType() == QInternal::Widget) redirected = static_cast(target)->d_func()->redirected(&redirectionOffset); - if (!redirected) - redirected = QPainter::redirected(target, &redirectionOffset); if (redirected) { target = redirected; diff --git a/src/gui/painting/qpaintdevice.cpp b/src/gui/painting/qpaintdevice.cpp index 8c694267a..27538f720 100644 --- a/src/gui/painting/qpaintdevice.cpp +++ b/src/gui/painting/qpaintdevice.cpp @@ -43,8 +43,6 @@ QT_BEGIN_NAMESPACE -extern void qt_painter_removePaintDevice(QPaintDevice *); //qpainter.cpp - QPaintDevice::QPaintDevice() { painters = 0; @@ -55,7 +53,6 @@ QPaintDevice::~QPaintDevice() if (paintingActive()) qWarning("QPaintDevice: Cannot destroy paint device that is being " "painted"); - qt_painter_removePaintDevice(this); } diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index 9ac78b22e..0cba3a0a1 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -1428,8 +1428,6 @@ bool QPainter::begin(QPaintDevice *pd) if (pd->devType() == QInternal::Widget) rpd = static_cast(pd)->d_func()->redirected(&redirectionOffset); - if (!rpd) - rpd = redirected(pd, &redirectionOffset); if (rpd) pd = rpd; @@ -6584,183 +6582,6 @@ struct QPaintDeviceRedirection Q_DUMMY_COMPARISON_OPERATOR(QPaintDeviceRedirection) }; -typedef QList 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. - - The redirection will not be effective until the begin() function - has been called; make sure to call end() for the given \a - device's painter (if any) before redirecting. Call - restoreRedirected() to restore the previous redirection. - - \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() -*/ -void QPainter::setRedirected(const QPaintDevice *device, - QPaintDevice *replacement, - const QPoint &offset) -{ - Q_ASSERT(device != 0); - - bool hadInternalWidgetRedirection = false; - if (device->devType() == QInternal::Widget) { - const QWidgetPrivate *widgetPrivate = static_cast(device)->d_func(); - // This is the case when the widget is in a paint event. - if (widgetPrivate->redirectDev) { - // Remove internal redirection and put it back into the global redirection list. - QPoint oldOffset; - QPaintDevice *oldReplacement = widgetPrivate->redirected(&oldOffset); - const_cast(widgetPrivate)->restoreRedirected(); - setRedirected(device, oldReplacement, oldOffset); - hadInternalWidgetRedirection = true; - } - } - - QPoint roffset; - QPaintDevice *rdev = redirected(replacement, &roffset); - - QMutexLocker locker(globalRedirectionsMutex()); - QPaintDeviceRedirectionList *redirections = globalRedirections(); - 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) -{ - Q_ASSERT(device != 0); - QMutexLocker locker(globalRedirectionsMutex()); - QPaintDeviceRedirectionList *redirections = globalRedirections(); - 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 - // redirection list and put it back into QWidgetPrivate. The index is only set when - // someone call QPainter::setRedirected in a widget's paint event and we internally - // have a redirection set (typically set in QWidgetPrivate::drawWidget). - if (internalWidgetRedirectionIndex >= 0) { - Q_ASSERT(internalWidgetRedirectionIndex < redirections->size()); - const QPaintDeviceRedirection &redirectionDevice = redirections->at(internalWidgetRedirectionIndex); - QWidget *widget = static_cast(const_cast(device)); - widget->d_func()->setRedirected(redirectionDevice.replacement, redirectionDevice.offset); - redirections->removeAt(internalWidgetRedirectionIndex); - } - return; - } - } -} - -/*! - \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) -{ - Q_ASSERT(device != 0); - - if (device->devType() == QInternal::Widget) { - const QWidgetPrivate *widgetPrivate = static_cast(device)->d_func(); - if (widgetPrivate->redirectDev) - return widgetPrivate->redirected(offset); - } - - if (!globalRedirectionAtomic() || *globalRedirectionAtomic() == 0) - return 0; - - QMutexLocker locker(globalRedirectionsMutex()); - QPaintDeviceRedirectionList *redirections = globalRedirections(); - Q_ASSERT(redirections != 0); - for (int i = redirections->size()-1; i >= 0; --i) - if (redirections->at(i) == device) { - if (offset) - *offset = redirections->at(i).offset; - return redirections->at(i).replacement; - } - if (offset) - *offset = QPoint(0, 0); - return 0; -} - - -void qt_painter_removePaintDevice(QPaintDevice *dev) -{ - if (!globalRedirectionAtomic() || *globalRedirectionAtomic() == 0) - return; - - QMutex *mutex = 0; - QT_TRY { - mutex = globalRedirectionsMutex(); - } QT_CATCH(...) { - // ignore the missing mutex, since we could be called from - // a destructor, and destructors shall not throw - } - QMutexLocker locker(mutex); - QPaintDeviceRedirectionList *redirections = 0; - QT_TRY { - redirections = globalRedirections(); - } QT_CATCH(...) { - // do nothing - code below is safe with redirections being 0. - } - if (redirections) { - for (int i = 0; i < redirections->size(); ) { - if(redirections->at(i) == dev || redirections->at(i).replacement == dev) - redirections->removeAt(i); - else - ++i; - } - } -} - void qt_format_text(const QFont &fnt, const QRectF &_r, int tf, const QString& str, QRectF *brect, int tabstops, int *ta, int tabarraylen, diff --git a/src/gui/painting/qpainter.h b/src/gui/painting/qpainter.h index 02d4d2f8c..eb5641fa0 100644 --- a/src/gui/painting/qpainter.h +++ b/src/gui/painting/qpainter.h @@ -424,11 +424,6 @@ public: QPaintEngine *paintEngine() const; - static void setRedirected(const QPaintDevice *device, QPaintDevice *replacement, - const QPoint& offset = QPoint()); - static QPaintDevice *redirected(const QPaintDevice *device, QPoint *offset = Q_NULLPTR); - static void restoreRedirected(const QPaintDevice *device); - void beginNativePainting(); void endNativePainting();