author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 04 Oct 2010 01:19:32 +0300 | |
changeset 37 | 758a864f9613 |
parent 33 | 3e2da88830cd |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
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 |
#include <exception> |
|
42 |
#include <w32std.h> |
|
43 |
#include <fbs.h> |
|
44 |
||
45 |
#include <private/qapplication_p.h> |
|
46 |
#include <private/qgraphicssystem_p.h> |
|
47 |
#include <private/qt_s60_p.h> |
|
48 |
#include <private/qpaintengine_s60_p.h> |
|
49 |
||
50 |
#include "qpixmap.h" |
|
51 |
#include "qpixmap_raster_p.h" |
|
52 |
#include <qwidget.h> |
|
53 |
#include "qpixmap_s60_p.h" |
|
54 |
#include "qnativeimage_p.h" |
|
55 |
#include "qbitmap.h" |
|
56 |
#include "qimage.h" |
|
57 |
#include "qimage_p.h" |
|
58 |
||
59 |
#include <fbs.h> |
|
60 |
||
61 |
QT_BEGIN_NAMESPACE |
|
62 |
||
63 |
const uchar qt_pixmap_bit_mask[] = { 0x01, 0x02, 0x04, 0x08, |
|
64 |
0x10, 0x20, 0x40, 0x80 }; |
|
65 |
||
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
66 |
static bool cleanup_function_registered = false; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
67 |
static QS60PixmapData *firstPixmap = 0; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
68 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
69 |
void qt_symbian_register_pixmap(QS60PixmapData *pd) |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
70 |
{ |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
71 |
if(!cleanup_function_registered) { |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
72 |
qAddPostRoutine(qt_symbian_release_pixmaps); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
73 |
cleanup_function_registered = true; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
74 |
} |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
75 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
76 |
pd->next = firstPixmap; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
77 |
pd->prev = 0; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
78 |
if (firstPixmap) |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
79 |
firstPixmap->prev = pd; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
80 |
firstPixmap = pd; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
81 |
} |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
82 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
83 |
void qt_symbian_unregister_pixmap(QS60PixmapData *pd) |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
84 |
{ |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
85 |
if (pd->next) |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
86 |
pd->next->prev = pd->prev; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
87 |
if (pd->prev) |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
88 |
pd->prev->next = pd->next; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
89 |
else |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
90 |
firstPixmap = pd->next; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
91 |
} |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
92 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
93 |
void qt_symbian_release_pixmaps() |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
94 |
{ |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
95 |
// Scan all QS60PixmapData objects in the system and destroy them. |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
96 |
QS60PixmapData *pd = firstPixmap; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
97 |
while (pd != 0) { |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
98 |
pd->release(); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
99 |
pd = pd->next; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
100 |
} |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
101 |
} |
0 | 102 |
|
103 |
/* |
|
104 |
\class QSymbianFbsClient |
|
105 |
\since 4.6 |
|
106 |
\internal |
|
107 |
||
108 |
Symbian Font And Bitmap server client that is |
|
109 |
used to lock the global bitmap heap. Only used in |
|
110 |
S60 v3.1 and S60 v3.2. |
|
111 |
*/ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
112 |
_LIT(KFBSERVLargeBitmapAccessName,"FbsLargeBitmapAccess"); |
0 | 113 |
class QSymbianFbsClient |
114 |
{ |
|
115 |
public: |
|
116 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
117 |
QSymbianFbsClient() : heapLocked(false) |
0 | 118 |
{ |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
119 |
heapLock.OpenGlobal(KFBSERVLargeBitmapAccessName); |
0 | 120 |
} |
121 |
||
122 |
~QSymbianFbsClient() |
|
123 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
124 |
heapLock.Close(); |
0 | 125 |
} |
126 |
||
127 |
bool lockHeap() |
|
128 |
{ |
|
129 |
bool wasLocked = heapLocked; |
|
130 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
131 |
if (heapLock.Handle() && !heapLocked) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
132 |
heapLock.Wait(); |
0 | 133 |
heapLocked = true; |
134 |
} |
|
135 |
||
136 |
return wasLocked; |
|
137 |
} |
|
138 |
||
139 |
bool unlockHeap() |
|
140 |
{ |
|
141 |
bool wasLocked = heapLocked; |
|
142 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
143 |
if (heapLock.Handle() && heapLocked) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
144 |
heapLock.Signal(); |
0 | 145 |
heapLocked = false; |
146 |
} |
|
147 |
||
148 |
return wasLocked; |
|
149 |
} |
|
150 |
||
151 |
||
152 |
private: |
|
153 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
154 |
RMutex heapLock; |
0 | 155 |
bool heapLocked; |
156 |
}; |
|
157 |
||
158 |
Q_GLOBAL_STATIC(QSymbianFbsClient, qt_symbianFbsClient); |
|
159 |
||
160 |
||
161 |
||
162 |
// QSymbianFbsHeapLock |
|
163 |
||
164 |
QSymbianFbsHeapLock::QSymbianFbsHeapLock(LockAction a) |
|
165 |
: action(a), wasLocked(false) |
|
166 |
{ |
|
167 |
QSysInfo::SymbianVersion symbianVersion = QSysInfo::symbianVersion(); |
|
168 |
if (symbianVersion == QSysInfo::SV_9_2 || symbianVersion == QSysInfo::SV_9_3) |
|
169 |
wasLocked = qt_symbianFbsClient()->unlockHeap(); |
|
170 |
} |
|
171 |
||
172 |
QSymbianFbsHeapLock::~QSymbianFbsHeapLock() |
|
173 |
{ |
|
174 |
// Do nothing |
|
175 |
} |
|
176 |
||
177 |
void QSymbianFbsHeapLock::relock() |
|
178 |
{ |
|
179 |
QSysInfo::SymbianVersion symbianVersion = QSysInfo::symbianVersion(); |
|
180 |
if (wasLocked && (symbianVersion == QSysInfo::SV_9_2 || symbianVersion == QSysInfo::SV_9_3)) |
|
181 |
qt_symbianFbsClient()->lockHeap(); |
|
182 |
} |
|
183 |
||
184 |
/* |
|
185 |
\class QSymbianBitmapDataAccess |
|
186 |
\since 4.6 |
|
187 |
\internal |
|
188 |
||
189 |
Data access class that is used to locks/unlocks pixel data |
|
190 |
when drawing or modifying CFbsBitmap pixel data. |
|
191 |
*/ |
|
192 |
class QSymbianBitmapDataAccess |
|
193 |
{ |
|
194 |
public: |
|
195 |
||
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
196 |
static int heapRefCount; |
0 | 197 |
QSysInfo::SymbianVersion symbianVersion; |
198 |
||
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
199 |
explicit QSymbianBitmapDataAccess() |
0 | 200 |
{ |
201 |
symbianVersion = QSysInfo::symbianVersion(); |
|
202 |
}; |
|
203 |
||
204 |
~QSymbianBitmapDataAccess() {}; |
|
205 |
||
206 |
inline void beginDataAccess(CFbsBitmap *bitmap) |
|
207 |
{ |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
208 |
if (symbianVersion == QSysInfo::SV_9_2) { |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
209 |
if (heapRefCount == 0) |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
210 |
qt_symbianFbsClient()->lockHeap(); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
211 |
} else { |
0 | 212 |
bitmap->LockHeap(ETrue); |
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
213 |
} |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
214 |
|
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
215 |
heapRefCount++; |
0 | 216 |
} |
217 |
||
218 |
inline void endDataAccess(CFbsBitmap *bitmap) |
|
219 |
{ |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
220 |
heapRefCount--; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
221 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
222 |
if (symbianVersion == QSysInfo::SV_9_2) { |
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
223 |
if (heapRefCount == 0) |
0 | 224 |
qt_symbianFbsClient()->unlockHeap(); |
225 |
} else { |
|
226 |
bitmap->UnlockHeap(ETrue); |
|
227 |
} |
|
228 |
} |
|
229 |
}; |
|
230 |
||
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
231 |
int QSymbianBitmapDataAccess::heapRefCount = 0; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
232 |
|
0 | 233 |
|
234 |
#define UPDATE_BUFFER() \ |
|
235 |
{ \ |
|
236 |
beginDataAccess(); \ |
|
237 |
endDataAccess(); \ |
|
238 |
} |
|
239 |
||
240 |
||
241 |
static CFbsBitmap* createSymbianCFbsBitmap(const TSize& size, TDisplayMode mode) |
|
242 |
{ |
|
243 |
QSymbianFbsHeapLock lock(QSymbianFbsHeapLock::Unlock); |
|
244 |
||
245 |
CFbsBitmap* bitmap = 0; |
|
246 |
QT_TRAP_THROWING(bitmap = new (ELeave) CFbsBitmap); |
|
247 |
||
248 |
if (bitmap->Create(size, mode) != KErrNone) { |
|
249 |
delete bitmap; |
|
250 |
bitmap = 0; |
|
251 |
} |
|
252 |
||
253 |
lock.relock(); |
|
254 |
||
255 |
return bitmap; |
|
256 |
} |
|
257 |
||
258 |
static CFbsBitmap* uncompress(CFbsBitmap* bitmap) |
|
259 |
{ |
|
260 |
if(bitmap->IsCompressedInRAM()) { |
|
261 |
QSymbianFbsHeapLock lock(QSymbianFbsHeapLock::Unlock); |
|
262 |
||
263 |
CFbsBitmap *uncompressed = 0; |
|
264 |
QT_TRAP_THROWING(uncompressed = new (ELeave) CFbsBitmap); |
|
265 |
||
266 |
if (uncompressed->Create(bitmap->SizeInPixels(), bitmap->DisplayMode()) != KErrNone) { |
|
267 |
delete bitmap; |
|
268 |
bitmap = 0; |
|
269 |
lock.relock(); |
|
270 |
||
271 |
return bitmap; |
|
272 |
} |
|
273 |
||
274 |
lock.relock(); |
|
275 |
||
276 |
CFbsBitmapDevice* bitmapDevice = 0; |
|
277 |
CFbsBitGc *bitmapGc = 0; |
|
278 |
QT_TRAP_THROWING(bitmapDevice = CFbsBitmapDevice::NewL(uncompressed)); |
|
279 |
QT_TRAP_THROWING(bitmapGc = CFbsBitGc::NewL()); |
|
280 |
bitmapGc->Activate(bitmapDevice); |
|
281 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
282 |
bitmapGc->BitBlt(TPoint(), bitmap); |
0 | 283 |
|
284 |
delete bitmapGc; |
|
285 |
delete bitmapDevice; |
|
286 |
||
287 |
return uncompressed; |
|
288 |
} else { |
|
289 |
return bitmap; |
|
290 |
} |
|
291 |
} |
|
292 |
||
293 |
QPixmap QPixmap::grabWindow(WId winId, int x, int y, int w, int h) |
|
294 |
{ |
|
295 |
CWsScreenDevice* screenDevice = S60->screenDevice(); |
|
296 |
TSize screenSize = screenDevice->SizeInPixels(); |
|
297 |
||
298 |
TSize srcSize; |
|
299 |
// Find out if this is one of our windows. |
|
300 |
QSymbianControl *sControl; |
|
301 |
sControl = winId->MopGetObject(sControl); |
|
302 |
if (sControl && sControl->widget()->windowType() == Qt::Desktop) { |
|
303 |
// Grabbing desktop widget |
|
304 |
srcSize = screenSize; |
|
305 |
} else { |
|
306 |
TPoint relativePos = winId->PositionRelativeToScreen(); |
|
307 |
x += relativePos.iX; |
|
308 |
y += relativePos.iY; |
|
309 |
srcSize = winId->Size(); |
|
310 |
} |
|
311 |
||
312 |
TRect srcRect(TPoint(x, y), srcSize); |
|
313 |
// Clip to the screen |
|
314 |
srcRect.Intersection(TRect(screenSize)); |
|
315 |
||
316 |
if (w > 0 && h > 0) { |
|
317 |
TRect subRect(TPoint(x, y), TSize(w, h)); |
|
318 |
// Clip to the subRect |
|
319 |
srcRect.Intersection(subRect); |
|
320 |
} |
|
321 |
||
322 |
if (srcRect.IsEmpty()) |
|
323 |
return QPixmap(); |
|
324 |
||
325 |
CFbsBitmap* temporary = createSymbianCFbsBitmap(srcRect.Size(), screenDevice->DisplayMode()); |
|
326 |
||
327 |
QPixmap pix; |
|
328 |
||
329 |
if (temporary && screenDevice->CopyScreenToBitmap(temporary, srcRect) == KErrNone) { |
|
330 |
pix = QPixmap::fromSymbianCFbsBitmap(temporary); |
|
331 |
} |
|
332 |
||
333 |
delete temporary; |
|
334 |
return pix; |
|
335 |
} |
|
336 |
||
337 |
/*! |
|
338 |
\fn CFbsBitmap *QPixmap::toSymbianCFbsBitmap() const |
|
339 |
\since 4.6 |
|
340 |
||
341 |
Creates a \c CFbsBitmap that is equivalent to the QPixmap. Internally this |
|
342 |
function will try to duplicate the handle instead of copying the data, |
|
343 |
however in scenarios where this is not possible the data will be copied. |
|
344 |
If the creation fails or the pixmap is null, then this function returns 0. |
|
345 |
||
346 |
It is the caller's responsibility to release the \c CFbsBitmap data |
|
347 |
after use either by deleting the bitmap or calling \c Reset(). |
|
348 |
||
349 |
\warning On S60 3.1 and S60 3.2, semi-transparent pixmaps are always copied |
|
350 |
and not duplicated. |
|
351 |
\warning This function is only available on Symbian OS. |
|
352 |
||
353 |
\sa fromSymbianCFbsBitmap() |
|
354 |
*/ |
|
355 |
CFbsBitmap *QPixmap::toSymbianCFbsBitmap() const |
|
356 |
{ |
|
357 |
QPixmapData *data = pixmapData(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
358 |
if (!data || data->isNull()) |
0 | 359 |
return 0; |
360 |
||
361 |
return reinterpret_cast<CFbsBitmap*>(data->toNativeType(QPixmapData::FbsBitmap)); |
|
362 |
} |
|
363 |
||
364 |
/*! |
|
365 |
\fn QPixmap QPixmap::fromSymbianCFbsBitmap(CFbsBitmap *bitmap) |
|
366 |
\since 4.6 |
|
367 |
||
368 |
Creates a QPixmap from a \c CFbsBitmap \a bitmap. Internally this function |
|
369 |
will try to duplicate the bitmap handle instead of copying the data, however |
|
370 |
in scenarios where this is not possible the data will be copied. |
|
371 |
To be sure that QPixmap does not modify your original instance, you should |
|
372 |
make a copy of your \c CFbsBitmap before calling this function. |
|
373 |
If the CFbsBitmap is not valid this function will return a null QPixmap. |
|
374 |
||
375 |
\warning This function is only available on Symbian OS. |
|
376 |
||
377 |
\sa toSymbianCFbsBitmap(), {QPixmap#Pixmap Conversion}{Pixmap Conversion} |
|
378 |
*/ |
|
379 |
QPixmap QPixmap::fromSymbianCFbsBitmap(CFbsBitmap *bitmap) |
|
380 |
{ |
|
381 |
if (!bitmap) |
|
382 |
return QPixmap(); |
|
383 |
||
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
384 |
QScopedPointer<QPixmapData> data(QPixmapData::create(0,0, QPixmapData::PixmapType)); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
385 |
data->fromNativeType(reinterpret_cast<void*>(bitmap), QPixmapData::FbsBitmap); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
386 |
QPixmap pixmap(data.take()); |
0 | 387 |
return pixmap; |
388 |
} |
|
389 |
||
390 |
QS60PixmapData::QS60PixmapData(PixelType type) : QRasterPixmapData(type), |
|
391 |
symbianBitmapDataAccess(new QSymbianBitmapDataAccess), |
|
392 |
cfbsBitmap(0), |
|
393 |
pengine(0), |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
394 |
bytes(0), |
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
395 |
formatLocked(false), |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
396 |
next(0), |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
397 |
prev(0) |
0 | 398 |
{ |
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
399 |
qt_symbian_register_pixmap(this); |
0 | 400 |
} |
401 |
||
402 |
QS60PixmapData::~QS60PixmapData() |
|
403 |
{ |
|
404 |
release(); |
|
405 |
delete symbianBitmapDataAccess; |
|
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
406 |
qt_symbian_unregister_pixmap(this); |
0 | 407 |
} |
408 |
||
409 |
void QS60PixmapData::resize(int width, int height) |
|
410 |
{ |
|
411 |
if (width <= 0 || height <= 0) { |
|
412 |
w = width; |
|
413 |
h = height; |
|
414 |
is_null = true; |
|
415 |
||
416 |
release(); |
|
417 |
return; |
|
418 |
} else if (!cfbsBitmap) { |
|
419 |
TDisplayMode mode; |
|
420 |
if (pixelType() == BitmapType) |
|
421 |
mode = EGray2; |
|
422 |
else |
|
423 |
mode = EColor16MU; |
|
424 |
||
425 |
CFbsBitmap* bitmap = createSymbianCFbsBitmap(TSize(width, height), mode); |
|
426 |
fromSymbianBitmap(bitmap); |
|
427 |
} else { |
|
428 |
||
429 |
TSize newSize(width, height); |
|
430 |
||
431 |
if(cfbsBitmap->SizeInPixels() != newSize) { |
|
432 |
cfbsBitmap->Resize(TSize(width, height)); |
|
433 |
if(pengine) { |
|
434 |
delete pengine; |
|
435 |
pengine = 0; |
|
436 |
} |
|
437 |
} |
|
438 |
||
439 |
UPDATE_BUFFER(); |
|
440 |
} |
|
441 |
} |
|
442 |
||
443 |
void QS60PixmapData::release() |
|
444 |
{ |
|
445 |
if (cfbsBitmap) { |
|
446 |
QSymbianFbsHeapLock lock(QSymbianFbsHeapLock::Unlock); |
|
447 |
delete cfbsBitmap; |
|
448 |
lock.relock(); |
|
449 |
} |
|
450 |
||
451 |
delete pengine; |
|
452 |
image = QImage(); |
|
453 |
cfbsBitmap = 0; |
|
454 |
pengine = 0; |
|
455 |
bytes = 0; |
|
456 |
} |
|
457 |
||
458 |
/*! |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
459 |
* Takes ownership of bitmap. Used by window surface |
0 | 460 |
*/ |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
461 |
void QS60PixmapData::fromSymbianBitmap(CFbsBitmap* bitmap, bool lockFormat) |
0 | 462 |
{ |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
463 |
Q_ASSERT(bitmap); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
464 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
465 |
release(); |
0 | 466 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
467 |
cfbsBitmap = bitmap; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
468 |
formatLocked = lockFormat; |
0 | 469 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
470 |
setSerialNumber(cfbsBitmap->Handle()); |
0 | 471 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
472 |
UPDATE_BUFFER(); |
0 | 473 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
474 |
// Create default palette if needed |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
475 |
if (cfbsBitmap->DisplayMode() == EGray2) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
476 |
image.setColorCount(2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
477 |
image.setColor(0, QColor(Qt::color0).rgba()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
478 |
image.setColor(1, QColor(Qt::color1).rgba()); |
0 | 479 |
|
480 |
//Symbian thinks set pixels are white/transparent, Qt thinks they are foreground/solid |
|
481 |
//So invert mono bitmaps so that masks work correctly. |
|
482 |
image.invertPixels(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
483 |
} else if (cfbsBitmap->DisplayMode() == EGray256) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
484 |
for (int i=0; i < 256; ++i) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
485 |
image.setColor(i, qRgb(i, i, i)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
486 |
} else if (cfbsBitmap->DisplayMode() == EColor256) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
487 |
const TColor256Util *palette = TColor256Util::Default(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
488 |
for (int i=0; i < 256; ++i) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
489 |
image.setColor(i, (QRgb)(palette->Color256(i).Value())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
490 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
491 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
492 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
493 |
QImage QS60PixmapData::toImage(const QRect &r) const |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
494 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
495 |
QS60PixmapData *that = const_cast<QS60PixmapData*>(this); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
496 |
that->beginDataAccess(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
497 |
QImage copy = that->image.copy(r); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
498 |
that->endDataAccess(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
499 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
500 |
return copy; |
0 | 501 |
} |
502 |
||
503 |
void QS60PixmapData::fromImage(const QImage &img, Qt::ImageConversionFlags flags) |
|
504 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
505 |
release(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
506 |
|
0 | 507 |
QImage sourceImage; |
508 |
||
509 |
if (pixelType() == BitmapType) { |
|
510 |
sourceImage = img.convertToFormat(QImage::Format_MonoLSB); |
|
511 |
} else { |
|
512 |
if (img.depth() == 1) { |
|
513 |
sourceImage = img.hasAlphaChannel() |
|
514 |
? img.convertToFormat(QImage::Format_ARGB32_Premultiplied) |
|
515 |
: img.convertToFormat(QImage::Format_RGB32); |
|
516 |
} else { |
|
517 |
||
518 |
QImage::Format opaqueFormat = QNativeImage::systemFormat(); |
|
519 |
QImage::Format alphaFormat = QImage::Format_ARGB32_Premultiplied; |
|
520 |
||
521 |
if (!img.hasAlphaChannel() |
|
522 |
|| ((flags & Qt::NoOpaqueDetection) == 0 |
|
523 |
&& !const_cast<QImage &>(img).data_ptr()->checkForAlphaPixels())) { |
|
524 |
sourceImage = img.convertToFormat(opaqueFormat); |
|
525 |
} else { |
|
526 |
sourceImage = img.convertToFormat(alphaFormat); |
|
527 |
} |
|
528 |
} |
|
529 |
} |
|
530 |
||
531 |
||
532 |
QImage::Format destFormat = sourceImage.format(); |
|
533 |
TDisplayMode mode; |
|
534 |
switch (destFormat) { |
|
535 |
case QImage::Format_MonoLSB: |
|
536 |
mode = EGray2; |
|
537 |
break; |
|
538 |
case QImage::Format_RGB32: |
|
539 |
mode = EColor16MU; |
|
540 |
break; |
|
541 |
case QImage::Format_ARGB32_Premultiplied: |
|
542 |
if (S60->supportsPremultipliedAlpha) { |
|
543 |
mode = Q_SYMBIAN_ECOLOR16MAP; |
|
544 |
break; |
|
545 |
} else { |
|
546 |
destFormat = QImage::Format_ARGB32; |
|
547 |
} |
|
548 |
// Fall through intended |
|
549 |
case QImage::Format_ARGB32: |
|
550 |
mode = EColor16MA; |
|
551 |
break; |
|
552 |
case QImage::Format_Invalid: |
|
553 |
return; |
|
554 |
default: |
|
555 |
qWarning("Image format not supported: %d", image.format()); |
|
556 |
return; |
|
557 |
} |
|
558 |
||
559 |
cfbsBitmap = createSymbianCFbsBitmap(TSize(sourceImage.width(), sourceImage.height()), mode); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
560 |
if (!cfbsBitmap) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
561 |
qWarning("Could not create CFbsBitmap"); |
0 | 562 |
release(); |
563 |
return; |
|
564 |
} |
|
565 |
||
566 |
setSerialNumber(cfbsBitmap->Handle()); |
|
567 |
||
568 |
const uchar *sptr = const_cast<const QImage &>(sourceImage).bits(); |
|
569 |
symbianBitmapDataAccess->beginDataAccess(cfbsBitmap); |
|
570 |
uchar *dptr = (uchar*)cfbsBitmap->DataAddress(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
571 |
Mem::Copy(dptr, sptr, sourceImage.byteCount()); |
0 | 572 |
symbianBitmapDataAccess->endDataAccess(cfbsBitmap); |
573 |
||
574 |
UPDATE_BUFFER(); |
|
575 |
||
576 |
if (destFormat == QImage::Format_MonoLSB) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
577 |
image.setColorCount(2); |
0 | 578 |
image.setColor(0, QColor(Qt::color0).rgba()); |
579 |
image.setColor(1, QColor(Qt::color1).rgba()); |
|
580 |
} else { |
|
581 |
image.setColorTable(sourceImage.colorTable()); |
|
582 |
} |
|
583 |
} |
|
584 |
||
585 |
void QS60PixmapData::copy(const QPixmapData *data, const QRect &rect) |
|
586 |
{ |
|
587 |
const QS60PixmapData *s60Data = static_cast<const QS60PixmapData*>(data); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
588 |
fromImage(s60Data->toImage(rect), Qt::AutoColor | Qt::OrderedAlphaDither); |
0 | 589 |
} |
590 |
||
591 |
bool QS60PixmapData::scroll(int dx, int dy, const QRect &rect) |
|
592 |
{ |
|
593 |
beginDataAccess(); |
|
594 |
bool res = QRasterPixmapData::scroll(dx, dy, rect); |
|
595 |
endDataAccess(); |
|
596 |
return res; |
|
597 |
} |
|
598 |
||
599 |
int QS60PixmapData::metric(QPaintDevice::PaintDeviceMetric metric) const |
|
600 |
{ |
|
601 |
if (!cfbsBitmap) |
|
602 |
return 0; |
|
603 |
||
604 |
switch (metric) { |
|
605 |
case QPaintDevice::PdmWidth: |
|
606 |
return cfbsBitmap->SizeInPixels().iWidth; |
|
607 |
case QPaintDevice::PdmHeight: |
|
608 |
return cfbsBitmap->SizeInPixels().iHeight; |
|
609 |
case QPaintDevice::PdmWidthMM: { |
|
610 |
TInt twips = cfbsBitmap->SizeInTwips().iWidth; |
|
611 |
return (int)(twips * (25.4/KTwipsPerInch)); |
|
612 |
} |
|
613 |
case QPaintDevice::PdmHeightMM: { |
|
614 |
TInt twips = cfbsBitmap->SizeInTwips().iHeight; |
|
615 |
return (int)(twips * (25.4/KTwipsPerInch)); |
|
616 |
} |
|
617 |
case QPaintDevice::PdmNumColors: |
|
618 |
return TDisplayModeUtils::NumDisplayModeColors(cfbsBitmap->DisplayMode()); |
|
619 |
case QPaintDevice::PdmDpiX: |
|
620 |
case QPaintDevice::PdmPhysicalDpiX: { |
|
621 |
TReal inches = cfbsBitmap->SizeInTwips().iWidth / (TReal)KTwipsPerInch; |
|
622 |
TInt pixels = cfbsBitmap->SizeInPixels().iWidth; |
|
623 |
return pixels / inches; |
|
624 |
} |
|
625 |
case QPaintDevice::PdmDpiY: |
|
626 |
case QPaintDevice::PdmPhysicalDpiY: { |
|
627 |
TReal inches = cfbsBitmap->SizeInTwips().iHeight / (TReal)KTwipsPerInch; |
|
628 |
TInt pixels = cfbsBitmap->SizeInPixels().iHeight; |
|
629 |
return pixels / inches; |
|
630 |
} |
|
631 |
case QPaintDevice::PdmDepth: |
|
632 |
return TDisplayModeUtils::NumDisplayModeBitsPerPixel(cfbsBitmap->DisplayMode()); |
|
633 |
default: |
|
634 |
qWarning("QPixmap::metric: Invalid metric command"); |
|
635 |
} |
|
636 |
return 0; |
|
637 |
||
638 |
} |
|
639 |
||
640 |
void QS60PixmapData::fill(const QColor &color) |
|
641 |
{ |
|
642 |
if (color.alpha() != 255) { |
|
643 |
QImage im(width(), height(), QImage::Format_ARGB32_Premultiplied); |
|
644 |
im.fill(PREMUL(color.rgba())); |
|
645 |
release(); |
|
646 |
fromImage(im, Qt::AutoColor | Qt::OrderedAlphaDither); |
|
647 |
} else { |
|
648 |
beginDataAccess(); |
|
649 |
QRasterPixmapData::fill(color); |
|
650 |
endDataAccess(); |
|
651 |
} |
|
652 |
} |
|
653 |
||
654 |
void QS60PixmapData::setMask(const QBitmap &mask) |
|
655 |
{ |
|
656 |
if (mask.size().isEmpty()) { |
|
657 |
if (image.depth() != 1) { |
|
658 |
QImage newImage = image.convertToFormat(QImage::Format_RGB32); |
|
659 |
release(); |
|
660 |
fromImage(newImage, Qt::AutoColor | Qt::OrderedAlphaDither); |
|
661 |
} |
|
662 |
} else if (image.depth() == 1) { |
|
663 |
beginDataAccess(); |
|
664 |
QRasterPixmapData::setMask(mask); |
|
665 |
endDataAccess(); |
|
666 |
} else { |
|
667 |
const int w = image.width(); |
|
668 |
const int h = image.height(); |
|
669 |
||
670 |
const QImage imageMask = mask.toImage().convertToFormat(QImage::Format_MonoLSB); |
|
671 |
QImage newImage = image.convertToFormat(QImage::Format_ARGB32_Premultiplied); |
|
672 |
for (int y = 0; y < h; ++y) { |
|
673 |
const uchar *mscan = imageMask.scanLine(y); |
|
674 |
QRgb *tscan = (QRgb *)newImage.scanLine(y); |
|
675 |
for (int x = 0; x < w; ++x) { |
|
676 |
if (!(mscan[x>>3] & qt_pixmap_bit_mask[x&7])) |
|
677 |
tscan[x] = 0; |
|
678 |
} |
|
679 |
} |
|
680 |
release(); |
|
681 |
fromImage(newImage, Qt::AutoColor | Qt::OrderedAlphaDither); |
|
682 |
} |
|
683 |
} |
|
684 |
||
685 |
void QS60PixmapData::setAlphaChannel(const QPixmap &alphaChannel) |
|
686 |
{ |
|
687 |
QImage img(toImage()); |
|
688 |
img.setAlphaChannel(alphaChannel.toImage()); |
|
689 |
release(); |
|
690 |
fromImage(img, Qt::OrderedDither | Qt::OrderedAlphaDither); |
|
691 |
} |
|
692 |
||
693 |
QImage QS60PixmapData::toImage() const |
|
694 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
695 |
return toImage(QRect()); |
0 | 696 |
} |
697 |
||
698 |
QPaintEngine* QS60PixmapData::paintEngine() const |
|
699 |
{ |
|
700 |
if (!pengine) { |
|
701 |
QS60PixmapData *that = const_cast<QS60PixmapData*>(this); |
|
702 |
that->pengine = new QS60PaintEngine(&that->image, that); |
|
703 |
} |
|
704 |
return pengine; |
|
705 |
} |
|
706 |
||
707 |
void QS60PixmapData::beginDataAccess() |
|
708 |
{ |
|
709 |
if(!cfbsBitmap) |
|
710 |
return; |
|
711 |
||
712 |
symbianBitmapDataAccess->beginDataAccess(cfbsBitmap); |
|
713 |
||
714 |
uchar* newBytes = (uchar*)cfbsBitmap->DataAddress(); |
|
715 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
716 |
TSize size = cfbsBitmap->SizeInPixels(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
717 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
718 |
if (newBytes == bytes && image.width() == size.iWidth && image.height() == size.iHeight) |
0 | 719 |
return; |
720 |
||
721 |
bytes = newBytes; |
|
722 |
TDisplayMode mode = cfbsBitmap->DisplayMode(); |
|
723 |
QImage::Format format = qt_TDisplayMode2Format(mode); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
724 |
// On S60 3.1, premultiplied alpha pixels are stored in a bitmap with 16MA type. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
725 |
// S60 window surface needs backing store pixmap for transparent window in ARGB32 format. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
726 |
// In that case formatLocked is true. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
727 |
if (!formatLocked && format == QImage::Format_ARGB32) |
0 | 728 |
format = QImage::Format_ARGB32_Premultiplied; // pixel data is actually in premultiplied format |
729 |
||
730 |
QVector<QRgb> savedColorTable; |
|
731 |
if (!image.isNull()) |
|
732 |
savedColorTable = image.colorTable(); |
|
733 |
||
734 |
image = QImage(bytes, size.iWidth, size.iHeight, format); |
|
735 |
||
736 |
// Restore the palette or create a default |
|
737 |
if (!savedColorTable.isEmpty()) { |
|
738 |
image.setColorTable(savedColorTable); |
|
739 |
} |
|
740 |
||
741 |
w = size.iWidth; |
|
742 |
h = size.iHeight; |
|
743 |
d = image.depth(); |
|
744 |
is_null = (w <= 0 || h <= 0); |
|
745 |
||
746 |
if (pengine) { |
|
747 |
QS60PaintEngine *engine = static_cast<QS60PaintEngine *>(pengine); |
|
748 |
engine->prepare(&image); |
|
749 |
} |
|
750 |
} |
|
751 |
||
752 |
void QS60PixmapData::endDataAccess(bool readOnly) const |
|
753 |
{ |
|
754 |
Q_UNUSED(readOnly); |
|
755 |
||
756 |
if(!cfbsBitmap) |
|
757 |
return; |
|
758 |
||
759 |
symbianBitmapDataAccess->endDataAccess(cfbsBitmap); |
|
760 |
} |
|
761 |
||
762 |
/*! |
|
763 |
\since 4.6 |
|
764 |
||
765 |
Returns a QPixmap that wraps given \a sgImage graphics resource. |
|
766 |
The data should be valid even when original RSgImage handle has been |
|
767 |
closed. |
|
768 |
||
769 |
\warning This function is only available on Symbian OS. |
|
770 |
||
771 |
\sa toSymbianRSgImage(), {QPixmap#Pixmap Conversion}{Pixmap Conversion} |
|
772 |
*/ |
|
773 |
||
774 |
QPixmap QPixmap::fromSymbianRSgImage(RSgImage *sgImage) |
|
775 |
{ |
|
776 |
// It is expected that RSgImage will |
|
777 |
// CURRENTLY be used in conjuction with |
|
778 |
// OpenVG graphics system |
|
779 |
// |
|
780 |
// Surely things might change in future |
|
781 |
||
782 |
if (!sgImage) |
|
783 |
return QPixmap(); |
|
784 |
||
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
785 |
QScopedPointer<QPixmapData> data(QPixmapData::create(0,0, QPixmapData::PixmapType)); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
786 |
data->fromNativeType(reinterpret_cast<void*>(sgImage), QPixmapData::SgImage); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
787 |
QPixmap pixmap(data.take()); |
0 | 788 |
return pixmap; |
789 |
} |
|
790 |
||
791 |
/*! |
|
792 |
\since 4.6 |
|
793 |
||
794 |
Returns a \c RSgImage that is equivalent to the QPixmap by copying the data. |
|
795 |
||
796 |
It is the caller's responsibility to close/delete the \c RSgImage after use. |
|
797 |
||
798 |
\warning This function is only available on Symbian OS. |
|
799 |
||
800 |
\sa fromSymbianRSgImage() |
|
801 |
*/ |
|
802 |
||
803 |
RSgImage *QPixmap::toSymbianRSgImage() const |
|
804 |
{ |
|
805 |
// It is expected that RSgImage will |
|
806 |
// CURRENTLY be used in conjuction with |
|
807 |
// OpenVG graphics system |
|
808 |
// |
|
809 |
// Surely things might change in future |
|
810 |
||
811 |
if (isNull()) |
|
812 |
return 0; |
|
813 |
||
814 |
RSgImage *sgImage = reinterpret_cast<RSgImage*>(pixmapData()->toNativeType(QPixmapData::SgImage)); |
|
815 |
||
816 |
return sgImage; |
|
817 |
} |
|
818 |
||
819 |
void* QS60PixmapData::toNativeType(NativeType type) |
|
820 |
{ |
|
821 |
if (type == QPixmapData::SgImage) { |
|
822 |
return 0; |
|
823 |
} else if (type == QPixmapData::FbsBitmap) { |
|
824 |
||
825 |
if (isNull() || !cfbsBitmap) |
|
826 |
return 0; |
|
827 |
||
828 |
bool convertToArgb32 = false; |
|
829 |
bool needsCopy = false; |
|
830 |
||
831 |
QSysInfo::SymbianVersion symbianVersion = QSysInfo::symbianVersion(); |
|
832 |
if (!(S60->supportsPremultipliedAlpha)) { |
|
833 |
// Convert argb32_premultiplied to argb32 since Symbian 9.2 does |
|
834 |
// not support premultipied format. |
|
835 |
||
836 |
if (image.format() == QImage::Format_ARGB32_Premultiplied) { |
|
837 |
needsCopy = true; |
|
838 |
convertToArgb32 = true; |
|
839 |
} |
|
840 |
} |
|
841 |
||
842 |
CFbsBitmap *bitmap = 0; |
|
843 |
||
844 |
TDisplayMode displayMode = cfbsBitmap->DisplayMode(); |
|
845 |
||
846 |
if(displayMode == EGray2) { |
|
847 |
//Symbian thinks set pixels are white/transparent, Qt thinks they are foreground/solid |
|
848 |
//So invert mono bitmaps so that masks work correctly. |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
849 |
beginDataAccess(); |
0 | 850 |
image.invertPixels(); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
851 |
endDataAccess(); |
0 | 852 |
needsCopy = true; |
853 |
} |
|
854 |
||
855 |
if (needsCopy) { |
|
856 |
QImage source; |
|
857 |
||
858 |
if (convertToArgb32) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
859 |
beginDataAccess(); |
0 | 860 |
source = image.convertToFormat(QImage::Format_ARGB32); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
861 |
endDataAccess(); |
0 | 862 |
displayMode = EColor16MA; |
863 |
} else { |
|
864 |
source = image; |
|
865 |
} |
|
866 |
||
867 |
CFbsBitmap *newBitmap = createSymbianCFbsBitmap(TSize(source.width(), source.height()), displayMode); |
|
868 |
const uchar *sptr = source.bits(); |
|
869 |
symbianBitmapDataAccess->beginDataAccess(newBitmap); |
|
870 |
||
871 |
uchar *dptr = (uchar*)newBitmap->DataAddress(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
872 |
Mem::Copy(dptr, sptr, source.byteCount()); |
0 | 873 |
|
874 |
symbianBitmapDataAccess->endDataAccess(newBitmap); |
|
875 |
||
876 |
bitmap = newBitmap; |
|
877 |
} else { |
|
878 |
||
879 |
QT_TRAP_THROWING(bitmap = new (ELeave) CFbsBitmap); |
|
880 |
||
881 |
TInt err = bitmap->Duplicate(cfbsBitmap->Handle()); |
|
882 |
if (err != KErrNone) { |
|
883 |
qWarning("Could not duplicate CFbsBitmap"); |
|
884 |
delete bitmap; |
|
885 |
bitmap = 0; |
|
886 |
} |
|
887 |
} |
|
888 |
||
889 |
if(displayMode == EGray2) { |
|
890 |
// restore pixels |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
891 |
beginDataAccess(); |
0 | 892 |
image.invertPixels(); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
893 |
endDataAccess(); |
0 | 894 |
} |
895 |
||
896 |
return reinterpret_cast<void*>(bitmap); |
|
897 |
||
898 |
} |
|
899 |
||
900 |
return 0; |
|
901 |
} |
|
902 |
||
903 |
void QS60PixmapData::fromNativeType(void* pixmap, NativeType nativeType) |
|
904 |
{ |
|
905 |
if (nativeType == QPixmapData::SgImage) { |
|
906 |
return; |
|
907 |
} else if (nativeType == QPixmapData::FbsBitmap && pixmap) { |
|
908 |
||
909 |
CFbsBitmap *bitmap = reinterpret_cast<CFbsBitmap*>(pixmap); |
|
910 |
||
911 |
bool deleteSourceBitmap = false; |
|
912 |
bool needsCopy = false; |
|
913 |
||
914 |
#ifdef Q_SYMBIAN_HAS_EXTENDED_BITMAP_TYPE |
|
915 |
||
916 |
// Rasterize extended bitmaps |
|
917 |
||
918 |
TUid extendedBitmapType = bitmap->ExtendedBitmapType(); |
|
919 |
if (extendedBitmapType != KNullUid) { |
|
920 |
CFbsBitmap *rasterBitmap = createSymbianCFbsBitmap(bitmap->SizeInPixels(), EColor16MA); |
|
921 |
||
922 |
CFbsBitmapDevice *rasterBitmapDev = 0; |
|
923 |
QT_TRAP_THROWING(rasterBitmapDev = CFbsBitmapDevice::NewL(rasterBitmap)); |
|
924 |
||
925 |
CFbsBitGc *rasterBitmapGc = 0; |
|
926 |
TInt err = rasterBitmapDev->CreateContext(rasterBitmapGc); |
|
927 |
if (err != KErrNone) { |
|
928 |
delete rasterBitmap; |
|
929 |
delete rasterBitmapDev; |
|
930 |
rasterBitmapDev = 0; |
|
931 |
return; |
|
932 |
} |
|
933 |
||
934 |
rasterBitmapGc->BitBlt(TPoint( 0, 0), bitmap); |
|
935 |
||
936 |
bitmap = rasterBitmap; |
|
937 |
||
938 |
delete rasterBitmapDev; |
|
939 |
delete rasterBitmapGc; |
|
940 |
||
941 |
rasterBitmapDev = 0; |
|
942 |
rasterBitmapGc = 0; |
|
943 |
||
944 |
deleteSourceBitmap = true; |
|
945 |
} |
|
946 |
#endif |
|
947 |
||
948 |
||
949 |
deleteSourceBitmap = bitmap->IsCompressedInRAM(); |
|
950 |
CFbsBitmap *sourceBitmap = uncompress(bitmap); |
|
951 |
||
952 |
TDisplayMode displayMode = sourceBitmap->DisplayMode(); |
|
953 |
QImage::Format format = qt_TDisplayMode2Format(displayMode); |
|
954 |
||
955 |
QImage::Format opaqueFormat = QNativeImage::systemFormat(); |
|
956 |
QImage::Format alphaFormat = QImage::Format_ARGB32_Premultiplied; |
|
957 |
||
958 |
if (format != opaqueFormat && format != alphaFormat && format != QImage::Format_MonoLSB) |
|
959 |
needsCopy = true; |
|
960 |
||
961 |
||
962 |
type = (format != QImage::Format_MonoLSB) |
|
963 |
? QPixmapData::PixmapType |
|
964 |
: QPixmapData::BitmapType; |
|
965 |
||
966 |
if (needsCopy) { |
|
967 |
||
968 |
TSize size = sourceBitmap->SizeInPixels(); |
|
969 |
||
970 |
QSymbianBitmapDataAccess da; |
|
971 |
da.beginDataAccess(sourceBitmap); |
|
972 |
uchar *bytes = (uchar*)sourceBitmap->DataAddress(); |
|
973 |
QImage img = QImage(bytes, size.iWidth, size.iHeight, format); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
974 |
img = img.copy(); |
0 | 975 |
da.endDataAccess(sourceBitmap); |
976 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
977 |
if(displayMode == EGray2) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
978 |
//Symbian thinks set pixels are white/transparent, Qt thinks they are foreground/solid |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
979 |
//So invert mono bitmaps so that masks work correctly. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
980 |
img.invertPixels(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
981 |
} else if(displayMode == EColor16M) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
982 |
img = img.rgbSwapped(); // EColor16M is BGR |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
983 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
984 |
|
0 | 985 |
fromImage(img, Qt::AutoColor); |
986 |
||
987 |
if(deleteSourceBitmap) |
|
988 |
delete sourceBitmap; |
|
989 |
} else { |
|
990 |
CFbsBitmap* duplicate = 0; |
|
991 |
QT_TRAP_THROWING(duplicate = new (ELeave) CFbsBitmap); |
|
992 |
||
993 |
TInt err = duplicate->Duplicate(sourceBitmap->Handle()); |
|
994 |
if (err != KErrNone) { |
|
995 |
qWarning("Could not duplicate CFbsBitmap"); |
|
996 |
||
997 |
if(deleteSourceBitmap) |
|
998 |
delete sourceBitmap; |
|
999 |
||
1000 |
delete duplicate; |
|
1001 |
return; |
|
1002 |
} |
|
1003 |
||
1004 |
fromSymbianBitmap(duplicate); |
|
1005 |
||
1006 |
if(deleteSourceBitmap) |
|
1007 |
delete sourceBitmap; |
|
1008 |
} |
|
1009 |
} |
|
1010 |
} |
|
1011 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1012 |
QPixmapData *QS60PixmapData::createCompatiblePixmapData() const |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1013 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1014 |
return new QS60PixmapData(pixelType()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1015 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1016 |
|
0 | 1017 |
QT_END_NAMESPACE |