Only open an X11 display when not provided by the application through eglGetDisplay().
diff --git a/src/Common/Version.h b/src/Common/Version.h
index bde1d05..229944b 100644
--- a/src/Common/Version.h
+++ b/src/Common/Version.h
@@ -1,7 +1,7 @@
#define MAJOR_VERSION 3
#define MINOR_VERSION 2
#define BUILD_VERSION 6
-#define BUILD_REVISION 47125
+#define BUILD_REVISION 47297
#define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x)
diff --git a/src/GLES2/libEGL/Surface.cpp b/src/GLES2/libEGL/Surface.cpp
index 1252471..678df3a 100644
--- a/src/GLES2/libEGL/Surface.cpp
+++ b/src/GLES2/libEGL/Surface.cpp
@@ -144,7 +144,7 @@
if(mWindow)
{
- frameBuffer = gl::createFrameBuffer(mWindow, backBufferWidth, backBufferHeight);
+ frameBuffer = gl::createFrameBuffer(mDisplay->getNativeDisplay(), mWindow, backBufferWidth, backBufferHeight);
if(!frameBuffer)
{
diff --git a/src/GLES2/libEGL/main.cpp b/src/GLES2/libEGL/main.cpp
index 7ddac11..854d02a 100644
--- a/src/GLES2/libEGL/main.cpp
+++ b/src/GLES2/libEGL/main.cpp
@@ -95,7 +95,7 @@
gl::getCurrentContext = (gl::Context *(*)())getProcAddress(libGLESv2, "glGetCurrentContext");
gl::getProcAddress = (__eglMustCastToProperFunctionPointerType (*)(const char*))getProcAddress(libGLESv2, "glGetProcAddress");
gl::createBackBuffer = (gl::Image *(*)(int, int, const egl::Config*))getProcAddress(libGLESv2, "createBackBuffer");
- gl::createFrameBuffer = (sw::FrameBuffer *(*)(EGLNativeWindowType, int, int))getProcAddress(libGLESv2, "createFrameBuffer");
+ gl::createFrameBuffer = (sw::FrameBuffer *(*)(EGLNativeDisplayType, EGLNativeWindowType, int, int))getProcAddress(libGLESv2, "createFrameBuffer");
return libGLESv2 != 0;
}
@@ -255,7 +255,7 @@
Context *(*getCurrentContext)() = 0;
__eglMustCastToProperFunctionPointerType (*getProcAddress)(const char *procname) = 0;
Image *(*createBackBuffer)(int width, int height, const egl::Config *config) = 0;
- sw::FrameBuffer *(*createFrameBuffer)(EGLNativeWindowType window, int width, int height) = 0;
+ sw::FrameBuffer *(*createFrameBuffer)(EGLNativeDisplayType display, EGLNativeWindowType window, int width, int height) = 0;
}
void *libGLESv2 = 0; // Handle to the libGLESv2 module
diff --git a/src/GLES2/libEGL/main.h b/src/GLES2/libEGL/main.h
index b8995db..2af202d 100644
--- a/src/GLES2/libEGL/main.h
+++ b/src/GLES2/libEGL/main.h
@@ -90,7 +90,7 @@
extern Context *(*getCurrentContext)();
extern __eglMustCastToProperFunctionPointerType (*getProcAddress)(const char *procname);
extern Image *(*createBackBuffer)(int width, int height, const egl::Config *config);
- extern sw::FrameBuffer *(*createFrameBuffer)(EGLNativeWindowType window, int width, int height);
+ extern sw::FrameBuffer *(*createFrameBuffer)(EGLNativeDisplayType display, EGLNativeWindowType window, int width, int height);
}
extern void *libGLESv2; // Handle to the libGLESv2 module
diff --git a/src/Main/FrameBuffer.cpp b/src/Main/FrameBuffer.cpp
index 854ab86..0534198 100644
--- a/src/Main/FrameBuffer.cpp
+++ b/src/Main/FrameBuffer.cpp
@@ -17,7 +17,6 @@
#include "Register.hpp"
#include "Renderer/Surface.hpp"
#include "Reactor/Reactor.hpp"
-#include "Common/Configurator.hpp"
#include "Common/Debug.hpp"
#include <stdio.h>
@@ -515,43 +514,4 @@
}
#endif
}
-}
-
-#if defined(_WIN32)
- #include "FrameBufferDD.hpp"
- #include "FrameBufferGDI.hpp"
-#else
- #include "FrameBufferX11.hpp"
-#endif
-
-extern "C"
-{
-#if defined(_WIN32)
- sw::FrameBuffer *createFrameBuffer(HWND window, int width, int height)
- {
- return createFrameBufferWin(window, width, height, false, false);
- }
-
- sw::FrameBufferWin *createFrameBufferWin(HWND windowHandle, int width, int height, bool fullscreen, bool topLeftOrigin)
- {
- sw::Configurator ini("SwiftShader.ini");
- int api = ini.getInteger("Testing", "FrameBufferAPI", 0);
-
- if(api == 0 && topLeftOrigin)
- {
- return new sw::FrameBufferDD(windowHandle, width, height, fullscreen, topLeftOrigin);
- }
- else
- {
- return new sw::FrameBufferGDI(windowHandle, width, height, fullscreen, topLeftOrigin);
- }
-
- return 0;
- }
-#else
- sw::FrameBuffer *createFrameBuffer(Window window, int width, int height)
- {
- return new sw::FrameBufferX11(window, width, height);
- }
-#endif
-}
+}
\ No newline at end of file
diff --git a/src/Main/FrameBuffer.hpp b/src/Main/FrameBuffer.hpp
index 18e123a..552e432 100644
--- a/src/Main/FrameBuffer.hpp
+++ b/src/Main/FrameBuffer.hpp
@@ -100,18 +100,6 @@
static bool topLeftOrigin;
};
-
- class FrameBufferWin;
-}
-
-extern "C"
-{
- #if defined(_WIN32)
- sw::FrameBuffer *createFrameBuffer(HWND windowHandle, int width, int height);
- sw::FrameBufferWin *createFrameBufferWin(HWND windowHandle, int width, int height, bool fullscreen, bool topLeftOrigin);
- #else
- sw::FrameBuffer *createFrameBuffer(unsigned long window, int width, int height);
- #endif
}
#endif // sw_FrameBuffer_hpp
diff --git a/src/Main/FrameBufferWin.cpp b/src/Main/FrameBufferWin.cpp
index 53cda59..19ffb68 100644
--- a/src/Main/FrameBufferWin.cpp
+++ b/src/Main/FrameBufferWin.cpp
@@ -47,3 +47,32 @@
}
}
}
+
+#include "FrameBufferDD.hpp"
+#include "FrameBufferGDI.hpp"
+#include "Common/Configurator.hpp"
+
+extern "C"
+{
+ sw::FrameBufferWin *createFrameBufferWin(HWND windowHandle, int width, int height, bool fullscreen, bool topLeftOrigin)
+ {
+ sw::Configurator ini("SwiftShader.ini");
+ int api = ini.getInteger("Testing", "FrameBufferAPI", 0);
+
+ if(api == 0 && topLeftOrigin)
+ {
+ return new sw::FrameBufferDD(windowHandle, width, height, fullscreen, topLeftOrigin);
+ }
+ else
+ {
+ return new sw::FrameBufferGDI(windowHandle, width, height, fullscreen, topLeftOrigin);
+ }
+
+ return 0;
+ }
+
+ sw::FrameBuffer *createFrameBuffer(HDC display, HWND window, int width, int height)
+ {
+ return createFrameBufferWin(window, width, height, false, false);
+ }
+}
diff --git a/src/Main/FrameBufferWin.hpp b/src/Main/FrameBufferWin.hpp
index 8199d00..40eefac 100644
--- a/src/Main/FrameBufferWin.hpp
+++ b/src/Main/FrameBufferWin.hpp
@@ -54,4 +54,9 @@
};
}
+extern "C"
+{
+ sw::FrameBufferWin *createFrameBufferWin(HWND windowHandle, int width, int height, bool fullscreen, bool topLeftOrigin);
+}
+
#endif // sw_FrameBufferWin_hpp
diff --git a/src/Main/FrameBufferX11.cpp b/src/Main/FrameBufferX11.cpp
index 5d7c469..2b01be8 100644
--- a/src/Main/FrameBufferX11.cpp
+++ b/src/Main/FrameBufferX11.cpp
@@ -38,9 +38,13 @@
}
}
- FrameBufferX11::FrameBufferX11(Window window, int width, int height) : FrameBuffer(width, height, false, false), x_window(window)
+ FrameBufferX11::FrameBufferX11(Display *display, Window window, int width, int height) : FrameBuffer(width, height, false, false), x_window(window), x_display(display), ownX11(!display)
{
- x_display = XOpenDisplay(0);
+ if(!x_display)
+ {
+ x_display = XOpenDisplay(0);
+ }
+
int screen = DefaultScreen(x_display);
x_gc = XDefaultGC(x_display, screen);
Visual *x_visual = XDefaultVisual(x_display, screen);
@@ -98,7 +102,10 @@
shmctl(shminfo.shmid, IPC_RMID, 0);
}
- XCloseDisplay(x_display);
+ if(ownX11)
+ {
+ XCloseDisplay(x_display);
+ }
}
void *FrameBufferX11::lock()
@@ -130,3 +137,11 @@
XSync(x_display, False);
}
}
+
+extern "C"
+{
+ sw::FrameBuffer *createFrameBuffer(void *display, Window window, int width, int height)
+ {
+ return new sw::FrameBufferX11((Display*)display, window, width, height);
+ }
+}
diff --git a/src/Main/FrameBufferX11.hpp b/src/Main/FrameBufferX11.hpp
index 2e0f3c6..8847492 100644
--- a/src/Main/FrameBufferX11.hpp
+++ b/src/Main/FrameBufferX11.hpp
@@ -28,7 +28,7 @@
class FrameBufferX11 : public FrameBuffer
{
public:
- FrameBufferX11(Window window, int width, int height);
+ FrameBufferX11(Display *display, Window window, int width, int height);
~FrameBufferX11();
@@ -38,7 +38,8 @@
virtual void *lock();
virtual void unlock();
- private:
+ private:
+ bool ownX11;
Display *x_display;
Window x_window;
XImage *x_image;