Skip to content

Commit

Permalink
Call init if current contex match context parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeshkova committed Apr 10, 2014
1 parent 5248ab8 commit 478aa1a
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 38 deletions.
4 changes: 2 additions & 2 deletions embedding/embedlite/EmbedLiteApp.cpp
Expand Up @@ -74,9 +74,9 @@ EmbedLiteApp::~EmbedLiteApp()
}

EmbedLiteRenderTarget*
EmbedLiteApp::CreateEmbedLiteRenderTarget()
EmbedLiteApp::CreateEmbedLiteRenderTarget(void* aContext, void* aSurface)
{
return new EmbedLiteRenderTarget(nullptr, nullptr);
return new EmbedLiteRenderTarget(aContext, aSurface);
}

void
Expand Down
2 changes: 1 addition & 1 deletion embedding/embedlite/EmbedLiteApp.h
Expand Up @@ -130,7 +130,7 @@ class EmbedLiteApp
virtual void RemoveObservers(nsTArray<nsCString>& observersList);

// Create wrapper for current active GL context, for proper GL sharing.
virtual EmbedLiteRenderTarget* CreateEmbedLiteRenderTarget();
virtual EmbedLiteRenderTarget* CreateEmbedLiteRenderTarget(void* aContext = nullptr, void* aSurface = nullptr);

// Only one EmbedHelper object allowed
static EmbedLiteApp* GetInstance();
Expand Down
2 changes: 1 addition & 1 deletion gfx/gl/GLContextEGL.h
Expand Up @@ -117,7 +117,7 @@ class GLContextEGL : public GLContext
#ifdef MOZ_WIDGET_GONK
nsRefPtr<HwcComposer2D> mHwc;
#endif
bool mIsOwnContext;
bool mOwnsContext;

static EGLSurface CreatePBufferSurfaceTryingPowerOfTwo(EGLConfig config,
EGLenum bindToTextureFormat,
Expand Down
2 changes: 1 addition & 1 deletion gfx/gl/GLContextGLX.h
Expand Up @@ -72,7 +72,7 @@ class GLContextGLX : public GLContext
GLXLibrary* mGLX;

nsRefPtr<gfxXlibSurface> mPixmap;
void* mIsOwnContext;
bool mOwnsContext;
};

}
Expand Down
15 changes: 8 additions & 7 deletions gfx/gl/GLContextProviderCGL.mm
Expand Up @@ -192,12 +192,16 @@ bool EnsureInitialized()
already_AddRefed<GLContext>
GLContextProviderCGL::CreateWrappingExisting(void* aContext, void* aSurface)
{
NSOpenGLContext *context = aContext ? aContext : [NSOpenGLContext currentContext];
if (!sCGLLibrary.EnsureInitialized()) {
return nullptr;
}

NSOpenGLContext* context = (NSOpenGLContext)aContext;
if (!context) {
return nullptr;
}

GLContextCGL *shareContext = GetGlobalContextCGL();
GLContextCGL* shareContext = GetGlobalContextCGL();

// make the context transparent
GLint opaque = 0;
Expand All @@ -207,7 +211,8 @@ bool EnsureInitialized()
nsRefPtr<GLContextCGL> glContext = new GLContextCGL(caps,
shareContext,
context);
if (!glContext->Init()) {

if ([NSOpenGLContext currentContext] == context && !glContext->Init()) {
return nullptr;
}

Expand All @@ -217,10 +222,6 @@ bool EnsureInitialized()
already_AddRefed<GLContext>
GLContextProviderCGL::CreateForWindow(nsIWidget *aWidget)
{
if (!sCGLLibrary.EnsureInitialized()) {
return nullptr;
}

GLContextCGL *shareContext = GetGlobalContextCGL();

NSOpenGLContext *context = [[NSOpenGLContext alloc]
Expand Down
22 changes: 13 additions & 9 deletions gfx/gl/GLContextProviderEGL.cpp
Expand Up @@ -234,7 +234,7 @@ GLContextEGL::GLContextEGL(
, mIsDoubleBuffered(false)
, mCanBindToTexture(false)
, mShareWithEGLImage(false)
, mIsOwnContext(true)
, mOwnsContext(true)
{
// any EGL contexts will always be GLESv2
SetProfileVersion(ContextProfile::OpenGLES, 200);
Expand Down Expand Up @@ -262,7 +262,7 @@ GLContextEGL::~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 (!mIsOwnContext)
if (!mOwnsContext)
return;

#ifdef DEBUG
Expand Down Expand Up @@ -429,7 +429,7 @@ GLContextEGL::RenewSurface() {

void
GLContextEGL::ReleaseSurface() {
if (mIsOwnContext) {
if (mOwnsContext) {
DestroySurface(mSurface);
}
mSurface = EGL_NO_SURFACE;
Expand All @@ -445,7 +445,7 @@ GLContextEGL::SetupLookupFunction()
bool
GLContextEGL::SwapBuffers()
{
if (mSurface && mIsOwnContext) {
if (mSurface && mOwnsContext) {
#ifdef MOZ_WIDGET_GONK
if (!mIsOffscreen) {
if (mHwc) {
Expand Down Expand Up @@ -691,18 +691,22 @@ GLContextProviderEGL::CreateWrappingExisting(void* aContext, void* aSurface)
return nullptr;
}

EGLContext eglContext = aContext ? (EGLContext)aContext : sEGLLibrary.fGetCurrentContext();
EGLSurface eglSurface = aSurface ? (EGLSurface)aSurface : sEGLLibrary.fGetCurrentSurface(LOCAL_EGL_DRAW);
if (eglContext && eglSurface) {
if (aContext && aSurface) {
SurfaceCaps caps = SurfaceCaps::Any();
EGLConfig config = EGL_NO_CONFIG;
nsRefPtr<GLContextEGL> glContext =
new GLContextEGL(caps,
nullptr, false,
config, eglSurface, eglContext);
config, (EGLSurface)aSurface, (EGLContext)aContext);

glContext->SetIsDoubleBuffered(true);
glContext->mIsOwnContext = false;
glContext->mOwnsContext = false;

if (sEGLLibrary.fGetCurrentContext() == aContext) {
if (!glContext->Init()) {
NS_WARNING("Failed to initialize wrapping EGL context");
}
}

return glContext.forget();
}
Expand Down
21 changes: 14 additions & 7 deletions gfx/gl/GLContextProviderGLX.cpp
Expand Up @@ -834,7 +834,7 @@ GLContextGLX::~GLContextGLX()
{
MarkDestroyed();

if (!mIsOwnContext)
if (!mOwnsContext)
return;

// see bug 659842 comment 76
Expand Down Expand Up @@ -916,7 +916,7 @@ GLContextGLX::SupportsRobustness() const
bool
GLContextGLX::SwapBuffers()
{
if (!mDoubleBuffered || !mIsOwnContext)
if (!mDoubleBuffered || !mOwnsContext)
return false;
mGLX->xSwapBuffers(mDisplay, mDrawable);
mGLX->xWaitGL();
Expand All @@ -941,7 +941,7 @@ GLContextGLX::GLContextGLX(
mDoubleBuffered(aDoubleBuffered),
mGLX(&sGLXLibrary),
mPixmap(aPixmap),
mIsOwnContext(true)
mOwnsContext(true)
{
MOZ_ASSERT(mGLX);
// See 899855
Expand Down Expand Up @@ -978,14 +978,14 @@ AreCompatibleVisuals(Visual *one, Visual *two)
static nsRefPtr<GLContext> gGlobalContext;

already_AddRefed<GLContext>
GLContextProviderGLX::CreateForEmbedded(void* aContext, void* aSurface)
GLContextProviderGLX::CreateWrappingExisting(void* aContext, void* aSurface)
{
if (!sGLXLibrary.EnsureInitialized()) {
return nullptr;
}

GLXContext glxContext = aContext ? (GLXContext)aContext : sGLXLibrary.xGetCurrentContext();
GLXDrawable glxDrawable = aSurface ? (GLXDrawable)aSurface : (GLXDrawable)sGLXLibrary.xGetCurrentDrawable();
GLXContext glxContext = (GLXContext)aContext;
GLXDrawable glxDrawable = (GLXDrawable)aSurface;
if (glxContext && glxDrawable) {
SurfaceCaps caps = SurfaceCaps::Any();
nsRefPtr<GLContextGLX> glContext =
Expand All @@ -998,9 +998,16 @@ GLContextProviderGLX::CreateForEmbedded(void* aContext, void* aSurface)
true,
(gfxXlibSurface*)nullptr);

glContext->mIsOwnContext = false;
glContext->mOwnsContext = false;
gGlobalContext = glContext;

if (sGLXLibrary.xGetCurrentContext() == aContext) {
if (!glContext->Init()) {
NS_WARNING("[GLX] Failed to initialize wrapping context");
return nullptr;
}
}

return glContext.forget();
}

Expand Down
17 changes: 7 additions & 10 deletions gfx/gl/GLContextProviderWGL.cpp
Expand Up @@ -413,23 +413,20 @@ GLContextProviderWGL::CreateWrappingExisting(void* aContext, void* aSurface)
* wglCreateContext will fail.
*/

HGLRC context = aContext ? (HGLRC)aContext : sWGLLib.fGetCurrentContext()
HDC dc = aSurface ? (HDC)aSurface : 0;

GLContextWGL *shareContext = GetGlobalContextWGL();


if (!context) {
if (!aContext) {
return nullptr;
}

GLContextWGL *shareContext = GetGlobalContextWGL();

SurfaceCaps caps = SurfaceCaps::ForRGBA();
nsRefPtr<GLContextWGL> glContext = new GLContextWGL(caps,
shareContext,
false,
dc,
context);
if (!glContext->Init()) {
(HDC)aSurface,
(HGLRC)aContext);

if (sWGLLib.fGetCurrentContext() == aContext && !glContext->Init()) {
return nullptr;
}

Expand Down

0 comments on commit 478aa1a

Please sign in to comment.