OpenCoverage

qbackingstore.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/painting/qbackingstore.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtGui module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include <qbackingstore.h>-
41#include <qwindow.h>-
42#include <qpixmap.h>-
43#include <qpa/qplatformbackingstore.h>-
44#include <qpa/qplatformintegration.h>-
45#include <qscreen.h>-
46#include <qdebug.h>-
47#include <qscopedpointer.h>-
48-
49#include <private/qguiapplication_p.h>-
50#include <private/qwindow_p.h>-
51-
52#include <private/qhighdpiscaling_p.h>-
53-
54QT_BEGIN_NAMESPACE-
55-
56class QBackingStorePrivate-
57{-
58public:-
59 QBackingStorePrivate(QWindow *w)-
60 : window(w)-
61 {-
62 }
never executed: end of block
0
63-
64 QWindow *window;-
65 QPlatformBackingStore *platformBackingStore;-
66 QScopedPointer<QImage> highDpiBackingstore;-
67 QRegion staticContents;-
68 QSize size;-
69};-
70-
71/*!-
72 \class QBackingStore-
73 \since 5.0-
74 \inmodule QtGui-
75-
76 \brief The QBackingStore class provides a drawing area for QWindow.-
77-
78 QBackingStore enables the use of QPainter to paint on a QWindow with type-
79 RasterSurface. The other way of rendering to a QWindow is through the use-
80 of OpenGL with QOpenGLContext.-
81-
82 A QBackingStore contains a buffered representation of the window contents,-
83 and thus supports partial updates by using QPainter to only update a sub-
84 region of the window contents.-
85-
86 QBackingStore might be used by an application that wants to use QPainter-
87 without OpenGL acceleration and without the extra overhead of using the-
88 QWidget or QGraphicsView UI stacks. For an example of how to use-
89 QBackingStore see the \l{Raster Window Example}.-
90*/-
91-
92/*!-
93 Flushes the given \a region from the specified window \a win onto the-
94 screen.-
95-
96 Note that the \a offset parameter is currently unused.-
97*/-
98void QBackingStore::flush(const QRegion &region, QWindow *win, const QPoint &offset)-
99{-
100 if (!win)
!winDescription
TRUEnever evaluated
FALSEnever evaluated
0
101 win = window();
never executed: win = window();
0
102 if (!win->handle()) {
!win->handle()Description
TRUEnever evaluated
FALSEnever evaluated
0
103 qWarning() << "QBackingStore::flush() called for "-
104 << win << " which does not have a handle.";-
105 return;
never executed: return;
0
106 }-
107-
108#ifdef QBACKINGSTORE_DEBUG-
109 if (win && win->isTopLevel() && !qt_window_private(win)->receivedExpose) {-
110 qWarning().nospace() << "QBackingStore::flush() called with non-exposed window "-
111 << win << ", behavior is undefined";-
112 }-
113#endif-
114-
115 d_ptr->platformBackingStore->flush(win, QHighDpi::toNativeLocalRegion(region, win),-
116 QHighDpi::toNativeLocalPosition(offset, win));-
117}
never executed: end of block
0
118-
119/*!-
120 \fn QPaintDevice* QBackingStore::paintDevice()-
121-
122 Implement this function to return the appropriate paint device.-
123*/-
124QPaintDevice *QBackingStore::paintDevice()-
125{-
126 QPaintDevice *device = d_ptr->platformBackingStore->paintDevice();-
127-
128 if (QHighDpiScaling::isActive() && device->devType() == QInternal::Image)
QHighDpiScaling::isActive()Description
TRUEnever evaluated
FALSEnever evaluated
device->devTyp...nternal::ImageDescription
TRUEnever evaluated
FALSEnever evaluated
0
129 return d_ptr->highDpiBackingstore.data();
never executed: return d_ptr->highDpiBackingstore.data();
0
130-
131 return device;
never executed: return device;
0
132}-
133-
134/*!-
135 Constructs an empty surface for the given top-level \a window.-
136*/-
137QBackingStore::QBackingStore(QWindow *window)-
138 : d_ptr(new QBackingStorePrivate(window))-
139{-
140 d_ptr->platformBackingStore = QGuiApplicationPrivate::platformIntegration()->createPlatformBackingStore(window);-
141}
never executed: end of block
0
142-
143/*!-
144 Destroys this surface.-
145*/-
146QBackingStore::~QBackingStore()-
147{-
148 delete d_ptr->platformBackingStore;-
149}
never executed: end of block
0
150-
151/*!-
152 Returns a pointer to the top-level window associated with this-
153 surface.-
154*/-
155QWindow* QBackingStore::window() const-
156{-
157 return d_ptr->window;
never executed: return d_ptr->window;
0
158}-
159-
160/*!-
161 This function is called before painting onto the surface begins,-
162 with the \a region in which the painting will occur.-
163-
164 \sa endPaint(), paintDevice()-
165*/-
166-
167void QBackingStore::beginPaint(const QRegion &region)-
168{-
169 if (d_ptr->highDpiBackingstore &&
d_ptr->highDpiBackingstoreDescription
TRUEnever evaluated
FALSEnever evaluated
0
170 d_ptr->highDpiBackingstore->devicePixelRatio() != d_ptr->window->devicePixelRatio())
d_ptr->highDpi...cePixelRatio()Description
TRUEnever evaluated
FALSEnever evaluated
0
171 resize(size());
never executed: resize(size());
0
172-
173 d_ptr->platformBackingStore->beginPaint(QHighDpi::toNativeLocalRegion(region, d_ptr->window));-
174-
175 // When QtGui is applying a high-dpi scale factor the backing store-
176 // creates a "large" backing store image. This image needs to be-
177 // painted on as a high-dpi image, which is done by setting-
178 // devicePixelRatio. Do this on a separate image instance that shares-
179 // the image data to avoid having the new devicePixelRatio be propagated-
180 // back to the platform plugin.-
181 QPaintDevice *device = d_ptr->platformBackingStore->paintDevice();-
182 if (QHighDpiScaling::isActive() && device->devType() == QInternal::Image) {
QHighDpiScaling::isActive()Description
TRUEnever evaluated
FALSEnever evaluated
device->devTyp...nternal::ImageDescription
TRUEnever evaluated
FALSEnever evaluated
0
183 QImage *source = static_cast<QImage *>(device);-
184 const bool needsNewImage = d_ptr->highDpiBackingstore.isNull()
d_ptr->highDpi...store.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
185 || source->data_ptr() != d_ptr->highDpiBackingstore->data_ptr()
source->data_p...re->data_ptr()Description
TRUEnever evaluated
FALSEnever evaluated
0
186 || source->size() != d_ptr->highDpiBackingstore->size()
source->size()...gstore->size()Description
TRUEnever evaluated
FALSEnever evaluated
0
187 || source->devicePixelRatio() != d_ptr->highDpiBackingstore->devicePixelRatio();
source->device...cePixelRatio()Description
TRUEnever evaluated
FALSEnever evaluated
0
188 if (needsNewImage) {
needsNewImageDescription
TRUEnever evaluated
FALSEnever evaluated
0
189 qCDebug(lcScaling) << "QBackingStore::beginPaint new backingstore for" << d_ptr->window;
never executed: QMessageLogger(__FILE__, 189, __PRETTY_FUNCTION__, lcScaling().categoryName()).debug() << "QBackingStore::beginPaint new backingstore for" << d_ptr->window;
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
190 qCDebug(lcScaling) << " source size" << source->size() << "dpr" << source->devicePixelRatio();
never executed: QMessageLogger(__FILE__, 190, __PRETTY_FUNCTION__, lcScaling().categoryName()).debug() << " source size" << source->size() << "dpr" << source->devicePixelRatio();
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
191 d_ptr->highDpiBackingstore.reset(-
192 new QImage(source->bits(), source->width(), source->height(), source->bytesPerLine(), source->format()));-
193-
194 qreal targetDevicePixelRatio = d_ptr->window->devicePixelRatio();-
195 d_ptr->highDpiBackingstore->setDevicePixelRatio(targetDevicePixelRatio);-
196 qCDebug(lcScaling) <<" destination size" << d_ptr->highDpiBackingstore->size()
never executed: QMessageLogger(__FILE__, 196, __PRETTY_FUNCTION__, lcScaling().categoryName()).debug() <<" destination size" << d_ptr->highDpiBackingstore->size() << "dpr" << targetDevicePixelRatio;
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
197 << "dpr" << targetDevicePixelRatio;
never executed: QMessageLogger(__FILE__, 196, __PRETTY_FUNCTION__, lcScaling().categoryName()).debug() <<" destination size" << d_ptr->highDpiBackingstore->size() << "dpr" << targetDevicePixelRatio;
0
198 }
never executed: end of block
0
199 }
never executed: end of block
0
200}
never executed: end of block
0
201-
202/*!-
203 This function is called after painting onto the surface has ended.-
204-
205 \sa beginPaint(), paintDevice()-
206*/-
207void QBackingStore::endPaint()-
208{-
209 d_ptr->platformBackingStore->endPaint();-
210}
never executed: end of block
0
211-
212/*!-
213 Sets the size of the windowsurface to be \a size.-
214-
215 \sa size()-
216*/-
217void QBackingStore::resize(const QSize &size)-
218{-
219 d_ptr->size = size;-
220 d_ptr->platformBackingStore->resize(QHighDpi::toNativePixels(size, d_ptr->window), d_ptr->staticContents);-
221}
never executed: end of block
0
222-
223/*!-
224 Returns the current size of the windowsurface.-
225*/-
226QSize QBackingStore::size() const-
227{-
228 return d_ptr->size;
never executed: return d_ptr->size;
0
229}-
230-
231/*!-
232 Scrolls the given \a area \a dx pixels to the right and \a dy-
233 downward; both \a dx and \a dy may be negative.-
234-
235 Returns \c true if the area was scrolled successfully; false otherwise.-
236*/-
237bool QBackingStore::scroll(const QRegion &area, int dx, int dy)-
238{-
239 // Disable scrolling for non-integer scroll deltas. For this case-
240 // the the existing rendered pixels can't be re-used, and we return-
241 // false to signal that a repaint is needed.-
242 const qreal nativeDx = QHighDpi::toNativePixels(qreal(dx), d_ptr->window);-
243 const qreal nativeDy = QHighDpi::toNativePixels(qreal(dy), d_ptr->window);-
244 if (qFloor(nativeDx) != nativeDx || qFloor(nativeDy) != nativeDy)
qFloor(nativeDx) != nativeDxDescription
TRUEnever evaluated
FALSEnever evaluated
qFloor(nativeDy) != nativeDyDescription
TRUEnever evaluated
FALSEnever evaluated
0
245 return false;
never executed: return false;
0
246-
247 return d_ptr->platformBackingStore->scroll(QHighDpi::toNativeLocalRegion(area, d_ptr->window),
never executed: return d_ptr->platformBackingStore->scroll(QHighDpi::toNativeLocalRegion(area, d_ptr->window), nativeDx, nativeDy);
0
248 nativeDx, nativeDy);
never executed: return d_ptr->platformBackingStore->scroll(QHighDpi::toNativeLocalRegion(area, d_ptr->window), nativeDx, nativeDy);
0
249}-
250-
251/*!-
252 Set \a region as the static contents of this window.-
253*/-
254void QBackingStore::setStaticContents(const QRegion &region)-
255{-
256 d_ptr->staticContents = region;-
257}
never executed: end of block
0
258-
259/*!-
260 Returns a pointer to the QRegion that has the static contents-
261 of this window.-
262*/-
263QRegion QBackingStore::staticContents() const-
264{-
265 return d_ptr->staticContents;
never executed: return d_ptr->staticContents;
0
266}-
267-
268/*!-
269 Returns a boolean indicating if this window-
270 has static contents or not.-
271*/-
272bool QBackingStore::hasStaticContents() const-
273{-
274 return !d_ptr->staticContents.isEmpty();
never executed: return !d_ptr->staticContents.isEmpty();
0
275}-
276-
277void Q_GUI_EXPORT qt_scrollRectInImage(QImage &img, const QRect &rect, const QPoint &offset)-
278{-
279 // make sure we don't detach-
280 uchar *mem = const_cast<uchar*>(const_cast<const QImage &>(img).bits());-
281-
282 int lineskip = img.bytesPerLine();-
283 int depth = img.depth() >> 3;-
284-
285 const QRect imageRect(0, 0, img.width(), img.height());-
286 const QRect r = rect & imageRect & imageRect.translated(-offset);-
287 const QPoint p = rect.topLeft() + offset;-
288-
289 if (r.isEmpty())
r.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
290 return;
never executed: return;
0
291-
292 const uchar *src;-
293 uchar *dest;-
294-
295 if (r.top() < p.y()) {
r.top() < p.y()Description
TRUEnever evaluated
FALSEnever evaluated
0
296 src = mem + r.bottom() * lineskip + r.left() * depth;-
297 dest = mem + (p.y() + r.height() - 1) * lineskip + p.x() * depth;-
298 lineskip = -lineskip;-
299 } else {
never executed: end of block
0
300 src = mem + r.top() * lineskip + r.left() * depth;-
301 dest = mem + p.y() * lineskip + p.x() * depth;-
302 }
never executed: end of block
0
303-
304 const int w = r.width();-
305 int h = r.height();-
306 const int bytes = w * depth;-
307-
308 // overlapping segments?-
309 if (offset.y() == 0 && qAbs(offset.x()) < w) {
offset.y() == 0Description
TRUEnever evaluated
FALSEnever evaluated
qAbs(offset.x()) < wDescription
TRUEnever evaluated
FALSEnever evaluated
0
310 do {-
311 ::memmove(dest, src, bytes);-
312 dest += lineskip;-
313 src += lineskip;-
314 } while (--h);
never executed: end of block
--hDescription
TRUEnever evaluated
FALSEnever evaluated
0
315 } else {
never executed: end of block
0
316 do {-
317 ::memcpy(dest, src, bytes);-
318 dest += lineskip;-
319 src += lineskip;-
320 } while (--h);
never executed: end of block
--hDescription
TRUEnever evaluated
FALSEnever evaluated
0
321 }
never executed: end of block
0
322}-
323-
324/*!-
325 Returns a pointer to the QPlatformBackingStore implementation-
326*/-
327QPlatformBackingStore *QBackingStore::handle() const-
328{-
329 return d_ptr->platformBackingStore;
never executed: return d_ptr->platformBackingStore;
0
330}-
331-
332QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9