From dc52950aa161aacf564b96abb8af6056dfa650cd Mon Sep 17 00:00:00 2001 From: Oleg Romashin Date: Wed, 23 Jun 2010 05:24:22 -0400 Subject: [PATCH] Bug 560537 - Make EGL provider use GL context created by Qt. r=bas.schouten. --HG-- extra : rebase_source : 45a0da770a8e8a89c4ca02c67469893cd4f9872a --- gfx/thebes/public/GLDefs.h | 2 + gfx/thebes/src/GLContextProviderEGL.cpp | 53 +++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/gfx/thebes/public/GLDefs.h b/gfx/thebes/public/GLDefs.h index e0fa9a468e00..35602f70993b 100644 --- a/gfx/thebes/public/GLDefs.h +++ b/gfx/thebes/public/GLDefs.h @@ -57,7 +57,9 @@ typedef unsigned char GLubyte; typedef unsigned short GLushort; typedef float GLfloat; typedef float GLclampf; +#ifndef GLdouble_defined typedef double GLdouble; +#endif typedef double GLclampd; typedef void GLvoid; diff --git a/gfx/thebes/src/GLContextProviderEGL.cpp b/gfx/thebes/src/GLContextProviderEGL.cpp index 47a35e4a3951..a95a7bddc464 100644 --- a/gfx/thebes/src/GLContextProviderEGL.cpp +++ b/gfx/thebes/src/GLContextProviderEGL.cpp @@ -47,6 +47,8 @@ #define GET_NATIVE_WINDOW(aWidget) (EGLNativeWindowType)GDK_WINDOW_XID((GdkWindow *) aWidget->GetNativeData(NS_NATIVE_WINDOW)) #elif defined(MOZ_WIDGET_QT) #include +#include +#define GLdouble_defined 1 // we're using default display for now #define GET_NATIVE_WINDOW(aWidget) (EGLNativeWindowType)static_cast(aWidget->GetNativeData(NS_NATIVE_SHELLWIDGET))->handle() #endif @@ -197,12 +199,21 @@ class GLContextEGL : public GLContext { public: GLContextEGL(EGLDisplay aDisplay, EGLConfig aConfig, - EGLSurface aSurface, EGLContext aContext) - : mDisplay(aDisplay), mConfig(aConfig), - mSurface(aSurface), mContext(aContext){} + EGLSurface aSurface, EGLContext aContext, + void *aGLWidget = nsnull) + : mDisplay(aDisplay), mConfig(aConfig) + , mSurface(aSurface), mContext(aContext) + , mGLWidget(aGLWidget) + {} ~GLContextEGL() { + // If mGLWidget is non-null, then we've been given it by the GL context provider, + // and it's managed by the widget implementation. In this case, We can't destroy + // our contexts. + if (mGLWidget) + return; + sEGLLibrary.fDestroyContext(mDisplay, mContext); sEGLLibrary.fDestroySurface(mDisplay, mSurface); } @@ -226,7 +237,15 @@ class GLContextEGL : public GLContext // where MakeCurrent with an already-current context is // still expensive. if (sEGLLibrary.fGetCurrentContext() != mContext) { - succeeded = sEGLLibrary.fMakeCurrent(mDisplay, mSurface, mSurface, mContext); + if (mGLWidget) { +#ifdef MOZ_WIDGET_QT + static_cast(mGLWidget)->makeCurrent(); +#else + succeeded = PR_FALSE; +#endif + } + else + succeeded = sEGLLibrary.fMakeCurrent(mDisplay, mSurface, mSurface, mContext); NS_ASSERTION(succeeded, "Failed to make GL context current!"); } @@ -258,6 +277,7 @@ class GLContextEGL : public GLContext EGLConfig mConfig; EGLSurface mSurface; EGLContext mContext; + void *mGLWidget; }; already_AddRefed @@ -267,6 +287,31 @@ GLContextProvider::CreateForWindow(nsIWidget *aWidget) return nsnull; } +#ifdef MOZ_WIDGET_QT + QWidget *viewport = static_cast(aWidget->GetNativeData(NS_NATIVE_SHELLWIDGET)); + if (!viewport) + return nsnull; + + if (viewport->paintEngine()->type() == QPaintEngine::OpenGL2) { + // Qt widget viewport already have GL context created by Qt + // Create dummy GLContextEGL class + nsRefPtr glContext = + new GLContextEGL(NULL, NULL, NULL, + sEGLLibrary.fGetCurrentContext(), + viewport); + if (!glContext->Init()) + return nsnull; + return glContext.forget().get(); + } else { + // All Qt nsIWidget's have the same X-Window surface + // And EGL not allowing to create multiple GL context for the same window + // we should be able to create GL context for QGV viewport once, and reuse it for all child widgets + NS_WARNING("Need special GLContext implementation for QT widgets structure"); + // Switch to software rendering here + return nsnull; + } +#endif + EGLDisplay display; EGLConfig config; EGLSurface surface;