/**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** Contact: Qt Software Information (qt-info@nokia.com) ** ** This file is part of the QtCore module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage ** This file contains pre-release code and may not be distributed. ** You may use this file in accordance with the terms and conditions ** contained in the either Technology Preview License Agreement or the ** Beta Release License Agreement. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 2.1 as published by the Free Software ** Foundation and appearing in the file LICENSE.LGPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Nokia gives you certain ** additional rights. These rights are described in the Nokia Qt LGPL ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this ** package. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 3.0 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU General Public License version 3.0 requirements will be ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you are unsure which license is appropriate for your use, please ** contact the sales department at qt-sales@nokia.com. ** $QT_END_LICENSE$ ** ****************************************************************************/ #include "qvariantanimation.h" #include "qvariantanimation_p.h" #include #include #include #include #ifndef QT_NO_ANIMATION QT_BEGIN_NAMESPACE /*! \class QVariantAnimation \ingroup animation \brief The QVariantAnimation class provides an abstract base class for animations. \since 4.6 This class is part of \l{The Animation Framework}. It serves as a base class for property and item animations, with functions for shared functionality. QVariantAnimation cannot be used directly as it is an abstract class; it has a pure virtual method called updateCurrentValue(). The class performs interpolation over \l{QVariant}s, but leaves using the interpolated values to its subclasses. Currently, Qt provides QPropertyAnimation, which animates Qt \l{Qt's Property System}{properties}. See the QPropertyAnimation class description if you wish to animate such properties. You can then set start and end values for the property by calling setStartValue() and setEndValue(), and finally call start() to start the animation. QVariantAnimation will interpolate the property of the target object and emit valueChanged(). To react to a change in the current value you have to reimplement the updateCurrentValue() virtual function. It is also possible to set values at specified steps situated between the start and end value. The interpolation will then touch these points at the specified steps. Note that the start and end values are defined as the key values at 0.0 and 1.0. There are two ways to affect how QVariantAnimation interpolates the values. You can set an easing curve by calling setEasingCurve(), and configure the duration by calling setDuration(). You can change how the QVariants are interpolated by creating a subclass of QVariantAnimation, and reimplementing the virtual interpolated() function. Subclassing QVariantAnimation can be an alternative if you have \l{QVariant}s that you do not wish to declare as Qt properties. Note, however, that you in most cases will be better off declaring your QVariant as a property. Not all QVariant types are supported. Below is a list of currently supported QVariant types: \list \o \l{QMetaType::}{Int} \o \l{QMetaType::}{Double} \o \l{QMetaType::}{Float} \o \l{QMetaType::}{QLine} \o \l{QMetaType::}{QLineF} \o \l{QMetaType::}{QPoint} \o \l{QMetaType::}{QSize} \o \l{QMetaType::}{QSizeF} \o \l{QMetaType::}{QRect} \o \l{QMetaType::}{QRectF} \endlist If you need to interpolate other variant types, including custom types, you have to implement interpolation for these yourself. You do this by reimplementing interpolated(), which returns interpolation values for the value being interpolated. \omit We need some snippets around here. \endomit \sa QPropertyAnimation, QAbstractAnimation, {The Animation Framework} */ /*! \fn void QVariantAnimation::valueChanged(const QVariant &value) QVariantAnimation emits this signal whenever the current \a value changes. \sa currentValue, startValue, endValue */ /*! \fn void QVariantAnimation::updateCurrentValue(const QVariant &value) = 0; This pure virtual function is called every time the animation's current value changes. The \a value argument is the new current value. \sa currentValue */ static bool animationValueLessThan(const QVariantAnimation::KeyValue &p1, const QVariantAnimation::KeyValue &p2) { return p1.first < p2.first; } static QVariant defaultInterpolator(const void *, const void *, qreal) { return QVariant(); } template<> Q_INLINE_TEMPLATE QRect _q_interpolate(const QRect &f, const QRect &t, qreal progress) { QRect ret; ret.setCoords(_q_interpolate(f.left(), t.left(), progress), _q_interpolate(f.top(), t.top(), progress), _q_interpolate(f.right(), t.right(), progress), _q_interpolate(f.bottom(), t.bottom(), progress)); return ret; } template<> Q_INLINE_TEMPLATE QRectF _q_interpolate(const QRectF &f, const QRectF &t, qreal progress) { qreal x1, y1, w1, h1; f.getRect(&x1, &y1, &w1, &h1); qreal x2, y2, w2, h2; t.getRect(&x2, &y2, &w2, &h2); return QRectF(_q_interpolate(x1, x2, progress), _q_interpolate(y1, y2, progress), _q_interpolate(w1, w2, progress), _q_interpolate(h1, h2, progress)); } template<> Q_INLINE_TEMPLATE QLine _q_interpolate(const QLine &f, const QLine &t, qreal progress) { return QLine( _q_interpolate(f.p1(), t.p1(), progress), _q_interpolate(f.p2(), t.p2(), progress)); } template<> Q_INLINE_TEMPLATE QLineF _q_interpolate(const QLineF &f, const QLineF &t, qreal progress) { return QLineF( _q_interpolate(f.p1(), t.p1(), progress), _q_interpolate(f.p2(), t.p2(), progress)); } QVariantAnimationPrivate::QVariantAnimationPrivate() : duration(250), hasStartValue(false), interpolator(&defaultInterpolator), changedSignalMask(1 << QVariantAnimation::staticMetaObject.indexOfSignal("valueChanged(QVariant)")) { //we keep the mask so that we emit valueChanged only when needed (for performance reasons) } void QVariantAnimationPrivate::convertValues(int t) { //this ensures that all the keyValues are of type t for (int i = 0; i < keyValues.count(); ++i) { QVariantAnimation::KeyValue &pair = keyValues[i]; pair.second.convert(static_cast(t)); } //we also need update to the current interval if needed currentInterval.start.second.convert(static_cast(t)); currentInterval.end.second.convert(static_cast(t)); //... and the interpolator updateInterpolator(); } void QVariantAnimationPrivate::updateInterpolator() { int type = currentInterval.start.second.userType(); if (type == currentInterval.end.second.userType()) interpolator = getInterpolator(type); else interpolator = 0; //we make sure that the interpolator is always set to something if (!interpolator) interpolator = &defaultInterpolator; } /*! \internal The goal of this function is to update the currentInterval member. As a consequence, we also need to update the currentValue. Set \a force to true to always recalculate the interval. */ void QVariantAnimationPrivate::recalculateCurrentInterval(bool force/*=false*/) { // can't interpolate if we have only 1 key value if (keyValues.count() <= 1) return; const qreal progress = easing.valueForProgress(((duration == 0) ? qreal(1) : qreal(currentTime) / qreal(duration))); if (force || progress < currentInterval.start.first || progress > currentInterval.end.first) { //let's update currentInterval QVariantAnimation::KeyValues::const_iterator itStart = qLowerBound(keyValues.constBegin(), keyValues.constEnd(), qMakePair(progress, QVariant()), animationValueLessThan); QVariantAnimation::KeyValues::const_iterator itEnd = itStart; // If we are at the end we should continue to use the last keyValues in case of extrapolation (progress > 1.0). // This is because the easing function can return a value slightly outside the range [0, 1] if (itStart != keyValues.constEnd()) { // this can't happen because we always prepend the default start value there if (itStart == keyValues.constBegin()) { ++itEnd; } else { --itStart; } // update all the values of the currentInterval currentInterval.start = *itStart; currentInterval.end = *itEnd; updateInterpolator(); } } setCurrentValueForProgress(progress); } void QVariantAnimationPrivate::setCurrentValueForProgress(const qreal progress) { Q_Q(QVariantAnimation); const qreal startProgress = currentInterval.start.first; const qreal endProgress = currentInterval.end.first; const qreal localProgress = (progress - startProgress) / (endProgress - startProgress); QVariant ret = q->interpolated(currentInterval.start.second, currentInterval.end.second, localProgress); qSwap(currentValue, ret); q->updateCurrentValue(currentValue); if ((connectedSignals & changedSignalMask) && currentValue != ret) { //the value has changed emit q->valueChanged(currentValue); } } QVariant QVariantAnimationPrivate::valueAt(qreal step) const { QVariantAnimation::KeyValues::const_iterator result = qBinaryFind(keyValues.begin(), keyValues.end(), qMakePair(step, QVariant()), animationValueLessThan); if (result != keyValues.constEnd()) return result->second; return QVariant(); } void QVariantAnimationPrivate::setValueAt(qreal step, const QVariant &value) { if (step < qreal(0.0) || step > qreal(1.0)) { qWarning("QVariantAnimation::setValueAt: invalid step = %f", step); return; } QVariantAnimation::KeyValue pair(step, value); QVariantAnimation::KeyValues::iterator result = qLowerBound(keyValues.begin(), keyValues.end(), pair, animationValueLessThan); if (result == keyValues.end() || result->first != step) { keyValues.insert(result, pair); } else { if (value.isValid()) result->second = value; // replaces the previous value else if (step == 0 && !hasStartValue && defaultStartValue.isValid()) result->second = defaultStartValue; // resets to the default start value else keyValues.erase(result); // removes the previous value } recalculateCurrentInterval(/*force=*/true); } void QVariantAnimationPrivate::setDefaultStartValue(const QVariant &value) { defaultStartValue = value; if (!hasStartValue) setValueAt(0, value); } /*! Construct a QVariantAnimation object. \a parent is passed to QAbstractAnimation's constructor. */ QVariantAnimation::QVariantAnimation(QObject *parent) : QAbstractAnimation(*new QVariantAnimationPrivate, parent) { } /*! \internal */ QVariantAnimation::QVariantAnimation(QVariantAnimationPrivate &dd, QObject *parent) : QAbstractAnimation(dd, parent) { } /*! Destroys the animation. */ QVariantAnimation::~QVariantAnimation() { } /*! \property QVariantAnimation::easingCurve \brief the easing curve of the animation This property defines the easing curve of the animation. By default, a linear easing curve is used, resulting in linear interpolation. Other curves are provided, for instance, QEasingCurve::InCirc, which provides a circular entry curve. Another example is QEasingCurve::InOutElastic, which provides an elastic effect on the values of the interpolated variant. The easing curve is used with the interpolator, the interpolated() virtual function, the animation's duration, and iterationCount, to control how the current value changes as the animation progresses. */ QEasingCurve QVariantAnimation::easingCurve() const { Q_D(const QVariantAnimation); return d->easing; } void QVariantAnimation::setEasingCurve(const QEasingCurve &easing) { Q_D(QVariantAnimation); d->easing = easing; d->recalculateCurrentInterval(); } typedef QVector QInterpolatorVector; Q_GLOBAL_STATIC(QInterpolatorVector, registeredInterpolators) /*! \fn void qRegisterAnimationInterpolator(QVariant (*func)(const T &from, const T &to, qreal progress)) \relates QVariantAnimation \threadsafe Registers a custom interpolator \a func for the template type \c{T}. The interpolator has to be registered before the animation is constructed. To unregister (and use the default interpolator) set \a func to 0. */ /*! \internal \typedef QVariantAnimation::Interpolator This is a typedef for a pointer to a function with the following signature: \code QVariant myInterpolator(const QVariant &from, const QVariant &to, qreal progress); \endcode */ /*! \internal * Registers a custom interpolator \a func for the specific \a interpolationType. * The interpolator has to be registered before the animation is constructed. * To unregister (and use the default interpolator) set \a func to 0. */ void QVariantAnimation::registerInterpolator(QVariantAnimation::Interpolator func, int interpolationType) { // will override any existing interpolators QInterpolatorVector *interpolators = registeredInterpolators(); QMutexLocker locker(QMutexPool::globalInstanceGet(interpolators)); if (int(interpolationType) >= interpolators->count()) interpolators->resize(int(interpolationType) + 1); interpolators->replace(interpolationType, func); } template static inline QVariantAnimation::Interpolator castToInterpolator(QVariant (*func)(const T &from, const T &to, qreal progress)) { return reinterpret_cast(func); } QVariantAnimation::Interpolator QVariantAnimationPrivate::getInterpolator(int interpolationType) { QInterpolatorVector *interpolators = registeredInterpolators(); QMutexLocker locker(QMutexPool::globalInstanceGet(interpolators)); QVariantAnimation::Interpolator ret = 0; if (interpolationType < interpolators->count()) { ret = interpolators->at(interpolationType); if (ret) return ret; } switch(interpolationType) { case QMetaType::Int: return castToInterpolator(_q_interpolateVariant); case QMetaType::Double: return castToInterpolator(_q_interpolateVariant); case QMetaType::Float: return castToInterpolator(_q_interpolateVariant); case QMetaType::QLine: return castToInterpolator(_q_interpolateVariant); case QMetaType::QLineF: return castToInterpolator(_q_interpolateVariant); case QMetaType::QPoint: return castToInterpolator(_q_interpolateVariant); case QMetaType::QPointF: return castToInterpolator(_q_interpolateVariant); case QMetaType::QSize: return castToInterpolator(_q_interpolateVariant); case QMetaType::QSizeF: return castToInterpolator(_q_interpolateVariant); case QMetaType::QRect: return castToInterpolator(_q_interpolateVariant); case QMetaType::QRectF: return castToInterpolator(_q_interpolateVariant); default: return 0; //this type is not handled } } /*! \property QVariantAnimation::duration \brief the duration of the animation This property describes the duration in milliseconds of the animation. The default duration is 250 milliseconds. \sa QAbstractAnimation::duration() */ int QVariantAnimation::duration() const { Q_D(const QVariantAnimation); return d->duration; } void QVariantAnimation::setDuration(int msecs) { Q_D(QVariantAnimation); if (msecs < 0) { qWarning("QVariantAnimation::setDuration: cannot set a negative duration"); return; } if (d->duration == msecs) return; d->duration = msecs; d->recalculateCurrentInterval(); } /*! \property QVariantAnimation::startValue \brief the optional start value of the animation This property describes the optional start value of the animation. If omitted, or if a null QVariant is assigned as the start value, the animation will use the current position of the end when the animation is started. \sa endValue */ QVariant QVariantAnimation::startValue() const { return keyValueAt(0); } void QVariantAnimation::setStartValue(const QVariant &value) { setKeyValueAt(0, value); } /*! \property QVariantAnimation::endValue \brief the end value of the animation This property describes the end value of the animation. \sa startValue */ QVariant QVariantAnimation::endValue() const { return keyValueAt(1); } void QVariantAnimation::setEndValue(const QVariant &value) { setKeyValueAt(1, value); } /*! Returns the key frame value for the given \a step. The given \a step must be in the range 0 to 1. If there is no KeyValue for \a step, it returns an invalid QVariant. \sa keyValues(), setKeyValueAt() */ QVariant QVariantAnimation::keyValueAt(qreal step) const { Q_D(const QVariantAnimation); if (step == 0 && !d->hasStartValue) return QVariant(); //special case where we don't have an explicit startValue return d->valueAt(step); } /*! \typedef QVariantAnimation::KeyValue This is a typedef for QPair. */ /*! \typedef QVariantAnimation::KeyValues This is a typedef for QVector */ /*! Creates a key frame at the given \a step with the given \a value. The given \a step must be in the range 0 to 1. \sa setKeyValues(), keyValueAt() */ void QVariantAnimation::setKeyValueAt(qreal step, const QVariant &value) { Q_D(QVariantAnimation); if (step == 0) d->hasStartValue = value.isValid(); d->setValueAt(step, value); } /*! Returns the key frames of this animation. \sa keyValueAt(), setKeyValues() */ QVariantAnimation::KeyValues QVariantAnimation::keyValues() const { Q_D(const QVariantAnimation); QVariantAnimation::KeyValues ret = d->keyValues; //in case we added the default start value, we remove it if (!d->hasStartValue && !ret.isEmpty() && ret.at(0).first == 0) ret.remove(0); return ret; } /*! Replaces the current set of key frames with the given \a keyValues. the step of the key frames must be in the range 0 to 1. \sa keyValues(), keyValueAt() */ void QVariantAnimation::setKeyValues(const KeyValues &keyValues) { Q_D(QVariantAnimation); d->keyValues = keyValues; qSort(d->keyValues.begin(), d->keyValues.end(), animationValueLessThan); d->hasStartValue = !d->keyValues.isEmpty() && d->keyValues.at(0).first == 0; d->recalculateCurrentInterval(/*force=*/true); } /*! \property QVariantAnimation::currentValue \brief the current value of the animation. This property describes the current value; an interpolated value between the \l{startValue}{start value} and the \l{endValue}{end value}, using the current time for progress. The value itself is obtained from interpolated(), which is called repeatedly as the animation is running. QVariantAnimation calls the virtual updateCurrentValue() function when the current value changes. This is particularly useful for subclasses that need to track updates. For example, QPropertyAnimation uses this function to animate Qt \l{Qt's Property System}{properties}. \sa startValue, endValue */ QVariant QVariantAnimation::currentValue() const { Q_D(const QVariantAnimation); if (!d->currentValue.isValid()) const_cast(d)->recalculateCurrentInterval(); return d->currentValue; } /*! \reimp */ bool QVariantAnimation::event(QEvent *event) { return QAbstractAnimation::event(event); } /*! \reimp */ void QVariantAnimation::updateState(QAbstractAnimation::State oldState, QAbstractAnimation::State newState) { Q_UNUSED(oldState); Q_UNUSED(newState); } /*! This virtual function returns the linear interpolation between variants \a from and \a to, at \a progress, usually a value between 0 and 1. You can reimplement this function in a subclass of QVariantAnimation to provide your own interpolation algorithm. Note that in order for the interpolation to work with a QEasingCurve that return a value smaller than 0 or larger than 1 (such as QEasingCurve::InBack) you should make sure that it can extrapolate. If the semantic of the datatype does not allow extrapolation this function should handle that gracefully. You should call the QVariantAnimation implementation of this function if you want your class to handle the types already supported by Qt (see class QVariantAnimation description for a list of supported types). \sa QEasingCurve */ QVariant QVariantAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const { return d_func()->interpolator(from.constData(), to.constData(), progress); } /*! \reimp */ void QVariantAnimation::updateCurrentTime(int msecs) { Q_UNUSED(msecs); d_func()->recalculateCurrentInterval(); } QT_END_NAMESPACE #include "moc_qvariantanimation.cpp" #endif //QT_NO_ANIMATION rect.size()) { if (dfbSurface) dfbSurface->Release(dfbSurface); - - IDirectFB *dfb = screen->dfb(); - if (!dfb) { - qFatal("QDirectFBWindowSurface::setGeometry(): " - "Unable to get DirectFB handle!"); - } - dfbSurface = screen->createDFBSurface(rect.size(), screen->pixelFormat(), QDirectFBScreen::DontTrackSurface); - } else { - Q_ASSERT(dfbSurface); - } -#else - const QRect oldRect = geometry(); - const bool isMove = oldRect.isEmpty() || - rect.topLeft() != oldRect.topLeft(); - - if (!dfbWindow) - createWindow(); - -#if (Q_DIRECTFB_VERSION >= 0x010000) - if (isResize && isMove) { - result = dfbWindow->SetBounds(dfbWindow, rect.x(), rect.y(), - rect.width(), rect.height()); - } else if (isResize) { - result = dfbWindow->Resize(dfbWindow, - rect.width(), rect.height()); - } else if (isMove) { - result = dfbWindow->MoveTo(dfbWindow, rect.x(), rect.y()); - } -#else - if (isResize) { - result = dfbWindow->Resize(dfbWindow, - rect.width(), rect.height()); } - if (isMove) { - result = dfbWindow->MoveTo(dfbWindow, rect.x(), rect.y()); - } -#endif -#endif + const QRegion region = QRegion(oldRect.isEmpty() ? screen->region() : QRegion(oldRect)).subtracted(rect); + screen->erase(region); + screen->flipSurface(primarySurface, flipFlags, region, QPoint()); + break; } } if (result != DFB_OK) DirectFBErrorFatal("QDirectFBWindowSurface::setGeometry()", result); } - QWSWindowSurface::setGeometry(rect, mask); + QWSWindowSurface::setGeometry(rect); } QByteArray QDirectFBWindowSurface::permanentState() const @@ -254,7 +270,6 @@ static inline void scrollSurface(IDirectFBSurface *surface, const QRect &r, int surface->Blit(surface, surface, &rect, r.x() + dx, r.y() + dy); } - bool QDirectFBWindowSurface::scroll(const QRegion ®ion, int dx, int dy) { if (!dfbSurface || !(flipFlags & DSFLIP_BLIT) || region.isEmpty()) @@ -272,35 +287,13 @@ bool QDirectFBWindowSurface::scroll(const QRegion ®ion, int dx, int dy) return true; } -bool QDirectFBWindowSurface::move(const QPoint &offset) -{ - QWSWindowSurface::move(offset); - -#ifdef QT_NO_DIRECTFB_WM - return true; // buffered -#else - if (!dfbWindow) - return false; - - DFBResult status = dfbWindow->Move(dfbWindow, offset.x(), offset.y()); - return (status == DFB_OK); -#endif -} - -QRegion QDirectFBWindowSurface::move(const QPoint &offset, const QRegion &newClip) +bool QDirectFBWindowSurface::move(const QPoint &moveBy) { -#ifdef QT_NO_DIRECTFB_WM - return QWSWindowSurface::move(offset, newClip); -#else - Q_UNUSED(offset); - Q_UNUSED(newClip); - - // DirectFB handles the entire move, so there's no need to blit. - return QRegion(); -#endif + setGeometry(geometry().translated(moveBy)); + return true; } -QPaintEngine* QDirectFBWindowSurface::paintEngine() const +QPaintEngine *QDirectFBWindowSurface::paintEngine() const { if (!engine) { QDirectFBWindowSurface *that = const_cast(this); @@ -333,57 +326,86 @@ inline bool isWidgetOpaque(const QWidget *w) return false; } -void QDirectFBWindowSurface::flush(QWidget *widget, const QRegion ®ion, + +void QDirectFBWindowSurface::flush(QWidget *, const QRegion ®ion, const QPoint &offset) { - Q_UNUSED(widget); -#ifdef QT_NO_DIRECTFB_WM - Q_UNUSED(region); - Q_UNUSED(offset); -#endif - - QWidget *win = window(); - // hw: make sure opacity information is updated before compositing - const bool opaque = isWidgetOpaque(win); - if (opaque != isOpaque()) { - SurfaceFlags flags = Buffered; - if (opaque) - flags |= Opaque; - setSurfaceFlags(flags); - } + if (QWidget *win = window()) { + + const bool opaque = isWidgetOpaque(win); + if (opaque != isOpaque()) { + SurfaceFlags flags = surfaceFlags(); + if (opaque) { + flags |= Opaque; + } else { + flags &= ~Opaque; + } + setSurfaceFlags(flags); + } #ifndef QT_NO_DIRECTFB_WM - const quint8 winOpacity = quint8(win->windowOpacity() * 255); - quint8 opacity; + const quint8 winOpacity = quint8(win->windowOpacity() * 255); + quint8 opacity; - if (dfbWindow) { - dfbWindow->GetOpacity(dfbWindow, &opacity); - if (winOpacity != opacity) - dfbWindow->SetOpacity(dfbWindow, winOpacity); - } + if (dfbWindow) { + dfbWindow->GetOpacity(dfbWindow, &opacity); + if (winOpacity != opacity) + dfbWindow->SetOpacity(dfbWindow, winOpacity); + } #endif - if (!(flipFlags & DSFLIP_BLIT)) { - dfbSurface->Flip(dfbSurface, 0, flipFlags); - } else { - if (!boundingRectFlip && region.numRects() > 1) { + } + + if (mode == Offscreen) { + IDirectFBSurface *primarySurface = screen->dfbSurface(); + primarySurface->SetBlittingFlags(primarySurface, DSBLIT_NOFX); + const QRect windowGeometry = QDirectFBWindowSurface::geometry(); + const QRect windowRect(0, 0, windowGeometry.width(), windowGeometry.height()); + if (boundingRectFlip || region.numRects() == 1) { + const QRect regionBoundingRect = region.boundingRect().translated(offset); + const QRect source = windowRect & regionBoundingRect; + const DFBRectangle rect = { + source.x(), source.y(), source.width(), source.height() + }; + primarySurface->Blit(primarySurface, dfbSurface, &rect, + windowGeometry.x() + source.x(), + windowGeometry.y() + source.y()); + } else { const QVector rects = region.rects(); - const DFBSurfaceFlipFlags nonWaitFlags = flipFlags & ~DSFLIP_WAIT; - for (int i=0; iFlip(dfbSurface, &dfbReg, i + 1 < rects.size() ? nonWaitFlags : flipFlags); + const int count = rects.size(); + for (int i=0; iBlit(primarySurface, dfbSurface, &rect, + windowGeometry.x() + source.x(), + windowGeometry.y() + source.y()); } - } else { - const QRect r = region.boundingRect(); - const DFBRegion dfbReg = { r.x() + offset.x(), r.y() + offset.y(), - r.x() + r.width() + offset.x(), - r.y() + r.height() + offset.y() }; - dfbSurface->Flip(dfbSurface, &dfbReg, flipFlags); } + if (QScreenCursor *cursor = QScreenCursor::instance()) { + const QRect cursorRectangle = cursor->boundingRect(); + if (cursor->isVisible() && !cursor->isAccelerated() + && region.intersects(cursorRectangle.translated(-(offset + windowGeometry.topLeft())))) { + const QImage image = cursor->image(); + + IDirectFBSurface *surface = screen->createDFBSurface(image, QDirectFBScreen::DontTrackSurface); + primarySurface->SetBlittingFlags(primarySurface, DSBLIT_BLEND_ALPHACHANNEL); + primarySurface->Blit(primarySurface, surface, 0, cursorRectangle.x(), cursorRectangle.y()); + surface->Release(surface); +#if (Q_DIRECTFB_VERSION >= 0x010000) + primarySurface->ReleaseSource(primarySurface); +#endif + } + } + + screen->flipSurface(primarySurface, flipFlags, region, offset + windowGeometry.topLeft()); + } else { + screen->flipSurface(dfbSurface, flipFlags, region, offset); } + + #ifdef QT_DIRECTFB_TIMING enum { Secs = 3 }; ++frames; diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbwindowsurface.h b/src/plugins/gfxdrivers/directfb/qdirectfbwindowsurface.h index 7885b73..c46d93b 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbwindowsurface.h +++ b/src/plugins/gfxdrivers/directfb/qdirectfbwindowsurface.h @@ -67,7 +67,7 @@ public: bool isValid() const; - void setGeometry(const QRect &rect, const QRegion &mask); + void setGeometry(const QRect &rect); QString key() const { return QLatin1String("directfb"); } QByteArray permanentState() const; @@ -76,7 +76,6 @@ public: bool scroll(const QRegion &area, int dx, int dy); bool move(const QPoint &offset); - QRegion move(const QPoint &offset, const QRegion &newClip); QImage image() const { return QImage(); } QPaintDevice *paintDevice() { return this; } @@ -88,7 +87,6 @@ public: void endPaint(const QRegion &); QImage *buffer(const QWidget *widget); - private: #ifndef QT_NO_DIRECTFB_WM void createWindow(); @@ -96,7 +94,11 @@ private: #endif QDirectFBPaintEngine *engine; - bool onscreen; + enum Mode { + Primary, + Offscreen, + Window + } mode; QList bufferImages; DFBSurfaceFlipFlags flipFlags; -- cgit v0.12 From d79f61b51868712590f423483f4d3b39cb60aa64 Mon Sep 17 00:00:00 2001 From: Anders Bakken Date: Wed, 22 Jul 2009 11:20:32 -0700 Subject: Fix IDirectFBSurface::ReleaseSource calls Make sure that these calls are in the right order. Reviewed-by: Donald --- src/plugins/gfxdrivers/directfb/qdirectfbpaintengine.cpp | 2 +- src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbpaintengine.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbpaintengine.cpp index 94f1aeb..68f37ff 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbpaintengine.cpp +++ b/src/plugins/gfxdrivers/directfb/qdirectfbpaintengine.cpp @@ -466,7 +466,7 @@ void QDirectFBPaintEngine::drawImage(const QRectF &r, const QImage &image, d->blit(r, imgSurface, sr); if (release) { #if (Q_DIRECTFB_VERSION >= 0x010000) - imgSurface->ReleaseSource(imgSurface); + d->surface->ReleaseSource(d->surface); #endif imgSurface->Release(imgSurface); } diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp index 88e304c..e12cbc4 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp +++ b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp @@ -141,6 +141,7 @@ IDirectFBSurface *QDirectFBScreen::createDFBSurface(const QImage &img, SurfaceCr { if (img.isNull()) // assert? return 0; + if (QDirectFBScreen::getSurfacePixelFormat(img.format()) == DSPF_UNKNOWN) { QImage image = img.convertToFormat(img.hasAlphaChannel() ? d_ptr->alphaPixmapFormat @@ -321,10 +322,10 @@ IDirectFBSurface *QDirectFBScreen::copyToDFBSurface(const QImage &img, DFBResult result = dfbSurface->Blit(dfbSurface, imgSurface, 0, 0, 0); if (result != DFB_OK) DirectFBError("QDirectFBScreen::copyToDFBSurface()", result); + imgSurface->Release(imgSurface); #if (Q_DIRECTFB_VERSION >= 0x010000) dfbSurface->ReleaseSource(dfbSurface); #endif - imgSurface->Release(imgSurface); #else // QT_NO_DIRECTFB_PREALLOCATED Q_ASSERT(image.format() == pixmapFormat); int bpl; -- cgit v0.12 From 18728d2ddd725199017a36cb290c30d6e8c9e647 Mon Sep 17 00:00:00 2001 From: Anders Bakken Date: Wed, 22 Jul 2009 11:25:47 -0700 Subject: Use dfbsurface::FillRectangles in solidFill Minor optimization Reviewed-by: Donald --- src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp index e12cbc4..ae2e38b 100644 --- a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp +++ b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp @@ -1254,11 +1254,21 @@ void QDirectFBScreen::solidFill(const QColor &color, const QRegion ®ion) d_ptr->dfbSurface->SetColor(d_ptr->dfbSurface, color.red(), color.green(), color.blue(), color.alpha()); - const QVector rects = region.rects(); - for (int i=0; idf