| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2011 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 | #ifndef QPIXMAPDATA_VG_P_H
|
|---|
| 43 | #define QPIXMAPDATA_VG_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 <QtGui/private/qpixmap_raster_p.h>
|
|---|
| 57 | #include <private/qvg_p.h>
|
|---|
| 58 |
|
|---|
| 59 | #if defined(Q_OS_SYMBIAN)
|
|---|
| 60 | class RSGImage;
|
|---|
| 61 | #endif
|
|---|
| 62 |
|
|---|
| 63 | QT_BEGIN_NAMESPACE
|
|---|
| 64 |
|
|---|
| 65 | class QEglContext;
|
|---|
| 66 | class QVGImagePool;
|
|---|
| 67 | class QImageReader;
|
|---|
| 68 |
|
|---|
| 69 | #if !defined(QT_NO_EGL)
|
|---|
| 70 | class QVGPixmapData;
|
|---|
| 71 | class QVGSharedContext;
|
|---|
| 72 |
|
|---|
| 73 | void qt_vg_register_pixmap(QVGPixmapData *pd);
|
|---|
| 74 | void qt_vg_unregister_pixmap(QVGPixmapData *pd);
|
|---|
| 75 | void qt_vg_hibernate_pixmaps(QVGSharedContext *context);
|
|---|
| 76 | #endif
|
|---|
| 77 |
|
|---|
| 78 | class Q_OPENVG_EXPORT QVGPixmapData : public QPixmapData
|
|---|
| 79 | {
|
|---|
| 80 | public:
|
|---|
| 81 | QVGPixmapData(PixelType type);
|
|---|
| 82 | ~QVGPixmapData();
|
|---|
| 83 |
|
|---|
| 84 | QPixmapData *createCompatiblePixmapData() const;
|
|---|
| 85 |
|
|---|
| 86 | // Is this pixmap valid (i.e. non-zero in size)?
|
|---|
| 87 | bool isValid() const;
|
|---|
| 88 |
|
|---|
| 89 | void resize(int width, int height);
|
|---|
| 90 | void fromImage(const QImage &image, Qt::ImageConversionFlags flags);
|
|---|
| 91 | void fromImageReader(QImageReader *imageReader,
|
|---|
| 92 | Qt::ImageConversionFlags flags);
|
|---|
| 93 | bool fromFile(const QString &filename, const char *format,
|
|---|
| 94 | Qt::ImageConversionFlags flags);
|
|---|
| 95 | bool fromData(const uchar *buffer, uint len, const char *format,
|
|---|
| 96 | Qt::ImageConversionFlags flags);
|
|---|
| 97 |
|
|---|
| 98 | void fill(const QColor &color);
|
|---|
| 99 | bool hasAlphaChannel() const;
|
|---|
| 100 | void setAlphaChannel(const QPixmap &alphaChannel);
|
|---|
| 101 | QImage toImage() const;
|
|---|
| 102 | QImage *buffer();
|
|---|
| 103 | QPaintEngine* paintEngine() const;
|
|---|
| 104 |
|
|---|
| 105 | // Return the VGImage form of this pixmap, creating it if necessary.
|
|---|
| 106 | // This assumes that there is a VG context current.
|
|---|
| 107 | virtual VGImage toVGImage();
|
|---|
| 108 |
|
|---|
| 109 | // Return the VGImage form for a specific opacity setting.
|
|---|
| 110 | virtual VGImage toVGImage(qreal opacity);
|
|---|
| 111 |
|
|---|
| 112 | // Detach this image from the image pool.
|
|---|
| 113 | virtual void detachImageFromPool();
|
|---|
| 114 |
|
|---|
| 115 | // Release the VG resources associated with this pixmap and copy
|
|---|
| 116 | // the pixmap's contents out of the GPU back into main memory.
|
|---|
| 117 | // The VG resource will be automatically recreated the next time
|
|---|
| 118 | // toVGImage() is called. Does nothing if the pixmap cannot be
|
|---|
| 119 | // hibernated for some reason (e.g. VGImage is shared with another
|
|---|
| 120 | // process via a SgImage).
|
|---|
| 121 | virtual void hibernate();
|
|---|
| 122 |
|
|---|
| 123 | // Called when the QVGImagePool wants to reclaim this pixmap's
|
|---|
| 124 | // VGImage objects to reuse storage.
|
|---|
| 125 | virtual void reclaimImages();
|
|---|
| 126 |
|
|---|
| 127 | QSize size() const { return QSize(w, h); }
|
|---|
| 128 |
|
|---|
| 129 | #if defined(Q_OS_SYMBIAN)
|
|---|
| 130 | void* toNativeType(NativeType type);
|
|---|
| 131 | void fromNativeType(void* pixmap, NativeType type);
|
|---|
| 132 | #endif
|
|---|
| 133 |
|
|---|
| 134 | protected:
|
|---|
| 135 | int metric(QPaintDevice::PaintDeviceMetric metric) const;
|
|---|
| 136 | void createPixmapForImage(QImage &image, Qt::ImageConversionFlags flags, bool inPlace);
|
|---|
| 137 |
|
|---|
| 138 | #if defined(Q_OS_SYMBIAN)
|
|---|
| 139 | void cleanup();
|
|---|
| 140 | #endif
|
|---|
| 141 |
|
|---|
| 142 | private:
|
|---|
| 143 | QVGPixmapData *nextLRU;
|
|---|
| 144 | QVGPixmapData *prevLRU;
|
|---|
| 145 | bool inLRU;
|
|---|
| 146 | bool failedToAlloc;
|
|---|
| 147 | friend class QVGImagePool;
|
|---|
| 148 | friend class QVGPaintEngine;
|
|---|
| 149 |
|
|---|
| 150 | #if !defined(QT_NO_EGL)
|
|---|
| 151 | QVGPixmapData *next;
|
|---|
| 152 | QVGPixmapData *prev;
|
|---|
| 153 |
|
|---|
| 154 | friend void qt_vg_register_pixmap(QVGPixmapData *pd);
|
|---|
| 155 | friend void qt_vg_unregister_pixmap(QVGPixmapData *pd);
|
|---|
| 156 | friend void qt_vg_hibernate_pixmaps(QVGSharedContext *context);
|
|---|
| 157 | #endif
|
|---|
| 158 |
|
|---|
| 159 | protected:
|
|---|
| 160 | QSize prevSize;
|
|---|
| 161 | VGImage vgImage;
|
|---|
| 162 | VGImage vgImageOpacity;
|
|---|
| 163 | qreal cachedOpacity;
|
|---|
| 164 | mutable QImage source;
|
|---|
| 165 | mutable bool recreate;
|
|---|
| 166 | bool inImagePool;
|
|---|
| 167 | #if !defined(QT_NO_EGL)
|
|---|
| 168 | mutable QEglContext *context;
|
|---|
| 169 | #endif
|
|---|
| 170 |
|
|---|
| 171 | void forceToImage();
|
|---|
| 172 | QImage::Format sourceFormat() const;
|
|---|
| 173 |
|
|---|
| 174 | void destroyImageAndContext();
|
|---|
| 175 | void destroyImages();
|
|---|
| 176 | };
|
|---|
| 177 |
|
|---|
| 178 | QT_END_NAMESPACE
|
|---|
| 179 |
|
|---|
| 180 | #endif
|
|---|