author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 08 Apr 2010 14:19:33 +0300 | |
branch | RCL_3 |
changeset 8 | 3f74d0d4af4c |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
7 |
** This file is part of the QtGui module of the Qt Toolkit. |
0 | 8 |
** |
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
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 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include <qglobal.h> // for Q_WS_WIN define (non-PCH) |
|
43 |
||
44 |
#include <QtGui/qpaintdevice.h> |
|
45 |
#include <private/qwidget_p.h> |
|
46 |
#include "qwindowsurface_s60_p.h" |
|
47 |
#include "qpixmap_s60_p.h" |
|
48 |
#include "qt_s60_p.h" |
|
49 |
#include "private/qdrawhelper_p.h" |
|
50 |
||
51 |
QT_BEGIN_NAMESPACE |
|
52 |
||
53 |
struct QS60WindowSurfacePrivate |
|
54 |
{ |
|
55 |
QPixmap device; |
|
56 |
QList<QImage*> bufferImages; |
|
57 |
}; |
|
58 |
||
59 |
QS60WindowSurface::QS60WindowSurface(QWidget* widget) |
|
60 |
: QWindowSurface(widget), d_ptr(new QS60WindowSurfacePrivate) |
|
61 |
{ |
|
62 |
||
63 |
TDisplayMode mode = S60->screenDevice()->DisplayMode(); |
|
64 |
bool isOpaque = qt_widget_private(widget)->isOpaque; |
|
65 |
if (mode == EColor16MA && isOpaque) |
|
66 |
mode = EColor16MU; // Faster since 16MU -> 16MA is typically accelerated |
|
67 |
else if (mode == EColor16MU && !isOpaque) |
|
68 |
mode = EColor16MA; // Try for transparency anyway |
|
69 |
||
70 |
// We create empty CFbsBitmap here -> it will be resized in setGeometry |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
71 |
CFbsBitmap *bitmap = q_check_ptr(new CFbsBitmap); // CBase derived object needs check on new |
0 | 72 |
qt_symbian_throwIfError( bitmap->Create( TSize(0, 0), mode ) ); |
8
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
73 |
|
0 | 74 |
QS60PixmapData *data = new QS60PixmapData(QPixmapData::PixmapType); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
75 |
if (data) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
76 |
data->fromSymbianBitmap(bitmap, true); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
77 |
d_ptr->device = QPixmap(data); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
78 |
} |
8
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
79 |
|
0 | 80 |
setStaticContentsSupport(true); |
81 |
} |
|
82 |
QS60WindowSurface::~QS60WindowSurface() |
|
83 |
{ |
|
84 |
delete d_ptr; |
|
85 |
} |
|
86 |
||
87 |
void QS60WindowSurface::beginPaint(const QRegion &rgn) |
|
88 |
{ |
|
89 |
if (!qt_widget_private(window())->isOpaque) { |
|
90 |
QS60PixmapData *pixmapData = static_cast<QS60PixmapData *>(d_ptr->device.data_ptr().data()); |
|
91 |
pixmapData->beginDataAccess(); |
|
92 |
||
8
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
93 |
QPainter p(&pixmapData->image); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
94 |
p.setCompositionMode(QPainter::CompositionMode_Source); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
95 |
const QVector<QRect> rects = rgn.rects(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
96 |
const QColor blank = Qt::transparent; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
97 |
for (QVector<QRect>::const_iterator it = rects.begin(); it != rects.end(); ++it) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
98 |
p.fillRect(*it, blank); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
99 |
} |
0 | 100 |
|
101 |
pixmapData->endDataAccess(); |
|
102 |
} |
|
103 |
} |
|
104 |
||
105 |
void QS60WindowSurface::endPaint(const QRegion &) |
|
106 |
{ |
|
107 |
qDeleteAll(d_ptr->bufferImages); |
|
108 |
d_ptr->bufferImages.clear(); |
|
109 |
} |
|
110 |
||
111 |
QImage* QS60WindowSurface::buffer(const QWidget *widget) |
|
112 |
{ |
|
113 |
if (widget->window() != window()) |
|
114 |
return 0; |
|
115 |
||
116 |
QPaintDevice *pdev = paintDevice(); |
|
117 |
if (!pdev) |
|
118 |
return 0; |
|
119 |
||
120 |
const QPoint off = offset(widget); |
|
121 |
QImage *img = &(static_cast<QS60PixmapData *>(d_ptr->device.data_ptr().data())->image); |
|
8
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
122 |
|
0 | 123 |
QRect rect(off, widget->size()); |
124 |
rect &= QRect(QPoint(), img->size()); |
|
125 |
||
126 |
if (rect.isEmpty()) |
|
127 |
return 0; |
|
128 |
||
129 |
img = new QImage(img->scanLine(rect.y()) + rect.x() * img->depth() / 8, |
|
130 |
rect.width(), rect.height(), |
|
131 |
img->bytesPerLine(), img->format()); |
|
132 |
d_ptr->bufferImages.append(img); |
|
133 |
||
134 |
return img; |
|
135 |
} |
|
136 |
||
137 |
void QS60WindowSurface::flush(QWidget *widget, const QRegion ®ion, const QPoint &) |
|
138 |
{ |
|
8
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
139 |
QWidget *window = widget->window(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
140 |
Q_ASSERT(window); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
141 |
QTLWExtra *topExtra = window->d_func()->maybeTopData(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
142 |
Q_ASSERT(topExtra); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
143 |
QRect qr = region.boundingRect(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
144 |
if (!topExtra->inExpose) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
145 |
topExtra->inExpose = true; // Prevent DrawNow() from calling syncBackingStore() again |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
146 |
TRect tr = qt_QRect2TRect(qr); |
0 | 147 |
widget->winId()->DrawNow(tr); |
8
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
148 |
topExtra->inExpose = false; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
149 |
} else { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
150 |
// This handles the case when syncBackingStore updates content outside of the |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
151 |
// original drawing rectangle. This might happen if there are pending update() |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
152 |
// events at the same time as we get a Draw() from Symbian. |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
153 |
QRect drawRect = qt_TRect2QRect(widget->winId()->DrawableWindow()->GetDrawRect()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
154 |
if (!drawRect.contains(qr)) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
155 |
widget->winId()->DrawDeferred(); |
0 | 156 |
} |
157 |
} |
|
158 |
||
159 |
bool QS60WindowSurface::scroll(const QRegion &area, int dx, int dy) |
|
160 |
{ |
|
161 |
QRect rect = area.boundingRect(); |
|
162 |
||
163 |
if (dx == 0 && dy == 0) |
|
164 |
return false; |
|
165 |
||
166 |
if (d_ptr->device.isNull()) |
|
167 |
return false; |
|
168 |
||
169 |
QS60PixmapData *data = static_cast<QS60PixmapData*>(d_ptr->device.data_ptr().data()); |
|
170 |
data->scroll(dx, dy, rect); |
|
171 |
||
172 |
return true; |
|
173 |
} |
|
174 |
||
175 |
QPaintDevice* QS60WindowSurface::paintDevice() |
|
176 |
{ |
|
177 |
return &d_ptr->device; |
|
178 |
} |
|
179 |
||
180 |
void QS60WindowSurface::setGeometry(const QRect& rect) |
|
181 |
{ |
|
182 |
if (rect == geometry()) |
|
183 |
return; |
|
184 |
||
185 |
QS60PixmapData *data = static_cast<QS60PixmapData*>(d_ptr->device.data_ptr().data()); |
|
186 |
data->resize(rect.width(), rect.height()); |
|
187 |
||
188 |
QWindowSurface::setGeometry(rect); |
|
189 |
} |
|
190 |
||
191 |
CFbsBitmap* QS60WindowSurface::symbianBitmap() const |
|
192 |
{ |
|
193 |
QS60PixmapData *data = static_cast<QS60PixmapData*>(d_ptr->device.data_ptr().data()); |
|
194 |
return data->cfbsBitmap; |
|
195 |
} |
|
196 |
||
197 |
QT_END_NAMESPACE |
|
198 |