#include "deDynamicLibrary.hpp"
#include "deSTLUtil.hpp"
+#include "deSharedPtr.hpp"
#include <string>
#include <string>
class RenderContext : public GLRenderContext
{
public:
- RenderContext (const NativeDisplayFactory* displayFactory, const NativeWindowFactory* windowFactory, const NativePixmapFactory* pixmapFactory, const glu::RenderConfig& config);
+ RenderContext (const NativeDisplayFactory* displayFactory, const NativeWindowFactory* windowFactory, const NativePixmapFactory* pixmapFactory, const glu::RenderConfig& config, const glu::RenderContext* sharedContext = DE_NULL);
virtual ~RenderContext (void);
virtual glu::ContextType getType (void) const { return m_renderConfig.type; }
virtual void makeCurrent (void);
private:
- void create (const NativeDisplayFactory* displayFactory, const NativeWindowFactory* windowFactory, const NativePixmapFactory* pixmapFactory, const glu::RenderConfig& config);
+ void create (const NativeDisplayFactory* displayFactory, const NativeWindowFactory* windowFactory, const NativePixmapFactory* pixmapFactory, const glu::RenderConfig& config, const glu::RenderContext* sharedContext);
void destroy (void);
const glu::RenderConfig m_renderConfig;
const NativeWindowFactory* const m_nativeWindowFactory; // Stored in case window must be re-created
- NativeDisplay* m_display;
+ de::SharedPtr<NativeDisplay> m_display;
NativeWindow* m_window;
NativePixmap* m_pixmap;
EGLConfig m_eglConfig;
EGLSurface m_eglSurface;
EGLContext m_eglContext;
+ EGLContext m_eglSharedContext;
tcu::RenderTarget m_glRenderTarget;
de::DynamicLibrary* m_dynamicGLLibrary;
glw::Functions m_glFunctions;
};
-RenderContext::RenderContext (const NativeDisplayFactory* displayFactory, const NativeWindowFactory* windowFactory, const NativePixmapFactory* pixmapFactory, const glu::RenderConfig& config)
+RenderContext::RenderContext (const NativeDisplayFactory* displayFactory, const NativeWindowFactory* windowFactory, const NativePixmapFactory* pixmapFactory, const glu::RenderConfig& config, const glu::RenderContext* sharedContext)
: m_renderConfig (config)
, m_nativeWindowFactory (windowFactory)
, m_display (DE_NULL)
, m_eglDisplay (EGL_NO_DISPLAY)
, m_eglSurface (EGL_NO_SURFACE)
, m_eglContext (EGL_NO_CONTEXT)
+ , m_eglSharedContext (EGL_NO_CONTEXT)
, m_dynamicGLLibrary (DE_NULL)
{
try
{
- create(displayFactory, windowFactory, pixmapFactory, config);
+ create(displayFactory, windowFactory, pixmapFactory, config, sharedContext);
}
catch (...)
{
delete m_window;
delete m_pixmap;
- delete m_display;
delete m_dynamicGLLibrary;
}
return (glw::GenericFuncType)m_display->getLibrary().getProcAddress(name);
}
-void RenderContext::create (const NativeDisplayFactory* displayFactory, const NativeWindowFactory* windowFactory, const NativePixmapFactory* pixmapFactory, const glu::RenderConfig& config)
+void RenderContext::create (const NativeDisplayFactory* displayFactory, const NativeWindowFactory* windowFactory, const NativePixmapFactory* pixmapFactory, const glu::RenderConfig& config, const glu::RenderContext *sharedContext)
{
glu::RenderConfig::SurfaceType surfaceType = config.surfaceType;
DE_ASSERT(displayFactory);
- m_display = displayFactory->createDisplay();
- m_eglDisplay = eglu::getDisplay(*m_display);
+ if (DE_NULL == sharedContext)
+ m_display = de::SharedPtr<NativeDisplay>(displayFactory->createDisplay());
+ else
+ {
+ const RenderContext* context = dynamic_cast<const RenderContext*>(sharedContext);
+ m_eglSharedContext = context->m_eglContext;
+ m_display = context->m_display;
+ }
+ m_eglDisplay = eglu::getDisplay(*m_display);
const Library& egl = m_display->getLibrary();
{
{
if (windowFactory)
{
- const WindowSurfacePair windowSurface = createWindow(m_display, windowFactory, m_eglDisplay, m_eglConfig, config);
+ const WindowSurfacePair windowSurface = createWindow(m_display.get(), windowFactory, m_eglDisplay, m_eglConfig, config);
m_window = windowSurface.first;
m_eglSurface = windowSurface.second;
}
{
if (pixmapFactory)
{
- const PixmapSurfacePair pixmapSurface = createPixmap(m_display, pixmapFactory, m_eglDisplay, m_eglConfig, config);
+ const PixmapSurfacePair pixmapSurface = createPixmap(m_display.get(), pixmapFactory, m_eglDisplay, m_eglConfig, config);
m_pixmap = pixmapSurface.first;
m_eglSurface = pixmapSurface.second;
}
throw tcu::InternalError("Invalid surface type");
}
- m_eglContext = createGLContext(egl, m_eglDisplay, m_eglConfig, config.type, config.resetNotificationStrategy);
+ m_eglContext = createGLContext(egl, m_eglDisplay, m_eglConfig, config.type, m_eglSharedContext, config.resetNotificationStrategy);
EGLU_CHECK_CALL(egl, makeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext));
if (m_eglContext != EGL_NO_CONTEXT)
EGLU_CHECK_CALL(egl, destroyContext(m_eglDisplay, m_eglContext));
- EGLU_CHECK_CALL(egl, terminate(m_eglDisplay));
+ if (m_eglSharedContext == EGL_NO_CONTEXT)
+ EGLU_CHECK_CALL(egl, terminate(m_eglDisplay));
m_eglDisplay = EGL_NO_DISPLAY;
m_eglSurface = EGL_NO_SURFACE;
delete m_window;
delete m_pixmap;
- delete m_display;
delete m_dynamicGLLibrary;
m_window = DE_NULL;
m_pixmap = DE_NULL;
- m_display = DE_NULL;
m_dynamicGLLibrary = DE_NULL;
}
try
{
- WindowSurfacePair windowSurface = createWindow(m_display, m_nativeWindowFactory, m_eglDisplay, m_eglConfig, m_renderConfig);
+ WindowSurfacePair windowSurface = createWindow(m_display.get(), m_nativeWindowFactory, m_eglDisplay, m_eglConfig, m_renderConfig);
m_window = windowSurface.first;
m_eglSurface = windowSurface.second;
{
}
-glu::RenderContext* GLContextFactory::createContext (const glu::RenderConfig& config, const tcu::CommandLine& cmdLine) const
+glu::RenderContext* GLContextFactory::createContext (const glu::RenderConfig& config, const tcu::CommandLine& cmdLine, const glu::RenderContext *sharedContext) const
{
const NativeDisplayFactory& displayFactory = selectNativeDisplayFactory(m_displayFactoryRegistry, cmdLine);
pixmapFactory = DE_NULL;
}
- return new RenderContext(&displayFactory, windowFactory, pixmapFactory, config);
+ return new RenderContext(&displayFactory, windowFactory, pixmapFactory, config, sharedContext);
}
} // eglu