I find myself in a situation where I’m mixing smpeg video
and widget-like things. In particular, displaying a dialog which
overlaps currently playing smpeg video. I’d like to continue
drawing the video directly to the screen surface, avoiding
extra buffering, but not have it overdraw a dialog which
overlaps the video, like so:±-------+
±-| dialog |
| | |
| video |
I decided to try being clever about what area gets passed to
SDL_UpdateRects(), and this works pretty well. In particular,
I keep track of what part of the video should be visible to
the user, and use the display update hook in the smpeg library
to mask the updated region.
The trouble with this approach is that when the SDL window is
overlayed by a window from another application and then reexposed,
the newly exposed area includes the overdrawn-but-not-updated
video. I’m working under X11, so I’m guessing that SDL is using
the user-accessible video buffer to also deal with expose
events and the like.
Digging through the SDL source, the functions X11_DisableAutoRefresh()
and X11_EnableAutoRefresh() appear to provide a solution to
this problem. Disabling auto refresh causes SDL to emit an
SDL_ExposeEvent when X11 emits an expose. The comments around
these functions, about troubles with opengl similar to those
I’ve been experiencing with smpeg, lead me to believe that’s
what these functions are for.
Would it be possible to export some functions like these in future
versions of SDL, which enable/disable auto refresh under X11,
and do the right thing (hopefully nothing?) under other platforms.
Also, since these functions actually increment/decrement a reference
count, would it be possible to have the 'enable auto refresh’
function emit a SDL_ExposeEvent on returning to auto refresh
so that the video buffer is again valid? Or just return a boolean
value so the enduser can do an update if necessary? I’d be happy
to submit a patch to do this.
Also, are there any addtional lurking pitfalls you can see with my approach?
“The sound of gunfire, off in the distance. I’m getting used to it now.”
– Talking Heads