62 #include "QtCore/qatomic.h" |
62 #include "QtCore/qatomic.h" |
63 #include "private/qwidget_p.h" |
63 #include "private/qwidget_p.h" |
64 #include "qcache.h" |
64 #include "qcache.h" |
65 #include "qglpaintdevice_p.h" |
65 #include "qglpaintdevice_p.h" |
66 |
66 |
67 #ifndef QT_OPENGL_ES_1_CL |
67 #ifndef QT_NO_EGL |
68 #define q_vertexType float |
68 #include <QtGui/private/qegl_p.h> |
69 #define q_vertexTypeEnum GL_FLOAT |
|
70 #define f2vt(f) (f) |
|
71 #define vt2f(x) (x) |
|
72 #define i2vt(i) (float(i)) |
|
73 #else |
|
74 #define FLOAT2X(f) (int( (f) * (65536))) |
|
75 #define X2FLOAT(x) (float(x) / 65536.0f) |
|
76 #define f2vt(f) FLOAT2X(f) |
|
77 #define i2vt(i) ((i)*65536) |
|
78 #define vt2f(x) X2FLOAT(x) |
|
79 #define q_vertexType GLfixed |
|
80 #define q_vertexTypeEnum GL_FIXED |
|
81 #endif //QT_OPENGL_ES_1_CL |
|
82 |
|
83 #if defined(QT_OPENGL_ES) || defined(QT_OPENGL_ES_2) |
|
84 QT_BEGIN_INCLUDE_NAMESPACE |
|
85 |
|
86 #if defined(QT_OPENGL_ES_2) |
|
87 # include <GLES2/gl2.h> |
|
88 #endif |
|
89 |
|
90 #if defined(QT_GLES_EGL) |
|
91 # include <GLES/egl.h> |
|
92 #else |
|
93 # include <EGL/egl.h> |
|
94 #endif |
|
95 |
|
96 QT_END_INCLUDE_NAMESPACE |
|
97 #endif |
69 #endif |
98 |
70 |
99 QT_BEGIN_NAMESPACE |
71 QT_BEGIN_NAMESPACE |
100 |
72 |
101 class QGLContext; |
73 class QGLContext; |
154 redSize(other->redSize), |
130 redSize(other->redSize), |
155 greenSize(other->greenSize), |
131 greenSize(other->greenSize), |
156 blueSize(other->blueSize), |
132 blueSize(other->blueSize), |
157 alphaSize(other->alphaSize), |
133 alphaSize(other->alphaSize), |
158 numSamples(other->numSamples), |
134 numSamples(other->numSamples), |
159 swapInterval(other->swapInterval) |
135 swapInterval(other->swapInterval), |
|
136 majorVersion(other->majorVersion), |
|
137 minorVersion(other->minorVersion), |
|
138 profile(other->profile) |
160 { |
139 { |
161 } |
140 } |
162 QAtomicInt ref; |
141 QAtomicInt ref; |
163 QGL::FormatOptions opts; |
142 QGL::FormatOptions opts; |
164 int pln; |
143 int pln; |
210 #if defined(Q_WS_WIN) |
192 #if defined(Q_WS_WIN) |
211 void updateColormap(); |
193 void updateColormap(); |
212 QGLContext *olcx; |
194 QGLContext *olcx; |
213 #elif defined(Q_WS_X11) |
195 #elif defined(Q_WS_X11) |
214 QGLOverlayWidget *olw; |
196 QGLOverlayWidget *olw; |
215 #if defined(QT_OPENGL_ES) |
197 #ifndef QT_NO_EGL |
216 void recreateEglSurface(bool force); |
198 void recreateEglSurface(); |
217 WId eglSurfaceWindowId; |
199 WId eglSurfaceWindowId; |
218 #endif |
200 #endif |
219 #elif defined(Q_WS_MAC) |
201 #elif defined(Q_WS_MAC) |
220 QGLContext *olcx; |
202 QGLContext *olcx; |
221 void updatePaintDevice(); |
203 void updatePaintDevice(); |
294 FragmentShader = 0x00040000 |
276 FragmentShader = 0x00040000 |
295 }; |
277 }; |
296 Q_DECLARE_FLAGS(Extensions, Extension) |
278 Q_DECLARE_FLAGS(Extensions, Extension) |
297 |
279 |
298 static Extensions glExtensions(); |
280 static Extensions glExtensions(); |
299 |
|
300 private: |
|
301 static Extensions currentContextExtensions(); |
281 static Extensions currentContextExtensions(); |
302 }; |
282 }; |
303 |
283 |
304 /* |
284 /* |
305 QGLTemporaryContext - the main objective of this class is to have a way of |
285 QGLTemporaryContext - the main objective of this class is to have a way of |
350 |
330 |
351 void setVertexAttribArrayEnabled(int arrayIndex, bool enabled = true); |
331 void setVertexAttribArrayEnabled(int arrayIndex, bool enabled = true); |
352 void syncGlState(); // Makes sure the GL context's state is what we think it is |
332 void syncGlState(); // Makes sure the GL context's state is what we think it is |
353 |
333 |
354 #if defined(Q_WS_WIN) |
334 #if defined(Q_WS_WIN) |
|
335 void updateFormatVersion(); |
|
336 #endif |
|
337 |
|
338 #if defined(Q_WS_WIN) |
355 HGLRC rc; |
339 HGLRC rc; |
356 HDC dc; |
340 HDC dc; |
357 WId win; |
341 WId win; |
358 int pixelFormatId; |
342 int pixelFormatId; |
359 QGLCmap* cmap; |
343 QGLCmap* cmap; |
360 HBITMAP hbitmap; |
344 HBITMAP hbitmap; |
361 HDC hbitmap_hdc; |
345 HDC hbitmap_hdc; |
362 #endif |
346 #endif |
363 #if defined(QT_OPENGL_ES) |
347 #ifndef QT_NO_EGL |
|
348 uint ownsEglContext : 1; |
364 QEglContext *eglContext; |
349 QEglContext *eglContext; |
365 EGLSurface eglSurface; |
350 EGLSurface eglSurface; |
366 void destroyEglSurfaceForDevice(); |
351 void destroyEglSurfaceForDevice(); |
|
352 EGLSurface eglSurfaceForDevice() const; |
367 #elif defined(Q_WS_X11) || defined(Q_WS_MAC) |
353 #elif defined(Q_WS_X11) || defined(Q_WS_MAC) |
368 void* cx; |
354 void* cx; |
369 #endif |
355 #endif |
370 #if defined(Q_WS_X11) || defined(Q_WS_MAC) |
356 #if defined(Q_WS_X11) || defined(Q_WS_MAC) |
371 void* vi; |
357 void* vi; |
373 #if defined(Q_WS_X11) |
359 #if defined(Q_WS_X11) |
374 void* pbuf; |
360 void* pbuf; |
375 quint32 gpm; |
361 quint32 gpm; |
376 int screen; |
362 int screen; |
377 QHash<QPixmapData*, QPixmap> boundPixmaps; |
363 QHash<QPixmapData*, QPixmap> boundPixmaps; |
378 QGLTexture *bindTextureFromNativePixmap(QPixmapData*, const qint64 key, |
364 QGLTexture *bindTextureFromNativePixmap(QPixmap*, const qint64 key, |
379 QGLContext::BindOptions options); |
365 QGLContext::BindOptions options); |
380 static void destroyGlSurfaceForPixmap(QPixmapData*); |
366 static void destroyGlSurfaceForPixmap(QPixmapData*); |
381 static void unbindPixmapFromTexture(QPixmapData*); |
367 static void unbindPixmapFromTexture(QPixmapData*); |
382 #endif |
368 #endif |
383 #if defined(Q_WS_MAC) |
369 #if defined(Q_WS_MAC) |
394 uint initDone : 1; |
380 uint initDone : 1; |
395 uint crWin : 1; |
381 uint crWin : 1; |
396 uint internal_context : 1; |
382 uint internal_context : 1; |
397 uint version_flags_cached : 1; |
383 uint version_flags_cached : 1; |
398 uint extension_flags_cached : 1; |
384 uint extension_flags_cached : 1; |
|
385 |
|
386 // workarounds for driver/hw bugs on different platforms |
|
387 uint workaround_needsFullClearOnEveryFrame : 1; |
|
388 uint workaround_brokenFBOReadBack : 1; |
|
389 uint workaroundsCached : 1; |
|
390 |
399 QPaintDevice *paintDevice; |
391 QPaintDevice *paintDevice; |
400 QColor transpColor; |
392 QColor transpColor; |
401 QGLContext *q_ptr; |
393 QGLContext *q_ptr; |
402 QGLFormat::OpenGLVersionFlags version_flags; |
394 QGLFormat::OpenGLVersionFlags version_flags; |
403 QGLExtensions::Extensions extension_flags; |
395 QGLExtensions::Extensions extension_flags; |
534 public: |
526 public: |
535 QGLTextureCache(); |
527 QGLTextureCache(); |
536 ~QGLTextureCache(); |
528 ~QGLTextureCache(); |
537 |
529 |
538 void insert(QGLContext *ctx, qint64 key, QGLTexture *texture, int cost); |
530 void insert(QGLContext *ctx, qint64 key, QGLTexture *texture, int cost); |
539 void remove(quint64 key) { m_cache.remove(key); } |
531 inline void remove(quint64 key); |
|
532 inline int size(); |
|
533 inline void setMaxCost(int newMax); |
|
534 inline int maxCost(); |
|
535 inline QGLTexture* getTexture(quint64 key); |
|
536 |
540 bool remove(QGLContext *ctx, GLuint textureId); |
537 bool remove(QGLContext *ctx, GLuint textureId); |
541 void removeContextTextures(QGLContext *ctx); |
538 void removeContextTextures(QGLContext *ctx); |
542 int size() { return m_cache.size(); } |
|
543 void setMaxCost(int newMax) { m_cache.setMaxCost(newMax); } |
|
544 int maxCost() {return m_cache.maxCost(); } |
|
545 QGLTexture* getTexture(quint64 key) { return m_cache.object(key); } |
|
546 |
|
547 static QGLTextureCache *instance(); |
539 static QGLTextureCache *instance(); |
548 static void deleteIfEmpty(); |
|
549 static void cleanupTexturesForCacheKey(qint64 cacheKey); |
540 static void cleanupTexturesForCacheKey(qint64 cacheKey); |
550 static void cleanupTexturesForPixampData(QPixmapData* pixmap); |
541 static void cleanupTexturesForPixampData(QPixmapData* pixmap); |
551 static void cleanupBeforePixmapDestruction(QPixmapData* pixmap); |
542 static void cleanupBeforePixmapDestruction(QPixmapData* pixmap); |
552 |
543 |
553 private: |
544 private: |
554 QCache<qint64, QGLTexture> m_cache; |
545 QCache<qint64, QGLTexture> m_cache; |
555 }; |
546 QReadWriteLock m_lock; |
|
547 }; |
|
548 |
|
549 int QGLTextureCache::size() { |
|
550 QReadLocker locker(&m_lock); |
|
551 return m_cache.size(); |
|
552 } |
|
553 |
|
554 void QGLTextureCache::setMaxCost(int newMax) |
|
555 { |
|
556 QWriteLocker locker(&m_lock); |
|
557 m_cache.setMaxCost(newMax); |
|
558 } |
|
559 |
|
560 int QGLTextureCache::maxCost() |
|
561 { |
|
562 QReadLocker locker(&m_lock); |
|
563 return m_cache.maxCost(); |
|
564 } |
|
565 |
|
566 QGLTexture* QGLTextureCache::getTexture(quint64 key) |
|
567 { |
|
568 QReadLocker locker(&m_lock); |
|
569 return m_cache.object(key); |
|
570 } |
|
571 |
|
572 void QGLTextureCache::remove(quint64 key) |
|
573 { |
|
574 QWriteLocker locker(&m_lock); |
|
575 m_cache.remove(key); |
|
576 } |
556 |
577 |
557 |
578 |
558 extern Q_OPENGL_EXPORT QPaintEngine* qt_qgl_paint_engine(); |
579 extern Q_OPENGL_EXPORT QPaintEngine* qt_qgl_paint_engine(); |
559 |
580 |
560 bool qt_gl_preferGL2Engine(); |
581 bool qt_gl_preferGL2Engine(); |