XShm patch

Another quick and dirty patch:
http://www.notam02.no/~kjetism/juce_xshm.diff

Its made according to these instructions:
http://pantransit.reptiles.org/prog/mit-shm.html

The patch gives a nice speedup boost. Juce feels much better now.

I have not checked for XShmCompletionEvent events, because I don’t know the internals of juce enough to know whether its necessary. So an XIfEvent call or something after blitting might be needed. But so far, I haven’t seen any problems with the current state.

XDestroyImage gives me a freeing-illegal-memory-block error, no matter what I do. After many hours trying to figure out why, I gave up and commented out the call. This probably needs a proper solution…

You probably need to fix the 24/32 stuff better than I did here. Turns out that the server stores 32 bit images no matter what, although the depth is set to 24. My solution is probably working correctly enough though, but the code is not pretty.

I did not add support for XShm for 16 bit displays. Its not difficult, everything just got a bit messy for me. I also guess that you probably will rewrite most of it anyway, and then adding hacks for 16 bit display could make the patch harder to read.

Please apply something like this for the next release. :slight_smile:

Cool.

In fact, not being a linux expert, I’d never even heard of XShm! I’ll go through this and get my head around it, and will probably merge it in for the next release. Thanks!

[quote=“jules”]Cool.

In fact, not being a linux expert, I’d never even heard of XShm! I’ll go through this and get my head around it, and will probably merge it in for the next release. Thanks![/quote]

Ouch, seems like the check I made for the existance of XShm was a bit inadequate. For example doesn’t ssh X tunneling work.

So here is an ugly hack to fix it:
http://www.notam02.no/~kjetism/xshmcheck.diff
I just put the checking function globally, but I guess (and hope) you will put it somewhere else.

The code is based on information gathered in this discussion:
http://groups.google.com/group/comp.windows.x/browse_thread/thread/d891878a49164e60/6eebdd84fd683a9a?lnk=st&q=XShmQueryExtension&rnum=6#6eebdd84fd683a9a