]> git.cworth.org Git - apitrace/blobdiff - glws_egl_xlib.cpp
Move tracers to wrappers subdirectory.
[apitrace] / glws_egl_xlib.cpp
index da232bdd63ed79762676fb663476679af86f3b28..66557815017fda939a5edc4e622b84c7e0ee7459 100644 (file)
@@ -1,12 +1,9 @@
 /**************************************************************************
  *
  * Copyright 2011 LunarG, Inc.
+ * Copyright 2011 Jose Fonseca
  * All Rights Reserved.
  *
- * Based on glws_glx.cpp, which has
- *
- *   Copyright 2011 Jose Fonseca
- *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
  * in the Software without restriction, including without limitation the rights
 
 #include <iostream>
 
-#include "glws.hpp"
+#include <dlfcn.h>
 
 #include "glproc.hpp"
+#include "glws.hpp"
 
 
 namespace glws {
@@ -97,7 +95,7 @@ public:
     EglDrawable(const Visual *vis, int w, int h) :
         Drawable(vis, w, h), api(EGL_OPENGL_ES_API)
     {
-        XVisualInfo *visinfo = dynamic_cast<const EglVisual *>(visual)->visinfo;
+        XVisualInfo *visinfo = static_cast<const EglVisual *>(visual)->visinfo;
 
         Window root = RootWindow(display, screen);
 
@@ -138,8 +136,8 @@ public:
 
         eglWaitNative(EGL_CORE_NATIVE_ENGINE);
 
-        EGLConfig config = dynamic_cast<const EglVisual *>(visual)->config;
-        surface = eglCreateWindowSurface(eglDisplay, config, window, NULL);
+        EGLConfig config = static_cast<const EglVisual *>(visual)->config;
+        surface = eglCreateWindowSurface(eglDisplay, config, (EGLNativeWindowType)window, NULL);
     }
 
     void waitForEvent(int type) {
@@ -152,7 +150,9 @@ public:
 
     ~EglDrawable() {
         eglDestroySurface(eglDisplay, surface);
+        eglWaitClient();
         XDestroyWindow(display, window);
+        eglWaitNative(EGL_CORE_NATIVE_ENGINE);
     }
 
     void
@@ -212,8 +212,8 @@ class EglContext : public Context
 public:
     EGLContext context;
 
-    EglContext(const Visual *vis, EGLContext ctx) :
-        Context(vis),
+    EglContext(const Visual *vis, Profile prof, EGLContext ctx) :
+        Context(vis, prof),
         context(ctx)
     {}
 
@@ -222,8 +222,23 @@ public:
     }
 };
 
+/**
+ * Load the symbols from the specified shared object into global namespace, so
+ * that they can be later found by dlsym(RTLD_NEXT, ...);
+ */
+static void
+load(const char *filename)
+{
+    if (!dlopen(filename, RTLD_GLOBAL | RTLD_LAZY)) {
+        std::cerr << "error: unable to open " << filename << "\n";
+        exit(1);
+    }
+}
+
 void
 init(void) {
+    load("libEGL.so.1");
+
     display = XOpenDisplay(NULL);
     if (!display) {
         std::cerr << "error: unable to open display " << XDisplayName(NULL) << "\n";
@@ -232,7 +247,7 @@ init(void) {
 
     screen = DefaultScreen(display);
 
-    eglDisplay = eglGetDisplay(display);
+    eglDisplay = eglGetDisplay((EGLNativeDisplayType)display);
     if (eglDisplay == EGL_NO_DISPLAY) {
         std::cerr << "error: unable to get EGL display\n";
         XCloseDisplay(display);
@@ -257,17 +272,50 @@ cleanup(void) {
 }
 
 Visual *
-createVisual(bool doubleBuffer) {
+createVisual(bool doubleBuffer, Profile profile) {
     EglVisual *visual = new EglVisual();
     // possible combinations
-    const EGLint api_bits[7] = {
+    const EGLint api_bits_gl[7] = {
         EGL_OPENGL_BIT | EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT,
-        EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT,
         EGL_OPENGL_BIT | EGL_OPENGL_ES_BIT,
         EGL_OPENGL_BIT | EGL_OPENGL_ES2_BIT,
+        EGL_OPENGL_BIT,
+        EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT,
+        EGL_OPENGL_ES2_BIT,
+        EGL_OPENGL_ES_BIT,
+    };
+    const EGLint api_bits_gles1[7] = {
+        EGL_OPENGL_BIT | EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT,
+        EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT,
+        EGL_OPENGL_BIT | EGL_OPENGL_ES_BIT,
         EGL_OPENGL_ES_BIT,
+        EGL_OPENGL_BIT | EGL_OPENGL_ES2_BIT,
+        EGL_OPENGL_BIT,
+        EGL_OPENGL_ES2_BIT,
+    };
+    const EGLint api_bits_gles2[7] = {
+        EGL_OPENGL_BIT | EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT,
+        EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT,
+        EGL_OPENGL_BIT | EGL_OPENGL_ES2_BIT,
         EGL_OPENGL_ES2_BIT,
+        EGL_OPENGL_BIT | EGL_OPENGL_ES_BIT,
         EGL_OPENGL_BIT,
+        EGL_OPENGL_ES_BIT,
+    };
+    const EGLint *api_bits;
+
+    switch(profile) {
+    case PROFILE_COMPAT:
+        api_bits = api_bits_gl;
+        break;
+    case PROFILE_ES1:
+        api_bits = api_bits_gles1;
+        break;
+    case PROFILE_ES2:
+        api_bits = api_bits_gles2;
+        break;
+    default:
+        return NULL;
     };
 
     for (int i = 0; i < 7; i++) {
@@ -310,28 +358,36 @@ createDrawable(const Visual *visual, int width, int height)
 Context *
 createContext(const Visual *_visual, Context *shareContext, Profile profile)
 {
-    const EglVisual *visual = dynamic_cast<const EglVisual *>(_visual);
+    const EglVisual *visual = static_cast<const EglVisual *>(_visual);
     EGLContext share_context = EGL_NO_CONTEXT;
     EGLContext context;
     Attributes<EGLint> attribs;
 
     if (shareContext) {
-        share_context = dynamic_cast<EglContext*>(shareContext)->context;
+        share_context = static_cast<EglContext*>(shareContext)->context;
     }
 
     EGLint api = eglQueryAPI();
 
     switch (profile) {
     case PROFILE_COMPAT:
+        load("libGL.so.1");
         eglBindAPI(EGL_OPENGL_API);
         break;
+    case PROFILE_CORE:
+        assert(0);
+        return NULL;
     case PROFILE_ES1:
+        load("libGLESv1_CM.so.1");
         eglBindAPI(EGL_OPENGL_ES_API);
         break;
     case PROFILE_ES2:
+        load("libGLESv2.so.2");
         eglBindAPI(EGL_OPENGL_ES_API);
         attribs.add(EGL_CONTEXT_CLIENT_VERSION, 2);
         break;
+    default:
+        return NULL;
     }
 
     attribs.end(EGL_NONE);
@@ -342,7 +398,7 @@ createContext(const Visual *_visual, Context *shareContext, Profile profile)
 
     eglBindAPI(api);
 
-    return new EglContext(visual, context);
+    return new EglContext(visual, profile, context);
 }
 
 bool
@@ -351,8 +407,8 @@ makeCurrent(Drawable *drawable, Context *context)
     if (!drawable || !context) {
         return eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
     } else {
-        EglDrawable *eglDrawable = dynamic_cast<EglDrawable *>(drawable);
-        EglContext *eglContext = dynamic_cast<EglContext *>(context);
+        EglDrawable *eglDrawable = static_cast<EglDrawable *>(drawable);
+        EglContext *eglContext = static_cast<EglContext *>(context);
         EGLBoolean ok;
 
         ok = eglMakeCurrent(eglDisplay, eglDrawable->surface,