Qt 4.8
qpixmapdata_gl_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtOpenGL module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QPIXMAPDATA_GL_P_H
43 #define QPIXMAPDATA_GL_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 purely as an
50 // implementation detail. 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 "qgl_p.h"
57 #include "qgl.h"
58 
59 #include "private/qpixmapdata_p.h"
60 #include "private/qglpaintdevice_p.h"
61 
62 #ifdef Q_OS_SYMBIAN
63 #include "private/qvolatileimage_p.h"
64 #ifdef QT_SYMBIAN_SUPPORTS_SGIMAGE
65 # include <sgresource/sgimage.h>
66 #endif
67 #endif
68 
70 
71 class QPaintEngine;
74 class QGLPixmapData;
75 
76 #ifdef Q_OS_SYMBIAN
78 #else
80 {
81 public:
82  QGLFramebufferObject *acquire(const QSize &size, const QGLFramebufferObjectFormat &format, bool strictSize = false);
83  void release(QGLFramebufferObject *fbo);
84 
85 private:
87 };
88 
90 
91 
93 {
94 public:
95  QPaintEngine* paintEngine() const;
96 
97  void beginPaint();
98  void endPaint();
99  QGLContext* context() const;
100  QSize size() const;
101  bool alphaRequested() const;
102 
103  void setPixmapData(QGLPixmapData*);
104 private:
106 };
107 #endif
108 
110 {
111 public:
113  ~QGLPixmapData();
114 
115  QPixmapData *createCompatiblePixmapData() const;
116 
117  // Re-implemented from QPixmapData:
118  void resize(int width, int height);
119  void fromImage(const QImage &image, Qt::ImageConversionFlags flags);
120  void fromImageReader(QImageReader *imageReader,
121  Qt::ImageConversionFlags flags);
122  bool fromFile(const QString &filename, const char *format,
123  Qt::ImageConversionFlags flags);
124  bool fromData(const uchar *buffer, uint len, const char *format,
125  Qt::ImageConversionFlags flags);
126  void copy(const QPixmapData *data, const QRect &rect);
127  bool scroll(int dx, int dy, const QRect &rect);
128  void fill(const QColor &color);
129  bool hasAlphaChannel() const;
130  QImage toImage() const;
131  QPaintEngine *paintEngine() const;
132  int metric(QPaintDevice::PaintDeviceMetric metric) const;
133 
134  // For accessing as a target:
135  QGLPaintDevice *glDevice() const;
136 
137  // For accessing as a source:
138  bool isValidContext(const QGLContext *ctx) const;
139  GLuint bind(bool copyBack = true) const;
140  QGLTexture *texture() const;
141 
142 #ifdef Q_OS_SYMBIAN
143  void destroyTexture();
144  // Detach this image from the image pool.
145  void detachTextureFromPool();
146  // Release the GL resources associated with this pixmap and copy
147  // the pixmap's contents out of the GPU back into main memory.
148  // The GL resource will be automatically recreated the next time
149  // ensureCreated() is called. Does nothing if the pixmap cannot be
150  // hibernated for some reason (e.g. texture is shared with another
151  // process via a SgImage).
152  void hibernate();
153  // Called when the QGLTexturePool wants to reclaim this pixmap's
154  // texture objects to reuse storage.
155  void reclaimTexture();
156  void forceToImage();
157 
158  QVolatileImage toVolatileImage() const { return m_source; }
159  QImage::Format idealFormat(QImage &image, Qt::ImageConversionFlags flags);
160  void* toNativeType(NativeType type);
161  void fromNativeType(void* pixmap, NativeType type);
162  bool initFromNativeImageHandle(void *handle, const QString &type);
163  void createFromNativeImageHandleProvider();
164  void releaseNativeImageHandle();
165 #endif
166 
167 private:
168  bool isValid() const;
169 
170  void ensureCreated() const;
171 
172  bool isUninitialized() const { return m_dirty && m_source.isNull(); }
173 
174  bool needsFill() const { return m_hasFillColor; }
175  QColor fillColor() const { return m_fillColor; }
176 
177 
178 
179  QGLPixmapData(const QGLPixmapData &other);
180  QGLPixmapData &operator=(const QGLPixmapData &other);
181 
182  void copyBackFromRenderFbo(bool keepCurrentFboBound) const;
183  QSize size() const { return QSize(w, h); }
184 
185  bool useFramebufferObjects() const;
186 
187  QImage fillImage(const QColor &color) const;
188 
189  void createPixmapForImage(QImage &image, Qt::ImageConversionFlags flags, bool inPlace);
190 
193  mutable QGLContext *m_ctx;
194 #ifdef Q_OS_SYMBIAN
195  mutable QVolatileImage m_source;
196  mutable QNativeImageHandleProvider *nativeImageHandleProvider;
197  void *nativeImageHandle;
198  QString nativeImageType;
199 #ifdef QT_SYMBIAN_SUPPORTS_SGIMAGE
200  RSgImage *m_sgImage;
201 #endif
202 #else
203  mutable QImage m_source;
204 #endif
206 
207  // the texture is not in sync with the source image
208  mutable bool m_dirty;
209 
210  // fill has been called and no painting has been done, so the pixmap is
211  // represented by a single fill color
213  mutable bool m_hasFillColor;
214 
215  mutable bool m_hasAlpha;
216 #ifndef Q_OS_SYMBIAN
218 #endif
220  friend class QMeeGoPixmapData;
221  friend class QMeeGoLivePixmapData;
222 };
223 
225 
226 #endif // QPIXMAPDATA_GL_P_H
227 
228 
QGLTexture m_texture
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
QGLContext * m_ctx
Format
The following image formats are available in Qt.
Definition: qimage.h:91
int type
Definition: qmetatype.cpp:239
QGLPixmapGLPaintDevice m_glDevice
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define Q_OPENGL_EXPORT
Definition: qglobal.h:1455
The QGLFramebufferObject class encapsulates an OpenGL framebuffer object.
The QGLFramebufferObject class provides a pool of framebuffer objects for offscreen rendering purpose...
QGLFramebufferObjectPool * qgl_fbo_pool()
The QString class provides a Unicode character string.
Definition: qstring.h:83
QPaintEngine * m_engine
QGLFramebufferObject * acquire(const QSize &size, const QGLFramebufferObjectFormat &format, bool strictSize=false)
unsigned char uchar
Definition: qglobal.h:994
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
QList< QGLFramebufferObject * > m_fbos
void release(QGLFramebufferObject *fbo)
QSize size() const
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
bool needsFill() const
The QPaintEngine class provides an abstract definition of how QPainter draws to a given device on a g...
Definition: qpaintengine.h:90
The QImageReader class provides a format independent interface for reading images from files or other...
Definition: qimagereader.h:62
#define ctx
Definition: qgl.cpp:6094
QColor fillColor() const
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QGLFramebufferObject * m_renderFbo
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
The QGLFramebufferObjectFormat class specifies the format of an OpenGL framebuffer object...
bool isUninitialized() const
The QList class is a template class that provides lists.
Definition: qdatastream.h:62