Changeset 846 for trunk/src/opengl/qgl_p.h
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/src/opengl/qgl_p.h
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 65 65 #include "qglpaintdevice_p.h" 66 66 67 #ifndef QT_OPENGL_ES_1_CL 68 #define q_vertexType float 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 67 #ifndef QT_NO_EGL 68 #include <QtGui/private/qegl_p.h> 97 69 #endif 98 70 … … 115 87 # ifdef old_qDebug 116 88 # undef qDebug 117 # define qDebug QT_ QDEBUG_MACRO89 # define qDebug QT_NO_QDEBUG_MACRO 118 90 # undef old_qDebug 119 91 # endif … … 125 97 #endif 126 98 127 #if defined(QT_OPENGL_ES)99 #ifndef QT_NO_EGL 128 100 class QEglContext; 129 101 #endif … … 139 111 : ref(1) 140 112 { 141 opts = QGL::DoubleBuffer | QGL::DepthBuffer | QGL::Rgba | QGL::DirectRendering | QGL::StencilBuffer; 113 opts = QGL::DoubleBuffer | QGL::DepthBuffer | QGL::Rgba | QGL::DirectRendering 114 | QGL::StencilBuffer | QGL::DeprecatedFunctions; 142 115 pln = 0; 143 116 depthSize = accumSize = stencilSize = redSize = greenSize = blueSize = alphaSize = -1; 144 117 numSamples = -1; 145 118 swapInterval = -1; 119 majorVersion = 1; 120 minorVersion = 0; 121 profile = QGLFormat::NoProfile; 146 122 } 147 123 QGLFormatPrivate(const QGLFormatPrivate *other) … … 157 133 alphaSize(other->alphaSize), 158 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 } … … 172 151 int numSamples; 173 152 int swapInterval; 153 int majorVersion; 154 int minorVersion; 155 QGLFormat::OpenGLContextProfile profile; 174 156 }; 175 157 … … 183 165 , wsurf(0) 184 166 #endif 185 #if defined(Q_WS_X11) && defined(QT_OPENGL_ES) 167 #if defined(Q_WS_X11) && !defined(QT_NO_EGL) 168 , eglSurfaceWindowId(0) 169 #endif 170 #if defined(Q_OS_SYMBIAN) 186 171 , eglSurfaceWindowId(0) 187 172 #endif … … 196 181 bool renderCxPm(QPixmap *pixmap); 197 182 void cleanupColormaps(); 183 void aboutToDestroy() { 184 if (glcx) 185 glcx->reset(); 186 } 198 187 199 188 QGLContext *glcx; … … 213 202 #elif defined(Q_WS_X11) 214 203 QGLOverlayWidget *olw; 215 #if defined(QT_OPENGL_ES)216 void recreateEglSurface( bool force);204 #ifndef QT_NO_EGL 205 void recreateEglSurface(); 217 206 WId eglSurfaceWindowId; 218 207 #endif … … 223 212 QWSGLWindowSurface *wsurf; 224 213 #endif 214 #ifdef Q_OS_SYMBIAN 215 void recreateEglSurface(); 216 WId eglSurfaceWindowId; 217 #endif 225 218 }; 226 219 … … 249 242 static void removeShare(const QGLContext *context); 250 243 private: 251 QGLContextGroup(const QGLContext *context) : m_context(context), m_guards(0), m_refs(1) { }244 QGLContextGroup(const QGLContext *context); 252 245 253 246 QGLExtensionFuncs m_extensionFuncs; … … 292 285 ETC1TextureCompression = 0x00010000, 293 286 PVRTCTextureCompression = 0x00020000, 294 FragmentShader = 0x00040000 287 FragmentShader = 0x00040000, 288 ElementIndexUint = 0x00080000, 289 Depth24 = 0x00100000 295 290 }; 296 291 Q_DECLARE_FLAGS(Extensions, Extension) 297 292 298 293 static Extensions glExtensions(); 299 300 private:301 294 static Extensions currentContextExtensions(); 302 295 }; … … 325 318 326 319 class QGLTexture; 320 class QGLTextureDestroyer; 327 321 328 322 // This probably needs to grow to GL_MAX_VERTEX_ATTRIBS, but 3 is ok for now as that's … … 334 328 Q_DECLARE_PUBLIC(QGLContext) 335 329 public: 336 explicit QGLContextPrivate(QGLContext *context) : internal_context(false), q_ptr(context) {group = new QGLContextGroup(context);}330 explicit QGLContextPrivate(QGLContext *context); 337 331 ~QGLContextPrivate(); 338 332 QGLTexture *bindTexture(const QImage &image, GLenum target, GLint format, … … 351 345 void setVertexAttribArrayEnabled(int arrayIndex, bool enabled = true); 352 346 void syncGlState(); // Makes sure the GL context's state is what we think it is 347 void swapRegion(const QRegion ®ion); 348 349 #if defined(Q_WS_WIN) 350 void updateFormatVersion(); 351 #endif 353 352 354 353 #if defined(Q_WS_WIN) … … 361 360 HDC hbitmap_hdc; 362 361 #endif 363 #if defined(QT_OPENGL_ES) 362 #ifndef QT_NO_EGL 363 uint ownsEglContext : 1; 364 364 QEglContext *eglContext; 365 365 EGLSurface eglSurface; 366 366 void destroyEglSurfaceForDevice(); 367 EGLSurface eglSurfaceForDevice() const; 367 368 #elif defined(Q_WS_X11) || defined(Q_WS_MAC) 368 369 void* cx; … … 376 377 int screen; 377 378 QHash<QPixmapData*, QPixmap> boundPixmaps; 378 QGLTexture *bindTextureFromNativePixmap(QPixmap Data*, const qint64 key,379 QGLTexture *bindTextureFromNativePixmap(QPixmap*, const qint64 key, 379 380 QGLContext::BindOptions options); 380 381 static void destroyGlSurfaceForPixmap(QPixmapData*); … … 397 398 uint version_flags_cached : 1; 398 399 uint extension_flags_cached : 1; 400 401 // workarounds for driver/hw bugs on different platforms 402 uint workaround_needsFullClearOnEveryFrame : 1; 403 uint workaround_brokenFBOReadBack : 1; 404 uint workaround_brokenTexSubImage : 1; 405 uint workaroundsCached : 1; 406 407 uint workaround_brokenTextureFromPixmap : 1; 408 uint workaround_brokenTextureFromPixmap_init : 1; 409 399 410 QPaintDevice *paintDevice; 400 411 QColor transpColor; … … 409 420 GLuint default_fbo; 410 421 QPaintEngine *active_engine; 422 QGLTextureDestroyer *texture_destroyer; 411 423 412 424 bool vertexAttributeArraysEnabledState[QT_GL_VERTEX_ARRAY_TRACKED_COUNT]; … … 418 430 #endif 419 431 420 #if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS) 432 #if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN) 421 433 static QGLExtensionFuncs qt_extensionFuncs; 422 static inline QGLExtensionFuncs& extensionFuncs(const QGLContext *) { return qt_extensionFuncs; }434 static Q_OPENGL_EXPORT QGLExtensionFuncs& extensionFuncs(const QGLContext *); 423 435 #endif 424 436 425 437 static void setCurrentContext(QGLContext *context); 426 };427 428 // ### make QGLContext a QObject in 5.0 and remove the proxy stuff429 class Q_OPENGL_EXPORT QGLSignalProxy : public QObject430 {431 Q_OBJECT432 public:433 QGLSignalProxy() : QObject() {}434 void emitAboutToDestroyContext(const QGLContext *context) {435 emit aboutToDestroyContext(context);436 }437 static QGLSignalProxy *instance();438 Q_SIGNALS:439 void aboutToDestroyContext(const QGLContext *context);440 438 }; 441 439 … … 482 480 }; 483 481 482 class QGLTextureDestroyer : public QObject 483 { 484 Q_OBJECT 485 public: 486 QGLTextureDestroyer() : QObject() { 487 qRegisterMetaType<GLuint>("GLuint"); 488 connect(this, SIGNAL(freeTexture(QGLContext *, QPixmapData *, GLuint)), 489 this, SLOT(freeTexture_slot(QGLContext *, QPixmapData *, GLuint))); 490 } 491 void emitFreeTexture(QGLContext *context, QPixmapData *boundPixmap, GLuint id) { 492 emit freeTexture(context, boundPixmap, id); 493 } 494 495 Q_SIGNALS: 496 void freeTexture(QGLContext *context, QPixmapData *boundPixmap, GLuint id); 497 498 private slots: 499 void freeTexture_slot(QGLContext *context, QPixmapData *boundPixmap, GLuint id) { 500 #if defined(Q_WS_X11) 501 if (boundPixmap) { 502 QGLContext *oldContext = const_cast<QGLContext *>(QGLContext::currentContext()); 503 context->makeCurrent(); 504 // Although glXReleaseTexImage is a glX call, it must be called while there 505 // is a current context - the context the pixmap was bound to a texture in. 506 // Otherwise the release doesn't do anything and you get BadDrawable errors 507 // when you come to delete the context. 508 QGLContextPrivate::unbindPixmapFromTexture(boundPixmap); 509 glDeleteTextures(1, &id); 510 if (oldContext) 511 oldContext->makeCurrent(); 512 return; 513 } 514 #endif 515 QGLShareContextScope scope(context); 516 glDeleteTextures(1, &id); 517 } 518 }; 519 520 // ### make QGLContext a QObject in 5.0 and remove the proxy stuff 521 class Q_OPENGL_EXPORT QGLSignalProxy : public QObject 522 { 523 Q_OBJECT 524 public: 525 void emitAboutToDestroyContext(const QGLContext *context) { 526 emit aboutToDestroyContext(context); 527 } 528 static QGLSignalProxy *instance(); 529 Q_SIGNALS: 530 void aboutToDestroyContext(const QGLContext *context); 531 }; 532 484 533 class QGLTexture { 485 534 public: … … 498 547 if (options & QGLContext::MemoryManagedBindOption) { 499 548 Q_ASSERT(context); 500 QGLShareContextScope scope(context); 501 #if defined(Q_WS_X11) 502 // Although glXReleaseTexImage is a glX call, it must be called while there 503 // is a current context - the context the pixmap was bound to a texture in. 504 // Otherwise the release doesn't do anything and you get BadDrawable errors 505 // when you come to delete the context. 506 if (boundPixmap) 507 QGLContextPrivate::unbindPixmapFromTexture(boundPixmap); 508 #endif 509 glDeleteTextures(1, &id); 549 #if !defined(Q_WS_X11) 550 QPixmapData *boundPixmap = 0; 551 #endif 552 context->d_ptr->texture_destroyer->emitFreeTexture(context, boundPixmap, id); 510 553 } 511 554 } … … 531 574 }; 532 575 576 struct QGLTextureCacheKey { 577 qint64 key; 578 QGLContextGroup *group; 579 }; 580 581 inline bool operator==(const QGLTextureCacheKey &a, const QGLTextureCacheKey &b) 582 { 583 return a.key == b.key && a.group == b.group; 584 } 585 586 inline uint qHash(const QGLTextureCacheKey &key) 587 { 588 return qHash(key.key) ^ qHash(key.group); 589 } 590 591 533 592 class Q_AUTOTEST_EXPORT QGLTextureCache { 534 593 public: … … 537 596 538 597 void insert(QGLContext *ctx, qint64 key, QGLTexture *texture, int cost); 539 void remove(quint64 key) { m_cache.remove(key); } 598 void remove(qint64 key); 599 inline int size(); 600 inline void setMaxCost(int newMax); 601 inline int maxCost(); 602 inline QGLTexture* getTexture(QGLContext *ctx, qint64 key); 603 540 604 bool remove(QGLContext *ctx, GLuint textureId); 541 605 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 606 static QGLTextureCache *instance(); 548 static void deleteIfEmpty();549 607 static void cleanupTexturesForCacheKey(qint64 cacheKey); 550 608 static void cleanupTexturesForPixampData(QPixmapData* pixmap); … … 552 610 553 611 private: 554 QCache<qint64, QGLTexture> m_cache; 555 }; 556 612 QCache<QGLTextureCacheKey, QGLTexture> m_cache; 613 QReadWriteLock m_lock; 614 }; 615 616 int QGLTextureCache::size() { 617 QReadLocker locker(&m_lock); 618 return m_cache.size(); 619 } 620 621 void QGLTextureCache::setMaxCost(int newMax) 622 { 623 QWriteLocker locker(&m_lock); 624 m_cache.setMaxCost(newMax); 625 } 626 627 int QGLTextureCache::maxCost() 628 { 629 QReadLocker locker(&m_lock); 630 return m_cache.maxCost(); 631 } 632 633 QGLTexture* QGLTextureCache::getTexture(QGLContext *ctx, qint64 key) 634 { 635 QReadLocker locker(&m_lock); 636 const QGLTextureCacheKey cacheKey = {key, QGLContextPrivate::contextGroup(ctx)}; 637 return m_cache.object(cacheKey); 638 } 557 639 558 640 extern Q_OPENGL_EXPORT QPaintEngine* qt_qgl_paint_engine();
Note:
See TracChangeset
for help on using the changeset viewer.