]> git.cworth.org Git - apitrace/blobdiff - glretrace_egl.cpp
Add "apitrace trim" command.
[apitrace] / glretrace_egl.cpp
index 4e549a3446401111d6a65d7b94a838ed65683b8a..e4178e307e3dfa8bca267ab8aed36c55020a8c03 100644 (file)
@@ -46,10 +46,13 @@ using namespace glretrace;
 
 typedef std::map<unsigned long long, glws::Drawable *> DrawableMap;
 typedef std::map<unsigned long long, glws::Context *> ContextMap;
+typedef std::map<unsigned long long, glws::Profile> ProfileMap;
 static DrawableMap drawable_map;
 static ContextMap context_map;
+static ProfileMap profile_map;
 
 static unsigned int current_api = EGL_OPENGL_ES_API;
+static glws::Profile last_profile = glws::PROFILE_COMPAT;
 
 static glws::Drawable *
 getDrawable(unsigned long long surface_ptr) {
@@ -75,11 +78,37 @@ getContext(unsigned long long context_ptr) {
     return (it != context_map.end()) ? it->second : NULL;
 }
 
+static void createDrawable(unsigned long long orig_config, unsigned long long orig_surface)
+{
+    ProfileMap::iterator it = profile_map.find(orig_config);
+    glws::Profile profile;
+
+    // If the requested config is associated with a profile, use that
+    // profile. Otherwise, assume that the last used profile is what
+    // the user wants.
+    if (it != profile_map.end()) {
+        profile = it->second;
+    } else {
+        profile = last_profile;
+    }
+
+    glws::Visual *visual = glretrace::visual[profile];
+
+    glws::Drawable *drawable = glws::createDrawable(visual);
+    drawable_map[orig_surface] = drawable;
+}
+
 static void retrace_eglCreateWindowSurface(trace::Call &call) {
+    unsigned long long orig_config = call.arg(1).toUIntPtr();
     unsigned long long orig_surface = call.ret->toUIntPtr();
+    createDrawable(orig_config, orig_surface);
+}
 
-    glws::Drawable *drawable = glws::createDrawable(glretrace::visual);
-    drawable_map[orig_surface] = drawable;
+static void retrace_eglCreatePbufferSurface(trace::Call &call) {
+    unsigned long long orig_config = call.arg(1).toUIntPtr();
+    unsigned long long orig_surface = call.ret->toUIntPtr();
+    createDrawable(orig_config, orig_surface);
+    // TODO: Respect the pbuffer dimensions too
 }
 
 static void retrace_eglDestroySurface(trace::Call &call) {
@@ -89,7 +118,10 @@ static void retrace_eglDestroySurface(trace::Call &call) {
     it = drawable_map.find(orig_surface);
 
     if (it != drawable_map.end()) {
-        delete it->second;
+        if (it->second != drawable) {
+            // TODO: reference count
+            delete it->second;
+        }
         drawable_map.erase(it);
     }
 }
@@ -100,6 +132,7 @@ static void retrace_eglBindAPI(trace::Call &call) {
 
 static void retrace_eglCreateContext(trace::Call &call) {
     unsigned long long orig_context = call.ret->toUIntPtr();
+    unsigned long long orig_config = call.arg(1).toUIntPtr();
     glws::Context *share_context = getContext(call.arg(2).toUIntPtr());
     trace::Array *attrib_array = dynamic_cast<trace::Array *>(&call.arg(3));
     glws::Profile profile;
@@ -126,7 +159,7 @@ static void retrace_eglCreateContext(trace::Call &call) {
     }
 
 
-    glws::Context *context = glws::createContext(glretrace::visual, share_context, profile);
+    glws::Context *context = glws::createContext(glretrace::visual[profile], share_context, profile);
     if (!context) {
         const char *name;
         switch (profile) {
@@ -149,6 +182,8 @@ static void retrace_eglCreateContext(trace::Call &call) {
     }
 
     context_map[orig_context] = context;
+    profile_map[orig_config] = profile;
+    last_profile = profile;
 }
 
 static void retrace_eglDestroyContext(trace::Call &call) {
@@ -210,7 +245,7 @@ const retrace::Entry glretrace::egl_callbacks[] = {
     {"eglChooseConfig", &retrace::ignore},
     {"eglGetConfigAttrib", &retrace::ignore},
     {"eglCreateWindowSurface", &retrace_eglCreateWindowSurface},
-    //{"eglCreatePbufferSurface", &retrace::ignore},
+    {"eglCreatePbufferSurface", &retrace_eglCreatePbufferSurface},
     //{"eglCreatePixmapSurface", &retrace::ignore},
     {"eglDestroySurface", &retrace_eglDestroySurface},
     {"eglQuerySurface", &retrace::ignore},