source: trunk/src/openvg/qpixmapdata_vg.cpp@ 1023

Last change on this file since 1023 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

  • Property svn:eol-style set to native
File size: 13.6 KB
RevLine 
[556]1/****************************************************************************
2**
[846]3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
[556]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>
[846]45#if !defined(QT_NO_EGL)
46#include <QtGui/private/qegl_p.h>
47#endif
[556]48#include "qvg_p.h"
49#include "qvgimagepool_p.h"
[846]50#include <QBuffer>
51#include <QImageReader>
52#include <QtGui/private/qimage_p.h>
[556]53
54QT_BEGIN_NAMESPACE
55
56static int qt_vg_pixmap_serial = 0;
57
58QVGPixmapData::QVGPixmapData(PixelType type)
59 : QPixmapData(type, OpenVGClass)
60{
61 Q_ASSERT(type == QPixmapData::PixmapType);
62 vgImage = VG_INVALID_HANDLE;
63 vgImageOpacity = VG_INVALID_HANDLE;
64 cachedOpacity = 1.0f;
65 recreate = true;
66 inImagePool = false;
67 inLRU = false;
[846]68 failedToAlloc = false;
[556]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
76QVGPixmapData::~QVGPixmapData()
77{
78 destroyImageAndContext();
79#if !defined(QT_NO_EGL)
80 qt_vg_unregister_pixmap(this);
81#endif
82}
83
84void 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
103void 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
131QPixmapData *QVGPixmapData::createCompatiblePixmapData() const
132{
133 return new QVGPixmapData(pixelType());
134}
135
136bool QVGPixmapData::isValid() const
137{
138 return (w > 0 && h > 0);
139}
140
141void 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
156void QVGPixmapData::fromImage
157 (const QImage &image, Qt::ImageConversionFlags flags)
158{
[846]159 if(image.isNull())
160 return;
161
162 QImage img = image;
163 createPixmapForImage(img, flags, false);