1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtGui module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include <qbackingstore.h>
45 #include <qpa/qplatformbackingstore.h>
46 #include <qpa/qplatformintegration.h>
49 #include <private/qguiapplication_p.h>
50 #include <private/qwindow_p.h>
54 class QBackingStorePrivate
57 QBackingStorePrivate(QWindow *w)
63 QPlatformBackingStore *platformBackingStore;
64 QRegion staticContents;
72 \brief The QBackingStore class provides the drawing area for top-level windows.
76 Flushes the given \a region from the specified \a window onto the
79 Note that the \a offset parameter is currently unused.
81 void QBackingStore::flush(const QRegion ®ion, QWindow *win, const QPoint &offset)
86 if (win && !qt_window_private(win)->receivedExpose)
87 qWarning("QBackingStore::flush() called with non-exposed window, behavior is undefined");
89 d_ptr->platformBackingStore->flush(win, region, offset);
93 \fn QPaintDevice* QBackingStore::paintDevice()
95 Implement this function to return the appropriate paint device.
97 QPaintDevice *QBackingStore::paintDevice()
99 return d_ptr->platformBackingStore->paintDevice();
103 Constructs an empty surface for the given top-level \a window.
105 QBackingStore::QBackingStore(QWindow *window)
106 : d_ptr(new QBackingStorePrivate(window))
108 d_ptr->platformBackingStore = QGuiApplicationPrivate::platformIntegration()->createPlatformBackingStore(window);
112 Destroys this surface.
114 QBackingStore::~QBackingStore()
116 delete d_ptr->platformBackingStore;
120 Returns a pointer to the top-level window associated with this
123 QWindow* QBackingStore::window() const
125 return d_ptr->window;
129 This function is called before painting onto the surface begins,
130 with the \a region in which the painting will occur.
132 \sa endPaint(), paintDevice()
135 void QBackingStore::beginPaint(const QRegion ®ion)
137 d_ptr->platformBackingStore->beginPaint(region);
141 This function is called after painting onto the surface has ended.
143 \sa beginPaint(), paintDevice()
145 void QBackingStore::endPaint()
147 d_ptr->platformBackingStore->endPaint();
151 Sets the size of the windowsurface to be \a size.
155 void QBackingStore::resize(const QSize &size)
158 d_ptr->platformBackingStore->resize(size, d_ptr->staticContents);
162 Returns the current size of the windowsurface.
164 QSize QBackingStore::size() const
170 Scrolls the given \a area \a dx pixels to the right and \a dy
171 downward; both \a dx and \a dy may be negative.
173 Returns true if the area was scrolled successfully; false otherwise.
175 bool QBackingStore::scroll(const QRegion &area, int dx, int dy)
181 return d_ptr->platformBackingStore->scroll(area, dx, dy);
184 void QBackingStore::setStaticContents(const QRegion ®ion)
186 d_ptr->staticContents = region;
189 QRegion QBackingStore::staticContents() const
191 return d_ptr->staticContents;
194 bool QBackingStore::hasStaticContents() const
196 return !d_ptr->staticContents.isEmpty();
199 void Q_GUI_EXPORT qt_scrollRectInImage(QImage &img, const QRect &rect, const QPoint &offset)
201 // make sure we don't detach
202 uchar *mem = const_cast<uchar*>(const_cast<const QImage &>(img).bits());
204 int lineskip = img.bytesPerLine();
205 int depth = img.depth() >> 3;
207 const QRect imageRect(0, 0, img.width(), img.height());
208 const QRect r = rect & imageRect & imageRect.translated(-offset);
209 const QPoint p = rect.topLeft() + offset;
217 if (r.top() < p.y()) {
218 src = mem + r.bottom() * lineskip + r.left() * depth;
219 dest = mem + (p.y() + r.height() - 1) * lineskip + p.x() * depth;
220 lineskip = -lineskip;
222 src = mem + r.top() * lineskip + r.left() * depth;
223 dest = mem + p.y() * lineskip + p.x() * depth;
226 const int w = r.width();
228 const int bytes = w * depth;
230 // overlapping segments?
231 if (offset.y() == 0 && qAbs(offset.x()) < w) {
233 ::memmove(dest, src, bytes);
239 ::memcpy(dest, src, bytes);
246 QPlatformBackingStore *QBackingStore::handle() const
248 return d_ptr->platformBackingStore;