Qt 4.8
Public Functions | Static Public Functions | Protected Functions | Properties | List of all members
QVGImagePool Class Reference

#include <qvgimagepool_p.h>

Public Functions

virtual VGImage createImageForPixmap (VGImageFormat format, VGint width, VGint height, VGbitfield allowedQuality, QVGPixmapData *data)
 
virtual VGImage createPermanentImage (VGImageFormat format, VGint width, VGint height, VGbitfield allowedQuality)
 
virtual VGImage createTemporaryImage (VGImageFormat format, VGint width, VGint height, VGbitfield allowedQuality, QVGPixmapData *keepData=0)
 
virtual void detachImage (QVGPixmapData *data)
 
virtual void hibernate ()
 
 QVGImagePool ()
 
virtual bool reclaimSpace (VGImageFormat format, VGint width, VGint height, QVGPixmapData *data)
 
virtual void releaseImage (QVGPixmapData *data, VGImage image)
 
virtual void useImage (QVGPixmapData *data)
 
virtual ~QVGImagePool ()
 

Static Public Functions

static QVGImagePoolinstance ()
 
static void setImagePool (QVGImagePool *pool)
 

Protected Functions

void moveToHeadOfLRU (QVGPixmapData *data)
 
QVGPixmapDatapixmapLRU ()
 
void removeFromLRU (QVGPixmapData *data)
 

Properties

QScopedPointer< QVGImagePoolPrivated_ptr
 

Detailed Description

Definition at line 64 of file qvgimagepool_p.h.

Constructors and Destructors

◆ QVGImagePool()

QVGImagePool::QVGImagePool ( )

Definition at line 58 of file qvgimagepool.cpp.

Referenced by instance().

59  : d_ptr(new QVGImagePoolPrivate())
60 {
61 }
QScopedPointer< QVGImagePoolPrivate > d_ptr

◆ ~QVGImagePool()

QVGImagePool::~QVGImagePool ( )
virtual

Definition at line 63 of file qvgimagepool.cpp.

64 {
65 }

Functions

◆ createImageForPixmap()

VGImage QVGImagePool::createImageForPixmap ( VGImageFormat  format,
VGint  width,
VGint  height,
VGbitfield  allowedQuality,
QVGPixmapData data 
)
virtual

Definition at line 97 of file qvgimagepool.cpp.

Referenced by QVGPixmapData::toVGImage().

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 }
void moveToHeadOfLRU(QVGPixmapData *data)
Q_CORE_EXPORT void qWarning(const char *,...)
virtual bool reclaimSpace(VGImageFormat format, VGint width, VGint height, QVGPixmapData *data)

◆ createPermanentImage()

VGImage QVGImagePool::createPermanentImage ( VGImageFormat  format,
VGint  width,
VGint  height,
VGbitfield  allowedQuality 
)
virtual

Definition at line 116 of file qvgimagepool.cpp.

Referenced by drawImageTiled(), toVGImage(), toVGImageSubRect(), toVGImageWithOpacity(), and toVGImageWithOpacitySubRect().

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 }
Q_CORE_EXPORT void qWarning(const char *,...)
virtual bool reclaimSpace(VGImageFormat format, VGint width, VGint height, QVGPixmapData *data)

◆ createTemporaryImage()

VGImage QVGImagePool::createTemporaryImage ( VGImageFormat  format,
VGint  width,
VGint  height,
VGbitfield  allowedQuality,
QVGPixmapData keepData = 0 
)
virtual

Definition at line 81 of file qvgimagepool.cpp.

Referenced by QVGPixmapConvolutionFilter::draw(), QVGPixmapColorizeFilter::draw(), QVGPixmapDropShadowFilter::draw(), and QVGPixmapBlurFilter::draw().

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 }
Q_CORE_EXPORT void qWarning(const char *,...)
virtual bool reclaimSpace(VGImageFormat format, VGint width, VGint height, QVGPixmapData *data)

◆ detachImage()

void QVGImagePool::detachImage ( QVGPixmapData data)
virtual

Definition at line 144 of file qvgimagepool.cpp.

Referenced by QVGPixmapData::detachImageFromPool().

145 {
146  removeFromLRU(data);
147 }
void removeFromLRU(QVGPixmapData *data)

◆ hibernate()

void QVGImagePool::hibernate ( )
virtual

Definition at line 176 of file qvgimagepool.cpp.

Referenced by QVGGraphicsSystem::createWindowSurface(), and qt_vg_hibernate_pixmaps().

177 {
178  Q_D(QVGImagePool);
179  QVGPixmapData *pd = d->lruLast;
180  while (pd) {
181  QVGPixmapData *prevLRU = pd->prevLRU;
182  pd->inImagePool = false;
183  pd->inLRU = false;
184  pd->nextLRU = 0;
185  pd->prevLRU = 0;
186  pd->hibernate();
187  pd = prevLRU;
188  }
189  d->lruFirst = 0;
190  d->lruLast = 0;
191 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QVGPixmapData * prevLRU
QVGPixmapData * nextLRU
virtual void hibernate()

◆ instance()

QVGImagePool * QVGImagePool::instance ( )
static

◆ moveToHeadOfLRU()

void QVGImagePool::moveToHeadOfLRU ( QVGPixmapData data)
protected

Definition at line 193 of file qvgimagepool.cpp.

Referenced by createImageForPixmap(), reclaimSpace(), and useImage().

194 {
195  Q_D(QVGImagePool);
196  if (data->inLRU) {
197  if (!data->prevLRU)
198  return; // Already at the head of the list.
199  removeFromLRU(data);
200  }
201  data->inLRU = true;
202  data->nextLRU = d->lruFirst;
203  data->prevLRU = 0;
204  if (d->lruFirst)
205  d->lruFirst->prevLRU = data;
206  else
207  d->lruLast = data;
208  d->lruFirst = data;
209 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QVGPixmapData * prevLRU
static const char * data(const QByteArray &arr)
void removeFromLRU(QVGPixmapData *data)
QVGPixmapData * nextLRU

◆ pixmapLRU()

QVGPixmapData * QVGImagePool::pixmapLRU ( )
protected

Definition at line 227 of file qvgimagepool.cpp.

Referenced by reclaimSpace().

228 {
229  Q_D(QVGImagePool);
230  return d->lruLast;
231 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

◆ reclaimSpace()

bool QVGImagePool::reclaimSpace ( VGImageFormat  format,
VGint  width,
VGint  height,
QVGPixmapData data 
)
virtual

Definition at line 149 of file qvgimagepool.cpp.

Referenced by createImageForPixmap(), createPermanentImage(), and createTemporaryImage().

152 {
153  Q_UNUSED(format); // For future use in picking the best image to eject.
154  Q_UNUSED(width);
155  Q_UNUSED(height);
156 
157  bool succeeded = false;
158  bool wasInLRU = false;
159  if (data) {
160  wasInLRU = data->inLRU;
161  moveToHeadOfLRU(data);
162  }
163 
164  QVGPixmapData *lrudata = pixmapLRU();
165  if (lrudata && lrudata != data) {
166  lrudata->reclaimImages();
167  succeeded = true;
168  }
169 
170  if (data && !wasInLRU)
171  removeFromLRU(data);
172 
173  return succeeded;
174 }
void moveToHeadOfLRU(QVGPixmapData *data)
void removeFromLRU(QVGPixmapData *data)
QVGPixmapData * pixmapLRU()
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
virtual void reclaimImages()

◆ releaseImage()

void QVGImagePool::releaseImage ( QVGPixmapData data,
VGImage  image 
)
virtual

Definition at line 131 of file qvgimagepool.cpp.

Referenced by QVGPixmapData::destroyImages(), QVGPixmapConvolutionFilter::draw(), QVGPixmapColorizeFilter::draw(), QVGPixmapDropShadowFilter::draw(), and QVGPixmapBlurFilter::draw().

132 {
133  // Very simple strategy at the moment: just destroy the image.
134  if (data)
135  removeFromLRU(data);
136  vgDestroyImage(image);
137 }
void removeFromLRU(QVGPixmapData *data)

◆ removeFromLRU()

void QVGImagePool::removeFromLRU ( QVGPixmapData data)
protected

Definition at line 211 of file qvgimagepool.cpp.

Referenced by detachImage(), moveToHeadOfLRU(), reclaimSpace(), and releaseImage().

212 {
213  Q_D(QVGImagePool);
214  if (!data->inLRU)
215  return;
216  if (data->nextLRU)
217  data->nextLRU->prevLRU = data->prevLRU;
218  else
219  d->lruLast = data->prevLRU;
220  if (data->prevLRU)
221  data->prevLRU->nextLRU = data->nextLRU;
222  else
223  d->lruFirst = data->nextLRU;
224  data->inLRU = false;
225 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QVGPixmapData * prevLRU
QVGPixmapData * nextLRU

◆ setImagePool()

void QVGImagePool::setImagePool ( QVGImagePool pool)
static

Definition at line 74 of file qvgimagepool.cpp.

75 {
76  if (qt_vg_image_pool != pool)
77  delete qt_vg_image_pool;
78  qt_vg_image_pool = pool;
79 }
static QVGImagePool * qt_vg_image_pool

◆ useImage()

void QVGImagePool::useImage ( QVGPixmapData data)
virtual

Definition at line 139 of file qvgimagepool.cpp.

Referenced by QVGPixmapData::toVGImage().

140 {
141  moveToHeadOfLRU(data);
142 }
void moveToHeadOfLRU(QVGPixmapData *data)

Properties

◆ d_ptr

QScopedPointer<QVGImagePoolPrivate> QVGImagePool::d_ptr
private

Definition at line 149 of file qvgimagepool_p.h.


The documentation for this class was generated from the following files: