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 | |
69 | QT_BEGIN_NAMESPACE |
70 | |
71 | class QPaintEngine; |
72 | class QGLFramebufferObject; |
73 | class QGLFramebufferObjectFormat; |
74 | class QGLPixmapData; |
75 | |
76 | #ifdef Q_OS_SYMBIAN |
77 | class QNativeImageHandleProvider; |
78 | #else |
79 | class QGLFramebufferObjectPool |
80 | { |
81 | public: |
82 | QGLFramebufferObject *acquire(const QSize &size, const QGLFramebufferObjectFormat &format, bool strictSize = false); |
83 | void release(QGLFramebufferObject *fbo); |
84 | |
85 | private: |
86 | QList<QGLFramebufferObject *> m_fbos; |
87 | }; |
88 | |
89 | QGLFramebufferObjectPool* qgl_fbo_pool(); |
90 | |
91 | |
92 | class QGLPixmapGLPaintDevice : public QGLPaintDevice |
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: |
105 | QGLPixmapData *data; |
106 | }; |
107 | #endif |
108 | |
109 | class Q_OPENGL_EXPORT QGLPixmapData : public QPixmapData |
110 | { |
111 | public: |
112 | QGLPixmapData(PixelType type); |
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 | |
191 | mutable QGLFramebufferObject *m_renderFbo; |
192 | mutable QPaintEngine *m_engine; |
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 |
205 | mutable QGLTexture m_texture; |
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 |
212 | mutable QColor m_fillColor; |
213 | mutable bool m_hasFillColor; |
214 | |
215 | mutable bool m_hasAlpha; |
216 | #ifndef Q_OS_SYMBIAN |
217 | mutable QGLPixmapGLPaintDevice m_glDevice; |
218 | #endif |
219 | friend class QGLPixmapGLPaintDevice; |
220 | friend class QMeeGoPixmapData; |
221 | friend class QMeeGoLivePixmapData; |
222 | }; |
223 | |
224 | QT_END_NAMESPACE |
225 | |
226 | #endif // QPIXMAPDATA_GL_P_H |
227 | |
228 | |
229 | |