summaryrefslogtreecommitdiffstatsci
path: root/src/glx.cpp
diff options
context:
space:
mode:
authorBryce Harrington <b.harrington@samsung.com>2013-11-27 16:41:29 -0800
committerBryce Harrington <b.harrington@samsung.com>2013-11-27 17:57:10 -0800
commit365615ba981fe42df9c7ae5d3e5f9b4afd3d3f0a (patch)
tree954e2762c40208ebc3c0129b13b58ead092582d2 /src/glx.cpp
parent0e456412a299c62b1a7468851cf2305b9702ccc4 (diff)
Generalize the GLX code and refactor for skia to reuse
Diffstat (limited to 'src/glx.cpp')
-rw-r--r--src/glx.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/glx.cpp b/src/glx.cpp
new file mode 100644
index 0000000..365c25f
--- /dev/null
+++ b/src/glx.cpp
@@ -0,0 +1,68 @@
+#include <err.h>
+#include <stdlib.h>
+
+#include "glx.h"
+
+bool
+createGLXContextAndWindow(glx_state_t *state, int width, int height)
+{
+ int rgba_attribs[] = {
+ GLX_RGBA,
+ GLX_RED_SIZE, 1,
+ GLX_GREEN_SIZE, 1,
+ GLX_BLUE_SIZE, 1,
+ GLX_ALPHA_SIZE, 1,
+ GLX_DOUBLEBUFFER,
+ None
+ };
+ XVisualInfo *visinfo;
+ XSetWindowAttributes xattr;
+
+ state->dpy = XOpenDisplay (NULL);
+ if (state->dpy == NULL) {
+ warnx ("Failed to open display: %s\n", XDisplayName (0));
+ return false;
+ }
+
+ visinfo = glXChooseVisual (state->dpy, DefaultScreen (state->dpy), rgba_attribs);
+ if (visinfo == NULL) {
+ warnx ("Failed to create RGBA and double-buffered visuals\n");
+ XCloseDisplay (state->dpy);
+ return NULL;
+ }
+
+ xattr.colormap = XCreateColormap (state->dpy,
+ RootWindow (state->dpy, visinfo->screen),
+ visinfo->visual, AllocNone);
+ xattr.border_pixel = 0;
+ state->window = XCreateWindow (state->dpy,
+ DefaultRootWindow (state->dpy),
+ 100, 50,
+ width, height, 0, visinfo->depth,
+ InputOutput, visinfo->visual,
+ CWBorderPixel | CWColormap,
+ &xattr);
+ XMapWindow (state->dpy, state->window);
+
+ state->glx_context = glXCreateContext (state->dpy, visinfo, NULL, True);
+ XFree (visinfo);
+
+ if (state->glx_context == NULL) {
+ warnx ("Could not create glx context\n");
+ XCloseDisplay (state->dpy);
+ return false;
+ }
+
+ return true;
+}
+
+void
+destroyGLXContextAndWindow (glx_state_t *state)
+{
+ if (state->dpy) {
+ glXDestroyContext (state->dpy, state->glx_context);
+
+ XDestroyWindow (state->dpy, state->window);
+ XCloseDisplay (state->dpy);
+ }
+}