source: trunk/src/openvg/qvgimagepool.cpp@ 674

Last change on this file since 674 was 651, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.2 sources.

  • Property svn:eol-style set to native
File size: 6.3 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 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 "qvgimagepool_p.h"
43#include "qpixmapdata_vg_p.h"
44
45QT_BEGIN_NAMESPACE
46
47static QVGImagePool *qt_vg_image_pool = 0;
48
49class QVGImagePoolPrivate
50{
51public:
52 QVGImagePoolPrivate() : lruFirst(0), lruLast(0) {}
53
54 QVGPixmapData *lruFirst;
55 QVGPixmapData *lruLast;
56};
57
58QVGImagePool::QVGImagePool()
59 : d_ptr(new QVGImagePoolPrivate())
60{
61}
62
63QVGImagePool::~QVGImagePool()
64{
65}
66
67QVGImagePool *QVGImagePool::instance()
68{
69 if (!qt_vg_image_pool)
70 qt_vg_image_pool = new QVGImagePool();
71 return qt_vg_image_pool;
72}
73
74void QVGImagePool::setImagePool(QVGImagePool *pool)
75{
76 if (qt_vg_image_pool != pool)
77 delete qt_vg_image_pool;
78 qt_vg_image_pool = pool;
79}
80
81VGImage QVGImagePool::createTemporaryImage(VGImageFormat format,
82 VGint width, VGint height,
83 VGbitfield allowedQuality,
84 QVGPixmapData *keepData)
85{
86 VGImage image;
87 do {
88 image = vgCreateImage(format, width, height, allowedQuality);
89 if (image != VG_INVALID_HANDLE)
90 return image;
91 } while (reclaimSpace(format, width, height, keepData));
92 qWarning("QVGImagePool: cannot reclaim sufficient space for a %dx%d temporary image",
93 width, height);
94 return VG_INVALID_HANDLE;
95}
96
97VGImage QVGImagePool::createImageForPixmap(VGImageFormat format,
98 VGint width, VGint height,
99 VGbitfield allowedQuality,
100 QVGPixmapData *data)
101{
102 VGImage image;
103 do {
104 image = vgCreateImage(format, width, height, allowedQuality);
105 if (image != VG_INVALID_HANDLE) {
106 if (data)
107 moveToHeadOfLRU(data);
108 return image;
109 }
110 } while (reclaimSpace(format, width, height, data));
111 qWarning("QVGImagePool: cannot reclaim sufficient space for a %dx%d pixmap",
112 width, height);
113 return VG_INVALID_HANDLE;
114}
115
116VGImage QVGImagePool::createPermanentImage(VGImageFormat format,
117 VGint width, VGint height,
118 VGbitfield allowedQuality)
119{
120 VGImage image;
121 do {
122 image = vgCreateImage(format, width, height, allowedQuality);
123 if (image != VG_INVALID_HANDLE)
124 return image;
125 } while (reclaimSpace(format, width, height, 0));
126 qWarning("QVGImagePool: cannot reclaim sufficient space for a %dx%d image",
127 width, height);
128 return VG_INVALID_HANDLE;
129}
130
131void QVGImagePool::releaseImage(QVGPixmapData *data, VGImage image)
132{
133 // Very simple strategy at the moment: just destroy the image.
134 if (data)
135 removeFromLRU(data);
136 vgDestroyImage(image);
137}
138
139void QVGImagePool::useImage(QVGPixmapData *data)
140{