author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 12 Mar 2010 15:46:37 +0200 | |
branch | RCL_3 |
changeset 5 | d3bac044e0f0 |
parent 4 | 3b1da2848fc7 |
child 7 | 3f74d0d4af4c |
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 |
** |
|
7 |
** This file is part of the QtOpenVG module of the Qt Toolkit. |
|
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 "qpixmapdata_vg_p.h" |
|
43 |
#include "qpaintengine_vg_p.h" |
|
44 |
#include <QtGui/private/qdrawhelper_p.h> |
|
45 |
#include "qvg_p.h" |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
46 |
#include "qvgimagepool_p.h" |
0 | 47 |
|
48 |
#ifdef QT_SYMBIAN_SUPPORTS_SGIMAGE |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
49 |
#include <private/qt_s60_p.h> |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
50 |
#include <fbs.h> |
0 | 51 |
#include <graphics/sgimage.h> |
52 |
typedef EGLImageKHR (*pfnEglCreateImageKHR)(EGLDisplay, EGLContext, EGLenum, EGLClientBuffer, EGLint*); |
|
53 |
typedef EGLBoolean (*pfnEglDestroyImageKHR)(EGLDisplay, EGLImageKHR); |
|
54 |
typedef VGImage (*pfnVgCreateEGLImageTargetKHR)(VGeglImageKHR); |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
55 |
#endif // QT_SYMBIAN_SUPPORTS_SGIMAGE |
0 | 56 |
|
57 |
QT_BEGIN_NAMESPACE |
|
58 |
||
59 |
static int qt_vg_pixmap_serial = 0; |
|
60 |
||
61 |
QVGPixmapData::QVGPixmapData(PixelType type) |
|
62 |
: QPixmapData(type, OpenVGClass) |
|
63 |
{ |
|
64 |
Q_ASSERT(type == QPixmapData::PixmapType); |
|
65 |
vgImage = VG_INVALID_HANDLE; |
|
66 |
vgImageOpacity = VG_INVALID_HANDLE; |
|
67 |
cachedOpacity = 1.0f; |
|
68 |
recreate = true; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
69 |
inImagePool = false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
70 |
inLRU = false; |
0 | 71 |
#if !defined(QT_NO_EGL) |
72 |
context = 0; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
73 |
qt_vg_register_pixmap(this); |
0 | 74 |
#endif |
75 |
setSerialNumber(++qt_vg_pixmap_serial); |
|
76 |
} |
|
77 |
||
78 |
QVGPixmapData::~QVGPixmapData() |
|
79 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
80 |
destroyImageAndContext(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
81 |
#if !defined(QT_NO_EGL) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
82 |
qt_vg_unregister_pixmap(this); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
83 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
84 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
85 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
86 |
void QVGPixmapData::destroyImages() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
87 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
88 |
if (inImagePool) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
89 |
QVGImagePool *pool = QVGImagePool::instance(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
90 |
if (vgImage != VG_INVALID_HANDLE) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
91 |
pool->releaseImage(this, vgImage); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
92 |
if (vgImageOpacity != VG_INVALID_HANDLE) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
93 |
pool->releaseImage(this, vgImageOpacity); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
94 |
} else { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
95 |
if (vgImage != VG_INVALID_HANDLE) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
96 |
vgDestroyImage(vgImage); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
97 |
if (vgImageOpacity != VG_INVALID_HANDLE) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
98 |
vgDestroyImage(vgImageOpacity); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
99 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
100 |
vgImage = VG_INVALID_HANDLE; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
101 |
vgImageOpacity = VG_INVALID_HANDLE; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
102 |
inImagePool = false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
103 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
104 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
105 |
void QVGPixmapData::destroyImageAndContext() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
106 |
{ |
0 | 107 |
if (vgImage != VG_INVALID_HANDLE) { |
108 |
// We need to have a context current to destroy the image. |
|
109 |
#if !defined(QT_NO_EGL) |
|
110 |
if (context->isCurrent()) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
111 |
destroyImages(); |
0 | 112 |
} else { |
113 |
// We don't currently have a widget surface active, but we |
|
114 |
// need a surface to make the context current. So use the |
|
115 |
// shared pbuffer surface instead. |
|
116 |
context->makeCurrent(qt_vg_shared_surface()); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
117 |
destroyImages(); |
0 | 118 |
context->lazyDoneCurrent(); |
119 |
} |
|
120 |
#else |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
121 |
destroyImages(); |
0 | 122 |
#endif |
123 |
} |
|
124 |
#if !defined(QT_NO_EGL) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
125 |
if (context) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
126 |
qt_vg_destroy_context(context, QInternal::Pixmap); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
127 |
context = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
128 |
} |
0 | 129 |
#endif |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
130 |
recreate = true; |
0 | 131 |
} |
132 |
||
133 |
QPixmapData *QVGPixmapData::createCompatiblePixmapData() const |
|
134 |
{ |
|
135 |
return new QVGPixmapData(pixelType()); |
|
136 |
} |
|
137 |
||
138 |
bool QVGPixmapData::isValid() const |
|
139 |
{ |
|
140 |
return (w > 0 && h > 0); |
|
141 |
} |
|
142 |
||
143 |
void QVGPixmapData::resize(int wid, int ht) |
|
144 |
{ |
|
145 |
if (w == wid && h == ht) |
|
146 |
return; |
|
147 |
||
148 |
w = wid; |
|
149 |
h = ht; |
|
150 |
d = 32; // We always use ARGB_Premultiplied for VG pixmaps. |
|
151 |
is_null = (w <= 0 || h <= 0); |
|
152 |
source = QImage(); |
|
153 |
recreate = true; |
|
154 |
||
155 |
setSerialNumber(++qt_vg_pixmap_serial); |
|
156 |
} |
|
157 |
||
158 |
void QVGPixmapData::fromImage |
|
159 |
(const QImage &image, Qt::ImageConversionFlags flags) |
|
160 |
{ |
|
161 |
if (image.size() == QSize(w, h)) |
|
162 |
setSerialNumber(++qt_vg_pixmap_serial); |
|
163 |
else |
|
164 |
resize(image.width(), image.height()); |
|
165 |
source = image.convertToFormat(sourceFormat(), flags); |
|
166 |
recreate = true; |
|
167 |
} |
|
168 |
||
169 |
void QVGPixmapData::fill(const QColor &color) |
|
170 |
{ |
|
171 |
if (!isValid()) |
|
172 |
return; |
|
173 |
||
174 |
if (source.isNull()) |
|
175 |
source = QImage(w, h, sourceFormat()); |
|
176 |
||
177 |
if (source.depth() == 1) { |
|
178 |
// Pick the best approximate color in the image's colortable. |
|
179 |
int gray = qGray(color.rgba()); |
|
180 |
if (qAbs(qGray(source.color(0)) - gray) < qAbs(qGray(source.color(1)) - gray)) |
|
181 |
source.fill(0); |
|
182 |
else |
|
183 |
source.fill(1); |
|
184 |
} else { |
|
185 |
source.fill(PREMUL(color.rgba())); |
|
186 |
} |
|
187 |
||
188 |
// Re-upload the image to VG the next time toVGImage() is called. |
|
189 |
recreate = true; |
|
190 |
} |
|
191 |
||
192 |
bool QVGPixmapData::hasAlphaChannel() const |
|
193 |
{ |
|
194 |
if (!source.isNull()) |
|
195 |
return source.hasAlphaChannel(); |
|
196 |
else |
|
197 |
return isValid(); |
|
198 |
} |
|
199 |
||
200 |
void QVGPixmapData::setAlphaChannel(const QPixmap &alphaChannel) |
|
201 |
{ |
|
202 |
forceToImage(); |
|
203 |
source.setAlphaChannel(alphaChannel.toImage()); |
|
204 |
} |
|
205 |
||
206 |
QImage QVGPixmapData::toImage() const |
|
207 |
{ |
|
208 |
if (!isValid()) |
|
209 |
return QImage(); |
|
210 |
||
211 |
if (source.isNull()) { |
|
212 |
source = QImage(w, h, sourceFormat()); |
|
213 |
recreate = true; |
|
214 |
} |
|
215 |
||
216 |
return source; |
|
217 |
} |
|
218 |
||
219 |
QImage *QVGPixmapData::buffer() |
|
220 |
{ |
|
221 |
forceToImage(); |
|
222 |
return &source; |
|
223 |
} |
|
224 |
||
225 |
QPaintEngine* QVGPixmapData::paintEngine() const |
|
226 |
{ |
|
227 |
// If the application wants to paint into the QPixmap, we first |
|
228 |
// force it to QImage format and then paint into that. |
|
229 |
// This is simpler than juggling multiple VG contexts. |
|
230 |
const_cast<QVGPixmapData *>(this)->forceToImage(); |
|
231 |
return source.paintEngine(); |
|
232 |
} |
|
233 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
234 |
// This function works around QImage::bits() making a deep copy if the |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
235 |
// QImage is not const. We force it to be const and then get the bits. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
236 |
// XXX: Should add a QImage::constBits() in the future to replace this. |
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
237 |
const uchar *qt_vg_imageBits(const QImage& image) |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
238 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
239 |
return image.bits(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
240 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
241 |
|
0 | 242 |
VGImage QVGPixmapData::toVGImage() |
243 |
{ |
|
244 |
if (!isValid()) |
|
245 |
return VG_INVALID_HANDLE; |
|
246 |
||
247 |
#if !defined(QT_NO_EGL) |
|
248 |
// Increase the reference count on the shared context. |
|
249 |
if (!context) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
250 |
context = qt_vg_create_context(0, QInternal::Pixmap); |
0 | 251 |
#endif |
252 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
253 |
if (recreate && prevSize != QSize(w, h)) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
254 |
destroyImages(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
255 |
else if (recreate) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
256 |
cachedOpacity = -1.0f; // Force opacity image to be refreshed later. |
0 | 257 |
|
258 |
if (vgImage == VG_INVALID_HANDLE) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
259 |
vgImage = QVGImagePool::instance()->createImageForPixmap |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
260 |
(VG_sARGB_8888_PRE, w, h, VG_IMAGE_QUALITY_FASTER, this); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
261 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
262 |
// Bail out if we run out of GPU memory - try again next time. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
263 |
if (vgImage == VG_INVALID_HANDLE) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
264 |
return VG_INVALID_HANDLE; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
265 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
266 |
inImagePool = true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
267 |
} else if (inImagePool) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
268 |
QVGImagePool::instance()->useImage(this); |
0 | 269 |
} |
270 |
||
271 |
if (!source.isNull() && recreate) { |
|
272 |
vgImageSubData |
|
273 |
(vgImage, |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
274 |
qt_vg_imageBits(source), source.bytesPerLine(), |
0 | 275 |
VG_sARGB_8888_PRE, 0, 0, w, h); |
276 |
} |
|
277 |
||
278 |
recreate = false; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
279 |
prevSize = QSize(w, h); |
0 | 280 |
|
281 |
return vgImage; |
|
282 |
} |
|
283 |
||
284 |
VGImage QVGPixmapData::toVGImage(qreal opacity) |
|
285 |
{ |
|
286 |
#if !defined(QT_SHIVAVG) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
287 |
// Force the primary VG image to be recreated if necessary. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
288 |
if (toVGImage() == VG_INVALID_HANDLE) |
0 | 289 |
return VG_INVALID_HANDLE; |
290 |
||
291 |
if (opacity == 1.0f) |
|
292 |
return vgImage; |
|
293 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
294 |
// Create an alternative image for the selected opacity. |
0 | 295 |
if (vgImageOpacity == VG_INVALID_HANDLE || cachedOpacity != opacity) { |
296 |
if (vgImageOpacity == VG_INVALID_HANDLE) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
297 |
if (inImagePool) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
298 |
vgImageOpacity = QVGImagePool::instance()->createImageForPixmap |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
299 |
(VG_sARGB_8888_PRE, w, h, VG_IMAGE_QUALITY_FASTER, this); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
300 |
} else { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
301 |
vgImageOpacity = vgCreateImage |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
302 |
(VG_sARGB_8888_PRE, w, h, VG_IMAGE_QUALITY_FASTER); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
303 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
304 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
305 |
// Bail out if we run out of GPU memory - try again next time. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
306 |
if (vgImageOpacity == VG_INVALID_HANDLE) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
307 |
return VG_INVALID_HANDLE; |
0 | 308 |
} |
309 |
VGfloat matrix[20] = { |
|
310 |
1.0f, 0.0f, 0.0f, 0.0f, |
|
311 |
0.0f, 1.0f, 0.0f, 0.0f, |
|
312 |
0.0f, 0.0f, 1.0f, 0.0f, |
|
313 |
0.0f, 0.0f, 0.0f, opacity, |
|
314 |
0.0f, 0.0f, 0.0f, 0.0f |
|
315 |
}; |
|
316 |
vgColorMatrix(vgImageOpacity, vgImage, matrix); |
|
317 |
cachedOpacity = opacity; |
|
318 |
} |
|
319 |
||
320 |
return vgImageOpacity; |
|
321 |
#else |
|
322 |
// vgColorMatrix() doesn't work with ShivaVG, so ignore the opacity. |
|
323 |
Q_UNUSED(opacity); |
|
324 |
return toVGImage(); |
|
325 |
#endif |
|
326 |
} |
|
327 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
328 |
void QVGPixmapData::detachImageFromPool() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
329 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
330 |
if (inImagePool) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
331 |
QVGImagePool::instance()->detachImage(this); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
332 |
inImagePool = false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
333 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
334 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
335 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
336 |
void QVGPixmapData::hibernate() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
337 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
338 |
// If the image was imported (e.g, from an SgImage under Symbian), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
339 |
// then we cannot copy it back to main memory for storage. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
340 |
if (vgImage != VG_INVALID_HANDLE && source.isNull()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
341 |
return; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
342 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
343 |
forceToImage(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
344 |
destroyImageAndContext(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
345 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
346 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
347 |
void QVGPixmapData::reclaimImages() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
348 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
349 |
if (!inImagePool) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
350 |
return; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
351 |
forceToImage(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
352 |
destroyImages(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
353 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
354 |
|
0 | 355 |
extern int qt_defaultDpiX(); |
356 |
extern int qt_defaultDpiY(); |
|
357 |
||
358 |
int QVGPixmapData::metric(QPaintDevice::PaintDeviceMetric metric) const |
|
359 |
{ |
|
360 |
switch (metric) { |
|
361 |
case QPaintDevice::PdmWidth: |
|
362 |
return w; |
|
363 |
case QPaintDevice::PdmHeight: |
|
364 |
return h; |
|
365 |
case QPaintDevice::PdmNumColors: |
|
366 |
return 0; |
|
367 |
case QPaintDevice::PdmDepth: |
|
368 |
return d; |
|
369 |
case QPaintDevice::PdmWidthMM: |
|
370 |
return qRound(w * 25.4 / qt_defaultDpiX()); |
|
371 |
case QPaintDevice::PdmHeightMM: |
|
372 |
return qRound(h * 25.4 / qt_defaultDpiY()); |
|
373 |
case QPaintDevice::PdmDpiX: |
|
374 |
case QPaintDevice::PdmPhysicalDpiX: |
|
375 |
return qt_defaultDpiX(); |
|
376 |
case QPaintDevice::PdmDpiY: |
|
377 |
case QPaintDevice::PdmPhysicalDpiY: |
|
378 |
return qt_defaultDpiY(); |
|
379 |
default: |
|
380 |
qWarning("QVGPixmapData::metric(): Invalid metric"); |
|
381 |
return 0; |
|
382 |
} |
|
383 |
} |
|
384 |
||
385 |
// Force the pixmap data to be in QImage format. |
|
386 |
void QVGPixmapData::forceToImage() |
|
387 |
{ |
|
388 |
if (!isValid()) |
|
389 |
return; |
|
390 |
||
391 |
if (source.isNull()) |
|
392 |
source = QImage(w, h, sourceFormat()); |
|
393 |
||
394 |
recreate = true; |
|
395 |
} |
|
396 |
||
397 |
QImage::Format QVGPixmapData::sourceFormat() const |
|
398 |
{ |
|
399 |
return QImage::Format_ARGB32_Premultiplied; |
|
400 |
} |
|
401 |
||
402 |
/* |
|
403 |
\internal |
|
404 |
||
405 |
Returns the VGImage that is storing the contents of \a pixmap. |
|
406 |
Returns VG_INVALID_HANDLE if \a pixmap is not owned by the OpenVG |
|
407 |
graphics system or \a pixmap is invalid. |
|
408 |
||
409 |
This function is typically used to access the backing store |
|
410 |
for a pixmap when executing raw OpenVG calls. It must only |
|
411 |
be used when a QPainter is active and the OpenVG paint engine |
|
412 |
is in use by the QPainter. |
|
413 |
||
414 |
\sa {QtOpenVG Module} |
|
415 |
*/ |
|
416 |
Q_OPENVG_EXPORT VGImage qPixmapToVGImage(const QPixmap& pixmap) |
|
417 |
{ |
|
418 |
QPixmapData *pd = pixmap.pixmapData(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
419 |
if (!pd) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
420 |
return VG_INVALID_HANDLE; // null QPixmap |
0 | 421 |
if (pd->classId() == QPixmapData::OpenVGClass) { |
422 |
QVGPixmapData *vgpd = static_cast<QVGPixmapData *>(pd); |
|
423 |
if (vgpd->isValid()) |
|
424 |
return vgpd->toVGImage(); |
|
425 |
} |
|
426 |
return VG_INVALID_HANDLE; |
|
427 |
} |
|
428 |
||
429 |
#if defined(Q_OS_SYMBIAN) |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
430 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
431 |
static CFbsBitmap* createBlitCopy(CFbsBitmap* bitmap) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
432 |
{ |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
433 |
CFbsBitmap *copy = q_check_ptr(new CFbsBitmap); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
434 |
if(!copy) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
435 |
return 0; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
436 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
437 |
if (copy->Create(bitmap->SizeInPixels(), bitmap->DisplayMode()) != KErrNone) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
438 |
delete copy; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
439 |
copy = 0; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
440 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
441 |
return 0; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
442 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
443 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
444 |
CFbsBitmapDevice* bitmapDevice = 0; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
445 |
CFbsBitGc *bitmapGc = 0; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
446 |
QT_TRAP_THROWING(bitmapDevice = CFbsBitmapDevice::NewL(copy)); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
447 |
QT_TRAP_THROWING(bitmapGc = CFbsBitGc::NewL()); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
448 |
bitmapGc->Activate(bitmapDevice); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
449 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
450 |
bitmapGc->BitBlt(TPoint(), bitmap); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
451 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
452 |
delete bitmapGc; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
453 |
delete bitmapDevice; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
454 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
455 |
return copy; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
456 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
457 |
|
0 | 458 |
void QVGPixmapData::cleanup() |
459 |
{ |
|
460 |
is_null = w = h = 0; |
|
461 |
recreate = false; |
|
462 |
source = QImage(); |
|
463 |
} |
|
464 |
||
465 |
void QVGPixmapData::fromNativeType(void* pixmap, NativeType type) |
|
466 |
{ |
|
467 |
#if defined(QT_SYMBIAN_SUPPORTS_SGIMAGE) && !defined(QT_NO_EGL) |
|
468 |
if (type == QPixmapData::SgImage && pixmap) { |
|
469 |
RSgImage *sgImage = reinterpret_cast<RSgImage*>(pixmap); |
|
470 |
// when "0" used as argument then |
|
471 |
// default display, context are used |
|
472 |
if (!context) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
473 |
context = qt_vg_create_context(0, QInternal::Pixmap); |
0 | 474 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
475 |
destroyImages(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
476 |
prevSize = QSize(); |
0 | 477 |
|
478 |
TInt err = 0; |
|
479 |
||
480 |
err = SgDriver::Open(); |
|
481 |
if(err != KErrNone) { |
|
482 |
cleanup(); |
|
483 |
return; |
|
484 |
} |
|
485 |
||
486 |
if(sgImage->IsNull()) { |
|
487 |
cleanup(); |
|
488 |
SgDriver::Close(); |
|
489 |
return; |
|
490 |
} |
|
491 |
||
492 |
TSgImageInfo sgImageInfo; |
|
493 |
err = sgImage->GetInfo(sgImageInfo); |
|
494 |
if(err != KErrNone) { |
|
495 |
cleanup(); |
|
496 |
SgDriver::Close(); |
|
497 |
return; |
|
498 |
} |
|
499 |
||
500 |
pfnEglCreateImageKHR eglCreateImageKHR = (pfnEglCreateImageKHR) eglGetProcAddress("eglCreateImageKHR"); |
|
501 |
pfnEglDestroyImageKHR eglDestroyImageKHR = (pfnEglDestroyImageKHR) eglGetProcAddress("eglDestroyImageKHR"); |
|
502 |
pfnVgCreateEGLImageTargetKHR vgCreateEGLImageTargetKHR = (pfnVgCreateEGLImageTargetKHR) eglGetProcAddress("vgCreateEGLImageTargetKHR"); |
|
503 |
||
504 |
if(eglGetError() != EGL_SUCCESS || !eglCreateImageKHR || !eglDestroyImageKHR || !vgCreateEGLImageTargetKHR) { |
|
505 |
cleanup(); |
|
506 |
SgDriver::Close(); |
|
507 |
return; |
|
508 |
} |
|
509 |
||
510 |
const EGLint KEglImageAttribs[] = {EGL_IMAGE_PRESERVED_SYMBIAN, EGL_TRUE, EGL_NONE}; |
|
511 |
EGLImageKHR eglImage = eglCreateImageKHR(context->display(), |
|
512 |
EGL_NO_CONTEXT, |
|
513 |
EGL_NATIVE_PIXMAP_KHR, |
|
514 |
(EGLClientBuffer)sgImage, |
|
515 |
(EGLint*)KEglImageAttribs); |
|
516 |
||
517 |
if(eglGetError() != EGL_SUCCESS) { |
|
518 |
cleanup(); |
|
519 |
SgDriver::Close(); |
|
520 |
return; |
|
521 |
} |
|
522 |
||
523 |
vgImage = vgCreateEGLImageTargetKHR(eglImage); |
|
524 |
if(vgGetError() != VG_NO_ERROR) { |
|
525 |
cleanup(); |
|
526 |
eglDestroyImageKHR(context->display(), eglImage); |
|
527 |
SgDriver::Close(); |
|
528 |
return; |
|
529 |
} |
|
530 |
||
531 |
w = sgImageInfo.iSizeInPixels.iWidth; |
|
532 |
h = sgImageInfo.iSizeInPixels.iHeight; |
|
533 |
d = 32; // We always use ARGB_Premultiplied for VG pixmaps. |
|
534 |
is_null = (w <= 0 || h <= 0); |
|
535 |
source = QImage(); |
|
536 |
recreate = false; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
537 |
prevSize = QSize(w, h); |
0 | 538 |
setSerialNumber(++qt_vg_pixmap_serial); |
539 |
// release stuff |
|
540 |
eglDestroyImageKHR(context->display(), eglImage); |
|
541 |
SgDriver::Close(); |
|
542 |
} else if (type == QPixmapData::FbsBitmap) { |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
543 |
CFbsBitmap *bitmap = reinterpret_cast<CFbsBitmap*>(pixmap); |
0 | 544 |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
545 |
bool deleteSourceBitmap = false; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
546 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
547 |
#ifdef Q_SYMBIAN_HAS_EXTENDED_BITMAP_TYPE |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
548 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
549 |
// Rasterize extended bitmaps |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
550 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
551 |
TUid extendedBitmapType = bitmap->ExtendedBitmapType(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
552 |
if (extendedBitmapType != KNullUid) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
553 |
bitmap = createBlitCopy(bitmap); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
554 |
deleteSourceBitmap = true; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
555 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
556 |
#endif |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
557 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
558 |
if (bitmap->IsCompressedInRAM()) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
559 |
bitmap = createBlitCopy(bitmap); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
560 |
deleteSourceBitmap = true; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
561 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
562 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
563 |
TDisplayMode displayMode = bitmap->DisplayMode(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
564 |
QImage::Format format = qt_TDisplayMode2Format(displayMode); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
565 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
566 |
TSize size = bitmap->SizeInPixels(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
567 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
568 |
bitmap->BeginDataAccess(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
569 |
uchar *bytes = (uchar*)bitmap->DataAddress(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
570 |
QImage img = QImage(bytes, size.iWidth, size.iHeight, format); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
571 |
img = img.copy(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
572 |
bitmap->EndDataAccess(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
573 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
574 |
if(displayMode == EGray2) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
575 |
//Symbian thinks set pixels are white/transparent, Qt thinks they are foreground/solid |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
576 |
//So invert mono bitmaps so that masks work correctly. |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
577 |
img.invertPixels(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
578 |
} else if(displayMode == EColor16M) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
579 |
img = img.rgbSwapped(); // EColor16M is BGR |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
580 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
581 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
582 |
fromImage(img, Qt::AutoColor); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
583 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
584 |
if(deleteSourceBitmap) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
585 |
delete bitmap; |
0 | 586 |
} |
587 |
#else |
|
588 |
Q_UNUSED(pixmap); |
|
589 |
Q_UNUSED(type); |
|
590 |
#endif |
|
591 |
} |
|
592 |
||
593 |
void* QVGPixmapData::toNativeType(NativeType type) |
|
594 |
{ |
|
595 |
#if defined(QT_SYMBIAN_SUPPORTS_SGIMAGE) && !defined(QT_NO_EGL) |
|
596 |
if (type == QPixmapData::SgImage) { |
|
597 |
toVGImage(); |
|
598 |
||
599 |
if(!isValid() || vgImage == VG_INVALID_HANDLE) |
|
600 |
return 0; |
|
601 |
||
602 |
TInt err = 0; |
|
603 |
||
604 |
err = SgDriver::Open(); |
|
605 |
if(err != KErrNone) |
|
606 |
return 0; |
|
607 |
||
608 |
TSgImageInfo sgInfo; |
|
609 |
sgInfo.iPixelFormat = EUidPixelFormatARGB_8888_PRE; |
|
610 |
sgInfo.iSizeInPixels.SetSize(w, h); |
|
611 |
sgInfo.iUsage = ESgUsageOpenVgImage | ESgUsageOpenVgTarget; |
|
612 |
sgInfo.iShareable = ETrue; |
|
613 |
sgInfo.iCpuAccess = ESgCpuAccessNone; |
|
614 |
sgInfo.iScreenId = KSgScreenIdMain; //KSgScreenIdAny; |
|
615 |
sgInfo.iUserAttributes = NULL; |
|
616 |
sgInfo.iUserAttributeCount = 0; |
|
617 |
||
618 |
RSgImage *sgImage = q_check_ptr(new RSgImage()); |
|
619 |
err = sgImage->Create(sgInfo, NULL, NULL); |
|
620 |
if(err != KErrNone) { |
|
621 |
SgDriver::Close(); |
|
622 |
return 0; |
|
623 |
} |
|
624 |
||
625 |
pfnEglCreateImageKHR eglCreateImageKHR = (pfnEglCreateImageKHR) eglGetProcAddress("eglCreateImageKHR"); |
|
626 |
pfnEglDestroyImageKHR eglDestroyImageKHR = (pfnEglDestroyImageKHR) eglGetProcAddress("eglDestroyImageKHR"); |
|
627 |
pfnVgCreateEGLImageTargetKHR vgCreateEGLImageTargetKHR = (pfnVgCreateEGLImageTargetKHR) eglGetProcAddress("vgCreateEGLImageTargetKHR"); |
|
628 |
||
629 |
if(eglGetError() != EGL_SUCCESS || !eglCreateImageKHR || !eglDestroyImageKHR || !vgCreateEGLImageTargetKHR) { |
|
630 |
SgDriver::Close(); |
|
631 |
return 0; |
|
632 |
} |
|
633 |
||
634 |
const EGLint KEglImageAttribs[] = {EGL_IMAGE_PRESERVED_SYMBIAN, EGL_TRUE, EGL_NONE}; |
|
635 |
EGLImageKHR eglImage = eglCreateImageKHR(context->display(), |
|
636 |
EGL_NO_CONTEXT, |
|
637 |
EGL_NATIVE_PIXMAP_KHR, |
|
638 |
(EGLClientBuffer)sgImage, |
|
639 |
(EGLint*)KEglImageAttribs); |
|
640 |
if(eglGetError() != EGL_SUCCESS) { |
|
641 |
sgImage->Close(); |
|
642 |
SgDriver::Close(); |
|
643 |
return 0; |
|
644 |
} |
|
645 |
||
646 |
VGImage dstVgImage = vgCreateEGLImageTargetKHR(eglImage); |
|
647 |
if(vgGetError() != VG_NO_ERROR) { |
|
648 |
eglDestroyImageKHR(context->display(), eglImage); |
|
649 |
sgImage->Close(); |
|
650 |
SgDriver::Close(); |
|
651 |
return 0; |
|
652 |
} |
|
653 |
||
654 |
vgCopyImage(dstVgImage, 0, 0, |
|
655 |
vgImage, 0, 0, |
|
656 |
w, h, VG_FALSE); |
|
657 |
||
658 |
if(vgGetError() != VG_NO_ERROR) { |
|
659 |
sgImage->Close(); |
|
660 |
sgImage = 0; |
|
661 |
} |
|
662 |
// release stuff |
|
663 |
vgDestroyImage(dstVgImage); |
|
664 |
eglDestroyImageKHR(context->display(), eglImage); |
|
665 |
SgDriver::Close(); |
|
666 |
return reinterpret_cast<void*>(sgImage); |
|
667 |
} else if (type == QPixmapData::FbsBitmap) { |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
668 |
CFbsBitmap *bitmap = q_check_ptr(new CFbsBitmap); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
669 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
670 |
if (bitmap) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
671 |
if (bitmap->Create(TSize(source.width(), source.height()), |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
672 |
EColor16MAP) == KErrNone) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
673 |
const uchar *sptr = qt_vg_imageBits(source); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
674 |
bitmap->BeginDataAccess(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
675 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
676 |
uchar *dptr = (uchar*)bitmap->DataAddress(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
677 |
Mem::Copy(dptr, sptr, source.byteCount()); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
678 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
679 |
bitmap->EndDataAccess(); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
680 |
} else { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
681 |
delete bitmap; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
682 |
bitmap = 0; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
683 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
684 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
685 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
686 |
return reinterpret_cast<void*>(bitmap); |
0 | 687 |
} |
688 |
#else |
|
689 |
Q_UNUSED(type); |
|
690 |
return 0; |
|
691 |
#endif |
|
692 |
} |
|
693 |
#endif //Q_OS_SYMBIAN |
|
694 |
||
695 |
QT_END_NAMESPACE |