already_AddRefed<GLContext> GLContextProviderWGL::CreateOffscreen(const gfxIntSize& size, const SurfaceCaps& caps) { if (!sWGLLib.EnsureInitialized()) { return nullptr; } nsRefPtr<GLContextWGL> glContext; // Always try to create a pbuffer context first, because we // want the context isolation. if (sWGLLib.fCreatePbuffer && sWGLLib.fChoosePixelFormat) { gfxIntSize dummySize = gfxIntSize(16, 16); glContext = CreatePBufferOffscreenContext(dummySize, GetGlobalContextWGL()); } // If it failed, then create a window context and use a FBO. if (!glContext) { glContext = CreateWindowOffscreenContext(); } if (!glContext || !glContext->Init()) { return nullptr; } if (!glContext->InitOffscreen(ToIntSize(size), caps)) return nullptr; return glContext.forget(); }
already_AddRefed<GLContext> GLContextProviderWGL::CreateForWindow(nsIWidget *aWidget) { if (!sWGLLib.EnsureInitialized()) { return nullptr; } /** * We need to make sure we call SetPixelFormat -after- calling * EnsureInitialized, otherwise it can load/unload the dll and * wglCreateContext will fail. */ HDC dc = (HDC)aWidget->GetNativeData(NS_NATIVE_GRAPHIC); SetPixelFormat(dc, sWGLLib.GetWindowPixelFormat(), nullptr); HGLRC context; GLContextWGL *shareContext = GetGlobalContextWGL(); if (sWGLLib.HasRobustness()) { int attribs[] = { LOCAL_WGL_CONTEXT_FLAGS_ARB, LOCAL_WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB, LOCAL_WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, LOCAL_WGL_LOSE_CONTEXT_ON_RESET_ARB, 0 }; context = sWGLLib.fCreateContextAttribs(dc, shareContext ? shareContext->Context() : nullptr, attribs); } else { context = sWGLLib.fCreateContext(dc); if (context && shareContext && !sWGLLib.fShareLists(shareContext->Context(), context)) { printf_stderr("WGL context creation failed for window: wglShareLists returned false!"); sWGLLib.fDeleteContext(context); context = nullptr; } } if (!context) { return nullptr; } SurfaceCaps caps = SurfaceCaps::ForRGBA(); nsRefPtr<GLContextWGL> glContext = new GLContextWGL(caps, shareContext, false, dc, context); if (!glContext->Init()) { return nullptr; } glContext->SetIsDoubleBuffered(true); return glContext.forget(); }
static already_AddRefed<GLContextWGL> CreateWindowOffscreenContext(const gfxIntSize& aSize, const ContextFormat& aFormat) { // CreateWindowOffscreenContext must return a global-shared context GLContextWGL *shareContext = GetGlobalContextWGL(); if (!shareContext) { return nsnull; } HDC dc; HWND win = CreateDummyWindow(&dc); if (!win) { return nsnull; } HGLRC context = sWGLLibrary.fCreateContext(dc); if (!context) { return nsnull; } if (!sWGLLibrary.fShareLists(shareContext->Context(), context)) { NS_WARNING("wglShareLists failed!"); sWGLLibrary.fDeleteContext(context); DestroyWindow(win); return nsnull; } nsRefPtr<GLContextWGL> glContext = new GLContextWGL(aFormat, shareContext, dc, context, win, PR_TRUE); return glContext.forget(); }
static already_AddRefed<GLContextWGL> CreateWindowOffscreenContext(GLContext::ContextFlags aFlags) { // CreateWindowOffscreenContext must return a global-shared context GLContextWGL *shareContext = GetGlobalContextWGL(aFlags); if (!shareContext) { return nullptr; } LibType libToUse = WGLLibrary::SelectLibrary(aFlags); HDC dc; HWND win = sWGLLib[libToUse].CreateDummyWindow(&dc); if (!win) { return nullptr; } HGLRC context = sWGLLib[libToUse].fCreateContext(dc); if (sWGLLib[libToUse].HasRobustness()) { int attribs[] = { LOCAL_WGL_CONTEXT_FLAGS_ARB, LOCAL_WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB, LOCAL_WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, LOCAL_WGL_LOSE_CONTEXT_ON_RESET_ARB, 0 }; context = sWGLLib[libToUse].fCreateContextAttribs(dc, shareContext->Context(), attribs); } else { context = sWGLLib[libToUse].fCreateContext(dc); if (context && shareContext && !sWGLLib[libToUse].fShareLists(shareContext->Context(), context)) { NS_WARNING("wglShareLists failed!"); sWGLLib[libToUse].fDeleteContext(context); DestroyWindow(win); return nullptr; } } if (!context) { return nullptr; } SurfaceCaps caps = SurfaceCaps::ForRGBA(); nsRefPtr<GLContextWGL> glContext = new GLContextWGL(caps, shareContext, true, dc, context, libToUse, win); return glContext.forget(); }
static already_AddRefed<GLContextWGL> CreateWindowOffscreenContext(const ContextFormat& aFormat) { // CreateWindowOffscreenContext must return a global-shared context GLContextWGL *shareContext = GetGlobalContextWGL(); if (!shareContext) { return nsnull; } HDC dc; HWND win = CreateDummyWindow(&dc); if (!win) { return nsnull; } HGLRC context = sWGLLibrary.fCreateContext(dc); if (sWGLLibrary.HasRobustness()) { int attribs[] = { LOCAL_WGL_CONTEXT_FLAGS_ARB, LOCAL_WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB, LOCAL_WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, LOCAL_WGL_LOSE_CONTEXT_ON_RESET_ARB, NULL }; context = sWGLLibrary.fCreateContextAttribs(dc, shareContext->Context(), attribs); } else { context = sWGLLibrary.fCreateContext(dc); if (context && shareContext && !sWGLLibrary.fShareLists(shareContext->Context(), context)) { NS_WARNING("wglShareLists failed!"); sWGLLibrary.fDeleteContext(context); DestroyWindow(win); return nsnull; } } if (!context) { return nsnull; } nsRefPtr<GLContextWGL> glContext = new GLContextWGL(aFormat, shareContext, dc, context, win, true); return glContext.forget(); }
already_AddRefed<GLContext> GLContextProviderWGL::CreateForWindow(nsIWidget *aWidget) { if (!sWGLLibrary.EnsureInitialized()) { return nsnull; } /** * We need to make sure we call SetPixelFormat -after- calling * EnsureInitialized, otherwise it can load/unload the dll and * wglCreateContext will fail. */ HDC dc = (HDC)aWidget->GetNativeData(NS_NATIVE_GRAPHIC); SetPixelFormat(dc, gSharedWindowPixelFormat, NULL); HGLRC context = sWGLLibrary.fCreateContext(dc); if (!context) { return nsnull; } GLContextWGL *shareContext = GetGlobalContextWGL(); if (shareContext && !sWGLLibrary.fShareLists(shareContext->Context(), context)) { shareContext = nsnull; } nsRefPtr<GLContextWGL> glContext = new GLContextWGL(ContextFormat(ContextFormat::BasicRGB24), shareContext, dc, context); if (!glContext->Init()) { return nsnull; } return glContext.forget(); }
already_AddRefed<GLContext> GLContextProviderWGL::CreateForWindow(nsIWidget *aWidget) { if (!sWGLLibrary.EnsureInitialized()) { return nsnull; } /** * We need to make sure we call SetPixelFormat -after- calling * EnsureInitialized, otherwise it can load/unload the dll and * wglCreateContext will fail. */ HDC dc = (HDC)aWidget->GetNativeData(NS_NATIVE_GRAPHIC); SetPixelFormat(dc, gSharedWindowPixelFormat, NULL); HGLRC context; GLContextWGL *shareContext = GetGlobalContextWGL(); if (sWGLLibrary.HasRobustness()) { int attribs[] = { LOCAL_WGL_CONTEXT_FLAGS_ARB, LOCAL_WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB, LOCAL_WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, LOCAL_WGL_LOSE_CONTEXT_ON_RESET_ARB, NULL }; context = sWGLLibrary.fCreateContextAttribs(dc, shareContext ? shareContext->Context() : nsnull, attribs); if (!context && shareContext) { context = sWGLLibrary.fCreateContextAttribs(dc, nsnull, attribs); if (context) { shareContext = nsnull; } } else { context = sWGLLibrary.fCreateContext(dc); if (context && shareContext && !sWGLLibrary.fShareLists(shareContext->Context(), context)) { shareContext = nsnull; } } } else { context = sWGLLibrary.fCreateContext(dc); if (context && shareContext && !sWGLLibrary.fShareLists(shareContext->Context(), context)) { shareContext = nsnull; } } if (!context) { return nsnull; } nsRefPtr<GLContextWGL> glContext = new GLContextWGL(ContextFormat(ContextFormat::BasicRGB24), shareContext, dc, context); if (!glContext->Init()) { return nsnull; } glContext->SetIsDoubleBuffered(gUseDoubleBufferedWindows); return glContext.forget(); }