| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information ([email protected])
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the QtGui module of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 9 | ** Commercial Usage
|
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 13 | ** a written agreement between you and Nokia.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain
|
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|---|
| 26 | ** package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please
|
|---|
| 37 | ** contact the sales department at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #ifndef QBACKINGSTORE_P_H
|
|---|
| 43 | #define QBACKINGSTORE_P_H
|
|---|
| 44 |
|
|---|
| 45 | //
|
|---|
| 46 | // W A R N I N G
|
|---|
| 47 | // -------------
|
|---|
| 48 | //
|
|---|
| 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.
|
|---|
| 52 | //
|
|---|
| 53 | // We mean it.
|
|---|
| 54 | //
|
|---|
| 55 |
|
|---|
| 56 | #include <QDebug>
|
|---|
| 57 | #include <QtGui/qwidget.h>
|
|---|
| 58 | #include <private/qwidget_p.h>
|
|---|
| 59 | #include <private/qwindowsurface_p.h>
|
|---|
| 60 | #ifdef Q_WS_QWS
|
|---|
| 61 | #include <private/qwindowsurface_qws_p.h>
|
|---|
| 62 | #endif
|
|---|
| 63 |
|
|---|
| 64 | QT_BEGIN_NAMESPACE
|
|---|
| 65 |
|
|---|
| 66 | class QWindowSurface;
|
|---|
| 67 |
|
|---|
| 68 | struct BeginPaintInfo {
|
|---|
| 69 | inline BeginPaintInfo() : wasFlushed(0), nothingToPaint(0), windowSurfaceRecreated(0) {}
|
|---|
| 70 | uint wasFlushed : 1;
|
|---|
| 71 | uint nothingToPaint : 1;
|
|---|
| 72 | uint windowSurfaceRecreated : 1;
|
|---|
| 73 | };
|
|---|
| 74 |
|
|---|
| 75 | class Q_AUTOTEST_EXPORT QWidgetBackingStore
|
|---|
| 76 | {
|
|---|
| 77 | public:
|
|---|
| 78 | QWidgetBackingStore(QWidget *t);
|
|---|
| 79 | ~QWidgetBackingStore();
|
|---|
| 80 |
|
|---|
| 81 | static void showYellowThing(QWidget *widget, const QRegion &rgn, int msec, bool);
|
|---|
| 82 |
|
|---|
| 83 | void sync(QWidget *exposedWidget, const QRegion &exposedRegion);
|
|---|
| 84 | void sync();
|
|---|
| 85 | void flush(QWidget *widget = 0, QWindowSurface *surface = 0);
|
|---|
| 86 |
|
|---|
| 87 | inline QPoint topLevelOffset() const { return tlwOffset; }
|
|---|
| 88 |
|
|---|
| 89 | QWindowSurface *surface() const { return windowSurface; }
|
|---|
| 90 |
|
|---|
| 91 | inline bool isDirty() const
|
|---|
| 92 | {
|
|---|
| 93 | return !(dirtyWidgets.isEmpty() && dirty.isEmpty() && !hasDirtyFromPreviousSync
|
|---|
| 94 | #if defined(Q_WS_QWS) && !defined(QT_NO_QWS_MANAGER)
|
|---|
| 95 | && !hasDirtyWindowDecoration()
|
|---|
| 96 | #endif
|
|---|
| 97 | );
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | private:
|
|---|
| 101 | QWidget *tlw;
|
|---|
| 102 | QRegion dirtyOnScreen; // needsFlush
|
|---|
| 103 | QRegion dirty; // needsRepaint
|
|---|
| 104 | QRegion dirtyFromPreviousSync;
|
|---|
| 105 | QVector<QWidget *> dirtyWidgets;
|
|---|
| 106 | QVector<QWidget *> *dirtyOnScreenWidgets;
|
|---|
| 107 | QList<QWidget *> staticWidgets;
|
|---|
| 108 | QWindowSurface *windowSurface;
|
|---|
| 109 | #ifdef Q_BACKINGSTORE_SUBSURFACES
|
|---|
| 110 | QList<QWindowSurface*> subSurfaces;
|
|---|
| 111 | #endif
|
|---|
| 112 | bool hasDirtyFromPreviousSync;
|
|---|
| 113 |
|
|---|
| 114 | QPoint tlwOffset;
|
|---|
| 115 |
|
|---|
| 116 | static bool flushPaint(QWidget *widget, const QRegion &rgn);
|
|---|
| 117 | static void unflushPaint(QWidget *widget, const QRegion &rgn);
|
|---|
| 118 |
|
|---|
| 119 | bool bltRect(const QRect &rect, int dx, int dy, QWidget *widget);
|
|---|
| 120 | void releaseBuffer();
|
|---|
| 121 |
|
|---|
| 122 | void beginPaint(QRegion &toClean, QWidget *widget, QWindowSurface *windowSurface,
|
|---|
| 123 | BeginPaintInfo *returnInfo, bool toCleanIsInTopLevelCoordinates = true);
|
|---|
| 124 | void endPaint(const QRegion &cleaned, QWindowSurface *windowSurface, BeginPaintInfo *beginPaintInfo);
|
|---|
| 125 |
|
|---|
| 126 | QRegion dirtyRegion(QWidget *widget = 0) const;
|
|---|
| 127 | QRegion staticContents(QWidget *widget = 0, const QRect &withinClipRect = QRect()) const;
|
|---|
| 128 |
|
|---|
| 129 | // ### Qt 4.6: Merge into a template function (after MSVC isn't supported anymore).
|
|---|
| 130 | void markDirty(const QRegion &rgn, QWidget *widget, bool updateImmediately = false,
|
|---|
| 131 | bool invalidateBuffer = false);
|
|---|
| 132 | void markDirty(const QRect &rect, QWidget *widget, bool updateImmediately = false,
|
|---|
| 133 | bool invalidateBuffer = false);
|
|---|
| 134 | void markDirtyOnScreen(const QRegion &dirtyOnScreen, QWidget *widget, const QPoint &topLevelOffset);
|
|---|
| 135 |
|
|---|
| 136 | void removeDirtyWidget(QWidget *w);
|
|---|
| 137 |
|
|---|
| 138 | #if defined(Q_WS_QWS) && !defined(QT_NO_QWS_MANAGER)
|
|---|
| 139 | bool hasDirtyWindowDecoration() const;
|
|---|
| 140 | void paintWindowDecoration();
|
|---|
| 141 | #endif
|
|---|
| 142 | void updateLists(QWidget *widget);
|
|---|
| 143 |
|
|---|
| 144 | inline void addDirtyWidget(QWidget *widget, const QRegion &rgn)
|
|---|
| 145 | {
|
|---|
| 146 | if (widget && !widget->d_func()->inDirtyList && !widget->data->in_destructor) {
|
|---|
| 147 | widget->d_func()->dirty = rgn;
|
|---|
| 148 | dirtyWidgets.append(widget);
|
|---|
| 149 | widget->d_func()->inDirtyList = true;
|
|---|
| 150 | }
|
|---|
| 151 | }
|
|---|
| 152 |
|
|---|
| 153 | inline void dirtyWidgetsRemoveAll(QWidget *widget)
|
|---|
| 154 | {
|
|---|
| 155 | int i = 0;
|
|---|
| 156 | while (i < dirtyWidgets.size()) {
|
|---|
| 157 | if (dirtyWidgets.at(i) == widget)
|
|---|
| 158 | dirtyWidgets.remove(i);
|
|---|
| 159 | else
|
|---|
| 160 | ++i;
|
|---|
| 161 | }
|
|---|
| 162 | }
|
|---|
| 163 |
|
|---|
| 164 | inline void addStaticWidget(QWidget *widget)
|
|---|
| 165 | {
|
|---|
| 166 | if (!widget)
|
|---|
| 167 | return;
|
|---|
| 168 |
|
|---|
| 169 | Q_ASSERT(widget->testAttribute(Qt::WA_StaticContents));
|
|---|
| 170 | if (!staticWidgets.contains(widget))
|
|---|
| 171 | staticWidgets.append(widget);
|
|---|
| 172 | }
|
|---|
| 173 |
|
|---|
| 174 | inline void removeStaticWidget(QWidget *widget)
|
|---|
| 175 | { staticWidgets.removeAll(widget); }
|
|---|
| 176 |
|
|---|
| 177 | // Move the reparented widget and all its static children from this backing store
|
|---|
| 178 | // to the new backing store if reparented into another top-level / backing store.
|
|---|
| 179 | inline void moveStaticWidgets(QWidget *reparented)
|
|---|
| 180 | {
|
|---|
| 181 | Q_ASSERT(reparented);
|
|---|
| 182 | QWidgetBackingStore *newBs = reparented->d_func()->maybeBackingStore();
|
|---|
| 183 | if (newBs == this)
|
|---|
| 184 | return;
|
|---|
| 185 |
|
|---|
| 186 | int i = 0;
|
|---|
| 187 | while (i < staticWidgets.size()) {
|
|---|
| 188 | QWidget *w = staticWidgets.at(i);
|
|---|
| 189 | if (reparented == w || reparented->isAncestorOf(w)) {
|
|---|
| 190 | staticWidgets.removeAt(i);
|
|---|
| 191 | if (newBs)
|
|---|
| 192 | newBs->addStaticWidget(w);
|
|---|
| 193 | } else {
|
|---|
| 194 | ++i;
|
|---|
| 195 | }
|
|---|
| 196 | }
|
|---|
| 197 | }
|
|---|
| 198 |
|
|---|
| 199 | inline QRect topLevelRect() const
|
|---|
| 200 | {
|
|---|
| 201 | #ifdef Q_WS_QWS
|
|---|
| 202 | return tlw->frameGeometry();
|
|---|
| 203 | #endif
|
|---|
| 204 | return tlw->data->crect;
|
|---|
| 205 | }
|
|---|
| 206 |
|
|---|
| 207 | inline void appendDirtyOnScreenWidget(QWidget *widget)
|
|---|
| 208 | {
|
|---|
| 209 | if (!widget)
|
|---|
| 210 | return;
|
|---|
| 211 |
|
|---|
| 212 | if (!dirtyOnScreenWidgets) {
|
|---|
| 213 | dirtyOnScreenWidgets = new QVector<QWidget *>;
|
|---|
| 214 | dirtyOnScreenWidgets->append(widget);
|
|---|
| 215 | } else if (!dirtyOnScreenWidgets->contains(widget)) {
|
|---|
| 216 | dirtyOnScreenWidgets->append(widget);
|
|---|
| 217 | }
|
|---|
| 218 | }
|
|---|
| 219 |
|
|---|
| 220 | inline void dirtyOnScreenWidgetsRemoveAll(QWidget *widget)
|
|---|
| 221 | {
|
|---|
| 222 | if (!widget || !dirtyOnScreenWidgets)
|
|---|
| 223 | return;
|
|---|
| 224 |
|
|---|
| 225 | int i = 0;
|
|---|
| 226 | while (i < dirtyOnScreenWidgets->size()) {
|
|---|
| 227 | if (dirtyOnScreenWidgets->at(i) == widget)
|
|---|
| 228 | dirtyOnScreenWidgets->remove(i);
|
|---|
| 229 | else
|
|---|
| 230 | ++i;
|
|---|
| 231 | }
|
|---|
| 232 | }
|
|---|
| 233 |
|
|---|
| 234 | inline void resetWidget(QWidget *widget)
|
|---|
| 235 | {
|
|---|
| 236 | if (widget) {
|
|---|
| 237 | widget->d_func()->inDirtyList = false;
|
|---|
| 238 | widget->d_func()->isScrolled = false;
|
|---|
| 239 | widget->d_func()->isMoved = false;
|
|---|
| 240 | widget->d_func()->dirty = QRegion();
|
|---|
| 241 | }
|
|---|
| 242 | }
|
|---|
| 243 |
|
|---|
| 244 | inline void updateStaticContentsSize()
|
|---|
| 245 | {
|
|---|
| 246 | for (int i = 0; i < staticWidgets.size(); ++i) {
|
|---|
| 247 | QWidgetPrivate *wd = staticWidgets.at(i)->d_func();
|
|---|
| 248 | if (!wd->extra)
|
|---|
| 249 | wd->createExtra();
|
|---|
| 250 | wd->extra->staticContentsSize = wd->data.crect.size();
|
|---|
| 251 | }
|
|---|
| 252 | }
|
|---|
| 253 |
|
|---|
| 254 | inline bool hasStaticContents() const
|
|---|
| 255 | { return !staticWidgets.isEmpty() && windowSurface->hasStaticContentsSupport(); }
|
|---|
| 256 |
|
|---|
| 257 | friend QRegion qt_dirtyRegion(QWidget *);
|
|---|
| 258 | friend class QWidgetPrivate;
|
|---|
| 259 | friend class QWidget;
|
|---|
| 260 | friend class QWSManagerPrivate;
|
|---|
| 261 | friend class QETWidget;
|
|---|
| 262 | friend class QWindowSurface;
|
|---|
| 263 | friend class QWSWindowSurface;
|
|---|
| 264 | };
|
|---|
| 265 |
|
|---|
| 266 | QT_END_NAMESPACE
|
|---|
| 267 |
|
|---|
| 268 | #endif // QBACKINGSTORE_P_H
|
|---|