1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtGui module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QBACKINGSTORE_P_H
43 #define QBACKINGSTORE_P_H
49 // This file is not part of the Qt API. It exists purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
57 #include <QtGui/qwidget.h>
58 #include <private/qwidget_p.h>
59 #include <private/qwindowsurface_p.h>
61 #include <private/qwindowsurface_qws_p.h>
68 struct BeginPaintInfo {
69 inline BeginPaintInfo() : wasFlushed(0), nothingToPaint(0), windowSurfaceRecreated(0) {}
71 uint nothingToPaint : 1;
72 uint windowSurfaceRecreated : 1;
75 class Q_AUTOTEST_EXPORT QWidgetBackingStore
78 QWidgetBackingStore(QWidget *t);
79 ~QWidgetBackingStore();
81 static void showYellowThing(QWidget *widget, const QRegion &rgn, int msec, bool);
83 void sync(QWidget *exposedWidget, const QRegion &exposedRegion);
85 void flush(QWidget *widget = 0, QWindowSurface *surface = 0);
87 inline QPoint topLevelOffset() const { return tlwOffset; }
89 QWindowSurface *surface() const { return windowSurface; }
91 inline bool isDirty() const
93 return !(dirtyWidgets.isEmpty() && dirty.isEmpty() && !hasDirtyFromPreviousSync
95 #if defined(Q_WS_QWS) && !defined(QT_NO_QWS_MANAGER)
96 && !hasDirtyWindowDecoration()
101 // ### Qt 4.6: Merge into a template function (after MSVC isn't supported anymore).
102 void markDirty(const QRegion &rgn, QWidget *widget, bool updateImmediately = false,
103 bool invalidateBuffer = false);
104 void markDirty(const QRect &rect, QWidget *widget, bool updateImmediately = false,
105 bool invalidateBuffer = false);
109 QRegion dirtyOnScreen; // needsFlush
110 QRegion dirty; // needsRepaint
111 QRegion dirtyFromPreviousSync;
112 QVector<QWidget *> dirtyWidgets;
113 QVector<QWidget *> *dirtyOnScreenWidgets;
114 QList<QWidget *> staticWidgets;
115 QWindowSurface *windowSurface;
116 #ifdef Q_BACKINGSTORE_SUBSURFACES
117 QList<QWindowSurface*> subSurfaces;
119 uint hasDirtyFromPreviousSync : 1;
120 uint fullUpdatePending : 1;
124 static bool flushPaint(QWidget *widget, const QRegion &rgn);
125 static void unflushPaint(QWidget *widget, const QRegion &rgn);
127 bool bltRect(const QRect &rect, int dx, int dy, QWidget *widget);
128 void releaseBuffer();
130 void beginPaint(QRegion &toClean, QWidget *widget, QWindowSurface *windowSurface,
131 BeginPaintInfo *returnInfo, bool toCleanIsInTopLevelCoordinates = true);
132 void endPaint(const QRegion &cleaned, QWindowSurface *windowSurface, BeginPaintInfo *beginPaintInfo);
134 QRegion dirtyRegion(QWidget *widget = 0) const;
135 QRegion staticContents(QWidget *widget = 0, const QRect &withinClipRect = QRect()) const;
137 void markDirtyOnScreen(const QRegion &dirtyOnScreen, QWidget *widget, const QPoint &topLevelOffset);
139 void removeDirtyWidget(QWidget *w);
141 #if defined(Q_WS_QWS) && !defined(QT_NO_QWS_MANAGER)
142 bool hasDirtyWindowDecoration() const;
143 void paintWindowDecoration();
145 void updateLists(QWidget *widget);
147 inline void addDirtyWidget(QWidget *widget, const QRegion &rgn)
149 if (widget && !widget->d_func()->inDirtyList && !widget->data->in_destructor) {
150 QWidgetPrivate *widgetPrivate = widget->d_func();
151 #ifndef QT_NO_GRAPHICSEFFECT
152 if (widgetPrivate->graphicsEffect)
153 widgetPrivate->dirty = widgetPrivate->effectiveRectFor(rgn.boundingRect());
155 #endif //QT_NO_GRAPHICSEFFECT
156 widgetPrivate->dirty = rgn;
157 dirtyWidgets.append(widget);
158 widgetPrivate->inDirtyList = true;
162 inline void dirtyWidgetsRemoveAll(QWidget *widget)
165 while (i < dirtyWidgets.size()) {
166 if (dirtyWidgets.at(i) == widget)
167 dirtyWidgets.remove(i);
173 inline void addStaticWidget(QWidget *widget)
178 Q_ASSERT(widget->testAttribute(Qt::WA_StaticContents));
179 if (!staticWidgets.contains(widget))
180 staticWidgets.append(widget);
183 inline void removeStaticWidget(QWidget *widget)
184 { staticWidgets.removeAll(widget); }
186 // Move the reparented widget and all its static children from this backing store
187 // to the new backing store if reparented into another top-level / backing store.
188 inline void moveStaticWidgets(QWidget *reparented)
190 Q_ASSERT(reparented);
191 QWidgetBackingStore *newBs = reparented->d_func()->maybeBackingStore();
196 while (i < staticWidgets.size()) {
197 QWidget *w = staticWidgets.at(i);
198 if (reparented == w || reparented->isAncestorOf(w)) {
199 staticWidgets.removeAt(i);
201 newBs->addStaticWidget(w);
208 inline QRect topLevelRect() const
211 return tlw->frameGeometry();
213 return tlw->data->crect;
217 inline void appendDirtyOnScreenWidget(QWidget *widget)
222 if (!dirtyOnScreenWidgets) {
223 dirtyOnScreenWidgets = new QVector<QWidget *>;
224 dirtyOnScreenWidgets->append(widget);
225 } else if (!dirtyOnScreenWidgets->contains(widget)) {
226 dirtyOnScreenWidgets->append(widget);
230 inline void dirtyOnScreenWidgetsRemoveAll(QWidget *widget)
232 if (!widget || !dirtyOnScreenWidgets)
236 while (i < dirtyOnScreenWidgets->size()) {
237 if (dirtyOnScreenWidgets->at(i) == widget)
238 dirtyOnScreenWidgets->remove(i);
244 inline void resetWidget(QWidget *widget)
247 widget->d_func()->inDirtyList = false;
248 widget->d_func()->isScrolled = false;
249 widget->d_func()->isMoved = false;
250 widget->d_func()->dirty = QRegion();
254 inline void updateStaticContentsSize()
256 for (int i = 0; i < staticWidgets.size(); ++i) {
257 QWidgetPrivate *wd = staticWidgets.at(i)->d_func();
260 wd->extra->staticContentsSize = wd->data.crect.size();
264 inline bool hasStaticContents() const
265 { return !staticWidgets.isEmpty() && windowSurface->hasFeature(QWindowSurface::StaticContents); }
267 friend QRegion qt_dirtyRegion(QWidget *);
268 friend class QWidgetPrivate;
269 friend class QWidget;
270 friend class QWSManagerPrivate;
271 friend class QETWidget;
272 friend class QWindowSurface;
273 friend class QWSWindowSurface;
278 #endif // QBACKINGSTORE_P_H