Skip to content

Commit

Permalink
Bug 560537 - Make EGL provider use GL context created by Qt. r=bas.sc…
Browse files Browse the repository at this point in the history
…houten.

--HG--
extra : rebase_source : 45a0da770a8e8a89c4ca02c67469893cd4f9872a
  • Loading branch information
romaxa committed Jun 23, 2010
1 parent 9e9a380 commit dc52950
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
2 changes: 2 additions & 0 deletions gfx/thebes/public/GLDefs.h
Expand Up @@ -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;

Expand Down
53 changes: 49 additions & 4 deletions gfx/thebes/src/GLContextProviderEGL.cpp
Expand Up @@ -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 <QWidget>
#include <QtOpenGL/QGLWidget>
#define GLdouble_defined 1
// we're using default display for now
#define GET_NATIVE_WINDOW(aWidget) (EGLNativeWindowType)static_cast<QWidget*>(aWidget->GetNativeData(NS_NATIVE_SHELLWIDGET))->handle()
#endif
Expand Down Expand Up @@ -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);
}
Expand All @@ -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<QGLWidget*>(mGLWidget)->makeCurrent();
#else
succeeded = PR_FALSE;
#endif
}
else
succeeded = sEGLLibrary.fMakeCurrent(mDisplay, mSurface, mSurface, mContext);
NS_ASSERTION(succeeded, "Failed to make GL context current!");
}

Expand Down Expand Up @@ -258,6 +277,7 @@ class GLContextEGL : public GLContext
EGLConfig mConfig;
EGLSurface mSurface;
EGLContext mContext;
void *mGLWidget;
};

already_AddRefed<GLContext>
Expand All @@ -267,6 +287,31 @@ GLContextProvider::CreateForWindow(nsIWidget *aWidget)
return nsnull;
}

#ifdef MOZ_WIDGET_QT
QWidget *viewport = static_cast<QWidget*>(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<GLContextEGL> 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;
Expand Down

0 comments on commit dc52950

Please sign in to comment.