]> git.cworth.org Git - apitrace/blobdiff - glretrace_egl.cpp
Move tracers to wrappers subdirectory.
[apitrace] / glretrace_egl.cpp
index 7393ab174b604b47f55118f90874a96e0215f5d6..d7b14ecad6c5e7db5861b42083e1b6b5fd3be2d5 100644 (file)
@@ -54,6 +54,9 @@ static ProfileMap profile_map;
 static unsigned int current_api = EGL_OPENGL_ES_API;
 static glws::Profile last_profile = glws::PROFILE_COMPAT;
 
+static void
+createDrawable(unsigned long long orig_config, unsigned long long orig_surface);
+
 static glws::Drawable *
 getDrawable(unsigned long long surface_ptr) {
     if (surface_ptr == 0) {
@@ -62,6 +65,13 @@ getDrawable(unsigned long long surface_ptr) {
 
     DrawableMap::const_iterator it;
     it = drawable_map.find(surface_ptr);
+    if (it == drawable_map.end()) {
+        // In Fennec we get the egl window surface from Java which isn't
+        // traced, so just create a drawable if it doesn't exist in here
+        createDrawable(0, surface_ptr);
+        it = drawable_map.find(surface_ptr);
+        assert(it != drawable_map.end());
+    }
 
     return (it != drawable_map.end()) ? it->second : NULL;
 }
@@ -78,9 +88,8 @@ getContext(unsigned long long context_ptr) {
     return (it != context_map.end()) ? it->second : NULL;
 }
 
-static void retrace_eglCreateWindowSurface(trace::Call &call) {
-    unsigned long long orig_surface = call.ret->toUIntPtr();
-    unsigned long long orig_config = call.arg(1).toUIntPtr();
+static void createDrawable(unsigned long long orig_config, unsigned long long orig_surface)
+{
     ProfileMap::iterator it = profile_map.find(orig_config);
     glws::Profile profile;
 
@@ -93,10 +102,25 @@ static void retrace_eglCreateWindowSurface(trace::Call &call) {
         profile = last_profile;
     }
 
-    glws::Drawable *drawable = glws::createDrawable(glretrace::visual[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);
+}
+
+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) {
     unsigned long long orig_surface = call.arg(1).toUIntPtr();
 
@@ -104,7 +128,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);
     }
 }
@@ -211,7 +238,7 @@ static void retrace_eglMakeCurrent(trace::Call &call) {
 static void retrace_eglSwapBuffers(trace::Call &call) {
     frame_complete(call);
 
-    if (double_buffer) {
+    if (double_buffer && drawable) {
         drawable->swapBuffers();
     } else {
         glFlush();
@@ -228,7 +255,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},