[PATCH] glretrace: Eliminate busy-waiting on "glretrace -w"

José Fonseca jose.r.fonseca at gmail.com
Thu Sep 6 08:15:23 PDT 2012


Carl,

Could you please update so that hitting Escape at any point (waiting
or not) terminates the trace? This meets your goals and also matches
how glretrace behaves on windows, without interface changes.

Jose

On Wed, Sep 5, 2012 at 8:29 PM, Carl Worth <cworth at cworth.org> wrote:
> Previously, if the user passed the "-w" option to beable to see the
> last frame of the retrace, the glretrace would enter an infinite
> busy-waiting loop, consuming as much CPU as possible. The only way to
> halt it was to interrupt the process.
>
> Fix this by implementing the retrace::waitForInput() function via a
> new glws::Drawable::waitForInput method. This method is currently
> implemented only on glws_glx where it correctly waits for a key-press
> event. On all other targets this method will simply return immediately
> for now.
> ---
>
> This is a better implementation than the previous patch. It avoids the
> arbitrary polling interval by instead adding a new glws method to wait
> for keyboard input.
>
>  retrace/glretrace.hpp      |    1 +
>  retrace/glretrace_main.cpp |    5 ++++-
>  retrace/glretrace_ws.cpp   |    3 ++-
>  retrace/glws.hpp           |    6 ++++++
>  retrace/glws_glx.cpp       |   15 +++++++++++++--
>  5 files changed, 26 insertions(+), 4 deletions(-)
>
> diff --git a/retrace/glretrace.hpp b/retrace/glretrace.hpp
> index 10991a4..8c7a268 100644
> --- a/retrace/glretrace.hpp
> +++ b/retrace/glretrace.hpp
> @@ -55,6 +55,7 @@ extern bool insideGlBeginEnd;
>  extern bool supportsARBShaderObjects;
>
>  extern glws::Drawable *currentDrawable;
> +extern glws::Drawable *latestDrawable;
>  extern Context *currentContext;
>
>  glws::Drawable *
> diff --git a/retrace/glretrace_main.cpp b/retrace/glretrace_main.cpp
> index 109efd9..55adeb4 100644
> --- a/retrace/glretrace_main.cpp
> +++ b/retrace/glretrace_main.cpp
> @@ -409,8 +409,11 @@ retrace::flushRendering(void) {
>
>  void
>  retrace::waitForInput(void) {
> -    while (glws::processEvents()) {
> +    if (!glretrace::latestDrawable) {
> +        return;
>      }
> +
> +    glretrace::latestDrawable->waitForInput();
>  }
>
>  void
> diff --git a/retrace/glretrace_ws.cpp b/retrace/glretrace_ws.cpp
> index bead54e..5cf8bb8 100644
> --- a/retrace/glretrace_ws.cpp
> +++ b/retrace/glretrace_ws.cpp
> @@ -41,6 +41,7 @@ namespace glretrace {
>
>
>  glws::Drawable *currentDrawable = NULL;
> +glws::Drawable *latestDrawable = NULL;
>  Context *currentContext = NULL;
>
>
> @@ -140,7 +141,7 @@ makeCurrent(trace::Call &call, glws::Drawable *drawable, Context *context)
>      }
>
>      if (drawable && context) {
> -        currentDrawable = drawable;
> +        latestDrawable = currentDrawable = drawable;
>          currentContext = context;
>      } else {
>          currentDrawable = NULL;
> diff --git a/retrace/glws.hpp b/retrace/glws.hpp
> index 05903a7..a40ee95 100644
> --- a/retrace/glws.hpp
> +++ b/retrace/glws.hpp
> @@ -31,6 +31,7 @@
>  #define _GLWS_HPP_
>
>
> +#include <iostream>
>  #include <vector>
>
>
> @@ -121,6 +122,11 @@ public:
>      }
>
>      virtual void swapBuffers(void) = 0;
> +
> +    virtual void waitForInput(void) {
> +        /* No waiting unless implemented by derived class. */
> +        std::cout << "Ack! Virtualized.\n";
> +    }
>  };
>
>
> diff --git a/retrace/glws_glx.cpp b/retrace/glws_glx.cpp
> index 1573bb9..b9b0429 100644
> --- a/retrace/glws_glx.cpp
> +++ b/retrace/glws_glx.cpp
> @@ -102,7 +102,7 @@ public:
>          attr.background_pixel = 0;
>          attr.border_pixel = 0;
>          attr.colormap = XCreateColormap(display, root, visinfo->visual, AllocNone);
> -        attr.event_mask = StructureNotifyMask;
> +        attr.event_mask = StructureNotifyMask | KeyPressMask;
>
>          unsigned long mask;
>          mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
> @@ -138,11 +138,22 @@ public:
>      void waitForEvent(int type) {
>          XEvent event;
>          do {
> -            XWindowEvent(display, window, StructureNotifyMask, &event);
> +            XWindowEvent(display, window, StructureNotifyMask | KeyPressMask, &event);
>              describeEvent(event);
>          } while (event.type != type);
>      }
>
> +    void waitForInput(void) {
> +        /* Flush any old events. */
> +        while (XPending(display) > 0) {
> +            XEvent event;
> +            XNextEvent(display, &event);
> +        }
> +
> +        /* Then wait for a new key-press event. */
> +        waitForEvent(KeyPress);
> +    }
> +
>      ~GlxDrawable() {
>          XDestroyWindow(display, window);
>      }
> --
> 1.7.10
>
> _______________________________________________
> apitrace mailing list
> apitrace at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/apitrace


More information about the apitrace mailing list