author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 18 Aug 2010 10:37:55 +0300 | |
changeset 33 | 3e2da88830cd |
parent 30 | 5dc02b23752f |
child 37 | 758a864f9613 |
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 |
** |
|
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> |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
45 |
#if !defined(QT_NO_EGL) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
46 |
#include <QtGui/private/qegl_p.h> |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
47 |
#endif |
0 | 48 |
#include "qvg_p.h" |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
49 |
#include "qvgimagepool_p.h" |
0 | 50 |
|
51 |
QT_BEGIN_NAMESPACE |
|
52 |
||
53 |
static int qt_vg_pixmap_serial = 0; |
|
54 |
||
55 |
QVGPixmapData::QVGPixmapData(PixelType type) |
|
56 |
: QPixmapData(type, OpenVGClass) |
|
57 |
{ |
|
58 |
Q_ASSERT(type == QPixmapData::PixmapType); |
|
59 |
vgImage = VG_INVALID_HANDLE; |
|
60 |
vgImageOpacity = VG_INVALID_HANDLE; |
|
61 |
cachedOpacity = 1.0f; |
|
62 |
recreate = true; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
63 |
inImagePool = false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
64 |
inLRU = false; |
0 | 65 |
#if !defined(QT_NO_EGL) |
66 |
context = 0; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
67 |
qt_vg_register_pixmap(this); |
0 | 68 |
#endif |
69 |
setSerialNumber(++qt_vg_pixmap_serial); |
|
70 |
} |
|
71 |
||
72 |
QVGPixmapData::~QVGPixmapData() |
|
73 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
74 |
destroyImageAndContext(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
75 |
#if !defined(QT_NO_EGL) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
76 |
qt_vg_unregister_pixmap(this); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
77 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
78 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
79 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
80 |
void QVGPixmapData::destroyImages() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
81 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
82 |
if (inImagePool) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
83 |
QVGImagePool *pool = QVGImagePool::instance(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
84 |
if (vgImage != VG_INVALID_HANDLE) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
85 |
pool->releaseImage(this, vgImage); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
86 |
if (vgImageOpacity != VG_INVALID_HANDLE) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
87 |
pool->releaseImage(this, vgImageOpacity); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
88 |
} else { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
89 |
if (vgImage != VG_INVALID_HANDLE) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
90 |
vgDestroyImage(vgImage); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
91 |
if (vgImageOpacity != VG_INVALID_HANDLE) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
92 |
vgDestroyImage(vgImageOpacity); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
93 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
94 |
vgImage = VG_INVALID_HANDLE; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
95 |
vgImageOpacity = VG_INVALID_HANDLE; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
96 |
inImagePool = false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
97 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
98 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
99 |
void QVGPixmapData::destroyImageAndContext() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
100 |
{ |
0 | 101 |
if (vgImage != VG_INVALID_HANDLE) { |
102 |
// We need to have a context current to destroy the image. |
|
103 |
#if !defined(QT_NO_EGL) |
|
104 |
if (context->isCurrent()) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
105 |
destroyImages(); |
0 | 106 |
} else { |
107 |
// We don't currently have a widget surface active, but we |
|
108 |
// need a surface to make the context current. So use the |
|
109 |
// shared pbuffer surface instead. |
|
110 |
context->makeCurrent(qt_vg_shared_surface()); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
111 |
destroyImages(); |
0 | 112 |
context->lazyDoneCurrent(); |
113 |
} |
|
114 |
#else |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
115 |
destroyImages(); |
0 | 116 |
#endif |
117 |
} |
|
118 |
#if !defined(QT_NO_EGL) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
119 |
if (context) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
120 |
qt_vg_destroy_context(context, QInternal::Pixmap); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
121 |
context = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
122 |
} |
0 | 123 |
#endif |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
124 |
recreate = true; |
0 | 125 |
} |
126 |
||
127 |
QPixmapData *QVGPixmapData::createCompatiblePixmapData() const |
|
128 |
{ |
|
129 |
return new QVGPixmapData(pixelType()); |
|
130 |
} |
|
131 |
||
132 |
bool QVGPixmapData::isValid() const |
|
133 |
{ |
|
134 |
return (w > 0 && h > 0); |
|
135 |
} |
|
136 |
||
137 |
void QVGPixmapData::resize(int wid, int ht) |
|
138 |
{ |
|
139 |
if (w == wid && h == ht) |
|
140 |
return; |
|
141 |
||
142 |
w = wid; |
|
143 |
h = ht; |
|
144 |
d = 32; // We always use ARGB_Premultiplied for VG pixmaps. |
|
145 |
is_null = (w <= 0 || h <= 0); |
|
146 |
source = QImage(); |
|
147 |
recreate = true; |
|
148 |
||
149 |
setSerialNumber(++qt_vg_pixmap_serial); |
|
150 |
} |
|
151 |
||
152 |
void QVGPixmapData::fromImage |
|
153 |
(const QImage &image, Qt::ImageConversionFlags flags) |
|
154 |
{ |
|
155 |
if (image.size() == QSize(w, h)) |
|
156 |
setSerialNumber(++qt_vg_pixmap_serial); |
|
157 |
else |
|
158 |
resize(image.width(), image.height()); |
|
159 |
source = image.convertToFormat(sourceFormat(), flags); |
|
160 |
recreate = true; |
|
161 |
} |
|
162 |
||
163 |
void QVGPixmapData::fill(const QColor &color) |
|
164 |
{ |
|
165 |
if (!isValid()) |
|
166 |
return; |
|
167 |
||
168 |
if (source.isNull()) |
|
169 |
source = QImage(w, h, sourceFormat()); |
|
170 |
||
171 |
if (source.depth() == 1) { |
|
172 |
// Pick the best approximate color in the image's colortable. |
|
173 |
int gray = qGray(color.rgba()); |
|
174 |
if (qAbs(qGray(source.color(0)) - gray) < qAbs(qGray(source.color(1)) - gray)) |
|
175 |
source.fill(0); |
|
176 |
else |
|
177 |
source.fill(1); |
|
178 |
} else { |
|
179 |
source.fill(PREMUL(color.rgba())); |
|
180 |
} |
|
181 |
||
182 |
// Re-upload the image to VG the next time toVGImage() is called. |
|
183 |
recreate = true; |
|
184 |
} |
|
185 |
||
186 |
bool QVGPixmapData::hasAlphaChannel() const |
|
187 |
{ |
|
188 |
if (!source.isNull()) |
|
189 |
return source.hasAlphaChannel(); |
|
190 |
else |
|
191 |
return isValid(); |
|
192 |
} |
|
193 |
||
194 |
void QVGPixmapData::setAlphaChannel(const QPixmap &alphaChannel) |
|
195 |
{ |
|
196 |
forceToImage(); |
|
197 |
source.setAlphaChannel(alphaChannel.toImage()); |
|
198 |
} |
|
199 |
||
200 |
QImage QVGPixmapData::toImage() const |
|
201 |
{ |
|
202 |
if (!isValid()) |
|
203 |
return QImage(); |
|
204 |
||
205 |
if (source.isNull()) { |
|
206 |
source = QImage(w, h, sourceFormat()); |
|
207 |
recreate = true; |
|
208 |
} |
|
209 |
||
210 |
return source; |
|
211 |
} |
|
212 |
||
213 |
QImage *QVGPixmapData::buffer() |
|
214 |
{ |
|
215 |
forceToImage(); |
|
216 |
return &source; |
|
217 |
} |
|
218 |
||
219 |
QPaintEngine* QVGPixmapData::paintEngine() const |
|
220 |
{ |
|
221 |
// If the application wants to paint into the QPixmap, we first |
|
222 |
// force it to QImage format and then paint into that. |
|
223 |
// This is simpler than juggling multiple VG contexts. |
|
224 |
const_cast<QVGPixmapData *>(this)->forceToImage(); |
|
225 |
return source.paintEngine(); |
|
226 |
} |
|
227 |
||
228 |
VGImage QVGPixmapData::toVGImage() |
|
229 |
{ |
|
230 |
if (!isValid()) |
|
231 |
return VG_INVALID_HANDLE; |
|
232 |
||
233 |
#if !defined(QT_NO_EGL) |
|
234 |
// Increase the reference count on the shared context. |
|
235 |
if (!context) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
236 |
context = qt_vg_create_context(0, QInternal::Pixmap); |
0 | 237 |
#endif |
238 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
239 |
if (recreate && prevSize != QSize(w, h)) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
240 |
destroyImages(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
241 |
else if (recreate) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
242 |
cachedOpacity = -1.0f; // Force opacity image to be refreshed later. |
0 | 243 |
|
244 |
if (vgImage == VG_INVALID_HANDLE) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
245 |
vgImage = QVGImagePool::instance()->createImageForPixmap |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
246 |
(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
|
247 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
248 |
// 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
|
249 |
if (vgImage == VG_INVALID_HANDLE) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
250 |
return VG_INVALID_HANDLE; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
251 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
252 |
inImagePool = true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
253 |
} else if (inImagePool) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
254 |
QVGImagePool::instance()->useImage(this); |
0 | 255 |
} |
256 |
||
257 |
if (!source.isNull() && recreate) { |
|
258 |
vgImageSubData |
|
259 |
(vgImage, |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
260 |
source.constBits(), source.bytesPerLine(), |
0 | 261 |
VG_sARGB_8888_PRE, 0, 0, w, h); |
262 |
} |
|
263 |
||
264 |
recreate = false; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
265 |
prevSize = QSize(w, h); |
0 | 266 |
|
267 |
return vgImage; |
|
268 |
} |
|
269 |
||
270 |
VGImage QVGPixmapData::toVGImage(qreal opacity) |
|
271 |
{ |
|
272 |
#if !defined(QT_SHIVAVG) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
273 |
// 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
|
274 |
if (toVGImage() == VG_INVALID_HANDLE) |
0 | 275 |
return VG_INVALID_HANDLE; |
276 |
||
277 |
if (opacity == 1.0f) |
|
278 |
return vgImage; |
|
279 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
280 |
// Create an alternative image for the selected opacity. |
0 | 281 |
if (vgImageOpacity == VG_INVALID_HANDLE || cachedOpacity != opacity) { |
282 |
if (vgImageOpacity == VG_INVALID_HANDLE) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
283 |
if (inImagePool) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
284 |
vgImageOpacity = QVGImagePool::instance()->createImageForPixmap |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
285 |
(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
|
286 |
} else { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
287 |
vgImageOpacity = vgCreateImage |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
288 |
(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
|
289 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
290 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
291 |
// 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
|
292 |
if (vgImageOpacity == VG_INVALID_HANDLE) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
293 |
return VG_INVALID_HANDLE; |
0 | 294 |
} |
295 |
VGfloat matrix[20] = { |
|
296 |
1.0f, 0.0f, 0.0f, 0.0f, |
|
297 |
0.0f, 1.0f, 0.0f, 0.0f, |
|
298 |
0.0f, 0.0f, 1.0f, 0.0f, |
|
299 |
0.0f, 0.0f, 0.0f, opacity, |
|
300 |
0.0f, 0.0f, 0.0f, 0.0f |
|
301 |
}; |
|
302 |
vgColorMatrix(vgImageOpacity, vgImage, matrix); |
|
303 |
cachedOpacity = opacity; |
|
304 |
} |
|
305 |
||
306 |
return vgImageOpacity; |
|
307 |
#else |
|
308 |
// vgColorMatrix() doesn't work with ShivaVG, so ignore the opacity. |
|
309 |
Q_UNUSED(opacity); |
|
310 |
return toVGImage(); |
|
311 |
#endif |
|
312 |
} |
|
313 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
314 |
void QVGPixmapData::detachImageFromPool() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
315 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
316 |
if (inImagePool) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
317 |
QVGImagePool::instance()->detachImage(this); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
318 |
inImagePool = false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
319 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
320 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
321 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
322 |
void QVGPixmapData::hibernate() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
323 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
324 |
// 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
|
325 |
// 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
|
326 |
if (vgImage != VG_INVALID_HANDLE && source.isNull()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
327 |
return; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
328 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
329 |
forceToImage(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
330 |
destroyImageAndContext(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
331 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
332 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
333 |
void QVGPixmapData::reclaimImages() |
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 |
if (!inImagePool) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
336 |
return; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
337 |
forceToImage(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
338 |
destroyImages(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
339 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
340 |
|
22
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
341 |
Q_DECL_IMPORT extern int qt_defaultDpiX(); |
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
342 |
Q_DECL_IMPORT extern int qt_defaultDpiY(); |
0 | 343 |
|
344 |
int QVGPixmapData::metric(QPaintDevice::PaintDeviceMetric metric) const |
|
345 |
{ |
|
346 |
switch (metric) { |
|
347 |
case QPaintDevice::PdmWidth: |
|
348 |
return w; |
|
349 |
case QPaintDevice::PdmHeight: |
|
350 |
return h; |
|
351 |
case QPaintDevice::PdmNumColors: |
|
352 |
return 0; |
|
353 |
case QPaintDevice::PdmDepth: |
|
354 |
return d; |
|
355 |
case QPaintDevice::PdmWidthMM: |
|
356 |
return qRound(w * 25.4 / qt_defaultDpiX()); |
|
357 |
case QPaintDevice::PdmHeightMM: |
|
358 |
return qRound(h * 25.4 / qt_defaultDpiY()); |
|
359 |
case QPaintDevice::PdmDpiX: |
|
360 |
case QPaintDevice::PdmPhysicalDpiX: |
|
361 |
return qt_defaultDpiX(); |
|
362 |
case QPaintDevice::PdmDpiY: |
|
363 |
case QPaintDevice::PdmPhysicalDpiY: |
|
364 |
return qt_defaultDpiY(); |
|
365 |
default: |
|
366 |
qWarning("QVGPixmapData::metric(): Invalid metric"); |
|
367 |
return 0; |
|
368 |
} |
|
369 |
} |
|
370 |
||
371 |
// Force the pixmap data to be in QImage format. |
|
372 |
void QVGPixmapData::forceToImage() |
|
373 |
{ |
|
374 |
if (!isValid()) |
|
375 |
return; |
|
376 |
||
377 |
if (source.isNull()) |
|
378 |
source = QImage(w, h, sourceFormat()); |
|
379 |
||
380 |
recreate = true; |
|
381 |
} |
|
382 |
||
383 |
QImage::Format QVGPixmapData::sourceFormat() const |
|
384 |
{ |
|
385 |
return QImage::Format_ARGB32_Premultiplied; |
|
386 |
} |
|
387 |
||
388 |
/* |
|
389 |
\internal |
|
390 |
||
391 |
Returns the VGImage that is storing the contents of \a pixmap. |
|
392 |
Returns VG_INVALID_HANDLE if \a pixmap is not owned by the OpenVG |
|
393 |
graphics system or \a pixmap is invalid. |
|
394 |
||
395 |
This function is typically used to access the backing store |
|
396 |
for a pixmap when executing raw OpenVG calls. It must only |
|
397 |
be used when a QPainter is active and the OpenVG paint engine |
|
398 |
is in use by the QPainter. |
|
399 |
||
400 |
\sa {QtOpenVG Module} |
|
401 |
*/ |
|
402 |
Q_OPENVG_EXPORT VGImage qPixmapToVGImage(const QPixmap& pixmap) |
|
403 |
{ |
|
404 |
QPixmapData *pd = pixmap.pixmapData(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
405 |
if (!pd) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
406 |
return VG_INVALID_HANDLE; // null QPixmap |
0 | 407 |
if (pd->classId() == QPixmapData::OpenVGClass) { |
408 |
QVGPixmapData *vgpd = static_cast<QVGPixmapData *>(pd); |
|
409 |
if (vgpd->isValid()) |
|
410 |
return vgpd->toVGImage(); |
|
411 |
} |
|
412 |
return VG_INVALID_HANDLE; |
|
413 |
} |
|
414 |
||
415 |
QT_END_NAMESPACE |