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 plugins 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 "qwindowsbackingstore.h"
43 #include "qwindowswindow.h"
44 #include "qwindowsnativeimage.h"
45 #include "qwindowscontext.h"
47 #include <QtGui/QWindow>
49 #include <QtCore/QDebug>
54 \class QWindowsBackingStore
55 \brief Backing store for windows.
56 \ingroup qt-lighthouse-win
59 QWindowsBackingStore::QWindowsBackingStore(QWindow *window) :
60 QPlatformBackingStore(window)
62 if (QWindowsContext::verboseBackingStore)
63 qDebug() << __FUNCTION__ << this << window;
66 QWindowsBackingStore::~QWindowsBackingStore()
68 if (QWindowsContext::verboseBackingStore)
69 qDebug() << __FUNCTION__ << this;
72 QPaintDevice *QWindowsBackingStore::paintDevice()
74 Q_ASSERT(!m_image.isNull());
75 return &m_image->image();
78 void QWindowsBackingStore::flush(QWindow *window, const QRegion ®ion,
82 // TODO: Prepare paint for translucent windows.
83 const QRect br = region.boundingRect();
84 if (QWindowsContext::verboseBackingStore > 1)
85 qDebug() << __FUNCTION__ << window << offset << br;
86 QWindowsWindow *rw = QWindowsWindow::baseWindowOf(window);
87 const HDC dc = rw->getDC();
89 qErrnoWarning("%s: GetDC failed", __FUNCTION__);
93 if (!BitBlt(dc, br.x(), br.y(), br.width(), br.height(),
94 m_image->hdc(), br.x() + offset.x(), br.y() + offset.y(), SRCCOPY))
95 qErrnoWarning("%s: BitBlt failed", __FUNCTION__);
97 // Write image for debug purposes.
98 if (QWindowsContext::verboseBackingStore > 2) {
100 const QString fileName = QString::fromLatin1("win%1_%2.png").
101 arg(rw->winId()).arg(n++);
102 m_image->image().save(fileName);
103 qDebug() << "Wrote " << m_image->image().size() << fileName;
107 void QWindowsBackingStore::resize(const QSize &size, const QRegion ®ion)
109 if (m_image.isNull() || m_image->image().size() != size) {
110 #ifndef QT_NO_DEBUG_OUTPUT
111 if (QWindowsContext::verboseBackingStore) {
112 QDebug nsp = qDebug().nospace();
113 nsp << __FUNCTION__ << ' ' << rasterWindow()->window()
114 << ' ' << size << ' ' << region;
115 if (!m_image.isNull())
116 nsp << " from: " << m_image->image().size();
119 m_image.reset(new QWindowsNativeImage(size.width(), size.height(),
120 QWindowsNativeImage::systemFormat()));
124 void QWindowsBackingStore::beginPaint(const QRegion ®ion)
127 if (QWindowsContext::verboseBackingStore > 1)
128 qDebug() << __FUNCTION__;
131 QWindowsWindow *QWindowsBackingStore::rasterWindow() const
133 if (const QWindow *w = window())
134 if (QPlatformWindow *pw = w->handle())
135 return static_cast<QWindowsWindow *>(pw);
139 HDC QWindowsBackingStore::getDC() const
141 if (!m_image.isNull())
142 return m_image->hdc();