source: trunk/src/gui/painting/qwindowsurface_raster.cpp@ 938

Last change on this file since 938 was 846, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 23.7 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtGui module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this 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 have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include <qdebug.h>
43
44#include <qglobal.h> // for Q_WS_WIN define (non-PCH)
45#ifdef Q_WS_WIN
46#include <qlibrary.h>
47#include <qt_windows.h>
48#endif
49
50#include <QtGui/qpaintdevice.h>
51#include <QtGui/qwidget.h>
52
53#include "private/qwindowsurface_raster_p.h"
54#include "private/qnativeimage_p.h"
55#include "private/qwidget_p.h"
56
57#ifdef Q_WS_X11
58#include "private/qpixmap_x11_p.h"
59#include "private/qt_x11_p.h"
60#include "private/qwidget_p.h"
61#include "qx11info_x11.h"
62#endif
63#include "private/qdrawhelper_p.h"
64
65#ifdef Q_WS_MAC
66#include <private/qt_cocoa_helpers_mac_p.h>
67#endif
68
69#if defined(Q_WS_PM) && defined(QT_LOG_BLITSPEED)
70#include <InnotekLIBC/FastInfoBlocks.h>
71#endif
72
73#if defined(Q_WS_PM)
74LONG APIENTRY GpiQueryYInversion(HPS hps);
75BOOL APIENTRY GpiEnableYInversion(HPS hps, LONG lHeight);
76#define QT_BITMAP_MIRROR 3 // 1 = QImage.mirrored()
77 // 2 = GpiEnableYInversion()
78 // 3 = GPI Matrix (seems to be the fastest)
79#endif
80
81QT_BEGIN_NAMESPACE
82
83#if defined(Q_WS_PM) && defined(QT_LOG_BLITSPEED)
84unsigned long long qt_total_blit_ms = 0;
85unsigned long long qt_total_blit_pixels = 0;
86#endif
87
88class QRasterWindowSurfacePrivate
89{
90public:
91 QNativeImage *image;
92
93#ifdef Q_WS_X11
94 GC gc;
95#ifndef QT_NO_XRENDER
96 uint translucentBackground : 1;
97#endif
98#endif
99 uint inSetGeometry : 1;
100};
101
102QRasterWindowSurface::QRasterWindowSurface(QWidget *window)
103 : QWindowSurface(window), d_ptr(new QRasterWindowSurfacePrivate)
104{
105#ifdef Q_WS_X11
106 d_ptr->gc = XCreateGC(X11->display, window->handle(), 0, 0);
107#ifndef QT_NO_XRENDER
108 d_ptr->translucentBackground = X11->use_xrender
109 && window->x11Info().depth() == 32;
110#endif
111#endif
112 d_ptr->image = 0;
113 d_ptr->inSetGeometry = false;
114 setStaticContentsSupport(true);
115}
116
117
118QRasterWindowSurface::~QRasterWindowSurface()
119{
120#ifdef Q_WS_X11
121 XFreeGC(X11->display, d_ptr->gc);
122#endif
123 if (d_ptr->image)
124 delete d_ptr->image;
125}
126
127
128QPaintDevice *QRasterWindowSurface::paintDevice()
129{
130 return &d_ptr->image->image;
131}
132
133void QRasterWindowSurface::beginPaint(const QRegion &rgn)
134{
135#if (defined(Q_WS_X11) && !defined(QT_NO_XRENDER)) || (defined(Q_WS_WIN) && !defined(Q_WS_WINCE))
136 if (!qt_widget_private(window())->isOpaque && window()->testAttribute(Qt::WA_TranslucentBackground)) {
137#if defined(Q_WS_WIN) && !defined(Q_WS_WINCE)
138 if (d_ptr->image->image.format() != QImage::Format_ARGB32_Premultiplied)
139 prepareBuffer(QImage::Format_ARGB32_Premultiplied, window());
140#endif
141 QPainter p(&d_ptr->image->image);
142 p.setCompositionMode(QPainter::CompositionMode_Source);
143 const QVector<QRect> rects = rgn.rects();
144 const QColor blank = Qt::transparent;
145 for (QVector<QRect>::const_iterator it = rects.begin(); it != rects.end(); ++it) {
146 p.fillRect(*it, blank);
147 }
148 }
149#else
150 Q_UNUSED(rgn);
151#endif
152}
153
154void QRasterWindowSurface::flush(QWidget *widget, const QRegion &rgn, const QPoint &offset)
155{
156 Q_D(QRasterWindowSurface);
157
158 // Not ready for painting yet, bail out. This can happen in
159 // QWidget::create_sys()
160 if (!d->image || rgn.rectCount() == 0)
161 return;
162
163#ifdef Q_WS_WIN
164 QRect br = rgn.boundingRect();