1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the QtOpenVG module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include "qpixmapdata_vg_p.h"
|
---|
43 | #include "qpaintengine_vg_p.h"
|
---|
44 | #include <QtGui/private/qdrawhelper_p.h>
|
---|
45 | #include "qvg_p.h"
|
---|
46 | #include "qvgimagepool_p.h"
|
---|
47 |
|
---|
48 | #ifdef QT_SYMBIAN_SUPPORTS_SGIMAGE
|
---|
49 | #include <graphics/sgimage.h>
|
---|
50 | typedef EGLImageKHR (*pfnEglCreateImageKHR)(EGLDisplay, EGLContext, EGLenum, EGLClientBuffer, EGLint*);
|
---|
51 | typedef EGLBoolean (*pfnEglDestroyImageKHR)(EGLDisplay, EGLImageKHR);
|
---|
52 | typedef VGImage (*pfnVgCreateEGLImageTargetKHR)(VGeglImageKHR);
|
---|
53 | #endif
|
---|
54 |
|
---|
55 | QT_BEGIN_NAMESPACE
|
---|
56 |
|
---|
57 | static int qt_vg_pixmap_serial = 0;
|
---|
58 |
|
---|
59 | QVGPixmapData::QVGPixmapData(PixelType type)
|
---|
60 | : QPixmapData(type, OpenVGClass)
|
---|
61 | {
|
---|
62 | Q_ASSERT(type == QPixmapData::PixmapType);
|
---|
63 | vgImage = VG_INVALID_HANDLE;
|
---|
64 | vgImageOpacity = VG_INVALID_HANDLE;
|
---|
65 | cachedOpacity = 1.0f;
|
---|
66 | recreate = true;
|
---|
67 | inImagePool = false;
|
---|
68 | inLRU = false;
|
---|
69 | #if !defined(QT_NO_EGL)
|
---|
70 | context = 0;
|
---|
71 | qt_vg_register_pixmap(this);
|
---|
72 | #endif
|
---|
73 | setSerialNumber(++qt_vg_pixmap_serial);
|
---|
74 | }
|
---|
75 |
|
---|
76 | QVGPixmapData::~QVGPixmapData()
|
---|
77 | {
|
---|
78 | destroyImageAndContext();
|
---|
79 | #if !defined(QT_NO_EGL)
|
---|
80 | qt_vg_unregister_pixmap(this);
|
---|
81 | #endif
|
---|
82 | }
|
---|
83 |
|
---|
84 | void QVGPixmapData::destroyImages()
|
---|
85 | {
|
---|
86 | if (inImagePool) {
|
---|
87 | QVGImagePool *pool = QVGImagePool::instance();
|
---|
88 | if (vgImage != VG_INVALID_HANDLE)
|
---|
89 | pool->releaseImage(this, vgImage);
|
---|
90 | if (vgImageOpacity != VG_INVALID_HANDLE)
|
---|
91 | pool->releaseImage(this, vgImageOpacity);
|
---|
92 | } else {
|
---|
93 | if (vgImage != VG_INVALID_HANDLE)
|
---|
94 | vgDestroyImage(vgImage);
|
---|
95 | if (vgImageOpacity != VG_INVALID_HANDLE)
|
---|
96 | vgDestroyImage(vgImageOpacity);
|
---|
97 | }
|
---|
98 | vgImage = VG_INVALID_HANDLE;
|
---|
99 | vgImageOpacity = VG_INVALID_HANDLE;
|
---|
100 | inImagePool = false;
|
---|
101 | }
|
---|
102 |
|
---|
103 | void QVGPixmapData::destroyImageAndContext()
|
---|
104 | {
|
---|
105 | if (vgImage != VG_INVALID_HANDLE) {
|
---|
106 | // We need to have a context current to destroy the image.
|
---|
107 | #if !defined(QT_NO_EGL)
|
---|
108 | if (context->isCurrent()) {
|
---|
109 | destroyImages();
|
---|
110 | } else {
|
---|
111 | // We don't currently have a widget surface active, but we
|
---|
112 | // need a surface to make the context current. So use the
|
---|
113 | // shared pbuffer surface instead.
|
---|
114 | context->makeCurrent(qt_vg_shared_surface());
|
---|
115 | destroyImages();
|
---|
116 | context->lazyDoneCurrent();
|
---|
117 | }
|
---|
118 | #else
|
---|
119 | destroyImages();
|
---|
120 | #endif
|
---|
121 | }
|
---|
122 | #if !defined(QT_NO_EGL)
|
---|
123 | if (context) {
|
---|
124 | qt_vg_destroy_context(context, QInternal::Pixmap);
|
---|
125 | context = 0;
|
---|
126 | }
|
---|
127 | #endif
|
---|
128 | recreate = true;
|
---|
129 | }
|
---|
130 |
|
---|
131 | QPixmapData *QVGPixmapData::createCompatiblePixmapData() const
|
---|
132 | {
|
---|
133 | return new QVGPixmapData(pixelType());
|
---|
134 | }
|
---|
135 |
|
---|
136 | bool QVGPixmapData::isValid() const
|
---|
137 | {
|
---|
138 | return (w > 0 && h > 0);
|
---|
139 | }
|
---|
140 |
|
---|
141 | void QVGPixmapData::resize(int wid, int ht)
|
---|
142 | {
|
---|
143 | if (w == wid && h == ht)
|
---|
144 | return;
|
---|
145 |
|
---|
146 | w = wid;
|
---|
147 | h = ht;
|
---|
148 | d = 32; // We always use ARGB_Premultiplied for VG pixmaps.
|
---|
149 | is_null = (w <= 0 || h <= 0);
|
---|
150 | source = QImage();
|
---|
151 | recreate = true;
|
---|
152 |
|
---|
153 | setSerialNumber(++qt_vg_pixmap_serial);
|
---|
154 | }
|
---|
155 |
|
---|
156 | void QVGPixmapData::fromImage
|
---|
157 | (const QImage &image, Qt::ImageConversionFlags flags)
|
---|
158 | {
|
---|
159 | if (image.size() == QSize(w, h))
|
---|
160 | setSerialNumber(++qt_vg_pixmap_serial);
|
---|
161 | else
|
---|
162 | resize(image.width(), image.height());
|
---|
163 | source = image.convertToFormat(sourceFormat(), flags);
|
---|
164 | recreate = true;
|
---|
165 | }
|
---|
166 |
|
---|
167 | void QVGPixmapData::fill(const QColor &color)
|
---|
168 | {
|
---|
169 | if (!isValid())
|
---|
170 | return;
|
---|
171 |
|
---|
172 | if (source.isNull())
|
---|
173 | source = QImage(w, h, sourceFormat());
|
---|
|
---|