Screen/Linux: mexLock() Screen() into memory if running on Mesa OpenGL

Turns out Mesa, at least as of 10.1, as shipped in Ubuntu 14.04-LTS,
has a bug which causes it to crash on a "clear Screen" -> Reload Screen
cycle.

On first call in a session to glXGetProcAddress('glfoo') to get the
entry point to gl function glfoo(), if the stub for this function
needs to get dynamically generated, Mesa will do so, but it will
setup a persistent pointer to the name string 'glfoo' passed to the
glXGetProcAddress() function. It will use the callers memory space
to cache the name string, instead of creating its own private copy!

For us this means that if Screen() calls glewInit() to setup gl
entry point bindings, Mesa will have pointers into the inside of
Screen! If the user 'clear Screen' unloads the Screen.mex file,
then reload it - usually to a different address in the address space
due to relocations or maybe address space layout randomization -
Mesa (specifically libglapi.so) will have dangling pointers to
unallocated memory. Next time somebody (e.g., reloaded Screen())
calls glXGetProcAddress(), libglapi will deref these invalid
pointers and crash!

As various bits of Octave and Matlab also use OpenGL and therefore
hold references to libOpenGL / libglapi, both libraries won't get
unloaded / reloaded when our Screen.mex file gets unloaded/reloaded,
therefore the dangling pointers won't get reinitialized properly.

The only real fix for this crasher is to fix Mesa with a trivial
one-liner bugfix. However, until that is done, we need a workaround.

Our workaround is to mexLock() Screen() into memory as soon as
"Mesa" is detected as underlying OpenGL library, so we can't get
clear'ed out of memory until session termination.

This can be prevented via setenv('PSYCH_DONT_LOCK_SCREEN','1'); and
won't happen at all on non-Mesa OpenGL implementations.

-> 'clear Screen' / 'clear mex' / 'clear all' won't clear Screen,
   with all the annoying inconvenience this causes to some users and
   Mk specifically during development. Better than crashing tough.

-> Hashtag: SoftwareSucks.
Screen/Linux: Add gcc pragma to suppress XKeyCodetoKeysym deprecation warning.
Screen/GStreamer: Change handling of pipeline bus messages.

Turns out our old method of receiving/handling messages on the
GStreamer GstPipeline message bus doesn't work on Octave 3.8 under
Linux if Octave's QT based GUI is active :(

The Qt toolkit on Linux - and thereby Octave on Linux GUI - uses
glib's event loops internally for some GUI event processing. We
also used glib's default event loop to process/dispatch bus
messages and this caused cross talk between Octave GUI and our
GStreamer backend - Octave GUI ate our events, so we never received
them. This caused failure to loop videos during playback because
we didn't get the EOS messages needed to trigger a rewind. It also
made error handling useless, because we couldn't get the error and
warning message events.

Now all our GStreamer backends (video playback, video capture/recording,
movie writing) implement a new strategy in their PsychGSProcessContext()
methods. Direct polling of the bus and direct dequeueing/dispatch without
GLib's event loops. Old code is still there as disabled alternative.

-> Works now fine under Linux with Octave GUI/CLI and Matlab GUI/CLI.
-> Needs retesting on OSX and Windows. If this doesn't work i will sob
   uncontrollably. How painful can this get??

-> Screen for 64-Bit Octave/Matlab on Linux rebuilt and tested.
-> Test on other platforms pending.

HashTag: CanThisReleaseCycleSuckEvenMore?
Screen/Linux: Move deprecated warning suppress pragma out of function.

Old gcc of Debian 6 doesn’t like the pragma inside the function, so
don’t do it.
Screen/Linux: Make output of Screen('Computer') more consistent with OSX.

computer.kern struct format should match OSX output closely.
computer.system format should match other OS’es closely.
PsychSupported() output format should match other OS’es closely.

-> Update PsychtoolboxRegistration.m to make use of the new
Screen(‘Computer’) fields and get rid of some Unix system() command
line calls.
Rebuild some sample of Screen mex files for compile testing and GStreamer testing.

Compile is ok. New GStreamer bus message handling works on all
operating systems and scripting environments. Pheew!
moalcore/moglcore: Add include of uchar.h to fix compile failure on R2012a

Add explicit #include <uchar.h> before include for mex.h into
mogltypes.h and moaltypes.h. Apparently latest versions of gcc
and clang do not include this file automatically, which causes
build failure for moglcore and moalcore under Matlab R2012a on
recent Ubuntu 14.04 and OSX 10.9.

Adding the defines fixes this. Similar fix may be needed for
some mex files on OSX which don't use Psychtoolbox core
infrastructure.
Screen: Disable RTLD_GLOBAL export of Screen's symbols on Linux.

Disable the dlopen() self-reloading() of Screen. It had the
purpose of making Screen's symbols globally available to other
shared libraries. However, the reason for doing this is long
gone (ListenChar magic sauce for Octave + GUI) as it proved
too fragile.

Now the code just causes trouble because mex files like
moglcore.mex would use Screen's symbols (e.g., for GLEW stuff)
and keep Screen.mex loaded into the process when it should
unload on 'clear Screen'. We disable this useless code, but
leave it in place to document the approach for future more
targeted use.

-> This prepares the latest workaround in the next commit
   for an annoying Mesa bug.

-> Remove some orphaned prototype from ScreenCloseAll().
Screen: Try harder to workaround Mesa OpenGL bug.

Same cause and solution principle as in commit

77b7b0fb2581473b5c1944b8f4b2161738da56e8

However, instead of locking Screen() into process memory, we
lock moglcore into process memory and make sure Mesa gets its
evil string pointers targeted to moglcore.

1. Perform OpenGL context creation/init/binding in Screen() as usual.
2. Detect buggy Mesa.
3. Call moglcore('LockModule') to trigger moglcore's glewInit() to
   get Mesa's pointers directed towards its library image and to
   mexLock() moglcore into memory, so moglcore is a safe haven for
   Mesa's pointers until the work session gets terminated normally.
4. Call Screen()'s glewInit(). Mesa won't redirect its pointers, as
   it already has happy pointers towards moglcore.

-> moglcore can'b be clear'ed, but that doesn't matter, given how
   rarely one rebuilds or reinitializes it. Or so i hope...

-> Screen is not locked and can be clear'ed as usual, which is
   convenient :)

-> Seems to work. Needed new moglcore('LockModule') subfunction to
   trigger a mexLock() inside moglcore, followed by a no-op otherwise.

-> Tested on Octave and Matlab on Linux with Mesa's Gallium nouveau
   driver under Ubuntu 14.04-LTS.
PsychHID: Update code comment wrt. CTRL+C handling on Octave 3.8

Update April 2014: As of Octave 3.8.1 on Linux, sending SIGINT
explicitely when running under Octave 3.8 with QT based GUI is no
longer needed for the Qt-GUI, and also not executed, because GNUTERM
is no longer set to 'qt', so all is good :)
Merge branch 'master' into Psychtoolbox-3.0.11

Merge fixes for GStreamer pipeline bus vs. Octave QT GUI incompatibility.
Merge workaround for Mesa OpenGL bug.
Merge minor cleanups and compile fixes.
Merge Screen('Computer') improvements for Linux.

Conflicts:
	Psychtoolbox/PsychBasic/Octave3OSXFiles64/Screen.mex
	Psychtoolbox/PsychBasic/Screen.mexmaci64
moglcore/moalcore: Undo uchar.h include

Breaks build on old build-system. Needs more thought.
Almost all mex files for all platforms rebuilt for 3.0.11 release.
Update release date to 30 April 2014 for v3.0.11 final.

This hopefully concludes Psychtoolbox-3.0.11.
Merge pull request #195 from kleinerm/Psychtoolbox-3.0.11

Psychtoolbox 3.0.11 final

* Workaround Mesa OpenGL bug on Linux.
* Refine nouveau-kms bug workaround for Linux 3.13+
* Make GStreamer backends compatible with Octave 3.8 GUI on Linux.
* Refine Screen('Computer') on Linux/Windows.
* Some cleanups.
* Most mex files rebuilt for 3.0.11.