src/openvg/qvgimagepool_p.h
changeset 3 41300fa6a67c
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     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 #ifndef QVGIMAGEPOOL_P_H
       
    43 #define QVGIMAGEPOOL_P_H
       
    44 
       
    45 //
       
    46 //  W A R N I N G
       
    47 //  -------------
       
    48 //
       
    49 // This file is not part of the Qt API.  It exists for the convenience
       
    50 // of other Qt classes.  This header file may change from version to
       
    51 // version without notice, or even be removed.
       
    52 //
       
    53 // We mean it.
       
    54 //
       
    55 
       
    56 #include "qvg.h"
       
    57 #include <QtCore/qscopedpointer.h>
       
    58 
       
    59 QT_BEGIN_NAMESPACE
       
    60 
       
    61 class QVGPixmapData;
       
    62 class QVGImagePoolPrivate;
       
    63 
       
    64 class Q_OPENVG_EXPORT QVGImagePool
       
    65 {
       
    66 public:
       
    67     QVGImagePool();
       
    68     virtual ~QVGImagePool();
       
    69 
       
    70     static QVGImagePool *instance();
       
    71 
       
    72     // This function can be used from system-specific graphics system
       
    73     // plugins to alter the image allocation strategy.
       
    74     static void setImagePool(QVGImagePool *pool);
       
    75 
       
    76     // Create a new VGImage from the pool with the specified parameters
       
    77     // that is not associated with a pixmap.  The VGImage is returned to
       
    78     // the pool when releaseImage() is called.
       
    79     //
       
    80     // This function will call reclaimSpace() when vgCreateImage() fails.
       
    81     //
       
    82     // This function is typically called when allocating temporary
       
    83     // VGImage's for pixmap filters.  The "keepData" object will not
       
    84     // be reclaimed if reclaimSpace() needs to be called.
       
    85     virtual VGImage createTemporaryImage(VGImageFormat format,
       
    86                                          VGint width, VGint height,
       
    87                                          VGbitfield allowedQuality,
       
    88                                          QVGPixmapData *keepData = 0);
       
    89 
       
    90     // Create a new VGImage with the specified parameters and associate
       
    91     // it with "data".  The QVGPixmapData will be notified when the
       
    92     // VGImage needs to be reclaimed by the pool.
       
    93     //
       
    94     // This function will call reclaimSpace() when vgCreateImage() fails.
       
    95     virtual VGImage createImageForPixmap(VGImageFormat format,
       
    96                                          VGint width, VGint height,
       
    97                                          VGbitfield allowedQuality,
       
    98                                          QVGPixmapData *data);
       
    99 
       
   100     // Create a permanent VGImage with the specified parameters.
       
   101     // If there is insufficient space for the vgCreateImage call,
       
   102     // then this function will call reclaimSpace() and try again.
       
   103     //
       
   104     // The caller is responsible for calling vgDestroyImage()
       
   105     // when it no longer needs the VGImage, as the image is not
       
   106     // recorded in the image pool.
       
   107     //
       
   108     // This function is typically used for pattern brushes where
       
   109     // the OpenVG engine is responsible for managing the lifetime
       
   110     // of the VGImage, destroying it automatically when the brush
       
   111     // is no longer in use.
       
   112     virtual VGImage createPermanentImage(VGImageFormat format,
       
   113                                          VGint width, VGint height,
       
   114                                          VGbitfield allowedQuality);
       
   115 
       
   116     // Release a VGImage that is no longer required.
       
   117     virtual void releaseImage(QVGPixmapData *data, VGImage image);
       
   118 
       
   119     // Notify the pool that a QVGPixmapData object is using
       
   120     // an image again.  This allows the pool to move the image
       
   121     // within a least-recently-used list of QVGPixmapData objects.
       
   122     virtual void useImage(QVGPixmapData *data);
       
   123 
       
   124     // Notify the pool that the VGImage's associated with a
       
   125     // QVGPixmapData are being detached from the pool.  The caller
       
   126     // will become responsible for calling vgDestroyImage().
       
   127     virtual void detachImage(QVGPixmapData *data);
       
   128 
       
   129     // Reclaim space for an image allocation with the specified parameters.
       
   130     // Returns true if space was reclaimed, or false if there is no
       
   131     // further space that can be reclaimed.  The "data" parameter
       
   132     // indicates the pixmap that is trying to obtain space which should
       
   133     // not itself be reclaimed.
       
   134     virtual bool reclaimSpace(VGImageFormat format,
       
   135                               VGint width, VGint height,
       
   136                               QVGPixmapData *data);
       
   137 
       
   138     // Hibernate the image pool because the context is about to be
       
   139     // destroyed.  All VGImage's left in the pool should be released.
       
   140     virtual void hibernate();
       
   141 
       
   142 protected:
       
   143     // Helper functions for managing the LRU list of QVGPixmapData objects.
       
   144     void moveToHeadOfLRU(QVGPixmapData *data);
       
   145     void removeFromLRU(QVGPixmapData *data);
       
   146     QVGPixmapData *pixmapLRU();
       
   147 
       
   148 private:
       
   149     QScopedPointer<QVGImagePoolPrivate> d_ptr;
       
   150 
       
   151     Q_DECLARE_PRIVATE(QVGImagePool)
       
   152     Q_DISABLE_COPY(QVGImagePool)
       
   153 };
       
   154 
       
   155 QT_END_NAMESPACE
       
   156 
       
   157 #endif