From bd38e9e98f97f8389aba2aad58da1bbe7f5c90ff Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Tue, 24 Dec 2019 21:31:08 +0100 Subject: [PATCH] Adding source/Platform/Unix/X11SharedDisplay.cpp --- engine.build.lua | 1 + source/Platform/Unix/X11SharedDisplay.cpp | 32 +++++++++++++++++++++++ source/Platform/Unix/X11SharedDisplay.h | 15 +++++++++++ 3 files changed, 48 insertions(+) create mode 100644 source/Platform/Unix/X11SharedDisplay.cpp create mode 100644 source/Platform/Unix/X11SharedDisplay.h diff --git a/engine.build.lua b/engine.build.lua index 24c1821..55ff80f 100644 --- a/engine.build.lua +++ b/engine.build.lua @@ -65,6 +65,7 @@ if TARGET_OS == "Win32" then elseif TARGET_OS == "Unix" then platform_spec_module = Module("source/Platform/Unix", { "UnixApplication.cpp", + "X11SharedDisplay.cpp", "X11Display.cpp", "GLXContext.cpp", "X11Input.cpp", diff --git a/source/Platform/Unix/X11SharedDisplay.cpp b/source/Platform/Unix/X11SharedDisplay.cpp new file mode 100644 index 0000000..bb76064 --- /dev/null +++ b/source/Platform/Unix/X11SharedDisplay.cpp @@ -0,0 +1,32 @@ + +#include "X11SharedDisplay.h" + +namespace sp { + +// Define a global display (for simplicity, we always connect to local one.) +::Display* sharedDisplay = NULL; +unsigned int refcount = 0; + +::Display* XGetDisplay() { + + // Create if we dont have any references. + if (refcount == 0) { + sharedDisplay = XOpenDisplay(NULL); + } + + refcount++; + return sharedDisplay; +} + +void XReleaseDisplay() { + + if (refcount < 1) { + return; + } + + if (--refcount == 0) { + XCloseDisplay(sharedDisplay); + } +} + +} // namespace sp diff --git a/source/Platform/Unix/X11SharedDisplay.h b/source/Platform/Unix/X11SharedDisplay.h new file mode 100644 index 0000000..91de116 --- /dev/null +++ b/source/Platform/Unix/X11SharedDisplay.h @@ -0,0 +1,15 @@ + +#ifndef SPECTRE_PLATFORM_UNIX_X11SHAREDDISPLAY_H +#define SPECTRE_PLATFORM_UNIX_X11SHAREDDISPLAY_H + +#include + +namespace sp { + +::Display* XGetDisplay(); + +void XReleaseDisplay(); + +} // namespace sp + +#endif /* SPECTRE_PLATFORM_UNIX_X11SHAREDDISPLAY_H */